Only user session api calls can get internal storage root path 29/177229/2 accepted/tizen/unified/20180426.145908 submit/tizen/20180426.094326
authorpr.jung <pr.jung@samsung.com>
Thu, 26 Apr 2018 08:20:01 +0000 (17:20 +0900)
committerpr.jung <pr.jung@samsung.com>
Thu, 26 Apr 2018 09:19:37 +0000 (18:19 +0900)
Change-Id: Ifc044e9151a3b855c8a2ad1bddc82e55bd2e699b
Signed-off-by: pr.jung <pr.jung@samsung.com>
src/storage.c

index 33bfc8e..d79a00d 100644 (file)
@@ -81,18 +81,24 @@ API int storage_foreach_device_supported(storage_device_supported_cb callback, v
        const struct storage_ops *st;
        dd_list *elem;
        int ret;
+       bool user = true;
 
        if (!callback) {
                _E("Invalid parameter");
                return STORAGE_ERROR_INVALID_PARAMETER;
        }
 
+       if (getuid() < USER_UID_START)
+               user = false;
+
        DD_LIST_FOREACH(st_int_head, elem, st) {
-               ret = callback(st->storage_id, st->type, st->get_state(),
-                               st->root(), user_data);
-               /* if the return value is false, will be stop to iterate */
-               if (!ret)
-                       break;
+               if (user) {
+                       ret = callback(st->storage_id, st->type, st->get_state(),
+                                       st->root(), user_data);
+                       /* if the return value is false, will be stop to iterate */
+                       if (!ret)
+                               break;
+               }
        }
 
        if (!storage_ext_is_supported()) {
@@ -116,6 +122,7 @@ API int storage_get_root_directory(int storage_id, char **path)
        char root[PATH_MAX];
        int ret;
        bool extendedint;
+       bool user = true;
 
        if (storage_id < 0)
                return STORAGE_ERROR_NOT_SUPPORTED;
@@ -125,16 +132,19 @@ API int storage_get_root_directory(int storage_id, char **path)
                return STORAGE_ERROR_INVALID_PARAMETER;
        }
 
-       if (storage_id == STORAGE_TYPE_INTERNAL && getuid() < USER_UID_START) {
-               _E("Only Tizen applications and user session daemons can use \
-                       storage_get_root_directory(STORAGE_TYPE_INTERNAL, ...)");
-               return STORAGE_ERROR_INVALID_PARAMETER;
-       }
+       if (getuid() < USER_UID_START)
+               user = false;
 
        /* internal storage */
        DD_LIST_FOREACH(st_int_head, elem, st) {
                if (st->storage_id != storage_id)
                        continue;
+               if (!user) {
+                       _E("Only Tizen applications and user session daemons can use \
+                               storage_get_root_directory(id , ...)");
+                       return STORAGE_ERROR_INVALID_PARAMETER;
+               }
+
                *path = strdup(st->root());
                if (!*path) {
 //LCOV_EXCL_START System Error
@@ -171,6 +181,7 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p
        dd_list *elem;
        bool found;
        bool extendedint;
+       bool user = true;
 
        if (storage_id < 0)
                return STORAGE_ERROR_NOT_SUPPORTED;
@@ -194,7 +205,16 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p
                break;
        }
 
+       if (getuid() < USER_UID_START)
+               user = false;
+
        if (found && st) {
+               if (!user) {
+                       _E("Only Tizen applications and user session daemons can use \
+                               storage_get_directory(id, ...)");
+                       return STORAGE_ERROR_INVALID_PARAMETER;
+               }
+
                snprintf(root, sizeof(root), "%s", st->root());
                if (type == STORAGE_DIRECTORY_SYSTEM_RINGTONES) {
                        temp2 = vconf_get_str(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR);