Commit Graph

1126 Commits

Author SHA1 Message Date
Panu Matilainen 1e2c2fece2 Add a string equality check function to string pool API
- As a special case, two strings (ids) from the same pool can be tested for
  equality in constant time (integer comparison). If the pools differ,
  a regular string comparison is needed.
2012-09-13 09:01:30 +03:00
Panu Matilainen 2ea2a0961f Only rehash the pool on insert if the data area actually moved
- realloc() might not need to actually move the data, and when it
  doesn't we dont need to do the very expensive rehash either.
  Unsurprisingly makes things a whole lot faster.
2012-09-12 19:29:28 +03:00
Panu Matilainen 0654685493 Allow keeping hash table around on pool freeze, adjust callers
- Pool id -> string always works with a frozen pool, but in some cases
  we'll need to go the other way, allow caller to specify whether
  string -> id lookups should be possible on frozen pool.
- On glibc, realloc() to smaller size doesn't move the data but on
  other platforms (including valgrind) it can and does move, which
  would require a full rehash. For now, just leave all the data
  alone unless we're also freeing the hash, the memory savings
  isn't much for a global pool (which is where this matters)
2012-09-12 19:17:20 +03:00
Panu Matilainen 3226c2073a String pool id 0 equals NULL
- Pool id 0 is special case for "not found". Return an actual NULL
  instead of an empty string.
2012-09-12 13:33:22 +03:00
Panu Matilainen bed3880ef1 Avoid doing anything if pool is already frozen 2012-09-12 13:30:50 +03:00
Panu Matilainen 51f1cff50d Fix segfault on rpmstrPoolId() on frozen pool
- String -> id lookups need the hash table in place even if we're not
  adding. We could do a linear search in such a case but...
2012-09-11 10:22:18 +03:00
Panu Matilainen 00deac224c Make rpmstrPoolUnfreeze() safe to call on unfrozen pool 2012-09-11 09:01:49 +03:00
Panu Matilainen 09373ec03a And now, on to the embarrassing string-pool reimplementation bugs, take I
- String pool offset resize was off by one, oops
- String pool data-area resize requires rehashing all the strings,
  as the key pointers change. Ouch. Should be avoidable by extending
  rpmhash to allow passing the pool itself around in comparisons as "self"
  and using offsets as keys, but for now working counts more than speed.
- The unfreeze-sizehint calculation could be negative. Turn the initial
  size into constant and use that as a minimum, otherwise rehashing
  uses (more or less arbitrary) heuristics to come up with some number.
  Lots of fine-tuning ahead...
2012-09-09 13:04:55 +03:00
Panu Matilainen d2bb9d38c9 Move string pool typedefs to rpmtypes.h
- I suspect these will be used widely, to avoid having to include
  rpmstrpool.h all over in headers...
2012-09-07 14:09:35 +03:00
Panu Matilainen 9e47043b2d First cut of a libsolv-style string <-> id pool API
- The pool stores "arbitrary" number of strings in a space-efficient
  manner, with near constant (hashed) string -> id lookup/store and
  constant time id -> string and id -> string length lookups.
- Credits for the idea go to the Suse developers working on libsolv,
  the basic concept is directly lifted from there but details
  differ due to using rpm's own hash table implementation etc.
  Another minor difference is using size_t for offsets to permit over
  4GB total data size on 64bit systems, the total number of id's in
  the pool is limited to uint32 max however (like in libsolv).
- Any (re)implementation bugs by yours truly, this is almost certainly
  going to need further tuning and tweaking, API and otherwise.
2012-09-07 13:34:27 +03:00
Panu Matilainen 75d88c405b Minor optimization to rnibble()
- Check for lowercase letters before uppercase. A very minor difference
  as such, but our file digests use lowercase hex and this gets
  called a lot from rpmfiNew().
2012-09-03 15:44:53 +03:00
Panu Matilainen 429b933b42 Revert "Always return NULL from fdFree()"
- This reverts commit 4c1f7e335de1724661ce63c53186d161ab71a63f:
  various things inside and outside of rpm actually do still depend
  on the old behavior, and leak file descriptors otherwise.
  As an easy backportable band-aid, revert back to the previous
  behavior, to which various callers are tuned to fix the regression
  introduced in rpm 4.10.0. The real fix would be something more like
  "eliminate fdFree() and make Fclose() honor refcounts".
2012-08-17 11:37:21 +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
Panu Matilainen ac8a0175be Only use local mempcpy() if system libraries dont provide one
- Obvious yes, but how come this didn't barf on my other rather
  identical system? Meh.
2012-05-31 18:10:33 +03:00
Panu Matilainen 794e24456a xmalloc() and xrealloc() never fail, remove redundant checks 2012-05-31 16:55:37 +03:00
Panu Matilainen a48c369a44 Call alloca() and stat() by their own names... 2012-05-31 16:48:57 +03:00
Panu Matilainen 0d9cfcc07f Eliminate unnecessary glob portability fiddles
- Flags available to our internal glob implementation do not depend on
  posix/gnu/bsd defines
