2003-08-13 05:53:07 +04:00
/*
Unix SMB / CIFS implementation .
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-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"
2006-01-03 16:41:17 +03:00
# include "torture/torture.h"
2005-02-10 08:09:35 +03:00
# include "system/filesys.h"
2006-05-13 23:14:12 +04:00
# include "system/locale.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 "pstring.h"
2007-12-14 00:46:09 +03:00
# include "param/param.h"
2003-08-13 05:53:07 +04:00
2006-10-16 17:06:41 +04:00
bool torture_utable ( struct torture_context * tctx ,
struct smbcli_state * cli )
2003-08-13 05:53:07 +04:00
{
fstring fname ;
2003-11-28 12:05:44 +03:00
const char * alt_name ;
2003-08-13 05:53:07 +04:00
int fnum ;
2004-12-04 16:56:25 +03:00
uint8_t c2 [ 4 ] ;
2003-08-13 05:53:07 +04:00
int c , len , fd ;
int chars_allowed = 0 , alt_allowed = 0 ;
2004-05-25 21:50:17 +04:00
uint8_t valid [ 0x10000 ] ;
2003-08-13 05:53:07 +04:00
2006-10-16 17:06:41 +04:00
torture_comment ( tctx , " Generating valid character table \n " ) ;
2003-08-13 05:53:07 +04:00
memset ( valid , 0 , sizeof ( valid ) ) ;
2006-10-16 17:06:41 +04:00
torture_assert ( tctx , torture_setup_dir ( cli , " \\ utable " ) ,
" Setting up dir \\ utable failed " ) ;
2003-08-13 05:53:07 +04:00
for ( c = 1 ; c < 0x10000 ; c + + ) {
char * p ;
2004-10-08 12:13:00 +04:00
SSVAL ( c2 , 0 , c ) ;
2003-08-13 05:53:07 +04:00
fstrcpy ( fname , " \\ utable \\ x " ) ;
p = fname + strlen ( fname ) ;
2007-12-14 00:46:09 +03:00
len = convert_string ( lp_iconv_convenience ( global_loadparm ) , CH_UTF16 , CH_UNIX ,
2004-10-08 12:13:00 +04:00
c2 , 2 ,
2003-08-13 05:53:07 +04:00
p , sizeof ( fname ) - strlen ( fname ) ) ;
p [ len ] = 0 ;
fstrcat ( fname , " _a_long_extension " ) ;
2004-08-04 17:23:35 +04:00
fnum = smbcli_open ( cli - > tree , fname , O_RDWR | O_CREAT | O_TRUNC ,
2003-08-13 05:53:07 +04:00
DENY_NONE ) ;
if ( fnum = = - 1 ) continue ;
chars_allowed + + ;
2004-08-04 17:23:35 +04:00
smbcli_qpathinfo_alt_name ( cli - > tree , fname , & alt_name ) ;
2003-08-13 05:53:07 +04:00
if ( strncmp ( alt_name , " X_A_L " , 5 ) ! = 0 ) {
alt_allowed + + ;
valid [ c ] = 1 ;
2006-10-16 17:06:41 +04:00
torture_comment ( tctx , " fname=[%s] alt_name=[%s] \n " , fname , alt_name ) ;
2003-08-13 05:53:07 +04:00
}
2004-08-04 17:23:35 +04:00
smbcli_close ( cli - > tree , fnum ) ;
smbcli_unlink ( cli - > tree , fname ) ;
2003-08-13 05:53:07 +04:00
if ( c % 100 = = 0 ) {
2007-04-30 01:37:29 +04:00
if ( torture_setting_bool ( tctx , " progress " , true ) ) {
torture_comment ( tctx , " %d (%d/%d) \r " , c , chars_allowed , alt_allowed ) ;
fflush ( stdout ) ;
}
2003-08-13 05:53:07 +04:00
}
}
2006-10-16 17:06:41 +04:00
torture_comment ( tctx , " %d (%d/%d) \n " , c , chars_allowed , alt_allowed ) ;
2003-08-13 05:53:07 +04:00
2004-08-04 17:23:35 +04:00
smbcli_rmdir ( cli - > tree , " \\ utable " ) ;
2003-08-13 05:53:07 +04:00
2006-10-16 17:06:41 +04:00
torture_comment ( tctx , " %d chars allowed %d alt chars allowed \n " , chars_allowed , alt_allowed ) ;
2003-08-13 05:53:07 +04:00
fd = open ( " valid.dat " , O_WRONLY | O_CREAT | O_TRUNC , 0644 ) ;
2006-10-16 17:06:41 +04:00
torture_assert ( tctx , fd ! = - 1 ,
talloc_asprintf ( tctx ,
" Failed to create valid.dat - %s " , strerror ( errno ) ) ) ;
2003-08-13 05:53:07 +04:00
write ( fd , valid , 0x10000 ) ;
close ( fd ) ;
2006-10-16 17:06:41 +04:00
torture_comment ( tctx , " wrote valid.dat \n " ) ;
2003-08-13 05:53:07 +04:00
2006-10-16 17:06:41 +04:00
return true ;
2003-08-13 05:53:07 +04:00
}
static char * form_name ( int c )
{
static fstring fname ;
2004-12-04 16:56:25 +03:00
uint8_t c2 [ 4 ] ;
2003-08-13 05:53:07 +04:00
char * p ;
int len ;
fstrcpy ( fname , " \\ utable \\ " ) ;
p = fname + strlen ( fname ) ;
2004-10-08 12:13:00 +04:00
SSVAL ( c2 , 0 , c ) ;
2003-08-13 05:53:07 +04:00
2007-12-14 00:46:09 +03:00
len = convert_string ( lp_iconv_convenience ( global_loadparm ) , CH_UTF16 , CH_UNIX ,
2004-10-08 12:13:00 +04:00
c2 , 2 ,
2003-08-13 05:53:07 +04:00
p , sizeof ( fname ) - strlen ( fname ) ) ;
p [ len ] = 0 ;
return fname ;
}
2006-10-16 17:06:41 +04:00
bool torture_casetable ( struct torture_context * tctx ,
struct smbcli_state * cli )
2003-08-13 05:53:07 +04:00
{
char * fname ;
int fnum ;
int c , i ;
# define MAX_EQUIVALENCE 8
2004-10-08 12:13:00 +04:00
codepoint_t equiv [ 0x10000 ] [ MAX_EQUIVALENCE ] ;
2003-08-13 05:53:07 +04:00
2006-10-16 17:06:41 +04:00
torture_comment ( tctx , " Determining upper/lower case table \n " ) ;
2003-08-13 05:53:07 +04:00
memset ( equiv , 0 , sizeof ( equiv ) ) ;
2006-10-16 17:06:41 +04:00
torture_assert ( tctx , torture_setup_dir ( cli , " \\ utable " ) ,
" Error setting up dir \\ utable " ) ;
2003-08-13 05:53:07 +04:00
for ( c = 1 ; c < 0x10000 ; c + + ) {
size_t size ;
if ( c = = ' . ' | | c = = ' \\ ' ) continue ;
2006-10-16 17:06:41 +04:00
torture_comment ( tctx , " %04x (%c) \n " , c , isprint ( c ) ? c : ' . ' ) ;
2003-08-13 05:53:07 +04:00
fname = form_name ( c ) ;
2004-08-04 17:23:35 +04:00
fnum = smbcli_nt_create_full ( cli - > tree , fname , 0 ,
2003-09-29 10:02:25 +04:00
#if 0
2004-11-30 07:33:27 +03:00
SEC_RIGHT_MAXIMUM_ALLOWED ,
2003-09-29 10:02:25 +04:00
# else
2004-12-02 07:37:36 +03:00
SEC_RIGHTS_FILE_ALL ,
2003-09-29 10:02:25 +04:00
# endif
2004-11-30 07:33:27 +03:00
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_NONE ,
NTCREATEX_DISP_OPEN_IF , 0 , 0 ) ;
2003-08-13 05:53:07 +04:00
2006-10-16 17:06:41 +04:00
torture_assert ( tctx , fnum ! = - 1 ,
talloc_asprintf ( tctx ,
" Failed to create file with char %04x \n " , c ) ) ;
2003-08-13 05:53:07 +04:00
size = 0 ;
2004-08-04 17:23:35 +04:00
if ( NT_STATUS_IS_ERR ( smbcli_qfileinfo ( cli - > tree , fnum , NULL , & size ,
2004-02-10 14:33:35 +03:00
NULL , NULL , NULL , NULL , NULL ) ) ) continue ;
2003-08-13 05:53:07 +04:00
if ( size > 0 ) {
/* found a character equivalence! */
int c2 [ MAX_EQUIVALENCE ] ;
if ( size / sizeof ( int ) > = MAX_EQUIVALENCE ) {
2006-10-16 17:06:41 +04:00
torture_comment ( tctx , " too many chars match?? size=%d c=0x%04x \n " ,
2005-07-17 13:20:52 +04:00
( int ) size , c ) ;
2004-08-04 17:23:35 +04:00
smbcli_close ( cli - > tree , fnum ) ;
2007-10-07 02:28:14 +04:00
return false ;
2003-08-13 05:53:07 +04:00
}
2004-12-04 16:56:25 +03:00
smbcli_read ( cli - > tree , fnum , c2 , 0 , size ) ;
2006-10-16 17:06:41 +04:00
torture_comment ( tctx , " %04x: " , c ) ;
2003-08-13 05:53:07 +04:00
equiv [ c ] [ 0 ] = c ;
for ( i = 0 ; i < size / sizeof ( int ) ; i + + ) {
2006-10-16 17:06:41 +04:00
torture_comment ( tctx , " %04x " , c2 [ i ] ) ;
2003-08-13 05:53:07 +04:00
equiv [ c ] [ i + 1 ] = c2 [ i ] ;
}
2006-10-16 17:06:41 +04:00
torture_comment ( tctx , " \n " ) ;
2003-08-13 05:53:07 +04:00
}
2004-12-04 16:56:25 +03:00
smbcli_write ( cli - > tree , fnum , 0 , & c , size , sizeof ( c ) ) ;
2004-08-04 17:23:35 +04:00
smbcli_close ( cli - > tree , fnum ) ;
2003-08-13 05:53:07 +04:00
}
2004-08-04 17:23:35 +04:00
smbcli_unlink ( cli - > tree , " \\ utable \\ * " ) ;
smbcli_rmdir ( cli - > tree , " \\ utable " ) ;
2003-08-13 05:53:07 +04:00
2006-10-16 17:06:41 +04:00
return true ;
2003-08-13 05:53:07 +04:00
}