' ########################################################################################
' Microsoft Windows
' File: LMJoin.inc
' Contents: Definitions and prototypes for the Net setup apis, for joining/unjoinging
' domains and promoting/demoting servers.
' 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_LMJoin_PBI)
#DEFINE PBX_LMJoin_PBI
%EQUATE `LMJOIN_INC = 1
'//
'// Types of name that can be validated
'//
' NETSETUP_NAME_TYPE enum
%EQUATE `NetSetupUnknown = 0
%EQUATE `NetSetupMachine = 1
%EQUATE `NetSetupWorkgroup = 2
%EQUATE `NetSetupDomain = 3
%EQUATE `NetSetupNonExistentDomain = 4
'#if(_WIN32_WINNT >= 0x0500)
%EQUATE `NetSetupDnsMachine = 5
'#endif
'//
'// Status of a workstation
'//
' NETSETUP_JOIN_STATUS enum
%EQUATE `NetSetupUnknownStatus = 0
%EQUATE `NetSetupUnjoined = 1
%EQUATE `NetSetupWorkgroupName = 2
%EQUATE `NetSetupDomainName = 3
'//
'// Flags to determine the behavior of the join/unjoin APIs
'//
%EQUATE `NETSETUP_JOIN_DOMAIN = &H00000001 ' // If not present, workgroup is joined
%EQUATE `NETSETUP_ACCT_CREATE = &H00000002 ' // Do the server side account creation/rename
%EQUATE `NETSETUP_ACCT_DELETE = &H00000004 ' // Delete the account when a domain is left
%EQUATE `NETSETUP_WIN9X_UPGRADE = &H00000010 ' // Invoked during upgrade of Windows 9x to
 ' // Windows NT
%EQUATE `NETSETUP_DOMAIN_JOIN_IF_JOINED = &H00000020 ' // Allow the client to join a new domain
 ' // even if it is already joined to a domain
%EQUATE `NETSETUP_JOIN_UNSECURE = &H00000040 ' // Performs an unsecure join
%EQUATE `NETSETUP_MACHINE_PWD_PASSED = &H00000080 ' // Indicates that the machine (not user) password
 ' // is passed. Valid only for unsecure joins
