コード例 #1
0
        protected internal string ResolveIdentityToNTDSSettingsDN(T identityObj, ICollection <string> propertiesToFetch, bool checkForDCs, out ADObject computerObj, out ADObject serverObj, out ADObject ntdsDSAObj)
        {
            string str = null;
            string str1;

            computerObj = null;
            serverObj   = null;
            ntdsDSAObj  = null;
            HashSet <string> strs = new HashSet <string>(ADDirectoryServerFactory <T> ._directoryServerDefaultAttributes, StringComparer.OrdinalIgnoreCase);

            if (propertiesToFetch != null)
            {
                strs.UnionWith(propertiesToFetch);
            }
            string[] strArrays = new string[strs.Count];
            strs.CopyTo(strArrays);
            string        configurationNamingContext = base.CmdletSessionInfo.ADRootDSE.ConfigurationNamingContext;
            ADSearchScope aDSearchScope = ADSearchScope.Subtree;
            IADOPathNode  aDOPathNode   = this.BuildIdentityFilter(identityObj);

            IADOPathNode[] structuralObjectFilter = new IADOPathNode[2];
            structuralObjectFilter[0] = aDOPathNode;
            structuralObjectFilter[1] = this.StructuralObjectFilter;
            aDOPathNode = ADOPathUtil.CreateAndClause(structuralObjectFilter);
            ADObjectSearcher nullable = SearchUtility.BuildSearcher(base.CmdletSessionInfo.ADSessionInfo, configurationNamingContext, aDSearchScope);

            using (nullable)
            {
                nullable.Filter = aDOPathNode;
                nullable.Properties.AddRange(strArrays);
                if (checkForDCs)
                {
                    nullable.SearchOption = new SearchOption?(SearchOption.PhantomRoot);
                    nullable.SearchRoot   = string.Empty;
                }
                List <ADObject> aDObjects = new List <ADObject>();
                foreach (ADObject aDObject in nullable.FindAll())
                {
                    aDObjects.Add(aDObject);
                }
                if (aDObjects.Count != 0)
                {
                    DirectoryServerUtil.CheckIfObjectsRefersToSingleDirectoryServer(base.CmdletSessionInfo.ADSessionInfo, aDObjects, checkForDCs, out str, out computerObj, out serverObj, out ntdsDSAObj);
                    if (str == null)
                    {
                        str1 = null;
                    }
                    else
                    {
                        str1 = string.Concat("CN=NTDS Settings,", str);
                    }
                }
                else
                {
                    DebugLogger.LogInfo("ADDirectoryServerFactory", string.Format("Could  not find identity using the following filter: {0}", aDOPathNode.GetLdapFilterString()));
                    str1 = null;
                }
            }
            return(str1);
        }
コード例 #2
0
 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);
         }
     }
 }