s3-samr: fix various potential memleaks in samr_SetUserInfo.
authorGünther Deschner <gd@samba.org>
Mon, 1 Dec 2008 21:20:41 +0000 (22:20 +0100)
committerGünther Deschner <gd@samba.org>
Mon, 1 Dec 2008 21:43:05 +0000 (22:43 +0100)
Was there any reason why we did all these individual TALLOC_FREEs ?

Guenther

source/rpc_server/srv_samr_nt.c

index a427843e3dfd53b6837cddb8efe34f37f6236a41..d807f3a2af1ba2a4bce06c272b0752e646b77cd0 100644 (file)
@@ -3726,13 +3726,11 @@ static NTSTATUS set_user_info_7(TALLOC_CTX *mem_ctx,
 
        if (id7 == NULL) {
                DEBUG(5, ("set_user_info_7: NULL id7\n"));
-               TALLOC_FREE(pwd);
                return NT_STATUS_ACCESS_DENIED;
        }
 
        if (!id7->account_name.string) {
                DEBUG(5, ("set_user_info_7: failed to get new username\n"));
-               TALLOC_FREE(pwd);
                return NT_STATUS_ACCESS_DENIED;
        }
 
@@ -3752,7 +3750,6 @@ static NTSTATUS set_user_info_7(TALLOC_CTX *mem_ctx,
 
        rc = pdb_rename_sam_account(pwd, id7->account_name.string);
 
-       TALLOC_FREE(pwd);
        return rc;
 }
 
@@ -3765,23 +3762,18 @@ static bool set_user_info_16(struct samr_UserInfo16 *id16,
 {
        if (id16 == NULL) {
                DEBUG(5, ("set_user_info_16: NULL id16\n"));
-               TALLOC_FREE(pwd);
                return False;
        }
 
        /* FIX ME: check if the value is really changed --metze */
        if (!pdb_set_acct_ctrl(pwd, id16->acct_flags, PDB_CHANGED)) {
-               TALLOC_FREE(pwd);
                return False;
        }
 
        if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd))) {
-               TALLOC_FREE(pwd);
                return False;
        }
 
-       TALLOC_FREE(pwd);
-
        return True;
 }
 
@@ -3794,29 +3786,23 @@ static bool set_user_info_18(struct samr_UserInfo18 *id18,
 {
        if (id18 == NULL) {
                DEBUG(2, ("set_user_info_18: id18 is NULL\n"));
-               TALLOC_FREE(pwd);
                return False;
        }
 
        if (!pdb_set_lanman_passwd (pwd, id18->lm_pwd.hash, PDB_CHANGED)) {
-               TALLOC_FREE(pwd);
                return False;
        }
        if (!pdb_set_nt_passwd     (pwd, id18->nt_pwd.hash, PDB_CHANGED)) {
-               TALLOC_FREE(pwd);
                return False;
        }
        if (!pdb_set_pass_last_set_time (pwd, time(NULL), PDB_CHANGED)) {
-               TALLOC_FREE(pwd);
                return False;
        }
 
        if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd))) {
-               TALLOC_FREE(pwd);
                return False;
        }
 
-       TALLOC_FREE(pwd);
        return True;
 }
 
@@ -3836,12 +3822,9 @@ static bool set_user_info_20(struct samr_UserInfo20 *id20,
 
        /* write the change out */
        if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd))) {
-               TALLOC_FREE(pwd);
                return False;
        }
 
-       TALLOC_FREE(pwd);
-
        return True;
 }
 
@@ -3861,7 +3844,6 @@ static NTSTATUS set_user_info_21(TALLOC_CTX *mem_ctx,
        }
 
        if (id21->fields_present & SAMR_FIELD_LAST_PWD_CHANGE) {
-               TALLOC_FREE(pwd);
                return NT_STATUS_ACCESS_DENIED;
        }
 
@@ -3890,7 +3872,6 @@ static NTSTATUS set_user_info_21(TALLOC_CTX *mem_ctx,
                if (!NT_STATUS_IS_OK(status)) {
                        DEBUG(0,("set_user_info_21: failed to rename account: %s\n",
                                nt_errstr(status)));
-                       TALLOC_FREE(pwd);
                        return status;
                }
 
@@ -3921,12 +3902,9 @@ static NTSTATUS set_user_info_21(TALLOC_CTX *mem_ctx,
 
        /* write the change out */
        if(!NT_STATUS_IS_OK(status = pdb_update_sam_account(pwd))) {
-               TALLOC_FREE(pwd);
                return status;
        }
 
-       TALLOC_FREE(pwd);
-
        return NT_STATUS_OK;
 }
 
@@ -3949,7 +3927,6 @@ static NTSTATUS set_user_info_23(TALLOC_CTX *mem_ctx,
        }
 
        if (id23->info.fields_present & SAMR_FIELD_LAST_PWD_CHANGE) {
-               TALLOC_FREE(pwd);
                return NT_STATUS_ACCESS_DENIED;
        }
 
@@ -3964,12 +3941,10 @@ static NTSTATUS set_user_info_23(TALLOC_CTX *mem_ctx,
                                &plaintext_buf,
                                &len,
                                STR_UNICODE)) {
-               TALLOC_FREE(pwd);
                return NT_STATUS_WRONG_PASSWORD;
        }
 
        if (!pdb_set_plaintext_passwd (pwd, plaintext_buf)) {
-               TALLOC_FREE(pwd);
                return NT_STATUS_ACCESS_DENIED;
        }
 
