-
-
Notifications
You must be signed in to change notification settings - Fork 141
/
Copy pathmormot.core.os.security.pas
5374 lines (4969 loc) · 179 KB
/
mormot.core.os.security.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
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
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/// Framework Core Definitions of Operating System Security
// - this unit is a part of the Open Source Synopse mORMot framework 2,
// licensed under a MPL/GPL/LGPL three license - see LICENSE.md
unit mormot.core.os.security;
{
*****************************************************************************
Cross-Platform Operating System Security Definitions
- Security IDentifier (SID) Definitions
- Security Descriptor Self-Relative Binary Structures
- Access Control List (DACL/SACL) Definitions
- Conditional ACE Expressions SDDL and Binary Support
- Active Directory Definitions
- Security Descriptor Definition Language (SDDL)
- TSecurityDescriptor Wrapper Object
- Windows API Specific Security Types and Functions
Even if most of those security definitions comes from the Windows/AD world,
our framework (re)implemented them in a cross-platform way.
Most definitions below refers to the official Windows Open Specifications
document, named [MS-DTYP] in comments below.
This low-level unit only refers to mormot.core.base and mormot.core.os.
*****************************************************************************
MS-DTYP: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-dtyp
TODO: resources attributes - see [MS-DTYP] 2.4.10.1
}
interface
{$I ..\mormot.defines.inc}
uses
{$ifdef OSWINDOWS}
Windows, // for Windows API Specific Security Types and Functions below
{$endif OSWINDOWS}
sysutils,
classes,
mormot.core.base,
mormot.core.os;
{ ****************** Security IDentifier (SID) Definitions }
type
/// exception class raised by this unit
EOSSecurity = class(ExceptionWithProps);
/// custom binary buffer type used as convenient Windows SID storage
// - mormot.crypt.secure will recognize this type and serialize its standard
// text as a JSON string
RawSid = type RawByteString;
PRawSid = ^RawSid;
/// a dynamic array of binary SID storage buffers
RawSidDynArray = array of RawSid;
/// Security IDentifier (SID) Authority, encoded as 48-bit binary
// - see [MS-DTYP] 2.4.1 SID_IDENTIFIER_AUTHORITY
TSidAuth = array[0..5] of byte;
PSidAuth = ^TSidAuth;
/// Security IDentifier (SID) binary format, as retrieved e.g. by Windows API
// - this definition is not detailed on oldest Delphi, and not available on
// POSIX, whereas it makes sense to also have it, e.g. for server process
// - its maximum used length is 1032 bytes
// - see [MS-DTYP] 2.4.2 SID
TSid = packed record
Revision: byte;
SubAuthorityCount: byte;
IdentifierAuthority: TSidAuth;
SubAuthority: array[byte] of cardinal;
end;
PSid = ^TSid;
PSids = array of PSid;
const
// some internal constants used for proper inlining (as required by Delphi)
SID_MINLEN = SizeOf(TSidAuth) + 2; // = 8
SID_RIDLEN = SID_MINLEN + 5 * SizeOf(cardinal); // sid.SubAuthority[4] = RID
SID_DOMAINLEN = SID_RIDLEN - SizeOf(cardinal); // exclude RID
SID_REV32 = ord('S') + ord('-') shl 8 + ord('1') shl 16 + ord('-') shl 24;
SID_DOM_MASKSID = $00000401; // Revision = 1 and SubAuthorityCount = 4
SID_DOM_MASKRID = $00000501; // Revision = 1 and SubAuthorityCount = 5
SID_DOM_MASKAUT = $05000000; // IdentifierAuthority = S-1-5-xxx
/// a wrapper around MemCmp() on two Security IDentifier binary buffers
// - will first compare by length, then by content
function SidCompare(a, b: PSid): integer;
/// compute the actual binary length of a Security IDentifier buffer, in bytes
function SidLength(sid: PSid): PtrInt;
{$ifdef HASINLINE} inline; {$endif}
/// allocate a RawSid instance from a PSid raw handler
procedure ToRawSid(sid: PSid; out result: RawSid);
/// check if a RawSid binary buffer has the expected length of a valid SID
function IsValidRawSid(const sid: RawSid): boolean;
/// search within SID dynamic array for a given SID
function HasSid(const sids: PSids; sid: PSid): boolean;
/// search within SID dynamic array for a given dynamic array of SID buffers
function HasAnySid(const sids: PSids; const sid: RawSidDynArray): boolean;
/// append a SID buffer pointer to a dynamic array of SID buffers
procedure AddRawSid(var sids: RawSidDynArray; sid: PSid);
/// append a SID as text, following the standard representation
procedure SidAppendShort(sid: PSid; var s: ShortString);
/// convert a Security IDentifier as text, following the standard representation
function SidToText(sid: PSid): RawUtf8; overload;
{$ifdef HASINLINE}inline;{$endif}
/// convert a Security IDentifier as text, following the standard representation
// - this function is able to convert into itself, i.e. allows sid=pointer(text)
procedure SidToText(sid: PSid; var text: RawUtf8); overload;
/// convert several Security IDentifier as text dynamic array
function SidsToText(sids: PSids): TRawUtf8DynArray;
/// convert a Security IDentifier as text, following the standard representation
function RawSidToText(const sid: RawSid): RawUtf8;
/// parse a Security IDentifier text, following the standard representation
// - won't support hexadecimal 48-bit IdentifierAuthority, i.e. S-1-0x######-..
// - will parse the input text buffer in-place, and return the next position
function TextToSid(var P: PUtf8Char; out sid: TSid): boolean;
/// parse a Security IDentifier text, following the standard representation
function TextToRawSid(const text: RawUtf8): RawSid; overload;
{$ifdef HASINLINE} inline; {$endif}
/// parse a Security IDentifier text, following the standard representation
function TextToRawSid(const text: RawUtf8; out sid: RawSid): boolean; overload;
/// parse several Security IDentifier text, following the standard representation
function TextToRawSidArray(const text: array of RawUtf8; out sid: RawSidDynArray): boolean;
/// quickly check if a SID is in 'S-1-5-21-xx-xx-xx-RID' domain form
function SidIsDomain(s: PSid): boolean;
{$ifdef HASINLINE} inline; {$endif}
/// decode a domain SID text into a generic binary RID value
// - returns true if Domain is '', or is in its 'S-1-5-21-xx-xx-xx' domain form
// - will also accepts any 'S-1-5-21-xx-xx-xx-yyy' form, e.g. the current user SID
// - if a domain SID, Dom binary buffer will contain a S-1-5-21-xx-xx-xx-0 value,
// ready to be used with KnownRidSid(), SidSameDomain(), SddlAppendSid(),
// SddlNextSid() or TSecurityDescriptor.AppendAsText functions
function TryDomainTextToSid(const Domain: RawUtf8; out Dom: RawSid): boolean;
/// quickly check if two binary SID buffers domain do overlap
// - sid should be a RID in S-1-5-21-xx-xx-xx-RID layout
// - dom should be a domain SID in S-1-5-21-xx-xx-xx[-RID] layout, typically
// from TryDomainTextToSid() output
function SidSameDomain(sid, dom: PSid): boolean;
{$ifdef HASINLINE} inline; {$endif}
/// check if a RID is part of OldDomain, then change it into NewDomain
// - Sid should be in S-1-5-21-xx-xx-xx-RID layout
// - OldDomain/NewDomain should be in S-1-5-21-xx-xx-xx[-RID] layout
// - returns 0 if SID was not modified, or 1 if its domain part has been adjusted
function SidReplaceDomain(OldDomain, NewDomain: PSid; maxRid: cardinal;
var Sid: RawSid): integer;
/// replace a any occurence of OldSid[] in Sid value by NewSid[]
// - length(OldSid) should equal length(NewSid)
function SidReplaceAny(const OldSid, NewSid: RawSidDynArray;
var Sid: RawSid): integer; overload;
/// replace a any occurence of OldSid[] in Sid value by NewSid[]
// - each length(OldSid[]) should equal length(NewSid[]) and also equal SidLen
function SidReplaceAny(const OldSid, NewSid: RawSidDynArray;
var Sid: TSid; SidLen: PtrInt): integer; overload;
type
/// define a list of well-known Security IDentifier (SID) groups
// - for instance, wksBuiltinAdministrators is set for local administrators
// - warning: does not exactly match winnt.h WELL_KNOWN_SID_TYPE enumeration
// - see [MS-DTYP] 2.4.2.4 Well-Known SID Structures
TWellKnownSid = (
wksNull, // S-1-0-0
wksWorld, // S-1-1-0 WD
wksLocal, // S-1-2-0
wksConsoleLogon, // S-1-2-1
wksCreatorOwner, // S-1-3-0 CO
wksCreatorGroup, // S-1-3-1 CG
wksCreatorOwnerServer, // S-1-3-2
wksCreatorGroupServer, // S-1-3-3
wksCreatorOwnerRights, // S-1-3-4 OW
wksIntegrityUntrusted, // S-1-16-0
wksIntegrityLow, // S-1-16-4096 LW
wksIntegrityMedium, // S-1-16-8192 ME
wksIntegrityMediumPlus, // S-1-16-8448 MP
wksIntegrityHigh, // S-1-16-12288 HI
wksIntegritySystem, // S-1-16-16384 SI
wksIntegrityProtectedProcess, // S-1-16-20480
wksIntegritySecureProcess, // S-1-16-28672
wksAuthenticationAuthorityAsserted, // S-1-18-1
wksAuthenticationServiceAsserted, // S-1-18-2 SS
wksAuthenticationFreshKeyAuth, // S-1-18-3
wksAuthenticationKeyTrust, // S-1-18-4
wksAuthenticationKeyPropertyMfa, // S-1-18-5
wksAuthenticationKeyPropertyAttestation, // S-1-18-6
wksNtAuthority, // S-1-5
wksDialup, // S-1-5-1
wksNetwork, // S-1-5-2 NU
wksBatch, // S-1-5-3
wksInteractive, // S-1-5-4 IU
wksService, // S-1-5-6 SU
wksAnonymous, // S-1-5-7 AN
wksProxy, // S-1-5-8
wksEnterpriseControllers, // S-1-5-9 ED
wksSelf, // S-1-5-10 PS
wksAuthenticatedUser, // S-1-5-11 AU
wksRestrictedCode, // S-1-5-12 RC
wksTerminalServer, // S-1-5-13
wksRemoteLogonId, // S-1-5-14
wksThisOrganisation, // S-1-5-15
wksIisUser, // S-1-5-17
wksLocalSystem, // S-1-5-18 SY
wksLocalService, // S-1-5-19 LS
wksNetworkService, // S-1-5-20 NS
wksLocalAccount, // S-1-5-113
wksLocalAccountAndAdministrator, // S-1-5-114
wksBuiltinDomain, // S-1-5-32
wksBuiltinAdministrators, // S-1-5-32-544 BA
wksBuiltinUsers, // S-1-5-32-545 BU
wksBuiltinGuests, // S-1-5-32-546 BG
wksBuiltinPowerUsers, // S-1-5-32-547 PU
wksBuiltinAccountOperators, // S-1-5-32-548 AO
wksBuiltinSystemOperators, // S-1-5-32-549 SO
wksBuiltinPrintOperators, // S-1-5-32-550 PO
wksBuiltinBackupOperators, // S-1-5-32-551 BO
wksBuiltinReplicator, // S-1-5-32-552 RE
wksBuiltinRasServers, // S-1-5-32-553
wksBuiltinPreWindows2000CompatibleAccess, // S-1-5-32-554 RU
wksBuiltinRemoteDesktopUsers, // S-1-5-32-555 RD
wksBuiltinNetworkConfigurationOperators, // S-1-5-32-556 NO
wksBuiltinIncomingForestTrustBuilders, // S-1-5-32-557
wksBuiltinPerfMonitoringUsers, // S-1-5-32-558 MU
wksBuiltinPerfLoggingUsers, // S-1-5-32-559 LU
wksBuiltinAuthorizationAccess, // S-1-5-32-560
wksBuiltinTerminalServerLicenseServers, // S-1-5-32-561
wksBuiltinDcomUsers, // S-1-5-32-562
wksBuiltinIUsers, // S-1-5-32-568 IS
wksBuiltinCryptoOperators, // S-1-5-32-569 CY
wksBuiltinUnknown, // S-1-5-32-570
wksBuiltinCacheablePrincipalsGroups, // S-1-5-32-571
wksBuiltinNonCacheablePrincipalsGroups, // S-1-5-32-572
wksBuiltinEventLogReadersGroup, // S-1-5-32-573 ER
wksBuiltinCertSvcDComAccessGroup, // S-1-5-32-574 CD
wksBuiltinRdsRemoteAccessServers, // S-1-5-32-575 RA
wksBuiltinRdsEndpointServers, // S-1-5-32-576 ES
wksBuiltinRdsManagementServers, // S-1-5-32-577 MS
wksBuiltinHyperVAdmins, // S-1-5-32-578 HA
wksBuiltinAccessControlAssistanceOperators, // S-1-5-32-579 AA
wksBuiltinRemoteManagementUsers, // S-1-5-32-580 RM
wksBuiltinDefaultSystemManagedGroup, // S-1-5-32-581
wksBuiltinStorageReplicaAdmins, // S-1-5-32-582
wksBuiltinDeviceOwners, // S-1-5-32-583
wksBuiltinWriteRestrictedCode, // S-1-5-33 WR
wksBuiltinUserModeDriver, // S-1-5-84-0-0-0-0-0 UD
wksCapabilityInternetClient, // S-1-15-3-1
wksCapabilityInternetClientServer, // S-1-15-3-2
wksCapabilityPrivateNetworkClientServer, // S-1-15-3-3
wksCapabilityPicturesLibrary, // S-1-15-3-4
wksCapabilityVideosLibrary, // S-1-15-3-5
wksCapabilityMusicLibrary, // S-1-15-3-6
wksCapabilityDocumentsLibrary, // S-1-15-3-7
wksCapabilityEnterpriseAuthentication, // S-1-15-3-8
wksCapabilitySharedUserCertificates, // S-1-15-3-9
wksCapabilityRemovableStorage, // S-1-15-3-10
wksCapabilityAppointments, // S-1-15-3-11
wksCapabilityContacts, // S-1-15-3-12
wksBuiltinAnyPackage, // S-1-15-2-1 AC
wksBuiltinAnyRestrictedPackage, // S-1-15-2-2
wksNtlmAuthentication, // S-1-5-64-10
wksSChannelAuthentication, // S-1-5-64-14
wksDigestAuthentication); // S-1-5-64-21
/// define a set of well-known SID
TWellKnownSids = set of TWellKnownSid;
/// define a list of well-known domain relative sub-authority RID values
// - see [MS-DTYP] 2.4.2.4 Well-Known SID Structures
TWellKnownRid = (
wkrGroupReadOnly, // DOMAIN_GROUP_RID_ENTERPRISE_READONLY_DOMAIN_CONTROLLERS RO
wkrUserAdmin, // DOMAIN_USER_RID_ADMIN LA
wkrUserGuest, // DOMAIN_USER_RID_GUEST LG
wkrServiceKrbtgt, // DOMAIN_USER_RID_KRBTGT
wkrGroupAdmins, // DOMAIN_GROUP_RID_ADMINS DA
wkrGroupUsers, // DOMAIN_GROUP_RID_USERS DU
wkrGroupGuests, // DOMAIN_GROUP_RID_GUESTS DG
wkrGroupComputers, // DOMAIN_GROUP_RID_COMPUTERS DC
wkrGroupControllers, // DOMAIN_GROUP_RID_CONTROLLERS DD
wkrGroupCertAdmins, // DOMAIN_GROUP_RID_CERT_ADMINS CA
wkrGroupSchemaAdmins, // DOMAIN_GROUP_RID_SCHEMA_ADMINS SA
wkrGroupEntrepriseAdmins, // DOMAIN_GROUP_RID_ENTERPRISE_ADMINS EA
wkrGroupPolicyAdmins, // DOMAIN_GROUP_RID_POLICY_ADMINS PA
wkrGroupReadOnlyControllers, // DOMAIN_GROUP_RID_READONLY_CONTROLLERS
wkrGroupCloneableControllers, // DOMAIN_GROUP_RID_CLONEABLE_CONTROLLERS CN
wkrGroupProtectedUsers, // DOMAIN_GROUP_RID_PROTECTED_USERS AP
wkrGroupKeyAdmins, // DOMAIN_GROUP_RID_KEY_ADMINS KA
wkrGroupEntrepriseKeyAdmins, // DOMAIN_GROUP_RID_ENTERPRISE_KEY_ADMINS EK
wrkGroupRasServers, // DOMAIN_ALIAS_RID_RAS_SERVERS RS
wrkAllowedRodcPasswordReplication, // ALLOWED_RODC_PASSWORD_REPLICATION_GROUP
wrkDeniedRodcPasswordReplication, // DENIED_RODC_PASSWORD_REPLICATION_GROUP
wrkUserModeHwOperator); // DOMAIN_ALIAS_RID_USER_MODE_HARDWARE_OPERATORS HO
/// define a set of well-known RID
TWellKnownRids = set of TWellKnownRid;
/// returns a Security IDentifier of a well-known SID as binary
// - is using an internal cache for the returned RawSid instances
function KnownRawSid(wks: TWellKnownSid): RawSid; overload;
{$ifdef HASINLINE} inline; {$endif}
/// returns a Security IDentifier of a well-known SID as binary
procedure KnownRawSid(wks: TWellKnownSid; var sid: RawSid); overload;
/// returns a Security IDentifier of a well-known SID as static binary buffer
procedure KnownRawSid(wks: TWellKnownSid; var sid: TSid); overload;
/// returns a Security IDentifier of a well-known SID as standard text
// - e.g. wksBuiltinAdministrators as 'S-1-5-32-544'
function KnownSidToText(wks: TWellKnownSid): PShortString; overload;
/// recognize most well-known SID from a Security IDentifier binary buffer
// - returns wksNull if the supplied buffer was not recognized
function SidToKnown(sid: PSid): TWellKnownSid; overload;
/// recognize most well-known SID from a Security IDentifier standard text
// - returns wksNull if the supplied text was not recognized
function SidToKnown(const text: RawUtf8): TWellKnownSid; overload;
/// recognize some well-known SIDs from the supplied SID dynamic array
function SidToKnownGroups(const sids: PSids): TWellKnownSids;
/// returns a Security IDentifier of a well-known RID as binary
// - the Domain is expected to be in its 'S-1-5-21-xxxxxx-xxxxxxx-xxxxxx' layout
function KnownRawSid(wkr: TWellKnownRid; const Domain: RawUtf8): RawSid; overload;
/// returns a Security IDentifier of a well-known RID as standard text
// - the Domain is expected to be in its 'S-1-5-21-xxxxxx-xxxxxxx-xxxxxx' layout
// - e.g. wkrUserAdmin as 'S-1-5-21-xxxxxx-xxxxxxx-xxxxxx-500'
function KnownSidToText(wkr: TWellKnownRid; const Domain: RawUtf8): RawUtf8; overload;
/// compute a binary SID from a decoded binary Domain and a well-known RID
// - more efficient than KnownRawSid() overload and KnownSidToText()
procedure KnownRidSid(wkr: TWellKnownRid; dom: PSid; var result: RawSid); overload;
/// compute a static binary SID from a decoded binary Domain and a well-known RID
procedure KnownRidSid(wkr: TWellKnownRid; dom: PSid; var result: TSid); overload;
const
/// the S-1-5-21-xx-xx-xx-RID trailer value of each known RID
// - see [MS-DTYP] 2.4.2.4 Well-Known SID Structures
WKR_RID: array[TWellKnownRid] of word = (
498, // $1f2 RO wkrGroupReadOnly
500, // $1f4 LA wkrUserAdmin
501, // $1f5 LG wkrUserGuest
502, // $1f6 wkrServiceKrbtgt
512, // $200 DA wkrGroupAdmins
513, // $201 DU wkrGroupUsers
514, // $202 DG wkrGroupGuests
515, // $203 DC wkrGroupComputers
516, // $204 DD wkrGroupControllers
517, // $205 CA wkrGroupCertAdmins
518, // $206 SA wkrGroupSchemaAdmins
519, // $207 EA wkrGroupEntrepriseAdmins
520, // $208 PA wkrGroupPolicyAdmins
521, // $209 wkrGroupReadOnlyControllers
522, // $20a CN wkrGroupCloneableControllers
525, // $20d AP wkrGroupProtectedUsers
526, // $20e KA wkrGroupKeyAdmins
527, // $20f EK wkrGroupEntrepriseKeyAdmins
553, // $229 RS wrkGroupRasServers
571, // $23b wrkAllowedRodcPasswordReplication
572, // $23c wrkDeniedRodcPasswordReplication
584); // $248 HO wrkUserModeHwOperator
/// the maximum known RID value of S-1-5-21-xx-xx-xx-RID patterns
WKR_RID_MAX = 584;
function ToText(w: TWellKnownSid): PShortString; overload;
function ToText(w: TWellKnownRid): PShortString; overload;
{ ****************** Security Descriptor Self-Relative Binary Structures }
type
/// flags to specify control access to TSecurityDescriptor
// - see e.g. [MS-DTYP] 2.4.6 SECURITY_DESCRIPTOR
TSecControl = (
scOwnerDefaulted,
scGroupDefaulted,
scDaclPresent,
scDaclDefaulted,
scSaclPresent,
scSaclDefaulted,
scDaclTrusted,
scServerSecurity,
scDaclAutoInheritReq,
scSaclAutoInheritReq,
scDaclAutoInherit,
scSaclAutoInherit,
scDaclProtected,
scSaclProtected,
scRmControlValid,
scSelfRelative);
/// TSecurityDescriptor.Controls to specify control access
TSecControls = set of TSecControl;
// map the _SECURITY_DESCRIPTOR struct in self-relative state
// - see [MS-DTYP] 2.4.6 SECURITY_DESCRIPTOR
TRawSD = packed record
Revision: byte;
Sbz1: byte; // always DWORD-aligned
Control: TSecControls;
Owner: cardinal; // not pointers, but self-relative position
Group: cardinal;
Sacl: cardinal;
Dacl: cardinal;
end;
PRawSD = ^TRawSD;
// map the Access Control List header
// - see [MS-DTYP] 2.4.5.1 ACL--RPC Representation
TRawAcl = packed record
AclRevision: byte;
Sbz1: byte;
AclSize: word; // including TRawAcl header + all ACEs
AceCount: word;
Sbz2: word; // always DWORD-aligned
end;
PRawAcl = ^TRawAcl;
/// high-level supported ACE flags in TSecAce.Flags
// - see [MS-DTYP] 2.4.4.1 ACE_HEADER
// - safObjectInherit: non-container child objects inherit the ACE as an
// effective ACE
// - safContainerInherit: child objects that are containers, such as directories,
// inherit the ACE as an effective ACE
// - safNoPropagateInherit: If the ACE is inherited by a child object, the
// system clears the safObjectInherit and safContainerInherit flags in the
// inherited ACE. This prevents the ACE from being inherited by subsequent
// generations of objects.
// - safInheritOnly indicates an inherit-only ACE, which does not control
// access to the object to which it is attached. If this flag is not set,
// the ACE is an effective ACE that controls access to the object to which
// it is attached
// - safInherited is used to indicate that the ACE was inherited
// - safSuccessfulAccess is used with system-audit ACEs in a SACL to generate
// audit messages for successful access attempts
// - safFailedAccess is used with system-audit ACEs in a system access
// control list (SACL) to generate audit messages for failed access attempts
TSecAceFlag = (
safObjectInherit, // OI
safContainerInherit, // CI
safNoPropagateInherit, // NP
safInheritOnly, // IO
safInherited, // ID
saf5,
safSuccessfulAccess, // SA
safFailedAccess); // FA
/// high-level supported ACE flags in TSecAce.Flags
TSecAceFlags = set of TSecAceFlag;
/// standard and generic access rights in TSecAce.Mask
// - see [MS-DTYP] 2.4.3 ACCESS_MASK
// - well defined set of files or keys flags are defined as TSecAccessRight
// - other sets of rights will be identified by those individual values
TSecAccess = (
samCreateChild, // CC
samDeleteChild, // DC
samListChildren, // LC
samSelfWrite, // SW
samReadProp, // RP
samWriteProp, // WP
samDeleteTree, // DT
samListObject, // LO
samControlAccess, // CR
sam9,
sam10,
sam11,
sam12,
sam13,
sam14,
sam15,
samDelete, // SD
samReadControl, // RC
samWriteDac, // WD
samWriteOwner, // WO
samSynchronize,
sam21,
sam22,
sam23,
samAccessSystemSecurity,
samMaximumAllowed,
sam26,
sam27,
samGenericAll, // GA
samGenericExecute, // GX
samGenericWrite, // GW
samGenericRead); // GR
/// 32-bit standard and generic access rights in TRawAce/TSecAce.Mask
// - see [MS-DTYP] 2.4.3 ACCESS_MASK
// - TSecAccessRight defines specific sets for files or registry keys
TSecAccessMask = set of TSecAccess;
PSecAccessMask = ^TSecAccessMask;
// map one Access Control Entry
// - see [MS-DTYP] 2.4.4.1 ACE_HEADER
TRawAce = packed record
// ACE header
AceType: byte; // typically equals ord(TSecAceType) - 1
AceFlags: TSecAceFlags;
AceSize: word; // include ACE header + whole body
// ACE body
Mask: TSecAccessMask;
case integer of
0: (CommonSid: cardinal);
1: (ObjectFlags: cardinal;
ObjectStart: cardinal);
end;
PRawAce = ^TRawAce;
/// TRawAce/TSecAce.Mask constant values with their own SDDL identifier
// - i.e. TSecAccessMask sets which are commonly used togethers
// - sarFile* for files, sarKey* for registry keys, and also services
// - note that sarKeyExecute and sarKeyRead have the actual same 32-bit value
TSecAccessRight = (
sarFileAll, // FA
sarFileRead, // FR
sarFileWrite, // FW
sarFileExecute, // FX
sarKeyAll, // KA
sarKeyRead, // KR
sarKeyWrite, // KW
sarKeyExecute); // KE
const
/// 'artx' prefix to identify a conditional ACE binary buffer
// - see [MS-DTYP] 2.4.4.17.4 Conditional ACE Binary Formats
ACE_CONDITION_SIGNATURE = $78747261;
ACE_OBJECT_TYPE_PRESENT = 1;
ACE_INHERITED_OBJECT_TYPE_PRESENT = 2;
{ cross-platform definitions of TSecAccessRight 32-bit Windows access rights }
SAR_FILE_ALL_ACCESS = $001f01ff;
SAR_FILE_GENERIC_READ = $00120089;
SAR_FILE_GENERIC_WRITE = $00120116;
SAR_FILE_GENERIC_EXECUTE = $001200a0;
SAR_KEY_ALL_ACCESS = $000f003f;
SAR_KEY_READ = $00020019;
SAR_KEY_WRITE = $00020006;
SAR_KEY_EXECUTE = $00020019; // note that KEY_EXECUTE = KEY_READ
/// match the TSecAce.Mask constant values with their own SDDL identifier
SAR_MASK: array[TSecAccessRight] of cardinal = (
SAR_FILE_ALL_ACCESS, // sarFileAll
SAR_FILE_GENERIC_READ, // sarFileRead
SAR_FILE_GENERIC_WRITE, // sarFileWrite
SAR_FILE_GENERIC_EXECUTE, // sarFileExecute
SAR_KEY_ALL_ACCESS, // sarKeyAll
SAR_KEY_READ, // sarKeyRead
SAR_KEY_WRITE, // sarKeyWrite
SAR_KEY_EXECUTE); // sarKeyExecute = sarKeyRead
/// specifies the user rights allowed by satObject ACE
// - see e.g. [MS-DTYP] 2.4.4.3 ACCESS_ALLOWED_OBJECT_ACE
samObject = [
samCreateChild,
samDeleteChild,
samSelfWrite,
samReadProp,
samWriteProp,
samControlAccess];
/// alias for satMandatoryLabel so that a principal with a lower mandatory
// level than the object cannot write to the object
samMandatoryLabelNoWriteUp = samCreateChild;
/// alias for satMandatoryLabel so that a principal with a lower mandatory
// level than the object cannot read the object
samMandatoryLabelNoReadUp = samDeleteChild;
/// alias for satMandatoryLabel so that a principal with a lower mandatory
// level than the object cannot execute the object
samMandatoryLabelNoExecuteUp = samListChildren;
{ ****************** Access Control List (DACL/SACL) Definitions }
type
/// high-level supported ACE kinds in TSecAce.AceType
// - see [MS-DTYP] 2.4.4.1 ACE_HEADER
// - satAccessAllowed/satAccessDenied allows or denies access to an object
// for a specific trustee identified by a security identifier (SID)
// - satAudit causes an audit message to be logged when a specified trustee
// (identified by a SID) attempts to gain access to an object
// - satObjectAccessAllowed/satObjectAccessDenied define an ACE that controls
// allowed/denied access to an object, a property set, or property: in addition
// to the access rights and SID, it includes object GUIDs and inheritance flags
// - satCallbackAccessAllowed/satCallbackAccessDenied allows or denies access
// to an object for a specific trustee identified by a SID, with optional
// application data, typically a conditional ACE expression
// - satMandatoryLabel defines an ACE for the SACL that specifies the
// mandatory access level and policy for a securable object - masks values
// are samMandatoryLabelNoWriteUp, samMandatoryLabelNoReadUp and
// samMandatoryLabelNoExecuteUp
// - satResourceAttribute defines an ACE for the specification of a resource
// attribute associated with an object, i.e. is is used in conditional ACEs in
// specifying access or audit policy for the resource - ending with a [MS-DTYP]
// 2.4.10.1 CLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1 resource attribute structure
// - satScoppedPolicy defines an ACE for the purpose of applying a central
// access policy to the resource: Mask is 0, and ends with a [MS-GPCAP] 3.2.1.1
// CentralAccessPoliciesList structure
TSecAceType = (
satUnknown,
satAccessAllowed, // A 0 0x00 ACCESS_ALLOWED_ACE_TYPE
satAccessDenied, // D 1 0x01 ACCESS_DENIED_ACE_TYPE
satAudit, // AU 2 0x02 SYSTEM_AUDIT_ACE_TYPE
satAlarm, // AL 3 0x03 SYSTEM_ALARM_ACE_TYPE
satCompoundAllowed, // 4 0x04 ACCESS_ALLOWED_COMPOUND_ACE_TYPE
satObjectAccessAllowed, // OA 5 0x05 ACCESS_ALLOWED_OBJECT_ACE_TYPE
satObjectAccessDenied, // OD 6 0x06 ACCESS_DENIED_OBJECT_ACE_TYPE
satObjectAudit, // OU 7 0x07 SYSTEM_AUDIT_OBJECT_ACE_TYPE
satObjectAlarm, // OL 8 0x08 SYSTEM_ALARM_OBJECT_ACE_TYPE
satCallbackAccessAllowed, // XA 9 0x09 ACCESS_ALLOWED_CALLBACK_ACE_TYPE
satCallbackAccessDenied, // XD 10 0x0a ACCESS_DENIED_CALLBACK_ACE_TYPE
satCallbackObjectAccessAllowed, // ZA 11 0x0b ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE
satCallbackObjectAccessDenied, // 12 0x0c ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE
satCallbackAudit, // XU 13 0x0d SYSTEM_AUDIT_CALLBACK_ACE_TYPE
satCallbackAlarm, // 14 0x0e SYSTEM_ALARM_CALLBACK_ACE_TYPE
satCallbackObjectAudit, // 15 0x0f SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE
satCallbackObjectAlarm, // 16 0x10 SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE
satMandatoryLabel, // ML 17 0x11 SYSTEM_MANDATORY_LABEL_ACE_TYPE
satResourceAttribute, // RA 18 0x12 SYSTEM_RESOURCE_ATTRIBUTE_ACE_TYPE
satScoppedPolicy, // SP 19 0x13 SYSTEM_SCOPED_POLICY_ID_ACE_TYPE
satProcessTrustLabel, // TL 20 0x14 SYSTEM_PROCESS_TRUST_LABEL_ACE_TYPE
satAccessFilter); // FL 21 0x15 SYSTEM_ACCESS_FILTER_ACE_TYPE
TSecAceTypes = set of TSecAceType;
/// define one TSecurityDescriptor Dacl[] or Sacl[] access control list (ACL)
TSecAceScope = (
sasDacl,
sasSacl);
/// result of TSecurityDescriptor.FromText and other SDDL parsing methods
TAceTextParse = (
atpSuccess,
atpInvalidOwner,
atpInvalidGroup,
atpInvalidType,
atpInvalidFlags,
atpInvalidMask,
atpInvalidUuid,
atpNoExpression,
atpTooManyExpressions,
atpTooManyParenthesis,
atpMissingParenthesis,
atpMissingFinal,
atpTooBigExpression,
atpMissingExpression,
atpUnexpectedToken,
atpInvalidExpression,
atpInvalidComposite,
atpInvalidUnicode,
atpInvalidSid,
atpInvalidOctet,
atpInvalidContent);
{$A-} // both TSecAce and TSecurityDescriptor should be packed for JSON serialization
/// define one discretionary/system access entry (ACE)
{$ifdef USERECORDWITHMETHODS}
TSecAce = record
{$else}
TSecAce = object
{$endif USERECORDWITHMETHODS}
public
/// high-level supported ACE kinds
AceType: TSecAceType;
// the ACE flags
Flags: TSecAceFlags;
/// the raw ACE identifier - typically = ord(AceType) - 1
// - if you force this type, ensure you set AceType=satUnknown before saving
// - defined as word for proper alignment
RawType: word;
/// contains the associated 32-bit access mask
Mask: TSecAccessMask;
/// contains an associated SID, in its raw binary content
Sid: RawSid;
/// some optional opaque callback/resource binary data, stored after the Sid
// - e.g. is a conditional expression binary for satConditional ACEs like
// '(@User.Project Any_of @Resource.Project)', or for satResourceAttribute
// is a CLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1 struct
// - may end with up to 3 zero bytes, for binary DWORD alignment
Opaque: RawByteString;
/// the associated Object Type GUID (satObject only)
ObjectType: TGuid;
/// the inherited Object Type GUID (satObject only)
InheritedObjectType: TGuid;
/// remove any previous content
procedure Clear;
/// compare the fields of this instance with another
function IsEqual(const ace: TSecAce): boolean;
/// append this entry as SDDL text into an existing buffer
// - could also generate SDDL RID placeholders, if dom binary is supplied,
// e.g. S-1-5-21-xx-xx-xx-512 (wkrGroupAdmins) into 'DA'
// - could also customize UUID values, e.g. with uuid = @AppendShortKnownUuid
procedure AppendAsText(var s: ShortString; var sddl: TSynTempAdder;
dom: PSid; uuid: TAppendShortUuid);
/// decode a SDDL ACE textual representation into this (cleared) entry
function FromText(var p: PUtf8Char; dom: PSid; uuid: TShortToUuid): TAceTextParse;
/// encode this entry into a self-relative binary buffer
// - returns the output length in bytes
// - if dest is nil, will compute the length but won't write anything
function ToBinary(dest: PAnsiChar): PtrInt;
/// decode a self-relative binary buffer into this (cleared) entry
function FromBinary(p, max: PByte): boolean;
/// user-friendly set the properties of this ACE
// - SID and Mask are supplied in their regular / SDDL text form
// - returns true on success - i.e. if all input params were correct
function Fill(sat: TSecAceType; const sidSddl, maskSddl: RawUtf8;
dom: PSid = nil; const condExp: RawUtf8 = ''; saf: TSecAceFlags = []): boolean;
/// get the associated SID, as SDDL text, optionally with a RID domain
function SidText(dom: PSid = nil): RawUtf8;
/// set the associated SID, parsed from SDDL text, optionally with a RID domain
function SidParse(const sidSddl: RawUtf8; dom: PSid = nil): boolean;
/// get the associated access mask, as SDDL text format
function MaskText: RawUtf8;
/// set the associated access mask, parsed from its SDDL text format
function MaskParse(const maskSddl: RawUtf8): boolean;
/// get the associated Object Type, as UUID text format
// - to customize the output format set e.g. uuid = @AppendShortKnownUuid
function ObjectText(uuid: TAppendShortUuid = nil): RawUtf8;
/// get the associated Inherited Object Type, as UUID text format
// - to customize the output format set e.g. uuid = @AppendShortKnownUuid
function InheritedText(uuid: TAppendShortUuid = nil): RawUtf8;
/// get the associated flags, as SDDL text format
function FlagsText: RawUtf8;
/// get the ACE conditional expression, as stored in Opaque binary
function ConditionalExpression(dom: PSid = nil): RawUtf8;
/// parse a ACE conditional expression, and assign it to the Opaque binary
function ConditionalExpressionParse(const condExp: RawUtf8;
dom: PSid = nil): TAceTextParse;
/// replace all nested RID from one domain to another
// - also within any ACE conditional expression
function ReplaceDomainRaw(old, new: PSid; maxRid: cardinal): integer;
/// replace all nested SID from one set of values to another
// - also within any ACE conditional expression
function ReplaceAnySid(const OldSid, NewSid: RawSidDynArray): integer;
end;
/// pointer to one ACE of the TSecurityDescriptor ACL
PSecAce = ^TSecAce;
/// define a discretionary/system access control list (DACL)
// - as stored in TSecurityDescriptor Dacl[] Sacl[] access control lists (ACL)
TSecAcl = array of TSecAce;
PSecAcl = ^TSecAcl;
{$A+}
const
/// the ACE which have just a Mask and SID in their definition
satCommon = [
satAccessAllowed,
satAccessDenied,
satAudit,
satAlarm,
satCallbackAccessAllowed,
satCallbackAccessDenied,
satCallbackAudit,
satCallbackAlarm,
satMandatoryLabel,
satResourceAttribute,
satScoppedPolicy,
satAccessFilter];
/// the ACE which have a samObject Mask, SID and Object UUIDs in their definition
satObject = [
satObjectAccessAllowed,
satObjectAccessDenied,
satObjectAudit,
satObjectAlarm,
satCallbackObjectAccessAllowed,
satCallbackObjectAccessDenied,
satCallbackObjectAudit,
satCallbackObjectAlarm];
/// the ACE which have a conditional expression as TSecAce.Opaque member
// - see [MS-DTYP] 2.4.4.17
// - the associated conditional expression is encoded in a binary format
// in the TSecAce.Opaque
satConditional = [
satCallbackAccessAllowed,
satCallbackAccessDenied,
satCallbackAudit,
satCallbackObjectAccessAllowed,
satCallbackObjectAccessDenied,
satCallbackObjectAudit];
/// defined in TSecAce.Flags for an ACE which has inheritance
safInheritanceFlags = [
safObjectInherit,
safContainerInherit,
safNoPropagateInherit,
safInheritOnly];
/// defined in TSecAce.Flags for an ACE which refers to audit
safAuditFlags = [
safSuccessfulAccess,
safFailedAccess];
/// compute a self-relative binary of a given ACL array
// - as stored within a TSecurityDescriptor instance, and accepted by
// low-level WinAPI SetSystemSecurityDescriptor() function
function SecAclToBinary(const acl: TSecAcl): RawByteString;
{ ******************* Conditional ACE Expressions SDDL and Binary Support }
type
/// token types for the conditional ACE binary storage
// - the conditional ACE is stored as a binary tree of value/operator nodes
// - mainly as sctLiteral, sctAttribute or sctOperator tokens
// - TSecConditionalToken ordinal value is the stored ACE binary token byte
// - tokens >= sctInternalFinal are never serialized, but used internally
// during SddlNextOperand() SDDL text parsing
// - see [MS-DTYP] 2.4.4.17.4 and following
TSecConditionalToken = (
sctPadding = $00,
sctInt8 = $01,
sctInt16 = $02,
sctInt32 = $03,
sctInt64 = $04,
sctUnicode = $10,
sctOctetString = $18,
sctComposite = $50,
sctSid = $51,
sctEqual = $80,
sctNotEqual = $81,
sctLessThan = $82,
sctLessThanOrEqual = $83,
sctGreaterThan = $84,
sctGreaterThanOrEqual = $85,
sctContains = $86,
sctExists = $87,
sctAnyOf = $88,
sctMemberOf = $89,
sctDeviceMemberOf = $8a,
sctMemberOfAny = $8b,
sctDeviceMemberOfAny = $8c,
sctNotExists = $8d,
sctNotContains = $8e,
sctNotAnyOf = $8f,
sctNotMemberOf = $90,
sctNotDeviceMemberOf = $91,
sctNotMemberOfAny = $92,
sctNotDeviceMemberOfAny = $93,
sctAnd = $a0,
sctOr = $a1,
sctNot = $a2,
sctLocalAttribute = $f8,
sctUserAttribute = $f9,
sctResourceAttribute = $fa,
sctDeviceAttribute = $fb,
// internal tokens - never serialized into binary
sctInternalFinal = $fc,
sctInternalParenthOpen = $fe,
sctInternalParenthClose = $ff);
PSecConditionalToken = ^TSecConditionalToken;
/// binary conditional ACE integer base indicator for SDDL/display purposes
// - see [MS-DTYP] 2.4.4.17.5 Literal Tokens
TSecConditionalBase = (
scbUndefined = 0,
scbOctal = 1,
scbDecimal = 2,
scbHexadecimal = 3);
/// binary conditional ACE integer sign indicator for SDDL/display purposes
// - see [MS-DTYP] 2.4.4.17.5 Literal Tokens
TSecConditionalSign = (
scsUndefined = 0,
scsPositive = 1,
scsNegative = 2,
scsNone = 3);
const
/// literal integer ACE token types
// - see [MS-DTYP] 2.4.4.17.5 Literal Tokens
sctInt = [
sctInt8 .. sctInt64];
/// literal ACE token types
// - see [MS-DTYP] 2.4.4.17.5 Literal Tokens
sctLiteral =
sctInt + [
sctUnicode,
sctOctetString,
sctComposite,
sctSid];
/// unary relational operator ACE token types
// - operand type must be either a SID literal, or a composite, each of
// whose elements is a SID literal
// - see [MS-DTYP] 2.4.4.17.6 Relational Operator Tokens
sctUnaryOperator = [
sctMemberOf .. sctDeviceMemberOfAny,
sctNotMemberOf .. sctNotDeviceMemberOfAny];
/// binary relational operator ACE token types
// - expects two operands, left-hand-side (LHS - in simple or @Prefixed form)
// and right-hand-side (RHS - in @Prefixed form or literal)
// - see [MS-DTYP] 2.4.4.17.6 Relational Operator Tokens
sctBinaryOperator = [
sctEqual .. sctContains,
sctAnyOf,
sctNotContains,
sctNotAnyOf];
/// relational operator ACE token types
// - see [MS-DTYP] 2.4.4.17.6 Relational Operator Tokens
sctRelationalOperator = sctUnaryOperator + sctBinaryOperator;
/// unary logical operator ACE token types
// - see [MS-DTYP] 2.4.4.17.7 Logical Operator Tokens
sctUnaryLogicalOperator = [
sctExists,
sctNotExists,
sctNot];
/// binary logical operator ACE token types
// - see [MS-DTYP] 2.4.4.17.7 Logical Operator Tokens
sctBinaryLogicalOperator = [
sctAnd,
sctOr];
/// logical operator ACE token types
// - operand type must be conditional expressions and/or expression terms:
// a sctLiteral operand would return an error
// - see [MS-DTYP] 2.4.4.17.7 Logical Operator Tokens
sctLogicalOperator = sctUnaryLogicalOperator + sctBinaryLogicalOperator;
/// attribute ACE token types
// - attributes can be associated with local environments, users, resources,
// or devices
// - see [MS-DTYP] 2.4.4.17.8 Attribute Tokens
sctAttribute = [
sctLocalAttribute,
sctUserAttribute,
sctResourceAttribute,
sctDeviceAttribute];
/// operands ACE token types
sctOperand = sctLiteral + sctAttribute;
/// single-operand ACE token types
sctUnary = sctUnaryOperator + sctUnaryLogicalOperator;
/// dual-operand ACE token types
sctBinary = sctBinaryOperator + sctBinaryLogicalOperator;
/// operator ACE tokens
sctOperator = sctUnary + sctBinary;
/// maximum depth of the TAceBinaryTree/TAceTextTree resolution
// - should be <= 255 to match the nodes index fields as byte
// - 192 nodes seems fair enough for realistic ACE conditional expressions
MAX_TREE_NODE = 191;
/// maximum length, in bytes, of a TAceBinaryTree/TAceTextTree binary/text input
// - absolute maximum is below 64KB (in TRawAce.AceSize)
// - 8KB of conditional expression is consistent with the MAX_TREE_NODE limit
MAX_TREE_BYTES = 8 shl 10;
type
/// internal type used for TRawAceOperand.Int
TRawAceOperandInt = packed record
/// the actual value is always stored as 64-bit little-endian
Value: Int64;
/// can customize the sign when serialized as SDDL text
Sign: TSecConditionalSign;
/// can customize the base when serialized as SDDL text
Base: TSecConditionalBase;
end;