2005-11-15 07:38:59 +03:00
/*
Unix SMB / CIFS implementation .
SMB2 getinfo test suite
Copyright ( C ) Andrew Tridgell 2005
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
2005-11-15 07:38:59 +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/>.
2005-11-15 07:38:59 +03:00
*/
# include "includes.h"
# include "libcli/smb2/smb2.h"
# include "libcli/smb2/smb2_calls.h"
2006-03-25 19:01:28 +03:00
# include "torture/torture.h"
2006-02-04 17:08:24 +03:00
# include "torture/smb2/proto.h"
2005-11-15 07:38:59 +03:00
static struct {
const char * name ;
uint16_t level ;
NTSTATUS fstatus ;
NTSTATUS dstatus ;
2005-11-17 14:06:13 +03:00
union smb_fileinfo finfo ;
union smb_fileinfo dinfo ;
} file_levels [ ] = {
2005-11-15 07:38:59 +03:00
# define LEVEL(x) #x, x
2005-11-17 14:06:13 +03:00
{ LEVEL ( RAW_FILEINFO_BASIC_INFORMATION ) } ,
{ LEVEL ( RAW_FILEINFO_STANDARD_INFORMATION ) } ,
{ LEVEL ( RAW_FILEINFO_INTERNAL_INFORMATION ) } ,
{ LEVEL ( RAW_FILEINFO_EA_INFORMATION ) } ,
{ LEVEL ( RAW_FILEINFO_ACCESS_INFORMATION ) } ,
{ LEVEL ( RAW_FILEINFO_POSITION_INFORMATION ) } ,
{ LEVEL ( RAW_FILEINFO_MODE_INFORMATION ) } ,
{ LEVEL ( RAW_FILEINFO_ALIGNMENT_INFORMATION ) } ,
{ LEVEL ( RAW_FILEINFO_ALL_INFORMATION ) } ,
{ LEVEL ( RAW_FILEINFO_ALT_NAME_INFORMATION ) } ,
{ LEVEL ( RAW_FILEINFO_STREAM_INFORMATION ) } ,
{ LEVEL ( RAW_FILEINFO_COMPRESSION_INFORMATION ) } ,
{ LEVEL ( RAW_FILEINFO_NETWORK_OPEN_INFORMATION ) } ,
{ LEVEL ( RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION ) } ,
2009-07-14 15:32:23 +04:00
2008-05-22 08:50:36 +04:00
{ LEVEL ( RAW_FILEINFO_SMB2_ALL_EAS ) } ,
2009-07-14 15:32:23 +04:00
2005-11-17 14:06:13 +03:00
{ LEVEL ( RAW_FILEINFO_SMB2_ALL_INFORMATION ) } ,
{ LEVEL ( RAW_FILEINFO_SEC_DESC ) }
} ;
static struct {
const char * name ;
uint16_t level ;
NTSTATUS status ;
union smb_fsinfo info ;
} fs_levels [ ] = {
{ LEVEL ( RAW_QFS_VOLUME_INFORMATION ) } ,
{ LEVEL ( RAW_QFS_SIZE_INFORMATION ) } ,
{ LEVEL ( RAW_QFS_DEVICE_INFORMATION ) } ,
{ LEVEL ( RAW_QFS_ATTRIBUTE_INFORMATION ) } ,
{ LEVEL ( RAW_QFS_QUOTA_INFORMATION ) } ,
{ LEVEL ( RAW_QFS_FULL_SIZE_INFORMATION ) } ,
{ LEVEL ( RAW_QFS_OBJECTID_INFORMATION ) }
2005-11-15 07:38:59 +03:00
} ;
# define FNAME "testsmb2_file.dat"
# define DNAME "testsmb2_dir"
2005-11-17 14:06:13 +03:00
/*
test fileinfo levels
2005-11-15 07:38:59 +03:00
*/
2007-12-03 17:53:17 +03:00
static bool torture_smb2_fileinfo ( struct torture_context * tctx , struct smb2_tree * tree )
2005-11-15 07:38:59 +03:00
{
struct smb2_handle hfile , hdir ;
NTSTATUS status ;
int i ;
status = torture_smb2_testfile ( tree , FNAME , & hfile ) ;
2012-02-28 17:19:49 +04:00
torture_assert_ntstatus_ok ( tctx , status , " Unable to create test file "
FNAME " \n " ) ;
2005-11-15 07:38:59 +03:00
status = torture_smb2_testdir ( tree , DNAME , & hdir ) ;
2012-02-28 17:19:49 +04:00
torture_assert_ntstatus_ok ( tctx , status , " Unable to create test dir "
DNAME " \n " ) ;
2005-11-15 07:38:59 +03:00
2005-11-19 08:55:08 +03:00
printf ( " Testing file info levels \n " ) ;
2005-11-15 07:38:59 +03:00
torture_smb2_all_info ( tree , hfile ) ;
torture_smb2_all_info ( tree , hdir ) ;
2005-11-17 14:06:13 +03:00
for ( i = 0 ; i < ARRAY_SIZE ( file_levels ) ; i + + ) {
if ( file_levels [ i ] . level = = RAW_FILEINFO_SEC_DESC ) {
2006-03-10 23:49:20 +03:00
file_levels [ i ] . finfo . query_secdesc . in . secinfo_flags = 0x7 ;
file_levels [ i ] . dinfo . query_secdesc . in . secinfo_flags = 0x7 ;
2005-11-15 07:38:59 +03:00
}
2005-11-19 08:55:08 +03:00
if ( file_levels [ i ] . level = = RAW_FILEINFO_SMB2_ALL_EAS ) {
2012-02-28 17:19:49 +04:00
file_levels [ i ] . finfo . all_eas . in . continue_flags =
2005-11-19 09:39:12 +03:00
SMB2_CONTINUE_FLAG_RESTART ;
2012-02-28 17:19:49 +04:00
file_levels [ i ] . dinfo . all_eas . in . continue_flags =
2005-11-19 09:39:12 +03:00
SMB2_CONTINUE_FLAG_RESTART ;
2005-11-19 08:55:08 +03:00
}
2005-11-17 14:06:13 +03:00
file_levels [ i ] . finfo . generic . level = file_levels [ i ] . level ;
2006-03-13 01:48:25 +03:00
file_levels [ i ] . finfo . generic . in . file . handle = hfile ;
2005-11-17 14:06:13 +03:00
file_levels [ i ] . fstatus = smb2_getinfo_file ( tree , tree , & file_levels [ i ] . finfo ) ;
2012-02-28 17:19:49 +04:00
torture_assert_ntstatus_ok ( tctx , file_levels [ i ] . fstatus ,
talloc_asprintf ( tctx , " %s on file " ,
file_levels [ i ] . name ) ) ;
2005-11-17 14:06:13 +03:00
file_levels [ i ] . dinfo . generic . level = file_levels [ i ] . level ;
2006-03-13 01:48:25 +03:00
file_levels [ i ] . dinfo . generic . in . file . handle = hdir ;
2005-11-17 14:06:13 +03:00
file_levels [ i ] . dstatus = smb2_getinfo_file ( tree , tree , & file_levels [ i ] . dinfo ) ;
2012-02-28 17:19:49 +04:00
torture_assert_ntstatus_ok ( tctx , file_levels [ i ] . dstatus ,
talloc_asprintf ( tctx , " %s on dir " ,
file_levels [ i ] . name ) ) ;
2005-11-15 07:38:59 +03:00
}
2007-10-07 02:28:14 +04:00
return true ;
2005-11-15 07:38:59 +03:00
}
2005-11-17 14:06:13 +03:00
/*
test fsinfo levels
*/
2012-02-28 17:19:49 +04:00
static bool torture_smb2_fsinfo ( struct torture_context * tctx , struct smb2_tree * tree )
2005-11-17 14:06:13 +03:00
{
int i ;
NTSTATUS status ;
struct smb2_handle handle ;
2005-11-19 08:55:08 +03:00
printf ( " Testing fsinfo levels \n " ) ;
status = smb2_util_roothandle ( tree , & handle ) ;
2012-02-28 17:19:49 +04:00
torture_assert_ntstatus_ok ( tctx , status , " Unable to create root handle " ) ;
2005-11-17 14:06:13 +03:00
for ( i = 0 ; i < ARRAY_SIZE ( fs_levels ) ; i + + ) {
fs_levels [ i ] . info . generic . level = fs_levels [ i ] . level ;
fs_levels [ i ] . info . generic . handle = handle ;
fs_levels [ i ] . status = smb2_getinfo_fs ( tree , tree , & fs_levels [ i ] . info ) ;
2012-02-28 17:19:49 +04:00
torture_assert_ntstatus_ok ( tctx , fs_levels [ i ] . status ,
fs_levels [ i ] . name ) ;
2005-11-17 14:06:13 +03:00
}
2007-10-07 02:28:14 +04:00
return true ;
2005-11-17 14:06:13 +03:00
}
2008-05-31 07:39:51 +04:00
/*
test for buffer size handling
*/
2012-02-28 17:19:49 +04:00
static bool torture_smb2_buffercheck ( struct torture_context * tctx , struct smb2_tree * tree )
2008-05-31 07:39:51 +04:00
{
NTSTATUS status ;
struct smb2_handle handle ;
struct smb2_getinfo b ;
printf ( " Testing buffer size handling \n " ) ;
status = smb2_util_roothandle ( tree , & handle ) ;
2012-02-28 17:19:49 +04:00
torture_assert_ntstatus_ok ( tctx , status , " Unable to create root handle " ) ;
2008-05-31 07:39:51 +04:00
ZERO_STRUCT ( b ) ;
b . in . info_type = SMB2_GETINFO_FS ;
b . in . info_class = 1 ;
b . in . output_buffer_length = 0x1 ;
b . in . input_buffer_length = 0 ;
b . in . file . handle = handle ;
status = smb2_getinfo ( tree , tree , & b ) ;
2012-02-28 17:19:49 +04:00
torture_assert_ntstatus_equal ( tctx , status ,
NT_STATUS_INFO_LENGTH_MISMATCH ,
" Wrong error code for small buffer " ) ;
2008-05-31 07:39:51 +04:00
return true ;
}
2005-11-17 14:06:13 +03:00
/* basic testing of all SMB2 getinfo levels
*/
2007-10-07 02:28:14 +04:00
bool torture_smb2_getinfo ( struct torture_context * torture )
2005-11-17 14:06:13 +03:00
{
TALLOC_CTX * mem_ctx = talloc_new ( NULL ) ;
struct smb2_tree * tree ;
2007-10-07 02:28:14 +04:00
bool ret = true ;
2005-11-18 12:51:13 +03:00
NTSTATUS status ;
2005-11-17 14:06:13 +03:00
2012-02-28 17:19:49 +04:00
ret = torture_smb2_connection ( torture , & tree ) ;
torture_assert ( torture , ret , " connection failed " ) ;
2005-11-17 14:06:13 +03:00
2008-05-22 08:50:36 +04:00
smb2_deltree ( tree , FNAME ) ;
smb2_deltree ( tree , DNAME ) ;
2005-11-18 12:51:13 +03:00
status = torture_setup_complex_file ( tree , FNAME ) ;
2012-02-28 17:19:49 +04:00
torture_assert_ntstatus_ok ( torture , status ,
" setup complex file " FNAME ) ;
2012-03-06 14:48:52 +04:00
status = torture_setup_complex_file ( tree , FNAME " :streamtwo " ) ;
torture_assert_ntstatus_ok ( torture , status ,
" setup complex file " FNAME " :streamtwo " ) ;
2012-02-28 17:19:49 +04:00
2005-11-18 12:51:13 +03:00
status = torture_setup_complex_dir ( tree , DNAME ) ;
2012-02-28 17:19:49 +04:00
torture_assert_ntstatus_ok ( torture , status ,
" setup complex dir " DNAME ) ;
2012-03-06 14:48:52 +04:00
status = torture_setup_complex_file ( tree , DNAME " :streamtwo " ) ;
torture_assert_ntstatus_ok ( torture , status ,
" setup complex dir " DNAME " :streamtwo " ) ;
2005-11-17 14:06:13 +03:00
2007-12-03 17:53:17 +03:00
ret & = torture_smb2_fileinfo ( torture , tree ) ;
2012-02-28 17:19:49 +04:00
ret & = torture_smb2_fsinfo ( torture , tree ) ;
ret & = torture_smb2_buffercheck ( torture , tree ) ;
2005-11-17 14:06:13 +03:00
talloc_free ( mem_ctx ) ;
return ret ;
}