From a1efb52511e05e0c27d5cd716dc6d93b4507e0e1 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Thu, 24 Nov 2016 20:54:36 +0900 Subject: [PATCH] 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