Pass adjusted file path to backend 73/106773/3
authorSangyoon Jang <s89.jang@samsung.com>
Fri, 23 Dec 2016 02:53:22 +0000 (11:53 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Fri, 23 Dec 2016 03:51:35 +0000 (12:51 +0900)
Submit with:
 - https://review.tizen.org/gerrit/106774

Change-Id: Iff9755081a5d8031395c031bc684d07d7a288cbc
Signed-off-by: Sangyoon Jang <s89.jang@samsung.com>
include/pkgmgr-server.h
src/request.c
src/util.c

index e22bfeb..0180fcb 100644 (file)
@@ -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_ */
index fce8210..2e4fbc1 100644 (file)
@@ -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) {
index d64ccb7..97799ac 100644 (file)
@@ -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;
+}