@@ -3986,7 +3961,6 @@ static NTSTATUS set_user_info_23(TALLOC_CTX *mem_ctx,
                        struct passwd *passwd;
                        if (pdb_get_username(pwd) == NULL) {
                                DEBUG(1, ("chgpasswd: User without name???\n"));
-                               TALLOC_FREE(pwd);
                                return NT_STATUS_ACCESS_DENIED;
                        }
 
@@ -3996,7 +3970,6 @@ static NTSTATUS set_user_info_23(TALLOC_CTX *mem_ctx,
                        }
 
                        if(!chgpasswd(pdb_get_username(pwd), passwd, "", plaintext_buf, True)) {
-                               TALLOC_FREE(pwd);
                                return NT_STATUS_ACCESS_DENIED;
                        }
                        TALLOC_FREE(passwd);
@@ -4008,17 +3981,13 @@ static NTSTATUS set_user_info_23(TALLOC_CTX *mem_ctx,
        if (IS_SAM_CHANGED(pwd, PDB_GROUPSID) &&
            (!NT_STATUS_IS_OK(status =  pdb_set_unix_primary_group(mem_ctx,
                                                                   pwd)))) {
-               TALLOC_FREE(pwd);
                return status;
        }
 
        if(!NT_STATUS_IS_OK(status = pdb_update_sam_account(pwd))) {
-               TALLOC_FREE(pwd);
                return status;
        }
 
-       TALLOC_FREE(pwd);
-
        return NT_STATUS_OK;
 }
 
@@ -4049,12 +4018,10 @@ static bool set_user_info_pw(uint8 *pass, struct samu *pwd,
                                &plaintext_buf,
                                &len,
                                STR_UNICODE)) {
-               TALLOC_FREE(pwd);
                return False;
        }
 
        if (!pdb_set_plaintext_passwd (pwd, plaintext_buf)) {
-               TALLOC_FREE(pwd);
                return False;
        }
 
@@ -4070,7 +4037,6 @@ static bool set_user_info_pw(uint8 *pass, struct samu *pwd,
 
                        if (pdb_get_username(pwd) == NULL) {
                                DEBUG(1, ("chgpasswd: User without name???\n"));
-                               TALLOC_FREE(pwd);
                                return False;
                        }
 
@@ -4080,7 +4046,6 @@ static bool set_user_info_pw(uint8 *pass, struct samu *pwd,
                        }
 
                        if(!chgpasswd(pdb_get_username(pwd), passwd, "", plaintext_buf, True)) {
-                               TALLOC_FREE(pwd);
                                return False;
                        }
                        TALLOC_FREE(passwd);
@@ -4108,12 +4073,9 @@ static bool set_user_info_pw(uint8 *pass, struct samu *pwd,
 
        /* update the SAMBA password */
        if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd))) {
-               TALLOC_FREE(pwd);
                return False;
        }
 
-       TALLOC_FREE(pwd);
-
        return True;
 }
 
@@ -4133,7 +4095,6 @@ static NTSTATUS set_user_info_25(TALLOC_CTX *mem_ctx,
        }
 
        if (id25->info.fields_present & SAMR_FIELD_LAST_PWD_CHANGE) {
-               TALLOC_FREE(pwd);
                return NT_STATUS_ACCESS_DENIED;
        }
 
@@ -4141,7 +4102,6 @@ static NTSTATUS set_user_info_25(TALLOC_CTX *mem_ctx,
 
        /* write the change out */
        if(!NT_STATUS_IS_OK(status = pdb_update_sam_account(pwd))) {
-               TALLOC_FREE(pwd);
                return status;
        }
 
@@ -4160,9 +4120,6 @@ static NTSTATUS set_user_info_25(TALLOC_CTX *mem_ctx,
                }
        }
 
-       /* WARNING: No TALLOC_FREE(pwd), we are about to set the password
-        * hereafter! */
-
        return NT_STATUS_OK;
 }
 
@@ -4374,6 +4331,8 @@ NTSTATUS _samr_SetUserInfo(pipes_struct *p,
 
  done:
 
+       TALLOC_FREE(pwd);
+
        if (has_enough_rights) {
                unbecome_root();
        }