/
ActiveDirectorySchemaProperty.cs
1406 lines (1234 loc) · 51.6 KB
/
ActiveDirectorySchemaProperty.cs
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Text;
using System.Diagnostics;
using System.ComponentModel;
using System.Runtime.InteropServices;
namespace System.DirectoryServices.ActiveDirectory
{
internal enum SearchFlags : int
{
None = 0,
IsIndexed = 1,
IsIndexedOverContainer = 2,
IsInAnr = 4,
IsOnTombstonedObject = 8,
IsTupleIndexed = 32
}
public class ActiveDirectorySchemaProperty : IDisposable
{
// private variables
private DirectoryEntry? _schemaEntry;
private DirectoryEntry? _propertyEntry;
private DirectoryEntry? _abstractPropertyEntry;
private readonly NativeComInterfaces.IAdsProperty? _iadsProperty;
private readonly DirectoryContext _context;
internal bool isBound;
private bool _disposed;
private ActiveDirectorySchema? _schema;
private bool _propertiesFromSchemaContainerInitialized;
private bool _isDefunctOnServer;
private SearchResult? _propertyValuesFromServer;
// private variables for caching properties
private readonly string _ldapDisplayName;
private string? _commonName;
private string? _oid;
private ActiveDirectorySyntax _syntax = (ActiveDirectorySyntax)(-1);
private bool _syntaxInitialized;
private string? _description;
private bool _descriptionInitialized;
private bool _isSingleValued;
private bool _isSingleValuedInitialized;
private bool _isInGlobalCatalog;
private bool _isInGlobalCatalogInitialized;
private Nullable<int> _rangeLower;
private bool _rangeLowerInitialized;
private Nullable<int> _rangeUpper;
private bool _rangeUpperInitialized;
private bool _isDefunct;
private SearchFlags _searchFlags = SearchFlags.None;
private bool _searchFlagsInitialized;
private ActiveDirectorySchemaProperty? _linkedProperty;
private bool _linkedPropertyInitialized;
private Nullable<int> _linkId;
private bool _linkIdInitialized;
private byte[]? _schemaGuidBinaryForm;
// OMObjectClass values for the syntax
//0x2B0C0287731C00854A
private static readonly OMObjectClass s_dnOMObjectClass = new OMObjectClass(new byte[] { 0x2B, 0x0C, 0x02, 0x87, 0x73, 0x1C, 0x00, 0x85, 0x4A });
//0x2A864886F7140101010C
private static readonly OMObjectClass s_dNWithStringOMObjectClass = new OMObjectClass(new byte[] { 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x14, 0x01, 0x01, 0x01, 0x0C });
//0x2A864886F7140101010B
private static readonly OMObjectClass s_dNWithBinaryOMObjectClass = new OMObjectClass(new byte[] { 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x14, 0x01, 0x01, 0x01, 0x0B });
//0x2A864886F71401010106
private static readonly OMObjectClass s_replicaLinkOMObjectClass = new OMObjectClass(new byte[] { 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x14, 0x01, 0x01, 0x01, 0x06 });
//0x2B0C0287731C00855C
private static readonly OMObjectClass s_presentationAddressOMObjectClass = new OMObjectClass(new byte[] { 0x2B, 0x0C, 0x02, 0x87, 0x73, 0x1C, 0x00, 0x85, 0x5C });
//0x2B0C0287731C00853E
private static readonly OMObjectClass s_accessPointDnOMObjectClass = new OMObjectClass(new byte[] { 0x2B, 0x0C, 0x02, 0x87, 0x73, 0x1C, 0x00, 0x85, 0x3E });
//0x56060102050B1D
private static readonly OMObjectClass s_oRNameOMObjectClass = new OMObjectClass(new byte[] { 0x56, 0x06, 0x01, 0x02, 0x05, 0x0B, 0x1D });
// syntaxes
private static readonly Syntax[] s_syntaxes = {/* CaseExactString */ new Syntax("2.5.5.3", 27, null),
/* CaseIgnoreString */ new Syntax("2.5.5.4", 20, null),
/* NumericString */ new Syntax("2.5.5.6", 18, null),
/* DirectoryString */ new Syntax("2.5.5.12", 64, null),
/* OctetString */ new Syntax("2.5.5.10", 4, null),
/* SecurityDescriptor */ new Syntax("2.5.5.15", 66, null),
/* Int */ new Syntax("2.5.5.9", 2, null),
/* Int64 */ new Syntax("2.5.5.16", 65, null),
/* Bool */ new Syntax("2.5.5.8", 1, null),
/* Oid */ new Syntax("2.5.5.2", 6, null),
/* GeneralizedTime */ new Syntax("2.5.5.11", 24, null),
/* UtcTime */ new Syntax("2.5.5.11", 23, null),
/* DN */ new Syntax("2.5.5.1", 127, s_dnOMObjectClass),
/* DNWithBinary */ new Syntax("2.5.5.7", 127, s_dNWithBinaryOMObjectClass),
/* DNWithString */ new Syntax("2.5.5.14", 127, s_dNWithStringOMObjectClass),
/* Enumeration */ new Syntax("2.5.5.9", 10, null),
/* IA5String */ new Syntax("2.5.5.5", 22, null),
/* PrintableString */ new Syntax("2.5.5.5", 19, null),
/* Sid */ new Syntax("2.5.5.17", 4, null),
/* AccessPointDN */ new Syntax("2.5.5.14", 127, s_accessPointDnOMObjectClass),
/* ORName */ new Syntax("2.5.5.7", 127, s_oRNameOMObjectClass),
/* PresentationAddress */ new Syntax("2.5.5.13", 127, s_presentationAddressOMObjectClass),
/* ReplicaLink */ new Syntax("2.5.5.10", 127, s_replicaLinkOMObjectClass)};
#region constructors
public ActiveDirectorySchemaProperty(DirectoryContext context, string ldapDisplayName)
{
ArgumentNullException.ThrowIfNull(context);
if ((context.Name == null) && (!context.isRootDomain()))
{
throw new ArgumentException(SR.ContextNotAssociatedWithDomain, nameof(context));
}
if (context.Name != null)
{
// the target should be a valid forest name or a server
if (!((context.isRootDomain()) || (context.isADAMConfigSet()) || (context.isServer())))
{
throw new ArgumentException(SR.NotADOrADAM, nameof(context));
}
}
ArgumentNullException.ThrowIfNull(ldapDisplayName);
if (ldapDisplayName.Length == 0)
{
throw new ArgumentException(SR.EmptyStringParameter, nameof(ldapDisplayName));
}
_context = new DirectoryContext(context);
// validate the context
_schemaEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.SchemaNamingContext);
_schemaEntry.Bind(true);
_ldapDisplayName = ldapDisplayName;
// common name of the property defaults to the ldap display name
_commonName = ldapDisplayName;
// set the bind flag
this.isBound = false;
}
// internal constructor
internal ActiveDirectorySchemaProperty(DirectoryContext context, string ldapDisplayName, DirectoryEntry? propertyEntry, DirectoryEntry? schemaEntry)
{
_context = context;
_ldapDisplayName = ldapDisplayName;
// common name of the property defaults to the ldap display name
_propertyEntry = propertyEntry;
_isDefunctOnServer = false;
_isDefunct = _isDefunctOnServer;
try
{
// initialize the directory entry for the abstract schema class
_abstractPropertyEntry = DirectoryEntryManager.GetDirectoryEntryInternal(context, "LDAP://" + context.GetServerName() + "/schema/" + ldapDisplayName);
_iadsProperty = (NativeComInterfaces.IAdsProperty)_abstractPropertyEntry.NativeObject;
}
catch (COMException e)
{
if (e.ErrorCode == unchecked((int)0x80005000))
{
throw new ActiveDirectoryObjectNotFoundException(SR.DSNotFound, typeof(ActiveDirectorySchemaProperty), ldapDisplayName);
}
else
{
throw ExceptionHelper.GetExceptionFromCOMException(context, e);
}
}
catch (InvalidCastException)
{
// this means that we found an object but it is not a schema class
throw new ActiveDirectoryObjectNotFoundException(SR.DSNotFound, typeof(ActiveDirectorySchemaProperty), ldapDisplayName);
}
catch (ActiveDirectoryObjectNotFoundException)
{
// this is the case where the context is a config set and we could not find an ADAM instance in that config set
throw new ActiveDirectoryOperationException(SR.Format(SR.ADAMInstanceNotFoundInConfigSet, context.Name));
}
// set the bind flag
this.isBound = true;
}
internal ActiveDirectorySchemaProperty(DirectoryContext context, string commonName, SearchResult propertyValuesFromServer, DirectoryEntry schemaEntry)
{
_context = context;
_schemaEntry = schemaEntry;
// all relevant properties have already been retrieved from the server
_propertyValuesFromServer = propertyValuesFromServer;
Debug.Assert(_propertyValuesFromServer != null);
_propertiesFromSchemaContainerInitialized = true;
_propertyEntry = GetSchemaPropertyDirectoryEntry();
// names
_commonName = commonName;
_ldapDisplayName = (string)GetValueFromCache(PropertyManager.LdapDisplayName, true)!;
// this constructor is only called for defunct classes
_isDefunctOnServer = true;
_isDefunct = _isDefunctOnServer;
// set the bind flag
this.isBound = true;
}
internal ActiveDirectorySchemaProperty(DirectoryContext context, string commonName, string ldapDisplayName, DirectoryEntry propertyEntry, DirectoryEntry schemaEntry)
{
_context = context;
_schemaEntry = schemaEntry;
_propertyEntry = propertyEntry;
// names
_commonName = commonName;
_ldapDisplayName = ldapDisplayName;
// this constructor is only called for defunct properties
_isDefunctOnServer = true;
_isDefunct = _isDefunctOnServer;
// set the bind flag
this.isBound = true;
}
#endregion constructors
#region IDisposable
public void Dispose()
{
Dispose(true);
}
// private Dispose method
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
// check if this is an explicit Dispose
// only then clean up the directory entries
if (disposing)
{
// dispose schema entry
if (_schemaEntry != null)
{
_schemaEntry.Dispose();
_schemaEntry = null;
}
// dispose property entry
if (_propertyEntry != null)
{
_propertyEntry.Dispose();
_propertyEntry = null;
}
// dispose abstract class entry
if (_abstractPropertyEntry != null)
{
_abstractPropertyEntry.Dispose();
_abstractPropertyEntry = null;
}
// dispose the schema object
_schema?.Dispose();
}
_disposed = true;
}
}
#endregion IDisposable
#region public methods
public static ActiveDirectorySchemaProperty FindByName(DirectoryContext context, string ldapDisplayName)
{
ArgumentNullException.ThrowIfNull(context);
ActiveDirectorySchemaProperty? schemaProperty = null;
if ((context.Name == null) && (!context.isRootDomain()))
{
throw new ArgumentException(SR.ContextNotAssociatedWithDomain, nameof(context));
}
if (context.Name != null)
{
// the target should be a valid forest name or a server
if (!((context.isRootDomain()) || (context.isADAMConfigSet()) || (context.isServer())))
{
throw new ArgumentException(SR.NotADOrADAM, nameof(context));
}
}
ArgumentNullException.ThrowIfNull(ldapDisplayName);
if (ldapDisplayName.Length == 0)
{
throw new ArgumentException(SR.EmptyStringParameter, nameof(ldapDisplayName));
}
// work with copy of the context
context = new DirectoryContext(context);
// create a schema property
schemaProperty = new ActiveDirectorySchemaProperty(context, ldapDisplayName, (DirectoryEntry?)null, null);
return schemaProperty;
}
public void Save()
{
CheckIfDisposed();
if (!isBound)
{
try
{
// create a new directory entry for this class
_schemaEntry ??= DirectoryEntryManager.GetDirectoryEntry(_context, WellKnownDN.SchemaNamingContext);
// this will create the class and set the CN value
string rdn = "CN=" + _commonName;
rdn = Utils.GetEscapedPath(rdn);
_propertyEntry = _schemaEntry.Children.Add(rdn, "attributeSchema");
}
catch (COMException e)
{
throw ExceptionHelper.GetExceptionFromCOMException(_context, e);
}
catch (ActiveDirectoryObjectNotFoundException)
{
// this is the case where the context is a config set and we could not find an ADAM instance in that config set
throw new ActiveDirectoryOperationException(SR.Format(SR.ADAMInstanceNotFoundInConfigSet, _context.Name));
}
// set the ldap display name property
SetProperty(PropertyManager.LdapDisplayName, _ldapDisplayName);
// set the oid value
SetProperty(PropertyManager.AttributeID, _oid);
// set the syntax
if (_syntax != (ActiveDirectorySyntax)(-1))
{
SetSyntax(_syntax);
}
// set the description
SetProperty(PropertyManager.Description, _description);
// set the isSingleValued attribute
_propertyEntry.Properties[PropertyManager.IsSingleValued].Value = _isSingleValued;
// set the isGlobalCatalogReplicated attribute
_propertyEntry.Properties[PropertyManager.IsMemberOfPartialAttributeSet].Value = _isInGlobalCatalog;
// set the isDefunct attribute
_propertyEntry.Properties[PropertyManager.IsDefunct].Value = _isDefunct;
// set the range lower attribute
if (_rangeLower != null)
{
_propertyEntry.Properties[PropertyManager.RangeLower].Value = (int)_rangeLower.Value;
}
// set the range upper attribute
if (_rangeUpper != null)
{
_propertyEntry.Properties[PropertyManager.RangeUpper].Value = (int)_rangeUpper.Value;
}
// set the searchFlags attribute
if (_searchFlags != SearchFlags.None)
{
_propertyEntry.Properties[PropertyManager.SearchFlags].Value = (int)_searchFlags;
}
// set the link id
if (_linkId != null)
{
_propertyEntry.Properties[PropertyManager.LinkID].Value = (int)_linkId.Value;
}
// set the schemaIDGuid property
if (_schemaGuidBinaryForm != null)
{
SetProperty(PropertyManager.SchemaIDGuid, _schemaGuidBinaryForm);
}
}
try
{
// commit the classEntry to server
_propertyEntry!.CommitChanges();
// Refresh the schema cache on the schema role owner
if (_schema == null)
{
ActiveDirectorySchema schemaObject = ActiveDirectorySchema.GetSchema(_context);
bool alreadyUsingSchemaRoleOwnerContext = false;
DirectoryServer? schemaRoleOwner = null;
try
{
//
// if we are not already talking to the schema role owner, change the context
//
schemaRoleOwner = schemaObject.SchemaRoleOwner;
if (Utils.Compare(schemaRoleOwner.Name, _context.GetServerName()) != 0)
{
DirectoryContext schemaRoleOwnerContext = Utils.GetNewDirectoryContext(schemaRoleOwner.Name, DirectoryContextType.DirectoryServer, _context);
_schema = ActiveDirectorySchema.GetSchema(schemaRoleOwnerContext);
}
else
{
alreadyUsingSchemaRoleOwnerContext = true;
_schema = schemaObject;
}
}
finally
{
schemaRoleOwner?.Dispose();
if (!alreadyUsingSchemaRoleOwnerContext)
{
schemaObject.Dispose();
}
}
}
_schema.RefreshSchema();
}
catch (COMException e)
{
throw ExceptionHelper.GetExceptionFromCOMException(_context, e);
}
// now that the changes are committed to the server
// update the defunct/non-defunct status of the class on the server
_isDefunctOnServer = _isDefunct;
// invalidate all properties
_commonName = null;
_oid = null;
_syntaxInitialized = false;
_descriptionInitialized = false;
_isSingleValuedInitialized = false;
_isInGlobalCatalogInitialized = false;
_rangeLowerInitialized = false;
_rangeUpperInitialized = false;
_searchFlagsInitialized = false;
_linkedPropertyInitialized = false;
_linkIdInitialized = false;
_schemaGuidBinaryForm = null;
_propertiesFromSchemaContainerInitialized = false;
// set bind flag
isBound = true;
}
public override string ToString() => Name;
public DirectoryEntry GetDirectoryEntry()
{
CheckIfDisposed();
if (!isBound)
{
throw new InvalidOperationException(SR.CannotGetObject);
}
GetSchemaPropertyDirectoryEntry();
Debug.Assert(_propertyEntry != null);
return DirectoryEntryManager.GetDirectoryEntryInternal(_context, _propertyEntry.Path);
}
#endregion public methods
#region public properties
public string Name
{
get
{
CheckIfDisposed();
return _ldapDisplayName;
}
}
public string? CommonName
{
get
{
CheckIfDisposed();
if (isBound)
{
// get the property from the server
_commonName ??= (string)GetValueFromCache(PropertyManager.Cn, true)!;
}
return _commonName;
}
set
{
CheckIfDisposed();
if (value != null && value.Length == 0)
throw new ArgumentException(SR.EmptyStringParameter, nameof(value));
if (isBound)
{
// set the value on the directory entry
SetProperty(PropertyManager.Cn, value);
}
_commonName = value;
}
}
public string? Oid
{
get
{
CheckIfDisposed();
if (isBound)
{
if (_oid == null)
{
// get the property from the abstract schema/ schema container
// (for non-defunt classes this property is available in the abstract schema)
if (!_isDefunctOnServer)
{
try
{
_oid = _iadsProperty!.OID;
}
catch (COMException e)
{
throw ExceptionHelper.GetExceptionFromCOMException(_context, e);
}
}
else
{
_oid = (string)GetValueFromCache(PropertyManager.AttributeID, true)!;
}
}
}
return _oid;
}
set
{
CheckIfDisposed();
if (value != null && value.Length == 0)
throw new ArgumentException(SR.EmptyStringParameter, nameof(value));
if (isBound)
{
// set the value on the directory entry
SetProperty(PropertyManager.AttributeID, value);
}
_oid = value;
}
}
public ActiveDirectorySyntax Syntax
{
get
{
CheckIfDisposed();
if (isBound)
{
if (!_syntaxInitialized)
{
byte[]? omObjectClassBinaryForm = (byte[]?)GetValueFromCache(PropertyManager.OMObjectClass, false);
OMObjectClass? omObjectClass = (omObjectClassBinaryForm != null) ? new OMObjectClass(omObjectClassBinaryForm) : null;
_syntax = MapSyntax((string)GetValueFromCache(PropertyManager.AttributeSyntax, true)!,
(int)GetValueFromCache(PropertyManager.OMSyntax, true)!,
omObjectClass);
_syntaxInitialized = true;
}
}
return _syntax;
}
set
{
CheckIfDisposed();
if (value < ActiveDirectorySyntax.CaseExactString || value > ActiveDirectorySyntax.ReplicaLink)
{
throw new InvalidEnumArgumentException(nameof(value), (int)value, typeof(ActiveDirectorySyntax));
}
if (isBound)
{
// set the value on the directory entry
SetSyntax(value);
}
_syntax = value;
}
}
public string? Description
{
get
{
CheckIfDisposed();
if (isBound)
{
if (!_descriptionInitialized)
{
// get the property from the server
_description = (string?)GetValueFromCache(PropertyManager.Description, false);
_descriptionInitialized = true;
}
}
return _description;
}
set
{
CheckIfDisposed();
if (value != null && value.Length == 0)
throw new ArgumentException(SR.EmptyStringParameter, nameof(value));
if (isBound)
{
// set the value on the directory entry
SetProperty(PropertyManager.Description, value);
}
_description = value;
}
}
public bool IsSingleValued
{
get
{
CheckIfDisposed();
if (isBound)
{
if (!_isSingleValuedInitialized)
{
// get the property from the abstract schema/ schema container
// (for non-defunt classes this property is available in the abstract schema)
if (!_isDefunctOnServer)
{
try
{
_isSingleValued = !_iadsProperty!.MultiValued;
}
catch (COMException e)
{
throw ExceptionHelper.GetExceptionFromCOMException(_context, e);
}
}
else
{
_isSingleValued = (bool)GetValueFromCache(PropertyManager.IsSingleValued, true)!;
}
_isSingleValuedInitialized = true;
}
}
return _isSingleValued;
}
set
{
CheckIfDisposed();
if (isBound)
{
// get the distinguished name to construct the directory entry
GetSchemaPropertyDirectoryEntry();
Debug.Assert(_propertyEntry != null);
// set the value on the directory entry
_propertyEntry.Properties[PropertyManager.IsSingleValued].Value = value;
}
_isSingleValued = value;
}
}
public bool IsIndexed
{
get
{
CheckIfDisposed();
return IsSetInSearchFlags(SearchFlags.IsIndexed);
}
set
{
CheckIfDisposed();
if (value)
{
SetBitInSearchFlags(SearchFlags.IsIndexed);
}
else
{
ResetBitInSearchFlags(SearchFlags.IsIndexed);
}
}
}
public bool IsIndexedOverContainer
{
get
{
CheckIfDisposed();
return IsSetInSearchFlags(SearchFlags.IsIndexedOverContainer);
}
set
{
CheckIfDisposed();
if (value)
{
SetBitInSearchFlags(SearchFlags.IsIndexedOverContainer);
}
else
{
ResetBitInSearchFlags(SearchFlags.IsIndexedOverContainer);
}
}
}
public bool IsInAnr
{
get
{
CheckIfDisposed();
return IsSetInSearchFlags(SearchFlags.IsInAnr);
}
set
{
CheckIfDisposed();
if (value)
{
SetBitInSearchFlags(SearchFlags.IsInAnr);
}
else
{
ResetBitInSearchFlags(SearchFlags.IsInAnr);
}
}
}
public bool IsOnTombstonedObject
{
get
{
CheckIfDisposed();
return IsSetInSearchFlags(SearchFlags.IsOnTombstonedObject);
}
set
{
CheckIfDisposed();
if (value)
{
SetBitInSearchFlags(SearchFlags.IsOnTombstonedObject);
}
else
{
ResetBitInSearchFlags(SearchFlags.IsOnTombstonedObject);
}
}
}
public bool IsTupleIndexed
{
get
{
CheckIfDisposed();
return IsSetInSearchFlags(SearchFlags.IsTupleIndexed);
}
set
{
CheckIfDisposed();
if (value)
{
SetBitInSearchFlags(SearchFlags.IsTupleIndexed);
}
else
{
ResetBitInSearchFlags(SearchFlags.IsTupleIndexed);
}
}
}
public bool IsInGlobalCatalog
{
get
{
CheckIfDisposed();
if (isBound)
{
if (!_isInGlobalCatalogInitialized)
{
// get the property from the server
object? value = GetValueFromCache(PropertyManager.IsMemberOfPartialAttributeSet, false);
_isInGlobalCatalog = (value != null) ? (bool)value : false;
_isInGlobalCatalogInitialized = true;
}
}
return _isInGlobalCatalog;
}
set
{
CheckIfDisposed();
if (isBound)
{
// get the distinguished name to construct the directory entry
GetSchemaPropertyDirectoryEntry();
Debug.Assert(_propertyEntry != null);
// set the value on the directory entry
_propertyEntry.Properties[PropertyManager.IsMemberOfPartialAttributeSet].Value = value;
}
_isInGlobalCatalog = value;
}
}
public Nullable<int> RangeLower
{
get
{
CheckIfDisposed();
if (isBound)
{
if (!_rangeLowerInitialized)
{
// get the property from the server
// if the property is not set then we will return null
object? value = GetValueFromCache(PropertyManager.RangeLower, false);
if (value == null)
{
_rangeLower = null;
}
else
{
_rangeLower = (int)value;
}
_rangeLowerInitialized = true;
}
}
return _rangeLower;
}
set
{
CheckIfDisposed();
if (isBound)
{
// get the distinguished name to construct the directory entry
GetSchemaPropertyDirectoryEntry();
Debug.Assert(_propertyEntry != null);
// set the value on the directory entry
if (value == null)
{
if (_propertyEntry.Properties.Contains(PropertyManager.RangeLower))
{
_propertyEntry.Properties[PropertyManager.RangeLower].Clear();
}
}
else
{
_propertyEntry.Properties[PropertyManager.RangeLower].Value = (int)value.Value;
}
}
_rangeLower = value;
}
}
public Nullable<int> RangeUpper
{
get
{
CheckIfDisposed();
if (isBound)
{
if (!_rangeUpperInitialized)
{
// get the property from the server
// if the property is not set then we will return null
object? value = GetValueFromCache(PropertyManager.RangeUpper, false);
if (value == null)
{
_rangeUpper = null;
}
else
{
_rangeUpper = (int)value;
}
_rangeUpperInitialized = true;
}
}
return _rangeUpper;
}
set
{
CheckIfDisposed();
if (isBound)
{
// get the distinguished name to construct the directory entry
GetSchemaPropertyDirectoryEntry();
Debug.Assert(_propertyEntry != null);
// set the value on the directory entry
if (value == null)
{
if (_propertyEntry.Properties.Contains(PropertyManager.RangeUpper))
{
_propertyEntry.Properties[PropertyManager.RangeUpper].Clear();
}
}
else
{
_propertyEntry.Properties[PropertyManager.RangeUpper].Value = (int)value.Value;
}
}
_rangeUpper = value;
}
}
public bool IsDefunct
{
get
{
CheckIfDisposed();
// this is initialized for bound properties in the constructor
return _isDefunct;
}
set
{
CheckIfDisposed();
if (isBound)
{
// set the value on the directory entry
SetProperty(PropertyManager.IsDefunct, value);
}
_isDefunct = value;
}
}
public ActiveDirectorySchemaProperty? Link
{
get
{
CheckIfDisposed();
if (isBound)
{
if (!_linkedPropertyInitialized)
{
object? value = GetValueFromCache(PropertyManager.LinkID, false);
int tempLinkId = (value != null) ? (int)value : -1;
if (tempLinkId != -1)
{
int linkIdToSearch = tempLinkId - 2 * (tempLinkId % 2) + 1;
try
{
_schemaEntry ??= DirectoryEntryManager.GetDirectoryEntry(_context, WellKnownDN.SchemaNamingContext);
string filter = "(&(" + PropertyManager.ObjectCategory + "=attributeSchema)" + "(" + PropertyManager.LinkID + "=" + linkIdToSearch + "))";
ReadOnlyActiveDirectorySchemaPropertyCollection linkedProperties = ActiveDirectorySchema.GetAllProperties(_context, _schemaEntry, filter);
if (linkedProperties.Count != 1)
{
throw new ActiveDirectoryObjectNotFoundException(SR.Format(SR.LinkedPropertyNotFound, linkIdToSearch), typeof(ActiveDirectorySchemaProperty), null);
}
_linkedProperty = linkedProperties[0];
}
catch (COMException e)
{
throw ExceptionHelper.GetExceptionFromCOMException(_context, e);
}
}
_linkedPropertyInitialized = true;
}
}
return _linkedProperty;
}
}