FreeRDP
sspi/NTLM/ntlm.c File Reference
#include <winpr/config.h>
#include <winpr/crt.h>
#include <winpr/assert.h>
#include <winpr/sspi.h>
#include <winpr/print.h>
#include <winpr/string.h>
#include <winpr/tchar.h>
#include <winpr/sysinfo.h>
#include <winpr/registry.h>
#include <winpr/endian.h>
#include <winpr/build-config.h>
#include "ntlm.h"
#include "ntlm_export.h"
#include "../sspi.h"
#include "ntlm_message.h"
#include "../../log.h"

Macros

#define TAG   WINPR_TAG("sspi.NTLM")
 
#define WINPR_KEY   "Software\\" WINPR_VENDOR_STRING "\\" WINPR_PRODUCT_STRING "\\WinPR\\NTLM"
 
#define check_context(ctx)   check_context_((ctx), __FILE__, __func__, __LINE__)
 

Functions

static BOOL check_context_ (NTLM_CONTEXT *context, const char *file, const char *fkt, size_t line)
 
static int ntlm_SetContextWorkstation (NTLM_CONTEXT *context, char *Workstation)
 
static int ntlm_SetContextServicePrincipalNameW (NTLM_CONTEXT *context, LPWSTR ServicePrincipalName)
 
static int ntlm_SetContextTargetName (NTLM_CONTEXT *context, char *TargetName)
 
static NTLM_CONTEXTntlm_ContextNew (void)
 
static void ntlm_ContextFree (NTLM_CONTEXT *context)
 
