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.7 by pcg, Thu Aug 7 17:54:27 2008 UTC vs.
Revision 1.10 by root, Tue Feb 8 23:11:36 2011 UTC

68static int kill_gvpe; 68static int kill_gvpe;
69 69
70/* 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. */
71static int show_config; 71static int show_config;
72 72
73/* If nonzero, do not output anything but warnings/errors/very unusual conditions */
74static int quiet;
75
73/* If nonzero, generate public/private keypair for this net. */ 76/* If nonzero, generate public/private keypair for this net. */
74static int generate_keys; 77static int generate_keys;
75 78
76static struct option const long_options[] = 79static struct option const long_options[] =
77 { 80{
78 {"config", required_argument, NULL, 'c'}, 81 {"config", required_argument, NULL, 'c'},
79 {"kill", optional_argument, NULL, 'k'}, 82 {"kill", optional_argument, NULL, 'k'},
80 {"help", no_argument, &show_help, 1}, 83 {"help", no_argument, &show_help, 1},
81 {"version", no_argument, &show_version, 1}, 84 {"version", no_argument, &show_version, 1},
82 {"generate-keys", no_argument, NULL, 'g'}, 85 {"generate-keys", no_argument, NULL, 'g'},
86 {"quiet", no_argument, &quiet, 1},
83 {"show-config", no_argument, &show_config, 's'}, 87 {"show-config", no_argument, &show_config, 's'},
84 {NULL, 0, NULL, 0} 88 {NULL, 0, NULL, 0}
85 }; 89};
86 90
87static void 91static void
88usage (int status) 92usage (int status)
89{ 93{
90 if (status != 0) 94 if (status != 0)
95 printf (_ 99 printf (_
96 (" -c, --config=DIR Read configuration options from DIR.\n" 100 (" -c, --config=DIR Read configuration options from DIR.\n"
97 " -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"
98 " -g, --generate-keys Generate public/private RSA keypair.\n" 102 " -g, --generate-keys Generate public/private RSA keypair.\n"
99 " -s, --show-config Display the configuration information.\n" 103 " -s, --show-config Display the configuration information.\n"
104 " -q, --quiet Be quite quiet.\n"
100 " --help Display this help and exit.\n" 105 " --help Display this help and exit.\n"
101 " --version Output version information and exit.\n\n")); 106 " --version Output version information and exit.\n\n"));
102 printf (_("Report bugs to <gvpe@schmorp.de>.\n")); 107 printf (_("Report bugs to <gvpe@schmorp.de>.\n"));
103 } 108 }
104 109
105 exit (status); 110 exit (status);
106} 111}
107 112
108void 113static void
109parse_options (int argc, char **argv, char **envp) 114parse_options (int argc, char **argv, char **envp)
110{ 115{
111 int r; 116 int r;
112 int option_index = 0; 117 int option_index = 0;
113 118
114 while ((r = 119 while ((r = getopt_long (argc, argv, "c:k::qgs", long_options, &option_index)) != EOF)
115 getopt_long (argc, argv, "c:k::gs", long_options,
116 &option_index)) != EOF)
117 { 120 {
118 switch (r) 121 switch (r)
119 { 122 {
120 case 0: /* long option */ 123 case 0: /* long option */
121 break; 124 break;
122 125
123 case 'c': /* config file */ 126 case 'c': /* config file */
124 confbase = strdup (optarg); 127 confbase = strdup (optarg);
125 break; 128 break;
126 129
127 case 'k': /* kill old gvpes */ 130 case 'k': /* kill old gvpes */
128 if (optarg) 131 if (optarg)
129 { 132 {
130 if (!strcasecmp (optarg, "HUP")) 133 if (!strcasecmp (optarg, "HUP"))
131 kill_gvpe = SIGHUP; 134 kill_gvpe = SIGHUP;
132 else if (!strcasecmp (optarg, "TERM")) 135 else if (!strcasecmp (optarg, "TERM"))
133 kill_gvpe = SIGTERM; 136 kill_gvpe = SIGTERM;
134 else if (!strcasecmp (optarg, "KILL")) 137 else if (!strcasecmp (optarg, "KILL"))
135 kill_gvpe = SIGKILL; 138 kill_gvpe = SIGKILL;
136 else if (!strcasecmp (optarg, "USR1")) 139 else if (!strcasecmp (optarg, "USR1"))
137 kill_gvpe = SIGUSR1; 140 kill_gvpe = SIGUSR1;
138 else if (!strcasecmp (optarg, "USR2")) 141 else if (!strcasecmp (optarg, "USR2"))
139 kill_gvpe = SIGUSR2; 142 kill_gvpe = SIGUSR2;
140 else if (!strcasecmp (optarg, "INT")) 143 else if (!strcasecmp (optarg, "INT"))
141 kill_gvpe = SIGINT; 144 kill_gvpe = SIGINT;
142 else if (!strcasecmp (optarg, "ALRM")) 145 else if (!strcasecmp (optarg, "ALRM"))
143 kill_gvpe = SIGALRM; 146 kill_gvpe = SIGALRM;
144 else 147 else
145 { 148 {
146 kill_gvpe = atoi (optarg); 149 kill_gvpe = atoi (optarg);
147 150
148 if (!kill_gvpe) 151 if (!kill_gvpe)
149 { 152 {
150 fprintf (stderr, 153 fprintf (stderr,
151 _ 154 _
152 ("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"),
153 optarg); 156 optarg);
154 usage (1); 157 usage (1);
155 } 158 }
156 } 159 }
157 } 160 }
158 else 161 else
159 kill_gvpe = SIGTERM; 162 kill_gvpe = SIGTERM;
160 163
161 break; 164 break;
162 165
163 case 'g': /* generate public/private keypair */ 166 case 'g': /* generate public/private keypair */
164 generate_keys = RSA_KEYBITS; 167 generate_keys = RSA_KEYBITS;
165 break; 168 break;
166 169
167 case 's': 170 case 's':
168 show_config = 1; 171 show_config = 1;
169 break; 172 break;
170 173
174 case 'q':
175 quiet = 1;
176 break;
177
171 case '?': 178 case '?':
172 usage (1); 179 usage (1);
173 180
174 default: 181 default:
175 break; 182 break;
176 } 183 }
177 } 184 }
178} 185}
179 186
180/* This function prettyprints the key generation process */ 187// this function prettyprints the key generation process
181 188static void
182void
183indicator (int a, int b, void *p) 189indicator (int a, int b, void *p)
184{ 190{
191 if (quiet)
192 return;
193
185 switch (a) 194 switch (a)
186 { 195 {
187 case 0: 196 case 0:
188 fprintf (stderr, "."); 197 fprintf (stderr, ".");
189 break; 198 break;
190 199
191 case 1: 200 case 1:
192 fprintf (stderr, "+"); 201 fprintf (stderr, "+");
193 break; 202 break;
194 203
195 case 2: 204 case 2:
196 fprintf (stderr, "-"); 205 fprintf (stderr, "-");
197 break; 206 break;
198 207
199 case 3: 208 case 3:
200 switch (b) 209 switch (b)
201 { 210 {
202 case 0: 211 case 0:
203 fprintf (stderr, " p\n"); 212 fprintf (stderr, " p\n");
204 break; 213 break;
205 214
206 case 1: 215 case 1:
207 fprintf (stderr, " q\n"); 216 fprintf (stderr, " q\n");
208 break; 217 break;
209 218
210 default: 219 default:
211 fprintf (stderr, "?"); 220 fprintf (stderr, "?");
212 } 221 }
213 break; 222 break;
214 223
215 default: 224 default:
216 fprintf (stderr, "?"); 225 fprintf (stderr, "?");
217 } 226 }
218} 227}
219 228
220/* 229/*
221 * 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.
222 */ 231 */
223int 232static int
224keygen (int bits) 233keygen (int bits)
225{ 234{
226 RSA *rsa_key; 235 RSA *rsa_key;
227 FILE *f; 236 FILE *f;
228 char *name = NULL; 237 char *name = NULL;
250 exit (EXIT_FAILURE); 259 exit (EXIT_FAILURE);
251 } 260 }
252 261
253 if (ftell (f)) 262 if (ftell (f))
254 { 263 {
264 if (!quiet)
255 fprintf (stderr, "'%s' already exists, skipping this node\n", 265 fprintf (stderr, "'%s' already exists, skipping this node %d\n",
256 fname); 266 fname, quiet);
267
257 fclose (f); 268 fclose (f);
258 continue; 269 continue;
259 } 270 }
260 271
261 fprintf (stderr, _("generating %d bits key for %s:\n"), bits, 272 fprintf (stderr, _("generating %d bits key for %s:\n"), bits,
308 { 319 {
309 printf (_("%s version %s (built %s %s, protocol version %d.%d)\n"), get_identity (), 320 printf (_("%s version %s (built %s %s, protocol version %d.%d)\n"), get_identity (),
310 VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR); 321 VERSION, __DATE__, __TIME__, PROTOCOL_MAJOR, PROTOCOL_MINOR);
311 printf (_("Built with kernel interface %s/%s.\n"), IFTYPE, IFSUBTYPE); 322 printf (_("Built with kernel interface %s/%s.\n"), IFTYPE, IFSUBTYPE);
312 printf (_ 323 printf (_
313 ("Copyright (C) 2003 Marc Lehmann <gvpe@schmorp.de> and others.\n" 324 ("Copyright (C) 2003-2008 Marc Lehmann <gvpe@schmorp.de> and others.\n"
314 "See the AUTHORS file for a complete list.\n\n" 325 "See the AUTHORS file for a complete list.\n\n"
315 "vpe comes with ABSOLUTELY NO WARRANTY. This is free software,\n" 326 "vpe comes with ABSOLUTELY NO WARRANTY. This is free software,\n"
316 "and you are welcome to redistribute it under certain conditions;\n" 327 "and you are welcome to redistribute it under certain conditions;\n"
317 "see the file COPYING for details.\n")); 328 "see the file COPYING for details.\n"));
318 329

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines