diff options
| author | Philipp Klaus <philipp.klaus@gmail.com> | 2011-06-21 17:12:21 +0200 |
|---|---|---|
| committer | Philipp Klaus <philipp.klaus@gmail.com> | 2011-06-21 17:12:21 +0200 |
| commit | 1832804a4c6771ff86fba6064a6fb575524b64ef (patch) | |
| tree | b931fdc1bb0692e5a3d145ceebc982e4d5d85d0f /pwgen.c | |
| parent | a067bd488fb1ad0ce4818c6601031554397c1d80 (diff) | |
| download | pwgen-1832804a4c6771ff86fba6064a6fb575524b64ef.zip | |
automatic commit for pwgen-2.04
Diffstat (limited to 'pwgen.c')
| -rw-r--r-- | pwgen.c | 96 |
1 files changed, 62 insertions, 34 deletions
@@ -18,18 +18,14 @@ #include "pwgen.h" -struct pwgen_func generators[] = { - { "phonemes", pw_phonemes, 0 }, - { "rand", pw_rand, 0 }, - { 0, 0, 0 } -}; +/* Globals variables */ +int (*pw_number)(int max_num); /* Program parameters set via getopt */ int pw_length = 8; int num_pw = -1; -int case_flag = 0; -int numeric_flag = 0; +int pwgen_flags = 0; int do_columns = 0; #ifdef HAVE_GETOPT_LONG @@ -37,35 +33,51 @@ struct option pwgen_options[] = { { "alt-phonics", no_argument, 0, 'a' }, { "capitalize", no_argument, 0, 'c' }, { "numerals", no_argument, 0, 'n'}, + { "symbols", no_argument, 0, 'y'}, { "num-passwords", required_argument, 0, 'N'}, { "secure", no_argument, 0, 's' }, { "help", no_argument, 0, 'h'}, - { "no-numerals", no_argument, &numeric_flag, 0 }, - { "no-capitalize", no_argument, &case_flag, 0 }, + { "no-numerals", no_argument, 0, '0' }, + { "no-capitalize", no_argument, 0, 'A' }, + { "sha1", required_argument, 0, 'H' }, + { "ambiguous", no_argument, 0, 'B' }, { 0, 0, 0, 0} }; #endif -const char *usage_msg = -"Usage: pwgen [ OPTIONS ] [ pw_length ] [ num_pw ]\n\n" -"Options supported by pwgen:\n" -" -c or -capitalize\n" -"\tInclude at least one capital letter in the password\n" -" -n or --numerals\n" -"\tInclude at least one number in the password\n" -" -s or --secure\n" -"\tGenerate completely random passwords\n" -" -h or --help\n" -"\tPrint a help message\n" -" --no-numerals, --no-capitalize\n" -"\tDon't include a number or capital letter in the password\n" -" -C\n\tPrint the generated passwords in columns\n" -" -1\n\tDon't print the generated passwords in columns\n" -; - +const char *pw_options = "01AaBCcnN:shH:y"; + static void usage(void) { - fprintf(stderr, usage_msg); + fputs("Usage: pwgen [ OPTIONS ] [ pw_length ] [ num_pw ]\n\n", stderr); + fputs("Options supported by pwgen:\n", stderr); + fputs(" -c or --capitalize\n", stderr); + fputs("\tInclude at least one capital letter in the password\n", + stderr); + fputs(" -A or --no-capitalize\n", stderr); + fputs("\tDon't include capital letters in the password\n", + stderr); + fputs(" -n or --numerals\n", stderr); + fputs("\tInclude at least one number in the password\n", stderr); + fputs(" -0 or --no-numerals\n", stderr); + fputs("\tDon't include numbers in the password\n", + stderr); + fputs(" -y or --symbols\n", stderr); + fputs("\tInclude at least one special symbol in the password\n", + stderr); + fputs(" -s or --secure\n", stderr); + fputs("\tGenerate completely random passwords\n", stderr); + fputs(" -B or --ambiguous\n", stderr); + fputs("\tDon't include ambiguous characters in the password\n", + stderr); + fputs(" -h or --help\n", stderr); + fputs("\tPrint a help message\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", + stderr); + fputs(" -C\n\tPrint the generated passwords in columns\n", stderr); + fputs(" -1\n\tDon't print the generated passwords in columns\n", + stderr); exit(1); } @@ -79,28 +91,37 @@ int main(int argc, char **argv) void (*pwgen)(char *inbuf, int size, int pw_flags); pwgen = pw_phonemes; + pw_number = pw_random_number; if (isatty(1)) { do_columns = 1; - case_flag = PW_ONE_CASE; - numeric_flag = PW_ONE_NUMBER; + pwgen_flags |= PW_DIGITS | PW_UPPERS; } while (1) { #ifdef HAVE_GETOPT_LONG - c = getopt_long(argc, argv, "1aCcnN:sh", pwgen_options, 0); + c = getopt_long(argc, argv, pw_options, pwgen_options, 0); #else - c = getopt(argc, argv, "1aCcnN:sh"); + c = getopt(argc, argv, pw_options); #endif if (c == -1) break; switch (c) { + case '0': + pwgen_flags &= ~PW_DIGITS; + break; + case 'A': + pwgen_flags &= ~PW_UPPERS; + break; case 'a': break; + case 'B': + pwgen_flags |= PW_AMBIGUOUS; + break; case 'c': - case_flag = PW_ONE_CASE; + pwgen_flags |= PW_UPPERS; break; case 'n': - numeric_flag = PW_ONE_NUMBER; + pwgen_flags |= PW_DIGITS; break; case 'N': num_pw = strtol(optarg, &tmp, 0); @@ -120,6 +141,13 @@ int main(int argc, char **argv) case '1': do_columns = 0; break; + case 'H': + pw_sha1_init(optarg); + pw_number = pw_sha1_number; + break; + case 'y': + pwgen_flags |= PW_SYMBOLS; + break; case 'h': case '?': usage(); @@ -161,7 +189,7 @@ int main(int argc, char **argv) exit(1); } for (i=0; i < num_pw; i++) { - pwgen(buf, pw_length, case_flag | numeric_flag); + pwgen(buf, pw_length, pwgen_flags); if (!do_columns || ((i % num_cols) == (num_cols-1))) printf("%s\n", buf); else |