Commit Graph

1240 Commits (cute-signatures)

Author SHA1 Message Date
Timo Teräs 7e585512f4 io: make apk_istream_get/read() fail on incomplete read 2021-07-22 15:30:08 +03:00
Timo Teräs 395e92b66e io: formalize apk_ostream_write() always writing full data 2021-07-22 15:30:08 +03:00
Timo Teräs 796d298313 rework apk_istream_splice and apk_istream_tee
- apk_istream_splice usage is converted to apk_stream_copy which
  is the newer variant. With caching enabled by default, this
  makes more sense mmapping or using separate buffers.

- apk_istream_tee is reworked to write to apk_ostream, which simplifies
  quite a bit of various things
2021-07-22 15:30:08 +03:00
Timo Teräs b559a81694 io: rework apk_istream_get_* to not return erros in blob value
The interface was slightly cumbersome, so replace these functions
to return explicit error, and make the return blob a pointer arg.
2021-07-22 15:30:08 +03:00
Timo Teräs 94c5e01038 adb: remove the now unused get_default_int() hook
It is no longer needed, and can be later reintroduced if needed.
2021-07-22 15:30:08 +03:00
Timo Teräs 3b00c0dc80 adb: unify various interfaces to adb_m_process
Removes code duplication, and puts important checks in one place.
Support seamless decompression in adbdump.
2021-07-22 15:30:08 +03:00
Timo Teräs 69bcdd23b9 adbsign: support compressed adb files 2021-07-22 15:30:08 +03:00
Timo Teräs 7af34db6cf adb: support seamless de/compression of adb files
Add compression header of adb files. Support uncompressed and
deflate compression at this time.
2021-07-22 15:30:08 +03:00
Timo Teräs 7b58f909fa convndx: add error reporting 2021-07-22 15:30:03 +03:00
Timo Teräs b2819a6d5a extract: fix integrity check failure to remove the bad file/volume 2021-07-16 10:16:32 +03:00
Timo Teräs 7b30db8dc8 genhelp: improve to work with lua 5.1
Fix the script to not contain \x00 escape which was the only new
feature used.

Fix the meson build script to use given lua interpreter for running
the genhelp.lua.

Based on patch from Daniel Golle <daniel@makrotopia.org>
2021-07-16 10:16:32 +03:00
Timo Teräs 2a25a595ce check trust in adb_trust_write_signatures()
Based on patch from Daniel Golle <daniel@makrotopia.org>
2021-07-16 10:16:32 +03:00
Ariadne Conill 34162d01fd define APK_DEFAULT_ARCH for loongarch targets
Macros used have been taken from Loongson's work-in-progress GCC 12
port.
2021-07-06 13:29:02 -06:00
Timo Teräs 22a81e8fb5 mkpkg, extract: implement support for symlinks, devices and fifos 2021-06-23 20:21:29 +03:00
Timo Teräs 2433c9d23b openssl: explicitly ignore BIO_reset() return value
This caused some -Wall errors on certain gcc versions due
to BIO_reset() being a macro with explicit cast.
2021-06-21 13:03:16 +03:00
Timo Teräs 0683b069ba db: check syscall errors in update_permissions() 2021-06-21 13:02:12 +03:00
Timo Teräs 22281fb4b5 print: handle write() errors in apk_print_progress() 2021-06-21 12:55:32 +03:00
Timo Teräs d89c219173 reduce misuse of error codes from errno.h 2021-06-19 16:10:13 +03:00
Timo Teräs 17684141fe crypto: improve compatibility
EVP_MD_CTX_set_pkey_ctx() is fairly new openssl function, and not
existing in many alternative. Use EVP_MD_CTX_reset() which is slightly
more heavy but more portable. Add also signature buffer lengths to
work with RSA.
2021-06-19 14:43:22 +03:00
Timo Teräs 8d92f9f2ae mkpkg: ignore special files with warning instead of erroring 2021-06-19 14:27:10 +03:00
Timo Teräs 2eba7f2af7 fixup some includes
- remove unneeded assert.h
- add needed limits.h
2021-06-19 14:25:54 +03:00
Timo Teräs d02b1030e9 update Makefile to include new v3 code and applets 2021-06-14 14:17:29 +03:00
Timo Teräs aeeb119fd8 crypto: make EVP_MD_CTX_FLAG_FINALISE optional
Improves compatibility with libressl, wolfssl and older openssl
libraries not having the flag. Usage of this is optional as it's
purely performance optimization related flag.
2021-06-12 08:40:53 +03:00
Timo Teräs 4403e7ec32 fix glibc build of crypto abstraction header 2021-06-11 13:51:13 +03:00
Timo Teräs 2f58322c70 fix makefile build after crypto abstraction work 2021-06-11 13:49:33 +03:00
Timo Teräs fb3d3c5e4a extract: add experimental support for uvol volumes 2021-06-11 13:35:32 +03:00
Timo Teräs 91cb2514e4 extract: new applet to extract v2 packages 2021-06-11 13:35:32 +03:00
Timo Teräs 7ce4cc4b73 add basic abstraction for cryptographic operations
- basic digesting and signing apis (subject still to fine tuning)
- update digest code, and adb signing for the thin wrapping layer
- old v1 package and database handling not updated
- default mkpkg file hash to sha256

