diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index 35f0c1ef721..de03cb77795 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -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 */ diff --git a/source3/smbd/smb1_process.c b/source3/smbd/smb1_process.c index cbd0a8aa334..a24f2089d85 100644 --- a/source3/smbd/smb1_process.c +++ b/source3/smbd/smb1_process.c @@ -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. diff --git a/source3/smbd/smb2_process.c b/source3/smbd/smb2_process.c index 0bc77b97120..35d18b9aaa8 100644 --- a/source3/smbd/smb2_process.c +++ b/source3/smbd/smb2_process.c @@ -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) {