From b3063a9f0fee0e431d45b1ce641f7f66e43097f6 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Thu, 24 Nov 2016 19:26:16 +0900 Subject: [PATCH 01/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 02/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 03/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 04/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 05/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 06/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 07/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 08/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 09/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 10/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 11/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 12/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 13/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 14/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 15/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 4b6f854383e05addb43658964d07370708de56cb Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Fri, 23 Dec 2016 11:53:22 +0900 Subject: [PATCH 16/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