Debian Codegraph @

src/rx_rule.c

raw symbols SCIP
1 /*
2 * AIDE (Advanced Intrusion Detection Environment)
3 *
4 * Copyright (C) 2016, 2020-2022,2024,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 "config.h"
22 #include <stdio.h>
23
24 #include "file.h"
25 #include "rx_rule.h"
26 #include "util.h"
27
28 static int generate_restriction_string(rx_restriction_t r, char *str) {
29 int n = 0;
30 if (r.f_type == FT_NULL
31 #ifdef HAVE_FSTYPE
32 && r.fs_type == 0
33 #endif
34 ) {
35 const char *no_restriction_string = "(none)";
36 size_t length = strlen(no_restriction_string);
37 if (str) { sprintf(&str[n], "%s", no_restriction_string); }
38 n = length+1;
39 } else {
40 FT_TYPE f_types = r.f_type;
41 unsigned int i = 0;
42 while (f_types) {
43 FT_TYPE t = (1U<<i);
44 if (f_types&t) {
45 if (n) {
46 if (str) { str[n] = ','; }
47 n++;
48 }
49 if (str) { str[n] = get_f_type_char_from_f_type(t); }
50 n++;
51 }
52 i++;
53 f_types &= ~t;
54 }
55 #ifdef HAVE_FSTYPE
56 if (r.fs_type != 0) {
57 if (str) { str[n] = '='; }
58 n++;
59 size_t length = generate_fs_type_string(r.fs_type, NULL);
60 if (str) { generate_fs_type_string(r.fs_type, &str[n]); }
61 n += length;
62 }
63 #endif
64 if (str) { str[n] = '\0'; }
65 n++;
66 }
67 return n;
68 }
69
70 char *get_restriction_string(rx_restriction_t r) {
71 char *str = NULL;
72 int n = generate_restriction_string(r, str);
73 str = checked_malloc(n);
74 generate_restriction_string(r, str);
75 return str;
76 }
77
78 char* get_rule_type_long_string(AIDE_RULE_TYPE rule_type) {
79 switch (rule_type) {
80 case AIDE_SELECTIVE_RULE: return "selective rule";
81 case AIDE_EQUAL_RULE: return "equal rule";
82 case AIDE_RECURSIVE_NEGATIVE_RULE: return "recursive negative rule";
83 case AIDE_NON_RECURSIVE_NEGATIVE_RULE: return "non-recursive negative rule";
84 }
85 return NULL;
86 }
87
88 char* get_rule_type_char(AIDE_RULE_TYPE rule_type) {
89 switch (rule_type) {
90 case AIDE_SELECTIVE_RULE: return "";
91 case AIDE_EQUAL_RULE: return "=";
92 case AIDE_RECURSIVE_NEGATIVE_RULE: return "!";
93 case AIDE_NON_RECURSIVE_NEGATIVE_RULE: return "-";
94 }
95 return NULL;
96 }
97
98 char *get_match_result_string(match_result match) {
99 switch(match) {
100 case RESULT_NO_RULE_MATCH:
101 return "RESULT_NO_RULE_MATCH";
102 case RESULT_RECURSIVE_NEGATIVE_MATCH:
103 return "RESULT_RECURSIVE_NEGATIVE_MATCH";
104 case RESULT_NON_RECURSIVE_NEGATIVE_MATCH:
105 return "RESULT_NON_RECURSIVE_NEGATIVE_MATCH";
106 case RESULT_EQUAL_MATCH:
107 return "RESULT_EQUAL_MATCH";
108 case RESULT_SELECTIVE_MATCH:
109 return "RESULT_SELECTIVE_MATCH";
110 case RESULT_PARTIAL_MATCH:
111 return "RESULT_PARTIAL_MATCH";
112 case RESULT_NO_LIMIT_MATCH:
113 return "RESULT_NO_LIMIT_MATCH";
114 case RESULT_PARTIAL_LIMIT_MATCH:
115 return "RESULT_PARTIAL_LIMIT_MATCH";
116 case RESULT_PART_LIMIT_AND_NO_RECURSE_MATCH:
117 return "RESULT_PART_LIMIT_AND_NO_RECURSE_MATCH";
118 case RESULT_NEGATIVE_PARENT_MATCH:
119 return "RESULT_NEGATIVE_PARENT_MATCH";
120 }
121 return "unknown match result";
122 }
123
124 char *get_match_result_desc(match_result match) {
125 switch(match) {
126 case RESULT_NO_RULE_MATCH:
127 return "no rule match";
128 case RESULT_RECURSIVE_NEGATIVE_MATCH:
129 return "recursive negative match";
130 case RESULT_NON_RECURSIVE_NEGATIVE_MATCH:
131 return "non-recursive negative match";
132 case RESULT_EQUAL_MATCH:
133 return "equal match";
134 case RESULT_SELECTIVE_MATCH:
135 return "selective match";
136 case RESULT_PARTIAL_MATCH:
137 return "partial match";
138 case RESULT_NO_LIMIT_MATCH:
139 return "no limit match";
140 case RESULT_PARTIAL_LIMIT_MATCH:
141 return "partial limit match";
142 case RESULT_PART_LIMIT_AND_NO_RECURSE_MATCH:
143 return "partial limit match but non-recursive negative match";
144 case RESULT_NEGATIVE_PARENT_MATCH:
145 return "negative parent match";
146 }
147 return "unknown match result";
148 }