2004-11-15 09:55:27 +03:00
/*
Unix SMB / CIFS implementation .
test alternate data streams
Copyright ( C ) Andrew Tridgell 2004
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-11-15 09:55:27 +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-11-15 09:55:27 +03:00
*/
# include "includes.h"
2006-01-03 16:41:17 +03:00
# include "torture/torture.h"
2004-11-15 09:55:27 +03:00
# include "libcli/raw/libcliraw.h"
2005-02-10 08:09:35 +03:00
# include "system/filesys.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"
2004-11-15 09:55:27 +03:00
# define BASEDIR "\\teststreams"
# define CHECK_STATUS(status, correct) do { \
if ( ! NT_STATUS_EQUAL ( status , correct ) ) { \
printf ( " (%s) Incorrect status %s - should be %s \n " , \
__location__ , nt_errstr ( status ) , nt_errstr ( correct ) ) ; \
2007-10-07 02:28:14 +04:00
ret = false ; \
2004-11-15 09:55:27 +03:00
goto done ; \
} } while ( 0 )
# define CHECK_VALUE(v, correct) do { \
if ( ( v ) ! = ( correct ) ) { \
printf ( " (%s) Incorrect value %s=%d - should be %d \n " , \
2005-07-17 13:20:52 +04:00
__location__ , # v , ( int ) v , ( int ) correct ) ; \
2007-10-07 02:28:14 +04:00
ret = false ; \
2004-11-15 09:55:27 +03:00
} } while ( 0 )
/*
check that a stream has the right contents
*/
2007-11-19 17:01:03 +03:00
static bool check_stream ( struct smbcli_state * cli , const char * location ,
TALLOC_CTX * mem_ctx ,
2004-11-15 09:55:27 +03:00
const char * fname , const char * sname ,
const char * value )
{
int fnum ;
const char * full_name ;
2004-12-04 16:56:25 +03:00
uint8_t * buf ;
2004-11-15 09:55:27 +03:00
ssize_t ret ;
full_name = talloc_asprintf ( mem_ctx , " %s:%s " , fname , sname ) ;
fnum = smbcli_open ( cli - > tree , full_name , O_RDONLY , DENY_NONE ) ;
if ( value = = NULL ) {
if ( fnum ! = - 1 ) {
2007-11-19 17:01:03 +03:00
printf ( " (%s) should have failed stream open of %s \n " ,
location , full_name ) ;
2007-10-07 02:28:14 +04:00
return false ;
2004-11-15 09:55:27 +03:00
}
2007-10-07 02:28:14 +04:00
return true ;
2004-11-15 09:55:27 +03:00
}
if ( fnum = = - 1 ) {
2007-11-19 17:01:03 +03:00
printf ( " (%s) Failed to open stream '%s' - %s \n " ,
location , full_name , smbcli_errstr ( cli - > tree ) ) ;
2007-10-07 02:28:14 +04:00
return false ;
2004-11-15 09:55:27 +03:00
}
2007-09-07 19:08:14 +04:00
buf = talloc_array ( mem_ctx , uint8_t , strlen ( value ) + 11 ) ;
2004-11-15 09:55:27 +03:00
ret = smbcli_read ( cli - > tree , fnum , buf , 0 , strlen ( value ) + 11 ) ;
if ( ret ! = strlen ( value ) ) {
2007-11-19 17:01:03 +03:00
printf ( " (%s) Failed to read %lu bytes from stream '%s' - got %d \n " ,
location , ( long ) strlen ( value ) , full_name , ( int ) ret ) ;
2007-10-07 02:28:14 +04:00
return false ;
2004-11-15 09:55:27 +03:00
}
if ( memcmp ( buf , value , strlen ( value ) ) ! = 0 ) {
2007-11-19 17:01:03 +03:00
printf ( " (%s) Bad data in stream \n " , location ) ;
2007-10-07 02:28:14 +04:00
return false ;
2004-11-15 09:55:27 +03:00
}
smbcli_close ( cli - > tree , fnum ) ;
2007-10-07 02:28:14 +04:00
return true ;
2004-11-15 09:55:27 +03:00
}
2007-11-19 17:01:03 +03:00
static int qsort_string ( const void * v1 , const void * v2 )
{
char * const * s1 = v1 ;
char * const * s2 = v2 ;
return strcmp ( * s1 , * s2 ) ;
}
static int qsort_stream ( const void * v1 , const void * v2 )
{
const struct stream_struct * s1 = v1 ;
const struct stream_struct * s2 = v2 ;
return strcmp ( s1 - > stream_name . s , s2 - > stream_name . s ) ;
}
static bool check_stream_list ( struct smbcli_state * cli , const char * fname ,
int num_exp , const char * * exp )
{
union smb_fileinfo finfo ;
NTSTATUS status ;
int i ;
TALLOC_CTX * tmp_ctx = talloc_new ( cli ) ;
char * * exp_sort ;
struct stream_struct * stream_sort ;
bool ret = false ;
finfo . generic . level = RAW_FILEINFO_STREAM_INFO ;
finfo . generic . in . file . path = fname ;
status = smb_raw_pathinfo ( cli - > tree , tmp_ctx , & finfo ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
d_fprintf ( stderr , " (%s) smb_raw_pathinfo failed: %s \n " ,
__location__ , nt_errstr ( status ) ) ;
goto fail ;
}
if ( finfo . stream_info . out . num_streams ! = num_exp ) {
d_fprintf ( stderr , " (%s) expected %d streams, got %d \n " ,
__location__ , num_exp ,
finfo . stream_info . out . num_streams ) ;
goto fail ;
}
exp_sort = talloc_memdup ( tmp_ctx , exp , num_exp * sizeof ( * exp ) ) ;
if ( exp_sort = = NULL ) {
goto fail ;
}
qsort ( exp_sort , num_exp , sizeof ( * exp_sort ) , qsort_string ) ;
stream_sort = talloc_memdup ( tmp_ctx , finfo . stream_info . out . streams ,
finfo . stream_info . out . num_streams *
sizeof ( * stream_sort ) ) ;
if ( stream_sort = = NULL ) {
goto fail ;
}
qsort ( stream_sort , finfo . stream_info . out . num_streams ,
sizeof ( * stream_sort ) , qsort_stream ) ;
for ( i = 0 ; i < num_exp ; i + + ) {
if ( strcmp ( exp_sort [ i ] , stream_sort [ i ] . stream_name . s ) ! = 0 ) {
d_fprintf ( stderr , " (%s) expected stream name %s, got "
" %s \n " , __location__ , exp_sort [ i ] ,
stream_sort [ i ] . stream_name . s ) ;
goto fail ;
}
}
ret = true ;
fail :
talloc_free ( tmp_ctx ) ;
return ret ;
}
2004-11-15 09:55:27 +03:00
/*
test basic io on streams
*/
2007-11-28 17:59:11 +03:00
static bool test_stream_io ( struct torture_context * tctx ,
struct smbcli_state * cli , TALLOC_CTX * mem_ctx )
2004-11-15 09:55:27 +03:00
{
NTSTATUS status ;
union smb_open io ;
const char * fname = BASEDIR " \\ stream.txt " ;
const char * sname1 , * sname2 ;
2007-10-07 02:28:14 +04:00
bool ret = true ;
2004-12-02 07:51:56 +03:00
int fnum = - 1 ;
2004-11-15 09:55:27 +03:00
ssize_t retsize ;
2007-11-19 17:01:03 +03:00
const char * one [ ] = { " ::$DATA " } ;
const char * two [ ] = { " ::$DATA " , " :Second Stream:$DATA " } ;
const char * three [ ] = { " ::$DATA " , " :Stream One:$DATA " ,
" :Second Stream:$DATA " } ;
2004-11-15 09:55:27 +03:00
sname1 = talloc_asprintf ( mem_ctx , " %s:%s " , fname , " Stream One " ) ;
2004-11-17 03:39:20 +03:00
sname2 = talloc_asprintf ( mem_ctx , " %s:%s:$DaTa " , fname , " Second Stream " ) ;
2004-11-15 09:55:27 +03:00
2007-11-19 17:01:03 +03:00
printf ( " (%s) opening non-existant directory stream \n " , __location__ ) ;
2004-11-15 09:55:27 +03:00
io . generic . level = RAW_OPEN_NTCREATEX ;
io . ntcreatex . in . root_fid = 0 ;
io . ntcreatex . in . flags = 0 ;
2004-11-30 07:33:27 +03:00
io . ntcreatex . in . access_mask = SEC_FILE_WRITE_DATA ;
2004-11-15 09:55:27 +03:00
io . ntcreatex . in . create_options = NTCREATEX_OPTIONS_DIRECTORY ;
io . ntcreatex . in . file_attr = FILE_ATTRIBUTE_NORMAL ;
2004-11-17 08:58:04 +03:00
io . ntcreatex . in . share_access = 0 ;
2004-11-15 09:55:27 +03:00
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 = sname1 ;
status = smb_raw_open ( cli - > tree , mem_ctx , & io ) ;
CHECK_STATUS ( status , NT_STATUS_NOT_A_DIRECTORY ) ;
2007-11-19 17:01:03 +03:00
printf ( " (%s) creating a stream on a non-existant file \n " , __location__ ) ;
2004-11-15 09:55:27 +03:00
io . ntcreatex . in . create_options = 0 ;
io . ntcreatex . in . fname = sname1 ;
status = smb_raw_open ( cli - > tree , mem_ctx , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-13 01:48:25 +03:00
fnum = io . ntcreatex . out . file . fnum ;
2004-11-15 09:55:27 +03:00
2007-11-19 17:01:03 +03:00
ret & = check_stream ( cli , __location__ , mem_ctx , fname , " Stream One " , NULL ) ;
2004-11-15 09:55:27 +03:00
2007-11-19 17:01:03 +03:00
printf ( " (%s) check that open of base file is allowed \n " , __location__ ) ;
2004-11-17 08:58:04 +03:00
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_OPEN ;
io . ntcreatex . in . fname = fname ;
status = smb_raw_open ( cli - > tree , mem_ctx , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-13 01:48:25 +03:00
smbcli_close ( cli - > tree , io . ntcreatex . out . file . fnum ) ;
2004-11-17 08:58:04 +03:00
2007-11-19 17:01:03 +03:00
printf ( " (%s) writing to stream \n " , __location__ ) ;
2004-11-15 09:55:27 +03:00
retsize = smbcli_write ( cli - > tree , fnum , 0 , " test data " , 0 , 9 ) ;
CHECK_VALUE ( retsize , 9 ) ;
smbcli_close ( cli - > tree , fnum ) ;
2007-11-19 17:01:03 +03:00
ret & = check_stream ( cli , __location__ , mem_ctx , fname , " Stream One " , " test data " ) ;
2004-11-15 09:55:27 +03:00
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_OPEN ;
2004-11-17 08:58:04 +03:00
io . ntcreatex . in . fname = sname1 ;
2004-11-15 09:55:27 +03:00
status = smb_raw_open ( cli - > tree , mem_ctx , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-13 01:48:25 +03:00
fnum = io . ntcreatex . out . file . fnum ;
2004-11-15 09:55:27 +03:00
2007-11-19 17:01:03 +03:00
printf ( " (%s) modifying stream \n " , __location__ ) ;
2004-11-15 09:55:27 +03:00
retsize = smbcli_write ( cli - > tree , fnum , 0 , " MORE DATA " , 5 , 10 ) ;
CHECK_VALUE ( retsize , 10 ) ;
smbcli_close ( cli - > tree , fnum ) ;
2007-11-19 17:01:03 +03:00
ret & = check_stream ( cli , __location__ , mem_ctx , fname , " Stream One:$FOO " , NULL ) ;
2004-11-17 03:39:20 +03:00
2007-11-19 17:01:03 +03:00
printf ( " (%s) creating a stream2 on a existing file \n " , __location__ ) ;
2004-11-17 03:39:20 +03:00
io . ntcreatex . in . fname = sname2 ;
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_OPEN_IF ;
status = smb_raw_open ( cli - > tree , mem_ctx , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-13 01:48:25 +03:00
fnum = io . ntcreatex . out . file . fnum ;
2004-11-17 03:39:20 +03:00
2007-11-19 17:01:03 +03:00
printf ( " (%s) modifying stream \n " , __location__ ) ;
2004-11-17 03:39:20 +03:00
retsize = smbcli_write ( cli - > tree , fnum , 0 , " SECOND STREAM " , 0 , 13 ) ;
CHECK_VALUE ( retsize , 13 ) ;
smbcli_close ( cli - > tree , fnum ) ;
2007-11-19 17:01:03 +03:00
ret & = check_stream ( cli , __location__ , mem_ctx , fname , " Stream One " , " test MORE DATA " ) ;
ret & = check_stream ( cli , __location__ , mem_ctx , fname , " Stream One:$DATA " , " test MORE DATA " ) ;
ret & = check_stream ( cli , __location__ , mem_ctx , fname , " Stream One: " , NULL ) ;
ret & = check_stream ( cli , __location__ , mem_ctx , fname , " Second Stream " , " SECOND STREAM " ) ;
2007-11-28 17:59:11 +03:00
if ( ! torture_setting_bool ( tctx , " samba4 " , false ) ) {
ret & = check_stream ( cli , __location__ , mem_ctx , fname ,
" SECOND STREAM:$DATA " , " SECOND STREAM " ) ;
}
2007-11-19 17:01:03 +03:00
ret & = check_stream ( cli , __location__ , mem_ctx , fname , " Second Stream:$DATA " , " SECOND STREAM " ) ;
ret & = check_stream ( cli , __location__ , mem_ctx , fname , " Second Stream: " , NULL ) ;
ret & = check_stream ( cli , __location__ , mem_ctx , fname , " Second Stream:$FOO " , NULL ) ;
2004-11-15 09:55:27 +03:00
2007-11-19 17:01:03 +03:00
check_stream_list ( cli , fname , 3 , three ) ;
printf ( " (%s) deleting stream \n " , __location__ ) ;
2004-11-15 09:55:27 +03:00
status = smbcli_unlink ( cli - > tree , sname1 ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2007-11-19 17:01:03 +03:00
check_stream_list ( cli , fname , 2 , two ) ;
printf ( " (%s) delete a stream via delete-on-close \n " , __location__ ) ;
2004-11-17 09:44:50 +03:00
io . ntcreatex . in . fname = sname2 ;
io . ntcreatex . in . create_options = NTCREATEX_OPTIONS_DELETE_ON_CLOSE ;
io . ntcreatex . in . share_access = NTCREATEX_SHARE_ACCESS_DELETE ;
2004-12-02 07:37:36 +03:00
io . ntcreatex . in . access_mask = SEC_RIGHTS_FILE_ALL ;
2004-11-17 09:44:50 +03:00
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_OPEN ;
2007-11-19 17:01:03 +03:00
2004-11-17 09:44:50 +03:00
status = smb_raw_open ( cli - > tree , mem_ctx , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2006-03-13 01:48:25 +03:00
fnum = io . ntcreatex . out . file . fnum ;
2004-11-17 09:44:50 +03:00
smbcli_close ( cli - > tree , fnum ) ;
status = smbcli_unlink ( cli - > tree , sname2 ) ;
CHECK_STATUS ( status , NT_STATUS_OBJECT_NAME_NOT_FOUND ) ;
2007-11-19 17:01:03 +03:00
check_stream_list ( cli , fname , 1 , one ) ;
2004-11-17 09:44:50 +03:00
2007-11-28 17:59:11 +03:00
if ( ! torture_setting_bool ( tctx , " samba4 " , false ) ) {
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_CREATE ;
io . ntcreatex . in . fname = sname1 ;
status = smb_raw_open ( cli - > tree , mem_ctx , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
smbcli_close ( cli - > tree , io . ntcreatex . out . file . fnum ) ;
io . ntcreatex . in . fname = sname2 ;
status = smb_raw_open ( cli - > tree , mem_ctx , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
smbcli_close ( cli - > tree , io . ntcreatex . out . file . fnum ) ;
}
2007-11-19 17:01:03 +03:00
printf ( " (%s) deleting file \n " , __location__ ) ;
2004-11-15 09:55:27 +03:00
status = smbcli_unlink ( cli - > tree , fname ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
done :
smbcli_close ( cli - > tree , fnum ) ;
2005-08-04 08:20:43 +04:00
return ret ;
2004-11-15 09:55:27 +03:00
}
2007-11-28 17:59:11 +03:00
/*
test stream sharemodes
*/
static bool test_stream_sharemodes ( struct torture_context * tctx ,
struct smbcli_state * cli ,
TALLOC_CTX * mem_ctx )
{
NTSTATUS status ;
union smb_open io ;
const char * fname = BASEDIR " \\ stream.txt " ;
const char * sname1 , * sname2 ;
bool ret = true ;
int fnum1 = - 1 ;
int fnum2 = - 1 ;
sname1 = talloc_asprintf ( mem_ctx , " %s:%s " , fname , " Stream One " ) ;
sname2 = talloc_asprintf ( mem_ctx , " %s:%s:$DaTa " , fname , " Second Stream " ) ;
printf ( " (%s) testing stream share mode conflicts \n " , __location__ ) ;
io . generic . level = RAW_OPEN_NTCREATEX ;
io . ntcreatex . in . root_fid = 0 ;
io . ntcreatex . in . flags = 0 ;
io . ntcreatex . in . access_mask = SEC_FILE_WRITE_DATA ;
io . ntcreatex . in . create_options = 0 ;
io . ntcreatex . in . file_attr = FILE_ATTRIBUTE_NORMAL ;
io . ntcreatex . in . share_access = 0 ;
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 = sname1 ;
status = smb_raw_open ( cli - > tree , mem_ctx , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
fnum1 = io . ntcreatex . out . file . fnum ;
/*
* A different stream does not give a sharing violation
*/
2008-03-12 16:21:21 +03:00
io . ntcreatex . in . fname = sname2 ;
status = smb_raw_open ( cli - > tree , mem_ctx , & io ) ;
2007-11-28 17:59:11 +03:00
CHECK_STATUS ( status , NT_STATUS_OK ) ;
2008-03-12 16:21:21 +03:00
fnum2 = io . ntcreatex . out . file . fnum ;
2007-11-28 17:59:11 +03:00
/*
* . . . whereas the same stream does with unchanged access / share_access
* flags
*/
2008-03-12 16:21:21 +03:00
io . ntcreatex . in . fname = sname1 ;
2007-11-28 17:59:11 +03:00
io . ntcreatex . in . open_disposition = 0 ;
status = smb_raw_open ( cli - > tree , mem_ctx , & io ) ;
CHECK_STATUS ( status , NT_STATUS_SHARING_VIOLATION ) ;
io . ntcreatex . in . fname = sname2 ;
status = smb_raw_open ( cli - > tree , mem_ctx , & io ) ;
2008-03-12 16:21:21 +03:00
CHECK_STATUS ( status , NT_STATUS_SHARING_VIOLATION ) ;
2007-11-28 17:59:11 +03:00
done :
if ( fnum1 ! = - 1 ) smbcli_close ( cli - > tree , fnum1 ) ;
if ( fnum2 ! = - 1 ) smbcli_close ( cli - > tree , fnum2 ) ;
status = smbcli_unlink ( cli - > tree , fname ) ;
return ret ;
}
/*
* Test FILE_SHARE_DELETE on streams
*
* A stream opened with ! FILE_SHARE_DELETE prevents the main file to be opened
* with SEC_STD_DELETE .
*
* The main file opened with ! FILE_SHARE_DELETE does * not * prevent a stream to
* be opened with SEC_STD_DELETE .
*
* A stream held open with FILE_SHARE_DELETE allows the file to be
* deleted . After the main file is deleted , access to the open file descriptor
* still works , but all name - based access to both the main file as well as the
* stream is denied with DELETE ending .
*
* This means , an open of the main file with SEC_STD_DELETE should walk all
* streams and also open them with SEC_STD_DELETE . If any of these opens gives
* SHARING_VIOLATION , the main open fails .
*
* Closing the main file after delete_on_close has been set does not really
* unlink it but leaves the corresponding share mode entry with
* delete_on_close being set around until all streams are closed .
*
* Opening a stream must also look at the main file ' s share mode entry , look
* at the delete_on_close bit and potentially return DELETE_PENDING .
*/
static bool test_stream_delete ( struct torture_context * tctx ,
struct smbcli_state * cli , TALLOC_CTX * mem_ctx )
{
NTSTATUS status ;
union smb_open io ;
const char * fname = BASEDIR " \\ stream.txt " ;
const char * sname1 ;
bool ret = true ;
int fnum = - 1 ;
uint8_t buf [ 9 ] ;
ssize_t retsize ;
union smb_fileinfo finfo ;
sname1 = talloc_asprintf ( mem_ctx , " %s:%s " , fname , " Stream One " ) ;
printf ( " (%s) opening non-existant directory stream \n " , __location__ ) ;
io . generic . level = RAW_OPEN_NTCREATEX ;
io . ntcreatex . in . root_fid = 0 ;
io . ntcreatex . in . flags = 0 ;
io . ntcreatex . in . access_mask = SEC_FILE_READ_DATA | SEC_FILE_WRITE_DATA ;
io . ntcreatex . in . create_options = 0 ;
io . ntcreatex . in . file_attr = FILE_ATTRIBUTE_NORMAL ;
io . ntcreatex . in . share_access = 0 ;
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 = sname1 ;
status = smb_raw_open ( cli - > tree , mem_ctx , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
fnum = io . ntcreatex . out . file . fnum ;
retsize = smbcli_write ( cli - > tree , fnum , 0 , " test data " , 0 , 9 ) ;
CHECK_VALUE ( retsize , 9 ) ;
/*
* One stream opened without FILE_SHARE_DELETE prevents the main file
* to be deleted or even opened with DELETE access
*/
status = smbcli_unlink ( cli - > tree , fname ) ;
CHECK_STATUS ( status , NT_STATUS_SHARING_VIOLATION ) ;
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_OPEN ;
io . ntcreatex . in . fname = fname ;
io . ntcreatex . in . access_mask = SEC_STD_DELETE ;
status = smb_raw_open ( cli - > tree , mem_ctx , & io ) ;
CHECK_STATUS ( status , NT_STATUS_SHARING_VIOLATION ) ;
smbcli_close ( cli - > tree , fnum ) ;
/*
* . . . but unlink works if a stream is opened with FILE_SHARE_DELETE
*/
io . ntcreatex . in . fname = sname1 ;
io . ntcreatex . in . access_mask = SEC_FILE_READ_DATA | SEC_FILE_WRITE_DATA ;
io . ntcreatex . in . share_access = NTCREATEX_SHARE_ACCESS_DELETE ;
status = smb_raw_open ( cli - > tree , mem_ctx , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
fnum = io . ntcreatex . out . file . fnum ;
status = smbcli_unlink ( cli - > tree , fname ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
/*
* file access still works on the stream while the main file is closed
*/
retsize = smbcli_read ( cli - > tree , fnum , buf , 0 , 9 ) ;
CHECK_VALUE ( retsize , 9 ) ;
finfo . generic . level = RAW_FILEINFO_STANDARD ;
finfo . generic . in . file . path = fname ;
/*
* name - based access to both the main file and the stream does not
* work anymore but gives DELETE_PENDING
*/
status = smb_raw_pathinfo ( cli - > tree , mem_ctx , & finfo ) ;
CHECK_STATUS ( status , NT_STATUS_DELETE_PENDING ) ;
2008-01-20 17:51:02 +03:00
if ( ! torture_setting_bool ( tctx , " samba3 " , false ) ) {
/*
* S3 doesn ' t do this yet
*/
finfo . generic . in . file . path = sname1 ;
status = smb_raw_pathinfo ( cli - > tree , mem_ctx , & finfo ) ;
CHECK_STATUS ( status , NT_STATUS_DELETE_PENDING ) ;
}
2007-11-28 17:59:11 +03:00
/*
* fd - based qfileinfo on the stream still works , the stream does not
* have the delete - on - close bit set . This could mean that open on the
* stream first opens the main file
*/
finfo . all_info . level = RAW_FILEINFO_ALL_INFO ;
finfo . all_info . in . file . fnum = fnum ;
status = smb_raw_fileinfo ( cli - > tree , mem_ctx , & finfo ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
CHECK_VALUE ( finfo . all_info . out . delete_pending , 0 ) ;
smbcli_close ( cli - > tree , fnum ) ;
/*
* After closing the stream the file is really gone .
*/
finfo . generic . in . file . path = fname ;
status = smb_raw_pathinfo ( cli - > tree , mem_ctx , & finfo ) ;
CHECK_STATUS ( status , NT_STATUS_OBJECT_NAME_NOT_FOUND ) ;
io . ntcreatex . in . access_mask = SEC_FILE_READ_DATA | SEC_FILE_WRITE_DATA
| SEC_STD_DELETE ;
io . ntcreatex . in . create_options = NTCREATEX_OPTIONS_DELETE_ON_CLOSE ;
io . ntcreatex . in . open_disposition = NTCREATEX_DISP_CREATE ;
status = smb_raw_open ( cli - > tree , mem_ctx , & io ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
fnum = io . ntcreatex . out . file . fnum ;
finfo . generic . in . file . path = fname ;
status = smb_raw_pathinfo ( cli - > tree , mem_ctx , & finfo ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
smbcli_close ( cli - > tree , fnum ) ;
status = smb_raw_pathinfo ( cli - > tree , mem_ctx , & finfo ) ;
CHECK_STATUS ( status , NT_STATUS_OK ) ;
done :
smbcli_close ( cli - > tree , fnum ) ;
return ret ;
}
2004-11-15 09:55:27 +03:00
/*
basic testing of streams calls
*/
2007-08-28 16:54:27 +04:00
bool torture_raw_streams ( struct torture_context * torture ,
2007-09-08 20:46:30 +04:00
struct smbcli_state * cli )
2004-11-15 09:55:27 +03:00
{
2007-09-08 20:46:30 +04:00
bool ret = true ;
2004-11-15 09:55:27 +03:00
if ( ! torture_setup_dir ( cli , BASEDIR ) ) {
2007-10-07 02:28:14 +04:00
return false ;
2004-11-15 09:55:27 +03:00
}
2007-11-28 17:59:11 +03:00
ret & = test_stream_io ( torture , cli , torture ) ;
ret & = test_stream_sharemodes ( torture , cli , torture ) ;
if ( ! torture_setting_bool ( torture , " samba4 " , false ) ) {
ret & = test_stream_delete ( torture , cli , torture ) ;
}
2004-11-15 09:55:27 +03:00
smb_raw_exit ( cli - > session ) ;
smbcli_deltree ( cli - > tree , BASEDIR ) ;
return ret ;
}