Manage user / Global requests for installation and Uninstallation 25/27625/1
authorBaptiste DURAND <baptiste.durand@open.eurogiciel.org>
Fri, 5 Sep 2014 10:02:48 +0000 (12:02 +0200)
committerBaptiste DURAND <baptiste.durand@open.eurogiciel.org>
Tue, 16 Sep 2014 17:23:34 +0000 (19:23 +0200)
Change-Id: I61dd33582f72f03499629e913e7dc7bda09fa1cf
Signed-off-by: Baptiste DURAND <baptiste.durand@open.eurogiciel.org>
12 files changed:
client/include/package-manager.h
client/src/pkgmgr.c
comm/comm_client.h
comm/comm_client_dbus.c
comm/comm_pkg_mgr.xml
comm/comm_pkg_mgr_server.c
comm/comm_pkg_mgr_server.h
comm/test/test_comm_client.c
server/include/pkgmgr-server.h
server/src/pkgmgr-server.c
server/src/pm-queue.c
tool/pkg_cmd.c

index 27adf63..7177752 100755 (executable)
@@ -351,7 +351,9 @@ int pkgmgr_client_usr_install(pkgmgr_client *pc, const char *pkg_type,
 int pkgmgr_client_reinstall(pkgmgr_client *pc, const char *pkg_type, const char *pkgid,
                            const char *optional_file, pkgmgr_mode mode,
                            pkgmgr_handler event_cb, void *data);
-
+int pkgmgr_client_usr_reinstall(pkgmgr_client * pc, const char *pkg_type, const char *pkgid,
+                                 const char *optional_file, pkgmgr_mode mode,
+                             pkgmgr_handler event_cb, void *data, uid_t uid);
 /**
  * @brief      This API uninstalls package.
  *
@@ -616,6 +618,7 @@ int pkgmgr_client_usr_request_service(pkgmgr_request_service_type service_type,
  * @retval     PKGMGR_R_ECOMM  communication error
 */
 int pkgmgr_client_get_size(pkgmgr_client * pc, const char *pkgid, pkgmgr_getsize_type get_type, pkgmgr_handler event_cb, void *data);
+int pkgmgr_client_usr_get_size(pkgmgr_client * pc, const char *pkgid, pkgmgr_getsize_type get_type, pkgmgr_handler event_cb, void *data, uid_t uid);
 
 /**
  * @brief      This API provides package list
index df69593..bff40ef 100755 (executable)
@@ -823,7 +823,7 @@ catch:
        return ret;
 }
 
-static int __get_size_process(pkgmgr_client * pc, const char *pkgid, pkgmgr_getsize_type get_type, pkgmgr_handler event_cb, void *data)
+static int __get_size_process(pkgmgr_client * pc, const char *pkgid, uid_t uid, pkgmgr_getsize_type get_type, pkgmgr_handler event_cb, void *data)
 {
        char *req_key = NULL;
        int ret =0;
@@ -871,7 +871,7 @@ static int __get_size_process(pkgmgr_client * pc, const char *pkgid, pkgmgr_gets
        tryvm_if(cookie == NULL, ret = PKGMGR_R_ERROR, "__get_cookie_from_security_server is NULL");
 
        /* request */
-       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_GET_SIZE, pkgtype, pkgid, args, cookie, 1);
+       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_GET_SIZE, pkgtype, pkgid, args, cookie, uid, 1);
        if (ret < 0)
                _LOGE("comm_client_request failed, ret=%d\n", ret);
 
@@ -969,7 +969,7 @@ static int __move_pkg_process(pkgmgr_client * pc, const char *pkgid, uid_t uid,
        tryvm_if(cookie == NULL, ret = PKGMGR_R_ERROR, "__get_cookie_from_security_server is NULL");
 
        /* 6. request */
-       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_MOVER, pkgtype, pkgid, args, cookie, 1);
+       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_MOVER, pkgtype, pkgid, args, cookie,uid, 1);
        if (ret < 0)
                _LOGE("comm_client_request failed, ret=%d\n", ret);
 
@@ -1017,9 +1017,9 @@ static int __check_app_process(pkgmgr_request_service_type service_type, pkgmgr_
 
        /* 3. request activate */
        if (service_type == PM_REQUEST_KILL_APP)
-               ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_KILL_APP, pkgtype, pkgid, NULL, NULL, 1);
+               ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_KILL_APP, pkgtype, pkgid, NULL, NULL, uid, 1);
        else if (service_type == PM_REQUEST_CHECK_APP)
-               ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_CHECK_APP, pkgtype, pkgid, NULL, NULL, 1);
+               ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_CHECK_APP, pkgtype, pkgid, NULL, NULL, uid, 1);
 
        if (ret < 0)
                _LOGE("request failed, ret=%d\n", ret);
