From: Volker Lendecke Date: Wed, 1 Jul 2026 15:39:59 +0000 (+0200) Subject: smbd: Move two SMB1-only functions to smb1_utils.c X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=edcffb336f9a3793617f931a75eead25f6728f87;p=thirdparty%2Fsamba.git smbd: Move two SMB1-only functions to smb1_utils.c Signed-off-by: Volker Lendecke Reviewed-by: Anoop C S --- diff --git a/source3/lib/util.c b/source3/lib/util.c index 73b9e4d50f9..06273b4a427 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -191,50 +191,6 @@ void show_msg(const char *buf) TALLOC_FREE(msg); } -/******************************************************************* - Setup only the byte count for a smb message. -********************************************************************/ - -int set_message_bcc(char *buf,int num_bytes) -{ - int num_words = CVAL(buf,smb_wct); - SSVAL(buf,smb_vwv + num_words*SIZEOFWORD,num_bytes); - _smb_setlen(buf,smb_size + num_words*2 + num_bytes - 4); - return (smb_size + num_words*2 + num_bytes); -} - -/******************************************************************* - Add a data blob to the end of a smb_buf, adjusting bcc and smb_len. - Return the bytes added -********************************************************************/ - -ssize_t message_push_blob(uint8_t **outbuf, DATA_BLOB blob) -{ - size_t newlen; - uint8_t *tmp; - - newlen = smb_len(*outbuf) + 4; - if (newlen < 4) { - return -1; - } - - newlen += blob.length; - if (newlen < blob.length) { - return -1; - } - - tmp = talloc_realloc(NULL, *outbuf, uint8_t, newlen); - if (tmp == NULL) { - DBG_ERR("talloc failed\n"); - return -1; - } - *outbuf = tmp; - - memcpy(tmp + smb_len(tmp) + 4, blob.data, blob.length); - set_message_bcc((char *)tmp, smb_buflen(tmp) + blob.length); - return blob.length; -} - /******************************************************************* Reduce a file name, removing .. elements. ********************************************************************/ diff --git a/source3/smbd/smb1_utils.c b/source3/smbd/smb1_utils.c index 56153cdd634..0c75df9e45d 100644 --- a/source3/smbd/smb1_utils.c +++ b/source3/smbd/smb1_utils.c @@ -345,3 +345,47 @@ files_struct *file_fsp(struct smb_request *req, uint16_t fid) fsp->fsp_name->st.cached_dos_attributes = FILE_ATTRIBUTE_INVALID; return fsp; } + +/******************************************************************* + Setup only the byte count for a smb message. +********************************************************************/ + +int set_message_bcc(char *buf, int num_bytes) +{ + int num_words = CVAL(buf, smb_wct); + SSVAL(buf, smb_vwv + num_words * SIZEOFWORD, num_bytes); + _smb_setlen(buf, smb_size + num_words * 2 + num_bytes - 4); + return (smb_size + num_words * 2 + num_bytes); +} + +/******************************************************************* + Add a data blob to the end of a smb_buf, adjusting bcc and smb_len. + Return the bytes added +********************************************************************/ + +ssize_t message_push_blob(uint8_t **outbuf, DATA_BLOB blob) +{ + size_t newlen; + uint8_t *tmp; + + newlen = smb_len(*outbuf) + 4; + if (newlen < 4) { + return -1; + } + + newlen += blob.length; + if (newlen < blob.length) { + return -1; + } + + tmp = talloc_realloc(NULL, *outbuf, uint8_t, newlen); + if (tmp == NULL) { + DBG_ERR("talloc failed\n"); + return -1; + } + *outbuf = tmp; + + memcpy(tmp + smb_len(tmp) + 4, blob.data, blob.length); + set_message_bcc((char *)tmp, smb_buflen(tmp) + blob.length); + return blob.length; +} diff --git a/source3/smbd/smb1_utils.h b/source3/smbd/smb1_utils.h index d5eb7a2deed..4e6aadfcb52 100644 --- a/source3/smbd/smb1_utils.h +++ b/source3/smbd/smb1_utils.h @@ -43,5 +43,7 @@ NTSTATUS filename_convert_smb1_search_path(TALLOC_CTX *ctx, struct smb_filename **_smb_fname_out, char **_mask_out); struct files_struct *file_fsp(struct smb_request *req, uint16_t fid); +int set_message_bcc(char *buf, int num_bytes); +ssize_t message_push_blob(uint8_t **outbuf, DATA_BLOB blob); #endif