mirror of https://github.com/neutrinolabs/xrdp
early work
This commit is contained in:
parent
12ed9b1002
commit
8cb69713be
|
@ -27,7 +27,7 @@ struct xrdp_iso* xrdp_iso_create(struct xrdp_mcs* owner)
|
|||
struct xrdp_iso* self;
|
||||
|
||||
self = (struct xrdp_iso*)g_malloc(sizeof(struct xrdp_iso), 1);
|
||||
self->owner = owner;
|
||||
self->mcs_layer = owner;
|
||||
self->in_s = owner->in_s;
|
||||
self->out_s = owner->out_s;
|
||||
self->tcp_layer = xrdp_tcp_create(self);
|
||||
|
@ -77,10 +77,12 @@ int xrdp_iso_recv(struct xrdp_iso* self)
|
|||
{
|
||||
int code;
|
||||
|
||||
DEBUG((" in xrdp_iso_recv\n\r"));
|
||||
if (xrdp_iso_recv_msg(self, &code) != 0)
|
||||
return 1;
|
||||
if (code != ISO_PDU_DT)
|
||||
return 1;
|
||||
DEBUG((" out xrdp_iso_recv\n\r"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -94,8 +96,8 @@ int xrdp_iso_send_msg(struct xrdp_iso* self, int code)
|
|||
out_uint16_be(self->out_s, 11); /* length */
|
||||
out_uint8(self->out_s, 8);
|
||||
out_uint8(self->out_s, code);
|
||||
out_uint16(self->out_s, 0);
|
||||
out_uint16(self->out_s, 0);
|
||||
out_uint16_le(self->out_s, 0);
|
||||
out_uint16_le(self->out_s, 0);
|
||||
out_uint8(self->out_s, 0);
|
||||
s_mark_end(self->out_s);
|
||||
if (xrdp_tcp_send(self->tcp_layer) != 0)
|
||||
|
@ -109,12 +111,14 @@ int xrdp_iso_incoming(struct xrdp_iso* self)
|
|||
{
|
||||
int code;
|
||||
|
||||
DEBUG((" in xrdp_iso_incoming\n\r"));
|
||||
if (xrdp_iso_recv_msg(self, &code) != 0)
|
||||
return 1;
|
||||
if (code != ISO_PDU_CR)
|
||||
return 1;
|
||||
if (xrdp_iso_send_msg(self, ISO_PDU_CC) != 0)
|
||||
return 1;
|
||||
DEBUG((" out xrdp_iso_incoming\n\r"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ struct xrdp_mcs* xrdp_mcs_create(struct xrdp_sec* owner)
|
|||
struct xrdp_mcs* self;
|
||||
|
||||
self = (struct xrdp_mcs*)g_malloc(sizeof(struct xrdp_mcs), 1);
|
||||
self->owner = owner;
|
||||
self->sec_layer = owner;
|
||||
self->in_s = owner->in_s;
|
||||
self->out_s = owner->out_s;
|
||||
self->userid = 1;
|
||||
|
@ -45,6 +45,23 @@ void xrdp_mcs_delete(struct xrdp_mcs* self)
|
|||
g_free(self);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* returns error */
|
||||
int xrdp_mcs_send_cjcf(struct xrdp_mcs* self, int chanid)
|
||||
{
|
||||
if (xrdp_iso_init(self->iso_layer, 8) != 0)
|
||||
return 1;
|
||||
out_uint8(self->out_s, (MCS_CJCF << 2) | 2);
|
||||
out_uint8(self->out_s, 0);
|
||||
out_uint16_be(self->out_s, self->userid);
|
||||
out_uint16_be(self->out_s, chanid);
|
||||
out_uint16_be(self->out_s, chanid);
|
||||
s_mark_end(self->out_s);
|
||||
if (xrdp_iso_send(self->iso_layer) != 0)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* returns error */
|
||||
int xrdp_mcs_recv(struct xrdp_mcs* self)
|
||||
|
@ -53,16 +70,32 @@ int xrdp_mcs_recv(struct xrdp_mcs* self)
|
|||
int opcode;
|
||||
int len;
|
||||
|
||||
if (xrdp_iso_recv(self->iso_layer) != 0)
|
||||
return 1;
|
||||
in_uint8(self->in_s, opcode);
|
||||
appid = opcode >> 2;
|
||||
DEBUG((" in xrdp_mcs_recv\n\r"));
|
||||
while (1)
|
||||
{
|
||||
if (xrdp_iso_recv(self->iso_layer) != 0)
|
||||
return 1;
|
||||
in_uint8(self->in_s, opcode);
|
||||
appid = opcode >> 2;
|
||||
if (appid == MCS_DPUM)
|
||||
return 1;
|
||||
if (appid == MCS_CJRQ)
|
||||
{
|
||||
xrdp_mcs_send_cjcf(self, self->userid + MCS_USERCHANNEL_BASE);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (appid != MCS_SDRQ)
|
||||
{
|
||||
DEBUG((" out xrdp_mcs_recv err got 0x%x need MCS_SDRQ\n\r", appid));
|
||||
return 1;
|
||||
}
|
||||
in_uint8s(self->in_s, 5);
|
||||
in_uint8(self->in_s, len);
|
||||
if (len & 0x80)
|
||||
in_uint8s(self->in_s, 1);
|
||||
DEBUG((" out xrdp_mcs_recv\n\r"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -72,6 +105,7 @@ int xrdp_mcs_ber_parse_header(struct xrdp_mcs* self, int tag_val, int* len)
|
|||
{
|
||||
int tag;
|
||||
int l;
|
||||
int i;
|
||||
|
||||
if (tag_val > 0xff)
|
||||
{
|
||||
|
@ -90,7 +124,8 @@ int xrdp_mcs_ber_parse_header(struct xrdp_mcs* self, int tag_val, int* len)
|
|||
*len = 0;
|
||||
while (l > 0)
|
||||
{
|
||||
next_be(self->in_s, *len);
|
||||
in_uint8(self->in_s, i);
|
||||
*len = (*len << 8) | i;
|
||||
l--;
|
||||
}
|
||||
}
|
||||
|
@ -203,7 +238,7 @@ int xrdp_mcs_send_aucf(struct xrdp_mcs* self)
|
|||
{
|
||||
if (xrdp_iso_init(self->iso_layer, 4) != 0)
|
||||
return 1;
|
||||
out_uint8(self->out_s, (MCS_AUCF << 2) | 2);
|
||||
out_uint8(self->out_s, ((MCS_AUCF << 2) | 2));
|
||||
out_uint8s(self->out_s, 1);
|
||||
out_uint16_be(self->out_s, self->userid);
|
||||
s_mark_end(self->out_s);
|
||||
|
@ -233,23 +268,6 @@ int xrdp_mcs_recv_cjrq(struct xrdp_mcs* self)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* returns error */
|
||||
int xrdp_mcs_send_cjcf(struct xrdp_mcs* self, int chanid)
|
||||
{
|
||||
if (xrdp_iso_init(self->iso_layer, 8) != 0)
|
||||
return 1;
|
||||
out_uint8(self->out_s, (MCS_CJCF << 2) | 2);
|
||||
out_uint8(self->out_s, 0);
|
||||
out_uint16_be(self->out_s, self->userid);
|
||||
out_uint16_be(self->out_s, chanid);
|
||||
out_uint16_be(self->out_s, chanid);
|
||||
s_mark_end(self->out_s);
|
||||
if (xrdp_iso_send(self->iso_layer) != 0)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* returns error */
|
||||
int xrdp_mcs_ber_out_header(struct xrdp_mcs* self, int tag_val, int len)
|
||||
|
@ -349,6 +367,7 @@ int xrdp_mcs_send_connect_response(struct xrdp_mcs* self)
|
|||
/* returns error */
|
||||
int xrdp_mcs_incoming(struct xrdp_mcs* self)
|
||||
{
|
||||
DEBUG((" in xrdp_mcs_incoming\n\r"));
|
||||
if (xrdp_iso_incoming(self->iso_layer) != 0)
|
||||
return 1;
|
||||
if (xrdp_mcs_recv_connect_initial(self) != 0)
|
||||
|
@ -369,6 +388,7 @@ int xrdp_mcs_incoming(struct xrdp_mcs* self)
|
|||
return 1;
|
||||
if (xrdp_mcs_send_cjcf(self, MCS_GLOBAL_CHANNEL) != 0)
|
||||
return 1;
|
||||
DEBUG((" out xrdp_mcs_incoming\n\r"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,9 +27,11 @@ struct xrdp_tcp* xrdp_tcp_create(struct xrdp_iso* owner)
|
|||
struct xrdp_tcp* self;
|
||||
|
||||
self = (struct xrdp_tcp*)g_malloc(sizeof(struct xrdp_tcp), 1);
|
||||
self->owner = owner;
|
||||
self->iso_layer = owner;
|
||||
self->in_s = owner->in_s;
|
||||
self->out_s = owner->out_s;
|
||||
/* get sck from xrdp_process */
|
||||
self->sck = owner->mcs_layer->sec_layer->rdp_layer->pro_layer->sck;
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -54,6 +56,7 @@ int xrdp_tcp_recv(struct xrdp_tcp* self, int len)
|
|||
{
|
||||
int rcvd;
|
||||
|
||||
DEBUG((" in xrdp_tcp_recv, gota get %d bytes\n", len))
|
||||
init_stream(self->in_s, len);
|
||||
while (len > 0)
|
||||
{
|
||||
|
@ -65,10 +68,16 @@ int xrdp_tcp_recv(struct xrdp_tcp* self, int len)
|
|||
if (g_tcp_last_error_would_block(self->sck))
|
||||
g_sleep(1);
|
||||
else
|
||||
{
|
||||
DEBUG((" error = -1 in xrdp_tcp_recv socket %d\n", self->sck))
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if (rcvd == 0)
|
||||
{
|
||||
DEBUG((" error = 0 in xrdp_tcp_recv socket %d\n", self->sck))
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
self->in_s->end += rcvd;
|
||||
|
@ -87,6 +96,7 @@ int xrdp_tcp_send(struct xrdp_tcp* self)
|
|||
int sent;
|
||||
|
||||
len = self->out_s->end - self->out_s->data;
|
||||
DEBUG((" in xrdp_tcp_send, gota send %d bytes\n", len))
|
||||
total = 0;
|
||||
while (total < len)
|
||||
{
|
||||
|
@ -98,10 +108,16 @@ int xrdp_tcp_send(struct xrdp_tcp* self)
|
|||
if (g_tcp_last_error_would_block(self->sck))
|
||||
g_sleep(1);
|
||||
else
|
||||
{
|
||||
DEBUG((" error = -1 in xrdp_tcp_send socket %d\n", self->sck))
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if (sent == 0)
|
||||
{
|
||||
DEBUG((" error = 0 in xrdp_tcp_send socket %d\n", self->sck))
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
total = total + sent;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue