2011-03-18 00:36:39 +01:00
/*
2004-11-15 06:55:27 +00:00
Unix SMB / CIFS implementation .
test DOS extended attributes
Copyright ( C ) Andrew Tridgell 2004
2005-06-30 01:36:02 +00:00
Copyright ( C ) Guenter Kukkukk 2005
2011-03-18 00:36:39 +01:00
2004-11-15 06:55:27 +00:00
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
2004-11-15 06:55:27 +00:00
( at your option ) any later version .
2011-03-18 00:36:39 +01:00
2004-11-15 06:55:27 +00:00
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 .
2011-03-18 00:36:39 +01:00
2004-11-15 06:55:27 +00:00
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/>.
2004-11-15 06:55:27 +00:00
*/
# include "includes.h"
2006-01-03 13:41:17 +00:00
# include "torture/torture.h"
2004-11-15 06:55:27 +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"
2004-11-15 06:55:27 +00:00
# define BASEDIR "\\testeas"
# define CHECK_STATUS(status, correct) do { \
2011-03-17 21:49:23 +01:00
torture_assert_ntstatus_equal_goto ( tctx , status , correct , ret , done , " Incorrect status " ) ; \
} while ( 0 )
2004-11-15 06:55:27 +00:00
2007-10-06 22:28:14 +00:00
static bool maxeadebug ; /* need that here, to allow no file delete in debug case */
2005-06-30 01:36:02 +00:00
2011-03-18 00:36:39 +01:00
static bool check_ea ( struct smbcli_state * cli ,
2004-12-13 10:48:21 +00:00
const char * fname , const char * eaname , const char * value )
{
NTSTATUS status = torture_check_ea ( cli , fname , eaname , value ) ;
return NT_STATUS_IS_OK ( status ) ;
}
2004-11-15 06:55:27 +00:00
2013-07-09 16:37:48 -07:00
static char bad_ea_chars [ ] = " \" *+,/:;<=>?[ \\ ]| " ;
2011-03-17 21:08:03 +01:00
static bool test_eas ( struct smbcli_state * cli , struct torture_context * tctx )
2004-11-15 06:55:27 +00:00
{
NTSTATUS status ;
union smb_setfileinfo setfile ;
union smb_open io ;
const char * fname = BASEDIR " \\ ea.txt " ;
2007-10-06 22:28:14 +00:00
bool ret = true ;
2014-09-02 14:38:11 +12:00
char bad_ea_name [ 7 ] ;
2013-07-09 16:37:48 -07:00
int i ;
2004-12-02 04:51:56 +00:00
int fnum = - 1 ;
2004-11-15 06:55:27 +00:00
2011-03-17 21:49:23 +01:00
torture_comment ( tctx , " TESTING SETFILEINFO EA_SET \n " ) ;
2004-11-17 22:00:15 +00:00
2004-11-15 06:55:27 +00:00
io . generic . level = RAW_OPEN_NTCREATEX ;
2009-10-15 18:26:19 +11:00
io . ntcreatex . in . root_fid . fnum = 0 ;
2004-11-15 06:55:27 +00:00
io . ntcreatex . in . flags = 0 ;
2004-12-02 04:37:36 +00:00
io . ntcreatex . in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
2004-11-15 06:55:27 +00:00
io . ntcreatex . in . create_options = 0 ;
io . ntcreatex . in . file_attr = FILE_ATTRIBUTE_NORMAL ;
2011-03-18 00:36:39 +01:00
io . ntcreatex . in . share_access =
NTCREATEX_SHARE_ACCESS_READ |
2004-11-15 06:55:27 +00:00
NTCREATEX_SHARE_ACCESS_WRITE ;
io . ntcreatex . in . alloc_size = 0 ;
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_CREATE ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
io . ntcreatex . in . fname = fname ;
2011-03-17 21:08:03 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2004-11-15 06:55:27 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum = io . ntcreatex . out . file . fnum ;
2011-03-18 00:36:39 +01:00
2004-12-13 10:48:21 +00:00
ret & = check_ea ( cli , fname , " EAONE " , NULL ) ;
2004-11-15 06:55:27 +00:00
2011-03-17 21:49:23 +01:00
torture_comment ( tctx , " Adding first two EAs \n " ) ;
2004-11-15 06:55:27 +00:00
setfile . generic . level = RAW_SFILEINFO_EA_SET ;
2006-03-12 22:48:25 +00:00
setfile . generic . in . file . fnum = fnum ;
2004-12-17 04:51:23 +00:00
setfile . ea_set . in . num_eas = 2 ;
2011-03-17 21:08:03 +01:00
setfile . ea_set . in . eas = talloc_array ( tctx , struct ea_struct , 2 ) ;
2004-12-17 04:51:23 +00:00
setfile . ea_set . in . eas [ 0 ] . flags = 0 ;
setfile . ea_set . in . eas [ 0 ] . name . s = " EAONE " ;
setfile . ea_set . in . eas [ 0 ] . value = data_blob_string_const ( " VALUE1 " ) ;
setfile . ea_set . in . eas [ 1 ] . flags = 0 ;
setfile . ea_set . in . eas [ 1 ] . name . s = " SECONDEA " ;
setfile . ea_set . in . eas [ 1 ] . value = data_blob_string_const ( " ValueTwo " ) ;
2004-11-15 06:55:27 +00:00
status = smb_raw_setfileinfo ( cli - > tree , & setfile ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2004-12-13 10:48:21 +00:00
ret & = check_ea ( cli , fname , " EAONE " , " VALUE1 " ) ;
ret & = check_ea ( cli , fname , " SECONDEA " , " ValueTwo " ) ;
2004-11-15 06:55:27 +00:00
2011-03-17 21:49:23 +01:00
torture_comment ( tctx , " Modifying 2nd EA \n " ) ;
2004-12-17 04:51:23 +00:00
setfile . ea_set . in . num_eas = 1 ;
setfile . ea_set . in . eas [ 0 ] . name . s = " SECONDEA " ;
setfile . ea_set . in . eas [ 0 ] . value = data_blob_string_const ( " Changed Value " ) ;
2004-11-15 06:55:27 +00:00
status = smb_raw_setfileinfo ( cli - > tree , & setfile ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2004-12-13 10:48:21 +00:00
ret & = check_ea ( cli , fname , " EAONE " , " VALUE1 " ) ;
ret & = check_ea ( cli , fname , " SECONDEA " , " Changed Value " ) ;
2004-11-15 06:55:27 +00:00
2011-03-17 21:49:23 +01:00
torture_comment ( tctx , " Setting a NULL EA \n " ) ;
2004-12-17 04:51:23 +00:00
setfile . ea_set . in . eas [ 0 ] . value = data_blob ( NULL , 0 ) ;
setfile . ea_set . in . eas [ 0 ] . name . s = " NULLEA " ;
2004-11-15 06:55:27 +00:00
status = smb_raw_setfileinfo ( cli - > tree , & setfile ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2004-12-13 10:48:21 +00:00
ret & = check_ea ( cli , fname , " EAONE " , " VALUE1 " ) ;
ret & = check_ea ( cli , fname , " SECONDEA " , " Changed Value " ) ;
ret & = check_ea ( cli , fname , " NULLEA " , NULL ) ;
2004-11-15 06:55:27 +00:00
2011-03-17 21:49:23 +01:00
torture_comment ( tctx , " Deleting first EA \n " ) ;
2004-12-17 04:51:23 +00:00
setfile . ea_set . in . eas [ 0 ] . flags = 0 ;
setfile . ea_set . in . eas [ 0 ] . name . s = " EAONE " ;
setfile . ea_set . in . eas [ 0 ] . value = data_blob ( NULL , 0 ) ;
2004-11-15 06:55:27 +00:00
status = smb_raw_setfileinfo ( cli - > tree , & setfile ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2004-12-13 10:48:21 +00:00
ret & = check_ea ( cli , fname , " EAONE " , NULL ) ;
ret & = check_ea ( cli , fname , " SECONDEA " , " Changed Value " ) ;
2004-11-15 06:55:27 +00:00
2011-03-17 21:49:23 +01:00
torture_comment ( tctx , " Deleting second EA \n " ) ;
2004-12-17 04:51:23 +00:00
setfile . ea_set . in . eas [ 0 ] . flags = 0 ;
setfile . ea_set . in . eas [ 0 ] . name . s = " SECONDEA " ;
setfile . ea_set . in . eas [ 0 ] . value = data_blob ( NULL , 0 ) ;
2004-11-15 06:55:27 +00:00
status = smb_raw_setfileinfo ( cli - > tree , & setfile ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2004-12-13 10:48:21 +00:00
ret & = check_ea ( cli , fname , " EAONE " , NULL ) ;
ret & = check_ea ( cli , fname , " SECONDEA " , NULL ) ;
2004-11-15 06:55:27 +00:00
2013-07-09 16:37:48 -07:00
/* Check EA name containing colon. All EA's set
must be ignored , not just the one with the bad
name . */
torture_comment ( tctx , " Adding bad EA name \n " ) ;
setfile . generic . level = RAW_SFILEINFO_EA_SET ;
setfile . generic . in . file . fnum = fnum ;
setfile . ea_set . in . num_eas = 3 ;
setfile . ea_set . in . eas = talloc_array ( tctx , struct ea_struct , 3 ) ;
setfile . ea_set . in . eas [ 0 ] . flags = 0 ;
setfile . ea_set . in . eas [ 0 ] . name . s = " EAONE " ;
setfile . ea_set . in . eas [ 0 ] . value = data_blob_string_const ( " VALUE1 " ) ;
setfile . ea_set . in . eas [ 1 ] . flags = 0 ;
setfile . ea_set . in . eas [ 1 ] . name . s = " SECOND:EA " ;
setfile . ea_set . in . eas [ 1 ] . value = data_blob_string_const ( " ValueTwo " ) ;
setfile . ea_set . in . eas [ 2 ] . flags = 0 ;
setfile . ea_set . in . eas [ 2 ] . name . s = " THIRDEA " ;
setfile . ea_set . in . eas [ 2 ] . value = data_blob_string_const ( " ValueThree " ) ;
status = smb_raw_setfileinfo ( cli - > tree , & setfile ) ;
CHECK_STATUS ( status , STATUS_INVALID_EA_NAME ) ;
ret & = check_ea ( cli , fname , " EAONE " , NULL ) ;
ret & = check_ea ( cli , fname , " THIRDEA " , NULL ) ;
setfile . generic . level = RAW_SFILEINFO_EA_SET ;
setfile . generic . in . file . fnum = fnum ;
setfile . ea_set . in . num_eas = 1 ;
setfile . ea_set . in . eas = talloc_array ( tctx , struct ea_struct , 1 ) ;
setfile . ea_set . in . eas [ 0 ] . flags = 0 ;
strlcpy ( bad_ea_name , " TEST_X " , sizeof ( bad_ea_name ) ) ;
setfile . ea_set . in . eas [ 0 ] . name . s = bad_ea_name ;
torture_comment ( tctx , " Testing bad EA name range. \n " ) ;
for ( i = 1 ; i < 256 ; i + + ) {
setfile . ea_set . in . eas [ 0 ] . value = data_blob_string_const ( " VALUE1 " ) ;
bad_ea_name [ 5 ] = ( char ) i ;
torture_comment ( tctx , " Testing bad EA name %d. \n " , i ) ;
status = smb_raw_setfileinfo ( cli - > tree , & setfile ) ;
if ( i < 32 | | strchr ( bad_ea_chars , i ) ) {
CHECK_STATUS ( status , STATUS_INVALID_EA_NAME ) ;
} else {
CHECK_STATUS ( status , NT_STATUS_OK ) ;
/* Now delete the EA we just set to make
sure we don ' t run out of room . */
setfile . ea_set . in . eas [ 0 ] . value = data_blob ( NULL , 0 ) ;
status = smb_raw_setfileinfo ( cli - > tree , & setfile ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
}
}
2004-11-15 06:55:27 +00:00
done :
smbcli_close ( cli - > tree , fnum ) ;
2004-11-17 22:00:15 +00:00
return ret ;
}
2005-06-30 01:36:02 +00:00
/*
* Helper function to retrieve the max . ea size for one ea name
*/
2011-03-17 21:49:23 +01:00
static int test_one_eamax ( struct torture_context * tctx ,
struct smbcli_state * cli , const int fnum ,
2011-03-18 00:36:39 +01:00
const char * eaname , DATA_BLOB eablob ,
const int eastart , const int eadebug )
2005-06-30 01:36:02 +00:00
{
NTSTATUS status ;
struct ea_struct eastruct ;
union smb_setfileinfo setfile ;
int i , high , low , maxeasize ;
setfile . generic . level = RAW_SFILEINFO_EA_SET ;
2006-03-12 22:48:25 +00:00
setfile . generic . in . file . fnum = fnum ;
2005-06-30 01:36:02 +00:00
setfile . ea_set . in . num_eas = 1 ;
setfile . ea_set . in . eas = & eastruct ;
setfile . ea_set . in . eas - > flags = 0 ;
setfile . ea_set . in . eas - > name . s = eaname ;
setfile . ea_set . in . eas - > value = eablob ;
maxeasize = eablob . length ;
i = eastart ;
low = 0 ;
high = maxeasize ;
do {
if ( eadebug ) {
2011-03-17 21:49:23 +01:00
torture_comment ( tctx , " Testing EA size: %d \n " , i ) ;
2005-06-30 01:36:02 +00:00
}
setfile . ea_set . in . eas - > value . length = i ;
status = smb_raw_setfileinfo ( cli - > tree , & setfile ) ;
if ( NT_STATUS_EQUAL ( status , NT_STATUS_OK ) ) {
if ( eadebug ) {
2011-03-17 21:49:23 +01:00
torture_comment ( tctx , " [%s] EA size %d succeeded! "
2011-03-18 00:36:39 +01:00
" (high=%d low=%d) \n " ,
2005-06-30 01:36:02 +00:00
eaname , i , high , low ) ;
}
low = i ;
if ( low = = maxeasize ) {
2011-03-17 21:49:23 +01:00
torture_comment ( tctx , " Max. EA size for \" %s \" =%d "
2011-03-18 00:36:39 +01:00
" [but could be possibly larger] \n " ,
2005-06-30 01:36:02 +00:00
eaname , low ) ;
break ;
}
if ( high - low = = 1 & & high ! = maxeasize ) {
2011-03-17 21:49:23 +01:00
torture_comment ( tctx , " Max. EA size for \" %s \" =%d \n " ,
2005-06-30 01:36:02 +00:00
eaname , low ) ;
break ;
}
i + = ( high - low + 1 ) / 2 ;
} else {
if ( eadebug ) {
2011-03-17 21:49:23 +01:00
torture_comment ( tctx , " [%s] EA size %d failed! "
2011-03-18 00:36:39 +01:00
" (high=%d low=%d) [%s] \n " ,
eaname , i , high , low ,
2005-06-30 01:36:02 +00:00
nt_errstr ( status ) ) ;
}
high = i ;
if ( high - low < = 1 ) {
2011-03-17 21:49:23 +01:00
torture_comment ( tctx , " Max. EA size for \" %s \" =%d \n " ,
2005-06-30 01:36:02 +00:00
eaname , low ) ;
break ;
}
i - = ( high - low + 1 ) / 2 ;
}
2007-10-06 22:28:14 +00:00
} while ( true ) ;
2005-06-30 01:36:02 +00:00
return low ;
}
/*
* Test for maximum ea size - more than one ea name is checked .
*
* Additional parameters can be passed , to allow further testing :
*
* default
* maxeasize 65536 limit the max . size for a single EA name
* maxeanames 101 limit of the number of tested names
* maxeastart 1 this EA size is used to test for the 1 st EA ( atm )
2007-10-06 22:28:14 +00:00
* maxeadebug 0 if set true , further debug output is done - in addition
2005-06-30 01:36:02 +00:00
* the testfile is not deleted for further inspection !
*
* Set some / all of these options on the cmdline with :
* - - option torture : maxeasize = 1024 - - option torture : maxeadebug = 1 . . .
*
*/
2007-12-03 00:28:22 +01:00
static bool test_max_eas ( struct smbcli_state * cli , struct torture_context * tctx )
2005-06-30 01:36:02 +00:00
{
NTSTATUS status ;
union smb_open io ;
const char * fname = BASEDIR " \\ ea_max.txt " ;
int fnum = - 1 ;
2007-10-06 22:28:14 +00:00
bool ret = true ;
bool err = false ;
2005-06-30 01:36:02 +00:00
2018-12-19 14:37:33 +13:00
int i , j , k , last ;
size_t total ;
2005-06-30 01:36:02 +00:00
DATA_BLOB eablob ;
char * eaname = NULL ;
int maxeasize ;
int maxeanames ;
int maxeastart ;
2011-03-17 21:49:23 +01:00
torture_comment ( tctx , " TESTING SETFILEINFO MAX. EA_SET \n " ) ;
2005-06-30 01:36:02 +00:00
2007-12-03 00:28:22 +01:00
maxeasize = torture_setting_int ( tctx , " maxeasize " , 65536 ) ;
maxeanames = torture_setting_int ( tctx , " maxeanames " , 101 ) ;
maxeastart = torture_setting_int ( tctx , " maxeastart " , 1 ) ;
2016-02-05 11:14:58 +01:00
maxeadebug = torture_setting_bool ( tctx , " maxeadebug " , false ) ;
2005-06-30 01:36:02 +00:00
/* Do some sanity check on possibly passed parms */
if ( maxeasize < = 0 ) {
2011-03-17 21:49:23 +01:00
torture_comment ( tctx , " Invalid parameter 'maxeasize=%d' " , maxeasize ) ;
2007-10-06 22:28:14 +00:00
err = true ;
2005-06-30 01:36:02 +00:00
}
if ( maxeanames < = 0 ) {
2011-03-17 21:49:23 +01:00
torture_comment ( tctx , " Invalid parameter 'maxeanames=%d' " , maxeanames ) ;
2007-10-06 22:28:14 +00:00
err = true ;
2005-06-30 01:36:02 +00:00
}
if ( maxeastart < = 0 ) {
2011-03-17 21:49:23 +01:00
torture_comment ( tctx , " Invalid parameter 'maxeastart=%d' " , maxeastart ) ;
2007-10-06 22:28:14 +00:00
err = true ;
2005-06-30 01:36:02 +00:00
}
if ( err ) {
2011-03-17 21:49:23 +01:00
torture_comment ( tctx , " \n \n " ) ;
2005-06-30 01:36:02 +00:00
goto done ;
}
if ( maxeastart > maxeasize ) {
maxeastart = maxeasize ;
2011-03-17 21:49:23 +01:00
torture_comment ( tctx , " 'maxeastart' outside range - corrected to %d \n " ,
2005-06-30 01:36:02 +00:00
maxeastart ) ;
}
2011-03-17 21:49:23 +01:00
torture_comment ( tctx , " MAXEA parms: maxeasize=%d maxeanames=%d maxeastart=%d "
2011-03-18 00:36:39 +01:00
" maxeadebug=%d \n " , maxeasize , maxeanames , maxeastart ,
2005-06-30 01:36:02 +00:00
maxeadebug ) ;
io . generic . level = RAW_OPEN_NTCREATEX ;
2009-10-15 18:26:19 +11:00
io . ntcreatex . in . root_fid . fnum = 0 ;
2005-06-30 01:36:02 +00:00
io . ntcreatex . in . flags = 0 ;
io . ntcreatex . in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
io . ntcreatex . in . create_options = 0 ;
io . ntcreatex . in . file_attr = FILE_ATTRIBUTE_NORMAL ;
2011-03-18 00:36:39 +01:00
io . ntcreatex . in . share_access =
NTCREATEX_SHARE_ACCESS_READ |
2005-06-30 01:36:02 +00:00
NTCREATEX_SHARE_ACCESS_WRITE ;
io . ntcreatex . in . alloc_size = 0 ;
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_CREATE ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
io . ntcreatex . in . fname = fname ;
2007-12-03 00:28:22 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2005-06-30 01:36:02 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum = io . ntcreatex . out . file . fnum ;
2011-03-18 00:36:39 +01:00
2007-12-03 00:28:22 +01:00
eablob = data_blob_talloc ( tctx , NULL , maxeasize ) ;
2005-06-30 01:36:02 +00:00
if ( eablob . data = = NULL ) {
goto done ;
}
2011-03-18 00:36:39 +01:00
/*
* Fill in some EA data - the offset could be easily checked
2005-06-30 01:36:02 +00:00
* during a hexdump .
*/
for ( i = 0 , k = 0 ; i < eablob . length / 4 ; i + + , k + = 4 ) {
eablob . data [ k ] = k & 0xff ;
eablob . data [ k + 1 ] = ( k > > 8 ) & 0xff ;
eablob . data [ k + 2 ] = ( k > > 16 ) & 0xff ;
eablob . data [ k + 3 ] = ( k > > 24 ) & 0xff ;
}
i = eablob . length % 4 ;
2011-03-18 00:36:39 +01:00
if ( i - - > 0 ) {
2005-06-30 01:36:02 +00:00
eablob . data [ k ] = k & 0xff ;
2011-03-18 00:36:39 +01:00
if ( i - - > 0 ) {
2005-06-30 01:36:02 +00:00
eablob . data [ k + 1 ] = ( k > > 8 ) & 0xff ;
2011-03-18 00:36:39 +01:00
if ( i - - > 0 ) {
2005-06-30 01:36:02 +00:00
eablob . data [ k + 2 ] = ( k > > 16 ) & 0xff ;
}
}
}
/*
* Filesystems might allow max . EAs data for different EA names .
* So more than one EA name should be checked .
*/
total = 0 ;
last = maxeastart ;
for ( i = 0 ; i < maxeanames ; i + + ) {
if ( eaname ! = NULL ) {
talloc_free ( eaname ) ;
}
2007-12-03 00:28:22 +01:00
eaname = talloc_asprintf ( tctx , " MAX%d " , i ) ;
2005-06-30 01:36:02 +00:00
if ( eaname = = NULL ) {
goto done ;
}
2011-03-17 21:49:23 +01:00
j = test_one_eamax ( tctx , cli , fnum , eaname , eablob , last , maxeadebug ) ;
2005-06-30 01:36:02 +00:00
if ( j < = 0 ) {
break ;
}
total + = j ;
last = j ;
}
2018-12-19 14:37:33 +13:00
torture_comment ( tctx , " Total EA size:%zu \n " , total ) ;
2005-06-30 01:36:02 +00:00
if ( i = = maxeanames ) {
2011-03-17 21:49:23 +01:00
torture_comment ( tctx , " NOTE: More EAs could be available! \n " ) ;
2011-03-18 00:36:39 +01:00
}
2005-06-30 01:36:02 +00:00
if ( total = = 0 ) {
2007-10-06 22:28:14 +00:00
ret = false ;
2005-06-30 01:36:02 +00:00
}
done :
smbcli_close ( cli - > tree , fnum ) ;
return ret ;
}
2004-11-17 22:00:15 +00:00
/*
test using NTTRANS CREATE to create a file with an initial EA set
*/
2011-03-17 21:08:03 +01:00
static bool test_nttrans_create ( struct smbcli_state * cli , struct torture_context * tctx )
2004-11-17 22:00:15 +00:00
{
NTSTATUS status ;
union smb_open io ;
const char * fname = BASEDIR " \\ ea2.txt " ;
2013-07-09 16:37:48 -07:00
const char * fname_bad = BASEDIR " \\ ea2_bad.txt " ;
2007-10-06 22:28:14 +00:00
bool ret = true ;
2004-11-17 22:00:15 +00:00
int fnum = - 1 ;
struct ea_struct eas [ 3 ] ;
struct smb_ea_list ea_list ;
2011-03-17 21:49:23 +01:00
torture_comment ( tctx , " TESTING NTTRANS CREATE WITH EAS \n " ) ;
2004-11-17 22:00:15 +00:00
io . generic . level = RAW_OPEN_NTTRANS_CREATE ;
2009-10-15 18:26:19 +11:00
io . ntcreatex . in . root_fid . fnum = 0 ;
2004-11-17 22:00:15 +00:00
io . ntcreatex . in . flags = 0 ;
2004-12-02 04:37:36 +00:00
io . ntcreatex . in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
2004-11-17 22:00:15 +00:00
io . ntcreatex . in . create_options = 0 ;
io . ntcreatex . in . file_attr = FILE_ATTRIBUTE_NORMAL ;
2011-03-18 00:36:39 +01:00
io . ntcreatex . in . share_access =
NTCREATEX_SHARE_ACCESS_READ |
2004-11-17 22:00:15 +00:00
NTCREATEX_SHARE_ACCESS_WRITE ;
io . ntcreatex . in . alloc_size = 0 ;
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_CREATE ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
io . ntcreatex . in . fname = fname ;
ea_list . num_eas = 3 ;
ea_list . eas = eas ;
eas [ 0 ] . flags = 0 ;
eas [ 0 ] . name . s = " 1st EA " ;
eas [ 0 ] . value = data_blob_string_const ( " Value One " ) ;
eas [ 1 ] . flags = 0 ;
eas [ 1 ] . name . s = " 2nd EA " ;
eas [ 1 ] . value = data_blob_string_const ( " Second Value " ) ;
eas [ 2 ] . flags = 0 ;
eas [ 2 ] . name . s = " and 3rd " ;
eas [ 2 ] . value = data_blob_string_const ( " final value " ) ;
io . ntcreatex . in . ea_list = & ea_list ;
io . ntcreatex . in . sec_desc = NULL ;
2011-03-17 21:08:03 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2004-11-17 22:00:15 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum = io . ntcreatex . out . file . fnum ;
2011-03-18 00:36:39 +01:00
2004-12-13 10:48:21 +00:00
ret & = check_ea ( cli , fname , " EAONE " , NULL ) ;
ret & = check_ea ( cli , fname , " 1st EA " , " Value One " ) ;
ret & = check_ea ( cli , fname , " 2nd EA " , " Second Value " ) ;
ret & = check_ea ( cli , fname , " and 3rd " , " final value " ) ;
2004-11-17 22:00:15 +00:00
2004-11-17 22:13:30 +00:00
smbcli_close ( cli - > tree , fnum ) ;
2011-03-17 21:49:23 +01:00
torture_comment ( tctx , " Trying to add EAs on non-create \n " ) ;
2004-11-17 22:13:30 +00:00
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_OPEN ;
io . ntcreatex . in . fname = fname ;
ea_list . num_eas = 1 ;
eas [ 0 ] . flags = 0 ;
eas [ 0 ] . name . s = " Fourth EA " ;
eas [ 0 ] . value = data_blob_string_const ( " Value Four " ) ;
2011-03-17 21:08:03 +01:00
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
2004-11-17 22:13:30 +00:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-12 22:48:25 +00:00
fnum = io . ntcreatex . out . file . fnum ;
2011-03-18 00:36:39 +01:00
2004-12-13 10:48:21 +00:00
ret & = check_ea ( cli , fname , " 1st EA " , " Value One " ) ;
ret & = check_ea ( cli , fname , " 2nd EA " , " Second Value " ) ;
ret & = check_ea ( cli , fname , " and 3rd " , " final value " ) ;
ret & = check_ea ( cli , fname , " Fourth EA " , NULL ) ;
2004-11-17 22:13:30 +00:00
2013-07-09 16:37:48 -07:00
torture_comment ( tctx , " TESTING NTTRANS CREATE WITH BAD EA NAMES \n " ) ;
io . generic . level = RAW_OPEN_NTTRANS_CREATE ;
io . ntcreatex . in . root_fid . fnum = 0 ;
io . ntcreatex . in . flags = 0 ;
io . ntcreatex . in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
io . ntcreatex . in . create_options = 0 ;
io . ntcreatex . in . file_attr = FILE_ATTRIBUTE_NORMAL ;
io . ntcreatex . in . share_access =
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE ;
io . ntcreatex . in . alloc_size = 0 ;
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_CREATE ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
io . ntcreatex . in . fname = fname_bad ;
ea_list . num_eas = 3 ;
ea_list . eas = eas ;
eas [ 0 ] . flags = 0 ;
eas [ 0 ] . name . s = " 1st EA " ;
eas [ 0 ] . value = data_blob_string_const ( " Value One " ) ;
eas [ 1 ] . flags = 0 ;
eas [ 1 ] . name . s = " 2nd:BAD:EA " ;
eas [ 1 ] . value = data_blob_string_const ( " Second Value " ) ;
eas [ 2 ] . flags = 0 ;
eas [ 2 ] . name . s = " and 3rd " ;
eas [ 2 ] . value = data_blob_string_const ( " final value " ) ;
io . ntcreatex . in . ea_list = & ea_list ;
io . ntcreatex . in . sec_desc = NULL ;
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
CHECK_STATUS ( status , STATUS_INVALID_EA_NAME ) ;
/* File must not exist. */
io . generic . level = RAW_OPEN_NTCREATEX ;
io . ntcreatex . in . root_fid . fnum = 0 ;
io . ntcreatex . in . flags = 0 ;
io . ntcreatex . in . access_mask = SEC_FLAG_MAXIMUM_ALLOWED ;
io . ntcreatex . in . create_options = 0 ;
io . ntcreatex . in . file_attr = FILE_ATTRIBUTE_NORMAL ;
io . ntcreatex . in . share_access =
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE ;
io . ntcreatex . in . alloc_size = 0 ;
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_OPEN ;
io . ntcreatex . in . impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS ;
io . ntcreatex . in . security_flags = 0 ;
io . ntcreatex . in . fname = fname_bad ;
status = smb_raw_open ( cli - > tree , tctx , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OBJECT_NAME_NOT_FOUND ) ;
2004-11-17 22:00:15 +00:00
done :
smbcli_close ( cli - > tree , fnum ) ;
return ret ;
2004-11-15 06:55:27 +00:00
}
2011-03-18 00:36:39 +01:00
/*
2004-11-15 06:55:27 +00:00
basic testing of EA calls
*/
2007-08-28 12:54:27 +00:00
bool torture_raw_eas ( struct torture_context * torture , struct smbcli_state * cli )
2004-11-15 06:55:27 +00:00
{
2007-09-08 16:46:30 +00:00
bool ret = true ;
2004-11-15 06:55:27 +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 ) ;
2004-11-15 06:55:27 +00:00
2007-08-28 12:54:27 +00:00
ret & = test_eas ( cli , torture ) ;
ret & = test_nttrans_create ( cli , torture ) ;
2004-11-15 06:55:27 +00:00
2005-07-01 11:50:30 +00:00
smb_raw_exit ( cli - > session ) ;
return ret ;
}
2011-03-18 00:36:39 +01:00
/*
2005-07-01 11:50:30 +00:00
test max EA size
*/
2007-09-07 15:08:14 +00:00
bool torture_max_eas ( struct torture_context * torture )
2005-07-01 11:50:30 +00:00
{
struct smbcli_state * cli ;
2007-10-06 22:28:14 +00:00
bool ret = true ;
2005-07-01 11:50:30 +00:00
2007-12-03 15:53:07 +01:00
if ( ! torture_open_connection ( & cli , torture , 0 ) ) {
2007-10-06 22:28:14 +00:00
return false ;
2005-07-01 11:50:30 +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 ) ;
2005-07-01 11:50:30 +00:00
2007-12-03 00:28:22 +01:00
ret & = test_max_eas ( cli , torture ) ;
2005-07-01 11:50:30 +00:00
2004-11-15 06:55:27 +00:00
smb_raw_exit ( cli - > session ) ;
2005-06-30 01:36:02 +00:00
if ( ! maxeadebug ) {
/* in no ea debug case, all files are gone now */
smbcli_deltree ( cli - > tree , BASEDIR ) ;
}
2004-11-15 06:55:27 +00:00
torture_close_connection ( cli ) ;
return ret ;
}