2006-07-12 07:35:20 +00:00
/*
Unix SMB / CIFS implementation .
SMB2 notify test suite
Copyright ( C ) Stefan Metzmacher 2006
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 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2006-07-12 07:35:20 +00: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 02:07:03 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2006-07-12 07:35:20 +00:00
*/
# include "includes.h"
# include "libcli/smb2/smb2.h"
# include "libcli/smb2/smb2_calls.h"
# include "torture/torture.h"
# include "torture/smb2/proto.h"
2007-05-15 10:50:25 +00:00
# include "libcli/raw/libcliraw.h"
# include "lib/events/events.h"
2006-07-12 07:35:20 +00:00
# define CHECK_STATUS(status, correct) do { \
if ( ! NT_STATUS_EQUAL ( status , correct ) ) { \
printf ( " (%s) Incorrect status %s - should be %s \n " , \
__location__ , nt_errstr ( status ) , nt_errstr ( correct ) ) ; \
2007-10-06 22:28:14 +00:00
ret = false ; \
2006-07-12 07:35:20 +00:00
goto done ; \
} } while ( 0 )
# define CHECK_VALUE(v, correct) do { \
if ( ( v ) ! = ( correct ) ) { \
printf ( " (%s) Incorrect value %s=%d - should be %d \n " , \
__location__ , # v , v , correct ) ; \
2007-10-06 22:28:14 +00:00
ret = false ; \
2006-07-12 07:35:20 +00:00
goto done ; \
} } while ( 0 )
2006-07-12 14:32:21 +00:00
# define CHECK_WIRE_STR(field, value) do { \
if ( ! field . s | | strcmp ( field . s , value ) ) { \
printf ( " (%s) %s [%s] != %s \n " , \
__location__ , # field , field . s , value ) ; \
2007-10-06 22:28:14 +00:00
ret = false ; \
2006-07-12 14:32:21 +00:00
goto done ; \
} } while ( 0 )
2006-07-12 10:14:18 +00:00
# define FNAME "smb2-notify01.dat"
2007-10-06 22:28:14 +00:00
static bool test_valid_request ( TALLOC_CTX * mem_ctx , struct smb2_tree * tree )
2006-07-12 07:35:20 +00:00
{
2007-10-06 22:28:14 +00:00
bool ret = true ;
2006-07-12 07:35:20 +00:00
NTSTATUS status ;
struct smb2_handle dh ;
struct smb2_notify n ;
struct smb2_request * req ;
status = smb2_util_roothandle ( tree , & dh ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-07-12 10:14:18 +00:00
n . in . recursive = 0x0000 ;
n . in . buffer_size = 0x00080000 ;
2006-07-12 07:35:20 +00:00
n . in . file . handle = dh ;
2006-07-12 10:14:18 +00:00
n . in . completion_filter = 0x00000FFF ;
2006-07-12 07:35:20 +00:00
n . in . unknown = 0x00000000 ;
req = smb2_notify_send ( tree , & n ) ;
2007-05-15 10:50:25 +00:00
while ( ! req - > cancel . can_cancel & & req - > state < = SMB2_REQUEST_RECV ) {
if ( event_loop_once ( req - > transport - > socket - > event . ctx ) ! = 0 ) {
break ;
}
}
2006-07-12 10:14:18 +00:00
status = torture_setup_complex_file ( tree , FNAME ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
status = smb2_notify_recv ( req , mem_ctx , & n ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-07-12 14:32:21 +00:00
CHECK_VALUE ( n . out . num_changes , 1 ) ;
CHECK_VALUE ( n . out . changes [ 0 ] . action , NOTIFY_ACTION_REMOVED ) ;
CHECK_WIRE_STR ( n . out . changes [ 0 ] . name , FNAME ) ;
2006-07-12 10:14:18 +00:00
/*
* if the change response doesn ' t fit in the buffer
* NOTIFY_ENUM_DIR is returned .
*/
n . in . buffer_size = 0x00000000 ;
req = smb2_notify_send ( tree , & n ) ;
2007-05-15 10:50:25 +00:00
while ( ! req - > cancel . can_cancel & & req - > state < = SMB2_REQUEST_RECV ) {
if ( event_loop_once ( req - > transport - > socket - > event . ctx ) ! = 0 ) {
break ;
}
}
2006-07-12 10:14:18 +00:00
status = torture_setup_complex_file ( tree , FNAME ) ;
2006-07-12 07:35:20 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
status = smb2_notify_recv ( req , mem_ctx , & n ) ;
CHECK_STATUS ( status , STATUS_NOTIFY_ENUM_DIR ) ;
2006-07-12 10:14:18 +00:00
/*
* if the change response fits in the buffer we get
* NT_STATUS_OK again
*/
n . in . buffer_size = 0x00080000 ;
req = smb2_notify_send ( tree , & n ) ;
2007-05-15 10:50:25 +00:00
while ( ! req - > cancel . can_cancel & & req - > state < = SMB2_REQUEST_RECV ) {
if ( event_loop_once ( req - > transport - > socket - > event . ctx ) ! = 0 ) {
break ;
}
}
2006-07-12 10:14:18 +00:00
status = torture_setup_complex_file ( tree , FNAME ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
status = smb2_notify_recv ( req , mem_ctx , & n ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-07-12 14:32:21 +00:00
CHECK_VALUE ( n . out . num_changes , 3 ) ;
CHECK_VALUE ( n . out . changes [ 0 ] . action , NOTIFY_ACTION_REMOVED ) ;
CHECK_WIRE_STR ( n . out . changes [ 0 ] . name , FNAME ) ;
CHECK_VALUE ( n . out . changes [ 1 ] . action , NOTIFY_ACTION_ADDED ) ;
CHECK_WIRE_STR ( n . out . changes [ 1 ] . name , FNAME ) ;
CHECK_VALUE ( n . out . changes [ 2 ] . action , NOTIFY_ACTION_MODIFIED ) ;
CHECK_WIRE_STR ( n . out . changes [ 2 ] . name , FNAME ) ;
2006-07-12 10:14:18 +00:00
/* if the first notify returns NOTIFY_ENUM_DIR, all do */
status = smb2_util_close ( tree , dh ) ;
2006-07-12 14:32:21 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-07-12 10:14:18 +00:00
status = smb2_util_roothandle ( tree , & dh ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
n . in . recursive = 0x0000 ;
n . in . buffer_size = 0x00000001 ;
n . in . file . handle = dh ;
n . in . completion_filter = 0x00000FFF ;
n . in . unknown = 0x00000000 ;
req = smb2_notify_send ( tree , & n ) ;
2007-05-15 10:50:25 +00:00
while ( ! req - > cancel . can_cancel & & req - > state < = SMB2_REQUEST_RECV ) {
if ( event_loop_once ( req - > transport - > socket - > event . ctx ) ! = 0 ) {
break ;
}
}
2006-07-12 10:14:18 +00:00
status = torture_setup_complex_file ( tree , FNAME ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
status = smb2_notify_recv ( req , mem_ctx , & n ) ;
CHECK_STATUS ( status , STATUS_NOTIFY_ENUM_DIR ) ;
n . in . buffer_size = 0x00080000 ;
req = smb2_notify_send ( tree , & n ) ;
2007-05-15 10:50:25 +00:00
while ( ! req - > cancel . can_cancel & & req - > state < = SMB2_REQUEST_RECV ) {
if ( event_loop_once ( req - > transport - > socket - > event . ctx ) ! = 0 ) {
break ;
}
}
2006-07-12 10:14:18 +00:00
status = torture_setup_complex_file ( tree , FNAME ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
status = smb2_notify_recv ( req , mem_ctx , & n ) ;
CHECK_STATUS ( status , STATUS_NOTIFY_ENUM_DIR ) ;
/* if the buffer size is too large, we get invalid parameter */
n . in . recursive = 0x0000 ;
n . in . buffer_size = 0x00080001 ;
n . in . file . handle = dh ;
n . in . completion_filter = 0x00000FFF ;
n . in . unknown = 0x00000000 ;
req = smb2_notify_send ( tree , & n ) ;
status = smb2_notify_recv ( req , mem_ctx , & n ) ;
CHECK_STATUS ( status , NT_STATUS_INVALID_PARAMETER ) ;
2006-07-12 07:35:20 +00:00
done :
return ret ;
}
/* basic testing of SMB2 notify
*/
2007-10-06 22:28:14 +00:00
bool torture_smb2_notify ( struct torture_context * torture )
2006-07-12 07:35:20 +00:00
{
struct smb2_tree * tree ;
2007-10-06 22:28:14 +00:00
bool ret = true ;
2006-07-12 07:35:20 +00:00
2007-12-03 00:28:22 +01:00
if ( ! torture_smb2_connection ( torture , & tree ) ) {
2007-10-06 22:28:14 +00:00
return false ;
2006-07-12 07:35:20 +00:00
}
2007-12-03 00:28:22 +01:00
ret & = test_valid_request ( torture , tree ) ;
2006-07-12 07:35:20 +00:00
return ret ;
}