ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/vpectrl.C
(Generate patch)

Comparing gvpe/src/vpectrl.C (file contents):
Revision 1.1 by pcg, Sat Mar 1 15:53:03 2003 UTC vs.
Revision 1.13 by pcg, Thu Mar 3 16:54:34 2005 UTC

1/* 1/*
2 vpectrl.C -- the main file for vpectrl 2 vpectrl.C -- the main file for gvpectrl
3 Copyright (C) 1998-2002 Ivo Timmermans <ivo@o2w.nl> 3 Copyright (C) 1998-2002 Ivo Timmermans <ivo@o2w.nl>
4 2000-2002 Guus Sliepen <guus@sliepen.eu.org> 4 2000-2002 Guus Sliepen <guus@sliepen.eu.org>
5 2003 Marc Lehmannn <pcg@goof.com> 5 2003-2005 Marc Lehmann <gvpe@schmorp.de>
6 6
7 This file is part of GVPE.
8
7 This program is free software; you can redistribute it and/or modify 9 GVPE is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 10 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 11 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 12 (at your option) any later version.
11 13
12 This program is distributed in the hope that it will be useful, 14 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 17 GNU General Public License for more details.
16 18
17 You should have received a copy of the GNU General Public License 19 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software 20 along with gvpe; if not, write to the Free Software
19 Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20*/ 22*/
21 23
22#include "config.h" 24#include "config.h"
23 25
24#include <cstdio> 26#include <cstdio>
25#include <cstring> 27#include <cstring>
28#include <cstdlib>
29#include <locale.h>
26 30
27#include <errno.h> 31#include <errno.h>
28#include <fcntl.h> 32#include <fcntl.h>
29#include <getopt.h> 33#include <getopt.h>
30#include <signal.h> 34#include <signal.h>
35#include <sys/stat.h>
31#include <sys/types.h> 36#include <sys/types.h>
32#include <unistd.h> 37#include <unistd.h>
33#include <signal.h> 38#include <signal.h>
34 39
35#include <openssl/rand.h> 40#include <openssl/rand.h>
42#include "gettext.h" 47#include "gettext.h"
43 48
44#include "conf.h" 49#include "conf.h"
45#include "slog.h" 50#include "slog.h"
46#include "util.h" 51#include "util.h"
47#include "protocol.h" 52#include "vpn.h"
48 53
49/* If nonzero, display usage information and exit. */ 54/* If nonzero, display usage information and exit. */
50static int show_help; 55static int show_help;
51 56
52/* If nonzero, print the version on standard output and exit. */ 57/* If nonzero, print the version on standard output and exit. */
123 kill_vped = SIGKILL; 128 kill_vped = SIGKILL;
124 else if (!strcasecmp (optarg, "USR1")) 129 else if (!strcasecmp (optarg, "USR1"))
125 kill_vped = SIGUSR1; 130 kill_vped = SIGUSR1;
126 else if (!strcasecmp (optarg, "USR2")) 131 else if (!strcasecmp (optarg, "USR2"))
127 kill_vped = SIGUSR2; 132 kill_vped = SIGUSR2;
128 else if (!strcasecmp (optarg, "WINCH"))
129 kill_vped = SIGWINCH;
130 else if (!strcasecmp (optarg, "INT")) 133 else if (!strcasecmp (optarg, "INT"))
131 kill_vped = SIGINT; 134 kill_vped = SIGINT;
132 else if (!strcasecmp (optarg, "ALRM")) 135 else if (!strcasecmp (optarg, "ALRM"))
133 kill_vped = SIGALRM; 136 kill_vped = SIGALRM;
134 else 137 else
235 f = fopen (fname, "a"); 238 f = fopen (fname, "a");
236 239
237 if (!f) 240 if (!f)
238 { 241 {
239 perror (fname); 242 perror (fname);
240 exit (1); 243 exit (EXIT_FAILURE);
241 } 244 }
242 245
243 if (ftell (f)) 246 if (ftell (f))
244 { 247 {
245 fprintf (stderr, "'%s' already exists, skipping this node\n", 248 fprintf (stderr, "'%s' already exists, skipping this node\n",
259 return -1; 262 return -1;
260 } 263 }
261 else 264 else
262 fprintf (stderr, _("Done.\n")); 265 fprintf (stderr, _("Done.\n"));
263 266
264 PEM_write_RSAPublicKey (f, rsa_key); 267 require (PEM_write_RSAPublicKey (f, rsa_key));
265 fclose (f); 268 fclose (f);
266 free (fname); 269 free (fname);
267 270
268 asprintf (&fname, "%s/hostkeys/%s", confbase, node->nodename); 271 asprintf (&fname, "%s/hostkeys/%s", confbase, node->nodename);
269 272
270 f = fopen (fname, "a"); 273 f = fopen (fname, "a");
271 if (!f) 274 if (!f)
272 { 275 {
273 perror (fname); 276 perror (fname);
274 exit (1); 277 exit (EXIT_FAILURE);
275 } 278 }
276 279
277 PEM_write_RSAPrivateKey (f, rsa_key, NULL, NULL, 0, NULL, NULL); 280 require (PEM_write_RSAPrivateKey (f, rsa_key, NULL, NULL, 0, NULL, NULL));
278 fclose (f); 281 fclose (f);
279 free (fname); 282 free (fname);
280 } 283 }
281 284
282 return 0; 285 return 0;
294 297
295 parse_options (argc, argv, envp); 298 parse_options (argc, argv, envp);
296 299
297 if (show_version) 300 if (show_version)
298 { 301 {
299 printf (_("%s version %s (built %s %s, protocol %d:%d)\n"), get_identity (), 302 printf (_("%s version %s (built %s %s, protocol %d.%d)\n"), get_identity (),
300 VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR); 303 VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR);
304 printf (_("Built with kernel interface %s/%s.\n"), IFTYPE, IFSUBTYPE);
301 printf (_ 305 printf (_
302 ("Copyright (C) 2003 Marc Lehmann <vpe@plan9.de> and others.\n" 306 ("Copyright (C) 2003 Marc Lehmann <vpe@plan9.de> and others.\n"
303 "See the AUTHORS file for a complete list.\n\n" 307 "See the AUTHORS file for a complete list.\n\n"
304 "vpe comes with ABSOLUTELY NO WARRANTY. This is free software,\n" 308 "vpe comes with ABSOLUTELY NO WARRANTY. This is free software,\n"
305 "and you are welcome to redistribute it under certain conditions;\n" 309 "and you are welcome to redistribute it under certain conditions;\n"
309 } 313 }
310 314
311 if (show_help) 315 if (show_help)
312 usage (0); 316 usage (0);
313 317
314 make_names ();
315 conf.read_config (false); 318 conf.read_config (false);
316 319
317 if (generate_keys) 320 if (generate_keys)
318 { 321 {
319 RAND_load_file ("/dev/urandom", 1024); 322 RAND_load_file ("/dev/urandom", 1024);
324 exit (kill_other (kill_vped)); 327 exit (kill_other (kill_vped));
325 328
326 if (show_config) 329 if (show_config)
327 { 330 {
328 conf.print (); 331 conf.print ();
329 exit (0); 332 exit (EXIT_SUCCESS);
330 } 333 }
331 334
332 usage (1); 335 usage (1);
333} 336}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines