' ########################################################################################
' Microsoft Windows
' File: DSGetDC.inc
' Contents: Structures, function prototypes, and definitions for the DsGetDcName API
' Copyright (c) 2011 Jos? Roca
' Portions Copyright (c) Microsoft Corporation.
' All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################
#IF NOT %DEF(PBX_DsGetDC_PBI)
#DEFINE PBX_DsGetDC_PBI
%EQUATE `DSGETDC_INC = 1
#INCLUDE ONCE "Legacy/System/ws2def.inc"
#INCLUDE ONCE "Legacy/Platform/NTSecAPI.inc"
'//
'// Structure definitions
'//
'//
'// Flags to passed to DsGetDcName
'//
%EQUATE `DS_FORCE_REDISCOVERY = &H00000001
%EQUATE `DS_DIRECTORY_SERVICE_REQUIRED = &H00000010
%EQUATE `DS_DIRECTORY_SERVICE_PREFERRED = &H00000020
%EQUATE `DS_GC_SERVER_REQUIRED = &H00000040
%EQUATE `DS_PDC_REQUIRED = &H00000080
%EQUATE `DS_BACKGROUND_ONLY = &H00000100
%EQUATE `DS_IP_REQUIRED = &H00000200
%EQUATE `DS_KDC_REQUIRED = &H00000400
%EQUATE `DS_TIMESERV_REQUIRED = &H00000800
%EQUATE `DS_WRITABLE_REQUIRED = &H00001000
%EQUATE `DS_GOOD_TIMESERV_PREFERRED = &H00002000
%EQUATE `DS_Avoid_SELF = &H00004000
%EQUATE `DS_ONLY_LDAP_NEEDED = &H00008000
%EQUATE `DS_IS_FLAT_NAME = &H00010000
%EQUATE `DS_IS_DNS_NAME = &H00020000
%EQUATE `DS_TRY_NEXTCLOSEST_SITE = &H00040000
%EQUATE `DS_DIRECTORY_SERVICE_6_REQUIRED = &H00080000
%EQUATE `DS_WEB_SERVICE_REQUIRED = &H00100000
%EQUATE `DS_RETURN_DNS_NAME = &H40000000
%EQUATE `DS_RETURN_FLAT_NAME = &H80000000
%EQUATE `DSGETDC_VALID_FLAGS = %DS_FORCE_REDISCOVERY OR %DS_DIRECTORY_SERVICE_REQUIRED OR %DS_DIRECTORY_SERVICE_PREFERRED OR %DS_GC_SERVER_REQUIRED OR %DS_PDC_REQUIRED OR %DS_BACKGROUND_ONLY OR %DS_IP_REQUIRED OR %DS_KDC_REQUIRED OR %DS_TIMESERV_REQUIRED OR %DS_WRITABLE_REQUIRED OR %DS_GOOD_TIMESERV_PREFERRED OR %DS_Avoid_SELF OR %DS_ONLY_LDAP_NEEDED OR %DS_IS_FLAT_NAME OR %DS_IS_DNS_NAME OR %DS_TRY_NEXTCLOSEST_SITE OR %DS_DIRECTORY_SERVICE_6_REQUIRED OR %DS_WEB_SERVICE_REQUIRED OR %DS_RETURN_FLAT_NAME OR %DS_RETURN_DNS_NAME
'//
'// Structure returned from DsGetDcName
'//
' // Size = 48 bytes
TYPE DOMAIN_CONTROLLER_INFOA DWORD
 DomainControllerName AS ASCIIZ PTR
 DomainControllerAddress AS ASCIIZ PTR
 DomainControllerAddressType AS DWORD ' ULONG
 DomainGuid AS GUID ' GUID
 DomainName AS ASCIIZ PTR
 DnsForestName AS ASCIIZ PTR
 Flags AS DWORD ' ULONG
 DcSiteName AS ASCIIZ PTR
 ClientSiteName AS ASCIIZ PTR
END TYPE
' // Size = 48 bytes
TYPE DOMAIN_CONTROLLER_INFOW DWORD
 DomainControllerName AS WSTRINGZ PTR
 DomainControllerAddress AS WSTRINGZ PTR
 DomainControllerAddressType AS DWORD ' ULONG
 DomainGuid AS GUID ' GUID
 DomainName AS WSTRINGZ PTR
 DnsForestName AS WSTRINGZ PTR
 Flags AS DWORD ' ULONG
 DcSiteName AS WSTRINGZ PTR
 ClientSiteName AS WSTRINGZ PTR
