2004-10-25 11:24:46 +04:00
/*
Unix SMB / CIFS implementation .
directory scanning tests
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
2004-10-25 11:24:46 +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/>.
2004-10-25 11:24:46 +04:00
*/
# include "includes.h"
2006-01-03 18:40:05 +03:00
# include "libcli/libcli.h"
2006-03-17 20:59:58 +03:00
# include "torture/util.h"
2005-02-10 08:09:35 +03:00
# include "system/filesys.h"
2011-03-19 02:42:52 +03:00
# include "torture/basic/proto.h"
2004-10-25 11:24:46 +04:00
2004-11-30 08:37:57 +03:00
static void list_fn ( struct clilist_file_info * finfo , const char * name , void * state )
2004-10-25 11:24:46 +04:00
{
}
/*
test directory listing speed
*/
2007-09-07 19:08:14 +04:00
bool torture_dirtest1 ( struct torture_context * tctx ,
struct smbcli_state * cli )
2004-10-25 11:24:46 +04:00
{
int i ;
int fnum ;
2007-10-07 02:28:14 +04:00
bool correct = true ;
2004-10-25 11:24:46 +04:00
extern int torture_numops ;
2004-11-03 13:09:48 +03:00
struct timeval tv ;
2016-04-05 19:19:30 +03:00
int ret ;
2004-10-25 11:24:46 +04:00
2006-10-16 17:06:41 +04:00
torture_comment ( tctx , " Creating %d random filenames \n " , torture_numops ) ;
2004-10-25 11:24:46 +04:00
srandom ( 0 ) ;
2004-11-03 13:09:48 +03:00
tv = timeval_current ( ) ;
2004-10-25 11:24:46 +04:00
for ( i = 0 ; i < torture_numops ; i + + ) {
char * fname ;
2016-04-05 19:19:30 +03:00
ret = asprintf ( & fname , " \\ %x " , ( int ) random ( ) ) ;
torture_assert ( tctx , ret ! = - 1 , " asprintf failed " ) ;
2004-10-25 11:24:46 +04:00
fnum = smbcli_open ( cli - > tree , fname , O_RDWR | O_CREAT , DENY_NONE ) ;
if ( fnum = = - 1 ) {
2004-10-25 11:58:47 +04:00
fprintf ( stderr , " (%s) Failed to open %s \n " ,
__location__ , fname ) ;
2007-10-07 02:28:14 +04:00
return false ;
2004-10-25 11:24:46 +04:00
}
smbcli_close ( cli - > tree , fnum ) ;
free ( fname ) ;
}
2006-10-16 17:06:41 +04:00
torture_comment ( tctx , " Matched %d \n " , smbcli_list ( cli - > tree , " a*.* " , 0 , list_fn , NULL ) ) ;
torture_comment ( tctx , " Matched %d \n " , smbcli_list ( cli - > tree , " b*.* " , 0 , list_fn , NULL ) ) ;
torture_comment ( tctx , " Matched %d \n " , smbcli_list ( cli - > tree , " xyzabc " , 0 , list_fn , NULL ) ) ;
2004-10-25 11:24:46 +04:00
2006-10-16 17:06:41 +04:00
torture_comment ( tctx , " dirtest core %g seconds \n " , timeval_elapsed ( & tv ) ) ;
2004-10-25 11:24:46 +04:00
srandom ( 0 ) ;
for ( i = 0 ; i < torture_numops ; i + + ) {
char * fname ;
2016-04-05 19:19:30 +03:00
ret = asprintf ( & fname , " \\ %x " , ( int ) random ( ) ) ;
torture_assert ( tctx , ret ! = - 1 , " asprintf failed " ) ;
2004-10-25 11:24:46 +04:00
smbcli_unlink ( cli - > tree , fname ) ;
free ( fname ) ;
}
return correct ;
}
2007-09-07 19:08:14 +04:00
bool torture_dirtest2 ( struct torture_context * tctx ,
struct smbcli_state * cli )
2004-10-25 11:24:46 +04:00
{
int i ;
int fnum , num_seen ;
2007-10-07 02:28:14 +04:00
bool correct = true ;
2004-10-25 11:24:46 +04:00
extern int torture_entries ;
2016-04-05 19:19:30 +03:00
int ret ;
2004-10-25 11:24:46 +04:00
2004-11-12 12:37:59 +03:00
if ( ! torture_setup_dir ( cli , " \\ LISTDIR " ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2004-10-25 11:24:46 +04:00
}
2006-10-16 17:06:41 +04:00
torture_comment ( tctx , " Creating %d files \n " , torture_entries ) ;
2004-10-25 11:24:46 +04:00
/* Create torture_entries files and torture_entries directories. */
for ( i = 0 ; i < torture_entries ; i + + ) {
char * fname ;
2016-04-05 19:19:30 +03:00
ret = asprintf ( & fname , " \\ LISTDIR \\ f%d " , i ) ;
torture_assert ( tctx , ret ! = - 1 , " asprintf failed " ) ;
2004-11-30 07:33:27 +03:00
fnum = smbcli_nt_create_full ( cli - > tree , fname , 0 ,
2004-12-02 07:37:36 +03:00
SEC_RIGHTS_FILE_ALL ,
2004-11-30 07:33:27 +03:00
FILE_ATTRIBUTE_ARCHIVE ,
NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE ,
NTCREATEX_DISP_OVERWRITE_IF , 0 , 0 ) ;
2004-10-25 11:24:46 +04:00
if ( fnum = = - 1 ) {
2004-10-25 11:58:47 +04:00
fprintf ( stderr , " (%s) Failed to open %s, error=%s \n " ,
__location__ , fname , smbcli_errstr ( cli - > tree ) ) ;
2007-10-07 02:28:14 +04:00
return false ;
2004-10-25 11:24:46 +04:00
}
free ( fname ) ;
smbcli_close ( cli - > tree , fnum ) ;
}
for ( i = 0 ; i < torture_entries ; i + + ) {
char * fname ;
2016-04-05 19:19:30 +03:00
ret = asprintf ( & fname , " \\ LISTDIR \\ d%d " , i ) ;
torture_assert ( tctx , ret ! = - 1 , " asprintf failed " ) ;
2004-10-25 11:24:46 +04:00
if ( NT_STATUS_IS_ERR ( smbcli_mkdir ( cli - > tree , fname ) ) ) {
2004-10-25 11:58:47 +04:00
fprintf ( stderr , " (%s) Failed to open %s, error=%s \n " ,
__location__ , fname , smbcli_errstr ( cli - > tree ) ) ;
2007-10-07 02:28:14 +04:00
return false ;
2004-10-25 11:24:46 +04:00
}
free ( fname ) ;
}
/* Now ensure that doing an old list sees both files and directories. */
num_seen = smbcli_list_old ( cli - > tree , " \\ LISTDIR \\ * " , FILE_ATTRIBUTE_DIRECTORY , list_fn , NULL ) ;
2006-10-16 17:06:41 +04:00
torture_comment ( tctx , " num_seen = %d \n " , num_seen ) ;
2004-10-25 11:24:46 +04:00
/* We should see (torture_entries) each of files & directories + . and .. */
if ( num_seen ! = ( 2 * torture_entries ) + 2 ) {
2007-10-07 02:28:14 +04:00
correct = false ;
2004-10-25 11:58:47 +04:00
fprintf ( stderr , " (%s) entry count mismatch, should be %d, was %d \n " ,
__location__ , ( 2 * torture_entries ) + 2 , num_seen ) ;
2004-10-25 11:24:46 +04:00
}
/* Ensure if we have the "must have" bits we only see the
* relevant entries .
*/
num_seen = smbcli_list_old ( cli - > tree , " \\ LISTDIR \\ * " , ( FILE_ATTRIBUTE_DIRECTORY < < 8 ) | FILE_ATTRIBUTE_DIRECTORY , list_fn , NULL ) ;
2006-10-16 17:06:41 +04:00
torture_comment ( tctx , " num_seen = %d \n " , num_seen ) ;
2004-10-25 11:24:46 +04:00
if ( num_seen ! = torture_entries + 2 ) {
2007-10-07 02:28:14 +04:00
correct = false ;
2004-10-25 11:58:47 +04:00
fprintf ( stderr , " (%s) entry count mismatch, should be %d, was %d \n " ,
__location__ , torture_entries + 2 , num_seen ) ;
2004-10-25 11:24:46 +04:00
}
num_seen = smbcli_list_old ( cli - > tree , " \\ LISTDIR \\ * " , ( FILE_ATTRIBUTE_ARCHIVE < < 8 ) | FILE_ATTRIBUTE_DIRECTORY , list_fn , NULL ) ;
2006-10-16 17:06:41 +04:00
torture_comment ( tctx , " num_seen = %d \n " , num_seen ) ;
2004-10-25 11:24:46 +04:00
if ( num_seen ! = torture_entries ) {
2007-10-07 02:28:14 +04:00
correct = false ;
2004-10-25 11:58:47 +04:00
fprintf ( stderr , " (%s) entry count mismatch, should be %d, was %d \n " ,
__location__ , torture_entries , num_seen ) ;
2004-10-25 11:24:46 +04:00
}
/* Delete everything. */
if ( smbcli_deltree ( cli - > tree , " \\ LISTDIR " ) = = - 1 ) {
2004-10-25 11:58:47 +04:00
fprintf ( stderr , " (%s) Failed to deltree %s, error=%s \n " , " \\ LISTDIR " ,
__location__ , smbcli_errstr ( cli - > tree ) ) ;
2007-10-07 02:28:14 +04:00
return false ;
2004-10-25 11:24:46 +04:00
}
#if 0
2006-10-16 17:06:41 +04:00
torture_comment ( tctx , " Matched %d \n " , smbcli_list ( cli - > tree , " a*.* " , 0 , list_fn , NULL ) ) ;
torture_comment ( tctx , " Matched %d \n " , smbcli_list ( cli - > tree , " b*.* " , 0 , list_fn , NULL ) ) ;
torture_comment ( tctx , " Matched %d \n " , smbcli_list ( cli - > tree , " xyzabc " , 0 , list_fn , NULL ) ) ;
2004-10-25 11:24:46 +04:00
# endif
return correct ;
}