Commit graph

11942 commits

Author SHA1 Message Date
Thomas Haller
eebcbfae75 dhcp: store dhclient's pid file in "/var/run/NetworkManager" instead of "/var/run"
The pid-file is private to NetworkManager. It should reside in NetworkManager's
run directory instead of "/var/run".

I don't think that changing this location can break existing uses. Why
would somebody outside of NetworkManager care about this file?

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/157
2019-05-20 11:52:31 +02:00
Thomas Haller
1da7dfc408 gitignore: merge gitignore files
For the most part, we only have one main .gitignore file.

There were a few nested files, merge them into the main file.

I find it better to have only one gitignore file, otherwise the
list of ignored files is spread out through the working directory.
2019-05-19 14:41:21 +02:00
Thomas Haller
5c0dd32622 src/tests: rename core's "test-general*" to "test-core*" 2019-05-19 14:41:00 +02:00
Thomas Haller
c99bbc99b0 wifi/tests: rename Wi-Fi's "test-general" to "test-devices-wifi"
We already have 4 other tests that are named "test-general". Rename.
2019-05-19 11:28:53 +02:00
Thomas Haller
d27f6b9d0a keyfile/tests: rename core's "test-keyfile" to "test-keyfile-settings"
We already have "libnm-core/tests/test-keyfile.c" from which we build
"test-keyfile".

Our test binaries should be named the following:

- "*/tests/test-*"

- the test binary "*/tests/test-*" should be build from a source file
  "*/tests/test-*.c". Meaning: the source's and executable's name should
  correspond.

- test binaries should be named uniquely. Also, because older meson
  versions don't like having the same binary name more than once.

Rename to avoid the duplicate name.
2019-05-19 11:25:59 +02:00
Patrick J. Volkerding
e1df17e0ac hostname-manager: use fqdn for persistent hostname on Slackware
This will be the default for Slackware 15.0 and on.

This should be safe for both master and 1.12.x stable branch, as
no existing Slackware releases are expected to run NM-1.12.x or
later.

Signed-off-by: Robby Workman <rworkman@slackware.com>

https://mail.gnome.org/archives/networkmanager-list/2019-May/msg00011.html
2019-05-19 10:45:07 +02:00
Thomas Haller
041aa3d605 platform/tests: rename platform's "test-general.c"
Older versions of meson don't like building multiple artifacts
with the same name (even if they are in different directories). We
have multiple tests called "test-general.c", and it would be natural
to compile a test binary of the same name.

  Meson encountered an error in file src/tests/meson.build, line 14, column 2:
  Tried to create target "test-general", but a target of that name already exists.

It's generally a bad idea to have in our source tree multiple files with the
same name. Rename the test.

Fixes: 16cd84d346 ('build/meson: rename platform tests to use same name as autotools'):
2019-05-18 11:37:47 +02:00
Thomas Haller
16cd84d346 build/meson: rename platform tests to use same name as autotools
First of all, all file names in our source-tree should be unique. We should
not have stuff like "libnm-core/tests/test-general.c" and "src/tests/test-general.c".
The problem here are the C source files, and consequently also the test
binaries have duplicate names. We should avoid that in general. However,
our binaries should have a matching name with the C source. If
"test-general.c" is not good enough, that needs renaming. Not building
"platform-test-general" out of it.

On the other hand, all our tests should have a filename "*/tests/test-*", like
they do for autotools.

Rename the meson platform tests.

It's also important because "tools/run-nm-test.sh" relies on the test
name to workaround valgrind warnings.
2019-05-17 21:47:04 +02:00
Thomas Haller
b32ad2344e session-monitor: use "/run/ConsoleKit/database" instead of "/var/run/ConsoleKit/database"
There should be no difference in pratice. But we should not mention "/var/run"
as /var might not be mounted in early boot or rescue environment. Of course,
in those cases ConsoleKit is not running either. But still...
2019-05-17 21:24:18 +02:00
Thomas Haller
6a89f6c368 trivial: fix code comment mentioning "/var/run/NetworManager" to refer to "/run" 2019-05-17 21:24:18 +02:00
Thomas Haller
10688e3d88 tests: use "/run" instead of "/var/run" 2019-05-17 21:24:18 +02:00
Thomas Haller
5c3f5a846e dhcp/dhcpcd: fix location of PID file for dhcpcd
"RUNDIR" is set to "$runstatedir/NetworkManager". That is not correct,
we must use "$runstatedir".

