Commit Graph
4053 Commits
Author SHA1 Message Date
Lennart Poettering 63e9c38370 terminal-util: add helper that determines terminal default bg color 2023-12-21 19:15:01 +01:00
Lennart Poettering 20f8b345db env-util: add strv_env_assignf() helper 2023-12-21 19:07:29 +01:00
Yu Watanabe e2ceb696d6 Merge pull request #30493 from teknoraver/main
Add verbose output on unit start #5717
2023-12-20 13:42:59 +09:00
Daan De Meyer a412a1b92a test: Skip various tests when /sys is not mounted
When running tests in a container, /sys might not be mounted, so
let's make sure we skip tests that depend on /sys in this case.
2023-12-19 16:38:57 +01:00
Matteo Croce e22ad53d5c dbus-wait-for-jobs: change 'quiet' flag to enum
Change the 'quiet' flag to `bus_wait_for_jobs()` to an enum, so we can
select with more granularity the type of information logged.
2023-12-19 04:52:41 -08:00
Frantisek Sumsal c15e51bde2 test: update comment style & drop one extraneous newline
Follow-up to 9fb2a61830.
2023-12-14 23:08:44 +01:00
Lennart Poettering 21c43631d7 rlimit-util: add pid_getrlimit() helper
This is gets the resource limits off a specified process, and is very
similar to prlimit() with a NULL new_rlimit argument. In fact, it tries
that first. However, it then falls back to use /proc/$PID/limits. Why?
Simply because Linux prohibits access to prlimit() for processes with a
different UID, but /proc/$PID/limits still works.

This is preparation to allow nspawn to run unprivileged.
2023-12-14 08:31:29 +00:00
Lennart Poettering bb59b92256 mount-util: make sure mount_switch_root() works as clean NOP when '/' is specified as target 2023-12-14 13:13:45 +09:00
Yu Watanabe 2527b725ba Merge pull request #30156 from yuwata/network-mtu
network: accept arbitrary size of MTU in .network
2023-12-12 19:03:21 +09:00
ksaleem 9fb2a61830 bootctl: fix case-sensitive comparisons in reporting bootloader entries
Fixes #30159
2023-12-11 10:51:56 +00:00
Luca Boccassi ae7482b994 core: do not make private /dev/ read-only too soon
The read-only bit is flipped after setting up all the mounts, so that
bind mounts can be added. Remove the early config, and add a unit
test.

Fixes https://github.com/systemd/systemd/issues/30372
2023-12-08 11:09:14 +09:00
Yu Watanabe a0460dfed6 parse-util: accept arbitrary MTU size when AF_UNSPEC
When [Link] MTU= is specified in a .network file, we have no idea about
that what kind of interface will be configured with the .network file.
The maximum and minimum MTU size depend on the kind of interface.
So, we should not filter MTU eagerly in the parser.

Closes #30140.
2023-12-08 10:47:42 +09:00
Lennart Poettering 4482ea0c24 Merge pull request #30271 from YHNdnzj/executor-cloexec
fdset,core/executor: ocloexecification ™️
2023-12-06 22:26:40 +01:00
Lennart Poettering 6498a0c2cc user-util: add new helper fully_set_uid_gid()
Usually when we do setresuid() we also do setesgid() and setgroups().
Let's add a common helper that does all three, and use it everywhere.
2023-12-06 22:11:38 +01:00
Luca Boccassi 5134e54625 basic: add fds_are_same_mount() helper 2023-12-05 17:20:27 +00:00
Zbigniew Jędrzejewski-Szmek 72420d39d7 test-macro: use capital test names for macro tests
It's just easier if the test is named as the thing being tested. Also, this way
inconsistent, because lower in the file uppercase test names are used.
2023-12-02 09:47:11 +01:00
Luca Boccassi f4a35f2ad9 core: do not drop CAP_SETUID if it is in AmbientCapabilities=
Follow-up for 24832d10b6
2023-12-01 10:48:14 +00:00
Mike Yuan a2467ea894 fdset: set all collected fds to CLOEXEC in fdset_new_fill() 2023-12-01 00:14:37 +08:00
Zbigniew Jędrzejewski-Szmek 78b95ccad8 test-time-util: suppress timestamp conversion failures for Africa/Khartoum timezone
Our timestamp conversion roundtrip test was failing. But I think that this
is not our bug:

$ TZ='Africa/Khartoum' date --date='@1509482094'
Tue Oct 31 23:34:54 EAT 2017
$ TZ='Africa/Khartoum' date --date='Tue Oct 31 23:34:54 EAT 2017' +%s
1509485694
$ TZ='Africa/Khartoum' date --date='@1509485694'
Tue Oct 31 23:34:54 CAT 2017
$ echo $[1509485694 - 1509482094]
3600

This is essentially the same as what happens in our test. After a round-trip, we
end up one hour ahead.

> For 1509482094632752, from the change log of tzdata:
>
> Release 2017c - 2017-10-20 14:49:34 -0700
>
>  Changes to future timestamps
>    Sudan will switch from +03 to +02 on 2017-11-01.

Fixes https://github.com/systemd/systemd/issues/28472.
2023-11-27 16:22:09 +00:00
Yu Watanabe fa3ab903f3 test: add test for draw_cylon() 2023-11-22 08:59:29 +09:00
Luca Boccassi 514c70eb52 test-condition: skip group test during Debian package build
The group names won't match in a package build chroot and the test might
fail, skip it.

https://buildd.debian.org/status/fetch.php?pkg=systemd&arch=hppa&ver=255%7Erc2-2&stamp=1700424353&raw=0
2023-11-20 10:51:42 +00:00
Yu Watanabe 965040d811 test: always call test_setup_logging() 2023-11-18 03:04:27 +09:00
Luca Boccassi dcddb2fc6b test: avoid asserting on default user shell
In some build environments it might differ:

/* test_get_user_creds_one("root", "root", 0, 0, "/root", "/usr/bin/bash") */
got "root", 0, 0, "/root", "/bin/sh": Success
Assertion 'path_equal(rshell, shell)' failed at src/test/test-user-util.c:345, function test_get_user_creds_one(). Aborting.

https://buildd.debian.org/status/fetch.php?pkg=systemd&arch=alpha&ver=255%7Erc2-1&stamp=1700147880&raw=0
2023-11-16 23:17:31 +00:00
Luca Boccassi 210dcd8fc6 test: minix fsck not found on alpha
It seems even this one is not everywhere, so relax the test:

/* test_fsck_exists */
Assertion 'fsck_exists_for_fstype("minix") == 1' failed at src/test/test-path-util.c:624, function test_fsck_exists(). Aborting.

https://buildd.debian.org/status/fetch.php?pkg=systemd&arch=alpha&ver=255%7Erc2-1&stamp=1700147880&raw=0
2023-11-16 23:01:46 +00:00
Luca Boccassi 1029edea3c Merge pull request #30018 from mrc0mmand/TEST-70
test: skip --tpm2-device-key= tests with older OpenSSL
2023-11-13 20:58:43 +00:00
Frantisek Sumsal 968d232db5 tree-wide: unify OpenSSL spelling in log messages
Seeing three different spellings of OpenSSL in one log file triggers
some inner OCD I didn't even know I have.
2023-11-13 20:47:17 +01:00
Lennart Poettering cc8c679281 test-tpm2: raise timeout, as RSA is slow 2023-11-13 16:53:56 +01:00
Lennart Poettering 3aea672bff test-tpm2: skip RSA generating TPM2 tests on physical hw
The TPM2 tests that genreate an RSA primary key are fast on vtpms, but
very slow on physical TPMs, simply because TPMs aren't precisely fast
devices. It makes sense to keep the tests around however. Hence hide the
test behind the "slow test" logic by default – but only if we run on
physical hw, and keep them in place on VMs (where we'd expect a vtpm, if
any).
2023-11-13 16:51:57 +01:00
Lennart Poettering 47a7a4d404 tests: add macro for generating function enter log message
The test-tpm2 test multiplexes a bunch of tests from a single
entrypoint test that creates the TPM2 connection. This means we only get
the nice log output which test we are looking for once for the
entrypoint.

