s3:passdb: fix logic in pdb_set_pw_history()
authorStefan Metzmacher <metze@samba.org>
Wed, 24 Dec 2014 12:58:12 +0000 (13:58 +0100)
committerVolker Lendecke <vl@samba.org>
Mon, 5 Jan 2015 15:51:30 +0000 (16:51 +0100)
Bug: https://bugzilla.samba.org/show_bug.cgi?id=10940

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Mon Jan  5 16:51:30 CET 2015 on sn-devel-104

source3/passdb/pdb_get_set.c

index 1b716f4728fd66ada0cdec98068cbc3b520e9987..5e162db725dc2ec220a2e2cdd61ecccfc02de043 100644 (file)
@@ -872,19 +872,20 @@ bool pdb_set_lanman_passwd(struct samu *sampass, const uint8 pwd[LM_HASH_LEN], e
 
 bool pdb_set_pw_history(struct samu *sampass, const uint8 *pwd, uint32_t historyLen, enum pdb_value_state flag)
 {
+       DATA_BLOB new_nt_pw_his = {};
+
        if (historyLen && pwd){
-               DATA_BLOB *old_nt_pw_his = &(sampass->nt_pw_his);
-               sampass->nt_pw_his = data_blob_talloc(sampass,
-                                                     pwd, historyLen*PW_HISTORY_ENTRY_LEN);
-               data_blob_free(old_nt_pw_his);
-               if (!sampass->nt_pw_his.length) {
+               new_nt_pw_his = data_blob_talloc(sampass,
+                                                pwd, historyLen*PW_HISTORY_ENTRY_LEN);
+               if (new_nt_pw_his.length == 0) {
                        DEBUG(0, ("pdb_set_pw_history: data_blob_talloc() failed!\n"));
                        return False;
                }
-       } else {
-               sampass->nt_pw_his = data_blob_talloc(sampass, NULL, 0);
        }
 
+       data_blob_free(&sampass->nt_pw_his);
+       sampass->nt_pw_his = new_nt_pw_his;
+
        return pdb_set_init_flags(sampass, PDB_PWHISTORY, flag);
 }