Only user session api calls can get internal storage root path
[platform/core/system/libstorage.git] / src / storage.c
index cd3e29a..d79a00d 100644 (file)
@@ -28,6 +28,8 @@
 #include "storage-external.h"
 
 #define BLOCK_CONF_FILE         "/etc/storaged/block.conf"
+#define USER_UID_START         5000
+
 const char *dir_path[STORAGE_DIRECTORY_MAX];
 
 const int tz_id[STORAGE_DIRECTORY_MAX] = {
@@ -79,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()) {
@@ -114,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;
@@ -123,10 +132,19 @@ API int storage_get_root_directory(int storage_id, char **path)
                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
@@ -163,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;
@@ -186,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);