Correction in enabling permissions.
authorJan Olszak <j.olszak@samsung.com>
Fri, 4 Oct 2013 17:00:09 +0000 (19:00 +0200)
committerJan Olszak <j.olszak@samsung.com>
Fri, 18 Oct 2013 12:41:41 +0000 (14:41 +0200)
[Issue#]       SSDWSSP-183
[Bug/Feature]  WRT_platform ect. permissions added as WRT
[Cause]        N/A
[Solution]     Correction in enabling permissions.
[Verification] Build, install, run tests.

Change-Id: I9c7202615550da2d152c6909b773e4a7d12d0641

include/common.h
include/privilege-control.h
include/rules-db.h
src/common.c
src/privilege-control.c
src/rules-db.c

index f32030d..9edc72c 100644 (file)
@@ -27,6 +27,7 @@
 #include <fts.h>
 #include <stdbool.h>
 #include <sys/smack.h>
+#include "privilege-control.h"
 
 #ifdef LOG_TAG
     #undef LOG_TAG
@@ -109,9 +110,32 @@ int smack_mark_file_name(const char *app_id, char **path);
 bool file_exists(const char* path);
 int smack_file_name(const char* app_id, char** path);
 inline int have_smack(void);
+int base_name_from_perm(const char *perm, char **name);
 
 
 /**
+ * Get the permission family type name.
+ *
+ * @ingroup RDB internal functions
+ *
+ * @param  app_type type of the application
+ * @return          PC_OPERATION_SUCCESS on success,
+ *                  error code otherwise
+ */
+const char* app_type_name(app_type_t app_type);
+
+/**
+ * Get the permission type name
+ *
+ * @ingroup RDB internal functions
+ *
+ * @param  app_type type of the application
+ * @return          PC_OPERATION_SUCCESS on success,
+ *                  error code otherwise
+ */
+const char* app_type_group_name(app_type_t app_type);
+
+/**
  * Divide a Smack rule into subject, object and access
  *
  * @ingroup RDB internal functions
index 32862b3..192a5d9 100644 (file)
@@ -435,10 +435,6 @@ int perm_end(void);
 int perm_add_additional_rules(const char** set_smack_rule_set);
 
 
-int base_name_from_perm(const char *perm, char **name);
-
-
-
 #ifdef __cplusplus
 }
 #endif // __cplusplus
index 7f8cd1d..48dce5c 100644 (file)
@@ -132,16 +132,16 @@ int rdb_add_permission_rules(const char  *const s_permission_name,
  * @ingroup RDB API functions
  *
  * @param  s_app_label_name       application's label name
- * @param  s_permission_type_name permission's type name
+ * @param  i_permission_type      permission's type id
  * @param  pp_permissions_list    array of permissions to parse
  * @param  b_is_volatile          are the new permissions volatile
  * @return                        PC_OPERATION_SUCCESS on success,
  *                                error code otherwise
  */
 int rdb_enable_app_permissions(const char  *const s_app_label_name,
-                              const char  *const s_permission_type_name,
+                              const app_type_t i_permission_type,
                               const char *const *const pp_permissions_list,
-                              const bool   b_is_volatile);
+                              const bool b_is_volatile);
 
 
 /**
@@ -150,13 +150,13 @@ int rdb_enable_app_permissions(const char  *const s_app_label_name,
  * @ingroup RDB API functions
  *
  * @param  s_app_label_name       application's label name
- * @param  s_permission_type_name permission's type name
+ * @param  i_permission_type      permission's type id
  * @param  pp_permissions_list    array of permissions to parse
  * @return                        PC_OPERATION_SUCCESS on success,
  *                                error code otherwise
  */
 int rdb_disable_app_permissions(const char  *const s_app_label_name,
-                               const char  *const s_permission_type_name,
+                               const app_type_t i_permission_type,
                                const char *const *const pp_permissions_list);
 
 
index 43f6a0a..309b97b 100644 (file)
@@ -27,6 +27,7 @@
 #include <sys/smack.h>
 #include <sys/stat.h>
 #include <sys/file.h>
+#include <iri.h>
 
 #include "common.h"
 #include "privilege-control.h"
@@ -331,4 +332,115 @@ inline int have_smack(void)
        }
 
        return have_smack;
