1 | /* |
1 | /* |
2 | vpectrl.C -- the main file for vpectrl |
2 | vpectrl.C -- the main file for vpectrl |
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 Marc Lehmann <pcg@goof.com> |
6 | |
6 | |
7 | This program is free software; you can redistribute it and/or modify |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by |
8 | 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 |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. |
10 | (at your option) any later version. |
… | |
… | |
21 | |
21 | |
22 | #include "config.h" |
22 | #include "config.h" |
23 | |
23 | |
24 | #include <cstdio> |
24 | #include <cstdio> |
25 | #include <cstring> |
25 | #include <cstring> |
|
|
26 | #include <cstdlib> |
|
|
27 | #include <clocale> |
26 | |
28 | |
27 | #include <errno.h> |
29 | #include <errno.h> |
28 | #include <fcntl.h> |
30 | #include <fcntl.h> |
29 | #include <getopt.h> |
31 | #include <getopt.h> |
30 | #include <signal.h> |
32 | #include <signal.h> |
|
|
33 | #include <sys/stat.h> |
31 | #include <sys/types.h> |
34 | #include <sys/types.h> |
32 | #include <unistd.h> |
35 | #include <unistd.h> |
33 | #include <signal.h> |
36 | #include <signal.h> |
34 | |
37 | |
35 | #include <openssl/rand.h> |
38 | #include <openssl/rand.h> |
… | |
… | |
42 | #include "gettext.h" |
45 | #include "gettext.h" |
43 | |
46 | |
44 | #include "conf.h" |
47 | #include "conf.h" |
45 | #include "slog.h" |
48 | #include "slog.h" |
46 | #include "util.h" |
49 | #include "util.h" |
47 | #include "protocol.h" |
50 | #include "vpn.h" |
48 | |
51 | |
49 | /* If nonzero, display usage information and exit. */ |
52 | /* If nonzero, display usage information and exit. */ |
50 | static int show_help; |
53 | static int show_help; |
51 | |
54 | |
52 | /* If nonzero, print the version on standard output and exit. */ |
55 | /* If nonzero, print the version on standard output and exit. */ |
… | |
… | |
123 | kill_vped = SIGKILL; |
126 | kill_vped = SIGKILL; |
124 | else if (!strcasecmp (optarg, "USR1")) |
127 | else if (!strcasecmp (optarg, "USR1")) |
125 | kill_vped = SIGUSR1; |
128 | kill_vped = SIGUSR1; |
126 | else if (!strcasecmp (optarg, "USR2")) |
129 | else if (!strcasecmp (optarg, "USR2")) |
127 | kill_vped = SIGUSR2; |
130 | kill_vped = SIGUSR2; |
128 | else if (!strcasecmp (optarg, "WINCH")) |
|
|
129 | kill_vped = SIGWINCH; |
|
|
130 | else if (!strcasecmp (optarg, "INT")) |
131 | else if (!strcasecmp (optarg, "INT")) |
131 | kill_vped = SIGINT; |
132 | kill_vped = SIGINT; |
132 | else if (!strcasecmp (optarg, "ALRM")) |
133 | else if (!strcasecmp (optarg, "ALRM")) |
133 | kill_vped = SIGALRM; |
134 | kill_vped = SIGALRM; |
134 | else |
135 | else |
… | |
… | |
235 | f = fopen (fname, "a"); |
236 | f = fopen (fname, "a"); |
236 | |
237 | |
237 | if (!f) |
238 | if (!f) |
238 | { |
239 | { |
239 | perror (fname); |
240 | perror (fname); |
240 | exit (1); |
241 | exit (EXIT_FAILURE); |
241 | } |
242 | } |
242 | |
243 | |
243 | if (ftell (f)) |
244 | if (ftell (f)) |
244 | { |
245 | { |
245 | fprintf (stderr, "'%s' already exists, skipping this node\n", |
246 | fprintf (stderr, "'%s' already exists, skipping this node\n", |
… | |
… | |
259 | return -1; |
260 | return -1; |
260 | } |
261 | } |
261 | else |
262 | else |
262 | fprintf (stderr, _("Done.\n")); |
263 | fprintf (stderr, _("Done.\n")); |
263 | |
264 | |
264 | PEM_write_RSAPublicKey (f, rsa_key); |
265 | require (PEM_write_RSAPublicKey (f, rsa_key)); |
265 | fclose (f); |
266 | fclose (f); |
266 | free (fname); |
267 | free (fname); |
267 | |
268 | |
268 | asprintf (&fname, "%s/hostkeys/%s", confbase, node->nodename); |
269 | asprintf (&fname, "%s/hostkeys/%s", confbase, node->nodename); |
269 | |
270 | |
270 | f = fopen (fname, "a"); |
271 | f = fopen (fname, "a"); |
271 | if (!f) |
272 | if (!f) |
272 | { |
273 | { |
273 | perror (fname); |
274 | perror (fname); |
274 | exit (1); |
275 | exit (EXIT_FAILURE); |
275 | } |
276 | } |
276 | |
277 | |
277 | PEM_write_RSAPrivateKey (f, rsa_key, NULL, NULL, 0, NULL, NULL); |
278 | require (PEM_write_RSAPrivateKey (f, rsa_key, NULL, NULL, 0, NULL, NULL)); |
278 | fclose (f); |
279 | fclose (f); |
279 | free (fname); |
280 | free (fname); |
280 | } |
281 | } |
281 | |
282 | |
282 | return 0; |
283 | return 0; |
… | |
… | |
294 | |
295 | |
295 | parse_options (argc, argv, envp); |
296 | parse_options (argc, argv, envp); |
296 | |
297 | |
297 | if (show_version) |
298 | if (show_version) |
298 | { |
299 | { |
299 | printf (_("%s version %s (built %s %s, protocol %d:%d)\n"), get_identity (), |
300 | printf (_("%s version %s (built %s %s, protocol %d.%d)\n"), get_identity (), |
300 | VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR); |
301 | VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR); |
|
|
302 | printf (_("Built with kernel interface %s/%s.\n"), IFTYPE, IFSUBTYPE); |
301 | printf (_ |
303 | printf (_ |
302 | ("Copyright (C) 2003 Marc Lehmann <vpe@plan9.de> and others.\n" |
304 | ("Copyright (C) 2003 Marc Lehmann <vpe@plan9.de> and others.\n" |
303 | "See the AUTHORS file for a complete list.\n\n" |
305 | "See the AUTHORS file for a complete list.\n\n" |
304 | "vpe comes with ABSOLUTELY NO WARRANTY. This is free software,\n" |
306 | "vpe comes with ABSOLUTELY NO WARRANTY. This is free software,\n" |
305 | "and you are welcome to redistribute it under certain conditions;\n" |
307 | "and you are welcome to redistribute it under certain conditions;\n" |
… | |
… | |
309 | } |
311 | } |
310 | |
312 | |
311 | if (show_help) |
313 | if (show_help) |
312 | usage (0); |
314 | usage (0); |
313 | |
315 | |
314 | make_names (); |
|
|
315 | conf.read_config (false); |
316 | conf.read_config (false); |
316 | |
317 | |
317 | if (generate_keys) |
318 | if (generate_keys) |
318 | { |
319 | { |
319 | RAND_load_file ("/dev/urandom", 1024); |
320 | RAND_load_file ("/dev/urandom", 1024); |
… | |
… | |
324 | exit (kill_other (kill_vped)); |
325 | exit (kill_other (kill_vped)); |
325 | |
326 | |
326 | if (show_config) |
327 | if (show_config) |
327 | { |
328 | { |
328 | conf.print (); |
329 | conf.print (); |
329 | exit (0); |
330 | exit (EXIT_SUCCESS); |
330 | } |
331 | } |
331 | |
332 | |
332 | usage (1); |
333 | usage (1); |
333 | } |
334 | } |