Skip to content

Commit

Permalink
Honor read-only transaction lock mode
Browse files Browse the repository at this point in the history
Now that the underlying rpmlock supports it, have rpmtxnBegin()
actually differentiate between read and write locks. This makes
it possible for a normal user to export the rpmdb.

Add test for export as a regular user (ie the fix here) and import
in general, we didn't have any tests for that before now.
  • Loading branch information
pmatilai committed Oct 11, 2024
1 parent 304d25d commit 0413c3b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rpmts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1479,7 +1479,8 @@ rpmtxn rpmtxnBegin(rpmts ts, rpmtxnFlags flags)
if (ts->lock == NULL)
ts->lock = rpmlockNew(ts->lockPath, _("transaction"));

if (rpmlockAcquire(ts->lock)) {
int lockmode = (flags & RPMTXN_WRITE) ? RPMLOCK_WRITE : RPMLOCK_READ;
if (rpmlockAcquire(ts->lock, lockmode)) {
txn = new rpmtxn_s {};
txn->lock = ts->lock;
txn->flags = flags;
Expand Down
36 changes: 36 additions & 0 deletions tests/rpmdb.at
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,42 @@ hello-2.0-1.x86_64
[])
RPMTEST_CLEANUP

AT_SETUP([rpmdb --export and --import])
AT_KEYWORDS([rpmdb])

RPMTEST_CHECK([
RPMDB_INIT
runroot rpm -U /data/RPMS/hlinktest-1.0-1.noarch.rpm
],
[0],
[],
[])

RPMTEST_CHECK([
# Need to pass the dbpath explicitly since we're not going through run/runroot
runroot_other /sbin/runuser -u nobody -- rpmdb --dbpath /var/lib/rpm --exportdb > hdr.list
],
[0],
[],
[])

RPMTEST_CHECK([
runroot rpm -qa --dbpath ${PWD}
],
[0],
[],
[])

RPMTEST_CHECK([
runroot rpmdb --importdb --dbpath ${PWD} < hdr.list
runroot rpm -qa --dbpath ${PWD}
],
[0],
[hlinktest-1.0-1.noarch
],
[])
RPMTEST_CLEANUP

AT_SETUP([rpm -qa and rpmkeys])
AT_KEYWORDS([rpmdb query])
AT_SKIP_IF([test x$PGP = xdummy])
Expand Down

0 comments on commit 0413c3b

Please sign in to comment.