From 8cc1e25a00434de1afe5d9fb7f4f8e503e7fb0f5 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Thu, 5 Jun 2014 10:52:54 +0100 Subject: [PATCH] libcli/smb: Allow dynamic setting of the max_data in SMB Pipe transaction. Some services like WSP can send larger messages than the current 'Max Ioctl' limit, this results in the server producing a BUFFER_OVERFLOW status (and additionally clipping the message sent). Add support to allow a client to modify the hardcoded 'Max Ioctl' default value to allow the server to successfully send larger responses. Signed-off-by: Noel Power Reviewed-by: Andrew Bartlett --- libcli/smb/tstream_smbXcli_np.c | 25 ++++++++++++++++++------- libcli/smb/tstream_smbXcli_np.h | 3 +++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/libcli/smb/tstream_smbXcli_np.c b/libcli/smb/tstream_smbXcli_np.c index 990673196a8..02483004080 100644 --- a/libcli/smb/tstream_smbXcli_np.c +++ b/libcli/smb/tstream_smbXcli_np.c @@ -57,6 +57,7 @@ struct tstream_smbXcli_np { uint16_t fnum; uint64_t fid_persistent; uint64_t fid_volatile; + uint32_t max_data; struct { bool active; @@ -362,6 +363,7 @@ NTSTATUS _tstream_smbXcli_np_open_recv(struct tevent_req *req, cli_nps->fnum = state->fnum; cli_nps->fid_persistent = state->fid_persistent; cli_nps->fid_volatile = state->fid_volatile; + cli_nps->max_data = TSTREAM_SMBXCLI_NP_MAX_BUF_SIZE; talloc_set_destructor(cli_nps, tstream_smbXcli_np_destructor); talloc_set_destructor(cli_nps->conn_ref, @@ -430,6 +432,15 @@ NTSTATUS tstream_smbXcli_np_use_trans(struct tstream_context *stream) return NT_STATUS_OK; } +void tstream_smbXcli_np_set_max_data(struct tstream_context *stream, + uint32_t max_data) +{ + struct tstream_smbXcli_np *cli_nps = tstream_context_data( + stream, struct tstream_smbXcli_np); + + cli_nps->max_data = max_data; +} + unsigned int tstream_smbXcli_np_set_timeout(struct tstream_context *stream, unsigned int timeout) { @@ -540,7 +551,7 @@ static void tstream_smbXcli_np_writev_write_next(struct tevent_req *req) } cli_nps->write.ofs = 0; - cli_nps->write.left = MIN(left, TSTREAM_SMBXCLI_NP_MAX_BUF_SIZE); + cli_nps->write.left = MIN(left, cli_nps->max_data); cli_nps->write.buf = talloc_realloc(cli_nps, cli_nps->write.buf, uint8_t, cli_nps->write.left); if (tevent_req_nomem(cli_nps->write.buf, req)) { @@ -862,14 +873,14 @@ static void tstream_smbXcli_np_readv_read_next(struct tevent_req *req) cli_nps->session, cli_nps->fnum, 0, /* offset */ - TSTREAM_SMBXCLI_NP_MAX_BUF_SIZE); + cli_nps->max_data); } else { subreq = smb2cli_read_send(state, state->ev, cli_nps->conn, cli_nps->timeout, cli_nps->session, cli_nps->tcon, - TSTREAM_SMBXCLI_NP_MAX_BUF_SIZE, /* length */ + cli_nps->max_data, /* length */ 0, /* offset */ cli_nps->fid_persistent, cli_nps->fid_volatile, @@ -917,7 +928,7 @@ static void tstream_smbXcli_np_readv_trans_start(struct tevent_req *req) NULL, 0, 0, cli_nps->write.buf, cli_nps->write.ofs, - TSTREAM_SMBXCLI_NP_MAX_BUF_SIZE); + cli_nps->max_data); } else { DATA_BLOB in_input_buffer = data_blob_null; DATA_BLOB in_output_buffer = data_blob_null; @@ -936,7 +947,7 @@ static void tstream_smbXcli_np_readv_trans_start(struct tevent_req *req) 0, /* in_max_input_length */ &in_input_buffer, /* in_max_output_length */ - TSTREAM_SMBXCLI_NP_MAX_BUF_SIZE, + cli_nps->max_data, &in_output_buffer, SMB2_IOCTL_FLAG_IS_FSCTL); } @@ -999,7 +1010,7 @@ static void tstream_smbXcli_np_readv_trans_done(struct tevent_req *subreq) return; } - if (received > TSTREAM_SMBXCLI_NP_MAX_BUF_SIZE) { + if (received > cli_nps->max_data) { tstream_smbXcli_np_readv_disconnect_now(req, EIO, __location__); return; } @@ -1083,7 +1094,7 @@ static void tstream_smbXcli_np_readv_read_done(struct tevent_req *subreq) return; } - if (received > TSTREAM_SMBXCLI_NP_MAX_BUF_SIZE) { + if (received > cli_nps->max_data) { TALLOC_FREE(subreq); tstream_smbXcli_np_readv_disconnect_now(req, EIO, __location__); return; diff --git a/libcli/smb/tstream_smbXcli_np.h b/libcli/smb/tstream_smbXcli_np.h index e8c5c39297a..d7a4e3c0583 100644 --- a/libcli/smb/tstream_smbXcli_np.h +++ b/libcli/smb/tstream_smbXcli_np.h @@ -69,4 +69,7 @@ unsigned int tstream_smbXcli_np_set_timeout(struct tstream_context *stream, */ #define TSTREAM_SMBXCLI_NP_MAX_BUF_SIZE 4280 +void tstream_smbXcli_np_set_max_data(struct tstream_context *stream, + uint32_t max_data); + #endif /* _CLI_NP_TSTREAM_H_ */ -- 2.47.3