]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
login: unify pw_shell script test
authorTobias Stoeckmann <tobias@stoeckmann.org>
Fri, 29 Dec 2023 17:11:42 +0000 (18:11 +0100)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Fri, 29 Dec 2023 17:11:42 +0000 (18:11 +0100)
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 <tobias@stoeckmann.org>
login-utils/login.c

index 9e9e02988909397024c43d67dfa7595cf8cd87dc..552cafbfb1df2998278f12cfc7dcba77275084b7 100644 (file)
@@ -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"));