Skip to content

Commit 3f2bcc8

Browse files
committed
Always use /var/lib/rpm as rpm dbpath
Fedora >=36 changed the default dbpath in librpm from /var/lib/rpm to /usr/lib/sysimage/rpm Therefore, when running openscap on a Fedora >=36 system scanning another systems (such as RHEL, SLES, Fedora<36) openscap's librpm will try to read the rpm db from /usr/lib/sysimage/rpm which doesn't exist and therefore won't work. In implementing this change, /var/lib/rpm is still a symlink to /usr/lib/sysimage/rpm so /var/lib/rpm still works. So /var/lib/rpm is a dbpath that will work on all systems. Therefore, set the dbpath to be /var/lib/rpm, allow openscap running on any system to scan any system. See: https://fedoraproject.org/wiki/Changes/RelocateRPMToUsr Fixes: #1942
1 parent 439ff6e commit 3f2bcc8

File tree

5 files changed

+61
-5
lines changed

5 files changed

+61
-5
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,17 @@ void *rpminfo_probe_init(void)
294294
return ((void *)g_rpm);
295295
}
296296

297+
/*
298+
* Fedora >=36 changed the default dbpath in librpm from /var/lib/rpm to /usr/lib/sysimage/rpm
299+
* See: https://fedoraproject.org/wiki/Changes/RelocateRPMToUsr
300+
* Therefore, when running openscap on a Fedora >=36 system scanning another systems (such as RHEL, SLES, Fedora<36)
301+
* openscap's librpm will try to read the rpm db from /usr/lib/sysimage/rpm which doesn't exist and therefore won't work.
302+
* In implementing this change, /var/lib/rpm is still a symlink to /usr/lib/sysimage/rpm
303+
* so /var/lib/rpm still works. So /var/lib/rpm is a dbpath that will work on all systems.
304+
* Therefore, set the dbpath to be /var/lib/rpm, allow openscap running on any system to scan any system.
305+
*/
306+
rpmPushMacro(NULL, "_dbpath", NULL, "/var/lib/rpm", RMIL_CMDLINE);
307+
297308
g_rpm->rpmts = rpmtsCreate();
298309
pthread_mutex_init (&(g_rpm->mutex), NULL);
299310

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,18 @@ void *rpmverify_probe_init(void)
234234
dD("rpmReadConfigFiles failed: %u, %s.", errno, strerror (errno));
235235
return (NULL);
236236
}
237+
238+
/*
239+
* Fedora >=36 changed the default dbpath in librpm from /var/lib/rpm to /usr/lib/sysimage/rpm
240+
* See: https://fedoraproject.org/wiki/Changes/RelocateRPMToUsr
241+
* Therefore, when running openscap on a Fedora >=36 system scanning another systems (such as RHEL, SLES, Fedora<36)
242+
* openscap's librpm will try to read the rpm db from /usr/lib/sysimage/rpm which doesn't exist and therefore won't work.
243+
* In implementing this change, /var/lib/rpm is still a symlink to /usr/lib/sysimage/rpm
244+
* so /var/lib/rpm still works. So /var/lib/rpm is a dbpath that will work on all systems.
245+
* Therefore, set the dbpath to be /var/lib/rpm, allow openscap running on any system to scan any system.
246+
*/
247+
rpmPushMacro(NULL, "_dbpath", NULL, "/var/lib/rpm", RMIL_CMDLINE);
248+
237249
struct rpm_probe_global *g_rpm = malloc(sizeof(struct rpm_probe_global));
238250
g_rpm->rpmts = rpmtsCreate();
239251

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,18 @@ void *rpmverifyfile_probe_init(void)
355355
}
356356

