From a5da77bc54cf57e18bba15ed475ff2aee07ca975 Mon Sep 17 00:00:00 2001 From: Unbit Date: Fri, 23 Aug 2013 14:46:06 +0200 Subject: [PATCH] added --add-gid --- core/utils.c | 25 +++++++++++++++++++++++++ core/uwsgi.c | 1 + uwsgi.h | 1 + 3 files changed, 27 insertions(+) diff --git a/core/utils.c b/core/utils.c index cebe2e4b..2aff0abe 100644 --- a/core/utils.c +++ b/core/utils.c @@ -488,6 +488,31 @@ void uwsgi_as_root() { exit(1); } } + struct uwsgi_string_list *usl; + size_t ags = 0; + uwsgi_foreach(usl, uwsgi.additional_gids) ags++; + if (ags > 0) { + gid_t *ags_list = uwsgi_calloc(sizeof(gid_t) * ags); + size_t g_pos = 0; + uwsgi_foreach(usl, uwsgi.additional_gids) { + ags_list[g_pos] = atoi(usl->value); + if (!ags_list[g_pos]) { + struct group *g = getgrnam(usl->value); + if (g) { + ags_list[g_pos] = g->gr_gid; + } + else { + uwsgi_log("unable to find group %s\n", usl->value); + exit(1); + } + } + g_pos++; + } + if (setgroups(ags, ags_list)) { + uwsgi_error("setgroups()"); + exit(1); + } + } int additional_groups = getgroups(0, NULL); if (additional_groups > 0) { gid_t *gids = uwsgi_calloc(sizeof(gid_t) * additional_groups); diff --git a/core/uwsgi.c b/core/uwsgi.c index 72be38e9..caa754a5 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -287,6 +287,7 @@ static struct uwsgi_option uwsgi_base_options[] = { {"chroot", required_argument, 0, "chroot() to the specified directory", uwsgi_opt_set_str, &uwsgi.chroot, 0}, {"uid", required_argument, 0, "setuid to the specified user/uid", uwsgi_opt_set_uid, NULL, 0}, {"gid", required_argument, 0, "setgid to the specified group/gid", uwsgi_opt_set_gid, NULL, 0}, + {"add-gid", required_argument, 0, "add the specified group id to the process credentials", uwsgi_opt_add_string_list, &uwsgi.additional_gids, 0}, {"immediate-uid", required_argument, 0, "setuid to the specified user/uid IMMEDIATELY", uwsgi_opt_set_immediate_uid, NULL, UWSGI_OPT_IMMEDIATE}, {"immediate-gid", required_argument, 0, "setgid to the specified group/gid IMMEDIATELY", uwsgi_opt_set_immediate_gid, NULL, UWSGI_OPT_IMMEDIATE}, {"no-initgroups", no_argument, 0, "disable additional groups set via initgroups()", uwsgi_opt_true, &uwsgi.no_initgroups, 0}, diff --git a/uwsgi.h b/uwsgi.h index ed684559..273e218d 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -1799,6 +1799,7 @@ struct uwsgi_server { char *uidname; char *gidname; int no_initgroups; + struct uwsgi_string_list *additional_gids; #ifdef UWSGI_CAP cap_value_t *cap;