This repository has been archived by the owner on Aug 1, 2024. It is now read-only.
forked from rohnedwards/PowerShellAccessControl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPowerShellAccessControlPinvokeSignatures.ps1
693 lines (621 loc) · 29.2 KB
/
PowerShellAccessControlPinvokeSignatures.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
Add-Type @"
using System;
using System.Runtime.InteropServices;
namespace PowerShellAccessControl {
namespace PInvoke {
// There are more than defined here. See http://msdn.microsoft.com/en-us/library/cc230369.aspx
[Flags]
public enum SecurityInformation : uint {
Owner = 0x00000001,
Group = 0x00000002,
Dacl = 0x00000004,
Sacl = 0x00000008,
All = 0x0000000f,
Label = 0x00000010,
Attribute = 0x00000020,
Scope = 0x00000040,
ProtectedDacl = 0x80000000,
ProtectedSacl = 0x40000000,
UnprotectedDacl = 0x20000000,
UnprotectedSacl = 0x10000000
}
public struct InheritArray {
public Int32 GenerationGap;
[MarshalAs(UnmanagedType.LPTStr)] public string AncestorName;
}
public struct GenericMapping {
public Int32 GenericRead;
public Int32 GenericWrite;
public Int32 GenericExecute;
public Int32 GenericAll;
}
public class advapi32 {
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa446645%28v=vs.85%29.aspx
[DllImport("advapi32.dll", EntryPoint = "GetNamedSecurityInfoW", CharSet = CharSet.Unicode)]
public static extern uint GetNamedSecurityInfo(
string ObjectName,
System.Security.AccessControl.ResourceType ObjectType,
SecurityInformation SecurityInfo,
out IntPtr pSidOwner,
out IntPtr pSidGroup,
out IntPtr pDacl,
out IntPtr pSacl,
out IntPtr pSecurityDescriptor
);
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa446654%28v=vs.85%29.aspx
[DllImport("advapi32.dll", SetLastError=true)]
public static extern uint GetSecurityInfo(
IntPtr handle,
System.Security.AccessControl.ResourceType ObjectType,
SecurityInformation SecurityInfo,
out IntPtr pSidOwner,
out IntPtr pSidGroup,
out IntPtr pDacl,
out IntPtr pSacl,
out IntPtr pSecurityDescriptor
);
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa446650%28v=vs.85%29.aspx
[DllImport("advapi32.dll")]
public static extern Int32 GetSecurityDescriptorLength(
IntPtr pSecurityDescriptor
);
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa379579%28v=vs.85%29.aspx
[DllImport("advapi32.dll", EntryPoint = "SetNamedSecurityInfoW", CharSet = CharSet.Unicode)]
public static extern uint SetNamedSecurityInfo(
string ObjectName,
System.Security.AccessControl.ResourceType ObjectType,
SecurityInformation SecurityInfo,
byte[] pSidOwner,
byte[] pSidGroup,
byte[] pDacl,
byte[] pSacl
);
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa379588(v=vs.85).aspx
[DllImport("advapi32.dll")]
public static extern Int32 SetSecurityInfo(
IntPtr handle,
System.Security.AccessControl.ResourceType ObjectType,
SecurityInformation SecurityInfo,
byte[] pSidOwner,
byte[] pSidGroup,
byte[] pDacl,
byte[] pSacl
);
[DllImport("advapi32.dll", EntryPoint = "GetInheritanceSourceW", CharSet = CharSet.Unicode)]
public static extern UInt32 GetInheritanceSource(
[MarshalAs(UnmanagedType.LPTStr)] string ObjectName,
System.Security.AccessControl.ResourceType ObjectType,
SecurityInformation SecurityInfo,
[MarshalAs(UnmanagedType.Bool)]bool Container,
IntPtr ObjectClassGuids,
UInt32 GuidCount,
byte[] Acl,
IntPtr pfnArray,
ref GenericMapping GenericMapping,
IntPtr InheritArray
);
[DllImport("advapi32.dll", EntryPoint = "GetInheritanceSourceW", CharSet = CharSet.Unicode)]
public static extern UInt32 GetInheritanceSource(
[MarshalAs(UnmanagedType.LPTStr)] string ObjectName,
System.Security.AccessControl.ResourceType ObjectType,
SecurityInformation SecurityInfo,
[MarshalAs(UnmanagedType.Bool)]bool Container,
ref Guid[] ObjectClassGuids, // double pointer
UInt32 GuidCount,
byte[] Acl,
IntPtr pfnArray,
ref GenericMapping GenericMapping,
IntPtr InheritArray
);
[DllImport("advapi32.dll")]
public static extern UInt32 FreeInheritedFromArray(
IntPtr InheritArray,
UInt16 AceCnt,
IntPtr pfnArray
);
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa375202(v=vs.85).aspx
[DllImport("advapi32.dll", EntryPoint="AdjustTokenPrivileges", SetLastError=true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool __AdjustTokenPrivileges(
IntPtr TokenHandle,
[MarshalAs(UnmanagedType.Bool)]bool DisableAllPrivileges,
ref TOKEN_PRIVILEGES NewState,
UInt32 BufferLengthInBytes,
ref TOKEN_PRIVILEGES PreviousState,
out UInt32 ReturnLengthInBytes
);
public static Int32 AdjustTokenPrivileges(IntPtr TokenHandle, bool DisableAllPrivileges, ref TOKEN_PRIVILEGES NewState, UInt32 BufferLengthInBytes, ref TOKEN_PRIVILEGES PreviousState, out UInt32 ReturnLengthInBytes) {
if (__AdjustTokenPrivileges(TokenHandle, DisableAllPrivileges, ref NewState, BufferLengthInBytes, ref PreviousState, out ReturnLengthInBytes)) {
return 0;
}
else {
return System.Runtime.InteropServices.Marshal.GetLastWin32Error();
}
}
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa379180(v=vs.85).aspx
[DllImport("advapi32.dll", EntryPoint="LookupPrivilegeValue", SetLastError=true, CharSet=CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool __LookupPrivilegeValue(
string lpSystemName,
string lpName,
out LUID lpLuid
);
public static Int32 LookupPrivilegeValue(string lpSystemName, string lpName, out LUID lpLuid) {
if (__LookupPrivilegeValue(lpSystemName, lpName, out lpLuid)) {
return 0;
}
else {
return System.Runtime.InteropServices.Marshal.GetLastWin32Error();
}
}
[DllImport("advapi32.dll", EntryPoint="OpenProcessToken", SetLastError=true, CharSet=CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool __OpenProcessToken(
IntPtr ProcessHandle,
System.Security.Principal.TokenAccessLevels DesiredAccess,
out IntPtr TokenHandle
);
public static Int32 OpenProcessToken(IntPtr ProcessHandle, System.Security.Principal.TokenAccessLevels DesiredAccess, out IntPtr TokenHandle) {
// Call original function:
if (__OpenProcessToken(ProcessHandle, DesiredAccess, out TokenHandle)) {
return 0;
}
else {
return System.Runtime.InteropServices.Marshal.GetLastWin32Error();
}
}
[Flags]
public enum PrivilegeAttributes : uint {
Disabled = 0x00000000,
EnabledByDefault = 0x00000001,
Enabled = 0x00000002,
Removed = 0x00000004,
UsedForAccess = 0x80000000
}
public struct TOKEN_PRIVILEGES {
public UInt32 PrivilegeCount;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=1)]
public LUID_AND_ATTRIBUTES [] Privileges;
}
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa379263(v=vs.85).aspx
[StructLayout(LayoutKind.Sequential)]
public struct LUID_AND_ATTRIBUTES {
public LUID Luid;
public PrivilegeAttributes Attributes;
}
[StructLayout(LayoutKind.Sequential)]
public struct LUID {
public UInt32 LowPart;
public Int32 HighPart;
}
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa379159(v=vs.85).aspx
[DllImport("advapi32.dll", EntryPoint="LookupAccountName", SetLastError=true)]
static extern bool __LookupAccountName(
string lpSystemName,
string lpAccountName,
[MarshalAs(UnmanagedType.LPArray)] byte[] Sid,
ref UInt32 cbSid,
System.Text.StringBuilder lpReferencedDomainName,
ref UInt32 cchReferencedDomainName,
out SID_NAME_USE peUse
);
public static Int32 LookupAccountName(string lpSystemName, string lpAccountName, byte[] Sid, ref UInt32 cbSid, System.Text.StringBuilder lpReferencedDomainName, ref UInt32 cchReferencedDomainName, out SID_NAME_USE peUse) {
if (__LookupAccountName(lpSystemName, lpAccountName, Sid, ref cbSid, lpReferencedDomainName, ref cchReferencedDomainName, out peUse)) {
return 0;
}
else {
return System.Runtime.InteropServices.Marshal.GetLastWin32Error();
}
}
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa379166(v=vs.85).aspx
[DllImport("advapi32.dll", EntryPoint="LookupAccountSid", SetLastError=true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool __LookupAccountSid(
string lpSystemName,
[MarshalAs(UnmanagedType.LPArray)] byte[] Sid,
System.Text.StringBuilder lpName,
ref UInt32 cchName,
System.Text.StringBuilder lpReferencedDomainName,
ref UInt32 cchReferencedDomainName,
out SID_NAME_USE peUse
);
public static Int32 LookupAccountSid(string lpSystemName, byte[] Sid, System.Text.StringBuilder lpName, ref UInt32 cchName, System.Text.StringBuilder lpReferencedDomainName, ref UInt32 cchReferencedDomainName, out SID_NAME_USE peUse) {
if (__LookupAccountSid(lpSystemName, Sid, lpName, ref cchName, lpReferencedDomainName, ref cchReferencedDomainName, out peUse)) {
return 0;
}
else {
return System.Runtime.InteropServices.Marshal.GetLastWin32Error();
}
}
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa379601(v=vs.85).aspx
public enum SID_NAME_USE {
User = 1,
Group,
Domain,
Alias,
WellKnownGroup,
DeletedAccount,
Invalid,
Unknown,
Computer,
Label
}
}
public class kernel32 {
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa366745%28v=vs.85%29.aspx
[DllImport("kernel32.dll")]
public static extern uint LocalSize(
IntPtr hMem
);
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa366728%28v=vs.85%29.aspx
[DllImport("kernel32.dll")]
public static extern uint LocalFlags(
IntPtr hMem
);
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa366730%28v=vs.85%29.aspx
// SetLastError is true, but I'm not checking it yet...
[DllImport("kernel32.dll", SetLastError=true)]
public static extern IntPtr LocalFree(
IntPtr hMem
);
[DllImport("kernel32.dll", EntryPoint="CloseHandle", SetLastError=true, CharSet=CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool __CloseHandle(
IntPtr hObject
);
public static Int32 CloseHandle(IntPtr hObject) {
if (__CloseHandle(hObject)) {
return 0;
}
else {
return System.Runtime.InteropServices.Marshal.GetLastWin32Error();
}
}
[DllImport("kernel32.dll", EntryPoint="GetFileAttributesW", CharSet = CharSet.Auto, SetLastError = true)]
public static extern UInt32 GetFileAttributes(
string lpFileName
);
}
namespace AuthZEnums {
[Flags]
public enum AuthzResourceManagerFlags : int {
None = 0,
NoAudit = 0x1,
InitializeUnderImpersonation = 0x2,
ValidInitFlags = (NoAudit | InitializeUnderImpersonation)
};
[Flags]
public enum AuthzContextFlags : int {
None = 0,
SkipTokenGroups = 0x2,
RequireS4ULogon = 0x4,
ComputePrivileges = 0x8
};
[Flags]
public enum AuthzAccessCheckFlags : int {
None = 0,
NoDeepCopySD = 0x00000001
};
[Flags]
public enum AuthzInitializeResourceManagerExFlags : int {
None = 0,
NoAudit = 0x1,
InitializeUnderImpersonation = 0x2,
NoCentralAccessPolicies = 0x4
};
[Flags]
public enum AuthzGenerateFlags : int {
None = 0,
SuccessAudit = 0x00000001,
FailureAudit = 0x00000002
};
public enum AuthzContextInformationClass : int {
UserSid = 1,
GroupsSids,
RestrictedSids,
Privileges,
ExpirationTime,
ServerContext,
Identifier,
Source,
All,
AuthenticationId,
SecurityAttributes,
DeviceSids,
UserClaims,
DeviceClaims,
AppContainerSid,
CapabilitySids
};
public enum AuthzSecurityAttributeOperation : int {
None = 0,
ReplaceAll,
Add,
Delete,
Replace
};
public enum AuthzSecurityAttributeValueType : ushort {
Invalid = 0x0,
Int = 0x1,
String = 0x3,
Boolean = 0x6,
};
[Flags]
public enum AuthzSecurityAttributeFlags : uint {
None = 0x0,
NonInheritable = 0x1,
ValueCaseSensitive = 0x2,
};
}
public class authz {
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa376322(v=vs.85).aspx
public struct AUTHZ_ACCESS_REQUEST {
public UInt32 DesiredAccess;
public byte[] PrincipalSelfSid;
// public OBJECT_TYPE_LIST[] ObjectTypeList;
public IntPtr ObjectTypeList;
public UInt32 ObjectTypeListLength;
public IntPtr OptionalArguments;
};
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa379294(v=vs.85).aspx
public struct OBJECT_TYPE_LIST {
public UInt16 Level;
public UInt16 Sbz;
public IntPtr ObjectType;
// public byte[] ObjectType;
};
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa376321(v=vs.85).aspx
public struct AUTHZ_ACCESS_REPLY {
public UInt32 ResultListLength;
public IntPtr GrantedAccessMask;
public IntPtr SaclEvaluationResults;
public IntPtr Error;
};
public struct LUID {
public UInt32 LowPart;
public Int32 HighPart;
}
[StructLayout(LayoutKind.Sequential)]
public struct AUTHZ_SECURITY_ATTRIBUTES_INFORMATION {
public UInt16 Version;
public UInt16 Reserved;
public UInt32 AttributeCount;
public IntPtr pAttributeV1;
}
[StructLayout(LayoutKind.Sequential)]
public struct AUTHZ_SECURITY_ATTRIBUTE_V1 {
[MarshalAs(UnmanagedType.LPWStr)]
public string Name;
public UInt16 ValueType;
public UInt32 Flags;
public UInt32 ValueCount;
public IntPtr Values;
}
[StructLayout(LayoutKind.Sequential)]
public struct AUTHZ_INIT_INFO_CLIENT {
public UInt16 version;
[MarshalAs(UnmanagedType.LPWStr)]
public string szResourceManagerName;
public IntPtr pfnDynamicAccessCheck;
public IntPtr pfnComputeDynamicGroups;
public IntPtr pfnFreeDynamicGroups;
public IntPtr pfnGetCentralAccessPolicy;
public IntPtr pfnFreeCentralAccessPolicy;
}
// http://msdn.microsoft.com/en-us/library/windows/desktop/hh448464(v=vs.85).aspx
[StructLayout(LayoutKind.Sequential)]
public struct AUTHZ_RPC_INIT_INFO_CLIENT {
public UInt16 version;
[MarshalAs(UnmanagedType.LPWStr)]
public string ObjectUuid;
[MarshalAs(UnmanagedType.LPWStr)]
public string ProtSeq;
[MarshalAs(UnmanagedType.LPWStr)]
public string NetworkAddr;
[MarshalAs(UnmanagedType.LPWStr)]
public string Endpoint;
[MarshalAs(UnmanagedType.LPWStr)]
public string Options;
[MarshalAs(UnmanagedType.LPWStr)]
public string ServerSpn;
}
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa375788(v=vs.85).aspx
[DllImport("authz.dll", EntryPoint="AuthzAccessCheck", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool __AuthzAccessCheck(
UInt32 flags,
IntPtr hAuthzClientContext,
ref AUTHZ_ACCESS_REQUEST pRequest,
IntPtr AuditEvent,
byte[] pSecurityDescriptor,
byte[] OptionalSecurityDescriptorArray,
UInt32 OptionalSecurityDescriptorCount,
ref AUTHZ_ACCESS_REPLY pReply,
out IntPtr phAccessCheckResults
);
public static Int32 AuthzAccessCheck(
UInt32 flags,
IntPtr hAuthzClientContext,
ref AUTHZ_ACCESS_REQUEST pRequest,
IntPtr AuditEvent,
byte[] pSecurityDescriptor,
byte[] OptionalSecurityDescriptorArray,
UInt32 OptionalSecurityDescriptorCount,
ref AUTHZ_ACCESS_REPLY pReply,
out IntPtr phAccessCheckResults
) {
if (__AuthzAccessCheck(flags, hAuthzClientContext, ref pRequest, AuditEvent, pSecurityDescriptor, OptionalSecurityDescriptorArray, OptionalSecurityDescriptorCount, ref pReply, out phAccessCheckResults)) {
return 0;
}
else {
return System.Runtime.InteropServices.Marshal.GetLastWin32Error();
}
}
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa376309(v=vs.85).aspx
[DllImport("authz.dll", EntryPoint = "AuthzInitializeContextFromSid", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool __AuthzInitializeContextFromSid(
UInt32 flags,
byte[] UserSid,
IntPtr hAuthzResourceManager,
IntPtr pExpirationTime,
LUID Identifier,
IntPtr DynamicGroupArgs,
out IntPtr pAuthzClientContext
);
public static Int32 AuthzInitializeContextFromSid(
UInt32 flags,
byte[] UserSid,
IntPtr hAuthzResourceManager,
IntPtr pExpirationTime,
LUID Identifier,
IntPtr DynamicGroupArgs,
out IntPtr pAuthzClientContext
) {
if (__AuthzInitializeContextFromSid(flags, UserSid, hAuthzResourceManager, pExpirationTime, Identifier, DynamicGroupArgs, out pAuthzClientContext)) {
return 0;
}
else {
return System.Runtime.InteropServices.Marshal.GetLastWin32Error();
}
}
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa375821(v=vs.85).aspx
[DllImport("authz.dll", EntryPoint = "AuthzFreeContext", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool __AuthzFreeContext(
IntPtr hAuthzClientContext
);
public static Int32 AuthzFreeContext(
IntPtr hAuthzClientContext
) {
if (__AuthzFreeContext(hAuthzClientContext)) {
return 0;
}
else {
return System.Runtime.InteropServices.Marshal.GetLastWin32Error();
}
}
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa376313(v=vs.85).aspx
[DllImport("authz.dll", EntryPoint = "AuthzInitializeResourceManager", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool __AuthzInitializeResourceManager(
UInt32 flags,
IntPtr pfnAccessCheck,
IntPtr pfnComputeDynamicGroups,
IntPtr pfnFreeDynamicGroups,
string szResourceManagerName,
out IntPtr phAuthzResourceManager
);
public static Int32 AuthzInitializeResourceManager(
UInt32 flags,
IntPtr pfnAccessCheck,
IntPtr pfnComputeDynamicGroups,
IntPtr pfnFreeDynamicGroups,
string szResourceManagerName,
out IntPtr phAuthzResourceManager
) {
if (__AuthzInitializeResourceManager(flags, pfnAccessCheck, pfnComputeDynamicGroups, pfnFreeDynamicGroups, szResourceManagerName, out phAuthzResourceManager)) {
return 0;
}
else {
return System.Runtime.InteropServices.Marshal.GetLastWin32Error();
}
}
[DllImport("authz.dll", EntryPoint = "AuthzInitializeResourceManagerEx", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool __AuthzInitializeResourceManagerEx(
Int32 Flags,
ref AUTHZ_INIT_INFO_CLIENT pAuthzInitInfo,
out IntPtr phAuthzResourceManager
);
public static Int32 AuthzInitializeResourceManagerEx(
Int32 Flags,
ref AUTHZ_INIT_INFO_CLIENT pAuthzInitInfo,
out IntPtr phAuthzResourceManager
) {
if (__AuthzInitializeResourceManagerEx(Flags, ref pAuthzInitInfo, out phAuthzResourceManager)) {
return 0;
}
else {
return System.Runtime.InteropServices.Marshal.GetLastWin32Error();
}
}
[DllImport("authz.dll", EntryPoint = "AuthzInitializeRemoteResourceManager", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool __AuthzInitializeRemoteResourceManager(
ref AUTHZ_RPC_INIT_INFO_CLIENT pRpcInitInfo,
out IntPtr phAuthzResourceManager
);
public static Int32 AuthzInitializeRemoteResourceManager(
ref AUTHZ_RPC_INIT_INFO_CLIENT pRpcInitInfo,
out IntPtr phAuthzResourceManager
) {
if (__AuthzInitializeRemoteResourceManager(ref pRpcInitInfo, out phAuthzResourceManager)) {
return 0;
}
else {
return System.Runtime.InteropServices.Marshal.GetLastWin32Error();
}
}
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa376097(v=vs.85).aspx
[DllImport("authz.dll", EntryPoint = "AuthzFreeResourceManager", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool __AuthzFreeResourceManager(
IntPtr hAuthzResourceManager
);
public static Int32 AuthzFreeResourceManager(
IntPtr hAuthzResourceManager
) {
if (__AuthzFreeResourceManager(hAuthzResourceManager)) {
return 0;
}
else {
return System.Runtime.InteropServices.Marshal.GetLastWin32Error();
}
}
[DllImport("authz.dll", EntryPoint = "AuthzModifyClaims", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool __AuthzModifyClaims(
IntPtr hAuthzClientContext,
PowerShellAccessControl.PInvoke.AuthZEnums.AuthzContextInformationClass ClaimClass,
PowerShellAccessControl.PInvoke.AuthZEnums.AuthzSecurityAttributeOperation[] pClaimOperation,
ref AUTHZ_SECURITY_ATTRIBUTES_INFORMATION pClaims
);
public static Int32 AuthzModifyClaims(
IntPtr hAuthzClientContext,
PowerShellAccessControl.PInvoke.AuthZEnums.AuthzContextInformationClass ClaimClass,
PowerShellAccessControl.PInvoke.AuthZEnums.AuthzSecurityAttributeOperation[] pClaimOperation,
ref AUTHZ_SECURITY_ATTRIBUTES_INFORMATION pClaims
) {
if (__AuthzModifyClaims(hAuthzClientContext, ClaimClass, pClaimOperation, ref pClaims)) {
return 0;
}
else {
return System.Runtime.InteropServices.Marshal.GetLastWin32Error();
}
}
// [DllImport("authz.dll", EntryPoint = "AuthzModifySids", SetLastError = true)]
// [return: MarshalAs(UnmanagedType.Bool)]
// static extern bool __AuthzModifySids(
// IntPtr hAuthzClientContext,
// PowerShellAccessControl.PInvoke.AuthZEnums.AuthzContextInformationClass SidClass,
// PowerShellAccessControl.PInvoke.AuthZEnums.AuthzSecurityAttributeOperation[] pSidOperations,
// ref TOKEN_GROUPS pSids
// );
// public static Int32 AuthzModifySids(
// IntPtr hAuthzClientContext,
// PowerShellAccessControl.PInvoke.AuthZEnums.AuthzContextInformationClass SidClass,
// PowerShellAccessControl.PInvoke.AuthZEnums.AuthzSecurityAttributeOperation[] pSidOperations,
// ref AUTHZ_SECURITY_ATTRIBUTES_INFORMATION pSids
// ) {
// if (__AuthzModifyClaims(hAuthzClientContext, SidClass, pSidOperations, ref pSids)) {
// return 0;
// }
// else {
// return System.Runtime.InteropServices.Marshal.GetLastWin32Error();
// }
// }
}
}
}
"@