ref #10744
2021-06-11 13:35:32 +03:00
Timo Teräs 7c9f001cda mkpkg: new applet to create v2 packages with basic functionality 2021-06-11 13:35:32 +03:00
Timo Teräs cd9aef8f7c genadb: fix maximum inner adb limit checking 2021-06-11 13:35:32 +03:00
Sören Tempel 429e5984c5 Disable progress bar on dumb terminals by default
The progress bar requires the terminal emulator to support ANSI escape
sequences. Normally, TERM is set to dumb to indicate that the terminal
emulator doesn't support any ANSI escape sequences. Attempting to use
ANSI escape sequences on dumb terminals will lead to weird output. In
order to make apk work by default, even on dumb terminals, this commit
introduces an additional check which consults $TERM and disables the
progress bar if it is set to "dumb".
2021-05-31 02:35:52 +02:00
Timo Teräs 1456296b43 add adbgen applet to generate databases from it's text dump 2021-06-02 22:35:58 +03:00
Timo Teräs 209201bc5d add abstraction to adb "walking" - a sax like API to enumerate whole db
This converts 'adbdump' applet to generate adb_walk api callbacks,
and implement gentext backend to generate the yaml-like text output.
2021-05-26 12:47:48 +03:00
Timo Teräs 7167bc9e7b solver: don't consider requirer count for preference
The original intent was to choose packages to which there is most
dependencies. However, since the code has evolved this is has been
mostly obsolete. And in fact now interferes with the provides and
provides priority mechanism. Remove this as obsolete.

Fixes #10742
2021-05-19 16:29:55 +03:00
Timo Teräs f7143c1766 io_archive: add bounds limit for uname and gname tar header fields
Modify apk_resolve_[ug]id to take the user/groupname as a blob, so
proper length checking is done and honored.

==31584== Conditional jump or move depends on uninitialised value(s)
==31584==    at 0x5C8CA5: strlen (strlen.c:17)
==31584==    by 0x432575: APK_BLOB_STR (apk_blob.h:79)
==31584==    by 0x4350EB: apk_resolve_uid (io.c:1112)
==31584==    by 0x43696C: apk_tar_parse (io_archive.c:152)
==31584==    by 0x4271BC: apk_pkg_read (package.c:929)
==31584==    by 0x402D75: add_main (app_add.c:163)
==31584==    by 0x40D5FF: main (apk-static.c:516)

Fixes a potential crash (DoS) on a crafted TAR file. CVE-2021-30139.

Reported-by: Sören Tempel <soeren+git@soeren-tempel.net>
Reviewed-by: Ariadne Conill <ariadne@dereferenced.org>
2021-04-12 15:30:14 +03:00
Timo Teräs 4bcd792194 io: fix fd leak in error handling paths
apk_dir_foreach_file and apk_resolve_[ug]id needs to free the fd in
case fdopen/fdopendir fails. Additionally this does not rely on fdopen
to fail if openat() returned -1, making sure that we don't call any
syscalls with invalid file handle.
2021-04-11 15:06:49 +03:00
Sören Tempel 1b954e4120 Fix segfault in log_internal if prefix is APK_OUT_LOG_ONLY
This commit fixes a regression which was introduced in changeset
646c834492. If apk_out_fmt() is called
while out->log is set and prefix is set to APK_OUT_LOG_ONLY, then
apk_out_fmt() would pass this prefix to log_internal() which would, in
turn, attempt to write it to standard out using fprintf().
Unfortunately, doing so wont work as intended if prefix is ((char*)-1)
(i.e. APK_OUT_LOG_ONLY) and will cause a segmentation fault instead.

This commit fixes this segmentation fault by not printing the prefix in
log_internal() if it is either NULL or APK_OUT_LOG_ONLY.
2021-04-02 12:22:25 +02:00
Drew DeVault 646c834492 Log to /var/log/apk.log
This adds a log file at /var/log/apk.log. On each run, apk's version
information and the current date & time are written to this file,
followed by any normal apk output.
2021-03-19 12:26:15 +00:00
Ariadne Conill 4fe5ac8328 database: do not chroot(".") unless actually necessary
If we use default root (/), then we do not have to chroot to run scripts.
Use APK_NO_CHROOT flag for this scenario to avoid the chroot.  This helps
with using apk with bwrap and OSTree.

Closes #10736.
2021-03-19 10:28:55 +00:00
Timo Teräs 511621438d del: report correctly package's provides names
The code assumed that when package is in world, it would be there
by it's primary name. The code is now updated to properly print the
package names that are actually present in world.

fixes #10718
2021-03-19 12:08:46 +02:00
Timo Teräs 361eb063c6 db: fix control character check to use uint8_t
fixes #10737
2021-02-07 23:43:48 +02:00
Timo Teräs 1a4f2e94dd db: consider control characters in filename as malicious
Especially a newline can produce havoc in the database file as
the filename is written there as-is. This hardenes the extraction
to consider any control character as malicious. Additional
hardening is added to database loading to better detect corrupt
state and return proper error code about it.

Reported-by: Luca Weiss <luca@z3ntu.xyz>
2021-02-04 22:30:26 +02:00
Olliver Schinagl f6656f9d8e io: Handle really long lines
While commit 18b0b45 (io: Handle long lines, Thu Jan 7 17:25:23 2021
+0100) did attempt to address this issue, the buffer really is still to
small when dealing with big-big dependency lists.

Lets make it sufficiently large for now, until the new APKINDEX format
can support multi-line dependencies, making this not needed any more.

[TT: Originally the buffer size was conservative to run on resource
constrained embedded platforms. But since the available memory on those
has also increased much, the adjustment to 128kB makes sense also to
increase performance a little bit. Removing also the iolimit test.]

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
2021-02-04 21:45:58 +02:00
Timo Teräs b43da45bc3 gunzip: fix false end-of-file condition in rare circumstances
It turns out inflate() can output zero bytes, even if it consumed
data. This had the unfortunate side effect of returning zero bytes
(end-of-file) condition before calling the boundary callbacks. This
fixes the logic to not return zero reads on gzip boundary.

In practice this fixes the seldom seen issues of apk reporting
bad signature (when it was correct).
2021-02-04 21:38:30 +02:00
Rosen Penev c4c8aa5ba0 fix compilation without deprecated OpenSSL APIs
(De)initialization is deprecated under OpenSSL 1.0 and above.

