1 |
/* |
/* -*- c-basic-offset: 8 -*- |
2 |
rdesktop: A Remote Desktop Protocol client. |
rdesktop: A Remote Desktop Protocol client. |
3 |
Protocol services - ISO layer |
Protocol services - ISO layer |
4 |
Copyright (C) Matthew Chapman 1999-2002 |
Copyright (C) Matthew Chapman 1999-2002 |
42 |
tcp_send(s); |
tcp_send(s); |
43 |
} |
} |
44 |
|
|
45 |
|
static void |
46 |
|
iso_send_connection_request(char *username) |
47 |
|
{ |
48 |
|
STREAM s; |
49 |
|
int length = 30 + strlen(username); |
50 |
|
|
51 |
|
s = tcp_init(length); |
52 |
|
|
53 |
|
out_uint8(s, 3); /* version */ |
54 |
|
out_uint8(s, 0); /* reserved */ |
55 |
|
out_uint16_be(s, length); /* length */ |
56 |
|
|
57 |
|
out_uint8(s, length - 5); /* hdrlen */ |
58 |
|
out_uint8(s, ISO_PDU_CR); |
59 |
|
out_uint16(s, 0); /* dst_ref */ |
60 |
|
out_uint16(s, 0); /* src_ref */ |
61 |
|
out_uint8(s, 0); /* class */ |
62 |
|
|
63 |
|
out_uint8p(s, "Cookie: mstshash=", strlen("Cookie: mstshash=")); |
64 |
|
out_uint8p(s, username, strlen(username)); |
65 |
|
|
66 |
|
out_uint8(s, 0x0d); /* Unknown */ |
67 |
|
out_uint8(s, 0x0a); /* Unknown */ |
68 |
|
|
69 |
|
s_mark_end(s); |
70 |
|
tcp_send(s); |
71 |
|
} |
72 |
|
|
73 |
/* Receive a message on the ISO layer, return code */ |
/* Receive a message on the ISO layer, return code */ |
74 |
static STREAM |
static STREAM |
75 |
iso_recv_msg(uint8 * code) |
iso_recv_msg(uint8 * code) |
77 |
STREAM s; |
STREAM s; |
78 |
uint16 length; |
uint16 length; |
79 |
uint8 version; |
uint8 version; |
80 |
|
BOOL shortform = False; // Shut the compiler up. |
81 |
|
|
82 |
|
next_packet: |
83 |
s = tcp_recv(4); |
s = tcp_recv(4); |
84 |
if (s == NULL) |
if (s == NULL) |
85 |
return NULL; |
return NULL; |
86 |
|
|
87 |
in_uint8(s, version); |
in_uint8(s, version); |
88 |
if (version != 3) |
switch (version & 3) |
89 |
{ |
{ |
90 |
error("TPKT v%d\n", version); |
case 0: |
91 |
return NULL; |
in_uint8(s, length); |
92 |
|
if (length & 0x80) |
93 |
|
{ |
94 |
|
length &= ~0x80; |
95 |
|
next_be(s, length); |
96 |
|
shortform = False; |
97 |
|
} |
98 |
|
else |
99 |
|
{ |
100 |
|
shortform = True; |
101 |
|
} |
102 |
|
break; |
103 |
|
|
104 |
|
case 3: |
105 |
|
in_uint8s(s, 1); /* pad */ |
106 |
|
in_uint16_be(s, length); |
107 |
|
break; |
108 |
|
|
109 |
|
default: |
110 |
|
error("TPKT v%d\n", version); |
111 |
|
return NULL; |
112 |
} |
} |
113 |
|
|
|
in_uint8s(s, 1); /* pad */ |
|
|
in_uint16_be(s, length); |
|
|
|
|
114 |
s = tcp_recv(length - 4); |
s = tcp_recv(length - 4); |
115 |
if (s == NULL) |
if (s == NULL) |
116 |
return NULL; |
return NULL; |
117 |
|
|
118 |
|
if ((version & 3) == 0) |
119 |
|
{ |
120 |
|
rdp5_process(s, version & 0x80, shortform); |
121 |
|
goto next_packet; |
122 |
|
} |
123 |
|
|
124 |
in_uint8s(s, 1); /* hdrlen */ |
in_uint8s(s, 1); /* hdrlen */ |
125 |
in_uint8(s, *code); |
in_uint8(s, *code); |
126 |
|
|
188 |
|
|
189 |
/* Establish a connection up to the ISO layer */ |
/* Establish a connection up to the ISO layer */ |
190 |
BOOL |
BOOL |
191 |
iso_connect(char *server) |
iso_connect(char *server, char *username) |
192 |
{ |
{ |
193 |
uint8 code; |
uint8 code; |
194 |
|
|
195 |
if (!tcp_connect(server)) |
if (!tcp_connect(server)) |
196 |
return False; |
return False; |
197 |
|
|
198 |
iso_send_msg(ISO_PDU_CR); |
iso_send_connection_request(username); |
199 |
|
|
200 |
if (iso_recv_msg(&code) == NULL) |
if (iso_recv_msg(&code) == NULL) |
201 |
return False; |
return False; |