s3:smbd:password_in_history: treat entry with 0 salt as 0 + plain nt hash
[ira/wip.git] / source3 / smbd / chgpasswd.c
index c858c2dfa0be4134a33e7c487e75801ef3e28611..dcefc82bba0278b89b1ad0d637492a15fa777beb 100644 (file)
@@ -1031,13 +1031,31 @@ bool password_in_history(uint8_t nt_pw[NT_HASH_LEN],
                        /* Ignore zero valued entries. */
                        continue;
                }
-               /* Create salted versions of new to compare. */
-               E_md5hash(current_salt, nt_pw, new_nt_pw_salted_md5_hash);
 
-               if (memcmp(new_nt_pw_salted_md5_hash,
-                          old_nt_pw_salted_md5_hash,
-                          SALTED_MD5_HASH_LEN) == 0) {
-                       return true;
+               if (memcmp(zero_md5_nt_pw, current_salt,
+                          PW_HISTORY_SALT_LEN) == 0)
+               {
+                       /*
+                        * New format: zero salt and then plain nt hash.
+                        * Directly compare the hashes.
+                        */
+                       if (memcmp(nt_pw, old_nt_pw_salted_md5_hash,
+                                  SALTED_MD5_HASH_LEN) == 0)
+                       {
+                               return true;
+                       }
+               } else {
+                       /*
+                        * Old format: md5sum of salted nt hash.
+                        * Create salted version of new pw to compare.
+                        */
+                       E_md5hash(current_salt, nt_pw, new_nt_pw_salted_md5_hash);
+
+                       if (memcmp(new_nt_pw_salted_md5_hash,
+                                  old_nt_pw_salted_md5_hash,
+                                  SALTED_MD5_HASH_LEN) == 0) {
+                               return true;
+                       }
                }
        }
        return false;