summaryrefslogtreecommitdiff
path: root/source3/passdb/passdb.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2006-06-15 01:54:09 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:17:27 -0500
commitf9147c4e408d316d194c4e367dfccbf433cb8ec9 (patch)
treec706add179942ab8c6b54cda49e9b0a47fc69bca /source3/passdb/passdb.c
parenta1e0a0e9286fbe90ca04cda9df38e72d8d18b0c1 (diff)
downloadsamba-f9147c4e408d316d194c4e367dfccbf433cb8ec9.tar.gz
samba-f9147c4e408d316d194c4e367dfccbf433cb8ec9.tar.bz2
samba-f9147c4e408d316d194c4e367dfccbf433cb8ec9.zip
r16241: Fix Klocwork #106 and others like it.
Make 2 important changes. pdb_get_methods() returning NULL is a *fatal* error. Don't try and cope with it just call smb_panic. This removes a *lot* of pointless "if (!pdb)" handling code. Secondly, ensure that if samu_init() fails we *always* back out of a function. That way we are never in a situation where the pdb_XXX() functions need to start with a "if (sampass)" test - this was just bad design, not defensive programming. Jeremy. (This used to be commit a0d368197d6ae6777b7c2c3c6e970ab8ae7ca2ae)
Diffstat (limited to 'source3/passdb/passdb.c')
-rw-r--r--source3/passdb/passdb.c41
1 files changed, 16 insertions, 25 deletions
diff --git a/source3/passdb/passdb.c b/source3/passdb/passdb.c
index 43171df8b0..d4e788ff68 100644
--- a/source3/passdb/passdb.c
+++ b/source3/passdb/passdb.c
@@ -67,7 +67,7 @@ static int samu_destroy(void *p)
generate a new struct samuser
***********************************************************************/
-struct samu* samu_new( TALLOC_CTX *ctx )
+struct samu *samu_new( TALLOC_CTX *ctx )
{
struct samu *user;
@@ -634,7 +634,7 @@ NTSTATUS local_password_change(const char *user_name, int local_flags,
char *err_str, size_t err_str_len,
char *msg_str, size_t msg_str_len)
{
- struct samu *sam_pass=NULL;
+ struct samu *sam_pass=NULL;
uint32 other_acb;
NTSTATUS result;
@@ -1094,12 +1094,6 @@ uint32 init_buffer_from_sam_v3 (uint8 **buf, struct samu *sampass, BOOL size_onl
uint32 nt_pw_hist_len;
uint32 pwHistLen = 0;
- /* do we have a valid struct samu pointer? */
- if (sampass == NULL) {
- DEBUG(0, ("init_buffer_from_sam: struct samu is NULL!\n"));
- return -1;
- }
-
*buf = NULL;
buflen = 0;
@@ -1330,27 +1324,31 @@ uint32 init_buffer_from_sam_v3 (uint8 **buf, struct samu *sampass, BOOL size_onl
BOOL pdb_copy_sam_account(struct samu *dst, struct samu *src )
{
- BOOL result;
- uint8 *buf;
+ uint8 *buf = NULL;
int len;
- if ( !dst )
- return False;
-
len = init_buffer_from_sam_v3(&buf, src, False);
+ if (len == -1 || !buf) {
+ return False;
+ }
- if (len == -1)
+ if (!init_sam_from_buffer_v3( dst, buf, len )) {
+ free(buf);
return False;
+ }
- result = init_sam_from_buffer_v3( dst, buf, len );
dst->methods = src->methods;
- if ( src->unix_pw )
+ if ( src->unix_pw ) {
dst->unix_pw = tcopy_passwd( dst, src->unix_pw );
+ if (!dst->unix_pw) {
+ free(buf);
+ return False;
+ }
+ }
free(buf);
-
- return result;
+ return True;
}
/*********************************************************************
@@ -1363,8 +1361,6 @@ BOOL pdb_update_bad_password_count(struct samu *sampass, BOOL *updated)
uint16 BadPasswordCount;
uint32 resettime;
- if (!sampass) return False;
-
BadPasswordCount = pdb_get_bad_password_count(sampass);
if (!BadPasswordCount) {
DEBUG(9, ("No bad password attempts.\n"));
@@ -1405,8 +1401,6 @@ BOOL pdb_update_autolock_flag(struct samu *sampass, BOOL *updated)
uint32 duration;
time_t LastBadPassword;
- if (!sampass) return False;
-
if (!(pdb_get_acct_ctrl(sampass) & ACB_AUTOLOCK)) {
DEBUG(9, ("pdb_update_autolock_flag: Account %s not autolocked, no check needed\n",
pdb_get_username(sampass)));
@@ -1459,9 +1453,6 @@ BOOL pdb_increment_bad_password_count(struct samu *sampass)
BOOL autolock_updated = False, badpw_updated = False;
BOOL ret;
- if (!sampass)
- return False;
-
/* Retrieve the account lockout policy */
become_root();
ret = pdb_get_account_policy(AP_BAD_ATTEMPT_LOCKOUT, &account_policy_lockout);