+}
+
+inline const char* app_type_name(app_type_t app_type)
+{
+       SECURE_C_LOGD("Entering function: %s. Params: app_type=%d",
+                               __func__, app_type);
+
+       switch (app_type) {
+       case PERM_APP_TYPE_WGT:
+               C_LOGD("App type = WRT");
+               return "WRT";
+       case PERM_APP_TYPE_OSP:
+               C_LOGD("App type = OSP");
+               return "OSP";
+       case PERM_APP_TYPE_WGT_PARTNER:
+               C_LOGD("App type = WRT_partner");
+               return "WRT_partner";
+       case PERM_APP_TYPE_WGT_PLATFORM:
+               C_LOGD("App type = WRT_platform");
+               return "WRT_platform";
+       case PERM_APP_TYPE_OSP_PARTNER:
+               C_LOGD("App type = OSP_partner");
+               return "OSP_partner";
+       case PERM_APP_TYPE_OSP_PLATFORM:
+               C_LOGD("App type = OSP_platform");
+               return "OSP_platform";
+       case PERM_APP_TYPE_EFL:
+               C_LOGD("App type = EFL");
+               return "EFL";
+       default:
+               C_LOGD("App type = other");
+               return NULL;
+       }
+}
+
+inline const char* app_type_group_name(app_type_t app_type)
+{
+       SECURE_C_LOGD("Entering function: %s. Params: app_type=%d",
+                               __func__, app_type);
+
+       switch (app_type) {
+       case PERM_APP_TYPE_WGT:
+       case PERM_APP_TYPE_WGT_PARTNER:
+       case PERM_APP_TYPE_WGT_PLATFORM:
+               C_LOGD("App type group name = WRT");
+               return "WRT";
+       case PERM_APP_TYPE_OSP:
+       case PERM_APP_TYPE_OSP_PARTNER:
+       case PERM_APP_TYPE_OSP_PLATFORM:
+               C_LOGD("App type group name = OST");
+               return "OSP";
+       case PERM_APP_TYPE_EFL:
+               C_LOGD("App type = EFL");
+               return "EFL";
+       default:
+               return NULL;
+       }
+}
+
+
+/**
+ * This function changes permission URI to basename for file name.
+ * For e.g. from http://tizen.org/privilege/contact.read will be
+ * created basename : org.tizen.privilege.contact.read
+ */
+
+int base_name_from_perm(const char *perm, char **name)
+{
+       SECURE_C_LOGD("Entering function: %s. Params: perm=%s",
+                               __func__, perm);
+
+       iri_t *ip = NULL;
+       char *host_dot = NULL;
+       char *rest_slash = NULL;
+       int ret;
+
+       ip = iri_parse(perm);
+       if (ip == NULL || ip->host == NULL) {
+               SECURE_C_LOGE("Bad permission format : %s", perm);
+               iri_destroy(ip);
+               return PC_ERR_INVALID_PARAM;
+       }
+
+       if (ip->path == NULL) {
+               ip->path = ip->host;
+               ip->host = NULL;
+       }
+
+       if (ip->host) {
+               host_dot = strrchr(ip->host, '.');
+               if (host_dot) {
+                       *host_dot = '\0';
+                       ++host_dot;
+               }
+       }
+
+       while ((rest_slash = strchr(ip->path, '/'))) {
+               *rest_slash = '.';
+       }
+
+       ret = asprintf(name, "%s%s%s%s",
+                       host_dot ? host_dot : "", host_dot ? "." : "",
+                       ip->host ? ip->host : "", ip->path);
+       if (ret == -1) {
+               C_LOGE("asprintf failed");
+               iri_destroy(ip);
+               return PC_ERR_MEM_OPERATION;
+       }
+
+       iri_destroy(ip);
+       return PC_OPERATION_SUCCESS;
 }
\ No newline at end of file
index 911a6fe..3a5a941 100644 (file)
@@ -41,7 +41,6 @@
 #include <sys/mman.h>
 #include <stdbool.h>
 #include <search.h>
-#include <iri.h>
 
 #include "privilege-control.h"
 #include "access-db.h"
