apply encoded name to the source file of losetup. 22/71222/6 accepted/tizen/common/20160602.140038 accepted/tizen/ivi/20160602.022844 accepted/tizen/mobile/20160602.023016 accepted/tizen/tv/20160602.022545 accepted/tizen/wearable/20160602.022731 submit/tizen/20160531.024853
authorjongmyeongko <jongmyeong.ko@samsung.com>
Tue, 24 May 2016 12:21:52 +0000 (21:21 +0900)
committerjongmyeongko <jongmyeong.ko@samsung.com>
Tue, 31 May 2016 12:04:10 +0000 (21:04 +0900)
losetup stores only 64 byte length for the filename.

Change-Id: Ib23a76e9c03a5d3ccd81fbda2698e1d4e7eefe1e
Signed-off-by: jongmyeongko <jongmyeong.ko@samsung.com>
plugin/app2sd/inc/app2sd_internals.h
plugin/app2sd/src/app2sd_interface.c
plugin/app2sd/src/app2sd_internals.c
plugin/app2sd/src/app2sd_internals_registry.c
plugin/app2sd/src/app2sd_internals_utils.c
plugin/app2sd/src/app2sd_server.c
src/app2ext_interface.c

index 2d6e815..1ee6274 100644 (file)
@@ -82,15 +82,6 @@ typedef enum app2sd_cmd_t {
        APP2SD_MOVE_APP_TO_PHONE
 } app2sd_cmd;
 
-/*This will store password in DB*/
-int _app2sd_set_passwod_in_db(const char *pkgid, const char *password);
-
-/*This will remove password from db*/
-int _app2sd_remove_password_from_db(const char *pkgid);
-
-/*This will fetch password from db*/
-char *_app2sd_get_passowrd_from_db(const char *pkgid);
-
 /*Checks whether mmc is present or not*/
 int _app2sd_check_mmc_status(void);
 
@@ -130,13 +121,13 @@ char *_app2sd_find_associated_device_node(const char *loopback_device);
 
 /*This function does the loopback encryption for app*/
 char *_app2sd_do_loopback_encryption_setup(const char *pkgid,
-               const char *loopback_device);
+               const char *loopback_device, uid_t uid);
 
 /*This function detaches the loopback device*/
 char *_app2sd_detach_loop_device(const char *device);
 
 /*This function finds loopback device associated with the app*/
-char *_app2sd_find_associated_device(const char *mmc_app_path);
+char *_app2sd_find_associated_device(const char *loopback_device);
 
 /*This function creates loopback device*/
 int _app2sd_create_loopback_device(const char *pkgid,
@@ -196,4 +187,6 @@ void _app2sd_make_result_info_file(char *pkgid, int size, uid_t uid);
 
 int _is_global(uid_t uid);
 
+char *_app2sd_get_encoded_name(const char *pkgid, uid_t uid);
+
 #endif
index 53ac5a4..b9e30c1 100644 (file)
@@ -31,7 +31,6 @@
 static int __app2sd_create_app2sd_directories(uid_t uid)
 {
        int ret = 0;
-       char app2sd_user_path[FILENAME_MAX] = { 0, };
        mode_t mode = DIR_PERMS;
 
        ret = mkdir(APP2SD_PATH, mode);
@@ -43,22 +42,6 @@ static int __app2sd_create_app2sd_directories(uid_t uid)
                }
        }
 
-       if (!_is_global(uid)) {
-               tzplatform_set_user(uid);
-               snprintf(app2sd_user_path, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, tzplatform_getenv(TZ_USER_NAME));
-               tzplatform_reset_user();
-
-               ret = mkdir(app2sd_user_path, mode);
-               if (ret) {
-                       if (errno != EEXIST) {
-                               _E("create directory failed," \
-                                       " error no is (%d)", errno);
-                               return APP2EXT_ERROR_CREATE_DIRECTORY;
-                       }
-               }
-       }
-
        return APP2EXT_SUCCESS;
 }
 
