' ########################################################################################
' Microsoft Windows
' File: WinCred.inc
' Contents: Public data structures and API definitions needed for the Credential Manager.
' 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_wincred_PBI)
#DEFINE PBX_wincred_PBI
%EQUATE `WINCRED_INC = 1
#INCLUDE ONCE "Core/Windows.inc"
#INCLUDE ONCE "Legacy/Platform/LMErr.inc"
#INCLUDE ONCE "Legacy/Platform/ntstatus.inc"
'//
'// Ensure PCtxtHandle is defined
'//
#IF NOT %DEF(%SECHANDLE_DEFINED)
%EQUATE `SECHANDLE_DEFINED = 1
' // Size = 8 bytes
TYPE SecHandle DWORD
 dwLower AS DWORD ' ULONG_PTR
 dwUpper AS DWORD ' ULONG_PTR
END TYPE
#ENDIF
'typedef PSecHandle PCtxtHandle;
'//
'// Ensure FILETIME is defined
'//
'#ifndef _WINBASE_
'#ifndef _FILETIME_
'#define _FILETIME_
'typedef struct _FILETIME
' {
' DWORD dwLowDateTime;
' DWORD dwHighDateTime;
' } FILETIME;
'typedef struct _FILETIME *PFILETIME;
'typedef struct _FILETIME *LPFILETIME;
'#endif // !_FILETIME
'#endif // _WINBASE_
#IF NOT %DEF(%FILETIME_DEFINED)
%EQUATE `FILETIME_DEFINED = 1
' // Size = 8 bytes
TYPE FILETIME_STRUCT DWORD
 dwLowDateTime AS DWORD
 dwHighDateTime AS DWORD
END TYPE
' // To allow to use both DWORD's and a QUAD
' // Size = 8 bytes
UNION FILETIME DWORD
 FILETIME_STRUCT
 qDateTime AS QUAD
END UNION
#ENDIF
'//
'// Ensure NTSTATUS is defined
'//
'#ifndef _NTDEF_
'typedef LONG NTSTATUS, *PNTSTATUS;
'#endif
'//-----------------------------------------------------------------------------
'// Macros
'//-----------------------------------------------------------------------------
'//
'// Macro to determine whether CredUIPromptForCredentials should be called upon a failed
'// authentication attempt.
'//
'// Implemented as a macro so that the caller can delay load credui.dll only if this
'// macro returns TRUE.
'//
'// Include only status codes that imply the username/password are wrong or that the
'// password is expired. In the former case, asking for a another username or password
'// is appropriate. In the later case, we put up a different dialog asking the
'// user to change the password on the server.
'//
'// Don't include status codes such as ERROR_ACCOUNT_DISABLED, ERROR_ACCOUNT_RESTRICTION,
'// ERROR_ACCOUNT_LOCKED_OUT, ERROR_ACCOUNT_EXPIRED, ERROR_LOGON_TYPE_NOT_GRANTED.
'// For those, the user isn't going to have another account so prompting him
'// won't help.
'//
'// STATUS_DOWNGRADE_DETECTED is included to handle the case where a corporate laptop
'// is brought to another LAN. A downgrade attack will indeed be detected,
'// but we want to popup UI to allow the user to connect to resources in the
'// other LAN.
'//
'// Don't use the CREDUIP_* macros directly. Their definition is private to credui.dll.
'//
'// Don't require ntstatus.h
%EQUATE `STATUS_LOGON_FAILURE = &HC000006D& ' // ntsubauth
%EQUATE `STATUS_WRONG_PASSWORD = &HC000006A& ' // ntsubauth
%EQUATE `STATUS_PASSWORD_EXPIRED = &HC0000071& ' // ntsubauth
%EQUATE `STATUS_PASSWORD_MUST_CHANGE = &HC0000224& ' // ntsubauth
%EQUATE `STATUS_ACCESS_DENIED = &HC0000022&
%EQUATE `STATUS_DOWNGRADE_DETECTED = &HC0000388&
%EQUATE `STATUS_AUTHENTICATION_FIREWALL_FAILED = &HC0000413&
%EQUATE `STATUS_ACCOUNT_DISABLED = &HC0000072& ' // ntsubauth
%EQUATE `STATUS_ACCOUNT_RESTRICTION = &HC000006E& ' // ntsubauth
%EQUATE `STATUS_ACCOUNT_LOCKED_OUT = &HC0000234& ' // ntsubauth
%EQUATE `STATUS_ACCOUNT_EXPIRED = &HC0000193& ' // ntsubauth
%EQUATE `STATUS_LOGON_TYPE_NOT_GRANTED = &HC000015B&
FUNCTION CREDUIP_IS_USER_PASSWORD_ERROR(BYVAL nStatus AS LONG) AS LONG
 IF nStatus = %ERROR_LOGON_FAILURE OR nStatus = HRESULT_FROM_WIN32(%ERROR_LOGON_FAILURE) OR nStatus = %STATUS_LOGON_FAILURE OR nStatus = HRESULT_FROM_NT(%STATUS_LOGON_FAILURE) OR nStatus = %ERROR_ACCESS_DENIED OR nStatus = HRESULT_FROM_WIN32(%ERROR_ACCESS_DENIED) OR nStatus = %STATUS_ACCESS_DENIED OR nStatus = HRESULT_FROM_NT(%STATUS_ACCESS_DENIED) OR nStatus = %ERROR_INVALID_PASSWORD OR nStatus = HRESULT_FROM_WIN32(%ERROR_INVALID_PASSWORD) OR nStatus = %STATUS_WRONG_PASSWORD OR nStatus = HRESULT_FROM_NT(%STATUS_WRONG_PASSWORD) OR nStatus = %SEC_E_NO_CREDENTIALS OR nStatus = %SEC_E_LOGON_DENIED OR nStatus = %SEC_E_NO_CONTEXT OR nStatus = %STATUS_NO_SECURITY_CONTEXT THEN
 FUNCTION = %TRUE
 END IF
END FUNCTION
FUNCTION CREDUIP_IS_DOWNGRADE_ERROR(BYVAL nStatus AS LONG) AS LONG
 IF nStatus = %ERROR_DOWNGRADE_DETECTED OR nStatus = HRESULT_FROM_WIN32(%ERROR_DOWNGRADE_DETECTED) OR nStatus = %STATUS_DOWNGRADE_DETECTED OR nStatus = HRESULT_FROM_NT(%STATUS_DOWNGRADE_DETECTED) THEN
 FUNCTION = %TRUE
 END IF
END FUNCTION
FUNCTION CREDUIP_IS_EXPIRED_ERROR(BYVAL nStatus AS LONG) AS LONG
 IF nStatus = %ERROR_PASSWORD_EXPIRED OR nStatus = HRESULT_FROM_WIN32(%ERROR_PASSWORD_EXPIRED) OR nStatus = %STATUS_PASSWORD_EXPIRED OR nStatus = HRESULT_FROM_NT(%STATUS_PASSWORD_EXPIRED) OR nStatus = %ERROR_PASSWORD_MUST_CHANGE OR nStatus = HRESULT_FROM_WIN32(%ERROR_PASSWORD_MUST_CHANGE) OR nStatus = %STATUS_PASSWORD_MUST_CHANGE OR nStatus = HRESULT_FROM_NT(%STATUS_PASSWORD_MUST_CHANGE) OR nStatus = %NERR_PasswordExpired OR nStatus = HRESULT_FROM_WIN32(%NERR_PasswordExpired) THEN
 FUNCTION = %TRUE
 END IF
END FUNCTION
FUNCTION CREDUI_IS_AUTHENTICATION_ERROR(BYVAL nStatus AS LONG) AS LONG
 IF CREDUIP_IS_USER_PASSWORD_ERROR(nStatus) OR CREDUIP_IS_DOWNGRADE_ERROR(nStatus) OR CREDUIP_IS_EXPIRED_ERROR(nStatus) THEN
 FUNCTION = %TRUE
 END IF
END FUNCTION
FUNCTION CREDUI_NO_PROMPT_AUTHENTICATION_ERROR(BYVAL nStatus AS LONG) AS LONG
 IF nStatus = %ERROR_AUTHENTICATION_FIREWALL_FAILED OR nStatus = HRESULT_FROM_WIN32(%ERROR_AUTHENTICATION_FIREWALL_FAILED) OR nStatus = %STATUS_AUTHENTICATION_FIREWALL_FAILED OR nStatus = HRESULT_FROM_NT(%STATUS_AUTHENTICATION_FIREWALL_FAILED) OR nStatus = %ERROR_ACCOUNT_DISABLED OR nStatus = HRESULT_FROM_WIN32(%ERROR_ACCOUNT_DISABLED) OR nStatus = %STATUS_ACCOUNT_DISABLED OR nStatus = HRESULT_FROM_NT(%STATUS_ACCOUNT_DISABLED) OR nStatus = %ERROR_ACCOUNT_RESTRICTION OR nStatus = HRESULT_FROM_WIN32(%ERROR_ACCOUNT_RESTRICTION) OR nStatus = %STATUS_ACCOUNT_RESTRICTION OR nStatus = HRESULT_FROM_NT(%STATUS_ACCOUNT_RESTRICTION) OR nStatus = %ERROR_ACCOUNT_LOCKED_OUT OR nStatus = HRESULT_FROM_WIN32(%ERROR_ACCOUNT_LOCKED_OUT) OR nStatus = %STATUS_ACCOUNT_LOCKED_OUT OR nStatus = HRESULT_FROM_NT(%STATUS_ACCOUNT_LOCKED_OUT) OR nStatus = %ERROR_ACCOUNT_EXPIRED OR nStatus = HRESULT_FROM_WIN32(%ERROR_ACCOUNT_EXPIRED) OR nStatus = %STATUS_ACCOUNT_EXPIRED OR nStatus = HRESULT_FROM_NT(%STATUS_ACCOUNT_EXPIRED) OR nStatus = %ERROR_LOGON_TYPE_NOT_GRANTED OR nStatus = HRESULT_FROM_WIN32(%ERROR_LOGON_TYPE_NOT_GRANTED) OR nStatus = %STATUS_LOGON_TYPE_NOT_GRANTED OR nStatus = HRESULT_FROM_NT(%STATUS_LOGON_TYPE_NOT_GRANTED) THEN
 FUNCTION = %TRUE
 END IF
END FUNCTION
'//-----------------------------------------------------------------------------
'// Structures
'//-----------------------------------------------------------------------------
'//
'// Credential Attribute
'//
'// Maximum length of the various credential string fields (in characters)
%EQUATE `CRED_MAX_STRING_LENGTH = 256
'// Maximum length of the UserName field. The worst case is <User>@<DnsDomain>
%EQUATE `CRED_MAX_USERNAME_LENGTH = (256+1+256)
'// Maximum length of the TargetName field for CRED_TYPE_GENERIC (in characters)
%EQUATE `CRED_MAX_GENERIC_TARGET_NAME_LENGTH = 32767
'// Maximum length of the TargetName field for CRED_TYPE_DOMAIN_* (in characters)
'// Largest one is <DfsRoot>\<DfsShare>
%EQUATE `CRED_MAX_DOMAIN_TARGET_NAME_LENGTH = (256+1+80)
'// Maximum size of the Credential Attribute Value field (in bytes)
%EQUATE `CRED_MAX_VALUE_SIZE = 256
'// Maximum number of attributes per credential
%EQUATE `CRED_MAX_ATTRIBUTES = 64
' // Size = 16 bytes
TYPE CREDENTIAL_ATTRIBUTEA DWORD
 Keyword AS ASCIIZ PTR
 Flags AS DWORD
 ValueSize AS DWORD
 Value AS BYTE PTR
END TYPE
' // Size = 16 bytes
TYPE CREDENTIAL_ATTRIBUTEW DWORD
 Keyword AS WSTRINGZ PTR
 Flags AS DWORD
 ValueSize AS DWORD
 Value AS BYTE PTR
END TYPE
#IF %DEF(%UNICODE)
 MACRO CREDENTIAL_ATTRIBUTE = CREDENTIAL_ATTRIBUTEW
#ELSE
 MACRO CREDENTIAL_ATTRIBUTE = CREDENTIAL_ATTRIBUTEA
#ENDIF
'//
'// Special values of the TargetName field
'//
'#define CRED_SESSION_WILDCARD_NAME_W L"*Session"
'#define CRED_SESSION_WILDCARD_NAME_A "*Session"
'#define CRED_UNIVERSAL_WILDCARD_W L'*'
'#define CRED_UNIVERSAL_WILDCARD_A '*'
'#define CRED_SESSION_WILDCARD_NAME_LENGTH (sizeof(CRED_SESSION_WILDCARD_NAME_A)-1)
'#define CRED_TARGETNAME_DOMAIN_NAMESPACE_W L"Domain"
'#define CRED_TARGETNAME_DOMAIN_NAMESPACE_A "Domain"
'#define CRED_TARGETNAME_DOMAIN_NAMESPACE_LENGTH (sizeof(CRED_TARGETNAME_DOMAIN_NAMESPACE_A)-1)
'#define CRED_UNIVERSAL_WILDCARD_W L'*'
'#define CRED_UNIVERSAL_WILDCARD_A '*'
'#define CRED_TARGETNAME_LEGACYGENERIC_NAMESPACE_W L"LegacyGeneric"
'#define CRED_TARGETNAME_LEGACYGENERIC_NAMESPACE_A "LegacyGeneric"
'#define CRED_TARGETNAME_LEGACYGENERIC_NAMESPACE_LENGTH (sizeof(CRED_TARGETNAME_LEGACYGENERIC_NAMESPACE_A)-1)
'#define CRED_TARGETNAME_NAMESPACE_SEPERATOR_W L':'
'#define CRED_TARGETNAME_NAMESPACE_SEPERATOR_A ':'
'#define CRED_TARGETNAME_ATTRIBUTE_SEPERATOR_W L'='
'#define CRED_TARGETNAME_ATTRIBUTE_SEPERATOR_A '='
'#define CRED_TARGETNAME_DOMAIN_EXTENDED_USERNAME_SEPARATOR_W L'|'
'#define CRED_TARGETNAME_DOMAIN_EXTENDED_USERNAME_SEPARATOR_A '|'
'#define CRED_TARGETNAME_ATTRIBUTE_TARGET_W L"target"
'#define CRED_TARGETNAME_ATTRIBUTE_TARGET_A "target"
'#define CRED_TARGETNAME_ATTRIBUTE_TARGET_LENGTH (sizeof(CRED_TARGETNAME_ATTRIBUTE_TARGET_A)-1)
'#define CRED_TARGETNAME_ATTRIBUTE_NAME_W L"name"
'#define CRED_TARGETNAME_ATTRIBUTE_NAME_A "name"
'#define CRED_TARGETNAME_ATTRIBUTE_NAME_LENGTH (sizeof(CRED_TARGETNAME_ATTRIBUTE_NAME_A)-1)
'#define CRED_TARGETNAME_ATTRIBUTE_BATCH_W L"batch"
'#define CRED_TARGETNAME_ATTRIBUTE_BATCH_A "batch"
'#define CRED_TARGETNAME_ATTRIBUTE_BATCH_LENGTH (sizeof(CRED_TARGETNAME_ATTRIBUTE_BATCH_A)-1)
'#define CRED_TARGETNAME_ATTRIBUTE_INTERACTIVE_W L"interactive"
'#define CRED_TARGETNAME_ATTRIBUTE_INTERACTIVE_A "interactive"
'#define CRED_TARGETNAME_ATTRIBUTE_INTERACTIVE_LENGTH (sizeof(CRED_TARGETNAME_ATTRIBUTE_INTERACTIVE_A)-1)
'#define CRED_TARGETNAME_ATTRIBUTE_SERVICE_W L"service"
'#define CRED_TARGETNAME_ATTRIBUTE_SERVICE_A "service"
'#define CRED_TARGETNAME_ATTRIBUTE_SERVICE_LENGTH (sizeof(CRED_TARGETNAME_ATTRIBUTE_SERVICE_A)-1)
'#define CRED_TARGETNAME_ATTRIBUTE_NETWORK_W L"network"
'#define CRED_TARGETNAME_ATTRIBUTE_NETWORK_A "network"
'#define CRED_TARGETNAME_ATTRIBUTE_NETWORK_LENGTH (sizeof(CRED_TARGETNAME_ATTRIBUTE_NETWORK_A)-1)
'#define CRED_TARGETNAME_ATTRIBUTE_NETWORKCLEARTEXT_W L"networkcleartext"
'#define CRED_TARGETNAME_ATTRIBUTE_NETWORKCLEARTEXT_A "networkcleartext"
'#define CRED_TARGETNAME_ATTRIBUTE_NETWORKCLEARTEXT_LENGTH (sizeof(CRED_TARGETNAME_ATTRIBUTE_NETWORKCLEARTEXT_A)-1)
'#define CRED_TARGETNAME_ATTRIBUTE_REMOTEINTERACTIVE_W L"remoteinteractive"
'#define CRED_TARGETNAME_ATTRIBUTE_REMOTEINTERACTIVE_A "remoteinteractive"
'#define CRED_TARGETNAME_ATTRIBUTE_REMOTEINTERACTIVE_LENGTH (sizeof(CRED_TARGETNAME_ATTRIBUTE_REMOTEINTERACTIVE_A)-1)
'#define CRED_TARGETNAME_ATTRIBUTE_CACHEDINTERACTIVE_W L"cachedinteractive"
'#define CRED_TARGETNAME_ATTRIBUTE_CACHEDINTERACTIVE_A "cachedinteractive"
'#define CRED_TARGETNAME_ATTRIBUTE_CACHEDINTERACTIVE_LENGTH (sizeof(CRED_TARGETNAME_ATTRIBUTE_CACHEDINTERACTIVE_A)-1)
$$CRED_SESSION_WILDCARD_NAME_W = "*Session"$$
$CRED_SESSION_WILDCARD_NAME_A = "*Session"
$$CRED_UNIVERSAL_WILDCARD_W = "*"$$
$CRED_UNIVERSAL_WILDCARD_A = "*"
%EQUATE `CRED_SESSION_WILDCARD_NAME_LENGTH = 7 ' (LEN($CRED_SESSION_WILDCARD_NAME_A)-1)
$$CRED_TARGETNAME_DOMAIN_NAMESPACE_W = "Domain"$$
$CRED_TARGETNAME_DOMAIN_NAMESPACE_A = "Domain"
%EQUATE `CRED_TARGETNAME_DOMAIN_NAMESPACE_LENGTH = 5 ' (LEN($CRED_TARGETNAME_DOMAIN_NAMESPACE_A)-1)
$$CRED_UNIVERSAL_WILDCARD_W = "*"$$
$CRED_UNIVERSAL_WILDCARD_A = "*"
$$CRED_TARGETNAME_LEGACYGENERIC_NAMESPACE_W = "LegacyGeneric"$$
$CRED_TARGETNAME_LEGACYGENERIC_NAMESPACE_A = "LegacyGeneric"
%EQUATE `CRED_TARGETNAME_LEGACYGENERIC_NAMESPACE_LENGTH = 12 ' (LEN($CRED_TARGETNAME_LEGACYGENERIC_NAMESPACE_A)-1)
$$CRED_TARGETNAME_NAMESPACE_SEPERATOR_W = ":"$$
$CRED_TARGETNAME_NAMESPACE_SEPERATOR_A = ":"
$$CRED_TARGETNAME_ATTRIBUTE_SEPERATOR_W = "="$$
$CRED_TARGETNAME_ATTRIBUTE_SEPERATOR_A = "="
$$CRED_TARGETNAME_DOMAIN_EXTENDED_USERNAME_SEPARATOR_W = "|"$$
$CRED_TARGETNAME_DOMAIN_EXTENDED_USERNAME_SEPARATOR_A = "|"
$$CRED_TARGETNAME_ATTRIBUTE_TARGET_W = "target"$$
$CRED_TARGETNAME_ATTRIBUTE_TARGET_A = "target"
%EQUATE `CRED_TARGETNAME_ATTRIBUTE_TARGET_LENGTH = 5 ' (LEN($CRED_TARGETNAME_ATTRIBUTE_TARGET_A)-1)
$$CRED_TARGETNAME_ATTRIBUTE_NAME_W = "name"$$
$CRED_TARGETNAME_ATTRIBUTE_NAME_A = "name"
%EQUATE `CRED_TARGETNAME_ATTRIBUTE_NAME_LENGTH = 3 ' (LEN($CRED_TARGETNAME_ATTRIBUTE_NAME_A)-1)
$$CRED_TARGETNAME_ATTRIBUTE_BATCH_W = "batch"$$
$CRED_TARGETNAME_ATTRIBUTE_BATCH_A = "batch"
%EQUATE `CRED_TARGETNAME_ATTRIBUTE_BATCH_LENGTH = 4 ' (LEN($CRED_TARGETNAME_ATTRIBUTE_BATCH_A)-1)
$$CRED_TARGETNAME_ATTRIBUTE_INTERACTIVE_W = "interactive"$$
$CRED_TARGETNAME_ATTRIBUTE_INTERACTIVE_A = "interactive"
%EQUATE `CRED_TARGETNAME_ATTRIBUTE_INTERACTIVE_LENGTH = 10 ' (LEN($CRED_TARGETNAME_ATTRIBUTE_INTERACTIVE_A)-1)
$$CRED_TARGETNAME_ATTRIBUTE_SERVICE_W = "service"$$
$CRED_TARGETNAME_ATTRIBUTE_SERVICE_A = "service"
%EQUATE `CRED_TARGETNAME_ATTRIBUTE_SERVICE_LENGTH = 6 ' (LEN($CRED_TARGETNAME_ATTRIBUTE_SERVICE_A)-1)
$$CRED_TARGETNAME_ATTRIBUTE_NETWORK_W = "network"$$
$CRED_TARGETNAME_ATTRIBUTE_NETWORK_A = "network"
%EQUATE `CRED_TARGETNAME_ATTRIBUTE_NETWORK_LENGTH = 6 ' (LEN($CRED_TARGETNAME_ATTRIBUTE_NETWORK_A)-1)
$$CRED_TARGETNAME_ATTRIBUTE_NETWORKCLEARTEXT_W = "networkcleartext"$$
$CRED_TARGETNAME_ATTRIBUTE_NETWORKCLEARTEXT_A = "networkcleartext"
%EQUATE `CRED_TARGETNAME_ATTRIBUTE_NETWORKCLEARTEXT_LENGTH = 15 ' (LEN($CRED_TARGETNAME_ATTRIBUTE_NETWORKCLEARTEXT_A)-1)
$$CRED_TARGETNAME_ATTRIBUTE_REMOTEINTERACTIVE_W = "remoteinteractive"$$
$CRED_TARGETNAME_ATTRIBUTE_REMOTEINTERACTIVE_A = "remoteinteractive"
%EQUATE `CRED_TARGETNAME_ATTRIBUTE_REMOTEINTERACTIVE_LENGTH = 16 ' (LEN($CRED_TARGETNAME_ATTRIBUTE_REMOTEINTERACTIVE_A)-1)
$$CRED_TARGETNAME_ATTRIBUTE_CACHEDINTERACTIVE_W = "cachedinteractive"$$
$CRED_TARGETNAME_ATTRIBUTE_CACHEDINTERACTIVE_A = "cachedinteractive"
%EQUATE `CRED_TARGETNAME_ATTRIBUTE_CACHEDINTERACTIVE_LENGTH = 16 ' (LEN($CRED_TARGETNAME_ATTRIBUTE_CACHEDINTERACTIVE_A)-1)
#IF %DEF(%UNICODE)
MACRO CRED_SESSION_WILDCARD_NAME = $$CRED_SESSION_WILDCARD_NAME_W
MACRO CRED_TARGETNAME_DOMAIN_NAMESPACE = $$CRED_TARGETNAME_DOMAIN_NAMESPACE_W
MACRO CRED_UNIVERSAL_WILDCARD = $$CRED_UNIVERSAL_WILDCARD_W
MACRO CRED_TARGETNAME_NAMESPACE_SEPERATOR = $$CRED_TARGETNAME_NAMESPACE_SEPERATOR_W
MACRO CRED_TARGETNAME_ATTRIBUTE_SEPERATOR = $$CRED_TARGETNAME_ATTRIBUTE_SEPERATOR_W
MACRO CRED_TARGETNAME_ATTRIBUTE_NAME = $$CRED_TARGETNAME_ATTRIBUTE_NAME_W
MACRO CRED_TARGETNAME_ATTRIBUTE_TARGET = $$CRED_TARGETNAME_ATTRIBUTE_TARGET_W
MACRO CRED_TARGETNAME_ATTRIBUTE_BATCH = $$CRED_TARGETNAME_ATTRIBUTE_BATCH_W
MACRO CRED_TARGETNAME_ATTRIBUTE_INTERACTIVE = $$CRED_TARGETNAME_ATTRIBUTE_INTERACTIVE_W
MACRO CRED_TARGETNAME_ATTRIBUTE_SERVICE = $$CRED_TARGETNAME_ATTRIBUTE_SERVICE_W
MACRO CRED_TARGETNAME_ATTRIBUTE_NETWORK = $$CRED_TARGETNAME_ATTRIBUTE_NETWORK_W
MACRO CRED_TARGETNAME_ATTRIBUTE_NETWORKCLEARTEXT = $$CRED_TARGETNAME_ATTRIBUTE_NETWORKCLEARTEXT_W
MACRO CRED_TARGETNAME_ATTRIBUTE_REMOTEINTERACTIVE = $$CRED_TARGETNAME_ATTRIBUTE_REMOTEINTERACTIVE_W
MACRO CRED_TARGETNAME_ATTRIBUTE_CACHEDINTERACTIVE = $$CRED_TARGETNAME_ATTRIBUTE_CACHEDINTERACTIVE_W
#ELSE
MACRO CRED_SESSION_WILDCARD_NAME = $CRED_SESSION_WILDCARD_NAME_A
MACRO CRED_TARGETNAME_DOMAIN_NAMESPACE = $CRED_TARGETNAME_DOMAIN_NAMESPACE_A
MACRO CRED_UNIVERSAL_WILDCARD = $CRED_UNIVERSAL_WILDCARD_A
MACRO CRED_TARGETNAME_NAMESPACE_SEPERATOR = $CRED_TARGETNAME_NAMESPACE_SEPERATOR_A
MACRO CRED_TARGETNAME_ATTRIBUTE_SEPERATOR = $CRED_TARGETNAME_ATTRIBUTE_SEPERATOR_A
MACRO CRED_TARGETNAME_ATTRIBUTE_NAME = $CRED_TARGETNAME_ATTRIBUTE_NAME_A
MACRO CRED_TARGETNAME_ATTRIBUTE_TARGET = $CRED_TARGETNAME_ATTRIBUTE_TARGET_A
MACRO CRED_TARGETNAME_ATTRIBUTE_BATCH = $CRED_TARGETNAME_ATTRIBUTE_BATCH_A
MACRO CRED_TARGETNAME_ATTRIBUTE_INTERACTIVE = $CRED_TARGETNAME_ATTRIBUTE_INTERACTIVE_A
MACRO CRED_TARGETNAME_ATTRIBUTE_SERVICE = $CRED_TARGETNAME_ATTRIBUTE_SERVICE_A
MACRO CRED_TARGETNAME_ATTRIBUTE_NETWORK = $CRED_TARGETNAME_ATTRIBUTE_NETWORK_A
MACRO CRED_TARGETNAME_ATTRIBUTE_NETWORKCLEARTEXT = $CRED_TARGETNAME_ATTRIBUTE_NETWORKCLEARTEXT_A
MACRO CRED_TARGETNAME_ATTRIBUTE_REMOTEINTERACTIVE = $CRED_TARGETNAME_ATTRIBUTE_REMOTEINTERACTIVE_A
MACRO CRED_TARGETNAME_ATTRIBUTE_CACHEDINTERACTIVE = $CRED_TARGETNAME_ATTRIBUTE_CACHEDINTERACTIVE_A
#ENDIF ' UNICODE
'//
'// Add\Extract Logon type from flags
'//
%EQUATE `CRED_LOGON_TYPES_MASK = &HF000 ' // Mask to get logon types
'#define CredAppendLogonTypeToFlags(Flags, LogonType) (Flags) |= ((LogonType) << 12)
'#define CredGetLogonTypeFromFlags(Flags) ((SECURITY_LOGON_TYPE)(((Flags) & CRED_LOGON_TYPES_MASK) >> 12))
'#define CredRemoveLogonTypeFromFlags(Flags) (Flags) &= ~CRED_LOGON_TYPES_MASK
FUNCTION CredAppendLogonTypeToFlags (BYVAL Flags AS DWORD, BYVAL LogonType AS DWORD) AS DWORD
 SHIFT LEFT LogonType, 12
 FUNCTION = Flags OR LogonType