Let's add a macro that allows it to nicely generate it for the inner
tests too and use it.
2023-11-13 16:50:55 +01:00
Yu Watanabe 5996cc348c conf-parser: fix argument type of ConfigPerfItemLookup
Prompted by #29972.
2023-11-13 00:46:39 +09:00
Luca Boccassi 22f62b8917 test: sort files in generate-sym-test.py
The test binaries are different depending on the filesystem, due to os.walk().
Sort the input before iterating on it to make it stable.
2023-11-12 12:54:23 +09:00
Dan Nicholson 9217255427 test-process-util: Handle unprivileged setrlimit success
Currently test_setpriority_closest assumes that setting RLIMIT_NICE to 30 will
fail if the process is unprivileged. If it succeeds, it assumes that the
process is privileged and setresuid and setresgid will succeed.

However, if RLIMIT_NICE is already >= 30, then setrlimit will succeed even if
the process is unprivileged. Guard against that by checking for permission
errors in setresuid and setresgid and skipping the full test if so.

Fixes #22896.
2023-11-08 21:29:16 +00:00
Lennart Poettering e3c5842732 Merge pull request #28519 from ddstreet/tpm2_external_seal
Update systemd-cryptenroll to enroll TPM using only public key
2023-11-08 10:28:28 +01:00
Luca Boccassi 00666ec71f Merge pull request #6763 from kinvolk/iaguis/no-new-privs
core: allow using seccomp without no_new_privs when unprivileged
2023-11-07 21:34:49 +00:00
Dan Streetman 65883f6c10 tpm2: update test-tpm2 for tpm2_calculate_seal()
Add testing for tpm2_calculate_seal().
2023-11-07 12:00:07 -05:00
Dan Streetman 2eea1b8f2f tpm2: add test to verify srk templates
Verify the tpm2_get_srk_template() and tpm2_get_best_srk_template() functions
work as expected.
2023-11-07 10:59:44 -05:00
Dan Streetman 788933379d tpm2: allow using tpm2_get_srk_template() without tpm
The SRK templates are defined by specification, so move the check for TPM
support to the tpm2_get_best_srk_template() function, and allow anyone to get
the ECC and RSA templates.

Also add test to verify the SRK templates are correct.
2023-11-07 10:59:44 -05:00
Lennart Poettering 67a3028555 json: teach dispatch logic to also take numbers formatted as strings
JSON famously is problematic with integers beyond 53 bits, because
JavaScript stores everything in double precision floating points.
Various implementations in other languages can deal with signed 64 bit
integers, and a few can deal with unsigned 64bit too (like ours).

Typically program that need more then 53 bit of accuracy encode integers
as decimal strings, to make sure that even if consumers can't really
process larger values they at least won't corrupt the data while passing
it along. This is also recommended by JSON-I (RFC 7493)

To maximize compatibility with other implementations let's add 1st class
parsing support for such objects in the json_dispatch() API.

This makes json_dispatch_uint64() and related calls parse such
integers-formatted-as-decimal-strings as uint64_t. This logic will only
be enabled if the "type" field of JsonDispatch is left unspecified (i.e.
set to negative/_JSON_VARIANT_TYPE_INVALID) though, hence alone does not
change anything in effect.

This purely is about consuming such values, whether we should genreate
them also is a discussion for a separate PR.
2023-11-07 14:25:40 +01:00
Iago López Galeiras e720cebf7c test-execute: add no_new_privs tests for SystemCallFilter
When starting a service with a non-root user and a SystemCallFilter and
other settings (like ProtectClock), the no_new_privs flag should not be set.

Also, test that CapabilityBoundingSet behaves correctly, since we need
to preserve some capabilities to do the seccomp filter and restore the
ones set by the service before executing.
2023-11-07 11:31:53 +01:00
Luca Boccassi 93c2d8d5c4 test: fix build without SBAT_DISTRO
Follow-up for c9bebec872
2023-11-06 19:05:47 +00:00
Lennart Poettering fd81692f4b test: add test for the combined base64/base64url decoder 2023-11-03 21:35:28 +01:00
Lennart Poettering a434270139 pcrlock: add new pcrlock tool 2023-11-03 11:23:54 +01:00
Frantisek Sumsal 69d17e23db varlink: limit the maximum nesting depth
Let's limit the maximum nesting depth for structure definitions to 64 to
avoid stack overflows with very deep definitions.

Resolves: #29589
2023-11-02 20:43:38 +00:00
Lennart Poettering 3b516db71d glyph-util: add computer disk + world emoji 2023-11-02 14:19:32 +01:00
Lennart Poettering e5f1e8b894 lock-util: add a new lock_generic_with_timeout() helper
This is just like lock_generic(), but applies the lock with a timeout.
This requires jumping through some hoops by executing things in a child
process, so that we can abort if necessary via a timer. Linux after all
has no native way to take file locks with a timeout.
2023-11-02 14:19:32 +01:00
Lennart Poettering e9ccae3135 process-util: add new FORK_DEATHSIG_SIGKILL flag, rename FORK_DEATHSIG → FORK_DEATHSIG_SIGTERM
Sometimes it makes sense to hard kill a client if we die. Let's hence
add a third FORK_DEATHSIG flag for this purpose: FORK_DEATHSIG_SIGKILL.

To make things less confusing this also renames FORK_DEATHSIG to
FORK_DEATHSIG_SIGTERM to make clear it sends SIGTERM. We already had
FORK_DEATHSIG_SIGINT, hence this makes things nicely symmetric.

A bunch of users are switched over for FORK_DEATHSIG_SIGKILL where we
know it's safe to abort things abruptly. This should make some kernel
cases more robust, since we cannot get confused by signal masks or such.

While we are at it, also fix a bunch of bugs where we didn't take
FORK_DEATHSIG_SIGINT into account in safe_fork()
2023-11-02 14:09:23 +01:00
Lennart Poettering f1b622a00c varlink,json: introduce new varlink_dispatch() helper
varlink_dispatch() is a simple wrapper around json_dispatch() that
returns clean, standards-compliant InvalidParameter error back to
clients, if the specified JSON cannot be parsed properly.

For this json_dispatch() is extended to return the offending field's
name. Because it already has quite a few parameters, I then renamed
json_dispatch() to json_dispatch_full() and made json_dispatch() a
wrapper around it that passes the new argument as NULL. While doing so I
figured we should also get rid of the bad= argument in the short
wrapper, since it's only used in the OCI code.

To simplify the OCI code this adds a second wrapper oci_dispatch()
around json_dispatch_full(), that fills in bad= the way we want.

Net result: instead of one json_dispatch() call there are now:

1. json_dispatch_full() for the fully feature mother of all dispathers.
2. json_dispatch() for the simpler version that you want to use most of
   the time.
3. varlink_dispatch() that generates nice Varlink errors
4. oci_dispatch() that does the OCI specific error handling

And that's all there is.
2023-11-02 01:19:21 +00:00
Arseny MaslennikovandMike Yuan c21566d90b basic/missing_syscall: add missing_fchmodat2()
Follow-up for 8b45281daa
and preparation for later commits.

Since libcs are more interested in the POSIX `fchmodat(3)`, they are
unlikely to provide a direct wrapper for this syscall. Thus, the headers
we examine to set `HAVE_*` are picked somewhat arbitrarily.

Also, hook up `try_fchmodat2()` in `test-seccomp.c`. (Also, correct that
function's prototype, despite the fact that mistake would not matter in
practice)

Co-authored-by: Mike Yuan <me@yhndnzj.com>
2023-11-02 00:23:12 +08:00
Lennart Poettering 9c21cfdd7d chase: fix corner case when using CHASE_PARENT with a path ending in ".."
If we use CHASE_PARENT on a path ending in ".." then things are a bit
weird, because we the last path we look at is actually the *parent* and not
the *child* of the preceeding path. Hence we cannot just return the 2nd
to last fd we look at. We have to correct it, by going *two* levels up,
to get to the actual parent, and make sure CHASE_PARENT does what it
should.

Example: for the path /a/b/c chase() with CHASE_PARENT will return
/a/b/c as path, and the fd returned points to /a/b. All good.  But now,
for the path /a/b/c/.. chase() with CHASE_PARENT would previously return
/a/b as path (which is OK) but the fd would point to /a/b/c, which is
*not* the parent of /a/b, after all! To get to the actual parent of
/a/b we have to go *two* levels up to get to /a.

Very confusing. But that's what we here for, no?

@mrc0mmand ran into this in https://github.com/systemd/systemd/pull/28891#issuecomment-1782833722
2023-11-01 14:43:24 +00:00
Luca Boccassi 7c2fd96dba Merge pull request #29764 from dtardon/varlink-io.systemd.service
Add varlink interface io.systemd.service
2023-11-01 14:41:58 +00:00