Commit graph

2971 commits

Author SHA1 Message Date
morganamilo
fff9296478
libalpm: improve error message for expired keys (cont)
Continuation of last commit.

Changes:

error: failed to commit transaction (invalid or corrupted package (PGP signature))

To:

error: failed to commit transaction (package signature has missing or invalid PGP key)
2025-08-01 09:41:56 +01:00
morganamilo
f42b93dd7f
libalpm: improve error message for expired keys
If the user does not update their system for a while some of the package
keys may expire. Pacman gives this message:

error: simdjson: signature from "Bert Peters (packager key)
<bertptrs@archlinux.org>" is unknown trust

While this is technically true it masks the real issue of the key being
expired.

This commit changes that error message to:

error: simdjson: key  "Bert Peters (packager key) <bertptrs@archlinux.org>" (38100C24376CD5F6ED4FF4B46918400C2703040C)
2025-08-01 06:15:06 +01:00
morganamilo
beb6bd80cd
libalpm: set errno when key is missing from keyring
There was no fitting error type for this so add ALPM_ERR_KEY_MISSING.
2025-08-01 04:09:26 +01:00
morganamilo
48a784dde8 libalpm: fix -U when pkg exists but not sig 2025-06-21 23:39:57 +10:00
morganamilo
67e3a7be36
libalpm: fix regression in downloader
Fixes failure to finalize download path if the package file already
exists but the .sig file does not.

This patch also moves .sig.part files which should be done for
completeness although it's probably rare/inconsequential for them to
exist.

Hopefully this is now the right approach now. The logic is as follows:

  Check if dest_name or temp_name exists and try to move whichever
  does.

  If neither exist assume we're just downloading sig files and don't
  error.

  Figure out the .sig base filename.

  Try to move the .sig file if one was needed and if that fails try
  move the .sig.part file.

The patch leaves the logging as is. Maybe we should check if moves fail
for reasons other than non existence and log it properly. Though this is
probably rare and pacman will error out later anyway.

Fixes #256
2025-05-30 14:48:14 +01:00
morganamilo
45c4eef61d libalpm: move tempdir cleanup into _alpm_download
this ensures the dir still gets cleaned up even if killed by a signal
2025-05-26 16:13:06 +10:00
morganamilo
5c451cd976 libalpm: propagate signal from child to parent
If we ^C while downloading the parent should propagate so pacman can
exit as it did before the sandboxing.
2025-05-26 16:13:06 +10:00
morganamilo
d87dd153fc libalpm: finalize tempfile if destfile doesn't exist
On setup we move the termfile into the temp download dir to resume
downloads. We don't move these back losing any tempfiles we already had.
2025-05-26 16:13:06 +10:00
morganamilo
6fcecbd08d libalpm: set errno if child exited via signal 2025-05-26 16:13:06 +10:00
morganamilo
e392f01a94 libalpm: move sig files when download is unnamed 2025-05-17 12:03:42 +10:00
morganamilo
f722b86990 libalpm: return final final temp path in pkgurl
When downloading unnamed files via alpm_fetch_pkgurl the returned path
would point to the temp pkgcache instead of the final download location.
2025-05-17 12:03:42 +10:00
Allan McRae
53b1db84ef Fix memory leak in download payload
The file stream associated with downloads without a filename is not
being freed when downloading using the sandbox user.

Signed-off-by: Allan McRae <allan@archlinux.org>
2025-05-17 10:40:09 +10:00
Allan McRae
692f7a2cfe Do not overwrite default download user when option is unset
Commit 7ccf316c provided "root" (or the user name for UID 0) as a
default download user.  However, when DownloadUser is unset in pacman.conf,
pacman was overwriting the default with null. Rectify this.

Fixes #248

Signed-off-by: Allan McRae <allan@archlinux.org>
2025-05-08 21:49:56 +10:00
morganamilo
b104b95423 log and set errno when failing to rename download 2025-05-07 18:22:55 +10:00
Allan McRae
d0c10a795e Free memory on failure to create temporary directory
Signed-off-by: Allan McRae <allan@archlinux.org>
2025-05-06 17:02:35 +10:00
Allan McRae
0d37c1daa0 Initialise callback event fields
While the event is already globally initialised, initialising the fields
prevents a valgrind warning (since the gcc-15 update).

Signed-off-by: Allan McRae <allan@archlinux.org>
2025-05-06 17:00:06 +10:00
Diego Viola
24fc50269d Fix typos 2025-05-04 21:42:34 +10:00
Allan McRae
f13d7d480c Update copyright years
./build-aux/update-copyright 2024 2025

