[SCM] Samba Shared Repository - branch master updated

Ralph Böhme slow at samba.org
Tue May 5 13:24:03 UTC 2020


The branch, master has been updated
       via  1be128eeedf smbd: Make share_mode_for_one_entry() use just a uint8*
       via  733ae9cd957 smbd: Make share_mode_do_locked() use a const uint8_t *
       via  14cc4a65767 smbd: Make parse_share_modes() use a const ptr
       via  b2dfd4cc538 smbd: Make share_mode_memcache_fetch() use a const ptr
       via  955b3c3de9a smbd: Convert get_share_mode_blob_header() to use a const ptr
       via  7905afcd772 smbd: Make share_mode_entry_find() take a const pointer
       via  6d3399906fe smbd: Make sure share_mode_entry_do() maintains sorting order
       via  7c3cce98886 smbd: Simplify reset_share_mode_entry()
       via  7cd687fd057 smbd: Simplify share_mode_entry_get()
       via  2e3be1394cc libsmb: Add a NULL check
       via  157554f3d85 libsmb: Align integer types in net_share_enum_rpc()
       via  3d2abb67724 libsmb: Use talloc_strndup() to cut a backslash
       via  2d6448a3df6 libsmb: Add a NULL check after talloc_strdup()
       via  1226f435495 lib: Move push_skip_string() to clirap2.c
       via  1814c14f713 librpc: Align integer types
       via  909c82fe031 net: Add g_lock dumpall
       via  50a1e995cb0 net: "net g_lock locks" needs to print binary keys
       via  abae5889d93 rpc_server3: Align integer types
       via  0ad9273961b lib: Fix a comment
       via  78737c6869d lib: Remove two unused macro definitions
       via  d0deaf90e57 torture4: Move a variable declaration closer to its use
       via  b3dec1bc1f6 registry3: Align a few integer types
       via  e96f6b0f886 locking: Move br_off typedef to where it's used
       via  489023e4810 locking: Move SMB_OFF_T_BITS macro to its only user
       via  652242f542e vfs_virusfilter: Fix canonicalizing socket path
       via  e3e902f5704 vfs_widelinks: Fix small typos
      from  0847f56f243 pytdb tests: add test for storev()

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 1be128eeedf2a4634a31e5b6a1c0f4b5f3f88345
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Apr 27 13:16:00 2020 +0200

    smbd: Make share_mode_for_one_entry() use just a uint8*
    
    "num_share_modes" is passed separately, so "data.dsize" was not used
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>
    
    Autobuild-User(master): Ralph Böhme <slow at samba.org>
    Autobuild-Date(master): Tue May  5 13:23:49 UTC 2020 on sn-devel-184

