LCOV - code coverage report
Current view: top level - source3/smbd - smb2_glue.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 40 41 97.6 %
Date: 2021-09-23 10:06:22 Functions: 3 3 100.0 %

          Line data    Source code
       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     1261492 : struct smb_request *smbd_smb2_fake_smb_request(struct smbd_smb2_request *req)
      30             : {
      31             :         struct smb_request *smbreq;
      32     1261492 :         const uint8_t *inhdr = SMBD_SMB2_IN_HDR_PTR(req);
      33             : 
      34     1261492 :         if (req->smb1req) {
      35         522 :                 smbreq = req->smb1req;
      36             :         } else {
      37     1260970 :                 smbreq = talloc_zero(req, struct smb_request);
      38     1260970 :                 if (smbreq == NULL) {
      39           0 :                         return NULL;
      40             :                 }
      41             :         }
      42             : 
      43     1261492 :         smbreq->request_time = req->request_time;
      44     1261492 :         if (req->session != NULL) {
      45     1261164 :                 smbreq->vuid = req->session->global->session_wire_id;
      46             :         }
      47     1261492 :         if (req->tcon != NULL) {
      48     1261164 :                 smbreq->tid = req->tcon->compat->cnum;
      49     1261164 :                 smbreq->conn = req->tcon->compat;
      50             :         }
      51     1261492 :         smbreq->sconn = req->sconn;
      52     1261492 :         smbreq->xconn = req->xconn;
      53     1261492 :         smbreq->session = req->session;
      54     1261492 :         smbreq->smbpid = (uint16_t)IVAL(inhdr, SMB2_HDR_PID);
      55     1261492 :         smbreq->flags2 = FLAGS2_UNICODE_STRINGS |
      56             :                          FLAGS2_32_BIT_ERROR_CODES |
      57             :                          FLAGS2_LONG_PATH_COMPONENTS |
      58             :                          FLAGS2_IS_LONG_NAME;
      59             : 
      60     1261492 :         if (IVAL(inhdr, SMB2_HDR_FLAGS) & SMB2_HDR_FLAG_DFS) {
      61        8654 :                 smbreq->flags2 |= FLAGS2_DFS_PATHNAMES;
      62             :         }
      63     1261492 :         smbreq->mid = BVAL(inhdr, SMB2_HDR_MESSAGE_ID);
      64     1261492 :         smbreq->chain_fsp = req->compat_chain_fsp;
      65     1261492 :         smbreq->smb2req = req;
      66     1261492 :         req->smb1req = smbreq;
      67             : 
      68     1261492 :         return smbreq;
      69             : }
      70             : 
      71             : /*********************************************************
      72             :  Are there unread bytes for recvfile ?
      73             : *********************************************************/
      74             : 
      75      128727 : size_t smbd_smb2_unread_bytes(struct smbd_smb2_request *req)
      76             : {
      77      128727 :         if (req->smb1req) {
      78      122228 :                 return req->smb1req->unread_bytes;
      79             :         }
      80        6499 :         return 0;
      81             : }
      82             : 
      83             : /*********************************************************
      84             :  Called from file_free() to remove any chained fsp pointers.
      85             : *********************************************************/
      86             : 
      87    10560528 : void remove_smb2_chained_fsp(files_struct *fsp)
      88             : {
      89    10560528 :         struct smbd_server_connection *sconn = fsp->conn->sconn;
      90    10560528 :         struct smbXsrv_connection *xconn = NULL;
      91             : 
      92    10560528 :         if (sconn->client != NULL) {
      93    10531592 :                 xconn = sconn->client->connections;
      94             :         }
      95             : 
      96    21020471 :         for (; xconn != NULL; xconn = xconn->next) {
      97             :                 struct smbd_smb2_request *smb2req;
      98             : 
      99    18719540 :                 for (smb2req = xconn->smb2.requests; smb2req; smb2req = smb2req->next) {
     100     8173134 :                         if (smb2req->compat_chain_fsp == fsp) {
     101      363094 :                                 smb2req->compat_chain_fsp = NULL;
     102             :                         }
     103     8173134 :                         if (smb2req->smb1req && smb2req->smb1req->chain_fsp == fsp) {
     104          24 :                                 smb2req->smb1req->chain_fsp = NULL;
     105             :                         }
     106             :                 }
     107             :         }
     108    10560528 : }

Generated by: LCOV version 1.13