]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
login-utils, sys-utils: use _PATH_BSHELL consistently
authorAlessandro Ratti <alessandro@0x65c.net>
Sun, 23 Nov 2025 15:26:37 +0000 (16:26 +0100)
committerAlessandro Ratti <alessandro@0x65c.net>
Mon, 1 Dec 2025 17:58:02 +0000 (18:58 +0100)
Remove local DEFAULT_SHELL definitions and hardcoded "/bin/sh" strings
in favor of the standard _PATH_BSHELL macro from <paths.h>. This
provides consistency across the codebase while following libc
conventions.

These tools already perform their own passwd lookups and only need a
fallback value, so they don't require the full ul_default_shell()
resolution logic.

Affected tools:
- su(1): already checks pw_shell validity
- sulogin(8): emergency login with explicit shell handling
- setpriv(1): already has passwd entry for environment setup

Signed-off-by: Alessandro Ratti <alessandro@0x65c.net>
login-utils/su-common.c
login-utils/sulogin.c
sys-utils/setpriv.c

index 4d54eab31b5865e3380bb8f151d3f8084c5e8765..c6232ce7acbd1845ae73d28ba288ec90890fd361 100644 (file)
@@ -105,9 +105,6 @@ UL_DEBUG_DEFINE_MASKNAMES(su) = UL_DEBUG_EMPTY_MASKNAMES;
 
 #define is_pam_failure(_rc)    ((_rc) != PAM_SUCCESS)
 
-/* The shell to run if none is given in the user's passwd entry.  */
-#define DEFAULT_SHELL "/bin/sh"
-
 /* The user to become if none is specified.  */
 #define DEFAULT_USER "root"
 
@@ -1167,7 +1164,7 @@ int su_main(int argc, char **argv, int mode)
        su->old_user = xgetlogin();
 
        if (!su->pwd->pw_shell || !*su->pwd->pw_shell)
-               su->pwd->pw_shell = DEFAULT_SHELL;
+               su->pwd->pw_shell = _PATH_BSHELL;
 
        if (use_supp && !use_gid)
                su->pwd->pw_gid = groups[0];
index eb4609db656f9d27136b2873689418b83c036cdb..c546cc7c163767a78d58c69089e0d9ac1b953b8d 100644 (file)
@@ -34,6 +34,7 @@
 #include <fcntl.h>
 #include <signal.h>
 #include <pwd.h>
+#include <paths.h>
 #include <shadow.h>
 #include <termios.h>
 #include <errno.h>
@@ -892,7 +893,7 @@ static void sushell(struct passwd *pwd, struct console *con)
                if (pwd->pw_shell[0])
                        su_shell = pwd->pw_shell;
                else
-                       su_shell = "/bin/sh";
+                       su_shell = _PATH_BSHELL;
        }
        if ((p = strrchr(su_shell, '/')) == NULL)
                p = su_shell;
@@ -941,9 +942,9 @@ static void sushell(struct passwd *pwd, struct console *con)
        execl(su_shell, shell, (char *)NULL);
        warn(_("failed to execute %s"), su_shell);
 
-       xsetenv("SHELL", "/bin/sh", 1);
-       execl("/bin/sh", profile ? "-sh" : "sh", (char *)NULL);
-       warn(_("failed to execute %s"), "/bin/sh");
+       xsetenv("SHELL", _PATH_BSHELL, 1);
+       execl(_PATH_BSHELL, profile ? "-sh" : "sh", (char *)NULL);
+       warn(_("failed to execute %s"), _PATH_BSHELL);
 }
 
 #ifdef HAVE_LIBSELINUX
index c218be8e5e3c15f1cd4a40ec7980b8312819229d..505d1ee5b4ecce374934fb8ad25875f3593cc043 100644 (file)
@@ -30,6 +30,7 @@
 #include <sys/prctl.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <paths.h>
 
 #include "all-io.h"
 #include "c.h"
@@ -56,9 +57,6 @@
 
 #define SETPRIV_EXIT_PRIVERR 127       /* how we exit when we fail to set privs */
 
-/* The shell to set SHELL env.variable if none is given in the user's passwd entry.  */
-#define DEFAULT_SHELL "/bin/sh"
-
 static gid_t get_group(const char *s, const char *err);
 
 enum cap_type {
@@ -741,7 +739,7 @@ static void do_reset_environ(struct passwd *pw)
        if (pw->pw_shell && *pw->pw_shell)
                xsetenv("SHELL", pw->pw_shell, 1);
        else
-               xsetenv("SHELL", DEFAULT_SHELL, 1);
+               xsetenv("SHELL", _PATH_BSHELL, 1);
 
        xsetenv("HOME", pw->pw_dir, 1);
        xsetenv("USER", pw->pw_name, 1);