END FUNCTION
FUNCTION CredGetLogonTypeFromFlags (BYVAL Flags AS DWORD) AS DWORD
 LOCAL x AS DWORD
 x = Flags AND %CRED_LOGON_TYPES_MASK
 SHIFT RIGHT x, 12
 FUNCTION = x
END FUNCTION
FUNCTION CredRemoveLogonTypeFromFlags (BYVAL Flags AS DWORD) AS DWORD
 FUNCTION = Flags AND (NOT %CRED_LOGON_TYPES_MASK)
END FUNCTION
'//
'// Values of the Credential Flags field.
'//
%EQUATE `CRED_FLAGS_PASSWORD_FOR_CERT = &H0001
%EQUATE `CRED_FLAGS_PROMPT_NOW = &H0002
%EQUATE `CRED_FLAGS_USERNAME_TARGET = &H0004
%EQUATE `CRED_FLAGS_OWF_CRED_BLOB = &H0008
%EQUATE `CRED_FLAGS_REQUIRE_CONFIRMATION = &H0010
'//
'// Valid only for return and only with CredReadDomainCredentials().
'// Indicates credential was returned due to wildcard match
'// of targetname with credential.
'//
%EQUATE `CRED_FLAGS_WILDCARD_MATCH = &H0020
%EQUATE `CRED_FLAGS_VALID_FLAGS = &HF01F ' // Mask of all valid flags
'//
'// Bit mask for only those flags which can be passed to the credman
'// APIs.
'//
%EQUATE `CRED_FLAGS_VALID_INPUT_FLAGS = &HF01F
'//
'// Values of the Credential Type field.
'//
%EQUATE `CRED_TYPE_GENERIC = 1
%EQUATE `CRED_TYPE_DOMAIN_PASSWORD = 2
%EQUATE `CRED_TYPE_DOMAIN_CERTIFICATE = 3
%EQUATE `CRED_TYPE_DOMAIN_VISIBLE_PASSWORD = 4
%EQUATE `CRED_TYPE_GENERIC_CERTIFICATE = 5
%EQUATE `CRED_TYPE_DOMAIN_EXTENDED = 6
%EQUATE `CRED_TYPE_MAXIMUM = 7 ' // Maximum supported cred type
%EQUATE `CRED_TYPE_MAXIMUM_EX = (%CRED_TYPE_MAXIMUM+1000) ' // Allow new applications to run on old OSes
'//
'// Maximum size of the CredBlob field (in bytes)
'//
%EQUATE `CRED_MAX_CREDENTIAL_BLOB_SIZE = 5 * 512
'//
'// Values of the Credential Persist field
'//
%EQUATE `CRED_PERSIST_NONE = 0
%EQUATE `CRED_PERSIST_SESSION = 1
%EQUATE `CRED_PERSIST_LOCAL_MACHINE = 2
%EQUATE `CRED_PERSIST_ENTERPRISE = 3
'//
'// A credential
'//
' // Size = 52 bytes
TYPE CREDENTIALA DWORD
 Flags AS DWORD
 Type AS DWORD
 TargetName AS ASCIIZ PTR
 Comment AS ASCIIZ PTR
 LastWritten AS FILETIME ' FILETIME
 CredentialBlobSize AS DWORD
 CredentialBlob AS BYTE PTR
 Persist AS DWORD
 AttributeCount AS DWORD
 Attributes AS CREDENTIAL_ATTRIBUTEA PTR ' PCREDENTIAL_ATTRIBUTEA
 TargetAlias AS ASCIIZ PTR
 UserName AS ASCIIZ PTR
END TYPE
' // Size = 52 bytes
TYPE CREDENTIALW DWORD
 Flags AS DWORD
 Type AS DWORD
 TargetName AS WSTRINGZ PTR
 Comment AS WSTRINGZ PTR
 LastWritten AS FILETIME ' FILETIME
 CredentialBlobSize AS DWORD
 CredentialBlob AS BYTE PTR
 Persist AS DWORD
 AttributeCount AS DWORD
 Attributes AS CREDENTIAL_ATTRIBUTEW PTR ' PCREDENTIAL_ATTRIBUTEW
 TargetAlias AS WSTRINGZ PTR
 UserName AS WSTRINGZ PTR
END TYPE
#IF %DEF(%UNICODE)
 MACRO CREDENTIAL = CREDENTIALW
#ELSE
 MACRO CREDENTIAL = CREDENTIALA
#ENDIF
'//
'// Value of the Flags field in CREDENTIAL_TARGET_INFORMATION
'//
%EQUATE `CRED_TI_SERVER_FORMAT_UNKNOWN = &H0001 ' // Don't know if server name is DNS or netbios format
%EQUATE `CRED_TI_DOMAIN_FORMAT_UNKNOWN = &H0002 ' // Don't know if domain name is DNS or netbios format
%EQUATE `CRED_TI_ONLY_PASSWORD_REQUIRED = &H0004 ' // Server only requires a password and not a username
%EQUATE `CRED_TI_USERNAME_TARGET = &H0008 ' // TargetName is username
%EQUATE `CRED_TI_CREATE_EXPLICIT_CRED = &H0010 ' // When creating a cred, create one named TargetInfo->TargetName
%EQUATE `CRED_TI_WORKGROUP_MEMBER = &H0020 ' // Indicates the machine is a member of a workgroup
%EQUATE `CRED_TI_VALID_FLAGS = &HF07F
'//
'// A credential target
'//
' // Size = 40 bytes
TYPE CREDENTIAL_TARGET_INFORMATIONA DWORD
 TargetName AS ASCIIZ PTR
 NetbiosServerName AS ASCIIZ PTR
 DnsServerName AS ASCIIZ PTR
 NetbiosDomainName AS ASCIIZ PTR
 DnsDomainName AS ASCIIZ PTR
 DnsTreeName AS ASCIIZ PTR
 PackageName AS ASCIIZ PTR
 Flags AS DWORD ' ULONG
 CredTypeCount AS DWORD
 CredTypes AS DWORD PTR
END TYPE
' // Size = 40 bytes
TYPE CREDENTIAL_TARGET_INFORMATIONW DWORD
 TargetName AS WSTRINGZ PTR
 NetbiosServerName AS WSTRINGZ PTR
 DnsServerName AS WSTRINGZ PTR
 NetbiosDomainName AS WSTRINGZ PTR
 DnsDomainName AS WSTRINGZ PTR
 DnsTreeName AS WSTRINGZ PTR
 PackageName AS WSTRINGZ PTR
 Flags AS DWORD ' ULONG
 CredTypeCount AS DWORD
 CredTypes AS DWORD PTR
END TYPE
#IF %DEF(%UNICODE)
 MACRO CREDENTIAL_TARGET_INFORMATION = CREDENTIAL_TARGET_INFORMATIONW
#ELSE
 MACRO CREDENTIAL_TARGET_INFORMATION = CREDENTIAL_TARGET_INFORMATIONA
#ENDIF
'//
'// Certificate credential information
'//
'// The cbSize should be the size of the structure, sizeof(CERT_CREDENTIAL_INFO),
'// rgbHashofCert is the hash of the cert which is to be used as the credential.
'//
%EQUATE `CERT_HASH_LENGTH = 20 ' // SHA1 hashes are used for cert hashes
' // Size = 24 bytes
TYPE CERT_CREDENTIAL_INFO DWORD
 cbSize AS DWORD ' ULONG
 rgbHashOfCert(%CERT_HASH_LENGTH - 1) AS BYTE ' UCHAR
END TYPE
'//
'// Username Target credential information
'//
'// This credential can be pass to LsaLogonUser to ask it to find a credential with a
'// TargetName of UserName.
'//
' // Size = 4 bytes
TYPE USERNAME_TARGET_CREDENTIAL_INFO DWORD
 UserName AS WSTRINGZ PTR
END TYPE
'//
'// Marshaled credential blob information.
'//
' // Size = 8 bytes
TYPE BINARY_BLOB_CREDENTIAL_INFO DWORD
 cbBlob AS DWORD ' ULONG
 pbBlob AS BYTE PTR
END TYPE
'//
'// Credential type for credential marshaling routines
'//
' enum CRED_MARSHAL_TYPE
%EQUATE `CertCredential = 1
%EQUATE `UsernameTargetCredential = 2
%EQUATE `BinaryBlobCredential = 3
%EQUATE `UsernameForPackedCredentials = 4 ' // internal only, reserved
'//
'// Protection type for credential providers secret protection routines
'//
' enum CRED_PROTECTION_TYPE
%EQUATE `CredUnprotected = 0
%EQUATE `CredUserProtection = 1
%EQUATE `CredTrustedProtection = 2
'//
'// Values for authentication buffers packing
'//
%EQUATE `CRED_PACK_PROTECTED_CREDENTIALS = &H1
%EQUATE `CRED_PACK_WOW_BUFFER = &H2
%EQUATE `CRED_PACK_GENERIC_CREDENTIALS = &H4
'//
'// Credential UI info
'//
%EQUATE `CREDUI_INFO_DEFINED = 1
' // Size = 20 bytes
TYPE CREDUI_INFOA DWORD
 cbSize AS DWORD
 hwndParent AS DWORD
 pszMessageText AS ASCIIZ PTR
 pszCaptionText AS ASCIIZ PTR
 hbmBanner AS DWORD ' HBITMAP