@@ -71,6 +54,7 @@ int app2sd_usr_pre_app_install(const char *pkgid, GList* dir_list, int size, uid
        char *result = NULL;
        char application_path[FILENAME_MAX] = { 0, };
        char loopback_device[FILENAME_MAX] = { 0, };
+       char *encoded_id = NULL;
        int reqd_disk_size = size + ceil(size * 0.2);
 
        /* validate the function parameter recieved */
@@ -106,19 +90,24 @@ int app2sd_usr_pre_app_install(const char *pkgid, GList* dir_list, int size, uid
                return APP2EXT_ERROR_MMC_INSUFFICIENT_MEMORY;
        }
 
+       encoded_id = _app2sd_get_encoded_name(pkgid, uid);
+       if (encoded_id == NULL) {
+               return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
+       }
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
                snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, pkgid);
+                       APP2SD_PATH, encoded_id);
        } else {
                tzplatform_set_user(uid);
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_USER_APP), pkgid);
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
-                       APP2SD_PATH, tzplatform_getenv(TZ_USER_NAME), pkgid);
+               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
+                       APP2SD_PATH, encoded_id);
                tzplatform_reset_user();
        }
+       free(encoded_id);
        _D("application_path = (%s)", application_path);
        _D("loopback_device = (%s)", loopback_device);
 
@@ -150,7 +139,7 @@ int app2sd_usr_pre_app_install(const char *pkgid, GList* dir_list, int size, uid
 
        /* perform loopback encryption setup */
        device_node = _app2sd_do_loopback_encryption_setup(pkgid,
-               loopback_device);
+               loopback_device, uid);
        if (!device_node) {
                _E("loopback encryption setup failed");
                _app2sd_delete_loopback_device(loopback_device);
@@ -221,6 +210,7 @@ int app2sd_usr_post_app_install(const char *pkgid,
        char *device_name = NULL;
        char application_path[FILENAME_MAX] = { 0, };
        char loopback_device[FILENAME_MAX] = { 0, };
+       char *encoded_id = NULL;
        int ret = APP2EXT_SUCCESS;
        int pkgmgr_ret = 0;
 
@@ -239,19 +229,24 @@ int app2sd_usr_post_app_install(const char *pkgid,
        }
        sync();
 
+       encoded_id = _app2sd_get_encoded_name(pkgid, uid);
+       if (encoded_id == NULL) {
+               return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
+       }
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
                snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, pkgid);
+                       APP2SD_PATH, encoded_id);
        } else {
                tzplatform_set_user(uid);
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_USER_APP), pkgid);
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
-                       APP2SD_PATH, tzplatform_getenv(TZ_USER_NAME), pkgid);
+               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
+                       APP2SD_PATH, encoded_id);
                tzplatform_reset_user();
        }
+       free(encoded_id);
        _D("application_path = (%s)", application_path);
        _D("loopback_device = (%s)", loopback_device);
 
@@ -328,6 +323,7 @@ int app2sd_usr_on_demand_setup_init(const char *pkgid, uid_t uid)
        int ret = APP2EXT_SUCCESS;
        char application_path[FILENAME_MAX] = { 0, };
        char loopback_device[FILENAME_MAX] = { 0, };
+       char *encoded_id = NULL;
        char *device_node = NULL;
        char *result = NULL;
        FILE *fp = NULL;
@@ -345,20 +341,25 @@ int app2sd_usr_on_demand_setup_init(const char *pkgid, uid_t uid)
                return APP2EXT_ERROR_MMC_STATUS;
        }
 
+       encoded_id = _app2sd_get_encoded_name(pkgid, uid);
+       if (encoded_id == NULL) {
+               return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
+       }
        /* check app entry is there in sd card or not. */
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
                snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, pkgid);
+                       APP2SD_PATH, encoded_id);
        } else {
                tzplatform_set_user(uid);
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_USER_APP), pkgid);
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
-                       APP2SD_PATH, tzplatform_getenv(TZ_USER_NAME), pkgid);
+               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
+                       APP2SD_PATH, encoded_id);
                tzplatform_reset_user();
        }
+       free(encoded_id);
        _D("application_path = (%s)", application_path);
        _D("loopback_device = (%s)", loopback_device);
 
