From b2ed57e933b0ce1c693b8b877c4f4ecc6a5e05f9 Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Thu, 27 Oct 2016 17:07:39 +0900 Subject: [PATCH] Code refactoring (Getting user session path) Change-Id: Ia409b169b99caa7d48867ded7915d5af00480c08 Signed-off-by: Minje Ahn --- lib/media-util-register.c | 18 ++++++++---------- packaging/media-server.spec | 2 +- src/common/media-common-utils.c | 17 +++++++---------- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/lib/media-util-register.c b/lib/media-util-register.c index 2fa50ec..c36b625 100755 --- a/lib/media-util-register.c +++ b/lib/media-util-register.c @@ -79,12 +79,14 @@ static char* __media_get_path(uid_t uid) { char *result_passwd = NULL; struct group *grpinfo = NULL; + + grpinfo = getgrnam("users"); + if (grpinfo == NULL) { + MSAPI_DBG_ERR("getgrnam(users) returns NULL !"); + return NULL; + } + if (uid == getuid()) { - grpinfo = getgrnam("users"); - if (grpinfo == NULL) { - MSAPI_DBG_ERR("getgrnam(users) returns NULL !"); - return NULL; - } if (MS_STRING_VALID(MEDIA_ROOT_PATH_INTERNAL)) result_passwd = strndup(MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL)); } else { @@ -93,11 +95,7 @@ static char* __media_get_path(uid_t uid) MSAPI_DBG_ERR("getpwuid(%d) returns NULL !", uid); return NULL; } - grpinfo = getgrnam("users"); - if (grpinfo == NULL) { - MSAPI_DBG_ERR("getgrnam(users) returns NULL !"); - return NULL; - } + // Compare git_t type and not group name if (grpinfo->gr_gid != userinfo->pw_gid) { MSAPI_DBG_ERR("UID [%d] does not belong to 'users' group!", uid); diff --git a/packaging/media-server.spec b/packaging/media-server.spec index 52c1f9a..82ddb4a 100755 --- a/packaging/media-server.spec +++ b/packaging/media-server.spec @@ -1,6 +1,6 @@ Name: media-server Summary: A server for media content management -Version: 0.3.6 +Version: 0.3.7 Release: 0 Group: Multimedia/Service License: Apache-2.0 diff --git a/src/common/media-common-utils.c b/src/common/media-common-utils.c index fed09ca..acb5b85 100755 --- a/src/common/media-common-utils.c +++ b/src/common/media-common-utils.c @@ -96,12 +96,13 @@ static char* __media_get_path(uid_t uid) char *result_passwd = NULL; struct group *grpinfo = NULL; + grpinfo = getgrnam("users"); + if (grpinfo == NULL) { + MS_DBG_ERR("getgrnam(users) returns NULL !"); + return NULL; + } + if (uid == getuid()) { - grpinfo = getgrnam("users"); - if (grpinfo == NULL) { - MS_DBG_ERR("getgrnam(users) returns NULL !"); - return NULL; - } if (MS_STRING_VALID(MEDIA_ROOT_PATH_INTERNAL)) result_passwd = strndup(MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL)); } else { @@ -110,11 +111,7 @@ static char* __media_get_path(uid_t uid) MS_DBG_ERR("getpwuid(%d) returns NULL !", uid); return NULL; } - grpinfo = getgrnam("users"); - if (grpinfo == NULL) { - MS_DBG_ERR("getgrnam(users) returns NULL !"); - return NULL; - } + // Compare git_t type and not group name if (grpinfo->gr_gid != userinfo->pw_gid) { MS_DBG_ERR("UID [%d] does not belong to 'users' group!", uid); -- 2.7.4