Debian Codegraph @

src/OVAL/probes/probe/probe_main.c

raw symbols SCIP
1 /*
2 * Copyright 2011 Red Hat Inc., Durham, North Carolina.
3 * All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 * Authors:
20 * Daniel Kopecek <[email protected]>
21 * Tomas Heinrich <[email protected]>
22 */
23 #include <config.h>cxx . . $ `<file>/build/config.h`/
24 #if !defined(_GNU_SOURCEcxx . . $ `<built-in>:422:9`!)
25 # if defined(HAVE_PTHREAD_TIMEDJOIN_NP) && defined(HAVE_CLOCK_GETTIME)
26 # define _GNU_SOURCE
27 # endif
28 #endif
29 #include <stdio.h>
30 #include <string.h>
31 #include <signal.h>
32 #include <pthread.h>
33 #include <errno.h>
34 #include <fcntl.h>
35 #include "_seap.h"cxx . . $ `<file>/src/OVAL/probes/SEAP/_seap.h`/
36 #include "common/bfind.h"cxx . . $ `<file>/src/common/bfind.h`/
37 #include "probe.h"cxx . . $ `<file>/src/OVAL/probes/probe/probe.h`/
38 #include "ncache.h"cxx . . $ `<file>/src/OVAL/probes/probe/ncache.h`/
39 #include "rcache.h"cxx . . $ `<file>/src/OVAL/probes/probe/rcache.h`/
40 #include "icache.h"cxx . . $ `<file>/src/OVAL/probes/probe/icache.h`/
41 #include "worker.h"cxx . . $ `<file>/src/OVAL/probes/probe/worker.h`/
42 #include "input_handler.h"cxx . . $ `<file>/src/OVAL/probes/probe/input_handler.h`/
43 #include "probe-api.h"cxx . . $ `<file>/src/OVAL/probes/public/probe-api.h`/
44 #include "option.h"cxx . . $ `<file>/src/OVAL/probes/probe/option.h`/
45 #include <oscap_debug.h>cxx . . $ `<file>/src/common/public/oscap_debug.h`/
46 #include "debug_priv.h"cxx . . $ `<file>/src/common/debug_priv.h`/
47
48 #if defined(OS_FREEBSD)
49 #include <pthread_np.h>
50 #endif
51
52 #ifdef OS_WINDOWS
53 #define STDIN_FILENO _fileno(stdin)
54 #define STDOUT_FILENO _fileno(stdout)
55 #else
56 #include <unistd.h>
57 #endif
58
59 #include "probe_main.h"cxx . . $ `<file>/src/OVAL/probes/probe/probe_main.h`/
60 #include "seap-descriptor.h"cxx . . $ `<file>/src/OVAL/probes/SEAP/seap-descriptor.h`/
61 #include "probe-table.h"cxx . . $ `<file>/src/OVAL/probes/public/probe-table.h`/
62
63 static int failcxx . . $ fail(50b278ac4ac9ad96).(int err, const char *who, int line)
64 {
65 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "FAIL: %d:%s: %d, %s\n", line, who, err, strerrorcxx . . $ strerror(ff224f080444ee45).(err));
66 exitcxx . . $ exit(3ca292c338df9bb3).(err);
67 }
68
69 void *OSCAP_GSYMcxx . . $ `src/common/util.h:444:9`!(probe_arg) = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
70 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! OSCAP_GSYMcxx . . $ `src/common/util.h:444:9`!(varref_handling) = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
71 char **OSCAP_GSYMcxx . . $ `src/common/util.h:444:9`!(no_varref_ents) = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
72 size_t OSCAP_GSYMcxx . . $ `src/common/util.h:444:9`!(no_varref_ents_cnt) = 0;
73
74 extern probe_ncache_tcxx . . $ probe_ncache_t# *OSCAP_GSYMcxx . . $ `src/common/util.h:444:9`!(ncache);
75
76 static int probe_optecmpcxx . . $ probe_optecmp(1c2bee554d4ac597).(char **a, char **b)
77 {
78 return strcmpcxx . . $ strcmp(5ae29d726ae57f88).(*a, *b);
79 }
80
81 static SEXP_tcxx . . $ SEXP_t# *probe_resetcxx . . $ probe_reset(313521213da5ee5).(SEXP_tcxx . . $ SEXP_t# *arg0, void *arg1)
82 {
83 probe_tcxx . . $ probe_t# *probe = (probe_tcxx . . $ probe_t# *)arg1;
84 /*
85 * FIXME: implement main loop locking & worker waiting
86 */
87 probe_rcache_freecxx . . $ probe_rcache_free(746d67ca65c3914d).(probe->rcachecxx . . $ $anonymous_type_3aeea60fe9979420_0#rcache.);
88
89 probe->rcachecxx . . $ $anonymous_type_3aeea60fe9979420_0#rcache. = probe_rcache_newcxx . . $ probe_rcache_new(828cb6e43476d228).();
90 probe_ncache_clearcxx . . $ probe_ncache_clear(c0ad2c06e7dc4d8f).(OSCAP_GSYMcxx . . $ `src/common/util.h:444:9`!(ncache));
91 probe->ncachecxx . . $ $anonymous_type_3aeea60fe9979420_0#ncache. = OSCAP_GSYMcxx . . $ `src/common/util.h:444:9`!(ncache);
92
93 return(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
94 }
95
96 static int probe_opthandler_varrefcxx . . $ probe_opthandler_varref(4150cf18850aca74).(int option, int op, va_listcxx . . $ va_list# args)
97 {
98 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! o_switch;
99 char *o_name;
100 char *o_temp;
101
102 if (op == PROBE_OPTION_GETcxx . . $ `src/OVAL/probes/probe/option.h:8:9`!)
103 return -1;
104
105 o_switch = va_argcxx . . $ `<external>/8105065126723003039/stdarg.h:53:9`!(args, int);
106 o_name = va_argcxx . . $ `<external>/8105065126723003039/stdarg.h:53:9`!(args, char *);
107
108 if (o_name == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
109 /* switch varref handling on/off globally */
110 OSCAP_GSYMcxx . . $ `src/common/util.h:444:9`!(varref_handling) = o_switch;
111 return (0);
112 }
113
114 o_temp = oscap_bfindcxx . . $ oscap_bfind(55e9dbee426f048c). (OSCAP_GSYMcxx . . $ `src/common/util.h:444:9`!(no_varref_ents), OSCAP_GSYMcxx . . $ `src/common/util.h:444:9`!(no_varref_ents_cnt),
115 sizeof(char *), o_name, (int(*)(void *, void *)) &probe_optecmpcxx . . $ probe_optecmp(1c2bee554d4ac597).);
116
117 if (o_temp != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
118 return (0);
119
120 void *new_no_varref_ents = realloccxx . . $ realloc(417ab160f6baadc6).(OSCAP_GSYMcxx . . $ `src/common/util.h:444:9`!(no_varref_ents),
121 sizeof (char *) * (OSCAP_GSYMcxx . . $ `src/common/util.h:444:9`!(no_varref_ents_cnt)+1));
122 if (new_no_varref_ents == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
123 return -2;
124 OSCAP_GSYMcxx . . $ `src/common/util.h:444:9`!(no_varref_ents_cnt)++;
125 OSCAP_GSYMcxx . . $ `src/common/util.h:444:9`!(no_varref_ents) = new_no_varref_ents;
126 OSCAP_GSYMcxx . . $ `src/common/util.h:444:9`!(no_varref_ents)[OSCAP_GSYMcxx . . $ `src/common/util.h:444:9`!(no_varref_ents_cnt) - 1] = strdupcxx . . $ strdup(a8b8e32347182212).(o_name);
127
128 qsortcxx . . $ qsort(ebb60b13a65e77d7).(OSCAP_GSYMcxx . . $ `src/common/util.h:444:9`!(no_varref_ents), OSCAP_GSYMcxx . . $ `src/common/util.h:444:9`!(no_varref_ents_cnt),
129 sizeof (char *), (int(*)(const void *, const void *))&probe_optecmpcxx . . $ probe_optecmp(1c2bee554d4ac597).);
130
131 return (0);
132 }
133
134 static int probe_opthandler_rcachecxx . . $ probe_opthandler_rcache(4150cf18850aca74).(int option, int op, va_listcxx . . $ va_list# args)
135 {
136 return (0);
137 }
138
139 static void probe_common_main_cleanupcxx . . $ probe_common_main_cleanup(5d22bdacc48458e8).(void *arg)
140 {
141 dDcxx . . $ `src/common/debug_priv.h:64:9`!("probe_common_main_cleanup started");
142
143 probe_tcxx . . $ probe_t# *probe = (probe_tcxx . . $ probe_t# *)arg;
144 /* Cancel probe_input_handler thread */
145 if (pthread_cancelcxx . . $ pthread_cancel(15f694ef3c96d230).(probe->th_inputcxx . . $ $anonymous_type_3aeea60fe9979420_0#th_input.) != 0) {
146 dEcxx . . $ `src/common/debug_priv.h:63:9`!("Cannot cancel the probe input thread.");
147 return;
148 }
149
150 void *status;
151 int ret = pthread_joincxx . . $ pthread_join(269902cf949f12c5).(probe->th_inputcxx . . $ $anonymous_type_3aeea60fe9979420_0#th_input., &status);
152 if (ret != 0) {
153 dEcxx . . $ `src/common/debug_priv.h:63:9`!("pthread_join of probe_input_handler thread has failed: %d", ret);
154 }
155 dDcxx . . $ `src/common/debug_priv.h:64:9`!("probe_input_handler thread has joined with status %ld", (long) status);
156
157 probe_fini_function_tcxx . . $ probe_fini_function_t# fini_function = probe_table_get_fini_functioncxx . . $ probe_table_get_fini_function(a6503bb9f69d5c62).(probe->subtypecxx . . $ $anonymous_type_3aeea60fe9979420_0#subtype.);
158 if (fini_function != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
159 fini_function(probe->probe_argcxx . . $ $anonymous_type_3aeea60fe9979420_0#probe_arg.);
160 }
161
162 probe_rcache_freecxx . . $ probe_rcache_free(746d67ca65c3914d).(probe->rcachecxx . . $ $anonymous_type_3aeea60fe9979420_0#rcache.);
163 probe_icache_freecxx . . $ probe_icache_free(b601f10d292cbb66).(probe->icachecxx . . $ $anonymous_type_3aeea60fe9979420_0#icache.);
164 rbt_i32_freecxx . . $ rbt_i32_free(c2e6369c3901716e).(probe->workerscxx . . $ $anonymous_type_3aeea60fe9979420_0#workers.);
165 SEAP_CTX_freecxx . . $ SEAP_CTX_free(6b73584f16c77d33).(probe->SEAP_ctxcxx . . $ $anonymous_type_3aeea60fe9979420_0#SEAP_ctx.);
166 freecxx . . $ free(5d22bdacc48458e8).(probe->optioncxx . . $ $anonymous_type_3aeea60fe9979420_0#option.);
167
168 dDcxx . . $ `src/common/debug_priv.h:64:9`!("probe_common_main_cleanup finished");
169 }
170
171 void *probe_common_maincxx . . $ probe_common_main(9f162e79bfc6c74).(void *arg)
172 {
173 pthread_attr_tcxx . . $ pthread_attr_t# th_attr;
174 probe_tcxx . . $ probe_t# probe;
175 struct probe_common_main_argumentcxx . . $ probe_common_main_argument# *probe_argument = (struct probe_common_main_argumentcxx . . $ probe_common_main_argument# *) arg;
176 sch_queuedata_tcxx . . $ sch_queuedata_t# *data = probe_argument->queuedatacxx . . $ probe_common_main_argument#queuedata.;
177 oval_subtype_tcxx . . $ oval_subtype_t# subtype = probe_argument->subtypecxx . . $ probe_common_main_argument#subtype.;
178 probe.subtypecxx . . $ $anonymous_type_3aeea60fe9979420_0#subtype. = subtype;
179 probe.real_root_fdcxx . . $ $anonymous_type_3aeea60fe9979420_0#real_root_fd. = -1;
180 probe.real_cwd_fdcxx . . $ $anonymous_type_3aeea60fe9979420_0#real_cwd_fd. = -1;
181
182 #if defined(HAVE_PTHREAD_SETNAME_NPcxx . . $ `build/config.h:53:9`!)
183 # if defined(OS_APPLE)
184 pthread_setname_np("common_main");
185 # else
186 pthread_setname_npcxx . . $ pthread_setname_np(bee54c13bee684da).(pthread_selfcxx . . $ pthread_self(f708dce9a8856c70).(), "common_main");
187 # endif
188 #endif
189
190 dDcxx . . $ `src/common/debug_priv.h:64:9`!("probe_common_main started");
191
192 pthread_barrier_tcxx . . $ pthread_barrier_t# barrier;
193
194 const unsigned thread_count = 2; // input and icache threads
195 if ((errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = pthread_barrier_initcxx . . $ pthread_barrier_init(4180f681c7d0b92f).(&barrier, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, thread_count)) != 0) {
196 failcxx . . $ fail(50b278ac4ac9ad96).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, "pthread_barrier_init", __LINE__ - 6);
197 }
198
199 probe.offline_modecxx . . $ $anonymous_type_3aeea60fe9979420_0#offline_mode. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
200 probe.selected_offline_modecxx . . $ $anonymous_type_3aeea60fe9979420_0#selected_offline_mode. = PROBE_OFFLINE_NONEcxx . . $ PROBE_OFFLINE_NONE.;
201 probe.flagscxx . . $ $anonymous_type_3aeea60fe9979420_0#flags. = 0;
202 probe.pidcxx . . $ $anonymous_type_3aeea60fe9979420_0#pid. = getpidcxx . . $ getpid(b126dc7c1de90089).();
203 probe.probe_exitcodecxx . . $ $anonymous_type_3aeea60fe9979420_0#probe_exitcode. = 0;
204
205 /*
206 * Initialize SEAP stuff
207 */
208 probe.SEAP_ctxcxx . . $ $anonymous_type_3aeea60fe9979420_0#SEAP_ctx. = SEAP_CTX_newcxx . . $ SEAP_CTX_new(4c59508b5756fef7).();
209 probe.sdcxx . . $ $anonymous_type_3aeea60fe9979420_0#sd. = SEAP_add_probecxx . . $ SEAP_add_probe(c415db66edacb127).(probe.SEAP_ctxcxx . . $ $anonymous_type_3aeea60fe9979420_0#SEAP_ctx., data);
210
211 if (probe.sdcxx . . $ $anonymous_type_3aeea60fe9979420_0#sd. < 0)
212 failcxx . . $ fail(50b278ac4ac9ad96).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, "SEAP_openfd2", __LINE__ - 3);
213
214 if (SEAP_cmd_registercxx . . $ SEAP_cmd_register(8e6e8c3c92801ad2).(probe.SEAP_ctxcxx . . $ $anonymous_type_3aeea60fe9979420_0#SEAP_ctx., PROBECMD_RESETcxx . . $ `src/OVAL/probes/public/probe-api.h:442:9`!, SEAP_CMDREG_USEARGcxx . . $ `src/OVAL/probes/SEAP/_seap-command.h:48:9`!, &probe_resetcxx . . $ probe_reset(313521213da5ee5)., &probe) != 0)
215 failcxx . . $ fail(50b278ac4ac9ad96).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, "SEAP_cmd_register", __LINE__ - 1);
216
217 /*
218 * Initialize result & name caching
219 */
220 probe.rcachecxx . . $ $anonymous_type_3aeea60fe9979420_0#rcache. = probe_rcache_newcxx . . $ probe_rcache_new(828cb6e43476d228).();
221 probe.icachecxx . . $ $anonymous_type_3aeea60fe9979420_0#icache. = probe_icache_newcxx . . $ probe_icache_new(863b34798c379835).(&barrier);
222 probe_ncache_clearcxx . . $ probe_ncache_clear(c0ad2c06e7dc4d8f).(OSCAP_GSYMcxx . . $ `src/common/util.h:444:9`!(ncache));
223 probe.ncachecxx . . $ $anonymous_type_3aeea60fe9979420_0#ncache. = OSCAP_GSYMcxx . . $ `src/common/util.h:444:9`!(ncache);
224 probe.th_barriercxx . . $ $anonymous_type_3aeea60fe9979420_0#th_barrier. = &barrier;
225
226 /*
227 * Initialize probe option handlers
228 */
229 #define PROBE_OPTION_INITCOUNTcxx . . $ `src/OVAL/probes/probe/probe_main.c:229:9`! 2
230
231 probe.optioncxx . . $ $anonymous_type_3aeea60fe9979420_0#option. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(probe_option_tcxx . . $ probe_option_t#) * PROBE_OPTION_INITCOUNTcxx . . $ `src/OVAL/probes/probe/probe_main.c:229:9`!);
232 probe.optcntcxx . . $ $anonymous_type_3aeea60fe9979420_0#optcnt. = PROBE_OPTION_INITCOUNTcxx . . $ `src/OVAL/probes/probe/probe_main.c:229:9`!;
233
234 probe.optioncxx . . $ $anonymous_type_3aeea60fe9979420_0#option.[0].optioncxx . . $ $anonymous_type_7ccdd93c6ac2fc09_0#option. = PROBEOPT_VARREF_HANDLINGcxx . . $ `src/OVAL/probes/probe/option.h:4:9`!;
235 probe.optioncxx . . $ $anonymous_type_3aeea60fe9979420_0#option.[0].handlercxx . . $ $anonymous_type_7ccdd93c6ac2fc09_0#handler. = &probe_opthandler_varrefcxx . . $ probe_opthandler_varref(4150cf18850aca74).;
236 probe.optioncxx . . $ $anonymous_type_3aeea60fe9979420_0#option.[1].optioncxx . . $ $anonymous_type_7ccdd93c6ac2fc09_0#option. = PROBEOPT_RESULT_CACHINGcxx . . $ `src/OVAL/probes/probe/option.h:5:9`!;
237 probe.optioncxx . . $ $anonymous_type_3aeea60fe9979420_0#option.[1].handlercxx . . $ $anonymous_type_7ccdd93c6ac2fc09_0#handler. = &probe_opthandler_rcachecxx . . $ probe_opthandler_rcache(4150cf18850aca74).;
238
239 OSCAP_GSYMcxx . . $ `src/common/util.h:444:9`!(probe_optdef) = probe.optioncxx . . $ $anonymous_type_3aeea60fe9979420_0#option.;
240 OSCAP_GSYMcxx . . $ `src/common/util.h:444:9`!(probe_optdef_count) = probe.optcntcxx . . $ $anonymous_type_3aeea60fe9979420_0#optcnt.;
241
242
243 /*
244 * Create input handler (detached)
245 */
246 probe.workerscxx . . $ $anonymous_type_3aeea60fe9979420_0#workers. = rbt_i32_newcxx . . $ rbt_i32_new(557e4aca7c153cb).();
247
248 probe_init_function_tcxx . . $ probe_init_function_t# init_function = probe_table_get_init_functioncxx . . $ probe_table_get_init_function(8866a821235b0b2).(probe.subtypecxx . . $ $anonymous_type_3aeea60fe9979420_0#subtype.);
249 if (init_function != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
250 probe.probe_argcxx . . $ $anonymous_type_3aeea60fe9979420_0#probe_arg. = init_function();
251 }
252
253 pthread_cleanup_pushcxx . . $ `<external>/14712363683955484316/pthread.h:681:10`!(probe_common_main_cleanup, (void *) &probe);
254
255 pthread_attr_initcxx . . $ pthread_attr_init(26f1688c57ac69c9).(&th_attr);
256
257 if (pthread_createcxx . . $ pthread_create(2141a84bcac899e5).(&probe.th_inputcxx . . $ $anonymous_type_3aeea60fe9979420_0#th_input., &th_attr, &probe_input_handlercxx . . $ probe_input_handler(9f162e79bfc6c74)., &probe))
258 failcxx . . $ fail(50b278ac4ac9ad96).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, "pthread_create(probe_input_handler)", __LINE__ - 1);
259
260 pthread_attr_destroycxx . . $ pthread_attr_destroy(26f1688c57ac69c9).(&th_attr);
261
262 void *status;
263 if (pthread_joincxx . . $ pthread_join(269902cf949f12c5).(probe.th_inputcxx . . $ $anonymous_type_3aeea60fe9979420_0#th_input., &status) != 0) {
264 dDcxx . . $ `src/common/debug_priv.h:64:9`!("pthread_join of probe_input_handler thread has failed");
265 }
266 dDcxx . . $ `src/common/debug_priv.h:64:9`!("probe_input_handler thread has joined with status %ld", (long) status);
267
268 pthread_cleanup_popcxx . . $ `<external>/14712363683955484316/pthread.h:702:10`!(1);
269
270 pthread_barrier_destroycxx . . $ pthread_barrier_destroy(6183b0e2072457c0).(&barrier);
271
272 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
273 }