libfreerdp-core: refactoring of RDP module

This commit is contained in:
Marc-André Moreau 2011-07-11 18:46:36 -04:00
parent e38ad39ef0
commit 297334bae2
13 changed files with 620 additions and 455 deletions

View File

@ -27,11 +27,11 @@
int main(int argc, char* argv[])
{
rdpRdp* rdp;
rdpSettings* settings;
rdpConnection* connection;
settings = settings_new();
connection = connection_new(settings);
rdp = rdp_new();
settings = rdp->settings;
if (argc < 4)
{
@ -54,7 +54,7 @@ int main(int argc, char* argv[])
printf("hostname: %s username: %s password: %s\n",
settings->hostname, settings->username, settings->password);
connection_client_connect(connection);
rdp_client_connect(rdp);
return 0;
}

View File

@ -28,12 +28,16 @@ set(LIBFREERDP_CORE_SRCS
mcs.h
nego.c
nego.h
info.c
info.h
crypto.c
crypto.h
credssp.c
credssp.h
ntlmssp.c
ntlmssp.h
security.c
security.h
settings.c
connection.c
connection.h

View File

@ -52,407 +52,24 @@
/**
* Establish RDP Connection.\n
* @msdn{cc240452}
* @param connection
* @param rdp RDP module
*/
void connection_client_connect(rdpConnection* connection)
void rdp_client_connect(rdpRdp* rdp)
{
STREAM* s;
rdp->settings->autologon = 1;
connection->settings->autologon = 1;
connection->transport = transport_new(connection->settings);
connection->nego = nego_new(connection->transport);
nego_init(rdp->nego);
nego_set_target(rdp->nego, rdp->settings->hostname, 3389);
nego_set_cookie(rdp->nego, rdp->settings->username);
nego_set_protocols(rdp->nego, 1, 1, 1);
nego_connect(rdp->nego);
nego_init(connection->nego);
nego_set_target(connection->nego, connection->settings->hostname, 3389);
nego_set_cookie(connection->nego, connection->settings->username);
nego_set_protocols(connection->nego, 1, 1, 1);
nego_connect(connection->nego);
transport_connect_nla(rdp->transport);
transport_connect_nla(connection->transport);
mcs_connect(rdp->mcs);
connection->mcs = mcs_new(connection->transport);
mcs_connect(connection->mcs);
connection_send_client_info(connection);
connection_recv_license_info(connection);
rdp_send_client_info(rdp);
rdp_recv(rdp);
}
/**
* Write SYSTEM_TIME structure (TS_SYSTEMTIME).\n
* @msdn{cc240478}
* @param s stream
* @param system_time system time structure
*/
void connection_write_system_time(STREAM* s, SYSTEM_TIME* system_time)
{
stream_write_uint16(s, system_time->wYear); /* wYear, must be set to 0 */
stream_write_uint16(s, system_time->wMonth); /* wMonth */
stream_write_uint16(s, system_time->wDayOfWeek); /* wDayOfWeek */
stream_write_uint16(s, system_time->wDay); /* wDay */
stream_write_uint16(s, system_time->wHour); /* wHour */
stream_write_uint16(s, system_time->wMinute); /* wMinute */
stream_write_uint16(s, system_time->wSecond); /* wSecond */
stream_write_uint16(s, system_time->wMilliseconds); /* wMilliseconds */
}
/**
* Get client time zone information.\n
* @param s stream
* @param settings settings
*/
void connection_get_client_time_zone(STREAM* s, rdpSettings* settings)
{
time_t t;
struct tm* local_time;
TIME_ZONE_INFORMATION* clientTimeZone;
time(&t);
local_time = localtime(&t);
clientTimeZone = &settings->client_time_zone;
#if defined(sun)
if(local_time->tm_isdst > 0)
clientTimeZone->bias = (uint32) (altzone / 3600);
else
clientTimeZone->bias = (uint32) (timezone / 3600);
#elif defined(HAVE_TM_GMTOFF)
if(local_time->tm_gmtoff >= 0)
clientTimeZone->bias = (uint32) (local_time->tm_gmtoff / 60);
else
clientTimeZone->bias = (uint32) ((-1 * local_time->tm_gmtoff) / 60 + 720);
#else
clientTimeZone->bias = 0;
#endif
if(local_time->tm_isdst > 0)
{
clientTimeZone->standardBias = clientTimeZone->bias - 60;
clientTimeZone->daylightBias = clientTimeZone->bias;
}
else
{
clientTimeZone->standardBias = clientTimeZone->bias;
clientTimeZone->daylightBias = clientTimeZone->bias + 60;
}
strftime(clientTimeZone->standardName, 32, "%Z, Standard Time", local_time);
clientTimeZone->standardName[31] = 0;
strftime(clientTimeZone->daylightName, 32, "%Z, Summer Time", local_time);
clientTimeZone->daylightName[31] = 0;
}
/**
* Write client time zone information (TS_TIME_ZONE_INFORMATION).\n
* @msdn{cc240477}
* @param s stream
* @param settings settings
*/
void connection_write_client_time_zone(STREAM* s, rdpSettings* settings)
{
size_t length;
uint8* standardName;
uint8* daylightName;
size_t standardNameLength;
size_t daylightNameLength;
TIME_ZONE_INFORMATION* clientTimeZone;
connection_get_client_time_zone(s, settings);
clientTimeZone = &settings->client_time_zone;
standardName = freerdp_uniconv_out(settings->uniconv, clientTimeZone->standardName, &length);
standardNameLength = length;
daylightName = freerdp_uniconv_out(settings->uniconv, clientTimeZone->daylightName, &length);
daylightNameLength = length;
if (standardNameLength > 62)
standardNameLength = 62;
if (daylightNameLength > 62)
daylightNameLength = 62;
stream_write_uint32(s, clientTimeZone->bias); /* Bias */
/* standardName (64 bytes) */
stream_write(s, standardName, standardNameLength);
stream_write_zero(s, 64 - standardNameLength);
connection_write_system_time(s, &clientTimeZone->standardDate); /* StandardDate */
stream_write_uint32(s, clientTimeZone->standardBias); /* StandardBias */
/* daylightName (64 bytes) */
stream_write(s, daylightName, daylightNameLength);
stream_write_zero(s, 64 - daylightNameLength);
connection_write_system_time(s, &clientTimeZone->daylightDate); /* DaylightDate */
stream_write_uint32(s, clientTimeZone->daylightBias); /* DaylightBias */
xfree(standardName);
xfree(daylightName);
}
/**
* Write Auto Reconnect Cookie (ARC_CS_PRIVATE_PACKET).\n
* @msdn{cc240541}
* @param s stream
* @param settings settings
*/
void connection_write_auto_reconnect_cookie(STREAM* s, rdpSettings* settings)
{
ARC_CS_PRIVATE_PACKET* autoReconnectCookie;
autoReconnectCookie = &settings->auto_reconnect_cookie;
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) */
stream_write(s, autoReconnectCookie->securityVerifier, 16); /* SecurityVerifier */
}
/**
* Write Extended Info Packet (TS_EXTENDED_INFO_PACKET).\n
* @msdn{cc240476}
* @param s stream
* @param settings settings
*/
void connection_write_extended_info_packet(STREAM* s, rdpSettings* settings)
{
size_t length;
uint16 clientAddressFamily;
uint8* clientAddress;
uint16 cbClientAddress;
uint8* clientDir;
uint16 cbClientDir;
uint16 cbAutoReconnectLen;
clientAddressFamily = settings->ipv6 ? ADDRESS_FAMILY_INET6 : ADDRESS_FAMILY_INET;
clientAddress = freerdp_uniconv_out(settings->uniconv, settings->ip_address, &length);
cbClientAddress = length;
clientDir = freerdp_uniconv_out(settings->uniconv, settings->client_dir, &length);
cbClientDir = length;
cbAutoReconnectLen = settings->auto_reconnect_cookie.cbLen;
stream_write_uint16(s, clientAddressFamily); /* clientAddressFamily */
stream_write_uint16(s, cbClientAddress + 2); /* cbClientAddress */
if (cbClientAddress > 0)
stream_write(s, clientAddress, cbClientAddress); /* clientAddress */
stream_write_uint16(s, 0);
stream_write_uint16(s, cbClientDir + 2); /* cbClientDir */
if (cbClientDir > 0)
stream_write(s, clientDir, cbClientDir); /* clientDir */
stream_write_uint16(s, 0);
connection_write_client_time_zone(s, settings); /* clientTimeZone */
stream_write_uint32(s, 0); /* clientSessionId, should be set to 0 */
stream_write_uint32(s, settings->performance_flags); /* performanceFlags */
stream_write_uint16(s, cbAutoReconnectLen); /* cbAutoReconnectLen */
if (cbAutoReconnectLen > 0)
connection_write_auto_reconnect_cookie(s, settings); /* autoReconnectCookie */
/* reserved1 (2 bytes) */
/* reserved2 (2 bytes) */
xfree(clientAddress);
xfree(clientDir);
}
/**
* Write Info Packet (TS_INFO_PACKET).\n
* @msdn{cc240475}
* @param s stream
* @param settings settings
*/
void connection_write_info_packet(STREAM* s, rdpSettings* settings)
{
size_t length;
uint32 flags;
uint8* domain;
uint16 cbDomain;
uint8* userName;
uint16 cbUserName;
uint8* password;
uint16 cbPassword;
uint8* alternateShell;
uint16 cbAlternateShell;
uint8* workingDir;
uint16 cbWorkingDir;
flags = INFO_MOUSE |
INFO_UNICODE |
INFO_LOGONERRORS |
INFO_LOGONNOTIFY |
INFO_MAXIMIZESHELL |
INFO_ENABLEWINDOWSKEY |
INFO_DISABLECTRLALTDEL |
RNS_INFO_AUDIOCAPTURE;
if (settings->autologon)
flags |= INFO_AUTOLOGON;
if (settings->console_audio)
flags |= INFO_REMOTECONSOLEAUDIO;
if (settings->compression)
flags |= INFO_COMPRESSION | PACKET_COMPR_TYPE_64K;
domain = freerdp_uniconv_out(settings->uniconv, settings->domain, &length);
cbDomain = length;
userName = freerdp_uniconv_out(settings->uniconv, settings->username, &length);
cbUserName = length;
password = freerdp_uniconv_out(settings->uniconv, settings->password, &length);
cbPassword = length;
alternateShell = freerdp_uniconv_out(settings->uniconv, settings->shell, &length);
cbAlternateShell = length;
workingDir = freerdp_uniconv_out(settings->uniconv, settings->directory, &length);
cbWorkingDir = length;
stream_write_uint32(s, 0); /* CodePage */
stream_write_uint32(s, flags); /* flags */
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 */
if (cbDomain > 0)
stream_write(s, domain, cbDomain);
stream_write_uint16(s, 0);
if (cbUserName > 0)
stream_write(s, userName, cbUserName);
stream_write_uint16(s, 0);
if (cbPassword > 0)
stream_write(s, password, cbPassword);
stream_write_uint16(s, 0);
if (cbAlternateShell > 0)
stream_write(s, alternateShell, cbAlternateShell);
stream_write_uint16(s, 0);
if (cbWorkingDir > 0)
stream_write(s, workingDir, cbWorkingDir);
stream_write_uint16(s, 0);
xfree(domain);
xfree(userName);
xfree(password);
xfree(alternateShell);
xfree(workingDir);
if (settings->rdp_version >= 5)
connection_write_extended_info_packet(s, settings); /* extraInfo */
}
/**
* Send Client Info PDU (CLIENT_INFO_PDU).\n
* @msdn{cc240474}
* @param connection connection module
*/
void connection_send_client_info(rdpConnection* connection)
{
STREAM* s;
int length;
uint8 *bm, *em;
s = transport_send_stream_init(connection->transport, 1024);
stream_get_mark(s, bm);
stream_seek(s, 15);
rdp_write_security_header(s, SEC_INFO_PKT);
connection_write_info_packet(s, connection->settings);
stream_get_mark(s, em);
length = (em - bm);
stream_set_mark(s, bm);
mcs_write_domain_mcspdu_header(s, DomainMCSPDU_SendDataRequest, length);
per_write_integer16(s, connection->mcs->user_id, MCS_BASE_CHANNEL_ID); /* initiator */
per_write_integer16(s, MCS_GLOBAL_CHANNEL_ID, 0); /* channelId */
stream_write_uint8(s, 0x70); /* dataPriority + segmentation */
per_write_length(s, length - 15); /* userData (OCTET_STRING) */
stream_set_mark(s, em);
transport_write(connection->transport, s);
}
void connection_recv_license_info(rdpConnection* connection)
{
STREAM* s;
int length;
int pduLength;
uint16 initiator;
uint16 channelId;
enum DomainMCSPDU MCSPDU;
s = transport_recv_stream_init(connection->transport, 4096);
transport_read(connection->transport, s);
MCSPDU = DomainMCSPDU_SendDataIndication;
mcs_read_domain_mcspdu_header(s, &MCSPDU, &length);
per_read_integer16(s, &initiator, MCS_BASE_CHANNEL_ID); /* initiator (UserId) */
per_read_integer16(s, &channelId, 0); /* channelId */
stream_seek(s, 1); /* dataPriority + Segmentation (0x70) */
per_read_length(s, &pduLength); /* userData (OCTET_STRING) */
printf("initiator:%d channelId:%d pduLength:%d\n", initiator, channelId, pduLength);
}
/**
* Instantiate new connection module.
* @return new connection module
*/
rdpConnection* connection_new(rdpSettings* settings)
{
rdpConnection* connection;
connection = (rdpConnection*) xzalloc(sizeof(rdpConnection));
if (connection != NULL)
{
connection->settings = settings;
}
return connection;
}
/**
* Free connection module.
* @param connection connect module to be freed
*/
void connection_free(rdpConnection* connection)
{
if (connection != NULL)
{
xfree(connection);
}
}

View File

@ -30,57 +30,6 @@
#include <freerdp/settings.h>
#include <freerdp/utils/memory.h>
/* Client Address Family */
#define ADDRESS_FAMILY_INET 0x0002
#define ADDRESS_FAMILY_INET6 0x0017
/* Client Info Packet Flags */
#define INFO_MOUSE 0x00000001
#define INFO_DISABLECTRLALTDEL 0x00000002
#define INFO_AUTOLOGON 0x00000008
#define INFO_UNICODE 0x00000010
#define INFO_MAXIMIZESHELL 0x00000020
#define INFO_LOGONNOTIFY 0x00000040
#define INFO_COMPRESSION 0x00000080
#define INFO_ENABLEWINDOWSKEY 0x00000100
#define INFO_REMOTECONSOLEAUDIO 0x00002000
#define INFO_FORCE_ENCRYPTED_CS_PDU 0x00004000
#define INFO_RAIL 0x00008000
#define INFO_LOGONERRORS 0x00010000
#define INFO_MOUSE_HAS_WHEEL 0x00020000
#define INFO_PASSWORD_IS_SC_PIN 0x00040000
#define INFO_NOAUDIOPLAYBACK 0x00080000
#define INFO_USING_SAVED_CREDS 0x00100000
#define RNS_INFO_AUDIOCAPTURE 0x00200000
#define RNS_INFO_VIDEO_DISABLE 0x00400000
#define CompressionTypeMask 0x00001E00
#define PACKET_COMPR_TYPE_8K 0x00000100
#define PACKET_COMPR_TYPE_64K 0x00000200
#define PACKET_COMPR_TYPE_RDP6 0x00000300
#define PACKET_COMPR_TYPE_RDP61 0x00000400
struct rdp_connection
{
struct rdp_mcs* mcs;
struct rdp_nego* nego;
struct rdp_settings* settings;
struct rdp_transport* transport;
};
typedef struct rdp_connection rdpConnection;
void connection_client_connect(rdpConnection* connection);
void connection_send_client_info(rdpConnection* connection);
void connection_recv_license_info(rdpConnection* connection);
void connection_write_system_time(STREAM* s, SYSTEM_TIME* system_time);
void connection_get_client_time_zone(STREAM* s, rdpSettings* settings);
void connection_write_client_time_zone(STREAM* s, rdpSettings* settings);
void connection_write_info_packet(STREAM* s, rdpSettings* settings);
void connection_write_extended_info_packet(STREAM* s, rdpSettings* settings);
void connection_write_auto_reconnect_cookie(STREAM* s, rdpSettings* settings);
rdpConnection* connection_new(rdpSettings* settings);
void connection_free(rdpConnection* connection);
void rdp_client_connect(rdpRdp* rdp);
#endif /* __CONNECTION_H */

326
libfreerdp-core/info.c Normal file
View File

@ -0,0 +1,326 @@
/**
* FreeRDP: A Remote Desktop Protocol Client
* 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.
*/
#include "info.h"
/**
* Write SYSTEM_TIME structure (TS_SYSTEMTIME).\n
* @msdn{cc240478}
* @param s stream
* @param system_time system time structure
*/
void rdp_write_system_time(STREAM* s, SYSTEM_TIME* system_time)
{
stream_write_uint16(s, system_time->wYear); /* wYear, must be set to 0 */
stream_write_uint16(s, system_time->wMonth); /* wMonth */
stream_write_uint16(s, system_time->wDayOfWeek); /* wDayOfWeek */
stream_write_uint16(s, system_time->wDay); /* wDay */
stream_write_uint16(s, system_time->wHour); /* wHour */
stream_write_uint16(s, system_time->wMinute); /* wMinute */
stream_write_uint16(s, system_time->wSecond); /* wSecond */
stream_write_uint16(s, system_time->wMilliseconds); /* wMilliseconds */
}
/**
* Get client time zone information.\n
* @param s stream
* @param settings settings
*/
void rdp_get_client_time_zone(STREAM* s, rdpSettings* settings)
{
time_t t;
struct tm* local_time;
TIME_ZONE_INFORMATION* clientTimeZone;
time(&t);
local_time = localtime(&t);
clientTimeZone = &settings->client_time_zone;
#if defined(sun)
if(local_time->tm_isdst > 0)
clientTimeZone->bias = (uint32) (altzone / 3600);
else
clientTimeZone->bias = (uint32) (timezone / 3600);
#elif defined(HAVE_TM_GMTOFF)
if(local_time->tm_gmtoff >= 0)
clientTimeZone->bias = (uint32) (local_time->tm_gmtoff / 60);
else
clientTimeZone->bias = (uint32) ((-1 * local_time->tm_gmtoff) / 60 + 720);
#else
clientTimeZone->bias = 0;
#endif
if(local_time->tm_isdst > 0)
{
clientTimeZone->standardBias = clientTimeZone->bias - 60;
clientTimeZone->daylightBias = clientTimeZone->bias;
}
else
{
clientTimeZone->standardBias = clientTimeZone->bias;
clientTimeZone->daylightBias = clientTimeZone->bias + 60;
}
strftime(clientTimeZone->standardName, 32, "%Z, Standard Time", local_time);
clientTimeZone->standardName[31] = 0;
strftime(clientTimeZone->daylightName, 32, "%Z, Summer Time", local_time);
clientTimeZone->daylightName[31] = 0;
}
/**
* Write client time zone information (TS_TIME_ZONE_INFORMATION).\n
* @msdn{cc240477}
* @param s stream
* @param settings settings
*/
void rdp_write_client_time_zone(STREAM* s, rdpSettings* settings)
{
size_t length;
uint8* standardName;
uint8* daylightName;
size_t standardNameLength;
size_t daylightNameLength;
TIME_ZONE_INFORMATION* clientTimeZone;
rdp_get_client_time_zone(s, settings);
clientTimeZone = &settings->client_time_zone;
standardName = freerdp_uniconv_out(settings->uniconv, clientTimeZone->standardName, &length);
standardNameLength = length;
daylightName = freerdp_uniconv_out(settings->uniconv, clientTimeZone->daylightName, &length);
daylightNameLength = length;
if (standardNameLength > 62)
standardNameLength = 62;
if (daylightNameLength > 62)
daylightNameLength = 62;
stream_write_uint32(s, clientTimeZone->bias); /* Bias */
/* standardName (64 bytes) */
stream_write(s, standardName, standardNameLength);
stream_write_zero(s, 64 - standardNameLength);
rdp_write_system_time(s, &clientTimeZone->standardDate); /* StandardDate */
stream_write_uint32(s, clientTimeZone->standardBias); /* StandardBias */
/* daylightName (64 bytes) */
stream_write(s, daylightName, daylightNameLength);
stream_write_zero(s, 64 - daylightNameLength);
rdp_write_system_time(s, &clientTimeZone->daylightDate); /* DaylightDate */
stream_write_uint32(s, clientTimeZone->daylightBias); /* DaylightBias */
xfree(standardName);
xfree(daylightName);
}
/**
* Write Auto Reconnect Cookie (ARC_CS_PRIVATE_PACKET).\n
* @msdn{cc240541}
* @param s stream
* @param settings settings
*/
void rdp_write_auto_reconnect_cookie(STREAM* s, rdpSettings* settings)
{
ARC_CS_PRIVATE_PACKET* autoReconnectCookie;
autoReconnectCookie = &settings->auto_reconnect_cookie;
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) */
stream_write(s, autoReconnectCookie->securityVerifier, 16); /* SecurityVerifier */
}
/**
* Write Extended Info Packet (TS_EXTENDED_INFO_PACKET).\n
* @msdn{cc240476}
* @param s stream
* @param settings settings
*/
void rdp_write_extended_info_packet(STREAM* s, rdpSettings* settings)
{
size_t length;
uint16 clientAddressFamily;
uint8* clientAddress;
uint16 cbClientAddress;
uint8* clientDir;
uint16 cbClientDir;
uint16 cbAutoReconnectLen;
clientAddressFamily = settings->ipv6 ? ADDRESS_FAMILY_INET6 : ADDRESS_FAMILY_INET;
clientAddress = freerdp_uniconv_out(settings->uniconv, settings->ip_address, &length);
cbClientAddress = length;
clientDir = freerdp_uniconv_out(settings->uniconv, settings->client_dir, &length);
cbClientDir = length;
cbAutoReconnectLen = settings->auto_reconnect_cookie.cbLen;
stream_write_uint16(s, clientAddressFamily); /* clientAddressFamily */
stream_write_uint16(s, cbClientAddress + 2); /* cbClientAddress */
if (cbClientAddress > 0)
stream_write(s, clientAddress, cbClientAddress); /* clientAddress */
stream_write_uint16(s, 0);
stream_write_uint16(s, cbClientDir + 2); /* cbClientDir */
if (cbClientDir > 0)
stream_write(s, clientDir, cbClientDir); /* clientDir */
stream_write_uint16(s, 0);
rdp_write_client_time_zone(s, settings); /* clientTimeZone */
stream_write_uint32(s, 0); /* clientSessionId, should be set to 0 */
stream_write_uint32(s, settings->performance_flags); /* performanceFlags */
stream_write_uint16(s, cbAutoReconnectLen); /* cbAutoReconnectLen */
if (cbAutoReconnectLen > 0)
rdp_write_auto_reconnect_cookie(s, settings); /* autoReconnectCookie */
/* reserved1 (2 bytes) */
/* reserved2 (2 bytes) */
xfree(clientAddress);
xfree(clientDir);
}
/**
* Write Info Packet (TS_INFO_PACKET).\n
* @msdn{cc240475}
* @param s stream
* @param settings settings
*/
void rdp_write_info_packet(STREAM* s, rdpSettings* settings)
{
size_t length;
uint32 flags;
uint8* domain;
uint16 cbDomain;
uint8* userName;
uint16 cbUserName;
uint8* password;
uint16 cbPassword;
uint8* alternateShell;
uint16 cbAlternateShell;
uint8* workingDir;
uint16 cbWorkingDir;
flags = INFO_MOUSE |
INFO_UNICODE |
INFO_LOGONERRORS |
INFO_LOGONNOTIFY |
INFO_MAXIMIZESHELL |
INFO_ENABLEWINDOWSKEY |
INFO_DISABLECTRLALTDEL |
RNS_INFO_AUDIOCAPTURE;
if (settings->autologon)
flags |= INFO_AUTOLOGON;
if (settings->console_audio)
flags |= INFO_REMOTECONSOLEAUDIO;
if (settings->compression)
flags |= INFO_COMPRESSION | PACKET_COMPR_TYPE_64K;
domain = freerdp_uniconv_out(settings->uniconv, settings->domain, &length);
cbDomain = length;
userName = freerdp_uniconv_out(settings->uniconv, settings->username, &length);
cbUserName = length;
password = freerdp_uniconv_out(settings->uniconv, settings->password, &length);
cbPassword = length;
alternateShell = freerdp_uniconv_out(settings->uniconv, settings->shell, &length);
cbAlternateShell = length;
workingDir = freerdp_uniconv_out(settings->uniconv, settings->directory, &length);
cbWorkingDir = length;
stream_write_uint32(s, 0); /* CodePage */
stream_write_uint32(s, flags); /* flags */
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 */
if (cbDomain > 0)
stream_write(s, domain, cbDomain);
stream_write_uint16(s, 0);
if (cbUserName > 0)
stream_write(s, userName, cbUserName);
stream_write_uint16(s, 0);
if (cbPassword > 0)
stream_write(s, password, cbPassword);
stream_write_uint16(s, 0);
if (cbAlternateShell > 0)
stream_write(s, alternateShell, cbAlternateShell);
stream_write_uint16(s, 0);
if (cbWorkingDir > 0)
stream_write(s, workingDir, cbWorkingDir);
stream_write_uint16(s, 0);
xfree(domain);
xfree(userName);
xfree(password);
xfree(alternateShell);
xfree(workingDir);
if (settings->rdp_version >= 5)
rdp_write_extended_info_packet(s, settings); /* extraInfo */
}
/**
* Send Client Info PDU (CLIENT_INFO_PDU).\n
* @msdn{cc240474}
* @param rdp RDP module
*/
void rdp_send_client_info(rdpRdp* rdp)
{
STREAM* s;
s = rdp_send_stream_init(rdp);
rdp_write_security_header(s, SEC_INFO_PKT);
rdp_write_info_packet(s, rdp->settings);
rdp_send(rdp, s);
}

65
libfreerdp-core/info.h Normal file
View File

@ -0,0 +1,65 @@
/**
* FreeRDP: A Remote Desktop Protocol Client
* 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.
*/
#ifndef __INFO_H
#define __INFO_H
#include "rdp.h"
#include <freerdp/freerdp.h>
#include <freerdp/utils/stream.h>
/* Client Address Family */
#define ADDRESS_FAMILY_INET 0x0002
#define ADDRESS_FAMILY_INET6 0x0017
/* Client Info Packet Flags */
#define INFO_MOUSE 0x00000001
#define INFO_DISABLECTRLALTDEL 0x00000002
#define INFO_AUTOLOGON 0x00000008
#define INFO_UNICODE 0x00000010
#define INFO_MAXIMIZESHELL 0x00000020
#define INFO_LOGONNOTIFY 0x00000040
#define INFO_COMPRESSION 0x00000080
#define INFO_ENABLEWINDOWSKEY 0x00000100
#define INFO_REMOTECONSOLEAUDIO 0x00002000
#define INFO_FORCE_ENCRYPTED_CS_PDU 0x00004000
#define INFO_RAIL 0x00008000
#define INFO_LOGONERRORS 0x00010000
#define INFO_MOUSE_HAS_WHEEL 0x00020000
#define INFO_PASSWORD_IS_SC_PIN 0x00040000
#define INFO_NOAUDIOPLAYBACK 0x00080000
#define INFO_USING_SAVED_CREDS 0x00100000
#define RNS_INFO_AUDIOCAPTURE 0x00200000
#define RNS_INFO_VIDEO_DISABLE 0x00400000
#define CompressionTypeMask 0x00001E00
#define PACKET_COMPR_TYPE_8K 0x00000100
#define PACKET_COMPR_TYPE_64K 0x00000200
#define PACKET_COMPR_TYPE_RDP6 0x00000300
#define PACKET_COMPR_TYPE_RDP61 0x00000400
void rdp_write_system_time(STREAM* s, SYSTEM_TIME* system_time);
void rdp_get_client_time_zone(STREAM* s, rdpSettings* settings);
void rdp_write_client_time_zone(STREAM* s, rdpSettings* settings);
void rdp_write_auto_reconnect_cookie(STREAM* s, rdpSettings* settings);
void rdp_write_extended_info_packet(STREAM* s, rdpSettings* settings);
void rdp_write_info_packet(STREAM* s, rdpSettings* settings);
void rdp_send_client_info(rdpRdp* rdp);
#endif /* __INFO_H */

