]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
libsmb: Move cli_smbwrite() to source3/torture
authorVolker Lendecke <vl@samba.org>
Thu, 19 Jun 2025 11:00:18 +0000 (13:00 +0200)
committerAnoop C S <anoopcs@samba.org>
Fri, 20 Jun 2025 10:14:37 +0000 (10:14 +0000)
Only used there

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
source3/libsmb/clireadwrite.c
source3/libsmb/proto.h
source3/torture/proto.h
source3/torture/torture.c

index a7bef4497e5fd1eabb9f4c95849f0249d21d7163..c4005030816a5fa7f7966f18376ee68e680870b1 100644 (file)
@@ -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
  */
index 97a83e46cb9c93424ba86b87651275576db83281..8d729e89ea279eefa335ef91463455ee16c90517 100644 (file)
@@ -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,
index 8783776a2c3bb2e66c3d20cbd35e8286d2aa2f0e..72c9ea801331ad6bc6b1a1fa0edbf4892f8d7d31 100644 (file)
@@ -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,
index e735eb8247daa9d4cf9f6c344dadbfc93b7756eb..22c89ff6f54d7d8d7fee0ff47dc3b8e099f9bcc4 100644 (file)
@@ -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)