コード例 #1
0
        internal override T GetExtendedObjectFromIdentity(T identityObj, string identityQueryPath, ICollection <string> propertiesToFetch, bool showDeleted)
        {
            AttributeSetRequest attributeSetRequest;
            string   distinguishedName;
            ADObject domain;

            if (!identityObj.IsSearchResult)
            {
                ADObject aDObject = identityObj;
                if (aDObject != null)
                {
                    if (base.CmdletSessionInfo != null)
                    {
                        attributeSetRequest = this.ConstructAttributeSetRequest(null);
                        attributeSetRequest.DirectoryAttributes.Add("distinguishedName");
                        IADOPathNode   aDOPathNode            = this.BuildIdentityFilter(identityObj);
                        IADOPathNode[] structuralObjectFilter = new IADOPathNode[2];
                        structuralObjectFilter[0] = aDOPathNode;
                        structuralObjectFilter[1] = this.StructuralObjectFilter;
                        aDOPathNode = ADOPathUtil.CreateAndClause(structuralObjectFilter);
                        string           str              = identityQueryPath;
                        ADSearchScope    aDSearchScope    = ADSearchScope.Subtree;
                        bool             flag             = false;
                        ADObjectSearcher aDObjectSearcher = SearchUtility.BuildSearcher(base.CmdletSessionInfo.ADSessionInfo, str, aDSearchScope, showDeleted);
                        using (aDObjectSearcher)
                        {
                            aDObjectSearcher.Filter = aDOPathNode;
                            aDObjectSearcher.Properties.AddRange(attributeSetRequest.DirectoryAttributes);
                            DebugLogger.LogInfo(this._debugCategory, string.Format("ADFactory: GetExtendedObjectFromIdentity: Searching for identity using filter: {0} searchbase: {1} scope: {2}", aDObjectSearcher.Filter.GetLdapFilterString(), aDObjectSearcher.SearchRoot, aDObjectSearcher.Scope));
                            ADObject aDObject1 = aDObjectSearcher.FindOne(out flag);
                            if (aDObject1 != null)
                            {
                                if (!flag)
                                {
                                    distinguishedName = aDObject1.DistinguishedName;
                                }
                                else
                                {
                                    throw new ADMultipleMatchingIdentitiesException(StringResources.MultipleMatches);
                                }
                            }
                            else
                            {
                                DebugLogger.LogInfo(this._debugCategory, string.Format("ADFactory: GetExtendedObjectFromIdentity: Identity not found", new object[0]));
                                object[] searchRoot = new object[2];
                                searchRoot[0] = identityObj.ToString();
                                searchRoot[1] = aDObjectSearcher.SearchRoot;
                                throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.IdentityNotFound, searchRoot));
                            }
                        }
                    }
                    else
                    {
                        throw new ArgumentNullException(StringResources.SessionRequired);
                    }
                }
                else
                {
                    object[] type = new object[2];
                    type[0] = "GetExtendedObjectFromIdentity";
                    type[1] = identityObj.GetType();
                    throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, StringResources.MethodNotSupportedForObjectType, type));
                }
            }
            else
            {
                distinguishedName = identityObj.DistinguishedName;
            }
            if (string.Compare(distinguishedName, base.CmdletSessionInfo.ADRootDSE.DefaultNamingContext, StringComparison.OrdinalIgnoreCase) == 0)
            {
                using (ADTopologyManagement aDTopologyManagement = new ADTopologyManagement(base.CmdletSessionInfo.ADSessionInfo))
                {
                    domain = aDTopologyManagement.GetDomain();
                }
                if (domain != null)
                {
                    domain.SessionInfo    = base.CmdletSessionInfo.ADSessionInfo;
                    domain.IsSearchResult = true;
                    attributeSetRequest   = base.ConstructAttributeSetRequest(propertiesToFetch);
                    return(this.Construct(domain, attributeSetRequest));
                }
                else
                {
                    DebugLogger.LogInfo(this._debugCategory, string.Format("GetExtendedObjectFromIdentity: No objects returned from custom action", new object[0]));
                    throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.ObjectNotFound, new object[0]));
                }
            }
            else
            {
                throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.ObjectNotFound, new object[0]));
            }
        }