static SECURITY_STATUS SEC_ENTRY ntlm_AcquireCredentialsHandleW (SEC_WCHAR *pszPrincipal, SEC_WCHAR *pszPackage, ULONG fCredentialUse, void *pvLogonID, void *pAuthData, SEC_GET_KEY_FN pGetKeyFn, void *pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
 
static SECURITY_STATUS SEC_ENTRY ntlm_AcquireCredentialsHandleA (SEC_CHAR *pszPrincipal, SEC_CHAR *pszPackage, ULONG fCredentialUse, void *pvLogonID, void *pAuthData, SEC_GET_KEY_FN pGetKeyFn, void *pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
 
static SECURITY_STATUS SEC_ENTRY ntlm_FreeCredentialsHandle (PCredHandle phCredential)
 
static SECURITY_STATUS SEC_ENTRY ntlm_QueryCredentialsAttributesW (PCredHandle phCredential, ULONG ulAttribute, void *pBuffer)
 
static SECURITY_STATUS SEC_ENTRY ntlm_QueryCredentialsAttributesA (PCredHandle phCredential, ULONG ulAttribute, void *pBuffer)
 
static SECURITY_STATUS SEC_ENTRY ntlm_AcceptSecurityContext (PCredHandle phCredential, PCtxtHandle phContext, PSecBufferDesc pInput, ULONG fContextReq, ULONG TargetDataRep, PCtxtHandle phNewContext, PSecBufferDesc pOutput, PULONG pfContextAttr, PTimeStamp ptsTimeStamp)
 
static SECURITY_STATUS SEC_ENTRY ntlm_ImpersonateSecurityContext (PCtxtHandle phContext)
 
static SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextW (PCredHandle phCredential, PCtxtHandle phContext, SEC_WCHAR *pszTargetName, ULONG fContextReq, ULONG Reserved1, ULONG TargetDataRep, PSecBufferDesc pInput, ULONG Reserved2, PCtxtHandle phNewContext, PSecBufferDesc pOutput, PULONG pfContextAttr, PTimeStamp ptsExpiry)
 
static SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextA (PCredHandle phCredential, PCtxtHandle phContext, SEC_CHAR *pszTargetName, ULONG fContextReq, ULONG Reserved1, ULONG TargetDataRep, PSecBufferDesc pInput, ULONG Reserved2, PCtxtHandle phNewContext, PSecBufferDesc pOutput, PULONG pfContextAttr, PTimeStamp ptsExpiry)
 
static SECURITY_STATUS SEC_ENTRY ntlm_DeleteSecurityContext (PCtxtHandle phContext)
 
SECURITY_STATUS ntlm_computeProofValue (NTLM_CONTEXT *ntlm, SecBuffer *ntproof)
 
SECURITY_STATUS ntlm_computeMicValue (NTLM_CONTEXT *ntlm, SecBuffer *micvalue)
 
static SECURITY_STATUS SEC_ENTRY ntlm_QueryContextAttributesW (PCtxtHandle phContext, ULONG ulAttribute, void *pBuffer)
 
static SECURITY_STATUS SEC_ENTRY ntlm_QueryContextAttributesA (PCtxtHandle phContext, ULONG ulAttribute, void *pBuffer)
 
static SECURITY_STATUS SEC_ENTRY ntlm_SetContextAttributesW (PCtxtHandle phContext, ULONG ulAttribute, void *pBuffer, ULONG cbBuffer)
 
static SECURITY_STATUS SEC_ENTRY ntlm_SetContextAttributesA (PCtxtHandle phContext, ULONG ulAttribute, void *pBuffer, ULONG cbBuffer)
 
static SECURITY_STATUS SEC_ENTRY ntlm_SetCredentialsAttributesW (PCredHandle phCredential, ULONG ulAttribute, void *pBuffer, ULONG cbBuffer)
 
static SECURITY_STATUS SEC_ENTRY ntlm_SetCredentialsAttributesA (PCredHandle phCredential, ULONG ulAttribute, void *pBuffer, ULONG cbBuffer)
 
static SECURITY_STATUS SEC_ENTRY ntlm_RevertSecurityContext (PCtxtHandle phContext)
 
static SECURITY_STATUS SEC_ENTRY ntlm_EncryptMessage (PCtxtHandle phContext, ULONG fQOP, PSecBufferDesc pMessage, ULONG MessageSeqNo)
 
static SECURITY_STATUS SEC_ENTRY ntlm_DecryptMessage (PCtxtHandle phContext, PSecBufferDesc pMessage, ULONG MessageSeqNo, PULONG pfQOP)
 
static SECURITY_STATUS SEC_ENTRY ntlm_MakeSignature (PCtxtHandle phContext, ULONG fQOP, PSecBufferDesc pMessage, ULONG MessageSeqNo)
 
static SECURITY_STATUS SEC_ENTRY ntlm_VerifySignature (PCtxtHandle phContext, PSecBufferDesc pMessage, ULONG MessageSeqNo, PULONG pfQOP)
 
char * ntlm_negotiate_flags_string (char *buffer, size_t size, UINT32 flags)
 
const char * ntlm_message_type_string (UINT32 messageType)
 
const char * ntlm_state_string (NTLM_STATE state)
 
void ntlm_change_state (NTLM_CONTEXT *ntlm, NTLM_STATE state)
 
NTLM_STATE ntlm_get_state (NTLM_CONTEXT *ntlm)
 
BOOL ntlm_reset_cipher_state (PSecHandle phContext)
 
BOOL NTLM_init (void)
 

Variables

static char * NTLM_PACKAGE_NAME = "NTLM"
 
const SecurityFunctionTableA NTLM_SecurityFunctionTableA
 
const SecurityFunctionTableW NTLM_SecurityFunctionTableW
 
const SecPkgInfoA NTLM_SecPkgInfoA
 
static WCHAR NTLM_SecPkgInfoW_NameBuffer [32] = { 0 }
 
static WCHAR NTLM_SecPkgInfoW_CommentBuffer [32] = { 0 }
 
const SecPkgInfoW NTLM_SecPkgInfoW
 

Macro Definition Documentation

◆ check_context

#define check_context (   ctx)    check_context_((ctx), __FILE__, __func__, __LINE__)

◆ TAG

#define TAG   WINPR_TAG("sspi.NTLM")

WinPR: Windows Portable Runtime NTLM Security Package

Copyright 2011-2014 Marc-Andre Moreau marca.nosp@m.ndre.nosp@m..more.nosp@m.au@g.nosp@m.mail..nosp@m.com

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

◆ WINPR_KEY

#define WINPR_KEY   "Software\\" WINPR_VENDOR_STRING "\\" WINPR_PRODUCT_STRING "\\WinPR\\NTLM"

Function Documentation

◆ check_context_()

static BOOL check_context_ ( NTLM_CONTEXT context,
const char *  file,
const char *  fkt,
size_t  line 
)
static
Here is the call graph for this function:

◆ ntlm_AcceptSecurityContext()

static SECURITY_STATUS SEC_ENTRY ntlm_AcceptSecurityContext ( PCredHandle  phCredential,
PCtxtHandle  phContext,
PSecBufferDesc  pInput,
ULONG  fContextReq,
ULONG  TargetDataRep,
PCtxtHandle  phNewContext,
PSecBufferDesc  pOutput,
PULONG  pfContextAttr,
PTimeStamp  ptsTimeStamp 
)
static
See also
http://msdn.microsoft.com/en-us/library/windows/desktop/aa374707
Here is the call graph for this function:

◆ ntlm_AcquireCredentialsHandleA()

static SECURITY_STATUS SEC_ENTRY ntlm_AcquireCredentialsHandleA ( SEC_CHAR pszPrincipal,
SEC_CHAR pszPackage,
ULONG  fCredentialUse,
void *  pvLogonID,
void *  pAuthData,
SEC_GET_KEY_FN  pGetKeyFn,
void *  pvGetKeyArgument,
PCredHandle  phCredential,
PTimeStamp  ptsExpiry 
)
static
Here is the call graph for this function:

◆ ntlm_AcquireCredentialsHandleW()

static SECURITY_STATUS SEC_ENTRY ntlm_AcquireCredentialsHandleW ( SEC_WCHAR pszPrincipal,
SEC_WCHAR pszPackage,
ULONG  fCredentialUse,
void *  pvLogonID,
void *  pAuthData,
SEC_GET_KEY_FN  pGetKeyFn,
void *  pvGetKeyArgument,
PCredHandle  phCredential,
PTimeStamp  ptsExpiry 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ntlm_change_state()

void ntlm_change_state ( NTLM_CONTEXT ntlm,
NTLM_STATE  state 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ntlm_computeMicValue()

SECURITY_STATUS ntlm_computeMicValue ( NTLM_CONTEXT ntlm,
SecBuffer micvalue 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ntlm_computeProofValue()

SECURITY_STATUS ntlm_computeProofValue ( NTLM_CONTEXT ntlm,
SecBuffer ntproof 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ntlm_ContextFree()

static void ntlm_ContextFree ( NTLM_CONTEXT context)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ntlm_ContextNew()

static NTLM_CONTEXT* ntlm_ContextNew ( void  )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ntlm_DecryptMessage()

static SECURITY_STATUS SEC_ENTRY ntlm_DecryptMessage ( PCtxtHandle  phContext,
PSecBufferDesc  pMessage,
ULONG  MessageSeqNo,
PULONG  pfQOP 
)
static
Here is the call graph for this function:

◆ ntlm_DeleteSecurityContext()

static SECURITY_STATUS SEC_ENTRY ntlm_DeleteSecurityContext ( PCtxtHandle  phContext)
static
Here is the call graph for this function:

◆ ntlm_EncryptMessage()

static SECURITY_STATUS SEC_ENTRY ntlm_EncryptMessage ( PCtxtHandle  phContext,
ULONG  fQOP,
PSecBufferDesc  pMessage,
ULONG  MessageSeqNo 
)
static
Here is the call graph for this function:

◆ ntlm_FreeCredentialsHandle()

static SECURITY_STATUS SEC_ENTRY ntlm_FreeCredentialsHandle ( PCredHandle  phCredential)
static
Here is the call graph for this function:

◆ ntlm_get_state()

NTLM_STATE ntlm_get_state ( NTLM_CONTEXT ntlm)
Here is the caller graph for this function:

◆ ntlm_ImpersonateSecurityContext()

static SECURITY_STATUS SEC_ENTRY ntlm_ImpersonateSecurityContext ( PCtxtHandle  phContext)
static

◆ NTLM_init()

BOOL NTLM_init ( void  )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ntlm_InitializeSecurityContextA()

static SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextA ( PCredHandle  phCredential,
PCtxtHandle  phContext,
SEC_CHAR pszTargetName,
ULONG  fContextReq,
ULONG  Reserved1,
ULONG  TargetDataRep,
PSecBufferDesc  pInput,
ULONG  Reserved2,
PCtxtHandle  phNewContext,
PSecBufferDesc  pOutput,
PULONG  pfContextAttr,
PTimeStamp  ptsExpiry 
)
static

◆ ntlm_InitializeSecurityContextW()

static SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextW ( PCredHandle  phCredential,
PCtxtHandle  phContext,
SEC_WCHAR pszTargetName,
ULONG  fContextReq,
ULONG  Reserved1,
ULONG  TargetDataRep,
PSecBufferDesc  pInput,
ULONG  Reserved2,
PCtxtHandle  phNewContext,
PSecBufferDesc  pOutput,
PULONG  pfContextAttr,
PTimeStamp  ptsExpiry 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ntlm_MakeSignature()

static SECURITY_STATUS SEC_ENTRY ntlm_MakeSignature ( PCtxtHandle  phContext,
ULONG  fQOP,
PSecBufferDesc  pMessage,
ULONG  MessageSeqNo 
)
static
Here is the call graph for this function:

◆ ntlm_message_type_string()

const char* ntlm_message_type_string ( UINT32  messageType)
Here is the caller graph for this function:

◆ ntlm_negotiate_flags_string()

char* ntlm_negotiate_flags_string ( char *  buffer,
size_t  size,
UINT32  flags 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ntlm_QueryContextAttributesA()

static SECURITY_STATUS SEC_ENTRY ntlm_QueryContextAttributesA ( PCtxtHandle  phContext,
ULONG  ulAttribute,
void *  pBuffer 
)
static
Here is the call graph for this function:

◆ ntlm_QueryContextAttributesW()

static SECURITY_STATUS SEC_ENTRY ntlm_QueryContextAttributesW ( PCtxtHandle  phContext,
ULONG  ulAttribute,
void *  pBuffer 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ntlm_QueryCredentialsAttributesA()

static SECURITY_STATUS SEC_ENTRY ntlm_QueryCredentialsAttributesA ( PCredHandle  phCredential,
ULONG  ulAttribute,
void *  pBuffer 
)
static
Here is the call graph for this function:

◆ ntlm_QueryCredentialsAttributesW()

static SECURITY_STATUS SEC_ENTRY ntlm_QueryCredentialsAttributesW ( PCredHandle  phCredential,
ULONG  ulAttribute,
void *  pBuffer 
)
static
Here is the caller graph for this function:

◆ ntlm_reset_cipher_state()

BOOL ntlm_reset_cipher_state ( PSecHandle  phContext)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ntlm_RevertSecurityContext()

static SECURITY_STATUS SEC_ENTRY ntlm_RevertSecurityContext ( PCtxtHandle  phContext)
static

◆ ntlm_SetContextAttributesA()

static SECURITY_STATUS SEC_ENTRY ntlm_SetContextAttributesA ( PCtxtHandle  phContext,
ULONG  ulAttribute,
void *  pBuffer,
ULONG  cbBuffer 
)
static
Here is the call graph for this function:

◆ ntlm_SetContextAttributesW()

static SECURITY_STATUS SEC_ENTRY ntlm_SetContextAttributesW ( PCtxtHandle  phContext,
ULONG  ulAttribute,
void *  pBuffer,
ULONG  cbBuffer 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ntlm_SetContextServicePrincipalNameW()

static int ntlm_SetContextServicePrincipalNameW ( NTLM_CONTEXT context,
LPWSTR  ServicePrincipalName 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ntlm_SetContextTargetName()

static int ntlm_SetContextTargetName ( NTLM_CONTEXT context,
char *  TargetName 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ntlm_SetContextWorkstation()

static int ntlm_SetContextWorkstation ( NTLM_CONTEXT context,
char *  Workstation 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ntlm_SetCredentialsAttributesA()

static SECURITY_STATUS SEC_ENTRY ntlm_SetCredentialsAttributesA ( PCredHandle  phCredential,
ULONG  ulAttribute,
void *  pBuffer,
ULONG  cbBuffer 
)
static

◆ ntlm_SetCredentialsAttributesW()

static SECURITY_STATUS SEC_ENTRY ntlm_SetCredentialsAttributesW ( PCredHandle  phCredential,
ULONG  ulAttribute,
void *  pBuffer,
ULONG  cbBuffer 
)
static

◆ ntlm_state_string()

const char* ntlm_state_string ( NTLM_STATE  state)
Here is the caller graph for this function:

◆ ntlm_VerifySignature()

static SECURITY_STATUS SEC_ENTRY ntlm_VerifySignature ( PCtxtHandle  phContext,
PSecBufferDesc  pMessage,
ULONG  MessageSeqNo,
PULONG  pfQOP 
)
static
Here is the call graph for this function:

Variable Documentation

◆ NTLM_PACKAGE_NAME

char* NTLM_PACKAGE_NAME = "NTLM"
static

◆ NTLM_SecPkgInfoA

const SecPkgInfoA NTLM_SecPkgInfoA
Initial value:
= {
0x00082B37,
1,
0x000A,
0x00000B48,
"NTLM",
"NTLM Security Package"
}

WinPR: Windows Portable Runtime NTLM Security Package

Copyright 2021 Armin Novak armin.nosp@m..nov.nosp@m.ak@th.nosp@m.inca.nosp@m.st.co.nosp@m.m Copyright 2021 Thincast Technologies GmbH

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

◆ NTLM_SecPkgInfoW

const SecPkgInfoW NTLM_SecPkgInfoW
Initial value:
= {
0x00082B37,
1,
0x000A,
0x00000B48,
}
static WCHAR NTLM_SecPkgInfoW_CommentBuffer[32]
Definition: sspi/NTLM/ntlm.c:1406
static WCHAR NTLM_SecPkgInfoW_NameBuffer[32]
Definition: sspi/NTLM/ntlm.c:1405

◆ NTLM_SecPkgInfoW_CommentBuffer

WCHAR NTLM_SecPkgInfoW_CommentBuffer[32] = { 0 }
static

◆ NTLM_SecPkgInfoW_NameBuffer

WCHAR NTLM_SecPkgInfoW_NameBuffer[32] = { 0 }
static

◆ NTLM_SecurityFunctionTableA

const SecurityFunctionTableA NTLM_SecurityFunctionTableA

◆ NTLM_SecurityFunctionTableW

const SecurityFunctionTableW NTLM_SecurityFunctionTableW