mkpasswd: use readpassphrase(3) if available

This commit is contained in:
Marco d'Itri 2025-06-21 01:34:43 +02:00
parent b64054961d
commit 6e74da05d1
No known key found for this signature in database
GPG Key ID: CB3EC33AE1DED781
2 changed files with 19 additions and 0 deletions

View File

@ -26,12 +26,17 @@
/* which versions? */
# define HAVE_GETOPT_LONG
# define HAVE_GETADDRINFO
# define HAVE_READPASSPHRASE
# define ENABLE_NLS
# ifndef LOCALEDIR
# define LOCALEDIR "/usr/local/share/locale"
# endif
#endif
#if defined OpenBSD
# define HAVE_READPASSPHRASE
#endif
/* needs unistd.h */
#if defined _POSIX_C_SOURCE && _POSIX_C_SOURCE >= 200112L
# define HAVE_GETADDRINFO
@ -41,6 +46,7 @@
#if defined __APPLE__ && defined __MACH__
# define HAVE_GETOPT_LONG
# define HAVE_GETADDRINFO
# define HAVE_READPASSPHRASE
# define HAVE_BSDICRYPT
#endif

View File

@ -47,6 +47,9 @@
#ifdef HAVE_GETTIMEOFDAY
#include <sys/time.h>
#endif
#ifdef HAVE_READPASSPHRASE
#include <readpassphrase.h>
#endif
/* Application-specific */
#include "version.h"
@ -387,11 +390,21 @@ int main(int argc, char *argv[])
exit(2);
}
} else {
#ifdef HAVE_READPASSPHRASE
const size_t size = 128;
password = NOFAIL(malloc(size));
if (!readpassphrase(_("Password: "), password, size, 0)) {
perror("readpassphrase");
exit(2);
}
#else
password = getpass(_("Password: "));
if (!password) {
perror("getpass");
exit(2);
}
#endif
}
{