libwinpr-sspi: add GetSystemTimeAsFileTime()
authorMarc-André Moreau <marcandre.moreau@gmail.com>
Fri, 29 Jun 2012 20:43:07 +0000 (16:43 -0400)
committerMarc-André Moreau <marcandre.moreau@gmail.com>
Fri, 29 Jun 2012 20:43:07 +0000 (16:43 -0400)
include/winpr/sysinfo.h
include/winpr/wtypes.h
winpr/sspi/NTLM/ntlm.c
winpr/sspi/NTLM/ntlm_compute.c
winpr/sspi/NTLM/ntlm_message.c
winpr/sysinfo/sysinfo.c

index 85ba5bd..efb97e7 100644 (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 */
index 1311132..f84710f 100644 (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;
index a74cb0e..a0a5458 100644 (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;
index 5fcb533..df5f112 100644 (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);
index cb8cedc..d55e3b5 100644 (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);
 
index fb1e5d0..feadc89 100644 (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