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.5 by pcg, Tue Jun 21 08:46:53 2005 UTC vs.
Revision 1.11 by root, Tue Feb 15 13:31:23 2011 UTC

1/* 1/*
2 gvpectrl.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-2011 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. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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>
58static int kill_gvpe; 68static int kill_gvpe;
59 69
60/* If nonzero, it will attempt to kill a running gvpe and exit. */ 70/* If nonzero, it will attempt to kill a running gvpe and exit. */
61static int show_config; 71static int show_config;
62 72
73/* If nonzero, do not output anything but warnings/errors/very unusual conditions */
74static int quiet;
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[] =
67 { 80{
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
78usage (int status) 92usage (int status)
79{ 93{
80 if (status != 0) 94 if (status != 0)
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 gvpe 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 <gvpe@schmorp.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
98void 113static void
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 gvpes */ 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_gvpe = SIGHUP; 134 kill_gvpe = SIGHUP;
122 else if (!strcasecmp (optarg, "TERM")) 135 else if (!strcasecmp (optarg, "TERM"))
123 kill_gvpe = SIGTERM; 136 kill_gvpe = SIGTERM;
124 else if (!strcasecmp (optarg, "KILL")) 137 else if (!strcasecmp (optarg, "KILL"))
125 kill_gvpe = SIGKILL; 138 kill_gvpe = SIGKILL;
126 else if (!strcasecmp (optarg, "USR1")) 139 else if (!strcasecmp (optarg, "USR1"))
127 kill_gvpe = SIGUSR1; 140 kill_gvpe = SIGUSR1;
128 else if (!strcasecmp (optarg, "USR2")) 141 else if (!strcasecmp (optarg, "USR2"))
129 kill_gvpe = SIGUSR2; 142 kill_gvpe = SIGUSR2;
130 else if (!strcasecmp (optarg, "INT")) 143 else if (!strcasecmp (optarg, "INT"))
131 kill_gvpe = SIGINT; 144 kill_gvpe = SIGINT;
132 else if (!strcasecmp (optarg, "ALRM")) 145 else if (!strcasecmp (optarg, "ALRM"))
133 kill_gvpe = SIGALRM; 146 kill_gvpe = SIGALRM;
134 else 147 else
135 { 148 {
136 kill_gvpe = atoi (optarg); 149 kill_gvpe = atoi (optarg);
137 150
138 if (!kill_gvpe) 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_gvpe = 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;
155 break; 168 break;
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;
166 } 183 }
167 } 184 }
168} 185}
169 186
170/* This function prettyprints the key generation process */ 187// this function prettyprints the key generation process
171 188static void
172void
173indicator (int a, int b, void *p) 189indicator (int a, int b, void *p)
174{ 190{
191 if (quiet)
192 return;
193
175 switch (a) 194 switch (a)
176 { 195 {
177 case 0: 196 case 0:
178 fprintf (stderr, "."); 197 fprintf (stderr, ".");
179 break; 198 break;
180 199
181 case 1: 200 case 1:
182 fprintf (stderr, "+"); 201 fprintf (stderr, "+");
183 break; 202 break;
184 203
185 case 2: 204 case 2:
186 fprintf (stderr, "-"); 205 fprintf (stderr, "-");
187 break; 206 break;
188 207
189 case 3: 208 case 3:
190 switch (b) 209 switch (b)
191 { 210 {
192 case 0: 211 case 0:
193 fprintf (stderr, " p\n"); 212 fprintf (stderr, " p\n");
194 break; 213 break;
195 214
196 case 1: 215 case 1:
197 fprintf (stderr, " q\n"); 216 fprintf (stderr, " q\n");
198 break; 217 break;
199 218
200 default: 219 default:
201 fprintf (stderr, "?"); 220 fprintf (stderr, "?");
202 } 221 }
203 break; 222 break;
204 223
205 default: 224 default:
206 fprintf (stderr, "?"); 225 fprintf (stderr, "?");
207 } 226 }
208} 227}
209 228
210/* 229/*
211 * generate public/private RSA keypairs for all hosts that don't have one. 230 * generate public/private RSA keypairs for all hosts that don't have one.
212 */ 231 */
213int 232static int
214keygen (int bits) 233keygen (int bits)
215{ 234{
216 RSA *rsa_key; 235 RSA *rsa_key;
217 FILE *f; 236 FILE *f;
218 char *name = NULL; 237 char *name = NULL;
240 exit (EXIT_FAILURE); 259 exit (EXIT_FAILURE);
241 } 260 }
242 261
243 if (ftell (f)) 262 if (ftell (f))
244 { 263 {
264 if (!quiet)
245 fprintf (stderr, "'%s' already exists, skipping this node\n", 265 fprintf (stderr, "'%s' already exists, skipping this node %d\n",
246 fname); 266 fname, quiet);
267
247 fclose (f); 268 fclose (f);
248 continue; 269 continue;
249 } 270 }
250 271
251 fprintf (stderr, _("generating %d bits key for %s:\n"), bits, 272 fprintf (stderr, _("generating %d bits key for %s:\n"), bits,
294 315
295 parse_options (argc, argv, envp); 316 parse_options (argc, argv, envp);
296 317
297 if (show_version) 318 if (show_version)
298 { 319 {
299 printf (_("%s version %s (built %s %s, protocol %d.%d)\n"), get_identity (), 320 printf (_("%s version %s (built %s %s, protocol version %d.%d)\n"), get_identity (),
300 VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR); 321 VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR);
301 printf (_("Built with kernel interface %s/%s.\n"), IFTYPE, IFSUBTYPE); 322 printf (_("Built with kernel interface %s/%s.\n"), IFTYPE, IFSUBTYPE);
302 printf (_ 323 printf (_
303 ("Copyright (C) 2003 Marc Lehmann <gvpe@schmorp.de> and others.\n" 324 ("Copyright (C) 2003-2008 Marc Lehmann <gvpe@schmorp.de> and others.\n"
304 "See the AUTHORS file for a complete list.\n\n" 325 "See the AUTHORS file for a complete list.\n\n"
305 "vpe comes with ABSOLUTELY NO WARRANTY. This is free software,\n" 326 "vpe comes with ABSOLUTELY NO WARRANTY. This is free software,\n"
306 "and you are welcome to redistribute it under certain conditions;\n" 327 "and you are welcome to redistribute it under certain conditions;\n"
307 "see the file COPYING for details.\n")); 328 "see the file COPYING for details.\n"));
308 329

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines