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 = True; |
BOOL bitmap_compression = True; |
36 |
|
BOOL sendmotion = 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 fullscreen = False; |
42 |
|
|
43 |
/* Display usage information */ |
/* Display usage information */ |
44 |
static void usage(char *program) |
static void |
45 |
|
usage(char *program) |
46 |
{ |
{ |
47 |
STATUS("Usage: %s [options] server\n", program); |
STATUS("Usage: %s [options] server\n", program); |
48 |
STATUS(" -u: user name\n"); |
STATUS(" -u: user name\n"); |
60 |
} |
} |
61 |
|
|
62 |
/* Client program */ |
/* Client program */ |
63 |
int main(int argc, char *argv[]) |
int |
64 |
|
main(int argc, char *argv[]) |
65 |
{ |
{ |
66 |
struct passwd *pw; |
struct passwd *pw; |
67 |
char *server; |
char *server; |
74 |
int c; |
int c; |
75 |
|
|
76 |
STATUS("rdesktop: A Remote Desktop Protocol client.\n"); |
STATUS("rdesktop: A Remote Desktop Protocol client.\n"); |
77 |
STATUS("Version "VERSION". Copyright (C) 1999-2000 Matt Chapman.\n"); |
STATUS("Version " VERSION |
78 |
|
". Copyright (C) 1999-2000 Matt Chapman.\n"); |
79 |
STATUS("See http://www.rdesktop.org/ for more information.\n\n"); |
STATUS("See http://www.rdesktop.org/ for more information.\n\n"); |
80 |
|
|
81 |
flags = RDP_LOGON_NORMAL; |
flags = RDP_LOGON_NORMAL; |
82 |
domain[0] = password[0] = shell[0] = directory[0] = 0; |
domain[0] = password[0] = shell[0] = directory[0] = 0; |
83 |
|
|
84 |
while ((c = getopt(argc, argv, "u:d:s:c:p:n:w:h:k:bml?")) != -1) |
while ((c = getopt(argc, argv, "u:d:s:c:p:n:g:k:mbleKFVh?")) != -1) |
85 |
{ |
{ |
86 |
switch (c) |
switch (c) |
87 |
{ |
{ |
109 |
case 'n': |
case 'n': |
110 |
strncpy(hostname, optarg, sizeof(hostname)); |
strncpy(hostname, optarg, sizeof(hostname)); |
111 |
break; |
break; |
112 |
|
case 'g': |
113 |
case 'w': |
{ |
114 |
width = strtol(optarg, NULL, 10); |
char *tgem = 0; |
115 |
break; |
width = strtol(optarg, NULL, 10); |
116 |
|
tgem = strchr(optarg, 'x'); |
117 |
case 'h': |
if ((tgem == 0) || (strlen(tgem) < 2)) |
118 |
height = strtol(optarg, NULL, 10); |
{ |
119 |
|
ERROR |
120 |
|
("-g: invalid parameter. Syntax example: -g 1024x768\n"); |
121 |
|
exit(1); |
122 |
|
} |
123 |
|
height = strtol(tgem + 1, NULL, 10); |
124 |
|
} |
125 |
break; |
break; |
126 |
|
|
127 |
case 'k': |
case 'k': |
128 |
keylayout = strtol(optarg, NULL, 16); |
keylayout = strtol(optarg, NULL, 16); |
129 |
|
/* keylayout = find_keyb_code(optarg); */ |
130 |
|
if (keylayout == 0) |
131 |
|
return 0; |
132 |
break; |
break; |
133 |
|
|
134 |
case 'm': |
case 'm': |
135 |
motion = False; |
sendmotion = False; |
136 |
break; |
break; |
137 |
|
|
138 |
case 'b': |
case 'b': |
143 |
licence = False; |
licence = False; |
144 |
break; |
break; |
145 |
|
|
146 |
|
case 'e': |
147 |
|
use_encryption = False; |
148 |
|
break; |
149 |
|
|
150 |
|
case 'F': |
151 |
|
fullscreen = True; |
152 |
|
break; |
153 |
|
|
154 |
|
case 'h': |
155 |
case '?': |
case '?': |
156 |
default: |
default: |
157 |
usage(argv[0]); |
usage(argv[0]); |
188 |
} |
} |
189 |
} |
} |
190 |
|
|
|
if (!rdp_connect(server, flags, domain, password, shell, directory)) |
|
|
return 1; |
|
|
|
|
|
STATUS("Connection successful.\n"); |
|
|
|
|
191 |
strcpy(title, "rdesktop - "); |
strcpy(title, "rdesktop - "); |
192 |
strncat(title, server, sizeof(title)); |
strncat(title, server, sizeof(title)); |
193 |
|
|
194 |
if (ui_create_window(title)) |
if (ui_create_window(title)) |
195 |
{ |
{ |
196 |
|
if (!rdp_connect(server, flags, domain, password, shell, |
197 |
|
directory)) |
198 |
|
return 1; |
199 |
|
|
200 |
|
STATUS("Connection successful.\n"); |
201 |
rdp_main_loop(); |
rdp_main_loop(); |
202 |
ui_destroy_window(); |
ui_destroy_window(); |
203 |
} |
} |
207 |
} |
} |
208 |
|
|
209 |
/* Generate a 32-byte random for the secure transport code. */ |
/* Generate a 32-byte random for the secure transport code. */ |
210 |
void generate_random(uint8 *random) |
void |
211 |
|
generate_random(uint8 *random) |
212 |
{ |
{ |
213 |
struct stat st; |
struct stat st; |
214 |
uint32 *r = (uint32 *)random; |
struct tms tmsbuf; |
215 |
|
uint32 *r = (uint32 *) random; |
216 |
int fd; |
int fd; |
217 |
|
|
218 |
/* If we have a kernel random device, use it. */ |
/* If we have a kernel random device, use it. */ |
226 |
/* Otherwise use whatever entropy we can gather - ideas welcome. */ |
/* Otherwise use whatever entropy we can gather - ideas welcome. */ |
227 |
r[0] = (getpid()) | (getppid() << 16); |
r[0] = (getpid()) | (getppid() << 16); |
228 |
r[1] = (getuid()) | (getgid() << 16); |
r[1] = (getuid()) | (getgid() << 16); |
229 |
r[2] = times(NULL); /* system uptime (clocks) */ |
r[2] = times(&tmsbuf); /* system uptime (clocks) */ |
230 |
gettimeofday((struct timeval *)&r[3], NULL); /* sec and usec */ |
gettimeofday((struct timeval *) &r[3], NULL); /* sec and usec */ |
231 |
stat("/tmp", &st); |
stat("/tmp", &st); |
232 |
r[5] = st.st_atime; |
r[5] = st.st_atime; |
233 |
r[6] = st.st_mtime; |
r[6] = st.st_mtime; |
235 |
} |
} |
236 |
|
|
237 |
/* malloc; exit if out of memory */ |
/* malloc; exit if out of memory */ |
238 |
void *xmalloc(int size) |
void * |
239 |
|
xmalloc(int size) |
240 |
{ |
{ |
241 |
void *mem = malloc(size); |
void *mem = malloc(size); |
242 |
if (mem == NULL) |
if (mem == NULL) |
248 |
} |
} |
249 |
|
|
250 |
/* realloc; exit if out of memory */ |
/* realloc; exit if out of memory */ |
251 |
void *xrealloc(void *oldmem, int size) |
void * |
252 |
|
xrealloc(void *oldmem, int size) |
253 |
{ |
{ |
254 |
void *mem = realloc(oldmem, size); |
void *mem = realloc(oldmem, size); |
255 |
if (mem == NULL) |
if (mem == NULL) |
261 |
} |
} |
262 |
|
|
263 |
/* free */ |
/* free */ |
264 |
void xfree(void *mem) |
void |
265 |
|
xfree(void *mem) |
266 |
{ |
{ |
267 |
free(mem); |
free(mem); |
268 |
} |
} |
269 |
|
|
270 |
/* Produce a hex dump */ |
/* Produce a hex dump */ |
271 |
void hexdump(unsigned char *p, unsigned int len) |
void |
272 |
|
hexdump(unsigned char *p, unsigned int len) |
273 |
{ |
{ |
274 |
unsigned char *line = p; |
unsigned char *line = p; |
275 |
unsigned int thisline, offset = 0; |
unsigned int thisline, offset = 0; |
283 |
thisline = 16; |
thisline = 16; |
284 |
|
|
285 |
for (i = 0; i < thisline; i++) |
for (i = 0; i < thisline; i++) |
286 |
STATUS("%02x ", line[i]) |
STATUS("%02x ", line[i]) for (; i < 16; i++) |
287 |
|
STATUS(" "); |
|
for (; i < 16; i++) |
|
|
STATUS(" "); |
|
288 |
|
|
289 |
for (i = 0; i < thisline; i++) |
for (i = 0; i < thisline; i++) |
290 |
STATUS("%c", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.'); |
STATUS("%c", |
291 |
|
(line[i] >= 0x20 |
292 |
|
&& line[i] < 0x7f) ? line[i] : '.'); |
293 |
|
|
294 |
STATUS("\n"); |
STATUS("\n"); |
295 |
offset += thisline; |
offset += thisline; |