internal virtual ADSessionInfo GetSessionInfo() { if (this._sessionInfo != null || !this.SessionSpecified() && this._pipelineSessionInfo != null) { if (this.SessionSpecified() || this._pipelineSessionInfo == null) { this.ApplyCmdletSessionOptions(this._sessionInfo); this.ConstructSessionCache(this._sessionInfo); return(this._sessionInfo); } else { this.ApplyCmdletSessionOptions(this._pipelineSessionInfo); this.ConstructSessionCache(this._pipelineSessionInfo); return(this._pipelineSessionInfo); } } else { this._sessionInfo = this.CreateSessionFromParameters(); this.ApplyCmdletSessionOptions(this._sessionInfo); this.ConstructSessionCache(this._sessionInfo); return(this._sessionInfo); } }
private void ConstructSessionCache(ADSessionInfo info) { if (this._cmdletCachedSession == null) { this._cmdletCachedSession = new SafeSessionCache(info); } }
internal override ADSessionInfo GetSessionInfo() { ADSessionInfo destination = base.GetSessionInfo().Copy(); destination.Server = this._cmdletParameters.Destination; return(destination); }
private void ApplyCmdletSessionOptions(ADSessionInfo sessionInfo) { if (this._cmdletSessionOptions != null) { this._cmdletSessionOptions.CopyValuesTo(sessionInfo.Options); } }
internal static ADSessionInfo GetCurrentDriveSessionInfo(SessionState sessionState) { ADSessionInfo aDSessionInfo = null; ADDriveInfo current = sessionState.Drive.Current as ADDriveInfo; if (current != null) { aDSessionInfo = current.SessionInfo.Copy(); } return(aDSessionInfo); }
internal static void PerformSetPassword(string partitionDN, ADObject directoryObj, SecureString newPassword) { ADSessionInfo sessionInfo = directoryObj.SessionInfo; using (ADAccountManagement aDAccountManagement = new ADAccountManagement(sessionInfo)) { IntPtr bSTR = Marshal.SecureStringToBSTR(newPassword); string stringUni = Marshal.PtrToStringUni(bSTR); aDAccountManagement.SetPassword(partitionDN, directoryObj.DistinguishedName, stringUni); } }
protected internal override string GenerateRDNPrefix(ADObjectFactory <ADObject> factory, ADParameterSet cmdletParameters, NewADObjectParameterSet dynamicParameters) { ADSessionInfo sessionInfo = this.GetSessionInfo(); ADSchemaUtil aDSchemaUtil = new ADSchemaUtil(sessionInfo); string rDNPrefix = aDSchemaUtil.GetRDNPrefix(dynamicParameters.Type); if (rDNPrefix == null) { rDNPrefix = factory.RDNPrefix; } return(rDNPrefix); }
internal virtual CmdletSessionInfo GetCmdletSessionInfo() { ADSessionInfo sessionInfo = this.GetSessionInfo(); this.ConstructSessionCache(this._sessionInfo); if (this._cachedCmdletSessionInfo == null || this._cachedCmdletSessionInfo.ADSessionInfo != sessionInfo) { sessionInfo.ServerType = this.GetConnectedStore(); this._cachedCmdletSessionInfo = new CmdletSessionInfo(sessionInfo, this.GetRootDSE(), this.GetDefaultQueryPath(), this.GetDefaultPartitionPath(), this.GetDefaultCreationPath(), sessionInfo.ServerType, this._cmdletSessionCache, this, this, this._cmdletParameters); } return(this._cachedCmdletSessionInfo); }
public CmdletSessionInfo(ADSessionInfo adSessionInfo, ADRootDSE adRootDse, string defaultQueryPath, string defaultPartitionPath, string defaultCreationPath, ADServerType connectedADServerType, IADCmdletCache cmdletSessionCache, IADCmdletMessageWriter cmdletMessageWriter, PSCmdlet psCmdlet, ADParameterSet cmdletParameters) { this._adSessionInfo = adSessionInfo; this._adRootDse = adRootDse; this._defaultQueryPath = defaultQueryPath; this._defaultPartitionPath = defaultPartitionPath; this._defaultCreationPath = defaultCreationPath; this._connectedADServerType = connectedADServerType; this._cmdletSessionCache = cmdletSessionCache; this._cmdletMessageWriter = cmdletMessageWriter; this._psCmdlet = psCmdlet; this._cmdletParameters = cmdletParameters; }
internal static ADObjectSearcher BuildSearcher(ADSessionInfo session, string searchRoot, ADSearchScope searchScope, bool showDeleted) { ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(session); aDObjectSearcher.PageSize = 0x100; aDObjectSearcher.SearchRoot = searchRoot; aDObjectSearcher.Scope = searchScope; if (showDeleted) { aDObjectSearcher.ShowDeleted = true; aDObjectSearcher.ShowDeactivatedLink = true; } return(aDObjectSearcher); }
protected internal virtual ADRootDSE GetRootDSE() { if (this._cachedRootDSE == null) { ADSessionInfo sessionInfo = this.GetSessionInfo(); using (ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(sessionInfo)) { this._cachedRootDSE = aDObjectSearcher.GetRootDSE(); this._cachedRootDSE.SessionInfo = sessionInfo; } this._connectedStore = new ADServerType?(Utils.ADServerTypeFromRootDSE(this._cachedRootDSE)); } return(this._cachedRootDSE); }
protected internal virtual bool SetFromIdentity(O identity) { bool flag; ADSessionInfo sessionInfo = base.GetSessionInfo(); string item = this._cmdletParameters["Partition"] as string; if (item == null) { item = this.GetDefaultPartitionPath(); if (item == null && !identity.IsSearchResult) { object[] objArray = new object[1]; objArray[0] = "Partition"; throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.ParameterRequired, objArray)); } } ADObject directoryObjectFromIdentity = this._factory.GetDirectoryObjectFromIdentity(identity, item); using (ADActiveObject aDActiveObject = new ADActiveObject(sessionInfo, directoryObjectFromIdentity)) { if (base.ShouldProcessOverride(directoryObjectFromIdentity.IdentifyingString, "Set")) { this._factory.UpdateFromParameters(this._cmdletParameters, this._cmdletParameters["Add"] as Hashtable, this._cmdletParameters["Replace"] as Hashtable, this._cmdletParameters["Remove"] as Hashtable, this._cmdletParameters["Clear"] as string[], directoryObjectFromIdentity); O o = default(O); this._factory.PreCommitProcesing(ADFactory <O> .DirectoryOperation.Update, o, this._cmdletParameters, directoryObjectFromIdentity); aDActiveObject.Update(); directoryObjectFromIdentity.TrackChanges = true; O o1 = default(O); if (this._factory.PostCommitProcesing(ADFactory <O> .DirectoryOperation.Update, o1, this._cmdletParameters, directoryObjectFromIdentity)) { aDActiveObject.Update(); } if (this._cmdletParameters.GetSwitchParameterBooleanValue("PassThru")) { O extendedObjectFromDN = this._factory.GetExtendedObjectFromDN(directoryObjectFromIdentity.DistinguishedName); base.WriteObject(extendedObjectFromDN); } return(true); } else { flag = true; } } return(flag); }
public static ADSessionInfo ConstructSessionFromIdentity <P, T>(ADCmdletBase <P> cmdletInstance, ADSessionInfo baseSessionInfo, bool ignoreNonDomainIdentity) where P : ADParameterSet, new() where T : ADEntity, new() { string str = null; string str1; string item = cmdletInstance._cmdletParameters["Server"] as string; object obj = cmdletInstance._cmdletParameters["Identity"]; if (item != null || obj == null) { return(baseSessionInfo); } else { if (((ADEntity)obj).Identity == null) { str1 = null; } else { str1 = ((ADEntity)obj).Identity.ToString(); } string str2 = str1; string str3 = ADDomainUtil.DiscoverDCFromIdentity <T>(obj, out str); if (str3 != null) { ADSessionInfo aDSessionInfo = baseSessionInfo.Copy(); aDSessionInfo.Server = str; return(aDSessionInfo); } else { if (!ignoreNonDomainIdentity) { ArgumentException argumentException = new ArgumentException(); argumentException.Data.Add("IdentityData", str2); throw argumentException; } else { return(baseSessionInfo); } } } }
private bool GetGroupMembershipProcessCSRoutine() { this._partitionPath = this._cmdletParameters["Partition"] as string; this._identityADPrincipal = this._cmdletParameters["Identity"] as ADPrincipal; base.SetPipelinedSessionInfo(this._identityADPrincipal.SessionInfo); CmdletSessionInfo cmdletSessionInfo = base.GetCmdletSessionInfo(); ADPrincipalFactory <ADPrincipal> aDPrincipalFactory = new ADPrincipalFactory <ADPrincipal>(); aDPrincipalFactory.SetCmdletSessionInfo(cmdletSessionInfo); this.ValidateParameters(); ADObject directoryObjectFromIdentity = aDPrincipalFactory.GetDirectoryObjectFromIdentity(this._identityADPrincipal, cmdletSessionInfo.DefaultPartitionPath); using (ADAccountManagement aDAccountManagement = new ADAccountManagement(cmdletSessionInfo.ADSessionInfo)) { if (!string.IsNullOrEmpty(this._resourceContextServer) && string.IsNullOrEmpty(this._resourceContextPartition)) { ADSessionInfo aDSessionInfo = cmdletSessionInfo.ADSessionInfo.Copy(); aDSessionInfo.Server = this._resourceContextServer; using (ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(aDSessionInfo)) { ADRootDSE rootDSE = aDObjectSearcher.GetRootDSE(); if (rootDSE.DefaultNamingContext != null) { this._resourceContextPartition = rootDSE.DefaultNamingContext; } else { object[] objArray = new object[1]; objArray[0] = "ResourceContextPartition"; base.ThrowTerminatingError(new ErrorRecord(new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.ParameterRequired, objArray)), "1", ErrorCategory.InvalidArgument, null)); } } } ADGroup[] principalGroupMembership = aDAccountManagement.GetPrincipalGroupMembership(cmdletSessionInfo.DefaultPartitionPath, directoryObjectFromIdentity.DistinguishedName, this._resourceContextServer, this._resourceContextPartition); ADGroup[] aDGroupArray = principalGroupMembership; for (int i = 0; i < (int)aDGroupArray.Length; i++) { ADGroup aDGroup = aDGroupArray[i]; base.WriteObject(aDGroup); } } return(true); }
internal static string GetWellKnownGuidDN(ADSessionInfo adSession, string partitionDN, string wellKnownGuid) { string distinguishedName; if (partitionDN != null) { ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(adSession); try { try { aDObjectSearcher.SearchRoot = string.Format("<WKGUID={0},{1}>", wellKnownGuid, partitionDN); aDObjectSearcher.Scope = ADSearchScope.Base; aDObjectSearcher.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Like, "objectClass", "*"); ADObject aDObject = aDObjectSearcher.FindOne(); if (aDObject == null) { distinguishedName = null; } else { distinguishedName = aDObject.DistinguishedName; } } catch (ADIdentityNotFoundException aDIdentityNotFoundException1) { ADIdentityNotFoundException aDIdentityNotFoundException = aDIdentityNotFoundException1; DebugLogger.LogError("Utils", string.Format("Error in searching for WKGUID {0}", aDIdentityNotFoundException.Message)); distinguishedName = null; } } finally { aDObjectSearcher.Dispose(); } return(distinguishedName); } else { return(null); } }
protected internal virtual string GenerateNewRDN(F factory, string newName, ADObject target) { string empty = string.Empty; if (target.Contains("objectClass")) { ADSessionInfo sessionInfo = this.GetSessionInfo(); ADSchemaUtil aDSchemaUtil = new ADSchemaUtil(sessionInfo); empty = aDSchemaUtil.GetRDNPrefix(target["objectClass"].Value as string); } if (!string.IsNullOrEmpty(newName)) { newName = Utils.EscapeDNComponent(newName); } if (!string.IsNullOrEmpty(empty)) { empty = string.Concat(empty, "=", newName); } return(empty); }
internal static string GetCurrentDriveLocation(SessionState sessionState, ADSessionInfo sessionInfo) { string str = null; ADDriveInfo current = sessionState.Drive.Current as ADDriveInfo; if (current != null) { string currentLocation = current.CurrentLocation; str = ADPathModule.MakePath(current.RootWithoutAbsolutePathToken, currentLocation, current.FormatType); if (current.FormatType == ADPathFormat.Canonical && str != string.Empty) { if (sessionInfo.Server != null) { //TODO: Review sessionInfo.Server; } str = ADPathModule.ConvertPath(sessionInfo, str, ADPathFormat.Canonical, ADPathFormat.X500); } } return(str); }
internal static bool IsStaleServerObject(ADSessionInfo sessionInfo, string serverObjectDN) { bool flag; if (serverObjectDN != null) { ADObjectSearcher aDObjectSearcher = SearchUtility.BuildSearcher(sessionInfo, serverObjectDN, ADSearchScope.OneLevel); using (aDObjectSearcher) { aDObjectSearcher.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "nTDSDSA"); ADObject aDObject = aDObjectSearcher.FindOne(); flag = aDObject == null; } return(flag); } else { throw new ArgumentNullException("serverObjectDN"); } }
public static string ConvertPath(ADSessionInfo sessionInfo, string path, ADPathFormat fromFormat, ADPathFormat toFormat) { string str; if (fromFormat != toFormat) { if (fromFormat == ADPathFormat.Canonical && !string.IsNullOrEmpty(path) && CanonicalPath.IndexOfFirstDelimiter(path) == -1) { path = string.Concat(path, "/"); } using (ADAccountManagement aDAccountManagement = new ADAccountManagement(sessionInfo)) { str = aDAccountManagement.TranslateName(path, fromFormat, toFormat); } return(str); } else { return(path); } }
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 ADSessionInfo CreateSessionFromParameters() { ADSessionInfo aDSessionInfo; AuthType authType; ADSessionInfo currentDriveSessionInfo = null; bool flag = ProviderUtils.IsCurrentDriveAD(base.SessionState); if (flag) { currentDriveSessionInfo = ProviderUtils.GetCurrentDriveSessionInfo(base.SessionState); } if (!this._cmdletParameters.Contains("Server")) { if (!flag) { string str = null; aDSessionInfo = new ADSessionInfo(str); } else { aDSessionInfo = currentDriveSessionInfo.Copy(); } } else { aDSessionInfo = new ADSessionInfo(this._cmdletParameters["Server"] as string); } if (!this._cmdletParameters.Contains("Credential")) { if (flag) { aDSessionInfo.Credential = currentDriveSessionInfo.Credential; } } else { aDSessionInfo.Credential = this._cmdletParameters["Credential"] as PSCredential; } if (!this._cmdletParameters.Contains("AuthType")) { if (flag) { aDSessionInfo.AuthType = currentDriveSessionInfo.AuthType; } } else { ADSessionInfo aDSessionInfo1 = aDSessionInfo; if (this.GetAuthType() == ADAuthType.Negotiate) { authType = AuthType.Negotiate; } else { authType = AuthType.Basic; } aDSessionInfo1.AuthType = authType; } if (flag) { aDSessionInfo.Timeout = currentDriveSessionInfo.Timeout; aDSessionInfo.Options = currentDriveSessionInfo.Options; } return(aDSessionInfo); }
private void SetDefaultSessionInfo(ADSessionInfo session) { this._sessionInfo = session; this._cachedRootDSE = null; }
internal static ADObjectSearcher BuildSearcher(ADSessionInfo session, string searchRoot, ADSearchScope searchScope) { return(SearchUtility.BuildSearcher(session, searchRoot, searchScope, false)); }
internal static void CheckIfObjectsRefersToSingleDirectoryServer(ADSessionInfo sessionInfo, ICollection <ADObject> objectList, bool checkForDCs, out string referredDirectoryServerDN, out ADObject computerObj, out ADObject serverObj, out ADObject ntdsDSAObj) { referredDirectoryServerDN = null; computerObj = null; serverObj = null; ntdsDSAObj = null; foreach (ADObject aDObject in objectList) { bool?nullable = aDObject.IsOfType("server"); if (!nullable.Value) { bool?nullable1 = aDObject.IsOfType("computer"); if (!nullable1.Value) { bool?nullable2 = aDObject.IsOfType("nTDSDSA"); if (!nullable2.Value) { object[] objectClass = new object[1]; objectClass[0] = aDObject.ObjectClass; DebugLogger.LogInfo("DirectoryServerUtil", string.Format(CultureInfo.CurrentCulture, "Unknown object of type: '{0}' found in directory server list", objectClass)); throw new NotSupportedException(string.Format(StringResources.UnsupportedObjectClass, aDObject.ObjectClass)); } else { if (ntdsDSAObj != null) { object[] objArray = new object[1]; objArray[0] = "nTDSDSA"; DebugLogger.LogInfo("DirectoryServerUtil", string.Format(CultureInfo.CurrentCulture, "Duplicate object of type: '{0}' found in directory server list", objArray)); throw new ADMultipleMatchingIdentitiesException(StringResources.MultipleMatches); } else { ntdsDSAObj = aDObject; } } } else { if (checkForDCs) { if (computerObj != null) { object[] objArray1 = new object[1]; objArray1[0] = "computer"; DebugLogger.LogInfo("DirectoryServerUtil", string.Format(CultureInfo.CurrentCulture, "Duplicate object of type: '{0}' found in directory server list", objArray1)); throw new ADMultipleMatchingIdentitiesException(StringResources.MultipleMatches); } else { computerObj = aDObject; } } else { object[] objectClass1 = new object[1]; objectClass1[0] = aDObject.ObjectClass; DebugLogger.LogInfo("DirectoryServerUtil", string.Format(CultureInfo.CurrentCulture, "Unknown object of type: '{0}' found in directory server list", objectClass1)); throw new NotSupportedException(string.Format(StringResources.UnsupportedObjectClass, aDObject.ObjectClass)); } } } else { if (serverObj != null) { if (!DirectoryServerUtil.IsStaleServerObject(sessionInfo, aDObject.DistinguishedName)) { object[] objArray2 = new object[1]; objArray2[0] = "server"; DebugLogger.LogInfo("DirectoryServerUtil", string.Format(CultureInfo.CurrentCulture, "Duplicate object of type: '{0}' found in directory server list", objArray2)); throw new ADMultipleMatchingIdentitiesException(StringResources.MultipleMatches); } else { object[] distinguishedName = new object[1]; distinguishedName[0] = aDObject.DistinguishedName; DebugLogger.LogInfo("DirectoryServerUtil", string.Format(CultureInfo.CurrentCulture, "Stale server object : '{0}' found in directory server list", distinguishedName)); } } else { if (DirectoryServerUtil.IsStaleServerObject(sessionInfo, aDObject.DistinguishedName)) { object[] distinguishedName1 = new object[1]; distinguishedName1[0] = aDObject.DistinguishedName; DebugLogger.LogInfo("DirectoryServerUtil", string.Format(CultureInfo.CurrentCulture, "Stale server object : '{0}' found in directory server list", distinguishedName1)); } else { serverObj = aDObject; } } } } if (computerObj != null) { referredDirectoryServerDN = computerObj["serverReferenceBL"].Value as string; } if (serverObj != null) { if (referredDirectoryServerDN == null || referredDirectoryServerDN.Equals(serverObj.DistinguishedName, StringComparison.OrdinalIgnoreCase)) { referredDirectoryServerDN = serverObj.DistinguishedName; } else { throw new ADMultipleMatchingIdentitiesException(StringResources.MultipleMatches); } } if (ntdsDSAObj != null) { string str = ntdsDSAObj.DistinguishedName.Substring("CN=NTDS Settings,".Length); if (referredDirectoryServerDN == null || referredDirectoryServerDN.Equals(str, StringComparison.OrdinalIgnoreCase)) { referredDirectoryServerDN = str; } else { throw new ADMultipleMatchingIdentitiesException(StringResources.MultipleMatches); } } }
public SafeSessionCache(ADSessionInfo info) { this._session = ADSession.ConstructSession(info); }
private bool ADTargetScopeEnumerationServerPreProcessTargetCSRoutine() { object baseObject; ADSessionInfo sessionInfo = this.GetSessionInfo(); string item = this._cmdletParameters["Server"] as string; object[] objArray = this._cmdletParameters["Target"] as object[]; for (int i = 0; i < (int)objArray.Length; i++) { object obj = objArray[i]; if (obj as PSObject == null) { baseObject = obj; } else { baseObject = ((PSObject)obj).BaseObject; } string str = baseObject as string; ADEntity aDEntity = baseObject as ADEntity; if (aDEntity == null) { ADScopeType?nullable = (ADScopeType?)(this._cmdletParameters["Scope"] as ADScopeType?); ADScopeType valueOrDefault = nullable.GetValueOrDefault(); if (nullable.HasValue) { switch (valueOrDefault) { case ADScopeType.Server: { this.AddSessionsMatchingServerName(str); break; } case ADScopeType.Domain: { if (item == null) { ADDiscoverableService[] aDDiscoverableServiceArray = new ADDiscoverableService[1]; aDDiscoverableServiceArray[0] = ADDiscoverableService.ADWS; ADMinimumDirectoryServiceVersion?nullable1 = null; ADEntity aDEntity1 = DomainControllerUtil.DiscoverDomainController(null, str, aDDiscoverableServiceArray, ADDiscoverDomainControllerOptions.ReturnDnsName, nullable1); this.SetPipelinedSessionInfo(new ADSessionInfo(aDEntity1["HostName"].Value as string)); } ADDomainFactory <ADDomain> aDDomainFactory = new ADDomainFactory <ADDomain>(); aDDomainFactory.SetCmdletSessionInfo(this.GetCmdletSessionInfo()); ADDomain extendedObjectFromIdentity = aDDomainFactory.GetExtendedObjectFromIdentity(new ADDomain(str), this.GetRootDSE().DefaultNamingContext); this.AddSessionsFromDomain(extendedObjectFromIdentity); if (item != null) { break; } this.SetPipelinedSessionInfo(sessionInfo); break; } case ADScopeType.Forest: { if (item != null) { ADForestFactory <ADForest> aDForestFactory = new ADForestFactory <ADForest>(); aDForestFactory.SetCmdletSessionInfo(this.GetCmdletSessionInfo()); try { aDForestFactory.GetDirectoryObjectFromIdentity(new ADForest(str), null); } catch (ADIdentityNotFoundException aDIdentityNotFoundException1) { ADIdentityNotFoundException aDIdentityNotFoundException = aDIdentityNotFoundException1; base.WriteError(this.ConstructErrorRecord(aDIdentityNotFoundException)); break; } } else { ADDiscoverableService[] aDDiscoverableServiceArray1 = new ADDiscoverableService[1]; aDDiscoverableServiceArray1[0] = ADDiscoverableService.ADWS; ADMinimumDirectoryServiceVersion?nullable2 = null; ADEntity aDEntity2 = DomainControllerUtil.DiscoverDomainController(null, str, aDDiscoverableServiceArray1, ADDiscoverDomainControllerOptions.ReturnDnsName, nullable2); this.SetPipelinedSessionInfo(new ADSessionInfo(aDEntity2["HostName"].Value as string)); } this.AddSessionsFromConnectedForest(); if (item != null) { break; } this.SetPipelinedSessionInfo(sessionInfo); break; } case ADScopeType.Site: { this.AddSessionsMatchingSiteName(str); break; } } } } else { if (aDEntity.IsSearchResult) { this.SetPipelinedSessionInfo(aDEntity.SessionInfo); if (aDEntity as ADForest == null) { if (aDEntity as ADDomain == null) { if (aDEntity as ADDirectoryServer == null) { if (aDEntity as ADReplicationSite == null) { object[] type = new object[2]; type[0] = aDEntity.GetType(); type[1] = "Target"; base.WriteErrorBuffered(this.ConstructErrorRecord(new ParameterBindingException(string.Format(CultureInfo.CurrentCulture, StringResources.UnsupportedParameterType, type)))); } else { ADReplicationSite aDReplicationSite = (ADReplicationSite)aDEntity; this.AddSessionFromSiteDN(aDReplicationSite.DistinguishedName); } } else { ADDirectoryServer aDDirectoryServer = (ADDirectoryServer)aDEntity; this._sessionPipe.AddLast(new ADSessionInfo(aDDirectoryServer["HostName"].Value as string)); } } else { ADDomain aDDomain = (ADDomain)aDEntity; this.AddSessionsFromDomain(aDDomain); } } else { this.AddSessionsFromConnectedForest(); } this.SetPipelinedSessionInfo(sessionInfo); } else { base.WriteErrorBuffered(this.ConstructErrorRecord(new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.OnlySearchResultsSupported, new object[0])))); } } } return(true); }
internal virtual void SetPipelinedSessionInfo(ADSessionInfo session) { this._pipelineSessionInfo = session; this._cachedRootDSE = null; }
internal virtual void OutputSearchResults(IADOPathNode filter) { string item; ADSessionInfo sessionInfo = base.GetSessionInfo(); int? nullable = (int?)this._cmdletParameters["ResultSetSize"]; int? nullable1 = null; ADSearchScope aDSearchScope = (ADSearchScope)this._cmdletParameters["SearchScope"]; bool flag = false; if (this._cmdletParameters.Contains("SearchBase")) { item = this._cmdletParameters["SearchBase"] as string; flag = true; } else { item = this.GetDefaultQueryPath(); } if (!flag || !(string.Empty == item) || sessionInfo.ConnectedToGC) { if (item == null || !sessionInfo.ConnectedToGC && item == string.Empty) { object[] objArray = new object[1]; objArray[0] = "SearchBase"; throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.ParameterRequired, objArray)); } else { if (this._cmdletParameters.Contains("ResultPageSize")) { nullable1 = new int?((int)this._cmdletParameters["ResultPageSize"]); } IEnumerable <O> extendedObjectFromFilter = this._factory.GetExtendedObjectFromFilter(filter, item, aDSearchScope, this._propertiesRequested, nullable, nullable1, this._showDeleted); if (extendedObjectFromFilter != null) { if (this._outputFilterFunction != null) { foreach (O o in extendedObjectFromFilter) { if (!this._outputFilterFunction(o)) { continue; } base.WriteObject(o); } } else { foreach (O o1 in extendedObjectFromFilter) { base.WriteObject(o1); } } } return; } } else { object[] objArray1 = new object[1]; objArray1[0] = "SearchBase"; throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.EmptySearchBaseNotSupported, objArray1)); } }
private bool ADMoveCmdletBaseProcessCSRoutine() { bool flag; O item = (O)this._cmdletParameters["Identity"]; this.SetPipelinedSessionInfo(item.SessionInfo); CmdletSessionInfo cmdletSessionInfo = this.GetCmdletSessionInfo(); this._factory.SetCmdletSessionInfo(cmdletSessionInfo); this.ValidateParameters(); string defaultPartitionPath = this.GetDefaultPartitionPath(); ADObject directoryObjectFromIdentity = this._factory.GetDirectoryObjectFromIdentity(item, defaultPartitionPath); using (ADActiveObject aDActiveObject = new ADActiveObject(cmdletSessionInfo.ADSessionInfo, directoryObjectFromIdentity)) { if (base.ShouldProcessOverride(directoryObjectFromIdentity.DistinguishedName, "Move")) { O o = default(O); if (this._factory.PreCommitProcesing(ADFactory <O> .DirectoryOperation.Move, o, this._cmdletParameters, directoryObjectFromIdentity)) { aDActiveObject.Update(); } string str = this._cmdletParameters["TargetPath"] as string; string childName = ADPathModule.GetChildName(directoryObjectFromIdentity.DistinguishedName, ADPathFormat.X500); string item1 = null; if (!this._cmdletParameters.Contains("TargetServer")) { aDActiveObject.Move(str, childName); } else { item1 = this._cmdletParameters["TargetServer"] as string; aDActiveObject.CrossDomainMove(str, childName, item1); } O o1 = default(O); this._factory.PostCommitProcesing(ADFactory <O> .DirectoryOperation.Move, o1, this._cmdletParameters, directoryObjectFromIdentity); if (this._cmdletParameters.GetSwitchParameterBooleanValue("PassThru")) { ADSessionInfo aDSessionInfo = cmdletSessionInfo.ADSessionInfo; if (this._cmdletParameters.Contains("TargetServer")) { aDSessionInfo.Server = item1; } string str1 = ADPathModule.MakePath(str, childName, ADPathFormat.X500); F f = Activator.CreateInstance <F>(); using (ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(aDSessionInfo)) { ADRootDSE rootDSE = aDObjectSearcher.GetRootDSE(); ADCmdletCache aDCmdletCache = new ADCmdletCache(); aDSessionInfo.ServerType = Utils.ADServerTypeFromRootDSE(rootDSE); CmdletSessionInfo cmdletSessionInfo1 = new CmdletSessionInfo(aDSessionInfo, rootDSE, rootDSE.DefaultNamingContext, rootDSE.DefaultNamingContext, rootDSE.DefaultNamingContext, aDSessionInfo.ServerType, aDCmdletCache, this, this, this._cmdletParameters); f.SetCmdletSessionInfo(cmdletSessionInfo1); O extendedObjectFromDN = this._factory.GetExtendedObjectFromDN(str1); base.WriteObject(extendedObjectFromDN); aDCmdletCache.Clear(); } } return(true); } else { flag = false; } } return(flag); }
private bool ADGetADTrustCmdletProcessInputObjectCSRoutine() { if (this._cmdletParameters.Contains("InputObject")) { object item = this._cmdletParameters["InputObject"]; if (item as PSObject != null) { item = ((PSObject)item).BaseObject; } ADEntity aDEntity = item as ADEntity; string str = item as string; if (aDEntity == null) { if (str == null) { object[] type = new object[2]; type[0] = item.GetType(); type[1] = "InputObject"; base.WriteErrorBuffered(this.ConstructErrorRecord(new ParameterBindingException(string.Format(CultureInfo.CurrentCulture, StringResources.UnsupportedParameterType, type)))); return(false); } else { this._cmdletParameters["Identity"] = new ADTrust(str); } } else { if (aDEntity.IsSearchResult) { if (aDEntity as ADForest != null || aDEntity as ADDomain != null || aDEntity as ADClaimTransformPolicy != null) { CmdletSessionInfo cmdletSessionInfo = this.GetCmdletSessionInfo(); ADTrustFactory <ADTrust> aDTrustFactory = new ADTrustFactory <ADTrust>(); IADOPathNode structuralObjectFilter = aDTrustFactory.StructuralObjectFilter; if (aDEntity as ADForest != null || aDEntity as ADDomain != null) { if (!this._cmdletParameters.Contains("Server")) { ADSessionInfo aDSessionInfo = new ADSessionInfo(aDEntity["Name"].Value as string); if (aDEntity as ADForest != null) { aDSessionInfo.SetDefaultPort(LdapConstants.LDAP_GC_PORT); } if (cmdletSessionInfo.ADSessionInfo != null) { aDSessionInfo.Credential = cmdletSessionInfo.ADSessionInfo.Credential; } cmdletSessionInfo.ADRootDSE = null; cmdletSessionInfo.ADSessionInfo = aDSessionInfo; using (ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(aDSessionInfo)) { cmdletSessionInfo.ADRootDSE = aDObjectSearcher.GetRootDSE(); cmdletSessionInfo.ADRootDSE.SessionInfo = aDSessionInfo; } this.SetPipelinedSessionInfo(aDSessionInfo); } else { base.WriteErrorBuffered(this.ConstructErrorRecord(new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.ServerParameterNotSupported, new object[0])))); return(false); } } else { IADOPathNode aDOPathNode = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "msDS-EgressClaimsTransformationPolicy", aDEntity["DistinguishedName"].Value as string); IADOPathNode aDOPathNode1 = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "msDS-IngressClaimsTransformationPolicy", aDEntity["DistinguishedName"].Value as string); IADOPathNode[] aDOPathNodeArray = new IADOPathNode[2]; aDOPathNodeArray[0] = aDOPathNode; aDOPathNodeArray[1] = aDOPathNode1; structuralObjectFilter = ADOPathUtil.CreateOrClause(aDOPathNodeArray); } base.BuildPropertySet(); this._factory.SetCmdletSessionInfo(cmdletSessionInfo); base.ValidateParameters(); base.OutputSearchResults(structuralObjectFilter); return(false); } else { if (aDEntity as ADTrust == null) { if (string.Compare(this._factory.StructuralObjectClass, aDEntity["ObjectClass"].Value as string, StringComparison.OrdinalIgnoreCase) == 0) { this._cmdletParameters["Identity"] = new ADTrust((string)aDEntity["DistinguishedName"].Value); } else { object[] objArray = new object[2]; objArray[0] = aDEntity.GetType(); objArray[1] = "InputObject"; base.WriteErrorBuffered(this.ConstructErrorRecord(new ParameterBindingException(string.Format(CultureInfo.CurrentCulture, StringResources.UnsupportedParameterType, objArray)))); return(false); } } else { this._cmdletParameters["Identity"] = (ADTrust)aDEntity; } } } else { base.WriteErrorBuffered(this.ConstructErrorRecord(new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.OnlySearchResultsSupported, new object[0])))); return(false); } } } return(true); }