View File

@ -121,6 +121,8 @@ struct rdp_mcs
};
typedef struct rdp_mcs rdpMcs;
#define MCS_SEND_DATA_HEADER_LENGTH 8
#define MCS_TYPE_CONNECT_INITIAL 0x65
#define MCS_TYPE_CONNECT_RESPONSE 0x66

View File

@ -288,7 +288,7 @@ void nego_send_negotiation_request(rdpNego* nego)
uint8 *bm, *em;
s = stream_new(64);
length = TPKT_HEADER_LENGTH + TPDU_CONNECTION_REQUEST_LENGTH;
length = TPDU_CONNECTION_REQUEST_LENGTH;
stream_get_mark(s, bm);
stream_seek(s, length);

View File

@ -46,3 +46,108 @@ void rdp_write_security_header(STREAM* s, uint16 flags)
stream_write_uint16(s, flags); /* flags */
stream_write_uint16(s, 0); /* flagsHi (unused) */
}
STREAM* rdp_send_stream_init(rdpRdp* rdp)
{
STREAM* s;
s = transport_send_stream_init(rdp->transport, 1024);
stream_seek(s, RDP_PACKET_HEADER_LENGTH);
return s;
}
void rdp_send(rdpRdp* rdp, STREAM* s)
{
int length;
length = stream_get_length(s);
stream_set_pos(s, 0);
mcs_write_domain_mcspdu_header(s, DomainMCSPDU_SendDataRequest, length);
per_write_integer16(s, rdp->mcs->user_id, MCS_BASE_CHANNEL_ID); /* initiator */
per_write_integer16(s, MCS_GLOBAL_CHANNEL_ID, 0); /* channelId */
stream_write_uint8(s, 0x70); /* dataPriority + segmentation */
per_write_length(s, length - RDP_PACKET_HEADER_LENGTH); /* userData (OCTET_STRING) */
stream_set_pos(s, length);
transport_write(rdp->transport, s);
}
void rdp_recv(rdpRdp* rdp)
{
STREAM* s;
int length;
int pduLength;
uint16 initiator;
uint16 channelId;
uint16 sec_flags;
enum DomainMCSPDU MCSPDU;
s = transport_recv_stream_init(rdp->transport, 4096);
transport_read(rdp->transport, s);
MCSPDU = DomainMCSPDU_SendDataIndication;
mcs_read_domain_mcspdu_header(s, &MCSPDU, &length);
per_read_integer16(s, &initiator, MCS_BASE_CHANNEL_ID); /* initiator (UserId) */
per_read_integer16(s, &channelId, 0); /* channelId */
stream_seek(s, 1); /* dataPriority + Segmentation (0x70) */
per_read_length(s, &pduLength); /* userData (OCTET_STRING) */
rdp_read_security_header(s, &sec_flags);
if (sec_flags & SEC_PKT_MASK)
{
switch (sec_flags & SEC_PKT_MASK)
{
case SEC_LICENSE_PKT:
security_read_license_packet(s, sec_flags);
break;
case SEC_REDIRECTION_PKT:
security_read_redirection_packet(s, sec_flags);
break;
default:
printf("incorrect security flags: 0x%02X\n", sec_flags);
break;
}
}
}
/**
* Instantiate new RDP module.
* @return new RDP module
*/
rdpRdp* rdp_new()
{
rdpRdp* rdp;
rdp = (rdpRdp*) xzalloc(sizeof(rdpRdp));
if (rdp != NULL)
{
rdp->settings = settings_new();
rdp->transport = transport_new(rdp->settings);
rdp->nego = nego_new(rdp->transport);
rdp->mcs = mcs_new(rdp->transport);
}
return rdp;
}
/**
* Free RDP module.
* @param RDP connect module to be freed
*/
void rdp_free(rdpRdp* rdp)
{
if (rdp != NULL)
{
settings_free(rdp->settings);
xfree(rdp);
}
}

