]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/install: fix %u expansion when running under sudo 4419/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 20 Oct 2016 04:27:46 +0000 (00:27 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 20 Oct 2016 13:28:51 +0000 (09:28 -0400)
Test case:
[Install]
DefaultInstance=bond1
WantedBy= foobar-U-%U.device
WantedBy= foobar-u-%u.device

$ sudo systemctl --root=/ enable testing4@.service
(before)
Created symlink /etc/systemd/system/foobar-U-0.device.wants/testing4@bond1.service → /etc/systemd/system/testing4@.service.
Created symlink /etc/systemd/system/foobar-u-zbyszek.device.wants/testing4@bond1.service → /etc/systemd/system/testing4@.service.

(after)
Created symlink /etc/systemd/system/foobar-U-0.device.wants/testing4@bond1.service → /etc/systemd/system/testing4@.service.
Created symlink /etc/systemd/system/foobar-u-root.device.wants/testing4@bond1.service → /etc/systemd/system/testing4@.service.

It doesn't make much sense to use a different user for %U and %u.

src/shared/install-printf.c

index 267762d84fbe97180bb7b6a0f1bbaba548d343e0..cbdf66827f838a604ff03ff3a088b4d857a227b9 100644 (file)
@@ -108,9 +108,13 @@ static int specifier_user_name(char specifier, void *data, void *userdata, char
         /* If we are UID 0 (root), this will not result in NSS,
          * otherwise it might. This is good, as we want to be able to
          * run this in PID 1, where our user ID is 0, but where NSS
-         * lookups are not allowed. */
+         * lookups are not allowed.
 
-        t = getusername_malloc();
+         * We don't user getusername_malloc() here, because we don't want to look
+         * at $USER, to remain consistent with specifer_user_id() below.
+         */
+
+        t = uid_to_name(getuid());
         if (!t)
                 return -ENOMEM;