@@ -380,7 +381,7 @@ int app2sd_usr_on_demand_setup_init(const char *pkgid, uid_t uid)
 
        /* do loopback setup */
        device_node = _app2sd_do_loopback_encryption_setup(pkgid,
-               loopback_device);
+               loopback_device, uid);
        if (device_node == NULL) {
                _E("loopback encryption setup failed");
                return APP2EXT_ERROR_DO_LOSETUP;
@@ -411,6 +412,7 @@ int app2sd_usr_on_demand_setup_exit(const char *pkgid, uid_t uid)
        int ret = APP2EXT_SUCCESS;
        char application_path[FILENAME_MAX] = { 0, };
        char loopback_device[FILENAME_MAX] = { 0, };
+       char *encoded_id = NULL;
        FILE *fp = NULL;
 
        /* validate the function parameter recieved */
@@ -426,20 +428,25 @@ int app2sd_usr_on_demand_setup_exit(const char *pkgid, uid_t uid)
                return APP2EXT_ERROR_MMC_STATUS;
        }
 
+       encoded_id = _app2sd_get_encoded_name(pkgid, uid);
+       if (encoded_id == NULL) {
+               return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
+       }
        /* check app entry is there in sd card or not. */
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
                snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, pkgid);
+                       APP2SD_PATH, encoded_id);
        } else {
                tzplatform_set_user(uid);
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_USER_APP), pkgid);
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
-                       APP2SD_PATH, tzplatform_getenv(TZ_USER_NAME), pkgid);
+               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
+                       APP2SD_PATH, encoded_id);
                tzplatform_reset_user();
        }
+       free(encoded_id);
        _D("application_path = (%s)", application_path);
        _D("loopback_device = (%s)", loopback_device);
 
@@ -470,6 +477,7 @@ int app2sd_usr_pre_app_uninstall(const char *pkgid, uid_t uid)
        int ret = APP2EXT_SUCCESS;
        char application_path[FILENAME_MAX] = { 0, };
        char loopback_device[FILENAME_MAX] = { 0, };
+       char *encoded_id = NULL;
        char *device_node = NULL;
        FILE *fp = NULL;
 
@@ -488,19 +496,24 @@ int app2sd_usr_pre_app_uninstall(const char *pkgid, uid_t uid)
                goto END;
        }
 
+       encoded_id = _app2sd_get_encoded_name(pkgid, uid);
+       if (encoded_id == NULL) {
+               return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
+       }
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
                snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, pkgid);
+                       APP2SD_PATH, encoded_id);
        } else {
                tzplatform_set_user(uid);
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_USER_APP), pkgid);
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
-                       APP2SD_PATH, tzplatform_getenv(TZ_USER_NAME), pkgid);
+               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
+                       APP2SD_PATH, encoded_id);
                tzplatform_reset_user();
        }
+       free(encoded_id);
        _D("application_path = (%s)", application_path);
        _D("loopback_device = (%s)", loopback_device);
 
@@ -518,7 +531,7 @@ int app2sd_usr_pre_app_uninstall(const char *pkgid, uid_t uid)
        if (NULL == device_node) {
                /* do loopback setup */
                device_node = _app2sd_do_loopback_encryption_setup(pkgid,
-                       loopback_device);
+                       loopback_device, uid);
                if (device_node == NULL) {
                        _E("loopback encryption setup failed");
                        ret = APP2EXT_ERROR_DO_LOSETUP;
@@ -565,6 +578,7 @@ int app2sd_usr_post_app_uninstall(const char *pkgid, uid_t uid)
 {
        char application_path[FILENAME_MAX] = { 0, };
        char loopback_device[FILENAME_MAX] = { 0, };
+       char *encoded_id = NULL;
        int ret = APP2EXT_SUCCESS;
 
        /* validate the function parameter recieved */
@@ -582,19 +596,24 @@ int app2sd_usr_post_app_uninstall(const char *pkgid, uid_t uid)
                goto END;
        }
 
+       encoded_id = _app2sd_get_encoded_name(pkgid, uid);
+       if (encoded_id == NULL) {
+               return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
+       }
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
                snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, pkgid);
