LCOV - code coverage report
Current view: top level - source3/smbd - smb1_utils.c (source / functions) Hit Total Coverage
Test: coverage report for master 6248eab5 Lines: 31 40 77.5 %
Date: 2021-08-25 13:27:56 Functions: 1 2 50.0 %

          Line data    Source code
       1             : /*
       2             :  * Unix SMB/CIFS implementation.
       3             :  * Util functions valid in the SMB1 server
       4             :  *
       5             :  * Copyright (C) Volker Lendecke 2019
       6             :  * Copyright by the authors of the functions moved here eventually
       7             :  *
       8             :  * This program is free software; you can redistribute it and/or modify
       9             :  * it under the terms of the GNU General Public License as published by
      10             :  * the Free Software Foundation; either version 3 of the License, or
      11             :  * (at your option) any later version.
      12             :  *
      13             :  * This program is distributed in the hope that it will be useful,
      14             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             :  * GNU General Public License for more details.
      17             :  *
      18             :  * You should have received a copy of the GNU General Public License
      19             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
      20             :  */
      21             : 
      22             : #include "includes.h"
      23             : #include "smb1_utils.h"
      24             : #include "libcli/security/security.h"
      25             : #include "lib/util/sys_rw_data.h"
      26             : #include "smbd/fd_handle.h"
      27             : 
      28             : /****************************************************************************
      29             :  Special FCB or DOS processing in the case of a sharing violation.
      30             :  Try and find a duplicated file handle.
      31             : ****************************************************************************/
      32             : 
      33        4425 : struct files_struct *fcb_or_dos_open(
      34             :         struct smb_request *req,
      35             :         const struct smb_filename *smb_fname,
      36             :         uint32_t access_mask,
      37             :         uint32_t create_options,
      38             :         uint32_t private_flags)
      39             : {
      40        4425 :         struct connection_struct *conn = req->conn;
      41        4425 :         struct file_id id = vfs_file_id_from_sbuf(conn, &smb_fname->st);
      42        4425 :         struct files_struct *fsp = NULL, *new_fsp = NULL;
      43             :         NTSTATUS status;
      44             : 
      45        4425 :         if ((private_flags &
      46             :              (NTCREATEX_FLAG_DENY_DOS|
      47             :               NTCREATEX_FLAG_DENY_FCB))
      48             :             == 0) {
      49        2976 :                 return NULL;
      50             :         }
      51             : 
      52        3422 :         for(fsp = file_find_di_first(conn->sconn, id, true);
      53             :             fsp != NULL;
      54         540 :             fsp = file_find_di_next(fsp, true)) {
      55             : 
      56         677 :                 DBG_DEBUG("Checking file %s, fd = %d, vuid = %"PRIu64", "
      57             :                           "file_pid = %"PRIu16", "
      58             :                           "private_options = 0x%"PRIx32", "
      59             :                           "access_mask = 0x%"PRIx32"\n",
      60             :                           fsp_str_dbg(fsp),
      61             :                           fsp_get_pathref_fd(fsp),
      62             :                           fsp->vuid,
      63             :                           fsp->file_pid,
      64             :                           fh_get_private_options(fsp->fh),
      65             :                           fsp->access_mask);
      66             : 
      67        1354 :                 if (fsp_get_pathref_fd(fsp) != -1 &&
      68        1354 :                     fsp->vuid == req->vuid &&
      69        1354 :                     fsp->file_pid == req->smbpid &&
      70         677 :                     (fh_get_private_options(fsp->fh) &
      71             :                      (NTCREATEX_FLAG_DENY_DOS |
      72         169 :                       NTCREATEX_FLAG_DENY_FCB)) &&
      73         306 :                     (fsp->access_mask & FILE_WRITE_DATA) &&
      74         274 :                     strequal(fsp->fsp_name->base_name, smb_fname->base_name) &&
      75         137 :                     strequal(fsp->fsp_name->stream_name,
      76         137 :                              smb_fname->stream_name)) {
      77         137 :                         DBG_DEBUG("file match\n");
      78         136 :                         break;
      79             :                 }
      80             :         }
      81             : 
      82        1441 :         if (fsp == NULL) {
      83        1304 :                 return NULL;
      84             :         }
      85             : 
      86             :         /* quite an insane set of semantics ... */
      87         197 :         if (is_executable(smb_fname->base_name) &&
      88          60 :             (fh_get_private_options(fsp->fh) & NTCREATEX_FLAG_DENY_DOS)) {
      89          24 :                 DBG_DEBUG("file fail due to is_executable.\n");
      90          24 :                 return NULL;
      91             :         }
      92             : 
      93         113 :         status = file_new(req, conn, &new_fsp);
      94         113 :         if (!NT_STATUS_IS_OK(status)) {
      95           0 :                 DBG_DEBUG("file_new failed: %s\n", nt_errstr(status));
      96           0 :                 return NULL;
      97             :         }
      98             : 
      99         113 :         status = dup_file_fsp(
     100             :                 req,
     101             :                 fsp,
     102             :                 access_mask,
     103             :                 create_options,
     104             :                 new_fsp);
     105             : 
     106         113 :         if (!NT_STATUS_IS_OK(status)) {
     107           0 :                 DBG_DEBUG("dup_file_fsp failed: %s\n", nt_errstr(status));
     108           0 :                 file_free(req, new_fsp);
     109           0 :                 return NULL;
     110             :         }
     111             : 
     112         113 :         return new_fsp;
     113             : }
     114             : 
     115             : /****************************************************************************
     116             :  Send a keepalive packet (rfc1002).
     117             : ****************************************************************************/
     118             : 
     119           0 : bool send_keepalive(int client)
     120             : {
     121             :         unsigned char buf[4];
     122             : 
     123           0 :         buf[0] = NBSSkeepalive;
     124           0 :         buf[1] = buf[2] = buf[3] = 0;
     125             : 
     126           0 :         return(write_data(client,(char *)buf,4) == 4);
     127             : }

Generated by: LCOV version 1.13