From: Lennart Poettering Date: Fri, 10 Jul 2026 07:07:49 +0000 (+0200) Subject: homed: set user.userdb xattrs on homed's userdb socket X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e3876f7559252ba6fb7581c9f6649ddd180422e5;p=thirdparty%2Fsystemd.git homed: set user.userdb xattrs on homed's userdb socket We can't make a lot of restrictions here, since users are allowed to basically freely pick their user names and UIDs too. But let's at least exclude system UID ranges and those beyond the 16bit range. --- diff --git a/src/home/homed-manager.c b/src/home/homed-manager.c index b949c4b8fdb..a19dc3f6c8a 100644 --- a/src/home/homed-manager.c +++ b/src/home/homed-manager.c @@ -65,6 +65,7 @@ #include "varlink-io.systemd.UserDatabase.h" #include "varlink-io.systemd.service.h" #include "varlink-util.h" +#include "xattr-util.h" /* Where to look for private/public keys that are used to sign the user records. We are not using * CONF_PATHS_NULSTR() here since we want to insert /var/lib/systemd/home/ in the middle. And we insert that @@ -1102,6 +1103,13 @@ static int manager_bind_varlink(Manager *m) { if (r < 0) return log_error_errno(r, "Failed to bind to varlink socket '%s': %m", socket_path); + /* Reduce the noise routed to us: advertise that only look-ups for non-system users in the 16bit + * range are routed to us (excluding 'nobody', i.e. 0xfffe) */ + char text[DECIMAL_STR_MAX(uid_t) + 1 + DECIMAL_STR_MAX(gid_t) + 1]; + xsprintf(text, UID_FMT "-" UID_FMT, (uid_t) (SYSTEM_UID_MAX + 1), UID_NOBODY - 1); + FOREACH_STRING(xattr, "user.userdb.uid", "user.userdb.gid") + (void) xsetxattr(AT_FDCWD, socket_path, /* at_flags= */ 0, xattr, text); + r = sd_varlink_server_attach_event(m->varlink_server, m->event, SD_EVENT_PRIORITY_NORMAL); if (r < 0) return log_error_errno(r, "Failed to attach varlink connection to event loop: %m");