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

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