]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: add fd_handle.[c|h]
authorRalph Boehme <slow@samba.org>
Sun, 27 Sep 2020 11:14:30 +0000 (13:14 +0200)
committerRalph Boehme <slow@samba.org>
Wed, 16 Dec 2020 09:08:30 +0000 (09:08 +0000)
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/fd_handle.c [new file with mode: 0644]
source3/smbd/fd_handle.h [new file with mode: 0644]
source3/smbd/smbd.h
source3/wscript_build

diff --git a/source3/smbd/fd_handle.c b/source3/smbd/fd_handle.c
new file mode 100644 (file)
index 0000000..ba614ee
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+   Unix SMB/CIFS implementation.
+   fd_handle structure handling
+   Copyright (C) Ralph Boehme 2020
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "fd_handle.h"
+
+struct fd_handle *fd_handle_create(TALLOC_CTX *mem_ctx)
+{
+       struct fd_handle *fh = NULL;
+
+       fh = talloc_zero(mem_ctx, struct fd_handle);
+       if (fh == NULL) {
+               return NULL;
+       }
+       fh->fd = -1;
+       return fh;
+}
+
+size_t fh_get_refcount(struct fd_handle *fh)
+{
+       return fh->ref_count;
+}
+
+void fh_set_refcount(struct fd_handle *fh, size_t ref_count)
+{
+       fh->ref_count = ref_count;
+}
+
+uint64_t fh_get_position_information(struct fd_handle *fh)
+{
+       return fh->position_information;
+}
+
+void fh_set_position_information(struct fd_handle *fh, uint64_t posinfo)
+{
+       fh->position_information = posinfo;
+}
+
+off_t fh_get_pos(struct fd_handle *fh)
+{
+       return fh->pos;
+}
+
+void fh_set_pos(struct fd_handle *fh, off_t pos)
+{
+       fh->pos = pos;
+}
+
+uint32_t fh_get_private_options(struct fd_handle *fh)
+{
+       return fh->private_options;
+}
+
+void fh_set_private_options(struct fd_handle *fh, uint32_t private_options)
+{
+       fh->private_options = private_options;
+}
+
+uint64_t fh_get_gen_id(struct fd_handle *fh)
+{
+       return fh->gen_id;
+}
+
+void fh_set_gen_id(struct fd_handle *fh, uint64_t gen_id)
+{
+       fh->gen_id = gen_id;
+}
+
+/****************************************************************************
+ Helper functions for working with fsp->fh->fd
+****************************************************************************/
+
+int fsp_get_io_fd(const struct files_struct *fsp)
+{
+       if (fsp->fsp_flags.is_pathref) {
+               DBG_ERR("fsp [%s] is a path referencing fsp\n",
+                       fsp_str_dbg(fsp));
+#ifdef DEVELOPER
+               smb_panic("fsp is a pathref");
+#endif
+               return -1;
+       }
+
+       return fsp->fh->fd;
+}
+
+int fsp_get_pathref_fd(const struct files_struct *fsp)
+{
+       return fsp->fh->fd;
+}
+
+void fsp_set_fd(struct files_struct *fsp, int fd)
+{
+       /*
+        * Deliberatly allow setting an fd if the existing fd is the
+        * same. This happens if a VFS module assigns the fd to
+        * fsp->fh->fd in its openat VFS function. The canonical place
+        * where the assignment is done is in fd_open(), but some VFS
+        * modules do it anyway.
+        */
+
+       SMB_ASSERT(fsp->fh->fd == -1 ||
+                  fsp->fh->fd == fd ||
+                  fd == -1 ||
+                  fd == AT_FDCWD);
+
+       fsp->fh->fd = fd;
+}
diff --git a/source3/smbd/fd_handle.h b/source3/smbd/fd_handle.h
new file mode 100644 (file)
index 0000000..052db1d
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+   Unix SMB/CIFS implementation.
+   Files handle structure handling
+   Copyright (C) Ralph Boehme 2020
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef FD_HANDLE_H
+#define FD_HANDLE_H
+
+#include "includes.h"
+#include "smbd/smbd.h"
+#include "smbd/globals.h"
+
+struct fd_handle *fd_handle_create(TALLOC_CTX *mem_ctx);
+
+size_t fh_get_refcount(struct fd_handle *fh);
+void fh_set_refcount(struct fd_handle *fh, size_t ref_count);
+
+uint64_t fh_get_position_information(struct fd_handle *fh);
+void fh_set_position_information(struct fd_handle *fh, uint64_t posinfo);
+
+off_t fh_get_pos(struct fd_handle *fh);
+void fh_set_pos(struct fd_handle *fh, off_t pos);
+
+uint32_t fh_get_private_options(struct fd_handle *fh);
+void fh_set_private_options(struct fd_handle *fh, uint32_t private_options);
+
+uint64_t fh_get_gen_id(struct fd_handle *fh);
+void fh_set_gen_id(struct fd_handle *fh, uint64_t gen_id);
+
+int fsp_get_io_fd(const struct files_struct *fsp);
+int fsp_get_pathref_fd(const struct files_struct *fsp);
+void fsp_set_fd(struct files_struct *fsp, int fd);
+
+#endif
index fb277bde780d9a0d0cb0005662311341db5619eb..84fcf033a71a43e50fbe4546d35eef910cf2fa5a 100644 (file)
@@ -25,6 +25,7 @@ struct dptr_struct;
 #include "vfs.h"
 #include "smbd/proto.h"
 #include "locking/proto.h"
+#include "smbd/fd_handle.h"
 
 struct trans_state {
        struct trans_state *next, *prev;
index 22e2bc7deeaaa746923b43277928dcefc031769b..b0ef06ebcb6da9ed096e7be96ff45c2337da5148 100644 (file)
@@ -1087,6 +1087,9 @@ bld.SAMBA3_SUBSYSTEM('ADOUBLE',
 bld.SAMBA3_SUBSYSTEM('STRING_REPLACE',
                     source='lib/string_replace.c')
 
+bld.SAMBA3_SUBSYSTEM('fd_handle',
+                    source='smbd/fd_handle.c')
+
 ########################## BINARIES #################################
 
 bld.SAMBA3_BINARY('smbd/smbd',