1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-02 09:47:23 +03:00

Add a "bytes_padding" parameter to smb_splice_chain

For example open&x and write&x needs the bytes to be aligned relative to the
SMB header. In particular for write&x we should not have to move stuff around.
This commit is contained in:
Volker Lendecke 2008-11-16 18:02:17 +01:00
parent f0bb53dd0f
commit ed25c6c287
2 changed files with 29 additions and 12 deletions

View File

@ -127,6 +127,7 @@ void cli_chain_uncork(struct cli_state *cli);
bool cli_in_chain(struct cli_state *cli);
bool smb_splice_chain(char **poutbuf, uint8_t smb_command,
uint8_t wct, const uint16_t *vwv,
size_t bytes_alignment,
uint16_t num_bytes, const uint8_t *bytes);
NTSTATUS cli_pull_reply(struct async_req *req,

View File

@ -223,6 +223,7 @@ static bool find_andx_cmd_ofs(char *buf, size_t *pofs)
* @param[in] smb_command The command that we want to issue
* @param[in] wct How many words?
* @param[in] vwv The words, already in network order
* @param[in] bytes_alignment How shall we align "bytes"?
* @param[in] num_bytes How many bytes?
* @param[in] bytes The data the request ships
*
@ -232,12 +233,14 @@ static bool find_andx_cmd_ofs(char *buf, size_t *pofs)
bool smb_splice_chain(char **poutbuf, uint8_t smb_command,
uint8_t wct, const uint16_t *vwv,
size_t bytes_alignment,
uint16_t num_bytes, const uint8_t *bytes)
{
char *outbuf;
size_t old_size, new_size;
size_t ofs;
size_t padding = 0;
size_t chain_padding = 0;
size_t bytes_padding = 0;
bool first_request;
old_size = talloc_get_size(*poutbuf);
@ -251,17 +254,25 @@ bool smb_splice_chain(char **poutbuf, uint8_t smb_command,
if (!first_request && ((old_size % 4) != 0)) {
/*
* Align subsequent requests to a 4-byte boundary
* Align the wct field of subsequent requests to a 4-byte
* boundary
*/
padding = 4 - (old_size % 4);
chain_padding = 4 - (old_size % 4);
}
/*
* We need space for the wct field, the words, the byte count field
* and the bytes themselves.
* After the old request comes the new wct field (1 byte), the vwv's
* and the num_bytes field. After at we might need to align the bytes
* given to us to "bytes_alignment", increasing the num_bytes value.
*/
new_size = old_size + padding
+ 1 + wct * sizeof(uint16_t) + 2 + num_bytes;
new_size = old_size + chain_padding + 1 + wct * sizeof(uint16_t) + 2;
if ((bytes_alignment != 0) && ((new_size % bytes_alignment) != 0)) {
bytes_padding = bytes_alignment + (new_size % bytes_alignment);
}
new_size += bytes_padding + num_bytes;
if (new_size > 0xffff) {
DEBUG(1, ("splice_chain: %u bytes won't fit\n",
@ -288,9 +299,9 @@ bool smb_splice_chain(char **poutbuf, uint8_t smb_command,
return false;
}
if (padding != 0) {
memset(outbuf + old_size, 0, padding);
old_size += padding;
if (chain_padding != 0) {
memset(outbuf + old_size, 0, chain_padding);
old_size += chain_padding;
}
SCVAL(outbuf, andx_cmd_ofs, smb_command);
@ -305,9 +316,14 @@ bool smb_splice_chain(char **poutbuf, uint8_t smb_command,
memcpy(outbuf + ofs, vwv, sizeof(uint16_t) * wct);
ofs += sizeof(uint16_t) * wct;
SSVAL(outbuf, ofs, num_bytes);
SSVAL(outbuf, ofs, num_bytes + bytes_padding);
ofs += sizeof(uint16_t);
if (bytes_padding != 0) {
memset(outbuf + ofs, 0, bytes_padding);
ofs += bytes_padding;
}
memcpy(outbuf + ofs, bytes, num_bytes);
return true;
@ -407,7 +423,7 @@ static struct async_req *cli_request_chain(TALLOC_CTX *mem_ctx,
cli_async_req_destructor);
if (!smb_splice_chain(&req->outbuf, smb_command, wct, vwv,
num_bytes, bytes)) {
0, num_bytes, bytes)) {
goto fail;
}