From 07713bf5e5048c40c7a86ae8de952df9a0baa9c3 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Sat, 11 Jun 2016 00:37:03 +0900 Subject: [PATCH] adjust app2sd-server capability remove smack labeling. - installer will set required labels using security api. sub change : refactor force_clean Change-Id: I7e75e20fff773ff79752ad5107186417615c9fd1 Signed-off-by: jongmyeongko --- common/inc/app2ext_utils.h | 3 + inc/app2ext_interface.h | 17 +++ packaging/app2sd.spec | 3 +- plugin/app2sd/CMakeLists.txt | 2 + plugin/app2sd/app2sd-server.service.in | 6 + plugin/app2sd/inc/app2sd_internals.h | 19 +-- plugin/app2sd/org.tizen.app2sd.service.in | 3 +- plugin/app2sd/src/app2sd_client_interface.c | 64 ++++++++ plugin/app2sd/src/app2sd_interface.c | 43 +----- plugin/app2sd/src/app2sd_internals.c | 223 ++++++++++++---------------- plugin/app2sd/src/app2sd_internals_utils.c | 2 +- plugin/app2sd/src/app2sd_server.c | 1 + src/app2ext_interface.c | 1 - 13 files changed, 195 insertions(+), 192 deletions(-) create mode 100644 plugin/app2sd/app2sd-server.service.in diff --git a/common/inc/app2ext_utils.h b/common/inc/app2ext_utils.h index f97d12b..8d77aa1 100644 --- a/common/inc/app2ext_utils.h +++ b/common/inc/app2ext_utils.h @@ -34,6 +34,7 @@ extern "C" { #include #include +#include #include #define _E(fmt, arg...) LOGE(fmt, ##arg) @@ -58,6 +59,8 @@ extern "C" { #define APP2SD_OBJECT_PATH "/org/tizen/app2sd" #define APP2SD_INTERFACE_NAME "org.tizen.app2sd" +#define DIR_PERMS (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) + int _is_global(uid_t uid); char *_app2sd_get_encoded_name(const char *pkgid, uid_t uid); diff --git a/inc/app2ext_interface.h b/inc/app2ext_interface.h index 77bea37..1e37c95 100644 --- a/inc/app2ext_interface.h +++ b/inc/app2ext_interface.h @@ -89,6 +89,23 @@ typedef enum app2ext_move_type_t { } app2ext_move_type; /** + * Enum for command type + * @see app2sd_move_installed_app() + */ +typedef enum app2sd_cmd_t { + APP2SD_PRE_INSTALL = 1, + APP2SD_POST_INSTALL, + APP2SD_PRE_UNINSTALL, + APP2SD_POST_UNINSTALL, + APP2SD_PRE_UPGRADE, + APP2SD_POST_UPGRADE, + APP2SD_APP_LAUNCH, + APP2SD_APP_TERMINATE, + APP2SD_MOVE_APP_TO_MMC, + APP2SD_MOVE_APP_TO_PHONE +} app2sd_cmd; + +/** * Enum for error codes */ typedef enum app2ext_error_t { diff --git a/packaging/app2sd.spec b/packaging/app2sd.spec index f07a373..d6ff491 100644 --- a/packaging/app2sd.spec +++ b/packaging/app2sd.spec @@ -40,7 +40,7 @@ Tizen application installation on external memory (test) %setup -q %build -%cmake . +%cmake . -DUNITDIR=%{_unitdir} make %{?jobs:-j%jobs} @@ -61,6 +61,7 @@ cp LICENSE %{buildroot}/usr/share/license/%{name} %{_libdir}/libapp2ext.so.* %{_libdir}/libapp2sd.so* %{_bindir}/app2sd-server +%{_unitdir}/app2sd-server.service %{_datadir}/dbus-1/system-services/org.tizen.app2sd.service %config %{_sysconfdir}/dbus-1/system.d/org.tizen.app2sd.conf /usr/share/license/%{name} diff --git a/plugin/app2sd/CMakeLists.txt b/plugin/app2sd/CMakeLists.txt index eb0866f..1545c32 100644 --- a/plugin/app2sd/CMakeLists.txt +++ b/plugin/app2sd/CMakeLists.txt @@ -62,9 +62,11 @@ TARGET_LINK_LIBRARIES(${APP2SD_SERVER} app2sd ${pkgs_LDFLAGS}) CONFIGURE_FILE(org.tizen.app2sd.service.in org.tizen.app2sd.service @ONLY) CONFIGURE_FILE(org.tizen.app2sd.conf.in org.tizen.app2sd.conf @ONLY) +CONFIGURE_FILE(app2sd-server.service.in app2sd-server.service @ONLY) INSTALL(TARGETS ${APP2SD_SERVER} DESTINATION bin) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.tizen.app2sd.service DESTINATION ${PREFIX}/share/dbus-1/system-services/) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.tizen.app2sd.conf DESTINATION ${SYSCONF_INSTALL_DIR}/dbus-1/system.d/) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/app2sd-server.service DESTINATION ${UNITDIR}) diff --git a/plugin/app2sd/app2sd-server.service.in b/plugin/app2sd/app2sd-server.service.in new file mode 100644 index 0000000..5656b13 --- /dev/null +++ b/plugin/app2sd/app2sd-server.service.in @@ -0,0 +1,6 @@ +[Unit] +Description=app2sd server + +[Service] +ExecStart=@PREFIX@/bin/app2sd-server +CapabilityBoundingSet=~CAP_MAC_ADMIN diff --git a/plugin/app2sd/inc/app2sd_internals.h b/plugin/app2sd/inc/app2sd_internals.h index 1fa40cb..9c6dfe9 100644 --- a/plugin/app2sd/inc/app2sd_internals.h +++ b/plugin/app2sd/inc/app2sd_internals.h @@ -52,8 +52,6 @@ #include "app2sd_interface.h" -#define DIR_PERMS (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) - #define BUF_SIZE 256 #define MEM_BUF_SIZE 5 /*Memory buffer size in MB*/ #define PKG_BUF_SIZE 2 /*Memory buffer size in MB*/ @@ -72,19 +70,6 @@ typedef enum mount_type_t { MOUNT_TYPE_RW_REMOUNT } mount_type; -typedef enum app2sd_cmd_t { - APP2SD_PRE_INSTALL = 1, - APP2SD_POST_INSTALL, - APP2SD_PRE_UNINSTALL, - APP2SD_POST_UNINSTALL, - APP2SD_PRE_UPGRADE, - APP2SD_POST_UPGRADE, - APP2SD_APP_LAUNCH, - APP2SD_APP_TERMINATE, - APP2SD_MOVE_APP_TO_MMC, - APP2SD_MOVE_APP_TO_PHONE -} app2sd_cmd; - /*Checks whether mmc is present or not*/ int _app2sd_check_mmc_status(void); @@ -185,7 +170,7 @@ int _app2sd_remove_password_from_db(const char *pkgid); /* This functions saved password in db */ int _app2sd_set_password_in_db(const char *pkgid, const char *passwd); -/* This functions make result file */ -void _app2sd_make_result_info_file(char *pkgid, int size, uid_t uid); +int _app2sd_force_clean(const char *pkgid, const char *application_path, + const char *loopback_device); #endif diff --git a/plugin/app2sd/org.tizen.app2sd.service.in b/plugin/app2sd/org.tizen.app2sd.service.in index 10d7bce..86c3394 100644 --- a/plugin/app2sd/org.tizen.app2sd.service.in +++ b/plugin/app2sd/org.tizen.app2sd.service.in @@ -1,4 +1,5 @@ [D-BUS Service] User=root Name=org.tizen.app2sd -Exec=@PREFIX@/bin/app2sd-server +Exec=@PREFIX@/bin/false +SystemdService=app2sd-server.service diff --git a/plugin/app2sd/src/app2sd_client_interface.c b/plugin/app2sd/src/app2sd_client_interface.c index 2c31350..50cb569 100644 --- a/plugin/app2sd/src/app2sd_client_interface.c +++ b/plugin/app2sd/src/app2sd_client_interface.c @@ -21,6 +21,7 @@ * */ +#include #include #include #include @@ -110,6 +111,51 @@ static void __app2sd_create_dir_list_builder(gpointer data, gpointer user_data) g_variant_builder_add(builder, "(si)", item->name, item->type); } +static int __app2sd_create_default_directories(const char *pkgid, + app2sd_cmd cmd, uid_t uid) +{ + int ret = 0; + mode_t mode = DIR_PERMS; + char application_path[FILENAME_MAX] = { 0, }; + char application_mmc_path[FILENAME_MAX] = { 0, }; + + if (_is_global(uid)) { + snprintf(application_path, FILENAME_MAX - 1, "%s/%s", + tzplatform_getenv(TZ_SYS_RW_APP), pkgid); + } else { + tzplatform_set_user(uid); + snprintf(application_path, FILENAME_MAX - 1, "%s/%s", + tzplatform_getenv(TZ_USER_APP), pkgid); + tzplatform_reset_user(); + } + + ret = mkdir(application_path, mode); + if (ret) { + if (errno != EEXIST) { + _E("create directory failed," \ + " error no is (%d)", errno); + return APP2EXT_ERROR_CREATE_DIRECTORY; + } + } + + snprintf(application_mmc_path, FILENAME_MAX - 1, "%s/.mmc", + application_path); + + ret = mkdir(application_mmc_path, mode); + if (ret) { + if (errno != EEXIST) { + _E("create directory failed," \ + " error no is (%d)", errno); + return APP2EXT_ERROR_CREATE_DIRECTORY; + } + } + + if (cmd == APP2SD_PRE_UPGRADE) { + } + + return APP2EXT_SUCCESS; +} + int app2sd_client_usr_pre_app_install(const char *pkgid, GList* dir_list, int size, uid_t uid) { @@ -123,6 +169,11 @@ int app2sd_client_usr_pre_app_install(const char *pkgid, GList* dir_list, return APP2EXT_ERROR_INVALID_ARGUMENTS; } + ret = __app2sd_create_default_directories(pkgid, + APP2SD_PRE_INSTALL, uid); + if (ret) + return ret; + builder = g_variant_builder_new(G_VARIANT_TYPE("a(si)")); g_list_foreach(dir_list, __app2sd_create_dir_list_builder, builder); @@ -187,6 +238,11 @@ int app2sd_client_usr_pre_app_upgrade(const char *pkgid, GList* dir_list, return APP2EXT_ERROR_INVALID_ARGUMENTS; } + ret = __app2sd_create_default_directories(pkgid, + APP2SD_PRE_UPGRADE, uid); + if (ret) + return ret; + builder = g_variant_builder_new(G_VARIANT_TYPE("a(si)")); g_list_foreach(dir_list, __app2sd_create_dir_list_builder, builder); @@ -373,6 +429,7 @@ int app2sd_client_usr_move_installed_app(const char *pkgid, GList* dir_list, int ret = 0; GVariantBuilder *builder = NULL; GVariant *param = NULL; + app2sd_cmd cmd = APP2SD_MOVE_APP_TO_PHONE; /* validate the function parameter recieved */ if (pkgid == NULL || dir_list == NULL @@ -382,6 +439,13 @@ int app2sd_client_usr_move_installed_app(const char *pkgid, GList* dir_list, return APP2EXT_ERROR_INVALID_ARGUMENTS; } + if (move_type == APP2EXT_MOVE_TO_EXT) + cmd = APP2SD_MOVE_APP_TO_MMC; + + ret = __app2sd_create_default_directories(pkgid, cmd, uid); + if (ret) + return ret; + builder = g_variant_builder_new(G_VARIANT_TYPE("a(si)")); g_list_foreach(dir_list, __app2sd_create_dir_list_builder, builder); diff --git a/plugin/app2sd/src/app2sd_interface.c b/plugin/app2sd/src/app2sd_interface.c index 76e5462..d9b6dde 100644 --- a/plugin/app2sd/src/app2sd_interface.c +++ b/plugin/app2sd/src/app2sd_interface.c @@ -122,15 +122,6 @@ int app2sd_usr_pre_app_install(const char *pkgid, GList* dir_list, int size, uid /* create a loopback device */ ret = _app2sd_create_loopback_device(pkgid, loopback_device, (reqd_disk_size + PKG_BUF_SIZE)); - if (ret) { - _W("package already present, delete app directory"); - ret = _app2sd_delete_directory(application_path); - if (ret) { - _E("unable to delete the directory (%s)", - application_path); - return ret; - } - } /* perform loopback encryption setup */ device_node = _app2sd_do_loopback_encryption_setup(pkgid, @@ -291,7 +282,6 @@ int app2sd_usr_post_app_install(const char *pkgid, _E("unable to delete the password"); ret = _app2sd_delete_directory(application_path); - if (ret) _E("unable to delete the directory (%s)", application_path); } else { @@ -1030,36 +1020,7 @@ int app2sd_usr_force_clean(const char *pkgid, uid_t uid) } free(encoded_id); - /* unmount the loopback encrypted pseudo device from the application installation path */ - ret = _app2sd_unmount_app_content(application_path); - if (ret) { - _E("unable to unmount the app content (%d)", ret); - } - - /* detach the loopback encryption setup for the application */ - ret = _app2sd_remove_all_loopback_encryption_setups(pkgid); - if (ret) { - _E("unable to detach the loopback encryption setup for the application"); - } + ret = _app2sd_force_clean(pkgid, application_path, loopback_device); - /* delete the loopback device from the SD card */ - ret = _app2sd_delete_loopback_device(loopback_device); - if (ret) { - _E("unable to detach the loopback encryption setup for the application"); - } - - /* delete symlink */ - _app2sd_delete_symlink(application_path); - - /* remove passwrd from DB */ - ret = _app2sd_initialize_db(); - if (ret) { - _E("app2sd db initialize failed"); - } - ret = _app2sd_remove_password_from_db(pkgid); - if (ret) { - _E("cannot remove password from db"); - } - - return 0; + return ret; } diff --git a/plugin/app2sd/src/app2sd_internals.c b/plugin/app2sd/src/app2sd_internals.c index 1816e58..82e38cb 100644 --- a/plugin/app2sd/src/app2sd_internals.c +++ b/plugin/app2sd/src/app2sd_internals.c @@ -28,83 +28,59 @@ #include "app2sd_internals.h" -static int _app2sd_setup_path(const char* path, const char *label, uid_t uid) +static int _app2sd_make_directory(const char* path, uid_t uid) { - int ret = APP2EXT_SUCCESS; + int ret = 0; + int fd = -1; + mode_t mode = DIR_PERMS; struct passwd pwd; struct passwd *pwd_result; char buf[1024] = { 0, }; - int fd; - fd = open(path, O_RDONLY); + ret = _app2sd_delete_directory(path); + if (ret) { + _E("unable to delete (%s)", path); + return APP2EXT_ERROR_DELETE_DIRECTORY; + } + + ret = getpwuid_r(uid, &pwd, buf, sizeof(buf), &pwd_result); + if (ret != 0 || pwd_result == NULL) { + _E("get uid failed(%d)", ret); + return APP2EXT_ERROR_ACCESS_FILE; + } + _D("uid(%d), gid(%d)", uid, pwd.pw_gid); + + /* create directory */ + ret = mkdir(path, mode); + if (ret) { + if (errno != EEXIST) { + _E("create directory failed," \ + " error no is (%d)", errno); + return APP2EXT_ERROR_CREATE_DIRECTORY; + } + } + + fd = open(path, O_RDONLY|O_DIRECTORY); if (fd < 0) { _E("can't open path(%s)", path); return APP2EXT_ERROR_OPEN_DIR; } + ret = fchmod(fd, 0755); if (ret < 0) { _E("change file permission error"); close(fd); return APP2EXT_ERROR_ACCESS_FILE; } - close(fd); - ret = lsetxattr(path, "security.SMACK64TRANSMUTE", "TRUE", 4, 0); - if (ret < 0) { - _E("set transmute error"); - return APP2EXT_ERROR_ACCESS_FILE; - } - ret = lsetxattr(path, "security.SMACK64", label, strlen(label), 0); - if (ret < 0) { - _E("set label(%s) error", label); - return APP2EXT_ERROR_ACCESS_FILE; - } - - ret = getpwuid_r(uid, &pwd, buf, sizeof(buf), &pwd_result); - if (ret != 0 || pwd_result == NULL) { - _E("get uid failed(%d)", ret); - return APP2EXT_ERROR_ACCESS_FILE; - } - - _D("uid(%d), gid(%d)", uid, pwd.pw_gid); - ret = chown(path, uid, pwd.pw_gid); + ret = fchown(fd, uid, pwd.pw_gid); if (ret < 0) { _E("change file owner error"); + close(fd); return APP2EXT_ERROR_ACCESS_FILE; } - return ret; -} - -static int _app2sd_apply_app_smack(const char *application_path, - const char *pkgid, GList* dir_list, uid_t uid) -{ - int ret = APP2EXT_SUCCESS; - GList *list = NULL; - app2ext_dir_details* dir_detail = NULL; - char temp_dir_path[FILENAME_MAX] = { 0, }; - char label[FILENAME_MAX] = { 0, }; - - snprintf(label, FILENAME_MAX, "User::Pkg::%s::RO", pkgid); - list = g_list_first(dir_list); - while (list) { - dir_detail = (app2ext_dir_details *)list->data; - if (dir_detail && dir_detail->name - && dir_detail->type == APP2EXT_DIR_RO) { - memset(temp_dir_path, '\0', FILENAME_MAX); - snprintf(temp_dir_path, FILENAME_MAX, - "%s/%s", application_path, - dir_detail->name); - _D("set label(%s) to path(%s)", - label, temp_dir_path); - ret = _app2sd_setup_path(temp_dir_path, /* label */ "*", uid); - if (ret) { - _E("unable to smack (%s)", label); - return APP2EXT_ERROR_MOVE; - } - } - list = g_list_next(list); - } + close(fd); return APP2EXT_SUCCESS; } @@ -307,7 +283,6 @@ char *_app2sd_do_loopback_duplicate_encryption_setup(const char *pkgid, return NULL; } } - } /* get free device node*/ @@ -427,7 +402,7 @@ int _app2sd_create_loopback_device(const char *pkgid, { "dd", "if=/dev/zero", command, "bs=1M", buff, NULL }; if ((fp = fopen(loopback_device, "r+")) != NULL) { - _E("encrypted file already exists (%s)", + _W("encrypted file already exists (%s)", loopback_device); fclose(fp); return APP2EXT_ERROR_PKG_EXISTS; @@ -492,25 +467,19 @@ int _app2sd_create_file_system(const char *device_path) static int _app2sd_create_dir_with_link(const char *application_path, const char *pkgid, const char *dir_name, uid_t uid) { - mode_t mode = DIR_PERMS; int ret = APP2EXT_SUCCESS; char application_dir_mmc_path[FILENAME_MAX] = { 0, }; char application_dir_path[FILENAME_MAX] = { 0, }; - char label[FILENAME_MAX] = { 0, }; snprintf(application_dir_mmc_path, FILENAME_MAX - 1, "%s/.mmc/%s", application_path, dir_name); snprintf(application_dir_path, FILENAME_MAX, "%s/%s", application_path, dir_name); - snprintf(label, FILENAME_MAX, "User::Pkg::%s::RO", pkgid); - ret = mkdir(application_dir_mmc_path, mode); + ret = _app2sd_make_directory(application_dir_mmc_path, uid); if (ret) { - if (errno != EEXIST) { - _E("create directory failed," \ - " error no is (%d)", errno); - return APP2EXT_ERROR_CREATE_DIRECTORY; - } + _E("create directory failed"); + return APP2EXT_ERROR_CREATE_DIRECTORY; } if ((ret = symlink(application_dir_mmc_path, @@ -525,19 +494,7 @@ static int _app2sd_create_dir_with_link(const char *application_path, } } - ret = _app2sd_setup_path(application_dir_path, /* label */ "*", uid); - if (ret) { - _E ("unable to smack (%s)", application_dir_path); - return APP2EXT_ERROR_MOVE; - } - - ret = _app2sd_setup_path(application_dir_mmc_path, /* label */ "*", uid); - if (ret) { - _E ("unable to smack (%s)", application_dir_mmc_path); - return APP2EXT_ERROR_MOVE; - } - - return ret; + return APP2EXT_SUCCESS; } static int _app2sd_create_directory_entry(const char *application_path, @@ -568,10 +525,9 @@ int _app2sd_mount_app_content(const char *application_path, const char *pkgid, app2sd_cmd cmd, uid_t uid) { int ret = APP2EXT_SUCCESS; - mode_t mode = DIR_PERMS; + int fd = -1; char application_mmc_path[FILENAME_MAX] = { 0, }; char temp_path[FILENAME_MAX] = { 0, }; - char label[FILENAME_MAX] = { 0, }; struct timespec time = { .tv_sec = 0, .tv_nsec = 1000 * 1000 * 200 @@ -583,38 +539,22 @@ int _app2sd_mount_app_content(const char *application_path, const char *pkgid, return APP2EXT_ERROR_INVALID_ARGUMENTS; } - ret = mkdir(application_path, mode); - if (ret) { - if (errno != EEXIST) { - _E("create directory failed," \ - " error no is (%d)", errno); - return APP2EXT_ERROR_CREATE_DIRECTORY; - } - } else { - ret = _app2sd_setup_path(application_path, "*", uid); - if (ret) { - _E ("unable to smack (%s)", application_path); - return APP2EXT_ERROR_ACCESS_FILE; - } + /* check directory existence */ + fd = open(application_path, O_RDONLY|O_DIRECTORY); + if (fd < 0) { + _E("path(%s) error(%d)", application_path, errno); + return APP2EXT_ERROR_OPEN_DIR; } + close(fd); snprintf(application_mmc_path, FILENAME_MAX - 1, "%s/.mmc", application_path); - ret = mkdir(application_mmc_path, mode); - if (ret) { - if (errno != EEXIST) { - _E("create directory failed," \ - " error no is (%d)", errno); - return APP2EXT_ERROR_CREATE_DIRECTORY; - } - } else { - snprintf(label, FILENAME_MAX, "User::Pkg::%s::RO", pkgid); - ret = _app2sd_setup_path(application_mmc_path, /* label */ "*", uid); - if (ret) { - _E ("unable to smack (%s)", application_mmc_path); - return APP2EXT_ERROR_ACCESS_FILE; - } + fd = open(application_mmc_path, O_RDONLY|O_DIRECTORY); + if (fd < 0) { + _E("path(%s) error(%d)", application_mmc_path, errno); + return APP2EXT_ERROR_OPEN_DIR; } + close(fd); nanosleep(&time, NULL); /* 200ms sleep */ _D("give a delay for mount"); @@ -673,7 +613,7 @@ int _app2sd_mount_app_content(const char *application_path, const char *pkgid, snprintf(temp_path, FILENAME_MAX - 1, "%s/lost+found", application_mmc_path); ret = _app2sd_delete_directory(temp_path); - if (ret && ret != APP2EXT_ERROR_ACCESS_FILE) { + if (ret) { _E("unable to delete (%s)", temp_path); return APP2EXT_ERROR_DELETE_DIRECTORY; } @@ -719,7 +659,7 @@ static int _app2sd_move_to_archive(const char *src_path, const char *arch_path) } ret = _app2sd_delete_directory((char *)src_path); - if (ret && ret != APP2EXT_ERROR_ACCESS_FILE) { + if (ret) { _E("unable to delete (%s)", src_path); return APP2EXT_ERROR_DELETE_DIRECTORY; } @@ -730,6 +670,7 @@ static int _app2sd_move_to_archive(const char *src_path, const char *arch_path) int _app2sd_move_app_to_external(const char *pkgid, GList* dir_list, uid_t uid) { int ret = APP2EXT_SUCCESS; + mode_t mode = DIR_PERMS; char temp_dir_path[FILENAME_MAX] = { 0, }; char application_mmc_path[FILENAME_MAX] = { 0, }; char application_archive_path[FILENAME_MAX] = { 0, }; @@ -740,7 +681,6 @@ int _app2sd_move_app_to_external(const char *pkgid, GList* dir_list, uid_t uid) int reqd_disk_size = 0; char *device_node = NULL; char *devi = NULL; - mode_t mode = DIR_PERMS; int free_mmc_mem = 0; FILE *fp = NULL; GList *list = NULL; @@ -778,15 +718,13 @@ int _app2sd_move_app_to_external(const char *pkgid, GList* dir_list, uid_t uid) _W("Already %s entry is present in the SD Card, " \ "delete entry and go on without return", pkgid); fclose(fp); - app2sd_usr_force_clean(pkgid, uid); + _app2sd_force_clean(pkgid, application_path, loopback_device); } snprintf(application_mmc_path, FILENAME_MAX - 1, "%s/.mmc", application_path); snprintf(application_archive_path, FILENAME_MAX - 1, "%s/.archive", application_path); - _D("application_mmc_path = (%s)", application_mmc_path); - _D("application_archive_path = (%s)", application_archive_path); ret = mkdir(application_archive_path, mode); if (ret) { @@ -929,13 +867,7 @@ int _app2sd_move_app_to_external(const char *pkgid, GList* dir_list, uid_t uid) } ret = _app2sd_delete_directory(temp_dir_path); if (ret) { - if (ret == APP2EXT_ERROR_ACCESS_FILE) { - _E("unable to access (%s)", - temp_dir_path); - } else { - _E("unable to delete (%s)", - temp_dir_path); - } + _E("unable to delete (%s)", temp_dir_path); return ret; } } @@ -948,12 +880,6 @@ int _app2sd_move_app_to_external(const char *pkgid, GList* dir_list, uid_t uid) return APP2EXT_ERROR_DELETE_DIRECTORY; } - ret = _app2sd_apply_app_smack(application_path, pkgid, dir_list, uid); - if (ret) { - _E("unable to apply app smack"); - return APP2EXT_ERROR_MOVE; - } - /* re-mount the loopback encrypted pseudo device on application installation path * as with Read Only permission */ @@ -1098,8 +1024,6 @@ int _app2sd_move_app_to_internal(const char *pkgid, GList* dir_list, uid_t uid) application_path); snprintf(application_archive_path, FILENAME_MAX - 1, "%s/.archive", application_path); - _D("application_mmc_path = (%s)", application_mmc_path); - _D("application_archive_path = (%s)", application_archive_path); ret = mkdir(application_archive_path, mode); if (ret) { @@ -1500,3 +1424,42 @@ FINISH_OFF: return err_res; } + +int _app2sd_force_clean(const char *pkgid, const char *application_path, + const char *loopback_device) +{ + int ret = APP2EXT_SUCCESS; + + /* unmount the loopback encrypted pseudo device from the application installation path */ + ret = _app2sd_unmount_app_content(application_path); + if (ret) { + _E("unable to unmount the app content (%d)", ret); + } + + /* detach the loopback encryption setup for the application */ + ret = _app2sd_remove_all_loopback_encryption_setups(loopback_device); + if (ret) { + _E("unable to detach the loopback encryption setup for the application"); + } + + /* delete the loopback device from the SD card */ + ret = _app2sd_delete_loopback_device(loopback_device); + if (ret) { + _E("unable to detach the loopback encryption setup for the application"); + } + + /* delete symlink */ + _app2sd_delete_symlink(application_path); + + /* remove passwrd from DB */ + ret = _app2sd_initialize_db(); + if (ret) { + _E("app2sd db initialize failed"); + } + ret = _app2sd_remove_password_from_db(pkgid); + if (ret) { + _E("cannot remove password from db"); + } + + return ret; +} diff --git a/plugin/app2sd/src/app2sd_internals_utils.c b/plugin/app2sd/src/app2sd_internals_utils.c index 9b51ca0..b48558a 100644 --- a/plugin/app2sd/src/app2sd_internals_utils.c +++ b/plugin/app2sd/src/app2sd_internals_utils.c @@ -177,7 +177,7 @@ int _app2sd_delete_directory(const char *dirname) if (ret <0) return -1; } else { - _E("couldn't open the directory[%s]", dirname); + _W("couldn't open the directory[%s]", dirname); } return 0; } diff --git a/plugin/app2sd/src/app2sd_server.c b/plugin/app2sd/src/app2sd_server.c index bb158c5..2188e6f 100644 --- a/plugin/app2sd/src/app2sd_server.c +++ b/plugin/app2sd/src/app2sd_server.c @@ -679,6 +679,7 @@ static void __app2sd_on_name_lost(GDBusConnection *connection, const gchar *name, gpointer user_data) { _E("name lost(%s)", name); + g_main_loop_quit(app2sd_mainloop); } static int __app2sd_server_init() diff --git a/src/app2ext_interface.c b/src/app2ext_interface.c index d2c914e..e0301f3 100644 --- a/src/app2ext_interface.c +++ b/src/app2ext_interface.c @@ -282,7 +282,6 @@ int app2ext_disable_external_pkg(const char *pkgid) int app2ext_usr_force_clean_pkg(const char *pkgid, uid_t uid) { - FILE *fp = NULL; app2ext_handle *app2_handle = NULL; /* validate the function parameter received */ -- 2.7.4