Commit Graph

5110 Commits

Author SHA1 Message Date
Panu Matilainen 7a50e9de80 Dont create redundant %config backups when on-disk content is same as new
- When on-disk %config file contents match the contents of the new
  package (such as config in old package was buggy, fixed in new
  and admin worked around in the meantime) there's no point creating
  a backup that's identical to what you already have. Note that
  we create the new config anyway instead of skipping as timestamp
  might have changed.
- Adjust test-cases to the new saner behavior.
2012-08-20 12:42:36 +03:00
Panu Matilainen 2067c7c0d3 Cosmetics: remove unnecessary line-wrap 2012-08-20 11:20:30 +03:00
Panu Matilainen bfb364563a Dont create %config backups on skipped files
- This cosmetical only, but there's no point creating the same backup
  twice. Depends on commit f7f5f88f9f.
2012-08-20 11:12:05 +03:00
Panu Matilainen f7f5f88f9f Only create the first instance of a file shared between packages
- When packages share an identical file, we only need to create the
  first one we encounter and skip it for the rest (reverse already
  happens, and must happen, on erase). This has the benefit of
  getting the timestamp to match the first file, which often is
  also the last one to get removed. Also when lots of shared files
  are involved (such as in multilib installations), this can give
  several percents worth of speed gain as we dont unnecessarily rewrite
  the same contents over and over.
2012-08-17 14:07:05 +03:00
Panu Matilainen d6b925342f Blargh, more fdFree() braindamage
- Commit 429b933b42 fixes the fd-leak
  regression in rpm 4.10, but we already have code which relies
  on the new behavior and segfaults with the former one. Adjust
  rpmcpioClose() to the old behavior to get master tree back to
  working shape. TODO: fix this properly some rainy day (oh and see
  http://geekandpoke.typepad.com/geekandpoke/2012/08/likelihood.html)
2012-08-17 13:09:19 +03:00
Panu Matilainen 227654f30c Verify files from non-installed packages again (RhBug:826589)
- Verifying files against the originating, non-installed package can
  be useful sometimes, eg if rpmdb is broken or cannot be trusted.
  Of course such verification will give false positives on files that
  were intentionally skipped during installation (nodocs, wrong color,
  netshared...), that can't be helped.
- This restores the former behavior that was erroneously changed
  in commit adbd484372 while "fixing"
  an unhandled enumeration in the switch. Doh.
2012-08-07 12:28:56 +03:00
Panu Matilainen 4fbb58c7e6 Fix RPMPROB_FILTER_FORCERELOCATE aka --badreloc (RhBug:828784)
- As noted (but since then blissfully forgotten) in the commit message,
  commit e696b409fe broke --badreloc
  so its been broken since rpm >= 4.9.x :-/
- Transaction problem filter is only available during rpmtsRun() so
  we have no clue whether bad relocations should be filtered or not
  during rpmte creation. Instead of creating the problems at rpmteNew()
  time, remember any bad relocations that were found and check +
  create the actual problems (unless filtered) along with other
  problems during rpmtsRun().
- Passing an "allow bad relocations" flag to rpmtsAddInstallElement()
  would be a saner option but this is a back-portable way of handling it.
2012-08-07 09:52:15 +03:00
Panu Matilainen ecd9aceb56 Honor RPMSENSE_MISSINGOK flag in dependency checking
- For now there's no way to set this flag from packages so it doesn't
  actually do anything, but it doesn't hurt anything either, allows
  Suse & friends to drop one patch (greetings Michael :) and there
  are might be some things we could use this for internally.
2012-08-03 12:43:59 +03:00
Panu Matilainen 928386a317 Report config and missinok flags in deptype format extension too 2012-07-11 15:10:08 +03:00
Panu Matilainen 32a4e283a6 Recognize relative paths as such in --whatprovides query 2012-07-03 08:51:09 +03:00
Panu Matilainen 338f6e4cf7 Push payload file size limit checking into cpio code
- At the time when the file list is being processed, we dont yet
  have the slightest clue what kind of payload will be used for
  for the archive or what limits it might have. Let the cpio code
  handle its own limits checking, the build-side only needs to
  worry about whether 32bit uints are sufficient for storing the
  sizes in headers.
2012-07-02 17:11:00 +03:00
Panu Matilainen eefcb12b9c Cosmetics: remove redundant {} block, fixup indentation 2012-07-02 15:05:30 +03:00
Panu Matilainen bf3a14a866 Dont use mmap() for anything, axe the code instead
- Commit 4cb02aa928 asked to see
  what breaks when mmap() is used, now we know: large package support
  broke when enabling it. Could be fixed of course by eg adding
  a size cap to the fsm part as well, but just doesn't seem worth it:
  I fail to measure any meaningful performance improvement from mmap
  usage in either case, and added complexity for what is close to
  zero benefit just doesn't make sense... and various sources in fact
  note the rpm usage (read through the entire file sequentially) as one
  of the cases where mmap() is NOT beneficial due to mmap() high
  setup + teardown cost + page fault speed (or lack of thereof).
2012-07-02 15:02:11 +03:00
Phil Knirsch a7248ac1c9 Plain 32bit ppc cannot be a ppc64p7
Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
2012-06-28 10:15:59 +03:00
Panu Matilainen 3ffaef5afc Clarify/correct tag usage in rpmdbProvides()
- Refer to RPMTAG_* for rpmds tags, not RPMDBI_*. The values for these
  are the same, only the "intended use" differs (RPMDBI refers to
  rpmdb indexes) so this doesn't change anything in practise.
2012-06-27 11:10:57 +03:00
Panu Matilainen 2cb102f35e Fix obsoletes-thinko in rpmdbProvides()
- dbtag cannot possibly be on obsoletes here, we need to look at deptag
  instead. This thinko in commit 5f1ec21518
  renders that whole commit useless. Doh.
2012-06-27 11:08:25 +03:00
Panu Matilainen 7c8c36c334 Fall back to using fsync() on systems without fdatasync()
- While fdatasync() is widely available on modernish systems,
  OS X doesn't have it
2012-06-21 09:45:16 +03:00
Panu Matilainen 50b03d015e Restore basic debug output for fsm operations
- This is close to what we had in the stage-machine days, just to allow
  easily viewing whats going on inside the fsm (create/skip/etc)
2012-05-21 13:34:03 +03:00
Panu Matilainen 8d277bbba6 Explicitly differentate internal/exported file attributes
- RPMFILE_EXCLUDE only exists during spec parse, and doesn't "leak"
  into headers only because the file is, well, excluded to start with.
  Unexport the internal-only bit and explicitly strip out any excess
  bits from data going to header. The current 16/16 split is artificial
  of course, RPMTAG_FILEATTRS is 32bit so there's plenty of room
  for growing new file attributes, with internal-only adjustments
  required.
- Eliminate RPMFILE_UNPATCHED while at it, this is a leftover
  from Suse patch rpms which are no longer used anywhere.
2012-05-16 10:58:00 +03:00
Michael Schroeder bb335292d3 Small patch to reverse hardlink ordering
Hi Panu et al,

Here's a small patch that changes the ordering used for putting
hardlinked files into the cpio archive back to lexicographical.

You might wonder what this is about. Well, old rpm-3 (and
also old versions of rpm-4, I think) already used lexicographical
ordering for files and hardlinks. When deltarpm was created,
it made use of this fact when "compressing" the file order
of the cpio archive into the so-called "sequence". Deltarpm
can deal with "out of order" files, but in that case it needs
to reset the compression, which leads to really long sequence
strings.

Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
2012-05-04 09:04:46 +03:00
Panu Matilainen 58c5eb28d5 Fall back to private db environment on system level EINVAL
- BDB wants to use mmap() for its environment by default, but not
  all (file)systems support this, as pointed out by Daniel Drak.
  However env->open() can return EINVAL for a number of reasons,
  require all the fallback reasons to be system level errors to
  differentiate from "logical" errors such as incompatible flags
  to (possibly pre-existing) db environment, in which case we better
  just error out.
2012-05-03 16:37:51 +03:00
Panu Matilainen d337924930 Eliminate rpmts usage from lower levels of fsm machinery
- The only remaining use for rpmts here was grabbing NODIGESTS
  from rpmtsFlags(). Pass the tiny little piece of information
  as an argument for the one place needing it and rip all the
  now unused related goo.
2012-04-24 15:52:41 +03:00
Panu Matilainen bf4b423fdf Only install needs selabel handle, dont bother elsewhere 2012-04-24 15:45:24 +03:00
Panu Matilainen 2eb24dcc20 Dont bother with fsm-level digest statistics
- Most of fsm doesnt need the actual transaction set for anything "real"
  and dragging it around as a mere statistics collector seems
  pretty dumb. If we want better statistics, we better come up with
  a saner way to gather them.
2012-04-24 15:36:15 +03:00
Panu Matilainen 4320b81251 Eliminate rpmts and rpmte kludgery from package building
- Package building has no associated transaction or ts members,
  this was all just fake-up kludgery to work around the way how
  fsm used to work. None of it relevant now, kill kill kill.
2012-04-24 14:28:03 +03:00
Panu Matilainen 2d563cefee Eliminate rpmte usage from lower levels of fsm machinery
- Determine the need for reverse iteration based on fsm goal
- Everything else was just using rpmte to get to its file states,
  eliminate the intermediate ping-pong by passign the file states
  around directly. Makes the thing that little bit less silly.
2012-04-24 14:16:21 +03:00
Panu Matilainen 7789f46e4c Move mode-specific flag setting out of fsmNew() 2012-04-24 14:01:46 +03:00
Panu Matilainen dc71b7ef15 Clean up file backup logic a bit
- Ghosts are never backed up, and the whole business is irrelevant
  for package building. Use fsm goal instead of rpmte mode to
  determine what to do, rpmte in build code is nothing but an ugly hack.
2012-04-24 13:48:11 +03:00
Panu Matilainen 015a34e0df Eliminate header and rpmte knowledge from rpmfs
- rpmfs is such a low-level construct it doesn't need to know anything
  about the upper layers. Gather the necessary bits of info in the
  sole caller instead and pass only whats needed to rpmfsNew() to
  enable creating a filestate item without having rpmte/header at hand,
  which we'll be needing in the fsm shortly.
2012-04-24 13:36:38 +03:00
Panu Matilainen 9f4186766c Bury build filestate setting inside fsm remains
- This whole thing probably isn't needed anymore, but for now just
  lift the FA_SKIP/FA_COPYOUT setting to rpmPackageFilesArchive(),
  allowing rpmfsSetAction() to become properly internal-only function.
- Trim out unnecessary now unnecessary librpm internal includes
  from librpmbuild code
2012-04-24 12:43:54 +03:00
Panu Matilainen 5dd61799ee Split out file state recording out of fsmMapPath()
- The file state that gets stored in the rpmdb has nothing to do with
  path and is only relevant for installs.
2012-04-24 11:55:37 +03:00
Michael Schroeder db28221a4a Add support for dpkg-style sorting of tilde in version/release
- This allows much nicer handling some common scenarios such as
  upstream pre-releases where the pre-release version would normally
  appear newer than final release, eg 1.0-rc1 vs 1.0. Previously this
  required mapping the pre-release tag into the release tag to achieve
  desired sorting, with tild this becomes simply 1.0~rc1 < 1.0.
- Add a rpmlib() tracking dependency to prevent older rpm versions
  from getting confused with packages relying on the new behavior.

Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
2012-04-23 11:04:02 +03:00
Panu Matilainen 5f1ec21518 rpmdsMatchesDep() isn't correct on obsoletes
- Fix oversight in commit 9fb81eac0bcd239e46459f72916099f1adfc5cb9:
  rpmdsMatchesDep() works on provides, but obsoletes are matched on
  package name so we want rpmdsNVRMatchesDep(). rpmdsMatchesDep()
  "worked" as the implicit self-provide is always at the 0 index
  on packages created by modern rpmbuild, but this isn't really
  guaranteed: very old V3 rpms can have something else at the
  first index, and ditto for non-rpmbuild created packages.
- Thanks to Michael Schroeder for pointing this out.
2012-04-20 09:31:17 +03:00
Panu Matilainen b45294ba68 Pay attention to NULL returns from rpmcpioOpen()
- The archive interface might actually want separate new + open,
  but for now just flag an internal error on NULL return on archive open.
2012-04-18 12:48:58 +03:00
Panu Matilainen 00db04cf2c Sanitize fsm creation/initialization and destruction
- Now that there are no more failing parts requiring return codes,
  change + rename fsmSetup() into a more regular fsmNew() construct,
  returning newly "instance" of fsm and similarly fsmTeardown() ->
  fsmFree() to free the thing.
- There's no real need to allocate this stuff on heap, but doing
  so makes life actually simpler for the three callers and makes the
  whole thing more consistent with common practises in the codebase.
2012-04-18 12:39:25 +03:00
Panu Matilainen df92175300 Split out hardlink checking from fsmTeardown()
- Checking missing links is only relevant for install, lift the
  code to separate function and call from the install-case only.
- Freeing data while checking seems like a dubious "optimization"
  but to keep changes minimal, leaving that as it is now.
2012-04-18 12:27:28 +03:00
Panu Matilainen de92cb7a43 Eliminate unused leftover rc member from fsm struct 2012-04-18 12:09:06 +03:00
Panu Matilainen 6e1b834928 Move cpio end trailer detection to the cpio code
- The fsm shouldn't know any archive format specifics, detect the trailer
  from rpmcpioHeaderRead() and signal EOF through CPIOERR_HDR_TRAILER
  instead.
2012-04-18 11:38:29 +03:00
Panu Matilainen 3c2be9072d Separate payload archive close and free
- When writing, archive finalization can write further data into
  the payload (eg cpio trailer). We need to be able to fish the
  final archive size *after* closing it, otherwise archive size
  will be off by trailer size.
- Add new rpmcpioFree() function which simpy frees the archive struct,
  calling rpmcpioClose() in the process if it wasn't already done.
- This also simplifies the error code gymnastics in fsm: we need to
  free the resources whether error or not, which rpmcpioFree() allows
  us to do. And for writers, calling rpmcpioClose() only needs to
  be done if earlier parts were successfull, so we dont need to worry
  about masking a former error code when calling it.
2012-04-18 10:30:11 +03:00
Panu Matilainen 6cb8e8b2ef Eliminate payload archive member from fsm struct
- Only install and build have an associated archive, and this can
  be just as well handled as a local variable, passing down as
  argument to the handful of places needing it.
- Error handling looks a bit fishy but that's not exactly new issue...
2012-04-17 20:10:10 +03:00
Panu Matilainen 189dec7ba9 Push fsm archive size down to the only caller who cares
- Archive size is only relevant for build code, no need for tracking
  this in the big struct. Just return the archiveSize at end of
  build process.
2012-04-17 19:18:28 +03:00
Panu Matilainen 00629aa636 Lose unnecessary cfd member from fsm, refcount through payload instead 2012-04-17 18:03:29 +03:00
Panu Matilainen f1d24281f5 Kill couple of useless "helper" functions
- Both are only ever called once and are so trivial that they're
  not helping anything at all
2012-04-17 17:36:47 +03:00
Panu Matilainen fa483f1762 Remove now unused psm argument to fsmSetup()
- Bah, should've been in commit 4ef540d25b
2012-04-17 17:21:02 +03:00
Panu Matilainen 28dc2eadfa Move mapping index + and related loop exits out of fsmInit()
- The mapping index is the same for build + erase, but different
  for install and so is the return code mapping. By doing this
  inline where the action is we avoid having to fiddle with
  mapped return codes for the exit case.
2012-04-17 17:08:49 +03:00
Panu Matilainen d852a56e17 Move the install-only payload reading to the install-only code
- Besides simplifying the common path everything takes, this removes
  the need to map error returns back and forth when we can just
  detect the end of payload directly in the loop and break out.
2012-04-17 16:55:46 +03:00
Panu Matilainen 9e73ca9fcc Split fsm state reset to a separate function
- No functional changes as such, but moving this out of fsmInit()
  permits other goal-specific items to be moved out of fsmInit()
2012-04-17 16:40:54 +03:00
Panu Matilainen 124db72a60 Zeroing out the fsm is common to all modes, move it to fsmSetup() 2012-04-17 16:30:43 +03:00
Panu Matilainen 380e19c62d Push dnl iterator init + free to the sole caller fsmMkdirs()
- There's zero need for the rest of the code to know or care about
  dnl iterator, just pass the file info- and state sets to
  fsmMkdirs() directly and hide the otherwise unused iterator
  business there.
2012-04-17 16:27:27 +03:00
Panu Matilainen 4cb9109d31 Inline what little is left of fsmCreate() into fsmSetup()
- Besides being a bizarre name for "some extra initialization" work,
  fsmCreate() was full of redundant goo, including a rather complex
  way of mapping a zero return back to zero in case it really was
  zero .. or something.
2012-04-17 16:15:33 +03:00
Panu Matilainen 577751c450 Move temporary install suffix creation to more logical place
- Only installation needs, so move it to rpmPackageFilesInstall()
2012-04-17 16:01:52 +03:00
Panu Matilainen 06badfc76e Move unowned directory creation to more logical place
- rpmPackageFilesInstall() is the only case where this needs to occur,
  move it there instead of yet-another goal-dependent piece where it has
  no business being in the strangely named fsmCreate()...
2012-04-17 15:47:20 +03:00
Panu Matilainen 5b40273785 Eliminate the pointless fsm NULL checking in fsmFsPath()
- There's just no damn way fsm can be NULL when this is called,
  a NULL fsm would've segfaulted miles earlier.
2012-04-17 15:40:00 +03:00
Panu Matilainen 17ae5675f2 Eliminate unused subdir argument from fsmFsPath() 2012-04-17 15:36:41 +03:00
Panu Matilainen f108c23176 fsmFsPath() only needs directory/something else not entire struct stat
- The less places we pass all the junk around, the easier its to
  follow, and in most places we already know whether its dir or not anyway.
2012-04-17 15:36:36 +03:00
Panu Matilainen 4ef540d25b Remove now unnecessary psm member from fsm struct
- Except for expandRegular(), all notification occurs from the three
  main worker functions. Pass as an argument for the lone special
  case, the other noticy already have the psm as their own argument.
2012-04-17 13:28:55 +03:00
Panu Matilainen fb51698e0c Remove redundant progress notification from fsmCommit()
- fsmCommit() does not advance the archive or anything else, so
  this was simply issuing the same exact notification that we
  just did from rpmPackageFilesInstall().
2012-04-17 13:25:59 +03:00
Panu Matilainen 05bde170d7 Clean up + improve file/directory removal error handling
- Only handle %missingok in the cases where it actually applies,
  and additionally handle missing %ghost which is not an error
  either. Dont log anything for these non-errors.
- Unify the error handling for files and directories, makes life
  simpler as they dont differ by that much.
- Log real failures as warnings instead of silencing them to debug
  spew, users will want to know if something that was supposed to
  be removed was not (say, a file with immutable attr set).
- Add comments for further work on this area.
2012-04-17 12:40:41 +03:00
Panu Matilainen a4d25c7ab2 Minimally fix file/directory removal
- In their previous life these breaks applied to a switch-case but
  now they end up aborting the loop on first successful removal, causing
  everything but the first file/directory of a package to be left behind
  on erase. Fixes the previously unnoticed regression from commit
  1845c1d711.
2012-04-17 11:04:22 +03:00
Phil Knirsch f9eedd7f69 - Add support for ppc64p7 architecture using new auxv parsing info
Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
2012-04-17 09:26:03 +03:00
Phil Knirsch 280494cce0 - Add general /proc/self/auxv parsing to rpmrc for better machine detection
Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
2012-04-17 09:25:53 +03:00
Panu Matilainen f5fdd5f9ca Axe unused leftover variable
- Should've been in commit cf10956481
2012-04-16 15:52:53 +03:00
Panu Matilainen 8e4c7a5615 Raise file conflicts on differing device node numbers
- For practical purposes, the "content" of a device node is its
  minor+major number, if those differ the files are very much
  not the same and thus cannot be shared.
2012-04-13 13:38:20 +03:00
Panu Matilainen cf10956481 Raise file conflicts on differing permissions (user, group, mode)
- Two files (or directories) cannot be correctly shared if their
  permissions differ, even if the content is identical: either
  file will end up having wrong permissions, depending on installation
  order. This means a package can among other things silently
  eg relax permissions of eg security sensitive directory (accidentally
  or intentionallY).
- We now require exact match of user, group and entire file mode
  (previously only the file type part of mode was tested)
2012-04-13 13:31:26 +03:00
Panu Matilainen 48c4ed1148 Check for file conflicts within package (RhBug:808750)
- Packages having file conflicts with itself may seem absurd, but
  directory symlinks (such as /lib being a symlink to /usr/lib)
  make this entirely possible. This makes us catch and abort early
  on these cases instead of silently overwriting the self-conflicting
  files, potentially with disastrous results.
2012-04-12 18:01:52 +03:00
Panu Matilainen a13e56cd87 Check for file conflicts within package (RhBug:808750)
- Packages having file conflicts with itself may seem absurd, but
  directory symlinks (such as /lib being a symlink to /usr/lib)
  make this entirely possible. This makes us catch and abort early
  on these cases instead of silently overwriting the self-conflicting
  files, potentially with disastrous results.
2012-04-12 17:54:08 +03:00
Panu Matilainen 7633410733 Change file disposition code to access rpmfi's by index
- The final pre-requisite to handling file conflicts within a package:
  with this we're no longer tied to the single index per rpmfi. This
  is not supposed to change anything yet unless I screwed something up.
  Also goes to show that a semi-iterator interface for something
  that really needs random access only gets in the way rather than
  helping...
2012-04-12 17:50:54 +03:00
Panu Matilainen 87e7e88f90 Change rpmfi replaced size functions to take index
- Further preliminaries to handle file conflicts within a package.
- These are internal-only interfaces so we can just change without
  bothering with compat wrappers.
2012-04-12 17:39:57 +03:00
Panu Matilainen 3f996a588a Add rpmfiFooIndex() variants for the conflict handling methods
- Preliminaries for handling file conflicts within a package:
  Using rpmfi's self-iterator limits access to the file info to
  one caller at a time, in order to self-file conflicts we'll need
  to be able to access the same rpmfi at different indexes simultaneously.
- As these are public API's, add compat wrappers for the self-iterator
  use (although AFAIK nothing except rpm itself uses these)
2012-04-12 17:39:32 +03:00
Panu Matilainen fbe424f202 Further tweak the config file removal/backup logic to make it clearer
- Turn the strange negated condition around: when dealing with
  config files test for it directly. This way, all the special
  cases are handled first and normal cases fall through the if-jungle
  to exactly one case of rpmfsSetAction(fs, i, FA_ERASE). Makes
  the logic more obvious, at least to me.
2012-04-12 17:27:24 +03:00
Panu Matilainen b013a139d2 Avoid unnecessary calls to rpmfiFN()
- handleOverlappedFiles() only needs the file name in a couple
  of relatively rare special cases. Constructing the fn more
  expensive than other rpmfi-calls, dont bother unless actually needed.
2012-04-12 17:00:33 +03:00
Panu Matilainen a359292046 Make config file modification detection a bit more readable 2012-04-12 16:28:43 +03:00
Panu Matilainen 11116a6786 Make rpmfiFNIndex() safe for callers on different indexes
- Previously this would return a pointer to an internal per-rpmfi buffer
  whose contents get silently overwritten on each call to rpmfiFNIndex(),
  making it unsafe for unsafe for random access for more than one
  active caller (such code does not currently exist in rpm though)
- Make rpmfiFNIndex() always return freshly allocated memory, and adjust
  the rpmfiFN() iteration wrapper to free and realloc the internal
  "buffer" on each call. It's a wee bit slower than before but it's
  not called *that* much, and if needed there are ways to optimize it.
2012-04-12 15:29:18 +03:00
Panu Matilainen 8106e7e89c Handle obsolete matches (more) correctly in rpmal
- Similar to commit 9fb81eac0b but
  on the to-be-installed set: obsoletes should only be matched against
  package names, not any provide or file names. Hasn't really mattered
  previously due to the way its called, but since commit
  05487d9a3f I guess it started to matter.
  It's more correct this way anyhow, and should fix RhBug:810077.
- Since rpmal only knows about provides, we need to handle obsoletes
  as a special case and filter out matches on provide names different
  than the matching package name.
2012-04-05 11:43:58 +03:00
Panu Matilainen b9c96a9fa9 Remove unused scareFlags member from rpmfi struct
- This is just a leftover from rpm < 4.7.x days
2012-04-04 17:30:04 +03:00
Panu Matilainen 6fc6b45bf9 Validate negated offsets too in headerVerifyInfo()
- Undo the ancient broken fix for RhBug:71996 from commit
  9e06e3b8ca76ae55eaf2c4e37ba9cac729789014: instead of disabling
  the check, pass in the correct upper range which is entirely
  different from everything else for the region trailer tag.
- Fixes CVE-2012-0815
2012-04-03 15:47:44 +03:00
Panu Matilainen f239982519 Differentiate between non-existent and invalid region tag
- Non-existent region tag is very different from existing but invalid
  one - the former is not an error but the latter one is, and needs
  to be handled as such. Previously an invalid region tag would cause
  us to treat it like rpm v3 package on entry, skipping all the region
  sanity checks and then crashing and burning later on when the immutable
  tag is fetched.
- Refer to REGION_TAG_TYPE instead of RPM_BIN_TYPE wrt the expected
  type of region tag for consistency and clarity, they are the same
  exact thing though.
- Should unify these damn copy-slop check one of these days, sigh...
  For now, settling for the easily backportable approach.
- Fixes the other half of CVE-2012-0060
2012-04-03 15:46:42 +03:00
Panu Matilainen e4eab2bc6d Specifically validate region tag on header import
- Region tags need to have very specific content, the generic
  header tag checks are not sufficient to ensure sanity. Verify
  the tag is one of the known region tags and that the entry has
  expected type and count.
- Fixes the first half of CVE-2012-0060
2012-04-03 15:45:46 +03:00
Florian Festi b4486175f3 Move internal stuff from fsm.h to fsm.c
Reduce fileStage to the three "goal" stages
2012-03-30 15:00:41 +02:00
Florian Festi 84867c8784 Replace fileStageString() with the __func__ macros in the debugging code
Remove fileStageString()
2012-03-30 15:00:41 +02:00
Florian Festi 9c342e4ce7 Remove checks for FSM_SYSCALL as FSM_* is going to go away 2012-03-30 15:00:41 +02:00
Florian Festi b65397f6c5 Drop no longer needed include of fsm.h 2012-03-30 15:00:41 +02:00
Florian Festi 14d1139bc5 Kill FSM: Remove remains 2012-03-30 15:00:41 +02:00
Florian Festi d951812386 Kill FSM: Make FSM_PKGBUILD a function 2012-03-30 15:00:41 +02:00
Florian Festi c5282fc60d Kill FSM: Make FSM_PKGERASE a function 2012-03-30 15:00:41 +02:00
Florian Festi bd60c4285f Kill FSM: Make FSM_PKGINSTALL a function 2012-03-30 15:00:41 +02:00
Florian Festi 800c60ea10 Prepare for killing the fsm: Move initial call to FSM from fsmSetup to rpmfsmRun. Make fsm FSM_t. 2012-03-30 15:00:41 +02:00
Florian Festi 8cd9750313 Prepare for killing the fsm: Inline FSM_UNDO; Remove FSM_UNDO calls were fsm->postpone is set and FSM_UNDO doesn't do anything. 2012-03-30 15:00:41 +02:00
Florian Festi a78d648c24 Prepare for killing the fsm: Inline remaining FSM_PROCESS code in FSM_PKGINSTALL 2012-03-30 15:00:40 +02:00
Florian Festi 80419742e6 Prepare for killing the fsm: Remove superfluous check for being in FSM_PROCESS to allow killing FSM_PROCESS. fsmVerify is only called while being in FSM_PROCESS. 2012-03-30 15:00:40 +02:00
Florian Festi a6479a8e47 Prepare for killing the fsm: Make FSM_COMMIT a function 2012-03-30 15:00:40 +02:00
Florian Festi 9b96ed08cc Prepare for killing the fsm: Move build code from PSM_PROCESS to FSM_PKGBUILD 2012-03-30 15:00:40 +02:00
Florian Festi 1845c1d711 Prepare for killing the fsm: Move code for erasing files from FSM_COMMIT to FSM_ERASE 2012-03-30 15:00:40 +02:00
Florian Festi ff4f110306 Prepare for killing the fsm: Inline FSM_DESTROY in fsmTeardown() 2012-03-30 15:00:40 +02:00
Florian Festi 9de132d9e5 Prepare for killing the fsm: Inline FSM_FINI code.
Move cleaning the stat_s structs to fsmInit() (beginning of the loop instead of the end)
Drop freeing fsm->path as this is done in fsmInit() and fsmTeardown()
2012-03-30 15:00:40 +02:00
Florian Festi c362272343 Prepare for killing the fsm: Inline the FSM_NOTIFY code 2012-03-30 15:00:40 +02:00
Ales Kozumplik b714dcea37 rpmbuild: warn if header color differs from color of the package architecture.
- For example, warn when building an x86_64 package that only contains 32
  bit binaries.
- This should indicate to the maintainers that they might have gotten the
  architecture wrong.
- Introduces 'archcolor' in rpmrc so we can map architectures to colors.
- Related: RhBug:713323
2012-03-30 13:55:03 +02:00
Florian Festi cc1e2328c1 Inline FSM_NEXT 2012-03-27 14:34:30 +02:00
Florian Festi c8d34d9deb Remove left over debugging code 2012-03-27 14:32:52 +02:00
Florian Festi 75073ae2a4 Move fsm_s to fsm.c and remove fsmNext() from fsm.h 2012-03-27 14:12:42 +02:00
Florian Festi 7c37d52941 Remove Fseek() code from rpmcpioHeaderRead for now
Fseek() does not return a proper error code. This needs to be fixed before we can use it as most comprssed files do not support seeking and we need to be able to detect this reliably
2012-03-27 14:12:42 +02:00
Florian Festi 6492aa800f Untangle lib/fsm.c and lib/cpio.c
Create cpio_t data type that holds the underlaying FD_t instance
Move padding and position handling and trailer generation into cpio.c
Use only one buffer in the fsm (merging the read and write buffer)
Replace the FSM_EAT, FSM_POS, FSM_PAD, FSM_DREAD, FSM_DWRITE states with cpio functions
Prepend "rpm" to the cpio function names
2012-03-27 14:12:42 +02:00
Panu Matilainen dd05fdd35f Dont bother building internal versions of db utilities we dont need
- rpmdb_dump, load, recover, verify, stat etc are useful at times,
  but these are not. This also fixes build with internal db for
  more recent versions of Berkeley DB.
2012-03-26 13:03:03 +03:00
Panu Matilainen 0b8c321802 Eliminate broken data end calculation in dataLength()
- If the caller doesn't know the end pointer, we dont have a whole lot
  of chance to come up with a reasonable one either. Just assume
  the terminating \0's are there when end boundary is not specified:
  when this happens we're dealing with relatively "trusted" data
  anyway, the more critical case of reading in unknown headers does
  always pass end pointers.
- While capping the end pointer to HEADER_DATA_MAX seems like a
  reasonable thing to do (as was done in commit
  f79909d04e), it doesn't really help
  (bad data would likely run past bounds anyway), and it's not right
  either: the pointer can be to a stack address, and the stack can be
  near the top of addressable range, and ptr + HEADER_DATA_MAX can
  cause pointer wraparound. Notably that's exactly what happens
  when running 32bit personality process on 64bit system on Linux,
  at least in case of i386 process on x86_64, causing all sorts of
  breakage..
2012-03-23 14:36:34 +02:00
Panu Matilainen 2f20f6e6b2 Transaction element file info can be legally NULL in some cases
- rpmteClose() will wipe out the file info to free memory, we only
  should care whether we failed to (re)load the file info. This
  thinko in commit 06a2f1269b
  broke %posttrans scriptlets (and without commit
  274dbf557d, %pretrans in other
  circumstances), whoopsie *blush*. Now, off to write a test-case
  for our scriptlet behavior...
2012-03-21 09:07:21 +02:00
Panu Matilainen 274dbf557d Don't free up file info sets on transaction test-runs, take II
- Despite commit cef18c9480, we'd still
  end up freeing the file info sets via rpmteClose() while going
  through the test-transaction packages. This together with commit
  06a2f1269b caused install failures
  on packages which have %pretrans scriptlets, if a test-transaction
  was first performed on the same transaction set that gets used
  for the "real" transaction as well. How wonderfully obscure...
2012-03-20 16:32:54 +02:00
Panu Matilainen ac5e6cd521 Bump library sonames in preparation for new release
- This is stupid... only librpm and librpmio actually need the bump due
  to ABI breakage, librpmbuild and librpmsign are unchanged and could
  use just a revision bump. But just incrementing the revision (or age)
  would set us on collision course with maintenance updates to 4.9.x.
  Then again its not like you can actually use librpmbuild or librpmsign
  without also linking to librpm(io) so from everything needs rebuilding
  anyway. This all also pretty much makes the whole libtool library
  versioning a bit moot. Bah.
2012-03-20 09:56:30 +02:00
Panu Matilainen 05487d9a3f Look up obsoletes both ways on dependency checking (RhBug:804069)
- "pure install" like 'rpm -i' never removes anything (long-standing
  behavior that we dont want to change), but that causes us to allow
  installing obsoleting packages without removing what they obsolete,
  which in turn causes errors on verify. Not good.
- This (together with commit 9fb81eac0b)
  makes obsoletes behave like conflicts in such a case, preventing
  the inconsistency from taking place. Also verify will now whine
  on all the involved packages on inconsistencies.
2012-03-19 17:05:52 +02:00
Panu Matilainen 9fb81eac0b Handle obsoletes (more) correctly in rpmdbProvides()
- Obsoletes should only be matched against package names, not provides,
  or file names for that matter. This hasn't really mattered so far
  due to the way rpmdbProvides() gets called currently, but there's
  a missing case that requires this...
2012-03-19 16:51:11 +02:00
Panu Matilainen 9a15e18a63 Include more package information in the progress output
- For non-hashed mode, dump the full NEVRA string. This might break
  programs that are parsing the --percent format, but such programs
  almost certainly need adjusting for the added erasure progress anyway.
- For hashed mode, show package NEVR instead of just name. Otherwise
  somebody will sooner or later file a bug on "confusing output"
  as it might seem it's removing what it just installed in upgrade-mode.
  Full NEVRA would be better still but screen estate is tight as it is...
- Also get rid of headerFormat() call here, use RPMTAG_NEVR(A) extensions
  instead.
2012-03-19 08:53:24 +02:00
Panu Matilainen 0d3d3d83f1 Make a bit more room for names in progress output (cosmetics) 2012-03-19 08:21:17 +02:00
Panu Matilainen dec729bc3a Eliminate rpmSetTable() from the API
- Presumably the rpmrc internals still need the magic table tennis
  but nobody else should want to mess with this, reconfiguration
  for another (build) arch is done through rpmReadConfigFiles().
2012-03-09 13:13:25 +02:00
Panu Matilainen c345cb28e1 Whoops, dont make install progress callbacks on erasure 2012-03-08 15:12:33 +02:00
Panu Matilainen 0232714ae5 Only consider rpmdb growth for added packages
- Blargh, dumb thinko in previous commit: removed packages wont
  necessarily decrease the rpmdb size, but they dont increase it
  either.
2012-02-28 15:22:32 +02:00
Panu Matilainen 96e0472301 Fix invalid memory access from rpmdb growth estimation (RhBug:766260)
- The dsi retrieved from rpmtsDbDSI() would become invalid whenever
  ts->dsi structure got realloced, ie anytime when disk space is
  calculated for a different fs than where the rpmdb resides. This
  is likely to be the real issue behind RhBug:766260 and also RhBug:671056.
  Just call rpmtsUpdateDSI() directly with suitable arguments for the
  rpmdb to avoid the special (re)alloc paths.
- In addition, consider the db growth for packages with no files too.
2012-02-28 14:53:29 +02:00
Panu Matilainen 4e207bfdfc Unbreak rpm -V output (RhBug:797964)
- Commit ac0ab016a5 unintentionally
  changed the order of the problems shown in verify strings due to
  a dumb oversight (greetings to self, duh). In other words, this
  fixes a verify output regression in rpm >= 4.9.x by restoring
  the long-standing (and documented) order of the verify output chars.
- Also fix the testcase which unfortunately was only added after
  the output-changing commit so it didn't catch the breakage either :-/
2012-02-28 10:36:10 +02:00
Panu Matilainen 97e72eaaea Test for file data tag sanity in fnTag() extensions
- Basename and dirindex counts must be equal, dirnames count must be
  larger than zero and no larger than number of basenames. Check
  that directory indexes are within range. Additionally file states
  array size, if used, must equal to the genaral file count.
2012-02-21 16:24:18 +02:00
Panu Matilainen e3fdb8a45a Fix crash on INSTFILENAMES extension on non-installed package
- Packages with no RPMTAG_FILESTATES cannot have installed files
  from our POV, just exit early in that case.
- Rerrange the exit path a bit and only call rpmtdFreeData() on
  file states if the corresponding headerGet() call was actually
  made. Wont make any difference yet, but once we have other jumps
  to exit it will.
2012-02-21 15:59:34 +02:00
Panu Matilainen fced9ab012 Sanitize filename tag extension handling
- Rename rpmfiBuildFNames() to fnTag() and push all the td manipulation
  there, making all the various different fn-related tags differ by
  just the arguments to fnTag() and allowing central error etc
  handling. No functional changes (yet) though.
2012-02-21 14:42:20 +02:00
Panu Matilainen d6a3d78a08 Flag error in tag container for non-extension tag retrieval
- This should mostly be a can't happen case, but at least in theory
  region retrieval could fail. So could unknown data type, but a header
  with unknown data types shouldn't even load... Anyway, there could
  be further error cases we might be able to flag here.
2012-02-21 14:14:09 +02:00
Panu Matilainen c172696ea0 Add error indicator flag for tag data containers
- Tag retrieval can in some cases fail, especially so for tag
  extensions. The headerGet() interface doesn't directly allow
  distinguishing between non-existent tag and existent but invalid,
  but we can sneak in that information through in the tag data flags.
2012-02-21 13:52:18 +02:00
Panu Matilainen b922b4392f Add getter for rpmtd flags
- While these are mostly of rpmtd-internal interest only, there are
  cases when caller might want to know...
2012-02-21 13:50:34 +02:00
Panu Matilainen 7a9a550566 Remap inode numbers to fit into 32bit integer space on build (RhBug:714678)
- 64bit inode numbers lose their uniquity when brutally truncated
  to 32bit integers as we've done so far. This can and will cause rpm
  (and cpio) to mix up arbitrary file entries as hardlinks and vice versa.
- As the only interesting aspect of inode numbers is whether they're
  equal to something else or not, we dont have to carry the "physical"
  on-disk value to preserve semantics. So we can just remap the
  inode numbers to something that fits our 32bit integer tags
  without causing compatibility complexies with older rpms and
  cpio (and since we can't handle more than INT32_MAX files in a package
  anyway, breaking compatibility for this would be just braindead dumb).
  An extremely simple way to achieve this is to use our
  build-time file list index as the basis of stored inode number.
- In theory this breaks inode-device pairing, but as the buildroot
  cannot span across filesystems in any remotely normal conditions,
  just add a sanity check to catch the dirty tricksters...
- Based on a patch by Zdenek Pavlas, just further simplified and
  buildroot fs boundary sanity check added.
2012-02-10 10:40:45 +02:00
Panu Matilainen f258e6089a Add tag extension to calculate hardlink count for files 2012-02-08 15:40:02 +02:00
Panu Matilainen c25894e3b9 Honor RPMTRANS_FLAG_TEST in rpmtsImportPubkey() 2012-02-03 12:23:31 +02:00
Panu Matilainen 120fd698c3 Remove the arbitrary limitation on transaction keyring change
- There are some situations where switching keyrings might be wanted,
  especially as long as we dont export a way to pass keyring as
  an argument to package reading/verification functions. Since thereäs
  no technical reason to disallow it, might as well allow it...
2012-02-02 19:13:03 +02:00
Panu Matilainen 89eadf7f14 Use private environment for database rebuilds too, document
- One of the more common reasons for users to do --rebuilddb is
  a paniced environment. Throwing DB_RUNRECOVER errors at the user
  who is trying to recover by rebuilding the db isn't terribly
  productive (RhBug:590710). Use a private environment while
  rebuilding for both the original and new database, and dont bother
  with CDB which only slows things down when there are no other
  players present.
- Verify wants the same flags but for different reasons...
2012-02-02 14:39:49 +02:00
Panu Matilainen 290fcbbe6b Never load ts keyring if signature checking is disabled
- Loading the pubkeys from database numerous often unwanted side-effects,
  if signature checking is disabled then there's no point loading
  the keys either.
- Commit cad147070e did this for
  rpmReadPackageFile() specifically but we really want it honored
  for all operations including headerCheck() and friends, handle
  it centrally in loadKeys() for simplicity.
2012-02-02 14:18:50 +02:00
Panu Matilainen cef18c9480 Don't free up file info sets on transaction test-runs
- We'd like to get rid of the potentially huge amounts of memory
  eaten by file info sets as early as possible, but when there's a
  chance that we'll get called again with either added transacation
  elements or on-disk changes, such as %pretrans changing something
  underneath us, we need to (be able to) recalculate everything
  from scratch. Only free up the memory when we know we dont need
  it anymore, ie on an actual transaction run.
- This doesn't change anything for rpm itself, for yum and others
  which do a separate test-transaction first, it means %pretrans
  directory<->symlink replacement hacks and the like have a chance
  of working again. I'm sure there's a bug filed on this somewhere but...
2012-02-01 18:01:00 +02:00
Panu Matilainen 4c3fb8051b Use rpmReadHeader() on signature checking path too
- rpmReadHeader() performs far more initial sanity checks on the header
  than headerRead() does, and makes behavior consistent with eg query
  and install paths. As an added bonus we'll get more detailed
  error messages too.
2012-01-30 10:23:51 +02:00
Panu Matilainen 502d07cf24 Test for filename triplet sanity in rpmfiNew()
- Basename and dirindex counts must be equal, dirnames count must be
  larger than zero and no larger than number of basenames. Check
  that directory indexes are within range.
- There are mountains of further checks to be added here (and elsewhere)
  but we gotta start somewhere... and filename triplets are one of the more
  critical elements we got.
2012-01-28 18:11:49 +02:00
Panu Matilainen 57b6b175ad xcalloc() cannot return NULL, remove redundant check 2012-01-28 17:23:16 +02:00
Panu Matilainen 06a2f1269b Don't assume rpmfiNew() always succeeds
- Add NULL checks and add/adjust comments where appropriate.
- The remaining callers should handle NULL fi gracefully if not
  entirely correctly: rpmfiFC() returns 0 on NULL fi, so these
  callers just see the erronous file info set as "no files" case.
  Something to fine-tune later...
2012-01-28 17:07:42 +02:00
Panu Matilainen 2c59afecc3 Add some basic sanity checks to rpmte creation, allow rpmteNew() to fail
- Verify that a header at least has the very basic elements like
  name, version, release, os and arch (except for gpg-pubkeys which
  dont have the latter two, sigh), fail if not.
- rpmfiNew() cannot currently fail but handling this error will allow
  sanity checking the file metadata which can be inconsistent even if
  a header is "physically" consistent.
- We'll eventually want to have sanity checks on dependency sets too, but
  unlike rpmfiNew(), rpmdsNew() currently returns NULL for non-existent
  dependencies (eg most packages do not have conflicts or obsoletes) to
  save memory. Either that needs to change or we'll need to check
  for tag existence for the meaning of a returned NULL here.
2012-01-28 15:24:01 +02:00
Panu Matilainen 5aeebe8d69 Don't assume rpmteNew() always succeeds, part III
- Return error from verifyscript if rpmteNew() fails. This can't
  currently happen but handling this error makes it possible to
  do sanity checks on the header contents, such as file list integrity etc.
  Unlikely to occur for installed packages, but verify can be run
  on non-installed packages as well, where failure is more of a possibility.
2012-01-28 15:17:02 +02:00
Panu Matilainen 0b65068823 Move TR_ADDED file size init into addTE()
- No functional changes, just stuffing it there along with most
  other rpmte init work and remove the pointless switch-case while at it
2012-01-28 14:50:16 +02:00
Panu Matilainen 45f6af7b2b Don't assume rpmteNew() always succeeds, part II
- Return error from rpmtsAddInstallElement() if rpmteNew() fails. This
  can't currently happen, but handling this error makes it possible
  to do sanity checks on the header contents, such as file list integrity.
2012-01-28 14:18:35 +02:00
Panu Matilainen f9e95c1155 Error out early if rpmdb open fails on upgrade element addition
- If we can't open the rpmdb then we cannot correctly process the
  upgrade, error out early. Mostly a "can't happen" case though.
  Also makes the logic a bit clearer, hopefully.
2012-01-28 14:11:08 +02:00
Panu Matilainen fa7face526 Don't assume rpmteNew() always succeeds, part I
- Return error from removePackage() if rpmteNew() fails. This can't
  currently happen and is unlikely anyway on already installed
  packages (this is more interesting for added packages) but
  just in case...
- Handling failure from upgrade- and obsoletes erasures is trickier
  both can add any number of erasure elements, and if one of them
  fails we'd need to undo all the erasures caused by this element.
  Just add a reminder comment for now.
2012-01-28 13:55:22 +02:00
Panu Matilainen 8cc69ab796 Axe unused cruft 2012-01-17 13:17:31 +02:00
Panu Matilainen ac4a011be5 Kill off yet more repackage remnants from fsm
- CPIO_ALL_HARDLINKS flag and related code has been unused and dead
  since rpm >= 4.6.x
2012-01-17 12:50:51 +02:00
Panu Matilainen 7bd0ee7669 Lift hard-link payload writing to helper function, fsmStage is big enough 2012-01-17 12:46:43 +02:00
Panu Matilainen 0b163b65a9 Eliminate FSM_WOPEN, FSM_WRITE and FSM_WCLOSE stages
- These are nothing but unnecessarily specialized Fopen(), Fwrite() and
  Fclose() for what is a purely local need in expandRegular(). Move
  the local stuff where it belongs.
2012-01-17 11:03:27 +02:00
Panu Matilainen 680c3cfbf7 Eliminate FSM_ROPEN, FSM_READ and FSM_RCLOSE stages
- These are nothing but unnecessarily specialized Fopen(), Fread() and
  Fclose() for what is a purely local need in writeFile(). Move
  the local stuff where it belongs.
2012-01-17 10:52:46 +02:00
Panu Matilainen ff74325088 Eliminate file digest related members from fsm struct
- Both digest algo and the current file digest from header are
  only needed inside expandRegular(), push the stuff down there.
2012-01-17 09:03:55 +02:00
Panu Matilainen 9834b743d6 Eliminate the now obviously unnecessary opath member from fsm struct 2012-01-16 14:40:45 +02:00
Panu Matilainen 830a551406 Avoid fsm->opath usage for symlink target
- Instead of behind-the-scenes pointer updating, use fsm->wrbuf
  explicitly for the link target. Doesn't make it less hackish
  but at least it now stands out.
2012-01-16 14:30:40 +02:00
Panu Matilainen 35efcc2b76 Avoid fsm->opath usage in fsmMakeLinks()
- opath is the file that links will be made to, we grab it at the
  start and free at the end. No need to save and restore what we
  dont modify, one more fsm->opath usage down...
2012-01-16 14:17:35 +02:00
Panu Matilainen 0b55a38fce Remove unused FSM_MKLINKS stage 2012-01-16 14:13:38 +02:00
Panu Matilainen 847bd5c5dd Avoid fsm->opath usage in final file rename
- Hopefully this makes the actual operation stand out more clearly
  with the unnecessary fsm->opath fiddling out of the picture,
  other than that there's not much to gain here.
2012-01-16 14:01:48 +02:00
Panu Matilainen 2ed8067811 Eliminate unnecessary fsm->path/opath shuffle on unlink
- No need to save and restore what we dont modify...
- Add comments to double-check later for couple of fishy looking bits
2012-01-16 13:15:09 +02:00
Panu Matilainen f34f68dca6 Eliminate unnecessary fsm->path/opath shuffle on backup renaming
- Makes the code much more obvious to follow since we're not swapping
  path/opath back and forwards just to be able to use a throwaway
  path for the rename. Dont bother null-checking on logging,
  if one of the paths was null we'd be dead already.
- Also fixes an ancient memleak: when osuffix is in use, fsm->path
  gets newly malloced before fsmVerify() but this part did another
  allocation on it, didn't save and restore fsm->path .. and nothing
  was freeing the original (local) allocation of fsm->path, only
  restoring the previous value.
2012-01-16 12:43:51 +02:00
Panu Matilainen e671fef91b Eliminate unnecessary st_mode save-modify-restore on dir creation 2012-01-16 11:40:37 +02:00
Panu Matilainen ddbb0e5abd Eliminate unnecessary save-modify-restore around fsmUtime() 2012-01-16 11:31:02 +02:00
Panu Matilainen 8da076e5a8 Eliminate unnecessary save-modify-restore on fifo creation 2012-01-16 11:27:49 +02:00
Panu Matilainen d63a803303 Move symlink() to separate helper function
- Similar to mkfifo(), mknod() & friends, doesn't do much but for
  consistency and fsmStage() size sanity...
2012-01-13 18:15:30 +02:00
Panu Matilainen 5cc634c7d3 Eliminate stupid fsm->path/opath in FSM_COMMIT now that we can
- Now that we can directly operate on temporarily variables instead
  of having to save-ping-restore-pong them, lets do so...
- Also eliminating NULL-checks on the path variables in logging - if
  either of the paths were NULL we would've already crashed in rename()
2012-01-13 18:09:03 +02:00
Panu Matilainen af9fb2b672 Blarg, stupid stupid mistake breaking symlink handling
- Introduced in commit d15bf56a70 and
  uncaught prior to push as none of the test-suite cases involve
  symlinks. This is what happens when trying to quickly rewrite
  git history to put combine a forgotten change into earlier ones,
  guilty as charged :(
2012-01-13 17:54:23 +02:00
Panu Matilainen 8a21e92b80 Only pass what little is actually needed in fsmMkdirs()
- Once all the other cruft has been carved out, turns out this needs
  nothing but a directory iterator which we can init and free
  in the caller easily enough, and selabel handle (duh). All the
  rest is independent of fsm internals in reality.
2012-01-13 17:19:17 +02:00
Panu Matilainen 764d1fe563 Eliminate stupid fsm->sb.st_mode abuse from fsmMkdirs()
- At the point where this runs there's probably nothing at all to
  save and restore in the stat buf anyway, but it's just stupid to
  abuse that when all we need is a local mode_t temp variable. Fix
  it now that we can.
2012-01-13 17:19:11 +02:00
Panu Matilainen d4215ed854 Move mknod() to separate helper function
- Similar to mknod() and all, this doesn't do anything that special
  but fsmStage() is big enough as it is.
2012-01-13 17:19:04 +02:00
Panu Matilainen 700e1390b2 Move mkfifo() to separate helper function
- Similar to the other fsm syscall wrappers, this doesn't do anything
  that special, but fsmStage() is big enough without things like
  this inline.
2012-01-13 17:18:59 +02:00
Panu Matilainen 99d00350b7 Change fsmReadLink() to take "normal" arguments
- This doesn't need access to the entire fsm, it just needs a buffer
  to place the results in / return errors. Currently the "out" buffer
  is (ab)used for the results, this just forces that to stand out
  and should make it easier to sanitize later.
2012-01-13 17:18:43 +02:00
Panu Matilainen 2412e66ea4 Change fsmUtime() to take "normal" arguments
- This doesn't need access to the entire fsm, just path and mtime
  from coming from a header originally. Will allow eliminating
  save -> abuse -> restore behavior in caller but leaving till later...
2012-01-13 17:18:35 +02:00
Panu Matilainen d15bf56a70 Change fsmChown(), fsmLChown() and fsmChmod() to take "normal" arguments
- None of these needs access to the entire fsm, they only
  exist to map and filter errors to rpm special needs and to
  create debug swew on top of the plain syscalls.
2012-01-13 17:17:19 +02:00
Panu Matilainen e0b1ff9a92 Change fsmMkdir() to take "normal" arguments
- This doesn't need access to the entire fsm, it only exists to
  map errors to CPIOERR_* and create debug foo. This will allow
  eliminating save -> abuse -> restore behavior in callers, but
  leaving that till later.
2012-01-13 15:06:06 +02:00
Panu Matilainen f7c1c54363 Change fsmStat() to take "normal" arguments
- This doesn't need access to the entire fsm, just regular stat()
  args and a flag whether to use lstat() or stat(). "followlinks"
  or such would be saner name for the flag but leaving that for now...
2012-01-13 14:47:19 +02:00
Panu Matilainen 5618c00071 Change fsmRename() to take "normal" arguments
- This doesn't need access to the entire fsm, just regular rename()
  args and a flags to see whether "secure" delete should be done.
  In itself this only looks like more trouble, but all the callers
  are fiddling and saving and restoring with fsm->[o]path just
  to call this, which we can now avoid. Leaving sanitizing the
  callers till later though, this is a minefield...
2012-01-13 14:42:57 +02:00
Panu Matilainen 8d18395abc Change fsmUnlink() and fsmRmdir() to take "normal" arguments
- Neither of these needs access to the entire fsm, they mostly
  exist to create debug cruft and to map errors to CPIOERR_*
2012-01-13 12:36:01 +02:00
Panu Matilainen 62c7654279 Sanitize file capability setting in fsm
- Move parsing, setting and freeing of capabilities into simple
  helper function, there's no point whatsoever having the current
  capability stored in fsm when it only complicates freeing and all.
  WTH was I thinking when implementing this? (well, everything in
  fsm was done that way so...  but that's a lame excuse)
2012-01-13 11:36:28 +02:00
Panu Matilainen d4b8acc5d3 Sanitize selinux labeling in fsm
- Move all the label foobar into a simple helper function which
  finds, sets and frees the context if selinux is enabled, use
  for both regular operation and orphan directory labeling.
  Simplifies things a good deal...
- While the selabel handle can change during a transaction, it
  wont change while the fsm is running so its sufficient to grab
  it on entry instead of repeatedly calling rpmtsSELabelHandle() after
  figuring out where in the world our ts might be.
2012-01-13 11:08:47 +02:00
Panu Matilainen cc1b352952 Eliminate unused subdir member from fsm struct 2012-01-13 10:27:11 +02:00
Panu Matilainen a8fd66d87f Eliminate silly sufbuf from fsm struct
- Allocate fsm->suffix directly when suffix is needed instead.
  Doesn't change anything, only makes life that little bit simpler.
2012-01-13 10:23:50 +02:00
Panu Matilainen 9e1feaf543 Ensure installs always use a temp suffix on files
- This bogosity goes back to commit fcf6b50378
  which was supposed to fix files getting erased if time() returns
  errors (RhBug:223931). Problem is, this "fix" didn't fix anything
  at all as the suffix still wouldn't be created in the error
  case, even if the FSM_UNDO part did the right thing. We always
  want a suffix on installs, it doesn't matter *what* the suffix is.
2012-01-13 10:06:09 +02:00
Panu Matilainen 37f7802aa6 Remove unused "orphan" directory creation tracking variable from fsm 2012-01-13 09:41:56 +02:00
Panu Matilainen 8049e42f30 Move directory tracking variables out of fsm struct to local scope
- These are not used or needed outside fsmMkdirs() so its just
  plain dumb to have them in the big struct. No functional changes,
  just taming the fsm monster a little bit.
2012-01-13 09:40:11 +02:00
Ales Kozumplik 7a530738ca remove the 'path' parameter of rpmtsSELabelInit()
- It is always selinux_file_context_path() anyway.
2012-01-12 14:27:36 +01:00
Ales Kozumplik 7a8b75d266 selinux: reopen label between transactions if necessary (RhBug: 746073) 2012-01-12 14:27:36 +01:00
Panu Matilainen a3123467a5 Eliminate now unnecessary runFsm() helper from psm 2012-01-11 15:47:18 +02:00
Panu Matilainen 8e609fc55b Eliminate no longer needed RPMFI_ISBUILD and RPMFI_ISSOURCE internal flags 2012-01-11 15:47:12 +02:00
Panu Matilainen aee64fbc46 Turn FSM into a blackbox, much like PSM is
- Similar in spirit to PSM blackbox treatment in
  commit df9cdb1321, except that
  technically fsm guts are still wide-open in fsm.h due to cpio
  "needing" them (yuck).
- Allows getting rid of dumb a**-backwards things like rpmfiFSM()
  which is just not needed, fsm is a relatively short-lived entity
  inside psm and build, nobody else needs to bother with it except
  for the returned results.
- Figure out the cpio map flags in fsmSetup() where it logically belongs,
  we have all the necessary info available there.
- Get rid of newFSM() and freeFSM(), we can just as well place the
  fsm on stack, merge the necessary cleanup bits from freeFSM()
  into fsmTeardown()
- Supposedly no functional changes, knock wood.
2012-01-11 15:41:22 +02:00
Panu Matilainen 1dc09307d8 Eliminate archiveSize member from rpmfi
- rpmfi itself doesn't need it for anything, its only really used
  for progress reporting during install. Grab the size into psm
  total directly, this is already passed down to fsm.
- Removes one of the last remaining rpmfi opacity violations, just
  fi->apath to go...
2012-01-11 12:17:31 +02:00
Panu Matilainen ef9b08a5d8 Explicitly tell rpmfiNew() when its being used for build
- Eliminate feeble heuristic on archive size tag not being set during
  build for detecting this and have build code explicitly pass
  RPMFI_ISBUILD flag instead.
- Also eliminate the pointless isSource variable from rpmfiNew() while.
2012-01-11 12:16:53 +02:00
Panu Matilainen 07379e27c0 Issue package install/erase progress callbacks on justdb operation too
- Large --justdb operations can take considerable amount of time as well,
  getting progress bars for it is nice even if hardly necessary...
2012-01-11 12:15:48 +02:00
Panu Matilainen 9d6450bc5a Eliminate fluff from PSM_INIT
- rpmpsmStage() runs with RPMRC_OK as assumed result, no need to
  set explicitly here.
- Dont bother testing for justdb flag here. The justdb case doesn't
  need fi->apath but it doesn't exactly hurt either, and we'll want
  to eliminate the apath kludge sooner or later anyway.
2012-01-11 12:15:38 +02:00
Panu Matilainen d8d52e0bc7 Oops, forgot to mark our new progress messages for translation 2012-01-10 20:27:25 +02:00
Panu Matilainen 280ad0796a Add erasure callback support to rpmShowProgress() and enable on rpmErase()
- Just use the same bits as install does, they behave the same for
  our purposes. On upgrades the output would get confusing especially
  with --hash when package versions aren't output'ed, so we print
  out extra output when entering install and erase stages. Only
  do this when --hash is used (ie a human is probably watching us)
  to hopefully avoid breaking scripts (including our test-suite) that
  rely on the ages old behavior of non-hashed output.
2012-01-05 16:28:06 +02:00
Panu Matilainen f0948894f0 Issue actual erasure progress callbacks too
- Whereas on install the progress is measured by bytes written to
  disk vs total archive size, on erase the best we can do is
  going by the number of files in the package. Fsm iterates backwards
  on erase so we can't just use fsm->ix but need to re-revert the value.
2012-01-05 16:05:11 +02:00
Panu Matilainen 72bd2de21e Clean up progress callbacks in fsm/psm machinery
- Move notifications from fsm to psm side for sanity and symmetry,
  psm already has members to hold the callback state.
- Replace PSM_NOTIFY "state" with a helper function that both
  fsm and psm itself use (except for error callbacks which are
  a bit different)
- Init psm->total early, this doesn't change and can now be
  used to refer to "all done" value whatever it happens to be,
  instead of magic "100" values etc.
- Packages with no files are now handled through the same path
  as everything else from progress reporting pov, we just skip calls
  to fsm if there are no files.
- Issue stop callbacks for install as well. While INST_CLOSE_FILE
  can be (and is currently) used to detect this condition, its
  conceptually an entirely different thing.
- Fix erasure callback parameters, they were reversed (starting from
  total and ending with 0, ehh...)
2012-01-05 16:05:10 +02:00
Panu Matilainen ff0ece3f6b Add enum for RPMCALLBACK_INST_STOP callback event
- Unused atm but we'll be adding this shortly
2012-01-05 16:05:10 +02:00
Panu Matilainen ef75cadf03 Pass and remember the controlling psm (if any) in fsm 2012-01-05 16:05:10 +02:00
Panu Matilainen 91a58bd423 Eliminate repackage notification remnants from fsm
- This has been unused and dead code since rpm >= 4.6.0
2012-01-05 16:05:10 +02:00
Panu Matilainen 033037a3b0 Use rpmtsNotify() directly for psm error callbacks
- On error we're already on our way out of the psm, no point mucking
  with the psm state. No functional changes, just makes the code
  a little bit shorter.
2012-01-05 16:05:10 +02:00
Ales Kozumplik ea9d9d68c8 rpmOption.required is not used. 2012-01-04 14:16:59 +01:00
Ales Kozumplik c6a9d0bd60 rpmrc: do not use that nonexistent rpmOptionValue struct. 2012-01-04 14:16:53 +01:00
Ales Kozumplik 322891aac7 depends.c: save us one rpmdsNew in addObsoleteErasures.
- replaces rpmdsAnyMatchesDep with rpmdsNVRMatchesDep
2012-01-04 14:13:01 +01:00
Ales Kozumplik 5a5f1fa51c depends.c: unused parameters in addUpgradeErasures, addObsoleteErasures.
- remove them.
2012-01-04 14:12:50 +01:00
Panu Matilainen ce2ce4c197 Implement scriptlet start and stop callbacks (RhBug:606239)
- Adds two new transaction callbacks: RPMCALLBACK_SCRIPT_START and
  RPMCALLBACK_SCRIPT_STOP which get issued for every scriptlet we run.
- On script start, callback can optionally return an FD which will
  override transaction-wide script fd to make it easier to accurately
  collect per-scriptlet output (eg per-scriptlet temporary file).
  Callback is also responsible for closing the fd if it returns one.
- For both callbacks, "amount" holds the script tag number. On stop
  callback, "total" holds the scriptlet exit status mapped into
  OK/NOTFOUND/FAIL for success/non-fatal/fatal errors. Abusing "notfound"
  for warning result is ugly but differentiating it from the other
  cases allows callers to ignore SCRIPT_ERROR if they choose to
  implement stop and start.
2012-01-03 15:15:24 +02:00
Panu Matilainen c4b78515d6 Eliminate rpm cli callback internals from the API
- rpmcliHashes*, and rpmcliProgress* and rpmcliPackagesTotal are
  implementation details of rpmShowProgress() and are useless outside
  of it. Make them static, these shouldn't have been exported to
  begin with.
2012-01-03 12:12:12 +02:00
Panu Matilainen 4c02238238 Eliminate pointless rpmcliPackagesTotal fiddling
- The total number of packages equals transaction order count, which
  is passed as total to transaction start callback. In particular
  messing with this from rpmtsAddInstallElement() is just stupid.
- This will break callers that are relying on rpmcliPackagesTotal value
  outside a running transaction, but that's just stupid anyway. The
  correct way to get number of elements in transaction set is calling
  rpmtsNElements(), which has been there for a good part of a decade.
2012-01-03 12:12:12 +02:00
Ales Kozumplik 9cb5d5ccfb Allow deprecations to work accross colors (RhBug:713323)
This enables package maintainers to:

- Force removal of a no longer supported multilib library (the patch also
  removes the check against obsoleting packages of the same name).

- Deprecate packages of different header color than the package's. Note:
  even x86_64 packages can have header color 1 in which case we are
  currently left with no means to deprecate them from another x86_64
  package. (RhBug:751574)
2011-12-23 14:36:42 +01:00
Ales Kozumplik 87e37b7daf depends.c:skipColor() is not longer a macro
- Prevents double evaluation of the 'ocolor' parameter.
2011-12-23 14:36:42 +01:00
Panu Matilainen ead20c495c Oops, newlines dont belong in format extension output
- Thinko in commit 6acef96d9e, duh
2011-12-15 15:21:57 +02:00
Panu Matilainen 9108129a3d Allow pre- and posttrans to omit interpreter or body (again)
- While most scriptlets have both an interpreter and a body, neither
  is strictly required: body can be omitted in cases like special
  purpose executables (eg -p /sbin/ldconfig) and for interpreter,
  /bin/sh is used if missing. This has been "broken" from somewhere
  around rpm 4.7.x and nobody noticed :)
2011-12-01 15:06:53 +02:00
Panu Matilainen 4abb1d8bc1 Cache all but FAIL results from rpmdb header verification
- This makes a huge difference in performance if you have lots
  of unsigned packages (NOTFOUND verify result) or signed packages
  without key (NOKEY verify result) installed, as we previously
  kept checking the same headers over and over again.
2011-11-30 13:38:35 +02:00
Panu Matilainen 570526b4ba Purge rpmdb header verification cache on added pubkeys
- When new keys are added, any previous NOKEY results can become
  invalid: either they become OK or FAIL, and its the FAIL case
  we want to catch.
- For removed keys, previous OK could become NOKEY but that doesn't
  make the header any less valid, so leave the cache alone on removal.
2011-11-30 13:32:56 +02:00
Panu Matilainen 2759c91b4c Enable fast-import mode for headers from rpmdb
- Assume our home turf is safe enough for this - in order to reach
  the rpmdb, headers must've gone through the more rigorous checking
  that's done through the rpmReadPackageFile() paths, plus in
  default configuration we'll be doing further verification on the
  header before loading the headers so the risk seems acceptable
  for the speed gain.
2011-11-30 12:09:44 +02:00
Panu Matilainen cd5222b6e3 Implement "fast" flag to headerImport()
- regionSwab() calling dataLength() on headerImport() is one of the
  busiest paths in rpm, and dataLength() on string types is a very
  expensive call as it has to walk through the string looking for \0's.
  The data size is actually available most of the time by just looking
  at offsets (idea lifted from rpm5.org), which is an order of magnitude
  faster than crawling string data. The downside (there always is one)
  is that with offsets, string data is not validated to contain
  sufficient number of \0's, which means malformed headers could cause
  us to crash, burn and overflow when accessing the string data.
- The new "fast" mode enables offset-based calculation at callers
  discretion, ie if the caller can reasonably assume the header is
  sane (known to be previously validated etc), using the fast-flag
  will make header loading/importing considerably faster.
  For now, only headerImport() will use the fast mode but it might
  make sense to remember the setting in the header and use for other
  operations as well.
2011-11-30 11:59:35 +02:00
Panu Matilainen eae6715564 Update internal callers to use headerExport(), no functional changes 2011-11-30 11:03:54 +02:00
Panu Matilainen 359baa2831 Add an enhanced interface for unloading, aka exporting, headers
- Most callers need the size of the blob as well, which the unloader
  internals know perfectly well but the interface doesn't support
  passing it. So callers were forced to make a second call to
  headerSizeof() to recalculate the size. Duh.
- Rename and export doHeaderUnload() as headerExport(), update internal
  callers to use the new name. headerExport() is hopefully a bit
  more obvious as a name than headerUnload() which doesn't actually
  undo the effect of headerLoad() for that header, but merely exports
  the data by serializing into on-disk format.
- Header size is not size_t really, its capped to fixed much lower
  size. Use unsigned int to better match reality.
2011-11-30 11:03:17 +02:00
Panu Matilainen e83aa4f638 Update internal callers to use headerImport() instead of headerLoad()
- Pass size where possible, this is a bit redundant in places since
  its already checked in various places but wont hurt anyway.
2011-11-30 11:00:40 +02:00
Panu Matilainen 52bcafcfb2 Add an enhanced interface for loading, aka importing, headers
- Unlike headerLoad(), headerImport() takes a blob size argument
  to allow sanity checking the size calculated from the blob itself
  against the "physical" passed-in blob size so its a bit safer.
  Note that header size is capped by various things - its not size_t.
- headerImport() also takes a flags argument to allow controlling
  various aspects of importing.
- Implement "take copy of blob" as a flag to headerImport(), push
  the copying into headerCreate() where we already know the blob
  size, avoiding the need to do double-calculations on headerCopyLoad()..
- headerLoad() and headerCopyLoad() are now just compat wrappers
  around the new interface.
2011-11-30 10:41:00 +02:00
Panu Matilainen c943d42880 Consolidate header alignment calculations to helper function
- Replace no less than five copy-paste versions of the same thing into
  an inlined helper function. No functional changes.
2011-11-29 15:46:07 +02:00
Panu Matilainen 21d8ceb866 Optimize string tag length calculations in regionSwab()
- Calling memchr() is circa 35% faster on my system than doing the
  same manually, and this in one of the most critical paths rpm has...
2011-11-29 10:38:53 +02:00
Panu Matilainen 3a75a9f6c4 Make gpg-pubkey headers properly verifiable
- The pubkey headers have been rpm v3 all the way until now, whoops :)
  Pull the actual key part of the header into immutable region and
  stomp a sha1 digest on the result, allowing a (much) better
  verification on loading. This part inspired by stumbling on a
  related discussion on rpm5.org mailing list so credits where...
- Since we only insert either literally constant data or data retrieved
  from the actual key into the immutable part of the header, the
  calculated digest is constant for a given key regardless of where
  and when it was imported. This gives some added verification and/or
  cross-checking possibilities (eg was the imported key exactly the
  same as what shipped etc)
2011-11-24 11:58:44 +02:00
Panu Matilainen 66d6987120 Sanitize makePubkeyHeader() calling semantics
- Create the header in makePubkeyHeader() as the name suggests,
  return the newly created header to caller on success.
- Move the installtime & -tid addition to the "install" part,
  makePubkeyHeader() only does the part that is specific to pubkey
  headers, again as the name suggests.
- No functional changes
2011-11-24 11:28:15 +02:00
Panu Matilainen 4c6397507b Make gpg-pubkey buildtime reflect the public key create time
- Pubkey buildtime has until now been the time of import, which equals
  install time/tid. Which is of course the time when that header
  does get created, but it seems rather redundant to have the same
  thing recorded in three places. Having the key creation time
  easily (easier than un-hexifying the version string, duh)
  available seems like a potentially useful thing. Buildtime is
  "wrong" for this, but ... so is everything.
- With this change, the "meat" of the pubkey headers is now constant
  and repeatable regardless of where and when a key gets imported,
  so we could stomp a digest on it and it'd be unique for that
  particular key everywhere.
2011-11-24 11:25:53 +02:00
Panu Matilainen 6b871c5337 Add key userid into gpg-pubkey headers as "packager"
- The userid has only been available in a mildly obfuscated format
  through summary, but this seems like a useful thing to have in
  a directly usable format without requiring callers to parse out
  the gpg() wrapping around it.
- Yes its a wonky mapping, but so is everything else wrt
  gpg-pubkeys, and adding a tag just for this also seems silly.
  Using vendor tag could be another possibility, dunno.
2011-11-24 11:21:41 +02:00
Panu Matilainen 4537c8c8bc Log an error on attempt to sign V3 packages (RhBug:517818 & others)
- We haven't been able to sign V3 packages in the last decade or so,
  might as well spit out an error on it instead of silently failing.
2011-11-24 11:16:19 +02:00
Panu Matilainen 858a328cd0 Fix dribble length calculation on headerLoad()
- When calculating length of dribbles, we need to take into account the
  size up to that point, otherwise the alignment can be wrong causing
  the sizes not to add up.
- With that mystery solved, we can now make the final length check
  as strict as it should be.
2011-11-24 11:12:03 +02:00
Panu Matilainen 0761bad269 Ehm, %pretrans failure shouldn't abort the entire transaction
- Brainfart in previous commit (71c6b06b3f):
  %pretrans failure should only cause that package to fail, not
  abort the entire transaction. Doh.
- Failures are tracked via transaction elements but pre/posttrans
  were specifically filtered out. All we need is removing that filtering
  and the warn-only vs error logic in psm takes care of the rest.
  The transaction.c changes in previous commit were just unnecessary.
2011-11-22 12:34:46 +02:00
Panu Matilainen 71c6b06b3f Make %pretrans failure fail the install (RhBug:736960)
- %pre and %preun scriptlets cause the package install/erase to fail,
  whereas %pretrans return has simply been ignored ever since its
  introduction somewhere in rpm <= 4.4.x. This is just inconsistent,
  make %pretrans more like the other %pre-scriptlets. %posttrans
  exit code is still essentially ignored, just like %post and %postun etc.
- This can obviously affect installability of existing packages: if
  they have been careless about their %pretrans exit code or outright
  relying on the "yes it spits errors in some situations but who cares"
  behavior, they will now fail to install at all. The way to write
  "portable" %pretrans scriptlets is ensuring non-error exit.
2011-11-22 11:38:13 +02:00
Ales Kozumplik cd68e2b27e cosmetic: indentation in rpmdbNextIterator.
- the hunk looked confusing with the wrong indentation.
2011-11-18 10:07:37 +01:00
Ales Kozumplik fa428c5bc1 Recognize "<epoch>:" as a part of a label (ticket #117)
- for instance this works now:
  $ rpm -q perl-4:5.14.1-188.fc16.x86_64
  perl-5.14.1-188.fc16.x86_64
2011-11-18 09:51:29 +01:00
Panu Matilainen 1e0e3e01d2 Doh, somehow managed to miss the warnings from these missing includes :(
- Should've been in commit 70f063cb77
2011-11-10 08:46:59 +02:00
Panu Matilainen 70f063cb77 Make base64 encoding/decoding part of rpmio public API
- Base64 is present in headers and all, it's only reasonable that
  our API users have access to this functionality without having
  to link to other libraries. Even if we didn't want to carry the
  implementation forever in our codebase, we should provide a wrapping
  for this (much like the other crypto stuff) for the reason stated above.
- A bigger issue is that our dirty little (badly hidden) secret was using
  non-namespaced function names, clashing with at least beecrypt. And we
  couldn't have made these internal-only symbols even on platforms that
  support it, because they are used all over the place outside rpmio.
  So... rename the b64 functions to rpmLikeNamingStyle and make 'em public.
  No functional changes, just trivial renaming despite touching numerous
  places.
2011-11-09 15:16:28 +02:00
Panu Matilainen 24eb3257f6 Eliminate uses of pgpDig in package reading & signature checking
- No functional changes, just eliminates pile of unnecessary allocations
  and other calls, simplifying the code a bit.
2011-11-09 13:44:31 +02:00
Panu Matilainen 5722245dd8 Take advantage of pgpPrtParams() directly in pgpsigFormat() extension
- No functional changes, just bypassing an unnecessary round-trip to
  a function really intended for other purposes, now that we can.
2011-11-09 13:29:42 +02:00
Panu Matilainen bbf2f63676 Switch to using rpmKeyringVerifySig() internally
- Change rpmVerifySignature() to take just the signature parameters
  instead of the whole dig (this is an internal API so we're free
  to mess with it) from which it only needed the signature params.
- The internal low-level verifySignature() is thus reduced to
  to a call to rpmKeyringVerifySig() and spitting some silly
  strings to msg.
- With this, keyring can now use and reuse the its internally stored
  pgp key parameters instead of having to parse the same PGP packets
  over and over. As a result, signature checking is faster now. Not
  dramatically so but measurably nevertheless.
2011-11-09 13:12:01 +02:00
Panu Matilainen 9e9761caa8 Don't make assumptions about how pgpDig allocates things
- Only call pgpDigGetParams() on the public key once we've at least
  tried to fetch it via rpmKeyringLookup(). This way we dont assume
  things about how pgpDig internal allocation is done - currently
  it does return what's essentially a static pointer into pgpDig,
  but this is not a reasonable assumption for an opaque type.
  No functional changes.
2011-11-09 09:23:26 +02:00
Ales Kozumplik 1c8e56729d Do not let 'rpm -q foo-' find package 'foo'. (RhBug:488567)
- Includes a test suite for the case.

Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
2011-11-08 11:15:54 +02:00
Panu Matilainen cde47f5945 Use pgpDigParamsAlgo() throughout the codebase
- Tedious but straightforward conversion to use the API instead
  of going to the struct directly.
- Remove digest.h includes where no longer necessary
2011-11-07 14:47:03 +02:00
Panu Matilainen c8fe64dbc6 Eliminate direct pgpDig accesses from pubkey importing 2011-11-07 12:55:27 +02:00
Panu Matilainen 13ff12421d Eliminate direct pgpDig access from package reading code 2011-11-07 12:55:02 +02:00
Panu Matilainen 0afd3343f0 Eliminate direct pgpDig accesses from lowlevel signature code 2011-11-07 12:54:30 +02:00
Panu Matilainen f3a8970e73 Take advantage of parsePGPSig() in pgpsigFormat() too
- Doesn't make for less lines in this case but unifying the accesses
  is good anyway.
2011-11-07 11:21:31 +02:00
Panu Matilainen 3a01513c76 Unify the parsePGP() variants from package.c and rpmchecksig.c
- Hide allocation inside the helper, automatically free on failure
- Return pointer to the signature parameters on success to simplify
  life for callers
- Don't bother checking or reporting the signature version: the
  pgp parser errors out if it encounters unsupported version and
  does not scrible anything to the version field in that case,
  mumbling about "V0 signatures" is not particularly helpful.
- Log the bad package names from rpmpkgReadHeader() too
2011-11-07 11:09:08 +02:00
Panu Matilainen e8bc3ff5d7 Hide pgpDig alloc etc details in the parsePGP helper
- Return a pointer to the signature part on success, hide allocation
  (and free on failure) in the helper. Makes life a little bit
  saner for the callers and limits the places where we access
  the full pgpDig further.
2011-11-07 10:45:56 +02:00
Panu Matilainen dc3f313b66 Add another pgpVerify variant which takes key and sig as separate args
- pgpVerifySig() is now just a dumb wrapper around pgpVerifySignature()
  which does the real work.
- Update the sole caller to use the new interface instead, deprecate
  the old dig interface.
- First steps towards getting rig of pgpDig which always was a
  strange creature and now is nothing but a nuisance and obfuscation.
  Yes keys and signatures walk hand in hand much of the time, but
  they come from different sources and want to be handled as
  separate data really.
2011-11-07 08:05:34 +02:00
Panu Matilainen 44f1c853fd Eliminate couple of unnecessary pgpDig usages
- stashKeyid() only wants the signature, not the whole dig
- dig argument to readFile() was simply unused
2011-11-07 08:05:25 +02:00
Panu Matilainen 85b90e4176 Add a couple of missing includes, masked by NSS headers 2011-11-04 16:28:13 +02:00
Panu Matilainen 97a452f732 Sanitize pgpsigFormat()
- Eliminate bogus size calculations: we have a buffer of td->count size
  that may or may not contain legal OpenPGP signature. Leave it up to
  pgpPrtPkts() to validate & figure it out and check its return code instead,
  eliminating need to repeat a bunch of tedious calculations here.
- Use non-zero signature version is used as a hint for valid signature,
  should be "close enough" for the rest of the code.
2011-10-24 12:34:07 +03:00
Thomas Jarosch ebf5a4e7c8 Fix unterminated buffer after readlink() call
readlink() never terminates the buffer.

Detected by "cppcheck" (git HEAD)

Signed-off-by: Thomas Jarosch <thomas.jarosch@intra2net.com>
Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
2011-10-23 14:45:47 +03:00
Panu Matilainen f79909d04e Fix ancient off-by-one at end boundary in string array size calculation
- String array size calculation could read one byte past data end
  pointer when expected count and number of \0's disagree (ie invalid data)
  due to while condition side-effects + bounds checking being in
  the inner loop.
- Lift the string length calculation to inline helper function, used for
  both string and string array types.
- Streamline the calculations:
  - Eliminate unnecessary length increments, calculate the length
    from pointer distance
  - Eliminate end pointer NULL checking within the loop: when caller
    doesn't supply end pointer, cap to HEADER_MAX_DATA (ie 16MB),
    anything larger would trip up in later hdrchkData() checks anyway.
  - Avoid the off-by-one by eliminating the problematic inner loop.
2011-10-21 13:33:59 +03:00
Panu Matilainen bfcc5bf3b9 Verify the entire region trailer, not just its offset, is within data area
- Offset being within the data area doesn't help if the actual data doesn't
  fit. Since the trailer size is well known, we can just as easily
  make the check accurate to prevent reading beyond end of data in case
  the offset is subtly wrong.
- In headerLoad(), region offset of zero doesn't need sanity checking,
  only validate if its something else and do so accurately there too.
2011-10-20 10:52:58 +03:00
Panu Matilainen 0167d8ccd1 Fix pretrans dependency calculation when provider is upgraded
- Pretrans-dependencies are twisty little beasts unlike anything else...
  When a pretrans-dependency provider is updated, the currently installed
  version is the provider for that transaction, unlike others where
  the packages from installing set act as providers for updates. So
  when looking up pretrans deps, we must not prune the to-be-erased
  packages from the db match iterators. As an added twist, we also
  must not cache these non-pruned cases as it would mess up the
  cache for "regular" dependencies.
- Fixes this case reported on fedora-devel:
  http://lists.fedoraproject.org/pipermail/devel/2011-October/158058.html
2011-10-12 09:59:21 +03:00
Mukund Sivaraman 9309458053 build: Update .gitignore rules 2011-10-11 12:55:15 +03:00
Panu Matilainen f822ffcbd7 Let headerLoad() failure message come through
- headerVerify() always returns with a message even for OK results,
  which was masking the error message from headerLoad(), sometimes
  giving not very helpful "headerRead failed: Header sanity check OK"
  style messages.
2011-10-11 10:31:40 +03:00
Panu Matilainen 90a6c2b944 Eliminate headerCheckPayloadFormat() from the API
- While we're on API killing spree... Exporting this was needless and
  dumb to begin with (greetings to self in 2007...), bury it inside
  depends.c as static and let rot there.
- Might be a better idea to kill it completely with some other
  mechanism such as turning payload format into rpmlib() dependency
  internally but just get it out of public sight for now.
2011-10-06 15:28:33 +03:00
Panu Matilainen 1de7539ea8 Eliminate headerMergeLegacySigs() from the API
- No need to export this in the API - if you want merged signature
  tags you use rpm's package reading functions.
2011-10-06 15:13:22 +03:00