Signed-off-by: Allan McRae <allan@archlinux.org>
2025-04-02 11:35:34 +10:00
Allan McRae
e65b7d421c Add accessor for handle->disable_dl_timeout
Signed-off-by: Allan McRae <allan@archlinux.org>
2025-01-10 04:36:49 +00:00
Allan McRae
e6b3eb2570 Add accessor for handle->disable_sandbox
Signed-off-by: Allan McRae <allan@archlinux.org>
2025-01-10 04:36:49 +00:00
Allan McRae
7ccf316ceb Provide a default sandboxuser
If sandboxuser is not set, pacman/libalpm does not handle moving
incomplete download files out of the temporary download directories
and into the cache. This leave download_XXXXXX directories in the
cache that cause warnings on -Sc operations.

Initialise the sandboxuser with the username of UID 0 (root on most
systems).

Fixes #209.

Signed-off-by: Allan McRae <allan@archlinux.org>
2025-01-09 12:14:25 +10:00
Integral
cb940620bc
fix: make dependency cycle a debug message 2024-12-10 21:10:35 +08:00
Integral
dd55afad68 refactor: use c99 struct initializers to enhance readability 2024-12-10 10:18:40 +00:00
Allan McRae
775db50538 Remove pubkey_algo from alpm_pgpkey_t
This field is no longer used and requires updating with gpgme changes.

Signed-off-by: Allan McRae <allan@archlinux.org>
2024-12-07 22:13:49 +10:00
Allan McRae
95a7d416ce Do not identify the public key algorithm
When the import key message was pushed to the pacman frontend, we no longer
displayed the length or algorithm used for the key, sticking to just the
user ID and the key ID.

Remove this code given this field is no longer used, and the code requires
updating for any now algorithm added.

Note: removal of the field from the alpm_pgpkey_t will happen in a separate
commit so that this commit can be readily backported.

Signed-off-by: Allan McRae <allan@archlinux.org>
2024-12-07 22:07:29 +10:00
Guillaume
a2d029388c fix a segfault in sandbox.c if handle->dlcb is null 2024-09-28 08:10:46 +00:00
Chih-Hsuan Yen
e80569f5da Correctly configure landlock for older ABIs
For example, with landlock ABI < 3, LANDLOCK_ACCESS_FS_TRUNCATE is not
set in ruleset_attr.handled_access_fs, so it should not be set in
path_beneath.allowed_access either. Otherwise, landlock_add_rule fails
with -EINVAL, and pacman complains:

> error: restricting filesystem access failed because the landlock rule for the temporary download directory could not be added!

The change is tested on Debian Bookworm kernel
linux-image-6.1.0-25-cloud-amd64 6.1.106-3.
2024-09-28 00:35:10 +00:00
Allan McRae
7bc5d55b56 libalpm: only chown downloaded files when running as root
Some libaplm utilities sync databases as a non-root user for use in
actvities other than system updates.  The ability to download as a
non-root user was broken as part of the download sandboxing.

Applying a minimial fix by preventing the chown of the downloaded file
if the user is non-root.  A larger change increasing the robustness
and error checking of this path is warranted in the future.

Signed-off-by: Allan McRae <allan@archlinux.org>
2024-09-08 11:49:21 +10:00
Remi Gacogne
cf473bcfbd Ensure that the download process cannot get new privileges
Signed-off-by: Remi Gacogne <rgacogne@archlinux.org>
2024-08-02 00:39:45 +00:00
Remi Gacogne
f142df92c7 Restrict syscalls for the download process whenever possible
Signed-off-by: Remi Gacogne <rgacogne@archlinux.org>
2024-08-02 00:39:45 +00:00
Allan McRae
aa1c64b21a Update translations for release
Signed-off-by: Allan McRae <allan@archlinux.org>
2024-07-14 19:11:18 +10:00
Allan McRae
9841f14f81 Prepare tranlsation strings for 7.0.0 release
Signed-off-by: Allan McRae <allan@archlinux.org>
2024-07-14 19:05:03 +10:00
Allan McRae
95e71ce52b Tidy up landlock check
This test was flagged as ambiguous by clang.

Signed-off-by: Allan McRae <allan@archlinux.org>
2024-07-14 19:03:23 +10:00
Allan McRae
cc0292a1ad Revert "_alpm_archive_fgets(): bail early if reached end of block"
This reverts commit 4dc21b965b.

Causes a segfault when reading some repos (gz compressed?)

Fixes #166.

Signed-off-by: Allan McRae <allan@archlinux.org>
2024-07-13 22:06:10 +10:00
Andrew Gregory
16a098a44e do not sort passed list
Sorting modifies the list in place, causing any existing pointers to the
list to point to a random element.

