1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

smbd: Move init_smb_request to smb2_process.c

init_smb_request is needed for a multi-protocol
negotiation.

Signed-off-by: David Mulder <dmulder@suse.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
David Mulder 2022-03-25 14:08:18 -06:00 committed by Jeremy Allison
parent ed23ce77d9
commit f0ae7fba87
3 changed files with 81 additions and 75 deletions

View File

@ -892,6 +892,12 @@ void smbd_process(struct tevent_context *ev_ctx,
int sock_fd,
bool interactive);
bool valid_smb_header(const uint8_t *inbuf);
bool init_smb_request(struct smb_request *req,
struct smbd_server_connection *sconn,
struct smbXsrv_connection *xconn,
const uint8_t *inbuf,
size_t unread_bytes, bool encrypted,
uint32_t seqnum);
/* The following definitions come from smbd/quotas.c */

View File

@ -529,81 +529,6 @@ NTSTATUS smb1_receive_talloc(TALLOC_CTX *mem_ctx,
return NT_STATUS_OK;
}
/*
* Initialize a struct smb_request from an inbuf
*/
static bool init_smb_request(struct smb_request *req,
struct smbd_server_connection *sconn,
struct smbXsrv_connection *xconn,
const uint8_t *inbuf,
size_t unread_bytes, bool encrypted,
uint32_t seqnum)
{
struct smbXsrv_tcon *tcon;
NTSTATUS status;
NTTIME now;
size_t req_size = smb_len(inbuf) + 4;
/* Ensure we have at least smb_size bytes. */
if (req_size < smb_size) {
DEBUG(0,("init_smb_request: invalid request size %u\n",
(unsigned int)req_size ));
return false;
}
req->request_time = timeval_current();
now = timeval_to_nttime(&req->request_time);
req->cmd = CVAL(inbuf, smb_com);
req->flags2 = SVAL(inbuf, smb_flg2);
req->smbpid = SVAL(inbuf, smb_pid);
req->mid = (uint64_t)SVAL(inbuf, smb_mid);
req->seqnum = seqnum;
req->vuid = SVAL(inbuf, smb_uid);
req->tid = SVAL(inbuf, smb_tid);
req->wct = CVAL(inbuf, smb_wct);
req->vwv = (const uint16_t *)(inbuf+smb_vwv);
req->buflen = smb_buflen(inbuf);
req->buf = (const uint8_t *)smb_buf_const(inbuf);
req->unread_bytes = unread_bytes;
req->encrypted = encrypted;
req->sconn = sconn;
req->xconn = xconn;
req->conn = NULL;
if (xconn != NULL) {
status = smb1srv_tcon_lookup(xconn, req->tid, now, &tcon);
if (NT_STATUS_IS_OK(status)) {
req->conn = tcon->compat;
}
}
req->chain_fsp = NULL;
req->smb2req = NULL;
req->chain = NULL;
req->posix_pathnames = lp_posix_pathnames();
smb_init_perfcount_data(&req->pcd);
/* Ensure we have at least wct words and 2 bytes of bcc. */
if (smb_size + req->wct*2 > req_size) {
DEBUG(0,("init_smb_request: invalid wct number %u (size %u)\n",
(unsigned int)req->wct,
(unsigned int)req_size));
return false;
}
/* Ensure bcc is correct. */
if (((const uint8_t *)smb_buf_const(inbuf)) + req->buflen > inbuf + req_size) {
DEBUG(0,("init_smb_request: invalid bcc number %u "
"(wct = %u, size %u)\n",
(unsigned int)req->buflen,
(unsigned int)req->wct,
(unsigned int)req_size));
return false;
}
req->outbuf = NULL;
return true;
}
/****************************************************************************
Function to push a message onto the tail of a linked list of smb messages ready
for processing.

View File

@ -743,6 +743,81 @@ const char *smbXsrv_connection_dbg(const struct smbXsrv_connection *xconn)
return ret;
}
/*
* Initialize a struct smb_request from an inbuf
*/
bool init_smb_request(struct smb_request *req,
struct smbd_server_connection *sconn,
struct smbXsrv_connection *xconn,
const uint8_t *inbuf,
size_t unread_bytes, bool encrypted,
uint32_t seqnum)
{
struct smbXsrv_tcon *tcon;
NTSTATUS status;
NTTIME now;
size_t req_size = smb_len(inbuf) + 4;
/* Ensure we have at least smb_size bytes. */
if (req_size < smb_size) {
DEBUG(0,("init_smb_request: invalid request size %u\n",
(unsigned int)req_size ));
return false;
}
req->request_time = timeval_current();
now = timeval_to_nttime(&req->request_time);
req->cmd = CVAL(inbuf, smb_com);
req->flags2 = SVAL(inbuf, smb_flg2);
req->smbpid = SVAL(inbuf, smb_pid);
req->mid = (uint64_t)SVAL(inbuf, smb_mid);
req->seqnum = seqnum;
req->vuid = SVAL(inbuf, smb_uid);
req->tid = SVAL(inbuf, smb_tid);
req->wct = CVAL(inbuf, smb_wct);
req->vwv = (const uint16_t *)(inbuf+smb_vwv);
req->buflen = smb_buflen(inbuf);
req->buf = (const uint8_t *)smb_buf_const(inbuf);
req->unread_bytes = unread_bytes;
req->encrypted = encrypted;
req->sconn = sconn;
req->xconn = xconn;
req->conn = NULL;
if (xconn != NULL) {
status = smb1srv_tcon_lookup(xconn, req->tid, now, &tcon);
if (NT_STATUS_IS_OK(status)) {
req->conn = tcon->compat;
}
}
req->chain_fsp = NULL;
req->smb2req = NULL;
req->chain = NULL;
req->posix_pathnames = lp_posix_pathnames();
smb_init_perfcount_data(&req->pcd);
/* Ensure we have at least wct words and 2 bytes of bcc. */
if (smb_size + req->wct*2 > req_size) {
DEBUG(0,("init_smb_request: invalid wct number %u (size %u)\n",
(unsigned int)req->wct,
(unsigned int)req_size));
return false;
}
/* Ensure bcc is correct. */
if (((const uint8_t *)smb_buf_const(inbuf)) + req->buflen > inbuf + req_size) {
DEBUG(0,("init_smb_request: invalid bcc number %u "
"(wct = %u, size %u)\n",
(unsigned int)req->buflen,
(unsigned int)req->wct,
(unsigned int)req_size));
return false;
}
req->outbuf = NULL;
return true;
}
static void smbd_server_connection_write_handler(
struct smbXsrv_connection *xconn)
{