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 |
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]; |
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 g_xpos = 0; |
53 |
|
int g_ypos = 0; |
54 |
extern int g_tcp_port_rdp; |
extern int g_tcp_port_rdp; |
55 |
int g_server_bpp = 8; |
int g_server_bpp = 8; |
56 |
int g_win_button_size = 0; /* If zero, disable single app mode */ |
int g_win_button_size = 0; /* If zero, disable single app mode */ |
57 |
BOOL g_bitmap_compression = True; |
BOOL g_bitmap_compression = True; |
58 |
BOOL g_sendmotion = True; |
BOOL g_sendmotion = True; |
59 |
BOOL g_bitmap_cache = True; |
BOOL g_bitmap_cache = True; |
60 |
|
BOOL g_bitmap_cache_persist_enable = False; |
61 |
|
BOOL g_bitmap_cache_precache = True; |
62 |
BOOL g_encryption = True; |
BOOL g_encryption = True; |
63 |
BOOL packet_encryption = True; |
BOOL packet_encryption = True; |
64 |
BOOL g_desktop_save = True; |
BOOL g_desktop_save = True; /* desktop save order */ |
65 |
|
BOOL g_polygon_ellipse_orders = True; /* polygon / ellipse orders */ |
66 |
BOOL g_fullscreen = False; |
BOOL g_fullscreen = False; |
67 |
BOOL g_grab_keyboard = True; |
BOOL g_grab_keyboard = True; |
68 |
BOOL g_hide_decorations = False; |
BOOL g_hide_decorations = False; |
95 |
usage(char *program) |
usage(char *program) |
96 |
{ |
{ |
97 |
fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n"); |
fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n"); |
98 |
fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2003 Matt Chapman.\n"); |
fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2005 Matt Chapman.\n"); |
99 |
fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n"); |
fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n"); |
100 |
|
|
101 |
fprintf(stderr, "Usage: %s [options] server[:port]\n", program); |
fprintf(stderr, "Usage: %s [options] server[:port]\n", program); |
125 |
fprintf(stderr, " -N: enable numlock syncronization\n"); |
fprintf(stderr, " -N: enable numlock syncronization\n"); |
126 |
fprintf(stderr, " -X: embed into another window with a given id.\n"); |
fprintf(stderr, " -X: embed into another window with a given id.\n"); |
127 |
fprintf(stderr, " -a: connection colour depth\n"); |
fprintf(stderr, " -a: connection colour depth\n"); |
128 |
fprintf(stderr, |
fprintf(stderr, " -z: enable rdp compression\n"); |
129 |
" -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"); |
130 |
|
fprintf(stderr, " -P: use persistent bitmap caching\n"); |
131 |
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"); |
132 |
fprintf(stderr, |
fprintf(stderr, |
133 |
" '-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"); |
134 |
fprintf(stderr, " or COM1=/dev/ttyS0,COM2=/dev/ttyS1\n"); |
fprintf(stderr, " or COM1=/dev/ttyS0,COM2=/dev/ttyS1\n"); |
135 |
fprintf(stderr, |
fprintf(stderr, |
136 |
" '-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"); |
137 |
fprintf(stderr, " or A=/mnt/floppy,D=/mnt/cdrom'\n"); |
fprintf(stderr, " or 'floppy=/mnt/floppy,cdrom=/mnt/cdrom'\n"); |
138 |
fprintf(stderr, " '-r clientname=<client name>': Set the client name displayed\n"); |
fprintf(stderr, " '-r clientname=<client name>': Set the client name displayed\n"); |
139 |
fprintf(stderr, " for redirected disks\n"); |
fprintf(stderr, " for redirected disks\n"); |
140 |
fprintf(stderr, |
fprintf(stderr, |
366 |
#define VNCOPT |
#define VNCOPT |
367 |
#endif |
#endif |
368 |
|
|
369 |
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, |
370 |
|
VNCOPT "u:d:s:c:p:n:k:g:fbBeEmzCDKS:T:NX:a:x:Pr:045h?")) != -1) |
371 |
{ |
{ |
372 |
switch (c) |
switch (c) |
373 |
{ |
{ |
442 |
} |
} |
443 |
|
|
444 |
if (*p == 'x') |
if (*p == 'x') |
445 |
g_height = strtol(p + 1, NULL, 10); |
g_height = strtol(p + 1, &p, 10); |
446 |
|
|
447 |
if (g_height <= 0) |
if (g_height <= 0) |
448 |
{ |
{ |
451 |
} |
} |
452 |
|
|
453 |
if (*p == '%') |
if (*p == '%') |
454 |
|
{ |
455 |
g_width = -g_width; |
g_width = -g_width; |
456 |
|
p++; |
457 |
|
} |
458 |
|
|
459 |
|
if (*p == '+' || *p == '-') |
460 |
|
g_xpos = strtol(p, &p, 10); |
461 |
|
|
462 |
|
if (*p == '+' || *p == '-') |
463 |
|
g_ypos = strtol(p, NULL, 10); |
464 |
|
|
465 |
break; |
break; |
466 |
|
|
537 |
} |
} |
538 |
break; |
break; |
539 |
|
|
540 |
case 'x': |
case 'z': |
541 |
|
DEBUG(("rdp compression enabled\n")); |
542 |
|
flags |= RDP_COMPRESSION; |
543 |
|
break; |
544 |
|
|
545 |
|
case 'x': |
546 |
if (strncmp("modem", optarg, 1) == 0) |
if (strncmp("modem", optarg, 1) == 0) |
547 |
{ |
{ |
548 |
g_rdp5_performanceflags = |
g_rdp5_performanceflags = |
563 |
} |
} |
564 |
break; |
break; |
565 |
|
|
566 |
|
case 'P': |
567 |
|
g_bitmap_cache_persist_enable = True; |
568 |
|
break; |
569 |
|
|
570 |
case 'r': |
case 'r': |
571 |
|
|
572 |
if (strncmp("sound", optarg, 5) == 0) |
if (strncmp("sound", optarg, 5) == 0) |
585 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
586 |
g_rdpsnd = True; |
g_rdpsnd = True; |
587 |
#else |
#else |
588 |
warning("Not compiled with sound support"); |
warning("Not compiled with sound support\n"); |
589 |
#endif |
#endif |
590 |
|
|
591 |
if (strncmp("off", optarg, 3) == 0) |
if (strncmp("off", optarg, 3) == 0) |
592 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
593 |
g_rdpsnd = False; |
g_rdpsnd = False; |
594 |
#else |
#else |
595 |
warning("Not compiled with sound support"); |
warning("Not compiled with sound support\n"); |
596 |
#endif |
#endif |
597 |
|
|
598 |
optarg = p; |
optarg = p; |
603 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
604 |
g_rdpsnd = True; |
g_rdpsnd = True; |
605 |
#else |
#else |
606 |
warning("Not compiled with sound support"); |
warning("Not compiled with sound support\n"); |
607 |
#endif |
#endif |
608 |
} |
} |
609 |
} |
} |
691 |
STRNCPY(g_hostname, fullhostname, sizeof(g_hostname)); |
STRNCPY(g_hostname, fullhostname, sizeof(g_hostname)); |
692 |
} |
} |
693 |
|
|
694 |
|
if ((flags & RDP_COMPRESSION) && (g_server_bpp > 8)) |
695 |
|
{ |
696 |
|
warning("rdp compression not supported for bpp > 8, compression disabled\n"); |
697 |
|
flags ^= RDP_COMPRESSION; |
698 |
|
} |
699 |
|
|
700 |
if (prompt_password && read_password(password, sizeof(password))) |
if (prompt_password && read_password(password, sizeof(password))) |
701 |
flags |= RDP_LOGON_AUTO; |
flags |= RDP_LOGON_AUTO; |
702 |
|
|
740 |
|
|
741 |
DEBUG(("Disconnecting...\n")); |
DEBUG(("Disconnecting...\n")); |
742 |
rdp_disconnect(); |
rdp_disconnect(); |
743 |
|
cache_save_state(); |
744 |
ui_deinit(); |
ui_deinit(); |
745 |
|
|
746 |
if (ext_disc_reason >= 2) |
if (ext_disc_reason >= 2) |
870 |
void * |
void * |
871 |
xrealloc(void *oldmem, int size) |
xrealloc(void *oldmem, int size) |
872 |
{ |
{ |
873 |
void *mem = realloc(oldmem, size); |
void *mem; |
874 |
|
|
875 |
|
if (size < 1) |
876 |
|
size = 1; |
877 |
|
mem = realloc(oldmem, size); |
878 |
if (mem == NULL) |
if (mem == NULL) |
879 |
{ |
{ |
880 |
error("xrealloc %d\n", size); |
error("xrealloc %d\n", size); |
1152 |
xfree(tmppath); |
xfree(tmppath); |
1153 |
xfree(path); |
xfree(path); |
1154 |
} |
} |
1155 |
|
|
1156 |
|
/* Create the bitmap cache directory */ |
1157 |
|
BOOL |
1158 |
|
rd_pstcache_mkdir(void) |
1159 |
|
{ |
1160 |
|
char *home; |
1161 |
|
char bmpcache_dir[256]; |
1162 |
|
|
1163 |
|
home = getenv("HOME"); |
1164 |
|
|
1165 |
|
if (home == NULL) |
1166 |
|
return False; |
1167 |
|
|
1168 |
|
sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop"); |
1169 |
|
|
1170 |
|
if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST) |
1171 |
|
{ |
1172 |
|
perror(bmpcache_dir); |
1173 |
|
return False; |
1174 |
|
} |
1175 |
|
|
1176 |
|
sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop/cache"); |
1177 |
|
|
1178 |
|
if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST) |
1179 |
|
{ |
1180 |
|
perror(bmpcache_dir); |
1181 |
|
return False; |
1182 |
|
} |
1183 |
|
|
1184 |
|
return True; |
1185 |
|
} |
1186 |
|
|
1187 |
|
/* open a file in the .rdesktop directory */ |
1188 |
|
int |
1189 |
|
rd_open_file(char *filename) |
1190 |
|
{ |
1191 |
|
char *home; |
1192 |
|
char fn[256]; |
1193 |
|
int fd; |
1194 |
|
|
1195 |
|
home = getenv("HOME"); |
1196 |
|
if (home == NULL) |
1197 |
|
return -1; |
1198 |
|
sprintf(fn, "%s/.rdesktop/%s", home, filename); |
1199 |
|
fd = open(fn, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); |
1200 |
|
if (fd == -1) |
1201 |
|
perror(fn); |
1202 |
|
return fd; |
1203 |
|
} |
1204 |
|
|
1205 |
|
/* close file */ |
1206 |
|
void |
1207 |
|
rd_close_file(int fd) |
1208 |
|
{ |
1209 |
|
close(fd); |
1210 |
|
} |
1211 |
|
|
1212 |
|
/* read from file*/ |
1213 |
|
int |
1214 |
|
rd_read_file(int fd, void *ptr, int len) |
1215 |
|
{ |
1216 |
|
return read(fd, ptr, len); |
1217 |
|
} |
1218 |
|
|
1219 |
|
/* write to file */ |
1220 |
|
int |
1221 |
|
rd_write_file(int fd, void *ptr, int len) |
1222 |
|
{ |
1223 |
|
return write(fd, ptr, len); |
1224 |
|
} |
1225 |
|
|
1226 |
|
/* move file pointer */ |
1227 |
|
int |
1228 |
|
rd_lseek_file(int fd, int offset) |
1229 |
|
{ |
1230 |
|
return lseek(fd, offset, SEEK_SET); |
1231 |
|
} |
1232 |
|
|
1233 |
|
/* do a write lock on a file */ |
1234 |
|
BOOL |
1235 |
|
rd_lock_file(int fd, int start, int len) |
1236 |
|
{ |
1237 |
|
struct flock lock; |
1238 |
|
|
1239 |
|
lock.l_type = F_WRLCK; |
1240 |
|
lock.l_whence = SEEK_SET; |
1241 |
|
lock.l_start = start; |
1242 |
|
lock.l_len = len; |
1243 |
|
if (fcntl(fd, F_SETLK, &lock) == -1) |
1244 |
|
return False; |
1245 |
|
return True; |
1246 |
|
} |