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; }
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); }
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 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 void WriteObjectsInBatch(List <IADOPathNode> filterList) { IADOPathNode item; if (filterList.Count != 1) { item = ADOPathUtil.CreateOrClause(filterList.ToArray()); } else { item = filterList[0]; } int?nullable = null; IEnumerable <RO> extendedObjectFromFilter = this._returnObjectFactory.GetExtendedObjectFromFilter(item, this.GetCmdletSessionInfo().DefaultPartitionPath, ADSearchScope.Subtree, null, nullable, new int?(this._pageSize), false); int num = 0; if (extendedObjectFromFilter != null) { foreach (RO rO in extendedObjectFromFilter) { base.WriteObject(rO); num++; } } }
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)); } }
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); }
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 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); }
internal override IADOPathNode IdentitySearchConverter(object identity) { if (identity != null) { ADDirectoryServer aDDirectoryServer = identity as ADDirectoryServer; if (aDDirectoryServer == null) { ADObject aDObject = new ADObject(); aDObject.Identity = identity; this._addsPseudoFactory.SetCmdletSessionInfo(base.CmdletSessionInfo); return(this._addsPseudoFactory.BuildIdentityFilter(aDObject)); } else { List <IADOPathNode> aDOPathNodes = new List <IADOPathNode>(); if (aDDirectoryServer["ServerObjectDN"] != null && aDDirectoryServer["ServerObjectDN"].Value != null) { aDOPathNodes.Add(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "distinguishedName", Utils.EscapeDNForFilter(aDDirectoryServer["ServerObjectDN"].Value as string))); } if (aDDirectoryServer["NTDSSettingsObjectDN"] != null && aDDirectoryServer["NTDSSettingsObjectDN"].Value != null) { aDOPathNodes.Add(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "distinguishedName", Utils.EscapeDNForFilter(aDDirectoryServer["NTDSSettingsObjectDN"].Value as string))); } if (aDDirectoryServer["Name"] != null && aDDirectoryServer["Name"].Value != null) { aDOPathNodes.Add(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "name", aDDirectoryServer["Name"].Value)); } if (aDOPathNodes.Count != 1) { return(ADOPathUtil.CreateOrClause(aDOPathNodes.ToArray())); } else { return(aDOPathNodes[0]); } } } else { throw new ArgumentNullException("identity"); } }
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; } ); }
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; } }
internal static ADObjectSearcher BuildGenericSearcher(string[] identityLdapAttributes, object identity, string searchRoot, CmdletSessionInfo cmdletSessionInfo, out bool useSearchFilter) { useSearchFilter = true; string str = identity as string; if (!string.IsNullOrEmpty(str)) { ADObjectSearcher item = SearchUtility.BuildSearcher(cmdletSessionInfo.ADSessionInfo, searchRoot, ADSearchScope.Subtree); List <IADOPathNode> aDOPathNodes = new List <IADOPathNode>((int)identityLdapAttributes.Length); string[] strArrays = identityLdapAttributes; for (int i = 0; i < (int)strArrays.Length; i++) { string str1 = strArrays[i]; if (str1 != "distinguishedName") { aDOPathNodes.Add(ADOPathUtil.CreateFilterClause(ADOperator.Eq, str1, str)); } else { string str2 = Utils.EscapeDNForFilter(str); aDOPathNodes.Add(ADOPathUtil.CreateFilterClause(ADOperator.Eq, str1, str2)); } } if (aDOPathNodes.Count <= 1) { item.Filter = aDOPathNodes[0]; } else { item.Filter = ADOPathUtil.CreateOrClause(aDOPathNodes.ToArray()); } return(item); } else { return(null); } }
internal override IADOPathNode IdentitySearchConverter(object identity) { IADOPathNode aDOPathNode; if (identity != null) { string str = identity as string; if (str == null) { SecurityIdentifier securityIdentifier = identity as SecurityIdentifier; if (securityIdentifier == null) { if (!(identity is Guid)) { ADDomainController aDDomainController = identity as ADDomainController; if (aDDomainController == null) { ADObject aDObject = identity as ADObject; if (aDObject == null) { throw new ArgumentException(string.Format(StringResources.SearchConverterUnrecognizedObjectType, identity.GetType())); } else { ADComputer aDComputer = new ADComputer(aDObject); ADDomainControllerFactory <T> .ADComputerPseudoFactory aDComputerPseudoFactory = new ADDomainControllerFactory <T> .ADComputerPseudoFactory(); aDComputerPseudoFactory.SetCmdletSessionInfo(base.CmdletSessionInfo); return(aDComputerPseudoFactory.BuildIdentityFilter(aDComputer)); } } else { IADOPathNode aDOPathNode1 = base.IdentitySearchConverter(identity); List <IADOPathNode> aDOPathNodes = new List <IADOPathNode>(); if (aDDomainController["ComputerDN"] != null && aDDomainController["ComputerDN"].Value != null) { aDOPathNodes.Add(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "distinguishedName", Utils.EscapeDNForFilter(aDDomainController["ComputerDN"].Value as string))); } aDOPathNodes.Add(aDOPathNode1); if (aDOPathNodes.Count != 1) { return(ADOPathUtil.CreateOrClause(aDOPathNodes.ToArray())); } else { return(aDOPathNodes[0]); } } } else { Guid guid = (Guid)identity; return(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectGuid", guid.ToByteArray())); } } else { byte[] numArray = new byte[securityIdentifier.BinaryLength]; securityIdentifier.GetBinaryForm(numArray, 0); return(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectSid", numArray)); } } else { Guid? nullable = null; IPAddress pAddress = null; if (!Utils.TryParseGuid(str, out nullable)) { if (!IPAddress.TryParse(str, out pAddress)) { List <IADOPathNode> aDOPathNodes1 = this.BuildIdentityFilterListFromString(str); if (aDOPathNodes1.Count <= 1) { return(aDOPathNodes1[0]); } else { return(ADOPathUtil.CreateOrClause(aDOPathNodes1.ToArray())); } } else { try { IPHostEntry hostEntry = Dns.GetHostEntry(pAddress); aDOPathNode = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "dNSHostName", hostEntry.HostName); } catch (SocketException socketException1) { SocketException socketException = socketException1; object[] objArray = new object[1]; objArray[0] = pAddress; throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.CannotResolveIPAddressToHostName, objArray), socketException); } return(aDOPathNode); } } else { Guid value = nullable.Value; return(ADOPathUtil.CreateFilterClause(ADOperator.Eq, "objectGuid", value.ToByteArray())); } } } else { throw new ArgumentNullException("identity"); } }
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"); } }
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"); } }
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; } }
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)); } } } }
private bool ADGetADTrustCmdletProcessInputObjectCSRoutine() { if (this._cmdletParameters.Contains("InputObject")) { object item = this._cmdletParameters["InputObject"]; if (item as PSObject != null) { item = ((PSObject)item).BaseObject; } ADEntity aDEntity = item as ADEntity; string str = item as string; if (aDEntity == null) { if (str == null) { object[] type = new object[2]; type[0] = item.GetType(); type[1] = "InputObject"; base.WriteErrorBuffered(this.ConstructErrorRecord(new ParameterBindingException(string.Format(CultureInfo.CurrentCulture, StringResources.UnsupportedParameterType, type)))); return(false); } else { this._cmdletParameters["Identity"] = new ADTrust(str); } } else { if (aDEntity.IsSearchResult) { if (aDEntity as ADForest != null || aDEntity as ADDomain != null || aDEntity as ADClaimTransformPolicy != null) { CmdletSessionInfo cmdletSessionInfo = this.GetCmdletSessionInfo(); ADTrustFactory <ADTrust> aDTrustFactory = new ADTrustFactory <ADTrust>(); IADOPathNode structuralObjectFilter = aDTrustFactory.StructuralObjectFilter; if (aDEntity as ADForest != null || aDEntity as ADDomain != null) { if (!this._cmdletParameters.Contains("Server")) { ADSessionInfo aDSessionInfo = new ADSessionInfo(aDEntity["Name"].Value as string); if (aDEntity as ADForest != null) { aDSessionInfo.SetDefaultPort(LdapConstants.LDAP_GC_PORT); } if (cmdletSessionInfo.ADSessionInfo != null) { aDSessionInfo.Credential = cmdletSessionInfo.ADSessionInfo.Credential; } cmdletSessionInfo.ADRootDSE = null; cmdletSessionInfo.ADSessionInfo = aDSessionInfo; using (ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(aDSessionInfo)) { cmdletSessionInfo.ADRootDSE = aDObjectSearcher.GetRootDSE(); cmdletSessionInfo.ADRootDSE.SessionInfo = aDSessionInfo; } this.SetPipelinedSessionInfo(aDSessionInfo); } else { base.WriteErrorBuffered(this.ConstructErrorRecord(new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.ServerParameterNotSupported, new object[0])))); return(false); } } else { IADOPathNode aDOPathNode = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "msDS-EgressClaimsTransformationPolicy", aDEntity["DistinguishedName"].Value as string); IADOPathNode aDOPathNode1 = ADOPathUtil.CreateFilterClause(ADOperator.Eq, "msDS-IngressClaimsTransformationPolicy", aDEntity["DistinguishedName"].Value as string); IADOPathNode[] aDOPathNodeArray = new IADOPathNode[2]; aDOPathNodeArray[0] = aDOPathNode; aDOPathNodeArray[1] = aDOPathNode1; structuralObjectFilter = ADOPathUtil.CreateOrClause(aDOPathNodeArray); } base.BuildPropertySet(); this._factory.SetCmdletSessionInfo(cmdletSessionInfo); base.ValidateParameters(); base.OutputSearchResults(structuralObjectFilter); return(false); } else { if (aDEntity as ADTrust == null) { if (string.Compare(this._factory.StructuralObjectClass, aDEntity["ObjectClass"].Value as string, StringComparison.OrdinalIgnoreCase) == 0) { this._cmdletParameters["Identity"] = new ADTrust((string)aDEntity["DistinguishedName"].Value); } else { object[] objArray = new object[2]; objArray[0] = aDEntity.GetType(); objArray[1] = "InputObject"; base.WriteErrorBuffered(this.ConstructErrorRecord(new ParameterBindingException(string.Format(CultureInfo.CurrentCulture, StringResources.UnsupportedParameterType, objArray)))); return(false); } } else { this._cmdletParameters["Identity"] = (ADTrust)aDEntity; } } } else { base.WriteErrorBuffered(this.ConstructErrorRecord(new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.OnlySearchResultsSupported, new object[0])))); return(false); } } } return(true); }