+                       APP2SD_PATH, encoded_id);
        } else {
                tzplatform_set_user(uid);
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_USER_APP), pkgid);
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
-                       APP2SD_PATH, tzplatform_getenv(TZ_USER_NAME), pkgid);
+               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
+                       APP2SD_PATH, encoded_id);
                tzplatform_reset_user();
        }
+       free(encoded_id);
        _D("application_path = (%s)", application_path);
        _D("loopback_device = (%s)", loopback_device);
 
@@ -731,10 +750,14 @@ int app2sd_usr_pre_app_upgrade(const char *pkgid, GList* dir_list,
        int ret = APP2EXT_SUCCESS;
        char loopback_device[FILENAME_MAX] = { 0, };
        char application_path[FILENAME_MAX] = { 0, };
-       char temp_pkgid[FILENAME_MAX] = { 0, };
-       char temp_loopback_device[FILENAME_MAX] = { 0, };
-       char temp_application_path[FILENAME_MAX] = { 0, };
+       char temp_uid[32] = { 0, };
+       char *temp_pkgid = NULL;
+       char *temp_loopback_device = NULL;
+       char *temp_application_path = NULL;
        char *device_node = NULL;
+       char *encoded_id = NULL;
+       char *temp_encoded_id = NULL;
+       int len = 0;
        unsigned long long curr_size = 0;
        FILE *fp = NULL;
        int reqd_disk_size = size + ceil(size * 0.2);
@@ -752,19 +775,24 @@ int app2sd_usr_pre_app_upgrade(const char *pkgid, GList* dir_list,
                return APP2EXT_ERROR_MMC_STATUS;
        }
 
+       encoded_id = _app2sd_get_encoded_name(pkgid, uid);
+       if (encoded_id == NULL) {
+               return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
+       }
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
                snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, pkgid);
+                       APP2SD_PATH, encoded_id);
        } else {
                tzplatform_set_user(uid);
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_USER_APP), pkgid);
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
-                       APP2SD_PATH, tzplatform_getenv(TZ_USER_NAME), pkgid);
+               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
+                       APP2SD_PATH, encoded_id);
                tzplatform_reset_user();
        }
+       free(encoded_id);
        _D("application_path = (%s)", application_path);
        _D("loopback_device = (%s)", loopback_device);
 
