1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 
5 using System.Diagnostics;
6 using System.Runtime.InteropServices;
7 
8 namespace System.DirectoryServices.ActiveDirectory
9 {
10     internal class PropertyManager
11     {
12         public static string DefaultNamingContext = "defaultNamingContext";
13         public static string SchemaNamingContext = "schemaNamingContext";
14         public static string ConfigurationNamingContext = "configurationNamingContext";
15         public static string RootDomainNamingContext = "rootDomainNamingContext";
16         public static string MsDSBehaviorVersion = "msDS-Behavior-Version";
17         public static string FsmoRoleOwner = "fsmoRoleOwner";
18         public static string ForestFunctionality = "forestFunctionality";
19         public static string NTMixedDomain = "ntMixedDomain";
20         public static string DomainFunctionality = "domainFunctionality";
21         public static string ObjectCategory = "objectCategory";
22         public static string SystemFlags = "systemFlags";
23         public static string DnsRoot = "dnsRoot";
24         public static string DistinguishedName = "distinguishedName";
25         public static string TrustParent = "trustParent";
26         // disable csharp compiler warning #0414: field assigned unused value
27 #pragma warning disable 0414
28         public static string FlatName = "flatName";
29         public static string Name = "name";
30         public static string Flags = "flags";
31         public static string TrustType = "trustType";
32         public static string TrustAttributes = "trustAttributes";
33 #pragma warning restore 0414
34         public static string BecomeSchemaMaster = "becomeSchemaMaster";
35         public static string BecomeDomainMaster = "becomeDomainMaster";
36         public static string BecomePdc = "becomePdc";
37         public static string BecomeRidMaster = "becomeRidMaster";
38         public static string BecomeInfrastructureMaster = "becomeInfrastructureMaster";
39         public static string DnsHostName = "dnsHostName";
40         public static string Options = "options";
41         public static string CurrentTime = "currentTime";
42         public static string HighestCommittedUSN = "highestCommittedUSN";
43         public static string OperatingSystem = "operatingSystem";
44         public static string HasMasterNCs = "hasMasterNCs";
45         public static string MsDSHasMasterNCs = "msDS-HasMasterNCs";
46         public static string MsDSHasFullReplicaNCs = "msDS-hasFullReplicaNCs";
47         public static string NCName = "nCName";
48         public static string Cn = "cn";
49         // disable csharp compiler warning #0414: field assigned unused value
50 #pragma warning disable 0414
51         public static string NETBIOSName = "nETBIOSName";
52 #pragma warning restore 0414
53         public static string DomainDNS = "domainDNS";
54         public static string InstanceType = "instanceType";
55         public static string MsDSSDReferenceDomain = "msDS-SDReferenceDomain";
56         public static string MsDSPortLDAP = "msDS-PortLDAP";
57         public static string MsDSPortSSL = "msDS-PortSSL";
58         public static string MsDSNCReplicaLocations = "msDS-NC-Replica-Locations";
59         public static string MsDSNCROReplicaLocations = "msDS-NC-RO-Replica-Locations";
60         public static string SupportedCapabilities = "supportedCapabilities";
61         public static string ServerName = "serverName";
62         public static string Enabled = "Enabled";
63         public static string ObjectGuid = "objectGuid";
64         public static string Keywords = "keywords";
65         public static string ServiceBindingInformation = "serviceBindingInformation";
66         public static string MsDSReplAuthenticationMode = "msDS-ReplAuthenticationMode";
67         public static string HasPartialReplicaNCs = "hasPartialReplicaNCs";
68         // disable csharp compiler warning #0414: field assigned unused value
69 #pragma warning disable 0414
70         public static string Container = "container";
71 #pragma warning restore 0414
72         public static string LdapDisplayName = "ldapDisplayName";
73         public static string AttributeID = "attributeID";
74         public static string AttributeSyntax = "attributeSyntax";
75         public static string Description = "description";
76         public static string SearchFlags = "searchFlags";
77         public static string OMSyntax = "oMSyntax";
78         public static string OMObjectClass = "oMObjectClass";
79         public static string IsSingleValued = "isSingleValued";
80         public static string IsDefunct = "isDefunct";
81         public static string RangeUpper = "rangeUpper";
82         public static string RangeLower = "rangeLower";
83         public static string IsMemberOfPartialAttributeSet = "isMemberOfPartialAttributeSet";
84         // disable csharp compiler warning #0414: field assigned unused value
85 #pragma warning disable 0414
86         public static string ObjectVersion = "objectVersion";
87 #pragma warning restore 0414
88         public static string LinkID = "linkID";
89         public static string ObjectClassCategory = "objectClassCategory";
90         public static string SchemaUpdateNow = "schemaUpdateNow";
91         public static string SubClassOf = "subClassOf";
92         public static string SchemaIDGuid = "schemaIDGUID";
93         public static string PossibleSuperiors = "possSuperiors";
94         public static string PossibleInferiors = "possibleInferiors";
95         public static string MustContain = "mustContain";
96         public static string MayContain = "mayContain";
97         public static string SystemMustContain = "systemMustContain";
98         public static string SystemMayContain = "systemMayContain";
99         public static string GovernsID = "governsID";
100         public static string IsGlobalCatalogReady = "isGlobalCatalogReady";
101         // disable csharp compiler warning #0414: field assigned unused value
102 #pragma warning disable 0414
103         public static string NTSecurityDescriptor = "ntSecurityDescriptor";
104 #pragma warning restore 0414
105         public static string DsServiceName = "dsServiceName";
106         public static string ReplicateSingleObject = "replicateSingleObject";
107         // disable csharp compiler warning #0414: field assigned unused value
108 #pragma warning disable 0414
109         public static string MsDSMasteredBy = "msDS-masteredBy";
110 #pragma warning restore 0414
111         public static string DefaultSecurityDescriptor = "defaultSecurityDescriptor";
112         public static string NamingContexts = "namingContexts";
113         public static string MsDSDefaultNamingContext = "msDS-DefaultNamingContext";
114         public static string OperatingSystemVersion = "operatingSystemVersion";
115         public static string AuxiliaryClass = "auxiliaryClass";
116         public static string SystemAuxiliaryClass = "systemAuxiliaryClass";
117         public static string SystemPossibleSuperiors = "systemPossSuperiors";
118         public static string InterSiteTopologyGenerator = "interSiteTopologyGenerator";
119         public static string FromServer = "fromServer";
120         public static string RIDAvailablePool = "rIDAvailablePool";
121 
122         // disable csharp compiler warning #0414: field assigned unused value
123 #pragma warning disable 0414
124         public static string SiteList = "siteList";
125 #pragma warning restore 0414
126         public static string MsDSHasInstantiatedNCs = "msDS-HasInstantiatedNCs";
127 
GetPropertyValue(DirectoryEntry directoryEntry, string propertyName)128         public static object GetPropertyValue(DirectoryEntry directoryEntry, string propertyName)
129         {
130             return GetPropertyValue(null, directoryEntry, propertyName);
131         }
132 
GetPropertyValue(DirectoryContext context, DirectoryEntry directoryEntry, string propertyName)133         public static object GetPropertyValue(DirectoryContext context, DirectoryEntry directoryEntry, string propertyName)
134         {
135             Debug.Assert(directoryEntry != null, "PropertyManager::GetPropertyValue - directoryEntry is null");
136 
137             Debug.Assert(propertyName != null, "PropertyManager::GetPropertyValue - propertyName is null");
138 
139             try
140             {
141                 if (directoryEntry.Properties[propertyName].Count == 0)
142                 {
143                     if (directoryEntry.Properties[PropertyManager.DistinguishedName].Count != 0)
144                     {
145                         throw new ActiveDirectoryOperationException(SR.Format(SR.PropertyNotFoundOnObject , propertyName, directoryEntry.Properties[PropertyManager.DistinguishedName].Value));
146                     }
147                     else
148                     {
149                         throw new ActiveDirectoryOperationException(SR.Format(SR.PropertyNotFound , propertyName));
150                     }
151                 }
152             }
153             catch (COMException e)
154             {
155                 throw ExceptionHelper.GetExceptionFromCOMException(context, e);
156             }
157 
158             return directoryEntry.Properties[propertyName].Value;
159         }
160 
GetSearchResultPropertyValue(SearchResult res, string propertyName)161         public static object GetSearchResultPropertyValue(SearchResult res, string propertyName)
162         {
163             Debug.Assert(res != null, "PropertyManager::GetSearchResultPropertyValue - res is null");
164 
165             Debug.Assert(propertyName != null, "PropertyManager::GetSearchResultPropertyValue - propertyName is null");
166 
167             ResultPropertyValueCollection propertyValues = null;
168             try
169             {
170                 propertyValues = res.Properties[propertyName];
171                 if ((propertyValues == null) || (propertyValues.Count < 1))
172                 {
173                     throw new ActiveDirectoryOperationException(SR.Format(SR.PropertyNotFound , propertyName));
174                 }
175             }
176             catch (COMException e)
177             {
178                 throw ExceptionHelper.GetExceptionFromCOMException(e);
179             }
180 
181             return propertyValues[0];
182         }
183     }
184 }
185