コード例 #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
        static ADServiceAccountFactory()
        {
            IADOPathNode[] aDOPathNodeArray  = new IADOPathNode[2];
            IADOPathNode[] aDOPathNodeArray1 = new IADOPathNode[2];
            aDOPathNodeArray1[0] = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "msDS-ManagedServiceAccount");
            aDOPathNodeArray1[1] = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectCategory", "msDS-ManagedServiceAccount");
            aDOPathNodeArray[0]  = ADOPathUtil.CreateAndClause(aDOPathNodeArray1);
            aDOPathNodeArray[1]  = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "msDS-GroupManagedServiceAccount");
            ADServiceAccountFactory <T> ._structuralObjectFilter = ADOPathUtil.CreateOrClause(aDOPathNodeArray);
            string[] strArrays = new string[1];
            strArrays[0] = "sAMAccountName";
            ADServiceAccountFactory <T> ._serviceAccountIdentityLdapAttributes = strArrays;
            IdentityResolverDelegate[] customIdentityResolver = new IdentityResolverDelegate[5];
            customIdentityResolver[0] = IdentityResolverMethods.GetCustomIdentityResolver(new IdentityResolverDelegate(IdentityResolverMethods.DistinguishedNameIdentityResolver));
            customIdentityResolver[1] = IdentityResolverMethods.GetCustomIdentityResolver(new IdentityResolverDelegate(IdentityResolverMethods.GuidIdentityResolver));
            customIdentityResolver[2] = IdentityResolverMethods.GetCustomIdentityResolver(new IdentityResolverDelegate(IdentityResolverMethods.SidIdentityResolver));
            customIdentityResolver[3] = IdentityResolverMethods.GetCustomIdentityResolver(new IdentityResolverDelegate(IdentityResolverMethods.SamAccountNameIdentityResolver));
            customIdentityResolver[4] = ADComputerUtil.GetGenericIdentityResolverWithSamName(ADServiceAccountFactory <T> ._serviceAccountIdentityLdapAttributes);
            ADServiceAccountFactory <T> ._identityResolvers = customIdentityResolver;
            AttributeConverterEntry[] attributeConverterEntry = new AttributeConverterEntry[5];
            attributeConverterEntry[0] = new AttributeConverterEntry(ADPrincipalFactory <T> .ADPrincipalPropertyMap.SamAccountName.PropertyName, ADPrincipalFactory <T> .ADPrincipalPropertyMap.SamAccountName.ADAttribute, TypeConstants.String, false, TypeAdapterAccess.ReadWrite, true, AttributeSet.Default, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(ADComputerUtil.ToDirectoryServiceAccountSamAccountName), new ToSearchFilterDelegate(ADComputerUtil.ToSearchComputerSamAccountName));
            attributeConverterEntry[1] = new AttributeConverterEntry(ADServiceAccountFactory <T> .ADServiceAccountPropertyMap.HostComputers.PropertyName, ADServiceAccountFactory <T> .ADServiceAccountPropertyMap.HostComputers.ADAttribute, TypeConstants.String, true, TypeAdapterAccess.Read, false, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedMultivalueObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryMultivalueObject), new ToSearchFilterDelegate(SearchConverters.ToSearchUsingSchemaInfo));
            attributeConverterEntry[2] = new AttributeConverterEntry(ADServiceAccountFactory <T> .ADServiceAccountPropertyMap.DNSHostName.PropertyName, ADServiceAccountFactory <T> .ADServiceAccountPropertyMap.DNSHostName.ADAttribute, TypeConstants.String, true, TypeAdapterAccess.ReadWrite, true, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchUsingSchemaInfo));
            attributeConverterEntry[3] = new AttributeConverterEntry(ADServiceAccountFactory <T> .ADServiceAccountPropertyMap.PrincipalsAllowedToRetrieveManagedPassword.PropertyName, ADServiceAccountFactory <T> .ADServiceAccountPropertyMap.PrincipalsAllowedToRetrieveManagedPassword.ADAttribute, TypeConstants.ADPrincipal, true, TypeAdapterAccess.ReadWrite, false, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedPrincipalFromSecDesc), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectorySecDescFromPrincipal), new ToSearchFilterDelegate(SearchConverters.ToSearchNotSupported));
            attributeConverterEntry[4] = new AttributeConverterEntry(ADServiceAccountFactory <T> .ADServiceAccountPropertyMap.ManagedPasswordIntervalInDays.PropertyName, ADServiceAccountFactory <T> .ADServiceAccountPropertyMap.ManagedPasswordIntervalInDays.ADAttribute, TypeConstants.Int, true, TypeAdapterAccess.ReadWrite, false, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchUsingSchemaInfo));
            ADServiceAccountFactory <T> .ADMappingTable = attributeConverterEntry;
            ADFactoryBase <T> .RegisterMappingTable(ADServiceAccountFactory <T> .ADMappingTable, ADServerType.ADDS);

            ADAccountFactory <T> .DefaultUserAccessControl      = 0x1002;
            ADAccountFactory <T> .UseComputerPasswordGeneration = true;
        }
コード例 #3
0
ファイル: ADDomainUtil.cs プロジェクト: modulexcite/pash-1
        public static string FindDomainNCHead(string identity, CmdletSessionInfo session)
        {
            ADObject aDObject;

            using (ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(session.ADSessionInfo))
            {
                aDObjectSearcher.SearchRoot = string.Concat("CN=Partitions,", session.ADRootDSE.ConfigurationNamingContext);
                aDObjectSearcher.Scope      = ADSearchScope.OneLevel;
                IADOPathNode[] aDOPathNodeArray = new IADOPathNode[3];
                aDOPathNodeArray[0] = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectCategory", "crossRef");
                aDOPathNodeArray[1] = ADOPathUtil.CreateFilterClause(ADOperator.Band, "systemFlags", 3);
                IADOPathNode[] aDOPathNodeArray1 = new IADOPathNode[3];
                aDOPathNodeArray1[0]    = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "nCName", identity);
                aDOPathNodeArray1[1]    = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "nETBIOSName", identity);
                aDOPathNodeArray1[2]    = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "dnsRoot", identity);
                aDOPathNodeArray[2]     = ADOPathUtil.CreateOrClause(aDOPathNodeArray1);
                aDObjectSearcher.Filter = ADOPathUtil.CreateAndClause(aDOPathNodeArray);
                aDObjectSearcher.Properties.Add("nCName");
                aDObject = aDObjectSearcher.FindOne();
            }
            if (aDObject != null)
            {
                return(aDObject.GetValue("nCName") as string);
            }
            else
            {
                return(null);
            }
        }
コード例 #4
0
 internal IADOPathNode AppendObjectClassFilter(IADOPathNode filter)
 {
     IADOPathNode[] structuralObjectFilter = new IADOPathNode[2];
     structuralObjectFilter[0] = filter;
     structuralObjectFilter[1] = this._factory.StructuralObjectFilter;
     return(ADOPathUtil.CreateAndClause(structuralObjectFilter));
 }
