Commit graph

2688 commits

Author SHA1 Message Date
Rikard Falkeborn
f2a7fb2b96 Fix clang 8 string-plus-int warnings
Clang 8 warns that adding a string to an integer does not append to
string. Indeed it doesn't, but that was not the intentetion. Use array
indexing as suggested by the compiler to silence the warning. There
should be no functional change.

Example of warning message:

    alpm.c:71:54: warning: adding 'int' to a string does not append to the string [-Wstring-plus-int]
            sprintf(hookdir, "%s%s", myhandle->root, SYSHOOKDIR + 1);
                                                     ~~~~~~~~~~~^~~
    alpm.c:71:54: note: use array indexing to silence this warning
            sprintf(hookdir, "%s%s", myhandle->root, SYSHOOKDIR + 1);
                                                                ^
                                                     &          [  ]
    1 warning generated.
2019-05-08 10:12:14 +10:00
Eli Schwartz
0a72874734 build: check for gpgme with pkg-config before gpgme-config
gpgme in git master now supports pkg-config and with the next release we
can and should prefer its use. However, retain the legacy code that
enables building with older versions of gpgme, as a fallback.

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Allan McRae <allan@archlinux.org>
2019-03-19 14:05:53 +10:00
Florian Wehner
c61cd050f9 Reformatting log timestamp to include time-zone
The time logged is currently given as localtime without any timezone
information. This is confusing in various scenarios.

Examples:
* If one is travelling across time-zones and the timestamps in the log
appear out of order.
* Comparing dates with `datediff` gives an offset by the time-zone

This patch would reformat the time-stamp to a full ISO-8601 version.
It includes the 'T' separating date and time including seconds.

Old: [2019-03-04 16:15]
New: [2019-03-04T16:15:45-05:00]

Signed-off-by: Florian Wehner <florian@whnr.de>
Signed-off-by: Allan McRae <allan@archlinux.org>
2019-03-19 11:53:30 +10:00
Allan McRae
c0e9be7973 Remove support for deltas from libalpm
Signed-off-by: Allan McRae <allan@archlinux.org>
2019-03-07 11:12:12 +10:00
Andrew Gregory
d197d8ab82 Sanitize file name received from Content-Disposition header
When installing a remote package with "pacman -U <url>", pacman renames
the downloaded package file to match the name given in the
Content-Disposition header. However, pacman does not sanitize this name,
which may contain slashes, before calling rename(). A malicious server (or
a network MitM if downloading over HTTP) can send a content-disposition
header to make pacman place the file anywhere in the filesystem,
potentially leading to arbitrary root code execution. Notably, this
bypasses pacman's package signature checking.

For example, a malicious package-hosting server (or a network
man-in-the-middle, if downloading over HTTP) could serve the following
header:

Content-Disposition: filename=../../../../../../usr/share/libalpm/hooks/evil.hook

and pacman would move the downloaded file to
/usr/share/libalpm/hooks/evil.hook. This invocation of "pacman -U" would
later fail, unable to find the downloaded package in the cache directory,
but the hook file would remain in place. The commands in the malicious
hook would then be run (as root) the next time any package is installed.

Discovered-by: Adam Suhl <asuhl@mit.edu>
Signed-off-by: Allan McRae <allan@archlinux.org>
2019-03-01 11:23:20 +10:00
Mark Ulrich
db102c67ef libalpm: prevent 301 redirect loop from hanging the process
If a mirror responds with a 301 redirect to itself, it will create an
infinite redirect loop. This will cause pacman to hang, unresponsive to
even a SIGINT. The result is pacman being unable to sync or
download any package from a particular repo if its current mirror
is stuck in a redirect loop. Setting libcurl's MAXREDIRS option
effectively prevents a redirect loop from hanging the process.

Signed-off-by: Mark Ulrich <mark.ulrich.86@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2019-02-07 09:51:01 +10:00
morganamilo
04e77591d6 fix various typos
Signed-off-by: morganamilo <morganamilo@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2019-02-04 10:17:30 +10:00
morganamilo
4d1d857ef0 libalpm: fix minor typo in _alpm_db_usage_
Signed-off-by: morganamilo <morganamilo@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2019-01-21 13:47:23 +10:00
Allan McRae
e9d91a688d libalpm/sync.c: change alpm_sync_newversion() to alpm_sync_get_new_version()
The behaviour of "pacman -Qu" was very strange...  It would only consider
packages from repos with Usage = Search (or All), and ignore those with
Usage = Sync, Install or Upgrade.

This is because the function alpm_sync_newversion() used ALPM_DB_USAGE_SEARCH
for its filtering. Given this function is documented (at least in the source)
to "Check for new version of pkg in sync repos", I would expect that to look at
all repos. However, just changing this parameter, would result in a fairly
silent change in behaviour of this function. Instead, rename the function
and remove this filtering altogether.  Users of this function can filter
the dbs passed to this function to achieve their desired output.

