Commit Graph

6743 Commits

Author SHA1 Message Date
Panu Matilainen ccfca4146d Use our O_DIRECTORY equivalent when opening files for setmeta
Ie if we expect a directory, ensure we got one.
2023-01-13 13:17:52 +02:00
Panu Matilainen 3a7c8bc401 Explicitly specify O_RDONLY when opening files for setmeta
On Linux, this is a no-op as O_RDONLY is 0 but this may not be so on
other platforms. Another 4.18 regression.
2023-01-13 13:17:52 +02:00
Panu Matilainen 3a3e10b981 Never follow links in path-based chown()
This is basically a leftover from the initial conversion to the *at()
family in commit 1bab34c6e4 - the logic
was already there and only converted to the *at() form. But this is not
only potentially insecure (remember all those symlink CVEs) but also
wrong simply because it's inconsistent with the other metadata ops which
never follow links in path-based mode.
2023-01-13 13:17:52 +02:00
Panu Matilainen 9320136981 Use fd-based ops for metadata in FA_TOUCH mode too, when possible
Fixes another brainfart in commit 25a435e908.
2023-01-13 13:17:52 +02:00
Panu Matilainen 28c92fd54c Fix install of block and character special files (#2195, #2275)
While it's possible to open special files, they are, well, special and
have "side-effects" also known as, ahem, semantics. Opening a device
file in Unix means accessing that *device*, and FIFOs have their own
semantics.  In other words, for rpm's purposes, we should never EVER
open these files as a part of the install / permission setting etc.
Fix this major brainfart in 25a435e908.

OTOH this forces us back to the less secure path based operations for
these files, which is what we were trying to avoid in the first place.
There always was a tiny race between create + open for these (because
there's no atomic way to create + open anything but regular files) but
this opens up the window quite a bit.
Nobody should be placing device nodes in user-owned directories but
FIFO's may be a different story.

We haven't had tests for device nodes because it requires privileges the
test-suite usually doesn't have, not testing FIFOs I have no excuse for.
Add that test now.

Fixes: #2195, #2275
2023-01-13 13:17:52 +02:00
Fabian Vogt cd46c1704c Add x86-64 architecture levels (v2-v4) as architectures
The x86_64 SysV psABI defines four levels of x86_64 with certain CPU
features required for each level. Those definitions are meant to be
generically useful and recognized as such by glibc and gcc as well.

For backward-compatibility and to avoid surprises, default to building
x86_64 even on v2+ capable machines.
2023-01-09 11:05:29 +02:00
xujing af81c95114 Fix fileleak when urlGetFile fails in rpmInstall
The "tfn" is created by calling rpmMkTempFile but not unlinked when
urlGetFile fails in rpmInstall. Fix it.
2022-12-20 10:13:11 +02:00
xujing f0f983b145 Fix fileleak and memleak in rpmInstall
The "*eiu->fnp" from "eiu->pkgURL[eiu->pkgx]" which is alloced. when
Fopen or rpmReadPackageFile fails in tryReadHeader, "*eiu->fnp" is
set to NULL but not freed. In addition, if "eiu->pkgState[eiu->pkgx]"
is set, the file is leaked too. Fix it.

Only resource free is added, no other logic change.
2022-12-20 10:13:11 +02:00
xujing 688c4ad34d Fix memleak when fsmRename failed in fsmCommit
The "dest" is alloced in fsmFsPath but not freed when fsmRename failed
in fsmCommit. Fix it.
2022-12-20 10:13:11 +02:00
Panu Matilainen e2c504c083 Move bunch of global compile definitions to the targets needing them
No functional changes, just declutter the global compilation stuff
a bit.
2022-12-15 12:26:23 +02:00
Daniel Alley 8e6108a596 Use unsigned integers more consistently in the handling of tag data
Not a functional change, it just makes the code more clear and
self-consistent.
2022-12-09 09:26:06 +02:00
Panu Matilainen 58ece20d33 Avoid unnecessary variables for cmake target data, part 1
The foo_SOURCES style isn't really in cmake ethos, and is wholly
unnecessary here: target_sources() achieves the same exact thing in a
slightly more straightforward way.
2022-11-28 13:55:07 +02:00
Panu Matilainen 71fe36cdc5 Use cmake imported targets to let it sort out the compiler flag details
These imported targets passed to target_link_library() are supposed to
handle all the pesky compilation, linkage etc details behind the scenes.
I was pretty sure I was missing a trick with this, but this sure isn't
exactly underlined in the documentation.

Unroll the supposedly helpful loop for handling plugins: turns out doing
this cmake native way is plenty shorter and more obvious too. The unroll
kinda belongs to a separate commit but that'd be rather painful for very
little if any gain.

Fixes: #2269 and a whole class of similar cases, allegedly
2022-11-28 11:31:21 +02:00
xujing 86c1d9738d Fix h->blob leak when installing source rpms
When installing source rpms, "ei" is malloced and is saved in
blob->ei by rpmReadPackageFile->rpmpkgRead->hdrblobRead, and then
blob->ei is saved in h->blob by rpmReadPackageFile->hdrblobImport,
which is leaked during installation.
2022-11-25 09:46:56 +02:00
xujing 0b34438ccc Fix file leak when src rpm in URL format is used for installation
%{_tmppath}/rpm-tmp.* is created by rpmMkTempFile() when src rpm in
URL format is used for installation, which is leaked.
2022-11-25 09:46:56 +02:00
xujing 084c64d5ea Fix eiu->sourceURL info leak in rpmInstall()
When installing source rpms, eiu->sourceURL info is leaked.
2022-11-25 09:46:56 +02:00
xujing 15a0c73f46 Fix header leak in rpmInstall()
When rpm installs a package, the header from tryReadHeader()
in rpmInstall() is leaked in some cases.
2022-11-25 09:46:56 +02:00
Panu Matilainen 3dcf09b0f2 Fix libacl and libaudit linkage to use info from pkg-config 2022-11-03 14:35:02 +02:00
Panu Matilainen c0578ad982 Drop misplaced sqlite3 linkage from bdb_ro which certainly doesn't... 2022-11-03 14:06:31 +02:00
Panu Matilainen d1e234bd56 Remember to set include directories from pkgconfig for Lua
We should really do this for all our dependencies, but notably Debian
and derivates have multiple versions of Lua available, each in different
includedir, and build fails without this.

Fixes: #2258
2022-11-03 13:16:05 +02:00
Panu Matilainen 6f1c67ffb1 Remove autotools build
There are some missing bits and pieces still to be done for cmake build,
but that is so much easier if you don't have to worry about keeping
compatibility with the system you're about to remove that it doesn't
make sense to drag this on any further. The sooner this is over, the
sooner it is over and we can start making use of cmake's advantages
instead of just trying to bend over backwards to maintain compatibility
with the autotools build.
2022-10-21 09:03:05 +03:00
Panu Matilainen c890b44821 Refactor db iterator locked to single rpmte to a common helper function
Two places doing the same thing, they also share all the bugs...
No functional changes here.
2022-10-20 14:01:21 +03:00
Panu Matilainen 89676fad73 Handle downgrade within V-R when epoch goes away (RhBug:1845069)
A missing epoch is returned as NULL from rpmteE(), but the rpmdb
matching code can't handle NULL in any meaningful way currently.
Arguably it should, but that's a bigger topic...

Specifically convert a missing epoch to a "0" which matches the behavior
in mireSkip() to handle, adjust testcases as appropriate.
2022-10-20 14:01:21 +03:00
Panu Matilainen 4eb26a8280 Drop redundant _GNU_SOURCE definitions from ndb 2022-10-20 13:52:45 +03:00
Panu Matilainen db46bd8bd1 Add support for %preuntrans and %postuntrans scriptlets
These are obviously the long lost uninstall-time counterparts of
%pretrans and %posttrans.

%preuntrans is easy but %postuntrans is the reason this hasn't been
implemented so far: by the time it's supposed to execute, the header will
be gone. Work around this by allowing the rpmte to hold on to its header
if it has a %postuntrans scriptlet.

Cheapskate on transaction flags and reuse pre/posttrans flags for these
uninstall counterparts too, adding separate flags and disablers just
doesn't seem worth it, especially as we're quite short of free bits.

Fixes: #2119
2022-09-26 13:00:05 +02:00
Panu Matilainen 9478961948 Clarify countCorrection usage in psm 2022-09-26 13:00:05 +02:00
Michal Domonkos 8ef29094fa Try globs literally when there are no matches
When a glob yields no matches, try accessing a file named like the
literal pattern before finally giving up.  Do this for any globs
supplied by the user, be it on the CLI or through a %files section.

We already do this with regular files in %files, this commit just
extends the same logic to the remaining places, namely special files
(%doc or %license) and package files passed on the CLI in install or
query mode (either directly or indirectly through a manifest).

This makes globbing in RPM consistent and more shell-like as Bash does
the same by default.

Do this by treating globs as filenames that may or may not expand into
multiple ones.  That way, both cases can be handled by the same code
path.

We don't need to check for the existence of the literal pattern since
that's eventually taken care of in the rpmGlob() caller, such as in
addFile().  As a nice side effect, error reporting for missing glob and
non-glob filenames is now also unified, see the updated tests.

Preserve the public signature of rpmGlob(), though, by adding a new,
more general wrapper that also takes flags.  The name is chosen to fit
the pre-existing scheme of rpm*Path() functions in rpmfileutil.h.
2022-09-20 15:01:05 +03:00
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