[TT: Some simplifications, and additional edits.]

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-01-27 09:13:07 +02:00
thibault.ferrante 7a3e8f4214 database.c: Fixed package DESCRIPTION parsing
Regression introduced by 0fb0d30 which makes parsing a description
a critical failure.

[TT: Minor stylistic change. Fix also missing final line change
from the earlier commit]
2021-01-14 16:19:26 +02:00
thibault.ferrante 18b0b45b5b io: Handle long lines
As an APKINDEX can become arbitrarely long due to dependencies and
other parameters, increasing the buffer size make this less likely
to happens.

Closes #10731.
2021-01-11 11:26:49 +02:00
thibault.ferrante 0fb0d30477 database: Propagate errors when loading an APKINDEX
In case of failure when loading an APKINDEX, no errors are
propagated to the user which may uncorrectly interpret the
current problem.
2021-01-11 11:26:49 +02:00
Alex Denes 9e9a9a2e71 apk_update: use URL_PRINTF 2020-12-29 13:52:29 +02:00
Timo Teräs da8d83338b add missing apk_trust.h 2020-10-09 16:18:23 +03:00
Timo Teräs 705e002bb0 rename adb_trust to apk_trust, and use it as package signature keystore too 2020-10-09 16:09:19 +03:00
Timo Teräs a627ab8eb8 make apk_database optional for applets that don't need it
The new v3 applets don't use it, and eventually all applets will
use the new formats only.

This prepares the code for this, and moves trust, id_cache, and
root_fd to apk_ctx which is enough for v3 applets at this time.

The generic code is made to not initialize apk_database if it's
not needed.
2020-10-09 16:09:19 +03:00
Timo Teräs 354713d2f7 rename apk_db_options to apk_ctx, rework logging
makes apk_verbosity non-global

fixes #10682
2020-10-09 16:09:19 +03:00
Timo Teräs 7a7eca8670 make apk_flags non-global, make progress printing state non-global
ref #10682
2020-10-09 16:09:19 +03:00
Timo Teräs 9afb4e8fd1 make apk_force non-global, remove left-over apk_arch
ref #10682
2020-10-09 16:09:19 +03:00
Timo Teräs b2af872fff db: convert repository list to a string array 2020-10-09 16:09:19 +03:00
Timo Teräs 010497cb5a add separate vertest applet for version string testing
start adding meson based tests
2020-10-09 16:09:19 +03:00
Timo Teräs 6d71f49c11 io: make ostream_file always use tmpname 2020-10-09 16:09:19 +03:00
Timo Teräs 2156107afc minor performance improvements on build and code 2020-10-09 16:09:19 +03:00
Timo Teräs f9f8594069 adb: improve sorting features, sort installed-db package listing 2020-10-09 16:09:19 +03:00
Timo Teräs e9caeff22b build: adopt meson build for v3 branch 2020-10-09 16:09:19 +03:00
Rasmus Thomsen 0cfa6cfb83 build: make sure to use helper scripts from git tree and not system 2020-10-09 16:09:19 +03:00
Rasmus Thomsen 1b168696aa build: use tabs for meson files 2020-10-09 16:09:19 +03:00
Rasmus Thomsen 1bbdc8eb37 build: add option to build apk.static binary 2020-10-09 16:09:19 +03:00
Rasmus Thomsen 8a11ac3952 build: add atom.c to meson 2020-10-09 16:09:19 +03:00
Rasmus Thomsen f6795011ca build: allow building without help in meson 2020-10-09 16:09:19 +03:00
Rasmus Thomsen 718e07f78a build: build help.h with meson 2020-10-09 16:09:19 +03:00
Rasmus Thomsen fe1de720d0 build: add support for building with meson 2020-10-09 16:09:19 +03:00
Timo Teräs efe0c4afec adb: introduce apk-tools database format, and few applets
This is a flat buffers inspired format that allows fast
mmaped access to the data with low overhead, signature support
and relatively good forward support.
2020-10-09 16:09:19 +03:00
Timo Teräs 5f66b618ef various changes to make clang not give warnings 2020-10-07 21:16:35 +03:00
Timo Teräs 3fae0c693f db: make the --repositories-file change more announced
Document the version when changed. And print error with similar note
if the given repositories-file cannot be read.
2020-10-06 14:27:59 +03:00
Paul Spooren dac30d5049 database: automatically create missing cache dir
On some systems the `/var/` dir is mounted in a tmpfs which is reseted
after each reboot. For that reason no post-install script can handle the
creation of the cache dir at `/var/cache/apk`.

Check on database opnening if the folder is available, if not create it.
Fixes #10715

