-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathNtUtils.Security.Sid.pas
More file actions
721 lines (587 loc) · 17.7 KB
/
NtUtils.Security.Sid.pas
File metadata and controls
721 lines (587 loc) · 17.7 KB
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
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
unit NtUtils.Security.Sid;
{
The module adds support for common operations on Security Identifiers.
}
interface
uses
Ntapi.WinNt, Ntapi.ntseapi, Ntapi.WinBase, NtUtils;
{ Construction }
// Build a new SID
function RtlxCreateSid(
out Sid: ISid;
const IdentifierAuthority: TSidIdentifierAuthority;
[opt] const SubAuthoritiesArray: TArray<Cardinal> = nil
): TNtxStatus;
// Build a new SID from an array
function RtlxCreateSidFromArray(
out Sid: ISid;
const Authorities: TArray<Cardinal>
): TNtxStatus;
// Build a new SID without failing
function RtlxMakeSid(
const IdentifierAuthority: TSidIdentifierAuthority;
[opt] const SubAuthoritiesArray: TArray<Cardinal> = nil
): ISid;
// Build a new SID from an array without failing
function RtlxMakeSidFromArray(
const Authorities: TArray<Cardinal>
): ISid;
// Validate the input buffer and capture a copy as a SID
function RtlxCopySid(
[in] Buffer: PSid;
out NewSid: ISid
): TNtxStatus;
// Validate the input buffer and capture a copy as a SID
function RtlxCopySidEx(
[in] Buffer: PSid;
BufferSize: Cardinal;
out NewSid: ISid
): TNtxStatus;
{ Information }
// Retrieve a copy of identifier authority of a SID as UIn64
function RtlxIdentifierAuthoritySid(
const Sid: ISid
): UInt64;
// Retrieve the number of sub-authorities of a SID
function RtlxSubAuthorityCountSid(
const Sid: ISid
): Cardinal;
// Retrieve the specified sub-authority of a SID
function RtlxSubAuthoritySid(
const Sid: ISid;
Index: Integer
): Cardinal;
// Retrieve an array of sub-authorities of a SID
function RtlxSubAuthoritiesSid(
const Sid: ISid
): TArray<Cardinal>;
// Check if two SIDs are equal
function RtlxEqualSids(
const Sid1: ISid;
const Sid2: ISid
): Boolean;
// Retrieve the RID (the last sub-authority) of a SID
function RtlxRidSid(
const Sid: ISid;
Default: Cardinal = 0
): Cardinal;
// Check if one SID is nested under (or equal to) another SID
function RtlxIsChildSid(
const Child: ISid;
const Parent: ISid;
AllowEqual: Boolean = False
): Boolean;
// Construct a child SID (add a sub authority)
function RtlxMakeChildSid(
out ChildSid: ISid;
const ParentSid: ISid;
Rid: Cardinal
): TNtxStatus;
// Construct a parent SID (remove the last sub authority)
function RtlxMakeParentSid(
out ParentSid: ISid;
const ChildSid: ISid
): TNtxStatus;
// Construct a sibling SID (change the last sub authority)
function RtlxMakeSiblingSid(
out SiblingSid: ISid;
const SourceSid: ISid;
Rid: Cardinal
): TNtxStatus;
// Sorting
function RtlxCompareSids(
const SidA: ISid;
const SidB: ISid
): Integer;
{ Custom SID Representation }
type
// A prototype for registering custom recognizers that convert strings to SIDs
[ThreadSafe]
TSidNameRecognizer = function (
const SidString: String;
out Sid: ISid
): Boolean;
// A prototype for registering custom lookup providers
[ThreadSafe]
TSidNameProvider = function (
const Sid: ISid;
out SidType: TSidNameUse;
out SidDomain: String;
out SidUser: String
): Boolean;
// Add a function for recognizing custom names for SIDs
[ThreadSafe]
procedure RtlxRegisterSidNameRecognizer(
const Recognizer: TSidNameRecognizer
);
// Add a function for representing SIDs under custom names
[ThreadSafe]
procedure RtlxRegisterSidNameProvider(
const Provider: TSidNameProvider
);
// Convert a SID to a human readable form using custom (fake) name providers
function RtlxLookupSidInCustomProviders(
const Sid: ISid;
out SidType: TSidNameUse;
out DomainName: String;
out UserName: String
): Boolean;
{ SDDL }
// Convert a SID to its SDDL representation
function RtlxSidToString(
const Sid: ISid;
out SDDL: String
): TNtxStatus;
// Convert a SID to its SDDL representation
function RtlxSidToStringNoError(
const Sid: ISid
): String;
// Convert SDDL string to a SID
function RtlxStringToSid(
const SDDL: String;
out Sid: ISid
): TNtxStatus;
// A converter from SDDL string to a SID for use with array conversion
function RtlxStringToSidConverter(
const SDDL: String;
out Sid: ISid
): Boolean;
{ Well known SIDs }
// Derive a service SID from a service name
function RtlxCreateServiceSid(
const ServiceName: String;
out Sid: ISid
): TNtxStatus;
// Derive a virtual account SID
function RtlxCreateVirtualAccountSid(
const AccountName: String;
BaseSubAuthority: Cardinal;
out Sid: ISid
): TNtxStatus;
// Construct a well-known SID
function SddlxCreateWellKnownSid(
WellKnownSidType: TWellKnownSidType;
out Sid: ISid
): TNtxStatus;
implementation
uses
Ntapi.ntdef, Ntapi.ntrtl, Ntapi.ntstatus, NtUtils.SysUtils, NtUtils.Errors,
NtUtils.Synchronization;
{$BOOLEVAL OFF}
{$IFOPT R+}{$DEFINE R+}{$ENDIF}
{$IFOPT Q+}{$DEFINE Q+}{$ENDIF}
{ Construction }
function RtlxCreateSid;
var
i: Integer;
begin
IMemory(Sid) := Auto.AllocateDynamic(
RtlLengthRequiredSid(Length(SubAuthoritiesArray)));
Result.Location := 'RtlInitializeSid';
Result.Status := RtlInitializeSid(Sid.Data, @IdentifierAuthority,
Length(SubAuthoritiesArray));
// Fill in the sub authorities
if Result.IsSuccess then
for i := 0 to High(SubAuthoritiesArray) do
RtlSubAuthoritySid(Sid.Data, i)^ := SubAuthoritiesArray[i];
end;
function RtlxCreateSidFromArray;
var
i: Integer;
IdentifierAuthority: TSidIdentifierAuthority;
begin
if Length(Authorities) < 1 then
begin
Result.Location := 'RtlxCreateSidFromArray';
Result.Status := STATUS_INVALID_PARAMETER;
Exit;
end;
IMemory(Sid) := Auto.AllocateDynamic(
RtlLengthRequiredSid(Length(Authorities) - 1));
// Extract the identifier authority and initialize the SID
IdentifierAuthority := Authorities[0];
Result.Location := 'RtlInitializeSid';
Result.Status := RtlInitializeSid(Sid.Data, @IdentifierAuthority,
Length(Authorities) - 1);
if not Result.IsSuccess then
Exit;
// Fill in the sub authorities
for i := 1 to High(Authorities) do
RtlSubAuthoritySid(Sid.Data, i - 1)^ := Authorities[i];
end;
function RtlxMakeSid;
var
i: Integer;
begin
IMemory(Result) := Auto.AllocateDynamic(
RtlLengthRequiredSid(Length(SubAuthoritiesArray)));
if not RtlInitializeSid(Result.Data, @IdentifierAuthority,
Length(SubAuthoritiesArray)).IsSuccess then
begin
// Construct manually on failure
Result.Data.Revision := SID_REVISION;
Result.Data.SubAuthorityCount := Length(SubAuthoritiesArray);
Result.Data.IdentifierAuthority := IdentifierAuthority;
end;
// Fill in the sub authorities
for i := 0 to High(SubAuthoritiesArray) do
RtlSubAuthoritySid(Result.Data, i)^ := SubAuthoritiesArray[i];
end;
function RtlxMakeSidFromArray;
var
i: Integer;
IdentifierAuthority: TSidIdentifierAuthority;
begin
if Length(Authorities) < 1 then
Exit(ISid(Auto.AllocateDynamic(RtlLengthRequiredSid(0))));
IMemory(Result) := Auto.AllocateDynamic(
RtlLengthRequiredSid(Length(Authorities) - 1));
IdentifierAuthority := Authorities[0];
if not RtlInitializeSid(Result.Data, @IdentifierAuthority,
Length(Authorities) - 1).IsSuccess then
begin
// Construct manually on failure
Result.Data.Revision := SID_REVISION;
Result.Data.SubAuthorityCount := Length(Authorities) - 1;
Result.Data.IdentifierAuthority := IdentifierAuthority;
end;
// Fill in the sub authorities
for i := 1 to High(Authorities) do
RtlSubAuthoritySid(Result.Data, i - 1)^ := Authorities[i];
end;
function RtlxCopySid;
begin
if not RtlValidSid(Buffer) then
begin
Result.Location := 'RtlxCopySid';
Result.Status := STATUS_INVALID_SID;
Exit;
end;
IMemory(NewSid) := Auto.AllocateDynamic(RtlLengthSid(Buffer));
Result.Location := 'RtlCopySid';
Result.Status := RtlCopySid(RtlLengthSid(Buffer), NewSid.Data, Buffer);
end;
function RtlxCopySidEx;
begin
// Let RtlValidSid do the buffer probing for us; it won't read past the
// header. Then we can check if the number of sub authorities fits.
if (BufferSize < RtlLengthRequiredSid(0)) or not RtlValidSid(Buffer) or
(BufferSize < RtlLengthRequiredSid(Buffer.SubAuthorityCount)) then
begin
Result.Location := 'RtlxCopySidEx';
Result.Status := STATUS_INVALID_SID;
Exit;
end;
IMemory(NewSid) := Auto.AllocateDynamic(RtlLengthSid(Buffer));
Result.Location := 'RtlCopySid';
Result.Status := RtlCopySid(RtlLengthSid(Buffer), NewSid.Data, Buffer);
end;
{ Information }
function RtlxIdentifierAuthoritySid;
begin
Result := RtlIdentifierAuthoritySid(Sid.Data)^;
end;
function RtlxSubAuthorityCountSid;
begin
Result := RtlSubAuthorityCountSid(Sid.Data)^;
end;
function RtlxSubAuthoritySid;
begin
if (Index >= 0) and (Index < RtlSubAuthorityCountSid(Sid.Data)^) then
Result := RtlSubAuthoritySid(Sid.Data, Index)^
else
Result := 0;
end;
function RtlxSubAuthoritiesSid;
var
i: Integer;
begin
SetLength(Result, RtlSubAuthorityCountSid(Sid.Data)^);
for i := 0 to High(Result) do
Result[i] := RtlSubAuthoritySid(Sid.Data, i)^;
end;
function RtlxEqualSids;
begin
Result := RtlEqualSid(Sid1.Data, Sid2.Data);
end;
function RtlxRidSid;
begin
if RtlSubAuthorityCountSid(Sid.Data)^ > 0 then
Result := RtlSubAuthoritySid(Sid.Data,
RtlSubAuthorityCountSid(Sid.Data)^ - 1)^
else
Result := Default;
end;
function RtlxIsChildSid;
var
i: Integer;
begin
Result := False;
// The parent SID cannot be longer than the child SID
if RtlxSubAuthorityCountSid(Parent) > RtlxSubAuthorityCountSid(Child) then
Exit;
// Optionally, disallow equal lengths
if not AllowEqual and (RtlxSubAuthorityCountSid(Parent) =
RtlxSubAuthorityCountSid(Child)) then
Exit;
// The SIDs should share the the identifier authority
if RtlxIdentifierAuthoritySid(Parent) <> RtlxIdentifierAuthoritySid(Child) then
Exit;
// Check if the SIDs share sub-authorities
for i := 0 to Integer(RtlxSubAuthorityCountSid(Parent)) - 1 do
if RtlxSubAuthoritySid(Parent, i) <> RtlxSubAuthoritySid(Child, i) then
Exit;
Result := True;
end;
function RtlxMakeChildSid;
begin
// Add a new sub authority at the end
Result := RtlxCreateSid(ChildSid, RtlIdentifierAuthoritySid(ParentSid.Data)^,
RtlxSubAuthoritiesSid(ParentSid) + [Rid]);
end;
function RtlxMakeParentSid;
var
SubAuthorities: TArray<Cardinal>;
begin
// Retrieve existing sub authorities
SubAuthorities := RtlxSubAuthoritiesSid(ChildSid);
if Length(SubAuthorities) > 0 then
begin
// Drop the last one
Delete(SubAuthorities, High(SubAuthorities), 1);
Result := RtlxCreateSid(ParentSid,
RtlIdentifierAuthoritySid(ChildSid.Data)^, SubAuthorities);
end
else
begin
// No parent SID available
Result.Location := 'RtlxMakeParentSid';
Result.Status := STATUS_INVALID_SID;
end;
end;
function RtlxMakeSiblingSid;
var
SubAuthorities: TArray<Cardinal>;
begin
SubAuthorities := RtlxSubAuthoritiesSid(SourceSid);
if Length(SubAuthorities) > 0 then
begin
// Replace the RID
SubAuthorities[High(SubAuthorities)] := Rid;
Result := RtlxCreateSid(SiblingSid,
RtlIdentifierAuthoritySid(SourceSid.Data)^, SubAuthorities);
end
else
begin
// No RID present
Result.Location := 'RtlxMakeSiblingSid';
Result.Status := STATUS_INVALID_SID;
end;
end;
function RtlxCompareSids;
var
i: Integer;
A, B: PSid;
begin
A := SidA.Data;
B := SidB.Data;
// Compare identifier authorities
if UInt64(RtlIdentifierAuthoritySid(A)^) <
UInt64(RtlIdentifierAuthoritySid(B)^) then
Exit(-1);
if UInt64(RtlIdentifierAuthoritySid(A)^) >
UInt64(RtlIdentifierAuthoritySid(B)^) then
Exit(1);
i := 0;
Result := 0;
// Compare sub authorities
while (Result = 0) and (i < RtlSubAuthorityCountSid(A)^) and
(i < RtlSubAuthorityCountSid(B)^) do
begin
if RtlSubAuthoritySid(A, i)^ < RtlSubAuthoritySid(B, i)^ then
Exit(-1);
if RtlSubAuthoritySid(A, i)^ > RtlSubAuthoritySid(B, i)^ then
Exit(1);
Inc(i);
end;
// The shorter SID goes first
Result := Integer(RtlSubAuthorityCountSid(A)^) - RtlSubAuthorityCountSid(B)^;
end;
{ SID name parsing }
function TryStrToUInt64Ex(S: String; out Value: UInt64): Boolean;
var
E: Integer;
begin
if RtlxPrefixStripString('0x', S) then
Insert('$', S, Low(S));
Val(S, Value, E);
Result := (E = 0);
end;
function RtlxZeroSubAuthorityStringToSid(
const SDDL: String;
out Sid: ISid
): Boolean;
var
S: String;
IdAuthority: UInt64;
begin
// Despite RtlConvertSidToUnicodeString's ability to convert SIDs with
// zero sub authorities to SDDL, ConvertStringSidToSidW cannot convert them
// back. Fix this issue by parsing them manually.
// Expected formats for an SID with 0 sub authorities:
// S-1-(\d+) | S-1-(0x[A-F\d]+)
// where the value fits into a 6-byte (48-bit) buffer
S := SDDL;
Result := RtlxPrefixStripString('S-1-', S) and TryStrToUInt64Ex(S,
IdAuthority) and (IdAuthority < UInt64(1) shl 48) and
RtlxCreateSid(Sid, IdAuthority).IsSuccess;
end;
var
// For string -> SID
CustomSidNameRecognizersLock: TRtlSRWLock;
CustomSidNameRecognizers: TArray<TSidNameRecognizer>;
// For SID -> string
CustomSidNameProvidersLock: TRtlSRWLock;
CustomSidNameProviders: TArray<TSidNameProvider>;
procedure RtlxRegisterSidNameRecognizer;
var
LockReverter: IAutoReleasable;
begin
LockReverter := RtlxAcquireSRWLockExclusive(@CustomSidNameRecognizersLock);
// Recognizers from other modules
SetLength(CustomSidNameRecognizers, Succ(Length(CustomSidNameRecognizers)));
CustomSidNameRecognizers[High(CustomSidNameRecognizers)] := Recognizer;
end;
procedure RtlxRegisterSidNameProvider;
var
LockReverter: IAutoReleasable;
begin
LockReverter := RtlxAcquireSRWLockExclusive(@CustomSidNameProvidersLock);
// Providers from other modules
SetLength(CustomSidNameProviders, Succ(Length(CustomSidNameProviders)));
CustomSidNameProviders[High(CustomSidNameProviders)] := Provider;
end;
function RtlxLookupSidInCustomProviders;
var
Provider: TSidNameProvider;
LockReverter: IAutoReleasable;
begin
LockReverter := RtlxAcquireSRWLockShared(@CustomSidNameProvidersLock);
for Provider in CustomSidNameProviders do
if Provider(Sid, SidType, DomainName, UserName) then
begin
Assert(SidType in VALID_SID_TYPES, 'Invalid SID type for custom provider');
Exit(True);
end;
Result := False;
end;
{ SDDL }
function RtlxSidToString;
var
SddlStr: TNtUnicodeString;
Buffer: array [0 .. SECURITY_MAX_SID_STRING_CHARACTERS - 1] of WideChar;
begin
SddlStr.Length := 0;
SddlStr.MaximumLength := SizeOf(Buffer);
SddlStr.Buffer := Buffer;
Result.Location := 'RtlConvertSidToUnicodeString';
Result.Status := RtlConvertSidToUnicodeString(SddlStr, Sid.Data, False);
if Result.IsSuccess then
SDDL := SddlStr.ToString;
end;
function RtlxSidToStringNoError;
begin
// Since SDDL permits hexadecimals, we can use them to represent some SIDs
// in a more user-friendly way.
case RtlxIdentifierAuthoritySid(SID) of
// Integrity: S-1-16-X
SECURITY_MANDATORY_LABEL_AUTHORITY:
if RtlxSubAuthorityCountSid(SID) = 1 then
Exit('S-1-16-' + RtlxIntToHex(RtlxSubAuthoritySid(SID, 0), 4));
// Trust: S-1-19-X-X
SECURITY_PROCESS_TRUST_AUTHORITY:
if RtlxSubAuthorityCountSid(SID) = 2 then
Exit('S-1-19-' + RtlxIntToHex(RtlxSubAuthoritySid(SID, 0), 3) + '-' +
RtlxIntToHex(RtlxSubAuthoritySid(SID, 1), 4));
end;
if not RtlxSidToString(Sid, Result).IsSuccess then
Result := '(invalid SID)';
end;
function RtlxStringToSid;
var
Buffer: PSid;
BufferDeallocator: IDeferredOperation;
LockReverter: IAutoReleasable;
Recognizer: TSidNameRecognizer;
begin
Result := NtxSuccess;
// Apply the workaround for zero sub authority SID lookup
if RtlxZeroSubAuthorityStringToSid(SDDL, Sid) then
Exit;
LockReverter := RtlxAcquireSRWLockShared(@CustomSidNameRecognizersLock);
// Try other custom recognizers
for Recognizer in CustomSidNameRecognizers do
if Recognizer(SDDL, Sid) then
begin
Assert(Assigned(Sid), 'Custom SID recognizer returned nil.');
Exit;
end;
// Usual SDDL conversion
Result.Location := 'ConvertStringSidToSidW';
Result.Win32Result := ConvertStringSidToSidW(PWideChar(SDDL), Buffer);
if not Result.IsSuccess then
Exit;
BufferDeallocator := DeferLocalFree(Buffer);
Result := RtlxCopySid(Buffer, Sid);
end;
function RtlxStringToSidConverter;
begin
// Use this function with TArrayHelper.Convert<String, ISid>
Result := RtlxStringToSid(SDDL, Sid).IsSuccess;
end;
{ Well-known SIDs }
function RtlxCreateServiceSid;
var
ServiceNameStr: TNtUnicodeString;
SidLength: Cardinal;
begin
Result := RtlxInitUnicodeString(ServiceNameStr, ServiceName);
if not Result.IsSuccess then
Exit;
Result.Location := 'RtlCreateServiceSid';
SidLength := RtlLengthRequiredSid(SECURITY_SERVICE_ID_RID_COUNT);
IMemory(Sid) := Auto.AllocateDynamic(SidLength);
repeat
Result.Status := RtlCreateServiceSid(ServiceNameStr, Sid.Data, SidLength);
until not NtxExpandBufferEx(Result, IMemory(Sid), SidLength, nil);
end;
function RtlxCreateVirtualAccountSid;
var
AccountNameStr: TNtUnicodeString;
SidLength: Cardinal;
begin
Result := RtlxInitUnicodeString(AccountNameStr, AccountName);
if not Result.IsSuccess then
Exit;
Result.Location := 'RtlCreateVirtualAccountSid';
SidLength := RtlLengthRequiredSid(SECURITY_VIRTUALACCOUNT_ID_RID_COUNT);
IMemory(Sid) := Auto.AllocateDynamic(SidLength);
repeat
Result.Status := RtlCreateVirtualAccountSid(AccountNameStr,
BaseSubAuthority, Sid.Data, SidLength);
until not NtxExpandBufferEx(Result, IMemory(Sid), SidLength, nil);
end;
function SddlxCreateWellKnownSid;
var
Buffer: IMemory absolute Sid;
Required: Cardinal;
begin
Result.Location := 'CreateWellKnownSid';
Buffer := Auto.AllocateDynamic(0);
repeat
Required := Buffer.Size;
Result.Win32Result := CreateWellKnownSid(WellKnownSidType, nil, Buffer.Data,
Required);
until not NtxExpandBufferEx(Result, Buffer, Required, nil);
end;
end.