Example #1
0
		public static void ToDirectoryGroupCategory(string extendedAttribute, string[] directoryAttributes, ADPropertyValueCollection extendedData, ADEntity directoryObj, CmdletSessionInfo cmdletSessionInfo)
		{
			ADGroupCategory aDGroupCategory = ADGroupCategory.Distribution;
			if (extendedData != null)
			{
				if (extendedData.Value != null)
				{
					ADGroupCategory value = (ADGroupCategory)extendedData.Value;
					int directoryGroupTypeValue = GroupTypeUtils.GetDirectoryGroupTypeValue(value);
					if (!directoryObj.Contains(directoryAttributes[0]))
					{
						directoryObj.Add(directoryAttributes[0], directoryGroupTypeValue);
					}
					else
					{
						int num = (int)directoryObj[directoryAttributes[0]].Value;
						if (GroupTypeUtils.TryGetExtendedGroupCategoryValue(num, out aDGroupCategory))
						{
							int directoryGroupTypeValue1 = GroupTypeUtils.GetDirectoryGroupTypeValue(aDGroupCategory);
							num = num & ~directoryGroupTypeValue1;
						}
						directoryObj[directoryAttributes[0]].Value = num + directoryGroupTypeValue;
						return;
					}
				}
				else
				{
					return;
				}
			}
		}
Example #2
0
		internal static void ToExtendedReplicationFailureType(string extendedAttribute, string[] directoryAttributes, ADEntity userObj, ADEntity directoryObj, CmdletSessionInfo cmdletSessionInfo)
		{
			string value = directoryObj[directoryAttributes[0]].Value as string;
			if (!string.Equals("msDS-ReplConnectionFailures", value, StringComparison.OrdinalIgnoreCase))
			{
				if (string.Equals("msDS-ReplLinkFailures", value, StringComparison.OrdinalIgnoreCase))
				{
					userObj.Add(extendedAttribute, ADReplicationFailureType.Link);
				}
				return;
			}
			else
			{
				userObj.Add(extendedAttribute, ADReplicationFailureType.Connection);
				return;
			}
		}
Example #3
0
		internal static void ToExtendedReplicationPartnerType(string extendedAttribute, string[] directoryAttributes, ADEntity userObj, ADEntity directoryObj, CmdletSessionInfo cmdletSessionInfo)
		{
			string value = directoryObj[directoryAttributes[0]].Value as string;
			if (!string.Equals("msDS-NCReplInboundNeighbors", value, StringComparison.OrdinalIgnoreCase))
			{
				if (string.Equals("msDS-NCReplOutboundNeighbors", value, StringComparison.OrdinalIgnoreCase))
				{
					userObj.Add(extendedAttribute, ADPartnerType.Outbound);
				}
				return;
			}
			else
			{
				userObj.Add(extendedAttribute, ADPartnerType.Inbound);
				return;
			}
		}
Example #4
0
		internal static void ToExtendedIsLinkValue(string extendedAttribute, string[] directoryAttributes, ADEntity userObj, ADEntity directoryObj, CmdletSessionInfo cmdletSessionInfo)
		{
			string value = directoryObj[directoryAttributes[0]].Value as string;
			if (!string.Equals("msDS-ReplAttributeMetaData", value, StringComparison.OrdinalIgnoreCase))
			{
				if (string.Equals("msDS-ReplValueMetaData", value, StringComparison.OrdinalIgnoreCase))
				{
					userObj.Add(extendedAttribute, true);
				}
				return;
			}
			else
			{
				userObj.Add(extendedAttribute, false);
				return;
			}
		}
Example #5
0
		public static void ToExtendedAccountExpirationDate(string extendedAttribute, string[] directoryAttributes, ADEntity userObj, ADEntity directoryObj, CmdletSessionInfo cmdletSessionInfo)
		{
			if (directoryObj[directoryAttributes[0]].Value != null)
			{
				long value = (long)directoryObj[directoryAttributes[0]].Value;
				if (value == (long)0 || value == 0x7fffffffffffffffL)
				{
					userObj.Add(extendedAttribute, new ADPropertyValueCollection(null));
					return;
				}
				else
				{
					AttributeConverters.ToExtendedDateTimeFromLong(extendedAttribute, directoryAttributes, userObj, directoryObj, cmdletSessionInfo);
					return;
				}
			}
			else
			{
				userObj.Add(extendedAttribute, new ADPropertyValueCollection(null));
				return;
			}
		}
