Commit graph

1079 commits

Author SHA1 Message Date
Lennart Poettering ae2a15bc14 macro: introduce TAKE_PTR() macro
This macro will read a pointer of any type, return it, and set the
pointer to NULL. This is useful as an explicit concept of passing
ownership of a memory area between pointers.

This takes inspiration from Rust:

https://doc.rust-lang.org/std/option/enum.Option.html#method.take

and was suggested by Alan Jenkins (@sourcejedi).

It drops ~160 lines of code from our codebase, which makes me like it.
Also, I think it clarifies passing of ownership, and thus helps
readability a bit (at least for the initiated who know the new macro)
2018-03-22 20:21:42 +01:00
Yu Watanabe 11d6e9e9dc resolve: show more global settings in systemd-resolve --status
Closes #8455.
2018-03-20 00:44:47 +09:00
Yu Watanabe bf4e5c4cc6 resolve: expose global LLMNR, MulticastDNS, and DNSSEC settings as bus property 2018-03-20 00:44:44 +09:00
Yu Watanabe f37f8a61c0 bus-util: make bus_map_all_properties() not copy string 2018-03-20 00:42:48 +09:00
Yu Watanabe ee5324aa04 tree-wide: voidify pager_open()
Even if pager_open() fails, in general, we should continue the operations.
All erroneous cases in pager_open() show log message in the function.
So, it is not necessary to check the returned value.
2018-03-19 21:04:02 +09:00
Lennart Poettering 088c136384 resolve-tool: provide resolvconf(8) compatibility
This turns resolve-tool into a multi-call binary. When invoked as
"resolvconf" it provides minimal compatibility with the resolvconf(8)
tool of various distributions (and FreeBSD as it appears).

This new interface understands to varying degrees features of the two
major implementations of resolvconf(8): Debian's original one and
"openresolv". Specifically:

Fully supported:

        -a -d (supported by all implementations)
        -f    (introduced by openresolv)

Somewhat supported:

        -x    (introduced by openresolv, mapped to a '~.' domain entry)

Unsupported and ignored:

        -m -p (introduced by openresolv, not really necessary for us)