I don't understand how this could have ever worked. Commit e2ecf5b808
('dhcp: dhcpcd uses a fixed path for PID files') seems to address this issue,
but already then "RUNDIR" was set to "$(localstatedir)/run/NetworkManager".
2019-05-17 21:24:18 +02:00
Thomas Haller
f8cbf06a77 logging: use stack allocated string buffer to constuct NM_LOG_DOMAINS field
NM_LOG_DOMAINS is a comma-separated list of the selected logging domains.

As the number of all logging domains is fixed at compile-time, the maximum
length of the buffer is known.

  $ git grep $'^\t{ LOGD_' | sed 's/.*"\(.*\)" .*/\1/' | xargs | sed 's/  */,/g' | sed 's/^/NM_LOG_DOMAINS=/'
  NM_LOG_DOMAINS=PLATFORM,RFKILL,ETHER,WIFI,BT,MB,DHCP4,DHCP6,PPP,WIFI_SCAN,IP4,IP6,AUTOIP4,DNS,VPN,SHARING,SUPPLICANT,AGENTS,SETTINGS,SUSPEND,CORE,DEVICE,OLPC,INFINIBAND,FIREWALL,ADSL,BOND,VLAN,BRIDGE,DBUS_PROPS,TEAM,CONCHECK,DCB,DISPATCH,AUDIT,SYSTEMD,VPN_PLUGIN,PROXY

Note that the static buffer "_all_logging_domains_to_str" is known
to be large enough to contain these domain names (it's even longer,
as it also contains "ALL", "IP", and "DHCP" alises). We can use that
to define the array of suitable size.
2019-05-17 21:12:38 +02:00
Thomas Haller
9cddb9f8bd logging: use static buffer in nm_logging_all_domains_to_string()
Don't create a heap allocated GString to hold the static
result of nm_logging_all_domains_to_string().

Instead, use a static buffer of the exactly required size.

The main reason to do this, is to get the exact size of
"_all_logging_domains_to_str" buffer. This is the upper
boundary for the size of a string buffer to hold all domain
names.
We will need that boundary in the next commit. The attractive
thing here is that we will have a unit-test failure if this
boundery no longer matches (--with-more-asserts). That means,
this boundary is guarded by unit tests and we don't accidentally
get it wrong when the domains change.

Also, take care to initialize the buffer in a thread-safe manner.
It's easy enough to get right, so there is no excuse for having
non-thread-safe code in logging.
2019-05-17 21:12:38 +02:00
Thomas Haller
cc2553e871 logging: don't misuse SYSLOG_FACILITY field in journal
Syslog's "facility" is a well defined thing and must be
one of a few well-known numbers. Don't re-use it for our
own purposes.

Fixes: 1b808d3b25 ('logging: add native systemd-journald support to nm-logging')

https://bugzilla.redhat.com/show_bug.cgi?id=1709741
2019-05-17 21:12:38 +02:00
Thomas Haller
467ac96dd1 logging: use char pointer for iov_free in _nm_log_impl() 2019-05-17 21:09:20 +02:00
Thomas Haller
138c187376 logging: fix stack overflow in logging for iov_data array
This overflow could only happen when we would try to log a message
with "NM_DEVICE=", "NM_CONNECTION=", and more than 8 logging domains
(_NUM_MAX_FIELDS_SYSLOG_FACILITY - 2).

The latter is never the case. While we sometimes log messages with
more than one logging domain, there are no logging statements that
use most as 8 different logging domains. So, this overflow is not
actually reachable from current code (I think).

Fixes: ed552c732c ('logging: log device and connection along with the message'):
2019-05-17 21:08:34 +02:00
Thomas Haller
87f3c50f48 wwan: minor cleanup for owns_port() to return early
I find

    for (i = 0; i < n_ports && !owns; i++)
        owns = ...

hard to read.

If the condition is satisfied, we can just return the result right
away.
2019-05-17 17:50:16 +02:00
Thomas Haller
03ab1466bd dhcp: use g_return_if_fail() instead of g_assert() in nm_dhcp_client_start_timeout() 2019-05-16 17:01:15 +02:00
Thomas Haller
98f4122673 core: ensure NUL padding interface name in nm_utils_ifname_cpy()
Always ensure that the entire buffer is initialized with padding NULs.

For example, valgrind checks whether we access uninitalized memory,
so leaving this uninitalized can be unexpected and cause valgrind
failures. In general, one might be tempted to copy the ifname buffer (of
well known size IFNAMSIZ) with memcpy(). In that case, we should not
have trailing garbage there.

We could use strncpy() for that (which guarantees NUL padding), but
then we still would have to ensure NUL termination. But strncpy() is
frowned upon, so let's not use it here.

Note that g_strlcpy() does not guarantee NUL padding, so it's
unsuitable.

We could also implement this with a combination of memcpy() and
memset(). But in this case, it just seems simpler to iterate over the
16 bytes and do it manually.
2019-05-16 10:17:33 +02:00
Thomas Haller
e9c76f375b platform: avoid valgrind warning about uninitialised memory in _ioctl_call()
==6207== Syscall param ioctl(SIOCETHTOOL) points to uninitialised byte(s)
==6207==    at 0x514603B: ioctl (syscall-template.S:78)
==6207==    by 0x19FC2F: _ioctl_call (nm-platform-utils.c:183)
==6207==    by 0x1A026B: _ethtool_call_handle (nm-platform-utils.c:319)
==6207==    by 0x1A031F: ethtool_get_stringset (nm-platform-utils.c:378)
==6207==    by 0x1A03BC: ethtool_get_stringset_index (nm-platform-utils.c:414)
==6207==    by 0x1A181E: nmp_utils_ethtool_supports_vlans (nm-platform-utils.c:912)
==6207==    by 0x1756D7: link_supports_vlans (nm-linux-platform.c:6508)
==6207==    by 0x1A81D8: nm_platform_link_supports_vlans (nm-platform.c:1536)
==6207==    by 0x14B96B: test_internal (test-link.c:602)
==6207==    by 0x4F5C18D: test_case_run (gtestutils.c:2597)
==6207==    by 0x4F5C18D: g_test_run_suite_internal (gtestutils.c:2685)
==6207==    by 0x4F5BF33: g_test_run_suite_internal (gtestutils.c:2697)
==6207==    by 0x4F5C679: g_test_run_suite (gtestutils.c:2772)
==6207==    by 0x4F5C694: g_test_run (gtestutils.c:2007)
==6207==    by 0x166B4D: main (test-common.c:2092)
==6207==  Address 0x1ffeffeecf is on thread 1's stack
==6207==  in frame #1, created by _ioctl_call (nm-platform-utils.c:110)
==6207==

"ifname" is the stack-allocated array "known_ifnames" of suitable
IFNAMSIZ bytes. But it may not be fully initialized, so using memcpy()
to copy the string leads to unintialized warning.

We really should only copy the valid bytes, either with strcpy() or our
nm_utils_ifname_cpy() wrapper.

Fixes: 856322562e ('platform/ethtool,mii: retry ioctl when interface name was renamed for ehttool/mii')
2019-05-16 10:17:04 +02:00
Thomas Haller
065d891402 platform: use memset() to initialize ifr struct in _ioctl_call()
"struct ifreq" contains a union field, and initalizing the struct is not
guaranteed to fill all bytes with zero (it only sets the first union
member to zero).

Since we later return the entire struct, ensure that it's initialized to
all zero by using memset().
2019-05-16 08:51:56 +02:00
Thomas Haller
e813bdaf5e ifcfg-rh: use a macro to initialize setting_8021x_scheme_vtable
Without macro, there is a lot of redundant information which makes it harder
to visually parse what is set.
2019-05-15 09:40:49 +02:00
Thomas Haller
9834c08b1a ifcfg-rh: stack allocate key names in write_object() 2019-05-15 08:43:01 +02:00
Thomas Haller
37faab73a8 systemd: merge branch systemd into master 2019-05-14 16:09:39 +02:00
Thomas Haller
f61a12ee20 systemd: update code from upstream (2019-05-14)
This is a direct dump from systemd git.

======

SYSTEMD_DIR=../systemd
COMMIT=b6ec9afd44934a599a761e8c741077a7512e0c82

(
  cd "$SYSTEMD_DIR"
  git checkout "$COMMIT"
  git reset --hard
  git clean -fdx
)

git ls-files -z :/src/systemd/src/ \
                :/shared/systemd/src/ \
                :/shared/nm-utils/unaligned.h | \
  xargs -0 rm -f

nm_copy_sd_shared() {
    mkdir -p "./shared/systemd/$(dirname "$1")"
    cp "$SYSTEMD_DIR/$1" "./shared/systemd/$1"
}

nm_copy_sd_core() {
    mkdir -p "./src/systemd/$(dirname "$1")"
    cp "$SYSTEMD_DIR/$1" "./src/systemd/$1"
}

nm_copy_sd_nmutils() {
    mkdir -p "./shared/nm-utils/"
    cp "$SYSTEMD_DIR/$1" "./shared/nm-utils/${1##*/}"
}

