Set list of supplementary groups IDs 74/84274/2 accepted/tizen/common/20160818.144545 accepted/tizen/ivi/20160819.063359 accepted/tizen/mobile/20160819.063301 accepted/tizen/tv/20160819.063346 accepted/tizen/wearable/20160819.063325 submit/tizen/20160818.060816
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 17 Aug 2016 23:01:17 +0000 (08:01 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 17 Aug 2016 23:04:12 +0000 (08:04 +0900)
Change-Id: I3072df4d4e41a12ca8fedcc4b59d3c378ef3c39f
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/pkgmgr-server.c

index 69a6623..22d15a8 100644 (file)
@@ -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]) {