Add posibility to check file xattrs (secutity.ima, security.evm) 35/26735/1
authorJanusz Kozerski <j.kozerski@samsung.com>
Wed, 4 Jun 2014 13:03:08 +0000 (15:03 +0200)
committerJanusz Kozerski <j.kozerski@samsung.com>
Thu, 28 Aug 2014 11:28:19 +0000 (13:28 +0200)
Change-Id: Idbd6217e42e5bd1b9423e732d25a3e15ce664e93
Signed-off-by: Janusz Kozerski <j.kozerski@samsung.com>
include/im-get-xattrs.h [new file with mode: 0644]
po/en.po
po/en_US.po
src/im-get-xattrs.c [new file with mode: 0644]
src/im-main-menu.c

diff --git a/include/im-get-xattrs.h b/include/im-get-xattrs.h
new file mode 100644 (file)
index 0000000..e521b36
--- /dev/null
@@ -0,0 +1,31 @@
+/**
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/*
+ * @file        im-get-xattrs.h
+ * @author      Janusz Kozerski (j.kozerski@samsung.com)
+ * @version     1.0
+ * @brief
+ */
+
+#ifndef __IM_GET_XATTRS_H__
+#define __IM_GET_XATTRS_H__
+
+#include "im-uigadget.h"
+
+void im_get_xattrs_cb (void *data, Evas_Object *obj, void *event_info);
+int  im_get_xattrs_wrapper (struct ug_data *ad, const char* const file_path);
+
+#endif /* __IM_GET_XATTRS_H__ */
index 8605010..d5eb8f9 100644 (file)
--- a/po/en.po
+++ b/po/en.po
@@ -58,6 +58,12 @@ msgstr "Get policy from kernel"
 msgid "IDS_ST_CHECK_FILE_STATE"
 msgstr "Check file state"
 
+msgid "IDS_ST_GET_FILE_XATTRS"
+msgstr "Get xattrs of file"
+
+msgid "IDS_ST_GET_XATTRS_MSG_BEGIN"
+msgstr "Xattrs of "
+
 msgid "IDS_ST_IMA_EVM_SETUP_MAIN"
 msgstr "IMA/EVM Setup"
 
index 8605010..d5eb8f9 100644 (file)
@@ -58,6 +58,12 @@ msgstr "Get policy from kernel"
 msgid "IDS_ST_CHECK_FILE_STATE"
 msgstr "Check file state"
 
+msgid "IDS_ST_GET_FILE_XATTRS"
+msgstr "Get xattrs of file"
+
+msgid "IDS_ST_GET_XATTRS_MSG_BEGIN"
+msgstr "Xattrs of "
+
 msgid "IDS_ST_IMA_EVM_SETUP_MAIN"
 msgstr "IMA/EVM Setup"
 
diff --git a/src/im-get-xattrs.c b/src/im-get-xattrs.c
new file mode 100644 (file)
index 0000000..0170742
--- /dev/null
@@ -0,0 +1,90 @@
+/**
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/*
+ * @file        im-get-xattrs.c
+ * @author      Janusz Kozerski (j.kozerski@samsung.com)
+ * @version     1.0
+ * @brief
+ */
+
+#include <imaevm.h>
+
+#include "im-common.h"
+#include "im-uigadget.h"
+#include "im-get-xattrs.h"
+
+#define GET_XATTRS_DEFAULT_PATH   "/"
+#define MESSAGE_BEGIN            "IDS_ST_GET_XATTRS_MSG_BEGIN" // "Xattrs of:"
+#define MESSAGE_IMA              ":<br>security.ima: "
+#define MESSAGE_EVM              "<br>security.evm: "
+#define FILE_SELECTOR_TITLE      "IDS_ST_GET_XATTRS_TITLE"
+
+void im_get_xattrs_cb (void *data, Evas_Object *obj, void *event_info)
+{
+    LOGD("Enter function: %s", __func__);
+    // Unused param warning
+    (void)obj;
+    (void)event_info;
+
+    struct ug_data *ad = (struct ug_data*) data;
+    ad->file_action = im_get_xattrs_wrapper;
+    ad->fileselector_default_path = GET_XATTRS_DEFAULT_PATH;
+
+    show_file_selector(ad, dgettext(PACKAGE, FILE_SELECTOR_TITLE));
+}
+
+int im_get_xattrs_wrapper (struct ug_data *ad, const char* const file_path)
+{
+    LOGD("Enter function: %s", __func__);
+
+    int ret;
+    char* ima_xattr = NULL;
+    char* evm_xattr = NULL;
+
+    ret = ima_get_xattr(file_path, &ima_xattr);
+    if (ret != LIB_SUCCESS) {
+        LOGE("ima_get_xattr (%s) failed (%d)", file_path, ret);
+        goto out;
+    }
+    ret = evm_get_xattr(file_path, &evm_xattr);
+    if (ret != LIB_SUCCESS) {
+        LOGE("evm_get_xattr (%s) failed (%d)", file_path, ret);
+        goto out;
+    }
+
+    size_t size =  strlen(dgettext(PACKAGE, IDS_ST_GET_XATTRS_MSG_BEGIN)) +
+                   strlen(file_path)   +
+                   strlen(MESSAGE_IMA) +
+                   strlen(ima_xattr)   +
+                   strlen(MESSAGE_EVM) +
+                   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),
+            file_path,
+            MESSAGE_IMA,
+            ima_xattr,
+            MESSAGE_EVM,
+            evm_xattr);
+    ad->popup_content[size-1] = '\0';
+
+    create_ok_popup(ad);
+
+out:
+    free(ima_xattr);
+    free(evm_xattr);
+    return 0;
+}
index a326c69..78863c3 100644 (file)
@@ -543,6 +543,10 @@ void im_main_menu_cb(void *data, Evas_Object *obj, void *event_info)
             NULL, im_check_file_cb, ad);
     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);
+    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"),
             NULL, NULL, genlist, NULL);
     elm_object_item_domain_text_translatable_set(nf_it, PACKAGE, EINA_TRUE);