| 1 | /** |
| 2 | * @file process58_probe.c |
| 3 | * @brief process58 probe |
| 4 | * @author "Steve Grubb" <[email protected]> |
| 5 | * |
| 6 | * 2010/06/13 [email protected] |
| 7 | * This probe is able to process58 an process58_object as defined in OVAL 5.4 and 5.5. |
| 8 | * |
| 9 | */ |
| 10 | |
| 11 | /* |
| 12 | * Copyright 2009-2011 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 | * Steve Grubb <[email protected]> |
| 31 | * Petr Lautrbach <[email protected]> |
| 32 | */ |
| 33 | |
| 34 | /* |
| 35 | * process58 probe: |
| 36 | * |
| 37 | * command_line |
| 38 | * exec_time |
| 39 | * pid |
| 40 | * ppid |
| 41 | * priority |
| 42 | * ruid |
| 43 | * scheduling_class |
| 44 | * start_time |
| 45 | * tty |
| 46 | * user_id |
| 47 | * exec_shield |
| 48 | * loginuid |
| 49 | * posix_capability |
| 50 | * selinux_domain_label |
| 51 | * session_id |
| 52 | */ |
| 53 | |
| 54 | #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`! |
| 55 | #include <config.h>cxx . . $ `<file>/build/config.h`/ |
| 56 | #endif |
| 57 | |
| 58 | #include <stdlib.h> |
| 59 | #include <string.h> |
| 60 | #include <stdio.h> |
| 61 | #include <errno.h> |
| 62 | #include <limits.h> |
| 63 | #ifdef HAVE_STDIO_EXT_Hcxx . . $ `build/config.h:71:9`! |
| 64 | # include <stdio_ext.h> |
| 65 | #endif |
| 66 | #include <dirent.h> |
| 67 | #include <sys/stat.h> |
| 68 | #include <fcntl.h> |
| 69 | #include <sched.h> |
| 70 | #include <time.h> |
| 71 | |
| 72 | #ifdef HAVE_PROC_DEVNAME_H |
| 73 | #include <proc/devname.h> |
| 74 | #endif |
| 75 | |
| 76 | #ifdef SELINUX_FOUNDcxx . . $ `build/config.h:73:9`! |
| 77 | #include <selinux/selinux.h> |
| 78 | #include <selinux/context.h> |
| 79 | #endif |
| 80 | #ifdef CAP_FOUNDcxx . . $ `build/config.h:72:9`! |
| 81 | #include <ctype.h> |
| 82 | #include <sys/types.h> |
| 83 | |
| 84 | #ifndef HAVE_CAP_GET_PIDcxx . . $ `build/config.h:37:9`! // we don't have cap_get_pid => assume libcap version == 1 |
| 85 | #undef _POSIX_SOURCE |
| 86 | #define LIBCAP_VERSION 1 |
| 87 | #include <sys/capability.h> |
| 88 | #define CAP_LAST_CAP CAP_AUDIT_CONTROL |
| 89 | extern char const *_cap_names[]; |
| 90 | #else |
| 91 | #define LIBCAP_VERSIONcxx . . $ `src/OVAL/probes/unix/process58_probe.c:91:9`! 2 |
| 92 | #include <sys/capability.h> |
| 93 | #endif |
| 94 | |
| 95 | #include "util.h"cxx . . $ `<file>/src/common/util.h`/ |
| 96 | #include "process58-capability.h"cxx . . $ `<file>/src/OVAL/probes/unix/process58-capability.h`/ |
| 97 | #endif /* CAP_FOUND */ |
| 98 | |
| 99 | #include <probe/probe.h>cxx . . $ `<file>/src/OVAL/probes/probe/probe.h`/ |
| 100 | |
| 101 | #include "_seap.h"cxx . . $ `<file>/src/OVAL/probes/SEAP/_seap.h`/ |
| 102 | #include "probe-api.h"cxx . . $ `<file>/src/OVAL/probes/public/probe-api.h`/ |
| 103 | #include "probe/entcmp.h"cxx . . $ `<file>/src/OVAL/probes/probe/entcmp.h`/ |
| 104 | #include "common/debug_priv.h"cxx . . $ `<file>/src/common/debug_priv.h`/ |
| 105 | #include <ctype.h> |
| 106 | #include "common/oscap_buffer.h"cxx . . $ `<file>/src/common/oscap_buffer.h`/ |
| 107 | #include "process58_probe.h"cxx . . $ `<file>/src/OVAL/probes/unix/process58_probe.h`/ |
| 108 | #include "oscap_helpers.h"cxx . . $ `<file>/src/common/public/oscap_helpers.h`/ |
| 109 | |
| 110 | #define CHUNK_SIZEcxx . . $ `src/OVAL/probes/unix/process58_probe.c:110:9`! 1024 |
| 111 | |
| 112 | /* Convenience structure for the results being reported */ |
| 113 | struct result_infocxx . . $ result_info# { |
| 114 | const char *command_linecxx . . $ result_info#command_line.; |
| 115 | const char *exec_timecxx . . $ result_info#exec_time.; |
| 116 | unsigned pidcxx . . $ result_info#pid.; |
| 117 | unsigned ppidcxx . . $ result_info#ppid.; |
| 118 | long prioritycxx . . $ result_info#priority.; |
| 119 | int ruidcxx . . $ result_info#ruid.; |
| 120 | const char *scheduling_classcxx . . $ result_info#scheduling_class.; |
| 121 | const char *start_timecxx . . $ result_info#start_time.; |
| 122 | const char *ttycxx . . $ result_info#tty.; |
| 123 | int user_idcxx . . $ result_info#user_id.; |
| 124 | int exec_shieldcxx . . $ result_info#exec_shield.; |
| 125 | unsigned loginuidcxx . . $ result_info#loginuid.; |
| 126 | char **posix_capabilitycxx . . $ result_info#posix_capability.; |
| 127 | const char *selinux_domain_labelcxx . . $ result_info#selinux_domain_label.; |
| 128 | int session_idcxx . . $ result_info#session_id.; |
| 129 | }; |
| 130 | |
| 131 | static void report_findingcxx . . $ report_finding(a44e8875aacc0cc1).(struct result_infocxx . . $ result_info# *res, probe_ctxcxx . . $ probe_ctx# *ctx) |
| 132 | { |
| 133 | SEXP_tcxx . . $ SEXP_t# *item; |
| 134 | |
| 135 | item = probe_item_createcxx . . $ probe_item_create(36b16a6622050a9c).(OVAL_UNIX_PROCESS58cxx . . $ OVAL_UNIX_PROCESS58., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, |
| 136 | "command_line", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., res->command_linecxx . . $ result_info#command_line., |
| 137 | "exec_time", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., res->exec_timecxx . . $ result_info#exec_time., |
| 138 | "pid", OVAL_DATATYPE_INTEGERcxx . . $ OVAL_DATATYPE_INTEGER., (int64_tcxx . . $ int64_t#)res->pidcxx . . $ result_info#pid., |
| 139 | "ppid", OVAL_DATATYPE_INTEGERcxx . . $ OVAL_DATATYPE_INTEGER., (int64_tcxx . . $ int64_t#)res->ppidcxx . . $ result_info#ppid., |
| 140 | "priority", OVAL_DATATYPE_INTEGERcxx . . $ OVAL_DATATYPE_INTEGER., (int64_tcxx . . $ int64_t#)res->prioritycxx . . $ result_info#priority., |
| 141 | "ruid", OVAL_DATATYPE_INTEGERcxx . . $ OVAL_DATATYPE_INTEGER., (int64_tcxx . . $ int64_t#) res->ruidcxx . . $ result_info#ruid., |
| 142 | "scheduling_class", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., res->scheduling_classcxx . . $ result_info#scheduling_class., |
| 143 | "start_time", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., res->start_timecxx . . $ result_info#start_time., |
| 144 | "tty", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., res->ttycxx . . $ result_info#tty., |
| 145 | "user_id", OVAL_DATATYPE_INTEGERcxx . . $ OVAL_DATATYPE_INTEGER., (int64_tcxx . . $ int64_t#)res->user_idcxx . . $ result_info#user_id., |
| 146 | "exec_shield", OVAL_DATATYPE_BOOLEANcxx . . $ OVAL_DATATYPE_BOOLEAN., (boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!)res->exec_shieldcxx . . $ result_info#exec_shield., |
| 147 | "loginuid", OVAL_DATATYPE_INTEGERcxx . . $ OVAL_DATATYPE_INTEGER., (int64_tcxx . . $ int64_t#)res->loginuidcxx . . $ result_info#loginuid., |
| 148 | "posix_capability", OVAL_DATATYPE_STRING_Mcxx . . $ OVAL_DATATYPE_STRING_M., res->posix_capabilitycxx . . $ result_info#posix_capability., |
| 149 | "selinux_domain_label", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., res->selinux_domain_labelcxx . . $ result_info#selinux_domain_label., |
| 150 | "session_id", OVAL_DATATYPE_INTEGERcxx . . $ OVAL_DATATYPE_INTEGER., (int64_tcxx . . $ int64_t#)res->session_idcxx . . $ result_info#session_id., |
| 151 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 152 | |
| 153 | probe_item_collectcxx . . $ probe_item_collect(11bb80e0c30650d7).(ctx, item); |
| 154 | } |
| 155 | |
| 156 | #if defined(OS_LINUXcxx . . $ `compat/oscap_platforms.h:38:10`!) |
| 157 | |
| 158 | static unsigned long tickscxx . . $ ticks., bootcxx . . $ boot.; |
| 159 | |
| 160 | static void get_boot_timecxx . . $ get_boot_time(49f6e7a06ebc5aa8).(void) |
| 161 | { |
| 162 | char buf[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 163 | FILEcxx . . $ FILE# *sf; |
| 164 | int line; |
| 165 | |
| 166 | bootcxx . . $ boot. = 0; |
| 167 | const char *prefix = getenvcxx . . $ getenv(a8b8e32347182212).("OSCAP_PROBE_ROOT"); |
| 168 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf, sizeof(buf), "%s/proc/stat", prefix ? prefix : ""); |
| 169 | sf = fopencxx . . $ fopen(82ec0787cd37e0a3).(buf, "rt"); |
| 170 | if (sf == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 171 | return; |
| 172 | |
| 173 | line = 0; |
| 174 | __fsetlockingcxx . . $ __fsetlocking(c2adc39b7d70763e).(sf, FSETLOCKING_BYCALLERcxx . . $ `<external>/9684955786050076606/stdio_ext.h:38:9`!); |
| 175 | while (fgetscxx . . $ fgets(efb0aaba7ac866ae).(buf, sizeof(buf), sf)) { |
| 176 | if (line == 0) { |
| 177 | line++; |
| 178 | continue; |
| 179 | } |
| 180 | if (memcmpcxx . . $ memcmp(36f949851efa3055).(buf, "btime", 5) == 0) { |
| 181 | sscanfcxx . . $ sscanf(5e8a2c12db2ea735).(buf, "btime %lu", &bootcxx . . $ boot.); |
| 182 | break; |
| 183 | } |
| 184 | } |
| 185 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(sf); |
| 186 | } |
| 187 | |
| 188 | static int get_uidscxx . . $ get_uids(60e87f32f3a14ea7).(int pid, struct result_infocxx . . $ result_info# *r) |
| 189 | { |
| 190 | char buf[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 191 | FILEcxx . . $ FILE# *sf; |
| 192 | |
| 193 | r->ruidcxx . . $ result_info#ruid. = -1; |
| 194 | r->user_idcxx . . $ result_info#user_id. = -1; |
| 195 | r->loginuidcxx . . $ result_info#loginuid. = -1; |
| 196 | |
| 197 | const char *prefix = getenvcxx . . $ getenv(a8b8e32347182212).("OSCAP_PROBE_ROOT"); |
| 198 | |
| 199 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf, sizeof(buf), "%s/proc/%d/status", prefix ? prefix : "", pid); |
| 200 | sf = fopencxx . . $ fopen(82ec0787cd37e0a3).(buf, "rt"); |
| 201 | if (sf) { |
| 202 | int line = 0; |
| 203 | __fsetlockingcxx . . $ __fsetlocking(c2adc39b7d70763e).(sf, FSETLOCKING_BYCALLERcxx . . $ `<external>/9684955786050076606/stdio_ext.h:38:9`!); |
| 204 | while (fgetscxx . . $ fgets(efb0aaba7ac866ae).(buf, sizeof(buf), sf)) { |
| 205 | if (line == 0) { |
| 206 | line++; |
| 207 | continue; |
| 208 | } |
| 209 | if (memcmpcxx . . $ memcmp(36f949851efa3055).(buf, "Uid:", 4) == 0) { |
| 210 | sscanfcxx . . $ sscanf(5e8a2c12db2ea735).(buf, "Uid: %d %d", &r->ruidcxx . . $ result_info#ruid., &r->user_idcxx . . $ result_info#user_id.); |
| 211 | break; |
| 212 | } |
| 213 | } |
| 214 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(sf); |
| 215 | } |
| 216 | |
| 217 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf, sizeof(buf), "%s/proc/%d/loginuid", prefix ? prefix : "", pid); |
| 218 | sf = fopencxx . . $ fopen(82ec0787cd37e0a3).(buf, "rt"); |
| 219 | if (sf) { |
| 220 | if (fscanfcxx . . $ fscanf(bc216f8e5b1ebeac).(sf, "%u", &r->loginuidcxx . . $ result_info#loginuid.) < 1) { |
| 221 | dWcxx . . $ `src/common/debug_priv.h:62:9`!("fscanf failed from %s", buf); |
| 222 | } |
| 223 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(sf); |
| 224 | } |
| 225 | |
| 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | static char *convert_timecxx . . $ convert_time(6012a4799d7b29fc).(unsigned long long t, char *tbuf, int tb_size) |
| 230 | { |
| 231 | unsigned d,h,m,s; |
| 232 | |
| 233 | s = t%60; |
| 234 | t /= 60; |
| 235 | m = t%60; |
| 236 | t /=60; |
| 237 | h = t%24; |
| 238 | t /= 24; |
| 239 | d = t; |
| 240 | if (d) |
| 241 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(tbuf, tb_size, "%u-%02u:%02u:%02u", d, h, m, s); |
| 242 | else |
| 243 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(tbuf, tb_size, "%02u:%02u:%02u", h, m, s); |
| 244 | return tbuf; |
| 245 | } |
| 246 | |
| 247 | #ifdef SELINUX_FOUNDcxx . . $ `build/config.h:73:9`! |
| 248 | static char *get_selinux_labelcxx . . $ get_selinux_label(ff224f080444ee45).(int pid) { |
| 249 | char *selinux_label; |
| 250 | char *pid_context; |
| 251 | context_tcxx . . $ context_t# context; |
| 252 | |
| 253 | if (is_selinux_enabledcxx . . $ is_selinux_enabled(b126dc7c1de90089).() == 1) { |
| 254 | if (getpidconcxx . . $ getpidcon(afcd3168fc1188a4).(pid, &pid_context) == -1) { |
| 255 | /* error getting pid selinux context */ |
| 256 | dWcxx . . $ `src/common/debug_priv.h:62:9`!("Can't get selinux context for process %d", pid); |
| 257 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 258 | } |
| 259 | context = context_newcxx . . $ context_new(48298312e2d58ff4).(pid_context); |
| 260 | if (context == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 261 | // There must be 3 or 4 colon-separated components and no |
| 262 | // whitespace in any component other than the MLS |
| 263 | // component. |
| 264 | freeconcxx . . $ freecon(fda57c8427c60377).(pid_context); |
| 265 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 266 | } |
| 267 | selinux_label = strdupcxx . . $ strdup(a8b8e32347182212).(context_type_getcxx . . $ context_type_get(937a50f5ac5c103a).(context)); |
| 268 | context_freecxx . . $ context_free(7fa3f91f37ede77).(context); |
| 269 | freeconcxx . . $ freecon(fda57c8427c60377).(pid_context); |
| 270 | return selinux_label; |
| 271 | } else { |
| 272 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 273 | } |
| 274 | } |
| 275 | #else |
| 276 | static char *get_selinux_label(int pid) { |
| 277 | return NULL; |
| 278 | } |
| 279 | #endif /* SELINUX_FOUND */ |
| 280 | |
| 281 | static char **get_posix_capabilitycxx . . $ get_posix_capability(f769fdfdd161e4bf).(int pid, int max_cap_id) { |
| 282 | #ifdef CAP_FOUNDcxx . . $ `build/config.h:72:9`! |
| 283 | cap_tcxx . . $ cap_t# pid_caps; |
| 284 | char *cap_name, **ret = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 285 | unsigned cap_value, ret_index = 0; |
| 286 | cap_flag_value_tcxx . . $ cap_flag_value_t# cap_flag; |
| 287 | int cap_id; |
| 288 | |
| 289 | #if LIBCAP_VERSIONcxx . . $ `src/OVAL/probes/unix/process58_probe.c:91:9`! == 1 |
| 290 | pid_caps = cap_init(); |
| 291 | if (capgetp(pid, pid_caps) == -1) { |
| 292 | dW("Can't get capabilities for process %d", pid); |
| 293 | cap_free(pid_caps); |
| 294 | return NULL; |
| 295 | } |
| 296 | #elif LIBCAP_VERSIONcxx . . $ `src/OVAL/probes/unix/process58_probe.c:91:9`! == 2 |
| 297 | pid_caps = cap_get_pidcxx . . $ cap_get_pid(a9fb606daf20ad0c).(pid); |
| 298 | #else |
| 299 | dW("Can't detect libcap version"); |
| 300 | return NULL; |
| 301 | #endif |
| 302 | |
| 303 | if (pid_caps == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 304 | dWcxx . . $ `src/common/debug_priv.h:62:9`!("Can't get capabilities for process %d", pid); |
| 305 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 306 | } |
| 307 | |
| 308 | for (cap_value = 0; cap_value < CAP_LAST_CAPcxx . . $ `<external>/9308485078006088655/capability.h:421:9`!; cap_value++) { |
| 309 | if (cap_get_flagcxx . . $ cap_get_flag(edb66f3a20902e53).(pid_caps, cap_value, CAP_EFFECTIVEcxx . . $ CAP_EFFECTIVE., &cap_flag) == -1) |
| 310 | continue; |
| 311 | if (cap_flag == CAP_SETcxx . . $ CAP_SET.) { |
| 312 | #if LIBCAP_VERSIONcxx . . $ `src/OVAL/probes/unix/process58_probe.c:91:9`! == 2 |
| 313 | cap_name = cap_to_namecxx . . $ cap_to_name(ff224f080444ee45).(cap_value); |
| 314 | #else |
| 315 | cap_name = strdup(_cap_names[cap_value]); |
| 316 | #endif |
| 317 | if (cap_name != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 318 | char *cap_name_p = cap_name; |
| 319 | while (*cap_name_p) { |
| 320 | *cap_name_p = touppercxx . . $ `<external>/17904084882347303253/ctype.h:221:11`!(*cap_name_p); |
| 321 | cap_name_p++; |
| 322 | } |
| 323 | |
| 324 | cap_id = oscap_string_to_enumcxx . . $ oscap_string_to_enum(851d6ce10579b7d8).(CapabilityTypecxx . . $ CapabilityType., cap_name); |
| 325 | if (cap_id > -1 && cap_id <= max_cap_id) { |
| 326 | void *new_ret = realloccxx . . $ realloc(417ab160f6baadc6).(ret, (ret_index + 1) * sizeof(char *)); |
| 327 | if (new_ret == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 328 | dEcxx . . $ `src/common/debug_priv.h:63:9`!("Unable to re-allocate memory for ret"); |
| 329 | cap_freecxx . . $ cap_free(dedf1e9b1c614a07).(cap_name); |
| 330 | freecxx . . $ free(5d22bdacc48458e8).(ret); |
| 331 | ret = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 332 | goto exit; |
| 333 | } |
| 334 | ret = new_ret; |
| 335 | ret[ret_index] = strdupcxx . . $ strdup(a8b8e32347182212).(cap_name); |
| 336 | ret_index++; |
| 337 | } |
| 338 | cap_freecxx . . $ cap_free(dedf1e9b1c614a07).(cap_name); |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | void *new_ret = realloccxx . . $ realloc(417ab160f6baadc6).(ret, (ret_index + 1) * sizeof(char *)); |
| 343 | if (new_ret == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 344 | dEcxx . . $ `src/common/debug_priv.h:63:9`!("Unable to re-allocate memory for ret"); |
| 345 | freecxx . . $ free(5d22bdacc48458e8).(ret); |
| 346 | ret = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 347 | goto exit; |
| 348 | } |
| 349 | ret = new_ret; |
| 350 | ret[ret_index] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 351 | |
| 352 | exit: |
| 353 | cap_freecxx . . $ cap_free(dedf1e9b1c614a07).(pid_caps); |
| 354 | return ret; |
| 355 | #else |
| 356 | return NULL; |
| 357 | #endif |
| 358 | } |
| 359 | |
| 360 | /* get exec shield status according to http://people.redhat.com/sgrubb/files/lsexec |
| 361 | * return value: -1 - not detected, 0 - disabled, 1 - enabled */ |
| 362 | static int get_exec_shield_statuscxx . . $ get_exec_shield_status(7864480464b09eea).(int pid) { |
| 363 | char buf[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 364 | FILEcxx . . $ FILE# *sf; |
| 365 | long unsigned low, high, inode; |
| 366 | long long unsigned offset; |
| 367 | int dev_min, dev_maj; |
| 368 | char perm[3], trim; |
| 369 | int ret = -1, read_items; |
| 370 | |
| 371 | const char *prefix = getenvcxx . . $ getenv(a8b8e32347182212).("OSCAP_PROBE_ROOT"); |
| 372 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf, sizeof(buf), "%s/proc/%d/maps", prefix ? prefix : "", pid); |
| 373 | sf = fopencxx . . $ fopen(82ec0787cd37e0a3).(buf, "rt"); |
| 374 | if (sf) { |
| 375 | while (fgetscxx . . $ fgets(efb0aaba7ac866ae).(buf, 500, sf)) { |
| 376 | read_items = sscanfcxx . . $ sscanf(5e8a2c12db2ea735).( |
| 377 | buf, "%lx-%lx rw%s %llx %x:%x %lu %c\n", |
| 378 | &low, &high, perm, &offset, &dev_min, |
| 379 | &dev_maj, &inode, &trim |
| 380 | ); |
| 381 | if (read_items == 7) { |
| 382 | if (perm[0] == 'x' && offset != 0) { |
| 383 | ret = 0; |
| 384 | } |
| 385 | else { |
| 386 | ret = 1; |
| 387 | } |
| 388 | } |
| 389 | } |
| 390 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(sf); |
| 391 | } |
| 392 | |
| 393 | return ret; |
| 394 | } |
| 395 | |
| 396 | /** |
| 397 | * Parse /proc/%d/cmdline file |
| 398 | * @param filepath Path to file ~ use preallocated buffer for the path |
| 399 | * @param buffer output buffer with non-zero size |
| 400 | * @return ps-like command info or NULL |
| 401 | */ |
| 402 | static inline boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! get_process_cmdlinecxx . . $ get_process_cmdline(f76e396f991ce395).(const char* filepath, struct oscap_buffercxx . . $ oscap_buffer#* const buffer){ |
| 403 | |
| 404 | int fd = opencxx . . $ open(e156e3aa1e5c4ad1).(filepath, O_RDONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:43:9`!, 0); |
| 405 | |
| 406 | if (fd < 0) { |
| 407 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 408 | } |
| 409 | |
| 410 | oscap_buffer_clearcxx . . $ oscap_buffer_clear(952d67516e6b9978).(buffer); |
| 411 | |
| 412 | |
| 413 | |
| 414 | for(;;) { |
| 415 | char chunk[CHUNK_SIZEcxx . . $ `src/OVAL/probes/unix/process58_probe.c:110:9`!]; |
| 416 | // Read data, store to buffer |
| 417 | ssize_tcxx . . $ ssize_t# read_size = readcxx . . $ read(7e34d0a36f355389).(fd, chunk, CHUNK_SIZEcxx . . $ `src/OVAL/probes/unix/process58_probe.c:110:9`!); |
| 418 | if (read_size < 0) { |
| 419 | closecxx . . $ close(7864480464b09eea).(fd); |
| 420 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 421 | } |
| 422 | oscap_buffer_append_binary_datacxx . . $ oscap_buffer_append_binary_data(ba3f817601beb05d).(buffer, chunk, read_size); |
| 423 | |
| 424 | // If reach end of file, then end the loop |
| 425 | if (CHUNK_SIZEcxx . . $ `src/OVAL/probes/unix/process58_probe.c:110:9`! != read_size) { |
| 426 | break; |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | closecxx . . $ close(7864480464b09eea).(fd); |
| 431 | |
| 432 | int length = oscap_buffer_get_lengthcxx . . $ oscap_buffer_get_length(6e8c5100821ac051).(buffer); |
| 433 | char* buffer_mem = oscap_buffer_get_rawcxx . . $ oscap_buffer_get_raw(3cd9678435dc2626).(buffer); |
| 434 | |
| 435 | if ( length == 0 ) { // empty file |
| 436 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 437 | } else { |
| 438 | |
| 439 | // Skip multiple trailing zeros |
| 440 | int i = length - 1; |
| 441 | while ( (i > 0) && (buffer_mem[i] == '\0') ) { |
| 442 | --i; |
| 443 | } |
| 444 | |
| 445 | // Program and args are separated by '\0' |
| 446 | // Replace them with spaces ' ' |
| 447 | while( i >= 0 ){ |
| 448 | char chr = buffer_mem[i]; |
| 449 | if ( ( chr == '\0') || ( chr == '\n' ) ) { |
| 450 | buffer_mem[i] = ' '; |
| 451 | } else if ( !isprintcxx . . $ `<external>/17904084882347303253/ctype.h:195:10`!(chr) ) { // "ps" replace non-printable characters with '.' (LC_ALL=C) |
| 452 | buffer_mem[i] = '.'; |
| 453 | } |
| 454 | --i; |
| 455 | } |
| 456 | } |
| 457 | return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 458 | } |
| 459 | |
| 460 | /** |
| 461 | * Make "[%s] <defunct>" from cmd string - inplace |
| 462 | * @param cmd_buffer @see read_process() > cmd_buffer |
| 463 | * @return pointer to start of string |
| 464 | */ |
| 465 | static inline char *make_defunc_strcxx . . $ make_defunc_str(7a9722d75b371431).(char* const cmd_buffer){ |
| 466 | static const char DEFUNC_STR[] = "] <defunct>"; |
| 467 | |
| 468 | size_t len = strlencxx . . $ strlen(751346f8406fd082).(cmd_buffer); |
| 469 | memcpycxx . . $ memcpy(cc817cb175f282d).(cmd_buffer + len, DEFUNC_STR, sizeof(DEFUNC_STR)); |
| 470 | return cmd_buffer; |
| 471 | } |
| 472 | |
| 473 | static int read_processcxx . . $ read_process(8cb7114d8bc47ec5).(SEXP_tcxx . . $ SEXP_t# *cmd_ent, SEXP_tcxx . . $ SEXP_t# *pid_ent, probe_ctxcxx . . $ probe_ctx# *ctx) |
| 474 | { |
| 475 | char buf[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 476 | int max_cap_id; |
| 477 | DIRcxx . . $ DIR# *d; |
| 478 | struct direntcxx . . $ dirent# *ent; |
| 479 | oval_schema_version_tcxx . . $ oval_schema_version_t# oval_version; |
| 480 | struct tmcxx . . $ tm# result; |
| 481 | |
| 482 | const char *prefix = getenvcxx . . $ getenv(a8b8e32347182212).("OSCAP_PROBE_ROOT"); |
| 483 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf, PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!, "%s/proc", prefix ? prefix : ""); |
| 484 | d = opendircxx . . $ opendir(f465d4b65cec8dd2).(buf); |
| 485 | if (d == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 486 | return prefix ? PROBE_ESUCCESScxx . . $ `src/OVAL/probes/public/probe-common.h:7:9`! : PROBE_EACCESScxx . . $ `src/OVAL/probes/public/probe-api.h:431:9`!; |
| 487 | } |
| 488 | |
| 489 | // Get the time tick hertz |
| 490 | tickscxx . . $ ticks. = (unsigned long)sysconfcxx . . $ sysconf(dc1f09c09fbff20f).(_SC_CLK_TCKcxx . . $ `<external>/6393649343499073842/confname.h:78:9`!); |
| 491 | get_boot_timecxx . . $ get_boot_time(49f6e7a06ebc5aa8).(); |
| 492 | |
| 493 | oval_version = probe_obj_get_platform_schema_versioncxx . . $ probe_obj_get_platform_schema_version(5bacca80194debea).(probe_ctx_getobjectcxx . . $ probe_ctx_getobject(4299b6b53fa804a5).(ctx)); |
| 494 | if (oval_schema_version_cmpcxx . . $ oval_schema_version_cmp(b4d0c2bfb97f274f).(oval_version, OVAL_SCHEMA_VERSIONcxx . . $ `src/OVAL/public/oval_schema_version.h:39:9`!(5.11)) < 0) { |
| 495 | max_cap_id = OVAL_5_8_MAX_CAP_IDcxx . . $ `src/OVAL/probes/unix/process58-capability.h:8:9`!; |
| 496 | } else { |
| 497 | max_cap_id = OVAL_5_11_MAX_CAP_IDcxx . . $ `src/OVAL/probes/unix/process58-capability.h:9:9`!; |
| 498 | } |
| 499 | |
| 500 | struct oscap_buffercxx . . $ oscap_buffer# *cmdline_buffer = oscap_buffer_newcxx . . $ oscap_buffer_new(78ca002e694d04d).(); |
| 501 | |
| 502 | char cmd_buffer[1 + 15 + 11 + 1]; // Format:" [ cmd:15 ] <defunc>" |
| 503 | cmd_buffer[0] = '['; |
| 504 | |
| 505 | // Scan the directories |
| 506 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! any_pid_dir_found = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 507 | while (( ent = readdircxx . . $ readdir(ffbaae344e1a615a).(d) )) { |
| 508 | int fd, len; |
| 509 | char *tmp, state, tty_dev[128]; |
| 510 | int pid, ppid, pgrp, session, tty_nr, tpgid; |
| 511 | unsigned flags, sched_policy; |
| 512 | unsigned long minflt, cminflt, majflt, cmajflt, uutime, ustime; |
| 513 | long cutime, cstime, priority, cnice, nthreads, itrealvalue; |
| 514 | unsigned long long start; |
| 515 | SEXP_tcxx . . $ SEXP_t# *cmd_sexp = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, *pid_sexp = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 516 | |
| 517 | // Skip non-process58 dir entries |
| 518 | if(*ent->d_namecxx . . $ dirent#d_name.<'0' || *ent->d_namecxx . . $ dirent#d_name.>'9') |
| 519 | continue; |
| 520 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = 0; |
| 521 | pid = strtolcxx . . $ strtol(44bbb87609b212fc).(ent->d_namecxx . . $ dirent#d_name., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 10); |
| 522 | if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! || pid == 2) // skip err & kthreads |
| 523 | continue; |
| 524 | |
| 525 | // Parse up the stat file for the proc |
| 526 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf, PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!, "%s/proc/%d/stat", prefix ? prefix : "", pid); |
| 527 | fd = opencxx . . $ open(e156e3aa1e5c4ad1).(buf, O_RDONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:43:9`!, 0); |
| 528 | if (fd < 0) |
| 529 | continue; |
| 530 | len = readcxx . . $ read(7e34d0a36f355389).(fd, buf, sizeof buf - 1); |
| 531 | closecxx . . $ close(7864480464b09eea).(fd); |
| 532 | if (len < 40) |
| 533 | continue; |
| 534 | buf[len] = 0; |
| 535 | tmp = strrchrcxx . . $ strrchr(2050848944e00d54).(buf, ')'); |
| 536 | if (tmp) |
| 537 | *tmp = 0; |
| 538 | else |
| 539 | continue; |
| 540 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(cmd_buffer + 1, 0, sizeof(cmd_buffer)-1); // clear cmd after starting '[' |
| 541 | sscanfcxx . . $ sscanf(5e8a2c12db2ea735).(buf, "%d (%15c", &ppid, cmd_buffer + 1); |
| 542 | sscanfcxx . . $ sscanf(5e8a2c12db2ea735).(tmp+2, "%c %d %d %d %d %d " |
| 543 | "%u %lu %lu %lu %lu " |
| 544 | "%lu %lu %lu %ld %ld " |
| 545 | "%ld %ld %ld %llu", |
| 546 | &state, &ppid, &pgrp, &session, &tty_nr, &tpgid, |
| 547 | &flags, &minflt, &cminflt, &majflt, &cmajflt, |
| 548 | &uutime, &ustime, &cutime, &cstime, &priority, |
| 549 | &cnice, &nthreads, &itrealvalue, &start |
| 550 | ); |
| 551 | |
| 552 | // Skip kthreads |
| 553 | if (ppid == 2) |
| 554 | continue; |
| 555 | |
| 556 | const char* cmd; |
| 557 | if (state == 'Z') { // zombie |
| 558 | cmd = make_defunc_strcxx . . $ make_defunc_str(7a9722d75b371431).(cmd_buffer); |
| 559 | } else { |
| 560 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf, PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!, "%s/proc/%d/cmdline", prefix ? prefix : "", pid); |
| 561 | if (get_process_cmdlinecxx . . $ get_process_cmdline(f76e396f991ce395).(buf, cmdline_buffer)) { |
| 562 | cmd = oscap_buffer_get_rawcxx . . $ oscap_buffer_get_raw(3cd9678435dc2626).(cmdline_buffer); // use full cmdline |
| 563 | } else { |
| 564 | cmd = cmd_buffer + 1; |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | any_pid_dir_found = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 569 | cmd_sexp = SEXP_string_newfcxx . . $ SEXP_string_newf(b2137ed863725962).("%s", cmd); |
| 570 | pid_sexp = SEXP_number_newu_32cxx . . $ SEXP_number_newu_32(8a1232211d6fd92a).(pid); |
| 571 | if ((cmd_sexp == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || probe_entobj_cmpcxx . . $ probe_entobj_cmp(e245451a1311e799).(cmd_ent, cmd_sexp) == OVAL_RESULT_TRUEcxx . . $ OVAL_RESULT_TRUE.) && |
| 572 | (pid_sexp == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || probe_entobj_cmpcxx . . $ probe_entobj_cmp(e245451a1311e799).(pid_ent, pid_sexp) == OVAL_RESULT_TRUEcxx . . $ OVAL_RESULT_TRUE.) |
| 573 | ) { |
| 574 | struct result_infocxx . . $ result_info# r; |
| 575 | unsigned long t = uutime/tickscxx . . $ ticks. + ustime/tickscxx . . $ ticks.; |
| 576 | char tbuf[32], sbuf[32], *selinux_domain_label, **posix_capabilities; |
| 577 | int tday,tyear; |
| 578 | time_tcxx . . $ time_t# s_time; |
| 579 | struct tmcxx . . $ tm# *proc, *now; |
| 580 | const char *fmt; |
| 581 | |
| 582 | // Now get scheduler policy |
| 583 | sched_policy = sched_getschedulercxx . . $ sched_getscheduler(7864480464b09eea).(pid); |
| 584 | switch (sched_policy) { |
| 585 | case SCHED_OTHERcxx . . $ `<external>/4872883757279652994/sched.h:28:9`!: |
| 586 | r.scheduling_classcxx . . $ result_info#scheduling_class. = "TS"; |
| 587 | break; |
| 588 | case SCHED_BATCHcxx . . $ `<external>/4872883757279652994/sched.h:33:10`!: |
| 589 | r.scheduling_classcxx . . $ result_info#scheduling_class. = "B"; |
| 590 | break; |
| 591 | #ifdef SCHED_IDLEcxx . . $ `<external>/4872883757279652994/sched.h:35:10`! |
| 592 | case SCHED_IDLEcxx . . $ `<external>/4872883757279652994/sched.h:35:10`!: |
| 593 | r.scheduling_classcxx . . $ result_info#scheduling_class. = "#5"; |
| 594 | break; |
| 595 | #endif |
| 596 | case SCHED_FIFOcxx . . $ `<external>/4872883757279652994/sched.h:29:9`!: |
| 597 | r.scheduling_classcxx . . $ result_info#scheduling_class. = "FF"; |
| 598 | break; |
| 599 | case SCHED_RRcxx . . $ `<external>/4872883757279652994/sched.h:30:9`!: |
| 600 | r.scheduling_classcxx . . $ result_info#scheduling_class. = "RR"; |
| 601 | break; |
| 602 | default: |
| 603 | r.scheduling_classcxx . . $ result_info#scheduling_class. = "?"; |
| 604 | break; |
| 605 | } |
| 606 | |
| 607 | // Calculate the start time |
| 608 | s_time = timecxx . . $ time(7f38134db6521d23).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 609 | now = localtime_rcxx . . $ localtime_r(92e3d173686db852).(&s_time, &result); |
| 610 | tyear = now->tm_yearcxx . . $ tm#tm_year.; |
| 611 | tday = now->tm_ydaycxx . . $ tm#tm_yday.; |
| 612 | s_time = bootcxx . . $ boot. + (start / tickscxx . . $ ticks.); |
| 613 | proc = localtime_rcxx . . $ localtime_r(92e3d173686db852).(&s_time, &result); |
| 614 | |
| 615 | // Select format based on how long we've been running |
| 616 | // |
| 617 | // FROM THE SPEC: |
| 618 | // "This is the time of day the process started formatted in HH:MM:SS if |
| 619 | // the same day the process started or formatted as MMM_DD (Ex.: Feb_5) |
| 620 | // if process started the previous day or further in the past." |
| 621 | // |
| 622 | if (tday != proc->tm_ydaycxx . . $ tm#tm_yday. || tyear != proc->tm_yearcxx . . $ tm#tm_year.) |
| 623 | fmt = "%b_%d"; |
| 624 | else |
| 625 | fmt = "%H:%M:%S"; |
| 626 | strftimecxx . . $ strftime(98e75925167c4f1b).(sbuf, sizeof(sbuf), fmt, proc); |
| 627 | |
| 628 | r.command_linecxx . . $ result_info#command_line. = cmd; |
| 629 | r.exec_timecxx . . $ result_info#exec_time. = convert_timecxx . . $ convert_time(6012a4799d7b29fc).(t, tbuf, sizeof(tbuf)); |
| 630 | r.pidcxx . . $ result_info#pid. = pid; |
| 631 | r.ppidcxx . . $ result_info#ppid. = ppid; |
| 632 | r.prioritycxx . . $ result_info#priority. = priority; |
| 633 | r.start_timecxx . . $ result_info#start_time. = sbuf; |
| 634 | |
| 635 | dev_to_ttycxx . . $ dev_to_tty(9dbadb94bc6da39).(tty_dev, sizeof(tty_dev), (dev_tcxx . . $ dev_t#) tty_nr, pid, ABBREV_DEVcxx . . $ `compat/compat.h:63:9`!); |
| 636 | r.ttycxx . . $ result_info#tty. = tty_dev; |
| 637 | |
| 638 | r.exec_shieldcxx . . $ result_info#exec_shield. = (get_exec_shield_statuscxx . . $ get_exec_shield_status(7864480464b09eea).(pid) > 0); |
| 639 | |
| 640 | selinux_domain_label = get_selinux_labelcxx . . $ get_selinux_label(ff224f080444ee45).(pid); |
| 641 | r.selinux_domain_labelcxx . . $ result_info#selinux_domain_label. = selinux_domain_label; |
| 642 | |
| 643 | posix_capabilities = get_posix_capabilitycxx . . $ get_posix_capability(f769fdfdd161e4bf).(pid, max_cap_id); |
| 644 | r.posix_capabilitycxx . . $ result_info#posix_capability. = posix_capabilities; |
| 645 | |
| 646 | r.session_idcxx . . $ result_info#session_id. = session; |
| 647 | |
| 648 | get_uidscxx . . $ get_uids(60e87f32f3a14ea7).(pid, &r); |
| 649 | report_findingcxx . . $ report_finding(a44e8875aacc0cc1).(&r, ctx); |
| 650 | |
| 651 | if (selinux_domain_label != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 652 | freecxx . . $ free(5d22bdacc48458e8).(selinux_domain_label); |
| 653 | |
| 654 | if (posix_capabilities != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 655 | char **posix_capabilities_p = posix_capabilities; |
| 656 | while (*posix_capabilities_p) |
| 657 | freecxx . . $ free(5d22bdacc48458e8).(*posix_capabilities_p++); |
| 658 | freecxx . . $ free(5d22bdacc48458e8).(posix_capabilities); |
| 659 | } |
| 660 | } |
| 661 | SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(cmd_sexp); |
| 662 | SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(pid_sexp); |
| 663 | } |
| 664 | closedircxx . . $ closedir(ac30a447bc7c2f80).(d); |
| 665 | oscap_buffer_freecxx . . $ oscap_buffer_free(952d67516e6b9978).(cmdline_buffer); |
| 666 | |
| 667 | if (!any_pid_dir_found) { |
| 668 | dWcxx . . $ `src/common/debug_priv.h:62:9`!("No data about processes could be read from '%s'.", buf); |
| 669 | } |
| 670 | // In offline mode, empty /proc might be a normal situation and doesn't |
| 671 | // have to mean permissions problems |
| 672 | if (prefix) |
| 673 | return PROBE_ESUCCESScxx . . $ `src/OVAL/probes/public/probe-common.h:7:9`!; |
| 674 | else |
| 675 | return any_pid_dir_found ? PROBE_ESUCCESScxx . . $ `src/OVAL/probes/public/probe-common.h:7:9`! : PROBE_EACCESScxx . . $ `src/OVAL/probes/public/probe-api.h:431:9`!; |
| 676 | } |
| 677 | |
| 678 | int process58_probe_offline_mode_supportedcxx . . $ process58_probe_offline_mode_supported(b126dc7c1de90089).(void) |
| 679 | { |
| 680 | return PROBE_OFFLINE_OWNcxx . . $ PROBE_OFFLINE_OWN.; |
| 681 | } |
| 682 | |
| 683 | int process58_probe_maincxx . . $ process58_probe_main(470536d3ffacaf10).(probe_ctxcxx . . $ probe_ctx# *ctx, void *arg) |
| 684 | { |
| 685 | SEXP_tcxx . . $ SEXP_t# *command_line_ent, *pid_ent; |
| 686 | |
| 687 | command_line_ent = probe_obj_getentcxx . . $ probe_obj_getent(7907a01f2ff841f3).(probe_ctx_getobjectcxx . . $ probe_ctx_getobject(4299b6b53fa804a5).(ctx), "command_line", 1); |
| 688 | pid_ent = probe_obj_getentcxx . . $ probe_obj_getent(7907a01f2ff841f3).(probe_ctx_getobjectcxx . . $ probe_ctx_getobject(4299b6b53fa804a5).(ctx), "pid", 1); |
| 689 | if (command_line_ent == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && pid_ent == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 690 | return PROBE_ENOVALcxx . . $ `src/OVAL/probes/public/probe-api.h:423:9`!; |
| 691 | } |
| 692 | |
| 693 | int err = read_processcxx . . $ read_process(8cb7114d8bc47ec5).(command_line_ent, pid_ent, ctx); |
| 694 | if (err) { |
| 695 | SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(command_line_ent); |
| 696 | SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(pid_ent); |
| 697 | return err; |
| 698 | } |
| 699 | |
| 700 | SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(command_line_ent); |
| 701 | SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(pid_ent); |
| 702 | |
| 703 | return 0; |
| 704 | } |
| 705 | #elif defined (OS_SOLARIS) |
| 706 | |
| 707 | #include <procfs.h> |
| 708 | #include <unistd.h> |
| 709 | |
| 710 | static char *convert_time(time_t t, char *tbuf, int tb_size) |
| 711 | { |
| 712 | unsigned d,h,m,s; |
| 713 | |
| 714 | s = t%60; |
| 715 | t /= 60; |
| 716 | m = t%60; |
| 717 | t /=60; |
| 718 | h = t%24; |
| 719 | t /= 24; |
| 720 | d = t; |
| 721 | if (d) |
| 722 | snprintf(tbuf, tb_size, "%u-%02u:%02u:%02u", d, h, m, s); |
| 723 | else |
| 724 | snprintf(tbuf, tb_size, "%02u:%02u:%02u", h, m, s); |
| 725 | return tbuf; |
| 726 | } |
| 727 | |
| 728 | static int read_process(SEXP_t *cmd_ent, probe_ctx *ctx) |
| 729 | { |
| 730 | int err = 1; |
| 731 | DIR *d; |
| 732 | struct dirent *ent; |
| 733 | struct tm result; |
| 734 | |
| 735 | d = opendir("/proc"); |
| 736 | if (d == NULL) |
| 737 | return err; |
| 738 | |
| 739 | psinfo_t *psinfo; |
| 740 | |
| 741 | // Scan the directories |
| 742 | while (( ent = readdir(d) )) { |
| 743 | int fd, len; |
| 744 | char buf[336]; |
| 745 | int pid; |
| 746 | unsigned sched_policy; |
| 747 | SEXP_t *cmd_sexp; |
| 748 | |
| 749 | |
| 750 | // Skip non-process58 dir entries |
| 751 | if(*ent->d_name<'0' || *ent->d_name>'9') |
| 752 | continue; |
| 753 | errno = 0; |
| 754 | pid = strtol(ent->d_name, NULL, 10); |
| 755 | if (errno || pid == 2) // skip err & kthreads |
| 756 | continue; |
| 757 | |
| 758 | // Parse up the stat file for the proc |
| 759 | snprintf(buf, 32, "/proc/%d/psinfo", pid); |
| 760 | fd = open(buf, O_RDONLY, 0); |
| 761 | if (fd < 0) |
| 762 | continue; |
| 763 | len = read(fd, buf, sizeof buf); |
| 764 | close(fd); |
| 765 | if (len < 336) |
| 766 | continue; |
| 767 | |
| 768 | // The psinfo file contains a psinfo struct; this typecast gets us the struct directly |
| 769 | psinfo = (psinfo_t *) buf; |
| 770 | |
| 771 | |
| 772 | err = 0; // If we get this far, no permission problems |
| 773 | dI("Have command: %s", psinfo->pr_fname); |
| 774 | cmd_sexp = SEXP_string_newf("%s", psinfo->pr_fname); |
| 775 | if (probe_entobj_cmp(cmd_ent, cmd_sexp) == OVAL_RESULT_TRUE) { |
| 776 | struct result_info r; |
| 777 | char tbuf[32], sbuf[32]; |
| 778 | int tday,tyear; |
| 779 | time_t s_time; |
| 780 | struct tm *proc, *now; |
| 781 | const char *fmt; |
| 782 | int fixfmt_year; |
| 783 | |
| 784 | r.scheduling_class = malloc(PRCLSZ); |
| 785 | strncpy(r.scheduling_class, (psinfo->pr_lwp).pr_clname, sizeof(r.scheduling_class)); |
| 786 | |
| 787 | // Get the start time |
| 788 | s_time = time(NULL); |
| 789 | now = localtime_r(&s_time, &result); |
| 790 | tyear = now->tm_year; |
| 791 | tday = now->tm_yday; |
| 792 | |
| 793 | // Get current time |
| 794 | s_time = psinfo->pr_start.tv_sec; |
| 795 | proc = localtime_r(&s_time, &result); |
| 796 | |
| 797 | // Select format based on how long we've been running |
| 798 | // |
| 799 | // FROM THE SPEC: |
| 800 | // "This is the time of day the process started formatted in HH:MM:SS if |
| 801 | // the same day the process started or formatted as MMM_DD (Ex.: Feb_5) |
| 802 | // if process started the previous day or further in the past." |
| 803 | // |
| 804 | if (tday != proc->tm_yday || tyear != proc->tm_year) |
| 805 | fmt = "%b_%d"; |
| 806 | else |
| 807 | fmt = "%H:%M:%S"; |
| 808 | strftime(sbuf, sizeof(sbuf), fmt, proc); |
| 809 | |
| 810 | r.command_line = psinfo->pr_fname; |
| 811 | r.exec_time = convert_time(psinfo->pr_time.tv_sec, tbuf, sizeof(tbuf)); |
| 812 | r.pid = psinfo->pr_pid; |
| 813 | r.ppid = psinfo->pr_ppid; |
| 814 | r.priority = (psinfo->pr_lwp).pr_pri; |
| 815 | r.ruid = psinfo->pr_uid; |
| 816 | r.start_time = sbuf; |
| 817 | r.tty = oscap_sprintf("%s", psinfo->pr_ttydev); |
| 818 | r.user_id = psinfo->pr_euid; |
| 819 | report_finding(&r, ctx); |
| 820 | } |
| 821 | SEXP_free(cmd_sexp); |
| 822 | } |
| 823 | closedir(d); |
| 824 | |
| 825 | return err; |
| 826 | } |
| 827 | |
| 828 | int process58_probe_offline_mode_supported(void) |
| 829 | { |
| 830 | return PROBE_OFFLINE_NONE; |
| 831 | } |
| 832 | |
| 833 | int process58_probe_main(probe_ctx *ctx, void *arg) |
| 834 | { |
| 835 | SEXP_t *ent; |
| 836 | |
| 837 | ent = probe_obj_getent(probe_ctx_getobject(ctx), "command", 1); |
| 838 | if (ent == NULL) { |
| 839 | return PROBE_ENOVAL; |
| 840 | } |
| 841 | |
| 842 | if (read_process(ent, ctx)) { |
| 843 | SEXP_free(ent); |
| 844 | return PROBE_EACCESS; |
| 845 | } |
| 846 | |
| 847 | SEXP_free(ent); |
| 848 | |
| 849 | return 0; |
| 850 | } |
| 851 | |
| 852 | #else |
| 853 | int process58_probe_main(probe_ctx *ctx, void *arg) |
| 854 | { |
| 855 | SEXP_t *item_sexp; |
| 856 | |
| 857 | item_sexp = probe_item_create(OVAL_UNIX_PROCESS58, NULL, NULL); |
| 858 | probe_item_setstatus (item_sexp, SYSCHAR_STATUS_NOT_COLLECTED); |
| 859 | probe_item_collect(ctx, item_sexp); |
| 860 | |
| 861 | return 0; |
| 862 | } |
| 863 | #endif /* __linux */ |