@@ -1244,7 +1244,7 @@ API int pkgmgr_client_usr_install(pkgmgr_client * pc, const char *pkg_type,
        /******************* end of quote ************************/
 
        /* 6. request install */
-       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_INSTALLER, pkgtype, pkg_path, args, cookie, 1);
+       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_INSTALLER, pkgtype, pkg_path, args, cookie, uid, 1);
        tryvm_if(ret < 0, ret = PKGMGR_R_ECOMM, "request failed, ret=%d", ret);
 
        ret = req_id;
@@ -1280,6 +1280,13 @@ API int pkgmgr_client_reinstall(pkgmgr_client * pc, const char *pkg_type, const
                                  const char *optional_file, pkgmgr_mode mode,
                              pkgmgr_handler event_cb, void *data)
 {
+       return pkgmgr_client_usr_reinstall(pc, pkg_type, pkgid, optional_file, mode, event_cb, data,GLOBAL_USER);
+}
+
+API int pkgmgr_client_usr_reinstall(pkgmgr_client * pc, const char *pkg_type, const char *pkgid,
+                                 const char *optional_file, pkgmgr_mode mode,
+                             pkgmgr_handler event_cb, void *data, uid_t uid)
+{
        char *pkgtype = NULL;
        char *installer_path = NULL;
        char *req_key = NULL;
@@ -1370,7 +1377,7 @@ API int pkgmgr_client_reinstall(pkgmgr_client * pc, const char *pkg_type, const
        /******************* end of quote ************************/
 
        /* 6. request install */
-       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_INSTALLER, pkgtype, pkgid, args, cookie, 1);
+       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_INSTALLER, pkgtype, pkgid, args, cookie, uid, 1);
        tryvm_if(ret < 0, ret = PKGMGR_R_ECOMM, "request failed");
 
        ret = req_id;
@@ -1416,7 +1423,7 @@ API int pkgmgr_client_usr_uninstall(pkgmgr_client *pc, const char *pkg_type,
 
        caller_pkgid = __get_caller_pkgid(uid);
        if (caller_pkgid == NULL)
-               _LOGE("caller dont have pkgid..\n");
+               _LOGD("caller dont have pkgid..\n");
 
        /* Check for NULL value of pc */
        retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client handle is NULL\n");
@@ -1524,7 +1531,7 @@ API int pkgmgr_client_usr_uninstall(pkgmgr_client *pc, const char *pkg_type,
        /******************* end of quote ************************/
 
        /* 6. request install */
-       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_INSTALLER, pkgtype, pkgid, args, cookie, 1);
+       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_INSTALLER, pkgtype, pkgid, args, cookie, uid, 1);
        tryvm_if(ret < 0, ret = PKGMGR_R_ECOMM, "calloc failed");
 
        ret = req_id;
@@ -1651,7 +1658,7 @@ API int pkgmgr_client_usr_move(pkgmgr_client *pc, const char *pkg_type,
        /* 6. request install */
        ret = comm_client_request(mpc->info.request.cc, req_key,
                                  COMM_REQ_TO_MOVER, pkgtype, pkgid,
-                                 args, cookie, 1);
+                                 args, cookie, uid, 1);
        if (ret < 0) {
                _LOGE("request failed, ret=%d\n", ret);
 
@@ -1802,7 +1809,7 @@ API int pkgmgr_client_move_usr_pkg(pkgmgr_client *pc, const char *pkg_type,
        /******************* end of quote ************************/
 
        /* 6. request install */
-       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_MOVER, pkgtype, pkgid, args, cookie, 1);
+       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_MOVER, pkgtype, pkgid, args, cookie, uid, 1);
        tryvm_if(ret < 0, ret = PKGMGR_R_ECOMM, "calloc failed");
 
        ret = req_id;
@@ -1857,7 +1864,7 @@ API int pkgmgr_client_usr_activate(pkgmgr_client * pc, const char *pkg_type,
        retvm_if(req_key == NULL, PKGMGR_R_EINVAL, "req_key is NULL");
 
        /* 3. request activate */
-       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_ACTIVATOR, pkgtype, pkgid, "1 PKG", cookie, 1);
+       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_ACTIVATOR, pkgtype, pkgid, "1 PKG", cookie, uid, 1);
        tryvm_if(ret < 0, ret = PKGMGR_R_ECOMM, "request failed, ret=%d", ret);
 
        ret = PKGMGR_R_OK;