commit 733ae9cd95701f781d78af72015d64d3e6706f0c
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Apr 24 11:07:53 2020 +0200

    smbd: Make share_mode_do_locked() use a const uint8_t *
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 14cc4a65767ea069e0ad03bb423f84f66a9e41ca
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Apr 24 09:14:55 2020 +0200

    smbd: Make parse_share_modes() use a const ptr
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit b2dfd4cc5384d3eeb328bebe69de17b3aaa90040
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Apr 24 09:04:27 2020 +0200

    smbd: Make share_mode_memcache_fetch() use a const ptr
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 955b3c3de9a0835372ba908ebe4dd1e4e1014401
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Apr 24 08:55:35 2020 +0200

    smbd: Convert get_share_mode_blob_header() to use a const ptr
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 7905afcd772dd5258f4f2932d486092576e0802a
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Apr 24 15:58:59 2020 +0200

    smbd: Make share_mode_entry_find() take a const pointer
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 6d3399906fe56cb0bd5245bfefb94391bbd0d32c
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Apr 27 15:59:09 2020 +0200

    smbd: Make sure share_mode_entry_do() maintains sorting order
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 7c3cce98886ca31b293e3dd1ad905ed215812919
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Apr 24 17:30:44 2020 +0200

    smbd: Simplify reset_share_mode_entry()
    
    This has more lines, but it's a lot simpler: reset_share_mode_entry is
    only called during durable reconnect, which only works with a single
    share mode entry. See durable_reconnect_fn(). Thus we don't have to
    keep the share mode array sorted, there is just a single entry.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 7cd687fd05719eee0acd72a2f2bf045841ff895b
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Apr 23 17:00:25 2020 +0200

    smbd: Simplify share_mode_entry_get()
    
    If we don't use a DATA_BLOB, we can more correctly state in the
    prototype that the buffer we parse is constant.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 2e3be1394ccd0fa7800fe5ab336a28a716335dac
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Feb 21 22:07:19 2020 +0100

    libsmb: Add a NULL check
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 157554f3d85277341fc4c9566392ff76e24ed17c
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Apr 20 09:56:51 2020 +0200

    libsmb: Align integer types in net_share_enum_rpc()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 3d2abb67724d23270da43948506772262760a7c1
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Apr 21 08:05:57 2020 +0200

    libsmb: Use talloc_strndup() to cut a backslash
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 2d6448a3df643d0bbcfe40726c13aa15a36bfd5e
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Apr 21 08:02:35 2020 +0200

    libsmb: Add a NULL check after talloc_strdup()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 1226f435495cabaf95eda3280f75dd0388cde5a1
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Apr 29 09:07:20 2020 +0200

    lib: Move push_skip_string() to clirap2.c
    
    It's only used there
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 1814c14f71367dc718328820507b0e97f4216ff6
Author: Volker Lendecke <vl at samba.org>
Date:   Fri May 1 19:26:40 2020 +0200

    librpc: Align integer types
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 909c82fe0310c9dd5bd64719c87a2378e987decd
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Apr 28 12:18:40 2020 +0200

    net: Add g_lock dumpall
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 50a1e995cb0d8b9d88297d6b0e959c964a77fc17
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Apr 28 12:08:14 2020 +0200

    net: "net g_lock locks" needs to print binary keys
    
    In 2017 g_lock changed to take TDB_DATA as a key
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit abae5889d930daf5cf532f1a9ca4ddb5b8c53dea
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Apr 27 10:25:47 2020 +0200

    rpc_server3: Align integer types
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 0ad9273961bb0b14e78bd02e6062eb2bba45af47
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Apr 28 16:55:55 2020 +0200

    lib: Fix a comment
    
    The "deleted bit" went away with 341223a00596e
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 78737c6869d3d797cac1e3696a201c3e2d276872
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Apr 27 12:22:53 2020 +0200

    lib: Remove two unused macro definitions
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit d0deaf90e579052bf36c3052f5efb7012bcb572c
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Apr 24 08:59:16 2020 +0200

    torture4: Move a variable declaration closer to its use
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit b3dec1bc1f6d4177077e2149282d965949c32ec6
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Apr 24 08:54:35 2020 +0200

    registry3: Align a few integer types
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit e96f6b0f8863ae45fac7475793cd80e673df7bb4
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Apr 27 11:49:55 2020 +0200

    locking: Move br_off typedef to where it's used
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 489023e4810b148b91fb039a6dfa67556ae45cfd
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Apr 27 11:49:20 2020 +0200

    locking: Move SMB_OFF_T_BITS macro to its only user
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 652242f542e9be51338aa32d147682e72a7ddc20
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Apr 23 08:37:01 2020 +0200

    vfs_virusfilter: Fix canonicalizing socket path
    
    canonicalize_absolute_path() returns its result, the previous code was
    a no-op
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit e3e902f57041b1c11fa7dc9e96b928420fa42263
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Apr 23 11:29:02 2020 +0200

    vfs_widelinks: Fix small typos
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 librpc/rpc/dcerpc_util.c          |   2 +-
 source3/include/includes.h        |   5 -
 source3/include/locking.h         |   1 +
 source3/include/proto.h           |   1 -
 source3/include/smb_macros.h      |   2 -
 source3/lib/dbwrap/dbwrap_watch.c |   2 +-
 source3/lib/util_str.c            |  10 --
 source3/libsmb/cli_smb2_fnum.c    |   6 +-
 source3/libsmb/libsmb_dir.c       |   8 +-
 source3/locking/locking.c         |   3 +-
 source3/locking/posix.c           |   2 +
 source3/locking/proto.h           |   3 +-
 source3/locking/share_mode_lock.c | 230 ++++++++++++++++++++++++--------------
 source3/modules/vfs_virusfilter.c |   8 +-
 source3/modules/vfs_widelinks.c   |   4 +-
 source3/registry/reg_objects.c    |   8 +-
 source3/rpc_server/mdssd.c        |   2 +-
 source3/smbd/reply.c              |   5 +-
 source3/utils/clirap2.c           |  10 ++
 source3/utils/net_g_lock.c        |  50 ++++++++-
 source4/torture/rpc/eventlog.c    |   5 +-
 21 files changed, 242 insertions(+), 125 deletions(-)


