From: pr.jung Date: Mon, 23 Jul 2018 06:52:22 +0000 (+0900) Subject: Change tzplatform_getenv to tzplatform_uid_getenv X-Git-Tag: submit/tizen_4.0/20180801.050519 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Ftags%2Fsubmit%2Ftizen_4.0%2F20180801.050519;p=platform%2Fcore%2Fsystem%2Flibstorage.git Change tzplatform_getenv to tzplatform_uid_getenv - Cover multi-user case Change-Id: I82cb6a0621ca1e87ae4009d7797cdd963ebf57a6 Signed-off-by: pr.jung --- diff --git a/include/common.h b/include/common.h index dd6f966..0e8f4a7 100644 --- a/include/common.h +++ b/include/common.h @@ -86,6 +86,8 @@ int storage_get_external_memory_size64_with_path(char *path, struct statvfs *buf int is_compat_bind_mount(void); int storage_ext_is_supported(void); +#define USER_UID_START 5000 + #ifdef __cplusplus } #endif diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c index 2c13dad..4031dec 100755 --- a/src/storage-inhouse.c +++ b/src/storage-inhouse.c @@ -15,6 +15,8 @@ */ +#include +#include #include #include #include @@ -59,6 +61,14 @@ API int storage_get_compat_internal_path(const char* origin, int len, char* comp return -1; } + if (getuid() <= USER_UID_START) { + //LCOV_EXCL_START System Error + _E("Only apps and user session daemons are allowed " + "to use storage_get_compat_internal_path()"); + return -1; + //LCOV_EXCL_STOP + } + // this API works on place where compat path is bind-mounted if (!is_compat_bind_mount()) { //LCOV_EXCL_START System Error @@ -67,7 +77,7 @@ API int storage_get_compat_internal_path(const char* origin, int len, char* comp //LCOV_EXCL_STOP } - str = tzplatform_getenv(TZ_USER_CONTENT); + str = tzplatform_uid_getenv(getuid(), TZ_USER_CONTENT); str_len = strlen(str); if (strncmp(origin, str, str_len) != 0) { _E("Failed to match TZ_USER_CONTENT"); @@ -115,6 +125,14 @@ API int storage_get_origin_internal_path(const char* compat, int len, char* orig return -1; } + if (getuid() <= USER_UID_START) { + //LCOV_EXCL_START System Error + _E("Only apps and user session daemons are allowed " + "to use storage_get_origin_internal_path()"); + return -1; + //LCOV_EXCL_STOP + } + // this API works on place where compat path is bind-mounted if (!is_compat_bind_mount()) { //LCOV_EXCL_START System Error @@ -129,7 +147,7 @@ API int storage_get_origin_internal_path(const char* compat, int len, char* orig return -1; } - r = snprintf(origin, len, "%s%s", tzplatform_getenv(TZ_USER_CONTENT), compat + compat_len); + r = snprintf(origin, len, "%s%s", tzplatform_uid_getenv(getuid(), TZ_USER_CONTENT), compat + compat_len); if (r < 0) { //LCOV_EXCL_START System Error _E("failed to create new path"); diff --git a/src/storage.c b/src/storage.c index 4197ec4..a92e519 100644 --- a/src/storage.c +++ b/src/storage.c @@ -27,8 +27,6 @@ #include "log.h" #include "storage-external.h" -#define USER_UID_START 5000 - const char *dir_path[STORAGE_DIRECTORY_MAX]; const int tz_id[STORAGE_DIRECTORY_MAX] = {