/[rdesktop]/sourceforge.net/trunk/rdesktop/iso.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /sourceforge.net/trunk/rdesktop/iso.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 347 - (hide annotations)
Thu Mar 27 13:11:58 2003 UTC (21 years, 3 months ago) by forsberg
File MIME type: text/plain
File size: 4098 byte(s)
Remade connection setup. Send mstshash in initial packet.

(This might not be needed, but the more lookalike to a MS client we are,
 the better).

Recognize RDP5 packets and hand them to the RDP5 parsing routine.

1 forsberg 347 /* -*- c-basic-offset: 8 -*-
2 matty 3 rdesktop: A Remote Desktop Protocol client.
3     Protocol services - ISO layer
4 matthewc 207 Copyright (C) Matthew Chapman 1999-2002
5 matty 3
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10    
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     GNU General Public License for more details.
15    
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19     */
20    
21 matty 10 #include "rdesktop.h"
22 matty 3
23 matty 10 /* Send a self-contained ISO PDU */
24 matty 25 static void
25     iso_send_msg(uint8 code)
26 matty 3 {
27 matty 10 STREAM s;
28 matty 3
29 matty 10 s = tcp_init(11);
30 matty 3
31 matty 24 out_uint8(s, 3); /* version */
32     out_uint8(s, 0); /* reserved */
33     out_uint16_be(s, 11); /* length */
34 matty 3
35 matty 24 out_uint8(s, 6); /* hdrlen */
36 matty 10 out_uint8(s, code);
37 matty 24 out_uint16(s, 0); /* dst_ref */
38     out_uint16(s, 0); /* src_ref */
39     out_uint8(s, 0); /* class */
40 matty 10
41     s_mark_end(s);
42     tcp_send(s);
43     }
44    
45 forsberg 347 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 matty 10 /* Receive a message on the ISO layer, return code */
74 matty 25 static STREAM
75 astrand 64 iso_recv_msg(uint8 * code)
76 matty 10 {
77     STREAM s;
78     uint16 length;
79     uint8 version;
80 forsberg 347 BOOL shortform = False; // Shut the compiler up.
81 matty 10
82 forsberg 347 next_packet:
83 matty 10 s = tcp_recv(4);
84     if (s == NULL)
85 matty 33 return NULL;
86 matty 10
87     in_uint8(s, version);
88 forsberg 347 switch (version & 3)
89 matty 3 {
90 forsberg 347 case 0:
91     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 matty 3 }
113    
114 matty 10 s = tcp_recv(length - 4);
115     if (s == NULL)
116 matty 33 return NULL;
117 matty 10
118 forsberg 347 if ((version & 3) == 0)
119     {
120     rdp5_process(s, version & 0x80, shortform);
121     goto next_packet;
122     }
123    
124 matty 24 in_uint8s(s, 1); /* hdrlen */
125 matty 10 in_uint8(s, *code);
126    
127     if (*code == ISO_PDU_DT)
128     {
129 matty 24 in_uint8s(s, 1); /* eot */
130     return s;
131 matty 10 }
132    
133 matty 24 in_uint8s(s, 5); /* dst_ref, src_ref, class */
134 matty 10 return s;
135 matty 3 }
136    
137 matty 10 /* Initialise ISO transport data packet */
138 matty 25 STREAM
139     iso_init(int length)
140 matty 3 {
141 matty 10 STREAM s;
142 matty 3
143 matty 10 s = tcp_init(length + 7);
144     s_push_layer(s, iso_hdr, 7);
145    
146     return s;
147 matty 3 }
148    
149 matty 10 /* Send an ISO data PDU */
150 matty 25 void
151     iso_send(STREAM s)
152 matty 3 {
153 matty 10 uint16 length;
154 matty 3
155 matty 10 s_pop_layer(s, iso_hdr);
156     length = s->end - s->p;
157 matty 3
158 matty 24 out_uint8(s, 3); /* version */
159     out_uint8(s, 0); /* reserved */
160 matty 10 out_uint16_be(s, length);
161 matty 3
162 matty 24 out_uint8(s, 2); /* hdrlen */
163     out_uint8(s, ISO_PDU_DT); /* code */
164     out_uint8(s, 0x80); /* eot */
165 matty 10
166     tcp_send(s);
167 matty 3 }
168    
169     /* Receive ISO transport data packet */
170 matty 25 STREAM
171 matthewc 192 iso_recv(void)
172 matty 3 {
173 matty 10 STREAM s;
174 matty 3 uint8 code;
175    
176 matty 10 s = iso_recv_msg(&code);
177 matty 33 if (s == NULL)
178     return NULL;
179    
180     if (code != ISO_PDU_DT)
181 matty 3 {
182 matty 33 error("expected DT, got 0x%x\n", code);
183     return NULL;
184 matty 3 }
185    
186 matty 10 return s;
187 matty 3 }
188    
189 matty 10 /* Establish a connection up to the ISO layer */
190 matty 25 BOOL
191 forsberg 347 iso_connect(char *server, char *username)
192 matty 3 {
193 matty 10 uint8 code;
194 matty 3
195 matty 10 if (!tcp_connect(server))
196     return False;
197 matty 3
198 forsberg 347 iso_send_connection_request(username);
199 matty 3
200 matty 33 if (iso_recv_msg(&code) == NULL)
201     return False;
202    
203     if (code != ISO_PDU_CC)
204 matty 3 {
205 matty 33 error("expected CC, got 0x%x\n", code);
206 matty 10 tcp_disconnect();
207 matty 3 return False;
208     }
209    
210     return True;
211     }
212    
213 matty 10 /* Disconnect from the ISO layer */
214 matty 25 void
215 matthewc 192 iso_disconnect(void)
216 matty 3 {
217 matty 10 iso_send_msg(ISO_PDU_DR);
218     tcp_disconnect();
219 matty 3 }

  ViewVC Help
Powered by ViewVC 1.1.26