---
 passwd.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/passwd.c b/passwd.c
index 3ea3dd1..5cf88a7 100644
--- a/passwd.c
+++ b/passwd.c
@@ -141,9 +141,12 @@ main(int argc, char *argv[])
        struct passwd *pw;
        struct spwd *spw = NULL;
        FILE *fp = NULL;
-       int r = -1, status = 1;
+       int r = -1, status = 1, dflg = 0;
 
        ARGBEGIN {
+       case 'd':
+               dflg = 1;
+               break;
        default:
                usage();
        } ARGEND;
@@ -207,10 +210,13 @@ main(int argc, char *argv[])
                eprintf("incorrect password\n");
 
 newpass:
-       inpass = getpass("Enter new password: ");
+       if (dflg)
+               inpass = "";
+       else
+               inpass = getpass("Enter new password: ");
        if (!inpass)
                eprintf("getpass:");
-       if (inpass[0] == '\0')
+       if (inpass[0] == '\0' && !dflg)
                eprintf("no password supplied\n");
        p = crypt(inpass, salt);
        if (!p)
@@ -222,10 +228,11 @@ newpass:
        /* Flush pending input */
        ioctl(0, TCFLSH, (void *)0);
 
-       inpass = getpass("Retype new password: ");
+       if (!dflg)
+               inpass = getpass("Retype new password: ");
        if (!inpass)
                eprintf("getpass:");
-       if (inpass[0] == '\0')
+       if (inpass[0] == '\0' && !dflg)
                eprintf("no password supplied\n");
        p = crypt(inpass, salt);
        if (!p)
-- 
2.10.2


Reply via email to