diff --git a/source3/lib/adouble.c b/source3/lib/adouble.c index 37fb686f17bb..aa78007dadd3 100644 --- a/source3/lib/adouble.c +++ b/source3/lib/adouble.c @@ -1254,13 +1254,13 @@ static bool ad_convert_xattr(vfs_handle_struct *handle, if (nwritten == -1) { DBG_ERR("SMB_VFS_PWRITE failed\n"); saved_errno = errno; - close_file(NULL, fsp, ERROR_CLOSE); + close_file_free(NULL, &fsp, ERROR_CLOSE); errno = saved_errno; ok = false; goto fail; } - status = close_file(NULL, fsp, NORMAL_CLOSE); + status = close_file_free(NULL, &fsp, NORMAL_CLOSE); if (!NT_STATUS_IS_OK(status)) { ok = false; goto fail; @@ -1395,12 +1395,12 @@ static bool ad_convert_finderinfo(vfs_handle_struct *handle, if (nwritten == -1) { DBG_ERR("SMB_VFS_PWRITE failed\n"); saved_errno = errno; - close_file(NULL, fsp, ERROR_CLOSE); + close_file_free(NULL, &fsp, ERROR_CLOSE); errno = saved_errno; return false; } - status = close_file(NULL, fsp, NORMAL_CLOSE); + status = close_file_free(NULL, &fsp, NORMAL_CLOSE); if (!NT_STATUS_IS_OK(status)) { return false; } @@ -1652,7 +1652,7 @@ static bool ad_unconvert_open_ad(TALLOC_CTX *mem_ctx, if (ret != 0) { DBG_ERR("SMB_VFS_FCHOWN [%s] failed: %s\n", fsp_str_dbg(fsp), nt_errstr(status)); - close_file(NULL, fsp, NORMAL_CLOSE); + close_file_free(NULL, &fsp, NORMAL_CLOSE); return false; } } @@ -1710,14 +1710,14 @@ static bool ad_unconvert_get_streams(struct vfs_handle_struct *handle, num_streams, streams); if (!NT_STATUS_IS_OK(status)) { - close_file(NULL, fsp, NORMAL_CLOSE); + close_file_free(NULL, &fsp, NORMAL_CLOSE); DBG_ERR("streaminfo on [%s] failed: %s\n", smb_fname_str_dbg(smb_fname), nt_errstr(status)); return false; } - status = close_file(NULL, fsp, NORMAL_CLOSE); + status = close_file_free(NULL, &fsp, NORMAL_CLOSE); if (!NT_STATUS_IS_OK(status)) { DBG_ERR("close_file [%s] failed: %s\n", smb_fname_str_dbg(smb_fname), @@ -1975,7 +1975,7 @@ static bool ad_collect_one_stream(struct vfs_handle_struct *handle, out: TALLOC_FREE(sname); if (fsp != NULL) { - status = close_file(NULL, fsp, NORMAL_CLOSE); + status = close_file_free(NULL, &fsp, NORMAL_CLOSE); if (!NT_STATUS_IS_OK(status)) { DBG_ERR("close_file [%s] failed: %s\n", smb_fname_str_dbg(smb_fname), @@ -2117,9 +2117,9 @@ bool ad_unconvert(TALLOC_CTX *mem_ctx, out: if (fsp != NULL) { - status = close_file(NULL, fsp, NORMAL_CLOSE); + status = close_file_free(NULL, &fsp, NORMAL_CLOSE); if (!NT_STATUS_IS_OK(status)) { - DBG_ERR("close_file [%s] failed: %s\n", + DBG_ERR("close_file_free() [%s] failed: %s\n", smb_fname_str_dbg(smb_fname), nt_errstr(status)); ok = false; diff --git a/source3/modules/vfs_fruit.c b/source3/modules/vfs_fruit.c index d6aa7e3644e6..303df41258e9 100644 --- a/source3/modules/vfs_fruit.c +++ b/source3/modules/vfs_fruit.c @@ -1002,7 +1002,7 @@ static bool readdir_attr_meta_finderi_stream( fail: if (fsp != NULL) { - close_file(NULL, fsp, NORMAL_CLOSE); + close_file_free(NULL, &fsp, NORMAL_CLOSE); } return ok; @@ -4247,8 +4247,8 @@ static NTSTATUS fruit_create_file(vfs_handle_struct *handle, DEBUG(10, ("fruit_create_file: %s\n", nt_errstr(status))); if (fsp) { - close_file(req, fsp, ERROR_CLOSE); - *result = fsp = NULL; + close_file_free(req, &fsp, ERROR_CLOSE); + *result = NULL; } return status; @@ -4993,8 +4993,7 @@ static bool fruit_get_bandsize(vfs_handle_struct *handle, } - status = close_file(NULL, fsp, NORMAL_CLOSE); - fsp = NULL; + status = close_file_free(NULL, &fsp, NORMAL_CLOSE); if (!NT_STATUS_IS_OK(status)) { DBG_ERR("close_file failed: %s\n", nt_errstr(status)); ok = false; @@ -5028,11 +5027,10 @@ static bool fruit_get_bandsize(vfs_handle_struct *handle, out: if (fsp != NULL) { - status = close_file(NULL, fsp, NORMAL_CLOSE); + status = close_file_free(NULL, &fsp, NORMAL_CLOSE); if (!NT_STATUS_IS_OK(status)) { DBG_ERR("close_file failed: %s\n", nt_errstr(status)); } - fsp = NULL; } TALLOC_FREE(plist); TALLOC_FREE(smb_fname); diff --git a/source3/modules/vfs_worm.c b/source3/modules/vfs_worm.c index 3ae1f9f39e68..76762e0a84f7 100644 --- a/source3/modules/vfs_worm.c +++ b/source3/modules/vfs_worm.c @@ -75,7 +75,7 @@ static NTSTATUS vfs_worm_create_file(vfs_handle_struct *handle, * Access via MAXIMUM_ALLOWED_ACCESS? */ if (readonly && ((*result)->access_mask & write_access_flags)) { - close_file(req, *result, NORMAL_CLOSE); + close_file_free(req, result, NORMAL_CLOSE); return NT_STATUS_ACCESS_DENIED; } return NT_STATUS_OK; diff --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c index a47afda4a842..1e35e017fb2b 100644 --- a/source3/printing/nt_printing.c +++ b/source3/printing/nt_printing.c @@ -874,8 +874,7 @@ static int file_version_is_newer(connection_struct *conn, fstring new_file, fstr (long)old_create_time)); } - close_file(NULL, fsp, NORMAL_CLOSE); - fsp = NULL; + close_file_free(NULL, &fsp, NORMAL_CLOSE); /* Get file version info (if available) for new file */ status = driver_unix_convert(conn, new_file, &smb_fname); @@ -935,8 +934,7 @@ static int file_version_is_newer(connection_struct *conn, fstring new_file, fstr (long)new_create_time)); } - close_file(NULL, fsp, NORMAL_CLOSE); - fsp = NULL; + close_file_free(NULL, &fsp, NORMAL_CLOSE); if (use_version && (new_major != old_major || new_minor != old_minor)) { /* Compare versions and choose the larger version number */ @@ -969,7 +967,7 @@ static int file_version_is_newer(connection_struct *conn, fstring new_file, fstr error_exit: if(fsp) - close_file(NULL, fsp, NORMAL_CLOSE); + close_file_free(NULL, &fsp, NORMAL_CLOSE); ret = -1; done: TALLOC_FREE(smb_fname); @@ -1177,7 +1175,7 @@ static uint32_t get_correct_cversion(const struct auth_session_info *session_inf unbecome_user_without_service(); error_free_conn: if (fsp != NULL) { - close_file(NULL, fsp, NORMAL_CLOSE); + close_file_free(NULL, &fsp, NORMAL_CLOSE); } if (!W_ERROR_IS_OK(*perr)) { cversion = -1; diff --git a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c index 770e5d368a80..ea296eaa6ab2 100644 --- a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c +++ b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c @@ -2539,7 +2539,7 @@ WERROR _srvsvc_NetGetFileSecurity(struct pipes_struct *p, error_exit: if (fsp) { - close_file(NULL, fsp, NORMAL_CLOSE); + close_file_free(NULL, &fsp, NORMAL_CLOSE); } TALLOC_FREE(frame); @@ -2659,7 +2659,7 @@ WERROR _srvsvc_NetSetFileSecurity(struct pipes_struct *p, error_exit: if (fsp) { - close_file(NULL, fsp, NORMAL_CLOSE); + close_file_free(NULL, &fsp, NORMAL_CLOSE); } TALLOC_FREE(frame); diff --git a/source3/smbd/close.c b/source3/smbd/close.c index af739abc4a3e..9160266c6fb4 100644 --- a/source3/smbd/close.c +++ b/source3/smbd/close.c @@ -1478,10 +1478,12 @@ static NTSTATUS close_directory(struct smb_request *req, files_struct *fsp, Close a files_struct. ****************************************************************************/ -NTSTATUS close_file(struct smb_request *req, files_struct *fsp, - enum file_close_type close_type) +NTSTATUS close_file_free(struct smb_request *req, + struct files_struct **_fsp, + enum file_close_type close_type) { NTSTATUS status; + struct files_struct *fsp = *_fsp; struct files_struct *base_fsp = fsp->base_fsp; bool close_base_fsp = false; @@ -1569,9 +1571,11 @@ NTSTATUS close_file(struct smb_request *req, files_struct *fsp, * those loops will become confused. */ - close_file(req, base_fsp, close_type); + close_file_free(req, &base_fsp, close_type); } + *_fsp = NULL; + return status; } @@ -1610,5 +1614,5 @@ void msg_close_file(struct messaging_context *msg_ctx, DEBUG(10,("msg_close_file: failed to find file.\n")); return; } - close_file(NULL, fsp, NORMAL_CLOSE); + close_file_free(NULL, &fsp, NORMAL_CLOSE); } diff --git a/source3/smbd/dir.c b/source3/smbd/dir.c index 8e5ce66c961d..581ce5202ed7 100644 --- a/source3/smbd/dir.c +++ b/source3/smbd/dir.c @@ -185,9 +185,12 @@ void dptr_closecnum(connection_struct *conn) for(dptr = sconn->searches.dirptrs; dptr; dptr = next) { next = dptr->next; if (dptr->conn == conn) { - files_struct *fsp = dptr->dir_hnd->fsp; - close_file(NULL, fsp, NORMAL_CLOSE); - fsp = NULL; + /* + * Need to make a copy, "dptr" will be gone + * after close_file_free() returns + */ + struct files_struct *fsp = dptr->dir_hnd->fsp; + close_file_free(NULL, &fsp, NORMAL_CLOSE); } } } diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 4113779f9636..4066822357eb 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -778,7 +778,7 @@ void file_close_conn(connection_struct *conn) */ fsp->op->global->durable = false; } - close_file(NULL, fsp, SHUTDOWN_CLOSE); + close_file_free(NULL, &fsp, SHUTDOWN_CLOSE); } } @@ -848,7 +848,7 @@ void file_close_user(struct smbd_server_connection *sconn, uint64_t vuid) for (fsp=sconn->files; fsp; fsp=next) { next=fsp->next; if (fsp->vuid == vuid) { - close_file(NULL, fsp, SHUTDOWN_CLOSE); + close_file_free(NULL, &fsp, SHUTDOWN_CLOSE); } } } diff --git a/source3/smbd/nttrans.c b/source3/smbd/nttrans.c index 4dcd4000b840..94b6c4184635 100644 --- a/source3/smbd/nttrans.c +++ b/source3/smbd/nttrans.c @@ -1649,7 +1649,7 @@ NTSTATUS copy_internals(TALLOC_CTX *ctx, NULL, NULL); /* create context */ if (!NT_STATUS_IS_OK(status)) { - close_file(NULL, fsp1, ERROR_CLOSE); + close_file_free(NULL, &fsp1, ERROR_CLOSE); goto out; } @@ -1663,12 +1663,12 @@ NTSTATUS copy_internals(TALLOC_CTX *ctx, * Thus we don't look at the error return from the * close of fsp1. */ - close_file(NULL, fsp1, NORMAL_CLOSE); + close_file_free(NULL, &fsp1, NORMAL_CLOSE); /* Ensure the modtime is set correctly on the destination file. */ set_close_write_time(fsp2, smb_fname_src->st.st_ex_mtime); - status = close_file(NULL, fsp2, NORMAL_CLOSE); + status = close_file_free(NULL, &fsp2, NORMAL_CLOSE); /* Grrr. We have to do this as open_file_ntcreate adds FILE_ATTRIBUTE_ARCHIVE when it creates the file. This isn't the correct thing to do in the copy diff --git a/source3/smbd/open.c b/source3/smbd/open.c index ba6e7c686182..98bbba3d722e 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -4765,7 +4765,7 @@ NTSTATUS create_directory(connection_struct *conn, struct smb_request *req, NULL, NULL); /* create context */ if (NT_STATUS_IS_OK(status)) { - close_file(req, fsp, NORMAL_CLOSE); + close_file_free(req, &fsp, NORMAL_CLOSE); } return status; @@ -5015,7 +5015,7 @@ static NTSTATUS open_streams_for_delete(connection_struct *conn, DEBUG(10, ("Closing stream # %d, %s\n", j, fsp_str_dbg(streams[j]))); - close_file(NULL, streams[j], NORMAL_CLOSE); + close_file_free(NULL, &streams[j], NORMAL_CLOSE); } fail: @@ -6058,12 +6058,10 @@ static NTSTATUS create_file_unixpath(connection_struct *conn, * fsp->base_fsp. */ base_fsp = NULL; - close_file(req, fsp, ERROR_CLOSE); - fsp = NULL; + close_file_free(req, &fsp, ERROR_CLOSE); } if (base_fsp != NULL) { - close_file(req, base_fsp, ERROR_CLOSE); - base_fsp = NULL; + close_file_free(req, &base_fsp, ERROR_CLOSE); } TALLOC_FREE(parent_dir_fname); @@ -6241,8 +6239,7 @@ NTSTATUS create_file_default(connection_struct *conn, DEBUG(10, ("create_file: %s\n", nt_errstr(status))); if (fsp != NULL) { - close_file(req, fsp, ERROR_CLOSE); - fsp = NULL; + close_file_free(req, &fsp, ERROR_CLOSE); } return status; } diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index 59a1bbd3e80b..e1443c1186fd 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -130,8 +130,9 @@ bool smbd_smb1_brl_finish_by_mid( /* The following definitions come from smbd/close.c */ void set_close_write_time(struct files_struct *fsp, struct timespec ts); -NTSTATUS close_file(struct smb_request *req, files_struct *fsp, - enum file_close_type close_type); +NTSTATUS close_file_free(struct smb_request *req, + struct files_struct **_fsp, + enum file_close_type close_type); void msg_close_file(struct messaging_context *msg_ctx, void *private_data, uint32_t msg_type, diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c index 28fee8392962..ee53fe3c89ea 100644 --- a/source3/smbd/reply.c +++ b/source3/smbd/reply.c @@ -1821,8 +1821,7 @@ void reply_search(struct smb_request *req) * as this is not a client visible handle so * can'tbe part of an SMB1 chain. */ - close_file(NULL, fsp, NORMAL_CLOSE); - fsp = NULL; + close_file_free(NULL, &fsp, NORMAL_CLOSE); reply_nterror(req, nt_status); goto out; } @@ -1953,15 +1952,13 @@ void reply_search(struct smb_request *req) if (numentries == 0) { dptr_num = -1; if (fsp != NULL) { - close_file(NULL, fsp, NORMAL_CLOSE); - fsp = NULL; + close_file_free(NULL, &fsp, NORMAL_CLOSE); } } else if(expect_close && status_len == 0) { /* Close the dptr - we know it's gone */ dptr_num = -1; if (fsp != NULL) { - close_file(NULL, fsp, NORMAL_CLOSE); - fsp = NULL; + close_file_free(NULL, &fsp, NORMAL_CLOSE); } } @@ -1970,8 +1967,7 @@ void reply_search(struct smb_request *req) dptr_num = -1; /* fsp may have been closed above. */ if (fsp != NULL) { - close_file(NULL, fsp, NORMAL_CLOSE); - fsp = NULL; + close_file_free(NULL, &fsp, NORMAL_CLOSE); } } @@ -2073,8 +2069,7 @@ void reply_fclose(struct smb_request *req) fsp = dptr_fetch_fsp(sconn, status+12,&dptr_num); if(fsp != NULL) { /* Close the file - we know it's gone */ - close_file(NULL, fsp, NORMAL_CLOSE); - fsp = NULL; + close_file_free(NULL, &fsp, NORMAL_CLOSE); dptr_num = -1; } @@ -2216,7 +2211,7 @@ void reply_open(struct smb_request *req) if (fattr & FILE_ATTRIBUTE_DIRECTORY) { DEBUG(3,("attempt to open a directory %s\n", fsp_str_dbg(fsp))); - close_file(req, fsp, ERROR_CLOSE); + close_file_free(req, &fsp, ERROR_CLOSE); reply_botherror(req, NT_STATUS_ACCESS_DENIED, ERRDOS, ERRnoaccess); goto out; @@ -2401,19 +2396,19 @@ void reply_open_and_X(struct smb_request *req) if (((smb_action == FILE_WAS_CREATED) || (smb_action == FILE_WAS_OVERWRITTEN)) && allocation_size) { fsp->initial_allocation_size = smb_roundup(fsp->conn, allocation_size); if (vfs_allocate_file_space(fsp, fsp->initial_allocation_size) == -1) { - close_file(req, fsp, ERROR_CLOSE); + close_file_free(req, &fsp, ERROR_CLOSE); reply_nterror(req, NT_STATUS_DISK_FULL); goto out; } retval = vfs_set_filelen(fsp, (off_t)allocation_size); if (retval < 0) { - close_file(req, fsp, ERROR_CLOSE); + close_file_free(req, &fsp, ERROR_CLOSE); reply_nterror(req, NT_STATUS_DISK_FULL); goto out; } status = vfs_stat_fsp(fsp); if (!NT_STATUS_IS_OK(status)) { - close_file(req, fsp, ERROR_CLOSE); + close_file_free(req, &fsp, ERROR_CLOSE); reply_nterror(req, status); goto out; } @@ -2421,7 +2416,7 @@ void reply_open_and_X(struct smb_request *req) fattr = fdos_mode(fsp); if (fattr & FILE_ATTRIBUTE_DIRECTORY) { - close_file(req, fsp, ERROR_CLOSE); + close_file_free(req, &fsp, ERROR_CLOSE); reply_nterror(req, NT_STATUS_ACCESS_DENIED); goto out; } @@ -3189,7 +3184,7 @@ NTSTATUS unlink_internals(connection_struct *conn, "(%s)\n", smb_fname_str_dbg(smb_fname), nt_errstr(status)); - close_file(req, fsp, NORMAL_CLOSE); + close_file_free(req, &fsp, NORMAL_CLOSE); return status; } @@ -3197,11 +3192,11 @@ NTSTATUS unlink_internals(connection_struct *conn, if (!set_delete_on_close(fsp, True, conn->session_info->security_token, conn->session_info->unix_token)) { - close_file(req, fsp, NORMAL_CLOSE); + close_file_free(req, &fsp, NORMAL_CLOSE); return NT_STATUS_ACCESS_DENIED; } - return close_file(req, fsp, NORMAL_CLOSE); + return close_file_free(req, &fsp, NORMAL_CLOSE); } /**************************************************************************** @@ -5661,7 +5656,7 @@ static void reply_exit_done(struct tevent_req *req) smb_request_done(smb1req); END_PROFILE(SMBexit); } - close_file(NULL, fsp, SHUTDOWN_CLOSE); + close_file_free(NULL, &fsp, SHUTDOWN_CLOSE); } reply_outbuf(smb1req, 0, 0); @@ -5737,12 +5732,12 @@ void reply_close(struct smb_request *smb1req) } /* - * close_file() returns the unix errno if an error was detected on + * close_file_free() returns the unix errno if an error was detected on * close - normally this is due to a disk full error. If not then it * was probably an I/O error. */ - status = close_file(smb1req, fsp, NORMAL_CLOSE); + status = close_file_free(smb1req, &fsp, NORMAL_CLOSE); done: if (!NT_STATUS_IS_OK(status)) { reply_nterror(smb1req, status); @@ -5868,7 +5863,7 @@ static void reply_close_done(struct tevent_req *req) return; } - status = close_file(smb1req, state->fsp, NORMAL_CLOSE); + status = close_file_free(smb1req, &state->fsp, NORMAL_CLOSE); if (NT_STATUS_IS_OK(status)) { reply_outbuf(smb1req, 0, 0); } else { @@ -5967,8 +5962,7 @@ void reply_writeclose(struct smb_request *req) if (numtowrite) { DEBUG(3,("reply_writeclose: zero length write doesn't close " "file %s\n", fsp_str_dbg(fsp))); - close_status = close_file(req, fsp, NORMAL_CLOSE); - fsp = NULL; + close_status = close_file_free(req, &fsp, NORMAL_CLOSE); } if(((nwritten == 0) && (numtowrite != 0))||(nwritten < 0)) { @@ -6516,7 +6510,7 @@ void reply_printclose(struct smb_request *req) DEBUG(3,("printclose fd=%d %s\n", fsp_get_io_fd(fsp), fsp_fnum_dbg(fsp))); - status = close_file(req, fsp, NORMAL_CLOSE); + status = close_file_free(req, &fsp, NORMAL_CLOSE); if(!NT_STATUS_IS_OK(status)) { reply_nterror(req, status); @@ -6919,7 +6913,7 @@ void reply_rmdir(struct smb_request *req) status = can_set_delete_on_close(fsp, FILE_ATTRIBUTE_DIRECTORY); if (!NT_STATUS_IS_OK(status)) { - close_file(req, fsp, ERROR_CLOSE); + close_file_free(req, &fsp, ERROR_CLOSE); reply_nterror(req, status); goto out; } @@ -6927,12 +6921,12 @@ void reply_rmdir(struct smb_request *req) if (!set_delete_on_close(fsp, true, conn->session_info->security_token, conn->session_info->unix_token)) { - close_file(req, fsp, ERROR_CLOSE); + close_file_free(req, &fsp, ERROR_CLOSE); reply_nterror(req, NT_STATUS_ACCESS_DENIED); goto out; } - status = close_file(req, fsp, NORMAL_CLOSE); + status = close_file_free(req, &fsp, NORMAL_CLOSE); if (!NT_STATUS_IS_OK(status)) { reply_nterror(req, status); } else { @@ -7680,7 +7674,7 @@ NTSTATUS rename_internals(TALLOC_CTX *ctx, attrs, replace_if_exists); - close_file(req, fsp, NORMAL_CLOSE); + close_file_free(req, &fsp, NORMAL_CLOSE); DBG_NOTICE("Error %s rename %s -> %s\n", nt_errstr(status), smb_fname_str_dbg(smb_fname_src), @@ -7974,7 +7968,7 @@ NTSTATUS copy_file(TALLOC_CTX *ctx, NULL, NULL); /* create context */ if (!NT_STATUS_IS_OK(status)) { - close_file(NULL, fsp1, ERROR_CLOSE); + close_file_free(NULL, &fsp1, ERROR_CLOSE); goto out; } @@ -7984,8 +7978,8 @@ NTSTATUS copy_file(TALLOC_CTX *ctx, DEBUG(0, ("error - vfs lseek returned error %s\n", strerror(errno))); status = map_nt_error_from_unix(errno); - close_file(NULL, fsp1, ERROR_CLOSE); - close_file(NULL, fsp2, ERROR_CLOSE); + close_file_free(NULL, &fsp1, ERROR_CLOSE); + close_file_free(NULL, &fsp2, ERROR_CLOSE); goto out; } } @@ -7997,7 +7991,7 @@ NTSTATUS copy_file(TALLOC_CTX *ctx, ret = 0; } - close_file(NULL, fsp1, NORMAL_CLOSE); + close_file_free(NULL, &fsp1, NORMAL_CLOSE); /* Ensure the modtime is set correctly on the destination file. */ set_close_write_time(fsp2, smb_fname_src->st.st_ex_mtime); @@ -8008,7 +8002,7 @@ NTSTATUS copy_file(TALLOC_CTX *ctx, * Thus we don't look at the error return from the * close of fsp1. */ - status = close_file(NULL, fsp2, NORMAL_CLOSE); + status = close_file_free(NULL, &fsp2, NORMAL_CLOSE); if (!NT_STATUS_IS_OK(status)) { goto out; diff --git a/source3/smbd/smb2_close.c b/source3/smbd/smb2_close.c index 648080f1a8cf..b434d696c3f6 100644 --- a/source3/smbd/smb2_close.c +++ b/source3/smbd/smb2_close.c @@ -260,7 +260,7 @@ static NTSTATUS smbd_smb2_close(struct smbd_smb2_request *req, &dos_attrs); } - status = close_file(smbreq, fsp, NORMAL_CLOSE); + status = close_file_free(smbreq, &fsp, NORMAL_CLOSE); if (!NT_STATUS_IS_OK(status)) { DEBUG(5,("smbd_smb2_close: close_file[%s]: %s\n", smb_fname_str_dbg(smb_fname), nt_errstr(status))); diff --git a/source3/smbd/smb2_create.c b/source3/smbd/smb2_create.c index ad1ddc9a65ea..932ec31a18a2 100644 --- a/source3/smbd/smb2_create.c +++ b/source3/smbd/smb2_create.c @@ -915,7 +915,8 @@ static struct tevent_req *smbd_smb2_create_send(TALLOC_CTX *mem_ctx, status = smbd_smb2_create_durable_lease_check( smb1req, state->fname, state->result, state->lease_ptr); if (!NT_STATUS_IS_OK(status)) { - close_file(smb1req, state->result, SHUTDOWN_CLOSE); + close_file_free( + smb1req, &state->result, SHUTDOWN_CLOSE); tevent_req_nterror(req, status); return tevent_req_post(req, state->ev); } diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c index b2d20a01888a..2f6b30e24d81 100644 --- a/source3/smbd/trans2.c +++ b/source3/smbd/trans2.c @@ -1396,7 +1396,7 @@ static void call_trans2open(connection_struct *conn, mtime = convert_timespec_to_time_t(smb_fname->st.st_ex_mtime); inode = smb_fname->st.st_ex_ino; if (fattr & FILE_ATTRIBUTE_DIRECTORY) { - close_file(req, fsp, ERROR_CLOSE); + close_file_free(req, &fsp, ERROR_CLOSE); reply_nterror(req, NT_STATUS_ACCESS_DENIED); goto out; } @@ -2896,8 +2896,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd * as this is not a client visible handle so * can'tbe part of an SMB1 chain. */ - close_file(NULL, fsp, NORMAL_CLOSE); - fsp = NULL; + close_file_free(NULL, &fsp, NORMAL_CLOSE); reply_nterror(req, ntstatus); goto out; } @@ -2987,8 +2986,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd if(close_after_first || (finished && close_if_end)) { DEBUG(5,("call_trans2findfirst - (2) closing dptr_num %d\n", dptr_num)); dptr_num = -1; - close_file(NULL, fsp, NORMAL_CLOSE); - fsp = NULL; + close_file_free(NULL, &fsp, NORMAL_CLOSE); } /* @@ -3005,8 +3003,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd * close_after_first or finished case above. */ if (fsp != NULL) { - close_file(NULL, fsp, NORMAL_CLOSE); - fsp = NULL; + close_file_free(NULL, &fsp, NORMAL_CLOSE); } if (get_Protocol() < PROTOCOL_NT1) { reply_force_doserror(req, ERRDOS, ERRnofiles); @@ -3409,8 +3406,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd if(close_after_request || (finished && close_if_end)) { DEBUG(5,("call_trans2findnext: closing dptr_num = %d\n", dptr_num)); dptr_num = -1; - close_file(NULL, fsp, NORMAL_CLOSE); - fsp = NULL; + close_file_free(NULL, &fsp, NORMAL_CLOSE); } if (as_root) { @@ -5043,8 +5039,7 @@ static NTSTATUS smb_query_posix_acl(connection_struct *conn, * date. Structure copy. */ smb_fname->st = fsp->fsp_name->st; - (void)close_file(req, fsp, NORMAL_CLOSE); - fsp = NULL; + (void)close_file_free(req, &fsp, NORMAL_CLOSE); } TALLOC_FREE(file_acl); @@ -6687,18 +6682,18 @@ static NTSTATUS smb_set_file_size(connection_struct *conn, /* See RAW-SFILEINFO-END-OF-FILE */ if (fail_after_createfile) { - close_file(req, new_fsp,NORMAL_CLOSE); + close_file_free(req, &new_fsp, NORMAL_CLOSE); return NT_STATUS_INVALID_LEVEL; } if (vfs_set_filelen(new_fsp, size) == -1) { status = map_nt_error_from_unix(errno); - close_file(req, new_fsp,NORMAL_CLOSE); + close_file_free(req, &new_fsp, NORMAL_CLOSE); return status; } trigger_write_time_update_immediate(new_fsp); - close_file(req, new_fsp,NORMAL_CLOSE); + close_file_free(req, &new_fsp, NORMAL_CLOSE); return NT_STATUS_OK; } @@ -7583,8 +7578,7 @@ static NTSTATUS smb_set_posix_acl(connection_struct *conn, out: if (close_fsp) { - (void)close_file(req, fsp, NORMAL_CLOSE); - fsp = NULL; + (void)close_file_free(req, &fsp, NORMAL_CLOSE); } return status; } @@ -7960,7 +7954,7 @@ static NTSTATUS smb_set_file_allocation_info(connection_struct *conn, if (allocation_size != get_file_size_stat(&smb_fname->st)) { if (vfs_allocate_file_space(new_fsp, allocation_size) == -1) { status = map_nt_error_from_unix(errno); - close_file(req, new_fsp, NORMAL_CLOSE); + close_file_free(req, &new_fsp, NORMAL_CLOSE); return status; } } @@ -7971,7 +7965,7 @@ static NTSTATUS smb_set_file_allocation_info(connection_struct *conn, * if there are no pending writes. */ trigger_write_time_update_immediate(new_fsp); - close_file(req, new_fsp, NORMAL_CLOSE); + close_file_free(req, &new_fsp, NORMAL_CLOSE); return NT_STATUS_OK; } @@ -8476,7 +8470,7 @@ static NTSTATUS smb_posix_mkdir(connection_struct *conn, TALLOC_FREE(posx); if (NT_STATUS_IS_OK(status)) { - close_file(req, fsp, NORMAL_CLOSE); + close_file_free(req, &fsp, NORMAL_CLOSE); } info_level_return = SVAL(pdata,16); @@ -8744,7 +8738,7 @@ static NTSTATUS smb_posix_open(connection_struct *conn, /* Realloc the data size */ *ppdata = (char *)SMB_REALLOC(*ppdata,*pdata_return_size); if (*ppdata == NULL) { - close_file(req, fsp, ERROR_CLOSE); + close_file_free(req, &fsp, ERROR_CLOSE); *pdata_return_size = 0; return NT_STATUS_NO_MEMORY; } @@ -8872,7 +8866,7 @@ static NTSTATUS smb_posix_unlink(connection_struct *conn, if (lck == NULL) { DEBUG(0, ("smb_posix_unlink: Could not get share mode " "lock for file %s\n", fsp_str_dbg(fsp))); - close_file(req, fsp, NORMAL_CLOSE); + close_file_free(req, &fsp, NORMAL_CLOSE); return NT_STATUS_INVALID_PARAMETER; } @@ -8880,7 +8874,7 @@ static NTSTATUS smb_posix_unlink(connection_struct *conn, if (other_nonposix_opens) { /* Fail with sharing violation. */ TALLOC_FREE(lck); - close_file(req, fsp, NORMAL_CLOSE); + close_file_free(req, &fsp, NORMAL_CLOSE); return NT_STATUS_SHARING_VIOLATION; } @@ -8896,10 +8890,10 @@ static NTSTATUS smb_posix_unlink(connection_struct *conn, TALLOC_FREE(lck); if (!NT_STATUS_IS_OK(status)) { - close_file(req, fsp, NORMAL_CLOSE); + close_file_free(req, &fsp, NORMAL_CLOSE); return status; } - return close_file(req, fsp, NORMAL_CLOSE); + return close_file_free(req, &fsp, NORMAL_CLOSE); } static NTSTATUS smbd_do_posix_setfilepathinfo(struct connection_struct *conn, @@ -9666,8 +9660,7 @@ static void call_trans2mkdir(connection_struct *conn, struct smb_request *req, out: if (fsp != NULL) { - close_file(NULL, fsp, NORMAL_CLOSE); - fsp = NULL; + close_file_free(NULL, &fsp, NORMAL_CLOSE); } TALLOC_FREE(smb_dname); return; @@ -9904,8 +9897,7 @@ void reply_findclose(struct smb_request *req) fsp = dptr_fetch_lanman2_fsp(sconn, dptr_num); dptr_num = -1; if (fsp != NULL) { - close_file(NULL, fsp, NORMAL_CLOSE); - fsp = NULL; + close_file_free(NULL, &fsp, NORMAL_CLOSE); } } diff --git a/source3/utils/net_vfs.c b/source3/utils/net_vfs.c index 73eda3e5cdac..53e4583af398 100644 --- a/source3/utils/net_vfs.c +++ b/source3/utils/net_vfs.c @@ -283,23 +283,22 @@ static int net_vfs_get_ntacl(struct net_context *net, goto done; } - status = close_file(NULL, fsp, NORMAL_CLOSE); + status = close_file_free(NULL, &fsp, NORMAL_CLOSE); if (!NT_STATUS_IS_OK(status)) { DBG_ERR("close_file [%s] failed: %s\n", smb_fname_str_dbg(smb_fname), nt_errstr(status)); goto done; } - fsp = NULL; sec_desc_print(NULL, stdout, sd, true); rc = 0; done: if (fsp != NULL) { - status = close_file(NULL, fsp, NORMAL_CLOSE); + status = close_file_free(NULL, &fsp, NORMAL_CLOSE); if (!NT_STATUS_IS_OK(status)) { - DBG_ERR("close_file [%s] failed: %s\n", + DBG_ERR("close_file_free() [%s] failed: %s\n", smb_fname_str_dbg(smb_fname), nt_errstr(status)); rc = 1;