]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
chsh: warn if root sets a shell not listed in /etc/shells
authorMichael Vetter <jubalh@iodoru.org>
Wed, 26 Jul 2023 08:13:53 +0000 (10:13 +0200)
committerSerge Hallyn <serge@hallyn.com>
Thu, 27 Jul 2023 17:35:27 +0000 (12:35 -0500)
Print a warning even for the root user if the provided shell isn't
listed in /etc/shells, but continue to execute the action.
In case of non root user exit.

See https://github.com/shadow-maint/shadow/issues/535

src/chsh.c

index 87aa4cb7468dbff4e910e8e9d26a869c9204d0f5..e069b9fb3707229b8aec0014cc8e828eab37200c 100644 (file)
@@ -574,12 +574,15 @@ int main (int argc, char **argv)
                fprintf (stderr, _("%s: Invalid entry: %s\n"), Prog, loginsh);
                fail_exit (1);
        }
-       if (   !amroot
-           && (   loginsh[0] != '/'
-               || is_restricted_shell (loginsh)
-               || (access (loginsh, X_OK) != 0))) {
-               fprintf (stderr, _("%s: %s is an invalid shell\n"), Prog, loginsh);
-               fail_exit (1);
+       if (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 {
+                       fprintf (stderr, _("%s: %s is an invalid shell\n"), Prog, loginsh);
+                       fail_exit (1);
+               }
        }
 
        /* Even for root, warn if an invalid shell is specified. */