27 |
#include <sys/time.h> /* gettimeofday */ |
#include <sys/time.h> /* gettimeofday */ |
28 |
#include <sys/times.h> /* times */ |
#include <sys/times.h> /* times */ |
29 |
#include <ctype.h> /* toupper */ |
#include <ctype.h> /* toupper */ |
|
#include <limits.h> /* PATH_MAX */ |
|
30 |
#include <errno.h> |
#include <errno.h> |
31 |
#include "rdesktop.h" |
#include "rdesktop.h" |
32 |
|
|
51 |
char g_username[64]; |
char g_username[64]; |
52 |
char g_hostname[16]; |
char g_hostname[16]; |
53 |
char g_keymapname[PATH_MAX] = ""; |
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 */ |
int g_keyboard_type = 0x4; /* Defaults to US keyboard layout */ |
56 |
int g_keyboard_subtype = 0x0; /* Defaults to US keyboard layout */ |
int g_keyboard_subtype = 0x0; /* Defaults to US keyboard layout */ |
57 |
int g_keyboard_functionkeys = 0xc; /* Defaults to US keyboard layout */ |
int g_keyboard_functionkeys = 0xc; /* Defaults to US keyboard layout */ |
69 |
2 xpos neg, |
2 xpos neg, |
70 |
4 ypos neg */ |
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 = 8; |
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; |
86 |
BOOL g_use_rdp5 = True; |
BOOL g_use_rdp5 = True; |
87 |
BOOL g_console_session = False; |
BOOL g_console_session = False; |
88 |
BOOL g_numlock_sync = False; |
BOOL g_numlock_sync = False; |
89 |
|
BOOL lspci_enabled = False; |
90 |
BOOL g_owncolmap = False; |
BOOL g_owncolmap = False; |
91 |
BOOL g_ownbackstore = True; /* We can't rely on external BackingStore */ |
BOOL g_ownbackstore = True; /* We can't rely on external BackingStore */ |
92 |
uint32 g_embed_wnd; |
uint32 g_embed_wnd; |
93 |
uint32 g_rdp5_performanceflags = |
uint32 g_rdp5_performanceflags = |
94 |
RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS; |
RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS; |
95 |
|
/* Session Directory redirection */ |
96 |
|
BOOL g_redirect = False; |
97 |
|
char g_redirect_server[64]; |
98 |
|
char g_redirect_domain[16]; |
99 |
|
char g_redirect_password[64]; |
100 |
|
char g_redirect_username[64]; |
101 |
|
char g_redirect_cookie[128]; |
102 |
|
uint32 g_redirect_flags = 0; |
103 |
|
|
104 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
105 |
BOOL g_rdpsnd = False; |
BOOL g_rdpsnd = False; |
283 |
fprintf(stderr, "disconnect: %s.\n", text); |
fprintf(stderr, "disconnect: %s.\n", text); |
284 |
} |
} |
285 |
|
|
286 |
|
static void |
287 |
|
rdesktop_reset_state(void) |
288 |
|
{ |
289 |
|
rdp_reset_state(); |
290 |
|
} |
291 |
|
|
292 |
static BOOL |
static BOOL |
293 |
read_password(char *password, int size) |
read_password(char *password, int size) |
294 |
{ |
{ |
381 |
char fullhostname[64]; |
char fullhostname[64]; |
382 |
char domain[16]; |
char domain[16]; |
383 |
char password[64]; |
char password[64]; |
384 |
char shell[128]; |
char shell[256]; |
385 |
char directory[32]; |
char directory[256]; |
386 |
BOOL prompt_password, deactivated; |
BOOL prompt_password, deactivated; |
387 |
struct passwd *pw; |
struct passwd *pw; |
388 |
uint32 flags, ext_disc_reason = 0; |
uint32 flags, ext_disc_reason = 0; |
390 |
int c; |
int c; |
391 |
char *locale = NULL; |
char *locale = NULL; |
392 |
int username_option = 0; |
int username_option = 0; |
393 |
|
int run_count = 0; /* Session Directory support */ |
394 |
|
BOOL continue_connect = True; /* Session Directory support */ |
395 |
|
|
396 |
#ifdef HAVE_LOCALE_H |
#ifdef HAVE_LOCALE_H |
397 |
/* Set locale according to environment */ |
/* Set locale according to environment */ |
591 |
break; |
break; |
592 |
|
|
593 |
case 'a': |
case 'a': |
594 |
g_server_bpp = strtol(optarg, NULL, 10); |
g_server_depth = strtol(optarg, NULL, 10); |
595 |
if (g_server_bpp != 8 && g_server_bpp != 16 && g_server_bpp != 15 |
if (g_server_depth != 8 && |
596 |
&& g_server_bpp != 24) |
g_server_depth != 16 && |
597 |
|
g_server_depth != 15 && g_server_depth != 24) |
598 |
{ |
{ |
599 |
error("invalid server bpp\n"); |
error("Invalid server colour depth.\n"); |
600 |
return 1; |
return 1; |
601 |
} |
} |
602 |
break; |
break; |
607 |
break; |
break; |
608 |
|
|
609 |
case 'x': |
case 'x': |
610 |
if (strncmp("modem", optarg, 1) == 0) |
if (str_startswith(optarg, "m")) /* modem */ |
611 |
{ |
{ |
612 |
g_rdp5_performanceflags = |
g_rdp5_performanceflags = |
613 |
RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | |
RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | |
614 |
RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING; |
RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING; |
615 |
} |
} |
616 |
else if (strncmp("broadband", optarg, 1) == 0) |
else if (str_startswith(optarg, "b")) /* broadband */ |
617 |
{ |
{ |
618 |
g_rdp5_performanceflags = RDP5_NO_WALLPAPER; |
g_rdp5_performanceflags = RDP5_NO_WALLPAPER; |
619 |
} |
} |
620 |
else if (strncmp("lan", optarg, 1) == 0) |
else if (str_startswith(optarg, "l")) /* lan */ |
621 |
{ |
{ |
622 |
g_rdp5_performanceflags = RDP5_DISABLE_NOTHING; |
g_rdp5_performanceflags = RDP5_DISABLE_NOTHING; |
623 |
} |
} |
633 |
|
|
634 |
case 'r': |
case 'r': |
635 |
|
|
636 |
if (strncmp("sound", optarg, 5) == 0) |
if (str_startswith(optarg, "sound")) |
637 |
{ |
{ |
638 |
optarg += 5; |
optarg += 5; |
639 |
|
|
642 |
*optarg++; |
*optarg++; |
643 |
while ((p = next_arg(optarg, ','))) |
while ((p = next_arg(optarg, ','))) |
644 |
{ |
{ |
645 |
if (strncmp("remote", optarg, 6) == 0) |
if (str_startswith(optarg, "remote")) |
646 |
flags |= RDP_LOGON_LEAVE_AUDIO; |
flags |= RDP_LOGON_LEAVE_AUDIO; |
647 |
|
|
648 |
if (strncmp("local", optarg, 5) == 0) |
if (str_startswith(optarg, "local")) |
649 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
650 |
g_rdpsnd = True; |
g_rdpsnd = True; |
651 |
#else |
#else |
652 |
warning("Not compiled with sound support\n"); |
warning("Not compiled with sound support\n"); |
653 |
#endif |
#endif |
654 |
|
|
655 |
if (strncmp("off", optarg, 3) == 0) |
if (str_startswith(optarg, "off")) |
656 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
657 |
g_rdpsnd = False; |
g_rdpsnd = False; |
658 |
#else |
#else |
671 |
#endif |
#endif |
672 |
} |
} |
673 |
} |
} |
674 |
else if (strncmp("disk", optarg, 4) == 0) |
else if (str_startswith(optarg, "disk")) |
675 |
{ |
{ |
676 |
/* -r disk:h:=/mnt/floppy */ |
/* -r disk:h:=/mnt/floppy */ |
677 |
disk_enum_devices(&g_num_devices, optarg + 4); |
disk_enum_devices(&g_num_devices, optarg + 4); |
678 |
} |
} |
679 |
else if (strncmp("comport", optarg, 7) == 0) |
else if (str_startswith(optarg, "comport")) |
680 |
{ |
{ |
681 |
serial_enum_devices(&g_num_devices, optarg + 7); |
serial_enum_devices(&g_num_devices, optarg + 7); |
682 |
} |
} |
683 |
else if (strncmp("lptport", optarg, 7) == 0) |
else if (str_startswith(optarg, "lspci")) |
684 |
|
{ |
685 |
|
lspci_enabled = True; |
686 |
|
} |
687 |
|
else if (str_startswith(optarg, "lptport")) |
688 |
{ |
{ |
689 |
parallel_enum_devices(&g_num_devices, optarg + 7); |
parallel_enum_devices(&g_num_devices, optarg + 7); |
690 |
} |
} |
691 |
else if (strncmp("printer", optarg, 7) == 0) |
else if (str_startswith(optarg, "printer")) |
692 |
{ |
{ |
693 |
printer_enum_devices(&g_num_devices, optarg + 7); |
printer_enum_devices(&g_num_devices, optarg + 7); |
694 |
} |
} |
695 |
else if (strncmp("clientname", optarg, 7) == 0) |
else if (str_startswith(optarg, "clientname")) |
696 |
{ |
{ |
697 |
g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1); |
g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1); |
698 |
strcpy(g_rdpdr_clientname, optarg + 11); |
strcpy(g_rdpdr_clientname, optarg + 11); |
809 |
if (g_rdpsnd) |
if (g_rdpsnd) |
810 |
rdpsnd_init(); |
rdpsnd_init(); |
811 |
#endif |
#endif |
812 |
|
|
813 |
|
if (lspci_enabled) |
814 |
|
lspci_init(); |
815 |
|
|
816 |
rdpdr_init(); |
rdpdr_init(); |
817 |
|
|
818 |
if (!rdp_connect(server, flags, domain, password, shell, directory)) |
while (run_count < 2 && continue_connect) /* add support for Session Directory; only reconnect once */ |
819 |
return 1; |
{ |
820 |
|
if (run_count == 0) |
821 |
|
{ |
822 |
|
if (!rdp_connect(server, flags, domain, password, shell, directory)) |
823 |
|
return 1; |
824 |
|
} |
825 |
|
else if (!rdp_reconnect |
826 |
|
(server, flags, domain, password, shell, directory, g_redirect_cookie)) |
827 |
|
return 1; |
828 |
|
|
829 |
/* By setting encryption to False here, we have an encrypted login |
/* By setting encryption to False here, we have an encrypted login |
830 |
packet but unencrypted transfer of other packets */ |
packet but unencrypted transfer of other packets */ |
831 |
if (!packet_encryption) |
if (!packet_encryption) |
832 |
g_encryption = False; |
g_encryption = False; |
833 |
|
|
834 |
|
|
835 |
DEBUG(("Connection successful.\n")); |
DEBUG(("Connection successful.\n")); |
836 |
memset(password, 0, sizeof(password)); |
memset(password, 0, sizeof(password)); |
837 |
|
|
838 |
if (ui_create_window()) |
if (run_count == 0) |
839 |
{ |
if (!ui_create_window()) |
840 |
rdp_main_loop(&deactivated, &ext_disc_reason); |
continue_connect = False; |
841 |
ui_destroy_window(); |
|
842 |
|
if (continue_connect) |
843 |
|
rdp_main_loop(&deactivated, &ext_disc_reason); |
844 |
|
|
845 |
|
DEBUG(("Disconnecting...\n")); |
846 |
|
rdp_disconnect(); |
847 |
|
|
848 |
|
if ((g_redirect == True) && (run_count == 0)) /* Support for Session Directory */ |
849 |
|
{ |
850 |
|
/* reset state of major globals */ |
851 |
|
rdesktop_reset_state(); |
852 |
|
|
853 |
|
STRNCPY(domain, g_redirect_domain, sizeof(domain)); |
854 |
|
STRNCPY(g_username, g_redirect_username, sizeof(g_username)); |
855 |
|
STRNCPY(password, g_redirect_password, sizeof(password)); |
856 |
|
STRNCPY(server, g_redirect_server, sizeof(server)); |
857 |
|
flags |= RDP_LOGON_AUTO; |
858 |
|
|
859 |
|
g_redirect = False; |
860 |
|
} |
861 |
|
else |
862 |
|
{ |
863 |
|
continue_connect = False; |
864 |
|
ui_destroy_window(); |
865 |
|
break; |
866 |
|
} |
867 |
|
|
868 |
|
run_count++; |
869 |
} |
} |
870 |
|
|
|
DEBUG(("Disconnecting...\n")); |
|
|
rdp_disconnect(); |
|
871 |
cache_save_state(); |
cache_save_state(); |
872 |
ui_deinit(); |
ui_deinit(); |
873 |
|
|
1180 |
} |
} |
1181 |
|
|
1182 |
|
|
1183 |
|
BOOL |
1184 |
|
str_startswith(const char *s, const char *prefix) |
1185 |
|
{ |
1186 |
|
return (strncmp(s, prefix, strlen(prefix)) == 0); |
1187 |
|
} |
1188 |
|
|
1189 |
|
|
1190 |
|
/* Split input into lines, and call linehandler for each |
1191 |
|
line. Incomplete lines are saved in the rest variable, which should |
1192 |
|
initially point to NULL. When linehandler returns False, stop and |
1193 |
|
return False. Otherwise, return True. */ |
1194 |
|
BOOL |
1195 |
|
str_handle_lines(const char *input, char **rest, str_handle_lines_t linehandler, void *data) |
1196 |
|
{ |
1197 |
|
char *buf, *p; |
1198 |
|
char *oldrest; |
1199 |
|
size_t inputlen; |
1200 |
|
size_t buflen; |
1201 |
|
size_t restlen = 0; |
1202 |
|
BOOL ret = True; |
1203 |
|
|
1204 |
|
/* Copy data to buffer */ |
1205 |
|
inputlen = strlen(input); |
1206 |
|
if (*rest) |
1207 |
|
restlen = strlen(*rest); |
1208 |
|
buflen = restlen + inputlen + 1; |
1209 |
|
buf = (char *) xmalloc(buflen); |
1210 |
|
buf[0] = '\0'; |
1211 |
|
if (*rest) |
1212 |
|
STRNCPY(buf, *rest, buflen); |
1213 |
|
strncat(buf, input, inputlen); |
1214 |
|
p = buf; |
1215 |
|
|
1216 |
|
while (1) |
1217 |
|
{ |
1218 |
|
char *newline = strchr(p, '\n'); |
1219 |
|
if (newline) |
1220 |
|
{ |
1221 |
|
*newline = '\0'; |
1222 |
|
if (!linehandler(p, data)) |
1223 |
|
{ |
1224 |
|
p = newline + 1; |
1225 |
|
ret = False; |
1226 |
|
break; |
1227 |
|
} |
1228 |
|
p = newline + 1; |
1229 |
|
} |
1230 |
|
else |
1231 |
|
{ |
1232 |
|
break; |
1233 |
|
|
1234 |
|
} |
1235 |
|
} |
1236 |
|
|
1237 |
|
/* Save in rest */ |
1238 |
|
oldrest = *rest; |
1239 |
|
restlen = buf + buflen - p; |
1240 |
|
*rest = (char *) xmalloc(restlen); |
1241 |
|
STRNCPY((*rest), p, restlen); |
1242 |
|
xfree(oldrest); |
1243 |
|
|
1244 |
|
xfree(buf); |
1245 |
|
return ret; |
1246 |
|
} |
1247 |
|
|
1248 |
|
/* Execute the program specified by argv. For each line in |
1249 |
|
stdout/stderr output, call linehandler. Returns false on failure. */ |
1250 |
|
BOOL |
1251 |
|
subprocess(char *const argv[], str_handle_lines_t linehandler, void *data) |
1252 |
|
{ |
1253 |
|
pid_t child; |
1254 |
|
int fd[2]; |
1255 |
|
int n = 1; |
1256 |
|
char output[256]; |
1257 |
|
char *rest = NULL; |
1258 |
|
|
1259 |
|
if (pipe(fd) < 0) |
1260 |
|
{ |
1261 |
|
perror("pipe"); |
1262 |
|
return False; |
1263 |
|
} |
1264 |
|
|
1265 |
|
if ((child = fork()) < 0) |
1266 |
|
{ |
1267 |
|
perror("fork"); |
1268 |
|
return False; |
1269 |
|
} |
1270 |
|
|
1271 |
|
/* Child */ |
1272 |
|
if (child == 0) |
1273 |
|
{ |
1274 |
|
/* Close read end */ |
1275 |
|
close(fd[0]); |
1276 |
|
|
1277 |
|
/* Redirect stdout and stderr to pipe */ |
1278 |
|
dup2(fd[1], 1); |
1279 |
|
dup2(fd[1], 2); |
1280 |
|
|
1281 |
|
/* Execute */ |
1282 |
|
execvp(argv[0], argv); |
1283 |
|
perror("Error executing child"); |
1284 |
|
_exit(128); |
1285 |
|
} |
1286 |
|
|
1287 |
|
/* Parent. Close write end. */ |
1288 |
|
close(fd[1]); |
1289 |
|
while (n > 0) |
1290 |
|
{ |
1291 |
|
n = read(fd[0], output, 255); |
1292 |
|
output[n] = '\0'; |
1293 |
|
str_handle_lines(output, &rest, linehandler, data); |
1294 |
|
} |
1295 |
|
xfree(rest); |
1296 |
|
|
1297 |
|
return True; |
1298 |
|
} |
1299 |
|
|
1300 |
|
|
1301 |
/* not all clibs got ltoa */ |
/* not all clibs got ltoa */ |
1302 |
#define LTOA_BUFSIZE (sizeof(long) * 8 + 1) |
#define LTOA_BUFSIZE (sizeof(long) * 8 + 1) |
1303 |
|
|