[PATCH] Allow reparse points to be created/read/removed over SMB2 from smbclient.

Ralph Böhme slow at samba.org
Tue Dec 5 22:26:21 UTC 2017


Hi Jeremy,

On Thu, Nov 30, 2017 at 04:29:42PM -0800, Jeremy Allison wrote:
> I've tested here and it works. Volker or Ralph, please
> review and push if happy !

few nitpicks below:

> From f082659a2b9a58c2ccef4a1cacc9efa9fd870c7b Mon Sep 17 00:00:00 2001
> From: Jeremy Allison <jra at samba.org>
> Date: Wed, 22 Nov 2017 00:47:48 +0000
> Subject: [PATCH 1/7] s3: libsmb: Rename cli_close_create() ->
>  cli_smb1_close_create().

patch1: +1

> From 8d5774eb888aee08f4ed2c3a13771b9dc86473b1 Mon Sep 17 00:00:00 2001
> From: Jeremy Allison <jra at samba.org>
> Date: Mon, 27 Nov 2017 14:38:49 -0800
> Subject: [PATCH 2/7] s3: libsmb: Make cli_close_send()/cli_close_recv() work
>  for SMB1 and SMB2.
> 
> Remove the escape into synchronous smb2 code.
> 
> BUG: https://bugzilla.samba.org/show_bug.cgi?id=13159
> 
> Signed-off-by: Jeremy Allison <jra at samba.org>
> ---
>  source3/libsmb/clifile.c | 51 ++++++++++++++++++++++++++++++++++++++++--------
>  1 file changed, 43 insertions(+), 8 deletions(-)
> 
> diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c
> index 2e3c2426030..b0a2759ecf8 100644
> --- a/source3/libsmb/clifile.c
> +++ b/source3/libsmb/clifile.c
> @@ -2818,26 +2818,65 @@ static void cli_smb1_close_done(struct tevent_req *subreq)
>  	tevent_req_done(req);
>  }
>  
> +struct cli_close_state {
> +	int dummy;
> +};
> +
> +static void cli_close_done(struct tevent_req *subreq);
> +
>  struct tevent_req *cli_close_send(TALLOC_CTX *mem_ctx,
>  				struct tevent_context *ev,
>  				struct cli_state *cli,
>  				uint16_t fnum)
>  {
>  	struct tevent_req *req, *subreq;
> +	struct cli_close_state *state;
>  	NTSTATUS status;
>  
> -	req = cli_smb1_close_create(mem_ctx, ev, cli, fnum, &subreq);
> +	req = tevent_req_create(mem_ctx, &state, struct cli_close_state);
>  	if (req == NULL) {
>  		return NULL;
>  	}
>  
> -	status = smb1cli_req_chain_submit(&subreq, 1);
> -	if (tevent_req_nterror(req, status)) {
> -		return tevent_req_post(req, ev);
> +	if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
> +		subreq = cli_smb2_close_fnum_send(mem_ctx,

wrong talloc context for the subreq, should be state.

> +						ev,
> +						cli,
> +						fnum);
> +		if (tevent_req_nomem(subreq, req)) {
> +			return tevent_req_post(req, ev);
> +		}
> +	} else {
> +		struct tevent_req *ch_req = NULL;
> +		subreq = cli_smb1_close_create(mem_ctx, ev, cli, fnum, &ch_req);

dito

> +		if (tevent_req_nomem(subreq, req)) {
> +			return tevent_req_post(req, ev);
> +		}
> +		status = smb1cli_req_chain_submit(&ch_req, 1);
> +		if (tevent_req_nterror(req, status)) {
> +			return tevent_req_post(req, ev);
> +		}
>  	}
> +
> +	tevent_req_set_callback(subreq, cli_close_done, req);
>  	return req;
>  }
>  
> +static void cli_close_done(struct tevent_req *subreq)
> +{
> +	struct tevent_req *req = tevent_req_callback_data(
> +		subreq, struct tevent_req);
> +	NTSTATUS status = NT_STATUS_OK;
> +	bool err = tevent_req_is_nterror(subreq, &status);
> +
> +	TALLOC_FREE(subreq);
> +	if (err) {
> +		tevent_req_nterror(req, status);
> +		return;
> +	}
> +	tevent_req_done(req);
> +}
> +
>  NTSTATUS cli_close_recv(struct tevent_req *req)
>  {
>  	return tevent_req_simple_recv_ntstatus(req);
> @@ -2850,10 +2889,6 @@ NTSTATUS cli_close(struct cli_state *cli, uint16_t fnum)
>  	struct tevent_req *req;
>  	NTSTATUS status = NT_STATUS_OK;
>  
> -	if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
> -		return cli_smb2_close_fnum(cli, fnum);
> -	}
> -
>  	frame = talloc_stackframe();
>  
>  	if (smbXcli_conn_has_async_calls(cli->conn)) {
> -- 
> 2.15.0.531.g2ccb3012c9-goog
> 
> 

> From faf81a560bcbaeab3ae0f32f5446716ec10179f1 Mon Sep 17 00:00:00 2001
> From: Jeremy Allison <jra at samba.org>
> Date: Tue, 28 Nov 2017 14:09:39 -0800
> Subject: [PATCH 3/7] s3: libsmb: Add SMB2 calls
>  cli_smb2_set_reparse_point_fnum_send()/cli_smb2_set_reparse_point_fnum_recv().

patch3: +1

> From 8bae632bf7bd53f1858fe206abf21290fa901367 Mon Sep 17 00:00:00 2001
> From: Jeremy Allison <jra at samba.org>
> Date: Tue, 28 Nov 2017 14:10:26 -0800
> Subject: [PATCH 4/7] s3: libsmb: Plumb in the new SMB2 reparse point calls
>  into the cli_symlink_create_XXX() calls.

patch4: +1

> From 5eadea9e7cc14ab3d9ebac268ad27b4b089bceef Mon Sep 17 00:00:00 2001
> From: Jeremy Allison <jra at samba.org>
> Date: Tue, 28 Nov 2017 15:46:40 -0800
> Subject: [PATCH 5/7] s3: libsmb: Do a naive response to SMB2 "stopped on
>  symlink". Assume the last component was the reparse point.

patch5: +1

> From 328229e2fe6a344f895baa47147c1f1aa5c1e2d4 Mon Sep 17 00:00:00 2001
> From: Jeremy Allison <jra at samba.org>
> Date: Wed, 29 Nov 2017 12:37:36 -0800
> Subject: [PATCH 6/7] s3: libsmb: Add SMB2 calls
>  cli_smb2_get_reparse_point_fnum_send()/cli_smb2_get_reparse_point_fnum_recv().
> 
> Allow reparse points to be queried over SMB2.
> 
> BUG: https://bugzilla.samba.org/show_bug.cgi?id=13159
> 
> Signed-off-by: Jeremy Allison <jra at samba.org>
> ---
>  source3/libsmb/cli_smb2_fnum.c | 96 ++++++++++++++++++++++++++++++++++++++++++
>  source3/libsmb/cli_smb2_fnum.h |  9 ++++
>  2 files changed, 105 insertions(+)
> 
> diff --git a/source3/libsmb/cli_smb2_fnum.c b/source3/libsmb/cli_smb2_fnum.c
> index c40d6dd3a45..a54c248720b 100644
> --- a/source3/libsmb/cli_smb2_fnum.c
> +++ b/source3/libsmb/cli_smb2_fnum.c
> @@ -4337,3 +4337,99 @@ NTSTATUS cli_smb2_set_reparse_point_fnum_recv(struct tevent_req *req)
>  {
>          return tevent_req_simple_recv_ntstatus(req);
>  }
> +
> +struct cli_smb2_get_reparse_point_fnum_state {
> +	struct cli_state *cli;
> +	uint16_t fnum;
> +	struct smb2_hnd *ph;
> +	DATA_BLOB output_buffer;
> +};
> +
> +static void cli_smb2_get_reparse_point_fnum_done(struct tevent_req *subreq);
> +
> +struct tevent_req *cli_smb2_get_reparse_point_fnum_send(
> +				TALLOC_CTX *mem_ctx,
> +				struct tevent_context *ev,
> +				struct cli_state *cli,
> +				uint16_t fnum)
> +{
> +	struct tevent_req *req, *subreq;
> +	struct cli_smb2_set_reparse_point_fnum_state *state = NULL;
> +	NTSTATUS status;
> +
> +	req = tevent_req_create(mem_ctx, &state,
> +				struct cli_smb2_get_reparse_point_fnum_state);
> +	if (req == NULL) {
> +		return NULL;
> +	}
> +
> +	if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
> +		tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
> +		return tevent_req_post(req, ev);
> +	}
> +
> +	state->cli = cli;
> +	state->fnum = fnum;
> +
> +	status = map_fnum_to_smb2_handle(cli, fnum, &state->ph);
> +	if (tevent_req_nterror(req, status)) {
> +		return tevent_req_post(req, ev);
> +	}
> +
> +	subreq = smb2cli_ioctl_send(state, ev, state->cli->conn,
> +			state->cli->timeout,
> +			state->cli->smb2.session,
> +			state->cli->smb2.tcon,
> +			state->ph->fid_persistent, /* in_fid_persistent */
> +			state->ph->fid_volatile, /* in_fid_volatile */
> +			FSCTL_GET_REPARSE_POINT,
> +			0, /* in_max_input_length */
> +			NULL,
> +			64*1024,
> +			NULL,
> +			SMB2_IOCTL_FLAG_IS_FSCTL);
> +
> +	if (tevent_req_nomem(subreq, req)) {
> +		return tevent_req_post(req, ev);
> +	}
> +	tevent_req_set_callback(subreq,
> +				cli_smb2_get_reparse_point_fnum_done,
> +				req);
> +
> +	return req;
> +}
> +
> +static void cli_smb2_get_reparse_point_fnum_done(struct tevent_req *subreq)
> +{
> +	struct tevent_req *req = tevent_req_callback_data(
> +		subreq, struct tevent_req);
> +	struct cli_smb2_get_reparse_point_fnum_state *state = tevent_req_data(
> +		req, struct cli_smb2_get_reparse_point_fnum_state);
> +	NTSTATUS status;
> +
> +	status = smb2cli_ioctl_recv(subreq, state,
> +				NULL,
> +				&state->output_buffer);
> +	TALLOC_FREE(subreq);
> +	if (tevent_req_nterror(req, status)) {
> +		return;
> +	}
> +	tevent_req_done(req);
> +}
> +
> +NTSTATUS cli_smb2_get_reparse_point_fnum_recv(struct tevent_req *req,
> +				TALLOC_CTX *mem_ctx,
> +				DATA_BLOB *output)
> +{
> +	struct cli_smb2_get_reparse_point_fnum_state *state = tevent_req_data(
> +		req, struct cli_smb2_get_reparse_point_fnum_state);
> +
> +	if (tevent_req_is_nterror(req, &state->cli->raw_status)) {
> +		return state->cli->raw_status;
> +	}
> +	*output = data_blob_dup_talloc(mem_ctx, state->output_buffer);

missing tevent_req_received().

> +	if (output->data == NULL) {
> +		return NT_STATUS_NO_MEMORY;
> +	}
> +	return NT_STATUS_OK;
> +}
> diff --git a/source3/libsmb/cli_smb2_fnum.h b/source3/libsmb/cli_smb2_fnum.h
> index 0f6809fe4ca..0ceddd0b9ab 100644
> --- a/source3/libsmb/cli_smb2_fnum.h
> +++ b/source3/libsmb/cli_smb2_fnum.h
> @@ -250,4 +250,13 @@ struct tevent_req *cli_smb2_set_reparse_point_fnum_send(
>  			DATA_BLOB in_buf);
>  NTSTATUS cli_smb2_set_reparse_point_fnum_recv(struct tevent_req *req);
>  
> +struct tevent_req *cli_smb2_get_reparse_point_fnum_send(
> +			TALLOC_CTX *mem_ctx,
> +			struct tevent_context *ev,
> +			struct cli_state *cli,
> +			uint16_t fnum);
> +NTSTATUS cli_smb2_get_reparse_point_fnum_recv(struct tevent_req *req,
> +			TALLOC_CTX *mem_ctx,
> +			DATA_BLOB *output);
> +
>  #endif /* __SMB2CLI_FNUM_H__ */
> -- 
> 2.15.0.531.g2ccb3012c9-goog
> 
> 
> From 5e891a142f85383af68d449671d2fc124bc7a37a Mon Sep 17 00:00:00 2001
> From: Jeremy Allison <jra at samba.org>
> Date: Wed, 29 Nov 2017 12:38:08 -0800
> Subject: [PATCH 7/7] s3: libsmb: Plumb in the new SMB2 get reparse point calls
>  into the cli_readlink_XXXX() calls.

patch7: +1

-slow

-- 
Ralph Boehme, Samba Team       https://samba.org/
Samba Developer, SerNet GmbH   https://sernet.de/en/samba/



More information about the samba-technical mailing list