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; |
38 |
int keylayout = 0x409; |
int tcp_port_rdp = TCP_PORT_RDP; |
39 |
BOOL bitmap_compression = True; |
BOOL bitmap_compression = True; |
40 |
BOOL sendmotion = True; |
BOOL sendmotion = True; |
41 |
BOOL orders = True; |
BOOL orders = True; |
55 |
printf(" -c: working directory\n"); |
printf(" -c: working directory\n"); |
56 |
printf(" -p: password (autologon)\n"); |
printf(" -p: password (autologon)\n"); |
57 |
printf(" -n: client hostname\n"); |
printf(" -n: client hostname\n"); |
58 |
printf(" -k: keyboard layout (hex)\n"); |
printf(" -k: keyboard layout\n"); |
59 |
printf(" -g: desktop geometry (WxH)\n"); |
printf(" -g: desktop geometry (WxH)\n"); |
60 |
printf(" -f: full-screen mode\n"); |
printf(" -f: full-screen mode\n"); |
61 |
printf(" -b: force bitmap updates\n"); |
printf(" -b: force bitmap updates\n"); |
62 |
printf(" -e: disable encryption (French TS)\n"); |
printf(" -e: disable encryption (French TS)\n"); |
63 |
printf(" -m: do not send motion events\n"); |
printf(" -m: do not send motion events\n"); |
64 |
printf(" -l: do not request licence\n\n"); |
printf(" -l: do not request licence\n"); |
65 |
|
printf(" -t: rdp tcp port\n\n"); |
66 |
} |
} |
67 |
|
|
68 |
/* Client program */ |
/* Client program */ |
86 |
|
|
87 |
flags = RDP_LOGON_NORMAL; |
flags = RDP_LOGON_NORMAL; |
88 |
domain[0] = password[0] = shell[0] = directory[0] = 0; |
domain[0] = password[0] = shell[0] = directory[0] = 0; |
89 |
|
strcpy(keymapname, "us"); |
90 |
|
|
91 |
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:t:fbemlh?")) != -1) |
92 |
{ |
{ |
93 |
switch (c) |
switch (c) |
94 |
{ |
{ |
118 |
break; |
break; |
119 |
|
|
120 |
case 'k': |
case 'k': |
121 |
keylayout = strtol(optarg, NULL, 16); |
STRNCPY(keymapname, optarg, sizeof(keymapname)); |
|
if (keylayout == 0) |
|
|
{ |
|
|
error("invalid keyboard layout\n"); |
|
|
return 1; |
|
|
} |
|
122 |
break; |
break; |
123 |
|
|
124 |
case 'g': |
case 'g': |
153 |
licence = False; |
licence = False; |
154 |
break; |
break; |
155 |
|
|
156 |
|
case 't': |
157 |
|
tcp_port_rdp = strtol(optarg, NULL, 10); |
158 |
|
break; |
159 |
|
|
160 |
case 'h': |
case 'h': |
161 |
case '?': |
case '?': |
162 |
default: |
default: |
220 |
strcpy(title, "rdesktop - "); |
strcpy(title, "rdesktop - "); |
221 |
strncat(title, server, sizeof(title) - sizeof("rdesktop - ")); |
strncat(title, server, sizeof(title) - sizeof("rdesktop - ")); |
222 |
|
|
223 |
|
if (!rdp_connect(server, flags, domain, password, shell, directory)) |
224 |
|
return 1; |
225 |
|
|
226 |
|
printf("Connection successful.\n"); |
227 |
|
|
228 |
if (ui_create_window(title)) |
if (ui_create_window(title)) |
229 |
{ |
{ |
|
if (!rdp_connect(server, flags, domain, password, shell, |
|
|
directory)) |
|
|
return 1; |
|
|
|
|
|
printf("Connection successful.\n"); |
|
230 |
rdp_main_loop(); |
rdp_main_loop(); |
|
printf("Disconnecting...\n"); |
|
231 |
ui_destroy_window(); |
ui_destroy_window(); |
232 |
} |
} |
233 |
|
|
234 |
|
printf("Disconnecting...\n"); |
235 |
rdp_disconnect(); |
rdp_disconnect(); |
236 |
return 0; |
return 0; |
237 |
} |
} |
355 |
line += thisline; |
line += thisline; |
356 |
} |
} |
357 |
} |
} |
358 |
|
|
359 |
|
int |
360 |
|
load_licence(unsigned char **data) |
361 |
|
{ |
362 |
|
char path[PATH_MAX]; |
363 |
|
char *home; |
364 |
|
struct stat st; |
365 |
|
int fd; |
366 |
|
|
367 |
|
home = getenv("HOME"); |
368 |
|
if (home == NULL) |
369 |
|
return -1; |
370 |
|
|
371 |
|
STRNCPY(path, home, sizeof(path)); |
372 |
|
strncat(path, "/.rdesktop/licence", sizeof(path)-strlen(path)-1); |
373 |
|
|
374 |
|
fd = open(path, O_RDONLY); |
375 |
|
if (fd == -1) |
376 |
|
return -1; |
377 |
|
|
378 |
|
if (fstat(fd, &st)) |
379 |
|
return -1; |
380 |
|
|
381 |
|
*data = xmalloc(st.st_size); |
382 |
|
return read(fd, *data, st.st_size); |
383 |
|
} |
384 |
|
|
385 |
|
void |
386 |
|
save_licence(unsigned char *data, int length) |
387 |
|
{ |
388 |
|
char path[PATH_MAX]; |
389 |
|
char *home; |
390 |
|
int fd; |
391 |
|
|
392 |
|
home = getenv("HOME"); |
393 |
|
if (home == NULL) |
394 |
|
return; |
395 |
|
|
396 |
|
STRNCPY(path, home, sizeof(path)); |
397 |
|
strncat(path, "/.rdesktop", sizeof(path)-strlen(path)-1); |
398 |
|
mkdir(path, 0700); |
399 |
|
|
400 |
|
strncat(path, "/licence", sizeof(path)-strlen(path)-1); |
401 |
|
|
402 |
|
fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0600); |
403 |
|
if (fd == -1) |
404 |
|
{ |
405 |
|
perror("open"); |
406 |
|
return; |
407 |
|
} |
408 |
|
|
409 |
|
write(fd, data, length); |
410 |
|
close(fd); |
411 |
|
} |
412 |
|
|