add smack label to app2sd
authorjunsuk77.oh <junsuk77.oh@samsung.com>
Tue, 16 Jul 2013 08:19:03 +0000 (17:19 +0900)
committerAnas Nashif <anas.nashif@intel.com>
Wed, 25 Sep 2013 03:57:58 +0000 (23:57 -0400)
Change-Id: I2617aff6941abc3f10f002bcfd2d8342ad13e725
Signed-off-by: junsuk77.oh <junsuk77.oh@samsung.com>
packaging/app2sd.spec
plugin/app2sd/inc/app2sd_internals.h
plugin/app2sd/src/app2sd_internals.c
plugin/app2sd/src/app2sd_internals_utils.c

index a9d9205..980adc6 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       app2sd
 Summary:    Application installation on external memory
-Version:    0.5.21
+Version:    0.5.22
 Release:    1
 Group:      Application Framework/Application Installer
 License:    Apache-2.0
index c81ca7c..b2e1a91 100755 (executable)
@@ -180,4 +180,8 @@ int _app2sd_remove_password_from_db(const char *pkgid);
 int _app2sd_set_password_in_db(const char *pkgid,
                                      const char *passwd);
 
+/* This functions setup path for smack */
+int _app2sd_setup_path(const char *pkgid, const char *dirpath,
+                                               int apppathtype, const char *groupid);
+
 #endif
index 9aba3fb..8ba3f46 100755 (executable)
 /*
 ########### Internal APIs ##################
  */
+enum path_type {
+       PATH_PRIVATE,
+       PATH_GROUP_RW,
+       PATH_PUBLIC_RO,
+       PATH_SETTINGS_RW,
+       PATH_ANY_LABEL
+};
+
+static int _app2sd_apply_app_smack(const char *pkgid, GList* dir_list, const char *groupid)
+{
+       int ret = APP2EXT_SUCCESS;
+       GList *list = NULL;
+       app2ext_dir_details* dir_detail = NULL;
+       char path[FILENAME_MAX] = { 0, };
+
+       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) {
+                       snprintf(path, FILENAME_MAX, "%s%s/%s",APP_INSTALLATION_PATH, pkgid, dir_detail->name);
+                       ret = _app2sd_setup_path(pkgid, path, PATH_ANY_LABEL, groupid);
+                       if (ret) {
+                               app2ext_print ("App2Sd Error : unable to smack %s\n", path);
+                               return APP2EXT_ERROR_MOVE;
+                       }
+               }
+               list = g_list_next(list);
+       }
+
+       return APP2EXT_SUCCESS;
+}
+
+static int _app2sd_apply_mmc_smack(const char *pkgid, GList* dir_list, const char *groupid)
+{
+       int ret = APP2EXT_SUCCESS;
+       GList *list = NULL;
+       app2ext_dir_details* dir_detail = NULL;
+       char path[FILENAME_MAX] = { 0, };
+
+       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) {
+                       snprintf(path, FILENAME_MAX, "%s%s/.mmc/%s",APP_INSTALLATION_PATH, pkgid, dir_detail->name);
+
+                       ret = _app2sd_setup_path(pkgid, path, PATH_ANY_LABEL, groupid);
+                       if (ret) {
+                               app2ext_print ("App2Sd Error : unable to smack %s\n", path);
+                               return APP2EXT_ERROR_MOVE;
+                       }
+               }
+               list = g_list_next(list);
+       }
+
+       return APP2EXT_SUCCESS;
+}
 
 char *_app2sd_find_associated_device_node(const char *pkgid)
 {
@@ -431,6 +489,12 @@ static int _app2sd_create_dir_with_link(const char *pkgid,
                }
        }
 
+       ret = _app2sd_setup_path(pkgid, app_dir_path, PATH_ANY_LABEL, pkgid);
+       if (ret) {
+               app2ext_print ("App2Sd Error : unable to smack %s\n", app_dir_mmc_path);
+               return APP2EXT_ERROR_MOVE;
+       }
+
        return ret;
 }
 
@@ -834,6 +898,13 @@ int _app2sd_move_app_to_external(const char *pkgid, GList* dir_list)
                     app_archive_path);
                return APP2EXT_ERROR_DELETE_DIRECTORY;
        }
+
+       ret = _app2sd_apply_mmc_smack(pkgid, dir_list, pkgid);
+       if (ret) {
+               app2ext_print("App2Sd Error : unable to apply app smack\n");
+               return APP2EXT_ERROR_MOVE;
+       }
+
        /*Restore archive ends */
        /*Re-mount the loopback encrypted pseudo device on application installation path as with Read Only permission */
        ret = _app2sd_unmount_app_content(pkgid);
@@ -1064,6 +1135,13 @@ int _app2sd_move_app_to_internal(const char *pkgid, GList* dir_list)
                     app_archive_path);
                return APP2EXT_ERROR_DELETE_DIRECTORY;
        }
+
+       ret = _app2sd_apply_app_smack(pkgid, dir_list, pkgid);
+       if (ret) {
+               app2ext_print("App2Sd Error : unable to apply app smack\n");
+               return APP2EXT_ERROR_MOVE;
+       }
+
        return APP2EXT_SUCCESS;
 }
 
index de537a3..38562ed 100755 (executable)
 #include <dlog.h>
 #include <sys/statvfs.h>
 #include <errno.h>
+#include <dlfcn.h>
 
 #define        PASSWD_LEN              8
 #define        ASCII_PASSWD_CHAR       93
+#define LIB_PRIVILEGE_CONTROL          "libprivilege-control.so.0"
 
 /*
 ########### Internal APIs ##################
@@ -508,3 +510,47 @@ char *_app2sd_generate_password(const char *pkgid)
        memcpy(ret_result, passwd, PASSWD_LEN+1);
        return ret_result;
 }
+
+/*@_app2sd_setup_path
+* change smack label given groupid
+* return: On success, it will return the password, else NULL.
+*/
+int _app2sd_setup_path(const char *pkgid, const char *dirpath,
+                                               int apppathtype, const char *groupid)
+{
+       int ret = 0;
+       void *handle = NULL;
+       char *errmsg = NULL;
+       int (*app_setup_path)(const char*, const char*, int, ...) = NULL;
+
+       if (pkgid == NULL || dirpath == NULL)
+               return -1;
+
+       handle = dlopen(LIB_PRIVILEGE_CONTROL, RTLD_LAZY | RTLD_GLOBAL);
+       if (!handle) {
+               app2ext_print( "setup path: dlopen() failed. [%s]", dlerror());
+               return -1;
+       }
+
+       app_setup_path = dlsym(handle, "app_setup_path");
+       errmsg = dlerror();
+       if ((errmsg != NULL) || (app_setup_path == NULL)) {
+               app2ext_print( "setup path: dlsym() failed. [%s]", errmsg);
+               dlclose(handle);
+               return -1;
+       }
+
+       if (groupid == NULL) {
+               app2ext_print( "[smack] app_setup_path(%s, %s, %d)", pkgid, dirpath, apppathtype);
+               ret = app_setup_path(pkgid, dirpath, apppathtype);
+               app2ext_print( "[smack] app_setup_path(), result = [%d]", ret);
+       } else {
+               app2ext_print( "[smack] app_setup_path(%s, %s, %d, %s)", pkgid, dirpath, apppathtype, groupid);
+               ret = app_setup_path(pkgid, dirpath, apppathtype, groupid);
+               app2ext_print( "[smack] app_setup_path(), result = [%d]", ret);
+       }
+
+       dlclose(handle);
+       return ret;
+}
+