@@ -784,25 +812,83 @@ int app2sd_usr_pre_app_upgrade(const char *pkgid, GList* dir_list,
                return APP2EXT_ERROR_LOOPBACK_DEVICE_UNAVAILABLE;
        }
        if ((int)curr_size < reqd_disk_size) {
-               snprintf(temp_pkgid, FILENAME_MAX - 1, "%s.new", pkgid);
+               len = strlen(pkgid) + strlen(".new");
+               temp_pkgid = calloc(len + 1, sizeof(char));
+               if (temp_pkgid == NULL) {
+                       _E("memory alloc failed");
+                       return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
+               }
+               snprintf(temp_pkgid, len, "%s.new", pkgid);
+
                if (_is_global(uid)) {
-                       snprintf(temp_application_path, FILENAME_MAX - 1,
-                               "%s/%s", tzplatform_getenv(TZ_SYS_RW_APP), temp_pkgid);
-                       snprintf(temp_loopback_device, FILENAME_MAX - 1,
-                               "%s/%s", APP2SD_PATH, temp_pkgid);
+                       len = strlen(tzplatform_getenv(TZ_SYS_RW_APP)) + strlen(temp_pkgid) + 1;
+                       temp_application_path = calloc(len + 1, sizeof(char));
+                       if (temp_application_path == NULL) {
+                               _E("memory alloc failed");
+                               free(temp_pkgid);
+                               return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
+                       }
+                       snprintf(temp_application_path, len, "%s/%s",
+                               tzplatform_getenv(TZ_SYS_RW_APP), temp_pkgid);
+
+                       temp_encoded_id = _app2sd_get_encoded_name((const char *)temp_pkgid, uid);
+                       if (temp_encoded_id == NULL) {
+                               free(temp_pkgid);
+                               free(temp_application_path);
+                               return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
+                       }
+                       len = strlen(APP2SD_PATH) + strlen(temp_encoded_id) + 1;
+                       temp_loopback_device = calloc(len + 1, sizeof(char));
+                       if (temp_loopback_device == NULL) {
+                               _E("memory alloc failed");
+                               free(temp_pkgid);
+                               free(temp_application_path);
+                               free(temp_encoded_id);
+                               return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
+                       }
+                       snprintf(temp_loopback_device, len, "%s/%s",
+                               APP2SD_PATH, temp_encoded_id);
+                       free(temp_encoded_id);
                } else {
                        tzplatform_set_user(uid);
-                       snprintf(temp_application_path, FILENAME_MAX - 1,
-                               "%s/%s", tzplatform_getenv(TZ_USER_APP), temp_pkgid);
-                       snprintf(temp_loopback_device, FILENAME_MAX - 1,
-                               "%s/%s/%s", APP2SD_PATH,
-                               tzplatform_getenv(TZ_USER_NAME), temp_pkgid);
+                       len = strlen(tzplatform_getenv(TZ_USER_APP)) + strlen(temp_pkgid) + 1;
+                       temp_application_path = calloc(len + 1, sizeof(char));
+                       if (temp_application_path == NULL) {
+                               _E("memory alloc failed");
+                               free(temp_pkgid);
+                               return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
+                       }
+                       snprintf(temp_application_path, len, "%s/%s",
+                               tzplatform_getenv(TZ_USER_APP), temp_pkgid);
+
+                       temp_encoded_id = _app2sd_get_encoded_name((const char*)temp_pkgid, uid);
+                       if (temp_encoded_id == NULL) {
+                               free(temp_pkgid);
+                               free(temp_application_path);
+                               return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
+                       }
+                       snprintf(temp_uid, 32, "%d", uid);
+                       len = strlen(APP2SD_PATH) + strlen(temp_uid) + strlen(temp_encoded_id) + 2;
+                       temp_loopback_device = calloc(len + 1, sizeof(char));
+                       if (temp_loopback_device == NULL) {
+                               _E("memory alloc failed");
+                               free(temp_pkgid);
+                               free(temp_application_path);
+                               free(temp_encoded_id);
+                               return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
+                       }
+                       snprintf(temp_loopback_device, len, "%s/%s",
+                               APP2SD_PATH, temp_encoded_id);
+                       free(temp_encoded_id);
                        tzplatform_reset_user();
                }
                ret = _app2sd_update_loopback_device_size(pkgid,
                        loopback_device, application_path, temp_pkgid,
                        temp_loopback_device, temp_application_path,
                        reqd_disk_size, dir_list, uid);
+               free(temp_pkgid);
+               free(temp_application_path);
+               free(temp_loopback_device);
                if (APP2EXT_SUCCESS != ret) {
                        _E("failed to update loopback device size");
                        return ret;
@@ -814,7 +900,7 @@ int app2sd_usr_pre_app_upgrade(const char *pkgid, GList* dir_list,
        if (NULL == device_node) {
                /* do loopback setup */
                device_node = _app2sd_do_loopback_encryption_setup(pkgid,
-                       loopback_device);
+                       loopback_device, uid);
                if (device_node == NULL) {
                        _E("loopback encryption setup failed");
                        return APP2EXT_ERROR_DO_LOSETUP;
@@ -860,6 +946,7 @@ int app2sd_usr_post_app_upgrade(const char *pkgid,
        char *device_name = NULL;
        char loopback_device[FILENAME_MAX] = { 0, };
        char application_path[FILENAME_MAX] = { 0, };
+       char *encoded_id = NULL;
        int ret = APP2EXT_SUCCESS;
 
        /* validate the function parameter recieved */
@@ -876,19 +963,24 @@ int app2sd_usr_post_app_upgrade(const char *pkgid,
                return APP2EXT_ERROR_MMC_STATUS;
        }
 
+       encoded_id = _app2sd_get_encoded_name(pkgid, uid);
+       if (encoded_id == NULL) {
+               return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
+       }
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
                snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, pkgid);
+                       APP2SD_PATH, encoded_id);
        } else {
                tzplatform_set_user(uid);
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_USER_APP), pkgid);
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
-                       APP2SD_PATH, tzplatform_getenv(TZ_USER_NAME), pkgid);
+               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
+                       APP2SD_PATH, encoded_id);
                tzplatform_reset_user();
        }
