"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "pwgen.c" between
pwgen-2.07.tar.gz and pwgen-2.08.tar.gz

About: pwgen generates secure or pronounceable passwords which are designed to be easily memorized by humans, while being as secure as possible.

pwgen.c  (pwgen-2.07):pwgen.c  (pwgen-2.08)
skipping to change at line 38 skipping to change at line 38
int pwgen_flags = 0; int pwgen_flags = 0;
int do_columns = 0; int do_columns = 0;
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
struct option pwgen_options[] = { struct option pwgen_options[] = {
{ "alt-phonics", no_argument, 0, 'a' }, { "alt-phonics", no_argument, 0, 'a' },
{ "capitalize", no_argument, 0, 'c' }, { "capitalize", no_argument, 0, 'c' },
{ "numerals", no_argument, 0, 'n'}, { "numerals", no_argument, 0, 'n'},
{ "symbols", no_argument, 0, 'y'}, { "symbols", no_argument, 0, 'y'},
{ "num-passwords", required_argument, 0, 'N'}, { "num-passwords", required_argument, 0, 'N'},
{ "remove-chars", required_argument, 0, 'r' },
{ "secure", no_argument, 0, 's' }, { "secure", no_argument, 0, 's' },
{ "help", no_argument, 0, 'h'}, { "help", no_argument, 0, 'h'},
{ "no-numerals", no_argument, 0, '0' }, { "no-numerals", no_argument, 0, '0' },
{ "no-capitalize", no_argument, 0, 'A' }, { "no-capitalize", no_argument, 0, 'A' },
{ "sha1", required_argument, 0, 'H' }, { "sha1", required_argument, 0, 'H' },
{ "ambiguous", no_argument, 0, 'B' }, { "ambiguous", no_argument, 0, 'B' },
{ "no-vowels", no_argument, 0, 'v' }, { "no-vowels", no_argument, 0, 'v' },
{ 0, 0, 0, 0} { 0, 0, 0, 0}
}; };
#endif #endif
const char *pw_options = "01AaBCcnN:shH:vy"; const char *pw_options = "01AaBCcnN:sr:hH:vy";
static void usage(void) static void usage(void)
{ {
fputs("Usage: pwgen [ OPTIONS ] [ pw_length ] [ num_pw ]\n\n", stderr); fputs("Usage: pwgen [ OPTIONS ] [ pw_length ] [ num_pw ]\n\n", stderr);
fputs("Options supported by pwgen:\n", stderr); fputs("Options supported by pwgen:\n", stderr);
fputs(" -c or --capitalize\n", stderr); fputs(" -c or --capitalize\n", stderr);
fputs("\tInclude at least one capital letter in the password\n", fputs("\tInclude at least one capital letter in the password\n",
stderr); stderr);
fputs(" -A or --no-capitalize\n", stderr); fputs(" -A or --no-capitalize\n", stderr);
fputs("\tDon't include capital letters in the password\n", fputs("\tDon't include capital letters in the password\n",
stderr); stderr);
fputs(" -n or --numerals\n", stderr); fputs(" -n or --numerals\n", stderr);
fputs("\tInclude at least one number in the password\n", stderr); fputs("\tInclude at least one number in the password\n", stderr);
fputs(" -0 or --no-numerals\n", stderr); fputs(" -0 or --no-numerals\n", stderr);
fputs("\tDon't include numbers in the password\n", fputs("\tDon't include numbers in the password\n",
stderr); stderr);
fputs(" -y or --symbols\n", stderr); fputs(" -y or --symbols\n", stderr);
fputs("\tInclude at least one special symbol in the password\n", fputs("\tInclude at least one special symbol in the password\n",
stderr); stderr);
fputs(" -r <chars> or --remove-chars=<chars>\n", stderr);
fputs("\tRemove characters from the set of characters to "
"generate passwords\n", stderr);
fputs(" -s or --secure\n", stderr); fputs(" -s or --secure\n", stderr);
fputs("\tGenerate completely random passwords\n", stderr); fputs("\tGenerate completely random passwords\n", stderr);
fputs(" -B or --ambiguous\n", stderr); fputs(" -B or --ambiguous\n", stderr);
fputs("\tDon't include ambiguous characters in the password\n", fputs("\tDon't include ambiguous characters in the password\n",
stderr); stderr);
fputs(" -h or --help\n", stderr); fputs(" -h or --help\n", stderr);
fputs("\tPrint a help message\n", stderr); fputs("\tPrint a help message\n", stderr);
fputs(" -H or --sha1=path/to/file[#seed]\n", stderr); fputs(" -H or --sha1=path/to/file[#seed]\n", stderr);
fputs("\tUse sha1 hash of given file as a (not so) random generator\n", fputs("\tUse sha1 hash of given file as a (not so) random generator\n",
stderr); stderr);
skipping to change at line 94 skipping to change at line 98
stderr); stderr);
exit(1); exit(1);
} }
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int term_width = 80; int term_width = 80;
int c, i; int c, i;
int num_cols = -1; int num_cols = -1;
char *buf, *tmp; char *buf, *tmp;
void (*pwgen)(char *inbuf, int size, int pw_flags); char *remove=NULL;
void (*pwgen)(char *inbuf, int size, int pw_flags, char *remove);
pwgen = pw_phonemes; pwgen = pw_phonemes;
pw_number = pw_random_number; pw_number = pw_random_number;
if (isatty(1)) if (isatty(1))
do_columns = 1; do_columns = 1;
pwgen_flags |= PW_DIGITS | PW_UPPERS; pwgen_flags |= PW_DIGITS | PW_UPPERS;
while (1) { while (1) {
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
c = getopt_long(argc, argv, pw_options, pwgen_options, 0); c = getopt_long(argc, argv, pw_options, pwgen_options, 0);
skipping to change at line 139 skipping to change at line 144
num_pw = strtol(optarg, &tmp, 0); num_pw = strtol(optarg, &tmp, 0);
if (*tmp) { if (*tmp) {
fprintf(stderr, fprintf(stderr,
"Invalid number of passwords: %s\n", "Invalid number of passwords: %s\n",
optarg); optarg);
exit(1); exit(1);
} }
break; break;
case 's': case 's':
pwgen = pw_rand; pwgen = pw_rand;
pwgen_flags = PW_DIGITS | PW_UPPERS;
break; break;
case 'C': case 'C':
do_columns = 1; do_columns = 1;
break; break;
case '1': case '1':
do_columns = 0; do_columns = 0;
break; break;
case 'H': case 'H':
pw_sha1_init(optarg); pw_sha1_init(optarg);
pw_number = pw_sha1_number; pw_number = pw_sha1_number;
break; break;
case 'y': case 'y':
pwgen_flags |= PW_SYMBOLS; pwgen_flags |= PW_SYMBOLS;
break; break;
case 'v': case 'v':
pwgen = pw_rand; pwgen = pw_rand;
pwgen_flags |= PW_NO_VOWELS | PW_DIGITS | PW_UPPERS; pwgen_flags |= PW_NO_VOWELS;
break;
case 'r':
remove = strdup(optarg);
pwgen = pw_rand;
break; break;
case 'h': case 'h':
case '?': case '?':
usage(); usage();
break; break;
} }
} }
if (optind < argc) { if (optind < argc) {
pw_length = strtol(argv[optind], &tmp, 0); pw_length = strtol(argv[optind], &tmp, 0);
if (pw_length < 5) if (pw_length < 5)
pwgen = pw_rand; pwgen = pw_rand;
if (pw_length <= 2) if (pwgen != pw_rand) {
pwgen_flags &= ~PW_UPPERS; if (pw_length <= 2)
if (pw_length <= 1) pwgen_flags &= ~PW_UPPERS;
pwgen_flags &= ~PW_DIGITS; if (pw_length <= 1)
pwgen_flags &= ~PW_DIGITS;
}
if (*tmp) { if (*tmp) {
fprintf(stderr, "Invalid password length: %s\n", fprintf(stderr, "Invalid password length: %s\n",
argv[optind]); argv[optind]);
exit(1); exit(1);
} }
optind++; optind++;
} }
if (optind < argc) { if (optind < argc) {
num_pw = strtol(argv[optind], &tmp, 0); num_pw = strtol(argv[optind], &tmp, 0);
skipping to change at line 203 skipping to change at line 213
} }
if (num_pw < 0) if (num_pw < 0)
num_pw = do_columns ? num_cols * 20 : 1; num_pw = do_columns ? num_cols * 20 : 1;
buf = malloc(pw_length+1); buf = malloc(pw_length+1);
if (!buf) { if (!buf) {
fprintf(stderr, "Couldn't malloc password buffer.\n"); fprintf(stderr, "Couldn't malloc password buffer.\n");
exit(1); exit(1);
} }
for (i=0; i < num_pw; i++) { for (i=0; i < num_pw; i++) {
pwgen(buf, pw_length, pwgen_flags); pwgen(buf, pw_length, pwgen_flags, remove);
if (!do_columns || ((i % num_cols) == (num_cols-1))) if (!do_columns || ((i % num_cols) == (num_cols-1)) ||
(i == (num_pw - 1)))
printf("%s\n", buf); printf("%s\n", buf);
else else
printf("%s ", buf); printf("%s ", buf);
} }
if ((num_cols > 1) && ((i % num_cols) != 0))
fputc('\n', stdout);
free(buf); free(buf);
return 0; return 0;
} }
 End of changes. 9 change blocks. 
12 lines changed or deleted 21 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)