From: Hwankyu Jhun Date: Wed, 17 Aug 2016 23:01:17 +0000 (+0900) Subject: Set list of supplementary groups IDs X-Git-Tag: accepted/tizen/common/20160818.144545^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ffa535f58fe63d72dc9427a840727fee0d1bee9f;p=platform%2Fcore%2Fappfw%2Fpkgmgr-server.git Set list of supplementary groups IDs Change-Id: I3072df4d4e41a12ca8fedcc4b59d3c378ef3c39f Signed-off-by: Hwankyu Jhun --- diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 69a6623..22d15a8 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -580,24 +580,42 @@ int set_environement(user_ctx *ctx) int i = 0; int res = 0; char **env = NULL; - gid_t groups[] = {EXT_STORAGE_GROUP, - EXT_STORAGE_APPDATA_GROUP, - MEDIA_STORAGE_GROUP}; + int n; + gid_t *groups; if (!ctx) - return -1;; - if (setgid(ctx->gid)) { - ERR("setgid failed: %d", errno); + return -1; + + n = getgroups(0, NULL); + if (n < 0) { + ERR("Failed to get the number of supplementary group IDs"); return -1; } - if (setgroups(ARRAY_SIZE(groups), groups) < 0) { - ERR("setgroups failed: %d", errno); + + groups = (gid_t *)calloc(1, sizeof(gid_t) * (n + 3)); + if (groups == NULL) { + ERR("out of memory"); + return -1; + } + + n = getgroups(n, groups); + if (n < 0) { + ERR("Failed to get list of supplementary group IDs"); + free(groups); return -1; } - if (setuid(ctx->uid)) { - ERR("setuid failed: %d", errno); + + groups[n++] = EXT_STORAGE_GROUP; + groups[n++] = EXT_STORAGE_APPDATA_GROUP; + groups[n++] = MEDIA_STORAGE_GROUP; + + if (setgroups(n, groups) < 0) { + ERR("setgroups failed: %d", errno); + free(groups); return -1; } + free(groups); + env = ctx->env; /* env variable ends by NULL element */ while (env[i]) {