private IEnumerable <T> ApplyPartitionFilter(IEnumerable <T> objectList) { string[] item = base.CmdletSessionInfo.CmdletParameters["PartitionFilter"] as string[]; if (item == null) { string[] strArrays = new string[1]; strArrays[0] = "Default"; item = strArrays; } if (!item.Contains <string>("*")) { IEnumerable <string> strs = ADForestPartitionInfo.ConstructPartitionList(base.CmdletSessionInfo.ADRootDSE, item, false); List <T> ts = new List <T>(); foreach (T t in objectList) { if (!strs.Contains <string>(t.Partition)) { continue; } ts.Add(t); } return(ts); } else { return(objectList); } }
internal static string GetCurrentPartitionPath(SessionState sessionState) { ADRootDSE rootDSE; string str = null; ADDriveInfo current = sessionState.Drive.Current as ADDriveInfo; if (current != null) { using (ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(current.SessionInfo)) { rootDSE = aDObjectSearcher.GetRootDSE(); rootDSE.SessionInfo = current.SessionInfo; } string currentDriveLocation = ProviderUtils.GetCurrentDriveLocation(sessionState, current.SessionInfo); if (currentDriveLocation != string.Empty) { try { str = ADForestPartitionInfo.ExtractAndValidatePartitionInfo(rootDSE, currentDriveLocation); } catch (ArgumentException argumentException1) { ArgumentException argumentException = argumentException1; object[] objArray = new object[1]; objArray[0] = currentDriveLocation; throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.ProviderUtilInvalidDrivePath, objArray), argumentException); } } else { return(string.Empty); } } return(str); }
// Methods internal override void PerServerProcessRecord() { ADObjectFactory <ADObject> factory = new ADObjectFactory <ADObject>(); CmdletSessionInfo cmdletSessionInfo = this.GetCmdletSessionInfo(); factory.SetCmdletSessionInfo(cmdletSessionInfo); base._factory.SetCmdletSessionInfo(cmdletSessionInfo); string[] propertiesToFetch = new string[] { "msDS-NCReplCursors" }; string[] partitionList = base._cmdletParameters["PartitionFilter"] as string[]; if (partitionList == null) { partitionList = new string[] { "Default" }; } foreach (string str in ADForestPartitionInfo.ConstructPartitionList(cmdletSessionInfo.ADRootDSE, partitionList, false)) { ADObject identityObj = new ADObject(str); try { identityObj = factory.GetExtendedObjectFromIdentity(identityObj, cmdletSessionInfo.DefaultPartitionPath, propertiesToFetch); } catch (Exception exception) { if (!(exception is ADIdentityNotFoundException) && !(exception is ADReferralException)) { throw exception; } continue; } foreach (ADReplicationUpToDatenessVectorTable table in base._factory.GetExtendedObjectFromDirectoryObject(identityObj, "msDS-NCReplCursors", "DS_REPL_CURSOR")) { base.WriteObject(table); } } }
protected internal virtual string GetDefaultPartitionPath() { string item; string identifyingString = null; if (this._cmdletParameters.Contains("Partition")) { item = this._cmdletParameters["Partition"] as string; if (!string.IsNullOrEmpty(item)) { ADForestPartitionInfo.ValidatePartitionDN(this.GetRootDSE(), item); return(item); } } if (!this._cmdletParameters.Contains("Identity")) { if (this._cmdletParameters.Contains("Path")) { identifyingString = (string)this._cmdletParameters["Path"]; } } else { ADObject aDObject = this._cmdletParameters["Identity"] as ADObject; if (aDObject != null) { identifyingString = aDObject.IdentifyingString; } } if (identifyingString != null) { ADRootDSE rootDSE = this.GetRootDSE(); item = ADForestPartitionInfo.ExtractPartitionInfo(this.GetRootDSE(), identifyingString, false); if (item == null && rootDSE.SessionInfo.ConnectedToGC) { item = ADForestPartitionInfo.ExtractPartitionInfo(this.GetRootDSE(), identifyingString, true); } if (item != null) { return(item); } } if (!this._cmdletParameters.Contains("Server") && this._pipelineSessionInfo == null && ProviderUtils.IsCurrentDriveAD(base.SessionState)) { string currentPartitionPath = ProviderUtils.GetCurrentPartitionPath(base.SessionState); if (!string.IsNullOrEmpty(currentPartitionPath)) { return(currentPartitionPath); } } return(this.GetDefaultPartitionPathBase()); }
protected internal override string GetDefaultPartitionPath() { string item = this._cmdletParameters["SearchBase"] as string; if (string.IsNullOrEmpty(item)) { return(base.GetDefaultPartitionPath()); } else { return(ADForestPartitionInfo.ExtractAndValidatePartitionInfo(this.GetRootDSE(), item)); } }
internal static ADObject GetObjectFromIdentitySearcher(ADObjectSearcher searcher, ADEntity identityObj, string searchRoot, AttributeSetRequest attrs, CmdletSessionInfo cmdletSessionInfo, out string[] warningMessages) { ADObject aDObject; bool flag = false; warningMessages = new string[0]; using (searcher) { searcher.Properties.AddRange(attrs.DirectoryAttributes); DebugLogger.LogInfo("ADFactoryUtil", string.Format("GetObjectFromIdentity: Searching for identity using filter: {0} searchbase: {1}", searcher.Filter.GetLdapFilterString(), searcher.SearchRoot)); aDObject = searcher.FindOne(out flag); if (aDObject != null) { if (flag) { throw new ADMultipleMatchingIdentitiesException(StringResources.MultipleMatches); } } else { DebugLogger.LogInfo("ADFactoryUtil", string.Format("GetObjectFromIdentity: Identity not found.", new object[0])); object[] str = new object[2]; str[0] = identityObj.ToString(); str[1] = searchRoot; throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.IdentityNotFound, str)); } } string str1 = ADForestPartitionInfo.ExtractPartitionInfo(cmdletSessionInfo.ADRootDSE, aDObject.DistinguishedName, false); if (cmdletSessionInfo.CmdletParameters.Contains("Partition")) { string item = cmdletSessionInfo.CmdletParameters["Partition"] as string; if (!ADPathModule.ComparePath(item, str1, ADPathFormat.X500)) { string[] strArrays = new string[1]; object[] objArray = new object[3]; objArray[0] = identityObj.ToString(); objArray[1] = str1; objArray[2] = item; strArrays[0] = string.Format(CultureInfo.CurrentCulture, StringResources.IdentityInWrongPartition, objArray); warningMessages = strArrays; } } cmdletSessionInfo.DefaultPartitionPath = str1; return(aDObject); }
internal override void PerServerProcessRecord() { ADObjectFactory <ADObject> factory = new ADObjectFactory <ADObject>(); CmdletSessionInfo cmdletSessionInfo = this.GetCmdletSessionInfo(); factory.SetCmdletSessionInfo(cmdletSessionInfo); base._factory.SetCmdletSessionInfo(cmdletSessionInfo); string[] partitionList = base._cmdletParameters["PartitionFilter"] as string[]; if (partitionList == null) { partitionList = new string[] { "Default" }; } foreach (string str in ADForestPartitionInfo.ConstructPartitionList(cmdletSessionInfo.ADRootDSE, partitionList, false)) { ADObject identityObj = new ADObject(str); try { identityObj = factory.GetExtendedObjectFromIdentity(identityObj, cmdletSessionInfo.DefaultPartitionPath, this._propertiesRequested); } catch (Exception exception) { if (!(exception is ADIdentityNotFoundException) && !(exception is ADReferralException)) { throw exception; } continue; } if (this._propertiesRequested.Contains <string>("msDS-NCReplInboundNeighbors")) { foreach (ADReplicationPartnerMetadata metadata in base._factory.GetExtendedObjectFromDirectoryObject(identityObj, "msDS-NCReplInboundNeighbors", "DS_REPL_NEIGHBOR")) { base.WriteObject(metadata); } } if (this._propertiesRequested.Contains <string>("msDS-NCReplOutboundNeighbors")) { foreach (ADReplicationPartnerMetadata metadata2 in base._factory.GetExtendedObjectFromDirectoryObject(identityObj, "msDS-NCReplOutboundNeighbors", "DS_REPL_NEIGHBOR")) { base.WriteObject(metadata2); } } } }
private void ValidateMemberOfParameter() { ADGroup extendedObjectFromIdentity; if (!this._isMemberOfValidated) { this._validExtendedGroupPartitionPairList = new List <SetADPrincipalGroupMembership <P> .ADGroupPartitionDNPair>(); object item = this._cmdletParameters["MemberOf"]; ADPrincipal[] aDPrincipalArray = item as ADGroup[]; if (aDPrincipalArray == null) { ADGroup aDGroup = item as ADGroup; if (aDGroup != null) { ADGroup[] aDGroupArray = new ADGroup[1]; aDGroupArray[0] = aDGroup; aDPrincipalArray = aDGroupArray; } } if (aDPrincipalArray != null) { new Hashtable(); ADGroupFactory <ADGroup> aDGroupFactory = new ADGroupFactory <ADGroup>(); CmdletSessionInfo cmdletSessionInfo = base.GetCmdletSessionInfo(); aDGroupFactory.SetCmdletSessionInfo(cmdletSessionInfo); ADPrincipal[] aDPrincipalArray1 = aDPrincipalArray; for (int i = 0; i < (int)aDPrincipalArray1.Length; i++) { ADGroup aDGroup1 = (ADGroup)aDPrincipalArray1[i]; try { if (!aDGroup1.IsSearchResult) { extendedObjectFromIdentity = aDGroupFactory.GetExtendedObjectFromIdentity(aDGroup1, cmdletSessionInfo.DefaultPartitionPath); this._validExtendedGroupPartitionPairList.Add(new SetADPrincipalGroupMembership <P> .ADGroupPartitionDNPair(extendedObjectFromIdentity)); } else { extendedObjectFromIdentity = aDGroup1; using (ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(extendedObjectFromIdentity.SessionInfo)) { ADRootDSE rootDSE = aDObjectSearcher.GetRootDSE(); string str = ADForestPartitionInfo.ExtractAndValidatePartitionInfo(rootDSE, extendedObjectFromIdentity.DistinguishedName); this._validExtendedGroupPartitionPairList.Add(new SetADPrincipalGroupMembership <P> .ADGroupPartitionDNPair(extendedObjectFromIdentity, str)); } } } catch (ADIdentityNotFoundException aDIdentityNotFoundException1) { ADIdentityNotFoundException aDIdentityNotFoundException = aDIdentityNotFoundException1; DebugLogger.LogError("SetADPrincipalGroupMembership", aDIdentityNotFoundException.ToString()); base.ThrowTerminatingError(new ErrorRecord(aDIdentityNotFoundException, "SetADPrincipalGroupMembership:ValidateMemberOfParameter", ErrorCategory.ObjectNotFound, aDGroup1)); } } } this._isMemberOfValidated = true; return; } else { return; } }
internal static ADObjectSearcher DistinguishedNameIdentityResolver(object identityObject, string searchBase, CmdletSessionInfo cmdletSessionInfo, out bool useSearchFilter) { useSearchFilter = false; if (identityObject != null) { string str = identityObject as string; if (string.IsNullOrEmpty(str) || !ADPathModule.IsValidPath(str, ADPathFormat.X500) || !ADForestPartitionInfo.IsDNUnderPartition(cmdletSessionInfo.ADRootDSE, str, false)) { ADObject aDObject = identityObject as ADObject; if (aDObject == null || string.IsNullOrEmpty(aDObject.DistinguishedName)) { return(null); } else { return(IdentityResolverMethods.BuildDNBaseSearcher(aDObject.DistinguishedName, cmdletSessionInfo)); } } else { return(IdentityResolverMethods.BuildDNBaseSearcher(str, cmdletSessionInfo)); } } else { throw new ArgumentNullException("identityObject"); } }