コード例 #2
0
        private bool MoveADDSOperationMasterRoleProcessCSRoutine()
        {
            ADObject aDObject;
            bool     flag = false;
            string   value;
            int?     nullable;

            this._identityDSObj = this._cmdletParameters["Identity"] as ADDirectoryServer;
            this._seize         = this._cmdletParameters.GetSwitchParameterBooleanValue("Force");
            this._operationMasterRolesToTransfer = this._cmdletParameters["OperationMasterRole"] as ADOperationMasterRole[];
            base.SetPipelinedSessionInfo(this._identityDSObj.SessionInfo);
            CmdletSessionInfo cmdletSessionInfo = this.GetCmdletSessionInfo();

            if (cmdletSessionInfo.ConnectedADServerType == ADServerType.ADLDS)
            {
                ADOperationMasterRole[] aDOperationMasterRoleArray = this._operationMasterRolesToTransfer;
                for (int i = 0; i < (int)aDOperationMasterRoleArray.Length; i++)
                {
                    ADOperationMasterRole aDOperationMasterRole  = aDOperationMasterRoleArray[i];
                    ADOperationMasterRole aDOperationMasterRole1 = aDOperationMasterRole;
                    switch (aDOperationMasterRole1)
                    {
                    case ADOperationMasterRole.PDCEmulator:
                    case ADOperationMasterRole.RIDMaster:
                    case ADOperationMasterRole.InfrastructureMaster:
                    {
                        object[] str = new object[1];
                        str[0] = aDOperationMasterRole.ToString();
                        throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.MoveOperationMasterRoleNotApplicableForADLDS, str));
                    }
                    }
                }
            }
            ADDirectoryServerFactory <ADDirectoryServer> aDDirectoryServerFactory = new ADDirectoryServerFactory <ADDirectoryServer>();

            aDDirectoryServerFactory.SetCmdletSessionInfo(cmdletSessionInfo);
            ADObject         directoryObjectFromIdentity = aDDirectoryServerFactory.GetDirectoryObjectFromIdentity(this._identityDSObj, cmdletSessionInfo.DefaultPartitionPath);
            string           distinguishedName           = directoryObjectFromIdentity.DistinguishedName;
            ADObjectSearcher aDObjectSearcher            = SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, distinguishedName, ADSearchScope.Base);

            using (aDObjectSearcher)
            {
                aDObjectSearcher.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Like, "objectClass", "*");
                aDObjectSearcher.Properties.Add("dNSHostName");
                directoryObjectFromIdentity = aDObjectSearcher.FindOne();
                if (directoryObjectFromIdentity != null)
                {
                    if (directoryObjectFromIdentity["dNSHostName"] == null)
                    {
                        value = null;
                    }
                    else
                    {
                        value = (string)directoryObjectFromIdentity["dNSHostName"].Value;
                    }
                    string str1 = value;
                    if (!string.IsNullOrEmpty(str1))
                    {
                        if (cmdletSessionInfo.ConnectedADServerType == ADServerType.ADLDS)
                        {
                            string           str2 = string.Concat("CN=NTDS Settings,", distinguishedName);
                            ADObjectSearcher aDObjectSearcher1 = SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, str2, ADSearchScope.Base);
                            using (aDObjectSearcher1)
                            {
                                aDObjectSearcher1.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Like, "objectClass", "*");
                                aDObjectSearcher1.Properties.Add("msDS-PortLDAP");
                                aDObject = aDObjectSearcher1.FindOne();
                            }
                            if (aDObject != null)
                            {
                                if (aDObject["msDS-PortLDAP"] == null)
                                {
                                    int?nullable1 = null;
                                    nullable = nullable1;
                                }
                                else
                                {
                                    nullable = (int?)aDObject["msDS-PortLDAP"].Value;
                                }
                                int?nullable2 = nullable;
                                if (nullable2.HasValue)
                                {
                                    str1 = string.Concat(str1, ":", nullable2);
                                }
                                else
                                {
                                    object[] objArray = new object[2];
                                    objArray[0] = "msDS-PortLDAP";
                                    objArray[1] = aDObject.DistinguishedName;
                                    throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.AttributeNotFoundOnObject, objArray));
                                }
                            }
                            else
                            {
                                throw new ADIdentityNotFoundException(string.Concat(StringResources.ObjectNotFound, " : ", str2));
                            }
                        }
                        ADSessionInfo aDSessionInfo = cmdletSessionInfo.ADSessionInfo.Copy();
                        aDSessionInfo.Server = str1;
                        using (ADTopologyManagement aDTopologyManagement = new ADTopologyManagement(aDSessionInfo))
                        {
                            ADOperationMasterRole[] aDOperationMasterRoleArray1 = this._operationMasterRolesToTransfer;
                            for (int j = 0; j < (int)aDOperationMasterRoleArray1.Length; j++)
                            {
                                ADOperationMasterRole aDOperationMasterRole2 = aDOperationMasterRoleArray1[j];
                                string   str3      = string.Format(CultureInfo.CurrentCulture, StringResources.MoveOperationMasterRoleDescription, new object[0]);
                                object[] objArray1 = new object[2];
                                objArray1[0] = aDOperationMasterRole2.ToString();
                                objArray1[1] = str1;
                                string str4 = string.Format(CultureInfo.CurrentCulture, StringResources.MoveOperationMasterRoleWarning, objArray1);
                                string str5 = string.Format(CultureInfo.CurrentCulture, StringResources.MoveOperationMasterRoleCaption, new object[0]);
                                if (base.ShouldProcessOverride(str3, str4, str5))
                                {
                                    aDTopologyManagement.MoveOperationMasterRole(aDOperationMasterRole2, this._seize, out flag);
                                }
                            }
                        }
                    }
                    else
                    {
                        object[] distinguishedName1 = new object[2];
                        distinguishedName1[0] = "dNSHostName";
                        distinguishedName1[1] = directoryObjectFromIdentity.DistinguishedName;
                        throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.AttributeNotFoundOnObject, distinguishedName1));
                    }
                }
                else
                {
                    throw new ADIdentityNotFoundException(string.Concat(StringResources.ObjectNotFound, " : ", distinguishedName));
                }
            }
            return(true);
        }
コード例 #3
0
        internal ADObject GetDirectoryObjectFromIdentity(T identityObj, string searchRoot, ICollection <string> propertiesToFetch)
        {
            ADObject         aDObject  = null;
            ADObject         aDObject1 = null;
            ADObject         aDObject2 = null;
            HashSet <string> strs      = new HashSet <string>(ADDomainControllerFactory <T> ._domainControllerDefaultAttributes, StringComparer.OrdinalIgnoreCase);

            if (propertiesToFetch != null)
            {
                strs.UnionWith(propertiesToFetch);
            }
            string[] strArrays = new string[strs.Count];
            strs.CopyTo(strArrays);
            string nTDSSettingsDN = base.ResolveIdentityToNTDSSettingsDN(identityObj, strArrays, true, out aDObject, out aDObject1, out aDObject2);

            if (nTDSSettingsDN != null)
            {
                ADObject aDSessionInfo = null;
                if (aDObject == null)
                {
                    string value = null;
                    if (aDObject1 == null)
                    {
                        string           str = nTDSSettingsDN.Substring("CN=NTDS Settings,".Length);
                        ADObjectSearcher aDObjectSearcher = SearchUtility.BuildSearcher(base.CmdletSessionInfo.ADSessionInfo, str, ADSearchScope.Base);
                        using (aDObjectSearcher)
                        {
                            aDObjectSearcher.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Like, "objectClass", "*");
                            string[] strArrays1 = new string[1];
                            strArrays1[0] = "serverReference";
                            aDObjectSearcher.Properties.AddRange(strArrays1);
                            ADObject aDObject3 = aDObjectSearcher.FindOne();
                            if (aDObject3 != null)
                            {
                                value = aDObject3["serverReference"].Value as string;
                            }
                        }
                    }
                    else
                    {
                        value = aDObject1["serverReference"].Value as string;
                    }
                    if (value != null)
                    {
                        ADObjectSearcher aDObjectSearcher1 = SearchUtility.BuildSearcher(base.CmdletSessionInfo.ADSessionInfo, value, ADSearchScope.Base);
                        using (aDObjectSearcher1)
                        {
                            aDObjectSearcher1.Filter = ADOPathUtil.CreateFilterClause(ADOperator.Like, "objectClass", "*");
                            aDObjectSearcher1.Properties.AddRange(strArrays);
                            aDSessionInfo = aDObjectSearcher1.FindOne();
                            if (aDSessionInfo == null)
                            {
                                DebugLogger.LogInfo("ADDomainControllerFactory", string.Format("GetDirectoryObjectFromIdentity: Identity not found. Filter used: {0}", value));
                                object[] objArray = new object[2];
                                objArray[0] = nTDSSettingsDN;
                                objArray[1] = aDObjectSearcher1.SearchRoot;
                                throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.IdentityNotFound, objArray));
                            }
                        }
                    }
                    else
                    {
                        object[] identity = new object[1];
                        identity[0] = identityObj.Identity;
                        throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.DirectoryServerNotFound, identity));
                    }
                }
                else
                {
                    aDSessionInfo = aDObject;
                }
                aDSessionInfo.TrackChanges = true;
                aDSessionInfo.SessionInfo  = base.CmdletSessionInfo.ADSessionInfo;
                return(aDSessionInfo);
            }
            else
            {
                DebugLogger.LogInfo("ADDomainControllerFactory", string.Format("GetDirectoryObjectFromIdentity: NTDS Settings DN for the given directory server identity not found", new object[0]));
                object[] identity1 = new object[1];
                identity1[0] = identityObj.Identity;
                throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.DirectoryServerNotFound, identity1));
            }
        }
