Get pkgtype from given pkgid or pkgfile 23/99923/5 accepted/tizen/3.0/common/20161125.101754 accepted/tizen/3.0/ivi/20161125.081932 accepted/tizen/3.0/mobile/20161125.081536 accepted/tizen/3.0/tv/20161125.081743 accepted/tizen/3.0/wearable/20161125.081854 submit/tizen_3.0/20161124.130849
authorSangyoon Jang <s89.jang@samsung.com>
Thu, 24 Nov 2016 11:54:36 +0000 (20:54 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Thu, 24 Nov 2016 12:32:32 +0000 (21:32 +0900)
Submit with:
 - https://review.tizen.org/gerrit/99922
 - https://review.tizen.org/gerrit/99944

Change-Id: I1392aa95b3ec8316255fbcd3d9f285463d3b8c99
Signed-off-by: Sangyoon Jang <s89.jang@samsung.com>
CMakeLists.txt
include/pkgmgr-server.h
packaging/pkgmgr-server.spec
src/request.c
src/util.c [new file with mode: 0644]

index dd3badc..b7bf90d 100644 (file)
@@ -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)
index 288798e..895c9bd 100644 (file)
@@ -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_ */
index 008b254..b27c953 100644 (file)
@@ -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"
index 7a5ba92..4698da9 100644 (file)
@@ -21,7 +21,6 @@ static const char instropection_xml[] =
        "  <interface name='org.tizen.pkgmgr'>"
        "    <method name='install'>"
        "      <arg type='u' name='uid' direction='in'/>"
-       "      <arg type='s' name='pkgtype' direction='in'/>"
        "      <arg type='s' name='pkgpath' direction='in'/>"
        "      <arg type='as' name='args' direction='in'/>"
        "      <arg type='i' name='ret' direction='out'/>"
@@ -29,14 +28,12 @@ static const char instropection_xml[] =
        "    </method>"
        "    <method name='reinstall'>"
        "      <arg type='u' name='uid' direction='in'/>"
-       "      <arg type='s' name='pkgtype' direction='in'/>"
        "      <arg type='s' name='pkgid' direction='in'/>"
        "      <arg type='i' name='ret' direction='out'/>"
        "      <arg type='s' name='reqkey' direction='out'/>"
        "    </method>"
        "    <method name='mount_install'>"
        "      <arg type='u' name='uid' direction='in'/>"
-       "      <arg type='s' name='pkgtype' direction='in'/>"
        "      <arg type='s' name='pkgpath' direction='in'/>"
        "      <arg type='as' name='args' direction='in'/>"
        "      <arg type='i' name='ret' direction='out'/>"
@@ -44,14 +41,12 @@ static const char instropection_xml[] =
        "    </method>"
        "    <method name='uninstall'>"
        "      <arg type='u' name='uid' direction='in'/>"
-       "      <arg type='s' name='pkgtype' direction='in'/>"
        "      <arg type='s' name='pkgid' direction='in'/>"
        "      <arg type='i' name='ret' direction='out'/>"
        "      <arg type='s' name='reqkey' direction='out'/>"
        "    </method>"
        "    <method name='move'>"
        "      <arg type='u' name='uid' direction='in'/>"
-       "      <arg type='s' name='pkgtype' direction='in'/>"
        "      <arg type='s' name='pkgid' direction='in'/>"
        "      <arg type='i' name='movetype' direction='in'/>"
        "      <arg type='i' name='ret' direction='out'/>"
@@ -59,14 +54,12 @@ static const char instropection_xml[] =
        "    </method>"
        "    <method name='enable_pkgs'>"
        "      <arg type='u' name='uid' direction='in'/>"
-       "      <arg type='s' name='pkgtype' direction='in'/>"
        "      <arg type='as' name='pkgids' direction='in'/>"
        "      <arg type='i' name='ret' direction='out'/>"
        "      <arg type='s' name='reqkey' direction='out'/>"
        "    </method>"
        "    <method name='disable_pkgs'>"
        "      <arg type='u' name='uid' direction='in'/>"
-       "      <arg type='s' name='pkgtype' direction='in'/>"
        "      <arg type='as' name='pkgids' direction='in'/>"
        "      <arg type='i' name='ret' direction='out'/>"
        "      <arg type='s' name='reqkey' direction='out'/>"
@@ -104,7 +97,6 @@ static const char instropection_xml[] =
        "    </method>"
        "    <method name='cleardata'>"
        "      <arg type='u' name='uid' direction='in'/>"
-       "      <arg type='s' name='pkgtype' direction='in'/>"
        "      <arg type='s' name='pkgid' direction='in'/>"
        "      <arg type='i' name='ret' direction='out'/>"
        "    </method>"
@@ -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 (file)
index 0000000..6b683fd
--- /dev/null
@@ -0,0 +1,74 @@
+#include <stdlib.h>
+#include <sys/types.h>
+
+#include <unzip.h>
+
+#include <pkgmgr-info.h>
+
+#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;
+}