2001-09-25 05:20:43 +00:00
/*
2002-01-30 06:08:46 +00:00
Unix SMB / CIFS implementation .
2001-09-25 05:20:43 +00: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 19:25:36 +00:00
the Free Software Foundation ; either version 3 of the License , or
2001-09-25 05:20:43 +00: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 00:52:41 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2001-09-25 05:20:43 +00:00
*/
# include "includes.h"
2011-02-25 23:20:06 +01:00
# include "system/filesys.h"
2009-11-24 11:43:56 +01:00
# include "torture/proto.h"
2010-10-12 15:27:50 +11:00
# include "../libcli/security/security.h"
2011-05-06 11:47:43 +02:00
# include "libsmb/libsmb.h"
2011-02-24 10:46:55 +01:00
# include "libsmb/clirap.h"
2001-09-25 05:20:43 +00:00
2007-10-18 17:40:25 -07:00
bool torture_utable ( int dummy )
2001-09-25 05:20:43 +00:00
{
2003-04-23 08:12:34 +00:00
struct cli_state * cli ;
2001-09-25 05:20:43 +00:00
fstring fname , alt_name ;
2009-04-30 15:26:43 -07:00
uint16_t fnum ;
2001-09-25 05:20:43 +00:00
smb_ucs2_t c2 ;
2001-10-03 12:18:20 +00:00
int c , len , fd ;
2001-09-25 05:20:43 +00:00
int chars_allowed = 0 , alt_allowed = 0 ;
2015-05-08 20:10:12 -07:00
uint8_t valid [ 0x10000 ] ;
2001-09-25 05:20:43 +00:00
printf ( " starting utable \n " ) ;
2006-07-31 09:41:25 +00:00
if ( ! torture_open_connection ( & cli , 0 ) ) {
2001-09-25 05:20:43 +00:00
return False ;
}
2001-10-03 12:18:20 +00:00
memset ( valid , 0 , sizeof ( valid ) ) ;
2003-04-23 08:12:34 +00:00
cli_mkdir ( cli , " \\ utable " ) ;
2011-04-29 13:23:14 +10:00
cli_unlink ( cli , " \\ utable \\ * " , FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN ) ;
2001-09-25 05:20:43 +00:00
for ( c = 1 ; c < 0x10000 ; c + + ) {
2011-03-30 13:08:31 -07:00
size_t size = 0 ;
2001-09-25 05:20:43 +00:00
char * p ;
SSVAL ( & c2 , 0 , c ) ;
fstrcpy ( fname , " \\ utable \\ x " ) ;
p = fname + strlen ( fname ) ;
2011-03-30 13:08:31 -07:00
if ( ! convert_string ( CH_UTF16LE , CH_UNIX ,
2001-09-25 05:20:43 +00:00
& c2 , 2 ,
2011-03-30 13:08:31 -07:00
p , sizeof ( fname ) - strlen ( fname ) , & size ) ) {
d_printf ( " convert_string %s failed ! \n " , fname ) ;
continue ;
}
len = size ;
2001-09-25 05:20:43 +00:00
p [ len ] = 0 ;
fstrcat ( fname , " _a_long_extension " ) ;
2011-12-03 21:13:08 -08:00
if ( ! NT_STATUS_IS_OK ( cli_openx ( cli , fname , O_RDWR | O_CREAT | O_TRUNC ,
2009-04-30 15:26:43 -07:00
DENY_NONE , & fnum ) ) ) {
continue ;
}
2001-09-25 05:20:43 +00:00
chars_allowed + + ;
2003-04-23 08:12:34 +00:00
cli_qpathinfo_alt_name ( cli , fname , alt_name ) ;
2001-09-25 05:20:43 +00:00
if ( strncmp ( alt_name , " X_A_L " , 5 ) ! = 0 ) {
alt_allowed + + ;
2001-10-03 12:18:20 +00:00
valid [ c ] = 1 ;
2001-10-11 08:40:42 +00:00
d_printf ( " fname=[%s] alt_name=[%s] \n " , fname , alt_name ) ;
2001-09-25 05:20:43 +00:00
}
2003-04-23 08:12:34 +00:00
cli_close ( cli , fnum ) ;
2011-04-29 13:23:14 +10:00
cli_unlink ( cli , fname , FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN ) ;
2001-09-25 05:20:43 +00: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 08:12:34 +00:00
cli_rmdir ( cli , " \\ utable " ) ;
2001-09-25 05:20:43 +00:00
d_printf ( " %d chars allowed %d alt chars allowed \n " , chars_allowed , alt_allowed ) ;
2001-10-03 12:18:20 +00: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 ;
}
2009-01-02 11:38:24 -08:00
if ( write ( fd , valid , 0x10000 ) ! = 0x10000 ) {
d_printf ( " Failed to create valid.dat - %s " , strerror ( errno ) ) ;
close ( fd ) ;
return false ;
}
2001-10-03 12:18:20 +00:00
close ( fd ) ;
d_printf ( " wrote valid.dat \n " ) ;
2001-09-25 05:20:43 +00:00
return True ;
}
2001-10-02 05:52:11 +00:00
static char * form_name ( int c )
{
static fstring fname ;
smb_ucs2_t c2 ;
char * p ;
2011-03-30 13:08:31 -07:00
size_t len = 0 ;
2001-10-02 05:52:11 +00:00
2001-10-02 13:26:38 +00:00
fstrcpy ( fname , " \\ utable \\ " ) ;
2001-10-02 05:52:11 +00:00
p = fname + strlen ( fname ) ;
SSVAL ( & c2 , 0 , c ) ;
2011-03-30 13:08:31 -07:00
if ( ! convert_string ( CH_UTF16LE , CH_UNIX ,
2001-10-02 05:52:11 +00:00
& c2 , 2 ,
2011-03-30 13:08:31 -07:00
p , sizeof ( fname ) - strlen ( fname ) , & len ) ) {
d_printf ( " form_name: convert string %s failed \n " ,
fname ) ;
return NULL ;
}
2001-10-02 05:52:11 +00:00
p [ len ] = 0 ;
return fname ;
}
2007-10-18 17:40:25 -07:00
bool torture_casetable ( int dummy )
2001-10-02 05:52:11 +00:00
{
2003-04-23 08:12:34 +00:00
static struct cli_state * cli ;
2001-10-02 05:52:11 +00:00
char * fname ;
2009-04-30 15:26:43 -07:00
uint16_t fnum ;
2001-10-02 13:26:38 +00:00
int c , i ;
# define MAX_EQUIVALENCE 8
smb_ucs2_t equiv [ 0x10000 ] [ MAX_EQUIVALENCE ] ;
printf ( " starting casetable \n " ) ;
2001-10-02 05:52:11 +00:00
2006-07-31 09:41:25 +00:00
if ( ! torture_open_connection ( & cli , 0 ) ) {
2001-10-02 05:52:11 +00:00
return False ;
}
2001-10-02 13:26:38 +00:00
memset ( equiv , 0 , sizeof ( equiv ) ) ;
2011-04-29 13:23:14 +10:00
cli_unlink ( cli , " \\ utable \\ * " , FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN ) ;
2003-04-23 08:12:34 +00:00
cli_rmdir ( cli , " \\ utable " ) ;
2009-04-21 05:52:34 -07:00
if ( ! NT_STATUS_IS_OK ( cli_mkdir ( cli , " \\ utable " ) ) ) {
2003-04-23 08:12:34 +00:00
printf ( " Failed to create utable directory! \n " ) ;
return False ;
}
2001-10-02 05:52:11 +00:00
for ( c = 1 ; c < 0x10000 ; c + + ) {
2012-04-05 14:53:08 +10:00
off_t size ;
2001-10-02 13:26:38 +00:00
2001-10-03 12:18:20 +00:00
if ( c = = ' . ' | | c = = ' \\ ' ) continue ;
2003-04-23 08:12:34 +00:00
printf ( " %04x (%c) \n " , c , isprint ( c ) ? c : ' . ' ) ;
2001-10-02 13:26:38 +00:00
2001-10-02 05:52:11 +00:00
fname = form_name ( c ) ;
2009-04-30 15:26:43 -07:00
if ( ! NT_STATUS_IS_OK ( cli_ntcreate ( cli , fname , 0 ,
2001-10-02 05:52:11 +00:00
GENERIC_ALL_ACCESS ,
FILE_ATTRIBUTE_NORMAL ,
FILE_SHARE_NONE ,
2014-05-08 20:55:57 -07:00
FILE_OPEN_IF , 0 , 0 , & fnum , NULL ) ) ) {
2003-04-23 08:12:34 +00:00
printf ( " Failed to create file with char %04x \n " , c ) ;
continue ;
}
2001-10-02 13:26:38 +00:00
size = 0 ;
2010-10-23 22:37:16 +02:00
if ( ! NT_STATUS_IS_OK ( cli_qfileinfo_basic (
cli , fnum , NULL , & size ,
NULL , NULL , NULL , NULL , NULL ) ) ) {
2010-10-23 09:28:47 +02:00
continue ;
}
2001-10-02 13:26:38 +00:00
if ( size > 0 ) {
2001-10-02 05:52:11 +00:00
/* found a character equivalence! */
2001-10-02 13:26:38 +00:00
int c2 [ MAX_EQUIVALENCE ] ;
if ( size / sizeof ( int ) > = MAX_EQUIVALENCE ) {
2003-11-06 22:11:08 +00:00
printf ( " too many chars match?? size=%ld c=0x%04x \n " ,
( unsigned long ) size , c ) ;
2003-04-23 08:12:34 +00:00
cli_close ( cli , fnum ) ;
2001-10-02 13:26:38 +00:00
return False ;
2001-10-02 05:52:11 +00:00
}
2011-07-22 13:46:57 +02:00
cli_read ( cli , fnum , ( char * ) c2 , 0 , size , NULL ) ;
2001-10-02 13:26:38 +00: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 05:52:11 +00:00
}
2011-04-02 11:46:30 +02:00
cli_writeall ( cli , fnum , 0 , ( uint8_t * ) & c , size , sizeof ( c ) ,
NULL ) ;
2003-04-23 08:12:34 +00:00
cli_close ( cli , fnum ) ;
2001-10-02 05:52:11 +00:00
}
2011-04-29 13:23:14 +10:00
cli_unlink ( cli , " \\ utable \\ * " , FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN ) ;
2003-04-23 08:12:34 +00:00
cli_rmdir ( cli , " \\ utable " ) ;
2001-10-02 05:52:11 +00:00
return True ;
}