LCOV - code coverage report
Current view: top level - source3/smbd - smb2_glue.c (source / functions) Hit Total Coverage
Test: coverage report for fix-15632 9995c5c2 Lines: 48 49 98.0 %
Date: 2024-04-13 12:30:31 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     1317684 : struct smb_request *smbd_smb2_fake_smb_request(struct smbd_smb2_request *req,
      30             :                                                struct files_struct *fsp)
      31             : {
      32        8766 :         struct smb_request *smbreq;
      33     1317684 :         const uint8_t *inhdr = SMBD_SMB2_IN_HDR_PTR(req);
      34             : 
      35     1317684 :         if (req->smb1req) {
      36         480 :                 smbreq = req->smb1req;
      37             :         } else {
      38     1317204 :                 smbreq = talloc_zero(req, struct smb_request);
      39     1317204 :                 if (smbreq == NULL) {
      40           0 :                         return NULL;
      41             :                 }
      42             :         }
      43             : 
      44     1317684 :         smbreq->request_time = req->request_time;
      45     1317684 :         if (req->session != NULL) {
      46     1317356 :                 smbreq->vuid = req->session->global->session_wire_id;
      47             :         }
      48     1317684 :         if (req->tcon != NULL) {
      49     1314546 :                 smbreq->tid = req->tcon->compat->cnum;
      50     1314546 :                 smbreq->conn = req->tcon->compat;
      51             :         }
      52     1317684 :         smbreq->sconn = req->sconn;
      53     1317684 :         smbreq->xconn = req->xconn;
      54     1317684 :         smbreq->session = req->session;
      55     1317684 :         smbreq->smbpid = (uint16_t)IVAL(inhdr, SMB2_HDR_PID);
      56     1317684 :         smbreq->flags2 = FLAGS2_UNICODE_STRINGS |
      57             :                          FLAGS2_32_BIT_ERROR_CODES |
      58             :                          FLAGS2_LONG_PATH_COMPONENTS |
      59             :                          FLAGS2_IS_LONG_NAME;
      60             : 
      61             :         /* Only set FLAGS2_DFS_PATHNAMES if it's really a DFS share */
      62     2632230 :         if (smbreq->conn != NULL &&
      63     2629092 :             lp_host_msdfs() &&
      64     1314546 :             lp_msdfs_root(SNUM(smbreq->conn))) {
      65       24484 :                 if (IVAL(inhdr, SMB2_HDR_FLAGS) & SMB2_HDR_FLAG_DFS) {
      66       12592 :                         smbreq->flags2 |= FLAGS2_DFS_PATHNAMES;
      67             :                 }
      68             :         }
      69     1317684 :         smbreq->mid = BVAL(inhdr, SMB2_HDR_MESSAGE_ID);
      70     1317684 :         smbreq->chain_fsp = req->compat_chain_fsp;
      71     1317684 :         if (fsp != NULL) {
      72      821955 :                 smbreq->posix_pathnames =
      73      821955 :                         (fsp->fsp_name->flags & SMB_FILENAME_POSIX_PATH);
      74             :         }
      75     1317684 :         smbreq->smb2req = req;
      76     1317684 :         req->smb1req = smbreq;
      77             : 
      78     1317684 :         return smbreq;
      79             : }
      80             : 
      81             : /*********************************************************
      82             :  Are there unread bytes for recvfile ?
      83             : *********************************************************/
      84             : 
      85      141568 : size_t smbd_smb2_unread_bytes(struct smbd_smb2_request *req)
      86             : {
      87      141568 :         if (req->smb1req) {
      88      133669 :                 return req->smb1req->unread_bytes;
      89             :         }
      90        7523 :         return 0;
      91             : }
      92             : 
      93             : /*********************************************************
      94             :  Called from file_free() to remove any chained fsp pointers.
      95             : *********************************************************/
      96             : 
      97     6858697 : void remove_smb2_chained_fsp(files_struct *fsp)
      98             : {
      99     6858697 :         struct smbd_server_connection *sconn = fsp->conn->sconn;
     100     6858697 :         struct smbXsrv_connection *xconn = NULL;
     101             : 
     102     6858697 :         if (sconn->client != NULL) {
     103     6721767 :                 xconn = sconn->client->connections;
     104             :         }
     105             : 
     106    13598621 :         for (; xconn != NULL; xconn = xconn->next) {
     107       34895 :                 struct smbd_smb2_request *smb2req;
     108             : 
     109    11875604 :                 for (smb2req = xconn->smb2.requests; smb2req; smb2req = smb2req->next) {
     110     5135680 :                         if (smb2req->compat_chain_fsp == fsp) {
     111      368284 :                                 smb2req->compat_chain_fsp = NULL;
     112             :                         }
     113     5135680 :                         if (smb2req->smb1req && smb2req->smb1req->chain_fsp == fsp) {
     114          24 :                                 smb2req->smb1req->chain_fsp = NULL;
     115             :                         }
     116             :                 }
     117             :         }
     118     6858697 : }

Generated by: LCOV version 1.14