Debian Codegraph @

src/OVAL/oval_probe_session.c

raw symbols SCIP
1 /**
2 * @file oval_probe_session.c
3 * @brief OVAL probe session API implementation
4 * @author "Daniel Kopecek" <[email protected]>
5 *
6 * @addtogroup PROBESESSION
7 * @{
8 */
9 /*
10 * Copyright 2010 Red Hat Inc., Durham, North Carolina.
11 * All Rights Reserved.
12 *
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
17 *
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
22 *
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 *
27 * Authors:
28 * "Daniel Kopecek" <[email protected]>
29 */
30
31 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`!
32 #include <config.h>cxx . . $ `<file>/build/config.h`/
33 #endif
34
35 #include <errno.h>
36 #include <string.h>
37 #include <stdlib.h>
38
39 #include "common/_error.h"cxx . . $ `<file>/src/common/_error.h`/
40 #include "common/bfind.h"cxx . . $ `<file>/src/common/bfind.h`/
41 #include "common/debug_priv.h"cxx . . $ `<file>/src/common/debug_priv.h`/
42
43
44 #include "public/oval_definitions.h"cxx . . $ `<file>/src/OVAL/public/oval_definitions.h`/
45 #include "_oval_probe_session.h"cxx . . $ `<file>/src/OVAL/_oval_probe_session.h`/
46 #include "_oval_probe_handler.h"cxx . . $ `<file>/src/OVAL/_oval_probe_handler.h`/
47 #include "oval_probe_impl.h"cxx . . $ `<file>/src/OVAL/oval_probe_impl.h`/
48 #include "oval_probe_ext.h"cxx . . $ `<file>/src/OVAL/oval_probe_ext.h`/
49 #include "probe-table.h"cxx . . $ `<file>/src/OVAL/probes/public/probe-table.h`/
50 #include "oval_types.h"cxx . . $ `<file>/src/OVAL/public/oval_types.h`/
51 #include "crapi/crapi.h"cxx . . $ `<file>/src/OVAL/probes/crapi/crapi.h`/
52
53 #if defined(OSCAP_THREAD_SAFEcxx . . $ `build/config.h:13:9`!)
54 #include <pthread.h>
55 static pthread_once_tcxx . . $ pthread_once_t# __oval_probe_session_init_oncecxx . . $ __oval_probe_session_init_once. = PTHREAD_ONCE_INITcxx . . $ `<external>/14712363683955484316/pthread.h:186:9`!;
56 #else
57 static volatile int __oval_probe_session_init_once = 0;
58 #endif /* OSCAP_THREAD_SAFE */
59
60 /**
61 * Entity name cache exit hook. This hook is registered using
62 * atexit(3) during initialization and ensures that the element
63 * name cache is freed before exit.
64 */
65 static void ncache_libfreecxx . . $ ncache_libfree(49f6e7a06ebc5aa8).(void)
66 {
67 probe_ncache_freecxx . . $ probe_ncache_free(c0ad2c06e7dc4d8f).(OSCAP_GSYMcxx . . $ `src/common/util.h:444:9`!(ncache));
68 }
69
70 /**
71 * Initialize element name cache and register an exit hook.
72 */
73 static void ncache_libinitcxx . . $ ncache_libinit(49f6e7a06ebc5aa8).(void)
74 {
75 if (OSCAP_GSYMcxx . . $ `src/common/util.h:444:9`!(ncache) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
76 OSCAP_GSYMcxx . . $ `src/common/util.h:444:9`!(ncache) = probe_ncache_newcxx . . $ probe_ncache_new(e2066d1f01a5893b).();
77 atexitcxx . . $ atexit(8919c3b35e68c42d).(ncache_libfreecxx . . $ ncache_libfree(49f6e7a06ebc5aa8).);
78 }
79 }
80
81 static void oval_probe_session_libinitcxx . . $ oval_probe_session_libinit(49f6e7a06ebc5aa8).(void)
82 {
83 /* HACK: Make sure S-exps are initialized before we initialize anything else
84 * that uses them. This is needed only if the S-exp library is compiled without
85 * atomic builtins. In that case it uses a fallback locking mechanism that uses
86 * a mutex array which needs to be initialized before S-exp are used and freed
87 * at exit(3). The later is done by registering an atexit(3) function.
88 * The ncache_libinit function also registers an atexit(3) function and we need
89 * to make sure that the S-exps are not deinitialized before the ncache atexit
90 * handler is called.
91 * TODO: Implement SEXP_libinit() and call it from oscap_init()?
92 */
93 volatile SEXP_tcxx . . $ SEXP_t# *exp = SEXP_string_newcxx . . $ SEXP_string_new(a588a58d7514eee2).("magic", 5);
94 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).((SEXP_tcxx . . $ SEXP_t# *)exp);
95
96 ncache_libinitcxx . . $ ncache_libinit(49f6e7a06ebc5aa8).();
97 /*
98 * Initialize crypto API
99 */
100 #ifndef OS_WINDOWS
101 if (crapi_initcxx . . $ crapi_init(dedf1e9b1c614a07). (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) != 0)
102 return;
103 #endif
104 }
105
106 /**
107 * Initialize the element name cache. This function can be called repeatedly
108 * from various probe system entry points to ensure that the cache is initialized.
109 * If OSCAP_THREAD_SAFE is defined at compilation time, the pthread_once call
110 * is used to ensure that the initialization is done just once. Otherwise a
111 * volatile integer flag is used.
112 */
113 static void __init_oncecxx . . $ __init_once(49f6e7a06ebc5aa8).(void)
114 {
115 #if defined(OSCAP_THREAD_SAFEcxx . . $ `build/config.h:13:9`!)
116 if (pthread_oncecxx . . $ pthread_once(95e4b41df204d8e2).(&__oval_probe_session_init_oncecxx . . $ __oval_probe_session_init_once.,
117 &oval_probe_session_libinitcxx . . $ oval_probe_session_libinit(49f6e7a06ebc5aa8).) != 0)
118 abortcxx . . $ abort(8df32a62017fbbf6).();
119 #else
120 if (__oval_probe_session_init_once == 0) {
121 oval_probe_session_libinit();
122 __oval_probe_session_init_once = 1;
123 }
124 #endif
125 return;
126 }
127
128 static void oval_probe_session_initcxx . . $ oval_probe_session_init(a1aec373ff6f3401).(oval_probe_session_tcxx . . $ oval_probe_session_t# *sess, struct oval_syschar_modelcxx . . $ oval_syschar_model# *model)
129 {
130 sess->phcxx . . $ oval_probe_session#ph. = oval_phtbl_newcxx . . $ oval_phtbl_new(b0133460b0177f0a).();
131 sess->sys_modelcxx . . $ oval_probe_session#sys_model. = model;
132 sess->flgcxx . . $ oval_probe_session#flg. = 0;
133 sess->pextcxx . . $ oval_probe_session#pext. = oval_pext_newcxx . . $ oval_pext_new(ae5e4f650a9e55e3).();
134 sess->pextcxx . . $ oval_probe_session#pext.->modelcxx . . $ oval_pext#model. = &sess->sys_modelcxx . . $ oval_probe_session#sys_model.;
135 sess->pextcxx . . $ oval_probe_session#pext.->sess_ptrcxx . . $ oval_pext#sess_ptr. = sess;
136
137 __init_oncecxx . . $ __init_once(49f6e7a06ebc5aa8).();
138
139 oval_probe_handler_tcxx . . $ oval_probe_handler_t# *probe_handler;
140 int probe_count = probe_table_sizecxx . . $ probe_table_size(b126dc7c1de90089).();
141 for (int i = 0; i < probe_count; i++) {
142 oval_subtype_tcxx . . $ oval_subtype_t# type = probe_table_at_indexcxx . . $ probe_table_at_index(d379c43f84bb4020).(i);
143 if (type == OVAL_INDEPENDENT_SYSCHAR_SUBTYPEcxx . . $ OVAL_INDEPENDENT_SYSCHAR_SUBTYPE.) {
144 probe_handler = &oval_probe_sys_handlercxx . . $ oval_probe_sys_handler(a49301219799be48).;
145 } else {
146 probe_handler = &oval_probe_ext_handlercxx . . $ oval_probe_ext_handler(a49301219799be48).;
147 }
148 oval_probe_handler_setcxx . . $ oval_probe_handler_set(f8ee9472e321c7fd).(sess->phcxx . . $ oval_probe_session#ph., type, probe_handler, sess->pextcxx . . $ oval_probe_session#pext.);
149 }
150
151 oval_probe_handler_setcxx . . $ oval_probe_handler_set(f8ee9472e321c7fd).(sess->phcxx . . $ oval_probe_session#ph., OVAL_SUBTYPE_ALLcxx . . $ OVAL_SUBTYPE_ALL., oval_probe_ext_handlercxx . . $ oval_probe_ext_handler(a49301219799be48)., sess->pextcxx . . $ oval_probe_session#pext.); /* special case for reset */
152 }
153
154 oval_probe_session_tcxx . . $ oval_probe_session_t# *oval_probe_session_newcxx . . $ oval_probe_session_new(fb0659dc1a6483df).(struct oval_syschar_modelcxx . . $ oval_syschar_model# *model)
155 {
156 oval_probe_session_tcxx . . $ oval_probe_session_t# *sess = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(oval_probe_session_tcxx . . $ oval_probe_session_t#));
157 oval_probe_session_initcxx . . $ oval_probe_session_init(a1aec373ff6f3401).(sess, model);
158 return sess;
159 }
160
161 static void oval_probe_session_freecxx . . $ oval_probe_session_free(7340ff736dc09416).(oval_probe_session_tcxx . . $ oval_probe_session_t# *sess)
162 {
163 if (sess == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
164 dEcxx . . $ `src/common/debug_priv.h:63:9`!("Invalid session (NULL)");
165 return;
166 }
167
168 oval_phtbl_freecxx . . $ oval_phtbl_free(39da376fa133fd00).(sess->phcxx . . $ oval_probe_session#ph.);
169 oval_pext_freecxx . . $ oval_pext_free(902eee71d5ac11e9).(sess->pextcxx . . $ oval_probe_session#pext.);
170 }
171
172 void oval_probe_session_reinitcxx . . $ oval_probe_session_reinit(a1aec373ff6f3401).(oval_probe_session_tcxx . . $ oval_probe_session_t# *sess, struct oval_syschar_modelcxx . . $ oval_syschar_model# *model)
173 {
174 oval_probe_session_freecxx . . $ oval_probe_session_free(7340ff736dc09416).(sess);
175
176 oval_probe_session_initcxx . . $ oval_probe_session_init(a1aec373ff6f3401).(sess, model);
177 }
178
179 void oval_probe_session_destroycxx . . $ oval_probe_session_destroy(7340ff736dc09416).(oval_probe_session_tcxx . . $ oval_probe_session_t# *sess)
180 {
181 oval_probe_session_freecxx . . $ oval_probe_session_free(7340ff736dc09416).(sess);
182 freecxx . . $ free(5d22bdacc48458e8).(sess);
183 }
184
185 int oval_probe_session_resetcxx . . $ oval_probe_session_reset(12f0a1f25401bce5).(oval_probe_session_tcxx . . $ oval_probe_session_t# *sess, struct oval_syschar_modelcxx . . $ oval_syschar_model# *sysch)
186 {
187 oval_ph_tcxx . . $ oval_ph_t# *ph;
188
189 if ((ph = oval_probe_handler_getcxx . . $ oval_probe_handler_get(a2b39ae009cb9244).(sess->phcxx . . $ oval_probe_session#ph., OVAL_SUBTYPE_ALLcxx . . $ OVAL_SUBTYPE_ALL.)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
190 dEcxx . . $ `src/common/debug_priv.h:63:9`!("No probe handler for OVAL_SUBTYPE_ALL");
191 return (-1);
192 }
193
194 if (ph->funccxx . . $ oval_ph#func.(OVAL_SUBTYPE_ALLcxx . . $ OVAL_SUBTYPE_ALL., ph->uptrcxx . . $ oval_ph#uptr., PROBE_HANDLER_ACT_RESETcxx . . $ `src/OVAL/_oval_probe_handler.h:48:9`!) != 0) {
195 return(-1);
196 }
197 if (sysch != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
198 sess->sys_modelcxx . . $ oval_probe_session#sys_model. = sysch;
199
200 return(0);
201 }
202
203 int oval_probe_session_abortcxx . . $ oval_probe_session_abort(88fe1961f49ced0d).(oval_probe_session_tcxx . . $ oval_probe_session_t# *sess)
204 {
205 oval_ph_tcxx . . $ oval_ph_t# *ph;
206
207 if ((ph = oval_probe_handler_getcxx . . $ oval_probe_handler_get(a2b39ae009cb9244).(sess->phcxx . . $ oval_probe_session#ph., OVAL_SUBTYPE_ALLcxx . . $ OVAL_SUBTYPE_ALL.) ) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
208 dEcxx . . $ `src/common/debug_priv.h:63:9`!("No probe handler for OVAL_SUBTYPE_ALL");
209 return (-1);
210 }
211
212 return ph->funccxx . . $ oval_ph#func.(OVAL_SUBTYPE_ALLcxx . . $ OVAL_SUBTYPE_ALL., ph->uptrcxx . . $ oval_ph#uptr., PROBE_HANDLER_ACT_ABORTcxx . . $ `src/OVAL/_oval_probe_handler.h:50:9`!);
213 }
214
215 struct oval_syschar_modelcxx . . $ oval_syschar_model# *oval_probe_session_getmodelcxx . . $ oval_probe_session_getmodel(570f146e09c5b13b).(oval_probe_session_tcxx . . $ oval_probe_session_t# *sess)
216 {
217 if (sess == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
218 dEcxx . . $ `src/common/debug_priv.h:63:9`!("Invalid session (NULL)");
219 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
220 }
221
222 return (sess->sys_modelcxx . . $ oval_probe_session#sys_model.);
223 }
224
225 /// @}