]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
chsh: allow user to set shell to /bin/sh if none is set
authorSami Kerola <kerolasa@iki.fi>
Sun, 14 Dec 2014 23:20:01 +0000 (23:20 +0000)
committerSami Kerola <kerolasa@iki.fi>
Mon, 5 Jan 2015 22:52:51 +0000 (22:52 +0000)
Earlier setting a /bin/sh was impossible for users that had nothing set
as shell, as that was seen as no change.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
login-utils/chsh.c

index a31641565fd42a64e1f2648d666b1ae9e958b511..0112fa45d17d81e695854f7bcd34d941f7021e73 100644 (file)
@@ -252,6 +252,7 @@ static int check_shell(const char *shell)
 int main(int argc, char **argv)
 {
        char *oldshell;
+       int nullshell = 0;
        const uid_t uid = getuid();
        struct sinfo info = { 0 };
        struct passwd *pw;
@@ -302,8 +303,10 @@ int main(int argc, char **argv)
 #endif
 
        oldshell = pw->pw_shell;
-       if (oldshell == NULL || *oldshell == '\0')
+       if (oldshell == NULL || *oldshell == '\0') {
                oldshell = _PATH_BSHELL;        /* default */
+               nullshell = 1;
+       }
 
        /* reality check */
 #ifdef HAVE_LIBUSER
@@ -339,7 +342,7 @@ int main(int argc, char **argv)
        if (check_shell(info.shell) < 0)
                return EXIT_FAILURE;
 
-       if (strcmp(oldshell, info.shell) == 0)
+       if (!nullshell && strcmp(oldshell, info.shell) == 0)
                errx(EXIT_SUCCESS, _("Shell not changed."));
 
 #ifdef HAVE_LIBUSER