From 40bb89b6a4feca88d33e06f92502a504fb1c11cc Mon Sep 17 00:00:00 2001 From: Chris Hofstaedtler Date: Tue, 18 Feb 2025 00:54:30 +0100 Subject: [PATCH] chsh: do not warn about blank shell MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Closes: Reported-by: 積丹尼 Dan Jacobson Signed-off-by: Chris Hofstaedtler Reviewed-by: Alejandro Colomar --- src/chsh.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/chsh.c b/src/chsh.c index 15bfae323..ecd5749ab 100644 --- a/src/chsh.c +++ b/src/chsh.c @@ -555,9 +555,11 @@ int main (int argc, char **argv) fprintf (stderr, _("%s: Invalid entry: %s\n"), Prog, loginsh); fail_exit (1); } - if (loginsh[0] != '/' - || is_restricted_shell (loginsh) - || (access (loginsh, X_OK) != 0)) { + if (!streq(loginsh, "") + && (loginsh[0] != '/' + || is_restricted_shell (loginsh) + || (access (loginsh, X_OK) != 0))) + { if (amroot) { fprintf (stderr, _("%s: Warning: %s is an invalid shell\n"), Prog, loginsh); } else { @@ -567,10 +569,13 @@ int main (int argc, char **argv) } /* Even for root, warn if an invalid shell is specified. */ - if (access (loginsh, F_OK) != 0) { - fprintf (stderr, _("%s: Warning: %s does not exist\n"), Prog, loginsh); - } else if (access (loginsh, X_OK) != 0) { - fprintf (stderr, _("%s: Warning: %s is not executable\n"), Prog, loginsh); + if (!streq(loginsh, "")) { + /* But not if an empty string is given, documented as meaning the default shell */ + if (access (loginsh, F_OK) != 0) { + fprintf (stderr, _("%s: Warning: %s does not exist\n"), Prog, loginsh); + } else if (access (loginsh, X_OK) != 0) { + fprintf (stderr, _("%s: Warning: %s is not executable\n"), Prog, loginsh); + } } update_shell (user, loginsh); -- 2.47.2