]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/userdb/userdbd.c
Merge pull request #31000 from flatcar-hub/krnowak/mutable-overlays
[thirdparty/systemd.git] / src / userdb / userdbd.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include <sys/stat.h>
4 #include <sys/types.h>
5
6 #include "daemon-util.h"
7 #include "userdbd-manager.h"
8 #include "log.h"
9 #include "main-func.h"
10 #include "signal-util.h"
11
12 /* This service offers two Varlink services, both implementing io.systemd.UserDatabase:
13 *
14 * → io.systemd.NameServiceSwitch: this is a compatibility interface for glibc NSS: it responds to
15 * name lookups by checking the classic NSS interfaces and responding that.
16 *
17 * → io.systemd.Multiplexer: this multiplexes lookup requests to all Varlink services that have a
18 * socket in /run/systemd/userdb/. It's supposed to simplify clients that don't want to implement
19 * the full iterative logic on their own.
20 *
21 * → io.systemd.DropIn: this makes JSON user/group records dropped into /run/userdb/ available as
22 * regular users.
23 */
24
25 static int run(int argc, char *argv[]) {
26 _cleanup_(manager_freep) Manager *m = NULL;
27 _unused_ _cleanup_(notify_on_cleanup) const char *notify_stop = NULL;
28 int r;
29
30 log_setup();
31
32 umask(0022);
33
34 if (argc != 1)
35 return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "This program takes no arguments.");
36
37 if (setenv("SYSTEMD_BYPASS_USERDB", "io.systemd.NameServiceSwitch:io.systemd.Multiplexer:io.systemd.DropIn", 1) < 0)
38 return log_error_errno(errno, "Failed to set $SYSTEMD_BYPASS_USERDB: %m");
39
40 assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGCHLD) >= 0);
41
42 r = manager_new(&m);
43 if (r < 0)
44 return log_error_errno(r, "Could not create manager: %m");
45
46 r = manager_startup(m);
47 if (r < 0)
48 return log_error_errno(r, "Failed to start up daemon: %m");
49
50 notify_stop = notify_start(NOTIFY_READY, NOTIFY_STOPPING);
51
52 r = sd_event_loop(m->event);
53 if (r < 0)
54 return log_error_errno(r, "Event loop failed: %m");
55
56 return 0;
57 }
58
59 DEFINE_MAIN_FUNCTION(run);