Commit Graph

6698 Commits

Author SHA1 Message Date
Panu Matilainen 33da0fdff8 Clean up canonical dirname calculation
Handle path canonicalization and trailing slash centrally.
No functional changes.
2022-05-06 11:34:23 +03:00
Panu Matilainen 328ff700a3 Oops, fixup remnants of old realpath() semantics in fingerprinting
The subsequent code relied on buffer lenght being explicit PATH_MAX
which certainly was no longer the case. Clearly, our test-suite does
not excercise this code...

Should've been in commit b1bc46e56a
2022-05-06 11:27:10 +03:00
Panu Matilainen 09ad6fa904 Rely on POSIX.1-2008 realpath() semantics in query path resolution
Now that we can, etc.  No functional changes.
2022-05-06 11:12:04 +03:00
Panu Matilainen dcf46f9e60 Rely on POSIX.1-2008 realpath() semantics in mountpoint resolution
Now that we can, etc.  No functional changes.
2022-05-06 11:08:54 +03:00
Panu Matilainen b1bc46e56a Rely on POSIX.1-2008 realpath() semantics in fingerprinting code
Since we're requiring POSIX.1-2008 now, we can rely on realpath()
being sane as well. Turns out we've been relying on that in the
debuginfo build-id code since 2016 already (commit
bbfe1f86b2), oops. But then, nobody
has complained...

No functional changes.
2022-05-06 11:08:35 +03:00
Panu Matilainen 066c00c908 Revert "Fix shared colored files not removed on erasure regression in >= 4.14.0"
This causes a worse regression by removing files on update, revert
for further investigation.

This reverts commit 9e4caf0fc5.
2022-04-25 12:50:31 +03:00
Neal H. Walfield c3e988287d Move digest functionality to the internal OpenPGP implementation
rpmio/digest.h contains definitions that are only used by the interal
OpenPGP parser, and are not required by the future Sequoia backend.
Move those definitions into rpmio/rpmpgp_internal.h.

Fixes #2006.
2022-04-13 10:25:04 +03:00
Panu Matilainen d28ecc66bf Purge long since deprecated header APIs too 2022-04-08 12:00:11 +03:00
Panu Matilainen f613b67189 Remove rpmds epoch promote APIs
This is a follow-up to commit 6800e0a4df,
kick out the remaining stubs for real this time.
2022-04-08 12:00:11 +03:00
Panu Matilainen 6fcdaefef5 Eliminate rpmteFI() and corresponding Python binding
These have been deprecated for quite some time, get rid of them
for real.
2022-04-08 12:00:11 +03:00
Panu Matilainen d307b02352 Delete directory index related API stubs for real
This is a follow-up to commit 53b408c18e
to actually remove the stubs since there will be a soname bump next time
around.
2022-04-08 12:00:11 +03:00
Panu Matilainen 6eec1f8a00 Kick out --nopromote remnants, add compiler deprecation warnings
Bury the two remaining callers that somehow avoided the massacre in
commit 6800e0a4df, add compiler
deprecation warnings.
2022-04-05 12:22:34 +03:00
Neal H. Walfield b113a9d729 Make pgpDigParams opaque
- Add accessor functions pgpDigParamsSignID, pgpDigParamsUserID,
    pgpDigParamsVersion, and pgpDigParamsTime.

  - Move the definition of `pgpDigParams_s` from `rpmio/digest.h` to
    `rpmio/rpmpgp.c`.

  - Change code to use the accessor functions.

  - Fixes #1979.
