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 hostname[16]; |
char g_hostname[16]; |
53 |
char keymapname[16]; |
char g_keymapname[PATH_MAX] = ""; |
54 |
int 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 tcp_port_rdp = TCP_PORT_RDP; |
int g_xpos = 0; |
66 |
int g_server_bpp = 8; |
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; |
72 |
|
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; |
76 |
BOOL g_orders = True; |
BOOL g_bitmap_cache = True; |
77 |
|
BOOL g_bitmap_cache_persist_enable = False; |
78 |
|
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_console_session = False; |
BOOL g_console_session = False; |
88 |
BOOL g_numlock_sync = False; |
BOOL g_numlock_sync = False; |
89 |
extern BOOL g_owncolmap; |
BOOL g_owncolmap = False; |
90 |
|
BOOL g_ownbackstore = True; /* We can't rely on external BackingStore */ |
91 |
|
uint32 g_embed_wnd; |
92 |
|
uint32 g_rdp5_performanceflags = |
93 |
|
RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS; |
94 |
|
/* Session Directory redirection */ |
95 |
|
BOOL g_redirect = False; |
96 |
|
char g_redirect_server[64]; |
97 |
|
char g_redirect_domain[16]; |
98 |
|
char g_redirect_password[64]; |
99 |
|
char g_redirect_username[64]; |
100 |
|
char g_redirect_cookie[128]; |
101 |
|
uint32 g_redirect_flags = 0; |
102 |
|
|
103 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
104 |
BOOL g_rdpsnd = False; |
BOOL g_rdpsnd = False; |
105 |
#endif |
#endif |
106 |
|
|
107 |
|
#ifdef HAVE_ICONV |
108 |
|
char g_codepage[16] = ""; |
109 |
|
#endif |
110 |
|
|
111 |
extern RDPDR_DEVICE g_rdpdr_device[]; |
extern RDPDR_DEVICE g_rdpdr_device[]; |
112 |
extern uint32 g_num_devices; |
extern uint32 g_num_devices; |
113 |
|
extern char *g_rdpdr_clientname; |
114 |
|
|
115 |
#ifdef RDP2VNC |
#ifdef RDP2VNC |
116 |
extern int rfb_port; |
extern int rfb_port; |
124 |
usage(char *program) |
usage(char *program) |
125 |
{ |
{ |
126 |
fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n"); |
fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n"); |
127 |
fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2003 Matt Chapman.\n"); |
fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2005 Matt Chapman.\n"); |
128 |
fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n"); |
fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n"); |
129 |
|
|
130 |
fprintf(stderr, "Usage: %s [options] server[:port]\n", program); |
fprintf(stderr, "Usage: %s [options] server[:port]\n", program); |
142 |
fprintf(stderr, " -g: desktop geometry (WxH)\n"); |
fprintf(stderr, " -g: desktop geometry (WxH)\n"); |
143 |
fprintf(stderr, " -f: full-screen mode\n"); |
fprintf(stderr, " -f: full-screen mode\n"); |
144 |
fprintf(stderr, " -b: force bitmap updates\n"); |
fprintf(stderr, " -b: force bitmap updates\n"); |
145 |
|
#ifdef HAVE_ICONV |
146 |
|
fprintf(stderr, " -L: local codepage\n"); |
147 |
|
#endif |
148 |
|
fprintf(stderr, " -B: use BackingStore of X-server (if available)\n"); |
149 |
fprintf(stderr, " -e: disable encryption (French TS)\n"); |
fprintf(stderr, " -e: disable encryption (French TS)\n"); |
150 |
fprintf(stderr, " -E: disable encryption from client to server\n"); |
fprintf(stderr, " -E: disable encryption from client to server\n"); |
151 |
fprintf(stderr, " -m: do not send motion events\n"); |
fprintf(stderr, " -m: do not send motion events\n"); |
155 |
fprintf(stderr, " -S: caption button size (single application mode)\n"); |
fprintf(stderr, " -S: caption button size (single application mode)\n"); |
156 |
fprintf(stderr, " -T: window title\n"); |
fprintf(stderr, " -T: window title\n"); |
157 |
fprintf(stderr, " -N: enable numlock syncronization\n"); |
fprintf(stderr, " -N: enable numlock syncronization\n"); |
158 |
|
fprintf(stderr, " -X: embed into another window with a given id.\n"); |
159 |
fprintf(stderr, " -a: connection colour depth\n"); |
fprintf(stderr, " -a: connection colour depth\n"); |
160 |
|
fprintf(stderr, " -z: enable rdp compression\n"); |
161 |
|
fprintf(stderr, " -x: RDP5 experience (m[odem 28.8], b[roadband], l[an] or hex nr.)\n"); |
162 |
|
fprintf(stderr, " -P: use persistent bitmap caching\n"); |
163 |
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"); |
164 |
fprintf(stderr, " '-r comport:COM1=/dev/ttyS0': enable serial redirection of /dev/ttyS0 to COM1\n"); |
fprintf(stderr, |
165 |
fprintf(stderr, " or :COM1=/dev/ttyS0:9600,0|1|2,0|2,5|6|7|8:dtr \n"); |
" '-r comport:COM1=/dev/ttyS0': enable serial redirection of /dev/ttyS0 to COM1\n"); |
166 |
fprintf(stderr, " '-r disk:A=/mnt/floppy': enable redirection of /mnt/floppy to A:\n"); |
fprintf(stderr, " or COM1=/dev/ttyS0,COM2=/dev/ttyS1\n"); |
167 |
fprintf(stderr, " or A=/mnt/floppy,D=/mnt/cdrom'\n"); |
fprintf(stderr, |
168 |
fprintf(stderr, " '-r lptport:LPT1=/dev/lp0': enable parallel redirection of /dev/lp0 to LPT1\n"); |
" '-r disk:floppy=/mnt/floppy': enable redirection of /mnt/floppy to 'floppy' share\n"); |
169 |
fprintf(stderr, " or LPT1=/dev/lp0,LPT2=/dev/lp1\n"); |
fprintf(stderr, " or 'floppy=/mnt/floppy,cdrom=/mnt/cdrom'\n"); |
170 |
|
fprintf(stderr, " '-r clientname=<client name>': Set the client name displayed\n"); |
171 |
|
fprintf(stderr, " for redirected disks\n"); |
172 |
|
fprintf(stderr, |
173 |
|
" '-r lptport:LPT1=/dev/lp0': enable parallel redirection of /dev/lp0 to LPT1\n"); |
174 |
|
fprintf(stderr, " or LPT1=/dev/lp0,LPT2=/dev/lp1\n"); |
175 |
fprintf(stderr, " '-r printer:mydeskjet': enable printer redirection\n"); |
fprintf(stderr, " '-r printer:mydeskjet': enable printer redirection\n"); |
176 |
fprintf(stderr, " or mydeskjet:\"HP Laserjet IIIP\" to enter server driver as well\n"); |
fprintf(stderr, |
177 |
fprintf(stderr, " '-r sound': enable sound redirection\n"); |
" or mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n"); |
178 |
|
fprintf(stderr, " '-r sound:[local|off|remote]': enable sound redirection\n"); |
179 |
|
fprintf(stderr, " remote would leave sound on server\n"); |
180 |
fprintf(stderr, " -0: attach to console\n"); |
fprintf(stderr, " -0: attach to console\n"); |
181 |
fprintf(stderr, " -4: use RDP version 4\n"); |
fprintf(stderr, " -4: use RDP version 4\n"); |
182 |
fprintf(stderr, " -5: use RDP version 5 (default)\n"); |
fprintf(stderr, " -5: use RDP version 5 (default)\n"); |
183 |
} |
} |
184 |
|
|
185 |
|
static void |
186 |
|
print_disconnect_reason(uint16 reason) |
187 |
|
{ |
188 |
|
char *text; |
189 |
|
|
190 |
|
switch (reason) |
191 |
|
{ |
192 |
|
case exDiscReasonNoInfo: |
193 |
|
text = "No information available"; |
194 |
|
break; |
195 |
|
|
196 |
|
case exDiscReasonAPIInitiatedDisconnect: |
197 |
|
text = "Server initiated disconnect"; |
198 |
|
break; |
199 |
|
|
200 |
|
case exDiscReasonAPIInitiatedLogoff: |
201 |
|
text = "Server initiated logoff"; |
202 |
|
break; |
203 |
|
|
204 |
|
case exDiscReasonServerIdleTimeout: |
205 |
|
text = "Server idle timeout reached"; |
206 |
|
break; |
207 |
|
|
208 |
|
case exDiscReasonServerLogonTimeout: |
209 |
|
text = "Server logon timeout reached"; |
210 |
|
break; |
211 |
|
|
212 |
|
case exDiscReasonReplacedByOtherConnection: |
213 |
|
text = "The session was replaced"; |
214 |
|
break; |
215 |
|
|
216 |
|
case exDiscReasonOutOfMemory: |
217 |
|
text = "The server is out of memory"; |
218 |
|
break; |
219 |
|
|
220 |
|
case exDiscReasonServerDeniedConnection: |
221 |
|
text = "The server denied the connection"; |
222 |
|
break; |
223 |
|
|
224 |
|
case exDiscReasonServerDeniedConnectionFips: |
225 |
|
text = "The server denied the connection for security reason"; |
226 |
|
break; |
227 |
|
|
228 |
|
case exDiscReasonLicenseInternal: |
229 |
|
text = "Internal licensing error"; |
230 |
|
break; |
231 |
|
|
232 |
|
case exDiscReasonLicenseNoLicenseServer: |
233 |
|
text = "No license server available"; |
234 |
|
break; |
235 |
|
|
236 |
|
case exDiscReasonLicenseNoLicense: |
237 |
|
text = "No valid license available"; |
238 |
|
break; |
239 |
|
|
240 |
|
case exDiscReasonLicenseErrClientMsg: |
241 |
|
text = "Invalid licensing message"; |
242 |
|
break; |
243 |
|
|
244 |
|
case exDiscReasonLicenseHwidDoesntMatchLicense: |
245 |
|
text = "Hardware id doesn't match software license"; |
246 |
|
break; |
247 |
|
|
248 |
|
case exDiscReasonLicenseErrClientLicense: |
249 |
|
text = "Client license error"; |
250 |
|
break; |
251 |
|
|
252 |
|
case exDiscReasonLicenseCantFinishProtocol: |
253 |
|
text = "Network error during licensing protocol"; |
254 |
|
break; |
255 |
|
|
256 |
|
case exDiscReasonLicenseClientEndedProtocol: |
257 |
|
text = "Licensing protocol was not completed"; |
258 |
|
break; |
259 |
|
|
260 |
|
case exDiscReasonLicenseErrClientEncryption: |
261 |
|
text = "Incorrect client license enryption"; |
262 |
|
break; |
263 |
|
|
264 |
|
case exDiscReasonLicenseCantUpgradeLicense: |
265 |
|
text = "Can't upgrade license"; |
266 |
|
break; |
267 |
|
|
268 |
|
case exDiscReasonLicenseNoRemoteConnections: |
269 |
|
text = "The server is not licensed to accept remote connections"; |
270 |
|
break; |
271 |
|
|
272 |
|
default: |
273 |
|
if (reason > 0x1000 && reason < 0x7fff) |
274 |
|
{ |
275 |
|
text = "Internal protocol error"; |
276 |
|
} |
277 |
|
else |
278 |
|
{ |
279 |
|
text = "Unknown reason"; |
280 |
|
} |
281 |
|
} |
282 |
|
fprintf(stderr, "disconnect: %s.\n", text); |
283 |
|
} |
284 |
|
|
285 |
|
static void |
286 |
|
rdesktop_reset_state(void) |
287 |
|
{ |
288 |
|
rdp_reset_state(); |
289 |
|
} |
290 |
|
|
291 |
static BOOL |
static BOOL |
292 |
read_password(char *password, int size) |
read_password(char *password, int size) |
293 |
{ |
{ |
345 |
if (*server == '[' && p != NULL) |
if (*server == '[' && p != NULL) |
346 |
{ |
{ |
347 |
if (*(p + 1) == ':' && *(p + 2) != '\0') |
if (*(p + 1) == ':' && *(p + 2) != '\0') |
348 |
tcp_port_rdp = strtol(p + 2, NULL, 10); |
g_tcp_port_rdp = strtol(p + 2, NULL, 10); |
349 |
/* remove the port number and brackets from the address */ |
/* remove the port number and brackets from the address */ |
350 |
*p = '\0'; |
*p = '\0'; |
351 |
strncpy(server, server + 1, strlen(server)); |
strncpy(server, server + 1, strlen(server)); |
357 |
p = strchr(server, ':'); |
p = strchr(server, ':'); |
358 |
if (p != NULL) |
if (p != NULL) |
359 |
{ |
{ |
360 |
tcp_port_rdp = strtol(p + 1, NULL, 10); |
g_tcp_port_rdp = strtol(p + 1, NULL, 10); |
361 |
*p = 0; |
*p = 0; |
362 |
} |
} |
363 |
} |
} |
365 |
p = strchr(server, ':'); |
p = strchr(server, ':'); |
366 |
if (p != NULL) |
if (p != NULL) |
367 |
{ |
{ |
368 |
tcp_port_rdp = strtol(p + 1, NULL, 10); |
g_tcp_port_rdp = strtol(p + 1, NULL, 10); |
369 |
*p = 0; |
*p = 0; |
370 |
} |
} |
371 |
#endif /* IPv6 */ |
#endif /* IPv6 */ |
382 |
char password[64]; |
char password[64]; |
383 |
char shell[128]; |
char shell[128]; |
384 |
char directory[32]; |
char directory[32]; |
385 |
BOOL prompt_password, rdp_retval = False; |
BOOL prompt_password, deactivated; |
386 |
struct passwd *pw; |
struct passwd *pw; |
387 |
uint32 flags; |
uint32 flags, ext_disc_reason = 0; |
388 |
char *p; |
char *p; |
389 |
int c; |
int c; |
390 |
|
char *locale = NULL; |
391 |
int username_option = 0; |
int username_option = 0; |
392 |
|
int run_count = 0; /* Session Directory support */ |
393 |
|
BOOL continue_connect = True; /* Session Directory support */ |
394 |
|
|
395 |
|
#ifdef HAVE_LOCALE_H |
396 |
|
/* Set locale according to environment */ |
397 |
|
locale = setlocale(LC_ALL, ""); |
398 |
|
if (locale) |
399 |
|
{ |
400 |
|
locale = xstrdup(locale); |
401 |
|
} |
402 |
|
|
403 |
|
#endif |
404 |
flags = RDP_LOGON_NORMAL; |
flags = RDP_LOGON_NORMAL; |
405 |
prompt_password = False; |
prompt_password = False; |
406 |
domain[0] = password[0] = shell[0] = directory[0] = 0; |
domain[0] = password[0] = shell[0] = directory[0] = 0; |
407 |
strcpy(keymapname, "en-us"); |
g_embed_wnd = 0; |
408 |
|
|
409 |
g_num_devices = 0; |
g_num_devices = 0; |
410 |
|
|
414 |
#define VNCOPT |
#define VNCOPT |
415 |
#endif |
#endif |
416 |
|
|
417 |
while ((c = getopt(argc, argv, VNCOPT "u:d:s:c:p:n:k:g:fbeEmCDKS:T:Na:r:045h?")) != -1) |
while ((c = getopt(argc, argv, |
418 |
|
VNCOPT "u:L:d:s:c:p:n:k:g:fbBeEmzCDKS:T:NX:a:x:Pr:045h?")) != -1) |
419 |
{ |
{ |
420 |
switch (c) |
switch (c) |
421 |
{ |
{ |
438 |
username_option = 1; |
username_option = 1; |
439 |
break; |
break; |
440 |
|
|
441 |
|
case 'L': |
442 |
|
#ifdef HAVE_ICONV |
443 |
|
STRNCPY(g_codepage, optarg, sizeof(g_codepage)); |
444 |
|
#else |
445 |
|
error("iconv support not available\n"); |
446 |
|
#endif |
447 |
|
break; |
448 |
|
|
449 |
case 'd': |
case 'd': |
450 |
STRNCPY(domain, optarg, sizeof(domain)); |
STRNCPY(domain, optarg, sizeof(domain)); |
451 |
break; |
break; |
475 |
break; |
break; |
476 |
|
|
477 |
case 'n': |
case 'n': |
478 |
STRNCPY(hostname, optarg, sizeof(hostname)); |
STRNCPY(g_hostname, optarg, sizeof(g_hostname)); |
479 |
break; |
break; |
480 |
|
|
481 |
case 'k': |
case 'k': |
482 |
STRNCPY(keymapname, optarg, sizeof(keymapname)); |
STRNCPY(g_keymapname, optarg, sizeof(g_keymapname)); |
483 |
break; |
break; |
484 |
|
|
485 |
case 'g': |
case 'g': |
498 |
} |
} |
499 |
|
|
500 |
if (*p == 'x') |
if (*p == 'x') |
501 |
g_height = strtol(p + 1, NULL, 10); |
g_height = strtol(p + 1, &p, 10); |
502 |
|
|
503 |
if (g_height <= 0) |
if (g_height <= 0) |
504 |
{ |
{ |
507 |
} |
} |
508 |
|
|
509 |
if (*p == '%') |
if (*p == '%') |
510 |
|
{ |
511 |
g_width = -g_width; |
g_width = -g_width; |
512 |
|
p++; |
513 |
|
} |
514 |
|
|
515 |
|
if (*p == '+' || *p == '-') |
516 |
|
{ |
517 |
|
g_pos |= (*p == '-') ? 2 : 1; |
518 |
|
g_xpos = strtol(p, &p, 10); |
519 |
|
|
520 |
|
} |
521 |
|
if (*p == '+' || *p == '-') |
522 |
|
{ |
523 |
|
g_pos |= (*p == '-') ? 4 : 1; |
524 |
|
g_ypos = strtol(p, NULL, 10); |
525 |
|
} |
526 |
|
|
527 |
break; |
break; |
528 |
|
|
531 |
break; |
break; |
532 |
|
|
533 |
case 'b': |
case 'b': |
534 |
g_orders = False; |
g_bitmap_cache = False; |
535 |
|
break; |
536 |
|
|
537 |
|
case 'B': |
538 |
|
g_ownbackstore = False; |
539 |
break; |
break; |
540 |
|
|
541 |
case 'e': |
case 'e': |
585 |
g_numlock_sync = True; |
g_numlock_sync = True; |
586 |
break; |
break; |
587 |
|
|
588 |
|
case 'X': |
589 |
|
g_embed_wnd = strtol(optarg, NULL, 0); |
590 |
|
break; |
591 |
|
|
592 |
case 'a': |
case 'a': |
593 |
g_server_bpp = strtol(optarg, NULL, 10); |
g_server_depth = strtol(optarg, NULL, 10); |
594 |
if (g_server_bpp != 8 && g_server_bpp != 16 && g_server_bpp != 15 |
if (g_server_depth != 8 && |
595 |
&& g_server_bpp != 24) |
g_server_depth != 16 && |
596 |
|
g_server_depth != 15 && g_server_depth != 24) |
597 |
{ |
{ |
598 |
error("invalid server bpp\n"); |
error("Invalid server colour depth.\n"); |
599 |
return 1; |
return 1; |
600 |
} |
} |
601 |
break; |
break; |
602 |
|
|
603 |
|
case 'z': |
604 |
|
DEBUG(("rdp compression enabled\n")); |
605 |
|
flags |= (RDP_LOGON_COMPRESSION | RDP_LOGON_COMPRESSION2); |
606 |
|
break; |
607 |
|
|
608 |
|
case 'x': |
609 |
|
if (str_startswith(optarg, "m")) /* modem */ |
610 |
|
{ |
611 |
|
g_rdp5_performanceflags = |
612 |
|
RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | |
613 |
|
RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING; |
614 |
|
} |
615 |
|
else if (str_startswith(optarg, "b")) /* broadband */ |
616 |
|
{ |
617 |
|
g_rdp5_performanceflags = RDP5_NO_WALLPAPER; |
618 |
|
} |
619 |
|
else if (str_startswith(optarg, "l")) /* lan */ |
620 |
|
{ |
621 |
|
g_rdp5_performanceflags = RDP5_DISABLE_NOTHING; |
622 |
|
} |
623 |
|
else |
624 |
|
{ |
625 |
|
g_rdp5_performanceflags = strtol(optarg, NULL, 16); |
626 |
|
} |
627 |
|
break; |
628 |
|
|
629 |
|
case 'P': |
630 |
|
g_bitmap_cache_persist_enable = True; |
631 |
|
break; |
632 |
|
|
633 |
case 'r': |
case 'r': |
634 |
|
|
635 |
if (strncmp("sound", optarg, 5) == 0) |
if (str_startswith(optarg, "sound")) |
636 |
{ |
{ |
637 |
|
optarg += 5; |
638 |
|
|
639 |
|
if (*optarg == ':') |
640 |
|
{ |
641 |
|
*optarg++; |
642 |
|
while ((p = next_arg(optarg, ','))) |
643 |
|
{ |
644 |
|
if (str_startswith(optarg, "remote")) |
645 |
|
flags |= RDP_LOGON_LEAVE_AUDIO; |
646 |
|
|
647 |
|
if (str_startswith(optarg, "local")) |
648 |
|
#ifdef WITH_RDPSND |
649 |
|
g_rdpsnd = True; |
650 |
|
#else |
651 |
|
warning("Not compiled with sound support\n"); |
652 |
|
#endif |
653 |
|
|
654 |
|
if (str_startswith(optarg, "off")) |
655 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
656 |
g_rdpsnd = True; |
g_rdpsnd = False; |
657 |
#else |
#else |
658 |
warning("Not compiled with sound support"); |
warning("Not compiled with sound support\n"); |
659 |
#endif |
#endif |
660 |
|
|
661 |
|
optarg = p; |
662 |
|
} |
663 |
|
} |
664 |
|
else |
665 |
|
{ |
666 |
|
#ifdef WITH_RDPSND |
667 |
|
g_rdpsnd = True; |
668 |
|
#else |
669 |
|
warning("Not compiled with sound support\n"); |
670 |
|
#endif |
671 |
|
} |
672 |
} |
} |
673 |
else if (strncmp("disk", optarg, 4) == 0) |
else if (str_startswith(optarg, "disk")) |
674 |
{ |
{ |
675 |
/* -r disk:h:=/mnt/floppy */ |
/* -r disk:h:=/mnt/floppy */ |
676 |
disk_enum_devices(&g_num_devices, optarg + 4); |
disk_enum_devices(&g_num_devices, optarg + 4); |
677 |
} |
} |
678 |
else if (strncmp("comport", optarg, 7) == 0) |
else if (str_startswith(optarg, "comport")) |
679 |
{ |
{ |
680 |
serial_enum_devices(&g_num_devices, optarg + 7); |
serial_enum_devices(&g_num_devices, optarg + 7); |
681 |
} |
} |
682 |
else if (strncmp("lptport", optarg, 7) == 0) |
else if (str_startswith(optarg, "lptport")) |
683 |
{ |
{ |
684 |
parallel_enum_devices(&g_num_devices, optarg + 7); |
parallel_enum_devices(&g_num_devices, optarg + 7); |
685 |
} |
} |
686 |
else if (strncmp("printer", optarg, 7) == 0) |
else if (str_startswith(optarg, "printer")) |
687 |
{ |
{ |
688 |
printer_enum_devices(&g_num_devices, optarg + 7); |
printer_enum_devices(&g_num_devices, optarg + 7); |
689 |
} |
} |
690 |
|
else if (str_startswith(optarg, "clientname")) |
691 |
|
{ |
692 |
|
g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1); |
693 |
|
strcpy(g_rdpdr_clientname, optarg + 11); |
694 |
|
} |
695 |
else |
else |
696 |
{ |
{ |
697 |
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\n"); |
718 |
} |
} |
719 |
} |
} |
720 |
|
|
721 |
if (argc - optind < 1) |
if (argc - optind != 1) |
722 |
{ |
{ |
723 |
usage(argv[0]); |
usage(argv[0]); |
724 |
return 1; |
return 1; |
739 |
STRNCPY(g_username, pw->pw_name, sizeof(g_username)); |
STRNCPY(g_username, pw->pw_name, sizeof(g_username)); |
740 |
} |
} |
741 |
|
|
742 |
if (hostname[0] == 0) |
#ifdef HAVE_ICONV |
743 |
|
if (g_codepage[0] == 0) |
744 |
|
{ |
745 |
|
if (setlocale(LC_CTYPE, "")) |
746 |
|
{ |
747 |
|
STRNCPY(g_codepage, nl_langinfo(CODESET), sizeof(g_codepage)); |
748 |
|
} |
749 |
|
else |
750 |
|
{ |
751 |
|
STRNCPY(g_codepage, DEFAULT_CODEPAGE, sizeof(g_codepage)); |
752 |
|
} |
753 |
|
} |
754 |
|
#endif |
755 |
|
|
756 |
|
if (g_hostname[0] == 0) |
757 |
{ |
{ |
758 |
if (gethostname(fullhostname, sizeof(fullhostname)) == -1) |
if (gethostname(fullhostname, sizeof(fullhostname)) == -1) |
759 |
{ |
{ |
765 |
if (p != NULL) |
if (p != NULL) |
766 |
*p = 0; |
*p = 0; |
767 |
|
|
768 |
STRNCPY(hostname, fullhostname, sizeof(hostname)); |
STRNCPY(g_hostname, fullhostname, sizeof(g_hostname)); |
769 |
} |
} |
770 |
|
|
771 |
|
if (g_keymapname[0] == 0) |
772 |
|
{ |
773 |
|
if (locale && xkeymap_from_locale(locale)) |
774 |
|
{ |
775 |
|
fprintf(stderr, "Autoselected keyboard map %s\n", g_keymapname); |
776 |
|
} |
777 |
|
else |
778 |
|
{ |
779 |
|
STRNCPY(g_keymapname, "en-us", sizeof(g_keymapname)); |
780 |
|
} |
781 |
|
} |
782 |
|
if (locale) |
783 |
|
xfree(locale); |
784 |
|
|
785 |
|
|
786 |
if (prompt_password && read_password(password, sizeof(password))) |
if (prompt_password && read_password(password, sizeof(password))) |
787 |
flags |= RDP_LOGON_AUTO; |
flags |= RDP_LOGON_AUTO; |
788 |
|
|
806 |
#endif |
#endif |
807 |
rdpdr_init(); |
rdpdr_init(); |
808 |
|
|
809 |
if (!rdp_connect(server, flags, domain, password, shell, directory)) |
while (run_count < 2 && continue_connect) /* add support for Session Directory; only reconnect once */ |
810 |
return 1; |
{ |
811 |
|
if (run_count == 0) |
812 |
|
{ |
813 |
|
if (!rdp_connect(server, flags, domain, password, shell, directory)) |
814 |
|
return 1; |
815 |
|
} |
816 |
|
else if (!rdp_reconnect |
817 |
|
(server, flags, domain, password, shell, directory, g_redirect_cookie)) |
818 |
|
return 1; |
819 |
|
|
820 |
/* By setting encryption to False here, we have an encrypted login |
/* By setting encryption to False here, we have an encrypted login |
821 |
packet but unencrypted transfer of other packets */ |
packet but unencrypted transfer of other packets */ |
822 |
if (!packet_encryption) |
if (!packet_encryption) |
823 |
g_encryption = False; |
g_encryption = False; |
824 |
|
|
825 |
|
|
826 |
DEBUG(("Connection successful.\n")); |
DEBUG(("Connection successful.\n")); |
827 |
memset(password, 0, sizeof(password)); |
memset(password, 0, sizeof(password)); |
828 |
|
|
829 |
if (ui_create_window()) |
if (run_count == 0) |
830 |
{ |
if (!ui_create_window()) |
831 |
rdp_retval = rdp_main_loop(); |
continue_connect = False; |
832 |
ui_destroy_window(); |
|
833 |
|
if (continue_connect) |
834 |
|
rdp_main_loop(&deactivated, &ext_disc_reason); |
835 |
|
|
836 |
|
DEBUG(("Disconnecting...\n")); |
837 |
|
rdp_disconnect(); |
838 |
|
|
839 |
|
if ((g_redirect == True) && (run_count == 0)) /* Support for Session Directory */ |
840 |
|
{ |
841 |
|
/* reset state of major globals */ |
842 |
|
rdesktop_reset_state(); |
843 |
|
|
844 |
|
STRNCPY(domain, g_redirect_domain, sizeof(domain)); |
845 |
|
STRNCPY(g_username, g_redirect_username, sizeof(g_username)); |
846 |
|
STRNCPY(password, g_redirect_password, sizeof(password)); |
847 |
|
STRNCPY(server, g_redirect_server, sizeof(server)); |
848 |
|
flags |= RDP_LOGON_AUTO; |
849 |
|
|
850 |
|
g_redirect = False; |
851 |
|
} |
852 |
|
else |
853 |
|
{ |
854 |
|
continue_connect = False; |
855 |
|
ui_destroy_window(); |
856 |
|
break; |
857 |
|
} |
858 |
|
|
859 |
|
run_count++; |
860 |
} |
} |
861 |
|
|
862 |
DEBUG(("Disconnecting...\n")); |
cache_save_state(); |
|
rdp_disconnect(); |
|
863 |
ui_deinit(); |
ui_deinit(); |
864 |
|
|
865 |
if (True == rdp_retval) |
if (ext_disc_reason >= 2) |
866 |
|
print_disconnect_reason(ext_disc_reason); |
867 |
|
|
868 |
|
if (deactivated) |
869 |
|
{ |
870 |
|
/* clean disconnect */ |
871 |
return 0; |
return 0; |
872 |
|
} |
873 |
else |
else |
874 |
return 2; |
{ |
875 |
|
if (ext_disc_reason == exDiscReasonAPIInitiatedDisconnect |
876 |
|
|| ext_disc_reason == exDiscReasonAPIInitiatedLogoff) |
877 |
|
{ |
878 |
|
/* not so clean disconnect, but nothing to worry about */ |
879 |
|
return 0; |
880 |
|
} |
881 |
|
else |
882 |
|
{ |
883 |
|
/* return error */ |
884 |
|
return 2; |
885 |
|
} |
886 |
|
} |
887 |
|
|
888 |
#endif |
#endif |
889 |
|
|
985 |
return mem; |
return mem; |
986 |
} |
} |
987 |
|
|
988 |
|
/* strdup */ |
989 |
|
char * |
990 |
|
xstrdup(const char *s) |
991 |
|
{ |
992 |
|
char *mem = strdup(s); |
993 |
|
if (mem == NULL) |
994 |
|
{ |
995 |
|
perror("strdup"); |
996 |
|
exit(1); |
997 |
|
} |
998 |
|
return mem; |
999 |
|
} |
1000 |
|
|
1001 |
/* realloc; exit if out of memory */ |
/* realloc; exit if out of memory */ |
1002 |
void * |
void * |
1003 |
xrealloc(void *oldmem, int size) |
xrealloc(void *oldmem, int size) |
1004 |
{ |
{ |
1005 |
void *mem = realloc(oldmem, size); |
void *mem; |
1006 |
|
|
1007 |
|
if (size < 1) |
1008 |
|
size = 1; |
1009 |
|
mem = realloc(oldmem, size); |
1010 |
if (mem == NULL) |
if (mem == NULL) |
1011 |
{ |
{ |
1012 |
error("xrealloc %d\n", size); |
error("xrealloc %d\n", size); |
1091 |
} |
} |
1092 |
|
|
1093 |
/* |
/* |
1094 |
input: src is the string we look in for needle |
input: src is the string we look in for needle. |
1095 |
|
Needle may be escaped by a backslash, in |
1096 |
|
that case we ignore that particular needle. |
1097 |
return value: returns next src pointer, for |
return value: returns next src pointer, for |
1098 |
succesive executions, like in a while loop |
succesive executions, like in a while loop |
1099 |
if retval is 0, then there are no more args. |
if retval is 0, then there are no more args. |
1115 |
{ |
{ |
1116 |
char *nextval; |
char *nextval; |
1117 |
char *p; |
char *p; |
1118 |
|
char *mvp = 0; |
1119 |
|
|
1120 |
// EOS |
/* EOS */ |
1121 |
if (*src == (char) 0x00) |
if (*src == (char) 0x00) |
1122 |
return 0; |
return 0; |
1123 |
|
|
1124 |
p = src; |
p = src; |
1125 |
// skip escaped needles. |
/* skip escaped needles */ |
1126 |
while( (nextval = strchr(p, needle) ) ) |
while ((nextval = strchr(p, needle))) |
1127 |
{ |
{ |
1128 |
if( *(nextval-1) != '\\' ) |
mvp = nextval - 1; |
1129 |
|
/* found backslashed needle */ |
1130 |
|
if (*mvp == '\\' && (mvp > src)) |
1131 |
|
{ |
1132 |
|
/* move string one to the left */ |
1133 |
|
while (*(mvp + 1) != (char) 0x00) |
1134 |
|
{ |
1135 |
|
*mvp = *(mvp + 1); |
1136 |
|
*mvp++; |
1137 |
|
} |
1138 |
|
*mvp = (char) 0x00; |
1139 |
|
p = nextval; |
1140 |
|
} |
1141 |
|
else |
1142 |
|
{ |
1143 |
|
p = nextval + 1; |
1144 |
break; |
break; |
1145 |
p = nextval +1; |
} |
1146 |
|
|
1147 |
} |
} |
1148 |
|
|
1149 |
// more args available |
/* more args available */ |
1150 |
if (nextval) |
if (nextval) |
1151 |
{ |
{ |
1152 |
*nextval = (char) 0x00; |
*nextval = (char) 0x00; |
1153 |
return ++nextval; |
return ++nextval; |
1154 |
} |
} |
1155 |
|
|
1156 |
// no more args after this, jump to EOS |
/* no more args after this, jump to EOS */ |
1157 |
nextval = src + strlen(src); |
nextval = src + strlen(src); |
1158 |
return nextval; |
return nextval; |
1159 |
} |
} |
1160 |
|
|
1161 |
|
|
1162 |
void |
void |
1163 |
toupper_str(char* p) |
toupper_str(char *p) |
1164 |
{ |
{ |
1165 |
while( *p ){ |
while (*p) |
1166 |
if( (*p >= 'a') && (*p <= 'z') ) |
{ |
1167 |
|
if ((*p >= 'a') && (*p <= 'z')) |
1168 |
*p = toupper((int) *p); |
*p = toupper((int) *p); |
1169 |
p++; |
p++; |
1170 |
} |
} |
1171 |
} |
} |
1172 |
|
|
1173 |
|
|
1174 |
|
BOOL |
1175 |
|
str_startswith(const char *s, const char *prefix) |
1176 |
|
{ |
1177 |
|
return (strncmp(s, prefix, strlen(prefix)) == 0); |
1178 |
|
} |
1179 |
|
|
1180 |
|
|
1181 |
/* not all clibs got ltoa */ |
/* not all clibs got ltoa */ |
1182 |
#define LTOA_BUFSIZE (sizeof(long) * 8 + 1) |
#define LTOA_BUFSIZE (sizeof(long) * 8 + 1) |
1183 |
|
|
1184 |
char * |
char * |
1185 |
ltoa(long N, int base) |
l_to_a(long N, int base) |
1186 |
{ |
{ |
1187 |
static char ret[LTOA_BUFSIZE]; |
static char ret[LTOA_BUFSIZE]; |
1188 |
|
|
1189 |
register int i = 2; |
char *head = ret, buf[LTOA_BUFSIZE], *tail = buf + sizeof(buf); |
|
long uarg; |
|
|
char *tail, *head = ret, buf[LTOA_BUFSIZE]; |
|
1190 |
|
|
1191 |
if (36 < base || 2 > base) |
register int divrem; |
|
base = 10; |
|
1192 |
|
|
1193 |
tail = &buf[LTOA_BUFSIZE - 1]; |
if (base < 36 || 2 > base) |
1194 |
*tail-- = '\0'; |
base = 10; |
1195 |
|
|
1196 |
if (10 == base && N < 0L) |
if (N < 0) |
1197 |
{ |
{ |
1198 |
*head++ = '-'; |
*head++ = '-'; |
1199 |
uarg = -N; |
N = -N; |
1200 |
} |
} |
|
else |
|
|
uarg = N; |
|
1201 |
|
|
1202 |
if (uarg) |
tail = buf + sizeof(buf); |
1203 |
{ |
*--tail = 0; |
|
for (i = 1; uarg; ++i) |
|
|
{ |
|
|
register ldiv_t r; |
|
1204 |
|
|
1205 |
r = ldiv(uarg, base); |
do |
1206 |
*tail-- = (char) (r.rem + ((9L < r.rem) ? ('A' - 10L) : '0')); |
{ |
1207 |
uarg = r.quot; |
divrem = N % base; |
1208 |
} |
*--tail = (divrem <= 9) ? divrem + '0' : divrem + 'a' - 10; |
1209 |
|
N /= base; |
1210 |
} |
} |
1211 |
else |
while (N); |
|
*tail-- = '0'; |
|
1212 |
|
|
1213 |
memcpy(head, ++tail, i); |
strcpy(head, tail); |
1214 |
return ret; |
return ret; |
1215 |
} |
} |
1216 |
|
|
1226 |
if (home == NULL) |
if (home == NULL) |
1227 |
return -1; |
return -1; |
1228 |
|
|
1229 |
path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence.")); |
path = (char *) xmalloc(strlen(home) + strlen(g_hostname) + sizeof("/.rdesktop/licence.")); |
1230 |
sprintf(path, "%s/.rdesktop/licence.%s", home, hostname); |
sprintf(path, "%s/.rdesktop/licence.%s", home, g_hostname); |
1231 |
|
|
1232 |
fd = open(path, O_RDONLY); |
fd = open(path, O_RDONLY); |
1233 |
if (fd == -1) |
if (fd == -1) |
1253 |
if (home == NULL) |
if (home == NULL) |
1254 |
return; |
return; |
1255 |
|
|
1256 |
path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence.")); |
path = (char *) xmalloc(strlen(home) + strlen(g_hostname) + sizeof("/.rdesktop/licence.")); |
1257 |
|
|
1258 |
sprintf(path, "%s/.rdesktop", home); |
sprintf(path, "%s/.rdesktop", home); |
1259 |
if ((mkdir(path, 0700) == -1) && errno != EEXIST) |
if ((mkdir(path, 0700) == -1) && errno != EEXIST) |
1264 |
|
|
1265 |
/* write licence to licence.hostname.new, then atomically rename to licence.hostname */ |
/* write licence to licence.hostname.new, then atomically rename to licence.hostname */ |
1266 |
|
|
1267 |
sprintf(path, "%s/.rdesktop/licence.%s", home, hostname); |
sprintf(path, "%s/.rdesktop/licence.%s", home, g_hostname); |
1268 |
tmppath = (char *) xmalloc(strlen(path) + sizeof(".new")); |
tmppath = (char *) xmalloc(strlen(path) + sizeof(".new")); |
1269 |
strcpy(tmppath, path); |
strcpy(tmppath, path); |
1270 |
strcat(tmppath, ".new"); |
strcat(tmppath, ".new"); |
1291 |
xfree(tmppath); |
xfree(tmppath); |
1292 |
xfree(path); |
xfree(path); |
1293 |
} |
} |
1294 |
|
|
1295 |
|
/* Create the bitmap cache directory */ |
1296 |
|
BOOL |
1297 |
|
rd_pstcache_mkdir(void) |
1298 |
|
{ |
1299 |
|
char *home; |
1300 |
|
char bmpcache_dir[256]; |
1301 |
|
|
1302 |
|
home = getenv("HOME"); |
1303 |
|
|
1304 |
|
if (home == NULL) |
1305 |
|
return False; |
1306 |
|
|
1307 |
|
sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop"); |
1308 |
|
|
1309 |
|
if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST) |
1310 |
|
{ |
1311 |
|
perror(bmpcache_dir); |
1312 |
|
return False; |
1313 |
|
} |
1314 |
|
|
1315 |
|
sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop/cache"); |
1316 |
|
|
1317 |
|
if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST) |
1318 |
|
{ |
1319 |
|
perror(bmpcache_dir); |
1320 |
|
return False; |
1321 |
|
} |
1322 |
|
|
1323 |
|
return True; |
1324 |
|
} |
1325 |
|
|
1326 |
|
/* open a file in the .rdesktop directory */ |
1327 |
|
int |
1328 |
|
rd_open_file(char *filename) |
1329 |
|
{ |
1330 |
|
char *home; |
1331 |
|
char fn[256]; |
1332 |
|
int fd; |
1333 |
|
|
1334 |
|
home = getenv("HOME"); |
1335 |
|
if (home == NULL) |
1336 |
|
return -1; |
1337 |
|
sprintf(fn, "%s/.rdesktop/%s", home, filename); |
1338 |
|
fd = open(fn, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); |
1339 |
|
if (fd == -1) |
1340 |
|
perror(fn); |
1341 |
|
return fd; |
1342 |
|
} |
1343 |
|
|
1344 |
|
/* close file */ |
1345 |
|
void |
1346 |
|
rd_close_file(int fd) |
1347 |
|
{ |
1348 |
|
close(fd); |
1349 |
|
} |
1350 |
|
|
1351 |
|
/* read from file*/ |
1352 |
|
int |
1353 |
|
rd_read_file(int fd, void *ptr, int len) |
1354 |
|
{ |
1355 |
|
return read(fd, ptr, len); |
1356 |
|
} |
1357 |
|
|
1358 |
|
/* write to file */ |
1359 |
|
int |
1360 |
|
rd_write_file(int fd, void *ptr, int len) |
1361 |
|
{ |
1362 |
|
return write(fd, ptr, len); |
1363 |
|
} |
1364 |
|
|
1365 |
|
/* move file pointer */ |
1366 |
|
int |
1367 |
|
rd_lseek_file(int fd, int offset) |
1368 |
|
{ |
1369 |
|
return lseek(fd, offset, SEEK_SET); |
1370 |
|
} |
1371 |
|
|
1372 |
|
/* do a write lock on a file */ |
1373 |
|
BOOL |
1374 |
|
rd_lock_file(int fd, int start, int len) |
1375 |
|
{ |
1376 |
|
struct flock lock; |
1377 |
|
|
1378 |
|
lock.l_type = F_WRLCK; |
1379 |
|
lock.l_whence = SEEK_SET; |
1380 |
|
lock.l_start = start; |
1381 |
|
lock.l_len = len; |
1382 |
|
if (fcntl(fd, F_SETLK, &lock) == -1) |
1383 |
|
return False; |
1384 |
|
return True; |
1385 |
|
} |