From: Alessandro Ratti Date: Sun, 23 Nov 2025 15:26:37 +0000 (+0100) Subject: login-utils, sys-utils: use _PATH_BSHELL consistently X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=54023fdf092ca479e1ccd5e6a7aa69cef68f840a;p=thirdparty%2Futil-linux.git login-utils, sys-utils: use _PATH_BSHELL consistently Remove local DEFAULT_SHELL definitions and hardcoded "/bin/sh" strings in favor of the standard _PATH_BSHELL macro from . 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 --- diff --git a/login-utils/su-common.c b/login-utils/su-common.c index 4d54eab31..c6232ce7a 100644 --- a/login-utils/su-common.c +++ b/login-utils/su-common.c @@ -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]; diff --git a/login-utils/sulogin.c b/login-utils/sulogin.c index eb4609db6..c546cc7c1 100644 --- a/login-utils/sulogin.c +++ b/login-utils/sulogin.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -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 diff --git a/sys-utils/setpriv.c b/sys-utils/setpriv.c index c218be8e5..505d1ee5b 100644 --- a/sys-utils/setpriv.c +++ b/sys-utils/setpriv.c @@ -30,6 +30,7 @@ #include #include #include +#include #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);