diff options
author | Marco d'Itri <md@linux.it> | 2005-09-11 16:04:48 +0200 |
---|---|---|
committer | Marco d'Itri <md@linux.it> | 2013-03-30 02:31:32 +0100 |
commit | 9ad7ad696c3bfd7086b453ee07305ceedeeb0a4e (patch) | |
tree | 19a4fc0b06c12acbbc22923fbc52404173c98e2f /mkpasswd.c | |
parent | 8d33311a6803e9d3f0ab8509c8bae686f2ff2d2f (diff) | |
download | whois-9ad7ad696c3bfd7086b453ee07305ceedeeb0a4e.tar.gz |
Imported Debian version 4.7.7v4.7.7
Diffstat (limited to 'mkpasswd.c')
-rw-r--r-- | mkpasswd.c | 35 |
1 files changed, 29 insertions, 6 deletions
@@ -45,18 +45,24 @@ static char valid_salts[] = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./"; struct salt_prefix { - const char *algo; - const char *prefix; - unsigned int len; - const char *desc; + const char *algo; /* short name used by the command line option */ + const char *prefix; /* salt prefix */ + unsigned int len; /* salt lenght */ + const char *desc; /* long description for the algorithms list */ }; struct salt_prefix salt_prefixes[] = { { "des", "", 2, N_("\tstandard 56 bit DES-based crypt(3)") }, { "md5", "$1$", 8, "\tMD5" }, +/* untested! is the salt correctly generated? */ #if defined OpenBSD || defined FreeBSD { "blf", "$2$", 16, "\tBlowfish" }, #endif +/* untested too, and does not even compile */ +#if defined HAVE_XCRYPT + { "blf", "$2a$", 16, "\tBlowfish" }, + { "sha", "{SHA}", , "\tSHA-1" }, +#endif { NULL, NULL, 0, NULL } }; @@ -160,8 +166,18 @@ int main(int argc, char *argv[]) exit(1); } } else { +#ifdef HAVE_XCRYPT + char *entropy = gather_entropy(4096); + salt = crypt_gensalt(salt_prefix, 0, entropy, 4096); + if (!salt) { + perror("crypt"); + exit(2); + } + free(entropy); +#else salt = malloc(salt_len + 1); generate_salt(salt, salt_len); +#endif } if (!password) { @@ -206,16 +222,22 @@ int main(int argc, char *argv[]) } { - char *pw; + char *pw, *result; pw = malloc(strlen(salt_prefix) + strlen(salt) + 1); *pw = '\0'; strcat(pw, salt_prefix); strcat(pw, salt); - printf("%s\n", crypt(password, pw)); + result = crypt(password, pw); + if (!result) { + perror("crypt"); + exit(2); + } + printf("%s\n", result); } exit(0); } +#ifndef HAVE_XCRYPT void generate_salt(char *buf, const unsigned int len) { unsigned int i; @@ -225,6 +247,7 @@ void generate_salt(char *buf, const unsigned int len) buf[i] = valid_salts[rand() % (sizeof valid_salts - 1)]; buf[i] = '\0'; } +#endif void display_help(void) { |