View File

@ -20,6 +20,16 @@
#ifndef __RDP_H
#define __RDP_H
typedef struct rdp_rdp rdpRdp;
#include "mcs.h"
#include "tpkt.h"
#include "tpdu.h"
#include "nego.h"
#include "security.h"
#include "transport.h"
#include "connection.h"
#include <freerdp/freerdp.h>
#include <freerdp/utils/stream.h>
@ -36,7 +46,29 @@
#define SEC_SECURE_CHECKSUM 0x0800
#define SEC_FLAGSHI_VALID 0x8000
#define SEC_PKT_CS_MASK (SEC_EXCHANGE_PKT | SEC_INFO_PKT)
#define SEC_PKT_SC_MASK (SEC_LICENSE_PKT | SEC_REDIRECTION_PKT)
#define SEC_PKT_MASK (SEC_PKT_CS_MASK | SEC_PKT_SC_MASK)
#define RDP_PACKET_HEADER_LENGTH (TPDU_DATA_LENGTH + MCS_SEND_DATA_HEADER_LENGTH)
struct rdp_rdp
{
struct rdp_mcs* mcs;
struct rdp_nego* nego;
struct rdp_settings* settings;
struct rdp_transport* transport;
};
void rdp_read_security_header(STREAM* s, uint16* flags);
void rdp_write_security_header(STREAM* s, uint16 flags);
STREAM* rdp_send_stream_init(rdpRdp* rdp);
void rdp_send(rdpRdp* rdp, STREAM* s);
void rdp_recv(rdpRdp* rdp);
rdpRdp* rdp_new();
void rdp_free(rdpRdp* rdp);
#endif /* __RDP_H */

