Commit Graph

14085 Commits

Author SHA1 Message Date
Panu Matilainen 8156b937d9 Don't initialize return values on rpmReadHeader() entry
For consistency with rpmReadPackageFile() (which changed behavior
similarly in the grand package read unification) and common practise,
only set return values pointers when we have something to return.
Other than that, everybody gets to initialize their own variables.

Also don't dereference msg, we really dont need to know whether it
points to a NULL string ornot in order to set it.
2017-10-03 10:37:39 +03:00
Panu Matilainen 7d2ead6c5f Remove no longer needed fakechroot workaround from rpmfilesStat()
Symlink sizes inside fakechroot environment used to be incorrect
in some situations, quite naturally since those links *are* longer
on disk. This was fixed a long long time ago in fakechroot 2.10 but
Fedora was stuck with 2.9 for a long time so... Anyway, good riddance.
2017-10-02 12:30:10 +03:00
Panu Matilainen b8e861110f Use the mode, size, mtime and rdev data from rpmfilesStat()
No need for the separate accessor calls now, just use the data from
the stat struct from rpmfilesStat(). No functional changes, but this
depends on commit b7f6ad3919 to get the
size right.
2017-10-02 11:59:41 +03:00
Panu Matilainen 363554386d Clean up file verify mode comparison
Casts from the past are not needed when we use mode_t for dealing
with this data to begin with. In addition, use the standard S_IFMT
macro for file type masking instead of hardcoded hex value.
2017-10-02 11:54:32 +03:00
Panu Matilainen d9a56786e5 Use just numeric uid/gid for user/group verification
Lose the duplicate detection introduced in commit
348eea3a41 which was a bit controversial,
and outside rpm's jurisdiction. Instead grab all the relevant file data
in through rpmfilesStat(). Simplifies things a good deal without really
losing anything, multiple user/groupnames will still be handled correctly
as long as they can be resolved to the same id via the normal means.
So from rpm's POV no functional changes, just 40 lines less goo...
2017-10-02 11:53:57 +03:00
Panu Matilainen b7f6ad3919 Fix st_size on non-archive use of rpmfiStat()/rpmfilesStat()
In archives, hardlinked files are zero-sized except for the last file
of the hardlinked set which carries the actual content. For other
purposes we want the actual size, hardlink or not. So in rpmfilesStat()
always just report the size from the header and fixup the size to
when iterating over archives from rpmfiStat() instead.
2017-10-02 11:50:23 +03:00
Panu Matilainen 2a1c3db622 And another test-suite related distcheck regression fix...
Commit ec0d4d80d8 added a bunch of
perfectly innocent looking rpm queries to the rpmbuild test suite,
which however end up breaking "make distcheck". Really.

The problem is that these are executed without the testsuite run()
wrapper function so the rpm running environment isn't quite right
and because of that, when run deep from distcheck in a crazy
prefix config (or something like that), an rpmdb instance gets left
over where it shouldn't be, and that makes distcheck unhappy.
And that in turn tends to make your head hurt.
2017-09-28 16:12:29 +03:00
Panu Matilainen af3b481d31 Unbreak make distcheck again
Regression introduced in commit 5b176ceca6
by the way of sloppy eyes: the main macros file used to be included
in the path via ${abs_top_builddir} but that's not where macros.debug
lives, unless you happen to build in the source directory directly.
The correct source for macros.debug is ${top_srcdir} instead.
2017-09-28 11:18:10 +03:00
Panu Matilainen c815822c8b Make verification match the new restricted directory symlink behavior
Only follow directory symlinks owned by target directory owner or root
during verification to match the behavior of fsmVerify() in the new
CVE-2017-7500 world order.

The code is klunkier than it should and the logic should use common code
with fsmVerify() instead of duplicating it here, but that needs more
changes than is comfortable to backport so starting with this.

Also worth noting that the previous "follow the link" logic from
commit 3ccd774255 was not quite right,
it'd fail with RPMVERIFY_LSTATFAIL on a broken symlink when it should've
ran verification on the symlink itself. This behavior is fixed here too.

