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

Comparing gvpe/src/gvpectrl.C (file contents):
Revision 1.1 by pcg, Fri Mar 18 01:53:05 2005 UTC vs.
Revision 1.8 by pcg, Mon Aug 11 16:02:16 2008 UTC

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-2008 Marc Lehmann <gvpe@schmorp.de>
6 6
7 This file is part of GVPE. 7 This file is part of GVPE.
8 8
9 GVPE is free software; you can redistribute it and/or modify 9 GVPE is free software; you can redistribute it and/or modify it
10 it under the terms of the GNU General Public License as published by 10 under the terms of the GNU General Public License as published by the
11 the Free Software Foundation; either version 2 of the License, or 11 Free Software Foundation; either version 3 of the License, or (at your
12 (at your option) any later version. 12 option) any later version.
13 13
14 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, but
15 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
17 GNU General Public License for more details. 17 Public License for more details.
18 18
19 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 along
20 along with gvpe; if not, write to the Free Software 20 with this program; if not, see <http://www.gnu.org/licenses/>.
21 Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21
22 Additional permission under GNU GPL version 3 section 7
23
24 If you modify this Program, or any covered work, by linking or
25 combining it with the OpenSSL project's OpenSSL library (or a modified
26 version of that library), containing parts covered by the terms of the
27 OpenSSL or SSLeay licenses, the licensors of this Program grant you
28 additional permission to convey the resulting work. Corresponding
29 Source for a non-source form of such a combination shall include the
30 source code for the parts of OpenSSL used as well as that of the
31 covered work.
22*/ 32*/
23 33
24#include "config.h" 34#include "config.h"
25 35
26#include <cstdio> 36#include <cstdio>
52static int show_help; 62static int show_help;
53 63
54/* If nonzero, print the version on standard output and exit. */ 64/* If nonzero, print the version on standard output and exit. */
55static int show_version; 65static int show_version;
56 66
57/* If nonzero, it will attempt to kill a running vped and exit. */ 67/* If nonzero, it will attempt to kill a running gvpe and exit. */
58static int kill_vped; 68static int kill_gvpe;
59 69
60/* If nonzero, it will attempt to kill a running vped and exit. */ 70/* If nonzero, it will attempt to kill a running gvpe and exit. */
61static int show_config; 71static int show_config;
72
73/* If nonzero, do not output anything but warnings/errors/very unusual conditions */
74static int quiet;
62 75
63/* If nonzero, generate public/private keypair for this net. */ 76/* If nonzero, generate public/private keypair for this net. */
64static int generate_keys; 77static int generate_keys;
65 78
66static struct option const long_options[] = 79static struct option const long_options[] =
68 {"config", required_argument, NULL, 'c'}, 81 {"config", required_argument, NULL, 'c'},
69 {"kill", optional_argument, NULL, 'k'}, 82 {"kill", optional_argument, NULL, 'k'},
70 {"help", no_argument, &show_help, 1}, 83 {"help", no_argument, &show_help, 1},
71 {"version", no_argument, &show_version, 1}, 84 {"version", no_argument, &show_version, 1},
72 {"generate-keys", no_argument, NULL, 'g'}, 85 {"generate-keys", no_argument, NULL, 'g'},
86 {"quiet", no_argument, &quiet, 1},
73 {"show-config", no_argument, &show_config, 's'}, 87 {"show-config", no_argument, &show_config, 's'},
74 {NULL, 0, NULL, 0} 88 {NULL, 0, NULL, 0}
75 }; 89 };
76 90
77static void 91static void
82 else 96 else
83 { 97 {
84 printf (_("Usage: %s [option]...\n\n"), get_identity ()); 98 printf (_("Usage: %s [option]...\n\n"), get_identity ());
85 printf (_ 99 printf (_
86 (" -c, --config=DIR Read configuration options from DIR.\n" 100 (" -c, --config=DIR Read configuration options from DIR.\n"
87 " -k, --kill[=SIGNAL] Attempt to kill a running vped and exit.\n" 101 " -k, --kill[=SIGNAL] Attempt to kill a running gvpe and exit.\n"
88 " -g, --generate-keys Generate public/private RSA keypair.\n" 102 " -g, --generate-keys Generate public/private RSA keypair.\n"
89 " -s, --show-config Display the configuration information.\n" 103 " -s, --show-config Display the configuration information.\n"
104 " -q, --quiet Be quite quiet.\n"
90 " --help Display this help and exit.\n" 105 " --help Display this help and exit.\n"
91 " --version Output version information and exit.\n\n")); 106 " --version Output version information and exit.\n\n"));
92 printf (_("Report bugs to <vpe@plan9.de>.\n")); 107 printf (_("Report bugs to <gvpe@schmorp.de>.\n"));
93 } 108 }
94 109
95 exit (status); 110 exit (status);
96} 111}
97 112
99parse_options (int argc, char **argv, char **envp) 114parse_options (int argc, char **argv, char **envp)
100{ 115{
101 int r; 116 int r;
102 int option_index = 0; 117 int option_index = 0;
103 118
104 while ((r = 119 while ((r = getopt_long (argc, argv, "c:k::qgs", long_options, &option_index)) != EOF)
105 getopt_long (argc, argv, "c:k::gs", long_options,
106 &option_index)) != EOF)
107 { 120 {
108 switch (r) 121 switch (r)
109 { 122 {
110 case 0: /* long option */ 123 case 0: /* long option */
111 break; 124 break;
112 125
113 case 'c': /* config file */ 126 case 'c': /* config file */
114 confbase = strdup (optarg); 127 confbase = strdup (optarg);
115 break; 128 break;
116 129
117 case 'k': /* kill old vpeds */ 130 case 'k': /* kill old gvpes */
118 if (optarg) 131 if (optarg)
119 { 132 {
120 if (!strcasecmp (optarg, "HUP")) 133 if (!strcasecmp (optarg, "HUP"))
121 kill_vped = SIGHUP; 134 kill_gvpe = SIGHUP;
122 else if (!strcasecmp (optarg, "TERM")) 135 else if (!strcasecmp (optarg, "TERM"))
123 kill_vped = SIGTERM; 136 kill_gvpe = SIGTERM;
124 else if (!strcasecmp (optarg, "KILL")) 137 else if (!strcasecmp (optarg, "KILL"))
125 kill_vped = SIGKILL; 138 kill_gvpe = SIGKILL;
126 else if (!strcasecmp (optarg, "USR1")) 139 else if (!strcasecmp (optarg, "USR1"))
127 kill_vped = SIGUSR1; 140 kill_gvpe = SIGUSR1;
128 else if (!strcasecmp (optarg, "USR2")) 141 else if (!strcasecmp (optarg, "USR2"))
129 kill_vped = SIGUSR2; 142 kill_gvpe = SIGUSR2;
130 else if (!strcasecmp (optarg, "INT")) 143 else if (!strcasecmp (optarg, "INT"))
131 kill_vped = SIGINT; 144 kill_gvpe = SIGINT;
132 else if (!strcasecmp (optarg, "ALRM")) 145 else if (!strcasecmp (optarg, "ALRM"))
133 kill_vped = SIGALRM; 146 kill_gvpe = SIGALRM;
134 else 147 else
135 { 148 {
136 kill_vped = atoi (optarg); 149 kill_gvpe = atoi (optarg);
137 150
138 if (!kill_vped) 151 if (!kill_gvpe)
139 { 152 {
140 fprintf (stderr, 153 fprintf (stderr,
141 _ 154 _
142 ("Invalid argument `%s'; SIGNAL must be a number or one of HUP, TERM, KILL, USR1, USR2, WINCH, INT or ALRM.\n"), 155 ("Invalid argument `%s'; SIGNAL must be a number or one of HUP, TERM, KILL, USR1, USR2, WINCH, INT or ALRM.\n"),
143 optarg); 156 optarg);
144 usage (1); 157 usage (1);
145 } 158 }
146 } 159 }
147 } 160 }
148 else 161 else
149 kill_vped = SIGTERM; 162 kill_gvpe = SIGTERM;
150 163
151 break; 164 break;
152 165
153 case 'g': /* generate public/private keypair */ 166 case 'g': /* generate public/private keypair */
154 generate_keys = RSA_KEYBITS; 167 generate_keys = RSA_KEYBITS;
156 169
157 case 's': 170 case 's':
158 show_config = 1; 171 show_config = 1;
159 break; 172 break;
160 173
174 case 'q':
175 quiet = 1;
176 break;
177
161 case '?': 178 case '?':
162 usage (1); 179 usage (1);
163 180
164 default: 181 default:
165 break; 182 break;
170/* This function prettyprints the key generation process */ 187/* This function prettyprints the key generation process */
171 188
172void 189void
173indicator (int a, int b, void *p) 190indicator (int a, int b, void *p)
174{ 191{
192 if (quiet)
193 return;
194
175 switch (a) 195 switch (a)
176 { 196 {
177 case 0: 197 case 0:
178 fprintf (stderr, "."); 198 fprintf (stderr, ".");
179 break; 199 break;
240 exit (EXIT_FAILURE); 260 exit (EXIT_FAILURE);
241 } 261 }
242 262
243 if (ftell (f)) 263 if (ftell (f))
244 { 264 {
265 if (!quiet)
245 fprintf (stderr, "'%s' already exists, skipping this node\n", 266 fprintf (stderr, "'%s' already exists, skipping this node %d\n",
246 fname); 267 fname, quiet);
268
247 fclose (f); 269 fclose (f);
248 continue; 270 continue;
249 } 271 }
250 272
251 fprintf (stderr, _("generating %d bits key for %s:\n"), bits, 273 fprintf (stderr, _("generating %d bits key for %s:\n"), bits,
294 316
295 parse_options (argc, argv, envp); 317 parse_options (argc, argv, envp);
296 318
297 if (show_version) 319 if (show_version)
298 { 320 {
299 printf (_("%s version %s (built %s %s, protocol %d.%d)\n"), get_identity (), 321 printf (_("%s version %s (built %s %s, protocol version %d.%d)\n"), get_identity (),
300 VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR); 322 VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR);
301 printf (_("Built with kernel interface %s/%s.\n"), IFTYPE, IFSUBTYPE); 323 printf (_("Built with kernel interface %s/%s.\n"), IFTYPE, IFSUBTYPE);
302 printf (_ 324 printf (_
303 ("Copyright (C) 2003 Marc Lehmann <vpe@plan9.de> and others.\n" 325 ("Copyright (C) 2003 Marc Lehmann <gvpe@schmorp.de> and others.\n"
304 "See the AUTHORS file for a complete list.\n\n" 326 "See the AUTHORS file for a complete list.\n\n"
305 "vpe comes with ABSOLUTELY NO WARRANTY. This is free software,\n" 327 "vpe comes with ABSOLUTELY NO WARRANTY. This is free software,\n"
306 "and you are welcome to redistribute it under certain conditions;\n" 328 "and you are welcome to redistribute it under certain conditions;\n"
307 "see the file COPYING for details.\n")); 329 "see the file COPYING for details.\n"));
308 330
310 } 332 }
311 333
312 if (show_help) 334 if (show_help)
313 usage (0); 335 usage (0);
314 336
315 conf.read_config (false); 337 {
338 configuration_parser (conf, false, 0, 0);
339 }
316 340
317 if (generate_keys) 341 if (generate_keys)
318 { 342 {
319 RAND_load_file ("/dev/urandom", 1024); 343 RAND_load_file ("/dev/urandom", 1024);
320 exit (keygen (generate_keys)); 344 exit (keygen (generate_keys));
321 } 345 }
322 346
323 if (kill_vped) 347 if (kill_gvpe)
324 exit (kill_other (kill_vped)); 348 exit (kill_other (kill_gvpe));
325 349
326 if (show_config) 350 if (show_config)
327 { 351 {
328 conf.print (); 352 conf.print ();
329 exit (EXIT_SUCCESS); 353 exit (EXIT_SUCCESS);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines