khenaidoo | 2672188 | 2021-08-11 17:42:52 -0400 | [diff] [blame] | 1 | package mstypes |
| 2 | |
| 3 | import ( |
| 4 | "encoding/binary" |
| 5 | "encoding/hex" |
| 6 | "fmt" |
| 7 | "math" |
| 8 | "strings" |
| 9 | ) |
| 10 | |
| 11 | // RPCSID implements https://msdn.microsoft.com/en-us/library/cc230364.aspx |
| 12 | type RPCSID struct { |
| 13 | Revision uint8 // An 8-bit unsigned integer that specifies the revision level of the SID. This value MUST be set to 0x01. |
| 14 | SubAuthorityCount uint8 // An 8-bit unsigned integer that specifies the number of elements in the SubAuthority array. The maximum number of elements allowed is 15. |
| 15 | IdentifierAuthority [6]byte // An RPC_SID_IDENTIFIER_AUTHORITY structure that indicates the authority under which the SID was created. It describes the entity that created the SID. The Identifier Authority value {0,0,0,0,0,5} denotes SIDs created by the NT SID authority. |
| 16 | SubAuthority []uint32 `ndr:"conformant"` // A variable length array of unsigned 32-bit integers that uniquely identifies a principal relative to the IdentifierAuthority. Its length is determined by SubAuthorityCount. |
| 17 | } |
| 18 | |
| 19 | // String returns the string representation of the RPC_SID. |
| 20 | func (s *RPCSID) String() string { |
| 21 | var strb strings.Builder |
| 22 | strb.WriteString("S-1-") |
| 23 | |
| 24 | b := append(make([]byte, 2, 2), s.IdentifierAuthority[:]...) |
| 25 | // For a strange reason this is read big endian: https://msdn.microsoft.com/en-us/library/dd302645.aspx |
| 26 | i := binary.BigEndian.Uint64(b) |
| 27 | if i > math.MaxUint32 { |
| 28 | fmt.Fprintf(&strb, "0x%s", hex.EncodeToString(s.IdentifierAuthority[:])) |
| 29 | } else { |
| 30 | fmt.Fprintf(&strb, "%d", i) |
| 31 | } |
| 32 | for _, sub := range s.SubAuthority { |
| 33 | fmt.Fprintf(&strb, "-%d", sub) |
| 34 | } |
| 35 | return strb.String() |
| 36 | } |