From f2941328651a227872f442eca49b4d6b807cb821 Mon Sep 17 00:00:00 2001 From: jooseong lee Date: Wed, 20 Jul 2016 20:25:04 +0900 Subject: [PATCH 01/16] Set the SMACK security label to run given executable file in systemd services Change-Id: Idc1e8645d1c96f5eb82651d7857ec74fe2e07d30 Signed-off-by: jooseong lee --- package-manager.service.in | 1 + 1 file changed, 1 insertion(+) diff --git a/package-manager.service.in b/package-manager.service.in index 3e318ec..c3aa925 100644 --- a/package-manager.service.in +++ b/package-manager.service.in @@ -4,4 +4,5 @@ Description=Tizen Package Manager [Service] User=app_fw Group=app_fw +SmackProcessLabel=System ExecStart=@PREFIX@/bin/pkgmgr-server -- 2.7.4 From 27682de924fa83098bc297107e3a8e2de5d87851 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Tue, 12 Jul 2016 14:13:49 +0900 Subject: [PATCH 02/16] Fix coding rule Change-Id: Ic18982d2254c09c628ae9e20059908c737063976 Signed-off-by: Junghyun Yeon --- src/pkgmgr-server.c | 51 +++++++++-------------- src/pm-queue.c | 109 ++++++++++++++++++------------------------------- src/request.c | 24 ++++------- src/restriction_mode.c | 3 +- 4 files changed, 70 insertions(+), 117 deletions(-) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index deb83ab..b727ac8 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -187,7 +187,7 @@ static void __send_fail_signal(backend_info *info) return; } pkgmgr_installer_set_session_id(pi, info->req_id); - switch(info->req_type) { + switch (info->req_type) { case PKGMGR_REQUEST_TYPE_INSTALL: case PKGMGR_REQUEST_TYPE_MOUNT_INSTALL: case PKGMGR_REQUEST_TYPE_REINSTALL: @@ -325,11 +325,8 @@ static int __register_signal_handler(void) static int __check_backend_status_for_exit(void) { int i = 0; - for(i = 0; i < num_of_backends; i++) - { - if (!__is_backend_busy(i)) - continue; - else + for (i = 0; i < num_of_backends; i++) { + if (__is_backend_busy(i)) return 0; } return 1; @@ -343,24 +340,18 @@ static int __check_queue_status_for_exit(void) int i = 0; int c = 0; int slot = -1; - for(i = 0; i < entries; i++) - { + for (i = 0; i < entries; i++) { if (ptr->queue_slot <= slot) { ptr++; - continue; - } - else { + } else { head[c] = ptr->head; slot = ptr->queue_slot; c++; ptr++; } } - for(i = 0; i < num_of_backends; i++) - { - if (!head[i]) - continue; - else + for (i = 0; i < num_of_backends; i++) { + if (head[i]) return 0; } return 1; @@ -427,9 +418,8 @@ static int __pkgcmd_proc_iter_kill_cmdline(const char *apppath, int option) int pgid; dp = opendir("/proc"); - if (dp == NULL) { + if (dp == NULL) return -1; - } for (ret = readdir_r(dp, &dentry, &result); ret == 0 && result != NULL; @@ -477,7 +467,7 @@ static void __make_pid_info_file(char *req_key, int pid, uid_t uid) struct passwd pwd; struct passwd *pwd_result; - if(req_key == NULL) + if (req_key == NULL) return; ret = getpwuid_r(uid, &pwd, buf, sizeof(buf), &pwd_result); @@ -526,9 +516,8 @@ static int __kill_app(char *appid, uid_t uid) } ret = __pkgcmd_proc_iter_kill_cmdline(exec, 1); - if (ret != PMINFO_R_OK) { + if (ret != PMINFO_R_OK) DBG("failed to kill app[%s], exec[%s]", appid, exec); - } pkgmgrinfo_appinfo_destroy_appinfo(appinfo); return ret; @@ -559,7 +548,7 @@ static int __pkgcmd_app_cb(const pkgmgrinfo_appinfo_h handle, void *user_data) if (strcmp(pdata->cmd, "kill") == 0) pid = __pkgcmd_proc_iter_kill_cmdline(exec, 1); - else if(strcmp(pdata->cmd, "check") == 0) + else if (strcmp(pdata->cmd, "check") == 0) pid = __pkgcmd_proc_iter_kill_cmdline(exec, 0); __make_pid_info_file(pkgid, pid, pdata->uid); @@ -574,7 +563,7 @@ void free_user_context(user_ctx* ctx) if (!ctx) return; env = ctx->env; - //env variable ends by NULL element + /* env variable ends by NULL element */ while (env[i]) { free(env[i]); i++; @@ -608,7 +597,7 @@ int set_environement(user_ctx *ctx) return -1; } env = ctx->env; - //env variable ends by NULL element + /* env variable ends by NULL element */ while (env[i]) { if (putenv(env[i]) != 0) res = -1; @@ -647,17 +636,17 @@ user_ctx *get_user_context(uid_t uid) ret = -1; break; } - // Build environment context + /* Build environment context */ len = snprintf(NULL, 0, "HOME=%s", pwd.pw_dir); env[0] = (char *)malloc((len + 1) * sizeof(char)); - if(env[0] == NULL) { + if (env[0] == NULL) { ret = -1; break; } snprintf(env[0], len + 1, "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) { + if (env[1] == NULL) { ret = -1; break; } @@ -669,7 +658,7 @@ user_ctx *get_user_context(uid_t uid) free(context_res); context_res = NULL; i = 0; - //env variable ends by NULL element + /* env variable ends by NULL element */ while (env && env[i]) { free(env[i]); i++; @@ -1538,10 +1527,10 @@ char *_get_backend_cmd(char *type) char buffer[1024] = { 0 }; char *command = NULL; int size = 0; + fp = fopen(PKG_CONF_PATH, "r"); - if (fp == NULL) { + if (fp == NULL) return NULL; - } char *path = NULL; while (fgets(buffer, 1024, fp) != NULL) { @@ -1612,7 +1601,7 @@ int main(int argc, char *argv[]) return -1; } -#if !GLIB_CHECK_VERSION(2,35,0) +#if !GLIB_CHECK_VERSION(2, 35, 0) g_type_init(); #endif mainloop = g_main_loop_new(NULL, FALSE); diff --git a/src/pm-queue.c b/src/pm-queue.c index 1022332..9ba8be9 100644 --- a/src/pm-queue.c +++ b/src/pm-queue.c @@ -56,14 +56,11 @@ static int __is_pkg_supported(const char *pkgtype) queue_info_map *ptr = NULL; ptr = start; int i = 0; - for(i = 0; i < entries; i++) - { + for (i = 0; i < entries; i++) { if (!strncmp(ptr->pkgtype, pkgtype, MAX_PKG_TYPE_LEN)) return 1; - else { + else ptr++; - continue; - } } return 0; } @@ -77,14 +74,11 @@ static int __entry_exist(char *backend) queue_info_map *ptr = NULL; ptr = start; int i = 0; - for(i = 0; i < entries; i++) - { + for (i = 0; i < entries; i++) { if (!strncmp(ptr->backend, backend, MAX_PKG_NAME_LEN)) return ptr->queue_slot; - else { + else ptr++; - continue; - } } return -1; } @@ -97,24 +91,20 @@ static void __update_head_from_pkgtype(pm_queue_data *data) ptr = start; int slot = -1; int i = 0; - for(i = 0; i < entries; i++) - { + for (i = 0; i < entries; i++) { if (!strncmp(ptr->pkgtype, data->msg->pkg_type, MAX_PKG_TYPE_LEN)) { ptr->head = data; slot = ptr->queue_slot; - } - else { + } else { ptr++; - continue; } } /*update head for each duplicate entry*/ ptr = start; - for(i = 0; i < entries; i++) - { - if(ptr->queue_slot == slot && !ptr->head) { + for (i = 0; i < entries; i++) { + if (ptr->queue_slot == slot && !ptr->head) ptr->head = data; - } + ptr++; } return; @@ -126,14 +116,11 @@ static pm_queue_data *__get_head_from_pkgtype(const char *pkg_type) queue_info_map *ptr = NULL; ptr = start; int i = 0; - for(i = 0; i < entries; i++) - { + for (i = 0; i < entries; i++) { if (!strncmp(ptr->pkgtype, pkg_type, MAX_PKG_TYPE_LEN)) return ptr->head; - else { + else ptr++; - continue; - } } return NULL; @@ -158,15 +145,14 @@ int _pm_queue_init(void) return -1; } i = n; - /*Find number of backends (symlinks + executables) - The backend dir should not conatin any other file except the backends.*/ - while(n--) - { - if(!strcmp(namelist[n]->d_name, ".") || - !strcmp(namelist[n]->d_name, "..")) + /* Find number of backends (symlinks + executables) + The backend dir should not conatin any other file except the backends. */ + while (n--) { + if (!strcmp(namelist[n]->d_name, ".") || + !strcmp(namelist[n]->d_name, "..")) continue; snprintf(abs_filename, MAX_PKG_NAME_LEN, "%s/%s", - BACKEND_DIR, namelist[n]->d_name); + BACKEND_DIR, namelist[n]->d_name); if (lstat(abs_filename, &fileinfo)) { perror("lstat"); continue; @@ -176,24 +162,22 @@ int _pm_queue_init(void) c++; memset(abs_filename, 0x00, MAX_PKG_NAME_LEN); } - /*Add entries to info map.*/ + /* Add entries to info map. */ ptr = (queue_info_map*)calloc(c , sizeof(queue_info_map)); memset(ptr, '\0', c * sizeof(queue_info_map)); start = ptr; - for(n = 0; n < c ; n++) - { + for (n = 0; n < c ; n++) { ptr->backend[0] = '\0'; ptr->head = NULL; - ptr->queue_slot = -2;/*-1 can be error return*/ + ptr->queue_slot = -2; /* -1 can be error return */ ptr->pkgtype[0] = '\0'; ptr++; } n = i; ptr = start; - while(n--) - { - if(!strcmp(namelist[n]->d_name, ".") || - !strcmp(namelist[n]->d_name, "..")) + while (n--) { + if (!strcmp(namelist[n]->d_name, ".") || + !strcmp(namelist[n]->d_name, "..")) continue; snprintf(abs_filename, MAX_PKG_NAME_LEN, "%s/%s", BACKEND_DIR, namelist[n]->d_name); @@ -212,9 +196,8 @@ int _pm_queue_init(void) return -1; } buf[ret] = '\0'; - } - /*executable*/ - else { + } else { + /*executable*/ snprintf(buf, sizeof(buf), "%s", abs_filename); } ret = __entry_exist(buf); @@ -226,8 +209,7 @@ int _pm_queue_init(void) entries++; slot++; ptr++; - } - else { + } else { snprintf(ptr->backend, sizeof(ptr->backend), "%s", buf); snprintf(ptr->pkgtype, sizeof(ptr->pkgtype), "%s", namelist[n]->d_name); ptr->queue_slot = ret; @@ -249,8 +231,7 @@ int _pm_queue_init(void) DBG("Number of Entries is %d", entries); DBG("Backend\tType\tSlot\tHead"); ptr = start; - for(n = 0; n < entries; n++) - { + for (n = 0; n < entries; n++) { DBG("%s\t%s\t%d\t%p", ptr->backend, ptr->pkgtype, ptr->queue_slot, ptr->head); ptr++; } @@ -306,8 +287,7 @@ int _pm_queue_push(uid_t uid, const char *req_id, int req_type, /* first push */ cur = data; __update_head_from_pkgtype(data); - } - else { + } else { while (tmp->next) tmp = tmp->next; @@ -332,8 +312,7 @@ pm_dbus_msg *_pm_queue_pop(int position) } memset(ret, 0x00, sizeof(pm_dbus_msg)); ptr = start; - for(i = 0; i < entries; i++) - { + for (i = 0; i < entries; i++) { if (ptr->queue_slot == position) { cur = ptr->head; break; @@ -358,19 +337,18 @@ pm_dbus_msg *_pm_queue_pop(int position) cur->next = NULL; free(cur->msg); free(cur); - /*update head for each duplicate queue entry*/ + /* update head for each duplicate queue entry */ ptr = start; - for(i = 0; i < entries; i++) - { - if(ptr->queue_slot == position) { + for (i = 0; i < entries; i++) { + if (ptr->queue_slot == position) ptr->head = saveptr; - } + ptr++; } return ret; } -/*populate an array of all queue heads and delete them one by one*/ +/* populate an array of all queue heads and delete them one by one */ void _pm_queue_final() { int c = 0; @@ -383,18 +361,13 @@ void _pm_queue_final() queue_info_map *ptr = NULL; ptr = start; - for(i = 0; i < num_of_backends; i++) - { + for (i = 0; i < num_of_backends; i++) head[i] = NULL; - } - for(i = 0; i < entries; i++) - { + for (i = 0; i < entries; i++) { if (ptr->queue_slot <= slot) { ptr++; - continue; - } - else { + } else { head[c] = ptr->head; slot = ptr->queue_slot; c++; @@ -403,7 +376,7 @@ void _pm_queue_final() } c = 0; - while(c < num_of_backends) { + while (c < num_of_backends) { if (!head[c]) { /* in case of head is NULL */ c = c + 1; continue; @@ -485,8 +458,7 @@ void _print_queue(int position) pm_queue_data *cur = NULL; queue_info_map *ptr = start; int i = 0; - for(i =0; i < entries; i++) - { + for (i = 0; i < entries; i++) { if (ptr->queue_slot == position) { cur = ptr->head; break; @@ -494,9 +466,8 @@ void _print_queue(int position) ptr++; } int index = 1; - if (!cur) { + if (!cur) return; - } while (cur) { index++; diff --git a/src/request.c b/src/request.c index d58f978..8f5e3f1 100644 --- a/src/request.c +++ b/src/request.c @@ -372,16 +372,14 @@ static int __handle_request_mount_install(uid_t uid, if (target_uid == (uid_t)-1 || pkgtype == NULL) { g_dbus_method_invocation_return_value(invocation, - g_variant_new("(is)", - PKGMGR_R_ECOMM, "")); + g_variant_new("(is)", PKGMGR_R_ECOMM, "")); ret = -1; goto catch; } if (pkgpath == NULL) { g_dbus_method_invocation_return_value(invocation, - g_variant_new("(is)", - PKGMGR_R_ECOMM, "")); + g_variant_new("(is)", PKGMGR_R_ECOMM, "")); ret = -1; goto catch; } @@ -393,21 +391,18 @@ static int __handle_request_mount_install(uid_t uid, } if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_MOUNT_INSTALL, - pkgtype, pkgpath, args)) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(is)", - PKGMGR_R_ESYSTEM, "")); + pkgtype, pkgpath, args)) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); ret = -1; goto catch; } g_dbus_method_invocation_return_value(invocation, - g_variant_new("(is)", - PKGMGR_R_OK, - reqkey)); + g_variant_new("(is)", PKGMGR_R_OK, reqkey)); ret = 0; - catch: +catch: if (reqkey) free(reqkey); @@ -623,7 +618,7 @@ static int __handle_request_enable_app(uid_t uid, ret = 0; catch: - if(reqkey) + if (reqkey) free(reqkey); return ret; @@ -1301,8 +1296,7 @@ int __return_value_to_caller(const char *req_key, GVariant *result) return 0; } -static const GDBusInterfaceVTable interface_vtable = -{ +static const GDBusInterfaceVTable interface_vtable = { __handle_method_call, NULL, NULL, diff --git a/src/restriction_mode.c b/src/restriction_mode.c index 376d4f9..a3a05fc 100644 --- a/src/restriction_mode.c +++ b/src/restriction_mode.c @@ -261,9 +261,8 @@ static int __get_pkg_restriction_mode(uid_t uid, const char *pkgid, int *mode) sqlite3_stmt *stmt; db = __open_db(); - if (db == NULL) { + if (db == NULL) return -1; - } ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); if (ret != SQLITE_OK) { -- 2.7.4 From db2cf2a95b07460cf45db1c61342fc89620e914d Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Mon, 4 Jul 2016 21:33:52 +0900 Subject: [PATCH 03/16] tpk/wgt backend will run as system session Related changes [slp-pkgmgr] https://review.tizen.org/gerrit/#/c/80764/ [app-installers] https://review.tizen.org/gerrit/#/c/78206/ [tpk-backend] https://review.tizen.org/gerrit/#/c/80787/ [wgt-backend] https://review.tizen.org/gerrit/#/c/81099/ Change-Id: Ifcbe6b0ceeb038d166ca924a576197299bcad8d9 Signed-off-by: Junghyun Yeon --- src/pkgmgr-server.c | 52 +++++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index b727ac8..69a6623 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -53,6 +53,8 @@ #define OWNER_ROOT 0 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) +#define APPFW_UID 301 + #define EXT_STORAGE_GROUP 10001 #define EXT_STORAGE_APPDATA_GROUP 10002 @@ -719,7 +721,7 @@ static int __fork_and_exec_with_args(char **argv, uid_t uid) user_context = get_user_context(uid); if (!user_context) { - DBG("Failed to getenv for the user : %d", uid); + DBG("Failed to getenv"); return -1; } @@ -801,12 +803,12 @@ static int __process_install(pm_dbus_msg *item) if (backend_cmd == NULL) return -1; - snprintf(args, sizeof(args), "%s -k %s -i %s %s", backend_cmd, - item->req_id, item->pkgid, item->args); + snprintf(args, sizeof(args), "%s -k %s -i %s -u %d %s", backend_cmd, + item->req_id, item->pkgid, (int)item->uid, item->args); argv = __generate_argv(args); - pid = __fork_and_exec_with_args(argv, item->uid); + pid = __fork_and_exec_with_args(argv, APPFW_UID); g_strfreev(argv); free(backend_cmd); @@ -824,12 +826,12 @@ static int __process_mount_install(pm_dbus_msg *item) if (backend_cmd == NULL) return -1; - snprintf(args, sizeof(args), "%s -k %s -w %s %s", backend_cmd, - item->req_id, item->pkgid, item->args); + snprintf(args, sizeof(args), "%s -k %s -w %s -u %d %s", backend_cmd, + item->req_id, item->pkgid, (int)item->uid, item->args); argv = __generate_argv(args); - pid = __fork_and_exec_with_args(argv, item->uid); + pid = __fork_and_exec_with_args(argv, APPFW_UID); g_strfreev(argv); free(backend_cmd); @@ -847,11 +849,11 @@ static int __process_reinstall(pm_dbus_msg *item) if (backend_cmd == NULL) return -1; - snprintf(args, sizeof(args), "%s -k %s -r %s", backend_cmd, - item->req_id, item->pkgid); + snprintf(args, sizeof(args), "%s -k %s -r %s -u %d", backend_cmd, + item->req_id, item->pkgid, (int)item->uid); argv = __generate_argv(args); - pid = __fork_and_exec_with_args(argv, item->uid); + pid = __fork_and_exec_with_args(argv, APPFW_UID); g_strfreev(argv); free(backend_cmd); @@ -870,11 +872,11 @@ static int __process_uninstall(pm_dbus_msg *item) if (backend_cmd == NULL) return -1; - snprintf(args, sizeof(args), "%s -k %s -d %s", backend_cmd, - item->req_id, item->pkgid); + snprintf(args, sizeof(args), "%s -k %s -d %s -u %d", backend_cmd, + item->req_id, item->pkgid, (int)item->uid); argv = __generate_argv(args); - pid = __fork_and_exec_with_args(argv, item->uid); + pid = __fork_and_exec_with_args(argv, APPFW_UID); g_strfreev(argv); free(backend_cmd); @@ -893,11 +895,11 @@ static int __process_move(pm_dbus_msg *item) if (backend_cmd == NULL) return -1; - snprintf(args, sizeof(args), "%s -k %s -m %s -t %s", backend_cmd, - item->req_id, item->pkgid, item->args); + snprintf(args, sizeof(args), "%s -k %s -m %s -u %d -t %s", backend_cmd, + item->req_id, item->pkgid, (int)item->uid, item->args); argv = __generate_argv(args); - pid = __fork_and_exec_with_args(argv, item->uid); + pid = __fork_and_exec_with_args(argv, APPFW_UID); g_strfreev(argv); free(backend_cmd); @@ -916,11 +918,11 @@ static int __process_enable_pkg(pm_dbus_msg *item) if (backend_cmd == NULL) return -1; - snprintf(args, sizeof(args), "%s -k %s -A %s", backend_cmd, - item->req_id, item->pkgid); + snprintf(args, sizeof(args), "%s -k %s -u %d -A %s", backend_cmd, + item->req_id, (int)item->uid, item->pkgid); argv = __generate_argv(args); - pid = __fork_and_exec_with_args(argv, item->uid); + pid = __fork_and_exec_with_args(argv, APPFW_UID); g_strfreev(argv); free(backend_cmd); @@ -939,11 +941,11 @@ static int __process_disable_pkg(pm_dbus_msg *item) if (backend_cmd == NULL) return -1; - snprintf(args, sizeof(args), "%s -k %s -D %s", backend_cmd, - item->req_id, item->pkgid); + snprintf(args, sizeof(args), "%s -k %s -u %d -D %s", backend_cmd, + item->req_id, (int)item->uid, item->pkgid); argv = __generate_argv(args); - pid = __fork_and_exec_with_args(argv, item->uid); + pid = __fork_and_exec_with_args(argv, APPFW_UID); g_strfreev(argv); free(backend_cmd); @@ -1116,11 +1118,11 @@ static int __process_cleardata(pm_dbus_msg *item) return -1; /* TODO: set movetype */ - snprintf(args, sizeof(args), "%s -k %s -c %s", backend_cmd, - item->req_id, item->pkgid); + snprintf(args, sizeof(args), "%s -k %s -c %s -u %d", backend_cmd, + item->req_id, item->pkgid, (int)item->uid); argv = __generate_argv(args); - pid = __fork_and_exec_with_args(argv, item->uid); + pid = __fork_and_exec_with_args(argv, APPFW_UID); g_strfreev(argv); free(backend_cmd); -- 2.7.4 From ffa535f58fe63d72dc9427a840727fee0d1bee9f Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 18 Aug 2016 08:01:17 +0900 Subject: [PATCH 04/16] Set list of supplementary groups IDs Change-Id: I3072df4d4e41a12ca8fedcc4b59d3c378ef3c39f Signed-off-by: Hwankyu Jhun --- src/pkgmgr-server.c | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) 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]) { -- 2.7.4 From 4e2567ece46d9dcb1322993e73da0d68020b5cf7 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Tue, 23 Aug 2016 14:36:56 +0900 Subject: [PATCH 05/16] Implement CSR checking routine Change-Id: Ida96780aef166ab47f3c9cd7f6f4212896923d8d Signed-off-by: Junghyun Yeon --- CMakeLists.txt | 1 + packaging/pkgmgr-server.spec | 1 + src/pkgmgr-server.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index accc292..ac0deb3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,7 @@ pkg_check_modules(SERVER_DEPS REQUIRED libgum sqlite3 pkgmgr + csr pkgmgr-installer) FOREACH(SERVER_FLAGS ${SERVER_DEPS_CFLAGS}) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SERVER_FLAGS}") diff --git a/packaging/pkgmgr-server.spec b/packaging/pkgmgr-server.spec index e2448fa..65ebcb1 100644 --- a/packaging/pkgmgr-server.spec +++ b/packaging/pkgmgr-server.spec @@ -25,6 +25,7 @@ BuildRequires: pkgconfig(pkgmgr-installer) BuildRequires: pkgconfig(drm-service-core-tizen) BuildRequires: pkgconfig(libgum) BuildRequires: pkgconfig(sqlite3) +BuildRequires: pkgconfig(csr) BuildRequires: pkgmgr-info-parser-devel BuildRequires: pkgmgr-info-parser BuildRequires: fdupes diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 22d15a8..1caa7d1 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -42,6 +42,7 @@ #include #include #include +#include #include "pkgmgr_installer.h" #include "pkgmgr-server.h" @@ -410,6 +411,35 @@ static int __pkgcmd_find_pid_by_cmdline(const char *dname, return pid; } +static int __check_csr(backend_info *ptr) +{ + csr_cs_context_h context = NULL; + csr_cs_malware_h detected = NULL; + int ret = -1; + + ret = csr_cs_context_create(&context); + if (ret != CSR_ERROR_NONE) { + ERR("Failed to create csr context"); + return -1; + } + + if (context) { + ret = csr_cs_scan_file(context, ptr->pkgid, &detected); + if (ret != CSR_ERROR_NONE) { + ERR("Failed to scan file[%d]", ret); + return -1; + } + + csr_cs_context_destroy(context); + if (detected != NULL) { + ERR("CSR Denied[%s] Installation", ptr->pkgid); + return -1; + } + } + + return 0; +} + static int __pkgcmd_proc_iter_kill_cmdline(const char *apppath, int option) { DIR *dp; @@ -1427,6 +1457,17 @@ gboolean queue_job(void *data) ptr->req_type = item->req_type; DBG("handle request type [%d]", item->req_type); + if (item->req_type == PKGMGR_REQUEST_TYPE_INSTALL || + item->req_type == PKGMGR_REQUEST_TYPE_MOUNT_INSTALL || + item->req_type == PKGMGR_REQUEST_TYPE_REINSTALL) { + ret = __check_csr(ptr); + if (ret != 0) { + ret = -1; + __send_fail_signal(ptr); + goto end; + } + } + switch (item->req_type) { case PKGMGR_REQUEST_TYPE_INSTALL: __set_backend_busy(x); @@ -1513,6 +1554,7 @@ gboolean queue_job(void *data) break; } +end: ptr->pid = ret; free(item); -- 2.7.4 From 0f06dba4ce99b3e89590c470232a279eccfab228 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Tue, 30 Aug 2016 09:58:19 +0900 Subject: [PATCH 06/16] Fix CSR routine to not to fail installation when engine is not exists Change-Id: I485108d8d62c5f1029bf646f6e73dda263f00a78 Signed-off-by: Junghyun Yeon --- src/pkgmgr-server.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 1caa7d1..021b327 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -417,7 +417,7 @@ static int __check_csr(backend_info *ptr) csr_cs_malware_h detected = NULL; int ret = -1; - ret = csr_cs_context_create(&context); + ret = csr_cs_context_create(&context); if (ret != CSR_ERROR_NONE) { ERR("Failed to create csr context"); return -1; @@ -425,10 +425,7 @@ static int __check_csr(backend_info *ptr) if (context) { ret = csr_cs_scan_file(context, ptr->pkgid, &detected); - if (ret != CSR_ERROR_NONE) { - ERR("Failed to scan file[%d]", ret); - return -1; - } + DBG("CSR result[%d]", ret); csr_cs_context_destroy(context); if (detected != NULL) { -- 2.7.4 From 4874b9682f11cf4c32c22a077e9a5cbfd8466a42 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Wed, 7 Sep 2016 19:18:07 +0900 Subject: [PATCH 07/16] remove csr routines in tv profile Change-Id: I0487e36776f510deb317cd80ee59d6c55fa4d764 Signed-off-by: Junghyun Yeon --- CMakeLists.txt | 23 +++++++++++------------ packaging/pkgmgr-server.spec | 14 ++++++++++++-- src/pkgmgr-server.c | 6 ++++++ 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ac0deb3..e4f7683 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,22 +32,21 @@ SET(SRCS src/restriction_mode.c ) -pkg_check_modules(SERVER_DEPS REQUIRED - gio-2.0 - dlog - pkgmgr-parser - pkgmgr-info - libtzplatform-config - drm-service-core-tizen - libgum - sqlite3 - pkgmgr - csr - pkgmgr-installer) +SET(SERVER_CHECK_MODULES gio-2.0 dlog pkgmgr-parser pkgmgr-info libtzplatform-config drm-service-core-tizen libgum sqlite3 pkgmgr pkgmgr-installer) +IF(TIZEN_FEATURE_CSR) + pkg_check_modules(SERVER_DEPS REQUIRED ${SERVER_CHECK_MODULES} csr) +ELSE(TIZEN_FEATURE_CSR) + pkg_check_modules(SERVER_DEPS REQUIRED ${SERVER_CHECK_MODULES}) +ENDIF(TIZEN_FEATURE_CSR) + FOREACH(SERVER_FLAGS ${SERVER_DEPS_CFLAGS}) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SERVER_FLAGS}") ENDFOREACH(SERVER_FLAGS) +IF(TIZEN_FEATURE_CSR) + ADD_DEFINITIONS("-DTIZEN_FEATURE_CSR") +ENDIF(TIZEN_FEATURE_CSR) + ADD_EXECUTABLE(${PKGMGR_SERVER} ${SRCS}) TARGET_LINK_LIBRARIES(${PKGMGR_SERVER} pkgmgr_installer) TARGET_LINK_LIBRARIES(${PKGMGR_SERVER} ${SERVER_DEPS_LDFLAGS}) diff --git a/packaging/pkgmgr-server.spec b/packaging/pkgmgr-server.spec index 65ebcb1..49f81b1 100644 --- a/packaging/pkgmgr-server.spec +++ b/packaging/pkgmgr-server.spec @@ -25,11 +25,14 @@ BuildRequires: pkgconfig(pkgmgr-installer) BuildRequires: pkgconfig(drm-service-core-tizen) BuildRequires: pkgconfig(libgum) BuildRequires: pkgconfig(sqlite3) -BuildRequires: pkgconfig(csr) BuildRequires: pkgmgr-info-parser-devel BuildRequires: pkgmgr-info-parser BuildRequires: fdupes +%if "%{?profile}" != "tv" +BuildRequires: pkgconfig(csr) +%endif + %description Packager Manager server package for packaging @@ -44,10 +47,17 @@ cp %{SOURCE1001} . %build sqlite3 restriction.db < ./restriction.sql +%if "%{?profile}" != "tv" +_TIZEN_FEATURE_CSR=ON +%else +_TIZEN_FEATURE_CSR=OFF +%endif + %cmake . -DRUN_DIR=%{run_dir} \ -DDB_DIR=%{db_dir} \ -DBACKEND_DIR=%{backend_dir} \ - -DUNITDIR=%{_unitdir} + -DUNITDIR=%{_unitdir} \ + -DTIZEN_FEATURE_CSR:BOOL=${_TIZEN_FEATURE_CSR} %__make %{?_smp_mflags} diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 021b327..15cd72c 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -42,7 +42,9 @@ #include #include #include +#ifdef TIZEN_FEATURE_CSR #include +#endif #include "pkgmgr_installer.h" #include "pkgmgr-server.h" @@ -411,6 +413,7 @@ static int __pkgcmd_find_pid_by_cmdline(const char *dname, return pid; } +#ifdef TIZEN_FEATURE_CSR static int __check_csr(backend_info *ptr) { csr_cs_context_h context = NULL; @@ -436,6 +439,7 @@ static int __check_csr(backend_info *ptr) return 0; } +#endif static int __pkgcmd_proc_iter_kill_cmdline(const char *apppath, int option) { @@ -1454,6 +1458,7 @@ gboolean queue_job(void *data) ptr->req_type = item->req_type; DBG("handle request type [%d]", item->req_type); +#ifdef TIZEN_FEATURE_CSR if (item->req_type == PKGMGR_REQUEST_TYPE_INSTALL || item->req_type == PKGMGR_REQUEST_TYPE_MOUNT_INSTALL || item->req_type == PKGMGR_REQUEST_TYPE_REINSTALL) { @@ -1464,6 +1469,7 @@ gboolean queue_job(void *data) goto end; } } +#endif switch (item->req_type) { case PKGMGR_REQUEST_TYPE_INSTALL: -- 2.7.4 From 7a2b123502d1a5e36bed7ff0ac96fc394a1586c0 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Wed, 7 Sep 2016 19:40:15 +0900 Subject: [PATCH 08/16] fix cmakelist Change-Id: Iedb7a27594e8b2bf2e354f1dce32acbbfd20b701 Signed-off-by: Junghyun Yeon --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e4f7683..aab4587 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,11 +34,11 @@ SET(SRCS SET(SERVER_CHECK_MODULES gio-2.0 dlog pkgmgr-parser pkgmgr-info libtzplatform-config drm-service-core-tizen libgum sqlite3 pkgmgr pkgmgr-installer) IF(TIZEN_FEATURE_CSR) - pkg_check_modules(SERVER_DEPS REQUIRED ${SERVER_CHECK_MODULES} csr) -ELSE(TIZEN_FEATURE_CSR) - pkg_check_modules(SERVER_DEPS REQUIRED ${SERVER_CHECK_MODULES}) + SET(SERVER_CHECK_MODULES "${SERVER_CHECK_MODULES} csr") ENDIF(TIZEN_FEATURE_CSR) +pkg_check_modules(SERVER_DEPS REQUIRED ${SERVER_CHECK_MODULES}) + FOREACH(SERVER_FLAGS ${SERVER_DEPS_CFLAGS}) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SERVER_FLAGS}") ENDFOREACH(SERVER_FLAGS) -- 2.7.4 From 02a73649f87abaa63b6ad893d3ea305ef5fa8770 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Tue, 13 Sep 2016 10:18:54 +0900 Subject: [PATCH 09/16] Fix sending app signal Send to signal agent too. Change-Id: Ifa2229c35ef5c9ce92938885892f2b78e3f65c52 Signed-off-by: Sangyoon Jang --- CMakeLists.txt | 3 +- include/pkgmgr-server.h | 4 ++ packaging/pkgmgr-server.spec | 1 + src/pkgmgr-server.c | 84 ---------------------- src/signal.c | 166 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 173 insertions(+), 85 deletions(-) create mode 100644 src/signal.c diff --git a/CMakeLists.txt b/CMakeLists.txt index aab4587..3abb01a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,9 +30,10 @@ SET(SRCS src/request.c src/pm-queue.c src/restriction_mode.c + src/signal.c ) -SET(SERVER_CHECK_MODULES gio-2.0 dlog pkgmgr-parser pkgmgr-info libtzplatform-config drm-service-core-tizen libgum sqlite3 pkgmgr pkgmgr-installer) +SET(SERVER_CHECK_MODULES gio-2.0 dlog pkgmgr-parser pkgmgr-info libtzplatform-config drm-service-core-tizen libgum sqlite3 pkgmgr pkgmgr-installer libsystemd) IF(TIZEN_FEATURE_CSR) SET(SERVER_CHECK_MODULES "${SERVER_CHECK_MODULES} csr") ENDIF(TIZEN_FEATURE_CSR) diff --git a/include/pkgmgr-server.h b/include/pkgmgr-server.h index 0c8b9dc..13efc58 100644 --- a/include/pkgmgr-server.h +++ b/include/pkgmgr-server.h @@ -109,6 +109,10 @@ gboolean queue_job(void *data); int __return_value_to_caller(const char *req_key, GVariant *result); int __init_request_handler(void); void __fini_request_handler(void); +void __send_app_signal(uid_t uid, const char *req_id, + const char *pkgid, const char *appid, + const char *key, const char *val, int req_type); +void __send_fail_signal(backend_info *info); int _restriction_mode_set(uid_t uid, const char *pkgid, int mode); int _restriction_mode_unset(uid_t uid, const char *pkgid, int mode); int _restriction_mode_get(uid_t uid, const char *pkgid, int *mode); diff --git a/packaging/pkgmgr-server.spec b/packaging/pkgmgr-server.spec index 49f81b1..dbb360f 100644 --- a/packaging/pkgmgr-server.spec +++ b/packaging/pkgmgr-server.spec @@ -25,6 +25,7 @@ BuildRequires: pkgconfig(pkgmgr-installer) BuildRequires: pkgconfig(drm-service-core-tizen) BuildRequires: pkgconfig(libgum) BuildRequires: pkgconfig(sqlite3) +BuildRequires: pkgconfig(libsystemd) BuildRequires: pkgmgr-info-parser-devel BuildRequires: pkgmgr-info-parser BuildRequires: fdupes diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 15cd72c..061c2b8 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -133,90 +133,6 @@ static void __set_backend_free(int position) backend_busy = backend_busy & ~(1<req_id); - switch (info->req_type) { - case PKGMGR_REQUEST_TYPE_INSTALL: - case PKGMGR_REQUEST_TYPE_MOUNT_INSTALL: - case PKGMGR_REQUEST_TYPE_REINSTALL: - req_type = PKGMGR_REQ_INSTALL; - break; - case PKGMGR_REQUEST_TYPE_UNINSTALL: - req_type = PKGMGR_REQ_UNINSTALL; - break; - case PKGMGR_REQUEST_TYPE_MOVE: - req_type = PKGMGR_REQ_MOVE; - break; - case PKGMGR_REQUEST_TYPE_GETSIZE: - req_type = PKGMGR_REQ_GETSIZE; - break; - default: - req_type = PKGMGR_REQ_INVALID; - break; - } - pkgmgr_installer_set_request_type(pi, req_type); - pkgmgr_installer_send_signal(pi, info->pkgtype, info->pkgid, "end", "fail"); - pkgmgr_installer_free(pi); - return; -} - static gboolean pipe_io_handler(GIOChannel *io, GIOCondition cond, gpointer data) { int x; diff --git a/src/signal.c b/src/signal.c new file mode 100644 index 0000000..536f8b3 --- /dev/null +++ b/src/signal.c @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include + +#include + +#include +#include + +#include "pkgmgr-server.h" + +#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) + +static int __get_uid_list(uid_t target_uid, uid_t **uids) +{ + int n; + + if (target_uid != GLOBAL_USER) { + *uids = malloc(sizeof(uid_t)); + if (*uids == NULL) { + ERR("out of memory"); + return 0; + } + (*uids)[0] = target_uid; + n = 1; + } else { + n = sd_get_uids(uids); + if (n < 0) { + ERR("cannot get login user list"); + return 0; + } + } + + return n; +} + +static void __free_uid_list(uid_t *uids) +{ + free(uids); +} + +void __send_app_signal(uid_t uid, const char *req_id, + const char *pkgid, const char *appid, + const char *key, const char *val, int req_type) +{ + pkgmgr_installer *pi; + uid_t *uids = NULL; + int n; + int i; + + pi = pkgmgr_installer_new(); + if (!pi) { + DBG("Failure in creating the pkgmgr_installer object"); + return; + } + + if (pkgmgr_installer_set_uid(pi, uid)) + goto catch; + + switch (req_type) { + case PKGMGR_REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID: + case PKGMGR_REQUEST_TYPE_ENABLE_APP: + if (pkgmgr_installer_set_request_type(pi, + PKGMGR_REQ_ENABLE_APP)) + goto catch; + break; + case PKGMGR_REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID: + case PKGMGR_REQUEST_TYPE_DISABLE_APP: + if (pkgmgr_installer_set_request_type(pi, + PKGMGR_REQ_DISABLE_APP)) + goto catch; + break; + case PKGMGR_REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN: + if (pkgmgr_installer_set_request_type(pi, + PKGMGR_REQ_ENABLE_APP_SPLASH_SCREEN)) + goto catch; + break; + case PKGMGR_REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN: + if (pkgmgr_installer_set_request_type(pi, + PKGMGR_REQ_DISABLE_APP_SPLASH_SCREEN)) + goto catch; + break; + default: + DBG("Unsupported req_type[%d]", req_type); + goto catch; + } + + if (pkgmgr_installer_set_session_id(pi, req_id)) + goto catch; + pkgmgr_installer_send_app_signal(pi, "app", pkgid, appid, key, val); + n = __get_uid_list(uid, &uids); + for (i = 0; i < n; i++) + pkgmgr_installer_send_app_signal_for_uid(pi, uids[i], "app", + pkgid, appid, key, val); + +catch: + __free_uid_list(uids); + pkgmgr_installer_free(pi); + + return; +} + +void __send_fail_signal(backend_info *info) +{ + int req_type; + pkgmgr_installer *pi; + uid_t *uids = NULL; + int n; + int i; + + pi = pkgmgr_installer_new(); + if (!pi) { + ERR("Failure in creating the pkgmgr_installer object"); + return; + } + pkgmgr_installer_set_session_id(pi, info->req_id); + switch (info->req_type) { + case PKGMGR_REQUEST_TYPE_INSTALL: + case PKGMGR_REQUEST_TYPE_MOUNT_INSTALL: + case PKGMGR_REQUEST_TYPE_REINSTALL: + req_type = PKGMGR_REQ_INSTALL; + break; + case PKGMGR_REQUEST_TYPE_UNINSTALL: + req_type = PKGMGR_REQ_UNINSTALL; + break; + case PKGMGR_REQUEST_TYPE_MOVE: + req_type = PKGMGR_REQ_MOVE; + break; + case PKGMGR_REQUEST_TYPE_GETSIZE: + req_type = PKGMGR_REQ_GETSIZE; + break; + default: + req_type = PKGMGR_REQ_INVALID; + break; + } + pkgmgr_installer_set_request_type(pi, req_type); + pkgmgr_installer_send_signal(pi, info->pkgtype, info->pkgid, + "end", "fail"); + n = __get_uid_list(info->uid, &uids); + for (i = 0; i < n; i++) + pkgmgr_installer_send_signal_for_uid(pi, uids[i], + info->pkgtype, info->pkgid, "end", "fail"); + + __free_uid_list(uids); + pkgmgr_installer_free(pi); + return; +} + + -- 2.7.4 From 2bfbc09eb9a2e8a2162e91c2ae6fdc4cbce8d71c Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Tue, 13 Sep 2016 10:37:47 +0900 Subject: [PATCH 10/16] Get actucal pkgid first and then send signal For sending pkgid, appid pair correctly, get pkgid from appid first. Change-Id: I72f682b2e519ebd96d5d812d3fb05256a2eb0277 Signed-off-by: Sangyoon Jang --- src/pkgmgr-server.c | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 061c2b8..505c874 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -923,19 +923,22 @@ static int __process_enable_app(pm_dbus_msg *item) int ret = -1; bool is_global = false; - __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, - PKGMGR_INSTALLER_START_KEY_STR, - PKGMGR_INSTALLER_APP_ENABLE_EVENT_STR, item->req_type); - /* get actual pkgid and replace it to appid which is currently stored at pkgid variable */ ret = __change_item_info(item, item->uid, &is_global); if (ret != PMINFO_R_OK || strlen(item->appid) == 0) { __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, + PKGMGR_INSTALLER_START_KEY_STR, + PKGMGR_INSTALLER_APP_ENABLE_EVENT_STR, item->req_type); + __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, item->req_type); return ret; } + __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, + PKGMGR_INSTALLER_START_KEY_STR, + PKGMGR_INSTALLER_APP_ENABLE_EVENT_STR, item->req_type); + ret = pkgmgr_parser_update_app_disable_info_in_usr_db(item->appid, item->uid, 0); if (ret != PMINFO_R_OK) __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, @@ -955,19 +958,22 @@ static int __process_disable_app(pm_dbus_msg *item) int ret = -1; bool is_global = false; - __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, - PKGMGR_INSTALLER_START_KEY_STR, - PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR, item->req_type); - /* get actual pkgid and replace it to appid which is currently stored at pkgid variable */ ret = __change_item_info(item, item->uid, &is_global); if (ret != PMINFO_R_OK || strlen(item->appid) == 0) { __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, + PKGMGR_INSTALLER_START_KEY_STR, + PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR, item->req_type); + __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, item->req_type); return ret; } + __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, + PKGMGR_INSTALLER_START_KEY_STR, + PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR, item->req_type); + ret = __kill_app(item->appid, item->uid); if (ret != PMINFO_R_OK) { __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, @@ -993,19 +999,22 @@ static int __process_enable_global_app_for_uid(pm_dbus_msg *item) int ret = -1; bool is_global = true; - __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, - PKGMGR_INSTALLER_START_KEY_STR, - PKGMGR_INSTALLER_GLOBAL_APP_ENABLE_FOR_UID, item->req_type); - /* get actual pkgid and replace it to appid which is currently stored at pkgid variable */ ret = __change_item_info(item, item->uid, &is_global); if (ret != PMINFO_R_OK || strlen(item->appid) == 0) { __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, + PKGMGR_INSTALLER_START_KEY_STR, + PKGMGR_INSTALLER_GLOBAL_APP_ENABLE_FOR_UID, item->req_type); + __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, item->req_type); return ret; } + __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, + PKGMGR_INSTALLER_START_KEY_STR, + PKGMGR_INSTALLER_GLOBAL_APP_ENABLE_FOR_UID, item->req_type); + ret = pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(item->appid, item->uid, 0); if (ret != PMINFO_R_OK) __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, @@ -1024,20 +1033,24 @@ static int __process_disable_global_app_for_uid(pm_dbus_msg *item) int ret = -1; bool is_global = true; - __send_app_signal(item->uid, item->req_id, - item->pkgid, item->pkgid, - PKGMGR_INSTALLER_START_KEY_STR, - PKGMGR_INSTALLER_GLOBAL_APP_DISABLE_FOR_UID, item->req_type); - /* get actual pkgid and replace it to appid which is currently stored at pkgid variable */ ret = __change_item_info(item, GLOBAL_USER, &is_global); if (ret != PMINFO_R_OK || strlen(item->appid) == 0) { + __send_app_signal(item->uid, item->req_id, + item->pkgid, item->pkgid, + PKGMGR_INSTALLER_START_KEY_STR, + PKGMGR_INSTALLER_GLOBAL_APP_DISABLE_FOR_UID, item->req_type); __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, item->req_type); return ret; } + __send_app_signal(item->uid, item->req_id, + item->pkgid, item->appid, + PKGMGR_INSTALLER_START_KEY_STR, + PKGMGR_INSTALLER_GLOBAL_APP_DISABLE_FOR_UID, item->req_type); + ret = __kill_app(item->appid, item->uid); ret = pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(item->appid, item->uid, 1); -- 2.7.4 From 03519278ee430b3e6acca68b59717b29d4352e5c Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Tue, 27 Sep 2016 11:27:43 +0900 Subject: [PATCH 11/16] suppess build warning on the profile which doesn't support CSR feature. Change-Id: I2a22e1002e417abdb7b03c43e794e830b14bbbbf Signed-off-by: jongmyeongko --- src/pkgmgr-server.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 505c874..64b87bc 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -1486,7 +1486,9 @@ gboolean queue_job(void *data) break; } +#ifdef TIZEN_FEATURE_CSR end: +#endif ptr->pid = ret; free(item); -- 2.7.4 From 8f546e002cd0cebe75656c670c36760cec05aaa2 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Tue, 27 Sep 2016 08:23:31 +0900 Subject: [PATCH 12/16] Set busy status flag on pkg enable/disable Change-Id: Ia27ff96bd2deec12162243a339d286fc9fa93335 Signed-off-by: Junghyun Yeon --- src/pkgmgr-server.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 64b87bc..6ef1661 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -1422,9 +1422,11 @@ gboolean queue_job(void *data) ret = __process_move(item); break; case PKGMGR_REQUEST_TYPE_ENABLE_PKG: + __set_backend_busy(x); ret = __process_enable_pkg(item); break; case PKGMGR_REQUEST_TYPE_DISABLE_PKG: + __set_backend_busy(x); ret = __process_disable_pkg(item); break; case PKGMGR_REQUEST_TYPE_ENABLE_APP: -- 2.7.4 From 6db02013234ecaa4e98423da805c96e6a86b8674 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Mon, 10 Oct 2016 23:35:34 +0900 Subject: [PATCH 13/16] fix wrong behavior of pkg_getsize - set uid/gid for pkg_getsize Change-Id: I57c33ae74d33148350520776d34db24bcc5ba6c9 Signed-off-by: jongmyeongko --- src/pkgmgr-server.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 6ef1661..764894a 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -533,6 +533,18 @@ int set_environement(user_ctx *ctx) if (!ctx) return -1; + if (ctx->uid != APPFW_UID) { + if (setuid(ctx->uid)) { + ERR("setuid failed: %d", errno); + 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"); -- 2.7.4 From 4257da53934d4d6e1f0780d81d5c0bb748698692 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Wed, 12 Oct 2016 13:52:00 +0900 Subject: [PATCH 14/16] Kill app using aul api instead of proc filesystem Change-Id: Ic48077821e5c81b378510deba30ecf0741b5e310 Signed-off-by: Sangyoon Jang --- CMakeLists.txt | 2 +- packaging/pkgmgr-server.spec | 1 + src/pkgmgr-server.c | 152 +++++++++++++------------------------------ 3 files changed, 46 insertions(+), 109 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3abb01a..3c76497 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ SET(SRCS src/signal.c ) -SET(SERVER_CHECK_MODULES gio-2.0 dlog pkgmgr-parser pkgmgr-info libtzplatform-config drm-service-core-tizen libgum sqlite3 pkgmgr pkgmgr-installer libsystemd) +SET(SERVER_CHECK_MODULES gio-2.0 dlog pkgmgr-parser pkgmgr-info libtzplatform-config drm-service-core-tizen libgum sqlite3 pkgmgr pkgmgr-installer libsystemd aul) IF(TIZEN_FEATURE_CSR) SET(SERVER_CHECK_MODULES "${SERVER_CHECK_MODULES} csr") ENDIF(TIZEN_FEATURE_CSR) diff --git a/packaging/pkgmgr-server.spec b/packaging/pkgmgr-server.spec index dbb360f..ef78063 100644 --- a/packaging/pkgmgr-server.spec +++ b/packaging/pkgmgr-server.spec @@ -13,6 +13,7 @@ BuildRequires: pkgconfig(dbus-glib-1) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(aul) BuildRequires: pkgconfig(bundle) BuildRequires: pkgconfig(pkgmgr-info) BuildRequires: pkgconfig(iniparser) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 764894a..2abd40f 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -38,6 +37,7 @@ #include #include +#include #include #include #include @@ -291,44 +291,6 @@ gboolean exit_server(void *data) return TRUE; } -static int __pkgcmd_read_proc(const char *path, char *buf, int size) -{ - int fd; - int ret; - if (buf == NULL || path == NULL) - return -1; - fd = open(path, O_RDONLY); - if (fd < 0) - return -1; - ret = read(fd, buf, size - 1); - if (ret <= 0) { - close(fd); - return -1; - } else - buf[ret] = 0; - close(fd); - return ret; -} - -static int __pkgcmd_find_pid_by_cmdline(const char *dname, - const char *cmdline, const char *apppath) -{ - int pid = 0; - int pgid = 0; - - if (strcmp(cmdline, apppath) == 0) { - pid = atoi(dname); - pgid = getpgid(pid); - if (pgid < 0) { - ERR("getpgid failed, errno(%d)", errno); - pid = 0; - } - if (pid != pgid) - pid = 0; - } - return pid; -} - #ifdef TIZEN_FEATURE_CSR static int __check_csr(backend_info *ptr) { @@ -357,55 +319,6 @@ static int __check_csr(backend_info *ptr) } #endif -static int __pkgcmd_proc_iter_kill_cmdline(const char *apppath, int option) -{ - DIR *dp; - struct dirent dentry, *result; - int pid; - int ret; - char buf[1024] = {'\0'}; - int pgid; - - dp = opendir("/proc"); - if (dp == NULL) - return -1; - - for (ret = readdir_r(dp, &dentry, &result); - ret == 0 && result != NULL; - ret = readdir_r(dp, &dentry, &result)) { - if (!isdigit(dentry.d_name[0])) - continue; - - snprintf(buf, sizeof(buf), "/proc/%s/cmdline", dentry.d_name); - ret = __pkgcmd_read_proc(buf, buf, sizeof(buf)); - if (ret <= 0) - continue; - - pid = __pkgcmd_find_pid_by_cmdline(dentry.d_name, buf, apppath); - if (pid > 0) { - if (option == 0) { - closedir(dp); - return pid; - } - pgid = getpgid(pid); - if (pgid <= 1) { - closedir(dp); - ERR("getpgid failed, errno(%d)", errno); - return -1; - } - if (killpg(pgid, SIGKILL) < 0) { - closedir(dp); - ERR("killpg failed, errno(%d)", errno); - return -1; - } - closedir(dp); - return pid; - } - } - closedir(dp); - return 0; -} - static void __make_pid_info_file(char *req_key, int pid, uid_t uid) { FILE* file; @@ -450,31 +363,46 @@ static void __make_pid_info_file(char *req_key, int pid, uid_t uid) static int __kill_app(char *appid, uid_t uid) { - pkgmgrinfo_appinfo_h appinfo; - int ret = PMINFO_R_ERROR; - char *exec = NULL; + int ret; + int pid; + int is_running; - ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid, &appinfo); - if (ret != PMINFO_R_OK) - return PMINFO_R_ERROR; + is_running = aul_app_is_running_for_uid(appid, uid); + /* app is not running */ + if (!is_running) + return 0; - ret = pkgmgrinfo_appinfo_get_exec(appinfo, &exec); - if (ret != PMINFO_R_OK) { - pkgmgrinfo_appinfo_destroy_appinfo(appinfo); - return PMINFO_R_ERROR; + pid = aul_app_get_pid_for_uid(appid, uid); + if (pid == -1) + return -1; + + ret = aul_terminate_pid_for_uid(pid, uid); + if (ret != AUL_R_OK) { + ERR("failed to terminate app(%d)", appid); + return -1; } - ret = __pkgcmd_proc_iter_kill_cmdline(exec, 1); - if (ret != PMINFO_R_OK) - DBG("failed to kill app[%s], exec[%s]", appid, exec); + return 0; +} - pkgmgrinfo_appinfo_destroy_appinfo(appinfo); - return ret; +static int __check_app(char *appid, uid_t uid) +{ + int pid; + int is_running; + + is_running = aul_app_is_running_for_uid(appid, uid); + if (!is_running) + return 0; + + pid = aul_app_get_pid_for_uid(appid, uid); + + return pid; } static int __pkgcmd_app_cb(const pkgmgrinfo_appinfo_h handle, void *user_data) { char *pkgid; + char *appid; char *exec; int ret; int pid = -1; @@ -489,16 +417,24 @@ static int __pkgcmd_app_cb(const pkgmgrinfo_appinfo_h handle, void *user_data) perror("Failed to get app exec path\n"); exit(1); } + ret = pkgmgrinfo_appinfo_get_appid(handle, &appid); + if (ret) { + perror("Failed to get appid\n"); + exit(1); + } ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid); if (ret) { perror("Failed to get pkgid\n"); exit(1); } - if (strcmp(pdata->cmd, "kill") == 0) - pid = __pkgcmd_proc_iter_kill_cmdline(exec, 1); - else if (strcmp(pdata->cmd, "check") == 0) - pid = __pkgcmd_proc_iter_kill_cmdline(exec, 0); + if (strcmp(pdata->cmd, "kill") == 0) { + pid = __check_app(appid, pdata->uid); + if (pid > 0) + ret = __kill_app(appid, pdata->uid); + } else if (strcmp(pdata->cmd, "check") == 0) { + pid = __check_app(appid, pdata->uid); + } __make_pid_info_file(pkgid, pid, pdata->uid); @@ -987,7 +923,7 @@ static int __process_disable_app(pm_dbus_msg *item) PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR, item->req_type); ret = __kill_app(item->appid, item->uid); - if (ret != PMINFO_R_OK) { + if (ret != 0) { __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, item->req_type); -- 2.7.4 From b3314aa160c433ec64c3f15dfb3b515f4f72e2d2 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Wed, 12 Oct 2016 15:22:55 +0900 Subject: [PATCH 15/16] Fix returning error to client Return ENOMEM when memory allocation failed. Change-Id: I4b4c0b8777c9f8a18fc1c1955e923d7ee3f290c1 Signed-off-by: Sangyoon Jang --- src/request.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 9 deletions(-) diff --git a/src/request.c b/src/request.c index 8f5e3f1..d4d049f 100644 --- a/src/request.c +++ b/src/request.c @@ -283,7 +283,9 @@ static int __handle_request_install(uid_t uid, args = (char *)calloc(len, sizeof(char)); if (args == NULL) { ERR("calloc failed"); - ret = -1; + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); + ret = -1; goto catch; } @@ -309,6 +311,8 @@ static int __handle_request_install(uid_t uid, reqkey = __generate_reqkey(pkgpath); if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); ret = -1; goto catch; } @@ -360,7 +364,9 @@ static int __handle_request_mount_install(uid_t uid, args = (char *)calloc(len, sizeof(char)); if (args == NULL) { ERR("calloc failed"); - ret = -1; + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); + ret = -1; goto catch; } @@ -386,6 +392,8 @@ static int __handle_request_mount_install(uid_t uid, reqkey = __generate_reqkey(pkgpath); if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); ret = -1; goto catch; } @@ -428,8 +436,11 @@ static int __handle_request_reinstall(uid_t uid, } reqkey = __generate_reqkey(pkgid); - if (reqkey == NULL) + if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); return -1; + } if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_REINSTALL, pkgtype, pkgid, "")) { g_dbus_method_invocation_return_value(invocation, @@ -461,8 +472,11 @@ static int __handle_request_uninstall(uid_t uid, } reqkey = __generate_reqkey(pkgid); - if (reqkey == NULL) + if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); return -1; + } if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_UNINSTALL, pkgtype, pkgid, "")) { g_dbus_method_invocation_return_value(invocation, @@ -496,8 +510,11 @@ static int __handle_request_move(uid_t uid, } reqkey = __generate_reqkey(pkgid); - if (reqkey == NULL) + if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); return -1; + } snprintf(buf, sizeof(buf), "%d", move_type); if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_MOVE, pkgtype, @@ -531,8 +548,11 @@ static int __handle_request_enable_pkg(uid_t uid, } reqkey = __generate_reqkey(pkgid); - if (reqkey == NULL) + if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(i)", PKGMGR_R_ENOMEM)); return -1; + } if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_ENABLE_PKG, pkgtype, pkgid, "")) { @@ -565,8 +585,11 @@ static int __handle_request_disable_pkg(uid_t uid, } reqkey = __generate_reqkey(pkgid); - if (reqkey == NULL) + if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(i)", PKGMGR_R_ENOMEM)); return -1; + } if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_DISABLE_PKG, pkgtype, pkgid, "")) { @@ -600,6 +623,8 @@ static int __handle_request_enable_app(uid_t uid, reqkey = __generate_reqkey(appid); if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); ret = -1; goto catch; } @@ -641,6 +666,8 @@ static int __handle_request_disable_app(uid_t uid, reqkey = __generate_reqkey(appid); if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); ret = -1; goto catch; } @@ -682,6 +709,8 @@ static int __handle_request_enable_global_app_for_uid(uid_t uid, reqkey = __generate_reqkey(appid); if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); ret = -1; goto catch; } @@ -723,6 +752,8 @@ static int __handle_request_disable_global_app_for_uid(uid_t uid, reqkey = __generate_reqkey(appid); if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); ret = -1; goto catch; } @@ -764,8 +795,11 @@ static int __handle_request_getsize(uid_t uid, } reqkey = __generate_reqkey(pkgid); - if (reqkey == NULL) + if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); return -1; + } snprintf(buf, sizeof(buf), "%d", get_type); if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_GETSIZE, "pkgtool", @@ -799,8 +833,11 @@ static int __handle_request_cleardata(uid_t uid, } reqkey = __generate_reqkey(pkgid); - if (reqkey == NULL) + if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(i)", PKGMGR_R_ENOMEM)); return -1; + } if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_CLEARDATA, pkgtype, pkgid, "")) { @@ -1025,6 +1062,8 @@ static int __update_app_splash_screen(uid_t uid, reqkey = __generate_reqkey(appid); if (reqkey == NULL) { ERR("Failed to generate request key"); + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(i)", PKGMGR_R_ENOMEM)); return -1; } -- 2.7.4 From 88951b80bdcf1bd17292dfc3e24851f0c7aeddfc Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Wed, 12 Oct 2016 15:25:08 +0900 Subject: [PATCH 16/16] Return kill/check result directly instead of writing on tmp file Submit together: - https://review.tizen.org/gerrit/91895 - https://review.tizen.org/gerrit/91896 Change-Id: I6d32d1f8fe93a8cbfb13429f34560024ac074549 Signed-off-by: Sangyoon Jang --- src/pkgmgr-server.c | 81 +++++++++++++++++------------------------------------ src/request.c | 44 +++++++++++++++++++++-------- 2 files changed, 58 insertions(+), 67 deletions(-) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 2abd40f..0986995 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -30,7 +30,6 @@ #include #include #include -#include #include #include @@ -73,6 +72,7 @@ typedef struct { typedef struct { uid_t uid; char *cmd; + int pid; } pkgcmd_data; /* @@ -319,48 +319,6 @@ static int __check_csr(backend_info *ptr) } #endif -static void __make_pid_info_file(char *req_key, int pid, uid_t uid) -{ - FILE* file; - int fd; - int ret; - char buf[MAX_PKG_TYPE_LEN] = {0}; - char info_file[PATH_MAX] = {'\0'}; - struct passwd pwd; - struct passwd *pwd_result; - - if (req_key == NULL) - return; - - ret = getpwuid_r(uid, &pwd, buf, sizeof(buf), &pwd_result); - if (ret != 0 || pwd_result == NULL) { - ERR("get uid failed(%d) for user(%d)", ret, uid); - return; - } - DBG("uid(%d), gid(%d)", uid, pwd.pw_gid); - - snprintf(info_file, PATH_MAX, "/tmp/pkgmgr/%s", req_key); - - DBG("info_path(%s)", info_file); - file = fopen(info_file, "w"); - if (file == NULL) { - ERR("Couldn't open the file(%s)", info_file); - return; - } - - snprintf(buf, MAX_PKG_TYPE_LEN, "%d\n", pid); - fwrite(buf, 1, strlen(buf), file); - - fflush(file); - fd = fileno(file); - if (fchmod(fd, 0777) < 0) - ERR("chmod failed, errno(%d)", errno); - if (fchown(fd, uid, pwd.pw_gid) < 0) - ERR("chown failed, errno(%d)", errno); - fsync(fd); - fclose(file); -} - static int __kill_app(char *appid, uid_t uid) { int ret; @@ -405,7 +363,6 @@ static int __pkgcmd_app_cb(const pkgmgrinfo_appinfo_h handle, void *user_data) char *appid; char *exec; int ret; - int pid = -1; pkgcmd_data *pdata = (pkgcmd_data *)user_data; if (handle == NULL) { @@ -429,15 +386,13 @@ static int __pkgcmd_app_cb(const pkgmgrinfo_appinfo_h handle, void *user_data) } if (strcmp(pdata->cmd, "kill") == 0) { - pid = __check_app(appid, pdata->uid); - if (pid > 0) + pdata->pid = __check_app(appid, pdata->uid); + if (pdata->pid > 0) ret = __kill_app(appid, pdata->uid); } else if (strcmp(pdata->cmd, "check") == 0) { - pid = __check_app(appid, pdata->uid); + pdata->pid = __check_app(appid, pdata->uid); } - __make_pid_info_file(pkgid, pid, pdata->uid); - return 0; } @@ -1076,33 +1031,41 @@ static int __process_kill(pm_dbus_msg *item) { int ret; pkgmgrinfo_pkginfo_h handle; - pkgcmd_data *pdata = NULL; + pkgcmd_data *pdata; ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(item->pkgid, item->uid, &handle); if (ret < 0) { ERR("Failed to get handle"); + __return_value_to_caller(item->req_id, + g_variant_new("(ii)", PKGMGR_R_ERROR, 0)); return -1; } pdata = calloc(1, sizeof(pkgcmd_data)); if (pdata == NULL) { ERR("memory alloc failed"); + __return_value_to_caller(item->req_id, + g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0)); return -1; } pdata->cmd = strdup("kill"); if (pdata->cmd == NULL) { ERR("out of memory"); + __return_value_to_caller(item->req_id, + g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0)); free(pdata); - pdata = NULL; return -1; } pdata->uid = item->uid; ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP, __pkgcmd_app_cb, pdata, item->uid); + + __return_value_to_caller(item->req_id, + g_variant_new("(ii)", PKGMGR_R_OK, pdata->pid)); + free(pdata->cmd); free(pdata); - pdata = NULL; pkgmgrinfo_pkginfo_destroy_pkginfo(handle); if (ret < 0) { ERR("pkgmgrinfo_appinfo_get_list() failed"); @@ -1116,33 +1079,41 @@ static int __process_check(pm_dbus_msg *item) { int ret; pkgmgrinfo_pkginfo_h handle; - pkgcmd_data *pdata = NULL; + pkgcmd_data *pdata; ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(item->pkgid, item->uid, &handle); if (ret < 0) { ERR("Failed to get handle"); + __return_value_to_caller(item->req_id, + g_variant_new("(ii)", PKGMGR_R_ERROR, 0)); return -1; } pdata = calloc(1, sizeof(pkgcmd_data)); if (pdata == NULL) { ERR("memory alloc failed"); + __return_value_to_caller(item->req_id, + g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0)); return -1; } pdata->cmd = strdup("check"); if (pdata->cmd == NULL) { ERR("out of memory"); + __return_value_to_caller(item->req_id, + g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0)); free(pdata); - pdata = NULL; return -1; } pdata->uid = item->uid; ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP, __pkgcmd_app_cb, pdata, item->uid); + + __return_value_to_caller(item->req_id, + g_variant_new("(ii)", PKGMGR_R_OK, pdata->pid)); + free(pdata->cmd); free(pdata); - pdata = NULL; pkgmgrinfo_pkginfo_destroy_pkginfo(handle); if (ret < 0) { ERR("pkgmgrinfo_appinfo_get_list() failed"); diff --git a/src/request.c b/src/request.c index d4d049f..e269030 100644 --- a/src/request.c +++ b/src/request.c @@ -113,11 +113,13 @@ static const char instropection_xml[] = " " " " " " + " " " " " " " " " " " " + " " " " " " " " @@ -886,23 +888,32 @@ static int __handle_request_kill(uid_t uid, { uid_t target_uid = (uid_t)-1; char *pkgid = NULL; + char *reqkey = NULL; g_variant_get(parameters, "(u&s)", &target_uid, &pkgid); if (target_uid == (uid_t)-1 || pkgid == NULL) { g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ECOMM)); + g_variant_new("(ii)", PKGMGR_R_ECOMM, 0)); return -1; } - if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_KILL, "default", - pkgid, "")) { + reqkey = __generate_reqkey(pkgid); + if (reqkey == NULL) { g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ESYSTEM)); + g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0)); return -1; } - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_OK)); + if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_KILL, + "default", pkgid, "")) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(ii)", PKGMGR_R_ESYSTEM, 0)); + return -1; + } + + if (!g_hash_table_insert(req_table, (gpointer)reqkey, + (gpointer)invocation)) + ERR("reqkey already exists"); return 0; } @@ -912,23 +923,32 @@ static int __handle_request_check(uid_t uid, { uid_t target_uid = (uid_t)-1; char *pkgid = NULL; + char *reqkey = NULL; g_variant_get(parameters, "(u&s)", &target_uid, &pkgid); if (target_uid == (uid_t)-1 || pkgid == NULL) { g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ECOMM)); + g_variant_new("(ii)", PKGMGR_R_ECOMM, 0)); return -1; } - if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_CHECK, "default", - pkgid, "")) { + reqkey = __generate_reqkey(pkgid); + if (reqkey == NULL) { g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ESYSTEM)); + g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0)); return -1; } - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_OK)); + if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_CHECK, + "default", pkgid, "")) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(ii)", PKGMGR_R_ESYSTEM, 0)); + return -1; + } + + if (!g_hash_table_insert(req_table, (gpointer)reqkey, + (gpointer)invocation)) + ERR("reqkey already exists"); return 0; } -- 2.7.4