Finally, once again fakechroot gets in the way and forces the related
verify testcase to be changed to be able to create a valid link. Reuse
the replacement testcase for the purpose and add another case for
verifying an invalid link.
2017-09-28 10:49:24 +03:00
Panu Matilainen f2d3be2a87 Restrict following symlinks to directories by ownership (CVE-2017-7500)
Only follow directory symlinks owned by target directory owner or root.
This prevents privilege escalation from user-writable directories via
directory symlinks to privileged directories on package upgrade, while
still allowing admin to arrange disk usage with symlinks.

The rationale is that if you can create symlinks owned by user X you *are*
user X (or root), and if you also own directory Y you can do whatever with
it already, including change permissions. So when you create a symlink to
that directory, the link ownership acts as a simple stamp of authority that
you indeed want rpm to treat this symlink as it were the directory that
you own. Such a permission can only be given by you or root, which
is just the way we want it. Plus it's almost ridiculously simple as far
as rules go, compared to trying to calculate something from the
source vs destination directory permissions etc.

In the normal case, the user arranging diskspace with symlinks is indeed
root so nothing changes, the only real change here is to links created by
non-privileged users which should be few and far between in practise.
Unfortunately our test-suite runs as a regular user via fakechroot and
thus the testcase for this fails under the new rules. Adjust the testcase
to get the ownership straight and add a second case for the illegal
behavior, basically the same as the old one but with different expectations.
2017-09-28 08:36:22 +03:00
Pavlina Moravcova Varekova e9d1ec565d Remove an outdated todo for %trace
I cannot find any reason for the TODO in these days.
2017-09-26 13:14:48 +03:00
Michael Schroeder 99e6de8109 Forbid 'if' richops in 'or' context and 'unless' richops in 'and' context
Guide users to the correct operator instead.
2017-09-22 14:38:27 +03:00
Panu Matilainen f97f91f2ab Argh, make the stupid new string translatable too 2017-09-22 14:08:38 +03:00
Panu Matilainen 9aad3ee2ce Implement --load cli switch to allow loading individual macro files 2017-09-22 14:02:27 +03:00
Panu Matilainen 5b176ceca6 Add + use a separate helper function for debuginfo test-cases
These need an extra macros file which OTOH cannot be present in other
tests, but overriding --macros tends to get into different kinds of
trouble, for example commit ec0d4d80d8
revealed hardcoded /usr/local/lib/rpm prefixes in the cli invocations
by the way of test-suite failures when a different prefix is used.

The testsuite runs with RPM_CONFIGDIR pointed to the test environment
so basic rpm configuration is fine as-is, just arrange the macros.debug
file into the environment by copying and removing for each of these tests.
Crude yeah, but works. Loading the macro file with --eval "%{load:...}"
would also work but that would introduce extra newlines everywhere, which
is ugly and avoided by copying. Maybe we should add a special --load=...
cli switch just to load additional macros - this isn't the first time
somebody needed that.
2017-09-22 13:26:06 +03:00
Panu Matilainen 7cf3c78678 Create $(prefix)/rpm/macros.d directory on make install
We read it so might as well create it too...
2017-09-22 13:09:30 +03:00
Mark Wielaard ec0d4d80d8 Add debugsource recommends to debuginfo packages.
Debuginfo packages are useful without debugsource files. But it is often
useful to also have the debugsource files. So make debuginfo packages that
don't contain sources recommend the debugsource package (or the main
debuginfo one if the sources are not in a separate debugsource package).

Add Package dbgsrc as argument to filterDebuginfoPackage so it can be
added as recommendation. Add a new function findDebugsourcePackage.
Use it to add a requires to the main debuginfo file and/or the debuginfo
subpackages.

