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); } } } }
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); }