Skip to content

Commit

Permalink
adding better error message with reference to /etc/nsswitch.conf when…
Browse files Browse the repository at this point in the history
… looking up a user results in ENOENT (#46556)
  • Loading branch information
eriktate authored Sep 13, 2024
1 parent 571f006 commit 4919fe7
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/srv/usermgmt_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package srv

import (
"bufio"
"errors"
"fmt"
"os"
"os/user"
Expand Down Expand Up @@ -59,7 +60,16 @@ func newHostSudoersBackend(uuid string) (HostSudoersBackend, error) {

// Lookup implements host user information lookup
func (*HostUsersProvisioningBackend) Lookup(username string) (*user.User, error) {
return user.Lookup(username)
usr, err := user.Lookup(username)
if err != nil {
if !errors.Is(err, user.UnknownUserError(username)) && strings.Contains(err.Error(), "no such file or directory") {
return nil, trace.Wrap(err, "looking up user %q, sources configured for passwd in host's /etc/nsswitch.conf may be misconfigured", username)
}

return nil, trace.Wrap(err)
}

return usr, nil
}

// UserGIDs returns the list of group IDs for a user
Expand Down

0 comments on commit 4919fe7

Please sign in to comment.