Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os/user: make Windows user lookup treat well-known groups as valid ac… #56823

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/os/user/lookup_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,19 @@ func getProfilesDirectory() (string, error) {
}
}

// isValidUserAccountType returns true if acctType is a valid type for user accounts.
func isValidUserAccountType(acctType uint32) bool {
// Some built-in system accounts are classified as well-known groups instead of users.
return acctType == syscall.SidTypeUser || acctType == syscall.SidTypeWellKnownGroup
}

// lookupUsernameAndDomain obtains the username and domain for usid.
func lookupUsernameAndDomain(usid *syscall.SID) (username, domain string, e error) {
username, domain, t, e := usid.LookupAccount("")
if e != nil {
return "", "", e
}
if t != syscall.SidTypeUser {
if !isValidUserAccountType(t) {
return "", "", fmt.Errorf("user: should be user account type, not %d", t)
}
return username, domain, nil
Expand Down Expand Up @@ -324,7 +330,7 @@ func lookupUser(username string) (*User, error) {
if e != nil {
return nil, e
}
if t != syscall.SidTypeUser {
if !isValidUserAccountType(t) {
return nil, fmt.Errorf("user: should be user account type, not %d", t)
}
return newUserFromSid(sid)
Expand Down
17 changes: 17 additions & 0 deletions src/os/user/lookup_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package user

import (
"testing"
)

func TestLookupLocalSystem(t *testing.T) {
// The string representation of the SID for `NT AUTHORITY\SYSTEM`
const localSystemSID = "S-1-5-18"
if _, err := LookupId(localSystemSID); err != nil {
t.Fatalf("LookupId(%q): %v", localSystemSID, err)
}
}