/[rdesktop]/sourceforge.net/branches/seamlessrdp-branch/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/branches/seamlessrdp-branch/rdesktop/rdesktop.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 24 - (show annotations)
Sat Jan 6 03:12:10 2001 UTC (23 years, 4 months ago) by matty
Original Path: sourceforge.net/trunk/rdesktop/rdesktop.c
File MIME type: text/plain
File size: 5757 byte(s)
ran indent (-bli0 -i8 -cli8 -npcs -npsl)

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

  ViewVC Help
Powered by ViewVC 1.1.26