2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file im-get-xattrs.c
18 * @author Janusz Kozerski (j.kozerski@samsung.com)
25 #include "im-common.h"
26 #include "im-uigadget.h"
27 #include "im-get-xattrs.h"
29 #define GET_XATTRS_DEFAULT_PATH "/root/ima-test/"
30 #define MESSAGE_BEGIN "IDS_ST_GET_XATTRS_MSG_BEGIN" // "Xattrs of:"
31 #define MESSAGE_IMA ":<br>security.ima: "
32 #define MESSAGE_EVM "<br>security.evm: "
33 #define FILE_SELECTOR_TITLE "IDS_ST_GET_XATTRS_TITLE"
35 void im_get_xattrs_cb (void *data, Evas_Object *obj, void *event_info)
37 LOGD("Enter function: %s", __func__);
38 // Unused param warning
42 struct ug_data *ad = (struct ug_data*) data;
43 ad->file_action = im_get_xattrs_wrapper;
44 ad->fileselector_default_path = GET_XATTRS_DEFAULT_PATH;
46 show_file_selector(ad, dgettext(PACKAGE, FILE_SELECTOR_TITLE));
47 // FIXME: For testing:
48 //im_get_xattrs_wrapper (ad, "/home/root/file");
51 static void im_print_xattr (char* xattr, char** out)
57 int len = strlen(xattr);
58 *out = calloc(sizeof(char), (len*2 + 1 ));
60 for (i = 0, j = 0; i < len; ++i) {
61 sprintf(&((*out)[j]), "%x", (unsigned char) xattr[i]);
62 if ((unsigned char) xattr[i] < 0x10)
69 int im_get_xattrs_wrapper (struct ug_data *ad, const char* const file_path)
71 LOGD("Enter function: %s", __func__);
75 char* ima_xattr = NULL;
76 char* evm_xattr = NULL;
78 ret = ima_get_xattr(file_path, &tmp);
79 if (ret != LIB_SUCCESS) {
80 LOGE("ima_get_xattr (%s) failed (%d)", file_path, ret);
83 //LOGD("IMA xattr: %x", tmp);
84 im_print_xattr(tmp, &ima_xattr);
88 ret = evm_get_xattr(file_path, &tmp);
89 if (ret != LIB_SUCCESS) {
90 LOGE("evm_get_xattr (%s) failed (%d)", file_path, ret);
93 //LOGD("EVM xattr: %x", tmp);
94 im_print_xattr(tmp, &evm_xattr);
98 size_t size = strlen(dgettext(PACKAGE, "IDS_ST_GET_XATTRS_MSG_BEGIN")) +
100 strlen(MESSAGE_IMA) +
102 strlen(MESSAGE_EVM) +
103 strlen(evm_xattr) + 1; // Use asprintf?
104 ad->popup_content = malloc(sizeof(char) * size); // One more char to add NULL at the end
105 snprintf(ad->popup_content, size, "%s%s%s%s%s%s",
106 dgettext(PACKAGE, "IDS_ST_GET_XATTRS_MSG_BEGIN"),
112 ad->popup_content[size-1] = '\0';