END TYPE
#IF %DEF(%UNICODE)
 MACRO DOMAIN_CONTROLLER_INFO = DOMAIN_CONTROLLER_INFOW
#ELSE
 MACRO DOMAIN_CONTROLLER_INFO = DOMAIN_CONTROLLER_INFOA
#ENDIF
'//
'// Values for DomainControllerAddressType
'//
%EQUATE `DS_INET_ADDRESS = 1
%EQUATE `DS_NETBIOS_ADDRESS = 2
'//
'// Values for returned Flags
'//
%EQUATE `DS_PDC_FLAG = &H00000001 ' // DC is PDC of Domain
%EQUATE `DS_GC_FLAG = &H00000004 ' // DC is a GC of forest
%EQUATE `DS_LDAP_FLAG = &H00000008 ' // Server supports an LDAP server
%EQUATE `DS_DS_FLAG = &H00000010 ' // DC supports a DS and is a Domain Controller
%EQUATE `DS_KDC_FLAG = &H00000020 ' // DC is running KDC service
%EQUATE `DS_TIMESERV_FLAG = &H00000040 ' // DC is running time service
%EQUATE `DS_CLOSEST_FLAG = &H00000080 ' // DC is in closest site to client
%EQUATE `DS_WRITABLE_FLAG = &H00000100 ' // DC has a writable DS
%EQUATE `DS_GOOD_TIMESERV_FLAG = &H00000200 ' // DC is running time service (and has clock hardware)
%EQUATE `DS_NDNC_FLAG = &H00000400 ' // DomainName is non-domain NC serviced by the LDAP server
%EQUATE `DS_SELECT_SECRET_DOMAIN_6_FLAG = &H00000800 ' // DC has some secrets
%EQUATE `DS_FULL_SECRET_DOMAIN_6_FLAG = &H00001000 ' // DC has all secrets
%EQUATE `DS_WS_FLAG = &H00002000 ' // DC is running web service
%EQUATE `DS_PING_FLAGS = &H0000FFFF ' // Flags returned on ping
%EQUATE `DS_DNS_CONTROLLER_FLAG = &H20000000 ' // DomainControllerName is a DNS name
%EQUATE `DS_DNS_DOMAIN_FLAG = &H40000000 ' // DomainName is a DNS name
%EQUATE `DS_DNS_FOREST_FLAG = &H80000000 ' // DnsForestName is a DNS name
'//
'// Function Prototypes
'//
DECLARE FUNCTION DsGetDcNameA LIB "netapi32.dll" ALIAS "DsGetDcNameA" ( BYREF ComputerName AS ASCIIZ , BYREF DomainName AS ASCIIZ , BYREF DomainGuid AS GUID , BYREF SiteName AS ASCIIZ , BYVAL Flags AS QUAD , BYREF DomainControllerInfo AS DOMAIN_CONTROLLER_INFOA ) AS QUAD
DECLARE FUNCTION DsGetDcNameW LIB "netapi32.dll" ALIAS "DsGetDcNameW" ( BYREF ComputerName AS WSTRINGZ
 , BYREF DomainName AS WSTRINGZ
 , BYREF DomainGuid AS GUID
 , BYREF SiteName AS WSTRINGZ
 , BYVAL Flags AS DWORD
 , BYREF DomainControllerInfo AS DOMAIN_CONTROLLER_INFOW
 ) AS DWORD
#IF %DEF(%UNICODE)
 MACRO DsGetDcName = DsGetDcNameW
#ELSE
 MACRO DsGetDcName = DsGetDcNameA
#ENDIF
DECLARE FUNCTION DsGetSiteNameA LIB "netapi32.dll" ALIAS "DsGetSiteNameA" ( BYREF ComputerName AS ASCIIZ , BYREF SiteName AS ASCIIZ ) AS QUAD
DECLARE FUNCTION DsGetSiteNameW LIB "netapi32.dll" ALIAS "DsGetSiteNameW" ( BYREF ComputerName AS WSTRINGZ
 , BYREF SiteName AS DWORD
 ) AS DWORD
#IF %DEF(%UNICODE)
 MACRO DsGetSiteName = DsGetSiteNameW
#ELSE
 MACRO DsGetSiteName = DsGetSiteNameA
#ENDIF
DECLARE FUNCTION DsValidateSubnetNameA LIB "netapi32.dll" ALIAS "DsValidateSubnetNameA" ( BYREF SubnetName AS ASCIIZ ) AS QUAD
DECLARE FUNCTION DsValidateSubnetNameW LIB "netapi32.dll" ALIAS "DsValidateSubnetNameW" ( BYREF SubnetName AS WSTRINGZ
 ) AS DWORD
#IF %DEF(%UNICODE)
 MACRO DsValidateSubnetName = DsValidateSubnetNameW
#ELSE
 MACRO DsValidateSubnetName = DsValidateSubnetNameA
#ENDIF
'//
'// Only include if winsock2.h has been included
'//
#IF NOT %DEF(%SOCKET_ADDRESS_DEFINED)
%EQUATE `SOCKET_ADDRESS_DEFINED = 1
' // Size = 8 bytes
TYPE SOCKET_ADDRESS DWORD
 lpSocaddr AS SOCKADDR PTR
 iSockaddrLength AS LONG
