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-2013 Marc Lehmann <gvpe@schmorp.de> |
5 | 2003-2016 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 it |
9 | GVPE is free software; you can redistribute it and/or modify it |
10 | under the terms of the GNU General Public License as published by the |
10 | under the terms of the GNU General Public License as published by the |
… | |
… | |
246 | * generate public/private RSA keypairs for all hosts that don't have one. |
246 | * generate public/private RSA keypairs for all hosts that don't have one. |
247 | */ |
247 | */ |
248 | static int |
248 | static int |
249 | keygen (const char *pub, const char *priv) |
249 | keygen (const char *pub, const char *priv) |
250 | { |
250 | { |
|
|
251 | /* some libcs are buggy and require an extra seek to the end */ |
251 | |
252 | |
252 | FILE *pubf = fopen (pub, "ab"); |
253 | FILE *pubf = fopen (pub, "ab"); |
253 | if (!pubf || fseek (pubf, 0, SEEK_END)) |
254 | if (!pubf || fseek (pubf, 0, SEEK_END)) |
254 | { |
255 | { |
255 | perror (pub); |
256 | perror (pub); |
… | |
… | |
261 | fclose (pubf); |
262 | fclose (pubf); |
262 | return 1; |
263 | return 1; |
263 | } |
264 | } |
264 | |
265 | |
265 | FILE *privf = fopen (priv, "ab"); |
266 | FILE *privf = fopen (priv, "ab"); |
266 | |
|
|
267 | /* some libcs are buggy and require an extra seek to the end */ |
|
|
268 | if (!privf || fseek (privf, 0, SEEK_END)) |
267 | if (!privf || fseek (privf, 0, SEEK_END)) |
269 | { |
268 | { |
270 | perror (priv); |
269 | perror (priv); |
271 | exit (EXIT_FAILURE); |
270 | exit (EXIT_FAILURE); |
272 | } |
271 | } |
… | |
… | |
347 | static int |
346 | static int |
348 | keygen_one (const char *pubname) |
347 | keygen_one (const char *pubname) |
349 | { |
348 | { |
350 | char *privname; |
349 | char *privname; |
351 | |
350 | |
352 | asprintf (&privname, "%s.key", pubname); |
351 | asprintf (&privname, "%s.privkey", pubname); |
353 | |
352 | |
354 | int status = keygen (pubname, privname); |
353 | int status = keygen (pubname, privname); |
355 | |
354 | |
356 | if (status == 0) |
355 | if (status == 0) |
357 | { |
356 | { |
… | |
… | |
362 | { |
361 | { |
363 | fprintf (stderr, _("'%s' keypair already exists, not generating key.\n"), pubname); |
362 | fprintf (stderr, _("'%s' keypair already exists, not generating key.\n"), pubname); |
364 | exit (EXIT_FAILURE); |
363 | exit (EXIT_FAILURE); |
365 | } |
364 | } |
366 | |
365 | |
367 | free(privname); |
366 | free (privname); |
|
|
367 | |
|
|
368 | return 0; |
368 | } |
369 | } |
369 | |
370 | |
370 | int |
371 | int |
371 | main (int argc, char **argv, char **envp) |
372 | main (int argc, char **argv, char **envp) |
372 | { |
373 | { |