Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
GenericSecurityDescriptor.cs
Go to the documentation of this file.
2
4
5public abstract class GenericSecurityDescriptor
6{
7 internal abstract GenericAcl? GenericSacl { get; }
8
9 internal abstract GenericAcl? GenericDacl { get; }
10
11 private bool IsCraftedAefaDacl
12 {
13 get
14 {
15 if (GenericDacl is DiscretionaryAcl discretionaryAcl)
16 {
17 return discretionaryAcl.EveryOneFullAccessForNullDacl;
18 }
19 return false;
20 }
21 }
22
23 public static byte Revision => 1;
24
25 public abstract ControlFlags ControlFlags { get; }
26
27 public abstract SecurityIdentifier? Owner { get; set; }
28
29 public abstract SecurityIdentifier? Group { get; set; }
30
31 public int BinaryLength
32 {
33 get
34 {
35 int num = 20;
36 if (Owner != null)
37 {
38 num += Owner.BinaryLength;
39 }
40 if (Group != null)
41 {
42 num += Group.BinaryLength;
43 }
44 if ((ControlFlags & ControlFlags.SystemAclPresent) != 0 && GenericSacl != null)
45 {
47 }
48 if ((ControlFlags & ControlFlags.DiscretionaryAclPresent) != 0 && GenericDacl != null && !IsCraftedAefaDacl)
49 {
51 }
52 return num;
53 }
54 }
55
56 private static void MarshalInt(byte[] binaryForm, int offset, int number)
57 {
58 binaryForm[offset] = (byte)number;
59 binaryForm[offset + 1] = (byte)(number >> 8);
60 binaryForm[offset + 2] = (byte)(number >> 16);
61 binaryForm[offset + 3] = (byte)(number >> 24);
62 }
63
64 internal static int UnmarshalInt(byte[] binaryForm, int offset)
65 {
66 return binaryForm[offset] + (binaryForm[offset + 1] << 8) + (binaryForm[offset + 2] << 16) + (binaryForm[offset + 3] << 24);
67 }
68
70 {
71 }
72
73 public static bool IsSddlConversionSupported()
74 {
75 return true;
76 }
77
78 public string GetSddlForm(AccessControlSections includeSections)
79 {
80 byte[] binaryForm = new byte[BinaryLength];
81 GetBinaryForm(binaryForm, 0);
82 SecurityInfos securityInfos = (SecurityInfos)0;
83 if ((includeSections & AccessControlSections.Owner) != 0)
84 {
85 securityInfos |= SecurityInfos.Owner;
86 }
87 if ((includeSections & AccessControlSections.Group) != 0)
88 {
89 securityInfos |= SecurityInfos.Group;
90 }
91 if ((includeSections & AccessControlSections.Audit) != 0)
92 {
93 securityInfos |= SecurityInfos.SystemAcl;
94 }
95 if ((includeSections & AccessControlSections.Access) != 0)
96 {
97 securityInfos |= SecurityInfos.DiscretionaryAcl;
98 }
99 string resultSddl;
100 switch (Win32.ConvertSdToSddl(binaryForm, 1, securityInfos, out resultSddl))
101 {
102 case 87:
103 case 1305:
104 throw new InvalidOperationException();
105 default:
106 throw new InvalidOperationException();
107 case 0:
108 return resultSddl;
109 }
110 }
111
112 public void GetBinaryForm(byte[] binaryForm, int offset)
113 {
114 if (binaryForm == null)
115 {
116 throw new ArgumentNullException("binaryForm");
117 }
118 if (offset < 0)
119 {
121 }
122 if (binaryForm.Length - offset < BinaryLength)
123 {
125 }
126 int num = offset;
127 byte b = (byte)((this is RawSecurityDescriptor rawSecurityDescriptor && (ControlFlags & ControlFlags.RMControlValid) != 0) ? rawSecurityDescriptor.ResourceManagerControl : 0);
128 int num2 = (int)ControlFlags;
130 {
131 num2 &= -5;
132 }
133 binaryForm[offset] = Revision;
134 binaryForm[offset + 1] = b;
135 binaryForm[offset + 2] = (byte)num2;
136 binaryForm[offset + 3] = (byte)(num2 >> 8);
137 int offset2 = offset + 4;
138 int offset3 = offset + 8;
139 int offset4 = offset + 12;
140 int offset5 = offset + 16;
141 offset += 20;
142 if (Owner != null)
143 {
144 MarshalInt(binaryForm, offset2, offset - num);
145 Owner.GetBinaryForm(binaryForm, offset);
147 }
148 else
149 {
150 MarshalInt(binaryForm, offset2, 0);
151 }
152 if (Group != null)
153 {
154 MarshalInt(binaryForm, offset3, offset - num);
155 Group.GetBinaryForm(binaryForm, offset);
157 }
158 else
159 {
160 MarshalInt(binaryForm, offset3, 0);
161 }
162 if ((ControlFlags & ControlFlags.SystemAclPresent) != 0 && GenericSacl != null)
163 {
164 MarshalInt(binaryForm, offset4, offset - num);
165 GenericSacl.GetBinaryForm(binaryForm, offset);
167 }
168 else
169 {
170 MarshalInt(binaryForm, offset4, 0);
171 }
172 if ((ControlFlags & ControlFlags.DiscretionaryAclPresent) != 0 && GenericDacl != null && !IsCraftedAefaDacl)
173 {
174 MarshalInt(binaryForm, offset5, offset - num);
175 GenericDacl.GetBinaryForm(binaryForm, offset);
177 }
178 else
179 {
180 MarshalInt(binaryForm, offset5, 0);
181 }
182 }
183}
static string ArgumentOutOfRange_ArrayTooSmall
Definition SR.cs:74
static string ArgumentOutOfRange_NeedNonNegNum
Definition SR.cs:32
Definition SR.cs:7
void GetBinaryForm(byte[] binaryForm, int offset)
static void MarshalInt(byte[] binaryForm, int offset, int number)
string GetSddlForm(AccessControlSections includeSections)
static int ConvertSdToSddl(byte[] binaryForm, int requestedRevision, SecurityInfos si, out string resultSddl)
Definition Win32.cs:8
void GetBinaryForm(byte[] binaryForm, int offset)