Debian Codegraph @

src/attributes.c

raw symbols SCIP
1 /*
2 * AIDE (Advanced Intrusion Detection Environment)
3 *
4 * Copyright (C) 2015,2016,2019-2025 Hannes von Haugwitz
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21 #include <string.h>
22 #include <stdio.h>
23 #include <stdbool.h>
24 #include "util.h"
25
26 #include "attributes.h"
27
28 attributes_t attributes[] = {
29 { ATTR(attr_filename), NULL, NULL, "name", "name", '\0' },
30 { ATTR(attr_linkname), "l", "Lname", "lname", "link_name", 'l' },
31 { ATTR(attr_perm), "p", "Perm", "perm", "perm", 'p' },
32 { ATTR(attr_uid), "u", "Uid", "uid", "uid", 'u' },
33 { ATTR(attr_gid), "g", "Gid", "gid", "gid", 'g' },
34 { ATTR(attr_size), "s", "Size", "size", "size", '>' },
35 { ATTR(attr_atime), "a", "Atime", "atime", "access_time", 'a' },
36 { ATTR(attr_ctime), "c", "Ctime", "ctime", "change_time", 'c' },
37 { ATTR(attr_mtime), "m", "Mtime" , "mtime", "modify_time", 'm' },
38 { ATTR(attr_inode), "i", "Inode", "inode", "inode", 'i' },
39 { ATTR(attr_bcount), "b", "Bcount", "bcount", "block_count", 'b' },
40 { ATTR(attr_linkcount), "n", "Linkcount", "lcount", "link_count", 'n' },
41 { ATTR(attr_md5), "md5", "MD5", "md5", "md5", '\0' },
42 { ATTR(attr_sha1), "sha1", "SHA1", "sha1", "sha1", '\0' },
43 { ATTR(attr_rmd160), "rmd160", "RMD160", "rmd160", "rmd160", '\0' },
44 { ATTR(attr_tiger), "tiger", "TIGER", "tiger", "tiger", '\0' },
45 { ATTR(attr_crc32), "crc32", "CRC32", "crc32", "crc32", '\0' },
46 { ATTR(attr_haval), "haval", "HAVAL", "haval", "haval", '\0' },
47 { ATTR(attr_gostr3411_94), "gost", "GOST", "gost", "gost", '\0' },
48 { ATTR(attr_crc32b), "crc32b", "CRC32B", "crc32b", "crc32b", '\0' },
49 { ATTR(attr_attr), NULL, "Attributes", "attr", "attributes", '\0' },
50 { ATTR(attr_acl), "acl", "ACL", "acl", "acl", 'A' },
51 { ATTR(attr_bsize), NULL, NULL, NULL, NULL, '\0' },
52 { ATTR(attr_rdev), NULL, NULL , NULL, NULL, '\0' },
53 { ATTR(attr_dev), NULL, NULL , NULL, NULL, '\0' },
54 { ATTR(attr_allhashsums), NULL, NULL, NULL, NULL, 'H' }, /* "H" is also default compound group for all compiled in hashsums */
55 { ATTR(attr_sizeg), "S", "Size (>)", NULL, "growing_size", '\0' },
56 { ATTR(attr_checkinode), "I", NULL, NULL, NULL, '\0' },
57 { ATTR(attr_allownewfile), "ANF", NULL, NULL, NULL, '\0' },
58 { ATTR(attr_allowrmfile), "ARF", NULL, NULL, NULL, '\0' },
59 { ATTR(attr_sha256), "sha256", "SHA256", "sha256", "sha256", '\0' },
60 { ATTR(attr_sha512), "sha512", "SHA512", "sha512", "sha512", '\0' },
61 { ATTR(attr_selinux), "selinux", "SELinux", "selinux", "selinux", 'S' },
62 { ATTR(attr_xattrs), "xattrs", "XAttrs", "xattrs", "xattrs", 'X' },
63 { ATTR(attr_whirlpool), "whirlpool", "WHIRLPOOL", "whirlpool", "whirlpool", '\0' },
64 { ATTR(attr_ftype), "ftype", "File type", NULL, "file_type", '!' },
65 { ATTR(attr_e2fsattrs), "e2fsattrs", "E2FSAttrs", "e2fsattrs", "e2fsattrs", 'E' },
66 { ATTR(attr_capabilities), "caps", "Caps", "capabilities", "capabilities", 'C' },
67 { ATTR(attr_stribog256), "stribog256", "STRIBOG256", "stribog256", "stribog256", '\0' },
68 { ATTR(attr_stribog512), "stribog512", "STRIBOG512", "stribog512", "stribog512", '\0' },
69 { ATTR(attr_growing), "growing", NULL, NULL, NULL, '\0' },
70 { ATTR(attr_compressed), "compressed", NULL, NULL, NULL, '\0' },
71 { ATTR(attr_sha512_256), "sha512_256", "SHA512/256", "sha512_256", "sha512-256", '\0' },
72 { ATTR(attr_sha3_256), "sha3_256", "SHA3-256", "sha3_256", "sha3-256", '\0' },
73 { ATTR(attr_sha3_512), "sha3_512", "SHA3-512", "sha3_512", "sha3-512", '\0' },
74 { ATTR(attr_fs_type), "fstype", "FS type", "fstype", "fs_type", 'F' },
75 };
76
77 DB_ATTR_TYPE num_attrs = sizeof(attributes)/sizeof(attributes_t);
78
79 static int get_diff_attrs_string(DB_ATTR_TYPE a, DB_ATTR_TYPE b, char *str, bool db) {
80 int n = 0;
81 for (ATTRIBUTE i = 0; i < num_attrs; ++i) {
82 if (db?attributes[i].db_name:attributes[i].config_name) {
83 if (((1LLU<<i)&a) ^ ((1LLU<<i)&b)) {
84 if (n || a != 0) {
85 if (str) { str[n] = ((1LLU<<i)&b)?'+':'-'; }
86 n++;
87 }
88 if (str) {
89 sprintf(&str[n], "%s", db?attributes[i].db_name:attributes[i].config_name);
90 }
91 n += strlen(db?attributes[i].db_name:attributes[i].config_name);
92 }
93 }
94 }
95 if (str) { str[n] = '\0'; }
96 n++;
97 return n;
98 }
99
100 char *diff_attributes(DB_ATTR_TYPE a, DB_ATTR_TYPE b) {
101 char *str = NULL;
102 int n = get_diff_attrs_string(a, b, str, false);
103 str = checked_malloc(n);
104 get_diff_attrs_string(a, b, str, false);
105 return str;
106 }
107
108 char *diff_database_attributes(DB_ATTR_TYPE a, DB_ATTR_TYPE b) {
109 char *str = NULL;
110 int n = get_diff_attrs_string(a, b, str, true);
111 str = checked_malloc(n);
112 get_diff_attrs_string(a, b, str, true);
113 return str;
114 }