From 8d1ca13c989d54fe4a3654b7feba3e7dba78fad9 Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Fri, 29 Dec 2023 18:11:42 +0100 Subject: [PATCH] login: unify pw_shell script test At first, a blank in pw_shell is sufficient to assume that the user login shell is actually a shell script. If execution fails, the test consists of testing argv[0] for "/bin/sh" which is set in case of shell script. But "/bin/sh" can also be the actual login shell set for the user. If execution fails, the error message erroneously talks about a shell script. Keep a boolean variable around to perform the test exactly once to have a precise error message. Signed-off-by: Tobias Stoeckmann --- login-utils/login.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/login-utils/login.c b/login-utils/login.c index 9e9e029889..552cafbfb1 100644 --- a/login-utils/login.c +++ b/login-utils/login.c @@ -1420,6 +1420,7 @@ int main(int argc, char **argv) .conv = { openpam_ttyconv, NULL } /* OpenPAM conversation function */ #endif }; + bool script; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); @@ -1544,7 +1545,9 @@ int main(int argc, char **argv) } /* if the shell field has a space: treat it like a shell script */ - if (strchr(pwd->pw_shell, ' ')) { + script = strchr(pwd->pw_shell, ' ') != NULL; + + if (script) { char *buff; xasprintf(&buff, "exec %s", pwd->pw_shell); @@ -1569,7 +1572,7 @@ int main(int argc, char **argv) execvp(child_argv[0], child_argv + 1); - if (!strcmp(child_argv[0], "/bin/sh")) + if (script) warn(_("couldn't exec shell script")); else warn(_("no shell")); -- 2.47.2