/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 25 - (show annotations)
Sat Jan 6 03:47:04 2001 UTC (23 years, 4 months ago) by matty
File MIME type: text/plain
File size: 5759 byte(s)
Changed indentation style (-psl).

1 /*
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 #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 #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 BOOL motion = True;
36 BOOL orders = True;
37 BOOL licence = True;
38
39 /* Display usage information */
40 static void
41 usage(char *program)
42 {
43 STATUS("Usage: %s [options] server\n", program);
44 STATUS(" -u: user name\n");
45 STATUS(" -d: domain\n");
46 STATUS(" -s: shell\n");
47 STATUS(" -c: working directory\n");
48 STATUS(" -p: password (autologon)\n");
49 STATUS(" -n: client hostname\n");
50 STATUS(" -w: desktop width\n");
51 STATUS(" -h: desktop height\n");
52 STATUS(" -k: keyboard layout (hex)\n");
53 STATUS(" -b: force bitmap updates\n");
54 STATUS(" -m: do not send motion events\n");
55 STATUS(" -l: do not request licence\n\n");
56 }
57
58 /* Client program */
59 int
60 main(int argc, char *argv[])
61 {
62 struct passwd *pw;
63 char *server;
64 uint32 flags;
65 char domain[16];
66 char password[16];
67 char shell[32];
68 char directory[32];
69 char title[32];
70 int c;
71
72 STATUS("rdesktop: A Remote Desktop Protocol client.\n");
73 STATUS("Version " VERSION
74 ". Copyright (C) 1999-2000 Matt Chapman.\n");
75 STATUS("See http://www.rdesktop.org/ for more information.\n\n");
76
77 flags = RDP_LOGON_NORMAL;
78 domain[0] = password[0] = shell[0] = directory[0] = 0;
79
80 while ((c = getopt(argc, argv, "u:d:s:c:p:n:w:h:k:bml?")) != -1)
81 {
82 switch (c)
83 {
84 case 'u':
85 strncpy(username, optarg, sizeof(username));
86 break;
87
88 case 'd':
89 strncpy(domain, optarg, sizeof(domain));
90 break;
91
92 case 'p':
93 flags |= RDP_LOGON_AUTO;
94 strncpy(password, optarg, sizeof(password));
95 break;
96
97 case 's':
98 strncpy(shell, optarg, sizeof(shell));
99 break;
100
101 case 'c':
102 strncpy(directory, optarg, sizeof(directory));
103 break;
104
105 case 'n':
106 strncpy(hostname, optarg, sizeof(hostname));
107 break;
108
109 case 'w':
110 width = strtol(optarg, NULL, 10);
111 break;
112
113 case 'h':
114 height = strtol(optarg, NULL, 10);
115 break;
116
117 case 'k':
118 keylayout = strtol(optarg, NULL, 16);
119 break;
120
121 case 'm':
122 motion = False;
123 break;
124
125 case 'b':
126 orders = False;
127 break;
128
129 case 'l':
130 licence = False;
131 break;
132
133 case '?':
134 default:
135 usage(argv[0]);
136 return 1;
137 }
138 }
139
140 if (argc - optind < 1)
141 {
142 usage(argv[0]);
143 return 1;
144 }
145
146 server = argv[optind];
147
148 if (username[0] == 0)
149 {
150 pw = getpwuid(getuid());
151 if ((pw == NULL) || (pw->pw_name == NULL))
152 {
153 STATUS("Could not determine user name.\n");
154 return 1;
155 }
156
157 strncpy(username, pw->pw_name, sizeof(username));
158 }
159
160 if (hostname[0] == 0)
161 {
162 if (gethostname(hostname, sizeof(hostname)) == -1)
163 {
164 STATUS("Could not determine host name.\n");
165 return 1;
166 }
167 }
168
169 if (!rdp_connect(server, flags, domain, password, shell, directory))
170 return 1;
171
172 STATUS("Connection successful.\n");
173
174 strcpy(title, "rdesktop - ");
175 strncat(title, server, sizeof(title));
176
177 if (ui_create_window(title))
178 {
179 rdp_main_loop();
180 ui_destroy_window();
181 }
182
183 rdp_disconnect();
184 return 0;
185 }
186
187 /* Generate a 32-byte random for the secure transport code. */
188 void
189 generate_random(uint8 *random)
190 {
191 struct stat st;
192 struct tms tmsbuf;
193 uint32 *r = (uint32 *) random;
194 int fd;
195
196 /* If we have a kernel random device, use it. */
197 if ((fd = open("/dev/urandom", O_RDONLY)) != -1)
198 {
199 read(fd, random, 32);
200 close(fd);
201 return;
202 }
203
204 /* Otherwise use whatever entropy we can gather - ideas welcome. */
205 r[0] = (getpid()) | (getppid() << 16);
206 r[1] = (getuid()) | (getgid() << 16);
207 r[2] = times(&tmsbuf); /* system uptime (clocks) */
208 gettimeofday((struct timeval *) &r[3], NULL); /* sec and usec */
209 stat("/tmp", &st);
210 r[5] = st.st_atime;
211 r[6] = st.st_mtime;
212 r[7] = st.st_ctime;
213 }
214
215 /* malloc; exit if out of memory */
216 void *
217 xmalloc(int size)
218 {
219 void *mem = malloc(size);
220 if (mem == NULL)
221 {
222 ERROR("xmalloc %d\n", size);
223 exit(1);
224 }
225 return mem;
226 }
227
228 /* realloc; exit if out of memory */
229 void *
230 xrealloc(void *oldmem, int size)
231 {
232 void *mem = realloc(oldmem, size);
233 if (mem == NULL)
234 {
235 ERROR("xrealloc %d\n", size);
236 exit(1);
237 }
238 return mem;
239 }
240
241 /* free */
242 void
243 xfree(void *mem)
244 {
245 free(mem);
246 }
247
248 /* Produce a hex dump */
249 void
250 hexdump(unsigned char *p, unsigned int len)
251 {
252 unsigned char *line = p;
253 unsigned int thisline, offset = 0;
254 int i;
255
256 while (offset < len)
257 {
258 STATUS("%04x ", offset);
259 thisline = len - offset;
260 if (thisline > 16)
261 thisline = 16;
262
263 for (i = 0; i < thisline; i++)
264 STATUS("%02x ", line[i]) for (; i < 16; i++)
265 STATUS(" ");
266
267 for (i = 0; i < thisline; i++)
268 STATUS("%c",
269 (line[i] >= 0x20
270 && line[i] < 0x7f) ? line[i] : '.');
271
272 STATUS("\n");
273 offset += thisline;
274 line += thisline;
275 }
276 }

  ViewVC Help
Powered by ViewVC 1.1.26