diff options
author | Gerald Carter <jerry@samba.org> | 2001-05-07 14:04:46 +0000 |
---|---|---|
committer | Gerald Carter <jerry@samba.org> | 2001-05-07 14:04:46 +0000 |
commit | 30c4c04c2f584857633ce7605555dcfb37a3e1af (patch) | |
tree | cd8eb3081373a1d46a9e5d601e92467db40f9817 /source3/passdb | |
parent | 050b0307f086037ec9c21d7125fd2a86cf218339 (diff) | |
download | samba-30c4c04c2f584857633ce7605555dcfb37a3e1af.tar.gz samba-30c4c04c2f584857633ce7605555dcfb37a3e1af.tar.xz samba-30c4c04c2f584857633ce7605555dcfb37a3e1af.zip |
Patch from Simo:
o sed 's/pdb_clear_sam/pdb_free_sam/g'
o add pdb_reset_sam()
o password changing should be ok now as well.
(This used to be commit 96d0e7c3301ad990f6c83b9c216720cb32661fb5)
Diffstat (limited to 'source3/passdb')
-rw-r--r-- | source3/passdb/passdb.c | 57 | ||||
-rw-r--r-- | source3/passdb/pdb_tdb.c | 20 |
2 files changed, 53 insertions, 24 deletions
diff --git a/source3/passdb/passdb.c b/source3/passdb/passdb.c index 3df58b2e7a..396eaf61f2 100644 --- a/source3/passdb/passdb.c +++ b/source3/passdb/passdb.c @@ -139,12 +139,12 @@ BOOL pdb_init_sam(SAM_ACCOUNT **user) /************************************************************ free the SAM_ACCOUNT and the NT/LM hashes. ***********************************************************/ -BOOL pdb_clear_sam(SAM_ACCOUNT *user) +BOOL pdb_free_sam(SAM_ACCOUNT *user) { if (user == NULL) { - DEBUG(0,("pdb_clear_sam: SAM_ACCOUNT was NULL\n")); + DEBUG(0,("pdb_free_sam: SAM_ACCOUNT was NULL\n")); #if 0 - smb_panic("NULL pointer passed to pdb_clear_sam\n"); + smb_panic("NULL pointer passed to pdb_free_sam\n"); #endif return False; } @@ -156,10 +156,32 @@ BOOL pdb_clear_sam(SAM_ACCOUNT *user) free(user->lm_pw); free(user); + user = NULL; return True; } +/************************************************************ + reset the SAM_ACCOUNT and the NT/LM hashes. + ***********************************************************/ + +BOOL pdb_reset_sam(SAM_ACCOUNT *user) +{ + if (user == NULL) { + DEBUG(0,("pdb_reset_sam: SAM_ACCOUNT was NULL\n")); + return False; + } + + if (user->nt_pw) + free(user->nt_pw); + + if (user->lm_pw) + free(user->lm_pw); + + ZERO_STRUCTP(user); + + return True; +} /************************************************************************* Routine to return the next entry in the sam passwd list. @@ -854,15 +876,12 @@ account without a valid local system user.\n", user_name); /* Get the smb passwd entry for this user */ pdb_init_sam(&sam_pass); - if(!pdb_getsampwnam(sam_pass, user_name)) { - pdb_clear_sam(sam_pass); - return False; - } - - if (sam_pass == NULL) { + if(!pdb_getsampwnam(sam_pass, user_name)) + { + pdb_free_sam(sam_pass); + if(!(local_flags & LOCAL_ADD_USER)) { slprintf(err_str, err_str_len-1,"Failed to find entry for user %s.\n", user_name); - pdb_clear_sam(sam_pass); return False; } @@ -895,15 +914,13 @@ account without a valid local system user.\n", user_name); pdb_set_nt_passwd (new_sam_acct, new_nt_p16); } - pdb_clear_sam(sam_pass); - if (pdb_add_sam_account(new_sam_acct)) { slprintf(msg_str, msg_str_len-1, "Added user %s.\n", user_name); - pdb_clear_sam(new_sam_acct); + pdb_free_sam(new_sam_acct); return True; } else { slprintf(err_str, err_str_len-1, "Failed to add entry for user %s.\n", user_name); - pdb_clear_sam(new_sam_acct); + pdb_free_sam(new_sam_acct); return False; } } else { @@ -925,13 +942,14 @@ account without a valid local system user.\n", user_name); pdb_set_nt_passwd (sam_pass, new_nt_p16); } pdb_set_acct_ctrl (sam_pass, pdb_get_acct_ctrl(sam_pass)&(~ACB_DISABLED)); - } else if (local_flags & LOCAL_SET_NO_PASSWORD) { + } + else if (local_flags & LOCAL_SET_NO_PASSWORD) { pdb_set_acct_ctrl (sam_pass, pdb_get_acct_ctrl(sam_pass)|ACB_PWNOTREQ); /* This is needed to preserve ACB_PWNOTREQ in mod_smbfilepwd_entry */ pdb_set_lanman_passwd (sam_pass, NULL); pdb_set_nt_passwd (sam_pass, NULL); - } + } else { /* @@ -953,7 +971,7 @@ account without a valid local system user.\n", user_name); if(local_flags & LOCAL_DELETE_USER) { if (!pdb_delete_sam_account(user_name)) { slprintf(err_str,err_str_len-1, "Failed to delete entry for user %s.\n", user_name); - pdb_clear_sam(sam_pass); + pdb_free_sam(sam_pass); return False; } slprintf(msg_str, msg_str_len-1, "Deleted user %s.\n", user_name); @@ -962,7 +980,7 @@ account without a valid local system user.\n", user_name); { if(!pdb_update_sam_account(sam_pass, True)) { slprintf(err_str, err_str_len-1, "Failed to modify entry for user %s.\n", user_name); - pdb_clear_sam(sam_pass); + pdb_free_sam(sam_pass); return False; } if(local_flags & LOCAL_DISABLE_USER) @@ -973,7 +991,7 @@ account without a valid local system user.\n", user_name); slprintf(msg_str, msg_str_len-1, "User %s password set to none.\n", user_name); } - pdb_clear_sam(sam_pass); + pdb_free_sam(sam_pass); return True; } @@ -1569,3 +1587,4 @@ BOOL pdb_set_hours (SAM_ACCOUNT *sampass, uint8 *hours) return True; } + diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 0bf8ca2da5..f2b98adebd 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -79,6 +79,7 @@ static BOOL init_sam_from_buffer (SAM_ACCOUNT *sampass, uint8 *buf, *nt_pw_ptr; uint32 len = 0; uint32 lmpwlen, ntpwlen, hourslen; + /* unpack the buffer into variables */ len = tdb_unpack (buf, buflen, TDB_FORMAT_STRING, @@ -148,6 +149,7 @@ static BOOL init_sam_from_buffer (SAM_ACCOUNT *sampass, uint8 *buf, pdb_set_logons_divs(sampass, logon_divs); pdb_set_hours(sampass, hours); + /* TODO: free TDB alloced memory !!!!! */ return True; } @@ -491,7 +493,6 @@ BOOL pdb_getsampwnam (SAM_ACCOUNT *user, char *sname) } /* unpack the buffer */ - /*pdb_clear_sam (&global_sam_pass);*/ if (!init_sam_from_buffer (user, data.dptr, data.dsize)) { DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); @@ -543,7 +544,7 @@ BOOL pdb_getsampwuid (SAM_ACCOUNT* user, uid_t uid) if (pw == NULL) { DEBUG(0,("pdb_getsampwuid: getpwuid(%d) return NULL. User does not exist!\n", uid)); - return NULL; + return False; } fstrcpy (name, pw->pw_name); @@ -606,6 +607,7 @@ BOOL pdb_getsampwrid (SAM_ACCOUNT *user, uint32 rid) BOOL pdb_delete_sam_account(char *sname) { struct passwd *pwd = NULL; + SAM_ACCOUNT *sam_pass = NULL; TDB_CONTEXT *pwd_tdb; TDB_DATA key, data; fstring keystr; @@ -642,14 +644,22 @@ BOOL pdb_delete_sam_account(char *sname) } /* unpack the buffer */ - pdb_clear_sam (&global_sam_pass); - if (!init_sam_from_buffer (&global_sam_pass, data.dptr, data.dsize)) + if (!pdb_init_sam (&sam_pass)) + { + tdb_close (pwd_tdb); + return False; + } + + if (!init_sam_from_buffer (sam_pass, data.dptr, data.dsize)) { DEBUG(0,("pdb_getsampwent: Bad SAM_ACCOUNT entry returned from TDB!\n")); + tdb_close (pwd_tdb); return False; } - pwd = sys_getpwnam(global_sam_pass.username); + pwd = sys_getpwnam(sam_pass->username); + + pdb_free_sam (sam_pass); rid = pdb_uid_to_user_rid (pwd->pw_uid); |