コード例 #4
0
        internal IEnumerable <T> GetAllDomainControllers(ICollection <string> propertiesToFetch)
        {
            IEnumerable <T>  ts;
            string           defaultNamingContext = base.CmdletSessionInfo.ADRootDSE.DefaultNamingContext;
            ADSearchScope    aDSearchScope        = ADSearchScope.Subtree;
            IADOPathNode     aDOPathNode          = ADDomainControllerFactory <T> ._domainControllerComputerObjectFilter;
            ADObjectSearcher aDObjectSearcher     = SearchUtility.BuildSearcher(base.CmdletSessionInfo.ADSessionInfo, defaultNamingContext, aDSearchScope);

            using (aDObjectSearcher)
            {
                aDObjectSearcher.Filter = aDOPathNode;
                aDObjectSearcher.Properties.AddRange(ADDomainControllerFactory <T> ._domainControllerDefaultAttributes);
                List <ADObject> aDObjects = new List <ADObject>();
                foreach (ADObject aDObject in aDObjectSearcher.FindAll())
                {
                    aDObjects.Add(aDObject);
                }
                if (aDObjects.Count != 0)
                {
                    List <string> strs = new List <string>();
                    foreach (ADObject aDObject1 in aDObjects)
                    {
                        string value = aDObject1["serverReferenceBL"].Value as string;
                        if (value == null)
                        {
                            DebugLogger.LogInfo("ADDomainControllerFactory", string.Format("Could  not find property: {0} for identity: {1}", "serverReferenceBL", aDObject1.DistinguishedName));
                        }
                        else
                        {
                            strs.Add(string.Concat("CN=NTDS Settings,", value));
                        }
                    }
                    if (strs.Count <= 0)
                    {
                        ts = null;
                    }
                    else
                    {
                        using (ADTopologyManagement aDTopologyManagement = new ADTopologyManagement(base.CmdletSessionInfo.ADSessionInfo))
                        {
                            ADEntity[] domainController = aDTopologyManagement.GetDomainController(strs.ToArray());
                            if (domainController == null || (int)domainController.Length == 0)
                            {
                                ts = new List <T>();
                            }
                            else
                            {
                                List <T>            ts1 = new List <T>();
                                AttributeSetRequest attributeSetRequest = this.ConstructAttributeSetRequest(propertiesToFetch);
                                ADEntity[]          aDEntityArray       = domainController;
                                for (int i = 0; i < (int)aDEntityArray.Length; i++)
                                {
                                    ADEntity aDEntity      = aDEntityArray[i];
                                    T        aDSessionInfo = this.Construct(aDEntity, attributeSetRequest);
                                    aDSessionInfo.SessionInfo = base.CmdletSessionInfo.ADSessionInfo;
                                    ts1.Add(aDSessionInfo);
                                }
                                ts = ts1;
                            }
                        }
                    }
                }
                else
                {
                    ts = new List <T>();
                }
            }
            return(ts);
        }
