From 549eb42c5cae8b7ce12787da961cd8100a0ffa9f Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Fri, 2 Dec 2016 22:02:40 +0900 Subject: [PATCH 01/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 02/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 03/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 04/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 05/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 From 4b04084aa72777d0cb8e6c41e67e0ea4d6e8262a Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Tue, 20 Dec 2016 11:42:53 +0900 Subject: [PATCH 06/16] Fix bug while handling change app label request Change-Id: Ia45ada0e6ed5a23ec7c45691b3ee864b715785dd Signed-off-by: Junghyun Yeon --- src/pkgmgr-server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index b3242ed..b7cf244 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -1255,7 +1255,7 @@ static int __process_set_app_label(struct backend_job *job) { int ret; - ret = pkgmgr_parser_update_app_label_info_in_usr_db(job->appid, + ret = pkgmgr_parser_update_app_label_info_in_usr_db(job->pkgid, job->target_uid, job->args); _return_value_to_caller(job->req_id, g_variant_new("(i)", ret)); -- 2.7.4 From 3f56536b54fa1282599a8110748a2eb829b80c58 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Thu, 15 Dec 2016 16:02:13 +0900 Subject: [PATCH 07/16] execute backend with different argument based on pkg's basic status - Change argument on pkg's status, RO/RW or Global/User pkg Change-Id: Ib15cbf9e8736598883ab2760bda980f10d4b8669 Signed-off-by: Junghyun Yeon --- src/pkgmgr-server.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++----- src/signal.c | 6 ++++ 2 files changed, 94 insertions(+), 9 deletions(-) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index b7cf244..c3d33d1 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -731,19 +731,52 @@ static int __process_enable_pkg(struct backend_job *job) char *backend_cmd; char **argv; char args[MAX_PKG_ARGS_LEN]; + pkgmgrinfo_pkginfo_h pkginfo_h; + bool is_readonly; + bool is_global; + int ret; int pid; backend_cmd = job->backend_path; if (backend_cmd == NULL) return -1; - snprintf(args, sizeof(args), "%s -k %s -u %d -A %s", backend_cmd, - job->req_id, (int)job->target_uid, job->pkgid); - argv = __generate_argv(args); + ret = pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo( + job->pkgid, job->target_uid, &pkginfo_h); + if (ret != PMINFO_R_OK) { + ERR("Failed to get appinfo"); + return -1; + } + + ret = pkgmgrinfo_pkginfo_is_global(pkginfo_h, &is_global); + if (ret != PMINFO_R_OK) { + ERR("Failed to get global value"); + pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo_h); + return -1; + } + + if ((is_global && job->target_uid != GLOBAL_USER) || + (!is_global && job->target_uid == GLOBAL_USER)) { + ERR("Invalid attempt to enable pkg"); + pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo_h); + return -1; + } + ret = pkgmgrinfo_pkginfo_is_readonly(pkginfo_h, &is_readonly); + if (ret != PMINFO_R_OK) { + ERR("Failed to get readonly value"); + pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo_h); + return -1; + } + + snprintf(args, sizeof(args), "%s -k %s -u %d -A %s %s", + backend_cmd, job->req_id, (int)job->target_uid, + job->pkgid, (is_readonly) ? "--preload" : ""); + argv = __generate_argv(args); pid = __fork_and_exec_with_args(argv, APPFW_UID); g_strfreev(argv); + pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo_h); return pid; } @@ -753,20 +786,54 @@ static int __process_disable_pkg(struct backend_job *job) char *backend_cmd; char **argv; char args[MAX_PKG_ARGS_LEN]; + pkgmgrinfo_pkginfo_h pkginfo_h; + bool is_readonly; + bool is_global; + int ret; int pid; backend_cmd = job->backend_path; if (backend_cmd == NULL) return -1; - snprintf(args, sizeof(args), "%s -k %s -u %d -D %s", backend_cmd, - job->req_id, (int)job->target_uid, job->pkgid); + ret = pkgmgrinfo_pkginfo_get_usr_pkginfo( + job->pkgid, job->target_uid, &pkginfo_h); + if (ret != PMINFO_R_OK) { + ERR("Failed to get appinfo"); + return -1; + } + + ret = pkgmgrinfo_pkginfo_is_global(pkginfo_h, &is_global); + if (ret != PMINFO_R_OK) { + ERR("Failed to get global value"); + pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo_h); + return -1; + } + + if ((is_global && job->target_uid != GLOBAL_USER) || + (!is_global && job->target_uid == GLOBAL_USER)) { + ERR("Invalid attempt to disable pkg"); + pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo_h); + return -1; + } + + ret = pkgmgrinfo_pkginfo_is_readonly(pkginfo_h, &is_readonly); + if (ret != PMINFO_R_OK) { + ERR("Failed to get readonly value"); + pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo_h); + return -1; + } + + snprintf(args, sizeof(args), "%s -k %s -u %d -D %s %s", + backend_cmd, job->req_id, (int)job->target_uid, + job->pkgid, (is_readonly) ? "--preload" : ""); argv = __generate_argv(args); pid = __fork_and_exec_with_args(argv, APPFW_UID); g_strfreev(argv); + pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo_h); return pid; } @@ -1335,14 +1402,26 @@ gboolean queue_job(void *data) case REQUEST_TYPE_ENABLE_PKG: __set_backend_busy(x); ret = __process_enable_pkg(job); - g_hash_table_insert(backend_info_table, (gpointer)ret, - (gpointer)job); + if (ret == -1) { + _send_fail_signal(job); + __set_backend_free(x); + _free_backend_job(job); + } else { + g_hash_table_insert(backend_info_table, (gpointer)ret, + (gpointer)job); + } break; case REQUEST_TYPE_DISABLE_PKG: __set_backend_busy(x); ret = __process_disable_pkg(job); - g_hash_table_insert(backend_info_table, (gpointer)ret, - (gpointer)job); + if (ret == -1) { + _send_fail_signal(job); + __set_backend_free(x); + _free_backend_job(job); + } else { + g_hash_table_insert(backend_info_table, (gpointer)ret, + (gpointer)job); + } break; case REQUEST_TYPE_ENABLE_APP: ret = __process_enable_app(job); diff --git a/src/signal.c b/src/signal.c index b7891aa..c1efa8c 100644 --- a/src/signal.c +++ b/src/signal.c @@ -146,6 +146,12 @@ void _send_fail_signal(struct backend_job *job) case REQUEST_TYPE_GETSIZE: req_type = PKGMGR_REQ_GETSIZE; break; + case REQUEST_TYPE_DISABLE_PKG: + req_type = PKGMGR_REQ_DISABLE_PKG; + break; + case REQUEST_TYPE_ENABLE_PKG: + req_type = PKGMGR_REQ_ENABLE_PKG; + break; default: req_type = PKGMGR_REQ_INVALID; break; -- 2.7.4 From 1177e23a32736ff1bd302475778eb663ddd760fa Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Wed, 21 Dec 2016 15:37:25 +0900 Subject: [PATCH 08/16] Enable disable/enable function of global apps - For now, disable/enabling of global apps are prohibited. Remove some codes to enable it Change-Id: I2dd4c7873ce3432e0c3e10c5df18a1cab96a1d6e Signed-off-by: Junghyun Yeon --- src/pkgmgr-server.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index c3d33d1..098b65c 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -588,14 +588,9 @@ static int __change_job_info(struct backend_job *job, uid_t uid, if (ret != PMINFO_R_OK) 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) && + 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; -- 2.7.4 From 882d44fdc021c34c7f38e66ac2f9c311cf285128 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Mon, 19 Dec 2016 23:10:32 +0900 Subject: [PATCH 09/16] refactor getsize sync function Submit with: https://review.tizen.org/gerrit/#/c/105817/ https://review.tizen.org/gerrit/#/c/105823/ https://review.tizen.org/gerrit/#/c/105825/ Change-Id: I2b5a17199324a1f0ee6a2bac0f5adf8d077283f8 Signed-off-by: jongmyeongko --- include/pkgmgr-server.h | 1 + include/queue.h | 8 ++ org.tizen.pkgmgr.conf | 1 + src/pkgmgr-server.c | 193 +++++++++++++++++++++++++++++++++++++++--------- src/queue.c | 17 +++++ src/request.c | 48 ++++++++++++ 6 files changed, 235 insertions(+), 33 deletions(-) diff --git a/include/pkgmgr-server.h b/include/pkgmgr-server.h index 530ca0d..e22bfeb 100644 --- a/include/pkgmgr-server.h +++ b/include/pkgmgr-server.h @@ -65,6 +65,7 @@ enum request_type { REQUEST_TYPE_ENABLE_APP, REQUEST_TYPE_DISABLE_APP, REQUEST_TYPE_GETSIZE, + REQUEST_TYPE_GETSIZE_SYNC, REQUEST_TYPE_CLEARDATA, REQUEST_TYPE_CLEARCACHE, REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID, diff --git a/include/queue.h b/include/queue.h index 27fd907..d89d78c 100644 --- a/include/queue.h +++ b/include/queue.h @@ -20,6 +20,12 @@ #include +struct job_extra_info { + int getsize_fd; + char *getsize_fifo; + GIOChannel *getsize_io; +}; + struct backend_job { uid_t target_uid; uid_t caller_uid; @@ -31,6 +37,7 @@ struct backend_job { int backend_slot; char *backend_type; char *backend_path; + struct job_extra_info *extra; }; int _is_queue_empty(int pos); @@ -41,5 +48,6 @@ 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); +void __free_extra_info(struct backend_job *job); #endif // _QUEUE_H_ diff --git a/org.tizen.pkgmgr.conf b/org.tizen.pkgmgr.conf index e94bf6c..7ad7a4b 100644 --- a/org.tizen.pkgmgr.conf +++ b/org.tizen.pkgmgr.conf @@ -25,6 +25,7 @@ + diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index c3d33d1..d390f90 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -59,6 +60,7 @@ #define EXT_STORAGE_APPDATA_GROUP 10002 #define MEDIA_STORAGE_GROUP 10502 #define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0])) +#define MAX_LONGLONG_LENGTH 32 typedef struct { char **env; @@ -89,7 +91,7 @@ static int pipe_sig[2]; static GIOChannel *pipe_io; static guint pipe_wid; static GHashTable *backend_info_table; -static GMainLoop *mainloop = NULL; +static GMainLoop *mainloop; static int __check_backend_status_for_exit(void); static int __check_queue_status_for_exit(void); @@ -116,6 +118,67 @@ static void __set_backend_free(int position) backend_busy = backend_busy & ~(1 << position); } +static gboolean getsize_io_handler(GIOChannel *io, GIOCondition cond, + gpointer data) +{ + GError *err = NULL; + GIOStatus s; + gsize len; + char buf[MAX_LONGLONG_LENGTH]; + long long result = 0; + struct backend_job *job = (struct backend_job *)data; + + s = g_io_channel_read_chars(io, (gchar *)buf, sizeof(buf), &len, &err); + if (s != G_IO_STATUS_NORMAL) { + ERR("getsize fd read failed: %s", err->message); + g_error_free(err); + result = -1; + } else { + if (strlen(buf) == 0) { + ERR("empty result"); + result = -1; + } else { + result = atoll(buf); + } + } + + _return_value_to_caller(job->req_id, g_variant_new("(ix)", + (result < 0) ? PKGMGR_R_ERROR : PKGMGR_R_OK, result)); + + unlink(job->extra->getsize_fifo); + free(job->extra->getsize_fifo); + job->extra->getsize_fifo = NULL; + + return FALSE; +} + +static int __setup_size_info_io(struct backend_job *job) +{ + guint getsize_wid; + + job->extra->getsize_fd = open(job->extra->getsize_fifo, + O_RDONLY | O_NONBLOCK); + if (job->extra->getsize_fd < 0) { + ERR("failed to open the fifo(%s), errno(%d)", + job->extra->getsize_fifo, errno); + return -1; + } + + job->extra->getsize_io = g_io_channel_unix_new(job->extra->getsize_fd); + if (!job->extra->getsize_io) + return -1; + g_io_channel_set_encoding(job->extra->getsize_io, NULL, NULL); + g_io_channel_set_buffered(job->extra->getsize_io, FALSE); + getsize_wid = g_io_add_watch(job->extra->getsize_io, + G_IO_IN, getsize_io_handler, job); + if (!getsize_wid) { + ERR("failed to add io watch"); + return -1; + } + + return 0; +} + static gboolean pipe_io_handler(GIOChannel *io, GIOCondition cond, gpointer data) { @@ -151,6 +214,14 @@ static gboolean pipe_io_handler(GIOChannel *io, GIOCondition cond, DBG("backend[%s] exit", job->backend_type); } + if (job->extra) { + if (job->extra->getsize_fifo) { + ERR("invalid backend close"); + _return_value_to_caller(job->req_id, + g_variant_new("(ix)", PKGMGR_R_ERROR, -1)); + } + } + g_hash_table_remove(backend_info_table, (gconstpointer)info.pid); g_idle_add(queue_job, NULL); @@ -356,7 +427,7 @@ static int __pkgcmd_app_cb(const pkgmgrinfo_appinfo_h handle, void *user_data) return 0; } -void free_user_context(user_ctx* ctx) +void free_user_context(user_ctx *ctx) { char **env = NULL; int i = 0; @@ -542,7 +613,7 @@ void __set_environment(gpointer user_data) static int __fork_and_exec_with_args(char **argv, uid_t uid) { - user_ctx* user_context; + user_ctx *user_context; GError *error = NULL; gboolean ret; int pid; @@ -559,6 +630,8 @@ static int __fork_and_exec_with_args(char **argv, uid_t uid) if (ret != TRUE) { ERR("Failed to excute backend: %s", error->message); g_error_free(error); + free_user_context(user_context); + return -1; } free_user_context(user_context); @@ -1033,6 +1106,59 @@ static int __process_getsize(struct backend_job *job) return pid; } +static int __process_getsize_sync(struct backend_job *job) +{ + static const char backend_cmd[] = "/usr/bin/pkg_getsize"; + char **argv; + char args[MAX_PKG_ARGS_LEN]; + char fifo_path[PATH_MAX]; + int pid; + + snprintf(fifo_path, sizeof(fifo_path), "/tmp/pkgmgr/%s", + job->req_id); + + job->extra = calloc(1, sizeof(struct job_extra_info)); + if (!job->extra) { + ERR("memory alloc failed"); + goto error; + } + + job->extra->getsize_fifo = strdup(fifo_path); + if (!job->extra->getsize_fifo) { + ERR("out of memory"); + goto error; + } + + if (mkfifo(job->extra->getsize_fifo, 0600) < 0) { + ERR("failed to mkfifo"); + goto error; + } + + snprintf(args, sizeof(args), "%s %s %s %d -k %s -u %d --sync", + 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, APPFW_UID); + + g_strfreev(argv); + + if (pid < 0) { + ERR("failed to execute backend"); + goto error; + } + if (__setup_size_info_io(job) < 0) { + ERR("failed to setup io handler"); + goto error; + } + + return pid; + +error: + _return_value_to_caller(job->req_id, + g_variant_new("(ix)", PKGMGR_R_ERROR, -1)); + return -1; +} + static int __process_cleardata(struct backend_job *job) { char *backend_cmd; @@ -1329,6 +1455,18 @@ static int __process_set_app_label(struct backend_job *job) return ret; } +static int __post_process(int ret, int x, struct backend_job *job) +{ + if (ret < 0) { + __set_backend_free(x); + _free_backend_job(job); + } else { + g_hash_table_insert(backend_info_table, (gpointer)ret, + (gpointer)job); + } + return 0; +} + gboolean queue_job(void *data) { struct backend_job *job = NULL; @@ -1372,56 +1510,41 @@ gboolean queue_job(void *data) case REQUEST_TYPE_INSTALL: __set_backend_busy(x); ret = __process_install(job); - g_hash_table_insert(backend_info_table, (gpointer)ret, - (gpointer)job); + __post_process(ret, x, job); break; case REQUEST_TYPE_MOUNT_INSTALL: __set_backend_busy(x); ret = __process_mount_install(job); - g_hash_table_insert(backend_info_table, (gpointer)ret, - (gpointer)job); + __post_process(ret, x, job); break; case REQUEST_TYPE_REINSTALL: __set_backend_busy(x); ret = __process_reinstall(job); - g_hash_table_insert(backend_info_table, (gpointer)ret, - (gpointer)job); + __post_process(ret, x, job); break; case REQUEST_TYPE_UNINSTALL: __set_backend_busy(x); ret = __process_uninstall(job); - g_hash_table_insert(backend_info_table, (gpointer)ret, - (gpointer)job); + __post_process(ret, x, job); break; case REQUEST_TYPE_MOVE: __set_backend_busy(x); ret = __process_move(job); - g_hash_table_insert(backend_info_table, (gpointer)ret, - (gpointer)job); + __post_process(ret, x, job); break; case REQUEST_TYPE_ENABLE_PKG: __set_backend_busy(x); ret = __process_enable_pkg(job); - if (ret == -1) { + if (ret < 0) _send_fail_signal(job); - __set_backend_free(x); - _free_backend_job(job); - } else { - g_hash_table_insert(backend_info_table, (gpointer)ret, - (gpointer)job); - } + __post_process(ret, x, job); break; case REQUEST_TYPE_DISABLE_PKG: __set_backend_busy(x); ret = __process_disable_pkg(job); - if (ret == -1) { + if (ret < 0) _send_fail_signal(job); - __set_backend_free(x); - _free_backend_job(job); - } else { - g_hash_table_insert(backend_info_table, (gpointer)ret, - (gpointer)job); - } + __post_process(ret, x, job); break; case REQUEST_TYPE_ENABLE_APP: ret = __process_enable_app(job); @@ -1434,20 +1557,24 @@ gboolean queue_job(void *data) case REQUEST_TYPE_GETSIZE: __set_backend_busy(x); ret = __process_getsize(job); - g_hash_table_insert(backend_info_table, (gpointer)ret, - (gpointer)job); + __post_process(ret, x, job); + break; + case REQUEST_TYPE_GETSIZE_SYNC: + __set_backend_busy(x); + ret = __process_getsize_sync(job); + if (ret < 0) + __free_extra_info(job); + __post_process(ret, x, 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); + __post_process(ret, x, job); break; case REQUEST_TYPE_CLEARCACHE: __set_backend_busy(x); ret = __process_clearcache(job); - g_hash_table_insert(backend_info_table, (gpointer)ret, - (gpointer)job); + __post_process(ret, x, job); break; case REQUEST_TYPE_ENABLE_GLOBAL_APP_FOR_UID: ret = __process_enable_global_app_for_uid(job); diff --git a/src/queue.c b/src/queue.c index 11e6ace..68b0476 100644 --- a/src/queue.c +++ b/src/queue.c @@ -159,8 +159,25 @@ static gboolean __str_equal(gconstpointer v1, gconstpointer v2) return strcasecmp(str1, str2) == 0; } +void __free_extra_info(struct backend_job *job) +{ + if (job->extra) { + if (job->extra->getsize_io) + g_io_channel_unref(job->extra->getsize_io); + if (job->extra->getsize_fd) + close(job->extra->getsize_fd); + if (job->extra->getsize_fifo) { + unlink(job->extra->getsize_fifo); + free(job->extra->getsize_fifo); + } + free(job->extra); + job->extra = NULL; + } +} + void _free_backend_job(struct backend_job *job) { + __free_extra_info(job); free(job->req_id); free(job->pkgid); free(job->appid); diff --git a/src/request.c b/src/request.c index 4db0f6d..fce8210 100644 --- a/src/request.c +++ b/src/request.c @@ -97,6 +97,13 @@ static const char instropection_xml[] = " " " " " " + " " + " " + " " + " " + " " + " " + " " " " " " " " @@ -914,6 +921,45 @@ static int __handle_request_getsize(uid_t caller_uid, return 0; } +static int __handle_request_getsize_sync(uid_t caller_uid, + GDBusMethodInvocation *invocation, GVariant *parameters) +{ + uid_t target_uid = (uid_t)-1; + char *pkgid = NULL; + int get_type = -1; + char *reqkey; + char buf[4]; + + g_variant_get(parameters, "(u&si)", &target_uid, &pkgid, &get_type); + if (target_uid == (uid_t)-1 || pkgid == NULL || get_type == -1) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ECOMM, "")); + return -1; + } + + reqkey = __generate_reqkey(pkgid); + if (reqkey == NULL) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ENOMEM, "")); + return -1; + } + + snprintf(buf, sizeof(buf), "%d", get_type); + if (_push_queue(target_uid, caller_uid, reqkey, REQUEST_TYPE_GETSIZE_SYNC, + "pkgtool", pkgid, buf)) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); + free(reqkey); + return -1; + } + + if (!g_hash_table_insert(req_table, (gpointer)reqkey, + (gpointer)invocation)) + ERR("reqkey already exists"); + + return 0; +} + static int __handle_request_cleardata(uid_t caller_uid, GDBusMethodInvocation *invocation, GVariant *parameters) { @@ -1442,6 +1488,8 @@ static void __handle_method_call(GDBusConnection *connection, ret = __handle_request_disable_pkgs(uid, invocation, parameters); else if (g_strcmp0(method_name, "getsize") == 0) ret = __handle_request_getsize(uid, invocation, parameters); + else if (g_strcmp0(method_name, "getsize_sync") == 0) + ret = __handle_request_getsize_sync(uid, invocation, parameters); else if (g_strcmp0(method_name, "clearcache") == 0) ret = __handle_request_clearcache(uid, invocation, parameters); else if (g_strcmp0(method_name, "enable_app") == 0) -- 2.7.4 From 74ee94ca22c75fa79c9ec7be630d4b7fb22c02ab Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Thu, 22 Dec 2016 10:26:10 +0900 Subject: [PATCH 10/16] Change bin file to be executed - pkg_clearcache is replced by pkg_cleardata so change code to use it - new pkg_cleardata will handle clear data of pkg Related changes: [pkgmgr-tool] : https://review.tizen.org/gerrit/106485 [app-installers] : https://review.tizen.org/gerrit/105691 [tpk-backend] : https://review.tizen.org/gerrit/106603 [wgt-backend] : https://review.tizen.org/gerrit/106601 Change-Id: Ifa296ecdaf00596261c7e676bbebe6a5b344a386 Signed-off-by: Junghyun Yeon --- src/pkgmgr-server.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index d69728f..dc8e153 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -1156,40 +1156,37 @@ error: static int __process_cleardata(struct backend_job *job) { - char *backend_cmd; + static const char *backend_cmd = "/usr/bin/pkg_cleardata"; char **argv; char args[MAX_PKG_ARGS_LEN]; int pid; - backend_cmd = job->backend_path; - if (backend_cmd == NULL) + if ((int)job->target_uid < REGULAR_USER) return -1; - /* TODO: set movetype */ - snprintf(args, sizeof(args), "%s -k %s -c %s -u %d", backend_cmd, - job->req_id, job->pkgid, (int)job->target_uid); + snprintf(args, sizeof(args), "%s -d %s", backend_cmd, job->pkgid); argv = __generate_argv(args); - - pid = __fork_and_exec_with_args(argv, APPFW_UID); + pid = __fork_and_exec_with_args(argv, job->target_uid); g_strfreev(argv); - return pid; } static int __process_clearcache(struct backend_job *job) { - static const char *backend_cmd = "/usr/bin/pkg_clearcache"; + static const char *backend_cmd = "/usr/bin/pkg_cleardata"; char **argv; char args[MAX_PKG_ARGS_LEN]; int pid; - snprintf(args, sizeof(args), "%s %s", backend_cmd, job->pkgid); + if ((int)job->target_uid < REGULAR_USER) + return -1; + + snprintf(args, sizeof(args), "%s -c %s", backend_cmd, job->pkgid); argv = __generate_argv(args); pid = __fork_and_exec_with_args(argv, job->target_uid); g_strfreev(argv); - return pid; } -- 2.7.4 From 4b6f854383e05addb43658964d07370708de56cb Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Fri, 23 Dec 2016 11:53:22 +0900 Subject: [PATCH 11/16] Pass adjusted file path to backend Submit with: - https://review.tizen.org/gerrit/106774 Change-Id: Iff9755081a5d8031395c031bc684d07d7a288cbc Signed-off-by: Sangyoon Jang --- include/pkgmgr-server.h | 3 ++- src/request.c | 6 ++++-- src/util.c | 32 +++++++++++++++++++------------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/include/pkgmgr-server.h b/include/pkgmgr-server.h index e22bfeb..0180fcb 100644 --- a/include/pkgmgr-server.h +++ b/include/pkgmgr-server.h @@ -94,7 +94,8 @@ 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, uid_t uid); +const char *_get_pkgtype_from_file(const char *file_path); char *_get_pkgtype_from_pkgid(const char *pkgid, uid_t uid); +const char *_get_adjusted_pkgpath(const char *org_file_path, uid_t caller_uid); #endif/* _PKGMGR_SERVER_H_ */ diff --git a/src/request.c b/src/request.c index fce8210..2e4fbc1 100644 --- a/src/request.c +++ b/src/request.c @@ -327,7 +327,8 @@ static int __handle_request_install(uid_t caller_uid, goto catch; } - pkgtype = _get_pkgtype_from_file(pkgpath, caller_uid); + pkgpath = _get_adjusted_pkgpath(pkgpath, caller_uid); + pkgtype = _get_pkgtype_from_file(pkgpath); if (!pkgtype && arg_pkgtype && strlen(arg_pkgtype)) pkgtype = (const char *)arg_pkgtype; if (pkgtype == NULL) { @@ -416,7 +417,8 @@ static int __handle_request_mount_install(uid_t caller_uid, goto catch; } - pkgtype = _get_pkgtype_from_file(pkgpath, caller_uid); + pkgpath = _get_adjusted_pkgpath(pkgpath, caller_uid); + pkgtype = _get_pkgtype_from_file(pkgpath); 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 d64ccb7..97799ac 100644 --- a/src/util.c +++ b/src/util.c @@ -22,24 +22,12 @@ struct manifest_and_type type_map[] = { 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 *_get_pkgtype_from_file(const char *file_path) { 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); @@ -83,3 +71,21 @@ char *_get_pkgtype_from_pkgid(const char *pkgid, uid_t uid) return type; } + +const char *_get_adjusted_pkgpath(const char *org_file_path, uid_t caller_uid) +{ + const char *file_path; + + 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; + } + + return file_path; +} -- 2.7.4 From 3dd6c6b1a9944e8ce90ec3779239280afc5d4843 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Tue, 3 Jan 2017 15:24:29 +0900 Subject: [PATCH 12/16] Fix queue_job When multiple job queued and some job failed, the server cannot process next job because queue_job() never invoked. Return TRUE to continue invoking queue_job() until no job available. Change-Id: I207ced8359ea177233c6d637b94ac6277a0a175c Signed-off-by: Sangyoon Jang --- src/pkgmgr-server.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index dc8e153..47002d1 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -1477,7 +1477,7 @@ gboolean queue_job(void *data) /* all backend messages queue are empty or busy */ if (x == num_of_backends || job == NULL) { - DBG("no job left"); + DBG("no job available"); return FALSE; } @@ -1493,7 +1493,7 @@ gboolean queue_job(void *data) ret = -1; _send_fail_signal(job); _free_backend_job(job); - return FALSE; + return TRUE; } } #endif @@ -1625,7 +1625,7 @@ gboolean queue_job(void *data) break; } - return FALSE; + return TRUE; } int main(int argc, char *argv[]) -- 2.7.4 From 4fa9e329803529328c8a40da87c615c9b24677cd Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Wed, 4 Jan 2017 15:27:20 +0900 Subject: [PATCH 13/16] Adjust to change of pkg_cleardata interface Submit together: - https://review.tizen.org/gerrit/108352 Change-Id: Id20f7c3362a7d12c7f2f565b9533879a8f659174 Signed-off-by: Sangyoon Jang --- src/pkgmgr-server.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index 47002d1..f55c88d 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -1164,9 +1164,10 @@ static int __process_cleardata(struct backend_job *job) if ((int)job->target_uid < REGULAR_USER) return -1; - snprintf(args, sizeof(args), "%s -d %s", backend_cmd, job->pkgid); + snprintf(args, sizeof(args), "%s -d -n %s -u %d", + backend_cmd, job->pkgid, job->target_uid); argv = __generate_argv(args); - pid = __fork_and_exec_with_args(argv, job->target_uid); + pid = __fork_and_exec_with_args(argv, APPFW_UID); g_strfreev(argv); return pid; @@ -1182,9 +1183,10 @@ static int __process_clearcache(struct backend_job *job) if ((int)job->target_uid < REGULAR_USER) return -1; - snprintf(args, sizeof(args), "%s -c %s", backend_cmd, job->pkgid); + snprintf(args, sizeof(args), "%s -c -n %s -u %d", + backend_cmd, job->pkgid, job->target_uid); argv = __generate_argv(args); - pid = __fork_and_exec_with_args(argv, job->target_uid); + pid = __fork_and_exec_with_args(argv, APPFW_UID); g_strfreev(argv); return pid; -- 2.7.4 From 0f239346bc64b1aa61adb0675520019b9b8cd1c4 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Tue, 27 Dec 2016 17:53:08 +0900 Subject: [PATCH 14/16] Change signal type when disabling app for certain user - Server will send disable_app/enable_app when disable/enable global app for certain uid Related changes: [pkgmgr-info] : https://review.tizen.org/gerrit/107069 [pkgmgr-tool] : https://review.tizen.org/gerrit/107098 [slp-pkgmgr] : https://review.tizen.org/gerrit/107263 Change-Id: I9b00ebb7f943740287b123c398b67b573be8c7f7 Signed-off-by: Junghyun Yeon --- src/pkgmgr-server.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index f55c88d..e4653a2 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -1007,7 +1007,7 @@ static int __process_enable_global_app_for_uid(struct backend_job *job) if (ret != PMINFO_R_OK || strlen(job->appid) == 0) { _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, + PKGMGR_INSTALLER_APP_ENABLE_EVENT_STR, job->req_type); _send_app_signal(job->target_uid, job->req_id, job->pkgid, job->pkgid, PKGMGR_INSTALLER_END_KEY_STR, @@ -1018,7 +1018,7 @@ static int __process_enable_global_app_for_uid(struct backend_job *job) _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, + PKGMGR_INSTALLER_APP_ENABLE_EVENT_STR, job->req_type); ret = pkgmgr_parser_update_global_app_disable_for_uid_info_in_db( @@ -1050,7 +1050,7 @@ static int __process_disable_global_app_for_uid(struct backend_job *job) _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, + PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR, job->req_type); _send_app_signal(job->target_uid, job->req_id, job->pkgid, job->pkgid, PKGMGR_INSTALLER_END_KEY_STR, @@ -1062,7 +1062,7 @@ static int __process_disable_global_app_for_uid(struct backend_job *job) _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, + PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR, job->req_type); ret = __kill_app(job->appid, job->target_uid); -- 2.7.4 From 5b010288c2ea73bb4fdb4eb302833e89c0b76650 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Mon, 2 Jan 2017 09:08:52 +0900 Subject: [PATCH 15/16] Fix possible memory leak Change-Id: I63fddbec9b75149b1b65ab9f8ad6993e52bde472 Signed-off-by: Junghyun Yeon --- src/request.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/request.c b/src/request.c index 2e4fbc1..073be8e 100644 --- a/src/request.c +++ b/src/request.c @@ -1450,6 +1450,7 @@ static uid_t __get_caller_uid(GDBusConnection *connection, const char *name) } g_variant_get(result, "(u)", &uid); + g_variant_unref(result); return uid; } -- 2.7.4 From 377140fd7524b797ac330bf833d81245af758e5f Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Thu, 5 Jan 2017 15:34:24 +0900 Subject: [PATCH 16/16] Append null byte when readlink on backend path readlink() does not append a null byte to buf. Change-Id: I28034db705afd0ad1b1a5275f7896a6f9f0c3399 Signed-off-by: Sangyoon Jang --- src/queue.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/queue.c b/src/queue.c index 68b0476..13617ab 100644 --- a/src/queue.c +++ b/src/queue.c @@ -121,6 +121,7 @@ int _push_queue(uid_t target_uid, uid_t caller_uid, const char *req_id, static int __init_backends(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf) { + int r; struct backend_queue *queue; if (typeflag != FTW_F && typeflag != FTW_SL) @@ -131,12 +132,14 @@ static int __init_backends(const char *fpath, const struct stat *sb, 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) { + r = readlink(fpath, queue->path, sb->st_size + 1); + if (r < 0 || r > sb->st_size) { ERR("failed to readlink for %s", fpath); free(queue->path); free(queue); return -1; } + queue->path[r] = '\0'; } queue->type = strdup(fpath + ftwbuf->base); queue->slot = num_of_backends++; -- 2.7.4