{
char *result_psswd = NULL;
struct group *grpinfo = NULL;
- if(uid == getuid())
- {
- result_psswd = strdup(MEDIA_ROOT_PATH_INTERNAL);
+ if (uid == getuid()) {
+ result_psswd = strndup(MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL));
grpinfo = getgrnam("users");
- if(grpinfo == NULL) {
+ if (grpinfo == NULL) {
MSAPI_DBG_ERR("getgrnam(users) returns NULL !");
return NULL;
}
- }
- else
- {
+ } else {
struct passwd *userinfo = getpwuid(uid);
- if(userinfo == NULL) {
+ if (userinfo == NULL) {
MSAPI_DBG_ERR("getpwuid(%d) returns NULL !", uid);
return NULL;
}
grpinfo = getgrnam("users");
- if(grpinfo == NULL) {
+ if (grpinfo == NULL) {
MSAPI_DBG_ERR("getgrnam(users) returns NULL !");
return NULL;
}
MSAPI_DBG_ERR("UID [%d] does not belong to 'users' group!", uid);
return NULL;
}
- asprintf(&result_psswd, "%s", userinfo->pw_dir);
+ result_psswd = strndup(userinfo->pw_dir, strlen(userinfo->pw_dir));
}
return result_psswd;
static bool _is_valid_path(const char *path, uid_t uid)
{
+ bool ret = false;
int length_path;
char * user_path = NULL;
-
+
if (path == NULL)
return false;
user_path = __media_get_path(uid);
+ if (user_path == NULL)
+ return false;
+
length_path = strlen(user_path);
if (strncmp(path, user_path, length_path) == 0) {
- return true;
+ ret = true;
} else if (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0) {
- return true;
+ ret = true;
} else if (strncmp(path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0) {
- return true;
- } else
- return false;
+ ret = true;
+ } else {
+ ret = false;
+ }
+
+ MS_SAFE_FREE(user_path);
+
+ return ret;
}
static int _check_dir_path(const char *dir_path, uid_t uid)
struct group *grpinfo = NULL;
int err = 0;
- if(uid == getuid())
- {
- result_psswd = strdup(MEDIA_ROOT_PATH_INTERNAL);
+ if (uid == getuid()) {
+ result_psswd = strndup(MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL));
grpinfo = getgrnam("users");
- if(grpinfo == NULL) {
+ if (grpinfo == NULL) {
MS_DBG_ERR("getgrnam(users) returns NULL !");
MS_SAFE_FREE(result_psswd);
return NULL;
}
- }
- else
- {
+ } else {
struct passwd *userinfo = getpwuid(uid);
- if(userinfo == NULL) {
+ if (userinfo == NULL) {
MS_DBG_ERR("getpwuid(%d) returns NULL !", uid);
return NULL;
}
grpinfo = getgrnam("users");
- if(grpinfo == NULL) {
+ if (grpinfo == NULL) {
MS_DBG_ERR("getgrnam(users) returns NULL !");
return NULL;
}
MS_DBG_ERR("UID [%d] does not belong to 'users' group!", uid);
return NULL;
}
- err = asprintf(&result_psswd, "%s", userinfo->pw_dir);
- if(err < 0) {
- MS_DBG_ERR("asprintf failed [%d]", err);
- return NULL;
- }
+ result_psswd = strndup(userinfo->pw_dir, strlen(userinfo->pw_dir));
}
return result_psswd;
ms_storage_type_t ms_get_storage_type_by_full(const char *path, uid_t uid)
{
int length_path;
+ int ret = MS_MEDIA_ERR_NONE;
char * user_path = NULL;
if (path == NULL)
- return false;
+ return MS_MEDIA_ERR_INVALID_PATH;
user_path = __media_get_path(uid);
+ if (user_path == NULL)
+ return MS_MEDIA_ERR_OUT_OF_MEMORY;
+
length_path = strlen(user_path);
if (strncmp(path, user_path, length_path) == 0) {
- return MS_STORAGE_INTERNAL;
+ ret = MS_STORAGE_INTERNAL;
} else if (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0) {
- return MS_STORAGE_EXTERNAL;
+ ret = MS_STORAGE_EXTERNAL;
+ } else if (strncmp(path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0) {
+ ret = MS_STORAGE_EXTERNAL_USB;
} else {
- free(user_path);
- return MS_MEDIA_ERR_INVALID_PATH;
- }
+ ret = MS_MEDIA_ERR_INVALID_PATH;
+ }
+
+ MS_SAFE_FREE(user_path);
+
+ return ret;
}
int ms_strappend(char *res, const int size, const char *pattern,
static char* __msc_get_path(uid_t uid)
{
+ int result_size = 0;
char *result_psswd = NULL;
struct group *grpinfo = NULL;
- if(uid == getuid())
- {
- result_psswd = strdup(MEDIA_ROOT_PATH_INTERNAL);
+ if (uid == getuid()) {
+ result_psswd = strndup(MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL));
grpinfo = getgrnam("users");
if(grpinfo == NULL) {
MS_DBG_ERR("getgrnam(users) returns NULL !");
return NULL;
}
- }
- else
- {
+ } else {
struct passwd *userinfo = getpwuid(uid);
- if(userinfo == NULL) {
+ if (userinfo == NULL) {
MS_DBG_ERR("getpwuid(%d) returns NULL !", uid);
return NULL;
}
grpinfo = getgrnam("users");
- if(grpinfo == NULL) {
+ if (grpinfo == NULL) {
MS_DBG_ERR("getgrnam(users) returns NULL !");
return NULL;
}
MS_DBG_ERR("UID [%d] does not belong to 'users' group!", uid);
return NULL;
}
- asprintf(&result_psswd, "%s/%s", userinfo->pw_dir, MEDIA_CONTENT_PATH);
+ result_size = strlen(userinfo->pw_dir) + strlen(MEDIA_CONTENT_PATH) + 2;
+
+ MS_MALLOC(result_psswd, result_size);
+ snprintf(result_psswd, result_size, "%s/%s", userinfo->pw_dir, MEDIA_CONTENT_PATH);
}
return result_psswd;
static bool __msc_is_valid_path(const char *path, uid_t uid)
{
+ bool ret = false;
char *usr_path = NULL;
if (path == NULL)
return false;
if (strncmp(path, usr_path, strlen(usr_path)) == 0) {
- MS_SAFE_FREE(usr_path);
- return true;
+ ret = true;
} else if (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0) {
- MS_SAFE_FREE(usr_path);
- return true;
+ ret = true;
+ } else if (strncmp(path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0) {
+ ret = true;
} else {
- MS_SAFE_FREE(usr_path);
- return false;
+ ret = false;
}
- return true;
+
+ MS_SAFE_FREE(usr_path);
+
+ return ret;
}
static int __msc_check_file_path(const char *file_path, uid_t uid)