]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic/user-util: introduce shell_is_placeholder() helper
authorMike Yuan <me@yhndnzj.com>
Mon, 18 Nov 2024 18:24:57 +0000 (19:24 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 28 Nov 2024 14:08:25 +0000 (15:08 +0100)
(cherry picked from commit 579ce77ead476e3d5b9a774ab00ec3ec53933ab2)

src/basic/user-util.c
src/basic/user-util.h

index 6bdf5bf1cdc9a1536b6cde2bc5edf5e11507ca1c..85bd5f20be0c71d6630fd0d39af3e02afeaf7050 100644 (file)
@@ -321,10 +321,9 @@ int get_user_creds(
 
         if (ret_shell)
                 *ret_shell = (FLAGS_SET(flags, USER_CREDS_CLEAN) &&
-                              (isempty(p->pw_shell) ||
+                              (shell_is_placeholder(p->pw_shell) ||
                                !path_is_valid(p->pw_shell) ||
-                               !path_is_absolute(p->pw_shell) ||
-                               is_nologin_shell(p->pw_shell))) ? NULL : p->pw_shell;
+                               !path_is_absolute(p->pw_shell))) ? NULL : p->pw_shell;
 
         if (patch_username)
                 *username = p->pw_name;
index 9d07ef31d22d852dcb93f1d717e2ff09d38aa2ef..d53b60c3567103da9d0ef70d4e759cc172a9399d 100644 (file)
@@ -12,6 +12,8 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#include "string-util.h"
+
 /* Users managed by systemd-homed. See https://systemd.io/UIDS-GIDS for details how this range fits into the rest of the world */
 #define HOME_UID_MIN ((uid_t) 60001)
 #define HOME_UID_MAX ((uid_t) 60513)
@@ -36,6 +38,15 @@ static inline int parse_gid(const char *s, gid_t *ret_gid) {
 char* getlogname_malloc(void);
 char* getusername_malloc(void);
 
+const char* default_root_shell_at(int rfd);
+const char* default_root_shell(const char *root);
+
+bool is_nologin_shell(const char *shell);
+
+static inline bool shell_is_placeholder(const char *shell) {
+        return isempty(shell) || is_nologin_shell(shell);
+}
+
 typedef enum UserCredsFlags {
         USER_CREDS_PREFER_NSS    = 1 << 0,  /* if set, only synthesize user records if database lacks them. Normally we bypass the userdb entirely for the records we can synthesize */
         USER_CREDS_ALLOW_MISSING = 1 << 1,  /* if a numeric UID string is resolved, be OK if there's no record for it */
@@ -133,10 +144,6 @@ int fgetsgent_sane(FILE *stream, struct sgrp **sg);
 int putsgent_sane(const struct sgrp *sg, FILE *stream);
 #endif
 
-bool is_nologin_shell(const char *shell);
-const char* default_root_shell_at(int rfd);
-const char* default_root_shell(const char *root);
-
 int is_this_me(const char *username);
 
 const char* get_home_root(void);