Esempio n. 1
0
        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);
        }
        private bool GetADDCBeginDiscoverCSRoutine()
        {
            bool flag;

            if (base.ParameterSetName == "DiscoverByService")
            {
                ADDiscoverDomainControllerOptions aDDiscoverDomainControllerOption = ADDiscoverDomainControllerOptions.None;
                ADDiscoverableService[]           service = this._cmdletParameters.Service;
                ADMinimumDirectoryServiceVersion? item    = (ADMinimumDirectoryServiceVersion?)(this._cmdletParameters["MinimumDirectoryServiceVersion"] as ADMinimumDirectoryServiceVersion?);
                string str   = this._cmdletParameters["SiteName"] as string;
                string item1 = this._cmdletParameters["DomainName"] as string;
                if (this._cmdletParameters.GetSwitchParameterBooleanValue("NextClosestSite"))
                {
                    aDDiscoverDomainControllerOption = aDDiscoverDomainControllerOption | ADDiscoverDomainControllerOptions.TryNextClosestSite;
                }
                if (this._cmdletParameters.GetSwitchParameterBooleanValue("ForceDiscover"))
                {
                    aDDiscoverDomainControllerOption = aDDiscoverDomainControllerOption | ADDiscoverDomainControllerOptions.ForceDiscover;
                }
                if (this._cmdletParameters.GetSwitchParameterBooleanValue("AvoidSelf"))
                {
                    aDDiscoverDomainControllerOption = aDDiscoverDomainControllerOption | ADDiscoverDomainControllerOptions.AvoidSelf;
                }
                if (this._cmdletParameters.GetSwitchParameterBooleanValue("Writable"))
                {
                    aDDiscoverDomainControllerOption = aDDiscoverDomainControllerOption | ADDiscoverDomainControllerOptions.Writable;
                }
                try
                {
                    ADEntity aDEntity = DomainControllerUtil.DiscoverDomainController(str, item1, service, aDDiscoverDomainControllerOption | ADDiscoverDomainControllerOptions.ReturnDnsName, item);
                    try
                    {
                        ADDiscoverDomainControllerOptions aDDiscoverDomainControllerOption1 = aDDiscoverDomainControllerOption;
                        aDDiscoverDomainControllerOption1 = aDDiscoverDomainControllerOption1 & (ADDiscoverDomainControllerOptions.AvoidSelf | ADDiscoverDomainControllerOptions.TryNextClosestSite | ADDiscoverDomainControllerOptions.Writable | ADDiscoverDomainControllerOptions.ReturnDnsName | ADDiscoverDomainControllerOptions.ReturnFlatName);
                        ADEntity aDEntity1 = DomainControllerUtil.DiscoverDomainController(str, item1, service, aDDiscoverDomainControllerOption1 | ADDiscoverDomainControllerOptions.ReturnFlatName, item);
                        if (aDEntity.InternalProperties.Contains("DiscoveryInternalPropertyDCAddress") && aDEntity1.InternalProperties.Contains("DiscoveryInternalPropertyDCAddress") && string.Equals((string)aDEntity.InternalProperties["DiscoveryInternalPropertyDCAddress"].Value, (string)aDEntity1.InternalProperties["DiscoveryInternalPropertyDCAddress"].Value))
                        {
                            aDEntity.Add("Name", aDEntity1["Name"].Value);
                        }
                    }
                    catch (ADException aDException1)
                    {
                        ADException aDException = aDException1;
                        DebugLogger.LogError("GetADDomainController", aDException.ToString());
                    }
                    CmdletSessionInfo cmdletSessionInfo = new CmdletSessionInfo();
                    this._factory.SetCmdletSessionInfo(cmdletSessionInfo);
                    ADDomainController aDDomainController = this._factory.Construct(aDEntity, new AttributeSetRequest(true));
                    base.WriteObject(aDDomainController);
                    return(false);
                }
                catch (ADException aDException3)
                {
                    ADException aDException2 = aDException3;
                    int         errorCode    = aDException2.ErrorCode;
                    base.WriteError(new ErrorRecord(aDException2, string.Concat("GetADDomainController:BeginProcessingOverride:DiscoverDC:", errorCode.ToString()), ErrorCategory.ObjectNotFound, null));
                    flag = false;
                }
                return(flag);
            }
            else
            {
                return(true);
            }
        }
Esempio n. 3
0
        public static string DiscoverDCFromIdentity <T>(object identity, bool forceDiscover, out string domainDNSFromIdentity)
            where T : ADEntity, new()
        {
            string   str;
            ADEntity aDEntity;

            domainDNSFromIdentity = null;
            if (identity as T == null)
            {
                if (identity as string == null)
                {
                    str = identity.ToString();
                }
                else
                {
                    str = identity as string;
                }
            }
            else
            {
                T t = (T)identity;
                if (!t.IsSearchResult)
                {
                    if (t.Identity as ADDomain == null || !((ADDomain)t.Identity).IsSearchResult)
                    {
                        str = t.Identity.ToString();
                    }
                    else
                    {
                        str = ((ADDomain)t.Identity).DNSRoot;
                    }
                }
                else
                {
                    if ((object)t as ADDomain == null)
                    {
                        if ((object)t as ADForest == null)
                        {
                            str = t["Name"].Value as string;
                        }
                        else
                        {
                            str = t["RootDomain"].Value as string;
                        }
                    }
                    else
                    {
                        str = t["DNSRoot"].Value as string;
                    }
                }
            }
            ADDiscoverableService[] aDDiscoverableServiceArray = new ADDiscoverableService[1];
            aDDiscoverableServiceArray[0] = ADDiscoverableService.ADWS;
            try
            {
                if (!forceDiscover)
                {
                    aDEntity = DomainControllerUtil.DiscoverDomainController(null, str, aDDiscoverableServiceArray, ADDiscoverDomainControllerOptions.ReturnDnsName, new ADMinimumDirectoryServiceVersion?(ADMinimumDirectoryServiceVersion.Windows2000));
                }
                else
                {
                    aDEntity = DomainControllerUtil.DiscoverDomainController(null, str, aDDiscoverableServiceArray, ADDiscoverDomainControllerOptions.ForceDiscover | ADDiscoverDomainControllerOptions.ReturnDnsName, new ADMinimumDirectoryServiceVersion?(ADMinimumDirectoryServiceVersion.Windows2000));
                }
                if (aDEntity != null)
                {
                    domainDNSFromIdentity = str;
                    string value = (string)aDEntity["HostName"].Value;
                    return(value);
                }
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                DebugLogger.LogError("ADDomainUtil", string.Concat("DiscoverDCFromIdentity: ", exception.ToString()));
            }
            return(null);
        }