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

Annotation of /sourceforge.net/branches/seamlessrdp-branch/rdesktop/rdesktop.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1042 - (hide annotations)
Tue Jan 24 12:40:24 2006 UTC (18 years, 3 months ago) by astrand
Original Path: sourceforge.net/trunk/rdesktop/rdesktop.c
File MIME type: text/plain
File size: 29275 byte(s)
Applied patch #1390148 from Ilya Konstantinov: Refactoring of color depth code.

1 forsberg 350 /* -*- c-basic-offset: 8 -*-
2 matty 10 rdesktop: A Remote Desktop Protocol client.
3     Entrypoint and utility functions
4 stargo 828 Copyright (C) Matthew Chapman 1999-2005
5 jsorg71 100
6 matty 10 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 jsorg71 100
11 matty 10 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 jsorg71 100
16 matty 10 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 30 #include <stdarg.h> /* va_list va_start va_end */
22 matty 24 #include <unistd.h> /* read close getuid getgid getpid getppid gethostname */
23     #include <fcntl.h> /* open */
24     #include <pwd.h> /* getpwuid */
25 matthewc 211 #include <termios.h> /* tcgetattr tcsetattr */
26 matty 24 #include <sys/stat.h> /* stat */
27     #include <sys/time.h> /* gettimeofday */
28     #include <sys/times.h> /* times */
29 stargo 570 #include <ctype.h> /* toupper */
30 astrand 325 #include <errno.h>
31 matty 10 #include "rdesktop.h"
32    
33 stargo 857 #ifdef HAVE_LOCALE_H
34 stargo 855 #include <locale.h>
35 stargo 857 #endif
36 astrand 962 #ifdef HAVE_ICONV
37 stargo 857 #ifdef HAVE_LANGINFO_H
38 stargo 855 #include <langinfo.h>
39     #endif
40 stargo 857 #endif
41 stargo 855
42 matthewc 220 #ifdef EGD_SOCKET
43 stargo 881 #include <sys/types.h>
44 matthewc 220 #include <sys/socket.h> /* socket connect */
45     #include <sys/un.h> /* sockaddr_un */
46     #endif
47    
48     #include <openssl/md5.h>
49    
50 astrand 479 char g_title[64] = "";
51     char g_username[64];
52 jsorg71 710 char g_hostname[16];
53 astrand 975 char g_keymapname[PATH_MAX] = "";
54 astrand 1035 unsigned int g_keylayout = 0x409; /* Defaults to US keyboard layout */
55 astrand 964 int g_keyboard_type = 0x4; /* Defaults to US keyboard layout */
56     int g_keyboard_subtype = 0x0; /* Defaults to US keyboard layout */
57     int g_keyboard_functionkeys = 0xc; /* Defaults to US keyboard layout */
58 astrand 500
59     int g_width = 800; /* width is special: If 0, the
60     geometry will be fetched from
61     _NET_WORKAREA. If negative,
62     absolute value specifies the
63     percent of the whole screen. */
64 jsorg71 447 int g_height = 600;
65 stargo 800 int g_xpos = 0;
66     int g_ypos = 0;
67 stargo 867 int g_pos = 0; /* 0 position unspecified,
68     1 specified,
69     2 xpos neg,
70     4 ypos neg */
71 jsorg71 710 extern int g_tcp_port_rdp;
72 astrand 1042 int g_server_depth = 8;
73 jsorg71 450 int g_win_button_size = 0; /* If zero, disable single app mode */
74 jsorg71 437 BOOL g_bitmap_compression = True;
75 jsorg71 447 BOOL g_sendmotion = True;
76 jsorg71 678 BOOL g_bitmap_cache = True;
77 jsorg71 725 BOOL g_bitmap_cache_persist_enable = False;
78     BOOL g_bitmap_cache_precache = True;
79 jsorg71 437 BOOL g_encryption = True;
80 forsberg 427 BOOL packet_encryption = True;
81 jsorg71 848 BOOL g_desktop_save = True; /* desktop save order */
82     BOOL g_polygon_ellipse_orders = True; /* polygon / ellipse orders */
83 jsorg71 447 BOOL g_fullscreen = False;
84 jsorg71 450 BOOL g_grab_keyboard = True;
85     BOOL g_hide_decorations = False;
86 astrand 458 BOOL g_use_rdp5 = True;
87 matthewc 482 BOOL g_console_session = False;
88 astrand 552 BOOL g_numlock_sync = False;
89 stargo 648 BOOL g_owncolmap = False;
90 astrand 651 BOOL g_ownbackstore = True; /* We can't rely on external BackingStore */
91 stargo 648 uint32 g_embed_wnd;
92 astrand 651 uint32 g_rdp5_performanceflags =
93     RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS;
94 astrand 977 /* Session Directory redirection */
95     BOOL g_redirect = False;
96     char g_redirect_server[64];
97     char g_redirect_domain[16];
98     char g_redirect_password[64];
99     char g_redirect_username[64];
100     char g_redirect_cookie[128];
101     uint32 g_redirect_flags = 0;
102 matty 10
103 stargo 501 #ifdef WITH_RDPSND
104 matthewc 520 BOOL g_rdpsnd = False;
105 stargo 501 #endif
106    
107 stargo 855 #ifdef HAVE_ICONV
108     char g_codepage[16] = "";
109     #endif
110    
111 n-ki 569 extern RDPDR_DEVICE g_rdpdr_device[];
112     extern uint32 g_num_devices;
113 astrand 651 extern char *g_rdpdr_clientname;
114 n-ki 569
115 astrand 333 #ifdef RDP2VNC
116     extern int rfb_port;
117     extern int defer_time;
118     void
119     rdp2vnc_connect(char *server, uint32 flags, char *domain, char *password,
120     char *shell, char *directory);
121     #endif
122 matty 10 /* Display usage information */
123 matty 25 static void
124     usage(char *program)
125 matty 10 {
126 matthewc 122 fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n");
127 stargo 828 fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2005 Matt Chapman.\n");
128 matthewc 122 fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n");
129    
130 matthewc 222 fprintf(stderr, "Usage: %s [options] server[:port]\n", program);
131 astrand 333 #ifdef RDP2VNC
132     fprintf(stderr, " -V: vnc port\n");
133 forsberg 471 fprintf(stderr, " -Q: defer time (ms)\n");
134 astrand 333 #endif
135 astrand 111 fprintf(stderr, " -u: user name\n");
136     fprintf(stderr, " -d: domain\n");
137     fprintf(stderr, " -s: shell\n");
138     fprintf(stderr, " -c: working directory\n");
139 matthewc 211 fprintf(stderr, " -p: password (- to prompt)\n");
140 astrand 111 fprintf(stderr, " -n: client hostname\n");
141 matthewc 520 fprintf(stderr, " -k: keyboard layout on server (en-us, de, sv, etc.)\n");
142 astrand 111 fprintf(stderr, " -g: desktop geometry (WxH)\n");
143     fprintf(stderr, " -f: full-screen mode\n");
144     fprintf(stderr, " -b: force bitmap updates\n");
145 stargo 855 #ifdef HAVE_ICONV
146     fprintf(stderr, " -L: local codepage\n");
147     #endif
148 stargo 609 fprintf(stderr, " -B: use BackingStore of X-server (if available)\n");
149 astrand 111 fprintf(stderr, " -e: disable encryption (French TS)\n");
150 forsberg 471 fprintf(stderr, " -E: disable encryption from client to server\n");
151 astrand 111 fprintf(stderr, " -m: do not send motion events\n");
152 n-ki 279 fprintf(stderr, " -C: use private colour map\n");
153 matthewc 520 fprintf(stderr, " -D: hide window manager decorations\n");
154 astrand 111 fprintf(stderr, " -K: keep window manager key bindings\n");
155 matthewc 520 fprintf(stderr, " -S: caption button size (single application mode)\n");
156 matthewc 223 fprintf(stderr, " -T: window title\n");
157 n-ki 569 fprintf(stderr, " -N: enable numlock syncronization\n");
158 stargo 636 fprintf(stderr, " -X: embed into another window with a given id.\n");
159 matthewc 520 fprintf(stderr, " -a: connection colour depth\n");
160 jsorg71 773 fprintf(stderr, " -z: enable rdp compression\n");
161 jsorg71 725 fprintf(stderr, " -x: RDP5 experience (m[odem 28.8], b[roadband], l[an] or hex nr.)\n");
162     fprintf(stderr, " -P: use persistent bitmap caching\n");
163 n-ki 569 fprintf(stderr, " -r: enable specified device redirection (this flag can be repeated)\n");
164 astrand 608 fprintf(stderr,
165     " '-r comport:COM1=/dev/ttyS0': enable serial redirection of /dev/ttyS0 to COM1\n");
166 n-ki 578 fprintf(stderr, " or COM1=/dev/ttyS0,COM2=/dev/ttyS1\n");
167 astrand 608 fprintf(stderr,
168 astrand 747 " '-r disk:floppy=/mnt/floppy': enable redirection of /mnt/floppy to 'floppy' share\n");
169     fprintf(stderr, " or 'floppy=/mnt/floppy,cdrom=/mnt/cdrom'\n");
170 forsberg 646 fprintf(stderr, " '-r clientname=<client name>': Set the client name displayed\n");
171     fprintf(stderr, " for redirected disks\n");
172 astrand 608 fprintf(stderr,
173     " '-r lptport:LPT1=/dev/lp0': enable parallel redirection of /dev/lp0 to LPT1\n");
174 n-ki 578 fprintf(stderr, " or LPT1=/dev/lp0,LPT2=/dev/lp1\n");
175 n-ki 569 fprintf(stderr, " '-r printer:mydeskjet': enable printer redirection\n");
176 astrand 608 fprintf(stderr,
177 n-ki 628 " or mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n");
178 n-ki 630 fprintf(stderr, " '-r sound:[local|off|remote]': enable sound redirection\n");
179 n-ki 628 fprintf(stderr, " remote would leave sound on server\n");
180 matthewc 482 fprintf(stderr, " -0: attach to console\n");
181     fprintf(stderr, " -4: use RDP version 4\n");
182     fprintf(stderr, " -5: use RDP version 5 (default)\n");
183 matty 10 }
184    
185 astrand 944 static void
186 astrand 676 print_disconnect_reason(uint16 reason)
187     {
188     char *text;
189    
190     switch (reason)
191     {
192     case exDiscReasonNoInfo:
193     text = "No information available";
194     break;
195    
196     case exDiscReasonAPIInitiatedDisconnect:
197     text = "Server initiated disconnect";
198     break;
199    
200     case exDiscReasonAPIInitiatedLogoff:
201     text = "Server initiated logoff";
202     break;
203    
204     case exDiscReasonServerIdleTimeout:
205     text = "Server idle timeout reached";
206     break;
207    
208     case exDiscReasonServerLogonTimeout:
209     text = "Server logon timeout reached";
210     break;
211    
212     case exDiscReasonReplacedByOtherConnection:
213     text = "The session was replaced";
214     break;
215    
216     case exDiscReasonOutOfMemory:
217     text = "The server is out of memory";
218     break;
219    
220     case exDiscReasonServerDeniedConnection:
221     text = "The server denied the connection";
222     break;
223    
224     case exDiscReasonServerDeniedConnectionFips:
225     text = "The server denied the connection for security reason";
226     break;
227    
228     case exDiscReasonLicenseInternal:
229     text = "Internal licensing error";
230     break;
231    
232     case exDiscReasonLicenseNoLicenseServer:
233     text = "No license server available";
234     break;
235    
236     case exDiscReasonLicenseNoLicense:
237     text = "No valid license available";
238     break;
239    
240     case exDiscReasonLicenseErrClientMsg:
241     text = "Invalid licensing message";
242     break;
243    
244     case exDiscReasonLicenseHwidDoesntMatchLicense:
245     text = "Hardware id doesn't match software license";
246     break;
247    
248     case exDiscReasonLicenseErrClientLicense:
249     text = "Client license error";
250     break;
251    
252     case exDiscReasonLicenseCantFinishProtocol:
253     text = "Network error during licensing protocol";
254     break;
255    
256     case exDiscReasonLicenseClientEndedProtocol:
257     text = "Licensing protocol was not completed";
258     break;
259    
260     case exDiscReasonLicenseErrClientEncryption:
261     text = "Incorrect client license enryption";
262     break;
263    
264     case exDiscReasonLicenseCantUpgradeLicense:
265     text = "Can't upgrade license";
266     break;
267    
268     case exDiscReasonLicenseNoRemoteConnections:
269     text = "The server is not licensed to accept remote connections";
270     break;
271    
272     default:
273     if (reason > 0x1000 && reason < 0x7fff)
274     {
275     text = "Internal protocol error";
276     }
277     else
278     {
279     text = "Unknown reason";
280     }
281     }
282     fprintf(stderr, "disconnect: %s.\n", text);
283     }
284    
285 astrand 977 static void
286     rdesktop_reset_state(void)
287     {
288     rdp_reset_state();
289     }
290    
291 matthewc 211 static BOOL
292     read_password(char *password, int size)
293     {
294     struct termios tios;
295     BOOL ret = False;
296     int istty = 0;
297     char *p;
298    
299     if (tcgetattr(STDIN_FILENO, &tios) == 0)
300     {
301     fprintf(stderr, "Password: ");
302     tios.c_lflag &= ~ECHO;
303     tcsetattr(STDIN_FILENO, TCSANOW, &tios);
304     istty = 1;
305     }
306    
307     if (fgets(password, size, stdin) != NULL)
308     {
309     ret = True;
310    
311     /* strip final newline */
312     p = strchr(password, '\n');
313     if (p != NULL)
314     *p = 0;
315     }
316    
317     if (istty)
318     {
319     tios.c_lflag |= ECHO;
320     tcsetattr(STDIN_FILENO, TCSANOW, &tios);
321     fprintf(stderr, "\n");
322     }
323    
324     return ret;
325     }
326    
327 astrand 444 static void
328     parse_server_and_port(char *server)
329     {
330     char *p;
331     #ifdef IPv6
332     int addr_colons;
333     #endif
334    
335     #ifdef IPv6
336     p = server;
337     addr_colons = 0;
338     while (*p)
339     if (*p++ == ':')
340     addr_colons++;
341     if (addr_colons >= 2)
342     {
343     /* numeric IPv6 style address format - [1:2:3::4]:port */
344     p = strchr(server, ']');
345     if (*server == '[' && p != NULL)
346     {
347     if (*(p + 1) == ':' && *(p + 2) != '\0')
348 jsorg71 710 g_tcp_port_rdp = strtol(p + 2, NULL, 10);
349 astrand 444 /* remove the port number and brackets from the address */
350     *p = '\0';
351     strncpy(server, server + 1, strlen(server));
352     }
353     }
354     else
355     {
356     /* dns name or IPv4 style address format - server.example.com:port or 1.2.3.4:port */
357     p = strchr(server, ':');
358     if (p != NULL)
359     {
360 jsorg71 710 g_tcp_port_rdp = strtol(p + 1, NULL, 10);
361 astrand 444 *p = 0;
362     }
363     }
364     #else /* no IPv6 support */
365     p = strchr(server, ':');
366     if (p != NULL)
367     {
368 jsorg71 710 g_tcp_port_rdp = strtol(p + 1, NULL, 10);
369 astrand 444 *p = 0;
370     }
371     #endif /* IPv6 */
372    
373     }
374    
375 matty 10 /* Client program */
376 matty 25 int
377     main(int argc, char *argv[])
378 matty 10 {
379 matthewc 222 char server[64];
380 matty 30 char fullhostname[64];
381 matty 21 char domain[16];
382 astrand 479 char password[64];
383 astrand 238 char shell[128];
384 matty 21 char directory[32];
385 astrand 676 BOOL prompt_password, deactivated;
386 matty 30 struct passwd *pw;
387 astrand 676 uint32 flags, ext_disc_reason = 0;
388 matthewc 222 char *p;
389 matty 10 int c;
390 astrand 973 char *locale = NULL;
391 astrand 289 int username_option = 0;
392 astrand 977 int run_count = 0; /* Session Directory support */
393     BOOL continue_connect = True; /* Session Directory support */
394 matty 10
395 astrand 973 #ifdef HAVE_LOCALE_H
396 astrand 962 /* Set locale according to environment */
397     locale = setlocale(LC_ALL, "");
398     if (locale)
399     {
400 astrand 974 locale = xstrdup(locale);
401 astrand 962 }
402    
403 astrand 973 #endif
404 matty 21 flags = RDP_LOGON_NORMAL;
405 matthewc 211 prompt_password = False;
406 matty 21 domain[0] = password[0] = shell[0] = directory[0] = 0;
407 stargo 636 g_embed_wnd = 0;
408 matty 21
409 n-ki 569 g_num_devices = 0;
410    
411 astrand 333 #ifdef RDP2VNC
412 forsberg 471 #define VNCOPT "V:Q:"
413 astrand 333 #else
414     #define VNCOPT
415     #endif
416    
417 jsorg71 725 while ((c = getopt(argc, argv,
418 stargo 855 VNCOPT "u:L:d:s:c:p:n:k:g:fbBeEmzCDKS:T:NX:a:x:Pr:045h?")) != -1)
419 matty 10 {
420     switch (c)
421     {
422 astrand 333 #ifdef RDP2VNC
423     case 'V':
424     rfb_port = strtol(optarg, NULL, 10);
425     if (rfb_port < 100)
426     rfb_port += 5900;
427     break;
428    
429 forsberg 471 case 'Q':
430 astrand 333 defer_time = strtol(optarg, NULL, 10);
431     if (defer_time < 0)
432     defer_time = 0;
433     break;
434     #endif
435    
436 matty 10 case 'u':
437 jsorg71 437 STRNCPY(g_username, optarg, sizeof(g_username));
438 astrand 289 username_option = 1;
439 matty 10 break;
440    
441 stargo 855 case 'L':
442     #ifdef HAVE_ICONV
443     STRNCPY(g_codepage, optarg, sizeof(g_codepage));
444     #else
445     error("iconv support not available\n");
446     #endif
447     break;
448    
449 matty 21 case 'd':
450 matty 30 STRNCPY(domain, optarg, sizeof(domain));
451 matty 21 break;
452    
453     case 's':
454 matty 30 STRNCPY(shell, optarg, sizeof(shell));
455 matty 21 break;
456    
457     case 'c':
458 matty 30 STRNCPY(directory, optarg, sizeof(directory));
459 matty 21 break;
460    
461 matty 30 case 'p':
462 matthewc 211 if ((optarg[0] == '-') && (optarg[1] == 0))
463     {
464     prompt_password = True;
465     break;
466     }
467    
468 matty 30 STRNCPY(password, optarg, sizeof(password));
469     flags |= RDP_LOGON_AUTO;
470 matthewc 211
471     /* try to overwrite argument so it won't appear in ps */
472 n-ki 171 p = optarg;
473     while (*p)
474     *(p++) = 'X';
475 matty 30 break;
476    
477 matty 10 case 'n':
478 jsorg71 710 STRNCPY(g_hostname, optarg, sizeof(g_hostname));
479 matty 10 break;
480    
481     case 'k':
482 astrand 975 STRNCPY(g_keymapname, optarg, sizeof(g_keymapname));
483 matty 10 break;
484    
485 matty 30 case 'g':
486 astrand 547 g_fullscreen = False;
487 astrand 263 if (!strcmp(optarg, "workarea"))
488     {
489 jsorg71 447 g_width = g_height = 0;
490 astrand 263 break;
491     }
492    
493 jsorg71 447 g_width = strtol(optarg, &p, 10);
494 astrand 500 if (g_width <= 0)
495     {
496     error("invalid geometry\n");
497     return 1;
498     }
499    
500 matty 30 if (*p == 'x')
501 stargo 800 g_height = strtol(p + 1, &p, 10);
502 matty 30
503 astrand 500 if (g_height <= 0)
504 matty 30 {
505     error("invalid geometry\n");
506     return 1;
507     }
508 astrand 500
509     if (*p == '%')
510 stargo 800 {
511 astrand 500 g_width = -g_width;
512 stargo 800 p++;
513     }
514 astrand 500
515 stargo 800 if (*p == '+' || *p == '-')
516 stargo 867 {
517     g_pos |= (*p == '-') ? 2 : 1;
518 stargo 800 g_xpos = strtol(p, &p, 10);
519 astrand 801
520 stargo 867 }
521 stargo 800 if (*p == '+' || *p == '-')
522 stargo 867 {
523     g_pos |= (*p == '-') ? 4 : 1;
524 stargo 800 g_ypos = strtol(p, NULL, 10);
525 stargo 867 }
526 stargo 800
527 matty 10 break;
528    
529 matty 30 case 'f':
530 jsorg71 447 g_fullscreen = True;
531 matty 30 break;
532    
533 matty 10 case 'b':
534 jsorg71 678 g_bitmap_cache = False;
535 matty 10 break;
536    
537 stargo 609 case 'B':
538     g_ownbackstore = False;
539     break;
540    
541 matty 30 case 'e':
542 jsorg71 437 g_encryption = False;
543 matty 10 break;
544 astrand 435 case 'E':
545 forsberg 427 packet_encryption = False;
546     break;
547 matty 30 case 'm':
548 jsorg71 447 g_sendmotion = False;
549 matty 28 break;
550 matty 29
551 n-ki 279 case 'C':
552 jsorg71 450 g_owncolmap = True;
553 n-ki 279 break;
554    
555 matthewc 520 case 'D':
556     g_hide_decorations = True;
557     break;
558    
559 astrand 76 case 'K':
560 jsorg71 450 g_grab_keyboard = False;
561 astrand 76 break;
562    
563 matthewc 520 case 'S':
564     if (!strcmp(optarg, "standard"))
565     {
566     g_win_button_size = 18;
567     break;
568     }
569    
570     g_win_button_size = strtol(optarg, &p, 10);
571    
572     if (*p)
573     {
574     error("invalid button size\n");
575     return 1;
576     }
577    
578     break;
579    
580 matthewc 223 case 'T':
581 jsorg71 450 STRNCPY(g_title, optarg, sizeof(g_title));
582 astrand 107 break;
583    
584 astrand 552 case 'N':
585     g_numlock_sync = True;
586     break;
587    
588 stargo 636 case 'X':
589 stargo 871 g_embed_wnd = strtol(optarg, NULL, 0);
590 stargo 636 break;
591 astrand 651
592 jsorg71 309 case 'a':
593 astrand 1042 g_server_depth = strtol(optarg, NULL, 10);
594     if (g_server_depth != 8 &&
595     g_server_depth != 16 &&
596     g_server_depth != 15 && g_server_depth != 24)
597 jsorg71 309 {
598 astrand 1042 error("Invalid server colour depth.\n");
599 jsorg71 309 return 1;
600     }
601     break;
602    
603 jsorg71 773 case 'z':
604     DEBUG(("rdp compression enabled\n"));
605 jdmeijer 889 flags |= (RDP_LOGON_COMPRESSION | RDP_LOGON_COMPRESSION2);
606 jsorg71 773 break;
607    
608 stargo 637 case 'x':
609 astrand 1010 if (str_startswith(optarg, "m")) /* modem */
610 stargo 637 {
611 astrand 651 g_rdp5_performanceflags =
612     RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG |
613     RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING;
614 stargo 637 }
615 astrand 1010 else if (str_startswith(optarg, "b")) /* broadband */
616 stargo 637 {
617     g_rdp5_performanceflags = RDP5_NO_WALLPAPER;
618     }
619 astrand 1010 else if (str_startswith(optarg, "l")) /* lan */
620 stargo 637 {
621     g_rdp5_performanceflags = RDP5_DISABLE_NOTHING;
622     }
623     else
624     {
625     g_rdp5_performanceflags = strtol(optarg, NULL, 16);
626     }
627     break;
628 astrand 651
629 jsorg71 725 case 'P':
630     g_bitmap_cache_persist_enable = True;
631     break;
632    
633 matthewc 520 case 'r':
634 n-ki 569
635 astrand 1010 if (str_startswith(optarg, "sound"))
636 n-ki 569 {
637 n-ki 629 optarg += 5;
638    
639     if (*optarg == ':')
640 n-ki 628 {
641 n-ki 629 *optarg++;
642     while ((p = next_arg(optarg, ',')))
643     {
644 astrand 1010 if (str_startswith(optarg, "remote"))
645 n-ki 629 flags |= RDP_LOGON_LEAVE_AUDIO;
646 n-ki 628
647 astrand 1010 if (str_startswith(optarg, "local"))
648 stargo 501 #ifdef WITH_RDPSND
649 n-ki 629 g_rdpsnd = True;
650 matthewc 520 #else
651 stargo 739 warning("Not compiled with sound support\n");
652 matthewc 520 #endif
653 n-ki 629
654 astrand 1010 if (str_startswith(optarg, "off"))
655 stargo 685 #ifdef WITH_RDPSND
656 n-ki 629 g_rdpsnd = False;
657 stargo 685 #else
658 stargo 739 warning("Not compiled with sound support\n");
659 stargo 685 #endif
660 n-ki 629
661     optarg = p;
662 n-ki 628 }
663     }
664     else
665     {
666     #ifdef WITH_RDPSND
667     g_rdpsnd = True;
668     #else
669 stargo 739 warning("Not compiled with sound support\n");
670 n-ki 628 #endif
671     }
672 n-ki 569 }
673 astrand 1010 else if (str_startswith(optarg, "disk"))
674 n-ki 569 {
675     /* -r disk:h:=/mnt/floppy */
676     disk_enum_devices(&g_num_devices, optarg + 4);
677     }
678 astrand 1010 else if (str_startswith(optarg, "comport"))
679 n-ki 569 {
680     serial_enum_devices(&g_num_devices, optarg + 7);
681     }
682 astrand 1010 else if (str_startswith(optarg, "lptport"))
683 n-ki 569 {
684     parallel_enum_devices(&g_num_devices, optarg + 7);
685     }
686 astrand 1010 else if (str_startswith(optarg, "printer"))
687 n-ki 569 {
688     printer_enum_devices(&g_num_devices, optarg + 7);
689     }
690 astrand 1010 else if (str_startswith(optarg, "clientname"))
691 forsberg 646 {
692 astrand 651 g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1);
693 forsberg 646 strcpy(g_rdpdr_clientname, optarg + 11);
694     }
695 n-ki 569 else
696     {
697     warning("Unknown -r argument\n\n\tPossible arguments are: comport, disk, lptport, printer, sound\n");
698     }
699 stargo 501 break;
700 matthewc 520
701 matthewc 482 case '0':
702     g_console_session = True;
703     break;
704    
705 astrand 458 case '4':
706     g_use_rdp5 = False;
707     break;
708    
709 forsberg 350 case '5':
710 jsorg71 438 g_use_rdp5 = True;
711 forsberg 350 break;
712 astrand 458
713 matty 28 case 'h':
714 matty 10 case '?':
715     default:
716     usage(argv[0]);
717     return 1;
718     }
719     }
720    
721 stargo 610 if (argc - optind != 1)
722 matty 10 {
723     usage(argv[0]);
724     return 1;
725     }
726    
727 matthewc 222 STRNCPY(server, argv[optind], sizeof(server));
728 astrand 444 parse_server_and_port(server);
729 matty 10
730 astrand 289 if (!username_option)
731 matty 10 {
732     pw = getpwuid(getuid());
733     if ((pw == NULL) || (pw->pw_name == NULL))
734     {
735 matty 30 error("could not determine username, use -u\n");
736 matty 10 return 1;
737     }
738    
739 jsorg71 437 STRNCPY(g_username, pw->pw_name, sizeof(g_username));
740 matty 10 }
741    
742 stargo 855 #ifdef HAVE_ICONV
743     if (g_codepage[0] == 0)
744     {
745     if (setlocale(LC_CTYPE, ""))
746     {
747     STRNCPY(g_codepage, nl_langinfo(CODESET), sizeof(g_codepage));
748     }
749     else
750     {
751     STRNCPY(g_codepage, DEFAULT_CODEPAGE, sizeof(g_codepage));
752     }
753     }
754     #endif
755 stargo 861
756 jsorg71 710 if (g_hostname[0] == 0)
757 matty 10 {
758 matty 30 if (gethostname(fullhostname, sizeof(fullhostname)) == -1)
759 matty 10 {
760 matty 30 error("could not determine local hostname, use -n\n");
761 matty 10 return 1;
762     }
763 matty 30
764     p = strchr(fullhostname, '.');
765     if (p != NULL)
766     *p = 0;
767    
768 jsorg71 710 STRNCPY(g_hostname, fullhostname, sizeof(g_hostname));
769 matty 10 }
770    
771 astrand 975 if (g_keymapname[0] == 0)
772 astrand 973 {
773     if (locale && xkeymap_from_locale(locale))
774     {
775 astrand 975 fprintf(stderr, "Autoselected keyboard map %s\n", g_keymapname);
776 astrand 973 }
777     else
778     {
779 astrand 975 STRNCPY(g_keymapname, "en-us", sizeof(g_keymapname));
780 astrand 973 }
781     }
782     if (locale)
783     xfree(locale);
784    
785    
786 matthewc 211 if (prompt_password && read_password(password, sizeof(password)))
787     flags |= RDP_LOGON_AUTO;
788 matty 30
789 jsorg71 450 if (g_title[0] == 0)
790 astrand 107 {
791 jsorg71 450 strcpy(g_title, "rdesktop - ");
792     strncat(g_title, server, sizeof(g_title) - sizeof("rdesktop - "));
793 astrand 107 }
794 matty 12
795 astrand 333 #ifdef RDP2VNC
796     rdp2vnc_connect(server, flags, domain, password, shell, directory);
797 forsberg 424 return 0;
798 astrand 333 #else
799    
800 astrand 82 if (!ui_init())
801     return 1;
802 astrand 66
803 matthewc 474 #ifdef WITH_RDPSND
804 stargo 501 if (g_rdpsnd)
805     rdpsnd_init();
806 matthewc 474 #endif
807 n-ki 569 rdpdr_init();
808 forsberg 416
809 astrand 977 while (run_count < 2 && continue_connect) /* add support for Session Directory; only reconnect once */
810     {
811     if (run_count == 0)
812     {
813     if (!rdp_connect(server, flags, domain, password, shell, directory))
814     return 1;
815     }
816     else if (!rdp_reconnect
817     (server, flags, domain, password, shell, directory, g_redirect_cookie))
818     return 1;
819 matthewc 53
820 astrand 977 /* By setting encryption to False here, we have an encrypted login
821     packet but unencrypted transfer of other packets */
822     if (!packet_encryption)
823     g_encryption = False;
824 forsberg 427
825    
826 astrand 977 DEBUG(("Connection successful.\n"));
827     memset(password, 0, sizeof(password));
828 matthewc 53
829 astrand 977 if (run_count == 0)
830     if (!ui_create_window())
831     continue_connect = False;
832    
833     if (continue_connect)
834     rdp_main_loop(&deactivated, &ext_disc_reason);
835    
836     DEBUG(("Disconnecting...\n"));
837     rdp_disconnect();
838    
839     if ((g_redirect == True) && (run_count == 0)) /* Support for Session Directory */
840     {
841     /* reset state of major globals */
842     rdesktop_reset_state();
843    
844     STRNCPY(domain, g_redirect_domain, sizeof(domain));
845     STRNCPY(g_username, g_redirect_username, sizeof(g_username));
846     STRNCPY(password, g_redirect_password, sizeof(password));
847     STRNCPY(server, g_redirect_server, sizeof(server));
848     flags |= RDP_LOGON_AUTO;
849    
850     g_redirect = False;
851     }
852     else
853     {
854     continue_connect = False;
855     ui_destroy_window();
856     break;
857     }
858    
859     run_count++;
860 matty 10 }
861    
862 jsorg71 725 cache_save_state();
863 matthewc 188 ui_deinit();
864 astrand 333
865 astrand 676 if (ext_disc_reason >= 2)
866     print_disconnect_reason(ext_disc_reason);
867    
868     if (deactivated)
869     {
870     /* clean disconnect */
871 forsberg 424 return 0;
872 astrand 676 }
873 forsberg 424 else
874 astrand 676 {
875     if (ext_disc_reason == exDiscReasonAPIInitiatedDisconnect
876     || ext_disc_reason == exDiscReasonAPIInitiatedLogoff)
877     {
878     /* not so clean disconnect, but nothing to worry about */
879     return 0;
880     }
881     else
882     {
883     /* return error */
884     return 2;
885     }
886     }
887 forsberg 424
888 astrand 333 #endif
889    
890 matty 10 }
891    
892 matthewc 220 #ifdef EGD_SOCKET
893     /* Read 32 random bytes from PRNGD or EGD socket (based on OpenSSL RAND_egd) */
894     static BOOL
895     generate_random_egd(uint8 * buf)
896     {
897     struct sockaddr_un addr;
898     BOOL ret = False;
899     int fd;
900    
901     fd = socket(AF_UNIX, SOCK_STREAM, 0);
902     if (fd == -1)
903     return False;
904    
905     addr.sun_family = AF_UNIX;
906     memcpy(addr.sun_path, EGD_SOCKET, sizeof(EGD_SOCKET));
907 astrand 259 if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) == -1)
908 matthewc 220 goto err;
909    
910     /* PRNGD and EGD use a simple communications protocol */
911 astrand 259 buf[0] = 1; /* Non-blocking (similar to /dev/urandom) */
912     buf[1] = 32; /* Number of requested random bytes */
913 matthewc 220 if (write(fd, buf, 2) != 2)
914     goto err;
915    
916 astrand 259 if ((read(fd, buf, 1) != 1) || (buf[0] == 0)) /* Available? */
917 matthewc 220 goto err;
918    
919     if (read(fd, buf, 32) != 32)
920     goto err;
921    
922     ret = True;
923    
924 astrand 259 err:
925 matthewc 220 close(fd);
926     return ret;
927     }
928     #endif
929    
930 matty 10 /* Generate a 32-byte random for the secure transport code. */
931 matty 25 void
932 astrand 64 generate_random(uint8 * random)
933 matty 10 {
934     struct stat st;
935 matty 22 struct tms tmsbuf;
936 matthewc 220 MD5_CTX md5;
937     uint32 *r;
938     int fd, n;
939 matty 10
940 matthewc 220 /* If we have a kernel random device, try that first */
941 matty 30 if (((fd = open("/dev/urandom", O_RDONLY)) != -1)
942     || ((fd = open("/dev/random", O_RDONLY)) != -1))
943 matty 10 {
944 matthewc 220 n = read(fd, random, 32);
945 matty 10 close(fd);
946 matthewc 220 if (n == 32)
947     return;
948 matty 10 }
949    
950 matthewc 220 #ifdef EGD_SOCKET
951     /* As a second preference use an EGD */
952     if (generate_random_egd(random))
953     return;
954     #endif
955    
956 matty 10 /* Otherwise use whatever entropy we can gather - ideas welcome. */
957 astrand 259 r = (uint32 *) random;
958 matty 10 r[0] = (getpid()) | (getppid() << 16);
959     r[1] = (getuid()) | (getgid() << 16);
960 matty 24 r[2] = times(&tmsbuf); /* system uptime (clocks) */
961     gettimeofday((struct timeval *) &r[3], NULL); /* sec and usec */
962 matty 10 stat("/tmp", &st);
963     r[5] = st.st_atime;
964     r[6] = st.st_mtime;
965     r[7] = st.st_ctime;
966 matthewc 220
967     /* Hash both halves with MD5 to obscure possible patterns */
968     MD5_Init(&md5);
969 astrand 259 MD5_Update(&md5, random, 16);
970 matthewc 220 MD5_Final(random, &md5);
971 astrand 259 MD5_Update(&md5, random + 16, 16);
972     MD5_Final(random + 16, &md5);
973 matty 10 }
974    
975     /* malloc; exit if out of memory */
976 matty 25 void *
977     xmalloc(int size)
978 matty 10 {
979     void *mem = malloc(size);
980     if (mem == NULL)
981     {
982 matty 30 error("xmalloc %d\n", size);
983 matty 10 exit(1);
984     }
985     return mem;
986     }
987    
988 astrand 974 /* strdup */
989     char *
990     xstrdup(const char *s)
991     {
992     char *mem = strdup(s);
993     if (mem == NULL)
994     {
995     perror("strdup");
996     exit(1);
997     }
998     return mem;
999     }
1000    
1001 matty 10 /* realloc; exit if out of memory */
1002 matty 25 void *
1003     xrealloc(void *oldmem, int size)
1004 matty 10 {
1005 astrand 782 void *mem;
1006 jsorg71 773
1007     if (size < 1)
1008     size = 1;
1009     mem = realloc(oldmem, size);
1010 matty 10 if (mem == NULL)
1011     {
1012 matty 30 error("xrealloc %d\n", size);
1013 matty 10 exit(1);
1014     }
1015     return mem;
1016     }
1017    
1018     /* free */
1019 matty 25 void
1020     xfree(void *mem)
1021 matty 10 {
1022     free(mem);
1023     }
1024    
1025 matty 30 /* report an error */
1026 matty 25 void
1027 matty 30 error(char *format, ...)
1028     {
1029     va_list ap;
1030    
1031     fprintf(stderr, "ERROR: ");
1032    
1033     va_start(ap, format);
1034     vfprintf(stderr, format, ap);
1035     va_end(ap);
1036     }
1037    
1038 matthewc 297 /* report a warning */
1039     void
1040     warning(char *format, ...)
1041     {
1042     va_list ap;
1043    
1044     fprintf(stderr, "WARNING: ");
1045    
1046     va_start(ap, format);
1047     vfprintf(stderr, format, ap);
1048     va_end(ap);
1049     }
1050    
1051 matty 30 /* report an unimplemented protocol feature */
1052     void
1053     unimpl(char *format, ...)
1054     {
1055     va_list ap;
1056    
1057     fprintf(stderr, "NOT IMPLEMENTED: ");
1058    
1059     va_start(ap, format);
1060     vfprintf(stderr, format, ap);
1061     va_end(ap);
1062     }
1063    
1064     /* produce a hex dump */
1065     void
1066 n-ki 569 hexdump(unsigned char *p, unsigned int len)
1067 matty 10 {
1068     unsigned char *line = p;
1069 jsorg71 376 int i, thisline, offset = 0;
1070 matty 10
1071     while (offset < len)
1072     {
1073 matthewc 169 printf("%04x ", offset);
1074 matty 10 thisline = len - offset;
1075     if (thisline > 16)
1076     thisline = 16;
1077    
1078     for (i = 0; i < thisline; i++)
1079 matthewc 169 printf("%02x ", line[i]);
1080 matty 10
1081 matty 30 for (; i < 16; i++)
1082 matthewc 169 printf(" ");
1083 matty 30
1084 matty 10 for (i = 0; i < thisline; i++)
1085 matthewc 169 printf("%c", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.');
1086 matty 10
1087 matthewc 169 printf("\n");
1088 matty 10 offset += thisline;
1089     line += thisline;
1090     }
1091     }
1092 astrand 325
1093 n-ki 569 /*
1094 n-ki 583 input: src is the string we look in for needle.
1095     Needle may be escaped by a backslash, in
1096     that case we ignore that particular needle.
1097 n-ki 569 return value: returns next src pointer, for
1098     succesive executions, like in a while loop
1099     if retval is 0, then there are no more args.
1100     pitfalls:
1101     src is modified. 0x00 chars are inserted to
1102     terminate strings.
1103     return val, points on the next val chr after ins
1104     0x00
1105 astrand 325
1106 n-ki 569 example usage:
1107     while( (pos = next_arg( optarg, ',')) ){
1108     printf("%s\n",optarg);
1109     optarg=pos;
1110     }
1111    
1112     */
1113     char *
1114     next_arg(char *src, char needle)
1115     {
1116     char *nextval;
1117 n-ki 571 char *p;
1118 n-ki 575 char *mvp = 0;
1119 n-ki 569
1120 n-ki 575 /* EOS */
1121 n-ki 569 if (*src == (char) 0x00)
1122     return 0;
1123    
1124 n-ki 571 p = src;
1125 n-ki 575 /* skip escaped needles */
1126 astrand 580 while ((nextval = strchr(p, needle)))
1127 n-ki 571 {
1128 n-ki 575 mvp = nextval - 1;
1129     /* found backslashed needle */
1130 astrand 580 if (*mvp == '\\' && (mvp > src))
1131 n-ki 575 {
1132     /* move string one to the left */
1133 astrand 580 while (*(mvp + 1) != (char) 0x00)
1134 n-ki 575 {
1135 astrand 580 *mvp = *(mvp + 1);
1136 n-ki 575 *mvp++;
1137     }
1138 astrand 580 *mvp = (char) 0x00;
1139 n-ki 575 p = nextval;
1140     }
1141     else
1142     {
1143 astrand 580 p = nextval + 1;
1144 n-ki 571 break;
1145 n-ki 575 }
1146    
1147 n-ki 571 }
1148    
1149 n-ki 575 /* more args available */
1150 n-ki 569 if (nextval)
1151     {
1152     *nextval = (char) 0x00;
1153     return ++nextval;
1154     }
1155    
1156 n-ki 575 /* no more args after this, jump to EOS */
1157 n-ki 569 nextval = src + strlen(src);
1158     return nextval;
1159     }
1160    
1161    
1162 stargo 570 void
1163 astrand 580 toupper_str(char *p)
1164 n-ki 569 {
1165 astrand 580 while (*p)
1166     {
1167     if ((*p >= 'a') && (*p <= 'z'))
1168 stargo 570 *p = toupper((int) *p);
1169 n-ki 569 p++;
1170     }
1171     }
1172    
1173    
1174 astrand 1010 BOOL
1175     str_startswith(const char *s, const char *prefix)
1176     {
1177     return (strncmp(s, prefix, strlen(prefix)) == 0);
1178     }
1179    
1180    
1181 n-ki 569 /* not all clibs got ltoa */
1182     #define LTOA_BUFSIZE (sizeof(long) * 8 + 1)
1183    
1184     char *
1185 stargo 603 l_to_a(long N, int base)
1186 n-ki 569 {
1187     static char ret[LTOA_BUFSIZE];
1188    
1189 n-ki 583 char *head = ret, buf[LTOA_BUFSIZE], *tail = buf + sizeof(buf);
1190 n-ki 569
1191 n-ki 583 register int divrem;
1192    
1193     if (base < 36 || 2 > base)
1194 n-ki 569 base = 10;
1195    
1196 n-ki 583 if (N < 0)
1197 n-ki 569 {
1198     *head++ = '-';
1199 n-ki 583 N = -N;
1200 n-ki 569 }
1201    
1202 n-ki 583 tail = buf + sizeof(buf);
1203     *--tail = 0;
1204    
1205     do
1206 n-ki 569 {
1207 n-ki 583 divrem = N % base;
1208     *--tail = (divrem <= 9) ? divrem + '0' : divrem + 'a' - 10;
1209     N /= base;
1210 n-ki 569 }
1211 n-ki 583 while (N);
1212 n-ki 569
1213 n-ki 583 strcpy(head, tail);
1214 n-ki 569 return ret;
1215     }
1216    
1217    
1218 astrand 325 int
1219     load_licence(unsigned char **data)
1220     {
1221 matthewc 367 char *home, *path;
1222 astrand 325 struct stat st;
1223 matthewc 367 int fd, length;
1224 astrand 325
1225     home = getenv("HOME");
1226     if (home == NULL)
1227     return -1;
1228    
1229 jsorg71 710 path = (char *) xmalloc(strlen(home) + strlen(g_hostname) + sizeof("/.rdesktop/licence."));
1230     sprintf(path, "%s/.rdesktop/licence.%s", home, g_hostname);
1231 astrand 325
1232     fd = open(path, O_RDONLY);
1233     if (fd == -1)
1234     return -1;
1235    
1236     if (fstat(fd, &st))
1237     return -1;
1238    
1239 forsberg 416 *data = (uint8 *) xmalloc(st.st_size);
1240 matthewc 367 length = read(fd, *data, st.st_size);
1241     close(fd);
1242     xfree(path);
1243     return length;
1244 astrand 325 }
1245    
1246     void
1247     save_licence(unsigned char *data, int length)
1248     {
1249 matthewc 367 char *home, *path, *tmppath;
1250     int fd;
1251 astrand 325
1252     home = getenv("HOME");
1253     if (home == NULL)
1254     return;
1255    
1256 jsorg71 710 path = (char *) xmalloc(strlen(home) + strlen(g_hostname) + sizeof("/.rdesktop/licence."));
1257 astrand 325
1258 matthewc 367 sprintf(path, "%s/.rdesktop", home);
1259     if ((mkdir(path, 0700) == -1) && errno != EEXIST)
1260 astrand 325 {
1261 matthewc 367 perror(path);
1262     return;
1263 astrand 325 }
1264    
1265 matthewc 367 /* write licence to licence.hostname.new, then atomically rename to licence.hostname */
1266 astrand 325
1267 jsorg71 710 sprintf(path, "%s/.rdesktop/licence.%s", home, g_hostname);
1268 forsberg 416 tmppath = (char *) xmalloc(strlen(path) + sizeof(".new"));
1269 matthewc 367 strcpy(tmppath, path);
1270     strcat(tmppath, ".new");
1271    
1272 forsberg 416 fd = open(tmppath, O_WRONLY | O_CREAT | O_TRUNC, 0600);
1273 matthewc 367 if (fd == -1)
1274 astrand 325 {
1275 matthewc 367 perror(tmppath);
1276     return;
1277 astrand 325 }
1278    
1279 matthewc 367 if (write(fd, data, length) != length)
1280 astrand 325 {
1281 matthewc 367 perror(tmppath);
1282     unlink(tmppath);
1283 astrand 325 }
1284 matthewc 367 else if (rename(tmppath, path) == -1)
1285 astrand 325 {
1286 matthewc 367 perror(path);
1287     unlink(tmppath);
1288 astrand 325 }
1289    
1290 matthewc 367 close(fd);
1291     xfree(tmppath);
1292     xfree(path);
1293 astrand 325 }
1294 jsorg71 725
1295     /* Create the bitmap cache directory */
1296     BOOL
1297     rd_pstcache_mkdir(void)
1298     {
1299     char *home;
1300     char bmpcache_dir[256];
1301    
1302     home = getenv("HOME");
1303    
1304     if (home == NULL)
1305     return False;
1306    
1307     sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop");
1308    
1309     if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST)
1310     {
1311     perror(bmpcache_dir);
1312     return False;
1313     }
1314    
1315     sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop/cache");
1316    
1317     if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST)
1318     {
1319     perror(bmpcache_dir);
1320     return False;
1321     }
1322    
1323     return True;
1324     }
1325    
1326     /* open a file in the .rdesktop directory */
1327     int
1328     rd_open_file(char *filename)
1329     {
1330     char *home;
1331     char fn[256];
1332 astrand 738 int fd;
1333 jsorg71 725
1334     home = getenv("HOME");
1335     if (home == NULL)
1336     return -1;
1337     sprintf(fn, "%s/.rdesktop/%s", home, filename);
1338     fd = open(fn, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
1339     if (fd == -1)
1340     perror(fn);
1341     return fd;
1342     }
1343    
1344     /* close file */
1345     void
1346     rd_close_file(int fd)
1347     {
1348 astrand 738 close(fd);
1349 jsorg71 725 }
1350    
1351     /* read from file*/
1352     int
1353     rd_read_file(int fd, void *ptr, int len)
1354     {
1355 astrand 738 return read(fd, ptr, len);
1356 jsorg71 725 }
1357    
1358     /* write to file */
1359     int
1360 astrand 738 rd_write_file(int fd, void *ptr, int len)
1361 jsorg71 725 {
1362 astrand 738 return write(fd, ptr, len);
1363 jsorg71 725 }
1364    
1365     /* move file pointer */
1366     int
1367     rd_lseek_file(int fd, int offset)
1368     {
1369 astrand 738 return lseek(fd, offset, SEEK_SET);
1370 jsorg71 725 }
1371    
1372     /* do a write lock on a file */
1373     BOOL
1374     rd_lock_file(int fd, int start, int len)
1375     {
1376     struct flock lock;
1377    
1378     lock.l_type = F_WRLCK;
1379     lock.l_whence = SEEK_SET;
1380     lock.l_start = start;
1381     lock.l_len = len;
1382     if (fcntl(fd, F_SETLK, &lock) == -1)
1383     return False;
1384     return True;
1385     }

  ViewVC Help
Powered by ViewVC 1.1.26