summaryrefslogtreecommitdiffstats
path: root/src/test (follow)
Commit message (Collapse)AuthorAgeFilesLines
* tree-wide: fix typoYu Watanabe2020-12-181-3/+3
|
* test: add tpm2 and fido2 libs to dlopen testLennart Poettering2020-12-171-0/+10
|
* homed: move homectl's recovery key generation/modhex code to src/shared/Lennart Poettering2020-12-172-0/+55
| | | | | This allows us to later reuse the code to generate recovery keys for traditional LUKS volumes, too and share the code.
* test: fix fd_is_mount_point() checkLennart Poettering2020-12-172-7/+32
| | | | | | | | | | | | | | | | | | | So the currentl and only fd_is_mount_point() check is actually entirely bogus: it passes "/" as filename argument, but that's not actually a a valid filename, but an absolute path. fd_is_mount_point() is written in a way tha the fd refers to a directory and the specified path is a file directly below it that shall be checked. The test call actually violated that rule, but still expected success. Let's fix this, and check for this explicitly, and refuse it. Let's extend the test and move it to test-mountpoint-util.c where the rest of the tests for related calls are placed. Replaces: #18004 Fixes: #17950
* Merge pull request #17026 from fw-strlen/nft_16Lennart Poettering2020-12-162-9/+27
|\ | | | | add networkd/nspawn nftables backend
| * firewall-util: add nftables backendFlorian Westphal2020-12-161-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Idea is to use a static ruleset, added when the first attempt to add a masquerade or dnat rule is made. The alternative would be to add the ruleset when the init function is called. The disadvantage is that this enables connection tracking and NAT in the kernel (as the ruleset needs this to work), which comes with some overhead that might not be needed (no nspawn usage and no IPMasquerade option set). There is no additional dependency on the 'nft' userspace binary or other libraries. sd-netlinks nfnetlink backend is used to modify the nftables ruleset. The commit message/comments still use nft syntax since that is what users will see when they use the nft tool to list the ruleset. The added initial skeleton (added on first fw_add_masquerade/local_dnat call) looks like this: table ip io.systemd.nat { set masq_saddr { type ipv4_addr flags interval elements = { 192.168.59.160/28 } } map map_port_ipport { type inet_proto . inet_service : ipv4_addr . inet_service elements = { tcp . 2222 : 192.168.59.169 . 22 } } chain prerouting { type nat hook prerouting priority dstnat + 1; policy accept; fib daddr type local dnat ip addr . port to meta l4proto . th dport map @map_port_ipport } chain output { type nat hook output priority -99; policy accept; ip daddr != 127.0.0.0/8 oif "lo" dnat ip addr . port to meta l4proto . th dport map @map_port_ipport } chain postrouting { type nat hook postrouting priority srcnat + 1; policy accept; ip saddr @masq_saddr masquerade } } Next calls to fw_add_masquerade/add_local_dnat will then only add/delete the element/mapping to masq_saddr and map_port_ipport, i.e. the ruleset doesn't change -- only the set/map content does. Running test-firewall-util with this backend gives following output on a parallel 'nft monitor': $ nft monitor add table ip io.systemd.nat add chain ip io.systemd.nat prerouting { type nat hook prerouting priority dstnat + 1; policy accept; } add chain ip io.systemd.nat output { type nat hook output priority -99; policy accept; } add chain ip io.systemd.nat postrouting { type nat hook postrouting priority srcnat + 1; policy accept; } add set ip io.systemd.nat masq_saddr { type ipv4_addr; flags interval; } add map ip io.systemd.nat map_port_ipport { type inet_proto . inet_service : ipv4_addr . inet_service; } add rule ip io.systemd.nat prerouting fib daddr type local dnat ip addr . port to meta l4proto . th dport map @map_port_ipport add rule ip io.systemd.nat output ip daddr != 127.0.0.0/8 fib daddr type local dnat ip addr . port to meta l4proto . th dport map @map_port_ipport add rule ip io.systemd.nat postrouting ip saddr @masq_saddr masquerade add element ip io.systemd.nat masq_saddr { 10.1.2.3 } add element ip io.systemd.nat masq_saddr { 10.0.2.0/28 } delete element ip io.systemd.nat masq_saddr { 10.0.2.0/28 } delete element ip io.systemd.nat masq_saddr { 10.1.2.3 } add element ip io.systemd.nat map_port_ipport { tcp . 4711 : 1.2.3.4 . 815 } delete element ip io.systemd.nat map_port_ipport { tcp . 4711 : 1.2.3.4 . 815 } add element ip io.systemd.nat map_port_ipport { tcp . 4711 : 1.2.3.5 . 815 } delete element ip io.systemd.nat map_port_ipport { tcp . 4711 : 1.2.3.5 . 815 } CTRL-C Things not implemented/supported: 1. Change monitoring. The kernel allows userspace to learn about changes made by other clients (using nfnetlink notifications). It would be possible to detect when e.g. someone removes the systemd nat table. This would need more work. Its also not clear on how to react to external changes -- it doesn't seem like a good idea to just auto-undo everthing. 2. 'set masq_saddr' doesn't handle overlaps. Example: fw_add_masquerade(true, AF_INET, "10.0.0.0" , 16); fw_add_masquerade(true, AF_INET, "10.0.0.0" , 8); /* fails */ With the iptables backend the second call works, as it adds an independent iptables rule. With the nftables backend, the range 10.0.0.0-10.255.255.255 clashes with the existing range of 10.0.0.0-10.0.255.255 so 2nd add gets rejected by the kernel. This will generate an error message from networkd ("Could not enable IP masquerading: File exists"). To resolve this it would be needed to either keep track of the added elements and perform range merging when overlaps are detected. However, the add erquests are done using the configured network on a device, so no overlaps should occur in normal setups. IPv6 support is added in a extra changeset. Fixes: #13307
| * firewall-util: introduce context structureFlorian Westphal2020-12-161-10/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | for planned nft backend we have three choices: - open/close a new nfnetlink socket for every operation - keep a nfnetlink socket open internally - expose a opaque fw_ctx and stash all internal data here. Originally I opted for the 2nd option, but during review it was suggested to avoid static storage duration because of perceived problems with threaded applications. This adds fw_ctx and new/free functions, then converts the existing api and nspawn and networkd to use it.
| * firewall-util: reject NULL source or address with prefixlen 0Florian Westphal2020-12-161-2/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Make sure we don't add masquerading rules without a explicitly specified network range we should be masquerading for. The only caller aside from test case is networkd-address.c which never passes a NULL source. As it also passes the network prefix, that should always be > 0 as well. This causes expected test failure: Failed to modify firewall: Invalid argument Failed to modify firewall: Invalid argument Failed to modify firewall: Invalid argument Failed to modify firewall: Protocol not available Failed to modify firewall: Protocol not available Failed to modify firewall: Protocol not available Failed to modify firewall: Protocol not available The failing test cases are amended to expect failure on NULL source or prefix instead of success.
* | shared/hostname-setup: add mode where we check what would be set, without doingZbigniew Jędrzejewski-Szmek2020-12-162-8/+3
| | | | | | | | This allows the 'unsafe' mark to be removed from the test.
* | Move hostname setup logic to new shared/hostname-setup.[ch]Zbigniew Jędrzejewski-Szmek2020-12-164-78/+83
| | | | | | | | | | | | | | | | | | | | No functional change, just moving a bunch of things around. Before we needed a rather complicated setup to test hostname_setup(), because the code was in src/core/. When things are moved to src/shared/ we can just test it as any function. The test is still "unsafe" because hostname_setup() may modify the hostname.
* | Merge pull request #17968 from yuwata/purge-libudevYu Watanabe2020-12-163-98/+98
|\ \ | |/ |/| udev: do not link with libudev
| * meson: do not link with libudevYu Watanabe2020-12-151-9/+9
| |
| * udev: move util_resolve_subsys_kernel() to udev-util.cYu Watanabe2020-12-152-34/+33
| |
| * udev: move util_replace_whitespace() to udev-util.cYu Watanabe2020-12-152-55/+56
| |
* | hostname-util: flagsify hostname_is_valid(), drop machine_name_is_valid()Lennart Poettering2020-12-151-35/+35
|/ | | | | | | | | | | | Let's clean up hostname_is_valid() a bit: let's turn the second boolean argument into a more explanatory flags field, and add a flag that accepts the special name ".host" as valid. This is useful for the container logic, where the special hostname ".host" refers to the "root container", i.e. the host system itself, and can be specified at various places. let's also get rid of machine_name_is_valid(). It was just an alias, which is confusing and even more so now that we have the flags param.
* sd-device: make TAGS= property prefixed and suffixed with ":"Yu Watanabe2020-12-141-20/+47
| | | | | | | | | The commit 6f3ac0d51766b0b9101676cefe5c4ba81feba436 drops the prefix and suffix in TAGS= property. But there exists several rules that have like `TAGS=="*:tag:*"`. So, the property must be always prefixed and suffixed with ":". Fixes #17930.
* udev: introduce new OPTIONS="log_level=" udev ruleYu Watanabe2020-12-101-1/+1
|
* test: add test that dlopen()'s all our weak library deps onceLennart Poettering2020-12-092-0/+44
| | | | | | | | | | This test should ensure we notice if distros update shared libraries that broke so name, and we still use the old soname. (In contrast to what the commit summary says, this currently doesn#t cover really all such deps, specifically xkbcommon and PCRE are missing, since they currently aren't loaded from src/shared/. This is stuff to fix later)
* set: introduce set_strjoin()Yu Watanabe2020-12-081-0/+51
|
* Make support for nscd flushing optionalZbigniew Jędrzejewski-Szmek2020-12-071-11/+14
| | | | | | | | | Fedora will deprecate support for nscd in the upcoming release [1] and plans to drop it in the next one [2]. At that point we might as well build systemd without that support too, since there'll be nothing to talk too. [1] https://fedoraproject.org/wiki/Changes/DeprecateNSCD [2] https://fedoraproject.org/wiki/Changes/RemoveNSCD
* Merge pull request #17079 from keszybz/late-exec-resolutionLennart Poettering2020-12-031-4/+44
|\ | | | | Resolve executable paths before execution, use fexecve()
| * core/execute: fall back to execve() for scriptsZbigniew Jędrzejewski-Szmek2020-11-061-2/+7
| | | | | | | | fexecve() fails with ENOENT and we need a fallback. Add appropriate test.
| * basic/path-util: let find_executable_full() optionally return an fdZbigniew Jędrzejewski-Szmek2020-11-061-4/+39
| |
* | Merge pull request #17812 from poettering/systemctl-version-feature-updateLennart Poettering2020-12-031-1/+1
|\ \ | | | | | | build.h: add a bunch of missing features strings
| * | shared/build: make the version string definition less terribleZbigniew Jędrzejewski-Szmek2020-12-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The BLKID and ELFUTILS strings were present twice. Let's reaarange things so that each times requires definition in exactly one place. Also let's sort things a bit: the "heavy hitters" like PAM/MAC first, then crypto libs, then other libs, alphabetically, compressors, and external compat integrations. I think it's useful for users to group similar concepts together to some extent. For example, when checking what compression is available, it helps a lot to have them listed together. FDISK is renamed to LIBFDISK to make it clear that this is about he library and the executable.
* | | fw_add_masquerade: remove unused function argumentsFlorian Westphal2020-12-031-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | Similar to the previous commit. All callers pass NULL. This will ease initial nftables backend implementation (less features to cover). Add the function parameters as local variables and let compiler remove branches. Followup patch can remove the if (NULL) conditionals.
* | | fw_add_local_dnat: remove unused function argumentsFlorian Westphal2020-12-031-4/+4
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | All users pass a NULL/0 for those, things haven't changed since 2015 when this was added originally, so remove the arguments. THe paramters are re-added as local function variables, initalised to NULL or 0. A followup patch can then manually remove all if (NULL) rather than leaving dead-branch optimization to compiler. Reason for not doing it here is to ease patch review. Not requiring support for this will ease initial nftables backend implementation. In case a use-case comues up later this feature can be re-added.
* | fs-util: add conservative_rename() that suppresses unnecessary renamesLennart Poettering2020-12-021-0/+48
| | | | | | | | | | | | | | | | if the source and destination file match in contents and basic file attributes, don#t rename, but just remove source. This is a simple way to suppress inotify events + mtime changes when atomically updating files.
* | fileio: teach read_full_file_full() to read from offset/with maximum sizeLennart Poettering2020-12-011-2/+47
| |
* | Merge pull request #17478 from yuwata/split-network-internalYu Watanabe2020-11-271-4/+1
|\ \ | | | | | | libsystemd-network: split network-internal.c
| * | meson: drop libsystemd_network from several binariesYu Watanabe2020-10-291-4/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reduces the size of udevadm: Before: ``` $ ll udevadm -rwxrwxr-x 1 watanabe watanabe 1203800 Oct 29 01:36 udevadm ``` After: ``` $ ll udevadm -rwxrwxr-x 1 watanabe watanabe 1094384 Oct 29 01:38 udevadm ```
* | | shared/seccomp-util: address family filtering is broken on ppcZbigniew Jędrzejewski-Szmek2020-11-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts the gist of da1921a5c396547261c8c7fcd94173346eb3b718 and 0d9fca76bb69e162265b2d25cb79f1890c0da31b (for ppc). Quoting #17559: > libseccomp 2.5 added socket syscall multiplexing on ppc64(el): > https://github.com/seccomp/libseccomp/pull/229 > > Like with i386, s390 and s390x this breaks socket argument filtering, so > RestrictAddressFamilies doesn't work. > > This causes the unit test to fail: > /* test_restrict_address_families */ > Operating on architecture: ppc > Failed to install socket family rules for architecture ppc, skipping: Operation canceled > Operating on architecture: ppc64 > Failed to add socket() rule for architecture ppc64, skipping: Invalid argument > Operating on architecture: ppc64-le > Failed to add socket() rule for architecture ppc64-le, skipping: Invalid argument > Assertion 'fd < 0' failed at src/test/test-seccomp.c:424, function test_restrict_address_families(). Aborting. > > The socket filters can't be added so `socket(AF_UNIX, SOCK_DGRAM, 0);` still > works, triggering the assertion. Fixes #17559.
* | | test: use cap_last_cap() for max supported cap number, not ↵Dan Streetman2020-11-261-29/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | capability_list_length() This test assumes capability_list_length() is an invalid cap number, but that isn't true if the running kernel supports more caps than we were compiled with, which results in the test failing. Instead use cap_last_cap() + 1. If cap_last_cap() is 63, there are no more 'invalid' cap numbers to test with, so the invalid cap number test part is skipped.
* | | Merge pull request #17709 from yuwata/test-seccomp-skipYu Watanabe2020-11-261-0/+45
|\ \ \ | | | | | | | | test: skip several tests in test-seccomp when running under valgrind or ASAN
| * | | test: skip several tests in test-seccomp when running on asanYu Watanabe2020-11-251-0/+15
| | | |
| * | | test: skip several tests in test-seccomp when running on valgrindYu Watanabe2020-11-251-0/+30
| | | |
* | | | specifiers: introduce common macros for generating specifier tablesLennart Poettering2020-11-252-26/+5
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In many cases the tables are largely the same, hence define a common set of macros to generate the common parts. This adds in a couple of missing specifiers here and there, so is more thant just refactoring: it actually fixes accidental omissions. Note that some entries that look like they could be unified under these macros can't really be unified, since they are slightly different. For example in the DNSSD service logic we want to use the DNSSD hostname for %H rather than the unmodified kernel one.
* | | test: bump timeout for test-libcrypt-utilMichael Biebl2020-11-161-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | Apparently this test is prone to time out on slower architectures, so bump it from 30s to 120s. See https://buildd.debian.org/status/fetch.php?pkg=systemd&arch=mipsel&ver=247%7Erc2-2&stamp=1605303506&raw=0 https://buildd.debian.org/status/fetch.php?pkg=systemd&arch=sparc64&ver=247%7Erc2-2&stamp=1605294845&raw=0
* | | tree-wide: unsetenv cannot failZbigniew Jędrzejewski-Szmek2020-11-103-8/+8
| | | | | | | | | | | | | | | | | | ... when called with a valid environment variable name. This means that any time we call it with a fixed string, it is guaranteed to return 0. (Also when the variable is not present in the environment block.)
* | | basic/env-util: add little helper to call setenv or unsetenvZbigniew Jędrzejewski-Szmek2020-11-101-4/+1
| | |
* | | license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-09160-160/+160
| | |
* | | fileio: beef up READ_FULL_FILE_CONNECT_SOCKET to allow setting sender socket ↵Lennart Poettering2020-11-031-3/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | name This beefs up the READ_FULL_FILE_CONNECT_SOCKET logic of read_full_file_full() a bit: when used a sender socket name may be specified. If specified as NULL behaviour is as before: the client socket name is picked by the kernel. But if specified as non-NULL the client can pick a socket name to use when connecting. This is useful to communicate a minimal amount of metainformation from client to server, outside of the transport payload. Specifically, these beefs up the service credential logic to pass an abstract AF_UNIX socket name as client socket name when connecting via READ_FULL_FILE_CONNECT_SOCKET, that includes the requesting unit name and the eventual credential name. This allows servers implementing the trivial credential socket logic to distinguish clients: via a simple getpeername() it can be determined which unit is requesting a credential, and which credential specifically. Example: with this patch in place, in a unit file "waldo.service" a configuration line like the following: LoadCredential=foo:/run/quux/creds.sock will result in a connection to the AF_UNIX socket /run/quux/creds.sock, originating from an abstract namespace AF_UNIX socket: @$RANDOM/unit/waldo.service/foo (The $RANDOM is replaced by some randomized string. This is included in the socket name order to avoid namespace squatting issues: the abstract socket namespace is open to unprivileged users after all, and care needs to be taken not to use guessable names) The services listening on the /run/quux/creds.sock socket may thus easily retrieve the name of the unit the credential is requested for plus the credential name, via a simpler getpeername(), discarding the random preifx and the /unit/ string. This logic uses "/" as separator between the fields, since both unit names and credential names appear in the file system, and thus are designed to use "/" as outer separators. Given that it's a good safe choice to use as separators here, too avoid any conflicts. This is a minimal patch only: the new logic is used only for the unit file credential logic. For other places where we use READ_FULL_FILE_CONNECT_SOCKET it is probably a good idea to use this scheme too, but this should be done carefully in later patches, since the socket names become API that way, and we should determine the right amount of info to pass over.
* | | Merge pull request #17399 from afq984/udev-escaped-stringYu Watanabe2020-10-302-0/+206
|\ \ \ | | | | | | | | Allow escaped string in udev rules
| * | | udev: test udev_rule_parse_value()Yu, Li-Yu2020-10-292-0/+206
| | | |
* | | | Merge pull request #17472 from keszybz/spdx-license-headersZbigniew Jędrzejewski-Szmek2020-10-291-0/+2
|\ \ \ \ | |_|/ / |/| | | More SPDX license headers
| * | | tree-wide: use the usual SPDX header for our own filesZbigniew Jędrzejewski-Szmek2020-10-291-0/+2
| | | |
* | | | Merge pull request #17454 from keszybz/journal-dlopen-cleanupZbigniew Jędrzejewski-Szmek2020-10-282-0/+27
|\ \ \ \ | |/ / / |/| | | Journal dlopen cleanup and qrcode printing test
| * | | test: add a simple test for the qr printing codeZbigniew Jędrzejewski-Szmek2020-10-272-0/+27
| | | | | | | | | | | | | | | | | | | | | | | | Ideally, we'd read back what we wrote, but that would have been much more complicated. But just writing stuff is useful to test under valgrind or manually.
* | | | Revert "basic/env-util: (mostly) follow POSIX for what variable names are ↵Zbigniew Jędrzejewski-Szmek2020-10-232-19/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | allowed" This reverts commit b45c068dd8fac7661a15e99e7cf699ff06010b13. I think the idea was generally sound, but didn't take into account the limitations of show-environment and how it is used. People expect to be able to eval systemctl show-environment output in bash, and no escaping syntax is defined for environment *names* (we only do escaping for *values*). We could skip such problematic variables in 'systemctl show-environment', and only allow them to be inherited directly. But this would be confusing and ugly. The original motivation for this change was that various import operations would fail. a4ccce22d9552dc74b6916cc5ec57f2a0b686b4f changed systemctl to filter invalid variables in import-environment. https://gitlab.gnome.org/GNOME/gnome-session/-/issues/71 does a similar change in GNOME. So those problematic variables should not cause failures, but just be silently ignored. Finally, the environment block is becoming a dumping ground. In my gnome session 'systemctl show-environment --user' includes stuff like PWD, FPATH (from zsh), SHLVL=0 (no idea what that is). This is not directly related to variable names (since all those are allowed under the stricter rules too), but I think we should start pushing people away from running import-environment and towards importing only select variables. https://github.com/systemd/systemd/pull/17188#issuecomment-708676511
* | | | test: add heavy load loopback block device testLennart Poettering2020-10-222-0/+261
| | | |