[Non-ACR][email-service][permission issue fix] 52/178552/3 accepted/tizen/unified/20180510.134427 submit/tizen/20180510.105236
authorSameer Prakash Pradhan <sp.pradhan@samsung.com>
Thu, 10 May 2018 10:25:24 +0000 (15:55 +0530)
committerSameer Prakash Pradhan <sp.pradhan@samsung.com>
Thu, 10 May 2018 10:43:13 +0000 (16:13 +0530)
Signed-off-by: Sameer Prakash Pradhan <sp.pradhan@samsung.com>
Change-Id: Ibcbb8e6ada26127d28812629ccee3d597d8b6899

email-core/email-storage/email-storage.c

index d13b14673f6fdbc7a08bd426a94410d20b4ec130..55e411d8c365989a6540b67c37beb346ead17ef8 100755 (executable)
@@ -413,7 +413,7 @@ INTERNAL_FUNC int emstorage_shm_file_init(const char *shm_file_name)
                return EMAIL_ERROR_SYSTEM_FAILURE;
        }
 
-       fchmod(fd, 0644);
+       fchmod(fd, 0666);
        EM_DEBUG_LOG("** Create SHM FILE **");
        if (ftruncate(fd, sizeof(mmapped_t)) != 0) {
                EM_DEBUG_EXCEPTION("ftruncate errno [%d]", errno);
@@ -480,7 +480,7 @@ int _initialize_shm_mutex(const char *shm_file_name, int *param_shm_fd, mmapped_
                        }
                }
 
