summaryrefslogtreecommitdiff
path: root/source3/passdb
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2004-07-08 21:01:30 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 10:52:10 -0500
commitd4ac326d46faab010eeeb24c893ab13bbbf0337e (patch)
tree8c9a257d054dbd4a8e79f6bccd6187f0b507468b /source3/passdb
parentc1a0b0a9e7ce57bdb0e5341f8d272bc02a4b6e84 (diff)
downloadsamba-d4ac326d46faab010eeeb24c893ab13bbbf0337e.tar.gz
samba-d4ac326d46faab010eeeb24c893ab13bbbf0337e.tar.bz2
samba-d4ac326d46faab010eeeb24c893ab13bbbf0337e.zip
r1412: Fix password history list in tdbsam. Fix some memory leaks. Add
my (C) to a header file that was at least 50% mine :-). Jeremy. (This used to be commit 8ee6060977ec8e65082f3ad09e1e1ccf5b4672ed)
Diffstat (limited to 'source3/passdb')
-rw-r--r--source3/passdb/passdb.c23
-rw-r--r--source3/passdb/pdb_tdb.c3
2 files changed, 22 insertions, 4 deletions
diff --git a/source3/passdb/passdb.c b/source3/passdb/passdb.c
index 7e291ade22..ea1ce80442 100644
--- a/source3/passdb/passdb.c
+++ b/source3/passdb/passdb.c
@@ -932,7 +932,7 @@ BOOL local_password_change(const char *user_name, int local_flags,
if ((local_flags & LOCAL_ADD_USER) || (local_flags & LOCAL_DELETE_USER)) {
/* Might not exist in /etc/passwd. Use rid algorithm here */
if (!NT_STATUS_IS_OK(pdb_init_sam_new(&sam_pass, user_name, 0))) {
- slprintf(err_str, err_str_len-1, "Failed to initialise SAM_ACCOUNT for user %s.\n", user_name);
+ slprintf(err_str, err_str_len-1, "Failed to initialise SAM_ACCOUNT for user %s. Does this user exist in the UNIX password database ?\n", user_name);
return False;
}
} else {
@@ -1840,12 +1840,27 @@ BOOL init_sam_from_buffer_v2(SAM_ACCOUNT *sampass, uint8 *buf, uint32 buflen)
/* Change from V1 is addition of password history field. */
account_policy_get(AP_PASSWORD_HISTORY, &pwHistLen);
-
- if (pwHistLen && nt_pw_hist_ptr && ((nt_pw_hist_len % NT_HASH_LEN) == 0)) {
- if (!pdb_set_pw_history(sampass, nt_pw_hist_ptr, nt_pw_hist_len/NT_HASH_LEN, PDB_SET)) {
+ if (pwHistLen) {
+ char *pw_hist = malloc(pwHistLen * NT_HASH_LEN);
+ if (!pw_hist) {
+ ret = False;
+ goto done;
+ }
+ memset(pw_hist, '\0', pwHistLen * NT_HASH_LEN);
+ if (nt_pw_hist_ptr && nt_pw_hist_len) {
+ int i;
+ SMB_ASSERT((nt_pw_hist_len % NT_HASH_LEN) == 0);
+ nt_pw_hist_len /= NT_HASH_LEN;
+ for (i = 0; (i < pwHistLen) && (i < nt_pw_hist_len); i++) {
+ memcpy(&pw_hist[i*NT_HASH_LEN], &nt_pw_hist_ptr[i*NT_HASH_LEN], NT_HASH_LEN);
+ }
+ }
+ if (!pdb_set_pw_history(sampass, pw_hist, pwHistLen, PDB_SET)) {
+ SAFE_FREE(pw_hist);
ret = False;
goto done;
}
+ SAFE_FREE(pw_hist);
} else {
pdb_set_pw_history(sampass, NULL, 0, PDB_SET);
}
diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c
index 97ef467064..5fb5ce3891 100644
--- a/source3/passdb/pdb_tdb.c
+++ b/source3/passdb/pdb_tdb.c
@@ -138,6 +138,9 @@ static BOOL tdbsam_convert(TDB_CONTEXT *pdb_tdb, tdbsamver_t from)
return False;
}
+ /* We're finished with the old data. */
+ SAFE_FREE(data.dptr);
+
/* pack from the buffer into the new format */
DEBUG(10,("tdbsam_convert: Try packing a record (key:%s) (version:%d)\n", key.dptr, from));
if ((data.dsize=init_buffer_from_sam (&buf, user, False)) == -1) {