From: Volker Lendecke Date: Thu, 19 Jun 2025 11:00:18 +0000 (+0200) Subject: libsmb: Move cli_smbwrite() to source3/torture X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=51b39cf457f940756b72fa0d242dd8268b56878a;p=thirdparty%2Fsamba.git libsmb: Move cli_smbwrite() to source3/torture Only used there Signed-off-by: Volker Lendecke Reviewed-by: Anoop C S --- diff --git a/source3/libsmb/clireadwrite.c b/source3/libsmb/clireadwrite.c index a7bef4497e5..c4005030816 100644 --- a/source3/libsmb/clireadwrite.c +++ b/source3/libsmb/clireadwrite.c @@ -858,74 +858,6 @@ NTSTATUS cli_read(struct cli_state *cli, uint16_t fnum, return NT_STATUS_OK; } -/**************************************************************************** - write to a file using a SMBwrite and not bypassing 0 byte writes -****************************************************************************/ - -NTSTATUS cli_smbwrite(struct cli_state *cli, uint16_t fnum, char *buf, - off_t offset, size_t size1, size_t *ptotal) -{ - uint8_t *bytes; - ssize_t total = 0; - - /* - * 3 bytes prefix - */ - - bytes = talloc_array(talloc_tos(), uint8_t, 3); - if (bytes == NULL) { - return NT_STATUS_NO_MEMORY; - } - bytes[0] = 1; - - do { - uint32_t usable_space = cli_state_available_size(cli, 48); - size_t size = MIN(size1, usable_space); - struct tevent_req *req; - uint16_t vwv[5]; - uint16_t *ret_vwv; - NTSTATUS status; - - SSVAL(vwv+0, 0, fnum); - SSVAL(vwv+1, 0, size); - SIVAL(vwv+2, 0, offset); - SSVAL(vwv+4, 0, 0); - - bytes = talloc_realloc(talloc_tos(), bytes, uint8_t, - size+3); - if (bytes == NULL) { - return NT_STATUS_NO_MEMORY; - } - SSVAL(bytes, 1, size); - memcpy(bytes + 3, buf + total, size); - - status = cli_smb(talloc_tos(), cli, SMBwrite, 0, 5, vwv, - size+3, bytes, &req, 1, NULL, &ret_vwv, - NULL, NULL); - if (!NT_STATUS_IS_OK(status)) { - TALLOC_FREE(bytes); - return status; - } - - size = SVAL(ret_vwv+0, 0); - TALLOC_FREE(req); - if (size == 0) { - break; - } - size1 -= size; - total += size; - offset += size; - - } while (size1); - - TALLOC_FREE(bytes); - - if (ptotal != NULL) { - *ptotal = total; - } - return NT_STATUS_OK; -} - /* * Send a write&x request */ diff --git a/source3/libsmb/proto.h b/source3/libsmb/proto.h index 97a83e46cb9..8d729e89ea2 100644 --- a/source3/libsmb/proto.h +++ b/source3/libsmb/proto.h @@ -917,8 +917,6 @@ NTSTATUS cli_read_recv(struct tevent_req *req, size_t *received); NTSTATUS cli_read(struct cli_state *cli, uint16_t fnum, char *buf, off_t offset, size_t size, size_t *nread); -NTSTATUS cli_smbwrite(struct cli_state *cli, uint16_t fnum, char *buf, - off_t offset, size_t size1, size_t *ptotal); struct tevent_req *cli_write_andx_create(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct cli_state *cli, uint16_t fnum, diff --git a/source3/torture/proto.h b/source3/torture/proto.h index 8783776a2c3..72c9ea80133 100644 --- a/source3/torture/proto.h +++ b/source3/torture/proto.h @@ -77,6 +77,9 @@ NTSTATUS torture_setup_unix_extensions(struct cli_state *cli); void torture_conn_set_sockopt(struct cli_state *cli); void torture_deltree(struct cli_state *cli, const char *dname); +NTSTATUS cli_smbwrite(struct cli_state *cli, uint16_t fnum, char *buf, + off_t offset, size_t size1, size_t *ptotal); + NTSTATUS cli_qpathinfo1(struct cli_state *cli, const char *fname, time_t *change_time, diff --git a/source3/torture/torture.c b/source3/torture/torture.c index e735eb8247d..22c89ff6f54 100644 --- a/source3/torture/torture.c +++ b/source3/torture/torture.c @@ -477,6 +477,74 @@ void torture_conn_set_sockopt(struct cli_state *cli) smbXcli_conn_set_sockopt(cli->conn, sockops); } +/**************************************************************************** + write to a file using a SMBwrite and not bypassing 0 byte writes +****************************************************************************/ + +NTSTATUS cli_smbwrite(struct cli_state *cli, uint16_t fnum, char *buf, + off_t offset, size_t size1, size_t *ptotal) +{ + uint8_t *bytes; + ssize_t total = 0; + + /* + * 3 bytes prefix + */ + + bytes = talloc_array(talloc_tos(), uint8_t, 3); + if (bytes == NULL) { + return NT_STATUS_NO_MEMORY; + } + bytes[0] = 1; + + do { + uint32_t usable_space = cli_state_available_size(cli, 48); + size_t size = MIN(size1, usable_space); + struct tevent_req *req; + uint16_t vwv[5]; + uint16_t *ret_vwv; + NTSTATUS status; + + SSVAL(vwv+0, 0, fnum); + SSVAL(vwv+1, 0, size); + SIVAL(vwv+2, 0, offset); + SSVAL(vwv+4, 0, 0); + + bytes = talloc_realloc(talloc_tos(), bytes, uint8_t, + size+3); + if (bytes == NULL) { + return NT_STATUS_NO_MEMORY; + } + SSVAL(bytes, 1, size); + memcpy(bytes + 3, buf + total, size); + + status = cli_smb(talloc_tos(), cli, SMBwrite, 0, 5, vwv, + size+3, bytes, &req, 1, NULL, &ret_vwv, + NULL, NULL); + if (!NT_STATUS_IS_OK(status)) { + TALLOC_FREE(bytes); + return status; + } + + size = SVAL(ret_vwv+0, 0); + TALLOC_FREE(req); + if (size == 0) { + break; + } + size1 -= size; + total += size; + offset += size; + + } while (size1); + + TALLOC_FREE(bytes); + + if (ptotal != NULL) { + *ptotal = total; + } + return NT_STATUS_OK; +} + static NTSTATUS torture_delete_fn(struct file_info *finfo, const char *pattern, void *state)