Fixes #165

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
2024-07-11 01:27:06 -04:00
Diego Viola
50bdd3d9bc Fix typos
Signed-off-by: Diego Viola <diego.viola@gmail.com>
2024-06-30 02:28:13 -03:00
Allan McRae
c9acfc2b50 Fix error when downloading signature file for an existing package file
If a package was already downloaded but its signature file was not,
pacman would download the signature then error out despite all files
being present.

Also fixes a similar error when some, but not all, package databases
were updated with -Sy.

Fixes #156

Signed-off-by: Allan McRae <allan@archlinux.org>
2024-06-19 17:38:07 +10:00
Allan McRae
b60b779fc8 Fix calculation of space needed for download package
The calculation used the size of the package rather than the amount
remaining to download for partially downloaded packages.

Signed-off-by: Allan McRae <allan@archlinux.org>
2024-06-19 17:33:36 +10:00
Allan McRae
479f4d574a Prevent buffer overflow when using a scriptlet shell with a long path
Observed in Nixpkgs.  Fixes #157.

Signed-off-by: Allan McRae <allan@archlinux.org>
2024-06-19 07:41:11 +10:00
Remi Gacogne
9f8f94c056 Add --disable-sandbox and DisableSandbox
Signed-off-by: Remi Gacogne <rgacogne@archlinux.org>
2024-06-17 11:01:42 +10:00
Remi Gacogne
eacadbcc41
Restrict filesystem access to the download process whenever possible
Signed-off-by: Remi Gacogne <rgacogne@archlinux.org>
2024-06-14 09:30:20 +02:00
Remi Gacogne
24304c6df0 Fix up-to-date repo databases being redownloaded when sandboxed
Signed-off-by: Remi Gacogne <rgacogne@archlinux.org>
Signed-off-by: Allan McRae <allan@archlinux.org>
2024-06-10 19:48:20 +10:00
Allan McRae
4dc21b965b _alpm_archive_fgets(): bail early if reached end of block
Bailing early when there are 0 blocks remaining means that we do not call
memchr on a NULL string (although with a 0 size parameter).  Fixes issues
reported using -fsanitise=address,undefined

Signed-off-by: Allan McRae <allan@archlinux.org>
2024-04-08 10:34:10 +00:00
Allan McRae
f86c15e780 unlink_file: restore trailing slash on directory before checking mountpoint
The dir_is_mountpoint() function has the explicit requirement that the
trailing slash of the directory is present.  We strip the trailing slash
in unlink_file() to handle directories replaced with symlinks, but that
then affects the dir_is_mountpoint() check.

Add the trailing slash when we have established we are dealing with a
directory. Note this may fail in the case of a file managed by pacmane
with name length of PATH_MAX that has been replaced by a directory on the
file system. Bail on this unlikely scenario.

In addtion, be less fancy with adjusting length of the file char array.

Signed-off-by: Allan McRae <allan@archlinux.org>
2024-04-05 00:51:13 +00:00
Allan McRae
0ccb584262 Do not pass NULL paramenter to bsearch with empty filelist
A filelist can be non-NULL but empty (particularly with a lot of
NoExtract entries). Handle this in alpm_filelist_contains()

Identified using the undefined behaviour sanitizer.

Signed-off-by: Allan McRae <allan@archlinux.org>
2024-04-05 00:35:08 +00:00
Remi Gacogne
cfa68f7b26 Restore partially downloaded files to the temporary directory
This allows downloads to be continued.

Signed-off-by: Allan McRae <allan@archlinux.org>
2024-04-01 20:52:55 +00:00
Remi Gacogne
e1a7b83e8e Download to a temporary directory owned by the Download user
Signed-off-by: Remi Gacogne <rgacogne@archlinux.org>
Signed-off-by: Allan McRae <allan@archlinux.org>
2024-04-01 20:52:55 +00:00
Remi Gacogne
5e9bff6216 Stop trusting the Content-Disposition HTTP header 2024-04-01 20:52:55 +00:00
Allan McRae
26b7b35307 Remove random_partfile from payload struct
It is not used any more due to filling the payload structure earlier.

Signed-off-by: Allan McRae <allan@archlinux.org>
2024-04-01 20:52:55 +00:00
Allan McRae
04d04381bc libalpm: fill in more payload information before passing to downloader
Filling in more of the payload fields before passing to the downloader ensures
that the these fields do not get lost during sandboxed operations.

It also fixes the use of -U with XferCommand, but testsuite still fails due to
"404" page being downloaded for the signature. Given we can not identify this
as being a non-signature download with the XferCommand, we can just turn off
signature checking in this test.

Signed-off-by: Allan McRae <allan@archlinux.org>
2024-04-01 20:52:55 +00:00