Enable libprivilege-control for target without smack module in kernel.
authorBartlomiej Grzelewski <b.grzelewski@samsung.com>
Fri, 15 Feb 2013 13:53:59 +0000 (14:53 +0100)
committerRafal Krypa <r.krypa@samsung.com>
Tue, 26 Mar 2013 10:37:33 +0000 (11:37 +0100)
[Issue#]       N/A
[Feature]      N/A
[Cause]        N/A
[Solution]     Added check if smack is supported in kernel.
[Verification] Compile, install, reboot target

Change-Id: I28bbcbe162e32a55c72c24a12c782ed269183cd8

src/privilege-control.c

index 028bb8b..52b261b 100644 (file)
@@ -90,6 +90,26 @@ static int set_smack_for_wrt(const char* widget_id);
 #endif //DLOG_ERROR_ENABLED
 
 
+static int nosmack = -1;
+
+#define IFNOSMACK(ret)                                               \
+do {                                                                 \
+    if (-1 == nosmack) {                                             \
+        int fd = open("/smack/load2", O_WRONLY);                     \
+        if (-1 == fd) {                                              \
+            C_LOGD("Libprivilage-control: no smack found on phone"); \
+            nosmack = 1;                                             \
+        } else {                                                     \
+            C_LOGD("Libprivilege-control: found smack on phone");    \
+            close(fd);                                               \
+            nosmack = 0;                                             \
+        }                                                            \
+    }                                                                \
+    if (1 == nosmack) {                                              \
+        return (ret);                                                \
+    }                                                                \
+} while(0)
+
 typedef enum {
        APP_TYPE_WGT,
        APP_TYPE_OTHER,
@@ -106,7 +126,7 @@ typedef struct {
 API int control_privilege(void)
 {
        C_LOGD("Enter function: %s", __func__);
-       if(getuid() == APP_UID) // current user is 'app'
+    if(getuid() == APP_UID)    // current user is 'app'
                return PC_OPERATION_SUCCESS;
 
        if(set_app_privilege("com.samsung.", NULL, NULL) == PC_OPERATION_SUCCESS)
@@ -377,8 +397,9 @@ static const char* parse_widget_id(const char* path)
 
 API int set_app_privilege(const char* name, const char* type, const char* path)
 {
-       C_LOGD("Enter function: %s", __func__);
+    C_LOGD("Enter function: %s", __func__);
        C_LOGD("Function params: name = %s, type = %s, path = %s", name, type, path);
+    IFNOSMACK(set_dac(name));
 #ifdef SMACK_ENABLED
        const char* widget_id;
        int ret = PC_OPERATION_SUCCESS;
@@ -409,7 +430,7 @@ API int set_app_privilege(const char* name, const char* type, const char* path)
 
 API int set_privilege(const char* pkg_name)
 {
-       C_LOGD("Enter function: %s", __func__);
+    C_LOGD("Enter function: %s", __func__);
        return set_app_privilege(pkg_name, NULL, NULL);
 }
 
@@ -541,7 +562,8 @@ static int set_smack_for_wrt(const char* widget_id)
 
 API char* app_id_from_socket(int sockfd)
 {
-       C_LOGD("Enter function: %s", __func__);
+    C_LOGD("Enter function: %s", __func__);
+    IFNOSMACK(PC_OPERATION_SUCCESS);
 #ifdef SMACK_ENABLED
        char* app_id;
        int ret;
@@ -654,13 +676,15 @@ out:
 
 API int app_add_permissions(const char* app_id, const char** perm_list)
 {
-       C_LOGD("Enter function: %s", __func__);
+    C_LOGD("Enter function: %s", __func__);
+    IFNOSMACK(PC_OPERATION_SUCCESS);
        return app_add_permissions_internal(app_id, perm_list, 1);
 }
 
 API int app_add_volatile_permissions(const char* app_id, const char** perm_list)
 {
-       C_LOGD("Enter function: %s", __func__);
+    C_LOGD("Enter function: %s", __func__);
+    IFNOSMACK(PC_OPERATION_SUCCESS);
        return app_add_permissions_internal(app_id, perm_list, 0);
 }
 
@@ -713,13 +737,15 @@ out:
 
 API int app_revoke_permissions(const char* app_id)
 {
-       C_LOGD("Enter function: %s", __func__);
+    C_LOGD("Enter function: %s", __func__);
+    IFNOSMACK(PC_OPERATION_SUCCESS);
        return app_revoke_permissions_internal(app_id, 1);
 }
 
 API int app_reset_permissions(const char* app_id)
 {
-       C_LOGD("Enter function: %s", __func__);
+    C_LOGD("Enter function: %s", __func__);
+    IFNOSMACK(PC_OPERATION_SUCCESS);
        int ret;
 
        ret = app_revoke_permissions_internal(app_id, 0);
@@ -734,7 +760,8 @@ API int app_reset_permissions(const char* app_id)
 
 API int app_label_dir(const char* label, const char* path)
 {
-       C_LOGD("Enter function: %s", __func__);
+    C_LOGD("Enter function: %s", __func__);
+    IFNOSMACK(PC_OPERATION_SUCCESS);
 #ifdef SMACK_ENABLED
 
        int ret = PC_OPERATION_SUCCESS;
@@ -761,6 +788,7 @@ API int app_label_dir(const char* label, const char* path)
 API int app_label_shared_dir(const char* app_label, const char* shared_label, const char* path)
 {
        C_LOGD("Enter function: %s", __func__);
+    IFNOSMACK(PC_OPERATION_SUCCESS);
 #ifdef SMACK_ENABLED
        char* smack_path = NULL;
        int ret;