Blame SOURCES/shadow-4.5-usermod-unlock.patch

2de3ab
Index: shadow-4.5/src/usermod.c
2de3ab
===================================================================
2de3ab
--- shadow-4.5.orig/src/usermod.c
2de3ab
+++ shadow-4.5/src/usermod.c
2de3ab
@@ -455,14 +455,17 @@ static char *new_pw_passwd (char *pw_pas
2de3ab
 		strcat (buf, pw_pass);
2de3ab
 		pw_pass = buf;
2de3ab
 	} else if (Uflg && pw_pass[0] == '!') {
2de3ab
-		char *s;
2de3ab
+		char *s = pw_pass;
2de3ab
 
2de3ab
-		if (pw_pass[1] == '\0') {
2de3ab
+		while ('!' == *s)
2de3ab
+			++s;
2de3ab
+
2de3ab
+		if (*s == '\0') {
2de3ab
 			fprintf (stderr,
2de3ab
 			         _("%s: unlocking the user's password would result in a passwordless account.\n"
2de3ab
 			           "You should set a password with usermod -p to unlock this user's password.\n"),
2de3ab
 			         Prog);
2de3ab
-			return pw_pass;
2de3ab
+			return NULL;
2de3ab
 		}
2de3ab
 
2de3ab
 #ifdef WITH_AUDIT
2de3ab
@@ -471,12 +474,15 @@ static char *new_pw_passwd (char *pw_pas
2de3ab
 		              user_newname, (unsigned int) user_newid, 1);
2de3ab
 #endif
2de3ab
 		SYSLOG ((LOG_INFO, "unlock user '%s' password", user_newname));
2de3ab
-		s = pw_pass;
2de3ab
-		while ('\0' != *s) {
2de3ab
-			*s = *(s + 1);
2de3ab
-			s++;
2de3ab
-		}
2de3ab
+		memmove (pw_pass, s, strlen (s) + 1);
2de3ab
 	} else if (pflg) {
2de3ab
+		if (strchr (user_pass, ':') != NULL) {
2de3ab
+			fprintf (stderr,
2de3ab
+			         _("%s: The password field cannot contain a colon character.\n"),
2de3ab
+			         Prog);
2de3ab
+			return NULL;
2de3ab
+
2de3ab
+		}
2de3ab
 #ifdef WITH_AUDIT
2de3ab
 		audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
2de3ab
 		              "updating-password",
2de3ab
@@ -525,6 +531,8 @@ static void new_pwent (struct passwd *pw
2de3ab
 	if (   (!is_shadow_pwd)
2de3ab
 	    || (strcmp (pwent->pw_passwd, SHADOW_PASSWD_STRING) != 0)) {
2de3ab
 		pwent->pw_passwd = new_pw_passwd (pwent->pw_passwd);
2de3ab
+		if (pwent->pw_passwd == NULL)
2de3ab
+			fail_exit (E_PW_UPDATE);
2de3ab
 	}
2de3ab
 
2de3ab
 	if (uflg) {
2de3ab
@@ -639,6 +647,8 @@ static void new_spent (struct spwd *spen
2de3ab
 	 *  + aging has been requested
2de3ab
 	 */
2de3ab
 	spent->sp_pwdp = new_pw_passwd (spent->sp_pwdp);
2de3ab
+	if (spent->sp_pwdp == NULL)
2de3ab
+		fail_exit(E_PW_UPDATE);
2de3ab
 
2de3ab
 	if (pflg) {
2de3ab
 		spent->sp_lstchg = (long) gettime () / SCALE;