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_orders = 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; |
66 |
BOOL g_use_rdp5 = True; |
BOOL g_use_rdp5 = True; |
67 |
BOOL g_console_session = False; |
BOOL g_console_session = False; |
68 |
BOOL g_numlock_sync = False; |
BOOL g_numlock_sync = False; |
69 |
extern BOOL g_owncolmap; |
BOOL g_owncolmap = False; |
70 |
extern BOOL g_ownbackstore; |
BOOL g_ownbackstore = True; /* We can't rely on external BackingStore */ |
71 |
|
uint32 g_embed_wnd; |
72 |
|
uint32 g_rdp5_performanceflags = |
73 |
|
RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS; |
74 |
|
|
75 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
76 |
BOOL g_rdpsnd = False; |
BOOL g_rdpsnd = False; |
78 |
|
|
79 |
extern RDPDR_DEVICE g_rdpdr_device[]; |
extern RDPDR_DEVICE g_rdpdr_device[]; |
80 |
extern uint32 g_num_devices; |
extern uint32 g_num_devices; |
81 |
|
extern char *g_rdpdr_clientname; |
82 |
|
|
83 |
#ifdef RDP2VNC |
#ifdef RDP2VNC |
84 |
extern int rfb_port; |
extern int rfb_port; |
120 |
fprintf(stderr, " -S: caption button size (single application mode)\n"); |
fprintf(stderr, " -S: caption button size (single application mode)\n"); |
121 |
fprintf(stderr, " -T: window title\n"); |
fprintf(stderr, " -T: window title\n"); |
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"); |
124 |
fprintf(stderr, " -a: connection colour depth\n"); |
fprintf(stderr, " -a: connection colour depth\n"); |
125 |
|
fprintf(stderr, " -z: enable rdp compression\n"); |
126 |
|
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"); |
136 |
|
fprintf(stderr, " for redirected disks\n"); |
137 |
fprintf(stderr, |
fprintf(stderr, |
138 |
" '-r lptport:LPT1=/dev/lp0': enable parallel redirection of /dev/lp0 to LPT1\n"); |
" '-r lptport:LPT1=/dev/lp0': enable parallel redirection of /dev/lp0 to LPT1\n"); |
139 |
fprintf(stderr, " or LPT1=/dev/lp0,LPT2=/dev/lp1\n"); |
fprintf(stderr, " or LPT1=/dev/lp0,LPT2=/dev/lp1\n"); |
140 |
fprintf(stderr, " '-r printer:mydeskjet': enable printer redirection\n"); |
fprintf(stderr, " '-r printer:mydeskjet': enable printer redirection\n"); |
141 |
fprintf(stderr, |
fprintf(stderr, |
142 |
" or mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n"); |
" or mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n"); |
143 |
fprintf(stderr, " '-r sound:[on|off|remote]': enable sound redirection\n"); |
fprintf(stderr, " '-r sound:[local|off|remote]': enable sound redirection\n"); |
144 |
fprintf(stderr, " remote would leave sound on server\n"); |
fprintf(stderr, " remote would leave sound on server\n"); |
145 |
fprintf(stderr, " -0: attach to console\n"); |
fprintf(stderr, " -0: attach to console\n"); |
146 |
fprintf(stderr, " -4: use RDP version 4\n"); |
fprintf(stderr, " -4: use RDP version 4\n"); |
147 |
fprintf(stderr, " -5: use RDP version 5 (default)\n"); |
fprintf(stderr, " -5: use RDP version 5 (default)\n"); |
148 |
} |
} |
149 |
|
|
150 |
|
void |
151 |
|
print_disconnect_reason(uint16 reason) |
152 |
|
{ |
153 |
|
char *text; |
154 |
|
|
155 |
|
switch (reason) |
156 |
|
{ |
157 |
|
case exDiscReasonNoInfo: |
158 |
|
text = "No information available"; |
159 |
|
break; |
160 |
|
|
161 |
|
case exDiscReasonAPIInitiatedDisconnect: |
162 |
|
text = "Server initiated disconnect"; |
163 |
|
break; |
164 |
|
|
165 |
|
case exDiscReasonAPIInitiatedLogoff: |
166 |
|
text = "Server initiated logoff"; |
167 |
|
break; |
168 |
|
|
169 |
|
case exDiscReasonServerIdleTimeout: |
170 |
|
text = "Server idle timeout reached"; |
171 |
|
break; |
172 |
|
|
173 |
|
case exDiscReasonServerLogonTimeout: |
174 |
|
text = "Server logon timeout reached"; |
175 |
|
break; |
176 |
|
|
177 |
|
case exDiscReasonReplacedByOtherConnection: |
178 |
|
text = "The session was replaced"; |
179 |
|
break; |
180 |
|
|
181 |
|
case exDiscReasonOutOfMemory: |
182 |
|
text = "The server is out of memory"; |
183 |
|
break; |
184 |
|
|
185 |
|
case exDiscReasonServerDeniedConnection: |
186 |
|
text = "The server denied the connection"; |
187 |
|
break; |
188 |
|
|
189 |
|
case exDiscReasonServerDeniedConnectionFips: |
190 |
|
text = "The server denied the connection for security reason"; |
191 |
|
break; |
192 |
|
|
193 |
|
case exDiscReasonLicenseInternal: |
194 |
|
text = "Internal licensing error"; |
195 |
|
break; |
196 |
|
|
197 |
|
case exDiscReasonLicenseNoLicenseServer: |
198 |
|
text = "No license server available"; |
199 |
|
break; |
200 |
|
|
201 |
|
case exDiscReasonLicenseNoLicense: |
202 |
|
text = "No valid license available"; |
203 |
|
break; |
204 |
|
|
205 |
|
case exDiscReasonLicenseErrClientMsg: |
206 |
|
text = "Invalid licensing message"; |
207 |
|
break; |
208 |
|
|
209 |
|
case exDiscReasonLicenseHwidDoesntMatchLicense: |
210 |
|
text = "Hardware id doesn't match software license"; |
211 |
|
break; |
212 |
|
|
213 |
|
case exDiscReasonLicenseErrClientLicense: |
214 |
|
text = "Client license error"; |
215 |
|
break; |
216 |
|
|
217 |
|
case exDiscReasonLicenseCantFinishProtocol: |
218 |
|
text = "Network error during licensing protocol"; |
219 |
|
break; |
220 |
|
|
221 |
|
case exDiscReasonLicenseClientEndedProtocol: |
222 |
|
text = "Licensing protocol was not completed"; |
223 |
|
break; |
224 |
|
|
225 |
|
case exDiscReasonLicenseErrClientEncryption: |
226 |
|
text = "Incorrect client license enryption"; |
227 |
|
break; |
228 |
|
|
229 |
|
case exDiscReasonLicenseCantUpgradeLicense: |
230 |
|
text = "Can't upgrade license"; |
231 |
|
break; |
232 |
|
|
233 |
|
case exDiscReasonLicenseNoRemoteConnections: |
234 |
|
text = "The server is not licensed to accept remote connections"; |
235 |
|
break; |
236 |
|
|
237 |
|
default: |
238 |
|
if (reason > 0x1000 && reason < 0x7fff) |
239 |
|
{ |
240 |
|
text = "Internal protocol error"; |
241 |
|
} |
242 |
|
else |
243 |
|
{ |
244 |
|
text = "Unknown reason"; |
245 |
|
} |
246 |
|
} |
247 |
|
fprintf(stderr, "disconnect: %s.\n", text); |
248 |
|
} |
249 |
|
|
250 |
static BOOL |
static BOOL |
251 |
read_password(char *password, int size) |
read_password(char *password, int size) |
252 |
{ |
{ |
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 */ |
341 |
char password[64]; |
char password[64]; |
342 |
char shell[128]; |
char shell[128]; |
343 |
char directory[32]; |
char directory[32]; |
344 |
BOOL prompt_password, rdp_retval = False; |
BOOL prompt_password, deactivated; |
345 |
struct passwd *pw; |
struct passwd *pw; |
346 |
uint32 flags; |
uint32 flags, ext_disc_reason = 0; |
347 |
char *p; |
char *p; |
348 |
int c; |
int c; |
349 |
|
|
353 |
prompt_password = False; |
prompt_password = False; |
354 |
domain[0] = password[0] = shell[0] = directory[0] = 0; |
domain[0] = password[0] = shell[0] = directory[0] = 0; |
355 |
strcpy(keymapname, "en-us"); |
strcpy(keymapname, "en-us"); |
356 |
|
g_embed_wnd = 0; |
357 |
|
|
358 |
g_num_devices = 0; |
g_num_devices = 0; |
359 |
|
|
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:Na: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': |
457 |
break; |
break; |
458 |
|
|
459 |
case 'b': |
case 'b': |
460 |
g_orders = False; |
g_bitmap_cache = False; |
461 |
break; |
break; |
462 |
|
|
463 |
case 'B': |
case 'B': |
511 |
g_numlock_sync = True; |
g_numlock_sync = True; |
512 |
break; |
break; |
513 |
|
|
514 |
|
case 'X': |
515 |
|
g_embed_wnd = strtol(optarg, NULL, 10); |
516 |
|
break; |
517 |
|
|
518 |
case 'a': |
case 'a': |
519 |
g_server_bpp = strtol(optarg, NULL, 10); |
g_server_bpp = strtol(optarg, NULL, 10); |
520 |
if (g_server_bpp != 8 && g_server_bpp != 16 && g_server_bpp != 15 |
if (g_server_bpp != 8 && g_server_bpp != 16 && g_server_bpp != 15 |
525 |
} |
} |
526 |
break; |
break; |
527 |
|
|
528 |
|
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) |
535 |
|
{ |
536 |
|
g_rdp5_performanceflags = |
537 |
|
RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | |
538 |
|
RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING; |
539 |
|
} |
540 |
|
else if (strncmp("broadband", optarg, 1) == 0) |
541 |
|
{ |
542 |
|
g_rdp5_performanceflags = RDP5_NO_WALLPAPER; |
543 |
|
} |
544 |
|
else if (strncmp("lan", optarg, 1) == 0) |
545 |
|
{ |
546 |
|
g_rdp5_performanceflags = RDP5_DISABLE_NOTHING; |
547 |
|
} |
548 |
|
else |
549 |
|
{ |
550 |
|
g_rdp5_performanceflags = strtol(optarg, NULL, 16); |
551 |
|
} |
552 |
|
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) |
561 |
{ |
{ |
562 |
if (*(optarg + 6) == ':') |
optarg += 5; |
|
{ |
|
563 |
|
|
564 |
if (strncmp("remote", optarg + 7, 6) == 0) |
if (*optarg == ':') |
565 |
flags |= RDP_LOGON_LEAVE_AUDIO; |
{ |
566 |
else if (strncmp("on", optarg + 7, 2) == 0) |
*optarg++; |
567 |
|
while ((p = next_arg(optarg, ','))) |
568 |
{ |
{ |
569 |
|
if (strncmp("remote", optarg, 6) == 0) |
570 |
|
flags |= RDP_LOGON_LEAVE_AUDIO; |
571 |
|
|
572 |
|
if (strncmp("local", 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) |
580 |
|
#ifdef WITH_RDPSND |
581 |
|
g_rdpsnd = False; |
582 |
|
#else |
583 |
|
warning("Not compiled with sound support\n"); |
584 |
|
#endif |
585 |
|
|
586 |
|
optarg = p; |
587 |
} |
} |
588 |
} |
} |
589 |
else |
else |
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 |
} |
} |
612 |
{ |
{ |
613 |
printer_enum_devices(&g_num_devices, optarg + 7); |
printer_enum_devices(&g_num_devices, optarg + 7); |
614 |
} |
} |
615 |
|
else if (strncmp("clientname", optarg, 7) == 0) |
616 |
|
{ |
617 |
|
g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1); |
618 |
|
strcpy(g_rdpdr_clientname, optarg + 11); |
619 |
|
} |
620 |
else |
else |
621 |
{ |
{ |
622 |
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"); |
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))) |
716 |
|
|
717 |
if (ui_create_window()) |
if (ui_create_window()) |
718 |
{ |
{ |
719 |
rdp_retval = rdp_main_loop(); |
rdp_main_loop(&deactivated, &ext_disc_reason); |
720 |
ui_destroy_window(); |
ui_destroy_window(); |
721 |
} |
} |
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 (True == rdp_retval) |
if (ext_disc_reason >= 2) |
729 |
|
print_disconnect_reason(ext_disc_reason); |
730 |
|
|
731 |
|
if (deactivated) |
732 |
|
{ |
733 |
|
/* clean disconnect */ |
734 |
return 0; |
return 0; |
735 |
|
} |
736 |
else |
else |
737 |
return 2; |
{ |
738 |
|
if (ext_disc_reason == exDiscReasonAPIInitiatedDisconnect |
739 |
|
|| ext_disc_reason == exDiscReasonAPIInitiatedLogoff) |
740 |
|
{ |
741 |
|
/* not so clean disconnect, but nothing to worry about */ |
742 |
|
return 0; |
743 |
|
} |
744 |
|
else |
745 |
|
{ |
746 |
|
/* return error */ |
747 |
|
return 2; |
748 |
|
} |
749 |
|
} |
750 |
|
|
751 |
#endif |
#endif |
752 |
|
|
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 |
|
} |