1
0

group_windows.go 865 B

123456789101112131415161718192021222324252627282930
  1. //go:build windows
  2. package localapi
  3. import (
  4. "fmt"
  5. "strings"
  6. "golang.org/x/sys/windows"
  7. )
  8. // lookupGroupID resolves an account name, local or domain qualified, or a SID written
  9. // out, to the SID as a string, which is how the pipe's security descriptor names it.
  10. // Any account the host can resolve is accepted, as docker accepts any SID for its -G: a
  11. // group is the natural thing to name, but the descriptor does not care.
  12. func lookupGroupID(name string) (string, error) {
  13. if strings.HasPrefix(strings.ToUpper(name), "S-1-") {
  14. sid, err := windows.StringToSid(name)
  15. if err != nil {
  16. return "", fmt.Errorf("%q is not a SID: %w", name, err)
  17. }
  18. return sid.String(), nil
  19. }
  20. sid, _, _, err := windows.LookupSID("", name)
  21. if err != nil {
  22. return "", fmt.Errorf("account %q does not exist on this host: %w", name, err)
  23. }
  24. return sid.String(), nil
  25. }