2012-05-31 16:48:52 +03:00
Panu Matilainen 68f991e50c Eliminate VMS, MS-DOS, Windows and Amiga compatibility hacks in rpmglob
- We'll never run on these platforms, we just dont care...
2012-05-31 16:48:46 +03:00
Panu Matilainen b1e9413a5b Eliminate shell interruptability hack in rpmglob 2012-05-31 16:48:41 +03:00
Panu Matilainen 8516fc2212 We always have xstrdup() available, eliminate redundant alternatve 2012-05-31 16:48:33 +03:00
Panu Matilainen 493571ce23 Eliminate getpwnam_r() and getlogin_r() uses from rpmglob
- We dont particularly care if rpmGlob() is thread-safe or not,
  just use the simpler code-path
2012-05-31 16:48:28 +03:00
Panu Matilainen f2954e9b97 Eliminate mempcpy() related conditionals from rpmglob
- Provide a local copy of the trivial mempcpy() function so we can always
  use the shorter code-path, eliminate now unnecessary ifdef goo.
2012-05-31 16:48:21 +03:00
Panu Matilainen 81560ef2e5 Remove __GNUC__ conditionals on variable sized local arrays
- We require a C99 compiler anyway so these conditionals are not needed
2012-05-31 16:48:17 +03:00
Panu Matilainen 9dc4c3c2d7 Eliminate unnecessary libc header typedeffery from rpmglob
- No doubt important bits in glibc but unnecessary goo for our
  internal implementation.
2012-05-31 16:48:11 +03:00
Panu Matilainen 3e05597ba9 Run indent -kr on the glob implementation
- rpm style isn't exactly K&R but close enuf for goverment work
  and prevent sore eyes now that this is a "real" part of rpm.
2012-05-31 16:47:40 +03:00
Panu Matilainen bf088dbeb5 Bury our glob() implementation entirely inside rpmglob.c (RhBug:819680)
- Lump glob.h and glob.c into rpmglob.c in all their g(l)ory libc
  decorations and make everything static to stop overriding system
  library symbols with our own glob().
2012-05-31 16:46:40 +03:00
Panu Matilainen 38932d1d17 Export our own version of glob_pattern_p() as rpmIsGlob()
- Further preliminaries to hiding the glob() implementation
2012-05-31 16:45:32 +03:00
Panu Matilainen a6821de783 Split rpmGlob() to a separate source file
- As a preliminary step to hiding our internal glob implementation,
  split our only glob() user to a source of its own.
2012-05-31 16:45:26 +03:00
Christophe Fergeau 185596818f Add support for 7zip compressed tarballs
Teach %prep and %uncompress how to handle 7zip tarballs, with
the mingw toolchain landing in fedora, this may be useful when
crossbuilding Windows sources compressed using 7zip (CxImage is
one such project).
2012-05-22 13:48:01 +03:00
Panu Matilainen 7df78ae466 Split prelink checking into a helper function
- No functional changes, just makes the thing a little bit more readable
  as the ELF details are buried out of sight in the helper
2012-05-21 15:15:34 +03:00
Panu Matilainen db782b4b62 Keep the macro buffer terminated on append
- This isn't strictly needed as we're terminating the buffers "just in
  case" all over the place but handling this centrally might allow
  some day eliminating the other fluff...
2012-05-10 11:49:24 +03:00
Panu Matilainen 6101cac6b3 Fix off-by-ones in mbAppend() and mbAppendStr()
- Oops, remember to reserve space for the trailing \0 when appending.
  mb->nb holds the number of actual characters left in the buffer,
  not the terminator. Fixes a regression introduced in rpm 4.9.x
  dynamic macro realloction work (RhBug:431009 reprise)
2012-05-10 11:28:39 +03:00
Panu Matilainen 4c1f7e335d Always return NULL from fdFree()
- Up to now, if the fd had remaining references fdFree() would return
  the supposedly free'd fd back to us, which is unlike anything else
  in rpm. Make this consistent with the rest of rpm finally as the
  last remaining caller requiring the old semantics is gone from
  the codebase (somewhere between 4.9 and 4.10): always return NULL,
  as the referenced instance is now gone as far as the caller is concerned.
2012-04-18 10:19:25 +03:00
Panu Matilainen 8a189c6383 Oops, "magic eight" is necessary here afterall
- Fix regression from commit 807b402d95,
  the array gets passed as a pointer (how else would it work at all),
  so despite having seemingly correct type, sizeof(keyid) depends
  on the pointer size. This happens to be 8 on x86_64 and friends
  but breaks pgp fingerprint calculation on eg i386.
- Also return the explicit size from pgpExtractPubkeyFingerprint(),
  this has been "broken" for much longer but then all callers should
  really care about is -1 for error.
2012-03-22 12:34:08 +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 ff0eed0552 Unbreak lua's base64 encode/decode extensions
- Commit 70f063cb77 accidentally
  changed lua's base64 encode/decode interface too, ugh. Dangers of
  search-and-replace... Only the function name string exported to
  lua matters but renaming the internal functions back as well
  for naming consistency.
2012-03-14 11:35:37 +02:00
Panu Matilainen aa90bda89b Fix ufdCopy() for large (> 2GB) files
- Files can be (much) larger than INT32_MAX, change the return
  type to off_t and fix + simplify the calculations. Fixes the other
  half of RhBug:790396 and makes ufdCopy() usable for other purposes too.
2012-03-14 11:19:47 +02: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 9e58316b0f Add a signature verification method to keyring
- At least within rpm itself, callers aren't particularly interested
  in the actual key that matches a given signature, they just want
  simple good/bad/nokey answers. This makes life simple for them
  and avoids exposing further rpmPubkey internals through APIs.
2011-11-09 13:09:37 +02:00
Panu Matilainen 6f7700dbed Split keyring find-by-signature to helper function, document...
- Document the broken rpmKeyringLookup() behavior / side-effect,
  the new helper uses the values from our stored pgp parameters though.
- Shouldn't make any difference functionality-wise, but we'll need
  the helper function shortly.
2011-11-09 12:51:39 +02:00
Panu Matilainen 564242f23b Parse pubkey parameters on rpmPubkeyNew() already and store results
- Yet more pre-requisites for separating key and signature management.
  In addition this gains us more thorough initial sanity checking and
  will allow reusing the parameters instead of having to parse
  the same packets over and over again on every single verification
  against this key. Unfortunately rpmKeyringLookup() is so braindead
  it prevents us from doing this right now, we'll need a better
  interface to take advantage of the stored pgp key parameters.
2011-11-09 11:59:31 +02:00
Panu Matilainen 345a061240 Add an alternative API for parsing PGP packets
- pgpPrtParams() returns a pointer to an allocated pgpDigParams
  on success, eliminating the need for callers to worry about
  freeing "target buffer" on failure and bypassing the now rather
  useless pgpDig middleman. Also allows specifying the expected
  packet type so if we expect a key we'll error out if we get a signature
  instead.
- pgpPrtPkts() is basically just a wrapper to pgpPrtParams()
- Further pre-requisites for separating key and signature management.
- Yes, pgpPrtParams() is a stupid name for this. However all the saner
  ones are already taken for other purposes (for which the names are
  just as bad/misleading, sigh)
2011-11-09 11:54:40 +02:00
Panu Matilainen 0bed4327fc Allocate signature and pubkey dynamically within pgpDig on PGP parse
- This way we can parse the whole thing into a private storage first
  and only if its actually successful we return anything through the
  pgpDig. Previously we would return partial garbage on failure
  and/or consecutive calls unless manually "cleaned" as we were
  parsing directly into the pgpDig.
- Dynamic allocation is a pre-requirement separating management of
  keys and signatures: while they walk hand in hand much of the time,
  they come from different sources and have different lifetimes and
  should be managed separately.
- Dynamic allocation of these is also a pre-requirement for handling
  more than one public key, ie mainly subkeys.
2011-11-09 10:49:23 +02:00
Panu Matilainen dbb303fe15 Use pgpDigGetParams() in pgpVerifySig() compat wrapper too
- The fewer places that "know" about pgpDig allocation internals the better...
2011-11-09 09:37:15 +02:00
Panu Matilainen 917a5c4f6b Revert "Take advantage of pgpDigParamsCmp() in rpmKeyringLookup()"
- This only "works" because of other brokenness in the sig/key
  parsing, revert while we can
- This reverts commit 4c51eff3f0.
2011-11-08 15:08:01 +02:00
Panu Matilainen 8b524080c6 Tolerate NULL key in pgpVerifySignature() 2011-11-08 14:08:40 +02:00
Panu Matilainen 1581f4e5c0 Eliminate unused params member from pgpDigParams
- Rpm has never used this for anything, amounting to helluva lot
  unnecessary free()'s over the years.
2011-11-07 15:41:43 +02:00
Panu Matilainen 4c51eff3f0 Take advantage of pgpDigParamsCmp() in rpmKeyringLookup()
- Besides eliminating a couple of direct struct accesses,
  pgpDigParamsCmp() does a much more thorough job of comparing
  the parameters than we ever did here (ie less chance for returning
  ok for for a wrong key, although because the interface is as
  braindead as it is, it doesn't make a whole lot of difference)
2011-11-07 14:49:47 +02:00
Panu Matilainen a6f25aff43 Add ad API for retrieving algorithm values from digest parameter containers
- Mildly annoying but necessary in order to make pgpDigParams properly
  opaque some day (and also allow sane access to this data)
2011-11-07 14:42:31 +02:00