コード例 #1
0
ファイル: GetADForest.cs プロジェクト: modulexcite/pash-1
        private bool GetADForestCalculateIdentityCSRoutine()
        {
            bool   hasValue;
            bool   flag;
            string value = null;
            string item  = this._cmdletParameters["Server"] as string;
            ADCurrentForestType?nullable = (ADCurrentForestType?)(this._cmdletParameters["Current"] as ADCurrentForestType?);

            if (this._cmdletParameters["Identity"] == null)
            {
                if (!nullable.HasValue)
                {
                    if (item != null || ProviderUtils.IsCurrentDriveAD(base.SessionState))
                    {
                        ADRootDSE        rootDSE          = this.GetRootDSE();
                        string           str              = string.Concat("CN=Partitions,", rootDSE.ConfigurationNamingContext);
                        ADObjectSearcher aDObjectSearcher = SearchUtility.BuildSearcher(this.GetSessionInfo(), str, ADSearchScope.OneLevel);
                        using (aDObjectSearcher)
                        {
                            IADOPathNode[] aDOPathNodeArray = new IADOPathNode[2];
                            aDOPathNodeArray[0]     = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "crossRef");
                            aDOPathNodeArray[1]     = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "nCName", rootDSE.RootDomainNamingContext);
                            aDObjectSearcher.Filter = ADOPathUtil.CreateAndClause(aDOPathNodeArray);
                            aDObjectSearcher.Properties.Add("dnsRoot");
                            ADObject aDObject = aDObjectSearcher.FindOne();
                            if (aDObject != null)
                            {
                                value = aDObject["dnsRoot"].Value as string;
                            }
                            if (value == null)
                            {
                                object[] rootDomainNamingContext = new object[1];
                                rootDomainNamingContext[0] = rootDSE.RootDomainNamingContext;
                                throw new ADIdentityResolutionException(string.Format(CultureInfo.CurrentCulture, StringResources.CouldNotFindForestIdentity, rootDomainNamingContext));
                            }
                        }
                    }
                    else
                    {
                        nullable = new ADCurrentForestType?(ADCurrentForestType.LoggedOnUser);
                    }
                }
                ADCurrentForestType?nullable1 = nullable;
                if (nullable1.GetValueOrDefault() != ADCurrentForestType.LocalComputer)
                {
                    hasValue = false;
                }
                else
                {
                    hasValue = nullable1.HasValue;
                }
                if (!hasValue)
                {
                    ADCurrentForestType?nullable2 = nullable;
                    if (nullable2.GetValueOrDefault() != ADCurrentForestType.LoggedOnUser)
                    {
                        flag = false;
                    }
                    else
                    {
                        flag = nullable2.HasValue;
                    }
                    if (!flag)
                    {
                        if (nullable.HasValue)
                        {
                            throw new ArgumentException("Current");
                        }
                    }
                    else
                    {
                        value = base.EffectiveDomainName;
                    }
                }
                else
                {
                    SelectQuery selectQuery = new SelectQuery(WMIConstants.ComputerSystem);
                    ManagementObjectSearcher   managementObjectSearcher              = new ManagementObjectSearcher(selectQuery);
                    ManagementObjectCollection managementObjectCollections           = managementObjectSearcher.Get();
                    ManagementObjectCollection.ManagementObjectEnumerator enumerator = managementObjectCollections.GetEnumerator();
                    using (enumerator)
                    {
                        if (enumerator.MoveNext())
                        {
                            ManagementObject current = (ManagementObject)enumerator.Current;
                            value = current[WMIConstants.Domain] as string;
                        }
                    }
                    if (value == null)
                    {
                        throw new ArgumentException(StringResources.CouldNotDetermineLocalComputerDomain);
                    }
                }
                if (value != null)
                {
                    this._cmdletParameters["Identity"] = new ADForest(value);
                }
                return(true);
            }
            else
            {
                return(true);
            }
        }
コード例 #2
0
        private bool ADGetDomainCmdletBaseCalculateIdentityCSRoutine()
        {
            bool hasValue;
            bool flag;

            if (this._cmdletParameters["Identity"] == null)
            {
                string defaultNamingContext = null;
                string item = this._cmdletParameters["Server"] as string;
                ADCurrentDomainType?nullable = (ADCurrentDomainType?)(this._cmdletParameters["Current"] as ADCurrentDomainType?);
                if (!nullable.HasValue)
                {
                    if (item != null || ProviderUtils.IsCurrentDriveAD(base.SessionState))
                    {
                        ADRootDSE rootDSE = this.GetRootDSE();
                        defaultNamingContext = rootDSE.DefaultNamingContext;
                    }
                    else
                    {
                        nullable = new ADCurrentDomainType?(ADCurrentDomainType.LoggedOnUser);
                    }
                }
                ADCurrentDomainType?nullable1 = nullable;
                if (nullable1.GetValueOrDefault() != ADCurrentDomainType.LocalComputer)
                {
                    hasValue = false;
                }
                else
                {
                    hasValue = nullable1.HasValue;
                }
                if (!hasValue)
                {
                    ADCurrentDomainType?nullable2 = nullable;
                    if (nullable2.GetValueOrDefault() != ADCurrentDomainType.LoggedOnUser)
                    {
                        flag = false;
                    }
                    else
                    {
                        flag = nullable2.HasValue;
                    }
                    if (!flag)
                    {
                        if (nullable.HasValue)
                        {
                            throw new ArgumentException("Current");
                        }
                    }
                    else
                    {
                        defaultNamingContext = base.EffectiveDomainName;
                    }
                }
                else
                {
                    defaultNamingContext = ADDomainUtil.GetLocalComputerDomain();
                    if (defaultNamingContext == null)
                    {
                        throw new ArgumentException(StringResources.CouldNotDetermineLocalComputerDomain);
                    }
                }
                if (defaultNamingContext != null)
                {
                    this._cmdletParameters["Identity"] = this.ConstructObjectFromIdentity(defaultNamingContext);
                }
                return(true);
            }
            else
            {
                return(true);
            }
        }
コード例 #3
0
ファイル: ADCmdletBase`1.cs プロジェクト: modulexcite/pash-1
        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());
        }
コード例 #4
0
ファイル: ADCmdletBase`1.cs プロジェクト: modulexcite/pash-1
 protected internal virtual string GetDefaultQueryPath()
 {
     if (!this._cmdletParameters.Contains("Server") && this._pipelineSessionInfo == null && ProviderUtils.IsCurrentDriveAD(base.SessionState))
     {
         string currentDriveLocation = ProviderUtils.GetCurrentDriveLocation(base.SessionState, this.GetSessionInfo());
         if (this.GetSessionInfo().ConnectedToGC || !string.IsNullOrEmpty(currentDriveLocation))
         {
             return(currentDriveLocation);
         }
     }
     return(this.GetDefaultQueryPathBase());
 }
コード例 #5
0
ファイル: ADCmdletBase`1.cs プロジェクト: modulexcite/pash-1
        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);
        }