Example #6
0
		internal ADEntity GetForest()
		{
			this.Init();
			GetADForestRequest getADForestRequest = new GetADForestRequest();
			GetADForestResponse aDForest = this._topoMgmt.GetADForest(this._sessionHandle, getADForestRequest);
			if (aDForest.Forest == null)
			{
				return null;
			}
			else
			{
				ActiveDirectoryForest forest = aDForest.Forest;
				ADEntity aDEntity = new ADEntity();
				aDEntity.Add("msDS-SPNSuffixes", forest.SPNSuffixes);
				aDEntity.Add("uPNSuffixes", forest.UPNSuffixes);
				aDEntity.Add("msDS-Behavior-Version", (ADForestMode)forest.ForestMode);
				aDEntity.Add("name", forest.Name);
				aDEntity.Add("RootDomain", forest.RootDomain);
				aDEntity.Add("ApplicationPartitions", forest.ApplicationPartitions);
				aDEntity.Add("CrossForestReferences", forest.CrossForestReferences);
				aDEntity.Add("Domains", forest.Domains);
				aDEntity.Add("GlobalCatalogs", forest.GlobalCatalogs);
				aDEntity.Add("Sites", forest.Sites);
				aDEntity.Add("DomainNamingMaster", forest.DomainNamingMaster);
				aDEntity.Add("SchemaMaster", forest.SchemaMaster);
				return aDEntity;
			}
		}
Example #7
0
		internal ADEntity[] GetDomainController(string[] dcNtdsSettingsDN)
		{
			this.Init();
			GetADDomainControllerRequest getADDomainControllerRequest = new GetADDomainControllerRequest();
			getADDomainControllerRequest.NtdsSettingsDN = dcNtdsSettingsDN;
			GetADDomainControllerResponse aDDomainController = this._topoMgmt.GetADDomainController(this._sessionHandle, getADDomainControllerRequest);
			List<ADEntity> aDEntities = new List<ADEntity>();
			if (aDDomainController.DomainControllers == null)
			{
				return new ADEntity[0];
			}
			else
			{
				ActiveDirectoryDomainController[] domainControllers = aDDomainController.DomainControllers;
				for (int i = 0; i < (int)domainControllers.Length; i++)
				{
					ActiveDirectoryDomainController activeDirectoryDomainController = domainControllers[i];
					ADEntity aDEntity = new ADEntity();
					aDEntity.Add("ComputerDN", activeDirectoryDomainController.ComputerDN);
					aDEntity.Add("Domain", activeDirectoryDomainController.Domain);
					aDEntity.Add("Forest", activeDirectoryDomainController.Forest);
					aDEntity.Add("Enabled", activeDirectoryDomainController.Enabled);
					aDEntity.Add("IsGlobalCatalog", activeDirectoryDomainController.IsGlobalCatalog);
					aDEntity.Add("IsReadOnly", activeDirectoryDomainController.IsReadOnly);
					aDEntity.Add("OSHotFix", activeDirectoryDomainController.OSHotFix);
					aDEntity.Add("OSName", activeDirectoryDomainController.OSName);
					aDEntity.Add("OSServicepack", activeDirectoryDomainController.OSServicepack);
					aDEntity.Add("OSVersion", activeDirectoryDomainController.OSVersion);
					aDEntity.Add("DefaultPartition", activeDirectoryDomainController.DefaultPartition);
					aDEntity.Add("HostName", activeDirectoryDomainController.HostName);
					aDEntity.Add("InvocationId", activeDirectoryDomainController.InvocationId);
					aDEntity.Add("LdapPort", activeDirectoryDomainController.LdapPort);
					aDEntity.Add("NTDSSettingsObjectDN", activeDirectoryDomainController.NTDSSettingsObjectDN);
					aDEntity.Add("Name", activeDirectoryDomainController.Name);
					aDEntity.Add("OperationMasterRole", activeDirectoryDomainController.OperationMasterRole);
					aDEntity.Add("Partitions", activeDirectoryDomainController.Partitions);
					aDEntity.Add("ServerObjectDN", activeDirectoryDomainController.ServerObjectDN);
					aDEntity.Add("ServerObjectGuid", activeDirectoryDomainController.ServerObjectGuid);
					aDEntity.Add("Site", activeDirectoryDomainController.Site);
					aDEntity.Add("SslPort", activeDirectoryDomainController.SslPort);
					aDEntities.Add(aDEntity);
				}
				return aDEntities.ToArray();
			}
		}
Example #8
0
		public static void ToExtendedGroupScope(string extendedAttribute, string[] directoryAttributes, ADEntity userObj, ADEntity directoryObj, CmdletSessionInfo cmdletSessionInfo)
		{
			if (!directoryObj.Contains(directoryAttributes[0]))
			{
				userObj.Add(extendedAttribute, new ADPropertyValueCollection(null));
			}
			else
			{
				int value = (int)directoryObj[directoryAttributes[0]].Value;
				if ((value & 4) != 4)
				{
					if ((value & 2) != 2)
					{
						if ((value & 8) == 8)
						{
							userObj.Add(extendedAttribute, ADGroupScope.Universal);
							return;
						}
					}
					else
					{
						userObj.Add(extendedAttribute, ADGroupScope.Global);
						return;
					}
				}
				else
				{
					userObj.Add(extendedAttribute, ADGroupScope.DomainLocal);
					return;
				}
			}
		}
Example #9
0
		public static void ToExtendedGroupCategory(string extendedAttribute, string[] directoryAttributes, ADEntity userObj, ADEntity directoryObj, CmdletSessionInfo cmdletSessionInfo)
		{
			if (!directoryObj.Contains(directoryAttributes[0]))
			{
				userObj.Add(extendedAttribute, new ADPropertyValueCollection(null));
				return;
			}
			else
			{
				int value = (int)directoryObj[directoryAttributes[0]].Value;
				if ((value & -2147483648) != -2147483648)
				{
					userObj.Add(extendedAttribute, ADGroupCategory.Distribution);
					return;
				}
				else
				{
					userObj.Add(extendedAttribute, ADGroupCategory.Security);
					return;
				}
			}
		}
Example #10
0
		internal static void ToExtendedGPLink(string extendedAttribute, string[] directoryAttributes, ADEntity userObj, ADEntity directoryObj, CmdletSessionInfo cmdletSessionInfo)
		{
			if (!directoryObj.Contains(directoryAttributes[0]))
			{
				userObj.Add(extendedAttribute, new ADPropertyValueCollection());
				return;
			}
			else
			{
				string value = directoryObj[directoryAttributes[0]].Value as string;
				userObj.Add(extendedAttribute, GPLinkUtil.ConvertLinkedGroupPolicyObjects(value));
				return;
			}
		}
Example #11
0
		internal static void ToExtendedServerFromSessionInfo(string extendedAttribute, string[] directoryAttributes, ADEntity userObj, ADEntity directoryObj, CmdletSessionInfo cmdletSessionInfo)
		{
			userObj.Add(extendedAttribute, cmdletSessionInfo.ADRootDSE.DNSHostName);
		}
