| 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 |
static void smb2cli_session_set_id(struct smbXcli_session *session, |
| 38 |
uint64_t session_id) |
| 39 |
{ |
| 40 |
smb2cli_session_set_id_and_flags(session, session_id, |
| 41 |
smb2cli_session_get_flags(session)); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
Try with a wrong session id and check error message. |
| 46 |
*/ |
| 47 |
|
| 48 |
bool run_sessidtest(struct torture_context *tctx, struct smb2_tree *tree) |
| 49 |
{ |
| 50 |
const char *fname = "sessid.tst"; |
| 51 |
struct smb2_handle fnum; |
| 52 |
struct smb2_create io = {0}; |
| 53 |
uint32_t session_id; |
| 54 |
union smb_fileinfo finfo; |
| 55 |
|
| 56 |
NTSTATUS status; |
| 57 |
|
| 58 |
smb2_util_unlink(tree, fname); |
| 59 |
|
| 60 |
io.in.fname = fname; |
| 61 |
io.in.desired_access = SEC_FILE_READ_DATA | SEC_FILE_WRITE_DATA; |
| 62 |
io.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF; |
| 63 |
io.in.share_access = NTCREATEX_SHARE_ACCESS_READ | |
| 64 |
NTCREATEX_SHARE_ACCESS_WRITE | |
| 65 |
NTCREATEX_SHARE_ACCESS_DELETE; |
| 66 |
status = smb2_create(tree, tree, &io); |
| 67 |
if (NT_STATUS_IS_ERR(status)) { |
| 68 |
torture_result(tctx, TORTURE_FAIL, "open of %s failed (%s)\n", |
| 69 |
fname, nt_errstr(status)); |
| 70 |
return false; |
| 71 |
} |
| 72 |
fnum = io.out.file.handle; |
| 73 |
|
| 74 |
session_id = smb2cli_session_current_id(tree->session->smbXcli); |
| 75 |
smb2cli_session_set_id(tree->session->smbXcli, session_id+1234); |
| 76 |
|
| 77 |
torture_comment(tctx, "Testing qfileinfo with wrong sessid\n"); |
| 78 |
|
| 79 |
finfo.all_info2.level = RAW_FILEINFO_SMB2_ALL_INFORMATION; |
| 80 |
finfo.all_info2.in.file.handle = fnum; |
| 81 |
status = smb2_getinfo_file(tree, tctx, &finfo); |
| 82 |
if (NT_STATUS_IS_OK(status)) { |
| 83 |
torture_fail(tctx, "smb2_getinfo_file passed with wrong sessid"); |
| 84 |
} |
| 85 |
|
| 86 |
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 |
smb2cli_session_set_id(tree->session->smbXcli, session_id); |
| 92 |
|
| 93 |
status = smb2_util_close(tree, fnum); |
| 94 |
torture_assert_ntstatus_ok(tctx, status, |
| 95 |
talloc_asprintf(tctx, "close failed (%s)", nt_errstr(status))); |
| 96 |
|
| 97 |
smb2_util_unlink(tree, fname); |
| 98 |
|
| 99 |
return true; |
| 100 |
} |