コード例 #5
0
 internal static void ToCompatibleResourceTypes(string extendedAttribute, string[] directoryAttributes, ADEntity userObj, ADEntity directoryObj, CmdletSessionInfo cmdletSessionInfo)
 {
     if (!directoryObj.Contains("msDS-ClaimValueType") || !directoryObj.Contains("msDS-ClaimIsValueSpaceRestricted"))
     {
         ADPropertyValueCollection aDPropertyValueCollection = new ADPropertyValueCollection(null);
         userObj.Add(extendedAttribute, aDPropertyValueCollection);
         return;
     }
     else
     {
         long           value            = (long)directoryObj["msDS-ClaimValueType"].Value;
         bool           flag             = directoryObj.Contains("msDS-ClaimPossibleValues");
         IADOPathNode   aDOPathNode      = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "msDS-ClaimValueType", value);
         IADOPathNode   aDOPathNode1     = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "msDS-IsPossibleValuesPresent", flag);
         IADOPathNode[] aDOPathNodeArray = new IADOPathNode[2];
         aDOPathNodeArray[0] = aDOPathNode;
         aDOPathNodeArray[1] = aDOPathNode1;
         IADOPathNode aDOPathNode2 = ADOPathUtil.CreateAndClause(aDOPathNodeArray);
         ADResourcePropertyValueTypeFactory <ADResourcePropertyValueType> aDResourcePropertyValueTypeFactory = new ADResourcePropertyValueTypeFactory <ADResourcePropertyValueType>();
         aDResourcePropertyValueTypeFactory.SetCmdletSessionInfo(cmdletSessionInfo);
         string str       = ADPathModule.MakePath(cmdletSessionInfo.ADRootDSE.ConfigurationNamingContext, "CN=Value Types,CN=Claims Configuration,CN=Services,", ADPathFormat.X500);
         int?   nullable  = null;
         int?   nullable1 = null;
         IEnumerable <ADResourcePropertyValueType> extendedObjectFromFilter = aDResourcePropertyValueTypeFactory.GetExtendedObjectFromFilter(aDOPathNode2, str, ADSearchScope.OneLevel, null, nullable, nullable1, false);
         List <string> strs = new List <string>();
         foreach (ADResourcePropertyValueType aDResourcePropertyValueType in extendedObjectFromFilter)
         {
             strs.Add(aDResourcePropertyValueType.Name);
         }
         userObj.Add(extendedAttribute, new ADPropertyValueCollection(strs));
         return;
     }
 }
コード例 #6
0
        private void ValidateIdentity(T identityObj)
        {
            string str;

            if (identityObj != null)
            {
                if (base.CmdletSessionInfo != null)
                {
                    if (!identityObj.IsSearchResult)
                    {
                        if (identityObj.Identity as ADDomain == null || !((ADDomain)identityObj.Identity).IsSearchResult)
                        {
                            str = identityObj.Identity.ToString();
                        }
                        else
                        {
                            str = ((ADDomain)identityObj.Identity).DNSRoot;
                        }
                    }
                    else
                    {
                        str = identityObj.Name;
                    }
                    ADRootDSE        aDRootDSE        = base.CmdletSessionInfo.ADRootDSE;
                    string           str1             = string.Concat("CN=Partitions,", aDRootDSE.ConfigurationNamingContext);
                    ADObjectSearcher aDObjectSearcher = SearchUtility.BuildSearcher(base.CmdletSessionInfo.ADSessionInfo, str1, ADSearchScope.OneLevel);
                    using (aDObjectSearcher)
                    {
                        IADOPathNode[] aDOPathNodeArray = new IADOPathNode[3];
                        aDOPathNodeArray[0] = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "crossRef");
                        IADOPathNode[] aDOPathNodeArray1 = new IADOPathNode[2];
                        aDOPathNodeArray1[0]    = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "dnsRoot", str);
                        aDOPathNodeArray1[1]    = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "nETBIOSName", str);
                        aDOPathNodeArray[1]     = ADOPathUtil.CreateOrClause(aDOPathNodeArray1);
                        aDOPathNodeArray[2]     = ADOPathUtil.CreateFilterClause(ADOperator.Band, "systemFlags", 3);
                        aDObjectSearcher.Filter = ADOPathUtil.CreateAndClause(aDOPathNodeArray);
                        ADObject aDObject = aDObjectSearcher.FindOne();
                        if (aDObject == null)
                        {
                            object[] objArray = new object[1];
                            objArray[0] = str;
                            throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.CouldNotFindForestIdentity, objArray));
                        }
                    }
                    return;
                }
                else
                {
                    throw new ArgumentNullException(StringResources.SessionRequired);
                }
            }
            else
            {
                object[] type = new object[2];
                type[0] = "ValidateIdentity";
                type[1] = identityObj.GetType();
                throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, StringResources.MethodNotSupportedForObjectType, type));
            }
        }
コード例 #7
0
        internal override T GetExtendedObjectFromIdentity(T identityObj, string identityQueryPath, ICollection <string> propertiesToFetch, bool showDeleted)
        {
            ADObject aDObject;
            ADDefaultDomainPasswordPolicy aDDefaultDomainPasswordPolicy = identityObj;

            if (aDDefaultDomainPasswordPolicy != null)
            {
                if (base.CmdletSessionInfo != null)
                {
                    AttributeSetRequest attributeSetRequest    = this.ConstructAttributeSetRequest(propertiesToFetch);
                    IADOPathNode[]      structuralObjectFilter = new IADOPathNode[2];
                    structuralObjectFilter[0] = this.StructuralObjectFilter;
                    structuralObjectFilter[1] = this.BuildIdentityFilter(identityObj);
                    IADOPathNode     aDOPathNode          = ADOPathUtil.CreateAndClause(structuralObjectFilter);
                    string           defaultNamingContext = base.CmdletSessionInfo.ADRootDSE.DefaultNamingContext;
                    ADSearchScope    aDSearchScope        = ADSearchScope.Base;
                    ADObjectSearcher aDObjectSearcher     = SearchUtility.BuildSearcher(base.CmdletSessionInfo.ADSessionInfo, defaultNamingContext, aDSearchScope, showDeleted);
                    using (aDObjectSearcher)
                    {
                        aDObjectSearcher.Filter = aDOPathNode;
                        aDObjectSearcher.Properties.AddRange(attributeSetRequest.DirectoryAttributes);
                        DebugLogger.LogInfo("ADDefaultDomainPasswordPolicyFactory", string.Format("ADFactory: GetExtendedObjectFromIdentity: Searching for identity using filter: {0} searchbase: {1} scope: {2}", aDObjectSearcher.Filter.GetLdapFilterString(), aDObjectSearcher.SearchRoot, aDObjectSearcher.Scope));
                        aDObject = aDObjectSearcher.FindOne();
                        if (aDObject == null)
                        {
                            DebugLogger.LogInfo("ADDefaultDomainPasswordPolicyFactory", string.Format("ADFactory: GetExtendedObjectFromIdentity: Identity not found", new object[0]));
                            object[] str = new object[2];
                            str[0] = identityObj.ToString();
                            str[1] = aDObjectSearcher.SearchRoot;
                            throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.IdentityNotFound, str));
                        }
                    }
                    T aDSessionInfo = this.Construct(aDObject, attributeSetRequest);
                    aDSessionInfo.SessionInfo = base.CmdletSessionInfo.ADSessionInfo;
                    return(aDSessionInfo);
                }
                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));
            }
        }
