2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1997-2003
5 Copyright (C) Jelmer Vernooij 2006
6 Copyright (C) David Mulder 2020
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.
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.
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/>.
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"
37 static void smb2cli_session_set_id(struct smbXcli_session
*session
,
40 smb2cli_session_set_id_and_flags(session
, session_id
,
41 smb2cli_session_get_flags(session
));
45 Try with a wrong session id and check error message.
48 bool run_sessidtest(struct torture_context
*tctx
, struct smb2_tree
*tree
)
50 const char *fname
= "sessid.tst";
51 struct smb2_handle fnum
;
52 struct smb2_create io
= {0};
54 union smb_fileinfo finfo
;
58 smb2_util_unlink(tree
, 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
));
72 fnum
= io
.out
.file
.handle
;
74 session_id
= smb2cli_session_current_id(tree
->session
->smbXcli
);
75 smb2cli_session_set_id(tree
->session
->smbXcli
, session_id
+1234);
77 torture_comment(tctx
, "Testing qfileinfo with wrong sessid\n");
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");
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");
91 smb2cli_session_set_id(tree
->session
->smbXcli
, session_id
);
93 status
= smb2_util_close(tree
, fnum
);
94 torture_assert_ntstatus_ok(tctx
, status
,
95 talloc_asprintf(tctx
, "close failed (%s)", nt_errstr(status
)));
97 smb2_util_unlink(tree
, fname
);