23 |
#include <unistd.h> /* read close getuid getgid getpid getppid gethostname */ |
#include <unistd.h> /* read close getuid getgid getpid getppid gethostname */ |
24 |
#include <fcntl.h> /* open */ |
#include <fcntl.h> /* open */ |
25 |
#include <pwd.h> /* getpwuid */ |
#include <pwd.h> /* getpwuid */ |
26 |
|
#include <limits.h> /* PATH_MAX */ |
27 |
#include <sys/stat.h> /* stat */ |
#include <sys/stat.h> /* stat */ |
28 |
#include <sys/time.h> /* gettimeofday */ |
#include <sys/time.h> /* gettimeofday */ |
29 |
#include <sys/times.h> /* times */ |
#include <sys/times.h> /* times */ |
31 |
|
|
32 |
char username[16]; |
char username[16]; |
33 |
char hostname[16]; |
char hostname[16]; |
34 |
|
char keymapname[16]; |
35 |
|
int keylayout; |
36 |
int width; |
int width; |
37 |
int height; |
int height; |
|
int keylayout = 0x409; |
|
38 |
BOOL bitmap_compression = True; |
BOOL bitmap_compression = True; |
39 |
BOOL sendmotion = True; |
BOOL sendmotion = True; |
40 |
BOOL orders = True; |
BOOL orders = True; |
54 |
printf(" -c: working directory\n"); |
printf(" -c: working directory\n"); |
55 |
printf(" -p: password (autologon)\n"); |
printf(" -p: password (autologon)\n"); |
56 |
printf(" -n: client hostname\n"); |
printf(" -n: client hostname\n"); |
57 |
printf(" -k: keyboard layout (hex)\n"); |
printf(" -k: keyboard layout\n"); |
58 |
printf(" -g: desktop geometry (WxH)\n"); |
printf(" -g: desktop geometry (WxH)\n"); |
59 |
printf(" -f: full-screen mode\n"); |
printf(" -f: full-screen mode\n"); |
60 |
printf(" -b: force bitmap updates\n"); |
printf(" -b: force bitmap updates\n"); |
84 |
|
|
85 |
flags = RDP_LOGON_NORMAL; |
flags = RDP_LOGON_NORMAL; |
86 |
domain[0] = password[0] = shell[0] = directory[0] = 0; |
domain[0] = password[0] = shell[0] = directory[0] = 0; |
87 |
|
strcpy(keymapname, "us"); |
88 |
|
|
89 |
while ((c = getopt(argc, argv, "u:d:s:c:p:n:k:g:fbemlh?")) != -1) |
while ((c = getopt(argc, argv, "u:d:s:c:p:n:k:g:fbemlh?")) != -1) |
90 |
{ |
{ |
116 |
break; |
break; |
117 |
|
|
118 |
case 'k': |
case 'k': |
119 |
keylayout = strtol(optarg, NULL, 16); |
STRNCPY(keymapname, optarg, sizeof(keymapname)); |
|
if (keylayout == 0) |
|
|
{ |
|
|
error("invalid keyboard layout\n"); |
|
|
return 1; |
|
|
} |
|
120 |
break; |
break; |
121 |
|
|
122 |
case 'g': |
case 'g': |
214 |
strcpy(title, "rdesktop - "); |
strcpy(title, "rdesktop - "); |
215 |
strncat(title, server, sizeof(title) - sizeof("rdesktop - ")); |
strncat(title, server, sizeof(title) - sizeof("rdesktop - ")); |
216 |
|
|
217 |
|
if (!rdp_connect(server, flags, domain, password, shell, directory)) |
218 |
|
return 1; |
219 |
|
|
220 |
|
printf("Connection successful.\n"); |
221 |
|
|
222 |
if (ui_create_window(title)) |
if (ui_create_window(title)) |
223 |
{ |
{ |
|
if (!rdp_connect(server, flags, domain, password, shell, |
|
|
directory)) |
|
|
return 1; |
|
|
|
|
|
printf("Connection successful.\n"); |
|
224 |
rdp_main_loop(); |
rdp_main_loop(); |
225 |
ui_destroy_window(); |
ui_destroy_window(); |
226 |
} |
} |
227 |
|
|
228 |
|
printf("Disconnecting...\n"); |
229 |
rdp_disconnect(); |
rdp_disconnect(); |
230 |
return 0; |
return 0; |
231 |
} |
} |
349 |
line += thisline; |
line += thisline; |
350 |
} |
} |
351 |
} |
} |
352 |
|
|
353 |
|
int |
354 |
|
load_licence(unsigned char **data) |
355 |
|
{ |
356 |
|
char path[PATH_MAX]; |
357 |
|
char *home; |
358 |
|
struct stat st; |
359 |
|
int fd; |
360 |
|
|
361 |
|
home = getenv("HOME"); |
362 |
|
if (home == NULL) |
363 |
|
return -1; |
364 |
|
|
365 |
|
STRNCPY(path, home, sizeof(path)); |
366 |
|
strncat(path, "/.rdesktop/licence", sizeof(path)-strlen(path)-1); |
367 |
|
|
368 |
|
fd = open(path, O_RDONLY); |
369 |
|
if (fd == -1) |
370 |
|
return -1; |
371 |
|
|
372 |
|
if (fstat(fd, &st)) |
373 |
|
return -1; |
374 |
|
|
375 |
|
*data = xmalloc(st.st_size); |
376 |
|
return read(fd, *data, st.st_size); |
377 |
|
} |
378 |
|
|
379 |
|
void |
380 |
|
save_licence(unsigned char *data, int length) |
381 |
|
{ |
382 |
|
char path[PATH_MAX]; |
383 |
|
char *home; |
384 |
|
int fd; |
385 |
|
|
386 |
|
home = getenv("HOME"); |
387 |
|
if (home == NULL) |
388 |
|
return; |
389 |
|
|
390 |
|
STRNCPY(path, home, sizeof(path)); |
391 |
|
strncat(path, "/.rdesktop", sizeof(path)-strlen(path)-1); |
392 |
|
mkdir(path, 0700); |
393 |
|
|
394 |
|
strncat(path, "/licence", sizeof(path)-strlen(path)-1); |
395 |
|
|
396 |
|
fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0600); |
397 |
|
if (fd == -1) |
398 |
|
{ |
399 |
|
perror("open"); |
400 |
|
return; |
401 |
|
} |
402 |
|
|
403 |
|
write(fd, data, length); |
404 |
|
close(fd); |
405 |
|
} |
406 |
|
|