Fix CAPI call logic: Replace CAPI related to Common Apps with CAPI related to user... 13/28713/7 accepted/tizen_3.0.2014.q3_common accepted/tizen_3.0.m14.3_ivi tizen_3.0.2014.q3_common tizen_3.0.m14.3_ivi accepted/tizen/3.0.2014.q3/common/20141020.112647 accepted/tizen/3.0.m14.3/ivi/20141017.215422 accepted/tizen/common/20141014.155457 accepted/tizen/ivi/20141017.224351 submit/tizen_3.0.2014.q3_common/20141020.111623 submit/tizen_3.0.m14.3_ivi/20141017.000000 submit/tizen_common/20141014.135300 submit/tizen_ivi/20141017.000000 submit/tizen_mobile/20141120.000000 tizen_3.0.2014.q3_common_release tizen_3.0.m14.3_ivi_release
authorBaptiste DURAND <baptiste.durand@open.eurogiciel.org>
Tue, 14 Oct 2014 12:15:12 +0000 (14:15 +0200)
committerBaptiste DURAND <baptiste.durand@open.eurogiciel.org>
Tue, 14 Oct 2014 13:49:34 +0000 (06:49 -0700)
BUG-Tizen=TC-1703
BUG-Tizen=TC-1704

Change-Id: I3cb1338ae59ed360b7fd431d8e81609ec4350de0
Signed-off-by: Baptiste DURAND <baptiste.durand@open.eurogiciel.org>
server/src/pkgmgr-server.c

index 8865c2f..ea8cea2 100755 (executable)
@@ -1490,8 +1490,43 @@ static int __pkgcmd_app_cb(const pkgmgrinfo_appinfo_h handle, void *user_data)
        return 0;
 }
 
+void free_user_context(user_ctx* ctx)
+{
+       char **env = NULL;
+       int i = 0;
+       if (!ctx)
+               return;
+       env = ctx->env;
+       //env variable ends by NULL element
+       while (env[i]) {
+               free(env[i]);
+               i++;
+       }
+       free(env);
+       env = NULL;
+       free(ctx);
+}
+
+int set_environement(user_ctx* ctx)
+{
+       int i = 0;
+       int res = 0;
+       char **env = NULL;
+       if (!ctx)
+               return;
+       setgid(ctx->gid);
+       setuid(ctx->uid);
+       env = ctx->env;
+       //env variable ends by NULL element
+       while (env[i]) {
+               if( putenv(env[i]) != 0 )
+                       res = -1;
+               i++;
+       }
+       return res;
+}
 
-user_ctx* getUserContext(uid_t uid)
+user_ctx* get_user_context(uid_t uid)
 {
        /* we can use getpwnam because this is used only after a
         * fork and just before an execv
@@ -1665,7 +1700,7 @@ pop:
                        }
 
                        /* Execute backend !!! */
-                       user_context = getUserContext(item->uid);
+                       user_context = get_user_context(item->uid);
                        if(user_context) {
                                setgid(user_context->gid);
                                setuid(item->uid);
@@ -1733,6 +1768,17 @@ pop:
                        gchar **argvp;
                        GError *gerr = NULL;
                        char *label = NULL;
+                       user_ctx* user_context = get_user_context(item->uid);
+                       if(!user_context) {
+                               DBG("Failed to getenv for the user : %d", item->uid);
+                               exit(1);
+                       }
+                       if(set_environement(user_context)){
+                               DBG("Failed to set env for the user : %d", item->uid);
+                               exit(1);
+                       }
+                       free_user_context(user_context);
+
                        ret_parse = g_shell_parse_argv(item->args,
                                                       &argcp, &argvp, &gerr);
                        if (FALSE == ret_parse) {
@@ -1756,20 +1802,21 @@ pop:
                                        }
                                }
 
-                               ret = pkgmgrinfo_appinfo_set_state_enabled(item->pkgid, val);
+                               ret = pkgmgrinfo_appinfo_set_usr_state_enabled(item->pkgid, val, item->uid);
                                if (ret != PMINFO_R_OK) {
                                        perror("fail to activate/deactivte package");
                                        exit(1);
                                }
 
                                if (label) {
-                                       ret = pkgmgrinfo_appinfo_set_default_label(item->pkgid, label);
+                                       ret = pkgmgrinfo_appinfo_set_usr_default_label(item->pkgid, label, item->uid);
                                        if (ret != PMINFO_R_OK) {
                                                perror("fail to activate/deactivte package");
                                                exit(1);
                                        }
 
-                                       ret = ail_desktop_appinfo_modify_str(item->pkgid,
+                                       ret = ail_desktop_appinfo_modify_usr_str(item->pkgid,
+                                                               item->uid,
                                                                AIL_PROP_NAME_STR,
                                                                label, FALSE);
                                        if (ret != AIL_ERROR_OK) {
@@ -1779,7 +1826,8 @@ pop:
                                        free(label);
                                }
 
-                               ret = ail_desktop_appinfo_modify_bool(item->pkgid,
+                               ret = ail_desktop_appinfo_modify_usr_bool(item->pkgid,
+                                                       item->uid,
                                                        AIL_PROP_X_SLP_ENABLED_BOOL,
                                                        val, TRUE);
                                if (ret != AIL_ERROR_OK) {
@@ -1798,14 +1846,14 @@ pop:
 
                                if (val) {
                                        pkgmgrinfo_pkginfo_h handle;
-                                       ret = pkgmgrinfo_pkginfo_get_pkginfo(item->pkgid, &handle);
+                                       ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(item->pkgid, item->uid, &handle);
                                        if (ret < 0) {
-                                               ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
+                                               ret = pkgmgr_parser_parse_usr_manifest_for_installation(manifest,item->uid, NULL);
                                                if (ret < 0) {
                                                        DBGE("insert in db failed\n");
                                                }
 
-                                               ret = ail_desktop_add(item->pkgid);
+                                               ret = ail_usr_desktop_add(item->pkgid, item->uid);
                                                if (ret != AIL_ERROR_OK) {
                                                        DBGE("fail to ail_desktop_add");
                                                }
@@ -1813,13 +1861,14 @@ pop:
                                                pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
                                        }
 
-                                       ret = pkgmgrinfo_appinfo_set_state_enabled(item->pkgid, val);
+                                       ret = pkgmgrinfo_appinfo_set_usr_state_enabled(item->pkgid, val, item->uid);
                                        if (ret != PMINFO_R_OK) {
                                                perror("fail to activate/deactivte package");
                                                exit(1);
                                        }
 
-                                       ret = ail_desktop_appinfo_modify_bool(item->pkgid,
+                                       ret = ail_desktop_appinfo_modify_usr_bool(item->pkgid,
+                                                               item->uid,
                                                                AIL_PROP_X_SLP_ENABLED_BOOL,
                                                                val, TRUE);
                                        if (ret != AIL_ERROR_OK) {
@@ -1828,7 +1877,7 @@ pop:
                                        }
                                }
                                else
-                                       ret = pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL);
+                                       ret = pkgmgr_parser_parse_usr_manifest_for_uninstallation(manifest, item->uid, NULL);
 
                                if (ret < 0) {
                                        DBGE("insert in db failed\n");
@@ -1887,6 +1936,17 @@ pop:
                        gint argcp;
                        gchar **argvp;
                        GError *gerr = NULL;
+                       user_ctx* user_context = get_user_context(item->uid);
+                       if(!user_context) {
+                               DBG("Failed to getenv for the user : %d", item->uid);
+                               exit(1);
+                       }
+                       if(set_environement(user_context)){
+                               DBG("Failed to set env for the user : %d", item->uid);
+                               exit(1);
+                       }
+                       free_user_context(user_context);
+
                        ret_parse = g_shell_parse_argv(item->args,
                                                       &argcp, &argvp, &gerr);
                        if (FALSE == ret_parse) {
@@ -1980,6 +2040,17 @@ pop:
                        gint argcp;
                        gchar **argvp;
                        GError *gerr = NULL;
+                       user_ctx* user_context = get_user_context(item->uid);
+                       if(!user_context) {
+                               DBG("Failed to getenv for the user : %d", item->uid);
+                               exit(1);
+                       }
+                       if(set_environement(user_context)){
+                               DBG("Failed to set env for the user : %d", item->uid);
+                               exit(1);
+                       }
+                       free_user_context(user_context);
+
                        ret_parse = g_shell_parse_argv(item->args,
                                                       &argcp, &argvp, &gerr);
                        if (FALSE == ret_parse) {
@@ -2056,21 +2127,21 @@ pop:
                        DBG("child run parse argv()");
 
                        pkgmgrinfo_pkginfo_h handle;
-                       ret = pkgmgrinfo_pkginfo_get_pkginfo(item->pkgid, &handle);
+                       ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(item->pkgid, item->uid, &handle);
                        if (ret < 0) {
                                DBG("Failed to get handle\n");
                                exit(1);
                        }
 
                        if (item->req_type == COMM_REQ_KILL_APP) {
-                               ret = pkgmgrinfo_appinfo_get_list(handle, PMSVC_UI_APP, __pkgcmd_app_cb, "kill");
+                               ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMSVC_UI_APP, __pkgcmd_app_cb, "kill", item->uid);
                                if (ret < 0) {
                                        DBG("pkgmgrinfo_appinfo_get_list() failed\n");
                                        pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
                                        exit(1);
                                }
                        } else if (item->req_type == COMM_REQ_CHECK_APP) {
-                               ret = pkgmgrinfo_appinfo_get_list(handle, PMSVC_UI_APP, __pkgcmd_app_cb, "check");
+                               ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMSVC_UI_APP, __pkgcmd_app_cb, "check", item->uid);
                                if (ret < 0) {
                                        DBG("pkgmgrinfo_appinfo_get_list() failed\n");
                                        pkgmgrinfo_pkginfo_destroy_pkginfo(handle);