Skip to content

chsh should check whether shell is listed in /etc/shells for root #535

@CamberLoid

Description

@CamberLoid

Currently, chsh will check whether the shell is listed in /etc/shells for non-root users but not for root.

shadow/src/chsh.c

Lines 517 to 530 in 1f84142

if ( !amroot
&& ( is_restricted_shell (loginsh)
|| (access (loginsh, X_OK) != 0))) {
fprintf (stderr, _("%s: %s is an invalid shell\n"), Prog, loginsh);
fail_exit (1);
}
/* 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);
}

This may lead to a login failure when, for example, user sets shell to /bin/bash instead of /usr/bin/bash, which the former is not listed in /etc/shells. chsh should warn user that the possible invalid shell is provided.

An expected behavior is to warn the root user that Warning: $SHELL is not present in /etc/shells.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions