/// <summary> /// Determines the domain and the LDAP paths for Central Policy and Central Access Rule in AD /// to facilitate subsequent queries. /// </summary> /// <param name="target">Name of the computer from which to query</param> public AvailableCentralPolicies(string target) { PDOMAIN_CONTROLLER_INFO dsInfoPtr = PDOMAIN_CONTROLLER_INFO.Zero; try { DWORD result = NativeMethods.DsGetDcName(target, null, PGUID.Zero, null, NativeMethods.DsGetDcNameFlags.DirectoryServiceRequired, out dsInfoPtr); if (result != Win32Error.ERROR_SUCCESS) { throw new Win32Exception((int)result); } NativeMethods.DOMAIN_CONTROLLER_INFO dsInfo = (NativeMethods.DOMAIN_CONTROLLER_INFO) Marshal.PtrToStructure( dsInfoPtr, typeof(NativeMethods.DOMAIN_CONTROLLER_INFO)); string domainDN = "DC=" + string.Join(",DC=", dsInfo.domainName.Split('.')); capContainerDN = "CN=Central Access Policies," + "CN=Claims Configuration," + "CN=Services," + "CN=Configuration," + domainDN; availableCaps = GetAvailableCaps(target); } finally { NativeMethods.NetApiBufferFree(dsInfoPtr); dsInfoPtr = PDOMAIN_CONTROLLER_INFO.Zero; } }
public static extern DWORD DsGetDcName(string computerName, string domainName, PGUID domainGuid, string siteName, DsGetDcNameFlags flags, out PDOMAIN_CONTROLLER_INFO dsInfo);