35 |
#include <sys/un.h> /* sockaddr_un */ |
#include <sys/un.h> /* sockaddr_un */ |
36 |
#endif |
#endif |
37 |
|
|
|
#ifdef WITH_OPENSSL |
|
38 |
#include <openssl/md5.h> |
#include <openssl/md5.h> |
|
#else |
|
|
#include "crypto/md5.h" |
|
|
#endif |
|
39 |
|
|
40 |
char g_title[64] = ""; |
char g_title[64] = ""; |
41 |
char g_username[64]; |
char g_username[64]; |
42 |
char hostname[16]; |
char g_hostname[16]; |
43 |
char keymapname[16]; |
char keymapname[16]; |
44 |
int keylayout = 0x409; /* Defaults to US keyboard layout */ |
int g_keylayout = 0x409; /* Defaults to US keyboard layout */ |
45 |
|
|
46 |
int g_width = 800; /* width is special: If 0, the |
int g_width = 800; /* width is special: If 0, the |
47 |
geometry will be fetched from |
geometry will be fetched from |
49 |
absolute value specifies the |
absolute value specifies the |
50 |
percent of the whole screen. */ |
percent of the whole screen. */ |
51 |
int g_height = 600; |
int g_height = 600; |
52 |
int tcp_port_rdp = TCP_PORT_RDP; |
extern int g_tcp_port_rdp; |
53 |
int g_server_bpp = 8; |
int g_server_bpp = 8; |
54 |
int g_win_button_size = 0; /* If zero, disable single app mode */ |
int g_win_button_size = 0; /* If zero, disable single app mode */ |
55 |
BOOL g_bitmap_compression = True; |
BOOL g_bitmap_compression = True; |
56 |
BOOL g_sendmotion = True; |
BOOL g_sendmotion = True; |
57 |
BOOL g_bitmap_cache = True; |
BOOL g_bitmap_cache = True; |
58 |
|
BOOL g_bitmap_cache_persist_enable = False; |
59 |
|
BOOL g_bitmap_cache_precache = True; |
60 |
BOOL g_encryption = True; |
BOOL g_encryption = True; |
61 |
BOOL packet_encryption = True; |
BOOL packet_encryption = True; |
62 |
BOOL g_desktop_save = True; |
BOOL g_desktop_save = True; |
122 |
fprintf(stderr, " -N: enable numlock syncronization\n"); |
fprintf(stderr, " -N: enable numlock syncronization\n"); |
123 |
fprintf(stderr, " -X: embed into another window with a given id.\n"); |
fprintf(stderr, " -X: embed into another window with a given id.\n"); |
124 |
fprintf(stderr, " -a: connection colour depth\n"); |
fprintf(stderr, " -a: connection colour depth\n"); |
125 |
fprintf(stderr, |
fprintf(stderr, " -z: enable rdp compression\n"); |
126 |
" -x: RDP5 experience (m[odem 28.8], b[roadband], l[an] or hex number)\n"); |
fprintf(stderr, " -x: RDP5 experience (m[odem 28.8], b[roadband], l[an] or hex nr.)\n"); |
127 |
|
fprintf(stderr, " -P: use persistent bitmap caching\n"); |
128 |
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"); |
129 |
fprintf(stderr, |
fprintf(stderr, |
130 |
" '-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"); |
131 |
fprintf(stderr, " or COM1=/dev/ttyS0,COM2=/dev/ttyS1\n"); |
fprintf(stderr, " or COM1=/dev/ttyS0,COM2=/dev/ttyS1\n"); |
132 |
fprintf(stderr, |
fprintf(stderr, |
133 |
" '-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"); |
134 |
fprintf(stderr, " or A=/mnt/floppy,D=/mnt/cdrom'\n"); |
fprintf(stderr, " or 'floppy=/mnt/floppy,cdrom=/mnt/cdrom'\n"); |
135 |
fprintf(stderr, " '-r clientname=<client name>': Set the client name displayed\n"); |
fprintf(stderr, " '-r clientname=<client name>': Set the client name displayed\n"); |
136 |
fprintf(stderr, " for redirected disks\n"); |
fprintf(stderr, " for redirected disks\n"); |
137 |
fprintf(stderr, |
fprintf(stderr, |
304 |
if (*server == '[' && p != NULL) |
if (*server == '[' && p != NULL) |
305 |
{ |
{ |
306 |
if (*(p + 1) == ':' && *(p + 2) != '\0') |
if (*(p + 1) == ':' && *(p + 2) != '\0') |
307 |
tcp_port_rdp = strtol(p + 2, NULL, 10); |
g_tcp_port_rdp = strtol(p + 2, NULL, 10); |
308 |
/* remove the port number and brackets from the address */ |
/* remove the port number and brackets from the address */ |
309 |
*p = '\0'; |
*p = '\0'; |
310 |
strncpy(server, server + 1, strlen(server)); |
strncpy(server, server + 1, strlen(server)); |
316 |
p = strchr(server, ':'); |
p = strchr(server, ':'); |
317 |
if (p != NULL) |
if (p != NULL) |
318 |
{ |
{ |
319 |
tcp_port_rdp = strtol(p + 1, NULL, 10); |
g_tcp_port_rdp = strtol(p + 1, NULL, 10); |
320 |
*p = 0; |
*p = 0; |
321 |
} |
} |
322 |
} |
} |
324 |
p = strchr(server, ':'); |
p = strchr(server, ':'); |
325 |
if (p != NULL) |
if (p != NULL) |
326 |
{ |
{ |
327 |
tcp_port_rdp = strtol(p + 1, NULL, 10); |
g_tcp_port_rdp = strtol(p + 1, NULL, 10); |
328 |
*p = 0; |
*p = 0; |
329 |
} |
} |
330 |
#endif /* IPv6 */ |
#endif /* IPv6 */ |
363 |
#define VNCOPT |
#define VNCOPT |
364 |
#endif |
#endif |
365 |
|
|
366 |
while ((c = getopt(argc, argv, VNCOPT "u:d:s:c:p:n:k:g:fbBeEmCDKS:T:NX:a:x:r:045h?")) != -1) |
while ((c = getopt(argc, argv, |
367 |
|
VNCOPT "u:d:s:c:p:n:k:g:fbBeEmzCDKS:T:NX:a:x:Pr:045h?")) != -1) |
368 |
{ |
{ |
369 |
switch (c) |
switch (c) |
370 |
{ |
{ |
416 |
break; |
break; |
417 |
|
|
418 |
case 'n': |
case 'n': |
419 |
STRNCPY(hostname, optarg, sizeof(hostname)); |
STRNCPY(g_hostname, optarg, sizeof(g_hostname)); |
420 |
break; |
break; |
421 |
|
|
422 |
case 'k': |
case 'k': |
525 |
} |
} |
526 |
break; |
break; |
527 |
|
|
528 |
case 'x': |
case 'z': |
529 |
|
DEBUG(("rdp compression enabled\n")); |
530 |
|
flags |= RDP_COMPRESSION; |
531 |
|
break; |
532 |
|
|
533 |
|
case 'x': |
534 |
if (strncmp("modem", optarg, 1) == 0) |
if (strncmp("modem", optarg, 1) == 0) |
535 |
{ |
{ |
536 |
g_rdp5_performanceflags = |
g_rdp5_performanceflags = |
551 |
} |
} |
552 |
break; |
break; |
553 |
|
|
554 |
|
case 'P': |
555 |
|
g_bitmap_cache_persist_enable = True; |
556 |
|
break; |
557 |
|
|
558 |
case 'r': |
case 'r': |
559 |
|
|
560 |
if (strncmp("sound", optarg, 5) == 0) |
if (strncmp("sound", optarg, 5) == 0) |
573 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
574 |
g_rdpsnd = True; |
g_rdpsnd = True; |
575 |
#else |
#else |
576 |
warning("Not compiled with sound support"); |
warning("Not compiled with sound support\n"); |
577 |
#endif |
#endif |
578 |
|
|
579 |
if (strncmp("off", optarg, 3) == 0) |
if (strncmp("off", optarg, 3) == 0) |
580 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
581 |
g_rdpsnd = False; |
g_rdpsnd = False; |
582 |
#else |
#else |
583 |
warning("Not compiled with sound support"); |
warning("Not compiled with sound support\n"); |
584 |
#endif |
#endif |
585 |
|
|
586 |
optarg = p; |
optarg = p; |
591 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
592 |
g_rdpsnd = True; |
g_rdpsnd = True; |
593 |
#else |
#else |
594 |
warning("Not compiled with sound support"); |
warning("Not compiled with sound support\n"); |
595 |
#endif |
#endif |
596 |
} |
} |
597 |
} |
} |
664 |
STRNCPY(g_username, pw->pw_name, sizeof(g_username)); |
STRNCPY(g_username, pw->pw_name, sizeof(g_username)); |
665 |
} |
} |
666 |
|
|
667 |
if (hostname[0] == 0) |
if (g_hostname[0] == 0) |
668 |
{ |
{ |
669 |
if (gethostname(fullhostname, sizeof(fullhostname)) == -1) |
if (gethostname(fullhostname, sizeof(fullhostname)) == -1) |
670 |
{ |
{ |
676 |
if (p != NULL) |
if (p != NULL) |
677 |
*p = 0; |
*p = 0; |
678 |
|
|
679 |
STRNCPY(hostname, fullhostname, sizeof(hostname)); |
STRNCPY(g_hostname, fullhostname, sizeof(g_hostname)); |
680 |
} |
} |
681 |
|
|
682 |
if (prompt_password && read_password(password, sizeof(password))) |
if (prompt_password && read_password(password, sizeof(password))) |
722 |
|
|
723 |
DEBUG(("Disconnecting...\n")); |
DEBUG(("Disconnecting...\n")); |
724 |
rdp_disconnect(); |
rdp_disconnect(); |
725 |
|
cache_save_state(); |
726 |
ui_deinit(); |
ui_deinit(); |
727 |
|
|
728 |
if (ext_disc_reason >= 2) |
if (ext_disc_reason >= 2) |
852 |
void * |
void * |
853 |
xrealloc(void *oldmem, int size) |
xrealloc(void *oldmem, int size) |
854 |
{ |
{ |
855 |
void *mem = realloc(oldmem, size); |
void *mem; |
856 |
|
|
857 |
|
if (size < 1) |
858 |
|
size = 1; |
859 |
|
mem = realloc(oldmem, size); |
860 |
if (mem == NULL) |
if (mem == NULL) |
861 |
{ |
{ |
862 |
error("xrealloc %d\n", size); |
error("xrealloc %d\n", size); |
1069 |
if (home == NULL) |
if (home == NULL) |
1070 |
return -1; |
return -1; |
1071 |
|
|
1072 |
path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence.")); |
path = (char *) xmalloc(strlen(home) + strlen(g_hostname) + sizeof("/.rdesktop/licence.")); |
1073 |
sprintf(path, "%s/.rdesktop/licence.%s", home, hostname); |
sprintf(path, "%s/.rdesktop/licence.%s", home, g_hostname); |
1074 |
|
|
1075 |
fd = open(path, O_RDONLY); |
fd = open(path, O_RDONLY); |
1076 |
if (fd == -1) |
if (fd == -1) |
1096 |
if (home == NULL) |
if (home == NULL) |
1097 |
return; |
return; |
1098 |
|
|
1099 |
path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence.")); |
path = (char *) xmalloc(strlen(home) + strlen(g_hostname) + sizeof("/.rdesktop/licence.")); |
1100 |
|
|
1101 |
sprintf(path, "%s/.rdesktop", home); |
sprintf(path, "%s/.rdesktop", home); |
1102 |
if ((mkdir(path, 0700) == -1) && errno != EEXIST) |
if ((mkdir(path, 0700) == -1) && errno != EEXIST) |
1107 |
|
|
1108 |
/* write licence to licence.hostname.new, then atomically rename to licence.hostname */ |
/* write licence to licence.hostname.new, then atomically rename to licence.hostname */ |
1109 |
|
|
1110 |
sprintf(path, "%s/.rdesktop/licence.%s", home, hostname); |
sprintf(path, "%s/.rdesktop/licence.%s", home, g_hostname); |
1111 |
tmppath = (char *) xmalloc(strlen(path) + sizeof(".new")); |
tmppath = (char *) xmalloc(strlen(path) + sizeof(".new")); |
1112 |
strcpy(tmppath, path); |
strcpy(tmppath, path); |
1113 |
strcat(tmppath, ".new"); |
strcat(tmppath, ".new"); |
1134 |
xfree(tmppath); |
xfree(tmppath); |
1135 |
xfree(path); |
xfree(path); |
1136 |
} |
} |
1137 |
|
|
1138 |
|
/* Create the bitmap cache directory */ |
1139 |
|
BOOL |
1140 |
|
rd_pstcache_mkdir(void) |
1141 |
|
{ |
1142 |
|
char *home; |
1143 |
|
char bmpcache_dir[256]; |
1144 |
|
|
1145 |
|
home = getenv("HOME"); |
1146 |
|
|
1147 |
|
if (home == NULL) |
1148 |
|
return False; |
1149 |
|
|
1150 |
|
sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop"); |
1151 |
|
|
1152 |
|
if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST) |
1153 |
|
{ |
1154 |
|
perror(bmpcache_dir); |
1155 |
|
return False; |
1156 |
|
} |
1157 |
|
|
1158 |
|
sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop/cache"); |
1159 |
|
|
1160 |
|
if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST) |
1161 |
|
{ |
1162 |
|
perror(bmpcache_dir); |
1163 |
|
return False; |
1164 |
|
} |
1165 |
|
|
1166 |
|
return True; |
1167 |
|
} |
1168 |
|
|
1169 |
|
/* open a file in the .rdesktop directory */ |
1170 |
|
int |
1171 |
|
rd_open_file(char *filename) |
1172 |
|
{ |
1173 |
|
char *home; |
1174 |
|
char fn[256]; |
1175 |
|
int fd; |
1176 |
|
|
1177 |
|
home = getenv("HOME"); |
1178 |
|
if (home == NULL) |
1179 |
|
return -1; |
1180 |
|
sprintf(fn, "%s/.rdesktop/%s", home, filename); |
1181 |
|
fd = open(fn, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); |
1182 |
|
if (fd == -1) |
1183 |
|
perror(fn); |
1184 |
|
return fd; |
1185 |
|
} |
1186 |
|
|
1187 |
|
/* close file */ |
1188 |
|
void |
1189 |
|
rd_close_file(int fd) |
1190 |
|
{ |
1191 |
|
close(fd); |
1192 |
|
} |
1193 |
|
|
1194 |
|
/* read from file*/ |
1195 |
|
int |
1196 |
|
rd_read_file(int fd, void *ptr, int len) |
1197 |
|
{ |
1198 |
|
return read(fd, ptr, len); |
1199 |
|
} |
1200 |
|
|
1201 |
|
/* write to file */ |
1202 |
|
int |
1203 |
|
rd_write_file(int fd, void *ptr, int len) |
1204 |
|
{ |
1205 |
|
return write(fd, ptr, len); |
1206 |
|
} |
1207 |
|
|
1208 |
|
/* move file pointer */ |
1209 |
|
int |
1210 |
|
rd_lseek_file(int fd, int offset) |
1211 |
|
{ |
1212 |
|
return lseek(fd, offset, SEEK_SET); |
1213 |
|
} |
1214 |
|
|
1215 |
|
/* do a write lock on a file */ |
1216 |
|
BOOL |
1217 |
|
rd_lock_file(int fd, int start, int len) |
1218 |
|
{ |
1219 |
|
struct flock lock; |
1220 |
|
|
1221 |
|
lock.l_type = F_WRLCK; |
1222 |
|
lock.l_whence = SEEK_SET; |
1223 |
|
lock.l_start = start; |
1224 |
|
lock.l_len = len; |
1225 |
|
if (fcntl(fd, F_SETLK, &lock) == -1) |
1226 |
|
return False; |
1227 |
|
return True; |
1228 |
|
} |