1 | /* |
1 | /* |
2 | vpectrl.C -- the main file for gvpectrl |
2 | gvpectrl.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-2005 Marc Lehmann <gvpe@schmorp.de> |
5 | 2003-2005 Marc Lehmann <gvpe@schmorp.de> |
6 | |
6 | |
7 | This file is part of GVPE. |
7 | This file is part of GVPE. |
… | |
… | |
52 | static int show_help; |
52 | static int show_help; |
53 | |
53 | |
54 | /* If nonzero, print the version on standard output and exit. */ |
54 | /* If nonzero, print the version on standard output and exit. */ |
55 | static int show_version; |
55 | static int show_version; |
56 | |
56 | |
57 | /* If nonzero, it will attempt to kill a running vped and exit. */ |
57 | /* If nonzero, it will attempt to kill a running gvpe and exit. */ |
58 | static int kill_vped; |
58 | static int kill_gvpe; |
59 | |
59 | |
60 | /* If nonzero, it will attempt to kill a running vped and exit. */ |
60 | /* If nonzero, it will attempt to kill a running gvpe and exit. */ |
61 | static int show_config; |
61 | static int show_config; |
62 | |
62 | |
63 | /* If nonzero, generate public/private keypair for this net. */ |
63 | /* If nonzero, generate public/private keypair for this net. */ |
64 | static int generate_keys; |
64 | static int generate_keys; |
65 | |
65 | |
… | |
… | |
82 | else |
82 | else |
83 | { |
83 | { |
84 | printf (_("Usage: %s [option]...\n\n"), get_identity ()); |
84 | printf (_("Usage: %s [option]...\n\n"), get_identity ()); |
85 | printf (_ |
85 | printf (_ |
86 | (" -c, --config=DIR Read configuration options from DIR.\n" |
86 | (" -c, --config=DIR Read configuration options from DIR.\n" |
87 | " -k, --kill[=SIGNAL] Attempt to kill a running vped and exit.\n" |
87 | " -k, --kill[=SIGNAL] Attempt to kill a running gvpe and exit.\n" |
88 | " -g, --generate-keys Generate public/private RSA keypair.\n" |
88 | " -g, --generate-keys Generate public/private RSA keypair.\n" |
89 | " -s, --show-config Display the configuration information.\n" |
89 | " -s, --show-config Display the configuration information.\n" |
90 | " --help Display this help and exit.\n" |
90 | " --help Display this help and exit.\n" |
91 | " --version Output version information and exit.\n\n")); |
91 | " --version Output version information and exit.\n\n")); |
92 | printf (_("Report bugs to <vpe@plan9.de>.\n")); |
92 | printf (_("Report bugs to <vpe@plan9.de>.\n")); |
… | |
… | |
112 | |
112 | |
113 | case 'c': /* config file */ |
113 | case 'c': /* config file */ |
114 | confbase = strdup (optarg); |
114 | confbase = strdup (optarg); |
115 | break; |
115 | break; |
116 | |
116 | |
117 | case 'k': /* kill old vpeds */ |
117 | case 'k': /* kill old gvpes */ |
118 | if (optarg) |
118 | if (optarg) |
119 | { |
119 | { |
120 | if (!strcasecmp (optarg, "HUP")) |
120 | if (!strcasecmp (optarg, "HUP")) |
121 | kill_vped = SIGHUP; |
121 | kill_gvpe = SIGHUP; |
122 | else if (!strcasecmp (optarg, "TERM")) |
122 | else if (!strcasecmp (optarg, "TERM")) |
123 | kill_vped = SIGTERM; |
123 | kill_gvpe = SIGTERM; |
124 | else if (!strcasecmp (optarg, "KILL")) |
124 | else if (!strcasecmp (optarg, "KILL")) |
125 | kill_vped = SIGKILL; |
125 | kill_gvpe = SIGKILL; |
126 | else if (!strcasecmp (optarg, "USR1")) |
126 | else if (!strcasecmp (optarg, "USR1")) |
127 | kill_vped = SIGUSR1; |
127 | kill_gvpe = SIGUSR1; |
128 | else if (!strcasecmp (optarg, "USR2")) |
128 | else if (!strcasecmp (optarg, "USR2")) |
129 | kill_vped = SIGUSR2; |
129 | kill_gvpe = SIGUSR2; |
130 | else if (!strcasecmp (optarg, "INT")) |
130 | else if (!strcasecmp (optarg, "INT")) |
131 | kill_vped = SIGINT; |
131 | kill_gvpe = SIGINT; |
132 | else if (!strcasecmp (optarg, "ALRM")) |
132 | else if (!strcasecmp (optarg, "ALRM")) |
133 | kill_vped = SIGALRM; |
133 | kill_gvpe = SIGALRM; |
134 | else |
134 | else |
135 | { |
135 | { |
136 | kill_vped = atoi (optarg); |
136 | kill_gvpe = atoi (optarg); |
137 | |
137 | |
138 | if (!kill_vped) |
138 | if (!kill_gvpe) |
139 | { |
139 | { |
140 | fprintf (stderr, |
140 | fprintf (stderr, |
141 | _ |
141 | _ |
142 | ("Invalid argument `%s'; SIGNAL must be a number or one of HUP, TERM, KILL, USR1, USR2, WINCH, INT or ALRM.\n"), |
142 | ("Invalid argument `%s'; SIGNAL must be a number or one of HUP, TERM, KILL, USR1, USR2, WINCH, INT or ALRM.\n"), |
143 | optarg); |
143 | optarg); |
144 | usage (1); |
144 | usage (1); |
145 | } |
145 | } |
146 | } |
146 | } |
147 | } |
147 | } |
148 | else |
148 | else |
149 | kill_vped = SIGTERM; |
149 | kill_gvpe = SIGTERM; |
150 | |
150 | |
151 | break; |
151 | break; |
152 | |
152 | |
153 | case 'g': /* generate public/private keypair */ |
153 | case 'g': /* generate public/private keypair */ |
154 | generate_keys = RSA_KEYBITS; |
154 | generate_keys = RSA_KEYBITS; |
… | |
… | |
310 | } |
310 | } |
311 | |
311 | |
312 | if (show_help) |
312 | if (show_help) |
313 | usage (0); |
313 | usage (0); |
314 | |
314 | |
315 | conf.read_config (false); |
315 | { |
|
|
316 | configuration_parser (conf, false, 0, 0); |
|
|
317 | } |
316 | |
318 | |
317 | if (generate_keys) |
319 | if (generate_keys) |
318 | { |
320 | { |
319 | RAND_load_file ("/dev/urandom", 1024); |
321 | RAND_load_file ("/dev/urandom", 1024); |
320 | exit (keygen (generate_keys)); |
322 | exit (keygen (generate_keys)); |
321 | } |
323 | } |
322 | |
324 | |
323 | if (kill_vped) |
325 | if (kill_gvpe) |
324 | exit (kill_other (kill_vped)); |
326 | exit (kill_other (kill_gvpe)); |
325 | |
327 | |
326 | if (show_config) |
328 | if (show_config) |
327 | { |
329 | { |
328 | conf.print (); |
330 | conf.print (); |
329 | exit (EXIT_SUCCESS); |
331 | exit (EXIT_SUCCESS); |