コード例 #8
0
 internal override IADOPathNode IdentitySearchConverter(object identity)
 {
     if (identity != null)
     {
         if ((int)this.IdentityLdapAttributes.Length <= 0)
         {
             return(null);
         }
         else
         {
             SecurityIdentifier securityIdentifier = identity as SecurityIdentifier;
             if (securityIdentifier == null)
             {
                 IADOPathNode aDOPathNode = base.IdentitySearchConverter(identity);
                 ADPrincipal  aDPrincipal = identity as ADPrincipal;
                 if (aDPrincipal == null)
                 {
                     return(aDOPathNode);
                 }
                 else
                 {
                     List <IADOPathNode> aDOPathNodes = new List <IADOPathNode>();
                     if (aDPrincipal.SamAccountName != null)
                     {
                         aDOPathNodes.Add(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "sAMAccountName", aDPrincipal.SamAccountName));
                     }
                     if (aDPrincipal.SID != null)
                     {
                         aDOPathNodes.Add(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectSid", aDPrincipal.SID));
                     }
                     aDOPathNodes.Add(aDOPathNode);
                     return(ADOPathUtil.CreateAndClause(aDOPathNodes.ToArray()));
                 }
             }
             else
             {
                 byte[] numArray = new byte[securityIdentifier.BinaryLength];
                 securityIdentifier.GetBinaryForm(numArray, 0);
                 return(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectSid", numArray));
             }
         }
     }
     else
     {
         throw new ArgumentNullException("identity");
     }
 }
コード例 #9
0
        internal override ADObject GetDirectoryObjectFromIdentity(T identityObj, string searchRoot, bool showDeleted)
        {
            ADObject aDSessionInfo;

            if (base.CmdletSessionInfo != null)
            {
                string           defaultNamingContext = base.CmdletSessionInfo.ADRootDSE.DefaultNamingContext;
                ADObjectSearcher aDObjectSearcher     = SearchUtility.BuildSearcher(base.CmdletSessionInfo.ADSessionInfo, defaultNamingContext, ADSearchScope.Base);
                using (aDObjectSearcher)
                {
                    AttributeSetRequest attributeSetRequest = this.ConstructAttributeSetRequest(null);
                    aDObjectSearcher.Properties.AddRange(attributeSetRequest.DirectoryAttributes);
                    IADOPathNode[] structuralObjectFilter = new IADOPathNode[2];
                    structuralObjectFilter[0] = this.StructuralObjectFilter;
                    structuralObjectFilter[1] = this.BuildIdentityFilter(identityObj);
                    aDObjectSearcher.Filter   = ADOPathUtil.CreateAndClause(structuralObjectFilter);
                    DebugLogger.LogInfo("ADDefaultDomainPasswordPolicyFactory", string.Format("GetDirectoryObjectFromIdentity: Searching for identity using filter: {0} searchbase: {1}", aDObjectSearcher.Filter.GetLdapFilterString(), aDObjectSearcher.SearchRoot));
                    aDSessionInfo = aDObjectSearcher.FindOne();
                    if (aDSessionInfo == null)
                    {
                        DebugLogger.LogInfo("ADDefaultDomainPasswordPolicyFactory", string.Format("GetDirectoryObjectFromIdentity: Identity not found.", new object[0]));
                        object[] str = new object[2];
                        str[0] = identityObj.ToString();
                        str[1] = aDObjectSearcher.SearchRoot;
                        throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.IdentityNotFound, str));
                    }
                }
                if (!aDSessionInfo.ObjectClass.Equals("domainDNS", StringComparison.OrdinalIgnoreCase))
                {
                    object[] objArray = new object[2];
                    objArray[0] = identityObj.ToString();
                    objArray[1] = defaultNamingContext;
                    throw new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.IdentityNotFound, objArray));
                }
                else
                {
                    aDSessionInfo.TrackChanges = true;
                    aDSessionInfo.SessionInfo  = base.CmdletSessionInfo.ADSessionInfo;
                    return(aDSessionInfo);
                }
            }
            else
            {
                throw new ArgumentNullException(StringResources.SessionRequired);
            }
        }
コード例 #10
0
 static ADDomainControllerFactory()
 {
     IADOPathNode[] aDOPathNodeArray = new IADOPathNode[2];
     aDOPathNodeArray[0] = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "computer");
     IADOPathNode[] aDOPathNodeArray1 = new IADOPathNode[2];
     aDOPathNodeArray1[0] = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "primaryGroupID", "516");
     aDOPathNodeArray1[1] = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "primaryGroupID", "521");
     aDOPathNodeArray[1]  = ADOPathUtil.CreateOrClause(aDOPathNodeArray1);
     ADDomainControllerFactory <T> ._domainControllerComputerObjectFilter = ADOPathUtil.CreateAndClause(aDOPathNodeArray);
     string[] strArrays = new string[7];
     strArrays[0] = "name";
     strArrays[1] = "distinguishedName";
     strArrays[2] = "objectClass";
     strArrays[3] = "objectGUID";
     strArrays[4] = "dNSHostName";
     strArrays[5] = "serverReference";
     strArrays[6] = "serverReferenceBL";
     ADDomainControllerFactory <T> ._domainControllerDefaultAttributes = strArrays;
     IADOPathNode[] aDOPathNodeArray2 = new IADOPathNode[3];
     aDOPathNodeArray2[0] = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "nTDSDSA");
     aDOPathNodeArray2[1] = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "server");
     aDOPathNodeArray2[2] = ADDomainControllerFactory <T> ._domainControllerComputerObjectFilter;
     ADDomainControllerFactory <T> ._domainControllerStructuralFilter = ADOPathUtil.CreateOrClause(aDOPathNodeArray2);
     string[] strArrays1 = new string[5];
     strArrays1[0] = "distinguishedName";
     strArrays1[1] = "objectGUID";
     strArrays1[2] = "dNSHostName";
     strArrays1[3] = "objectSid";
     strArrays1[4] = "sAMAccountName";
     ADDomainControllerFactory <T> ._identityLdapAttributes = strArrays1;
     AttributeConverterEntry[] attributeConverterEntry = new AttributeConverterEntry[10];
     attributeConverterEntry[0] = new AttributeConverterEntry("IsReadOnly", "IsReadOnly", TypeConstants.Bool, false, TypeAdapterAccess.Read, true, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchObjectClientSideFilter));
     attributeConverterEntry[1] = new AttributeConverterEntry("IsGlobalCatalog", "IsGlobalCatalog", TypeConstants.Bool, false, TypeAdapterAccess.Read, true, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchObjectClientSideFilter));
     attributeConverterEntry[2] = new AttributeConverterEntry("Enabled", "Enabled", TypeConstants.Bool, false, TypeAdapterAccess.Read, true, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchObjectClientSideFilter));
     attributeConverterEntry[3] = new AttributeConverterEntry("OperatingSystemVersion", "OSVersion", TypeConstants.String, false, TypeAdapterAccess.Read, true, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchObjectClientSideFilter));
     attributeConverterEntry[4] = new AttributeConverterEntry("OperatingSystem", "OSName", TypeConstants.String, false, TypeAdapterAccess.Read, true, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchObjectClientSideFilter));
     attributeConverterEntry[5] = new AttributeConverterEntry("OperatingSystemServicePack", "OSServicepack", TypeConstants.String, false, TypeAdapterAccess.Read, true, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchObjectClientSideFilter));
     attributeConverterEntry[6] = new AttributeConverterEntry("OperatingSystemHotfix", "OSHotFix", TypeConstants.String, false, TypeAdapterAccess.Read, true, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchObjectClientSideFilter));
     attributeConverterEntry[7] = new AttributeConverterEntry("ComputerObjectDN", "ComputerDN", TypeConstants.String, false, TypeAdapterAccess.Read, true, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchObjectClientSideFilter));
     attributeConverterEntry[8] = new AttributeConverterEntry("Domain", "Domain", TypeConstants.String, false, TypeAdapterAccess.Read, true, AttributeSet.Default, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchObjectClientSideFilter));
     attributeConverterEntry[9] = new AttributeConverterEntry("Forest", "Forest", TypeConstants.String, false, TypeAdapterAccess.Read, true, AttributeSet.Default, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchObjectClientSideFilter));
     ADDomainControllerFactory <T> .ADMappingTable = attributeConverterEntry;
     ADFactoryBase <T> .RegisterMappingTable(ADDomainControllerFactory <T> .ADMappingTable, ADServerType.ADDS);
 }