END TYPE
#ENDIF
#IF %DEF(%WINSOCK2API)
DECLARE FUNCTION DsAddressToSiteNamesA LIB "netapi32.dll" ALIAS "DsAddressToSiteNamesA" ( BYREF ComputerName AS ASCIIZ , BYVAL EntryCount AS QUAD , BYREF SocketAddresses AS SOCKET_ADDRESS , BYREF SiteNames AS ASCIIZ ) AS QUAD
DECLARE FUNCTION DsAddressToSiteNamesW LIB "netapi32.dll" ALIAS "DsAddressToSiteNamesW" ( BYREF ComputerName AS WSTRINGZ
 , BYVAL EntryCount AS DWORD
 , BYREF SocketAddresses AS SOCKET_ADDRESS
 , BYREF SiteNames AS DWORD
 ) AS DWORD
#IF %DEF(%UNICODE)
 MACRO DsAddressToSiteNames = DsAddressToSiteNamesW
#ELSE
 MACRO DsAddressToSiteNames = DsAddressToSiteNamesA
#ENDIF
DECLARE FUNCTION DsAddressToSiteNamesExA LIB "netapi32.dll" ALIAS "DsAddressToSiteNamesExA" ( BYREF ComputerName AS ASCIIZ , BYVAL EntryCount AS QUAD , BYREF SocketAddresses AS SOCKET_ADDRESS , BYREF SiteNames AS ASCIIZ , BYREF SubnetNames AS ASCIIZ ) AS QUAD
DECLARE FUNCTION DsAddressToSiteNamesExW LIB "netapi32.dll" ALIAS "DsAddressToSiteNamesExW" ( BYREF ComputerName AS WSTRINGZ
 , BYVAL EntryCount AS DWORD
 , BYREF SocketAddresses AS SOCKET_ADDRESS
 , BYREF SiteNames AS DWORD
 , BYREF SubnetNames AS DWORD
 ) AS DWORD
#IF %DEF(%UNICODE)
 MACRO DsAddressToSiteNamesEx = DsAddressToSiteNamesExW
#ELSE
 MACRO DsAddressToSiteNamesEx = DsAddressToSiteNamesExA
