libwinpr-sspi: add GetSystemTimeAsFileTime()

This commit is contained in:
Marc-André Moreau 2012-06-29 16:43:07 -04:00
parent 633e0f90bf
commit d3f9b057a2
6 changed files with 56 additions and 14 deletions

View File

@ -145,6 +145,8 @@ WINPR_API BOOL GetVersionExW(LPOSVERSIONINFOW lpVersionInformation);
#define GetVersionEx GetVersionExA
#endif
WINPR_API VOID GetSystemTimeAsFileTime(LPFILETIME lpSystemTimeAsFileTime);
#endif
#endif /* WINPR_SYSINFO_H */

View File

@ -143,6 +143,23 @@ typedef LPSTR LPTSTR;
typedef LPCSTR LPCTSTR;
#endif
typedef union _ULARGE_INTEGER
{
struct
{
DWORD LowPart;
DWORD HighPart;
};
struct
{
DWORD LowPart;
DWORD HighPart;
} u;
ULONGLONG QuadPart;
} ULARGE_INTEGER, *PULARGE_INTEGER;
typedef struct _FILETIME
{
DWORD dwLowDateTime;

View File

@ -85,7 +85,7 @@ NTLM_CONTEXT* ntlm_ContextNew()
if (context != NULL)
{
context->ntlm_v2 = 0;
context->ntlm_v2 = FALSE;
context->NegotiateFlags = 0;
context->SendVersionInfo = 0;
context->LmCompatibilityLevel = 3;

View File

@ -166,13 +166,15 @@ void ntlm_output_channel_bindings(NTLM_CONTEXT* context)
void ntlm_current_time(BYTE* timestamp)
{
UINT64 time64;
FILETIME filetime;
ULARGE_INTEGER time64;
/* Timestamp (8 bytes), represented as the number of tenths of microseconds since midnight of January 1, 1601 */
time64 = time(NULL) + 11644473600LL; /* Seconds since January 1, 1601 */
time64 *= 10000000; /* Convert timestamp to tenths of a microsecond */
GetSystemTimeAsFileTime(&filetime);
CopyMemory(timestamp, &time64, 8); /* Copy into timestamp in little-endian */
time64.LowPart = filetime.dwLowDateTime;
time64.HighPart = filetime.dwHighDateTime;
CopyMemory(timestamp, &(time64.QuadPart), 8);
}
/**
@ -191,6 +193,13 @@ void ntlm_generate_timestamp(NTLM_CONTEXT* context)
CopyMemory(context->av_pairs->Timestamp.value, context->Timestamp, 8);
return;
}
else
{
context->ntlm_v2 = FALSE;
context->av_pairs->Timestamp.length = 8;
context->av_pairs->Timestamp.value = malloc(context->av_pairs->Timestamp.length);
CopyMemory(context->av_pairs->Timestamp.value, context->Timestamp, 8);
}
}
else
{
@ -279,23 +288,23 @@ void ntlm_compute_ntlm_v2_response(NTLM_CONTEXT* context)
sspi_SecBufferAlloc(&ntlm_v2_temp, context->TargetInfo.cbBuffer + 28);
memset(ntlm_v2_temp.pvBuffer, '\0', ntlm_v2_temp.cbBuffer);
ZeroMemory(ntlm_v2_temp.pvBuffer, ntlm_v2_temp.cbBuffer);
blob = (BYTE*) ntlm_v2_temp.pvBuffer;
/* Compute the NTLMv2 hash */
ntlm_compute_ntlm_v2_hash(context, (char*) ntlm_v2_hash);
#ifdef WITH_DEBUG_NTLM
printf("Password (length = %d)\n", context->identity.PasswordLength);
winpr_HexDump((BYTE*) context->identity.Password, context->identity.PasswordLength);
printf("Password (length = %d)\n", context->identity.PasswordLength * 2);
winpr_HexDump((BYTE*) context->identity.Password, context->identity.PasswordLength * 2);
printf("\n");
printf("Username (length = %d)\n", context->identity.UserLength);
winpr_HexDump((BYTE*) context->identity.User, context->identity.UserLength);
printf("Username (length = %d)\n", context->identity.UserLength * 2);
winpr_HexDump((BYTE*) context->identity.User, context->identity.UserLength * 2);
printf("\n");
printf("Domain (length = %d)\n", context->identity.DomainLength);
winpr_HexDump((BYTE*) context->identity.Domain, context->identity.DomainLength);
printf("Domain (length = %d)\n", context->identity.DomainLength * 2);
winpr_HexDump((BYTE*) context->identity.Domain, context->identity.DomainLength * 2);
printf("\n");
printf("Workstation (length = %d)\n", context->WorkstationLength);

View File

@ -381,8 +381,8 @@ SECURITY_STATUS ntlm_read_ChallengeMessage(NTLM_CONTEXT* context, PSecBuffer buf
winpr_HexDump(context->ChallengeMessage.pvBuffer, context->ChallengeMessage.cbBuffer);
printf("\n");
#endif
/* AV_PAIRs */
if (context->ntlm_v2)
ntlm_populate_av_pairs(context);

View File

@ -63,6 +63,7 @@
#ifndef _WIN32
#include <time.h>
#include <unistd.h>
#include <winpr/crt.h>
@ -152,4 +153,17 @@ BOOL GetVersionExW(LPOSVERSIONINFOW lpVersionInformation)
return 1;
}
VOID GetSystemTimeAsFileTime(LPFILETIME lpSystemTimeAsFileTime)
{
ULARGE_INTEGER time64;
/* time represented in tenths of microseconds since midnight of January 1, 1601 */
time64.QuadPart = time(NULL) + 11644473600LL; /* Seconds since January 1, 1601 */
time64.QuadPart *= 10000000; /* Convert timestamp to tenths of a microsecond */
lpSystemTimeAsFileTime->dwLowDateTime = time64.LowPart;
lpSystemTimeAsFileTime->dwHighDateTime = time64.HighPart;
}
#endif