Debian Codegraph @

src/OVAL/probes/independent/system_info_probe.c

raw symbols SCIP
1 /**
2 * @file system_info_probe.c
3 * @brief system_info probe
4 * @author "Tomas Heinrich" <[email protected]>
5 */
6
7 /*
8 * Copyright 2009 Red Hat Inc., Durham, North Carolina.
9 * All Rights Reserved.
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 *
25 * Authors:
26 * "Tomas Heinrich" <[email protected]>
27 */
28
29 /*
30 * system_info probe:
31 *
32 * (for internal use)
33 *
34 * system_info_object
35 *
36 * system_info_item
37 * attrs
38 * id
39 * status_enum status
40 * os_name
41 * os_version
42 * architecture
43 * primary_host_name
44 * //interfaces
45 * interface [0..*]
46 * attrs
47 * interface_name
48 * ip_address
49 * mac_address
50 * any [0..*]
51 */
52
53 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`!
54 #include <config.h>cxx . . $ `<file>/build/config.h`/
55 #endif
56
57 #include "_seap.h"cxx . . $ `<file>/src/OVAL/probes/SEAP/_seap.h`/
58 #include <probe-api.h>cxx . . $ `<file>/src/OVAL/probes/public/probe-api.h`/
59 #include <probe/probe.h>cxx . . $ `<file>/src/OVAL/probes/probe/probe.h`/
60 #include <probe/option.h>cxx . . $ `<file>/src/OVAL/probes/probe/option.h`/
61 #include <debug_priv.h>cxx . . $ `<file>/src/common/debug_priv.h`/
62
63 #ifdef OS_WINDOWS
64 /* By defining WIN32_LEAN_AND_MEAN we ensure that Windows.h won't include
65 * winsock.h, which would conflict with symbols from WinSock2.h.
66 */
67 #ifndef WIN32_LEAN_AND_MEAN
68 #define WIN32_LEAN_AND_MEAN
69 #endif
70 #include <WinSock2.h>
71 #include <Iphlpapi.h>
72 #include <Windows.h>
73 #include <ws2def.h>
74 #include <io.h>
75 #include <winternl.h>
76 #else
77 #include <sys/utsname.h>
78 #include <unistd.h>
79 #endif
80 #include <stdlib.h>
81 #include <string.h>
82 #include <ctype.h>
83 #include <errno.h>
84 #include <limits.h>
85 #include "system_info_probe.h"cxx . . $ `<file>/src/OVAL/probes/independent/system_info_probe.h`/
86 #include "oscap_helpers.h"cxx . . $ `<file>/src/common/public/oscap_helpers.h`/
87
88 #define _REGEX_RES_VECSIZEcxx . . $ `src/OVAL/probes/independent/system_info_probe.c:88:9`! 12
89 #define MAX_BUFFER_SIZEcxx . . $ `src/OVAL/probes/independent/system_info_probe.c:89:9`! 4096
90
91 #if !defined(HOST_NAME_MAXcxx . . $ `<external>/2191589805780913682/local_lim.h:93:9`!)
92 #define HOST_NAME_MAX _POSIX_HOST_NAME_MAX
93 #endif
94
95 #if defined(OS_LINUXcxx . . $ `compat/oscap_platforms.h:38:10`!)
96 #include <sys/socket.h>
97 #include <ifaddrs.h>
98 #include <netdb.h>
99 #include <sys/ioctl.h>
100 #include <string.h>
101 #include <net/if.h>
102 #include <arpa/inet.h>
103 #include <sys/types.h>
104 #elif defined(OS_FREEBSD)
105 #include <arpa/inet.h>
106 #include <ifaddrs.h>
107 #include <netdb.h>
108 #include <netinet/in.h>
109 #include <net/if.h>
110 #include <sys/ioctl.h>
111 #endif
112
113 #if defined(OS_LINUXcxx . . $ `compat/oscap_platforms.h:38:10`!)
114 static char *get_maccxx . . $ get_mac(4eee0b5a11f18b5).(const struct ifaddrscxx . . $ ifaddrs# *ifa, int fd)
115 {
116 struct ifreqcxx . . $ ifreq# ifr;
117 unsigned char mac[6];
118 static char mac_buf[20];
119
120 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&ifr, 0, sizeof(struct ifreqcxx . . $ ifreq#));
121 strncpycxx . . $ strncpy(255158a415b673b0).(ifr.ifr_namecxx . . $ `<external>/2638090476884991293/if.h:151:10`!, ifa->ifa_namecxx . . $ ifaddrs#ifa_name., IFNAMSIZcxx . . $ `<external>/2638090476884991293/if.h:129:10`!);
122 ifr.ifr_namecxx . . $ `<external>/2638090476884991293/if.h:151:10`![IFNAMSIZcxx . . $ `<external>/2638090476884991293/if.h:129:10`!-1] = 0;
123 if (ioctlcxx . . $ ioctl(67fa1c773b05068c).(fd, SIOCGIFHWADDRcxx . . $ `<external>/13324550044150506404/sockios.h:80:9`!, &ifr) >= 0) {
124 memcpycxx . . $ memcpy(cc817cb175f282d).(mac, ifr.ifr_hwaddrcxx . . $ `<external>/2638090476884991293/if.h:152:10`!.sa_datacxx . . $ sockaddr#sa_data., sizeof(mac));
125 snprintfcxx . . $ snprintf(ea502d73e74c754c).(mac_buf, sizeof(mac_buf),
126 "%02X:%02X:%02X:%02X:%02X:%02X",
127 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
128 } else
129 mac_buf[0] = 0;
130
131 return mac_buf;
132 }
133 #elif defined(OS_SOLARIS)
134 #include <sys/socket.h>
135 #include <ifaddrs.h>
136 #include <netdb.h>
137 #include <sys/ioctl.h>
138 #include <string.h>
139 #include <net/if.h>
140 #include <arpa/inet.h>
141 #include <sys/sockio.h>
142 #include <net/if_types.h>
143 #include <libdlpi.h>
144
145 static char *get_mac(const struct ifaddrs *ifa, int fd)
146 {
147 struct lifreq lifr;
148 size_t physaddrlen = DLPI_PHYSADDR_MAX;
149 uchar_t physaddr[DLPI_PHYSADDR_MAX];
150 static char mac_buf[DLPI_PHYSADDR_MAX];
151 char *str;
152 int retv;
153 dlpi_handle_t dh;
154 dlpi_info_t dlinfo;
155
156 memset(mac_buf, 0, sizeof(mac_buf));
157 memset(&lifr, 0, sizeof(struct lifreq));
158 strlcpy(lifr.lifr_name, ifa->ifa_name, sizeof (lifr.lifr_name));
159 if (ioctl(fd, SIOCGLIFFLAGS, &lifr) >= 0) {
160
161 if (lifr.lifr_flags & (IFF_VIRTUAL| IFF_IPMP))
162 return (mac_buf);
163
164 if (dlpi_open(lifr.lifr_name, &dh, 0) != DLPI_SUCCESS)
165 return (NULL);
166
167 retv = dlpi_get_physaddr(dh, DL_CURR_PHYS_ADDR, physaddr,
168 &physaddrlen);
169 if (retv != DLPI_SUCCESS) {
170 dlpi_close(dh);
171 return (NULL);
172 }
173
174 retv = dlpi_info(dh, &dlinfo, DLPI_INFO_VERSION);
175 if (retv != DLPI_SUCCESS) {
176 dlpi_close(dh);
177 return (NULL);
178 }
179 dlpi_close(dh);
180 str = _link_ntoa(physaddr, NULL, physaddrlen, IFT_OTHER);
181
182 if (str != NULL && physaddrlen != 0) {
183 switch(dlinfo.di_mactype) {
184 case DL_IB:
185 break;
186 default:
187 strlcpy(mac_buf, str, sizeof(mac_buf));
188 break;
189 }
190 free(str);
191 }
192 }
193 return mac_buf;
194 }
195
196 #elif defined(OS_FREEBSD)
197 static char *get_mac(const struct ifaddrs *ifa, int fd)
198 {
199 struct ifreq ifr;
200 unsigned char mac[6];
201 static char mac_buf[20];
202
203 memset(&ifr, 0, sizeof(struct ifreq));
204 strncpy(ifr.ifr_name, ifa->ifa_name, IFNAMSIZ);
205 ifr.ifr_name[IFNAMSIZ-1] = 0;
206
207 if (ioctl(fd, SIOCGHWADDR, &ifr) >= 0) {
208 memcpy(mac, ifr.ifr_addr.sa_data, sizeof(mac));
209 snprintf(mac_buf, sizeof(mac_buf),
210 "%02X:%02X:%02X:%02X:%02X:%02X",
211 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
212 } else {
213 mac_buf[0] = 0;
214 }
215
216 return mac_buf;
217 }
218 #endif
219
220 #if defined(OS_LINUXcxx . . $ `compat/oscap_platforms.h:38:10`!) || defined(OS_SOLARIS) || defined(OS_FREEBSD)
221 static int get_ifscxx . . $ get_ifs(8164f9e61f8947d8).(SEXP_tcxx . . $ SEXP_t# *item)
222 {
223 struct ifaddrscxx . . $ ifaddrs# *ifaddr, *ifa;
224 int family, rc=1;
225 char host[NI_MAXHOSTcxx . . $ `<external>/564697342961150458/netdb.h:638:11`!], *mac;
226 SEXP_tcxx . . $ SEXP_t# *attrs;
227 SEXP_tcxx . . $ SEXP_t# *r0, *r1, *r2;
228 #if defined(OS_SOLARIS)
229 int item_added = 0;
230 #endif
231
232 if (getifaddrscxx . . $ getifaddrs(1d1e0a5ba40b9a63).(&ifaddr) == -1)
233 return rc;
234
235 int fd = socketcxx . . $ socket(2326284602b0bb2d).(PF_INETcxx . . $ `<external>/8962547315054503424/socket.h:45:9`!, SOCK_DGRAMcxx . . $ `<external>/5956532346368192945/socket_type.h:31:9`!, IPPROTO_IPcxx . . $ `<external>/9581057695539925927/in.h:43:9`!);
236 if (fd < 0)
237 goto leave1;
238
239 /* Walk through linked list, maintaining head pointer so we
240 can free list later */
241 for (ifa = ifaddr; ifa != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; ifa = ifa->ifa_nextcxx . . $ ifaddrs#ifa_next.) {
242 if (ifa->ifa_addrcxx . . $ ifaddrs#ifa_addr.) {
243 family = ifa->ifa_addrcxx . . $ ifaddrs#ifa_addr.->sa_familycxx . . $ sockaddr#sa_family.;
244 if (family != AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`! && family != AF_INET6cxx . . $ `<external>/8962547315054503424/socket.h:105:9`!)
245 continue;
246 } else
247 continue;
248
249 mac = get_maccxx . . $ get_mac(4eee0b5a11f18b5).(ifa, fd);
250 #if defined(OS_SOLARIS)
251 if (mac == NULL) {
252 rc = 1;
253 goto leave2;
254 }
255 if (mac[0] == '\0')
256 continue;
257 #endif
258 if (family == AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!) {
259 rc = getnameinfocxx . . $ getnameinfo(44a49899269c09ff).(ifa->ifa_addrcxx . . $ ifaddrs#ifa_addr., sizeof(struct sockaddr_incxx . . $ sockaddr_in#),
260 host, NI_MAXHOSTcxx . . $ `<external>/564697342961150458/netdb.h:638:11`!, NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!, 0, NI_NUMERICHOSTcxx . . $ `<external>/564697342961150458/netdb.h:642:10`!);
261 if (rc) {
262 rc = 1;
263 goto leave2;
264 }
265 }
266 else {
267 struct sockaddr_in6cxx . . $ sockaddr_in6# *sin6p;
268 sin6p = (struct sockaddr_in6cxx . . $ sockaddr_in6# *) ifa->ifa_addrcxx . . $ ifaddrs#ifa_addr.;
269 if (! inet_ntopcxx . . $ inet_ntop(6a923972b45bea03).(family, (const void *)&sin6p->sin6_addrcxx . . $ sockaddr_in6#sin6_addr., host, NI_MAXHOSTcxx . . $ `<external>/564697342961150458/netdb.h:638:11`!)) {
270 rc = 1;
271 goto leave2;
272 }
273 }
274 attrs = probe_attr_creatcxx . . $ probe_attr_creat(5e3fef9c42f0315b).("name",
275 r0 = SEXP_string_newfcxx . . $ SEXP_string_newf(b2137ed863725962).("%s", ifa->ifa_namecxx . . $ ifaddrs#ifa_name.),
276 "ip_address",
277 r1 = SEXP_string_newfcxx . . $ SEXP_string_newf(b2137ed863725962).("%s", host),
278 "mac_address",
279 r2 = SEXP_string_newfcxx . . $ SEXP_string_newf(b2137ed863725962).("%s", mac),
280 NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!);
281 probe_item_ent_addcxx . . $ probe_item_ent_add(9f488d3b029fc9d1).(item, "interface", attrs, NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!);
282 #if defined(OS_SOLARIS)
283 item_added = 1;
284 #endif
285 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(attrs);
286 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(r0);
287 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(r1);
288 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(r2);
289 }
290 leave2:
291 closecxx . . $ close(7864480464b09eea).(fd);
292 #if defined(OS_SOLARIS)
293 if (item_added == 0) {
294 attrs = probe_attr_creat("name",
295 r0 = SEXP_string_newf("dummy0"),
296 "ip_address",
297 r1 = SEXP_string_newf("127.0.0.1"),
298 "mac_address",
299 r2 = SEXP_string_newf("aa:bb:cc:dd:ee:ff"),
300 NULL);
301 probe_item_ent_add(item, "interface", attrs, NULL);
302 SEXP_free(attrs);
303 SEXP_free(r0);
304 SEXP_free(r1);
305 SEXP_free(r2);
306 }
307 /* if not able to get info on interfaces, do not fail. */
308 if (rc > 0)
309 rc = 0;
310 #endif
311 leave1:
312 freeifaddrscxx . . $ freeifaddrs(195192b4a808fd42).(ifaddr);
313 return rc;
314 }
315
316 #elif defined(OS_WINDOWS)
317
318 #define VERSION_LEN 32
319 /* Microsoft recommends to start with a 15 kB buffer for GetAdaptersAddresses. */
320 #define ADDRESSES_BUFFER_SIZE 15000
321 #define MAX_TRIES 3
322 #define MAX_IP_ADDRESS_STRING_LENGTH 128
323
324 static int get_ifs(SEXP_t *item)
325 {
326 /*
327 * Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h
328 * to define the Windows Socket specification version we will use.
329 * The current version of the Windows Sockets specification is version 2.2.
330 * Version 2.2 is supported on all systems since Windows 95 OSR2.
331 */
332 WORD requested_version = MAKEWORD(2, 2);
333
334 WSADATA wsa_data;
335 int err = WSAStartup(requested_version, &wsa_data);
336 if (err != 0) {
337 char *error_message = oscap_windows_error_message(err);
338 dE("Can't initialize Winsock DLL. WSAStartup failed: %s", error_message);
339 free(error_message);
340 return 1;
341 }
342
343 PIP_ADAPTER_ADDRESSES addresses = NULL;
344 ULONG ret_val = 0;
345 ULONG addresses_size = ADDRESSES_BUFFER_SIZE;
346 ULONG family = AF_UNSPEC; // both IPv4 and IPv6
347 ULONG flags = GAA_FLAG_INCLUDE_PREFIX;
348 int iterations = 0;
349
350 /* Try to get information about network adapters and their adresses */
351 do {
352 addresses = malloc(addresses_size);
353 ret_val = GetAdaptersAddresses(family, flags, NULL, addresses, &addresses_size);
354 if (ret_val == ERROR_BUFFER_OVERFLOW) {
355 free(addresses);
356 addresses = NULL;
357 }
358 iterations++;
359 } while (ret_val == ERROR_BUFFER_OVERFLOW && iterations < MAX_TRIES);
360
361 if (ret_val != NO_ERROR) {
362 char *error_message = oscap_windows_error_message(err);
363 dE("Can't get information about network adapters and their adresses. %s", error_message);
364 free(error_message);
365 free(addresses);
366 WSACleanup();
367 return 1;
368 }
369
370 /* Iterate over all network adapters */
371 PIP_ADAPTER_ADDRESSES current_address = addresses;
372 while (current_address != NULL) {
373 /* MAC address */
374 char *mac_address_str;
375 if (current_address->PhysicalAddressLength != 0) {
376 /* n bytes of MAC address will be printed as:
377 (2 * n) hexa numbers + (n - 1) delimiters + 1 terminating null byte = 3 * n */
378 const size_t mac_address_str_len = current_address->PhysicalAddressLength * 3;
379 mac_address_str = malloc(mac_address_str_len);
380
381 for (unsigned i = 0; i < current_address->PhysicalAddressLength; i++) {
382 if (i == (current_address->PhysicalAddressLength - 1)) {
383 snprintf(mac_address_str + i * 3, mac_address_str_len, "%.2X",
384 (int)current_address->PhysicalAddress[i]);
385 } else {
386 snprintf(mac_address_str + i * 3, mac_address_str_len, "%.2X-",
387 (int)current_address->PhysicalAddress[i]);
388 }
389 }
390 } else {
391 mac_address_str = strdup("unknown");
392 }
393
394 /* Find the network intefrace name */
395 char *interface_name_str = oscap_windows_wstr_to_str(current_address->FriendlyName);
396
397 /* Iterate over all unicast IP addresses of the network interface */
398 PIP_ADAPTER_UNICAST_ADDRESS unicast_address = current_address->FirstUnicastAddress;
399 while (unicast_address != NULL) {
400 SOCKET_ADDRESS socket_address = unicast_address->Address;
401 WCHAR ip_address_wstr[MAX_IP_ADDRESS_STRING_LENGTH];
402 DWORD ip_address_wstr_length = MAX_IP_ADDRESS_STRING_LENGTH;
403 int rc = WSAAddressToStringW(socket_address.lpSockaddr, socket_address.iSockaddrLength, NULL, ip_address_wstr, &ip_address_wstr_length);
404 if (rc != 0) {
405 free(mac_address_str);
406 free(interface_name_str);
407 free(addresses);
408 WSACleanup();
409 return 1;
410 }
411
412 /* Add prefix length (mask) */
413 char *ip_address_str = oscap_windows_wstr_to_str(ip_address_wstr);
414 UINT8 prefix = unicast_address->OnLinkPrefixLength;
415 char *ip_address_with_prefix = oscap_sprintf("%s/%d", ip_address_str, prefix);
416 free(ip_address_str);
417
418 /* Create probe item */
419 SEXP_t *interface_name_sexp = SEXP_string_newf(interface_name_str);
420 SEXP_t *ip_address_sexp = SEXP_string_newf(ip_address_with_prefix);
421 SEXP_t *mac_address_sexp = SEXP_string_newf(mac_address_str);
422 SEXP_t *attrs = probe_attr_creat("name", interface_name_sexp,
423 "ip_address", ip_address_sexp,
424 "mac_address", mac_address_sexp,
425 NULL);
426 probe_item_ent_add(item, "interface", attrs, NULL);
427 SEXP_free(attrs);
428 SEXP_free(interface_name_sexp);
429 SEXP_free(ip_address_sexp);
430 SEXP_free(mac_address_sexp);
431 free(ip_address_with_prefix);
432
433 unicast_address = unicast_address->Next;
434 }
435 free(interface_name_str);
436 free(mac_address_str);
437 current_address = current_address->Next;
438 }
439
440 free(addresses);
441 WSACleanup();
442 return 0;
443 }
444
445 #else
446
447 static int get_ifs(SEXP_t *item)
448 {
449 /* TODO */
450
451 SEXP_t *attrs, *r0, *r1, *r2;
452
453 attrs = probe_attr_creat("name",
454 r0 = SEXP_string_newf("dummy0"),
455 "ip_address",
456 r1 = SEXP_string_newf("127.0.0.1"),
457 "mac_address",
458 r2 = SEXP_string_newf("aa:bb:cc:dd:ee:ff"),
459 NULL);
460
461 probe_item_ent_add(item, "interface", attrs, NULL);
462
463 SEXP_free(attrs);
464 SEXP_free(r0);
465 SEXP_free(r1);
466 SEXP_free(r2);
467
468 return 0;
469 }
470 #endif
471
472 /*
473 * If no forbidden chars are found, returns the trimmed length
474 * of the input string. Otherwise a negative number is returned
475 */
476 static ssize_tcxx . . $ ssize_t# __sysinfo_sanevalcxx . . $ __sysinfo_saneval(3c95bd14d5d5d286).(const char *s)
477 {
478 size_t i, space_count, real_length;
479
480 real_length = space_count = i = 0;
481
482 for (; i < strlencxx . . $ strlen(751346f8406fd082).(s); ++i) {
483 /* check for space */
484 if (isspacecxx . . $ `<external>/17904084882347303253/ctype.h:197:10`!(s[i])) {
485 if (real_length > 0) {
486 ++space_count;
487 continue;
488 }
489 }
490 /* check for printable */
491 if (!isprintcxx . . $ `<external>/17904084882347303253/ctype.h:195:10`!(s[i])) {
492 return -1;
493 }
494 /* check for forbidden chars */
495 switch(s[i]) {
496 case '\'':
497 case '"':
498 case '<':
499 case '>':
500 return -1;
501 }
502 /* Allowed character found */
503 real_length += 1 + space_count;
504 space_count = 0;
505 }
506 return (ssize_tcxx . . $ ssize_t#)real_length;
507 }
508
509 #ifndef OS_WINDOWS
510 static char *_get_os_releasecxx . . $ _get_os_release(a8b8e32347182212).(const char *oscap_probe_root)
511 {
512 char os_release_data[MAX_BUFFER_SIZEcxx . . $ `src/OVAL/probes/independent/system_info_probe.c:89:9`!+1];
513 char *ret = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
514
515 FILEcxx . . $ FILE# *fp = oscap_fopen_with_prefixcxx . . $ oscap_fopen_with_prefix(82ec0787cd37e0a3).(oscap_probe_root, "/etc/os-release");
516 if (fp == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!)
517 goto fail;
518
519 int rc = freadcxx . . $ fread(738fc8ac1d711e58).(os_release_data, 1, MAX_BUFFER_SIZEcxx . . $ `src/OVAL/probes/independent/system_info_probe.c:89:9`!, fp);
520 if (ferrorcxx . . $ ferror(89bc1efcdac0ca22).(fp))
521 goto finish;
522 os_release_data[rc] = '\0';
523 ret = strdupcxx . . $ strdup(a8b8e32347182212).(os_release_data);
524
525 finish:
526 fclosecxx . . $ fclose(89bc1efcdac0ca22).(fp);
527 fail:
528 return ret;
529 }
530
531 static char *_get_os_release_elemcxx . . $ _get_os_release_elem(b7b3a83273496486).(char *os_release_data, const char *elem_name)
532 {
533 if (os_release_data == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!)
534 return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
535
536 char *ret = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
537 size_t len = strlencxx . . $ strlen(751346f8406fd082).(os_release_data);
538
539 char elem_re[128] = {0};
540 snprintfcxx . . $ snprintf(ea502d73e74c754c).(elem_re, sizeof(elem_re), "%s%s%s", "^", elem_name, "=[\"']?(.*?)[\"']?$");
541
542 char *error;
543 int erroffset, ovec[_REGEX_RES_VECSIZEcxx . . $ `src/OVAL/probes/independent/system_info_probe.c:88:9`!] = {0};
544 oscap_pcre_tcxx . . $ oscap_pcre_t# *re = oscap_pcre_compilecxx . . $ oscap_pcre_compile(29ca11f2d36a957a).(elem_re, OSCAP_PCRE_OPTS_MULTILINEcxx . . $ OSCAP_PCRE_OPTS_MULTILINE., &error, &erroffset);
545 if (re == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) {
546 oscap_pcre_err_freecxx . . $ oscap_pcre_err_free(fda57c8427c60377).(error);
547 goto finish;
548 }
549
550 char *ptr = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
551 int rc = oscap_pcre_execcxx . . $ oscap_pcre_exec(7630dfd25fd504ec).(re, os_release_data, len, 0, 0, ovec, _REGEX_RES_VECSIZEcxx . . $ `src/OVAL/probes/independent/system_info_probe.c:88:9`!);
552 if (rc >= 0) {
553 /* ovec[0] and ovec[1] - are the start and the end of the whole pattern match (=".....")
554 * ovec[2] and ovec[3] - are start and end char positions of the capture group (.*?) */
555 ptr = strndupcxx . . $ strndup(eabdfdef77619b3d).(os_release_data+ovec[2], ovec[3]-ovec[2]);
556 ret = ptr;
557 }
558 oscap_pcre_freecxx . . $ oscap_pcre_free(804bb72472b0846e).(re);
559
560 finish:
561 return ret;
562 }
563
564 #if defined(OS_FREEBSD)
565 static char *_offline_get_hname(const char *oscap_probe_root)
566 {
567 FILE *fp;
568 size_t len;
569 char *strp;
570 char *entry;
571 char *hname;
572 char *ret = NULL;
573 char *line = NULL;
574 const char *sep = "\"";
575 const char *expected_entry = "hostname=";
576
577 fp = oscap_fopen_with_prefix(oscap_probe_root, "/etc/rc.conf");
578
579 if (!fp)
580 goto fail;
581
582 while (getline(&line, &len, fp) > 0) {
583 entry = strtok_r(line, sep, &strp);
584 if (strcmp(entry, expected_entry) == 0) {
585 hname = strtok_r(NULL, sep, &strp);
586 ret = strdup(hname);
587 break;
588 }
589 }
590
591 fclose(fp);
592 fail:
593 return ret;
594 }
595
596 #else
597 static char *_offline_get_hnamecxx . . $ _offline_get_hname(a8b8e32347182212).(const char *oscap_probe_root)
598 {
599 FILEcxx . . $ FILE# *fp;
600 char hname[HOST_NAME_MAXcxx . . $ `<external>/2191589805780913682/local_lim.h:93:9`!+1] = { '\0' };
601 char *ret = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
602 int rc;
603
604 fp = oscap_fopen_with_prefixcxx . . $ oscap_fopen_with_prefix(82ec0787cd37e0a3).(oscap_probe_root, "/etc/hostname");
605
606 if (fp == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!)
607 goto fail;
608
609 rc = freadcxx . . $ fread(738fc8ac1d711e58).(hname, 1, HOST_NAME_MAXcxx . . $ `<external>/2191589805780913682/local_lim.h:93:9`!, fp);
610 /* If file is empty, we don't want to allocate an empty string for it */
611 if (ferrorcxx . . $ ferror(89bc1efcdac0ca22).(fp) || rc == 0 )
612 goto finish;
613
614 hname[strcspncxx . . $ strcspn(335c1dc86f5c867f).(hname, "\n")] = '\0';
615 ret = strdupcxx . . $ strdup(a8b8e32347182212).(hname);
616
617 finish:
618 fclosecxx . . $ fclose(89bc1efcdac0ca22).(fp);
619 fail:
620 return ret;
621 }
622 #endif /* ifdef OS_FREEBSD */
623 #endif /* ifndef OS_WINDOWS */
624
625 #ifdef OS_WINDOWS
626 static char *get_windows_version()
627 {
628 /* We can't use GetVersionEx to get Windows version because we want to get
629 * the real Windows version, but the compatibilty mode lies to applications
630 * about system version. Moreover the GetVersionEx function is deprecated
631 * since Windows 8.1. Instead we need to access RtlGetVersion.
632 * Code inspired by https://github.com/GNOME/glib/blob/master/glib/gwin32.c
633 */
634 OSVERSIONINFOEXW osverinfo;
635 typedef NTSTATUS(WINAPI f_rtl_get_version) (PRTL_OSVERSIONINFOEXW);
636 f_rtl_get_version *rtl_get_version;
637 HMODULE hmodule;
638
639 hmodule = LoadLibraryW(L"ntdll.dll");
640 rtl_get_version = (f_rtl_get_version *)GetProcAddress(hmodule, "RtlGetVersion");
641
642 memset(&osverinfo, 0, sizeof(OSVERSIONINFOEXW));
643 osverinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
644 rtl_get_version(&osverinfo);
645
646 char *version = oscap_sprintf("%d.%d.%d", osverinfo.dwMajorVersion,
647 osverinfo.dwMinorVersion, osverinfo.dwBuildNumber);
648
649 return version;
650 }
651
652 static const char *get_windows_architecture(void)
653 {
654 SYSTEM_INFO si;
655 GetNativeSystemInfo(&si);
656 const char *arch;
657 switch (si.wProcessorArchitecture) {
658 case PROCESSOR_ARCHITECTURE_AMD64:
659 arch = "x64";
660 break;
661 case PROCESSOR_ARCHITECTURE_ARM:
662 arch = "ARM";
663 break;
664 case PROCESSOR_ARCHITECTURE_ARM64:
665 arch = "ARM64";
666 break;
667 case PROCESSOR_ARCHITECTURE_IA64:
668 arch = "Intel Itanium-based";
669 break;
670 case PROCESSOR_ARCHITECTURE_INTEL:
671 arch = "x86";
672 break;
673 case PROCESSOR_ARCHITECTURE_UNKNOWN:
674 default:
675 arch = "unknown";
676 break;
677 }
678 return arch;
679 }
680 #endif
681
682 int system_info_probe_offline_mode_supportedcxx . . $ system_info_probe_offline_mode_supported(b126dc7c1de90089).()
683 {
684 return PROBE_OFFLINE_OWNcxx . . $ PROBE_OFFLINE_OWN.;
685 }
686
687 int system_info_probe_maincxx . . $ system_info_probe_main(470536d3ffacaf10).(probe_ctxcxx . . $ probe_ctx# *ctx, void *arg)
688 {
689 SEXP_tcxx . . $ SEXP_t# *item = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
690 char *os_name, *architecture, *hname, *os_version = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
691 const char unknown[] = "Unknown";
692 int ret = 0;
693 (void)arg;
694
695 os_name = architecture = hname = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
696
697 #ifdef OS_WINDOWS
698 WCHAR computer_name_wstr[MAX_COMPUTERNAME_LENGTH + 1];
699 DWORD computer_name_len = MAX_COMPUTERNAME_LENGTH + 1;
700 GetComputerNameW(computer_name_wstr, &computer_name_len);
701
702 os_name = strdup("Windows");
703 os_version = get_windows_version();
704 architecture = strdup(get_windows_architecture());
705 hname = oscap_windows_wstr_to_str(computer_name_wstr);
706 #else
707 const char *oscap_probe_root = "";
708 if (ctx->offline_modecxx . . $ probe_ctx#offline_mode. & PROBE_OFFLINE_OWNcxx . . $ PROBE_OFFLINE_OWN.) {
709 oscap_probe_root = getenvcxx . . $ getenv(a8b8e32347182212).("OSCAP_PROBE_ROOT");
710 }
711 char *os_release_data = _get_os_releasecxx . . $ _get_os_release(a8b8e32347182212).(oscap_probe_root);
712 os_name = _get_os_release_elemcxx . . $ _get_os_release_elem(b7b3a83273496486).(os_release_data, "NAME");
713 os_version = _get_os_release_elemcxx . . $ _get_os_release_elem(b7b3a83273496486).(os_release_data, "VERSION");
714 if (ctx->offline_modecxx . . $ probe_ctx#offline_mode. == PROBE_OFFLINE_NONEcxx . . $ PROBE_OFFLINE_NONE.) {
715 struct utsnamecxx . . $ utsname# sname;
716 if (unamecxx . . $ uname(c69a16225c55e184).(&sname) == 0) {
717 architecture = strdupcxx . . $ strdup(a8b8e32347182212).(sname.machinecxx . . $ utsname#machine.);
718 hname = strdupcxx . . $ strdup(a8b8e32347182212).(sname.nodenamecxx . . $ utsname#nodename.);
719 }
720 } else if (ctx->offline_modecxx . . $ probe_ctx#offline_mode. & PROBE_OFFLINE_OWNcxx . . $ PROBE_OFFLINE_OWN.) {
721 hname = _offline_get_hnamecxx . . $ _offline_get_hname(a8b8e32347182212).(oscap_probe_root);
722 }
723 freecxx . . $ free(5d22bdacc48458e8).(os_release_data);
724 #endif
725
726 /* All four elements are required */
727 if (!os_name)
728 os_name = strdupcxx . . $ strdup(a8b8e32347182212).(unknown);
729
730 if (!os_version)
731 os_version = strdupcxx . . $ strdup(a8b8e32347182212).(unknown);
732
733 if (!architecture)
734 architecture = strdupcxx . . $ strdup(a8b8e32347182212).(unknown);
735
736 if (hname && *hname == '\0') {
737 freecxx . . $ free(5d22bdacc48458e8).(hname);
738 hname = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
739 }
740 if (!hname) {
741 hname = strdupcxx . . $ strdup(a8b8e32347182212).(unknown);
742 }
743
744 if (__sysinfo_sanevalcxx . . $ __sysinfo_saneval(3c95bd14d5d5d286).(os_name) < 1 ||
745 __sysinfo_sanevalcxx . . $ __sysinfo_saneval(3c95bd14d5d5d286).(os_version) < 1 ||
746 __sysinfo_sanevalcxx . . $ __sysinfo_saneval(3c95bd14d5d5d286).(architecture) < 1 ||
747 __sysinfo_sanevalcxx . . $ __sysinfo_saneval(3c95bd14d5d5d286).(hname) < 1) {
748 ret = PROBE_EINVALcxx . . $ `src/OVAL/probes/public/probe-common.h:8:9`!;
749 goto cleanup;
750 }
751
752 item = probe_item_createcxx . . $ probe_item_create(36b16a6622050a9c).(OVAL_INDEPENDENT_SYSCHAR_SUBTYPEcxx . . $ OVAL_INDEPENDENT_SYSCHAR_SUBTYPE., NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!,
753 "os_name", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., os_name,
754 "os_version", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., os_version,
755 "os_architecture", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., architecture,
756 "primary_host_name", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., hname,
757 NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!);
758 cleanup:
759 freecxx . . $ free(5d22bdacc48458e8).(os_name);
760 freecxx . . $ free(5d22bdacc48458e8).(os_version);
761 freecxx . . $ free(5d22bdacc48458e8).(architecture);
762 freecxx . . $ free(5d22bdacc48458e8).(hname);
763
764 if (ctx->offline_modecxx . . $ probe_ctx#offline_mode. == PROBE_OFFLINE_NONEcxx . . $ PROBE_OFFLINE_NONE. && item) {
765 if (get_ifscxx . . $ get_ifs(8164f9e61f8947d8).(item)) {
766 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(item);
767 return PROBE_EUNKNOWNcxx . . $ `src/OVAL/probes/public/probe-common.h:24:9`!;
768 }
769 }
770 probe_item_collectcxx . . $ probe_item_collect(11bb80e0c30650d7).(ctx, item);
771
772 return ret;
773 }