mirror of
https://github.com/samba-team/samba.git
synced 2025-03-27 22:50:26 +03:00
smbd: Replace SMB_VFS_CLOSE() calls with fd_close()
fd_close() mostly wraps SMB_VFS_CLOSE() but also takes care of refcounting fsp->fh properly and also makes sure that fsp->fh->fd is set to -1 after close. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
This commit is contained in:
parent
e6c8b38ecf
commit
529e6718c0
@ -837,15 +837,15 @@ NTSTATUS vfs_default_durable_reconnect(struct connection_struct *conn,
|
||||
|
||||
ret = SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st);
|
||||
if (ret == -1) {
|
||||
NTSTATUS close_status;
|
||||
status = map_nt_error_from_unix_common(errno);
|
||||
DEBUG(1, ("Unable to fstat stream: %s => %s\n",
|
||||
smb_fname_str_dbg(smb_fname),
|
||||
nt_errstr(status)));
|
||||
ret = SMB_VFS_CLOSE(fsp);
|
||||
if (ret == -1) {
|
||||
DEBUG(0, ("vfs_default_durable_reconnect: "
|
||||
"SMB_VFS_CLOSE failed (%s) - leaking file "
|
||||
"descriptor\n", strerror(errno)));
|
||||
close_status = fd_close(fsp);
|
||||
if (!NT_STATUS_IS_OK(close_status)) {
|
||||
DBG_ERR("fd_close failed (%s) - leaking file "
|
||||
"descriptor\n", nt_errstr(close_status));
|
||||
}
|
||||
TALLOC_FREE(lck);
|
||||
op->compat = NULL;
|
||||
@ -855,11 +855,10 @@ NTSTATUS vfs_default_durable_reconnect(struct connection_struct *conn,
|
||||
}
|
||||
|
||||
if (!S_ISREG(fsp->fsp_name->st.st_ex_mode)) {
|
||||
ret = SMB_VFS_CLOSE(fsp);
|
||||
if (ret == -1) {
|
||||
DEBUG(0, ("vfs_default_durable_reconnect: "
|
||||
"SMB_VFS_CLOSE failed (%s) - leaking file "
|
||||
"descriptor\n", strerror(errno)));
|
||||
NTSTATUS close_status = fd_close(fsp);
|
||||
if (!NT_STATUS_IS_OK(close_status)) {
|
||||
DBG_ERR("fd_close failed (%s) - leaking file "
|
||||
"descriptor\n", nt_errstr(close_status));
|
||||
}
|
||||
TALLOC_FREE(lck);
|
||||
op->compat = NULL;
|
||||
@ -870,11 +869,10 @@ NTSTATUS vfs_default_durable_reconnect(struct connection_struct *conn,
|
||||
|
||||
file_id = vfs_file_id_from_sbuf(conn, &fsp->fsp_name->st);
|
||||
if (!file_id_equal(&cookie.id, &file_id)) {
|
||||
ret = SMB_VFS_CLOSE(fsp);
|
||||
if (ret == -1) {
|
||||
DEBUG(0, ("vfs_default_durable_reconnect: "
|
||||
"SMB_VFS_CLOSE failed (%s) - leaking file "
|
||||
"descriptor\n", strerror(errno)));
|
||||
NTSTATUS close_status = fd_close(fsp);
|
||||
if (!NT_STATUS_IS_OK(close_status)) {
|
||||
DBG_ERR("fd_close failed (%s) - leaking file "
|
||||
"descriptor\n", nt_errstr(close_status));
|
||||
}
|
||||
TALLOC_FREE(lck);
|
||||
op->compat = NULL;
|
||||
@ -889,11 +887,10 @@ NTSTATUS vfs_default_durable_reconnect(struct connection_struct *conn,
|
||||
&fsp->fsp_name->st,
|
||||
fsp_str_dbg(fsp));
|
||||
if (!ok) {
|
||||
ret = SMB_VFS_CLOSE(fsp);
|
||||
if (ret == -1) {
|
||||
DEBUG(0, ("vfs_default_durable_reconnect: "
|
||||
"SMB_VFS_CLOSE failed (%s) - leaking file "
|
||||
"descriptor\n", strerror(errno)));
|
||||
NTSTATUS close_status = fd_close(fsp);
|
||||
if (!NT_STATUS_IS_OK(close_status)) {
|
||||
DBG_ERR("fd_close failed (%s) - leaking file "
|
||||
"descriptor\n", nt_errstr(close_status));
|
||||
}
|
||||
TALLOC_FREE(lck);
|
||||
op->compat = NULL;
|
||||
@ -904,13 +901,10 @@ NTSTATUS vfs_default_durable_reconnect(struct connection_struct *conn,
|
||||
|
||||
status = set_file_oplock(fsp);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
DEBUG(1, ("vfs_default_durable_reconnect failed to set oplock "
|
||||
"after opening file: %s\n", nt_errstr(status)));
|
||||
ret = SMB_VFS_CLOSE(fsp);
|
||||
if (ret == -1) {
|
||||
DEBUG(0, ("vfs_default_durable_reconnect: "
|
||||
"SMB_VFS_CLOSE failed (%s) - leaking file "
|
||||
"descriptor\n", strerror(errno)));
|
||||
NTSTATUS close_status = fd_close(fsp);
|
||||
if (!NT_STATUS_IS_OK(close_status)) {
|
||||
DBG_ERR("fd_close failed (%s) - leaking file "
|
||||
"descriptor\n", nt_errstr(close_status));
|
||||
}
|
||||
TALLOC_FREE(lck);
|
||||
op->compat = NULL;
|
||||
|
@ -801,10 +801,8 @@ static NTSTATUS non_widelink_open(const struct files_struct *dirfsp,
|
||||
* and errno=ELOOP.
|
||||
*/
|
||||
if (S_ISLNK(fsp->fsp_name->st.st_ex_mode)) {
|
||||
ret = SMB_VFS_CLOSE(fsp);
|
||||
SMB_ASSERT(ret == 0);
|
||||
|
||||
fsp_set_fd(fsp, -1);
|
||||
status = fd_close(fsp);
|
||||
SMB_ASSERT(NT_STATUS_IS_OK(status));
|
||||
fd = -1;
|
||||
status = NT_STATUS_STOPPED_ON_SYMLINK;
|
||||
}
|
||||
@ -1158,7 +1156,6 @@ static NTSTATUS reopen_from_procfd(struct files_struct *fsp,
|
||||
int old_fd;
|
||||
int new_fd;
|
||||
NTSTATUS status;
|
||||
int ret;
|
||||
|
||||
if (!fsp->fsp_flags.have_proc_fds) {
|
||||
return NT_STATUS_MORE_PROCESSING_REQUIRED;
|
||||
@ -1197,15 +1194,13 @@ static NTSTATUS reopen_from_procfd(struct files_struct *fsp,
|
||||
mode);
|
||||
if (new_fd == -1) {
|
||||
status = map_nt_error_from_unix(errno);
|
||||
SMB_VFS_CLOSE(fsp);
|
||||
fsp_set_fd(fsp, -1);
|
||||
fd_close(fsp);
|
||||
return status;
|
||||
}
|
||||
|
||||
ret = SMB_VFS_CLOSE(fsp);
|
||||
fsp_set_fd(fsp, -1);
|
||||
if (ret != 0) {
|
||||
return map_nt_error_from_unix(errno);
|
||||
status = fd_close(fsp);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
fsp_set_fd(fsp, new_fd);
|
||||
|
@ -282,7 +282,7 @@ static NTSTATUS set_nt_acl_conn(const char *fname,
|
||||
DBG_ERR("init_files_struct failed: %s\n",
|
||||
nt_errstr(status));
|
||||
if (fsp != NULL) {
|
||||
SMB_VFS_CLOSE(fsp);
|
||||
fd_close(fsp);
|
||||
}
|
||||
TALLOC_FREE(frame);
|
||||
return status;
|
||||
@ -293,7 +293,7 @@ static NTSTATUS set_nt_acl_conn(const char *fname,
|
||||
DEBUG(0,("set_nt_acl_no_snum: fset_nt_acl returned %s.\n", nt_errstr(status)));
|
||||
}
|
||||
|
||||
SMB_VFS_CLOSE(fsp);
|
||||
fd_close(fsp);
|
||||
|
||||
TALLOC_FREE(frame);
|
||||
return status;
|
||||
@ -631,7 +631,7 @@ static PyObject *py_smbd_chown(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||
DBG_ERR("init_files_struct failed: %s\n",
|
||||
nt_errstr(status));
|
||||
if (fsp != NULL) {
|
||||
SMB_VFS_CLOSE(fsp);
|
||||
fd_close(fsp);
|
||||
}
|
||||
TALLOC_FREE(frame);
|
||||
/*
|
||||
@ -644,13 +644,13 @@ static PyObject *py_smbd_chown(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||
ret = SMB_VFS_FCHOWN(fsp, uid, gid);
|
||||
if (ret != 0) {
|
||||
int saved_errno = errno;
|
||||
SMB_VFS_CLOSE(fsp);
|
||||
fd_close(fsp);
|
||||
TALLOC_FREE(frame);
|
||||
errno = saved_errno;
|
||||
return PyErr_SetFromErrno(PyExc_OSError);
|
||||
}
|
||||
|
||||
SMB_VFS_CLOSE(fsp);
|
||||
fd_close(fsp);
|
||||
TALLOC_FREE(frame);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
@ -1230,7 +1230,7 @@ static PyObject *py_smbd_create_file(PyObject *self, PyObject *args, PyObject *k
|
||||
DBG_ERR("init_files_struct failed: %s\n",
|
||||
nt_errstr(status));
|
||||
} else if (fsp != NULL) {
|
||||
SMB_VFS_CLOSE(fsp);
|
||||
fd_close(fsp);
|
||||
}
|
||||
|
||||
TALLOC_FREE(frame);
|
||||
|
@ -429,7 +429,7 @@ static NTSTATUS cmd_open(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, c
|
||||
}
|
||||
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
SMB_VFS_CLOSE(fsp);
|
||||
fd_close(fsp);
|
||||
TALLOC_FREE(fsp);
|
||||
TALLOC_FREE(smb_fname);
|
||||
return status;
|
||||
@ -513,7 +513,8 @@ static NTSTATUS cmd_pathfunc(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int arg
|
||||
|
||||
static NTSTATUS cmd_close(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
|
||||
{
|
||||
int fd, ret;
|
||||
int fd;
|
||||
NTSTATUS status;
|
||||
|
||||
if (argc != 2) {
|
||||
printf("Usage: close <fd>\n");
|
||||
@ -526,15 +527,15 @@ static NTSTATUS cmd_close(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
|
||||
return NT_STATUS_OK;
|
||||
}
|
||||
|
||||
ret = SMB_VFS_CLOSE(vfs->files[fd]);
|
||||
if (ret == -1 )
|
||||
printf("close: error=%d (%s)\n", errno, strerror(errno));
|
||||
status = fd_close(vfs->files[fd]);
|
||||
if (!NT_STATUS_IS_OK(status))
|
||||
printf("close: error=%s\n", nt_errstr(status));
|
||||
else
|
||||
printf("close: ok\n");
|
||||
|
||||
TALLOC_FREE(vfs->files[fd]);
|
||||
vfs->files[fd] = NULL;
|
||||
return NT_STATUS_OK;
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -1816,9 +1817,9 @@ static NTSTATUS cmd_set_nt_acl(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int a
|
||||
out:
|
||||
TALLOC_FREE(sd);
|
||||
|
||||
ret = SMB_VFS_CLOSE(fsp);
|
||||
if (ret == -1 )
|
||||
printf("close: error=%d (%s)\n", errno, strerror(errno));
|
||||
status = fd_close(fsp);
|
||||
if (!NT_STATUS_IS_OK(status))
|
||||
printf("close: error= (%s)\n", nt_errstr(status));
|
||||
|
||||
TALLOC_FREE(fsp);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user