diff --git a/channels/rail/rail_orders.c b/channels/rail/rail_orders.c index 65c96c6d8..a5a641678 100644 --- a/channels/rail/rail_orders.c +++ b/channels/rail/rail_orders.c @@ -60,7 +60,7 @@ static const char* const RAIL_ORDER_TYPE_STRINGS[] = "Execute Result" }; -void rail_string_to_unicode_string(rdpRailOrder* rail_order, char* string, UNICODE_STRING* unicode_string) +void rail_string_to_unicode_string(rdpRailOrder* rail_order, char* string, RAIL_UNICODE_STRING* unicode_string) { char* buffer; size_t length = 0; diff --git a/channels/rail/rail_orders.h b/channels/rail/rail_orders.h index fbbe20f66..cd4e07bb5 100644 --- a/channels/rail/rail_orders.h +++ b/channels/rail/rail_orders.h @@ -54,7 +54,7 @@ #define RAIL_GET_APPID_REQ_ORDER_LENGTH 4 /* fixed */ #define RAIL_LANGBAR_INFO_ORDER_LENGTH 4 /* fixed */ -void rail_string_to_unicode_string(rdpRailOrder* rail_order, char* string, UNICODE_STRING* unicode_string); +void rail_string_to_unicode_string(rdpRailOrder* rail_order, char* string, RAIL_UNICODE_STRING* unicode_string); void rail_read_handshake_order(STREAM* s, RAIL_HANDSHAKE_ORDER* handshake); void rail_read_server_exec_result_order(STREAM* s, RAIL_EXEC_RESULT_ORDER* exec_result); diff --git a/include/freerdp/crypto/der.h b/include/freerdp/crypto/der.h index e692823b9..1902f93cb 100644 --- a/include/freerdp/crypto/der.h +++ b/include/freerdp/crypto/der.h @@ -30,6 +30,7 @@ FREERDP_API int der_skip_octet_string(int length); FREERDP_API int der_skip_sequence_tag(int length); FREERDP_API int der_write_sequence_tag(STREAM* s, int length); FREERDP_API int der_skip_contextual_tag(int length); +FREERDP_API int der_write_contextual_tag(STREAM* s, uint8 tag, int length, boolean pc); FREERDP_API void der_write_octet_string(STREAM* s, uint8* oct_str, int length); #endif /* FREERDP_CRYPTO_DER_H */ diff --git a/include/freerdp/rail.h b/include/freerdp/rail.h index 840e7f0c6..6ac2b4c2b 100644 --- a/include/freerdp/rail.h +++ b/include/freerdp/rail.h @@ -150,18 +150,18 @@ enum SPI_MASK #define TF_SFT_NOEXTRAICONSONMINIMIZED 0x00000400 #define TF_SFT_DESKBAND 0x00000800 -struct _UNICODE_STRING +struct _RAIL_UNICODE_STRING { uint16 length; uint8* string; }; -typedef struct _UNICODE_STRING UNICODE_STRING; +typedef struct _RAIL_UNICODE_STRING RAIL_UNICODE_STRING; struct _HIGH_CONTRAST { uint32 flags; uint32 colorSchemeLength; - UNICODE_STRING colorScheme; + RAIL_UNICODE_STRING colorScheme; }; typedef struct _HIGH_CONTRAST HIGH_CONTRAST; @@ -182,9 +182,9 @@ typedef struct _RAIL_CLIENT_STATUS_ORDER RAIL_CLIENT_STATUS_ORDER; struct _RAIL_EXEC_ORDER { uint16 flags; - UNICODE_STRING exeOrFile; - UNICODE_STRING workingDir; - UNICODE_STRING arguments; + RAIL_UNICODE_STRING exeOrFile; + RAIL_UNICODE_STRING workingDir; + RAIL_UNICODE_STRING arguments; }; typedef struct _RAIL_EXEC_ORDER RAIL_EXEC_ORDER; @@ -193,7 +193,7 @@ struct _RAIL_EXEC_RESULT_ORDER uint16 flags; uint16 execResult; uint32 rawResult; - UNICODE_STRING exeOrFile; + RAIL_UNICODE_STRING exeOrFile; }; typedef struct _RAIL_EXEC_RESULT_ORDER RAIL_EXEC_RESULT_ORDER; @@ -287,7 +287,7 @@ typedef struct _RAIL_GET_APPID_REQ_ORDER RAIL_GET_APPID_REQ_ORDER; struct _RAIL_GET_APPID_RESP_ORDER { uint32 windowId; - UNICODE_STRING applicationId; + RAIL_UNICODE_STRING applicationId; uint8 applicationIdBuffer[512]; }; typedef struct _RAIL_GET_APPID_RESP_ORDER RAIL_GET_APPID_RESP_ORDER; diff --git a/include/freerdp/rail/window.h b/include/freerdp/rail/window.h index 87eeb2318..7f32615b4 100644 --- a/include/freerdp/rail/window.h +++ b/include/freerdp/rail/window.h @@ -46,7 +46,7 @@ struct rdp_window uint32 style; uint32 extendedStyle; uint8 showState; - UNICODE_STRING titleInfo; + RAIL_UNICODE_STRING titleInfo; uint32 clientOffsetX; uint32 clientOffsetY; uint32 clientAreaWidth; diff --git a/include/freerdp/utils/rail.h b/include/freerdp/utils/rail.h index c47a16917..8ad2129fc 100644 --- a/include/freerdp/utils/rail.h +++ b/include/freerdp/utils/rail.h @@ -25,11 +25,11 @@ #include #include -FREERDP_API void rail_unicode_string_alloc(UNICODE_STRING* unicode_string, uint16 cbString); -FREERDP_API void rail_unicode_string_free(UNICODE_STRING* unicode_string); -FREERDP_API void rail_read_unicode_string(STREAM* s, UNICODE_STRING* unicode_string); -FREERDP_API void rail_write_unicode_string(STREAM* s, UNICODE_STRING* unicode_string); -FREERDP_API void rail_write_unicode_string_value(STREAM* s, UNICODE_STRING* unicode_string); +FREERDP_API void rail_unicode_string_alloc(RAIL_UNICODE_STRING* unicode_string, uint16 cbString); +FREERDP_API void rail_unicode_string_free(RAIL_UNICODE_STRING* unicode_string); +FREERDP_API void rail_read_unicode_string(STREAM* s, RAIL_UNICODE_STRING* unicode_string); +FREERDP_API void rail_write_unicode_string(STREAM* s, RAIL_UNICODE_STRING* unicode_string); +FREERDP_API void rail_write_unicode_string_value(STREAM* s, RAIL_UNICODE_STRING* unicode_string); FREERDP_API void* rail_clone_order(uint32 event_type, void* order); FREERDP_API void rail_free_cloned_order(uint32 event_type, void* order); diff --git a/include/freerdp/window.h b/include/freerdp/window.h index 3a4fcf098..3338e1757 100644 --- a/include/freerdp/window.h +++ b/include/freerdp/window.h @@ -155,8 +155,8 @@ struct _NOTIFY_ICON_INFOTIP { uint32 timeout; uint32 flags; - UNICODE_STRING text; - UNICODE_STRING title; + RAIL_UNICODE_STRING text; + RAIL_UNICODE_STRING title; }; typedef struct _NOTIFY_ICON_INFOTIP NOTIFY_ICON_INFOTIP; @@ -166,7 +166,7 @@ struct _WINDOW_STATE_ORDER uint32 style; uint32 extendedStyle; uint32 showState; - UNICODE_STRING titleInfo; + RAIL_UNICODE_STRING titleInfo; uint32 clientOffsetX; uint32 clientOffsetY; uint32 clientAreaWidth; @@ -203,7 +203,7 @@ typedef struct _WINDOW_CACHED_ICON_ORDER WINDOW_CACHED_ICON_ORDER; struct _NOTIFY_ICON_STATE_ORDER { uint32 version; - UNICODE_STRING toolTip; + RAIL_UNICODE_STRING toolTip; NOTIFY_ICON_INFOTIP infoTip; uint32 state; ICON_INFO icon; diff --git a/include/winpr/security.h b/include/winpr/security.h new file mode 100644 index 000000000..f4b97d8e7 --- /dev/null +++ b/include/winpr/security.h @@ -0,0 +1,34 @@ +/** + * WinPR: Windows Portable Runtime + * Security Definitions + * + * Copyright 2012 Marc-Andre Moreau + * + * 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. + */ + +#ifndef WINPR_SECURITY_H +#define WINPR_SECURITY_H + +#include +#include + +typedef struct _LSA_UNICODE_STRING +{ + USHORT Length; + USHORT MaximumLength; + PWSTR Buffer; +} LSA_UNICODE_STRING, *PLSA_UNICODE_STRING, UNICODE_STRING, *PUNICODE_STRING; + +#endif /* WINPR_SECURITY_H */ + diff --git a/include/winpr/sspi.h b/include/winpr/sspi.h index bc375d692..e0881e566 100644 --- a/include/winpr/sspi.h +++ b/include/winpr/sspi.h @@ -26,6 +26,7 @@ #include #include #include +#include #ifdef _WIN32 diff --git a/libfreerdp-crypto/der.c b/libfreerdp-crypto/der.c index 8c127136f..395b94ec3 100644 --- a/libfreerdp-crypto/der.c +++ b/libfreerdp-crypto/der.c @@ -60,6 +60,11 @@ int der_get_content_length(int length) return length - 2; } +int der_skip_contextual_tag(int length) +{ + return _der_skip_length(length) + 1; +} + int der_write_contextual_tag(STREAM* s, uint8 tag, int length, boolean pc) { stream_write_uint8(s, (ER_CLASS_CTXT | ER_PC(pc)) | (ER_TAG_MASK & tag)); @@ -94,7 +99,3 @@ int der_write_sequence_tag(STREAM* s, int length) return der_write_length(s, length) + 1; } -int der_skip_contextual_tag(int length) -{ - return _der_skip_length(length) + 1; -} diff --git a/libfreerdp-crypto/nla.c b/libfreerdp-crypto/nla.c index fe882d9b4..22fd5117f 100644 --- a/libfreerdp-crypto/nla.c +++ b/libfreerdp-crypto/nla.c @@ -311,7 +311,7 @@ int credssp_client_authenticate(rdpCredssp* credssp) return -1; #ifdef WITH_DEBUG_CREDSSP - printf("Receiving Authentication Token (%d)\n", credssp->negoToken.cbBuffer); + printf("Receiving Authentication Token (%d)\n", (int) credssp->negoToken.cbBuffer); winpr_HexDump(credssp->negoToken.pvBuffer, credssp->negoToken.cbBuffer); #endif @@ -655,7 +655,7 @@ SECURITY_STATUS credssp_decrypt_public_key_echo(rdpCredssp* credssp) if (credssp->PublicKey.cbBuffer + credssp->ContextSizes.cbMaxSignature != credssp->pubKeyAuth.cbBuffer) { - printf("credssp_decrypt_public_key_echo: unexpected pubKeyAuth buffer size:%d\n", credssp->pubKeyAuth.cbBuffer); + printf("unexpected pubKeyAuth buffer size:%d\n", (int) credssp->pubKeyAuth.cbBuffer); return SEC_E_INVALID_TOKEN; } diff --git a/libfreerdp-utils/rail.c b/libfreerdp-utils/rail.c index 4cf5906d5..dbd7d3f54 100644 --- a/libfreerdp-utils/rail.c +++ b/libfreerdp-utils/rail.c @@ -23,13 +23,13 @@ #include #include -void rail_unicode_string_alloc(UNICODE_STRING* unicode_string, uint16 cbString) +void rail_unicode_string_alloc(RAIL_UNICODE_STRING* unicode_string, uint16 cbString) { unicode_string->length = cbString; unicode_string->string = xzalloc(cbString); } -void rail_unicode_string_free(UNICODE_STRING* unicode_string) +void rail_unicode_string_free(RAIL_UNICODE_STRING* unicode_string) { unicode_string->length = 0; @@ -37,7 +37,7 @@ void rail_unicode_string_free(UNICODE_STRING* unicode_string) xfree(unicode_string->string); } -void rail_read_unicode_string(STREAM* s, UNICODE_STRING* unicode_string) +void rail_read_unicode_string(STREAM* s, RAIL_UNICODE_STRING* unicode_string) { stream_read_uint16(s, unicode_string->length); /* cbString (2 bytes) */ @@ -49,14 +49,14 @@ void rail_read_unicode_string(STREAM* s, UNICODE_STRING* unicode_string) stream_read(s, unicode_string->string, unicode_string->length); } -void rail_write_unicode_string(STREAM* s, UNICODE_STRING* unicode_string) +void rail_write_unicode_string(STREAM* s, RAIL_UNICODE_STRING* unicode_string) { stream_check_size(s, 2 + unicode_string->length); stream_write_uint16(s, unicode_string->length); /* cbString (2 bytes) */ stream_write(s, unicode_string->string, unicode_string->length); /* string */ } -void rail_write_unicode_string_value(STREAM* s, UNICODE_STRING* unicode_string) +void rail_write_unicode_string_value(STREAM* s, RAIL_UNICODE_STRING* unicode_string) { if (unicode_string->length > 0) { diff --git a/winpr/sspi/CMakeLists.txt b/winpr/sspi/CMakeLists.txt index 283822edc..6ec31db3a 100644 --- a/winpr/sspi/CMakeLists.txt +++ b/winpr/sspi/CMakeLists.txt @@ -61,6 +61,7 @@ set_target_properties(winpr-sspi PROPERTIES VERSION ${FREERDP_VERSION_FULL} SOVE if (NOT WIN32) target_link_libraries(winpr-sspi winpr-crt) + target_link_libraries(winpr-sspi winpr-sysinfo) endif() target_link_libraries(winpr-sspi winpr-utils) diff --git a/winpr/sspi/NTLM/ntlm.c b/winpr/sspi/NTLM/ntlm.c index 1d9c3917f..93e9c73bd 100644 --- a/winpr/sspi/NTLM/ntlm.c +++ b/winpr/sspi/NTLM/ntlm.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "ntlm.h" #include "../sspi.h" @@ -37,18 +38,42 @@ char* NTLM_PACKAGE_NAME = "NTLM"; void ntlm_SetContextWorkstation(NTLM_CONTEXT* context, char* Workstation) { + DWORD nSize = 0; + + if (!Workstation) + { + GetComputerNameExA(ComputerNameNetBIOS, NULL, &nSize); + Workstation = malloc(nSize); + GetComputerNameExA(ComputerNameNetBIOS, Workstation, &nSize); + } + context->WorkstationLength = strlen(Workstation) * 2; context->Workstation = (UINT16*) malloc(context->WorkstationLength); MultiByteToWideChar(CP_ACP, 0, Workstation, strlen(Workstation), (LPWSTR) context->Workstation, context->WorkstationLength / 2); + + if (nSize > 0) + free(Workstation); } void ntlm_SetContextTargetName(NTLM_CONTEXT* context, char* TargetName) { + DWORD nSize = 0; + + if (!TargetName) + { + GetComputerNameExA(ComputerNameDnsHostname, NULL, &nSize); + TargetName = malloc(nSize); + GetComputerNameExA(ComputerNameDnsHostname, TargetName, &nSize); + } + context->TargetName.cbBuffer = strlen(TargetName) * 2; context->TargetName.pvBuffer = (void*) malloc(context->TargetName.cbBuffer); MultiByteToWideChar(CP_ACP, 0, TargetName, strlen(TargetName), (LPWSTR) context->TargetName.pvBuffer, context->TargetName.cbBuffer / 2); + + if (nSize > 0) + free(TargetName); } NTLM_CONTEXT* ntlm_ContextNew() @@ -236,7 +261,7 @@ SECURITY_STATUS SEC_ENTRY ntlm_AcceptSecurityContext(PCredHandle phCredential, P credentials = (CREDENTIALS*) sspi_SecureHandleGetLowerPointer(phCredential); sspi_CopyAuthIdentity(&context->identity, &credentials->identity); - ntlm_SetContextTargetName(context, "FreeRDP"); + ntlm_SetContextTargetName(context, NULL); sspi_SecureHandleSetLowerPointer(phNewContext, context); sspi_SecureHandleSetUpperPointer(phNewContext, (void*) NTLM_PACKAGE_NAME); @@ -348,7 +373,7 @@ SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextA(PCredHandle phCredenti credentials = (CREDENTIALS*) sspi_SecureHandleGetLowerPointer(phCredential); sspi_CopyAuthIdentity(&context->identity, &credentials->identity); - ntlm_SetContextWorkstation(context, "WORKSTATION"); + ntlm_SetContextWorkstation(context, NULL); sspi_SecureHandleSetLowerPointer(phNewContext, context); sspi_SecureHandleSetUpperPointer(phNewContext, (void*) NTLM_PACKAGE_NAME); diff --git a/winpr/sspi/NTLM/ntlm_message.c b/winpr/sspi/NTLM/ntlm_message.c index 8a7451ee2..ebf9b8a1d 100644 --- a/winpr/sspi/NTLM/ntlm_message.c +++ b/winpr/sspi/NTLM/ntlm_message.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "ntlm_compute.h" @@ -118,11 +119,15 @@ static const char* const NTLM_NEGOTIATE_STRINGS[] = void ntlm_output_version(PStream s) { - /* Version Info for Windows 7 SP1 */ + OSVERSIONINFOA osVersionInfo; - StreamWrite_UINT8(s, WINDOWS_MAJOR_VERSION_6); /* ProductMajorVersion (1 byte) */ - StreamWrite_UINT8(s, WINDOWS_MINOR_VERSION_1); /* ProductMinorVersion (1 byte) */ - StreamWrite_UINT16(s, 7601); /* ProductBuild (2 bytes) */ + osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA); + + GetVersionExA(&osVersionInfo); + + StreamWrite_UINT8(s, osVersionInfo.dwMajorVersion); /* ProductMajorVersion (1 byte) */ + StreamWrite_UINT8(s, osVersionInfo.dwMinorVersion); /* ProductMinorVersion (1 byte) */ + StreamWrite_UINT16(s, osVersionInfo.dwBuildNumber); /* ProductBuild (2 bytes) */ StreamZero(s, 3); /* Reserved (3 bytes) */ StreamWrite_UINT8(s, NTLMSSP_REVISION_W2K3); /* NTLMRevisionCurrent (1 byte) */ } diff --git a/winpr/sysinfo/sysinfo.c b/winpr/sysinfo/sysinfo.c index 9e44e84f2..fb1e5d02a 100644 --- a/winpr/sysinfo/sysinfo.c +++ b/winpr/sysinfo/sysinfo.c @@ -63,11 +63,17 @@ #ifndef _WIN32 +#include #include -#include BOOL GetComputerNameExA(COMPUTER_NAME_FORMAT NameType, LPSTR lpBuffer, LPDWORD nSize) { + char hostname[256]; + int hostname_length; + + gethostname(hostname, sizeof(hostname)); + hostname_length = strlen(hostname); + switch (NameType) { case ComputerNameNetBIOS: @@ -79,8 +85,16 @@ BOOL GetComputerNameExA(COMPUTER_NAME_FORMAT NameType, LPSTR lpBuffer, LPDWORD n case ComputerNamePhysicalDnsDomain: case ComputerNamePhysicalDnsFullyQualified: - if (gethostname(lpBuffer, *nSize) < 0) + if (*nSize <= hostname_length) + { + *nSize = hostname_length + 1; return 0; + } + + if (!lpBuffer) + return 0; + + CopyMemory(lpBuffer, hostname, hostname_length + 1); break;