2004-03-26 05:39:48 +03:00
/*
Unix SMB / CIFS implementation .
SMB torture tester - charset test routines
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
2004-03-26 05:39:48 +03: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/>.
2004-03-26 05:39:48 +03:00
*/
# include "includes.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"
2004-03-26 05:39:48 +03:00
2006-10-16 17:06:41 +04:00
# define BASEDIR "\\chartest\\"
2004-03-26 05:39:48 +03:00
/*
open a file using a set of unicode code points for the name
the prefix BASEDIR is added before the name
*/
2006-10-16 17:06:41 +04:00
static NTSTATUS unicode_open ( struct torture_context * tctx ,
2007-09-02 06:07:55 +04:00
struct smbcli_tree * tree ,
2004-03-26 05:39:48 +03:00
TALLOC_CTX * mem_ctx ,
2004-05-25 20:24:13 +04:00
uint32_t open_disposition ,
const uint32_t * u_name ,
2004-03-26 05:39:48 +03:00
size_t u_name_len )
{
union smb_open io ;
char * fname , * fname2 = NULL , * ucs_name ;
2009-03-01 21:55:46 +03:00
size_t i ;
2004-03-26 05:39:48 +03:00
NTSTATUS status ;
2005-01-06 06:06:58 +03:00
ucs_name = talloc_size ( mem_ctx , ( 1 + u_name_len ) * 2 ) ;
2004-03-26 05:39:48 +03:00
if ( ! ucs_name ) {
2004-09-23 02:06:21 +04:00
printf ( " Failed to create UCS2 Name - talloc() failure \n " ) ;
2004-03-26 05:39:48 +03:00
return NT_STATUS_NO_MEMORY ;
}
for ( i = 0 ; i < u_name_len ; i + + ) {
SSVAL ( ucs_name , i * 2 , u_name [ i ] ) ;
}
SSVAL ( ucs_name , i * 2 , 0 ) ;
2011-03-25 00:37:00 +03:00
if ( ! convert_string_talloc_handle ( ucs_name , lpcfg_iconv_handle ( tctx - > lp_ctx ) , CH_UTF16 , CH_UNIX , ucs_name , ( 1 + u_name_len ) * 2 , ( void * * ) & fname , & i ) ) {
2006-10-16 17:06:41 +04:00
torture_comment ( tctx , " Failed to convert UCS2 Name into unix - convert_string_talloc() failure \n " ) ;
2004-09-23 02:06:21 +04:00
talloc_free ( ucs_name ) ;
2004-03-26 05:39:48 +03:00
return NT_STATUS_NO_MEMORY ;
}
2006-10-16 17:06:41 +04:00
fname2 = talloc_asprintf ( ucs_name , " %s%s " , BASEDIR , fname ) ;
2004-03-26 05:39:48 +03:00
if ( ! fname2 ) {
2004-09-23 02:06:21 +04:00
talloc_free ( ucs_name ) ;
2004-03-26 05:39:48 +03:00
return NT_STATUS_NO_MEMORY ;
}
io . generic . level = RAW_OPEN_NTCREATEX ;
io . ntcreatex . in . flags = NTCREATEX_FLAGS_EXTENDED ;
2009-10-15 11:26:19 +04:00
io . ntcreatex . in . root_fid . fnum = 0 ;
2004-12-02 07:37:36 +03:00
io . ntcreatex . in . access_mask = SEC_RIGHTS_FILE_ALL ;
2004-03-26 05:39:48 +03:00
io . ntcreatex . in . alloc_size = 0 ;
io . ntcreatex . in . file_attr = FILE_ATTRIBUTE_NORMAL ;
io . ntcreatex . in . share_access = NTCREATEX_SHARE_ACCESS_NONE ;
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_CREATE ;
io . ntcreatex . in . create_options = 0 ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
io . ntcreatex . in . fname = fname2 ;
io . ntcreatex . in . open_disposition = open_disposition ;
2007-09-02 06:07:55 +04:00
status = smb_raw_open ( tree , tctx , & io ) ;
2004-03-26 05:39:48 +03:00
2004-09-23 02:06:21 +04:00
talloc_free ( ucs_name ) ;
2004-03-26 05:39:48 +03:00
return status ;
}
/*
see if the server recognises composed characters
*/
2007-09-02 06:07:55 +04:00
static bool test_composed ( struct torture_context * tctx ,
struct smbcli_state * cli )
2004-03-26 05:39:48 +03:00
{
2004-05-25 20:24:13 +04:00
const uint32_t name1 [ ] = { 0x61 , 0x308 } ;
const uint32_t name2 [ ] = { 0xe4 } ;
2004-03-26 05:39:48 +03:00
NTSTATUS status1 , status2 ;
2007-09-02 06:07:55 +04:00
torture_assert ( tctx , torture_setup_dir ( cli , BASEDIR ) ,
" setting up basedir " ) ;
2004-03-26 05:39:48 +03:00
2007-09-02 06:07:55 +04:00
status1 = unicode_open ( tctx , cli - > tree , tctx , NTCREATEX_DISP_CREATE , name1 , 2 ) ;
torture_assert_ntstatus_ok ( tctx , status1 , " Failed to create composed name " ) ;
2004-03-26 05:39:48 +03:00
2007-09-02 06:07:55 +04:00
status2 = unicode_open ( tctx , cli - > tree , tctx , NTCREATEX_DISP_CREATE , name2 , 1 ) ;
torture_assert_ntstatus_ok ( tctx , status2 , " Failed to create accented character " ) ;
2004-03-26 05:39:48 +03:00
2007-09-02 06:07:55 +04:00
return true ;
2004-03-26 05:39:48 +03:00
}
/*
see if the server recognises a naked diacritical
*/
2007-09-02 06:07:55 +04:00
static bool test_diacritical ( struct torture_context * tctx ,
struct smbcli_state * cli )
2004-03-26 05:39:48 +03:00
{
2004-05-25 20:24:13 +04:00
const uint32_t name1 [ ] = { 0x308 } ;
const uint32_t name2 [ ] = { 0x308 , 0x308 } ;
2004-03-26 05:39:48 +03:00
NTSTATUS status1 , status2 ;
2007-09-02 06:07:55 +04:00
torture_assert ( tctx , torture_setup_dir ( cli , BASEDIR ) ,
" setting up basedir " ) ;
2004-03-26 05:39:48 +03:00
2007-09-02 06:07:55 +04:00
status1 = unicode_open ( tctx , cli - > tree , tctx , NTCREATEX_DISP_CREATE , name1 , 1 ) ;
torture_assert_ntstatus_ok ( tctx , status1 , " Failed to create naked diacritical " ) ;
2004-03-26 05:39:48 +03:00
/* try a double diacritical */
2007-09-02 06:07:55 +04:00
status2 = unicode_open ( tctx , cli - > tree , tctx , NTCREATEX_DISP_CREATE , name2 , 2 ) ;
2004-03-26 05:39:48 +03:00
2007-09-02 06:07:55 +04:00
torture_assert_ntstatus_ok ( tctx , status2 , " Failed to create double naked diacritical " ) ;
2004-03-26 05:39:48 +03:00
2007-09-02 06:07:55 +04:00
return true ;
2004-03-26 05:39:48 +03:00
}
/*
see if the server recognises a partial surrogate pair
*/
2007-09-02 06:07:55 +04:00
static bool test_surrogate ( struct torture_context * tctx ,
struct smbcli_state * cli )
2004-03-26 05:39:48 +03:00
{
2004-05-25 20:24:13 +04:00
const uint32_t name1 [ ] = { 0xd800 } ;
const uint32_t name2 [ ] = { 0xdc00 } ;
const uint32_t name3 [ ] = { 0xd800 , 0xdc00 } ;
2004-03-26 05:39:48 +03:00
NTSTATUS status ;
2007-09-02 06:07:55 +04:00
torture_assert ( tctx , torture_setup_dir ( cli , BASEDIR ) ,
" setting up basedir " ) ;
2004-03-26 05:39:48 +03:00
2007-09-02 06:07:55 +04:00
status = unicode_open ( tctx , cli - > tree , tctx , NTCREATEX_DISP_CREATE , name1 , 1 ) ;
2004-03-26 05:39:48 +03:00
2007-09-02 06:07:55 +04:00
torture_assert_ntstatus_ok ( tctx , status , " Failed to create partial surrogate 1 " ) ;
2004-03-26 05:39:48 +03:00
2007-09-02 06:07:55 +04:00
status = unicode_open ( tctx , cli - > tree , tctx , NTCREATEX_DISP_CREATE , name2 , 1 ) ;
2004-03-26 05:39:48 +03:00
2007-09-02 06:07:55 +04:00
torture_assert_ntstatus_ok ( tctx , status , " Failed to create partial surrogate 2 " ) ;
2004-03-26 05:39:48 +03:00
2007-09-02 06:07:55 +04:00
status = unicode_open ( tctx , cli - > tree , tctx , NTCREATEX_DISP_CREATE , name3 , 2 ) ;
2004-03-26 05:39:48 +03:00
2007-09-02 06:07:55 +04:00
torture_assert_ntstatus_ok ( tctx , status , " Failed to create full surrogate " ) ;
2004-03-26 05:39:48 +03:00
2007-09-02 06:07:55 +04:00
return true ;
2004-03-26 05:39:48 +03:00
}
/*
see if the server recognises wide - a characters
*/
2007-09-02 06:07:55 +04:00
static bool test_widea ( struct torture_context * tctx ,
struct smbcli_state * cli )
2004-03-26 05:39:48 +03:00
{
2004-05-25 20:24:13 +04:00
const uint32_t name1 [ ] = { ' a ' } ;
const uint32_t name2 [ ] = { 0xff41 } ;
const uint32_t name3 [ ] = { 0xff21 } ;
2004-03-26 05:39:48 +03:00
NTSTATUS status ;
2007-09-02 06:07:55 +04:00
torture_assert ( tctx , torture_setup_dir ( cli , BASEDIR ) ,
" setting up basedir " ) ;
2004-03-26 05:39:48 +03:00
2007-09-02 06:07:55 +04:00
status = unicode_open ( tctx , cli - > tree , tctx , NTCREATEX_DISP_CREATE , name1 , 1 ) ;
2004-03-26 05:39:48 +03:00
2007-09-02 06:07:55 +04:00
torture_assert_ntstatus_ok ( tctx , status , " Failed to create 'a' " ) ;
2004-03-26 05:39:48 +03:00
2007-09-02 06:07:55 +04:00
status = unicode_open ( tctx , cli - > tree , tctx , NTCREATEX_DISP_CREATE , name2 , 1 ) ;
2004-03-26 05:39:48 +03:00
2007-09-02 06:07:55 +04:00
torture_assert_ntstatus_ok ( tctx , status , " Failed to create wide-a " ) ;
2004-03-26 05:39:48 +03:00
2007-09-02 06:07:55 +04:00
status = unicode_open ( tctx , cli - > tree , tctx , NTCREATEX_DISP_CREATE , name3 , 1 ) ;
2004-03-26 05:39:48 +03:00
2007-09-02 06:07:55 +04:00
torture_assert_ntstatus_equal ( tctx , status , NT_STATUS_OBJECT_NAME_COLLISION ,
" Failed to create wide-A " ) ;
return true ;
2004-03-26 05:39:48 +03:00
}
2007-09-02 06:07:55 +04:00
struct torture_suite * torture_charset ( TALLOC_CTX * mem_ctx )
2004-03-26 05:39:48 +03:00
{
2010-12-11 05:26:31 +03:00
struct torture_suite * suite = torture_suite_create ( mem_ctx , " charset " ) ;
2004-03-26 05:39:48 +03:00
2007-09-02 06:07:55 +04:00
torture_suite_add_1smb_test ( suite , " Testing composite character (a umlaut) " , test_composed ) ;
torture_suite_add_1smb_test ( suite , " Testing naked diacritical (umlaut) " , test_diacritical ) ;
torture_suite_add_1smb_test ( suite , " Testing partial surrogate " , test_surrogate ) ;
torture_suite_add_1smb_test ( suite , " Testing wide-a " , test_widea ) ;
2004-03-26 05:39:48 +03:00
2007-09-02 06:07:55 +04:00
return suite ;
2004-03-26 05:39:48 +03:00
}