#ENDIF
#ENDIF ' #IF %DEF(%WINSOCK2API)
'//
'// API to enumerate trusted domains
'//
%EQUATE `DS_DOMAIN_IN_FOREST = &H0001 ' // Domain is a member of the forest
%EQUATE `DS_DOMAIN_DIRECT_OUTBOUND = &H0002 ' // Domain is directly trusted
%EQUATE `DS_DOMAIN_TREE_ROOT = &H0004 ' // Domain is root of a tree in the forest
%EQUATE `DS_DOMAIN_PRIMARY = &H0008 ' // Domain is the primary domain of queried server
%EQUATE `DS_DOMAIN_NATIVE_MODE = &H0010 ' // Primary domain is running in native mode
%EQUATE `DS_DOMAIN_DIRECT_INBOUND = &H0020 ' // Domain is directly trusting
%EQUATE `DS_DOMAIN_VALID_FLAGS = %DS_DOMAIN_IN_FOREST OR %DS_DOMAIN_DIRECT_OUTBOUND OR %DS_DOMAIN_TREE_ROOT OR %DS_DOMAIN_PRIMARY OR %DS_DOMAIN_NATIVE_MODE OR %DS_DOMAIN_DIRECT_INBOUND
' // Size = 44 bytes
TYPE DS_DOMAIN_TRUSTSW DWORD
 NetbiosDomainName AS WSTRINGZ PTR
 DnsDomainName AS WSTRINGZ PTR
 Flags AS DWORD ' ULONG
 ParentIndex AS DWORD ' ULONG
 TrustType AS DWORD ' ULONG
 TrustAttributes AS DWORD ' ULONG
 DomainSid AS SID PTR
 DomainGuid AS GUID ' GUID
END TYPE
' // Size = 44 bytes
TYPE DS_DOMAIN_TRUSTSA DWORD
 NetbiosDomainName AS ASCIIZ PTR
 DnsDomainName AS ASCIIZ PTR
 Flags AS DWORD ' ULONG
 ParentIndex AS DWORD ' ULONG
 TrustType AS DWORD ' ULONG
 TrustAttributes AS DWORD ' ULONG
 DomainSid AS SID PTR
 DomainGuid AS GUID ' GUID
END TYPE
MACRO DS_DOMAIN_TRUSTS = DS_DOMAIN_TRUSTSA
DECLARE FUNCTION DsEnumerateDomainTrustsA LIB "netapi32.dll" ALIAS "DsEnumerateDomainTrustsA" ( BYREF ServerName AS ASCIIZ , BYVAL Flags AS QUAD , BYREF Domains AS DS_DOMAIN_TRUSTSA , BYREF DomainCount AS QUAD ) AS QUAD
DECLARE FUNCTION DsEnumerateDomainTrustsW LIB "netapi32.dll" ALIAS "DsEnumerateDomainTrustsW" ( BYREF ServerName AS WSTRINGZ
 , BYVAL Flags AS DWORD
 , BYREF Domains AS DS_DOMAIN_TRUSTSW
 , BYREF DomainCount AS DWORD
 ) AS DWORD
#IF %DEF(%UNICODE)
 MACRO DsEnumerateDomainTrusts = DsEnumerateDomainTrustsW
#ELSE
 MACRO DsEnumerateDomainTrusts = DsEnumerateDomainTrustsA
#ENDIF
'//
'// Only define this API if the caller has #included the pre-requisite
'// ntlsa.h or ntsecapi.h
'//
'#if defined(_NTLSA_) || defined(_NTSECAPI_)
#IF %DEF(%NTSECAPI)
' // There is not ansi version
DECLARE FUNCTION DsGetForestTrustInformationW LIB "netapi32.dll" ALIAS "DsGetForestTrustInformationW" ( BYREF ServerName AS WSTRINGZ , BYREF TrustedDomainName AS WSTRINGZ , BYVAL Flags AS QUAD , BYREF ForestTrustInfo AS LSA_FOREST_TRUST_INFORMATION ) AS QUAD
MACRO DsGetForestTrustInformation = DsGetForestTrustInformationW
%EQUATE `DS_GFTI_UPDATE_TDO = &H1 ' // Update TDO with information returned
%EQUATE `DS_GFTI_VALID_FLAGS = &H1 ' // All valid flags to DsGetForestTrustInformation
' // There is not ansi version
DECLARE FUNCTION DsMergeForestTrustInformationW LIB "netapi32.dll" ALIAS "DsMergeForestTrustInformationW" ( BYREF DomainName AS WSTRINGZ , BYREF NewForestTrustInfo AS LSA_FOREST_TRUST_INFORMATION , BYREF OldForestTrustInfo AS LSA_FOREST_TRUST_INFORMATION , BYREF MergedForestTrustInfo AS LSA_FOREST_TRUST_INFORMATION ) AS QUAD
MACRO DsMergeForestTrustInformation = DsMergeForestTrustInformationW
'#endif // _NTLSA_ || _NTSECAPI_
#ENDIF ' #IF %DEF(%NTSECAPI)
DECLARE FUNCTION DsGetDcSiteCoverageA LIB "netapi32.dll" ALIAS "DsGetDcSiteCoverageA" ( BYREF ServerName AS ASCIIZ , BYREF EntryCount AS QUAD , BYREF SiteNames AS ASCIIZ ) AS QUAD
DECLARE FUNCTION DsGetDcSiteCoverageW LIB "netapi32.dll" ALIAS "DsGetDcSiteCoverageW" ( BYREF ServerName AS WSTRINGZ
 , BYREF EntryCount AS DWORD
 , BYREF SiteNames AS DWORD
 ) AS DWORD
#IF %DEF(%UNICODE)
 MACRO DsGetDcSiteCoverage = DsGetDcSiteCoverageW
#ELSE
 MACRO DsGetDcSiteCoverage = DsGetDcSiteCoverageA
#ENDIF
DECLARE FUNCTION DsDeregisterDnsHostRecordsA LIB "netapi32.dll" ALIAS "DsDeregisterDnsHostRecordsA" ( BYREF ServerName AS ASCIIZ , BYREF DnsDomainName AS ASCIIZ , BYREF DomainGuid AS GUID , BYREF DsaGuid AS GUID , BYREF DnsHostName AS ASCIIZ ) AS QUAD
DECLARE FUNCTION DsDeregisterDnsHostRecordsW LIB "netapi32.dll" ALIAS "DsDeregisterDnsHostRecordsW" ( BYREF ServerName AS WSTRINGZ
 , BYREF DnsDomainName AS WSTRINGZ
 , BYREF DomainGuid AS GUID
 , BYREF DsaGuid AS GUID
 , BYREF DnsHostName AS WSTRINGZ
 ) AS DWORD
#IF %DEF(%UNICODE)
 MACRO DsDeregisterDnsHostRecords = DsDeregisterDnsHostRecordsW
#ELSE
 MACRO DsDeregisterDnsHostRecords = DsDeregisterDnsHostRecordsA
#ENDIF
#IF %DEF(%WINSOCK2API) ' // DsGetDcOpen/Next/Close depend on winsock2.h be included
'//
'// Option flags passed to DsGetDcOpen
'//
%EQUATE `DS_ONLY_DO_SITE_NAME = &H01 ' // Non-site specific names should be avoided.
%EQUATE `DS_NOTIFY_AFTER_SITE_RECORDS = &H02 ' // Return ERROR_FILEMARK_DETECTED after all
 ' // site specific records have been processed.
%EQUATE `DS_OPEN_VALID_OPTION_FLAGS = %DS_ONLY_DO_SITE_NAME OR %DS_NOTIFY_AFTER_SITE_RECORDS
'//
'// Valid DcFlags for DsGetDcOpen
'//
%EQUATE `DS_OPEN_VALID_FLAGS = %DS_FORCE_REDISCOVERY OR %DS_ONLY_LDAP_NEEDED OR %DS_KDC_REQUIRED OR %DS_PDC_REQUIRED OR %DS_GC_SERVER_REQUIRED OR %DS_WRITABLE_REQUIRED
DECLARE FUNCTION DsGetDcOpenA LIB "netapi32.dll" ALIAS "DsGetDcOpenA" ( BYREF DnsName AS ASCIIZ , BYVAL OptionFlags AS QUAD , BYREF SiteName AS ASCIIZ , BYREF DomainGuid AS GUID , BYREF DnsForestName AS ASCIIZ , BYVAL DcFlags AS QUAD , BYREF RetGetDcContext AS QUAD ) AS QUAD
DECLARE FUNCTION DsGetDcOpenW LIB "netapi32.dll" ALIAS "DsGetDcOpenW" ( BYREF DnsName AS WSTRINGZ
 , BYVAL OptionFlags AS DWORD
 , BYREF SiteName AS WSTRINGZ
 , BYREF DomainGuid AS GUID
 , BYREF DnsForestName AS WSTRINGZ
 , BYVAL DcFlags AS DWORD
 , BYREF RetGetDcContext AS DWORD
 ) AS DWORD
#IF %DEF(%UNICODE)
 MACRO DsGetDcOpen = DsGetDcOpenW
#ELSE
 MACRO DsGetDcOpen = DsGetDcOpenA
#ENDIF
DECLARE FUNCTION DsGetDcNextA LIB "netapi32.dll" ALIAS "DsGetDcNextA" ( BYVAL GetDcContextHandle AS QUAD , BYREF SockAddressCount AS QUAD , BYREF SockAddresses AS SOCKET_ADDRESS , BYREF DnsHostName AS ASCIIZ ) AS QUAD
DECLARE FUNCTION DsGetDcNextW LIB "netapi32.dll" ALIAS "DsGetDcNextW" ( BYVAL GetDcContextHandle AS QUAD
 , BYREF SockAddressCount AS DWORD
 , BYREF SockAddresses AS SOCKET_ADDRESS
 , BYREF DnsHostName AS DWORD
 ) AS DWORD
#IF %DEF(%UNICODE)
 MACRO DsGetDcNext = DsGetDcNextW
#ELSE
 MACRO DsGetDcNext = DsGetDcNextA
#ENDIF
' // There is not ansi version
DECLARE SUB DsGetDcCloseW LIB "netapi32.dll" ALIAS "DsGetDcCloseW" ( BYVAL GetDcContextHandle AS QUAD ) ' void
MACRO DsGetDcClose = DsGetDcNextW
#ENDIF ' #IF %DEF(%WINSOCK2API)
#ENDIF