コード例 #11
0
        internal static ADObjectSearcher BuildAggregatedSearchFilterIdentityResolver(IdentityResolverDelegate[] identityDelegates, ADOperator op, object identity, string searchRoot, CmdletSessionInfo cmdletSessionInfo, out bool useSearchFilter)
        {
            ADObjectSearcher    item;
            List <IADOPathNode> aDOPathNodes = new List <IADOPathNode>((int)identityDelegates.Length);

            IdentityResolverDelegate[] identityResolverDelegateArray = identityDelegates;
            for (int i = 0; i < (int)identityResolverDelegateArray.Length; i++)
            {
                bool V_1;
                IdentityResolverDelegate identityResolverDelegate = identityResolverDelegateArray[i];
                item = identityResolverDelegate(identity, searchRoot, cmdletSessionInfo, out V_1);
                if (item != null)
                {
                    aDOPathNodes.Add(item.Filter);
                }
            }
            item = SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, searchRoot, ADSearchScope.Subtree);
            if (aDOPathNodes.Count <= 1)
            {
                if (aDOPathNodes.Count != 1)
                {
                    item = null;
                }
                else
                {
                    item.Filter = aDOPathNodes[0];
                }
            }
            else
            {
                if (ADOperator.Or != op)
                {
                    item.Filter = ADOPathUtil.CreateAndClause(aDOPathNodes.ToArray());
                }
                else
                {
                    item.Filter = ADOPathUtil.CreateOrClause(aDOPathNodes.ToArray());
                }
            }
            useSearchFilter = true;
            return(item);
        }
コード例 #12
0
        private void AddSessionsMatchingSiteName(string siteName)
        {
            bool flag = false;

            if (siteName == null || siteName == "*")
            {
                this.AddSessionsFromConnectedForest();
                return;
            }
            else
            {
                IADOPathNode[] aDOPathNodeArray  = new IADOPathNode[2];
                IADOPathNode[] aDOPathNodeArray1 = new IADOPathNode[2];
                aDOPathNodeArray1[0] = ADOPathUtil.CreateFilterClause(ADOperator.Like, "distinguishedName", siteName);
                aDOPathNodeArray1[1] = ADOPathUtil.CreateFilterClause(ADOperator.Like, "name", siteName);
                aDOPathNodeArray[0]  = ADOPathUtil.CreateOrClause(aDOPathNodeArray1);
                aDOPathNodeArray[1]  = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "site");
                IADOPathNode  aDOPathNode = ADOPathUtil.CreateAndClause(aDOPathNodeArray);
                List <string> strs        = new List <string>();
                strs.Add("distinguishedName");
                ICollection <string> strs1 = strs;
                this._sharedADOFactory.SetCmdletSessionInfo(this.GetCmdletSessionInfo());
                int?nullable  = null;
                int?nullable1 = null;
                IEnumerable <ADObject> extendedObjectFromFilter = this._sharedADOFactory.GetExtendedObjectFromFilter(aDOPathNode, string.Concat("CN=Sites,", this.GetCmdletSessionInfo().ADRootDSE.ConfigurationNamingContext), ADSearchScope.OneLevel, strs1, nullable, nullable1, false);
                foreach (ADObject aDObject in extendedObjectFromFilter)
                {
                    this.AddSessionFromSiteDN(aDObject.DistinguishedName);
                    flag = true;
                }
                if (!flag)
                {
                    object[] item = new object[2];
                    item[0] = siteName;
                    item[1] = this._cmdletParameters["Scope"];
                    base.WriteErrorBuffered(this.ConstructErrorRecord(new ADIdentityNotFoundException(string.Format(CultureInfo.CurrentCulture, StringResources.NoMatchingResultsForTarget, item))));
                }
                return;
            }
        }
コード例 #13
0
        static ADComputerFactory()
        {
            IADOPathNode[] aDOPathNodeArray = new IADOPathNode[2];
            aDOPathNodeArray[0] = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "computer");
            aDOPathNodeArray[1] = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectCategory", "computer");
            ADComputerFactory <T> ._structuralObjectFilter = ADOPathUtil.CreateAndClause(aDOPathNodeArray);
            ADComputerFactory <T> ._rDNPrefix             = "CN";
            ADComputerFactory <T> ._structuralObjectClass = "computer";
            string[] strArrays = new string[1];
            strArrays[0] = "sAMAccountName";
            ADComputerFactory <T> ._computerIdentityLdapAttributes = strArrays;
            IdentityResolverDelegate[] customIdentityResolver = new IdentityResolverDelegate[5];
            customIdentityResolver[0] = IdentityResolverMethods.GetCustomIdentityResolver(new IdentityResolverDelegate(IdentityResolverMethods.DistinguishedNameIdentityResolver));
            customIdentityResolver[1] = IdentityResolverMethods.GetCustomIdentityResolver(new IdentityResolverDelegate(IdentityResolverMethods.GuidIdentityResolver));
            customIdentityResolver[2] = IdentityResolverMethods.GetCustomIdentityResolver(new IdentityResolverDelegate(IdentityResolverMethods.SidIdentityResolver));
            customIdentityResolver[3] = IdentityResolverMethods.GetCustomIdentityResolver(new IdentityResolverDelegate(IdentityResolverMethods.SamAccountNameIdentityResolver));
            customIdentityResolver[4] = ADComputerUtil.GetGenericIdentityResolverWithSamName(ADComputerFactory <T> ._computerIdentityLdapAttributes);
            ADComputerFactory <T> ._identityResolvers = customIdentityResolver;
            AttributeConverterEntry[] attributeConverterEntry = new AttributeConverterEntry[11];
            attributeConverterEntry[0]              = new AttributeConverterEntry(ADPrincipalFactory <T> .ADPrincipalPropertyMap.SamAccountName.PropertyName, ADPrincipalFactory <T> .ADPrincipalPropertyMap.SamAccountName.ADAttribute, TypeConstants.String, false, TypeAdapterAccess.ReadWrite, true, AttributeSet.Default, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(ADComputerUtil.ToDirectoryComputerSamAccountName), new ToSearchFilterDelegate(ADComputerUtil.ToSearchComputerSamAccountName));
            attributeConverterEntry[1]              = new AttributeConverterEntry(ADComputerFactory <T> .ADComputerPropertyMap.DNSHostName.PropertyName, ADComputerFactory <T> .ADComputerPropertyMap.DNSHostName.ADAttribute, TypeConstants.String, true, TypeAdapterAccess.ReadWrite, true, AttributeSet.Default, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchUsingSchemaInfo));
            attributeConverterEntry[2]              = new AttributeConverterEntry(ADComputerFactory <T> .ADComputerPropertyMap.ServiceAccount.PropertyName, ADComputerFactory <T> .ADComputerPropertyMap.ServiceAccount.ADAttribute, TypeConstants.String, true, TypeAdapterAccess.ReadWrite, false, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedMultivalueObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryMultivalueObject), new ToSearchFilterDelegate(SearchConverters.ToSearchUsingSchemaInfo));
            attributeConverterEntry[3]              = new AttributeConverterEntry(ADComputerFactory <T> .ADComputerPropertyMap.IPv4Address.PropertyName, ADComputerFactory <T> .ADComputerPropertyMap.IPv4Address.ADAttribute, TypeConstants.String, false, TypeAdapterAccess.Read, true, AttributeSet.Extended, new ToExtendedFormatDelegate(ADComputerFactory <T> .ToExtendedIPv4), null, new ToSearchFilterDelegate(ADComputerFactory <T> .ToSearchIPv4));
            attributeConverterEntry[4]              = new AttributeConverterEntry(ADComputerFactory <T> .ADComputerPropertyMap.IPv6Address.PropertyName, ADComputerFactory <T> .ADComputerPropertyMap.IPv6Address.ADAttribute, TypeConstants.String, false, TypeAdapterAccess.Read, true, AttributeSet.Extended, new ToExtendedFormatDelegate(ADComputerFactory <T> .ToExtendedIPv6), null, new ToSearchFilterDelegate(ADComputerFactory <T> .ToSearchIPv6));
            attributeConverterEntry[5]              = new AttributeConverterEntry(ADComputerFactory <T> .ADComputerPropertyMap.Location.PropertyName, ADComputerFactory <T> .ADComputerPropertyMap.Location.ADAttribute, TypeConstants.String, true, TypeAdapterAccess.ReadWrite, true, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchUsingSchemaInfo));
            attributeConverterEntry[6]              = new AttributeConverterEntry(ADComputerFactory <T> .ADComputerPropertyMap.ManagedBy.PropertyName, ADComputerFactory <T> .ADComputerPropertyMap.ManagedBy.ADAttribute, TypeConstants.ADPrincipal, true, TypeAdapterAccess.ReadWrite, true, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryFromADObjectToDN <ADPrincipalFactory <ADPrincipal>, ADPrincipal>), new ToSearchFilterDelegate(SearchConverters.ToSearchFromADObjectToDN <ADPrincipalFactory <ADPrincipal>, ADPrincipal>));
            attributeConverterEntry[7]              = new AttributeConverterEntry(ADComputerFactory <T> .ADComputerPropertyMap.OS.PropertyName, ADComputerFactory <T> .ADComputerPropertyMap.OS.ADAttribute, TypeConstants.String, true, TypeAdapterAccess.ReadWrite, true, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchUsingSchemaInfo));
            attributeConverterEntry[8]              = new AttributeConverterEntry(ADComputerFactory <T> .ADComputerPropertyMap.OSHotfix.PropertyName, ADComputerFactory <T> .ADComputerPropertyMap.OSHotfix.ADAttribute, TypeConstants.String, true, TypeAdapterAccess.ReadWrite, true, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchUsingSchemaInfo));
            attributeConverterEntry[9]              = new AttributeConverterEntry(ADComputerFactory <T> .ADComputerPropertyMap.OSServicePack.PropertyName, ADComputerFactory <T> .ADComputerPropertyMap.OSServicePack.ADAttribute, TypeConstants.String, true, TypeAdapterAccess.ReadWrite, true, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchUsingSchemaInfo));
            attributeConverterEntry[10]             = new AttributeConverterEntry(ADComputerFactory <T> .ADComputerPropertyMap.OSVersion.PropertyName, ADComputerFactory <T> .ADComputerPropertyMap.OSVersion.ADAttribute, TypeConstants.String, true, TypeAdapterAccess.ReadWrite, true, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchUsingSchemaInfo));
            ADComputerFactory <T> .ADMappingTable   = attributeConverterEntry;
            ADComputerFactory <T> .ADAMMappingTable = ADComputerFactory <T> .ADMappingTable;
            ADFactoryBase <T> .RegisterMappingTable(ADComputerFactory <T> .ADAMMappingTable, ADServerType.ADLDS);

            ADFactoryBase <T> .RegisterMappingTable(ADComputerFactory <T> .ADMappingTable, ADServerType.ADDS);

            ADAccountFactory <T> .DefaultUserAccessControl      = 0x1002;
            ADAccountFactory <T> .UseComputerPasswordGeneration = true;
        }
