blob: 8e347058c006e2115de82a788c808e1401f5c03b [file] [log] [blame]
kesavand2cde6582020-06-22 04:56:23 -04001package mstypes
2
3import (
4 "encoding/binary"
5 "encoding/hex"
6 "fmt"
kesavandc71914f2022-03-25 11:19:03 +05307 "math"
8 "strings"
kesavand2cde6582020-06-22 04:56:23 -04009)
10
11// RPCSID implements https://msdn.microsoft.com/en-us/library/cc230364.aspx
12type 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.
20func (s *RPCSID) String() string {
kesavandc71914f2022-03-25 11:19:03 +053021 var strb strings.Builder
22 strb.WriteString("S-1-")
23
kesavand2cde6582020-06-22 04:56:23 -040024 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)
kesavandc71914f2022-03-25 11:19:03 +053027 if i > math.MaxUint32 {
28 fmt.Fprintf(&strb, "0x%s", hex.EncodeToString(s.IdentifierAuthority[:]))
kesavand2cde6582020-06-22 04:56:23 -040029 } else {
kesavandc71914f2022-03-25 11:19:03 +053030 fmt.Fprintf(&strb, "%d", i)
kesavand2cde6582020-06-22 04:56:23 -040031 }
32 for _, sub := range s.SubAuthority {
kesavandc71914f2022-03-25 11:19:03 +053033 fmt.Fprintf(&strb, "-%d", sub)
kesavand2cde6582020-06-22 04:56:23 -040034 }
kesavandc71914f2022-03-25 11:19:03 +053035 return strb.String()
kesavand2cde6582020-06-22 04:56:23 -040036}