@@ -619,116 +618,6 @@ API int set_privilege(const char* pkg_name)//deprecated
        return perm_app_set_privilege(pkg_name, NULL, NULL);
 }
 
-static inline const char* app_type_name(app_type_t app_type)
-{
-       SECURE_C_LOGD("Entering function: %s. Params: app_type=%d",
-                               __func__, app_type);
-
-       switch (app_type) {
-       case PERM_APP_TYPE_WGT:
-               C_LOGD("App type = WRT");
-               return "WRT";
-       case PERM_APP_TYPE_OSP:
-               C_LOGD("App type = OSP");
-               return "OSP";
-       case PERM_APP_TYPE_WGT_PARTNER:
-               C_LOGD("App type = WRT_partner");
-               return "WRT_partner";
-       case PERM_APP_TYPE_WGT_PLATFORM:
-               C_LOGD("App type = WRT_platform");
-               return "WRT_platform";
-       case PERM_APP_TYPE_OSP_PARTNER:
-               C_LOGD("App type = OSP_partner");
-               return "OSP_partner";
-       case PERM_APP_TYPE_OSP_PLATFORM:
-               C_LOGD("App type = OSP_platform");
-               return "OSP_platform";
-       case PERM_APP_TYPE_EFL:
-               C_LOGD("App type = EFL");
-               return "EFL";
-       default:
-               C_LOGD("App type = other");
-               return NULL;
-       }
-}
-
-static inline const char* app_type_group_name(app_type_t app_type)
-{
-       SECURE_C_LOGD("Entering function: %s. Params: app_type=%d",
-                               __func__, app_type);
-
-       switch (app_type) {
-       case PERM_APP_TYPE_WGT:
-       case PERM_APP_TYPE_WGT_PARTNER:
-       case PERM_APP_TYPE_WGT_PLATFORM:
-               C_LOGD("App type group name = WRT");
-               return "WRT";
-       case PERM_APP_TYPE_OSP:
-       case PERM_APP_TYPE_OSP_PARTNER:
-       case PERM_APP_TYPE_OSP_PLATFORM:
-               C_LOGD("App type group name = OST");
-               return "OSP";
-       case PERM_APP_TYPE_EFL:
-               C_LOGD("App type = EFL");
-               return "EFL";
-       default:
-               return NULL;
-       }
-}
-
-/**
- * This function changes permission URI to basename for file name.
- * For e.g. from http://tizen.org/privilege/contact.read will be
- * created basename : org.tizen.privilege.contact.read
- */
-
-int base_name_from_perm(const char *perm, char **name)
-{
-       SECURE_C_LOGD("Entering function: %s. Params: perm=%s",
-                               __func__, perm);
-
-       iri_t *ip = NULL;
-       char *host_dot = NULL;
-       char *rest_slash = NULL;
-       int ret;
-
-       ip = iri_parse(perm);
-       if (ip == NULL || ip->host == NULL) {
-               SECURE_C_LOGE("Bad permission format : %s", perm);
-               iri_destroy(ip);
-               return PC_ERR_INVALID_PARAM;
-       }
-
-       if (ip->path == NULL) {
-               ip->path = ip->host;
-               ip->host = NULL;
-       }
-
-       if (ip->host) {
-               host_dot = strrchr(ip->host, '.');
-               if (host_dot) {
-                       *host_dot = '\0';
-                       ++host_dot;
-               }
-       }
-
-       while ((rest_slash = strchr(ip->path, '/'))) {
-               *rest_slash = '.';
-       }
-
-       ret = asprintf(name, "%s%s%s%s",
-                       host_dot ? host_dot : "", host_dot ? "." : "",
-                       ip->host ? ip->host : "", ip->path);
-       if (ret == -1) {
-               C_LOGE("asprintf failed");
-               iri_destroy(ip);
-               return PC_ERR_MEM_OPERATION;
-       }
-
-       iri_destroy(ip);
-       return PC_OPERATION_SUCCESS;
-}
-
 static int perm_file_path(char** path, app_type_t app_type, const char* perm, const char *suffix, bool is_early)
 {
        SECURE_C_LOGD("Entering function: %s. Params: app_type=%d, perm=%s, suffix=%s, is_early=%d",
@@ -981,7 +870,7 @@ static int app_add_permissions_internal(const char* app_id, app_type_t app_type,
 
        // Enable the permissions:
        ret = rdb_enable_app_permissions(app_id,
-                                        app_type_group_name(app_type),
+                                        app_type,
                                         perm_list,
                                         !((bool)permanent));
        if (ret != PC_OPERATION_SUCCESS) {
@@ -1058,7 +947,7 @@ API int perm_app_disable_permissions(const char* pkg_id, app_type_t app_type, co
                return PC_ERR_INVALID_PARAM;
        }
 
-       ret = rdb_disable_app_permissions(pkg_id, app_type_group_name(app_type), perm_list);
+       ret = rdb_disable_app_permissions(pkg_id, app_type, perm_list);
        if (ret != PC_OPERATION_SUCCESS) {
                C_LOGE("RDB rdb_disable_app_permissions failed with: %d", ret);
                return ret;
index 6aa633b..538da8a 100644 (file)
@@ -270,18 +270,20 @@ finish:
 
 
 int rdb_enable_app_permissions(const char *const s_app_label_name,
-                              const char *const s_permission_type_name,
+                              const app_type_t i_permission_type,
                               const char *const *const pp_permissions_list,
                               const bool   b_is_volatile)
 {
-       RDB_LOG_ENTRY_PARAM("%s %s %d", s_app_label_name, s_permission_type_name,(int)b_is_volatile);
+       RDB_LOG_ENTRY_PARAM("%s %d %d", s_app_label_name, i_permission_type,(int)b_is_volatile);
 
        int ret = PC_ERR_DB_OPERATION;
        sqlite3 *p_db = NULL;
        char *s_permission_name = NULL;
        int i;
        int i_app_id = 0;
-       C_LOGD("RDB: Enabling permissions START");
+
+       const char* s_permission_type_name = app_type_name(i_permission_type);
+       const char* s_permission_group_type_name = app_type_group_name(i_permission_type);
 
        ret = rdb_begin(&p_db);
        if(ret != PC_OPERATION_SUCCESS) goto finish;
@@ -299,7 +301,7 @@ int rdb_enable_app_permissions(const char *const s_app_label_name,
        if(ret != PC_OPERATION_SUCCESS) goto finish;
 
        // Add permissions from the list:
-       for(i = 0; pp_permissions_list[i] != NULL ; ++i) {
+       for(i = 0; pp_permissions_list[i] != NULL; ++i) {
                // Ignore empty lines
                if(strspn(pp_permissions_list[i], " \t\n")
                    == strlen(pp_permissions_list[i]))
@@ -311,7 +313,7 @@ int rdb_enable_app_permissions(const char *const s_app_label_name,
                ret = change_app_permission_internal(p_db,
                                                     i_app_id,
                                                     s_permission_name,
-                                                    s_permission_type_name,
+                                                    s_permission_group_type_name,
                                                     b_is_volatile,
                                                     RDB_ENABLE);
                if(ret != PC_OPERATION_SUCCESS) goto finish;
@@ -326,15 +328,16 @@ finish:
 
 
 int rdb_disable_app_permissions(const char *const s_app_label_name,
-                               const char *const s_permission_type_name,
+                               const app_type_t i_permission_type,
                                const char *const *const pp_permissions_list)
 {
-       RDB_LOG_ENTRY_PARAM("%s %s", s_app_label_name, s_permission_type_name);
+       RDB_LOG_ENTRY_PARAM("%s %d", s_app_label_name, i_permission_type);
 
        int ret = PC_ERR_DB_OPERATION;
        sqlite3 *p_db = NULL;
        char *s_permission_name = NULL;
        int i, i_app_id;
+       const char* s_permission_group_type_name = app_type_group_name(i_permission_type);
 
        ret = rdb_begin(&p_db);
        if(ret != PC_OPERATION_SUCCESS) goto finish;
@@ -354,7 +357,7 @@ int rdb_disable_app_permissions(const char *const s_app_label_name,
                ret = switch_app_permission_internal(p_db,
                                                     i_app_id,
                                                     s_permission_name,
-                                                    s_permission_type_name,
+                                                    s_permission_group_type_name,
                                                     RDB_DISABLE);
                if(ret != PC_OPERATION_SUCCESS) goto finish;