From bc26579d2efb3e749b2735dccce8e8ebad01b801 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 27 Jan 2016 14:48:20 +0900 Subject: [PATCH] Deprecate shared directory related API - Shared/data directory is only available applications with api-version lower than 3.0 from Tizen 3.0. Change-Id: I4fe84168f5921f033a31510cccfac84cb16ea6c3 Signed-off-by: Hwankyu Jhun --- include/aul.h | 2 +- src/aul_path.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/include/aul.h b/include/aul.h index 9be56d8..ff19011 100644 --- a/include/aul.h +++ b/include/aul.h @@ -1663,7 +1663,7 @@ const char *aul_get_app_tep_resource_path(void); /* * This API is only for Appfw internally. */ -const char *aul_get_app_shared_data_path(void); +int aul_get_app_shared_data_path(char **path); /* * This API is only for Appfw internally. diff --git a/src/aul_path.c b/src/aul_path.c index 400a0e7..0964635 100644 --- a/src/aul_path.c +++ b/src/aul_path.c @@ -208,6 +208,38 @@ static const char *__get(char **path, const char *appid, return *path; } +static int __compare_api_version(const char *appid, uid_t uid, int *result) +{ + int ret; + char pkgid[NAME_MAX]; + pkgmgrinfo_pkginfo_h pkginfo; + char *api_version; + + ret = __get_pkgid(pkgid, sizeof(pkgid), appid, uid); + if (ret != AUL_R_OK) { + _E("Failed to get package id"); + return ret; + } + + ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &pkginfo); + if (ret != PMINFO_R_OK) { + _E("Failed to get pakckage info"); + return ret; + } + + ret = pkgmgrinfo_pkginfo_get_api_version(pkginfo, &api_version); + if (ret != PMINFO_R_OK) { + _E("Failed to get api-version"); + pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo); + return ret; + } + + *result = strverscmp(api_version, "3.0"); + pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo); + + return ret; +} + API const char *aul_get_app_external_root_path(void) { static char *path; @@ -250,11 +282,17 @@ API const char *aul_get_app_tep_resource_path(void) return __get(&path, NULL, _TEP_RESOURCE_DIR, getuid(), __get_path_from_db); } -API const char *aul_get_app_shared_data_path(void) +API int aul_get_app_shared_data_path(char **path) { - static char *path; + int res; - return __get(&path, NULL, _SHARED_DATA_DIR, getuid(), __get_path); + if (__compare_api_version(NULL, getuid(), &res) < 0) + return AUL_R_EREJECTED; + + if (res >= 0) + return AUL_R_EREJECTED; + + return __get_path(path, NULL, _SHARED_DATA_DIR, getuid()); } API const char *aul_get_app_shared_resource_path(void) @@ -317,9 +355,28 @@ API const char *aul_get_app_external_specific_path(void) API int aul_get_app_shared_data_path_by_appid(const char *appid, char **path) { + int res; + int callee_pid; + int caller_pid = getpid(); + if (appid == NULL || path == NULL) return AUL_R_EINVAL; + if (__compare_api_version(NULL, getuid(), &res) < 0) + return AUL_R_EREJECTED; + + if (res >= 0) + return AUL_R_EREJECTED; + + callee_pid = aul_app_get_pid(appid); + if (caller_pid != callee_pid) { + if (__compare_api_version(appid, getuid(), &res) < 0) + return AUL_R_EREJECTED; + + if (res >= 0) + return AUL_R_EREJECTED; + } + return __get_path(path, appid, _SHARED_DATA_DIR, getuid()); } -- 2.7.4