Skip to content

Commit

Permalink
Fix missing shell error checking logic (#40591)
Browse files Browse the repository at this point in the history
  • Loading branch information
espadolini authored Apr 16, 2024
1 parent bd23f30 commit 89cdeff
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func GetLoginShell(username string) (string, error) {

shellcmd, err = getLoginShell(username)
if err != nil {
if !trace.IsNotFound(err) {
if trace.IsNotFound(err) {
logrus.Warnf("No shell specified for %v, using default %v.", username, DefaultShell)
return DefaultShell, nil
}
Expand Down
5 changes: 2 additions & 3 deletions lib/shell/shell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ func TestGetShell(t *testing.T) {
require.NoError(t, err)
require.True(t, shell == "/bin/bash" || shell == "/bin/sh")

shell, err = GetLoginShell("non-existent-user")
require.NoError(t, err)
require.Equal(t, DefaultShell, shell)
_, err = GetLoginShell("non-existent-user")
require.ErrorContains(t, err, "unknown user")

shell, err = GetLoginShell("nobody")
require.NoError(t, err)
Expand Down
3 changes: 1 addition & 2 deletions lib/srv/reexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -871,8 +871,7 @@ func buildCommand(c *ExecCommand, localUser *user.User, tty *os.File, pty *os.Fi
// Get the login shell for the user (or fallback to the default).
shellPath, err := shell.GetLoginShell(c.Login)
if err != nil {
log.Debugf("Failed to get login shell for %v: %v. Using default: %v.",
c.Login, err, shell.DefaultShell)
log.Debugf("Failed to get login shell for %v: %v.", c.Login, err)
}
if c.IsTestStub {
shellPath = "/bin/sh"
Expand Down

0 comments on commit 89cdeff

Please sign in to comment.