Skip to content

Commit

Permalink
[omnibus] Don't create RPM database if it doesn't exist already
Browse files Browse the repository at this point in the history
On Linux distributions not using the RPM package manager
(Debian, Ubuntu, etc.), the rpm probe of OpenSCAP could
initialize the sqlite RPM database into the /var/lib/rpm,
directory, as a side effect.

This change adds a new patch "rpmdb-no-create" to the RPM package.

This patch changes the openDatabase function to prevent creation
of the RPM database when it doesn't exist already.
  • Loading branch information
0intro committed May 31, 2023
1 parent 9a28beb commit f2d2c59
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
42 changes: 42 additions & 0 deletions omnibus/config/patches/rpm/rpmdb-no-create.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
--- a/lib/rpmdb.c
+++ b/lib/rpmdb.c
@@ -463,6 +463,11 @@ static int openDatabase(const char * prefix,
if (db == NULL)
return 1;

+ /* Don't create db if it doesn't exist already */
+ struct stat st;
+ if (stat(rpmdbHome(db), &st) < 0)
+ return 1;
+
/* Try to ensure db home exists, error out if we can't even create */
rc = rpmioMkpath(rpmdbHome(db), 0755, getuid(), getgid());
if (rc == 0) {
diff --git a/lib/rpmts.c b/lib/rpmts.c
index 7a717b87d..21a2d3bec 100644
--- a/lib/rpmts.c
+++ b/lib/rpmts.c
@@ -91,8 +91,6 @@ int rpmtsCloseDB(rpmts ts)

int rpmtsOpenDB(rpmts ts, int dbmode)
{
- int rc = 0;
-
if (ts->rdb != NULL && ts->dbmode == dbmode)
return 0;

@@ -101,13 +99,7 @@ int rpmtsOpenDB(rpmts ts, int dbmode)
/* XXX there's a potential db lock race here. */

ts->dbmode = dbmode;
- rc = rpmdbOpen(ts->rootDir, &ts->rdb, ts->dbmode, 0644);
- if (rc) {
- char * dn = rpmGetPath(ts->rootDir, "%{_dbpath}", NULL);
- rpmlog(RPMLOG_ERR, _("cannot open Packages database in %s\n"), dn);
- free(dn);
- }
- return rc;
+ return rpmdbOpen(ts->rootDir, &ts->rdb, ts->dbmode, 0644);
}

int rpmtsInitDB(rpmts ts, int perms)
1 change: 1 addition & 0 deletions omnibus/config/software/rpm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
env["CFLAGS"] << " -fPIC"

patch source: "0001-Include-fcntl.patch", env: env # fix build
patch source: "rpmdb-no-create.patch", env: env # don't create db if it doesn't exist already

update_config_guess

Expand Down

0 comments on commit f2d2c59

Please sign in to comment.