use access() in ctsvc_have_file_read_permission 74/47974/2
authorGukhwan Cho <gh78.cho@samsung.com>
Thu, 10 Sep 2015 11:35:27 +0000 (20:35 +0900)
committerGukhwan Cho <gh78.cho@samsung.com>
Mon, 14 Sep 2015 02:14:13 +0000 (11:14 +0900)
Change-Id: I62223ce39b8e2412adf5269b26fa5fd79838492d
Signed-off-by: Gukhwan Cho <gh78.cho@samsung.com>
server/db/ctsvc_db_access_control.c

index efec3de..43fd411 100644 (file)
@@ -16,6 +16,7 @@
  * limitations under the License.
  *
  */
+#include <unistd.h>
 #include <pthread.h>
 #include <sys/smack.h>
 #include <pims-ipc-svc.h>
@@ -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 */