LCOV - code coverage report
Current view: top level - source4/torture/smb2 - sessid.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 32 35 91.4 %
Date: 2024-04-21 15:09:00 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          10 : static void smb2cli_session_set_id(struct smbXcli_session *session,
      38             :                                    uint64_t session_id)
      39             : {
      40          10 :         smb2cli_session_set_id_and_flags(session, session_id,
      41          10 :                                          smb2cli_session_get_flags(session));
      42           8 : }
      43             : 
      44             : /**
      45             :   Try with a wrong session id and check error message.
      46             :  */
      47             : 
      48           5 : bool run_sessidtest(struct torture_context *tctx, struct smb2_tree *tree)
      49             : {
      50           5 :         const char *fname = "sessid.tst";
      51           1 :         struct smb2_handle fnum;
      52           5 :         struct smb2_create io = {0};
      53           1 :         uint32_t session_id;
      54           1 :         union smb_fileinfo finfo;
      55             : 
      56           1 :         NTSTATUS status;
      57             : 
      58           5 :         smb2_util_unlink(tree, fname);
      59             : 
      60           5 :         io.in.fname = fname;
      61           5 :         io.in.desired_access = SEC_FILE_READ_DATA | SEC_FILE_WRITE_DATA;
      62           5 :         io.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF;
      63           5 :         io.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
      64             :                              NTCREATEX_SHARE_ACCESS_WRITE |
      65             :                              NTCREATEX_SHARE_ACCESS_DELETE;
      66           5 :         status = smb2_create(tree, tree, &io);
      67           5 :         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           5 :         fnum = io.out.file.handle;
      73             : 
      74           5 :         session_id = smb2cli_session_current_id(tree->session->smbXcli);
      75           5 :         smb2cli_session_set_id(tree->session->smbXcli, session_id+1234);
      76             : 
      77           5 :         torture_comment(tctx, "Testing qfileinfo with wrong sessid\n");
      78             : 
      79           5 :         finfo.all_info2.level = RAW_FILEINFO_SMB2_ALL_INFORMATION;
      80           5 :         finfo.all_info2.in.file.handle = fnum;
      81           5 :         status = smb2_getinfo_file(tree, tctx, &finfo);
      82           5 :         if (NT_STATUS_IS_OK(status)) {
      83           0 :                 torture_fail(tctx, "smb2_getinfo_file passed with wrong sessid");
      84             :         }
      85             : 
      86           5 :         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           5 :         smb2cli_session_set_id(tree->session->smbXcli, session_id);
      92             : 
      93           5 :         status = smb2_util_close(tree, fnum);
      94           5 :         torture_assert_ntstatus_ok(tctx, status,
      95             :                 talloc_asprintf(tctx, "close failed (%s)", nt_errstr(status)));
      96             : 
      97           5 :         smb2_util_unlink(tree, fname);
      98             : 
      99           5 :         return true;
     100             : }

Generated by: LCOV version 1.14