Signed-off-by: Allan McRae <allan@archlinux.org>
2019-01-10 14:14:04 +10:00
Allan McRae
9b637cc27a be_local.c: remove aligment in local_pkg_ops
The alignment was not overly helpful and caused unnecessary churn when a new
value with longer name was added.

Signed-off-by: Allan McRae <allan@archlinux.org>
2019-01-10 14:10:55 +10:00
morganamilo
f9eb2aacb4 libalpm: parse {check, make}depends when reading database
Commit 0994893b0e added the
alpm_pkg_get_{make,check}depends functions but forgot to include
logic for parsing these fields from the database. As a result these
functions will always return an empty list.

This commit adds the parsing logic.

Signed-off-by: morganamilo <morganamilo@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2019-01-10 14:04:59 +10:00
Michael Straube
e1fc2f901e libalpm/add.c: move assignment into conditional in alpm_add_pkg
While at it and for consistency move the assignment of the variable
'local' into the subsequent conditional.

Signed-off-by: Michael Straube <michael.straube@posteo.de>
Signed-off-by: Allan McRae <allan@archlinux.org>
2019-01-04 11:32:49 +10:00
Michael Straube
3a5a0d53bc Move skipping of duplicate sync/remove targets into libalpm
sync:
As pointed out by Andrew Gregory there could be an error when adding
duplicates if they are two separate packages with the same name. Add a
check in alpm_add_pkg() to test whether the duplicate is actually the
same package, and if so, log a debug message and return success to skip
the package. If the duplicate is a different package return
ALPM_ERR_TRANS_DUP_TARGET and treat that error just like any other error
in pacman.

remove:
Change alpm_remove_pkg() to just log a debug message and return success
to skip duplicates. Remove the handling of ALPM_ERR_TRANS_DUP_TARGET in
pacman.

Also fixes FS#49377.

Suggested-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Michael Straube <michael.straube@posteo.de>
Signed-off-by: Allan McRae <allan@archlinux.org>
2019-01-04 11:31:55 +10:00
Andrew Gregory
33a8ced334 silence warning when built without curl
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2019-01-04 11:08:54 +10:00
Andrew Gregory
f28ddd9d93 check localdb before upgrading package
Commit 2ee7a8d89a replaced a manual check
for a local package with a check for the "oldpkg" member, which gets set
at the beginning of the transaction.  If the package was also in the
remove list, such as when a package gets replaced, it would no longer be
in the local db and pacman would try to remove it twice, resulting in
superfluous error messages.

Fixes: FS#50875, FS#55534

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2018-12-10 11:12:06 +10:00
Andrew Gregory
44cfc09511 require actual siglevel for default
ALPM_SIG_USE_DEFAULT does not refer to an actual siglevel, rather it
indicates that the global default should be used in place of the
operation-specific one.  Setting this value for the global default
itself makes no sense.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2018-11-27 22:48:43 +10:00
Andrew Gregory
61fe738043 always allow explicit empty siglevel for sync dbs
An empty siglevel does not do any signature verification which is
exactly what we want when compiled without gpg support.  This is already
allowed in other parts of the codebase and required for the test suite
to pass when compiled without gpg support.

Fixes: FS#60880

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2018-11-27 22:48:43 +10:00
Andrew Gregory
3726693612 add specific error for missing gpg support
"wrong or NULL argument passed" is a useless error for end users.

Fixes FS#60880.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2018-11-27 22:48:43 +10:00
Dave Reisner
51db84750e Add meson.build files to build with meson
Provide both build systems in parallel for now, to ensure that we work
out all the differences between the two. Some time from now, we'll give
up on autotools.

Meson tends to be faster and probably easier to read/maintain. On my
machine, the full meson configure+build+install takes a little under
half as long as a similar autotools-based invocation.

Building with meson is a two step process. First, configure the build:

  meson build

Then, compile the project:

  ninja -C build

There's some mild differences in functionality between meson and
autotools.  specifically:

1) No singular update-po target. meson only generates individual
update-po targets for each textdomain (of which we have 3).  To make
this easier, there's a build-aux/update-po script which finds all
update-po targets and runs them.

2) No 'make dist' equivalent. Just run 'git archive' to generate a
suitable tarball for distribution.
2018-11-02 03:16:34 -04:00
Andrew Gregory
ac959bb9c6 handle EINTR while polling scripts/hooks
If poll() is interrupted by a signal, alpm was closing the socket it
uses for listening to script/hook output.  This would drop script output
at the least and kill the script at the worst.

