18 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 |
*/ |
*/ |
20 |
|
|
21 |
#include <stdlib.h> /* malloc realloc free */ |
#include <stdlib.h> /* malloc realloc free */ |
22 |
#include <unistd.h> /* read close getuid getgid getpid getppid gethostname */ |
#include <unistd.h> /* read close getuid getgid getpid getppid gethostname */ |
23 |
#include <fcntl.h> /* open */ |
#include <fcntl.h> /* open */ |
24 |
#include <pwd.h> /* getpwuid */ |
#include <pwd.h> /* getpwuid */ |
25 |
#include <sys/stat.h> /* stat */ |
#include <sys/stat.h> /* stat */ |
26 |
#include <sys/time.h> /* gettimeofday */ |
#include <sys/time.h> /* gettimeofday */ |
27 |
#include <sys/times.h> /* times */ |
#include <sys/times.h> /* times */ |
28 |
#include "rdesktop.h" |
#include "rdesktop.h" |
29 |
|
|
30 |
char username[16]; |
char username[16]; |
32 |
int width = 800; |
int width = 800; |
33 |
int height = 600; |
int height = 600; |
34 |
int keylayout = 0x409; |
int keylayout = 0x409; |
35 |
BOOL motion = False; |
BOOL bitmap_compression = True; |
36 |
|
BOOL motion = True; |
37 |
BOOL orders = True; |
BOOL orders = True; |
38 |
BOOL licence = True; |
BOOL licence = True; |
39 |
|
BOOL use_encryption = True; |
40 |
|
BOOL desktop_save = True; |
41 |
|
BOOL grab_keyboard = True; |
42 |
|
BOOL fullscreen = False; |
43 |
|
int private_colormap = False; |
44 |
|
|
45 |
/* Display usage information */ |
/* Display usage information */ |
46 |
static void usage(char *program) |
static void |
47 |
|
usage(char *program) |
48 |
{ |
{ |
49 |
STATUS("Usage: %s [options] server\n", program); |
STATUS("Usage: %s [options] server\n", program); |
50 |
STATUS(" -u: user name\n"); |
STATUS(" -u: user name\n"); |
51 |
|
STATUS(" -d: domain\n"); |
52 |
|
STATUS(" -s: shell\n"); |
53 |
|
STATUS(" -c: working directory\n"); |
54 |
|
STATUS(" -p: password (autologon)\n"); |
55 |
STATUS(" -n: client hostname\n"); |
STATUS(" -n: client hostname\n"); |
56 |
STATUS(" -w: desktop width\n"); |
STATUS(" -w: desktop width\n"); |
57 |
STATUS(" -h: desktop height\n"); |
STATUS(" -h: desktop height\n"); |
58 |
STATUS(" -k: keyboard layout (hex)\n"); |
STATUS(" -k: keyboard layout (hex)\n"); |
|
STATUS(" -m: send motion events\n"); |
|
59 |
STATUS(" -b: force bitmap updates\n"); |
STATUS(" -b: force bitmap updates\n"); |
60 |
|
STATUS(" -m: do not send motion events\n"); |
61 |
STATUS(" -l: do not request licence\n\n"); |
STATUS(" -l: do not request licence\n\n"); |
62 |
} |
} |
63 |
|
|
64 |
/* Client program */ |
/* Client program */ |
65 |
int main(int argc, char *argv[]) |
int |
66 |
|
main(int argc, char *argv[]) |
67 |
{ |
{ |
68 |
struct passwd *pw; |
struct passwd *pw; |
69 |
char *server; |
char *server; |
70 |
|
uint32 flags; |
71 |
|
char domain[16]; |
72 |
|
char password[16]; |
73 |
|
char shell[32]; |
74 |
|
char directory[32]; |
75 |
char title[32]; |
char title[32]; |
76 |
int c; |
int c; |
77 |
|
|
78 |
STATUS("rdesktop: A Remote Desktop Protocol client.\n"); |
STATUS("rdesktop: A Remote Desktop Protocol client.\n"); |
79 |
STATUS("Version "VERSION". Copyright (C) 1999-2000 Matt Chapman.\n"); |
STATUS("Version " VERSION |
80 |
|
". Copyright (C) 1999-2000 Matt Chapman.\n"); |
81 |
STATUS("See http://www.rdesktop.org/ for more information.\n\n"); |
STATUS("See http://www.rdesktop.org/ for more information.\n\n"); |
82 |
|
|
83 |
while ((c = getopt(argc, argv, "u:n:w:h:k:mbl?")) != -1) |
flags = RDP_LOGON_NORMAL; |
84 |
|
domain[0] = password[0] = shell[0] = directory[0] = 0; |
85 |
|
|
86 |
|
while ((c = getopt(argc, argv, "u:d:s:c:p:n:w:h:k:bml?")) != -1) |
87 |
{ |
{ |
88 |
switch (c) |
switch (c) |
89 |
{ |
{ |
91 |
strncpy(username, optarg, sizeof(username)); |
strncpy(username, optarg, sizeof(username)); |
92 |
break; |
break; |
93 |
|
|
94 |
case 'n': |
case 'd': |
95 |
strncpy(hostname, optarg, sizeof(hostname)); |
strncpy(domain, optarg, sizeof(domain)); |
96 |
break; |
break; |
97 |
|
|
98 |
case 'w': |
case 'p': |
99 |
width = strtol(optarg, NULL, 10); |
flags |= RDP_LOGON_AUTO; |
100 |
|
strncpy(password, optarg, sizeof(password)); |
101 |
break; |
break; |
102 |
|
|
103 |
case 'h': |
case 's': |
104 |
height = strtol(optarg, NULL, 10); |
strncpy(shell, optarg, sizeof(shell)); |
105 |
|
break; |
106 |
|
|
107 |
|
case 'c': |
108 |
|
strncpy(directory, optarg, sizeof(directory)); |
109 |
|
break; |
110 |
|
|
111 |
|
case 'n': |
112 |
|
strncpy(hostname, optarg, sizeof(hostname)); |
113 |
|
break; |
114 |
|
case 'g': |
115 |
|
{ |
116 |
|
char *tgem = 0; |
117 |
|
width = strtol(optarg, NULL, 10); |
118 |
|
tgem = strchr(optarg, 'x'); |
119 |
|
if ((tgem == 0) || (strlen(tgem) < 2)) |
120 |
|
{ |
121 |
|
ERROR |
122 |
|
("-g: invalid parameter. Syntax example: -g 1024x768\n"); |
123 |
|
exit(1); |
124 |
|
} |
125 |
|
height = strtol(tgem + 1, NULL, 10); |
126 |
|
} |
127 |
break; |
break; |
128 |
|
|
129 |
case 'k': |
case 'k': |
130 |
keylayout = strtol(optarg, NULL, 16); |
keylayout = strtol(optarg, NULL, 16); |
131 |
|
/* keylayout = find_keyb_code(optarg); */ |
132 |
|
if (keylayout == 0) |
133 |
|
return 0; |
134 |
break; |
break; |
135 |
|
|
136 |
case 'm': |
case 'm': |
137 |
motion = True; |
motion = False; |
138 |
break; |
break; |
139 |
|
|
140 |
case 'b': |
case 'b': |
145 |
licence = False; |
licence = False; |
146 |
break; |
break; |
147 |
|
|
148 |
|
case 'e': |
149 |
|
use_encryption = False; |
150 |
|
break; |
151 |
|
case 'K': |
152 |
|
grab_keyboard = False; |
153 |
|
break; |
154 |
|
case 'F': |
155 |
|
fullscreen = True; |
156 |
|
break; |
157 |
|
case 'v': |
158 |
|
private_colormap = True; |
159 |
|
break; |
160 |
|
case 'h': |
161 |
case '?': |
case '?': |
162 |
default: |
default: |
163 |
usage(argv[0]); |
usage(argv[0]); |
194 |
} |
} |
195 |
} |
} |
196 |
|
|
|
if (!rdp_connect(server)) |
|
|
return 1; |
|
|
|
|
|
STATUS("Connection successful.\n"); |
|
|
|
|
197 |
strcpy(title, "rdesktop - "); |
strcpy(title, "rdesktop - "); |
198 |
strncat(title, server, sizeof(title)); |
strncat(title, server, sizeof(title)); |
199 |
|
|
200 |
if (ui_create_window(title)) |
if (ui_create_window(title)) |
201 |
{ |
{ |
202 |
|
if (!rdp_connect(server, flags, domain, password, shell, |
203 |
|
directory)) |
204 |
|
return 1; |
205 |
|
|
206 |
|
STATUS("Connection successful.\n"); |
207 |
rdp_main_loop(); |
rdp_main_loop(); |
208 |
ui_destroy_window(); |
ui_destroy_window(); |
209 |
} |
} |
213 |
} |
} |
214 |
|
|
215 |
/* Generate a 32-byte random for the secure transport code. */ |
/* Generate a 32-byte random for the secure transport code. */ |
216 |
void generate_random(uint8 *random) |
void |
217 |
|
generate_random(uint8 *random) |
218 |
{ |
{ |
219 |
struct stat st; |
struct stat st; |
220 |
uint32 *r = (uint32 *)random; |
struct tms tmsbuf; |
221 |
|
uint32 *r = (uint32 *) random; |
222 |
int fd; |
int fd; |
223 |
|
|
224 |
/* If we have a kernel random device, use it. */ |
/* If we have a kernel random device, use it. */ |
232 |
/* Otherwise use whatever entropy we can gather - ideas welcome. */ |
/* Otherwise use whatever entropy we can gather - ideas welcome. */ |
233 |
r[0] = (getpid()) | (getppid() << 16); |
r[0] = (getpid()) | (getppid() << 16); |
234 |
r[1] = (getuid()) | (getgid() << 16); |
r[1] = (getuid()) | (getgid() << 16); |
235 |
r[2] = times(NULL); /* system uptime (clocks) */ |
r[2] = times(&tmsbuf); /* system uptime (clocks) */ |
236 |
gettimeofday((struct timeval *)&r[3], NULL); /* sec and usec */ |
gettimeofday((struct timeval *) &r[3], NULL); /* sec and usec */ |
237 |
stat("/tmp", &st); |
stat("/tmp", &st); |
238 |
r[5] = st.st_atime; |
r[5] = st.st_atime; |
239 |
r[6] = st.st_mtime; |
r[6] = st.st_mtime; |
241 |
} |
} |
242 |
|
|
243 |
/* malloc; exit if out of memory */ |
/* malloc; exit if out of memory */ |
244 |
void *xmalloc(int size) |
void * |
245 |
|
xmalloc(int size) |
246 |
{ |
{ |
247 |
void *mem = malloc(size); |
void *mem = malloc(size); |
248 |
if (mem == NULL) |
if (mem == NULL) |
254 |
} |
} |
255 |
|
|
256 |
/* realloc; exit if out of memory */ |
/* realloc; exit if out of memory */ |
257 |
void *xrealloc(void *oldmem, int size) |
void * |
258 |
|
xrealloc(void *oldmem, int size) |
259 |
{ |
{ |
260 |
void *mem = realloc(oldmem, size); |
void *mem = realloc(oldmem, size); |
261 |
if (mem == NULL) |
if (mem == NULL) |
267 |
} |
} |
268 |
|
|
269 |
/* free */ |
/* free */ |
270 |
void xfree(void *mem) |
void |
271 |
|
xfree(void *mem) |
272 |
{ |
{ |
273 |
free(mem); |
free(mem); |
274 |
} |
} |
275 |
|
|
276 |
/* Produce a hex dump */ |
/* Produce a hex dump */ |
277 |
void hexdump(unsigned char *p, unsigned int len) |
void |
278 |
|
hexdump(unsigned char *p, unsigned int len) |
279 |
{ |
{ |
280 |
unsigned char *line = p; |
unsigned char *line = p; |
281 |
unsigned int thisline, offset = 0; |
unsigned int thisline, offset = 0; |
289 |
thisline = 16; |
thisline = 16; |
290 |
|
|
291 |
for (i = 0; i < thisline; i++) |
for (i = 0; i < thisline; i++) |
292 |
STATUS("%02x ", line[i]) |
STATUS("%02x ", line[i]) for (; i < 16; i++) |
293 |
|
STATUS(" "); |
|
for (; i < 16; i++) |
|
|
STATUS(" "); |
|
294 |
|
|
295 |
for (i = 0; i < thisline; i++) |
for (i = 0; i < thisline; i++) |
296 |
STATUS("%c", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.'); |
STATUS("%c", |
297 |
|
(line[i] >= 0x20 |
298 |
|
&& line[i] < 0x7f) ? line[i] : '.'); |
299 |
|
|
300 |
STATUS("\n"); |
STATUS("\n"); |
301 |
offset += thisline; |
offset += thisline; |