Replace the deprecated getpass(3) by our agetpass()

getpass(3) is broken in all implementations; in some, more than
others, but somewhat broken in all of them.  Check the immediate
previous commit, which added the functions, for more details.
Check also the Linux man-pages commit that marked it as
deprecated, for more details:
7ca189099d73bde954eed2d7fc21732bcc8ddc6b.

Link: <https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit?id=7ca189099d73bde954eed2d7fc21732bcc8ddc6b>
Reported-by: Christian Göttsche <cgzones@googlemail.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
Alejandro Colomar 2022-09-27 21:21:35 +02:00 committed by Iker Pedrosa
parent 155c9421b9
commit 554f86bafa
4 changed files with 21 additions and 18 deletions

View File

@ -887,24 +887,24 @@ static void change_passwd (struct group *gr)
printf (_("Changing the password for group %s\n"), group); printf (_("Changing the password for group %s\n"), group);
for (retries = 0; retries < RETRIES; retries++) { for (retries = 0; retries < RETRIES; retries++) {
cp = getpass (_("New Password: ")); cp = agetpass (_("New Password: "));
if (NULL == cp) { if (NULL == cp) {
exit (1); exit (1);
} }
STRFCPY (pass, cp); STRFCPY (pass, cp);
strzero (cp); erase_pass (cp);
cp = getpass (_("Re-enter new password: ")); cp = agetpass (_("Re-enter new password: "));
if (NULL == cp) { if (NULL == cp) {
exit (1); exit (1);
} }
if (strcmp (pass, cp) == 0) { if (strcmp (pass, cp) == 0) {
strzero (cp); erase_pass (cp);
break; break;
} }
strzero (cp); erase_pass (cp);
memzero (pass, sizeof pass); memzero (pass, sizeof pass);
if (retries + 1 < RETRIES) { if (retries + 1 < RETRIES) {

View File

@ -158,7 +158,7 @@ static void check_perms (const struct group *grp,
* get the password from her, and set the salt for * get the password from her, and set the salt for
* the decryption from the group file. * the decryption from the group file.
*/ */
cp = getpass (_("Password: ")); cp = agetpass (_("Password: "));
if (NULL == cp) { if (NULL == cp) {
goto failure; goto failure;
} }
@ -169,7 +169,7 @@ static void check_perms (const struct group *grp,
* must match the previously encrypted value in the file. * must match the previously encrypted value in the file.
*/ */
cpasswd = pw_encrypt (cp, grp->gr_passwd); cpasswd = pw_encrypt (cp, grp->gr_passwd);
strzero (cp); erase_pass (cp);
if (NULL == cpasswd) { if (NULL == cpasswd) {
fprintf (stderr, fprintf (stderr,

View File

@ -186,7 +186,7 @@ static int new_password (const struct passwd *pw)
char *clear; /* Pointer to clear text */ char *clear; /* Pointer to clear text */
char *cipher; /* Pointer to cipher text */ char *cipher; /* Pointer to cipher text */
const char *salt; /* Pointer to new salt */ const char *salt; /* Pointer to new salt */
char *cp; /* Pointer to getpass() response */ char *cp; /* Pointer to agetpass() response */
char orig[200]; /* Original password */ char orig[200]; /* Original password */
char pass[200]; /* New password */ char pass[200]; /* New password */
int i; /* Counter for retries */ int i; /* Counter for retries */
@ -204,7 +204,7 @@ static int new_password (const struct passwd *pw)
*/ */
if (!amroot && ('\0' != crypt_passwd[0])) { if (!amroot && ('\0' != crypt_passwd[0])) {
clear = getpass (_("Old password: ")); clear = agetpass (_("Old password: "));
if (NULL == clear) { if (NULL == clear) {
return -1; return -1;
} }
@ -212,7 +212,7 @@ static int new_password (const struct passwd *pw)
cipher = pw_encrypt (clear, crypt_passwd); cipher = pw_encrypt (clear, crypt_passwd);
if (NULL == cipher) { if (NULL == cipher) {
strzero (clear); erase_pass (clear);
fprintf (stderr, fprintf (stderr,
_("%s: failed to crypt password with previous salt: %s\n"), _("%s: failed to crypt password with previous salt: %s\n"),
Prog, strerror (errno)); Prog, strerror (errno));
@ -223,7 +223,7 @@ static int new_password (const struct passwd *pw)
} }
if (strcmp (cipher, crypt_passwd) != 0) { if (strcmp (cipher, crypt_passwd) != 0) {
strzero (clear); erase_pass (clear);
strzero (cipher); strzero (cipher);
SYSLOG ((LOG_WARN, "incorrect password for %s", SYSLOG ((LOG_WARN, "incorrect password for %s",
pw->pw_name)); pw->pw_name));
@ -234,7 +234,7 @@ static int new_password (const struct passwd *pw)
return -1; return -1;
} }
STRFCPY (orig, clear); STRFCPY (orig, clear);
strzero (clear); erase_pass (clear);
strzero (cipher); strzero (cipher);
} else { } else {
orig[0] = '\0'; orig[0] = '\0';
@ -286,7 +286,7 @@ static int new_password (const struct passwd *pw)
warned = false; warned = false;
for (i = getdef_num ("PASS_CHANGE_TRIES", 5); i > 0; i--) { for (i = getdef_num ("PASS_CHANGE_TRIES", 5); i > 0; i--) {
cp = getpass (_("New password: ")); cp = agetpass (_("New password: "));
if (NULL == cp) { if (NULL == cp) {
memzero (orig, sizeof orig); memzero (orig, sizeof orig);
memzero (pass, sizeof pass); memzero (pass, sizeof pass);
@ -296,7 +296,7 @@ static int new_password (const struct passwd *pw)
warned = false; warned = false;
} }
STRFCPY (pass, cp); STRFCPY (pass, cp);
strzero (cp); erase_pass (cp);
if (!amroot && (!obscure (orig, pass, pw) || reuse (pass, pw))) { if (!amroot && (!obscure (orig, pass, pw) || reuse (pass, pw))) {
(void) puts (_("Try again.")); (void) puts (_("Try again."));
@ -314,16 +314,17 @@ static int new_password (const struct passwd *pw)
warned = true; warned = true;
continue; continue;
} }
cp = getpass (_("Re-enter new password: ")); cp = agetpass (_("Re-enter new password: "));
if (NULL == cp) { if (NULL == cp) {
memzero (orig, sizeof orig); memzero (orig, sizeof orig);
memzero (pass, sizeof pass); memzero (pass, sizeof pass);
return -1; return -1;
} }
if (strcmp (cp, pass) != 0) { if (strcmp (cp, pass) != 0) {
erase_pass (cp);
(void) fputs (_("They don't match; try again.\n"), stderr); (void) fputs (_("They don't match; try again.\n"), stderr);
} else { } else {
strzero (cp); erase_pass (cp);
break; break;
} }
} }

View File

@ -182,7 +182,7 @@ static void catch_signals (unused int sig)
*/ */
/* get a password for root */ /* get a password for root */
cp = getpass (_( cp = agetpass (_(
"\n" "\n"
"Type control-d to proceed with normal startup,\n" "Type control-d to proceed with normal startup,\n"
"(or give root password for system maintenance):")); "(or give root password for system maintenance):"));
@ -193,6 +193,7 @@ static void catch_signals (unused int sig)
* --marekm * --marekm
*/ */
if ((NULL == cp) || ('\0' == *cp)) { if ((NULL == cp) || ('\0' == *cp)) {
erase_pass (cp);
#ifdef USE_SYSLOG #ifdef USE_SYSLOG
SYSLOG (LOG_INFO, "Normal startup\n"); SYSLOG (LOG_INFO, "Normal startup\n");
closelog (); closelog ();
@ -204,7 +205,8 @@ static void catch_signals (unused int sig)
exit (0); exit (0);
} }
STRFCPY (pass, cp); STRFCPY (pass, cp);
strzero (cp); erase_pass (cp);
if (valid (pass, &pwent)) { /* check encrypted passwords ... */ if (valid (pass, &pwent)) { /* check encrypted passwords ... */
break; /* ... encrypted passwords matched */ break; /* ... encrypted passwords matched */
} }