| 1 | /** |
| 2 | * @file runlevel_probe.c |
| 3 | * @brief runlevel probe |
| 4 | * @author "Daniel Kopecek" <[email protected]> |
| 5 | * @author "Tomas Heinrich" <[email protected]> |
| 6 | * |
| 7 | * 2010/06/13 [email protected] |
| 8 | * This probe is able to process a runlevel_object as defined in OVAL 5.4 and 5.5. |
| 9 | * |
| 10 | */ |
| 11 | |
| 12 | /* |
| 13 | * Copyright 2009 Red Hat Inc., Durham, North Carolina. |
| 14 | * All Rights Reserved. |
| 15 | * |
| 16 | * This library is free software; you can redistribute it and/or |
| 17 | * modify it under the terms of the GNU Lesser General Public |
| 18 | * License as published by the Free Software Foundation; either |
| 19 | * version 2.1 of the License, or (at your option) any later version. |
| 20 | * |
| 21 | * This library is distributed in the hope that it will be useful, |
| 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 24 | * Lesser General Public License for more details. |
| 25 | * |
| 26 | * You should have received a copy of the GNU Lesser General Public |
| 27 | * License along with this library; if not, write to the Free Software |
| 28 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 29 | * |
| 30 | * Authors: |
| 31 | * "Daniel Kopecek" <[email protected]> |
| 32 | * "Tomas Heinrich" <[email protected]> |
| 33 | */ |
| 34 | |
| 35 | /* |
| 36 | * runlevel probe: |
| 37 | * |
| 38 | * runlevel_object(string service_name, |
| 39 | * string runlevel) |
| 40 | * |
| 41 | * runlevel_state(string service_name, |
| 42 | * string runlevel, |
| 43 | * bool start, |
| 44 | * bool kill) |
| 45 | */ |
| 46 | |
| 47 | #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`! |
| 48 | #include <config.h>cxx . . $ `<file>/build/config.h`/ |
| 49 | #endif |
| 50 | |
| 51 | #undef _BSD_SOURCE |
| 52 | #define _BSD_SOURCEcxx . . $ `src/OVAL/probes/unix/runlevel_probe.c:52:9`! |
| 53 | #undef _DEFAULT_SOURCEcxx . . $ `<external>/18206667465210621810/features.h:250:10`! |
| 54 | #define _DEFAULT_SOURCEcxx . . $ `src/OVAL/probes/unix/runlevel_probe.c:54:9`! |
| 55 | #include <stdio.h> |
| 56 | #include <stdbool.h> |
| 57 | #include <string.h> |
| 58 | #include <errno.h> |
| 59 | #include <assert.h> |
| 60 | #include <unistd.h> |
| 61 | #include <sys/types.h> |
| 62 | #include <sys/stat.h> |
| 63 | #include <dirent.h> |
| 64 | #include <limits.h> |
| 65 | |
| 66 | #include "_seap.h"cxx . . $ `<file>/src/OVAL/probes/SEAP/_seap.h`/ |
| 67 | #include <probe-api.h>cxx . . $ `<file>/src/OVAL/probes/public/probe-api.h`/ |
| 68 | #include <probe/probe.h>cxx . . $ `<file>/src/OVAL/probes/probe/probe.h`/ |
| 69 | #include <probe/entcmp.h>cxx . . $ `<file>/src/OVAL/probes/probe/entcmp.h`/ |
| 70 | #include <probe/option.h>cxx . . $ `<file>/src/OVAL/probes/probe/option.h`/ |
| 71 | #include "common/debug_priv.h"cxx . . $ `<file>/src/common/debug_priv.h`/ |
| 72 | #include "runlevel_probe.h"cxx . . $ `<file>/src/OVAL/probes/unix/runlevel_probe.h`/ |
| 73 | |
| 74 | #define RELEASENAME_MAX_SIZEcxx . . $ `src/OVAL/probes/unix/runlevel_probe.c:74:9`! 256 |
| 75 | #define RELEASENAME_PATTERNcxx . . $ `src/OVAL/probes/unix/runlevel_probe.c:75:9`! "CPE_NAME=\"%255s\"" |
| 76 | |
| 77 | struct runlevel_reqcxx . . $ runlevel_req# { |
| 78 | SEXP_tcxx . . $ SEXP_t# *service_name_entcxx . . $ runlevel_req#service_name_ent.; |
| 79 | SEXP_tcxx . . $ SEXP_t# *runlevel_entcxx . . $ runlevel_req#runlevel_ent.; |
| 80 | }; |
| 81 | |
| 82 | struct runlevel_repcxx . . $ runlevel_rep# { |
| 83 | char *service_namecxx . . $ runlevel_rep#service_name.; |
| 84 | char *runlevelcxx . . $ runlevel_rep#runlevel.; |
| 85 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! startcxx . . $ runlevel_rep#start.; |
| 86 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! killcxx . . $ runlevel_rep#kill.; |
| 87 | struct runlevel_repcxx . . $ runlevel_rep# *nextcxx . . $ runlevel_rep#next.; |
| 88 | }; |
| 89 | |
| 90 | static int get_runlevelcxx . . $ get_runlevel(d9fe5c65e6dc8195). (struct runlevel_reqcxx . . $ runlevel_req# *req, struct runlevel_repcxx . . $ runlevel_rep# **rep); |
| 91 | |
| 92 | #if defined(OS_LINUXcxx . . $ `compat/oscap_platforms.h:38:10`!) || defined(OS_SOLARIS) |
| 93 | static int get_runlevel_sysvcxx . . $ get_runlevel_sysv(1face2f70783bb3b). (struct runlevel_reqcxx . . $ runlevel_req# *req, struct runlevel_repcxx . . $ runlevel_rep# **rep, boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! suse, const char *init_path, const char *rc_path) |
| 94 | { |
| 95 | const char runlevel_list[] = {'0', '1', '2', '3', '4', '5', '6'}; |
| 96 | |
| 97 | char pathbuf[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 98 | DIRcxx . . $ DIR# *init_dir, *rc_dir, *orig_dir; |
| 99 | struct direntcxx . . $ dirent# *init_dp, *rc_dp; |
| 100 | struct statcxx . . $ stat# init_st, rc_st; |
| 101 | struct runlevel_repcxx . . $ runlevel_rep# *rep_lst = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 102 | |
| 103 | _Acxx . . $ `src/common/debug_priv.h:43:9`!(req != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 104 | _Acxx . . $ `src/common/debug_priv.h:43:9`!(rep != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 105 | |
| 106 | orig_dir = opendircxx . . $ opendir(f465d4b65cec8dd2).("."); |
| 107 | if (orig_dir == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 108 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("Can't open directory \".\": errno=%d, %s.", errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 109 | return -1; |
| 110 | } |
| 111 | init_dir = opendircxx . . $ opendir(f465d4b65cec8dd2).(init_path); |
| 112 | if (init_dir == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 113 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("Can't open directory \"%s\": errno=%d, %s.", |
| 114 | init_path, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, strerror (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 115 | closedircxx . . $ closedir(ac30a447bc7c2f80).(orig_dir); |
| 116 | return (-1); |
| 117 | } |
| 118 | |
| 119 | while ((init_dp = readdircxx . . $ readdir(ffbaae344e1a615a).(init_dir)) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 120 | char *service_name; |
| 121 | unsigned int i; |
| 122 | SEXP_tcxx . . $ SEXP_t# *r0; |
| 123 | |
| 124 | // Ensure that we are in the expected directory before |
| 125 | // touching relative paths |
| 126 | if (fchdircxx . . $ fchdir(7864480464b09eea).(dirfdcxx . . $ dirfd(ac30a447bc7c2f80).(init_dir)) != 0) { |
| 127 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("Can't fchdir to \"%s\": errno=%d, %s.", |
| 128 | init_path, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, strerror (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 129 | closedircxx . . $ closedir(ac30a447bc7c2f80).(init_dir); |
| 130 | closedircxx . . $ closedir(ac30a447bc7c2f80).(orig_dir); |
| 131 | return -1; |
| 132 | } |
| 133 | |
| 134 | if (statcxx . . $ stat(a9cd1e23e96f423c).(init_dp->d_namecxx . . $ dirent#d_name., &init_st) != 0) { |
| 135 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("Can't stat file %s/%s: errno=%d, %s.", |
| 136 | init_path, init_dp->d_name, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 137 | continue; |
| 138 | } |
| 139 | |
| 140 | r0 = SEXP_string_newfcxx . . $ SEXP_string_newf(b2137ed863725962).("%s", init_dp->d_namecxx . . $ dirent#d_name.); |
| 141 | if (probe_entobj_cmpcxx . . $ probe_entobj_cmp(e245451a1311e799).(req->service_name_entcxx . . $ runlevel_req#service_name_ent., r0) != OVAL_RESULT_TRUEcxx . . $ OVAL_RESULT_TRUE.) { |
| 142 | SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(r0); |
| 143 | continue; |
| 144 | } |
| 145 | SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(r0); |
| 146 | service_name = init_dp->d_namecxx . . $ dirent#d_name.; |
| 147 | |
| 148 | for (i = 0; i < (sizeof (runlevel_list) / sizeof (runlevel_list[0])); ++i) { |
| 149 | char runlevel[2] = {'\0', '\0'}; |
| 150 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! start, kill; |
| 151 | |
| 152 | r0 = SEXP_string_newfcxx . . $ SEXP_string_newf(b2137ed863725962).("%c", runlevel_list[i]); |
| 153 | if (probe_entobj_cmpcxx . . $ probe_entobj_cmp(e245451a1311e799).(req->runlevel_entcxx . . $ runlevel_req#runlevel_ent., r0) != OVAL_RESULT_TRUEcxx . . $ OVAL_RESULT_TRUE.) { |
| 154 | SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(r0); |
| 155 | continue; |
| 156 | } |
| 157 | SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(r0); |
| 158 | runlevel[0] = runlevel_list[i]; |
| 159 | |
| 160 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(pathbuf, sizeof (pathbuf), rc_path, runlevel_list[i]); |
| 161 | rc_dir = opendircxx . . $ opendir(f465d4b65cec8dd2).(pathbuf); |
| 162 | if (rc_dir == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 163 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("Can't open directory \"%s\": errno=%d, %s.", |
| 164 | rc_path, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, strerror (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 165 | continue; |
| 166 | } |
| 167 | if (chdircxx . . $ chdir(5c4306d8553b3696).(pathbuf) != 0) { |
| 168 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("Can't fchdir to \"%s\": errno=%d, %s.", |
| 169 | rc_path, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, strerror (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 170 | closedircxx . . $ closedir(ac30a447bc7c2f80).(rc_dir); |
| 171 | continue; |
| 172 | } |
| 173 | |
| 174 | // On SUSE, the presence of a symbolic link to the init.d/<service> in |
| 175 | // a runlevel directory rcx.d implies that the sevice is started on x. |
| 176 | |
| 177 | if (suse) { |
| 178 | start = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 179 | kill = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 180 | } |
| 181 | else |
| 182 | start = kill = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 183 | |
| 184 | while ((rc_dp = readdircxx . . $ readdir(ffbaae344e1a615a).(rc_dir)) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 185 | if (statcxx . . $ stat(a9cd1e23e96f423c).(rc_dp->d_namecxx . . $ dirent#d_name., &rc_st) != 0) { |
| 186 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("Can't stat file %s/%s: errno=%d, %s.", |
| 187 | rc_path, rc_dp->d_name, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 188 | continue; |
| 189 | } |
| 190 | |
| 191 | if (init_st.st_inocxx . . $ stat#st_ino. == rc_st.st_inocxx . . $ stat#st_ino.) { |
| 192 | |
| 193 | if (suse) { |
| 194 | if (rc_dp->d_namecxx . . $ dirent#d_name.[0] == 'S') { |
| 195 | |
| 196 | start = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 197 | kill = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 198 | |
| 199 | break; |
| 200 | } |
| 201 | } |
| 202 | else { |
| 203 | if (rc_dp->d_namecxx . . $ dirent#d_name.[0] == 'S') { |
| 204 | start = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 205 | break; |
| 206 | } else if (rc_dp->d_namecxx . . $ dirent#d_name.[0] == 'K') { |
| 207 | kill = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 208 | break; |
| 209 | } else { |
| 210 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("Unexpected character in filename: %c, %s/%s.", |
| 211 | rc_dp->d_name[0], pathbuf, rc_dp->d_name); |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | closedircxx . . $ closedir(ac30a447bc7c2f80).(rc_dir); |
| 217 | |
| 218 | if (rep_lst == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 219 | rep_lst = *rep = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof (struct runlevel_repcxx . . $ runlevel_rep#)); |
| 220 | } else { |
| 221 | rep_lst->nextcxx . . $ runlevel_rep#next. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof (struct runlevel_repcxx . . $ runlevel_rep#)); |
| 222 | rep_lst = rep_lst->nextcxx . . $ runlevel_rep#next.; |
| 223 | } |
| 224 | |
| 225 | rep_lst->service_namecxx . . $ runlevel_rep#service_name. = strdupcxx . . $ strdup(a8b8e32347182212).(service_name); |
| 226 | rep_lst->runlevelcxx . . $ runlevel_rep#runlevel. = strdupcxx . . $ strdup(a8b8e32347182212).(runlevel); |
| 227 | rep_lst->startcxx . . $ runlevel_rep#start. = start; |
| 228 | rep_lst->killcxx . . $ runlevel_rep#kill. = kill; |
| 229 | rep_lst->nextcxx . . $ runlevel_rep#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 230 | } |
| 231 | } |
| 232 | closedircxx . . $ closedir(ac30a447bc7c2f80).(init_dir); |
| 233 | |
| 234 | if (fchdircxx . . $ fchdir(7864480464b09eea).(dirfdcxx . . $ dirfd(ac30a447bc7c2f80).(orig_dir)) == -1) { |
| 235 | dEcxx . . $ `src/common/debug_priv.h:63:9`!("Can't fchdir back to original working directory: errno=%d, %s.", errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 236 | return -1; |
| 237 | } |
| 238 | closedircxx . . $ closedir(ac30a447bc7c2f80).(orig_dir); |
| 239 | |
| 240 | return (1); |
| 241 | } |
| 242 | |
| 243 | static int get_runlevel_redhatcxx . . $ get_runlevel_redhat(d9fe5c65e6dc8195). (struct runlevel_reqcxx . . $ runlevel_req# *req, struct runlevel_repcxx . . $ runlevel_rep# **rep) |
| 244 | { |
| 245 | #if defined(OS_LINUXcxx . . $ `compat/oscap_platforms.h:38:10`!) |
| 246 | const char *init_path = "/etc/rc.d/init.d"; |
| 247 | #elif defined(OS_SOLARIS) |
| 248 | const char *init_path = "/etc/init.d"; |
| 249 | #endif |
| 250 | const char *rc_path = "/etc/rc%c.d"; |
| 251 | |
| 252 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! suse = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 253 | return (get_runlevel_sysvcxx . . $ get_runlevel_sysv(1face2f70783bb3b). (req, rep, suse, init_path, rc_path)); |
| 254 | } |
| 255 | |
| 256 | static int get_runlevel_debiancxx . . $ get_runlevel_debian(d9fe5c65e6dc8195). (struct runlevel_reqcxx . . $ runlevel_req# *req, struct runlevel_repcxx . . $ runlevel_rep# **rep) |
| 257 | { |
| 258 | return (-1); |
| 259 | } |
| 260 | |
| 261 | static int get_runlevel_slackcxx . . $ get_runlevel_slack(d9fe5c65e6dc8195). (struct runlevel_reqcxx . . $ runlevel_req# *req, struct runlevel_repcxx . . $ runlevel_rep# **rep) |
| 262 | { |
| 263 | return (-1); |
| 264 | } |
| 265 | |
| 266 | static int get_runlevel_gentoocxx . . $ get_runlevel_gentoo(d9fe5c65e6dc8195). (struct runlevel_reqcxx . . $ runlevel_req# *req, struct runlevel_repcxx . . $ runlevel_rep# **rep) |
| 267 | { |
| 268 | return (-1); |
| 269 | } |
| 270 | |
| 271 | static int get_runlevel_archcxx . . $ get_runlevel_arch(d9fe5c65e6dc8195). (struct runlevel_reqcxx . . $ runlevel_req# *req, struct runlevel_repcxx . . $ runlevel_rep# **rep) |
| 272 | { |
| 273 | return (-1); |
| 274 | } |
| 275 | |
| 276 | static int get_runlevel_mandrivacxx . . $ get_runlevel_mandriva(d9fe5c65e6dc8195). (struct runlevel_reqcxx . . $ runlevel_req# *req, struct runlevel_repcxx . . $ runlevel_rep# **rep) |
| 277 | { |
| 278 | return (-1); |
| 279 | } |
| 280 | |
| 281 | static int get_runlevel_susecxx . . $ get_runlevel_suse(d9fe5c65e6dc8195). (struct runlevel_reqcxx . . $ runlevel_req# *req, struct runlevel_repcxx . . $ runlevel_rep# **rep) |
| 282 | { |
| 283 | const char *init_path = "/etc/init.d"; |
| 284 | const char *rc_path = "/etc/init.d/rc%c.d"; |
| 285 | |
| 286 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! suse = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 287 | return (get_runlevel_sysvcxx . . $ get_runlevel_sysv(1face2f70783bb3b). (req, rep, suse, init_path, rc_path)); |
| 288 | } |
| 289 | |
| 290 | static int get_runlevel_wrlinuxcxx . . $ get_runlevel_wrlinux(d9fe5c65e6dc8195). (struct runlevel_reqcxx . . $ runlevel_req# *req, struct runlevel_repcxx . . $ runlevel_rep# **rep) |
| 291 | { |
| 292 | return (-1); |
| 293 | } |
| 294 | |
| 295 | static int get_runlevel_commoncxx . . $ get_runlevel_common(d9fe5c65e6dc8195). (struct runlevel_reqcxx . . $ runlevel_req# *req, struct runlevel_repcxx . . $ runlevel_rep# **rep) |
| 296 | { |
| 297 | return (-1); |
| 298 | } |
| 299 | |
| 300 | #if !defined(LINUX_DISTRO) |
| 301 | # define LINUX_DISTROcxx . . $ `src/OVAL/probes/unix/runlevel_probe.c:301:10`! generic |
| 302 | |
| 303 | /** |
| 304 | * Parse /etc/os-release and return 1 if CPE_NAME inside starts with given |
| 305 | * value in "cpe". Otherwise returns 0. |
| 306 | * |
| 307 | * Examples (on Fedora 25): |
| 308 | * - parse_os_release("cpe:/o:fedoraproject:fedora:25") returns 1 |
| 309 | * - parse_os_release("cpe:/o:fedoraproject:fedora:24") returns 0 |
| 310 | * - parse_os_release("aasdfasdfasdf") returns 0 |
| 311 | * - parse_os_release("cpe") returns 1 (!!!) |
| 312 | * - parse_os_release("cpe:/o:fedoraproject:fedora:*") returns 0 (!!!) |
| 313 | */ |
| 314 | static int parse_os_releasecxx . . $ parse_os_release(5c4306d8553b3696).(const char *cpe) |
| 315 | { |
| 316 | FILEcxx . . $ FILE# *osrelease = fopencxx . . $ fopen(82ec0787cd37e0a3).("/etc/os-release", "r"); |
| 317 | if (osrelease == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 318 | // we cound't match the CPE because we couldn't open the file |
| 319 | return 0; |
| 320 | |
| 321 | char releasename[RELEASENAME_MAX_SIZEcxx . . $ `src/OVAL/probes/unix/runlevel_probe.c:74:9`!]; |
| 322 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(releasename, 0, RELEASENAME_MAX_SIZEcxx . . $ `src/OVAL/probes/unix/runlevel_probe.c:74:9`!); |
| 323 | |
| 324 | int got = -1; |
| 325 | int c; |
| 326 | do { |
| 327 | got = fscanfcxx . . $ fscanf(bc216f8e5b1ebeac).(osrelease, RELEASENAME_PATTERNcxx . . $ `src/OVAL/probes/unix/runlevel_probe.c:75:9`!, releasename); |
| 328 | c = fgetccxx . . $ fgetc(89bc1efcdac0ca22).(osrelease); |
| 329 | } while (got == 0 && c != EOFcxx . . $ `<external>/232824719582829767/stdio.h:105:9`!); |
| 330 | |
| 331 | int ret; |
| 332 | if (got < 0) { |
| 333 | ret = 0; // 0 means we couldn't find a match |
| 334 | goto done; |
| 335 | } |
| 336 | |
| 337 | ret = strncmpcxx . . $ strncmp(fd278af2f295fa2e).(releasename, cpe, strlencxx . . $ strlen(751346f8406fd082).(cpe)) == 0; |
| 338 | |
| 339 | done: |
| 340 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(osrelease); |
| 341 | return ret; |
| 342 | } |
| 343 | |
| 344 | static int is_redhatcxx . . $ is_redhat(b126dc7c1de90089). (void) |
| 345 | { |
| 346 | struct statcxx . . $ stat# st; |
| 347 | return (statcxx . . $ stat(a9cd1e23e96f423c). ("/etc/redhat-release", &st) == 0); |
| 348 | } |
| 349 | |
| 350 | static int is_debiancxx . . $ is_debian(b126dc7c1de90089). (void) |
| 351 | { |
| 352 | struct statcxx . . $ stat# st; |
| 353 | return (statcxx . . $ stat(a9cd1e23e96f423c). ("/etc/debian_version", &st) == 0 || |
| 354 | statcxx . . $ stat(a9cd1e23e96f423c). ("/etc/debian_release", &st) == 0); |
| 355 | } |
| 356 | |
| 357 | static int is_slackcxx . . $ is_slack(b126dc7c1de90089). (void) |
| 358 | { |
| 359 | struct statcxx . . $ stat# st; |
| 360 | return (statcxx . . $ stat(a9cd1e23e96f423c). ("/etc/slackware-release", &st) == 0); |
| 361 | } |
| 362 | |
| 363 | static int is_gentoocxx . . $ is_gentoo(b126dc7c1de90089). (void) |
| 364 | { |
| 365 | struct statcxx . . $ stat# st; |
| 366 | return (statcxx . . $ stat(a9cd1e23e96f423c). ("/etc/gentoo-release", &st) == 0); |
| 367 | } |
| 368 | |
| 369 | static int is_archcxx . . $ is_arch(b126dc7c1de90089). (void) |
| 370 | { |
| 371 | struct statcxx . . $ stat# st; |
| 372 | return (statcxx . . $ stat(a9cd1e23e96f423c). ("/etc/arch-release", &st) == 0); |
| 373 | } |
| 374 | |
| 375 | static int is_mandrivacxx . . $ is_mandriva(b126dc7c1de90089). (void) |
| 376 | { |
| 377 | struct statcxx . . $ stat# st; |
| 378 | return (statcxx . . $ stat(a9cd1e23e96f423c). ("/etc/mandriva-release", &st) == 0); |
| 379 | } |
| 380 | |
| 381 | static int is_susecxx . . $ is_suse(b126dc7c1de90089). (void) |
| 382 | { |
| 383 | struct statcxx . . $ stat# st; |
| 384 | return (statcxx . . $ stat(a9cd1e23e96f423c). ("/etc/SuSE-release", &st) == 0 || |
| 385 | statcxx . . $ stat(a9cd1e23e96f423c). ("/etc/sles-release", &st) == 0 || |
| 386 | statcxx . . $ stat(a9cd1e23e96f423c). ("/etc/novell-release", &st) == 0); |
| 387 | } |
| 388 | |
| 389 | static int is_solariscxx . . $ is_solaris(b126dc7c1de90089). (void) |
| 390 | { |
| 391 | struct statcxx . . $ stat# st; |
| 392 | return (statcxx . . $ stat(a9cd1e23e96f423c). ("/etc/release", &st) == 0); |
| 393 | } |
| 394 | |
| 395 | static int is_oraclecxx . . $ is_oracle(b126dc7c1de90089). (void) |
| 396 | { |
| 397 | struct statcxx . . $ stat# st; |
| 398 | return (statcxx . . $ stat(a9cd1e23e96f423c). ("/etc/oracle-release", &st) == 0); |
| 399 | } |
| 400 | |
| 401 | static int is_wrlinuxcxx . . $ is_wrlinux(b126dc7c1de90089).(void) |
| 402 | { |
| 403 | return parse_os_releasecxx . . $ parse_os_release(5c4306d8553b3696).("cpe:/o:windriver:wrlinux"); |
| 404 | } |
| 405 | |
| 406 | static int is_openembeddedcxx . . $ is_openembedded(b126dc7c1de90089).(void) |
| 407 | { |
| 408 | return parse_os_releasecxx . . $ parse_os_release(5c4306d8553b3696).("cpe:/o:openembedded:nodistro"); |
| 409 | } |
| 410 | |
| 411 | static int is_pokycxx . . $ is_poky(b126dc7c1de90089).(void) |
| 412 | { |
| 413 | return parse_os_releasecxx . . $ parse_os_release(5c4306d8553b3696).("cpe:/o:openembedded:poky"); |
| 414 | } |
| 415 | |
| 416 | static int is_commoncxx . . $ is_common(b126dc7c1de90089). (void) |
| 417 | { |
| 418 | return (1); |
| 419 | } |
| 420 | |
| 421 | typedef structcxx . . $ $anonymous_type_44647afaaf8b70d7_0# { |
| 422 | int (*distropcxx . . $ $anonymous_type_44647afaaf8b70d7_0#distrop.)(void); |
| 423 | int (*get_runlevelcxx . . $ $anonymous_type_44647afaaf8b70d7_0#get_runlevel.)(struct runlevel_reqcxx . . $ runlevel_req# *, struct runlevel_repcxx . . $ runlevel_rep# **); |
| 424 | } distro_tbl_tcxx . . $ distro_tbl_t#; |
| 425 | |
| 426 | const distro_tbl_tcxx . . $ distro_tbl_t# distro_tblcxx . . $ distro_tbl.[] = { |
| 427 | { &is_debiancxx . . $ is_debian(b126dc7c1de90089)., &get_runlevel_debiancxx . . $ get_runlevel_debian(d9fe5c65e6dc8195). }, |
| 428 | { &is_oraclecxx . . $ is_oracle(b126dc7c1de90089)., &get_runlevel_redhatcxx . . $ get_runlevel_redhat(d9fe5c65e6dc8195). }, |
| 429 | { &is_redhatcxx . . $ is_redhat(b126dc7c1de90089)., &get_runlevel_redhatcxx . . $ get_runlevel_redhat(d9fe5c65e6dc8195). }, |
| 430 | { &is_slackcxx . . $ is_slack(b126dc7c1de90089)., &get_runlevel_slackcxx . . $ get_runlevel_slack(d9fe5c65e6dc8195). }, |
| 431 | { &is_gentoocxx . . $ is_gentoo(b126dc7c1de90089)., &get_runlevel_gentoocxx . . $ get_runlevel_gentoo(d9fe5c65e6dc8195). }, |
| 432 | { &is_archcxx . . $ is_arch(b126dc7c1de90089)., &get_runlevel_archcxx . . $ get_runlevel_arch(d9fe5c65e6dc8195). }, |
| 433 | { &is_mandrivacxx . . $ is_mandriva(b126dc7c1de90089)., &get_runlevel_mandrivacxx . . $ get_runlevel_mandriva(d9fe5c65e6dc8195). }, |
| 434 | { &is_susecxx . . $ is_suse(b126dc7c1de90089)., &get_runlevel_susecxx . . $ get_runlevel_suse(d9fe5c65e6dc8195). }, |
| 435 | { &is_solariscxx . . $ is_solaris(b126dc7c1de90089)., &get_runlevel_redhatcxx . . $ get_runlevel_redhat(d9fe5c65e6dc8195). }, |
| 436 | { &is_wrlinuxcxx . . $ is_wrlinux(b126dc7c1de90089)., &get_runlevel_wrlinuxcxx . . $ get_runlevel_wrlinux(d9fe5c65e6dc8195). }, |
| 437 | { &is_commoncxx . . $ is_common(b126dc7c1de90089)., &get_runlevel_commoncxx . . $ get_runlevel_common(d9fe5c65e6dc8195). }, |
| 438 | { &is_openembeddedcxx . . $ is_openembedded(b126dc7c1de90089)., &get_runlevel_commoncxx . . $ get_runlevel_common(d9fe5c65e6dc8195). }, |
| 439 | { &is_pokycxx . . $ is_poky(b126dc7c1de90089)., &get_runlevel_commoncxx . . $ get_runlevel_common(d9fe5c65e6dc8195). } |
| 440 | }; |
| 441 | |
| 442 | #define DISTRO_TBL_SIZEcxx . . $ `src/OVAL/probes/unix/runlevel_probe.c:442:9`! ((sizeof distro_tbl)/sizeof (distro_tbl_t)) |
| 443 | |
| 444 | static int get_runlevel_genericcxx . . $ get_runlevel_generic(d9fe5c65e6dc8195). (struct runlevel_reqcxx . . $ runlevel_req# *req, struct runlevel_repcxx . . $ runlevel_rep# **rep) |
| 445 | { |
| 446 | uint16_tcxx . . $ uint16_t# i; |
| 447 | |
| 448 | _Acxx . . $ `src/common/debug_priv.h:43:9`!(req != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 449 | _Acxx . . $ `src/common/debug_priv.h:43:9`!(rep != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 450 | |
| 451 | for (i = 0; i < DISTRO_TBL_SIZEcxx . . $ `src/OVAL/probes/unix/runlevel_probe.c:442:9`!; ++i) |
| 452 | if (distro_tblcxx . . $ distro_tbl.[i].distropcxx . . $ $anonymous_type_44647afaaf8b70d7_0#distrop. ()) |
| 453 | return distro_tblcxx . . $ distro_tbl.[i].get_runlevelcxx . . $ $anonymous_type_44647afaaf8b70d7_0#get_runlevel. (req, rep); |
| 454 | |
| 455 | abortcxx . . $ abort(8df32a62017fbbf6). (); |
| 456 | |
| 457 | /* NOTREACHED */ |
| 458 | return (-1); |
| 459 | } |
| 460 | #endif |
| 461 | |
| 462 | #define CONCATcxx . . $ `src/OVAL/probes/unix/runlevel_probe.c:462:9`!(a, b) a ## b |
| 463 | #define GET_RUNLEVELcxx . . $ `src/OVAL/probes/unix/runlevel_probe.c:463:9`!(d, q, p) CONCATcxx . . $ `src/OVAL/probes/unix/runlevel_probe.c:462:9`!(get_runlevel_, d) (q, p) |
| 464 | |
| 465 | static int get_runlevelcxx . . $ get_runlevel(d9fe5c65e6dc8195). (struct runlevel_reqcxx . . $ runlevel_req# *req, struct runlevel_repcxx . . $ runlevel_rep# **rep) |
| 466 | { |
| 467 | _Acxx . . $ `src/common/debug_priv.h:43:9`!(req != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 468 | _Acxx . . $ `src/common/debug_priv.h:43:9`!(rep != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 469 | return GET_RUNLEVELcxx . . $ `src/OVAL/probes/unix/runlevel_probe.c:463:9`!(LINUX_DISTROcxx . . $ `src/OVAL/probes/unix/runlevel_probe.c:301:10`!, req, rep); |
| 470 | } |
| 471 | #elif defined(OS_FREEBSD) |
| 472 | static int get_runlevel (struct runlevel_req *req, struct runlevel_rep **rep) |
| 473 | { |
| 474 | _A(req != NULL); |
| 475 | _A(rep != NULL); |
| 476 | return (-1); |
| 477 | } |
| 478 | #else |
| 479 | # error "Sorry, your OS isn't supported." |
| 480 | #endif |
| 481 | |
| 482 | int runlevel_probe_offline_mode_supportedcxx . . $ runlevel_probe_offline_mode_supported(b126dc7c1de90089).() |
| 483 | { |
| 484 | return PROBE_OFFLINE_CHROOTcxx . . $ PROBE_OFFLINE_CHROOT.; |
| 485 | } |
| 486 | |
| 487 | int runlevel_probe_maincxx . . $ runlevel_probe_main(470536d3ffacaf10).(probe_ctxcxx . . $ probe_ctx# *ctx, void *arg) |
| 488 | { |
| 489 | SEXP_tcxx . . $ SEXP_t# *object; |
| 490 | struct runlevel_reqcxx . . $ runlevel_req# request_st; |
| 491 | struct runlevel_repcxx . . $ runlevel_rep# *reply_st = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 492 | |
| 493 | object = probe_ctx_getobjectcxx . . $ probe_ctx_getobject(4299b6b53fa804a5).(ctx); |
| 494 | |
| 495 | request_st.service_name_entcxx . . $ runlevel_req#service_name_ent. = probe_obj_getentcxx . . $ probe_obj_getent(7907a01f2ff841f3).(object, "service_name", 1); |
| 496 | if (request_st.service_name_entcxx . . $ runlevel_req#service_name_ent. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 497 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("%s: element not found", "service_name"); |
| 498 | |
| 499 | return PROBE_ENOELMcxx . . $ `src/OVAL/probes/public/probe-common.h:9:9`!; |
| 500 | } |
| 501 | |
| 502 | request_st.runlevel_entcxx . . $ runlevel_req#runlevel_ent. = probe_obj_getentcxx . . $ probe_obj_getent(7907a01f2ff841f3).(object, "runlevel", 1); |
| 503 | if (request_st.runlevel_entcxx . . $ runlevel_req#runlevel_ent. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 504 | SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(request_st.service_name_entcxx . . $ runlevel_req#service_name_ent.); |
| 505 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("%s: element not found", "runlevel"); |
| 506 | |
| 507 | return PROBE_ENOELMcxx . . $ `src/OVAL/probes/public/probe-common.h:9:9`!; |
| 508 | } |
| 509 | |
| 510 | if (get_runlevelcxx . . $ get_runlevel(d9fe5c65e6dc8195).(&request_st, &reply_st) == -1) { |
| 511 | SEXP_tcxx . . $ SEXP_t# *msg; |
| 512 | |
| 513 | msg = probe_msg_creatcxx . . $ probe_msg_creat(c07e3aa4e7ab9719).(OVAL_MESSAGE_LEVEL_ERRORcxx . . $ OVAL_MESSAGE_LEVEL_ERROR., "get_runlevel failed."); |
| 514 | probe_cobj_add_msgcxx . . $ probe_cobj_add_msg(ef7ee42b5817e0be).(probe_ctx_getresultcxx . . $ probe_ctx_getresult(4299b6b53fa804a5).(ctx), msg); |
| 515 | SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(msg); |
| 516 | probe_cobj_set_flagcxx . . $ probe_cobj_set_flag(644bab5dffe689c).(probe_ctx_getresultcxx . . $ probe_ctx_getresult(4299b6b53fa804a5).(ctx), SYSCHAR_FLAG_ERRORcxx . . $ SYSCHAR_FLAG_ERROR.); |
| 517 | } else { |
| 518 | struct runlevel_repcxx . . $ runlevel_rep# *next_rep; |
| 519 | SEXP_tcxx . . $ SEXP_t# *item; |
| 520 | |
| 521 | while (reply_st != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 522 | dDcxx . . $ `src/common/debug_priv.h:64:9`!("get_runlevel: [0]=\"%s\", [1]=\"%s\", [2]=\"%d\", [3]=\"%d\"", |
| 523 | reply_st->service_name, reply_st->runlevel, reply_st->start, reply_st->kill); |
| 524 | |
| 525 | item = probe_item_createcxx . . $ probe_item_create(36b16a6622050a9c).(OVAL_UNIX_RUNLEVELcxx . . $ OVAL_UNIX_RUNLEVEL., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, |
| 526 | "service_name", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., reply_st->service_namecxx . . $ runlevel_rep#service_name., |
| 527 | "runlevel", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., reply_st->runlevelcxx . . $ runlevel_rep#runlevel., |
| 528 | "start", OVAL_DATATYPE_BOOLEANcxx . . $ OVAL_DATATYPE_BOOLEAN., reply_st->startcxx . . $ runlevel_rep#start., |
| 529 | "kill", OVAL_DATATYPE_BOOLEANcxx . . $ OVAL_DATATYPE_BOOLEAN., reply_st->killcxx . . $ runlevel_rep#kill., |
| 530 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 531 | |
| 532 | probe_item_collectcxx . . $ probe_item_collect(11bb80e0c30650d7).(ctx, item); |
| 533 | |
| 534 | next_rep = reply_st->nextcxx . . $ runlevel_rep#next.; |
| 535 | freecxx . . $ free(5d22bdacc48458e8).(reply_st->service_namecxx . . $ runlevel_rep#service_name.); |
| 536 | freecxx . . $ free(5d22bdacc48458e8).(reply_st->runlevelcxx . . $ runlevel_rep#runlevel.); |
| 537 | freecxx . . $ free(5d22bdacc48458e8).(reply_st); |
| 538 | reply_st = next_rep; |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(request_st.runlevel_entcxx . . $ runlevel_req#runlevel_ent.); |
| 543 | SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(request_st.service_name_entcxx . . $ runlevel_req#service_name_ent.); |
| 544 | |
| 545 | return 0; |
| 546 | } |