Commit graph

2208 commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek 1c7ed99027 resolved: adjust message about credentials
"credential provided widget" would be better spelled as "credential-provided widget".
But let's adjust the message to name the bad credential explicitly: this
makes it easier to fix for the user.
2023-04-25 18:08:15 +02:00
Zbigniew Jędrzejewski-Szmek 55ace8e5c5 shared/creds-util: return 0 for missing creds in read_credential_strings_many
Realistically, the only thing that the caller can do is ignore failures related
to missing credentials. If the caller requires some credentials to be present,
they should just check which output variables are not NULL. One of the callers
was already doing that, and the other wanted to, but missed -ENOENT. By
suppressing -ENOENT and -ENXIO, both callers are simplified.

Fixes a warning at boot:
systemd-vconsole-setup[221]: Failed to import credentials, ignoring: No such file or directory
2023-04-25 18:08:15 +02:00
Yu Watanabe d8e75260e9
Merge pull request #27253 from yuwata/cmsg-find-and-copy-data
socket-util: introduce CMSG_FIND_AND_COPY_DATA()
2023-04-16 16:28:26 +09:00
Yu Watanabe b5d39bb3ca tree-wide: also use CMSG_TYPED_DATA() on writing message header 2023-04-16 13:26:58 +09:00
David Tardon cfc28ee232 tree-wide: add some asserts 2023-04-14 10:16:01 +02:00
David Tardon 088d71f8ed tree-wide: use TAKE_STRUCT 2023-04-14 10:15:44 +02:00
Lennart Poettering b1d0219136 tree-wide: port more code over to CMSG_TYPED_DATA() 2023-04-13 10:49:23 +02:00
Cristian Rodríguez e144a26306
resolve: change DNS_PACKET_UNICAST_SIZE_LARGE_MAX to 1232 (#27171)
The old common default was 4096, until 2020 on which all DNS servers (verified
on BIND9, NSD, Unbound, dnsmasq) switched to 1232 as an agreed max size [1].

[1] https://www.dnsflagday.net/2020/#message-size-considerations
2023-04-07 09:52:52 +02:00
Ronan Pigott cad0fc7a13 resolve: refuse mdns scope for ipv4 broadcast addresses
This query can never be answered, so let's no wait for it to timeout.
2023-04-05 13:27:16 +02:00
Franck Bui 07e0ffc823 conf: replace config_parse_many_nulstr() with config_parse_config_file()
All daemons use a similar scheme to read their main config files and theirs
drop-ins. The main config files are always stored in /etc/systemd directory and
it's easy enough to construct the name of the drop-in directories based on the
name of the main config file.

Hence the new helper does that internally, which allows to reduce and simplify
the args passed previously to config_parse_many_nulstr().

Besides the overall code simplification it results:

  16 files changed, 87 insertions(+), 159 deletions(-)

it allows to identify clearly the locations in the code where configuration
files are parsed.
2023-03-14 03:31:21 +09:00
Jan Janssen 9214828313 meson: Introduce userspace dep
This will help in a later commit to separate userspace from EFI builds.
2023-03-10 11:40:14 +01:00
Lennart Poettering 5f64d2bf33 socket-util: fix socket_get_family()
Function didn't actually return anything useful. Quite a shame.
2023-03-10 09:36:18 +01:00
Lennart Poettering bb3517181b resolved: flush caches on memory pressure and support SIGRTMIN+18 2023-03-01 09:43:23 +01:00
Lennart Poettering 70f1280c83 tree-wide: use unlink_and_freep() moreover 2023-02-23 10:10:48 +09:00
Yu Watanabe 4788f635e3
Merge pull request #26203 from medhefgo/meson
meson: Use dicts for test/fuzzer definitions
2023-02-22 10:27:16 +09:00
Jan Janssen 2ed35b2f3e meson: Use dicts for fuzzer definitions 2023-02-21 15:10:26 +01:00
Jan Janssen 822cd3ff25 meson: Use dicts for test definitions
Although this slightly more verbose it makes it much easier to reason
about. The code that produces the tests heavily benefits from this.

Test lists are also now sorted by test name.
2023-02-21 15:10:26 +01:00
Yu Watanabe 0c2aedb451 tree-wide: use FORK_REARRANGE_STDIO and FORK_CLOSE_ALL_FDS 2023-02-21 07:39:18 +09:00
Yu Watanabe 911f8f0183 process-util: rename FORK_NULL_STDIO -> FORK_REARRANGE_STDIO
And make safe_fork_full() takes fds to be assigned to stdio.
2023-02-21 07:37:51 +09:00
Joan Bruguera 3dd6336ad0 resolved: Fall back to TCP if UDP is blocked
If UDP is blocked on the system (e.g. by iptables or BPF), the kernel will
return EPERM on some or all of the system calls (connect, sendmsg, etc.).
In this case, try to fall back to TCP, which hopefully will not be blocked.
2023-02-15 20:01:39 +00:00
Dmitry V. Levin 30fd9a2dab treewide: fix a few typos in NEWS, docs and comments 2023-02-15 10:41:03 +00:00
Zbigniew Jędrzejewski-Szmek bbb86efa7c resolve: adjust message for NXDOMAIN lookup result
Previously, we reported:
  nx.example.org: resolve call failed: 'nx.example.org' not found
But the call did succeed, and in fact all communication with the upstream
servers was successful, and we got an authoritative negative answer.
So instead of saying that the call fail, just say that the host doesn't exist:
  nx.example.org: Name 'nx.example.org' not found

I wanted to keep the prefix of "<name>: ", to keep the output uniform. But
it'd look a bit strange to say "<name>: <name> not found", so I added "Name "
to make the output more readable. (Another option would be to not display
the error string received from resolved, but that seems risky: even if right
now resolved uses just one message format, it could start doing something else
in the future, so it's better to display the error as received.)

Fixes #26233.
2023-02-07 14:49:58 +01:00
Zbigniew Jędrzejewski-Szmek 03e80572a7 resolve: define normal macros for BUS_ERROR_DNS error codes
This result is identical after cpp is done, so we don't save anything
by not having the usual macros. And with the usual macros it's easier to
grep and code-crossreferencing works better.
2023-02-07 14:49:58 +01:00
Daan De Meyer 0398c084ef resolve: Skip creating stubs if missing CAP_NET_BIND_SERVICE
If we don't have CAP_NET_BIND_SERVICE, we won't be able to bind
the stub listener socket, so let's skip creating it and log a warning.

We do the same for the extra stubs if they're configured on privileged
ports.
2023-01-26 22:29:05 +01:00
Jan Janssen 4a7ee0a521 meson: Do not include headers in source lists
Meson+ninja+compiler do this for us and are better at it.

https://mesonbuild.com/FAQ.html#do-i-need-to-add-my-headers-to-the-sources-list-like-in-autotools
2023-01-24 22:04:03 +01:00
Lennart Poettering 7153213e40 string-util: add common implementation of function that converts sized character buffers to NUL terminated C strings 2023-01-21 10:45:25 +01:00
Daan De Meyer cc232fa094 basic: Use statement expressions more in list.h
Let's use statement expressions to return values instead of passing
in return arguments to the LIST macros.
2023-01-08 16:31:15 +01:00
Daan De Meyer e0ff0ee8f9
Merge pull request #25947 from poettering/resolved-dns-creds
resolved: add support for reading DNS config from kernel cmdline + service credentials
2023-01-06 14:11:57 +01:00
Lennart Poettering 5f9041afec resolved: disable SO_BINDTOIFINDEX hack for localhost IP addresses
Fixes: #23010
2023-01-06 10:37:37 +01:00
Lennart Poettering 218db3d9ef dns-domain: dns_name_is_empty() is redundant
dns_name_is_empty() was added later, but does the same thing as the more
accurately called dns_name_is_root(), hence drop the former.
2023-01-05 21:44:26 +01:00
Lennart Poettering ef503f1cec resolvectl: remove duplicate ':' from output
The second argument to dump_list() actually ends up in a TABLE_FIELD
cell now, where we implicitly append a ":". Hence drop it from the
strings.

Follow-up for: 37a50123fa
2023-01-05 21:44:11 +01:00
Lennart Poettering 116687f267 resolved: read DNS conf also from creds and kernel cmdline
Note that this drops ProtectProc=invisible from
systemd-resolved.service.

This is done because othewise access to the booted "kernel" command line is not
necessarily available. That's because in containers we want to read
/proc/1/cmdline for that.

Fixes: #24103
2023-01-05 18:52:15 +01:00
Lennart Poettering 889a1b9f4e resolvectl: don't filter loopback DNS server from global DNS server list
"resolvectl status" shows per-link DNS servers separately from global
ones. When querying the global list, it will contain both per-link and
global servers however. Thus, to not show duplicate info we filter all
entries that actually have a non-zero ifindex set (under the assumption
that that's a per-link server).

This doesn't work if people configured 127.0.0.1 as global server
though, as we'll add ifindex 1 to it since
6e32414a66 unconditionally even for global
servers.

Let's address that by excluding entries with ifindex 1 from suppression.
This is safe as resolved ignores loopback ifaces, hence never will have
per-link servers on ifindex 1.

Note that this splits up the "with_ifindex" parameter into a second
parameter "only_global", since they semantically do two different
things. One controls whether we shall expect/parse an ifindex dbus
field. The other controls whether we shall filter all ifindex values set
!= 0. These are effectively always used in conjunction hence making them
the same actually worked. However this is utterly confusing I think,
which as I guess is resulting in the confusion around #25796 (which
removes the whole check)

Replaces: #25796
2023-01-04 16:47:40 +01:00
Lennart Poettering 5707fb1297 resolved: add some line-breaks/comments
Let's make this a bit more readable.
2023-01-04 16:32:53 +01:00
Lennart Poettering a5e6c8498c resolvectl: fix type of ifindex D-Bus field, and make sure to initialize to zero in all code paths 2023-01-04 16:29:34 +01:00
Lennart Poettering 40557509be resolved: downgrade inability to send varlink reply error message
Previously, if a client disconnected after sending a lookup request but
before waiting for the reply we'd log at LOG_ERR level. That's
confusing, since it's entirely OK for the client to lose interest.

Hence, let's downgrade to debug level.

Fixes: #25892
2023-01-03 23:12:02 +01:00
Lennart Poettering 4f06325ce9 fundamental: rework IN_SET() to require at least three arguments
If less than three parameters are passed a simple comparison is the
better choice.

Lo and behold this found two pretty bad typos.
2023-01-02 17:16:50 +01:00
Jacek Migacz 8b23242989 resolve: fix enumerator name for DNS search domain 2022-12-20 19:02:18 +01:00
Yu Watanabe 5bb1d7fbab tree-wide: use -EBADF more 2022-12-21 01:50:33 +09:00
Zbigniew Jędrzejewski-Szmek 254d1313ae tree-wide: use -EBADF for fd initialization
-1 was used everywhere, but -EBADF or -EBADFD started being used in various
places. Let's make things consistent in the new style.

Note that there are two candidates:
EBADF 9 Bad file descriptor
EBADFD 77 File descriptor in bad state

Since we're initializating the fd, we're just assigning a value that means
"no fd yet", so it's just a bad file descriptor, and the first errno fits
better. If instead we had a valid file descriptor that became invalid because
of some operation or state change, the other errno would fit better.

In some places, initialization is dropped if unnecessary.
2022-12-19 15:00:57 +01:00
Yu Watanabe 863b620a4a resolve: fix NULL-pointer dereference
Fixes a bug introduced by 16a6bc5a7a.
Fixes CID#1501514.
2022-12-14 19:10:19 +09:00
Yu Watanabe 16a6bc5a7a resolve: dedup entries in /etc/hosts
This improves the performance of parsing the file and reduces memory pressure.

Running 'fuzz-etc-hosts timeout-strv' with valgrind,

Before:
total heap usage: 321,020 allocs, 321,020 frees, 15,820,387,193 bytes allocated
real    0m23.531s
user    0m21.458s
sys     0m1.961s

After:
total heap usage: 112,408 allocs, 112,408 frees, 7,297,480 bytes allocated
real    0m8.664s
user    0m8.545s
sys     0m0.065s

Hopefully fixes oss-fuzz#47708 (https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=47708).
2022-12-13 20:37:48 +09:00
Yu Watanabe 59dad407a2 resolve: introduce more hash-ops and use them
No functional changes, just refactoring.
2022-12-13 20:37:48 +09:00
Yu Watanabe 232481a0e6 resolve: use dns_name_hash_ops_free
No functional changes, just refactoring.
2022-12-13 20:37:04 +09:00
Yu Watanabe 0f17886390 resolve: split manager_etc_hosts_lookup() into small parts
No functional changes, just refactoring.
2022-12-13 20:32:00 +09:00
Yu Watanabe 10b0c81802 resolve: adjust warning 2022-12-13 20:29:16 +09:00
Yu Watanabe 9f1a1f2047 resolve: merge two boolean variables
No functional changes, just refactoring.
2022-12-13 20:29:16 +09:00
Yu Watanabe e4e340990f resolve: introduce cleanup functions for EtcHostsItemBy{Address,Name}
No functional change, just refactoring and preparation for later
commits.
2022-12-13 20:29:16 +09:00
Yu Watanabe bb5c77305e resolve: make etc_hosts_item_by_{address,name}_free() accept NULL 2022-12-13 20:29:12 +09:00
Yu Watanabe 133eedad2b resolve: rename EtcHostsItem -> EtcHostsItemByAddress 2022-12-13 20:26:55 +09:00