2000-02-09 17:10:08 +03:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
2000-02-09 17:10:08 +03:00
mask_match tester
Copyright ( C ) Andrew Tridgell 1999
2011-05-28 22:24:01 +04:00
2000-02-09 17:10:08 +03:00
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-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
2000-02-09 17:10:08 +03:00
( at your option ) any later version .
2011-05-28 22:24:01 +04:00
2000-02-09 17:10:08 +03:00
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 .
2011-05-28 22:24:01 +04:00
2000-02-09 17:10:08 +03:00
You should have received a copy of the GNU General Public License
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2000-02-09 17:10:08 +03:00
*/
# include "includes.h"
2011-02-26 01:20:06 +03:00
# include "system/filesys.h"
2011-02-25 02:03:01 +03:00
# include "trans2.h"
2011-05-06 13:47:43 +04:00
# include "libsmb/libsmb.h"
2011-03-23 16:18:59 +03:00
# include "libsmb/nmblib.h"
2012-05-19 20:09:30 +04:00
# include "../libcli/smb/smbXcli_base.h"
2000-02-09 17:10:08 +03:00
static fstring password ;
static fstring username ;
static int got_pass ;
2016-10-28 13:42:01 +03:00
static struct cli_credentials * test_creds ;
2013-08-11 15:10:13 +04:00
static int max_protocol = - 1 ;
2007-10-19 04:40:25 +04:00
static bool showall = False ;
static bool old_list = False ;
2003-01-03 11:28:12 +03:00
static const char * maskchars = " <> \" ?*abc. " ;
static const char * filechars = " abcdefghijklm. " ;
2001-02-27 07:18:12 +03:00
static int verbose ;
2001-03-21 09:44:49 +03:00
static int die_on_error ;
2002-03-22 03:09:09 +03:00
static int NumLoops = 0 ;
2003-04-23 12:12:34 +04:00
static int ignore_dot_errors = 0 ;
2000-02-09 17:10:08 +03:00
2006-12-18 23:37:26 +03:00
extern char * optarg ;
extern int optind ;
2001-02-26 02:47:27 +03:00
/* a test fn for LANMAN mask support */
2006-12-19 23:16:52 +03:00
static int ms_fnmatch_lanman_core ( const char * pattern , const char * string )
2000-02-09 17:10:08 +03:00
{
2003-01-03 11:28:12 +03:00
const char * p = pattern , * n = string ;
2001-02-26 02:47:27 +03:00
char c ;
2001-02-27 15:04:49 +03:00
if ( strcmp ( p , " ? " ) = = 0 & & strcmp ( n , " . " ) = = 0 ) goto match ;
2001-02-27 09:11:59 +03:00
2001-02-26 02:47:27 +03:00
while ( ( c = * p + + ) ) {
switch ( c ) {
2001-02-27 15:04:49 +03:00
case ' . ' :
2001-03-21 08:54:09 +03:00
/* if (! *n && ! *p) goto match; */
2001-02-27 15:04:49 +03:00
if ( * n ! = ' . ' ) goto nomatch ;
n + + ;
break ;
2001-02-26 02:47:27 +03:00
case ' ? ' :
2001-02-27 15:04:49 +03:00
if ( ( * n = = ' . ' & & n [ 1 ] ! = ' . ' ) | | ! * n ) goto next ;
2001-02-26 02:47:27 +03:00
n + + ;
break ;
case ' > ' :
if ( n [ 0 ] = = ' . ' ) {
2001-02-27 07:18:12 +03:00
if ( ! n [ 1 ] & & ms_fnmatch_lanman_core ( p , n + 1 ) = = 0 ) goto match ;
if ( ms_fnmatch_lanman_core ( p , n ) = = 0 ) goto match ;
goto nomatch ;
2001-02-26 02:47:27 +03:00
}
2001-02-27 15:04:49 +03:00
if ( ! * n ) goto next ;
2001-02-26 02:47:27 +03:00
n + + ;
break ;
2000-02-09 17:10:08 +03:00
2001-02-26 02:47:27 +03:00
case ' * ' :
2001-02-27 07:18:12 +03:00
if ( ! * p ) goto match ;
2001-02-26 02:47:27 +03:00
for ( ; * n ; n + + ) {
2001-02-27 07:18:12 +03:00
if ( ms_fnmatch_lanman_core ( p , n ) = = 0 ) goto match ;
2001-02-26 02:47:27 +03:00
}
break ;
case ' < ' :
for ( ; * n ; n + + ) {
2001-02-27 07:18:12 +03:00
if ( ms_fnmatch_lanman_core ( p , n ) = = 0 ) goto match ;
2001-07-04 11:36:09 +04:00
if ( * n = = ' . ' & & ! strchr_m ( n + 1 , ' . ' ) ) {
2001-02-26 02:47:27 +03:00
n + + ;
break ;
}
}
break ;
case ' " ' :
2001-02-27 07:18:12 +03:00
if ( * n = = 0 & & ms_fnmatch_lanman_core ( p , n ) = = 0 ) goto match ;
if ( * n ! = ' . ' ) goto nomatch ;
2001-02-26 02:47:27 +03:00
n + + ;
break ;
default :
2001-02-27 07:18:12 +03:00
if ( c ! = * n ) goto nomatch ;
2001-02-26 02:47:27 +03:00
n + + ;
}
}
2007-12-05 05:02:06 +03:00
2001-02-27 07:18:12 +03:00
if ( ! * n ) goto match ;
2007-12-05 05:02:06 +03:00
2001-02-27 07:18:12 +03:00
nomatch :
if ( verbose ) printf ( " NOMATCH pattern=[%s] string=[%s] \n " , pattern , string ) ;
2001-02-26 02:47:27 +03:00
return - 1 ;
2001-02-27 07:18:12 +03:00
2001-02-27 15:04:49 +03:00
next :
if ( ms_fnmatch_lanman_core ( p , n ) = = 0 ) goto match ;
goto nomatch ;
2001-02-27 07:18:12 +03:00
match :
if ( verbose ) printf ( " MATCH pattern=[%s] string=[%s] \n " , pattern , string ) ;
return 0 ;
2001-02-26 02:47:27 +03:00
}
2006-12-19 23:16:52 +03:00
static int ms_fnmatch_lanman ( const char * pattern , const char * string )
2001-02-26 02:47:27 +03:00
{
2001-02-27 15:04:49 +03:00
if ( ! strpbrk ( pattern , " ?*<> \" " ) ) {
2003-01-03 11:28:12 +03:00
if ( strcmp ( string , " .. " ) = = 0 )
string = " . " ;
2001-02-27 15:04:49 +03:00
return strcmp ( pattern , string ) ;
2001-02-27 09:11:59 +03:00
}
2001-03-21 08:54:09 +03:00
if ( strcmp ( string , " .. " ) = = 0 | | strcmp ( string , " . " ) = = 0 ) {
return ms_fnmatch_lanman_core ( pattern , " .. " ) & &
ms_fnmatch_lanman_core ( pattern , " . " ) ;
}
2001-02-27 15:04:49 +03:00
return ms_fnmatch_lanman_core ( pattern , string ) ;
2001-02-26 02:47:27 +03:00
}
2007-10-19 04:40:25 +04:00
static bool reg_match_one ( struct cli_state * cli , const char * pattern , const char * file )
2001-02-26 02:47:27 +03:00
{
2000-04-30 18:37:57 +04:00
/* oh what a weird world this is */
if ( old_list & & strcmp ( pattern , " *.* " ) = = 0 ) return True ;
2001-02-26 09:53:42 +03:00
if ( strcmp ( pattern , " . " ) = = 0 ) return False ;
2001-02-26 02:47:27 +03:00
if ( max_protocol < = PROTOCOL_LANMAN2 ) {
return ms_fnmatch_lanman ( pattern , file ) = = 0 ;
}
2001-03-21 08:54:09 +03:00
if ( strcmp ( file , " .. " ) = = 0 ) file = " . " ;
2012-05-19 20:09:30 +04:00
return ms_fnmatch ( pattern , file , smbXcli_conn_protocol ( cli - > conn ) , False ) = = 0 ;
2000-02-09 17:10:08 +03:00
}
2007-12-05 05:02:06 +03:00
static char * reg_test ( struct cli_state * cli , const char * pattern , const char * long_name , const char * short_name )
2000-02-10 16:43:59 +03:00
{
static fstring ret ;
2007-12-05 05:02:06 +03:00
const char * new_pattern = 1 + strrchr_m ( pattern , ' \\ ' ) ;
2000-02-10 16:43:59 +03:00
2007-12-05 05:02:06 +03:00
fstrcpy ( ret , " --- " ) ;
if ( reg_match_one ( cli , new_pattern , " . " ) ) ret [ 0 ] = ' + ' ;
if ( reg_match_one ( cli , new_pattern , " .. " ) ) ret [ 1 ] = ' + ' ;
if ( reg_match_one ( cli , new_pattern , long_name ) | |
( * short_name & & reg_match_one ( cli , new_pattern , short_name ) ) ) ret [ 2 ] = ' + ' ;
2000-02-10 16:43:59 +03:00
return ret ;
}
2000-02-09 17:10:08 +03:00
/*****************************************************
return a connection to a server
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-12-19 23:16:52 +03:00
static struct cli_state * connect_one ( char * share )
2000-02-09 17:10:08 +03:00
{
struct cli_state * c ;
char * server_n ;
char * server ;
2007-06-20 21:38:42 +04:00
NTSTATUS status ;
2000-02-09 17:10:08 +03:00
server = share + 2 ;
2001-07-04 11:36:09 +04:00
share = strchr_m ( server , ' \\ ' ) ;
2000-02-09 17:10:08 +03:00
if ( ! share ) return NULL ;
* share = 0 ;
share + + ;
server_n = server ;
2007-10-25 01:16:54 +04:00
2011-11-02 21:41:50 +04:00
status = cli_connect_nb ( server , NULL , 0 , 0x20 , " masktest " ,
SMB_SIGNING_DEFAULT , 0 , & c ) ;
2007-06-20 21:38:42 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-05-28 22:26:49 +04:00
DEBUG ( 0 , ( " Connection to %s failed. Error %s \n " , server_n ,
nt_errstr ( status ) ) ) ;
2007-06-20 21:38:42 +04:00
return NULL ;
}
2012-05-20 19:54:29 +04:00
status = smbXcli_negprot ( c - > conn , c - > timeout , PROTOCOL_CORE ,
max_protocol ) ;
2008-09-11 20:57:49 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 0 , ( " protocol negotiation failed: %s \n " ,
nt_errstr ( status ) ) ) ;
2000-02-09 17:10:08 +03:00
cli_shutdown ( c ) ;
return NULL ;
}
2016-10-28 13:42:01 +03:00
status = cli_session_setup_creds ( c , test_creds ) ;
2011-01-20 16:08:42 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 0 , ( " session setup failed: %s \n " , nt_errstr ( status ) ) ) ;
2000-02-09 17:10:08 +03:00
return NULL ;
}
/*
* These next two lines are needed to emulate
* old client behaviour for people who have
* scripts based on client output .
* QUESTION ? Do we want to have a ' client compatibility
* mode to turn these on / off ? JRA .
*/
if ( * c - > server_domain | | * c - > server_os | | * c - > server_type )
DEBUG ( 1 , ( " Domain=[%s] OS=[%s] Server=[%s] \n " ,
c - > server_domain , c - > server_os , c - > server_type ) ) ;
2007-12-05 05:02:06 +03:00
2000-02-09 17:10:08 +03:00
DEBUG ( 4 , ( " session setup ok \n " ) ) ;
2016-12-09 11:49:17 +03:00
status = cli_tree_connect_creds ( c , share , " ????? " , test_creds ) ;
2009-01-26 10:37:13 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 0 , ( " tree connect failed: %s \n " , nt_errstr ( status ) ) ) ;
2000-02-09 17:10:08 +03:00
cli_shutdown ( c ) ;
return NULL ;
}
DEBUG ( 4 , ( " tconx ok \n " ) ) ;
return c ;
}
static char * resultp ;
2010-08-10 09:44:15 +04:00
struct rn_state {
char * * pp_long_name ;
char * short_name ;
} ;
2000-02-09 17:10:08 +03:00
2010-10-29 22:56:51 +04:00
static NTSTATUS listfn ( const char * mnt , struct file_info * f , const char * s ,
2010-08-10 09:44:15 +04:00
void * private_data )
2000-02-09 17:10:08 +03:00
{
2010-08-10 09:44:15 +04:00
struct rn_state * state = ( struct rn_state * ) private_data ;
2000-02-09 17:10:08 +03:00
if ( strcmp ( f - > name , " . " ) = = 0 ) {
resultp [ 0 ] = ' + ' ;
} else if ( strcmp ( f - > name , " .. " ) = = 0 ) {
2007-12-05 05:02:06 +03:00
resultp [ 1 ] = ' + ' ;
2000-02-09 17:10:08 +03:00
} else {
resultp [ 2 ] = ' + ' ;
}
2010-08-10 09:44:15 +04:00
2010-10-29 22:56:51 +04:00
if ( state = = NULL ) {
return NT_STATUS_INTERNAL_ERROR ;
}
if ( ISDOT ( f - > name ) | | ISDOTDOT ( f - > name ) ) {
return NT_STATUS_OK ;
2010-08-10 09:44:15 +04:00
}
2011-07-06 20:57:27 +04:00
fstrcpy ( state - > short_name , f - > short_name ? f - > short_name : " " ) ;
2012-08-09 04:01:00 +04:00
( void ) strlower_m ( state - > short_name ) ;
2010-08-10 09:44:15 +04:00
* state - > pp_long_name = SMB_STRDUP ( f - > name ) ;
if ( ! * state - > pp_long_name ) {
2010-10-29 22:56:51 +04:00
return NT_STATUS_NO_MEMORY ;
2010-08-10 09:44:15 +04:00
}
2012-08-09 04:01:00 +04:00
( void ) strlower_m ( * state - > pp_long_name ) ;
2010-10-29 22:56:51 +04:00
return NT_STATUS_OK ;
2000-02-09 17:10:08 +03:00
}
2007-12-05 05:02:06 +03:00
static void get_real_name ( struct cli_state * cli ,
char * * pp_long_name , fstring short_name )
2000-05-24 09:56:34 +04:00
{
2010-08-10 09:44:15 +04:00
struct rn_state state ;
state . pp_long_name = pp_long_name ;
state . short_name = short_name ;
2007-12-05 05:02:06 +03:00
* pp_long_name = NULL ;
2001-02-26 09:53:42 +03:00
/* nasty hack to force level 260 listings - tridge */
2001-02-26 08:13:19 +03:00
if ( max_protocol < = PROTOCOL_LANMAN1 ) {
2011-04-29 05:57:02 +04:00
cli_list_trans ( cli , " \\ masktest \\ *.* " , FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_DIRECTORY ,
2010-08-10 09:44:15 +04:00
SMB_FIND_FILE_BOTH_DIRECTORY_INFO , listfn ,
& state ) ;
2001-02-26 08:13:19 +03:00
} else {
2011-04-29 05:57:02 +04:00
cli_list_trans ( cli , " \\ masktest \\ * " , FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_DIRECTORY ,
2010-08-10 09:44:15 +04:00
SMB_FIND_FILE_BOTH_DIRECTORY_INFO ,
listfn , & state ) ;
2000-05-24 09:56:34 +04:00
}
2001-03-21 08:54:09 +03:00
if ( * short_name = = 0 ) {
2007-12-05 05:02:06 +03:00
fstrcpy ( short_name , * pp_long_name ) ;
2001-03-21 08:54:09 +03:00
}
#if 0
2001-07-04 11:36:09 +04:00
if ( ! strchr_m ( short_name , ' . ' ) ) {
2001-03-21 08:54:09 +03:00
fstrcat ( short_name , " . " ) ;
}
# endif
2000-05-24 09:56:34 +04:00
}
2000-02-09 17:10:08 +03:00
2007-12-05 05:02:06 +03:00
static void testpair ( struct cli_state * cli , const char * mask , const char * file )
2000-02-09 17:10:08 +03:00
{
2009-05-01 02:26:43 +04:00
uint16_t fnum ;
2000-04-30 15:11:19 +04:00
fstring res1 ;
char * res2 ;
2000-02-09 17:10:08 +03:00
static int count ;
2000-04-30 08:45:16 +04:00
fstring short_name ;
2007-12-05 05:02:06 +03:00
char * long_name = NULL ;
2000-02-09 17:10:08 +03:00
count + + ;
fstrcpy ( res1 , " --- " ) ;
2000-04-30 08:45:16 +04:00
2011-12-04 09:13:08 +04:00
if ( ! NT_STATUS_IS_OK ( cli_openx ( cli , file , O_CREAT | O_TRUNC | O_RDWR , 0 , & fnum ) ) ) {
2000-04-30 15:11:19 +04:00
DEBUG ( 0 , ( " Can't create %s \n " , file ) ) ;
2000-02-09 17:10:08 +03:00
return ;
}
2000-04-30 15:11:19 +04:00
cli_close ( cli , fnum ) ;
2000-02-09 17:10:08 +03:00
resultp = res1 ;
2000-04-30 08:45:16 +04:00
fstrcpy ( short_name , " " ) ;
2007-12-05 05:02:06 +03:00
get_real_name ( cli , & long_name , short_name ) ;
if ( ! long_name ) {
return ;
}
2001-02-26 08:13:19 +03:00
fstrcpy ( res1 , " --- " ) ;
2011-04-29 05:57:02 +04:00
cli_list ( cli , mask , FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_DIRECTORY , listfn , NULL ) ;
2000-02-09 17:10:08 +03:00
2001-08-20 09:15:26 +04:00
res2 = reg_test ( cli , mask , long_name , short_name ) ;
2000-02-09 17:10:08 +03:00
2007-12-05 05:02:06 +03:00
if ( showall | |
2003-04-23 12:12:34 +04:00
( ( strcmp ( res1 , res2 ) & & ! ignore_dot_errors ) | |
( strcmp ( res1 + 2 , res2 + 2 ) & & ignore_dot_errors ) ) ) {
2001-02-26 08:13:19 +03:00
DEBUG ( 0 , ( " %s %s %d mask=[%s] file=[%s] rfile=[%s/%s] \n " ,
res1 , res2 , count , mask , file , long_name , short_name ) ) ;
2001-03-21 09:44:49 +03:00
if ( die_on_error ) exit ( 1 ) ;
2000-02-09 17:10:08 +03:00
}
2011-04-29 07:23:14 +04:00
cli_unlink ( cli , file , FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN ) ;
2000-02-10 16:43:59 +03:00
2000-05-25 01:11:34 +04:00
if ( count % 100 = = 0 ) DEBUG ( 0 , ( " %d \n " , count ) ) ;
2007-12-05 05:02:06 +03:00
SAFE_FREE ( long_name ) ;
2000-02-09 17:10:08 +03:00
}
2007-12-05 05:02:06 +03:00
static void test_mask ( int argc , char * argv [ ] ,
2000-04-30 15:11:19 +04:00
struct cli_state * cli )
2000-02-09 17:10:08 +03:00
{
2007-12-05 05:02:06 +03:00
char * mask , * file ;
2000-04-30 15:11:19 +04:00
int l1 , l2 , i , l ;
2000-02-09 17:10:08 +03:00
int mc_len = strlen ( maskchars ) ;
int fc_len = strlen ( filechars ) ;
2007-12-05 05:02:06 +03:00
TALLOC_CTX * ctx = talloc_tos ( ) ;
2000-02-09 17:10:08 +03:00
2000-05-24 09:56:34 +04:00
cli_mkdir ( cli , " \\ masktest " ) ;
2000-02-09 17:10:08 +03:00
2011-04-29 07:23:14 +04:00
cli_unlink ( cli , " \\ masktest \\ * " , FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN ) ;
2000-02-09 17:10:08 +03:00
if ( argc > = 2 ) {
while ( argc > = 2 ) {
2007-12-05 05:02:06 +03:00
mask = talloc_asprintf ( ctx ,
" \\ masktest \\ %s " ,
argv [ 0 ] ) ;
file = talloc_asprintf ( ctx ,
" \\ masktest \\ %s " ,
argv [ 1 ] ) ;
if ( ! mask | | ! file ) {
goto finished ;
}
2000-04-30 15:11:19 +04:00
testpair ( cli , mask , file ) ;
2000-02-09 17:10:08 +03:00
argv + = 2 ;
argc - = 2 ;
}
goto finished ;
}
while ( 1 ) {
l1 = 1 + random ( ) % 20 ;
l2 = 1 + random ( ) % 20 ;
2011-06-07 05:30:12 +04:00
mask = talloc_array ( ctx , char , strlen ( " \\ masktest \\ " ) + 1 + 22 ) ;
file = talloc_array ( ctx , char , strlen ( " \\ masktest \\ " ) + 1 + 22 ) ;
2007-12-05 05:02:06 +03:00
if ( ! mask | | ! file ) {
goto finished ;
}
memcpy ( mask , " \\ masktest \\ " , strlen ( " \\ masktest \\ " ) + 1 ) ;
memcpy ( file , " \\ masktest \\ " , strlen ( " \\ masktest \\ " ) + 1 ) ;
2000-02-09 17:10:08 +03:00
l = strlen ( mask ) ;
for ( i = 0 ; i < l1 ; i + + ) {
mask [ i + l ] = maskchars [ random ( ) % mc_len ] ;
}
mask [ l + l1 ] = 0 ;
for ( i = 0 ; i < l2 ; i + + ) {
file [ i + l ] = filechars [ random ( ) % fc_len ] ;
}
file [ l + l2 ] = 0 ;
if ( strcmp ( file + l , " . " ) = = 0 | |
strcmp ( file + l , " .. " ) = = 0 | |
strcmp ( mask + l , " .. " ) = = 0 ) continue ;
2001-03-21 09:44:49 +03:00
if ( strspn ( file + l , " . " ) = = strlen ( file + l ) ) continue ;
2000-04-30 15:11:19 +04:00
testpair ( cli , mask , file ) ;
2002-03-22 03:09:09 +03:00
if ( NumLoops & & ( - - NumLoops = = 0 ) )
break ;
2007-12-05 05:02:06 +03:00
TALLOC_FREE ( mask ) ;
TALLOC_FREE ( file ) ;
2000-02-09 17:10:08 +03:00
}
finished :
2000-04-30 15:11:19 +04:00
cli_rmdir ( cli , " \\ masktest " ) ;
2000-02-09 17:10:08 +03:00
}
static void usage ( void )
{
printf (
" Usage: \n \
2000-04-30 15:11:19 +04:00
masktest / / server / share [ options . . ] \ n \
2000-02-09 17:10:08 +03:00
options : \ n \
2002-03-21 17:03:41 +03:00
- d debuglevel \ n \
2002-03-22 03:09:09 +03:00
- n numloops \ n \
2000-05-23 03:38:56 +04:00
- W workgroup \ n \
2000-02-09 17:10:08 +03:00
- U user % % pass \ n \
- s seed \ n \
2001-08-24 03:16:42 +04:00
- M max protocol \ n \
2000-02-09 17:10:08 +03:00
- f filechars ( default % s ) \ n \
- m maskchars ( default % s ) \ n \
2002-03-21 17:03:41 +03:00
- v verbose mode \ n \
- E die on error \ n \
2000-02-09 17:10:08 +03:00
- a show all tests \ n \
2003-04-23 12:12:34 +04:00
- i ignore . and . . errors \ n \
2000-02-09 17:10:08 +03:00
\ n \
This program tests wildcard matching between two servers . It generates \ n \
random pairs of filenames / masks and tests that they match in the same \ n \
2000-04-30 15:11:19 +04:00
way on the servers and internally \ n \
2000-02-09 17:10:08 +03:00
" ,
filechars , maskchars ) ;
}
/****************************************************************************
main program
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int main ( int argc , char * argv [ ] )
{
2000-04-30 15:11:19 +04:00
char * share ;
2007-12-05 05:02:06 +03:00
struct cli_state * cli ;
2000-02-09 17:10:08 +03:00
int opt ;
char * p ;
int seed ;
2007-12-05 05:02:06 +03:00
TALLOC_CTX * frame = talloc_stackframe ( ) ;
2000-02-09 17:10:08 +03:00
setlinebuf ( stdout ) ;
2010-10-29 08:06:36 +04:00
lp_set_cmdline ( " log level " , " 0 " ) ;
2002-03-21 17:03:41 +03:00
2002-03-22 01:36:04 +03:00
if ( argc < 2 | | argv [ 1 ] [ 0 ] = = ' - ' ) {
2000-02-09 17:10:08 +03:00
usage ( ) ;
exit ( 1 ) ;
}
2000-04-30 15:11:19 +04:00
share = argv [ 1 ] ;
2000-02-09 17:10:08 +03:00
2000-04-30 15:11:19 +04:00
all_string_sub ( share , " / " , " \\ " , 0 ) ;
2000-02-09 17:10:08 +03:00
2010-10-29 07:19:32 +04:00
setup_logging ( argv [ 0 ] , DEBUG_STDERR ) ;
2000-02-09 17:10:08 +03:00
2000-04-30 16:34:26 +04:00
argc - = 1 ;
argv + = 1 ;
2000-02-09 17:10:08 +03:00
2015-03-21 22:00:06 +03:00
smb_init_locale ( ) ;
2011-07-27 19:02:51 +04:00
lp_load_global ( get_dyn_CONFIGFILE ( ) ) ;
2000-03-26 13:20:47 +04:00
load_interfaces ( ) ;
2000-02-09 17:10:08 +03:00
if ( getenv ( " USER " ) ) {
2003-01-14 11:53:59 +03:00
fstrcpy ( username , getenv ( " USER " ) ) ;
2000-02-09 17:10:08 +03:00
}
seed = time ( NULL ) ;
2003-04-23 12:12:34 +04:00
while ( ( opt = getopt ( argc , argv , " n:d:U:s:hm:f:aoW:M:vEi " ) ) ! = EOF ) {
2000-02-09 17:10:08 +03:00
switch ( opt ) {
2002-03-22 03:09:09 +03:00
case ' n ' :
NumLoops = atoi ( optarg ) ;
break ;
2002-03-21 17:03:41 +03:00
case ' d ' :
2010-10-29 08:29:09 +04:00
lp_set_cmdline ( " log level " , optarg ) ;
2002-03-21 17:03:41 +03:00
break ;
2001-03-21 09:44:49 +03:00
case ' E ' :
die_on_error = 1 ;
break ;
2003-04-23 12:12:34 +04:00
case ' i ' :
ignore_dot_errors = 1 ;
break ;
2001-02-27 07:18:12 +03:00
case ' v ' :
verbose + + ;
break ;
2001-02-26 02:47:27 +03:00
case ' M ' :
2013-08-11 15:10:13 +04:00
lp_set_cmdline ( " client max protocol " , optarg ) ;
2001-02-26 02:47:27 +03:00
break ;
2000-02-09 17:10:08 +03:00
case ' U ' :
2003-01-14 11:53:59 +03:00
fstrcpy ( username , optarg ) ;
2001-07-04 11:36:09 +04:00
p = strchr_m ( username , ' % ' ) ;
2000-02-09 17:10:08 +03:00
if ( p ) {
* p = 0 ;
2003-01-14 11:53:59 +03:00
fstrcpy ( password , p + 1 ) ;
2000-02-09 17:10:08 +03:00
got_pass = 1 ;
}
break ;
case ' s ' :
seed = atoi ( optarg ) ;
break ;
case ' h ' :
usage ( ) ;
exit ( 1 ) ;
case ' m ' :
maskchars = optarg ;
break ;
case ' f ' :
filechars = optarg ;
break ;
case ' a ' :
showall = 1 ;
break ;
2000-04-30 16:34:26 +04:00
case ' o ' :
old_list = True ;
break ;
2000-02-09 17:10:08 +03:00
default :
printf ( " Unknown option %c (%d) \n " , ( char ) opt , opt ) ;
exit ( 1 ) ;
}
}
argc - = optind ;
argv + = optind ;
2014-02-04 06:09:08 +04:00
max_protocol = lp_client_max_protocol ( ) ;
2016-12-09 11:49:17 +03:00
max_protocol = MIN ( max_protocol , PROTOCOL_NT1 ) ;
2000-02-09 17:10:08 +03:00
2016-10-28 13:42:01 +03:00
if ( ! got_pass ) {
char pwd [ 256 ] = { 0 } ;
int rc ;
rc = samba_getpass ( " Password: " , pwd , sizeof ( pwd ) , false , false ) ;
if ( rc = = 0 ) {
fstrcpy ( password , pass ) ;
}
}
test_creds = cli_session_creds_init ( frame ,
username ,
lp_workgroup ( ) ,
NULL , /* realm */
password ,
false , /* use_kerberos */
false , /* fallback_after_kerberos */
false , /* use_ccache */
false ) ; /* password_is_nt_hash */
if ( test_creds = = NULL ) {
d_printf ( " cli_session_creds_init() failed. \n " ) ;
exit ( 1 ) ;
}
2000-04-30 15:11:19 +04:00
cli = connect_one ( share ) ;
if ( ! cli ) {
DEBUG ( 0 , ( " Failed to connect to %s \n " , share ) ) ;
2000-02-09 17:10:08 +03:00
exit ( 1 ) ;
}
2000-05-27 04:28:02 +04:00
/* need to init seed after connect as clientgen uses random numbers */
DEBUG ( 0 , ( " seed=%d \n " , seed ) ) ;
srandom ( seed ) ;
2000-04-30 15:11:19 +04:00
test_mask ( argc , argv , cli ) ;
2000-02-09 17:10:08 +03:00
2007-12-05 05:02:06 +03:00
TALLOC_FREE ( frame ) ;
2000-02-09 17:10:08 +03:00
return ( 0 ) ;
}