%EQUATE `NETSETUP_DEFER_SPN_SET = &H00000100 ' // Specifies that writting SPN and DnsHostName
 ' // attributes on the computer object should be
 ' // defered until rename that will follow join
%EQUATE `NETSETUP_JOIN_DC_ACCOUNT = &H00000200 ' // Allow join if existing account is a DC
%EQUATE `NETSETUP_JOIN_WITH_NEW_NAME = &H00000400 ' // Check for computer name change
%EQUATE `NETSETUP_JOIN_READONLY = &H00000800 ' // Perform join using a pre-created account w/o requiring a writable DC
%EQUATE `NETSETUP_DNS_NAME_CHANGES_ONLY = &H00001000 ' // When performing machine rename only update DNS based names
%EQUATE `NETSETUP_INSTALL_INVOCATION = &H00040000 ' // The APIs were invoked during install
%EQUATE `NETSETUP_AMBIGUOUS_DC = &H00001000 ' // When joiing the domain don't try to set the
 ' // preferred DC in the registry.
%EQUATE `NETSETUP_NO_NETLOGON_CACHE = &H00002000 ' // Don't create the netlogon cache
%EQUATE `NETSETUP_DONT_CONTROL_SERVICES = &H00004000 ' // Don't force netlogon to start
%EQUATE `NETSETUP_SET_MACHINE_NAME = &H00008000 ' // For offline join only, set target machine hostname and NB name.
%EQUATE `NETSETUP_FORCE_SPN_SET = &H00010000 ' // Override other settings during domain join
 ' // and attempt to set the SPN.
%EQUATE `NETSETUP_NO_ACCT_REUSE = &H00020000 ' // Do not reuse an existing account
%EQUATE `NETSETUP_IGNORE_UNSUPPORTED_FLAGS = &H10000000 ' // If this bit is set, unrecognized flags
 ' // will be ignored by the NetJoin API and
 ' // the API will behave as if the flags
 ' // were not set.
%EQUATE `NETSETUP_VALID_UNJOIN_FLAGS = %NETSETUP_ACCT_DELETE OR %NETSETUP_IGNORE_UNSUPPORTED_FLAGS OR %NETSETUP_JOIN_DC_ACCOUNT
'// The following flags are used when the system is processing information left from a prior offline
'// join. We want to force DC discovery and we don't want to create the netlogon cache. We also
'// don't want to immediately force netlogon to start, let it start on its own.
%EQUATE `NETSETUP_PROCESS_OFFLINE_FLAGS = %NETSETUP_JOIN_DOMAIN OR %NETSETUP_DOMAIN_JOIN_IF_JOINED OR %NETSETUP_JOIN_WITH_NEW_NAME OR %NETSETUP_DONT_CONTROL_SERVICES OR %NETSETUP_MACHINE_PWD_PASSED
'//
'// 0x80000000 is reserved for internal use only
'//
'//
'// Joins a machine to the domain.
'//
DECLARE FUNCTION NetJoinDomain LIB "netapi32.dll" ALIAS "NetJoinDomain" ( BYREF lpServer AS WSTRINGZ , BYREF lpDomain AS WSTRINGZ , BYREF lpAccountOU AS WSTRINGZ , BYREF lpAccount AS WSTRINGZ , BYREF lpPassword AS WSTRINGZ , BYVAL fJoinOptions AS QUAD ) AS QUAD ' NET_API_STATUS
'#if(_WIN32_WINNT >= 0x0601)
'//
'// Flags to determine the behavior of NetProvisionComputerAccount
'//
'// The caller requires account creation by privilege, this option will cause a retry
'// on failure using down level account creation APIs.
'//
%EQUATE `NETSETUP_PROVISION_DOWNLEVEL_PRIV_SUPPORT = &H00000001
'// If the named account already exists an attempt will be made to reuse. Requires
'// sufficient credentials i.e. Domain Administrator or the object owner.
'//
%EQUATE `NETSETUP_PROVISION_REUSE_ACCOUNT = &H00000002
'// Use the default machine account password which is the machine name in lowercase.
'//
%EQUATE `NETSETUP_PROVISION_USE_DEFAULT_PASSWORD = &H00000004
'// Do not try to find the account on any DC in the domain. This is faster but
'// should only be used when the caller is certain that an account by the same
'// name hasn't recently been created. Only valid when specifying the target DC.
'// When the pre-requisites are met, this option allows for must faster provisioning
'// useful for scenarios such as batch processing.
'//
%EQUATE `NETSETUP_PROVISION_SKIP_ACCOUNT_SEARCH = &H00000008
'//
'// The following are reserved for internal use.
'//
'// The operation is online.
'// This is an internal option not available through the API.
'//
%EQUATE `NETSETUP_PROVISION_ONLINE_CALLER = &H40000000
'// Validate the machine password only. This is an internal option not available
'// through the API.
'//
%EQUATE `NETSETUP_PROVISION_CHECK_PWD_ONLY = &H80000000
DECLARE FUNCTION NetProvisionComputerAccount LIB "netapi32.dll" ALIAS "NetProvisionComputerAccount" ( BYREF lpDomain AS WSTRINGZ , BYREF lpMachineName AS WSTRINGZ , BYREF lpMachineAccountOU AS WSTRINGZ , BYREF lpDcName AS WSTRINGZ , BYVAL dwOptions AS QUAD , BYREF pProvisionBinData AS ANY , BYREF pdwProvisionBinDataSize AS QUAD , BYREF pProvisionTextData AS ANY ) AS QUAD ' NET_API_STATUS
DECLARE FUNCTION NetRequestOfflineDomainJoin LIB "netapi32.dll" ALIAS "NetRequestOfflineDomainJoin" ( BYVAL pProvisionBinData AS BYTE PTR , BYVAL cbProvisionBinDataSize AS QUAD , BYVAL dwOptions AS QUAD , BYREF lpWindowsPath AS WSTRINGZ ) AS QUAD ' NET_API_STATUS
'#endif // (_WIN32_WINNT >= 0x0601)
DECLARE FUNCTION NetUnjoinDomain LIB "netapi32.dll" ALIAS "NetUnjoinDomain" ( BYREF lpServer AS WSTRINGZ , BYREF lpAccount AS WSTRINGZ , BYREF lpPassword AS WSTRINGZ , BYVAL fUnjoinOptions AS QUAD ) AS QUAD ' NET_API_STATUS
DECLARE FUNCTION NetRenameMachineInDomain LIB "netapi32.dll" ALIAS "NetRenameMachineInDomain" ( BYREF lpServer AS WSTRINGZ , BYREF lpNewMachineName AS WSTRINGZ , BYREF lpAccount AS WSTRINGZ , BYREF lpPassword AS WSTRINGZ , BYVAL fRenameOptions AS QUAD ) AS QUAD ' NET_API_STATUS
'//
'// Determine the validity of a name
'//
DECLARE FUNCTION NetValidateName LIB "netapi32.dll" ALIAS "NetValidateName" ( BYREF lpServer AS WSTRINGZ , BYREF lpName AS WSTRINGZ , BYREF lpAccount AS WSTRINGZ , BYREF lpPassword AS WSTRINGZ , BYVAL NameType AS LONG ) AS QUAD ' NET_API_STATUS
'//
'// Determines whether a workstation is joined to a domain or not
'//
DECLARE FUNCTION NetGetJoinInformation LIB "netapi32.dll" ALIAS "NetGetJoinInformation" ( BYREF lpServer AS WSTRINGZ , BYREF lpNameBuffer AS ANY , BYREF BufferType AS LONG ) AS QUAD ' NET_API_STATUS
'//
'// Determines the list of OUs that the client can create a machine account in
'//
DECLARE FUNCTION NetGetJoinableOUs LIB "netapi32.dll" ALIAS "NetGetJoinableOUs" ( BYREF lpServer AS WSTRINGZ , BYREF lpDomain AS WSTRINGZ , BYREF lpAccount AS WSTRINGZ , BYREF lpPassword AS WSTRINGZ , BYREF OUCount AS QUAD , BYREF OUs AS ANY ) AS QUAD ' NET_API_STATUS
'#if(_WIN32_WINNT >= 0x0501)
'//
'// Computer rename preparation APIs
'//
'#define NET_IGNORE_UNSUPPORTED_FLAGS 0x01
%EQUATE `NET_IGNORE_UNSUPPORTED_FLAGS = &H01
DECLARE FUNCTION NetAddAlternateComputerName LIB "netapi32.dll" ALIAS "NetAddAlternateComputerName" ( BYREF Server AS WSTRINGZ , BYREF AlternateName AS WSTRINGZ , BYREF DomainAccount AS WSTRINGZ , BYREF DomainAccountPassword AS WSTRINGZ , BYVAL Reserved AS QUAD ) AS QUAD ' NET_API_STATUS
DECLARE FUNCTION NetRemoveAlternateComputerName LIB "netapi32.dll" ALIAS "NetRemoveAlternateComputerName" ( BYREF Server AS WSTRINGZ , BYREF AlternateName AS WSTRINGZ , BYREF DomainAccount AS WSTRINGZ , BYREF DomainAccountPassword AS WSTRINGZ , BYVAL Reserved AS QUAD ) AS QUAD ' NET_API_STATUS
DECLARE FUNCTION NetSetPrimaryComputerName LIB "netapi32.dll" ALIAS "NetSetPrimaryComputerName" ( BYREF Server AS WSTRINGZ , BYREF PrimaryName AS WSTRINGZ , BYREF DomainAccount AS WSTRINGZ , BYREF DomainAccountPassword AS WSTRINGZ , BYVAL Reserved AS QUAD ) AS QUAD ' NET_API_STATUS
'//
'// The following enumeration must be kept
'// in sync with COMPUTER_NAME_TYPE defined
'// in winbase.h
'//
' NET_COMPUTER_NAME_TYPE enum
%EQUATE `NetPrimaryComputerName = 0
%EQUATE `NetAlternateComputerNames = 1
%EQUATE `NetAllComputerNames = 2
%EQUATE `NetComputerNameTypeMax = 3
DECLARE FUNCTION NetEnumerateComputerNames LIB "netapi32.dll" ALIAS "NetEnumerateComputerNames" ( BYREF Server AS WSTRINGZ , BYVAL NameType AS LONG , BYVAL Reserved AS QUAD , BYREF EntryCount AS QUAD , BYREF ComputerNames AS ANY ) AS QUAD ' NET_API_STATUS
'#endif // (_WIN32_WINNT >= 0x0501)
#ENDIF
