1 /* SPDX-License-Identifier: LGPL-2.1+ */
4 #include "nscd-flush.h"
8 static int on_nscd_cache_flush_event(sd_event_source
*s
, void *userdata
) {
9 /* Let's ask glibc's nscd daemon to flush its caches. We request this for the three database machines may show
10 * up in: the hosts database (for resolvable machine names) and the user and group databases (for the user ns
13 (void) nscd_flush_cache(STRV_MAKE("passwd", "group", "hosts"));
17 int manager_enqueue_nscd_cache_flush(Manager
*m
) {
22 if (!m
->nscd_cache_flush_event
) {
23 r
= sd_event_add_defer(m
->event
, &m
->nscd_cache_flush_event
, on_nscd_cache_flush_event
, m
);
25 return log_error_errno(r
, "Failed to allocate NSCD cache flush event: %m");
27 sd_event_source_set_description(m
->nscd_cache_flush_event
, "nscd-cache-flush");
30 r
= sd_event_source_set_enabled(m
->nscd_cache_flush_event
, SD_EVENT_ONESHOT
);
32 m
->nscd_cache_flush_event
= sd_event_source_unref(m
->nscd_cache_flush_event
);
33 return log_error_errno(r
, "Failed to enable NSCD cache flush event: %m");
39 int manager_find_machine_for_uid(Manager
*m
, uid_t uid
, Machine
**ret_machine
, uid_t
*ret_internal_uid
) {
44 assert(uid_is_valid(uid
));
46 /* Finds the machine for the specified host UID and returns it along with the UID translated into the
47 * internal UID inside the machine */
49 HASHMAP_FOREACH(machine
, m
->machines
) {
52 r
= machine_owns_uid(machine
, uid
, &converted
);
57 *ret_machine
= machine
;
60 *ret_internal_uid
= converted
;
69 *ret_internal_uid
= UID_INVALID
;
74 int manager_find_machine_for_gid(Manager
*m
, gid_t gid
, Machine
**ret_machine
, gid_t
*ret_internal_gid
) {
79 assert(gid_is_valid(gid
));
81 HASHMAP_FOREACH(machine
, m
->machines
) {
84 r
= machine_owns_gid(machine
, gid
, &converted
);
89 *ret_machine
= machine
;
92 *ret_internal_gid
= converted
;
100 if (ret_internal_gid
)
101 *ret_internal_gid
= GID_INVALID
;