2022-03-31 15:48:18 +03:00
Demi Marie Obenour 619ef3edc5 Fix inverted logic in base2bin()
headerGet() returning 0 is an error condition.
2022-03-31 13:16:38 +03:00
Demi Marie Obenour 6d3ce1c968 Avoid calling memcpy() on NULL
base2bin() would call memcpy() on NULL for empty fsverity signatures.
This is undefined behavior, even if the length is 0.
2022-03-31 12:23:08 +03:00
Panu Matilainen fa70eca360 Support imports to fs keyring too
The fs keyring doesn't of course need the header to be created, but
going through the same motions ensures consistent results, ie the
key goes throught the same validation steps and we also get a
"descriptive" file name for free (descriptive in that it matches the
rpmdb NVR)
2022-03-31 09:56:03 +03:00
Panu Matilainen 3e4c0a95d3 Remember used keyring type in the transaction set
The keyring a transaction uses shouldn't change by somebody defining
macro in the meanwhile. Add an enum for known types and a helper to
lazily determine it on the first keyring load.
2022-03-31 09:56:03 +03:00
Panu Matilainen 9e4caf0fc5 Fix shared colored files not removed on erasure regression in >= 4.14.0
Commit 2d52726bd5 was not SUPPOSED to
change any behavior, but it did: "shared" colored files (ie one being
wrong color and the other one actually installed) removed in the
same transaction would not get removed at all. Fix the embarrasment
that happens when you don't have systematic tests.

Fixes: #1800
2022-03-28 10:43:36 +03:00
Panu Matilainen 0bb3fa9025 Fix excluded paths taking part in file disposition calculations
Commit f311fb65ee added a step to reset
calculated states between rpmtsRun() calls to allow for %pretrans
hacks, but this causes actions set for --excludepath to get lost.
While those do get recalculated at the time of actual install and
correctly skipped, this causes them to be considered for file
disposition which they should not.
2022-03-28 10:43:36 +03:00
Panu Matilainen cf2752b05c Fix non-installed files taking part in file disposition calculations
Files that are not installed cannot conflict with anything, any more
than skipped files can. The latter we handled, the former not. Strange
what "obvious" cases can go on unnoticed forever, when lacking systematic
tests.
2022-03-28 10:43:36 +03:00
Panu Matilainen f60eaa1e0f Set program name centrally from rpmcliInit()
Most of our tools go through rpmcliInit() so take the opportunity
lessen the clutter wrt xsetprogname() calls. No functional changes.
2022-03-25 10:23:37 +02:00
Ludwig Nussel d747bf045e Prevent NULL deref in rpmfsGetStates() 2022-03-18 11:00:40 +02:00
Dirk Müller fccf7eddbc Small speedup on rpm -V
This improves performance of rpm -V --nofiledigests by ~2%
by avoiding an extra parameter and a sprintf call.
2022-03-16 13:57:46 +01:00
Panu Matilainen ee98f9fe57 Use fsmClose() for closing file descriptors everywhere within fsm
fsmClose() does all the necessary checks and resets the fd to -1 after
close, why duplicate these all over the code when we already have a
function...

There's no difference wrt file descriptors getting closed here, but
there is a side-effect to this: if %_flush_io is enabled, they now
get fsync() on the associated directories too, which I think is a good
thing for those who care about it.
2022-03-14 10:05:19 +02:00
Panu Matilainen fee3aafbf6 Fix file descriptor leak regression on install (#1947)
Commit 0e3024ca3e introduced a leak on
directory file descriptors from hardlinked sets, preventing some large
packages with many hardlinks from installing at all.

fsmMkfile() needs to close the firstdir fd when done with it because
that's the only place that knows when it's safe to do so. However, there
could be non-hardlink entries left in the same directory, so we must not
close *that* descriptor. Dup the firstdir descriptor so we're free to
close it without worrying about the other state.

Fixes: #1947
2022-03-14 10:05:19 +02:00
Ludwig Nussel 400ec22aaa List available backends in rpm --showrc 2022-03-10 12:38:57 +02:00
Panu Matilainen b447ad31fb Drop support for undocumented keyid based import over the net
This is insecure in so many ways I'm not going to bother trying to list
them all. It's an undocumented "feature" left over from more innocent
times, time to give it the axe.
2022-03-10 08:43:01 +02:00
Panu Matilainen 650ba79f22 Eliminate the strange include pre-build install machinery
Introduced back in 2007 in 5831404601 the
point was to fake up a sane public header structure with minimal
internal disruption, TEMPORARILY. I think 15 years is temporary enough.

The machinery has worked rather well for what it is, but having the
headers appear in multiple locations is weird and confusing to people,
plus this "physical" separation makes it far more clearer what is
a public header and what isn't.
2022-03-10 08:40:07 +02:00
Panu Matilainen 3d97c19c6e Remove leading directories from doxygen notation
These don't represent the exported include structure so they're
probably more harmful than anything else.
2022-03-10 08:40:07 +02:00
Panu Matilainen 2f0f3be64d Use proper addressing for our public headers everywhere 2022-03-10 08:40:07 +02:00
Panu Matilainen fb104a12eb Fix circular dependency between rpmtypes.h and rpmtag.h
Stop including rpmtag.h from rpmtypes.h, fix callers instead.
This fixes the long-standing issue that rpmtypes.h is not the
free-standing header it's supposed to be and that its sole purpose
is, ie safe to include from anywhere.
2022-03-10 08:40:07 +02:00
Panu Matilainen ba29958753 Drop now unnecessary rpmsqPoll() calls from librpm 2022-03-07 09:34:45 +02:00
Panu Matilainen 35b93119a3 Drop rpmdb shutdown on exit()
This is continuation to the previous commit, this was necessary for
clean Berkeley DB shutdown but current backends do not need it. And
as we no longer route signals through a polled machinery to get an
exit() from eg ctrl-c, this is for all practical purposes dead code,
callers are expected to free their iterators as needed anyway.

As a bonus, eliminating these static structures improves thread-safety
without complicated locking.
2022-03-07 09:34:45 +02:00
Panu Matilainen f9290999e9 Detach rpm signal queue enablement from database open
The rpm signal queue (rpmsq) was necessary to support clean shutdown
of Berkeley Database on signals, but our current backends do not
need such handholding. A library silently hogging your signals on
function call is antisocial behavior, stop doing that since we no
longer have to.

Since the rpmsq is no longer active in transactions, use sigaction()
instead of rpmsqSetAction() to manipulate SIGPIPE. While at it,
eliminate the use of deprecated signal() which in particular should
not be mixed with sigaction() use.

This is quite a dramatic behavior change to a long-standing behavior
so while everybody hated the signal hogging, this may still cause some
fallout in strange places.

This also makes a whole lot of rpmsq code redundant and unused, leaving
it in place for the time being as a backup if we need to revert
short term, to be flushed in the next soname bump.
2022-03-07 09:34:45 +02:00
Panu Matilainen 25c4c61a95 Fix regression on ctrl-c during transaction killing scriptlets
Commit cb6aa82dbc unblocked all signals
from scriptlets, but turns out this is too much: SIGINT, SIGTSTP and
SIGQUIT sent from the terminal are passed to the process group, and
with unblocked signals end up killing our scriptlets while rpm itself
continues. -ENOSENSE.

Stopping (and continuing) is okay though so we don't block that.
2022-03-07 09:33:53 +02:00
Panu Matilainen 2cf26bdd2f Fix memleak in commit dd4f2c68a0 2022-03-03 12:19:50 +02:00
Panu Matilainen dd4f2c68a0 Handle missing RPMTAG_ARCH in RPMTAG_ARCHSUFFIX
RPMTAG_ARCHSUFFIX from commit e6a6399cb4
assumes all headers have RPMTAG_ARCH, but a notable exception is gpg-pubkey
headers in rpmdb, causing segfaults on `rpm -qa` on normal systems.

Special case conditionals in queryformats get ugly and error-prone real
fast, which is why we have all the NEVRA formatter extensions. Avoid
adding yet more of those tags by handling the dot formatting in
ARCHSUFFIX instead - the "suffix" in the name seems to imply this
anyway.

Also add tests to cover the common -qa cases.
2022-03-02 14:22:39 +01:00
Panu Matilainen d44be2cbc1 Rename pgpHexStr() to rpmhex(), but preserve ABI for now
Fixup internal callers to use rpmhex(), deprecate pgpHexStr().
pgpHexStr() should be dropped at next soname bump, whenever that
happens.
2022-02-25 11:08:25 +01:00
Panu Matilainen 01d6605d93 Detach rpm's hash algorithm values from PGP hash algorith values
At this point this is quite literally merely a symbolic change,
as values from PGP hash algo are assumed equal to RPM hash algos,
but it's a necessary first step to supporting hashes not included
in RFC-4880.

Fixes: #1899
2022-02-25 11:08:25 +01:00
Elia Pinto e52d7d8a8e fsm.c: permit building without file capability support
Permit building with ./configure --with-cap=no
2022-02-23 10:33:16 +02:00
Florian Festi e6a6399cb4 Add ARCHSUFFIX extension tag
The new tag returns src/nosrc instead of the build architecture of
(no)source packages.
2022-02-21 16:12:01 +02:00
Panu Matilainen 6dd62720fe Swap over to dirfd+basename based operation within the fsm
Within fsm this is just a matter of adjusting error messages to include
the directory... if it only wasn't for the plugins requiring absolute
paths for outside users. For the plugins, we need to assemble absolute
paths as needed, both in ensureDir() and plugin file slots.
2022-02-16 10:57:18 +02:00
Panu Matilainen 0e3024ca3e Track first hardlink directory descriptor as well
Cross-directory hardlinks shouldn't be used as there's no guarantee
two directories are on the same filesystem, but these exist in the
wild so we need to care.
2022-02-16 10:57:18 +02:00
Panu Matilainen 35195684d2 Pass file descriptor to file prepare plugin hook, use when possible
Sadly the thing that allegedly makes things better mostly just makes
things more complicated as symlinks can't be opened, so we'll now have
to deal with both cases in plugins too. To make matters worse, most
APIs out there support either an fd or a path, but very few support
the *at() style dirfd + basename approach so plugins are stuck with
absolute paths for now.

This is of course a plugin API/ABI change too.
2022-02-16 10:57:18 +02:00
Panu Matilainen 661a37905e Return a validated open directory fd from fsmDoMkDir() 2022-02-16 10:57:18 +02:00
Panu Matilainen 7dc45d932a Add O_DIRECTORY equivalent parameter to fsmOpenat(), use as relevant 2022-02-16 10:57:18 +02:00
Panu Matilainen 1cc29d88ea Add fsm debug logging to ensureDir()
This being one of the more central functions in fsm now, there better
be some diagnostics from it too. Especially when we move to
dirfd+basename operation.
2022-02-16 10:57:18 +02:00
Panu Matilainen ef95f110a3 Parent directory needs to be open before we can back up stuff
A thinko originating from commit c9b2686a4748c227b0abdc0752d844e35296474e
which doesn't matter greatly as long as we're still using absolute
paths but will fail as soon as dirfd+basename is used.

Also pay more attention to the rc's: we must not backup, or run file
pre plugin hook if we know it'll fail.
2022-02-16 10:57:18 +02:00
Panu Matilainen 948be518d5 Convert removeSBITS() to dirfd-based operation 2022-02-16 10:57:18 +02:00
Panu Matilainen 25a435e908 Set file metadata via fd-based ops for everything but symlinks
Regular file ops are fd-based already, for the rest we need to open them
manually. Files with temporary suffix must never be followed, for
directories (and pre-existing FA_TOUCHed files) use the rpm symlink
"root or target owner allowed" rule wrt following.

This mostly fixes CVE-2021-35938, but as we're not yet using dirfd-based
operatiosn for everything there are corner cases left undone. And then
there's the plugin API which needs updating for all this.
2022-02-16 10:57:18 +02:00