2011-07-12 02:46:36 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-07-12 02:46:36 +04:00
|
|
|
* RDP Client Info
|
|
|
|
*
|
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.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.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-12-17 08:34:07 +04:00
|
|
|
#include <winpr/crt.h>
|
|
|
|
|
2012-02-16 10:53:58 +04:00
|
|
|
#include "timezone.h"
|
|
|
|
|
2011-07-12 02:46:36 +04:00
|
|
|
#include "info.h"
|
|
|
|
|
2011-07-25 21:42:14 +04:00
|
|
|
#define INFO_TYPE_LOGON 0x00000000
|
|
|
|
#define INFO_TYPE_LOGON_LONG 0x00000001
|
|
|
|
#define INFO_TYPE_LOGON_PLAIN_NOTIFY 0x00000002
|
|
|
|
#define INFO_TYPE_LOGON_EXTENDED_INF 0x00000003
|
|
|
|
|
2011-11-30 05:15:50 +04:00
|
|
|
/*
|
|
|
|
static const char* const INFO_TYPE_LOGON_STRINGS[] =
|
2011-07-25 21:42:14 +04:00
|
|
|
{
|
|
|
|
"Logon Info V1",
|
|
|
|
"Logon Info V2",
|
|
|
|
"Logon Plain Notify",
|
|
|
|
"Logon Extended Info"
|
|
|
|
};
|
2011-11-30 05:15:50 +04:00
|
|
|
*/
|
2011-07-25 21:42:14 +04:00
|
|
|
|
2011-07-12 02:46:36 +04:00
|
|
|
/**
|
2011-07-25 21:42:14 +04:00
|
|
|
* Read Server Auto Reconnect Cookie (ARC_SC_PRIVATE_PACKET).\n
|
|
|
|
* @msdn{cc240540}
|
|
|
|
* @param s stream
|
|
|
|
* @param settings settings
|
|
|
|
*/
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL rdp_read_server_auto_reconnect_cookie(wStream* s, rdpSettings* settings)
|
2011-07-25 21:42:14 +04:00
|
|
|
{
|
|
|
|
ARC_SC_PRIVATE_PACKET* autoReconnectCookie;
|
2012-11-08 00:13:14 +04:00
|
|
|
autoReconnectCookie = settings->ServerAutoReconnectCookie;
|
2011-07-25 21:42:14 +04:00
|
|
|
|
2013-03-29 06:26:28 +04:00
|
|
|
if (stream_get_left(s) < 4+4+4+16)
|
2013-01-11 04:18:11 +04:00
|
|
|
return FALSE;
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_read_UINT32(s, autoReconnectCookie->cbLen); /* cbLen (4 bytes) */
|
|
|
|
stream_read_UINT32(s, autoReconnectCookie->version); /* version (4 bytes) */
|
|
|
|
stream_read_UINT32(s, autoReconnectCookie->logonId); /* LogonId (4 bytes) */
|
2011-07-25 21:42:14 +04:00
|
|
|
stream_read(s, autoReconnectCookie->arcRandomBits, 16); /* arcRandomBits (16 bytes) */
|
2013-01-11 04:18:11 +04:00
|
|
|
return TRUE;
|
2011-07-25 21:42:14 +04:00
|
|
|
}
|
|
|
|
|
2011-08-20 14:22:14 +04:00
|
|
|
/**
|
|
|
|
* Read Client Auto Reconnect Cookie (ARC_CS_PRIVATE_PACKET).\n
|
|
|
|
* @msdn{cc240541}
|
|
|
|
* @param s stream
|
|
|
|
* @param settings settings
|
|
|
|
*/
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL rdp_read_client_auto_reconnect_cookie(wStream* s, rdpSettings* settings)
|
2011-08-20 14:22:14 +04:00
|
|
|
{
|
|
|
|
ARC_CS_PRIVATE_PACKET* autoReconnectCookie;
|
2012-11-08 00:13:14 +04:00
|
|
|
autoReconnectCookie = settings->ClientAutoReconnectCookie;
|
2011-08-20 14:22:14 +04:00
|
|
|
|
|
|
|
if (stream_get_left(s) < 28)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-20 14:22:14 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_read_UINT32(s, autoReconnectCookie->cbLen); /* cbLen (4 bytes) */
|
|
|
|
stream_read_UINT32(s, autoReconnectCookie->version); /* version (4 bytes) */
|
|
|
|
stream_read_UINT32(s, autoReconnectCookie->logonId); /* LogonId (4 bytes) */
|
2012-03-16 23:47:34 +04:00
|
|
|
stream_read(s, autoReconnectCookie->securityVerifier, 16); /* SecurityVerifier */
|
2011-08-20 14:22:14 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-20 14:22:14 +04:00
|
|
|
}
|
|
|
|
|
2011-07-25 21:42:14 +04:00
|
|
|
/**
|
|
|
|
* Write Client Auto Reconnect Cookie (ARC_CS_PRIVATE_PACKET).\n
|
2011-07-12 02:46:36 +04:00
|
|
|
* @msdn{cc240541}
|
|
|
|
* @param s stream
|
|
|
|
* @param settings settings
|
|
|
|
*/
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
void rdp_write_client_auto_reconnect_cookie(wStream* s, rdpSettings* settings)
|
2011-07-12 02:46:36 +04:00
|
|
|
{
|
|
|
|
ARC_CS_PRIVATE_PACKET* autoReconnectCookie;
|
2012-11-08 00:13:14 +04:00
|
|
|
autoReconnectCookie = settings->ClientAutoReconnectCookie;
|
2011-07-12 02:46:36 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_write_UINT32(s, autoReconnectCookie->cbLen); /* cbLen (4 bytes) */
|
|
|
|
stream_write_UINT32(s, autoReconnectCookie->version); /* version (4 bytes) */
|
|
|
|
stream_write_UINT32(s, autoReconnectCookie->logonId); /* LogonId (4 bytes) */
|
2011-07-12 02:46:36 +04:00
|
|
|
stream_write(s, autoReconnectCookie->securityVerifier, 16); /* SecurityVerifier */
|
|
|
|
}
|
|
|
|
|
2011-08-20 14:22:14 +04:00
|
|
|
/**
|
|
|
|
* Read Extended Info Packet (TS_EXTENDED_INFO_PACKET).\n
|
|
|
|
* @msdn{cc240476}
|
|
|
|
* @param s stream
|
|
|
|
* @param settings settings
|
|
|
|
*/
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL rdp_read_extended_info_packet(wStream* s, rdpSettings* settings)
|
2011-08-20 14:22:14 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 clientAddressFamily;
|
|
|
|
UINT16 cbClientAddress;
|
|
|
|
UINT16 cbClientDir;
|
|
|
|
UINT16 cbAutoReconnectLen;
|
2011-08-20 14:22:14 +04:00
|
|
|
|
2013-03-29 06:26:28 +04:00
|
|
|
if (stream_get_left(s) < 4)
|
2013-01-11 04:18:11 +04:00
|
|
|
return FALSE;
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_UINT16(s, clientAddressFamily); /* clientAddressFamily */
|
|
|
|
stream_read_UINT16(s, cbClientAddress); /* cbClientAddress */
|
2011-08-20 14:22:14 +04:00
|
|
|
|
2012-11-08 03:23:25 +04:00
|
|
|
settings->IPv6Enabled = (clientAddressFamily == ADDRESS_FAMILY_INET6 ? TRUE : FALSE);
|
2012-09-24 04:11:50 +04:00
|
|
|
|
2011-08-20 14:22:14 +04:00
|
|
|
if (stream_get_left(s) < cbClientAddress)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-09-24 04:11:50 +04:00
|
|
|
|
2012-12-17 08:34:07 +04:00
|
|
|
ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) stream_get_tail(s), cbClientAddress / 2, &settings->ClientAddress, 0, NULL, NULL);
|
2011-08-20 14:22:14 +04:00
|
|
|
stream_seek(s, cbClientAddress);
|
|
|
|
|
2013-03-29 06:26:28 +04:00
|
|
|
if (stream_get_left(s) < 2)
|
2013-01-11 04:18:11 +04:00
|
|
|
return FALSE;
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_UINT16(s, cbClientDir); /* cbClientDir */
|
2012-09-24 04:11:50 +04:00
|
|
|
|
2011-08-20 14:22:14 +04:00
|
|
|
if (stream_get_left(s) < cbClientDir)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-09-24 04:11:50 +04:00
|
|
|
|
2012-11-08 03:23:25 +04:00
|
|
|
if (settings->ClientDir)
|
|
|
|
free(settings->ClientDir);
|
2012-09-24 04:11:50 +04:00
|
|
|
|
2012-12-17 08:34:07 +04:00
|
|
|
ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) stream_get_tail(s), cbClientDir / 2, &settings->ClientDir, 0, NULL, NULL);
|
2011-08-20 14:22:14 +04:00
|
|
|
stream_seek(s, cbClientDir);
|
|
|
|
|
|
|
|
if (!rdp_read_client_time_zone(s, settings))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-20 14:22:14 +04:00
|
|
|
|
2013-03-29 06:26:28 +04:00
|
|
|
if (stream_get_left(s) < 10)
|
2013-01-11 04:18:11 +04:00
|
|
|
return FALSE;
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_seek_UINT32(s); /* clientSessionId, should be set to 0 */
|
2012-11-08 00:13:14 +04:00
|
|
|
stream_read_UINT32(s, settings->PerformanceFlags); /* performanceFlags */
|
2011-08-20 14:22:14 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_UINT16(s, cbAutoReconnectLen); /* cbAutoReconnectLen */
|
2011-08-20 14:22:14 +04:00
|
|
|
|
|
|
|
if (cbAutoReconnectLen > 0)
|
|
|
|
return rdp_read_client_auto_reconnect_cookie(s, settings); /* autoReconnectCookie */
|
|
|
|
|
|
|
|
/* reserved1 (2 bytes) */
|
|
|
|
/* reserved2 (2 bytes) */
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-20 14:22:14 +04:00
|
|
|
}
|
|
|
|
|
2011-07-12 02:46:36 +04:00
|
|
|
/**
|
|
|
|
* Write Extended Info Packet (TS_EXTENDED_INFO_PACKET).\n
|
|
|
|
* @msdn{cc240476}
|
|
|
|
* @param s stream
|
|
|
|
* @param settings settings
|
|
|
|
*/
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
void rdp_write_extended_info_packet(wStream* s, rdpSettings* settings)
|
2011-07-12 02:46:36 +04:00
|
|
|
{
|
2012-09-24 03:49:13 +04:00
|
|
|
int clientAddressFamily;
|
2013-01-11 00:30:32 +04:00
|
|
|
WCHAR* clientAddress = NULL;
|
2012-09-24 03:49:13 +04:00
|
|
|
int cbClientAddress;
|
2013-01-11 00:30:32 +04:00
|
|
|
WCHAR* clientDir = NULL;
|
2012-09-24 03:49:13 +04:00
|
|
|
int cbClientDir;
|
|
|
|
int cbAutoReconnectLen;
|
2011-07-12 02:46:36 +04:00
|
|
|
|
2012-11-08 03:23:25 +04:00
|
|
|
clientAddressFamily = settings->IPv6Enabled ? ADDRESS_FAMILY_INET6 : ADDRESS_FAMILY_INET;
|
2011-07-12 02:46:36 +04:00
|
|
|
|
2012-12-17 19:20:25 +04:00
|
|
|
cbClientAddress = ConvertToUnicode(CP_UTF8, 0, settings->ClientAddress, -1, &clientAddress, 0) * 2;
|
2011-07-12 02:46:36 +04:00
|
|
|
|
2012-12-17 19:20:25 +04:00
|
|
|
cbClientDir = ConvertToUnicode(CP_UTF8, 0, settings->ClientDir, -1, &clientDir, 0) * 2;
|
2011-07-12 02:46:36 +04:00
|
|
|
|
2012-11-08 00:13:14 +04:00
|
|
|
cbAutoReconnectLen = (int) settings->ClientAutoReconnectCookie->cbLen;
|
2011-07-12 02:46:36 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, clientAddressFamily); /* clientAddressFamily */
|
2011-07-12 02:46:36 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, cbClientAddress + 2); /* cbClientAddress */
|
2011-07-12 02:46:36 +04:00
|
|
|
|
|
|
|
if (cbClientAddress > 0)
|
|
|
|
stream_write(s, clientAddress, cbClientAddress); /* clientAddress */
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, 0);
|
2011-07-12 02:46:36 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, cbClientDir + 2); /* cbClientDir */
|
2011-07-12 02:46:36 +04:00
|
|
|
|
|
|
|
if (cbClientDir > 0)
|
|
|
|
stream_write(s, clientDir, cbClientDir); /* clientDir */
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, 0);
|
2011-07-12 02:46:36 +04:00
|
|
|
|
|
|
|
rdp_write_client_time_zone(s, settings); /* clientTimeZone */
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_write_UINT32(s, 0); /* clientSessionId, should be set to 0 */
|
2012-11-08 00:13:14 +04:00
|
|
|
stream_write_UINT32(s, settings->PerformanceFlags); /* performanceFlags */
|
2011-07-12 02:46:36 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, cbAutoReconnectLen); /* cbAutoReconnectLen */
|
2011-07-12 02:46:36 +04:00
|
|
|
|
|
|
|
if (cbAutoReconnectLen > 0)
|
2011-07-25 21:42:14 +04:00
|
|
|
rdp_write_client_auto_reconnect_cookie(s, settings); /* autoReconnectCookie */
|
2011-07-12 02:46:36 +04:00
|
|
|
|
|
|
|
/* reserved1 (2 bytes) */
|
|
|
|
/* reserved2 (2 bytes) */
|
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(clientAddress);
|
|
|
|
free(clientDir);
|
2011-07-12 02:46:36 +04:00
|
|
|
}
|
|
|
|
|
2011-08-20 14:22:14 +04:00
|
|
|
/**
|
|
|
|
* Read Info Packet (TS_INFO_PACKET).\n
|
|
|
|
* @msdn{cc240475}
|
|
|
|
* @param s stream
|
|
|
|
* @param settings settings
|
|
|
|
*/
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL rdp_read_info_packet(wStream* s, rdpSettings* settings)
|
2011-08-20 14:22:14 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 flags;
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 cbDomain;
|
|
|
|
UINT16 cbUserName;
|
|
|
|
UINT16 cbPassword;
|
|
|
|
UINT16 cbAlternateShell;
|
|
|
|
UINT16 cbWorkingDir;
|
2011-08-20 14:22:14 +04:00
|
|
|
|
2013-03-29 06:26:28 +04:00
|
|
|
if (stream_get_left(s) < 18) // invalid packet
|
2013-01-11 04:18:11 +04:00
|
|
|
return FALSE;
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_seek_UINT32(s); /* CodePage */
|
|
|
|
stream_read_UINT32(s, flags); /* flags */
|
2011-08-20 14:22:14 +04:00
|
|
|
|
2012-11-08 03:23:25 +04:00
|
|
|
settings->AutoLogonEnabled = ((flags & INFO_AUTOLOGON) ? TRUE : FALSE);
|
2012-11-08 00:13:14 +04:00
|
|
|
settings->RemoteApplicationMode = ((flags & INFO_RAIL) ? TRUE : FALSE);
|
2012-11-08 03:23:25 +04:00
|
|
|
settings->RemoteConsoleAudio = ((flags & INFO_REMOTECONSOLEAUDIO) ? TRUE : FALSE);
|
|
|
|
settings->CompressionEnabled = ((flags & INFO_COMPRESSION) ? TRUE : FALSE);
|
2011-08-20 14:22:14 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_UINT16(s, cbDomain); /* cbDomain */
|
|
|
|
stream_read_UINT16(s, cbUserName); /* cbUserName */
|
|
|
|
stream_read_UINT16(s, cbPassword); /* cbPassword */
|
|
|
|
stream_read_UINT16(s, cbAlternateShell); /* cbAlternateShell */
|
|
|
|
stream_read_UINT16(s, cbWorkingDir); /* cbWorkingDir */
|
2011-08-20 14:22:14 +04:00
|
|
|
|
|
|
|
if (stream_get_left(s) < cbDomain + 2)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-09-24 04:11:50 +04:00
|
|
|
|
2011-08-20 14:22:14 +04:00
|
|
|
if (cbDomain > 0)
|
|
|
|
{
|
2012-12-17 08:34:07 +04:00
|
|
|
ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) stream_get_tail(s), cbDomain / 2, &settings->Domain, 0, NULL, NULL);
|
2011-08-20 14:22:14 +04:00
|
|
|
stream_seek(s, cbDomain);
|
|
|
|
}
|
|
|
|
stream_seek(s, 2);
|
|
|
|
|
|
|
|
if (stream_get_left(s) < cbUserName + 2)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-09-24 04:11:50 +04:00
|
|
|
|
2011-08-20 14:22:14 +04:00
|
|
|
if (cbUserName > 0)
|
|
|
|
{
|
2012-12-17 08:34:07 +04:00
|
|
|
ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) stream_get_tail(s), cbUserName / 2, &settings->Username, 0, NULL, NULL);
|
2011-08-20 14:22:14 +04:00
|
|
|
stream_seek(s, cbUserName);
|
|
|
|
}
|
|
|
|
stream_seek(s, 2);
|
|
|
|
|
|
|
|
if (stream_get_left(s) < cbPassword + 2)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-09-24 04:11:50 +04:00
|
|
|
|
2011-08-20 14:22:14 +04:00
|
|
|
if (cbPassword > 0)
|
|
|
|
{
|
2012-12-17 08:34:07 +04:00
|
|
|
ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) stream_get_tail(s), cbPassword / 2, &settings->Password, 0, NULL, NULL);
|
2011-08-20 14:22:14 +04:00
|
|
|
stream_seek(s, cbPassword);
|
|
|
|
}
|
|
|
|
stream_seek(s, 2);
|
|
|
|
|
|
|
|
if (stream_get_left(s) < cbAlternateShell + 2)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-09-24 04:11:50 +04:00
|
|
|
|
2011-08-20 14:22:14 +04:00
|
|
|
if (cbAlternateShell > 0)
|
|
|
|
{
|
2012-12-17 08:34:07 +04:00
|
|
|
ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) stream_get_tail(s), cbAlternateShell / 2, &settings->AlternateShell, 0, NULL, NULL);
|
2011-08-20 14:22:14 +04:00
|
|
|
stream_seek(s, cbAlternateShell);
|
|
|
|
}
|
|
|
|
stream_seek(s, 2);
|
|
|
|
|
|
|
|
if (stream_get_left(s) < cbWorkingDir + 2)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-09-24 04:11:50 +04:00
|
|
|
|
2011-08-20 14:22:14 +04:00
|
|
|
if (cbWorkingDir > 0)
|
|
|
|
{
|
2012-12-17 08:34:07 +04:00
|
|
|
ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) stream_get_tail(s), cbWorkingDir / 2, &settings->ShellWorkingDirectory, 0, NULL, NULL);
|
2011-08-20 14:22:14 +04:00
|
|
|
stream_seek(s, cbWorkingDir);
|
|
|
|
}
|
|
|
|
stream_seek(s, 2);
|
|
|
|
|
2012-11-07 19:33:06 +04:00
|
|
|
if (settings->RdpVersion >= 5)
|
2011-08-20 14:22:14 +04:00
|
|
|
return rdp_read_extended_info_packet(s, settings); /* extraInfo */
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-20 14:22:14 +04:00
|
|
|
}
|
|
|
|
|
2011-07-12 02:46:36 +04:00
|
|
|
/**
|
|
|
|
* Write Info Packet (TS_INFO_PACKET).\n
|
|
|
|
* @msdn{cc240475}
|
|
|
|
* @param s stream
|
|
|
|
* @param settings settings
|
|
|
|
*/
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
void rdp_write_info_packet(wStream* s, rdpSettings* settings)
|
2011-07-12 02:46:36 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 flags;
|
2012-12-17 19:20:25 +04:00
|
|
|
WCHAR* domain = NULL;
|
|
|
|
int cbDomain = 0;
|
|
|
|
WCHAR* userName = NULL;
|
|
|
|
int cbUserName = 0;
|
|
|
|
WCHAR* password = NULL;
|
|
|
|
int cbPassword = 0;
|
|
|
|
WCHAR* alternateShell = NULL;
|
|
|
|
int cbAlternateShell = 0;
|
|
|
|
WCHAR* workingDir = NULL;
|
|
|
|
int cbWorkingDir = 0;
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL usedPasswordCookie = FALSE;
|
2011-07-12 02:46:36 +04:00
|
|
|
|
|
|
|
flags = INFO_MOUSE |
|
|
|
|
INFO_UNICODE |
|
|
|
|
INFO_LOGONERRORS |
|
|
|
|
INFO_LOGONNOTIFY |
|
|
|
|
INFO_MAXIMIZESHELL |
|
|
|
|
INFO_ENABLEWINDOWSKEY |
|
2012-03-13 13:05:14 +04:00
|
|
|
INFO_DISABLECTRLALTDEL;
|
|
|
|
|
2012-11-08 00:13:14 +04:00
|
|
|
if (settings->AudioCapture)
|
2012-03-13 13:05:14 +04:00
|
|
|
flags |= RNS_INFO_AUDIOCAPTURE;
|
|
|
|
|
2012-11-08 00:13:14 +04:00
|
|
|
if (!settings->AudioPlayback)
|
2012-03-13 13:05:14 +04:00
|
|
|
flags |= INFO_NOAUDIOPLAYBACK;
|
2011-07-12 02:46:36 +04:00
|
|
|
|
2012-11-08 03:23:25 +04:00
|
|
|
if (settings->AutoLogonEnabled)
|
2011-07-12 02:46:36 +04:00
|
|
|
flags |= INFO_AUTOLOGON;
|
|
|
|
|
2012-11-08 00:13:14 +04:00
|
|
|
if (settings->RemoteApplicationMode)
|
2011-08-08 23:06:07 +04:00
|
|
|
flags |= INFO_RAIL;
|
|
|
|
|
2012-11-08 03:23:25 +04:00
|
|
|
if (settings->RemoteConsoleAudio)
|
2011-07-12 02:46:36 +04:00
|
|
|
flags |= INFO_REMOTECONSOLEAUDIO;
|
|
|
|
|
2012-11-08 03:23:25 +04:00
|
|
|
if (settings->CompressionEnabled)
|
2012-03-21 21:18:40 +04:00
|
|
|
flags |= INFO_COMPRESSION | INFO_PACKET_COMPR_TYPE_RDP6;
|
2011-07-12 02:46:36 +04:00
|
|
|
|
2012-11-08 00:13:14 +04:00
|
|
|
if (settings->Domain)
|
2012-09-24 03:49:13 +04:00
|
|
|
{
|
2012-12-17 19:20:25 +04:00
|
|
|
cbDomain = ConvertToUnicode(CP_UTF8, 0, settings->Domain, -1, &domain, 0) * 2;
|
2012-09-24 03:49:13 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
domain = NULL;
|
|
|
|
cbDomain = 0;
|
|
|
|
}
|
2011-07-12 02:46:36 +04:00
|
|
|
|
2012-12-17 19:20:25 +04:00
|
|
|
cbUserName = ConvertToUnicode(CP_UTF8, 0, settings->Username, -1, &userName, 0) * 2;
|
2011-07-12 02:46:36 +04:00
|
|
|
|
2012-11-08 20:16:54 +04:00
|
|
|
if (settings->RedirectionPassword && settings->RedirectionPasswordLength > 0)
|
2012-01-31 05:54:46 +04:00
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
usedPasswordCookie = TRUE;
|
2012-11-08 20:16:54 +04:00
|
|
|
password = (WCHAR*) settings->RedirectionPassword;
|
|
|
|
cbPassword = settings->RedirectionPasswordLength - 2; /* Strip double zero termination */
|
2012-01-31 05:54:46 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-12-17 19:20:25 +04:00
|
|
|
cbPassword = ConvertToUnicode(CP_UTF8, 0, settings->Password, -1, &password, 0) * 2;
|
2012-01-31 05:54:46 +04:00
|
|
|
}
|
2011-07-12 02:46:36 +04:00
|
|
|
|
2012-12-17 19:20:25 +04:00
|
|
|
cbAlternateShell = ConvertToUnicode(CP_UTF8, 0, settings->AlternateShell, -1, &alternateShell, 0) * 2;
|
2011-07-12 02:46:36 +04:00
|
|
|
|
2012-12-17 19:20:25 +04:00
|
|
|
cbWorkingDir = ConvertToUnicode(CP_UTF8, 0, settings->ShellWorkingDirectory, -1, &workingDir, 0) * 2;
|
2011-07-12 02:46:36 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_write_UINT32(s, 0); /* CodePage */
|
|
|
|
stream_write_UINT32(s, flags); /* flags */
|
2011-07-12 02:46:36 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, cbDomain); /* cbDomain */
|
|
|
|
stream_write_UINT16(s, cbUserName); /* cbUserName */
|
|
|
|
stream_write_UINT16(s, cbPassword); /* cbPassword */
|
|
|
|
stream_write_UINT16(s, cbAlternateShell); /* cbAlternateShell */
|
|
|
|
stream_write_UINT16(s, cbWorkingDir); /* cbWorkingDir */
|
2011-07-12 02:46:36 +04:00
|
|
|
|
|
|
|
if (cbDomain > 0)
|
|
|
|
stream_write(s, domain, cbDomain);
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, 0);
|
2011-07-12 02:46:36 +04:00
|
|
|
|
|
|
|
if (cbUserName > 0)
|
|
|
|
stream_write(s, userName, cbUserName);
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, 0);
|
2011-07-12 02:46:36 +04:00
|
|
|
|
|
|
|
if (cbPassword > 0)
|
2012-03-16 23:47:34 +04:00
|
|
|
stream_write(s, password, cbPassword);
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, 0);
|
2011-07-12 02:46:36 +04:00
|
|
|
|
|
|
|
if (cbAlternateShell > 0)
|
|
|
|
stream_write(s, alternateShell, cbAlternateShell);
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, 0);
|
2011-07-12 02:46:36 +04:00
|
|
|
|
|
|
|
if (cbWorkingDir > 0)
|
|
|
|
stream_write(s, workingDir, cbWorkingDir);
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, 0);
|
2011-07-12 02:46:36 +04:00
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(domain);
|
|
|
|
free(userName);
|
|
|
|
free(alternateShell);
|
|
|
|
free(workingDir);
|
2011-07-12 02:46:36 +04:00
|
|
|
|
2012-02-01 20:58:06 +04:00
|
|
|
if (!usedPasswordCookie)
|
2012-10-09 07:21:26 +04:00
|
|
|
free(password);
|
2012-02-01 20:58:06 +04:00
|
|
|
|
2012-11-07 19:33:06 +04:00
|
|
|
if (settings->RdpVersion >= 5)
|
2011-07-12 02:46:36 +04:00
|
|
|
rdp_write_extended_info_packet(s, settings); /* extraInfo */
|
|
|
|
}
|
|
|
|
|
2011-08-20 14:22:14 +04:00
|
|
|
/**
|
|
|
|
* Read Client Info PDU (CLIENT_INFO_PDU).\n
|
|
|
|
* @msdn{cc240474}
|
|
|
|
* @param rdp RDP module
|
|
|
|
* @param s stream
|
|
|
|
*/
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL rdp_recv_client_info(rdpRdp* rdp, wStream* s)
|
2011-08-20 14:22:14 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 length;
|
|
|
|
UINT16 channelId;
|
|
|
|
UINT16 securityFlags;
|
2011-08-20 14:22:14 +04:00
|
|
|
|
|
|
|
if (!rdp_read_header(rdp, s, &length, &channelId))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-20 14:22:14 +04:00
|
|
|
|
2013-01-15 02:40:34 +04:00
|
|
|
if (!rdp_read_security_header(s, &securityFlags))
|
|
|
|
return FALSE;
|
|
|
|
|
2012-01-25 19:30:54 +04:00
|
|
|
if ((securityFlags & SEC_INFO_PKT) == 0)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-20 14:22:14 +04:00
|
|
|
|
2012-11-08 08:29:24 +04:00
|
|
|
if (rdp->settings->DisableEncryption)
|
2012-01-25 19:30:54 +04:00
|
|
|
{
|
|
|
|
if (securityFlags & SEC_REDIRECTION_PKT)
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "Error: SEC_REDIRECTION_PKT unsupported\n");
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-01-25 19:30:54 +04:00
|
|
|
}
|
2013-03-29 06:26:28 +04:00
|
|
|
|
2012-01-25 19:30:54 +04:00
|
|
|
if (securityFlags & SEC_ENCRYPT)
|
|
|
|
{
|
|
|
|
if (!rdp_decrypt(rdp, s, length - 4, securityFlags))
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "rdp_decrypt failed\n");
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-01-25 19:30:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-20 14:22:14 +04:00
|
|
|
return rdp_read_info_packet(s, rdp->settings);
|
|
|
|
}
|
|
|
|
|
2011-07-12 02:46:36 +04:00
|
|
|
/**
|
|
|
|
* Send Client Info PDU (CLIENT_INFO_PDU).\n
|
|
|
|
* @msdn{cc240474}
|
|
|
|
* @param rdp RDP module
|
|
|
|
*/
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL rdp_send_client_info(rdpRdp* rdp)
|
2011-07-12 02:46:36 +04:00
|
|
|
{
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* s;
|
2011-07-12 02:46:36 +04:00
|
|
|
|
2011-09-13 10:40:27 +04:00
|
|
|
//rdp->settings->crypt_flags |= SEC_INFO_PKT;
|
|
|
|
rdp->sec_flags |= SEC_INFO_PKT;
|
2011-07-12 02:46:36 +04:00
|
|
|
s = rdp_send_stream_init(rdp);
|
|
|
|
rdp_write_info_packet(s, rdp->settings);
|
2011-08-22 11:03:58 +04:00
|
|
|
return rdp_send(rdp, s, MCS_GLOBAL_CHANNEL_ID);
|
2011-07-12 02:46:36 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL rdp_recv_logon_info_v1(rdpRdp* rdp, wStream* s)
|
2011-07-25 21:42:14 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 cbDomain;
|
|
|
|
UINT32 cbUserName;
|
2011-07-25 21:42:14 +04:00
|
|
|
|
2013-03-29 06:26:28 +04:00
|
|
|
if (stream_get_left(s) < (4 + 52 + 4 + 512 + 4))
|
2013-01-11 04:18:11 +04:00
|
|
|
return FALSE;
|
2013-03-29 06:26:28 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_read_UINT32(s, cbDomain); /* cbDomain (4 bytes) */
|
2011-07-25 21:42:14 +04:00
|
|
|
stream_seek(s, 52); /* domain (52 bytes) */
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_read_UINT32(s, cbUserName); /* cbUserName (4 bytes) */
|
2011-07-25 21:42:14 +04:00
|
|
|
stream_seek(s, 512); /* userName (512 bytes) */
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_seek_UINT32(s); /* sessionId (4 bytes) */
|
2013-03-29 06:26:28 +04:00
|
|
|
|
2013-01-11 04:18:11 +04:00
|
|
|
return TRUE;
|
2011-07-25 21:42:14 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL rdp_recv_logon_info_v2(rdpRdp* rdp, wStream* s)
|
2011-07-25 21:42:14 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 cbDomain;
|
|
|
|
UINT32 cbUserName;
|
2011-07-25 21:42:14 +04:00
|
|
|
|
2013-03-29 06:26:28 +04:00
|
|
|
if (stream_get_left(s) < (2 + 4 + 4 + 4 + 4 + 558))
|
2013-01-11 04:18:11 +04:00
|
|
|
return FALSE;
|
2013-03-29 06:26:28 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_seek_UINT16(s); /* version (2 bytes) */
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_seek_UINT32(s); /* size (4 bytes) */
|
|
|
|
stream_seek_UINT32(s); /* sessionId (4 bytes) */
|
|
|
|
stream_read_UINT32(s, cbDomain); /* cbDomain (4 bytes) */
|
|
|
|
stream_read_UINT32(s, cbUserName); /* cbUserName (4 bytes) */
|
2011-07-25 21:42:14 +04:00
|
|
|
stream_seek(s, 558); /* pad */
|
2013-01-11 04:18:11 +04:00
|
|
|
|
2013-03-29 06:26:28 +04:00
|
|
|
if (stream_get_left(s) < cbDomain+cbUserName)
|
2013-01-11 04:18:11 +04:00
|
|
|
return FALSE;
|
2013-03-29 06:26:28 +04:00
|
|
|
|
2011-07-25 21:42:14 +04:00
|
|
|
stream_seek(s, cbDomain); /* domain */
|
|
|
|
stream_seek(s, cbUserName); /* userName */
|
2013-03-29 06:26:28 +04:00
|
|
|
|
2013-01-11 04:18:11 +04:00
|
|
|
return TRUE;
|
2011-07-25 21:42:14 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL rdp_recv_logon_plain_notify(rdpRdp* rdp, wStream* s)
|
2011-07-25 21:42:14 +04:00
|
|
|
{
|
2013-03-29 06:26:28 +04:00
|
|
|
if (stream_get_left(s) < 576)
|
2013-01-11 04:18:11 +04:00
|
|
|
return FALSE;
|
2013-03-29 06:26:28 +04:00
|
|
|
|
2011-07-25 21:42:14 +04:00
|
|
|
stream_seek(s, 576); /* pad */
|
2013-03-29 06:26:28 +04:00
|
|
|
|
2013-01-11 04:18:11 +04:00
|
|
|
return TRUE;
|
2011-07-25 21:42:14 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL rdp_recv_logon_error_info(rdpRdp* rdp, wStream* s)
|
2011-07-25 21:42:14 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 errorNotificationData;
|
2013-03-29 06:26:28 +04:00
|
|
|
UINT32 errorNotificationType;
|
2011-07-25 21:42:14 +04:00
|
|
|
|
2013-03-29 06:26:28 +04:00
|
|
|
if (stream_get_left(s) < 4)
|
2013-01-11 04:18:11 +04:00
|
|
|
return FALSE;
|
2013-03-29 06:26:28 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_read_UINT32(s, errorNotificationData); /* errorNotificationData (4 bytes) */
|
2013-03-29 06:26:28 +04:00
|
|
|
stream_read_UINT32(s, errorNotificationType); /* errorNotificationType (4 bytes) */
|
|
|
|
|
|
|
|
IFCALL(rdp->instance->LogonErrorInfo, rdp->instance, errorNotificationData, errorNotificationType);
|
|
|
|
|
2013-01-11 04:18:11 +04:00
|
|
|
return TRUE;
|
2011-07-25 21:42:14 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL rdp_recv_logon_info_extended(rdpRdp* rdp, wStream* s)
|
2011-07-25 21:42:14 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 cbFieldData;
|
|
|
|
UINT32 fieldsPresent;
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 Length;
|
2011-07-25 21:42:14 +04:00
|
|
|
|
2013-03-29 06:26:28 +04:00
|
|
|
if (stream_get_left(s) < 6)
|
2013-01-11 04:18:11 +04:00
|
|
|
return FALSE;
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_UINT16(s, Length); /* The total size in bytes of this structure */
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_read_UINT32(s, fieldsPresent); /* fieldsPresent (4 bytes) */
|
2011-07-25 21:42:14 +04:00
|
|
|
|
|
|
|
/* logonFields */
|
|
|
|
|
|
|
|
if (fieldsPresent & LOGON_EX_AUTORECONNECTCOOKIE)
|
|
|
|
{
|
2013-03-29 06:26:28 +04:00
|
|
|
if (stream_get_left(s) < 4)
|
2013-01-11 04:18:11 +04:00
|
|
|
return FALSE;
|
2013-03-29 06:26:28 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_read_UINT32(s, cbFieldData); /* cbFieldData (4 bytes) */
|
2013-03-29 06:26:28 +04:00
|
|
|
|
|
|
|
if (rdp_read_server_auto_reconnect_cookie(s, rdp->settings) == FALSE)
|
2013-01-11 04:18:11 +04:00
|
|
|
return FALSE;
|
2011-07-25 21:42:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fieldsPresent & LOGON_EX_LOGONERRORS)
|
|
|
|
{
|
2013-03-29 06:26:28 +04:00
|
|
|
if (stream_get_left(s) < 4)
|
2013-01-11 04:18:11 +04:00
|
|
|
return FALSE;
|
2013-03-29 06:26:28 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_read_UINT32(s, cbFieldData); /* cbFieldData (4 bytes) */
|
2013-03-29 06:26:28 +04:00
|
|
|
|
|
|
|
if (rdp_recv_logon_error_info(rdp, s) == FALSE)
|
2013-01-11 04:18:11 +04:00
|
|
|
return FALSE;
|
2011-07-25 21:42:14 +04:00
|
|
|
}
|
|
|
|
|
2013-03-29 06:26:28 +04:00
|
|
|
if (stream_get_left(s) < 570)
|
2013-01-11 04:18:11 +04:00
|
|
|
return FALSE;
|
2013-03-29 06:26:28 +04:00
|
|
|
|
2011-07-25 21:42:14 +04:00
|
|
|
stream_seek(s, 570); /* pad */
|
2013-03-29 06:26:28 +04:00
|
|
|
|
2013-01-11 04:18:11 +04:00
|
|
|
return TRUE;
|
2011-07-25 21:42:14 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL rdp_recv_save_session_info(rdpRdp* rdp, wStream* s)
|
2011-07-25 21:42:14 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 infoType;
|
2011-07-25 21:42:14 +04:00
|
|
|
|
2013-03-29 06:26:28 +04:00
|
|
|
if (stream_get_left(s) < 4)
|
2013-01-11 04:18:11 +04:00
|
|
|
return FALSE;
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_read_UINT32(s, infoType); /* infoType (4 bytes) */
|
2011-07-25 21:42:14 +04:00
|
|
|
|
2013-03-29 02:06:34 +04:00
|
|
|
//fprintf(stderr, "%s\n", INFO_TYPE_LOGON_STRINGS[infoType]);
|
2011-07-25 21:42:14 +04:00
|
|
|
|
|
|
|
switch (infoType)
|
|
|
|
{
|
|
|
|
case INFO_TYPE_LOGON:
|
2013-01-11 04:18:11 +04:00
|
|
|
return rdp_recv_logon_info_v1(rdp, s);
|
2011-07-25 21:42:14 +04:00
|
|
|
|
|
|
|
case INFO_TYPE_LOGON_LONG:
|
2013-01-11 04:18:11 +04:00
|
|
|
return rdp_recv_logon_info_v2(rdp, s);
|
2011-07-25 21:42:14 +04:00
|
|
|
|
|
|
|
case INFO_TYPE_LOGON_PLAIN_NOTIFY:
|
2013-01-11 04:18:11 +04:00
|
|
|
return rdp_recv_logon_plain_notify(rdp, s);
|
2011-07-25 21:42:14 +04:00
|
|
|
|
|
|
|
case INFO_TYPE_LOGON_EXTENDED_INF:
|
2013-01-11 04:18:11 +04:00
|
|
|
return rdp_recv_logon_info_extended(rdp, s);
|
2011-07-25 21:42:14 +04:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-08-22 13:49:39 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-07-25 21:42:14 +04:00
|
|
|
}
|
|
|
|
|