コード例 #14
0
        private void ValidateMembersParameter()
        {
            bool flag;

            if (!this._isMembersValidated)
            {
                object        item             = this._cmdletParameters["Members"];
                ADPrincipal[] aDPrincipalArray = item as ADPrincipal[];
                if (aDPrincipalArray == null)
                {
                    ADPrincipal aDPrincipal = item as ADPrincipal;
                    if (aDPrincipal != null)
                    {
                        ADPrincipal[] aDPrincipalArray1 = new ADPrincipal[1];
                        aDPrincipalArray1[0] = aDPrincipal;
                        aDPrincipalArray     = aDPrincipalArray1;
                    }
                }
                if (aDPrincipalArray != null)
                {
                    List <string> strs       = new List <string>();
                    Hashtable     hashtables = new Hashtable();
                    ADPrincipalFactory <ADPrincipal> aDPrincipalFactory = new ADPrincipalFactory <ADPrincipal>();
                    CmdletSessionInfo cmdletSessionInfo = base.GetCmdletSessionInfo();
                    aDPrincipalFactory.SetCmdletSessionInfo(cmdletSessionInfo);
                    if (cmdletSessionInfo.ConnectedADServerType != ADServerType.ADDS)
                    {
                        flag = false;
                    }
                    else
                    {
                        flag = this._operationType == SetADGroupMemberOperationType.RemoveGroupMember;
                    }
                    bool flag1 = flag;
                    Dictionary <SecurityIdentifier, string> securityIdentifiers = new Dictionary <SecurityIdentifier, string>();
                    IADOPathNode       aDOPathNode = null;
                    SecurityIdentifier value       = null;
                    if (flag1)
                    {
                        ADGroup aDGroup = (ADGroup)this._cmdletParameters["Identity"];
                        if (!aDGroup.IsSearchResult)
                        {
                            ADObject directoryObjectFromIdentity = aDPrincipalFactory.GetDirectoryObjectFromIdentity(aDGroup, cmdletSessionInfo.DefaultPartitionPath);
                            value = (SecurityIdentifier)directoryObjectFromIdentity["objectSid"].Value;
                        }
                        else
                        {
                            value = aDGroup.SID;
                        }
                    }
                    ADPrincipal[] aDPrincipalArray2 = aDPrincipalArray;
                    for (int i = 0; i < (int)aDPrincipalArray2.Length; i++)
                    {
                        ADPrincipal        aDPrincipal1      = aDPrincipalArray2[i];
                        SecurityIdentifier sID               = null;
                        string             distinguishedName = null;
                        try
                        {
                            if (!aDPrincipal1.IsSearchResult)
                            {
                                ADObject aDObject = aDPrincipalFactory.GetDirectoryObjectFromIdentity(aDPrincipal1, cmdletSessionInfo.DefaultPartitionPath);
                                sID = (SecurityIdentifier)aDObject["objectSid"].Value;
                                distinguishedName = (string)aDObject["distinguishedName"].Value;
                            }
                            else
                            {
                                sID = aDPrincipal1.SID;
                                distinguishedName = aDPrincipal1.DistinguishedName;
                            }
                            if (distinguishedName != null)
                            {
                                if (sID == null)
                                {
                                    object[] objArray = new object[2];
                                    objArray[0] = "objectSid";
                                    objArray[1] = distinguishedName;
                                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.AttributeNotFoundOnObject, objArray));
                                }
                            }
                            else
                            {
                                object[] identifyingString = new object[2];
                                identifyingString[0] = "distinguishedName";
                                identifyingString[1] = aDPrincipal1.IdentifyingString;
                                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.AttributeNotFoundOnObject, identifyingString));
                            }
                        }
                        catch (ADIdentityNotFoundException aDIdentityNotFoundException1)
                        {
                            ADIdentityNotFoundException aDIdentityNotFoundException = aDIdentityNotFoundException1;
                            DebugLogger.LogError("SetADGroupMember", aDIdentityNotFoundException.ToString());
                            base.ThrowTerminatingError(new ErrorRecord(aDIdentityNotFoundException, "SetADGroupMember.ValidateMembersParameter", ErrorCategory.ObjectNotFound, aDPrincipal1));
                        }
                        catch (ArgumentException argumentException1)
                        {
                            ArgumentException argumentException = argumentException1;
                            DebugLogger.LogError("SetADGroupMember", argumentException.ToString());
                            base.ThrowTerminatingError(new ErrorRecord(argumentException, "SetADGroupMember.ValidateMembersParameter", ErrorCategory.ReadError, aDPrincipal1));
                        }
                        if (!flag1 || value.IsEqualDomainSid(sID))
                        {
                            strs.Add(Utils.ConvertSIDToStringizedSid(sID));
                        }
                        else
                        {
                            IADOPathNode aDOPathNode1 = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectSid", sID);
                            if (aDOPathNode != null)
                            {
                                IADOPathNode[] aDOPathNodeArray = new IADOPathNode[2];
                                aDOPathNodeArray[0] = aDOPathNode;
                                aDOPathNodeArray[1] = aDOPathNode1;
                                aDOPathNode         = ADOPathUtil.CreateOrClause(aDOPathNodeArray);
                            }
                            else
                            {
                                aDOPathNode = aDOPathNode1;
                            }
                            securityIdentifiers.Add(sID, distinguishedName);
                        }
                    }
                    if (aDOPathNode != null)
                    {
                        using (ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(this.GetSessionInfo()))
                        {
                            IADOPathNode aDOPathNode2 = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "foreignSecurityPrincipal");
                            aDObjectSearcher.SearchRoot = this.GetRootDSE().DefaultNamingContext;
                            IADOPathNode[] aDOPathNodeArray1 = new IADOPathNode[2];
                            aDOPathNodeArray1[0]    = aDOPathNode2;
                            aDOPathNodeArray1[1]    = aDOPathNode;
                            aDObjectSearcher.Filter = ADOPathUtil.CreateAndClause(aDOPathNodeArray1);
                            aDObjectSearcher.Properties.Add("objectSid");
                            foreach (ADObject aDObject1 in aDObjectSearcher.FindAll())
                            {
                                SecurityIdentifier securityIdentifier = (SecurityIdentifier)aDObject1["objectSid"].Value;
                                if (!securityIdentifiers.ContainsKey(securityIdentifier))
                                {
                                    continue;
                                }
                                strs.Add(Utils.ConvertSIDToStringizedSid(securityIdentifier));
                                securityIdentifiers.Remove(securityIdentifier);
                            }
                            foreach (string str in securityIdentifiers.Values)
                            {
                                strs.Add(str);
                            }
                        }
                    }
                    if (this._operationType != SetADGroupMemberOperationType.AddGroupMember)
                    {
                        if (this._operationType == SetADGroupMemberOperationType.RemoveGroupMember)
                        {
                            hashtables.Add(PropertyModifyOp.Remove.ToString(), strs.ToArray());
                        }
                    }
                    else
                    {
                        hashtables.Add(PropertyModifyOp.Add.ToString(), strs.ToArray());
                    }
                    this._cmdletParameters.RemoveParameter("Members");
                    this._cmdletParameters["Members"] = new ADMultivalueHashtableParameter <string>(hashtables);
                    this._isMembersValidated          = true;
                }
                return;
            }
            else
            {
                return;
            }
        }
