/[rdesktop]/jpeg/rdesktop/trunk/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

Diff of /jpeg/rdesktop/trunk/iso.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 24 by matty, Sat Jan 6 03:12:10 2001 UTC revision 1434 by matthewc, Thu Feb 14 11:45:13 2008 UTC
# Line 1  Line 1 
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-2000     Copyright (C) Matthew Chapman 1999-2007
5      
6     This program is free software; you can redistribute it and/or modify     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     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     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.     (at your option) any later version.
10      
11     This program is distributed in the hope that it will be useful,     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.     GNU General Public License for more details.
15      
16     You should have received a copy of the GNU General Public License     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# Line 21  Line 21 
21  #include "rdesktop.h"  #include "rdesktop.h"
22    
23  /* Send a self-contained ISO PDU */  /* Send a self-contained ISO PDU */
24  static void iso_send_msg(uint8 code)  static void
25    iso_send_msg(uint8 code)
26  {  {
27          STREAM s;          STREAM s;
28    
# Line 41  static void iso_send_msg(uint8 code) Line 42  static void iso_send_msg(uint8 code)
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 iso_recv_msg(uint8 *code)  static STREAM
75    iso_recv_msg(uint8 * code, uint8 * rdpver)
76  {  {
77          STREAM s;          STREAM s;
78          uint16 length;          uint16 length;
79          uint8 version;          uint8 version;
80    
81          s = tcp_recv(4);          s = tcp_recv(NULL, 4);
82          if (s == NULL)          if (s == NULL)
83                  return False;                  return NULL;
   
84          in_uint8(s, version);          in_uint8(s, version);
85          if (version != 3)          if (rdpver != NULL)
86                    *rdpver = version;
87            if (version == 3)
88          {          {
89                  ERROR("TPKT v%d\n", version);                  in_uint8s(s, 1);        /* pad */
90                  return False;                  in_uint16_be(s, length);
91          }          }
92            else
93          in_uint8s(s, 1);        /* pad */          {
94          in_uint16_be(s, length);                  in_uint8(s, length);
95                    if (length & 0x80)
96          s = tcp_recv(length - 4);                  {
97                            length &= ~0x80;
98                            next_be(s, length);
99                    }
100            }
101            if (length < 4)
102            {
103                    error("Bad packet header\n");
104                    return NULL;
105            }
106            s = tcp_recv(s, length - 4);
107          if (s == NULL)          if (s == NULL)
108                  return False;                  return NULL;
109            if (version != 3)
110                    return s;
111          in_uint8s(s, 1);        /* hdrlen */          in_uint8s(s, 1);        /* hdrlen */
112          in_uint8(s, *code);          in_uint8(s, *code);
   
113          if (*code == ISO_PDU_DT)          if (*code == ISO_PDU_DT)
114          {          {
115                  in_uint8s(s, 1);        /* eot */                  in_uint8s(s, 1);        /* eot */
116                  return s;                  return s;
117          }          }
   
118          in_uint8s(s, 5);        /* dst_ref, src_ref, class */          in_uint8s(s, 5);        /* dst_ref, src_ref, class */
119          return s;          return s;
120  }  }
121    
122  /* Initialise ISO transport data packet */  /* Initialise ISO transport data packet */
123  STREAM iso_init(int length)  STREAM
124    iso_init(int length)
125  {  {
126          STREAM s;          STREAM s;
127    
# Line 91  STREAM iso_init(int length) Line 132  STREAM iso_init(int length)
132  }  }
133    
134  /* Send an ISO data PDU */  /* Send an ISO data PDU */
135  void iso_send(STREAM s)  void
136    iso_send(STREAM s)
137  {  {
138          uint16 length;          uint16 length;
139    
# Line 110  void iso_send(STREAM s) Line 152  void iso_send(STREAM s)
152  }  }
153    
154  /* Receive ISO transport data packet */  /* Receive ISO transport data packet */
155  STREAM iso_recv()  STREAM
156    iso_recv(uint8 * rdpver)
157  {  {
158          STREAM s;          STREAM s;
159          uint8 code;          uint8 code = 0;
160    
161          s = iso_recv_msg(&code);          s = iso_recv_msg(&code, rdpver);
162          if ((s == NULL) || (code != ISO_PDU_DT))          if (s == NULL)
163                    return NULL;
164            if (rdpver != NULL)
165                    if (*rdpver != 3)
166                            return s;
167            if (code != ISO_PDU_DT)
168          {          {
169                  ERROR("expected DT, got %d\n", code);                  error("expected DT, got 0x%x\n", code);
170                  return False;                  return NULL;
171          }          }
   
172          return s;          return s;
173  }  }
174    
175  /* Establish a connection up to the ISO layer */  /* Establish a connection up to the ISO layer */
176  BOOL iso_connect(char *server)  RD_BOOL
177    iso_connect(char *server, char *username)
178    {
179            uint8 code = 0;
180    
181            if (!tcp_connect(server))
182                    return False;
183    
184            iso_send_connection_request(username);
185    
186            if (iso_recv_msg(&code, NULL) == NULL)
187                    return False;
188    
189            if (code != ISO_PDU_CC)
190            {
191                    error("expected CC, got 0x%x\n", code);
192                    tcp_disconnect();
193                    return False;
194            }
195    
196            return True;
197    }
198    
199    /* Establish a reconnection up to the ISO layer */
200    RD_BOOL
201    iso_reconnect(char *server)
202  {  {
203          uint8 code;          uint8 code = 0;
204    
205          if (!tcp_connect(server))          if (!tcp_connect(server))
206                  return False;                  return False;
207    
208          iso_send_msg(ISO_PDU_CR);          iso_send_msg(ISO_PDU_CR);
209    
210          if ((iso_recv_msg(&code) == NULL) || (code != ISO_PDU_CC))          if (iso_recv_msg(&code, NULL) == NULL)
211                    return False;
212    
213            if (code != ISO_PDU_CC)
214          {          {
215                  ERROR("expected CC, got %d\n", code);                  error("expected CC, got 0x%x\n", code);
216                  tcp_disconnect();                  tcp_disconnect();
217                  return False;                  return False;
218          }          }
# Line 146  BOOL iso_connect(char *server) Line 221  BOOL iso_connect(char *server)
221  }  }
222    
223  /* Disconnect from the ISO layer */  /* Disconnect from the ISO layer */
224  void iso_disconnect()  void
225    iso_disconnect(void)
226  {  {
227          iso_send_msg(ISO_PDU_DR);          iso_send_msg(ISO_PDU_DR);
228          tcp_disconnect();          tcp_disconnect();
229  }  }
230    
231    /* reset the state to support reconnecting */
232    void
233    iso_reset_state(void)
234    {
235            tcp_reset_state();
236    }

Legend:
Removed from v.24  
changed lines
  Added in v.1434

  ViewVC Help
Powered by ViewVC 1.1.26