/[rdesktop]/sourceforge.net/trunk/rdesktop/rdesktop.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 /sourceforge.net/trunk/rdesktop/rdesktop.c

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

revision 424 by forsberg, Thu Jun 19 07:29:53 2003 UTC revision 547 by astrand, Mon Nov 10 15:09:49 2003 UTC
# Line 40  Line 40 
40  #include "crypto/md5.h"  #include "crypto/md5.h"
41  #endif  #endif
42    
43  char title[32] = "";  char g_title[64] = "";
44  char username[16];  char g_username[64];
45  char hostname[16];  char hostname[16];
46  char keymapname[16];  char keymapname[16];
47  int keylayout = 0x409;          /* Defaults to US keyboard layout */  int keylayout = 0x409;          /* Defaults to US keyboard layout */
48  int width = 800;                /* If width or height are reset to zero, the geometry will  
49                                     be fetched from _NET_WORKAREA */  int g_width = 800;              /* width is special: If 0, the
50  int height = 600;                                     geometry will be fetched from
51                                       _NET_WORKAREA. If negative,
52                                       absolute value specifies the
53                                       percent of the whole screen. */
54    int g_height = 600;
55  int tcp_port_rdp = TCP_PORT_RDP;  int tcp_port_rdp = TCP_PORT_RDP;
56  int server_bpp = 8;  int g_server_bpp = 8;
57  int win_button_size = 0;        /* If zero, disable single app mode */  int g_win_button_size = 0;      /* If zero, disable single app mode */
58  BOOL bitmap_compression = True;  BOOL g_bitmap_compression = True;
59  BOOL sendmotion = True;  BOOL g_sendmotion = True;
60  BOOL orders = True;  BOOL g_orders = True;
61  BOOL encryption = True;  BOOL g_encryption = True;
62  BOOL desktop_save = True;  BOOL packet_encryption = True;
63  BOOL fullscreen = False;  BOOL g_desktop_save = True;
64  BOOL grab_keyboard = True;  BOOL g_fullscreen = False;
65  BOOL hide_decorations = False;  BOOL g_grab_keyboard = True;
66  BOOL use_rdp5 = False;  BOOL g_hide_decorations = False;
67  extern BOOL owncolmap;  BOOL g_use_rdp5 = True;
68    BOOL g_console_session = False;
69    extern BOOL g_owncolmap;
70    
71    #ifdef WITH_RDPSND
72    BOOL g_rdpsnd = False;
73    #endif
74    
75  #ifdef RDP2VNC  #ifdef RDP2VNC
76  extern int rfb_port;  extern int rfb_port;
# Line 80  usage(char *program) Line 90  usage(char *program)
90          fprintf(stderr, "Usage: %s [options] server[:port]\n", program);          fprintf(stderr, "Usage: %s [options] server[:port]\n", program);
91  #ifdef RDP2VNC  #ifdef RDP2VNC
92          fprintf(stderr, "   -V: vnc port\n");          fprintf(stderr, "   -V: vnc port\n");
93          fprintf(stderr, "   -E: defer time (ms)\n");          fprintf(stderr, "   -Q: defer time (ms)\n");
94  #endif  #endif
95          fprintf(stderr, "   -u: user name\n");          fprintf(stderr, "   -u: user name\n");
96          fprintf(stderr, "   -d: domain\n");          fprintf(stderr, "   -d: domain\n");
97          fprintf(stderr, "   -s: shell\n");          fprintf(stderr, "   -s: shell\n");
         fprintf(stderr, "   -S: caption button size (single application mode)\n");  
98          fprintf(stderr, "   -c: working directory\n");          fprintf(stderr, "   -c: working directory\n");
99          fprintf(stderr, "   -p: password (- to prompt)\n");          fprintf(stderr, "   -p: password (- to prompt)\n");
100          fprintf(stderr, "   -n: client hostname\n");          fprintf(stderr, "   -n: client hostname\n");
101          fprintf(stderr, "   -k: keyboard layout on terminal server (us,sv,gr,etc.)\n");          fprintf(stderr, "   -k: keyboard layout on server (en-us, de, sv, etc.)\n");
102          fprintf(stderr, "   -g: desktop geometry (WxH)\n");          fprintf(stderr, "   -g: desktop geometry (WxH)\n");
103          fprintf(stderr, "   -f: full-screen mode\n");          fprintf(stderr, "   -f: full-screen mode\n");
104          fprintf(stderr, "   -b: force bitmap updates\n");          fprintf(stderr, "   -b: force bitmap updates\n");
105          fprintf(stderr, "   -e: disable encryption (French TS)\n");          fprintf(stderr, "   -e: disable encryption (French TS)\n");
106            fprintf(stderr, "   -E: disable encryption from client to server\n");
107          fprintf(stderr, "   -m: do not send motion events\n");          fprintf(stderr, "   -m: do not send motion events\n");
108          fprintf(stderr, "   -C: use private colour map\n");          fprintf(stderr, "   -C: use private colour map\n");
109            fprintf(stderr, "   -D: hide window manager decorations\n");
110          fprintf(stderr, "   -K: keep window manager key bindings\n");          fprintf(stderr, "   -K: keep window manager key bindings\n");
111            fprintf(stderr, "   -S: caption button size (single application mode)\n");
112          fprintf(stderr, "   -T: window title\n");          fprintf(stderr, "   -T: window title\n");
113          fprintf(stderr, "   -D: hide window manager decorations\n");          fprintf(stderr, "   -a: connection colour depth\n");
114          fprintf(stderr, "   -a: server bpp\n");          fprintf(stderr, "   -r: enable specified device redirection (currently: sound)\n");
115          fprintf(stderr, "   -5: Use RDP5 (EXPERIMENTAL!)\n");          fprintf(stderr, "   -0: attach to console\n");
116            fprintf(stderr, "   -4: use RDP version 4\n");
117            fprintf(stderr, "   -5: use RDP version 5 (default)\n");
118  }  }
119    
120  static BOOL  static BOOL
# Line 139  read_password(char *password, int size) Line 153  read_password(char *password, int size)
153          return ret;          return ret;
154  }  }
155    
156    static void
157    parse_server_and_port(char *server)
158    {
159            char *p;
160    #ifdef IPv6
161            int addr_colons;
162    #endif
163    
164    #ifdef IPv6
165            p = server;
166            addr_colons = 0;
167            while (*p)
168                    if (*p++ == ':')
169                            addr_colons++;
170            if (addr_colons >= 2)
171            {
172                    /* numeric IPv6 style address format - [1:2:3::4]:port */
173                    p = strchr(server, ']');
174                    if (*server == '[' && p != NULL)
175                    {
176                            if (*(p + 1) == ':' && *(p + 2) != '\0')
177                                    tcp_port_rdp = strtol(p + 2, NULL, 10);
178                            /* remove the port number and brackets from the address */
179                            *p = '\0';
180                            strncpy(server, server + 1, strlen(server));
181                    }
182            }
183            else
184            {
185                    /* dns name or IPv4 style address format - server.example.com:port or 1.2.3.4:port */
186                    p = strchr(server, ':');
187                    if (p != NULL)
188                    {
189                            tcp_port_rdp = strtol(p + 1, NULL, 10);
190                            *p = 0;
191                    }
192            }
193    #else /* no IPv6 support */
194            p = strchr(server, ':');
195            if (p != NULL)
196            {
197                    tcp_port_rdp = strtol(p + 1, NULL, 10);
198                    *p = 0;
199            }
200    #endif /* IPv6 */
201    
202    }
203    
204  /* Client program */  /* Client program */
205  int  int
206  main(int argc, char *argv[])  main(int argc, char *argv[])
# Line 146  main(int argc, char *argv[]) Line 208  main(int argc, char *argv[])
208          char server[64];          char server[64];
209          char fullhostname[64];          char fullhostname[64];
210          char domain[16];          char domain[16];
211          char password[16];          char password[64];
212          char shell[128];          char shell[128];
213          char directory[32];          char directory[32];
214          BOOL prompt_password, rdp_retval = False;          BOOL prompt_password, rdp_retval = False;
# Line 162  main(int argc, char *argv[]) Line 224  main(int argc, char *argv[])
224          strcpy(keymapname, "en-us");          strcpy(keymapname, "en-us");
225    
226  #ifdef RDP2VNC  #ifdef RDP2VNC
227  #define VNCOPT "V:E:"  #define VNCOPT "V:Q:"
228  #else  #else
229  #define VNCOPT  #define VNCOPT
230  #endif  #endif
231    
232          while ((c = getopt(argc, argv, VNCOPT "u:d:s:S:c:p:n:k:g:a:fbemCKT:Dh?54")) != -1)          while ((c = getopt(argc, argv, VNCOPT "u:d:s:c:p:n:k:g:fbeEmCDKS:T:a:r:045h?")) != -1)
233          {          {
234                  switch (c)                  switch (c)
235                  {                  {
# Line 178  main(int argc, char *argv[]) Line 240  main(int argc, char *argv[])
240                                          rfb_port += 5900;                                          rfb_port += 5900;
241                                  break;                                  break;
242    
243                          case 'E':                          case 'Q':
244                                  defer_time = strtol(optarg, NULL, 10);                                  defer_time = strtol(optarg, NULL, 10);
245                                  if (defer_time < 0)                                  if (defer_time < 0)
246                                          defer_time = 0;                                          defer_time = 0;
# Line 186  main(int argc, char *argv[]) Line 248  main(int argc, char *argv[])
248  #endif  #endif
249    
250                          case 'u':                          case 'u':
251                                  STRNCPY(username, optarg, sizeof(username));                                  STRNCPY(g_username, optarg, sizeof(g_username));
252                                  username_option = 1;                                  username_option = 1;
253                                  break;                                  break;
254    
# Line 198  main(int argc, char *argv[]) Line 260  main(int argc, char *argv[])
260                                  STRNCPY(shell, optarg, sizeof(shell));                                  STRNCPY(shell, optarg, sizeof(shell));
261                                  break;                                  break;
262    
                         case 'S':  
                                 if (!strcmp(optarg, "standard"))  
                                 {  
                                         win_button_size = 18;  
                                         break;  
                                 }  
   
                                 win_button_size = strtol(optarg, &p, 10);  
   
                                 if (*p)  
                                 {  
                                         error("invalid button size\n");  
                                         return 1;  
                                 }  
   
                                 break;  
   
263                          case 'c':                          case 'c':
264                                  STRNCPY(directory, optarg, sizeof(directory));                                  STRNCPY(directory, optarg, sizeof(directory));
265                                  break;                                  break;
# Line 244  main(int argc, char *argv[]) Line 289  main(int argc, char *argv[])
289                                  break;                                  break;
290    
291                          case 'g':                          case 'g':
292                                    g_fullscreen = False;
293                                  if (!strcmp(optarg, "workarea"))                                  if (!strcmp(optarg, "workarea"))
294                                  {                                  {
295                                          width = height = 0;                                          g_width = g_height = 0;
296                                          break;                                          break;
297                                  }                                  }
298    
299                                  width = strtol(optarg, &p, 10);                                  g_width = strtol(optarg, &p, 10);
300                                    if (g_width <= 0)
301                                    {
302                                            error("invalid geometry\n");
303                                            return 1;
304                                    }
305    
306                                  if (*p == 'x')                                  if (*p == 'x')
307                                          height = strtol(p + 1, NULL, 10);                                          g_height = strtol(p + 1, NULL, 10);
308    
309                                  if ((width == 0) || (height == 0))                                  if (g_height <= 0)
310                                  {                                  {
311                                          error("invalid geometry\n");                                          error("invalid geometry\n");
312                                          return 1;                                          return 1;
313                                  }                                  }
314    
315                                    if (*p == '%')
316                                            g_width = -g_width;
317    
318                                  break;                                  break;
319    
320                          case 'f':                          case 'f':
321                                  fullscreen = True;                                  g_fullscreen = True;
322                                  break;                                  break;
323    
324                          case 'b':                          case 'b':
325                                  orders = False;                                  g_orders = False;
326                                  break;                                  break;
327    
328                          case 'e':                          case 'e':
329                                  encryption = False;                                  g_encryption = False;
330                                    break;
331                            case 'E':
332                                    packet_encryption = False;
333                                  break;                                  break;
   
334                          case 'm':                          case 'm':
335                                  sendmotion = False;                                  g_sendmotion = False;
336                                  break;                                  break;
337    
338                          case 'C':                          case 'C':
339                                  owncolmap = True;                                  g_owncolmap = True;
340                                    break;
341    
342                            case 'D':
343                                    g_hide_decorations = True;
344                                  break;                                  break;
345    
346                          case 'K':                          case 'K':
347                                  grab_keyboard = False;                                  g_grab_keyboard = False;
348                                  break;                                  break;
349    
350                          case 'T':                          case 'S':
351                                  STRNCPY(title, optarg, sizeof(title));                                  if (!strcmp(optarg, "standard"))
352                                    {
353                                            g_win_button_size = 18;
354                                            break;
355                                    }
356    
357                                    g_win_button_size = strtol(optarg, &p, 10);
358    
359                                    if (*p)
360                                    {
361                                            error("invalid button size\n");
362                                            return 1;
363                                    }
364    
365                                  break;                                  break;
366    
367                          case 'D':                          case 'T':
368                                  hide_decorations = True;                                  STRNCPY(g_title, optarg, sizeof(g_title));
369                                  break;                                  break;
370    
371                          case 'a':                          case 'a':
372                                  server_bpp = strtol(optarg, NULL, 10);                                  g_server_bpp = strtol(optarg, NULL, 10);
373                                  if (server_bpp != 8 && server_bpp != 16 && server_bpp != 15                                  if (g_server_bpp != 8 && g_server_bpp != 16 && g_server_bpp != 15
374                                      && server_bpp != 24)                                      && g_server_bpp != 24)
375                                  {                                  {
376                                          error("invalid server bpp\n");                                          error("invalid server bpp\n");
377                                          return 1;                                          return 1;
378                                  }                                  }
379                                  break;                                  break;
380    
381                            case 'r':
382                                    if (!strcmp(optarg, "sound"))
383    #ifdef WITH_RDPSND
384                                            g_rdpsnd = True;
385    #else
386                                            warning("Not compiled with sound support");
387    #endif
388                                    break;
389    
390                            case '0':
391                                    g_console_session = True;
392                                    break;
393    
394                            case '4':
395                                    g_use_rdp5 = False;
396                                    break;
397    
398                          case '5':                          case '5':
399                                  use_rdp5 = True;                                  g_use_rdp5 = True;
400                                  break;                                  break;
401    
402                          case 'h':                          case 'h':
403                          case '?':                          case '?':
404                          default:                          default:
# Line 321  main(int argc, char *argv[]) Line 414  main(int argc, char *argv[])
414          }          }
415    
416          STRNCPY(server, argv[optind], sizeof(server));          STRNCPY(server, argv[optind], sizeof(server));
417          p = strchr(server, ':');          parse_server_and_port(server);
         if (p != NULL)  
         {  
                 tcp_port_rdp = strtol(p + 1, NULL, 10);  
                 *p = 0;  
         }  
418    
419          if (!username_option)          if (!username_option)
420          {          {
# Line 337  main(int argc, char *argv[]) Line 425  main(int argc, char *argv[])
425                          return 1;                          return 1;
426                  }                  }
427    
428                  STRNCPY(username, pw->pw_name, sizeof(username));                  STRNCPY(g_username, pw->pw_name, sizeof(g_username));
429          }          }
430    
431          if (hostname[0] == 0)          if (hostname[0] == 0)
# Line 358  main(int argc, char *argv[]) Line 446  main(int argc, char *argv[])
446          if (prompt_password && read_password(password, sizeof(password)))          if (prompt_password && read_password(password, sizeof(password)))
447                  flags |= RDP_LOGON_AUTO;                  flags |= RDP_LOGON_AUTO;
448    
449          if (title[0] == 0)          if (g_title[0] == 0)
450          {          {
451                  strcpy(title, "rdesktop - ");                  strcpy(g_title, "rdesktop - ");
452                  strncat(title, server, sizeof(title) - sizeof("rdesktop - "));                  strncat(g_title, server, sizeof(g_title) - sizeof("rdesktop - "));
453          }          }
454    
455  #ifdef RDP2VNC  #ifdef RDP2VNC
# Line 372  main(int argc, char *argv[]) Line 460  main(int argc, char *argv[])
460          if (!ui_init())          if (!ui_init())
461                  return 1;                  return 1;
462    
463          ipc_init();             // Must be run after ui_init, we need X to be setup.  #ifdef WITH_RDPSND
464            if (g_rdpsnd)
465          if (use_rdp5)                  rdpsnd_init();
466                  cliprdr_init(); // FIXME: Should perhaps be integrated into the channel management code?  #endif
467            /* rdpdr_init(); */
468    
469          if (!rdp_connect(server, flags, domain, password, shell, directory))          if (!rdp_connect(server, flags, domain, password, shell, directory))
470                  return 1;                  return 1;
471    
472            /* By setting encryption to False here, we have an encrypted login
473               packet but unencrypted transfer of other packets */
474            if (!packet_encryption)
475                    g_encryption = False;
476    
477    
478          DEBUG(("Connection successful.\n"));          DEBUG(("Connection successful.\n"));
479          memset(password, 0, sizeof(password));          memset(password, 0, sizeof(password));
480    
# Line 393  main(int argc, char *argv[]) Line 488  main(int argc, char *argv[])
488          rdp_disconnect();          rdp_disconnect();
489          ui_deinit();          ui_deinit();
490    
491          if (True == rdp_retval)          if (True == rdp_retval)
492                  return 0;                  return 0;
493          else          else
494                  return 2;                  return 2;

Legend:
Removed from v.424  
changed lines
  Added in v.547

  ViewVC Help
Powered by ViewVC 1.1.26