]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved.c
2 This file is part of systemd.
4 Copyright 2014 Tom Gundersen <teg@jklm.no>
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 #include "sd-daemon.h"
23 #include "capability-util.h"
25 #include "resolved-conf.h"
26 #include "resolved-manager.h"
27 #include "resolved-resolv-conf.h"
28 #include "selinux-util.h"
29 #include "signal-util.h"
30 #include "user-util.h"
32 int main(int argc
, char *argv
[]) {
33 _cleanup_(manager_freep
) Manager
*m
= NULL
;
34 const char *user
= "systemd-resolve";
39 log_set_target(LOG_TARGET_AUTO
);
40 log_parse_environment();
44 log_error("This program takes no arguments.");
51 r
= mac_selinux_init();
53 log_error_errno(r
, "SELinux setup failed: %m");
57 r
= get_user_creds(&user
, &uid
, &gid
, NULL
, NULL
);
59 log_error_errno(r
, "Cannot resolve user name %s: %m", user
);
63 /* Always create the directory where resolv.conf will live */
64 r
= mkdir_safe_label("/run/systemd/resolve", 0755, uid
, gid
);
66 log_error_errno(r
, "Could not create runtime directory: %m");
70 /* Drop privileges, but keep three caps. Note that we drop those too, later on (see below) */
71 r
= drop_privileges(uid
, gid
,
72 (UINT64_C(1) << CAP_NET_RAW
)| /* needed for SO_BINDTODEVICE */
73 (UINT64_C(1) << CAP_NET_BIND_SERVICE
)| /* needed to bind on port 53 */
74 (UINT64_C(1) << CAP_SETPCAP
) /* needed in order to drop the caps later */);
78 assert_se(sigprocmask_many(SIG_BLOCK
, NULL
, SIGTERM
, SIGINT
, SIGUSR1
, SIGUSR2
, -1) >= 0);
82 log_error_errno(r
, "Could not create manager: %m");
88 log_error_errno(r
, "Failed to start manager: %m");
92 /* Write finish default resolv.conf to avoid a dangling symlink */
93 (void) manager_write_resolv_conf(m
);
95 /* Let's drop the remaining caps now */
96 r
= capability_bounding_set_drop(0, true);
98 log_error_errno(r
, "Failed to drop remaining caps: %m");
104 "STATUS=Processing requests...");
106 r
= sd_event_loop(m
->event
);
108 log_error_errno(r
, "Event loop failed: %m");
112 sd_event_get_exit_code(m
->event
, &r
);
117 "STATUS=Shutting down...");
119 return r
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;