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

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