1 /* 2 Unix SMB/CIFS implementation. 3 Core SMB2 server 4 5 Copyright (C) Stefan Metzmacher 2009 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 3 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 #include "includes.h" 22 #include "smbd/smbd.h" 23 #include "smbd/globals.h" 24 #include "../libcli/smb/smb_common.h" 25 26 #undef DBGC_CLASS 27 #define DBGC_CLASS DBGC_SMB2 28 29 struct smb_request *smbd_smb2_fake_smb_request(struct smbd_smb2_request *req) 30 { 31 struct smb_request *smbreq; 32 const uint8_t *inhdr = SMBD_SMB2_IN_HDR_PTR(req); 33 34 if (req->smb1req) { 35 smbreq = req->smb1req; 36 } else { 37 smbreq = talloc_zero(req, struct smb_request); 38 if (smbreq == NULL) { 39 return NULL; 40 } 41 } 42 43 smbreq->request_time = req->request_time; 44 smbreq->vuid = req->session->global->session_wire_id; 45 smbreq->tid = req->tcon->compat->cnum; 46 smbreq->conn = req->tcon->compat; 47 smbreq->sconn = req->sconn; 48 smbreq->xconn = req->xconn; 49 smbreq->session = req->session; smbd_smb2_request_process_getinfo(struct smbd_smb2_request * req)50 smbreq->smbpid = (uint16_t)IVAL(inhdr, SMB2_HDR_PID); 51 smbreq->flags2 = FLAGS2_UNICODE_STRINGS | 52 FLAGS2_32_BIT_ERROR_CODES | 53 FLAGS2_LONG_PATH_COMPONENTS | 54 FLAGS2_IS_LONG_NAME; 55 56 if (IVAL(inhdr, SMB2_HDR_FLAGS) & SMB2_HDR_FLAG_DFS) { 57 smbreq->flags2 |= FLAGS2_DFS_PATHNAMES; 58 } 59 smbreq->mid = BVAL(inhdr, SMB2_HDR_MESSAGE_ID); 60 smbreq->chain_fsp = req->compat_chain_fsp; 61 smbreq->smb2req = req; 62 req->smb1req = smbreq; 63 64 return smbreq; 65 } 66 67 /********************************************************* 68 Are there unread bytes for recvfile ? 69 *********************************************************/ 70 71 size_t smbd_smb2_unread_bytes(struct smbd_smb2_request *req) 72 { 73 if (req->smb1req) { 74 return req->smb1req->unread_bytes; 75 } 76 return 0; 77 } 78 79 /********************************************************* 80 Called from file_free() to remove any chained fsp pointers. 81 *********************************************************/ 82 83 void remove_smb2_chained_fsp(files_struct *fsp) 84 { 85 struct smbd_server_connection *sconn = fsp->conn->sconn; 86 struct smbXsrv_connection *xconn = NULL; 87 88 if (sconn->client != NULL) { 89 xconn = sconn->client->connections; 90 } 91 92 for (; xconn != NULL; xconn = xconn->next) { 93 struct smbd_smb2_request *smb2req; 94 95 for (smb2req = xconn->smb2.requests; smb2req; smb2req = smb2req->next) { 96 if (smb2req->compat_chain_fsp == fsp) { 97 smb2req->compat_chain_fsp = NULL; 98 } 99 if (smb2req->smb1req && smb2req->smb1req->chain_fsp == fsp) { 100 smb2req->smb1req->chain_fsp = NULL; 101 } 102 } 103 } 104 } 105