internal override T GetExtendedObjectFromDN(string distinguishedName, ICollection <string> propertiesToFetch, bool showDeleted) { ADObject domain = null; if (string.Compare(distinguishedName, base.CmdletSessionInfo.ADRootDSE.DefaultNamingContext, StringComparison.OrdinalIgnoreCase) == 0) { using (ADTopologyManagement aDTopologyManagement = new ADTopologyManagement(base.CmdletSessionInfo.ADSessionInfo)) { domain = aDTopologyManagement.GetDomain(); } if (domain == null) { DebugLogger.LogInfo(this._debugCategory, string.Format("GetExtendedObjectFromIdentity: No objects returned from custom action", new object[0])); } } if (domain == null) { DebugLogger.LogInfo(this._debugCategory, string.Format("ADFactory: GetExtendedObjectFromDN: Identity not found", new object[0])); T t = default(T); return(t); } else { T aDSessionInfo = this.Construct(domain, null); aDSessionInfo.SessionInfo = base.CmdletSessionInfo.ADSessionInfo; return(aDSessionInfo); } }
private T GetExtendedForestObjectUsingCurrentSession(ICollection <string> propertiesToFetch, bool showDeleted) { ADEntity forest; using (ADTopologyManagement aDTopologyManagement = new ADTopologyManagement(base.CmdletSessionInfo.ADSessionInfo)) { forest = aDTopologyManagement.GetForest(); } T aDSessionInfo = this.Construct(forest, null); aDSessionInfo.SetValue("PartitionsContainer", string.Concat("CN=Partitions,", base.CmdletSessionInfo.ADRootDSE.ConfigurationNamingContext)); aDSessionInfo.SessionInfo = base.CmdletSessionInfo.ADSessionInfo; aDSessionInfo.IsSearchResult = true; return(aDSessionInfo); }
internal override T GetExtendedObjectFromIdentity(T identityObj, string identityQueryPath, ICollection <string> propertiesToFetch, bool showDeleted) { ADObject aDObject = null; ADObject aDObject1 = null; ADObject aDObject2 = null; T t; string nTDSSettingsDN = this.ResolveIdentityToNTDSSettingsDN(identityObj, null, false, out aDObject, out aDObject1, out aDObject2); if (nTDSSettingsDN != null) { using (ADTopologyManagement aDTopologyManagement = new ADTopologyManagement(base.CmdletSessionInfo.ADSessionInfo)) { string[] strArrays = new string[1]; strArrays[0] = nTDSSettingsDN; ADEntity[] domainController = aDTopologyManagement.GetDomainController(strArrays); if (domainController == null || (int)domainController.Length == 0) { DebugLogger.LogInfo("ADDirectoryServerFactory", string.Format("GetExtendedObjectFromIdentity: No objects returned from custom action", new object[0])); throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.ObjectNotFound, new object[0])); } else { AttributeSetRequest attributeSetRequest = this.ConstructAttributeSetRequest(propertiesToFetch); T aDSessionInfo = this.Construct(domainController[0], attributeSetRequest); aDSessionInfo.SessionInfo = base.CmdletSessionInfo.ADSessionInfo; t = aDSessionInfo; } } return(t); } else { DebugLogger.LogInfo("ADDirectoryServerFactory", string.Format("GetExtendedObjectFromIdentity: Could not find the DirectoryServer's NTDS Settings DN", new object[0])); object[] identity = new object[1]; identity[0] = identityObj.Identity; throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.DirectoryServerNotFound, identity)); } }
protected void TargetOperationMasterRole(ADOperationMasterRole fsmoRole) { bool flag; ADSessionInfo sessionInfo = this.GetSessionInfo(); string server = sessionInfo.Server; if (server != null) { flag = this.DoesServerNameRepresentDomainName(server); } else { flag = true; } if (flag) { string value = null; if (fsmoRole == ADOperationMasterRole.PDCEmulator || fsmoRole == ADOperationMasterRole.RIDMaster || fsmoRole == ADOperationMasterRole.InfrastructureMaster) { using (ADTopologyManagement aDTopologyManagement = new ADTopologyManagement(sessionInfo)) { ADObject domain = aDTopologyManagement.GetDomain(); ADOperationMasterRole aDOperationMasterRole = fsmoRole; switch (aDOperationMasterRole) { case ADOperationMasterRole.PDCEmulator: { value = domain["PDCEmulator"].Value as string; break; } case ADOperationMasterRole.RIDMaster: { value = domain["RIDMaster"].Value as string; break; } case ADOperationMasterRole.InfrastructureMaster: { value = domain["InfrastructureMaster"].Value as string; break; } } } if (string.IsNullOrEmpty(value)) { object[] objArray = new object[2]; objArray[0] = fsmoRole; objArray[1] = server; throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.FSMORoleNotFoundInDomain, objArray)); } } else { if (fsmoRole == ADOperationMasterRole.SchemaMaster || fsmoRole == ADOperationMasterRole.DomainNamingMaster) { using (ADTopologyManagement aDTopologyManagement1 = new ADTopologyManagement(sessionInfo)) { ADEntity forest = aDTopologyManagement1.GetForest(); ADOperationMasterRole aDOperationMasterRole1 = fsmoRole; switch (aDOperationMasterRole1) { case ADOperationMasterRole.SchemaMaster: { value = forest["SchemaMaster"].Value as string; break; } case ADOperationMasterRole.DomainNamingMaster: { value = forest["DomainNamingMaster"].Value as string; break; } } } if (string.IsNullOrEmpty(value)) { object[] objArray1 = new object[2]; objArray1[0] = fsmoRole; objArray1[1] = server; throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.FSMORoleNotFoundInForest, objArray1)); } } } ADSessionInfo aDSessionInfo = sessionInfo.Copy(); aDSessionInfo.Server = value; if (!this.SessionSpecified()) { this.SetPipelinedSessionInfo(aDSessionInfo); } else { this.SetDefaultSessionInfo(aDSessionInfo); return; } } }
private bool MoveADDSOperationMasterRoleProcessCSRoutine() { ADObject aDObject; bool flag = false; string value; int? nullable; this._identityDSObj = this._cmdletParameters["Identity"] as ADDirectoryServer; this._seize = this._cmdletParameters.GetSwitchParameterBooleanValue("Force"); this._operationMasterRolesToTransfer = this._cmdletParameters["OperationMasterRole"] as ADOperationMasterRole[]; base.SetPipelinedSessionInfo(this._identityDSObj.SessionInfo); CmdletSessionInfo cmdletSessionInfo = this.GetCmdletSessionInfo(); if (cmdletSessionInfo.ConnectedADServerType == ADServerType.ADLDS) { ADOperationMasterRole[] aDOperationMasterRoleArray = this._operationMasterRolesToTransfer; for (int i = 0; i < (int)aDOperationMasterRoleArray.Length; i++) { ADOperationMasterRole aDOperationMasterRole = aDOperationMasterRoleArray[i]; ADOperationMasterRole aDOperationMasterRole1 = aDOperationMasterRole; switch (aDOperationMasterRole1) { case ADOperationMasterRole.PDCEmulator: case ADOperationMasterRole.RIDMaster: case ADOperationMasterRole.InfrastructureMaster: { object[] str = new object[1]; str[0] = aDOperationMasterRole.ToString(); throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.MoveOperationMasterRoleNotApplicableForADLDS, str)); } } } } ADDirectoryServerFactory <ADDirectoryServer> aDDirectoryServerFactory = new ADDirectoryServerFactory <ADDirectoryServer>(); aDDirectoryServerFactory.SetCmdletSessionInfo(cmdletSessionInfo); ADObject directoryObjectFromIdentity = aDDirectoryServerFactory.GetDirectoryObjectFromIdentity(this._identityDSObj, cmdletSessionInfo.DefaultPartitionPath); string distinguishedName = directoryObjectFromIdentity.DistinguishedName; ADObjectSearcher aDObjectSearcher = SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, distinguishedName, ADSearchScope.Base); using (aDObjectSearcher) { aDObjectSearcher.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Like, "objectClass", "*"); aDObjectSearcher.Properties.Add("dNSHostName"); directoryObjectFromIdentity = aDObjectSearcher.FindOne(); if (directoryObjectFromIdentity != null) { if (directoryObjectFromIdentity["dNSHostName"] == null) { value = null; } else { value = (string)directoryObjectFromIdentity["dNSHostName"].Value; } string str1 = value; if (!string.IsNullOrEmpty(str1)) { if (cmdletSessionInfo.ConnectedADServerType == ADServerType.ADLDS) { string str2 = string.Concat("CN=NTDS Settings,", distinguishedName); ADObjectSearcher aDObjectSearcher1 = SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, str2, ADSearchScope.Base); using (aDObjectSearcher1) { aDObjectSearcher1.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Like, "objectClass", "*"); aDObjectSearcher1.Properties.Add("msDS-PortLDAP"); aDObject = aDObjectSearcher1.FindOne(); } if (aDObject != null) { if (aDObject["msDS-PortLDAP"] == null) { int?nullable1 = null; nullable = nullable1; } else { nullable = (int?)aDObject["msDS-PortLDAP"].Value; } int?nullable2 = nullable; if (nullable2.HasValue) { str1 = string.Concat(str1, ":", nullable2); } else { object[] objArray = new object[2]; objArray[0] = "msDS-PortLDAP"; objArray[1] = aDObject.DistinguishedName; throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.AttributeNotFoundOnObject, objArray)); } } else { throw new ADIdentityNotFoundException(string.Concat(StringResources.ObjectNotFound, " : ", str2)); } } ADSessionInfo aDSessionInfo = cmdletSessionInfo.ADSessionInfo.Copy(); aDSessionInfo.Server = str1; using (ADTopologyManagement aDTopologyManagement = new ADTopologyManagement(aDSessionInfo)) { ADOperationMasterRole[] aDOperationMasterRoleArray1 = this._operationMasterRolesToTransfer; for (int j = 0; j < (int)aDOperationMasterRoleArray1.Length; j++) { ADOperationMasterRole aDOperationMasterRole2 = aDOperationMasterRoleArray1[j]; string str3 = string.Format(CultureInfo.CurrentCulture, StringResources.MoveOperationMasterRoleDescription, new object[0]); object[] objArray1 = new object[2]; objArray1[0] = aDOperationMasterRole2.ToString(); objArray1[1] = str1; string str4 = string.Format(CultureInfo.CurrentCulture, StringResources.MoveOperationMasterRoleWarning, objArray1); string str5 = string.Format(CultureInfo.CurrentCulture, StringResources.MoveOperationMasterRoleCaption, new object[0]); if (base.ShouldProcessOverride(str3, str4, str5)) { aDTopologyManagement.MoveOperationMasterRole(aDOperationMasterRole2, this._seize, out flag); } } } } else { object[] distinguishedName1 = new object[2]; distinguishedName1[0] = "dNSHostName"; distinguishedName1[1] = directoryObjectFromIdentity.DistinguishedName; throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.AttributeNotFoundOnObject, distinguishedName1)); } } else { throw new ADIdentityNotFoundException(string.Concat(StringResources.ObjectNotFound, " : ", distinguishedName)); } } return(true); }
internal override T GetExtendedObjectFromIdentity(T identityObj, string identityQueryPath, ICollection <string> propertiesToFetch, bool showDeleted) { AttributeSetRequest attributeSetRequest; string distinguishedName; ADObject domain; if (!identityObj.IsSearchResult) { ADObject aDObject = identityObj; if (aDObject != null) { if (base.CmdletSessionInfo != null) { attributeSetRequest = this.ConstructAttributeSetRequest(null); attributeSetRequest.DirectoryAttributes.Add("distinguishedName"); IADOPathNode aDOPathNode = this.BuildIdentityFilter(identityObj); IADOPathNode[] structuralObjectFilter = new IADOPathNode[2]; structuralObjectFilter[0] = aDOPathNode; structuralObjectFilter[1] = this.StructuralObjectFilter; aDOPathNode = ADOPathUtil.CreateAndClause(structuralObjectFilter); string str = identityQueryPath; ADSearchScope aDSearchScope = ADSearchScope.Subtree; bool flag = false; ADObjectSearcher aDObjectSearcher = SearchUtility.BuildSearcher(base.CmdletSessionInfo.ADSessionInfo, str, aDSearchScope, showDeleted); using (aDObjectSearcher) { aDObjectSearcher.Filter = aDOPathNode; aDObjectSearcher.Properties.AddRange(attributeSetRequest.DirectoryAttributes); DebugLogger.LogInfo(this._debugCategory, string.Format("ADFactory: GetExtendedObjectFromIdentity: Searching for identity using filter: {0} searchbase: {1} scope: {2}", aDObjectSearcher.Filter.GetLdapFilterString(), aDObjectSearcher.SearchRoot, aDObjectSearcher.Scope)); ADObject aDObject1 = aDObjectSearcher.FindOne(out flag); if (aDObject1 != null) { if (!flag) { distinguishedName = aDObject1.DistinguishedName; } else { throw new ADMultipleMatchingIdentitiesException(StringResources.MultipleMatches); } } else { DebugLogger.LogInfo(this._debugCategory, string.Format("ADFactory: GetExtendedObjectFromIdentity: Identity not found", new object[0])); object[] searchRoot = new object[2]; searchRoot[0] = identityObj.ToString(); searchRoot[1] = aDObjectSearcher.SearchRoot; throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.IdentityNotFound, searchRoot)); } } } else { throw new ArgumentNullException(StringResources.SessionRequired); } } else { object[] type = new object[2]; type[0] = "GetExtendedObjectFromIdentity"; type[1] = identityObj.GetType(); throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, StringResources.MethodNotSupportedForObjectType, type)); } } else { distinguishedName = identityObj.DistinguishedName; } if (string.Compare(distinguishedName, base.CmdletSessionInfo.ADRootDSE.DefaultNamingContext, StringComparison.OrdinalIgnoreCase) == 0) { using (ADTopologyManagement aDTopologyManagement = new ADTopologyManagement(base.CmdletSessionInfo.ADSessionInfo)) { domain = aDTopologyManagement.GetDomain(); } if (domain != null) { domain.SessionInfo = base.CmdletSessionInfo.ADSessionInfo; domain.IsSearchResult = true; attributeSetRequest = base.ConstructAttributeSetRequest(propertiesToFetch); return(this.Construct(domain, attributeSetRequest)); } else { DebugLogger.LogInfo(this._debugCategory, string.Format("GetExtendedObjectFromIdentity: No objects returned from custom action", new object[0])); throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.ObjectNotFound, new object[0])); } } else { throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.ObjectNotFound, new object[0])); } }
internal IEnumerable <T> GetAllDomainControllers(ICollection <string> propertiesToFetch) { IEnumerable <T> ts; string defaultNamingContext = base.CmdletSessionInfo.ADRootDSE.DefaultNamingContext; ADSearchScope aDSearchScope = ADSearchScope.Subtree; IADOPathNode aDOPathNode = ADDomainControllerFactory <T> ._domainControllerComputerObjectFilter; ADObjectSearcher aDObjectSearcher = SearchUtility.BuildSearcher(base.CmdletSessionInfo.ADSessionInfo, defaultNamingContext, aDSearchScope); using (aDObjectSearcher) { aDObjectSearcher.Filter = aDOPathNode; aDObjectSearcher.Properties.AddRange(ADDomainControllerFactory <T> ._domainControllerDefaultAttributes); List <ADObject> aDObjects = new List <ADObject>(); foreach (ADObject aDObject in aDObjectSearcher.FindAll()) { aDObjects.Add(aDObject); } if (aDObjects.Count != 0) { List <string> strs = new List <string>(); foreach (ADObject aDObject1 in aDObjects) { string value = aDObject1["serverReferenceBL"].Value as string; if (value == null) { DebugLogger.LogInfo("ADDomainControllerFactory", string.Format("Could not find property: {0} for identity: {1}", "serverReferenceBL", aDObject1.DistinguishedName)); } else { strs.Add(string.Concat("CN=NTDS Settings,", value)); } } if (strs.Count <= 0) { ts = null; } else { using (ADTopologyManagement aDTopologyManagement = new ADTopologyManagement(base.CmdletSessionInfo.ADSessionInfo)) { ADEntity[] domainController = aDTopologyManagement.GetDomainController(strs.ToArray()); if (domainController == null || (int)domainController.Length == 0) { ts = new List <T>(); } else { List <T> ts1 = new List <T>(); AttributeSetRequest attributeSetRequest = this.ConstructAttributeSetRequest(propertiesToFetch); ADEntity[] aDEntityArray = domainController; for (int i = 0; i < (int)aDEntityArray.Length; i++) { ADEntity aDEntity = aDEntityArray[i]; T aDSessionInfo = this.Construct(aDEntity, attributeSetRequest); aDSessionInfo.SessionInfo = base.CmdletSessionInfo.ADSessionInfo; ts1.Add(aDSessionInfo); } ts = ts1; } } } } else { ts = new List <T>(); } } return(ts); }
private bool ModifyADOptionalFeatureBaseProcessCSRoutine() { string distinguishedName; string str; string str1 = null; bool flag; if (this._cmdletParameters.Contains("Identity")) { ADOptionalFeature item = this._cmdletParameters["Identity"] as ADOptionalFeature; ADOptionalFeatureScope aDOptionalFeatureScope = (ADOptionalFeatureScope)this._cmdletParameters["Scope"]; ADEntity aDEntity = this._cmdletParameters["Target"] as ADEntity; this.SetPipelinedSessionInfo(item.SessionInfo); CmdletSessionInfo cmdletSessionInfo = this.GetCmdletSessionInfo(); this._factory.SetCmdletSessionInfo(cmdletSessionInfo); if (aDOptionalFeatureScope != ADOptionalFeatureScope.Domain) { if (aDOptionalFeatureScope != ADOptionalFeatureScope.ForestOrConfigurationSet) { distinguishedName = null; } else { string item1 = this._cmdletParameters["Server"] as string; ADRootDSE rootDSE = this.GetRootDSE(); if (rootDSE.ServerType != ADServerType.ADDS) { cmdletSessionInfo = this.GetCmdletSessionInfo(); ADObjectFactory <ADObject> aDObjectFactory = new ADObjectFactory <ADObject>(); aDObjectFactory.SetCmdletSessionInfo(cmdletSessionInfo); ADObject aDObject = new ADObject(); aDObject.Identity = aDEntity.Identity; ADObject directoryObjectFromIdentity = aDObjectFactory.GetDirectoryObjectFromIdentity(aDObject, rootDSE.ConfigurationNamingContext, false); string str2 = X500Path.StripX500Whitespace(directoryObjectFromIdentity.DistinguishedName); if (string.Compare(rootDSE.ConfigurationNamingContext, str2, StringComparison.InvariantCultureIgnoreCase) == 0) { distinguishedName = string.Concat("CN=Partitions,", directoryObjectFromIdentity.DistinguishedName); } else { object[] objArray = new object[1]; objArray[0] = aDEntity.Identity.ToString(); throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.ConfigSetNotFound, objArray)); } } else { ADRootDSE aDRootDSE = null; if (item1 != null) { aDRootDSE = rootDSE; } if (aDEntity as ADForest == null) { str = ADDomainUtil.DiscoverDCFromIdentity <ADForest>(aDEntity.Identity, out str1); } else { str = ADDomainUtil.DiscoverDCFromIdentity <ADForest>(aDEntity, out str1); } if (str != null) { ADSessionInfo sessionInfo = this.GetSessionInfo(); sessionInfo.Server = str1; this.SetPipelinedSessionInfo(sessionInfo); if (aDRootDSE != null) { ADRootDSE rootDSE1 = this.GetRootDSE(); if (rootDSE1.RootDomainNamingContext == aDRootDSE.RootDomainNamingContext) { sessionInfo.Server = item1; this.SetPipelinedSessionInfo(sessionInfo); } else { throw new ADIdentityNotFoundException(); } } base.TargetOperationMasterRole(ADOperationMasterRole.DomainNamingMaster); cmdletSessionInfo = this.GetCmdletSessionInfo(); this._factory.SetCmdletSessionInfo(cmdletSessionInfo); ADForestFactory <ADForest> aDForestFactory = new ADForestFactory <ADForest>(); aDForestFactory.SetCmdletSessionInfo(cmdletSessionInfo); ADForest aDForest = new ADForest(str1); ADObject directoryObjectFromIdentity1 = aDForestFactory.GetDirectoryObjectFromIdentity(aDForest, this.GetRootDSE().DefaultNamingContext, false); distinguishedName = directoryObjectFromIdentity1.DistinguishedName; } else { object[] defaultNamingContext = new object[2]; defaultNamingContext[0] = aDEntity.Identity.ToString(); defaultNamingContext[1] = this.GetRootDSE().DefaultNamingContext; throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.IdentityNotFound, defaultNamingContext)); } } } } else { ADDomainFactory <ADDomain> aDDomainFactory = new ADDomainFactory <ADDomain>(); aDDomainFactory.SetCmdletSessionInfo(cmdletSessionInfo); ADDomain aDDomain = new ADDomain(); if (aDEntity as ADObject == null) { aDDomain = new ADDomain(aDEntity.Identity as string); } else { aDDomain.Identity = aDEntity; } ADObject aDObject1 = aDDomainFactory.GetDirectoryObjectFromIdentity(aDDomain, this.GetRootDSE().DefaultNamingContext, false); distinguishedName = aDObject1.DistinguishedName; } this.ValidateParameters(); item = this._factory.GetExtendedObjectFromIdentity(item, this.GetDefaultPartitionPath(), null, false); Guid? featureGUID = item.FeatureGUID; string str3 = featureGUID.ToString(); if (this._action != ModifyADOptionalFeatureBase <P> .ModifyADOptionalFeatureAction.Enable) { if (this._action != ModifyADOptionalFeatureBase <P> .ModifyADOptionalFeatureAction.Disable) { throw new NotImplementedException(this._action.ToString()); } else { flag = false; } } else { if (!item.IsDisableable) { base.WriteWarning(string.Format(StringResources.EnablingIsIrreversible, item.Name, distinguishedName)); } flag = true; } if (base.ShouldProcessOverride(item.Name, this._action.ToString())) { using (ADTopologyManagement aDTopologyManagement = new ADTopologyManagement(cmdletSessionInfo.ADSessionInfo)) { aDTopologyManagement.ChangeOptionalFeature(distinguishedName, flag, str3); } return(true); } else { return(false); } } else { object[] objArray1 = new object[1]; objArray1[0] = "Identity,Instance"; throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.ParameterRequiredMultiple, objArray1)); } }