2003-08-13 05:53:07 +04:00
/*
Unix SMB / CIFS implementation .
basic raw test suite for change notify
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"
2005-12-28 18:38:36 +03:00
# include "libcli/raw/libcliraw.h"
2008-04-02 06:53:27 +04:00
# include "libcli/raw/raw_proto.h"
2006-01-03 18:40:05 +03:00
# include "libcli/libcli.h"
2006-03-09 06:52:10 +03:00
# include "system/filesys.h"
2006-03-17 20:59:58 +03:00
# include "torture/util.h"
2011-03-19 02:42:42 +03:00
# include "torture/raw/proto.h"
2018-09-11 01:35:03 +03:00
# include "lib/events/events.h"
2003-08-13 05:53:07 +04:00
# define BASEDIR "\\test_notify"
2015-03-26 20:58:05 +03:00
# define CHECK_WSTR(tctx, field, value, flags) \
2010-06-29 03:06:33 +04:00
do { \
2015-03-26 21:11:16 +03:00
torture_assert_str_equal ( tctx , field . s , value , " values don't match " ) ; \
torture_assert ( tctx , \
! wire_bad_flags ( & field , STR_UNICODE , cli - > transport ) , \
" wire_bad_flags " ) ; \
2010-06-29 03:06:33 +04:00
} while ( 0 )
2003-08-13 05:53:07 +04:00
2018-09-08 01:14:37 +03:00
# define BASEDIR_CN1_DIR BASEDIR "_CN1_DIR"
2003-08-13 05:53:07 +04:00
/*
2006-03-15 17:08:55 +03:00
basic testing of change notify on directories
2003-08-13 05:53:07 +04:00
*/
2015-03-27 19:40:16 +03:00
static bool test_notify_dir ( struct torture_context * tctx ,
2012-04-18 14:19:12 +04:00
struct smbcli_state * cli ,
struct smbcli_state * cli2 )
2003-08-13 05:53:07 +04:00
{
2007-10-07 02:28:14 +04:00
bool ret = true ;
2003-08-13 05:53:07 +04:00
NTSTATUS status ;
2006-07-12 18:25:50 +04:00
union smb_notify notify ;
2003-08-13 05:53:07 +04:00
union smb_open io ;
2006-03-23 18:03:52 +03:00
union smb_close cl ;
2006-03-09 06:52:10 +03:00
int i , count , fnum , fnum2 ;
struct smbcli_request * req , * req2 ;
extern int torture_numops ;
2003-08-13 05:53:07 +04:00
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " TESTING CHANGE NOTIFY ON DIRECTORIES \n " ) ;
2015-03-26 21:18:43 +03:00
2018-09-08 01:14:37 +03:00
torture_assert ( tctx , torture_setup_dir ( cli , BASEDIR_CN1_DIR ) ,
" Failed to setup up test directory: " BASEDIR_CN1_DIR ) ;
2012-04-18 14:19:12 +04:00
2003-08-13 05:53:07 +04:00
/*
get a handle on the directory
*/
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-11-30 07:33:27 +03:00
io . ntcreatex . in . access_mask = SEC_FILE_ALL ;
2003-08-13 05:53:07 +04:00
io . ntcreatex . in . create_options = NTCREATEX_OPTIONS_DIRECTORY ;
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 ;
2005-07-04 09:54:09 +04:00
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_OPEN ;
2003-08-13 05:53:07 +04:00
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
2018-09-08 01:14:37 +03:00
io . ntcreatex . in . fname = BASEDIR_CN1_DIR ;
2003-08-13 05:53:07 +04:00
2015-03-27 19:40:16 +03:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_open " ) ;
2006-03-13 01:48:25 +03:00
fnum = io . ntcreatex . out . file . fnum ;
2003-08-13 05:53:07 +04:00
2015-03-27 19:40:16 +03:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_open " ) ;
2006-03-13 01:48:25 +03:00
fnum2 = io . ntcreatex . out . file . fnum ;
2006-03-09 06:52:10 +03:00
2006-03-15 17:08:55 +03:00
/* ask for a change notify,
on file or directory name changes */
2006-07-12 18:25:50 +04:00
notify . nttrans . level = RAW_NOTIFY_NTTRANS ;
notify . nttrans . in . buffer_size = 1000 ;
notify . nttrans . in . completion_filter = FILE_NOTIFY_CHANGE_NAME ;
notify . nttrans . in . file . fnum = fnum ;
2007-10-07 02:28:14 +04:00
notify . nttrans . in . recursive = true ;
2003-08-13 05:53:07 +04:00
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing notify cancel \n " ) ;
2006-03-15 16:02:37 +03:00
req = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
smb_raw_ntcancel ( req ) ;
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req , tctx , & notify ) ;
torture_assert_ntstatus_equal_goto ( tctx , status , NT_STATUS_CANCELLED ,
2015-03-26 14:00:15 +03:00
ret , done ,
" smb_raw_changenotify_recv " ) ;
2006-03-15 16:02:37 +03:00
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing notify mkdir \n " ) ;
2003-08-13 05:53:07 +04:00
req = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
2018-09-08 01:14:37 +03:00
smbcli_mkdir ( cli2 - > tree , BASEDIR_CN1_DIR " \\ subdir-name " ) ;
2003-08-13 05:53:07 +04:00
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req , tctx , & notify ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_changenotify_recv " ) ;
2003-08-13 05:53:07 +04:00
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx , notify . nttrans . out . num_changes ,
2015-03-26 20:45:47 +03:00
1 , ret , done , " more than one change " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-26 20:45:47 +03:00
notify . nttrans . out . changes [ 0 ] . action ,
NOTIFY_ACTION_ADDED , ret , done ,
" wrong action (exp: ADDED) " ) ;
2015-03-27 19:40:16 +03:00
CHECK_WSTR ( tctx , notify . nttrans . out . changes [ 0 ] . name , " subdir-name " ,
2015-03-26 20:58:05 +03:00
STR_UNICODE ) ;
2003-08-13 05:53:07 +04:00
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing notify rmdir \n " ) ;
2003-08-13 05:53:07 +04:00
req = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
2018-09-08 01:14:37 +03:00
smbcli_rmdir ( cli2 - > tree , BASEDIR_CN1_DIR " \\ subdir-name " ) ;
2003-08-13 05:53:07 +04:00
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req , tctx , & notify ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_changenotify_recv " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx , notify . nttrans . out . num_changes ,
2015-03-26 20:45:47 +03:00
1 , ret , done , " more than one change " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-26 20:45:47 +03:00
notify . nttrans . out . changes [ 0 ] . action ,
NOTIFY_ACTION_REMOVED , ret , done ,
" wrong action (exp: REMOVED) " ) ;
2015-03-27 19:40:16 +03:00
CHECK_WSTR ( tctx , notify . nttrans . out . changes [ 0 ] . name , " subdir-name " ,
2015-03-26 20:58:05 +03:00
STR_UNICODE ) ;
2003-08-13 05:53:07 +04:00
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing notify mkdir - rmdir - mkdir - rmdir \n " ) ;
2003-08-13 05:53:07 +04:00
2018-09-08 01:14:37 +03:00
smbcli_mkdir ( cli2 - > tree , BASEDIR_CN1_DIR " \\ subdir-name " ) ;
smbcli_rmdir ( cli2 - > tree , BASEDIR_CN1_DIR " \\ subdir-name " ) ;
smbcli_mkdir ( cli2 - > tree , BASEDIR_CN1_DIR " \\ subdir-name " ) ;
smbcli_rmdir ( cli2 - > tree , BASEDIR_CN1_DIR " \\ subdir-name " ) ;
2010-09-16 23:36:37 +04:00
smb_msleep ( 200 ) ;
2006-03-15 16:02:37 +03:00
req = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req , tctx , & notify ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_changenotify_recv " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx , notify . nttrans . out . num_changes ,
2015-03-26 20:45:47 +03:00
4 , ret , done , " wrong number of changes " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-26 20:45:47 +03:00
notify . nttrans . out . changes [ 0 ] . action ,
NOTIFY_ACTION_ADDED , ret , done ,
" wrong action (exp: ADDED) " ) ;
2015-03-27 19:40:16 +03:00
CHECK_WSTR ( tctx , notify . nttrans . out . changes [ 0 ] . name , " subdir-name " ,
2015-03-26 20:58:05 +03:00
STR_UNICODE ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-26 20:45:47 +03:00
notify . nttrans . out . changes [ 1 ] . action ,
NOTIFY_ACTION_REMOVED , ret , done ,
" wrong action (exp: REMOVED) " ) ;
2015-03-27 19:40:16 +03:00
CHECK_WSTR ( tctx , notify . nttrans . out . changes [ 1 ] . name , " subdir-name " ,
2015-03-26 20:58:05 +03:00
STR_UNICODE ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-26 20:45:47 +03:00
notify . nttrans . out . changes [ 2 ] . action ,
NOTIFY_ACTION_ADDED , ret , done ,
" wrong action (exp: ADDED) " ) ;
2015-03-27 19:40:16 +03:00
CHECK_WSTR ( tctx , notify . nttrans . out . changes [ 2 ] . name , " subdir-name " ,
2015-03-26 20:58:05 +03:00
STR_UNICODE ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-26 20:45:47 +03:00
notify . nttrans . out . changes [ 3 ] . action ,
NOTIFY_ACTION_REMOVED , ret , done ,
" wrong action (exp: REMOVED) " ) ;
2015-03-27 19:40:16 +03:00
CHECK_WSTR ( tctx , notify . nttrans . out . changes [ 3 ] . name , " subdir-name " ,
2015-03-26 20:58:05 +03:00
STR_UNICODE ) ;
2003-08-13 05:53:07 +04:00
2006-03-09 06:52:10 +03:00
count = torture_numops ;
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing buffered notify on create of %d files \n " , count ) ;
2006-03-09 06:52:10 +03:00
for ( i = 0 ; i < count ; i + + ) {
2018-09-08 01:14:37 +03:00
char * fname = talloc_asprintf ( cli ,
BASEDIR_CN1_DIR " \\ test%d.txt " ,
i ) ;
2006-03-09 06:52:10 +03:00
int fnum3 = smbcli_open ( cli - > tree , fname , O_CREAT | O_RDWR , DENY_NONE ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_not_equal_goto ( tctx , fnum3 , - 1 , ret , done ,
talloc_asprintf ( tctx , " Failed to create %s - %s " ,
2015-03-26 21:41:06 +03:00
fname , smbcli_errstr ( cli - > tree ) ) ) ;
2006-03-09 06:52:10 +03:00
talloc_free ( fname ) ;
smbcli_close ( cli - > tree , fnum3 ) ;
}
2006-03-15 16:02:37 +03:00
/* (1st notify) setup a new notify on a different directory handle.
This new notify won ' t see the events above . */
2006-07-12 18:25:50 +04:00
notify . nttrans . in . file . fnum = fnum2 ;
2006-03-09 06:52:10 +03:00
req2 = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
2006-03-15 16:02:37 +03:00
/* (2nd notify) whereas this notify will see the above buffered events,
and it directly returns the buffered events */
2006-07-12 18:25:50 +04:00
notify . nttrans . in . file . fnum = fnum ;
2006-03-09 06:52:10 +03:00
req = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
2018-09-08 01:14:37 +03:00
status = smbcli_unlink ( cli - > tree , BASEDIR_CN1_DIR " \\ nonexistent.txt " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_ntstatus_equal_goto ( tctx , status ,
2015-03-26 14:00:15 +03:00
NT_STATUS_OBJECT_NAME_NOT_FOUND ,
ret , done ,
" smbcli_unlink " ) ;
2007-05-04 16:41:28 +04:00
2006-03-15 16:02:37 +03:00
/* (1st unlink) as the 2nd notify directly returns,
this unlink is only seen by the 1 st notify and
the 3 rd notify ( later ) */
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing notify on unlink for the first file \n " ) ;
2018-09-08 01:14:37 +03:00
status = smbcli_unlink ( cli2 - > tree , BASEDIR_CN1_DIR " \\ test0.txt " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smbcli_unlink " ) ;
2006-03-09 06:52:10 +03:00
/* receive the reply from the 2nd notify */
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req , tctx , & notify ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_changenotify_recv " ) ;
2006-03-09 06:52:10 +03:00
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx , notify . nttrans . out . num_changes ,
2015-03-26 20:45:47 +03:00
count , ret , done ,
" wrong number of changes " ) ;
2007-05-04 16:41:28 +04:00
for ( i = 1 ; i < count ; i + + ) {
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-26 20:45:47 +03:00
notify . nttrans . out . changes [ i ] . action ,
NOTIFY_ACTION_ADDED , ret , done ,
" wrong action (exp: ADDED) " ) ;
2006-03-09 06:52:10 +03:00
}
2015-03-27 19:40:16 +03:00
CHECK_WSTR ( tctx , notify . nttrans . out . changes [ 0 ] . name , " test0.txt " ,
2015-03-26 20:58:05 +03:00
STR_UNICODE ) ;
2006-03-09 06:52:10 +03:00
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " and now from the 1st notify \n " ) ;
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req2 , tctx , & notify ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_changenotify_recv " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx , notify . nttrans . out . num_changes ,
2015-03-26 20:45:47 +03:00
1 , ret , done , " wrong number of changes " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-26 20:45:47 +03:00
notify . nttrans . out . changes [ 0 ] . action ,
NOTIFY_ACTION_REMOVED , ret , done ,
" wrong action (exp: REMOVED) " ) ;
2015-03-27 19:40:16 +03:00
CHECK_WSTR ( tctx , notify . nttrans . out . changes [ 0 ] . name , " test0.txt " ,
2015-03-26 20:58:05 +03:00
STR_UNICODE ) ;
2006-03-09 06:52:10 +03:00
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " (3rd notify) this notify will only see the 1st unlink \n " ) ;
2006-03-09 06:52:10 +03:00
req = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
2006-03-15 16:02:37 +03:00
2018-09-08 01:14:37 +03:00
status = smbcli_unlink ( cli - > tree , BASEDIR_CN1_DIR " \\ nonexistent.txt " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_ntstatus_equal_goto ( tctx , status ,
2015-03-26 14:00:15 +03:00
NT_STATUS_OBJECT_NAME_NOT_FOUND ,
ret , done ,
" smbcli_unlink " ) ;
2007-05-04 16:41:28 +04:00
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing notify on wildcard unlink for %d files \n " , count - 1 ) ;
2006-03-15 16:02:37 +03:00
/* (2nd unlink) do a wildcard unlink */
2021-12-02 23:08:49 +03:00
status = smbcli_unlink_wcard ( cli2 - > tree , BASEDIR_CN1_DIR " \\ test*.txt " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_changenotify_recv " ) ;
2006-03-09 06:52:10 +03:00
2006-04-06 15:09:24 +04:00
/* receive the 3rd notify */
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req , tctx , & notify ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_changenotify_recv " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx , notify . nttrans . out . num_changes ,
2015-03-26 20:45:47 +03:00
1 , ret , done , " wrong number of changes " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-26 20:45:47 +03:00
notify . nttrans . out . changes [ 0 ] . action ,
NOTIFY_ACTION_REMOVED , ret , done ,
" wrong action (exp: REMOVED) " ) ;
2015-03-27 19:40:16 +03:00
CHECK_WSTR ( tctx , notify . nttrans . out . changes [ 0 ] . name , " test0.txt " ,
2015-03-26 20:58:05 +03:00
STR_UNICODE ) ;
2006-03-09 06:52:10 +03:00
2006-03-15 16:02:37 +03:00
/* and we now see the rest of the unlink calls on both directory handles */
2006-07-12 18:25:50 +04:00
notify . nttrans . in . file . fnum = fnum ;
2006-09-11 06:09:03 +04:00
sleep ( 3 ) ;
2006-03-09 06:52:10 +03:00
req = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req , tctx , & notify ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_changenotify_recv " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx , notify . nttrans . out . num_changes ,
2015-03-26 20:45:47 +03:00
count - 1 , ret , done ,
" wrong number of changes " ) ;
2006-07-12 18:25:50 +04:00
for ( i = 0 ; i < notify . nttrans . out . num_changes ; i + + ) {
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-26 20:45:47 +03:00
notify . nttrans . out . changes [ i ] . action ,
NOTIFY_ACTION_REMOVED , ret , done ,
" wrong action (exp: REMOVED) " ) ;
2006-03-09 06:52:10 +03:00
}
2006-07-12 18:25:50 +04:00
notify . nttrans . in . file . fnum = fnum2 ;
2006-03-09 06:52:10 +03:00
req = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req , tctx , & notify ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_changenotify_recv " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx , notify . nttrans . out . num_changes ,
2015-03-26 20:45:47 +03:00
count - 1 , ret , done ,
" wrong number of changes " ) ;
2006-07-12 18:25:50 +04:00
for ( i = 0 ; i < notify . nttrans . out . num_changes ; i + + ) {
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-26 20:45:47 +03:00
notify . nttrans . out . changes [ i ] . action ,
NOTIFY_ACTION_REMOVED , ret , done ,
" wrong action (exp: REMOVED) " ) ;
2006-03-09 06:52:10 +03:00
}
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing if a close() on the dir handle triggers the notify reply \n " ) ;
2006-03-23 18:03:52 +03:00
2006-07-12 18:25:50 +04:00
notify . nttrans . in . file . fnum = fnum ;
2006-03-23 18:03:52 +03:00
req = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
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 ) ;
2015-03-27 19:40:16 +03:00
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_close " ) ;
2006-03-23 18:03:52 +03:00
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req , tctx , & notify ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_changenotify_recv " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx , notify . nttrans . out . num_changes ,
2015-03-26 20:45:47 +03:00
0 , ret , done , " no changes expected " ) ;
2006-03-23 18:03:52 +03:00
2003-08-13 05:53:07 +04:00
done :
2006-03-15 17:08:55 +03:00
smb_raw_exit ( cli - > session ) ;
2018-09-08 01:14:37 +03:00
smbcli_deltree ( cli - > tree , BASEDIR_CN1_DIR ) ;
2006-03-15 17:08:55 +03:00
return ret ;
}
2007-02-02 20:30:10 +03:00
/*
* Check notify reply for a rename action . Not sure if this is a valid thing
* to do , but depending on timing between inotify and messaging we get the
* add / remove / modify in any order . This routines tries to find the action / name
* pair in any of the three following notify_changes .
*/
2015-03-26 21:08:26 +03:00
static bool check_rename_reply ( struct torture_context * tctx ,
struct smbcli_state * cli ,
2007-02-02 20:30:10 +03:00
int line ,
struct notify_changes * actions ,
uint32_t action , const char * name )
{
int i ;
for ( i = 0 ; i < 3 ; i + + ) {
if ( actions [ i ] . action = = action ) {
2015-03-26 21:08:26 +03:00
CHECK_WSTR ( tctx , actions [ i ] . name , name , STR_UNICODE ) ;
2007-10-07 02:28:14 +04:00
return true ;
2007-02-02 20:30:10 +03:00
}
}
2015-03-26 21:08:26 +03:00
torture_result ( tctx , TORTURE_FAIL ,
__location__ " : (%d) expected action %d, not found \n " ,
line , action ) ;
2007-10-07 02:28:14 +04:00
return false ;
2007-02-02 20:30:10 +03:00
}
2006-04-05 12:56:16 +04:00
/*
testing of recursive change notify
*/
2018-09-08 01:14:37 +03:00
# define BASEDIR_CN1_RECUR BASEDIR "_CN1_RECUR"
2015-03-27 19:40:16 +03:00
static bool test_notify_recursive ( struct torture_context * tctx ,
2012-04-18 16:45:20 +04:00
struct smbcli_state * cli ,
struct smbcli_state * cli2 )
2006-04-05 12:56:16 +04:00
{
2007-10-07 02:28:14 +04:00
bool ret = true ;
2006-04-05 12:56:16 +04:00
NTSTATUS status ;
2006-07-12 18:25:50 +04:00
union smb_notify notify ;
2006-04-05 12:56:16 +04:00
union smb_open io ;
int fnum ;
struct smbcli_request * req1 , * req2 ;
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " TESTING CHANGE NOTIFY WITH RECURSION \n " ) ;
2015-03-26 21:18:43 +03:00
2018-09-08 01:14:37 +03:00
torture_assert ( tctx , torture_setup_dir ( cli , BASEDIR_CN1_RECUR ) ,
" Failed to setup up test directory: " BASEDIR_CN1_RECUR ) ;
2012-04-18 14:24:59 +04:00
2006-04-05 12:56:16 +04:00
/*
get a handle on the directory
*/
io . generic . level = RAW_OPEN_NTCREATEX ;
2009-10-15 11:26:19 +04:00
io . ntcreatex . in . root_fid . fnum = 0 ;
2006-04-05 12:56:16 +04:00
io . ntcreatex . in . flags = 0 ;
io . ntcreatex . in . access_mask = SEC_FILE_ALL ;
io . ntcreatex . in . create_options = NTCREATEX_OPTIONS_DIRECTORY ;
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_OPEN ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
2018-09-08 01:14:37 +03:00
io . ntcreatex . in . fname = BASEDIR_CN1_RECUR ;
2006-04-05 12:56:16 +04:00
2015-03-27 19:40:16 +03:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_open " ) ;
2006-04-05 12:56:16 +04:00
fnum = io . ntcreatex . out . file . fnum ;
/* ask for a change notify, on file or directory name
changes . Setup both with and without recursion */
2006-07-12 18:25:50 +04:00
notify . nttrans . level = RAW_NOTIFY_NTTRANS ;
notify . nttrans . in . buffer_size = 1000 ;
notify . nttrans . in . completion_filter = FILE_NOTIFY_CHANGE_NAME | FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_CREATION ;
notify . nttrans . in . file . fnum = fnum ;
2006-04-05 12:56:16 +04:00
2007-10-07 02:28:14 +04:00
notify . nttrans . in . recursive = true ;
2006-04-05 12:56:16 +04:00
req1 = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
2007-10-07 02:28:14 +04:00
notify . nttrans . in . recursive = false ;
2006-04-05 12:56:16 +04:00
req2 = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
/* cancel initial requests so the buffer is setup */
smb_raw_ntcancel ( req1 ) ;
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req1 , tctx , & notify ) ;
torture_assert_ntstatus_equal_goto ( tctx , status ,
2015-03-26 14:00:15 +03:00
NT_STATUS_CANCELLED ,
ret , done ,
" smb_raw_changenotify_recv " ) ;
2006-04-05 12:56:16 +04:00
smb_raw_ntcancel ( req2 ) ;
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req2 , tctx , & notify ) ;
torture_assert_ntstatus_equal_goto ( tctx , status ,
2015-03-26 14:00:15 +03:00
NT_STATUS_CANCELLED ,
ret , done ,
" smb_raw_changenotify_recv " ) ;
2006-04-05 12:56:16 +04:00
2012-04-18 16:45:20 +04:00
/*
* Make notifies a bit more interesting in a cluster by doing
* the changes against different nodes with - - unclist
*/
2018-09-08 01:14:37 +03:00
smbcli_mkdir ( cli - > tree , BASEDIR_CN1_RECUR " \\ subdir-name " ) ;
smbcli_mkdir ( cli2 - > tree , BASEDIR_CN1_RECUR " \\ subdir-name \\ subname1 " ) ;
2006-04-06 14:06:28 +04:00
smbcli_close ( cli - > tree ,
2018-09-08 01:14:37 +03:00
smbcli_open ( cli - > tree ,
BASEDIR_CN1_RECUR " \\ subdir-name \\ subname2 " ,
O_CREAT , 0 ) ) ;
smbcli_rename ( cli2 - > tree , BASEDIR_CN1_RECUR " \\ subdir-name \\ subname1 " ,
BASEDIR_CN1_RECUR " \\ subdir-name \\ subname1-r " ) ;
smbcli_rename ( cli - > tree ,
BASEDIR_CN1_RECUR " \\ subdir-name \\ subname2 " ,
BASEDIR_CN1_RECUR " \\ subname2-r " ) ;
smbcli_rename ( cli2 - > tree , BASEDIR_CN1_RECUR " \\ subname2-r " ,
BASEDIR_CN1_RECUR " \\ subname3-r " ) ;
2006-04-05 12:56:16 +04:00
2006-07-12 18:25:50 +04:00
notify . nttrans . in . completion_filter = 0 ;
2007-10-07 02:28:14 +04:00
notify . nttrans . in . recursive = true ;
2010-09-16 23:36:37 +04:00
smb_msleep ( 200 ) ;
2006-04-05 12:56:16 +04:00
req1 = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
2018-09-08 01:14:37 +03:00
smbcli_rmdir ( cli - > tree , BASEDIR_CN1_RECUR " \\ subdir-name \\ subname1-r " ) ;
smbcli_rmdir ( cli2 - > tree , BASEDIR_CN1_RECUR " \\ subdir-name " ) ;
smbcli_unlink ( cli - > tree , BASEDIR_CN1_RECUR " \\ subname3-r " ) ;
2006-04-05 12:56:16 +04:00
2015-07-12 11:59:38 +03:00
smb_msleep ( 200 ) ;
2007-10-07 02:28:14 +04:00
notify . nttrans . in . recursive = false ;
2006-04-05 12:56:16 +04:00
req2 = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req1 , tctx , & notify ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_changenotify_recv " ) ;
2006-04-05 12:56:16 +04:00
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx , notify . nttrans . out . num_changes ,
2015-03-26 20:45:47 +03:00
11 , ret , done , " wrong number of changes " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-26 20:45:47 +03:00
notify . nttrans . out . changes [ 0 ] . action ,
NOTIFY_ACTION_ADDED , ret , done ,
" wrong action (exp: ADDED) " ) ;
2015-03-27 19:40:16 +03:00
CHECK_WSTR ( tctx , notify . nttrans . out . changes [ 0 ] . name , " subdir-name " ,
2015-03-26 20:58:05 +03:00
STR_UNICODE ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-26 20:45:47 +03:00
notify . nttrans . out . changes [ 1 ] . action ,
NOTIFY_ACTION_ADDED , ret , done ,
" wrong action (exp: ADDED) " ) ;
2015-03-27 19:40:16 +03:00
CHECK_WSTR ( tctx , notify . nttrans . out . changes [ 1 ] . name ,
2015-03-26 20:58:05 +03:00
" subdir-name \\ subname1 " , STR_UNICODE ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-26 20:45:47 +03:00
notify . nttrans . out . changes [ 2 ] . action ,
NOTIFY_ACTION_ADDED , ret , done ,
" wrong action (exp: ADDED) " ) ;
2015-03-27 19:40:16 +03:00
CHECK_WSTR ( tctx , notify . nttrans . out . changes [ 2 ] . name ,
2015-03-26 20:58:05 +03:00
" subdir-name \\ subname2 " , STR_UNICODE ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-26 20:45:47 +03:00
notify . nttrans . out . changes [ 3 ] . action ,
NOTIFY_ACTION_OLD_NAME , ret , done ,
" wrong action (exp: OLD_NAME) " ) ;
2015-03-27 19:40:16 +03:00
CHECK_WSTR ( tctx , notify . nttrans . out . changes [ 3 ] . name ,
2015-03-26 20:58:05 +03:00
" subdir-name \\ subname1 " , STR_UNICODE ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-26 20:45:47 +03:00
notify . nttrans . out . changes [ 4 ] . action ,
NOTIFY_ACTION_NEW_NAME , ret , done ,
" wrong action (exp: NEW_NAME) " ) ;
2015-03-27 19:40:16 +03:00
CHECK_WSTR ( tctx , notify . nttrans . out . changes [ 4 ] . name ,
2015-03-26 20:58:05 +03:00
" subdir-name \\ subname1-r " , STR_UNICODE ) ;
2006-04-05 12:56:16 +04:00
2015-03-27 19:40:16 +03:00
ret & = check_rename_reply ( tctx ,
2007-02-02 20:30:10 +03:00
cli , __LINE__ , & notify . nttrans . out . changes [ 5 ] ,
NOTIFY_ACTION_ADDED , " subname2-r " ) ;
2015-03-27 19:40:16 +03:00
ret & = check_rename_reply ( tctx ,
2007-02-02 20:30:10 +03:00
cli , __LINE__ , & notify . nttrans . out . changes [ 5 ] ,
NOTIFY_ACTION_REMOVED , " subdir-name \\ subname2 " ) ;
2015-03-27 19:40:16 +03:00
ret & = check_rename_reply ( tctx ,
2007-02-02 20:30:10 +03:00
cli , __LINE__ , & notify . nttrans . out . changes [ 5 ] ,
NOTIFY_ACTION_MODIFIED , " subname2-r " ) ;
2015-03-27 19:40:16 +03:00
ret & = check_rename_reply ( tctx ,
2007-02-02 20:30:10 +03:00
cli , __LINE__ , & notify . nttrans . out . changes [ 8 ] ,
NOTIFY_ACTION_OLD_NAME , " subname2-r " ) ;
2015-03-27 19:40:16 +03:00
ret & = check_rename_reply ( tctx ,
2007-02-02 20:30:10 +03:00
cli , __LINE__ , & notify . nttrans . out . changes [ 8 ] ,
NOTIFY_ACTION_NEW_NAME , " subname3-r " ) ;
2015-03-27 19:40:16 +03:00
ret & = check_rename_reply ( tctx ,
2007-02-02 20:30:10 +03:00
cli , __LINE__ , & notify . nttrans . out . changes [ 8 ] ,
NOTIFY_ACTION_MODIFIED , " subname3-r " ) ;
if ( ! ret ) {
goto done ;
2006-04-06 14:06:28 +04:00
}
2006-04-05 12:56:16 +04:00
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req2 , tctx , & notify ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_changenotify_recv " ) ;
2006-04-05 12:56:16 +04:00
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx , notify . nttrans . out . num_changes ,
2015-03-26 20:45:47 +03:00
3 , ret , done , " wrong number of changes " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-26 20:45:47 +03:00
notify . nttrans . out . changes [ 0 ] . action ,
NOTIFY_ACTION_REMOVED , ret , done ,
" wrong action (exp: REMOVED) " ) ;
2015-03-27 19:40:16 +03:00
CHECK_WSTR ( tctx , notify . nttrans . out . changes [ 0 ] . name ,
2015-03-26 20:58:05 +03:00
" subdir-name \\ subname1-r " , STR_UNICODE ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-26 20:45:47 +03:00
notify . nttrans . out . changes [ 1 ] . action ,
NOTIFY_ACTION_REMOVED , ret , done ,
" wrong action (exp: REMOVED) " ) ;
2015-03-27 19:40:16 +03:00
CHECK_WSTR ( tctx , notify . nttrans . out . changes [ 1 ] . name , " subdir-name " ,
2015-03-26 20:58:05 +03:00
STR_UNICODE ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-26 20:45:47 +03:00
notify . nttrans . out . changes [ 2 ] . action ,
NOTIFY_ACTION_REMOVED , ret , done ,
" wrong action (exp: REMOVED) " ) ;
2015-03-27 19:40:16 +03:00
CHECK_WSTR ( tctx , notify . nttrans . out . changes [ 2 ] . name , " subname3-r " ,
2015-03-26 20:58:05 +03:00
STR_UNICODE ) ;
2006-04-05 12:56:16 +04:00
done :
smb_raw_exit ( cli - > session ) ;
2018-09-08 01:14:37 +03:00
smbcli_deltree ( cli - > tree , BASEDIR_CN1_RECUR ) ;
2006-04-05 12:56:16 +04:00
return ret ;
}
2007-07-06 23:45:01 +04:00
/*
testing of change notify mask change
*/
2018-09-08 01:14:37 +03:00
# define BASEDIR_CN1_CNMC BASEDIR "_CN1_CNMC"
2015-03-27 19:40:16 +03:00
static bool test_notify_mask_change ( struct torture_context * tctx ,
2012-04-18 14:27:38 +04:00
struct smbcli_state * cli )
2007-07-06 23:45:01 +04:00
{
2007-10-07 02:28:14 +04:00
bool ret = true ;
2007-07-06 23:45:01 +04:00
NTSTATUS status ;
union smb_notify notify ;
union smb_open io ;
int fnum ;
struct smbcli_request * req1 , * req2 ;
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " TESTING CHANGE NOTIFY WITH MASK CHANGE \n " ) ;
2007-07-06 23:45:01 +04:00
2018-09-08 01:14:37 +03:00
torture_assert ( tctx , torture_setup_dir ( cli , BASEDIR_CN1_CNMC ) ,
" Failed to setup up test directory: " BASEDIR_CN1_CNMC ) ;
2012-04-18 14:27:38 +04:00
2007-07-06 23:45:01 +04:00
/*
get a handle on the directory
*/
io . generic . level = RAW_OPEN_NTCREATEX ;
2009-10-15 11:26:19 +04:00
io . ntcreatex . in . root_fid . fnum = 0 ;
2007-07-06 23:45:01 +04:00
io . ntcreatex . in . flags = 0 ;
io . ntcreatex . in . access_mask = SEC_FILE_ALL ;
io . ntcreatex . in . create_options = NTCREATEX_OPTIONS_DIRECTORY ;
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_OPEN ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
2018-09-08 01:14:37 +03:00
io . ntcreatex . in . fname = BASEDIR_CN1_CNMC ;
2007-07-06 23:45:01 +04:00
2015-03-27 19:40:16 +03:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_open " ) ;
2007-07-06 23:45:01 +04:00
fnum = io . ntcreatex . out . file . fnum ;
/* ask for a change notify, on file or directory name
changes . Setup both with and without recursion */
notify . nttrans . level = RAW_NOTIFY_NTTRANS ;
notify . nttrans . in . buffer_size = 1000 ;
notify . nttrans . in . completion_filter = FILE_NOTIFY_CHANGE_ATTRIBUTES ;
notify . nttrans . in . file . fnum = fnum ;
2007-10-07 02:28:14 +04:00
notify . nttrans . in . recursive = true ;
2007-07-06 23:45:01 +04:00
req1 = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
2007-10-07 02:28:14 +04:00
notify . nttrans . in . recursive = false ;
2007-07-06 23:45:01 +04:00
req2 = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
/* cancel initial requests so the buffer is setup */
smb_raw_ntcancel ( req1 ) ;
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req1 , tctx , & notify ) ;
torture_assert_ntstatus_equal_goto ( tctx , status ,
2015-03-26 14:00:15 +03:00
NT_STATUS_CANCELLED ,
ret , done ,
" smb_raw_changenotify_recv " ) ;
2007-07-06 23:45:01 +04:00
smb_raw_ntcancel ( req2 ) ;
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req2 , tctx , & notify ) ;
torture_assert_ntstatus_equal_goto ( tctx , status ,
2015-03-26 14:00:15 +03:00
NT_STATUS_CANCELLED ,
ret , done ,
" smb_raw_changenotify_recv " ) ;
2007-07-06 23:45:01 +04:00
2007-10-07 02:28:14 +04:00
notify . nttrans . in . recursive = true ;
2007-07-06 23:45:01 +04:00
req1 = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
/* Set to hidden then back again. */
2018-09-08 01:14:37 +03:00
smbcli_close ( cli - > tree ,
smbcli_open ( cli - > tree , BASEDIR_CN1_CNMC " \\ tname1 " , O_CREAT , 0 ) ) ;
smbcli_setatr ( cli - > tree , BASEDIR_CN1_CNMC " \\ tname1 " ,
FILE_ATTRIBUTE_HIDDEN , 0 ) ;
smbcli_unlink ( cli - > tree , BASEDIR_CN1_CNMC " \\ tname1 " ) ;
2007-07-06 23:45:01 +04:00
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req1 , tctx , & notify ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_changenotify_recv " ) ;
2007-07-06 23:45:01 +04:00
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx , notify . nttrans . out . num_changes ,
2015-03-26 20:45:47 +03:00
1 , ret , done , " wrong number of changes " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-26 20:45:47 +03:00
notify . nttrans . out . changes [ 0 ] . action ,
NOTIFY_ACTION_MODIFIED , ret , done ,
" wrong action (exp: MODIFIED) " ) ;
2015-03-27 19:40:16 +03:00
CHECK_WSTR ( tctx , notify . nttrans . out . changes [ 0 ] . name , " tname1 " ,
2015-03-26 20:58:05 +03:00
STR_UNICODE ) ;
2007-07-06 23:45:01 +04:00
/* Now try and change the mask to include other events.
* This should not work - once the mask is set on a directory
* fnum it seems to be fixed until the fnum is closed . */
notify . nttrans . in . completion_filter = FILE_NOTIFY_CHANGE_NAME | FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_CREATION ;
2007-10-07 02:28:14 +04:00
notify . nttrans . in . recursive = true ;
2007-07-06 23:45:01 +04:00
req1 = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
2007-10-07 02:28:14 +04:00
notify . nttrans . in . recursive = false ;
2007-07-06 23:45:01 +04:00
req2 = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
2018-09-08 01:14:37 +03:00
smbcli_mkdir ( cli - > tree , BASEDIR_CN1_CNMC " \\ subdir-name " ) ;
smbcli_mkdir ( cli - > tree , BASEDIR_CN1_CNMC " \\ subdir-name \\ subname1 " ) ;
2007-07-06 23:45:01 +04:00
smbcli_close ( cli - > tree ,
2018-09-08 01:14:37 +03:00
smbcli_open ( cli - > tree ,
BASEDIR_CN1_CNMC " \\ subdir-name \\ subname2 " ,
O_CREAT , 0 ) ) ;
smbcli_rename ( cli - > tree ,
BASEDIR_CN1_CNMC " \\ subdir-name \\ subname1 " ,
BASEDIR_CN1_CNMC " \\ subdir-name \\ subname1-r " ) ;
smbcli_rename ( cli - > tree ,
BASEDIR_CN1_CNMC " \\ subdir-name \\ subname2 " ,
BASEDIR_CN1_CNMC " \\ subname2-r " ) ;
smbcli_rename ( cli - > tree ,
BASEDIR_CN1_CNMC " \\ subname2-r " ,
BASEDIR_CN1_CNMC " \\ subname3-r " ) ;
smbcli_rmdir ( cli - > tree , BASEDIR_CN1_CNMC " \\ subdir-name \\ subname1-r " ) ;
smbcli_rmdir ( cli - > tree , BASEDIR_CN1_CNMC " \\ subdir-name " ) ;
smbcli_unlink ( cli - > tree , BASEDIR_CN1_CNMC " \\ subname3-r " ) ;
2007-07-06 23:45:01 +04:00
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req1 , tctx , & notify ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_changenotify_recv " ) ;
2007-07-06 23:45:01 +04:00
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx , notify . nttrans . out . num_changes ,
2015-03-26 20:45:47 +03:00
1 , ret , done , " wrong number of changes " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-26 20:45:47 +03:00
notify . nttrans . out . changes [ 0 ] . action ,
NOTIFY_ACTION_MODIFIED , ret , done ,
" wrong action (exp: MODIFIED) " ) ;
2015-03-27 19:40:16 +03:00
CHECK_WSTR ( tctx , notify . nttrans . out . changes [ 0 ] . name , " subname2-r " ,
2015-03-26 20:58:05 +03:00
STR_UNICODE ) ;
2007-07-06 23:45:01 +04:00
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req2 , tctx , & notify ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_changenotify_recv " ) ;
2007-07-06 23:45:01 +04:00
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx , notify . nttrans . out . num_changes ,
2015-03-26 20:45:47 +03:00
1 , ret , done , " wrong number of changes " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-26 20:45:47 +03:00
notify . nttrans . out . changes [ 0 ] . action ,
NOTIFY_ACTION_MODIFIED , ret , done ,
" wrong action (exp: MODIFIED) " ) ;
2015-03-27 19:40:16 +03:00
CHECK_WSTR ( tctx , notify . nttrans . out . changes [ 0 ] . name , " subname3-r " ,
2015-03-26 20:58:05 +03:00
STR_UNICODE ) ;
2007-07-06 23:45:01 +04:00
done :
smb_raw_exit ( cli - > session ) ;
2018-09-08 01:14:37 +03:00
smbcli_deltree ( cli - > tree , BASEDIR_CN1_CNMC ) ;
2007-07-06 23:45:01 +04:00
return ret ;
}
2006-04-06 05:58:50 +04:00
/*
testing of mask bits for change notify
*/
2018-09-08 01:14:37 +03:00
# define BASEDIR_CN1_NOTM BASEDIR "_CN1_NOTM"
2012-04-18 14:22:31 +04:00
static bool test_notify_mask ( struct torture_context * tctx ,
2012-04-18 16:45:20 +04:00
struct smbcli_state * cli ,
struct smbcli_state * cli2 )
2006-04-06 05:58:50 +04:00
{
2007-10-07 02:28:14 +04:00
bool ret = true ;
2006-04-06 05:58:50 +04:00
NTSTATUS status ;
2006-07-12 18:25:50 +04:00
union smb_notify notify ;
2006-04-06 05:58:50 +04:00
union smb_open io ;
2012-04-18 20:05:24 +04:00
union smb_chkpath chkpath ;
2006-04-06 05:58:50 +04:00
int fnum , fnum2 ;
uint32_t mask ;
int i ;
char c = 1 ;
2006-04-06 14:06:28 +04:00
struct timeval tv ;
NTTIME t ;
2006-04-06 05:58:50 +04:00
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " TESTING CHANGE NOTIFY COMPLETION FILTERS \n " ) ;
2006-04-06 14:06:28 +04:00
2018-09-08 01:14:37 +03:00
torture_assert ( tctx , torture_setup_dir ( cli , BASEDIR_CN1_NOTM ) ,
" Failed to setup up test directory: " BASEDIR_CN1_NOTM ) ;
2012-04-18 14:22:31 +04:00
2006-04-06 14:06:28 +04:00
tv = timeval_current_ofs ( 1000 , 0 ) ;
t = timeval_to_nttime ( & tv ) ;
2009-02-20 04:06:27 +03:00
2006-04-06 05:58:50 +04:00
/*
get a handle on the directory
*/
io . generic . level = RAW_OPEN_NTCREATEX ;
2009-10-15 11:26:19 +04:00
io . ntcreatex . in . root_fid . fnum = 0 ;
2006-04-06 05:58:50 +04:00
io . ntcreatex . in . flags = 0 ;
io . ntcreatex . in . access_mask = SEC_FILE_ALL ;
io . ntcreatex . in . create_options = NTCREATEX_OPTIONS_DIRECTORY ;
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_OPEN ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
2018-09-08 01:14:37 +03:00
io . ntcreatex . in . fname = BASEDIR_CN1_NOTM ;
2006-04-06 05:58:50 +04:00
2006-07-12 18:25:50 +04:00
notify . nttrans . level = RAW_NOTIFY_NTTRANS ;
notify . nttrans . in . buffer_size = 1000 ;
2007-10-07 02:28:14 +04:00
notify . nttrans . in . recursive = true ;
2006-04-06 05:58:50 +04:00
2012-04-18 20:05:24 +04:00
chkpath . chkpath . in . path = " \\ " ;
2008-09-30 23:33:00 +04:00
# define NOTIFY_MASK_TEST(test_name, setup, op, cleanup, Action, expected, nchanges) \
2008-09-30 23:44:24 +04:00
do { \
smbcli_getatr ( cli - > tree , test_name , NULL , NULL , NULL ) ; \
2015-03-27 02:43:30 +03:00
for ( mask = i = 0 ; i < 32 ; i + + ) { \
2006-04-06 05:58:50 +04:00
struct smbcli_request * req ; \
2007-12-03 02:28:22 +03:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ; \
2015-03-26 14:00:15 +03:00
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done , \
" smb_raw_open " ) ; \
2006-04-06 05:58:50 +04:00
fnum = io . ntcreatex . out . file . fnum ; \
setup \
2006-07-12 18:25:50 +04:00
notify . nttrans . in . file . fnum = fnum ; \
2019-05-22 14:24:43 +03:00
notify . nttrans . in . completion_filter = ( ( uint32_t ) 1 < < i ) ; \
2006-04-06 05:58:50 +04:00
req = smb_raw_changenotify_send ( cli - > tree , & notify ) ; \
2012-04-18 20:05:24 +04:00
smb_raw_chkpath ( cli - > tree , & chkpath ) ; \
2006-04-06 05:58:50 +04:00
op \
2010-09-16 23:36:37 +04:00
smb_msleep ( 200 ) ; smb_raw_ntcancel ( req ) ; \
2007-12-03 02:28:22 +03:00
status = smb_raw_changenotify_recv ( req , tctx , & notify ) ; \
2006-04-06 05:58:50 +04:00
cleanup \
2006-04-06 14:06:28 +04:00
smbcli_close ( cli - > tree , fnum ) ; \
2006-04-06 05:58:50 +04:00
if ( NT_STATUS_EQUAL ( status , NT_STATUS_CANCELLED ) ) continue ; \
2015-03-26 14:00:15 +03:00
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done , \
" smbcli_close " ) ; \
2006-04-06 14:06:28 +04:00
/* special case to cope with file rename behaviour */ \
2006-07-12 18:25:50 +04:00
if ( nchanges = = 2 & & notify . nttrans . out . num_changes = = 1 & & \
notify . nttrans . out . changes [ 0 ] . action = = NOTIFY_ACTION_MODIFIED & & \
2006-04-06 14:06:28 +04:00
( ( expected ) & FILE_NOTIFY_CHANGE_ATTRIBUTES ) & & \
Action = = NOTIFY_ACTION_OLD_NAME ) { \
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " (rename file special handling OK) \n " ) ; \
2015-03-27 12:19:26 +03:00
} else { \
torture_assert_int_equal_goto ( tctx , \
notify . nttrans . out . num_changes , \
nchanges , ret , done , \
talloc_asprintf ( tctx , \
" nchanges=%d expected=%d action=%d " \
" filter=0x%08x \n " , \
notify . nttrans . out . num_changes , \
nchanges , \
notify . nttrans . out . changes [ 0 ] . action , \
notify . nttrans . in . completion_filter ) ) ; \
torture_assert_int_equal_goto ( tctx , \
notify . nttrans . out . changes [ 0 ] . action , \
Action , ret , done , \
talloc_asprintf ( tctx , \
" nchanges=%d action=%d " \
" expectedAction=%d filter=0x%08x \n " , \
notify . nttrans . out . num_changes , \
notify . nttrans . out . changes [ 0 ] . action , \
Action , \
notify . nttrans . in . completion_filter ) ) ; \
torture_assert_str_equal_goto ( tctx , \
notify . nttrans . out . changes [ 0 ] . name . s , \
" tname1 " , ret , done , \
talloc_asprintf ( tctx , \
" nchanges=%d action=%d filter=0x%08x " \
" name=%s expected_name=tname1 \n " , \
notify . nttrans . out . num_changes , \
notify . nttrans . out . changes [ 0 ] . action , \
notify . nttrans . in . completion_filter , \
notify . nttrans . out . changes [ 0 ] . name . s ) ) ; \
2006-04-06 05:58:50 +04:00
} \
2019-05-22 14:24:43 +03:00
mask | = ( ( uint32_t ) 1 < < i ) ; \
2006-04-06 05:58:50 +04:00
} \
2006-04-06 14:06:28 +04:00
if ( ( expected ) ! = mask ) { \
2015-03-27 12:19:26 +03:00
torture_assert_int_not_equal_goto ( tctx , ( ( expected ) & ~ mask ) , \
0 , ret , done , " Too few bits " ) ; \
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " WARNING: trigger on too many bits. mask=0x%08x expected=0x%08x \n " , \
2015-03-27 12:19:26 +03:00
mask , expected ) ; \
2006-04-06 14:06:28 +04:00
} \
2008-09-30 23:44:24 +04:00
} while ( 0 ) ;
2006-04-06 05:58:50 +04:00
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing mkdir \n " ) ;
2010-04-11 03:39:06 +04:00
NOTIFY_MASK_TEST ( " Testing mkdir " , ; ,
2018-09-08 01:14:37 +03:00
smbcli_mkdir ( cli - > tree , BASEDIR_CN1_NOTM " \\ tname1 " ) ; ,
smbcli_rmdir ( cli2 - > tree , BASEDIR_CN1_NOTM " \\ tname1 " ) ; ,
2006-04-06 05:58:50 +04:00
NOTIFY_ACTION_ADDED ,
FILE_NOTIFY_CHANGE_DIR_NAME , 1 ) ;
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing create file \n " ) ;
2010-04-11 03:39:06 +04:00
NOTIFY_MASK_TEST ( " Testing create file " , ; ,
2018-09-08 01:14:37 +03:00
smbcli_close ( cli - > tree ,
smbcli_open ( cli - > tree ,
BASEDIR_CN1_NOTM " \\ tname1 " ,
O_CREAT , 0 ) ) ; ,
smbcli_unlink ( cli2 - > tree ,
BASEDIR_CN1_NOTM " \\ tname1 " ) ; ,
2006-04-06 05:58:50 +04:00
NOTIFY_ACTION_ADDED ,
FILE_NOTIFY_CHANGE_FILE_NAME , 1 ) ;
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing unlink \n " ) ;
2010-04-11 03:39:06 +04:00
NOTIFY_MASK_TEST ( " Testing unlink " ,
2018-09-08 01:14:37 +03:00
smbcli_close ( cli - > tree ,
smbcli_open ( cli - > tree ,
BASEDIR_CN1_NOTM " \\ tname1 " ,
O_CREAT , 0 ) ) ; ,
smbcli_unlink ( cli2 - > tree ,
BASEDIR_CN1_NOTM " \\ tname1 " ) ; ,
2006-04-06 05:58:50 +04:00
; ,
NOTIFY_ACTION_REMOVED ,
FILE_NOTIFY_CHANGE_FILE_NAME , 1 ) ;
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing rmdir \n " ) ;
2010-04-11 03:39:06 +04:00
NOTIFY_MASK_TEST ( " Testing rmdir " ,
2018-09-08 01:14:37 +03:00
smbcli_mkdir ( cli - > tree , BASEDIR_CN1_NOTM " \\ tname1 " ) ; ,
smbcli_rmdir ( cli2 - > tree , BASEDIR_CN1_NOTM " \\ tname1 " ) ; ,
2006-04-06 05:58:50 +04:00
; ,
NOTIFY_ACTION_REMOVED ,
FILE_NOTIFY_CHANGE_DIR_NAME , 1 ) ;
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing rename file \n " ) ;
2010-04-11 03:39:06 +04:00
NOTIFY_MASK_TEST ( " Testing rename file " ,
2018-09-08 01:14:37 +03:00
smbcli_close ( cli - > tree ,
smbcli_open ( cli - > tree ,
BASEDIR_CN1_NOTM " \\ tname1 " ,
O_CREAT , 0 ) ) ; ,
smbcli_rename ( cli2 - > tree ,
BASEDIR_CN1_NOTM " \\ tname1 " ,
BASEDIR_CN1_NOTM " \\ tname2 " ) ; ,
smbcli_unlink ( cli - > tree , BASEDIR_CN1_NOTM " \\ tname2 " ) ; ,
2006-04-06 05:58:50 +04:00
NOTIFY_ACTION_OLD_NAME ,
FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_CREATION , 2 ) ;
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing rename dir \n " ) ;
2010-04-11 03:39:06 +04:00
NOTIFY_MASK_TEST ( " Testing rename dir " ,
2018-09-08 01:14:37 +03:00
smbcli_mkdir ( cli - > tree , BASEDIR_CN1_NOTM " \\ tname1 " ) ; ,
smbcli_rename ( cli2 - > tree ,
BASEDIR_CN1_NOTM " \\ tname1 " ,
BASEDIR_CN1_NOTM " \\ tname2 " ) ; ,
smbcli_rmdir ( cli - > tree , BASEDIR_CN1_NOTM " \\ tname2 " ) ; ,
2006-04-06 05:58:50 +04:00
NOTIFY_ACTION_OLD_NAME ,
FILE_NOTIFY_CHANGE_DIR_NAME , 2 ) ;
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing set path attribute \n " ) ;
2010-04-11 03:39:06 +04:00
NOTIFY_MASK_TEST ( " Testing set path attribute " ,
2018-09-08 01:14:37 +03:00
smbcli_close ( cli - > tree ,
smbcli_open ( cli - > tree ,
BASEDIR_CN1_NOTM " \\ tname1 " , O_CREAT , 0 ) ) ; ,
smbcli_setatr ( cli2 - > tree ,
BASEDIR_CN1_NOTM " \\ tname1 " , FILE_ATTRIBUTE_HIDDEN , 0 ) ; ,
smbcli_unlink ( cli - > tree , BASEDIR_CN1_NOTM " \\ tname1 " ) ; ,
2006-04-06 05:58:50 +04:00
NOTIFY_ACTION_MODIFIED ,
FILE_NOTIFY_CHANGE_ATTRIBUTES , 1 ) ;
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing set path write time \n " ) ;
2010-04-11 03:39:06 +04:00
NOTIFY_MASK_TEST ( " Testing set path write time " ,
2018-09-08 01:14:37 +03:00
smbcli_close ( cli - > tree , smbcli_open ( cli - > tree ,
BASEDIR_CN1_NOTM " \\ tname1 " , O_CREAT , 0 ) ) ; ,
smbcli_setatr ( cli2 - > tree ,
BASEDIR_CN1_NOTM " \\ tname1 " ,
FILE_ATTRIBUTE_NORMAL , 1000 ) ; ,
smbcli_unlink ( cli - > tree , BASEDIR_CN1_NOTM " \\ tname1 " ) ; ,
2006-04-06 05:58:50 +04:00
NOTIFY_ACTION_MODIFIED ,
FILE_NOTIFY_CHANGE_LAST_WRITE , 1 ) ;
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing set file attribute \n " ) ;
2010-04-11 03:39:06 +04:00
NOTIFY_MASK_TEST ( " Testing set file attribute " ,
2018-09-08 01:14:37 +03:00
fnum2 = create_complex_file ( cli2 , tctx ,
BASEDIR_CN1_NOTM " \\ tname1 " ) ; ,
2012-04-18 16:45:20 +04:00
smbcli_fsetatr ( cli2 - > tree , fnum2 , FILE_ATTRIBUTE_HIDDEN , 0 , 0 , 0 , 0 ) ; ,
2018-09-08 01:14:37 +03:00
( smbcli_close ( cli2 - > tree , fnum2 ) ,
smbcli_unlink ( cli2 - > tree , BASEDIR_CN1_NOTM " \\ tname1 " ) ) ; ,
2006-04-06 05:58:50 +04:00
NOTIFY_ACTION_MODIFIED ,
FILE_NOTIFY_CHANGE_ATTRIBUTES , 1 ) ;
2007-12-03 02:28:22 +03:00
if ( torture_setting_bool ( tctx , " samba3 " , false ) ) {
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Samba3 does not yet support create times "
2007-02-02 18:36:17 +03:00
" everywhere \n " ) ;
}
else {
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing set file create time \n " ) ;
2010-04-11 03:39:06 +04:00
NOTIFY_MASK_TEST ( " Testing set file create time " ,
2007-12-03 02:28:22 +03:00
fnum2 = create_complex_file ( cli , tctx ,
2018-09-08 01:14:37 +03:00
BASEDIR_CN1_NOTM " \\ tname1 " ) ; ,
2007-02-02 18:36:17 +03:00
smbcli_fsetatr ( cli - > tree , fnum2 , 0 , t , 0 , 0 , 0 ) ; ,
( smbcli_close ( cli - > tree , fnum2 ) ,
2018-09-08 01:14:37 +03:00
smbcli_unlink ( cli - > tree ,
BASEDIR_CN1_NOTM " \\ tname1 " ) ) ; ,
2007-02-02 18:36:17 +03:00
NOTIFY_ACTION_MODIFIED ,
FILE_NOTIFY_CHANGE_CREATION , 1 ) ;
}
2006-04-06 05:58:50 +04:00
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing set file access time \n " ) ;
2010-04-11 03:39:06 +04:00
NOTIFY_MASK_TEST ( " Testing set file access time " ,
2018-09-08 01:14:37 +03:00
fnum2 = create_complex_file ( cli , tctx ,
BASEDIR_CN1_NOTM " \\ tname1 " ) ; ,
2006-04-06 14:06:28 +04:00
smbcli_fsetatr ( cli - > tree , fnum2 , 0 , 0 , t , 0 , 0 ) ; ,
2018-09-08 01:14:37 +03:00
( smbcli_close ( cli - > tree , fnum2 ) ,
smbcli_unlink ( cli - > tree , BASEDIR_CN1_NOTM " \\ tname1 " ) ) ; ,
2006-04-06 05:58:50 +04:00
NOTIFY_ACTION_MODIFIED ,
FILE_NOTIFY_CHANGE_LAST_ACCESS , 1 ) ;
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing set file write time \n " ) ;
2010-04-11 03:39:06 +04:00
NOTIFY_MASK_TEST ( " Testing set file write time " ,
2018-09-08 01:14:37 +03:00
fnum2 = create_complex_file ( cli , tctx ,
BASEDIR_CN1_NOTM " \\ tname1 " ) ; ,
2006-04-06 14:06:28 +04:00
smbcli_fsetatr ( cli - > tree , fnum2 , 0 , 0 , 0 , t , 0 ) ; ,
2018-09-08 01:14:37 +03:00
( smbcli_close ( cli - > tree , fnum2 ) ,
smbcli_unlink ( cli - > tree , BASEDIR_CN1_NOTM " \\ tname1 " ) ) ; ,
2006-04-06 05:58:50 +04:00
NOTIFY_ACTION_MODIFIED ,
FILE_NOTIFY_CHANGE_LAST_WRITE , 1 ) ;
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing set file change time \n " ) ;
2010-04-11 03:39:06 +04:00
NOTIFY_MASK_TEST ( " Testing set file change time " ,
2018-09-08 01:14:37 +03:00
fnum2 = create_complex_file ( cli , tctx ,
BASEDIR_CN1_NOTM " \\ tname1 " ) ; ,
2006-04-06 14:06:28 +04:00
smbcli_fsetatr ( cli - > tree , fnum2 , 0 , 0 , 0 , 0 , t ) ; ,
2018-09-08 01:14:37 +03:00
( smbcli_close ( cli - > tree , fnum2 ) ,
smbcli_unlink ( cli - > tree , BASEDIR_CN1_NOTM " \\ tname1 " ) ) ; ,
2006-04-06 05:58:50 +04:00
NOTIFY_ACTION_MODIFIED ,
0 , 1 ) ;
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing write \n " ) ;
2010-04-11 03:39:06 +04:00
NOTIFY_MASK_TEST ( " Testing write " ,
2018-09-08 01:14:37 +03:00
fnum2 = create_complex_file ( cli2 , tctx ,
BASEDIR_CN1_NOTM " \\ tname1 " ) ; ,
2012-04-18 16:45:20 +04:00
smbcli_write ( cli2 - > tree , fnum2 , 1 , & c , 10000 , 1 ) ; ,
2018-09-08 01:14:37 +03:00
( smbcli_close ( cli2 - > tree , fnum2 ) ,
smbcli_unlink ( cli - > tree , BASEDIR_CN1_NOTM " \\ tname1 " ) ) ; ,
2006-04-06 05:58:50 +04:00
NOTIFY_ACTION_MODIFIED ,
0 , 1 ) ;
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing truncate \n " ) ;
2010-04-11 03:39:06 +04:00
NOTIFY_MASK_TEST ( " Testing truncate " ,
2018-09-08 01:14:37 +03:00
fnum2 = create_complex_file ( cli2 , tctx ,
BASEDIR_CN1_NOTM " \\ tname1 " ) ; ,
2012-04-18 16:45:20 +04:00
smbcli_ftruncate ( cli2 - > tree , fnum2 , 10000 ) ; ,
2018-09-08 01:14:37 +03:00
( smbcli_close ( cli2 - > tree , fnum2 ) ,
smbcli_unlink ( cli2 - > tree , BASEDIR_CN1_NOTM " \\ tname1 " ) ) ; ,
2006-04-06 15:09:24 +04:00
NOTIFY_ACTION_MODIFIED ,
FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_ATTRIBUTES , 1 ) ;
2006-04-06 05:58:50 +04:00
done :
smb_raw_exit ( cli - > session ) ;
2018-09-08 01:14:37 +03:00
smbcli_deltree ( cli - > tree , BASEDIR_CN1_NOTM ) ;
2006-04-06 05:58:50 +04:00
return ret ;
}
2006-03-15 17:08:55 +03:00
/*
basic testing of change notify on files
*/
2018-09-08 01:14:37 +03:00
# define BASEDIR_CN1_FILE BASEDIR "_CN1_FILE"
2015-03-27 19:40:16 +03:00
static bool test_notify_file ( struct torture_context * tctx ,
2012-04-18 14:31:12 +04:00
struct smbcli_state * cli )
2006-03-15 17:08:55 +03:00
{
NTSTATUS status ;
2007-10-07 02:28:14 +04:00
bool ret = true ;
2006-03-15 17:08:55 +03:00
union smb_open io ;
union smb_close cl ;
2006-07-12 18:25:50 +04:00
union smb_notify notify ;
2006-03-15 17:08:55 +03:00
struct smbcli_request * req ;
int fnum ;
2018-09-08 01:14:37 +03:00
const char * fname = BASEDIR_CN1_FILE " \\ file.txt " ;
2006-03-15 17:08:55 +03:00
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " TESTING CHANGE NOTIFY ON FILES \n " ) ;
2006-03-15 17:08:55 +03:00
2018-09-08 01:14:37 +03:00
torture_assert ( tctx , torture_setup_dir ( cli , BASEDIR_CN1_FILE ) ,
" Failed to setup up test directory: " BASEDIR_CN1_FILE ) ;
2012-04-18 14:31:12 +04:00
2006-03-15 17:08:55 +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-15 17:08:55 +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 ;
2015-03-27 19:40:16 +03:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_open " ) ;
2006-03-15 17:08:55 +03:00
fnum = io . ntcreatex . out . file . fnum ;
/* ask for a change notify,
on file or directory name changes */
2006-07-12 18:25:50 +04:00
notify . nttrans . level = RAW_NOTIFY_NTTRANS ;
notify . nttrans . in . file . fnum = fnum ;
notify . nttrans . in . buffer_size = 1000 ;
notify . nttrans . in . completion_filter = FILE_NOTIFY_CHANGE_STREAM_NAME ;
2007-10-07 02:28:14 +04:00
notify . nttrans . in . recursive = false ;
2006-03-15 17:08:55 +03:00
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing if notifies on file handles are invalid (should be) \n " ) ;
2006-03-15 17:08:55 +03:00
req = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req , tctx , & notify ) ;
torture_assert_ntstatus_equal_goto ( tctx , status ,
2015-03-26 14:00:15 +03:00
NT_STATUS_INVALID_PARAMETER ,
ret , done ,
" smb_raw_changenotify_recv " ) ;
2006-03-15 17:08:55 +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 ) ;
2015-03-27 19:40:16 +03:00
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_close " ) ;
2006-03-15 17:08:55 +03:00
status = smbcli_unlink ( cli - > tree , fname ) ;
2015-03-27 19:40:16 +03:00
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smbcli_unlink " ) ;
2006-03-15 17:08:55 +03:00
done :
smb_raw_exit ( cli - > session ) ;
2018-09-08 01:14:37 +03:00
smbcli_deltree ( cli - > tree , BASEDIR_CN1_FILE ) ;
2006-03-15 17:08:55 +03:00
return ret ;
}
2006-03-23 18:03:52 +03:00
/*
basic testing of change notifies followed by a tdis
*/
2018-09-08 01:14:37 +03:00
# define BASEDIR_CN1_TDIS BASEDIR "_CN1_TDIS"
2012-04-18 14:39:08 +04:00
static bool test_notify_tdis ( struct torture_context * tctx ,
struct smbcli_state * cli1 )
2006-03-23 18:03:52 +03:00
{
2007-10-07 02:28:14 +04:00
bool ret = true ;
2006-03-23 18:03:52 +03:00
NTSTATUS status ;
2006-07-12 18:25:50 +04:00
union smb_notify notify ;
2006-03-23 18:03:52 +03:00
union smb_open io ;
int fnum ;
struct smbcli_request * req ;
struct smbcli_state * cli = NULL ;
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " TESTING CHANGE NOTIFY FOLLOWED BY TDIS \n " ) ;
2006-03-23 18:03:52 +03:00
2018-09-08 01:14:37 +03:00
torture_assert ( tctx , torture_setup_dir ( cli1 , BASEDIR_CN1_TDIS ) ,
" Failed to setup up test directory: " BASEDIR_CN1_TDIS ) ;
2012-04-18 14:39:08 +04:00
2015-03-26 21:22:08 +03:00
torture_assert ( tctx , torture_open_connection ( & cli , tctx , 0 ) ,
" Failed to open connection. " ) ;
2006-03-23 18:03:52 +03:00
/*
get a handle on the directory
*/
io . generic . level = RAW_OPEN_NTCREATEX ;
2009-10-15 11:26:19 +04:00
io . ntcreatex . in . root_fid . fnum = 0 ;
2006-03-23 18:03:52 +03:00
io . ntcreatex . in . flags = 0 ;
io . ntcreatex . in . access_mask = SEC_FILE_ALL ;
io . ntcreatex . in . create_options = NTCREATEX_OPTIONS_DIRECTORY ;
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_OPEN ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
2018-09-08 01:14:37 +03:00
io . ntcreatex . in . fname = BASEDIR_CN1_TDIS ;
2006-03-23 18:03:52 +03:00
2007-12-03 17:53:07 +03:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2015-03-26 14:00:15 +03:00
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
" smb_raw_open " ) ;
2006-03-23 18:03:52 +03:00
fnum = io . ntcreatex . out . file . fnum ;
/* ask for a change notify,
on file or directory name changes */
2006-07-12 18:25:50 +04:00
notify . nttrans . level = RAW_NOTIFY_NTTRANS ;
notify . nttrans . in . buffer_size = 1000 ;
notify . nttrans . in . completion_filter = FILE_NOTIFY_CHANGE_NAME ;
notify . nttrans . in . file . fnum = fnum ;
2007-10-07 02:28:14 +04:00
notify . nttrans . in . recursive = true ;
2006-03-23 18:03:52 +03:00
req = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
status = smbcli_tdis ( cli ) ;
2015-03-26 14:00:15 +03:00
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
" smbcli_tdis " ) ;
2006-07-13 20:16:29 +04:00
cli - > tree = NULL ;
2006-03-23 18:03:52 +03:00
2007-12-03 17:53:07 +03:00
status = smb_raw_changenotify_recv ( req , tctx , & notify ) ;
2015-03-26 14:00:15 +03:00
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
" smb_raw_changenotify_recv " ) ;
2015-03-26 20:45:47 +03:00
torture_assert_int_equal_goto ( tctx , notify . nttrans . out . num_changes ,
0 , ret , done , " no changes expected " ) ;
2006-03-23 18:03:52 +03:00
done :
torture_close_connection ( cli ) ;
2018-09-08 01:14:37 +03:00
smbcli_deltree ( cli1 - > tree , BASEDIR_CN1_TDIS ) ;
2006-03-23 18:03:52 +03:00
return ret ;
}
/*
basic testing of change notifies followed by a exit
*/
2018-09-08 01:14:37 +03:00
# define BASEDIR_CN1_EX BASEDIR "_CN1_EX"
2012-04-18 14:42:13 +04:00
static bool test_notify_exit ( struct torture_context * tctx ,
struct smbcli_state * cli1 )
2006-03-23 18:03:52 +03:00
{
2007-10-07 02:28:14 +04:00
bool ret = true ;
2006-03-23 18:03:52 +03:00
NTSTATUS status ;
2006-07-12 18:25:50 +04:00
union smb_notify notify ;
2006-03-23 18:03:52 +03:00
union smb_open io ;
int fnum ;
struct smbcli_request * req ;
struct smbcli_state * cli = NULL ;
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " TESTING CHANGE NOTIFY FOLLOWED BY EXIT \n " ) ;
2006-03-23 18:03:52 +03:00
2018-09-08 01:14:37 +03:00
torture_assert ( tctx , torture_setup_dir ( cli1 , BASEDIR_CN1_EX ) ,
" Failed to setup up test directory: " BASEDIR_CN1_EX ) ;
2012-04-18 14:42:13 +04:00
2015-03-26 21:22:08 +03:00
torture_assert ( tctx , torture_open_connection ( & cli , tctx , 0 ) ,
" Failed to open connection. " ) ;
2006-03-23 18:03:52 +03:00
/*
get a handle on the directory
*/
io . generic . level = RAW_OPEN_NTCREATEX ;
2009-10-15 11:26:19 +04:00
io . ntcreatex . in . root_fid . fnum = 0 ;
2006-03-23 18:03:52 +03:00
io . ntcreatex . in . flags = 0 ;
io . ntcreatex . in . access_mask = SEC_FILE_ALL ;
io . ntcreatex . in . create_options = NTCREATEX_OPTIONS_DIRECTORY ;
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_OPEN ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
2018-09-08 01:14:37 +03:00
io . ntcreatex . in . fname = BASEDIR_CN1_EX ;
2006-03-23 18:03:52 +03:00
2007-12-03 17:53:07 +03:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2015-03-26 14:00:15 +03:00
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
" smb_raw_open " ) ;
2006-03-23 18:03:52 +03:00
fnum = io . ntcreatex . out . file . fnum ;
/* ask for a change notify,
on file or directory name changes */
2006-07-12 18:25:50 +04:00
notify . nttrans . level = RAW_NOTIFY_NTTRANS ;
notify . nttrans . in . buffer_size = 1000 ;
notify . nttrans . in . completion_filter = FILE_NOTIFY_CHANGE_NAME ;
notify . nttrans . in . file . fnum = fnum ;
2007-10-07 02:28:14 +04:00
notify . nttrans . in . recursive = true ;
2006-03-23 18:03:52 +03:00
req = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
status = smb_raw_exit ( cli - > session ) ;
2015-03-26 14:00:15 +03:00
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
" smb_raw_exit " ) ;
2006-03-23 18:03:52 +03:00
2007-12-03 17:53:07 +03:00
status = smb_raw_changenotify_recv ( req , tctx , & notify ) ;
2015-03-26 14:00:15 +03:00
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
" smb_raw_changenotify_recv " ) ;
2015-03-26 20:45:47 +03:00
torture_assert_int_equal_goto ( tctx , notify . nttrans . out . num_changes ,
0 , ret , done , " no changes expected " ) ;
2006-03-23 18:03:52 +03:00
done :
torture_close_connection ( cli ) ;
2018-09-08 01:14:37 +03:00
smbcli_deltree ( cli1 - > tree , BASEDIR_CN1_EX ) ;
2006-03-23 18:03:52 +03:00
return ret ;
}
/*
basic testing of change notifies followed by a ulogoff
*/
2018-09-08 01:14:37 +03:00
# define BASEDIR_CN1_UL BASEDIR "_CN1_UL"
2012-04-18 14:44:21 +04:00
static bool test_notify_ulogoff ( struct torture_context * tctx ,
struct smbcli_state * cli1 )
2006-03-23 18:03:52 +03:00
{
2007-10-07 02:28:14 +04:00
bool ret = true ;
2006-03-23 18:03:52 +03:00
NTSTATUS status ;
2006-07-12 18:25:50 +04:00
union smb_notify notify ;
2006-03-23 18:03:52 +03:00
union smb_open io ;
int fnum ;
struct smbcli_request * req ;
struct smbcli_state * cli = NULL ;
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " TESTING CHANGE NOTIFY FOLLOWED BY ULOGOFF \n " ) ;
2006-03-23 18:03:52 +03:00
2018-09-08 01:14:37 +03:00
torture_assert ( tctx , torture_setup_dir ( cli1 , BASEDIR_CN1_UL ) ,
" Failed to setup up test directory: " BASEDIR_CN1_UL ) ;
2012-04-18 14:44:21 +04:00
2015-03-26 21:22:08 +03:00
torture_assert ( tctx , torture_open_connection ( & cli , tctx , 0 ) ,
" Failed to open connection. " ) ;
2006-03-23 18:03:52 +03:00
/*
get a handle on the directory
*/
io . generic . level = RAW_OPEN_NTCREATEX ;
2009-10-15 11:26:19 +04:00
io . ntcreatex . in . root_fid . fnum = 0 ;
2006-03-23 18:03:52 +03:00
io . ntcreatex . in . flags = 0 ;
io . ntcreatex . in . access_mask = SEC_FILE_ALL ;
io . ntcreatex . in . create_options = NTCREATEX_OPTIONS_DIRECTORY ;
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_OPEN ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
2018-09-08 01:14:37 +03:00
io . ntcreatex . in . fname = BASEDIR_CN1_UL ;
2006-03-23 18:03:52 +03:00
2007-12-03 17:53:07 +03:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2015-03-26 14:00:15 +03:00
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
" smb_raw_open " ) ;
2006-03-23 18:03:52 +03:00
fnum = io . ntcreatex . out . file . fnum ;
/* ask for a change notify,
on file or directory name changes */
2006-07-12 18:25:50 +04:00
notify . nttrans . level = RAW_NOTIFY_NTTRANS ;
notify . nttrans . in . buffer_size = 1000 ;
notify . nttrans . in . completion_filter = FILE_NOTIFY_CHANGE_NAME ;
notify . nttrans . in . file . fnum = fnum ;
2007-10-07 02:28:14 +04:00
notify . nttrans . in . recursive = true ;
2006-03-23 18:03:52 +03:00
req = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
status = smb_raw_ulogoff ( cli - > session ) ;
2015-03-26 14:00:15 +03:00
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
" smb_raw_ulogoff " ) ;
2006-03-23 18:03:52 +03:00
2007-12-03 17:53:07 +03:00
status = smb_raw_changenotify_recv ( req , tctx , & notify ) ;
2015-03-26 14:00:15 +03:00
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
" smb_raw_changenotify_recv " ) ;
2015-03-26 20:45:47 +03:00
torture_assert_int_equal_goto ( tctx , notify . nttrans . out . num_changes ,
0 , ret , done , " no changes expected " ) ;
2006-03-23 18:03:52 +03:00
done :
torture_close_connection ( cli ) ;
2018-09-08 01:14:37 +03:00
smbcli_deltree ( cli1 - > tree , BASEDIR_CN1_UL ) ;
2006-03-23 18:03:52 +03:00
return ret ;
}
2006-07-13 20:16:29 +04:00
static void tcp_dis_handler ( struct smbcli_transport * t , void * p )
{
2007-09-07 19:08:14 +04:00
struct smbcli_state * cli = ( struct smbcli_state * ) p ;
2006-07-13 21:37:45 +04:00
smbcli_transport_dead ( cli - > transport , NT_STATUS_LOCAL_DISCONNECT ) ;
2006-07-13 20:16:29 +04:00
cli - > transport = NULL ;
cli - > tree = NULL ;
}
/*
basic testing of change notifies followed by tcp disconnect
*/
2018-09-08 01:14:37 +03:00
# define BASEDIR_CN1_TCPDIS BASEDIR "_CN1_TCPDIS"
2012-04-18 14:47:39 +04:00
static bool test_notify_tcp_dis ( struct torture_context * tctx ,
struct smbcli_state * cli1 )
2006-07-13 20:16:29 +04:00
{
2007-10-07 02:28:14 +04:00
bool ret = true ;
2006-07-13 20:16:29 +04:00
NTSTATUS status ;
union smb_notify notify ;
union smb_open io ;
int fnum ;
struct smbcli_request * req ;
struct smbcli_state * cli = NULL ;
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " TESTING CHANGE NOTIFY FOLLOWED BY TCP DISCONNECT \n " ) ;
2006-07-13 20:16:29 +04:00
2018-09-08 01:14:37 +03:00
torture_assert ( tctx , torture_setup_dir ( cli1 , BASEDIR_CN1_TCPDIS ) ,
" Failed to setup up test directory: "
BASEDIR_CN1_TCPDIS ) ;
2012-04-18 14:47:39 +04:00
2015-03-26 21:22:08 +03:00
torture_assert ( tctx , torture_open_connection ( & cli , tctx , 0 ) ,
" Failed to open connection. " ) ;
2006-07-13 20:16:29 +04:00
/*
get a handle on the directory
*/
io . generic . level = RAW_OPEN_NTCREATEX ;
2009-10-15 11:26:19 +04:00
io . ntcreatex . in . root_fid . fnum = 0 ;
2006-07-13 20:16:29 +04:00
io . ntcreatex . in . flags = 0 ;
io . ntcreatex . in . access_mask = SEC_FILE_ALL ;
io . ntcreatex . in . create_options = NTCREATEX_OPTIONS_DIRECTORY ;
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_OPEN ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
2018-09-08 01:14:37 +03:00
io . ntcreatex . in . fname = BASEDIR_CN1_TCPDIS ;
2006-07-13 20:16:29 +04:00
2007-12-03 17:53:07 +03:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2015-03-26 14:00:15 +03:00
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
" smb_raw_open " ) ;
2006-07-13 20:16:29 +04:00
fnum = io . ntcreatex . out . file . fnum ;
/* ask for a change notify,
on file or directory name changes */
notify . nttrans . level = RAW_NOTIFY_NTTRANS ;
notify . nttrans . in . buffer_size = 1000 ;
notify . nttrans . in . completion_filter = FILE_NOTIFY_CHANGE_NAME ;
notify . nttrans . in . file . fnum = fnum ;
2007-10-07 02:28:14 +04:00
notify . nttrans . in . recursive = true ;
2006-07-13 20:16:29 +04:00
req = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
2013-02-18 01:43:49 +04:00
smbcli_transport_idle_handler ( cli - > transport , tcp_dis_handler , 250000 , cli ) ;
2006-07-13 20:16:29 +04:00
2007-12-03 17:53:07 +03:00
status = smb_raw_changenotify_recv ( req , tctx , & notify ) ;
2015-03-26 14:00:15 +03:00
torture_assert_ntstatus_equal_goto ( tctx , status ,
NT_STATUS_LOCAL_DISCONNECT ,
ret , done ,
" smb_raw_changenotify_recv " ) ;
2006-07-13 20:16:29 +04:00
done :
torture_close_connection ( cli ) ;
2018-09-08 01:14:37 +03:00
smbcli_deltree ( cli1 - > tree , BASEDIR_CN1_TCPDIS ) ;
2006-07-13 20:16:29 +04:00
return ret ;
}
2006-03-30 06:25:04 +04:00
/*
test setting up two change notify requests on one handle
*/
2018-09-08 01:14:37 +03:00
# define BASEDIR_CN1_DBL BASEDIR "_CN1_DBL"
2015-03-27 19:40:16 +03:00
static bool test_notify_double ( struct torture_context * tctx ,
2012-04-18 14:49:55 +04:00
struct smbcli_state * cli )
2006-03-30 06:25:04 +04:00
{
2007-10-07 02:28:14 +04:00
bool ret = true ;
2006-03-30 06:25:04 +04:00
NTSTATUS status ;
2006-07-12 18:25:50 +04:00
union smb_notify notify ;
2006-03-30 06:25:04 +04:00
union smb_open io ;
int fnum ;
struct smbcli_request * req1 , * req2 ;
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " TESTING CHANGE NOTIFY TWICE ON ONE DIRECTORY \n " ) ;
2015-03-26 21:18:43 +03:00
2018-09-08 01:14:37 +03:00
torture_assert ( tctx , torture_setup_dir ( cli , BASEDIR_CN1_DBL ) ,
" Failed to setup up test directory: " BASEDIR_CN1_DBL ) ;
2015-03-26 21:18:43 +03:00
2006-03-30 06:25:04 +04:00
/*
get a handle on the directory
*/
io . generic . level = RAW_OPEN_NTCREATEX ;
2009-10-15 11:26:19 +04:00
io . ntcreatex . in . root_fid . fnum = 0 ;
2006-03-30 06:25:04 +04:00
io . ntcreatex . in . flags = 0 ;
io . ntcreatex . in . access_mask = SEC_FILE_ALL ;
io . ntcreatex . in . create_options = NTCREATEX_OPTIONS_DIRECTORY ;
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_OPEN ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
2018-09-08 01:14:37 +03:00
io . ntcreatex . in . fname = BASEDIR_CN1_DBL ;
2006-03-30 06:25:04 +04:00
2015-03-27 19:40:16 +03:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_open " ) ;
2006-03-30 06:25:04 +04:00
fnum = io . ntcreatex . out . file . fnum ;
/* ask for a change notify,
on file or directory name changes */
2006-07-12 18:25:50 +04:00
notify . nttrans . level = RAW_NOTIFY_NTTRANS ;
notify . nttrans . in . buffer_size = 1000 ;
notify . nttrans . in . completion_filter = FILE_NOTIFY_CHANGE_NAME ;
notify . nttrans . in . file . fnum = fnum ;
2007-10-07 02:28:14 +04:00
notify . nttrans . in . recursive = true ;
2006-03-30 06:25:04 +04:00
req1 = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
req2 = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
2018-09-08 01:14:37 +03:00
smbcli_mkdir ( cli - > tree , BASEDIR_CN1_DBL " \\ subdir-name " ) ;
2006-03-30 06:25:04 +04:00
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req1 , tctx , & notify ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_changenotify_recv " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx , notify . nttrans . out . num_changes ,
2015-03-26 20:45:47 +03:00
1 , ret , done , " wrong number of changes " ) ;
2015-03-27 19:40:16 +03:00
CHECK_WSTR ( tctx , notify . nttrans . out . changes [ 0 ] . name , " subdir-name " ,
2015-03-26 20:58:05 +03:00
STR_UNICODE ) ;
2006-03-30 06:25:04 +04:00
2018-09-08 01:14:37 +03:00
smbcli_mkdir ( cli - > tree , BASEDIR_CN1_DBL " \\ subdir-name2 " ) ;
2006-03-30 06:25:04 +04:00
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req2 , tctx , & notify ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_changenotify_recv " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx , notify . nttrans . out . num_changes ,
2015-03-26 20:45:47 +03:00
1 , ret , done , " wrong number of changes " ) ;
2015-03-27 19:40:16 +03:00
CHECK_WSTR ( tctx , notify . nttrans . out . changes [ 0 ] . name , " subdir-name2 " ,
2015-03-26 20:58:05 +03:00
STR_UNICODE ) ;
2006-03-30 06:25:04 +04:00
done :
smb_raw_exit ( cli - > session ) ;
2018-09-08 01:14:37 +03:00
smbcli_deltree ( cli - > tree , BASEDIR_CN1_DBL ) ;
2006-03-30 06:25:04 +04:00
return ret ;
}
2006-04-07 14:36:54 +04:00
/*
test multiple change notifies at different depths and with / without recursion
*/
2018-09-08 01:14:37 +03:00
# define BASEDIR_CN1_TNT BASEDIR "_CN1_TNT"
2015-03-27 19:40:16 +03:00
static bool test_notify_tree ( struct torture_context * tctx ,
2012-04-18 16:45:20 +04:00
struct smbcli_state * cli ,
struct smbcli_state * cli2 )
2006-04-07 14:36:54 +04:00
{
2007-10-07 02:28:14 +04:00
bool ret = true ;
2006-07-12 18:25:50 +04:00
union smb_notify notify ;
2006-04-07 14:36:54 +04:00
union smb_open io ;
struct smbcli_request * req ;
2006-09-11 11:58:08 +04:00
struct timeval tv ;
2006-04-07 14:36:54 +04:00
struct {
const char * path ;
2007-10-07 02:28:14 +04:00
bool recursive ;
2006-04-07 14:36:54 +04:00
uint32_t filter ;
int expected ;
int fnum ;
2006-09-11 11:58:08 +04:00
int counted ;
2006-04-07 14:36:54 +04:00
} dirs [ ] = {
2018-12-13 15:08:42 +03:00
{
. path = BASEDIR_CN1_TNT " \\ abc " ,
. recursive = true ,
. filter = FILE_NOTIFY_CHANGE_NAME ,
. expected = 30 ,
} ,
{
. path = BASEDIR_CN1_TNT " \\ zqy " ,
. recursive = true ,
. filter = FILE_NOTIFY_CHANGE_NAME ,
. expected = 8 ,
} ,
{
. path = BASEDIR_CN1_TNT " \\ atsy " ,
. recursive = true ,
. filter = FILE_NOTIFY_CHANGE_NAME ,
. expected = 4 ,
} ,
{
. path = BASEDIR_CN1_TNT " \\ abc \\ foo " ,
. recursive = true ,
. filter = FILE_NOTIFY_CHANGE_NAME ,
. expected = 2 ,
} ,
{
. path = BASEDIR_CN1_TNT " \\ abc \\ blah " ,
. recursive = true ,
. filter = FILE_NOTIFY_CHANGE_NAME ,
. expected = 13 ,
} ,
{
. path = BASEDIR_CN1_TNT " \\ abc \\ blah " ,
. recursive = false ,
. filter = FILE_NOTIFY_CHANGE_NAME ,
. expected = 7 ,
} ,
{
. path = BASEDIR_CN1_TNT " \\ abc \\ blah \\ a " ,
. recursive = true ,
. filter = FILE_NOTIFY_CHANGE_NAME ,
. expected = 2 ,
} ,
{
. path = BASEDIR_CN1_TNT " \\ abc \\ blah \\ b " ,
. recursive = true ,
. filter = FILE_NOTIFY_CHANGE_NAME ,
. expected = 2 ,
} ,
{
. path = BASEDIR_CN1_TNT " \\ abc \\ blah \\ c " ,
. recursive = true ,
. filter = FILE_NOTIFY_CHANGE_NAME ,
. expected = 2 ,
} ,
{
. path = BASEDIR_CN1_TNT " \\ abc \\ fooblah " ,
. recursive = true ,
. filter = FILE_NOTIFY_CHANGE_NAME ,
. expected = 2 ,
} ,
{
. path = BASEDIR_CN1_TNT " \\ zqy \\ xx " ,
. recursive = true ,
. filter = FILE_NOTIFY_CHANGE_NAME ,
. expected = 2 ,
} ,
{
. path = BASEDIR_CN1_TNT " \\ zqy \\ yyy " ,
. recursive = true ,
. filter = FILE_NOTIFY_CHANGE_NAME ,
. expected = 2 ,
} ,
{
. path = BASEDIR_CN1_TNT " \\ zqy \\ .. " ,
. recursive = true ,
. filter = FILE_NOTIFY_CHANGE_NAME ,
. expected = 40 ,
} ,
{
. path = BASEDIR_CN1_TNT ,
. recursive = true ,
. filter = FILE_NOTIFY_CHANGE_NAME ,
. expected = 40 ,
} ,
{
. path = BASEDIR_CN1_TNT ,
. recursive = false ,
. filter = FILE_NOTIFY_CHANGE_NAME ,
. expected = 6 ,
} ,
{
. path = BASEDIR_CN1_TNT " \\ atsy " ,
. recursive = false ,
. filter = FILE_NOTIFY_CHANGE_NAME ,
. expected = 4 ,
} ,
{
. path = BASEDIR_CN1_TNT " \\ abc " ,
. recursive = true ,
. filter = FILE_NOTIFY_CHANGE_NAME ,
. expected = 24 ,
} ,
{
. path = BASEDIR_CN1_TNT " \\ abc " ,
. recursive = false ,
. filter = FILE_NOTIFY_CHANGE_FILE_NAME ,
. expected = 0 ,
} ,
{
. path = BASEDIR_CN1_TNT " \\ abc " ,
. recursive = true ,
. filter = FILE_NOTIFY_CHANGE_FILE_NAME ,
. expected = 0 ,
} ,
{
. path = BASEDIR_CN1_TNT " \\ abc " ,
. recursive = true ,
. filter = FILE_NOTIFY_CHANGE_NAME ,
. expected = 24 ,
} ,
2006-04-07 14:36:54 +04:00
} ;
int i ;
NTSTATUS status ;
2007-10-07 02:28:14 +04:00
bool all_done = false ;
2006-04-07 14:36:54 +04:00
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " TESTING CHANGE NOTIFY FOR DIFFERENT DEPTHS \n " ) ;
2006-04-07 14:36:54 +04:00
2018-09-08 01:14:37 +03:00
torture_assert ( tctx , torture_setup_dir ( cli , BASEDIR_CN1_TNT ) ,
" Failed to setup up test directory: " BASEDIR_CN1_TNT ) ;
2012-04-18 14:51:26 +04:00
2006-04-07 14:36:54 +04:00
io . generic . level = RAW_OPEN_NTCREATEX ;
2009-10-15 11:26:19 +04:00
io . ntcreatex . in . root_fid . fnum = 0 ;
2006-04-07 14:36:54 +04:00
io . ntcreatex . in . flags = 0 ;
io . ntcreatex . in . access_mask = SEC_FILE_ALL ;
io . ntcreatex . in . create_options = NTCREATEX_OPTIONS_DIRECTORY ;
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_OPEN_IF ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
2006-07-12 18:25:50 +04:00
notify . nttrans . level = RAW_NOTIFY_NTTRANS ;
notify . nttrans . in . buffer_size = 20000 ;
2006-04-07 14:36:54 +04:00
/*
setup the directory tree , and the notify buffer on each directory
*/
for ( i = 0 ; i < ARRAY_SIZE ( dirs ) ; i + + ) {
io . ntcreatex . in . fname = dirs [ i ] . path ;
2015-03-27 19:40:16 +03:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_open " ) ;
2006-04-07 14:36:54 +04:00
dirs [ i ] . fnum = io . ntcreatex . out . file . fnum ;
2006-07-12 18:25:50 +04:00
notify . nttrans . in . completion_filter = dirs [ i ] . filter ;
notify . nttrans . in . file . fnum = dirs [ i ] . fnum ;
notify . nttrans . in . recursive = dirs [ i ] . recursive ;
2006-04-07 14:36:54 +04:00
req = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
smb_raw_ntcancel ( req ) ;
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req , tctx , & notify ) ;
torture_assert_ntstatus_equal_goto ( tctx , status ,
2015-03-26 14:00:15 +03:00
NT_STATUS_CANCELLED ,
ret , done ,
" smb_raw_changenotify_recv " ) ;
2006-04-07 14:36:54 +04:00
}
/* trigger 2 events in each dir */
for ( i = 0 ; i < ARRAY_SIZE ( dirs ) ; i + + ) {
2015-03-27 19:40:16 +03:00
char * path = talloc_asprintf ( tctx , " %s \\ test.dir " , dirs [ i ] . path ) ;
2012-04-18 16:45:20 +04:00
/*
* Make notifies a bit more interesting in a cluster
* by doing the changes against different nodes with
* - - unclist
*/
2006-04-07 14:36:54 +04:00
smbcli_mkdir ( cli - > tree , path ) ;
2012-04-18 16:45:20 +04:00
smbcli_rmdir ( cli2 - > tree , path ) ;
2006-04-07 14:36:54 +04:00
talloc_free ( path ) ;
}
2018-05-04 23:22:46 +03:00
/* give a bit of time for the events to propagate */
2006-09-11 11:58:08 +04:00
tv = timeval_current ( ) ;
do {
/* count events that have happened in each dir */
for ( i = 0 ; i < ARRAY_SIZE ( dirs ) ; i + + ) {
notify . nttrans . in . file . fnum = dirs [ i ] . fnum ;
req = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
smb_raw_ntcancel ( req ) ;
notify . nttrans . out . num_changes = 0 ;
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req , tctx , & notify ) ;
2006-09-11 11:58:08 +04:00
dirs [ i ] . counted + = notify . nttrans . out . num_changes ;
}
2007-10-07 02:28:14 +04:00
all_done = true ;
2006-09-11 11:58:08 +04:00
for ( i = 0 ; i < ARRAY_SIZE ( dirs ) ; i + + ) {
if ( dirs [ i ] . counted ! = dirs [ i ] . expected ) {
2007-10-07 02:28:14 +04:00
all_done = false ;
2006-09-11 11:58:08 +04:00
}
}
} while ( ! all_done & & timeval_elapsed ( & tv ) < 20 ) ;
2018-05-04 23:22:46 +03:00
torture_comment ( tctx , " took %.4f seconds to propagate all events \n " , timeval_elapsed ( & tv ) ) ;
2006-04-07 14:36:54 +04:00
for ( i = 0 ; i < ARRAY_SIZE ( dirs ) ; i + + ) {
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-27 12:25:17 +03:00
dirs [ i ] . counted , dirs [ i ] . expected , ret , done ,
2015-03-27 19:40:16 +03:00
talloc_asprintf ( tctx ,
2015-03-27 12:25:17 +03:00
" unexpected number of events for '%s' " ,
dirs [ i ] . path ) ) ;
2006-04-07 14:36:54 +04:00
}
/*
run from the back , closing and deleting
*/
for ( i = ARRAY_SIZE ( dirs ) - 1 ; i > = 0 ; i - - ) {
smbcli_close ( cli - > tree , dirs [ i ] . fnum ) ;
smbcli_rmdir ( cli - > tree , dirs [ i ] . path ) ;
}
done :
smb_raw_exit ( cli - > session ) ;
2018-09-08 01:14:37 +03:00
smbcli_deltree ( cli - > tree , BASEDIR_CN1_TNT ) ;
2006-04-07 14:36:54 +04:00
return ret ;
}
2009-02-20 04:06:27 +03:00
/*
Test response when cached server events exceed single NT NOTFIY response
packet size .
*/
2018-09-08 01:14:37 +03:00
# define BASEDIR_CN1_NO BASEDIR "_CN1_NO"
2015-03-27 19:40:16 +03:00
static bool test_notify_overflow ( struct torture_context * tctx ,
2012-04-18 14:53:08 +04:00
struct smbcli_state * cli )
2009-02-20 04:06:27 +03:00
{
bool ret = true ;
NTSTATUS status ;
union smb_notify notify ;
union smb_open io ;
2009-09-29 13:49:50 +04:00
int fnum ;
2009-02-20 04:06:27 +03:00
int count = 100 ;
struct smbcli_request * req1 ;
int i ;
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " TESTING CHANGE NOTIFY EVENT OVERFLOW \n " ) ;
2009-02-20 04:06:27 +03:00
2018-09-08 01:14:37 +03:00
torture_assert ( tctx , torture_setup_dir ( cli , BASEDIR_CN1_NO ) ,
" Failed to setup up test directory: " BASEDIR_CN1_NO ) ;
2012-04-18 14:53:08 +04:00
2009-02-20 04:06:27 +03:00
/* get a handle on the directory */
io . generic . level = RAW_OPEN_NTCREATEX ;
2009-10-15 11:26:19 +04:00
io . ntcreatex . in . root_fid . fnum = 0 ;
2009-02-20 04:06:27 +03:00
io . ntcreatex . in . flags = 0 ;
io . ntcreatex . in . access_mask = SEC_FILE_ALL ;
io . ntcreatex . in . create_options = NTCREATEX_OPTIONS_DIRECTORY ;
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_OPEN ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
2018-09-08 01:14:37 +03:00
io . ntcreatex . in . fname = BASEDIR_CN1_NO ;
2009-02-20 04:06:27 +03:00
2015-03-27 19:40:16 +03:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_open " ) ;
2009-02-20 04:06:27 +03:00
fnum = io . ntcreatex . out . file . fnum ;
/* ask for a change notify, on name changes. */
notify . nttrans . level = RAW_NOTIFY_NTTRANS ;
notify . nttrans . in . buffer_size = 1000 ;
notify . nttrans . in . completion_filter = FILE_NOTIFY_CHANGE_NAME ;
notify . nttrans . in . file . fnum = fnum ;
notify . nttrans . in . recursive = true ;
req1 = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
/* cancel initial requests so the buffer is setup */
smb_raw_ntcancel ( req1 ) ;
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req1 , tctx , & notify ) ;
torture_assert_ntstatus_equal_goto ( tctx , status ,
2015-03-26 14:00:15 +03:00
NT_STATUS_CANCELLED ,
ret , done ,
" smb_raw_changenotify_recv " ) ;
2009-02-20 04:06:27 +03:00
/* open a lot of files, filling up the server side notify buffer */
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing overflowed buffer notify on create of %d files \n " ,
2009-02-20 04:06:27 +03:00
count ) ;
for ( i = 0 ; i < count ; i + + ) {
2018-09-08 01:14:37 +03:00
char * fname = talloc_asprintf ( cli ,
BASEDIR_CN1_NO " \\ test%d.txt " , i ) ;
2009-02-20 04:06:27 +03:00
int fnum2 = smbcli_open ( cli - > tree , fname , O_CREAT | O_RDWR ,
DENY_NONE ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_not_equal_goto ( tctx , fnum2 , - 1 , ret , done ,
talloc_asprintf ( tctx , " Failed to create %s - %s " ,
2015-03-26 21:41:06 +03:00
fname , smbcli_errstr ( cli - > tree ) ) ) ;
2009-02-20 04:06:27 +03:00
talloc_free ( fname ) ;
smbcli_close ( cli - > tree , fnum2 ) ;
}
/* expect that 0 events will be returned with NT_STATUS_OK */
req1 = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req1 , tctx , & notify ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_changenotify_recv " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx , notify . nttrans . out . num_changes ,
2015-03-26 20:45:47 +03:00
0 , ret , done , " no changes expected " ) ;
2009-02-20 04:06:27 +03:00
done :
smb_raw_exit ( cli - > session ) ;
2018-09-08 01:14:37 +03:00
smbcli_deltree ( cli - > tree , BASEDIR_CN1_NO ) ;
2009-02-20 04:06:27 +03:00
return ret ;
}
/*
Test if notifications are returned for changes to the base directory .
They shouldn ' t be .
*/
2018-09-08 01:14:37 +03:00
# define BASEDIR_CN1_NBASE BASEDIR "_CN1_NBASE"
2015-03-27 19:40:16 +03:00
static bool test_notify_basedir ( struct torture_context * tctx ,
2012-04-18 14:54:25 +04:00
struct smbcli_state * cli )
2009-02-20 04:06:27 +03:00
{
bool ret = true ;
NTSTATUS status ;
union smb_notify notify ;
union smb_open io ;
2009-09-29 13:49:50 +04:00
int fnum ;
2009-02-20 04:06:27 +03:00
struct smbcli_request * req1 ;
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " TESTING CHANGE NOTIFY BASEDIR EVENTS \n " ) ;
2009-02-20 04:06:27 +03:00
2018-09-08 01:14:37 +03:00
torture_assert ( tctx , torture_setup_dir ( cli , BASEDIR_CN1_NBASE ) ,
" Failed to setup up test directory: " BASEDIR_CN1_NBASE ) ;
2012-04-18 14:54:25 +04:00
2009-02-20 04:06:27 +03:00
/* get a handle on the directory */
io . generic . level = RAW_OPEN_NTCREATEX ;
2009-10-15 11:26:19 +04:00
io . ntcreatex . in . root_fid . fnum = 0 ;
2009-02-20 04:06:27 +03:00
io . ntcreatex . in . flags = 0 ;
io . ntcreatex . in . access_mask = SEC_FILE_ALL ;
io . ntcreatex . in . create_options = NTCREATEX_OPTIONS_DIRECTORY ;
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_OPEN ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
2018-09-08 01:14:37 +03:00
io . ntcreatex . in . fname = BASEDIR_CN1_NBASE ;
2009-02-20 04:06:27 +03:00
2015-03-27 19:40:16 +03:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_open " ) ;
2009-02-20 04:06:27 +03:00
fnum = io . ntcreatex . out . file . fnum ;
/* create a test file that will also be modified */
2018-09-08 01:14:37 +03:00
smbcli_close ( cli - > tree , smbcli_open ( cli - > tree ,
BASEDIR_CN1_NBASE " \\ tname1 " ,
2009-02-20 04:06:27 +03:00
O_CREAT , 0 ) ) ;
/* ask for a change notify, on attribute changes. */
notify . nttrans . level = RAW_NOTIFY_NTTRANS ;
notify . nttrans . in . buffer_size = 1000 ;
notify . nttrans . in . completion_filter = FILE_NOTIFY_CHANGE_ATTRIBUTES ;
notify . nttrans . in . file . fnum = fnum ;
notify . nttrans . in . recursive = true ;
req1 = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
/* set attribute on the base dir */
2018-09-08 01:14:37 +03:00
smbcli_setatr ( cli - > tree , BASEDIR_CN1_NBASE , FILE_ATTRIBUTE_HIDDEN , 0 ) ;
2009-02-20 04:06:27 +03:00
/* set attribute on a file to assure we receive a notification */
2018-09-08 01:14:37 +03:00
smbcli_setatr ( cli - > tree , BASEDIR_CN1_NBASE " \\ tname1 " ,
FILE_ATTRIBUTE_HIDDEN , 0 ) ;
2010-09-16 23:36:37 +04:00
smb_msleep ( 200 ) ;
2009-02-20 04:06:27 +03:00
/* check how many responses were given, expect only 1 for the file */
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req1 , tctx , & notify ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_changenotify_recv " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx , notify . nttrans . out . num_changes ,
2015-03-26 20:45:47 +03:00
1 , ret , done , " wrong number of changes " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-26 20:45:47 +03:00
notify . nttrans . out . changes [ 0 ] . action ,
NOTIFY_ACTION_MODIFIED , ret , done ,
" wrong action (exp: MODIFIED) " ) ;
2015-03-27 19:40:16 +03:00
CHECK_WSTR ( tctx , notify . nttrans . out . changes [ 0 ] . name , " tname1 " ,
2015-03-26 20:58:05 +03:00
STR_UNICODE ) ;
2009-02-20 04:06:27 +03:00
done :
smb_raw_exit ( cli - > session ) ;
2018-09-08 01:14:37 +03:00
smbcli_deltree ( cli - > tree , BASEDIR_CN1_NBASE ) ;
2009-02-20 04:06:27 +03:00
return ret ;
}
2009-03-10 07:12:48 +03:00
/*
create a secondary tree connect - used to test for a bug in Samba3 messaging
with change notify
*/
2018-09-08 01:14:37 +03:00
2009-03-10 07:12:48 +03:00
static struct smbcli_tree * secondary_tcon ( struct smbcli_state * cli ,
struct torture_context * tctx )
{
NTSTATUS status ;
const char * share , * host ;
struct smbcli_tree * tree ;
union smb_tcon tcon ;
share = torture_setting_string ( tctx , " share " , NULL ) ;
host = torture_setting_string ( tctx , " host " , NULL ) ;
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " create a second tree context on the same session \n " ) ;
2009-03-10 07:12:48 +03:00
tree = smbcli_tree_init ( cli - > session , tctx , false ) ;
tcon . generic . level = RAW_TCON_TCONX ;
2012-08-02 10:48:11 +04:00
tcon . tconx . in . flags = TCONX_FLAG_EXTENDED_RESPONSE ;
2009-03-10 07:12:48 +03:00
tcon . tconx . in . password = data_blob ( NULL , 0 ) ;
tcon . tconx . in . path = talloc_asprintf ( tctx , " \\ \\ %s \\ %s " , host , share ) ;
tcon . tconx . in . device = " A: " ;
status = smb_raw_tcon ( tree , tctx , & tcon ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
talloc_free ( tree ) ;
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Failed to create secondary tree \n " ) ;
2009-03-10 07:12:48 +03:00
return NULL ;
}
tree - > tid = tcon . tconx . out . tid ;
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " tid1=%d tid2=%d \n " , cli - > tree - > tid , tree - > tid ) ;
2009-03-10 07:12:48 +03:00
return tree ;
}
/*
very simple change notify test
*/
2018-09-08 01:14:37 +03:00
# define BASEDIR_CN1_NTCON BASEDIR "_CN1_NTCON"
2015-03-27 19:40:16 +03:00
static bool test_notify_tcon ( struct torture_context * tctx ,
2012-04-18 13:47:48 +04:00
struct smbcli_state * cli )
2009-03-10 07:12:48 +03:00
{
bool ret = true ;
NTSTATUS status ;
union smb_notify notify ;
union smb_open io ;
2011-11-22 01:06:00 +04:00
int fnum ;
2009-03-10 07:12:48 +03:00
struct smbcli_request * req ;
extern int torture_numops ;
struct smbcli_tree * tree = NULL ;
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " TESTING SIMPLE CHANGE NOTIFY \n " ) ;
2015-03-26 21:18:43 +03:00
2018-09-08 01:14:37 +03:00
torture_assert ( tctx , torture_setup_dir ( cli , BASEDIR_CN1_NTCON ) ,
" Failed to setup up test directory: " BASEDIR_CN1_NTCON ) ;
2012-04-18 13:47:48 +04:00
2009-03-10 07:12:48 +03:00
/*
get a handle on the directory
*/
io . generic . level = RAW_OPEN_NTCREATEX ;
2009-10-15 11:26:19 +04:00
io . ntcreatex . in . root_fid . fnum = 0 ;
2009-03-10 07:12:48 +03:00
io . ntcreatex . in . flags = 0 ;
io . ntcreatex . in . access_mask = SEC_FILE_ALL ;
io . ntcreatex . in . create_options = NTCREATEX_OPTIONS_DIRECTORY ;
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_OPEN ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
2018-09-08 01:14:37 +03:00
io . ntcreatex . in . fname = BASEDIR_CN1_NTCON ;
2009-03-10 07:12:48 +03:00
2015-03-27 19:40:16 +03:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_open " ) ;
2009-03-10 07:12:48 +03:00
fnum = io . ntcreatex . out . file . fnum ;
2015-03-27 19:40:16 +03:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_open " ) ;
2009-03-10 07:12:48 +03:00
/* ask for a change notify,
on file or directory name changes */
notify . nttrans . level = RAW_NOTIFY_NTTRANS ;
notify . nttrans . in . buffer_size = 1000 ;
notify . nttrans . in . completion_filter = FILE_NOTIFY_CHANGE_NAME ;
notify . nttrans . in . file . fnum = fnum ;
notify . nttrans . in . recursive = true ;
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing notify mkdir \n " ) ;
2009-03-10 07:12:48 +03:00
req = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
2018-09-08 01:14:37 +03:00
smbcli_mkdir ( cli - > tree , BASEDIR_CN1_NTCON " \\ subdir-name " ) ;
2009-03-10 07:12:48 +03:00
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req , tctx , & notify ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_changenotify_recv " ) ;
2009-03-10 07:12:48 +03:00
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx , notify . nttrans . out . num_changes ,
2015-03-26 20:45:47 +03:00
1 , ret , done , " wrong number of changes " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-26 20:45:47 +03:00
notify . nttrans . out . changes [ 0 ] . action ,
NOTIFY_ACTION_ADDED , ret , done ,
" wrong action (exp: ADDED) " ) ;
2015-03-27 19:40:16 +03:00
CHECK_WSTR ( tctx , notify . nttrans . out . changes [ 0 ] . name , " subdir-name " ,
2015-03-26 20:58:05 +03:00
STR_UNICODE ) ;
2009-03-10 07:12:48 +03:00
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing notify rmdir \n " ) ;
2009-03-10 07:12:48 +03:00
req = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
2018-09-08 01:14:37 +03:00
smbcli_rmdir ( cli - > tree , BASEDIR_CN1_NTCON " \\ subdir-name " ) ;
2009-03-10 07:12:48 +03:00
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req , tctx , & notify ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_changenotify_recv " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx , notify . nttrans . out . num_changes ,
2015-03-26 20:45:47 +03:00
1 , ret , done , " wrong number of changes " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-26 20:45:47 +03:00
notify . nttrans . out . changes [ 0 ] . action ,
NOTIFY_ACTION_REMOVED , ret , done ,
" wrong action (exp: REMOVED) " ) ;
2015-03-27 19:40:16 +03:00
CHECK_WSTR ( tctx , notify . nttrans . out . changes [ 0 ] . name , " subdir-name " ,
2015-03-26 20:58:05 +03:00
STR_UNICODE ) ;
2009-03-10 07:12:48 +03:00
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " SIMPLE CHANGE NOTIFY OK \n " ) ;
2009-03-10 07:12:48 +03:00
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " TESTING WITH SECONDARY TCON \n " ) ;
2015-03-27 19:40:16 +03:00
tree = secondary_tcon ( cli , tctx ) ;
torture_assert_not_null_goto ( tctx , tree , ret , done ,
2015-03-27 12:34:34 +03:00
" failed to create secondary tcon " ) ;
2009-03-10 07:12:48 +03:00
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing notify mkdir \n " ) ;
2009-03-10 07:12:48 +03:00
req = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
2018-09-08 01:14:37 +03:00
smbcli_mkdir ( cli - > tree , BASEDIR_CN1_NTCON " \\ subdir-name " ) ;
2009-03-10 07:12:48 +03:00
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req , tctx , & notify ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_changenotify_recv " ) ;
2009-03-10 07:12:48 +03:00
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx , notify . nttrans . out . num_changes ,
2015-03-26 20:45:47 +03:00
1 , ret , done , " wrong number of changes " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-26 20:45:47 +03:00
notify . nttrans . out . changes [ 0 ] . action ,
NOTIFY_ACTION_ADDED , ret , done ,
" wrong action (exp: ADDED) " ) ;
2015-03-27 19:40:16 +03:00
CHECK_WSTR ( tctx , notify . nttrans . out . changes [ 0 ] . name , " subdir-name " ,
2015-03-26 20:58:05 +03:00
STR_UNICODE ) ;
2009-03-10 07:12:48 +03:00
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing notify rmdir \n " ) ;
2009-03-10 07:12:48 +03:00
req = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
2018-09-08 01:14:37 +03:00
smbcli_rmdir ( cli - > tree , BASEDIR_CN1_NTCON " \\ subdir-name " ) ;
2009-03-10 07:12:48 +03:00
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req , tctx , & notify ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_changenotify_recv " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx , notify . nttrans . out . num_changes ,
2015-03-26 20:45:47 +03:00
1 , ret , done , " wrong number of changes " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-26 20:45:47 +03:00
notify . nttrans . out . changes [ 0 ] . action ,
NOTIFY_ACTION_REMOVED , ret , done ,
" wrong action (exp: REMOVED) " ) ;
2015-03-27 19:40:16 +03:00
CHECK_WSTR ( tctx , notify . nttrans . out . changes [ 0 ] . name , " subdir-name " ,
2015-03-26 20:58:05 +03:00
STR_UNICODE ) ;
2009-03-10 07:12:48 +03:00
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " CHANGE NOTIFY WITH TCON OK \n " ) ;
2009-03-10 07:12:48 +03:00
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Disconnecting secondary tree \n " ) ;
2009-03-10 07:12:48 +03:00
status = smb_tree_disconnect ( tree ) ;
2015-03-27 19:40:16 +03:00
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_tree_disconnect " ) ;
2009-03-10 07:12:48 +03:00
talloc_free ( tree ) ;
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing notify mkdir \n " ) ;
2009-03-10 07:12:48 +03:00
req = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
2018-09-08 01:14:37 +03:00
smbcli_mkdir ( cli - > tree , BASEDIR_CN1_NTCON " \\ subdir-name " ) ;
2009-03-10 07:12:48 +03:00
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req , tctx , & notify ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_changenotify_recv " ) ;
2009-03-10 07:12:48 +03:00
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx , notify . nttrans . out . num_changes ,
2015-03-26 20:45:47 +03:00
1 , ret , done , " wrong number of changes " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-26 20:45:47 +03:00
notify . nttrans . out . changes [ 0 ] . action ,
NOTIFY_ACTION_ADDED , ret , done ,
" wrong action (exp: ADDED) " ) ;
2015-03-27 19:40:16 +03:00
CHECK_WSTR ( tctx , notify . nttrans . out . changes [ 0 ] . name , " subdir-name " ,
2015-03-26 20:58:05 +03:00
STR_UNICODE ) ;
2009-03-10 07:12:48 +03:00
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " Testing notify rmdir \n " ) ;
2009-03-10 07:12:48 +03:00
req = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
2018-09-08 01:14:37 +03:00
smbcli_rmdir ( cli - > tree , BASEDIR_CN1_NTCON " \\ subdir-name " ) ;
2009-03-10 07:12:48 +03:00
2015-03-27 19:40:16 +03:00
status = smb_raw_changenotify_recv ( req , tctx , & notify ) ;
torture_assert_ntstatus_ok_goto ( tctx , status , ret , done ,
2015-03-26 14:00:15 +03:00
" smb_raw_changenotify_recv " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx , notify . nttrans . out . num_changes ,
2015-03-26 20:45:47 +03:00
1 , ret , done , " wrong number of changes " ) ;
2015-03-27 19:40:16 +03:00
torture_assert_int_equal_goto ( tctx ,
2015-03-26 20:45:47 +03:00
notify . nttrans . out . changes [ 0 ] . action ,
NOTIFY_ACTION_REMOVED , ret , done ,
" wrong action (exp: REMOVED) " ) ;
2015-03-27 19:40:16 +03:00
CHECK_WSTR ( tctx , notify . nttrans . out . changes [ 0 ] . name , " subdir-name " ,
2015-03-26 20:58:05 +03:00
STR_UNICODE ) ;
2009-03-10 07:12:48 +03:00
2015-03-27 19:47:42 +03:00
torture_comment ( tctx , " CHANGE NOTIFY WITH TDIS OK \n " ) ;
2009-03-10 07:12:48 +03:00
done :
smb_raw_exit ( cli - > session ) ;
2018-09-08 01:14:37 +03:00
smbcli_deltree ( cli - > tree , BASEDIR_CN1_NTCON ) ;
2009-03-10 07:12:48 +03:00
return ret ;
}
2018-09-11 01:35:03 +03:00
struct cb_data {
struct smbcli_request * req ;
bool timed_out ;
} ;
static void timeout_cb ( struct tevent_context * ev ,
struct tevent_timer * te ,
struct timeval current_time ,
void * private_data )
{
struct cb_data * cbp = ( struct cb_data * ) private_data ;
cbp - > req - > state = SMBCLI_REQUEST_ERROR ;
cbp - > timed_out = true ;
}
2009-03-10 07:12:48 +03:00
2010-06-29 03:06:33 +04:00
/*
testing alignment of multiple change notify infos
*/
2018-09-08 01:14:37 +03:00
# define BASEDIR_CN1_NALIGN BASEDIR "_CN1_NALIGN"
2012-04-18 14:56:39 +04:00
static bool test_notify_alignment ( struct torture_context * tctx ,
struct smbcli_state * cli )
2010-06-29 03:06:33 +04:00
{
NTSTATUS status ;
union smb_notify notify ;
union smb_open io ;
2018-09-11 01:35:03 +03:00
int fnum , fnum2 ;
2010-06-29 03:06:33 +04:00
struct smbcli_request * req ;
2018-09-08 01:14:37 +03:00
const char * fname = BASEDIR_CN1_NALIGN " \\ starter " ;
2010-06-29 03:06:33 +04:00
const char * fnames [ ] = { " a " ,
" ab " ,
" abc " ,
" abcd " } ;
2018-09-11 01:35:03 +03:00
bool fnames_received [ ] = { false ,
false ,
false ,
false } ;
size_t total_names_received = 0 ;
size_t num_names = ARRAY_SIZE ( fnames ) ;
size_t i ;
2010-08-27 00:43:05 +04:00
char * fpath = NULL ;
2010-06-29 03:06:33 +04:00
torture_comment ( tctx , " TESTING CHANGE NOTIFY REPLY ALIGNMENT \n " ) ;
2018-09-08 01:14:37 +03:00
torture_assert ( tctx , torture_setup_dir ( cli , BASEDIR_CN1_NALIGN ) ,
" Failed to setup up test directory: " BASEDIR_CN1_NALIGN ) ;
2012-04-18 14:56:39 +04:00
2010-06-29 03:06:33 +04:00
/* get a handle on the directory */
io . generic . level = RAW_OPEN_NTCREATEX ;
io . ntcreatex . in . root_fid . fnum = 0 ;
io . ntcreatex . in . flags = 0 ;
io . ntcreatex . in . access_mask = SEC_FILE_ALL ;
io . ntcreatex . in . create_options = NTCREATEX_OPTIONS_DIRECTORY ;
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_OPEN ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
2018-09-08 01:14:37 +03:00
io . ntcreatex . in . fname = BASEDIR_CN1_NALIGN ;
2010-06-29 03:06:33 +04:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2015-03-26 21:13:58 +03:00
torture_assert_ntstatus_ok ( tctx , status , " smb_raw_open " ) ;
2010-06-29 03:06:33 +04:00
fnum = io . ntcreatex . out . file . fnum ;
/* ask for a change notify, on file creation */
notify . nttrans . level = RAW_NOTIFY_NTTRANS ;
notify . nttrans . in . buffer_size = 1000 ;
notify . nttrans . in . completion_filter = FILE_NOTIFY_CHANGE_FILE_NAME ;
notify . nttrans . in . file . fnum = fnum ;
notify . nttrans . in . recursive = false ;
/* start change tracking */
req = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
fnum2 = smbcli_open ( cli - > tree , fname , O_CREAT | O_RDWR , DENY_NONE ) ;
torture_assert ( tctx , fnum2 ! = - 1 , smbcli_errstr ( cli - > tree ) ) ;
smbcli_close ( cli - > tree , fnum2 ) ;
status = smb_raw_changenotify_recv ( req , tctx , & notify ) ;
2015-03-26 21:13:58 +03:00
torture_assert_ntstatus_ok ( tctx , status , " smb_raw_changenotify_recv " ) ;
2010-06-29 03:06:33 +04:00
/* create 4 files that will cause CHANGE_NOTIFY_INFO structures
* to be returned in the same packet with all possible 4 - byte padding
* permutations . As per MS - CIFS 2.2 .7 .4 .2 these structures should be
* 4 - byte aligned . */
for ( i = 0 ; i < num_names ; i + + ) {
2018-09-08 01:14:37 +03:00
fpath = talloc_asprintf ( tctx , " %s \\ %s " ,
BASEDIR_CN1_NALIGN , fnames [ i ] ) ;
2010-06-29 03:06:33 +04:00
fnum2 = smbcli_open ( cli - > tree , fpath ,
O_CREAT | O_RDWR , DENY_NONE ) ;
torture_assert ( tctx , fnum2 ! = - 1 , smbcli_errstr ( cli - > tree ) ) ;
smbcli_close ( cli - > tree , fnum2 ) ;
talloc_free ( fpath ) ;
}
2018-09-11 01:35:03 +03:00
/*
* Slow cloud filesystems mean we might
* not get everything in one go . Keep going
* until we get them all .
*/
while ( total_names_received < num_names ) {
struct tevent_timer * te = NULL ;
struct cb_data to_data = { 0 } ;
2010-06-29 03:06:33 +04:00
2018-09-11 01:35:03 +03:00
/*
* We send a notify packet , and let
* smb_raw_changenotify_recv ( ) do
* the alignment checking for us .
*/
req = smb_raw_changenotify_send ( cli - > tree , & notify ) ;
torture_assert ( tctx ,
req ! = NULL ,
" smb_raw_changenotify_send failed \n " ) ;
/* Ensure we don't wait more than 30 seconds. */
to_data . req = req ;
to_data . timed_out = false ;
te = tevent_add_timer ( tctx - > ev ,
req ,
tevent_timeval_current_ofs ( 30 , 0 ) ,
timeout_cb ,
& to_data ) ;
if ( te = = NULL ) {
torture_fail ( tctx , " tevent_add_timer fail \n " ) ;
}
status = smb_raw_changenotify_recv ( req , tctx , & notify ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
if ( to_data . timed_out = = true ) {
torture_fail ( tctx , " smb_raw_changenotify_recv "
" timed out \n " ) ;
}
}
torture_assert_ntstatus_ok ( tctx , status ,
" smb_raw_changenotify_recv " ) ;
for ( i = 0 ; i < notify . nttrans . out . num_changes ; i + + ) {
size_t j ;
/* Ensure it was an 'add'. */
torture_assert ( tctx ,
notify . nttrans . out . changes [ i ] . action = =
NOTIFY_ACTION_ADDED ,
" " ) ;
for ( j = 0 ; j < num_names ; j + + ) {
if ( strcmp ( notify . nttrans . out . changes [ i ] . name . s ,
fnames [ j ] ) = = 0 ) {
if ( fnames_received [ j ] = = true ) {
const char * err =
talloc_asprintf ( tctx ,
" Duplicate "
" name %s \n " ,
fnames [ j ] ) ;
if ( err = = NULL ) {
torture_fail ( tctx ,
" talloc "
" fail \n " ) ;
}
/* already got this. */
torture_fail ( tctx , err ) ;
}
fnames_received [ j ] = true ;
break ;
}
}
if ( j = = num_names ) {
/* No name match. */
const char * err = talloc_asprintf ( tctx ,
" Unexpected name %s \n " ,
notify . nttrans . out . changes [ i ] . name . s ) ;
if ( err = = NULL ) {
torture_fail ( tctx , " talloc fail \n " ) ;
}
torture_fail ( tctx , err ) ;
}
total_names_received + + ;
}
2010-06-29 03:06:33 +04:00
}
2012-04-18 14:56:39 +04:00
smb_raw_exit ( cli - > session ) ;
2018-09-08 01:14:37 +03:00
smbcli_deltree ( cli - > tree , BASEDIR_CN1_NALIGN ) ;
2010-06-29 03:06:33 +04:00
return true ;
}
2012-04-18 13:43:12 +04:00
struct torture_suite * torture_raw_notify ( TALLOC_CTX * mem_ctx )
{
struct torture_suite * suite = torture_suite_create ( mem_ctx , " notify " ) ;
2012-04-18 13:47:48 +04:00
torture_suite_add_1smb_test ( suite , " tcon " , test_notify_tcon ) ;
2012-04-18 14:19:12 +04:00
torture_suite_add_2smb_test ( suite , " dir " , test_notify_dir ) ;
2012-04-18 16:45:20 +04:00
torture_suite_add_2smb_test ( suite , " mask " , test_notify_mask ) ;
2012-04-18 16:45:20 +04:00
torture_suite_add_2smb_test ( suite , " recursive " , test_notify_recursive ) ;
2012-04-18 14:27:38 +04:00
torture_suite_add_1smb_test ( suite , " mask_change " ,
test_notify_mask_change ) ;
2012-04-18 14:31:12 +04:00
torture_suite_add_1smb_test ( suite , " file " , test_notify_file ) ;
2012-04-18 14:39:08 +04:00
torture_suite_add_1smb_test ( suite , " tdis " , test_notify_tdis ) ;
2012-04-18 14:42:13 +04:00
torture_suite_add_1smb_test ( suite , " exit " , test_notify_exit ) ;
2012-04-18 14:44:21 +04:00
torture_suite_add_1smb_test ( suite , " ulogoff " , test_notify_ulogoff ) ;
2012-04-18 14:47:39 +04:00
torture_suite_add_1smb_test ( suite , " tcp_dis " , test_notify_tcp_dis ) ;
2012-04-18 14:49:55 +04:00
torture_suite_add_1smb_test ( suite , " double " , test_notify_double ) ;
2012-04-18 16:45:20 +04:00
torture_suite_add_2smb_test ( suite , " tree " , test_notify_tree ) ;
2012-04-18 14:53:08 +04:00
torture_suite_add_1smb_test ( suite , " overflow " , test_notify_overflow ) ;
2012-04-18 14:54:25 +04:00
torture_suite_add_1smb_test ( suite , " basedir " , test_notify_basedir ) ;
2012-04-18 14:56:39 +04:00
torture_suite_add_1smb_test ( suite , " alignment " , test_notify_alignment ) ;
2012-04-18 13:43:12 +04:00
return suite ;
}