… | |
… | |
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> |
26 | #include <clocale> |
27 | #include <clocale> |
27 | |
28 | |
28 | #include <errno.h> |
29 | #include <errno.h> |
29 | #include <fcntl.h> |
30 | #include <fcntl.h> |
30 | #include <getopt.h> |
31 | #include <getopt.h> |
… | |
… | |
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; |
… | |
… | |
325 | exit (kill_other (kill_vped)); |
326 | exit (kill_other (kill_vped)); |
326 | |
327 | |
327 | if (show_config) |
328 | if (show_config) |
328 | { |
329 | { |
329 | conf.print (); |
330 | conf.print (); |
330 | exit (0); |
331 | exit (EXIT_SUCCESS); |
331 | } |
332 | } |
332 | |
333 | |
333 | usage (1); |
334 | usage (1); |
334 | } |
335 | } |