blob: 98a9c5ab8bf2c62db864df06d29fb10c35868b6d [file] [log] [blame]
Scott Bakered4efab2020-01-13 19:12:25 -08001package mstypes
2
3import (
4 "encoding/binary"
5 "encoding/hex"
6 "fmt"
7)
8
9// RPCSID implements https://msdn.microsoft.com/en-us/library/cc230364.aspx
10type RPCSID struct {
11 Revision uint8 // An 8-bit unsigned integer that specifies the revision level of the SID. This value MUST be set to 0x01.
12 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.
13 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.
14 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.
15}
16
17// String returns the string representation of the RPC_SID.
18func (s *RPCSID) String() string {
19 var str string
20 b := append(make([]byte, 2, 2), s.IdentifierAuthority[:]...)
21 // For a strange reason this is read big endian: https://msdn.microsoft.com/en-us/library/dd302645.aspx
22 i := binary.BigEndian.Uint64(b)
23 if i >= 4294967296 {
24 str = fmt.Sprintf("S-1-0x%s", hex.EncodeToString(s.IdentifierAuthority[:]))
25 } else {
26 str = fmt.Sprintf("S-1-%d", i)
27 }
28 for _, sub := range s.SubAuthority {
29 str = fmt.Sprintf("%s-%d", str, sub)
30 }
31 return str
32}