diff --git a/cunit/test_freerdp.h b/cunit/test_freerdp.h index 436e959b0..d9d223043 100644 --- a/cunit/test_freerdp.h +++ b/cunit/test_freerdp.h @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include diff --git a/freerdp-ui/test/freerdp.c b/freerdp-ui/test/freerdp.c index 6a3b4fd61..f4207e40f 100644 --- a/freerdp-ui/test/freerdp.c +++ b/freerdp-ui/test/freerdp.c @@ -24,19 +24,24 @@ #include "nego.h" #include "transport.h" +#include #include -rdpNego * nego; -rdpTransport * transport; +rdpNego* nego; +rdpSettings* settings; +rdpTransport* transport; int main(int argc, char* argv[]) { char* username; char* hostname; - transport = transport_new((rdpSettings*) NULL); + char* password; + + settings = settings_new(); + transport = transport_new(settings); nego = nego_new(transport); - if (argc < 3) + if (argc < 4) { printf("Usage: freerdp-test \n"); return 0; @@ -50,15 +55,22 @@ int main(int argc, char* argv[]) memcpy(username, argv[2], strlen(argv[2])); username[strlen(argv[2])] = '\0'; - printf("hostname: %s username: %s\n", hostname, username); + password = (char*) xmalloc(strlen(argv[3])); + memcpy(password, argv[3], strlen(argv[3])); + password[strlen(argv[3])] = '\0'; + + printf("hostname: %s username: %s password: %s\n", + hostname, username, password); + + settings->password = password; nego_init(nego); nego_set_target(nego, hostname, 3389); - nego_set_protocols(nego, 1, 1, 0); + nego_set_protocols(nego, 1, 1, 1); nego_set_cookie(nego, username); nego_connect(nego); - transport_connect_tls(transport); + transport_connect_nla(transport); return 0; } diff --git a/include/freerdp/extension.h b/include/freerdp/extension.h index 91b25df3e..4ae0f9868 100644 --- a/include/freerdp/extension.h +++ b/include/freerdp/extension.h @@ -21,7 +21,7 @@ #define __RDP_EXTENSION_H #include -#include +#include /* Extensions ought to check for it to ensure compatibility */ #define RDPEXT_API 1 diff --git a/include/freerdp/freerdp.h b/include/freerdp/freerdp.h index 7e8eb09fd..b98c050f0 100644 --- a/include/freerdp/freerdp.h +++ b/include/freerdp/freerdp.h @@ -21,7 +21,7 @@ #define __FREERDP_H #include -#include +#include #include #include diff --git a/include/freerdp/kbd.h b/include/freerdp/kbd.h index 58c3f6281..8d7b0a1f3 100644 --- a/include/freerdp/kbd.h +++ b/include/freerdp/kbd.h @@ -20,7 +20,7 @@ #ifndef __FREERDP_KBD_H #define __FREERDP_KBD_H -#include +#include #define RDP_KEYBOARD_LAYOUT_TYPE_STANDARD 1 #define RDP_KEYBOARD_LAYOUT_TYPE_VARIANT 2 diff --git a/include/freerdp/settings.h b/include/freerdp/settings.h index 566cb96e3..10a8a6746 100644 --- a/include/freerdp/settings.h +++ b/include/freerdp/settings.h @@ -20,7 +20,7 @@ #ifndef __RDP_SETTINGS_H #define __RDP_SETTINGS_H -#include +#include struct rdp_chan { @@ -69,7 +69,8 @@ struct rdp_settings char hostname[16]; char server[64]; char domain[16]; - char password[64]; + char* password; + char shell[256]; char directory[256]; char username[256]; @@ -102,5 +103,9 @@ struct rdp_settings int software_gdi; struct rdp_ext_set extensions[16]; }; +typedef struct rdp_settings rdpSettings; + +rdpSettings* settings_new(); +void settings_free(rdpSettings* settings); #endif /* __RDP_SETTINGS_H */ diff --git a/include/freerdp/types/ui.h b/include/freerdp/types.h similarity index 75% rename from include/freerdp/types/ui.h rename to include/freerdp/types.h index a8a6995ed..eaa8a64cb 100644 --- a/include/freerdp/types/ui.h +++ b/include/freerdp/types.h @@ -1,8 +1,9 @@ /** * FreeRDP: A Remote Desktop Protocol Client - * User Interface Types + * Type Definitions * * Copyright 2009-2011 Jay Sorg + * Copyright 2011 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. @@ -17,10 +18,44 @@ * limitations under the License. */ -#ifndef __TYPES_UI_H -#define __TYPES_UI_H +#ifndef __RDP_TYPES_H +#define __RDP_TYPES_H -#include +/* Base Types */ + +typedef unsigned char uint8; +typedef signed char sint8; +typedef unsigned short uint16; +typedef signed short sint16; +typedef unsigned int uint32; +typedef signed int sint32; +#ifdef _WIN32 +typedef unsigned __int64 uint64; +typedef signed __int64 sint64; +#else +typedef unsigned long long uint64; +typedef signed long long sint64; +#endif + +#ifndef True +#define True (1) +#endif + +#ifndef False +#define False (0) +#endif + +typedef int boolean; + +#ifndef MIN +#define MIN(x,y) (((x) < (y)) ? (x) : (y)) +#endif + +#ifndef MAX +#define MAX(x,y) (((x) > (y)) ? (x) : (y)) +#endif + +#include typedef void *FRDP_HBITMAP; typedef void *FRDP_HGLYPH; @@ -129,12 +164,6 @@ struct _FRDP_REDRAW_EVENT }; typedef struct _FRDP_REDRAW_EVENT FRDP_REDRAW_EVENT; -/* defined in include/freerdp/freerdp.h */ -struct rdp_inst; typedef struct rdp_inst rdpInst; -/* defined in include/freerdp/settings.h */ -struct rdp_settings; -typedef struct rdp_settings rdpSettings; - -#endif +#endif /* __RDP_TYPES_H */ diff --git a/include/freerdp/utils/stream.h b/include/freerdp/utils/stream.h index 6884e4948..66e8b5952 100644 --- a/include/freerdp/utils/stream.h +++ b/include/freerdp/utils/stream.h @@ -22,7 +22,7 @@ #define __STREAM_UTILS_H #include -#include +#include struct _STREAM { diff --git a/libfreerdp-core/CMakeLists.txt b/libfreerdp-core/CMakeLists.txt index 7e0cbf7d0..9591ab9f4 100644 --- a/libfreerdp-core/CMakeLists.txt +++ b/libfreerdp-core/CMakeLists.txt @@ -34,6 +34,7 @@ set(LIBFREERDP_CORE_SRCS credssp.h ntlmssp.c ntlmssp.h + settings.c per.c per.h tcp.c diff --git a/libfreerdp-core/credssp.h b/libfreerdp-core/credssp.h index 1d09c5e1d..0dc69eaad 100644 --- a/libfreerdp-core/credssp.h +++ b/libfreerdp-core/credssp.h @@ -20,6 +20,8 @@ #ifndef __CREDSSP_H #define __CREDSSP_H +typedef struct rdp_credssp rdpCredssp; + #include "tls.h" #include "crypto.h" #include "transport.h" @@ -41,9 +43,8 @@ struct rdp_credssp BLOB ts_credentials; CryptoRc4 rc4_seal_state; struct _NTLMSSP *ntlmssp; - struct rdp_transport * transport; + struct rdp_transport* transport; }; -typedef struct rdp_credssp rdpCredssp; int credssp_authenticate(rdpCredssp* credssp); diff --git a/libfreerdp-core/nego.c b/libfreerdp-core/nego.c index b840c0fc5..ced96b567 100644 --- a/libfreerdp-core/nego.c +++ b/libfreerdp-core/nego.c @@ -33,7 +33,7 @@ * @return */ -int nego_connect(rdpNego *nego) +int nego_connect(rdpNego* nego) { if (nego->state == NEGO_STATE_INITIAL) { @@ -47,7 +47,7 @@ int nego_connect(rdpNego *nego) nego->state = NEGO_STATE_FAIL; } - while (nego->state != NEGO_STATE_FINAL) + do { DEBUG_NEGO("state: %s", NEGO_STATE_STRINGS[nego->state]); @@ -55,13 +55,18 @@ int nego_connect(rdpNego *nego) if (nego->state == NEGO_STATE_FAIL) { + DEBUG_NEGO("Protocol Security Negotiation Failure"); nego->state = NEGO_STATE_FINAL; return 0; } } + while (nego->state != NEGO_STATE_FINAL); DEBUG_NEGO("Negotiated %s security", PROTOCOL_SECURITY_STRINGS[nego->selected_protocol]); + /* update settings with negotiated protocol security */ + nego->transport->settings->selected_protocol = nego->selected_protocol; + return 1; } @@ -71,7 +76,7 @@ int nego_connect(rdpNego *nego) * @return */ -int nego_tcp_connect(rdpNego *nego) +int nego_tcp_connect(rdpNego* nego) { if (nego->tcp_connected == 0) { @@ -96,7 +101,7 @@ int nego_tcp_connect(rdpNego *nego) * @return */ -int nego_tcp_disconnect(rdpNego *nego) +int nego_tcp_disconnect(rdpNego* nego) { if (nego->tcp_connected) transport_disconnect(nego->transport); @@ -110,7 +115,7 @@ int nego_tcp_disconnect(rdpNego *nego) * @param nego */ -void nego_attempt_nla(rdpNego *nego) +void nego_attempt_nla(rdpNego* nego) { uint8 code; nego->requested_protocols = PROTOCOL_NLA | PROTOCOL_TLS; @@ -120,7 +125,7 @@ void nego_attempt_nla(rdpNego *nego) nego_tcp_connect(nego); nego_send_negotiation_request(nego); - transport_check_fds(nego->transport); + nego_recv_response(nego); if (nego->state != NEGO_STATE_FINAL) { @@ -140,7 +145,7 @@ void nego_attempt_nla(rdpNego *nego) * @param nego */ -void nego_attempt_tls(rdpNego *nego) +void nego_attempt_tls(rdpNego* nego) { uint8 code; nego->requested_protocols = PROTOCOL_TLS; @@ -150,7 +155,7 @@ void nego_attempt_tls(rdpNego *nego) nego_tcp_connect(nego); nego_send_negotiation_request(nego); - transport_check_fds(nego->transport); + nego_recv_response(nego); if (nego->state != NEGO_STATE_FINAL) { @@ -168,7 +173,7 @@ void nego_attempt_tls(rdpNego *nego) * @param nego */ -void nego_attempt_rdp(rdpNego *nego) +void nego_attempt_rdp(rdpNego* nego) { uint8 code; nego->requested_protocols = PROTOCOL_RDP; @@ -178,7 +183,20 @@ void nego_attempt_rdp(rdpNego *nego) nego_tcp_connect(nego); nego_send_negotiation_request(nego); - transport_check_fds(nego->transport); + nego_recv_response(nego); +} + +/** + * Wait to receive a negotiation response + * @param nego + */ + +void nego_recv_response(rdpNego* nego) +{ + while (nego->state != NEGO_STATE_FINAL && nego->state != NEGO_STATE_FAIL) + { + transport_check_fds(nego->transport); + } } /** @@ -189,11 +207,11 @@ void nego_attempt_rdp(rdpNego *nego) * @param extra nego pointer */ -int nego_recv(rdpTransport * transport, STREAM* s, void * extra) +int nego_recv(rdpTransport* transport, STREAM* s, void* extra) { uint8 li; uint8 type; - rdpNego *nego = (rdpNego*) extra; + rdpNego* nego = (rdpNego*) extra; tpkt_read_header(s); li = tpdu_read_connection_confirm(s); @@ -215,8 +233,10 @@ int nego_recv(rdpTransport * transport, STREAM* s, void * extra) break; } } - - nego->state = NEGO_STATE_FINAL; + else + { + nego->state = NEGO_STATE_FINAL; + } return 0; } @@ -226,7 +246,7 @@ int nego_recv(rdpTransport * transport, STREAM* s, void * extra) * @param nego */ -void nego_send(rdpNego *nego) +void nego_send(rdpNego* nego) { if (nego->state == NEGO_STATE_NLA) nego_attempt_nla(nego); @@ -234,6 +254,8 @@ void nego_send(rdpNego *nego) nego_attempt_tls(nego); else if (nego->state == NEGO_STATE_RDP) nego_attempt_rdp(nego); + else + DEBUG_NEGO("invalid negotiation state for sending"); } /** @@ -243,7 +265,7 @@ void nego_send(rdpNego *nego) * @param nego */ -void nego_send_negotiation_request(rdpNego *nego) +void nego_send_negotiation_request(rdpNego* nego) { STREAM* s; int length; @@ -295,24 +317,16 @@ void nego_send_negotiation_request(rdpNego *nego) * @param s */ -void nego_process_negotiation_response(rdpNego *nego, STREAM* s) +void nego_process_negotiation_response(rdpNego* nego, STREAM* s) { uint8 flags; uint16 length; - uint32 selectedProtocol; DEBUG_NEGO("RDP_NEG_RSP"); stream_read_uint8(s, flags); stream_read_uint16(s, length); - stream_read_uint32(s, selectedProtocol); - - if (selectedProtocol == PROTOCOL_NLA) - nego->selected_protocol = PROTOCOL_NLA; - else if (selectedProtocol == PROTOCOL_TLS) - nego->selected_protocol = PROTOCOL_TLS; - else if (selectedProtocol == PROTOCOL_RDP) - nego->selected_protocol = PROTOCOL_RDP; + stream_read_uint32(s, nego->selected_protocol); nego->state = NEGO_STATE_FINAL; } @@ -323,7 +337,7 @@ void nego_process_negotiation_response(rdpNego *nego, STREAM* s) * @param s */ -void nego_process_negotiation_failure(rdpNego *nego, STREAM* s) +void nego_process_negotiation_failure(rdpNego* nego, STREAM* s) { uint8 flags; uint16 length; @@ -365,7 +379,7 @@ void nego_process_negotiation_failure(rdpNego *nego, STREAM* s) * @param nego */ -void nego_init(rdpNego *nego) +void nego_init(rdpNego* nego) { nego->state = NEGO_STATE_INITIAL; nego->requested_protocols = PROTOCOL_RDP; @@ -381,7 +395,7 @@ void nego_init(rdpNego *nego) rdpNego* nego_new(struct rdp_transport * transport) { - rdpNego *nego = (rdpNego*) xzalloc(sizeof(rdpNego)); + rdpNego* nego = (rdpNego*) xzalloc(sizeof(rdpNego)); if (nego != NULL) { @@ -397,7 +411,7 @@ rdpNego* nego_new(struct rdp_transport * transport) * @param nego */ -void nego_free(rdpNego *nego) +void nego_free(rdpNego* nego) { xfree(nego); } @@ -409,7 +423,7 @@ void nego_free(rdpNego *nego) * @param port */ -void nego_set_target(rdpNego *nego, char* hostname, int port) +void nego_set_target(rdpNego* nego, char* hostname, int port) { nego->hostname = hostname; nego->port = port; @@ -423,7 +437,7 @@ void nego_set_target(rdpNego *nego, char* hostname, int port) * @param nla */ -void nego_set_protocols(rdpNego *nego, int rdp, int tls, int nla) +void nego_set_protocols(rdpNego* nego, int rdp, int tls, int nla) { nego->enabled_protocols[PROTOCOL_RDP] = rdp; nego->enabled_protocols[PROTOCOL_TLS] = tls; @@ -436,7 +450,7 @@ void nego_set_protocols(rdpNego *nego, int rdp, int tls, int nla) * @param routing_token */ -void nego_set_routing_token(rdpNego *nego, char* routing_token) +void nego_set_routing_token(rdpNego* nego, char* routing_token) { nego->routing_token = routing_token; } @@ -447,7 +461,7 @@ void nego_set_routing_token(rdpNego *nego, char* routing_token) * @param cookie */ -void nego_set_cookie(rdpNego *nego, char* cookie) +void nego_set_cookie(rdpNego* nego, char* cookie) { nego->cookie = cookie; } diff --git a/libfreerdp-core/nego.h b/libfreerdp-core/nego.h index cf1627a46..aa701e74f 100644 --- a/libfreerdp-core/nego.h +++ b/libfreerdp-core/nego.h @@ -21,7 +21,8 @@ #define __NEGO_H #include "transport.h" -#include +#include +#include #include #include @@ -67,37 +68,38 @@ struct rdp_nego { int port; char* hostname; - char *cookie; + char* cookie; char* routing_token; NEGO_STATE state; int tcp_connected; uint32 selected_protocol; uint32 requested_protocols; uint8 enabled_protocols[3]; - struct rdp_transport * transport; + rdpTransport* transport; }; typedef struct rdp_nego rdpNego; -int nego_connect(rdpNego *nego); +int nego_connect(rdpNego* nego); -void nego_attempt_nla(rdpNego *nego); -void nego_attempt_tls(rdpNego *nego); -void nego_attempt_rdp(rdpNego *nego); +void nego_attempt_nla(rdpNego* nego); +void nego_attempt_tls(rdpNego* nego); +void nego_attempt_rdp(rdpNego* nego); -void nego_send(rdpNego *nego); -int nego_recv(rdpTransport * transport, STREAM* s, void * extra); +void nego_send(rdpNego* nego); +int nego_recv(rdpTransport* transport, STREAM* s, void* extra); +void nego_recv_response(rdpNego* nego); -void nego_send_negotiation_request(rdpNego *nego); -void nego_process_negotiation_response(rdpNego *nego, STREAM* s); -void nego_process_negotiation_failure(rdpNego *nego, STREAM* s); +void nego_send_negotiation_request(rdpNego* nego); +void nego_process_negotiation_response(rdpNego* nego, STREAM* s); +void nego_process_negotiation_failure(rdpNego* nego, STREAM* s); rdpNego* nego_new(struct rdp_transport * transport); -void nego_free(rdpNego *nego); -void nego_init(rdpNego *nego); -void nego_set_target(rdpNego *nego, char* hostname, int port); -void nego_set_protocols(rdpNego *nego, int rdp, int tls, int nla); -void nego_set_routing_token(rdpNego *nego, char* routing_token); -void nego_set_cookie(rdpNego *nego, char* cookie); +void nego_free(rdpNego* nego); +void nego_init(rdpNego* nego); +void nego_set_target(rdpNego* nego, char* hostname, int port); +void nego_set_protocols(rdpNego* nego, int rdp, int tls, int nla); +void nego_set_routing_token(rdpNego* nego, char* routing_token); +void nego_set_cookie(rdpNego* nego, char* cookie); #define WITH_DEBUG_NEGO 1 diff --git a/include/freerdp/types/base.h b/libfreerdp-core/settings.c similarity index 51% rename from include/freerdp/types/base.h rename to libfreerdp-core/settings.c index 7064a01cf..1bcc8b97a 100644 --- a/include/freerdp/types/base.h +++ b/libfreerdp-core/settings.c @@ -1,6 +1,6 @@ /** * FreeRDP: A Remote Desktop Protocol Client - * Base Types + * RDP Settings * * Copyright 2009-2011 Jay Sorg * @@ -17,39 +17,36 @@ * limitations under the License. */ -#ifndef __TYPES_BASE_H -#define __TYPES_BASE_H +#include -typedef unsigned char uint8; -typedef signed char sint8; -typedef unsigned short uint16; -typedef signed short sint16; -typedef unsigned int uint32; -typedef signed int sint32; -#ifdef _WIN32 -typedef unsigned __int64 uint64; -typedef signed __int64 sint64; -#else -typedef unsigned long long uint64; -typedef signed long long sint64; -#endif +#include -#ifndef True -#define True (1) -#endif +rdpSettings* settings_new() +{ + rdpSettings* settings; -#ifndef False -#define False (0) -#endif + settings = (rdpSettings*) xzalloc(sizeof(rdpSettings)); -typedef int boolean; + if (settings != NULL) + { + /* assign default settings */ -#ifndef MIN -#define MIN(x,y) (((x) < (y)) ? (x) : (y)) -#endif + settings->width = 1024; + settings->height = 768; + settings->color_depth = 16; + settings->nla_security = 1; + settings->tls_security = 1; + settings->rdp_security = 1; + settings->encryption = 1; + } -#ifndef MAX -#define MAX(x,y) (((x) > (y)) ? (x) : (y)) -#endif + return settings; +} -#endif +void settings_free(rdpSettings* settings) +{ + if (settings != NULL) + { + xfree(settings); + } +} diff --git a/libfreerdp-core/tcp.c b/libfreerdp-core/tcp.c index f21d5482c..06b213a8d 100644 --- a/libfreerdp-core/tcp.c +++ b/libfreerdp-core/tcp.c @@ -32,8 +32,7 @@ #include "tcp.h" -boolean -tcp_connect(rdpTcp * tcp, const char * hostname, int port) +boolean tcp_connect(rdpTcp* tcp, const char* hostname, int port) { int status; int sockfd = -1; @@ -81,8 +80,7 @@ tcp_connect(rdpTcp * tcp, const char * hostname, int port) return True; } -boolean -tcp_disconnect(rdpTcp * tcp) +boolean tcp_disconnect(rdpTcp * tcp) { if (tcp->sockfd != -1) { @@ -93,8 +91,7 @@ tcp_disconnect(rdpTcp * tcp) return True; } -boolean -tcp_set_blocking_mode(rdpTcp * tcp, boolean blocking) +boolean tcp_set_blocking_mode(rdpTcp* tcp, boolean blocking) { int flags; flags = fcntl(tcp->sockfd, F_GETFL); @@ -119,10 +116,9 @@ tcp_set_blocking_mode(rdpTcp * tcp, boolean blocking) return True; } -rdpTcp* -tcp_new() +rdpTcp* tcp_new() { - rdpTcp *tcp = (rdpTcp*) xzalloc(sizeof(rdpTcp)); + rdpTcp* tcp = (rdpTcp*) xzalloc(sizeof(rdpTcp)); if (tcp != NULL) { @@ -135,8 +131,7 @@ tcp_new() return tcp; } -void -tcp_free(rdpTcp* tcp) +void tcp_free(rdpTcp* tcp) { if (tcp != NULL) { diff --git a/libfreerdp-core/tcp.h b/libfreerdp-core/tcp.h index 927ad1641..bfa25d559 100644 --- a/libfreerdp-core/tcp.h +++ b/libfreerdp-core/tcp.h @@ -21,13 +21,13 @@ #ifndef __TCP_H #define __TCP_H -#include +#include #include typedef struct rdp_tcp rdpTcp; -typedef boolean (*TcpConnect) (rdpTcp * tcp, const char * hostname, int port); -typedef boolean (*TcpDisconnect) (rdpTcp * tcp); -typedef boolean (*TcpSetBlockingMode) (rdpTcp * tcp, boolean blocking); +typedef boolean (*TcpConnect) (rdpTcp* tcp, const char* hostname, int port); +typedef boolean (*TcpDisconnect) (rdpTcp* tcp); +typedef boolean (*TcpSetBlockingMode) (rdpTcp* tcp, boolean blocking); struct rdp_tcp { @@ -37,16 +37,11 @@ struct rdp_tcp TcpSetBlockingMode set_blocking_mode; }; -boolean -tcp_connect(rdpTcp * tcp, const char * hostname, int port); -boolean -tcp_disconnect(rdpTcp * tcp); -boolean -tcp_set_blocking_mode(rdpTcp * tcp, boolean blocking); +boolean tcp_connect(rdpTcp* tcp, const char* hostname, int port); +boolean tcp_disconnect(rdpTcp* tcp); +boolean tcp_set_blocking_mode(rdpTcp* tcp, boolean blocking); -rdpTcp* -tcp_new(); -void -tcp_free(rdpTcp* tcp); +rdpTcp* tcp_new(); +void tcp_free(rdpTcp* tcp); #endif /* __TCP_H */ diff --git a/libfreerdp-core/tls.h b/libfreerdp-core/tls.h index 7c3d3afd2..8366f019b 100644 --- a/libfreerdp-core/tls.h +++ b/libfreerdp-core/tls.h @@ -26,7 +26,7 @@ #include "crypto.h" -#include +#include #include typedef struct rdp_tls rdpTls; diff --git a/libfreerdp-core/transport.c b/libfreerdp-core/transport.c index 71ab2844c..86ddd9444 100644 --- a/libfreerdp-core/transport.c +++ b/libfreerdp-core/transport.c @@ -30,6 +30,7 @@ #include #include "tpkt.h" +#include "credssp.h" #include "transport.h" #ifndef MSG_NOSIGNAL @@ -38,20 +39,17 @@ #define BUFFER_SIZE 16384 -boolean -transport_connect(rdpTransport * transport, const char * server, int port) +boolean transport_connect(rdpTransport* transport, const char* server, int port) { return transport->tcp->connect(transport->tcp, server, port); } -boolean -transport_disconnect(rdpTransport * transport) +boolean transport_disconnect(rdpTransport* transport) { return transport->tcp->disconnect(transport->tcp); } -boolean -transport_connect_rdp(rdpTransport * transport) +boolean transport_connect_rdp(rdpTransport* transport) { transport->state = TRANSPORT_STATE_RDP; @@ -60,8 +58,7 @@ transport_connect_rdp(rdpTransport * transport) return True; } -boolean -transport_connect_tls(rdpTransport * transport) +boolean transport_connect_tls(rdpTransport* transport) { if (transport->tls == NULL) transport->tls = tls_new(); @@ -76,8 +73,7 @@ transport_connect_tls(rdpTransport * transport) return True; } -boolean -transport_connect_nla(rdpTransport * transport) +boolean transport_connect_nla(rdpTransport* transport) { if (transport->tls == NULL) transport->tls = tls_new(); @@ -91,28 +87,38 @@ transport_connect_nla(rdpTransport * transport) /* Network Level Authentication */ + if (transport->credssp == NULL) + transport->credssp = credssp_new(transport); + + if (credssp_authenticate(transport->credssp) < 0) + { + printf("Authentication failure, check credentials.\n" + "If credentials are valid, the NTLMSSP implementation may be to blame.\n"); + + credssp_free(transport->credssp); + return False; + } + + credssp_free(transport->credssp); + return True; } -static int -transport_recv(rdpTransport * transport); +static int transport_read(rdpTransport* transport); -static int -transport_delay(rdpTransport * transport) +static int transport_delay(rdpTransport* transport) { - transport_recv(transport); + transport_read(transport); nanosleep(&transport->ts, NULL); return 0; } -static int -transport_send_tls(rdpTransport * transport, STREAM * stream) +static int transport_send_tls(rdpTransport* transport, STREAM * stream) { return 0; } -static int -transport_send_tcp(rdpTransport * transport, STREAM * stream) +static int transport_send_tcp(rdpTransport* transport, STREAM * stream) { int bytes; uint8 * head; @@ -144,8 +150,7 @@ transport_send_tcp(rdpTransport * transport, STREAM * stream) return 0; } -int -transport_send(rdpTransport * transport, STREAM * stream) +int transport_send(rdpTransport* transport, STREAM * stream) { int r; @@ -160,14 +165,12 @@ transport_send(rdpTransport * transport, STREAM * stream) return r; } -static int -transport_recv_tls(rdpTransport * transport) +static int transport_read_tls(rdpTransport* transport) { return 0; } -static int -transport_recv_tcp(rdpTransport * transport) +static int transport_read_tcp(rdpTransport* transport) { int bytes; @@ -189,24 +192,22 @@ transport_recv_tcp(rdpTransport * transport) return bytes; } -static int -transport_recv(rdpTransport * transport) +static int transport_read(rdpTransport* transport) { if (transport->state == TRANSPORT_STATE_TLS) - return transport_recv_tls(transport); + return transport_read_tls(transport); else - return transport_recv_tcp(transport); + return transport_read_tcp(transport); } -int -transport_check_fds(rdpTransport * transport) +int transport_check_fds(rdpTransport* transport) { int pos; int bytes; uint16 length; - STREAM * received; + STREAM* received; - bytes = transport_recv(transport); + bytes = transport_read(transport); if (bytes <= 0) return bytes; @@ -257,22 +258,21 @@ transport_check_fds(rdpTransport * transport) return 0; } -void -transport_init(rdpTransport * transport) +void transport_init(rdpTransport* transport) { transport->state = TRANSPORT_STATE_NEGO; } -rdpTransport * -transport_new(rdpSettings * settings) +rdpTransport* transport_new(rdpSettings* settings) { - rdpTransport * transport; + rdpTransport* transport; - transport = (rdpTransport *) xzalloc(sizeof(rdpTransport)); + transport = (rdpTransport*) xzalloc(sizeof(rdpTransport)); if (transport != NULL) { transport->tcp = tcp_new(); + transport->settings = settings; /* a small 0.1ms delay when transport is blocking. */ transport->ts.tv_sec = 0; @@ -285,8 +285,7 @@ transport_new(rdpSettings * settings) return transport; } -void -transport_free(rdpTransport * transport) +void transport_free(rdpTransport* transport) { if (transport != NULL) { diff --git a/libfreerdp-core/transport.h b/libfreerdp-core/transport.h index 2e099a333..84f91eeae 100644 --- a/libfreerdp-core/transport.h +++ b/libfreerdp-core/transport.h @@ -20,12 +20,15 @@ #ifndef __TRANSPORT_H #define __TRANSPORT_H +typedef struct rdp_transport rdpTransport; + #include "tcp.h" #include "tls.h" +#include "credssp.h" #include +#include #include -#include #include enum _TRANSPORT_STATE @@ -39,38 +42,29 @@ enum _TRANSPORT_STATE }; typedef enum _TRANSPORT_STATE TRANSPORT_STATE; -typedef struct rdp_transport rdpTransport; -typedef int (* PacketReceivedCallback) (rdpTransport * transport, STREAM * stream, void* extra); +typedef int (*TransportRecv) (rdpTransport* transport, STREAM* stream, void* extra); struct rdp_transport { TRANSPORT_STATE state; - struct rdp_tcp * tcp; - struct rdp_tls * tls; + struct rdp_tcp* tcp; + struct rdp_tls* tls; + struct rdp_settings* settings; + struct rdp_credssp* credssp; struct timespec ts; - STREAM * recv_buffer; - PacketReceivedCallback recv_callback; void* recv_extra; - struct rdp_settings * settings; + STREAM* recv_buffer; + TransportRecv recv_callback; }; -rdpTransport * -transport_new(rdpSettings * settings); -void -transport_free(rdpTransport * transport); -boolean -transport_connect(rdpTransport * transport, const char * server, int port); -boolean -transport_disconnect(rdpTransport * transport); -boolean -transport_connect_rdp(rdpTransport * transport); -boolean -transport_connect_tls(rdpTransport * transport); -boolean -transport_connect_nla(rdpTransport * transport); -int -transport_send(rdpTransport * transport, STREAM * stream); -int -transport_check_fds(rdpTransport * transport); +rdpTransport* transport_new(rdpSettings* settings); +void transport_free(rdpTransport* transport); +boolean transport_connect(rdpTransport* transport, const char* server, int port); +boolean transport_disconnect(rdpTransport* transport); +boolean transport_connect_rdp(rdpTransport* transport); +boolean transport_connect_tls(rdpTransport* transport); +boolean transport_connect_nla(rdpTransport* transport); +int transport_send(rdpTransport* transport, STREAM* stream); +int transport_check_fds(rdpTransport* transport); #endif diff --git a/libfreerdp-kbd/libkbd.c b/libfreerdp-kbd/libkbd.c index 97c2bdb31..86d9c0847 100644 --- a/libfreerdp-kbd/libkbd.c +++ b/libfreerdp-kbd/libkbd.c @@ -22,7 +22,7 @@ #include #include -#include +#include #include "locales.h" #include "layout_ids.h" diff --git a/libfreerdp-utils/hexdump.c b/libfreerdp-utils/hexdump.c index 158879895..1db8cd6e2 100644 --- a/libfreerdp-utils/hexdump.c +++ b/libfreerdp-utils/hexdump.c @@ -20,7 +20,7 @@ #include #include -#include +#include #include