Fix xattr 38/26738/1
authorJanusz Kozerski <j.kozerski@samsung.com>
Fri, 4 Jul 2014 09:46:03 +0000 (11:46 +0200)
committerJanusz Kozerski <j.kozerski@samsung.com>
Thu, 28 Aug 2014 11:28:58 +0000 (13:28 +0200)
Change-Id: I29a2ff60893852f402c2c32b710cfb119826b358
Signed-off-by: Janusz Kozerski <j.kozerski@samsung.com>
src/CMakeLists.txt
src/im-get-xattrs.c
src/im-main-menu.c

index 8b154e9..4217939 100644 (file)
@@ -13,6 +13,7 @@ SET(SRCS
     im-compromised-list.c
     im-load-policy.c
     im-get-policy.c
+    im-get-xattrs.c
     im-main-menu.c
     im-uigadget.c
 )
index e8539ed..5bde988 100644 (file)
@@ -26,7 +26,7 @@
 #include "im-uigadget.h"
 #include "im-get-xattrs.h"
 
-#define GET_XATTRS_DEFAULT_PATH   "/"
+#define GET_XATTRS_DEFAULT_PATH   "/root/ima-test/"
 #define MESSAGE_BEGIN            "IDS_ST_GET_XATTRS_MSG_BEGIN" // "Xattrs of:"
 #define MESSAGE_IMA              ":<br>security.ima: "
 #define MESSAGE_EVM              "<br>security.evm: "
@@ -43,9 +43,27 @@ void im_get_xattrs_cb (void *data, Evas_Object *obj, void *event_info)
     ad->file_action = im_get_xattrs_wrapper;
     ad->fileselector_default_path = GET_XATTRS_DEFAULT_PATH;
 
-    //show_file_selector(ad, dgettext(PACKAGE, FILE_SELECTOR_TITLE));
+    show_file_selector(ad, dgettext(PACKAGE, FILE_SELECTOR_TITLE));
     // FIXME: For testing:
-    im_get_xattrs_wrapper (ad, "/home/root/file");
+    //im_get_xattrs_wrapper (ad, "/home/root/file");
+}
+
+static void im_print_xattr (char* xattr, char** out)
+{
+    if (!xattr || !out)
+        return;
+
+    int i, j;
+    int len = strlen(xattr);
+    *out = calloc(sizeof(char), (len*2 + 1 ));
+
+    for (i = 0, j = 0; i < len; ++i) {
+        sprintf(&((*out)[j]), "%x", (unsigned char) xattr[i]);
+        if ((unsigned char) xattr[i] < 0x10)
+            j += 1;
+        else
+            j += 2;
+    }
 }
 
 int im_get_xattrs_wrapper (struct ug_data *ad, const char* const file_path)
@@ -53,21 +71,31 @@ int im_get_xattrs_wrapper (struct ug_data *ad, const char* const file_path)
     LOGD("Enter function: %s", __func__);
 
     int ret;
+    char* tmp = NULL;
     char* ima_xattr = NULL;
     char* evm_xattr = NULL;
 
-    ret = ima_get_xattr(file_path, &ima_xattr);
+    ret = ima_get_xattr(file_path, &tmp);
     if (ret != LIB_SUCCESS) {
         LOGE("ima_get_xattr (%s) failed (%d)", file_path, ret);
         goto out;
     }
-    ret = evm_get_xattr(file_path, &evm_xattr);
+    //LOGD("IMA xattr: %x", tmp);
+    im_print_xattr(tmp, &ima_xattr);
+    free(tmp);
+    tmp = NULL;
+
+    ret = evm_get_xattr(file_path, &tmp);
     if (ret != LIB_SUCCESS) {
         LOGE("evm_get_xattr (%s) failed (%d)", file_path, ret);
         goto out;
     }
+    //LOGD("EVM xattr: %x", tmp);
+    im_print_xattr(tmp, &evm_xattr);
+    free(tmp);
+    tmp = NULL;
 
-    size_t size =  strlen(dgettext(PACKAGE, IDS_ST_GET_XATTRS_MSG_BEGIN)) +
+    size_t size =  strlen(dgettext(PACKAGE, "IDS_ST_GET_XATTRS_MSG_BEGIN")) +
                    strlen(file_path)   +
                    strlen(MESSAGE_IMA) +
                    strlen(ima_xattr)   +
@@ -75,7 +103,7 @@ int im_get_xattrs_wrapper (struct ug_data *ad, const char* const file_path)
                    strlen(evm_xattr)   + 1;  // Use asprintf?
     ad->popup_content = malloc(sizeof(char) * size);  // One more char to add NULL at the end
     snprintf(ad->popup_content, size, "%s%s%s%s%s%s",
-            dgettext(PACKAGE, IDS_ST_GET_XATTRS_MSG_BEGIN),
+            dgettext(PACKAGE, "IDS_ST_GET_XATTRS_MSG_BEGIN"),
             file_path,
             MESSAGE_IMA,
             ima_xattr,
index 79d1272..e653ef2 100644 (file)
@@ -28,6 +28,7 @@
 #include "im-compromised-list.h"
 #include "im-load-policy.h"
 #include "im-get-policy.h"
+#include "im-get-xattrs.h"
 
 // FIXME: For testing/debug purpose only
 //        This flag cause that errors from libimaevm will be ignored.
@@ -545,7 +546,7 @@ void im_main_menu_cb(void *data, Evas_Object *obj, void *event_info)
     elm_object_item_domain_text_translatable_set(nf_it, PACKAGE, EINA_TRUE);
 
     nf_it = _add_genlist_item(genlist, ITC_TYPE_LIST, dgettext(PACKAGE, "IDS_ST_GET_FILE_XATTRS"),
-            NULL, im_check_file_cb, ad);
+            NULL, im_get_xattrs_cb, ad);
     elm_object_item_domain_text_translatable_set(nf_it, PACKAGE, EINA_TRUE);
 
     nf_it = elm_naviframe_item_push(ad->navi_bar, dgettext(PACKAGE, "IDS_ST_IMA_EVM_SETUP_MAIN"),