From 4999e0273e0dd0b40ccb22dbaa83772d69b68689 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Fri, 28 Oct 2016 21:43:20 +0900 Subject: [PATCH 01/16] Code refactoring - Rewrite queue management code. Data Struture. * struct backend_queue: store each backend's informations(backend path, slot num, job list) * struct backend_job: store each job(request)'s infomations(req type, uid, pkgid, ...) The pkgmgr-server has two hash tables which map each backend, each table use type(tpk, wgt) and slot number as key. And there is another table which stores informations about the job currently processed. The pkgmgr-server will push job to each queue, pop it at idler, and insert the job into the backend info table(using slot num as key). When the backend finished the job, the server will get the job info and free it(by removing from the table). All the memories for the request data will be allocated dynamically, and nerver duplicated. - Remove unused code. - Rename enums/internal apis. - Fix some code style. Change-Id: Ie95b369608dc6675aeccc6a66b255b28ca200059 Signed-off-by: Sangyoon Jang --- include/pkgmgr-server.h | 94 +++--- include/pm-queue.h | 56 ---- include/queue.h | 43 +++ src/pkgmgr-server.c | 797 ++++++++++++++++++++++-------------------------- src/pm-queue.c | 479 ----------------------------- src/queue.c | 197 ++++++++++++ src/request.c | 128 ++++---- src/restriction_mode.c | 6 +- src/signal.c | 40 ++- 9 files changed, 725 insertions(+), 1115 deletions(-) delete mode 100644 include/pm-queue.h create mode 100644 include/queue.h delete mode 100644 src/pm-queue.c create mode 100644 src/queue.c diff --git a/include/pkgmgr-server.h b/include/pkgmgr-server.h index 61b5696..288798e 100644 --- a/include/pkgmgr-server.h +++ b/include/pkgmgr-server.h @@ -27,6 +27,8 @@ #include #include +#include "queue.h" + #ifdef LOG_TAG #undef LOG_TAG #endif /* LOG_TAG */ @@ -44,12 +46,6 @@ #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" - -#define PKG_BACKEND "backend:" -#define PKG_CONF_PATH "/etc/package-manager/pkg_path.conf" - #define MAX_REQ_ID_LEN 256 #define MAX_PKG_TYPE_LEN 128 #define MAX_PKG_NAME_LEN 256 @@ -57,64 +53,42 @@ #define DESKTOP_FILE_DIRS_NUM 1024 enum request_type { - PKGMGR_REQUEST_TYPE_INSTALL, - PKGMGR_REQUEST_TYPE_MOUNT_INSTALL, - PKGMGR_REQUEST_TYPE_REINSTALL, - PKGMGR_REQUEST_TYPE_UNINSTALL, - PKGMGR_REQUEST_TYPE_MOVE, - PKGMGR_REQUEST_TYPE_ENABLE_PKG, - PKGMGR_REQUEST_TYPE_DISABLE_PKG, - PKGMGR_REQUEST_TYPE_ENABLE_APP, - PKGMGR_REQUEST_TYPE_DISABLE_APP, - PKGMGR_REQUEST_TYPE_GETSIZE, - PKGMGR_REQUEST_TYPE_CLEARDATA, - PKGMGR_REQUEST_TYPE_CLEARCACHE, - PKGMGR_REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID, - PKGMGR_REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID, - PKGMGR_REQUEST_TYPE_KILL, - PKGMGR_REQUEST_TYPE_CHECK, - PKGMGR_REQUEST_TYPE_GENERATE_LICENSE_REQUEST, - PKGMGR_REQUEST_TYPE_REGISTER_LICENSE, - PKGMGR_REQUEST_TYPE_DECRYPT_PACKAGE, - 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, + REQUEST_TYPE_INSTALL, + REQUEST_TYPE_MOUNT_INSTALL, + REQUEST_TYPE_REINSTALL, + REQUEST_TYPE_UNINSTALL, + REQUEST_TYPE_MOVE, + REQUEST_TYPE_ENABLE_PKG, + REQUEST_TYPE_DISABLE_PKG, + REQUEST_TYPE_ENABLE_APP, + REQUEST_TYPE_DISABLE_APP, + REQUEST_TYPE_GETSIZE, + REQUEST_TYPE_CLEARDATA, + REQUEST_TYPE_CLEARCACHE, + REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID, + REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID, + REQUEST_TYPE_KILL, + REQUEST_TYPE_CHECK, + REQUEST_TYPE_GENERATE_LICENSE_REQUEST, + REQUEST_TYPE_REGISTER_LICENSE, + REQUEST_TYPE_DECRYPT_PACKAGE, + REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN, + REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN, + REQUEST_TYPE_SET_RESTRICTION_MODE, + REQUEST_TYPE_UNSET_RESTRICTION_MODE, + REQUEST_TYPE_GET_RESTRICTION_MODE, }; -typedef struct { - char req_id[MAX_REQ_ID_LEN]; - int req_type; - uid_t uid; - char pkg_type[MAX_PKG_TYPE_LEN]; - char pkgid[MAX_PKG_NAME_LEN]; - char appid[MAX_PKG_NAME_LEN]; - char *args; -} pm_dbus_msg; - -typedef struct backend_info_t { - int pid; - uid_t uid; - int req_type; - char req_id[MAX_REQ_ID_LEN]; - char pkgtype[MAX_PKG_TYPE_LEN]; - char pkgid[MAX_PKG_NAME_LEN]; - char *args; -} backend_info; - -char *_get_backend_cmd(char *type); - gboolean queue_job(void *data); -int __return_value_to_caller(const char *req_key, GVariant *result); -int __init_request_handler(void); -void __fini_request_handler(void); -void __send_app_signal(uid_t uid, const char *req_id, +int _return_value_to_caller(const char *req_key, GVariant *result); +int _init_request_handler(void); +void _fini_request_handler(void); +void _send_app_signal(uid_t uid, const char *req_id, const char *pkgid, const char *appid, const char *key, const char *val, int req_type); -void __send_fail_signal(backend_info *info); -int _restriction_mode_set(uid_t uid, const char *pkgid, int mode); -int _restriction_mode_unset(uid_t uid, const char *pkgid, int mode); -int _restriction_mode_get(uid_t uid, const char *pkgid, int *mode); +void _send_fail_signal(struct backend_job *job); +int _set_restriction_mode(uid_t uid, const char *pkgid, int mode); +int _unset_restriction_mode(uid_t uid, const char *pkgid, int mode); +int _get_restriction_mode(uid_t uid, const char *pkgid, int *mode); #endif/* _PKGMGR_SERVER_H_ */ diff --git a/include/pm-queue.h b/include/pm-queue.h deleted file mode 100644 index eca0ce3..0000000 --- a/include/pm-queue.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * slp-pkgmgr - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Jayoun Lee , Sewook Park , - * Jaeho Lee , Shobhit Srivastava - * - * 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. - * - */ - - - - - -#ifndef _PM_QUEUE_H_ -#define _PM_QUEUE_H_ - -#include "pkgmgr-server.h" - -typedef struct _pm_queue_data { - pm_dbus_msg *msg; - struct _pm_queue_data *next; -} pm_queue_data; - -typedef struct queue_info_map_t { - char pkgtype[MAX_PKG_TYPE_LEN]; - char backend[MAX_PKG_NAME_LEN]; - int queue_slot; - pm_queue_data *head; -} queue_info_map; - -#define MAX_QUEUE_NUM 128 - -int _pm_queue_init(void); -int _pm_queue_push(uid_t uid, const char *req_id, int req_type, - 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(); -void _pm_queue_delete(pm_dbus_msg *item); -pm_queue_data *_add_node(); -void _print_queue(int position); - -#endif /* _PM_QUEUE_H_ */ diff --git a/include/queue.h b/include/queue.h new file mode 100644 index 0000000..5276ee6 --- /dev/null +++ b/include/queue.h @@ -0,0 +1,43 @@ +/* + * 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. + * + */ + +#ifndef _QUEUE_H_ +#define _QUEUE_H_ + +#include + +struct backend_job { + uid_t uid; + int req_type; + char *req_id; + char *pkgid; + char *appid; + char *args; + int backend_slot; + char *backend_type; + char *backend_path; +}; + +int _is_queue_empty(int pos); +int _push_queue(uid_t uid, const char *req_id, int req_type, + const char *queue_type, const char *pkgid, const char *args); +struct backend_job *_pop_queue(int pos); +void _free_backend_job(struct backend_job *job); +int _init_backend_queue(void); +void _fini_backend_queue(void); + +#endif // _QUEUE_H_ diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 72d6cd3..d824e5e 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -47,12 +47,9 @@ #include "pkgmgr_installer.h" #include "pkgmgr-server.h" -#include "pm-queue.h" +#include "queue.h" #include "package-manager.h" -#define BUFMAX 128 -#define NO_MATCHING_FILE 11 - #define OWNER_ROOT 0 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) #define APPFW_UID 301 @@ -80,7 +77,7 @@ typedef struct { Each bit position corresponds to a queue slot which is dynamically determined. */ -char backend_busy = 0; +static char backend_busy = 0; extern int num_of_backends; struct signal_info_t { @@ -91,22 +88,8 @@ struct signal_info_t { static int pipe_sig[2]; static GIOChannel *pipe_io; static guint pipe_wid; - -backend_info *begin; -extern queue_info_map *start; -extern int entries; - -GMainLoop *mainloop = NULL; - - -/* operation_type */ -typedef enum { - OPERATION_INSTALL = 0, - OPERATION_UNINSTALL, - OPERATION_ACTIVATE, - OPERATION_REINSTALL, - OPERATION_MAX -} OPERATION_TYPE; +static GHashTable *backend_info_table; +static GMainLoop *mainloop = NULL; static int __check_backend_status_for_exit(void); static int __check_queue_status_for_exit(void); @@ -117,59 +100,58 @@ static void sighandler(int signo); gboolean exit_server(void *data); -/* To check whether a particular backend is free/busy*/ +/* To check whether a particular backend is free/busy */ static int __is_backend_busy(int position) { - return backend_busy & 1<message); g_error_free(err); return TRUE; } - for (x = 0; x < num_of_backends; x++, ptr++) { - if (ptr && ptr->pid == info.pid) - break; - } - - if (x == num_of_backends) { + job = (struct backend_job *)g_hash_table_lookup(backend_info_table, + (gconstpointer)info.pid); + if (job == NULL) { ERR("Unknown child exit"); return -1; } - __set_backend_free(x); + __set_backend_free(job->backend_slot); if (WIFSIGNALED(info.status)) { - __send_fail_signal(ptr); - DBG("backend[%s] exit with signal[%d]", ptr->pkgtype, + _send_fail_signal(job); + DBG("backend[%s] exit with signal[%d]", job->backend_type, WTERMSIG(info.status)); } else if (WEXITSTATUS(info.status)) { - DBG("backend[%s] exit with error", ptr->pkgtype); + DBG("backend[%s] exit with error", job->backend_type); } else { - DBG("backend[%s] exit", ptr->pkgtype); + DBG("backend[%s] exit", job->backend_type); } + g_hash_table_remove(backend_info_table, (gconstpointer)info.pid); g_idle_add(queue_job, NULL); return TRUE; @@ -177,15 +159,9 @@ static gboolean pipe_io_handler(GIOChannel *io, GIOCondition cond, gpointer data static int __init_backend_info(void) { - backend_info *ptr; - - /*Allocate memory for holding pid, pkgtype and pkgid*/ - ptr = (backend_info*)calloc(num_of_backends, sizeof(backend_info)); - if (ptr == NULL) { - DBG("Malloc Failed\n"); - return -1; - } - begin = ptr; + backend_info_table = g_hash_table_new_full(g_direct_hash, + g_direct_equal, NULL, + (GDestroyNotify)_free_backend_job); if (pipe(pipe_sig)) { ERR("create pipe failed"); @@ -208,7 +184,7 @@ static void __fini_backend_info(void) close(pipe_sig[1]); /*Free backend info */ - free(begin); + g_hash_table_destroy(backend_info_table); } static void sighandler(int signo) @@ -218,7 +194,8 @@ static void sighandler(int signo) 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_r(errno, buf, sizeof(buf))); + ERR("failed to write result: %s", + strerror_r(errno, buf, sizeof(buf))); } static int __register_signal_handler(void) @@ -233,7 +210,7 @@ static int __register_signal_handler(void) sigemptyset(&act.sa_mask); act.sa_flags = SA_NOCLDSTOP; if (sigaction(SIGCHLD, &act, NULL) < 0) { - ERR("signal: SIGCHLD failed\n"); + ERR("signal: SIGCHLD failed"); return -1; } @@ -245,7 +222,7 @@ static int __register_signal_handler(void) static int __check_backend_status_for_exit(void) { - int i = 0; + int i; for (i = 0; i < num_of_backends; i++) { if (__is_backend_busy(i)) return 0; @@ -255,24 +232,9 @@ static int __check_backend_status_for_exit(void) static int __check_queue_status_for_exit(void) { - pm_queue_data *head[MAX_QUEUE_NUM] = {NULL,}; - queue_info_map *ptr = NULL; - ptr = start; - int i = 0; - int c = 0; - int slot = -1; - for (i = 0; i < entries; i++) { - if (ptr->queue_slot <= slot) { - ptr++; - } else { - head[c] = ptr->head; - slot = ptr->queue_slot; - c++; - ptr++; - } - } + int i; for (i = 0; i < num_of_backends; i++) { - if (head[i]) + if (_is_queue_empty(i) == 0) return 0; } return 1; @@ -280,19 +242,17 @@ static int __check_queue_status_for_exit(void) gboolean exit_server(void *data) { - DBG("exit_server Start\n"); + DBG("exit_server Start"); if (__check_backend_status_for_exit() && __check_queue_status_for_exit()) { - if (!getenv("PMS_STANDALONE")) { - g_main_loop_quit(mainloop); - return FALSE; - } + g_main_loop_quit(mainloop); + return FALSE; } return TRUE; } #ifdef TIZEN_FEATURE_CSR -static int __check_csr(backend_info *ptr) +static int __check_csr(const char *path) { csr_cs_context_h context = NULL; csr_cs_malware_h detected = NULL; @@ -305,12 +265,12 @@ static int __check_csr(backend_info *ptr) } if (context) { - ret = csr_cs_scan_file(context, ptr->pkgid, &detected); + ret = csr_cs_scan_file(context, path, &detected); DBG("CSR result[%d]", ret); csr_cs_context_destroy(context); if (detected != NULL) { - ERR("CSR Denied[%s] Installation", ptr->pkgid); + ERR("CSR Denied[%s] Installation", path); return -1; } } @@ -606,22 +566,25 @@ 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, bool *is_global) +static int __change_job_info(struct backend_job *job, uid_t uid, + bool *is_global) { int ret = 0; char *pkgid = NULL; 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); + switch (job->req_type) { + case REQUEST_TYPE_DISABLE_APP: + case REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID: + case REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN: + case REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN: + ret = pkgmgrinfo_appinfo_get_usr_appinfo(job->pkgid, uid, + &handle); 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); + case REQUEST_TYPE_ENABLE_APP: + case REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID: + ret = pkgmgrinfo_appinfo_get_usr_disabled_appinfo(job->pkgid, + uid, &handle); break; default: return PMINFO_R_ERROR; @@ -634,25 +597,27 @@ static int __change_item_info(pm_dbus_msg *item, uid_t uid, bool *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; + if ((job->req_type == REQUEST_TYPE_DISABLE_APP || + job->req_type == REQUEST_TYPE_ENABLE_APP) && + *is_global) { + ret = PMINFO_R_ERROR; + goto catch; + } else if ((job->req_type == REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID || + job->req_type == + 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); + free(job->appid); + job->appid = strdup(job->pkgid); + free(job->pkgid); + job->pkgid = strdup(pkgid); catch: pkgmgrinfo_appinfo_destroy_appinfo(handle); @@ -660,384 +625,405 @@ catch: return ret; } -static int __process_install(pm_dbus_msg *item) +static int __process_install(struct backend_job *job) { char *backend_cmd; char **argv; - char args[MAX_PKG_ARGS_LEN] = {'\0', }; + char args[MAX_PKG_ARGS_LEN]; int pid; - backend_cmd = _get_backend_cmd(item->pkg_type); + backend_cmd = job->backend_path; if (backend_cmd == NULL) return -1; snprintf(args, sizeof(args), "%s -k %s -i %s -u %d %s", backend_cmd, - item->req_id, item->pkgid, (int)item->uid, item->args); + job->req_id, job->pkgid, (int)job->uid, job->args); argv = __generate_argv(args); pid = __fork_and_exec_with_args(argv, APPFW_UID); g_strfreev(argv); - free(backend_cmd); return pid; } -static int __process_mount_install(pm_dbus_msg *item) +static int __process_mount_install(struct backend_job *job) { char *backend_cmd; char **argv; - char args[MAX_PKG_ARGS_LEN] = {'\0', }; + char args[MAX_PKG_ARGS_LEN]; int pid; - backend_cmd = _get_backend_cmd(item->pkg_type); + backend_cmd = job->backend_path; if (backend_cmd == NULL) return -1; snprintf(args, sizeof(args), "%s -k %s -w %s -u %d %s", backend_cmd, - item->req_id, item->pkgid, (int)item->uid, item->args); + job->req_id, job->pkgid, (int)job->uid, job->args); argv = __generate_argv(args); pid = __fork_and_exec_with_args(argv, APPFW_UID); g_strfreev(argv); - free(backend_cmd); return pid; } -static int __process_reinstall(pm_dbus_msg *item) +static int __process_reinstall(struct backend_job *job) { char *backend_cmd; char **argv; char args[MAX_PKG_ARGS_LEN]; int pid; - backend_cmd = _get_backend_cmd(item->pkg_type); + backend_cmd = job->backend_path; if (backend_cmd == NULL) return -1; snprintf(args, sizeof(args), "%s -k %s -r %s -u %d", backend_cmd, - item->req_id, item->pkgid, (int)item->uid); + job->req_id, job->pkgid, (int)job->uid); argv = __generate_argv(args); pid = __fork_and_exec_with_args(argv, APPFW_UID); g_strfreev(argv); - free(backend_cmd); return pid; } -static int __process_uninstall(pm_dbus_msg *item) +static int __process_uninstall(struct backend_job *job) { char *backend_cmd; char **argv; char args[MAX_PKG_ARGS_LEN]; int pid; - backend_cmd = _get_backend_cmd(item->pkg_type); + backend_cmd = job->backend_path; if (backend_cmd == NULL) return -1; snprintf(args, sizeof(args), "%s -k %s -d %s -u %d", backend_cmd, - item->req_id, item->pkgid, (int)item->uid); + job->req_id, job->pkgid, (int)job->uid); argv = __generate_argv(args); pid = __fork_and_exec_with_args(argv, APPFW_UID); g_strfreev(argv); - free(backend_cmd); return pid; } -static int __process_move(pm_dbus_msg *item) +static int __process_move(struct backend_job *job) { char *backend_cmd; char **argv; char args[MAX_PKG_ARGS_LEN]; int pid; - backend_cmd = _get_backend_cmd(item->pkg_type); + backend_cmd = job->backend_path; if (backend_cmd == NULL) return -1; snprintf(args, sizeof(args), "%s -k %s -m %s -u %d -t %s", backend_cmd, - item->req_id, item->pkgid, (int)item->uid, item->args); + job->req_id, job->pkgid, (int)job->uid, job->args); argv = __generate_argv(args); pid = __fork_and_exec_with_args(argv, APPFW_UID); g_strfreev(argv); - free(backend_cmd); return pid; } -static int __process_enable_pkg(pm_dbus_msg *item) +static int __process_enable_pkg(struct backend_job *job) { char *backend_cmd; char **argv; char args[MAX_PKG_ARGS_LEN]; int pid; - backend_cmd = _get_backend_cmd(item->pkg_type); + backend_cmd = job->backend_path; if (backend_cmd == NULL) return -1; snprintf(args, sizeof(args), "%s -k %s -u %d -A %s", backend_cmd, - item->req_id, (int)item->uid, item->pkgid); + job->req_id, (int)job->uid, job->pkgid); argv = __generate_argv(args); pid = __fork_and_exec_with_args(argv, APPFW_UID); g_strfreev(argv); - free(backend_cmd); return pid; } -static int __process_disable_pkg(pm_dbus_msg *item) +static int __process_disable_pkg(struct backend_job *job) { char *backend_cmd; char **argv; char args[MAX_PKG_ARGS_LEN]; int pid; - backend_cmd = _get_backend_cmd(item->pkg_type); + backend_cmd = job->backend_path; if (backend_cmd == NULL) return -1; snprintf(args, sizeof(args), "%s -k %s -u %d -D %s", backend_cmd, - item->req_id, (int)item->uid, item->pkgid); + job->req_id, (int)job->uid, job->pkgid); argv = __generate_argv(args); pid = __fork_and_exec_with_args(argv, APPFW_UID); g_strfreev(argv); - free(backend_cmd); return pid; } -static int __process_enable_app(pm_dbus_msg *item) +static int __process_enable_app(struct backend_job *job) { int ret = -1; bool is_global = false; - /* get actual pkgid and replace it to appid which is currently stored at pkgid variable */ - ret = __change_item_info(item, item->uid, &is_global); - if (ret != PMINFO_R_OK || strlen(item->appid) == 0) { - __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, + /* get actual pkgid and replace it to appid which is currently stored + * at pkgid variable + */ + ret = __change_job_info(job, job->uid, &is_global); + if (ret != PMINFO_R_OK || strlen(job->appid) == 0) { + _send_app_signal(job->uid, job->req_id, job->pkgid, job->pkgid, PKGMGR_INSTALLER_START_KEY_STR, - PKGMGR_INSTALLER_APP_ENABLE_EVENT_STR, item->req_type); - __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, - PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, - item->req_type); + PKGMGR_INSTALLER_APP_ENABLE_EVENT_STR, + job->req_type); + _send_app_signal(job->uid, job->req_id, job->pkgid, job->pkgid, + PKGMGR_INSTALLER_END_KEY_STR, + PKGMGR_INSTALLER_FAIL_EVENT_STR, + job->req_type); return ret; } - __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, + _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid, PKGMGR_INSTALLER_START_KEY_STR, - PKGMGR_INSTALLER_APP_ENABLE_EVENT_STR, item->req_type); + PKGMGR_INSTALLER_APP_ENABLE_EVENT_STR, job->req_type); - ret = pkgmgr_parser_update_app_disable_info_in_usr_db(item->appid, item->uid, 0); + ret = pkgmgr_parser_update_app_disable_info_in_usr_db(job->appid, + job->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, - item->req_type); + _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid, + PKGMGR_INSTALLER_END_KEY_STR, + PKGMGR_INSTALLER_FAIL_EVENT_STR, + job->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); - + _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid, + PKGMGR_INSTALLER_END_KEY_STR, + PKGMGR_INSTALLER_OK_EVENT_STR, + job->req_type); return ret; } -static int __process_disable_app(pm_dbus_msg *item) +static int __process_disable_app(struct backend_job *job) { int ret = -1; bool is_global = false; - /* get actual pkgid and replace it to appid which is currently stored at pkgid variable */ - ret = __change_item_info(item, item->uid, &is_global); - if (ret != PMINFO_R_OK || strlen(item->appid) == 0) { - __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, + /* get actual pkgid and replace it to appid which is currently stored + * at pkgid variable + */ + ret = __change_job_info(job, job->uid, &is_global); + if (ret != PMINFO_R_OK || strlen(job->appid) == 0) { + _send_app_signal(job->uid, job->req_id, job->pkgid, job->pkgid, PKGMGR_INSTALLER_START_KEY_STR, - PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR, item->req_type); - __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, - PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, - item->req_type); + PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR, + job->req_type); + _send_app_signal(job->uid, job->req_id, job->pkgid, job->pkgid, + PKGMGR_INSTALLER_END_KEY_STR, + PKGMGR_INSTALLER_FAIL_EVENT_STR, + job->req_type); return ret; } - __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, + _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid, PKGMGR_INSTALLER_START_KEY_STR, - PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR, item->req_type); + PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR, job->req_type); - ret = __kill_app(item->appid, item->uid); + ret = __kill_app(job->appid, job->uid); if (ret != 0) { - __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, - PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, - item->req_type); + _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid, + PKGMGR_INSTALLER_END_KEY_STR, + PKGMGR_INSTALLER_FAIL_EVENT_STR, + job->req_type); } - ret = pkgmgr_parser_update_app_disable_info_in_usr_db(item->appid, item->uid, 1); + ret = pkgmgr_parser_update_app_disable_info_in_usr_db(job->appid, + job->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, - item->req_type); + _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid, + PKGMGR_INSTALLER_END_KEY_STR, + PKGMGR_INSTALLER_FAIL_EVENT_STR, + job->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); + _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid, + PKGMGR_INSTALLER_END_KEY_STR, + PKGMGR_INSTALLER_OK_EVENT_STR, + job->req_type); return ret; } -static int __process_enable_global_app_for_uid(pm_dbus_msg *item) +static int __process_enable_global_app_for_uid(struct backend_job *job) { int ret = -1; bool is_global = true; - /* get actual pkgid and replace it to appid which is currently stored at pkgid variable */ - ret = __change_item_info(item, item->uid, &is_global); - if (ret != PMINFO_R_OK || strlen(item->appid) == 0) { - __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, + /* get actual pkgid and replace it to appid which is currently stored + * at pkgid variable + */ + ret = __change_job_info(job, job->uid, &is_global); + if (ret != PMINFO_R_OK || strlen(job->appid) == 0) { + _send_app_signal(job->uid, job->req_id, job->pkgid, job->pkgid, PKGMGR_INSTALLER_START_KEY_STR, - PKGMGR_INSTALLER_GLOBAL_APP_ENABLE_FOR_UID, item->req_type); - __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, - PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, - item->req_type); + PKGMGR_INSTALLER_GLOBAL_APP_ENABLE_FOR_UID, + job->req_type); + _send_app_signal(job->uid, job->req_id, job->pkgid, job->pkgid, + PKGMGR_INSTALLER_END_KEY_STR, + PKGMGR_INSTALLER_FAIL_EVENT_STR, + job->req_type); return ret; } - __send_app_signal(item->uid, item->req_id, item->pkgid, item->appid, + _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid, PKGMGR_INSTALLER_START_KEY_STR, - PKGMGR_INSTALLER_GLOBAL_APP_ENABLE_FOR_UID, item->req_type); + PKGMGR_INSTALLER_GLOBAL_APP_ENABLE_FOR_UID, + job->req_type); - ret = pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(item->appid, item->uid, 0); + ret = pkgmgr_parser_update_global_app_disable_for_uid_info_in_db( + job->appid, job->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, - item->req_type); + _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid, + PKGMGR_INSTALLER_END_KEY_STR, + PKGMGR_INSTALLER_FAIL_EVENT_STR, + job->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); + _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid, + PKGMGR_INSTALLER_END_KEY_STR, + PKGMGR_INSTALLER_OK_EVENT_STR, + job->req_type); return ret; } -static int __process_disable_global_app_for_uid(pm_dbus_msg *item) +static int __process_disable_global_app_for_uid(struct backend_job *job) { int ret = -1; bool is_global = true; - /* get actual pkgid and replace it to appid which is currently stored at pkgid variable */ - ret = __change_item_info(item, GLOBAL_USER, &is_global); - if (ret != PMINFO_R_OK || strlen(item->appid) == 0) { - __send_app_signal(item->uid, item->req_id, - item->pkgid, item->pkgid, + /* get actual pkgid and replace it to appid which is currently stored + * at pkgid variable + */ + ret = __change_job_info(job, GLOBAL_USER, &is_global); + if (ret != PMINFO_R_OK || strlen(job->appid) == 0) { + _send_app_signal(job->uid, job->req_id, + job->pkgid, job->pkgid, PKGMGR_INSTALLER_START_KEY_STR, - PKGMGR_INSTALLER_GLOBAL_APP_DISABLE_FOR_UID, item->req_type); - __send_app_signal(item->uid, item->req_id, item->pkgid, item->pkgid, - PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, - item->req_type); + PKGMGR_INSTALLER_GLOBAL_APP_DISABLE_FOR_UID, + job->req_type); + _send_app_signal(job->uid, job->req_id, job->pkgid, job->pkgid, + PKGMGR_INSTALLER_END_KEY_STR, + PKGMGR_INSTALLER_FAIL_EVENT_STR, + job->req_type); return ret; } - __send_app_signal(item->uid, item->req_id, - item->pkgid, item->appid, + _send_app_signal(job->uid, job->req_id, + job->pkgid, job->appid, PKGMGR_INSTALLER_START_KEY_STR, - PKGMGR_INSTALLER_GLOBAL_APP_DISABLE_FOR_UID, item->req_type); + PKGMGR_INSTALLER_GLOBAL_APP_DISABLE_FOR_UID, + job->req_type); - ret = __kill_app(item->appid, item->uid); - ret = pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(item->appid, - item->uid, 1); + ret = __kill_app(job->appid, job->uid); + ret = pkgmgr_parser_update_global_app_disable_for_uid_info_in_db( + job->appid, job->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, - item->req_type); + _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid, + PKGMGR_INSTALLER_END_KEY_STR, + PKGMGR_INSTALLER_FAIL_EVENT_STR, + job->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); + _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid, + PKGMGR_INSTALLER_END_KEY_STR, + PKGMGR_INSTALLER_OK_EVENT_STR, + job->req_type); return ret; } -static int __process_getsize(pm_dbus_msg *item) +static int __process_getsize(struct backend_job *job) { static const char *backend_cmd = "/usr/bin/pkg_getsize"; char **argv; char args[MAX_PKG_ARGS_LEN]; int pid; - snprintf(args, sizeof(args), "%s %s %s -k %s", backend_cmd, item->pkgid, - item->args, item->req_id); + snprintf(args, sizeof(args), "%s %s %s -k %s", backend_cmd, job->pkgid, + job->args, job->req_id); argv = __generate_argv(args); - pid = __fork_and_exec_with_args(argv, item->uid); + pid = __fork_and_exec_with_args(argv, job->uid); g_strfreev(argv); return pid; } -static int __process_cleardata(pm_dbus_msg *item) +static int __process_cleardata(struct backend_job *job) { char *backend_cmd; char **argv; char args[MAX_PKG_ARGS_LEN]; int pid; - backend_cmd = _get_backend_cmd(item->pkg_type); + backend_cmd = job->backend_path; if (backend_cmd == NULL) return -1; /* TODO: set movetype */ snprintf(args, sizeof(args), "%s -k %s -c %s -u %d", backend_cmd, - item->req_id, item->pkgid, (int)item->uid); + job->req_id, job->pkgid, (int)job->uid); argv = __generate_argv(args); pid = __fork_and_exec_with_args(argv, APPFW_UID); g_strfreev(argv); - free(backend_cmd); return pid; } -static int __process_clearcache(pm_dbus_msg *item) +static int __process_clearcache(struct backend_job *job) { static const char *backend_cmd = "/usr/bin/pkg_clearcache"; char **argv; char args[MAX_PKG_ARGS_LEN]; int pid; - snprintf(args, sizeof(args), "%s %s", backend_cmd, item->pkgid); + snprintf(args, sizeof(args), "%s %s", backend_cmd, job->pkgid); argv = __generate_argv(args); - pid = __fork_and_exec_with_args(argv, item->uid); + pid = __fork_and_exec_with_args(argv, job->uid); g_strfreev(argv); return pid; } -static int __process_kill(pm_dbus_msg *item) +static int __process_kill(struct backend_job *job) { int ret; pkgmgrinfo_pkginfo_h handle; pkgcmd_data *pdata; - ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(item->pkgid, item->uid, + ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(job->pkgid, job->uid, &handle); if (ret < 0) { ERR("Failed to get handle"); - __return_value_to_caller(item->req_id, + _return_value_to_caller(job->req_id, g_variant_new("(ii)", PKGMGR_R_ERROR, 0)); return -1; } @@ -1045,23 +1031,23 @@ static int __process_kill(pm_dbus_msg *item) pdata = calloc(1, sizeof(pkgcmd_data)); if (pdata == NULL) { ERR("memory alloc failed"); - __return_value_to_caller(item->req_id, + _return_value_to_caller(job->req_id, g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0)); return -1; } pdata->cmd = strdup("kill"); if (pdata->cmd == NULL) { ERR("out of memory"); - __return_value_to_caller(item->req_id, + _return_value_to_caller(job->req_id, g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0)); free(pdata); return -1; } - pdata->uid = item->uid; + pdata->uid = job->uid; ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP, - __pkgcmd_app_cb, pdata, item->uid); + __pkgcmd_app_cb, pdata, job->uid); - __return_value_to_caller(item->req_id, + _return_value_to_caller(job->req_id, g_variant_new("(ii)", PKGMGR_R_OK, pdata->pid)); free(pdata->cmd); @@ -1075,17 +1061,17 @@ static int __process_kill(pm_dbus_msg *item) return 0; } -static int __process_check(pm_dbus_msg *item) +static int __process_check(struct backend_job *job) { int ret; pkgmgrinfo_pkginfo_h handle; pkgcmd_data *pdata; - ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(item->pkgid, item->uid, + ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(job->pkgid, job->uid, &handle); if (ret < 0) { ERR("Failed to get handle"); - __return_value_to_caller(item->req_id, + _return_value_to_caller(job->req_id, g_variant_new("(ii)", PKGMGR_R_ERROR, 0)); return -1; } @@ -1093,23 +1079,23 @@ static int __process_check(pm_dbus_msg *item) pdata = calloc(1, sizeof(pkgcmd_data)); if (pdata == NULL) { ERR("memory alloc failed"); - __return_value_to_caller(item->req_id, + _return_value_to_caller(job->req_id, g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0)); return -1; } pdata->cmd = strdup("check"); if (pdata->cmd == NULL) { ERR("out of memory"); - __return_value_to_caller(item->req_id, + _return_value_to_caller(job->req_id, g_variant_new("(ii)", PKGMGR_R_ENOMEM, 0)); free(pdata); return -1; } - pdata->uid = item->uid; + pdata->uid = job->uid; ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP, - __pkgcmd_app_cb, pdata, item->uid); + __pkgcmd_app_cb, pdata, job->uid); - __return_value_to_caller(item->req_id, + _return_value_to_caller(job->req_id, g_variant_new("(ii)", PKGMGR_R_OK, pdata->pid)); free(pdata->cmd); @@ -1123,7 +1109,7 @@ static int __process_check(pm_dbus_msg *item) return 0; } -static int __process_generate_license_request(pm_dbus_msg *item) +static int __process_generate_license_request(struct backend_job *job) { int ret; char *resp_data; @@ -1132,7 +1118,7 @@ static int __process_generate_license_request(pm_dbus_msg *item) char license_url[MAX_PKG_ARGS_LEN]; unsigned int license_url_len; - resp_data = item->args; + resp_data = job->args; req_data_len = sizeof(req_data); license_url_len = sizeof(license_url); @@ -1140,135 +1126,134 @@ static int __process_generate_license_request(pm_dbus_msg *item) req_data, &req_data_len, license_url, &license_url_len); if (ret != TADC_SUCCESS) { ERR("drm_tizen_generate_license_request failed: %d", ret); - __return_value_to_caller(item->req_id, g_variant_new("(iss)", + _return_value_to_caller(job->req_id, g_variant_new("(iss)", PKGMGR_R_ESYSTEM, "", "")); return -1; } - __return_value_to_caller(item->req_id, + _return_value_to_caller(job->req_id, g_variant_new("(iss)", PKGMGR_R_OK, req_data, license_url)); return 0; } -static int __process_register_license(pm_dbus_msg *item) +static int __process_register_license(struct backend_job *job) { int ret; char *resp_data; - resp_data = item->args; + resp_data = job->args; ret = drm_tizen_register_license(resp_data, strlen(resp_data)); if (ret != TADC_SUCCESS) { ERR("drm_tizen_register_license failed: %d", ret); - __return_value_to_caller(item->req_id, + _return_value_to_caller(job->req_id, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); return -1; } - __return_value_to_caller(item->req_id, + _return_value_to_caller(job->req_id, g_variant_new("(i)", PKGMGR_R_OK)); return 0; } -static int __process_decrypt_package(pm_dbus_msg *item) +static int __process_decrypt_package(struct backend_job *job) { int ret; char *drm_file_path; char *decrypted_file_path; - drm_file_path = item->pkgid; - decrypted_file_path = item->args; + drm_file_path = job->pkgid; + decrypted_file_path = job->args; /* TODO: check ownership of decrypted file */ ret = drm_tizen_decrypt_package(drm_file_path, strlen(drm_file_path), decrypted_file_path, strlen(decrypted_file_path)); if (ret != TADC_SUCCESS) { ERR("drm_tizen_register_license failed: %d", ret); - __return_value_to_caller(item->req_id, + _return_value_to_caller(job->req_id, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); return -1; } - __return_value_to_caller(item->req_id, + _return_value_to_caller(job->req_id, g_variant_new("(i)", PKGMGR_R_OK)); return 0; } -static int __process_update_app_splash_screen(pm_dbus_msg *item, int flag) +static int __process_update_app_splash_screen(struct backend_job *job, 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) + ret = __change_job_info(job, job->uid, &is_global); + if (ret != PMINFO_R_OK || strlen(job->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); + _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid, + PKGMGR_INSTALLER_START_KEY_STR, val, job->req_type); if (is_global) - ret = pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db( - item->appid, item->uid, flag); + ret = pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(job->appid, job->uid, flag); else ret = pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db( - item->appid, item->uid, flag); + job->appid, job->uid, flag); if (ret != PMINFO_R_OK) - __send_app_signal(item->uid, item->req_id, item->pkgid, - item->appid, PKGMGR_INSTALLER_END_KEY_STR, + _send_app_signal(job->uid, job->req_id, job->pkgid, + job->appid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, - item->req_type); + job->req_type); else - __send_app_signal(item->uid, item->req_id, item->pkgid, - item->appid, PKGMGR_INSTALLER_END_KEY_STR, + _send_app_signal(job->uid, job->req_id, job->pkgid, + job->appid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR, - item->req_type); + job->req_type); return ret; } -static int __process_set_restriction_mode(pm_dbus_msg *item) +static int __process_set_restriction_mode(struct backend_job *job) { int ret; int mode; - mode = atoi(item->args); - ret = _restriction_mode_set(item->uid, item->pkgid, mode); + mode = atoi(job->args); + ret = _set_restriction_mode(job->uid, job->pkgid, mode); - __return_value_to_caller(item->req_id, + _return_value_to_caller(job->req_id, g_variant_new("(i)", ret)); return ret; } -static int __process_unset_restriction_mode(pm_dbus_msg *item) +static int __process_unset_restriction_mode(struct backend_job *job) { int ret; int mode; - mode = atoi(item->args); - ret = _restriction_mode_unset(item->uid, item->pkgid, mode); + mode = atoi(job->args); + ret = _unset_restriction_mode(job->uid, job->pkgid, mode); - __return_value_to_caller(item->req_id, + _return_value_to_caller(job->req_id, g_variant_new("(i)", ret)); return ret; } -static int __process_get_restriction_mode(pm_dbus_msg *item) +static int __process_get_restriction_mode(struct backend_job *job) { int ret; int mode = -1; - ret = _restriction_mode_get(item->uid, item->pkgid, &mode); + ret = _get_restriction_mode(job->uid, job->pkgid, &mode); - __return_value_to_caller(item->req_id, + _return_value_to_caller(job->req_id, g_variant_new("(ii)", mode, ret)); return ret; @@ -1276,230 +1261,170 @@ static int __process_get_restriction_mode(pm_dbus_msg *item) gboolean queue_job(void *data) { - pm_dbus_msg *item = NULL; - backend_info *ptr; + struct backend_job *job = NULL; int x; int ret; /* Pop a job from queue */ - for (x = 0, ptr = begin; x < num_of_backends; x++, ptr++) { + for (x = 0; x < num_of_backends; x++) { if (__is_backend_busy(x)) continue; - item = _pm_queue_pop(x); - if (item && item->req_type != -1) + job = _pop_queue(x); + if (job) break; - free(item); } /* all backend messages queue are empty or busy */ - if (x == num_of_backends) + if (x == num_of_backends || job == NULL) { + DBG("no job left"); return FALSE; + } - /*save pkg type and pkg name for future*/ - strncpy(ptr->req_id, item->req_id, MAX_REQ_ID_LEN - 1); - strncpy(ptr->pkgtype, item->pkg_type, MAX_PKG_TYPE_LEN - 1); - strncpy(ptr->pkgid, item->pkgid, MAX_PKG_NAME_LEN - 1); - free(ptr->args); - if (item->args) - ptr->args = strdup(item->args); - memset((item->appid), 0, MAX_PKG_NAME_LEN); - ptr->uid = item->uid; - ptr->req_type = item->req_type; - DBG("handle request type [%d]", item->req_type); + /* set current backend job */ + DBG("handle request type [%d]", job->req_type); #ifdef TIZEN_FEATURE_CSR - if (item->req_type == PKGMGR_REQUEST_TYPE_INSTALL || - item->req_type == PKGMGR_REQUEST_TYPE_MOUNT_INSTALL || - item->req_type == PKGMGR_REQUEST_TYPE_REINSTALL) { - ret = __check_csr(ptr); + if (job->req_type == REQUEST_TYPE_INSTALL || + job->req_type == REQUEST_TYPE_MOUNT_INSTALL || + job->req_type == REQUEST_TYPE_REINSTALL) { + ret = __check_csr(job->pkgid); if (ret != 0) { ret = -1; - __send_fail_signal(ptr); - goto end; + _send_fail_signal(job); + _free_backend_job(job); + return FALSE; } } #endif - switch (item->req_type) { - case PKGMGR_REQUEST_TYPE_INSTALL: + switch (job->req_type) { + case REQUEST_TYPE_INSTALL: __set_backend_busy(x); - ret = __process_install(item); + ret = __process_install(job); + g_hash_table_insert(backend_info_table, (gpointer)ret, + (gpointer)job); break; - case PKGMGR_REQUEST_TYPE_MOUNT_INSTALL: + case REQUEST_TYPE_MOUNT_INSTALL: __set_backend_busy(x); - ret = __process_mount_install(item); + ret = __process_mount_install(job); + g_hash_table_insert(backend_info_table, (gpointer)ret, + (gpointer)job); break; - case PKGMGR_REQUEST_TYPE_REINSTALL: + case REQUEST_TYPE_REINSTALL: __set_backend_busy(x); - ret = __process_reinstall(item); + ret = __process_reinstall(job); + g_hash_table_insert(backend_info_table, (gpointer)ret, + (gpointer)job); break; - case PKGMGR_REQUEST_TYPE_UNINSTALL: + case REQUEST_TYPE_UNINSTALL: __set_backend_busy(x); - ret = __process_uninstall(item); + ret = __process_uninstall(job); + g_hash_table_insert(backend_info_table, (gpointer)ret, + (gpointer)job); break; - case PKGMGR_REQUEST_TYPE_MOVE: + case REQUEST_TYPE_MOVE: __set_backend_busy(x); - ret = __process_move(item); + ret = __process_move(job); + g_hash_table_insert(backend_info_table, (gpointer)ret, + (gpointer)job); break; - case PKGMGR_REQUEST_TYPE_ENABLE_PKG: + case REQUEST_TYPE_ENABLE_PKG: __set_backend_busy(x); - ret = __process_enable_pkg(item); + ret = __process_enable_pkg(job); + g_hash_table_insert(backend_info_table, (gpointer)ret, + (gpointer)job); break; - case PKGMGR_REQUEST_TYPE_DISABLE_PKG: + case REQUEST_TYPE_DISABLE_PKG: __set_backend_busy(x); - ret = __process_disable_pkg(item); + ret = __process_disable_pkg(job); + g_hash_table_insert(backend_info_table, (gpointer)ret, + (gpointer)job); break; - case PKGMGR_REQUEST_TYPE_ENABLE_APP: - ret = __process_enable_app(item); + case REQUEST_TYPE_ENABLE_APP: + ret = __process_enable_app(job); break; - case PKGMGR_REQUEST_TYPE_DISABLE_APP: - ret = __process_disable_app(item); + case REQUEST_TYPE_DISABLE_APP: + ret = __process_disable_app(job); break; - case PKGMGR_REQUEST_TYPE_GETSIZE: + case REQUEST_TYPE_GETSIZE: __set_backend_busy(x); - ret = __process_getsize(item); + ret = __process_getsize(job); break; - case PKGMGR_REQUEST_TYPE_CLEARDATA: + case REQUEST_TYPE_CLEARDATA: __set_backend_busy(x); - ret = __process_cleardata(item); + ret = __process_cleardata(job); break; - case PKGMGR_REQUEST_TYPE_CLEARCACHE: + case REQUEST_TYPE_CLEARCACHE: __set_backend_busy(x); - ret = __process_clearcache(item); + ret = __process_clearcache(job); + _free_backend_job(job); break; - case PKGMGR_REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID: - ret = __process_enable_global_app_for_uid(item); + case REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID: + ret = __process_enable_global_app_for_uid(job); + _free_backend_job(job); break; - case PKGMGR_REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID: - ret = __process_disable_global_app_for_uid(item); + case REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID: + ret = __process_disable_global_app_for_uid(job); + _free_backend_job(job); break; - case PKGMGR_REQUEST_TYPE_KILL: - ret = __process_kill(item); + case REQUEST_TYPE_KILL: + ret = __process_kill(job); + _free_backend_job(job); break; - case PKGMGR_REQUEST_TYPE_CHECK: - ret = __process_check(item); + case REQUEST_TYPE_CHECK: + ret = __process_check(job); + _free_backend_job(job); break; - case PKGMGR_REQUEST_TYPE_GENERATE_LICENSE_REQUEST: - ret = __process_generate_license_request(item); + case REQUEST_TYPE_GENERATE_LICENSE_REQUEST: + ret = __process_generate_license_request(job); + _free_backend_job(job); break; - case PKGMGR_REQUEST_TYPE_REGISTER_LICENSE: - ret = __process_register_license(item); + case REQUEST_TYPE_REGISTER_LICENSE: + ret = __process_register_license(job); + _free_backend_job(job); break; - case PKGMGR_REQUEST_TYPE_DECRYPT_PACKAGE: - ret = __process_decrypt_package(item); + case REQUEST_TYPE_DECRYPT_PACKAGE: + ret = __process_decrypt_package(job); + _free_backend_job(job); break; - case PKGMGR_REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN: - ret = __process_update_app_splash_screen(item, 1); + case REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN: + ret = __process_update_app_splash_screen(job, 1); + _free_backend_job(job); break; - case PKGMGR_REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN: - ret = __process_update_app_splash_screen(item, 0); + case REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN: + ret = __process_update_app_splash_screen(job, 0); + _free_backend_job(job); break; - case PKGMGR_REQUEST_TYPE_SET_RESTRICTION_MODE: - ret = __process_set_restriction_mode(item); + case REQUEST_TYPE_SET_RESTRICTION_MODE: + ret = __process_set_restriction_mode(job); + _free_backend_job(job); break; - case PKGMGR_REQUEST_TYPE_UNSET_RESTRICTION_MODE: - ret = __process_unset_restriction_mode(item); + case REQUEST_TYPE_UNSET_RESTRICTION_MODE: + ret = __process_unset_restriction_mode(job); + _free_backend_job(job); break; - case PKGMGR_REQUEST_TYPE_GET_RESTRICTION_MODE: - ret = __process_get_restriction_mode(item); + case REQUEST_TYPE_GET_RESTRICTION_MODE: + ret = __process_get_restriction_mode(job); + _free_backend_job(job); break; default: ret = -1; break; } -#ifdef TIZEN_FEATURE_CSR -end: -#endif - ptr->pid = ret; - free(item); - return FALSE; } -#define IS_WHITESPACE(CHAR) \ -((CHAR == ' ' || CHAR == '\t' || CHAR == '\r' || CHAR == '\n') ? TRUE : FALSE) - -void _app_str_trim(char *input) -{ - char *trim_str = input; - - if (input == NULL) - return; - - while (*input != 0) { - if (!IS_WHITESPACE(*input)) { - *trim_str = *input; - trim_str++; - } - input++; - } - - *trim_str = 0; - return; -} - -char *_get_backend_cmd(char *type) -{ - FILE *fp = NULL; - char buffer[1024] = { 0 }; - char *command = NULL; - int size = 0; - - fp = fopen(PKG_CONF_PATH, "r"); - if (fp == NULL) - return NULL; - - char *path = NULL; - while (fgets(buffer, 1024, fp) != NULL) { - if (buffer[0] == '#') - continue; - - _app_str_trim(buffer); - - if ((path = strstr(buffer, PKG_BACKEND)) != NULL) { - DBG("buffer [%s]", buffer); - path = path + strlen(PKG_BACKEND); - DBG("path [%s]", path); - - command = - (char *)malloc(sizeof(char) * strlen(path) + - strlen(type) + 1); - if (command == NULL) { - fclose(fp); - return NULL; - } - - size = strlen(path) + strlen(type) + 1; - snprintf(command, size, "%s%s", path, type); - command[strlen(path) + strlen(type)] = '\0'; - DBG("command [%s]", command); - - if (fp != NULL) - fclose(fp); - - return command; - } - - memset(buffer, 0x00, 1024); - } - - if (fp != NULL) - fclose(fp); - - return NULL; /* cannot find proper command */ -} - int main(int argc, char *argv[]) { int r; DBG("server start"); - r = _pm_queue_init(); + r = _init_backend_queue(); if (r) { - DBG("Queue Initialization Failed\n"); + DBG("Queue Initialization Failed"); return -1; } @@ -1509,7 +1434,7 @@ int main(int argc, char *argv[]) return -1; } - r = __init_request_handler(); + r = _init_request_handler(); if (r) { ERR("dbus init failed"); return -1; @@ -1534,9 +1459,9 @@ int main(int argc, char *argv[]) g_main_loop_run(mainloop); DBG("Quit main loop."); - __fini_request_handler(); + _fini_request_handler(); __fini_backend_info(); - _pm_queue_final(); + _fini_backend_queue(); DBG("package manager server terminated."); diff --git a/src/pm-queue.c b/src/pm-queue.c deleted file mode 100644 index 7085367..0000000 --- a/src/pm-queue.c +++ /dev/null @@ -1,479 +0,0 @@ -/* - * slp-pkgmgr - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Jayoun Lee , Sewook Park , - * Jaeho Lee , Shobhit Srivastava - * - * 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 "pkgmgr-server.h" -#include "pm-queue.h" - -#ifndef BACKEND_DIR -#define BACKEND_DIR "/etc/package-manager/backend" -#endif - -static pm_queue_data *__get_head_from_pkgtype(const char *pkg_type); -static void __update_head_from_pkgtype(pm_queue_data *data); -static int __entry_exist(char *backend); -static int __is_pkg_supported(const char *pkgtype); - -queue_info_map *start = NULL; -int entries = 0; -int slot = 0; -int num_of_backends = 0; - -/*Function to check whether a particular package type -is supported or not. It parses the queue info map -to get the information. -It will prevent the accidental hanging of server. -Returns 1 if found.*/ -static int __is_pkg_supported(const char *pkgtype) -{ - queue_info_map *ptr = NULL; - ptr = start; - int i = 0; - for (i = 0; i < entries; i++) { - if (!strncmp(ptr->pkgtype, pkgtype, MAX_PKG_TYPE_LEN)) - return 1; - else - ptr++; - } - return 0; -} - -/*tells whether a particular backend exists in the -* info map or not. -* on Success it return the queue slot of the already present entry -* on Failure -1 is returned*/ -static int __entry_exist(char *backend) -{ - queue_info_map *ptr = NULL; - ptr = start; - int i = 0; - for (i = 0; i < entries; i++) { - if (!strncmp(ptr->backend, backend, MAX_PKG_NAME_LEN)) - return ptr->queue_slot; - else - ptr++; - } - return -1; -} - -/*In case of first push, it updates the queue head -and copies it to all duplicate entries in queue info map*/ -static void __update_head_from_pkgtype(pm_queue_data *data) -{ - queue_info_map *ptr = NULL; - ptr = start; - int slot = -1; - int i = 0; - for (i = 0; i < entries; i++) { - if (!strncmp(ptr->pkgtype, data->msg->pkg_type, MAX_PKG_TYPE_LEN)) { - ptr->head = data; - slot = ptr->queue_slot; - } else { - ptr++; - } - } - /*update head for each duplicate entry*/ - ptr = start; - for (i = 0; i < entries; i++) { - if (ptr->queue_slot == slot && !ptr->head) - ptr->head = data; - - ptr++; - } - return; -} - -/*Gets the queue head based on pkg type*/ -static pm_queue_data *__get_head_from_pkgtype(const char *pkg_type) -{ - queue_info_map *ptr = NULL; - ptr = start; - int i = 0; - for (i = 0; i < entries; i++) { - if (!strncmp(ptr->pkgtype, pkg_type, MAX_PKG_TYPE_LEN)) - return ptr->head; - else - ptr++; - } - return NULL; - -} - -int _pm_queue_init(void) -{ - /*Find the num of backends currently supported and initialize - that many queues. It is dynamically determined.*/ - struct dirent **namelist; - struct stat fileinfo = {0}; - queue_info_map *ptr = NULL; - int n = 0; - int c = 0; - int i = 0; - int ret = 0; - char abs_filename[MAX_PKG_NAME_LEN] = {'\0'}; - char buf[MAX_PKG_NAME_LEN] = {'\0'}; - n = scandir(BACKEND_DIR, &namelist, NULL, alphasort); - if (n < 0) { - perror("scandir"); - return -1; - } - i = n; - /* Find number of backends (symlinks + executables) - The backend dir should not conatin any other file except the backends. */ - while (n--) { - if (!strcmp(namelist[n]->d_name, ".") || - !strcmp(namelist[n]->d_name, "..")) - continue; - snprintf(abs_filename, MAX_PKG_NAME_LEN, "%s/%s", - BACKEND_DIR, namelist[n]->d_name); - if (lstat(abs_filename, &fileinfo)) { - perror("lstat"); - continue; - } - if (S_ISDIR(fileinfo.st_mode)) - continue; - c++; - memset(abs_filename, 0x00, MAX_PKG_NAME_LEN); - } - /* Add entries to info map. */ - ptr = (queue_info_map*)calloc(c , sizeof(queue_info_map)); - memset(ptr, '\0', c * sizeof(queue_info_map)); - start = ptr; - for (n = 0; n < c ; n++) { - ptr->backend[0] = '\0'; - ptr->head = NULL; - ptr->queue_slot = -2; /* -1 can be error return */ - ptr->pkgtype[0] = '\0'; - ptr++; - } - n = i; - ptr = start; - while (n--) { - if (!strcmp(namelist[n]->d_name, ".") || - !strcmp(namelist[n]->d_name, "..")) - continue; - snprintf(abs_filename, MAX_PKG_NAME_LEN, "%s/%s", - BACKEND_DIR, namelist[n]->d_name); - if (lstat(abs_filename, &fileinfo) < 0) { - perror(abs_filename); - return -1; - } - if (S_ISDIR(fileinfo.st_mode)) - continue; - /*Found backend*/ - if (S_ISLNK(fileinfo.st_mode)) { - /*found a symlink*/ - ret = readlink(abs_filename, buf, MAX_PKG_NAME_LEN - 1); - if (ret == -1) { - perror("readlink"); - return -1; - } - buf[ret] = '\0'; - } else { - /*executable*/ - snprintf(buf, sizeof(buf), "%s", abs_filename); - } - ret = __entry_exist(buf); - if (ret == -1) { - snprintf(ptr->backend, sizeof(ptr->backend), "%s", buf); - snprintf(ptr->pkgtype, sizeof(ptr->pkgtype), "%s", namelist[n]->d_name); - ptr->queue_slot = slot; - ptr->head = NULL; - entries++; - slot++; - ptr++; - } else { - snprintf(ptr->backend, sizeof(ptr->backend), "%s", buf); - snprintf(ptr->pkgtype, sizeof(ptr->pkgtype), "%s", namelist[n]->d_name); - ptr->queue_slot = ret; - ptr->head = NULL; - entries++; - ptr++; - } - free(namelist[n]); - memset(buf, 0x00, MAX_PKG_NAME_LEN); - continue; - } - free(namelist); - num_of_backends = slot; - -#ifdef DEBUG_INFO - /*Debug info*/ - DBG("Queue Info Map"); - DBG("Number of Backends is %d", num_of_backends); - DBG("Number of Entries is %d", entries); - DBG("Backend\tType\tSlot\tHead"); - ptr = start; - for (n = 0; n < entries; n++) { - DBG("%s\t%s\t%d\t%p", ptr->backend, ptr->pkgtype, ptr->queue_slot, ptr->head); - ptr++; - } -#endif - - return 0; -} - -static void __convert_to_lower_case(char *dst, const char *src) -{ - int i; - - for (i = 0; src[i] != '\0'; i++) - dst[i] = tolower(src[i]); - dst[i] = '\0'; -} - -int _pm_queue_push(uid_t uid, const char *req_id, int req_type, - 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; - char type[MAX_PKG_NAME_LEN]; - int ret; - - __convert_to_lower_case(type, queue_type); - - ret = __is_pkg_supported(type); - if (ret == 0) - return -1; - - cur = __get_head_from_pkgtype(type); - tmp = cur; - - /* TODO: use glist */ - data = _add_node(); - if (!data) { /* fail to allocate mem */ - ERR("Fail to allocate memory\n"); - return -1; - } - - 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", type); - snprintf(data->msg->pkgid, sizeof(data->msg->pkgid), "%s", pkgid); - if (args) - data->msg->args = strdup(args); - - data->next = NULL; - - if (cur == NULL) { - /* first push */ - cur = data; - __update_head_from_pkgtype(data); - } else { - while (tmp->next) - tmp = tmp->next; - - tmp->next = data; - } - return 0; -} - -/*pop request from queue slot "position" */ -pm_dbus_msg *_pm_queue_pop(int position) -{ - pm_dbus_msg *ret; - pm_queue_data *cur = NULL; - pm_queue_data *saveptr = NULL; - queue_info_map *ptr = NULL; - int i = 0; - - ret = (pm_dbus_msg *) malloc(sizeof(pm_dbus_msg)); - if (!ret) { - ERR("Mem alloc error"); - return NULL; - } - memset(ret, 0x00, sizeof(pm_dbus_msg)); - ptr = start; - for (i = 0; i < entries; i++) { - if (ptr->queue_slot == position) { - cur = ptr->head; - break; - } - ptr++; - } - - if (!cur) { /* queue is empty */ - ret->req_type = -1; - return ret; - } - - snprintf(ret->req_id, sizeof(ret->req_id), "%s", cur->msg->req_id); - ret->req_type = cur->msg->req_type; - ret->uid = cur->msg->uid; - snprintf(ret->pkg_type, sizeof(ret->pkg_type), "%s", cur->msg->pkg_type); - snprintf(ret->pkgid, sizeof(ret->pkgid), "%s", cur->msg->pkgid); - if (cur->msg->args) - ret->args = strdup(cur->msg->args); - - ptr->head = cur->next; - saveptr = ptr->head; - cur->next = NULL; - free(cur->msg); - free(cur); - /* update head for each duplicate queue entry */ - ptr = start; - for (i = 0; i < entries; i++) { - if (ptr->queue_slot == position) - ptr->head = saveptr; - - ptr++; - } - return ret; -} - -/* populate an array of all queue heads and delete them one by one */ -void _pm_queue_final() -{ - int c = 0; - int i = 0; - int slot = -1; - pm_queue_data *cur = NULL; - pm_queue_data *tail = NULL; - pm_queue_data *prev = NULL; - pm_queue_data *head[MAX_QUEUE_NUM] = {NULL,}; - queue_info_map *ptr = NULL; - ptr = start; - - for (i = 0; i < num_of_backends; i++) - head[i] = NULL; - - for (i = 0; i < entries; i++) { - if (ptr->queue_slot <= slot) { - ptr++; - } else { - head[c] = ptr->head; - slot = ptr->queue_slot; - c++; - ptr++; - } - } - - c = 0; - while (c < num_of_backends) { - if (!head[c]) { /* in case of head is NULL */ - c = c + 1; - continue; - } - - while (head[c]->next) { - cur = head[c]->next; - - while (cur->next) { - prev = cur; - cur = cur->next; - } - - tail = cur; - - free(tail->msg); - free(tail); - prev->next = NULL; - } - - free(head[c]->msg->args); - free(head[c]->msg); - free(head[c]); - - head[c] = NULL; - c = c + 1; - } - /*Free the info map*/ - if (start) { - free(start); - start = NULL; - } -} - -pm_queue_data *_add_node() -{ - pm_queue_data *newnode = NULL; - - newnode = (pm_queue_data *) malloc(sizeof(pm_queue_data)); - if (!newnode) { /* if NULL */ - ERR("Mem alloc error"); - return NULL; - } - memset(newnode, 0x00, sizeof(pm_queue_data)); - - newnode->msg = (pm_dbus_msg *) malloc(sizeof(pm_dbus_msg)); - if (!newnode->msg) { - ERR("Mem alloc error"); - free(newnode); - return NULL; - } - memset(newnode->msg, 0x00, sizeof(pm_dbus_msg)); - - return newnode; -} - -void _pm_queue_delete(pm_dbus_msg *item) -{ - /* Assume that pacakge name is unique */ - pm_queue_data *cur = NULL; - pm_queue_data *prev = NULL; - cur = __get_head_from_pkgtype(item->pkg_type); - prev = cur; - if (cur) { - while (cur->next) { - if (!strcmp(item->pkgid, cur->msg->pkgid)) { - prev->next = cur->next; - free(cur->msg); - free(cur); - break; - } - prev = cur; - cur = cur->next; - } - } -} - -void _print_queue(int position) -{ - pm_queue_data *cur = NULL; - queue_info_map *ptr = start; - int i = 0; - for (i = 0; i < entries; i++) { - if (ptr->queue_slot == position) { - cur = ptr->head; - break; - } - ptr++; - } - int index = 1; - if (!cur) - return; - - while (cur) { - index++; - cur = cur->next; - } -} diff --git a/src/queue.c b/src/queue.c new file mode 100644 index 0000000..2d741ae --- /dev/null +++ b/src/queue.c @@ -0,0 +1,197 @@ +/* + * 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. + * + */ + +#define _XOPEN_SOURCE 500 +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "pkgmgr-server.h" +#include "queue.h" + +#define BACKEND_DIR "/etc/package-manager/backend" +#define NOPENFD 20 + +struct backend_queue { + char *path; + char *type; + int slot; + GList *job_list; +}; + +static GHashTable *queue_type_table; +static GHashTable *queue_slot_table; + +int num_of_backends; + +int _is_queue_empty(int pos) +{ + struct backend_queue *queue; + + queue = (struct backend_queue *)g_hash_table_lookup(queue_slot_table, + (gconstpointer)pos); + if (queue == NULL) { + ERR("cannot find queue of slot %d", pos); + return -1; + } + + if (queue->job_list == NULL) + return 1; + + return 0; +} + +struct backend_job *_pop_queue(int pos) +{ + struct backend_queue *queue; + struct backend_job *job; + GList *tmp; + + queue = (struct backend_queue *)g_hash_table_lookup(queue_slot_table, + (gconstpointer)pos); + if (queue == NULL) { + ERR("cannot find queue of slot %d", pos); + return NULL; + } + + tmp = g_list_first(queue->job_list); + if (tmp == NULL) + return NULL; + job = (struct backend_job *)tmp->data; + queue->job_list = g_list_delete_link(queue->job_list, tmp); + + return job; +} + +int _push_queue(uid_t uid, const char *req_id, int req_type, + const char *queue_type, const char *pkgid, const char *args) +{ + struct backend_queue *queue; + struct backend_job *job; + + queue = (struct backend_queue *)g_hash_table_lookup(queue_type_table, + (gconstpointer)queue_type); + if (queue == NULL) { + ERR("no such queue: %s", queue_type); + return -1; + } + + job = calloc(1, sizeof(struct backend_job)); + job->uid = uid; + if (req_id) + job->req_id = strdup(req_id); + job->req_type = req_type; + if (pkgid) + job->pkgid = strdup(pkgid); + if (args) + job->args = strdup(args); + /* just assign pointer value */ + job->backend_slot = queue->slot; + job->backend_type = queue->type; + job->backend_path = queue->path; + + queue->job_list = g_list_append(queue->job_list, (gpointer)job); + + return 0; +} + +static int __init_backends(const char *fpath, const struct stat *sb, + int typeflag, struct FTW *ftwbuf) +{ + struct backend_queue *queue; + + if (typeflag != FTW_F && typeflag != FTW_SL) + return 0; + + queue = calloc(1, sizeof(struct backend_queue)); + if (typeflag == FTW_F) { + queue->path = strdup(fpath); + } else if (typeflag == FTW_SL) { + queue->path = malloc(sb->st_size + 1); + if (readlink(fpath, queue->path, sb->st_size + 1) < 0) { + ERR("failed to readlink for %s", fpath); + free(queue->path); + free(queue); + return -1; + } + } + queue->type = strdup(fpath + ftwbuf->base); + queue->slot = num_of_backends++; + g_hash_table_insert(queue_type_table, (gpointer)queue->type, + (gpointer)queue); + g_hash_table_insert(queue_slot_table, (gpointer)queue->slot, + (gpointer)queue); + + DBG("backend detected: %s(%s)", queue->type, queue->path); + + return 0; +} + +static gboolean __str_equal(gconstpointer v1, gconstpointer v2) +{ + const char *str1 = (const char *)v1; + const char *str2 = (const char *)v2; + + /* ignore case */ + return strcasecmp(str1, str2) == 0; +} + +void _free_backend_job(struct backend_job *job) +{ + free(job->req_id); + free(job->pkgid); + free(job->appid); + free(job->args); + free(job); +} + +static void __free_backend_queue(gpointer data) +{ + struct backend_queue *queue = (struct backend_queue *)data; + + g_list_free_full(queue->job_list, (GDestroyNotify)_free_backend_job); + free(queue->path); + free(queue->type); + free(queue); +} + +void _fini_backend_queue(void) +{ + g_hash_table_destroy(queue_slot_table); + g_hash_table_destroy(queue_type_table); +} + +int _init_backend_queue(void) +{ + queue_type_table = g_hash_table_new_full(g_str_hash, __str_equal, + NULL, __free_backend_queue); + queue_slot_table = g_hash_table_new(g_direct_hash, g_direct_equal); + + if (nftw(BACKEND_DIR, __init_backends, NOPENFD, FTW_PHYS)) + return -1; + + DBG("number of backends: %d", num_of_backends); + + return 0; +} diff --git a/src/request.c b/src/request.c index 3ae16c7..5f4668b 100644 --- a/src/request.c +++ b/src/request.c @@ -7,7 +7,7 @@ #include #include -#include "pm-queue.h" +#include "queue.h" #include "pkgmgr-server.h" #include "package-manager.h" @@ -276,7 +276,8 @@ static int __handle_request_install(uid_t uid, int i = 0; int len = 0; - g_variant_get(parameters, "(u&s&s@as)", &target_uid, &pkgtype, &pkgpath, &value); + 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++) @@ -319,7 +320,7 @@ static int __handle_request_install(uid_t uid, goto catch; } - if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_INSTALL, pkgtype, + if (_push_queue(target_uid, reqkey, REQUEST_TYPE_INSTALL, pkgtype, pkgpath, args)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); @@ -357,7 +358,8 @@ static int __handle_request_mount_install(uid_t uid, int i = 0; int len = 0; - g_variant_get(parameters, "(u&s&s@as)", &target_uid, &pkgtype, &pkgpath, &value); + 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++) @@ -400,8 +402,8 @@ static int __handle_request_mount_install(uid_t uid, goto catch; } - if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_MOUNT_INSTALL, - pkgtype, pkgpath, args)) { + if (_push_queue(target_uid, reqkey, REQUEST_TYPE_MOUNT_INSTALL, + pkgtype, pkgpath, args)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); ret = -1; @@ -443,8 +445,8 @@ static int __handle_request_reinstall(uid_t uid, g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); return -1; } - if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_REINSTALL, pkgtype, - pkgid, "")) { + if (_push_queue(target_uid, reqkey, REQUEST_TYPE_REINSTALL, pkgtype, + pkgid, NULL)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); free(reqkey); @@ -479,8 +481,8 @@ static int __handle_request_uninstall(uid_t uid, g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); return -1; } - if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_UNINSTALL, pkgtype, - pkgid, "")) { + if (_push_queue(target_uid, reqkey, REQUEST_TYPE_UNINSTALL, pkgtype, + pkgid, NULL)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); free(reqkey); @@ -504,7 +506,8 @@ static int __handle_request_move(uid_t uid, int move_type = -1; char buf[4] = { '\0' }; - g_variant_get(parameters, "(u&s&si)", &target_uid, &pkgtype, &pkgid, &move_type); + 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, "")); @@ -519,7 +522,7 @@ static int __handle_request_move(uid_t uid, } snprintf(buf, sizeof(buf), "%d", move_type); - if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_MOVE, pkgtype, + if (_push_queue(target_uid, reqkey, REQUEST_TYPE_MOVE, pkgtype, pkgid, buf)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); @@ -558,9 +561,8 @@ static int __handle_request_enable_pkgs(uid_t uid, return -1; } - if (_pm_queue_push(target_uid, reqkey, - PKGMGR_REQUEST_TYPE_ENABLE_PKG, - pkgtype, pkgid, "")) { + if (_push_queue(target_uid, reqkey, REQUEST_TYPE_ENABLE_PKG, + pkgtype, pkgid, NULL)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); free(reqkey); @@ -600,9 +602,8 @@ static int __handle_request_disable_pkgs(uid_t uid, return -1; } - if (_pm_queue_push(target_uid, reqkey, - PKGMGR_REQUEST_TYPE_DISABLE_PKG, - pkgtype, pkgid, "")) { + if (_push_queue(target_uid, reqkey, REQUEST_TYPE_DISABLE_PKG, + pkgtype, pkgid, NULL)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); free(reqkey); @@ -641,8 +642,8 @@ static int __handle_request_enable_app(uid_t uid, goto catch; } - if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_ENABLE_APP, "default", - appid, "")) { + if (_push_queue(target_uid, reqkey, REQUEST_TYPE_ENABLE_APP, "default", + appid, NULL)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); ret = -1; @@ -684,8 +685,8 @@ static int __handle_request_disable_app(uid_t uid, goto catch; } - if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_DISABLE_APP, "default", - appid, "")) { + if (_push_queue(target_uid, reqkey, REQUEST_TYPE_DISABLE_APP, "default", + appid, NULL)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); ret = -1; @@ -727,8 +728,9 @@ 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, "default", - appid, "")) { + if (_push_queue(target_uid, reqkey, + REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID, + "default", appid, NULL)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); ret = -1; @@ -770,8 +772,9 @@ 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, "default", - appid, "")) { + if (_push_queue(target_uid, reqkey, + REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID, + "default", appid, NULL)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); ret = -1; @@ -814,7 +817,7 @@ static int __handle_request_getsize(uid_t uid, } snprintf(buf, sizeof(buf), "%d", get_type); - if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_GETSIZE, "pkgtool", + if (_push_queue(target_uid, reqkey, REQUEST_TYPE_GETSIZE, "pkgtool", pkgid, buf)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); @@ -851,8 +854,8 @@ static int __handle_request_cleardata(uid_t uid, return -1; } - if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_CLEARDATA, pkgtype, - pkgid, "")) { + if (_push_queue(target_uid, reqkey, REQUEST_TYPE_CLEARDATA, pkgtype, + pkgid, NULL)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); free(reqkey); @@ -880,8 +883,8 @@ static int __handle_request_clearcache(uid_t uid, return -1; } - if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_CLEARCACHE, - "pkgtool", pkgid, "")) { + if (_push_queue(target_uid, NULL, REQUEST_TYPE_CLEARCACHE, + "pkgtool", pkgid, NULL)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); return -1; @@ -914,8 +917,8 @@ static int __handle_request_kill(uid_t uid, return -1; } - if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_KILL, - "default", pkgid, "")) { + if (_push_queue(target_uid, reqkey, REQUEST_TYPE_KILL, + "default", pkgid, NULL)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(ii)", PKGMGR_R_ESYSTEM, 0)); free(reqkey); @@ -950,8 +953,8 @@ static int __handle_request_check(uid_t uid, return -1; } - if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_CHECK, - "default", pkgid, "")) { + if (_push_queue(target_uid, reqkey, REQUEST_TYPE_CHECK, + "default", pkgid, NULL)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(ii)", PKGMGR_R_ESYSTEM, 0)); free(reqkey); @@ -986,9 +989,9 @@ static int __handle_request_generate_license_request(uid_t uid, return -1; } - if (_pm_queue_push(uid, reqkey, - PKGMGR_REQUEST_TYPE_GENERATE_LICENSE_REQUEST, - "default", "", resp_data)) { + if (_push_queue(uid, reqkey, + REQUEST_TYPE_GENERATE_LICENSE_REQUEST, + "default", NULL, resp_data)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(iss)", PKGMGR_R_ESYSTEM, "", "")); @@ -1023,8 +1026,8 @@ static int __handle_request_register_license(uid_t uid, return -1; } - if (_pm_queue_push(uid, reqkey, PKGMGR_REQUEST_TYPE_REGISTER_LICENSE, - "default", "", resp_data)) { + if (_push_queue(uid, reqkey, REQUEST_TYPE_REGISTER_LICENSE, + "default", NULL, resp_data)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); free(reqkey); @@ -1060,8 +1063,9 @@ static int __handle_request_decrypt_package(uid_t uid, return -1; } - if (_pm_queue_push(uid, reqkey, PKGMGR_REQUEST_TYPE_DECRYPT_PACKAGE, - "default", drm_file_path, decrypted_file_path)) { + if (_push_queue(uid, reqkey, REQUEST_TYPE_DECRYPT_PACKAGE, + "default", drm_file_path, + decrypted_file_path)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); free(reqkey); @@ -1099,8 +1103,8 @@ static int __update_app_splash_screen(uid_t uid, return -1; } - if (_pm_queue_push(target_uid, reqkey, req_type, "default", - appid, "")) { + if (_push_queue(target_uid, reqkey, req_type, "default", + appid, NULL)) { ERR("Failed to push request"); g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); @@ -1121,14 +1125,14 @@ 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); + 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); + REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN); } static int __handle_request_set_restriction_mode(uid_t uid, @@ -1155,8 +1159,8 @@ 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, + if (_push_queue(target_uid, reqkey, + REQUEST_TYPE_SET_RESTRICTION_MODE, "default", pkgid, buf)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); @@ -1195,8 +1199,8 @@ 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, + if (_push_queue(target_uid, reqkey, + REQUEST_TYPE_UNSET_RESTRICTION_MODE, "default", pkgid, buf)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); @@ -1232,9 +1236,9 @@ static int __handle_request_get_restriction_mode(uid_t uid, return -1; } - if (_pm_queue_push(target_uid, reqkey, - PKGMGR_REQUEST_TYPE_GET_RESTRICTION_MODE, - "default", pkgid, "")) { + if (_push_queue(target_uid, reqkey, + REQUEST_TYPE_GET_RESTRICTION_MODE, + "default", pkgid, NULL)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(ii)", -1, PKGMGR_R_ESYSTEM)); free(reqkey); @@ -1290,7 +1294,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); + 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) @@ -1312,9 +1317,11 @@ static void __handle_method_call(GDBusConnection *connection, else if (g_strcmp0(method_name, "disable_app") == 0) ret = __handle_request_disable_app(uid, invocation, parameters); else if (g_strcmp0(method_name, "enable_global_app_for_uid") == 0) - ret = __handle_request_enable_global_app_for_uid(uid, invocation, parameters); + ret = __handle_request_enable_global_app_for_uid(uid, + invocation, parameters); else if (g_strcmp0(method_name, "disable_global_app_for_uid") == 0) - ret = __handle_request_disable_global_app_for_uid(uid, invocation, parameters); + ret = __handle_request_disable_global_app_for_uid(uid, + invocation, parameters); else if (g_strcmp0(method_name, "kill") == 0) ret = __handle_request_kill(uid, invocation, parameters); else if (g_strcmp0(method_name, "check") == 0) @@ -1350,7 +1357,7 @@ static void __handle_method_call(GDBusConnection *connection, g_idle_add(queue_job, NULL); } -int __return_value_to_caller(const char *req_key, GVariant *result) +int _return_value_to_caller(const char *req_key, GVariant *result) { GDBusMethodInvocation *invocation; @@ -1403,9 +1410,10 @@ static void __on_name_lost(GDBusConnection *connection, const gchar *name, DBG("on name lost: %s", name); } -int __init_request_handler(void) +int _init_request_handler(void) { - instropection_data = g_dbus_node_info_new_for_xml(instropection_xml, NULL); + instropection_data = g_dbus_node_info_new_for_xml(instropection_xml, + NULL); owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, PKGMGR_DBUS_SERVICE, G_BUS_NAME_OWNER_FLAGS_NONE, __on_bus_acquired, @@ -1419,7 +1427,7 @@ int __init_request_handler(void) return 0; } -void __fini_request_handler(void) +void _fini_request_handler(void) { g_hash_table_destroy(req_table); g_bus_unown_name(owner_id); diff --git a/src/restriction_mode.c b/src/restriction_mode.c index a3a05fc..98cc83d 100644 --- a/src/restriction_mode.c +++ b/src/restriction_mode.c @@ -290,7 +290,7 @@ static int __get_pkg_restriction_mode(uid_t uid, const char *pkgid, int *mode) return 0; } -int _restriction_mode_set(uid_t uid, const char *pkgid, int mode) +int _set_restriction_mode(uid_t uid, const char *pkgid, int mode) { if (pkgid && strlen(pkgid)) return __update_pkg_restriction_mode(uid, pkgid, mode, @@ -299,7 +299,7 @@ int _restriction_mode_set(uid_t uid, const char *pkgid, int mode) return __set_restriction_mode(uid, mode); } -int _restriction_mode_unset(uid_t uid, const char *pkgid, int mode) +int _unset_restriction_mode(uid_t uid, const char *pkgid, int mode) { if (pkgid && strlen(pkgid)) return __update_pkg_restriction_mode(uid, pkgid, mode, @@ -308,7 +308,7 @@ int _restriction_mode_unset(uid_t uid, const char *pkgid, int mode) return __unset_restriction_mode(uid, mode); } -int _restriction_mode_get(uid_t uid, const char *pkgid, int *mode) +int _get_restriction_mode(uid_t uid, const char *pkgid, int *mode) { if (pkgid && strlen(pkgid)) return __get_pkg_restriction_mode(uid, pkgid, mode); diff --git a/src/signal.c b/src/signal.c index 536f8b3..f6ad233 100644 --- a/src/signal.c +++ b/src/signal.c @@ -56,7 +56,7 @@ static void __free_uid_list(uid_t *uids) free(uids); } -void __send_app_signal(uid_t uid, const char *req_id, +void _send_app_signal(uid_t uid, const char *req_id, const char *pkgid, const char *appid, const char *key, const char *val, int req_type) { @@ -75,24 +75,24 @@ void __send_app_signal(uid_t uid, const char *req_id, goto catch; switch (req_type) { - case PKGMGR_REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID: - case PKGMGR_REQUEST_TYPE_ENABLE_APP: + case REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID: + case REQUEST_TYPE_ENABLE_APP: if (pkgmgr_installer_set_request_type(pi, PKGMGR_REQ_ENABLE_APP)) goto catch; break; - case PKGMGR_REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID: - case PKGMGR_REQUEST_TYPE_DISABLE_APP: + case REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID: + case REQUEST_TYPE_DISABLE_APP: if (pkgmgr_installer_set_request_type(pi, PKGMGR_REQ_DISABLE_APP)) goto catch; break; - case PKGMGR_REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN: + case 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: + case REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN: if (pkgmgr_installer_set_request_type(pi, PKGMGR_REQ_DISABLE_APP_SPLASH_SCREEN)) goto catch; @@ -117,7 +117,7 @@ catch: return; } -void __send_fail_signal(backend_info *info) +void _send_fail_signal(struct backend_job *job) { int req_type; pkgmgr_installer *pi; @@ -130,20 +130,20 @@ void __send_fail_signal(backend_info *info) ERR("Failure in creating the pkgmgr_installer object"); return; } - pkgmgr_installer_set_session_id(pi, info->req_id); - switch (info->req_type) { - case PKGMGR_REQUEST_TYPE_INSTALL: - case PKGMGR_REQUEST_TYPE_MOUNT_INSTALL: - case PKGMGR_REQUEST_TYPE_REINSTALL: + pkgmgr_installer_set_session_id(pi, job->req_id); + switch (job->req_type) { + case REQUEST_TYPE_INSTALL: + case REQUEST_TYPE_MOUNT_INSTALL: + case REQUEST_TYPE_REINSTALL: req_type = PKGMGR_REQ_INSTALL; break; - case PKGMGR_REQUEST_TYPE_UNINSTALL: + case REQUEST_TYPE_UNINSTALL: req_type = PKGMGR_REQ_UNINSTALL; break; - case PKGMGR_REQUEST_TYPE_MOVE: + case REQUEST_TYPE_MOVE: req_type = PKGMGR_REQ_MOVE; break; - case PKGMGR_REQUEST_TYPE_GETSIZE: + case REQUEST_TYPE_GETSIZE: req_type = PKGMGR_REQ_GETSIZE; break; default: @@ -151,16 +151,14 @@ void __send_fail_signal(backend_info *info) break; } pkgmgr_installer_set_request_type(pi, req_type); - pkgmgr_installer_send_signal(pi, info->pkgtype, info->pkgid, + pkgmgr_installer_send_signal(pi, job->backend_type, job->pkgid, "end", "fail"); - n = __get_uid_list(info->uid, &uids); + n = __get_uid_list(job->uid, &uids); for (i = 0; i < n; i++) pkgmgr_installer_send_signal_for_uid(pi, uids[i], - info->pkgtype, info->pkgid, "end", "fail"); + job->backend_type, job->pkgid, "end", "fail"); __free_uid_list(uids); pkgmgr_installer_free(pi); return; } - - -- 2.7.4 From 27cca08ba0fac5d10fd5303bed875adc339280b0 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Tue, 8 Nov 2016 16:12:10 +0900 Subject: [PATCH 02/16] Fix enable/disable pkgs handler Use one request key for each request. Change-Id: I3ab60a450101761400d0913d71b5ab094f049b36 Signed-off-by: Sangyoon Jang --- src/request.c | 58 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/src/request.c b/src/request.c index 5f4668b..7345026 100644 --- a/src/request.c +++ b/src/request.c @@ -60,12 +60,14 @@ static const char instropection_xml[] = " " " " " " + " " " " " " " " " " " " " " + " " " " " " " " @@ -542,38 +544,38 @@ static int __handle_request_enable_pkgs(uid_t uid, { uid_t target_uid = (uid_t)-1; char *pkgtype = NULL; - char *pkgid = NULL; - char *reqkey = NULL; + char *pkgid; + char *reqkey; GVariantIter *iter; g_variant_get(parameters, "(u&sas)", &target_uid, &pkgtype, &iter); if (target_uid == (uid_t)-1 || pkgtype == NULL || iter == NULL) { g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ECOMM)); + g_variant_new("(is)", PKGMGR_R_ECOMM, "")); return -1; } - while (g_variant_iter_loop(iter, "&s", &pkgid)) { - reqkey = __generate_reqkey(pkgid); - if (reqkey == NULL) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ENOMEM)); - return -1; - } + reqkey = __generate_reqkey("enable_pkgs"); + if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); + return -1; + } + while (g_variant_iter_next(iter, "&s", &pkgid)) { if (_push_queue(target_uid, reqkey, REQUEST_TYPE_ENABLE_PKG, pkgtype, pkgid, NULL)) { g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ESYSTEM)); + g_variant_new("(is)", + PKGMGR_R_ESYSTEM, "")); free(reqkey); return -1; } - - free(reqkey); } g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_OK)); + g_variant_new("(is)", PKGMGR_R_OK, reqkey)); + free(reqkey); return 0; } @@ -583,38 +585,38 @@ static int __handle_request_disable_pkgs(uid_t uid, { uid_t target_uid = (uid_t)-1; char *pkgtype = NULL; - char *pkgid = NULL; - char *reqkey = NULL; + char *pkgid; + char *reqkey; GVariantIter *iter; g_variant_get(parameters, "(u&sas)", &target_uid, &pkgtype, &iter); if (target_uid == (uid_t)-1 || pkgtype == NULL || iter == NULL) { g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ECOMM)); + g_variant_new("(is)", PKGMGR_R_ECOMM, "")); return -1; } - while (g_variant_iter_loop(iter, "&s", &pkgid)) { - reqkey = __generate_reqkey(pkgid); - if (reqkey == NULL) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ENOMEM)); - return -1; - } + reqkey = __generate_reqkey("disable_pkgs"); + if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); + return -1; + } + while (g_variant_iter_next(iter, "&s", &pkgid)) { if (_push_queue(target_uid, reqkey, REQUEST_TYPE_DISABLE_PKG, pkgtype, pkgid, NULL)) { g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ESYSTEM)); + g_variant_new("(is)", + PKGMGR_R_ESYSTEM, "")); free(reqkey); return -1; } - - free(reqkey); } g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_OK)); + g_variant_new("(is)", PKGMGR_R_OK, reqkey)); + free(reqkey); return 0; } -- 2.7.4 From d6f32e6a2885055df389c9b9c3376faf71c2401a Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Tue, 8 Nov 2016 19:07:50 +0900 Subject: [PATCH 03/16] Fix a bug in queue_job Change-Id: I101dd3b6dcafda27ed401fdb6c2dd34af6d7b585 Signed-off-by: Sangyoon Jang --- src/pkgmgr-server.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index d824e5e..d5b59ee 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -1343,22 +1343,29 @@ gboolean queue_job(void *data) break; case REQUEST_TYPE_ENABLE_APP: ret = __process_enable_app(job); + _free_backend_job(job); break; case REQUEST_TYPE_DISABLE_APP: ret = __process_disable_app(job); + _free_backend_job(job); break; case REQUEST_TYPE_GETSIZE: __set_backend_busy(x); ret = __process_getsize(job); + g_hash_table_insert(backend_info_table, (gpointer)ret, + (gpointer)job); break; case REQUEST_TYPE_CLEARDATA: __set_backend_busy(x); ret = __process_cleardata(job); + g_hash_table_insert(backend_info_table, (gpointer)ret, + (gpointer)job); break; case REQUEST_TYPE_CLEARCACHE: __set_backend_busy(x); ret = __process_clearcache(job); - _free_backend_job(job); + g_hash_table_insert(backend_info_table, (gpointer)ret, + (gpointer)job); break; case REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID: ret = __process_enable_global_app_for_uid(job); -- 2.7.4 From 6f4967d409088e0f0a85aea14d71c6fc75ddeb3a Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 11 Nov 2016 07:51:45 +0900 Subject: [PATCH 04/16] Fix memory leak Change-Id: Ie588a5a60ad426e070b62367f36078ee82a0a454 Signed-off-by: Hwankyu Jhun --- src/request.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/request.c b/src/request.c index 7345026..ad964c1 100644 --- a/src/request.c +++ b/src/request.c @@ -342,6 +342,9 @@ catch: if (args) free(args); + if (tmp_args) + g_free(tmp_args); + return ret; } @@ -423,6 +426,9 @@ catch: if (args) free(args); + if (tmp_args) + g_free(tmp_args); + return ret; } -- 2.7.4 From e85d6878662f18050a54369fb36aabf6a578b360 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Fri, 11 Nov 2016 21:51:46 +0900 Subject: [PATCH 05/16] apply retry logic to get an user type using gum api. Change-Id: I3c72109483737e0ba8281cadde48b24e9f7d2928 Signed-off-by: jongmyeongko --- src/request.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/request.c b/src/request.c index ad964c1..7a5ba92 100644 --- a/src/request.c +++ b/src/request.c @@ -11,6 +11,8 @@ #include "pkgmgr-server.h" #include "package-manager.h" +#define RETRY_MAX 5 +#define RETRY_WAIT_USEC (1000000 / 2) /* 0.5 sec */ #define PKGMGR_DBUS_SERVICE "org.tizen.pkgmgr" #define PKGMGR_DBUS_OBJECT_PATH "/org/tizen/pkgmgr" @@ -200,10 +202,21 @@ static int __is_admin_user(uid_t uid) { GumUser *guser; GumUserType ut = GUM_USERTYPE_NONE; + int retry_cnt = 0; + + do { + guser = gum_user_get_sync(uid, FALSE); + if (guser == NULL) { + ERR("cannot get user information from gumd, retry"); + retry_cnt++; + usleep(RETRY_WAIT_USEC); + continue; + } + break; + } while (retry_cnt <= RETRY_MAX); - guser = gum_user_get_sync(uid, FALSE); if (guser == NULL) { - ERR("cannot get user information from gumd"); + ERR("cannot get user information from gumd, failed"); return -1; } -- 2.7.4 From b3063a9f0fee0e431d45b1ce641f7f66e43097f6 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Thu, 24 Nov 2016 19:26:16 +0900 Subject: [PATCH 06/16] Fix build dependency Remove unused dependency. Add some missing dependency obviously. Change-Id: I1461d25385616593f54e7c4f13d254c28e7fd96f Signed-off-by: Sangyoon Jang --- CMakeLists.txt | 2 +- packaging/pkgmgr-server.spec | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fe7ecc3..dd3badc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,7 @@ INCLUDE(FindPkgConfig) SET(PKGMGR_SERVER "pkgmgr-server") AUX_SOURCE_DIRECTORY(src SRCS) -SET(SERVER_CHECK_MODULES gio-2.0 dlog pkgmgr-parser pkgmgr-info libtzplatform-config drm-service-core-tizen libgum sqlite3 pkgmgr pkgmgr-installer libsystemd aul) +SET(SERVER_CHECK_MODULES gio-2.0 glib-2.0 dlog pkgmgr-parser pkgmgr-info libtzplatform-config drm-service-core-tizen libgum sqlite3 pkgmgr pkgmgr-installer libsystemd aul) IF(TIZEN_FEATURE_CSR) SET(SERVER_CHECK_MODULES "${SERVER_CHECK_MODULES} csr") ENDIF(TIZEN_FEATURE_CSR) diff --git a/packaging/pkgmgr-server.spec b/packaging/pkgmgr-server.spec index 1fcf88e..008b254 100644 --- a/packaging/pkgmgr-server.spec +++ b/packaging/pkgmgr-server.spec @@ -9,26 +9,21 @@ Source1001: %{name}.manifest BuildRequires: cmake BuildRequires: unzip BuildRequires: gettext-tools -BuildRequires: pkgconfig(dbus-glib-1) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(aul) BuildRequires: pkgconfig(bundle) BuildRequires: pkgconfig(pkgmgr-info) -BuildRequires: pkgconfig(iniparser) BuildRequires: pkgconfig(libtzplatform-config) -BuildRequires: pkgconfig(security-manager) -BuildRequires: pkgconfig(xdgmime) -BuildRequires: pkgconfig(db-util) BuildRequires: pkgconfig(pkgmgr) +BuildRequires: pkgconfig(pkgmgr-info) BuildRequires: pkgconfig(pkgmgr-installer) +BuildRequires: pkgconfig(pkgmgr-parser) BuildRequires: pkgconfig(drm-service-core-tizen) BuildRequires: pkgconfig(libgum) BuildRequires: pkgconfig(sqlite3) BuildRequires: pkgconfig(libsystemd) -BuildRequires: pkgmgr-info-parser-devel -BuildRequires: pkgmgr-info-parser BuildRequires: fdupes %if "%{?profile}" != "tv" -- 2.7.4 From a1efb52511e05e0c27d5cd716dc6d93b4507e0e1 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Thu, 24 Nov 2016 20:54:36 +0900 Subject: [PATCH 07/16] Get pkgtype from given pkgid or pkgfile Submit with: - https://review.tizen.org/gerrit/99922 - https://review.tizen.org/gerrit/99944 Change-Id: I1392aa95b3ec8316255fbcd3d9f285463d3b8c99 Signed-off-by: Sangyoon Jang --- CMakeLists.txt | 2 +- include/pkgmgr-server.h | 2 + packaging/pkgmgr-server.spec | 1 + src/request.c | 125 ++++++++++++++++++++++++++++++------------- src/util.c | 74 +++++++++++++++++++++++++ 5 files changed, 166 insertions(+), 38 deletions(-) create mode 100644 src/util.c diff --git a/CMakeLists.txt b/CMakeLists.txt index dd3badc..b7bf90d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,7 @@ INCLUDE(FindPkgConfig) SET(PKGMGR_SERVER "pkgmgr-server") AUX_SOURCE_DIRECTORY(src SRCS) -SET(SERVER_CHECK_MODULES gio-2.0 glib-2.0 dlog pkgmgr-parser pkgmgr-info libtzplatform-config drm-service-core-tizen libgum sqlite3 pkgmgr pkgmgr-installer libsystemd aul) +SET(SERVER_CHECK_MODULES gio-2.0 glib-2.0 dlog pkgmgr-parser pkgmgr-info libtzplatform-config drm-service-core-tizen libgum sqlite3 pkgmgr pkgmgr-installer libsystemd aul minizip) IF(TIZEN_FEATURE_CSR) SET(SERVER_CHECK_MODULES "${SERVER_CHECK_MODULES} csr") ENDIF(TIZEN_FEATURE_CSR) diff --git a/include/pkgmgr-server.h b/include/pkgmgr-server.h index 288798e..895c9bd 100644 --- a/include/pkgmgr-server.h +++ b/include/pkgmgr-server.h @@ -90,5 +90,7 @@ void _send_fail_signal(struct backend_job *job); int _set_restriction_mode(uid_t uid, const char *pkgid, int mode); int _unset_restriction_mode(uid_t uid, const char *pkgid, int mode); int _get_restriction_mode(uid_t uid, const char *pkgid, int *mode); +const char *_get_pkgtype_from_file(const char *file_path); +char *_get_pkgtype_from_pkgid(const char *pkgid, uid_t uid); #endif/* _PKGMGR_SERVER_H_ */ diff --git a/packaging/pkgmgr-server.spec b/packaging/pkgmgr-server.spec index 008b254..b27c953 100644 --- a/packaging/pkgmgr-server.spec +++ b/packaging/pkgmgr-server.spec @@ -24,6 +24,7 @@ BuildRequires: pkgconfig(drm-service-core-tizen) BuildRequires: pkgconfig(libgum) BuildRequires: pkgconfig(sqlite3) BuildRequires: pkgconfig(libsystemd) +BuildRequires: pkgconfig(minizip) BuildRequires: fdupes %if "%{?profile}" != "tv" diff --git a/src/request.c b/src/request.c index 7a5ba92..4698da9 100644 --- a/src/request.c +++ b/src/request.c @@ -21,7 +21,6 @@ static const char instropection_xml[] = " " " " " " - " " " " " " " " @@ -29,14 +28,12 @@ static const char instropection_xml[] = " " " " " " - " " " " " " " " " " " " " " - " " " " " " " " @@ -44,14 +41,12 @@ static const char instropection_xml[] = " " " " " " - " " " " " " " " " " " " " " - " " " " " " " " @@ -59,14 +54,12 @@ static const char instropection_xml[] = " " " " " " - " " " " " " " " " " " " " " - " " " " " " " " @@ -104,7 +97,6 @@ static const char instropection_xml[] = " " " " " " - " " " " " " " " @@ -280,7 +272,7 @@ static int __handle_request_install(uid_t uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; - char *pkgtype = NULL; + const char *pkgtype; char *pkgpath = NULL; char *args = NULL; char *reqkey = NULL; @@ -291,8 +283,7 @@ static int __handle_request_install(uid_t uid, int i = 0; int len = 0; - g_variant_get(parameters, "(u&s&s@as)", &target_uid, &pkgtype, &pkgpath, - &value); + g_variant_get(parameters, "(u&s@as)", &target_uid, &pkgpath, &value); tmp_args = (gchar **)g_variant_get_strv(value, &args_count); for (i = 0; i < args_count; i++) @@ -313,14 +304,15 @@ static int __handle_request_install(uid_t uid, strncat(args, " ", strlen(" ")); } - if (target_uid == (uid_t)-1 || pkgtype == NULL) { + if (target_uid == (uid_t)-1 || pkgpath == NULL) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ECOMM, "")); ret = -1; goto catch; } - if (pkgpath == NULL) { + pkgtype = _get_pkgtype_from_file(pkgpath); + if (pkgtype == NULL) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ECOMM, "")); ret = -1; @@ -365,7 +357,7 @@ static int __handle_request_mount_install(uid_t uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; - char *pkgtype = NULL; + const char *pkgtype; char *pkgpath = NULL; char *args = NULL; char *reqkey = NULL; @@ -376,8 +368,7 @@ static int __handle_request_mount_install(uid_t uid, int i = 0; int len = 0; - g_variant_get(parameters, "(u&s&s@as)", &target_uid, &pkgtype, &pkgpath, - &value); + g_variant_get(parameters, "(u&s@as)", &target_uid, &pkgpath, &value); tmp_args = (gchar **)g_variant_get_strv(value, &args_count); for (i = 0; i < args_count; i++) @@ -398,14 +389,15 @@ static int __handle_request_mount_install(uid_t uid, strncat(args, " ", strlen(" ")); } - if (target_uid == (uid_t)-1 || pkgtype == NULL) { + if (target_uid == (uid_t)-1 || pkgpath == NULL) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ECOMM, "")); ret = -1; goto catch; } - if (pkgpath == NULL) { + pkgtype = _get_pkgtype_from_file(pkgpath); + if (pkgtype == NULL) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ECOMM, "")); ret = -1; @@ -449,21 +441,29 @@ static int __handle_request_reinstall(uid_t uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; - char *pkgtype = NULL; + char *pkgtype; char *pkgid = NULL; char *reqkey; - g_variant_get(parameters, "(u&s&s)", &target_uid, &pkgtype, &pkgid); - if (target_uid == (uid_t)-1 || pkgtype == NULL || 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("(is)", PKGMGR_R_ECOMM, "")); return -1; } + pkgtype = _get_pkgtype_from_pkgid(pkgid, target_uid); + if (pkgtype == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); + return -1; + } + reqkey = __generate_reqkey(pkgid); if (reqkey == NULL) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); + free(pkgtype); return -1; } if (_push_queue(target_uid, reqkey, REQUEST_TYPE_REINSTALL, pkgtype, @@ -471,12 +471,14 @@ static int __handle_request_reinstall(uid_t uid, g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); free(reqkey); + free(pkgtype); return -1; } g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_OK, reqkey)); free(reqkey); + free(pkgtype); return 0; } @@ -485,21 +487,29 @@ static int __handle_request_uninstall(uid_t uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; - char *pkgtype = NULL; + char *pkgtype; char *pkgid = NULL; char *reqkey; - g_variant_get(parameters, "(u&s&s)", &target_uid, &pkgtype, &pkgid); - if (target_uid == (uid_t)-1 || pkgtype == NULL || 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("(is)", PKGMGR_R_ECOMM, "")); return -1; } + pkgtype = _get_pkgtype_from_pkgid(pkgid, target_uid); + if (pkgtype == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); + return -1; + } + reqkey = __generate_reqkey(pkgid); if (reqkey == NULL) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); + free(pkgtype); return -1; } if (_push_queue(target_uid, reqkey, REQUEST_TYPE_UNINSTALL, pkgtype, @@ -507,12 +517,14 @@ static int __handle_request_uninstall(uid_t uid, g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); free(reqkey); + free(pkgtype); return -1; } g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_OK, reqkey)); free(reqkey); + free(pkgtype); return 0; } @@ -521,24 +533,31 @@ static int __handle_request_move(uid_t uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; - char *pkgtype = NULL; + char *pkgtype; char *pkgid = NULL; char *reqkey; int move_type = -1; char buf[4] = { '\0' }; - g_variant_get(parameters, "(u&s&si)", &target_uid, &pkgtype, &pkgid, - &move_type); - if (target_uid == (uid_t)-1 || pkgtype == NULL || pkgid == NULL) { + g_variant_get(parameters, "(u&si)", &target_uid, &pkgid, &move_type); + if (target_uid == (uid_t)-1 || pkgid == NULL) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ECOMM, "")); return -1; } + pkgtype = _get_pkgtype_from_pkgid(pkgid, target_uid); + if (pkgtype == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); + return -1; + } + reqkey = __generate_reqkey(pkgid); if (reqkey == NULL) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); + free(pkgtype); return -1; } @@ -548,12 +567,14 @@ static int __handle_request_move(uid_t uid, g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); free(reqkey); + free(pkgtype); return -1; } g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_OK, reqkey)); free(reqkey); + free(pkgtype); return 0; } @@ -562,13 +583,13 @@ static int __handle_request_enable_pkgs(uid_t uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; - char *pkgtype = NULL; + char *pkgtype; char *pkgid; char *reqkey; GVariantIter *iter; - g_variant_get(parameters, "(u&sas)", &target_uid, &pkgtype, &iter); - if (target_uid == (uid_t)-1 || pkgtype == NULL || iter == NULL) { + g_variant_get(parameters, "(uas)", &target_uid, &iter); + if (target_uid == (uid_t)-1 || iter == NULL) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ECOMM, "")); return -1; @@ -582,14 +603,24 @@ static int __handle_request_enable_pkgs(uid_t uid, } while (g_variant_iter_next(iter, "&s", &pkgid)) { + pkgtype = _get_pkgtype_from_pkgid(pkgid, target_uid); + if (pkgtype == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", + PKGMGR_R_ESYSTEM, "")); + free(reqkey); + return -1; + } if (_push_queue(target_uid, reqkey, REQUEST_TYPE_ENABLE_PKG, pkgtype, pkgid, NULL)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); + free(pkgtype); free(reqkey); return -1; } + free(pkgtype); } g_dbus_method_invocation_return_value(invocation, @@ -603,13 +634,13 @@ static int __handle_request_disable_pkgs(uid_t uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; - char *pkgtype = NULL; + char *pkgtype; char *pkgid; char *reqkey; GVariantIter *iter; - g_variant_get(parameters, "(u&sas)", &target_uid, &pkgtype, &iter); - if (target_uid == (uid_t)-1 || pkgtype == NULL || iter == NULL) { + g_variant_get(parameters, "(uas)", &target_uid, &iter); + if (target_uid == (uid_t)-1 || iter == NULL) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ECOMM, "")); return -1; @@ -623,14 +654,24 @@ static int __handle_request_disable_pkgs(uid_t uid, } while (g_variant_iter_next(iter, "&s", &pkgid)) { + pkgtype = _get_pkgtype_from_pkgid(pkgid, target_uid); + if (pkgtype == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", + PKGMGR_R_ESYSTEM, "")); + free(reqkey); + return -1; + } if (_push_queue(target_uid, reqkey, REQUEST_TYPE_DISABLE_PKG, pkgtype, pkgid, NULL)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); + free(pkgtype); free(reqkey); return -1; } + free(pkgtype); } g_dbus_method_invocation_return_value(invocation, @@ -857,21 +898,29 @@ static int __handle_request_cleardata(uid_t uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; - char *pkgtype = NULL; + char *pkgtype; 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) { + 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; } + pkgtype = _get_pkgtype_from_pkgid(pkgid, target_uid); + if (pkgtype == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(i)", PKGMGR_R_ESYSTEM)); + return -1; + } + reqkey = __generate_reqkey(pkgid); if (reqkey == NULL) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ENOMEM)); + free(pkgtype); return -1; } @@ -880,6 +929,7 @@ static int __handle_request_cleardata(uid_t uid, g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); free(reqkey); + free(pkgtype); return -1; } @@ -887,6 +937,7 @@ static int __handle_request_cleardata(uid_t uid, g_variant_new("(i)", PKGMGR_R_OK)); free(reqkey); + free(pkgtype); return 0; } diff --git a/src/util.c b/src/util.c new file mode 100644 index 0000000..6b683fd --- /dev/null +++ b/src/util.c @@ -0,0 +1,74 @@ +#include +#include + +#include + +#include + +#include "pkgmgr-server.h" + +struct manifest_and_type { + const char *manifest; + const char *type; +}; + +struct manifest_and_type type_map[] = { + { "res/wgt/config.xml", "wgt" }, + { "config.xml", "wgt" }, + { "tizen-manifest.xml", "tpk" }, + { NULL, NULL } +}; + +const char *_get_pkgtype_from_file(const char *file_path) +{ + const char *type = NULL; + unzFile uf; + int i; + + uf = unzOpen(file_path); + if (uf == NULL) { + ERR("failed to open zip file %s", file_path); + return NULL; + } + + for (i = 0; type_map[i].manifest != NULL; i++) { + if (unzLocateFile(uf, type_map[i].manifest, 0) == UNZ_OK) { + DBG("pkgtype of %s: [%s]", file_path, type_map[i].type); + type = type_map[i].type; + break; + } + } + + unzClose(uf); + + return type; +} + +char *_get_pkgtype_from_pkgid(const char *pkgid, uid_t uid) +{ + char *type; + char *pkgtype; + pkgmgrinfo_pkginfo_h info; + int ret; + + ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &info); + if (ret != PMINFO_R_OK) { + ret = pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(pkgid, uid, + &info); + if (ret != PMINFO_R_OK) + return NULL; + } + + ret = pkgmgrinfo_pkginfo_get_type(info, &pkgtype); + if (ret != PMINFO_R_OK) { + pkgmgrinfo_pkginfo_destroy_pkginfo(info); + return NULL; + } + + DBG("pkgtype of %s: [%s]", pkgid, pkgtype); + + type = strdup(pkgtype); + pkgmgrinfo_pkginfo_destroy_pkginfo(info); + + return type; +} -- 2.7.4 From 1be0cffa31214163723b939c6137f89536ffe94b Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Mon, 28 Nov 2016 19:42:24 +0900 Subject: [PATCH 08/16] Consider caller uid when handling request Request for getsize now need caller uid to sending result signal, so pkgmgr-server should pass caller uid to getsize process. Submit with: - https://review.tizen.org/gerrit/100542 - https://review.tizen.org/gerrit/100544 Change-Id: I3ec28b650d705257007ce250c91137116063aa01 Signed-off-by: Sangyoon Jang --- include/queue.h | 8 ++-- src/pkgmgr-server.c | 117 ++++++++++++++++++++++++++------------------------- src/queue.c | 8 ++-- src/request.c | 119 +++++++++++++++++++++++++++------------------------- src/signal.c | 2 +- 5 files changed, 133 insertions(+), 121 deletions(-) diff --git a/include/queue.h b/include/queue.h index 5276ee6..27fd907 100644 --- a/include/queue.h +++ b/include/queue.h @@ -21,7 +21,8 @@ #include struct backend_job { - uid_t uid; + uid_t target_uid; + uid_t caller_uid; int req_type; char *req_id; char *pkgid; @@ -33,8 +34,9 @@ struct backend_job { }; int _is_queue_empty(int pos); -int _push_queue(uid_t uid, const char *req_id, int req_type, - const char *queue_type, const char *pkgid, const char *args); +int _push_queue(uid_t target_uid, uid_t caller_uid, const char *req_id, + int req_type, const char *queue_type, const char *pkgid, + const char *args); struct backend_job *_pop_queue(int pos); void _free_backend_job(struct backend_job *job); int _init_backend_queue(void); diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index d5b59ee..e4c312f 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -637,7 +637,7 @@ static int __process_install(struct backend_job *job) return -1; snprintf(args, sizeof(args), "%s -k %s -i %s -u %d %s", backend_cmd, - job->req_id, job->pkgid, (int)job->uid, job->args); + job->req_id, job->pkgid, (int)job->target_uid, job->args); argv = __generate_argv(args); @@ -659,7 +659,7 @@ static int __process_mount_install(struct backend_job *job) return -1; snprintf(args, sizeof(args), "%s -k %s -w %s -u %d %s", backend_cmd, - job->req_id, job->pkgid, (int)job->uid, job->args); + job->req_id, job->pkgid, (int)job->target_uid, job->args); argv = __generate_argv(args); @@ -681,7 +681,7 @@ static int __process_reinstall(struct backend_job *job) return -1; snprintf(args, sizeof(args), "%s -k %s -r %s -u %d", backend_cmd, - job->req_id, job->pkgid, (int)job->uid); + job->req_id, job->pkgid, (int)job->target_uid); argv = __generate_argv(args); pid = __fork_and_exec_with_args(argv, APPFW_UID); @@ -703,7 +703,7 @@ static int __process_uninstall(struct backend_job *job) return -1; snprintf(args, sizeof(args), "%s -k %s -d %s -u %d", backend_cmd, - job->req_id, job->pkgid, (int)job->uid); + job->req_id, job->pkgid, (int)job->target_uid); argv = __generate_argv(args); pid = __fork_and_exec_with_args(argv, APPFW_UID); @@ -725,7 +725,7 @@ static int __process_move(struct backend_job *job) return -1; snprintf(args, sizeof(args), "%s -k %s -m %s -u %d -t %s", backend_cmd, - job->req_id, job->pkgid, (int)job->uid, job->args); + job->req_id, job->pkgid, (int)job->target_uid, job->args); argv = __generate_argv(args); pid = __fork_and_exec_with_args(argv, APPFW_UID); @@ -747,7 +747,7 @@ static int __process_enable_pkg(struct backend_job *job) return -1; snprintf(args, sizeof(args), "%s -k %s -u %d -A %s", backend_cmd, - job->req_id, (int)job->uid, job->pkgid); + job->req_id, (int)job->target_uid, job->pkgid); argv = __generate_argv(args); pid = __fork_and_exec_with_args(argv, APPFW_UID); @@ -769,7 +769,7 @@ static int __process_disable_pkg(struct backend_job *job) return -1; snprintf(args, sizeof(args), "%s -k %s -u %d -D %s", backend_cmd, - job->req_id, (int)job->uid, job->pkgid); + job->req_id, (int)job->target_uid, job->pkgid); argv = __generate_argv(args); pid = __fork_and_exec_with_args(argv, APPFW_UID); @@ -787,32 +787,32 @@ static int __process_enable_app(struct backend_job *job) /* get actual pkgid and replace it to appid which is currently stored * at pkgid variable */ - ret = __change_job_info(job, job->uid, &is_global); + ret = __change_job_info(job, job->target_uid, &is_global); if (ret != PMINFO_R_OK || strlen(job->appid) == 0) { - _send_app_signal(job->uid, job->req_id, job->pkgid, job->pkgid, + _send_app_signal(job->target_uid, job->req_id, job->pkgid, job->pkgid, PKGMGR_INSTALLER_START_KEY_STR, PKGMGR_INSTALLER_APP_ENABLE_EVENT_STR, job->req_type); - _send_app_signal(job->uid, job->req_id, job->pkgid, job->pkgid, + _send_app_signal(job->target_uid, job->req_id, job->pkgid, job->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, job->req_type); return ret; } - _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid, + _send_app_signal(job->target_uid, job->req_id, job->pkgid, job->appid, PKGMGR_INSTALLER_START_KEY_STR, PKGMGR_INSTALLER_APP_ENABLE_EVENT_STR, job->req_type); ret = pkgmgr_parser_update_app_disable_info_in_usr_db(job->appid, - job->uid, 0); + job->target_uid, 0); if (ret != PMINFO_R_OK) - _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid, + _send_app_signal(job->target_uid, job->req_id, job->pkgid, job->appid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, job->req_type); else - _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid, + _send_app_signal(job->target_uid, job->req_id, job->pkgid, job->appid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR, job->req_type); @@ -828,40 +828,40 @@ static int __process_disable_app(struct backend_job *job) /* get actual pkgid and replace it to appid which is currently stored * at pkgid variable */ - ret = __change_job_info(job, job->uid, &is_global); + ret = __change_job_info(job, job->target_uid, &is_global); if (ret != PMINFO_R_OK || strlen(job->appid) == 0) { - _send_app_signal(job->uid, job->req_id, job->pkgid, job->pkgid, + _send_app_signal(job->target_uid, job->req_id, job->pkgid, job->pkgid, PKGMGR_INSTALLER_START_KEY_STR, PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR, job->req_type); - _send_app_signal(job->uid, job->req_id, job->pkgid, job->pkgid, + _send_app_signal(job->target_uid, job->req_id, job->pkgid, job->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, job->req_type); return ret; } - _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid, + _send_app_signal(job->target_uid, job->req_id, job->pkgid, job->appid, PKGMGR_INSTALLER_START_KEY_STR, PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR, job->req_type); - ret = __kill_app(job->appid, job->uid); + ret = __kill_app(job->appid, job->target_uid); if (ret != 0) { - _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid, + _send_app_signal(job->target_uid, job->req_id, job->pkgid, job->appid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, job->req_type); } ret = pkgmgr_parser_update_app_disable_info_in_usr_db(job->appid, - job->uid, 1); + job->target_uid, 1); if (ret != PMINFO_R_OK) - _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid, + _send_app_signal(job->target_uid, job->req_id, job->pkgid, job->appid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, job->req_type); else - _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid, + _send_app_signal(job->target_uid, job->req_id, job->pkgid, job->appid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR, job->req_type); @@ -877,33 +877,33 @@ static int __process_enable_global_app_for_uid(struct backend_job *job) /* get actual pkgid and replace it to appid which is currently stored * at pkgid variable */ - ret = __change_job_info(job, job->uid, &is_global); + ret = __change_job_info(job, job->target_uid, &is_global); if (ret != PMINFO_R_OK || strlen(job->appid) == 0) { - _send_app_signal(job->uid, job->req_id, job->pkgid, job->pkgid, + _send_app_signal(job->target_uid, job->req_id, job->pkgid, job->pkgid, PKGMGR_INSTALLER_START_KEY_STR, PKGMGR_INSTALLER_GLOBAL_APP_ENABLE_FOR_UID, job->req_type); - _send_app_signal(job->uid, job->req_id, job->pkgid, job->pkgid, + _send_app_signal(job->target_uid, job->req_id, job->pkgid, job->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, job->req_type); return ret; } - _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid, + _send_app_signal(job->target_uid, job->req_id, job->pkgid, job->appid, PKGMGR_INSTALLER_START_KEY_STR, PKGMGR_INSTALLER_GLOBAL_APP_ENABLE_FOR_UID, job->req_type); ret = pkgmgr_parser_update_global_app_disable_for_uid_info_in_db( - job->appid, job->uid, 0); + job->appid, job->target_uid, 0); if (ret != PMINFO_R_OK) - _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid, + _send_app_signal(job->target_uid, job->req_id, job->pkgid, job->appid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, job->req_type); else - _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid, + _send_app_signal(job->target_uid, job->req_id, job->pkgid, job->appid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR, job->req_type); @@ -921,35 +921,35 @@ static int __process_disable_global_app_for_uid(struct backend_job *job) */ ret = __change_job_info(job, GLOBAL_USER, &is_global); if (ret != PMINFO_R_OK || strlen(job->appid) == 0) { - _send_app_signal(job->uid, job->req_id, + _send_app_signal(job->target_uid, job->req_id, job->pkgid, job->pkgid, PKGMGR_INSTALLER_START_KEY_STR, PKGMGR_INSTALLER_GLOBAL_APP_DISABLE_FOR_UID, job->req_type); - _send_app_signal(job->uid, job->req_id, job->pkgid, job->pkgid, + _send_app_signal(job->target_uid, job->req_id, job->pkgid, job->pkgid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, job->req_type); return ret; } - _send_app_signal(job->uid, job->req_id, + _send_app_signal(job->target_uid, job->req_id, job->pkgid, job->appid, PKGMGR_INSTALLER_START_KEY_STR, PKGMGR_INSTALLER_GLOBAL_APP_DISABLE_FOR_UID, job->req_type); - ret = __kill_app(job->appid, job->uid); + ret = __kill_app(job->appid, job->target_uid); ret = pkgmgr_parser_update_global_app_disable_for_uid_info_in_db( - job->appid, job->uid, 1); + job->appid, job->target_uid, 1); if (ret != PMINFO_R_OK) - _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid, + _send_app_signal(job->target_uid, job->req_id, job->pkgid, job->appid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, job->req_type); else - _send_app_signal(job->uid, job->req_id, job->pkgid, job->appid, + _send_app_signal(job->target_uid, job->req_id, job->pkgid, job->appid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR, job->req_type); @@ -959,15 +959,16 @@ static int __process_disable_global_app_for_uid(struct backend_job *job) static int __process_getsize(struct backend_job *job) { - static const char *backend_cmd = "/usr/bin/pkg_getsize"; + static const char backend_cmd[] = "/usr/bin/pkg_getsize"; char **argv; char args[MAX_PKG_ARGS_LEN]; int pid; - snprintf(args, sizeof(args), "%s %s %s -k %s", backend_cmd, job->pkgid, - job->args, job->req_id); + snprintf(args, sizeof(args), "%s %s %s %d -k %s -u %d", + backend_cmd, job->pkgid, job->args, job->caller_uid, + job->req_id, job->target_uid); argv = __generate_argv(args); - pid = __fork_and_exec_with_args(argv, job->uid); + pid = __fork_and_exec_with_args(argv, APPFW_UID); g_strfreev(argv); @@ -987,7 +988,7 @@ static int __process_cleardata(struct backend_job *job) /* TODO: set movetype */ snprintf(args, sizeof(args), "%s -k %s -c %s -u %d", backend_cmd, - job->req_id, job->pkgid, (int)job->uid); + job->req_id, job->pkgid, (int)job->target_uid); argv = __generate_argv(args); pid = __fork_and_exec_with_args(argv, APPFW_UID); @@ -1006,7 +1007,7 @@ static int __process_clearcache(struct backend_job *job) snprintf(args, sizeof(args), "%s %s", backend_cmd, job->pkgid); argv = __generate_argv(args); - pid = __fork_and_exec_with_args(argv, job->uid); + pid = __fork_and_exec_with_args(argv, job->target_uid); g_strfreev(argv); @@ -1019,7 +1020,7 @@ static int __process_kill(struct backend_job *job) pkgmgrinfo_pkginfo_h handle; pkgcmd_data *pdata; - ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(job->pkgid, job->uid, + ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(job->pkgid, job->target_uid, &handle); if (ret < 0) { ERR("Failed to get handle"); @@ -1043,9 +1044,9 @@ static int __process_kill(struct backend_job *job) free(pdata); return -1; } - pdata->uid = job->uid; + pdata->uid = job->target_uid; ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP, - __pkgcmd_app_cb, pdata, job->uid); + __pkgcmd_app_cb, pdata, job->target_uid); _return_value_to_caller(job->req_id, g_variant_new("(ii)", PKGMGR_R_OK, pdata->pid)); @@ -1067,7 +1068,7 @@ static int __process_check(struct backend_job *job) pkgmgrinfo_pkginfo_h handle; pkgcmd_data *pdata; - ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(job->pkgid, job->uid, + ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(job->pkgid, job->target_uid, &handle); if (ret < 0) { ERR("Failed to get handle"); @@ -1091,9 +1092,9 @@ static int __process_check(struct backend_job *job) free(pdata); return -1; } - pdata->uid = job->uid; + pdata->uid = job->target_uid; ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP, - __pkgcmd_app_cb, pdata, job->uid); + __pkgcmd_app_cb, pdata, job->target_uid); _return_value_to_caller(job->req_id, g_variant_new("(ii)", PKGMGR_R_OK, pdata->pid)); @@ -1190,27 +1191,27 @@ static int __process_update_app_splash_screen(struct backend_job *job, int flag) bool is_global = false; const char *val; - ret = __change_job_info(job, job->uid, &is_global); + ret = __change_job_info(job, job->target_uid, &is_global); if (ret != PMINFO_R_OK || strlen(job->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(job->uid, job->req_id, job->pkgid, job->appid, + _send_app_signal(job->target_uid, job->req_id, job->pkgid, job->appid, PKGMGR_INSTALLER_START_KEY_STR, val, job->req_type); if (is_global) - ret = pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(job->appid, job->uid, flag); + ret = pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(job->appid, job->target_uid, flag); else ret = pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db( - job->appid, job->uid, flag); + job->appid, job->target_uid, flag); if (ret != PMINFO_R_OK) - _send_app_signal(job->uid, job->req_id, job->pkgid, + _send_app_signal(job->target_uid, job->req_id, job->pkgid, job->appid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR, job->req_type); else - _send_app_signal(job->uid, job->req_id, job->pkgid, + _send_app_signal(job->target_uid, job->req_id, job->pkgid, job->appid, PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR, job->req_type); @@ -1224,7 +1225,7 @@ static int __process_set_restriction_mode(struct backend_job *job) int mode; mode = atoi(job->args); - ret = _set_restriction_mode(job->uid, job->pkgid, mode); + ret = _set_restriction_mode(job->target_uid, job->pkgid, mode); _return_value_to_caller(job->req_id, g_variant_new("(i)", ret)); @@ -1238,7 +1239,7 @@ static int __process_unset_restriction_mode(struct backend_job *job) int mode; mode = atoi(job->args); - ret = _unset_restriction_mode(job->uid, job->pkgid, mode); + ret = _unset_restriction_mode(job->target_uid, job->pkgid, mode); _return_value_to_caller(job->req_id, g_variant_new("(i)", ret)); @@ -1251,7 +1252,7 @@ static int __process_get_restriction_mode(struct backend_job *job) int ret; int mode = -1; - ret = _get_restriction_mode(job->uid, job->pkgid, &mode); + ret = _get_restriction_mode(job->target_uid, job->pkgid, &mode); _return_value_to_caller(job->req_id, g_variant_new("(ii)", mode, ret)); diff --git a/src/queue.c b/src/queue.c index 2d741ae..11e6ace 100644 --- a/src/queue.c +++ b/src/queue.c @@ -84,8 +84,9 @@ struct backend_job *_pop_queue(int pos) return job; } -int _push_queue(uid_t uid, const char *req_id, int req_type, - const char *queue_type, const char *pkgid, const char *args) +int _push_queue(uid_t target_uid, uid_t caller_uid, const char *req_id, + int req_type, const char *queue_type, const char *pkgid, + const char *args) { struct backend_queue *queue; struct backend_job *job; @@ -98,7 +99,8 @@ int _push_queue(uid_t uid, const char *req_id, int req_type, } job = calloc(1, sizeof(struct backend_job)); - job->uid = uid; + job->target_uid = target_uid; + job->caller_uid = caller_uid; if (req_id) job->req_id = strdup(req_id); job->req_type = req_type; diff --git a/src/request.c b/src/request.c index 4698da9..3269b24 100644 --- a/src/request.c +++ b/src/request.c @@ -268,7 +268,7 @@ static int __check_caller_permission(uid_t uid, return 0; } -static int __handle_request_install(uid_t uid, +static int __handle_request_install(uid_t caller_uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; @@ -327,8 +327,8 @@ static int __handle_request_install(uid_t uid, goto catch; } - if (_push_queue(target_uid, reqkey, REQUEST_TYPE_INSTALL, pkgtype, - pkgpath, args)) { + if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_INSTALL, + pkgtype, pkgpath, args)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); ret = -1; @@ -353,7 +353,7 @@ catch: return ret; } -static int __handle_request_mount_install(uid_t uid, +static int __handle_request_mount_install(uid_t caller_uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; @@ -412,7 +412,8 @@ static int __handle_request_mount_install(uid_t uid, goto catch; } - if (_push_queue(target_uid, reqkey, REQUEST_TYPE_MOUNT_INSTALL, + if (_push_queue(target_uid, caller_uid, reqkey, + REQUEST_TYPE_MOUNT_INSTALL, pkgtype, pkgpath, args)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); @@ -437,7 +438,7 @@ catch: return ret; } -static int __handle_request_reinstall(uid_t uid, +static int __handle_request_reinstall(uid_t caller_uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; @@ -466,8 +467,8 @@ static int __handle_request_reinstall(uid_t uid, free(pkgtype); return -1; } - if (_push_queue(target_uid, reqkey, REQUEST_TYPE_REINSTALL, pkgtype, - pkgid, NULL)) { + if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_REINSTALL, + pkgtype, pkgid, NULL)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); free(reqkey); @@ -483,7 +484,7 @@ static int __handle_request_reinstall(uid_t uid, return 0; } -static int __handle_request_uninstall(uid_t uid, +static int __handle_request_uninstall(uid_t caller_uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; @@ -512,8 +513,8 @@ static int __handle_request_uninstall(uid_t uid, free(pkgtype); return -1; } - if (_push_queue(target_uid, reqkey, REQUEST_TYPE_UNINSTALL, pkgtype, - pkgid, NULL)) { + if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_UNINSTALL, + pkgtype, pkgid, NULL)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); free(reqkey); @@ -529,7 +530,7 @@ static int __handle_request_uninstall(uid_t uid, return 0; } -static int __handle_request_move(uid_t uid, +static int __handle_request_move(uid_t caller_uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; @@ -562,8 +563,8 @@ static int __handle_request_move(uid_t uid, } snprintf(buf, sizeof(buf), "%d", move_type); - if (_push_queue(target_uid, reqkey, REQUEST_TYPE_MOVE, pkgtype, - pkgid, buf)) { + if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_MOVE, + pkgtype, pkgid, buf)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); free(reqkey); @@ -579,7 +580,7 @@ static int __handle_request_move(uid_t uid, return 0; } -static int __handle_request_enable_pkgs(uid_t uid, +static int __handle_request_enable_pkgs(uid_t caller_uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; @@ -611,7 +612,8 @@ static int __handle_request_enable_pkgs(uid_t uid, free(reqkey); return -1; } - if (_push_queue(target_uid, reqkey, REQUEST_TYPE_ENABLE_PKG, + if (_push_queue(target_uid, caller_uid, reqkey, + REQUEST_TYPE_ENABLE_PKG, pkgtype, pkgid, NULL)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", @@ -630,7 +632,7 @@ static int __handle_request_enable_pkgs(uid_t uid, return 0; } -static int __handle_request_disable_pkgs(uid_t uid, +static int __handle_request_disable_pkgs(uid_t caller_uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; @@ -662,7 +664,8 @@ static int __handle_request_disable_pkgs(uid_t uid, free(reqkey); return -1; } - if (_push_queue(target_uid, reqkey, REQUEST_TYPE_DISABLE_PKG, + if (_push_queue(target_uid, caller_uid, reqkey, + REQUEST_TYPE_DISABLE_PKG, pkgtype, pkgid, NULL)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", @@ -681,7 +684,7 @@ static int __handle_request_disable_pkgs(uid_t uid, return 0; } -static int __handle_request_enable_app(uid_t uid, +static int __handle_request_enable_app(uid_t caller_uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; @@ -704,7 +707,8 @@ static int __handle_request_enable_app(uid_t uid, goto catch; } - if (_push_queue(target_uid, reqkey, REQUEST_TYPE_ENABLE_APP, "default", + if (_push_queue(target_uid, caller_uid, reqkey, + REQUEST_TYPE_ENABLE_APP, "default", appid, NULL)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); @@ -724,7 +728,7 @@ catch: return ret; } -static int __handle_request_disable_app(uid_t uid, +static int __handle_request_disable_app(uid_t caller_uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; @@ -747,7 +751,8 @@ static int __handle_request_disable_app(uid_t uid, goto catch; } - if (_push_queue(target_uid, reqkey, REQUEST_TYPE_DISABLE_APP, "default", + if (_push_queue(target_uid, caller_uid, reqkey, + REQUEST_TYPE_DISABLE_APP, "default", appid, NULL)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); @@ -767,7 +772,7 @@ catch: return ret; } -static int __handle_request_enable_global_app_for_uid(uid_t uid, +static int __handle_request_enable_global_app_for_uid(uid_t caller_uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; @@ -790,7 +795,7 @@ static int __handle_request_enable_global_app_for_uid(uid_t uid, goto catch; } - if (_push_queue(target_uid, reqkey, + if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID, "default", appid, NULL)) { g_dbus_method_invocation_return_value(invocation, @@ -811,7 +816,7 @@ catch: return ret; } -static int __handle_request_disable_global_app_for_uid(uid_t uid, +static int __handle_request_disable_global_app_for_uid(uid_t caller_uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; @@ -834,7 +839,7 @@ static int __handle_request_disable_global_app_for_uid(uid_t uid, goto catch; } - if (_push_queue(target_uid, reqkey, + if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID, "default", appid, NULL)) { g_dbus_method_invocation_return_value(invocation, @@ -855,7 +860,7 @@ catch: return ret; } -static int __handle_request_getsize(uid_t uid, +static int __handle_request_getsize(uid_t caller_uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; @@ -879,8 +884,8 @@ static int __handle_request_getsize(uid_t uid, } snprintf(buf, sizeof(buf), "%d", get_type); - if (_push_queue(target_uid, reqkey, REQUEST_TYPE_GETSIZE, "pkgtool", - pkgid, buf)) { + if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_GETSIZE, + "pkgtool", pkgid, buf)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); free(reqkey); @@ -894,7 +899,7 @@ static int __handle_request_getsize(uid_t uid, return 0; } -static int __handle_request_cleardata(uid_t uid, +static int __handle_request_cleardata(uid_t caller_uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; @@ -924,8 +929,8 @@ static int __handle_request_cleardata(uid_t uid, return -1; } - if (_push_queue(target_uid, reqkey, REQUEST_TYPE_CLEARDATA, pkgtype, - pkgid, NULL)) { + if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_CLEARDATA, + pkgtype, pkgid, NULL)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); free(reqkey); @@ -942,7 +947,7 @@ static int __handle_request_cleardata(uid_t uid, return 0; } -static int __handle_request_clearcache(uid_t uid, +static int __handle_request_clearcache(uid_t caller_uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; @@ -955,7 +960,7 @@ static int __handle_request_clearcache(uid_t uid, return -1; } - if (_push_queue(target_uid, NULL, REQUEST_TYPE_CLEARCACHE, + if (_push_queue(target_uid, caller_uid, NULL, REQUEST_TYPE_CLEARCACHE, "pkgtool", pkgid, NULL)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); @@ -968,7 +973,7 @@ static int __handle_request_clearcache(uid_t uid, return 0; } -static int __handle_request_kill(uid_t uid, +static int __handle_request_kill(uid_t caller_uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; @@ -989,7 +994,7 @@ static int __handle_request_kill(uid_t uid, return -1; } - if (_push_queue(target_uid, reqkey, REQUEST_TYPE_KILL, + if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_KILL, "default", pkgid, NULL)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(ii)", PKGMGR_R_ESYSTEM, 0)); @@ -1004,7 +1009,7 @@ static int __handle_request_kill(uid_t uid, return 0; } -static int __handle_request_check(uid_t uid, +static int __handle_request_check(uid_t caller_uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; @@ -1025,7 +1030,7 @@ static int __handle_request_check(uid_t uid, return -1; } - if (_push_queue(target_uid, reqkey, REQUEST_TYPE_CHECK, + if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_CHECK, "default", pkgid, NULL)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(ii)", PKGMGR_R_ESYSTEM, 0)); @@ -1040,7 +1045,7 @@ static int __handle_request_check(uid_t uid, return 0; } -static int __handle_request_generate_license_request(uid_t uid, +static int __handle_request_generate_license_request(uid_t caller_uid, GDBusMethodInvocation *invocation, GVariant *parameters) { char *reqkey; @@ -1061,7 +1066,7 @@ static int __handle_request_generate_license_request(uid_t uid, return -1; } - if (_push_queue(uid, reqkey, + if (_push_queue(caller_uid, caller_uid, reqkey, REQUEST_TYPE_GENERATE_LICENSE_REQUEST, "default", NULL, resp_data)) { g_dbus_method_invocation_return_value(invocation, @@ -1078,7 +1083,7 @@ static int __handle_request_generate_license_request(uid_t uid, return 0; } -static int __handle_request_register_license(uid_t uid, +static int __handle_request_register_license(uid_t caller_uid, GDBusMethodInvocation *invocation, GVariant *parameters) { char *reqkey; @@ -1098,7 +1103,8 @@ static int __handle_request_register_license(uid_t uid, return -1; } - if (_push_queue(uid, reqkey, REQUEST_TYPE_REGISTER_LICENSE, + if (_push_queue(caller_uid, caller_uid, reqkey, + REQUEST_TYPE_REGISTER_LICENSE, "default", NULL, resp_data)) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", PKGMGR_R_ESYSTEM)); @@ -1113,7 +1119,7 @@ static int __handle_request_register_license(uid_t uid, return 0; } -static int __handle_request_decrypt_package(uid_t uid, +static int __handle_request_decrypt_package(uid_t caller_uid, GDBusMethodInvocation *invocation, GVariant *parameters) { char *reqkey; @@ -1135,7 +1141,8 @@ static int __handle_request_decrypt_package(uid_t uid, return -1; } - if (_push_queue(uid, reqkey, REQUEST_TYPE_DECRYPT_PACKAGE, + if (_push_queue(caller_uid, caller_uid, reqkey, + REQUEST_TYPE_DECRYPT_PACKAGE, "default", drm_file_path, decrypted_file_path)) { g_dbus_method_invocation_return_value(invocation, @@ -1151,7 +1158,7 @@ static int __handle_request_decrypt_package(uid_t uid, return 0; } -static int __update_app_splash_screen(uid_t uid, +static int __update_app_splash_screen(uid_t caller_uid, GDBusMethodInvocation *invocation, GVariant *parameters, int req_type) { @@ -1175,7 +1182,7 @@ static int __update_app_splash_screen(uid_t uid, return -1; } - if (_push_queue(target_uid, reqkey, req_type, "default", + if (_push_queue(target_uid, caller_uid, reqkey, req_type, "default", appid, NULL)) { ERR("Failed to push request"); g_dbus_method_invocation_return_value(invocation, @@ -1193,21 +1200,21 @@ static int __update_app_splash_screen(uid_t uid, return 0; } -static int __handle_request_enable_app_splash_screen(uid_t uid, +static int __handle_request_enable_app_splash_screen(uid_t caller_uid, GDBusMethodInvocation *invocation, GVariant *parameters) { - return __update_app_splash_screen(uid, invocation, parameters, + return __update_app_splash_screen(caller_uid, invocation, parameters, REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN); } -static int __handle_request_disable_app_splash_screen(uid_t uid, +static int __handle_request_disable_app_splash_screen(uid_t caller_uid, GDBusMethodInvocation *invocation, GVariant *parameters) { - return __update_app_splash_screen(uid, invocation, parameters, + return __update_app_splash_screen(caller_uid, invocation, parameters, REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN); } -static int __handle_request_set_restriction_mode(uid_t uid, +static int __handle_request_set_restriction_mode(uid_t caller_uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; @@ -1231,7 +1238,7 @@ static int __handle_request_set_restriction_mode(uid_t uid, } snprintf(buf, sizeof(buf), "%d", mode); - if (_push_queue(target_uid, reqkey, + if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_SET_RESTRICTION_MODE, "default", pkgid, buf)) { g_dbus_method_invocation_return_value(invocation, @@ -1247,7 +1254,7 @@ static int __handle_request_set_restriction_mode(uid_t uid, return 0; } -static int __handle_request_unset_restriction_mode(uid_t uid, +static int __handle_request_unset_restriction_mode(uid_t caller_uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; @@ -1271,7 +1278,7 @@ static int __handle_request_unset_restriction_mode(uid_t uid, } snprintf(buf, sizeof(buf), "%d", mode); - if (_push_queue(target_uid, reqkey, + if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_UNSET_RESTRICTION_MODE, "default", pkgid, buf)) { g_dbus_method_invocation_return_value(invocation, @@ -1287,7 +1294,7 @@ static int __handle_request_unset_restriction_mode(uid_t uid, return 0; } -static int __handle_request_get_restriction_mode(uid_t uid, +static int __handle_request_get_restriction_mode(uid_t caller_uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; @@ -1308,7 +1315,7 @@ static int __handle_request_get_restriction_mode(uid_t uid, return -1; } - if (_push_queue(target_uid, reqkey, + if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_GET_RESTRICTION_MODE, "default", pkgid, NULL)) { g_dbus_method_invocation_return_value(invocation, diff --git a/src/signal.c b/src/signal.c index f6ad233..b7891aa 100644 --- a/src/signal.c +++ b/src/signal.c @@ -153,7 +153,7 @@ void _send_fail_signal(struct backend_job *job) pkgmgr_installer_set_request_type(pi, req_type); pkgmgr_installer_send_signal(pi, job->backend_type, job->pkgid, "end", "fail"); - n = __get_uid_list(job->uid, &uids); + n = __get_uid_list(job->target_uid, &uids); for (i = 0; i < n; i++) pkgmgr_installer_send_signal_for_uid(pi, uids[i], job->backend_type, job->pkgid, "end", "fail"); -- 2.7.4 From 7023f9ad7258759c11ff66d03515058f56355374 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Tue, 29 Nov 2016 10:37:00 +0900 Subject: [PATCH 09/16] Using different pkgmgr-info API while getting pkgtype - Change API which is used while retrieving pkginfo to retrieve disabled and external-installed pkg properly (externally installed pkg but external storage has removed) Change-Id: I374ccc1c7e73734729aafcdf68a7c38a3d06ffb4 Signed-off-by: Junghyun Yeon --- src/pkgmgr-server.c | 23 +++++++---------------- src/util.c | 10 +++------- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index e4c312f..268a1ad 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -572,24 +572,15 @@ static int __change_job_info(struct backend_job *job, uid_t uid, int ret = 0; char *pkgid = NULL; pkgmgrinfo_appinfo_h handle = NULL; - - switch (job->req_type) { - case REQUEST_TYPE_DISABLE_APP: - case REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID: - case REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN: - case REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN: - ret = pkgmgrinfo_appinfo_get_usr_appinfo(job->pkgid, uid, - &handle); - break; - case REQUEST_TYPE_ENABLE_APP: - case REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID: - ret = pkgmgrinfo_appinfo_get_usr_disabled_appinfo(job->pkgid, - uid, &handle); - break; - default: + if (job->req_type != REQUEST_TYPE_DISABLE_APP && + job->req_type != REQUEST_TYPE_DISABLE_GLOBAL_APP_FOR_UID && + job->req_type != REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN && + job->req_type != REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN && + job->req_type != REQUEST_TYPE_ENABLE_APP && + job->req_type != REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID) return PMINFO_R_ERROR; - } + ret = pkgmgrinfo_appinfo_get_usr_all_appinfo(job->pkgid, uid, &handle); if (ret != PMINFO_R_OK) return PMINFO_R_ERROR; diff --git a/src/util.c b/src/util.c index 6b683fd..6a1b7b9 100644 --- a/src/util.c +++ b/src/util.c @@ -51,13 +51,9 @@ char *_get_pkgtype_from_pkgid(const char *pkgid, uid_t uid) pkgmgrinfo_pkginfo_h info; int ret; - ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &info); - if (ret != PMINFO_R_OK) { - ret = pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(pkgid, uid, - &info); - if (ret != PMINFO_R_OK) - return NULL; - } + ret = pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkgid, uid, &info); + if (ret != PMINFO_R_OK) + return NULL; ret = pkgmgrinfo_pkginfo_get_type(info, &pkgtype); if (ret != PMINFO_R_OK) { -- 2.7.4 From 09f70f3b89ec8f42249f5fc66f813fec52c3011f Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Mon, 28 Nov 2016 21:02:27 +0900 Subject: [PATCH 10/16] Add request type and codes for set app label Related changes: [slp-pkgmgr] : https://review.tizen.org/gerrit/100579 Change-Id: Ib2b395db143d6230817884c922e09c37f7289b38 Signed-off-by: Junghyun Yeon --- include/pkgmgr-server.h | 1 + src/pkgmgr-server.c | 15 +++++++++++++++ src/request.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/include/pkgmgr-server.h b/include/pkgmgr-server.h index 895c9bd..210a8a4 100644 --- a/include/pkgmgr-server.h +++ b/include/pkgmgr-server.h @@ -77,6 +77,7 @@ enum request_type { REQUEST_TYPE_SET_RESTRICTION_MODE, REQUEST_TYPE_UNSET_RESTRICTION_MODE, REQUEST_TYPE_GET_RESTRICTION_MODE, + REQUEST_TYPE_SET_APP_LABEL, }; gboolean queue_job(void *data); diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index e4c312f..04a80ca 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -1260,6 +1260,18 @@ static int __process_get_restriction_mode(struct backend_job *job) return ret; } +static int __process_set_app_label(struct backend_job *job) +{ + int ret; + int mode = -1; + + ret = pkgmgr_parser_update_app_label_info_in_usr_db(job->pkgid, job->appid, + job->args); + _return_value_to_caller(job->req_id, g_variant_new("(i)", ret)); + + return ret; +} + gboolean queue_job(void *data) { struct backend_job *job = NULL; @@ -1416,6 +1428,9 @@ gboolean queue_job(void *data) ret = __process_get_restriction_mode(job); _free_backend_job(job); break; + case REQUEST_TYPE_SET_APP_LABEL: + ret = __process_set_app_label(job); + _free_backend_job(job); default: ret = -1; break; diff --git a/src/request.c b/src/request.c index 3269b24..1213bc9 100644 --- a/src/request.c +++ b/src/request.c @@ -160,6 +160,12 @@ static const char instropection_xml[] = " " " " " " + " " + " " + " " + " " + " " + " " " " ""; static GDBusNodeInfo *instropection_data; @@ -1331,6 +1337,44 @@ static int __handle_request_get_restriction_mode(uid_t caller_uid, return 0; } +static int __handle_request_set_app_label(uid_t uid, + GDBusMethodInvocation *invocation, GVariant *parameters) +{ + uid_t target_uid = (uid_t)-1; + char *appid = NULL; + char *label = NULL; + char *reqkey; + + g_variant_get(parameters, "(uss)", &target_uid, &appid, &label); + if (target_uid == (uid_t)-1 || appid == NULL || label == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(i)", PKGMGR_R_ECOMM)); + return -1; + } + + reqkey = __generate_reqkey("appid"); + if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(i)", PKGMGR_R_ENOMEM)); + return -1; + } + + if (_push_queue(target_uid, reqkey, + REQUEST_TYPE_SET_APP_LABEL, + "default", appid, label)) { + 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 uid_t __get_caller_uid(GDBusConnection *connection, const char *name) { GError *err = NULL; @@ -1429,6 +1473,8 @@ static void __handle_method_call(GDBusConnection *connection, else if (g_strcmp0(method_name, "get_restriction_mode") == 0) ret = __handle_request_get_restriction_mode(uid, invocation, parameters); + else if (g_strcmp0(method_name, "set_app_label") == 0) + ret = __handle_request_set_app_label(uid, invocation, parameters); else ret = -1; -- 2.7.4 From 75bd111f9ba3e4ce635cb788187cbc5dfd2a85c5 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 30 Nov 2016 20:21:25 +0900 Subject: [PATCH 11/16] Fix build break Change-Id: Ifb16e6f37fd5192bca08a5fb2c84d505b91a025b Signed-off-by: Hwankyu Jhun --- src/pkgmgr-server.c | 5 ++--- src/request.c | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index fbe5424..a82f2fd 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -1254,10 +1254,9 @@ static int __process_get_restriction_mode(struct backend_job *job) static int __process_set_app_label(struct backend_job *job) { int ret; - int mode = -1; - ret = pkgmgr_parser_update_app_label_info_in_usr_db(job->pkgid, job->appid, - job->args); + ret = pkgmgr_parser_update_app_label_info_in_usr_db(job->appid, + job->target_uid, job->args); _return_value_to_caller(job->req_id, g_variant_new("(i)", ret)); return ret; diff --git a/src/request.c b/src/request.c index 1213bc9..d8e034a 100644 --- a/src/request.c +++ b/src/request.c @@ -1359,7 +1359,7 @@ static int __handle_request_set_app_label(uid_t uid, return -1; } - if (_push_queue(target_uid, reqkey, + if (_push_queue(target_uid, uid, reqkey, REQUEST_TYPE_SET_APP_LABEL, "default", appid, label)) { g_dbus_method_invocation_return_value(invocation, -- 2.7.4 From 549eb42c5cae8b7ce12787da961cd8100a0ffa9f Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Fri, 2 Dec 2016 22:02:40 +0900 Subject: [PATCH 12/16] if it's failed to get the pkgtype from the file, use the pkgtype argument. Change-Id: I8deaf21a552e94007e5a1c7b9341dcb69ccfe0d5 Signed-off-by: jongmyeongko --- src/request.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/request.c b/src/request.c index d8e034a..f7c10fb 100644 --- a/src/request.c +++ b/src/request.c @@ -21,6 +21,7 @@ static const char instropection_xml[] = " " " " " " + " " " " " " " " @@ -34,6 +35,7 @@ static const char instropection_xml[] = " " " " " " + " " " " " " " " @@ -278,6 +280,7 @@ static int __handle_request_install(uid_t caller_uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; + char *arg_pkgtype = NULL; const char *pkgtype; char *pkgpath = NULL; char *args = NULL; @@ -289,7 +292,8 @@ static int __handle_request_install(uid_t caller_uid, int i = 0; int len = 0; - g_variant_get(parameters, "(u&s@as)", &target_uid, &pkgpath, &value); + g_variant_get(parameters, "(u&s&s@as)", &target_uid, &arg_pkgtype, + &pkgpath, &value); tmp_args = (gchar **)g_variant_get_strv(value, &args_count); for (i = 0; i < args_count; i++) @@ -318,6 +322,8 @@ static int __handle_request_install(uid_t caller_uid, } pkgtype = _get_pkgtype_from_file(pkgpath); + if (!pkgtype && arg_pkgtype) + pkgtype = (const char *)arg_pkgtype; if (pkgtype == NULL) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ECOMM, "")); @@ -363,6 +369,7 @@ static int __handle_request_mount_install(uid_t caller_uid, GDBusMethodInvocation *invocation, GVariant *parameters) { uid_t target_uid = (uid_t)-1; + char *arg_pkgtype = NULL; const char *pkgtype; char *pkgpath = NULL; char *args = NULL; @@ -374,7 +381,8 @@ static int __handle_request_mount_install(uid_t caller_uid, int i = 0; int len = 0; - g_variant_get(parameters, "(u&s@as)", &target_uid, &pkgpath, &value); + g_variant_get(parameters, "(u&s&s@as)", &target_uid, &arg_pkgtype, + &pkgpath, &value); tmp_args = (gchar **)g_variant_get_strv(value, &args_count); for (i = 0; i < args_count; i++) @@ -403,6 +411,8 @@ static int __handle_request_mount_install(uid_t caller_uid, } pkgtype = _get_pkgtype_from_file(pkgpath); + if (!pkgtype && arg_pkgtype) + pkgtype = (const char *)arg_pkgtype; if (pkgtype == NULL) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", PKGMGR_R_ECOMM, "")); -- 2.7.4 From a498ba2cafb512cb9ff60fa62209c6e3f1e27150 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Wed, 7 Dec 2016 13:56:55 +0900 Subject: [PATCH 13/16] Fix unintended switch-case operation Change-Id: I463eeb18ea67e589b609d4d09e68dee81964aed6 Signed-off-by: Junghyun Yeon --- src/pkgmgr-server.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index a82f2fd..b3242ed 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -1421,6 +1421,7 @@ gboolean queue_job(void *data) case REQUEST_TYPE_SET_APP_LABEL: ret = __process_set_app_label(job); _free_backend_job(job); + break; default: ret = -1; break; -- 2.7.4 From d017fb753c147bddde26c874aa56b29c1d58ea5f Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Thu, 8 Dec 2016 17:26:01 +0900 Subject: [PATCH 14/16] Fix getting pkgtype from request Change-Id: I9d85af7f9da1f5c7615ee1d3c403054dc673e8d6 Signed-off-by: Sangyoon Jang --- src/request.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/request.c b/src/request.c index f7c10fb..7fb6e20 100644 --- a/src/request.c +++ b/src/request.c @@ -322,7 +322,7 @@ static int __handle_request_install(uid_t caller_uid, } pkgtype = _get_pkgtype_from_file(pkgpath); - if (!pkgtype && arg_pkgtype) + if (!pkgtype && arg_pkgtype && strlen(arg_pkgtype)) pkgtype = (const char *)arg_pkgtype; if (pkgtype == NULL) { g_dbus_method_invocation_return_value(invocation, @@ -411,7 +411,7 @@ static int __handle_request_mount_install(uid_t caller_uid, } pkgtype = _get_pkgtype_from_file(pkgpath); - if (!pkgtype && arg_pkgtype) + if (!pkgtype && arg_pkgtype && strlen(arg_pkgtype)) pkgtype = (const char *)arg_pkgtype; if (pkgtype == NULL) { g_dbus_method_invocation_return_value(invocation, -- 2.7.4 From ab806950b0e1b738863038b5ed90be323f8e4230 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Fri, 9 Dec 2016 01:38:16 +0900 Subject: [PATCH 15/16] consideration about legacy media path. if caller uid is regular user, then check and convert legacy path. Change-Id: I22d4ead49a6b599b08a2cdea6f6b590fe6319b97 Signed-off-by: jongmyeongko --- include/pkgmgr-server.h | 4 +++- src/request.c | 5 ++--- src/util.c | 17 ++++++++++++++++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/include/pkgmgr-server.h b/include/pkgmgr-server.h index 210a8a4..530ca0d 100644 --- a/include/pkgmgr-server.h +++ b/include/pkgmgr-server.h @@ -52,6 +52,8 @@ #define MAX_PKG_ARGS_LEN 4096 #define DESKTOP_FILE_DIRS_NUM 1024 +#define REGULAR_USER 5000 + enum request_type { REQUEST_TYPE_INSTALL, REQUEST_TYPE_MOUNT_INSTALL, @@ -91,7 +93,7 @@ void _send_fail_signal(struct backend_job *job); int _set_restriction_mode(uid_t uid, const char *pkgid, int mode); int _unset_restriction_mode(uid_t uid, const char *pkgid, int mode); int _get_restriction_mode(uid_t uid, const char *pkgid, int *mode); -const char *_get_pkgtype_from_file(const char *file_path); +const char *_get_pkgtype_from_file(const char *file_path, uid_t uid); char *_get_pkgtype_from_pkgid(const char *pkgid, uid_t uid); #endif/* _PKGMGR_SERVER_H_ */ diff --git a/src/request.c b/src/request.c index 7fb6e20..c03f602 100644 --- a/src/request.c +++ b/src/request.c @@ -235,7 +235,6 @@ 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) { @@ -321,7 +320,7 @@ static int __handle_request_install(uid_t caller_uid, goto catch; } - pkgtype = _get_pkgtype_from_file(pkgpath); + pkgtype = _get_pkgtype_from_file(pkgpath, caller_uid); if (!pkgtype && arg_pkgtype && strlen(arg_pkgtype)) pkgtype = (const char *)arg_pkgtype; if (pkgtype == NULL) { @@ -410,7 +409,7 @@ static int __handle_request_mount_install(uid_t caller_uid, goto catch; } - pkgtype = _get_pkgtype_from_file(pkgpath); + pkgtype = _get_pkgtype_from_file(pkgpath, caller_uid); if (!pkgtype && arg_pkgtype && strlen(arg_pkgtype)) pkgtype = (const char *)arg_pkgtype; if (pkgtype == NULL) { diff --git a/src/util.c b/src/util.c index 6a1b7b9..d64ccb7 100644 --- a/src/util.c +++ b/src/util.c @@ -3,6 +3,7 @@ #include +#include #include #include "pkgmgr-server.h" @@ -19,12 +20,26 @@ struct manifest_and_type type_map[] = { { NULL, NULL } }; -const char *_get_pkgtype_from_file(const char *file_path) +static const char legacy_content_path[] = "/opt/usr/media"; + +const char *_get_pkgtype_from_file(const char *org_file_path, uid_t caller_uid) { const char *type = NULL; + const char *file_path = NULL; unzFile uf; int i; + if (caller_uid >= REGULAR_USER && + strstr(org_file_path, legacy_content_path) == org_file_path) { + DBG("legacy media path!"); + tzplatform_set_user(caller_uid); + file_path = tzplatform_mkpath(TZ_USER_CONTENT, + org_file_path + strlen(legacy_content_path)); + tzplatform_reset_user(); + } else { + file_path = org_file_path; + } + uf = unzOpen(file_path); if (uf == NULL) { ERR("failed to open zip file %s", file_path); -- 2.7.4 From 504e4f1a18b60992a73f4fb9a349ec63a4a7b8f2 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Mon, 12 Dec 2016 14:52:40 +0900 Subject: [PATCH 16/16] Return no such pkg error when failed to get pkgtype Change-Id: I33265d0a30cd4162551d1cff3489797ce933fe05 Signed-off-by: Junghyun Yeon --- src/request.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/request.c b/src/request.c index c03f602..4db0f6d 100644 --- a/src/request.c +++ b/src/request.c @@ -471,7 +471,7 @@ static int __handle_request_reinstall(uid_t caller_uid, pkgtype = _get_pkgtype_from_pkgid(pkgid, target_uid); if (pkgtype == NULL) { g_dbus_method_invocation_return_value(invocation, - g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); + g_variant_new("(is)", PKGMGR_R_ENOPKG, "")); return -1; } @@ -517,7 +517,7 @@ static int __handle_request_uninstall(uid_t caller_uid, pkgtype = _get_pkgtype_from_pkgid(pkgid, target_uid); if (pkgtype == NULL) { g_dbus_method_invocation_return_value(invocation, - g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); + g_variant_new("(is)", PKGMGR_R_ENOPKG, "")); return -1; } @@ -565,7 +565,7 @@ static int __handle_request_move(uid_t caller_uid, pkgtype = _get_pkgtype_from_pkgid(pkgid, target_uid); if (pkgtype == NULL) { g_dbus_method_invocation_return_value(invocation, - g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); + g_variant_new("(is)", PKGMGR_R_ENOPKG, "")); return -1; } @@ -623,7 +623,7 @@ static int __handle_request_enable_pkgs(uid_t caller_uid, if (pkgtype == NULL) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", - PKGMGR_R_ESYSTEM, "")); + PKGMGR_R_ENOPKG, "")); free(reqkey); return -1; } @@ -675,7 +675,7 @@ static int __handle_request_disable_pkgs(uid_t caller_uid, if (pkgtype == NULL) { g_dbus_method_invocation_return_value(invocation, g_variant_new("(is)", - PKGMGR_R_ESYSTEM, "")); + PKGMGR_R_ENOPKG, "")); free(reqkey); return -1; } @@ -932,7 +932,7 @@ static int __handle_request_cleardata(uid_t caller_uid, pkgtype = _get_pkgtype_from_pkgid(pkgid, target_uid); if (pkgtype == NULL) { g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ESYSTEM)); + g_variant_new("(i)", PKGMGR_R_ENOPKG)); return -1; } -- 2.7.4