X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fgenauth.c;h=1d2645760375358f5d9ae8a7e718c6bd19693c82;hp=23f9770ae9e74b92ef00147b34ee4cead54c659b;hb=8cb4bb619d777022a55255c5fa17a1a55a270ff3;hpb=210a92cae90deb5b4a410b1b7d5c625c5c5f2ffb diff --git a/src/genauth.c b/src/genauth.c index 23f9770a..1d264576 100644 --- a/src/genauth.c +++ b/src/genauth.c @@ -1,6 +1,6 @@ /* genauth.c -- generate a random passphrase - Copyright (C) 1998,99 Ivo Timmermans + Copyright (C) 1998,1999,2000 Ivo Timmermans This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -15,6 +15,8 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + $Id: genauth.c,v 1.7 2000/05/31 18:21:27 zarq Exp $ */ #include "config.h" @@ -27,6 +29,8 @@ #include "encr.h" +#include "system.h" + unsigned char initvec[] = { 0x22, 0x7b, 0xad, 0x55, 0x41, 0xf4, 0x3e, 0xf3 }; int main(int argc, char **argv) @@ -35,25 +39,32 @@ int main(int argc, char **argv) int bits, c, i, bytes; unsigned char *p; - if(argc != 2) + setlocale (LC_ALL, ""); + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); + + if(argc > 2 || (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")))) { - fprintf(stderr, "Usage: %s bits\n", argv[0]); + fprintf(stderr, _("Usage: %s bits\n"), argv[0]); return 1; } + if(!argv[1]) + argv[1] = "1024"; + if(!(bits = atol(argv[1]))) { - fprintf(stderr, "Illegal number: %s\n", argv[1]); + fprintf(stderr, _("Illegal number: %s\n"), argv[1]); return 1; } bits = ((bits - 1) | 63) + 1; - fprintf(stderr, "Generating %d bits number", bits); + fprintf(stderr, _("Generating %d bits number"), bits); bytes = bits >> 3; if((fp = fopen("/dev/urandom", "r")) == NULL) { - perror("Opening /dev/urandom"); + perror(_("Opening /dev/urandom")); return 1; } @@ -66,17 +77,28 @@ int main(int argc, char **argv) if(feof(fp)) { puts(""); - fprintf(stderr, "File was empty!\n"); + fprintf(stderr, _("File was empty!\n")); } p[i] = c; } fclose(fp); - printf("%d ", bits); - for(i = 0; i < bytes; i++) - printf("%02x", p[i]); - puts(""); - fprintf(stderr, ": done.\n"); + if(isatty(1)) + { + fprintf(stderr, _(": done.\nThe following line should be ENTIRELY copied into a passphrase file:\n")); + printf("%d ", bits); + for(i = 0; i < bytes; i++) + printf("%02x", p[i]); + puts(""); + } + else + { + printf("%d ", bits); + for(i = 0; i < bytes; i++) + printf("%02x", p[i]); + puts(""); + fprintf(stderr, _(": done.\n")); + } return 0; }