+       free(encoded_id);
        _D("application_path = (%s)", application_path);
        _D("loopback_device = (%s)", loopback_device);
 
@@ -931,6 +1023,7 @@ int app2sd_usr_force_clean(const char *pkgid, uid_t uid)
 {
        char loopback_device[FILENAME_MAX] = { 0, };
        char application_path[FILENAME_MAX] = { 0, };
+       char *encoded_id = NULL;
        int ret = APP2EXT_SUCCESS;
 
        _D("start force_clean [%s]", pkgid);
@@ -943,19 +1036,24 @@ int app2sd_usr_force_clean(const char *pkgid, uid_t uid)
 
        sync();
 
+       encoded_id = _app2sd_get_encoded_name(pkgid, uid);
+       if (encoded_id == NULL) {
+               return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
+       }
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
                snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, pkgid);
+                       APP2SD_PATH, encoded_id);
        } else {
                tzplatform_set_user(uid);
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_USER_APP), pkgid);
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
-                       APP2SD_PATH, tzplatform_getenv(TZ_USER_NAME), pkgid);
+               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
+                       APP2SD_PATH, encoded_id);
                tzplatform_reset_user();
        }
+       free(encoded_id);
        _D("application_path = (%s)", application_path);
        _D("loopback_device = (%s)", loopback_device);
 
