set groups for the access of external storage. 29/72229/3
authorjongmyeongko <jongmyeong.ko@samsung.com>
Tue, 31 May 2016 08:11:04 +0000 (17:11 +0900)
committerSemun Lee <sm79.lee@samsung.com>
Wed, 1 Jun 2016 02:41:13 +0000 (19:41 -0700)
Change-Id: Id15871fc965d241616d06efce1990d67e723e814
Signed-off-by: jongmyeongko <jongmyeong.ko@samsung.com>
src/pkgmgr-server.c

index 58f79f0..dadac26 100644 (file)
@@ -33,6 +33,7 @@
 #include <sys/types.h>
 #include <fcntl.h>
 #include <signal.h>
+#include <grp.h>
 
 #include <glib.h>
 #include <gio/gio.h>
 #define OWNER_ROOT 0
 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
 
+#define EXT_STORAGE_GROUP 10001
+#define EXT_STORAGE_APPDATA_GROUP 10002
+#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
+
 typedef struct  {
        char **env;
        uid_t uid;
@@ -631,12 +636,18 @@ 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};
+
        if (!ctx)
                return -1;;
        if (setgid(ctx->gid)) {
                ERR("setgid failed: %d", errno);
                return -1;
        }
+       if (setgroups(ARRAY_SIZE(groups), groups) < 0) {
+               ERR("setgroups failed: %d", errno);
+               return -1;
+       }
        if (setuid(ctx->uid)) {
                ERR("setuid failed: %d", errno);
                return -1;