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
the Free Software Foundation ; either version 2 of the License , or
( 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
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "includes.h"
2004-11-01 04:03:22 +03:00
# include "libcli/raw/libcliraw.h"
2005-01-16 14:15:08 +03:00
# include "libcli/composite/composite.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"
2005-04-12 11:43:38 +04:00
# include "lib/events/events.h"
2003-08-13 05:53:07 +04:00
# define BASEDIR "\\rawcontext"
# define CHECK_STATUS(status, correct) do { \
if ( ! NT_STATUS_EQUAL ( status , correct ) ) { \
2004-10-25 06:36:12 +04:00
printf ( " (%s) Incorrect status %s - should be %s \n " , \
__location__ , nt_errstr ( status ) , nt_errstr ( correct ) ) ; \
2005-07-04 09:06:16 +04:00
ret = False ; \
2003-08-13 05:53:07 +04:00
goto done ; \
} } while ( 0 )
# define CHECK_VALUE(v, correct) do { \
if ( ( v ) ! = ( correct ) ) { \
2004-10-25 06:36:12 +04:00
printf ( " (%s) Incorrect value %s=%d - should be %d \n " , \
__location__ , # v , v , correct ) ; \
2003-08-13 05:53:07 +04:00
ret = False ; \
goto done ; \
} } while ( 0 )
2004-08-12 11:29:49 +04:00
# define CHECK_NOT_VALUE(v, correct) do { \
if ( ( v ) = = ( correct ) ) { \
2004-10-25 06:36:12 +04:00
printf ( " (%s) Incorrect value %s=%d - should not be %d \n " , \
__location__ , # v , v , correct ) ; \
2004-08-12 11:29:49 +04:00
ret = False ; \
goto done ; \
} } while ( 0 )
2003-08-13 05:53:07 +04:00
/*
test session ops
*/
2004-08-04 17:23:35 +04:00
static BOOL test_session ( struct smbcli_state * cli , TALLOC_CTX * mem_ctx )
2003-08-13 05:53:07 +04:00
{
NTSTATUS status ;
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 ;
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 ] ;
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 ;
2003-08-13 05:53:07 +04:00
printf ( " TESTING SESSION HANDLING \n " ) ;
2004-11-12 12:37:59 +03:00
if ( ! torture_setup_dir ( cli , BASEDIR ) ) {
2003-08-13 05:53:07 +04:00
return False ;
}
printf ( " create a second security context on the same transport \n " ) ;
2005-01-24 03:57:14 +03:00
session = smbcli_session_init ( cli - > transport , mem_ctx , False ) ;
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 */
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
setup . in . workgroup = lp_workgroup ( ) ;
setup . in . credentials = cmdline_credentials ;
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
2004-08-12 11:29:49 +04:00
printf ( " create a third security context on the same transport, with vuid set \n " ) ;
2005-01-24 03:57:14 +03:00
session2 = smbcli_session_init ( cli - > transport , mem_ctx , False ) ;
2004-09-26 15:30:20 +04:00
2004-08-12 11:29:49 +04:00
session2 - > vuid = session - > vuid ;
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 */
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
setup . in . workgroup = lp_workgroup ( ) ;
2005-03-22 00:22:07 +03:00
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
setup . in . credentials = cmdline_credentials ;
2005-01-16 14:15:08 +03:00
status = smb_composite_sesssetup ( session2 , & setup ) ;
2004-08-12 11:29:49 +04:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2005-01-16 14:15:08 +03:00
session2 - > vuid = setup . out . vuid ;
2004-08-12 11:29:49 +04:00
printf ( " vuid1=%d vuid2=%d vuid3=%d \n " , cli - > session - > vuid , session - > vuid , session2 - > vuid ) ;
2005-04-12 11:43:38 +04:00
if ( cli - > transport - > negotiate . capabilities & CAP_EXTENDED_SECURITY ) {
/* Samba4 currently fails this - we need to determine if this insane behaviour is important */
2005-04-12 11:56:56 +04:00
if ( session2 - > vuid = = session - > vuid ) {
printf ( " server allows the user to re-use an existing vuid in session setup \n " ) ;
}
2005-04-12 11:43:38 +04:00
} else {
CHECK_NOT_VALUE ( session2 - > vuid , session - > vuid ) ;
}
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 ) {
printf ( " create a fourth security context on the same transport, without extended security \n " ) ;
2005-01-24 03:57:14 +03:00
session3 = smbcli_session_init ( cli - > transport , mem_ctx , False ) ;
2004-09-26 15:30:20 +04:00
2004-08-12 11:29:49 +04:00
session3 - > vuid = session - > vuid ;
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) */
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
setup . in . workgroup = lp_workgroup ( ) ;
setup . in . credentials = cmdline_credentials ;
2005-01-16 14:15:08 +03:00
status = smb_composite_sesssetup ( session3 , & setup ) ;
2005-07-04 09:05:28 +04:00
CHECK_STATUS ( status , NT_STATUS_LOGON_FAILURE ) ;
2004-09-26 15:30:20 +04:00
2005-06-17 10:30:03 +04:00
printf ( " create a fouth anonymous security context on the same transport, without extended security \n " ) ;
session4 = smbcli_session_init ( cli - > transport , mem_ctx , False ) ;
session4 - > vuid = session - > vuid ;
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) */
2005-06-17 10:30:03 +04:00
setup . in . workgroup = lp_workgroup ( ) ;
anon_creds = cli_credentials_init ( mem_ctx ) ;
cli_credentials_set_conf ( anon_creds ) ;
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
}
2003-08-13 05:53:07 +04:00
printf ( " use the same tree as the existing connection \n " ) ;
2005-01-24 03:57:14 +03:00
tree = smbcli_tree_init ( session , mem_ctx , False ) ;
2003-08-13 05:53:07 +04:00
tree - > tid = cli - > tree - > tid ;
printf ( " create a file using the new vuid \n " ) ;
io . generic . level = RAW_OPEN_NTCREATEX ;
io . ntcreatex . in . root_fid = 0 ;
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 ( tree , mem_ctx , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
fnum = io . ntcreatex . out . fnum ;
printf ( " write using the old vuid \n " ) ;
wr . generic . level = RAW_WRITE_WRITEX ;
wr . writex . in . 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_INVALID_HANDLE ) ;
printf ( " write with the new vuid \n " ) ;
status = smb_raw_write ( tree , & wr ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( wr . writex . out . nwritten , 1 ) ;
printf ( " logoff the new vuid \n " ) ;
status = smb_raw_ulogoff ( session ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
printf ( " the new vuid should not now be accessible \n " ) ;
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
2005-04-12 11:43:38 +04:00
printf ( " second logoff for the new vuid should fail \n " ) ;
status = smb_raw_ulogoff ( session ) ;
2005-07-04 05:23:38 +04:00
CHECK_STATUS ( status , NT_STATUS_DOS ( ERRSRV , ERRbaduid ) ) ;
2005-04-12 11:43:38 +04:00
talloc_free ( session ) ;
2003-08-13 05:53:07 +04:00
printf ( " the fnum should have been auto-closed \n " ) ;
cl . close . level = RAW_CLOSE_CLOSE ;
cl . close . in . fnum = fnum ;
cl . close . in . write_time = 0 ;
status = smb_raw_close ( cli - > tree , & cl ) ;
CHECK_STATUS ( status , NT_STATUS_INVALID_HANDLE ) ;
2005-04-12 11:43:38 +04:00
printf ( " 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 */
setups [ i ] . in . workgroup = lp_workgroup ( ) ;
setups [ i ] . in . credentials = cmdline_credentials ;
sessions [ i ] = smbcli_session_init ( cli - > transport , mem_ctx , False ) ;
composite_contexts [ i ] = smb_composite_sesssetup_send ( sessions [ i ] , & setups [ i ] ) ;
}
/* flush the queue */
for ( i = 0 ; i < ARRAY_SIZE ( sessions ) ; i + + ) {
event_loop_once ( composite_contexts [ 0 ] - > event_ctx ) ;
}
printf ( " 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 ;
printf ( " VUID: %d \n " , sessions [ i ] - > vuid ) ;
status = smb_raw_ulogoff ( sessions [ i ] ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
}
2004-09-26 15:30:20 +04:00
talloc_free ( tree ) ;
2003-08-13 05:53:07 +04:00
done :
return ret ;
}
/*
test tree ops
*/
2004-08-04 17:23:35 +04:00
static BOOL test_tree ( struct smbcli_state * cli , TALLOC_CTX * mem_ctx )
2003-08-13 05:53:07 +04:00
{
NTSTATUS status ;
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
printf ( " TESTING TREE HANDLING \n " ) ;
2004-11-12 12:37:59 +03:00
if ( ! torture_setup_dir ( cli , BASEDIR ) ) {
2003-08-13 05:53:07 +04:00
return False ;
}
share = lp_parm_string ( - 1 , " torture " , " share " ) ;
2005-08-04 08:21:52 +04:00
host = lp_parm_string ( - 1 , " torture " , " host " ) ;
2004-09-26 15:30:20 +04:00
2003-08-13 05:53:07 +04:00
printf ( " create a second tree context on the same session \n " ) ;
2005-01-24 03:57:14 +03:00
tree = smbcli_tree_init ( cli - > session , mem_ctx , False ) ;
2003-08-13 05:53:07 +04:00
tcon . generic . level = RAW_TCON_TCONX ;
tcon . tconx . in . flags = 0 ;
tcon . tconx . in . password = data_blob ( NULL , 0 ) ;
2005-08-04 08:21:52 +04:00
tcon . tconx . in . path = talloc_asprintf ( mem_ctx , " \\ \\ %s \\ %s " , host , share ) ;
2003-08-13 05:53:07 +04:00
tcon . tconx . in . device = " A: " ;
2005-08-09 07:09:47 +04:00
status = smb_raw_tcon ( tree , mem_ctx , & 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 ;
2003-08-13 05:53:07 +04:00
printf ( " tid1=%d tid2=%d \n " , cli - > tree - > tid , tree - > tid ) ;
printf ( " try a tconx with a bad device type \n " ) ;
tcon . tconx . in . device = " FOO " ;
2005-08-09 07:09:47 +04:00
status = smb_raw_tcon ( tree , mem_ctx , & tcon ) ;
2003-08-13 05:53:07 +04:00
CHECK_STATUS ( status , NT_STATUS_BAD_DEVICE_TYPE ) ;
printf ( " create a file using the new tid \n " ) ;
io . generic . level = RAW_OPEN_NTCREATEX ;
io . ntcreatex . in . root_fid = 0 ;
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 ( tree , mem_ctx , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
fnum = io . ntcreatex . out . fnum ;
printf ( " write using the old tid \n " ) ;
wr . generic . level = RAW_WRITE_WRITEX ;
wr . writex . in . 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_INVALID_HANDLE ) ;
printf ( " write with the new tid \n " ) ;
status = smb_raw_write ( tree , & wr ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( wr . writex . out . nwritten , 1 ) ;
printf ( " disconnect the new tid \n " ) ;
status = smb_tree_disconnect ( tree ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
printf ( " the new tid should not now be accessible \n " ) ;
status = smb_raw_write ( tree , & wr ) ;
CHECK_STATUS ( status , NT_STATUS_INVALID_HANDLE ) ;
printf ( " the fnum should have been auto-closed \n " ) ;
cl . close . level = RAW_CLOSE_CLOSE ;
cl . close . in . fnum = fnum ;
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 ;
}
/*
test pid ops
*/
2004-08-04 17:23:35 +04:00
static BOOL test_pid ( struct smbcli_state * cli , TALLOC_CTX * mem_ctx )
2003-08-13 05:53:07 +04:00
{
NTSTATUS status ;
BOOL ret = True ;
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
printf ( " TESTING PID HANDLING \n " ) ;
2004-11-12 12:37:59 +03:00
if ( ! torture_setup_dir ( cli , BASEDIR ) ) {
2003-08-13 05:53:07 +04:00
return False ;
}
printf ( " create a second pid \n " ) ;
pid1 = cli - > session - > pid ;
pid2 = pid1 + 1 ;
printf ( " pid1=%d pid2=%d \n " , pid1 , pid2 ) ;
printf ( " create a file using the new pid \n " ) ;
cli - > session - > pid = pid2 ;
io . generic . level = RAW_OPEN_NTCREATEX ;
io . ntcreatex . in . root_fid = 0 ;
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 ) ;
fnum = io . ntcreatex . out . fnum ;
printf ( " write using the old pid \n " ) ;
cli - > session - > pid = pid1 ;
wr . generic . level = RAW_WRITE_WRITEX ;
wr . writex . in . 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 ) ;
printf ( " write with the new pid \n " ) ;
cli - > session - > pid = pid2 ;
status = smb_raw_write ( cli - > tree , & wr ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( wr . writex . out . nwritten , 1 ) ;
printf ( " exit the old pid \n " ) ;
cli - > session - > pid = pid1 ;
status = smb_raw_exit ( cli - > session ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
printf ( " the fnum should still be accessible \n " ) ;
cli - > session - > pid = pid1 ;
status = smb_raw_write ( cli - > tree , & wr ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( wr . writex . out . nwritten , 1 ) ;
printf ( " exit the new pid \n " ) ;
cli - > session - > pid = pid2 ;
status = smb_raw_exit ( cli - > session ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
printf ( " the fnum should not now be accessible \n " ) ;
cli - > session - > pid = pid1 ;
status = smb_raw_write ( cli - > tree , & wr ) ;
CHECK_STATUS ( status , NT_STATUS_INVALID_HANDLE ) ;
printf ( " the fnum should have been auto-closed \n " ) ;
cl . close . level = RAW_CLOSE_CLOSE ;
cl . close . in . 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 ;
}
/*
basic testing of session / tree context calls
*/
2005-04-12 11:43:38 +04:00
static BOOL torture_raw_context_int ( void )
2003-08-13 05:53:07 +04:00
{
2004-08-04 17:23:35 +04:00
struct smbcli_state * cli ;
2003-08-13 05:53:07 +04:00
BOOL ret = True ;
TALLOC_CTX * mem_ctx ;
if ( ! torture_open_connection ( & cli ) ) {
return False ;
}
mem_ctx = talloc_init ( " torture_raw_context " ) ;
if ( ! test_session ( cli , mem_ctx ) ) {
ret = False ;
}
if ( ! test_tree ( cli , mem_ctx ) ) {
ret = False ;
}
if ( ! test_pid ( cli , mem_ctx ) ) {
ret = False ;
}
smb_raw_exit ( cli - > session ) ;
2004-08-04 17:23:35 +04:00
smbcli_deltree ( cli - > tree , BASEDIR ) ;
2003-08-13 05:53:07 +04:00
torture_close_connection ( cli ) ;
2005-01-27 10:08:20 +03:00
talloc_free ( mem_ctx ) ;
2004-09-26 15:30:20 +04:00
2003-08-13 05:53:07 +04:00
return ret ;
}
2005-04-12 11:43:38 +04:00
/*
basic testing of session / tree context calls
*/
BOOL torture_raw_context ( void )
{
BOOL ret = True ;
if ( lp_use_spnego ( ) ) {
ret & = torture_raw_context_int ( ) ;
lp_set_cmdline ( " use spnego " , " False " ) ;
}
ret & = torture_raw_context_int ( ) ;
return ret ;
}