Debian Codegraph @

src/seltree.c

raw symbols SCIP
1 /*
2 * AIDE (Advanced Intrusion Detection Environment)
3 *
4 * Copyright (C) 1999-2006, 2009-2011, 2015-2016, 2019-2025 Rami Lehti,
5 * Pablo Virolainen, Richard van den Berg, Hannes von Haugwitz
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22 #include "file.h"cxx . . $ `<file>/include/file.h`/
23 #include <stdbool.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <pthread.h>
27 #define PCRE2_CODE_UNIT_WIDTHcxx . . $ `src/seltree.c:27:9`! 8
28 #include <pcre2.h>
29 #include "attributes.h"cxx . . $ `<file>/include/attributes.h`/
30 #include "list.h"cxx . . $ `<file>/include/list.h`/
31 #include "log.h"cxx . . $ `<file>/include/log.h`/
32 #include <string.h>
33 #include "rx_rule.h"cxx . . $ `<file>/include/rx_rule.h`/
34 #include "seltree.h"cxx . . $ `<file>/include/seltree.h`/
35 #include "seltree_struct.h"cxx . . $ `<file>/include/seltree_struct.h`/
36 #include "util.h"cxx . . $ `<file>/include/util.h`/
37 #include "errorcodes.h"cxx . . $ `<file>/include/errorcodes.h`/
38 #include "db.h"cxx . . $ `<file>/include/db.h`/
39
40 void log_treecxx . . $ log_tree(9936388f9497775b).(LOG_LEVELcxx . . $ LOG_LEVEL# log_level, seltreecxx . . $ seltree#* node, int depth) {
41
42 listcxx . . $ list#* r;
43 rx_rulecxx . . $ rx_rule#* rxc;
44
45 pthread_rwlock_rdlockcxx . . $ pthread_rwlock_rdlock(e530de6d038c3578).(&node->rwlockcxx . . $ seltree#rwlock.);
46
47 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(log_level, "%-*s %s:", depth, depth?"\u251d":"\u250c", node->pathcxx . . $ seltree#path.);
48
49 char *attr_str, *rs_str;
50
51 for(r=node->equ_rx_lstcxx . . $ seltree#equ_rx_lst.;r!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;r=r->nextcxx . . $ list#next.) {
52 rxc=r->datacxx . . $ list#data.;
53 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(log_level, "%-*s '=%s %s %s' (%s:%d: '%s%s%s')", depth+2, "\u2502", rxc->rxcxx . . $ rx_rule#rx., rs_str = get_restriction_stringcxx . . $ get_restriction_string(7c1dd464d1a8aef8).(rxc->restrictioncxx . . $ rx_rule#restriction.), attr_str = diff_attributescxx . . $ diff_attributes(39cd1df6f24d7ad6).(0, rxc->attrcxx . . $ rx_rule#attr.), rxc->config_filenamecxx . . $ rx_rule#config_filename., rxc->config_linenumbercxx . . $ rx_rule#config_linenumber., rxc->config_linecxx . . $ rx_rule#config_line., rxc->prefixcxx . . $ rx_rule#prefix.?"', prefix: '":"", rxc->prefixcxx . . $ rx_rule#prefix.?rxc->prefixcxx . . $ rx_rule#prefix.:"");
54 freecxx . . $ free(5d22bdacc48458e8).(rs_str);
55 freecxx . . $ free(5d22bdacc48458e8).(attr_str);
56 }
57 for(r=node->sel_rx_lstcxx . . $ seltree#sel_rx_lst.;r!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;r=r->nextcxx . . $ list#next.) {
58 rxc=r->datacxx . . $ list#data.;
59 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(log_level, "%-*s '%s %s %s' (%s:%d: '%s%s%s')", depth+2, "\u2502", rxc->rxcxx . . $ rx_rule#rx., rs_str = get_restriction_stringcxx . . $ get_restriction_string(7c1dd464d1a8aef8).(rxc->restrictioncxx . . $ rx_rule#restriction.), attr_str = diff_attributescxx . . $ diff_attributes(39cd1df6f24d7ad6).(0, rxc->attrcxx . . $ rx_rule#attr.), rxc->config_filenamecxx . . $ rx_rule#config_filename., rxc->config_linenumbercxx . . $ rx_rule#config_linenumber., rxc->config_linecxx . . $ rx_rule#config_line., rxc->prefixcxx . . $ rx_rule#prefix.?"', prefix: '":"", rxc->prefixcxx . . $ rx_rule#prefix.?rxc->prefixcxx . . $ rx_rule#prefix.:"");
60 freecxx . . $ free(5d22bdacc48458e8).(rs_str);
61 freecxx . . $ free(5d22bdacc48458e8).(attr_str);
62 }
63 for(r=node->neg_rx_lstcxx . . $ seltree#neg_rx_lst.;r!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;r=r->nextcxx . . $ list#next.) {
64 rxc=r->datacxx . . $ list#data.;
65 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(log_level, "%-*s '%s%s %s' (%s:%d: '%s%s%s')", depth+2, "\u2502", get_rule_type_charcxx . . $ get_rule_type_char(10604bca7de90ad2).(rxc->typecxx . . $ rx_rule#type.), rxc->rxcxx . . $ rx_rule#rx., rs_str = get_restriction_stringcxx . . $ get_restriction_string(7c1dd464d1a8aef8).(rxc->restrictioncxx . . $ rx_rule#restriction.), rxc->config_filenamecxx . . $ rx_rule#config_filename., rxc->config_linenumbercxx . . $ rx_rule#config_linenumber., rxc->config_linecxx . . $ rx_rule#config_line., rxc->prefixcxx . . $ rx_rule#prefix.?"', prefix: '":"", rxc->prefixcxx . . $ rx_rule#prefix.?rxc->prefixcxx . . $ rx_rule#prefix.:"");
66 freecxx . . $ free(5d22bdacc48458e8).(rs_str);
67 }
68
69 for(tree_nodecxx . . $ tree_node# *n = tree_walk_firstcxx . . $ tree_walk_first(29fe63215e0d1f08).(node->childrencxx . . $ seltree#children.); n != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! ; n = tree_walk_nextcxx . . $ tree_walk_next(29fe63215e0d1f08).(n)) {
70 log_treecxx . . $ log_tree(9936388f9497775b).(log_level, tree_get_datacxx . . $ tree_get_data(3ed80db4a2c90a05).(n), depth+2);
71 }
72
73 pthread_rwlock_unlockcxx . . $ pthread_rwlock_unlock(e530de6d038c3578).(&node->rwlockcxx . . $ seltree#rwlock.);
74
75 if (depth == 0) {
76 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(log_level, "%s", "\u2514");
77 }
78 }
79
80 /*
81 * strrxtok()
82 * return a pointer to a copy of the non-regexp path part of the argument
83 */
84 static char* strrxtokcxx . . $ strrxtok(7a9722d75b371431).(char* rx)
85 {
86 char*p=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
87 size_t i=0;
88
89 /* The following code assumes that the first character is a slash */
90 size_t lastslash=1;
91
92 p=checked_strdupcxx . . $ checked_strdup(42228c1987407501).(rx);
93 p[0]='/';
94
95 for(i=1;i<strlencxx . . $ strlen(751346f8406fd082).(p);i++){
96 switch(p[i])
97 {
98 case '/':
99 lastslash=i;
100 break;
101 case '(':
102 case '^':
103 case '$':
104 case '?':
105 case '*':
106 case '[':
107 i=strlencxx . . $ strlen(751346f8406fd082).(p);
108 break;
109 case '\\':
110 for (int j = i; p[j]; j++) {
111 p[j] = p[j+1];
112 }
113 break;
114 default:
115 break;
116 }
117 }
118
119 p[lastslash]='\0';
120
121 return p;
122 }
123
124
125 static seltreecxx . . $ seltree# *create_seltree_nodecxx . . $ create_seltree_node(85c1953ed0757132).(char *path, seltreecxx . . $ seltree# *parent) {
126 seltreecxx . . $ seltree# *node = checked_malloccxx . . $ checked_malloc(bfcfa4d6b7f7ef64).(sizeof(seltreecxx . . $ seltree#)); /* not to be freed */
127
128 node->pathcxx . . $ seltree#path. = checked_strdupcxx . . $ checked_strdup(42228c1987407501).(path); /* not to be freed */
129 node->parentcxx . . $ seltree#parent. = parent;
130
131 pthread_rwlock_initcxx . . $ pthread_rwlock_init(fc6013e2b28f9555).(&node->rwlockcxx . . $ seltree#rwlock., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
132
133 node->sel_rx_lstcxx . . $ seltree#sel_rx_lst. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
134 node->neg_rx_lstcxx . . $ seltree#neg_rx_lst. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
135 node->equ_rx_lstcxx . . $ seltree#equ_rx_lst. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
136
137 node->childrencxx . . $ seltree#children. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
138
139 node->checkedcxx . . $ seltree#checked. = 0;
140 node->new_datacxx . . $ seltree#new_data. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
141 node->old_datacxx . . $ seltree#old_data. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
142 node->changed_attrscxx . . $ seltree#changed_attrs. = 0;
143
144 return node;
145 }
146
147 static seltreecxx . . $ seltree#* _get_seltree_nodecxx . . $ _get_seltree_node(1d4996a5cd20e67c).(seltreecxx . . $ seltree#* node, char *path, boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! create) {
148 LOG_LEVELcxx . . $ LOG_LEVEL# log_level = LOG_LEVEL_TRACEcxx . . $ LOG_LEVEL_TRACE.;
149 pthread_rwlock_rdlockcxx . . $ pthread_rwlock_rdlock(e530de6d038c3578).(&node->rwlockcxx . . $ seltree#rwlock.);
150 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(log_level, "_get_seltree_node(): %s> node: '%s' (%p), create: %s", path, node->pathcxx . . $ seltree#path., (void*) node, btoacxx . . $ btoa(626eec357d49c77e).(create));
151 pthread_rwlock_unlockcxx . . $ pthread_rwlock_unlock(e530de6d038c3578).(&node->rwlockcxx . . $ seltree#rwlock.);
152 seltreecxx . . $ seltree# *parent = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
153 char *tmp = checked_strdupcxx . . $ checked_strdup(42228c1987407501).(path);
154
155 if (node && strcmpcxx . . $ strcmp(5ae29d726ae57f88).(node->pathcxx . . $ seltree#path., path) != 0) {
156 char *next_dir = path;;
157 do {
158 parent = node;
159 next_dir = strchrcxx . . $ `<external>/13506128340496143423/string.h:264:11`!(&next_dir[1], '/');
160 if (next_dir) { tmp[next_dir-path] = '\0'; }
161 pthread_rwlock_rdlockcxx . . $ pthread_rwlock_rdlock(e530de6d038c3578).(&parent->rwlockcxx . . $ seltree#rwlock.);
162 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(log_level, "_get_seltree_node(): %s> search for child node '%s' (parent: '%s' (%p))", path, strrchrcxx . . $ `<external>/13506128340496143423/string.h:295:11`!(tmp,'/'), parent->pathcxx . . $ seltree#path., (void*) parent);
163 node = tree_searchcxx . . $ tree_search(c7431b44d47a918d).(parent->childrencxx . . $ seltree#children., strrchrcxx . . $ `<external>/13506128340496143423/string.h:295:11`!(tmp,'/'), (tree_cmp_fcxx . . $ tree_cmp_f#) strcmpcxx . . $ strcmp(5ae29d726ae57f88).);
164 pthread_rwlock_unlockcxx . . $ pthread_rwlock_unlock(e530de6d038c3578).(&parent->rwlockcxx . . $ seltree#rwlock.);
165 if (create && node == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
166 pthread_rwlock_wrlockcxx . . $ pthread_rwlock_wrlock(e530de6d038c3578).(&parent->rwlockcxx . . $ seltree#rwlock.);
167 node = tree_searchcxx . . $ tree_search(c7431b44d47a918d).(parent->childrencxx . . $ seltree#children., strrchrcxx . . $ `<external>/13506128340496143423/string.h:295:11`!(tmp,'/'), (tree_cmp_fcxx . . $ tree_cmp_f#) strcmpcxx . . $ strcmp(5ae29d726ae57f88).);
168 if (node == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
169 node = create_seltree_nodecxx . . $ create_seltree_node(85c1953ed0757132).(tmp, parent);
170 parent ->childrencxx . . $ seltree#children. = tree_insertcxx . . $ tree_insert(819ff1d36eaa519d).(parent->childrencxx . . $ seltree#children., strrchrcxx . . $ `<external>/13506128340496143423/string.h:295:11`!(node->path,'/'), (void*)node, (tree_cmp_fcxx . . $ tree_cmp_f#) strcmpcxx . . $ strcmp(5ae29d726ae57f88).);
171 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(log_level, "_get_seltree_node(): %s> created new %s node '%s' (%p) (parent: %p)", path, next_dir?"inner":"leaf", tmp, (void*) node, (void*) parent);
172 }
173 pthread_rwlock_unlockcxx . . $ pthread_rwlock_unlock(e530de6d038c3578).(&parent->rwlockcxx . . $ seltree#rwlock.);
174 }
175 if (next_dir) { tmp[next_dir-path] = '/'; }
176 } while (node != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! && next_dir);
177 }
178 freecxx . . $ free(5d22bdacc48458e8).(tmp);
179 if (node == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
180 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(log_level, "_get_seltree_node(): %s> return NULL (node == NULL)", path);
181 } else {
182 pthread_rwlock_rdlockcxx . . $ pthread_rwlock_rdlock(e530de6d038c3578).(&node->rwlockcxx . . $ seltree#rwlock.);
183 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(log_level, "_get_seltree_node(): %s> return node: '%s' (%p)", path, node->pathcxx . . $ seltree#path., (void*) node);
184 pthread_rwlock_unlockcxx . . $ pthread_rwlock_unlock(e530de6d038c3578).(&node->rwlockcxx . . $ seltree#rwlock.);
185 }
186 return node;
187 }
188
189 seltreecxx . . $ seltree#* get_or_create_seltree_nodecxx . . $ get_or_create_seltree_node(e2ef57450a84c6c6).(seltreecxx . . $ seltree#* node, char *path) {
190 return _get_seltree_nodecxx . . $ _get_seltree_node(1d4996a5cd20e67c).(node, path, truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!);
191 }
192
193 seltreecxx . . $ seltree#* get_seltree_nodecxx . . $ get_seltree_node(e2ef57450a84c6c6).(seltreecxx . . $ seltree#* node, char *path) {
194 return _get_seltree_nodecxx . . $ _get_seltree_node(1d4996a5cd20e67c).(node, path, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!);
195 }
196
197 seltreecxx . . $ seltree# *init_treecxx . . $ init_tree(b0d239dcd5721ff6).(void) {
198 seltreecxx . . $ seltree# *node = create_seltree_nodecxx . . $ create_seltree_node(85c1953ed0757132).("/", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
199 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_DEBUGcxx . . $ LOG_LEVEL_DEBUG., "created root node '%s' (%p)", node->pathcxx . . $ seltree#path., (void*) node);
200 return node;
201 }
202
203 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! is_tree_emptycxx . . $ is_tree_empty(58db79c0038671b0).(seltreecxx . . $ seltree# *node) {
204 pthread_rwlock_rdlockcxx . . $ pthread_rwlock_rdlock(e530de6d038c3578).(&node->rwlockcxx . . $ seltree#rwlock.);
205 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! is_empty = (node->childrencxx . . $ seltree#children. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!
206 && node->equ_rx_lstcxx . . $ seltree#equ_rx_lst. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!
207 && node->sel_rx_lstcxx . . $ seltree#sel_rx_lst. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!
208 && node->neg_rx_lstcxx . . $ seltree#neg_rx_lst. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!
209 );
210 pthread_rwlock_unlockcxx . . $ pthread_rwlock_unlock(e530de6d038c3578).(&node->rwlockcxx . . $ seltree#rwlock.);
211 return is_empty;
212 }
213
214 rx_rulecxx . . $ rx_rule# * add_rx_to_treecxx . . $ add_rx_to_tree(fa81f7bbcf0f6ec9).(char * rx, rx_restriction_tcxx . . $ rx_restriction_t# restriction, AIDE_RULE_TYPEcxx . . $ AIDE_RULE_TYPE# rule_type, seltreecxx . . $ seltree# *tree, int linenumber, char* filename, char* linebuf, char **node_path) {
215 rx_rulecxx . . $ rx_rule#* r = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
216 seltreecxx . . $ seltree# *curnode = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
217 char *rxtok = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
218
219 r=(rx_rulecxx . . $ rx_rule#*)checked_malloccxx . . $ checked_malloc(bfcfa4d6b7f7ef64).(sizeof(rx_rulecxx . . $ rx_rule#));
220
221 r->rxcxx . . $ rx_rule#rx.=rx;
222 r->typecxx . . $ rx_rule#type. = rule_type;
223 r->restrictioncxx . . $ rx_rule#restriction. = restriction;
224
225 r->config_linenumbercxx . . $ rx_rule#config_linenumber. = linenumber;
226 r->config_filenamecxx . . $ rx_rule#config_filename. = filename;
227 r->config_linecxx . . $ rx_rule#config_line. = checked_strdupcxx . . $ checked_strdup(42228c1987407501).(linebuf);
228 r->prefixcxx . . $ rx_rule#prefix. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
229 r->attrcxx . . $ rx_rule#attr. = 0;
230
231 int pcre2_errorcode;
232 PCRE2_SIZEcxx . . $ `<external>/9988290459910441303/pcre2.h:528:9`! pcre2_erroffset;
233
234 if((r->crxcxx . . $ rx_rule#crx.=pcre2_compilecxx . . $ `<external>/9988290459910441303/pcre2.h:910:9`!((PCRE2_SPTRcxx . . $ `<external>/9988290459910441303/pcre2.h:877:9`!) r->rxcxx . . $ rx_rule#rx., PCRE2_ZERO_TERMINATEDcxx . . $ `<external>/9988290459910441303/pcre2.h:530:9`!, PCRE2_UTFcxx . . $ `<external>/9988290459910441303/pcre2.h:138:9`!|PCRE2_ANCHOREDcxx . . $ `<external>/9988290459910441303/pcre2.h:105:9`!, &pcre2_errorcode, &pcre2_erroffset, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
235 PCRE2_UCHARcxx . . $ `<external>/9988290459910441303/pcre2.h:876:9`! pcre2_error[128];
236 pcre2_get_error_messagecxx . . $ `<external>/9988290459910441303/pcre2.h:923:9`!(pcre2_errorcode, pcre2_error, 128);
237 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "%s:%d:%zu: error in rule '%s': %s (line: '%s')", filename, linenumber, pcre2_erroffset, rx, pcre2_error, linebuf);
238 freecxx . . $ free(5d22bdacc48458e8).(r);
239 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
240 } else {
241 r->mdcxx . . $ rx_rule#md. = pcre2_match_data_create_from_patterncxx . . $ `<external>/9988290459910441303/pcre2.h:943:9`!(r->crxcxx . . $ rx_rule#crx., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
242 if (r->mdcxx . . $ rx_rule#md. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
243 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "pcre2_match_data_create_from_pattern: failed to allocate memory");
244 exitcxx . . $ exit(3ca292c338df9bb3).(MEMORY_ALLOCATION_FAILUREcxx . . $ `include/errorcodes.h:33:9`!);
245 }
246 int pcre2_jit = pcre2_jit_compilecxx . . $ `<external>/9988290459910441303/pcre2.h:930:9`!(r->crxcxx . . $ rx_rule#crx., PCRE2_JIT_PARTIAL_SOFTcxx . . $ `<external>/9988290459910441303/pcre2.h:171:9`!);
247 if (pcre2_jit < 0) {
248 PCRE2_UCHARcxx . . $ `<external>/9988290459910441303/pcre2.h:876:9`! pcre2_error[128];
249 pcre2_get_error_messagecxx . . $ `<external>/9988290459910441303/pcre2.h:923:9`!(pcre2_jit, pcre2_error, 128);
250 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_DEBUGcxx . . $ LOG_LEVEL_DEBUG., "JIT compilation for regex '%s' failed: %s (fall back to interpreted matching)", r->rxcxx . . $ rx_rule#rx., pcre2_error);
251 } else {
252 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_DEBUGcxx . . $ LOG_LEVEL_DEBUG., "JIT compilation for regex '%s' successful", r->rxcxx . . $ rx_rule#rx.);
253 }
254
255 rxtok=strrxtokcxx . . $ strrxtok(7a9722d75b371431).(r->rxcxx . . $ rx_rule#rx.);
256
257 for(size_t i=1;i < strlencxx . . $ strlen(751346f8406fd082).(rxtok); ++i){
258 if (rxtok[i] == '/' && rxtok[i-1] == '/') {
259 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "%s:%d:1: error in rule '%s': invalid double slash (line: '%s')", filename, linenumber, rx, linebuf);
260 freecxx . . $ free(5d22bdacc48458e8).(r);
261 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
262 }
263 }
264
265 curnode = get_or_create_seltree_nodecxx . . $ get_or_create_seltree_node(e2ef57450a84c6c6).(tree, rxtok);
266
267 pthread_rwlock_wrlockcxx . . $ pthread_rwlock_wrlock(e530de6d038c3578).(&curnode->rwlockcxx . . $ seltree#rwlock.);
268 *node_path = curnode->pathcxx . . $ seltree#path.;
269 switch (rule_type){
270 case AIDE_RECURSIVE_NEGATIVE_RULEcxx . . $ AIDE_RECURSIVE_NEGATIVE_RULE.:
271 case AIDE_NON_RECURSIVE_NEGATIVE_RULEcxx . . $ AIDE_NON_RECURSIVE_NEGATIVE_RULE.:{
272 curnode->neg_rx_lstcxx . . $ seltree#neg_rx_lst.=list_appendcxx . . $ list_append(6224ec1eaf824d25).(curnode->neg_rx_lstcxx . . $ seltree#neg_rx_lst.,(void*)r);
273 break;
274 }
275 case AIDE_EQUAL_RULEcxx . . $ AIDE_EQUAL_RULE.:{
276 curnode->equ_rx_lstcxx . . $ seltree#equ_rx_lst.=list_appendcxx . . $ list_append(6224ec1eaf824d25).(curnode->equ_rx_lstcxx . . $ seltree#equ_rx_lst.,(void*)r);
277 break;
278 }
279 case AIDE_SELECTIVE_RULEcxx . . $ AIDE_SELECTIVE_RULE.:{
280 curnode->sel_rx_lstcxx . . $ seltree#sel_rx_lst.=list_appendcxx . . $ list_append(6224ec1eaf824d25).(curnode->sel_rx_lstcxx . . $ seltree#sel_rx_lst.,(void*)r);
281 break;
282 }
283 }
284 pthread_rwlock_unlockcxx . . $ pthread_rwlock_unlock(e530de6d038c3578).(&curnode->rwlockcxx . . $ seltree#rwlock.);
285 freecxx . . $ free(5d22bdacc48458e8).(rxtok);
286
287 while (curnode) {
288 pthread_rwlock_tcxx . . $ pthread_rwlock_t# *rwlock = &curnode->rwlockcxx . . $ seltree#rwlock.;
289 pthread_rwlock_wrlockcxx . . $ pthread_rwlock_wrlock(e530de6d038c3578).(rwlock);
290 if(curnode->checkedcxx . . $ seltree#checked.&NODE_HAS_SUB_RULEScxx . . $ `include/db.h:70:9`!) {
291 curnode = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
292 } else {
293 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_DEBUGcxx . . $ LOG_LEVEL_DEBUG., "set NODE_HAS_SUB_RULES for node '%s' (%p)", curnode->pathcxx . . $ seltree#path., (void*) curnode);
294 curnode->checkedcxx . . $ seltree#checked. |= NODE_HAS_SUB_RULEScxx . . $ `include/db.h:70:9`!;
295 curnode = curnode->parentcxx . . $ seltree#parent.;
296 }
297 pthread_rwlock_unlockcxx . . $ pthread_rwlock_unlock(e530de6d038c3578).(rwlock);
298 }
299 }
300 return r;
301 }
302
303 #define LOG_MATCHcxx . . $ `src/seltree.c:303:9`!(log_level, border, format, ...) \
304 log_msg(log_level, "%*s%s%s %*c'%s' " #format " of %s (%s:%d: '%s%s%s')", whoami?10:0, whoami?whoami:"", whoami?": ":"", border, depth, ' ', file.name, __VA_ARGS__, get_rule_type_long_string(rx->type), rx->config_filename, rx->config_linenumber, rx->config_line, rx->prefix?"', prefix: '":"", rx->prefix?rx->prefix:"");
305
306 static int check_list_for_matchcxx . . $ check_list_for_match(986abd588090b7a3).(listcxx . . $ list#* rxrlist, file_tcxx . . $ file_t# file, rx_rulecxx . . $ rx_rule#* *rule, int depth, const char* whoami)
307 {
308 listcxx . . $ list#* r=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
309 int retval=RESULT_NO_RULE_MATCHcxx . . $ RESULT_NO_RULE_MATCH.;
310 int pcre_retval;
311 char *rs_str = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
312 for(r=rxrlist;r;r=r->nextcxx . . $ list#next.){
313 rx_rulecxx . . $ rx_rule# *rx = (rx_rulecxx . . $ rx_rule#*)r->datacxx . . $ list#data.;
314
315 pcre_retval = pcre2_matchcxx . . $ `<external>/9988290459910441303/pcre2.h:938:9`!(rx->crxcxx . . $ rx_rule#crx., (PCRE2_SPTRcxx . . $ `<external>/9988290459910441303/pcre2.h:877:9`!) file.namecxx . . $ file_t#name., PCRE2_ZERO_TERMINATEDcxx . . $ `<external>/9988290459910441303/pcre2.h:530:9`!, 0, PCRE2_PARTIAL_SOFTcxx . . $ `<external>/9988290459910441303/pcre2.h:186:9`!, rx->mdcxx . . $ rx_rule#md., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
316 if (pcre_retval >= 0) { /* matching regex */
317 if (!rx->restrictioncxx . . $ rx_rule#restriction..f_typecxx . . $ rx_restriction_t#f_type. || file.typecxx . . $ file_t#type.&rx->restrictioncxx . . $ rx_rule#restriction..f_typecxx . . $ rx_restriction_t#f_type.) { /* no file type restriction OR matching file type */
318 #ifdef HAVE_FSTYPEcxx . . $ `./include/config.h:53:9`!
319 if (rx->restrictioncxx . . $ rx_rule#restriction..fs_typecxx . . $ rx_restriction_t#fs_type. && file.fs_typecxx . . $ file_t#fs_type. == 0) { /* no file system data but file system type restricted rule */
320 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., "unable to match the file system type restriction of %s (%s:%d: '%s%s%s'): file system type missing for '%s'", get_rule_type_long_stringcxx . . $ get_rule_type_long_string(10604bca7de90ad2).(rx->typecxx . . $ rx_rule#type.), rx->config_filenamecxx . . $ rx_rule#config_filename., rx->config_linenumbercxx . . $ rx_rule#config_linenumber., rx->config_linecxx . . $ rx_rule#config_line., rx->prefixcxx . . $ rx_rule#prefix.?"', prefix: '":"", rx->prefixcxx . . $ rx_rule#prefix.?rx->prefixcxx . . $ rx_rule#prefix.:"", file.namecxx . . $ file_t#name.);
321 /* RESULT_NO_RULE_MATCH */
322 } else if (!rx->restrictioncxx . . $ rx_rule#restriction..fs_typecxx . . $ rx_restriction_t#fs_type. || rx->restrictioncxx . . $ rx_rule#restriction..fs_typecxx . . $ rx_restriction_t#fs_type. == file.fs_typecxx . . $ file_t#fs_type.) { /* no file system restriction OR matching file sytem */
323 #endif
324 *rule = rx;
325 LOG_MATCHcxx . . $ `src/seltree.c:303:9`!(LOG_LEVEL_RULE, "\u251d", matches regex '%s' and restriction '%s', rx->rx, rs_str = get_restriction_string(rx->restriction))
326 freecxx . . $ free(5d22bdacc48458e8).(rs_str);
327 switch(rx->typecxx . . $ rx_rule#type.) {
328 case AIDE_SELECTIVE_RULEcxx . . $ AIDE_SELECTIVE_RULE.:
329 retval = RESULT_SELECTIVE_MATCHcxx . . $ RESULT_SELECTIVE_MATCH.;
330 break;
331 case AIDE_EQUAL_RULEcxx . . $ AIDE_EQUAL_RULE.:
332 retval = RESULT_EQUAL_MATCHcxx . . $ RESULT_EQUAL_MATCH.;
333 break;
334 case AIDE_RECURSIVE_NEGATIVE_RULEcxx . . $ AIDE_RECURSIVE_NEGATIVE_RULE.:
335 retval = RESULT_RECURSIVE_NEGATIVE_MATCHcxx . . $ RESULT_RECURSIVE_NEGATIVE_MATCH.;
336 break;
337 case AIDE_NON_RECURSIVE_NEGATIVE_RULEcxx . . $ AIDE_NON_RECURSIVE_NEGATIVE_RULE.:
338 retval = RESULT_NON_RECURSIVE_NEGATIVE_MATCHcxx . . $ RESULT_NON_RECURSIVE_NEGATIVE_MATCH.;
339 break;
340 }
341 break;
342 #ifdef HAVE_FSTYPEcxx . . $ `./include/config.h:53:9`!
343 } else { /* file system restriction does not match */
344 LOG_MATCHcxx . . $ `src/seltree.c:303:9`!(LOG_LEVEL_DEBUG, "\u2502", does not match file system of restriction '%s', rs_str = get_restriction_string(rx->restriction))
345 freecxx . . $ free(5d22bdacc48458e8).(rs_str);
346 retval=RESULT_PARTIAL_MATCHcxx . . $ RESULT_PARTIAL_MATCH.;
347 }
348 #endif
349 } else { /* file type restriction does not match */
350 LOG_MATCHcxx . . $ `src/seltree.c:303:9`!(LOG_LEVEL_DEBUG, "\u2502", does not match file type of rule restriction '%s', rs_str = get_restriction_string(rx->restriction))
351 freecxx . . $ free(5d22bdacc48458e8).(rs_str);
352 retval=RESULT_PARTIAL_MATCHcxx . . $ RESULT_PARTIAL_MATCH.;
353 }
354 } else if (pcre_retval == PCRE2_ERROR_PARTIALcxx . . $ `<external>/9988290459910441303/pcre2.h:350:9`!) { /* partial match of regex */
355 LOG_MATCHcxx . . $ `src/seltree.c:303:9`!(LOG_LEVEL_DEBUG, "\u2502", partially matches regex '%s', rx->rx)
356 retval=RESULT_PARTIAL_MATCHcxx . . $ RESULT_PARTIAL_MATCH.;
357 } else { /* regex does not match */
358 LOG_MATCHcxx . . $ `src/seltree.c:303:9`!(LOG_LEVEL_DEBUG, "\u2502", does not match regex '%s', rx->rx)
359 /* RESULT_NO_RULE_MATCH */
360 }
361 }
362 return retval;
363 }
364
365 static match_resultcxx . . $ match_result# _get_default_match_resultcxx . . $ _get_default_match_result(68bfae347459243b).(const seltreecxx . . $ seltree# *node, int depth, const char* whoami) {
366 if (node->checkedcxx . . $ seltree#checked.&NODE_HAS_SUB_RULEScxx . . $ `include/db.h:70:9`!) {
367 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_DEBUG, "\u2502 %*cdirectory node '%s' (%p) has NODE_HAS_SUB_RULES set (set default match result to RESULT_PARTIAL_MATCH)", depth, ' ', node->path, (void*) node);
368 return RESULT_PARTIAL_MATCHcxx . . $ RESULT_PARTIAL_MATCH.;
369 }
370 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_DEBUG, "\u2502 %*cdirectory node '%s' (%p) has NODE_HAS_SUB_RULES NOT set (keep default match result at RESULT_NO_RULE_MATCH)", depth, ' ', node->path, (void*) node);
371 return RESULT_NO_RULE_MATCHcxx . . $ RESULT_NO_RULE_MATCH.;
372 }
373
374 static match_tcxx . . $ match_t# check_node_for_matchcxx . . $ check_node_for_match(283bceff9a564d1e).(seltreecxx . . $ seltree# *pnode, file_tcxx . . $ file_t# file, const char* whoami) {
375
376 match_tcxx . . $ match_t# match = { RESULT_NO_RULE_MATCHcxx . . $ RESULT_NO_RULE_MATCH., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, 0 };
377 match_resultcxx . . $ match_result# result;
378 int depth = 1;
379
380 char *last_slash = strrchrcxx . . $ `<external>/13506128340496143423/string.h:295:11`!(file.name,'/');
381 int parent_length = (last_slash != file.namecxx . . $ file_t#name.?last_slash-file.namecxx . . $ file_t#name.:0);
382
383 pthread_rwlock_rdlockcxx . . $ pthread_rwlock_rdlock(e530de6d038c3578).(&pnode->rwlockcxx . . $ seltree#rwlock.);
384 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_TRACE, "\u2502 check_node_for_match: pnode: '%s' (%p), filename: '%s', file_type: %c", pnode->path, (void*) pnode, file.name, get_f_type_char_from_f_type(file.type));
385 if (strncmpcxx . . $ strncmp(fd278af2f295fa2e).(pnode->pathcxx . . $ seltree#path., file.namecxx . . $ file_t#name., parent_length) == 0) {
386
387 if (file.typecxx . . $ file_t#type. == FT_DIRcxx . . $ `include/file.h:32:9`!) {
388 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(pnode->pathcxx . . $ seltree#path., file.namecxx . . $ file_t#name.) == 0) {
389 match.resultcxx . . $ match_t#result. = _get_default_match_resultcxx . . $ _get_default_match_result(68bfae347459243b).(pnode, depth, whoami);
390 } else {
391 seltreecxx . . $ seltree# * child_node = tree_searchcxx . . $ tree_search(c7431b44d47a918d).(pnode->childrencxx . . $ seltree#children., last_slash, (tree_cmp_fcxx . . $ tree_cmp_f#) strcmpcxx . . $ strcmp(5ae29d726ae57f88).);
392 if (child_node) {
393 pthread_rwlock_rdlockcxx . . $ pthread_rwlock_rdlock(e530de6d038c3578).(&child_node->rwlockcxx . . $ seltree#rwlock.);
394 match.resultcxx . . $ match_t#result. = _get_default_match_resultcxx . . $ _get_default_match_result(68bfae347459243b).(child_node, depth, whoami);
395 pthread_rwlock_unlockcxx . . $ pthread_rwlock_unlock(e530de6d038c3578).(&child_node->rwlockcxx . . $ seltree#rwlock.);
396 } else {
397 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_DEBUG, "\u2502 %*cno node for directory '%s' exists (keep default match result at RESULT_NO_RULE_MATCH)", depth, ' ', file.name);
398 }
399 }
400 }
401
402 if (pnode->equ_rx_lstcxx . . $ seltree#equ_rx_lst.) {
403 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_RULE, "\u2502 %*cnode: '%s': check equal list", depth, ' ', pnode->path);
404 result = check_list_for_matchcxx . . $ check_list_for_match(986abd588090b7a3).(pnode->equ_rx_lstcxx . . $ seltree#equ_rx_lst., file, &match.rulecxx . . $ match_t#rule., depth+2, whoami);
405 if (result == RESULT_EQUAL_MATCHcxx . . $ RESULT_EQUAL_MATCH. || result == RESULT_PARTIAL_MATCHcxx . . $ RESULT_PARTIAL_MATCH.) {
406 match.resultcxx . . $ match_t#result. = result;
407 }
408 } else {
409 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_DEBUG, "\u2502 %*cnode: '%s': skip equal list (reason: list is empty)", depth, ' ', pnode->path);
410 }
411 } else {
412 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_DEBUG, "\u2502 %*cnode: '%s' skip equal list (reason: not on top level)", depth, ' ', pnode->path);
413 }
414 pthread_rwlock_unlockcxx . . $ pthread_rwlock_unlock(e530de6d038c3578).(&pnode->rwlockcxx . . $ seltree#rwlock.);
415
416 /* seltree* stack for negative rules */
417 int i = 0;
418 seltreecxx . . $ seltree# * p = pnode;
419 while (p) {
420 pthread_rwlock_tcxx . . $ pthread_rwlock_t# *rwlock = &p->rwlockcxx . . $ seltree#rwlock.;
421 pthread_rwlock_rdlockcxx . . $ pthread_rwlock_rdlock(e530de6d038c3578).(rwlock);
422 p = p->parentcxx . . $ seltree#parent.;
423 i++;
424 pthread_rwlock_unlockcxx . . $ pthread_rwlock_unlock(e530de6d038c3578).(rwlock);
425 }
426 seltreecxx . . $ seltree#* *nodes = checked_malloccxx . . $ checked_malloc(bfcfa4d6b7f7ef64).(sizeof(seltreecxx . . $ seltree#*)*i);
427
428 i = 0;
429 seltreecxx . . $ seltree# *next_parent = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;;
430 /* check selective rules down -> top */
431 do {
432 pthread_rwlock_rdlockcxx . . $ pthread_rwlock_rdlock(e530de6d038c3578).(&pnode->rwlockcxx . . $ seltree#rwlock.);
433 if (pnode->sel_rx_lstcxx . . $ seltree#sel_rx_lst. || pnode->neg_rx_lstcxx . . $ seltree#neg_rx_lst.) {
434 nodes[i++] = pnode;
435
436 if (match.resultcxx . . $ match_t#result. != RESULT_EQUAL_MATCHcxx . . $ RESULT_EQUAL_MATCH. && match.resultcxx . . $ match_t#result. != RESULT_SELECTIVE_MATCHcxx . . $ RESULT_SELECTIVE_MATCH.) {
437 if (pnode->sel_rx_lstcxx . . $ seltree#sel_rx_lst.) {
438 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_RULE, "\u2502 %*cnode: '%s': check selective list", depth, ' ', pnode->path);
439 result = check_list_for_matchcxx . . $ check_list_for_match(986abd588090b7a3).(pnode->sel_rx_lstcxx . . $ seltree#sel_rx_lst., file, &match.rulecxx . . $ match_t#rule., depth+2, whoami);
440 if (result == RESULT_SELECTIVE_MATCHcxx . . $ RESULT_SELECTIVE_MATCH. || result == RESULT_PARTIAL_MATCHcxx . . $ RESULT_PARTIAL_MATCH.) {
441 match.resultcxx . . $ match_t#result. = result;
442 }
443 } else {
444 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_DEBUG, "\u2502 %*cnode: '%s': skip selective list (reason: list is empty)", depth, ' ', pnode->path);
445 }
446 } else {
447 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_DEBUG, "\u2502 %*cnode: '%s': skip selective list (reason: previous positive match)", depth, ' ', pnode->path);
448 }
449 depth++;
450 } else {
451 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_DEBUG, "\u2502 %*cnode: '%s': skip selective and negative list (reason: lists are empty)", depth, ' ', pnode->path);
452 }
453 next_parent = pnode->parentcxx . . $ seltree#parent.;
454 pthread_rwlock_unlockcxx . . $ pthread_rwlock_unlock(e530de6d038c3578).(&pnode->rwlockcxx . . $ seltree#rwlock.);
455 } while ((pnode = next_parent));
456
457 /* check negative rules top -> down */
458 while (--i >=0) {
459 pnode = nodes[i];
460 depth--;
461 pthread_rwlock_rdlockcxx . . $ pthread_rwlock_rdlock(e530de6d038c3578).(&pnode->rwlockcxx . . $ seltree#rwlock.);
462 if (match.resultcxx . . $ match_t#result. == RESULT_EQUAL_MATCHcxx . . $ RESULT_EQUAL_MATCH. || match.resultcxx . . $ match_t#result. == RESULT_SELECTIVE_MATCHcxx . . $ RESULT_SELECTIVE_MATCH. || match.resultcxx . . $ match_t#result. == RESULT_PARTIAL_MATCHcxx . . $ RESULT_PARTIAL_MATCH.) {
463 if (pnode->neg_rx_lstcxx . . $ seltree#neg_rx_lst.) {
464 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_RULE, "\u2502 %*cnode: '%s': check negative list (reason: previous positive/partial match)", depth, ' ', pnode->path);
465 result = check_list_for_matchcxx . . $ check_list_for_match(986abd588090b7a3).(pnode->neg_rx_lstcxx . . $ seltree#neg_rx_lst., file, &match.rulecxx . . $ match_t#rule., depth+2, whoami);
466 if ((match.resultcxx . . $ match_t#result. != RESULT_PARTIAL_MATCHcxx . . $ RESULT_PARTIAL_MATCH. && result == RESULT_RECURSIVE_NEGATIVE_MATCHcxx . . $ RESULT_RECURSIVE_NEGATIVE_MATCH.) || result == RESULT_NON_RECURSIVE_NEGATIVE_MATCHcxx . . $ RESULT_NON_RECURSIVE_NEGATIVE_MATCH.) {
467 match.resultcxx . . $ match_t#result. = result;
468 }
469 } else {
470 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_DEBUG, "\u2502 %*cnode: '%s': skip negative list (reason: list is empty)", depth, ' ', pnode->path);
471 }
472 } else if (match.resultcxx . . $ match_t#result. == RESULT_NON_RECURSIVE_NEGATIVE_MATCHcxx . . $ RESULT_NON_RECURSIVE_NEGATIVE_MATCH. || match.resultcxx . . $ match_t#result. == RESULT_RECURSIVE_NEGATIVE_MATCHcxx . . $ RESULT_RECURSIVE_NEGATIVE_MATCH.) {
473 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_DEBUG, "\u2502 %*cnode: '%s': skip negative list (reason: previous negative match)", depth, ' ', pnode->path);
474 } else {
475 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_DEBUG, "\u2502 %*cnode: '%s': skip negative list (reason: no previous positive/partial match)", depth, ' ', pnode->path);
476 }
477 pthread_rwlock_unlockcxx . . $ pthread_rwlock_unlock(e530de6d038c3578).(&pnode->rwlockcxx . . $ seltree#rwlock.);
478 }
479 freecxx . . $ free(5d22bdacc48458e8).(nodes);
480 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_TRACE, "\u2502 check_node_for_match: match result %s (%d) for '%s'", get_match_result_string(match.result), match.result, file.name);
481 return match;
482 }
483
484 match_tcxx . . $ match_t# check_seltreecxx . . $ check_seltree(634c6f0bfd0e2c3d).(seltreecxx . . $ seltree# *tree, file_tcxx . . $ file_t# file, boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! check_parent_dirs, const char * whoami) {
485 seltreecxx . . $ seltree#* pnode=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
486 match_tcxx . . $ match_t# match = { RESULT_NO_RULE_MATCHcxx . . $ RESULT_NO_RULE_MATCH., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, 0 };
487 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! parent_negative_match = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
488
489 const char *next_dir = file.namecxx . . $ file_t#name.;
490 char *parent = checked_strdupcxx . . $ checked_strdup(42228c1987407501).(file.namecxx . . $ file_t#name.); /* freed below */
491 pnode = tree;
492 seltreecxx . . $ seltree# *node = tree;
493
494 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_TRACE, "\u2502 search for parent node for '%s' (tree: '%s' (%p))", file.name, tree->path, (void*) tree);
495
496 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(file.namecxx . . $ file_t#name., "/") == 0) { check_parent_dirs = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; } /* do not check parent directories for '/' */
497
498 char *relative_child_path = parent;
499 while ((next_dir = strchrcxx . . $ `<external>/13506128340496143423/string.h:264:11`!(next_dir, '/'))) {
500 int parent_length = next_dir-file.namecxx . . $ file_t#name.;
501 int relative_child_path_start = parent_length;
502 if (next_dir == file.namecxx . . $ file_t#name.) { /* handle "/" directory */
503 parent_length = 1;
504 relative_child_path_start = 0;
505 }
506 parent[parent_length] = '\0';
507
508 if (node && relative_child_path_start) {
509 node = get_seltree_nodecxx . . $ get_seltree_node(e2ef57450a84c6c6).(pnode, relative_child_path);
510 if (node) {
511 pthread_rwlock_rdlockcxx . . $ pthread_rwlock_rdlock(e530de6d038c3578).(&node->rwlockcxx . . $ seltree#rwlock.);
512 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_TRACE, "\u2502 got %s (%p) for '%s'", node->path, (void*) node, relative_child_path);
513 pthread_rwlock_unlockcxx . . $ pthread_rwlock_unlock(e530de6d038c3578).(&node->rwlockcxx . . $ seltree#rwlock.);
514 pnode = node;
515 }
516 }
517
518 if (check_parent_dirs) {
519 pthread_rwlock_rdlockcxx . . $ pthread_rwlock_rdlock(e530de6d038c3578).(&pnode->rwlockcxx . . $ seltree#rwlock.);
520 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_RULE, "\u2502 check parent directory '%s' for non-recurse match (node: '%s' (%p))", parent, pnode->path, (void*) pnode);
521 match = check_node_for_matchcxx . . $ check_node_for_match(283bceff9a564d1e).(pnode, (file_tcxx . . $ file_t#) { .name = parent, .type = FT_DIRcxx . . $ `include/file.h:32:9`!,
522 #ifdef HAVE_FSTYPEcxx . . $ `./include/config.h:53:9`!
523 .fs_type = 0UL
524 #endif
525 }, whoami);
526 pthread_rwlock_unlockcxx . . $ pthread_rwlock_unlock(e530de6d038c3578).(&pnode->rwlockcxx . . $ seltree#rwlock.);
527 if (match.resultcxx . . $ match_t#result. == RESULT_NON_RECURSIVE_NEGATIVE_MATCHcxx . . $ RESULT_NON_RECURSIVE_NEGATIVE_MATCH.) {
528 match.resultcxx . . $ match_t#result. = RESULT_NEGATIVE_PARENT_MATCHcxx . . $ RESULT_NEGATIVE_PARENT_MATCH.;
529 match.lengthcxx . . $ match_t#length. = parent_length;
530 parent_negative_match = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
531 break;
532 } else if (match.resultcxx . . $ match_t#result. == RESULT_NO_RULE_MATCHcxx . . $ RESULT_NO_RULE_MATCH.) {
533 parent_negative_match = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
534 break;
535 } else {
536 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_RULE, "\u2502 no non-recurse match found for parent directory '%s'", parent);
537 }
538 }
539
540 parent[parent_length] = file.namecxx . . $ file_t#name.[parent_length];
541 relative_child_path = &parent[relative_child_path_start];
542 next_dir += 1;
543 }
544 pthread_rwlock_rdlockcxx . . $ pthread_rwlock_rdlock(e530de6d038c3578).(&pnode->rwlockcxx . . $ seltree#rwlock.);
545 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_TRACE, "\u2502 got parent node '%s' (%p) for parent name '%s'", pnode->path, (void*) pnode, parent);
546 pthread_rwlock_unlockcxx . . $ pthread_rwlock_unlock(e530de6d038c3578).(&pnode->rwlockcxx . . $ seltree#rwlock.);
547 freecxx . . $ free(5d22bdacc48458e8).(parent);
548 if (!parent_negative_match) {
549 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_RULE, "\u2502 check '%s' (filetype: %c)", file.name, get_f_type_char_from_f_type(file.type));
550 match = check_node_for_matchcxx . . $ check_node_for_match(283bceff9a564d1e).(pnode, file, whoami);
551 }
552
553 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_DEBUG, "\u2502 check_selree: match result %s (%d) for '%s'", get_match_result_string(match.result), match.result, file.name);
554 return match;
555 }