Debian Codegraph @

tests/check_attributes.c

raw symbols SCIP
1 /*
2 * AIDE (Advanced Intrusion Detection Environment)
3 *
4 * Copyright (C) 2019-2020 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 <check.h>
22 #include <stdlib.h>
23
24 #include "attributes.h"
25
26 typedef struct {
27 DB_ATTR_TYPE a;
28 DB_ATTR_TYPE b;
29 const char *expected_string;
30 } diff_attributes_t;
31
32 static diff_attributes_t diff_attributes_tests[] = {
33 { 0, 0, "" },
34 /* { 0, ATTR(attr_filename), "filename" }, */
35 { 0, ATTR(attr_linkname), "l" },
36 { 0, ATTR(attr_perm), "p" },
37 { 0, ATTR(attr_uid), "u" },
38 { 0, ATTR(attr_gid), "g" },
39 { 0, ATTR(attr_size), "s" },
40 { 0, ATTR(attr_atime), "a" },
41 { 0, ATTR(attr_ctime), "c" },
42 { 0, ATTR(attr_mtime), "m" },
43 { 0, ATTR(attr_inode), "i" },
44 { 0, ATTR(attr_bcount), "b" },
45 { 0, ATTR(attr_linkcount), "n" },
46 { 0, ATTR(attr_md5), "md5" },
47 { 0, ATTR(attr_sha1), "sha1" },
48 { 0, ATTR(attr_rmd160), "rmd160" },
49 { 0, ATTR(attr_tiger), "tiger" },
50 { 0, ATTR(attr_crc32), "crc32" },
51 { 0, ATTR(attr_haval), "haval" },
52 { 0, ATTR(attr_gostr3411_94), "gost" },
53 { 0, ATTR(attr_crc32b), "crc32b" },
54 /* { 0, ATTR(attr_attr), "attr" }, */
55 { 0, ATTR(attr_acl), "acl" },
56 /* { 0, ATTR(attr_bsize), "bsize" }, */
57 /* { 0, ATTR(attr_rdev), "rdev" }, */
58 /* { 0, ATTR(attr_dev), "dev" }, */
59 /* { 0, ATTR(attr_allhashsums), "H" }, */
60 { 0, ATTR(attr_sizeg), "S" },
61 { 0, ATTR(attr_checkinode), "I" },
62 { 0, ATTR(attr_allownewfile) , "ANF" },
63 { 0, ATTR(attr_allowrmfile), "ARF" },
64 { 0, ATTR(attr_sha256), "sha256" },
65 { 0, ATTR(attr_sha512), "sha512" },
66 { 0, ATTR(attr_selinux), "selinux" },
67 { 0, ATTR(attr_xattrs), "xattrs" },
68 { 0, ATTR(attr_whirlpool), "whirlpool" },
69 { 0, ATTR(attr_ftype), "ftype" },
70 { 0, ATTR(attr_e2fsattrs), "e2fsattrs" },
71 { 0, ATTR(attr_capabilities), "caps" },
72
73 { 0, ATTR(attr_linkname)|ATTR(attr_perm), "l+p" },
74 { 0, ATTR(attr_ctime)|ATTR(attr_ftype), "c+ftype" },
75 { 0, ATTR(attr_linkname)|ATTR(attr_perm)|ATTR(attr_uid)|ATTR(attr_gid)|ATTR(attr_size)|ATTR(attr_bcount)|ATTR(attr_linkcount)|ATTR(attr_sha256)|ATTR(attr_tiger)|ATTR(attr_haval)|ATTR(attr_sha512)|ATTR(attr_ftype), "l+p+u+g+s+b+n+tiger+haval+sha256+sha512+ftype" },
76
77 { ATTR(attr_linkname), 0 , "-l" },
78 { ATTR(attr_linkname), ATTR(attr_linkname) , "" },
79 { ATTR(attr_linkname), ATTR(attr_linkname)|ATTR(attr_perm) , "+p" },
80 { ATTR(attr_linkname)|ATTR(attr_perm), ATTR(attr_linkname) , "-p" },
81 { ATTR(attr_perm)|ATTR(attr_mtime), ATTR(attr_perm)|ATTR(attr_uid)|ATTR(attr_gid)|ATTR(attr_size)|ATTR(attr_bcount)|ATTR(attr_linkcount), "+u+g+s-m+b+n" },
82 };
83
84 static int num_diff_attributes_tests = sizeof diff_attributes_tests / sizeof(diff_attributes_t);
85
86 START_TEST (test_diff_attributes) {
87 char *str = diff_attributes(diff_attributes_tests[_i].a, diff_attributes_tests[_i].b);
88 ck_assert_msg(strcmp(diff_attributes_tests[_i].expected_string, str) == 0, "diff_attributes: %llu %llu: string returned '%s' != '%s'", diff_attributes_tests[_i].a, diff_attributes_tests[_i].b, str, diff_attributes_tests[_i].expected_string);
89 free(str);
90 }
91 END_TEST
92
93 Suite *make_attributes_suite(void) {
94
95 Suite *s = suite_create ("attributes");
96
97 TCase *tc_diff_attributes = tcase_create ("diff_attributes");
98
99 tcase_add_loop_test (tc_diff_attributes, test_diff_attributes, 0, num_diff_attributes_tests);
100
101 suite_add_tcase (s, tc_diff_attributes);
102
103 return s;
104 }