nm_copy_sd_core "src/libsystemd-network/arp-util.c"
nm_copy_sd_core "src/libsystemd-network/arp-util.h"
nm_copy_sd_core "src/libsystemd-network/dhcp-identifier.c"
nm_copy_sd_core "src/libsystemd-network/dhcp-identifier.h"
nm_copy_sd_core "src/libsystemd-network/dhcp-internal.h"
nm_copy_sd_core "src/libsystemd-network/dhcp-lease-internal.h"
nm_copy_sd_core "src/libsystemd-network/dhcp-network.c"
nm_copy_sd_core "src/libsystemd-network/dhcp-option.c"
nm_copy_sd_core "src/libsystemd-network/dhcp-packet.c"
nm_copy_sd_core "src/libsystemd-network/dhcp-protocol.h"
nm_copy_sd_core "src/libsystemd-network/dhcp6-internal.h"
nm_copy_sd_core "src/libsystemd-network/dhcp6-lease-internal.h"
nm_copy_sd_core "src/libsystemd-network/dhcp6-network.c"
nm_copy_sd_core "src/libsystemd-network/dhcp6-option.c"
nm_copy_sd_core "src/libsystemd-network/dhcp6-protocol.h"
nm_copy_sd_core "src/libsystemd-network/lldp-internal.h"
nm_copy_sd_core "src/libsystemd-network/lldp-neighbor.c"
nm_copy_sd_core "src/libsystemd-network/lldp-neighbor.h"
nm_copy_sd_core "src/libsystemd-network/lldp-network.c"
nm_copy_sd_core "src/libsystemd-network/lldp-network.h"
nm_copy_sd_core "src/libsystemd-network/network-internal.c"
nm_copy_sd_core "src/libsystemd-network/network-internal.h"
nm_copy_sd_core "src/libsystemd-network/sd-dhcp-client.c"
nm_copy_sd_core "src/libsystemd-network/sd-dhcp-lease.c"
nm_copy_sd_core "src/libsystemd-network/sd-dhcp6-client.c"
nm_copy_sd_core "src/libsystemd-network/sd-dhcp6-lease.c"
nm_copy_sd_core "src/libsystemd-network/sd-ipv4acd.c"
nm_copy_sd_core "src/libsystemd-network/sd-ipv4ll.c"
nm_copy_sd_core "src/libsystemd-network/sd-lldp.c"
nm_copy_sd_core "src/libsystemd/sd-event/event-source.h"
nm_copy_sd_core "src/libsystemd/sd-event/event-util.c"
nm_copy_sd_core "src/libsystemd/sd-event/event-util.h"
nm_copy_sd_core "src/libsystemd/sd-event/sd-event.c"
nm_copy_sd_core "src/libsystemd/sd-id128/id128-util.c"
nm_copy_sd_core "src/libsystemd/sd-id128/id128-util.h"
nm_copy_sd_core "src/libsystemd/sd-id128/sd-id128.c"
nm_copy_sd_core "src/shared/dns-domain.c"
nm_copy_sd_core "src/shared/dns-domain.h"
nm_copy_sd_core "src/systemd/_sd-common.h"
nm_copy_sd_core "src/systemd/sd-dhcp-client.h"
nm_copy_sd_core "src/systemd/sd-dhcp-lease.h"
nm_copy_sd_core "src/systemd/sd-dhcp6-client.h"
nm_copy_sd_core "src/systemd/sd-dhcp6-lease.h"
nm_copy_sd_core "src/systemd/sd-event.h"
nm_copy_sd_core "src/systemd/sd-id128.h"
nm_copy_sd_core "src/systemd/sd-ipv4acd.h"
nm_copy_sd_core "src/systemd/sd-ipv4ll.h"
nm_copy_sd_core "src/systemd/sd-lldp.h"
nm_copy_sd_core "src/systemd/sd-ndisc.h"
nm_copy_sd_nmutils "src/basic/unaligned.h"
nm_copy_sd_shared "src/basic/alloc-util.c"
nm_copy_sd_shared "src/basic/alloc-util.h"
nm_copy_sd_shared "src/basic/async.h"
nm_copy_sd_shared "src/basic/env-file.c"
nm_copy_sd_shared "src/basic/env-file.h"
nm_copy_sd_shared "src/basic/env-util.c"
nm_copy_sd_shared "src/basic/env-util.h"
nm_copy_sd_shared "src/basic/errno-util.h"
nm_copy_sd_shared "src/basic/escape.c"
nm_copy_sd_shared "src/basic/escape.h"
nm_copy_sd_shared "src/basic/ether-addr-util.c"
nm_copy_sd_shared "src/basic/ether-addr-util.h"
nm_copy_sd_shared "src/basic/extract-word.c"
nm_copy_sd_shared "src/basic/extract-word.h"
nm_copy_sd_shared "src/basic/fd-util.c"
nm_copy_sd_shared "src/basic/fd-util.h"
nm_copy_sd_shared "src/basic/fileio.c"
nm_copy_sd_shared "src/basic/fileio.h"
nm_copy_sd_shared "src/basic/fs-util.c"
nm_copy_sd_shared "src/basic/fs-util.h"
nm_copy_sd_shared "src/basic/hash-funcs.c"
nm_copy_sd_shared "src/basic/hash-funcs.h"
nm_copy_sd_shared "src/basic/hashmap.c"
nm_copy_sd_shared "src/basic/hashmap.h"
nm_copy_sd_shared "src/basic/hexdecoct.c"
nm_copy_sd_shared "src/basic/hexdecoct.h"
nm_copy_sd_shared "src/basic/hostname-util.c"
nm_copy_sd_shared "src/basic/hostname-util.h"
nm_copy_sd_shared "src/basic/in-addr-util.c"
nm_copy_sd_shared "src/basic/in-addr-util.h"
nm_copy_sd_shared "src/basic/io-util.c"
nm_copy_sd_shared "src/basic/io-util.h"
nm_copy_sd_shared "src/basic/list.h"
nm_copy_sd_shared "src/basic/log.h"
nm_copy_sd_shared "src/basic/macro.h"
nm_copy_sd_shared "src/basic/memory-util.c"
nm_copy_sd_shared "src/basic/memory-util.h"
nm_copy_sd_shared "src/basic/mempool.c"
nm_copy_sd_shared "src/basic/mempool.h"
nm_copy_sd_shared "src/basic/missing_fcntl.h"
nm_copy_sd_shared "src/basic/missing_socket.h"
nm_copy_sd_shared "src/basic/missing_stat.h"
nm_copy_sd_shared "src/basic/missing_type.h"
nm_copy_sd_shared "src/basic/parse-util.c"
nm_copy_sd_shared "src/basic/parse-util.h"
nm_copy_sd_shared "src/basic/path-util.c"
nm_copy_sd_shared "src/basic/path-util.h"
nm_copy_sd_shared "src/basic/prioq.c"
nm_copy_sd_shared "src/basic/prioq.h"
nm_copy_sd_shared "src/basic/process-util.c"
nm_copy_sd_shared "src/basic/process-util.h"
nm_copy_sd_shared "src/basic/random-util.c"
nm_copy_sd_shared "src/basic/random-util.h"
nm_copy_sd_shared "src/basic/set.h"
nm_copy_sd_shared "src/basic/signal-util.h"
nm_copy_sd_shared "src/basic/siphash24.h"
nm_copy_sd_shared "src/basic/socket-util.c"
nm_copy_sd_shared "src/basic/socket-util.h"
nm_copy_sd_shared "src/basic/sort-util.h"
nm_copy_sd_shared "src/basic/sparse-endian.h"
nm_copy_sd_shared "src/basic/stat-util.c"
nm_copy_sd_shared "src/basic/stat-util.h"
nm_copy_sd_shared "src/basic/stdio-util.h"
nm_copy_sd_shared "src/basic/string-table.c"
nm_copy_sd_shared "src/basic/string-table.h"
nm_copy_sd_shared "src/basic/string-util.c"
nm_copy_sd_shared "src/basic/string-util.h"
nm_copy_sd_shared "src/basic/strv.c"
nm_copy_sd_shared "src/basic/strv.h"
nm_copy_sd_shared "src/basic/time-util.c"
nm_copy_sd_shared "src/basic/time-util.h"
nm_copy_sd_shared "src/basic/tmpfile-util.c"
nm_copy_sd_shared "src/basic/tmpfile-util.h"
nm_copy_sd_shared "src/basic/umask-util.h"
nm_copy_sd_shared "src/basic/utf8.c"
nm_copy_sd_shared "src/basic/utf8.h"
nm_copy_sd_shared "src/basic/util.c"
nm_copy_sd_shared "src/basic/util.h"
2019-05-14 15:26:04 +02:00
Thomas Haller
dc3a2f9bc4 core: fix file permissions for "/var/lib/NetworkManager/secret_key"
Ooherwise, the file has wrong permissions:

  # ls -la /var/lib/NetworkManager/secret_key
  ----r-xr-x. 1 root root 50 May 14 13:52 /var/lib/NetworkManager/secret_key

Luckily, /var/lib/NetworkManager should be already

  # ls -lad /var/lib/NetworkManager
  drwx------. 2 root root 8192 May 14 13:57 /var/lib/NetworkManager

which mitigates this a bit.

Fixes: dbcb1d6d97 ('core: let nm_utils_secret_key_read() handle failures internally')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/175
2019-05-14 13:59:08 +02:00
Thomas Haller
58df3f37ea core: don't log plain pointer values for singletons
Logging pointer values allows to defeat ASLR. Don't do that.
2019-05-13 09:25:05 +02:00
Thomas Haller
156f4ee53f core/pppd-plugin: use GDBusConnection in "nm-pppd-plugin.c"
- use GDBusConnection instead of GDBusProxy.

- namespace global variables with a "gl" struct.

- don't log __func__. If a log line should have a certain
  topic/tag, the tag should be set manually, not based on the
  function name. It just looks odd. Also, it's unnecessary.
2019-05-13 09:25:05 +02:00
Thomas Haller
83476a3fb6 pacrunner: refactor pacrunner to use GDBusConnection
- use GDBusConnection instead of GDBusProxy.

- rename "call-id" to "conf-id". It's really not a "call" but
  configuration that gets added and NMPacrunnerManager ensures that
  the configuration is send to pacrunner.

- let "conf-id" keep a reference to NMPacrunnerManager. For one,
  when we remove configurations we need to call DestroyProxyConfiguration
  to remove it again. We cannot just abort the requests but must linger
  around until our configuration is properly cleaned up. Hence, we
  anyway cannot destroy the NMPacrunnerManager earlier.
  With respect to fixing shutdown not to leak anything, this merely
  means that we must wait (and iterate the main loop) as long as
  NMPacrunnerManager singleton still exits (that is anyway the plan
  how to fix shutdown).
  With these considerations it's also clear that our D-Bus calls must
  have a stricter timeout: NM_SHUTDOWN_TIMEOUT_MS.
  This is also nice because nm_pacrunner_manager_remove() no longer
  needs a manager parameter, it can just rely on having a reference
  to the manager.

- for logging the configuration IDs, don't log pointer values.
  Logging pointer values should be avoided as it defeats ASLR.
  Instead, give them a "log_id" number.

- pacrunner is a D-Bus activatable service. D-Bus activatable services
  needs special care. We don't want to start it over and over again.
  Instead, we only try to "StartServiceByName" if

    - we have any configuration to add

    - if pacrunner is currently confirmed not to be running (by watching
      name owner changes)

    - we didn't try to start it already. That means, only start it
      at the beginning and afterwards set a flag to block it. When
      we see pacrunner appear on D-Bus we always clear that flag,
      that means if pacrunner drops of, we will try to restart it
      (once).
2019-05-13 09:24:02 +02:00
Thomas Haller
cbdb498197 auth-manager: don't watch polkit's D-Bus name and don't emit change signal when NameOwner disconnects
PolicyKit is a D-Bus activatable service. I don't think it exits on idle (but maybe
it does, it certainly should).

Anyway, NetworkManager was watching the NameOwner of polkit and if the name was lost(!)
it would emit a NM_AUTH_MANAGER_SIGNAL_CHANGED, which causes the internal code to re-authenticate
right away. That means, if you stop policy kit, NetworkManager will ask it right away and
D-Bus activate it. This is not right.

In fact, we don't have to care about the name owner at all. Whenever we make a request,
we just make it and D-Bus activate the service as needed. If polkit starts, it emits a
Changed signal that we watch on D-Bus. That is the only moment when we should actually
emit NM_AUTH_MANAGER_SIGNAL_CHANGED, not when polkit disconnects.
2019-05-12 09:56:36 +02:00
Thomas Haller
6153cb0000 auth-manager: drop GDBusProxy and use GDBusConnection directly
Aside avoiding the unnecessary overhead of GDBusProxy, this simplifies
NMAuthManager because the instance is ready from the start to use D-Bus.

Previously, in the early phase requests needed to be queued until
GDBusProxy could be created asynchronously. Now, there is nothing
asynchronous involved during construction of the NMAuthManager (and
of course there are no blocking calls).
2019-05-12 09:56:36 +02:00
Thomas Haller
458a5e6531 src: use nm_dbus_connection_call_start_service_by_name() 2019-05-12 09:56:36 +02:00
Thomas Haller
309271ac17 all: use nm_clear_g_dbus_connection_signal() helper
I also like this because it's non-obvious that subscription IDs from
GDBusConnection are "guint" (contrary to signal handler IDs which are
"gulong"). So, by using this API you get a compiler error when using the
wrong type.
In the past, when switching to nm_clear_g_signal_handler() this uncovered
multiple bugs where the wrong type was used to hold the ID.
2019-05-12 09:56:36 +02:00
Thomas Haller
b9e2fcccf7 all: use nm_dbus_connection_signal_subscribe_name_owner_changed()
... and nm_dbus_connection_call_get_name_owner().
2019-05-12 09:56:36 +02:00
Thomas Haller
a381b3999e core/dbus: aquire D-Bus name earlier before initializing NMPlatform/NMNetns singletons
Aquiring the bus early tells systemd that NetworkManager is started.
Do that even before setting up/creating the singletons for NMPlatform
and NMNetns.

This is a trick so that NetworkManager is considered earlier to be started.
But it's right, because we can and should create the D-Bus socket as early as
possible to let other services (that order After=network.target) can already
start too.

Of course, NetworkManager is not yet fully running and it will take a
while longer until it actually replies on D-Bus. But the requests are
not lost and services that talk to NetworkManager that early can in the
meantime to other startup actions.
2019-05-12 09:56:36 +02:00
Thomas Haller
40fb6652a2 auth-manager: re-use D-Bus connection from NMDBusManager
First of all, NMDBusManager takes the system D-Bus connection synchronously, so we
should avoid API that is asynchronous and first needs to get glib's G_BUS_TYPE_SYSTEM
instance.

Also, the only reason why NMDBusManager might not have a D-Bus connection is in "initrd"
configure-and-quit mode. In that mode we also don't need polkit.
2019-05-12 09:56:36 +02:00
Thomas Haller
1e01c5fec9 core: use NM_MAIN_DBUS_CONNECTION_GET macro
We will use the D-Bus connection of our NMDBusManager singleton more.
Use a macro.

- it's shorter to type and it's one distinct word.

- the name indicates what this is: the main D-Bus connection singleton.
  By searching for this name we can find all users that care about using
  this singleton.
2019-05-12 09:56:36 +02:00
Thomas Haller
143b6e41af core: add NM_MAIN_DBUS_CONNECTION_GET macro 2019-05-12 09:56:36 +02:00
Thomas Haller
49ed2079ab core/dbus: let NMDBusManager create a D-Bus connection in "configure-and-quit=true" mode
Note that various components (NMFirewallManager, NMAuthManager,
NMConnectivity, etc.pp) all request their own GDBusConnection from
glib's G_BUS_TYPE_SYSTEM singleton.

In the future, let them instead use the D-Bus connection that
NMDBusManager already has.

- NMDBusManager also uses g_bus_get(G_BUS_TYPE_SYSTEM), so in practice this
  is just the same GDBusConnection instance.

- if it would not be the same GDBusConnection instance, it would
  be more correct/logical to use the one that NMDBusManager uses.

- NMDBusManager already aquired the GDBusConnection synchronously
  and it's ready for use. On the other hand, g_bus_get()/g_bus_get_sync()
  has the notion that getting the singleton cannot be done without
  waiting/blocking. So at least it involves locking or even dispatching
  the async reply on D-Bus.

- in "configure-and-quit=initrd" we really don't have D-Bus available.
  NMDBusManager should control whether the other components use D-Bus
  or not. For example, NMFirewallManager should not ask glib for a
  G_BUS_TYPE_SYSTEM singleton only to later find out that it doesn't work.

So if these components would reuse NMDBusManager's GDBusConnection,
then it must have the connection also in regular "configure-and-quit=true"
mode. In this case, we are in late boot and want do connectivity
checking and talk to firewalld.
2019-05-12 09:56:36 +02:00
Thomas Haller
4e24ebcc7b core: minor cleanup 2019-05-12 09:56:36 +02:00
Thomas Haller
5a3ffffe74 auth-chain: don't copy ChainData tag
All callers pass a C string literal as the user-data tag of NMAuthChain.
It makes little sense otherwise because you usually know which user data
you need in advance.

So don't bother with copying the string. Just reference the defacto
static string.

Rename nm_auth_chain_set_data() to nm_auth_chain_set_data_unsafe() to indicate
that the lifetime of the tag string is now the caller's responsibility.

