]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
logind: Properly unescape names of lingering users
authorMichal Koutný <mkoutny@suse.com>
Fri, 25 Nov 2022 16:25:36 +0000 (17:25 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 25 Nov 2022 23:27:16 +0000 (08:27 +0900)
Filenames to store user linger requests are created with C-escaping.
When we enumerate the files to acquire ligering users, we use the
filenames verbatim. In the case C-escaping is not an identity map (such
as "DOMAIN\User"), we won't be able to start user instances of
such mangled users.

Unescape filenames when we treat them as usernames again.

Fixes: #25448
src/login/logind.c

index cc153fd6bfd3c0014e4093b3bd7c7bd876957d51..a564f94bfe918c839b9ad98f13378a20dbf9d01b 100644 (file)
@@ -18,6 +18,7 @@
 #include "daemon-util.h"
 #include "device-util.h"
 #include "dirent-util.h"
+#include "escape.h"
 #include "fd-util.h"
 #include "format-util.h"
 #include "fs-util.h"
@@ -299,11 +300,16 @@ static int manager_enumerate_linger_users(Manager *m) {
 
         FOREACH_DIRENT(de, d, return -errno) {
                 int k;
+                _cleanup_free_ char *n = NULL;
 
                 if (!dirent_is_file(de))
                         continue;
-
-                k = manager_add_user_by_name(m, de->d_name, NULL);
+                k = cunescape(de->d_name, 0, &n);
+                if (k < 0) {
+                        r = log_warning_errno(k, "Failed to unescape username '%s', ignoring: %m", de->d_name);
+                        continue;
+                }
+                k = manager_add_user_by_name(m, n, NULL);
                 if (k < 0)
                         r = log_warning_errno(k, "Couldn't add lingering user %s, ignoring: %m", de->d_name);
         }