コード例 #5
0
ファイル: ADFactoryUtil.cs プロジェクト: modulexcite/pash-1
        internal static ADObjectSearcher GetADObjectSearcherFromIdentity(ADEntity identityObj, string searchRoot, bool showDeleted, IADOPathNode structuralObjectFilter, IADOPathNode identityFilter, IdentityResolverDelegate[] identityResolvers, CmdletSessionInfo cmdletSessionInfo)
        {
            ADObjectSearcher identity    = null;
            IADOPathNode     aDOPathNode = null;
            bool             flag        = true;

            IdentityResolverDelegate[] identityResolverDelegateArray = identityResolvers;
            int num = 0;

            while (num < (int)identityResolverDelegateArray.Length)
            {
                IdentityResolverDelegate identityResolverDelegate = identityResolverDelegateArray[num];
                if (identityObj.Identity == null)
                {
                    identity = identityResolverDelegate(identityObj, searchRoot, cmdletSessionInfo, out flag);
                }
                else
                {
                    identity = identityResolverDelegate(identityObj.Identity, searchRoot, cmdletSessionInfo, out flag);
                }
                if (identity == null)
                {
                    num++;
                }
                else
                {
                    if (!flag)
                    {
                        aDOPathNode = structuralObjectFilter;
                        break;
                    }
                    else
                    {
                        IADOPathNode[] filter = new IADOPathNode[2];
                        filter[0]   = identity.Filter;
                        filter[1]   = structuralObjectFilter;
                        aDOPathNode = ADOPathUtil.CreateAndClause(filter);
                        break;
                    }
                }
            }
            if (identity == null)
            {
                if (searchRoot != null)
                {
                    if (identityFilter != null)
                    {
                        IADOPathNode[] aDOPathNodeArray = new IADOPathNode[2];
                        aDOPathNodeArray[0] = identityFilter;
                        aDOPathNodeArray[1] = structuralObjectFilter;
                        aDOPathNode         = ADOPathUtil.CreateAndClause(aDOPathNodeArray);
                        identity            = SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, searchRoot, ADSearchScope.Subtree);
                    }
                    else
                    {
                        object[] str = new object[2];
                        str[0] = identityObj.ToString();
                        str[1] = searchRoot;
                        throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.IdentityNotFound, str));
                    }
                }
                else
                {
                    throw new ADIdentityResolutionException(StringResources.IdentityResolutionPartitionRequired);
                }
            }
            identity.Filter      = aDOPathNode;
            identity.ShowDeleted = showDeleted;
            return(identity);
        }
コード例 #6
0
        internal static ADObjectSearcher BuildGuidBaseSearcher(Guid?guidObject, CmdletSessionInfo cmdletSessionInfo)
        {
            string str = string.Concat("<GUID=", guidObject, ">");

            return(SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, str, ADSearchScope.Base));
        }
コード例 #7
0
 internal static ADObjectSearcher BuildDNBaseSearcher(string DN, CmdletSessionInfo cmdletSessionInfo)
 {
     return(SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, DN, ADSearchScope.Base));
 }