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"
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"
2007-12-14 00:46:09 +03:00
# include "param/param.h"
2011-03-19 02:42:52 +03:00
# include "torture/basic/proto.h"
2016-04-05 19:16:46 +03:00
# include "lib/util/sys_rw.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
{
2008-10-22 07:14:14 +04:00
char fname [ 256 ] ;
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 ] ;
2009-03-01 21:55:46 +03:00
int c , fd ;
size_t len ;
2003-08-13 05:53:07 +04:00
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 ) ;
2008-10-22 07:14:14 +04:00
strncpy ( fname , " \\ utable \\ x " , sizeof ( fname ) - 1 ) ;
2003-08-13 05:53:07 +04:00
p = fname + strlen ( fname ) ;
2011-03-31 00:08:31 +04:00
len = 0 ;
if ( ! convert_string ( CH_UTF16 , CH_UNIX ,
2004-10-08 12:13:00 +04:00
c2 , 2 ,
2011-03-31 00:08:31 +04:00
p , sizeof ( fname ) - strlen ( fname ) , & len ) ) {
torture_comment ( tctx , " convert_string failed [%s] \n " ,
fname ) ;
continue ;
}
2003-08-13 05:53:07 +04:00
p [ len ] = 0 ;
2008-10-22 07:14:14 +04:00
strncat ( fname , " _a_long_extension " , sizeof ( fname ) - 1 ) ;
2003-08-13 05:53:07 +04:00
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 ) ) ) ;
2016-04-05 19:16:46 +03:00
sys_write_v ( fd , valid , 0x10000 ) ;
2003-08-13 05:53:07 +04:00
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
}
2010-05-09 19:20:01 +04:00
static char * form_name ( int c )
2003-08-13 05:53:07 +04:00
{
2008-10-22 07:14:14 +04:00
static char fname [ 256 ] ;
2004-12-04 16:56:25 +03:00
uint8_t c2 [ 4 ] ;
2003-08-13 05:53:07 +04:00
char * p ;
2011-03-31 00:08:31 +04:00
size_t len = 0 ;
2003-08-13 05:53:07 +04:00
2008-10-22 07:14:14 +04:00
strncpy ( fname , " \\ utable \\ " , sizeof ( fname ) - 1 ) ;
2003-08-13 05:53:07 +04:00
p = fname + strlen ( fname ) ;
2004-10-08 12:13:00 +04:00
SSVAL ( c2 , 0 , c ) ;
2003-08-13 05:53:07 +04:00
2011-03-31 00:08:31 +04:00
if ( ! convert_string ( CH_UTF16 , CH_UNIX ,
2004-10-08 12:13:00 +04:00
c2 , 2 ,
2011-03-31 00:08:31 +04:00
p , sizeof ( fname ) - strlen ( fname ) , & len ) ) {
2010-05-09 19:20:01 +04:00
return NULL ;
2011-03-31 00:08:31 +04:00
}
2003-08-13 05:53:07 +04:00
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
2010-05-09 19:20:01 +04:00
fname = form_name ( c ) ;
2011-08-15 03:53:45 +04:00
if ( fname = = NULL ) continue ;
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
2011-08-15 03:53:45 +04:00
if ( fnum = = - 1 ) {
torture_comment ( tctx , " Failed to create file with char %04x \n " , c ) ;
continue ;
}
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
}