Extend the various rpmbuild.at tests that create debugsource and/or
debuginfo subpackages to check the debugsource (or main debuginfo)
package is recommended.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2017-09-22 08:51:31 +03:00
Mark Wielaard 8a2eed2211 Rename addPackageRequires to addPackageDeps in build/files.
Also add the dependency tag as argument so it can be used to add either
a Requires or Recommends. Adjust the one caller to pass RPMTAG_REQUIRENAME.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2017-09-22 08:51:31 +03:00
Panu Matilainen 4087530f0f Add configuration option for controlling file IO flushing behavior
This is just a slightly simpler alternative to PR #187 with a more generic
name to leave room for future developments. The thing is, flushing out IO
is something rpm should really do always on *some* level, but on rotational
disks doing so on this simple per-file level is so horribly expensive that
it's simply not practical. SSD's are an entirely different story however,
and on some workloads regularly flushing out IO has other benefits (which
is what PR #187 is actually about) even if you dont actually care about the
durability aspects.

Documentation is intentionally left scarce as this is not at a stage
where we'd want to actually advertise it.
2017-09-20 17:06:37 +03:00
Panu Matilainen 5b3781c686 Fix excessive dependencies for elfdeps and sepdebugcrcfix
These only need libelf, debugedit needs libdw and libdwarf too.
Add comments to the endif's to make it easier to parse for us mortals.
2017-09-20 11:24:28 +03:00
Panu Matilainen 404ef011c3 Don't follow symlinks on file creation (CVE-2017-7501)
Open newly created files with O_EXCL to prevent symlink tricks.
When reopening hardlinks for writing the actual content, use append
mode instead. This is compatible with the write-only permissions but
is not destructive in case we got redirected to somebody elses file,
verify the target before actually writing anything.

As these are files with the temporary suffix, errors mean a local
user with sufficient privileges to break the installation of the package
anyway is trying to goof us on purpose, don't bother trying to mend it
(we couldn't fix the hardlink case anyhow) but just bail out.

Based on a patch by Florian Festi.
2017-09-19 14:46:36 +03:00
Panu Matilainen cfa106ee08 Add testcases for unpackaged files and directories detection
Unpackaged files we detect, directories we dont, never have.
2017-09-19 09:39:36 +03:00
Panu Matilainen 90802a894a Fix Ftell() past 2GB on 32bit architectures (RhBug:1492587)
Back in 2011 "somebody" forgot to apply brain when copying the return
type of "long" from ftell() to the Ftell() implementations within rpmio
(commit 61f5838aa8).

Fast-forward six years and suddenly TexLive in Fedora no longer builds
on 32bit architectures due to that thinko, appearing to be a regression
in commit 7d1a303c45. However that only
exposes the inner flaw of Ftell() as the code now relies on values
past the initial header range, for which the 2G of "long" has been more
than enough on 32bit architectures too.

Doh, dude...
2017-09-18 16:28:06 +03:00
Panu Matilainen e3cd2bc85e Avoid multiple strlen() calls on the constant prefix string when searching 2017-09-13 13:05:02 +03:00
Panu Matilainen e760730738 Fix file triggers failing to match on some packages (MgBug:18797)
Directory names as stored in RPMTAG_DIRNAMES are not sorted when
separated from basenames, so binary search has no chance of working.
While a linear search on the dirnames would be guaranteed to find *some*
matches when they exist, it could still miss some results as the
matches are not guaranteed to exist in a neat low-high range.

Construct the entire pathname for prefix comparisons to ensure sorted
paths and adjust the file trigger testcase to cover this too.

Thanks to Pascal Terjan for initial investigations and Thierry
Vignaud for providing a workable reproducer.
2017-09-13 13:01:33 +03:00
Pavlina Moravcova Varekova 4adc4f198c Add documentation for %load macro 2017-09-11 14:23:02 +03:00
Panu Matilainen 7481f0ff15 Always calculate disk space info, only don't report them if filtered
In the distant past when rpm just stat()'ed all mounted filesystems,
it was quite necessary to have the option of disabling the fs stats.
However now that we only stat() filesystems we actually use, the
situation is quite the reverse: if stat() eg hangs, we wouldn't be
able to complete the transaction anyway so it's better to find that
out before the transaction even starts, regardless of problem filters.

Also the filesystem info sets could be used to track other things besides
space, such as suid/sgid availability, selinux and file caps support etc.
2017-09-11 10:32:17 +03:00
Panu Matilainen 9e65d6ee9a Don't sync filesystems unless we actually did something in the transaction
Non-zero transaction members is not a meaningful test for this, as we can
can fail early for several reasons. Only sync if we actually executed
rpmtsProcess().
2017-09-11 10:32:17 +03:00
Panu Matilainen cf4e631283 Inode zero is just a regular inode
Inspired by a similar change in glibc:
https://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=686f2ea18374a541d203cfcc0e1dfba1666f49c2
2017-09-09 09:45:45 +03:00
Michael Schroeder 9809319df2 Allow rpmrichParse to be called with no callback
This is useful if you want to just verify the syntax or find
the end of a rich dependency.
2017-09-07 11:47:25 +02:00
Panu Matilainen eef82b0e81 Less naive version of sync-after-transaction (RhBug:1461765)
If syncfs() is available (ie on Linux), only sync modified filesystems.
In order to do this, keep the diskspace information around throughout
the transaction.

Skip the sync entirely on chroot installations for now, but this
too should be configurable (always/auto/never or so).

There's a bit of a chicken-egg problem with post-transaction plugins:
for example systemd_inhibit should only be released after syncing,
but OTOH some other plugins might be performing actions whose results
should be syncing. Leaving it alone for now.
2017-09-07 12:01:39 +03:00
Panu Matilainen 4bb954086a Fix PYTHONPATH in test-suite when prefix differs from system python (#265)
Prior to this, test-suite PYTHONPATH would be wrong for all but builds
using --prefix equal to system python location, and eg --prefix=/opt
would cause the testsuite to fall back to system rpm bindings instead
of the in-tree one. Ditto for dist-check.
2017-09-06 17:35:36 +03:00
Panu Matilainen 5763f40c21 Enable python build during dist-check
The test-suite fails if python is not enabled. An alternative solution
could be disabling python tests when not enabled, but the python
tests cover things that are not covered elsewhere so especially
for dist cutting the tests are quite important.
2017-09-06 17:33:30 +03:00
Panu Matilainen 8db7862638 Fix false negatives on signature/digest tests inside "make distcheck"
distcheck runs from a read-only source tree so the packages that we
copy around for fuzzing "fuzz" have read-only permisssions and
modifications fail, causing the tests to fail. So instead copy the
to-be-modified packages from inside testing/data where the permissions
are taken care of by commit ecb4182655.
2017-09-06 14:14:20 +03:00
Panu Matilainen b7a869f0f3 Sync disks at the end of transactions (RhBug:1461765)
Bit hysterical that we haven't done this...
On Linux we could call syncfs() for only those filesystems that we
actually touched but somehow I doubt it's worth the trouble.

Another option might be doing this at rpmtxnEnd() but maybe that's
excessive.
2017-09-06 09:14:49 +03:00
Michael Schroeder 37982efbac Add support for 'unless' rich dependencies
An (A unless B) dependency implements (A and not(B)). This kind is useful
for "or" type dependencies, e.g. "Conflicts" or "Supplements".

As "Conflicts: (A unless B)" is equivalent to "Requires: (B if A)", I
thought this type is not needed. But there is no such equivalence
for Supplements, thus the change in mind.

Like with "if" we also have a syntactic sugar "else" flavor:
(A unless B else C) is the same as ((A unless B) or (B and C))

This commit also makes the "else" handling code in depends.c much
easier to understand.
2017-09-06 08:32:45 +03:00
Panu Matilainen a8abf2cfd0 Eliminate the rest of idiotic assert()'s in rpmtd.c
Finish what was started in commit 9c979cffe9,
with greetings to self ten years ago...
2017-09-05 13:13:49 +03:00
Panu Matilainen 80b5c12eaa Use pkg-config for figuring python cflags and libs
Simplifies things a bit and also makes "PYTHON=python3 ./configure" work,
whereas it previously barfed on figuring the library names like
"libpython3.6m"
2017-09-05 12:00:30 +03:00
Panu Matilainen 6d610e9b9a Always execute scriptlet callbacks with owning header (RhBug:1485389)
Triggers and file triggers can and do execute scriptlets from installed
packages which are not part of the current transaction and thus have no
associated transaction element, making the scriptlet callbacks
inconsistent and cumbersome for API users.

Create a fake transaction element for the poor orphan scriptlets lacking
one to make it consistent (of course, creating rpmte's with all their
associated data just to pass a header pointer along is ridiculously
expensive but *shrug*).

Regular triggers used to execute in the context of the triggering
transaction element, make them run with the owning trigger header too.
2017-09-04 17:39:16 +03:00
Panu Matilainen 61aef0f835 Fix %transfiletriggerpostun diagnostic showing "unknown"
The file trigger diagnostics are ambiguous with regular triggers,
but "triggerpostun" is much closer to the mark and easier to
debug than  "unknown".
2017-09-04 11:13:36 +03:00
Panu Matilainen 9b4bcd15a3 Limit "<package> has N files" debug diagnostics to install/erase goals
This was only really meant for install/erase goals, and is not really
meaningful for scriptlet goals which came much later in the history.
2017-09-04 11:11:45 +03:00
Panu Matilainen d6be2e4312 Mark ndb and lmdb experimental in configure too
Nobody reads release notes, better carry the message here...
2017-09-01 14:03:39 +03:00
Panu Matilainen 44570e253d Remove leftover parentheses, no functional change.
Should've been in commit 206c12acc2.
2017-09-01 11:17:48 +03:00
Panu Matilainen 206c12acc2 Don't assume %{quote:...} is surrounded by whitespace
As implemented in commit cdbc7e1d8b,
%{quote:...} only works when its used to quote the entire argument
and produces garbage when used in middle of other text, such as
"x%{quote:y}z". Not sure there's actual need to do that, but producing
garbage is never good.

Only unquoted separators can split an argument, copy argument manually
to strip any quote characters and adjust the math to match. Oh and
add testcases too.

Thanks to Pavlina Moravcova Varekova for pointing this out.
2017-09-01 10:59:21 +03:00
Panu Matilainen 1a08ab7e30 Add documentation for all/most built-in macros
This hasn't seen much love in recent decades, ugh...
2017-08-31 15:15:29 +03:00
Panu Matilainen 58213365e9 Plug what's probably an ancient memleak in build code 2017-08-31 13:25:02 +03:00
Panu Matilainen 0034a5c6e5 Avoid macro expansion on every rpmlog() call + fix a related memleak
Move color config macro expand into a helper function that's only called
once per thread and use enums for the possible states, ints are nicer
to compare than strings. Also remember to free the expansion result to plug
a memleak as well.
2017-08-31 13:25:02 +03:00
Michael Schroeder c69cfdf901 Fix classification of ELF binaries with both setuid/setgid set
There is a ',' between multiple entries.
2017-08-31 12:01:24 +02:00
Panu Matilainen cdbc7e1d8b Support parametric macro argument quoting, take three (#222)
All the nice quote-characters are already spoken for, we need to
do something more special here. Add a special-purpose built-in %{quote:...}
macro which quotes its argument using ASCII unit separator character 0x1f
(so it really shouldn't get into anybodys way) and teach macro argument
splitting to support that.

So with %{quote:...} it's now possible to pass strings containing
whitespace and empty strings as arguments. It might not be pretty, but
it's at least POSSIBLE, and no existing user is bothered by this.
2017-08-31 12:36:32 +03:00
Panu Matilainen 08ed0b20c6 Add a few more parametric macro argument tests 2017-08-31 12:14:36 +03:00