Example #12
0
		internal static ADEntity DiscoverDomainController(string siteName, string domainName, ADDiscoverableService[] servicesToFind, ADDiscoverDomainControllerOptions discoverOptions, ADMinimumDirectoryServiceVersion? minDSVersion)
		{
			DOMAIN_CONTROLLER_INFO structure;
			string domainControllerName;
			IntPtr zero = IntPtr.Zero;
			uint num = 0;
			if (servicesToFind.Length != 0)
			{
				ADDiscoverableService[] aDDiscoverableServiceArray = servicesToFind;
				for (int i = 0; i < (int)aDDiscoverableServiceArray.Length; i++)
				{
					ADDiscoverableService aDDiscoverableService = aDDiscoverableServiceArray[i];
					ADDiscoverableService aDDiscoverableService1 = aDDiscoverableService;
					if (aDDiscoverableService1 == ADDiscoverableService.PrimaryDC)
					{
						num = num | Convert.ToUInt32(ADLocatorFlags.PdcRequired);
					}
					else if (aDDiscoverableService1 == ADDiscoverableService.GlobalCatalog)
					{
						num = num | Convert.ToUInt32(ADLocatorFlags.GCRequired);
					}
					else if (aDDiscoverableService1 == ADDiscoverableService.KDC)
					{
						num = num | Convert.ToUInt32(ADLocatorFlags.KdcRequired);
					}
					else if (aDDiscoverableService1 == ADDiscoverableService.TimeService)
					{
						num = num | Convert.ToUInt32(ADLocatorFlags.TimeServerRequired);
					}
					else if (aDDiscoverableService1 == ADDiscoverableService.ReliableTimeService)
					{
						num = num | Convert.ToUInt32(ADLocatorFlags.GoodTimeServerPreferred);
						num = num | Convert.ToUInt32(ADLocatorFlags.TimeServerRequired);
					}
					else if (aDDiscoverableService1 == ADDiscoverableService.ADWS)
					{
						num = num | Convert.ToUInt32(ADLocatorFlags.WebServiceRequired);
					}
					else
					{
						object[] str = new object[1];
						str[0] = (object)aDDiscoverableService.ToString();
						throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.UnsupportedOptionSpecified, str));
					}
				}
			}
			ADMinimumDirectoryServiceVersion valueOrDefault = minDSVersion.GetValueOrDefault();
			if (minDSVersion.HasValue)
			{
				switch (valueOrDefault)
				{
					case ADMinimumDirectoryServiceVersion.Windows2000:
					{
						num = num | Convert.ToUInt32(ADLocatorFlags.DirectoryServicesRequired);
						break;
					}
					case ADMinimumDirectoryServiceVersion.Windows2008:
					{
						num = num | Convert.ToUInt32(ADLocatorFlags.DirectoryServices6Required);
						break;
					}
					case ADMinimumDirectoryServiceVersion.Windows2012:
					{
						num = num | Convert.ToUInt32(ADLocatorFlags.DirectoryServices8Required);
						break;
					}
				}
			}
			if ((discoverOptions & ADDiscoverDomainControllerOptions.Writable) == ADDiscoverDomainControllerOptions.Writable)
			{
				num = num | Convert.ToUInt32(ADLocatorFlags.WriteableRequired);
			}
			if ((discoverOptions & ADDiscoverDomainControllerOptions.AvoidSelf) == ADDiscoverDomainControllerOptions.AvoidSelf)
			{
				num = num | Convert.ToUInt32(ADLocatorFlags.AvoidSelf);
			}
			if ((discoverOptions & ADDiscoverDomainControllerOptions.ForceDiscover) == ADDiscoverDomainControllerOptions.ForceDiscover)
			{
				num = num | Convert.ToUInt32(ADLocatorFlags.ForceRediscovery);
			}
			if ((discoverOptions & ADDiscoverDomainControllerOptions.TryNextClosestSite) == ADDiscoverDomainControllerOptions.TryNextClosestSite)
			{
				num = num | Convert.ToUInt32(ADLocatorFlags.TryNextClosestSite);
			}
			if ((discoverOptions & ADDiscoverDomainControllerOptions.ReturnDnsName) == ADDiscoverDomainControllerOptions.ReturnDnsName)
			{
				num = num | Convert.ToUInt32(ADLocatorFlags.ReturnDnsName);
			}
			if ((discoverOptions & ADDiscoverDomainControllerOptions.ReturnFlatName) == ADDiscoverDomainControllerOptions.ReturnFlatName)
			{
				num = num | Convert.ToUInt32(-2147483648);
			}
			try
			{
				int num1 = UnsafeNativeMethods.DsGetDcName(null, domainName, 0, siteName, num, out zero);
				if (num1 != 0)
				{
					Win32Exception win32Exception = new Win32Exception(num1);
					throw new ADException(win32Exception.Message, num1);
				}
				else
				{
					structure = (DOMAIN_CONTROLLER_INFO)Marshal.PtrToStructure(zero, typeof(DOMAIN_CONTROLLER_INFO));
				}
			}
			finally
			{
				UnsafeNativeMethods.NetApiBufferFree(zero);
			}
			ADEntity aDEntity = new ADEntity();
			if (!structure.DomainControllerName.StartsWith("\\\\"))
			{
				domainControllerName = structure.DomainControllerName;
			}
			else
			{
				domainControllerName = structure.DomainControllerName.Substring(2);
			}
			if ((structure.Flags & 0x20000000) != 0x20000000)
			{
				aDEntity.Add("Name", domainControllerName);
			}
			else
			{
				aDEntity.Add("HostName", domainControllerName);
			}
			aDEntity.Add("Domain", structure.DomainName);
			aDEntity.Add("Forest", structure.DnsForestName);
			aDEntity.Add("Site", structure.DcSiteName);
			aDEntity.InternalProperties.Add("DiscoveryInternalPropertyDCAddress", structure.DomainControllerAddress);
			return aDEntity;
		}
        internal ADEntity GetForest()
        {
            this.Init();
            GetADForestRequest  getADForestRequest = new GetADForestRequest();
            GetADForestResponse aDForest           = this._topoMgmt.GetADForest(this._sessionHandle, getADForestRequest);

            if (aDForest.Forest == null)
            {
                return(null);
            }
            else
            {
                ActiveDirectoryForest forest = aDForest.Forest;
                ADEntity aDEntity            = new ADEntity();
                aDEntity.Add("msDS-SPNSuffixes", forest.SPNSuffixes);
                aDEntity.Add("uPNSuffixes", forest.UPNSuffixes);
                aDEntity.Add("msDS-Behavior-Version", (ADForestMode)forest.ForestMode);
                aDEntity.Add("name", forest.Name);
                aDEntity.Add("RootDomain", forest.RootDomain);
                aDEntity.Add("ApplicationPartitions", forest.ApplicationPartitions);
                aDEntity.Add("CrossForestReferences", forest.CrossForestReferences);
                aDEntity.Add("Domains", forest.Domains);
                aDEntity.Add("GlobalCatalogs", forest.GlobalCatalogs);
                aDEntity.Add("Sites", forest.Sites);
                aDEntity.Add("DomainNamingMaster", forest.DomainNamingMaster);
                aDEntity.Add("SchemaMaster", forest.SchemaMaster);
                return(aDEntity);
            }
        }
        internal ADEntity[] GetDomainController(string[] dcNtdsSettingsDN)
        {
            this.Init();
            GetADDomainControllerRequest getADDomainControllerRequest = new GetADDomainControllerRequest();

            getADDomainControllerRequest.NtdsSettingsDN = dcNtdsSettingsDN;
            GetADDomainControllerResponse aDDomainController = this._topoMgmt.GetADDomainController(this._sessionHandle, getADDomainControllerRequest);
            List <ADEntity> aDEntities = new List <ADEntity>();

            if (aDDomainController.DomainControllers == null)
            {
                return(new ADEntity[0]);
            }
            else
            {
                ActiveDirectoryDomainController[] domainControllers = aDDomainController.DomainControllers;
                for (int i = 0; i < (int)domainControllers.Length; i++)
                {
                    ActiveDirectoryDomainController activeDirectoryDomainController = domainControllers[i];
                    ADEntity aDEntity = new ADEntity();
                    aDEntity.Add("ComputerDN", activeDirectoryDomainController.ComputerDN);
                    aDEntity.Add("Domain", activeDirectoryDomainController.Domain);
                    aDEntity.Add("Forest", activeDirectoryDomainController.Forest);
                    aDEntity.Add("Enabled", activeDirectoryDomainController.Enabled);
                    aDEntity.Add("IsGlobalCatalog", activeDirectoryDomainController.IsGlobalCatalog);
                    aDEntity.Add("IsReadOnly", activeDirectoryDomainController.IsReadOnly);
                    aDEntity.Add("OSHotFix", activeDirectoryDomainController.OSHotFix);
                    aDEntity.Add("OSName", activeDirectoryDomainController.OSName);
                    aDEntity.Add("OSServicepack", activeDirectoryDomainController.OSServicepack);
                    aDEntity.Add("OSVersion", activeDirectoryDomainController.OSVersion);
                    aDEntity.Add("DefaultPartition", activeDirectoryDomainController.DefaultPartition);
                    aDEntity.Add("HostName", activeDirectoryDomainController.HostName);
                    aDEntity.Add("InvocationId", activeDirectoryDomainController.InvocationId);
                    aDEntity.Add("LdapPort", activeDirectoryDomainController.LdapPort);
                    aDEntity.Add("NTDSSettingsObjectDN", activeDirectoryDomainController.NTDSSettingsObjectDN);
                    aDEntity.Add("Name", activeDirectoryDomainController.Name);
                    aDEntity.Add("OperationMasterRole", activeDirectoryDomainController.OperationMasterRole);
                    aDEntity.Add("Partitions", activeDirectoryDomainController.Partitions);
                    aDEntity.Add("ServerObjectDN", activeDirectoryDomainController.ServerObjectDN);
                    aDEntity.Add("ServerObjectGuid", activeDirectoryDomainController.ServerObjectGuid);
                    aDEntity.Add("Site", activeDirectoryDomainController.Site);
                    aDEntity.Add("SslPort", activeDirectoryDomainController.SslPort);
                    aDEntities.Add(aDEntity);
                }
                return(aDEntities.ToArray());
            }
        }