View File

@ -0,0 +1,30 @@
/**
* FreeRDP: A Remote Desktop Protocol Client
* RDP Security
*
* 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.
*/
#include "security.h"
void security_read_license_packet(STREAM* s, uint16 sec_flags)
{
printf("SEC_LICENSE_PKT\n");
}
void security_read_redirection_packet(STREAM* s, uint16 sec_flags)
{
printf("SEC_REDIRECTION_PKT\n");
}

View File

@ -0,0 +1,29 @@
/**
* FreeRDP: A Remote Desktop Protocol Client
* RDP Security
*
* 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.
*/
#ifndef __SECURITY_H
#define __SECURITY_H
#include <freerdp/freerdp.h>
#include <freerdp/utils/stream.h>
void security_read_license_packet(STREAM* s, uint16 sec_flags);
void security_read_redirection_packet(STREAM* s, uint16 sec_flags);
#endif /* __SECURITY_H */

View File

@ -31,9 +31,15 @@ enum X224_TPDU_TYPE
X224_TPDU_ERROR = 0x70
};
#define TPDU_CONNECTION_REQUEST_LENGTH 7
#define TPDU_CONNECTION_CONFIRM_LENGTH 7
#define TPDU_DISCONNECT_REQUEST_LENGTH 7
#define TPDU_DATA_HEADER_LENGTH 3
#define TPDU_CONNECTION_REQUEST_HEADER_LENGTH 7
#define TPDU_CONNECTION_CONFIRM_HEADER_LENGTH 7
#define TPDU_DISCONNECT_REQUEST_HEADER_LENGTH 7
#define TPDU_DATA_LENGTH (TPKT_HEADER_LENGTH + TPDU_DATA_HEADER_LENGTH)
#define TPDU_CONNECTION_REQUEST_LENGTH (TPKT_HEADER_LENGTH + TPDU_CONNECTION_REQUEST_HEADER_LENGTH)
#define TPDU_CONNECTION_CONFIRM_LENGTH (TPKT_HEADER_LENGTH + TPDU_CONNECTION_CONFIRM_HEADER_LENGTH)
#define TPDU_DISCONNECT_REQUEST_LENGTH (TPKT_HEADER_LENGTH + TPDU_DISCONNECT_REQUEST_HEADER_LENGTH)
uint8 tpdu_read_header(STREAM* s, uint8* code);
void tpdu_write_header(STREAM* s, uint16 length, uint8 code);