Changeset truncated at 500 lines:

diff --git a/librpc/rpc/dcerpc_util.c b/librpc/rpc/dcerpc_util.c
index cf6cb942b1c..3d622b2be49 100644
--- a/librpc/rpc/dcerpc_util.c
+++ b/librpc/rpc/dcerpc_util.c
@@ -996,7 +996,7 @@ const char *dcerpc_default_transport_endpoint(TALLOC_CTX *mem_ctx,
 	NTSTATUS status;
 	const char *p = NULL;
 	const char *endpoint = NULL;
-	int i;
+	uint32_t i;
 	struct dcerpc_binding *default_binding = NULL;
 	TALLOC_CTX *frame = talloc_stackframe();
 
diff --git a/source3/include/includes.h b/source3/include/includes.h
index 2dafc65f41a..8fa65cc3122 100644
--- a/source3/include/includes.h
+++ b/source3/include/includes.h
@@ -176,11 +176,6 @@ typedef sig_atomic_t volatile SIG_ATOMIC_T;
 #define BIG_UINT(p, ofs) BVAL(p, ofs)
 #define IVAL2_TO_SMB_BIG_UINT(p, ofs) BVAL(p, ofs)
 
-/* this should really be a 64 bit type if possible */
-typedef uint64_t br_off;
-
-#define SMB_OFF_T_BITS (sizeof(off_t)*8)
-
 /*
  * Set the define that tells us if we can do 64 bit
  * NT SMB calls.
diff --git a/source3/include/locking.h b/source3/include/locking.h
index 0175db2dd47..1aad6626f34 100644
--- a/source3/include/locking.h
+++ b/source3/include/locking.h
@@ -47,6 +47,7 @@ struct files_struct;
 #include "lib/file_id.h"
 
 struct byte_range_lock;
+typedef uint64_t br_off;
 
 /* Internal structure in brlock.tdb.
    The data in brlock records is an unsorted linear array of these
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 0fd6e64fee3..3bd336c1d37 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -584,7 +584,6 @@ bool next_token(const char **ptr, char *buff, const char *sep, size_t bufsize);
 bool strnequal(const char *s1,const char *s2,size_t n);
 bool strcsequal(const char *s1,const char *s2);
 bool strnorm(char *s, int case_default);
-char *push_skip_string(char *buf);
 char *skip_string(const char *base, size_t len, char *buf);
 size_t str_charnum(const char *s);
 bool trim_char(char *s,char cfront,char cback);
diff --git a/source3/include/smb_macros.h b/source3/include/smb_macros.h
index 702be07aacd..90ec794a519 100644
--- a/source3/include/smb_macros.h
+++ b/source3/include/smb_macros.h
@@ -231,9 +231,7 @@ copy an IP address from one buffer to another
 #define SMB_MALLOC_ARRAY(type,count) (type *)malloc_array(sizeof(type),(count))
 #define SMB_MEMALIGN_ARRAY(type,align,count) (type *)memalign_array(sizeof(type),align,(count))
 #define SMB_REALLOC(p,s) Realloc((p),(s),True)	/* Always frees p on error or s == 0 */
-#define SMB_REALLOC_KEEP_OLD_ON_ERROR(p,s) Realloc((p),(s),False) /* Never frees p on error or s == 0 */
 #define SMB_REALLOC_ARRAY(p,type,count) (type *)realloc_array((p),sizeof(type),(count),True) /* Always frees p on error or s == 0 */
-#define SMB_REALLOC_ARRAY_KEEP_OLD_ON_ERROR(p,type,count) (type *)realloc_array((p),sizeof(type),(count),False) /* Never frees p on error or s == 0 */
 #define SMB_CALLOC_ARRAY(type,count) (type *)calloc_array(sizeof(type),(count))
 #define SMB_XMALLOC_P(type) (type *)smb_xmalloc_array(sizeof(type),1)
 #define SMB_XMALLOC_ARRAY(type,count) (type *)smb_xmalloc_array(sizeof(type),(count))
diff --git a/source3/lib/dbwrap/dbwrap_watch.c b/source3/lib/dbwrap/dbwrap_watch.c
index 14d3525047e..206eabc8d5d 100644
--- a/source3/lib/dbwrap/dbwrap_watch.c
+++ b/source3/lib/dbwrap/dbwrap_watch.c
@@ -45,7 +45,7 @@ struct dbwrap_watcher {
 /*
  * Watched records contain a header of:
  *
- * [uint32] num_records | deleted bit
+ * [uint32] num_records
  * 0 [DBWRAP_WATCHER_BUF_LENGTH]              \
  * 1 [DBWRAP_WATCHER_BUF_LENGTH]              |
  * ..                                         |- Array of watchers
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index cc3c257e41d..c62cbe16a59 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -63,16 +63,6 @@ bool strnorm(char *s, int case_default)
 		return strlower_m(s);
 }
 
-/**
- *  Skip past some strings in a buffer - old version - no checks.
- *  **/
-
-char *push_skip_string(char *buf)
-{
-	buf += strlen(buf) + 1;
-	return(buf);
-}
-
 /**
  Skip past a string in a buffer. Buffer may not be
  null terminated. end_ptr points to the first byte after
diff --git a/source3/libsmb/cli_smb2_fnum.c b/source3/libsmb/cli_smb2_fnum.c
index 4cae87853db..d29341c1708 100644
--- a/source3/libsmb/cli_smb2_fnum.c
+++ b/source3/libsmb/cli_smb2_fnum.c
@@ -1549,8 +1549,10 @@ NTSTATUS cli_smb2_qpathinfo_basic(struct cli_state *cli,
 	/* SMB2 is pickier about pathnames. Ensure it doesn't
 	   end in a '\' */
 	if (namelen > 0 && name[namelen-1] == '\\') {
-		char *modname = talloc_strdup(talloc_tos(), name);
-		modname[namelen-1] = '\0';
+		char *modname = talloc_strndup(talloc_tos(), name, namelen-1);
+		if (modname == NULL) {
+			return NT_STATUS_NO_MEMORY;
+		}
 		name = modname;
 	}
 
diff --git a/source3/libsmb/libsmb_dir.c b/source3/libsmb/libsmb_dir.c
index 581dd6b9c1c..36caad88058 100644
--- a/source3/libsmb/libsmb_dir.c
+++ b/source3/libsmb/libsmb_dir.c
@@ -360,7 +360,7 @@ net_share_enum_rpc(struct cli_state *cli,
                               void *state),
                    void *state)
 {
-        int i;
+        uint32_t i;
 	WERROR result;
 	uint32_t preferred_len = 0xffffffff;
         uint32_t type;
@@ -547,6 +547,12 @@ SMBC_opendir_ctx(SMBCCTX *context,
 
 	dir->cli_fd   = 0;
 	dir->fname    = SMB_STRDUP(fname);
+	if (dir->fname == NULL) {
+		SAFE_FREE(dir);
+		TALLOC_FREE(frame);
+		errno = ENOMEM;
+		return NULL;
+	}
 	dir->srv      = NULL;
 	dir->offset   = 0;
 	dir->file     = False;
diff --git a/source3/locking/locking.c b/source3/locking/locking.c
index f5426391c21..a108ebba00d 100644
--- a/source3/locking/locking.c
+++ b/source3/locking/locking.c
@@ -250,7 +250,8 @@ struct do_lock_state {
 };
 
 static void do_lock_fn(
-	TDB_DATA value,
+	const uint8_t *buf,
+	size_t buflen,
 	bool *modified_dependent,
 	void *private_data)
 {
diff --git a/source3/locking/posix.c b/source3/locking/posix.c
index 32f8317776e..e2eda225590 100644
--- a/source3/locking/posix.c
+++ b/source3/locking/posix.c
@@ -84,6 +84,8 @@ static const char *posix_lock_type_name(int lock_type)
  False if not.
 ****************************************************************************/
 
+#define SMB_OFF_T_BITS (sizeof(off_t)*8)
+
 static bool posix_lock_in_range(off_t *offset_out, off_t *count_out,
 				uint64_t u_offset, uint64_t u_count)
 {
diff --git a/source3/locking/proto.h b/source3/locking/proto.h
index b7098c1e788..f4c68bc5ca4 100644
--- a/source3/locking/proto.h
+++ b/source3/locking/proto.h
@@ -144,7 +144,8 @@ bool file_has_read_lease(struct files_struct *fsp);
 struct db_record;
 NTSTATUS share_mode_do_locked(
 	struct file_id id,
-	void (*fn)(TDB_DATA value,
+	void (*fn)(const uint8_t *buf,
+		   size_t buflen,
 		   bool *modified_dependent,
 		   void *private_data),
 	void *private_data);
diff --git a/source3/locking/share_mode_lock.c b/source3/locking/share_mode_lock.c
index ed96541c36d..de59b8d2545 100644
--- a/source3/locking/share_mode_lock.c
+++ b/source3/locking/share_mode_lock.c
@@ -211,9 +211,12 @@ static void share_mode_memcache_store(struct share_mode_data *d)
  */
 
 static enum ndr_err_code get_share_mode_blob_header(
-	DATA_BLOB *blob, uint64_t *pseq, uint16_t *pflags)
+	const uint8_t *buf, size_t buflen, uint64_t *pseq, uint16_t *pflags)
 {
-	struct ndr_pull ndr = {.data = blob->data, .data_size = blob->length};
+	struct ndr_pull ndr = {
+		.data = discard_const_p(uint8_t, buf),
+		.data_size = buflen,
+	};
 	NDR_CHECK(ndr_pull_hyper(&ndr, NDR_SCALARS, pseq));
 	NDR_CHECK(ndr_pull_uint16(&ndr, NDR_SCALARS, pflags));
 	return NDR_ERR_SUCCESS;
@@ -225,14 +228,16 @@ struct fsp_update_share_mode_flags_state {
 };
 
 static void fsp_update_share_mode_flags_fn(
-	TDB_DATA value, bool *modified_dependent, void *private_data)
+	const uint8_t *buf,
+	size_t buflen,
+	bool *modified_dependent,
+	void *private_data)
 {
 	struct fsp_update_share_mode_flags_state *state = private_data;
-	DATA_BLOB blob = { .data = value.dptr, .length = value.dsize };
 	uint64_t seq;
 
 	state->ndr_err = get_share_mode_blob_header(
-		&blob, &seq, &state->share_mode_flags);
+		buf, buflen, &seq, &state->share_mode_flags);
 }
 
 static NTSTATUS fsp_update_share_mode_flags(struct files_struct *fsp)
@@ -283,9 +288,11 @@ static int share_mode_data_nofree_destructor(struct share_mode_data *d)
 	return -1;
 }
 
-static struct share_mode_data *share_mode_memcache_fetch(TALLOC_CTX *mem_ctx,
-					const TDB_DATA id_key,
-					DATA_BLOB *blob)
+static struct share_mode_data *share_mode_memcache_fetch(
+	TALLOC_CTX *mem_ctx,
+	const TDB_DATA id_key,
+	const uint8_t *buf,
+	size_t buflen)
 {
 	enum ndr_err_code ndr_err;
 	struct share_mode_data *d;
@@ -313,7 +320,8 @@ static struct share_mode_data *share_mode_memcache_fetch(TALLOC_CTX *mem_ctx,
 		return NULL;
 	}
 	/* sequence number key is at start of blob. */
-	ndr_err = get_share_mode_blob_header(blob, &sequence_number, &flags);
+	ndr_err = get_share_mode_blob_header(
+		buf, buflen, &sequence_number, &flags);
 	if (ndr_err != NDR_ERR_SUCCESS) {
 		/* Bad blob. Remove entry. */
 		DBG_DEBUG("bad blob %u key %s\n",
@@ -368,19 +376,18 @@ static struct share_mode_data *share_mode_memcache_fetch(TALLOC_CTX *mem_ctx,
  Get all share mode entries for a dev/inode pair.
 ********************************************************************/
 
-static struct share_mode_data *parse_share_modes(TALLOC_CTX *mem_ctx,
-						const TDB_DATA key,
-						const TDB_DATA dbuf)
+static struct share_mode_data *parse_share_modes(
+	TALLOC_CTX *mem_ctx,
+	const TDB_DATA key,
+	const uint8_t *buf,
+	size_t buflen)
 {
 	struct share_mode_data *d;
 	enum ndr_err_code ndr_err;
 	DATA_BLOB blob;
 
-	blob.data = dbuf.dptr;
-	blob.length = dbuf.dsize;
-
 	/* See if we already have a cached copy of this key. */
-	d = share_mode_memcache_fetch(mem_ctx, key, &blob);
+	d = share_mode_memcache_fetch(mem_ctx, key, buf, buflen);
 	if (d != NULL) {
 		return d;
 	}
@@ -391,6 +398,10 @@ static struct share_mode_data *parse_share_modes(TALLOC_CTX *mem_ctx,
 		goto fail;
 	}
 
+	blob = (DATA_BLOB) {
+		.data = discard_const_p(uint8_t, buf),
+		.length = buflen,
+	};
 	ndr_err = ndr_pull_struct_blob_all(
 		&blob, d, d, (ndr_pull_flags_fn_t)ndr_pull_share_mode_data);
 	if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
@@ -573,7 +584,7 @@ static NTSTATUS get_static_share_mode_data(
 		}
 	} else {
 		TDB_DATA key = locking_key(&id);
-		d = parse_share_modes(lock_db, key, value);
+		d = parse_share_modes(lock_db, key, value.dptr, value.dsize);
 		if (d == NULL) {
 			return NT_STATUS_INTERNAL_DB_CORRUPTION;
 		}
@@ -715,7 +726,8 @@ static int share_mode_lock_destructor(struct share_mode_lock *lck)
 }
 
 struct share_mode_do_locked_state {
-	void (*fn)(TDB_DATA value,
+	void (*fn)(const uint8_t *buf,
+		   size_t buflen,
 		   bool *modified_dependent,
 		   void *private_data);
 	void *private_data;
@@ -739,7 +751,10 @@ static void share_mode_do_locked_fn(
 		SMB_ASSERT(static_share_mode_record == rec);
 	}
 
-	state->fn(value, &modified_dependent, state->private_data);
+	state->fn(value.dptr,
+		  value.dsize,
+		  &modified_dependent,
+		  state->private_data);
 
 	if (modified_dependent) {
 		dbwrap_watched_wakeup(rec);
@@ -752,7 +767,8 @@ static void share_mode_do_locked_fn(
 
 NTSTATUS share_mode_do_locked(
 	struct file_id id,
-	void (*fn)(TDB_DATA value,
+	void (*fn)(const uint8_t *buf,
+		   size_t buflen,
 		   bool *modified_dependent,
 		   void *private_data),
 	void *private_data)
@@ -774,7 +790,8 @@ NTSTATUS share_mode_do_locked(
 			return NT_STATUS_INVALID_LOCK_SEQUENCE;
 		}
 
-		fn(static_share_mode_record_value,
+		fn(static_share_mode_record_value.dptr,
+		   static_share_mode_record_value.dsize,
 		   &modified_dependent,
 		   private_data);
 
@@ -801,9 +818,11 @@ NTSTATUS share_mode_do_locked(
 	return NT_STATUS_OK;
 }
 
-static void share_mode_wakeup_waiters_fn(TDB_DATA value,
-					 bool *modified_dependent,
-					 void *private_data)
+static void share_mode_wakeup_waiters_fn(
+	const uint8_t *buf,
+	size_t buflen,
+	bool *modified_dependent,
+	void *private_data)
 {
 	*modified_dependent = true;
 }
@@ -826,7 +845,10 @@ struct share_mode_watch_state {
 };
 
 static void share_mode_watch_fn(
-	TDB_DATA value, bool *modified_dependent, void *private_data)
+	const uint8_t *buf,
+	size_t buflen,
+	bool *modified_dependent,
+	void *private_data)
 {
 	struct share_mode_watch_state *state = talloc_get_type_abort(
 		private_data, struct share_mode_watch_state);
@@ -922,7 +944,8 @@ static void fetch_share_mode_unlocked_parser(
 		return;
 	}
 
-	state->lck->data = parse_share_modes(state->lck, key, data);
+	state->lck->data = parse_share_modes(
+		state->lck, key, data.dptr, data.dsize);
 }
 
 /*******************************************************************
@@ -1438,9 +1461,13 @@ static bool share_mode_entry_put(
 }
 
 static bool share_mode_entry_get(
-	DATA_BLOB blob, struct share_mode_entry *e)
+	const uint8_t ptr[SHARE_MODE_ENTRY_SIZE], struct share_mode_entry *e)
 {
 	enum ndr_err_code ndr_err = NDR_ERR_SUCCESS;
+	DATA_BLOB blob = {
+		.data = discard_const_p(uint8_t, ptr),
+		.length = SHARE_MODE_ENTRY_SIZE,
+	};
 
 	ndr_err = ndr_pull_struct_blob_all_noalloc(
 		&blob, e, (ndr_pull_flags_fn_t)ndr_pull_share_mode_entry);
@@ -1452,7 +1479,7 @@ static bool share_mode_entry_get(
 }
 
 static size_t share_mode_entry_find(
-	uint8_t *data,
+	const uint8_t *data,
 	size_t num_share_modes,
 	struct server_id pid,
 	uint64_t share_file_id,
@@ -1470,27 +1497,20 @@ static size_t share_mode_entry_find(
 	right = (num_share_modes-1);
 
 	while (left <= right) {
-		DATA_BLOB blob;
+		const uint8_t *middle_ptr = NULL;
 		int cmp;
 		bool ok;
 
 		middle = left + ((right - left) / 2);
+		middle_ptr = data + middle * SHARE_MODE_ENTRY_SIZE;
 
-		DBG_DEBUG("left=%zu, right=%zu, middle=%zu\n",
+		DBG_DEBUG("left=%zu, right=%zu, middle=%zu, middle_ptr=%p\n",
 			  left,
 			  right,
-			  middle);
-
-		blob = (DATA_BLOB) {
-			.data = data + middle * SHARE_MODE_ENTRY_SIZE,
-			.length = SHARE_MODE_ENTRY_SIZE,
-		};
-
-		DBG_DEBUG("blob.data=%p, blob.length=%zu\n",
-			  blob.data,
-			  blob.length);
+			  middle,
+			  middle_ptr);
 
-		ok = share_mode_entry_get(blob, e);
+		ok = share_mode_entry_get(middle_ptr, e);
 		if (!ok) {
 			DBG_DEBUG("share_mode_entry_get failed\n");
 			return false;
@@ -1669,12 +1689,12 @@ struct share_mode_forall_entries_state {
 static bool share_mode_for_one_entry(
 	struct share_mode_forall_entries_state *state,
 	size_t *i,
+	uint8_t *data,
 	size_t *num_share_modes,
-	TDB_DATA data,
 	bool *writeback)
 {
 	DATA_BLOB blob = {
-		.data = data.dptr + (*i) * SHARE_MODE_ENTRY_SIZE,
+		.data = data + (*i) * SHARE_MODE_ENTRY_SIZE,
 		.length = SHARE_MODE_ENTRY_SIZE,
 	};
 	struct share_mode_entry e = {.pid.pid=0};
@@ -1782,7 +1802,7 @@ static void share_mode_forall_entries_fn(
 	i = 0;
 	while (i<num_share_modes) {
 		stop = share_mode_for_one_entry(
-			state, &i, &num_share_modes, data, &writeback);
+			state, &i, data.dptr, &num_share_modes, &writeback);
 		if (stop) {
 			break;
 		}
@@ -1965,7 +1985,17 @@ static void share_mode_entry_do_fn(
 	}
 
 	if (!e.stale) {
-		bool ok = share_mode_entry_put(&e, &buf);
+		bool ok;
+
+		if (state->num_share_modes != 1) {
+			/*
+			 * Make sure the sorting order stays intact
+			 */
+			SMB_ASSERT(server_id_equal(&e.pid, &state->pid));
+			SMB_ASSERT(e.share_file_id == state->share_file_id);
+		}
+
+		ok = share_mode_entry_put(&e, &buf);
 		if (!ok) {
 			DBG_DEBUG("share_mode_entry_put failed\n");
 			state->status = NT_STATUS_INTERNAL_ERROR;
@@ -2244,17 +2274,72 @@ bool mark_share_mode_disconnected(struct share_mode_lock *lck,
 	return true;
 }
 
-static void reset_share_mode_entry_del_fn(
-	struct share_mode_entry *e,
-	size_t num_share_modes,
-	bool *modified,
-	void *private_data)
+struct reset_share_mode_entry_state {
+	struct server_id old_pid;
+	uint64_t old_share_file_id;
+	struct server_id new_pid;
+	uint64_t new_mid;
+	uint64_t new_share_file_id;
+	bool ok;
+};
+
+static void reset_share_mode_entry_fn(
+	struct db_record *rec, TDB_DATA value, void *private_data)
 {
-	struct set_share_mode_state *state = private_data;
+	struct reset_share_mode_entry_state *state = private_data;
+	struct share_mode_entry e;
+	struct share_mode_entry_buf e_buf;


-- 
Samba Shared Repository



More information about the samba-cvs mailing list