Change tzplatform_getenv to tzplatform_uid_getenv 94/184794/2 accepted/tizen/4.0/unified/20180803.172030 submit/tizen_4.0/20180723.094836 submit/tizen_4.0/20180723.095728 submit/tizen_4.0/20180801.050519
authorpr.jung <pr.jung@samsung.com>
Mon, 23 Jul 2018 06:52:22 +0000 (15:52 +0900)
committerJung <pr.jung@samsung.com>
Mon, 23 Jul 2018 07:32:57 +0000 (07:32 +0000)
- Cover multi-user case

Change-Id: I82cb6a0621ca1e87ae4009d7797cdd963ebf57a6
Signed-off-by: pr.jung <pr.jung@samsung.com>
include/common.h
src/storage-inhouse.c
src/storage.c

index dd6f966..0e8f4a7 100644 (file)
@@ -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
index 2c13dad..4031dec 100755 (executable)
@@ -15,6 +15,8 @@
  */
 
 
+#include <unistd.h>
+#include <sys/types.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -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");
index 4197ec4..a92e519 100644 (file)
@@ -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] = {