Fixes FS#60396

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2018-10-21 19:19:48 +10:00
Andrew Gregory
9886566abb reset signal handlers before running scripts/hooks
Front-ends or libraries may set signals to be ignored, which gets
inherited across fork and exec.  This can cause scripts to malfunction
if they expect the signal.  To make matters worse, scripts written in
bash can't reset signals that were ignored when bash was started.

Fixes FS#56756

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2018-10-21 19:18:29 +10:00
morganamilo
02255fd97e libalpm: process needed before group selection
When --needed is used, up to date packages are now filtered out
before showing the group select.

Fixes FS#22870.

Signed-off-by: morganamilo <morganamilo@gmail.com>
2018-10-20 12:08:27 -07:00
Olivier Brunel
ffde85aadf alpm: Fix SIGINT handling re: aborting download
Upon receiving SIGINT a flag is set to abort the (curl) download.
However, since it was never reset/initialized, if a front-end doesn't
actually exit on SIGINT, and later tries any operation that needs to
perform a new download, said download would always get aborted right
away due to the flag not having been reset.
2018-10-17 17:28:32 -07:00
Olivier Brunel
d96d0ffe7c alpm: Do not raise SIGINT when filesize goes over limit
Variable dload_interrupted is used both to abort a download because
SIGINT was caught, and when a file limit is reached. But raising SIGINT
is only meant to happen in the first case.

Signed-off-by: Olivier Brunel <jjk@jjacky.com>
2018-10-17 17:28:32 -07:00
David Phillips
192d6166e9 User-visible log when validity check fails due to access
Currently, if checking the validity of packages fails due to an access
error on one or more packages, the user must sift through debug output
in order to find the culprit package(s). This patch adds a call to
_alpm_log in such a case to make the culprits more easily visible.

Signed-off-by: Allan McRae <allan@archlinux.org>
2018-09-19 17:04:45 +10:00
David Phillips
b54b33d816 Change if-else chain to switch
Signed-off-by: Allan McRae <allan@archlinux.org>
2018-09-19 17:04:38 +10:00
Allan McRae
7d05ffceaf Remove the last traces of the pacman --force option
Signed-off-by: Allan McRae <allan@archlinux.org>
2018-08-10 12:38:03 +10:00
Michael Straube
9e960d9d5a libalpm/dload.c: add case for CURLE_COULDNT_RESOLVE_HOST
Add a case for curl error 'Could not resolve host'.
An attempt to fix FS#48285.

Signed-off-by: Michael Straube <straubem@gmx.de>
Signed-off-by: Allan McRae <allan@archlinux.org>
2018-08-10 12:37:19 +10:00
Jouke Witteveen
7f1f1355bb libalpm: ignore .hook suffix when sorting hooks
It is desirable to have 'a-post.hook' ordered after 'a.hook'. For this,
it is needed to ignore the suffix when sorting.

Signed-off-by: Allan McRae <allan@archlinux.org>
2018-08-10 12:37:19 +10:00
Allan McRae
13fb2430e8 Pull updated translations from Transifex
Signed-off-by: Allan McRae <allan@archlinux.org>
2018-07-27 10:38:57 +10:00
Allan McRae
0827aff85e Handle root prefix in overwrite operations
The pacman --overwrite operation currently expects a path without
the root prefix specified.  This is unexpected, particularly
given our conflict error message reports the path with the root
prefix included.

This patch allows libalpm to overwrite files with the root prefix
specified.

Signed-off-by: Allan McRae <allan@archlinux.org>
2018-07-27 10:24:57 +10:00
Michael Straube
72263e22bd libalpm/dload.c: fix filename in license header
The filename in the license header did not match the actual filename
as in the other files. Hopefully this is not too nit-picky.

Signed-off-by: Michael Straube <straubem@gmx.de>
Signed-off-by: Allan McRae <allan@archlinux.org>
2018-06-18 16:28:04 +10:00
Allan McRae
ca128f2eff Pull updated translations from Transifex
Also remove any translations that are less than 75% complete.  These will
be readded once translation completion passes our minimum threshold.

Signed-off-by: Allan McRae <allan@archlinux.org>
2018-05-28 09:25:04 +10:00
Allan McRae
652438772e Pull translations from Transifex and regenerate
Signed-off-by: Allan McRae <allan@archlinux.org>
2018-05-15 11:03:42 +10:00
Eli Schwartz
860e4c4943 Remove all modelines from the project
Many of these are pointless (e.g. there is no need to explicitly turn on
spellchecking and language dictionaries for the manpages by default).

The only useful modelines are the ones enforcing the project coding
standards for indentation style (and "maybe" filetype/syntax, but
everything except the asciidoc manpages and makepkg.conf is already
autodetected), and indent style can be applied more easily with
.editorconfig

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Allan McRae <allan@archlinux.org>
2018-05-14 09:59:15 +10:00
Eli Schwartz
af6125fbcc Fix gcc8 warnings.
Attempting to compile pacman with gcc8 results in several warnings like:

