1 |
/* -*- c-basic-offset: 8 -*- |
/* -*- c-basic-offset: 8 -*- |
2 |
rdesktop: A Remote Desktop Protocol client. |
rdesktop: A Remote Desktop Protocol client. |
3 |
Entrypoint and utility functions |
Entrypoint and utility functions |
4 |
Copyright (C) Matthew Chapman 1999-2003 |
Copyright (C) Matthew Chapman 1999-2005 |
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 |
30 |
#include <errno.h> |
#include <errno.h> |
31 |
#include "rdesktop.h" |
#include "rdesktop.h" |
32 |
|
|
33 |
|
#ifdef HAVE_LOCALE_H |
34 |
|
#include <locale.h> |
35 |
|
#endif |
36 |
|
#ifdef HAVE_ICONV |
37 |
|
#ifdef HAVE_LANGINFO_H |
38 |
|
#include <langinfo.h> |
39 |
|
#endif |
40 |
|
#endif |
41 |
|
|
42 |
#ifdef EGD_SOCKET |
#ifdef EGD_SOCKET |
43 |
|
#include <sys/types.h> |
44 |
#include <sys/socket.h> /* socket connect */ |
#include <sys/socket.h> /* socket connect */ |
45 |
#include <sys/un.h> /* sockaddr_un */ |
#include <sys/un.h> /* sockaddr_un */ |
46 |
#endif |
#endif |
47 |
|
|
|
#ifdef WITH_OPENSSL |
|
48 |
#include <openssl/md5.h> |
#include <openssl/md5.h> |
|
#else |
|
|
#include "crypto/md5.h" |
|
|
#endif |
|
49 |
|
|
50 |
char g_title[64] = ""; |
char g_title[64] = ""; |
51 |
char g_username[64]; |
char g_username[64]; |
52 |
char g_hostname[16]; |
char g_hostname[16]; |
53 |
char keymapname[16]; |
char g_keymapname[PATH_MAX] = ""; |
54 |
int g_keylayout = 0x409; /* Defaults to US keyboard layout */ |
unsigned int g_keylayout = 0x409; /* Defaults to US keyboard layout */ |
55 |
|
int g_keyboard_type = 0x4; /* Defaults to US keyboard layout */ |
56 |
|
int g_keyboard_subtype = 0x0; /* Defaults to US keyboard layout */ |
57 |
|
int g_keyboard_functionkeys = 0xc; /* Defaults to US keyboard layout */ |
58 |
|
|
59 |
int g_width = 800; /* width is special: If 0, the |
int g_width = 800; /* width is special: If 0, the |
60 |
geometry will be fetched from |
geometry will be fetched from |
62 |
absolute value specifies the |
absolute value specifies the |
63 |
percent of the whole screen. */ |
percent of the whole screen. */ |
64 |
int g_height = 600; |
int g_height = 600; |
65 |
|
int g_xpos = 0; |
66 |
|
int g_ypos = 0; |
67 |
|
int g_pos = 0; /* 0 position unspecified, |
68 |
|
1 specified, |
69 |
|
2 xpos neg, |
70 |
|
4 ypos neg */ |
71 |
extern int g_tcp_port_rdp; |
extern int g_tcp_port_rdp; |
72 |
int g_server_bpp = 8; |
int g_server_depth = -1; |
73 |
int g_win_button_size = 0; /* If zero, disable single app mode */ |
int g_win_button_size = 0; /* If zero, disable single app mode */ |
74 |
BOOL g_bitmap_compression = True; |
BOOL g_bitmap_compression = True; |
75 |
BOOL g_sendmotion = True; |
BOOL g_sendmotion = True; |
78 |
BOOL g_bitmap_cache_precache = True; |
BOOL g_bitmap_cache_precache = True; |
79 |
BOOL g_encryption = True; |
BOOL g_encryption = True; |
80 |
BOOL packet_encryption = True; |
BOOL packet_encryption = True; |
81 |
BOOL g_desktop_save = True; |
BOOL g_desktop_save = True; /* desktop save order */ |
82 |
|
BOOL g_polygon_ellipse_orders = True; /* polygon / ellipse orders */ |
83 |
BOOL g_fullscreen = False; |
BOOL g_fullscreen = False; |
84 |
BOOL g_grab_keyboard = True; |
BOOL g_grab_keyboard = True; |
85 |
BOOL g_hide_decorations = False; |
BOOL g_hide_decorations = False; |
86 |
BOOL g_use_rdp5 = True; |
BOOL g_use_rdp5 = True; |
87 |
|
BOOL g_rdpclip = True; |
88 |
BOOL g_console_session = False; |
BOOL g_console_session = False; |
89 |
BOOL g_numlock_sync = False; |
BOOL g_numlock_sync = False; |
90 |
|
BOOL lspci_enabled = False; |
91 |
BOOL g_owncolmap = False; |
BOOL g_owncolmap = False; |
92 |
BOOL g_ownbackstore = True; /* We can't rely on external BackingStore */ |
BOOL g_ownbackstore = True; /* We can't rely on external BackingStore */ |
93 |
|
BOOL g_seamless_rdp = False; |
94 |
uint32 g_embed_wnd; |
uint32 g_embed_wnd; |
95 |
uint32 g_rdp5_performanceflags = |
uint32 g_rdp5_performanceflags = |
96 |
RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS; |
RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS; |
97 |
|
/* Session Directory redirection */ |
98 |
|
BOOL g_redirect = False; |
99 |
|
char g_redirect_server[64]; |
100 |
|
char g_redirect_domain[16]; |
101 |
|
char g_redirect_password[64]; |
102 |
|
char g_redirect_username[64]; |
103 |
|
char g_redirect_cookie[128]; |
104 |
|
uint32 g_redirect_flags = 0; |
105 |
|
|
106 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
107 |
BOOL g_rdpsnd = False; |
BOOL g_rdpsnd = False; |
108 |
#endif |
#endif |
109 |
|
|
110 |
|
#ifdef HAVE_ICONV |
111 |
|
char g_codepage[16] = ""; |
112 |
|
#endif |
113 |
|
|
114 |
extern RDPDR_DEVICE g_rdpdr_device[]; |
extern RDPDR_DEVICE g_rdpdr_device[]; |
115 |
extern uint32 g_num_devices; |
extern uint32 g_num_devices; |
116 |
extern char *g_rdpdr_clientname; |
extern char *g_rdpdr_clientname; |
127 |
usage(char *program) |
usage(char *program) |
128 |
{ |
{ |
129 |
fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n"); |
fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n"); |
130 |
fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2003 Matt Chapman.\n"); |
fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2005 Matt Chapman.\n"); |
131 |
fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n"); |
fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n"); |
132 |
|
|
133 |
fprintf(stderr, "Usage: %s [options] server[:port]\n", program); |
fprintf(stderr, "Usage: %s [options] server[:port]\n", program); |
145 |
fprintf(stderr, " -g: desktop geometry (WxH)\n"); |
fprintf(stderr, " -g: desktop geometry (WxH)\n"); |
146 |
fprintf(stderr, " -f: full-screen mode\n"); |
fprintf(stderr, " -f: full-screen mode\n"); |
147 |
fprintf(stderr, " -b: force bitmap updates\n"); |
fprintf(stderr, " -b: force bitmap updates\n"); |
148 |
|
#ifdef HAVE_ICONV |
149 |
|
fprintf(stderr, " -L: local codepage\n"); |
150 |
|
#endif |
151 |
|
fprintf(stderr, " -A: enable SeamlessRDP mode\n"); |
152 |
fprintf(stderr, " -B: use BackingStore of X-server (if available)\n"); |
fprintf(stderr, " -B: use BackingStore of X-server (if available)\n"); |
153 |
fprintf(stderr, " -e: disable encryption (French TS)\n"); |
fprintf(stderr, " -e: disable encryption (French TS)\n"); |
154 |
fprintf(stderr, " -E: disable encryption from client to server\n"); |
fprintf(stderr, " -E: disable encryption from client to server\n"); |
161 |
fprintf(stderr, " -N: enable numlock syncronization\n"); |
fprintf(stderr, " -N: enable numlock syncronization\n"); |
162 |
fprintf(stderr, " -X: embed into another window with a given id.\n"); |
fprintf(stderr, " -X: embed into another window with a given id.\n"); |
163 |
fprintf(stderr, " -a: connection colour depth\n"); |
fprintf(stderr, " -a: connection colour depth\n"); |
164 |
|
fprintf(stderr, " -z: enable rdp compression\n"); |
165 |
fprintf(stderr, " -x: RDP5 experience (m[odem 28.8], b[roadband], l[an] or hex nr.)\n"); |
fprintf(stderr, " -x: RDP5 experience (m[odem 28.8], b[roadband], l[an] or hex nr.)\n"); |
166 |
fprintf(stderr, " -P: use persistent bitmap caching\n"); |
fprintf(stderr, " -P: use persistent bitmap caching\n"); |
167 |
fprintf(stderr, " -r: enable specified device redirection (this flag can be repeated)\n"); |
fprintf(stderr, " -r: enable specified device redirection (this flag can be repeated)\n"); |
169 |
" '-r comport:COM1=/dev/ttyS0': enable serial redirection of /dev/ttyS0 to COM1\n"); |
" '-r comport:COM1=/dev/ttyS0': enable serial redirection of /dev/ttyS0 to COM1\n"); |
170 |
fprintf(stderr, " or COM1=/dev/ttyS0,COM2=/dev/ttyS1\n"); |
fprintf(stderr, " or COM1=/dev/ttyS0,COM2=/dev/ttyS1\n"); |
171 |
fprintf(stderr, |
fprintf(stderr, |
172 |
" '-r disk:A=/mnt/floppy': enable redirection of /mnt/floppy to A:\n"); |
" '-r disk:floppy=/mnt/floppy': enable redirection of /mnt/floppy to 'floppy' share\n"); |
173 |
fprintf(stderr, " or A=/mnt/floppy,D=/mnt/cdrom'\n"); |
fprintf(stderr, " or 'floppy=/mnt/floppy,cdrom=/mnt/cdrom'\n"); |
174 |
fprintf(stderr, " '-r clientname=<client name>': Set the client name displayed\n"); |
fprintf(stderr, " '-r clientname=<client name>': Set the client name displayed\n"); |
175 |
fprintf(stderr, " for redirected disks\n"); |
fprintf(stderr, " for redirected disks\n"); |
176 |
fprintf(stderr, |
fprintf(stderr, |
179 |
fprintf(stderr, " '-r printer:mydeskjet': enable printer redirection\n"); |
fprintf(stderr, " '-r printer:mydeskjet': enable printer redirection\n"); |
180 |
fprintf(stderr, |
fprintf(stderr, |
181 |
" or mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n"); |
" or mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n"); |
182 |
fprintf(stderr, " '-r sound:[local|off|remote]': enable sound redirection\n"); |
#ifdef WITH_RDPSND |
183 |
|
fprintf(stderr, |
184 |
|
" '-r sound:[local[:driver[:device]]|off|remote]': enable sound redirection\n"); |
185 |
fprintf(stderr, " remote would leave sound on server\n"); |
fprintf(stderr, " remote would leave sound on server\n"); |
186 |
|
fprintf(stderr, " available drivers for 'local':\n"); |
187 |
|
rdpsnd_show_help(); |
188 |
|
#endif |
189 |
|
fprintf(stderr, |
190 |
|
" '-r clipboard:[off|PRIMARYCLIPBOARD|CLIPBOARD]': enable clipboard\n"); |
191 |
|
fprintf(stderr, " redirection.\n"); |
192 |
|
fprintf(stderr, |
193 |
|
" 'PRIMARYCLIPBOARD' looks at both PRIMARY and CLIPBOARD\n"); |
194 |
|
fprintf(stderr, " when sending data to server.\n"); |
195 |
|
fprintf(stderr, " 'CLIPBOARD' looks at only CLIPBOARD.\n"); |
196 |
fprintf(stderr, " -0: attach to console\n"); |
fprintf(stderr, " -0: attach to console\n"); |
197 |
fprintf(stderr, " -4: use RDP version 4\n"); |
fprintf(stderr, " -4: use RDP version 4\n"); |
198 |
fprintf(stderr, " -5: use RDP version 5 (default)\n"); |
fprintf(stderr, " -5: use RDP version 5 (default)\n"); |
199 |
} |
} |
200 |
|
|
201 |
void |
static void |
202 |
print_disconnect_reason(uint16 reason) |
print_disconnect_reason(uint16 reason) |
203 |
{ |
{ |
204 |
char *text; |
char *text; |
298 |
fprintf(stderr, "disconnect: %s.\n", text); |
fprintf(stderr, "disconnect: %s.\n", text); |
299 |
} |
} |
300 |
|
|
301 |
|
static void |
302 |
|
rdesktop_reset_state(void) |
303 |
|
{ |
304 |
|
rdp_reset_state(); |
305 |
|
} |
306 |
|
|
307 |
static BOOL |
static BOOL |
308 |
read_password(char *password, int size) |
read_password(char *password, int size) |
309 |
{ |
{ |
396 |
char fullhostname[64]; |
char fullhostname[64]; |
397 |
char domain[16]; |
char domain[16]; |
398 |
char password[64]; |
char password[64]; |
399 |
char shell[128]; |
char shell[256]; |
400 |
char directory[32]; |
char directory[256]; |
401 |
BOOL prompt_password, deactivated; |
BOOL prompt_password, deactivated; |
402 |
struct passwd *pw; |
struct passwd *pw; |
403 |
uint32 flags, ext_disc_reason = 0; |
uint32 flags, ext_disc_reason = 0; |
404 |
char *p; |
char *p; |
405 |
int c; |
int c; |
406 |
|
char *locale = NULL; |
407 |
int username_option = 0; |
int username_option = 0; |
408 |
|
BOOL geometry_option = False; |
409 |
|
int run_count = 0; /* Session Directory support */ |
410 |
|
BOOL continue_connect = True; /* Session Directory support */ |
411 |
|
|
412 |
|
#ifdef HAVE_LOCALE_H |
413 |
|
/* Set locale according to environment */ |
414 |
|
locale = setlocale(LC_ALL, ""); |
415 |
|
if (locale) |
416 |
|
{ |
417 |
|
locale = xstrdup(locale); |
418 |
|
} |
419 |
|
|
420 |
|
#endif |
421 |
flags = RDP_LOGON_NORMAL; |
flags = RDP_LOGON_NORMAL; |
422 |
prompt_password = False; |
prompt_password = False; |
423 |
domain[0] = password[0] = shell[0] = directory[0] = 0; |
domain[0] = password[0] = shell[0] = directory[0] = 0; |
|
strcpy(keymapname, "en-us"); |
|
424 |
g_embed_wnd = 0; |
g_embed_wnd = 0; |
425 |
|
|
426 |
g_num_devices = 0; |
g_num_devices = 0; |
432 |
#endif |
#endif |
433 |
|
|
434 |
while ((c = getopt(argc, argv, |
while ((c = getopt(argc, argv, |
435 |
VNCOPT "u:d:s:c:p:n:k:g:fbBeEmCDKS:T:NX:a:x:Pr:045h?")) != -1) |
VNCOPT "Au:L:d:s:c:p:n:k:g:fbBeEmzCDKS:T:NX:a:x:Pr:045h?")) != -1) |
436 |
{ |
{ |
437 |
switch (c) |
switch (c) |
438 |
{ |
{ |
450 |
break; |
break; |
451 |
#endif |
#endif |
452 |
|
|
453 |
|
case 'A': |
454 |
|
g_seamless_rdp = True; |
455 |
|
break; |
456 |
|
|
457 |
case 'u': |
case 'u': |
458 |
STRNCPY(g_username, optarg, sizeof(g_username)); |
STRNCPY(g_username, optarg, sizeof(g_username)); |
459 |
username_option = 1; |
username_option = 1; |
460 |
break; |
break; |
461 |
|
|
462 |
|
case 'L': |
463 |
|
#ifdef HAVE_ICONV |
464 |
|
STRNCPY(g_codepage, optarg, sizeof(g_codepage)); |
465 |
|
#else |
466 |
|
error("iconv support not available\n"); |
467 |
|
#endif |
468 |
|
break; |
469 |
|
|
470 |
case 'd': |
case 'd': |
471 |
STRNCPY(domain, optarg, sizeof(domain)); |
STRNCPY(domain, optarg, sizeof(domain)); |
472 |
break; |
break; |
500 |
break; |
break; |
501 |
|
|
502 |
case 'k': |
case 'k': |
503 |
STRNCPY(keymapname, optarg, sizeof(keymapname)); |
STRNCPY(g_keymapname, optarg, sizeof(g_keymapname)); |
504 |
break; |
break; |
505 |
|
|
506 |
case 'g': |
case 'g': |
507 |
|
geometry_option = True; |
508 |
g_fullscreen = False; |
g_fullscreen = False; |
509 |
if (!strcmp(optarg, "workarea")) |
if (!strcmp(optarg, "workarea")) |
510 |
{ |
{ |
520 |
} |
} |
521 |
|
|
522 |
if (*p == 'x') |
if (*p == 'x') |
523 |
g_height = strtol(p + 1, NULL, 10); |
g_height = strtol(p + 1, &p, 10); |
524 |
|
|
525 |
if (g_height <= 0) |
if (g_height <= 0) |
526 |
{ |
{ |
529 |
} |
} |
530 |
|
|
531 |
if (*p == '%') |
if (*p == '%') |
532 |
|
{ |
533 |
g_width = -g_width; |
g_width = -g_width; |
534 |
|
p++; |
535 |
|
} |
536 |
|
|
537 |
|
if (*p == '+' || *p == '-') |
538 |
|
{ |
539 |
|
g_pos |= (*p == '-') ? 2 : 1; |
540 |
|
g_xpos = strtol(p, &p, 10); |
541 |
|
|
542 |
|
} |
543 |
|
if (*p == '+' || *p == '-') |
544 |
|
{ |
545 |
|
g_pos |= (*p == '-') ? 4 : 1; |
546 |
|
g_ypos = strtol(p, NULL, 10); |
547 |
|
} |
548 |
|
|
549 |
break; |
break; |
550 |
|
|
608 |
break; |
break; |
609 |
|
|
610 |
case 'X': |
case 'X': |
611 |
g_embed_wnd = strtol(optarg, NULL, 10); |
g_embed_wnd = strtol(optarg, NULL, 0); |
612 |
break; |
break; |
613 |
|
|
614 |
case 'a': |
case 'a': |
615 |
g_server_bpp = strtol(optarg, NULL, 10); |
g_server_depth = strtol(optarg, NULL, 10); |
616 |
if (g_server_bpp != 8 && g_server_bpp != 16 && g_server_bpp != 15 |
if (g_server_depth != 8 && |
617 |
&& g_server_bpp != 24) |
g_server_depth != 16 && |
618 |
|
g_server_depth != 15 && g_server_depth != 24) |
619 |
{ |
{ |
620 |
error("invalid server bpp\n"); |
error("Invalid server colour depth.\n"); |
621 |
return 1; |
return 1; |
622 |
} |
} |
623 |
break; |
break; |
624 |
|
|
625 |
case 'x': |
case 'z': |
626 |
|
DEBUG(("rdp compression enabled\n")); |
627 |
|
flags |= (RDP_LOGON_COMPRESSION | RDP_LOGON_COMPRESSION2); |
628 |
|
break; |
629 |
|
|
630 |
if (strncmp("modem", optarg, 1) == 0) |
case 'x': |
631 |
|
if (str_startswith(optarg, "m")) /* modem */ |
632 |
{ |
{ |
633 |
g_rdp5_performanceflags = |
g_rdp5_performanceflags = |
634 |
RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | |
RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | |
635 |
RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING; |
RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING; |
636 |
} |
} |
637 |
else if (strncmp("broadband", optarg, 1) == 0) |
else if (str_startswith(optarg, "b")) /* broadband */ |
638 |
{ |
{ |
639 |
g_rdp5_performanceflags = RDP5_NO_WALLPAPER; |
g_rdp5_performanceflags = RDP5_NO_WALLPAPER; |
640 |
} |
} |
641 |
else if (strncmp("lan", optarg, 1) == 0) |
else if (str_startswith(optarg, "l")) /* lan */ |
642 |
{ |
{ |
643 |
g_rdp5_performanceflags = RDP5_DISABLE_NOTHING; |
g_rdp5_performanceflags = RDP5_DISABLE_NOTHING; |
644 |
} |
} |
654 |
|
|
655 |
case 'r': |
case 'r': |
656 |
|
|
657 |
if (strncmp("sound", optarg, 5) == 0) |
if (str_startswith(optarg, "sound")) |
658 |
{ |
{ |
659 |
optarg += 5; |
optarg += 5; |
660 |
|
|
661 |
if (*optarg == ':') |
if (*optarg == ':') |
662 |
{ |
{ |
663 |
*optarg++; |
optarg++; |
664 |
while ((p = next_arg(optarg, ','))) |
while ((p = next_arg(optarg, ','))) |
665 |
{ |
{ |
666 |
if (strncmp("remote", optarg, 6) == 0) |
if (str_startswith(optarg, "remote")) |
667 |
flags |= RDP_LOGON_LEAVE_AUDIO; |
flags |= RDP_LOGON_LEAVE_AUDIO; |
668 |
|
|
669 |
if (strncmp("local", optarg, 5) == 0) |
if (str_startswith(optarg, "local")) |
670 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
671 |
|
{ |
672 |
|
char *driver = NULL, *options = |
673 |
|
NULL; |
674 |
|
|
675 |
|
if ((driver = |
676 |
|
next_arg(optarg, ':'))) |
677 |
|
{ |
678 |
|
if (!strlen(driver)) |
679 |
|
{ |
680 |
|
driver = NULL; |
681 |
|
} |
682 |
|
else if ((options = |
683 |
|
next_arg(driver, |
684 |
|
':'))) |
685 |
|
{ |
686 |
|
if (!strlen |
687 |
|
(options)) |
688 |
|
options = |
689 |
|
NULL; |
690 |
|
} |
691 |
|
} |
692 |
|
|
693 |
g_rdpsnd = True; |
g_rdpsnd = True; |
694 |
|
if (!rdpsnd_select_driver |
695 |
|
(driver, options)) |
696 |
|
{ |
697 |
|
warning("Driver not available\n"); |
698 |
|
} |
699 |
|
} |
700 |
|
|
701 |
#else |
#else |
702 |
warning("Not compiled with sound support"); |
warning("Not compiled with sound support\n"); |
703 |
#endif |
#endif |
704 |
|
|
705 |
if (strncmp("off", optarg, 3) == 0) |
if (str_startswith(optarg, "off")) |
706 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
707 |
g_rdpsnd = False; |
g_rdpsnd = False; |
708 |
#else |
#else |
709 |
warning("Not compiled with sound support"); |
warning("Not compiled with sound support\n"); |
710 |
#endif |
#endif |
711 |
|
|
712 |
optarg = p; |
optarg = p; |
716 |
{ |
{ |
717 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
718 |
g_rdpsnd = True; |
g_rdpsnd = True; |
719 |
|
if (!rdpsnd_select_driver(NULL, NULL)) |
720 |
|
{ |
721 |
|
warning("No sound-driver available\n"); |
722 |
|
} |
723 |
#else |
#else |
724 |
warning("Not compiled with sound support"); |
warning("Not compiled with sound support\n"); |
725 |
#endif |
#endif |
726 |
} |
} |
727 |
} |
} |
728 |
else if (strncmp("disk", optarg, 4) == 0) |
else if (str_startswith(optarg, "disk")) |
729 |
{ |
{ |
730 |
/* -r disk:h:=/mnt/floppy */ |
/* -r disk:h:=/mnt/floppy */ |
731 |
disk_enum_devices(&g_num_devices, optarg + 4); |
disk_enum_devices(&g_num_devices, optarg + 4); |
732 |
} |
} |
733 |
else if (strncmp("comport", optarg, 7) == 0) |
else if (str_startswith(optarg, "comport")) |
734 |
{ |
{ |
735 |
serial_enum_devices(&g_num_devices, optarg + 7); |
serial_enum_devices(&g_num_devices, optarg + 7); |
736 |
} |
} |
737 |
else if (strncmp("lptport", optarg, 7) == 0) |
else if (str_startswith(optarg, "lspci")) |
738 |
|
{ |
739 |
|
lspci_enabled = True; |
740 |
|
} |
741 |
|
else if (str_startswith(optarg, "lptport")) |
742 |
{ |
{ |
743 |
parallel_enum_devices(&g_num_devices, optarg + 7); |
parallel_enum_devices(&g_num_devices, optarg + 7); |
744 |
} |
} |
745 |
else if (strncmp("printer", optarg, 7) == 0) |
else if (str_startswith(optarg, "printer")) |
746 |
{ |
{ |
747 |
printer_enum_devices(&g_num_devices, optarg + 7); |
printer_enum_devices(&g_num_devices, optarg + 7); |
748 |
} |
} |
749 |
else if (strncmp("clientname", optarg, 7) == 0) |
else if (str_startswith(optarg, "clientname")) |
750 |
{ |
{ |
751 |
g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1); |
g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1); |
752 |
strcpy(g_rdpdr_clientname, optarg + 11); |
strcpy(g_rdpdr_clientname, optarg + 11); |
753 |
} |
} |
754 |
|
else if (str_startswith(optarg, "clipboard")) |
755 |
|
{ |
756 |
|
optarg += 9; |
757 |
|
|
758 |
|
if (*optarg == ':') |
759 |
|
{ |
760 |
|
optarg++; |
761 |
|
|
762 |
|
if (str_startswith(optarg, "off")) |
763 |
|
g_rdpclip = False; |
764 |
|
else |
765 |
|
cliprdr_set_mode(optarg); |
766 |
|
} |
767 |
|
else |
768 |
|
g_rdpclip = True; |
769 |
|
} |
770 |
else |
else |
771 |
{ |
{ |
772 |
warning("Unknown -r argument\n\n\tPossible arguments are: comport, disk, lptport, printer, sound\n"); |
warning("Unknown -r argument\n\n\tPossible arguments are: comport, disk, lptport, printer, sound, clipboard\n"); |
773 |
} |
} |
774 |
break; |
break; |
775 |
|
|
802 |
STRNCPY(server, argv[optind], sizeof(server)); |
STRNCPY(server, argv[optind], sizeof(server)); |
803 |
parse_server_and_port(server); |
parse_server_and_port(server); |
804 |
|
|
805 |
|
if (g_seamless_rdp) |
806 |
|
{ |
807 |
|
if (g_win_button_size) |
808 |
|
{ |
809 |
|
error("You cannot use -S and -A at the same time\n"); |
810 |
|
return 1; |
811 |
|
} |
812 |
|
g_rdp5_performanceflags &= ~RDP5_NO_FULLWINDOWDRAG; |
813 |
|
if (geometry_option) |
814 |
|
{ |
815 |
|
error("You cannot use -g and -A at the same time\n"); |
816 |
|
return 1; |
817 |
|
} |
818 |
|
if (g_fullscreen) |
819 |
|
{ |
820 |
|
error("You cannot use -f and -A at the same time\n"); |
821 |
|
return 1; |
822 |
|
} |
823 |
|
if (g_hide_decorations) |
824 |
|
{ |
825 |
|
error("You cannot use -D and -A at the same time\n"); |
826 |
|
return 1; |
827 |
|
} |
828 |
|
if (g_embed_wnd) |
829 |
|
{ |
830 |
|
error("You cannot use -X and -A at the same time\n"); |
831 |
|
return 1; |
832 |
|
} |
833 |
|
if (!g_use_rdp5) |
834 |
|
{ |
835 |
|
error("You cannot use -4 and -A at the same time\n"); |
836 |
|
return 1; |
837 |
|
} |
838 |
|
g_width = -100; |
839 |
|
g_grab_keyboard = False; |
840 |
|
} |
841 |
|
|
842 |
if (!username_option) |
if (!username_option) |
843 |
{ |
{ |
844 |
pw = getpwuid(getuid()); |
pw = getpwuid(getuid()); |
851 |
STRNCPY(g_username, pw->pw_name, sizeof(g_username)); |
STRNCPY(g_username, pw->pw_name, sizeof(g_username)); |
852 |
} |
} |
853 |
|
|
854 |
|
#ifdef HAVE_ICONV |
855 |
|
if (g_codepage[0] == 0) |
856 |
|
{ |
857 |
|
if (setlocale(LC_CTYPE, "")) |
858 |
|
{ |
859 |
|
STRNCPY(g_codepage, nl_langinfo(CODESET), sizeof(g_codepage)); |
860 |
|
} |
861 |
|
else |
862 |
|
{ |
863 |
|
STRNCPY(g_codepage, DEFAULT_CODEPAGE, sizeof(g_codepage)); |
864 |
|
} |
865 |
|
} |
866 |
|
#endif |
867 |
|
|
868 |
if (g_hostname[0] == 0) |
if (g_hostname[0] == 0) |
869 |
{ |
{ |
870 |
if (gethostname(fullhostname, sizeof(fullhostname)) == -1) |
if (gethostname(fullhostname, sizeof(fullhostname)) == -1) |
880 |
STRNCPY(g_hostname, fullhostname, sizeof(g_hostname)); |
STRNCPY(g_hostname, fullhostname, sizeof(g_hostname)); |
881 |
} |
} |
882 |
|
|
883 |
|
if (g_keymapname[0] == 0) |
884 |
|
{ |
885 |
|
if (locale && xkeymap_from_locale(locale)) |
886 |
|
{ |
887 |
|
fprintf(stderr, "Autoselected keyboard map %s\n", g_keymapname); |
888 |
|
} |
889 |
|
else |
890 |
|
{ |
891 |
|
STRNCPY(g_keymapname, "en-us", sizeof(g_keymapname)); |
892 |
|
} |
893 |
|
} |
894 |
|
if (locale) |
895 |
|
xfree(locale); |
896 |
|
|
897 |
|
|
898 |
if (prompt_password && read_password(password, sizeof(password))) |
if (prompt_password && read_password(password, sizeof(password))) |
899 |
flags |= RDP_LOGON_AUTO; |
flags |= RDP_LOGON_AUTO; |
900 |
|
|
916 |
if (g_rdpsnd) |
if (g_rdpsnd) |
917 |
rdpsnd_init(); |
rdpsnd_init(); |
918 |
#endif |
#endif |
919 |
|
|
920 |
|
if (lspci_enabled) |
921 |
|
lspci_init(); |
922 |
|
|
923 |
rdpdr_init(); |
rdpdr_init(); |
924 |
|
|
925 |
if (!rdp_connect(server, flags, domain, password, shell, directory)) |
while (run_count < 2 && continue_connect) /* add support for Session Directory; only reconnect once */ |
926 |
return 1; |
{ |
927 |
|
if (run_count == 0) |
928 |
|
{ |
929 |
|
if (!rdp_connect(server, flags, domain, password, shell, directory)) |
930 |
|
return 1; |
931 |
|
} |
932 |
|
else if (!rdp_reconnect |
933 |
|
(server, flags, domain, password, shell, directory, g_redirect_cookie)) |
934 |
|
return 1; |
935 |
|
|
936 |
/* By setting encryption to False here, we have an encrypted login |
/* By setting encryption to False here, we have an encrypted login |
937 |
packet but unencrypted transfer of other packets */ |
packet but unencrypted transfer of other packets */ |
938 |
if (!packet_encryption) |
if (!packet_encryption) |
939 |
g_encryption = False; |
g_encryption = False; |
940 |
|
|
941 |
|
|
942 |
DEBUG(("Connection successful.\n")); |
DEBUG(("Connection successful.\n")); |
943 |
memset(password, 0, sizeof(password)); |
memset(password, 0, sizeof(password)); |
944 |
|
|
945 |
if (ui_create_window()) |
if (run_count == 0) |
946 |
{ |
if (!ui_create_window()) |
947 |
rdp_main_loop(&deactivated, &ext_disc_reason); |
continue_connect = False; |
948 |
ui_destroy_window(); |
|
949 |
|
if (continue_connect) |
950 |
|
rdp_main_loop(&deactivated, &ext_disc_reason); |
951 |
|
|
952 |
|
DEBUG(("Disconnecting...\n")); |
953 |
|
rdp_disconnect(); |
954 |
|
|
955 |
|
if ((g_redirect == True) && (run_count == 0)) /* Support for Session Directory */ |
956 |
|
{ |
957 |
|
/* reset state of major globals */ |
958 |
|
rdesktop_reset_state(); |
959 |
|
|
960 |
|
STRNCPY(domain, g_redirect_domain, sizeof(domain)); |
961 |
|
STRNCPY(g_username, g_redirect_username, sizeof(g_username)); |
962 |
|
STRNCPY(password, g_redirect_password, sizeof(password)); |
963 |
|
STRNCPY(server, g_redirect_server, sizeof(server)); |
964 |
|
flags |= RDP_LOGON_AUTO; |
965 |
|
|
966 |
|
g_redirect = False; |
967 |
|
} |
968 |
|
else |
969 |
|
{ |
970 |
|
continue_connect = False; |
971 |
|
ui_destroy_window(); |
972 |
|
break; |
973 |
|
} |
974 |
|
|
975 |
|
run_count++; |
976 |
} |
} |
977 |
|
|
|
DEBUG(("Disconnecting...\n")); |
|
|
rdp_disconnect(); |
|
978 |
cache_save_state(); |
cache_save_state(); |
979 |
ui_deinit(); |
ui_deinit(); |
980 |
|
|
1101 |
return mem; |
return mem; |
1102 |
} |
} |
1103 |
|
|
1104 |
|
/* strdup */ |
1105 |
|
char * |
1106 |
|
xstrdup(const char *s) |
1107 |
|
{ |
1108 |
|
char *mem = strdup(s); |
1109 |
|
if (mem == NULL) |
1110 |
|
{ |
1111 |
|
perror("strdup"); |
1112 |
|
exit(1); |
1113 |
|
} |
1114 |
|
return mem; |
1115 |
|
} |
1116 |
|
|
1117 |
/* realloc; exit if out of memory */ |
/* realloc; exit if out of memory */ |
1118 |
void * |
void * |
1119 |
xrealloc(void *oldmem, int size) |
xrealloc(void *oldmem, int size) |
1120 |
{ |
{ |
1121 |
void *mem = realloc(oldmem, size); |
void *mem; |
1122 |
|
|
1123 |
|
if (size < 1) |
1124 |
|
size = 1; |
1125 |
|
mem = realloc(oldmem, size); |
1126 |
if (mem == NULL) |
if (mem == NULL) |
1127 |
{ |
{ |
1128 |
error("xrealloc %d\n", size); |
error("xrealloc %d\n", size); |
1249 |
while (*(mvp + 1) != (char) 0x00) |
while (*(mvp + 1) != (char) 0x00) |
1250 |
{ |
{ |
1251 |
*mvp = *(mvp + 1); |
*mvp = *(mvp + 1); |
1252 |
*mvp++; |
mvp++; |
1253 |
} |
} |
1254 |
*mvp = (char) 0x00; |
*mvp = (char) 0x00; |
1255 |
p = nextval; |
p = nextval; |
1287 |
} |
} |
1288 |
|
|
1289 |
|
|
1290 |
|
BOOL |
1291 |
|
str_startswith(const char *s, const char *prefix) |
1292 |
|
{ |
1293 |
|
return (strncmp(s, prefix, strlen(prefix)) == 0); |
1294 |
|
} |
1295 |
|
|
1296 |
|
|
1297 |
|
/* Split input into lines, and call linehandler for each |
1298 |
|
line. Incomplete lines are saved in the rest variable, which should |
1299 |
|
initially point to NULL. When linehandler returns False, stop and |
1300 |
|
return False. Otherwise, return True. */ |
1301 |
|
BOOL |
1302 |
|
str_handle_lines(const char *input, char **rest, str_handle_lines_t linehandler, void *data) |
1303 |
|
{ |
1304 |
|
char *buf, *p; |
1305 |
|
char *oldrest; |
1306 |
|
size_t inputlen; |
1307 |
|
size_t buflen; |
1308 |
|
size_t restlen = 0; |
1309 |
|
BOOL ret = True; |
1310 |
|
|
1311 |
|
/* Copy data to buffer */ |
1312 |
|
inputlen = strlen(input); |
1313 |
|
if (*rest) |
1314 |
|
restlen = strlen(*rest); |
1315 |
|
buflen = restlen + inputlen + 1; |
1316 |
|
buf = (char *) xmalloc(buflen); |
1317 |
|
buf[0] = '\0'; |
1318 |
|
if (*rest) |
1319 |
|
STRNCPY(buf, *rest, buflen); |
1320 |
|
strncat(buf, input, inputlen); |
1321 |
|
p = buf; |
1322 |
|
|
1323 |
|
while (1) |
1324 |
|
{ |
1325 |
|
char *newline = strchr(p, '\n'); |
1326 |
|
if (newline) |
1327 |
|
{ |
1328 |
|
*newline = '\0'; |
1329 |
|
if (!linehandler(p, data)) |
1330 |
|
{ |
1331 |
|
p = newline + 1; |
1332 |
|
ret = False; |
1333 |
|
break; |
1334 |
|
} |
1335 |
|
p = newline + 1; |
1336 |
|
} |
1337 |
|
else |
1338 |
|
{ |
1339 |
|
break; |
1340 |
|
|
1341 |
|
} |
1342 |
|
} |
1343 |
|
|
1344 |
|
/* Save in rest */ |
1345 |
|
oldrest = *rest; |
1346 |
|
restlen = buf + buflen - p; |
1347 |
|
*rest = (char *) xmalloc(restlen); |
1348 |
|
STRNCPY((*rest), p, restlen); |
1349 |
|
xfree(oldrest); |
1350 |
|
|
1351 |
|
xfree(buf); |
1352 |
|
return ret; |
1353 |
|
} |
1354 |
|
|
1355 |
|
/* Execute the program specified by argv. For each line in |
1356 |
|
stdout/stderr output, call linehandler. Returns false on failure. */ |
1357 |
|
BOOL |
1358 |
|
subprocess(char *const argv[], str_handle_lines_t linehandler, void *data) |
1359 |
|
{ |
1360 |
|
pid_t child; |
1361 |
|
int fd[2]; |
1362 |
|
int n = 1; |
1363 |
|
char output[256]; |
1364 |
|
char *rest = NULL; |
1365 |
|
|
1366 |
|
if (pipe(fd) < 0) |
1367 |
|
{ |
1368 |
|
perror("pipe"); |
1369 |
|
return False; |
1370 |
|
} |
1371 |
|
|
1372 |
|
if ((child = fork()) < 0) |
1373 |
|
{ |
1374 |
|
perror("fork"); |
1375 |
|
return False; |
1376 |
|
} |
1377 |
|
|
1378 |
|
/* Child */ |
1379 |
|
if (child == 0) |
1380 |
|
{ |
1381 |
|
/* Close read end */ |
1382 |
|
close(fd[0]); |
1383 |
|
|
1384 |
|
/* Redirect stdout and stderr to pipe */ |
1385 |
|
dup2(fd[1], 1); |
1386 |
|
dup2(fd[1], 2); |
1387 |
|
|
1388 |
|
/* Execute */ |
1389 |
|
execvp(argv[0], argv); |
1390 |
|
perror("Error executing child"); |
1391 |
|
_exit(128); |
1392 |
|
} |
1393 |
|
|
1394 |
|
/* Parent. Close write end. */ |
1395 |
|
close(fd[1]); |
1396 |
|
while (n > 0) |
1397 |
|
{ |
1398 |
|
n = read(fd[0], output, 255); |
1399 |
|
output[n] = '\0'; |
1400 |
|
str_handle_lines(output, &rest, linehandler, data); |
1401 |
|
} |
1402 |
|
xfree(rest); |
1403 |
|
|
1404 |
|
return True; |
1405 |
|
} |
1406 |
|
|
1407 |
|
|
1408 |
/* not all clibs got ltoa */ |
/* not all clibs got ltoa */ |
1409 |
#define LTOA_BUFSIZE (sizeof(long) * 8 + 1) |
#define LTOA_BUFSIZE (sizeof(long) * 8 + 1) |
1410 |
|
|
1556 |
{ |
{ |
1557 |
char *home; |
char *home; |
1558 |
char fn[256]; |
char fn[256]; |
1559 |
int fd; |
int fd; |
1560 |
|
|
1561 |
home = getenv("HOME"); |
home = getenv("HOME"); |
1562 |
if (home == NULL) |
if (home == NULL) |
1572 |
void |
void |
1573 |
rd_close_file(int fd) |
rd_close_file(int fd) |
1574 |
{ |
{ |
1575 |
close(fd); |
close(fd); |
1576 |
} |
} |
1577 |
|
|
1578 |
/* read from file*/ |
/* read from file*/ |
1579 |
int |
int |
1580 |
rd_read_file(int fd, void *ptr, int len) |
rd_read_file(int fd, void *ptr, int len) |
1581 |
{ |
{ |
1582 |
return read(fd, ptr, len); |
return read(fd, ptr, len); |
1583 |
} |
} |
1584 |
|
|
1585 |
/* write to file */ |
/* write to file */ |
1586 |
int |
int |
1587 |
rd_write_file(int fd, void* ptr, int len) |
rd_write_file(int fd, void *ptr, int len) |
1588 |
{ |
{ |
1589 |
return write(fd, ptr, len); |
return write(fd, ptr, len); |
1590 |
} |
} |
1591 |
|
|
1592 |
/* move file pointer */ |
/* move file pointer */ |
1593 |
int |
int |
1594 |
rd_lseek_file(int fd, int offset) |
rd_lseek_file(int fd, int offset) |
1595 |
{ |
{ |
1596 |
return lseek(fd, offset, SEEK_SET); |
return lseek(fd, offset, SEEK_SET); |
1597 |
} |
} |
1598 |
|
|
1599 |
/* do a write lock on a file */ |
/* do a write lock on a file */ |