/[rdesktop]/sourceforge.net/trunk/rdesktop/rdesktop.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /sourceforge.net/trunk/rdesktop/rdesktop.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 28 - (hide annotations)
Wed Jun 20 13:54:48 2001 UTC (22 years, 10 months ago) by matty
File MIME type: text/plain
File size: 6429 byte(s)
Merges from pl19-6-5.

1 matty 10 /*
2     rdesktop: A Remote Desktop Protocol client.
3     Entrypoint and utility functions
4     Copyright (C) Matthew Chapman 1999-2000
5    
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10    
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     GNU General Public License for more details.
15    
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19     */
20    
21 matty 24 #include <stdlib.h> /* malloc realloc free */
22     #include <unistd.h> /* read close getuid getgid getpid getppid gethostname */
23     #include <fcntl.h> /* open */
24     #include <pwd.h> /* getpwuid */
25     #include <sys/stat.h> /* stat */
26     #include <sys/time.h> /* gettimeofday */
27     #include <sys/times.h> /* times */
28 matty 10 #include "rdesktop.h"
29    
30     char username[16];
31     char hostname[16];
32     int width = 800;
33     int height = 600;
34     int keylayout = 0x409;
35 matty 28 BOOL bitmap_compression = True;
36 matty 21 BOOL motion = True;
37 matty 10 BOOL orders = True;
38     BOOL licence = True;
39 matty 28 BOOL use_encryption = True;
40     BOOL desktop_save = True;
41     BOOL grab_keyboard = True;
42     BOOL fullscreen = False;
43     int private_colormap = False;
44 matty 10
45     /* Display usage information */
46 matty 25 static void
47     usage(char *program)
48 matty 10 {
49     STATUS("Usage: %s [options] server\n", program);
50     STATUS(" -u: user name\n");
51 matty 21 STATUS(" -d: domain\n");
52     STATUS(" -s: shell\n");
53     STATUS(" -c: working directory\n");
54     STATUS(" -p: password (autologon)\n");
55 matty 10 STATUS(" -n: client hostname\n");
56     STATUS(" -w: desktop width\n");
57     STATUS(" -h: desktop height\n");
58     STATUS(" -k: keyboard layout (hex)\n");
59     STATUS(" -b: force bitmap updates\n");
60 matty 21 STATUS(" -m: do not send motion events\n");
61 matty 10 STATUS(" -l: do not request licence\n\n");
62     }
63    
64     /* Client program */
65 matty 25 int
66     main(int argc, char *argv[])
67 matty 10 {
68     struct passwd *pw;
69     char *server;
70 matty 21 uint32 flags;
71     char domain[16];
72     char password[16];
73     char shell[32];
74     char directory[32];
75 matty 10 char title[32];
76     int c;
77    
78     STATUS("rdesktop: A Remote Desktop Protocol client.\n");
79 matty 24 STATUS("Version " VERSION
80     ". Copyright (C) 1999-2000 Matt Chapman.\n");
81 matty 17 STATUS("See http://www.rdesktop.org/ for more information.\n\n");
82 matty 10
83 matty 21 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 matty 10 {
88     switch (c)
89     {
90     case 'u':
91     strncpy(username, optarg, sizeof(username));
92     break;
93    
94 matty 21 case 'd':
95     strncpy(domain, optarg, sizeof(domain));
96     break;
97    
98     case 'p':
99     flags |= RDP_LOGON_AUTO;
100     strncpy(password, optarg, sizeof(password));
101     break;
102    
103     case 's':
104     strncpy(shell, optarg, sizeof(shell));
105     break;
106    
107     case 'c':
108     strncpy(directory, optarg, sizeof(directory));
109     break;
110    
111 matty 10 case 'n':
112     strncpy(hostname, optarg, sizeof(hostname));
113     break;
114 matty 28 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 matty 10 break;
128    
129     case 'k':
130     keylayout = strtol(optarg, NULL, 16);
131 matty 28 /* keylayout = find_keyb_code(optarg); */
132     if (keylayout == 0)
133     return 0;
134 matty 10 break;
135    
136     case 'm':
137 matty 21 motion = False;
138 matty 10 break;
139    
140     case 'b':
141     orders = False;
142     break;
143    
144     case 'l':
145     licence = False;
146     break;
147    
148 matty 28 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 matty 10 case '?':
162     default:
163     usage(argv[0]);
164     return 1;
165     }
166     }
167    
168     if (argc - optind < 1)
169     {
170     usage(argv[0]);
171     return 1;
172     }
173    
174     server = argv[optind];
175    
176     if (username[0] == 0)
177     {
178     pw = getpwuid(getuid());
179     if ((pw == NULL) || (pw->pw_name == NULL))
180     {
181     STATUS("Could not determine user name.\n");
182     return 1;
183     }
184    
185     strncpy(username, pw->pw_name, sizeof(username));
186     }
187    
188     if (hostname[0] == 0)
189     {
190     if (gethostname(hostname, sizeof(hostname)) == -1)
191     {
192     STATUS("Could not determine host name.\n");
193     return 1;
194     }
195     }
196    
197 matty 12 strcpy(title, "rdesktop - ");
198     strncat(title, server, sizeof(title));
199    
200 matty 10 if (ui_create_window(title))
201     {
202 matty 28 if (!rdp_connect(server, flags, domain, password, shell,
203     directory))
204     return 1;
205    
206     STATUS("Connection successful.\n");
207 matty 10 rdp_main_loop();
208     ui_destroy_window();
209     }
210    
211     rdp_disconnect();
212     return 0;
213     }
214    
215     /* Generate a 32-byte random for the secure transport code. */
216 matty 25 void
217     generate_random(uint8 *random)
218 matty 10 {
219     struct stat st;
220 matty 22 struct tms tmsbuf;
221 matty 24 uint32 *r = (uint32 *) random;
222 matty 10 int fd;
223    
224     /* If we have a kernel random device, use it. */
225     if ((fd = open("/dev/urandom", O_RDONLY)) != -1)
226     {
227     read(fd, random, 32);
228     close(fd);
229     return;
230     }
231    
232     /* Otherwise use whatever entropy we can gather - ideas welcome. */
233     r[0] = (getpid()) | (getppid() << 16);
234     r[1] = (getuid()) | (getgid() << 16);
235 matty 24 r[2] = times(&tmsbuf); /* system uptime (clocks) */
236     gettimeofday((struct timeval *) &r[3], NULL); /* sec and usec */
237 matty 10 stat("/tmp", &st);
238     r[5] = st.st_atime;
239     r[6] = st.st_mtime;
240     r[7] = st.st_ctime;
241     }
242    
243     /* malloc; exit if out of memory */
244 matty 25 void *
245     xmalloc(int size)
246 matty 10 {
247     void *mem = malloc(size);
248     if (mem == NULL)
249     {
250     ERROR("xmalloc %d\n", size);
251     exit(1);
252     }
253     return mem;
254     }
255    
256     /* realloc; exit if out of memory */
257 matty 25 void *
258     xrealloc(void *oldmem, int size)
259 matty 10 {
260     void *mem = realloc(oldmem, size);
261     if (mem == NULL)
262     {
263     ERROR("xrealloc %d\n", size);
264     exit(1);
265     }
266     return mem;
267     }
268    
269     /* free */
270 matty 25 void
271     xfree(void *mem)
272 matty 10 {
273     free(mem);
274     }
275    
276     /* Produce a hex dump */
277 matty 25 void
278     hexdump(unsigned char *p, unsigned int len)
279 matty 10 {
280     unsigned char *line = p;
281     unsigned int thisline, offset = 0;
282     int i;
283    
284     while (offset < len)
285     {
286     STATUS("%04x ", offset);
287     thisline = len - offset;
288     if (thisline > 16)
289     thisline = 16;
290    
291     for (i = 0; i < thisline; i++)
292 matty 24 STATUS("%02x ", line[i]) for (; i < 16; i++)
293     STATUS(" ");
294 matty 10
295     for (i = 0; i < thisline; i++)
296 matty 24 STATUS("%c",
297     (line[i] >= 0x20
298     && line[i] < 0x7f) ? line[i] : '.');
299 matty 10
300     STATUS("\n");
301     offset += thisline;
302     line += thisline;
303     }
304     }

  ViewVC Help
Powered by ViewVC 1.1.26