Debian Codegraph @

src/OVAL/probes/unix/linux/selinuxboolean_probe.c

raw symbols SCIP
1 /**
2 * @file selinuxboolean_probe.c
3 * @brief selinuxboolean probe
4 * @author "Petr Lautrbach" <[email protected]>
5 *
6 * This probe is able to process a selinuxboolean_object as defined in OVAL 5.8.
7 *
8 */
9
10 /*
11 * Copyright 2009-2011 Red Hat Inc., Durham, North Carolina.
12 * All Rights Reserved.
13 *
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 *
28 * Authors:
29 * Petr Lautrbach <[email protected]>
30 */
31
32 /*
33 * selinuxboolean probe:
34 *
35 * name
36 * current_status
37 * pending_status
38 */
39
40 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`!
41 #include <config.h>cxx . . $ `<file>/build/config.h`/
42 #endif
43
44 #include <stdlib.h>
45 #include <string.h>
46 #include <stdio.h>
47 #include <stdio_ext.h>
48 #include <errno.h>
49 #include <sys/stat.h>
50 #include <sys/vfs.h>
51 #include <sys/statvfs.h>
52 #include <fcntl.h>
53 #include <limits.h>
54
55 #include "_seap.h"cxx . . $ `<file>/src/OVAL/probes/SEAP/_seap.h`/
56 #include "probe-api.h"cxx . . $ `<file>/src/OVAL/probes/public/probe-api.h`/
57 #include "probe/entcmp.h"cxx . . $ `<file>/src/OVAL/probes/probe/entcmp.h`/
58 #include <probe/probe.h>cxx . . $ `<file>/src/OVAL/probes/probe/probe.h`/
59
60 #include <selinux/selinux.h>
61 #include "selinuxboolean_probe.h"cxx . . $ `<file>/src/OVAL/probes/unix/linux/selinuxboolean_probe.h`/
62
63
64 /* These definitions and three functions were commandeered from SELinux internals
65 * and creatively improved to take the global prefix into account */
66
67 #define OLDSELINUXMNTcxx . . $ `src/OVAL/probes/unix/linux/selinuxboolean_probe.c:67:9`! "/selinux"
68 #define SELINUXMNTcxx . . $ `src/OVAL/probes/unix/linux/selinuxboolean_probe.c:68:9`! "/sys/fs/selinux"
69 #define SELINUXFScxx . . $ `src/OVAL/probes/unix/linux/selinuxboolean_probe.c:69:9`! "selinuxfs"
70 #define SELINUX_MAGICcxx . . $ `src/OVAL/probes/unix/linux/selinuxboolean_probe.c:70:9`! 0xf97cff8c
71
72 static int verify_selinuxmnt_prefixedcxx . . $ verify_selinuxmnt_prefixed(5ae29d726ae57f88).(const char *prefix, const char *mnt)
73 {
74 char path[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!] = {0};
75 struct statfscxx . . $ statfs# sfbuf;
76 int rc;
77
78 if (!prefix)
79 return -1;
80
81 snprintfcxx . . $ snprintf(ea502d73e74c754c).(path, PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!, "%s%s", prefix, mnt);
82
83 do {
84 rc = statfscxx . . $ statfs(361e01602215989e).(path, &sfbuf);
85 } while (rc < 0 && errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`!);
86 if (rc == 0) {
87 if ((uint32_tcxx . . $ uint32_t#)sfbuf.f_typecxx . . $ statfs#f_type. == (uint32_tcxx . . $ uint32_t#)SELINUX_MAGICcxx . . $ `src/OVAL/probes/unix/linux/selinuxboolean_probe.c:70:9`!) {
88 struct statvfscxx . . $ statvfs# vfsbuf;
89 rc = statvfscxx . . $ statvfs(b2fdbc4bb2d0b440).(path, &vfsbuf);
90 if (rc == 0) {
91 if (!(vfsbuf.f_flagcxx . . $ statvfs#f_flag. & ST_RDONLYcxx . . $ `<external>/1309920113683139129/statvfs.h:85:9`!)) {
92 set_selinuxmntcxx . . $ set_selinuxmnt(85c52e162fed56f9).(path);
93 }
94 return 0;
95 }
96 }
97 }
98
99 return -1;
100 }
101
102 static int selinuxfs_exists_prefixedcxx . . $ selinuxfs_exists_prefixed(5c4306d8553b3696).(const char *prefix)
103 {
104 char path[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!] = {0};
105 int exists = 0;
106 FILEcxx . . $ FILE# *fp = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
107 char *buf = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
108 size_t len;
109 ssize_tcxx . . $ ssize_t# num;
110
111 if (!prefix)
112 return 0;
113
114 snprintfcxx . . $ snprintf(ea502d73e74c754c).(path, PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!, "%s/proc/filesystems", prefix);
115 fp = fopencxx . . $ fopen(82ec0787cd37e0a3).(path, "re");
116 if (!fp)
117 return 1; /* Fail as if it exists */
118 __fsetlockingcxx . . $ __fsetlocking(c2adc39b7d70763e).(fp, FSETLOCKING_BYCALLERcxx . . $ `<external>/9684955786050076606/stdio_ext.h:38:9`!);
119
120 num = getlinecxx . . $ getline(960b3da7d5d5ad33).(&buf, &len, fp);
121 while (num != -1) {
122 if (strstrcxx . . $ strstr(a713fe7b9a57cf96).(buf, SELINUXFScxx . . $ `src/OVAL/probes/unix/linux/selinuxboolean_probe.c:69:9`!)) {
123 exists = 1;
124 break;
125 }
126 num = getlinecxx . . $ getline(960b3da7d5d5ad33).(&buf, &len, fp);
127 }
128
129 freecxx . . $ free(5d22bdacc48458e8).(buf);
130 fclosecxx . . $ fclose(89bc1efcdac0ca22).(fp);
131 return exists;
132 }
133
134 static int init_selinuxmnt_prefixedcxx . . $ init_selinuxmnt_prefixed(5c4306d8553b3696).(const char *prefix)
135 {
136 char path[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!] = {0};
137 char *buf = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, *p;
138 FILEcxx . . $ FILE# *fp = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
139 size_t len;
140 ssize_tcxx . . $ ssize_t# num;
141 int res = -1;
142
143 if (!prefix)
144 return res;
145
146 if (verify_selinuxmnt_prefixedcxx . . $ verify_selinuxmnt_prefixed(5ae29d726ae57f88).(prefix, SELINUXMNTcxx . . $ `src/OVAL/probes/unix/linux/selinuxboolean_probe.c:68:9`!) == 0)
147 return 0;
148
149 if (verify_selinuxmnt_prefixedcxx . . $ verify_selinuxmnt_prefixed(5ae29d726ae57f88).(prefix, OLDSELINUXMNTcxx . . $ `src/OVAL/probes/unix/linux/selinuxboolean_probe.c:67:9`!) == 0)
150 return 0;
151
152 /* Drop back to detecting it the long way. */
153 if (!selinuxfs_exists_prefixedcxx . . $ selinuxfs_exists_prefixed(5c4306d8553b3696).(prefix))
154 goto out;
155
156 /* At this point, the usual spot doesn't have an selinuxfs so
157 * we look around for it */
158 snprintfcxx . . $ snprintf(ea502d73e74c754c).(path, PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!, "%s/proc/mounts", prefix);
159 fp = fopencxx . . $ fopen(82ec0787cd37e0a3).(path, "re");
160 if (!fp)
161 goto out;
162
163 __fsetlockingcxx . . $ __fsetlocking(c2adc39b7d70763e).(fp, FSETLOCKING_BYCALLERcxx . . $ `<external>/9684955786050076606/stdio_ext.h:38:9`!);
164 while ((num = getlinecxx . . $ getline(960b3da7d5d5ad33).(&buf, &len, fp)) != -1) {
165 char *tmp;
166 p = strchrcxx . . $ strchr(2050848944e00d54).(buf, ' ');
167 if (!p)
168 goto out;
169 p++;
170 tmp = strchrcxx . . $ strchr(2050848944e00d54).(p, ' ');
171 if (!tmp)
172 goto out;
173 if (!strncmpcxx . . $ strncmp(fd278af2f295fa2e).(tmp + 1, SELINUXFScxx . . $ `src/OVAL/probes/unix/linux/selinuxboolean_probe.c:69:9`!" ", strlencxx . . $ strlen(751346f8406fd082).(SELINUXFScxx . . $ `src/OVAL/probes/unix/linux/selinuxboolean_probe.c:69:9`!)+1)) {
174 *tmp = '\0';
175 break;
176 }
177 }
178
179 /* If we found something, dup it */
180 if (num > 0)
181 res = verify_selinuxmnt_prefixedcxx . . $ verify_selinuxmnt_prefixed(5ae29d726ae57f88).(prefix, p);
182
183 out:
184 freecxx . . $ free(5d22bdacc48458e8).(buf);
185 if (fp)
186 fclosecxx . . $ fclose(89bc1efcdac0ca22).(fp);
187 return res;
188 }
189
190 /* End of borrowing from SELinux */
191
192 static int get_selinuxbooleancxx . . $ get_selinuxboolean(241d6c535218441).(SEXP_tcxx . . $ SEXP_t# *ut_ent, probe_ctxcxx . . $ probe_ctx# *ctx)
193 {
194 int err = 1, active, pending, len, i;
195 SEXP_tcxx . . $ SEXP_t# *boolean, *item;
196 char **booleans;
197
198 if (security_get_boolean_namescxx . . $ security_get_boolean_names(d13e9a4ccee1c4f0).(&booleans, &len) == -1) {
199 probe_cobj_set_flagcxx . . $ probe_cobj_set_flag(644bab5dffe689c).(probe_ctx_getresultcxx . . $ probe_ctx_getresult(4299b6b53fa804a5).(ctx), SYSCHAR_FLAG_ERRORcxx . . $ SYSCHAR_FLAG_ERROR.);
200 return err;
201 }
202
203 for (i = 0; i < len; i++) {
204 boolean = SEXP_string_newcxx . . $ SEXP_string_new(a588a58d7514eee2).(booleans[i], strlencxx . . $ strlen(751346f8406fd082).(booleans[i]));
205 if (probe_entobj_cmpcxx . . $ probe_entobj_cmp(e245451a1311e799).(ut_ent, boolean) == OVAL_RESULT_TRUEcxx . . $ OVAL_RESULT_TRUE.) {
206 active = security_get_boolean_activecxx . . $ security_get_boolean_active(5c4306d8553b3696).(booleans[i]);
207 pending = security_get_boolean_pendingcxx . . $ security_get_boolean_pending(5c4306d8553b3696).(booleans[i]);
208 item = probe_item_createcxx . . $ probe_item_create(36b16a6622050a9c).(
209 OVAL_LINUX_SELINUXBOOLEANcxx . . $ OVAL_LINUX_SELINUXBOOLEAN., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!,
210 "name", OVAL_DATATYPE_SEXPcxx . . $ OVAL_DATATYPE_SEXP., boolean,
211 "current_status", OVAL_DATATYPE_BOOLEANcxx . . $ OVAL_DATATYPE_BOOLEAN., active,
212 "pending_status", OVAL_DATATYPE_BOOLEANcxx . . $ OVAL_DATATYPE_BOOLEAN., pending,
213 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
214 probe_item_collectcxx . . $ probe_item_collect(11bb80e0c30650d7).(ctx, item);
215 }
216 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(boolean);
217 }
218
219 for (i = 0; i < len; i++)
220 freecxx . . $ free(5d22bdacc48458e8).(booleans[i]);
221 freecxx . . $ free(5d22bdacc48458e8).(booleans);
222
223 return 0;
224 }
225
226 int selinuxboolean_probe_offline_mode_supportedcxx . . $ selinuxboolean_probe_offline_mode_supported(b126dc7c1de90089).(void)
227 {
228 return PROBE_OFFLINE_OWNcxx . . $ PROBE_OFFLINE_OWN.;
229 }
230
231 int selinuxboolean_probe_maincxx . . $ selinuxboolean_probe_main(470536d3ffacaf10).(probe_ctxcxx . . $ probe_ctx# *ctx, void *arg)
232 {
233 SEXP_tcxx . . $ SEXP_t# *probe_in, *name;
234 int err;
235
236 probe_in = probe_ctx_getobjectcxx . . $ probe_ctx_getobject(4299b6b53fa804a5).(ctx);
237 name = probe_obj_getentcxx . . $ probe_obj_getent(7907a01f2ff841f3).(probe_in, "name", 1);
238
239 if (name == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
240 return PROBE_ENOVALcxx . . $ `src/OVAL/probes/public/probe-common.h:10:9`!;
241 }
242
243 const char *prefix = getenvcxx . . $ getenv(a8b8e32347182212).("OSCAP_PROBE_ROOT");
244 if (prefix != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
245 if (init_selinuxmnt_prefixedcxx . . $ init_selinuxmnt_prefixed(5c4306d8553b3696).(prefix)) {
246 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(name);
247 return PROBE_ESUCCESScxx . . $ `src/OVAL/probes/public/probe-common.h:7:9`!;
248 }
249 }
250
251 err = get_selinuxbooleancxx . . $ get_selinuxboolean(241d6c535218441).(name, ctx);
252 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(name);
253
254 return err;
255 }