Debian Codegraph @

src/OVAL/probes/unix/file_probe.c

raw symbols SCIP
1 /**
2 * @file file_probe.c
3 * @brief file probe
4 * @author "Daniel Kopecek" <[email protected]>
5 *
6 * 2010/06/13 [email protected]
7 * This probe is able to process a file_object as defined in OVAL 5.4 and 5.5.
8 *
9 */
10
11 /*
12 * Copyright 2009 Red Hat Inc., Durham, North Carolina.
13 * All Rights Reserved.
14 *
15 * This library is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License as published by the Free Software Foundation; either
18 * version 2.1 of the License, or (at your option) any later version.
19 *
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
24 *
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28 *
29 * Authors:
30 * "Daniel Kopecek" <[email protected]>
31 */
32
33 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`!
34 #include <config.h>cxx . . $ `<file>/build/config.h`/
35 #endif
36
37 #include "_seap.h"cxx . . $ `<file>/src/OVAL/probes/SEAP/_seap.h`/
38 #include <probe-api.h>cxx . . $ `<file>/src/OVAL/probes/public/probe-api.h`/
39 #include <stdlib.h>
40 #include <string.h>
41 #include <sys/stat.h>
42 #include <pthread.h>
43 #include <errno.h>
44 #include <limits.h>
45
46 #if defined(HAVE_ACL_LIBACL_Hcxx . . $ `build/config.h:77:9`!)
47 # include <sys/types.h>
48 # include <acl/libacl.h>
49 #endif
50
51 #if defined(HAVE_SYS_ACL_Hcxx . . $ `build/config.h:78:9`!) && defined(OS_SOLARIS)
52 # include <sys/acl.h>
53 #endif
54
55 #include <probe/probe.h>cxx . . $ `<file>/src/OVAL/probes/probe/probe.h`/
56 #include <probe/option.h>cxx . . $ `<file>/src/OVAL/probes/probe/option.h`/
57 #include "oval_fts.h"cxx . . $ `<file>/src/OVAL/probes/oval_fts.h`/
58 #include "SEAP/generic/rbt/rbt.h"cxx . . $ `<file>/src/OVAL/probes/SEAP/generic/rbt/rbt.h`/
59 #include "common/debug_priv.h"cxx . . $ `<file>/src/common/debug_priv.h`/
60 #include "file_probe.h"cxx . . $ `<file>/src/OVAL/probes/unix/file_probe.h`/
61
62 #ifndef PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!
63 #define PATH_MAX 4096
64 #endif
65
66 #define FILE_SEPARATORcxx . . $ `src/OVAL/probes/unix/file_probe.c:66:9`! '/'
67
68 #define STR_REGULARcxx . . $ `src/OVAL/probes/unix/file_probe.c:68:9`! "regular"
69 #define STR_DIRECTORYcxx . . $ `src/OVAL/probes/unix/file_probe.c:69:9`! "directory"
70 #define STR_SYMLINKcxx . . $ `src/OVAL/probes/unix/file_probe.c:70:9`! "symbolic link"
71 #define STR_BLKSPECcxx . . $ `src/OVAL/probes/unix/file_probe.c:71:9`! "block special"
72 #define STR_FIFOcxx . . $ `src/OVAL/probes/unix/file_probe.c:72:9`! "fifo"
73 #define STR_SOCKETcxx . . $ `src/OVAL/probes/unix/file_probe.c:73:9`! "socket"
74 #define STR_CHARSPECcxx . . $ `src/OVAL/probes/unix/file_probe.c:74:9`! "character special"
75 #define STRLEN_PAIRcxx . . $ `src/OVAL/probes/unix/file_probe.c:75:9`!(str) (str), strlen(str)
76 #if defined(OS_SOLARIS)
77 #define STR_DOOR "door"
78 #define STR_PORT "port"
79 #endif
80
81 struct gr_sexpscxx . . $ gr_sexps# {
82 SEXP_tcxx . . $ SEXP_t# *gr_t_regcxx . . $ gr_sexps#gr_t_reg.;
83 SEXP_tcxx . . $ SEXP_t# *gr_t_dircxx . . $ gr_sexps#gr_t_dir.;
84 SEXP_tcxx . . $ SEXP_t# *gr_t_lnkcxx . . $ gr_sexps#gr_t_lnk.;
85 SEXP_tcxx . . $ SEXP_t# *gr_t_blkcxx . . $ gr_sexps#gr_t_blk.;
86 SEXP_tcxx . . $ SEXP_t# *gr_t_fifocxx . . $ gr_sexps#gr_t_fifo.;
87 SEXP_tcxx . . $ SEXP_t# *gr_t_sockcxx . . $ gr_sexps#gr_t_sock.;
88 SEXP_tcxx . . $ SEXP_t# *gr_t_charcxx . . $ gr_sexps#gr_t_char.;
89 #if defined(OS_SOLARIS)
90 SEXP_t *gr_t_door;
91 SEXP_t *gr_t_port;
92 #endif
93 };
94
95 static struct gr_sexpscxx . . $ gr_sexps# *gr_sexps_initcxx . . $ gr_sexps_init(f19583c65c203a6d).()
96 {
97 struct gr_sexpscxx . . $ gr_sexps# *s = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(struct gr_sexpscxx . . $ gr_sexps#));
98 s->gr_t_regcxx . . $ gr_sexps#gr_t_reg. = SEXP_string_newcxx . . $ SEXP_string_new(a588a58d7514eee2).(STRLEN_PAIRcxx . . $ `src/OVAL/probes/unix/file_probe.c:75:9`!(STR_REGULARcxx . . $ `src/OVAL/probes/unix/file_probe.c:68:9`!));
99 s->gr_t_dircxx . . $ gr_sexps#gr_t_dir. = SEXP_string_newcxx . . $ SEXP_string_new(a588a58d7514eee2).(STRLEN_PAIRcxx . . $ `src/OVAL/probes/unix/file_probe.c:75:9`!(STR_DIRECTORYcxx . . $ `src/OVAL/probes/unix/file_probe.c:69:9`!));
100 s->gr_t_lnkcxx . . $ gr_sexps#gr_t_lnk. = SEXP_string_newcxx . . $ SEXP_string_new(a588a58d7514eee2).(STRLEN_PAIRcxx . . $ `src/OVAL/probes/unix/file_probe.c:75:9`!(STR_SYMLINKcxx . . $ `src/OVAL/probes/unix/file_probe.c:70:9`!));
101 s->gr_t_blkcxx . . $ gr_sexps#gr_t_blk. = SEXP_string_newcxx . . $ SEXP_string_new(a588a58d7514eee2).(STRLEN_PAIRcxx . . $ `src/OVAL/probes/unix/file_probe.c:75:9`!(STR_BLKSPECcxx . . $ `src/OVAL/probes/unix/file_probe.c:71:9`!));
102 s->gr_t_fifocxx . . $ gr_sexps#gr_t_fifo. = SEXP_string_newcxx . . $ SEXP_string_new(a588a58d7514eee2).(STRLEN_PAIRcxx . . $ `src/OVAL/probes/unix/file_probe.c:75:9`!(STR_FIFOcxx . . $ `src/OVAL/probes/unix/file_probe.c:72:9`!));
103 s->gr_t_sockcxx . . $ gr_sexps#gr_t_sock. = SEXP_string_newcxx . . $ SEXP_string_new(a588a58d7514eee2).(STRLEN_PAIRcxx . . $ `src/OVAL/probes/unix/file_probe.c:75:9`!(STR_SOCKETcxx . . $ `src/OVAL/probes/unix/file_probe.c:73:9`!));
104 s->gr_t_charcxx . . $ gr_sexps#gr_t_char. = SEXP_string_newcxx . . $ SEXP_string_new(a588a58d7514eee2).(STRLEN_PAIRcxx . . $ `src/OVAL/probes/unix/file_probe.c:75:9`!(STR_CHARSPECcxx . . $ `src/OVAL/probes/unix/file_probe.c:74:9`!));
105 #if defined(OS_SOLARIS)
106 s->gr_t_door = SEXP_string_new(STRLEN_PAIR(STR_DOOR));
107 s->gr_t_port = SEXP_string_new(STRLEN_PAIR(STR_PORT));
108 #endif
109 return s;
110 }
111
112 static void gr_sexps_freecxx . . $ gr_sexps_free(d14f47b19e5f0e47).(struct gr_sexpscxx . . $ gr_sexps# *s)
113 {
114 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(s->gr_t_regcxx . . $ gr_sexps#gr_t_reg.);
115 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(s->gr_t_dircxx . . $ gr_sexps#gr_t_dir.);
116 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(s->gr_t_lnkcxx . . $ gr_sexps#gr_t_lnk.);
117 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(s->gr_t_blkcxx . . $ gr_sexps#gr_t_blk.);
118 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(s->gr_t_fifocxx . . $ gr_sexps#gr_t_fifo.);
119 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(s->gr_t_sockcxx . . $ gr_sexps#gr_t_sock.);
120 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(s->gr_t_charcxx . . $ gr_sexps#gr_t_char.);
121 #if defined(OS_SOLARIS)
122 SEXP_free(s->gr_t_door);
123 SEXP_free(s->gr_t_port);
124 #endif
125 freecxx . . $ free(5d22bdacc48458e8).(s);
126 }
127
128 static SEXP_tcxx . . $ SEXP_t# *se_filetypecxx . . $ se_filetype(a5872d784e8f3643).(struct gr_sexpscxx . . $ gr_sexps# *s, mode_tcxx . . $ mode_t# mode)
129 {
130 switch (mode & S_IFMTcxx . . $ `<external>/531885356569766532/stat.h:104:10`!) {
131 case S_IFREGcxx . . $ `<external>/531885356569766532/stat.h:108:10`!:
132 return s->gr_t_regcxx . . $ gr_sexps#gr_t_reg.;
133 case S_IFDIRcxx . . $ `<external>/531885356569766532/stat.h:105:10`!:
134 return s->gr_t_dircxx . . $ gr_sexps#gr_t_dir.;
135 case S_IFLNKcxx . . $ `<external>/531885356569766532/stat.h:113:11`!:
136 return s->gr_t_lnkcxx . . $ gr_sexps#gr_t_lnk.;
137 case S_IFBLKcxx . . $ `<external>/531885356569766532/stat.h:107:10`!:
138 return s->gr_t_blkcxx . . $ gr_sexps#gr_t_blk.;
139 case S_IFIFOcxx . . $ `<external>/531885356569766532/stat.h:110:11`!:
140 return s->gr_t_fifocxx . . $ gr_sexps#gr_t_fifo.;
141 case S_IFSOCKcxx . . $ `<external>/531885356569766532/stat.h:117:11`!:
142 return s->gr_t_sockcxx . . $ gr_sexps#gr_t_sock.;
143 case S_IFCHRcxx . . $ `<external>/531885356569766532/stat.h:106:10`!:
144 return s->gr_t_charcxx . . $ gr_sexps#gr_t_char.;
145 #if defined(OS_SOLARIS)
146 case S_IFDOOR:
147 return s->gr_t_door;
148 case S_IFPORT:
149 return s->gr_t_port;
150 #endif
151 default:
152 abortcxx . . $ abort(8df32a62017fbbf6). ();
153 }
154 /* NOTREACHED */
155 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
156 }
157
158 struct cbargscxx . . $ cbargs# {
159 probe_ctxcxx . . $ probe_ctx# *ctxcxx . . $ cbargs#ctx.;
160 int errorcxx . . $ cbargs#error.;
161 };
162
163 struct ID_cachecxx . . $ ID_cache# {
164 rbt_tcxx . . $ rbt_t# *treecxx . . $ ID_cache#tree.;
165 uint32_tcxx . . $ uint32_t# maxcxx . . $ ID_cache#max.;
166 };
167
168 static SEXP_tcxx . . $ SEXP_t# *ID_cache_getcxx . . $ ID_cache_get(6fe81a833b32a07e).(struct ID_cachecxx . . $ ID_cache# *cache, int32_tcxx . . $ int32_t# id, oval_schema_version_tcxx . . $ oval_schema_version_t# over)
169 {
170 SEXP_tcxx . . $ SEXP_t# *s_id = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, *s_id2 = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
171
172 if (rbt_i32_getcxx . . $ rbt_i32_get(fbdfcf5a3c6c46ec).(cache->treecxx . . $ ID_cache#tree., id, (void *)&s_id) == 0)
173 return SEXP_refcxx . . $ SEXP_ref(2f7f980afaaae0f0).(s_id); /* cache hit (first attempt) */
174
175 if (oval_schema_version_cmpcxx . . $ oval_schema_version_cmp(b4d0c2bfb97f274f).(over, OVAL_SCHEMA_VERSIONcxx . . $ `src/OVAL/public/oval_schema_version.h:39:9`!(5.8)) < 0) {
176 s_id = SEXP_string_newfcxx . . $ SEXP_string_newf(b2137ed863725962).("%u", id);
177 } else {
178 s_id = SEXP_number_newu_32cxx . . $ SEXP_number_newu_32(8a1232211d6fd92a).(id);
179 }
180
181 if (cache->maxcxx . . $ ID_cache#max. == 0 || rbt_i32_sizecxx . . $ rbt_i32_size(6ae908cc234686bf).(cache->treecxx . . $ ID_cache#tree.) < cache->maxcxx . . $ ID_cache#max.) {
182 if (rbt_i32_addcxx . . $ rbt_i32_add(3215e2e734e57b31).(cache->treecxx . . $ ID_cache#tree., id, (void *)s_id, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) == 0)
183 return SEXP_refcxx . . $ SEXP_ref(2f7f980afaaae0f0).(s_id); /* insert succeeded */
184
185 if (rbt_i32_getcxx . . $ rbt_i32_get(fbdfcf5a3c6c46ec).(cache->treecxx . . $ ID_cache#tree., id, (void *)&s_id2) == 0) {
186 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4). (s_id); /* cache hit (second attempt) */
187 return SEXP_refcxx . . $ SEXP_ref(2f7f980afaaae0f0).(s_id2);
188 }
189 }
190
191 /* fallback */
192 return (s_id);
193 }
194
195 static struct ID_cachecxx . . $ ID_cache# *ID_cache_initcxx . . $ ID_cache_init(533d61ea28805df8).(uint32_tcxx . . $ uint32_t# max)
196 {
197 struct ID_cachecxx . . $ ID_cache# *cache = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(struct ID_cachecxx . . $ ID_cache#));
198 cache->maxcxx . . $ ID_cache#max. = max;
199 cache->treecxx . . $ ID_cache#tree. = rbt_i32_newcxx . . $ rbt_i32_new(557e4aca7c153cb).();
200 return cache;
201 }
202
203 static void ID_cache_free_cbcxx . . $ ID_cache_free_cb(5d3939e05c3402e7).(rbt_i32_node_tcxx . . $ rbt_i32_node_t# *n)
204 {
205 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(n->datacxx . . $ rbt_i32_node#data.);
206 }
207
208 static void ID_cache_freecxx . . $ ID_cache_free(9f6544478c2a54b).(struct ID_cachecxx . . $ ID_cache# *cache)
209 {
210 rbt_i32_free_cbcxx . . $ rbt_i32_free_cb(bb6fef081ac885b3).(cache->treecxx . . $ ID_cache#tree., ID_cache_free_cbcxx . . $ ID_cache_free_cb(5d3939e05c3402e7).);
211 freecxx . . $ free(5d22bdacc48458e8).(cache);
212 }
213
214 static SEXP_tcxx . . $ SEXP_t# *get_atimecxx . . $ get_atime(d555d27c05c733fb).(struct statcxx . . $ stat# *st, SEXP_tcxx . . $ SEXP_t# *sexp, oval_schema_version_tcxx . . $ oval_schema_version_t# over)
215 {
216 uint64_tcxx . . $ uint64_t# t = (
217 #if defined(OS_FREEBSD)
218 (uint64_t) st->st_atimespec.tv_sec
219 #elif defined(OS_LINUXcxx . . $ `compat/oscap_platforms.h:38:10`!) || defined(OS_SOLARIS)
220 (uint64_tcxx . . $ uint64_t#) st->st_atimcxx . . $ stat#st_atim..tv_seccxx . . $ timespec#tv_sec.
221 #else /* Use the legacy field */
222 (uint64_t) st->st_atime
223 #endif
224 );
225
226 if (oval_schema_version_cmpcxx . . $ oval_schema_version_cmp(b4d0c2bfb97f274f).(over, OVAL_SCHEMA_VERSIONcxx . . $ `src/OVAL/public/oval_schema_version.h:39:9`!(5.8)) < 0) {
227 return SEXP_string_newf_rcxx . . $ SEXP_string_newf_r(f7254ae56fe447d7).(sexp, "%llu", (long long unsigned) t);
228 } else {
229 return SEXP_number_newu_64_rcxx . . $ SEXP_number_newu_64_r(529ea53413afaf2).(sexp, t);
230 }
231 }
232
233 static SEXP_tcxx . . $ SEXP_t# *get_ctimecxx . . $ get_ctime(d555d27c05c733fb).(struct statcxx . . $ stat# *st, SEXP_tcxx . . $ SEXP_t# *sexp, oval_schema_version_tcxx . . $ oval_schema_version_t# over)
234 {
235 uint64_tcxx . . $ uint64_t# t = (
236 #if defined(OS_FREEBSD)
237 (uint64_t) st->st_ctimespec.tv_sec
238 #elif defined(OS_LINUXcxx . . $ `compat/oscap_platforms.h:38:10`!) || defined(OS_SOLARIS)
239 (uint64_tcxx . . $ uint64_t#) st->st_ctimcxx . . $ stat#st_ctim..tv_seccxx . . $ timespec#tv_sec.
240 #else /* Use the legacy field */
241 (uint64_t) st->st_ctime
242 #endif
243 );
244
245 if (oval_schema_version_cmpcxx . . $ oval_schema_version_cmp(b4d0c2bfb97f274f).(over, OVAL_SCHEMA_VERSIONcxx . . $ `src/OVAL/public/oval_schema_version.h:39:9`!(5.8)) < 0) {
246 return SEXP_string_newf_rcxx . . $ SEXP_string_newf_r(f7254ae56fe447d7).(sexp, "%llu", (long long unsigned) t);
247 } else {
248 return SEXP_number_newu_64_rcxx . . $ SEXP_number_newu_64_r(529ea53413afaf2).(sexp, t);
249 }
250 }
251
252 static SEXP_tcxx . . $ SEXP_t# *get_mtimecxx . . $ get_mtime(d555d27c05c733fb).(struct statcxx . . $ stat# *st, SEXP_tcxx . . $ SEXP_t# *sexp, oval_schema_version_tcxx . . $ oval_schema_version_t# over)
253 {
254 uint64_tcxx . . $ uint64_t# t = (
255 #if defined(OS_FREEBSD)
256 (uint64_t) st->st_mtimespec.tv_sec
257 #elif defined(OS_LINUXcxx . . $ `compat/oscap_platforms.h:38:10`!) || defined(OS_SOLARIS)
258 (uint64_tcxx . . $ uint64_t#) st->st_mtimcxx . . $ stat#st_mtim..tv_seccxx . . $ timespec#tv_sec.
259 #else /* Use the legacy field */
260 (uint64_t) st->st_mtime
261 #endif
262 );
263
264 if (oval_schema_version_cmpcxx . . $ oval_schema_version_cmp(b4d0c2bfb97f274f).(over, OVAL_SCHEMA_VERSIONcxx . . $ `src/OVAL/public/oval_schema_version.h:39:9`!(5.8)) < 0) {
265 return SEXP_string_newf_rcxx . . $ SEXP_string_newf_r(f7254ae56fe447d7).(sexp, "%llu", (long long unsigned) t);
266 } else {
267 return SEXP_number_newu_64_rcxx . . $ SEXP_number_newu_64_r(529ea53413afaf2).(sexp, t);
268 }
269 }
270
271 static SEXP_tcxx . . $ SEXP_t# *get_sizecxx . . $ get_size(283fb60bfd223c23).(struct statcxx . . $ stat# *st, SEXP_tcxx . . $ SEXP_t# *sexp)
272 {
273 switch (sizeof(st->st_sizecxx . . $ stat#st_size.)) {
274 case 8:
275 return SEXP_number_newu_64_rcxx . . $ SEXP_number_newu_64_r(529ea53413afaf2).(sexp, st->st_sizecxx . . $ stat#st_size.);
276 case 4:
277 return SEXP_number_newu_32_rcxx . . $ SEXP_number_newu_32_r(3d152c928d5432a1).(sexp, st->st_sizecxx . . $ stat#st_size.);
278 default: /* Should not happen. */
279 abortcxx . . $ abort(8df32a62017fbbf6).();
280
281 /* NOTREACHED */
282 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
283 }
284 }
285
286 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! MODEPcxx . . $ MODEP(caac88c1706b39df).(struct statcxx . . $ stat# *statp, unsigned int bit)
287 {
288 return (statp->st_modecxx . . $ stat#st_mode. & bit);
289 }
290
291 static SEXP_tcxx . . $ SEXP_t# *has_extended_aclcxx . . $ has_extended_acl(b11f8c5057ee8d85).(const char *path)
292 {
293 #if defined(HAVE_ACL_EXTENDED_FILEcxx . . $ `build/config.h:35:9`!)
294 int has_acl = acl_extended_filecxx . . $ acl_extended_file(5c4306d8553b3696).(path);
295 if (has_acl == -1) {
296 dDcxx . . $ `src/common/debug_priv.h:64:9`!("Getting extended ACL for file '%s' has failed, %s", path, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
297 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
298 }
299 return (has_acl == 1) ? SEXP_number_newbcxx . . $ SEXP_number_newb(f1e7d218d08e4133).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!) : SEXP_number_newbcxx . . $ SEXP_number_newb(f1e7d218d08e4133).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!);
300 #elif defined(OS_SOLARIS)
301 return acl_trivial(path) ? SEXP_number_newb(true) : SEXP_number_newb(false);
302 #else
303 return NULL;
304 #endif
305 }
306
307 static int file_cbcxx . . $ file_cb(70c5008b100fad3a).(const char *prefix, const char *p, const char *f, void *ptr, oval_schema_version_tcxx . . $ oval_schema_version_t# over, struct ID_cachecxx . . $ ID_cache# *cache, struct gr_sexpscxx . . $ gr_sexps# *grs, SEXP_tcxx . . $ SEXP_t# *gr_lastpath, struct oscap_listcxx . . $ oscap_list# *blocked_paths)
308 {
309 char path_buffer[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!];
310 SEXP_tcxx . . $ SEXP_t# *item;
311 struct cbargscxx . . $ cbargs# *args = (struct cbargscxx . . $ cbargs# *) ptr;
312 struct statcxx . . $ stat# st;
313 const char *st_path;
314
315 if (f == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
316 st_path = p;
317 } else {
318 const size_t p_len = strlencxx . . $ strlen(751346f8406fd082).(p);
319 /* Avoid 2 slashes */
320 if (p_len >= 1 && p[p_len - 1] == FILE_SEPARATORcxx . . $ `src/OVAL/probes/unix/file_probe.c:66:9`!) {
321 snprintfcxx . . $ snprintf(ea502d73e74c754c).(path_buffer, sizeof path_buffer, "%s%s", p, f);
322 } else {
323 snprintfcxx . . $ snprintf(ea502d73e74c754c).(path_buffer, sizeof path_buffer, "%s%c%s", p, FILE_SEPARATORcxx . . $ `src/OVAL/probes/unix/file_probe.c:66:9`!, f);
324 }
325 st_path = path_buffer;
326 }
327
328 if (probe_path_is_blockedcxx . . $ probe_path_is_blocked(6f786adec44f4a13).(st_path, blocked_paths)) {
329 return 0;
330 }
331
332 char *st_path_with_prefix = oscap_path_joincxx . . $ oscap_path_join(a713fe7b9a57cf96).(prefix, st_path);
333 if (lstatcxx . . $ lstat(a9cd1e23e96f423c).(st_path_with_prefix, &st) == -1) {
334 dDcxx . . $ `src/common/debug_priv.h:64:9`!("lstat failed when processing %s: errno=%u, %s.", st_path, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, strerror (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
335 /*
336 * Whatever the reason of this lstat error (for example the file may
337 * have disappeared) we don't want it to stop the whole file tree walk;
338 * so we just don't report the error.
339 */
340 freecxx . . $ free(5d22bdacc48458e8).(st_path_with_prefix);
341 return 0;
342 } else {
343 SEXP_tcxx . . $ SEXP_t# *se_usr_id, *se_grp_id;
344 SEXP_tcxx . . $ SEXP_t# se_atime_mem, se_ctime_mem, se_mtime_mem, se_size_mem;
345 SEXP_tcxx . . $ SEXP_t# *se_filepath, *se_acl;
346
347 if (oval_schema_version_cmpcxx . . $ oval_schema_version_cmp(b4d0c2bfb97f274f).(over, OVAL_SCHEMA_VERSIONcxx . . $ `src/OVAL/public/oval_schema_version.h:39:9`!(5.6)) < 0
348 || f == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
349 se_filepath = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
350 } else {
351 se_filepath = SEXP_string_newfcxx . . $ SEXP_string_newf(b2137ed863725962).("%s", st_path);
352 }
353
354 se_usr_id = ID_cache_getcxx . . $ ID_cache_get(6fe81a833b32a07e).(cache, st.st_uidcxx . . $ stat#st_uid., over);
355 se_grp_id = st.st_gidcxx . . $ stat#st_gid. != st.st_uidcxx . . $ stat#st_uid. ? ID_cache_getcxx . . $ ID_cache_get(6fe81a833b32a07e).(cache, st.st_gidcxx . . $ stat#st_gid., over) : SEXP_refcxx . . $ SEXP_ref(2f7f980afaaae0f0).(se_usr_id);
356
357 if (!SEXP_emptypcxx . . $ SEXP_emptyp(48c7cf01dfc2748d).(gr_lastpath)) {
358 if (SEXP_strcmpcxx . . $ SEXP_strcmp(3ef1a37bcb3c2a).(gr_lastpath, p) != 0) {
359 SEXP_free_rcxx . . $ SEXP_free_r(c6b28547479798f4).(gr_lastpath);
360 SEXP_string_new_rcxx . . $ SEXP_string_new_r(26dc94eb5d76b6d1).(gr_lastpath, p, strlencxx . . $ strlen(751346f8406fd082).(p));
361 }
362 } else
363 SEXP_string_new_rcxx . . $ SEXP_string_new_r(26dc94eb5d76b6d1).(gr_lastpath, p, strlencxx . . $ strlen(751346f8406fd082).(p));
364
365 if (oval_schema_version_cmpcxx . . $ oval_schema_version_cmp(b4d0c2bfb97f274f).(over, OVAL_SCHEMA_VERSIONcxx . . $ `src/OVAL/public/oval_schema_version.h:39:9`!(5.7)) < 0) {
366 se_acl = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
367 } else {
368 se_acl = has_extended_aclcxx . . $ has_extended_acl(b11f8c5057ee8d85).(st_path_with_prefix);
369 }
370 freecxx . . $ free(5d22bdacc48458e8).(st_path_with_prefix);
371
372 item = probe_item_createcxx . . $ probe_item_create(36b16a6622050a9c).(OVAL_UNIX_FILEcxx . . $ OVAL_UNIX_FILE., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!,
373 "filepath", OVAL_DATATYPE_SEXPcxx . . $ OVAL_DATATYPE_SEXP., se_filepath,
374 "path", OVAL_DATATYPE_SEXPcxx . . $ OVAL_DATATYPE_SEXP., gr_lastpath,
375 "filename", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., f == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! ? "" : f,
376 "type", OVAL_DATATYPE_SEXPcxx . . $ OVAL_DATATYPE_SEXP., se_filetypecxx . . $ se_filetype(a5872d784e8f3643).(grs, st.st_modecxx . . $ stat#st_mode.),
377 "group_id", OVAL_DATATYPE_SEXPcxx . . $ OVAL_DATATYPE_SEXP., se_grp_id,
378 "user_id", OVAL_DATATYPE_SEXPcxx . . $ OVAL_DATATYPE_SEXP., se_usr_id,
379 "a_time", OVAL_DATATYPE_SEXPcxx . . $ OVAL_DATATYPE_SEXP., get_atimecxx . . $ get_atime(d555d27c05c733fb).(&st, &se_atime_mem, over),
380 "c_time", OVAL_DATATYPE_SEXPcxx . . $ OVAL_DATATYPE_SEXP., get_ctimecxx . . $ get_ctime(d555d27c05c733fb).(&st, &se_ctime_mem, over),
381 "m_time", OVAL_DATATYPE_SEXPcxx . . $ OVAL_DATATYPE_SEXP., get_mtimecxx . . $ get_mtime(d555d27c05c733fb).(&st, &se_mtime_mem, over),
382 "size", OVAL_DATATYPE_SEXPcxx . . $ OVAL_DATATYPE_SEXP., get_sizecxx . . $ get_size(283fb60bfd223c23).(&st, &se_size_mem),
383 "suid", OVAL_DATATYPE_BOOLEANcxx . . $ OVAL_DATATYPE_BOOLEAN., MODEPcxx . . $ MODEP(caac88c1706b39df).(&st, S_ISUIDcxx . . $ `<external>/531885356569766532/stat.h:160:9`!),
384 "sgid", OVAL_DATATYPE_BOOLEANcxx . . $ OVAL_DATATYPE_BOOLEAN., MODEPcxx . . $ MODEP(caac88c1706b39df).(&st, S_ISGIDcxx . . $ `<external>/531885356569766532/stat.h:161:9`!),
385 "sticky", OVAL_DATATYPE_BOOLEANcxx . . $ OVAL_DATATYPE_BOOLEAN., MODEPcxx . . $ MODEP(caac88c1706b39df).(&st, S_ISVTXcxx . . $ `<external>/531885356569766532/stat.h:165:10`!),
386 "uread", OVAL_DATATYPE_BOOLEANcxx . . $ OVAL_DATATYPE_BOOLEAN., MODEPcxx . . $ MODEP(caac88c1706b39df).(&st, S_IRUSRcxx . . $ `<external>/531885356569766532/stat.h:168:9`!),
387 "uwrite", OVAL_DATATYPE_BOOLEANcxx . . $ OVAL_DATATYPE_BOOLEAN., MODEPcxx . . $ MODEP(caac88c1706b39df).(&st, S_IWUSRcxx . . $ `<external>/531885356569766532/stat.h:169:9`!),
388 "uexec", OVAL_DATATYPE_BOOLEANcxx . . $ OVAL_DATATYPE_BOOLEAN., MODEPcxx . . $ MODEP(caac88c1706b39df).(&st, S_IXUSRcxx . . $ `<external>/531885356569766532/stat.h:170:9`!),
389 "gread", OVAL_DATATYPE_BOOLEANcxx . . $ OVAL_DATATYPE_BOOLEAN., MODEPcxx . . $ MODEP(caac88c1706b39df).(&st, S_IRGRPcxx . . $ `<external>/531885356569766532/stat.h:180:9`!),
390 "gwrite", OVAL_DATATYPE_BOOLEANcxx . . $ OVAL_DATATYPE_BOOLEAN., MODEPcxx . . $ MODEP(caac88c1706b39df).(&st, S_IWGRPcxx . . $ `<external>/531885356569766532/stat.h:181:9`!),
391 "gexec", OVAL_DATATYPE_BOOLEANcxx . . $ OVAL_DATATYPE_BOOLEAN., MODEPcxx . . $ MODEP(caac88c1706b39df).(&st, S_IXGRPcxx . . $ `<external>/531885356569766532/stat.h:182:9`!),
392 "oread", OVAL_DATATYPE_BOOLEANcxx . . $ OVAL_DATATYPE_BOOLEAN., MODEPcxx . . $ MODEP(caac88c1706b39df).(&st, S_IROTHcxx . . $ `<external>/531885356569766532/stat.h:186:9`!),
393 "owrite", OVAL_DATATYPE_BOOLEANcxx . . $ OVAL_DATATYPE_BOOLEAN., MODEPcxx . . $ MODEP(caac88c1706b39df).(&st, S_IWOTHcxx . . $ `<external>/531885356569766532/stat.h:187:9`!),
394 "oexec", OVAL_DATATYPE_BOOLEANcxx . . $ OVAL_DATATYPE_BOOLEAN., MODEPcxx . . $ MODEP(caac88c1706b39df).(&st, S_IXOTHcxx . . $ `<external>/531885356569766532/stat.h:188:9`!),
395 "has_extended_acl", OVAL_DATATYPE_SEXPcxx . . $ OVAL_DATATYPE_SEXP., se_acl,
396 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
397 if (se_acl == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
398 SEXP_tcxx . . $ SEXP_t# *sexp_true = SEXP_number_newbcxx . . $ SEXP_number_newb(f1e7d218d08e4133).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!);
399 probe_item_ent_addcxx . . $ probe_item_ent_add(9f488d3b029fc9d1).(item, "has_extended_acl", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, sexp_true);
400 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(sexp_true);
401 probe_itement_setstatuscxx . . $ probe_itement_setstatus(998e25cd01fde21b).(item, "has_extended_acl", 1, SYSCHAR_STATUS_DOES_NOT_EXISTcxx . . $ SYSCHAR_STATUS_DOES_NOT_EXIST.);
402 } else {
403 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(se_acl);
404 }
405
406 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(se_grp_id);
407 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(se_usr_id);
408 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(se_filepath);
409 SEXP_free_rcxx . . $ SEXP_free_r(c6b28547479798f4).(&se_atime_mem);
410 SEXP_free_rcxx . . $ SEXP_free_r(c6b28547479798f4).(&se_ctime_mem);
411 SEXP_free_rcxx . . $ SEXP_free_r(c6b28547479798f4).(&se_mtime_mem);
412 SEXP_free_rcxx . . $ SEXP_free_r(c6b28547479798f4).(&se_size_mem);
413
414 /*
415 * Stop collecting if we hit the memory usage limit
416 * (return code == 2)
417 */
418 return probe_item_collectcxx . . $ probe_item_collect(11bb80e0c30650d7).(args->ctxcxx . . $ cbargs#ctx., item) == 2 ? 1 : 0;
419 }
420
421 return (0);
422 }
423
424
425 int file_probe_offline_mode_supportedcxx . . $ file_probe_offline_mode_supported(b126dc7c1de90089).()
426 {
427 return PROBE_OFFLINE_OWNcxx . . $ PROBE_OFFLINE_OWN.;
428 }
429
430 void *file_probe_initcxx . . $ file_probe_init(50c7df7de5344ebb).(void)
431 {
432 /*
433 * Initialize mutex.
434 */
435 pthread_mutex_tcxx . . $ pthread_mutex_t# *file_probe_mutex = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(pthread_mutex_tcxx . . $ pthread_mutex_t#));
436 switch (pthread_mutex_initcxx . . $ pthread_mutex_init(db9d29dab44ea1aa). (file_probe_mutex, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)) {
437 case 0:
438 return ((void *)file_probe_mutex);
439 default:
440 freecxx . . $ free(5d22bdacc48458e8).(file_probe_mutex);
441 dDcxx . . $ `src/common/debug_priv.h:64:9`!("Can't initialize mutex: errno=%u, %s.", errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, strerror (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
442 }
443 #if 0
444 probe_setoption(PROBEOPT_VARREF_HANDLING, false, "path");
445 probe_setoption(PROBEOPT_VARREF_HANDLING, false, "filename");
446 #endif
447 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
448 }
449
450 void file_probe_finicxx . . $ file_probe_fini(5d22bdacc48458e8).(void *arg)
451 {
452 /*
453 * Destroy mutex.
454 */
455 (void) pthread_mutex_destroycxx . . $ pthread_mutex_destroy(d89ae235521888f9).((pthread_mutex_tcxx . . $ pthread_mutex_t# *)arg);
456 freecxx . . $ free(5d22bdacc48458e8).(arg);
457 }
458
459 int file_probe_maincxx . . $ file_probe_main(470536d3ffacaf10).(probe_ctxcxx . . $ probe_ctx# *ctx, void *mutex)
460 {
461 SEXP_tcxx . . $ SEXP_t# *path, *filename, *behaviors, *filepath, *probe_in;
462 int err;
463 struct cbargscxx . . $ cbargs# cbargs;
464 OVAL_FTScxx . . $ OVAL_FTS# *ofts;
465 OVAL_FTSENTcxx . . $ OVAL_FTSENT# *ofts_ent;
466
467 if (mutex == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
468 return PROBE_EINITcxx . . $ `src/OVAL/probes/public/probe-common.h:12:9`!;
469 }
470
471 probe_in = probe_ctx_getobjectcxx . . $ probe_ctx_getobject(4299b6b53fa804a5).(ctx);
472
473 oval_schema_version_tcxx . . $ oval_schema_version_t# over = probe_obj_get_platform_schema_versioncxx . . $ probe_obj_get_platform_schema_version(5bacca80194debea).(probe_in);
474 path = probe_obj_getentcxx . . $ probe_obj_getent(7907a01f2ff841f3). (probe_in, "path", 1);
475 filename = probe_obj_getentcxx . . $ probe_obj_getent(7907a01f2ff841f3). (probe_in, "filename", 1);
476 behaviors = probe_obj_getentcxx . . $ probe_obj_getent(7907a01f2ff841f3). (probe_in, "behaviors", 1);
477 filepath = probe_obj_getentcxx . . $ probe_obj_getent(7907a01f2ff841f3). (probe_in, "filepath", 1);
478
479 /* we want either path+filename or filepath */
480 if ( (path == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || filename == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) && filepath==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! ) {
481 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4). (behaviors);
482 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4). (path);
483 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4). (filename);
484 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4). (filepath);
485
486 return PROBE_ENOELMcxx . . $ `src/OVAL/probes/public/probe-common.h:9:9`!;
487 }
488
489 probe_filebehaviors_canonicalizecxx . . $ probe_filebehaviors_canonicalize(e661f441b24a5de6).(&behaviors);
490
491 switch (pthread_mutex_lockcxx . . $ pthread_mutex_lock(d89ae235521888f9). (mutex)) {
492 case 0:
493 break;
494 default:
495 dDcxx . . $ `src/common/debug_priv.h:64:9`!("Can't lock mutex(%p): %u, %s.", mutex, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, strerror (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
496
497 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(path);
498 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(filename);
499 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(filepath);
500 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(behaviors);
501
502 return PROBE_EFATALcxx . . $ `src/OVAL/probes/public/probe-common.h:23:9`!;
503 }
504
505 cbargs.ctxcxx . . $ cbargs#ctx. = ctx;
506 cbargs.errorcxx . . $ cbargs#error. = 0;
507
508 const char *prefix = getenvcxx . . $ getenv(a8b8e32347182212).("OSCAP_PROBE_ROOT");
509 SEXP_tcxx . . $ SEXP_t# gr_lastpath;
510 SEXP_initcxx . . $ SEXP_init(478b347fcbbad3c5).(&gr_lastpath);
511 struct ID_cachecxx . . $ ID_cache# *cache = ID_cache_initcxx . . $ ID_cache_init(533d61ea28805df8).(10000);
512 struct gr_sexpscxx . . $ gr_sexps# *grs = gr_sexps_initcxx . . $ gr_sexps_init(f19583c65c203a6d).();
513
514 if ((ofts = oval_fts_open_prefixedcxx . . $ oval_fts_open_prefixed(d2d91f0fe545c5d7).(prefix, path, filename, filepath, behaviors, probe_ctx_getresultcxx . . $ probe_ctx_getresult(4299b6b53fa804a5).(ctx))) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
515 while ((ofts_ent = oval_fts_readcxx . . $ oval_fts_read(592d87f37bbdbe51).(ofts)) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
516 if (file_cbcxx . . $ file_cb(70c5008b100fad3a).(prefix, ofts_ent->pathcxx . . $ $anonymous_type_ebdee0feb58b991e_1#path., ofts_ent->filecxx . . $ $anonymous_type_ebdee0feb58b991e_1#file., &cbargs, over, cache, grs, &gr_lastpath, ctx->blocked_pathscxx . . $ probe_ctx#blocked_paths.) != 0) {
517 oval_ftsent_freecxx . . $ oval_ftsent_free(7e09326da17d8ab0).(ofts_ent);
518 break;
519 }
520 oval_ftsent_freecxx . . $ oval_ftsent_free(7e09326da17d8ab0).(ofts_ent);
521 }
522 oval_fts_closecxx . . $ oval_fts_close(cd898f79c195c42c).(ofts);
523 }
524 ID_cache_freecxx . . $ ID_cache_free(9f6544478c2a54b).(cache);
525 gr_sexps_freecxx . . $ gr_sexps_free(d14f47b19e5f0e47).(grs);
526
527 if (!SEXP_emptypcxx . . $ SEXP_emptyp(48c7cf01dfc2748d).(&gr_lastpath))
528 SEXP_free_rcxx . . $ SEXP_free_r(c6b28547479798f4).(&gr_lastpath);
529
530 err = 0;
531
532 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(path);
533 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(filename);
534 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(filepath);
535 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(behaviors);
536
537 switch (pthread_mutex_unlockcxx . . $ pthread_mutex_unlock(d89ae235521888f9). (mutex)) {
538 case 0:
539 break;
540 default:
541 dDcxx . . $ `src/common/debug_priv.h:64:9`!("Can't unlock mutex(%p): %u, %s.", mutex, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, strerror (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
542
543 return PROBE_EFATALcxx . . $ `src/OVAL/probes/public/probe-common.h:23:9`!;
544 }
545
546 return err;
547 }