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; }
internal CompositeADOPathNode(ADOperator op, IADOPathNode[] exprList) { if (exprList != null) { if ((int)exprList.Length >= 2) { this._operator = op; this._childNodes = new List <IADOPathNode>(); IADOPathNode[] aDOPathNodeArray = exprList; for (int i = 0; i < (int)aDOPathNodeArray.Length; i++) { IADOPathNode aDOPathNode = aDOPathNodeArray[i]; this.AddExpressionToChildNodes(aDOPathNode); } return; } else { throw new ArgumentException(StringResources.ADFilterExprListLessThanTwo); } } else { throw new ArgumentNullException("exprList"); } }
internal CompositeADOPathNode(ADOperator op, IADOPathNode[] exprList) { if (exprList != null) { if ((int)exprList.Length >= 2) { this._operator = op; this._childNodes = new List<IADOPathNode>(); IADOPathNode[] aDOPathNodeArray = exprList; for (int i = 0; i < (int)aDOPathNodeArray.Length; i++) { IADOPathNode aDOPathNode = aDOPathNodeArray[i]; this.AddExpressionToChildNodes(aDOPathNode); } return; } else { throw new ArgumentException(StringResources.ADFilterExprListLessThanTwo); } } else { throw new ArgumentNullException("exprList"); } }
private static IADOPathNode BuildGPLinkFilter(string extendedAttribute, string directoryAttribute, IADOPathNode filterClause) { BinaryADOPathNode binaryADOPathNode = filterClause as BinaryADOPathNode; if (binaryADOPathNode != null) { IDataNode rightNode = binaryADOPathNode.RightNode as IDataNode; if (rightNode != null) { string dataObject = rightNode.DataObject as string; if (dataObject != null) { ADOperator @operator = binaryADOPathNode.Operator; if (@operator == ADOperator.Eq || @operator == ADOperator.Ne || @operator == ADOperator.Like || @operator == ADOperator.NotLike) { if (@operator != ADOperator.Eq) { if (@operator == ADOperator.Ne) { dataObject = ADOPathUtil.LdapSearchEncodeString(dataObject, true); @operator = ADOperator.NotLike; } } else { dataObject = ADOPathUtil.LdapSearchEncodeString(dataObject, true); @operator = ADOperator.Like; } dataObject = string.Concat(GPLinkUtil.GpLinkFilterPrefix, dataObject, GPLinkUtil.GpLinkFilterSuffix); return ADOPathUtil.CreateFilterClause(@operator, directoryAttribute, dataObject); } else { object[] str = new object[2]; ADOperator[] aDOperatorArray = new ADOperator[4]; aDOperatorArray[1] = ADOperator.Ne; aDOperatorArray[2] = ADOperator.Like; aDOperatorArray[3] = ADOperator.NotLike; str[0] = SearchConverters.ConvertOperatorListToString(aDOperatorArray); str[1] = extendedAttribute; throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterSupportedOperatorListErrorMessage, str)); } } else { object[] type = new object[2]; type[0] = rightNode.DataObject.GetType(); type[1] = extendedAttribute; throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterRHSInvalidType, type)); } } else { throw new ArgumentException(StringResources.SearchConverterRHSNotDataNode); } } else { throw new ArgumentException(StringResources.SearchConverterNotBinaryNode); } }
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); } }
private bool ADReplicationSiteRemovePreCommitFSRoutine(ADFactory <T> .DirectoryOperation operation, T instance, ADParameterSet parameters, ADObject directoryObj) { if (ADFactory <T> .DirectoryOperation.Delete == operation) { ADObjectFactory <ADObject> aDObjectFactory = new ADObjectFactory <ADObject>(); aDObjectFactory.SetCmdletSessionInfo(base.CmdletSessionInfo); IADOPathNode aDOPathNode = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "server"); int? nullable = null; int? nullable1 = null; IEnumerable <ADObject> extendedObjectFromFilter = aDObjectFactory.GetExtendedObjectFromFilter(aDOPathNode, directoryObj.DistinguishedName, ADSearchScope.Subtree, null, nullable, nullable1, false); IEnumerator <ADObject> enumerator = extendedObjectFromFilter.GetEnumerator(); using (enumerator) { if (enumerator.MoveNext()) { //TODO: Review: URGENT!! : enumerator.Current; object[] distinguishedName = new object[1]; distinguishedName[0] = directoryObj.DistinguishedName; throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.ServerContainerNotEmpty, distinguishedName)); } } return(false); } else { return(false); } }
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; } }
internal override IADOPathNode IdentitySearchConverter(object identity) { if (identity != null) { 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) { IADOPathNode aDOPathNode = base.IdentitySearchConverter(identity); return(aDOPathNode); } else { return(ADDomainUtil.CreateSidFilterClause(securityIdentifier)); } } else { throw new ArgumentNullException("Identity"); } }
internal override IADOPathNode BuildSearchFilter(IADOPathNode filter) { MappingTable <AttributeConverterEntry> item = ADNtdsSiteSettingFactory <ADNtdsSiteSetting> .AttributeTable[base.ConnectedStore]; MappingTable <AttributeConverterEntry> mappingTable = ADReplicationSiteFactory <T> .AttributeTable[base.ConnectedStore]; return(ADTopologyUtil.BuildSearchFilter(filter, mappingTable, item, base.CmdletSessionInfo)); }
internal static bool IsAttributeValueUsed <F, O>(string attributeName, string attributeValue, CmdletSessionInfo cmdletSessionInfo, string searchPath) where F : ADFactory <O>, new() where O : ADEntity, new() { bool flag; IADOPathNode aDOPathNode = ADOPathUtil.CreateFilterClause(ADOperator.Eq, attributeName, attributeValue); F f = Activator.CreateInstance <F>(); f.SetCmdletSessionInfo(cmdletSessionInfo); int? nullable = null; int? nullable1 = null; IEnumerable <O> extendedObjectFromFilter = f.GetExtendedObjectFromFilter(aDOPathNode, searchPath, ADSearchScope.Subtree, null, nullable, nullable1, false); IEnumerator <O> enumerator = extendedObjectFromFilter.GetEnumerator(); using (enumerator) { if (enumerator.MoveNext()) { //TODO: Review: enumerator.Current; flag = true; } else { return(false); } } return(flag); }
internal IADOPathNode AppendObjectClassFilter(IADOPathNode filter) { IADOPathNode[] structuralObjectFilter = new IADOPathNode[2]; structuralObjectFilter[0] = filter; structuralObjectFilter[1] = this._factory.StructuralObjectFilter; return(ADOPathUtil.CreateAndClause(structuralObjectFilter)); }
static ADPrincipalFactory() { ADPrincipalFactory <T> ._principalStructuralFilter = null; string[] strArrays = new string[1]; strArrays[0] = "sAMAccountName"; ADPrincipalFactory <T> ._principalIdentityLdapAttributes = 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] = IdentityResolverMethods.GetGenericIdentityResolver(ADPrincipalFactory <T> ._principalIdentityLdapAttributes); ADPrincipalFactory <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(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchUsingSchemaInfo)); attributeConverterEntry[1] = new AttributeConverterEntry(ADPrincipalFactory <T> .ADPrincipalPropertyMap.SID.PropertyName, ADPrincipalFactory <T> .ADPrincipalPropertyMap.SID.ADAttribute, TypeConstants.SID, false, TypeAdapterAccess.Read, true, AttributeSet.Default, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), null, new ToSearchFilterDelegate(SearchConverters.ToSearchUsingSchemaInfo)); attributeConverterEntry[2] = new AttributeConverterEntry(ADPrincipalFactory <T> .ADPrincipalPropertyMap.HomePage.PropertyName, ADPrincipalFactory <T> .ADPrincipalPropertyMap.HomePage.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(ADPrincipalFactory <T> .ADPrincipalPropertyMap.SIDHistory.PropertyName, ADPrincipalFactory <T> .ADPrincipalPropertyMap.SIDHistory.ADAttribute, TypeConstants.SID, false, TypeAdapterAccess.Read, false, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedMultivalueObject), null, new ToSearchFilterDelegate(SearchConverters.ToSearchUsingSchemaInfo)); attributeConverterEntry[4] = new AttributeConverterEntry(ADPrincipalFactory <T> .ADPrincipalPropertyMap.MemberOf.PropertyName, ADPrincipalFactory <T> .ADPrincipalPropertyMap.MemberOf.ADAttribute, TypeConstants.ADGroup, false, TypeAdapterAccess.Read, false, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedMultivalueObject), null, new ToSearchFilterDelegate(SearchConverters.ToSearchUsingSchemaInfo)); ADPrincipalFactory <T> .ADMappingTable = attributeConverterEntry; AttributeConverterEntry[] attributeConverterEntryArray = new AttributeConverterEntry[3]; attributeConverterEntryArray[0] = new AttributeConverterEntry(ADPrincipalFactory <T> .ADPrincipalPropertyMap.SID.PropertyName, ADPrincipalFactory <T> .ADPrincipalPropertyMap.SID.ADAMAttribute, TypeConstants.SID, false, TypeAdapterAccess.Read, true, AttributeSet.Default, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), null, new ToSearchFilterDelegate(SearchConverters.ToSearchUsingSchemaInfo)); attributeConverterEntryArray[1] = new AttributeConverterEntry(ADPrincipalFactory <T> .ADPrincipalPropertyMap.HomePage.PropertyName, ADPrincipalFactory <T> .ADPrincipalPropertyMap.HomePage.ADAMAttribute, TypeConstants.String, true, TypeAdapterAccess.ReadWrite, true, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchUsingSchemaInfo)); attributeConverterEntryArray[2] = new AttributeConverterEntry(ADPrincipalFactory <T> .ADPrincipalPropertyMap.MemberOf.PropertyName, ADPrincipalFactory <T> .ADPrincipalPropertyMap.MemberOf.ADAMAttribute, TypeConstants.ADGroup, false, TypeAdapterAccess.Read, false, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedMultivalueObject), null, new ToSearchFilterDelegate(SearchConverters.ToSearchUsingSchemaInfo)); ADPrincipalFactory <T> .ADAMMappingTable = attributeConverterEntryArray; IADOPathNode[] aDOPathNodeArray = new IADOPathNode[2]; aDOPathNodeArray[0] = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "group"); aDOPathNodeArray[1] = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "user"); ADPrincipalFactory <T> ._principalStructuralFilter = ADOPathUtil.CreateOrClause(aDOPathNodeArray); ADFactoryBase <T> .RegisterMappingTable(ADPrincipalFactory <T> .ADAMMappingTable, ADServerType.ADLDS); ADFactoryBase <T> .RegisterMappingTable(ADPrincipalFactory <T> .ADMappingTable, ADServerType.ADDS); }
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); }
internal virtual IADOPathNode BuildSearchFilter(IADOPathNode filter) { if (this.CmdletSessionInfo != null) { MappingTable <AttributeConverterEntry> item = ADFactoryBase <T> .AttributeTable[this.ConnectedStore]; BinaryADOPathNode binaryADOPathNode = filter as BinaryADOPathNode; if (binaryADOPathNode == null) { return(null); } else { string ldapFilterString = binaryADOPathNode.LeftNode.GetLdapFilterString(); AttributeConverterEntry attributeConverterEntry = null; if (!item.TryGetValue(ldapFilterString, out attributeConverterEntry)) { string[] strArrays = new string[1]; strArrays[0] = ldapFilterString; return(SearchConverters.ToSearchUsingSchemaInfo(ldapFilterString, strArrays, filter, this.CmdletSessionInfo)); } else { return(attributeConverterEntry.InvokeToSearcherConverter(filter, this.CmdletSessionInfo)); } } } else { throw new ArgumentNullException(StringResources.SessionRequired); } }
internal static IADOPathNode BuildSearchFilter(IADOPathNode filter, MappingTable <AttributeConverterEntry> attrMapBaseObj, MappingTable <AttributeConverterEntry> attrMapChildObj, CmdletSessionInfo sessionInfo) { BinaryADOPathNode binaryADOPathNode = filter as BinaryADOPathNode; if (binaryADOPathNode == null) { return(null); } else { string ldapFilterString = binaryADOPathNode.LeftNode.GetLdapFilterString(); AttributeConverterEntry attributeConverterEntry = null; if (!attrMapBaseObj.TryGetValue(ldapFilterString, out attributeConverterEntry)) { if (!attrMapChildObj.TryGetValue(ldapFilterString, out attributeConverterEntry)) { string[] strArrays = new string[1]; strArrays[0] = ldapFilterString; return(SearchConverters.ToSearchObjectClientSideFilter(ldapFilterString, strArrays, filter, sessionInfo)); } else { return(attributeConverterEntry.InvokeToSearcherConverter(filter, sessionInfo)); } } else { return(attributeConverterEntry.InvokeToSearcherConverter(filter, sessionInfo)); } } }
static ADDirectoryServerFactory() { IADOPathNode[] aDOPathNodeArray = new IADOPathNode[2]; aDOPathNodeArray[0] = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "nTDSDSA"); aDOPathNodeArray[1] = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "server"); ADDirectoryServerFactory <T> ._directoryServerStructuralFilter = ADOPathUtil.CreateOrClause(aDOPathNodeArray); string[] strArrays = new string[6]; strArrays[0] = "name"; strArrays[1] = "distinguishedName"; strArrays[2] = "objectClass"; strArrays[3] = "objectGUID"; strArrays[4] = "dNSHostName"; strArrays[5] = "serverReferenceBL"; ADDirectoryServerFactory <T> ._directoryServerDefaultAttributes = strArrays; AttributeConverterEntry[] attributeConverterEntry = new AttributeConverterEntry[14]; attributeConverterEntry[0] = new AttributeConverterEntry("Name", "Name", TypeConstants.String, false, TypeAdapterAccess.Read, true, AttributeSet.Default, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchObjectClientSideFilter)); attributeConverterEntry[1] = new AttributeConverterEntry("Site", "Site", TypeConstants.String, false, TypeAdapterAccess.Read, true, AttributeSet.Default, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchObjectClientSideFilter)); attributeConverterEntry[2] = new AttributeConverterEntry("IPv4Address", "HostName", TypeConstants.String, false, TypeAdapterAccess.Read, true, AttributeSet.Default, new ToExtendedFormatDelegate(ADComputerFactory <ADComputer> .ToExtendedIPv4), null, new ToSearchFilterDelegate(SearchConverters.ToSearchObjectClientSideFilter)); attributeConverterEntry[3] = new AttributeConverterEntry("IPv6Address", "HostName", TypeConstants.String, false, TypeAdapterAccess.Read, true, AttributeSet.Default, new ToExtendedFormatDelegate(ADComputerFactory <ADComputer> .ToExtendedIPv6), null, new ToSearchFilterDelegate(SearchConverters.ToSearchObjectClientSideFilter)); attributeConverterEntry[4] = new AttributeConverterEntry("Partitions", "Partitions", TypeConstants.String, false, TypeAdapterAccess.Read, false, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchObjectClientSideFilter)); attributeConverterEntry[5] = new AttributeConverterEntry("DefaultPartition", "DefaultPartition", TypeConstants.String, false, TypeAdapterAccess.Read, true, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchObjectClientSideFilter)); attributeConverterEntry[6] = new AttributeConverterEntry("HostName", "HostName", TypeConstants.String, false, TypeAdapterAccess.Read, true, AttributeSet.Default, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchObjectClientSideFilter)); attributeConverterEntry[7] = new AttributeConverterEntry("LdapPort", "LdapPort", TypeConstants.Int, false, TypeAdapterAccess.Read, true, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchObjectClientSideFilter)); attributeConverterEntry[8] = new AttributeConverterEntry("SslPort", "SslPort", TypeConstants.Int, false, TypeAdapterAccess.Read, true, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchObjectClientSideFilter)); attributeConverterEntry[9] = new AttributeConverterEntry("OperationMasterRoles", "OperationMasterRole", TypeConstants.ADOperationMasterRole, false, TypeAdapterAccess.Read, false, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchObjectClientSideFilter)); attributeConverterEntry[10] = new AttributeConverterEntry("NTDSSettingsObjectDN", "NTDSSettingsObjectDN", TypeConstants.String, false, TypeAdapterAccess.Read, true, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchObjectClientSideFilter)); attributeConverterEntry[11] = new AttributeConverterEntry("ServerObjectDN", "ServerObjectDN", TypeConstants.String, false, TypeAdapterAccess.Read, true, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchObjectClientSideFilter)); attributeConverterEntry[12] = new AttributeConverterEntry("ServerObjectGuid", "ServerObjectGuid", TypeConstants.Guid, false, TypeAdapterAccess.Read, true, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchObjectClientSideFilter)); attributeConverterEntry[13] = new AttributeConverterEntry("InvocationId", "InvocationId", TypeConstants.Guid, false, TypeAdapterAccess.Read, true, AttributeSet.Extended, new ToExtendedFormatDelegate(AttributeConverters.ToExtendedObject), new ToDirectoryFormatDelegate(AttributeConverters.ToDirectoryObject), new ToSearchFilterDelegate(SearchConverters.ToSearchObjectClientSideFilter)); ADDirectoryServerFactory <T> .ADMappingTable = attributeConverterEntry; ADDirectoryServerFactory <T> .ADAMMappingTable = ADDirectoryServerFactory <T> .ADMappingTable; ADFactoryBase <T> .RegisterMappingTable(ADDirectoryServerFactory <T> .ADAMMappingTable, ADServerType.ADLDS); ADFactoryBase <T> .RegisterMappingTable(ADDirectoryServerFactory <T> .ADMappingTable, ADServerType.ADDS); }
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); } } } }
internal string GetRDNPrefix(string objectClass) { ADObject aDObject; ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(this._sessionInfo); using (aDObjectSearcher) { ADRootDSE rootDSE = aDObjectSearcher.GetRootDSE(); aDObjectSearcher.SearchRoot = rootDSE.SchemaNamingContext; aDObjectSearcher.Properties.Add("rDNAttID"); IADOPathNode aDOPathNode = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "classSchema"); IADOPathNode aDOPathNode1 = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "lDAPDisplayName", objectClass); IADOPathNode[] aDOPathNodeArray = new IADOPathNode[2]; aDOPathNodeArray[0] = aDOPathNode; aDOPathNodeArray[1] = aDOPathNode1; IADOPathNode aDOPathNode2 = ADOPathUtil.CreateAndClause(aDOPathNodeArray); aDObjectSearcher.Filter = aDOPathNode2; aDObject = aDObjectSearcher.FindOne(); } if (aDObject == null) { return(null); } else { return((string)aDObject["rDNAttID"][0]); } }
private void AddSchemaClassObjects(ADObjectSearcher searcher, ADSchema adSchema) { searcher.SchemaTranslation = false; ADRootDSE rootDSE = searcher.GetRootDSE(); searcher.SearchRoot = rootDSE.SchemaNamingContext; IADOPathNode aDOPathNode = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "classSchema"); IADOPathNode aDOPathNode1 = ADOPathUtil.CreateFilterClause(ADOperator.NotLike, "isDefunct", "*"); IADOPathNode[] aDOPathNodeArray = new IADOPathNode[2]; aDOPathNodeArray[0] = aDOPathNode; aDOPathNodeArray[1] = aDOPathNode1; searcher.Filter = ADOPathUtil.CreateAndClause(aDOPathNodeArray); searcher.Scope = ADSearchScope.Subtree; searcher.PageSize = 0x100; searcher.Properties.Clear(); searcher.Properties.Add("lDAPDisplayName"); searcher.Properties.Add("subClassOf"); searcher.Properties.Add("systemMayContain"); searcher.Properties.Add("mayContain"); searcher.Properties.Add("mustContain"); searcher.Properties.Add("systemMustContain"); searcher.Properties.Add("auxiliaryClass"); searcher.Properties.Add("systemAuxiliaryClass"); IEnumerable<ADObject> aDObjects = searcher.FindAll(); foreach (ADObject aDObject in aDObjects) { if (!aDObject.Contains("lDAPDisplayName") || aDObject["lDAPDisplayName"].Value == null) { continue; } adSchema._schemaClasses.Add((string)aDObject["lDAPDisplayName"].Value, aDObject); adSchema._schemaClassesDnHash.Add((string)aDObject["distinguishedName"].Value, (string)aDObject["lDAPDisplayName"].Value); } }
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)); } }
internal static List <IADOPathNode> BuildComputerSamAccountNameIdentityFilter(string identity, List <IADOPathNode> baseList) { if (!identity.EndsWith("$", StringComparison.OrdinalIgnoreCase)) { IADOPathNode aDOPathNode = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "sAMAccountName", string.Concat(identity, "$")); baseList.Add(aDOPathNode); } return(baseList); }
internal static IADOPathNode ToSearchComputerSamAccountName(string extendedAttribute, string[] directoryAttributes, IADOPathNode filterClause, CmdletSessionInfo cmdletSessionInfo) { BinaryADOPathNode binaryADOPathNode = filterClause as BinaryADOPathNode; if (binaryADOPathNode != null) { IDataNode rightNode = binaryADOPathNode.RightNode as IDataNode; if (rightNode != null) { string dataObject = rightNode.DataObject as string; if (dataObject != null) { bool flag = dataObject.EndsWith("$", StringComparison.OrdinalIgnoreCase); bool flag1 = dataObject.EndsWith("*", StringComparison.OrdinalIgnoreCase); ADOperator @operator = binaryADOPathNode.Operator; if ((@operator == ADOperator.Eq || @operator == ADOperator.Ne) && !flag) { object[] objArray = new object[3]; objArray[0] = extendedAttribute; objArray[1] = "$"; objArray[2] = filterClause; cmdletSessionInfo.CmdletMessageWriter.WriteWarningBuffered(string.Format(CultureInfo.CurrentCulture, StringResources.WarningSamAccountNameClauseLacksDollarSign, objArray)); } else { if ((@operator == ADOperator.Like || @operator == ADOperator.NotLike) && !flag && !flag1) { object[] objArray1 = new object[3]; objArray1[0] = extendedAttribute; objArray1[1] = "$"; objArray1[2] = filterClause; cmdletSessionInfo.CmdletMessageWriter.WriteWarningBuffered(string.Format(CultureInfo.CurrentCulture, StringResources.WarningSamAccountNameClauseLacksDollarSign, objArray1)); } } return(SearchConverters.ToSearchObject(extendedAttribute, directoryAttributes, filterClause, cmdletSessionInfo)); } else { object[] type = new object[2]; type[0] = rightNode.DataObject.GetType(); type[1] = extendedAttribute; throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterRHSInvalidType, type)); } } else { throw new ArgumentException(StringResources.SearchConverterRHSNotDataNode); } } else { throw new ArgumentException(StringResources.SearchConverterNotBinaryNode); } }
private static ADObjectSearcher BuildADOFGuidSearcher(Guid guidObject, string searchBase, CmdletSessionInfo cmdletSessionInfo) { ADObjectSearcher aDObjectSearcher = SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, searchBase, ADSearchScope.Subtree); IADOPathNode aDOPathNode = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectGUID", guidObject.ToByteArray()); IADOPathNode aDOPathNode1 = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "msDS-OptionalFeatureGUID", guidObject.ToByteArray()); IADOPathNode[] aDOPathNodeArray = new IADOPathNode[2]; aDOPathNodeArray[0] = aDOPathNode; aDOPathNodeArray[1] = aDOPathNode1; aDObjectSearcher.Filter = ADOPathUtil.CreateOrClause(aDOPathNodeArray); return(aDObjectSearcher); }
internal UnaryADOPathNode(ADOperator op, IADOPathNode expr) { if (expr != null) { this._operator = op; this._childExpr = expr; return; } else { throw new ArgumentNullException("expr"); } }
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)); } }
private void AddExpressionToChildNodes(IADOPathNode expr) { CompositeADOPathNode compositeADOPathNode = expr as CompositeADOPathNode; if (compositeADOPathNode == null || compositeADOPathNode._operator != this._operator) { this._childNodes.Add(expr); } else { foreach (IADOPathNode _childNode in compositeADOPathNode._childNodes) { this._childNodes.Add(_childNode); } } }
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"); } }
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); } }
private bool ADGetCmdletBaseBeginCSRoutine() { IADOPathNode ldapFilterADOPathNode = null; bool flag = false; this._showDeleted = this._cmdletParameters.GetSwitchParameterBooleanValue("IncludeDeletedObjects"); if (this._cmdletParameters.Contains("Filter") || this._cmdletParameters.Contains("LDAPFilter")) { CmdletSessionInfo cmdletSessionInfo = this.GetCmdletSessionInfo(); this._factory.SetCmdletSessionInfo(cmdletSessionInfo); this.ValidateParameters(); this.BuildPropertySet(); } if (!this._cmdletParameters.Contains("Filter")) { if (this._cmdletParameters.Contains("LDAPFilter")) { ldapFilterADOPathNode = new LdapFilterADOPathNode(this._cmdletParameters["LDAPFilter"] as string); flag = true; } } else { string item = this._cmdletParameters["Filter"] as string; try { var obj = this._factory; ConvertSearchFilterDelegate convertSearchFilterDelegate = new ConvertSearchFilterDelegate(obj.BuildSearchFilter); VariableExpressionConverter variableExpressionConverter = new VariableExpressionConverter(new EvaluateVariableDelegate(this.EvaluateFilterVariable)); QueryParser queryParser = new QueryParser(item, variableExpressionConverter, convertSearchFilterDelegate); ldapFilterADOPathNode = queryParser.FilterExpressionTree; } catch (ADFilterParsingException aDFilterParsingException1) { ADFilterParsingException aDFilterParsingException = aDFilterParsingException1; base.ThrowTerminatingError(base.ConstructErrorRecord(aDFilterParsingException)); } flag = true; } this._filterProcessed = flag; if (flag) { this.OutputSearchResults(ldapFilterADOPathNode); } return(true); }
private void AddSessionFromSiteDN(string siteDN) { IADOPathNode aDOPathNode = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "server"); List <string> strs = new List <string>(); strs.Add("dNSHostName"); 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=Servers,", siteDN), ADSearchScope.OneLevel, strs1, nullable, nullable1, false); foreach (ADObject aDObject in extendedObjectFromFilter) { this._sessionPipe.AddLast(new ADSessionInfo(aDObject["dNSHostName"].Value as string)); } }
private void AddSessionsFromConnectedForest() { IADOPathNode aDOPathNode = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "server"); List <string> strs = new List <string>(); strs.Add("dNSHostName"); 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.Subtree, strs1, nullable, nullable1, false); foreach (ADObject aDObject in extendedObjectFromFilter) { this._sessionPipe.AddLast(new ADSessionInfo(aDObject["dNSHostName"].Value as string)); } }
private void ReadObjectSchema(ADObjectSearcher searcher, ADSchema adSchema) { searcher.SchemaTranslation = false; ADRootDSE rootDSE = searcher.GetRootDSE(); searcher.SearchRoot = rootDSE.SchemaNamingContext; IADOPathNode[] aDOPathNodeArray = new IADOPathNode[3]; aDOPathNodeArray[0] = ADOPathUtil.CreateNotClause(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "isDefunct", true)); aDOPathNodeArray[1] = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "attributeSchema"); IADOPathNode[] aDOPathNodeArray1 = new IADOPathNode[3]; aDOPathNodeArray1[0] = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "attributeSyntax", SchemaConstants.SidAttributeSyntax); aDOPathNodeArray1[1] = ADOPathUtil.CreateFilterClause(ADOperator.Like, "linkID", "*"); aDOPathNodeArray1[2] = ADOPathUtil.CreateFilterClause(ADOperator.Band, "systemFlags", SchemaConstants.systemFlagsConstructedBitMask); aDOPathNodeArray[2] = ADOPathUtil.CreateOrClause(aDOPathNodeArray1); searcher.Filter = ADOPathUtil.CreateAndClause(aDOPathNodeArray); searcher.Scope = ADSearchScope.Subtree; searcher.PageSize = 0x100; searcher.Properties.Clear(); searcher.Properties.Add("lDAPDisplayName"); searcher.Properties.Add("linkID"); searcher.Properties.Add("systemFlags"); searcher.Properties.Add("attributeSyntax"); IEnumerable <ADObject> aDObjects = searcher.FindAll(); foreach (ADObject nullable in aDObjects) { if (adSchema._schemaProperties.ContainsKey((string)nullable["lDAPDisplayName"].Value)) { if (nullable.Contains("linkID")) { adSchema._schemaProperties[(string)nullable["lDAPDisplayName"].Value].LinkID = new int?(int.Parse(nullable["linkID"].Value as string, NumberFormatInfo.InvariantInfo)); } if (nullable.Contains("systemFlags") && (long)0 != (ulong.Parse(nullable["systemFlags"].Value as string, NumberFormatInfo.InvariantInfo) & SchemaConstants.systemFlagsConstructedBitMask)) { adSchema._schemaProperties[(string)nullable["lDAPDisplayName"].Value].IsConstructed = true; } if (!nullable.Contains("attributeSyntax") || string.Compare(nullable["attributeSyntax"].Value as string, SchemaConstants.SidAttributeSyntax, true) != 0) { continue; } adSchema._schemaProperties[(string)nullable["lDAPDisplayName"].Value].Syntax = ADAttributeSyntax.Sid; } } }
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); }
internal static IADOPathNode BuildIPFilter(string extendedAttribute, string directoryAttribute, IADOPathNode filterClause, IPUtil.IPVersion ipVersion) { BinaryADOPathNode binaryADOPathNode = filterClause as BinaryADOPathNode; if (binaryADOPathNode != null) { IDataNode rightNode = binaryADOPathNode.RightNode as IDataNode; if (rightNode != null) { if (rightNode.DataObject as string != null) { ADOperator @operator = binaryADOPathNode.Operator; if (@operator == ADOperator.Eq || @operator == ADOperator.Ne) { return IPUtil.BuildHostFilterFromIP(rightNode.DataObject as string, ipVersion, extendedAttribute, directoryAttribute, @operator); } else { object[] str = new object[2]; ADOperator[] aDOperatorArray = new ADOperator[2]; aDOperatorArray[1] = ADOperator.Ne; str[0] = SearchConverters.ConvertOperatorListToString(aDOperatorArray); str[1] = extendedAttribute; throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterSupportedOperatorListErrorMessage, str)); } } else { object[] type = new object[2]; type[0] = rightNode.DataObject.GetType(); type[1] = extendedAttribute; throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterRHSInvalidType, type)); } } else { throw new ArgumentException(StringResources.SearchConverterRHSNotDataNode); } } else { throw new ArgumentException(StringResources.SearchConverterNotBinaryNode); } }
internal static IADOPathNode ToSearchMultivalueCertificate(string extendedAttribute, string[] directoryAttributes, IADOPathNode filterClause, CmdletSessionInfo cmdletSessionInfo) { BinaryADOPathNode binaryADOPathNode = filterClause as BinaryADOPathNode; if (binaryADOPathNode == null) { throw new ArgumentException(StringResources.SearchConverterNotBinaryNode); } else { if (binaryADOPathNode.Operator == ADOperator.Eq || binaryADOPathNode.Operator == ADOperator.Ne) { IDataNode rightNode = binaryADOPathNode.RightNode as IDataNode; if (rightNode == null) { throw new ArgumentException(StringResources.SearchConverterRHSNotDataNode); } else { X509Certificate dataObject = rightNode.DataObject as X509Certificate; if (dataObject != null) { IADOPathNode aDOPathNode = ADOPathUtil.CreateFilterClause(binaryADOPathNode.Operator, directoryAttributes[0], dataObject.GetRawCertData()); return(aDOPathNode); } else { throw new ArgumentException(StringResources.SearchConverterInvalidValue); } } } else { object[] str = new object[2]; ADOperator[] aDOperatorArray = new ADOperator[2]; aDOperatorArray[1] = ADOperator.Ne; str[0] = SearchConverters.ConvertOperatorListToString(aDOperatorArray); str[1] = extendedAttribute; throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterSupportedOperatorListErrorMessage, str)); } } }
internal static IdentityResolverDelegate GetGenericIdentityResolverWithSamName(string[] identityLdapAttributes) { return (object identityObject, string searchBase, CmdletSessionInfo cmdletSessionInfo, out bool useSearchFilter) => { useSearchFilter = true; ADObjectSearcher aDObjectSearcher = IdentityResolverMethods.BuildGenericSearcher(identityLdapAttributes, identityObject, searchBase, cmdletSessionInfo, out useSearchFilter); if (aDObjectSearcher != null) { string str = identityObject as string; if (str != null && !str.EndsWith("$", StringComparison.OrdinalIgnoreCase)) { IADOPathNode aDOPathNode = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "sAMAccountName", string.Concat(str, "$")); IADOPathNode[] filter = new IADOPathNode[2]; filter[0] = aDObjectSearcher.Filter; filter[1] = aDOPathNode; aDObjectSearcher.Filter = ADOPathUtil.CreateOrClause(filter); } } return aDObjectSearcher; } ; }
internal virtual IADOPathNode InvokeToSearcherConverter(IADOPathNode filter, CmdletSessionInfo cmdletSessionInfo) { return this._toSearchDelegate(base.ExtendedAttribute, this.DirectoryAttributes, filter, cmdletSessionInfo); }
internal static IADOPathNode ToSearchGPLink(string extendedAttribute, string[] directoryAttributes, IADOPathNode filterClause, CmdletSessionInfo cmdletSessionInfo) { return GPLinkUtil.BuildGPLinkFilter(extendedAttribute, directoryAttributes[0], filterClause); }
internal static string ChangeNodeToWhereFilterSyntax(IADOPathNode node) { if (node != null) { if (node as UnaryADOPathNode == null) { if (node as BinaryADOPathNode == null) { if (node as TextDataADOPathNode == null) { if (node as VariableADOPathNode == null) { if (node as CompositeADOPathNode == null) { if (node as IDataNode == null) { object[] type = new object[1]; type[0] = node.GetType(); throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Node type: {0} not supported", type)); } else { IDataNode dataNode = (IDataNode)node; return dataNode.DataObject.ToString(); } } else { CompositeADOPathNode compositeADOPathNode = (CompositeADOPathNode)node; StringBuilder stringBuilder = new StringBuilder("( "); int num = 0; foreach (IADOPathNode childNode in compositeADOPathNode.ChildNodes) { if (num > 0) { stringBuilder.Append(" -"); stringBuilder.Append(compositeADOPathNode.Operator); stringBuilder.Append(" "); } stringBuilder.Append(ADOPathUtil.ChangeNodeToWhereFilterSyntax(childNode)); num++; } stringBuilder.Append(" )"); return stringBuilder.ToString(); } } else { VariableADOPathNode variableADOPathNode = (VariableADOPathNode)node; return string.Concat("$", variableADOPathNode.VariableExpression); } } else { TextDataADOPathNode textDataADOPathNode = (TextDataADOPathNode)node; return string.Concat("\"", textDataADOPathNode.TextValue, "\""); } } else { BinaryADOPathNode binaryADOPathNode = (BinaryADOPathNode)node; if (binaryADOPathNode.Operator == ADOperator.Approx || binaryADOPathNode.Operator == ADOperator.RecursiveMatch) { object[] str = new object[1]; str[0] = binaryADOPathNode.Operator.ToString(); throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Operator type: {0} is not supported", str)); } else { StringBuilder stringBuilder1 = new StringBuilder("( "); if (binaryADOPathNode.LeftNode as VariableADOPathNode == null) { stringBuilder1.Append("$_."); stringBuilder1.Append(ADOPathUtil.ChangeNodeToWhereFilterSyntax(binaryADOPathNode.LeftNode)); } else { IDataNode leftNode = (VariableADOPathNode)binaryADOPathNode.LeftNode; stringBuilder1.Append("$_."); stringBuilder1.Append(leftNode.DataObject.ToString()); } if (ADOperator.Like != binaryADOPathNode.Operator || string.Compare(binaryADOPathNode.RightNode.GetLdapFilterString(), "*", StringComparison.OrdinalIgnoreCase) != 0) { stringBuilder1.Append(" -"); stringBuilder1.Append(binaryADOPathNode.Operator.ToString()); stringBuilder1.Append(" "); stringBuilder1.Append(ADOPathUtil.ChangeNodeToWhereFilterSyntax(binaryADOPathNode.RightNode)); stringBuilder1.Append(" )"); } else { stringBuilder1.Append(" -"); stringBuilder1.Append(ADOperator.Ne.ToString()); stringBuilder1.Append(" "); stringBuilder1.Append("$null"); stringBuilder1.Append(" )"); } return stringBuilder1.ToString(); } } } else { UnaryADOPathNode unaryADOPathNode = (UnaryADOPathNode)node; StringBuilder stringBuilder2 = new StringBuilder("-"); stringBuilder2.Append(unaryADOPathNode.Operator.ToString()); stringBuilder2.Append("( "); stringBuilder2.Append(ADOPathUtil.ChangeNodeToWhereFilterSyntax(unaryADOPathNode.ChildNode)); stringBuilder2.Append(" )"); return stringBuilder2.ToString(); } } else { throw new ArgumentNullException("node"); } }
private HashSet<string> GetUserSubClasses(ADObjectSearcher searcher, ADRootDSE rootDSE) { HashSet<string> strs = new HashSet<string>(StringComparer.OrdinalIgnoreCase); searcher.SearchRoot = rootDSE.SchemaNamingContext; searcher.Properties.Add("lDAPDisplayName"); string str = string.Concat("CN=Person,", rootDSE.SchemaNamingContext); IADOPathNode aDOPathNode = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "classSchema"); IADOPathNode aDOPathNode1 = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "subClassOf", "user"); IADOPathNode aDOPathNode2 = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "defaultObjectCategory", str); IADOPathNode[] aDOPathNodeArray = new IADOPathNode[2]; aDOPathNodeArray[0] = aDOPathNode; IADOPathNode[] aDOPathNodeArray1 = new IADOPathNode[2]; aDOPathNodeArray1[0] = aDOPathNode1; aDOPathNodeArray1[1] = aDOPathNode2; aDOPathNodeArray[1] = ADOPathUtil.CreateAndClause(aDOPathNodeArray1); IADOPathNode aDOPathNode3 = ADOPathUtil.CreateAndClause(aDOPathNodeArray); searcher.Filter = aDOPathNode3; IEnumerable<ADObject> aDObjects = searcher.FindAll(); foreach (ADObject aDObject in aDObjects) { var ldapDisplayName = aDObject["lDAPDisplayName"]; if (ldapDisplayName != null) { if (ldapDisplayName.Count > 0) { strs.Add((string)ldapDisplayName[0]); } } } strs.Add("user"); return strs; }
internal static IADOPathNode CreateRelationalExpressionNode(ADOperator op, IADOPathNode leftExpr, IADOPathNode rightExpr, ConvertSearchFilterDelegate searchFilterConverter) { if (op == ADOperator.Eq || op == ADOperator.Ne) { VariableADOPathNode variableADOPathNode = rightExpr as VariableADOPathNode; if (variableADOPathNode != null) { variableADOPathNode.EncodeAsteriskChar = true; } TextDataADOPathNode textDataADOPathNode = rightExpr as TextDataADOPathNode; if (textDataADOPathNode != null) { textDataADOPathNode.EncodeAsteriskChar = true; } } IADOPathNode binaryADOPathNode = new BinaryADOPathNode(op, leftExpr, rightExpr); if (searchFilterConverter != null) { binaryADOPathNode = searchFilterConverter(binaryADOPathNode); } return binaryADOPathNode; }
private int yyparse() { int num; int num2; this.init_stacks(); this.yynerrs = 0; this.yyerrflag = 0; this.yychar = -1; int state = 0; this.state_push(state); Label_0025: num = yydefred[state]; if (num == 0) { if (this.yychar < 0) { this.yychar = this.yylex(); if (this.yychar < 0) { this.yychar = 0; } } num = yysindex[state]; if (((num != 0) && ((num += this.yychar) >= 0)) && ((num <= YYTABLESIZE) && (yycheck[num] == this.yychar))) { state = yytable[num]; this.state_push(state); this.val_push(this.yylval); this.yychar = -1; if (this.yyerrflag > 0) { this.yyerrflag--; } } else { num = yyrindex[state]; if (((num != 0) && ((num += this.yychar) >= 0)) && ((num <= YYTABLESIZE) && (yycheck[num] == this.yychar))) { num = yytable[num]; goto Label_01D9; } if (this.yyerrflag == 0) { this.yyerror("syntax error"); this.yynerrs++; } if (this.yyerrflag < 3) { this.yyerrflag = 3; while (true) { if (this.stateptr < 0) { goto Label_0849; } num = yysindex[this.state_peek(0)]; if (((num != 0) && ((num += YYERRCODE) >= 0)) && ((num <= YYTABLESIZE) && (yycheck[num] == YYERRCODE))) { if (this.stateptr < 0) { goto Label_0849; } state = yytable[num]; this.state_push(state); this.val_push(this.yylval); goto Label_0025; } if (this.stateptr < 0) { goto Label_0849; } this.state_pop(); this.val_pop(); } } if (this.yychar == 0) { goto Label_0854; } this.yychar = -1; } goto Label_0025; } Label_01D9: num2 = yylen[num]; this.yyval = this.val_peek(num2 - 1); switch (num) { case 1: this._filterExprTree = null; break; case 2: this._filterExprTree = (IADOPathNode) this.val_peek(1); break; case 3: this.yyval = this.val_peek(0); break; case 4: this.yyval = new CompositeADOPathNode(ADOperator.And, new IADOPathNode[] { (IADOPathNode) this.val_peek(2), (IADOPathNode) this.val_peek(0) }); break; case 5: this.yyval = new CompositeADOPathNode(ADOperator.Or, new IADOPathNode[] { (IADOPathNode) this.val_peek(2), (IADOPathNode) this.val_peek(0) }); break; case 6: this.yyval = this.val_peek(1); break; case 7: this.yyval = new UnaryADOPathNode(ADOperator.Not, (IADOPathNode) this.val_peek(0)); break; case 8: this.yyval = this.val_peek(1); break; case 9: this.yyval = ADOPathUtil.CreateRelationalExpressionNode(ADOperator.Eq, (IADOPathNode) this.val_peek(2), (IADOPathNode) this.val_peek(0), this._searchFilterConverter); break; case 10: this.yyval = ADOPathUtil.CreateRelationalExpressionNode(ADOperator.Ne, (IADOPathNode) this.val_peek(2), (IADOPathNode) this.val_peek(0), this._searchFilterConverter); break; case 11: this.yyval = ADOPathUtil.CreateRelationalExpressionNode(ADOperator.Gt, (IADOPathNode) this.val_peek(2), (IADOPathNode) this.val_peek(0), this._searchFilterConverter); break; case 12: this.yyval = ADOPathUtil.CreateRelationalExpressionNode(ADOperator.Lt, (IADOPathNode) this.val_peek(2), (IADOPathNode) this.val_peek(0), this._searchFilterConverter); break; case 13: this.yyval = ADOPathUtil.CreateRelationalExpressionNode(ADOperator.Ge, (IADOPathNode) this.val_peek(2), (IADOPathNode) this.val_peek(0), this._searchFilterConverter); break; case 14: this.yyval = ADOPathUtil.CreateRelationalExpressionNode(ADOperator.Le, (IADOPathNode) this.val_peek(2), (IADOPathNode) this.val_peek(0), this._searchFilterConverter); break; case 15: this.yyval = ADOPathUtil.CreateRelationalExpressionNode(ADOperator.Like, (IADOPathNode) this.val_peek(2), (IADOPathNode) this.val_peek(0), this._searchFilterConverter); break; case 0x10: this.yyval = ADOPathUtil.CreateRelationalExpressionNode(ADOperator.NotLike, (IADOPathNode) this.val_peek(2), (IADOPathNode) this.val_peek(0), this._searchFilterConverter); break; case 0x11: this.yyval = ADOPathUtil.CreateRelationalExpressionNode(ADOperator.Approx, (IADOPathNode) this.val_peek(2), (IADOPathNode) this.val_peek(0), this._searchFilterConverter); break; case 0x12: this.yyval = ADOPathUtil.CreateRelationalExpressionNode(ADOperator.Band, (IADOPathNode) this.val_peek(2), (IADOPathNode) this.val_peek(0), this._searchFilterConverter); break; case 0x13: this.yyval = ADOPathUtil.CreateRelationalExpressionNode(ADOperator.Bor, (IADOPathNode) this.val_peek(2), (IADOPathNode) this.val_peek(0), this._searchFilterConverter); break; case 20: this.yyval = ADOPathUtil.CreateRelationalExpressionNode(ADOperator.RecursiveMatch, (IADOPathNode) this.val_peek(2), (IADOPathNode) this.val_peek(0), this._searchFilterConverter); break; case 0x15: this.yyval = this.val_peek(1); break; case 0x16: if (this.val_peek(0) != null) { throw new ADFilterParsingException(this._query, "Operator Not supported: " + this.lexer.yytext(), this.pos + 1); } break; case 0x17: this.yyval = this.val_peek(0); break; case 0x18: { string data = this.lexer.yytext().Substring(1, this.lexer.yytext().Length - 2).Replace("''", "'"); this.yyval = new TextDataADOPathNode(data); break; } case 0x19: { string str2 = this.lexer.yytext().Substring(1, this.lexer.yytext().Length - 2).Replace("`\"", "\""); this.yyval = new TextDataADOPathNode(str2); break; } case 0x1a: this.yyval = new NumberADOPathNode(this.lexer.yytext()); break; case 0x1b: this.yyval = new NumberADOPathNode(this.lexer.yytext()); break; case 0x1c: this.yyval = this.val_peek(0); break; case 0x1d: this.yyval = new PropertyADOPathNode(this.lexer.yytext()); break; case 30: { string varNameStr = this.lexer.yytext().Substring(1); this.yyval = new VariableADOPathNode(varNameStr, new EvaluateVariableDelegate(this._varExpressionConverter.GetVariableExpressionValue)); break; } case 0x1f: { string str4 = this.lexer.yytext(); str4 = str4.Substring(2, str4.Length - 2); int index = str4.IndexOf("}"); str4 = str4.Remove(index, 1); this.yyval = new VariableADOPathNode(str4, new EvaluateVariableDelegate(this._varExpressionConverter.GetVariableExpressionValue)); break; } } this.state_drop(num2); state = this.state_peek(0); this.val_drop(num2); num2 = yylhs[num]; if ((state == 0) && (num2 == 0)) { state = YYFINAL; this.state_push(YYFINAL); this.val_push(this.yyval); if (this.yychar < 0) { this.yychar = this.yylex(); if (this.yychar < 0) { this.yychar = 0; } } if (this.yychar == 0) { return 0; } goto Label_0025; } num = yygindex[num2]; if (((num != 0) && ((num += state) >= 0)) && ((num <= YYTABLESIZE) && (yycheck[num] == state))) { state = yytable[num]; } else { state = yydgoto[num2]; } if (this.stateptr >= 0) { this.state_push(state); this.val_push(this.yyval); goto Label_0025; } Label_0849: this.yyerror("yacc stack overflow"); Label_0854: return 1; }
internal static IADOPathNode CreateOrClause(IADOPathNode[] exprList) { return new CompositeADOPathNode(ADOperator.Or, exprList); }
internal static IADOPathNode CreateNotClause(IADOPathNode expr) { return new UnaryADOPathNode(ADOperator.Not, expr); }
static ADObjectSearcher() { ADObjectSearcher.AllProperties = "*"; ADObjectSearcher.DefaultSearchFilterString = "(objectClass=*)"; ADObjectSearcher.DefaultSearchFilter = ADOPathUtil.CreateFilterClause(ADOperator.Like, "objectClass", "*"); }
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; }
internal BinaryADOPathNode(ADOperator op, IADOPathNode leftExpr, IADOPathNode rightExpr) { this._operator = op; this._leftExpr = leftExpr; this._rightExpr = rightExpr; }
internal static IADOPathNode ToSearchComputerSamAccountName(string extendedAttribute, string[] directoryAttributes, IADOPathNode filterClause, CmdletSessionInfo cmdletSessionInfo) { BinaryADOPathNode binaryADOPathNode = filterClause as BinaryADOPathNode; if (binaryADOPathNode != null) { IDataNode rightNode = binaryADOPathNode.RightNode as IDataNode; if (rightNode != null) { string dataObject = rightNode.DataObject as string; if (dataObject != null) { bool flag = dataObject.EndsWith("$", StringComparison.OrdinalIgnoreCase); bool flag1 = dataObject.EndsWith("*", StringComparison.OrdinalIgnoreCase); ADOperator @operator = binaryADOPathNode.Operator; if ((@operator == ADOperator.Eq || @operator == ADOperator.Ne) && !flag) { object[] objArray = new object[3]; objArray[0] = extendedAttribute; objArray[1] = "$"; objArray[2] = filterClause; cmdletSessionInfo.CmdletMessageWriter.WriteWarningBuffered(string.Format(CultureInfo.CurrentCulture, StringResources.WarningSamAccountNameClauseLacksDollarSign, objArray)); } else { if ((@operator == ADOperator.Like || @operator == ADOperator.NotLike) && !flag && !flag1) { object[] objArray1 = new object[3]; objArray1[0] = extendedAttribute; objArray1[1] = "$"; objArray1[2] = filterClause; cmdletSessionInfo.CmdletMessageWriter.WriteWarningBuffered(string.Format(CultureInfo.CurrentCulture, StringResources.WarningSamAccountNameClauseLacksDollarSign, objArray1)); } } return SearchConverters.ToSearchObject(extendedAttribute, directoryAttributes, filterClause, cmdletSessionInfo); } else { object[] type = new object[2]; type[0] = rightNode.DataObject.GetType(); type[1] = extendedAttribute; throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterRHSInvalidType, type)); } } else { throw new ArgumentException(StringResources.SearchConverterRHSNotDataNode); } } else { throw new ArgumentException(StringResources.SearchConverterNotBinaryNode); } }
internal string GetRDNPrefix(string objectClass) { ADObject aDObject; ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(this._sessionInfo); using (aDObjectSearcher) { ADRootDSE rootDSE = aDObjectSearcher.GetRootDSE(); aDObjectSearcher.SearchRoot = rootDSE.SchemaNamingContext; aDObjectSearcher.Properties.Add("rDNAttID"); IADOPathNode aDOPathNode = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "classSchema"); IADOPathNode aDOPathNode1 = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "lDAPDisplayName", objectClass); IADOPathNode[] aDOPathNodeArray = new IADOPathNode[2]; aDOPathNodeArray[0] = aDOPathNode; aDOPathNodeArray[1] = aDOPathNode1; IADOPathNode aDOPathNode2 = ADOPathUtil.CreateAndClause(aDOPathNodeArray); aDObjectSearcher.Filter = aDOPathNode2; aDObject = aDObjectSearcher.FindOne(); } if (aDObject == null) { return null; } else { return (string)aDObject["rDNAttID"][0]; } }
public static IADOPathNode ToSearchGroupScope(string extendedAttributeName, string[] directoryAttributes, IADOPathNode filterClause, CmdletSessionInfo cmdletSessionInfo) { ADGroupScope aDGroupScope = ADGroupScope.DomainLocal; BinaryADOPathNode binaryADOPathNode = filterClause as BinaryADOPathNode; if (binaryADOPathNode == null) { throw new ArgumentException(StringResources.SearchConverterNotBinaryNode); } else { if (binaryADOPathNode.Operator == ADOperator.Eq || binaryADOPathNode.Operator == ADOperator.Ne) { IDataNode rightNode = binaryADOPathNode.RightNode as IDataNode; if (rightNode == null) { throw new ArgumentException(StringResources.SearchConverterRHSNotDataNode); } else { if (!Utils.TryParseEnum<ADGroupScope>(rightNode.DataObject.ToString(), out aDGroupScope)) { object[] str = new object[2]; str[0] = rightNode.DataObject.ToString(); str[1] = extendedAttributeName; throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterInvalidValue, str)); } else { PropertyADOPathNode propertyADOPathNode = new PropertyADOPathNode(directoryAttributes[0]); ObjectADOPathNode objectADOPathNode = new ObjectADOPathNode((object)GroupTypeUtils.GetDirectoryGroupTypeValue(aDGroupScope)); IADOPathNode aDOPathNode = new BinaryADOPathNode(ADOperator.Band, propertyADOPathNode, objectADOPathNode); if (binaryADOPathNode.Operator != ADOperator.Eq) { return ADOPathUtil.CreateNotClause(aDOPathNode); } else { return aDOPathNode; } } } } else { object[] objArray = new object[2]; ADOperator[] aDOperatorArray = new ADOperator[2]; aDOperatorArray[1] = ADOperator.Ne; objArray[0] = SearchConverters.ConvertOperatorListToString(aDOperatorArray); objArray[1] = extendedAttributeName; throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterSupportedOperatorListErrorMessage, objArray)); } } }
private ADObjectSearcher GetADObjectSearcher(string path, ADSearchScope scope, IADOPathNode filter, ADProviderSearchParameters parameters, PSCredential credential, ADDriveInfo extendedDriveInfo) { this.Trace(DebugLogLevel.Verbose, "Entering GetADObjectSearcher"); ADSessionInfo sessionInfo = this.GetSessionInfo(parameters, credential, extendedDriveInfo); ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(sessionInfo); aDObjectSearcher.SearchRoot = path; aDObjectSearcher.Scope = scope; if (filter != null) { aDObjectSearcher.Filter = filter; } if (parameters != null) { if (parameters.Properties != null) { aDObjectSearcher.Properties.AddRange(parameters.Properties); } aDObjectSearcher.PageSize = parameters.PageSize; } if (this.GetFormatType(parameters, extendedDriveInfo) == ADPathFormat.Canonical) { aDObjectSearcher.Properties.Add("canonicalName"); } this.Trace(DebugLogLevel.Verbose, "Leaving GetADObjectSearcher"); return aDObjectSearcher; }
private void ReadObjectSchema(ADObjectSearcher searcher, ADSchema adSchema) { searcher.SchemaTranslation = false; ADRootDSE rootDSE = searcher.GetRootDSE(); searcher.SearchRoot = rootDSE.SchemaNamingContext; IADOPathNode[] aDOPathNodeArray = new IADOPathNode[3]; aDOPathNodeArray[0] = ADOPathUtil.CreateNotClause(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "isDefunct", true)); aDOPathNodeArray[1] = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectClass", "attributeSchema"); IADOPathNode[] aDOPathNodeArray1 = new IADOPathNode[3]; aDOPathNodeArray1[0] = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "attributeSyntax", SchemaConstants.SidAttributeSyntax); aDOPathNodeArray1[1] = ADOPathUtil.CreateFilterClause(ADOperator.Like, "linkID", "*"); aDOPathNodeArray1[2] = ADOPathUtil.CreateFilterClause(ADOperator.Band, "systemFlags", SchemaConstants.systemFlagsConstructedBitMask); aDOPathNodeArray[2] = ADOPathUtil.CreateOrClause(aDOPathNodeArray1); searcher.Filter = ADOPathUtil.CreateAndClause(aDOPathNodeArray); searcher.Scope = ADSearchScope.Subtree; searcher.PageSize = 0x100; searcher.Properties.Clear(); searcher.Properties.Add("lDAPDisplayName"); searcher.Properties.Add("linkID"); searcher.Properties.Add("systemFlags"); searcher.Properties.Add("attributeSyntax"); IEnumerable<ADObject> aDObjects = searcher.FindAll(); foreach (ADObject nullable in aDObjects) { if (adSchema._schemaProperties.ContainsKey ((string)nullable["lDAPDisplayName"].Value)) { if (nullable.Contains("linkID")) { adSchema._schemaProperties[(string)nullable["lDAPDisplayName"].Value].LinkID = new int?(int.Parse(nullable["linkID"].Value as string, NumberFormatInfo.InvariantInfo)); } if (nullable.Contains("systemFlags") && (long)0 != (ulong.Parse(nullable["systemFlags"].Value as string, NumberFormatInfo.InvariantInfo) & SchemaConstants.systemFlagsConstructedBitMask)) { adSchema._schemaProperties[(string)nullable["lDAPDisplayName"].Value].IsConstructed = true; } if (!nullable.Contains("attributeSyntax") || string.Compare(nullable["attributeSyntax"].Value as string, SchemaConstants.SidAttributeSyntax, true) != 0) { continue; } adSchema._schemaProperties[(string)nullable["lDAPDisplayName"].Value].Syntax = ADAttributeSyntax.Sid; } } }
public ADObjectSearcher(ADSessionInfo sessionInfo, ADObject obj) { this._searchScope = ADSearchScope.Subtree; this._filter = ADOPathUtil.CreateFilterClause(ADOperator.Like, "objectClass", "*"); this._propertyList = new List<string>(ADObject.DefaultProperties); this._timeLimit = TimeSpan.Zero; this._schemaTranslationEnabled = true; this._pageSize = 0x100; this._searchOption = null; this._autoRangeRetrieve = true; this._sdFlags = SecurityMasks.Owner | SecurityMasks.Group | SecurityMasks.Dacl; if (sessionInfo == null) { if (obj == null) { this._adSession = ADSession.ConstructSession(null); } else { this._adSession = ADSession.ConstructSession(obj.SessionInfo); } } else { this._adSession = ADSession.ConstructSession(sessionInfo); } if (obj != null) { this._adObject = obj; this._searchRoot = this._adObject.DistinguishedName; foreach (string propertyName in this._adObject.PropertyNames) { this._propertyList.Add(propertyName); } } }