index 85761a1..0050a25 100644 (file)
@@ -221,7 +221,7 @@ char *_app2sd_create_loopdevice_node(void)
 }
 
 char *_app2sd_do_loopback_encryption_setup(const char *pkgid,
-       const char *loopback_device)
+       const char *loopback_device, uid_t uid)
 {
        int ret = APP2EXT_SUCCESS;
        char *passwd = NULL;
@@ -233,12 +233,13 @@ char *_app2sd_do_loopback_encryption_setup(const char *pkgid,
                return NULL;
        }
 
-       /* Get password for loopback encryption */
+       /* get password for loopback encryption */
        ret = _app2sd_initialize_db();
        if (ret) {
                _E("app2sd db initialize failed");
                return NULL;
        }
+
        if ((passwd = _app2sd_get_password_from_db(pkgid)) == NULL) {
                passwd = (char *)_app2sd_generate_password(pkgid);
                if (NULL == passwd) {
@@ -255,7 +256,7 @@ char *_app2sd_do_loopback_encryption_setup(const char *pkgid,
                }
        }
 
-       /* Get Free device node*/
+       /* get free device node*/
        device_node = _app2sd_create_loopdevice_node();
        if (NULL == device_node) {
                free(passwd);
@@ -284,8 +285,8 @@ char *_app2sd_do_loopback_encryption_setup(const char *pkgid,
 }
 
 char *_app2sd_do_loopback_duplicate_encryption_setup(const char *pkgid,
-               const char *temp_pkgid,
-               const char *temp_loopback_device)
+               const char *temp_pkgid, const char *temp_loopback_device,
+               uid_t uid)
 {
        int ret = APP2EXT_SUCCESS;
        char *passwd = NULL;
@@ -311,7 +312,6 @@ char *_app2sd_do_loopback_duplicate_encryption_setup(const char *pkgid,
                        _E("unable to generate password");
                        return NULL;
                } else {
-                       _E("password is (%s)", passwd);
                        if ((ret = _app2sd_set_password_in_db(pkgid,
                                passwd)) < 0) {
                                _E("unable to save password");
@@ -851,7 +851,7 @@ int _app2sd_move_app_to_external(const char *pkgid, GList* dir_list, uid_t uid)
        }
        /* perform loopback encryption setup */
        device_node = _app2sd_do_loopback_encryption_setup(pkgid,
-               loopback_device);
+               loopback_device, uid);
        if (!device_node) {
                _E("loopback encryption setup failed");
                return APP2EXT_ERROR_DO_LOSETUP;
@@ -1079,7 +1079,7 @@ int _app2sd_move_app_to_internal(const char *pkgid, GList* dir_list, uid_t uid)
        if (NULL == device_node) {
                /* do loopback setup */
                device_node = _app2sd_do_loopback_encryption_setup(pkgid,
-                       loopback_device);
+                       loopback_device, uid);
                if (device_node == NULL) {
                        _E("loopback encryption setup failed");
                        return APP2EXT_ERROR_DO_LOSETUP;
@@ -1315,7 +1315,7 @@ int _app2sd_duplicate_device(const char *pkgid,
 
        /* perform loopback encryption setup */
        dev_node = _app2sd_do_loopback_duplicate_encryption_setup(pkgid,
-               temp_pkgid, temp_loopback_device);
+               temp_pkgid, temp_loopback_device, uid);
        if (!dev_node) {
                _E("losetup failed, device node is (%s)", dev_node);
                _app2sd_delete_loopback_device(loopback_device);
@@ -1409,7 +1409,7 @@ int _app2sd_update_loopback_device_size(const char *pkgid,
        if (NULL == old_device_node) {
                /* do loopback setup */
                old_device_node = _app2sd_do_loopback_encryption_setup(pkgid,
-                       loopback_device);
+                       loopback_device, uid);
                if (old_device_node == NULL) {
                        _E("loopback encryption setup failed");
                        err_res = APP2EXT_ERROR_DO_LOSETUP;
index 4913a3a..6e817b4 100644 (file)
@@ -55,6 +55,7 @@ int _app2sd_initialize_db()
        char *error_message = NULL;
        int ret;
        FILE * fp = NULL;
+
        fp = fopen(APP2SD_DB_FILE, "r");
        if (fp != NULL) {
                fclose(fp);
@@ -87,18 +88,16 @@ int _app2sd_initialize_db()
                return -1;
        }
 
-       _D("db_initialize_done");
-
        return 0;
 }
 
-int _app2sd_set_password_in_db(const char *pkgid,
-                                     const char *passwd)
+int _app2sd_set_password_in_db(const char *pkgid, const char *passwd)
 {
        char *error_message = NULL;
+       char *query = NULL;
 
-       char *query = sqlite3_mprintf("insert into app2sd(pkgid,password) values (%Q, %Q)",
-               pkgid, passwd);
+       query = sqlite3_mprintf("insert into app2sd" \
+               "(pkgid, password) values (%Q, %Q)", pkgid, passwd);
 
        if (SQLITE_OK != sqlite3_exec(app2sd_db, query, NULL, NULL,
                &error_message)) {
@@ -108,7 +107,6 @@ int _app2sd_set_password_in_db(const char *pkgid,
                return APP2EXT_ERROR_SQLITE_REGISTRY;
        }
        sqlite3_free(query);
-       _D("sqlite insertion done");
 
        return APP2EXT_SUCCESS;
 }
@@ -116,9 +114,10 @@ int _app2sd_set_password_in_db(const char *pkgid,
 int _app2sd_remove_password_from_db(const char *pkgid)
 {
        char *error_message = NULL;
-       char *query = sqlite3_mprintf("delete from app2sd"
-               " where pkgid LIKE %Q", pkgid);
-       _D("deletion querys is (%s)", query);
+       char *query = NULL;
+
+       query = sqlite3_mprintf("delete from app2sd" \
+               " where pkgid=%Q", pkgid);
 
        if (SQLITE_OK != sqlite3_exec(app2sd_db, query, NULL,
                NULL, &error_message)) {
@@ -135,20 +134,19 @@ int _app2sd_remove_password_from_db(const char *pkgid)
 
 char *_app2sd_get_password_from_db(const char *pkgid)
 {
-       char query[MAX_QUERY_LEN] = { 0 };
-       sqlite3_stmt *stmt = NULL;
+       char *query = NULL;
+       char *passwd = NULL;
        const char *tail = NULL;
+       sqlite3_stmt *stmt = NULL;
        int rc = 0;
-       char *passwd = NULL;
 
-       sqlite3_snprintf(MAX_QUERY_LEN, query,
-               "select * from app2sd where pkgid LIKE '%s'", pkgid);
-       _D("access querys is (%s)", query);
+       query = sqlite3_mprintf("select * from app2sd" \
+               " where pkgid=%Q", pkgid);
 
        if (SQLITE_OK != sqlite3_prepare(app2sd_db, query,
                strlen(query), &stmt, &tail)) {
                _E("sqlite3_prepare error");
-
+               sqlite3_free(query);
                return NULL;
        }
 
@@ -163,7 +161,6 @@ char *_app2sd_get_password_from_db(const char *pkgid)
                goto FINISH_OFF;
        }
 
-       _D("entry available in sqlite");
        strncpy(passwd, (const char*)sqlite3_column_text(stmt, 1),
                PASSWORD_LENGTH);
        if (passwd == NULL) {
@@ -174,6 +171,7 @@ char *_app2sd_get_password_from_db(const char *pkgid)
                _E("error : sqlite3_finalize");
                goto FINISH_OFF;
        }
+       sqlite3_free(query);
 
        return passwd;
 
@@ -182,6 +180,7 @@ FINISH_OFF:
        if (rc != SQLITE_OK) {
                _E("sqlite3_finalize failed(%d)", rc);
        }
+       sqlite3_free(query);
 
        if (passwd)
                free(passwd);
index 83e415e..300f86b 100644 (file)
@@ -60,9 +60,9 @@ int _xsystem(const char *argv[])
        case 0:
                /* child */
                strerror_r(errno, err_buf, sizeof(err_buf));
-               if (execvp(argv[0], (char *const *)argv) < 0) {
-                       fprintf(stderr, "execvp failed %d....%s\n", errno, err_buf);    /*Don't use d_msg_app2sd */
-               }
+               if (execvp(argv[0], (char *const *)argv) < 0)
+                       fprintf(stderr, "execvp failed %d....%s\n",
+                               errno, err_buf);
                _exit(-1);
        default:
                /* parent */
@@ -611,9 +611,9 @@ char *_app2sd_find_free_device(void)
 */
 char *_app2sd_generate_password(const char *pkgid)
 {
-       char passwd[PASSWD_LEN+1] = { 0, };
+       char passwd[PASSWD_LEN + 1] = { 0, };
        char *ret_result = NULL;
-       char set[ASCII_PASSWD_CHAR+1] =
+       char set[ASCII_PASSWD_CHAR + 1] =
                "!\"#$%&()*+,-./0123456789:;<=>?@ABCDE" \
                "FGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
        unsigned char char_1;
@@ -646,3 +646,23 @@ char *_app2sd_generate_password(const char *pkgid)
 
        return ret_result;
 }
+
+char *_app2sd_get_encoded_name(const char *pkgid, uid_t uid)
+{
+       char *new_name = NULL;
+       char *temp_string = NULL;
+       char source_name[FILENAME_MAX] = { 0, };
+       GChecksum *checksum;
+
+       snprintf(source_name, FILENAME_MAX - 1, "%s_%d", pkgid, uid);
+       checksum = g_checksum_new(G_CHECKSUM_MD5);
+       g_checksum_update(checksum, (const guchar *)source_name, strlen(source_name));
+       temp_string = (char *)g_checksum_get_string(checksum);
+       _D("temp_string(%s)", temp_string);
+       new_name = strdup(temp_string);
+       g_checksum_free(checksum);
+
+       _D("new_name(%s)", new_name);
+
+       return new_name;
+}
index d73b5d7..4cfea99 100644 (file)
@@ -75,6 +75,7 @@ out:
        return ret;
 }
 
+/*
 static int __app2sd_get_sender_pid(GDBusConnection *conn,
                const char *sender_name)
 {
@@ -91,6 +92,7 @@ static int __app2sd_get_sender_pid(GDBusConnection *conn,
 
        return pid;
 }
+*/
 
 static int __app2sd_get_sender_uid(GDBusConnection *conn,
                const char *sender_name)
index e373184..156fd41 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <app2ext_interface.h>
 #include <errno.h>
+#include <unistd.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <dlfcn.h>