mirror of
https://github.com/rwinkhart/go-winio.git
synced 2026-09-02 15:17:38 -04:00
Add lookup of account names by SID
This commit adds a new function LookupNameBySid that wraps LookupAccountSidW and works as an inverse of the already existing LookupSidByName. In addition to offering new functionality, this fixes #202. Signed-off-by: Michael Hofmann <michael.hofmann@bitgestalt.com>
This commit is contained in:
+17
-3
@@ -12,10 +12,24 @@ func TestLookupInvalidSid(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLookupInvalidName(t *testing.T) {
|
||||
_, err := LookupNameBySid("notasid")
|
||||
aerr, ok := err.(*AccountLookupError)
|
||||
if !ok || aerr.Err != cERROR_INVALID_SID {
|
||||
t.Fatalf("expected AccountLookupError with ERROR_INVALID_SID got %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLookupValidSid(t *testing.T) {
|
||||
sid, err := LookupSidByName("Everyone")
|
||||
if err != nil || sid != "S-1-1-0" {
|
||||
t.Fatalf("expected S-1-1-0, got %s, %s", sid, err)
|
||||
everyone := "S-1-1-0"
|
||||
name, err := LookupNameBySid(everyone)
|
||||
if err != nil {
|
||||
t.Fatalf("expected a valid account name, got %v", err)
|
||||
}
|
||||
|
||||
sid, err := LookupSidByName(name)
|
||||
if err != nil || sid != everyone {
|
||||
t.Fatalf("expected %s, got %s, %s", everyone, sid, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user