Fix helper to restart user units with older systemd

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2021-11-08 10:27:00 +01:00
parent c0981501ef
commit 5326f0bf63
2 changed files with 73 additions and 1 deletions

67
2da7d0bc92.patch Normal file
View File

@ -0,0 +1,67 @@
From 2da7d0bc92e2423a5c7225c5d24b99d5d52a0bc6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Date: Wed, 7 Jul 2021 18:02:50 +0200
Subject: [PATCH] sd-bus: allow numerical uids in -M user@.host
UIDs don't work well over ssh, but locally or with containers they are OK.
In particular, user@.service uses UIDs as identifiers, and it's nice to be
able to copy&paste that UID for interaction with the user's managers.
---
src/libsystemd/sd-bus/sd-bus.c | 27 ++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
index a32e2f5e2085..6960161c3658 100644
--- a/src/libsystemd/sd-bus/sd-bus.c
+++ b/src/libsystemd/sd-bus/sd-bus.c
@@ -39,6 +39,7 @@
#include "parse-util.h"
#include "path-util.h"
#include "process-util.h"
+#include "stdio-util.h"
#include "string-util.h"
#include "strv.h"
#include "user-util.h"
@@ -1617,7 +1618,7 @@ static int user_and_machine_valid(const char *user_and_machine) {
if (!user)
return -ENOMEM;
- if (!isempty(user) && !valid_user_group_name(user, VALID_USER_RELAX))
+ if (!isempty(user) && !valid_user_group_name(user, VALID_USER_RELAX | VALID_USER_ALLOW_NUMERIC))
return false;
h++;
@@ -1648,17 +1649,25 @@ static int user_and_machine_equivalent(const char *user_and_machine) {
/* Otherwise, if we are root, then we can also allow the ".host" syntax, as that's the user this
* would connect to. */
- if (geteuid() == 0 && STR_IN_SET(user_and_machine, ".host", "root@.host"))
+ uid_t uid = geteuid();
+
+ if (uid == 0 && STR_IN_SET(user_and_machine, ".host", "root@.host", "0@.host"))
return true;
- /* Otherwise, we have to figure our user name, and compare things with that. */
- un = getusername_malloc();
- if (!un)
- return -ENOMEM;
+ /* Otherwise, we have to figure out our user id and name, and compare things with that. */
+ char buf[DECIMAL_STR_MAX(uid_t)];
+ xsprintf(buf, UID_FMT, uid);
+
+ f = startswith(user_and_machine, buf);
+ if (!f) {
+ un = getusername_malloc();
+ if (!un)
+ return -ENOMEM;
- f = startswith(user_and_machine, un);
- if (!f)
- return false;
+ f = startswith(user_and_machine, un);
+ if (!f)
+ return false;
+ }
return STR_IN_SET(f, "@", "@.host");
}

View File

@ -31,7 +31,7 @@ Name: systemd
Url: https://www.freedesktop.org/wiki/Software/systemd
%if %{without inplace}
Version: 249.6
Release: 2%{?dist}
Release: 3%{?dist}
%else
# determine the build information from local checkout
Version: %(tools/meson-vcs-tag.sh . error | sed -r 's/-([0-9])/.^\1/; s/-g/_g/')
@ -98,6 +98,8 @@ Patch0004: 0004-rpm-restart-user-services-at-the-end-of-the-transact.patch
Patch0005: 0005-update-helper-also-add-user-reexec-verb.patch
Patch0006: 0006-update-helper-add-missing-loop-over-user-units.patch
Patch0007: https://github.com/systemd/systemd/commit/2da7d0bc92.patch
# Downstream-only patches (50009999)
# https://bugzilla.redhat.com/show_bug.cgi?id=1738828
Patch0500: use-bfq-scheduler.patch
@ -999,6 +1001,9 @@ fi
%files standalone-sysusers -f .file-list-standalone-sysusers
%changelog
* Mon Nov 8 2021 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - 249.6-3
- Fix helper to restart user units with older systemd (#2020415)
* Thu Nov 4 2021 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - 249.6-2
- Latest bugfix release (networkd, coredumpctl, varlink, udev,
systemctl, systemd itself, better detection of Hyper-V and