2001-09-25 09:20:43 +04:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
2001-09-25 09:20:43 +04:00
SMB torture tester - unicode table dumper
Copyright ( C ) Andrew Tridgell 2001
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
2001-09-25 09:20:43 +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 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2001-09-25 09:20:43 +04:00
*/
# include "includes.h"
2007-10-19 04:40:25 +04:00
bool torture_utable ( int dummy )
2001-09-25 09:20:43 +04:00
{
2003-04-23 12:12:34 +04:00
struct cli_state * cli ;
2001-09-25 09:20:43 +04:00
fstring fname , alt_name ;
int fnum ;
smb_ucs2_t c2 ;
2001-10-03 16:18:20 +04:00
int c , len , fd ;
2001-09-25 09:20:43 +04:00
int chars_allowed = 0 , alt_allowed = 0 ;
2001-10-03 16:18:20 +04:00
uint8 valid [ 0x10000 ] ;
2001-09-25 09:20:43 +04:00
printf ( " starting utable \n " ) ;
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli , 0 ) ) {
2001-09-25 09:20:43 +04:00
return False ;
}
2001-10-03 16:18:20 +04:00
memset ( valid , 0 , sizeof ( valid ) ) ;
2003-04-23 12:12:34 +04:00
cli_mkdir ( cli , " \\ utable " ) ;
cli_unlink ( cli , " \\ utable \\ * " ) ;
2001-09-25 09:20:43 +04:00
for ( c = 1 ; c < 0x10000 ; c + + ) {
char * p ;
SSVAL ( & c2 , 0 , c ) ;
fstrcpy ( fname , " \\ utable \\ x " ) ;
p = fname + strlen ( fname ) ;
2006-09-22 00:53:56 +04:00
len = convert_string ( CH_UTF16LE , CH_UNIX ,
2001-09-25 09:20:43 +04:00
& c2 , 2 ,
2004-03-12 15:57:39 +03:00
p , sizeof ( fname ) - strlen ( fname ) , True ) ;
2001-09-25 09:20:43 +04:00
p [ len ] = 0 ;
fstrcat ( fname , " _a_long_extension " ) ;
2003-04-23 12:12:34 +04:00
fnum = cli_open ( cli , fname , O_RDWR | O_CREAT | O_TRUNC ,
2001-09-25 09:20:43 +04:00
DENY_NONE ) ;
if ( fnum = = - 1 ) continue ;
chars_allowed + + ;
2003-04-23 12:12:34 +04:00
cli_qpathinfo_alt_name ( cli , fname , alt_name ) ;
2001-09-25 09:20:43 +04:00
if ( strncmp ( alt_name , " X_A_L " , 5 ) ! = 0 ) {
alt_allowed + + ;
2001-10-03 16:18:20 +04:00
valid [ c ] = 1 ;
2001-10-11 12:40:42 +04:00
d_printf ( " fname=[%s] alt_name=[%s] \n " , fname , alt_name ) ;
2001-09-25 09:20:43 +04:00
}
2003-04-23 12:12:34 +04:00
cli_close ( cli , fnum ) ;
cli_unlink ( cli , fname ) ;
2001-09-25 09:20:43 +04:00
if ( c % 100 = = 0 ) {
printf ( " %d (%d/%d) \r " , c , chars_allowed , alt_allowed ) ;
}
}
printf ( " %d (%d/%d) \n " , c , chars_allowed , alt_allowed ) ;
2003-04-23 12:12:34 +04:00
cli_rmdir ( cli , " \\ utable " ) ;
2001-09-25 09:20:43 +04:00
d_printf ( " %d chars allowed %d alt chars allowed \n " , chars_allowed , alt_allowed ) ;
2001-10-03 16:18:20 +04:00
fd = open ( " valid.dat " , O_WRONLY | O_CREAT | O_TRUNC , 0644 ) ;
if ( fd = = - 1 ) {
d_printf ( " Failed to create valid.dat - %s " , strerror ( errno ) ) ;
return False ;
}
write ( fd , valid , 0x10000 ) ;
close ( fd ) ;
d_printf ( " wrote valid.dat \n " ) ;
2001-09-25 09:20:43 +04:00
return True ;
}
2001-10-02 09:52:11 +04:00
static char * form_name ( int c )
{
static fstring fname ;
smb_ucs2_t c2 ;
char * p ;
int len ;
2001-10-02 17:26:38 +04:00
fstrcpy ( fname , " \\ utable \\ " ) ;
2001-10-02 09:52:11 +04:00
p = fname + strlen ( fname ) ;
SSVAL ( & c2 , 0 , c ) ;
2006-09-22 00:53:56 +04:00
len = convert_string ( CH_UTF16LE , CH_UNIX ,
2001-10-02 09:52:11 +04:00
& c2 , 2 ,
2004-03-12 15:57:39 +03:00
p , sizeof ( fname ) - strlen ( fname ) , True ) ;
2001-10-02 09:52:11 +04:00
p [ len ] = 0 ;
return fname ;
}
2007-10-19 04:40:25 +04:00
bool torture_casetable ( int dummy )
2001-10-02 09:52:11 +04:00
{
2003-04-23 12:12:34 +04:00
static struct cli_state * cli ;
2001-10-02 09:52:11 +04:00
char * fname ;
int fnum ;
2001-10-02 17:26:38 +04:00
int c , i ;
# define MAX_EQUIVALENCE 8
smb_ucs2_t equiv [ 0x10000 ] [ MAX_EQUIVALENCE ] ;
printf ( " starting casetable \n " ) ;
2001-10-02 09:52:11 +04:00
2006-07-31 13:41:25 +04:00
if ( ! torture_open_connection ( & cli , 0 ) ) {
2001-10-02 09:52:11 +04:00
return False ;
}
2001-10-02 17:26:38 +04:00
memset ( equiv , 0 , sizeof ( equiv ) ) ;
2003-04-23 12:12:34 +04:00
cli_unlink ( cli , " \\ utable \\ * " ) ;
cli_rmdir ( cli , " \\ utable " ) ;
if ( ! cli_mkdir ( cli , " \\ utable " ) ) {
printf ( " Failed to create utable directory! \n " ) ;
return False ;
}
2001-10-02 09:52:11 +04:00
for ( c = 1 ; c < 0x10000 ; c + + ) {
2005-03-23 00:17:01 +03:00
SMB_OFF_T size ;
2001-10-02 17:26:38 +04:00
2001-10-03 16:18:20 +04:00
if ( c = = ' . ' | | c = = ' \\ ' ) continue ;
2003-04-23 12:12:34 +04:00
printf ( " %04x (%c) \n " , c , isprint ( c ) ? c : ' . ' ) ;
2001-10-02 17:26:38 +04:00
2001-10-02 09:52:11 +04:00
fname = form_name ( c ) ;
2003-04-23 12:12:34 +04:00
fnum = cli_nt_create_full ( cli , fname , 0 ,
2001-10-02 09:52:11 +04:00
GENERIC_ALL_ACCESS ,
FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_NONE ,
2003-04-18 07:35:39 +04:00
FILE_OPEN_IF , 0 , 0 ) ;
2001-10-02 09:52:11 +04:00
2003-04-23 12:12:34 +04:00
if ( fnum = = - 1 ) {
printf ( " Failed to create file with char %04x \n " , c ) ;
continue ;
}
2001-10-02 17:26:38 +04:00
size = 0 ;
2003-04-23 12:12:34 +04:00
if ( ! cli_qfileinfo ( cli , fnum , NULL , & size ,
2001-10-02 17:26:38 +04:00
NULL , NULL , NULL , NULL , NULL ) ) continue ;
if ( size > 0 ) {
2001-10-02 09:52:11 +04:00
/* found a character equivalence! */
2001-10-02 17:26:38 +04:00
int c2 [ MAX_EQUIVALENCE ] ;
if ( size / sizeof ( int ) > = MAX_EQUIVALENCE ) {
2003-11-07 01:11:08 +03:00
printf ( " too many chars match?? size=%ld c=0x%04x \n " ,
( unsigned long ) size , c ) ;
2003-04-23 12:12:34 +04:00
cli_close ( cli , fnum ) ;
2001-10-02 17:26:38 +04:00
return False ;
2001-10-02 09:52:11 +04:00
}
2003-04-23 12:12:34 +04:00
cli_read ( cli , fnum , ( char * ) c2 , 0 , size ) ;
2001-10-02 17:26:38 +04:00
printf ( " %04x: " , c ) ;
equiv [ c ] [ 0 ] = c ;
for ( i = 0 ; i < size / sizeof ( int ) ; i + + ) {
printf ( " %04x " , c2 [ i ] ) ;
equiv [ c ] [ i + 1 ] = c2 [ i ] ;
}
printf ( " \n " ) ;
fflush ( stdout ) ;
2001-10-02 09:52:11 +04:00
}
2003-04-23 12:12:34 +04:00
cli_write ( cli , fnum , 0 , ( char * ) & c , size , sizeof ( c ) ) ;
cli_close ( cli , fnum ) ;
2001-10-02 09:52:11 +04:00
}
2003-04-23 12:12:34 +04:00
cli_unlink ( cli , " \\ utable \\ * " ) ;
cli_rmdir ( cli , " \\ utable " ) ;
2001-10-02 09:52:11 +04:00
return True ;
}