The nm_auth_chain_set_data() macro now ensures that the tag argument is
a C string literal. In fact, all callers that we had did that already.
2019-05-12 09:56:36 +02:00
Thomas Haller
04fafd582b manager: use "perm" name for nm_auth_chain_set_data() tag in device_auth_request_cb()
There are two similar cases where the caller attaches the requested
permission to the auth-chain. There the tag "perm" is used.

Rename for consistency.
2019-05-12 09:56:36 +02:00
Thomas Haller
9df2abea53 auth-chain: don't clone the permission string for AuthChain
Out of the 33 callers of nm_auth_chain_add_call(), the permission
argument is:

 - 29 times a C string literal like NM_AUTH_PERMISSION_NETWORK_CONTROL.

 - 3 times assign a string that is in fact a static string (it's just
   not a string literal)

 - only NMManager's device_auth_request_cb() passes a permission of
   (possibly) non static origin. But it already duplicates the string
   for it's own purposes and attaches it as user-data to the
   NMAuthChain.

There really is no need to duplicate the string.

Replace nm_auth_chain_add_call() by a macro that ensures that the
permission string is a C literal.

Rename nm_auth_chain_add_call() to nm_auth_chain_add_call_unsafe() to
indicate that the lifetime of the permission argument is now the
responsibility of the caller.
2019-05-12 09:56:36 +02:00
Thomas Haller
6c63799e4f auth-chain: don't allow setting the same user-data twice
We track the user-data in a linked list. Hence, when setting
a user data we would need to search the list whether the
tag already exists.

This has an overhead and makes set-data() O(n). But we really don't need
this. The NMAuthChain allows a simple way to attach user-data to the
request. We don't need a full-blown g_object_set_data() (which btw is
also just implemented as a linked list).
2019-05-12 09:56:36 +02:00
Thomas Haller
58ee66404d auth-chain: don't put permission results into regular user data
NMAuthChain tracks arbitrary user-data pointers for convenience of the
caller.

Previously, it would also track the permission request result as such
user-data. That is not optimal.

- for one, we should keep the namespaces for user data (tags) and
  permissions separate. When the user requests a permission result with
  nm_auth_chain_get_result() then clearly no user-data is requested.

- we already track permissions in a separate linked list. Previously, when the
  auth-call completes, we would destroy the entry in the linked list for
  requests and create an entry in the linked list for user-data.
  Possibly this was done in the past, because the user-data list was
  indexed by a hash table. So, in that case, we only would need to
  lookup the permission results in the indexed user-data hash, but never
  do any search of a linked list. That is no longer the case, because
  in practice the number of tracked user-data/permissions is fixed and
  small (at which point it's just more efficient to search a short
  linked list).

- There is already distrinct API for getting user-data and permissions.
  By keeping the lists separate we don't need to search the list for
  entries of the wrong type (it's faster).

- also assert that nm_auth_chain_get_result() indeed asks for a result
  that was previously requested. It makes no sense otherwise.
2019-05-12 09:56:36 +02:00
Thomas Haller
d460ec8e67 core: remove unused error argument from NMAuthChainResultFunc
NMAuthChain usually requests several permissions at once. Hence, an error
argument in the overall callback does not make sense, because you
wouldn't know which request failed.

If at all, it could only mean that the overall request failed (like an
D-Bus failure communicating to D-Bus *for all permisssions*),
but we don't need to handle that specially. In fact, we don't really care
why permission was not granted, whether it's due to an error or legitimate
reasons.

The error in the callback was always set to %NULL. Remove it.
2019-05-12 09:56:36 +02:00
Thomas Haller
f8de94736e auth-chain: use linked list instead of hash table to track user data of NMAuthChain
The number of user-datas attached to the NMAuthChain is generally fixed
and small.

For example, in current code impl_manager_get_permissions() will be the
instance that ends up with the largest number of data items. It
performs zero calls of nm_auth_chain_set_data() but 16 times
nm_auth_chain_add_call(). So currently the maximum number is 16.

With such a fixed, small number of elements it is expected to be more
efficient to just track the elements in a CList instead of a GHashTable.
2019-05-12 09:56:36 +02:00
Thomas Haller
6085ded6f4 auth-chain: cleanup chain-data in NMAuthChain
- consistently name the ChainData variable "chain_data"

- return the ChainData element from _get_data(). This way it
  also can be used by nm_auth_chain_steal_data(), which needs
  the ChainData element.
2019-05-12 09:56:36 +02:00
Thomas Haller
4d79e3276b auth-chain: embed copy of permission string in AuthCall
Since the allocated AuthCall struct is small, we can just copy the
permission string inside the struct. No need to strdup() the string
separately.
2019-05-12 09:56:36 +02:00