Signed-off-by: Paul Spooren <mail@aparcar.org>
2020-10-06 10:02:21 +03:00
Timo Teräs 7c2a3657fb db: make --repositories-file relative to host root
It used to be relative to the --root specified root, but that
causes issues with relative command line filenames and is unintuitive.
Update documentation accordingly. Fixes #10702.
2020-10-05 16:49:57 +03:00
Timo Teräs 6cedfe27ac db: mask password component of printed URLs
fixes #10710
2020-10-05 12:58:46 +03:00
Timo Teräs 8a794021c4 commit: rephrase the error messages more understandable
fixes #10703
2020-10-03 13:58:30 +03:00
Timo Teräs c269e9c24d db: check cache only if some repositories are enabled 2020-10-01 14:31:41 +03:00
Timo Teräs c538509a2a Implement upgrade --prune to remove stale world dependencies 2020-09-28 17:38:07 +03:00
Ariadne Conill fa63e46a75 database: clarify the deprecation notice for checksum-less packages
Closes #10708.
2020-08-29 20:37:57 +03:00
Timo Teräs fb0109fdb1 fix --repository short option to be -X as before
unintentional regression from commit edb45ae464
fixes #10707
2020-08-26 23:05:03 +03:00
Timo Teräs 2408ad4f95 build: make soname explicit and simplify and fix soname link 2020-08-25 15:35:46 +03:00
Timo Teräs e2afc7e7a9 fix, simplify and document upgrade --ignore 2020-08-24 15:26:25 +03:00
Oliver Smith f3cf824948 solver: add more dbg_printfs 2020-08-24 14:25:40 +03:00
Timo Teräs edb45ae464 enforce options definitions to bind the enum and the descriptor
This uses some macro trickery to make sure that there's one-to-one
mapping with the option index enum and the descriptor. The down
side is that enum's are generated via #define's and editors might
not pick them up for auto completion, but the benefits are more:
it's no longer possible have mismatching enum value and descriptor
index, and the amount of source code lines is less.
2020-08-24 13:35:36 +03:00
Ariadne Conill bef1faf1cb upgrade: allow for specified package upgrades
Fixes #10667 and #10700
2020-07-30 11:41:35 +03:00
Ariadne Conill f4c3f0ad2a database: create additional device nodes when initializing root fs
Some triggers and maintainer scripts depend on /dev/random, /dev/urandom,
/dev/zero and /dev/console.
2020-05-27 08:29:01 +03:00
Fredrik Gustafsson 4d69d123f5 fix logic to not compile lua module when it was not asked
fixes 12fdf6fc "allow building without help..."
2020-05-19 17:03:25 +03:00
Timo Teräs d0edeec8fb make the atom functions not use global state
This greatly helps with memory management on applications that
may want to daemonize and open/close database several times.

Also the lifetime and "owner" of memory for all data is now
explicitly bound to owning struct apk_database, which might
be helpful when writing language bindings. As side effect, the
interned "atoms" are unique only within what apk_database, so
comparing packages from different apk_database may not work
as expected.

Fixes #10697
2020-05-19 12:02:56 +03:00
Timo Teräs 12fdf6fc21 allow building without help when lua interpreter is not available
fixes #10696
2020-05-19 10:50:57 +03:00
Ariadne Conill 0732976dbe define APK_DEFAULT_ARCH for riscv32 and riscv64 targets 2020-05-17 00:54:51 -06:00
Timo Teräs 7b76182f39 fix apk_blob_pull_csum to always initialize apk_checksum
Fixes #10686 to not use uninitialized value in the error paths.
2020-05-07 13:28:24 +03:00
TBK 5d796b5678 use SPDX-License-Identifier in source files 2020-05-07 10:45:42 +03:00
Fredrik Gustafsson 6863928677 index: add argument --no-warnings
When creating an index apk warns if a dependency is missing a provider.
However when using a multi-arch repository, it's not an error that
a certain architecture is missing a dependency because that dependency
could be in an other architecture. Since apk index doesn't know about
this, add an argument to disable that warning.

Maintainer note: rebased for new option handling, and minor stylistic
adjustments.

Signed-off-by: Fredrik Gustafsson <fredrigu@axis.com>
2020-05-06 15:49:33 +03:00
Timo Teräs 1d7123d837 rewrite option descriptors to be single string
This reduces the number of relocations on PIE binaries, and also
reduces the executable size. Parsing of the options is slightly
sped up as only the exact matching option group parser is called.
2020-05-06 13:05:25 +03:00
Timo Teräs 5258b484bf add script to autogenerate help from man pages
This creates main help like:
--
usage: apk [<OPTIONS>...] COMMAND [<ARGUMENTS>...]

Package installation and removal:
  add        Add packages to WORLD and commit changes
  del        Remove packages from WORLD and commit changes

System maintenance:
  fix        Check WORLD against the system and ensure consistency
  update     Update repository indexes
  upgrade    Install upgrades available from repositories
  cache      Commands related to the management of an offline package cache

Querying package information:
  info       Give detailed information about packages or repositories
  list       List packages matching a pattern or other criteria
  dot        Generate graphviz graphs
  policy     Show repository policy for packages

Repository maintenance:
  index      Create repository index file from packages
  fetch      Download packages from global repositories to a local directory
  manifest   Show checksums of package contents
  verify     Verify package integrity and signature

Miscellaneous:
  audit      Audit directories for changes
  stats      Show statistics about repositories and installations
  version    Compare package versions or perform tests on version strings

This apk has coffee making abilities.
--

And applet specific help like:
--
usage: apk add [<OPTIONS>...] PACKAGES...

Description:
  apk add adds the requested packages to WORLD and installs (or upgrades)
  them if not already present, ensuring all dependencies are met.

Options:
  --initdb         Initialize a new package database
  -l, --latest     Disables normal heuristics for choosing which repository to install a
  -u, --upgrade    When adding packages which are already installed, upgrade them rather
  -t, --virtual NAME
                   Instead of adding the specified packages to WORLD, create a new
  --no-chown       Do not change file owner or group
--
2020-05-06 13:05:19 +03:00
Fredrik Gustafsson d61c009f7a apk: do not manage file ownership as non-root or when asked so
If apk is run as a non-root user, it's not possible to chown files.

Maintainers note: minor wording changes on commit log and man page.

Signed-off-by: Fredrik Gustafsson <fredrigu@axis.com>
2020-04-28 14:48:49 +03:00
Rasmus Thomsen 47053ede6b build: fix includedir in pkgconfig file
We want to include via <apk/$headerfile> and not via <$headerfile>,
so we want to add an include statement for the dir the apk folder
which contains the headers is contained in.
2020-04-01 19:14:28 +03:00
Timo Teräs 845b6397ab db: fix database reading without scripts or triggers
Most notably this happens after blank database is initialized with --initdb,
but can happen also in other conditions.

The error checking changes modified behaviour if the file does not exist.
Explicitly check for ENOENT and ignore it. But the behaviour is improved
from earlier as now e.g. EPERM will be detected and reported correctly.

Fixes #10679

Fixes: 6da3e8eb15 "istream, archive, db: convert db and tar function to use istream"
2020-04-01 10:47:54 +03:00
Rasmus Thomsen 104c65ab92 build: add apk.pc.in 2020-03-23 13:44:42 +02:00
Antoine Fontaine e8522411c1 lower min-width to 25 columns
Some screen size are quite small. For example, the default phosh
terminal is less than 50 character wide on Pinephone. This lowers the minimum
loading bar size to 25 characters.

For comparison, 25 character wide is just as wide as "apk add firefox
linux-lts" without the quotes.

Here's a bad picture to illustrate the result
gitlab.alpine.org/uploads/48c20f746fbf685b62b6bd73585ecbf2/pinephone-phosh.png
2020-03-21 17:41:49 +02:00
TBK a9916c2d4a fix glibc build
fixes #10677

src/apk_defines.h:152:15: error: unknown type name 'uint32_t'
 static inline uint32_t get_unaligned32(const void *ptr)
               ^~~~~~~~
2020-03-21 17:37:47 +02:00
Rasmus Thomsen 4966bc5ede build: enable building of development package
- always create .so and .a with the apk libary code
- create .pc file
- install headers and above mentioned files

Maintainers edit: merged commits, cleaned up sed script logic,
and few other minor fixes.
2020-03-16 15:36:46 +02:00
Timo Teräs c054fbc11e db: fix unaligned memory access in csum_hash() 2020-02-21 09:33:58 +02:00
Timo Teräs 3694dc5fa2 fix murmur3 hash unaligned memory access
- do not do unaligned accesses on non-x86 hardware
- clean up the code a little bit
2020-02-17 21:36:28 +02:00
Timo Teräs 6d11ec36e6 rename all iostream source to io_*.c 2020-02-14 16:53:12 +02:00
Timo Teräs 60b87557e5 rename all applets sources to app_*.c 2020-02-14 16:49:55 +02:00
Timo Teräs 72be813930 io: add stream copy helper 2020-02-14 16:45:13 +02:00
Timo Teräs d60477751f defines: add typeof() as it's gcc built-in
Related to MR !15
2020-02-04 10:36:05 +02:00
Timo Teräs 45d313c51c remove apk_time() as it is causing problems with shared objects
Instead, to make sure test mode produces same output, redefine
time() for the test mode binary.

Reverts parts of 0b82bcc53e.
2020-02-04 10:31:10 +02:00
Drew DeVault b62d252b7b Update apk to make man pages sole source of truth
Detailed docs have been removed from the apk binaries, in favor of
git-style short summaries of each command.
2020-01-26 09:03:18 +02:00
Drew DeVault 7c2c68df69 add apk-manifest(8) 2020-01-26 09:01:26 +02:00
Reid Rankin c7c8ab7c57 don't use hardcoded checksum buffer sizes 2020-01-25 16:35:31 +02:00
Reid Rankin aa882df511 document mysterious SHA-1 blob in database.c 2020-01-25 16:33:54 +02:00
Reid Rankin 6cc3e6a1de don't ignore md parameter to apk_fileinfo_hash_xattr_array() 2020-01-25 16:33:17 +02:00
Timo Teräs 9a76f0d6a6 db: additional clean up and hardening for apk extraction
This enforces all scripts to be in the control block, and
all data files to be in data block. Ignoring of dot files in
root is added back: packages without any real files will
ship one ".dummy" item in the data block to trigger processing
and validation to work.
2020-01-24 10:39:01 +02:00
Reid Rankin d25e5e3879 Harden signature verification process
This mostly boils down to making sure control_started and
data_started are consistently used to gate actions, instead of
relying whether on file names start with a '.'.

None of the weaknesses this fixes are exploitable, but they
might have become so after changes to seemingly-unrelated code,
so it's good to clean them up.
2020-01-24 09:28:48 +02:00
Reid Rankin 093c4b8077 Improve documentation of signature verification process 2020-01-24 09:28:00 +02:00
Reid Rankin 1f9e56d8a4 manifest: fix package file processing
This change ensures that apk_sign_ctx_process_file() and
apk_sign_ctx_parse_pkginfo_line() are called during archive
processing, allowing discovery of signatures and the data section
checksum.

Fixes a bug uncovered by commit f123d77e.
2020-01-24 05:11:58 +02:00
Timo Teräs 67696b2ac6 io: use min() instead of MIN() 2020-01-11 11:32:51 +02:00
Timo Teräs f123d77e0b archive: make apk_tar_parse check and close input stream
simplifies other code quite a bit
2020-01-11 11:32:51 +02:00
Timo Teräs 1de9ef422c io: convert bstream mmap to istream, remove the now obsolete bstream machinery 2020-01-11 11:32:21 +02:00
Timo Teräs 7caa217731 convert remaining locations to use istream instead of bstream 2020-01-11 11:20:48 +02:00
Timo Teräs 6da3e8eb15 istream, archive, db: convert db and tar function to use istream 2020-01-11 11:20:45 +02:00
Timo Teräs 7ca0d146ec istream: add buffering capability
Convert all implementations to do buffering. This is in preparation
to remove bstream interface as redundant.

