summaryrefslogtreecommitdiffstats
path: root/login-utils
diff options
context:
space:
mode:
authorSami Kerola2014-12-15 00:20:01 +0100
committerSami Kerola2015-01-05 23:52:51 +0100
commitf64979233f9093bfa1a628eac163ee025e9ab1a4 (patch)
tree4bbeaf01890b5283f0f98e7aba0bf6fd9bb0f28b /login-utils
parentchsh: set few variables read-only and rename one of them (diff)
downloadkernel-qcow2-util-linux-f64979233f9093bfa1a628eac163ee025e9ab1a4.tar.gz
kernel-qcow2-util-linux-f64979233f9093bfa1a628eac163ee025e9ab1a4.tar.xz
kernel-qcow2-util-linux-f64979233f9093bfa1a628eac163ee025e9ab1a4.zip
chsh: allow user to set shell to /bin/sh if none is set
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>
Diffstat (limited to 'login-utils')
-rw-r--r--login-utils/chsh.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/login-utils/chsh.c b/login-utils/chsh.c
index a31641565..0112fa45d 100644
--- a/login-utils/chsh.c
+++ b/login-utils/chsh.c
@@ -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