Commit Graph

392 Commits (2a9c0277c0d633d940a48726b214b89de2957d07)

Author SHA1 Message Date
Ariadne Conill 2a9c0277c0 use fstatat, not fstatat64
the stat64 family of functions were provided as transitional functions,
but when building on glibc with _GNU_SOURCE, or any other supported system,
the stat functions are equivalent to their stat64 counterparts
2021-12-29 07:52:48 +00:00
Paul Spooren f2a5959139 apk: add --preserve-env option
This options is useful for (post)install scripts to run with the same
environment variables as apk is executed.

[TT: minor stylistic changes]

Signed-off-by: Paul Spooren <mail@aparcar.org>
2021-12-29 09:50:50 +02:00
Ariadne Conill f4f7796ccc everywhere: use stdlib.h for malloc(3) definition, not GNU-specific malloc.h
musl implements support for malloc.h, but it is only a stub.  we do not use
any of the GNU-specific malloc interfaces, so just use POSIX stdlib.h instead.

ref #10794
2021-12-14 16:23:29 +00:00
Timo Teräs 1ab81fdd4c db: convert v3 scripts to ipkg on install
fixes #10796
2021-12-03 14:53:30 +02:00
Timo Teräs 845fa93814 db: synthesize symlink hashes for v3 packages
The v3 format will not require the hash, but synthesize it to the
DB so v3 packages can get installed properly.

fixes #10785
2021-11-22 13:41:22 +02:00
Timo Teräs cce6239074 db: fix regression in creating .apk-new files
The apk_fsdir_file_digest() servers dual purpose: to calculate
the checksum, but also to determine if the file exists. Move
it's error check where it originally was.

fixes #10791
2021-11-22 10:35:18 +02:00
Timo Teräs 83b71f0baf db: lazy create directories with --initdb
fixes #10778
2021-11-15 15:56:48 +02:00
Timo Teräs 16e0f6df7f fix fetching of depdencies only packages
Remove the APK_REPOSITORY_CACHED bit from dependencies only
packages (that is, installed_size == 0). For fetch, the problem
is that apk_db_select_repo() would return the cache repository,
but the package would not be there. Update also the locations
needed to handle these packages correctly without the cached
repository bit being set.
2021-11-15 13:35:59 +02:00
Timo Teräs 7d6de2203e database: support loading v3 indexes 2021-11-09 21:50:11 +02:00
Timo Teräs a673653200 database: implement uvol support
by adding an abstraction layer to the file system
2021-11-09 21:50:11 +02:00
Timo Teräs d441cf523c db: purge temporary files without explicit modification check
When extraction failed, the user has had no opportunity to edit
any files. Just clean up.
2021-11-03 16:06:04 +02:00
Timo Teräs 5c0c249b78 extract: move uvol extraction code to extract
fix also the progress callback on uvol extraction
2021-11-03 15:37:10 +02:00
Timo Teräs d821265865 db, extract: handle waitpid returning EINTR 2021-11-03 15:37:10 +02:00
Timo Teräs 6941aac4c6 db, audit: support sha256-160 hashes for v3 pkg compat 2021-11-03 15:37:10 +02:00
Timo Teräs 40f0866367 db, add: support adding v3 package files 2021-10-27 16:14:45 +03:00
Timo Teräs 72d8cb8937 remove IS_ERR_OR_NULL
In most places where pointer can be an 'error' it cannot be null
pointer. Further, in those cases just calling PTR_ERR() is not enough
to handle the null case. Simplify code by removing this case.

If NULL case needs to be handled, it's better to add separate check
and return fixed error code in that case.
2021-08-23 17:02:50 +03:00
Timo Teräs 33c1de8ea1 db: honor SOURCE_DATE_EPOCH for scriptdb
fixes #10762
2021-08-23 11:11:29 +03:00
Timo Teräs 5843daf7a1 Further refactor extract API to have separate ops vtable
This splits the callbacks by type, and further prepares the API
to be usable for v3 files too.
2021-07-27 16:28:22 +03:00
Timo Teräs 9c843e4ecd Refactor .apk extraction code
This moves and isolates the tar code to tar.c. And the actual
file extraction to disk is moved to extract.c.

A new API is introduced and used for v2 file extraction. This
essentially moves and isolates the apk_sign_ctx_* beast into
extract_v2.c and offers a saner interface to handling packages.

A place holder is added for v3 extraction.
2021-07-27 14:09:38 +03:00
Timo Teräs 083ea5a13b db: add some error checking to database state write
Make errors more observable. Unfortunately full rollback is
non-trivial to implement. This is something to be fixed with
the v3 database format.
2021-07-26 14:10:07 +03:00
Samanta Navarro d212aca070 db: fix installed db writing with long names
Packages containing files with path names longer than 1024 characters
cannot fit into the buffer which is used to write "installed" database.
This leads to bbuf being APK_BLOB_NULL in apk_db_write_fdb because
apk_blob_push_blob notices the condition and correctly handles it.

The problem occurs when arguments to apk_ostream_write are manually
calculated by pointer arithmetics. Since bbuf.ptr is NULL in such a
case, bbuf.ptr - buf leads to a huge size value while buf still points
into the stack.

fixes #10751

[TT: minor edit to commit and abbreviating the commit message]
2021-07-26 13:36:28 +03:00
Timo Teräs 3d203e8f5f db: allow read-only operations without cache
fixes #10748
2021-07-23 14:39:38 +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 0683b069ba db: check syscall errors in update_permissions() 2021-06-21 13:02:12 +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 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
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 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
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 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
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 6d71f49c11 io: make ostream_file always use tmpname 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 c269e9c24d db: check cache only if some repositories are enabled 2020-10-01 14:31:41 +03:00
Ariadne Conill fa63e46a75 database: clarify the deprecation notice for checksum-less packages
Closes #10708.
2020-08-29 20:37:57 +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