libfreerdp-core: fix negotiation module
This commit is contained in:
parent
9f48b605ea
commit
2199475153
@ -21,7 +21,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <CUnit/CUnit.h>
|
||||
#include <freerdp/types/base.h>
|
||||
#include <freerdp/types.h>
|
||||
#include <freerdp/utils/stream.h>
|
||||
#include <freerdp/utils/hexdump.h>
|
||||
|
||||
|
@ -24,19 +24,24 @@
|
||||
#include "nego.h"
|
||||
#include "transport.h"
|
||||
|
||||
#include <freerdp/settings.h>
|
||||
#include <freerdp/utils/memory.h>
|
||||
|
||||
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 <hostname> <username>\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;
|
||||
}
|
||||
|
@ -21,7 +21,7 @@
|
||||
#define __RDP_EXTENSION_H
|
||||
|
||||
#include <freerdp/api.h>
|
||||
#include <freerdp/types/ui.h>
|
||||
#include <freerdp/types.h>
|
||||
|
||||
/* Extensions ought to check for it to ensure compatibility */
|
||||
#define RDPEXT_API 1
|
||||
|
@ -21,7 +21,7 @@
|
||||
#define __FREERDP_H
|
||||
|
||||
#include <freerdp/api.h>
|
||||
#include <freerdp/types/ui.h>
|
||||
#include <freerdp/types.h>
|
||||
#include <freerdp/settings.h>
|
||||
#include <freerdp/extension.h>
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
#ifndef __FREERDP_KBD_H
|
||||
#define __FREERDP_KBD_H
|
||||
|
||||
#include <freerdp/types/base.h>
|
||||
#include <freerdp/types.h>
|
||||
|
||||
#define RDP_KEYBOARD_LAYOUT_TYPE_STANDARD 1
|
||||
#define RDP_KEYBOARD_LAYOUT_TYPE_VARIANT 2
|
||||
|
@ -20,7 +20,7 @@
|
||||
#ifndef __RDP_SETTINGS_H
|
||||
#define __RDP_SETTINGS_H
|
||||
|
||||
#include <freerdp/types/base.h>
|
||||
#include <freerdp/types.h>
|
||||
|
||||
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 */
|
||||
|
@ -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 <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.
|
||||
@ -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 <freerdp/types/base.h>
|
||||
/* 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 <freerdp/settings.h>
|
||||
|
||||
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 */
|
@ -22,7 +22,7 @@
|
||||
#define __STREAM_UTILS_H
|
||||
|
||||
#include <string.h>
|
||||
#include <freerdp/types/base.h>
|
||||
#include <freerdp/types.h>
|
||||
|
||||
struct _STREAM
|
||||
{
|
||||
|
@ -34,6 +34,7 @@ set(LIBFREERDP_CORE_SRCS
|
||||
credssp.h
|
||||
ntlmssp.c
|
||||
ntlmssp.h
|
||||
settings.c
|
||||
per.c
|
||||
per.h
|
||||
tcp.c
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -21,7 +21,8 @@
|
||||
#define __NEGO_H
|
||||
|
||||
#include "transport.h"
|
||||
#include <freerdp/types/base.h>
|
||||
#include <freerdp/types.h>
|
||||
#include <freerdp/settings.h>
|
||||
#include <freerdp/utils/debug.h>
|
||||
#include <freerdp/utils/stream.h>
|
||||
|
||||
@ -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
|
||||
|
||||
|
@ -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 <freerdp/utils/memory.h>
|
||||
|
||||
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 <freerdp/settings.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
}
|
@ -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)
|
||||
{
|
||||
|
@ -21,13 +21,13 @@
|
||||
#ifndef __TCP_H
|
||||
#define __TCP_H
|
||||
|
||||
#include <freerdp/types/base.h>
|
||||
#include <freerdp/types.h>
|
||||
#include <freerdp/utils/stream.h>
|
||||
|
||||
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 */
|
||||
|
@ -26,7 +26,7 @@
|
||||
|
||||
#include "crypto.h"
|
||||
|
||||
#include <freerdp/types/base.h>
|
||||
#include <freerdp/types.h>
|
||||
#include <freerdp/utils/stream.h>
|
||||
|
||||
typedef struct rdp_tls rdpTls;
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <fcntl.h>
|
||||
|
||||
#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)
|
||||
{
|
||||
|
@ -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 <time.h>
|
||||
#include <freerdp/types.h>
|
||||
#include <freerdp/settings.h>
|
||||
#include <freerdp/types/ui.h>
|
||||
#include <freerdp/utils/stream.h>
|
||||
|
||||
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
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <freerdp/kbd.h>
|
||||
#include <freerdp/types/base.h>
|
||||
#include <freerdp/types.h>
|
||||
|
||||
#include "locales.h"
|
||||
#include "layout_ids.h"
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <freerdp/types/base.h>
|
||||
#include <freerdp/types.h>
|
||||
|
||||
#include <freerdp/utils/hexdump.h>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user