-       fchmod((*param_shm_fd), 0644);
+       fchmod((*param_shm_fd), 0666);
        EM_DEBUG_LOG("** Create SHM FILE **");
        if (ftruncate((*param_shm_fd), sizeof(mmapped_t)) != 0) {
                EM_DEBUG_EXCEPTION("ftruncate errno [%d]", errno);
@@ -667,7 +667,7 @@ enum {
        SYNC_STATUS_IDX_IN_MAIL_READ_MAIL_UID_TBL,
        FLAGS_SEEN_FIELD_IDX_IN_MAIL_READ_MAIL_UID_TBL,
        FLAGS_FLAGGED_FIELD_IDX_IN_MAIL_READ_MAIL_UID_TBL,
-       IDX_NUM_IDX_IN_MAIL_READ_MAIL_UID_TBL,          /* unused */
+       IDX_NUM_IDX_IN_MAIL_READ_MAIL_UID_TBL,  /* unused */
 };
 
 #ifdef __FEATURE_BODY_SEARCH__
@@ -749,8 +749,8 @@ enum {
        DEFAULT_CHARSET_IDX_IN_MAIL_TBL,
        EAS_DATA_LENGTH_IDX_IN_MAIL_TBL,
        EAS_DATA_IDX_IN_MAIL_TBL,
-        USER_NAME_IDX_IN_MAIL_TBL,
-       FIELD_COUNT_OF_MAIL_TBL,  /* End of mail_tbl */
+       USER_NAME_IDX_IN_MAIL_TBL,
+       FIELD_COUNT_OF_MAIL_TBL,        /* End of mail_tbl */
 };
 
 enum {
@@ -799,7 +799,7 @@ enum {
        MAIL_ID_IDX_MAIL_AUTO_DOWNLOAD_ACTIVITY_TBL,
        SERVER_MAIL_ID_IDX_MAIL_AUTO_DOWNLOAD_ACTIVITY_TBL,
        MAILBOX_ID_IDX_MAIL_AUTO_DOWNLOAD_ACTIVITY_TBL,
-    MULTI_USER_NAME_IDX_MAIL_AUTO_DOWNLOAD_ACTIVITY_TBL,
+       MULTI_USER_NAME_IDX_MAIL_AUTO_DOWNLOAD_ACTIVITY_TBL,
 };
 #endif
 
@@ -987,7 +987,7 @@ static char *g_test_query[] = {
                "   activity_type, "
                "   mailbox_id, "
                "   mailbox_name "
-                "   multi_user_name "
+               "   multi_user_name "
                " FROM mail_partial_body_activity_tbl ",
 #endif
 
@@ -1059,7 +1059,7 @@ static char *g_test_query[] = {
                "   mail_id, "
                "   server_mail_id, "
                "   mailbox_id, "
-                "   multi_user_name, "
+               "   multi_user_name, "
                " FROM mail_auto_download_activity_tbl ",
 #endif
                NULL,
@@ -1544,8 +1544,8 @@ static void *_emstorage_open_once(char *multi_user_name, int *err_code)
 
        int error = EMAIL_ERROR_NONE;
 
-    if (EM_SAFE_STRLEN(multi_user_name) > 0) {
-        char buf[MAX_PATH] = {0};
+       if (EM_SAFE_STRLEN(multi_user_name) > 0) {
+               char buf[MAX_PATH] = {0};
                char *prefix_path = NULL;
 
                error = emcore_get_container_path(multi_user_name, &prefix_path);
@@ -1554,28 +1554,28 @@ static void *_emstorage_open_once(char *multi_user_name, int *err_code)
                        goto FINISH_OFF;
                }
 
-        memset(buf, 0x00, sizeof(buf));
-        SNPRINTF(buf, sizeof(buf), "%s%s", prefix_path, EMAIL_PATH);
-        mkdir(buf, DIRECTORY_PERMISSION);
+               memset(buf, 0x00, sizeof(buf));
+               SNPRINTF(buf, sizeof(buf), "%s%s", prefix_path, EMAIL_PATH);
+               mkdir(buf, DIRECTORY_PERMISSION);
 
-        memset(buf, 0x00, sizeof(buf));
-        SNPRINTF(buf, sizeof(buf), "%s%s", prefix_path, MAIL_HOME);
-        mkdir(buf, DIRECTORY_PERMISSION);
+               memset(buf, 0x00, sizeof(buf));
+               SNPRINTF(buf, sizeof(buf), "%s%s", prefix_path, MAIL_HOME);
+               mkdir(buf, DIRECTORY_PERMISSION);
 
-        memset(buf, 0x00, sizeof(buf));
-        SNPRINTF(buf, sizeof(buf), "%s%s", prefix_path, MAIL_TEMP);
-        mkdir(buf, DIRECTORY_PERMISSION);
+               memset(buf, 0x00, sizeof(buf));
+               SNPRINTF(buf, sizeof(buf), "%s%s", prefix_path, MAIL_TEMP);
+               mkdir(buf, DIRECTORY_PERMISSION);
 
-        _delete_temp_file(buf);
+               _delete_temp_file(buf);
                EM_SAFE_FREE(prefix_path);
-    } else {
-        mkdir(DATA_PATH, DIRECTORY_PERMISSION);
-        mkdir(EMAIL_PATH, DIRECTORY_PERMISSION);
-        mkdir(MAIL_HOME, DIRECTORY_PERMISSION);
-        mkdir(MAIL_TEMP, DIRECTORY_PERMISSION);
+       } else {
+               mkdir(DATA_PATH, DIRECTORY_PERMISSION);
+               mkdir(EMAIL_PATH, DIRECTORY_PERMISSION);
+               mkdir(MAIL_HOME, DIRECTORY_PERMISSION);
+               mkdir(MAIL_TEMP, DIRECTORY_PERMISSION);
 
-        _delete_temp_file(MAIL_TEMP);
-    }
+               _delete_temp_file(MAIL_TEMP);
+       }
 
        if (!emstorage_create_table(multi_user_name, EMAIL_CREATE_DB_NORMAL, &error)) {
                EM_DEBUG_EXCEPTION(" emstorage_create_table failed - %d", error);
@@ -1612,10 +1612,10 @@ static int _callback_sqlite_busy_handler(void *pData, int count)
 static int _callback_collation_utf7_sort(void *data, int length_text_a, const void *text_a,
                                                                                                         int length_text_b, const void *text_b)
 {
-    EM_DEBUG_FUNC_BEGIN();
-    int result = 0;
-    char *converted_string_a = NULL;
-    char *converted_string_b = NULL;
+       EM_DEBUG_FUNC_BEGIN();
+       int result = 0;
+       char *converted_string_a = NULL;
+       char *converted_string_b = NULL;
 
        EM_DEBUG_LOG_DEV("text_a : [%s]", text_a);
        converted_string_a = emcore_convert_mutf7_to_utf8((char *)text_a);
@@ -1697,19 +1697,18 @@ int _xsystem(const char *argv[])
        pid = fork();
 
        switch (pid) {
-               case -1:
-                       perror("fork failed");
-                       return -1;
-               case 0:
-                       if (execvp(argv[0], (char *const *)argv) == -1) {
-                               perror("execute init db script");
-                               _exit(-1);
-                       }
-
-                       _exit(2);
-               default:
-                       /* parent */
-                       break;
+       case -1:
+               perror("fork failed");
+               return -1;
+       case 0:
+               if (execvp(argv[0], (char *const *)argv) == -1) {
+                       perror("execute init db script");
+                       _exit(-1);
+               }
+               _exit(2);
+       default:
+               /* parent */
+               break;
        }
 
        if (waitpid(pid, &status, 0) == -1) {
@@ -1919,14 +1918,14 @@ INTERNAL_FUNC sqlite3* emstorage_db_open(char *multi_user_name, int *err_code)
         char temp_file_path[MAX_PATH] = {0};
 
         if (EM_SAFE_STRLEN(multi_user_name) > 0) {
-                       error = emcore_get_container_path(multi_user_name, &prefix_path);
-                       if (error != EMAIL_ERROR_CONTAINER_NOT_INITIALIZATION && error != EMAIL_ERROR_NONE) {
-                               EM_DEBUG_EXCEPTION("emcore_get_container_path failed :[%d]", error);
-                               goto FINISH_OFF;
-                       }
-        } else {
-            prefix_path = strdup("");
-        }
+       error = emcore_get_container_path(multi_user_name, &prefix_path);
+       if (error != EMAIL_ERROR_CONTAINER_NOT_INITIALIZATION && error != EMAIL_ERROR_NONE) {
+               EM_DEBUG_EXCEPTION("emcore_get_container_path failed :[%d]", error);
+               goto FINISH_OFF;
+       }
+       } else {
+               prefix_path = strdup("");
+       }
 
                if (error == EMAIL_ERROR_CONTAINER_NOT_INITIALIZATION) {
                        if ((error = emcore_get_canonicalize_path((char *)EMAIL_SERVICE_DB_FILE_PATH, &output_file_path)) != EMAIL_ERROR_NONE) {
@@ -2005,22 +2004,22 @@ INTERNAL_FUNC int emstorage_open(char *multi_user_name, int *err_code)
 {
        EM_DEBUG_FUNC_BEGIN();
 
-    int ret = false;
-    int error = EMAIL_ERROR_NONE;
-    int retValue;
+       int ret = false;
+       int error = EMAIL_ERROR_NONE;
+       int retValue;
        char *prefix_path = NULL;
-    char buf[MAX_PATH] = {0};
+       char buf[MAX_PATH] = {0};
 
-    if (EM_SAFE_STRLEN(multi_user_name) <= 0) {
-        SNPRINTF(buf, sizeof(buf), "%s", DB_PATH);
-    } else {
+       if (EM_SAFE_STRLEN(multi_user_name) <= 0) {
+               SNPRINTF(buf, sizeof(buf), "%s", DB_PATH);
+       } else {
                error = emcore_get_container_path(multi_user_name, &prefix_path);
                if (error != EMAIL_ERROR_NONE) {
                        EM_DEBUG_EXCEPTION("emcore_get_container_path failed : [%d]", error);
                        goto FINISH_OFF;
                }
-        SNPRINTF(buf, sizeof(buf), "%s/%s", prefix_path, DB_PATH);
-    }
+               SNPRINTF(buf, sizeof(buf), "%s/%s", prefix_path, DB_PATH);
+       }
 
        if (!g_file_test(buf, G_FILE_TEST_EXISTS)) {
            retValue = mkdir(buf, DIRECTORY_PERMISSION);
@@ -2029,26 +2028,26 @@ INTERNAL_FUNC int emstorage_open(char *multi_user_name, int *err_code)
            EM_DEBUG_LOG("emstorage_open - before sqlite3_open - pid = %d", getpid());
        }
 
-    if (emstorage_db_open(multi_user_name, &error) == NULL) {
-        EM_DEBUG_EXCEPTION("emstorage_db_open failed[%d]", error);
-        goto FINISH_OFF;
-    }
+       if (emstorage_db_open(multi_user_name, &error) == NULL) {
+               EM_DEBUG_EXCEPTION("emstorage_db_open failed[%d]", error);
+               goto FINISH_OFF;
+       }
 
-    if (_open_counter++ == 0) {
-        _emstorage_open_once(multi_user_name, &error);
-    }
+       if (_open_counter++ == 0) {
+               _emstorage_open_once(multi_user_name, &error);
+       }
 
-    ret = true;
+       ret = true;
 
 FINISH_OFF:
 
        EM_SAFE_FREE(prefix_path);
 
-    if (err_code != NULL)
-        *err_code = error;
+       if (err_code != NULL)
+               *err_code = error;
 
-    EM_DEBUG_FUNC_END("ret [%d]", ret);
-    return ret;
+       EM_DEBUG_FUNC_END("ret [%d]", ret);
+       return ret;
 }
 
 static int emstorage_get_field_count_from_create_table_query(char *input_create_table_query, int *output_field_count)
@@ -11484,7 +11483,7 @@ INTERNAL_FUNC int emstorage_clear_mail_data(char *multi_user_name, int transacti
 
        mkdir(MAIL_HOME, DIRECTORY_PERMISSION);
        mkdir(MAIL_TEMP, DIRECTORY_PERMISSION);
-       chmod(MAIL_TEMP, 0644);
+       chmod(MAIL_TEMP, 0777);
 
        /*  first clear index. */
        while (indexes->object_name) {
@@ -11752,7 +11751,7 @@ INTERNAL_FUNC int emstorage_create_dir(char *multi_user_name, int account_id, in
                        }
 
                        if (account_id == EML_FOLDER) {
-                               chmod(buf, 0644);
+                               chmod(buf, 0777);
                        }
                }
        }
@@ -11791,7 +11790,7 @@ INTERNAL_FUNC int emstorage_create_dir(char *multi_user_name, int account_id, in
                        }
 
                        if (account_id == EML_FOLDER) {
-                               chmod(buf, 0644);
+                               chmod(buf, 0777);
                        }
                }
        }
@@ -11821,7 +11820,7 @@ INTERNAL_FUNC int emstorage_create_dir(char *multi_user_name, int account_id, in
                        }
 
                        if (account_id == EML_FOLDER) {
-                               chmod(buf, 0644);
+                               chmod(buf, 0777);
                        }
                }
        }
@@ -11944,7 +11943,7 @@ INTERNAL_FUNC void emstorage_create_dir_if_delete()
        mkdir(EMAIL_PATH, DIRECTORY_PERMISSION);
        mkdir(MAIL_HOME, DIRECTORY_PERMISSION);
        mkdir(MAIL_TEMP, DIRECTORY_PERMISSION);
-       chmod(MAIL_TEMP, 0644);
+       chmod(MAIL_TEMP, 0777);
 
        EM_DEBUG_FUNC_END();
 }