@ -51,8 +51,10 @@ func LookupByUsername(username string) (*user.User, error) {
type lookupStd func ( string ) ( * user . User , error )
type lookupStd func ( string ) ( * user . User , error )
func lookup ( usernameOrUID string , std lookupStd , wantShell bool ) ( * user . User , string , error ) {
func lookup ( usernameOrUID string , std lookupStd , wantShell bool ) ( * user . User , string , error ) {
// TODO(awly): we should use genet on more platforms, like FreeBSD.
// Skip getent entirely on Non-Unix platforms that won't ever have it.
if runtime . GOOS != "linux" {
// (Using HasPrefix for "wasip1", anticipating that WASI support will
// move beyond "preview 1" some day.)
if runtime . GOOS == "windows" || runtime . GOOS == "js" || strings . HasPrefix ( runtime . GOOS , "wasi" ) {
u , err := std ( usernameOrUID )
u , err := std ( usernameOrUID )
return u , "" , err
return u , "" , err
}
}
@ -129,6 +131,14 @@ func userLookupGetent(usernameOrUID string, std lookupStd) (*user.User, string,
for len ( f ) < 7 {
for len ( f ) < 7 {
f = append ( f , "" )
f = append ( f , "" )
}
}
var mandatoryFields = [ ] int { 0 , 2 , 3 , 5 }
for _ , v := range mandatoryFields {
if f [ v ] == "" {
log . Printf ( "getent for user %q returned invalid output: %q" , usernameOrUID , out )
u , err := std ( usernameOrUID )
return u , "" , err
}
}
return & user . User {
return & user . User {
Username : f [ 0 ] ,
Username : f [ 0 ] ,
Uid : f [ 2 ] ,
Uid : f [ 2 ] ,