From d2615838721b67d0f0a50eebf704da5efad12d54 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Sat, 12 Mar 2016 13:42:05 +0900 Subject: [PATCH 01/16] suppress build warnings Change-Id: I725ef47c4da3fa80f3c9ce618d6cb21b99572260 Signed-off-by: Junghyun Yeon --- src/pkgmgr-server.c | 2 +- src/request.c | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 65a6ccb..f375160 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -38,7 +38,7 @@ #include #include -#include +#include #include #include diff --git a/src/request.c b/src/request.c index 79ff721..a818550 100644 --- a/src/request.c +++ b/src/request.c @@ -177,7 +177,6 @@ static int __handle_request_install(uid_t uid, gsize args_count; int ret = -1; GVariant *value; - gchar *str; int i = 0; int len = 0; -- 2.7.4 From 04d1633c43e924ee44c332bf2db88f6ab0d43f28 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Mon, 14 Mar 2016 14:54:03 +0900 Subject: [PATCH 02/16] fix to check given app handle is from global db or not Change-Id: I789427820696a1d5bd87cc1017a5fa206d7d7189 Signed-off-by: Junghyun Yeon --- src/pkgmgr-server.c | 52 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index f375160..5726ccd 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -730,41 +730,59 @@ static int __fork_and_exec_with_args(char **argv, uid_t uid) return pid; } -void __change_item_info(pm_dbus_msg *item, uid_t uid) +static int __change_item_info(pm_dbus_msg *item, uid_t uid) { int ret = 0; char *pkgid = NULL; + bool is_global = false; pkgmgrinfo_appinfo_h handle = NULL; switch (item->req_type) { case PKGMGR_REQUEST_TYPE_DISABLE_APP: case PKGMGR_REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID: ret = pkgmgrinfo_appinfo_get_usr_appinfo(item->pkgid, uid, &handle); - break; + break; case PKGMGR_REQUEST_TYPE_ENABLE_APP: case PKGMGR_REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID: ret = pkgmgrinfo_appinfo_get_usr_disabled_appinfo(item->pkgid, uid, &handle); - break; + break; default: - return; + return PMINFO_R_ERROR; } if (ret != PMINFO_R_OK) - return; + return PMINFO_R_ERROR; - ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid); - if (ret != PMINFO_R_OK) { - pkgmgrinfo_appinfo_destroy_appinfo(handle); - return; + ret = pkgmgrinfo_appinfo_is_global(handle, &is_global); + if (ret != PMINFO_R_OK) + goto catch; + + if ((item->req_type == PKGMGR_REQUEST_TYPE_DISABLE_APP + || item->req_type == PKGMGR_REQUEST_TYPE_ENABLE_APP) + && is_global) { + ret = PMINFO_R_ERROR; + goto catch; + } else if ((item->req_type == PKGMGR_REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID + || item->req_type == PKGMGR_REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID) + && !is_global) { + ret = PMINFO_R_ERROR; + goto catch; } + ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid); + if (ret != PMINFO_R_OK) + goto catch; + strncpy(item->appid, item->pkgid, sizeof(item->pkgid) - 1); memset((item->pkgid),0,MAX_PKG_NAME_LEN); strncpy(item->pkgid, pkgid, sizeof(item->pkgid) - 1); +catch: pkgmgrinfo_appinfo_destroy_appinfo(handle); + + return ret; } static int __process_install(pm_dbus_msg *item) @@ -882,8 +900,8 @@ static int __process_enable_app(pm_dbus_msg *item) PKGMGR_INSTALLER_APP_ENABLE_EVENT_STR); /* get actual pkgid and replace it to appid which is currently stored at pkgid variable */ - __change_item_info(item, item->uid); - if (strlen(item->appid) == 0) { + ret = __change_item_info(item, item->uid); + if (ret != PMINFO_R_OK || strlen(item->appid) == 0) { __send_app_signal(item->uid, item->req_id, item->pkg_type, item->pkgid, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR); @@ -913,8 +931,8 @@ static int __process_disable_app(pm_dbus_msg *item) PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR); /* get actual pkgid and replace it to appid which is currently stored at pkgid variable */ - __change_item_info(item, item->uid); - if (strlen(item->appid) == 0) { + ret = __change_item_info(item, item->uid); + if (ret != PMINFO_R_OK || strlen(item->appid) == 0) { __send_app_signal(item->uid, item->req_id, item->pkg_type, item->pkgid, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR); @@ -944,8 +962,8 @@ static int __process_enable_global_app_for_uid(pm_dbus_msg *item) PKGMGR_INSTALLER_GLOBAL_APP_ENABLE_FOR_UID); /* get actual pkgid and replace it to appid which is currently stored at pkgid variable */ - __change_item_info(item, item->uid); - if (strlen(item->appid) == 0) { + ret = __change_item_info(item, item->uid); + if (ret != PMINFO_R_OK || strlen(item->appid) == 0) { __send_app_signal(item->uid, item->req_id, item->pkg_type, item->pkgid, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR); @@ -975,8 +993,8 @@ static int __process_disable_global_app_for_uid(pm_dbus_msg *item) PKGMGR_INSTALLER_GLOBAL_APP_DISABLE_FOR_UID); /* get actual pkgid and replace it to appid which is currently stored at pkgid variable */ - __change_item_info(item, GLOBAL_USER); - if (strlen(item->appid) == 0) { + ret = __change_item_info(item, GLOBAL_USER); + if (ret != PMINFO_R_OK || strlen(item->appid) == 0) { __send_app_signal(item->uid, item->req_id, item->pkg_type, item->pkgid, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR); -- 2.7.4 From 81f225100adf2a792825bb9db7e8ebba402148e9 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Tue, 15 Mar 2016 17:44:27 +0900 Subject: [PATCH 03/16] change functions for thread-safe Change-Id: Iebcda54f4a0880a8b0ac6f7ed629a4c26188eb9d Signed-off-by: Junghyun Yeon --- src/pkgmgr-server.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 5726ccd..7c85902 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -336,10 +336,11 @@ static void __fini_backend_info(void) static void sighandler(int signo) { struct signal_info_t info; + char buf[1024] = {0, }; info.pid = waitpid(-1, &info.status, WNOHANG); if (write(pipe_sig[1], &info, sizeof(struct signal_info_t)) < 0) - ERR("failed to write result: %s", strerror(errno)); + ERR("failed to write result: %s", strerror_r(errno, buf, sizeof(buf))); } static int __register_signal_handler(void) @@ -456,7 +457,7 @@ static int __pkgcmd_find_pid_by_cmdline(const char *dname, static int __pkgcmd_proc_iter_kill_cmdline(const char *apppath, int option) { DIR *dp; - struct dirent *dentry; + struct dirent dentry, *result; int pid; int ret; char buf[1024] = {'\0'}; @@ -467,16 +468,18 @@ static int __pkgcmd_proc_iter_kill_cmdline(const char *apppath, int option) return -1; } - while ((dentry = readdir(dp)) != NULL) { - if (!isdigit(dentry->d_name[0])) + 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); + 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); + pid = __pkgcmd_find_pid_by_cmdline(dentry.d_name, buf, apppath); if (pid > 0) { if (option == 0) { closedir(dp); @@ -610,13 +613,14 @@ user_ctx *get_user_context(uid_t uid) */ user_ctx *context_res; char **env = NULL; - struct passwd *pwd; + char buf[1024] = {0, }; + struct passwd pwd, *result; int len; int ret = 0; int i; - pwd = getpwuid(uid); - if (!pwd) + ret = getpwuid_r(uid, &pwd, buf, sizeof(buf), &result); + if (ret != 0 || result == NULL) return NULL; do { @@ -631,20 +635,20 @@ user_ctx *get_user_context(uid_t uid) break; } // Build environment context - len = snprintf(NULL, 0, "HOME=%s", pwd->pw_dir); + len = snprintf(NULL, 0, "HOME=%s", pwd.pw_dir); env[0] = (char *)malloc((len + 1) * sizeof(char)); 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); + 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) { ret = -1; break; } - snprintf(env[1], len + 1, "USER=%s", pwd->pw_name); + snprintf(env[1], len + 1, "USER=%s", pwd.pw_name); env[2] = NULL; } while (0); @@ -662,7 +666,7 @@ user_ctx *get_user_context(uid_t uid) } else { context_res->env = env; context_res->uid = uid; - context_res->gid = pwd->pw_gid; + context_res->gid = pwd.pw_gid; } return context_res; } -- 2.7.4 From af1decf51017faa78cac217d522b52d6a3133c84 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Mon, 21 Mar 2016 16:40:18 +0900 Subject: [PATCH 04/16] kill app before server tried to disable it Change-Id: Idad9ddb91cdcbe9e304b466e5a14a6cf0745284e Signed-off-by: Junghyun Yeon --- src/pkgmgr-server.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 7c85902..a0bd7c8 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -530,6 +530,31 @@ static void __make_pid_info_file(char *req_key, int pid) fclose(file); } +static int __kill_app(char *appid, uid_t uid) +{ + pkgmgrinfo_appinfo_h appinfo; + int ret = PMINFO_R_ERROR; + char *exec = NULL; + + ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid, &appinfo); + if (ret != PMINFO_R_OK) + return PMINFO_R_ERROR; + + ret = pkgmgrinfo_appinfo_get_exec(appinfo, &exec); + if (ret != PMINFO_R_OK) { + pkgmgrinfo_appinfo_destroy_appinfo(appinfo); + return PMINFO_R_ERROR; + } + + ret = __pkgcmd_proc_iter_kill_cmdline(exec, 1); + if (ret != PMINFO_R_OK) { + DBG("failed to kill app[%s], exec[%s]", appid, exec); + } + + pkgmgrinfo_appinfo_destroy_appinfo(appinfo); + return ret; +} + static int __pkgcmd_app_cb(const pkgmgrinfo_appinfo_h handle, void *user_data) { char *pkgid; @@ -943,6 +968,13 @@ static int __process_disable_app(pm_dbus_msg *item) return ret; } + ret = __kill_app(item->appid, item->uid); + if (ret != PMINFO_R_OK) { + __send_app_signal(item->uid, item->req_id, item->pkg_type, + item->pkgid, item->appid, + PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR); + } + ret = pkgmgr_parser_update_app_disable_info_in_usr_db(item->appid, item->uid, 1); if (ret != PMINFO_R_OK) __send_app_signal(item->uid, item->req_id, item->pkg_type, @@ -1005,6 +1037,8 @@ static int __process_disable_global_app_for_uid(pm_dbus_msg *item) return ret; } + ret = __kill_app(item->appid, item->uid); + ret = pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(item->appid, item->uid, 1); if (ret != PMINFO_R_OK) __send_app_signal(item->uid, item->req_id, item->pkg_type, -- 2.7.4 From d6027b359c76c8cdf4c45aa76ef127702f4a2e68 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Mon, 21 Mar 2016 15:20:07 +0900 Subject: [PATCH 05/16] remove unnecessary pkg queue and reassign operations Change-Id: I05effb13bbafb3dfc925a828d0fa0dbc223e15b3 Signed-off-by: Junghyun Yeon --- include/pm-queue.h | 2 +- src/pkgmgr-server.c | 51 ++++++++++++++++++--------------------------------- src/pm-queue.c | 8 ++++---- src/request.c | 42 +++++++++++++++++++++++------------------- 4 files changed, 46 insertions(+), 57 deletions(-) diff --git a/include/pm-queue.h b/include/pm-queue.h index fac45d5..046edb9 100644 --- a/include/pm-queue.h +++ b/include/pm-queue.h @@ -48,7 +48,7 @@ typedef struct queue_info_map_t { int _pm_queue_init(void); int _pm_queue_push(uid_t uid, const char *req_id, int req_type, - const char *pkg_type, const char *pkgid, const char *argv); + const char *queue_type, const char *pkgid, const char *argv); /*position specifies the queue from which to pop request*/ pm_dbus_msg *_pm_queue_pop(int position); void _pm_queue_final(); diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index a0bd7c8..d3a780d 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -204,7 +204,7 @@ static void __unset_recovery_mode(uid_t uid, char *pkgid, char *pkg_type) } static void __send_app_signal(uid_t uid, const char *req_id, - const char *pkg_type, const char *pkgid, const char *appid, + const char *pkgid, const char *appid, const char *key, const char *val) { pkgmgr_installer *pi; @@ -221,7 +221,7 @@ static void __send_app_signal(uid_t uid, const char *req_id, goto catch; if (pkgmgr_installer_set_session_id(pi, req_id)) goto catch; - pkgmgr_installer_send_app_signal(pi, pkg_type, pkgid, appid, key, val); + pkgmgr_installer_send_app_signal(pi, "app", pkgid, appid, key, val); catch: pkgmgr_installer_free(pi); @@ -923,28 +923,24 @@ static int __process_enable_app(pm_dbus_msg *item) { int ret = -1; - __send_app_signal(item->uid, item->req_id, item->pkg_type, - item->pkgid, item->pkgid, + __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, PKGMGR_INSTALLER_START_KEY_STR, PKGMGR_INSTALLER_APP_ENABLE_EVENT_STR); /* get actual pkgid and replace it to appid which is currently stored at pkgid variable */ ret = __change_item_info(item, item->uid); if (ret != PMINFO_R_OK || strlen(item->appid) == 0) { - __send_app_signal(item->uid, item->req_id, item->pkg_type, - item->pkgid, item->pkgid, + __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR); return ret; } 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->pkg_type, - item->pkgid, item->appid, + __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR); else - __send_app_signal(item->uid, item->req_id, item->pkg_type, - item->pkgid, item->appid, + __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR); return ret; @@ -954,16 +950,14 @@ static int __process_disable_app(pm_dbus_msg *item) { int ret = -1; - __send_app_signal(item->uid, item->req_id, item->pkg_type, - item->pkgid, item->pkgid, + __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, PKGMGR_INSTALLER_START_KEY_STR, PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR); /* get actual pkgid and replace it to appid which is currently stored at pkgid variable */ ret = __change_item_info(item, item->uid); if (ret != PMINFO_R_OK || strlen(item->appid) == 0) { - __send_app_signal(item->uid, item->req_id, item->pkg_type, - item->pkgid, item->pkgid, + __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR); return ret; } @@ -977,12 +971,10 @@ static int __process_disable_app(pm_dbus_msg *item) ret = pkgmgr_parser_update_app_disable_info_in_usr_db(item->appid, item->uid, 1); if (ret != PMINFO_R_OK) - __send_app_signal(item->uid, item->req_id, item->pkg_type, - item->pkgid, item->appid, + __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR); else - __send_app_signal(item->uid, item->req_id, item->pkg_type, - item->pkgid, item->appid, + __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR); return ret; @@ -992,28 +984,24 @@ static int __process_enable_global_app_for_uid(pm_dbus_msg *item) { int ret = -1; - __send_app_signal(item->uid, item->req_id, item->pkg_type, - item->pkgid, item->pkgid, + __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, PKGMGR_INSTALLER_START_KEY_STR, PKGMGR_INSTALLER_GLOBAL_APP_ENABLE_FOR_UID); /* get actual pkgid and replace it to appid which is currently stored at pkgid variable */ ret = __change_item_info(item, item->uid); if (ret != PMINFO_R_OK || strlen(item->appid) == 0) { - __send_app_signal(item->uid, item->req_id, item->pkg_type, - item->pkgid, item->pkgid, + __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR); return ret; } 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->pkg_type, - item->pkgid, item->appid, + __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR); else - __send_app_signal(item->uid, item->req_id, item->pkg_type, - item->pkgid, item->appid, + __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR); return ret; @@ -1023,7 +1011,7 @@ static int __process_disable_global_app_for_uid(pm_dbus_msg *item) { int ret = -1; - __send_app_signal(item->uid, item->req_id, item->pkg_type, + __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, PKGMGR_INSTALLER_START_KEY_STR, PKGMGR_INSTALLER_GLOBAL_APP_DISABLE_FOR_UID); @@ -1031,8 +1019,7 @@ static int __process_disable_global_app_for_uid(pm_dbus_msg *item) /* get actual pkgid and replace it to appid which is currently stored at pkgid variable */ ret = __change_item_info(item, GLOBAL_USER); if (ret != PMINFO_R_OK || strlen(item->appid) == 0) { - __send_app_signal(item->uid, item->req_id, item->pkg_type, - item->pkgid, item->pkgid, + __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR); return ret; } @@ -1041,12 +1028,10 @@ static int __process_disable_global_app_for_uid(pm_dbus_msg *item) ret = pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(item->appid, item->uid, 1); if (ret != PMINFO_R_OK) - __send_app_signal(item->uid, item->req_id, item->pkg_type, - item->pkgid, item->appid, + __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR); else - __send_app_signal(item->uid, item->req_id, item->pkg_type, - item->pkgid, item->appid, + __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR); return ret; diff --git a/src/pm-queue.c b/src/pm-queue.c index 1839d53..5131015 100644 --- a/src/pm-queue.c +++ b/src/pm-queue.c @@ -259,17 +259,17 @@ int _pm_queue_init(void) } int _pm_queue_push(uid_t uid, const char *req_id, int req_type, - const char *pkg_type, const char *pkgid, const char *args) + const char *queue_type, const char *pkgid, const char *args) { pm_queue_data *data = NULL; pm_queue_data *cur = NULL; pm_queue_data *tmp = NULL; int ret = 0; - ret = __is_pkg_supported(pkg_type); + ret = __is_pkg_supported(queue_type); if (ret == 0) return -1; - cur = __get_head_from_pkgtype(pkg_type); + cur = __get_head_from_pkgtype(queue_type); tmp = cur; /* TODO: use glist */ @@ -282,7 +282,7 @@ int _pm_queue_push(uid_t uid, const char *req_id, int req_type, snprintf(data->msg->req_id, sizeof(data->msg->req_id), "%s", req_id); data->msg->req_type = req_type; data->msg->uid = uid; - snprintf(data->msg->pkg_type, sizeof(data->msg->pkg_type), "%s", pkg_type); + snprintf(data->msg->pkg_type, sizeof(data->msg->pkg_type), "%s", queue_type); snprintf(data->msg->pkgid, sizeof(data->msg->pkgid), "%s", pkgid); snprintf(data->msg->args, sizeof(data->msg->args), "%s", args); diff --git a/src/request.c b/src/request.c index a818550..d26165b 100644 --- a/src/request.c +++ b/src/request.c @@ -44,11 +44,13 @@ static const char instropection_xml[] = " " " " " " + " " " " " " " " " " " " + " " " " " " " " @@ -344,16 +346,17 @@ static int __handle_request_enable_pkg(uid_t uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; + char *pkgtype = NULL; char *pkgid = NULL; - g_variant_get(parameters, "(u&s)", &target_uid, &pkgid); + g_variant_get(parameters, "(u&s&s)", &target_uid, &pkgtype, &pkgid); if (target_uid == (uid_t)-1 || pkgid == NULL) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ECOMM)); return -1; } - if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_ENABLE_PKG, "pkg", + if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_ENABLE_PKG, &pkgtype, pkgid, "")) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); @@ -370,16 +373,17 @@ static int __handle_request_disable_pkg(uid_t uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; + char *pkgtype = NULL; char *pkgid = NULL; - g_variant_get(parameters, "(u&s)", &target_uid, &pkgid); + g_variant_get(parameters, "(u&s&s)", &target_uid, &pkgtype, &pkgid); if (target_uid == (uid_t)-1 || pkgid == NULL) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ECOMM)); return -1; } - if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_DISABLE_PKG, "pkg", + if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_DISABLE_PKG, &pkgtype, pkgid, "")) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); @@ -413,7 +417,7 @@ static int __handle_request_enable_app(uid_t uid, goto catch; } - if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_ENABLE_APP, "app", + if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_ENABLE_APP, "default", appid, "")) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); @@ -454,7 +458,7 @@ static int __handle_request_disable_app(uid_t uid, goto catch; } - if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_DISABLE_APP, "app", + if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_DISABLE_APP, "default", appid, "")) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); @@ -495,7 +499,7 @@ static int __handle_request_enable_global_app_for_uid(uid_t uid, goto catch; } - if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID, "app", + if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID, "default", appid, "")) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); @@ -536,7 +540,7 @@ static int __handle_request_disable_global_app_for_uid(uid_t uid, goto catch; } - if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID, "app", + if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID, "default", appid, "")) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); @@ -577,7 +581,7 @@ static int __handle_request_getsize(uid_t uid, return -1; snprintf(buf, sizeof(buf), "%d", get_type); - if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_GETSIZE, "getsize", + if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_GETSIZE, "pkgtool", pkgid, buf)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); @@ -606,7 +610,7 @@ static int __handle_request_cleardata(uid_t uid, return -1; } - if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_CLEARDATA, pkgtype, + if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_CLEARDATA, "pkgtool", pkgid, "")) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); @@ -633,7 +637,7 @@ static int __handle_request_clearcache(uid_t uid, } if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_CLEARCACHE, - "clearcache", pkgid, "")) { + "pkgtool", pkgid, "")) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); return -1; @@ -658,7 +662,7 @@ static int __handle_request_kill(uid_t uid, return -1; } - if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_KILL, "pkg", + if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_KILL, "default", pkgid, "")) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); @@ -684,7 +688,7 @@ static int __handle_request_check(uid_t uid, return -1; } - if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_CHECK, "pkg", + if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_CHECK, "default", pkgid, "")) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); @@ -720,7 +724,7 @@ static int __handle_request_generate_license_request(uid_t uid, if (_pm_queue_push(uid, reqkey, PKGMGR_REQUEST_TYPE_GENERATE_LICENSE_REQUEST, - "pkg", "", resp_data)) { + "default", "", resp_data)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(iss)", PKGMGR_R_ESYSTEM, "", "")); @@ -756,7 +760,7 @@ static int __handle_request_register_license(uid_t uid, } if (_pm_queue_push(uid, reqkey, PKGMGR_REQUEST_TYPE_REGISTER_LICENSE, - "pkg", "", resp_data)) { + "default", "", resp_data)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); free(reqkey); @@ -793,7 +797,7 @@ static int __handle_request_decrypt_package(uid_t uid, } if (_pm_queue_push(uid, reqkey, PKGMGR_REQUEST_TYPE_DECRYPT_PACKAGE, - "pkg", drm_file_path, decrypted_file_path)) { + "default", drm_file_path, decrypted_file_path)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); free(reqkey); @@ -830,7 +834,7 @@ static int __handle_request_add_blacklist(uid_t uid, if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_ADD_BLACKLIST, - "pkg", pkgid, "")) { + "default", pkgid, "")) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); free(reqkey); @@ -867,7 +871,7 @@ static int __handle_request_remove_blacklist(uid_t uid, if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_REMOVE_BLACKLIST, - "pkg", pkgid, "")) { + "default", pkgid, "")) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); free(reqkey); @@ -904,7 +908,7 @@ static int __handle_request_check_blacklist(uid_t uid, if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_CHECK_BLACKLIST, - "pkg", pkgid, "")) { + "default", pkgid, "")) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(ii)", PKGMGR_R_ESYSTEM, -1)); free(reqkey); -- 2.7.4 From 15e9652d0de6c6020c16ad4a92acd487a886242e Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Wed, 16 Mar 2016 20:51:23 +0900 Subject: [PATCH 06/16] seperate app enable/disable signal Change-Id: I6431cc7502d51b30d28355baa84fdb9957e81576 Signed-off-by: Junghyun Yeon --- src/pkgmgr-server.c | 69 ++++++++++++++++++++++++++++++++++++----------------- src/request.c | 4 ++-- 2 files changed, 49 insertions(+), 24 deletions(-) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index d3a780d..17a8617 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -205,7 +205,7 @@ static void __unset_recovery_mode(uid_t uid, char *pkgid, char *pkg_type) static void __send_app_signal(uid_t uid, const char *req_id, const char *pkgid, const char *appid, - const char *key, const char *val) + const char *key, const char *val, int req_type) { pkgmgr_installer *pi; @@ -217,8 +217,19 @@ static void __send_app_signal(uid_t uid, const char *req_id, if (pkgmgr_installer_set_uid(pi, uid)) goto catch; - if (pkgmgr_installer_set_request_type(pi,PKGMGR_REQ_ENABLE_DISABLE_APP)) + if (req_type == PKGMGR_REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID + || req_type == PKGMGR_REQUEST_TYPE_ENABLE_APP) { + if (pkgmgr_installer_set_request_type(pi, PKGMGR_REQ_ENABLE_APP)) + goto catch; + } else if (req_type == PKGMGR_REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID + || req_type == PKGMGR_REQUEST_TYPE_DISABLE_APP) { + if (pkgmgr_installer_set_request_type(pi, PKGMGR_REQ_DISABLE_APP)) + goto catch; + } else { + 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); @@ -925,23 +936,27 @@ static int __process_enable_app(pm_dbus_msg *item) __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, PKGMGR_INSTALLER_START_KEY_STR, - PKGMGR_INSTALLER_APP_ENABLE_EVENT_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); if (ret != PMINFO_R_OK || strlen(item->appid) == 0) { __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, - PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR); + PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, + item->req_type); return ret; } 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, - PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR); + PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, + item->req_type); else __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, - PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR); + PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR, + item->req_type); + return ret; } @@ -952,30 +967,33 @@ static int __process_disable_app(pm_dbus_msg *item) __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, PKGMGR_INSTALLER_START_KEY_STR, - PKGMGR_INSTALLER_APP_DISABLE_EVENT_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); if (ret != PMINFO_R_OK || strlen(item->appid) == 0) { __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, - PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR); + PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, + item->req_type); return ret; } ret = __kill_app(item->appid, item->uid); if (ret != PMINFO_R_OK) { - __send_app_signal(item->uid, item->req_id, item->pkg_type, - item->pkgid, item->appid, - PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR); + __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); } ret = pkgmgr_parser_update_app_disable_info_in_usr_db(item->appid, item->uid, 1); if (ret != PMINFO_R_OK) __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, - PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR); + PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, + item->req_type); else __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, - PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR); + PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR, + item->req_type); return ret; } @@ -986,23 +1004,26 @@ static int __process_enable_global_app_for_uid(pm_dbus_msg *item) __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, PKGMGR_INSTALLER_START_KEY_STR, - PKGMGR_INSTALLER_GLOBAL_APP_ENABLE_FOR_UID); + 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); if (ret != PMINFO_R_OK || strlen(item->appid) == 0) { __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, - PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR); + PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, + item->req_type); return ret; } 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, - PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR); + PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, + item->req_type); else __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, - PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR); + PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR, + item->req_type); return ret; } @@ -1014,25 +1035,29 @@ static int __process_disable_global_app_for_uid(pm_dbus_msg *item) __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, PKGMGR_INSTALLER_START_KEY_STR, - PKGMGR_INSTALLER_GLOBAL_APP_DISABLE_FOR_UID); + 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); if (ret != PMINFO_R_OK || strlen(item->appid) == 0) { __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, - PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR); + PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, + item->req_type); return ret; } ret = __kill_app(item->appid, item->uid); + ret = pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(item->appid, + item->uid, 1); - ret = pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(item->appid, item->uid, 1); if (ret != PMINFO_R_OK) __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, - PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR); + PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, + item->req_type); else __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, - PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR); + PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR, + item->req_type); return ret; } diff --git a/src/request.c b/src/request.c index d26165b..3e89ed1 100644 --- a/src/request.c +++ b/src/request.c @@ -356,7 +356,7 @@ static int __handle_request_enable_pkg(uid_t uid, return -1; } - if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_ENABLE_PKG, &pkgtype, + if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_ENABLE_PKG, pkgtype, pkgid, "")) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); @@ -383,7 +383,7 @@ static int __handle_request_disable_pkg(uid_t uid, return -1; } - if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_DISABLE_PKG, &pkgtype, + if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_DISABLE_PKG, pkgtype, pkgid, "")) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); -- 2.7.4 From d97867f3bf553bd408e74c128569c8ea03e97c24 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Mon, 4 Apr 2016 16:39:57 +0900 Subject: [PATCH 07/16] not to add space at last of argument Change-Id: I4ccfc956b5b4829f37519c5cbd7816f31afc6132 Signed-off-by: Junghyun Yeon --- src/request.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/request.c b/src/request.c index 3e89ed1..35587d1 100644 --- a/src/request.c +++ b/src/request.c @@ -197,7 +197,8 @@ static int __handle_request_install(uid_t uid, for (i = 0; i < args_count; i++) { strncat(args, tmp_args[i], strlen(tmp_args[i])); - strncat(args, " ", strlen(" ")); + if (i != args_count - 1) + strncat(args, " ", strlen(" ")); } if (target_uid == (uid_t)-1 || pkgtype == NULL) { -- 2.7.4 From 4f1fa44e2ed879868f187b325b145db5ad49f4a8 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Mon, 18 Apr 2016 17:00:22 +0900 Subject: [PATCH 08/16] Fix build fail issue Change-Id: I6c8cd8a93108cb0d955ead98f5f7e35722de2ae4 Signed-off-by: Sangyoon Jang --- CMakeLists.txt | 3 ++- include/pkgmgr-server.h | 14 +++++++++++++- packaging/pkgmgr-server.spec | 1 + src/db.c | 1 - src/pkgmgr-server.c | 1 - src/request.c | 10 ++++++---- 6 files changed, 22 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ab31aa..8e115b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,7 +30,8 @@ pkg_check_modules(SERVER_DEPS REQUIRED libtzplatform-config drm-service-core-tizen sqlite3 - pkgmgr) + pkgmgr + pkgmgr-installer) FOREACH(SERVER_FLAGS ${SERVER_DEPS_CFLAGS}) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SERVER_FLAGS}") ENDFOREACH(SERVER_FLAGS) diff --git a/include/pkgmgr-server.h b/include/pkgmgr-server.h index d4cadde..6bb8f08 100644 --- a/include/pkgmgr-server.h +++ b/include/pkgmgr-server.h @@ -25,12 +25,24 @@ #include #include +#include #ifdef LOG_TAG #undef LOG_TAG #endif /* LOG_TAG */ #define LOG_TAG "PKGMGR_SERVER" -#include "package-manager-debug.h" + +#ifndef ERR +#define ERR(fmt, args...) LOGE("[%s:%d] "fmt"\n", __func__, __LINE__, ##args) +#endif + +#ifndef DBG +#define DBG(fmt, args...) LOGD("[%s:%d] "fmt"\n", __func__, __LINE__, ##args) +#endif + +#ifndef INFO +#define INFO(fmt, args...) LOGI("[%s:%d] "fmt"\n", __func__, __LINE__, ##args) +#endif #define CONF_FILE "/etc/package-manager/server/.config" #define DESKTOP_FILE_DIRS "/usr/share/install-info/desktop.conf" diff --git a/packaging/pkgmgr-server.spec b/packaging/pkgmgr-server.spec index 21fe2fc..f1ab500 100644 --- a/packaging/pkgmgr-server.spec +++ b/packaging/pkgmgr-server.spec @@ -22,6 +22,7 @@ BuildRequires: pkgconfig(xdgmime) BuildRequires: pkgconfig(db-util) BuildRequires: pkgconfig(libsmack) BuildRequires: pkgconfig(pkgmgr) +BuildRequires: pkgconfig(pkgmgr-installer) BuildRequires: pkgconfig(drm-service-core-tizen) BuildRequires: pkgconfig(sqlite3) BuildRequires: pkgmgr-info-parser-devel diff --git a/src/db.c b/src/db.c index c57f995..68b8cdf 100644 --- a/src/db.c +++ b/src/db.c @@ -22,7 +22,6 @@ #include #include -#include #include "pkgmgr-server.h" diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 17a8617..f4e3463 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -45,7 +45,6 @@ #include "pkgmgr_installer.h" #include "pkgmgr-server.h" #include "pm-queue.h" -#include "comm_config.h" #include "package-manager.h" #define BUFMAX 128 diff --git a/src/request.c b/src/request.c index 35587d1..a9a2e5d 100644 --- a/src/request.c +++ b/src/request.c @@ -1,14 +1,16 @@ +#include #include #include #include #include -#include "comm_config.h" #include "pm-queue.h" #include "pkgmgr-server.h" #include "package-manager.h" -#include "package-manager-debug.h" + +#define PKGMGR_DBUS_SERVICE "org.tizen.pkgmgr" +#define PKGMGR_DBUS_OBJECT_PATH "/org/tizen/pkgmgr" static const char instropection_xml[] = "" @@ -1046,7 +1048,7 @@ static void __on_bus_acquired(GDBusConnection *connection, const gchar *name, DBG("on bus acquired"); reg_id = g_dbus_connection_register_object(connection, - COMM_PKGMGR_DBUS_OBJECT_PATH, + PKGMGR_DBUS_OBJECT_PATH, instropection_data->interfaces[0], &interface_vtable, NULL, NULL, &err); @@ -1072,7 +1074,7 @@ int __init_request_handler(void) { instropection_data = g_dbus_node_info_new_for_xml(instropection_xml, NULL); - owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, COMM_PKGMGR_DBUS_SERVICE, + owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, PKGMGR_DBUS_SERVICE, G_BUS_NAME_OWNER_FLAGS_NONE, __on_bus_acquired, __on_name_acquired, __on_name_lost, NULL, NULL); -- 2.7.4 From 89def384b3f456943058bfa1541fc7c711cac833 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Wed, 30 Mar 2016 16:13:57 +0900 Subject: [PATCH 09/16] implement pkg move changes are applied in these repos [pkgmgr-tool] https://review.tizen.org/gerrit/#/c/64121/ [slp-pkgmgr] https://review.tizen.org/gerrit/#/c/64122/ [pkgmgr-server] https://review.tizen.org/gerrit/#/c/64123/ Change-Id: I34e4d9ea0e3d8aea86681d34391d353916e4708d Signed-off-by: Junghyun Yeon --- src/pkgmgr-server.c | 1 - src/request.c | 16 ++++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index f4e3463..05f3460 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -904,7 +904,6 @@ static int __process_move(pm_dbus_msg *item) if (backend_cmd == NULL) return -1; - /* TODO: set movetype */ snprintf(args, sizeof(args), "%s -k %s -m %s -t %s", backend_cmd, item->req_id, item->pkgid, item->args); argv = __generate_argv(args); diff --git a/src/request.c b/src/request.c index a9a2e5d..bd7e3f5 100644 --- a/src/request.c +++ b/src/request.c @@ -41,8 +41,8 @@ static const char instropection_xml[] = " " " " " " + " " " " - " " " " " " " " @@ -319,27 +319,31 @@ static int __handle_request_move(uid_t uid, char *pkgtype = NULL; char *pkgid = NULL; char *reqkey; + int move_type = -1; + char buf[4] = { '\0' }; - g_variant_get(parameters, "(u&s&s)", &target_uid, &pkgtype, &pkgid); + g_variant_get(parameters, "(u&s&si)", &target_uid, &pkgtype, &pkgid, &move_type); if (target_uid == (uid_t)-1 || pkgtype == NULL || pkgid == NULL) { g_dbus_method_invocation_return_value(invocation, - g_variant_new("(is)", PKGMGR_R_ECOMM, "")); + g_variant_new("(i)", PKGMGR_R_ECOMM)); return -1; } reqkey = __generate_reqkey(pkgid); if (reqkey == NULL) return -1; + + snprintf(buf, sizeof(buf), "%d", move_type); if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_MOVE, pkgtype, - pkgid, "")) { + pkgid, buf)) { g_dbus_method_invocation_return_value(invocation, - g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); + g_variant_new("(i)", PKGMGR_R_ESYSTEM)); free(reqkey); return -1; } g_dbus_method_invocation_return_value(invocation, - g_variant_new("(is)", PKGMGR_R_OK, reqkey)); + g_variant_new("(i)", PKGMGR_R_OK)); free(reqkey); return 0; -- 2.7.4 From f71cb549b1b61012d707e9121711110fdb7f8706 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 19 Apr 2016 17:32:19 +0900 Subject: [PATCH 10/16] Implement app signal related with app splash screen display - Requires: [pkgmgr-info] https://review.tizen.org/gerrit/#/c/65897/ [slp-pkgmgr] https://review.tizen.org/gerrit/#/c/64902/ Change-Id: I1a32909ffda34ce0f50228188826a860dd2cb2c6 Signed-off-by: Hwankyu Jhun --- include/pkgmgr-server.h | 2 ++ org.tizen.pkgmgr.conf.in | 2 ++ src/pkgmgr-server.c | 94 ++++++++++++++++++++++++++++++++++++++---------- src/request.c | 71 ++++++++++++++++++++++++++++++++++++ 4 files changed, 150 insertions(+), 19 deletions(-) diff --git a/include/pkgmgr-server.h b/include/pkgmgr-server.h index 6bb8f08..ea02b8f 100644 --- a/include/pkgmgr-server.h +++ b/include/pkgmgr-server.h @@ -78,6 +78,8 @@ enum request_type { PKGMGR_REQUEST_TYPE_ADD_BLACKLIST, PKGMGR_REQUEST_TYPE_REMOVE_BLACKLIST, PKGMGR_REQUEST_TYPE_CHECK_BLACKLIST, + PKGMGR_REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN, + PKGMGR_REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN, }; typedef struct { diff --git a/org.tizen.pkgmgr.conf.in b/org.tizen.pkgmgr.conf.in index c237b44..f3c5caf 100644 --- a/org.tizen.pkgmgr.conf.in +++ b/org.tizen.pkgmgr.conf.in @@ -24,5 +24,7 @@ + + diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 05f3460..6414b57 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -216,15 +216,27 @@ static void __send_app_signal(uid_t uid, const char *req_id, if (pkgmgr_installer_set_uid(pi, uid)) goto catch; - if (req_type == PKGMGR_REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID - || req_type == PKGMGR_REQUEST_TYPE_ENABLE_APP) { + + 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; - } else if (req_type == PKGMGR_REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID - || req_type == PKGMGR_REQUEST_TYPE_DISABLE_APP) { + 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; - } else { + 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; } @@ -769,24 +781,23 @@ static int __fork_and_exec_with_args(char **argv, uid_t uid) return pid; } -static int __change_item_info(pm_dbus_msg *item, uid_t uid) +static int __change_item_info(pm_dbus_msg *item, uid_t uid, bool *is_global) { int ret = 0; char *pkgid = NULL; - bool is_global = false; pkgmgrinfo_appinfo_h handle = NULL; switch (item->req_type) { case PKGMGR_REQUEST_TYPE_DISABLE_APP: case PKGMGR_REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID: + case PKGMGR_REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN: + case PKGMGR_REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN: ret = pkgmgrinfo_appinfo_get_usr_appinfo(item->pkgid, uid, &handle); - break; - + break; case PKGMGR_REQUEST_TYPE_ENABLE_APP: case PKGMGR_REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID: ret = pkgmgrinfo_appinfo_get_usr_disabled_appinfo(item->pkgid, uid, &handle); - break; - + break; default: return PMINFO_R_ERROR; } @@ -794,18 +805,18 @@ static int __change_item_info(pm_dbus_msg *item, uid_t uid) if (ret != PMINFO_R_OK) return PMINFO_R_ERROR; - ret = pkgmgrinfo_appinfo_is_global(handle, &is_global); + ret = pkgmgrinfo_appinfo_is_global(handle, is_global); if (ret != PMINFO_R_OK) goto catch; if ((item->req_type == PKGMGR_REQUEST_TYPE_DISABLE_APP || item->req_type == PKGMGR_REQUEST_TYPE_ENABLE_APP) - && is_global) { + && *is_global) { ret = PMINFO_R_ERROR; goto catch; } else if ((item->req_type == PKGMGR_REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID || item->req_type == PKGMGR_REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID) - && !is_global) { + && !*is_global) { ret = PMINFO_R_ERROR; goto catch; } @@ -815,7 +826,7 @@ static int __change_item_info(pm_dbus_msg *item, uid_t uid) goto catch; strncpy(item->appid, item->pkgid, sizeof(item->pkgid) - 1); - memset((item->pkgid),0,MAX_PKG_NAME_LEN); + memset((item->pkgid), 0, MAX_PKG_NAME_LEN); strncpy(item->pkgid, pkgid, sizeof(item->pkgid) - 1); catch: @@ -931,13 +942,14 @@ static int __process_disable_pkg(pm_dbus_msg *item) 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); + 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_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, @@ -962,13 +974,14 @@ static int __process_enable_app(pm_dbus_msg *item) 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); + 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_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, @@ -999,13 +1012,14 @@ static int __process_disable_app(pm_dbus_msg *item) 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); + 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_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, @@ -1029,6 +1043,7 @@ static int __process_enable_global_app_for_uid(pm_dbus_msg *item) 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, @@ -1036,7 +1051,7 @@ static int __process_disable_global_app_for_uid(pm_dbus_msg *item) 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); + 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_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, @@ -1275,6 +1290,41 @@ static int __process_check_blacklist(pm_dbus_msg *item) return ret; } +static int __process_update_app_splash_screen(pm_dbus_msg *item, int flag) +{ + int ret; + bool is_global = false; + const char *val; + + ret = __change_item_info(item, item->uid, &is_global); + if (ret != PMINFO_R_OK || strlen(item->appid) == 0) + return -1; + + val = flag ? PKGMGR_INSTALLER_APP_ENABLE_SPLASH_SCREEN_EVENT_STR : + PKGMGR_INSTALLER_APP_DISABLE_SPLASH_SCREEN_EVENT_STR; + __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, + PKGMGR_INSTALLER_START_KEY_STR, val, item->req_type); + + if (is_global) + ret = pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db( + item->appid, item->uid, flag); + else + ret = pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db( + item->appid, item->uid, flag); + if (ret != PMINFO_R_OK) + __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); + else + __send_app_signal(item->uid, item->req_id, item->pkgid, + item->appid, PKGMGR_INSTALLER_END_KEY_STR, + PKGMGR_INSTALLER_OK_EVENT_STR, + item->req_type); + + return ret; +} + gboolean queue_job(void *data) { pm_dbus_msg *item = NULL; @@ -1380,6 +1430,12 @@ gboolean queue_job(void *data) case PKGMGR_REQUEST_TYPE_CHECK_BLACKLIST: ret = __process_check_blacklist(item); break; + case PKGMGR_REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN: + ret = __process_update_app_splash_screen(item, 1); + break; + case PKGMGR_REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN: + ret = __process_update_app_splash_screen(item, 0); + break; default: ret = -1; break; diff --git a/src/request.c b/src/request.c index bd7e3f5..9acbed0 100644 --- a/src/request.c +++ b/src/request.c @@ -139,6 +139,16 @@ static const char instropection_xml[] = " " " " " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " " " ""; static GDBusNodeInfo *instropection_data; @@ -929,6 +939,61 @@ static int __handle_request_check_blacklist(uid_t uid, return 0; } + +static int __update_app_splash_screen(uid_t uid, + GDBusMethodInvocation *invocation, GVariant *parameters, + int req_type) +{ + uid_t target_uid = (uid_t)-1; + char *appid = NULL; + char *reqkey; + + g_variant_get(parameters, "(u&s)", &target_uid, &appid); + if (target_uid == (uid_t)-1 || appid == NULL) { + ERR("target_uid: %d, appid: %s", target_uid, appid); + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(i)", PKGMGR_R_ECOMM)); + return -1; + } + + reqkey = __generate_reqkey(appid); + if (reqkey == NULL) { + ERR("Failed to generate request key"); + return -1; + } + + if (_pm_queue_push(target_uid, reqkey, req_type, "default", + appid, "")) { + ERR("Failed to push request"); + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(i)", PKGMGR_R_ESYSTEM)); + free(reqkey); + return -1; + } + + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(i)", PKGMGR_R_OK)); + + if (reqkey) + free(reqkey); + + return 0; +} + +static int __handle_request_enable_app_splash_screen(uid_t uid, + GDBusMethodInvocation *invocation, GVariant *parameters) +{ + return __update_app_splash_screen(uid, invocation, parameters, + PKGMGR_REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN); +} + +static int __handle_request_disable_app_splash_screen(uid_t uid, + GDBusMethodInvocation *invocation, GVariant *parameters) +{ + return __update_app_splash_screen(uid, invocation, parameters, + PKGMGR_REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN); +} + static uid_t __get_caller_uid(GDBusConnection *connection, const char *name) { GError *err = NULL; @@ -1013,6 +1078,12 @@ static void __handle_method_call(GDBusConnection *connection, else if (g_strcmp0(method_name, "check_blacklist") == 0) ret = __handle_request_check_blacklist(uid, invocation, parameters); + else if (g_strcmp0(method_name, "disable_app_splash_screen") == 0) + ret = __handle_request_disable_app_splash_screen(uid, + invocation, parameters); + else if (g_strcmp0(method_name, "enable_app_splash_screen") == 0) + ret = __handle_request_enable_app_splash_screen(uid, + invocation, parameters); else ret = -1; -- 2.7.4 From 9a0232b4ab04465354b05dec33256f8899320a9c Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Mon, 2 May 2016 15:47:34 +0900 Subject: [PATCH 11/16] Add checking user type non-admin user cannot request operation to other users. Change-Id: If36ac04c6e7547ca9ecc4b65ab715e81ce96d6ae Signed-off-by: Sangyoon Jang --- CMakeLists.txt | 1 + packaging/pkgmgr-server.spec | 1 + src/request.c | 68 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e115b4..7d89a0b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,7 @@ pkg_check_modules(SERVER_DEPS REQUIRED libtzplatform-config drm-service-core-tizen sqlite3 + libgum pkgmgr pkgmgr-installer) FOREACH(SERVER_FLAGS ${SERVER_DEPS_CFLAGS}) diff --git a/packaging/pkgmgr-server.spec b/packaging/pkgmgr-server.spec index f1ab500..7c9768d 100644 --- a/packaging/pkgmgr-server.spec +++ b/packaging/pkgmgr-server.spec @@ -25,6 +25,7 @@ BuildRequires: pkgconfig(pkgmgr) BuildRequires: pkgconfig(pkgmgr-installer) BuildRequires: pkgconfig(drm-service-core-tizen) BuildRequires: pkgconfig(sqlite3) +BuildRequires: pkgconfig(libgum) BuildRequires: pkgmgr-info-parser-devel BuildRequires: pkgmgr-info-parser BuildRequires: fdupes diff --git a/src/request.c b/src/request.c index 9acbed0..70a7182 100644 --- a/src/request.c +++ b/src/request.c @@ -4,6 +4,8 @@ #include #include +#include +#include #include "pm-queue.h" #include "pkgmgr-server.h" @@ -179,6 +181,69 @@ static char *__generate_reqkey(const char *pkgid) return str_req_key; } +static int __is_admin_user(uid_t uid) +{ + GumUser *guser; + GumUserType ut = GUM_USERTYPE_NONE; + + guser = gum_user_get_sync(uid, FALSE); + if (guser == NULL) { + ERR("cannot get user information from gumd"); + return -1; + } + + g_object_get(G_OBJECT(guser), "usertype", &ut, NULL); + if (ut == GUM_USERTYPE_NONE) { + ERR("cannot get user type"); + g_object_unref(guser); + return -1; + } else if (ut != GUM_USERTYPE_ADMIN) { + g_object_unref(guser); + return 0; + } + + g_object_unref(guser); + + return 1; +} + +static int __check_caller_permission(uid_t uid, + GDBusMethodInvocation *invocation, GVariant *parameters) +{ + GVariant *v; + uid_t target_uid; + int is_admin; + + v = g_variant_get_child_value(parameters, 0); + if (v == NULL) { + g_dbus_method_invocation_return_error_literal(invocation, + G_DBUS_ERROR, G_DBUS_ERROR_FAILED, + "Internal error."); + return -1; + } + + target_uid = g_variant_get_uint32(v); + g_variant_unref(v); + if (uid == target_uid) + return 0; + + is_admin = __is_admin_user(uid); + if (is_admin == -1) { + g_dbus_method_invocation_return_error_literal(invocation, + G_DBUS_ERROR, G_DBUS_ERROR_FAILED, + "Internal error."); + return -1; + } else if (is_admin == 0) { + g_dbus_method_invocation_return_error_literal(invocation, + G_DBUS_ERROR, G_DBUS_ERROR_ACCESS_DENIED, + "Non-admin user cannot request operation to " + "other users."); + return -1; + } + + return 0; +} + static int __handle_request_install(uid_t uid, GDBusMethodInvocation *invocation, GVariant *parameters) { @@ -1030,6 +1095,9 @@ static void __handle_method_call(GDBusConnection *connection, if (uid == (uid_t)-1) return; + if (__check_caller_permission(uid, invocation, parameters)) + return; + if (g_strcmp0(method_name, "install") == 0) ret = __handle_request_install(uid, invocation, parameters); else if (g_strcmp0(method_name, "reinstall") == 0) -- 2.7.4 From ef1da22e96d67de02122ded04626e98736d76210 Mon Sep 17 00:00:00 2001 From: Arkadiusz Szulakiewicz Date: Wed, 13 Apr 2016 11:05:06 +0200 Subject: [PATCH 12/16] Add support for mount install Change-Id: I084d0359ece0d0bcaad80ccba1fa022da897f967 --- include/pkgmgr-server.h | 1 + org.tizen.pkgmgr.conf.in | 1 + src/pkgmgr-server.c | 28 +++++++++++++++ src/request.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 121 insertions(+) diff --git a/include/pkgmgr-server.h b/include/pkgmgr-server.h index ea02b8f..602e0fa 100644 --- a/include/pkgmgr-server.h +++ b/include/pkgmgr-server.h @@ -58,6 +58,7 @@ enum request_type { PKGMGR_REQUEST_TYPE_INSTALL, + PKGMGR_REQUEST_TYPE_MOUNT_INSTALL, PKGMGR_REQUEST_TYPE_REINSTALL, PKGMGR_REQUEST_TYPE_UNINSTALL, PKGMGR_REQUEST_TYPE_MOVE, diff --git a/org.tizen.pkgmgr.conf.in b/org.tizen.pkgmgr.conf.in index f3c5caf..c3b0204 100644 --- a/org.tizen.pkgmgr.conf.in +++ b/org.tizen.pkgmgr.conf.in @@ -9,6 +9,7 @@ + diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 6414b57..78ed2b3 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -858,6 +858,29 @@ static int __process_install(pm_dbus_msg *item) return pid; } +static int __process_mount_install(pm_dbus_msg *item) +{ + char *backend_cmd; + char **argv; + char args[MAX_PKG_ARGS_LEN] = {'\0', }; + int pid; + + backend_cmd = _get_backend_cmd(item->pkg_type); + 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); + + argv = __generate_argv(args); + + pid = __fork_and_exec_with_args(argv, item->uid); + g_strfreev(argv); + free(backend_cmd); + + return pid; +} + static int __process_reinstall(pm_dbus_msg *item) { char *backend_cmd; @@ -1361,6 +1384,11 @@ gboolean queue_job(void *data) __set_recovery_mode(item->uid, item->pkgid, item->pkg_type); ret = __process_install(item); break; + case PKGMGR_REQUEST_TYPE_MOUNT_INSTALL: + __set_backend_busy(x); + __set_recovery_mode(item->uid, item->pkgid, item->pkg_type); + ret = __process_mount_install(item); + break; case PKGMGR_REQUEST_TYPE_REINSTALL: __set_backend_busy(x); __set_recovery_mode(item->uid, item->pkgid, item->pkg_type); diff --git a/src/request.c b/src/request.c index 70a7182..daf4d12 100644 --- a/src/request.c +++ b/src/request.c @@ -32,6 +32,14 @@ static const char instropection_xml[] = " " " " " " + " " + " " + " " + " " + " " + " " + " " + " " " " " " " " @@ -321,6 +329,87 @@ catch: return ret; } +static int __handle_request_mount_install(uid_t uid, + GDBusMethodInvocation *invocation, GVariant *parameters) +{ + uid_t target_uid = (uid_t)-1; + char *pkgtype = NULL; + char *pkgpath = NULL; + char *args = NULL; + char *reqkey = NULL; + gchar **tmp_args = NULL; + gsize args_count; + int ret = -1; + GVariant *value; + int i = 0; + int len = 0; + + g_variant_get(parameters, "(u&s&s@as)", &target_uid, &pkgtype, &pkgpath, &value); + tmp_args = (gchar **)g_variant_get_strv(value, &args_count); + + for (i = 0; i < args_count; i++) + len = len + strlen(tmp_args[i]) + 1; + + args = (char *)calloc(len, sizeof(char)); + if (args == NULL) { + ERR("calloc failed"); + ret = -1; + goto catch; + } + + for (i = 0; i < args_count; i++) { + strncat(args, tmp_args[i], strlen(tmp_args[i])); + if (i != args_count - 1) + strncat(args, " ", strlen(" ")); + } + + if (target_uid == (uid_t)-1 || pkgtype == NULL) { + g_dbus_method_invocation_return_value(invocation, + 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, "")); + ret = -1; + goto catch; + } + + reqkey = __generate_reqkey(pkgpath); + if (reqkey == NULL) { + ret = -1; + goto catch; + } + + 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, "")); + ret = -1; + goto catch; + } + + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", + PKGMGR_R_OK, + reqkey)); + ret = 0; + + catch: + if (reqkey) + free(reqkey); + + if (args) + free(args); + + return ret; +} + static int __handle_request_reinstall(uid_t uid, GDBusMethodInvocation *invocation, GVariant *parameters) { @@ -1100,6 +1189,8 @@ static void __handle_method_call(GDBusConnection *connection, if (g_strcmp0(method_name, "install") == 0) ret = __handle_request_install(uid, invocation, parameters); + else if (g_strcmp0(method_name, "mount_install") == 0) + ret = __handle_request_mount_install(uid, invocation, parameters); else if (g_strcmp0(method_name, "reinstall") == 0) ret = __handle_request_reinstall(uid, invocation, parameters); else if (g_strcmp0(method_name, "uninstall") == 0) -- 2.7.4 From dbf600d69b3cb2d24d63165da9cf5e801397fedf Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Fri, 22 Apr 2016 15:06:47 +0900 Subject: [PATCH 13/16] Implement restriction mode For setting restriction mode, pkgmgr-server will make a file at /run/user// This file contains current restriction mode. Since this directory is volitile, it will be deleted if the user session closed. Change-Id: Ic665cbefc40e1010d266d809def549ab36eb51eb Signed-off-by: Sangyoon Jang --- CMakeLists.txt | 9 ++- include/pkgmgr-server.h | 6 ++ org.tizen.pkgmgr.conf.in | 3 + packaging/pkgmgr-server.spec | 1 + src/pkgmgr-server.c | 50 ++++++++++++ src/request.c | 139 ++++++++++++++++++++++++++++++- src/restriction_mode.c | 189 +++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 395 insertions(+), 2 deletions(-) create mode 100644 src/restriction_mode.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d89a0b..917b6f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ SET(LIBDIR ${LIB_INSTALL_DIR}) SET(INCLUDEDIR "\${prefix}/include") ADD_DEFINITIONS(-DDB_DIR="${DB_DIR}") +ADD_DEFINITIONS(-DRUN_DIR="${RUN_DIR}") ADD_DEFINITIONS(-DBACKEND_DIR="${BACKEND_DIR}") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -g -Wall") @@ -20,7 +21,13 @@ INCLUDE_DIRECTORIES(include) INCLUDE(FindPkgConfig) SET(PKGMGR_SERVER "pkgmgr-server") -SET(SRCS src/pkgmgr-server.c src/request.c src/pm-queue.c src/db.c) +SET(SRCS + src/pkgmgr-server.c + src/request.c + src/pm-queue.c + src/db.c + src/restriction_mode.c + ) pkg_check_modules(SERVER_DEPS REQUIRED gio-2.0 diff --git a/include/pkgmgr-server.h b/include/pkgmgr-server.h index 602e0fa..5faf134 100644 --- a/include/pkgmgr-server.h +++ b/include/pkgmgr-server.h @@ -81,6 +81,9 @@ enum request_type { PKGMGR_REQUEST_TYPE_CHECK_BLACKLIST, PKGMGR_REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN, PKGMGR_REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN, + PKGMGR_REQUEST_TYPE_SET_RESTRICTION_MODE, + PKGMGR_REQUEST_TYPE_UNSET_RESTRICTION_MODE, + PKGMGR_REQUEST_TYPE_GET_RESTRICTION_MODE, }; typedef struct { @@ -110,5 +113,8 @@ void __fini_request_handler(void); int __add_blacklist(uid_t uid, const char *pkgid); int __remove_blacklist(uid_t uid, const char *pkgid); int __check_blacklist(uid_t uid, const char *pkgid, int *result); +int __set_restriction_mode(uid_t uid, int mode); +int __unset_restriction_mode(uid_t uid, int mode); +int __get_restriction_mode(uid_t uid, int *result); #endif/* _PKGMGR_SERVER_H_ */ diff --git a/org.tizen.pkgmgr.conf.in b/org.tizen.pkgmgr.conf.in index c3b0204..6aeb6f4 100644 --- a/org.tizen.pkgmgr.conf.in +++ b/org.tizen.pkgmgr.conf.in @@ -27,5 +27,8 @@ + + + diff --git a/packaging/pkgmgr-server.spec b/packaging/pkgmgr-server.spec index 7c9768d..5dd8633 100644 --- a/packaging/pkgmgr-server.spec +++ b/packaging/pkgmgr-server.spec @@ -38,6 +38,7 @@ Packager Manager server package for packaging cp %{SOURCE1001} . %define db_dir %{_localstatedir}/lib/package-manager +%define run_dir /run/user %define backend_dir %{_sysconfdir}/package-manager/backend %build diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 78ed2b3..ada3f99 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -1348,6 +1348,47 @@ static int __process_update_app_splash_screen(pm_dbus_msg *item, int flag) return ret; } +static int __process_set_restriction_mode(pm_dbus_msg *item) +{ + int ret; + int mode; + + mode = atoi(item->args); + ret = __set_restriction_mode(item->uid, mode); + + __return_value_to_caller(item->req_id, + g_variant_new("(i)", ret)); + + return ret; +} + +static int __process_unset_restriction_mode(pm_dbus_msg *item) +{ + int ret; + int mode; + + mode = atoi(item->args); + ret = __unset_restriction_mode(item->uid, mode); + + __return_value_to_caller(item->req_id, + g_variant_new("(i)", ret)); + + return ret; +} + +static int __process_get_restriction_mode(pm_dbus_msg *item) +{ + int ret; + int result = -1; + + ret = __get_restriction_mode(item->uid, &result); + + __return_value_to_caller(item->req_id, + g_variant_new("(ii)", result, ret)); + + return ret; +} + gboolean queue_job(void *data) { pm_dbus_msg *item = NULL; @@ -1464,6 +1505,15 @@ gboolean queue_job(void *data) case PKGMGR_REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN: ret = __process_update_app_splash_screen(item, 0); break; + case PKGMGR_REQUEST_TYPE_SET_RESTRICTION_MODE: + ret = __process_set_restriction_mode(item); + break; + case PKGMGR_REQUEST_TYPE_UNSET_RESTRICTION_MODE: + ret = __process_unset_restriction_mode(item); + break; + case PKGMGR_REQUEST_TYPE_GET_RESTRICTION_MODE: + ret = __process_get_restriction_mode(item); + break; default: ret = -1; break; diff --git a/src/request.c b/src/request.c index daf4d12..e2c6871 100644 --- a/src/request.c +++ b/src/request.c @@ -159,6 +159,21 @@ static const char instropection_xml[] = " " " " " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " " " ""; static GDBusNodeInfo *instropection_data; @@ -1093,7 +1108,6 @@ static int __handle_request_check_blacklist(uid_t uid, return 0; } - static int __update_app_splash_screen(uid_t uid, GDBusMethodInvocation *invocation, GVariant *parameters, int req_type) @@ -1148,6 +1162,120 @@ static int __handle_request_disable_app_splash_screen(uid_t uid, PKGMGR_REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN); } +static int __handle_request_set_restriction_mode(uid_t uid, + GDBusMethodInvocation *invocation, GVariant *parameters) +{ + uid_t target_uid = (uid_t)-1; + char *reqkey; + int mode = -1; + char buf[4]; + + g_variant_get(parameters, "(ui)", &target_uid, &mode); + if (target_uid == (uid_t)-1 || mode < 0) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(i)", PKGMGR_R_ECOMM)); + return -1; + } + + reqkey = __generate_reqkey("restriction"); + if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(i)", PKGMGR_R_ENOMEM)); + return -1; + } + + snprintf(buf, sizeof(buf), "%d", mode); + if (_pm_queue_push(target_uid, reqkey, + PKGMGR_REQUEST_TYPE_SET_RESTRICTION_MODE, + "default", "", buf)) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(i)", PKGMGR_R_ESYSTEM)); + free(reqkey); + return -1; + } + + if (!g_hash_table_insert(req_table, (gpointer)reqkey, + (gpointer)invocation)) + ERR("reqkey already exists"); + + return 0; +} + +static int __handle_request_unset_restriction_mode(uid_t uid, + GDBusMethodInvocation *invocation, GVariant *parameters) +{ + uid_t target_uid = (uid_t)-1; + char *reqkey; + int mode = -1; + char buf[4]; + + g_variant_get(parameters, "(ui)", &target_uid, &mode); + if (target_uid == (uid_t)-1 || mode < 0) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(i)", PKGMGR_R_ECOMM)); + return -1; + } + + reqkey = __generate_reqkey("restriction"); + if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(i)", PKGMGR_R_ENOMEM)); + return -1; + } + + snprintf(buf, sizeof(buf), "%d", mode); + if (_pm_queue_push(target_uid, reqkey, + PKGMGR_REQUEST_TYPE_UNSET_RESTRICTION_MODE, + "default", "", buf)) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(i)", PKGMGR_R_ESYSTEM)); + free(reqkey); + return -1; + } + + if (!g_hash_table_insert(req_table, (gpointer)reqkey, + (gpointer)invocation)) + ERR("reqkey already exists"); + + return 0; +} + +static int __handle_request_get_restriction_mode(uid_t uid, + GDBusMethodInvocation *invocation, GVariant *parameters) +{ + uid_t target_uid = (uid_t)-1; + char *reqkey; + + g_variant_get(parameters, "(u)", &target_uid); + if (target_uid == (uid_t)-1) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(i)", PKGMGR_R_ECOMM)); + return -1; + } + + reqkey = __generate_reqkey("restriction"); + if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(ii)", -1, PKGMGR_R_ENOMEM)); + return -1; + } + + if (_pm_queue_push(target_uid, reqkey, + PKGMGR_REQUEST_TYPE_GET_RESTRICTION_MODE, + "default", "", "")) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(ii)", -1, PKGMGR_R_ESYSTEM)); + free(reqkey); + return -1; + } + + if (!g_hash_table_insert(req_table, (gpointer)reqkey, + (gpointer)invocation)) + ERR("reqkey already exists"); + + return 0; +} + static uid_t __get_caller_uid(GDBusConnection *connection, const char *name) { GError *err = NULL; @@ -1243,6 +1371,15 @@ static void __handle_method_call(GDBusConnection *connection, else if (g_strcmp0(method_name, "enable_app_splash_screen") == 0) ret = __handle_request_enable_app_splash_screen(uid, invocation, parameters); + else if (g_strcmp0(method_name, "set_restriction_mode") == 0) + ret = __handle_request_set_restriction_mode(uid, invocation, + parameters); + else if (g_strcmp0(method_name, "unset_restriction_mode") == 0) + ret = __handle_request_unset_restriction_mode(uid, invocation, + parameters); + else if (g_strcmp0(method_name, "get_restriction_mode") == 0) + ret = __handle_request_get_restriction_mode(uid, invocation, + parameters); else ret = -1; diff --git a/src/restriction_mode.c b/src/restriction_mode.c new file mode 100644 index 0000000..50fe8d5 --- /dev/null +++ b/src/restriction_mode.c @@ -0,0 +1,189 @@ +/* + * 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 +#include +#include + +#include "pkgmgr-server.h" + +#ifndef RUN_DIR +#define RUN_DIR "/run/user" +#endif + +#define RESTRICTION_CONF ".package_manager_restriction_mode" + +static char *_get_conf_file_path(uid_t uid) +{ + char buf[PATH_MAX]; + + snprintf(buf, sizeof(buf), "%s/%d/%s", RUN_DIR, uid, RESTRICTION_CONF); + + return strdup(buf); +} + +static int __set_mode(int cur, int mode) +{ + return cur | mode; +} + +static int __unset_mode(int cur, int mode) +{ + return cur & ~(mode); +} + +int __set_restriction_mode(uid_t uid, int mode) +{ + char *conf_path; + int fd; + int cur = 0; + ssize_t len; + + conf_path = _get_conf_file_path(uid); + if (conf_path == NULL) { + ERR("failed to get conf path"); + return -1; + } + + fd = open(conf_path, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); + if (fd < 0) { + ERR("failed to open conf file: %d", errno); + free(conf_path); + return -1; + } + + len = read(fd, &cur, sizeof(int)); + if (len < 0) { + ERR("failed to read conf file: %d", errno); + close(fd); + free(conf_path); + return -1; + } + + mode = __set_mode(cur, mode); + + lseek(fd, 0, SEEK_SET); + len = write(fd, &mode, sizeof(int)); + if (len < 0) { + ERR("failed to write conf file: %d", errno); + close(fd); + free(conf_path); + return -1; + } + + close(fd); + free(conf_path); + + return 0; +} + +int __unset_restriction_mode(uid_t uid, int mode) +{ + char *conf_path; + int fd; + int cur = 0; + ssize_t len; + + conf_path = _get_conf_file_path(uid); + if (conf_path == NULL) { + ERR("failed to get conf path"); + return -1; + } + + if (access(conf_path, F_OK) != 0) { + ERR("restriction mode is not set"); + free(conf_path); + return 0; + } + + fd = open(conf_path, O_RDWR, 0); + if (fd < 0) { + ERR("failed to open conf file: %s", errno); + free(conf_path); + return -1; + } + + len = read(fd, &cur, sizeof(int)); + if (len < 0) { + ERR("failed to read conf file: %d", errno); + close(fd); + free(conf_path); + return -1; + } + + mode = __unset_mode(cur, mode); + + lseek(fd, 0, SEEK_SET); + len = write(fd, &mode, sizeof(int)); + if (len < 0) { + ERR("failed to write conf file: %d", errno); + close(fd); + free(conf_path); + return -1; + } + + close(fd); + free(conf_path); + + return 0; +} + +int __get_restriction_mode(uid_t uid, int *result) +{ + char *conf_path; + int fd; + int cur; + ssize_t len; + + conf_path = _get_conf_file_path(uid); + if (conf_path == NULL) + return -1; + + if (access(conf_path, F_OK) != 0) { + free(conf_path); + *result = 0; + return 0; + } + + fd = open(conf_path, O_RDONLY, 0); + if (fd < 0) { + ERR("failed to open conf file: %s", errno); + free(conf_path); + return -1; + } + + len = read(fd, &cur, sizeof(int)); + if (len < 0) { + ERR("failed to read conf file: %d", errno); + close(fd); + free(conf_path); + return -1; + } + + *result = cur; + + close(fd); + free(conf_path); + + return 0; +} -- 2.7.4 From b06797764d79c49e5c2643ff877482fa9c792da4 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Fri, 13 May 2016 18:41:52 +0900 Subject: [PATCH 14/16] Redesign restriction mode - Remove blacklist feature(merged to restriction mode) - Use gdbm to store mode - set/unset/get by pkgid Change-Id: I3da360eb5b20471c5249f8445b96560c7fead598 Signed-off-by: Sangyoon Jang --- CMakeLists.txt | 4 +- blacklist.sql | 8 -- include/pkgmgr-server.h | 12 +-- org.tizen.pkgmgr.conf.in | 8 +- packaging/pkgmgr-server.spec | 11 +-- src/db.c | 217 ----------------------------------------- src/pkgmgr-server.c | 56 +---------- src/request.c | 160 +++--------------------------- src/restriction_mode.c | 225 ++++++++++++++++++++++--------------------- 9 files changed, 146 insertions(+), 555 deletions(-) delete mode 100644 blacklist.sql delete mode 100644 src/db.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 917b6f3..9b8829e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,6 @@ SET(SRCS src/pkgmgr-server.c src/request.c src/pm-queue.c - src/db.c src/restriction_mode.c ) @@ -36,7 +35,6 @@ pkg_check_modules(SERVER_DEPS REQUIRED pkgmgr-info libtzplatform-config drm-service-core-tizen - sqlite3 libgum pkgmgr pkgmgr-installer) @@ -46,7 +44,7 @@ ENDFOREACH(SERVER_FLAGS) ADD_EXECUTABLE(${PKGMGR_SERVER} ${SRCS}) TARGET_LINK_LIBRARIES(${PKGMGR_SERVER} pkgmgr_installer) -TARGET_LINK_LIBRARIES(${PKGMGR_SERVER} ${SERVER_DEPS_LDFLAGS}) +TARGET_LINK_LIBRARIES(${PKGMGR_SERVER} ${SERVER_DEPS_LDFLAGS} -lgdbm) CONFIGURE_FILE(org.tizen.pkgmgr.service.in org.tizen.pkgmgr.service @ONLY) CONFIGURE_FILE(org.tizen.pkgmgr.conf.in org.tizen.pkgmgr.conf @ONLY) diff --git a/blacklist.sql b/blacklist.sql deleted file mode 100644 index 0db3ddb..0000000 --- a/blacklist.sql +++ /dev/null @@ -1,8 +0,0 @@ -PRAGMA user_version = 30; /* Tizen 3.0 */ -PRAGMA journal_mode = WAL; - -CREATE TABLE blacklist ( - uid INTEGER NOT NULL, - pkgid TEXT NOT NULL, - UNIQUE (uid, pkgid) -); diff --git a/include/pkgmgr-server.h b/include/pkgmgr-server.h index 5faf134..8a49751 100644 --- a/include/pkgmgr-server.h +++ b/include/pkgmgr-server.h @@ -76,9 +76,6 @@ enum request_type { PKGMGR_REQUEST_TYPE_GENERATE_LICENSE_REQUEST, PKGMGR_REQUEST_TYPE_REGISTER_LICENSE, PKGMGR_REQUEST_TYPE_DECRYPT_PACKAGE, - PKGMGR_REQUEST_TYPE_ADD_BLACKLIST, - PKGMGR_REQUEST_TYPE_REMOVE_BLACKLIST, - PKGMGR_REQUEST_TYPE_CHECK_BLACKLIST, PKGMGR_REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN, PKGMGR_REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN, PKGMGR_REQUEST_TYPE_SET_RESTRICTION_MODE, @@ -110,11 +107,8 @@ 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); -int __add_blacklist(uid_t uid, const char *pkgid); -int __remove_blacklist(uid_t uid, const char *pkgid); -int __check_blacklist(uid_t uid, const char *pkgid, int *result); -int __set_restriction_mode(uid_t uid, int mode); -int __unset_restriction_mode(uid_t uid, int mode); -int __get_restriction_mode(uid_t uid, int *result); +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); #endif/* _PKGMGR_SERVER_H_ */ diff --git a/org.tizen.pkgmgr.conf.in b/org.tizen.pkgmgr.conf.in index 6aeb6f4..bee2a29 100644 --- a/org.tizen.pkgmgr.conf.in +++ b/org.tizen.pkgmgr.conf.in @@ -5,6 +5,9 @@ + + + @@ -27,8 +30,5 @@ - - - - + diff --git a/packaging/pkgmgr-server.spec b/packaging/pkgmgr-server.spec index 5dd8633..4ea86ec 100644 --- a/packaging/pkgmgr-server.spec +++ b/packaging/pkgmgr-server.spec @@ -24,8 +24,8 @@ BuildRequires: pkgconfig(libsmack) BuildRequires: pkgconfig(pkgmgr) BuildRequires: pkgconfig(pkgmgr-installer) BuildRequires: pkgconfig(drm-service-core-tizen) -BuildRequires: pkgconfig(sqlite3) BuildRequires: pkgconfig(libgum) +BuildRequires: gdbm-devel BuildRequires: pkgmgr-info-parser-devel BuildRequires: pkgmgr-info-parser BuildRequires: fdupes @@ -37,14 +37,11 @@ Packager Manager server package for packaging %setup -q cp %{SOURCE1001} . -%define db_dir %{_localstatedir}/lib/package-manager %define run_dir /run/user %define backend_dir %{_sysconfdir}/package-manager/backend %build -sqlite3 blacklist.db < ./blacklist.sql - -%cmake . -DDB_DIR=%{db_dir} -DBACKEND_DIR=%{backend_dir} +%cmake . -DRUN_DIR=%{run_dir} -DBACKEND_DIR=%{backend_dir} %__make %{?_smp_mflags} @@ -55,9 +52,6 @@ mkdir -p %{buildroot}/usr/share/license cp LICENSE %{buildroot}/usr/share/license/%{name} mkdir -p %{buildroot}%{_sysconfdir}/package-manager/server -mkdir -p %{buildroot}%{db_dir} -install -m 0600 blacklist.db %{buildroot}%{db_dir} - %fdupes %{buildroot} %post @@ -70,6 +64,5 @@ install -m 0600 blacklist.db %{buildroot}%{db_dir} %config %{_sysconfdir}/dbus-1/system.d/org.tizen.pkgmgr.conf %{_bindir}/pkgmgr-server %{_sysconfdir}/package-manager/server -%config(noreplace) %{db_dir}/blacklist.db %exclude %{_sysconfdir}/package-manager/server/queue_status /usr/share/license/%{name} diff --git a/src/db.c b/src/db.c deleted file mode 100644 index 68b8cdf..0000000 --- a/src/db.c +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Copyright (c) 2000 - 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 "pkgmgr-server.h" - -#ifndef DB_DIR -#define DB_DIR "/var/lib/package-manager" -#endif - -static const char *_get_db_path(void) -{ - return DB_DIR"/blacklist.db"; -} - -static sqlite3 *_open_db(void) -{ - int ret; - const char *path; - sqlite3 *db; - - path = _get_db_path(); - if (path == NULL) { - ERR("get db path error"); - return NULL; - } - - ret = sqlite3_open_v2(path, &db, SQLITE_OPEN_READWRITE, NULL); - if (ret != SQLITE_OK) { - ERR("open db error: %d", ret); - return NULL; - } - - return db; -} - -static int __add_blacklist_info(sqlite3 *db, uid_t uid, const char *pkgid) -{ - static const char query[] = - "INSERT INTO blacklist (uid, pkgid) VALUES(?, ?)"; - int ret; - sqlite3_stmt *stmt; - - ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); - if (ret != SQLITE_OK) { - ERR("prepare error: %s", sqlite3_errmsg(db)); - return -1; - } - - sqlite3_bind_int(stmt, 1, uid); - sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_STATIC); - - ret = sqlite3_step(stmt); - sqlite3_finalize(stmt); - if (ret != SQLITE_DONE) { - ERR("step error: %s", sqlite3_errmsg(db)); - return -1; - } - - return 0; -} - -int __add_blacklist(uid_t uid, const char *pkgid) -{ - int ret; - sqlite3 *db; - - db = _open_db(); - if (db == NULL) - return PKGMGR_R_ERROR; - - ret = sqlite3_exec(db, "BEGIN EXCLUSIVE", NULL, NULL, NULL); - if (ret != SQLITE_OK) { - sqlite3_close_v2(db); - ERR("transaction failed"); - return PKGMGR_R_ERROR; - } - - if (__add_blacklist_info(db, uid, pkgid)) { - sqlite3_exec(db, "ROLLBACK", NULL, NULL, NULL); - sqlite3_close_v2(db); - return PKGMGR_R_ERROR; - } - - ret = sqlite3_exec(db, "COMMIT", NULL, NULL, NULL); - if (ret != SQLITE_OK) { - ERR("commit error: %s", sqlite3_errmsg(db)); - sqlite3_close_v2(db); - return PKGMGR_R_ERROR; - } - - sqlite3_close_v2(db); - - return PKGMGR_R_OK; -} - -static int __remove_blacklist_info(sqlite3 *db, uid_t uid, const char *pkgid) -{ - static const char query[] = - "DELETE FROM blacklist WHERE uid=? AND pkgid=?"; - int ret; - sqlite3_stmt *stmt; - - ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); - if (ret != SQLITE_OK) { - ERR("prepare error: %s", sqlite3_errmsg(db)); - return -1; - } - - sqlite3_bind_int(stmt, 1, uid); - sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_STATIC); - - ret = sqlite3_step(stmt); - sqlite3_finalize(stmt); - if (ret != SQLITE_DONE) { - ERR("step error: %s", sqlite3_errmsg(db)); - return -1; - } - - return 0; -} - -int __remove_blacklist(uid_t uid, const char *pkgid) -{ - int ret; - sqlite3 *db; - - db = _open_db(); - if (db == NULL) - return PKGMGR_R_ERROR; - - ret = sqlite3_exec(db, "BEGIN EXCLUSIVE", NULL, NULL, NULL); - if (ret != SQLITE_OK) { - sqlite3_close_v2(db); - ERR("transaction failed"); - return PKGMGR_R_ERROR; - } - - if (__remove_blacklist_info(db, uid, pkgid)) { - sqlite3_exec(db, "ROLLBACK", NULL, NULL, NULL); - sqlite3_close_v2(db); - return PKGMGR_R_ERROR; - } - - ret = sqlite3_exec(db, "COMMIT", NULL, NULL, NULL); - if (ret != SQLITE_OK) { - ERR("commit error: %s", sqlite3_errmsg(db)); - sqlite3_close_v2(db); - return PKGMGR_R_ERROR; - } - - sqlite3_close_v2(db); - - return PKGMGR_R_OK; -} - -int __check_blacklist(uid_t uid, const char *pkgid, int *result) -{ - static const char query[] = - "SELECT * FROM blacklist WHERE uid=? AND pkgid=?"; - int ret; - sqlite3 *db; - sqlite3_stmt *stmt; - - db = _open_db(); - if (db == NULL) { - *result = 0; - return PKGMGR_R_ERROR; - } - - ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); - if (ret != SQLITE_OK) { - ERR("prepare error: %s", sqlite3_errmsg(db)); - *result = 0; - sqlite3_close_v2(db); - return PKGMGR_R_ERROR; - } - - sqlite3_bind_int(stmt, 1, uid); - sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_STATIC); - - ret = sqlite3_step(stmt); - sqlite3_finalize(stmt); - if (ret != SQLITE_ROW) { - if (ret != SQLITE_DONE) - ERR("step error: %s", sqlite3_errmsg(db)); - *result = 0; - sqlite3_close_v2(db); - return ret == SQLITE_DONE ? PKGMGR_R_OK : PKGMGR_R_ERROR; - } - - *result = 1; - sqlite3_close_v2(db); - - return PKGMGR_R_OK; -} diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index ada3f99..58f79f0 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -1276,43 +1276,6 @@ static int __process_decrypt_package(pm_dbus_msg *item) return 0; } -static int __process_add_blacklist(pm_dbus_msg *item) -{ - int ret; - - ret = __add_blacklist(item->uid, item->pkgid); - - __return_value_to_caller(item->req_id, - g_variant_new("(i)", ret)); - - return ret; -} - -static int __process_remove_blacklist(pm_dbus_msg *item) -{ - int ret; - - ret = __remove_blacklist(item->uid, item->pkgid); - - __return_value_to_caller(item->req_id, - g_variant_new("(i)", ret)); - - return ret; -} - -static int __process_check_blacklist(pm_dbus_msg *item) -{ - int ret; - int result = 0; - - ret = __check_blacklist(item->uid, item->pkgid, &result); - - __return_value_to_caller(item->req_id, - g_variant_new("(ii)", result, ret)); - - return ret; -} - static int __process_update_app_splash_screen(pm_dbus_msg *item, int flag) { int ret; @@ -1354,7 +1317,7 @@ static int __process_set_restriction_mode(pm_dbus_msg *item) int mode; mode = atoi(item->args); - ret = __set_restriction_mode(item->uid, mode); + ret = __restriction_mode_set(item->uid, item->pkgid, mode); __return_value_to_caller(item->req_id, g_variant_new("(i)", ret)); @@ -1368,7 +1331,7 @@ static int __process_unset_restriction_mode(pm_dbus_msg *item) int mode; mode = atoi(item->args); - ret = __unset_restriction_mode(item->uid, mode); + ret = __restriction_mode_unset(item->uid, item->pkgid, mode); __return_value_to_caller(item->req_id, g_variant_new("(i)", ret)); @@ -1379,12 +1342,12 @@ static int __process_unset_restriction_mode(pm_dbus_msg *item) static int __process_get_restriction_mode(pm_dbus_msg *item) { int ret; - int result = -1; + int mode = -1; - ret = __get_restriction_mode(item->uid, &result); + ret = __restriction_mode_get(item->uid, item->pkgid, &mode); __return_value_to_caller(item->req_id, - g_variant_new("(ii)", result, ret)); + g_variant_new("(ii)", mode, ret)); return ret; } @@ -1490,15 +1453,6 @@ gboolean queue_job(void *data) case PKGMGR_REQUEST_TYPE_DECRYPT_PACKAGE: ret = __process_decrypt_package(item); break; - case PKGMGR_REQUEST_TYPE_ADD_BLACKLIST: - ret = __process_add_blacklist(item); - break; - case PKGMGR_REQUEST_TYPE_REMOVE_BLACKLIST: - ret = __process_remove_blacklist(item); - break; - case PKGMGR_REQUEST_TYPE_CHECK_BLACKLIST: - ret = __process_check_blacklist(item); - break; case PKGMGR_REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN: ret = __process_update_app_splash_screen(item, 1); break; diff --git a/src/request.c b/src/request.c index e2c6871..ba99bf0 100644 --- a/src/request.c +++ b/src/request.c @@ -133,22 +133,6 @@ static const char instropection_xml[] = " " " " " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " " " " " " " @@ -161,16 +145,19 @@ static const char instropection_xml[] = " " " " " " + " " " " " " " " " " " " + " " " " " " " " " " " " + " " " " " " " " @@ -997,117 +984,6 @@ static int __handle_request_decrypt_package(uid_t uid, return 0; } -static int __handle_request_add_blacklist(uid_t uid, - GDBusMethodInvocation *invocation, GVariant *parameters) -{ - uid_t target_uid = (uid_t)-1; - char *reqkey; - char *pkgid = 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)); - return -1; - } - - reqkey = __generate_reqkey("blacklist"); - 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_ADD_BLACKLIST, - "default", pkgid, "")) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ESYSTEM)); - free(reqkey); - return -1; - } - - if (!g_hash_table_insert(req_table, (gpointer)reqkey, - (gpointer)invocation)) - ERR("reqkey already exists"); - - return 0; -} - -static int __handle_request_remove_blacklist(uid_t uid, - GDBusMethodInvocation *invocation, GVariant *parameters) -{ - uid_t target_uid = (uid_t)-1; - char *reqkey; - char *pkgid = 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)); - return -1; - } - - reqkey = __generate_reqkey("blacklist"); - 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_REMOVE_BLACKLIST, - "default", pkgid, "")) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ESYSTEM)); - free(reqkey); - return -1; - } - - if (!g_hash_table_insert(req_table, (gpointer)reqkey, - (gpointer)invocation)) - ERR("reqkey already exists"); - - return 0; -} - -static int __handle_request_check_blacklist(uid_t uid, - GDBusMethodInvocation *invocation, GVariant *parameters) -{ - uid_t target_uid = (uid_t)-1; - char *reqkey; - char *pkgid = 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("(ii)", PKGMGR_R_ECOMM, -1)); - return -1; - } - - reqkey = __generate_reqkey("blacklist"); - if (reqkey == NULL) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(ii)", PKGMGR_R_ENOMEM, -1)); - return -1; - } - - if (_pm_queue_push(target_uid, reqkey, - PKGMGR_REQUEST_TYPE_CHECK_BLACKLIST, - "default", pkgid, "")) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(ii)", PKGMGR_R_ESYSTEM, -1)); - free(reqkey); - return -1; - } - - if (!g_hash_table_insert(req_table, (gpointer)reqkey, - (gpointer)invocation)) - ERR("reqkey already exists"); - - return 0; -} - static int __update_app_splash_screen(uid_t uid, GDBusMethodInvocation *invocation, GVariant *parameters, int req_type) @@ -1166,12 +1042,13 @@ static int __handle_request_set_restriction_mode(uid_t uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; + char *pkgid = NULL; char *reqkey; int mode = -1; char buf[4]; - g_variant_get(parameters, "(ui)", &target_uid, &mode); - if (target_uid == (uid_t)-1 || mode < 0) { + g_variant_get(parameters, "(usi)", &target_uid, &pkgid, &mode); + if (target_uid == (uid_t)-1 || pkgid == NULL || mode < 0) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ECOMM)); return -1; @@ -1187,7 +1064,7 @@ static int __handle_request_set_restriction_mode(uid_t uid, snprintf(buf, sizeof(buf), "%d", mode); if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_SET_RESTRICTION_MODE, - "default", "", buf)) { + "default", pkgid, buf)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); free(reqkey); @@ -1205,12 +1082,13 @@ static int __handle_request_unset_restriction_mode(uid_t uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; + char *pkgid = NULL; char *reqkey; int mode = -1; char buf[4]; - g_variant_get(parameters, "(ui)", &target_uid, &mode); - if (target_uid == (uid_t)-1 || mode < 0) { + g_variant_get(parameters, "(usi)", &target_uid, &pkgid, &mode); + if (target_uid == (uid_t)-1 || pkgid == NULL || mode < 0) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ECOMM)); return -1; @@ -1226,7 +1104,7 @@ static int __handle_request_unset_restriction_mode(uid_t uid, snprintf(buf, sizeof(buf), "%d", mode); if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_UNSET_RESTRICTION_MODE, - "default", "", buf)) { + "default", pkgid, buf)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); free(reqkey); @@ -1244,10 +1122,11 @@ static int __handle_request_get_restriction_mode(uid_t uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; + char *pkgid = NULL; char *reqkey; - g_variant_get(parameters, "(u)", &target_uid); - if (target_uid == (uid_t)-1) { + g_variant_get(parameters, "(us)", &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)); return -1; @@ -1262,7 +1141,7 @@ static int __handle_request_get_restriction_mode(uid_t uid, if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_GET_RESTRICTION_MODE, - "default", "", "")) { + "default", pkgid, "")) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(ii)", -1, PKGMGR_R_ESYSTEM)); free(reqkey); @@ -1356,15 +1235,6 @@ static void __handle_method_call(GDBusConnection *connection, else if (g_strcmp0(method_name, "decrypt_package") == 0) ret = __handle_request_decrypt_package(uid, invocation, parameters); - else if (g_strcmp0(method_name, "add_blacklist") == 0) - ret = __handle_request_add_blacklist(uid, invocation, - parameters); - else if (g_strcmp0(method_name, "remove_blacklist") == 0) - ret = __handle_request_remove_blacklist(uid, invocation, - parameters); - else if (g_strcmp0(method_name, "check_blacklist") == 0) - ret = __handle_request_check_blacklist(uid, invocation, - parameters); else if (g_strcmp0(method_name, "disable_app_splash_screen") == 0) ret = __handle_request_disable_app_splash_screen(uid, invocation, parameters); diff --git a/src/restriction_mode.c b/src/restriction_mode.c index 50fe8d5..c7ee92c 100644 --- a/src/restriction_mode.c +++ b/src/restriction_mode.c @@ -1,43 +1,27 @@ -/* - * 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 #include -#include #include +#include + #include "pkgmgr-server.h" #ifndef RUN_DIR #define RUN_DIR "/run/user" #endif +#define RESTRICTION_DB ".package_manager_restriction_mode" +#define VAL_SIZE sizeof(int) +#define ALL_PKG "ALL_PKG" -#define RESTRICTION_CONF ".package_manager_restriction_mode" - -static char *_get_conf_file_path(uid_t uid) +static char *__get_dbpath(uid_t uid) { char buf[PATH_MAX]; - snprintf(buf, sizeof(buf), "%s/%d/%s", RUN_DIR, uid, RESTRICTION_CONF); + snprintf(buf, sizeof(buf), "%s/%d/%s", RUN_DIR, uid, RESTRICTION_DB); return strdup(buf); } @@ -52,138 +36,161 @@ static int __unset_mode(int cur, int mode) return cur & ~(mode); } -int __set_restriction_mode(uid_t uid, int mode) +static GDBM_FILE __open(const char *path, bool writable) { - char *conf_path; - int fd; - int cur = 0; - ssize_t len; + GDBM_FILE db; + + db = gdbm_open((char *)path, 0, writable ? GDBM_WRCREAT : GDBM_READER, + S_IRUSR | S_IWUSR, NULL); + if (db == NULL) + ERR("failed to open gdbm file(%s): %d", path, gdbm_errno); - conf_path = _get_conf_file_path(uid); - if (conf_path == NULL) { - ERR("failed to get conf path"); + return db; +} + +static void __close(GDBM_FILE dbf) +{ + gdbm_close(dbf); +} + +static int __set_value(GDBM_FILE dbf, const char *pkgid, int mode) +{ + datum key; + datum content; + char buf[VAL_SIZE]; + + key.dptr = (char *)pkgid; + key.dsize = strlen(pkgid) + 1; + + memcpy(buf, &mode, VAL_SIZE); + content.dptr = buf; + content.dsize = VAL_SIZE; + + if (gdbm_store(dbf, key, content, GDBM_REPLACE)) { + ERR("failed to store value"); return -1; } - fd = open(conf_path, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); - if (fd < 0) { - ERR("failed to open conf file: %d", errno); - free(conf_path); + return 0; +} + +static int __get_value(GDBM_FILE dbf, const char *pkgid, int *mode) +{ + datum key; + datum content; + + key.dptr = (char *)pkgid; + key.dsize = strlen(pkgid) + 1; + + content = gdbm_fetch(dbf, key); + if (content.dptr == NULL) { + DBG("no value for key(%s)", pkgid); return -1; } - len = read(fd, &cur, sizeof(int)); - if (len < 0) { - ERR("failed to read conf file: %d", errno); - close(fd); - free(conf_path); + if (content.dsize != VAL_SIZE) + ERR("content size is different"); + + memcpy(mode, content.dptr, VAL_SIZE); + free(content.dptr); + + return 0; +} + +int __restriction_mode_set(uid_t uid, const char *pkgid, int mode) +{ + GDBM_FILE dbf; + char *dbpath; + int cur = 0; + + if (pkgid == NULL || !strcmp(pkgid, "")) + pkgid = ALL_PKG; + + dbpath = __get_dbpath(uid); + if (dbpath == NULL) + return -1; + + dbf = __open(dbpath, true); + if (dbf == NULL) { + free(dbpath); return -1; } + __get_value(dbf, pkgid, &cur); mode = __set_mode(cur, mode); - lseek(fd, 0, SEEK_SET); - len = write(fd, &mode, sizeof(int)); - if (len < 0) { - ERR("failed to write conf file: %d", errno); - close(fd); - free(conf_path); + if (__set_value(dbf, pkgid, mode)) { + free(dbpath); return -1; } - close(fd); - free(conf_path); + __close(dbf); + free(dbpath); return 0; } -int __unset_restriction_mode(uid_t uid, int mode) +int __restriction_mode_unset(uid_t uid, const char *pkgid, int mode) { - char *conf_path; - int fd; + GDBM_FILE dbf; + char *dbpath; int cur = 0; - ssize_t len; - conf_path = _get_conf_file_path(uid); - if (conf_path == NULL) { - ERR("failed to get conf path"); - return -1; - } + if (pkgid == NULL || !strcmp(pkgid, "")) + pkgid = ALL_PKG; - if (access(conf_path, F_OK) != 0) { - ERR("restriction mode is not set"); - free(conf_path); - return 0; - } - - fd = open(conf_path, O_RDWR, 0); - if (fd < 0) { - ERR("failed to open conf file: %s", errno); - free(conf_path); + dbpath = __get_dbpath(uid); + if (dbpath == NULL) return -1; - } - len = read(fd, &cur, sizeof(int)); - if (len < 0) { - ERR("failed to read conf file: %d", errno); - close(fd); - free(conf_path); + dbf = __open(dbpath, true); + if (dbf == NULL) { + free(dbpath); return -1; } + __get_value(dbf, pkgid, &cur); mode = __unset_mode(cur, mode); - lseek(fd, 0, SEEK_SET); - len = write(fd, &mode, sizeof(int)); - if (len < 0) { - ERR("failed to write conf file: %d", errno); - close(fd); - free(conf_path); + if (__set_value(dbf, pkgid, mode)) { + free(dbpath); return -1; } - close(fd); - free(conf_path); + __close(dbf); + free(dbpath); return 0; } -int __get_restriction_mode(uid_t uid, int *result) +int __restriction_mode_get(uid_t uid, const char *pkgid, int *mode) { - char *conf_path; - int fd; - int cur; - ssize_t len; + GDBM_FILE dbf; + char *dbpath; - conf_path = _get_conf_file_path(uid); - if (conf_path == NULL) - return -1; - - if (access(conf_path, F_OK) != 0) { - free(conf_path); - *result = 0; - return 0; - } + if (pkgid == NULL || !strcmp(pkgid, "")) + pkgid = ALL_PKG; - fd = open(conf_path, O_RDONLY, 0); - if (fd < 0) { - ERR("failed to open conf file: %s", errno); - free(conf_path); + dbpath = __get_dbpath(uid); + if (dbpath == NULL) return -1; - } - len = read(fd, &cur, sizeof(int)); - if (len < 0) { - ERR("failed to read conf file: %d", errno); - close(fd); - free(conf_path); + dbf = __open(dbpath, false); + if (dbf == NULL) { + if (gdbm_errno == GDBM_FILE_OPEN_ERROR) { + *mode = 0; + return 0; + } + free(dbpath); return -1; } - *result = cur; + if (__get_value(dbf, pkgid, mode)) { + free(dbpath); + } - close(fd); - free(conf_path); + __close(dbf); + free(dbpath); return 0; } -- 2.7.4 From ce32097d814aa00e110ea4ac161c2a8337efd2c5 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Thu, 19 May 2016 19:08:24 +0900 Subject: [PATCH 15/16] Fix checking caller permission Skip checking when caller is system user. Change-Id: I93bc80dd744805b9ccb4ab860426f38fd592dfd7 Signed-off-by: Sangyoon Jang --- src/request.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/request.c b/src/request.c index ba99bf0..e4dda11 100644 --- a/src/request.c +++ b/src/request.c @@ -217,6 +217,7 @@ static int __is_admin_user(uid_t uid) return 1; } +#define REGULAR_USER 5000 static int __check_caller_permission(uid_t uid, GDBusMethodInvocation *invocation, GVariant *parameters) { @@ -224,6 +225,9 @@ static int __check_caller_permission(uid_t uid, uid_t target_uid; int is_admin; + if (uid < REGULAR_USER) + return 0; + v = g_variant_get_child_value(parameters, 0); if (v == NULL) { g_dbus_method_invocation_return_error_literal(invocation, -- 2.7.4 From 4e4aa023d3d21d2cb690f514981b2a5932e1f9e0 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Fri, 27 May 2016 19:43:53 +0900 Subject: [PATCH 16/16] fix clear data behavior Change-Id: I272de791ac3973e3ca9530f0dba1855aeda75474 Signed-off-by: jongmyeongko --- src/request.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/request.c b/src/request.c index e4dda11..58987d9 100644 --- a/src/request.c +++ b/src/request.c @@ -779,6 +779,7 @@ static int __handle_request_cleardata(uid_t uid, uid_t target_uid = (uid_t)-1; char *pkgtype = NULL; char *pkgid = NULL; + char *reqkey = NULL; g_variant_get(parameters, "(u&s&s)", &target_uid, &pkgtype, &pkgid); if (target_uid == (uid_t)-1 || pkgtype == NULL || pkgid == NULL) { @@ -787,7 +788,11 @@ static int __handle_request_cleardata(uid_t uid, return -1; } - if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_CLEARDATA, "pkgtool", + reqkey = __generate_reqkey(pkgid); + if (reqkey == NULL) + return -1; + + if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_CLEARDATA, pkgtype, pkgid, "")) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); @@ -797,6 +802,8 @@ static int __handle_request_cleardata(uid_t uid, g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_OK)); + free(reqkey); + return 0; } -- 2.7.4