From: Gukhwan Cho Date: Thu, 10 Sep 2015 11:35:27 +0000 (+0900) Subject: use access() in ctsvc_have_file_read_permission X-Git-Tag: accepted/tizen/mobile/20151119.033537~18 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1012621f804e1752bdfc355eeb07c5fa71805bc4;p=platform%2Fcore%2Fpim%2Fcontacts-service.git use access() in ctsvc_have_file_read_permission Change-Id: I62223ce39b8e2412adf5269b26fa5fd79838492d Signed-off-by: Gukhwan Cho --- diff --git a/server/db/ctsvc_db_access_control.c b/server/db/ctsvc_db_access_control.c index efec3de..43fd411 100644 --- a/server/db/ctsvc_db_access_control.c +++ b/server/db/ctsvc_db_access_control.c @@ -16,6 +16,7 @@ * limitations under the License. * */ +#include #include #include #include @@ -73,52 +74,20 @@ static ctsvc_permission_info_s * __ctsvc_find_access_info(unsigned int thread_id */ int ctsvc_have_file_read_permission(const char *path) { - int ret; - int permission = -1; - char *file_label = NULL; - ctsvc_permission_info_s *find = NULL; - const char *smack_label; - int have_smack; - unsigned int thread_id; - - have_smack = __ctsvc_have_smack(); - if (have_smack != 1) /* smack disable */ - return CONTACTS_ERROR_NONE; - - /* Get SMACK label of the file */ - ret = smack_getlabel(path, &file_label, SMACK_LABEL_ACCESS); - if (ret < 0) { - CTS_ERR("smack_getlabel Fail (%d)", ret); - return CONTACTS_ERROR_SYSTEM; - } - - ctsvc_mutex_lock(CTS_MUTEX_ACCESS_CONTROL); - thread_id = (unsigned int)pthread_self(); - find = __ctsvc_find_access_info(thread_id); - if (NULL == find) { - CTS_ERR("does not have access info of the thread"); - free(file_label); - ctsvc_mutex_unlock(CTS_MUTEX_ACCESS_CONTROL); - return CONTACTS_ERROR_INTERNAL; - } - - smack_label = find->smack; - permission = smack_have_access(smack_label, file_label, "r"); - free(file_label); - if (permission == 0) { - CTS_ERR("Thread(0x%x), smack_have_access Fail(%d) : does not have permission", thread_id, permission); - ret = CONTACTS_ERROR_PERMISSION_DENIED; - } - else if (permission != 1) { - CTS_ERR("Thread(0x%x), smack_have_access Fail(%d)", thread_id, ret); - ret = CONTACTS_ERROR_SYSTEM; - } - else { - ret= CONTACTS_ERROR_NONE; + CTS_FN_CALL; + RETV_IF(NULL == path, CONTACTS_ERROR_INVALID_PARAMETER); + + if (0 != access(path, F_OK|R_OK)) { + CTS_ERR("access(%s) Fail(%d)", path, errno); + switch (errno) { + case EACCES: + return CONTACTS_ERROR_PERMISSION_DENIED; + default: + return CONTACTS_ERROR_SYSTEM; + } } - ctsvc_mutex_unlock(CTS_MUTEX_ACCESS_CONTROL); - return ret; + return CONTACTS_ERROR_NONE; } /* this function is called in mutex lock */