2003-08-13 05:53:07 +04:00
/*
Unix SMB / CIFS implementation .
test suite for session setup operations
Copyright ( C ) Andrew Tridgell 2003
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-10 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2003-08-13 05:53:07 +04:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2003-08-13 05:53:07 +04:00
*/
# include "includes.h"
2004-11-01 04:03:22 +03:00
# include "libcli/raw/libcliraw.h"
2008-04-02 06:53:27 +04:00
# include "libcli/raw/raw_proto.h"
2005-09-26 15:47:55 +04:00
# include "libcli/smb_composite/smb_composite.h"
2005-03-22 00:22:07 +03:00
# include "lib/cmdline/popt_common.h"
2006-01-03 18:40:05 +03:00
# include "libcli/libcli.h"
2006-03-17 20:59:58 +03:00
# include "torture/util.h"
2006-03-14 04:29:56 +03:00
# include "auth/credentials/credentials.h"
2007-09-08 16:42:09 +04:00
# include "param/param.h"
2011-03-19 02:42:42 +03:00
# include "torture/raw/proto.h"
2003-08-13 05:53:07 +04:00
# define BASEDIR "\\rawcontext"
2012-05-01 14:39:21 +04:00
# define CHECK_STATUS(status, correct) \
torture_assert_ntstatus_equal_goto ( tctx , status , correct , ret , done , __location__ )
# define CHECK_VALUE(v, correct) \
torture_assert_int_equal_goto ( tctx , v , correct , ret , done , __location__ )
# define CHECK_NOT_VALUE(v, correct) \
torture_assert_goto ( tctx , ( ( v ) ! = ( correct ) ) , ret , done , \
talloc_asprintf ( tctx , " (%s) Incorrect value %s=%d - should not be %d \n " , \
__location__ , # v , v , correct ) ) ;
2004-08-12 11:29:49 +04:00
2003-08-13 05:53:07 +04:00
/*
test session ops
*/
2012-05-03 16:41:21 +04:00
static bool test_session ( struct torture_context * tctx ,
struct smbcli_state * cli )
2003-08-13 05:53:07 +04:00
{
NTSTATUS status ;
2007-10-07 02:28:14 +04:00
bool ret = true ;
2004-08-04 17:23:35 +04:00
struct smbcli_session * session ;
2004-08-12 11:29:49 +04:00
struct smbcli_session * session2 ;
2012-05-01 15:33:14 +04:00
uint16_t vuid3 ;
2004-08-12 11:29:49 +04:00
struct smbcli_session * session3 ;
2005-06-17 10:30:03 +04:00
struct smbcli_session * session4 ;
struct cli_credentials * anon_creds ;
2005-04-12 11:43:38 +04:00
struct smbcli_session * sessions [ 15 ] ;
struct composite_context * composite_contexts [ 15 ] ;
2004-08-04 17:23:35 +04:00
struct smbcli_tree * tree ;
2005-01-16 14:15:08 +03:00
struct smb_composite_sesssetup setup ;
2005-04-12 11:43:38 +04:00
struct smb_composite_sesssetup setups [ 15 ] ;
2008-11-02 04:05:48 +03:00
struct gensec_settings * gensec_settings ;
2003-08-13 05:53:07 +04:00
union smb_open io ;
union smb_write wr ;
union smb_close cl ;
int fnum ;
const char * fname = BASEDIR " \\ test.txt " ;
2004-12-04 16:56:25 +03:00
uint8_t c = 1 ;
2005-04-12 11:43:38 +04:00
int i ;
2008-09-30 03:29:53 +04:00
struct smbcli_session_options options ;
2003-08-13 05:53:07 +04:00
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " TESTING SESSION HANDLING \n " ) ;
2003-08-13 05:53:07 +04:00
2012-05-18 09:43:31 +04:00
torture_assert ( tctx , torture_setup_dir ( cli , BASEDIR ) , " Failed to setup up test directory: " BASEDIR ) ;
2003-08-13 05:53:07 +04:00
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " create a second security context on the same transport \n " ) ;
2008-09-30 03:29:53 +04:00
2010-07-16 08:32:42 +04:00
lpcfg_smbcli_session_options ( tctx - > lp_ctx , & options ) ;
gensec_settings = lpcfg_gensec_settings ( tctx , tctx - > lp_ctx ) ;
2008-09-30 03:29:53 +04:00
session = smbcli_session_init ( cli - > transport , tctx , false , options ) ;
2004-09-26 15:30:20 +04:00
2005-01-16 14:15:08 +03:00
setup . in . sesskey = cli - > transport - > negotiate . sesskey ;
setup . in . capabilities = cli - > transport - > negotiate . capabilities ; /* ignored in secondary session setup, except by our libs, which care about the extended security bit */
2010-07-16 08:32:42 +04:00
setup . in . workgroup = lpcfg_workgroup ( tctx - > lp_ctx ) ;
r6028: A MAJOR update to intergrate the new credentails system fully with
GENSEC, and to pull SCHANNEL into GENSEC, by making it less 'special'.
GENSEC now no longer has it's own handling of 'set username' etc,
instead it uses cli_credentials calls.
In order to link the credentails code right though Samba, a lot of
interfaces have changed to remove 'username, domain, password'
arguments, and these have been replaced with a single 'struct
cli_credentials'.
In the session setup code, a new parameter 'workgroup' contains the
client/server current workgroup, which seems unrelated to the
authentication exchange (it was being filled in from the auth info).
This allows in particular kerberos to only call back for passwords
when it actually needs to perform the kinit.
The kerberos code has been modified not to use the SPNEGO provided
'principal name' (in the mechListMIC), but to instead use the name the
host was connected to as. This better matches Microsoft behaviour,
is more secure and allows better use of standard kerberos functions.
To achieve this, I made changes to our socket code so that the
hostname (before name resolution) is now recorded on the socket.
In schannel, most of the code from librpc/rpc/dcerpc_schannel.c is now
in libcli/auth/schannel.c, and it looks much more like a standard
GENSEC module. The actual sign/seal code moved to
libcli/auth/schannel_sign.c in a previous commit.
The schannel credentails structure is now merged with the rest of the
credentails, as many of the values (username, workstation, domain)
where already present there. This makes handling this in a generic
manner much easier, as there is no longer a custom entry-point.
The auth_domain module continues to be developed, but is now just as
functional as auth_winbind. The changes here are consequential to the
schannel changes.
The only removed function at this point is the RPC-LOGIN test
(simulating the load of a WinXP login), which needs much more work to
clean it up (it contains copies of too much code from all over the
torture suite, and I havn't been able to penetrate its 'structure').
Andrew Bartlett
(This used to be commit 2301a4b38a21aa60917973451687063d83d18d66)
2005-03-24 07:14:06 +03:00
2017-05-10 02:10:03 +03:00
setup . in . credentials = popt_get_cmdline_credentials ( ) ;
2008-11-02 04:05:48 +03:00
setup . in . gensec_settings = gensec_settings ;
2003-08-13 05:53:07 +04:00
2005-01-16 14:15:08 +03:00
status = smb_composite_sesssetup ( session , & setup ) ;
2003-08-13 05:53:07 +04:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2005-04-12 11:43:38 +04:00
2005-01-16 14:15:08 +03:00
session - > vuid = setup . out . vuid ;
2003-08-13 05:53:07 +04:00
2012-05-01 15:33:14 +04:00
torture_comment ( tctx , " create a third security context on the same transport, with given vuid \n " ) ;
2008-09-30 03:29:53 +04:00
session2 = smbcli_session_init ( cli - > transport , tctx , false , options ) ;
2004-09-26 15:30:20 +04:00
2012-05-01 15:33:14 +04:00
if ( cli - > transport - > negotiate . capabilities & CAP_EXTENDED_SECURITY ) {
vuid3 = session - > vuid + 1 ;
if ( vuid3 = = cli - > session - > vuid ) {
vuid3 + = 1 ;
}
if ( vuid3 = = UINT16_MAX ) {
vuid3 + = 2 ;
}
} else {
vuid3 = session - > vuid ;
}
session2 - > vuid = vuid3 ;
2005-01-16 14:15:08 +03:00
setup . in . sesskey = cli - > transport - > negotiate . sesskey ;
setup . in . capabilities = cli - > transport - > negotiate . capabilities ; /* ignored in secondary session setup, except by our libs, which care about the extended security bit */
2010-07-16 08:32:42 +04:00
setup . in . workgroup = lpcfg_workgroup ( tctx - > lp_ctx ) ;
2005-03-22 00:22:07 +03:00
2017-05-10 02:10:03 +03:00
setup . in . credentials = popt_get_cmdline_credentials ( ) ;
2005-01-16 14:15:08 +03:00
2012-05-01 15:33:14 +04:00
torture_comment ( tctx , " vuid1=%d vuid2=%d vuid3=%d \n " , cli - > session - > vuid , session - > vuid , vuid3 ) ;
2004-08-12 11:29:49 +04:00
2012-05-01 15:33:14 +04:00
status = smb_composite_sesssetup ( session2 , & setup ) ;
2005-04-12 11:43:38 +04:00
if ( cli - > transport - > negotiate . capabilities & CAP_EXTENDED_SECURITY ) {
2012-05-01 15:33:14 +04:00
CHECK_STATUS ( status , NT_STATUS_DOS ( ERRSRV , ERRbaduid ) ) ;
2005-04-12 11:43:38 +04:00
} else {
2012-05-01 15:33:14 +04:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
session2 - > vuid = setup . out . vuid ;
CHECK_NOT_VALUE ( session2 - > vuid , vuid3 ) ;
2005-04-12 11:43:38 +04:00
}
2012-05-01 15:33:14 +04:00
torture_comment ( tctx , " vuid1=%d vuid2=%d vuid3=%d=>%d (%s) \n " ,
cli - > session - > vuid , session - > vuid ,
vuid3 , session2 - > vuid , nt_errstr ( status ) ) ;
2004-09-26 15:30:20 +04:00
talloc_free ( session2 ) ;
2004-08-12 11:29:49 +04:00
if ( cli - > transport - > negotiate . capabilities & CAP_EXTENDED_SECURITY ) {
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " create a fourth security context on the same transport, without extended security \n " ) ;
2008-09-30 03:29:53 +04:00
session3 = smbcli_session_init ( cli - > transport , tctx , false , options ) ;
2004-09-26 15:30:20 +04:00
2012-05-01 15:33:14 +04:00
session3 - > vuid = vuid3 ;
2005-01-16 14:15:08 +03:00
setup . in . sesskey = cli - > transport - > negotiate . sesskey ;
2005-07-04 09:05:28 +04:00
setup . in . capabilities & = ~ CAP_EXTENDED_SECURITY ; /* force a non extended security login (should fail) */
2010-07-16 08:32:42 +04:00
setup . in . workgroup = lpcfg_workgroup ( tctx - > lp_ctx ) ;
r6028: A MAJOR update to intergrate the new credentails system fully with
GENSEC, and to pull SCHANNEL into GENSEC, by making it less 'special'.
GENSEC now no longer has it's own handling of 'set username' etc,
instead it uses cli_credentials calls.
In order to link the credentails code right though Samba, a lot of
interfaces have changed to remove 'username, domain, password'
arguments, and these have been replaced with a single 'struct
cli_credentials'.
In the session setup code, a new parameter 'workgroup' contains the
client/server current workgroup, which seems unrelated to the
authentication exchange (it was being filled in from the auth info).
This allows in particular kerberos to only call back for passwords
when it actually needs to perform the kinit.
The kerberos code has been modified not to use the SPNEGO provided
'principal name' (in the mechListMIC), but to instead use the name the
host was connected to as. This better matches Microsoft behaviour,
is more secure and allows better use of standard kerberos functions.
To achieve this, I made changes to our socket code so that the
hostname (before name resolution) is now recorded on the socket.
In schannel, most of the code from librpc/rpc/dcerpc_schannel.c is now
in libcli/auth/schannel.c, and it looks much more like a standard
GENSEC module. The actual sign/seal code moved to
libcli/auth/schannel_sign.c in a previous commit.
The schannel credentails structure is now merged with the rest of the
credentails, as many of the values (username, workstation, domain)
where already present there. This makes handling this in a generic
manner much easier, as there is no longer a custom entry-point.
The auth_domain module continues to be developed, but is now just as
functional as auth_winbind. The changes here are consequential to the
schannel changes.
The only removed function at this point is the RPC-LOGIN test
(simulating the load of a WinXP login), which needs much more work to
clean it up (it contains copies of too much code from all over the
torture suite, and I havn't been able to penetrate its 'structure').
Andrew Bartlett
(This used to be commit 2301a4b38a21aa60917973451687063d83d18d66)
2005-03-24 07:14:06 +03:00
2017-05-10 02:10:03 +03:00
setup . in . credentials = popt_get_cmdline_credentials ( ) ;
2005-01-16 14:15:08 +03:00
status = smb_composite_sesssetup ( session3 , & setup ) ;
2012-05-01 14:38:06 +04:00
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_LOGON_FAILURE ) ) {
/*
* Windows 2008 R2 returns INVALID_PARAMETER
* while Windows 2000 sp4 returns LOGON_FAILURE . . .
*/
CHECK_STATUS ( status , NT_STATUS_INVALID_PARAMETER ) ;
}
2004-09-26 15:30:20 +04:00
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " create a fouth anonymous security context on the same transport, without extended security \n " ) ;
2008-09-30 03:29:53 +04:00
session4 = smbcli_session_init ( cli - > transport , tctx , false , options ) ;
2005-06-17 10:30:03 +04:00
2012-05-01 15:33:14 +04:00
session4 - > vuid = vuid3 ;
2005-06-17 10:30:03 +04:00
setup . in . sesskey = cli - > transport - > negotiate . sesskey ;
2005-07-04 09:05:28 +04:00
setup . in . capabilities & = ~ CAP_EXTENDED_SECURITY ; /* force a non extended security login (should fail) */
2010-07-16 08:32:42 +04:00
setup . in . workgroup = lpcfg_workgroup ( tctx - > lp_ctx ) ;
2005-06-17 10:30:03 +04:00
2007-12-03 02:28:22 +03:00
anon_creds = cli_credentials_init ( tctx ) ;
cli_credentials_set_conf ( anon_creds , tctx - > lp_ctx ) ;
2005-06-17 10:30:03 +04:00
cli_credentials_set_anonymous ( anon_creds ) ;
setup . in . credentials = anon_creds ;
status = smb_composite_sesssetup ( session3 , & setup ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
talloc_free ( session4 ) ;
2004-08-12 11:29:49 +04:00
}
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " use the same tree as the existing connection \n " ) ;
2007-12-03 02:28:22 +03:00
tree = smbcli_tree_init ( session , tctx , false ) ;
2003-08-13 05:53:07 +04:00
tree - > tid = cli - > tree - > tid ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " create a file using the new vuid \n " ) ;
2003-08-13 05:53:07 +04:00
io . generic . level = RAW_OPEN_NTCREATEX ;
2009-10-15 11:26:19 +04:00
io . ntcreatex . in . root_fid . fnum = 0 ;
2003-08-13 05:53:07 +04:00
io . ntcreatex . in . flags = 0 ;
2004-12-02 07:37:36 +03:00
io . ntcreatex . in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
2003-08-13 05:53:07 +04:00
io . ntcreatex . in . create_options = 0 ;
io . ntcreatex . in . file_attr = FILE_ATTRIBUTE_NORMAL ;
io . ntcreatex . in . share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE ;
io . ntcreatex . in . alloc_size = 0 ;
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_CREATE ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
io . ntcreatex . in . fname = fname ;
2007-12-03 02:28:22 +03:00
status = smb_raw_open ( tree , tctx , & io ) ;
2003-08-13 05:53:07 +04:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-13 01:48:25 +03:00
fnum = io . ntcreatex . out . file . fnum ;
2003-08-13 05:53:07 +04:00
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " write using the old vuid \n " ) ;
2003-08-13 05:53:07 +04:00
wr . generic . level = RAW_WRITE_WRITEX ;
2006-03-13 01:48:25 +03:00
wr . writex . in . file . fnum = fnum ;
2003-08-13 05:53:07 +04:00
wr . writex . in . offset = 0 ;
wr . writex . in . wmode = 0 ;
wr . writex . in . remaining = 0 ;
wr . writex . in . count = 1 ;
wr . writex . in . data = & c ;
status = smb_raw_write ( cli - > tree , & wr ) ;
CHECK_STATUS ( status , NT_STATUS_INVALID_HANDLE ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " write with the new vuid \n " ) ;
2003-08-13 05:53:07 +04:00
status = smb_raw_write ( tree , & wr ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( wr . writex . out . nwritten , 1 ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " logoff the new vuid \n " ) ;
2003-08-13 05:53:07 +04:00
status = smb_raw_ulogoff ( session ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " the new vuid should not now be accessible \n " ) ;
2003-08-13 05:53:07 +04:00
status = smb_raw_write ( tree , & wr ) ;
2005-07-04 09:05:28 +04:00
CHECK_STATUS ( status , NT_STATUS_INVALID_HANDLE ) ;
2003-08-13 05:53:07 +04:00
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " second logoff for the new vuid should fail \n " ) ;
2005-04-12 11:43:38 +04:00
status = smb_raw_ulogoff ( session ) ;
2005-07-04 05:23:38 +04:00
CHECK_STATUS ( status , NT_STATUS_DOS ( ERRSRV , ERRbaduid ) ) ;
2012-05-01 15:33:14 +04:00
talloc_free ( tree ) ;
2005-04-12 11:43:38 +04:00
talloc_free ( session ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " the fnum should have been auto-closed \n " ) ;
2003-08-13 05:53:07 +04:00
cl . close . level = RAW_CLOSE_CLOSE ;
2006-03-13 01:48:25 +03:00
cl . close . in . file . fnum = fnum ;
2003-08-13 05:53:07 +04:00
cl . close . in . write_time = 0 ;
status = smb_raw_close ( cli - > tree , & cl ) ;
CHECK_STATUS ( status , NT_STATUS_INVALID_HANDLE ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " create %d secondary security contexts on the same transport \n " ,
2005-07-17 13:20:52 +04:00
( int ) ARRAY_SIZE ( sessions ) ) ;
2005-04-12 11:43:38 +04:00
for ( i = 0 ; i < ARRAY_SIZE ( sessions ) ; i + + ) {
setups [ i ] . in . sesskey = cli - > transport - > negotiate . sesskey ;
setups [ i ] . in . capabilities = cli - > transport - > negotiate . capabilities ; /* ignored in secondary session setup, except by our libs, which care about the extended security bit */
2010-07-16 08:32:42 +04:00
setups [ i ] . in . workgroup = lpcfg_workgroup ( tctx - > lp_ctx ) ;
2005-04-12 11:43:38 +04:00
2017-05-10 02:10:03 +03:00
setups [ i ] . in . credentials = popt_get_cmdline_credentials ( ) ;
2008-11-02 04:05:48 +03:00
setups [ i ] . in . gensec_settings = gensec_settings ;
2005-04-12 11:43:38 +04:00
2008-09-30 03:29:53 +04:00
sessions [ i ] = smbcli_session_init ( cli - > transport , tctx , false , options ) ;
2005-04-12 11:43:38 +04:00
composite_contexts [ i ] = smb_composite_sesssetup_send ( sessions [ i ] , & setups [ i ] ) ;
}
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " finishing %d secondary security contexts on the same transport \n " ,
2005-07-17 13:20:52 +04:00
( int ) ARRAY_SIZE ( sessions ) ) ;
2005-04-12 11:43:38 +04:00
for ( i = 0 ; i < ARRAY_SIZE ( sessions ) ; i + + ) {
status = smb_composite_sesssetup_recv ( composite_contexts [ i ] ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
sessions [ i ] - > vuid = setups [ i ] . out . vuid ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " VUID: %d \n " , sessions [ i ] - > vuid ) ;
2005-04-12 11:43:38 +04:00
status = smb_raw_ulogoff ( sessions [ i ] ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
}
2003-08-13 05:53:07 +04:00
done :
return ret ;
}
/*
test tree ops
*/
2012-05-03 16:41:21 +04:00
static bool test_tree ( struct torture_context * tctx , struct smbcli_state * cli )
2003-08-13 05:53:07 +04:00
{
NTSTATUS status ;
2007-10-07 02:28:14 +04:00
bool ret = true ;
2005-08-04 08:21:52 +04:00
const char * share , * host ;
2004-08-04 17:23:35 +04:00
struct smbcli_tree * tree ;
2003-08-13 05:53:07 +04:00
union smb_tcon tcon ;
union smb_open io ;
union smb_write wr ;
union smb_close cl ;
int fnum ;
const char * fname = BASEDIR " \\ test.txt " ;
2004-12-04 16:56:25 +03:00
uint8_t c = 1 ;
2003-08-13 05:53:07 +04:00
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " TESTING TREE HANDLING \n " ) ;
2003-08-13 05:53:07 +04:00
2012-05-18 09:43:31 +04:00
torture_assert ( tctx , torture_setup_dir ( cli , BASEDIR ) , " Failed to setup up test directory: " BASEDIR ) ;
2003-08-13 05:53:07 +04:00
2007-12-03 02:28:22 +03:00
share = torture_setting_string ( tctx , " share " , NULL ) ;
host = torture_setting_string ( tctx , " host " , NULL ) ;
2004-09-26 15:30:20 +04:00
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " create a second tree context on the same session \n " ) ;
2007-12-03 02:28:22 +03:00
tree = smbcli_tree_init ( cli - > session , tctx , false ) ;
2003-08-13 05:53:07 +04:00
tcon . generic . level = RAW_TCON_TCONX ;
2012-08-02 10:48:11 +04:00
tcon . tconx . in . flags = TCONX_FLAG_EXTENDED_RESPONSE ;
2003-08-13 05:53:07 +04:00
tcon . tconx . in . password = data_blob ( NULL , 0 ) ;
2007-12-03 02:28:22 +03:00
tcon . tconx . in . path = talloc_asprintf ( tctx , " \\ \\ %s \\ %s " , host , share ) ;
2003-08-13 05:53:07 +04:00
tcon . tconx . in . device = " A: " ;
2007-12-03 02:28:22 +03:00
status = smb_raw_tcon ( tree , tctx , & tcon ) ;
2003-08-13 05:53:07 +04:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2005-08-04 08:21:52 +04:00
2003-08-13 05:53:07 +04:00
2005-01-13 21:49:10 +03:00
tree - > tid = tcon . tconx . out . tid ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " tid1=%d tid2=%d \n " , cli - > tree - > tid , tree - > tid ) ;
2003-08-13 05:53:07 +04:00
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " try a tconx with a bad device type \n " ) ;
2003-08-13 05:53:07 +04:00
tcon . tconx . in . device = " FOO " ;
2007-12-03 02:28:22 +03:00
status = smb_raw_tcon ( tree , tctx , & tcon ) ;
2003-08-13 05:53:07 +04:00
CHECK_STATUS ( status , NT_STATUS_BAD_DEVICE_TYPE ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " create a file using the new tid \n " ) ;
2003-08-13 05:53:07 +04:00
io . generic . level = RAW_OPEN_NTCREATEX ;
2009-10-15 11:26:19 +04:00
io . ntcreatex . in . root_fid . fnum = 0 ;
2003-08-13 05:53:07 +04:00
io . ntcreatex . in . flags = 0 ;
2004-12-02 07:37:36 +03:00
io . ntcreatex . in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
2003-08-13 05:53:07 +04:00
io . ntcreatex . in . create_options = 0 ;
io . ntcreatex . in . file_attr = FILE_ATTRIBUTE_NORMAL ;
io . ntcreatex . in . share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE ;
io . ntcreatex . in . alloc_size = 0 ;
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_CREATE ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
io . ntcreatex . in . fname = fname ;
2007-12-03 02:28:22 +03:00
status = smb_raw_open ( tree , tctx , & io ) ;
2003-08-13 05:53:07 +04:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-13 01:48:25 +03:00
fnum = io . ntcreatex . out . file . fnum ;
2003-08-13 05:53:07 +04:00
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " write using the old tid \n " ) ;
2003-08-13 05:53:07 +04:00
wr . generic . level = RAW_WRITE_WRITEX ;
2006-03-13 01:48:25 +03:00
wr . writex . in . file . fnum = fnum ;
2003-08-13 05:53:07 +04:00
wr . writex . in . offset = 0 ;
wr . writex . in . wmode = 0 ;
wr . writex . in . remaining = 0 ;
wr . writex . in . count = 1 ;
wr . writex . in . data = & c ;
status = smb_raw_write ( cli - > tree , & wr ) ;
CHECK_STATUS ( status , NT_STATUS_INVALID_HANDLE ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " write with the new tid \n " ) ;
2003-08-13 05:53:07 +04:00
status = smb_raw_write ( tree , & wr ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( wr . writex . out . nwritten , 1 ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " disconnect the new tid \n " ) ;
2003-08-13 05:53:07 +04:00
status = smb_tree_disconnect ( tree ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " the new tid should not now be accessible \n " ) ;
2003-08-13 05:53:07 +04:00
status = smb_raw_write ( tree , & wr ) ;
CHECK_STATUS ( status , NT_STATUS_INVALID_HANDLE ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " the fnum should have been auto-closed \n " ) ;
2003-08-13 05:53:07 +04:00
cl . close . level = RAW_CLOSE_CLOSE ;
2006-03-13 01:48:25 +03:00
cl . close . in . file . fnum = fnum ;
2003-08-13 05:53:07 +04:00
cl . close . in . write_time = 0 ;
status = smb_raw_close ( cli - > tree , & cl ) ;
CHECK_STATUS ( status , NT_STATUS_INVALID_HANDLE ) ;
/* close down the new tree */
2004-09-26 15:30:20 +04:00
talloc_free ( tree ) ;
2003-08-13 05:53:07 +04:00
done :
return ret ;
}
2006-03-26 01:33:49 +03:00
/*
test tree with ulogoff
this demonstrates that a tcon isn ' t autoclosed by a ulogoff
the tcon can be reused using any other valid session later
*/
2012-05-03 16:41:21 +04:00
static bool test_tree_ulogoff ( struct torture_context * tctx , struct smbcli_state * cli )
2006-03-26 01:33:49 +03:00
{
NTSTATUS status ;
2007-10-07 02:28:14 +04:00
bool ret = true ;
2006-03-26 01:33:49 +03:00
const char * share , * host ;
struct smbcli_session * session1 ;
struct smbcli_session * session2 ;
struct smb_composite_sesssetup setup ;
struct smbcli_tree * tree ;
union smb_tcon tcon ;
union smb_open io ;
union smb_write wr ;
int fnum1 , fnum2 ;
const char * fname1 = BASEDIR " \\ test1.txt " ;
const char * fname2 = BASEDIR " \\ test2.txt " ;
uint8_t c = 1 ;
2008-09-30 03:29:53 +04:00
struct smbcli_session_options options ;
2006-03-26 01:33:49 +03:00
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " TESTING TREE with ulogoff \n " ) ;
2006-03-26 01:33:49 +03:00
2012-05-18 09:43:31 +04:00
torture_assert ( tctx , torture_setup_dir ( cli , BASEDIR ) , " Failed to setup up test directory: " BASEDIR ) ;
2006-03-26 01:33:49 +03:00
2007-12-03 02:28:22 +03:00
share = torture_setting_string ( tctx , " share " , NULL ) ;
host = torture_setting_string ( tctx , " host " , NULL ) ;
2006-03-26 01:33:49 +03:00
2010-07-16 08:32:42 +04:00
lpcfg_smbcli_session_options ( tctx - > lp_ctx , & options ) ;
2008-09-30 03:29:53 +04:00
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " create the first new sessions \n " ) ;
2008-09-30 03:29:53 +04:00
session1 = smbcli_session_init ( cli - > transport , tctx , false , options ) ;
2006-03-26 01:33:49 +03:00
setup . in . sesskey = cli - > transport - > negotiate . sesskey ;
setup . in . capabilities = cli - > transport - > negotiate . capabilities ;
2010-07-16 08:32:42 +04:00
setup . in . workgroup = lpcfg_workgroup ( tctx - > lp_ctx ) ;
2017-05-10 02:10:03 +03:00
setup . in . credentials = popt_get_cmdline_credentials ( ) ;
2010-07-16 08:32:42 +04:00
setup . in . gensec_settings = lpcfg_gensec_settings ( tctx , tctx - > lp_ctx ) ;
2006-03-26 01:33:49 +03:00
status = smb_composite_sesssetup ( session1 , & setup ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
session1 - > vuid = setup . out . vuid ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " vuid1=%d \n " , session1 - > vuid ) ;
2006-03-26 01:33:49 +03:00
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " create a tree context on the with vuid1 \n " ) ;
2007-12-03 02:28:22 +03:00
tree = smbcli_tree_init ( session1 , tctx , false ) ;
2006-03-26 01:33:49 +03:00
tcon . generic . level = RAW_TCON_TCONX ;
2012-08-02 10:48:11 +04:00
tcon . tconx . in . flags = TCONX_FLAG_EXTENDED_RESPONSE ;
2006-03-26 01:33:49 +03:00
tcon . tconx . in . password = data_blob ( NULL , 0 ) ;
2007-12-03 02:28:22 +03:00
tcon . tconx . in . path = talloc_asprintf ( tctx , " \\ \\ %s \\ %s " , host , share ) ;
2006-03-26 01:33:49 +03:00
tcon . tconx . in . device = " A: " ;
2007-12-03 02:28:22 +03:00
status = smb_raw_tcon ( tree , tctx , & tcon ) ;
2006-03-26 01:33:49 +03:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
tree - > tid = tcon . tconx . out . tid ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " tid=%d \n " , tree - > tid ) ;
2006-03-26 01:33:49 +03:00
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " create a file using vuid1 \n " ) ;
2006-03-26 01:33:49 +03:00
io . generic . level = RAW_OPEN_NTCREATEX ;
2009-10-15 11:26:19 +04:00
io . ntcreatex . in . root_fid . fnum = 0 ;
2006-03-26 01:33:49 +03:00
io . ntcreatex . in . flags = 0 ;
io . ntcreatex . in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
io . ntcreatex . in . create_options = 0 ;
io . ntcreatex . in . file_attr = FILE_ATTRIBUTE_NORMAL ;
io . ntcreatex . in . share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE ;
io . ntcreatex . in . alloc_size = 0 ;
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_CREATE ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
io . ntcreatex . in . fname = fname1 ;
2007-12-03 02:28:22 +03:00
status = smb_raw_open ( tree , tctx , & io ) ;
2006-03-26 01:33:49 +03:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
fnum1 = io . ntcreatex . out . file . fnum ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " write using vuid1 \n " ) ;
2006-03-26 01:33:49 +03:00
wr . generic . level = RAW_WRITE_WRITEX ;
wr . writex . in . file . fnum = fnum1 ;
wr . writex . in . offset = 0 ;
wr . writex . in . wmode = 0 ;
wr . writex . in . remaining = 0 ;
wr . writex . in . count = 1 ;
wr . writex . in . data = & c ;
status = smb_raw_write ( tree , & wr ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( wr . writex . out . nwritten , 1 ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " ulogoff the vuid1 \n " ) ;
2006-03-26 01:33:49 +03:00
status = smb_raw_ulogoff ( session1 ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " create the second new sessions \n " ) ;
2008-09-30 03:29:53 +04:00
session2 = smbcli_session_init ( cli - > transport , tctx , false , options ) ;
2006-03-26 01:33:49 +03:00
setup . in . sesskey = cli - > transport - > negotiate . sesskey ;
setup . in . capabilities = cli - > transport - > negotiate . capabilities ;
2010-07-16 08:32:42 +04:00
setup . in . workgroup = lpcfg_workgroup ( tctx - > lp_ctx ) ;
2017-05-10 02:10:03 +03:00
setup . in . credentials = popt_get_cmdline_credentials ( ) ;
2010-07-16 08:32:42 +04:00
setup . in . gensec_settings = lpcfg_gensec_settings ( tctx , tctx - > lp_ctx ) ;
2006-03-26 01:33:49 +03:00
status = smb_composite_sesssetup ( session2 , & setup ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
session2 - > vuid = setup . out . vuid ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " vuid2=%d \n " , session2 - > vuid ) ;
2006-03-26 01:33:49 +03:00
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " use the existing tree with vuid2 \n " ) ;
2006-03-26 01:33:49 +03:00
tree - > session = session2 ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " create a file using vuid2 \n " ) ;
2006-03-26 01:33:49 +03:00
io . generic . level = RAW_OPEN_NTCREATEX ;
2009-10-15 11:26:19 +04:00
io . ntcreatex . in . root_fid . fnum = 0 ;
2006-03-26 01:33:49 +03:00
io . ntcreatex . in . flags = 0 ;
io . ntcreatex . in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
io . ntcreatex . in . create_options = 0 ;
io . ntcreatex . in . file_attr = FILE_ATTRIBUTE_NORMAL ;
io . ntcreatex . in . share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE ;
io . ntcreatex . in . alloc_size = 0 ;
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_CREATE ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
io . ntcreatex . in . fname = fname2 ;
2007-12-03 02:28:22 +03:00
status = smb_raw_open ( tree , tctx , & io ) ;
2006-03-26 01:33:49 +03:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
fnum2 = io . ntcreatex . out . file . fnum ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " write using vuid2 \n " ) ;
2006-03-26 01:33:49 +03:00
wr . generic . level = RAW_WRITE_WRITEX ;
wr . writex . in . file . fnum = fnum2 ;
wr . writex . in . offset = 0 ;
wr . writex . in . wmode = 0 ;
wr . writex . in . remaining = 0 ;
wr . writex . in . count = 1 ;
wr . writex . in . data = & c ;
status = smb_raw_write ( tree , & wr ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( wr . writex . out . nwritten , 1 ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " ulogoff the vuid2 \n " ) ;
2006-03-26 01:33:49 +03:00
status = smb_raw_ulogoff ( session2 ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
/* this also demonstrates that SMBtdis doesn't need a valid vuid */
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " disconnect the existing tree connection \n " ) ;
2006-03-26 01:33:49 +03:00
status = smb_tree_disconnect ( tree ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " disconnect the existing tree connection \n " ) ;
2006-03-26 01:33:49 +03:00
status = smb_tree_disconnect ( tree ) ;
CHECK_STATUS ( status , NT_STATUS_DOS ( ERRSRV , ERRinvnid ) ) ;
/* close down the new tree */
talloc_free ( tree ) ;
done :
return ret ;
}
2003-08-13 05:53:07 +04:00
/*
test pid ops
2006-03-25 13:16:27 +03:00
this test demonstrates that exit ( ) only sees the PID
used for the open ( ) calls
2003-08-13 05:53:07 +04:00
*/
2012-05-03 16:41:21 +04:00
static bool test_pid_exit_only_sees_open ( struct torture_context * tctx ,
struct smbcli_state * cli )
2003-08-13 05:53:07 +04:00
{
NTSTATUS status ;
2012-05-01 14:35:28 +04:00
TALLOC_CTX * mem_ctx = tctx ;
2007-10-07 02:28:14 +04:00
bool ret = true ;
2003-08-13 05:53:07 +04:00
union smb_open io ;
union smb_write wr ;
union smb_close cl ;
int fnum ;
const char * fname = BASEDIR " \\ test.txt " ;
2004-12-04 16:56:25 +03:00
uint8_t c = 1 ;
2004-05-25 21:24:24 +04:00
uint16_t pid1 , pid2 ;
2003-08-13 05:53:07 +04:00
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " TESTING PID HANDLING exit() only cares about open() PID \n " ) ;
2003-08-13 05:53:07 +04:00
2012-05-18 09:43:31 +04:00
torture_assert ( tctx , torture_setup_dir ( cli , BASEDIR ) , " Failed to setup up test directory: " BASEDIR ) ;
2003-08-13 05:53:07 +04:00
2006-03-30 19:47:41 +04:00
pid1 = cli - > session - > pid ;
pid2 = pid1 + 1 ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " pid1=%d pid2=%d \n " , pid1 , pid2 ) ;
2003-08-13 05:53:07 +04:00
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " create a file using pid1 \n " ) ;
2006-03-25 13:16:27 +03:00
cli - > session - > pid = pid1 ;
2003-08-13 05:53:07 +04:00
io . generic . level = RAW_OPEN_NTCREATEX ;
2009-10-15 11:26:19 +04:00
io . ntcreatex . in . root_fid . fnum = 0 ;
2003-08-13 05:53:07 +04:00
io . ntcreatex . in . flags = 0 ;
2004-12-02 07:37:36 +03:00
io . ntcreatex . in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
2003-08-13 05:53:07 +04:00
io . ntcreatex . in . create_options = 0 ;
io . ntcreatex . in . file_attr = FILE_ATTRIBUTE_NORMAL ;
io . ntcreatex . in . share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE ;
io . ntcreatex . in . alloc_size = 0 ;
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_CREATE ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
io . ntcreatex . in . fname = fname ;
status = smb_raw_open ( cli - > tree , mem_ctx , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-13 01:48:25 +03:00
fnum = io . ntcreatex . out . file . fnum ;
2003-08-13 05:53:07 +04:00
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " write using pid2 \n " ) ;
2006-03-26 01:20:48 +03:00
cli - > session - > pid = pid2 ;
2003-08-13 05:53:07 +04:00
wr . generic . level = RAW_WRITE_WRITEX ;
2006-03-13 01:48:25 +03:00
wr . writex . in . file . fnum = fnum ;
2003-08-13 05:53:07 +04:00
wr . writex . in . offset = 0 ;
wr . writex . in . wmode = 0 ;
wr . writex . in . remaining = 0 ;
wr . writex . in . count = 1 ;
wr . writex . in . data = & c ;
status = smb_raw_write ( cli - > tree , & wr ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( wr . writex . out . nwritten , 1 ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " exit pid2 \n " ) ;
2006-03-25 13:16:27 +03:00
cli - > session - > pid = pid2 ;
status = smb_raw_exit ( cli - > session ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " the fnum should still be accessible via pid2 \n " ) ;
2003-08-13 05:53:07 +04:00
cli - > session - > pid = pid2 ;
status = smb_raw_write ( cli - > tree , & wr ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( wr . writex . out . nwritten , 1 ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " exit pid2 \n " ) ;
2006-03-25 13:16:27 +03:00
cli - > session - > pid = pid2 ;
2003-08-13 05:53:07 +04:00
status = smb_raw_exit ( cli - > session ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " the fnum should still be accessible via pid1 and pid2 \n " ) ;
2003-08-13 05:53:07 +04:00
cli - > session - > pid = pid1 ;
status = smb_raw_write ( cli - > tree , & wr ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( wr . writex . out . nwritten , 1 ) ;
cli - > session - > pid = pid2 ;
2006-03-25 13:16:27 +03:00
status = smb_raw_write ( cli - > tree , & wr ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( wr . writex . out . nwritten , 1 ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " exit pid1 \n " ) ;
2006-03-25 13:16:27 +03:00
cli - > session - > pid = pid1 ;
2003-08-13 05:53:07 +04:00
status = smb_raw_exit ( cli - > session ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " the fnum should not now be accessible via pid1 or pid2 \n " ) ;
2003-08-13 05:53:07 +04:00
cli - > session - > pid = pid1 ;
status = smb_raw_write ( cli - > tree , & wr ) ;
CHECK_STATUS ( status , NT_STATUS_INVALID_HANDLE ) ;
2006-03-25 13:16:27 +03:00
cli - > session - > pid = pid2 ;
status = smb_raw_write ( cli - > tree , & wr ) ;
CHECK_STATUS ( status , NT_STATUS_INVALID_HANDLE ) ;
2003-08-13 05:53:07 +04:00
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " the fnum should have been auto-closed \n " ) ;
2006-03-25 13:16:27 +03:00
cli - > session - > pid = pid1 ;
2003-08-13 05:53:07 +04:00
cl . close . level = RAW_CLOSE_CLOSE ;
2006-03-13 01:48:25 +03:00
cl . close . in . file . fnum = fnum ;
2003-08-13 05:53:07 +04:00
cl . close . in . write_time = 0 ;
status = smb_raw_close ( cli - > tree , & cl ) ;
CHECK_STATUS ( status , NT_STATUS_INVALID_HANDLE ) ;
done :
return ret ;
}
2006-03-15 14:27:40 +03:00
/*
test pid ops with 2 sessions
*/
2012-05-03 16:41:21 +04:00
static bool test_pid_2sess ( struct torture_context * tctx ,
struct smbcli_state * cli )
2006-03-15 14:27:40 +03:00
{
NTSTATUS status ;
2007-10-07 02:28:14 +04:00
bool ret = true ;
2006-03-15 14:27:40 +03:00
struct smbcli_session * session ;
struct smb_composite_sesssetup setup ;
union smb_open io ;
union smb_write wr ;
union smb_close cl ;
int fnum ;
const char * fname = BASEDIR " \\ test.txt " ;
uint8_t c = 1 ;
uint16_t vuid1 , vuid2 ;
2008-09-30 03:29:53 +04:00
struct smbcli_session_options options ;
2006-03-15 14:27:40 +03:00
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " TESTING PID HANDLING WITH 2 SESSIONS \n " ) ;
2006-03-15 14:27:40 +03:00
2012-05-18 09:43:31 +04:00
torture_assert ( tctx , torture_setup_dir ( cli , BASEDIR ) , " Failed to setup up test directory: " BASEDIR ) ;
2006-03-15 14:27:40 +03:00
2010-07-16 08:32:42 +04:00
lpcfg_smbcli_session_options ( tctx - > lp_ctx , & options ) ;
2008-09-30 03:29:53 +04:00
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " create a second security context on the same transport \n " ) ;
2008-09-30 03:29:53 +04:00
session = smbcli_session_init ( cli - > transport , tctx , false , options ) ;
2006-03-15 14:27:40 +03:00
setup . in . sesskey = cli - > transport - > negotiate . sesskey ;
setup . in . capabilities = cli - > transport - > negotiate . capabilities ; /* ignored in secondary session setup, except by our libs, which care about the extended security bit */
2010-07-16 08:32:42 +04:00
setup . in . workgroup = lpcfg_workgroup ( tctx - > lp_ctx ) ;
2017-05-10 02:10:03 +03:00
setup . in . credentials = popt_get_cmdline_credentials ( ) ;
2010-07-16 08:32:42 +04:00
setup . in . gensec_settings = lpcfg_gensec_settings ( tctx , tctx - > lp_ctx ) ;
2006-03-15 14:27:40 +03:00
status = smb_composite_sesssetup ( session , & setup ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
session - > vuid = setup . out . vuid ;
vuid1 = cli - > session - > vuid ;
vuid2 = session - > vuid ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " vuid1=%d vuid2=%d \n " , vuid1 , vuid2 ) ;
2006-03-15 14:27:40 +03:00
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " create a file using the vuid1 \n " ) ;
2006-03-15 14:27:40 +03:00
cli - > session - > vuid = vuid1 ;
io . generic . level = RAW_OPEN_NTCREATEX ;
2009-10-15 11:26:19 +04:00
io . ntcreatex . in . root_fid . fnum = 0 ;
2006-03-15 14:27:40 +03:00
io . ntcreatex . in . flags = 0 ;
io . ntcreatex . in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
io . ntcreatex . in . create_options = 0 ;
io . ntcreatex . in . file_attr = FILE_ATTRIBUTE_NORMAL ;
io . ntcreatex . in . share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE ;
io . ntcreatex . in . alloc_size = 0 ;
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_CREATE ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
io . ntcreatex . in . fname = fname ;
2007-12-03 02:28:22 +03:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2006-03-15 14:27:40 +03:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
fnum = io . ntcreatex . out . file . fnum ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " write using the vuid1 (fnum=%d) \n " , fnum ) ;
2006-03-15 14:27:40 +03:00
cli - > session - > vuid = vuid1 ;
wr . generic . level = RAW_WRITE_WRITEX ;
wr . writex . in . file . fnum = fnum ;
wr . writex . in . offset = 0 ;
wr . writex . in . wmode = 0 ;
wr . writex . in . remaining = 0 ;
wr . writex . in . count = 1 ;
wr . writex . in . data = & c ;
status = smb_raw_write ( cli - > tree , & wr ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( wr . writex . out . nwritten , 1 ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " exit the pid with vuid2 \n " ) ;
2006-03-15 14:27:40 +03:00
cli - > session - > vuid = vuid2 ;
status = smb_raw_exit ( cli - > session ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " the fnum should still be accessible \n " ) ;
2006-03-15 14:27:40 +03:00
cli - > session - > vuid = vuid1 ;
status = smb_raw_write ( cli - > tree , & wr ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( wr . writex . out . nwritten , 1 ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " exit the pid with vuid1 \n " ) ;
2006-03-15 14:27:40 +03:00
cli - > session - > vuid = vuid1 ;
status = smb_raw_exit ( cli - > session ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " the fnum should not now be accessible \n " ) ;
2006-03-15 14:27:40 +03:00
status = smb_raw_write ( cli - > tree , & wr ) ;
CHECK_STATUS ( status , NT_STATUS_INVALID_HANDLE ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " the fnum should have been auto-closed \n " ) ;
2006-03-15 14:27:40 +03:00
cl . close . level = RAW_CLOSE_CLOSE ;
cl . close . in . file . fnum = fnum ;
cl . close . in . write_time = 0 ;
status = smb_raw_close ( cli - > tree , & cl ) ;
CHECK_STATUS ( status , NT_STATUS_INVALID_HANDLE ) ;
done :
return ret ;
}
/*
test pid ops with 2 tcons
*/
2012-05-03 16:41:21 +04:00
static bool test_pid_2tcon ( struct torture_context * tctx ,
struct smbcli_state * cli )
2006-03-15 14:27:40 +03:00
{
NTSTATUS status ;
2007-10-07 02:28:14 +04:00
bool ret = true ;
2006-03-15 14:27:40 +03:00
const char * share , * host ;
struct smbcli_tree * tree ;
union smb_tcon tcon ;
union smb_open io ;
union smb_write wr ;
union smb_close cl ;
int fnum1 , fnum2 ;
const char * fname1 = BASEDIR " \\ test1.txt " ;
const char * fname2 = BASEDIR " \\ test2.txt " ;
uint8_t c = 1 ;
uint16_t tid1 , tid2 ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " TESTING PID HANDLING WITH 2 TCONS \n " ) ;
2006-03-15 14:27:40 +03:00
2012-05-18 09:43:31 +04:00
torture_assert ( tctx , torture_setup_dir ( cli , BASEDIR ) , " Failed to setup up test directory: " BASEDIR ) ;
2006-03-15 14:27:40 +03:00
2007-12-03 02:28:22 +03:00
share = torture_setting_string ( tctx , " share " , NULL ) ;
host = torture_setting_string ( tctx , " host " , NULL ) ;
2006-03-15 14:27:40 +03:00
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " create a second tree context on the same session \n " ) ;
2007-12-03 02:28:22 +03:00
tree = smbcli_tree_init ( cli - > session , tctx , false ) ;
2006-03-15 14:27:40 +03:00
tcon . generic . level = RAW_TCON_TCONX ;
2012-08-02 10:48:11 +04:00
tcon . tconx . in . flags = TCONX_FLAG_EXTENDED_RESPONSE ;
2006-03-15 14:27:40 +03:00
tcon . tconx . in . password = data_blob ( NULL , 0 ) ;
2007-12-03 02:28:22 +03:00
tcon . tconx . in . path = talloc_asprintf ( tctx , " \\ \\ %s \\ %s " , host , share ) ;
2006-03-15 14:27:40 +03:00
tcon . tconx . in . device = " A: " ;
2007-12-03 02:28:22 +03:00
status = smb_raw_tcon ( tree , tctx , & tcon ) ;
2006-03-15 14:27:40 +03:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
tree - > tid = tcon . tconx . out . tid ;
tid1 = cli - > tree - > tid ;
tid2 = tree - > tid ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " tid1=%d tid2=%d \n " , tid1 , tid2 ) ;
2006-03-15 14:27:40 +03:00
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " create a file using the tid1 \n " ) ;
2006-03-15 14:27:40 +03:00
cli - > tree - > tid = tid1 ;
io . generic . level = RAW_OPEN_NTCREATEX ;
2009-10-15 11:26:19 +04:00
io . ntcreatex . in . root_fid . fnum = 0 ;
2006-03-15 14:27:40 +03:00
io . ntcreatex . in . flags = 0 ;
io . ntcreatex . in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
io . ntcreatex . in . create_options = 0 ;
io . ntcreatex . in . file_attr = FILE_ATTRIBUTE_NORMAL ;
io . ntcreatex . in . share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE ;
io . ntcreatex . in . alloc_size = 0 ;
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_CREATE ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
io . ntcreatex . in . fname = fname1 ;
2007-12-03 02:28:22 +03:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2006-03-15 14:27:40 +03:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
fnum1 = io . ntcreatex . out . file . fnum ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " write using the tid1 \n " ) ;
2006-03-15 14:27:40 +03:00
wr . generic . level = RAW_WRITE_WRITEX ;
wr . writex . in . file . fnum = fnum1 ;
wr . writex . in . offset = 0 ;
wr . writex . in . wmode = 0 ;
wr . writex . in . remaining = 0 ;
wr . writex . in . count = 1 ;
wr . writex . in . data = & c ;
status = smb_raw_write ( cli - > tree , & wr ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( wr . writex . out . nwritten , 1 ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " create a file using the tid2 \n " ) ;
2006-03-15 14:27:40 +03:00
cli - > tree - > tid = tid2 ;
io . generic . level = RAW_OPEN_NTCREATEX ;
2009-10-15 11:26:19 +04:00
io . ntcreatex . in . root_fid . fnum = 0 ;
2006-03-15 14:27:40 +03:00
io . ntcreatex . in . flags = 0 ;
io . ntcreatex . in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
io . ntcreatex . in . create_options = 0 ;
io . ntcreatex . in . file_attr = FILE_ATTRIBUTE_NORMAL ;
io . ntcreatex . in . share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE ;
io . ntcreatex . in . alloc_size = 0 ;
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_CREATE ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
io . ntcreatex . in . fname = fname2 ;
2007-12-03 02:28:22 +03:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2006-03-15 14:27:40 +03:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
fnum2 = io . ntcreatex . out . file . fnum ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " write using the tid2 \n " ) ;
2006-03-15 14:27:40 +03:00
wr . generic . level = RAW_WRITE_WRITEX ;
wr . writex . in . file . fnum = fnum2 ;
wr . writex . in . offset = 0 ;
wr . writex . in . wmode = 0 ;
wr . writex . in . remaining = 0 ;
wr . writex . in . count = 1 ;
wr . writex . in . data = & c ;
status = smb_raw_write ( cli - > tree , & wr ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( wr . writex . out . nwritten , 1 ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " exit the pid \n " ) ;
2006-03-15 14:27:40 +03:00
status = smb_raw_exit ( cli - > session ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " the fnum1 on tid1 should not be accessible \n " ) ;
2006-03-15 14:27:40 +03:00
cli - > tree - > tid = tid1 ;
wr . writex . in . file . fnum = fnum1 ;
status = smb_raw_write ( cli - > tree , & wr ) ;
CHECK_STATUS ( status , NT_STATUS_INVALID_HANDLE ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " the fnum1 on tid1 should have been auto-closed \n " ) ;
2006-03-15 14:27:40 +03:00
cl . close . level = RAW_CLOSE_CLOSE ;
cl . close . in . file . fnum = fnum1 ;
cl . close . in . write_time = 0 ;
status = smb_raw_close ( cli - > tree , & cl ) ;
CHECK_STATUS ( status , NT_STATUS_INVALID_HANDLE ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " the fnum2 on tid2 should not be accessible \n " ) ;
2006-03-15 14:27:40 +03:00
cli - > tree - > tid = tid2 ;
wr . writex . in . file . fnum = fnum2 ;
status = smb_raw_write ( cli - > tree , & wr ) ;
CHECK_STATUS ( status , NT_STATUS_INVALID_HANDLE ) ;
2012-05-01 14:39:21 +04:00
torture_comment ( tctx , " the fnum2 on tid2 should have been auto-closed \n " ) ;
2006-03-15 14:27:40 +03:00
cl . close . level = RAW_CLOSE_CLOSE ;
cl . close . in . file . fnum = fnum2 ;
cl . close . in . write_time = 0 ;
status = smb_raw_close ( cli - > tree , & cl ) ;
CHECK_STATUS ( status , NT_STATUS_INVALID_HANDLE ) ;
done :
return ret ;
}
2012-05-02 15:46:34 +04:00
struct torture_suite * torture_raw_context ( TALLOC_CTX * mem_ctx )
{
struct torture_suite * suite = torture_suite_create ( mem_ctx , " context " ) ;
2012-05-03 16:41:21 +04:00
torture_suite_add_1smb_test ( suite , " session1 " , test_session ) ;
/*
* TODO : add test_session with ' use spnego = false '
* torture_suite_add_1smb_test ( suite , " session1 " , test_session ) ;
*/
torture_suite_add_1smb_test ( suite , " tree " , test_tree ) ;
torture_suite_add_1smb_test ( suite , " tree_ulogoff " , test_tree_ulogoff ) ;
torture_suite_add_1smb_test ( suite , " pid_only_sess " , test_pid_exit_only_sees_open ) ;
torture_suite_add_1smb_test ( suite , " pid_2sess " , test_pid_2sess ) ;
torture_suite_add_1smb_test ( suite , " pid_2tcon " , test_pid_2tcon ) ;
2012-05-02 15:46:34 +04:00
return suite ;
}