@@ -1904,7 +1911,7 @@ API int pkgmgr_client_usr_deactivate(pkgmgr_client *pc, const char *pkg_type,
        retvm_if(req_key == NULL, PKGMGR_R_EINVAL, "req_key is NULL");
 
        /* 3. request activate */
-       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_ACTIVATOR, pkgtype, pkgid, "0 PKG", cookie, 1);
+       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_ACTIVATOR, pkgtype, pkgid, "0 PKG", cookie, uid, 1);
        tryvm_if(ret < 0, ret = PKGMGR_R_ECOMM, "request failed, ret=%d", ret);
 
        ret = PKGMGR_R_OK;
@@ -1945,7 +1952,7 @@ API int pkgmgr_client_usr_activate_app(pkgmgr_client * pc, const char *appid, ui
        retvm_if(req_key == NULL, PKGMGR_R_EINVAL, "req_key is NULL");
 
        /* 3. request activate */
-       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_ACTIVATOR, pkgtype, appid, "1 APP", cookie, 1);
+       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_ACTIVATOR, pkgtype, appid, "1 APP", cookie, uid, 1);
        tryvm_if(ret < 0, ret = PKGMGR_R_ECOMM, "request failed, ret=%d", ret);
 
        ret = PKGMGR_R_OK;
@@ -2027,7 +2034,7 @@ API int pkgmgr_client_usr_activate_appv(pkgmgr_client * pc, const char *appid, c
        /******************* end of quote ************************/
 
        /* 3. request activate */
-       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_ACTIVATOR, pkgtype, appid, argsr, cookie, 1);
+       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_ACTIVATOR, pkgtype, appid, argsr, cookie, uid, 1);
        tryvm_if(ret < 0, ret = PKGMGR_R_ECOMM, "request failed, ret=%d", ret);
 
        ret = PKGMGR_R_OK;
@@ -2073,7 +2080,7 @@ API int pkgmgr_client_usr_deactivate_app(pkgmgr_client *pc, const char *appid, u
        retvm_if(req_key == NULL, PKGMGR_R_EINVAL, "req_key is NULL");
 
        /* 3. request activate */
-       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_ACTIVATOR, pkgtype, appid, "0 APP", cookie, 1);
+       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_TO_ACTIVATOR, pkgtype, appid, "0 APP", cookie, uid, 1);
        tryvm_if(ret < 0, ret = PKGMGR_R_ECOMM, "request failed, ret=%d", ret);
 
        ret = PKGMGR_R_OK;
@@ -2183,7 +2190,7 @@ API int pkgmgr_client_usr_clear_user_data(pkgmgr_client *pc, const char *pkg_typ
        /* 6. request clear */
        ret = comm_client_request(mpc->info.request.cc, req_key,
                                  COMM_REQ_TO_CLEARER, pkgtype, appid,
-                                 args, cookie, 1);
+                                 args, cookie, uid, 1);
        if (ret < 0) {
                _LOGE("request failed, ret=%d\n", ret);
 
@@ -2372,7 +2379,7 @@ API int pkgmgr_client_usr_request_service(pkgmgr_request_service_type service_ty
                tryvm_if(pc == NULL, ret = PKGMGR_R_EINVAL, "pc is NULL\n");
                tryvm_if((service_mode < PM_GET_TOTAL_SIZE) || (service_mode >= PM_GET_MAX), ret = PKGMGR_R_EINVAL, "service_mode is wrong\n");
 
-               ret = __get_size_process(pc, pkgid, (pkgmgr_getsize_type)service_mode, event_cb, data);
+               ret = __get_size_process(pc, pkgid, uid, (pkgmgr_getsize_type)service_mode, event_cb, data);
                break;
 
        case PM_REQUEST_KILL_APP:
@@ -2399,8 +2406,14 @@ catch:
        return ret;
 }
 
+
 API int pkgmgr_client_get_size(pkgmgr_client * pc, const char *pkgid, pkgmgr_getsize_type get_type, pkgmgr_handler event_cb, void *data)
 {
+       return pkgmgr_client_usr_get_size(pc, pkgid, get_type, event_cb, data, GLOBAL_USER);
+}
+
+API int pkgmgr_client_usr_get_size(pkgmgr_client * pc, const char *pkgid, pkgmgr_getsize_type get_type, pkgmgr_handler event_cb, void *data, uid_t uid)
+{
        char *req_key = NULL;
        int ret =0;
        char *pkgtype = "rpm";
@@ -2456,7 +2469,7 @@ API int pkgmgr_client_get_size(pkgmgr_client * pc, const char *pkgid, pkgmgr_get
        tryvm_if(cookie == NULL, ret = PKGMGR_R_ERROR, "__get_cookie_from_security_server is NULL");
 
        /* request */
-       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_GET_SIZE, pkgtype, pkgid, args, cookie, 1);
+       ret = comm_client_request(mpc->info.request.cc, req_key, COMM_REQ_GET_SIZE, pkgtype, pkgid, args, cookie, uid, 1);
        if (ret < 0)
                _LOGE("comm_client_request failed, ret=%d\n", ret);
 
index 13b62e4..af6a65b 100755 (executable)
@@ -46,7 +46,7 @@ API int comm_client_free(comm_client *cc);
 API int comm_client_request(comm_client *cc, const char *req_id,
                            const int req_type, const char *pkg_type,
                            const char *pkgid, const char *args,
-                           const char *cookie, int is_block);
+                           const char *cookie, uid_t uid, int is_block);
 
 API int comm_client_set_status_callback(int comm_status_type, comm_client *cc, status_cb cb, void *cb_data);
 #endif                         /* __COMM_CLIENT_H__ */
index a39fefe..ce5cc4a 100755 (executable)
@@ -337,8 +337,9 @@ comm_client_request(
                const char *pkgid,
                const char *args,
                const char *cookie,
+               uid_t uid,
                int is_block)
-{
+{      
        DBusError err;
        DBusMessage *msg = NULL;
        int r = COMM_RET_ERROR; /* Default return */
@@ -381,6 +382,7 @@ comm_client_request(
                                      DBUS_TYPE_STRING, &pkgid,
                                      DBUS_TYPE_STRING, &args,
                                      DBUS_TYPE_STRING, &cookie,
+                                     DBUS_TYPE_INT32, &uid,
                                      DBUS_TYPE_INVALID)) {
                r = -3;
                ERR("dbus_message_append_args fail");
index b82a38a..28ec17c 100644 (file)
@@ -10,6 +10,7 @@
                        <arg type="s" name="pkgid" direction="in" />
                        <arg type="s" name="args" direction="in" />
                        <arg type="s" name="cookie" direction="in" />
+                       <arg type="i" name="uid" direction="in" />
                        <arg type="i" name="ret" direction="out" />
                </method>
        </interface>
index 6560426..61dbd08 100755 (executable)
@@ -75,7 +75,7 @@ G_DEFINE_TYPE(PkgMgrObject, pkg_mgr_object, G_TYPE_OBJECT);
 GCallback pkgmgr_request(PkgMgrObject *obj, const gchar *req_id,
                         const gint req_type, const gchar *pkg_type,
                         const gchar *pkgid, const gchar *args,
-                        const gchar *cookie, gint *ret, GError *err);
+                        const gchar *cookie, uid_t uid, gint *ret, GError *err);
 
 /* Include stub header */
 #include "comm_pkg_mgr_server_dbus_bindings.h"
@@ -165,7 +165,7 @@ pkgmgr_request(PkgMgrObject *obj,
               const gchar *pkg_type,
               const gchar *pkgid,
               const gchar *args,
-              const gchar *cookie, gint *ret, GError *err)
+              const gchar *cookie, uid_t uid, gint *ret, GError *err)
 {
        dbg("Called");
        *ret = COMM_RET_OK;     /* TODO: fix this! */
@@ -175,9 +175,9 @@ pkgmgr_request(PkgMgrObject *obj,
         * */
 
        if (obj->req_cb) {
-               dbg("Call request callback(obj, %s, %d, %s, %s, %s, *ret)",
-                   req_id, req_type, pkg_type, pkgid, args);
-               obj->req_cb(obj->req_cb_data, req_id, req_type, pkg_type,
+               dbg("Call request callback(obj, %lu, %s, %d, %s, %s, %s, *ret)",
+                   uid, req_id, req_type, pkg_type, pkgid, args);
+               obj->req_cb(obj->req_cb_data, uid, req_id, req_type, pkg_type,
                            pkgid, args, cookie, ret);
        } else {
                dbg("Attempt to call request callback,"
index 65dbf2d..0e45b8c 100755 (executable)
@@ -38,7 +38,7 @@ typedef struct PkgMgrObject PkgMgrObject;
 API GType pkg_mgr_object_get_type(void);
 #define PKG_MGR_TYPE_OBJECT (pkg_mgr_object_get_type())
 
-typedef void (*request_callback) (void *cb_data, const char *req_id,
+typedef void (*request_callback) (void *cb_data, uid_t uid, const char *req_id,
                                  const int req_type, const char *pkg_type,
                                  const char *pkgid, const char *args,
                                  const char *cookie, int *ret);
index d7f26e0..d3bf0d5 100755 (executable)
@@ -47,7 +47,7 @@ int main(int argc, char **argv)
        gint ret;
        ret = comm_client_request(cc, "__test__req_key", COMM_REQ_TO_INSTALLER,
                                  "dpkg", "test_pkg", "arg1 arg2 arg3",
-                                 "this_is_a_cookie", 0);
+                                 "this_is_a_cookie", getuid(), 0);
 
        printf("client: waiting signal...\n");
        comm_client_set_status_callback(COMM_STATUS_BROADCAST_ALL,
index d4efb4d..dae1f27 100755 (executable)
@@ -43,6 +43,7 @@
 typedef struct {
        char req_id[MAX_REQ_ID_LEN];
        int req_type;
+       uid_t uid;
        char pkg_type[MAX_PKG_TYPE_LEN];
        char pkgid[MAX_PKG_NAME_LEN];
        char args[MAX_PKG_ARGS_LEN];
index eca012b..8865c2f 100755 (executable)
@@ -96,6 +96,13 @@ FILE *___log = NULL;
 static int backend_flag = 0;   /* 0 means that backend process is not running */
 static int drawing_popup = 0;  /* 0 means that pkgmgr-server has no popup now */
 
+typedef struct  {
+       char **env;
+       uid_t uid;
+       gid_t gid;
+} user_ctx;
+
+
 /* For pkgs with no desktop file, inotify callback wont be called.
 *  To handle that case ail_db_update is initialized as 1
 *  This flag will be used to ensure that pkgmgr server does not exit
@@ -1018,7 +1025,7 @@ static void sighandler(int signo)
 
 }
 
-void req_cb(void *cb_data, const char *req_id, const int req_type,
+void req_cb(void *cb_data, uid_t uid, const char *req_id, const int req_type,
            const char *pkg_type, const char *pkgid, const char *args,
            const char *cookie, int *ret)
 {
@@ -1041,7 +1048,23 @@ void req_cb(void *cb_data, const char *req_id, const int req_type,
        strncpy(item->pkgid, pkgid, sizeof(item->pkgid) - 1);
        strncpy(item->args, args, sizeof(item->args) - 1);
        strncpy(item->cookie, cookie, sizeof(item->cookie) - 1);
-
+       item->uid = uid;
+       /* uid equals to GLOBALUSER means that the installation or action is made at Global level.
+        * At this time, we are not able to check the credentials of this dbus message (due to gdbus API to implement the pkgmgr-server)
+        * So we cannot check if the user that makes request has permisssion to do it.
+        * Note theses CAPI could be used by deamon (user is root or system user) or web/native API framework (user id is one of regular users)
+        * In consequence a bug is filed : 
+        * 
+        * Logic has to be implmemented:
+        * RUID means the id of the user that make the request (retreived from credential of the message)
+        * UID is the uid in argument of the request
+        * 
+        * if RUID == UID & UID is regular user == TRUE ==> Granted
+        * if UID == GLOBAL_USER & RUID is ADMIN == TRUE ==> Granted
+        * if RUID == (ROOT or System USER) & UID is Regular USER ==> Granted
+        * if UID != Regular USER & UID != GLOBAL USER  == TRUE ==> NOT GRANTED
+        * if RUID == Regular USER & UID != RUID == True ==> NOT GRANTED
+        *  */
        if (sig_reg == 0) {
                struct sigaction act;
 
@@ -1467,6 +1490,74 @@ static int __pkgcmd_app_cb(const pkgmgrinfo_appinfo_h handle, void *user_data)
        return 0;
 }
 
+
+user_ctx* getUserContext(uid_t uid)
+{
+       /* we can use getpwnam because this is used only after a
+        * fork and just before an execv
+        * No concurrencial call can corrupt the data
+        * returned by getpwuid
+        */
+       user_ctx *context_res;
+       char ** env;
+       struct passwd * pwd;
+       int len;
+       int ret = 0;
+
+       pwd = getpwuid(uid);
+       if (!pwd)
+               return NULL;
+       
+       do {
+               context_res = (user_ctx *)malloc(sizeof(user_ctx));
+               if (!context_res) {
+                       ret = -1;
+                       break;
+               }
+               env = (char**)malloc(3* sizeof(char *));
+               if (!env) {
+                       ret = -1;
+                       break;
+               }
+               // Build environment context
+               len = snprintf(NULL,0, "HOME=%s", pwd->pw_dir);
+               env[0] = (char*)malloc((len + 1)* sizeof(char));
+               if(env[0] == NULL) {
+                       ret = -1;
+                       break;
+               }
+               sprintf(env[0], "HOME=%s", pwd->pw_dir);
+               len = snprintf(NULL,0, "USER=%s", pwd->pw_name);
+               env[1] = (char*)malloc((len + 1)* sizeof(char));
+               if(env[1] == NULL) {
+                       ret = -1;
+                       break;
+               }
+               
+               sprintf(env[1], "USER=%s", pwd->pw_name);
+               env[2] = NULL;
+       } while (0);
+       
+       if(ret == -1) {
+               free(context_res);
+               context_res = NULL;
+               int i = 0;
+               //env variable ends by NULL element
+               while (env[i]) {
+                       free(env[i]);
+                       i++;
+               }
+               free(env);
+               env = NULL;
+       } else {
+               context_res->env = env;
+               context_res->uid = uid;
+               context_res->gid = pwd->pw_gid;
+       }
+       return context_res;
+}
+  
+
 gboolean queue_job(void *data)
 {
        /* DBG("queue_job start"); */
@@ -1513,6 +1604,7 @@ pop:
                switch ((ptr + x)->pid) {
                case 0: /* child */
                        DBG("before run _get_backend_cmd()");
+                       user_ctx* user_context; 
                        /*Check for efl-tpk app*/
                        backend_cmd = _get_backend_cmd(item->pkg_type);
 
@@ -1573,8 +1665,16 @@ pop:
                        }
 
                        /* Execute backend !!! */
-                       ret = execv(backend_cmd, args_vector);
-
+                       user_context = getUserContext(item->uid);
+                       if(user_context) {
+                               setgid(user_context->gid);
+                               setuid(item->uid);
+                               ret = execve(backend_cmd, args_vector,user_context->env);
+                       } else {
+                               ret = -1;
+                               perror("fail to retreive user context");
+                               exit(1);
+                       }
                        /* Code below: exec failure. Should not be happened! */
                        DBG(">>>>>> OOPS 2!!!");
 
index b9ae684..6ac727b 100755 (executable)
@@ -280,6 +280,7 @@ int _pm_queue_push(pm_dbus_msg *item)
 
        strncpy(data->msg->req_id, item->req_id, strlen(item->req_id));
        data->msg->req_type = item->req_type;
+       data->msg->uid = item->uid;
        strncpy(data->msg->pkg_type, item->pkg_type, strlen(item->pkg_type));
        strncpy(data->msg->pkgid, item->pkgid, strlen(item->pkgid));
        strncpy(data->msg->args, item->args, strlen(item->args));
@@ -333,6 +334,7 @@ pm_dbus_msg *_pm_queue_pop(int position)
 
        strncpy(ret->req_id, cur->msg->req_id, strlen(cur->msg->req_id));
        ret->req_type = cur->msg->req_type;
+       ret->uid = cur->msg->uid;
        strncpy(ret->pkg_type, cur->msg->pkg_type, strlen(cur->msg->pkg_type));
        strncpy(ret->pkgid, cur->msg->pkgid, strlen(cur->msg->pkgid));
        strncpy(ret->args, cur->msg->args, strlen(cur->msg->args));
index ea80e4f..17f302d 100755 (executable)
@@ -529,34 +529,18 @@ static int __process_request(uid_t uid)
                        mode = PM_QUIET;
                if (data.des_path[0] == '\0')
                {
-                       if(uid != GLOBAL_USER)
-                       {
-                               ret =
-                                       pkgmgr_client_usr_install(pc, data.pkg_type, NULL,
-                                                       data.pkg_path, NULL, mode,
-                                                       __return_cb, pc, uid);
-                       }else
-                       {
-                               ret =
-                           pkgmgr_client_install(pc, data.pkg_type, NULL,
-                                                 data.pkg_path, NULL, mode,
-                                                 __return_cb, pc);
-                       }
+                       ret =
+                               pkgmgr_client_usr_install(pc, data.pkg_type, NULL,
+                                               data.pkg_path, NULL, mode,
+                                               __return_cb, pc, uid);
                }else{
-                       if(uid != GLOBAL_USER)
-                       {
-                               ret =
-                                       pkgmgr_client_usr_install(pc, data.pkg_type,
-                                                       data.des_path, data.pkg_path,
-                                                       NULL, mode, __return_cb, pc, uid);
-                       }else
-                       {
-                               ret =
-                                       pkgmgr_client_install(pc, data.pkg_type,
-                                                       data.des_path, data.pkg_path,
-                                                       NULL, mode, __return_cb, pc);
-                       }
-               }if (ret < 0){
+                       ret =
+                               pkgmgr_client_usr_install(pc, data.pkg_type,
+                                               data.des_path, data.pkg_path,
+                                               NULL, mode, __return_cb, pc, uid);
+
+               }
+               if (ret < 0){
                        data.result = PKGCMD_ERR_FATAL_ERROR;
                        if (access(data.pkg_path, F_OK) != 0)
                                data.result = PKGCMD_ERR_PACKAGE_NOT_FOUND;
@@ -594,8 +578,8 @@ static int __process_request(uid_t uid)
                }
 
                ret =
-                   pkgmgr_client_uninstall(pc, data.pkg_type, data.pkgid,
-                                           mode, __return_cb, NULL);
+                   pkgmgr_client_usr_uninstall(pc, data.pkg_type, data.pkgid,
+                                           mode, __return_cb, NULL,uid);
                if (ret < 0){
                        data.result = PKGCMD_ERR_FATAL_ERROR;
                        if (access(data.pkg_path, F_OK) != 0)
@@ -623,7 +607,7 @@ static int __process_request(uid_t uid)
                }
 
                mode = PM_QUIET;
-               ret = pkgmgr_client_reinstall(pc, data.pkg_type, data.pkgid, NULL, mode, __return_cb, pc);
+               ret = pkgmgr_client_usr_reinstall(pc, data.pkg_type, data.pkgid, NULL, mode, __return_cb, pc, uid);
                if (ret < 0){
                        data.result = PKGCMD_ERR_FATAL_ERROR;
                        if (access(data.pkg_path, F_OK) != 0)
@@ -657,15 +641,8 @@ static int __process_request(uid_t uid)
                        printf("package is not installed\n");
                        break;
                }
-               if(uid != GLOBAL_USER)
-               {
-                       ret = pkgmgr_client_usr_clear_user_data(pc, data.pkg_type,
+               ret = pkgmgr_client_usr_clear_user_data(pc, data.pkg_type,
                                                    data.pkgid, mode, uid);
-               }else
-               {
-                       ret = pkgmgr_client_clear_user_data(pc, data.pkg_type,
-                                                   data.pkgid, mode);
-               }
                if (ret < 0)
                        break;
                ret = data.result;
@@ -688,10 +665,7 @@ static int __process_request(uid_t uid)
 
                if ( strcmp(data.pkg_type, "app") == 0 ) {
                        if (strlen(data.label) == 0) {
-                               if (uid != GLOBAL_USER)
-                                       ret = pkgmgr_client_usr_activate_app(pc, data.pkgid, uid);
-                               else
-                                       ret = pkgmgr_client_activate_app(pc, data.pkgid);
+                               ret = pkgmgr_client_usr_activate_app(pc, data.pkgid, uid);
                                if (ret < 0)
                                        break;
                        } else {
@@ -699,20 +673,14 @@ static int __process_request(uid_t uid)
                                char *largv[3] = {NULL, };
                                largv[0] = "-l";
                                largv[1] = data.label;
-                               if(uid != GLOBAL_USER)
-                                       ret = pkgmgr_client_usr_activate_appv(pc, data.pkgid, largv, uid);
-                               else
-                                       ret = pkgmgr_client_activate_appv(pc, data.pkgid, largv);
+                               ret = pkgmgr_client_usr_activate_appv(pc, data.pkgid, largv, uid);
                                if (ret < 0)
                                        break;
                        }
                } else {
-                       if (uid != GLOBAL_USER)
                                ret = pkgmgr_client_usr_activate(pc, data.pkg_type, data.pkgid, uid);
-                       else
-                               ret = pkgmgr_client_activate(pc, data.pkg_type, data.pkgid);
-                       if (ret < 0)
-                               break;
+                               if (ret < 0)
+                                       break;
                }
                ret = data.result;
 
@@ -735,17 +703,11 @@ static int __process_request(uid_t uid)
                }
 
                if ( strcmp(data.pkg_type, "app") == 0 ) {
-                       if (uid != GLOBAL_USER)
-                               ret = pkgmgr_client_usr_deactivate_app(pc, data.pkgid, uid);
-                       else
-                               ret = pkgmgr_client_deactivate_app(pc, data.pkgid);
+                       ret = pkgmgr_client_usr_deactivate_app(pc, data.pkgid, uid);
                        if (ret < 0)
                                break;
                }else {
-                       if(uid != GLOBAL_USER)
-                               ret = pkgmgr_client_usr_deactivate(pc, data.pkg_type, data.pkgid, uid);
-                       else
-                               ret = pkgmgr_client_deactivate(pc, data.pkg_type, data.pkgid);
+                       ret = pkgmgr_client_usr_deactivate(pc, data.pkg_type, data.pkgid, uid);
                        if (ret < 0)
                                break;
                }
@@ -778,18 +740,10 @@ static int __process_request(uid_t uid)
                        break;
                }
                if (data.quiet == 0)
-               {
-                       if(uid != GLOBAL_USER)
-                               ret = pkgmgr_client_usr_move(pc, data.pkg_type, data.pkgid,  data.type, mode, uid);
-                       else
-                               ret = pkgmgr_client_move(pc, data.pkg_type, data.pkgid,  data.type, mode);
-               }else
-               {
-                       if (uid != GLOBAL_USER)
-                               ret = pkgmgr_client_usr_request_service(PM_REQUEST_MOVE, data.type, pc, NULL, data.pkgid, uid, NULL, NULL, NULL);
-                       else
-                               ret = pkgmgr_client_request_service(PM_REQUEST_MOVE, data.type, pc, NULL, data.pkgid, NULL, NULL, NULL);
-               }
+                       ret = pkgmgr_client_usr_move(pc, data.pkg_type, data.pkgid,  data.type, mode, uid);
+                else
+                       ret = pkgmgr_client_usr_request_service(PM_REQUEST_MOVE, data.type, pc, NULL, data.pkgid, uid, NULL, NULL, NULL);
+               
                printf("pkg[%s] move result = %d\n", data.pkgid, ret);
 
                if (ret < 0)
@@ -848,10 +802,7 @@ static int __process_request(uid_t uid)
                }
 
                if (data.request == KILLAPP_REQ) {
-                       if (uid != GLOBAL_USER)
-                               ret = pkgmgr_client_usr_request_service(PM_REQUEST_KILL_APP, NULL, pc, NULL, data.pkgid, uid, NULL, NULL, &pid);
-                       else
-                               ret = pkgmgr_client_request_service(PM_REQUEST_KILL_APP, NULL, pc, NULL, data.pkgid, NULL, NULL, &pid);
+                       ret = pkgmgr_client_usr_request_service(PM_REQUEST_KILL_APP, NULL, pc, NULL, data.pkgid, uid, NULL, NULL, &pid);
                        if (ret < 0){
                                data.result = PKGCMD_ERR_FATAL_ERROR;
                                break;
@@ -862,10 +813,7 @@ static int __process_request(uid_t uid)
                                printf("Pkgid: %s is already Terminated\n", data.pkgid);
 
                } else if (data.request == CHECKAPP_REQ) {
-                       if (uid != GLOBAL_USER)
-                               ret = pkgmgr_client_usr_request_service(PM_REQUEST_CHECK_APP, NULL, pc, NULL, data.pkgid, uid, NULL, NULL, &pid);
-                       else
-                               ret = pkgmgr_client_request_service(PM_REQUEST_CHECK_APP, NULL, pc, NULL, data.pkgid, NULL, NULL, &pid);
+                       ret = pkgmgr_client_usr_request_service(PM_REQUEST_CHECK_APP, NULL, pc, NULL, data.pkgid, uid, NULL, NULL, &pid);
                        if (ret < 0){
                                data.result = PKGCMD_ERR_FATAL_ERROR;
                                break;
@@ -976,10 +924,7 @@ static int __process_request(uid_t uid)
                break;
 
        case CSC_REQ:
-               if (uid != GLOBAL_USER)
-                       ret = pkgmgr_client_usr_request_service(PM_REQUEST_CSC, 0, NULL, NULL, NULL, uid, data.des_path, NULL, (void *)data.pkg_path);
-               else
-                       ret = pkgmgr_client_request_service(PM_REQUEST_CSC, 0, NULL, NULL, NULL, data.des_path, NULL, (void *)data.pkg_path);
+               ret = pkgmgr_client_usr_request_service(PM_REQUEST_CSC, 0, NULL, NULL, NULL, uid, data.des_path, NULL, (void *)data.pkg_path);
                if (ret < 0)
                        data.result = PKGCMD_ERR_FATAL_ERROR;
                break;
@@ -1000,16 +945,10 @@ static int __process_request(uid_t uid)
                }
 
                if (data.type == 9) {
-                       if (uid != GLOBAL_USER)
-                               ret = pkgmgrinfo_pkginfo_get_usr_list(__pkg_list_cb, (void *)pc, uid);
-                       else
-                               ret = pkgmgrinfo_pkginfo_get_list(__pkg_list_cb, (void *)pc);
+                       ret = pkgmgrinfo_pkginfo_get_usr_list(__pkg_list_cb, (void *)pc, uid);
                        break;
                }
-               if (uid != GLOBAL_USER)
-                       ret = pkgmgr_client_usr_request_service(PM_REQUEST_GET_SIZE, data.type, pc, NULL, data.pkgid, uid, NULL, NULL, NULL);
-               else
-                       ret = pkgmgr_client_request_service(PM_REQUEST_GET_SIZE, data.type, pc, NULL, data.pkgid, NULL, NULL, NULL);
+               ret = pkgmgr_client_usr_request_service(PM_REQUEST_GET_SIZE, data.type, pc, NULL, data.pkgid, uid, NULL, NULL, NULL);
                if (ret < 0){
                        data.result = PKGCMD_ERR_FATAL_ERROR;
                        break;