mirror of
https://github.com/rfc1036/whois.git
synced 2026-05-03 06:51:09 +00:00
mkpasswd: use perror with crypt and crypt_gensalt
Only some implementations of crypt(3) set errno on errors.
This commit is contained in:
parent
5fc64b5eba
commit
8392fd349d
7
config.h
7
config.h
@ -95,6 +95,13 @@
|
|||||||
# define HAVE_GETENTROPY
|
# define HAVE_GETENTROPY
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* some versions of crypt(3) set errno on error */
|
||||||
|
#if defined __GLIBC__ || (defined __SVR4 && defined __sun) || defined OpenBSD || AIX
|
||||||
|
# define CRYPT_SETS_ERRNO 1
|
||||||
|
#else
|
||||||
|
# define CRYPT_SETS_ERRNO 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_NLS
|
#ifdef ENABLE_NLS
|
||||||
# ifndef NLS_CAT_NAME
|
# ifndef NLS_CAT_NAME
|
||||||
# define NLS_CAT_NAME "whois"
|
# define NLS_CAT_NAME "whois"
|
||||||
|
|||||||
13
mkpasswd.c
13
mkpasswd.c
@ -283,16 +283,16 @@ int main(int argc, char *argv[])
|
|||||||
#ifdef HAVE_SOLARIS_CRYPT_GENSALT
|
#ifdef HAVE_SOLARIS_CRYPT_GENSALT
|
||||||
salt = crypt_gensalt(salt_prefix, NULL);
|
salt = crypt_gensalt(salt_prefix, NULL);
|
||||||
if (!salt) {
|
if (!salt) {
|
||||||
perror("crypt_gensalt");
|
perror("crypt_gensalt");
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
#elif defined HAVE_LINUX_CRYPT_GENSALT
|
#elif defined HAVE_LINUX_CRYPT_GENSALT
|
||||||
void *entropy = get_random_bytes(64);
|
void *entropy = get_random_bytes(64);
|
||||||
|
|
||||||
salt = crypt_gensalt(salt_prefix, rounds, entropy, 64);
|
salt = crypt_gensalt(salt_prefix, rounds, entropy, 64);
|
||||||
if (!salt) {
|
if (!salt) {
|
||||||
fprintf(stderr, "crypt_gensalt failed.\n");
|
perror("crypt_gensalt");
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
free(entropy);
|
free(entropy);
|
||||||
#else
|
#else
|
||||||
@ -342,7 +342,10 @@ int main(int argc, char *argv[])
|
|||||||
result = crypt(password, salt);
|
result = crypt(password, salt);
|
||||||
/* xcrypt returns "*0" on errors */
|
/* xcrypt returns "*0" on errors */
|
||||||
if (!result || result[0] == '*') {
|
if (!result || result[0] == '*') {
|
||||||
fprintf(stderr, "crypt failed.\n");
|
if (CRYPT_SETS_ERRNO)
|
||||||
|
perror("crypt");
|
||||||
|
else
|
||||||
|
fprintf(stderr, "crypt failed.\n");
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
/* yes, using strlen(salt_prefix) on salt. It's not
|
/* yes, using strlen(salt_prefix) on salt. It's not
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user