diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-01-17 03:35:25 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-01-17 03:35:28 +0900 |
commit | 0a02e38379950b38263639b07ab1010fe38c5321 (patch) | |
tree | cdbbef6f551091932f60cbc5f2fd1d361beb89b2 /src/network/networkd.c | |
parent | d1c2774b6d246046b1ba68e7d794c9e50e521ec4 (diff) | |
download | systemd-0a02e38379950b38263639b07ab1010fe38c5321.tar.gz |
network: create runtime sub-directories after drop_privileges()
For old kernels not supporting AmbientCapabilities=, networkd is
started as root with limited capabilities. Then, networkd cannot
chown the directories under runtime directory as
CapabilityBoundingSet= does not contains enough capabilities.
This makes these directories are created after dropping privileges.
Thus, networkd does not need to chown them anymore.
Fixes #7863.
Diffstat (limited to 'src/network/networkd.c')
-rw-r--r-- | src/network/networkd.c | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/src/network/networkd.c b/src/network/networkd.c index 9243384af8..79c15d4111 100644 --- a/src/network/networkd.c +++ b/src/network/networkd.c @@ -53,24 +53,13 @@ int main(int argc, char *argv[]) { goto out; } - /* Always create the directories people can create inotify - * watches in. */ + /* Create runtime directory. This is not necessary when networkd is + * started with "RuntimeDirectory=systemd/netif", or after + * systemd-tmpfiles-setup.service. */ r = mkdir_safe_label("/run/systemd/netif", 0755, uid, gid, false); if (r < 0) log_warning_errno(r, "Could not create runtime directory: %m"); - r = mkdir_safe_label("/run/systemd/netif/links", 0755, uid, gid, false); - if (r < 0) - log_warning_errno(r, "Could not create runtime directory 'links': %m"); - - r = mkdir_safe_label("/run/systemd/netif/leases", 0755, uid, gid, false); - if (r < 0) - log_warning_errno(r, "Could not create runtime directory 'leases': %m"); - - r = mkdir_safe_label("/run/systemd/netif/lldp", 0755, uid, gid, false); - if (r < 0) - log_warning_errno(r, "Could not create runtime directory 'lldp': %m"); - /* Drop privileges, but only if we have been started as root. If we are not running as root we assume all * privileges are already dropped. */ if (geteuid() == 0) { @@ -83,6 +72,21 @@ int main(int argc, char *argv[]) { goto out; } + /* Always create the directories people can create inotify watches in. + * It is necessary to create the following subdirectories after drop_privileges() + * to support old kernels not supporting AmbientCapabilities=. */ + r = mkdir_safe_label("/run/systemd/netif/links", 0755, uid, gid, false); + if (r < 0) + log_warning_errno(r, "Could not create runtime directory 'links': %m"); + + r = mkdir_safe_label("/run/systemd/netif/leases", 0755, uid, gid, false); + if (r < 0) + log_warning_errno(r, "Could not create runtime directory 'leases': %m"); + + r = mkdir_safe_label("/run/systemd/netif/lldp", 0755, uid, gid, false); + if (r < 0) + log_warning_errno(r, "Could not create runtime directory 'lldp': %m"); + assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGTERM, SIGINT, -1) >= 0); r = sd_event_default(&event); |