コード例 #15
0
        internal static IADOPathNode ToSearchFlagEnumerationInInt <T>(string extendedAttributeName, string[] directoryAttributes, IADOPathNode filterClause, CmdletSessionInfo cmdletSessionInfo)
        {
            T                 t = default(T);
            object            num;
            IADOPathNode      item;
            BinaryADOPathNode binaryADOPathNode = filterClause as BinaryADOPathNode;

            if (binaryADOPathNode != null)
            {
                IDataNode rightNode = binaryADOPathNode.RightNode as IDataNode;
                if (rightNode != null)
                {
                    ADOperator @operator = binaryADOPathNode.Operator;
                    if (@operator == ADOperator.Eq || @operator == ADOperator.Ne)
                    {
                        char[] chrArray = new char[1];
                        chrArray[0] = ',';
                        string[]            strArrays    = rightNode.DataObject.ToString().Split(chrArray);
                        List <IADOPathNode> aDOPathNodes = new List <IADOPathNode>();
                        string[]            strArrays1   = strArrays;
                        int num1 = 0;
                        while (num1 < (int)strArrays1.Length)
                        {
                            string str = strArrays1[num1];
                            if (!Utils.TryParseEnum <T>(str, out t))
                            {
                                object[] objArray = new object[1];
                                objArray[0] = extendedAttributeName;
                                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterRHSNotMatchEnumValue, objArray));
                            }
                            else
                            {
                                if (Enum.GetUnderlyingType(typeof(T)) != typeof(int))
                                {
                                    num = Convert.ToInt64(t, CultureInfo.InvariantCulture);
                                }
                                else
                                {
                                    num = Convert.ToInt32(t, CultureInfo.InvariantCulture);
                                }
                                IADOPathNode aDOPathNode = new BinaryADOPathNode(ADOperator.Bor, new PropertyADOPathNode(directoryAttributes[0]), new ObjectADOPathNode(num));
                                aDOPathNodes.Add(aDOPathNode);
                                num1++;
                            }
                        }
                        if (aDOPathNodes.Count <= 1)
                        {
                            if (aDOPathNodes.Count != 1)
                            {
                                object[] objArray1 = new object[1];
                                objArray1[0] = extendedAttributeName;
                                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterRHSNotMatchEnumValue, objArray1));
                            }
                            else
                            {
                                item = aDOPathNodes[0];
                            }
                        }
                        else
                        {
                            item = ADOPathUtil.CreateAndClause(aDOPathNodes.ToArray());
                        }
                        if (@operator == ADOperator.Ne)
                        {
                            item = ADOPathUtil.CreateNotClause(item);
                        }
                        return(item);
                    }
                    else
                    {
                        object[]     str1            = new object[2];
                        ADOperator[] aDOperatorArray = new ADOperator[2];
                        aDOperatorArray[1] = ADOperator.Ne;
                        str1[0]            = SearchConverters.ConvertOperatorListToString(aDOperatorArray);
                        str1[1]            = extendedAttributeName;
                        throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterSupportedOperatorListErrorMessage, str1));
                    }
                }
                else
                {
                    throw new ArgumentException(StringResources.SearchConverterRHSNotDataNode);
                }
            }
            else
            {
                throw new ArgumentException(StringResources.SearchConverterNotBinaryNode);
            }
        }