istream_read() will return full reads unless end-of-file. The backends
can return short reads to optimize buffering or due to other reasons
like boundary change for gz.
2020-01-11 03:44:23 +02:00
Timo Teräs 9dda2d3c21 archive: remove support for old packages without xattr checksums 2020-01-11 03:43:38 +02:00
Timo Teräs 6fae74e1da remove obsolete md5.h 2020-01-10 03:48:29 +02:00
Drew DeVault 7e2e440d4c database.c: drop GNU extension for fnmatch
The non-wildcard version of the function is case-sensitive anyway.
2020-01-09 08:47:31 +02:00
Timo Teräs 3cd7d1e077 io: remove the now unused pid association with istream 2020-01-06 01:17:08 +02:00
Timo Teräs e39334e44f io: remove unused size parameter from bstream close 2020-01-06 00:27:17 +02:00
Matthew McGill e4aae45f96 info: Remove short options for --install-if, --rinstall-if
The "apk info" option --install-if, which had the short option -i,
was being shadowed by the apk global option --interactive, which
has the same short option. To fix this issue the short option for
--install-if was removed, as has been done in other cases where an
applet short option would be shadowed by a global short option. The
short option for --rinstall-if was also removed for consistency,
since it is the complement of --install-if.
2020-01-05 23:28:43 +02:00
Sören Tempel 7d930f942c commit: make use of the apk_get_human_unit function 2020-01-05 23:26:50 +02:00
Sören Tempel a6039e38a4 Humanize size output of `apk info`
This commits adds a function for receiving the closet byte unit and the
size in that unit for a given size_t. The function doesn't return a
string since dynamic memory allocation (or a static buffer) would be
required to implement this properly.

Discussion: It might be useful to add a command line flag for disabling
this behaviour in order to retain compatibility with the previous apk
info output format.
2020-01-05 23:26:50 +02:00
Timo Teräs 0b82bcc53e lua: fix build and update to lua5.3
Fixes #8360
2019-12-30 16:17:14 +02:00
Timo Teräs 90fc52e2b8 del: report non-matching names and install-if rule non-deletion 2019-12-29 19:40:24 +02:00
Timo Teräs 7af5384db7 Revert "search: remove from APK_COMMAND_GROUP_QUERY"
This reverts commit d379edd5bf.

Requested multiple times. Let's enable this for now. For v3.0,
we reconsider which applets to keep and remove the ones not needed.
2019-12-27 17:30:21 +02:00
Timo Teräs 063c3acbbd db: parse tabulator as repository separator char
Fixes #10662
2019-12-27 17:06:23 +02:00
Timo Teräs 6996b1ea75 io: use proper base struct types for method implementations 2019-12-18 10:00:29 +02:00
nrybowski 695a2f8231 upgrade: implement --ignore to exclude some packages from upgrade 2019-12-12 13:47:11 +02:00
Fredrik Gustafsson cfa8b736f8 Don't unpack files to system root
When unpacking a file that is in root, it got a temporary file
name /.apk...  however if the --root option was used it should
have the name root/.apk... otherwise unpacking will fail if the
user does not have write access to /.

Signed-off-by: Fredrik Gustafsson <fredrigu@axis.com>
2019-11-22 14:41:55 +02:00
Max Rees 800488a1ef add: always use UTC for virtual package versions 2019-11-18 16:46:57 +01:00
Fredrik Gustafsson f8d5aa58f9 Make tests pass and introduce a memory leak
Since 37fbafcd92 the tests hasn't worked
since a string on the stack was added as version for a virtual package.
Instead create the version string on the heap and then simply leak it.
A short running program as apk shouldn't need to worry about memory
leaks.
2019-11-18 16:18:24 +01:00
Timo Teräs b45415b109 add: fix virtual package id generation
Fixes 37fbafcd by adding more input to the hash than just second
grained time stamp - collisions would happen when running apk
scripted.

For virtual package the hash works only as unique identifier, so
try to add elements that should make it unique in most cases.

Fixes #10648
2019-07-02 15:27:57 +03:00
Timo Teräs 366d0ee371 print usage and exit with error on invalid arguments
Add also some testing to make sure help, long help and handling
of invalid arguments works as expected.

