2011-05-05 20:12:07 +04:00
/*
Unix SMB / CIFS implementation .
Initial test for the smb2 client lib
Copyright ( C ) Volker Lendecke 2011
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 3 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 , see < http : //www.gnu.org/licenses/>.
*/
# include "includes.h"
# include "torture/proto.h"
# include "client.h"
2011-08-30 13:38:26 +04:00
# include "../libcli/smb/smbXcli_base.h"
2011-05-05 20:12:07 +04:00
# include "libsmb/smb2cli.h"
# include "libcli/security/security.h"
2011-09-28 02:58:28 +04:00
# include "libsmb/proto.h"
2011-12-27 06:27:45 +04:00
# include "auth/gensec/gensec.h"
# include "auth_generic.h"
2011-05-05 20:12:07 +04:00
extern fstring host , workgroup , share , password , username , myname ;
bool run_smb2_basic ( int dummy )
{
struct cli_state * cli ;
NTSTATUS status ;
uint64_t fid_persistent , fid_volatile ;
const char * hello = " Hello, world \n " ;
uint8_t * result ;
uint32_t nread ;
uint8_t * dir_data ;
uint32_t dir_data_length ;
2011-11-24 15:33:19 +04:00
uint32_t saved_tid = 0 ;
uint64_t saved_uid = 0 ;
2011-05-05 20:12:07 +04:00
printf ( " Starting SMB2-BASIC \n " ) ;
if ( ! torture_init_connection ( & cli ) ) {
return false ;
}
cli - > smb2 . pid = 0xFEFF ;
2011-08-30 13:38:26 +04:00
status = smbXcli_negprot ( cli - > conn , cli - > timeout ,
PROTOCOL_SMB2_02 , PROTOCOL_SMB2_02 ) ;
2011-05-05 20:12:07 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-08-30 13:38:26 +04:00
printf ( " smbXcli_negprot returned %s \n " , nt_errstr ( status ) ) ;
2011-05-05 20:12:07 +04:00
return false ;
}
2011-09-28 02:58:28 +04:00
status = cli_session_setup ( cli , username ,
password , strlen ( password ) ,
password , strlen ( password ) ,
workgroup ) ;
2011-05-05 20:12:07 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-09-28 02:58:28 +04:00
printf ( " cli_session_setup returned %s \n " , nt_errstr ( status ) ) ;
2011-05-05 20:12:07 +04:00
return false ;
}
2011-11-24 16:03:11 +04:00
status = cli_tree_connect ( cli , share , " ????? " , " " , 0 ) ;
2011-05-05 20:12:07 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-11-24 16:03:11 +04:00
printf ( " cli_tree_connect returned %s \n " , nt_errstr ( status ) ) ;
2011-05-05 20:12:07 +04:00
return false ;
}
2011-11-02 17:38:08 +04:00
status = smb2cli_create ( cli , " smb2-basic.txt " ,
SMB2_OPLOCK_LEVEL_NONE , /* oplock_level, */
SMB2_IMPERSONATION_IMPERSONATION , /* impersonation_level, */
SEC_STD_ALL | SEC_FILE_ALL , /* desired_access, */
FILE_ATTRIBUTE_NORMAL , /* file_attributes, */
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE , /* share_access, */
FILE_CREATE , /* create_disposition, */
FILE_DELETE_ON_CLOSE , /* create_options, */
NULL , /* smb2_create_blobs *blobs */
& fid_persistent ,
& fid_volatile ) ;
2011-05-05 20:12:07 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_create returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_write ( cli , strlen ( hello ) , 0 , fid_persistent ,
fid_volatile , 0 , 0 , ( const uint8_t * ) hello ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_write returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
2011-09-17 21:29:51 +04:00
status = smb2cli_flush ( cli , fid_persistent , fid_volatile ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_flush returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
2011-05-05 20:12:07 +04:00
status = smb2cli_read ( cli , 0x10000 , 0 , fid_persistent ,
fid_volatile , 2 , 0 ,
talloc_tos ( ) , & result , & nread ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_read returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
if ( nread ! = strlen ( hello ) ) {
printf ( " smb2cli_read returned %d bytes, expected %d \n " ,
( int ) nread , ( int ) strlen ( hello ) ) ;
return false ;
}
if ( memcmp ( hello , result , nread ) ! = 0 ) {
printf ( " smb2cli_read returned '%s', expected '%s' \n " ,
result , hello ) ;
return false ;
}
status = smb2cli_close ( cli , 0 , fid_persistent , fid_volatile ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_close returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
2011-11-02 17:38:08 +04:00
status = smb2cli_create ( cli , " " ,
SMB2_OPLOCK_LEVEL_NONE , /* oplock_level, */
SMB2_IMPERSONATION_IMPERSONATION , /* impersonation_level, */
SEC_STD_SYNCHRONIZE |
SEC_DIR_LIST |
SEC_DIR_READ_ATTRIBUTE , /* desired_access, */
0 , /* file_attributes, */
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE , /* share_access, */
FILE_OPEN , /* create_disposition, */
FILE_SYNCHRONOUS_IO_NONALERT | FILE_DIRECTORY_FILE , /* create_options, */
NULL , /* smb2_create_blobs *blobs */
& fid_persistent ,
& fid_volatile ) ;
2011-05-05 20:12:07 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_create returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_query_directory (
cli , 1 , 0 , 0 , fid_persistent , fid_volatile , " * " , 0xffff ,
talloc_tos ( ) , & dir_data , & dir_data_length ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_query_directory returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_close ( cli , 0 , fid_persistent , fid_volatile ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_close returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
2011-11-24 15:33:19 +04:00
saved_tid = cli - > smb2 . tid ;
status = smb2cli_tdis ( cli ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_tdis returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
cli - > smb2 . tid = saved_tid ;
status = smb2cli_tdis ( cli ) ;
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_NETWORK_NAME_DELETED ) ) {
printf ( " 2nd smb2cli_tdis returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
saved_uid = smb2cli_session_current_id ( cli - > smb2 . session ) ;
status = smb2cli_logoff ( cli ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_logoff returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
cli - > smb2 . session = smbXcli_session_create ( cli , cli - > conn ) ;
if ( cli - > smb2 . session = = NULL ) {
printf ( " smbXcli_session_create() returned NULL \n " ) ;
return false ;
}
smb2cli_session_set_id_and_flags ( cli - > smb2 . session , saved_uid , 0 ) ;
status = smb2cli_logoff ( cli ) ;
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_USER_SESSION_DELETED ) ) {
printf ( " 2nd smb2cli_logoff returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
2011-05-05 20:12:07 +04:00
return true ;
}
2011-08-30 20:50:35 +04:00
bool run_smb2_negprot ( int dummy )
{
struct cli_state * cli ;
NTSTATUS status ;
enum protocol_types protocol ;
const char * name = NULL ;
printf ( " Starting SMB2-NEGPROT \n " ) ;
if ( ! torture_init_connection ( & cli ) ) {
return false ;
}
cli - > smb2 . pid = 0xFEFF ;
status = smbXcli_negprot ( cli - > conn , cli - > timeout ,
2011-12-22 16:14:21 +04:00
PROTOCOL_CORE , PROTOCOL_SMB2_24 ) ;
2011-08-30 20:50:35 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smbXcli_negprot returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
protocol = smbXcli_conn_protocol ( cli - > conn ) ;
switch ( protocol ) {
case PROTOCOL_SMB2_02 :
name = " SMB2_02 " ;
break ;
case PROTOCOL_SMB2_10 :
name = " SMB2_10 " ;
break ;
case PROTOCOL_SMB2_22 :
name = " SMB2_22 " ;
break ;
2011-12-22 16:14:21 +04:00
case PROTOCOL_SMB2_24 :
name = " SMB2_24 " ;
break ;
2011-08-30 20:50:35 +04:00
default :
break ;
}
if ( name ) {
printf ( " Server supports %s \n " , name ) ;
} else {
printf ( " Server DOES NOT support SMB2 \n " ) ;
return false ;
}
status = smbXcli_negprot ( cli - > conn , cli - > timeout ,
protocol , protocol ) ;
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_CONNECTION_RESET ) & &
! NT_STATUS_EQUAL ( status , NT_STATUS_CONNECTION_DISCONNECTED ) & &
! NT_STATUS_EQUAL ( status , NT_STATUS_CONNECTION_ABORTED ) ) {
printf ( " 2nd smbXcli_negprot should disconnect - returned %s \n " ,
nt_errstr ( status ) ) ;
return false ;
}
if ( smbXcli_conn_is_connected ( cli - > conn ) ) {
printf ( " 2nd smbXcli_negprot should disconnect "
" - still connected \n " ) ;
return false ;
}
return true ;
}
2011-09-19 12:08:48 +04:00
bool run_smb2_session_reconnect ( int dummy )
{
struct cli_state * cli1 ;
struct cli_state * cli2 ;
NTSTATUS status ;
bool ok ;
uint64_t fid_persistent , fid_volatile ;
struct tevent_context * ev ;
struct tevent_req * subreq ;
DATA_BLOB in_blob = data_blob_null ;
DATA_BLOB out_blob ;
2011-12-27 06:27:45 +04:00
DATA_BLOB session_key ;
struct auth_generic_state * auth_generic_state ;
2011-09-19 12:08:48 +04:00
struct iovec * recv_iov ;
const char * hello = " Hello, world \n " ;
uint8_t * result ;
uint32_t nread ;
printf ( " Starting SMB2-SESSION-RECONNECT \n " ) ;
if ( ! torture_init_connection ( & cli1 ) ) {
return false ;
}
cli1 - > smb2 . pid = 0xFEFF ;
status = smbXcli_negprot ( cli1 - > conn , cli1 - > timeout ,
2011-12-22 16:14:21 +04:00
PROTOCOL_SMB2_02 , PROTOCOL_SMB2_24 ) ;
2011-09-19 12:08:48 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smbXcli_negprot returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = cli_session_setup ( cli1 , username ,
password , strlen ( password ) ,
password , strlen ( password ) ,
workgroup ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " cli_session_setup returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = cli_tree_connect ( cli1 , share , " ????? " , " " , 0 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " cli_tree_connect returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_create ( cli1 , " session-reconnect.txt " ,
SMB2_OPLOCK_LEVEL_NONE , /* oplock_level, */
SMB2_IMPERSONATION_IMPERSONATION , /* impersonation_level, */
SEC_STD_ALL | SEC_FILE_ALL , /* desired_access, */
FILE_ATTRIBUTE_NORMAL , /* file_attributes, */
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE , /* share_access, */
FILE_CREATE , /* create_disposition, */
FILE_DELETE_ON_CLOSE , /* create_options, */
NULL , /* smb2_create_blobs *blobs */
& fid_persistent ,
& fid_volatile ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_create on cli1 %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_write ( cli1 , strlen ( hello ) , 0 , fid_persistent ,
fid_volatile , 0 , 0 , ( const uint8_t * ) hello ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_write returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_flush ( cli1 , fid_persistent , fid_volatile ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_flush returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_read ( cli1 , 0x10000 , 0 , fid_persistent ,
fid_volatile , 2 , 0 ,
talloc_tos ( ) , & result , & nread ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_read returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
if ( nread ! = strlen ( hello ) ) {
printf ( " smb2cli_read returned %d bytes, expected %d \n " ,
( int ) nread , ( int ) strlen ( hello ) ) ;
return false ;
}
if ( memcmp ( hello , result , nread ) ! = 0 ) {
printf ( " smb2cli_read returned '%s', expected '%s' \n " ,
result , hello ) ;
return false ;
}
/* prepare second session */
if ( ! torture_init_connection ( & cli2 ) ) {
return false ;
}
cli2 - > smb2 . pid = 0xFEFF ;
status = smbXcli_negprot ( cli2 - > conn , cli2 - > timeout ,
2011-12-22 16:14:21 +04:00
PROTOCOL_SMB2_02 , PROTOCOL_SMB2_24 ) ;
2011-09-19 12:08:48 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smbXcli_negprot returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
2011-12-27 06:27:45 +04:00
status = auth_generic_client_prepare ( talloc_tos ( ) , & auth_generic_state ) ;
2011-09-19 12:08:48 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-12-27 06:27:45 +04:00
printf ( " auth_generic_client_prepare returned %s \n " , nt_errstr ( status ) ) ;
2011-09-19 12:08:48 +04:00
return false ;
}
2011-12-27 06:27:45 +04:00
gensec_want_feature ( auth_generic_state - > gensec_security ,
GENSEC_FEATURE_SESSION_KEY ) ;
status = auth_generic_set_username ( auth_generic_state , username ) ;
2011-09-19 12:08:48 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-12-27 06:27:45 +04:00
printf ( " auth_generic_set_username returned %s \n " , nt_errstr ( status ) ) ;
2011-09-19 12:08:48 +04:00
return false ;
}
2011-12-27 06:27:45 +04:00
status = auth_generic_set_domain ( auth_generic_state , workgroup ) ;
2011-09-19 12:08:48 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-12-27 06:27:45 +04:00
printf ( " auth_generic_set_domain returned %s \n " , nt_errstr ( status ) ) ;
2011-09-19 12:08:48 +04:00
return false ;
}
2011-12-27 06:27:45 +04:00
status = auth_generic_set_password ( auth_generic_state , password ) ;
2011-09-19 12:08:48 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-12-27 06:27:45 +04:00
printf ( " auth_generic_set_password returned %s \n " , nt_errstr ( status ) ) ;
2011-09-19 12:08:48 +04:00
return false ;
}
2011-12-27 06:27:45 +04:00
status = auth_generic_client_start ( auth_generic_state , GENSEC_OID_NTLMSSP ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " auth_generic_client_start returned %s \n " , nt_errstr ( status ) ) ;
2011-09-19 12:08:48 +04:00
return false ;
}
ev = event_context_init ( talloc_tos ( ) ) ;
if ( ev = = NULL ) {
printf ( " event_context_init() returned NULL \n " ) ;
return false ;
}
2011-12-27 06:27:45 +04:00
status = gensec_update ( auth_generic_state - > gensec_security , talloc_tos ( ) , ev , data_blob_null , & in_blob ) ;
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_MORE_PROCESSING_REQUIRED ) ) {
printf ( " gensec_update returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
cli2 - > smb2 . session = smbXcli_session_create ( cli2 , cli2 - > conn ) ;
2011-09-19 12:08:48 +04:00
subreq = smb2cli_session_setup_send ( talloc_tos ( ) , ev ,
cli2 - > conn ,
cli2 - > timeout ,
cli2 - > smb2 . session ,
0x0 , /* in_flags */
SMB2_CAP_DFS , /* in_capabilities */
0 , /* in_channel */
2012-02-26 20:35:28 +04:00
/* in_previous_session_id: */
smb2cli_session_current_id ( cli1 - > smb2 . session ) ,
2011-09-19 12:08:48 +04:00
& in_blob ) ; /* in_security_buffer */
if ( subreq = = NULL ) {
printf ( " smb2cli_session_setup_send() returned NULL \n " ) ;
return false ;
}
ok = tevent_req_poll ( subreq , ev ) ;
if ( ! ok ) {
printf ( " tevent_req_poll() returned false \n " ) ;
return false ;
}
status = smb2cli_session_setup_recv ( subreq , talloc_tos ( ) ,
NULL , & out_blob ) ;
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_MORE_PROCESSING_REQUIRED ) ) {
printf ( " smb2cli_session_setup_recv returned %s \n " ,
nt_errstr ( status ) ) ;
return false ;
}
2011-12-27 06:27:45 +04:00
status = gensec_update ( auth_generic_state - > gensec_security , talloc_tos ( ) , ev , out_blob , & in_blob ) ;
2011-09-19 12:08:48 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-12-27 06:27:45 +04:00
printf ( " auth_generic_update returned %s \n " , nt_errstr ( status ) ) ;
2011-09-19 12:08:48 +04:00
return false ;
}
subreq = smb2cli_session_setup_send ( talloc_tos ( ) , ev ,
cli2 - > conn ,
cli2 - > timeout ,
cli2 - > smb2 . session ,
0x0 , /* in_flags */
SMB2_CAP_DFS , /* in_capabilities */
0 , /* in_channel */
2012-02-26 20:35:28 +04:00
/* in_previous_session_id: */
smb2cli_session_current_id ( cli1 - > smb2 . session ) ,
2011-09-19 12:08:48 +04:00
& in_blob ) ; /* in_security_buffer */
if ( subreq = = NULL ) {
printf ( " smb2cli_session_setup_send() returned NULL \n " ) ;
return false ;
}
ok = tevent_req_poll ( subreq , ev ) ;
if ( ! ok ) {
printf ( " tevent_req_poll() returned false \n " ) ;
return false ;
}
status = smb2cli_session_setup_recv ( subreq , talloc_tos ( ) ,
& recv_iov , & out_blob ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_session_setup_recv returned %s \n " ,
nt_errstr ( status ) ) ;
return false ;
}
2011-12-27 06:27:45 +04:00
status = gensec_session_key ( auth_generic_state - > gensec_security , talloc_tos ( ) ,
& session_key ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " gensec_session_key returned %s \n " ,
nt_errstr ( status ) ) ;
return false ;
}
2011-09-19 12:08:48 +04:00
/* check file operation on the old client */
status = smb2cli_flush ( cli1 , fid_persistent , fid_volatile ) ;
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_USER_SESSION_DELETED ) ) {
printf ( " smb2cli_flush returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = cli_tree_connect ( cli1 , share , " ????? " , " " , 0 ) ;
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_USER_SESSION_DELETED ) ) {
printf ( " cli_tree_connect returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
/*
* checking file operations without signing .
* on w2k8r2 at least , flush , read and write also work the same way ,
* while create gives ACCESS_DENIED without signing
*/
status = smb2cli_flush ( cli2 , fid_persistent , fid_volatile ) ;
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_FILE_CLOSED ) ) {
printf ( " smb2cli_flush returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_write ( cli2 , strlen ( hello ) , 0 , fid_persistent ,
fid_volatile , 0 , 0 , ( const uint8_t * ) hello ) ;
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_FILE_CLOSED ) ) {
printf ( " smb2cli_write returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_read ( cli2 , 0x10000 , 0 , fid_persistent ,
fid_volatile , 2 , 0 ,
talloc_tos ( ) , & result , & nread ) ;
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_FILE_CLOSED ) ) {
printf ( " smb2cli_read returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_create ( cli2 , " session-reconnect.txt " ,
SMB2_OPLOCK_LEVEL_NONE , /* oplock_level, */
SMB2_IMPERSONATION_IMPERSONATION , /* impersonation_level, */
SEC_STD_ALL | SEC_FILE_ALL , /* desired_access, */
FILE_ATTRIBUTE_NORMAL , /* file_attributes, */
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE , /* share_access, */
FILE_CREATE , /* create_disposition, */
FILE_DELETE_ON_CLOSE , /* create_options, */
NULL , /* smb2_create_blobs *blobs */
& fid_persistent ,
& fid_volatile ) ;
2012-01-06 11:31:16 +04:00
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_ACCESS_DENIED ) & &
! NT_STATUS_EQUAL ( status , NT_STATUS_NETWORK_NAME_DELETED ) ) {
2011-09-19 12:08:48 +04:00
printf ( " smb2cli_create on cli2 %s \n " , nt_errstr ( status ) ) ;
return false ;
}
/* now grab the session key and try with signing */
2012-02-27 11:48:55 +04:00
status = smb2cli_session_set_session_key ( cli2 - > smb2 . session ,
session_key ,
recv_iov ) ;
2011-09-19 12:08:48 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2012-02-27 11:48:55 +04:00
printf ( " smb2cli_session_set_session_key %s \n " , nt_errstr ( status ) ) ;
2011-09-19 12:08:48 +04:00
return false ;
}
/* the tid seems to be irrelevant at this stage */
cli2 - > smb2 . tid = cli1 - > smb2 . tid ;
status = smb2cli_flush ( cli2 , fid_persistent , fid_volatile ) ;
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_FILE_CLOSED ) ) {
printf ( " smb2cli_flush returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_write ( cli2 , strlen ( hello ) , 0 , fid_persistent ,
fid_volatile , 0 , 0 , ( const uint8_t * ) hello ) ;
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_FILE_CLOSED ) ) {
printf ( " smb2cli_write returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_read ( cli2 , 0x10000 , 0 , fid_persistent ,
fid_volatile , 2 , 0 ,
talloc_tos ( ) , & result , & nread ) ;
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_FILE_CLOSED ) ) {
printf ( " smb2cli_read returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_create ( cli2 , " session-reconnect.txt " ,
SMB2_OPLOCK_LEVEL_NONE , /* oplock_level, */
SMB2_IMPERSONATION_IMPERSONATION , /* impersonation_level, */
SEC_STD_ALL | SEC_FILE_ALL , /* desired_access, */
FILE_ATTRIBUTE_NORMAL , /* file_attributes, */
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE , /* share_access, */
FILE_CREATE , /* create_disposition, */
FILE_DELETE_ON_CLOSE , /* create_options, */
NULL , /* smb2_create_blobs *blobs */
& fid_persistent ,
& fid_volatile ) ;
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_NETWORK_NAME_DELETED ) ) {
printf ( " smb2cli_create on cli2 %s \n " , nt_errstr ( status ) ) ;
return false ;
}
/* now do a new tcon and test file calls again */
status = cli_tree_connect ( cli2 , share , " ????? " , " " , 0 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " cli_tree_connect returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_create ( cli2 , " session-reconnect.txt " ,
SMB2_OPLOCK_LEVEL_NONE , /* oplock_level, */
SMB2_IMPERSONATION_IMPERSONATION , /* impersonation_level, */
SEC_STD_ALL | SEC_FILE_ALL , /* desired_access, */
FILE_ATTRIBUTE_NORMAL , /* file_attributes, */
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE , /* share_access, */
FILE_CREATE , /* create_disposition, */
FILE_DELETE_ON_CLOSE , /* create_options, */
NULL , /* smb2_create_blobs *blobs */
& fid_persistent ,
& fid_volatile ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_create on cli2 %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_write ( cli2 , strlen ( hello ) , 0 , fid_persistent ,
fid_volatile , 0 , 0 , ( const uint8_t * ) hello ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_write returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_flush ( cli2 , fid_persistent , fid_volatile ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_flush returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_read ( cli2 , 0x10000 , 0 , fid_persistent ,
fid_volatile , 2 , 0 ,
talloc_tos ( ) , & result , & nread ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_read returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
if ( nread ! = strlen ( hello ) ) {
printf ( " smb2cli_read returned %d bytes, expected %d \n " ,
( int ) nread , ( int ) strlen ( hello ) ) ;
return false ;
}
if ( memcmp ( hello , result , nread ) ! = 0 ) {
printf ( " smb2cli_read returned '%s', expected '%s' \n " ,
result , hello ) ;
return false ;
}
return true ;
}
2011-09-19 12:09:34 +04:00
bool run_smb2_tcon_dependence ( int dummy )
{
struct cli_state * cli ;
NTSTATUS status ;
uint64_t fid_persistent , fid_volatile ;
const char * hello = " Hello, world \n " ;
uint8_t * result ;
uint32_t nread ;
printf ( " Starting SMB2-TCON-DEPENDENCE \n " ) ;
if ( ! torture_init_connection ( & cli ) ) {
return false ;
}
cli - > smb2 . pid = 0xFEFF ;
status = smbXcli_negprot ( cli - > conn , cli - > timeout ,
2011-12-22 16:14:21 +04:00
PROTOCOL_SMB2_02 , PROTOCOL_SMB2_24 ) ;
2011-09-19 12:09:34 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smbXcli_negprot returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = cli_session_setup ( cli , username ,
password , strlen ( password ) ,
password , strlen ( password ) ,
workgroup ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " cli_session_setup returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = cli_tree_connect ( cli , share , " ????? " , " " , 0 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " cli_tree_connect returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_create ( cli , " tcon_depedence.txt " ,
SMB2_OPLOCK_LEVEL_NONE , /* oplock_level, */
SMB2_IMPERSONATION_IMPERSONATION , /* impersonation_level, */
SEC_STD_ALL | SEC_FILE_ALL , /* desired_access, */
FILE_ATTRIBUTE_NORMAL , /* file_attributes, */
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE , /* share_access, */
FILE_CREATE , /* create_disposition, */
FILE_DELETE_ON_CLOSE , /* create_options, */
NULL , /* smb2_create_blobs *blobs */
& fid_persistent ,
& fid_volatile ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_create on cli %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_write ( cli , strlen ( hello ) , 0 , fid_persistent ,
fid_volatile , 0 , 0 , ( const uint8_t * ) hello ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_write returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_flush ( cli , fid_persistent , fid_volatile ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_flush returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_read ( cli , 0x10000 , 0 , fid_persistent ,
fid_volatile , 2 , 0 ,
talloc_tos ( ) , & result , & nread ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_read returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
if ( nread ! = strlen ( hello ) ) {
printf ( " smb2cli_read returned %d bytes, expected %d \n " ,
( int ) nread , ( int ) strlen ( hello ) ) ;
return false ;
}
if ( memcmp ( hello , result , nread ) ! = 0 ) {
printf ( " smb2cli_read returned '%s', expected '%s' \n " ,
result , hello ) ;
return false ;
}
/* check behaviour with wrong tid... */
cli - > smb2 . tid + + ;
status = smb2cli_read ( cli , 0x10000 , 0 , fid_persistent ,
fid_volatile , 2 , 0 ,
talloc_tos ( ) , & result , & nread ) ;
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_NETWORK_NAME_DELETED ) ) {
printf ( " smb2cli_read returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
cli - > smb2 . tid - - ;
return true ;
}
2011-10-22 12:34:31 +04:00
bool run_smb2_multi_channel ( int dummy )
{
struct cli_state * cli1 ;
struct cli_state * cli2 ;
NTSTATUS status ;
bool ok ;
uint64_t fid_persistent , fid_volatile ;
struct tevent_context * ev ;
struct tevent_req * subreq ;
DATA_BLOB in_blob = data_blob_null ;
DATA_BLOB out_blob ;
2012-02-27 11:48:55 +04:00
DATA_BLOB channel_session_key ;
2011-12-27 06:27:45 +04:00
struct auth_generic_state * auth_generic_state ;
2011-10-22 12:34:31 +04:00
struct iovec * recv_iov ;
const char * hello = " Hello, world \n " ;
uint8_t * result ;
uint32_t nread ;
printf ( " Starting SMB2-MULTI-CHANNEL \n " ) ;
if ( ! torture_init_connection ( & cli1 ) ) {
return false ;
}
cli1 - > smb2 . pid = 0xFEFF ;
if ( ! torture_init_connection ( & cli2 ) ) {
return false ;
}
cli2 - > smb2 . pid = 0xFEFF ;
status = smbXcli_negprot ( cli1 - > conn , cli1 - > timeout ,
2011-12-22 16:14:21 +04:00
PROTOCOL_SMB2_22 , PROTOCOL_SMB2_24 ) ;
2011-10-22 12:34:31 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smbXcli_negprot returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smbXcli_negprot ( cli2 - > conn , cli2 - > timeout ,
2011-12-22 16:14:21 +04:00
PROTOCOL_SMB2_22 , PROTOCOL_SMB2_24 ) ;
2011-10-22 12:34:31 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smbXcli_negprot returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = cli_session_setup ( cli1 , username ,
password , strlen ( password ) ,
password , strlen ( password ) ,
workgroup ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_sesssetup returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = cli_tree_connect ( cli1 , share , " ????? " , " " , 0 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " cli_tree_connect returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_session_create_channel ( cli2 ,
cli1 - > smb2 . session ,
cli2 - > conn ,
& cli2 - > smb2 . session ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_session_create_channel returned %s \n " ,
nt_errstr ( status ) ) ;
return false ;
}
2011-12-27 06:27:45 +04:00
status = auth_generic_client_prepare ( talloc_tos ( ) , & auth_generic_state ) ;
2011-10-22 12:34:31 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-12-27 06:27:45 +04:00
printf ( " auth_generic_client_prepare returned %s \n " , nt_errstr ( status ) ) ;
2011-10-22 12:34:31 +04:00
return false ;
}
2011-12-27 06:27:45 +04:00
gensec_want_feature ( auth_generic_state - > gensec_security ,
GENSEC_FEATURE_SESSION_KEY ) ;
status = auth_generic_set_username ( auth_generic_state , username ) ;
2011-10-22 12:34:31 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-12-27 06:27:45 +04:00
printf ( " auth_generic_set_username returned %s \n " , nt_errstr ( status ) ) ;
2011-10-22 12:34:31 +04:00
return false ;
}
2011-12-27 06:27:45 +04:00
status = auth_generic_set_domain ( auth_generic_state , workgroup ) ;
2011-10-22 12:34:31 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-12-27 06:27:45 +04:00
printf ( " auth_generic_set_domain returned %s \n " , nt_errstr ( status ) ) ;
2011-10-22 12:34:31 +04:00
return false ;
}
2011-12-27 06:27:45 +04:00
status = auth_generic_set_password ( auth_generic_state , password ) ;
2011-10-22 12:34:31 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-12-27 06:27:45 +04:00
printf ( " auth_generic_set_password returned %s \n " , nt_errstr ( status ) ) ;
2011-10-22 12:34:31 +04:00
return false ;
}
2011-12-27 06:27:45 +04:00
status = auth_generic_client_start ( auth_generic_state , GENSEC_OID_NTLMSSP ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " auth_generic_client_start returned %s \n " , nt_errstr ( status ) ) ;
2011-10-22 12:34:31 +04:00
return false ;
}
ev = event_context_init ( talloc_tos ( ) ) ;
if ( ev = = NULL ) {
printf ( " event_context_init() returned NULL \n " ) ;
return false ;
}
2011-12-27 06:27:45 +04:00
status = gensec_update ( auth_generic_state - > gensec_security , talloc_tos ( ) , ev , data_blob_null , & in_blob ) ;
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_MORE_PROCESSING_REQUIRED ) ) {
printf ( " gensec_update returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
2011-10-22 12:34:31 +04:00
subreq = smb2cli_session_setup_send ( talloc_tos ( ) , ev ,
cli2 - > conn ,
cli2 - > timeout ,
cli2 - > smb2 . session ,
0x01 , /* in_flags */
SMB2_CAP_DFS , /* in_capabilities */
0 , /* in_channel */
2012-02-26 20:35:28 +04:00
0 , /* in_previous_session_id */
2011-10-22 12:34:31 +04:00
& in_blob ) ; /* in_security_buffer */
if ( subreq = = NULL ) {
printf ( " smb2cli_session_setup_send() returned NULL \n " ) ;
return false ;
}
ok = tevent_req_poll ( subreq , ev ) ;
if ( ! ok ) {
printf ( " tevent_req_poll() returned false \n " ) ;
return false ;
}
status = smb2cli_session_setup_recv ( subreq , talloc_tos ( ) ,
NULL , & out_blob ) ;
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_MORE_PROCESSING_REQUIRED ) ) {
printf ( " smb2cli_session_setup_recv returned %s \n " ,
nt_errstr ( status ) ) ;
return false ;
}
2011-12-27 06:27:45 +04:00
status = gensec_update ( auth_generic_state - > gensec_security , talloc_tos ( ) , ev , out_blob , & in_blob ) ;
2011-10-22 12:34:31 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-12-27 06:27:45 +04:00
printf ( " auth_generic_update returned %s \n " , nt_errstr ( status ) ) ;
2011-10-22 12:34:31 +04:00
return false ;
}
subreq = smb2cli_session_setup_send ( talloc_tos ( ) , ev ,
cli2 - > conn ,
cli2 - > timeout ,
cli2 - > smb2 . session ,
0x01 , /* in_flags */
SMB2_CAP_DFS , /* in_capabilities */
0 , /* in_channel */
2012-02-26 20:35:28 +04:00
0 , /* in_previous_session_id */
2011-10-22 12:34:31 +04:00
& in_blob ) ; /* in_security_buffer */
if ( subreq = = NULL ) {
printf ( " smb2cli_session_setup_send() returned NULL \n " ) ;
return false ;
}
ok = tevent_req_poll ( subreq , ev ) ;
if ( ! ok ) {
printf ( " tevent_req_poll() returned false \n " ) ;
return false ;
}
status = smb2cli_session_setup_recv ( subreq , talloc_tos ( ) ,
& recv_iov , & out_blob ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_session_setup_recv returned %s \n " ,
nt_errstr ( status ) ) ;
return false ;
}
2011-12-27 06:27:45 +04:00
status = gensec_session_key ( auth_generic_state - > gensec_security , talloc_tos ( ) ,
2012-02-27 11:48:55 +04:00
& channel_session_key ) ;
2011-12-27 06:27:45 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " gensec_session_key returned %s \n " ,
nt_errstr ( status ) ) ;
return false ;
}
2012-02-27 11:48:55 +04:00
status = smb2cli_session_set_channel_key ( cli2 - > smb2 . session ,
channel_session_key ,
recv_iov ) ;
2011-10-22 12:34:31 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2012-02-27 11:48:55 +04:00
printf ( " smb2cli_session_set_channel_key %s \n " , nt_errstr ( status ) ) ;
2011-10-22 12:34:31 +04:00
return false ;
}
cli2 - > smb2 . tid = cli1 - > smb2 . tid ;
status = smb2cli_create ( cli2 , " multi-channel.txt " ,
SMB2_OPLOCK_LEVEL_NONE , /* oplock_level, */
SMB2_IMPERSONATION_IMPERSONATION , /* impersonation_level, */
SEC_STD_ALL | SEC_FILE_ALL , /* desired_access, */
FILE_ATTRIBUTE_NORMAL , /* file_attributes, */
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE , /* share_access, */
FILE_CREATE , /* create_disposition, */
FILE_DELETE_ON_CLOSE , /* create_options, */
NULL , /* smb2_create_blobs *blobs */
& fid_persistent ,
& fid_volatile ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_create on cli2 %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_write ( cli1 , strlen ( hello ) , 0 , fid_persistent ,
fid_volatile , 0 , 0 , ( const uint8_t * ) hello ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_write returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_flush ( cli2 , fid_persistent , fid_volatile ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_flush returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_flush ( cli1 , fid_persistent , fid_volatile ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_flush returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_read ( cli2 , 0x10000 , 0 , fid_persistent ,
fid_volatile , 2 , 0 ,
talloc_tos ( ) , & result , & nread ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_read returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
if ( nread ! = strlen ( hello ) ) {
printf ( " smb2cli_read returned %d bytes, expected %d \n " ,
( int ) nread , ( int ) strlen ( hello ) ) ;
return false ;
}
if ( memcmp ( hello , result , nread ) ! = 0 ) {
printf ( " smb2cli_read returned '%s', expected '%s' \n " ,
result , hello ) ;
return false ;
}
status = smb2cli_close ( cli1 , 0 , fid_persistent , fid_volatile ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_close returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_flush ( cli2 , fid_persistent , fid_volatile ) ;
2012-02-29 06:57:34 +04:00
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_FILE_CLOSED ) ) {
2011-10-22 12:34:31 +04:00
printf ( " smb2cli_flush returned %s \n " , nt_errstr ( status ) ) ;
2012-02-29 06:57:34 +04:00
return false ;
2011-10-22 12:34:31 +04:00
}
status = smb2cli_flush ( cli1 , fid_persistent , fid_volatile ) ;
2012-02-29 06:57:34 +04:00
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_FILE_CLOSED ) ) {
2011-10-22 12:34:31 +04:00
printf ( " smb2cli_flush returned %s \n " , nt_errstr ( status ) ) ;
2012-02-29 06:57:34 +04:00
return false ;
2011-10-22 12:34:31 +04:00
}
return true ;
}
2011-10-22 12:37:34 +04:00
bool run_smb2_session_reauth ( int dummy )
{
struct cli_state * cli ;
NTSTATUS status ;
bool ok ;
uint64_t fid_persistent , fid_volatile ;
2012-02-28 07:24:12 +04:00
uint64_t dir_persistent , dir_volatile ;
uint8_t * dir_data ;
uint32_t dir_data_length ;
2011-10-22 12:37:34 +04:00
struct tevent_context * ev ;
struct tevent_req * subreq ;
DATA_BLOB in_blob = data_blob_null ;
DATA_BLOB out_blob ;
2011-12-27 06:27:45 +04:00
struct auth_generic_state * auth_generic_state ;
2011-10-22 12:37:34 +04:00
struct iovec * recv_iov ;
2012-02-28 08:11:23 +04:00
uint32_t saved_tid ;
2011-10-22 12:37:34 +04:00
printf ( " Starting SMB2-SESSION_REAUTH \n " ) ;
if ( ! torture_init_connection ( & cli ) ) {
return false ;
}
cli - > smb2 . pid = 0xFEFF ;
/*
* PROTOCOL_SMB2_22 has a bug in win8pre0
* it behaves like PROTOCOL_SMB2_02
* and returns NT_STATUS_REQUEST_NOT_ACCEPTED ,
* while it allows it on PROTOCOL_SMB2_02 .
*/
status = smbXcli_negprot ( cli - > conn , cli - > timeout ,
PROTOCOL_SMB2_10 , PROTOCOL_SMB2_10 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smbXcli_negprot returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = cli_session_setup ( cli , username ,
password , strlen ( password ) ,
password , strlen ( password ) ,
workgroup ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_sesssetup returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = cli_tree_connect ( cli , share , " ????? " , " " , 0 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " cli_tree_connect returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_create ( cli , " session-reauth.txt " ,
SMB2_OPLOCK_LEVEL_NONE , /* oplock_level, */
SMB2_IMPERSONATION_IMPERSONATION , /* impersonation_level, */
SEC_STD_ALL | SEC_FILE_ALL , /* desired_access, */
FILE_ATTRIBUTE_NORMAL , /* file_attributes, */
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE , /* share_access, */
FILE_CREATE , /* create_disposition, */
FILE_DELETE_ON_CLOSE , /* create_options, */
NULL , /* smb2_create_blobs *blobs */
& fid_persistent ,
& fid_volatile ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_create %s \n " , nt_errstr ( status ) ) ;
return false ;
}
2012-02-28 07:24:12 +04:00
status = smb2cli_create ( cli , " " ,
SMB2_OPLOCK_LEVEL_NONE , /* oplock_level, */
SMB2_IMPERSONATION_IMPERSONATION , /* impersonation_level, */
SEC_STD_SYNCHRONIZE |
SEC_DIR_LIST |
SEC_DIR_READ_ATTRIBUTE , /* desired_access, */
0 , /* file_attributes, */
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE , /* share_access, */
FILE_OPEN , /* create_disposition, */
FILE_SYNCHRONOUS_IO_NONALERT | FILE_DIRECTORY_FILE , /* create_options, */
NULL , /* smb2_create_blobs *blobs */
& dir_persistent ,
& dir_volatile ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_create returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_query_directory (
cli , 1 , 0x3 , 0 , dir_persistent , dir_volatile ,
" session-reauth.txt " , 0xffff ,
talloc_tos ( ) , & dir_data , & dir_data_length ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_query_directory returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
2011-12-27 06:27:45 +04:00
status = auth_generic_client_prepare ( talloc_tos ( ) , & auth_generic_state ) ;
2011-10-22 12:37:34 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-12-27 06:27:45 +04:00
printf ( " auth_generic_client_prepare returned %s \n " , nt_errstr ( status ) ) ;
2011-10-22 12:37:34 +04:00
return false ;
}
2011-12-27 06:27:45 +04:00
gensec_want_feature ( auth_generic_state - > gensec_security ,
GENSEC_FEATURE_SESSION_KEY ) ;
status = auth_generic_set_username ( auth_generic_state , username ) ;
2011-10-22 12:37:34 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-12-27 06:27:45 +04:00
printf ( " auth_generic_set_username returned %s \n " , nt_errstr ( status ) ) ;
2011-10-22 12:37:34 +04:00
return false ;
}
2011-12-27 06:27:45 +04:00
status = auth_generic_set_domain ( auth_generic_state , workgroup ) ;
2011-10-22 12:37:34 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-12-27 06:27:45 +04:00
printf ( " auth_generic_set_domain returned %s \n " , nt_errstr ( status ) ) ;
2011-10-22 12:37:34 +04:00
return false ;
}
2011-12-27 06:27:45 +04:00
status = auth_generic_set_password ( auth_generic_state , password ) ;
2011-10-22 12:37:34 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-12-27 06:27:45 +04:00
printf ( " auth_generic_set_password returned %s \n " , nt_errstr ( status ) ) ;
2011-10-22 12:37:34 +04:00
return false ;
}
2011-12-27 06:27:45 +04:00
status = auth_generic_client_start ( auth_generic_state , GENSEC_OID_NTLMSSP ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " auth_generic_client_start returned %s \n " , nt_errstr ( status ) ) ;
2011-10-22 12:37:34 +04:00
return false ;
}
ev = event_context_init ( talloc_tos ( ) ) ;
if ( ev = = NULL ) {
printf ( " event_context_init() returned NULL \n " ) ;
return false ;
}
2011-12-27 06:27:45 +04:00
status = gensec_update ( auth_generic_state - > gensec_security , talloc_tos ( ) , ev , data_blob_null , & in_blob ) ;
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_MORE_PROCESSING_REQUIRED ) ) {
printf ( " gensec_update returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
2011-10-22 12:37:34 +04:00
subreq = smb2cli_session_setup_send ( talloc_tos ( ) , ev ,
cli - > conn ,
cli - > timeout ,
cli - > smb2 . session ,
0x0 , /* in_flags */
SMB2_CAP_DFS , /* in_capabilities */
0 , /* in_channel */
2012-02-26 20:35:28 +04:00
0 , /* in_previous_session_id */
2011-10-22 12:37:34 +04:00
& in_blob ) ; /* in_security_buffer */
if ( subreq = = NULL ) {
printf ( " smb2cli_session_setup_send() returned NULL \n " ) ;
return false ;
}
ok = tevent_req_poll ( subreq , ev ) ;
if ( ! ok ) {
printf ( " tevent_req_poll() returned false \n " ) ;
return false ;
}
status = smb2cli_session_setup_recv ( subreq , talloc_tos ( ) ,
NULL , & out_blob ) ;
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_MORE_PROCESSING_REQUIRED ) ) {
printf ( " smb2cli_session_setup_recv returned %s \n " ,
nt_errstr ( status ) ) ;
return false ;
}
2011-12-27 06:27:45 +04:00
status = gensec_update ( auth_generic_state - > gensec_security , talloc_tos ( ) , ev , out_blob , & in_blob ) ;
2011-10-22 12:37:34 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-12-27 06:27:45 +04:00
printf ( " auth_generic_update returned %s \n " , nt_errstr ( status ) ) ;
2011-10-22 12:37:34 +04:00
return false ;
}
2012-02-27 16:18:42 +04:00
status = smb2cli_flush ( cli , fid_persistent , fid_volatile ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_flush returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
2012-02-28 07:24:12 +04:00
status = smb2cli_query_directory (
cli , 1 , 0x3 , 0 , dir_persistent , dir_volatile ,
" session-reauth.txt " , 0xffff ,
talloc_tos ( ) , & dir_data , & dir_data_length ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_query_directory returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
2012-02-27 16:23:53 +04:00
status = smb2cli_create ( cli , " session-reauth-invalid.txt " ,
SMB2_OPLOCK_LEVEL_NONE , /* oplock_level, */
SMB2_IMPERSONATION_IMPERSONATION , /* impersonation_level, */
SEC_STD_ALL | SEC_FILE_ALL , /* desired_access, */
FILE_ATTRIBUTE_NORMAL , /* file_attributes, */
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE , /* share_access, */
FILE_CREATE , /* create_disposition, */
FILE_DELETE_ON_CLOSE , /* create_options, */
NULL , /* smb2_create_blobs *blobs */
& fid_persistent ,
& fid_volatile ) ;
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_INVALID_HANDLE ) ) {
printf ( " smb2cli_create %s \n " , nt_errstr ( status ) ) ;
return false ;
}
2012-02-28 07:24:12 +04:00
status = smb2cli_create ( cli , " " ,
SMB2_OPLOCK_LEVEL_NONE , /* oplock_level, */
SMB2_IMPERSONATION_IMPERSONATION , /* impersonation_level, */
SEC_STD_SYNCHRONIZE |
SEC_DIR_LIST |
SEC_DIR_READ_ATTRIBUTE , /* desired_access, */
0 , /* file_attributes, */
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE , /* share_access, */
FILE_OPEN , /* create_disposition, */
FILE_SYNCHRONOUS_IO_NONALERT | FILE_DIRECTORY_FILE , /* create_options, */
NULL , /* smb2_create_blobs *blobs */
& dir_persistent ,
& dir_volatile ) ;
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_INVALID_HANDLE ) ) {
printf ( " smb2cli_create returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
2012-02-28 08:11:23 +04:00
saved_tid = cli - > smb2 . tid ;
status = cli_tree_connect ( cli , share , " ????? " , " " , 0 ) ;
if ( ! NT_STATUS_EQUAL ( status , NT_STATUS_INVALID_HANDLE ) ) {
printf ( " cli_tree_connect returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
cli - > smb2 . tid = saved_tid ;
2011-10-22 12:37:34 +04:00
subreq = smb2cli_session_setup_send ( talloc_tos ( ) , ev ,
cli - > conn ,
cli - > timeout ,
cli - > smb2 . session ,
0x0 , /* in_flags */
SMB2_CAP_DFS , /* in_capabilities */
0 , /* in_channel */
2012-02-26 20:35:28 +04:00
0 , /* in_previous_session_id */
2011-10-22 12:37:34 +04:00
& in_blob ) ; /* in_security_buffer */
if ( subreq = = NULL ) {
printf ( " smb2cli_session_setup_send() returned NULL \n " ) ;
return false ;
}
ok = tevent_req_poll ( subreq , ev ) ;
if ( ! ok ) {
printf ( " tevent_req_poll() returned false \n " ) ;
return false ;
}
status = smb2cli_session_setup_recv ( subreq , talloc_tos ( ) ,
& recv_iov , & out_blob ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_session_setup_recv returned %s \n " ,
nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_flush ( cli , fid_persistent , fid_volatile ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_flush returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_close ( cli , 0 , fid_persistent , fid_volatile ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_close returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
2012-02-27 16:26:00 +04:00
status = smb2cli_create ( cli , " session-reauth.txt " ,
2011-10-22 12:37:34 +04:00
SMB2_OPLOCK_LEVEL_NONE , /* oplock_level, */
SMB2_IMPERSONATION_IMPERSONATION , /* impersonation_level, */
SEC_STD_ALL | SEC_FILE_ALL , /* desired_access, */
FILE_ATTRIBUTE_NORMAL , /* file_attributes, */
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE , /* share_access, */
FILE_CREATE , /* create_disposition, */
FILE_DELETE_ON_CLOSE , /* create_options, */
NULL , /* smb2_create_blobs *blobs */
& fid_persistent ,
& fid_volatile ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_create %s \n " , nt_errstr ( status ) ) ;
return false ;
}
2012-02-28 07:24:12 +04:00
status = smb2cli_query_directory (
cli , 1 , 0x3 , 0 , dir_persistent , dir_volatile ,
" session-reauth.txt " , 0xffff ,
talloc_tos ( ) , & dir_data , & dir_data_length ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_query_directory returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
status = smb2cli_close ( cli , 0 , dir_persistent , dir_volatile ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_close returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
2011-10-22 12:37:34 +04:00
status = smb2cli_close ( cli , 0 , fid_persistent , fid_volatile ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " smb2cli_close returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
2012-02-28 08:11:23 +04:00
saved_tid = cli - > smb2 . tid ;
status = cli_tree_connect ( cli , share , " ????? " , " " , 0 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " cli_tree_connect returned %s \n " , nt_errstr ( status ) ) ;
return false ;
}
cli - > smb2 . tid = saved_tid ;
2011-10-22 12:37:34 +04:00
return true ;
}