Commit Graph

1221 Commits

Author SHA1 Message Date
Yu Watanabe 93bab28895 tree-wide: use typesafe_qsort() 2018-09-19 08:02:52 +09:00
Filipe Brandenburger 55890a40c3 test: remove support for suffix in get_testdata_dir()
Instead, use path_join() in callers wherever needed.
2018-09-12 09:49:03 -07:00
Alan Jenkins 8f8112f916 resolve: update comment, avoid alarming wrongness
`systemd-resolved.service` runs as `User=systemd-resolved`, and uses certain
Capabilit{y,ies} magic. By my understanding, this means it is started with a
number of "privileges".  Indeed, `capabilities(7)` explains

> Linux divides  the  privileges  traditionally
> associated  with  superuser into distinct units, known as capabilities,
> which can be independently enabled and disabled."

This situation appears to contradict our current code comment which said

> If we are not running as root we assume all privileges are already dropped.

This appears to be a confusion in the comment only.  The rest of the code
tells a much clearer story.  (Don't ask me if the story is correct.
`capabilities(7)` scares me).  Let's tweak the comment to make it consistent
and avoid worrying readers about this.
2018-08-29 18:07:06 +02:00
Yu Watanabe 8301aa0bf1 tree-wide: use DEFINE_TRIVIAL_REF_UNREF_FUNC() macro or friends where applicable 2018-08-27 14:01:46 +09:00
Yu Watanabe cf4b2f9906 tree-wide: use unsigned for refcount 2018-08-27 13:48:04 +09:00
Zbigniew Jędrzejewski-Szmek 7692fed98b
Merge pull request #9783 from poettering/get-user-creds-flags
beef up get_user_creds() a bit and other improvements
2018-08-21 10:09:33 +02:00
Lennart Poettering fafff8f1ff user-util: rework get_user_creds()
Let's fold get_user_creds_clean() into get_user_creds(), and introduce a
flags argument for it to select "clean" behaviour. This flags parameter
also learns to other new flags:

- USER_CREDS_SYNTHESIZE_FALLBACK: in this mode the user records for
  root/nobody are only synthesized as fallback. Normally, the synthesized
  records take precedence over what is in the user database.  With this
  flag set this is reversed, and the user database takes precedence, and
  the synthesized records are only used if they are missing there. This
  flag should be set in cases where doing NSS is deemed safe, and where
  there's interest in knowing the correct shell, for example if the
  admin changed root's shell to zsh or suchlike.

- USER_CREDS_ALLOW_MISSING: if set, and a UID/GID is specified by
  numeric value, and there's no user/group record for it accept it
  anyway. This allows us to fix #9767

This then also ports all users to set the most appropriate flags.

Fixes: #9767

[zj: remove one isempty() call]
2018-08-20 15:58:21 +02:00
Lennart Poettering 37ec0fdd34 tree-wide: add clickable man page link to all --help texts
This is a bit like the info link in most of GNU's --help texts, but we
don't do info but man pages, and we make them properly clickable on
terminal supporting that, because awesome.

I think it's generally advisable to link up our (brief) --help texts and
our (more comprehensive) man pages a bit, so this should be an easy and
straight-forward way to do it.
2018-08-20 11:33:04 +02:00
Evgeny Vereshchagin 670e95aecd resolvectl: free the block of memory 'hashed' points to before reusing it
This fixes a memory leak:
```
d5070e2f67ededca022f81f2941900606b16f3196b2268e856295f59._openpgpkey.gmail.com: resolve call failed: 'd5070e2f67ededca022f81f2941900606b16f3196b2268e856295f59._openpgpkey.gmail.com' not found

=================================================================
==224==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 65 byte(s) in 1 object(s) allocated from:
    #0 0x7f71b0878850 in malloc (/usr/lib64/libasan.so.4+0xde850)
    #1 0x7f71afaf69b0 in malloc_multiply ../src/basic/alloc-util.h:63
    #2 0x7f71afaf6c95 in hexmem ../src/basic/hexdecoct.c:62
    #3 0x7f71afbb574b in string_hashsum ../src/basic/gcrypt-util.c:45
    #4 0x56201333e0b9 in string_hashsum_sha256 ../src/basic/gcrypt-util.h:30
    #5 0x562013347b63 in resolve_openpgp ../src/resolve/resolvectl.c:908
    #6 0x562013348b9f in verb_openpgp ../src/resolve/resolvectl.c:944
    #7 0x7f71afbae0b0 in dispatch_verb ../src/basic/verbs.c:119
    #8 0x56201335790b in native_main ../src/resolve/resolvectl.c:2947
    #9 0x56201335880d in main ../src/resolve/resolvectl.c:3087
    #10 0x7f71ad8fcf29 in __libc_start_main (/lib64/libc.so.6+0x20f29)

SUMMARY: AddressSanitizer: 65 byte(s) leaked in 1 allocation(s).
```
2018-08-16 06:48:06 +00:00
Iwan Timmer 19feb28fa1 resolved: do not keep dns_server to dns_stream ref if tls connection failed (#9855)
The references to the dns_server are now setup after the tls connection is setup.
This ensures that the stream got fully stopped when the initial tls setup failed
instead of having the unref being blocked by the reference to the stream by the server.
Therefore on_stream_io would no longer be called with a half setup encrypted connection.

Fixes the issue reported in #9838.
2018-08-13 15:20:25 +09:00
Yu Watanabe 3740146a4c
resolve: do not hit CNAME or DNAME entry in NODATA cache (#9836)
Fixes #9833.
2018-08-13 14:32:33 +09:00
Lennart Poettering 9e888a9c5b
Merge pull request #9827 from yuwata/fix-9795-9820
journal: fixes issues reported by ASan
2018-08-08 14:07:40 +02:00
Yu Watanabe b2776a60f3 resolve: do not compress target names in SRV records
Fixes #9793.
2018-08-08 12:24:32 +02:00
Yu Watanabe 1f66559ca2 resolve: use memcmp_safe() and memcpy_safe()
As the length of salt in NSEC3 may be zero.

Fixes #9757.
2018-08-08 17:11:56 +09:00
Lennart Poettering 91f4424012
Merge pull request #9817 from yuwata/shorten-error-logging
tree-wide: Shorten error logging and several code cleanups
2018-08-07 10:44:44 +02:00
Filipe Brandenburger 53c5797fbd resolve: use CMP() in dns_resource_record_compare_func
This function doesn't really implement ordering, but CMP() is still fine to use
there. Keep the comment in place, just update it slightly to indicate that.
2018-08-06 19:26:44 -07:00
Filipe Brandenburger a0edd02e43 tree-wide: Convert compare_func's to use CMP() macro wherever possible.
Looked for definitions of functions using the *_compare_func() suffix.

Tested:
- Unit tests passed (ninja -C build/ test)
- Installed this build and booted with it.
2018-08-06 19:26:35 -07:00
Yu Watanabe 4ae25393f3 tree-wide: shorten error logging a bit
Continuation of 4027f96aa0.
2018-08-07 10:14:33 +09:00
Yu Watanabe 906119c046 resolve: use _cleanup_ attribute 2018-08-07 10:13:44 +09:00
Lennart Poettering 5d00545a6e test-resolved: fix whitespace issue 2018-08-06 21:16:31 +02:00
Lennart Poettering 6fb93e10cf test-resolved: add one more assert_se() check 2018-08-06 21:16:31 +02:00
Zbigniew Jędrzejewski-Szmek 7735d9397b
Merge pull request #9792 from poettering/hashmap-mempool
minor hashmap fixes
2018-08-06 14:13:30 +02:00
Yu Watanabe 72938b9309 resolve: sort headers 2018-08-06 09:57:00 +02:00
Yu Watanabe 10c6e7e51e resolve: fix error handling of dns_name_is_valid() 2018-08-06 10:48:20 +09:00
Lennart Poettering 7612719ef4 test-resolved: follow coding style, use fopen() with 'e' 2018-08-03 17:36:11 +02:00
Yu Watanabe 8e740110df resolve: openssl: make dnstls_stream_{write,read}() may return zero 2018-08-03 07:19:01 +09:00
Yu Watanabe 8eadd29183 resolve: fix error handling of SSL_shutdown() 2018-08-03 07:18:08 +09:00
Yu Watanabe 36f1946c73 resolve: fix typo and coding style cleanups 2018-08-03 06:29:38 +09:00
Yu Watanabe 59c3fee2c7 resolve: clear error queue before calling SSL_*() 2018-08-03 06:26:58 +09:00
Yu Watanabe 99521cab77 resolve: fix error handling of dns_stream_read() 2018-08-02 17:06:32 +02:00
Yu Watanabe 5e5420d1a1
Merge pull request #9770 from keszybz/etc-resolved-no-address
Slightly more efficient handling of /etc/hosts blacklist entries
2018-08-02 12:54:50 +09:00
Zbigniew Jędrzejewski-Szmek be19cdf31c resolved: change error handling for manager_etc_hosts_read()
The choice what errors to ignore is left to the caller, and the caller is
changed to ignore all errors.

On error, previously read data is kept. So if e.g. an oom error happens, we
will continue to return slightly stale data instead of pretending we have no
entries for the given address. I think that's better, for example when
/etc/hosts contains some important overrides that external DNS should not be
queried for.
2018-08-01 12:45:54 +02:00
Zbigniew Jędrzejewski-Szmek fd373593ba resolved: keep addresses mapped to ::0 in a separate set
We'd store every 0.0.0.0 and ::0 entry as a structure without any addresses
allocated. This is a somewhat common use case, let's optimize it a bit.

This gives some memory savings and a bit faster response time too:
'time build/test-resolved-etc-hosts hosts' goes from 7.7s to 5.6s, and
memory use as reported by valgrind for ~10000 hosts is reduced
==18097==   total heap usage: 29,902 allocs, 29,902 frees, 2,136,437 bytes allocated
==18240==   total heap usage: 19,955 allocs, 19,955 frees, 1,556,021 bytes allocated

Also rename 'suppress' to 'found' (with reverse meaning). I think this makes
the intent clearer.
2018-08-01 12:38:39 +02:00
Zbigniew Jędrzejewski-Szmek 78fc21a11a test-resolved-etc-hosts: add tests for /etc/hosts parsing
Calling 'build/test-resolved-etc-hosts filename' parses just that file.
This is useful to test against https://hosts.ubuntu101.co.za/hosts.
2018-08-01 12:38:39 +02:00
Zbigniew Jędrzejewski-Szmek 37b7cc8d9a resolved: put /etc/hosts hashmaps in a structure and pass that around
This hides the details of juggling the two hashmaps from the callers a bit.
It also makes memory management a bit easier, because those two hashmaps share
some strings, so we can only free them together.

etc_hosts_parse() is made responsible to free the half-filled data structures
on error, which makes the caller a bit simpler.

No functional change. A refactoring to prepare for later changes.
2018-08-01 12:38:34 +02:00
Zbigniew Jędrzejewski-Szmek 5a8b164092 meson: drop parens when appending to list
Meson does not care either way, so let's use the simpler syntax. And files()
already gives a list, so nesting this in a list wouldn't be necessary even
if meson did not flatten everything.
2018-07-31 21:02:01 +09:00
Yu Watanabe 7bf8c3ded4 resolve: support address with ifname in /etc/hosts 2018-07-31 16:12:13 +09:00
Yu Watanabe 0351eb1148 resolve: use in_addr_data type for storing address 2018-07-31 15:46:28 +09:00
Lennart Poettering f6f8a1aee0
Merge pull request #9734 from irtimmer/feature/dns-over-tls-openssl
resolved: Add OpenSSL as alternative SSL library
2018-07-30 14:13:05 +02:00
Yu Watanabe 8631708741 resolve: add option to toggle reading /etc/hosts
Workaround for #9718.
2018-07-28 21:46:00 +09:00
Yu Watanabe 452ca09152 resolve: make manager_etc_hosts_read() static 2018-07-28 20:36:13 +09:00
Iwan Timmer 04c4d9199e resolved: TCP Fast Open and TLS Session Tickets for OpenSSL
To decreae latency this add support for TFO and TLS Session Tickets. As OpenSSL wouldn't let you easily set a different function all written data is temporarily cached and therefore needs to be flushed after each SSL function which can write data.
2018-07-27 21:23:17 +01:00
Iwan Timmer 096cbdce13 resolved: basic OpenSSL support for DNS-over-TLS
This provides basic OpenSSL support without optimizations like TCP Fast Open and TLS Session Tickets.
Notice only a single SSL library can be enabled at a time and therefore journald functions provided by GnuTLS will be disabled when using OpenSSL.
Fixes #9531
2018-07-27 21:23:17 +01:00
Iwan Timmer ba6aaf5727 resolved: set io events after receiving EAGAIN for TLS
During handshake and TLS session closing, messages needs to be exchanged. Therefore this patch overrides the requested IO events for the TCP stream when the TLS is waiting for sending or receiving of messages during theses periods. This fixes issues with correctly closing the TLS stream and prevents the handshake from hanging in rare cases (not seen yet).
2018-07-27 21:23:17 +01:00
Iwan Timmer 6016fcb0ea resolved: refactor GnuTLS specific code in separate source file
This is a first step towards supporting alternative TLS implementations for DNS-over-TLS.

Co-authored-by: Filipe Brandenburger <filbranden@google.com>
2018-07-27 21:23:17 +01:00
Yu Watanabe 52588e0bda resolve: use structured initialization and use new() instead of new0() 2018-07-26 17:45:34 +09:00
Yu Watanabe c0df8f834a resolve: fix memleak 2018-07-26 17:45:34 +09:00
Yu Watanabe df0fbad0d4 resolve: add assert_not_reached()
Follow-up for 3fe30d85e3.
2018-07-24 13:00:11 +02:00
Yu Watanabe e6e7a551a0 test: add more string-table tests in test-resolve-tables 2018-07-24 01:26:14 +09:00
Yu Watanabe 3fe30d85e3 resolve: define _DNS_SERVER_TYPE_MAX in enum 2018-07-24 01:23:41 +09:00