diff options
author | Jeremy Allison <jra@samba.org> | 2006-06-15 01:54:09 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 11:17:27 -0500 |
commit | a0d368197d6ae6777b7c2c3c6e970ab8ae7ca2ae (patch) | |
tree | 35d2d865dae6d0c9ad16664f262461a54af82a0d /source/utils/smbpasswd.c | |
parent | 6c61dc8ed6d84f310ef391fb7700e93ef42c4afc (diff) | |
download | samba-a0d368197d6ae6777b7c2c3c6e970ab8ae7ca2ae.tar.gz samba-a0d368197d6ae6777b7c2c3c6e970ab8ae7ca2ae.tar.xz samba-a0d368197d6ae6777b7c2c3c6e970ab8ae7ca2ae.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.
Diffstat (limited to 'source/utils/smbpasswd.c')
-rw-r--r-- | source/utils/smbpasswd.c | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/source/utils/smbpasswd.c b/source/utils/smbpasswd.c index 24b3759605b..fc339ffaa95 100644 --- a/source/utils/smbpasswd.c +++ b/source/utils/smbpasswd.c @@ -403,12 +403,19 @@ static int process_root(int local_flags) if(local_flags & LOCAL_ENABLE_USER) { struct samu *sampass = NULL; - BOOL ret; sampass = samu_new( NULL ); - ret = pdb_getsampwnam(sampass, user_name); - if((ret) && - (pdb_get_nt_passwd(sampass) == NULL)) { + if (!sampass) { + fprintf(stderr, "talloc fail for struct samu.\n"); + exit(1); + } + if (!pdb_getsampwnam(sampass, user_name)) { + fprintf(stderr, "Failed to find user %s in passdb backend.\n", + user_name ); + exit(1); + } + + if(pdb_get_nt_passwd(sampass) == NULL) { local_flags |= LOCAL_SET_PASSWORD; } TALLOC_FREE(sampass); @@ -437,16 +444,26 @@ static int process_root(int local_flags) printf("Password changed for user %s on %s.\n", user_name, remote_machine ); } else if(!(local_flags & (LOCAL_ADD_USER|LOCAL_DISABLE_USER|LOCAL_ENABLE_USER|LOCAL_DELETE_USER|LOCAL_SET_NO_PASSWORD|LOCAL_SET_PASSWORD))) { struct samu *sampass = NULL; - BOOL ret; sampass = samu_new( NULL ); - ret = pdb_getsampwnam(sampass, user_name); + if (!samu_new) { + fprintf(stderr, "talloc fail for struct samu.\n"); + exit(1); + } + + if (!pdb_getsampwnam(sampass, user_name)) { + fprintf(stderr, "Failed to find user %s in passdb backend.\n", + user_name ); + exit(1); + } printf("Password changed for user %s.", user_name ); - if( (ret != False) && (pdb_get_acct_ctrl(sampass)&ACB_DISABLED) ) + if(pdb_get_acct_ctrl(sampass)&ACB_DISABLED) { printf(" User has disabled flag set."); - if((ret != False) && (pdb_get_acct_ctrl(sampass) & ACB_PWNOTREQ) ) + } + if(pdb_get_acct_ctrl(sampass) & ACB_PWNOTREQ) { printf(" User has no password flag set."); + } printf("\n"); TALLOC_FREE(sampass); } |