summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalph Boehme <slow@samba.org>2020-09-26 21:46:51 +0200
committerRalph Boehme <slow@samba.org>2020-12-16 09:08:30 +0000
commit50ce980902c9bd76bb4e800fb7d142013605e737 (patch)
tree882bbb4f1a20f9a935b88fda9324704c06129b95
parent28f43fdadc89bdc2e3041fe077df2389acd0ceaa (diff)
downloadsamba-50ce980902c9bd76bb4e800fb7d142013605e737.tar.gz
smbd: use fsp_set_fd()
No change in behaviour. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
-rw-r--r--source3/modules/vfs_aio_fork.c2
-rw-r--r--source3/modules/vfs_commit.c2
-rw-r--r--source3/modules/vfs_dirsort.c2
-rw-r--r--source3/modules/vfs_fruit.c14
-rw-r--r--source3/modules/vfs_shadow_copy.c4
-rw-r--r--source3/modules/vfs_shadow_copy2.c18
-rw-r--r--source3/modules/vfs_streams_xattr.c2
-rw-r--r--source3/modules/vfs_xattr_tdb.c22
-rw-r--r--source3/printing/printspoolss.c3
-rw-r--r--source3/smbd/conn.c2
-rw-r--r--source3/smbd/dir.c4
-rw-r--r--source3/smbd/fake_file.c2
-rw-r--r--source3/smbd/files.c2
-rw-r--r--source3/smbd/open.c4
-rw-r--r--source3/smbd/pipes.c2
-rw-r--r--source3/smbd/pysmbd.c16
-rw-r--r--source3/smbd/vfs.c6
-rw-r--r--source3/torture/cmd_vfs.c48
-rw-r--r--source3/wscript_build1
19 files changed, 84 insertions, 72 deletions
diff --git a/source3/modules/vfs_aio_fork.c b/source3/modules/vfs_aio_fork.c
index 7c6f4b00fd0..0b74e4e05c0 100644
--- a/source3/modules/vfs_aio_fork.c
+++ b/source3/modules/vfs_aio_fork.c
@@ -421,7 +421,7 @@ static struct files_struct *close_fsp_fd(struct files_struct *fsp,
{
if ((fsp->fh != NULL) && (fsp->fh->fd != -1)) {
close(fsp->fh->fd);
- fsp->fh->fd = -1;
+ fsp_set_fd(fsp, -1);
}
return NULL;
}
diff --git a/source3/modules/vfs_commit.c b/source3/modules/vfs_commit.c
index fae94329af3..4c6142e83dc 100644
--- a/source3/modules/vfs_commit.c
+++ b/source3/modules/vfs_commit.c
@@ -240,7 +240,7 @@ static int commit_openat(struct vfs_handle_struct *handle,
* but also practiced elsewhere -
* needed for calling the VFS.
*/
- fsp->fh->fd = fd;
+ fsp_set_fd(fsp, fd);
if (SMB_VFS_FSTAT(fsp, &st) == -1) {
int saved_errno = errno;
SMB_VFS_CLOSE(fsp);
diff --git a/source3/modules/vfs_dirsort.c b/source3/modules/vfs_dirsort.c
index f43a5f0b98a..3b3d609563d 100644
--- a/source3/modules/vfs_dirsort.c
+++ b/source3/modules/vfs_dirsort.c
@@ -165,7 +165,7 @@ static DIR *dirsort_fdopendir(vfs_handle_struct *handle,
SMB_VFS_NEXT_CLOSEDIR(handle,data->source_directory);
TALLOC_FREE(data);
/* fd is now closed. */
- fsp->fh->fd = -1;
+ fsp_set_fd(fsp, -1);
return NULL;
}
diff --git a/source3/modules/vfs_fruit.c b/source3/modules/vfs_fruit.c
index 8a843407596..31e2ccef3c9 100644
--- a/source3/modules/vfs_fruit.c
+++ b/source3/modules/vfs_fruit.c
@@ -1490,10 +1490,10 @@ static int fruit_open_rsrc_adouble(vfs_handle_struct *handle,
goto exit;
}
- fsp->fh->fd = hostfd;
+ fsp_set_fd(fsp, hostfd);
rc = ad_fset(handle, ad, fsp);
- fsp->fh->fd = -1;
+ fsp_set_fd(fsp, -1);
if (rc != 0) {
rc = -1;
goto exit;
@@ -1514,7 +1514,7 @@ exit:
* fd_close_posix here, but we don't have a
* full fsp yet
*/
- fsp->fh->fd = hostfd;
+ fsp_set_fd(fsp, hostfd);
SMB_VFS_CLOSE(fsp);
}
hostfd = -1;
@@ -1670,7 +1670,7 @@ static int fruit_close_meta(vfs_handle_struct *handle,
case FRUIT_META_NETATALK:
ret = close(fsp->fh->fd);
- fsp->fh->fd = -1;
+ fsp_set_fd(fsp, -1);
break;
default:
@@ -1699,7 +1699,7 @@ static int fruit_close_rsrc(vfs_handle_struct *handle,
case FRUIT_RSRC_XATTR:
ret = close(fsp->fh->fd);
- fsp->fh->fd = -1;
+ fsp_set_fd(fsp, -1);
break;
default:
@@ -2459,10 +2459,10 @@ static ssize_t fruit_pwrite_meta_stream(vfs_handle_struct *handle,
int fd;
ret = SMB_VFS_NEXT_CLOSE(handle, fsp);
+ fsp_set_fd(fsp, -1);
if (ret != 0) {
DBG_ERR("Close [%s] failed: %s\n",
fsp_str_dbg(fsp), strerror(errno));
- fsp->fh->fd = -1;
return -1;
}
@@ -2477,7 +2477,7 @@ static ssize_t fruit_pwrite_meta_stream(vfs_handle_struct *handle,
fsp_str_dbg(fsp), strerror(errno));
return -1;
}
- fsp->fh->fd = fd;
+ fsp_set_fd(fsp, fd);
fio->fake_fd = false;
}
diff --git a/source3/modules/vfs_shadow_copy.c b/source3/modules/vfs_shadow_copy.c
index 31333dc2239..79f20979127 100644
--- a/source3/modules/vfs_shadow_copy.c
+++ b/source3/modules/vfs_shadow_copy.c
@@ -89,7 +89,7 @@ static DIR *shadow_copy_fdopendir(vfs_handle_struct *handle, files_struct *fsp,
DEBUG(0,("shadow_copy_fdopendir: Out of memory\n"));
SMB_VFS_NEXT_CLOSEDIR(handle,p);
/* We have now closed the fd in fsp. */
- fsp->fh->fd = -1;
+ fsp_set_fd(fsp, -1);
return NULL;
}
@@ -121,7 +121,7 @@ static DIR *shadow_copy_fdopendir(vfs_handle_struct *handle, files_struct *fsp,
SMB_VFS_NEXT_CLOSEDIR(handle,p);
/* We have now closed the fd in fsp. */
- fsp->fh->fd = -1;
+ fsp_set_fd(fsp, -1);
return((DIR *)dirp);
}
diff --git a/source3/modules/vfs_shadow_copy2.c b/source3/modules/vfs_shadow_copy2.c
index 665080060d2..b449e20ac0d 100644
--- a/source3/modules/vfs_shadow_copy2.c
+++ b/source3/modules/vfs_shadow_copy2.c
@@ -1952,6 +1952,7 @@ static int shadow_copy2_get_shadow_copy_data(
bool get_snaplist = false;
bool access_granted = false;
int open_flags = O_RDONLY;
+ int fd;
int ret = -1;
NTSTATUS status;
@@ -2001,18 +2002,19 @@ static int shadow_copy2_get_shadow_copy_data(
open_flags |= O_DIRECTORY;
#endif
- dirfsp->fh->fd = SMB_VFS_NEXT_OPENAT(handle,
- fspcwd,
- snapdir_smb_fname,
- dirfsp,
- open_flags,
- 0);
- if (dirfsp->fh->fd == -1) {
+ fd = SMB_VFS_NEXT_OPENAT(handle,
+ fspcwd,
+ snapdir_smb_fname,
+ dirfsp,
+ open_flags,
+ 0);
+ if (fd == -1) {
DBG_WARNING("SMB_VFS_NEXT_OPEN failed for '%s'"
" - %s\n", snapdir, strerror(errno));
errno = ENOSYS;
goto done;
}
+ fsp_set_fd(dirfsp, fd);
p = SMB_VFS_NEXT_FDOPENDIR(handle, dirfsp, NULL, 0);
if (!p) {
@@ -2121,7 +2123,7 @@ done:
* VFS_CLOSEDIR implicitly
* closed the associated fd.
*/
- dirfsp->fh->fd = -1;
+ fsp_set_fd(dirfsp, -1);
}
}
if (dirfsp != NULL) {
diff --git a/source3/modules/vfs_streams_xattr.c b/source3/modules/vfs_streams_xattr.c
index 2f786327835..f564efcb6e7 100644
--- a/source3/modules/vfs_streams_xattr.c
+++ b/source3/modules/vfs_streams_xattr.c
@@ -515,7 +515,7 @@ static int streams_xattr_close(vfs_handle_struct *handle,
}
ret = close(fd);
- fsp->fh->fd = -1;
+ fsp_set_fd(fsp, -1);
return ret;
}
diff --git a/source3/modules/vfs_xattr_tdb.c b/source3/modules/vfs_xattr_tdb.c
index c8cc247345d..67b1a120b3b 100644
--- a/source3/modules/vfs_xattr_tdb.c
+++ b/source3/modules/vfs_xattr_tdb.c
@@ -502,21 +502,23 @@ static int xattr_tdb_openat(struct vfs_handle_struct *handle,
struct db_context *db = NULL;
TALLOC_CTX *frame = NULL;
SMB_STRUCT_STAT sbuf;
+ int fd;
int ret;
- fsp->fh->fd = SMB_VFS_NEXT_OPENAT(handle,
- dirfsp,
- smb_fname,
- fsp,
- flags,
- mode);
+ fd = SMB_VFS_NEXT_OPENAT(handle,
+ dirfsp,
+ smb_fname,
+ fsp,
+ flags,
+ mode);
- if (fsp->fh->fd < 0) {
- return fsp->fh->fd;
+ if (fd == -1) {
+ return -1;
}
+ fsp_set_fd(fsp, fd);
if ((flags & (O_CREAT|O_EXCL)) != (O_CREAT|O_EXCL)) {
- return fsp->fh->fd;
+ return fd;
}
/*
@@ -546,7 +548,7 @@ static int xattr_tdb_openat(struct vfs_handle_struct *handle,
xattr_tdb_remove_all_attrs(db, &fsp->file_id);
TALLOC_FREE(frame);
- return fsp->fh->fd;
+ return fd;
}
static int xattr_tdb_mkdirat(vfs_handle_struct *handle,
diff --git a/source3/printing/printspoolss.c b/source3/printing/printspoolss.c
index f3376d8f31e..9c682e59edd 100644
--- a/source3/printing/printspoolss.c
+++ b/source3/printing/printspoolss.c
@@ -25,6 +25,7 @@
#include "rpc_server/rpc_ncacn_np.h"
#include "smbd/globals.h"
#include "../libcli/security/security.h"
+#include "smbd/fd_handle.h"
struct print_file_data {
char *svcname;
@@ -230,7 +231,7 @@ NTSTATUS print_spool_open(files_struct *fsp,
}
fsp->file_id = vfs_file_id_from_sbuf(fsp->conn, &fsp->fsp_name->st);
- fsp->fh->fd = fd;
+ fsp_set_fd(fsp, fd);
fsp->vuid = current_vuid;
fsp->fsp_flags.can_lock = false;
diff --git a/source3/smbd/conn.c b/source3/smbd/conn.c
index 547f55db7d8..04a9dfeea9d 100644
--- a/source3/smbd/conn.c
+++ b/source3/smbd/conn.c
@@ -108,7 +108,7 @@ connection_struct *conn_new(struct smbd_server_connection *sconn)
}
conn->sconn = sconn;
conn->force_group_gid = (gid_t)-1;
- conn->cwd_fsp->fh->fd = -1;
+ fsp_set_fd(conn->cwd_fsp, -1);
conn->cwd_fsp->fnum = FNUM_FIELD_INVALID;
conn->cwd_fsp->conn = conn;
diff --git a/source3/smbd/dir.c b/source3/smbd/dir.c
index 73eb2d17166..7c2dbb14056 100644
--- a/source3/smbd/dir.c
+++ b/source3/smbd/dir.c
@@ -1339,7 +1339,7 @@ static int smb_Dir_destructor(struct smb_Dir *dir_hnd)
files_struct *fsp = dir_hnd->fsp;
SMB_VFS_CLOSEDIR(dir_hnd->conn, dir_hnd->dir);
- fsp->fh->fd = -1;
+ fsp_set_fd(fsp, -1);
if (fsp->dptr != NULL) {
SMB_ASSERT(fsp->dptr->dir_hnd == dir_hnd);
fsp->dptr->dir_hnd = NULL;
@@ -1412,7 +1412,7 @@ static struct smb_Dir *OpenDir_fsp(TALLOC_CTX *mem_ctx, connection_struct *conn,
goto fail;
}
- if (fsp->fh->fd == -1) {
+ if (fsp_get_io_fd(fsp) == -1) {
errno = EBADF;
goto fail;
}
diff --git a/source3/smbd/fake_file.c b/source3/smbd/fake_file.c
index 90921a65e36..705fe0c00ec 100644
--- a/source3/smbd/fake_file.c
+++ b/source3/smbd/fake_file.c
@@ -167,7 +167,7 @@ NTSTATUS open_fake_file(struct smb_request *req, connection_struct *conn,
(unsigned int)access_mask));
fsp->conn = conn;
- fsp->fh->fd = -1;
+ fsp_set_fd(fsp, -1);
fsp->vuid = current_vuid;
fsp->fh->pos = -1;
fsp->fsp_flags.can_lock = false; /* Should this be true ? - No, JRA */
diff --git a/source3/smbd/files.c b/source3/smbd/files.c
index ada9a5fd473..02d3b060552 100644
--- a/source3/smbd/files.c
+++ b/source3/smbd/files.c
@@ -57,7 +57,7 @@ NTSTATUS fsp_new(struct connection_struct *conn, TALLOC_CTX *mem_ctx,
#endif
fsp->fh->ref_count = 1;
- fsp->fh->fd = -1;
+ fsp_set_fd(fsp, -1);
fsp->fnum = FNUM_FIELD_INVALID;
fsp->conn = conn;
diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index c487cd273f1..a5e4f5cdc81 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -824,7 +824,7 @@ NTSTATUS fd_open(files_struct *fsp,
return status;
}
- fsp->fh->fd = fd;
+ fsp_set_fd(fsp, fd);
DBG_DEBUG("name %s, flags = 0%o mode = 0%o, fd = %d\n",
smb_fname_str_dbg(smb_fname), flags, (int)mode, fd);
@@ -859,7 +859,7 @@ NTSTATUS fd_close(files_struct *fsp)
}
ret = SMB_VFS_CLOSE(fsp);
- fsp->fh->fd = -1;
+ fsp_set_fd(fsp, -1);
if (ret == -1) {
return map_nt_error_from_unix(errno);
}
diff --git a/source3/smbd/pipes.c b/source3/smbd/pipes.c
index 785cbb23b5f..4338971d7fa 100644
--- a/source3/smbd/pipes.c
+++ b/source3/smbd/pipes.c
@@ -50,7 +50,7 @@ NTSTATUS open_np_file(struct smb_request *smb_req, const char *name,
}
fsp->conn = conn;
- fsp->fh->fd = -1;
+ fsp_set_fd(fsp, -1);
fsp->vuid = smb_req->vuid;
fsp->fsp_flags.can_lock = false;
fsp->access_mask = FILE_READ_DATA | FILE_WRITE_DATA;
diff --git a/source3/smbd/pysmbd.c b/source3/smbd/pysmbd.c
index dd4a70ca256..034d0621c02 100644
--- a/source3/smbd/pysmbd.c
+++ b/source3/smbd/pysmbd.c
@@ -155,6 +155,7 @@ static NTSTATUS init_files_struct(TALLOC_CTX *mem_ctx,
struct files_struct **_fsp)
{
struct smb_filename *smb_fname = NULL;
+ int fd;
int ret;
mode_t saved_umask;
struct files_struct *fsp;
@@ -191,22 +192,23 @@ static NTSTATUS init_files_struct(TALLOC_CTX *mem_ctx,
*/
saved_umask = umask(0);
- fsp->fh->fd = SMB_VFS_OPENAT(conn,
- fspcwd,
- smb_fname,
- fsp,
- flags,
- 00644);
+ fd = SMB_VFS_OPENAT(conn,
+ fspcwd,
+ smb_fname,
+ fsp,
+ flags,
+ 00644);
umask(saved_umask);
- if (fsp->fh->fd == -1) {
+ if (fd == -1) {
int err = errno;
if (err == ENOENT) {
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
}
return NT_STATUS_INVALID_PARAMETER;
}
+ fsp_set_fd(fsp, fd);
ret = SMB_VFS_FSTAT(fsp, &smb_fname->st);
if (ret == -1) {
diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c
index 1c8368b060c..b4a265e346d 100644
--- a/source3/smbd/vfs.c
+++ b/source3/smbd/vfs.c
@@ -921,7 +921,7 @@ int vfs_ChDir(connection_struct *conn, const struct smb_filename *smb_fname)
* tree connect to a share with the same underlying
* path (may or may not the same share).
*/
- conn->cwd_fsp->fh->fd = AT_FDCWD;
+ fsp_set_fd(conn->cwd_fsp, AT_FDCWD);
return 0;
}
@@ -985,7 +985,7 @@ int vfs_ChDir(connection_struct *conn, const struct smb_filename *smb_fname)
talloc_move(talloc_tos(), &conn->cwd_fsp->fsp_name);
conn->cwd_fsp->fsp_name = talloc_move(conn->cwd_fsp, &cwd);
- conn->cwd_fsp->fh->fd = AT_FDCWD;
+ fsp_set_fd(conn->cwd_fsp, AT_FDCWD);
DBG_INFO("vfs_ChDir got %s\n", fsp_str_dbg(conn->cwd_fsp));
@@ -1620,7 +1620,7 @@ NTSTATUS vfs_at_fspcwd(TALLOC_CTX *mem_ctx,
return NT_STATUS_NO_MEMORY;
}
- fsp->fh->fd = AT_FDCWD;
+ fsp_set_fd(fsp, AT_FDCWD);
fsp->fnum = FNUM_FIELD_INVALID;
fsp->conn = conn;
diff --git a/source3/torture/cmd_vfs.c b/source3/torture/cmd_vfs.c
index 7f3b7e04e48..cae2042ae72 100644
--- a/source3/torture/cmd_vfs.c
+++ b/source3/torture/cmd_vfs.c
@@ -298,6 +298,7 @@ static NTSTATUS cmd_open(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, c
struct smb_filename *smb_fname = NULL;
NTSTATUS status;
int ret;
+ int fd;
mode = 00400;
@@ -399,18 +400,19 @@ static NTSTATUS cmd_open(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, c
return status;
}
- fsp->fh->fd = SMB_VFS_OPENAT(vfs->conn,
- fspcwd,
- smb_fname,
- fsp,
- flags,
- mode);
- if (fsp->fh->fd == -1) {
+ fd = SMB_VFS_OPENAT(vfs->conn,
+ fspcwd,
+ smb_fname,
+ fsp,
+ flags,
+ mode);
+ if (fd == -1) {
printf("open: error=%d (%s)\n", errno, strerror(errno));
TALLOC_FREE(fsp);
TALLOC_FREE(smb_fname);
return NT_STATUS_UNSUCCESSFUL;
}
+ fsp_set_fd(fsp, fd);
status = NT_STATUS_OK;
ret = SMB_VFS_FSTAT(fsp, &smb_fname->st);
@@ -1626,6 +1628,7 @@ static NTSTATUS cmd_set_nt_acl(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int a
struct smb_filename *smb_fname = NULL;
NTSTATUS status;
struct security_descriptor *sd = NULL;
+ int fd;
if (argc != 3) {
printf("Usage: set_nt_acl <file> <sddl>\n");
@@ -1667,26 +1670,27 @@ static NTSTATUS cmd_set_nt_acl(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int a
return status;
}
- fsp->fh->fd = SMB_VFS_OPENAT(vfs->conn,
- fspcwd,
- smb_fname,
- fsp,
- O_RDWR,
- mode);
- if (fsp->fh->fd == -1 && errno == EISDIR) {
- fsp->fh->fd = SMB_VFS_OPENAT(vfs->conn,
- fspcwd,
- smb_fname,
- fsp,
- flags,
- mode);
- }
- if (fsp->fh->fd == -1) {
+ fd = SMB_VFS_OPENAT(vfs->conn,
+ fspcwd,
+ smb_fname,
+ fsp,
+ O_RDWR,
+ mode);
+ if (fd == -1 && errno == EISDIR) {
+ fd = SMB_VFS_OPENAT(vfs->conn,
+ fspcwd,
+ smb_fname,
+ fsp,
+ flags,
+ mode);
+ }
+ if (fd == -1) {
printf("open: error=%d (%s)\n", errno, strerror(errno));
TALLOC_FREE(fsp);
TALLOC_FREE(smb_fname);
return NT_STATUS_UNSUCCESSFUL;
}
+ fsp_set_fd(fsp, fd);
status = NT_STATUS_OK;
ret = SMB_VFS_FSTAT(fsp, &smb_fname->st);
diff --git a/source3/wscript_build b/source3/wscript_build
index b0ef06ebcb6..708ddd7ed45 100644
--- a/source3/wscript_build
+++ b/source3/wscript_build
@@ -733,6 +733,7 @@ bld.SAMBA3_LIBRARY('smbd_base',
vfs_acl_common
NDR_QUOTA
GNUTLS_HELPERS
+ fd_handle
''' +
bld.env['dmapi_lib'] +
bld.env['legacy_quota_libs'] +