Debian Codegraph @

src/userdb/userdbd.c

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