Commit Graph

6716 Commits

Author SHA1 Message Date
Panu Matilainen f78be76a00 Fix a memory leak in the new directory dance in ensureDir()
This would leak the path whenever we already had the directory open.
Which happens a lot. Oops.
2022-09-14 13:13:24 +03:00
Panu Matilainen 3848c97cb2 Fix %posttrans argument on upgrade
Packages need to be able to differentiate between install and upgrade
scenarios, seems commit ab069ec876 with
half the lights out...

As %posttrans happens after all the excitement, with the erasure elements
already executed, so the installed package count cannot be used to
differentiate between install and upgrade. So we need to find it out the
hard way: see if there's an erasure element that depends on this
package.
2022-09-13 12:57:22 +03:00
Panu Matilainen af08077fb4 Fix possible descriptor leak in fsmOpenat()
For the very unlikely case when openat() succeeded but fstatat()
doesn't, the directory descriptor may be leaved opened. Rearrange
the code a bit to ensure it'll always get closed when appropriate.

Suggested-by: Pavel Kopylov <pkopylov@cloudlinux.com>
Suggested-by: Dmitry Antipov <dantipov@cloudlinux.com>
2022-09-13 10:26:05 +03:00
Panu Matilainen 19d73f6788 Fix buffer overrun from commit 4420c78beb
The newly handled ^ needs to be accounted for when allocating memory.
Found when testing #1936, goes to show what a useful thing that is.
2022-09-06 13:18:33 +03:00
Panu Matilainen 866a235441 Allow suppressing key import lint warnings
Hack to allow suppressing key import lint warning messages. Emitting
warning messages depending on verbosity level is ugly but for the case
at hand (different output between PGP backends on CI) it's probably the
lesser evil here.

Initial patch by Neal H. Walfield.
2022-08-25 11:35:39 +03:00
Michal Domonkos ce6247e9e3 Append to arglist in rpmGlob()
Instead of constructing a new list from scratch and returning that, just
extend the passed list.  This makes it easier to use this function
incrementally when expanding multiple patterns in a loop, such as during
package manifest parsing which we adapt here right away.

Preserve the ability to pass NULL as argvPtr and still get a match count
via argcPtr, by keeping the local argv around for that case.

No functional change.
2022-08-18 12:33:00 +03:00
Panu Matilainen a7c3886b35 Mop up leftovers from rpmteFI()
This should've been in commit 6fcdaefef5
2022-08-10 13:36:57 +03:00
Florian Festi 2b5b271b0e Add support for --oldpackage to --freshen
This allows to downgrade packages just as with --upgrade but limited to
already installed packages.

Also add basic tests for --freshen

Resolves: #652
2022-07-14 16:02:01 +02:00
yangchenguang 4420c78beb
Fix query arguments with ^ not working
when querying packages in the RPM database.

Rersolves: #2104
2022-07-13 10:52:07 +02:00
Panu Matilainen 8c3fb5eb01 Add an experimental CMake build system
This is an incomplete release-early version, NOT intended or
suitable for production use. It is intended to replace the autotools
based buildsystem in rpm 4.20, until then it'll be developed alongside
it. This causes some extra complications of course, but then we avoid
a huge flag-day, and that matters more.

To those wondering why cmake and not ${myfavorite}: the community around
us effectively made that choice for us. We've made a lot of noise about
bootstrap dependencies. When libsolv, dnf and all the related stack is
powered by cmake build, it'd be just foolish to go with anything else.
This way people working on the rpm stack have only one build system to
learn, there's peer support available nearby and bootstrap dependencies
are reduced, not increased. It also doesn't hurt that cmake is actually
and actively maintained.
2022-06-28 16:33:33 +03:00
Michal Domonkos 9e541c6a7d Fix rpmGlob() escape support
We currently accept a space-separated list of patterns here so any
backslash, whether it belongs to a space char or not, gets consumed by
poptParseArgvString() before the string is passed to glob(3), requiring
callers to double-escape anything they wish to keep literal.

Fix that by only accepting one pattern.  Adapt the one caller which
relies on this actually being a list, in rpmReadPackageManifest(), and
those callers where we preserve spaces by escaping them which is no
longer needed.

Replace our own heuristic emulating GLOB_NOMAGIC with the actual flag to
glob(3) so that literal (double) backslashes are also handled properly.

Keep the indentation of the original for loop to make the diff easier to
read, next commit will fix that.

No immediate effect within RPM since we currently avoid passing escaped
patterns to rpmGlob(), this is just a prerequisite for the following
commits.  External users of rpmGlob(), as unlikely as they are, might,
in theory, notice this subtle change but we'll be bumping the soname in
4.19 so that's covered.
2022-06-27 08:42:36 +03:00
Panu Matilainen 9b64dacd82 Use consistent WITH/ENABLE names between defines and conditionals
If it's enabled with --enable then the define should be ENABLE_FOO
not WITH_FOO, for sanity's sake. No functional changes.
2022-06-17 11:52:47 +03:00
Panu Matilainen b7e71ffa47 Drop support for ancient libcap
cap_compare() is in libcap since 2008 or so, we really don't need to
bother with versions older than that. Another redundant configure check
and a piece of moldy code bites the dust.
2022-06-16 09:35:40 +03:00
Panu Matilainen 48d0fa954c Test for preprocessor definition rather than value consistently everywhere
This is not supposed to actually change anything as such but
inconsistency is bad and causes other kinds of headaches.
2022-06-15 16:24:51 +03:00
Panu Matilainen a3d11f7a53 Fix potential uninitialized variable use in rpmtsImportPubkey()
Commit d703160334 introduced a new step
to key import which can fail before keyring is initialized.

Always initialize your variables, never need "fixes" like this.
2022-06-06 12:04:15 +03:00
Panu Matilainen cbfba05d7f Prevent uncontrolled sqlite WAL growth during large transactions
Sqlite WAL threshold of 1000 pages is way too low for rpmdb as a single
header often exceeds that, but disabling the checkpointing entirely can
cause the WAL to grow to multiple gigabytes during large distro update
transactions, which isn't healty either. Bump the threshold to 10000
pages which caps the WAL size to tens of megabytes, which hopefully
is a reasonable balance between performance on rotational disks (anybody
remember those?) and diskpace consumption.

Also drop no longer meaningful link to %_flush_io configuration.
2022-05-23 12:56:45 +03:00
Panu Matilainen e36ac91ee2 Unhide -q/--query option
Fixes: #1473
2022-05-17 09:32:56 +03:00
Neal H. Walfield d703160334 Before importing an OpenPGP certificate, lint it
When importing an OpenPGP certificate, lint the certificate to show
the user possible issues.  Fail if the certificate is completely
unusable.  Using the Sequoia backend, this yields, for instance:

  $ ./rpmkeys --import tests/data/keys/alice-revoked-subkey.asc
  Certificate B3A771BFEB04E625:
    Subkey 1F71177215217EE0 was revoked: Key material has been compromised, it was the maid
    Certificate does not have any usable signing keys

Fixes #1974.
2022-05-12 15:00:39 +03:00
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