[PATCH] Remove "file_id" from share_mode_entry

Jeremy Allison jra at samba.org
Mon Feb 12 22:47:18 UTC 2018


On Sun, Feb 11, 2018 at 01:40:06PM +0100, Volker Lendecke via samba-technical wrote:
> Hi!
> 
> share_mode_entries are always part of a locking.tdb entry. Those
> entries are per inode, and a "struct file_id" describes that. The
> "file_id" (24 bytes) is redunant in the share mode entry, we can
> always access that via the share_mode_data.
> 
> Review appreciated!

That is a really nice cleanup, and a great catch that
this value is redundant in the shared databases (the
less in there the better). Was this one my fault ?

Anyway, RB+ and pushed !

Thanks,

	Jeremy.

> -- 
> Besuchen Sie die verinice.XP 2018 in Berlin,
> Anwenderkonferenz für Informationssicherheit
> vom 21.-23.03.2018 im Sofitel Kurfürstendamm
> Info & Anmeldung hier: http://veriniceXP.org
> 
> SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
> phone: +49-551-370000-0, fax: +49-551-370000-9
> AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
> http://www.sernet.de, mailto:kontakt at sernet.de

> From 01827555196c0173af978618370625ce33d41efb Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Wed, 7 Feb 2018 10:05:57 +0100
> Subject: [PATCH 01/16] smbd: Fix a signed/unsigned hickup
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source3/locking/locking.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/source3/locking/locking.c b/source3/locking/locking.c
> index 4e9f1bbc681..8e63bfc4a69 100644
> --- a/source3/locking/locking.c
> +++ b/source3/locking/locking.c
> @@ -860,7 +860,7 @@ struct share_mode_entry *find_share_mode_entry(
>  {
>  	struct share_mode_data *d = lck->data;
>  	struct server_id pid;
> -	int i;
> +	uint32_t i;
>  
>  	pid = messaging_server_id(fsp->conn->sconn->msg_ctx);
>  
> -- 
> 2.11.0
> 
> 
> From 902d636320dcf28a8968d3bab413d73f41df3044 Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Wed, 7 Feb 2018 10:43:11 +0100
> Subject: [PATCH 02/16] smbd: Pass "file_id" through share_entry_forall
> 
> It's also in the share_entry, but that is redundant and will go
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source3/locking/proto.h                   | 1 +
>  source3/locking/share_mode_lock.c         | 3 +++
>  source3/rpc_server/srvsvc/srv_srvsvc_nt.c | 6 +++++-
>  source3/utils/status.c                    | 1 +
>  4 files changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/source3/locking/proto.h b/source3/locking/proto.h
> index 33184e0fa0a..671b8327e49 100644
> --- a/source3/locking/proto.h
> +++ b/source3/locking/proto.h
> @@ -210,6 +210,7 @@ int share_mode_forall(int (*fn)(struct file_id fid,
>  				void *private_data),
>  		      void *private_data);
>  int share_entry_forall(int (*fn)(const struct share_mode_entry *,
> +				 const struct file_id *id,
>  				 const char *, const char *,
>  				 const char *, void *),
>  		      void *private_data);
> diff --git a/source3/locking/share_mode_lock.c b/source3/locking/share_mode_lock.c
> index cee00458079..fce0c335ec3 100644
> --- a/source3/locking/share_mode_lock.c
> +++ b/source3/locking/share_mode_lock.c
> @@ -879,6 +879,7 @@ int share_mode_forall(int (*fn)(struct file_id fid,
>  
>  struct share_entry_forall_state {
>  	int (*fn)(const struct share_mode_entry *e,
> +		  const struct file_id *id,
>  		  const char *service_path,
>  		  const char *base_name,
>  		  const char *stream_name,
> @@ -897,6 +898,7 @@ static int share_entry_traverse_fn(struct file_id fid,
>  		int ret;
>  
>  		ret = state->fn(&data->share_modes[i],
> +				&data->id,
>  				data->servicepath,
>  				data->base_name,
>  				data->stream_name,
> @@ -915,6 +917,7 @@ static int share_entry_traverse_fn(struct file_id fid,
>  ********************************************************************/
>  
>  int share_entry_forall(int (*fn)(const struct share_mode_entry *,
> +				 const struct file_id *id,
>  				 const char *, const char *,
>  				 const char *, void *),
>  		       void *private_data)
> diff --git a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
> index 2ff8e64fccc..19e63053ece 100644
> --- a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
> +++ b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
> @@ -82,6 +82,7 @@ struct share_conn_stat {
>  ********************************************************************/
>  
>  static int enum_file_fn(const struct share_mode_entry *e,
> +			const struct file_id *id,
>  			const char *sharepath,
>  			const char *fname,
>  			const char *sname,
> @@ -173,7 +174,7 @@ static WERROR net_enum_files(TALLOC_CTX *ctx,
>  	f_enum_cnt.username = username;
>  	f_enum_cnt.ctr3 = *ctr3;
>  
> -	share_entry_forall( enum_file_fn, (void *)&f_enum_cnt );
> +	share_entry_forall(enum_file_fn, (void *)&f_enum_cnt );
>  
>  	*ctr3 = f_enum_cnt.ctr3;
>  
> @@ -841,6 +842,7 @@ static WERROR init_srv_sess_info_0(struct pipes_struct *p,
>   **********************************************************************/
>  
>  static int count_sess_files_fn(const struct share_mode_entry *e,
> +			       const struct file_id *id,
>  			       const char *sharepath,
>  			       const char *fname,
>  			       const char *sname,
> @@ -968,6 +970,7 @@ static WERROR init_srv_sess_info_1(struct pipes_struct *p,
>   ********************************************************************/
>  
>  static int share_file_fn(const struct share_mode_entry *e,
> +			 const struct file_id *id,
>  			 const char *sharepath,
>  			 const char *fname,
>  			 const char *sname,
> @@ -2699,6 +2702,7 @@ struct enum_file_close_state {
>  };
>  
>  static int enum_file_close_fn(const struct share_mode_entry *e,
> +			      const struct file_id *id,
>  			      const char *sharepath,
>  			      const char *fname,
>  			      const char *sname,
> diff --git a/source3/utils/status.c b/source3/utils/status.c
> index dfb1d921a42..beae85c4d3e 100644
> --- a/source3/utils/status.c
> +++ b/source3/utils/status.c
> @@ -117,6 +117,7 @@ static bool Ucrit_addPid( struct server_id pid )
>  }
>  
>  static int print_share_mode(const struct share_mode_entry *e,
> +			    const struct file_id *id,
>  			    const char *sharepath,
>  			    const char *fname,
>  			    const char *sname,
> -- 
> 2.11.0
> 
> 
> From 7444129073a4eb342b0433aa39022215b4fc53d8 Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Wed, 7 Feb 2018 10:52:23 +0100
> Subject: [PATCH 03/16] srvsvc: Use the passed-in file id, not the one from
>  share_mode_entry
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source3/rpc_server/srvsvc/srv_srvsvc_nt.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
> index 19e63053ece..0d15381e31c 100644
> --- a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
> +++ b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
> @@ -124,7 +124,7 @@ static int enum_file_fn(const struct share_mode_entry *e,
>  	/* need to count the number of locks on a file */
>  
>  	ZERO_STRUCT( fsp );
> -	fsp.file_id = e->id;
> +	fsp.file_id = *id;
>  
>  	if ( (brl = brl_get_locks(talloc_tos(), &fsp)) != NULL ) {
>  		num_locks = brl_num_locks(brl);
> -- 
> 2.11.0
> 
> 
> From 36d7c06d706396261ca0f969afac8844cb092471 Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Wed, 7 Feb 2018 11:05:33 +0100
> Subject: [PATCH 04/16] smbd: Pass in "file_id" into share_mode_str()
> 
> This used to directly access share_entry->id, which will go
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source3/locking/locking.c                 |  6 ++++--
>  source3/locking/proto.h                   |  4 +++-
>  source3/rpc_server/srvsvc/srv_srvsvc_nt.c |  5 ++---
>  source3/smbd/close.c                      |  2 +-
>  source3/smbd/open.c                       | 10 ++++++----
>  5 files changed, 16 insertions(+), 11 deletions(-)
> 
> diff --git a/source3/locking/locking.c b/source3/locking/locking.c
> index 8e63bfc4a69..6311cda276a 100644
> --- a/source3/locking/locking.c
> +++ b/source3/locking/locking.c
> @@ -425,7 +425,9 @@ void locking_close_file(struct messaging_context *msg_ctx,
>   Print out a share mode.
>  ********************************************************************/
>  
> -char *share_mode_str(TALLOC_CTX *ctx, int num, const struct share_mode_entry *e)
> +char *share_mode_str(TALLOC_CTX *ctx, int num,
> +		     const struct file_id *id,
> +		     const struct share_mode_entry *e)
>  {
>  	struct server_id_buf tmp;
>  
> @@ -439,7 +441,7 @@ char *share_mode_str(TALLOC_CTX *ctx, int num, const struct share_mode_entry *e)
>  		 e->access_mask, (unsigned long long)e->op_mid,
>  		 e->op_type, (unsigned long long)e->share_file_id,
>  		 (unsigned int)e->uid, (unsigned int)e->flags,
> -		 file_id_string_tos(&e->id),
> +		 file_id_string_tos(id),
>  		 (unsigned int)e->name_hash);
>  }
>  
> diff --git a/source3/locking/proto.h b/source3/locking/proto.h
> index 671b8327e49..afd5373772a 100644
> --- a/source3/locking/proto.h
> +++ b/source3/locking/proto.h
> @@ -140,7 +140,9 @@ void locking_close_file(struct messaging_context *msg_ctx,
>  bool locking_init(void);
>  bool locking_init_readonly(void);
>  bool locking_end(void);
> -char *share_mode_str(TALLOC_CTX *ctx, int num, const struct share_mode_entry *e);
> +char *share_mode_str(TALLOC_CTX *ctx, int num,
> +		     const struct file_id *id,
> +		     const struct share_mode_entry *e);
>  struct share_mode_lock *get_existing_share_mode_lock(TALLOC_CTX *mem_ctx,
>  						     struct file_id id);
>  struct share_mode_lock *get_share_mode_lock(
> diff --git a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
> index 0d15381e31c..8e830ff9112 100644
> --- a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
> +++ b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
> @@ -2722,9 +2722,8 @@ static int enum_file_close_fn(const struct share_mode_entry *e,
>  	}
>  
>  	/* Ok - send the close message. */
> -	DEBUG(10,("enum_file_close_fn: request to close file %s, %s\n",
> -		sharepath,
> -		share_mode_str(talloc_tos(), 0, e) ));
> +	DBG_DEBUG("request to close file %s, %s\n", sharepath,
> +		  share_mode_str(talloc_tos(), 0, &e->id, e));
>  
>  	share_mode_entry_to_message(msg, e);
>  
> diff --git a/source3/smbd/close.c b/source3/smbd/close.c
> index 2f6cc4f0aad..0d60a2258e2 100644
> --- a/source3/smbd/close.c
> +++ b/source3/smbd/close.c
> @@ -1288,7 +1288,7 @@ void msg_close_file(struct messaging_context *msg_ctx,
>  	message_to_share_mode_entry(&e, (char *)data->data);
>  
>  	if(DEBUGLVL(10)) {
> -		char *sm_str = share_mode_str(NULL, 0, &e);
> +		char *sm_str = share_mode_str(NULL, 0, &e.id, &e);
>  		if (!sm_str) {
>  			smb_panic("talloc failed");
>  		}
> diff --git a/source3/smbd/open.c b/source3/smbd/open.c
> index 5817bdbe9ae..57497bcbcd6 100644
> --- a/source3/smbd/open.c
> +++ b/source3/smbd/open.c
> @@ -1566,8 +1566,9 @@ static void validate_my_share_entries(struct smbd_server_connection *sconn,
>  	fsp = file_find_dif(sconn, share_entry->id,
>  			    share_entry->share_file_id);
>  	if (!fsp) {
> -		DEBUG(0,("validate_my_share_entries: PANIC : %s\n",
> -			 share_mode_str(talloc_tos(), num, share_entry) ));
> +		DBG_ERR("PANIC : %s\n",
> +			share_mode_str(talloc_tos(), num, &share_entry->id,
> +				       share_entry));
>  		smb_panic("validate_my_share_entries: Cannot match a "
>  			  "share entry with an open file\n");
>  	}
> @@ -1581,8 +1582,9 @@ static void validate_my_share_entries(struct smbd_server_connection *sconn,
>   panic:
>  	{
>  		char *str;
> -		DEBUG(0,("validate_my_share_entries: PANIC : %s\n",
> -			 share_mode_str(talloc_tos(), num, share_entry) ));
> +		DBG_ERR("validate_my_share_entries: PANIC : %s\n",
> +			share_mode_str(talloc_tos(), num, &share_entry->id,
> +				       share_entry));
>  		str = talloc_asprintf(talloc_tos(),
>  			"validate_my_share_entries: "
>  			"file %s, oplock_type = 0x%x, op_type = 0x%x\n",
> -- 
> 2.11.0
> 
> 
> From a11b00c9bd95dcf46b9b467687b02c484f4d6c3c Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Wed, 7 Feb 2018 11:09:10 +0100
> Subject: [PATCH 05/16] smbd: Pass in "file_id" into validate_my_share_entries
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source3/smbd/open.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/source3/smbd/open.c b/source3/smbd/open.c
> index 57497bcbcd6..9f96d581212 100644
> --- a/source3/smbd/open.c
> +++ b/source3/smbd/open.c
> @@ -1544,6 +1544,7 @@ sa = 0x%x, share = 0x%x\n", (num), (unsigned int)(am), (unsigned int)(right), (u
>  
>  #if defined(DEVELOPER)
>  static void validate_my_share_entries(struct smbd_server_connection *sconn,
> +				      const struct file_id id,
>  				      int num,
>  				      struct share_mode_entry *share_entry)
>  {
> @@ -1563,11 +1564,10 @@ static void validate_my_share_entries(struct smbd_server_connection *sconn,
>  		return;
>  	}
>  
> -	fsp = file_find_dif(sconn, share_entry->id,
> -			    share_entry->share_file_id);
> +	fsp = file_find_dif(sconn, id, share_entry->share_file_id);
>  	if (!fsp) {
>  		DBG_ERR("PANIC : %s\n",
> -			share_mode_str(talloc_tos(), num, &share_entry->id,
> +			share_mode_str(talloc_tos(), num, &id,
>  				       share_entry));
>  		smb_panic("validate_my_share_entries: Cannot match a "
>  			  "share entry with an open file\n");
> @@ -1583,7 +1583,7 @@ static void validate_my_share_entries(struct smbd_server_connection *sconn,
>  	{
>  		char *str;
>  		DBG_ERR("validate_my_share_entries: PANIC : %s\n",
> -			share_mode_str(talloc_tos(), num, &share_entry->id,
> +			share_mode_str(talloc_tos(), num, &id,
>  				       share_entry));
>  		str = talloc_asprintf(talloc_tos(),
>  			"validate_my_share_entries: "
> @@ -1656,7 +1656,7 @@ static NTSTATUS open_mode_check(connection_struct *conn,
>  
>  #if defined(DEVELOPER)
>  	for(i = 0; i < lck->data->num_share_modes; i++) {
> -		validate_my_share_entries(conn->sconn, i,
> +		validate_my_share_entries(conn->sconn, lck->data->id, i,
>  					  &lck->data->share_modes[i]);
>  	}
>  #endif
> -- 
> 2.11.0
> 
> 
> From 6365347b03012baabf78f3ae85199c0a0a1abc74 Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Wed, 7 Feb 2018 11:10:14 +0100
> Subject: [PATCH 06/16] srvsvc: Use the passed-in file_id
> 
> The one in share_mode_entry will go
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source3/rpc_server/srvsvc/srv_srvsvc_nt.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
> index 8e830ff9112..e0561b6e7e0 100644
> --- a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
> +++ b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
> @@ -2723,7 +2723,7 @@ static int enum_file_close_fn(const struct share_mode_entry *e,
>  
>  	/* Ok - send the close message. */
>  	DBG_DEBUG("request to close file %s, %s\n", sharepath,
> -		  share_mode_str(talloc_tos(), 0, &e->id, e));
> +		  share_mode_str(talloc_tos(), 0, id, e));
>  
>  	share_mode_entry_to_message(msg, e);
>  
> -- 
> 2.11.0
> 
> 
> From 9b1ff9b61f23cac338b13b9d3412835e3c0f66d9 Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Wed, 7 Feb 2018 11:13:40 +0100
> Subject: [PATCH 07/16] smbd: Use "share_mode_data->id", not
>  "share_mode_entry->id"
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source3/locking/locking.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/source3/locking/locking.c b/source3/locking/locking.c
> index 6311cda276a..2b5c7c7885f 100644
> --- a/source3/locking/locking.c
> +++ b/source3/locking/locking.c
> @@ -722,7 +722,7 @@ static void remove_share_mode_lease(struct share_mode_data *d,
>  
>  		status = leases_db_del(&client_guid,
>  					&lease_key,
> -					&e->id);
> +					&d->id);
>  
>  		DEBUG(10, ("%s: leases_db_del returned %s\n", __func__,
>  			   nt_errstr(status)));
> -- 
> 2.11.0
> 
> 
> From 2e170b53e8765ea999ee9017f5174862c233b675 Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Wed, 7 Feb 2018 11:14:31 +0100
> Subject: [PATCH 08/16] smbd: Remove a redundant check
> 
> The file ids in all share modes match the share_mode_data's one
> 
> We don't have a paranoia check for this, but the share mode is per inode.
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source3/locking/locking.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/source3/locking/locking.c b/source3/locking/locking.c
> index 2b5c7c7885f..738b997f644 100644
> --- a/source3/locking/locking.c
> +++ b/source3/locking/locking.c
> @@ -875,9 +875,6 @@ struct share_mode_entry *find_share_mode_entry(
>  		if (!serverid_equal(&pid, &e->pid)) {
>  			continue;
>  		}
> -		if (!file_id_equal(&fsp->file_id, &e->id)) {
> -			continue;
> -		}
>  		if (fsp->fh->gen_id != e->share_file_id) {
>  			continue;
>  		}
> -- 
> 2.11.0
> 
> 
> From 1a1f08959c3aa5152f8ee5c70f66ae86e84fceeb Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Wed, 7 Feb 2018 11:36:51 +0100
> Subject: [PATCH 09/16] smbd: Pass "file_id" explicitly into
>  share_mode_entry_to_message()
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source3/rpc_server/srvsvc/srv_srvsvc_nt.c |  2 +-
>  source3/smbd/open.c                       |  2 +-
>  source3/smbd/oplock.c                     | 11 ++++++++---
>  source3/smbd/proto.h                      |  3 ++-
>  4 files changed, 12 insertions(+), 6 deletions(-)
> 
> diff --git a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
> index e0561b6e7e0..8a738b396cd 100644
> --- a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
> +++ b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
> @@ -2725,7 +2725,7 @@ static int enum_file_close_fn(const struct share_mode_entry *e,
>  	DBG_DEBUG("request to close file %s, %s\n", sharepath,
>  		  share_mode_str(talloc_tos(), 0, id, e));
>  
> -	share_mode_entry_to_message(msg, e);
> +	share_mode_entry_to_message(msg, &e->id, e);
>  
>  	state->r->out.result = ntstatus_to_werror(
>  		messaging_send_buf(state->msg_ctx,
> diff --git a/source3/smbd/open.c b/source3/smbd/open.c
> index 9f96d581212..995417bc764 100644
> --- a/source3/smbd/open.c
> +++ b/source3/smbd/open.c
> @@ -1701,7 +1701,7 @@ NTSTATUS send_break_message(struct messaging_context *msg_ctx,
>  		   server_id_str_buf(exclusive->pid, &tmp)));
>  
>  	/* Create the message. */
> -	share_mode_entry_to_message(msg, exclusive);
> +	share_mode_entry_to_message(msg, &exclusive->id, exclusive);
>  
>  	/* Overload entry->op_type */
>  	/*
> diff --git a/source3/smbd/oplock.c b/source3/smbd/oplock.c
> index e848b5e0d86..419296eb060 100644
> --- a/source3/smbd/oplock.c
> +++ b/source3/smbd/oplock.c
> @@ -1134,7 +1134,7 @@ static void send_break_to_none(struct messaging_context *msg_ctx,
>  {
>  	char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE];
>  
> -	share_mode_entry_to_message(msg, e);
> +	share_mode_entry_to_message(msg, &e->id, e);
>  	/* Overload entry->op_type */
>  	SSVAL(msg, OP_BREAK_MSG_OP_TYPE_OFFSET, NO_OPLOCK);
>  
> @@ -1291,7 +1291,8 @@ void smbd_contend_level2_oplocks_end(files_struct *fsp,
>   Linearize a share mode entry struct to an internal oplock break message.
>  ****************************************************************************/
>  
> -void share_mode_entry_to_message(char *msg, const struct share_mode_entry *e)
> +void share_mode_entry_to_message(char *msg, const struct file_id *id,
> +				 const struct share_mode_entry *e)
>  {
>  	SIVAL(msg,OP_BREAK_MSG_PID_OFFSET,(uint32_t)e->pid.pid);
>  	SBVAL(msg,OP_BREAK_MSG_MID_OFFSET,e->op_mid);
> @@ -1301,7 +1302,11 @@ void share_mode_entry_to_message(char *msg, const struct share_mode_entry *e)
>  	SIVAL(msg,OP_BREAK_MSG_PRIV_OFFSET,e->private_options);
>  	SIVAL(msg,OP_BREAK_MSG_TIME_SEC_OFFSET,(uint32_t)e->time.tv_sec);
>  	SIVAL(msg,OP_BREAK_MSG_TIME_USEC_OFFSET,(uint32_t)e->time.tv_usec);
> -	push_file_id_24(msg+OP_BREAK_MSG_DEV_OFFSET, &e->id);
> +	/*
> +	 * "id" used to be part of share_mode_entry, thus the strange
> +	 * place to put this. Feel free to move somewhere else :-)
> +	 */
> +	push_file_id_24(msg+OP_BREAK_MSG_DEV_OFFSET, id);
>  	SIVAL(msg,OP_BREAK_MSG_FILE_ID_OFFSET,e->share_file_id);
>  	SIVAL(msg,OP_BREAK_MSG_UID_OFFSET,e->uid);
>  	SSVAL(msg,OP_BREAK_MSG_FLAGS_OFFSET,e->flags);
> diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h
> index fe376404709..175b92bc1cd 100644
> --- a/source3/smbd/proto.h
> +++ b/source3/smbd/proto.h
> @@ -722,7 +722,8 @@ void smbd_contend_level2_oplocks_begin(files_struct *fsp,
>  				  enum level2_contention_type type);
>  void smbd_contend_level2_oplocks_end(files_struct *fsp,
>  				enum level2_contention_type type);
> -void share_mode_entry_to_message(char *msg, const struct share_mode_entry *e);
> +void share_mode_entry_to_message(char *msg, const struct file_id *id,
> +				 const struct share_mode_entry *e);
>  void message_to_share_mode_entry(struct share_mode_entry *e, const char *msg);
>  bool init_oplocks(struct smbd_server_connection *sconn);
>  void init_kernel_oplocks(struct smbd_server_connection *sconn);
> -- 
> 2.11.0
> 
> 
> From cb59255a0f105e63beaf5b9f440fd9fdd82e9714 Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Wed, 7 Feb 2018 11:39:32 +0100
> Subject: [PATCH 10/16] smbd: Pass "file_id" explicitly to
>  message_to_share_mode_entry()
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source3/smbd/close.c  |  2 +-
>  source3/smbd/oplock.c | 12 +++++++++---
>  source3/smbd/proto.h  |  4 +++-
>  3 files changed, 13 insertions(+), 5 deletions(-)
> 
> diff --git a/source3/smbd/close.c b/source3/smbd/close.c
> index 0d60a2258e2..c7ec3fdb6af 100644
> --- a/source3/smbd/close.c
> +++ b/source3/smbd/close.c
> @@ -1285,7 +1285,7 @@ void msg_close_file(struct messaging_context *msg_ctx,
>  		talloc_get_type_abort(private_data,
>  		struct smbd_server_connection);
>  
> -	message_to_share_mode_entry(&e, (char *)data->data);
> +	message_to_share_mode_entry(&e.id, &e, (char *)data->data);
>  
>  	if(DEBUGLVL(10)) {
>  		char *sm_str = share_mode_str(NULL, 0, &e.id, &e);
> diff --git a/source3/smbd/oplock.c b/source3/smbd/oplock.c
> index 419296eb060..6674c2e5ae7 100644
> --- a/source3/smbd/oplock.c
> +++ b/source3/smbd/oplock.c
> @@ -816,7 +816,7 @@ static void process_oplock_break_message(struct messaging_context *msg_ctx,
>  	}
>  
>  	/* De-linearize incoming message. */
> -	message_to_share_mode_entry(&msg, (char *)data->data);
> +	message_to_share_mode_entry(&msg.id, &msg, (char *)data->data);
>  	break_to = msg.op_type;
>  
>  	DEBUG(10, ("Got oplock break to %u message from pid %s: %s/%llu\n",
> @@ -1318,7 +1318,9 @@ void share_mode_entry_to_message(char *msg, const struct file_id *id,
>   De-linearize an internal oplock break message to a share mode entry struct.
>  ****************************************************************************/
>  
> -void message_to_share_mode_entry(struct share_mode_entry *e, const char *msg)
> +void message_to_share_mode_entry(struct file_id *id,
> +				 struct share_mode_entry *e,
> +				 const char *msg)
>  {
>  	e->pid.pid = (pid_t)IVAL(msg,OP_BREAK_MSG_PID_OFFSET);
>  	e->op_mid = BVAL(msg,OP_BREAK_MSG_MID_OFFSET);
> @@ -1328,7 +1330,11 @@ void message_to_share_mode_entry(struct share_mode_entry *e, const char *msg)
>  	e->private_options = IVAL(msg,OP_BREAK_MSG_PRIV_OFFSET);
>  	e->time.tv_sec = (time_t)IVAL(msg,OP_BREAK_MSG_TIME_SEC_OFFSET);
>  	e->time.tv_usec = (int)IVAL(msg,OP_BREAK_MSG_TIME_USEC_OFFSET);
> -	pull_file_id_24(msg+OP_BREAK_MSG_DEV_OFFSET, &e->id);
> +	/*
> +	 * "id" used to be part of share_mode_entry, thus the strange
> +	 * place to put this. Feel free to move somewhere else :-)
> +	 */
> +	pull_file_id_24(msg+OP_BREAK_MSG_DEV_OFFSET, id);
>  	e->share_file_id = (unsigned long)IVAL(msg,OP_BREAK_MSG_FILE_ID_OFFSET);
>  	e->uid = (uint32_t)IVAL(msg,OP_BREAK_MSG_UID_OFFSET);
>  	e->flags = (uint16_t)SVAL(msg,OP_BREAK_MSG_FLAGS_OFFSET);
> diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h
> index 175b92bc1cd..96636696f91 100644
> --- a/source3/smbd/proto.h
> +++ b/source3/smbd/proto.h
> @@ -724,7 +724,9 @@ void smbd_contend_level2_oplocks_end(files_struct *fsp,
>  				enum level2_contention_type type);
>  void share_mode_entry_to_message(char *msg, const struct file_id *id,
>  				 const struct share_mode_entry *e);
> -void message_to_share_mode_entry(struct share_mode_entry *e, const char *msg);
> +void message_to_share_mode_entry(struct file_id *id,
> +				 struct share_mode_entry *e,
> +				 const char *msg);
>  bool init_oplocks(struct smbd_server_connection *sconn);
>  void init_kernel_oplocks(struct smbd_server_connection *sconn);
>  
> -- 
> 2.11.0
> 
> 
> From 7691492735c55d02036b834d06ad28c40bdef6c5 Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Wed, 7 Feb 2018 11:40:58 +0100
> Subject: [PATCH 11/16] smbd: Avoid a dependency on share_mode_entry->id
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source3/smbd/close.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/source3/smbd/close.c b/source3/smbd/close.c
> index c7ec3fdb6af..3324d3ec4e0 100644
> --- a/source3/smbd/close.c
> +++ b/source3/smbd/close.c
> @@ -1280,15 +1280,16 @@ void msg_close_file(struct messaging_context *msg_ctx,
>  			DATA_BLOB *data)
>  {
>  	files_struct *fsp = NULL;
> +	struct file_id id;
>  	struct share_mode_entry e;
>  	struct smbd_server_connection *sconn =
>  		talloc_get_type_abort(private_data,
>  		struct smbd_server_connection);
>  
> -	message_to_share_mode_entry(&e.id, &e, (char *)data->data);
> +	message_to_share_mode_entry(&id, &e, (char *)data->data);
>  
>  	if(DEBUGLVL(10)) {
> -		char *sm_str = share_mode_str(NULL, 0, &e.id, &e);
> +		char *sm_str = share_mode_str(NULL, 0, &id, &e);
>  		if (!sm_str) {
>  			smb_panic("talloc failed");
>  		}
> @@ -1297,7 +1298,7 @@ void msg_close_file(struct messaging_context *msg_ctx,
>  		TALLOC_FREE(sm_str);
>  	}
>  
> -	fsp = file_find_dif(sconn, e.id, e.share_file_id);
> +	fsp = file_find_dif(sconn, id, e.share_file_id);
>  	if (!fsp) {
>  		DEBUG(10,("msg_close_file: failed to find file.\n"));
>  		return;
> -- 
> 2.11.0
> 
> 
> From a7be192a8eff00c3711cb0c6c271040219bac91a Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Wed, 7 Feb 2018 12:11:10 +0100
> Subject: [PATCH 12/16] smbd: Avoid a dependency on share_mode_entry->id
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source3/smbd/oplock.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/source3/smbd/oplock.c b/source3/smbd/oplock.c
> index 6674c2e5ae7..a742fe5c9cf 100644
> --- a/source3/smbd/oplock.c
> +++ b/source3/smbd/oplock.c
> @@ -792,6 +792,7 @@ static void process_oplock_break_message(struct messaging_context *msg_ctx,
>  					 struct server_id src,
>  					 DATA_BLOB *data)
>  {
> +	struct file_id id;
>  	struct share_mode_entry msg;
>  	files_struct *fsp;
>  	bool use_kernel;
> @@ -816,15 +817,15 @@ static void process_oplock_break_message(struct messaging_context *msg_ctx,
>  	}
>  
>  	/* De-linearize incoming message. */
> -	message_to_share_mode_entry(&msg.id, &msg, (char *)data->data);
> +	message_to_share_mode_entry(&id, &msg, (char *)data->data);
>  	break_to = msg.op_type;
>  
>  	DEBUG(10, ("Got oplock break to %u message from pid %s: %s/%llu\n",
>  		   (unsigned)break_to, server_id_str_buf(src, &tmp),
> -		   file_id_string_tos(&msg.id),
> +		   file_id_string_tos(&id),
>  		   (unsigned long long)msg.share_file_id));
>  
> -	fsp = initial_break_processing(sconn, msg.id, msg.share_file_id);
> +	fsp = initial_break_processing(sconn, id, msg.share_file_id);
>  
>  	if (fsp == NULL) {
>  		/* We hit a race here. Break messages are sent, and before we
> -- 
> 2.11.0
> 
> 
> From b5bd966f9de9a2a4549f06c7f1fb5f25bbefbda6 Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Wed, 7 Feb 2018 12:16:10 +0100
> Subject: [PATCH 13/16] srvsvc: Avoid a dependency on share_mode_entry->id
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source3/rpc_server/srvsvc/srv_srvsvc_nt.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
> index 8a738b396cd..6536e3daa96 100644
> --- a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
> +++ b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
> @@ -2725,7 +2725,7 @@ static int enum_file_close_fn(const struct share_mode_entry *e,
>  	DBG_DEBUG("request to close file %s, %s\n", sharepath,
>  		  share_mode_str(talloc_tos(), 0, id, e));
>  
> -	share_mode_entry_to_message(msg, &e->id, e);
> +	share_mode_entry_to_message(msg, id, e);
>  
>  	state->r->out.result = ntstatus_to_werror(
>  		messaging_send_buf(state->msg_ctx,
> -- 
> 2.11.0
> 
> 
> From 7a688fc2768ebfd8231d9a46100523536888ca99 Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Wed, 7 Feb 2018 12:24:35 +0100
> Subject: [PATCH 14/16] smbd: Pass "file_id" explicitly to send_break_message()
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source3/smbd/open.c         | 13 +++++++------
>  source3/smbd/proto.h        |  5 +++--
>  source3/smbd/smb2_setinfo.c |  3 ++-
>  3 files changed, 12 insertions(+), 9 deletions(-)
> 
> diff --git a/source3/smbd/open.c b/source3/smbd/open.c
> index 995417bc764..be9e601bb15 100644
> --- a/source3/smbd/open.c
> +++ b/source3/smbd/open.c
> @@ -1690,8 +1690,9 @@ static NTSTATUS open_mode_check(connection_struct *conn,
>   */
>  
>  NTSTATUS send_break_message(struct messaging_context *msg_ctx,
> -				   const struct share_mode_entry *exclusive,
> -				   uint16_t break_to)
> +			    const struct file_id *id,
> +			    const struct share_mode_entry *exclusive,
> +			    uint16_t break_to)
>  {
>  	NTSTATUS status;
>  	char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE];
> @@ -1701,7 +1702,7 @@ NTSTATUS send_break_message(struct messaging_context *msg_ctx,
>  		   server_id_str_buf(exclusive->pid, &tmp)));
>  
>  	/* Create the message. */
> -	share_mode_entry_to_message(msg, &exclusive->id, exclusive);
> +	share_mode_entry_to_message(msg, id, exclusive);
>  
>  	/* Overload entry->op_type */
>  	/*
> @@ -1927,8 +1928,8 @@ static bool delay_for_oplock(files_struct *fsp,
>  
>  		DEBUG(10, ("breaking from %d to %d\n",
>  			   (int)e_lease_type, (int)break_to));
> -		send_break_message(fsp->conn->sconn->msg_ctx, e,
> -				   break_to);
> +		send_break_message(fsp->conn->sconn->msg_ctx, &fsp->file_id,
> +				   e, break_to);
>  		if (e_lease_type & delay_mask) {
>  			delay = true;
>  		}
> @@ -4983,7 +4984,7 @@ static NTSTATUS lease_match(connection_struct *conn,
>  				continue;
>  			}
>  
> -			send_break_message(conn->sconn->msg_ctx, e,
> +			send_break_message(conn->sconn->msg_ctx, &d->id, e,
>  					   SMB2_LEASE_NONE);
>  
>  			/*
> diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h
> index 96636696f91..4417595df3a 100644
> --- a/source3/smbd/proto.h
> +++ b/source3/smbd/proto.h
> @@ -651,8 +651,9 @@ void change_file_owner_to_parent(connection_struct *conn,
>  				 files_struct *fsp);
>  bool is_stat_open(uint32_t access_mask);
>  NTSTATUS send_break_message(struct messaging_context *msg_ctx,
> -				const struct share_mode_entry *exclusive,
> -				uint16_t break_to);
> +			    const struct file_id *id,
> +			    const struct share_mode_entry *exclusive,
> +			    uint16_t break_to);
>  struct deferred_open_record;
>  bool is_deferred_open_async(const struct deferred_open_record *rec);
>  NTSTATUS create_directory(connection_struct *conn, struct smb_request *req,
> diff --git a/source3/smbd/smb2_setinfo.c b/source3/smbd/smb2_setinfo.c
> index 0355095c8b1..996e4f24632 100644
> --- a/source3/smbd/smb2_setinfo.c
> +++ b/source3/smbd/smb2_setinfo.c
> @@ -226,7 +226,8 @@ static struct tevent_req *delay_rename_for_lease_break(struct tevent_req *req,
>  		delay = true;
>  		break_to = (e_lease_type & ~SMB2_LEASE_HANDLE);
>  
> -		send_break_message(fsp->conn->sconn->msg_ctx, e, break_to);
> +		send_break_message(fsp->conn->sconn->msg_ctx, &fsp->file_id,
> +				   e, break_to);
>  	}
>  
>  	if (!delay) {
> -- 
> 2.11.0
> 
> 
> From e5a1e8c45cac69c16bc3adb6068181f627c5f16f Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Wed, 7 Feb 2018 12:28:13 +0100
> Subject: [PATCH 15/16] smbd: Pass "file_id" explicitly to send_break_to_none
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source3/smbd/oplock.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/source3/smbd/oplock.c b/source3/smbd/oplock.c
> index a742fe5c9cf..0f95bb01398 100644
> --- a/source3/smbd/oplock.c
> +++ b/source3/smbd/oplock.c
> @@ -1131,11 +1131,12 @@ static void contend_level2_oplocks_begin_default(files_struct *fsp,
>  }
>  
>  static void send_break_to_none(struct messaging_context *msg_ctx,
> +			       const struct file_id *id,
>  			       const struct share_mode_entry *e)
>  {
>  	char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE];
>  
> -	share_mode_entry_to_message(msg, &e->id, e);
> +	share_mode_entry_to_message(msg, id, e);
>  	/* Overload entry->op_type */
>  	SSVAL(msg, OP_BREAK_MSG_OP_TYPE_OFFSET, NO_OPLOCK);
>  
> @@ -1203,7 +1204,7 @@ static void do_break_to_none(struct tevent_context *ctx,
>  		DEBUG(10, ("Breaking lease# %"PRIu32" with share_entry# "
>  			   "%"PRIu32"\n", i, j));
>  
> -		send_break_to_none(state->sconn->msg_ctx, e);
> +		send_break_to_none(state->sconn->msg_ctx, &state->id, e);
>  	}
>  
>  	for(i = 0; i < d->num_share_modes; i++) {
> @@ -1246,7 +1247,7 @@ static void do_break_to_none(struct tevent_context *ctx,
>  			abort();
>  		}
>  
> -		send_break_to_none(state->sconn->msg_ctx, e);
> +		send_break_to_none(state->sconn->msg_ctx, &state->id, e);
>  	}
>  
>  	/* We let the message receivers handle removing the oplock state
> -- 
> 2.11.0
> 
> 
> From 8098f8efc8cf517cc862b4bc162f4cd919c7c558 Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Wed, 7 Feb 2018 14:32:37 +0100
> Subject: [PATCH 16/16] smbd: remove "id" from share_mode_entry
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source3/librpc/idl/open_files.idl | 1 -
>  source3/locking/locking.c         | 1 -
>  2 files changed, 2 deletions(-)
> 
> diff --git a/source3/librpc/idl/open_files.idl b/source3/librpc/idl/open_files.idl
> index 1f85f245fca..8d652a9fa01 100644
> --- a/source3/librpc/idl/open_files.idl
> +++ b/source3/librpc/idl/open_files.idl
> @@ -51,7 +51,6 @@ interface open_files
>  		uint32		share_access;
>  		uint32		private_options;
>  		timeval		time;
> -		file_id		id;
>  		udlong		share_file_id;
>  		uint32		uid;
>  		uint16		flags;
> diff --git a/source3/locking/locking.c b/source3/locking/locking.c
> index 738b997f644..791878c6383 100644
> --- a/source3/locking/locking.c
> +++ b/source3/locking/locking.c
> @@ -847,7 +847,6 @@ bool set_share_mode(struct share_mode_lock *lck, struct files_struct *fsp,
>  	e->lease = lease;
>  	e->time.tv_sec = fsp->open_time.tv_sec;
>  	e->time.tv_usec = fsp->open_time.tv_usec;
> -	e->id = fsp->file_id;
>  	e->share_file_id = fsp->fh->gen_id;
>  	e->uid = (uint32_t)uid;
>  	e->flags = (fsp->posix_flags & FSP_POSIX_FLAGS_OPEN) ?
> -- 
> 2.11.0
> 




More information about the samba-technical mailing list