-
Notifications
You must be signed in to change notification settings - Fork 35
/
NtUtils.Tokens.pas
688 lines (568 loc) · 18.3 KB
/
NtUtils.Tokens.pas
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
unit NtUtils.Tokens;
{
The module provides support for various operations with tokens via Native API.
}
interface
uses
Ntapi.WinNt, Ntapi.ntdef, Ntapi.ntseapi, NtUtils, NtUtils.Objects;
type
TFbqnValue = record
Version: UInt64;
Name: String;
constructor Create(
const Version: UInt64;
const Name: String
);
end;
TSecurityAttribute = record
Name: String;
ValueType: TSecurityAttributeType;
Flags: TSecurityAttributeFlags;
ValuesUInt64: TArray<UInt64>;
ValuesString: TArray<String>;
ValuesFqbn: TArray<TFbqnValue>;
ValuesOctet: TArray<IMemory>;
constructor CreateUInt64(
const Name: String;
Flags: TSecurityAttributeFlags;
const Values: TArray<UInt64>;
ValueType: TSecurityAttributeType = SECURITY_ATTRIBUTE_TYPE_UINT64
);
constructor CreateString(
const Name: String;
Flags: TSecurityAttributeFlags;
const Values: TArray<String>
);
constructor CreateFqbn(
const Name: String;
Flags: TSecurityAttributeFlags;
const Values: TArray<TFbqnValue>
);
constructor CreateOctet(
const Name: String;
Flags: TSecurityAttributeFlags;
const Values: TArray<IMemory>;
ValueType: TSecurityAttributeType = SECURITY_ATTRIBUTE_TYPE_OCTET_STRING
);
end;
{ Pseudo-handles }
// Open a token of a process
function NtxOpenProcessToken(
out hxToken: IHandle;
[Access(PROCESS_QUERY_LIMITED_INFORMATION)] const hxProcess: IHandle;
DesiredAccess: TTokenAccessMask;
HandleAttributes: TObjectAttributesFlags = 0
): TNtxStatus;
// Open a token of a process by ID
[RequiredPrivilege(SE_DEBUG_PRIVILEGE, rpForBypassingChecks)]
function NtxOpenProcessTokenById(
out hxToken: IHandle;
[Access(PROCESS_QUERY_LIMITED_INFORMATION)] PID: TProcessId;
DesiredAccess: TTokenAccessMask;
HandleAttributes: TObjectAttributesFlags = 0
): TNtxStatus;
// Open a token of a thread
function NtxOpenThreadToken(
out hxToken: IHandle;
[Access(THREAD_QUERY_LIMITED_INFORMATION)] const hxThread: IHandle;
DesiredAccess: TTokenAccessMask;
HandleAttributes: TObjectAttributesFlags = 0;
InvertOpenLogic: Boolean = False
): TNtxStatus;
// Open a token of a thread by ID
[RequiredPrivilege(SE_DEBUG_PRIVILEGE, rpForBypassingChecks)]
function NtxOpenThreadTokenById(
out hxToken: IHandle;
[Access(THREAD_QUERY_LIMITED_INFORMATION)] TID: TThreadId;
DesiredAccess: TTokenAccessMask;
HandleAttributes: TObjectAttributesFlags = 0;
InvertOpenLogic: Boolean = False
): TNtxStatus;
// Open an effective token of a thread
[RequiredPrivilege(SE_DEBUG_PRIVILEGE, rpForBypassingChecks)]
function NtxOpenEffectiveTokenById(
out hxToken: IHandle;
const ClientId: TClientId;
DesiredAccess: TTokenAccessMask;
HandleAttributes: TObjectAttributesFlags = 0;
InvertOpenLogic: Boolean = False
): TNtxStatus;
// Make sure to convert a pseudo-handles to an actual token handle if necessary
function NtxExpandToken(
[opt] var hxToken: IHandle;
DesiredAccess: TTokenAccessMask
): TNtxStatus;
// Duplicate existing token
function NtxDuplicateToken(
out hxToken: IHandle;
[Access(TOKEN_DUPLICATE)] hxExistingToken: IHandle;
TokenType: TTokenType;
ImpersonationLevel: TSecurityImpersonationLevel = SecurityImpersonation;
[opt] const ObjectAttributes: IObjectAttributes = nil
): TNtxStatus;
// Duplicate an existing token in-place
function NtxDuplicateTokenLocal(
[Access(TOKEN_DUPLICATE)] var hxToken: IHandle;
TokenType: TTokenType;
ImpersonationLevel: TSecurityImpersonationLevel = SecurityImpersonation;
[opt] const ObjectAttributes: IObjectAttributes = nil
): TNtxStatus;
// Filter a token
[RequiredPrivilege(SE_TCB_PRIVILEGE, rpSometimes)]
function NtxFilterToken(
out hxNewToken: IHandle;
[Access(TOKEN_DUPLICATE)] hxToken: IHandle;
Flags: TTokenFilterFlags;
[opt] const SidsToDisable: TArray<ISid> = nil;
[opt] const PrivilegesToDelete: TArray<TPrivilegeId> = nil;
[opt] const SidsToRestrict: TArray<ISid> = nil
): TNtxStatus;
// Filter a token in place
[RequiredPrivilege(SE_TCB_PRIVILEGE, rpSometimes)]
function NtxFilterTokenInline(
var hxToken: IHandle;
Flags: TTokenFilterFlags;
[opt] const SidsToDisable: TArray<ISid> = nil;
[opt] const PrivilegesToDelete: TArray<TPrivilegeId> = nil;
[opt] const SidsToRestrict: TArray<ISid> = nil
): TNtxStatus;
// Create a new token from scratch. Requires SeCreateTokenPrivilege.
[RequiredPrivilege(SE_CREATE_TOKEN_PRIVILEGE, rpAlways)]
function NtxCreateToken(
out hxToken: IHandle;
TokenType: TTokenType;
ImpersonationLevel: TSecurityImpersonationLevel;
const TokenSource: TTokenSource;
const AuthenticationId: TLuid;
const User: TGroup;
const PrimaryGroup: ISid;
[opt] const Groups: TArray<TGroup> = nil;
[opt] const Privileges: TArray<TPrivilege> = nil;
[opt] const Owner: ISid = nil;
[opt] const DefaultDacl: IAcl = nil;
const ExpirationTime: TLargeInteger = INFINITE_FUTURE;
[opt] const ObjectAttributes: IObjectAttributes = nil
): TNtxStatus;
// Create a new token from scratch. Requires SeCreateTokenPrivilege & Win 8+
[RequiredPrivilege(SE_CREATE_TOKEN_PRIVILEGE, rpAlways)]
function NtxCreateTokenEx(
out hxToken: IHandle;
TokenType: TTokenType;
ImpersonationLevel: TSecurityImpersonationLevel;
const TokenSource: TTokenSource;
const AuthenticationId: TLuid;
const User: TGroup;
const PrimaryGroup: ISid;
[opt] const Groups: TArray<TGroup> = nil;
[opt] const Privileges: TArray<TPrivilege> = nil;
[opt] const UserAttributes: TArray<TSecurityAttribute> = nil;
[opt] const DeviceAttributes: TArray<TSecurityAttribute> = nil;
[opt] const DeviceGroups: TArray<TGroup> = nil;
[opt] const Owner: ISid = nil;
[opt] const DefaultDacl: IAcl = nil;
MandatoryPolicy: TTokenMandatoryPolicy = TOKEN_MANDATORY_POLICY_ALL;
const ExpirationTime: TLargeInteger = INFINITE_FUTURE;
[opt] const ObjectAttributes: IObjectAttributes = nil
): TNtxStatus;
// Create an AppContainer token, Win 8+
function NtxCreateLowBoxToken(
out hxToken: IHandle;
[Access(TOKEN_DUPLICATE)] hxExistingToken: IHandle;
const Package: ISid;
[opt] const Capabilities: TArray<TGroup> = nil;
[opt] const Handles: TArray<IHandle> = nil;
[opt] const ObjectAttributes: IObjectAttributes = nil
): TNtxStatus;
{ --------------------------- Other operations ---------------------------- }
// Adjust a single privilege
function NtxAdjustPrivilege(
[Access(TOKEN_ADJUST_PRIVILEGES)] const hxToken: IHandle;
Privilege: TSeWellKnownPrivilege;
NewAttribute: TPrivilegeAttributes;
IgnoreMissing: Boolean = False
): TNtxStatus;
// Adjust multiple privileges
function NtxAdjustPrivileges(
[Access(TOKEN_ADJUST_PRIVILEGES)] hxToken: IHandle;
[opt] const Privileges: TArray<TSeWellKnownPrivilege>;
NewAttribute: TPrivilegeAttributes;
IgnoreMissing: Boolean = False
): TNtxStatus;
// Adjust groups
function NtxAdjustGroups(
[Access(TOKEN_ADJUST_GROUPS)] hxToken: IHandle;
const Sids: TArray<ISid>;
NewAttribute: TGroupAttributes;
ResetToDefault: Boolean
): TNtxStatus;
implementation
uses
Ntapi.ntstatus, Ntapi.ntpsapi, Ntapi.WinError, NtUtils.Tokens.Misc,
NtUtils.Processes, NtUtils.Threads, NtUtils.Ldr, Ntapi.ntpebteb,
DelphiUtils.AutoObjects;
{$BOOLEVAL OFF}
{$IFOPT R+}{$DEFINE R+}{$ENDIF}
{$IFOPT Q+}{$DEFINE Q+}{$ENDIF}
{ Creation }
function NtxOpenProcessToken;
var
hToken: THandle;
begin
Result.Location := 'NtOpenProcessTokenEx';
Result.LastCall.OpensForAccess(DesiredAccess);
Result.LastCall.Expects<TProcessAccessMask>(PROCESS_QUERY_LIMITED_INFORMATION);
Result.Status := NtOpenProcessTokenEx(HandleOrDefault(hxProcess),
DesiredAccess, HandleAttributes, hToken);
if Result.IsSuccess then
hxToken := Auto.CaptureHandle(hToken);
end;
function NtxOpenProcessTokenById;
var
hxProcess: IHandle;
begin
Result := NtxOpenProcess(hxProcess, PID, PROCESS_QUERY_LIMITED_INFORMATION);
if Result.IsSuccess then
Result := NtxOpenProcessToken(hxToken, hxProcess, DesiredAccess,
HandleAttributes);
end;
function NtxOpenThreadToken;
var
hToken: THandle;
begin
Result.Location := 'NtOpenThreadTokenEx';
Result.LastCall.OpensForAccess(DesiredAccess);
Result.LastCall.Expects<TThreadAccessMask>(THREAD_QUERY_LIMITED_INFORMATION);
// By default, when opening other thread's token use our effective (thread)
// security context. When reading a token from the current thread use the
// process' security context.
Result.Status := NtOpenThreadTokenEx(HandleOrDefault(hxThread), DesiredAccess,
(Assigned(hxThread) and (hxThread.Handle = NtCurrentThread)) xor
InvertOpenLogic, HandleAttributes, hToken);
if Result.IsSuccess then
hxToken := Auto.CaptureHandle(hToken);
end;
function NtxOpenThreadTokenById;
var
hxThread: IHandle;
begin
Result := NtxOpenThread(hxThread, TID, THREAD_QUERY_LIMITED_INFORMATION);
if Result.IsSuccess then
Result := NtxOpenThreadToken(hxToken, hxThread, DesiredAccess,
HandleAttributes, InvertOpenLogic);
end;
function NtxOpenEffectiveTokenById;
begin
// When querying effective token, we read thread token first, and then fall
// back to process token if it's not available.
Result := NtxOpenThreadTokenById(hxToken, ClientId.UniqueThread,
DesiredAccess, HandleAttributes, InvertOpenLogic);
if Result.Status = STATUS_NO_TOKEN then
Result := NtxOpenProcessTokenById(hxToken, ClientId.UniqueProcess,
DesiredAccess, HandleAttributes);
end;
function NtxExpandToken;
begin
if not Assigned(hxToken) then
Result := NtxSuccess
else if hxToken.Handle = NtCurrentProcessToken then
Result := NtxOpenProcessToken(hxToken, NtxCurrentProcess, DesiredAccess)
else if hxToken.Handle = NtCurrentThreadToken then
Result := NtxOpenThreadToken(hxToken, NtxCurrentThread, DesiredAccess)
else if hxToken.Handle = NtCurrentEffectiveToken then
Result := NtxOpenEffectiveTokenById(hxToken, NtCurrentTeb.ClientId,
DesiredAccess)
else
Result := NtxSuccess
end;
function NtxDuplicateToken;
var
ObjAttr: PObjectAttributes;
hToken: THandle;
begin
// Manage support for pseudo-handles
Result := NtxExpandToken(hxExistingToken, TOKEN_DUPLICATE);
if not Result.IsSuccess then
Exit;
Result := AttributeBuilder(ObjectAttributes)
.UseImpersonation(ImpersonationLevel).Build(ObjAttr);
if not Result.IsSuccess then
Exit;
Result.Location := 'NtDuplicateToken';
Result.LastCall.Expects<TTokenAccessMask>(TOKEN_DUPLICATE);
Result.Status := NtDuplicateToken(
hxExistingToken.Handle,
AccessMaskOverride(TOKEN_ALL_ACCESS, ObjectAttributes),
ObjAttr,
Assigned(ObjectAttributes) and ObjectAttributes.EffectiveOnly,
TokenType,
hToken
);
if Result.IsSuccess then
hxToken := Auto.CaptureHandle(hToken);
end;
function NtxDuplicateTokenLocal;
var
hxNewToken: IHandle;
begin
Result := NtxDuplicateToken(hxNewToken, hxToken, TokenType,
ImpersonationLevel, ObjectAttributes);
if Result.IsSuccess then
hxToken := hxNewToken;
end;
function NtxFilterToken;
var
hNewToken: THandle;
begin
// Manage pseudo-tokens. While the Duplicate access is the only strictly
// required, we asks for as much as possible since NtFilterToken copies it.
Result := NtxExpandToken(hxToken, TOKEN_DUPLICATE or MAXIMUM_ALLOWED);
if not Result.IsSuccess then
Exit;
Result.Location := 'NtFilterToken';
Result.LastCall.Expects<TTokenAccessMask>(TOKEN_DUPLICATE);
Result.Status := NtFilterToken(
hxToken.Handle,
Flags,
NtxpAllocGroups(SidsToDisable, 0).Data,
NtxpAllocPrivileges(PrivilegesToDelete, 0).Data,
NtxpAllocGroups(SidsToRestrict, 0).Data,
hNewToken
);
if Result.IsSuccess then
hxNewToken := Auto.CaptureHandle(hNewToken);
end;
function NtxFilterTokenInline;
var
hxNewToken: IHandle;
begin
Result := NtxFilterToken(hxNewToken, hxToken, Flags, SidsToDisable,
PrivilegesToDelete, SidsToRestrict);
if Result.IsSuccess then
hxToken := hxNewToken;
end;
function NtxCreateToken;
var
ObjAttr: PObjectAttributes;
hToken: THandle;
TokenUser: TSidAndAttributes;
TokenPrimaryGroup: TTokenSidInformation;
OwnerSid: PSid;
DefaultAcl: PAcl;
begin
Result := AttributeBuilder(ObjectAttributes)
.UseImpersonation(ImpersonationLevel).Build(ObjAttr);
if not Result.IsSuccess then
Exit;
// Prepare the user
TokenUser.Sid := User.Sid.Data;
TokenUser.Attributes := User.Attributes;
// Prepare the rest
OwnerSid := Auto.RefOrNil<PSid>(Owner);
DefaultAcl := Auto.RefOrNil<PAcl>(DefaultDacl);
TokenPrimaryGroup.Sid := PrimaryGroup.Data;
Result.Location := 'NtCreateToken';
Result.LastCall.ExpectedPrivilege := SE_CREATE_TOKEN_PRIVILEGE;
Result.Status := NtCreateToken(
hToken,
AccessMaskOverride(TOKEN_ALL_ACCESS, ObjectAttributes),
ObjAttr,
TokenType,
AuthenticationId,
ExpirationTime,
TokenUser,
NtxpAllocGroups2(Groups).Data,
NtxpAllocPrivileges2(Privileges).Data,
SidInfoRefOrNil(OwnerSid),
TokenPrimaryGroup,
DefaultDaclRefOrNil(DefaultAcl),
TokenSource
);
if Result.IsSuccess then
hxToken := Auto.CaptureHandle(hToken);
end;
function NtxCreateTokenEx;
var
ObjAttr: PObjectAttributes;
hToken: THandle;
TokenUser: TSidAndAttributes;
TokenPrimaryGroup: TTokenSidInformation;
OwnerSid: PSid;
DefaultAcl: PAcl;
UserAttr, DeviceAttr: IMemory<PTokenSecurityAttributes>;
begin
// Check required function
Result := LdrxCheckDelayedImport(delayed_NtCreateTokenEx);
if not Result.IsSuccess then
Exit;
Result := AttributeBuilder(ObjectAttributes)
.UseImpersonation(ImpersonationLevel).Build(ObjAttr);
if not Result.IsSuccess then
Exit;
Result := NtxpAllocSecurityAttributes(UserAttr, UserAttributes);
if not Result.IsSuccess then
Exit;
Result := NtxpAllocSecurityAttributes(DeviceAttr, DeviceAttributes);
if not Result.IsSuccess then
Exit;
// Prepare the user
TokenUser.Sid := User.Sid.Data;
TokenUser.Attributes := User.Attributes;
// Prepare the rest
OwnerSid := Auto.RefOrNil<PSid>(Owner);
DefaultAcl := Auto.RefOrNil<PAcl>(DefaultDacl);
TokenPrimaryGroup.Sid := PrimaryGroup.Data;
Result.Location := 'NtCreateTokenEx';
Result.LastCall.ExpectedPrivilege := SE_CREATE_TOKEN_PRIVILEGE;
Result.Status := NtCreateTokenEx(
hToken,
AccessMaskOverride(TOKEN_ALL_ACCESS, ObjectAttributes),
ObjAttr,
TokenType,
AuthenticationId,
ExpirationTime,
TokenUser,
NtxpAllocGroups2(Groups).Data,
NtxpAllocPrivileges2(Privileges).Data,
UserAttr.Data,
DeviceAttr.Data,
NtxpAllocGroups2(DeviceGroups).Data,
MandatoryPolicy,
SidInfoRefOrNil(OwnerSid),
TokenPrimaryGroup,
DefaultDaclRefOrNil(DefaultAcl),
TokenSource
);
if Result.IsSuccess then
hxToken := Auto.CaptureHandle(hToken);
end;
function NtxCreateLowBoxToken;
var
ObjAttr: PObjectAttributes;
hToken: THandle;
HandleValues: TArray<THandle>;
CapArray: TArray<TSidAndAttributes>;
i: Integer;
begin
Result := LdrxCheckDelayedImport(delayed_NtCreateLowBoxToken);
if not Result.IsSuccess then
Exit;
// Manage pseudo-handles on input
Result := NtxExpandToken(hxExistingToken, TOKEN_DUPLICATE);
if not Result.IsSuccess then
Exit;
SetLength(HandleValues, Length(Handles));
for i := 0 to High(HandleValues) do
HandleValues[i] := Handles[i].Handle;
// Prepare capabilities
SetLength(CapArray, Length(Capabilities));
for i := 0 to High(CapArray) do
begin
CapArray[i].Sid := Capabilities[i].Sid.Data;
CapArray[i].Attributes := Capabilities[i].Attributes;
end;
Result := AttributesRefOrNil(ObjAttr, ObjectAttributes);
if not Result.IsSuccess then
Exit;
Result.Location := 'NtCreateLowBoxToken';
Result.LastCall.Expects<TTokenAccessMask>(TOKEN_DUPLICATE);
Result.Status := NtCreateLowBoxToken(
hToken,
hxExistingToken.Handle,
AccessMaskOverride(TOKEN_ALL_ACCESS, ObjectAttributes),
ObjAttr,
Package.Data,
Length(CapArray),
CapArray,
Length(HandleValues),
HandleValues
);
if Result.IsSuccess then
hxToken := Auto.CaptureHandle(hToken);
end;
{ Other operations }
function NtxAdjustPrivileges;
begin
// Manage working with pseudo-handles
Result := NtxExpandToken(hxToken, TOKEN_ADJUST_PRIVILEGES);
if not Result.IsSuccess then
Exit;
Result.Location := 'NtAdjustPrivilegesToken';
Result.LastCall.Expects<TTokenAccessMask>(TOKEN_ADJUST_PRIVILEGES);
Result.Status := NtAdjustPrivilegesToken(
hxToken.Handle,
False,
NtxpAllocWellKnownPrivileges(Privileges, NewAttribute).Data,
0,
nil,
nil
);
// If we need to fail the function when some privileges are missing,
// STATUS_NOT_ALL_ASSIGNED won't work because it is a successful code.
// Use something else.
if (Result.Status = STATUS_NOT_ALL_ASSIGNED) and not IgnoreMissing then
begin
Result.Location := 'NtxAdjustPrivileges';
if Length(Privileges) = 1 then
Result.Status := STATUS_PRIVILEGE_NOT_HELD
else
Result.Win32Error := ERROR_NOT_ALL_ASSIGNED;
end;
// Forward a single privilege
if Length(Privileges) = 1 then
Result.LastCall.ExpectedPrivilege := Privileges[0];
end;
function NtxAdjustPrivilege;
begin
Result := NtxAdjustPrivileges(hxToken, [Privilege], NewAttribute,
IgnoreMissing);
end;
function NtxAdjustGroups;
var
TokenGroups: IMemory<PTokenGroups>;
begin
// Manage working with pseudo-handles
Result := NtxExpandToken(hxToken, TOKEN_ADJUST_GROUPS);
if not Result.IsSuccess then
Exit;
TokenGroups := NtxpAllocGroups(Sids, NewAttribute);
Result.Location := 'NtAdjustGroupsToken';
Result.LastCall.Expects<TTokenAccessMask>(TOKEN_ADJUST_GROUPS);
Result.Status := NtAdjustGroupsToken(hxToken.Handle, ResetToDefault,
TokenGroups.Data, 0, nil, nil);
end;
{ TFbqnValue }
constructor TFbqnValue.Create;
begin
Self.Version := Version;
Self.Name := Name;
end;
{ TSecurityAttribute }
constructor TSecurityAttribute.CreateFqbn;
begin
Self.Name := Name;
Self.ValueType := SECURITY_ATTRIBUTE_TYPE_FQBN;
Self.Flags := Flags;
Self.ValuesFqbn := Values;
end;
constructor TSecurityAttribute.CreateOctet;
begin
Self.Name := Name;
Self.ValueType := ValueType;
Self.Flags := Flags;
Self.ValuesOctet := Values;
end;
constructor TSecurityAttribute.CreateString;
begin
Self.Name := Name;
Self.ValueType := SECURITY_ATTRIBUTE_TYPE_STRING;
Self.Flags := Flags;
Self.ValuesString := Values;
end;
constructor TSecurityAttribute.CreateUInt64;
begin
Self.Name := Name;
Self.ValueType := ValueType;
Self.Flags := Flags;
Self.ValuesUInt64 := Values;
end;
end.