[hackers] [PATCH] passwd, login: Support empty passwords

From: Drew DeVault <sir_AT_cmpwn.com>
Date: Sun, 14 Jan 2018 21:54:09 -0500

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
_AT_@ -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
_AT_@ -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;
_AT_@ -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)
_AT_@ -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)
_AT_@ -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
Received on Mon Jan 15 2018 - 03:54:09 CET

This archive was generated by hypermail 2.3.0 : Mon Jan 15 2018 - 04:00:25 CET