Based on pull request #19 originally by Laurent Arnoud (@spk).
2019-06-05 09:56:13 +03:00
Timo Teräs c3a93a4aa5 fix all applets to return -ENOTSUP if it's unrecognized
The return -1 seems to have been left over from earlier code, and
could have been treated as -EPERM. This helps to fix the other command
line handling that potentially require changing.
2019-06-05 09:32:29 +03:00
Timo Teräs b0be9f610c solver: fix common dependency merging to inherit pinning and flags
Notably this fixes occasional issues when doing upgrade with multiple
versions of same packages. Without this the upgrade flag is not always
propagated properly down the dependency chain.
2019-06-05 08:51:00 +03:00
Timo Teräs 1c47f37443 use fixed system time in test mode to have fixed test output
fixes test suite regression from previous commit
2019-06-03 16:19:17 +03:00
Timo Teräs 37fbafcd92 add: make virtual packages upgradeable (ref #9957)
Originally the virtual packages could have dependencies added to it.
However, commit b06e3b99 broke this behaviour to fix error reporting.
The root cause however was that the virtual depedency package was not
properly versioned.

This fixes to use current date/time as the package version, and
constructs the "faked" package hash from it. This effectively makes
"add -t virtpkg deps.." replace the dependencies which should be the
desired behaviour for "abuild deps".

'world' dependency to the generated virtual package is also now
versioned to make sure it get's upgraded.
2019-06-03 09:33:43 +03:00
Ian Douglas Scott d901444ec9 Fix compile with glibc 2019-05-28 13:07:50 +03:00
A. Wilcox 84941a5967 list: Detect orphaned packages correctly
BIT(1) corresponds with decimal 2, which is the first available repository.

Before this fix, `apk list -O` would list every package installed from the
first available repository, which is the 'system' repository on most Adélie
Linux computers.

After this fix, `apk list -O` correctly lists only the packages which are
no longer available.
2019-05-01 18:56:43 +03:00
Timo Teräs 44daf80873 fix strncpy bounds errors
error: 'strncpy' specified bound 4096 equals destination size [-Werror=stringop-truncation]

Based on patch by Elan Ruusamäe <glen@delfi.ee>
2019-02-13 16:05:27 +02:00
Elan Ruusamäe 86922d1a34 include sys/sysmacros.h for makedev definition 2019-02-13 15:32:22 +02:00
Natanael Copa 947baeea18 fetch: fix error message for --recursive
Give error message for `apk fetch --recursive missing`
2019-01-10 09:29:35 +01:00
Timo Teräs bd8967bcb7 Revert "move --simulate to global options"
This reverts commit 358f703b76.

The short option -s conflicts info --size and fetch --stdout.
Revert this for now.
2018-11-15 12:03:51 +02:00
Timo Teräs 0565e9bb05 fix orphan package handling for certain provides cases 2018-11-12 15:00:14 +02:00
Timo Teräs 47570f80e9 prefer selecting packages by their primary name 2018-11-12 14:16:36 +02:00
Timo Teräs a86c8ed082 fix package preference based on it's conflicts in --latest mode
remove also redundant pkg_selectable check in repair mode.
2018-11-12 13:20:14 +02:00
Timo Teräs c3fe426da0 fix short option string to be nil terminated 2018-11-02 17:42:46 +02:00
Timo Teräs b06e3b991d fix error reporting for virtual package addition
Move addition of virtual package after the dependencies have been parsed
as then the reverse dependency structers can be populated correctly.
2018-11-02 17:41:34 +02:00
Timo Teräs 31338affc2 don't report virtual packages as masked 2018-11-02 17:12:20 +02:00
Timo Teräs 22abda2af4 inhibit printing same 'required by' dependency multiple times
this would happen if same package matched multiple times due to
multiple provided names.
2018-11-02 15:40:53 +02:00
Timo Teräs 59271f8c13 print: don't print spurious newlines 2018-11-02 15:40:45 +02:00
Timo Teräs f38d1f74af fix xattr hash to be sha1
The hash type was accidentally changed in previous commit. Currently
csum->data cannot hold longer hash, so fix the hash.
2018-10-30 18:26:10 +02:00
Timo Teräs beab8545eb add support for openssl 1.1 2018-10-26 08:22:08 +03:00
Timo Teräs 40ffdfe623 apk: fix all_options array size off-by-one
merge_options() will write one more entry to the options table
which is the end-of-table indicator. Allocate memory for it too.
valgrind did not pick it up due to being in stack; changing alloca
to malloc would make valgrind notice the issue too.

Reported-by: Mobile Stream <info@mobile-stream.com>
2018-10-05 09:45:02 +03:00
Timo Teräs 0e3be0fd4a cache: support --latest and --upgrade to affect download policy 2018-09-25 13:07:42 +03:00
Timo Teräs 358f703b76 move --simulate to global options
there are several applets that support simulation but are not
committing changes to database
2018-09-25 13:06:40 +03:00
Timo Teräs 4c6fc81474 add: add --latest flag to help analyze why upgrade fails 2018-09-11 10:34:14 +03:00
Timo Teräs 6484ed9849 rework unpacking of packages and harden package file format requirements
A crafted .apk file could to trick apk writing unverified data to
an unexpected file during temporary file creation due to bugs in handling
long link target name and the way a regular file is extracted.

Several hardening steps are implemented to avoid this:
 - the temporary file is now always first unlinked (apk thus reserved
   all filenames .apk.* to be it's working files)
 - the temporary file is after that created with O_EXCL to avoid races
 - the temporary file is no longer directly the archive entry name
   and thus directly controlled by potentially untrusted data
 - long file names and link target names are now rejected
 - hard link targets are now more rigorously checked
 - various additional checks added for the extraction process to
   error out early in case of malformed (or old legacy) file

Reported-by: Max Justicz <max@justi.cz>
2018-09-10 10:59:39 +03:00
Timo Teräs 7b654e1254 apk: sanitize return value
Most applets return whatever apk_solver_commit() returns. It is the
number of errors found (or negative for hard error). Sanitize the
error value to not give false success exit code in the unlikely case
of errors % 256 == 0.

Reported-by: Max Justicz <max@justi.cz>
2018-09-05 10:21:22 +03:00
Natanael Copa 13c534db77 prevent automatic repository index update with --no-network
We should not update repository index when --no-network is specified.

ref #9126
2018-08-21 12:25:37 +00:00
Jesse Young 1d55b9488f archive: enable FIFO extraction 2018-08-14 23:27:08 +03:00
Timo Teräs e1a05c74cb prevent automatic repository index update for 'apk del'
ref #9063
2018-07-18 13:29:13 +03:00
Jussi Kukkonen d609ef3c6c Invalidate id cache after script execution
It's common for a pre-install script to do something like
    addgroup -S group 2>/dev/null
When apk installs files after this, it sets the owner/group based on id cache
but currently the id cache is stale and doesn't contain the new group at that
point: instead the file will be installed with gid that the build host
happened to have for that group -- on target this might mean a non-existing
group or a completely different group.

We can't know if the script really did modify id cache contents so make sure
to reset the id cache on every script execution.
2018-07-02 10:06:53 -05:00
Sören Tempel 5c4b90dfd4 list: fix segmentation fault with virtual packages
Virtual packages have the origin pointer set to NULL. Trying to print it
using the BLOB_PRINTF macros causes a segmentation fault.

Inspired by the `print_origin_name` function from `src/search.c` this
commit attempts to fix it by checking whether `pkg->origin` is NULL
before attempting to print it. If it is NULL the pkg name is printed
instead.

Since printing the pkg name requires a different format string this
commit splits the printf call for printing the package line into
multiple ones. The output format shouldn't have changed at all though.
2018-07-02 08:52:22 -05:00
Timo Teräs 7561a501b4 fetch: ignore conflicts when solving --recursive fetches 2018-06-14 20:40:05 +03:00
Natanael Copa 611172b7a9 fetch: include install_if dependencies with --recursive
Run apk_solver_solve once with all args as dependencies instead of
running apk_solver_solve for each arg. This is neccesary so the
install_if calculation is done correctly.
2018-06-14 18:55:06 +03:00
Edan Bedrik dafbb1c4f4 url: return relevant error value from apk_istream_fetch 2018-05-08 22:44:23 +03:00
Timo Teräs 258519b1cd db: fix refreshing index if time is zero
During netboot on systems without RTC, time() will be near zero,
and the index fill not exist. Thus the plain test of st.st_mtime
against system time failed. Verify that fstatat() succeeds.
2018-04-05 09:57:17 +03:00
William Pitcock 0dcbd933c8 solver: allow names with only one provider to be autoselected regardless of priority 2018-02-21 15:35:53 +00:00
William Pitcock a5d9e2eb0a add: child dependencies can never take a pinning, give a useful error 2018-02-20 22:22:02 +00:00
William Pitcock dc7298122e apk: in test mode, always exit 0 (so the test harness doesn't stop running tests) 2018-02-20 22:21:27 +00:00
William Pitcock d52285c9aa list: use `apk list --providers` to search virtual providers instead of enabling virtuals by default 2018-01-29 03:17:07 +00:00
William Pitcock d379edd5bf search: remove from APK_COMMAND_GROUP_QUERY
list does everything search does and more
2018-01-29 03:03:15 +00:00
William Pitcock 3334624cd1 list: add option to match against real names only instead of providers 2018-01-29 02:59:39 +00:00
William Pitcock 368b8b6725 list: add --depends option for searching based on rdepends 2018-01-29 02:55:29 +00:00
William Pitcock 8fcb57bf0f list: refactor package dumping vs package filtering 2018-01-29 02:39:39 +00:00
William Pitcock fff8bfa588 list: new applet
The list applet provides a convenient way of inspecting both the available
and installed package databases by listing their contents.  In some ways,
it is similar to `apk search` but is considered to be a superset of
`apk search` functionality.

A few `apk list` criterion are not yet ready though, such as `apk list --depends`
which searches by runtime dependency (replacing `apk info --rdepends`).
2018-01-28 23:55:29 +00:00
William Pitcock 5da4dec2a2 apk: make --help --verbose actually work. 2018-01-09 17:07:22 +00:00
William Pitcock 182bfa0a9f apk: properly error out if an unknown command is requested 2018-01-09 17:07:22 +00:00
William Pitcock 1777040cc5 apk: commit options help text: fix typo concerning diskless boot 2018-01-09 17:07:22 +00:00
William Pitcock abf7c2838b apk: usage: cleanup help text when no applet is selected 2018-01-09 17:07:13 +00:00
Timo Teräs 118f29c895 fix --update-cache help to reflect reality
Internally the value is in seconds, but on command line it's in
minutes.
2018-01-09 10:32:03 +02:00
Timo Teräs 5f7dcadc69 auto-update index only when database is opened for writing 2018-01-08 11:56:48 +02:00
Timo Teräs d0a25d670a increase libfetch connection pool limits slightly 2018-01-04 11:08:30 +02:00
Timo Teräs 8a28c6d0d4 enable automatic update of indexes controlled by --cache-max-age
This modifies apk cache for indexes to be automatically refreshed
periodically without explicit 'update' or '--update-cache' usage.

The default is to do if-modified-since request if the local copy
is older than 4 hours. This age can be changed with --cache-max-age.
Using --update-cache will change this age to 60 seconds to make
sure the cached copy is relatively new. The small age is in order
to try to avoid downloading indexes second time when apk-tools is
upgraded and apk re-execs after self-upgrade.

Accordingly using explicitly 'apk update' will now enforce
--force-refresh and request the very latest index by requesting
any potential http proxy to do refresh too.
2018-01-04 10:56:09 +02:00
Timo Teräs 2da67940d5 url: add "Cache-Control: no-cache" header with --force-refresh
fixes #8161
2018-01-03 16:00:38 +02:00
Timo Teräs 039ff3bd46 split --force to several --force-[type] options
This unloads --force as several of the things are really not wanted
together. E.g. --force-refresh is a lot different from --force-broken-world
and doing --force to get the other might introduce unwanted behaviour.

--force is still kept for backwards compatibility and it enables
most things --force was used for.
2018-01-03 16:00:38 +02:00
Henrik Riomar e0eff8742f add new umbrella flag --initramfs-diskless-boot
This flag enables a group of options used during initramfs tmpfs
initial install.
2018-01-03 14:21:40 +02:00
Henrik Riomar 23cb104775 add new flag --no-commit-hooks
This flag skips running hook scripts

This flag *must* be used during initramfs tmpfs initial install.
The reason that this new flag is needed is that the hooks will currently
always fail as musl and /bin/sh is missing at this stage on diskless.
2018-01-03 14:20:58 +02:00
Timo Teräs b0fcc56f22 db: fix triggers to report deleted directories
This change just changes to keep deleted directory items in
the hash with ref count zero and modified flag set. Those entries
are reused when needed. The side effect is that fire_triggers()
will now see those removed direcotries and reports them. Other
enumerators of the directories hash are protected to skip removed
directories when appropriate.
2018-01-03 09:31:10 +02:00
Timo Teräs 8ee79c72b2 apk, del: fix few memory leaks
This fixes couple of valgrind reported leaks - though they are
non-important since the leak happens on "exit" only and kernel
frees it anyway.
2018-01-03 09:30:12 +02:00