These are useful for daemon users, etc.
---
Sent a similar patch in March, never heard back.

 login.c  |  5 ++++-
 passwd.c | 20 +++++++++++++++-----
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/login.c b/login.c
index 25a59e4..f4fd3cc 100644
--- a/login.c
+++ b/login.c
@@ -107,7 +107,10 @@ main(int argc, char *argv[])
        /* Flush pending input */
        ioctl(0, TCFLSH, (void *)0);
 
-       pass = getpass("Password: ");
+       if (pw->pw_passwd[0] == '\0')
+               pass = "";
+       else
+               pass = getpass("Password: ");
        if (!pass)
                eprintf("getpass:");
        if (pw_check(pw, pass) <= 0)
diff --git a/passwd.c b/passwd.c
index 52b70a8..79a1a66 100644
--- a/passwd.c
+++ b/passwd.c
@@ -164,9 +164,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, fdel = 0;
 
        ARGBEGIN {
+       case 'd':
+               fdel = 1;
+               break;
        default:
                usage();
        } ARGEND;
@@ -216,6 +219,9 @@ main(int argc, char *argv[])
                        prevhash = pw->pw_passwd;
        }
 
+       if (!*prevhash)
+               goto newpass;
+
        printf("Changing password for %s\n", pw->pw_name);
        inpass = getpass("Old password: ");
        if (!inpass)
@@ -230,10 +236,13 @@ main(int argc, char *argv[])
                eprintf("incorrect password\n");
 
 newpass:
-       inpass = getpass("Enter new password: ");
+       if (fdel)
+               inpass = "";
+       else
+               inpass = getpass("Enter new password: ");
        if (!inpass)
                eprintf("getpass:");
-       if (inpass[0] == '\0')
+       if (inpass[0] == '\0' && !fdel)
                eprintf("no password supplied\n");
        p = crypt(inpass, prevhash);
        if (!p)
@@ -249,10 +258,11 @@ newpass:
        /* Flush pending input */
        ioctl(0, TCFLSH, (void *)0);
 
-       inpass = getpass("Retype new password: ");
+       if (!fdel)
+               inpass = getpass("Retype new password: ");
        if (!inpass)
                eprintf("getpass:");
-       if (inpass[0] == '\0')
+       if (inpass[0] == '\0' && !fdel)
                eprintf("no password supplied\n");
        p = crypt(inpass, salt);
        if (!p)
-- 
2.15.0


Reply via email to