Debian Codegraph @

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

raw symbols SCIP
1 /**
2 * @file rpmverifyfile_probe.c
3 * @brief rpmverifyfile probe
4 * @author "Daniel Kopecek" <[email protected]>
5 * @author "Petr Lautrbach" <[email protected]>
6 *
7 */
8
9 /*
10 * Copyright 2012 Red Hat Inc., Durham, North Carolina.
11 * All Rights Reserved.
12 *
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
17 *
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
22 *
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 *
27 * Authors:
28 * "Daniel Kopecek" <[email protected]>
29 * "Petr Lautrbach" <[email protected]>
30 */
31
32 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`!
33 #include <config.h>cxx . . $ `<file>/build/config.h`/
34 #endif
35
36 #include <stdio.h>
37 #include <string.h>
38 #include <errno.h>
39 #include <assert.h>
40 #include <limits.h>
41 #include <sys/types.h>
42 #include <sys/stat.h>
43 #include <fcntl.h>
44
45 #include "rpm-helper.h"cxx . . $ `<file>/src/OVAL/probes/unix/linux/rpm-helper.h`/
46 #include "oscap_helpers.h"cxx . . $ `<file>/src/common/public/oscap_helpers.h`/
47
48 /* Individual RPM headers */
49 #include <rpm/rpmfi.h>
50 #include <rpm/rpmcli.h>
51
52 /* SEAP */
53 #include <probe-api.h>cxx . . $ `<file>/src/OVAL/probes/public/probe-api.h`/
54 #include "debug_priv.h"cxx . . $ `<file>/src/common/debug_priv.h`/
55 #include "probe/entcmp.h"cxx . . $ `<file>/src/OVAL/probes/probe/entcmp.h`/
56
57 #include <probe/probe.h>cxx . . $ `<file>/src/OVAL/probes/probe/probe.h`/
58 #include <probe/option.h>cxx . . $ `<file>/src/OVAL/probes/probe/option.h`/
59 #include "common/oscap_pcre.h"cxx . . $ `<file>/src/common/oscap_pcre.h`/
60
61 #include "rpmverifyfile_probe.h"cxx . . $ `<file>/src/OVAL/probes/unix/linux/rpmverifyfile_probe.h`/
62
63 struct rpmverify_rescxx . . $ rpmverify_res# {
64 char *namecxx . . $ rpmverify_res#name.; /**< package name */
65 char *epochcxx . . $ rpmverify_res#epoch.;
66 char *versioncxx . . $ rpmverify_res#version.;
67 char *releasecxx . . $ rpmverify_res#release.;
68 char *archcxx . . $ rpmverify_res#arch.;
69 char *filecxx . . $ rpmverify_res#file.; /**< filepath */
70 char extended_namecxx . . $ rpmverify_res#extended_name.[1024];
71 rpmVerifyAttrscxx . . $ rpmVerifyAttrs# vflagscxx . . $ rpmverify_res#vflags.; /**< rpm verify flags */
72 rpmVerifyAttrscxx . . $ rpmVerifyAttrs# oflagscxx . . $ rpmverify_res#oflags.; /**< rpm verify omit flags */
73 rpmfileAttrscxx . . $ rpmfileAttrs# fflagscxx . . $ rpmverify_res#fflags.; /**< rpm file flags */
74 };
75
76 #define RPMVERIFY_SKIP_CONFIGcxx . . $ `src/OVAL/probes/unix/linux/rpmverifyfile_probe.c:76:9`! 0x1000000000000000
77 #define RPMVERIFY_SKIP_GHOSTcxx . . $ `src/OVAL/probes/unix/linux/rpmverifyfile_probe.c:77:9`! 0x2000000000000000
78 #define RPMVERIFY_RPMATTRMASKcxx . . $ `src/OVAL/probes/unix/linux/rpmverifyfile_probe.c:78:9`! 0x00000000ffffffff
79
80 /* In rmplib older than 4.7 some of the enum values aren't defined.
81 * We need to provide fallback definitions.
82 */
83 #ifndef RPM47_FOUNDcxx . . $ `build/config.h:47:9`!
84 /* *VERIFY_FILEDIGEST were introduced as aliases to *VERIFY_MD5
85 * They all have the same value (1) - see 'rpm/rpmvf.h'.
86 */
87 #define RPMVERIFY_FILEDIGEST RPMVERIFY_MD5
88 /* RPMVERIFY_CAPS is not supported in older rpmlib.
89 * We can set it to 0 because 0 is neutral to bit OR operation.
90 */
91 #define RPMVERIFY_CAPS 0
92 #endif
93
94 #define RPMVERIFY_LOCKcxx . . $ `src/OVAL/probes/unix/linux/rpmverifyfile_probe.c:94:9`! RPM_MUTEX_LOCKcxx . . $ `src/OVAL/probes/unix/linux/rpm-helper.h:59:9`!(&g_rpm->mutex)
95
96 #define RPMVERIFY_UNLOCKcxx . . $ `src/OVAL/probes/unix/linux/rpmverifyfile_probe.c:96:9`! RPM_MUTEX_UNLOCKcxx . . $ `src/OVAL/probes/unix/linux/rpm-helper.h:69:9`!(&g_rpm->mutex)
97
98 static int rpmverify_additemcxx . . $ rpmverify_additem(e8a8575ef97ee980).(probe_ctxcxx . . $ probe_ctx# *ctx, struct rpmverify_rescxx . . $ rpmverify_res# *res);
99
100 /* modify passed-in iterator to test also given entity */
101 static int adjust_filtercxx . . $ adjust_filter(d18df26666f416ae).(rpmdbMatchIteratorcxx . . $ rpmdbMatchIterator# iterator, SEXP_tcxx . . $ SEXP_t# *ent, rpmTagcxx . . $ rpmTag# rpm_tag) {
102 oval_operation_tcxx . . $ oval_operation_t# ent_op;
103 char ent_str[1024];
104 int ret = 0;
105
106 if (ent) {
107 ent_op = probe_ent_getoperationcxx . . $ probe_ent_getoperation(8f085ec993ec77d).(ent, OVAL_OPERATION_EQUALScxx . . $ OVAL_OPERATION_EQUALS.);
108 PROBE_ENT_STRVALcxx . . $ `src/OVAL/probes/public/probe-api.h:487:9`!(ent, ent_str, sizeof ent_str, /* void */, strcpy(ent_str, ""););
109
110 switch (ent_op) {
111 case OVAL_OPERATION_EQUALScxx . . $ OVAL_OPERATION_EQUALS.:
112 if (rpmdbSetIteratorREcxx . . $ rpmdbSetIteratorRE(24a7459ecac1f13c). (iterator, rpm_tag, RPMMIRE_STRCMPcxx . . $ RPMMIRE_STRCMP., ent_str) != 0)
113 ret = -1;
114
115 break;
116 case OVAL_OPERATION_PATTERN_MATCHcxx . . $ OVAL_OPERATION_PATTERN_MATCH.:
117 if (rpmdbSetIteratorREcxx . . $ rpmdbSetIteratorRE(24a7459ecac1f13c). (iterator, rpm_tag, RPMMIRE_REGEXcxx . . $ RPMMIRE_REGEX.,
118 (const char *)ent_str) != 0)
119 ret = -1;
120
121 break;
122 default:
123 ret = 0;
124 }
125 }
126 return ret;
127 }
128
129 /*
130 * Compare file with item iterated over.
131 * Returns 0 when they match, 1 when don't match, -1 on error.
132 * Returns the matched file path in result_file.
133 */
134 static int _compare_file_with_current_filecxx . . $ _compare_file_with_current_file(f5f9f43371b457dc).(oval_operation_tcxx . . $ oval_operation_t# file_op, const char *file, const char *current_file, char **result_file)
135 {
136 int ret = 0;
137
138 char *file_realpath = oscap_realpathcxx . . $ oscap_realpath(ed8193f262e4eda).(file, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
139 char *current_file_realpath = oscap_realpathcxx . . $ oscap_realpath(ed8193f262e4eda).(current_file, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
140
141 if (file_op == OVAL_OPERATION_EQUALScxx . . $ OVAL_OPERATION_EQUALS.) {
142 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(current_file, file) != 0 &&
143 current_file_realpath && file_realpath &&
144 strcmpcxx . . $ strcmp(5ae29d726ae57f88).(current_file_realpath, file_realpath) != 0) {
145 ret = 1;
146 goto cleanup;
147 }
148 *result_file = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(file);
149 } else if (file_op == OVAL_OPERATION_NOT_EQUALcxx . . $ OVAL_OPERATION_NOT_EQUAL.) {
150 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(current_file, file) == 0 ||
151 (current_file_realpath && file_realpath &&
152 strcmpcxx . . $ strcmp(5ae29d726ae57f88).(current_file_realpath, file_realpath) == 0)) {
153 ret = 1;
154 goto cleanup;
155 }
156 *result_file = current_file_realpath ? oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(current_file_realpath) : oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(current_file);
157 } else if (file_op == OVAL_OPERATION_PATTERN_MATCHcxx . . $ OVAL_OPERATION_PATTERN_MATCH.) {
158 char *errmsg;
159 int erroff;
160 oscap_pcre_tcxx . . $ oscap_pcre_t# *re = oscap_pcre_compilecxx . . $ oscap_pcre_compile(29ca11f2d36a957a).(file, OSCAP_PCRE_OPTS_UTF8cxx . . $ OSCAP_PCRE_OPTS_UTF8., &errmsg, &erroff);
161 if (re == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
162 dEcxx . . $ `src/common/debug_priv.h:63:9`!("oscap_pcre_compile pattern='%s': %s", file, errmsg);
163 ret = -1;
164 oscap_pcre_err_freecxx . . $ oscap_pcre_err_free(fda57c8427c60377).(errmsg);
165 goto cleanup;
166 }
167 int pcre_ret = oscap_pcre_execcxx . . $ oscap_pcre_exec(7630dfd25fd504ec).(re, current_file, strlencxx . . $ strlen(751346f8406fd082).(current_file), 0, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0);
168 oscap_pcre_freecxx . . $ oscap_pcre_free(804bb72472b0846e).(re);
169 if (pcre_ret > OSCAP_PCRE_ERR_NOMATCHcxx . . $ OSCAP_PCRE_ERR_NOMATCH.) {
170 /* match */
171 *result_file = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(current_file);
172 } else if (pcre_ret == OSCAP_PCRE_ERR_NOMATCHcxx . . $ OSCAP_PCRE_ERR_NOMATCH.) {
173 /* no match */
174 ret = 1;
175 goto cleanup;
176 } else {
177 dEcxx . . $ `src/common/debug_priv.h:63:9`!("oscap_pcre_exec() failed!");
178 ret = -1;
179 goto cleanup;
180 }
181 } else {
182 /* unsupported operation */
183 dEcxx . . $ `src/common/debug_priv.h:63:9`!("Operation \"%d\" on `filepath' not supported", file_op);
184 ret = -1;
185 goto cleanup;
186 }
187
188 cleanup:
189 freecxx . . $ free(5d22bdacc48458e8).(file_realpath);
190 freecxx . . $ free(5d22bdacc48458e8).(current_file_realpath);
191
192 return ret;
193 }
194
195 static int rpmverify_collect_package_files_or_directoriescxx . . $ rpmverify_collect_package_files_or_directories(18ff063f1103f22e).(
196 struct rpm_probe_globalcxx . . $ rpm_probe_global# *g_rpm, probe_ctxcxx . . $ probe_ctx# *ctx, Headercxx . . $ Header# pkgh,
197 const char *file, oval_operation_tcxx . . $ oval_operation_t# file_op, rpmTagcxx . . $ rpmTag# tag,
198 struct rpmverify_rescxx . . $ rpmverify_res# *res, uint64_tcxx . . $ uint64_t# flags)
199 {
200 int ret = 0;
201 rpmVerifyAttrscxx . . $ rpmVerifyAttrs# omit = (rpmVerifyAttrscxx . . $ rpmVerifyAttrs#)(flags & RPMVERIFY_RPMATTRMASKcxx . . $ `src/OVAL/probes/unix/linux/rpmverifyfile_probe.c:78:9`!);
202 rpmficxx . . $ rpmfi# fi = rpmfiNewcxx . . $ rpmfiNew(765de6e9cbcb5527).(g_rpm->rpmtscxx . . $ rpm_probe_global#rpmts., pkgh, tag, 1);
203
204 while (rpmfiNextcxx . . $ rpmfiNext(b7df0ed902649c2e).(fi) != -1) {
205 const char *current_file = rpmfiFNcxx . . $ rpmfiFN(24fadc50c126301f).(fi);
206 res->fflagscxx . . $ rpmverify_res#fflags. = rpmfiFFlagscxx . . $ rpmfiFFlags(c56bffef931de6c8).(fi);
207 res->oflagscxx . . $ rpmverify_res#oflags. = omit;
208
209 if (((res->fflagscxx . . $ rpmverify_res#fflags. & RPMFILE_CONFIGcxx . . $ RPMFILE_CONFIG.) && (flags & RPMVERIFY_SKIP_CONFIGcxx . . $ `src/OVAL/probes/unix/linux/rpmverifyfile_probe.c:76:9`!)) ||
210 ((res->fflagscxx . . $ rpmverify_res#fflags. & RPMFILE_GHOSTcxx . . $ RPMFILE_GHOST.) && (flags & RPMVERIFY_SKIP_GHOSTcxx . . $ `src/OVAL/probes/unix/linux/rpmverifyfile_probe.c:77:9`!))) {
211 continue;
212 }
213 int cmp_res = _compare_file_with_current_filecxx . . $ _compare_file_with_current_file(f5f9f43371b457dc).(file_op, file, current_file, &res->filecxx . . $ rpmverify_res#file.);
214 if (cmp_res == 1) {
215 /* no match */
216 continue;
217 }
218 if (cmp_res == -1) {
219 ret = -1;
220 goto cleanup;
221 }
222
223 if (rpmVerifyFilecxx . . $ rpmVerifyFile(3d59f9e68d5ecc36).(g_rpm->rpmtscxx . . $ rpm_probe_global#rpmts., fi, &res->vflagscxx . . $ rpmverify_res#vflags., omit) != 0) {
224 res->vflagscxx . . $ rpmverify_res#vflags. = RPMVERIFY_FAILUREScxx . . $ `<external>/1632812796624396431/rpmfiles.h:97:9`!;
225 }
226
227 if (rpmverify_additemcxx . . $ rpmverify_additem(e8a8575ef97ee980).(ctx, res) != 0) {
228 ret = -1;
229 freecxx . . $ free(5d22bdacc48458e8).(res->filecxx . . $ rpmverify_res#file.);
230 goto cleanup;
231 }
232 freecxx . . $ free(5d22bdacc48458e8).(res->filecxx . . $ rpmverify_res#file.);
233 }
234
235 cleanup:
236 rpmfiFreecxx . . $ rpmfiFree(cff0d0dd50e20ae4).(fi);
237 return ret;
238 }
239
240 static int rpmverify_collectcxx . . $ rpmverify_collect(1bf70a275fddce7e).(probe_ctxcxx . . $ probe_ctx# *ctx,
241 const char *file, oval_operation_tcxx . . $ oval_operation_t# file_op,
242 SEXP_tcxx . . $ SEXP_t# *name_ent, SEXP_tcxx . . $ SEXP_t# *epoch_ent, SEXP_tcxx . . $ SEXP_t# *version_ent, SEXP_tcxx . . $ SEXP_t# *release_ent, SEXP_tcxx . . $ SEXP_t# *arch_ent,
243 uint64_tcxx . . $ uint64_t# flags,
244 struct rpm_probe_globalcxx . . $ rpm_probe_global# *g_rpm)
245 {
246 rpmdbMatchIteratorcxx . . $ rpmdbMatchIterator# match;
247 Headercxx . . $ Header# pkgh;
248 int ret = -1;
249
250 RPMVERIFY_LOCKcxx . . $ `src/OVAL/probes/unix/linux/rpmverifyfile_probe.c:94:9`!;
251
252 if (file != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && file_op == OVAL_OPERATION_EQUALScxx . . $ OVAL_OPERATION_EQUALS.) {
253 /*
254 * When we know the exact file path we look for, we don't need to
255 * filter all RPM packages, but we can ask the rpmdb directly for
256 * the package which provides this file, similar to `rpm -q -f`.
257 */
258 match = rpmtsInitIteratorcxx . . $ rpmtsInitIterator(41c3f6b2f2ef385d).(g_rpm->rpmtscxx . . $ rpm_probe_global#rpmts., RPMDBI_INSTFILENAMEScxx . . $ RPMDBI_INSTFILENAMES., file, 0);
259 } else {
260 match = rpmtsInitIteratorcxx . . $ rpmtsInitIterator(41c3f6b2f2ef385d).(g_rpm->rpmtscxx . . $ rpm_probe_global#rpmts., RPMDBI_PACKAGEScxx . . $ RPMDBI_PACKAGES., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0);
261 }
262 if (match == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
263 ret = 0;
264 goto ret;
265 }
266
267 if ((ret = adjust_filtercxx . . $ adjust_filter(d18df26666f416ae).(match, name_ent, RPMTAG_NAMEcxx . . $ RPMTAG_NAME.)) == -1) {
268 dEcxx . . $ `src/common/debug_priv.h:63:9`!("can't adjust filter with name");
269 goto ret;
270 }
271 if ((ret = adjust_filtercxx . . $ adjust_filter(d18df26666f416ae).(match, epoch_ent, RPMTAG_EPOCHcxx . . $ RPMTAG_EPOCH.)) == -1) {
272 dEcxx . . $ `src/common/debug_priv.h:63:9`!("can't adjust filter with epoch");
273 goto ret;
274 }
275 if ((ret = adjust_filtercxx . . $ adjust_filter(d18df26666f416ae).(match, version_ent, RPMTAG_VERSIONcxx . . $ RPMTAG_VERSION.)) == -1) {
276 dEcxx . . $ `src/common/debug_priv.h:63:9`!("can't adjust filter with version");
277 goto ret;
278 }
279 if ((ret = adjust_filtercxx . . $ adjust_filter(d18df26666f416ae).(match, release_ent, RPMTAG_RELEASEcxx . . $ RPMTAG_RELEASE.)) == -1) {
280 dEcxx . . $ `src/common/debug_priv.h:63:9`!("can't adjust filter with version");
281 goto ret;
282 }
283 if ((ret = adjust_filtercxx . . $ adjust_filter(d18df26666f416ae).(match, arch_ent, RPMTAG_ARCHcxx . . $ RPMTAG_ARCH.)) == -1) {
284 dEcxx . . $ `src/common/debug_priv.h:63:9`!("can't adjust filter with version");
285 goto ret;
286 }
287
288 while ((pkgh = rpmdbNextIteratorcxx . . $ rpmdbNextIterator(12a0bfe3c2421784). (match)) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
289 SEXP_tcxx . . $ SEXP_t# *ent;
290 struct rpmverify_rescxx . . $ rpmverify_res# res;
291 errmsg_tcxx . . $ errmsg_t# rpmerr;
292
293 #define COMPARE_ENTcxx . . $ `src/OVAL/probes/unix/linux/rpmverifyfile_probe.c:293:9`!(XXX) \
294 if (XXX ## _ent != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { \
295 ent = probe_entval_from_cstr( \
296 probe_ent_getdatatype(XXX ## _ent), res.XXX, strlen(res.XXX) \
297 ); \
298 if (ent != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && probe_entobj_cmp(XXX ## _ent, ent) != OVAL_RESULT_TRUE) { \
299 SEXP_free(ent); \
300 continue; \
301 } \
302 SEXP_free(ent); \
303 }
304
305 res.namecxx . . $ rpmverify_res#name. = headerFormatcxx . . $ headerFormat(ff7bd715129ef29).(pkgh, "%{NAME}", &rpmerr);
306 COMPARE_ENTcxx . . $ `src/OVAL/probes/unix/linux/rpmverifyfile_probe.c:293:9`!(name);
307
308 res.epochcxx . . $ rpmverify_res#epoch. = headerFormatcxx . . $ headerFormat(ff7bd715129ef29).(pkgh, "%{EPOCH}", &rpmerr);
309 COMPARE_ENTcxx . . $ `src/OVAL/probes/unix/linux/rpmverifyfile_probe.c:293:9`!(epoch);
310
311 res.versioncxx . . $ rpmverify_res#version. = headerFormatcxx . . $ headerFormat(ff7bd715129ef29).(pkgh, "%{VERSION}", &rpmerr);
312 COMPARE_ENTcxx . . $ `src/OVAL/probes/unix/linux/rpmverifyfile_probe.c:293:9`!(version);
313 res.releasecxx . . $ rpmverify_res#release. = headerFormatcxx . . $ headerFormat(ff7bd715129ef29).(pkgh, "%{RELEASE}", &rpmerr);
314 COMPARE_ENTcxx . . $ `src/OVAL/probes/unix/linux/rpmverifyfile_probe.c:293:9`!(release);
315 res.archcxx . . $ rpmverify_res#arch. = headerFormatcxx . . $ headerFormat(ff7bd715129ef29).(pkgh, "%{ARCH}", &rpmerr);
316 COMPARE_ENTcxx . . $ `src/OVAL/probes/unix/linux/rpmverifyfile_probe.c:293:9`!(arch);
317 snprintfcxx . . $ snprintf(ea502d73e74c754c).(res.extended_namecxx . . $ rpmverify_res#extended_name., 1024, "%s-%s:%s-%s.%s", res.namecxx . . $ rpmverify_res#name.,
318 oscap_streqcxx . . $ oscap_streq(b7a7aa4a824b7595).(res.epochcxx . . $ rpmverify_res#epoch., "(none)") ? "0" : res.epochcxx . . $ rpmverify_res#epoch.,
319 res.versioncxx . . $ rpmverify_res#version., res.releasecxx . . $ rpmverify_res#release., res.archcxx . . $ rpmverify_res#arch.);
320
321 if (rpmverify_collect_package_files_or_directoriescxx . . $ rpmverify_collect_package_files_or_directories(18ff063f1103f22e).(g_rpm, ctx, pkgh, file, file_op, RPMTAG_BASENAMEScxx . . $ RPMTAG_BASENAMES., &res, flags) != 0 ||
322 rpmverify_collect_package_files_or_directoriescxx . . $ rpmverify_collect_package_files_or_directories(18ff063f1103f22e).(g_rpm, ctx, pkgh, file, file_op, RPMTAG_DIRNAMEScxx . . $ RPMTAG_DIRNAMES., &res, flags) != 0) {
323 ret = -1;
324 }
325
326 freecxx . . $ free(5d22bdacc48458e8).(res.namecxx . . $ rpmverify_res#name.);
327 freecxx . . $ free(5d22bdacc48458e8).(res.epochcxx . . $ rpmverify_res#epoch.);
328 freecxx . . $ free(5d22bdacc48458e8).(res.versioncxx . . $ rpmverify_res#version.);
329 freecxx . . $ free(5d22bdacc48458e8).(res.releasecxx . . $ rpmverify_res#release.);
330 freecxx . . $ free(5d22bdacc48458e8).(res.archcxx . . $ rpmverify_res#arch.);
331 if (ret == -1) {
332 goto ret;
333 }
334 }
335
336 ret = 0;
337 ret:
338 match = rpmdbFreeIteratorcxx . . $ rpmdbFreeIterator(8defa6d083da6e8).(match);
339 RPMVERIFY_UNLOCKcxx . . $ `src/OVAL/probes/unix/linux/rpmverifyfile_probe.c:96:9`!;
340 return (ret);
341 }
342
343 int rpmverifyfile_probe_offline_mode_supportedcxx . . $ rpmverifyfile_probe_offline_mode_supported(b126dc7c1de90089).()
344 {
345 // TODO: Switch this to OFFLINE_MODE_OWN once rpmtsSetRootDir is fully supported by librpm
346 return PROBE_OFFLINE_CHROOTcxx . . $ PROBE_OFFLINE_CHROOT.;
347 }
348
349 void *rpmverifyfile_probe_initcxx . . $ rpmverifyfile_probe_init(50c7df7de5344ebb).(void)
350 {
351 #ifdef RPM46_FOUNDcxx . . $ `build/config.h:46:9`!
352 rpmlogSetCallbackcxx . . $ rpmlogSetCallback(3af8381b9d28b514).(rpmErrorCbcxx . . $ rpmErrorCb(fff58a40e215938)., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
353 #endif
354 if (rpmReadConfigFilescxx . . $ rpmReadConfigFiles(5ae29d726ae57f88). ((const char *)NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, (const char *)NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) != 0) {
355 dDcxx . . $ `src/common/debug_priv.h:64:9`!("rpmReadConfigFiles failed: %u, %s.", errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, strerror (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
356 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
357 }
358
359 struct rpm_probe_globalcxx . . $ rpm_probe_global# *g_rpm = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(struct rpm_probe_globalcxx . . $ rpm_probe_global#));
360
361 set_rpm_db_pathcxx . . $ set_rpm_db_path(49f6e7a06ebc5aa8).();
362
363 g_rpm->rpmtscxx . . $ rpm_probe_global#rpmts. = rpmtsCreatecxx . . $ rpmtsCreate(17624c196b75261f).();
364
365 pthread_mutex_initcxx . . $ pthread_mutex_init(db9d29dab44ea1aa).(&(g_rpm->mutexcxx . . $ rpm_probe_global#mutex.), NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
366
367 return ((void *)g_rpm);
368 }
369
370 void rpmverifyfile_probe_finicxx . . $ rpmverifyfile_probe_fini(5d22bdacc48458e8).(void *ptr)
371 {
372 struct rpm_probe_globalcxx . . $ rpm_probe_global# *r = (struct rpm_probe_globalcxx . . $ rpm_probe_global# *)ptr;
373
374 rpmFreeCryptocxx . . $ rpmFreeCrypto(b126dc7c1de90089).();
375 rpmFreeRpmrccxx . . $ rpmFreeRpmrc(49f6e7a06ebc5aa8).();
376 rpmFreeMacroscxx . . $ rpmFreeMacros(9f41120681ff0556).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
377 rpmlogClosecxx . . $ rpmlogClose(49f6e7a06ebc5aa8).();
378
379 // If probe_init() failed r->rpmts and r->mutex were not initialized
380 if (r == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
381 return;
382
383 rpmtsFreecxx . . $ rpmtsFree(39c31376fa367c52).(r->rpmtscxx . . $ rpm_probe_global#rpmts.);
384 pthread_mutex_destroycxx . . $ pthread_mutex_destroy(d89ae235521888f9). (&(r->mutexcxx . . $ rpm_probe_global#mutex.));
385 freecxx . . $ free(5d22bdacc48458e8).(r);
386
387 return;
388 }
389
390 static void _add_ent_from_cstrcxx . . $ _add_ent_from_cstr(56f1cf1671c930dd).(SEXP_tcxx . . $ SEXP_t# *item, const char *name, const char *value)
391 {
392 SEXP_tcxx . . $ SEXP_t# *sexp_str = SEXP_string_newcxx . . $ SEXP_string_new(a588a58d7514eee2).(value, strlencxx . . $ strlen(751346f8406fd082).(value));
393 probe_item_ent_addcxx . . $ probe_item_ent_add(9f488d3b029fc9d1).(item, name, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, sexp_str);
394 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(sexp_str);
395 }
396
397 static void _add_ent_from_flagcxx . . $ _add_ent_from_flag(f0c5e214ce649d56).(SEXP_tcxx . . $ SEXP_t# *item, const char *name, struct rpmverify_rescxx . . $ rpmverify_res# *res, int flag)
398 {
399 const char *result;
400 if (res->oflagscxx . . $ rpmverify_res#oflags. & flag || res->vflagscxx . . $ rpmverify_res#vflags. & RPMVERIFY_FAILUREScxx . . $ `<external>/1632812796624396431/rpmfiles.h:97:9`!) {
401 result = "not performed";
402 } else if (res->vflagscxx . . $ rpmverify_res#vflags. & flag) {
403 result = "fail";
404 } else {
405 result = "pass";
406 }
407 _add_ent_from_cstrcxx . . $ _add_ent_from_cstr(56f1cf1671c930dd).(item, name, result);
408 }
409
410 static void _add_ent_bool_from_flagcxx . . $ _add_ent_bool_from_flag(f0c5e214ce649d56).(SEXP_tcxx . . $ SEXP_t# *item, const char *name, struct rpmverify_rescxx . . $ rpmverify_res# *res, int flag)
411 {
412 SEXP_tcxx . . $ SEXP_t# *sexp_str;
413 sexp_str = SEXP_number_newbcxx . . $ SEXP_number_newb(f1e7d218d08e4133).(res->fflagscxx . . $ rpmverify_res#fflags. & flag);
414 probe_item_ent_addcxx . . $ probe_item_ent_add(9f488d3b029fc9d1).(item, name, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, sexp_str);
415 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(sexp_str);
416 }
417
418 static int rpmverify_additemcxx . . $ rpmverify_additem(e8a8575ef97ee980).(probe_ctxcxx . . $ probe_ctx# *ctx, struct rpmverify_rescxx . . $ rpmverify_res# *res)
419 {
420 SEXP_tcxx . . $ SEXP_t# *item;
421 oval_schema_version_tcxx . . $ oval_schema_version_t# oval_version;
422
423 item = probe_item_createcxx . . $ probe_item_create(36b16a6622050a9c).(OVAL_LINUX_RPMVERIFYFILEcxx . . $ OVAL_LINUX_RPMVERIFYFILE., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!,NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
424 _add_ent_from_cstrcxx . . $ _add_ent_from_cstr(56f1cf1671c930dd).(item, "name", res->namecxx . . $ rpmverify_res#name.);
425 _add_ent_from_cstrcxx . . $ _add_ent_from_cstr(56f1cf1671c930dd).(item, "epoch", res->epochcxx . . $ rpmverify_res#epoch.);
426 _add_ent_from_cstrcxx . . $ _add_ent_from_cstr(56f1cf1671c930dd).(item, "version", res->versioncxx . . $ rpmverify_res#version.);
427 _add_ent_from_cstrcxx . . $ _add_ent_from_cstr(56f1cf1671c930dd).(item, "release", res->releasecxx . . $ rpmverify_res#release.);
428 _add_ent_from_cstrcxx . . $ _add_ent_from_cstr(56f1cf1671c930dd).(item, "arch", res->archcxx . . $ rpmverify_res#arch.);
429 _add_ent_from_cstrcxx . . $ _add_ent_from_cstr(56f1cf1671c930dd).(item, "filepath", res->filecxx . . $ rpmverify_res#file.);
430 _add_ent_from_cstrcxx . . $ _add_ent_from_cstr(56f1cf1671c930dd).(item, "extended_name", res->extended_namecxx . . $ rpmverify_res#extended_name.);
431 _add_ent_from_flagcxx . . $ _add_ent_from_flag(f0c5e214ce649d56).(item, "size_differs", res, RPMVERIFY_FILESIZEcxx . . $ RPMVERIFY_FILESIZE.);
432 _add_ent_from_flagcxx . . $ _add_ent_from_flag(f0c5e214ce649d56).(item, "mode_differs", res, RPMVERIFY_MODEcxx . . $ RPMVERIFY_MODE.);
433 _add_ent_from_flagcxx . . $ _add_ent_from_flag(f0c5e214ce649d56).(item, "md5_differs", res, RPMVERIFY_MD5cxx . . $ RPMVERIFY_MD5.); // deprecated since OVAL 5.11.1
434 oval_version = probe_obj_get_platform_schema_versioncxx . . $ probe_obj_get_platform_schema_version(5bacca80194debea).(probe_ctx_getobjectcxx . . $ probe_ctx_getobject(4299b6b53fa804a5).(ctx));
435 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.1)) >= 0) {
436 _add_ent_from_flagcxx . . $ _add_ent_from_flag(f0c5e214ce649d56).(item, "filedigest_differs", res, RPMVERIFY_FILEDIGESTcxx . . $ RPMVERIFY_FILEDIGEST.);
437 }
438 _add_ent_from_flagcxx . . $ _add_ent_from_flag(f0c5e214ce649d56).(item, "device_differs", res, RPMVERIFY_RDEVcxx . . $ RPMVERIFY_RDEV.);
439 _add_ent_from_flagcxx . . $ _add_ent_from_flag(f0c5e214ce649d56).(item, "link_mismatch", res, RPMVERIFY_LINKTOcxx . . $ RPMVERIFY_LINKTO.);
440 _add_ent_from_flagcxx . . $ _add_ent_from_flag(f0c5e214ce649d56).(item, "ownership_differs", res, RPMVERIFY_USERcxx . . $ RPMVERIFY_USER.);
441 _add_ent_from_flagcxx . . $ _add_ent_from_flag(f0c5e214ce649d56).(item, "group_differs", res, RPMVERIFY_GROUPcxx . . $ RPMVERIFY_GROUP.);
442 _add_ent_from_flagcxx . . $ _add_ent_from_flag(f0c5e214ce649d56).(item, "mtime_differs", res, RPMVERIFY_MTIMEcxx . . $ RPMVERIFY_MTIME.);
443 #ifndef HAVE_LIBRPM44
444 _add_ent_from_flagcxx . . $ _add_ent_from_flag(f0c5e214ce649d56).(item, "capabilities_differ", res, RPMVERIFY_CAPScxx . . $ RPMVERIFY_CAPS.);
445 #endif
446 _add_ent_bool_from_flagcxx . . $ _add_ent_bool_from_flag(f0c5e214ce649d56).(item, "configuration_file", res, RPMFILE_CONFIGcxx . . $ RPMFILE_CONFIG.);
447 _add_ent_bool_from_flagcxx . . $ _add_ent_bool_from_flag(f0c5e214ce649d56).(item, "documentation_file", res, RPMFILE_DOCcxx . . $ RPMFILE_DOC.);
448 _add_ent_bool_from_flagcxx . . $ _add_ent_bool_from_flag(f0c5e214ce649d56).(item, "ghost_file", res, RPMFILE_GHOSTcxx . . $ RPMFILE_GHOST.);
449 _add_ent_bool_from_flagcxx . . $ _add_ent_bool_from_flag(f0c5e214ce649d56).(item, "license_file", res, RPMFILE_LICENSEcxx . . $ RPMFILE_LICENSE.);
450 _add_ent_bool_from_flagcxx . . $ _add_ent_bool_from_flag(f0c5e214ce649d56).(item, "readme_file", res, RPMFILE_READMEcxx . . $ RPMFILE_README.);
451
452 return probe_item_collectcxx . . $ probe_item_collect(11bb80e0c30650d7).(ctx, item) == 2 ? 1 : 0;
453 }
454
455 typedef structcxx . . $ $anonymous_type_5c413c996dac8716_0# {
456 const char *a_namecxx . . $ $anonymous_type_5c413c996dac8716_0#a_name.;
457 uint64_tcxx . . $ uint64_t# a_flagcxx . . $ $anonymous_type_5c413c996dac8716_0#a_flag.;
458 } rpmverifyfile_bhmap_tcxx . . $ rpmverifyfile_bhmap_t#;
459
460 const rpmverifyfile_bhmap_tcxx . . $ rpmverifyfile_bhmap_t# rpmverifyfile_bhmapcxx . . $ rpmverifyfile_bhmap.[] = {
461 { "nolinkto", (uint64_tcxx . . $ uint64_t#)RPMVERIFY_LINKTOcxx . . $ RPMVERIFY_LINKTO. },
462 { "nomd5", (uint64_tcxx . . $ uint64_t#)RPMVERIFY_MD5cxx . . $ RPMVERIFY_MD5. }, // deprecated since OVAL 5.11.1
463 { "nosize", (uint64_tcxx . . $ uint64_t#)RPMVERIFY_FILESIZEcxx . . $ RPMVERIFY_FILESIZE. },
464 { "nouser", (uint64_tcxx . . $ uint64_t#)RPMVERIFY_USERcxx . . $ RPMVERIFY_USER. },
465 { "nogroup", (uint64_tcxx . . $ uint64_t#)RPMVERIFY_GROUPcxx . . $ RPMVERIFY_GROUP. },
466 { "nomtime", (uint64_tcxx . . $ uint64_t#)RPMVERIFY_MTIMEcxx . . $ RPMVERIFY_MTIME. },
467 { "nomode", (uint64_tcxx . . $ uint64_t#)RPMVERIFY_MODEcxx . . $ RPMVERIFY_MODE. },
468 { "nordev", (uint64_tcxx . . $ uint64_t#)RPMVERIFY_RDEVcxx . . $ RPMVERIFY_RDEV. },
469 { "noconfigfiles", RPMVERIFY_SKIP_CONFIGcxx . . $ `src/OVAL/probes/unix/linux/rpmverifyfile_probe.c:76:9`! },
470 { "noghostfiles", RPMVERIFY_SKIP_GHOSTcxx . . $ `src/OVAL/probes/unix/linux/rpmverifyfile_probe.c:77:9`! },
471 { "nofiledigest", (uint64_tcxx . . $ uint64_t#)RPMVERIFY_FILEDIGESTcxx . . $ RPMVERIFY_FILEDIGEST. },
472 { "nocaps", (uint64_tcxx . . $ uint64_t#)RPMVERIFY_CAPScxx . . $ RPMVERIFY_CAPS. }
473 };
474
475 int rpmverifyfile_probe_maincxx . . $ rpmverifyfile_probe_main(470536d3ffacaf10).(probe_ctxcxx . . $ probe_ctx# *ctx, void *arg)
476 {
477 SEXP_tcxx . . $ SEXP_t# *probe_in, *file_ent, *bh_ent;
478 SEXP_tcxx . . $ SEXP_t# *name_ent, *epoch_ent, *version_ent, *release_ent, *arch_ent;
479 char file[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!];
480 size_t file_len = sizeof file;
481 oval_operation_tcxx . . $ oval_operation_t# file_op;
482 uint64_tcxx . . $ uint64_t# collect_flags = 0;
483 unsigned int i;
484
485 // If probe_init() failed it's because there was no rpm config files
486 if (arg == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
487 probe_cobj_set_flagcxx . . $ probe_cobj_set_flag(644bab5dffe689c).(probe_ctx_getresultcxx . . $ probe_ctx_getresult(4299b6b53fa804a5).(ctx), SYSCHAR_FLAG_NOT_APPLICABLEcxx . . $ SYSCHAR_FLAG_NOT_APPLICABLE.);
488 return 0;
489 }
490 struct rpm_probe_globalcxx . . $ rpm_probe_global# *g_rpm = (struct rpm_probe_globalcxx . . $ rpm_probe_global# *)arg;
491
492 if (ctx->offline_modecxx . . $ probe_ctx#offline_mode. & PROBE_OFFLINE_OWNcxx . . $ PROBE_OFFLINE_OWN.) {
493 const char* root = getenvcxx . . $ getenv(a8b8e32347182212).("OSCAP_PROBE_ROOT");
494 rpmtsSetRootDircxx . . $ rpmtsSetRootDir(23a209d8fccc3ea8).(g_rpm->rpmtscxx . . $ rpm_probe_global#rpmts., root);
495 }
496
497 /*
498 * Get refs to object entities
499 */
500 probe_in = probe_ctx_getobjectcxx . . $ probe_ctx_getobject(4299b6b53fa804a5).(ctx);
501 file_ent = probe_obj_getentcxx . . $ probe_obj_getent(7907a01f2ff841f3).(probe_in, "filepath", 1);
502
503 if (file_ent == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
504 dEcxx . . $ `src/common/debug_priv.h:63:9`!("Missing \"filepath\" (%p) entity", file_ent);
505
506 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(file_ent);
507
508 return (PROBE_ENOENTcxx . . $ `src/OVAL/probes/public/probe-common.h:20:9`!);
509 }
510
511
512 /*
513 * Extract the requested operation for each entity
514 */
515 file_op = probe_ent_getoperationcxx . . $ probe_ent_getoperation(8f085ec993ec77d).(file_ent, OVAL_OPERATION_EQUALScxx . . $ OVAL_OPERATION_EQUALS.);
516
517 if (file_op == OVAL_OPERATION_UNKNOWNcxx . . $ OVAL_OPERATION_UNKNOWN.)
518 {
519 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(file_ent);
520
521 return (PROBE_EINVALcxx . . $ `src/OVAL/probes/public/probe-common.h:8:9`!);
522 }
523
524 PROBE_ENT_STRVALcxx . . $ `src/OVAL/probes/public/probe-api.h:487:9`!(file_ent, file, file_len, /* void */, strcpy(file, ""););
525 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(file_ent);
526
527 name_ent = probe_obj_getentcxx . . $ probe_obj_getent(7907a01f2ff841f3).(probe_in, "name", 1);
528 epoch_ent = probe_obj_getentcxx . . $ probe_obj_getent(7907a01f2ff841f3).(probe_in, "epoch", 1);
529 version_ent = probe_obj_getentcxx . . $ probe_obj_getent(7907a01f2ff841f3).(probe_in, "version", 1);
530 release_ent = probe_obj_getentcxx . . $ probe_obj_getent(7907a01f2ff841f3).(probe_in, "release", 1);
531 arch_ent = probe_obj_getentcxx . . $ probe_obj_getent(7907a01f2ff841f3).(probe_in, "arch", 1);
532
533 /*
534 * Parse behaviors
535 */
536 bh_ent = probe_obj_getentcxx . . $ probe_obj_getent(7907a01f2ff841f3).(probe_in, "behaviors", 1);
537
538 if (bh_ent != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
539 SEXP_tcxx . . $ SEXP_t# *aval;
540
541 for (i = 0; i < sizeof rpmverifyfile_bhmapcxx . . $ rpmverifyfile_bhmap./sizeof(rpmverifyfile_bhmap_tcxx . . $ rpmverifyfile_bhmap_t#); ++i) {
542 aval = probe_ent_getattrvalcxx . . $ probe_ent_getattrval(42b37380d22a3312).(bh_ent, rpmverifyfile_bhmapcxx . . $ rpmverifyfile_bhmap.[i].a_namecxx . . $ $anonymous_type_5c413c996dac8716_0#a_name.);
543
544 if (aval != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
545 if (SEXP_strcmpcxx . . $ SEXP_strcmp(3ef1a37bcb3c2a).(aval, "true") == 0) {
546 dDcxx . . $ `src/common/debug_priv.h:64:9`!("omit verify attr: %s", rpmverifyfile_bhmap[i].a_name);
547 collect_flags |= rpmverifyfile_bhmapcxx . . $ rpmverifyfile_bhmap.[i].a_flagcxx . . $ $anonymous_type_5c413c996dac8716_0#a_flag.;
548 }
549
550 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(aval);
551 }
552 }
553
554 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(bh_ent);
555 }
556
557 dDcxx . . $ `src/common/debug_priv.h:64:9`!("Collecting rpmverifyfile data, query: f=\"%s\" (%d)",
558 file, file_op);
559
560 if (rpmverify_collectcxx . . $ rpmverify_collect(1bf70a275fddce7e).(ctx,
561 file, file_op,
562 name_ent, epoch_ent, version_ent, release_ent, arch_ent,
563 collect_flags,
564 g_rpm) != 0)
565 {
566 dEcxx . . $ `src/common/debug_priv.h:63:9`!("An error ocured while collecting rpmverifyfile data");
567 probe_cobj_set_flagcxx . . $ probe_cobj_set_flag(644bab5dffe689c).(probe_ctx_getresultcxx . . $ probe_ctx_getresult(4299b6b53fa804a5).(ctx), SYSCHAR_FLAG_ERRORcxx . . $ SYSCHAR_FLAG_ERROR.);
568 }
569
570 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(name_ent);
571 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(epoch_ent);
572 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(version_ent);
573 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(release_ent);
574 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(arch_ent);
575
576 return 0;
577 }