357357
struct rpm_probe_global *g_rpm = malloc(sizeof(struct rpm_probe_global));
358+
359+
/*
360+
* Fedora >=36 changed the default dbpath in librpm from /var/lib/rpm to /usr/lib/sysimage/rpm
361+
* See: https://fedoraproject.org/wiki/Changes/RelocateRPMToUsr
362+
* Therefore, when running openscap on a Fedora >=36 system scanning another systems (such as RHEL, SLES, Fedora<36)
363+
* openscap's librpm will try to read the rpm db from /usr/lib/sysimage/rpm which doesn't exist and therefore won't work.
364+
* In implementing this change, /var/lib/rpm is still a symlink to /usr/lib/sysimage/rpm
365+
* so /var/lib/rpm still works. So /var/lib/rpm is a dbpath that will work on all systems.
366+
* Therefore, set the dbpath to be /var/lib/rpm, allow openscap running on any system to scan any system.
367+
*/
368+
rpmPushMacro(NULL, "_dbpath", NULL, "/var/lib/rpm", RMIL_CMDLINE);
369+
358370
g_rpm->rpmts = rpmtsCreate();
359371

360372
pthread_mutex_init(&(g_rpm->mutex), NULL);

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,17 @@ static int rpmverify_collect(probe_ctx *ctx,
271271
// so we have to reload everything again
272272
rpmReadConfigFiles ((const char *)NULL, (const char *)NULL);
273273

274+
/*
275+
* Fedora >=36 changed the default dbpath in librpm from /var/lib/rpm to /usr/lib/sysimage/rpm
276+
* See: https://fedoraproject.org/wiki/Changes/RelocateRPMToUsr
277+
* Therefore, when running openscap on a Fedora >=36 system scanning another systems (such as RHEL, SLES, Fedora<36)
278+
* openscap's librpm will try to read the rpm db from /usr/lib/sysimage/rpm which doesn't exist and therefore won't work.
279+
* In implementing this change, /var/lib/rpm is still a symlink to /usr/lib/sysimage/rpm
280+
* so /var/lib/rpm still works. So /var/lib/rpm is a dbpath that will work on all systems.
281+
* Therefore, set the dbpath to be /var/lib/rpm, allow openscap running on any system to scan any system.
282+
*/
283+
rpmPushMacro(NULL, "_dbpath", NULL, "/var/lib/rpm", RMIL_CMDLINE);
284+
274285
rpmts ts = rpmtsCreate();
275286
char* const * args = (char* const *)poptGetArgs(rpmcli_context);
276287

@@ -344,6 +355,17 @@ void *rpmverifypackage_probe_init(void)
344355
return ((void *)g_rpm);
345356
}
346357

358+
/*
359+
* Fedora >=36 changed the default dbpath in librpm from /var/lib/rpm to /usr/lib/sysimage/rpm
360+
* See: https://fedoraproject.org/wiki/Changes/RelocateRPMToUsr
361+
* Therefore, when running openscap on a Fedora >=36 system scanning another systems (such as RHEL, SLES, Fedora<36)
362+
* openscap's librpm will try to read the rpm db from /usr/lib/sysimage/rpm which doesn't exist and therefore won't work.
363+
* In implementing this change, /var/lib/rpm is still a symlink to /usr/lib/sysimage/rpm
364+
* so /var/lib/rpm still works. So /var/lib/rpm is a dbpath that will work on all systems.
365+
* Therefore, set the dbpath to be /var/lib/rpm, allow openscap running on any system to scan any system.
366+
*/
367+
rpmPushMacro(NULL, "_dbpath", NULL, "/var/lib/rpm", RMIL_CMDLINE);
368+
347369
g_rpm->rpm.rpmts = rpmtsCreate();
348370

349371
if (CHROOT_IS_SET()) {

tests/probes/rpm/rpm_common.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ RPMBUILD="${RPMBASE}/build"
1111

1212
# Since Fedora 36 RPM database location changed, see
1313
# https://fedoraproject.org/wiki/Changes/RelocateRPMToUsr
14-
if [ -d "/usr/lib/sysimage/rpm/" ]; then
15-
RPMDB_PATH="/usr/lib/sysimage/rpm/"
16-
else
17-
RPMDB_PATH="/var/lib/rpm/"
18-
fi
14+
# However, /var/lib/rpm/ still works as it is a symlink to
15+
# the new path, /usr/lib/sysimage/rpm/, in Fedora >= 36
16+
# Therefore, always use /var/lib/rpm/ as it always works.
17+
RPMDB_PATH="/var/lib/rpm/"
1918

2019
function rpm_build {
2120
require "rpmbuild" || return 255

0 commit comments

Comments
 (0)