2003-08-13 01:53:07 +00:00
/*
Unix SMB / CIFS implementation .
chkpath individual test suite
Copyright ( C ) Andrew Tridgell 2003
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 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2003-08-13 01:53:07 +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 02:07:03 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2003-08-13 01:53:07 +00:00
*/
# include "includes.h"
2008-12-01 14:42:48 -08:00
# include "system/locale.h"
2005-12-28 15:38:36 +00:00
# include "libcli/raw/libcliraw.h"
2006-01-03 15:40:05 +00:00
# include "libcli/libcli.h"
2006-03-17 17:59:58 +00:00
# include "torture/util.h"
2011-03-19 00:42:42 +01:00
# include "torture/raw/proto.h"
2003-08-13 01:53:07 +00:00
# define BASEDIR "\\rawchkpath"
2005-07-06 03:13:17 +00:00
# define CHECK_STATUS(status, correct, dos_correct) do { \
if ( ! NT_STATUS_EQUAL ( status , correct ) & & ! NT_STATUS_EQUAL ( status , dos_correct ) ) { \
2003-08-13 01:53:07 +00:00
printf ( " (%d) Incorrect status %s - should be %s \n " , \
__LINE__ , nt_errstr ( status ) , nt_errstr ( correct ) ) ; \
2007-10-06 22:28:14 +00:00
ret = false ; \
2003-08-13 01:53:07 +00:00
goto done ; \
} } while ( 0 )
2004-09-03 20:06:27 +00:00
static NTSTATUS single_search ( struct smbcli_state * cli ,
TALLOC_CTX * mem_ctx , const char * pattern )
{
2006-07-06 08:00:24 +00:00
union smb_search_first io ;
NTSTATUS status ;
io . t2ffirst . level = RAW_SEARCH_TRANS2 ;
io . t2ffirst . data_level = RAW_SEARCH_DATA_STANDARD ;
2004-09-03 20:06:27 +00:00
io . t2ffirst . in . search_attrib = 0 ;
io . t2ffirst . in . max_count = 1 ;
io . t2ffirst . in . flags = FLAG_TRANS2_FIND_CLOSE ;
io . t2ffirst . in . storage_type = 0 ;
io . t2ffirst . in . pattern = pattern ;
status = smb_raw_search_first ( cli - > tree , mem_ctx ,
2006-07-06 08:00:24 +00:00
& io , NULL , NULL ) ;
return status ;
2004-09-03 20:06:27 +00:00
}
2008-02-29 08:15:50 +01:00
static bool test_path_ex ( struct smbcli_state * cli , struct torture_context * tctx ,
const char * path , const char * path_expected ,
NTSTATUS expected , NTSTATUS dos_expected )
2004-10-27 08:36:51 +00:00
{
2006-03-10 20:49:20 +00:00
union smb_chkpath io ;
2008-02-29 08:15:50 +01:00
union smb_fileinfo finfo ;
2004-10-27 08:36:51 +00:00
NTSTATUS status ;
2008-02-29 08:15:50 +01:00
2006-03-10 20:49:20 +00:00
io . chkpath . in . path = path ;
2004-10-27 08:36:51 +00:00
status = smb_raw_chkpath ( cli - > tree , & io ) ;
2005-07-06 03:13:17 +00:00
if ( ! NT_STATUS_EQUAL ( status , expected ) & & ! NT_STATUS_EQUAL ( status , dos_expected ) ) {
2008-02-29 08:15:50 +01:00
printf ( " FAILED %-30s chkpath %s should be %s or %s \n " ,
2005-07-06 03:13:17 +00:00
path , nt_errstr ( status ) , nt_errstr ( expected ) , nt_errstr ( dos_expected ) ) ;
2007-10-06 22:28:14 +00:00
return false ;
2004-10-27 08:36:51 +00:00
} else {
2008-02-29 08:15:50 +01:00
printf ( " %-30s chkpath correct (%s) \n " , path , nt_errstr ( status ) ) ;
}
if ( NT_STATUS_EQUAL ( expected , NT_STATUS_NOT_A_DIRECTORY ) ) {
expected = NT_STATUS_OK ;
}
ZERO_STRUCT ( finfo ) ;
finfo . generic . level = RAW_FILEINFO_NAME_INFO ;
finfo . generic . in . file . path = path ;
status = smb_raw_pathinfo ( cli - > tree , cli , & finfo ) ;
if ( ! NT_STATUS_EQUAL ( status , expected ) & & ! NT_STATUS_EQUAL ( status , dos_expected ) ) {
printf ( " FAILED: %-30s pathinfo %s should be %s or %s \n " ,
path , nt_errstr ( status ) , nt_errstr ( expected ) , nt_errstr ( dos_expected ) ) ;
return false ;
}
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " %-30s chkpath correct (%s) \n " , path , nt_errstr ( status ) ) ;
return true ;
}
2004-10-27 08:36:51 +00:00
2008-02-29 08:15:50 +01:00
if ( path_expected & &
( ! finfo . name_info . out . fname . s | |
strcmp ( finfo . name_info . out . fname . s , path_expected ) ! = 0 ) ) {
if ( tctx & & torture_setting_bool ( tctx , " samba4 " , false ) ) {
printf ( " IGNORE: %-30s => %-20s should be %s \n " ,
path , finfo . name_info . out . fname . s , path_expected ) ;
return true ;
}
printf ( " FAILED: %-30s => %-20s should be %s \n " ,
path , finfo . name_info . out . fname . s , path_expected ) ;
return false ;
2004-10-27 08:36:51 +00:00
}
2008-02-29 08:15:50 +01:00
printf ( " %-30s => %-20s correct \n " ,
path , finfo . name_info . out . fname . s ) ;
2007-10-06 22:28:14 +00:00
return true ;
2004-10-27 08:36:51 +00:00
}
2008-02-29 08:15:50 +01:00
static bool test_path ( struct smbcli_state * cli , const char * path ,
NTSTATUS expected , NTSTATUS dos_expected )
{
return test_path_ex ( cli , NULL , path , path , expected , dos_expected ) ;
}
static bool test_chkpath ( struct smbcli_state * cli , struct torture_context * tctx )
2003-08-13 01:53:07 +00:00
{
2006-03-10 20:49:20 +00:00
union smb_chkpath io ;
2003-08-13 01:53:07 +00:00
NTSTATUS status ;
2007-10-06 22:28:14 +00:00
bool ret = true ;
2003-08-13 01:53:07 +00:00
int fnum = - 1 ;
2006-03-10 20:49:20 +00:00
io . chkpath . in . path = BASEDIR ;
2003-08-13 01:53:07 +00:00
status = smb_raw_chkpath ( cli - > tree , & io ) ;
2005-07-06 03:13:17 +00:00
CHECK_STATUS ( status , NT_STATUS_OK , NT_STATUS_OK ) ;
2003-08-13 01:53:07 +00:00
2005-07-06 03:13:17 +00:00
ret & = test_path ( cli , BASEDIR " \\ nodir " , NT_STATUS_OBJECT_NAME_NOT_FOUND , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
2003-08-13 01:53:07 +00:00
2008-02-29 08:15:50 +01:00
fnum = create_complex_file ( cli , tctx , BASEDIR " \\ test.txt.. " ) ;
2003-08-13 01:53:07 +00:00
if ( fnum = = - 1 ) {
2004-08-04 13:23:35 +00:00
printf ( " failed to open test.txt - %s \n " , smbcli_errstr ( cli - > tree ) ) ;
2007-10-06 22:28:14 +00:00
ret = false ;
2003-08-13 01:53:07 +00:00
goto done ;
}
2005-07-06 03:13:17 +00:00
ret & = test_path ( cli , BASEDIR " \\ test.txt.. " , NT_STATUS_NOT_A_DIRECTORY , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
2003-08-13 01:53:07 +00:00
if ( ! torture_set_file_attribute ( cli - > tree , BASEDIR , FILE_ATTRIBUTE_HIDDEN ) ) {
printf ( " failed to set basedir hidden \n " ) ;
2007-10-06 22:28:14 +00:00
ret = false ;
2003-08-13 01:53:07 +00:00
goto done ;
}
2008-02-29 08:15:50 +01:00
ret & = test_path_ex ( cli , tctx , BASEDIR , BASEDIR , NT_STATUS_OK , NT_STATUS_OK ) ;
2008-10-08 17:19:46 +02:00
ret & = test_path_ex ( cli , tctx , ( ( const char * ) BASEDIR ) + 1 , BASEDIR , NT_STATUS_OK , NT_STATUS_OK ) ;
ret & = test_path_ex ( cli , tctx , ( ( const char * ) BASEDIR " \\ \\ " ) + 1 , BASEDIR , NT_STATUS_OK , NT_STATUS_OK ) ;
ret & = test_path_ex ( cli , tctx , ( ( const char * ) BASEDIR " \\ foo \\ .. " ) + 1 , BASEDIR , NT_STATUS_OK , NT_STATUS_OK ) ;
ret & = test_path_ex ( cli , tctx , ( ( const char * ) BASEDIR " \\ f \\ o \\ o \\ .. \\ .. \\ .. " ) + 1 , BASEDIR , NT_STATUS_OK , NT_STATUS_OK ) ;
ret & = test_path_ex ( cli , tctx , ( ( const char * ) BASEDIR " \\ foo \\ \\ .. \\ \\ " ) + 1 , BASEDIR , NT_STATUS_OK , NT_STATUS_OK ) ;
2008-02-29 08:15:50 +01:00
ret & = test_path_ex ( cli , tctx , BASEDIR " \\ " , BASEDIR , NT_STATUS_OK , NT_STATUS_OK ) ;
ret & = test_path_ex ( cli , tctx , BASEDIR " \\ \\ .. \\ " BASEDIR , BASEDIR , NT_STATUS_OK , NT_STATUS_OK ) ;
ret & = test_path_ex ( cli , tctx , BASEDIR " \\ \\ \\ " , BASEDIR , NT_STATUS_OK , NT_STATUS_OK ) ;
ret & = test_path_ex ( cli , tctx , " \\ \\ \\ \\ " BASEDIR " \\ \\ \\ \\ " , BASEDIR , NT_STATUS_OK , NT_STATUS_OK ) ;
ret & = test_path_ex ( cli , tctx , " \\ \\ \\ \\ " BASEDIR , BASEDIR , NT_STATUS_OK , NT_STATUS_OK ) ;
ret & = test_path_ex ( cli , tctx , BASEDIR " \\ foo \\ .. \\ test.txt.. " , BASEDIR " \\ test.txt.. " ,
NT_STATUS_NOT_A_DIRECTORY , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path_ex ( cli , tctx , " " , " \\ " , NT_STATUS_OK , NT_STATUS_OK ) ;
2005-07-06 03:13:17 +00:00
ret & = test_path ( cli , " . " , NT_STATUS_OBJECT_NAME_INVALID , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , " . \\ " , NT_STATUS_OBJECT_NAME_INVALID , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , " \\ \\ \\ . \\ " , NT_STATUS_OBJECT_NAME_INVALID , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , " . \\ . " , NT_STATUS_OBJECT_PATH_NOT_FOUND , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , " . " BASEDIR , NT_STATUS_OBJECT_PATH_NOT_FOUND , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , BASEDIR " \\ . " , NT_STATUS_OBJECT_NAME_INVALID , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , BASEDIR " \\ . \\ test.txt.. " , NT_STATUS_OBJECT_PATH_NOT_FOUND , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , " . \\ . \\ " , NT_STATUS_OBJECT_PATH_NOT_FOUND , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , " . \\ . \\ . " , NT_STATUS_OBJECT_PATH_NOT_FOUND , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , " . \\ . \\ .aaaaa " , NT_STATUS_OBJECT_PATH_NOT_FOUND , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , " \\ . \\ " , NT_STATUS_OBJECT_NAME_INVALID , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , " \\ . \\ \\ " , NT_STATUS_OBJECT_NAME_INVALID , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , " \\ . \\ \\ \\ \\ \\ \\ " , NT_STATUS_OBJECT_NAME_INVALID , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
2004-09-03 20:06:27 +00:00
/* Note that the two following paths are identical but
give different NT status returns for chkpth and findfirst . */
2010-04-11 01:39:06 +02:00
printf ( " Testing findfirst on %s \n " , " \\ . \\ \\ \\ \\ \\ \\ . " ) ;
2008-02-29 08:15:50 +01:00
status = single_search ( cli , tctx , " \\ . \\ \\ \\ \\ \\ \\ . " ) ;
2005-07-06 03:13:17 +00:00
CHECK_STATUS ( status , NT_STATUS_OBJECT_NAME_INVALID , NT_STATUS_DOS ( ERRDOS , ERRinvalidname ) ) ;
2004-09-03 20:06:27 +00:00
2005-07-06 03:13:17 +00:00
ret & = test_path ( cli , " \\ . \\ \\ \\ \\ \\ \\ . " , NT_STATUS_OBJECT_PATH_NOT_FOUND , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
2004-09-03 20:06:27 +00:00
/* We expect this open to fail with the same error code as the chkpath below. */
2010-04-11 01:39:06 +02:00
printf ( " Testing Open on %s \n " , " \\ . \\ \\ \\ \\ \\ \\ . " ) ;
2004-09-03 20:06:27 +00:00
/* findfirst seems to fail with a different error. */
2011-11-21 13:06:00 -08:00
( void ) smbcli_nt_create_full ( cli - > tree , " \\ . \\ \\ \\ \\ \\ \\ . " ,
2004-12-02 04:37:36 +00:00
0 , SEC_RIGHTS_FILE_ALL ,
2004-11-30 04:33:27 +00:00
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_DELETE |
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE ,
NTCREATEX_DISP_OVERWRITE_IF ,
0 , 0 ) ;
2004-09-03 20:06:27 +00:00
status = smbcli_nt_error ( cli - > tree ) ;
2005-07-06 03:13:17 +00:00
CHECK_STATUS ( status , NT_STATUS_OBJECT_PATH_NOT_FOUND , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , " \\ . \\ \\ xxx " , NT_STATUS_OBJECT_PATH_NOT_FOUND , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , " .. \\ .. \\ .. " , NT_STATUS_OBJECT_PATH_SYNTAX_BAD , NT_STATUS_DOS ( ERRDOS , ERRinvalidpath ) ) ;
ret & = test_path ( cli , " \\ .. " , NT_STATUS_OBJECT_PATH_SYNTAX_BAD , NT_STATUS_DOS ( ERRDOS , ERRinvalidpath ) ) ;
ret & = test_path ( cli , " \\ . \\ \\ \\ \\ \\ \\ xxx " , NT_STATUS_OBJECT_PATH_NOT_FOUND , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , BASEDIR " \\ . \\ " , NT_STATUS_OBJECT_NAME_INVALID , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , BASEDIR " \\ . \\ \\ " , NT_STATUS_OBJECT_NAME_INVALID , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , BASEDIR " \\ . \\ nt " , NT_STATUS_OBJECT_PATH_NOT_FOUND , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , BASEDIR " \\ . \\ . \\ nt " , NT_STATUS_OBJECT_PATH_NOT_FOUND , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , BASEDIR " \\ nt " , NT_STATUS_OK , NT_STATUS_OK ) ;
ret & = test_path ( cli , BASEDIR " . \\ foo " , NT_STATUS_OBJECT_PATH_NOT_FOUND , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , BASEDIR " xx \\ foo " , NT_STATUS_OBJECT_PATH_NOT_FOUND , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , " . \\ " , NT_STATUS_OBJECT_NAME_INVALID , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , " . \\ . " , NT_STATUS_OBJECT_PATH_NOT_FOUND , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , " . \\ . \\ . \\ . \\ foo \\ . \\ . \\ " , NT_STATUS_OBJECT_PATH_NOT_FOUND , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , BASEDIR " . \\ . \\ . \\ . \\ foo \\ . \\ . \\ " , NT_STATUS_OBJECT_PATH_NOT_FOUND , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , BASEDIR " . \\ . \\ . \\ . \\ foo \\ .. \\ . \\ " , NT_STATUS_OBJECT_PATH_NOT_FOUND , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , BASEDIR " . " , NT_STATUS_OBJECT_NAME_NOT_FOUND , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , " \\ " , NT_STATUS_OK , NT_STATUS_OK ) ;
ret & = test_path ( cli , " \\ . " , NT_STATUS_OBJECT_NAME_INVALID , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , " \\ .. \\ " , NT_STATUS_OBJECT_PATH_SYNTAX_BAD , NT_STATUS_DOS ( ERRDOS , ERRinvalidpath ) ) ;
ret & = test_path ( cli , " \\ .. " , NT_STATUS_OBJECT_PATH_SYNTAX_BAD , NT_STATUS_DOS ( ERRDOS , ERRinvalidpath ) ) ;
ret & = test_path ( cli , BASEDIR " \\ . " , NT_STATUS_OBJECT_NAME_INVALID , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
2008-02-29 08:15:50 +01:00
ret & = test_path_ex ( cli , tctx , BASEDIR " \\ .. " , " \\ " , NT_STATUS_OK , NT_STATUS_OK ) ;
2005-07-06 03:13:17 +00:00
ret & = test_path ( cli , BASEDIR " \\ nt \\ V S \\ VB98 \\ vb600 " , NT_STATUS_OBJECT_NAME_NOT_FOUND , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , BASEDIR " \\ nt \\ V S \\ VB98 \\ vb6.exe " , NT_STATUS_NOT_A_DIRECTORY , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
2004-06-10 01:08:54 +00:00
2004-08-31 21:34:14 +00:00
/* We expect this open to fail with the same error code as the chkpath below. */
2010-04-11 01:39:06 +02:00
printf ( " Testing Open on %s \n " , BASEDIR " . \\ . \\ . \\ . \\ foo \\ .. \\ . \\ " ) ;
2004-09-03 20:06:27 +00:00
/* findfirst seems to fail with a different error. */
2011-11-21 13:06:00 -08:00
( void ) smbcli_nt_create_full ( cli - > tree , BASEDIR " . \\ . \\ . \\ . \\ foo \\ .. \\ . \\ " ,
2004-12-02 04:37:36 +00:00
0 , SEC_RIGHTS_FILE_ALL ,
2004-11-30 04:33:27 +00:00
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_DELETE |
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE ,
NTCREATEX_DISP_OVERWRITE_IF ,
0 , 0 ) ;
2004-09-03 20:06:27 +00:00
status = smbcli_nt_error ( cli - > tree ) ;
2005-07-06 03:13:17 +00:00
CHECK_STATUS ( status , NT_STATUS_OBJECT_PATH_NOT_FOUND , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
2004-09-03 20:06:27 +00:00
2010-04-11 01:39:06 +02:00
printf ( " Testing findfirst on %s \n " , BASEDIR " . \\ . \\ . \\ . \\ foo \\ .. \\ . \\ " ) ;
2008-02-29 08:15:50 +01:00
status = single_search ( cli , tctx , BASEDIR " . \\ . \\ . \\ . \\ foo \\ .. \\ . \\ " ) ;
2005-07-06 03:13:17 +00:00
CHECK_STATUS ( status , NT_STATUS_OBJECT_PATH_NOT_FOUND , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
2004-09-03 20:06:27 +00:00
/* We expect this open to fail with the same error code as the chkpath below. */
/* findfirst seems to fail with a different error. */
2010-04-11 01:39:06 +02:00
printf ( " Testing Open on %s \n " , BASEDIR " \\ nt \\ V S \\ VB98 \\ vb6.exe \\ 3 " ) ;
2011-11-21 13:06:00 -08:00
( void ) smbcli_nt_create_full ( cli - > tree , BASEDIR " \\ nt \\ V S \\ VB98 \\ vb6.exe \\ 3 " ,
2004-12-02 04:37:36 +00:00
0 , SEC_RIGHTS_FILE_ALL ,
2004-11-30 04:33:27 +00:00
FILE_ATTRIBUTE_NORMAL ,
NTCREATEX_SHARE_ACCESS_DELETE |
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE ,
NTCREATEX_DISP_OVERWRITE_IF ,
0 , 0 ) ;
2004-08-31 21:34:14 +00:00
status = smbcli_nt_error ( cli - > tree ) ;
2005-07-06 03:13:17 +00:00
CHECK_STATUS ( status , NT_STATUS_OBJECT_PATH_NOT_FOUND , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
2004-08-31 21:34:14 +00:00
2005-07-06 03:13:17 +00:00
ret & = test_path ( cli , BASEDIR " \\ nt \\ V S \\ VB98 \\ vb6.exe \\ 3 " , NT_STATUS_OBJECT_PATH_NOT_FOUND , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , BASEDIR " \\ nt \\ V S \\ VB98 \\ vb6.exe \\ 3 \\ foo " , NT_STATUS_OBJECT_PATH_NOT_FOUND , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , BASEDIR " \\ nt \\ 3 \\ foo " , NT_STATUS_OBJECT_PATH_NOT_FOUND , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , BASEDIR " \\ nt \\ V S \\ * \\ vb6.exe \\ 3 " , NT_STATUS_OBJECT_NAME_INVALID , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
ret & = test_path ( cli , BASEDIR " \\ nt \\ V S \\ * \\ * \\ vb6.exe \\ 3 " , NT_STATUS_OBJECT_NAME_INVALID , NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ) ;
2004-06-10 23:17:22 +00:00
2003-08-13 01:53:07 +00:00
done :
2004-08-04 13:23:35 +00:00
smbcli_close ( cli - > tree , fnum ) ;
2003-08-13 01:53:07 +00:00
return ret ;
}
2008-12-01 14:42:48 -08:00
static bool test_chkpath_names ( struct smbcli_state * cli , struct torture_context * tctx )
{
union smb_chkpath io ;
union smb_fileinfo finfo ;
NTSTATUS status ;
bool ret = true ;
uint8_t i ;
/*
* we don ' t test characters > = 0x80 yet ,
* as somehow our client libraries can ' t do that
*/
for ( i = 0x01 ; i < = 0x7F ; i + + ) {
/*
* it ' s important that we test the last character
* because of the error code with ' : ' 0x3A
* and servers without stream support
*/
char * path = talloc_asprintf ( tctx , " %s \\ File0x%02X%c " ,
BASEDIR , i , i ) ;
NTSTATUS expected ;
NTSTATUS expected_dos1 ;
NTSTATUS expected_dos2 ;
expected = NT_STATUS_OBJECT_NAME_NOT_FOUND ;
expected_dos1 = NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ;
expected_dos2 = NT_STATUS_DOS ( ERRDOS , ERRbadfile ) ;
switch ( i ) {
case ' " ' : /*0x22*/
case ' * ' : /*0x2A*/
case ' / ' : /*0x2F*/
case ' : ' : /*0x3A*/
case ' < ' : /*0x3C*/
case ' > ' : /*0x3E*/
case ' ? ' : /*0x3F*/
case ' | ' : /*0x7C*/
if ( i = = ' / ' & &
2008-12-18 08:54:59 +01:00
torture_setting_bool ( tctx , " samba3 " , false ) ) {
2008-12-01 14:42:48 -08:00
/* samba 3 handles '/' as '\\' */
break ;
}
expected = NT_STATUS_OBJECT_NAME_INVALID ;
expected_dos1 = NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ;
expected_dos2 = NT_STATUS_DOS ( ERRDOS , ERRinvalidname ) ;
break ;
default :
if ( i < = 0x1F ) {
expected = NT_STATUS_OBJECT_NAME_INVALID ;
expected_dos1 = NT_STATUS_DOS ( ERRDOS , ERRbadpath ) ;
expected_dos2 = NT_STATUS_DOS ( ERRDOS , ERRinvalidname ) ;
}
break ;
}
printf ( " Checking File0x%02X%c%s expected[%s|%s|%s] \n " ,
i , isprint ( i ) ? ( char ) i : ' ' ,
isprint ( i ) ? " " : " (not printable) " ,
nt_errstr ( expected ) ,
nt_errstr ( expected_dos1 ) ,
nt_errstr ( expected_dos2 ) ) ;
io . chkpath . in . path = path ;
status = smb_raw_chkpath ( cli - > tree , & io ) ;
CHECK_STATUS ( status , expected , expected_dos1 ) ;
ZERO_STRUCT ( finfo ) ;
finfo . generic . level = RAW_FILEINFO_NAME_INFO ;
finfo . generic . in . file . path = path ;
status = smb_raw_pathinfo ( cli - > tree , cli , & finfo ) ;
CHECK_STATUS ( status , expected , expected_dos2 ) ;
talloc_free ( path ) ;
}
done :
return ret ;
}
2003-08-13 01:53:07 +00:00
/*
basic testing of chkpath calls
*/
2007-08-28 12:54:27 +00:00
bool torture_raw_chkpath ( struct torture_context * torture ,
2007-09-07 15:08:14 +00:00
struct smbcli_state * cli )
2003-08-13 01:53:07 +00:00
{
2007-08-28 12:54:27 +00:00
bool ret = true ;
2004-06-10 01:08:54 +00:00
int fnum ;
2003-08-13 01:53:07 +00:00
2012-05-18 15:43:31 +10:00
torture_assert ( torture , torture_setup_dir ( cli , BASEDIR ) , " Failed to setup up test directory: " BASEDIR ) ;
2003-08-13 01:53:07 +00:00
2004-08-04 13:23:35 +00:00
if ( NT_STATUS_IS_ERR ( smbcli_mkdir ( cli - > tree , BASEDIR " \\ nt " ) ) ) {
printf ( " Failed to create " BASEDIR " - %s \n " , smbcli_errstr ( cli - > tree ) ) ;
2007-10-06 22:28:14 +00:00
return false ;
2004-06-10 01:08:54 +00:00
}
2004-10-27 08:36:51 +00:00
if ( NT_STATUS_IS_ERR ( smbcli_mkdir ( cli - > tree , BASEDIR " \\ nt \\ V S " ) ) ) {
2004-08-04 13:23:35 +00:00
printf ( " Failed to create " BASEDIR " - %s \n " , smbcli_errstr ( cli - > tree ) ) ;
2007-10-06 22:28:14 +00:00
return false ;
2004-06-10 01:08:54 +00:00
}
2004-10-27 08:36:51 +00:00
if ( NT_STATUS_IS_ERR ( smbcli_mkdir ( cli - > tree , BASEDIR " \\ nt \\ V S \\ VB98 " ) ) ) {
2004-08-04 13:23:35 +00:00
printf ( " Failed to create " BASEDIR " - %s \n " , smbcli_errstr ( cli - > tree ) ) ;
2007-10-06 22:28:14 +00:00
return false ;
2004-06-10 01:08:54 +00:00
}
2007-08-28 12:54:27 +00:00
fnum = create_complex_file ( cli , torture , BASEDIR " \\ nt \\ V S \\ VB98 \\ vb6.exe " ) ;
2004-06-10 01:08:54 +00:00
if ( fnum = = - 1 ) {
2004-10-27 08:36:51 +00:00
printf ( " failed to open \\ nt \\ V S \\ VB98 \\ vb6.exe - %s \n " , smbcli_errstr ( cli - > tree ) ) ;
2007-10-06 22:28:14 +00:00
ret = false ;
2004-06-10 01:08:54 +00:00
goto done ;
}
2007-08-28 12:54:27 +00:00
ret & = test_chkpath ( cli , torture ) ;
2008-12-01 14:42:48 -08:00
ret & = test_chkpath_names ( cli , torture ) ;
2003-08-13 01:53:07 +00:00
2004-06-10 01:08:54 +00:00
done :
2003-08-13 01:53:07 +00:00
smb_raw_exit ( cli - > session ) ;
2004-08-04 13:23:35 +00:00
smbcli_deltree ( cli - > tree , BASEDIR ) ;
2003-08-13 01:53:07 +00:00
return ret ;
}