Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ GetSecurityInfo()

static int System.Security.AccessControl.Win32.GetSecurityInfo ( ResourceType resourceType,
string name,
SafeHandle handle,
AccessControlSections accessControlSections,
out RawSecurityDescriptor resultSd )
inlinestaticpackage

Definition at line 26 of file Win32.cs.

27 {
28 resultSd = null;
29 SecurityInfos securityInfos = (SecurityInfos)0;
30 Privilege privilege = null;
31 if ((accessControlSections & AccessControlSections.Owner) != 0)
32 {
33 securityInfos |= SecurityInfos.Owner;
34 }
35 if ((accessControlSections & AccessControlSections.Group) != 0)
36 {
37 securityInfos |= SecurityInfos.Group;
38 }
39 if ((accessControlSections & AccessControlSections.Access) != 0)
40 {
41 securityInfos |= SecurityInfos.DiscretionaryAcl;
42 }
43 if ((accessControlSections & AccessControlSections.Audit) != 0)
44 {
45 securityInfos |= SecurityInfos.SystemAcl;
46 privilege = new Privilege("SeSecurityPrivilege");
47 }
48 int num;
49 IntPtr securityDescriptor;
50 try
51 {
52 if (privilege != null)
53 {
54 try
55 {
56 privilege.Enable();
57 }
58 catch (PrivilegeNotHeldException)
59 {
60 }
61 }
62 IntPtr sidOwner;
63 IntPtr sidGroup;
64 IntPtr dacl;
65 IntPtr sacl;
66 if (name != null)
67 {
68 num = (int)global::Interop.Advapi32.GetSecurityInfoByName(name, (uint)resourceType, (uint)securityInfos, out sidOwner, out sidGroup, out dacl, out sacl, out securityDescriptor);
69 }
70 else
71 {
72 if (handle == null)
73 {
74 throw new ArgumentException();
75 }
76 if (handle.IsInvalid)
77 {
79 }
80 num = (int)global::Interop.Advapi32.GetSecurityInfoByHandle(handle, (uint)resourceType, (uint)securityInfos, out sidOwner, out sidGroup, out dacl, out sacl, out securityDescriptor);
81 }
82 if (num == 0 && IntPtr.Zero.Equals(securityDescriptor))
83 {
85 }
86 switch (num)
87 {
88 case 1300:
89 case 1314:
90 throw new PrivilegeNotHeldException("SeSecurityPrivilege");
91 case 5:
92 case 1347:
93 throw new UnauthorizedAccessException();
94 case 0:
95 break;
96 default:
97 goto IL_013f;
98 }
99 }
100 catch
101 {
102 privilege?.Revert();
103 throw;
104 }
105 finally
106 {
107 privilege?.Revert();
108 }
109 uint securityDescriptorLength = global::Interop.Advapi32.GetSecurityDescriptorLength(securityDescriptor);
110 byte[] array = new byte[securityDescriptorLength];
111 Marshal.Copy(securityDescriptor, array, 0, (int)securityDescriptorLength);
112 Marshal.FreeHGlobal(securityDescriptor);
113 resultSd = new RawSecurityDescriptor(array, 0);
114 return 0;
115 IL_013f:
116 if (num == 8)
117 {
118 throw new OutOfMemoryException();
119 }
120 return num;
121 }
static void FreeHGlobal(IntPtr hglobal)
Definition Marshal.cs:1680
static void Copy(int[] source, int startIndex, IntPtr destination, int length)
Definition Marshal.cs:800
static string Argument_InvalidSafeHandle
Definition SR.cs:62
static string InvalidOperation_NoSecurityDescriptor
Definition SR.cs:92
Definition SR.cs:7

References System.SR.Argument_InvalidSafeHandle, System.array, System.Runtime.InteropServices.Marshal.Copy(), System.Security.AccessControl.Privilege.Enable(), System.Runtime.InteropServices.Marshal.FreeHGlobal(), System.handle, System.SR.InvalidOperation_NoSecurityDescriptor, System.Security.AccessControl.Privilege.Revert(), and System.IntPtr.Zero.

Referenced by System.Security.AccessControl.NativeObjectSecurity.CreateInternal().