remove.c: In function ‘unlink_file.isra.4’:
remove.c:407:34: warning: ‘.pacsave.’ directive output may be truncated writing 9 bytes into a region of size between 1 and 4096 [-Wformat-truncation=]

Fix by adding checks to error out if snprintf tries to reserve a
truncated filename. Because the return values are checked, gcc delegates
the truncation response to our code instead of throwing warnings.

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Allan McRae <allan@archlinux.org>
2018-05-12 21:36:35 +10:00
Allan McRae
c3402ab44e add missing newline to error message
Signed-off-by: Allan McRae <allan@archlinux.org>
2018-04-30 00:43:06 +10:00
Allan McRae
4d1e27957d Initial translation preparation for pacman-5.1
Signed-off-by: Allan McRae <allan@archlinux.org>
2018-04-29 23:56:07 +10:00
Allan McRae
254a8e2e05 Import updated translations from Transifex
Signed-off-by: Allan McRae <allan@archlinux.org>
2018-04-29 23:43:07 +10:00
Allan McRae
6018063ef6 Update POTFILES.in
Add all files to the relevant POTFILES.in.  This avoids missing
translations added to old files.

Signed-off-by: Allan McRae <allan@archlinux.org>
2018-04-29 22:44:46 +10:00
Eli Schwartz
ab7393c53e libalpm.pc: migrate to Requires.private
pkg-config has built-in dependency handling, but we currently insert the
raw $LIBS into libalpm's own linker flags and fail to handle Cflags at
all.

For dependencies which support pkg-config, simply use that instead.

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Allan McRae <allan@archlinux.org>
2018-04-29 21:57:17 +10:00
Allan McRae
b6bb8cb7dc Update coyrights for 2018
make update-copyright OLD=2017 NEW=201

Signed-off-by: Allan McRae <allan@archlinux.org>
2018-03-14 13:31:31 +10:00
Stefan Klinger
d884a791b9 hooks: Complain if hook parameters are overwritten. Fixed 2 space leaks.
Signed-off-by: Stefan Klinger <git@stefan-klinger.de>
Signed-off-by: Allan McRae <allan@archlinux.org>
2018-03-14 12:53:52 +10:00
Allan McRae
e8462a4f88 Support new OpenPGP format packets lengths
RFC 4880 defines two packet formats for OpenPGP.  Pacman aborted its key
in keyring check with an error message if it encountered the new format.
This was fine until some annoying Arch Trusted User generated a key
using the new format!

Implement the new format.  This also required parsing the hashed sub
packets. requiring the parsing code to moved to its own function.

Signed-off-by: Allan McRae <allan@archlinux.org>
2018-01-11 15:58:05 +10:00
Andrew Gregory
4d80d87f90 add missing newline to debug message
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2018-01-10 10:53:15 +10:00
Andrew Gregory
2bda849bf9 detect pkghash allocation failure
If rehash ever failed with a full hash it would return the old hash
that is already full.  get_hash_position would then loop forever
because it would never find an empty bucket.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2018-01-10 10:52:26 +10:00
Allan McRae
59b6fdeee1 Do not continuously try to open an invalid database
If you manage to download a bad database (e.g. an html file when
behind a proxy or with a badly configured webserver), pacman makes
sure you know about it.  Here is some example output:

error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format
error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format
error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format
error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format
error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format
error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format
error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format
error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format
error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format
error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format
error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format
error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format
error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format
error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format
error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format
error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format
error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format
error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format
error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format
error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format
error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format
error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format
error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format
error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format

I don't know how many times that gets printed because it goes beyond my scrollback
buffer.

Flag a database that we can "open" and "fstat" but not read from as invalid to avoid
this.

Signed-off-by: Allan McRae <allan@archlinux.org>
2018-01-10 09:53:40 +10:00
Andrew Gregory
3a9a510ca8 do not rely on name hashes for matching
6cfc4757b9 was overzealous in attempting
to optimize away a call to strcmp based on a comparison of hashes.  The
call can be skipped if the hashes are different, but different strings
could have the same hash.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2018-01-06 13:35:48 +10:00
Andrew Gregory
59bb21fce3 dload: ensure callback is always initialized once
Frontends rely on an initialization call for setup between downloads.
Checking for intialization after checking for a completed download can
skip initialization in cases where files are small enough to be
downloaded all at once (FS#56408).  Relying on previous download size
can result in multiple initializations if there are multiple
non-transfer events prior to the download starting (fS#56468).

Introduce a new cb_initialized variable to the payload struct and use it
to ensure that the callback is initialized exactly once prior to any
actual events.

Fixes FS#56408, FS#56468

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2018-01-06 12:59:32 +10:00
Andrew Gregory
d0981d4c5b avoid printing NULL string
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
2018-01-06 12:56:54 +10:00