Unsupported and resulting in failure:
        -u    (supported by all other implementations)
        -I -i -l -R -r -v -V
              (all introduced by openresolv)
        --enable-updates --disable-updates --updates-are-enabled
              (specific to Debian's implementation)

Of course, resolvconf(8) is a tool with multiple backends, in our
implementation systemd-resolved is the only backend.

Fixes: #7202
2018-03-02 15:48:46 +01:00
Lennart Poettering 650f401123
Merge pull request #8336 from poettering/coccinelle-reallocarray
reallocarray() coccinellization
2018-03-02 15:40:52 +01:00
Lennart Poettering b351c300ee resolved: debug log about resolv.conf lines we don't grok 2018-03-02 12:43:12 +01:00
Lennart Poettering 9f0454a833 resolve-tool: propagate sensible errors from due to dns_name_is_valid() check failures 2018-03-02 12:43:12 +01:00
Lennart Poettering 27d8af3e39 resolve-tool: trivial coding style improvements 2018-03-02 12:43:12 +01:00
Lennart Poettering 3209c8e650 resolve-tool: use reallocarray() where appropriate 2018-03-02 12:39:07 +01:00
Zbigniew Jędrzejewski-Szmek 9b3cff199d meson: drop unnecessary "transformation" of policy files
Those files don't contain any @variables@, so the configuration step was just
copying them to build/. Let's avoid that, and fix their suffixes while at it.
2018-02-16 13:01:12 +01:00
Gunnar Hjalmarsson 264d8dcc16 Gettextize policy files
* Don't merge translations into the files
* Add gettext-domain="systemd" to description and message

Closes #8162, replaces #8118.
2018-02-16 13:00:52 +01:00
Zbigniew Jędrzejewski-Szmek 15c533103a resolved: use _cleanup_ in one more place
No functional change.
2018-02-05 10:08:18 +01:00
Zbigniew Jędrzejewski-Szmek 8530efc1c3 resolved: fix memleak of gcrypt context on error
Bug found by Stef Bon <stefbon@gmail.com>. Thanks!
2018-02-05 10:08:02 +01:00
Lennart Poettering db4a47e9fe coccinelle: O_NDELAY → O_NONBLOCK
Apparently O_NONBLOCK is the modern name used in most documentation and
for most cases in our sources. Let's hence replace the old alias
O_NDELAY and stick to O_NONBLOCK everywhere.
2018-01-24 11:09:29 +01:00
Michael Biebl 546e635a4e resolve: fix build without gcrypt
Follow-up for 73a4cd17c3.

Fixes #7977.
2018-01-24 12:59:22 +09:00
ott 73a4cd17c3 resolve: signal Ed25519 support (#7960)
Ed25519 is supported but not signalled as an understood cryptographic
algorithm as per RFC 6975.
2018-01-24 05:13:05 +09:00
ott 4cbfd62b46 resolve: Adjust and unify D-Bus call timeout (#7847)
DNS queries have a timeout of DNS_TRANSACTION_ATTEMPTS_MAX *
DNS_TIMEOUT_MAX_USEC = 120 s. Calls to the ResolveHostname method of
the org.freedesktop.resolve1.Manager interface have various call
timeouts that are smaller than 120 s. So it seems correct to adjust
the call timeout to the maximum query timeout and to unify the call
timeout among all callers.

A timeout of 120 s might seem large, in particular since BIND does seem
to have a query timeout of 10 s. However, it seems match the timeout
value of 120 s of Unbound. Moreover, the query and timeout handling of
resolve have problems and might be improved in the future, so this
change is at best an interim solution.
2018-01-23 09:53:31 +09:00
Zbigniew Jędrzejewski-Szmek bfc1d7345f resolved: fix confusion with generic data in unparsable packets
Issue 5465.
2018-01-18 20:28:38 +11:00
Zbigniew Jędrzejewski-Szmek 4a49e560d4 resolved: split out parts of dns_packet_extract
This fairly complicated function was deeply nested and
hard to read...
2018-01-18 19:35:47 +11:00
Shawn Landden 8a0f6d1f6b resolve: check for underflow of size parameter (#7889)
to dns_packet_read_memdup()

Closes #7888
2018-01-18 00:49:22 +11:00
Lennart Poettering dccca82b1a log: minimize includes in log.h
log.h really should only include the bare minimum of other headers, as
it is really pulled into pretty much everything else and already in
itself one of the most basic pieces of code we have.

Let's hence drop inclusion of:

1. sd-id128.h because it's entirely unneeded in current log.h
2. errno.h, dito.
3. sys/signalfd.h which we can replace by a simple struct forward
   declaration
4. process-util.h which was needed for getpid_cached() which we now hide
   in a funciton log_emergency_level() instead, which nicely abstracts
   the details away.
5. sys/socket.h which was needed for struct iovec, but a simple struct
   forward declaration suffices for that too.

Ultimately this actually makes our source tree larger (since users of
the functionality above must now include it themselves, log.h won't do
that for them), but I think it helps to untangle our web of includes a
tiny bit.

(Background: I'd like to isolate the generic bits of src/basic/ enough
so that we can do a git submodule import into casync for it)
2018-01-11 14:44:31 +01:00
Michal Koutný 4848b1f91a test-dnssec: Allow builds without libgcrypt (#7850) (#7850)
Fixes: #7845
2018-01-11 12:28:32 +01:00
Lennart Poettering d7afd945b5 networkd,resolved: make use of watch_bind feature to connect to the bus
The changes both networkd and resolved to make use of the watch_bind
feature of sd-bus to connect to the system bus. This way, both daemons
can be started during early boot, and automatically and instantly
connect to the system bus as it becomes available.

This replaces prior code that used a time-based retry logic to connect
to the bus.
2018-01-05 13:58:32 +01:00
Lennart Poettering 75152a4d6a tree-wide: install matches asynchronously
Let's remove a number of synchronization points from our service
startups: let's drop synchronous match installation, and let's opt for
asynchronous instead.

Also, let's use sd_bus_match_signal() instead of sd_bus_add_match()
where we can.
2018-01-05 13:58:32 +01:00
Lennart Poettering 0c0b930647 tree-wide: make name requesting asynchronous in all our services
This optimizes service startup a bit, and makes it less prone to
deadlocks.
2018-01-05 13:58:32 +01:00
Lennart Poettering 4ab02a0d36
Merge pull request #7793 from rojkov/fix-6456
resolved: fix refcounting DnsScope's conflict_queue
2018-01-03 18:43:14 +01:00
Dmitry Rozhkov c1227a1840 resolved: use DNS_ANSWER_FOREACH instead of for 2018-01-03 15:04:20 +02:00
Dmitry Rozhkov cfcc8dcc86 resolved: skip conflict notifications for DNS-SD PTR RRs
Enumerating DNS-SD PTR resource records are a special case and
are supposed to have non-unique keys pointing to services of the
same type running on different hosts. There's no need for them
to be checked for conflicts.

Thus don't check for conflicts such RRs.
2018-01-03 15:04:20 +02:00
Dmitry Rozhkov 432d108c25 resolved: fix refcounting DnsScope's conflict_queue
Refcounting for a RR's key is done separately from refcounting
for the RR itself, but in dns_scope_notify_conflict() we don't
do that. This may lead to a situation when a RR key put in the
conflict_queue hash as a value's key gets freed upon
cache reduction when it's still referenced by the hash.

Thus increase refcount for the key when putting it into the hash
and unreference it upon removing from the hash.

Closes #6456
2018-01-03 15:04:20 +02:00
Zbigniew Jędrzejewski-Szmek 568a4ff8b1 meson: use a convenience lib for shared resolve files
This reduces the man=false meson target count from 1281 to 1253.

--

A fully scientific test:
  git grep _sources, :/*.build|cut -d: -f2|tr -d ' '|sort|uniq -c
reveals that libudev_sources is the only source list now reused twice.  There's
some ugly circular dependency between libudev and libshared, and anyway I'm not
sure if we don't want to use different compilation options (LOG_REALM_…) in
those two cases, so I'm leaving that alone for now.
2018-01-03 12:09:46 +01:00
Lennart Poettering f1d34068ef tree-wide: add DEBUG_LOGGING macro that checks whether debug logging is on (#7645)
This makes things a bit easier to read I think, and also makes sure we
always use the _unlikely_ wrapper around it, which so far we used
sometimes and other times we didn't. Let's clean that up.
2017-12-15 11:09:00 +01:00
Lennart Poettering 14965b94f2
resolve: extend systemd-resolve so that it can push per-interface DNS configuration into systemd-resolved (#7576)
This is useful to debug things, but also to hook up external post-up
scripts with resolved.

Eventually this code might be useful to implement a
resolvconf(8)-compatible interface for compatibility purposes. Since the
semantics don't map entirely cleanly as first step we add a native
interface for pushing DNS configuration into resolved, that exposes the
correct semantics, before adding any compatibility interface.

See: #7202
2017-12-14 20:13:14 +01:00
Lennart Poettering fbd0b64f44
tree-wide: make use of new STRLEN() macro everywhere (#7639)
Let's employ coccinelle to do this for us.

Follow-up for #7625.
2017-12-14 19:02:29 +01:00
Lennart Poettering 0d53667334 tree-wide: use __fsetlocking() instead of fxyz_unlocked()
Let's replace usage of fputc_unlocked() and friends by __fsetlocking(f,
FSETLOCKING_BYCALLER). This turns off locking for the entire FILE*,
instead of doing individual per-call decision whether to use normal
calls or _unlocked() calls.

This has various benefits:

1. It's easier to read and easier not to forget

2. It's more comprehensive, as fprintf() and friends are covered too
   (as these functions have no _unlocked() counterpart)

3. Philosophically, it's a bit more correct, because it's more a
   property of the file handle really whether we ever pass it on to another
   thread, not of the operations we then apply to it.

This patch reworks all pieces of codes that so far used fxyz_unlocked()
calls to use __fsetlocking() instead. It also reworks all places that
use open_memstream(), i.e. use stdio FILE* for string manipulations.

Note that this in some way a revert of 4b61c87511.
2017-12-14 10:42:25 +01:00
Yu Watanabe ffbae6c978
Merge pull request #7588 from poettering/resolve-route-tweak
resolved domain routing tweaks and /etc/resolv.conf handling improvements
2017-12-13 13:43:55 +09:00
Zbigniew Jędrzejewski-Szmek 404a048623
Merge pull request #7591 from poettering/retry-on-servfail
resolved: retry with a different server on SERVFAIL
2017-12-12 22:22:06 +01:00
ott cb9eeb062c resolve: add support for RFC 8080 (#7600)
RFC 8080 describes how to use EdDSA keys and signatures in DNSSEC. It
uses the curves Ed25519 and Ed448. Libgcrypt 1.8.1 does not support
Ed448, so only the Ed25519 is supported at the moment. Once Libgcrypt
supports Ed448, support for it can be trivially added to resolve.
2017-12-12 16:30:12 +01:00
Lennart Poettering e82b113257 resolved: try a different server if server is too dumb to do DNSSEC
If we are in strict DNSSEC mode it's worthy to try a different DNS
server before accepting that DNSSEC is not actually supported.

Fixes: #7040
2017-12-12 12:10:08 +01:00
Lennart Poettering 5cdb8930e0 resolved: cast dns_scope_get_dns_server() to NULL when we ignore it 2017-12-12 12:10:08 +01:00
Lennart Poettering 44db02d0ef resolved: when a server consistently returns SERVFAIL, try another one
Currently, we accept SERVFAIL after downgrading fully, cache it and move
on. Let's extend this a bit: after downgrading fully, if the SERVFAIL
logic continues to be an issue, then use a different DNS server if there
are any.

Fixes: #7147
2017-12-12 12:10:08 +01:00
Yu Watanabe 4a0e9289bf resolved: fix wrong error code (#7601) 2017-12-10 16:27:19 +01:00
Lennart Poettering 613dca46d2 resolved: tweak domain routing logic a bit
This makes sure that a classic DNS scope that has no DNS servers
assigned is never considered for routing requests to even if it has
matching search/routing domains associated.

This is inspired by #7544, where lookup requests are refused since a
scope with no DNS server is configured. This change does not deliver
what the reporter intended, but is generally useful in general, as it
makes us mor robust to misconfiguration.
2017-12-08 17:25:08 +01:00
Lennart Poettering d937ef74ed resolved: synchronize introduction blurbs in all three resolv.conf files we provide
Let's use the same wording and same contents in all three versions.
2017-12-08 17:25:08 +01:00
Lennart Poettering b6de578d73 resolved: beef up logic to detect our own configuration files
Let's also check for the static resolv.conf, so that we filter all three
of our own files out.
2017-12-08 17:25:08 +01:00
Lennart Poettering a50d79103f resolved: don't make defines needlessly public 2017-12-08 17:25:08 +01:00
Lennart Poettering ace68cd711 resolved: store the mtime of the file we read
Let's make sure we use the mtime of the current fstat() data, rather
than the mtime of the old stat(), fixing a theoretical race.
2017-12-08 17:25:08 +01:00
Lennart Poettering 043d392878 resolved: fix a minimal race, when reading /etc/resolv.conf
The user might replace a foreign /etc/resolv.conf with a symlink to one
of ours between the time we did stat() and open the file. Hence, let's
check the fstat() data right after opening the file, a second time.
2017-12-08 17:25:08 +01:00
Dmitry Rozhkov 400f54fb36 resolved: support multiple TXT RRs per DNS-SD service
Section 6.8 of RFC 6763 allows having service instances with
multiple TXT resource records.
2017-12-08 14:29:27 +02:00