]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Replace the deprecated getpass(3) by our agetpass()
authorAlejandro Colomar <alx@kernel.org>
Tue, 27 Sep 2022 19:21:35 +0000 (21:21 +0200)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Mon, 5 Dec 2022 09:47:19 +0000 (10:47 +0100)
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>
src/gpasswd.c
src/newgrp.c
src/passwd.c
src/sulogin.c

index 5983f787984d852a4361db909ac5a8a62eb2789a..b372de4734a7bc9f806e4b91e740ae46e039ca78 100644 (file)
@@ -887,24 +887,24 @@ static void change_passwd (struct group *gr)
        printf (_("Changing the password for group %s\n"), group);
 
        for (retries = 0; retries < RETRIES; retries++) {
-               cp = getpass (_("New Password: "));
+               cp = agetpass (_("New Password: "));
                if (NULL == cp) {
                        exit (1);
                }
 
                STRFCPY (pass, cp);
-               strzero (cp);
-               cp = getpass (_("Re-enter new password: "));
+               erase_pass (cp);
+               cp = agetpass (_("Re-enter new password: "));
                if (NULL == cp) {
                        exit (1);
                }
 
                if (strcmp (pass, cp) == 0) {
-                       strzero (cp);
+                       erase_pass (cp);
                        break;
                }
 
-               strzero (cp);
+               erase_pass (cp);
                memzero (pass, sizeof pass);
 
                if (retries + 1 < RETRIES) {
index 9982083214427d5dced19470875fcf214128787c..966c25dd32ee29717e57e963d6bb8b32312cdd34 100644 (file)
@@ -158,7 +158,7 @@ static void check_perms (const struct group *grp,
                 * get the password from her, and set the salt for
                 * the decryption from the group file.
                 */
-               cp = getpass (_("Password: "));
+               cp = agetpass (_("Password: "));
                if (NULL == cp) {
                        goto failure;
                }
@@ -169,7 +169,7 @@ static void check_perms (const struct group *grp,
                 * must match the previously encrypted value in the file.
                 */
                cpasswd = pw_encrypt (cp, grp->gr_passwd);
-               strzero (cp);
+               erase_pass (cp);
 
                if (NULL == cpasswd) {
                        fprintf (stderr,
index 8c6f81a9175e77b0feef8f35a53977020b714c60..c729a14a1d6130aa3b24326d75f89992130657be 100644 (file)
@@ -186,7 +186,7 @@ static int new_password (const struct passwd *pw)
        char *clear;            /* Pointer to clear text */
        char *cipher;           /* Pointer to cipher text */
        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 pass[200];         /* New password */
        int i;                  /* Counter for retries */
@@ -204,7 +204,7 @@ static int new_password (const struct passwd *pw)
         */
 
        if (!amroot && ('\0' != crypt_passwd[0])) {
-               clear = getpass (_("Old password: "));
+               clear = agetpass (_("Old password: "));
                if (NULL == clear) {
                        return -1;
                }
@@ -212,7 +212,7 @@ static int new_password (const struct passwd *pw)
                cipher = pw_encrypt (clear, crypt_passwd);
 
                if (NULL == cipher) {
-                       strzero (clear);
+                       erase_pass (clear);
                        fprintf (stderr,
                                 _("%s: failed to crypt password with previous salt: %s\n"),
                                 Prog, strerror (errno));
@@ -223,7 +223,7 @@ static int new_password (const struct passwd *pw)
                }
 
                if (strcmp (cipher, crypt_passwd) != 0) {
-                       strzero (clear);
+                       erase_pass (clear);
                        strzero (cipher);
                        SYSLOG ((LOG_WARN, "incorrect password for %s",
                                 pw->pw_name));
@@ -234,7 +234,7 @@ static int new_password (const struct passwd *pw)
                        return -1;
                }
                STRFCPY (orig, clear);
-               strzero (clear);
+               erase_pass (clear);
                strzero (cipher);
        } else {
                orig[0] = '\0';
@@ -286,7 +286,7 @@ static int new_password (const struct passwd *pw)
 
        warned = false;
        for (i = getdef_num ("PASS_CHANGE_TRIES", 5); i > 0; i--) {
-               cp = getpass (_("New password: "));
+               cp = agetpass (_("New password: "));
                if (NULL == cp) {
                        memzero (orig, sizeof orig);
                        memzero (pass, sizeof pass);
@@ -296,7 +296,7 @@ static int new_password (const struct passwd *pw)
                        warned = false;
                }
                STRFCPY (pass, cp);
-               strzero (cp);
+               erase_pass (cp);
 
                if (!amroot && (!obscure (orig, pass, pw) || reuse (pass, pw))) {
                        (void) puts (_("Try again."));
@@ -314,16 +314,17 @@ static int new_password (const struct passwd *pw)
                        warned = true;
                        continue;
                }
-               cp = getpass (_("Re-enter new password: "));
+               cp = agetpass (_("Re-enter new password: "));
                if (NULL == cp) {
                        memzero (orig, sizeof orig);
                        memzero (pass, sizeof pass);
                        return -1;
                }
                if (strcmp (cp, pass) != 0) {
+                       erase_pass (cp);
                        (void) fputs (_("They don't match; try again.\n"), stderr);
                } else {
-                       strzero (cp);
+                       erase_pass (cp);
                        break;
                }
        }
index 9bad438e70e2990ce16774a6072af4c92d8bc635..65b74da4160a16b83fa778f41058e095b055d6e4 100644 (file)
@@ -182,7 +182,7 @@ static void catch_signals (unused int sig)
                 */
 
                /* get a password for root */
-               cp = getpass (_(
+               cp = agetpass (_(
 "\n"
 "Type control-d to proceed with normal startup,\n"
 "(or give root password for system maintenance):"));
@@ -193,6 +193,7 @@ static void catch_signals (unused int sig)
                 * --marekm
                 */
                if ((NULL == cp) || ('\0' == *cp)) {
+                       erase_pass (cp);
 #ifdef USE_SYSLOG
                        SYSLOG (LOG_INFO, "Normal startup\n");
                        closelog ();
@@ -204,7 +205,8 @@ static void catch_signals (unused int sig)
                        exit (0);
                }
                STRFCPY (pass, cp);
-               strzero (cp);
+               erase_pass (cp);
+
                if (valid (pass, &pwent)) {     /* check encrypted passwords ... */
                        break;  /* ... encrypted passwords matched */
                }