/[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 21 - (show annotations)
Mon Oct 16 08:44:48 2000 UTC (23 years, 7 months ago) by matty
Original Path: sourceforge.net/trunk/rdesktop/rdesktop.c
File MIME type: text/plain
File size: 5703 byte(s)
Added a number of command line options including autologon.
Inverted sense of -m (the default is now to send mouse move events).
Preparing for release of 1.0.0.

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

  ViewVC Help
Powered by ViewVC 1.1.26