END TYPE
' // Size = 20 bytes
TYPE CREDUI_INFOW DWORD
 cbSize AS DWORD
 hwndParent AS DWORD
 pszMessageText AS WSTRINGZ PTR
 pszCaptionText AS WSTRINGZ PTR
 hbmBanner AS DWORD ' HBITMAP
END TYPE
#IF %DEF(%UNICODE)
 MACRO CREDUI_INFO = CREDUI_INFOW
#ELSE
 MACRO CREDUI_INFO = CREDUI_INFOA
#ENDIF
'//-----------------------------------------------------------------------------
'// Values
'//-----------------------------------------------------------------------------
'// String length limits:
%EQUATE `CREDUI_MAX_MESSAGE_LENGTH = 32767
%EQUATE `CREDUI_MAX_CAPTION_LENGTH = 128
%EQUATE `CREDUI_MAX_GENERIC_TARGET_LENGTH = %CRED_MAX_GENERIC_TARGET_NAME_LENGTH
%EQUATE `CREDUI_MAX_DOMAIN_TARGET_LENGTH = %CRED_MAX_DOMAIN_TARGET_NAME_LENGTH
'//
'// Username can be in <domain>\<user> or <user>@<domain>
'// Length in characters, not including NULL termination.
'//
%EQUATE `CREDUI_MAX_USERNAME_LENGTH = %CRED_MAX_USERNAME_LENGTH
%EQUATE `CREDUI_MAX_PASSWORD_LENGTH = 512 \ 2
'//
'// Packed credential returned by SspiEncodeAuthIdentityAsStrings().
'// Length in characters, not including NULL termination.
'//
%EQUATE `CREDUI_MAX_PACKED_CREDENTIALS_LENGTH = (65535 \ 2) - 2 ' ((MAXUSHORT / 2) - 2)
'// maximum length in bytes for binary credential blobs
%EQUATE `CREDUI_MAX_CREDENTIALS_BLOB_SIZE = 65535 ' (MAXUSHORT)
'//
'// Flags for CredUIPromptForCredentials and/or CredUICmdLinePromptForCredentials
'//
%EQUATE `CREDUI_FLAGS_INCORRECT_PASSWORD = &H00001 ' // indicates the username is valid, but password is not
%EQUATE `CREDUI_FLAGS_DO_NOT_PERSIST = &H00002 ' // Do not show "Save" checkbox, and do not persist credentials
%EQUATE `CREDUI_FLAGS_REQUEST_ADMINISTRATOR = &H00004 ' // Populate list box with admin accounts
%EQUATE `CREDUI_FLAGS_EXCLUDE_CERTIFICATES = &H00008 ' // do not include certificates in the drop list
%EQUATE `CREDUI_FLAGS_REQUIRE_CERTIFICATE = &H00010
%EQUATE `CREDUI_FLAGS_SHOW_SAVE_CHECK_BOX = &H00040
%EQUATE `CREDUI_FLAGS_ALWAYS_SHOW_UI = &H00080
%EQUATE `CREDUI_FLAGS_REQUIRE_SMARTCARD = &H00100
%EQUATE `CREDUI_FLAGS_PASSWORD_ONLY_OK = &H00200
%EQUATE `CREDUI_FLAGS_VALIDATE_USERNAME = &H00400
%EQUATE `CREDUI_FLAGS_COMPLETE_USERNAME = &H00800 ' //
%EQUATE `CREDUI_FLAGS_PERSIST = &H01000 ' // Do not show "Save" checkbox, but persist credentials anyway
%EQUATE `CREDUI_FLAGS_SERVER_CREDENTIAL = &H04000
%EQUATE `CREDUI_FLAGS_EXPECT_CONFIRMATION = &H20000 ' // do not persist unless caller later confirms credential via CredUIConfirmCredential() api
%EQUATE `CREDUI_FLAGS_GENERIC_CREDENTIALS = &H40000 ' // Credential is a generic credential
%EQUATE `CREDUI_FLAGS_USERNAME_TARGET_CREDENTIALS = &H80000 ' // Credential has a username as the target
%EQUATE `CREDUI_FLAGS_KEEP_USERNAME = &H100000 ' // don't allow the user to change the supplied username
'//
'// Mask of flags valid for CredUIPromptForCredentials
'//
%EQUATE `CREDUI_FLAGS_PROMPT_VALID = %CREDUI_FLAGS_INCORRECT_PASSWORD OR %CREDUI_FLAGS_DO_NOT_PERSIST OR %CREDUI_FLAGS_REQUEST_ADMINISTRATOR OR %CREDUI_FLAGS_EXCLUDE_CERTIFICATES OR %CREDUI_FLAGS_REQUIRE_CERTIFICATE OR %CREDUI_FLAGS_SHOW_SAVE_CHECK_BOX OR %CREDUI_FLAGS_ALWAYS_SHOW_UI OR %CREDUI_FLAGS_REQUIRE_SMARTCARD OR %CREDUI_FLAGS_PASSWORD_ONLY_OK OR %CREDUI_FLAGS_VALIDATE_USERNAME OR %CREDUI_FLAGS_COMPLETE_USERNAME OR %CREDUI_FLAGS_PERSIST OR %CREDUI_FLAGS_SERVER_CREDENTIAL OR %CREDUI_FLAGS_EXPECT_CONFIRMATION OR %CREDUI_FLAGS_GENERIC_CREDENTIALS OR %CREDUI_FLAGS_USERNAME_TARGET_CREDENTIALS OR %CREDUI_FLAGS_KEEP_USERNAME
'//
'// Flags for CredUIPromptForWindowsCredentials and CPUS_CREDUI Usage Scenarios
'//
%EQUATE `CREDUIWIN_GENERIC = &H00000001 ' // Plain text username/password is being requested
%EQUATE `CREDUIWIN_CHECKBOX = &H00000002 ' // Show the Save Credential checkbox
%EQUATE `CREDUIWIN_AUTHPACKAGE_ONLY = &H00000010 ' // Only Cred Providers that support the input auth package should enumerate
%EQUATE `CREDUIWIN_IN_CRED_ONLY = &H00000020 ' // Only the incoming cred for the specific auth package should be enumerated
%EQUATE `CREDUIWIN_ENUMERATE_ADMINS = &H00000100 ' // Cred Providers should enumerate administrators only
%EQUATE `CREDUIWIN_ENUMERATE_CURRENT_USER = &H00000200 ' // Only the incoming cred for the specific auth package should be enumerated
%EQUATE `CREDUIWIN_SECURE_PROMPT = &H00001000 ' // The Credui prompt should be displayed on the secure desktop
%EQUATE `CREDUIWIN_PACK_32_WOW = &H10000000 ' // Tell the credential provider it should be packing its Auth Blob 32 bit even though it is running 64 native
%EQUATE `CREDUIWIN_VALID_FLAGS = %CREDUIWIN_GENERIC OR %CREDUIWIN_CHECKBOX OR %CREDUIWIN_AUTHPACKAGE_ONLY OR %CREDUIWIN_IN_CRED_ONLY OR %CREDUIWIN_ENUMERATE_ADMINS OR %CREDUIWIN_ENUMERATE_CURRENT_USER OR %CREDUIWIN_SECURE_PROMPT OR %CREDUIWIN_PACK_32_WOW
'//-----------------------------------------------------------------------------
'// Functions
'//-----------------------------------------------------------------------------
'//
'// Values of flags to CredWrite and CredWriteDomainCredentials
'//
%EQUATE `CRED_PRESERVE_CREDENTIAL_BLOB = &H1
DECLARE FUNCTION CredWriteW LIB "advapi32.dll" ALIAS "CredWriteW" ( BYREF Credential AS CREDENTIALW , BYVAL Flags AS QUAD ) AS LONG
DECLARE FUNCTION CredWriteA LIB "advapi32.dll" ALIAS "CredWriteA" ( BYREF Credential AS CREDENTIALA
 , BYVAL Flags AS DWORD
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO CredWrite = CredWriteW
#ELSE
 MACRO CredWrite = CredWriteA
#ENDIF
DECLARE FUNCTION CredReadW LIB "advapi32.dll" ALIAS "CredReadW" ( BYREF TargetName AS WSTRINGZ , BYVAL Type AS QUAD , BYVAL Flags AS QUAD , BYREF Credential AS ANY ) AS LONG
DECLARE FUNCTION CredReadA LIB "advapi32.dll" ALIAS "CredReadA" ( BYREF TargetName AS ASCIIZ
 , BYVAL Type AS DWORD
 , BYVAL Flags AS DWORD
 , BYREF Credential AS ANY
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO CredRead = CredReadW
#ELSE
 MACRO CredRead = CredReadA
#ENDIF
'//
'// Values of flags to CredEnumerate
'//
%EQUATE `CRED_ENUMERATE_ALL_CREDENTIALS = &H1
DECLARE FUNCTION CredEnumerateW LIB "advapi32.dll" ALIAS "CredEnumerateW" ( BYREF Filter AS WSTRINGZ , BYVAL Flags AS QUAD , BYREF Count AS QUAD , BYREF Credential AS ANY ) AS LONG
DECLARE FUNCTION CredEnumerateA LIB "advapi32.dll" ALIAS "CredEnumerateA" ( BYREF Filter AS ASCIIZ
 , BYVAL Flags AS DWORD
 , BYREF Count AS DWORD
 , BYREF Credential AS ANY
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO CredEnumerate = CredEnumerateW
#ELSE
 MACRO CredEnumerate = CredEnumerateA
#ENDIF
DECLARE FUNCTION CredWriteDomainCredentialsW LIB "advapi32.dll" ALIAS "CredWriteDomainCredentialsW" ( BYREF TargetInfo AS CREDENTIAL_TARGET_INFORMATIONW , BYREF Credential AS CREDENTIALW , BYVAL Flags AS QUAD ) AS LONG
DECLARE FUNCTION CredWriteDomainCredentialsA LIB "advapi32.dll" ALIAS "CredWriteDomainCredentialsA" ( BYREF TargetInfo AS CREDENTIAL_TARGET_INFORMATIONA
 , BYREF Credential AS CREDENTIALA
 , BYVAL Flags AS DWORD
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO CredWriteDomainCredentials = CredWriteDomainCredentialsW
#ELSE
 MACRO CredWriteDomainCredentials = CredWriteDomainCredentialsA
#ENDIF
'//
'// Values of flags to CredReadDomainCredentials
'//
%EQUATE `CRED_CACHE_TARGET_INFORMATION = &H1
DECLARE FUNCTION CredReadDomainCredentialsW LIB "advapi32.dll" ALIAS "CredReadDomainCredentialsW" ( BYREF TargetInfo AS CREDENTIAL_TARGET_INFORMATIONW , BYVAL Flags AS QUAD , BYREF Count AS QUAD , BYREF Credential AS ANY ) AS LONG
DECLARE FUNCTION CredReadDomainCredentialsA LIB "advapi32.dll" ALIAS "CredReadDomainCredentialsA" ( BYREF TargetInfo AS CREDENTIAL_TARGET_INFORMATIONA
 , BYVAL Flags AS DWORD
 , BYREF Count AS DWORD
 , BYREF Credential AS ANY
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO CredReadDomainCredentials = CredReadDomainCredentialsW
#ELSE
 MACRO CredReadDomainCredentials = CredReadDomainCredentialsA
#ENDIF
DECLARE FUNCTION CredDeleteW LIB "advapi32.dll" ALIAS "CredDeleteW" ( BYREF TargetName AS WSTRINGZ , BYVAL Type AS QUAD , BYVAL Flags AS QUAD ) AS LONG
DECLARE FUNCTION CredDeleteA LIB "advapi32.dll" ALIAS "CredDeleteA" ( BYREF TargetName AS ASCIIZ
 , BYVAL Type AS DWORD
 , BYVAL Flags AS DWORD
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO CredDelete = CredDeleteW
#ELSE
 MACRO CredDelete = CredDeleteA
#ENDIF
DECLARE FUNCTION CredRenameW LIB "advapi32.dll" ALIAS "CredRenameW" ( BYREF TargetName AS WSTRINGZ , BYREF NewTargetName AS WSTRINGZ , BYVAL Type AS QUAD , BYVAL Flags AS QUAD ) AS LONG
DECLARE FUNCTION CredRenameA LIB "advapi32.dll" ALIAS "CredRenameA" ( BYREF TargetName AS ASCIIZ
 , BYREF NewTargetName AS ASCIIZ
 , BYVAL Type AS DWORD
 , BYVAL Flags AS DWORD
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO CredRename = CredRenameW
#ELSE
 MACRO CredRename = CredRenameA
#ENDIF
'//
'// Values of flags to CredGetTargetInfo
'//
%EQUATE `CRED_ALLOW_NAME_RESOLUTION = &H1
DECLARE FUNCTION CredGetTargetInfoW LIB "advapi32.dll" ALIAS "CredGetTargetInfoW" ( BYREF TargetName AS WSTRINGZ , BYVAL Flags AS QUAD , BYREF TargetInfo AS ANY ) AS LONG
DECLARE FUNCTION CredGetTargetInfoA LIB "advapi32.dll" ALIAS "CredGetTargetInfoA" ( BYREF TargetName AS ASCIIZ
 , BYVAL Flags AS DWORD
 , BYREF TargetInfo AS ANY
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO CredGetTargetInfo = CredGetTargetInfoW
#ELSE
 MACRO CredGetTargetInfo = CredGetTargetInfoA
#ENDIF
DECLARE FUNCTION CredMarshalCredentialW LIB "advapi32.dll" ALIAS "CredMarshalCredentialW" ( BYVAL CredType AS LONG , BYREF Credential AS ANY , BYREF MarshaledCredential AS ANY ) AS LONG
DECLARE FUNCTION CredMarshalCredentialA LIB "advapi32.dll" ALIAS "CredMarshalCredentialA" ( BYVAL CredType AS LONG
 , BYREF Credential AS ANY
 , BYREF MarshaledCredential AS ANY
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO CredMarshalCredential = CredMarshalCredentialW
#ELSE
 MACRO CredMarshalCredential = CredMarshalCredentialA
#ENDIF
DECLARE FUNCTION CredUnmarshalCredentialW LIB "advapi32.dll" ALIAS "CredUnmarshalCredentialW" ( BYREF MarshaledCredential AS WSTRINGZ , BYREF CredType AS LONG , BYREF Credential AS ANY ) AS LONG
DECLARE FUNCTION CredUnmarshalCredentialA LIB "advapi32.dll" ALIAS "CredUnmarshalCredentialA" ( BYREF MarshaledCredential AS ASCIIZ
 , BYREF CredType AS LONG
 , BYREF Credential AS ANY
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO CredUnmarshalCredential = CredUnmarshalCredentialW
#ELSE
 MACRO CredUnmarshalCredential = CredUnmarshalCredentialA
#ENDIF
DECLARE FUNCTION CredIsMarshaledCredentialW LIB "advapi32.dll" ALIAS "CredIsMarshaledCredentialW" ( BYREF MarshaledCredential AS WSTRINGZ ) AS LONG
DECLARE FUNCTION CredIsMarshaledCredentialA LIB "advapi32.dll" ALIAS "CredIsMarshaledCredentialA" ( BYREF MarshaledCredential AS ASCIIZ
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO CredIsMarshaledCredential = CredIsMarshaledCredentialW
#ELSE
 MACRO CredIsMarshaledCredential = CredIsMarshaledCredentialA
#ENDIF
DECLARE FUNCTION CredUnPackAuthenticationBufferW LIB "credui.dll" ALIAS "CredUnPackAuthenticationBufferW" ( BYVAL dwFlags AS QUAD , BYREF pAuthBuffer AS ANY , BYVAL cbAuthBuffer AS QUAD , BYREF pszUserName AS WSTRINGZ , BYREF pcchMaxUserName AS QUAD , BYREF pszDomainName AS WSTRINGZ , BYREF pcchMaxDomainName AS QUAD , BYREF pszPassword AS WSTRINGZ , BYREF pcchMaxPassword AS QUAD ) AS LONG
DECLARE FUNCTION CredUnPackAuthenticationBufferA LIB "credui.dll" ALIAS "CredUnPackAuthenticationBufferA" ( BYVAL dwFlags AS QUAD
 , BYREF pAuthBuffer AS ANY
 , BYVAL cbAuthBuffer AS DWORD
 , BYREF pszUserName AS ASCIIZ
 , BYREF pcchMaxUserName AS DWORD
 , BYREF pszDomainName AS ASCIIZ
 , BYREF pcchMaxDomainName AS DWORD
 , BYREF pszPassword AS ASCIIZ
 , BYREF pcchMaxPassword AS DWORD
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO CredUnPackAuthenticationBuffer = CredUnPackAuthenticationBufferW
#ELSE
 MACRO CredUnPackAuthenticationBuffer = CredUnPackAuthenticationBufferA
#ENDIF
DECLARE FUNCTION CredPackAuthenticationBufferW LIB "credui.dll" ALIAS "CredPackAuthenticationBufferW" ( BYVAL dwFlags AS QUAD , BYREF pszUserName AS WSTRINGZ , BYREF pszPassword AS WSTRINGZ , BYVAL pPackedCredentials AS QUAD , BYREF pcbPackedCredentials AS QUAD ) AS LONG
DECLARE FUNCTION CredPackAuthenticationBufferA LIB "credui.dll" ALIAS "CredPackAuthenticationBufferA" ( BYVAL dwFlags AS QUAD
 , BYREF pszUserName AS ASCIIZ
 , BYREF pszPassword AS ASCIIZ
 , BYVAL pPackedCredentials AS DWORD
 , BYREF pcbPackedCredentials AS DWORD
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO CredPackAuthenticationBuffer = CredPackAuthenticationBufferW
#ELSE
 MACRO CredPackAuthenticationBuffer = CredPackAuthenticationBufferA
#ENDIF
DECLARE FUNCTION CredProtectW LIB "advapi32.dll" ALIAS "CredProtectW" ( BYVAL fAsSelf AS LONG , BYREF pszCredentials AS WSTRINGZ , BYVAL cchCredentials AS QUAD , BYREF pszProtectedCredentials AS WSTRINGZ , BYREF pcchMaxChars AS QUAD , BYREF ProtectionType AS QUAD ) AS LONG
DECLARE FUNCTION CredProtectA LIB "advapi32.dll" ALIAS "CredProtectA" ( BYVAL fAsSelf AS LONG
 , BYREF pszCredentials AS ASCIIZ
 , BYVAL cchCredentials AS DWORD
 , BYREF pszProtectedCredentials AS ASCIIZ
 , BYREF pcchMaxChars AS DWORD
 , BYREF ProtectionType AS DWORD
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO CredProtect = CredProtectW
#ELSE
 MACRO CredProtect = CredProtectA
#ENDIF
DECLARE FUNCTION CredUnprotectW LIB "advapi32.dll" ALIAS "CredUnprotectW" ( BYVAL fAsSelf AS LONG , BYREF pszProtectedCredentials AS WSTRINGZ , BYVAL cchProtectedCredentials AS QUAD , BYREF pszCredentials AS WSTRINGZ , BYREF pcchMaxChars AS QUAD ) AS LONG
DECLARE FUNCTION CredUnprotectA LIB "advapi32.dll" ALIAS "CredUnprotectA" ( BYVAL fAsSelf AS LONG
 , BYREF pszProtectedCredentials AS ASCIIZ
 , BYVAL cchProtectedCredentials AS DWORD
 , BYREF pszCredentials AS ASCIIZ
 , BYREF pcchMaxChars AS DWORD
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO CredUnprotect = CredUnprotectW
#ELSE
 MACRO CredUnprotect = CredUnprotectA
#ENDIF
DECLARE FUNCTION CredIsProtectedW LIB "advapi32.dll" ALIAS "CredIsProtectedW" ( BYREF pszProtectedCredentials AS WSTRINGZ , BYREF pProtectionType AS QUAD ) AS LONG
DECLARE FUNCTION CredIsProtectedA LIB "advapi32.dll" ALIAS "CredIsProtectedA" ( BYREF pszProtectedCredentials AS ASCIIZ
 , BYREF pProtectionType AS DWORD
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO CredIsProtected = CredIsProtectedW
#ELSE
 MACRO CredIsProtected = CredIsProtectedA
#ENDIF
DECLARE FUNCTION CredFindBestCredentialW LIB "advapi32.dll" ALIAS "CredFindBestCredentialW" ( BYREF TargetName AS WSTRINGZ , BYVAL Type AS QUAD , BYVAL Flags AS QUAD , BYREF Credential AS ANY ) AS LONG
DECLARE FUNCTION CredFindBestCredentialA LIB "advapi32.dll" ALIAS "CredFindBestCredentialA" ( BYREF TargetName AS ASCIIZ
 , BYVAL Type AS DWORD
 , BYVAL Flags AS DWORD
 , BYREF Credential AS ANY
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO CredFindBestCredential = CredFindBestCredentialW
#ELSE
 MACRO CredFindBestCredential = CredFindBestCredentialA
#ENDIF
DECLARE FUNCTION CredGetSessionTypes LIB "advapi32.dll" ALIAS "CredGetSessionTypes" ( BYVAL MaximumPersistCount AS QUAD , BYREF MaximumPersist AS QUAD ) AS LONG
#IF %DEF(%USEPBDECL)
DECLARE SUB CredFree LIB "AdvApi32.dll" ALIAS "CredFree" ( Buffer AS ANY)
#ELSE
DECLARE SUB CredFree LIB "advapi32.dll" ALIAS "CredFree" ( BYVAL Buffer AS QUAD )
#ENDIF
DECLARE FUNCTION CredUIPromptForCredentialsW LIB "credui.dll" ALIAS "CredUIPromptForCredentialsW" ( BYREF pUiInfo AS CREDUI_INFOW , BYREF pszTargetName AS WSTRINGZ , BYREF pContext AS SecHandle , BYVAL dwAuthError AS QUAD , BYREF pszUserName AS WSTRINGZ , BYVAL ulUserNameBufferSize AS QUAD , BYREF pszPassword AS WSTRINGZ , BYVAL ulPasswordBufferSize AS QUAD , BYREF save AS LONG , BYVAL dwFlags AS QUAD ) AS QUAD
DECLARE FUNCTION CredUIPromptForCredentialsA LIB "credui.dll" ALIAS "CredUIPromptForCredentialsA" ( BYREF pUiInfo AS CREDUI_INFOA
 , BYREF pszTargetName AS ASCIIZ
 , BYREF pContext AS SecHandle
 , BYVAL dwAuthError AS DWORD
 , BYREF pszUserName AS ASCIIZ
 , BYVAL ulUserNameBufferSize AS DWORD
 , BYREF pszPassword AS ASCIIZ
 , BYVAL ulPasswordBufferSize AS DWORD
 , BYREF save AS LONG
 , BYVAL dwFlags AS DWORD
 ) AS DWORD
#IF %DEF(%UNICODE)
 MACRO CredUIPromptForCredentials = CredUIPromptForCredentialsW
#ELSE
 MACRO CredUIPromptForCredentials = CredUIPromptForCredentialsA
#ENDIF
DECLARE FUNCTION CredUIPromptForWindowsCredentialsW LIB "credui.dll" ALIAS "CredUIPromptForWindowsCredentialsW" ( BYREF pUiInfo AS CREDUI_INFOW , BYVAL dwAuthError AS QUAD , BYREF pulAuthPackage AS QUAD , BYREF pvInAuthBuffer AS ANY , BYVAL ulInAuthBufferSize AS QUAD , BYREF ppvOutAuthBuffer AS ANY , BYREF pulOutAuthBufferSize AS QUAD , BYREF pfSave AS LONG , BYVAL dwFlags AS QUAD ) AS QUAD
DECLARE FUNCTION CredUIPromptForWindowsCredentialsA LIB "credui.dll" ALIAS "CredUIPromptForWindowsCredentialsA" ( BYREF pUiInfo AS CREDUI_INFOA
 , BYVAL dwAuthError AS DWORD
 , BYREF pulAuthPackage AS DWORD
 , BYREF pvInAuthBuffer AS ANY
 , BYVAL ulInAuthBufferSize AS DWORD
 , BYREF ppvOutAuthBuffer AS ANY
 , BYREF pulOutAuthBufferSize AS DWORD
 , BYREF pfSave AS LONG
 , BYVAL dwFlags AS DWORD
 ) AS DWORD
#IF %DEF(%UNICODE)
 MACRO CredUIPromptForWindowsCredentials = CredUIPromptForWindowsCredentialsW
#ELSE
 MACRO CredUIPromptForWindowsCredentials = CredUIPromptForWindowsCredentialsA
#ENDIF
DECLARE FUNCTION CredUIParseUserNameW LIB "credui.dll" ALIAS "CredUIParseUserNameW" ( BYREF UserName AS WSTRINGZ , BYREF user AS WSTRINGZ , BYVAL userBufferSize AS QUAD , BYREF domain AS WSTRINGZ , BYVAL domainBufferSize AS QUAD ) AS QUAD
DECLARE FUNCTION CredUIParseUserNameA LIB "credui.dll" ALIAS "CredUIParseUserNameA" ( BYREF UserName AS ASCIIZ
 , BYREF user AS ASCIIZ
 , BYVAL userBufferSize AS DWORD
 , BYREF domain AS ASCIIZ
 , BYVAL domainBufferSize AS DWORD
 ) AS DWORD
#IF %DEF(%UNICODE)
 MACRO CredUIParseUserName = CredUIParseUserNameW
#ELSE
 MACRO CredUIParseUserName = CredUIParseUserNameA
#ENDIF
DECLARE FUNCTION CredUICmdLinePromptForCredentialsW LIB "credui.dll" ALIAS "CredUICmdLinePromptForCredentialsW" ( BYREF pszTargetName AS WSTRINGZ , BYREF pContext AS SecHandle , BYVAL dwAuthError AS QUAD , BYREF UserName AS WSTRINGZ , BYVAL ulUserBufferSize AS QUAD , BYREF pszPassword AS WSTRINGZ , BYVAL ulPasswordBufferSize AS QUAD , BYREF pfSave AS LONG , BYVAL dwFlags AS QUAD ) AS QUAD
DECLARE FUNCTION CredUICmdLinePromptForCredentialsA LIB "credui.dll" ALIAS "CredUICmdLinePromptForCredentialsA" ( BYREF pszTargetName AS ASCIIZ
 , BYREF pContext AS SecHandle
 , BYVAL dwAuthError AS DWORD
 , BYREF UserName AS ASCIIZ
 , BYVAL ulUserBufferSize AS DWORD
 , BYREF pszPassword AS ASCIIZ
 , BYVAL ulPasswordBufferSize AS DWORD
 , BYREF pfSave AS LONG
 , BYVAL dwFlags AS DWORD
 ) AS DWORD
#IF %DEF(%UNICODE)
 MACRO CredUICmdLinePromptForCredentials = CredUICmdLinePromptForCredentialsW
#ELSE
 MACRO CredUICmdLinePromptForCredentials = CredUICmdLinePromptForCredentialsA
#ENDIF
'//
'// Call this API with bConfirm set to TRUE to confirm that the credential (previously created
'// via CredUIGetCredentials or CredUIPromptForCredentials worked, or with bConfirm set to FALSE
'// to indicate it didn't
DECLARE FUNCTION CredUIConfirmCredentialsW LIB "credui.dll" ALIAS "CredUIConfirmCredentialsW" ( BYREF pszTargetName AS WSTRINGZ , BYVAL bConfirm AS QUAD ) AS QUAD
DECLARE FUNCTION CredUIConfirmCredentialsA LIB "credui.dll" ALIAS "CredUIConfirmCredentialsA" ( BYREF pszTargetName AS ASCIIZ
 , BYVAL bConfirm AS DWORD
 ) AS DWORD
#IF %DEF(%UNICODE)
 MACRO CredUIConfirmCredentials = CredUIConfirmCredentialsW
#ELSE
 MACRO CredUIConfirmCredentials = CredUIConfirmCredentialsA
#ENDIF
DECLARE FUNCTION CredUIStoreSSOCredW LIB "credui.dll" ALIAS "CredUIStoreSSOCredW" ( BYREF pszRealm AS WSTRINGZ , BYREF pszUsername AS WSTRINGZ , BYREF pszPassword AS WSTRINGZ , BYVAL bPersist AS LONG ) AS QUAD
MACRO CredUIStoreSSOCred = CredUIStoreSSOCredW
DECLARE FUNCTION CredUIReadSSOCredW LIB "credui.dll" ALIAS "CredUIReadSSOCredW" ( BYREF pszRealm AS WSTRINGZ , BYREF ppszUsername AS ANY ) AS QUAD
MACRO CredUIReadSSOCred = CredUIReadSSOCredW
#ENDIF
