From 4b6f854383e05addb43658964d07370708de56cb Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Fri, 23 Dec 2016 11:53:22 +0900 Subject: [PATCH] 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