smbd: Move message_push_string() to smb1_utils.c
authorVolker Lendecke <vl@samba.org>
Sun, 5 Jun 2022 14:44:28 +0000 (16:44 +0200)
committerJeremy Allison <jra@samba.org>
Mon, 6 Jun 2022 19:22:28 +0000 (19:22 +0000)
Only used in SMB1 code

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/proto.h
source3/smbd/smb1_utils.c
source3/smbd/smb1_utils.h
source3/smbd/srvstr.c

index 9917562d1def05f21420ee1a4e2d57e648b64cb8..f7c5c620a1bdc7a5c3d613784969daebeaefc495 100644 (file)
@@ -1081,7 +1081,6 @@ bool is_share_read_only_for_token(const char *username,
 
 NTSTATUS srvstr_push_fn(const char *base_ptr, uint16_t smb_flags2, void *dest,
                      const char *src, int dest_len, int flags, size_t *ret_len);
-ssize_t message_push_string(uint8_t **outbuf, const char *str, int flags);
 
 /* The following definitions come from smbd/statcache.c  */
 
index 15afc3f5ef9cb0899a9af985d29a4f232b81a730..5092aa519299828264419914960b028370e80ae7 100644 (file)
@@ -121,3 +121,58 @@ bool send_keepalive(int client)
 
        return(write_data(client,(char *)buf,4) == 4);
 }
+
+/*******************************************************************
+ Add a string to the end of a smb_buf, adjusting bcc and smb_len.
+ Return the bytes added
+********************************************************************/
+
+ssize_t message_push_string(uint8_t **outbuf, const char *str, int flags)
+{
+       size_t buf_size = smb_len(*outbuf) + 4;
+       size_t grow_size;
+       size_t result = 0;
+       uint8_t *tmp;
+       NTSTATUS status;
+
+       /*
+        * We need to over-allocate, now knowing what srvstr_push will
+        * actually use. This is very generous by incorporating potential
+        * padding, the terminating 0 and at most 4 chars per UTF-16 code
+        * point.
+        */
+       grow_size = (strlen(str) + 2) * 4;
+
+       if (!(tmp = talloc_realloc(NULL, *outbuf, uint8_t,
+                                        buf_size + grow_size))) {
+               DEBUG(0, ("talloc failed\n"));
+               return -1;
+       }
+
+       status = srvstr_push((char *)tmp, SVAL(tmp, smb_flg2),
+                            tmp + buf_size, str, grow_size, flags, &result);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0, ("srvstr_push failed\n"));
+               return -1;
+       }
+
+       /*
+        * Ensure we clear out the extra data we have
+        * grown the buffer by, but not written to.
+        */
+       if (buf_size + result < buf_size) {
+               return -1;
+       }
+       if (grow_size < result) {
+               return -1;
+       }
+
+       memset(tmp + buf_size + result, '\0', grow_size - result);
+
+       set_message_bcc((char *)tmp, smb_buflen(tmp) + result);
+
+       *outbuf = tmp;
+
+       return result;
+}
index 2416a91148a7539b0d534b5c79612a07126a10bb..6f791e2ff801868381c392e474c3ed821c47de77 100644 (file)
@@ -25,6 +25,7 @@
 #include "includes.h"
 #include "vfs.h"
 #include "proto.h"
+#include "lib/util/string_wrappers.h"
 
 struct files_struct *fcb_or_dos_open(
        struct smb_request *req,
@@ -33,5 +34,6 @@ struct files_struct *fcb_or_dos_open(
        uint32_t create_options,
        uint32_t private_flags);
 bool send_keepalive(int client);
+ssize_t message_push_string(uint8_t **outbuf, const char *str, int flags);
 
 #endif
index 6ea3ea48a5991bc12169ce583014d322dab7fd8c..5298ea735b3a995900b14916cb62345c2c700774 100644 (file)
@@ -76,58 +76,3 @@ NTSTATUS srvstr_push_fn(const char *base_ptr, uint16_t smb_flags2, void *dest,
        }
        return status;
 }
-
-/*******************************************************************
- Add a string to the end of a smb_buf, adjusting bcc and smb_len.
- Return the bytes added
-********************************************************************/
-
-ssize_t message_push_string(uint8_t **outbuf, const char *str, int flags)
-{
-       size_t buf_size = smb_len(*outbuf) + 4;
-       size_t grow_size;
-       size_t result = 0;
-       uint8_t *tmp;
-       NTSTATUS status;
-
-       /*
-        * We need to over-allocate, now knowing what srvstr_push will
-        * actually use. This is very generous by incorporating potential
-        * padding, the terminating 0 and at most 4 chars per UTF-16 code
-        * point.
-        */
-       grow_size = (strlen(str) + 2) * 4;
-
-       if (!(tmp = talloc_realloc(NULL, *outbuf, uint8_t,
-                                        buf_size + grow_size))) {
-               DEBUG(0, ("talloc failed\n"));
-               return -1;
-       }
-
-       status = srvstr_push((char *)tmp, SVAL(tmp, smb_flg2),
-                            tmp + buf_size, str, grow_size, flags, &result);
-
-       if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(0, ("srvstr_push failed\n"));
-               return -1;
-       }
-
-       /*
-        * Ensure we clear out the extra data we have
-        * grown the buffer by, but not written to.
-        */
-       if (buf_size + result < buf_size) {
-               return -1;
-       }
-       if (grow_size < result) {
-               return -1;
-       }
-
-       memset(tmp + buf_size + result, '\0', grow_size - result);
-
-       set_message_bcc((char *)tmp, smb_buflen(tmp) + result);
-
-       *outbuf = tmp;
-
-       return result;
-}