Debian Codegraph @

src/OVAL/probes/unix/linux/rpm-helper.c

raw symbols SCIP
1 /*
2 * Copyright 2016 Red Hat Inc., Durham, North Carolina.
3 * All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 */
20
21 #include "rpm-helper.h"cxx . . $ `<file>/src/OVAL/probes/unix/linux/rpm-helper.h`/
22
23 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`!
24 #include <config.h>cxx . . $ `<file>/build/config.h`/
25 #endif
26
27 #ifdef RPM46_FOUNDcxx . . $ `build/config.h:46:9`!
28 int rpmErrorCbcxx . . $ rpmErrorCb(fff58a40e215938). (rpmlogReccxx . . $ rpmlogRec# rec, rpmlogCallbackDatacxx . . $ rpmlogCallbackData# data)
29 {
30 dEcxx . . $ `src/common/debug_priv.h:63:9`!("RPM: %s", rpmlogRecMessage(rec));
31 return RPMLOG_DEFAULTcxx . . $ `<external>/10238567921865421537/rpmlog.h:63:9`!;
32 }
33 #endif
34
35 #ifndef HAVE_RPMVERIFYFILE
36 int rpmVerifyFilecxx . . $ rpmVerifyFile(3d59f9e68d5ecc36).(const rpmtscxx . . $ rpmts# ts, const rpmficxx . . $ rpmfi# fi,
37 rpmVerifyAttrscxx . . $ rpmVerifyAttrs# * res, rpmVerifyAttrscxx . . $ rpmVerifyAttrs# omitMask)
38 {
39 rpmVerifyAttrscxx . . $ rpmVerifyAttrs# vfy = rpmfiVerifycxx . . $ rpmfiVerify(2aefa3c1d5a51507).(fi, omitMask);
40 if (res)
41 *res = vfy;
42
43 return (vfy & RPMVERIFY_LSTATFAILcxx . . $ RPMVERIFY_LSTATFAIL.) ? 1 : 0;
44 }
45 #endif
46
47 void rpmLibsPreloadcxx . . $ rpmLibsPreload(49f6e7a06ebc5aa8).()
48 {
49 // Don't load rpmrc files. The are useless for us,
50 // because we only need to preload libraries
51 const char* rcfiles = "";
52 rpmReadConfigFilescxx . . $ rpmReadConfigFiles(5ae29d726ae57f88).(rcfiles, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
53 }
54
55 void set_rpm_db_pathcxx . . $ set_rpm_db_path(49f6e7a06ebc5aa8).()
56 {
57 /*
58 * Fedora >=36 changed the default dbpath in librpm from /var/lib/rpm to /usr/lib/sysimage/rpm.
59 * See: https://fedoraproject.org/wiki/Changes/RelocateRPMToUsr
60 *
61 * Therefore, when running openscap on a Fedora >=36 system scanning another systems (such as RHEL, SLES, Fedora<36)
62 * openscap's librpm will try to read the rpm db from /usr/lib/sysimage/rpm which doesn't exist and therefore won't work.
63 * On many systems, /var/lib/rpm is still a symlink to /usr/lib/sysimage/rpm, so using /var/lib/rpm can work there.
64 * However, on some systems, eg. bootc images, /var/lib/rpm isn't a symlink and doesn't contain the RPM database.
65 *
66 * We will first try if the "new" location /usr/lib/sysimage/rpm exists, and use it only if it exists.
67 * If it doesn't exist, we will fall back to the "old" location /var/lib/rpm.
68 */
69
70 struct statcxx . . $ stat# sb;
71 const char *dbpath;
72 const char *prefix = getenvcxx . . $ getenv(a8b8e32347182212).("OSCAP_PROBE_ROOT");
73 char *path_with_prefix = oscap_path_joincxx . . $ oscap_path_join(a713fe7b9a57cf96).(prefix, "/usr/lib/sysimage/rpm");
74 if (statcxx . . $ stat(a9cd1e23e96f423c).(path_with_prefix, &sb) == 0) {
75 dbpath = "/usr/lib/sysimage/rpm";
76 } else {
77 dbpath = "/var/lib/rpm";
78 }
79 freecxx . . $ free(5d22bdacc48458e8).(path_with_prefix);
80 dIcxx . . $ `src/common/debug_priv.h:61:9`!("Using %s as rpm database.", dbpath);
81 rpmPushMacrocxx . . $ rpmPushMacro(d3a70335639f9adf).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, "_dbpath", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, dbpath, RMIL_CMDLINEcxx . . $ `<external>/2040797851061054216/rpmmacro.h:47:9`!);
82 }