libfreerdp-core: refactoring of sequencing of TSG connection

This commit is contained in:
Marc-André Moreau 2012-11-29 01:33:19 -05:00
parent dde2e60a56
commit 4fe3501bc4
7 changed files with 73 additions and 37 deletions

View File

@ -31,6 +31,8 @@
#include <X11/Xutil.h>
#include <X11/keysym.h>
#include <freerdp/locale/keyboard.h>
#include "xf_keyboard.h"
void xf_kbd_init(xfInfo* xfi)

View File

@ -569,6 +569,11 @@ int rpc_write(rdpRpc* rpc, BYTE* data, int length, UINT16 opnum)
return length;
}
int rpc_recv(rdpRpc* rpc, RPC_PDU* pdu)
{
return 0;
}
BOOL rpc_connect(rdpRpc* rpc)
{
rpc->TlsIn = rpc->transport->TlsIn;

View File

@ -793,9 +793,10 @@ BOOL rpc_get_stub_data_info(rdpRpc* rpc, BYTE* header, UINT32* offset, UINT32* l
int rpc_recv_pdu_header(rdpRpc* rpc, BYTE* header);
RPC_PDU* rpc_recv_pdu(rdpRpc* rpc);
int rpc_write(rdpRpc* rpc, BYTE* data, int length, UINT16 opnum);
int rpc_recv(rdpRpc* rpc, RPC_PDU* pdu);
rdpRpc* rpc_new(rdpTransport* transport);
void rpc_free(rdpRpc* rpc);

View File

@ -213,18 +213,12 @@ int rpc_send_bind_pdu(rdpRpc* rpc)
* abstract GSS_Init_sec_context call, which returns an auth_token and continue status in this example.
*/
int rpc_recv_bind_ack_pdu(rdpRpc* rpc)
int rpc_recv_bind_ack_pdu(rdpRpc* rpc, BYTE* buffer, UINT32 length)
{
RPC_PDU* pdu;
BYTE* auth_data;
rpcconn_hdr_t* header;
pdu = rpc_recv_dequeue_pdu(rpc);
if (!pdu)
return -1;
header = (rpcconn_hdr_t*) pdu->Buffer;
header = (rpcconn_hdr_t*) buffer;
rpc->max_recv_frag = header->bind_ack.max_xmit_frag;
rpc->max_xmit_frag = header->bind_ack.max_recv_frag;
@ -232,12 +226,12 @@ int rpc_recv_bind_ack_pdu(rdpRpc* rpc)
rpc->ntlm->inputBuffer.cbBuffer = header->common.auth_length;
rpc->ntlm->inputBuffer.pvBuffer = malloc(header->common.auth_length);
auth_data = pdu->Buffer + (header->common.frag_length - header->common.auth_length);
auth_data = buffer + (header->common.frag_length - header->common.auth_length);
CopyMemory(rpc->ntlm->inputBuffer.pvBuffer, auth_data, header->common.auth_length);
ntlm_authenticate(rpc->ntlm);
return pdu->Length;
return (int) length;
}
/**
@ -254,7 +248,7 @@ int rpc_send_rpc_auth_3_pdu(rdpRpc* rpc)
UINT32 length;
rpcconn_rpc_auth_3_hdr_t* auth_3_pdu;
DEBUG_RPC("Sending auth_3 PDU");
DEBUG_RPC("Sending rpc_auth_3 PDU");
auth_3_pdu = (rpcconn_rpc_auth_3_hdr_t*) malloc(sizeof(rpcconn_rpc_auth_3_hdr_t));
ZeroMemory(auth_3_pdu, sizeof(rpcconn_rpc_auth_3_hdr_t));
@ -329,33 +323,59 @@ int rpc_send_rpc_auth_3_pdu(rdpRpc* rpc)
int rpc_secure_bind(rdpRpc* rpc)
{
if (rpc->State != RPC_CLIENT_STATE_ESTABLISHED)
{
printf("rpc_secure_bind: invalid state, expected RPC_CLIENT_STATE_ESTABLISHED\n");
return -1;
}
int status;
RPC_PDU* pdu;
if (rpc_send_bind_pdu(rpc) <= 0)
rpc->client->SynchronousSend = FALSE;
rpc->client->SynchronousReceive = TRUE;
while (rpc->State != RPC_CLIENT_STATE_CONTEXT_NEGOTIATED)
{
printf("rpc_send_bind_pdu error!\n");
if (rpc->State == RPC_CLIENT_STATE_ESTABLISHED)
{
status = rpc_send_bind_pdu(rpc);
if (status <= 0)
{
printf("rpc_secure_bind: error sending bind pdu!\n");
return -1;
}
rpc->State = RPC_CLIENT_STATE_WAIT_SECURE_BIND_ACK;
if (rpc_recv_bind_ack_pdu(rpc) <= 0)
}
else if (rpc->State == RPC_CLIENT_STATE_WAIT_SECURE_BIND_ACK)
{
printf("rpc_recv_bind_ack_pdu error!\n");
pdu = rpc_recv_dequeue_pdu(rpc);
if (!pdu)
{
printf("rpc_secure_bind: error receiving bind ack pdu!\n");
return -1;
}
if (rpc_recv_bind_ack_pdu(rpc, pdu->Buffer, pdu->Length) <= 0)
{
printf("rpc_secure_bind: error receiving bind ack pdu!\n");
return -1;
}
if (rpc_send_rpc_auth_3_pdu(rpc) <= 0)
{
printf("rpc_send_rpc_auth_3 error!\n");
printf("rpc_secure_bind: error sending rpc_auth_3 pdu!\n");
return -1;
}
rpc->State = RPC_CLIENT_STATE_CONTEXT_NEGOTIATED;
}
else
{
printf("rpc_secure_bind: invalid state: %d\n", rpc->State);
return -1;
}
}
rpc->client->SynchronousSend = FALSE;
rpc->client->SynchronousReceive = FALSE;
return 0;
}

View File

@ -25,7 +25,7 @@
#include <winpr/wtypes.h>
int rpc_send_bind_pdu(rdpRpc* rpc);
int rpc_recv_bind_ack_pdu(rdpRpc* rpc);
int rpc_recv_bind_ack_pdu(rdpRpc* rpc, BYTE* buffer, UINT32 length);
int rpc_send_rpc_auth_3_pdu(rdpRpc* rpc);
int rpc_secure_bind(rdpRpc* rpc);

View File

@ -87,6 +87,9 @@ BOOL rts_connect(rdpRpc* rpc)
rpc->VirtualConnection->State = VIRTUAL_CONNECTION_STATE_INITIAL;
DEBUG_RTS("VIRTUAL_CONNECTION_STATE_INITIAL");
rpc->client->SynchronousSend = TRUE;
rpc->client->SynchronousReceive = TRUE;
if (!rpc_ntlm_http_out_connect(rpc))
{
printf("rpc_out_connect_http error!\n");
@ -231,6 +234,9 @@ BOOL rts_connect(rdpRpc* rpc)
rpc->VirtualConnection->State = VIRTUAL_CONNECTION_STATE_OPENED;
DEBUG_RTS("VIRTUAL_CONNECTION_STATE_OPENED");
rpc->client->SynchronousSend = FALSE;
rpc->client->SynchronousReceive = FALSE;
return TRUE;
}

View File

@ -940,6 +940,7 @@ BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port)
tsg->state = TSG_STATE_INITIAL;
rpc->client->SynchronousSend = TRUE;
rpc->client->SynchronousReceive = TRUE;
/*
* Sequential processing rules for connection process:
@ -1080,6 +1081,7 @@ BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port)
return FALSE;
rpc->client->SynchronousSend = TRUE;
rpc->client->SynchronousReceive = TRUE;
return TRUE;
}