コード例 #16
0
 internal override IADOPathNode IdentitySearchConverter(object identity)
 {
     if (identity != null)
     {
         if (identity as ADDefaultDomainPasswordPolicy != null)
         {
             ADDefaultDomainPasswordPolicy aDDefaultDomainPasswordPolicy = (ADDefaultDomainPasswordPolicy)identity;
             if (aDDefaultDomainPasswordPolicy.DistinguishedName == null)
             {
                 while (identity as ADDefaultDomainPasswordPolicy != null)
                 {
                     identity = ((ADDefaultDomainPasswordPolicy)identity).Identity;
                 }
             }
             else
             {
                 identity = aDDefaultDomainPasswordPolicy.DistinguishedName;
             }
         }
         string str = identity as string;
         if (str != null)
         {
             string str1 = ADDomainUtil.FindDomainNCHead(str, base.CmdletSessionInfo);
             if (str1 != null)
             {
                 return(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "distinguishedName", str1));
             }
         }
         SecurityIdentifier securityIdentifier = identity as SecurityIdentifier;
         if (securityIdentifier == null)
         {
             if (identity as string == null)
             {
                 if (!(identity is Guid))
                 {
                     if (identity as ADObject == null)
                     {
                         throw new ArgumentException(string.Format(StringResources.SearchConverterUnrecognizedObjectType, identity.GetType()));
                     }
                     else
                     {
                         ADObject            aDObject     = identity as ADObject;
                         List <IADOPathNode> aDOPathNodes = new List <IADOPathNode>(2);
                         if (!string.IsNullOrEmpty(aDObject.DistinguishedName))
                         {
                             aDOPathNodes.Add(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "distinguishedName", aDObject.DistinguishedName));
                         }
                         Guid?objectGuid = aDObject.ObjectGuid;
                         if (objectGuid.HasValue)
                         {
                             Guid?nullable = aDObject.ObjectGuid;
                             Guid value    = nullable.Value;
                             aDOPathNodes.Add(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectGuid", value.ToByteArray()));
                         }
                         if (aDOPathNodes.Count != 0)
                         {
                             return(ADOPathUtil.CreateAndClause(aDOPathNodes.ToArray()));
                         }
                         else
                         {
                             throw new ArgumentException(StringResources.SearchConverterIdentityAttributeNotSet);
                         }
                     }
                 }
                 else
                 {
                     Guid guid = (Guid)identity;
                     return(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectGuid", guid.ToByteArray()));
                 }
             }
             else
             {
                 Guid?nullable1 = null;
                 if (!Utils.TryParseGuid(str, out nullable1))
                 {
                     List <IADOPathNode> aDOPathNodes1 = new List <IADOPathNode>((int)ADDefaultDomainPasswordPolicyFactory <T> ._ddppIdentityLdapAttributes.Length);
                     string[]            strArrays     = ADDefaultDomainPasswordPolicyFactory <T> ._ddppIdentityLdapAttributes;
                     for (int i = 0; i < (int)strArrays.Length; i++)
                     {
                         string str2 = strArrays[i];
                         aDOPathNodes1.Add(ADOPathUtil.CreateFilterClause(ADOperator.Eq, str2, str));
                     }
                     if (aDOPathNodes1.Count <= 1)
                     {
                         return(aDOPathNodes1[0]);
                     }
                     else
                     {
                         return(ADOPathUtil.CreateOrClause(aDOPathNodes1.ToArray()));
                     }
                 }
                 else
                 {
                     Guid value1 = nullable1.Value;
                     return(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectGuid", value1.ToByteArray()));
                 }
             }
         }
         else
         {
             return(ADDomainUtil.CreateSidFilterClause(securityIdentifier));
         }
     }
     else
     {
         throw new ArgumentNullException("Identity");
     }
 }
コード例 #17
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);
        }
コード例 #18
0
 internal override IADOPathNode IdentitySearchConverter(object identity)
 {
     if (identity != null)
     {
         if ((int)this.IdentityLdapAttributes.Length <= 0)
         {
             return(null);
         }
         else
         {
             if (identity as string == null)
             {
                 if (!(identity is Guid))
                 {
                     if (identity as ADObject == null)
                     {
                         throw new ArgumentException(string.Format(StringResources.SearchConverterUnrecognizedObjectType, identity.GetType()));
                     }
                     else
                     {
                         ADObject            aDObject     = identity as ADObject;
                         List <IADOPathNode> aDOPathNodes = new List <IADOPathNode>(2);
                         if (!string.IsNullOrEmpty(aDObject.DistinguishedName))
                         {
                             aDOPathNodes.Add(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "distinguishedName", aDObject.DistinguishedName));
                         }
                         Guid?objectGuid = aDObject.ObjectGuid;
                         if (objectGuid.HasValue)
                         {
                             Guid?nullable = aDObject.ObjectGuid;
                             Guid value    = nullable.Value;
                             aDOPathNodes.Add(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectGuid", value.ToByteArray()));
                         }
                         if (aDOPathNodes.Count != 0)
                         {
                             if (aDOPathNodes.Count != 1)
                             {
                                 return(ADOPathUtil.CreateAndClause(aDOPathNodes.ToArray()));
                             }
                             else
                             {
                                 return(aDOPathNodes[0]);
                             }
                         }
                         else
                         {
                             throw new ArgumentException(StringResources.SearchConverterIdentityAttributeNotSet);
                         }
                     }
                 }
                 else
                 {
                     Guid guid = (Guid)identity;
                     return(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectGuid", guid.ToByteArray()));
                 }
             }
             else
             {
                 string str       = identity as string;
                 Guid?  nullable1 = null;
                 if (!Utils.TryParseGuid(str, out nullable1))
                 {
                     List <IADOPathNode> aDOPathNodes1 = this.BuildIdentityFilterListFromString(str);
                     if (aDOPathNodes1.Count <= 1)
                     {
                         return(aDOPathNodes1[0]);
                     }
                     else
                     {
                         return(ADOPathUtil.CreateOrClause(aDOPathNodes1.ToArray()));
                     }
                 }
                 else
                 {
                     Guid value1 = nullable1.Value;
                     return(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectGuid", value1.ToByteArray()));
                 }
             }
         }
     }
     else
     {
         throw new ArgumentNullException("identity");
     }
 }
コード例 #19
0
        public static IADOPathNode ToSearchAccountExpirationDate(string extendedAttribute, string[] directoryAttributes, IADOPathNode filterClause, CmdletSessionInfo cmdletSessionInfo)
        {
            bool flag;
            BinaryADOPathNode binaryADOPathNode = filterClause as BinaryADOPathNode;

            if (binaryADOPathNode == null)
            {
                throw new ArgumentException(StringResources.SearchConverterNotBinaryNode);
            }
            else
            {
                PropertyADOPathNode propertyADOPathNode = new PropertyADOPathNode(directoryAttributes[0]);
                IDataNode           rightNode           = binaryADOPathNode.RightNode as IDataNode;
                if (rightNode == null)
                {
                    throw new ArgumentException(StringResources.SearchConverterRHSNotDataNode);
                }
                else
                {
                    ObjectADOPathNode objectADOPathNode = new ObjectADOPathNode(rightNode.DataObject);
                    objectADOPathNode.EncodeAsteriskChar = rightNode.EncodeAsteriskChar;
                    IADOPathNode searchDateTimeUsingSchemaInfo = new BinaryADOPathNode(binaryADOPathNode.Operator, propertyADOPathNode, objectADOPathNode);
                    searchDateTimeUsingSchemaInfo = SearchConverters.ToSearchDateTimeUsingSchemaInfo(extendedAttribute, directoryAttributes, searchDateTimeUsingSchemaInfo, cmdletSessionInfo);
                    bool flag1 = true;
                    if (binaryADOPathNode.Operator != ADOperator.Eq)
                    {
                        if (binaryADOPathNode.Operator == ADOperator.Like)
                        {
                            if (rightNode.DataObject as string == null)
                            {
                                flag = false;
                            }
                            else
                            {
                                flag = ADOPathUtil.IsValueAllAsterisk((string)rightNode.DataObject);
                            }
                            flag1 = flag;
                        }
                    }
                    else
                    {
                        flag1 = false;
                    }
                    if (!flag1)
                    {
                        return(searchDateTimeUsingSchemaInfo);
                    }
                    else
                    {
                        IADOPathNode[] aDOPathNodeArray = new IADOPathNode[2];
                        aDOPathNodeArray[0] = ADOPathUtil.CreateFilterClause(ADOperator.Eq, directoryAttributes[0], 0);
                        aDOPathNodeArray[1] = ADOPathUtil.CreateFilterClause(ADOperator.Eq, directoryAttributes[0], 0x7fffffffffffffffL);
                        IADOPathNode   aDOPathNode       = ADOPathUtil.CreateNotClause(ADOPathUtil.CreateOrClause(aDOPathNodeArray));
                        IADOPathNode[] aDOPathNodeArray1 = new IADOPathNode[2];
                        aDOPathNodeArray1[0] = searchDateTimeUsingSchemaInfo;
                        aDOPathNodeArray1[1] = aDOPathNode;
                        return(ADOPathUtil.CreateAndClause(aDOPathNodeArray1));
                    }
                }
            }
        }
コード例 #20
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]));
            }
        }
コード例 #21
0
        private bool SearchADAccountBeginCSRoutine()
        {
            IADOPathNode        item;
            DateTime            value;
            DateTime            dateTime;
            List <IADOPathNode> aDOPathNodes      = new List <IADOPathNode>();
            CmdletSessionInfo   cmdletSessionInfo = this.GetCmdletSessionInfo();

            this._factory.SetCmdletSessionInfo(cmdletSessionInfo);
            this.ValidateParameters();
            string[] strArrays = new string[6];
            strArrays[0] = "Enabled";
            strArrays[1] = "LockedOut";
            strArrays[2] = "PasswordNeverExpires";
            strArrays[3] = "PasswordExpired";
            strArrays[4] = "AccountExpirationDate";
            strArrays[5] = "LastLogonDate";
            this._cmdletParameters["Properties"] = strArrays;
            base.BuildPropertySet();
            new StringBuilder();
            int num = 0;

            //TODO: Review: this._cmdletParameters.ComputersOnly;
            if (this._cmdletParameters.ComputersOnly)
            {
                aDOPathNodes.Add(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "computer"));
                num++;
            }
            //TODO: Review: this._cmdletParameters.UsersOnly;
            if (this._cmdletParameters.UsersOnly)
            {
                aDOPathNodes.Add(ADOPathUtil.CreateFilterClause(ADOperator.Ne, "objectClass", "computer"));
                num++;
            }
            if (num <= 1)
            {
                double?  nullable  = null;
                DateTime?nullable1 = null;
                if (this._cmdletParameters.Contains("TimeSpan"))
                {
                    //TODO: Review: this._cmdletParameters.TimeSpan;
                    TimeSpan timeSpan = this._cmdletParameters.TimeSpan;
                    nullable = new double?(timeSpan.TotalDays);
                }
                if (this._cmdletParameters.Contains("DateTime"))
                {
                    //TODO: Review: this._cmdletParameters.DateTime;
                    nullable1 = new DateTime?(this._cmdletParameters.DateTime);
                }
                if (!this._cmdletParameters.AccountDisabled)
                {
                    if (!this._cmdletParameters.PasswordNeverExpires)
                    {
                        if (!this._cmdletParameters.PasswordExpired)
                        {
                            if (!this._cmdletParameters.AccountExpiring)
                            {
                                if (!this._cmdletParameters.AccountExpired)
                                {
                                    if (!this._cmdletParameters.AccountInactive)
                                    {
                                        if (this._cmdletParameters.LockedOut)
                                        {
                                            aDOPathNodes.Add(ADAccountFactory <ADAccount> .AttributeTable[cmdletSessionInfo.ConnectedADServerType]["AccountLockoutTime"].InvokeToSearcherConverter(ADOPathUtil.CreateFilterClause(ADOperator.Ge, "AccountLockoutTime", 1), cmdletSessionInfo));
                                            base.OutputFilterFunction = new ADGetCmdletBase <SearchADAccountParameterSet, ADAccountFactory <ADAccount>, ADAccount> .OutputFilterDelegate(this.FilterIsLockedOut);
                                        }
                                    }
                                    else
                                    {
                                        double inactiveTimeSpanDays = this.GetInactiveTimeSpanDays(cmdletSessionInfo);
                                        if (!nullable1.HasValue)
                                        {
                                            if (!nullable.HasValue)
                                            {
                                                DateTime now = DateTime.Now;
                                                dateTime = now.AddDays(-inactiveTimeSpanDays);
                                            }
                                            else
                                            {
                                                DateTime now1 = DateTime.Now;
                                                dateTime = now1.AddDays(-(nullable.Value + inactiveTimeSpanDays));
                                            }
                                        }
                                        else
                                        {
                                            DateTime value1 = nullable1.Value;
                                            dateTime = value1.AddDays(-inactiveTimeSpanDays);
                                        }
                                        aDOPathNodes.Add(ADOPathUtil.CreateNotClause(ADAccountFactory <ADAccount> .AttributeTable[cmdletSessionInfo.ConnectedADServerType]["LastLogonDate"].InvokeToSearcherConverter(ADOPathUtil.CreateFilterClause(ADOperator.Ge, "LastLogonDate", dateTime), cmdletSessionInfo)));
                                    }
                                }
                                else
                                {
                                    aDOPathNodes.Add(ADOPathUtil.CreateNotClause(ADAccountFactory <ADAccount> .AttributeTable[cmdletSessionInfo.ConnectedADServerType]["AccountExpirationDate"].InvokeToSearcherConverter(ADOPathUtil.CreateFilterClause(ADOperator.Ge, "AccountExpirationDate", DateTime.Now), cmdletSessionInfo)));
                                    aDOPathNodes.Add(ADAccountFactory <ADAccount> .AttributeTable[cmdletSessionInfo.ConnectedADServerType]["AccountExpirationDate"].InvokeToSearcherConverter(ADOPathUtil.CreateFilterClause(ADOperator.Like, "AccountExpirationDate", "*"), cmdletSessionInfo));
                                }
                            }
                            else
                            {
                                DateTime dateTime1 = DateTime.Now;
                                if (!nullable1.HasValue)
                                {
                                    if (!nullable.HasValue)
                                    {
                                        value = dateTime1.AddDays(5);
                                    }
                                    else
                                    {
                                        value = dateTime1.AddDays(nullable.Value);
                                    }
                                }
                                else
                                {
                                    value = nullable1.Value;
                                }
                                aDOPathNodes.Add(ADOPathUtil.CreateNotClause(ADAccountFactory <ADAccount> .AttributeTable[cmdletSessionInfo.ConnectedADServerType]["AccountExpirationDate"].InvokeToSearcherConverter(ADOPathUtil.CreateFilterClause(ADOperator.Ge, "AccountExpirationDate", value), cmdletSessionInfo)));
                                aDOPathNodes.Add(ADAccountFactory <ADAccount> .AttributeTable[cmdletSessionInfo.ConnectedADServerType]["AccountExpirationDate"].InvokeToSearcherConverter(ADOPathUtil.CreateFilterClause(ADOperator.Ge, "AccountExpirationDate", dateTime1), cmdletSessionInfo));
                            }
                        }
                        else
                        {
                            aDOPathNodes.Add(ADAccountFactory <ADAccount> .AttributeTable[cmdletSessionInfo.ConnectedADServerType]["PasswordExpired"].InvokeToSearcherConverter(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "PasswordExpired", true), cmdletSessionInfo));
                        }
                    }
                    else
                    {
                        aDOPathNodes.Add(ADAccountFactory <ADAccount> .AttributeTable[cmdletSessionInfo.ConnectedADServerType]["PasswordNeverExpires"].InvokeToSearcherConverter(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "PasswordNeverExpires", true), cmdletSessionInfo));
                    }
                }
                else
                {
                    aDOPathNodes.Add(ADAccountFactory <ADAccount> .AttributeTable[cmdletSessionInfo.ConnectedADServerType]["Enabled"].InvokeToSearcherConverter(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "Enabled", false), cmdletSessionInfo));
                }
                if (aDOPathNodes.Count <= 0)
                {
                    this.OutputSearchResults(null);
                }
                else
                {
                    if (aDOPathNodes.Count != 1)
                    {
                        item = ADOPathUtil.CreateAndClause(aDOPathNodes.ToArray());
                    }
                    else
                    {
                        item = aDOPathNodes[0];
                    }
                    this.OutputSearchResults(item);
                }
                return(true);
            }
            else
            {
                throw new ParameterBindingException(string.Format(StringResources.ParameterRequiredOnlyOne, string.Format("{0} {1}", "ComputersOnly", "UsersOnly")));
            }
        }
コード例 #22
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);
            }
        }