LCOV - code coverage report
Current view: top level - source4/torture/smb2 - sessid.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 28 31 90.3 %
Date: 2021-09-23 10:06:22 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    SMB torture tester
       4             :    Copyright (C) Andrew Tridgell 1997-2003
       5             :    Copyright (C) Jelmer Vernooij 2006
       6             :    Copyright (C) David Mulder 2020
       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 "torture/smbtorture.h"
      24             : #include "libcli/libcli.h"
      25             : #include "libcli/raw/raw_proto.h"
      26             : #include "system/filesys.h"
      27             : #include "system/time.h"
      28             : #include "libcli/resolve/resolve.h"
      29             : #include "lib/events/events.h"
      30             : #include "param/param.h"
      31             : #include "libcli/smb2/smb2.h"
      32             : #include "libcli/smb2/smb2_calls.h"
      33             : #include "torture/smb2/proto.h"
      34             : #include "libcli/smb/smbXcli_base.h"
      35             : 
      36             : 
      37           8 : static void smb2cli_session_set_id(struct smbXcli_session *session,
      38             :                                    uint64_t session_id)
      39             : {
      40           8 :         smb2cli_session_set_id_and_flags(session, session_id,
      41           8 :                                          smb2cli_session_get_flags(session));
      42           8 : }
      43             : 
      44             : /**
      45             :   Try with a wrong session id and check error message.
      46             :  */
      47             : 
      48           4 : bool run_sessidtest(struct torture_context *tctx, struct smb2_tree *tree)
      49             : {
      50           4 :         const char *fname = "sessid.tst";
      51             :         struct smb2_handle fnum;
      52           4 :         struct smb2_create io = {0};
      53             :         uint32_t session_id;
      54             :         union smb_fileinfo finfo;
      55             : 
      56             :         NTSTATUS status;
      57             : 
      58           4 :         smb2_util_unlink(tree, fname);
      59             : 
      60           4 :         io.in.fname = fname;
      61           4 :         io.in.desired_access = SEC_FILE_READ_DATA | SEC_FILE_WRITE_DATA;
      62           4 :         io.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF;
      63           4 :         io.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
      64             :                              NTCREATEX_SHARE_ACCESS_WRITE |
      65             :                              NTCREATEX_SHARE_ACCESS_DELETE;
      66           4 :         status = smb2_create(tree, tree, &io);
      67           4 :         if (NT_STATUS_IS_ERR(status)) {
      68           0 :                 torture_result(tctx, TORTURE_FAIL, "open of %s failed (%s)\n",
      69             :                                fname, nt_errstr(status));
      70           0 :                 return false;
      71             :         }
      72           4 :         fnum = io.out.file.handle;
      73             : 
      74           4 :         session_id = smb2cli_session_current_id(tree->session->smbXcli);
      75           4 :         smb2cli_session_set_id(tree->session->smbXcli, session_id+1234);
      76             : 
      77           4 :         torture_comment(tctx, "Testing qfileinfo with wrong sessid\n");
      78             : 
      79           4 :         finfo.all_info2.level = RAW_FILEINFO_SMB2_ALL_INFORMATION;
      80           4 :         finfo.all_info2.in.file.handle = fnum;
      81           4 :         status = smb2_getinfo_file(tree, tctx, &finfo);
      82           4 :         if (NT_STATUS_IS_OK(status)) {
      83           0 :                 torture_fail(tctx, "smb2_getinfo_file passed with wrong sessid");
      84             :         }
      85             : 
      86           4 :         torture_assert_ntstatus_equal(tctx, status,
      87             :                                       NT_STATUS_USER_SESSION_DELETED,
      88             :                                       "smb2_getinfo_file should have returned "
      89             :                                       "NT_STATUS_USER_SESSION_DELETED");
      90             : 
      91           4 :         smb2cli_session_set_id(tree->session->smbXcli, session_id);
      92             : 
      93           4 :         status = smb2_util_close(tree, fnum);
      94           4 :         torture_assert_ntstatus_ok(tctx, status,
      95             :                 talloc_asprintf(tctx, "close failed (%s)", nt_errstr(status)));
      96             : 
      97           4 :         smb2_util_unlink(tree, fname);
      98             : 
      99           4 :         return true;
     100             : }

Generated by: LCOV version 1.13