2007-09-13 03:50:21 +04:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
1998-08-17 17:11:34 +04:00
file closing
Copyright ( C ) Andrew Tridgell 1992 - 1998
2007-02-07 00:05:34 +03:00
Copyright ( C ) Jeremy Allison 1992 - 2007.
2005-07-08 08:51:27 +04:00
Copyright ( C ) Volker Lendecke 2005
2007-09-13 03:50:21 +04:00
1998-08-17 17:11:34 +04: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-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
1998-08-17 17:11:34 +04:00
( at your option ) any later version .
2007-09-13 03:50:21 +04:00
1998-08-17 17:11:34 +04: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 .
2007-09-13 03:50:21 +04:00
1998-08-17 17:11:34 +04:00
You should have received a copy of the GNU General Public License
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
1998-08-17 17:11:34 +04:00
*/
# include "includes.h"
2011-02-26 01:20:06 +03:00
# include "system/filesys.h"
2017-01-01 23:00:55 +03:00
# include "lib/util/server_id.h"
2010-05-04 12:28:48 +04:00
# include "printing.h"
2011-03-22 18:57:01 +03:00
# include "smbd/smbd.h"
2010-07-04 20:25:02 +04:00
# include "smbd/globals.h"
2013-03-20 13:01:43 +04:00
# include "smbd/scavenger.h"
2010-10-03 12:46:22 +04:00
# include "fake_file.h"
2011-02-26 02:56:46 +03:00
# include "transfer_file.h"
2011-03-24 15:46:20 +03:00
# include "auth.h"
2011-03-24 17:31:06 +03:00
# include "messages.h"
2011-11-24 17:11:28 +04:00
# include "../librpc/gen_ndr/open_files.h"
2020-03-09 13:31:00 +03:00
# include "lib/util/tevent_ntstatus.h"
1998-08-17 17:11:34 +04:00
/****************************************************************************
2003-01-03 21:50:13 +03:00
Run a file if it is a magic script .
1998-08-17 17:11:34 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-01-03 21:50:13 +03:00
2009-06-07 01:27:31 +04:00
static NTSTATUS check_magic ( struct files_struct * fsp )
1998-08-17 17:11:34 +04:00
{
2007-09-13 03:50:21 +04:00
int ret ;
2019-10-31 20:47:43 +03:00
const struct loadparm_substitution * lp_sub =
loadparm_s3_global_substitution ( ) ;
2007-09-13 03:50:21 +04:00
const char * magic_output = NULL ;
SMB_STRUCT_STAT st ;
int tmp_fd , outfd ;
TALLOC_CTX * ctx = NULL ;
const char * p ;
2007-12-22 04:13:02 +03:00
struct connection_struct * conn = fsp - > conn ;
2009-07-11 01:50:37 +04:00
char * fname = NULL ;
NTSTATUS status ;
2007-09-13 03:50:21 +04:00
2019-10-31 20:49:07 +03:00
if ( ! * lp_magic_script ( talloc_tos ( ) , lp_sub , SNUM ( conn ) ) ) {
2009-06-07 01:27:31 +04:00
return NT_STATUS_OK ;
2007-09-13 03:50:21 +04:00
}
2003-01-03 21:50:13 +03:00
2009-07-11 01:50:37 +04:00
DEBUG ( 5 , ( " checking magic for %s \n " , fsp_str_dbg ( fsp ) ) ) ;
ctx = talloc_stackframe ( ) ;
2009-07-21 22:35:17 +04:00
fname = fsp - > fsp_name - > base_name ;
2003-01-03 21:50:13 +03:00
2009-07-11 01:50:37 +04:00
if ( ! ( p = strrchr_m ( fname , ' / ' ) ) ) {
p = fname ;
2007-09-13 03:50:21 +04:00
} else {
p + + ;
}
2003-01-03 21:50:13 +03:00
2019-10-31 20:49:07 +03:00
if ( ! strequal ( lp_magic_script ( talloc_tos ( ) , lp_sub , SNUM ( conn ) ) , p ) ) {
2009-07-11 01:50:37 +04:00
status = NT_STATUS_OK ;
goto out ;
2001-04-13 04:37:00 +04:00
}
2019-10-31 20:47:43 +03:00
if ( * lp_magic_output ( talloc_tos ( ) , lp_sub , SNUM ( conn ) ) ) {
magic_output = lp_magic_output ( talloc_tos ( ) , lp_sub , SNUM ( conn ) ) ;
2007-09-13 03:50:21 +04:00
} else {
magic_output = talloc_asprintf ( ctx ,
" %s.out " ,
2009-07-11 01:50:37 +04:00
fname ) ;
2007-09-13 03:50:21 +04:00
}
if ( ! magic_output ) {
2009-07-11 01:50:37 +04:00
status = NT_STATUS_NO_MEMORY ;
goto out ;
2007-09-13 03:50:21 +04:00
}
2009-01-07 03:05:28 +03:00
/* Ensure we don't depend on user's PATH. */
2009-07-11 01:50:37 +04:00
p = talloc_asprintf ( ctx , " ./%s " , fname ) ;
2009-01-07 03:05:28 +03:00
if ( ! p ) {
2009-07-11 01:50:37 +04:00
status = NT_STATUS_NO_MEMORY ;
goto out ;
2009-01-07 03:05:28 +03:00
}
2009-07-11 01:50:37 +04:00
if ( chmod ( fname , 0755 ) = = - 1 ) {
status = map_nt_error_from_unix ( errno ) ;
goto out ;
2009-01-07 03:05:28 +03:00
}
2016-10-12 18:55:15 +03:00
ret = smbrun ( p , & tmp_fd , NULL ) ;
2007-09-13 03:50:21 +04:00
DEBUG ( 3 , ( " Invoking magic command %s gave %d \n " ,
2009-01-07 03:05:28 +03:00
p , ret ) ) ;
2003-01-03 21:50:13 +03:00
2009-07-11 01:50:37 +04:00
unlink ( fname ) ;
2007-09-13 03:50:21 +04:00
if ( ret ! = 0 | | tmp_fd = = - 1 ) {
if ( tmp_fd ! = - 1 ) {
2003-01-03 21:50:13 +03:00
close ( tmp_fd ) ;
}
2009-07-11 01:50:37 +04:00
status = NT_STATUS_UNSUCCESSFUL ;
goto out ;
2007-09-13 03:50:21 +04:00
}
outfd = open ( magic_output , O_CREAT | O_EXCL | O_RDWR , 0600 ) ;
if ( outfd = = - 1 ) {
2009-06-07 01:27:31 +04:00
int err = errno ;
2007-09-13 03:50:21 +04:00
close ( tmp_fd ) ;
2009-07-11 01:50:37 +04:00
status = map_nt_error_from_unix ( err ) ;
goto out ;
2007-09-13 03:50:21 +04:00
}
2003-01-03 21:50:13 +03:00
2009-11-27 14:58:26 +03:00
if ( sys_fstat ( tmp_fd , & st , false ) = = - 1 ) {
2009-06-07 01:27:31 +04:00
int err = errno ;
2001-04-13 04:37:00 +04:00
close ( tmp_fd ) ;
close ( outfd ) ;
2009-07-11 01:50:37 +04:00
status = map_nt_error_from_unix ( err ) ;
goto out ;
2001-04-13 04:37:00 +04:00
}
2007-09-13 03:50:21 +04:00
2012-04-05 08:53:08 +04:00
if ( transfer_file ( tmp_fd , outfd , ( off_t ) st . st_ex_size ) = = ( off_t ) - 1 ) {
2009-06-13 00:55:18 +04:00
int err = errno ;
close ( tmp_fd ) ;
close ( outfd ) ;
2009-07-11 01:50:37 +04:00
status = map_nt_error_from_unix ( err ) ;
goto out ;
2009-06-13 00:55:18 +04:00
}
2007-09-13 03:50:21 +04:00
close ( tmp_fd ) ;
2009-06-07 01:27:31 +04:00
if ( close ( outfd ) = = - 1 ) {
2009-07-11 01:50:37 +04:00
status = map_nt_error_from_unix ( errno ) ;
goto out ;
2009-06-07 01:27:31 +04:00
}
2009-07-11 01:50:37 +04:00
status = NT_STATUS_OK ;
out :
2007-09-13 03:50:21 +04:00
TALLOC_FREE ( ctx ) ;
2009-07-11 01:50:37 +04:00
return status ;
1998-08-17 17:11:34 +04:00
}
2008-01-20 01:25:36 +03:00
/****************************************************************************
Delete all streams
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2016-03-05 01:07:04 +03:00
NTSTATUS delete_all_streams ( connection_struct * conn ,
const struct smb_filename * smb_fname )
2008-01-20 01:25:36 +03:00
{
2011-10-14 02:41:53 +04:00
struct stream_struct * stream_info = NULL ;
2019-08-14 22:39:50 +03:00
unsigned int i ;
2011-10-14 02:41:53 +04:00
unsigned int num_streams = 0 ;
2008-01-20 01:25:36 +03:00
TALLOC_CTX * frame = talloc_stackframe ( ) ;
NTSTATUS status ;
2016-03-05 01:16:13 +03:00
status = vfs_streaminfo ( conn , NULL , smb_fname , talloc_tos ( ) ,
2011-10-17 22:10:29 +04:00
& num_streams , & stream_info ) ;
2008-01-20 01:25:36 +03:00
if ( NT_STATUS_EQUAL ( status , NT_STATUS_NOT_IMPLEMENTED ) ) {
DEBUG ( 10 , ( " no streams around \n " ) ) ;
TALLOC_FREE ( frame ) ;
return NT_STATUS_OK ;
}
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-10-17 22:10:29 +04:00
DEBUG ( 10 , ( " vfs_streaminfo failed: %s \n " ,
2008-01-20 01:25:36 +03:00
nt_errstr ( status ) ) ) ;
goto fail ;
}
DEBUG ( 10 , ( " delete_all_streams found %d streams \n " ,
num_streams ) ) ;
if ( num_streams = = 0 ) {
TALLOC_FREE ( frame ) ;
return NT_STATUS_OK ;
}
for ( i = 0 ; i < num_streams ; i + + ) {
int res ;
2013-04-15 13:25:41 +04:00
struct smb_filename * smb_fname_stream ;
2008-01-20 01:25:36 +03:00
if ( strequal ( stream_info [ i ] . name , " ::$DATA " ) ) {
continue ;
}
2016-03-05 01:07:04 +03:00
smb_fname_stream = synthetic_smb_fname ( talloc_tos ( ) ,
smb_fname - > base_name ,
stream_info [ i ] . name ,
2016-03-19 07:19:38 +03:00
NULL ,
2016-07-19 19:21:08 +03:00
( smb_fname - > flags &
~ SMB_FILENAME_POSIX_PATH ) ) ;
2008-01-20 01:25:36 +03:00
2013-04-15 13:25:41 +04:00
if ( smb_fname_stream = = NULL ) {
2008-01-20 01:25:36 +03:00
DEBUG ( 0 , ( " talloc_aprintf failed \n " ) ) ;
2013-04-15 13:25:41 +04:00
status = NT_STATUS_NO_MEMORY ;
2008-01-20 01:25:36 +03:00
goto fail ;
}
2019-09-13 22:23:02 +03:00
res = SMB_VFS_UNLINKAT ( conn ,
conn - > cwd_fsp ,
smb_fname_stream ,
0 ) ;
2008-01-20 01:25:36 +03:00
if ( res = = - 1 ) {
status = map_nt_error_from_unix ( errno ) ;
DEBUG ( 10 , ( " Could not delete stream %s: %s \n " ,
2009-07-02 20:27:44 +04:00
smb_fname_str_dbg ( smb_fname_stream ) ,
strerror ( errno ) ) ) ;
TALLOC_FREE ( smb_fname_stream ) ;
2008-01-20 01:25:36 +03:00
break ;
}
2009-07-02 20:27:44 +04:00
TALLOC_FREE ( smb_fname_stream ) ;
2008-01-20 01:25:36 +03:00
}
fail :
TALLOC_FREE ( frame ) ;
return status ;
}
2019-08-14 22:40:07 +03:00
struct has_other_nonposix_opens_state {
files_struct * fsp ;
bool found_another ;
} ;
static bool has_other_nonposix_opens_fn (
struct share_mode_entry * e ,
bool * modified ,
void * private_data )
2018-09-08 17:58:36 +03:00
{
2019-08-14 22:40:07 +03:00
struct has_other_nonposix_opens_state * state = private_data ;
struct files_struct * fsp = state - > fsp ;
2018-09-08 17:58:36 +03:00
2019-08-14 22:40:07 +03:00
if ( e - > name_hash ! = fsp - > name_hash ) {
return false ;
}
if ( ( fsp - > posix_flags & FSP_POSIX_FLAGS_OPEN ) & &
( e - > flags & SHARE_MODE_FLAG_POSIX_OPEN ) ) {
return false ;
}
if ( e - > share_file_id = = fsp - > fh - > gen_id ) {
struct server_id self = messaging_server_id (
fsp - > conn - > sconn - > msg_ctx ) ;
if ( server_id_equal ( & self , & e - > pid ) ) {
return false ;
2018-09-08 17:58:36 +03:00
}
}
2019-08-14 22:40:07 +03:00
if ( share_entry_stale_pid ( e ) ) {
return false ;
}
state - > found_another = true ;
return true ;
}
2018-09-08 17:58:36 +03:00
2019-08-14 22:40:07 +03:00
bool has_other_nonposix_opens ( struct share_mode_lock * lck ,
struct files_struct * fsp )
{
struct has_other_nonposix_opens_state state = { . fsp = fsp } ;
bool ok ;
ok = share_mode_forall_entries (
lck , has_other_nonposix_opens_fn , & state ) ;
if ( ! ok ) {
return false ;
}
return state . found_another ;
2018-09-08 17:58:36 +03:00
}
1998-08-17 17:11:34 +04:00
/****************************************************************************
2006-05-18 03:15:53 +04:00
Deal with removing a share mode on last close .
1998-08-17 17:11:34 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2007-01-05 14:31:28 +03:00
static NTSTATUS close_remove_share_mode ( files_struct * fsp ,
enum file_close_type close_type )
1998-08-17 17:11:34 +04:00
{
connection_struct * conn = fsp - > conn ;
2008-01-11 03:35:54 +03:00
bool delete_file = false ;
bool changed_user = false ;
2009-07-02 20:27:44 +04:00
struct share_mode_lock * lck = NULL ;
2007-01-05 14:31:28 +03:00
NTSTATUS status = NT_STATUS_OK ;
2009-10-03 00:45:38 +04:00
NTSTATUS tmp_status ;
2007-05-29 13:30:34 +04:00
struct file_id id ;
2011-02-11 10:49:15 +03:00
const struct security_unix_token * del_token = NULL ;
2012-04-05 01:54:02 +04:00
const struct security_token * del_nt_token = NULL ;
bool got_tokens = false ;
2012-06-01 18:13:22 +04:00
bool normal_close ;
2019-09-13 22:25:10 +03:00
int ret ;
1998-08-17 17:11:34 +04:00
2009-11-06 09:58:12 +03:00
/* Ensure any pending write time updates are done. */
if ( fsp - > update_write_time_event ) {
2018-05-23 10:41:29 +03:00
fsp_flush_write_time_update ( fsp ) ;
2009-11-06 09:58:12 +03:00
}
This is a big, rather ugly patch. Whilst investigating the files not truncated
when copying to a full disk problem, I discovered that we were not allowing
the delete on close flag to be set properly, this led to other things, and
after investigation of the proper delete on close semantics and their relationship
to the file_share_delete flag I discovered there were some cases where we
weren't doing the deny modes properly. And this after only 5 years working
on them..... :-) :-).
So here's the latest attempt. I realised the delete on close flag needs to
be set across all smbds with a dev/ino pair open - in addition, the delete
on close flag, allow share delete and delete access requested all need to
be stored in the share mode tdb.
The "delete_on_close" entry in the fsp struct is now redundant and should
really be removed. This may also mean we can get rid of the "iterate_fsp"
calls that I didn't like adding in the first place. Whilst doing this patch,
I also discovered we needed to do the se_map_generic() call for file opens
and POSIX ACL mapping, so I added that also.
This code, although ugly, now passes the deny mode torture tests plus the
delete on close tests I added. I do need to add one more multiple connection
delete on close test to make sure I got the semantics exactly right, plus we
should also (as Andrew suggested) move to random testing here.
The good news is that NT should now correctly delete the file on disk
full error when copying to a disk :-).
Jeremy.
(This used to be commit 51987684bd231c744da2e5f3705fd236d5616173)
2001-03-30 12:57:24 +04:00
/*
* Lock the share entries , and determine if we should delete
* on close . If so delete whilst the lock is still in effect .
* This prevents race conditions with the file being created . JRA .
*/
1998-08-17 17:11:34 +04:00
2012-02-19 17:23:56 +04:00
lck = get_existing_share_mode_lock ( talloc_tos ( ) , fsp - > file_id ) ;
2005-09-30 21:13:37 +04:00
if ( lck = = NULL ) {
2007-01-04 18:12:22 +03:00
DEBUG ( 0 , ( " close_remove_share_mode: Could not get share mode "
2009-07-11 01:50:37 +04:00
" lock for file %s \n " , fsp_str_dbg ( fsp ) ) ) ;
2012-06-01 18:42:29 +04:00
return NT_STATUS_INVALID_PARAMETER ;
2005-09-30 21:13:37 +04:00
}
2001-08-22 04:29:40 +04:00
2016-08-11 00:42:07 +03:00
/* Remove the oplock before potentially deleting the file. */
if ( fsp - > oplock_type ) {
2019-08-05 18:05:20 +03:00
remove_oplock ( fsp ) ;
2016-08-11 00:42:07 +03:00
}
2008-03-12 17:39:38 +03:00
if ( fsp - > write_time_forced ) {
2019-12-02 18:30:50 +03:00
struct timespec ts ;
2009-11-06 03:20:11 +03:00
DEBUG ( 10 , ( " close_remove_share_mode: write time forced "
" for file %s \n " ,
fsp_str_dbg ( fsp ) ) ) ;
2019-12-02 18:30:50 +03:00
ts = nt_time_to_full_timespec ( lck - > data - > changed_write_time ) ;
set_close_write_time ( fsp , ts ) ;
2009-11-06 08:27:25 +03:00
} else if ( fsp - > update_write_time_on_close ) {
2009-11-06 09:58:12 +03:00
/* Someone had a pending write. */
2019-12-02 18:30:50 +03:00
if ( is_omit_timespec ( & fsp - > close_write_time ) ) {
2009-11-06 09:58:12 +03:00
DEBUG ( 10 , ( " close_remove_share_mode: update to current time "
" for file %s \n " ,
fsp_str_dbg ( fsp ) ) ) ;
/* Update to current time due to "normal" write. */
set_close_write_time ( fsp , timespec_current ( ) ) ;
2009-11-06 08:27:25 +03:00
} else {
2009-11-06 09:58:12 +03:00
DEBUG ( 10 , ( " close_remove_share_mode: write time pending "
" for file %s \n " ,
fsp_str_dbg ( fsp ) ) ) ;
/* Update to time set on close call. */
set_close_write_time ( fsp , fsp - > close_write_time ) ;
2009-11-06 08:27:25 +03:00
}
2008-03-12 17:39:38 +03:00
}
2011-01-26 01:23:19 +03:00
if ( fsp - > initial_delete_on_close & &
! is_delete_on_close_set ( lck , fsp - > name_hash ) ) {
2007-10-19 04:40:25 +04:00
bool became_user = False ;
2007-01-19 00:51:52 +03:00
/* Initial delete on close was set and no one else
* wrote a real delete on close . */
2010-03-15 22:13:30 +03:00
if ( get_current_vuid ( conn ) ! = fsp - > vuid ) {
2019-07-19 12:14:13 +03:00
become_user_without_service ( conn , fsp - > vuid ) ;
2007-01-19 00:51:52 +03:00
became_user = True ;
}
2010-01-13 03:04:44 +03:00
fsp - > delete_on_close = true ;
2015-04-21 12:41:45 +03:00
set_delete_on_close_lck ( fsp , lck ,
2012-04-05 01:54:02 +04:00
get_current_nttok ( conn ) ,
get_current_utok ( conn ) ) ;
2007-01-19 00:51:52 +03:00
if ( became_user ) {
2019-07-19 12:14:13 +03:00
unbecome_user_without_service ( ) ;
2007-01-19 00:51:52 +03:00
}
}
2019-09-09 11:42:59 +03:00
delete_file = is_delete_on_close_set ( lck , fsp - > name_hash ) & &
! has_other_nonposix_opens ( lck , fsp ) ;
1998-08-17 17:11:34 +04:00
1998-09-11 23:14:27 +04:00
/*
* NT can set delete_on_close of the last open
* reference to a file .
*/
2012-06-01 18:13:22 +04:00
normal_close = ( close_type = = NORMAL_CLOSE | | close_type = = SHUTDOWN_CLOSE ) ;
if ( ! normal_close | | ! delete_file ) {
2013-06-21 17:11:55 +04:00
status = NT_STATUS_OK ;
goto done ;
2007-01-04 18:12:22 +03:00
}
2005-12-13 21:11:50 +03:00
2007-01-04 18:12:22 +03:00
/*
* Ok , we have to delete the file
*/
2005-12-13 21:11:50 +03:00
2007-01-04 18:12:22 +03:00
DEBUG ( 5 , ( " close_remove_share_mode: file %s. Delete on close was set "
2009-07-11 01:50:37 +04:00
" - deleting file. \n " , fsp_str_dbg ( fsp ) ) ) ;
2006-02-02 23:44:50 +03:00
2008-03-12 17:39:38 +03:00
/*
* Don ' t try to update the write time when we delete the file
*/
fsp - > update_write_time_on_close = false ;
2012-04-05 01:54:02 +04:00
got_tokens = get_delete_on_close_token ( lck , fsp - > name_hash ,
& del_nt_token , & del_token ) ;
SMB_ASSERT ( got_tokens ) ;
2011-01-26 01:23:19 +03:00
if ( ! unix_token_equal ( del_token , get_current_utok ( conn ) ) ) {
2008-01-11 03:35:54 +03:00
/* Become the user who requested the delete. */
2006-02-02 23:44:50 +03:00
2008-01-11 03:35:54 +03:00
DEBUG ( 5 , ( " close_remove_share_mode: file %s. "
" Change user to uid %u \n " ,
2009-07-11 01:50:37 +04:00
fsp_str_dbg ( fsp ) ,
2011-01-26 01:23:19 +03:00
( unsigned int ) del_token - > uid ) ) ;
2008-01-11 03:35:54 +03:00
if ( ! push_sec_ctx ( ) ) {
smb_panic ( " close_remove_share_mode: file %s. failed to push "
" sec_ctx. \n " ) ;
}
2006-02-02 23:44:50 +03:00
2011-01-26 01:23:19 +03:00
set_sec_ctx ( del_token - > uid ,
del_token - > gid ,
del_token - > ngroups ,
del_token - > groups ,
2012-04-05 01:54:02 +04:00
del_nt_token ) ;
2008-01-11 03:35:54 +03:00
changed_user = true ;
}
2007-01-04 18:12:22 +03:00
/* We can only delete the file if the name we have is still valid and
hasn ' t been renamed . */
2007-07-17 04:09:56 +04:00
2009-10-03 00:45:38 +04:00
tmp_status = vfs_stat_fsp ( fsp ) ;
if ( ! NT_STATUS_IS_OK ( tmp_status ) ) {
2007-01-04 18:12:22 +03:00
DEBUG ( 5 , ( " close_remove_share_mode: file %s. Delete on close "
" was set and stat failed with error %s \n " ,
2009-10-03 00:45:38 +04:00
fsp_str_dbg ( fsp ) , nt_errstr ( tmp_status ) ) ) ;
2007-01-05 14:31:28 +03:00
/*
* Don ' t save the errno here , we ignore this error
*/
2007-01-04 18:12:22 +03:00
goto done ;
}
2009-07-11 01:50:37 +04:00
id = vfs_file_id_from_sbuf ( conn , & fsp - > fsp_name - > st ) ;
2007-05-29 13:30:34 +04:00
if ( ! file_id_equal ( & fsp - > file_id , & id ) ) {
2019-09-09 17:34:10 +03:00
struct file_id_buf ftmp1 , ftmp2 ;
2007-01-04 18:12:22 +03:00
DEBUG ( 5 , ( " close_remove_share_mode: file %s. Delete on close "
" was set and dev and/or inode does not match \n " ,
2009-07-11 01:50:37 +04:00
fsp_str_dbg ( fsp ) ) ) ;
2007-05-29 13:30:34 +04:00
DEBUG ( 5 , ( " close_remove_share_mode: file %s. stored file_id %s, "
" stat file_id %s \n " ,
2009-07-11 01:50:37 +04:00
fsp_str_dbg ( fsp ) ,
2019-09-09 17:34:10 +03:00
file_id_str_buf ( fsp - > file_id , & ftmp1 ) ,
file_id_str_buf ( id , & ftmp2 ) ) ) ;
2007-01-05 14:31:28 +03:00
/*
* Don ' t save the errno here , we ignore this error
*/
2007-01-04 18:12:22 +03:00
goto done ;
2001-11-13 04:35:20 +03:00
}
1998-09-11 23:14:27 +04:00
2008-01-20 01:25:36 +03:00
if ( ( conn - > fs_capabilities & FILE_NAMED_STREAMS )
2009-07-11 01:50:37 +04:00
& & ! is_ntfs_stream_smb_fname ( fsp - > fsp_name ) ) {
2008-01-20 01:25:36 +03:00
2016-03-05 01:07:04 +03:00
status = delete_all_streams ( conn , fsp - > fsp_name ) ;
2008-01-20 01:25:36 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 5 , ( " delete_all_streams failed: %s \n " ,
nt_errstr ( status ) ) ) ;
goto done ;
}
}
2018-01-11 01:56:08 +03:00
if ( fsp - > kernel_share_modes_taken ) {
int ret_flock ;
/*
* A file system sharemode could block the unlink ;
* remove filesystem sharemodes first .
*/
ret_flock = SMB_VFS_KERNEL_FLOCK ( fsp , 0 , 0 ) ;
if ( ret_flock = = - 1 ) {
DBG_INFO ( " removing kernel flock for %s failed: %s \n " ,
fsp_str_dbg ( fsp ) , strerror ( errno ) ) ;
}
fsp - > kernel_share_modes_taken = false ;
}
2008-01-20 01:25:36 +03:00
2019-09-13 22:25:10 +03:00
ret = SMB_VFS_UNLINKAT ( conn ,
conn - > cwd_fsp ,
fsp - > fsp_name ,
0 ) ;
if ( ret ! = 0 ) {
2007-01-04 18:12:22 +03:00
/*
* This call can potentially fail as another smbd may
* have had the file open with delete on close set and
* deleted it when its last reference to this file
* went away . Hence we log this but not at debug level
* zero .
*/
DEBUG ( 5 , ( " close_remove_share_mode: file %s. Delete on close "
" was set and unlink failed with error %s \n " ,
2009-07-11 01:50:37 +04:00
fsp_str_dbg ( fsp ) , strerror ( errno ) ) ) ;
2007-01-05 14:31:28 +03:00
status = map_nt_error_from_unix ( errno ) ;
2007-01-04 18:12:22 +03:00
}
2007-02-11 07:37:56 +03:00
/* As we now have POSIX opens which can unlink
* with other open files we may have taken
* this code path with more than one share mode
* entry - ensure we only delete once by resetting
* the delete on close flag . JRA .
*/
2010-01-13 03:04:44 +03:00
fsp - > delete_on_close = false ;
2015-04-21 12:38:32 +03:00
reset_delete_on_close_lck ( fsp , lck ) ;
2007-02-11 07:37:56 +03:00
2007-01-04 18:12:22 +03:00
done :
2007-02-07 00:05:34 +03:00
2008-01-11 03:35:54 +03:00
if ( changed_user ) {
/* unbecome user. */
pop_sec_ctx ( ) ;
}
2016-05-16 00:24:08 +03:00
if ( fsp - > kernel_share_modes_taken ) {
int ret_flock ;
/* remove filesystem sharemodes */
ret_flock = SMB_VFS_KERNEL_FLOCK ( fsp , 0 , 0 ) ;
if ( ret_flock = = - 1 ) {
DEBUG ( 2 , ( " close_remove_share_mode: removing kernel "
" flock for %s failed: %s \n " ,
fsp_str_dbg ( fsp ) , strerror ( errno ) ) ) ;
}
2013-06-13 17:23:07 +04:00
}
2012-06-01 18:29:51 +04:00
if ( ! del_share_mode ( lck , fsp ) ) {
DEBUG ( 0 , ( " close_remove_share_mode: Could not delete share "
" entry for file %s \n " , fsp_str_dbg ( fsp ) ) ) ;
}
2006-02-20 20:59:58 +03:00
TALLOC_FREE ( lck ) ;
2011-01-21 12:30:13 +03:00
if ( delete_file ) {
/*
* Do the notification after we released the share
* mode lock . Inside notify_fname we take out another
* tdb lock . With ctdb also accessing our databases ,
* this can lead to deadlocks . Putting this notify
* after the TALLOC_FREE ( lck ) above we avoid locking
* two records simultaneously . Notifies are async and
* informational only , so calling the notify_fname
* without holding the share mode lock should not do
* any harm .
*/
notify_fname ( conn , NOTIFY_ACTION_REMOVED ,
FILE_NOTIFY_CHANGE_FILE_NAME ,
fsp - > fsp_name - > base_name ) ;
}
2007-01-05 14:31:28 +03:00
return status ;
2006-05-18 03:15:53 +04:00
}
2009-11-06 09:58:12 +03:00
void set_close_write_time ( struct files_struct * fsp , struct timespec ts )
2008-03-12 17:39:38 +03:00
{
DEBUG ( 6 , ( " close_write_time: %s " , time_to_asc ( convert_timespec_to_time_t ( ts ) ) ) ) ;
2019-12-02 18:30:50 +03:00
if ( is_omit_timespec ( & ts ) ) {
2008-03-12 17:39:38 +03:00
return ;
}
2009-11-06 08:27:25 +03:00
fsp - > write_time_forced = false ;
2008-03-12 17:39:38 +03:00
fsp - > update_write_time_on_close = true ;
fsp - > close_write_time = ts ;
}
static NTSTATUS update_write_time_on_close ( struct files_struct * fsp )
{
2009-01-24 01:40:19 +03:00
struct smb_file_time ft ;
2008-03-12 17:39:38 +03:00
NTSTATUS status ;
2009-11-06 09:58:12 +03:00
struct share_mode_lock * lck = NULL ;
2008-03-12 17:39:38 +03:00
2019-12-02 18:30:50 +03:00
init_smb_file_time ( & ft ) ;
2008-03-12 17:39:38 +03:00
if ( ! fsp - > update_write_time_on_close ) {
return NT_STATUS_OK ;
}
2019-12-02 18:30:50 +03:00
if ( is_omit_timespec ( & fsp - > close_write_time ) ) {
2008-03-12 17:39:38 +03:00
fsp - > close_write_time = timespec_current ( ) ;
}
/* Ensure we have a valid stat struct for the source. */
2009-10-03 00:45:38 +04:00
status = vfs_stat_fsp ( fsp ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2009-02-26 01:57:16 +03:00
}
2009-07-11 01:50:37 +04:00
if ( ! VALID_STAT ( fsp - > fsp_name - > st ) ) {
2008-03-12 17:39:38 +03:00
/* if it doesn't seem to be a real file */
2009-07-11 01:50:37 +04:00
return NT_STATUS_OK ;
2008-03-12 17:39:38 +03:00
}
2012-05-19 06:29:36 +04:00
/*
* get_existing_share_mode_lock ( ) isn ' t really the right
* call here , as we ' re being called after
* close_remove_share_mode ( ) inside close_normal_file ( )
* so it ' s quite normal to not have an existing share
* mode here . However , get_share_mode_lock ( ) doesn ' t
* work because that will create a new share mode if
* one doesn ' t exist - so stick with this call ( just
* ignore any error we get if the share mode doesn ' t
* exist .
*/
2009-11-06 09:58:12 +03:00
2012-02-19 17:23:56 +04:00
lck = get_existing_share_mode_lock ( talloc_tos ( ) , fsp - > file_id ) ;
2009-11-06 09:58:12 +03:00
if ( lck ) {
2012-05-19 06:29:36 +04:00
/* On close if we're changing the real file time we
* must update it in the open file db too . */
( void ) set_write_time ( fsp - > file_id , fsp - > close_write_time ) ;
2009-11-06 09:58:12 +03:00
/* Close write times overwrite sticky write times
so we must replace any sticky write time here . */
2019-12-02 18:30:50 +03:00
if ( ! null_nttime ( lck - > data - > changed_write_time ) ) {
2009-11-06 09:58:12 +03:00
( void ) set_sticky_write_time ( fsp - > file_id , fsp - > close_write_time ) ;
}
TALLOC_FREE ( lck ) ;
}
2009-01-24 01:40:19 +03:00
ft . mtime = fsp - > close_write_time ;
2011-11-16 05:41:48 +04:00
/* As this is a close based update, we are not directly changing the
2011-02-23 03:38:42 +03:00
file attributes from a client call , but indirectly from a write . */
2011-11-16 05:41:48 +04:00
status = smb_set_file_time ( fsp - > conn , fsp , fsp - > fsp_name , & ft , false ) ;
2008-03-12 17:39:38 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-02-23 03:38:42 +03:00
DEBUG ( 10 , ( " update_write_time_on_close: smb_set_file_time "
" on file %s returned %s \n " ,
fsp_str_dbg ( fsp ) ,
nt_errstr ( status ) ) ) ;
2009-07-11 01:50:37 +04:00
return status ;
2008-03-12 17:39:38 +03:00
}
2009-07-03 00:39:20 +04:00
return status ;
2008-03-12 17:39:38 +03:00
}
2009-06-07 01:20:44 +04:00
static NTSTATUS ntstatus_keeperror ( NTSTATUS s1 , NTSTATUS s2 )
{
if ( ! NT_STATUS_IS_OK ( s1 ) ) {
return s1 ;
}
return s2 ;
}
2020-03-09 13:16:37 +03:00
static void close_free_pending_aio ( struct files_struct * fsp ,
enum file_close_type close_type )
{
unsigned num_requests = fsp - > num_aio_requests ;
if ( num_requests = = 0 ) {
return ;
}
if ( close_type ! = SHUTDOWN_CLOSE ) {
/*
* reply_close and the smb2 close must have
* taken care of this . No other callers of
* close_file should ever have created async
* I / O .
*
* We need to panic here because if we close ( )
* the fd while we have outstanding async I / O
* requests , in the worst case we could end up
* writing to the wrong file .
*/
DBG_ERR ( " fsp->num_aio_requests=%u \n " , num_requests ) ;
smb_panic ( " can not close with outstanding aio requests " ) ;
return ;
}
/*
* For shutdown close , just drop the async requests
* including a potential close request pending for
* this fsp . Drop the close request first , the
* destructor for the aio_requests would execute it .
*/
TALLOC_FREE ( fsp - > deferred_close ) ;
while ( fsp - > num_aio_requests ! = 0 ) {
/*
* Previously we just called talloc_free ( )
* on the outstanding request , but this
* caused crashes ( before the async callback
* functions were fixed not to reference req
* directly ) and also leaves the SMB2 request
* outstanding on the processing queue .
*
2020-03-09 13:31:00 +03:00
* Using tevent_req_ [ nt ] error ( ) instead
2020-03-09 13:16:37 +03:00
* causes the outstanding SMB1 / 2 / 3 request to
* return with NT_STATUS_INVALID_HANDLE
* and removes it from the processing queue .
*
* The callback function called from this
* calls talloc_free ( req ) . The destructor will remove
* itself from the fsp and the aio_requests array .
*/
2020-03-09 13:31:00 +03:00
if ( fsp - > is_directory ) {
tevent_req_nterror ( fsp - > aio_requests [ 0 ] ,
NT_STATUS_INVALID_HANDLE ) ;
} else {
tevent_req_error ( fsp - > aio_requests [ 0 ] , EBADF ) ;
}
2020-03-09 13:16:37 +03:00
/* Paranoia to ensure we don't spin. */
num_requests - - ;
if ( fsp - > num_aio_requests ! = num_requests ) {
smb_panic ( " cannot cancel outstanding aio "
" requests " ) ;
}
}
}
2006-05-18 03:15:53 +04:00
/****************************************************************************
Close a file .
close_type can be NORMAL_CLOSE = 0 , SHUTDOWN_CLOSE , ERROR_CLOSE .
printing and magic scripts are only run on normal close .
delete on close is done on normal and shutdown close .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-10-09 18:27:49 +04:00
static NTSTATUS close_normal_file ( struct smb_request * req , files_struct * fsp ,
enum file_close_type close_type )
2006-05-18 03:15:53 +04:00
{
2007-02-07 00:05:34 +03:00
NTSTATUS status = NT_STATUS_OK ;
2009-06-07 01:20:44 +04:00
NTSTATUS tmp ;
2006-05-18 03:15:53 +04:00
connection_struct * conn = fsp - > conn ;
2012-08-03 18:47:57 +04:00
bool is_durable = false ;
This is a big, rather ugly patch. Whilst investigating the files not truncated
when copying to a full disk problem, I discovered that we were not allowing
the delete on close flag to be set properly, this led to other things, and
after investigation of the proper delete on close semantics and their relationship
to the file_share_delete flag I discovered there were some cases where we
weren't doing the deny modes properly. And this after only 5 years working
on them..... :-) :-).
So here's the latest attempt. I realised the delete on close flag needs to
be set across all smbds with a dev/ino pair open - in addition, the delete
on close flag, allow share delete and delete access requested all need to
be stored in the share mode tdb.
The "delete_on_close" entry in the fsp struct is now redundant and should
really be removed. This may also mean we can get rid of the "iterate_fsp"
calls that I didn't like adding in the first place. Whilst doing this patch,
I also discovered we needed to do the se_map_generic() call for file opens
and POSIX ACL mapping, so I added that also.
This code, although ugly, now passes the deny mode torture tests plus the
delete on close tests I added. I do need to add one more multiple connection
delete on close test to make sure I got the semantics exactly right, plus we
should also (as Andrew suggested) move to random testing here.
The good news is that NT should now correctly delete the file on disk
full error when copying to a disk :-).
Jeremy.
(This used to be commit 51987684bd231c744da2e5f3705fd236d5616173)
2001-03-30 12:57:24 +04:00
2020-03-09 13:16:37 +03:00
close_free_pending_aio ( fsp , close_type ) ;
2010-06-05 08:00:24 +04:00
2019-06-13 13:38:57 +03:00
while ( talloc_array_length ( fsp - > blocked_smb1_lock_reqs ) ! = 0 ) {
smbd_smb1_brl_finish_by_req (
fsp - > blocked_smb1_lock_reqs [ 0 ] ,
NT_STATUS_RANGE_NOT_LOCKED ) ;
}
2006-05-18 03:15:53 +04:00
/*
* If we ' re flushing on a close we can get a write
* error here , we must remember this .
*/
2012-08-03 18:47:57 +04:00
if ( NT_STATUS_IS_OK ( status ) & & fsp - > op ! = NULL ) {
is_durable = fsp - > op - > global - > durable ;
}
if ( close_type ! = SHUTDOWN_CLOSE ) {
is_durable = false ;
}
if ( is_durable ) {
DATA_BLOB new_cookie = data_blob_null ;
tmp = SMB_VFS_DURABLE_DISCONNECT ( fsp ,
fsp - > op - > global - > backend_cookie ,
fsp - > op ,
& new_cookie ) ;
if ( NT_STATUS_IS_OK ( tmp ) ) {
2013-02-13 17:26:43 +04:00
struct timeval tv ;
NTTIME now ;
if ( req ! = NULL ) {
tv = req - > request_time ;
} else {
tv = timeval_current ( ) ;
}
now = timeval_to_nttime ( & tv ) ;
2012-08-03 18:47:57 +04:00
data_blob_free ( & fsp - > op - > global - > backend_cookie ) ;
fsp - > op - > global - > backend_cookie = new_cookie ;
2013-02-19 02:21:24 +04:00
fsp - > op - > compat = NULL ;
2013-02-13 17:26:43 +04:00
tmp = smbXsrv_open_close ( fsp - > op , now ) ;
2013-02-12 20:44:51 +04:00
if ( ! NT_STATUS_IS_OK ( tmp ) ) {
DEBUG ( 1 , ( " Failed to update smbXsrv_open "
" record when disconnecting durable "
" handle for file %s: %s - "
" proceeding with normal close \n " ,
fsp_str_dbg ( fsp ) , nt_errstr ( tmp ) ) ) ;
}
2013-03-20 13:01:43 +04:00
scavenger_schedule_disconnected ( fsp ) ;
2013-02-12 20:44:51 +04:00
} else {
DEBUG ( 1 , ( " Failed to disconnect durable handle for "
" file %s: %s - proceeding with normal "
" close \n " , fsp_str_dbg ( fsp ) , nt_errstr ( tmp ) ) ) ;
2012-08-03 18:47:57 +04:00
}
if ( ! NT_STATUS_IS_OK ( tmp ) ) {
is_durable = false ;
}
}
if ( is_durable ) {
/*
* This is the case where we successfully disconnected
* a durable handle and closed the underlying file .
* In all other cases , we proceed with a genuine close .
*/
2013-02-12 20:44:51 +04:00
DEBUG ( 10 , ( " %s disconnected durable handle for file %s \n " ,
conn - > session_info - > unix_info - > unix_name ,
fsp_str_dbg ( fsp ) ) ) ;
2012-08-03 18:47:57 +04:00
file_free ( req , fsp ) ;
return NT_STATUS_OK ;
}
if ( fsp - > op ! = NULL ) {
/*
* Make sure the handle is not marked as durable anymore
*/
fsp - > op - > global - > durable = false ;
}
2006-05-18 03:15:53 +04:00
if ( fsp - > print_file ) {
2010-05-04 12:28:48 +04:00
/* FIXME: return spool errors */
print_spool_end ( fsp , close_type ) ;
2008-10-09 18:27:49 +04:00
file_free ( req , fsp ) ;
2007-02-07 00:05:34 +03:00
return NT_STATUS_OK ;
2006-05-18 03:15:53 +04:00
}
/* If this is an old DOS or FCB open and we have multiple opens on
the same handle we only have one share mode . Ensure we only remove
the share mode on the last close . */
if ( fsp - > fh - > ref_count = = 1 ) {
/* Should we return on error here... ? */
2009-06-07 01:20:44 +04:00
tmp = close_remove_share_mode ( fsp , close_type ) ;
status = ntstatus_keeperror ( status , tmp ) ;
2006-05-18 03:15:53 +04:00
}
2019-07-01 16:35:19 +03:00
locking_close_file ( fsp , close_type ) ;
This is a big, rather ugly patch. Whilst investigating the files not truncated
when copying to a full disk problem, I discovered that we were not allowing
the delete on close flag to be set properly, this led to other things, and
after investigation of the proper delete on close semantics and their relationship
to the file_share_delete flag I discovered there were some cases where we
weren't doing the deny modes properly. And this after only 5 years working
on them..... :-) :-).
So here's the latest attempt. I realised the delete on close flag needs to
be set across all smbds with a dev/ino pair open - in addition, the delete
on close flag, allow share delete and delete access requested all need to
be stored in the share mode tdb.
The "delete_on_close" entry in the fsp struct is now redundant and should
really be removed. This may also mean we can get rid of the "iterate_fsp"
calls that I didn't like adding in the first place. Whilst doing this patch,
I also discovered we needed to do the se_map_generic() call for file opens
and POSIX ACL mapping, so I added that also.
This code, although ugly, now passes the deny mode torture tests plus the
delete on close tests I added. I do need to add one more multiple connection
delete on close test to make sure I got the semantics exactly right, plus we
should also (as Andrew suggested) move to random testing here.
The good news is that NT should now correctly delete the file on disk
full error when copying to a disk :-).
Jeremy.
(This used to be commit 51987684bd231c744da2e5f3705fd236d5616173)
2001-03-30 12:57:24 +04:00
2009-06-07 01:20:44 +04:00
tmp = fd_close ( fsp ) ;
status = ntstatus_keeperror ( status , tmp ) ;
2004-10-21 23:51:33 +04:00
This is a big, rather ugly patch. Whilst investigating the files not truncated
when copying to a full disk problem, I discovered that we were not allowing
the delete on close flag to be set properly, this led to other things, and
after investigation of the proper delete on close semantics and their relationship
to the file_share_delete flag I discovered there were some cases where we
weren't doing the deny modes properly. And this after only 5 years working
on them..... :-) :-).
So here's the latest attempt. I realised the delete on close flag needs to
be set across all smbds with a dev/ino pair open - in addition, the delete
on close flag, allow share delete and delete access requested all need to
be stored in the share mode tdb.
The "delete_on_close" entry in the fsp struct is now redundant and should
really be removed. This may also mean we can get rid of the "iterate_fsp"
calls that I didn't like adding in the first place. Whilst doing this patch,
I also discovered we needed to do the se_map_generic() call for file opens
and POSIX ACL mapping, so I added that also.
This code, although ugly, now passes the deny mode torture tests plus the
delete on close tests I added. I do need to add one more multiple connection
delete on close test to make sure I got the semantics exactly right, plus we
should also (as Andrew suggested) move to random testing here.
The good news is that NT should now correctly delete the file on disk
full error when copying to a disk :-).
Jeremy.
(This used to be commit 51987684bd231c744da2e5f3705fd236d5616173)
2001-03-30 12:57:24 +04:00
/* check for magic scripts */
2006-02-02 23:44:50 +03:00
if ( close_type = = NORMAL_CLOSE ) {
2009-06-07 01:27:31 +04:00
tmp = check_magic ( fsp ) ;
status = ntstatus_keeperror ( status , tmp ) ;
This is a big, rather ugly patch. Whilst investigating the files not truncated
when copying to a full disk problem, I discovered that we were not allowing
the delete on close flag to be set properly, this led to other things, and
after investigation of the proper delete on close semantics and their relationship
to the file_share_delete flag I discovered there were some cases where we
weren't doing the deny modes properly. And this after only 5 years working
on them..... :-) :-).
So here's the latest attempt. I realised the delete on close flag needs to
be set across all smbds with a dev/ino pair open - in addition, the delete
on close flag, allow share delete and delete access requested all need to
be stored in the share mode tdb.
The "delete_on_close" entry in the fsp struct is now redundant and should
really be removed. This may also mean we can get rid of the "iterate_fsp"
calls that I didn't like adding in the first place. Whilst doing this patch,
I also discovered we needed to do the se_map_generic() call for file opens
and POSIX ACL mapping, so I added that also.
This code, although ugly, now passes the deny mode torture tests plus the
delete on close tests I added. I do need to add one more multiple connection
delete on close test to make sure I got the semantics exactly right, plus we
should also (as Andrew suggested) move to random testing here.
The good news is that NT should now correctly delete the file on disk
full error when copying to a disk :-).
Jeremy.
(This used to be commit 51987684bd231c744da2e5f3705fd236d5616173)
2001-03-30 12:57:24 +04:00
}
2001-12-17 00:04:19 +03:00
/*
* Ensure pending modtime is set after close .
*/
2009-06-07 01:20:44 +04:00
tmp = update_write_time_on_close ( fsp ) ;
if ( NT_STATUS_EQUAL ( tmp , NT_STATUS_OBJECT_NAME_NOT_FOUND ) ) {
2009-02-26 01:57:16 +03:00
/* Someone renamed the file or a parent directory containing
* this file . We can ' t do anything about this , we don ' t have
* an " update timestamp by fd " call in POSIX . Eat the error . */
2009-06-07 01:20:44 +04:00
tmp = NT_STATUS_OK ;
2009-02-26 01:57:16 +03:00
}
This is a big, rather ugly patch. Whilst investigating the files not truncated
when copying to a full disk problem, I discovered that we were not allowing
the delete on close flag to be set properly, this led to other things, and
after investigation of the proper delete on close semantics and their relationship
to the file_share_delete flag I discovered there were some cases where we
weren't doing the deny modes properly. And this after only 5 years working
on them..... :-) :-).
So here's the latest attempt. I realised the delete on close flag needs to
be set across all smbds with a dev/ino pair open - in addition, the delete
on close flag, allow share delete and delete access requested all need to
be stored in the share mode tdb.
The "delete_on_close" entry in the fsp struct is now redundant and should
really be removed. This may also mean we can get rid of the "iterate_fsp"
calls that I didn't like adding in the first place. Whilst doing this patch,
I also discovered we needed to do the se_map_generic() call for file opens
and POSIX ACL mapping, so I added that also.
This code, although ugly, now passes the deny mode torture tests plus the
delete on close tests I added. I do need to add one more multiple connection
delete on close test to make sure I got the semantics exactly right, plus we
should also (as Andrew suggested) move to random testing here.
The good news is that NT should now correctly delete the file on disk
full error when copying to a disk :-).
Jeremy.
(This used to be commit 51987684bd231c744da2e5f3705fd236d5616173)
2001-03-30 12:57:24 +04:00
2009-06-07 01:20:44 +04:00
status = ntstatus_keeperror ( status , tmp ) ;
2007-02-07 00:05:34 +03:00
1999-12-13 16:27:58 +03:00
DEBUG ( 2 , ( " %s closed file %s (numopen=%d) %s \n " ,
2011-07-15 09:55:31 +04:00
conn - > session_info - > unix_info - > unix_name , fsp_str_dbg ( fsp ) ,
2008-11-21 23:14:53 +03:00
conn - > num_files_open - 1 ,
2007-02-07 00:05:34 +03:00
nt_errstr ( status ) ) ) ;
1998-08-17 17:11:34 +04:00
2008-10-09 18:27:49 +04:00
file_free ( req , fsp ) ;
2007-02-07 00:05:34 +03:00
return status ;
1998-08-17 17:11:34 +04:00
}
2009-12-04 00:01:10 +03:00
/****************************************************************************
2012-10-01 11:55:28 +04:00
Function used by reply_rmdir to delete an entire directory
2009-12-04 00:01:10 +03:00
tree recursively . Return True on ok , False on fail .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2012-10-01 11:55:28 +04:00
bool recursive_rmdir ( TALLOC_CTX * ctx ,
connection_struct * conn ,
struct smb_filename * smb_dname )
2009-12-04 00:01:10 +03:00
{
const char * dname = NULL ;
char * talloced = NULL ;
bool ret = True ;
long offset = 0 ;
SMB_STRUCT_STAT st ;
struct smb_Dir * dir_hnd ;
2019-09-13 22:29:41 +03:00
int retval ;
2009-12-04 00:01:10 +03:00
SMB_ASSERT ( ! is_ntfs_stream_smb_fname ( smb_dname ) ) ;
2016-02-27 02:55:14 +03:00
dir_hnd = OpenDir ( talloc_tos ( ) , conn , smb_dname , NULL , 0 ) ;
2009-12-04 00:01:10 +03:00
if ( dir_hnd = = NULL )
return False ;
while ( ( dname = ReadDirName ( dir_hnd , & offset , & st , & talloced ) ) ) {
struct smb_filename * smb_dname_full = NULL ;
char * fullname = NULL ;
bool do_break = true ;
if ( ISDOT ( dname ) | | ISDOTDOT ( dname ) ) {
TALLOC_FREE ( talloced ) ;
continue ;
}
if ( ! is_visible_file ( conn , smb_dname - > base_name , dname , & st ,
false ) ) {
TALLOC_FREE ( talloced ) ;
continue ;
}
/* Construct the full name. */
fullname = talloc_asprintf ( ctx ,
" %s/%s " ,
smb_dname - > base_name ,
dname ) ;
if ( ! fullname ) {
errno = ENOMEM ;
goto err_break ;
}
2016-03-19 07:19:38 +03:00
smb_dname_full = synthetic_smb_fname ( talloc_tos ( ) ,
fullname ,
NULL ,
NULL ,
smb_dname - > flags ) ;
2013-04-15 13:27:35 +04:00
if ( smb_dname_full = = NULL ) {
errno = ENOMEM ;
2009-12-04 00:01:10 +03:00
goto err_break ;
}
if ( SMB_VFS_LSTAT ( conn , smb_dname_full ) ! = 0 ) {
goto err_break ;
}
if ( smb_dname_full - > st . st_ex_mode & S_IFDIR ) {
if ( ! recursive_rmdir ( ctx , conn , smb_dname_full ) ) {
goto err_break ;
}
2019-10-04 22:54:05 +03:00
retval = SMB_VFS_UNLINKAT ( conn ,
conn - > cwd_fsp ,
smb_dname_full ,
AT_REMOVEDIR ) ;
if ( retval ! = 0 ) {
2009-12-04 00:01:10 +03:00
goto err_break ;
}
2019-09-13 22:29:41 +03:00
} else {
retval = SMB_VFS_UNLINKAT ( conn ,
conn - > cwd_fsp ,
smb_dname_full ,
0 ) ;
if ( retval ! = 0 ) {
goto err_break ;
}
2009-12-04 00:01:10 +03:00
}
/* Successful iteration. */
do_break = false ;
err_break :
TALLOC_FREE ( smb_dname_full ) ;
TALLOC_FREE ( fullname ) ;
TALLOC_FREE ( talloced ) ;
if ( do_break ) {
ret = false ;
break ;
}
}
TALLOC_FREE ( dir_hnd ) ;
return ret ;
}
/****************************************************************************
The internals of the rmdir code - called elsewhere .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static NTSTATUS rmdir_internals ( TALLOC_CTX * ctx , files_struct * fsp )
{
connection_struct * conn = fsp - > conn ;
struct smb_filename * smb_dname = fsp - > fsp_name ;
2019-11-04 14:29:44 +03:00
const struct loadparm_substitution * lp_sub =
loadparm_s3_global_substitution ( ) ;
2009-12-04 00:01:10 +03:00
int ret ;
SMB_ASSERT ( ! is_ntfs_stream_smb_fname ( smb_dname ) ) ;
/* Might be a symlink. */
if ( SMB_VFS_LSTAT ( conn , smb_dname ) ! = 0 ) {
return map_nt_error_from_unix ( errno ) ;
}
if ( S_ISLNK ( smb_dname - > st . st_ex_mode ) ) {
/* Is what it points to a directory ? */
if ( SMB_VFS_STAT ( conn , smb_dname ) ! = 0 ) {
return map_nt_error_from_unix ( errno ) ;
}
if ( ! ( S_ISDIR ( smb_dname - > st . st_ex_mode ) ) ) {
return NT_STATUS_NOT_A_DIRECTORY ;
}
2019-09-13 22:34:31 +03:00
ret = SMB_VFS_UNLINKAT ( conn ,
conn - > cwd_fsp ,
smb_dname ,
0 ) ;
2009-12-04 00:01:10 +03:00
} else {
2019-10-04 23:51:09 +03:00
ret = SMB_VFS_UNLINKAT ( conn ,
conn - > cwd_fsp ,
smb_dname ,
AT_REMOVEDIR ) ;
2009-12-04 00:01:10 +03:00
}
if ( ret = = 0 ) {
notify_fname ( conn , NOTIFY_ACTION_REMOVED ,
FILE_NOTIFY_CHANGE_DIR_NAME ,
smb_dname - > base_name ) ;
return NT_STATUS_OK ;
}
2019-11-04 14:29:44 +03:00
if ( ( ( errno = = ENOTEMPTY ) | | ( errno = = EEXIST ) ) & & * lp_veto_files ( talloc_tos ( ) , lp_sub , SNUM ( conn ) ) ) {
2009-12-04 00:01:10 +03:00
/*
* Check to see if the only thing in this directory are
* vetoed files / directories . If so then delete them and
* retry . If we fail to delete any of them ( and we * don ' t *
* do a recursive delete ) then fail the rmdir .
*/
SMB_STRUCT_STAT st ;
const char * dname = NULL ;
char * talloced = NULL ;
long dirpos = 0 ;
struct smb_Dir * dir_hnd = OpenDir ( talloc_tos ( ) , conn ,
2016-02-27 02:55:14 +03:00
smb_dname , NULL ,
2009-12-04 00:01:10 +03:00
0 ) ;
if ( dir_hnd = = NULL ) {
errno = ENOTEMPTY ;
goto err ;
}
while ( ( dname = ReadDirName ( dir_hnd , & dirpos , & st ,
& talloced ) ) ! = NULL ) {
if ( ( strcmp ( dname , " . " ) = = 0 ) | | ( strcmp ( dname , " .. " ) = = 0 ) ) {
TALLOC_FREE ( talloced ) ;
continue ;
}
if ( ! is_visible_file ( conn , smb_dname - > base_name , dname ,
& st , false ) ) {
TALLOC_FREE ( talloced ) ;
continue ;
}
if ( ! IS_VETO_PATH ( conn , dname ) ) {
TALLOC_FREE ( dir_hnd ) ;
TALLOC_FREE ( talloced ) ;
errno = ENOTEMPTY ;
goto err ;
}
TALLOC_FREE ( talloced ) ;
}
/* We only have veto files/directories.
* Are we allowed to delete them ? */
2014-02-04 06:08:58 +04:00
if ( ! lp_delete_veto_files ( SNUM ( conn ) ) ) {
2009-12-04 00:01:10 +03:00
TALLOC_FREE ( dir_hnd ) ;
errno = ENOTEMPTY ;
goto err ;
}
/* Do a recursive delete. */
RewindDir ( dir_hnd , & dirpos ) ;
while ( ( dname = ReadDirName ( dir_hnd , & dirpos , & st ,
& talloced ) ) ! = NULL ) {
struct smb_filename * smb_dname_full = NULL ;
char * fullname = NULL ;
bool do_break = true ;
if ( ISDOT ( dname ) | | ISDOTDOT ( dname ) ) {
TALLOC_FREE ( talloced ) ;
continue ;
}
if ( ! is_visible_file ( conn , smb_dname - > base_name , dname ,
& st , false ) ) {
TALLOC_FREE ( talloced ) ;
continue ;
}
fullname = talloc_asprintf ( ctx ,
" %s/%s " ,
smb_dname - > base_name ,
dname ) ;
if ( ! fullname ) {
errno = ENOMEM ;
goto err_break ;
}
2016-03-19 07:19:38 +03:00
smb_dname_full = synthetic_smb_fname ( talloc_tos ( ) ,
fullname ,
NULL ,
NULL ,
smb_dname - > flags ) ;
2013-04-15 13:28:47 +04:00
if ( smb_dname_full = = NULL ) {
errno = ENOMEM ;
2009-12-04 00:01:10 +03:00
goto err_break ;
}
if ( SMB_VFS_LSTAT ( conn , smb_dname_full ) ! = 0 ) {
goto err_break ;
}
if ( smb_dname_full - > st . st_ex_mode & S_IFDIR ) {
2019-10-04 23:51:09 +03:00
int retval ;
2009-12-04 00:01:10 +03:00
if ( ! recursive_rmdir ( ctx , conn ,
smb_dname_full ) ) {
goto err_break ;
}
2019-10-04 23:51:09 +03:00
retval = SMB_VFS_UNLINKAT ( conn ,
conn - > cwd_fsp ,
smb_dname_full ,
AT_REMOVEDIR ) ;
if ( retval ! = 0 ) {
2009-12-04 00:01:10 +03:00
goto err_break ;
}
2019-09-13 22:34:31 +03:00
} else {
int retval = SMB_VFS_UNLINKAT ( conn ,
conn - > cwd_fsp ,
smb_dname_full ,
0 ) ;
if ( retval ! = 0 ) {
goto err_break ;
}
2009-12-04 00:01:10 +03:00
}
/* Successful iteration. */
do_break = false ;
err_break :
TALLOC_FREE ( fullname ) ;
TALLOC_FREE ( smb_dname_full ) ;
TALLOC_FREE ( talloced ) ;
if ( do_break )
break ;
}
TALLOC_FREE ( dir_hnd ) ;
/* Retry the rmdir */
2019-10-04 23:51:09 +03:00
ret = SMB_VFS_UNLINKAT ( conn ,
conn - > cwd_fsp ,
smb_dname ,
AT_REMOVEDIR ) ;
2009-12-04 00:01:10 +03:00
}
err :
if ( ret ! = 0 ) {
DEBUG ( 3 , ( " rmdir_internals: couldn't remove directory %s : "
" %s \n " , smb_fname_str_dbg ( smb_dname ) ,
strerror ( errno ) ) ) ;
return map_nt_error_from_unix ( errno ) ;
}
notify_fname ( conn , NOTIFY_ACTION_REMOVED ,
FILE_NOTIFY_CHANGE_DIR_NAME ,
smb_dname - > base_name ) ;
return NT_STATUS_OK ;
}
1998-08-17 17:11:34 +04:00
/****************************************************************************
Close a directory opened by an NT SMB call .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-10-09 18:27:49 +04:00
static NTSTATUS close_directory ( struct smb_request * req , files_struct * fsp ,
enum file_close_type close_type )
1998-08-17 17:11:34 +04:00
{
2009-07-02 20:27:44 +04:00
struct share_mode_lock * lck = NULL ;
2007-10-19 04:40:25 +04:00
bool delete_dir = False ;
2007-02-07 00:05:34 +03:00
NTSTATUS status = NT_STATUS_OK ;
2010-01-13 03:55:31 +03:00
NTSTATUS status1 = NT_STATUS_OK ;
2012-04-05 01:54:02 +04:00
const struct security_token * del_nt_token = NULL ;
2011-02-11 10:49:15 +03:00
const struct security_unix_token * del_token = NULL ;
2015-05-01 21:02:38 +03:00
NTSTATUS notify_status ;
if ( fsp - > conn - > sconn - > using_smb2 ) {
notify_status = STATUS_NOTIFY_CLEANUP ;
} else {
notify_status = NT_STATUS_OK ;
}
2005-10-28 02:35:08 +04:00
2020-03-09 13:18:23 +03:00
close_free_pending_aio ( fsp , close_type ) ;
2018-03-21 22:41:44 +03:00
1999-12-13 16:27:58 +03:00
/*
* NT can set delete_on_close of the last open
* reference to a directory also .
*/
2012-02-19 17:23:56 +04:00
lck = get_existing_share_mode_lock ( talloc_tos ( ) , fsp - > file_id ) ;
2005-10-28 02:35:08 +04:00
if ( lck = = NULL ) {
2009-07-02 20:27:44 +04:00
DEBUG ( 0 , ( " close_directory: Could not get share mode lock for "
2009-07-11 01:50:37 +04:00
" %s \n " , fsp_str_dbg ( fsp ) ) ) ;
2018-09-28 00:12:47 +03:00
file_free ( req , fsp ) ;
2012-06-02 16:04:52 +04:00
return NT_STATUS_INVALID_PARAMETER ;
2005-10-28 02:35:08 +04:00
}
2007-01-19 00:51:52 +03:00
if ( fsp - > initial_delete_on_close ) {
2007-10-19 04:40:25 +04:00
bool became_user = False ;
2007-01-19 00:51:52 +03:00
/* Initial delete on close was set - for
* directories we don ' t care if anyone else
* wrote a real delete on close . */
2010-03-15 22:13:30 +03:00
if ( get_current_vuid ( fsp - > conn ) ! = fsp - > vuid ) {
2019-07-19 12:14:13 +03:00
become_user_without_service ( fsp - > conn , fsp - > vuid ) ;
2007-01-19 00:51:52 +03:00
became_user = True ;
}
2010-07-07 00:43:14 +04:00
send_stat_cache_delete_message ( fsp - > conn - > sconn - > msg_ctx ,
fsp - > fsp_name - > base_name ) ;
2015-04-21 12:41:45 +03:00
set_delete_on_close_lck ( fsp , lck ,
2012-04-05 01:54:02 +04:00
get_current_nttok ( fsp - > conn ) ,
2011-01-26 01:23:19 +03:00
get_current_utok ( fsp - > conn ) ) ;
2010-01-13 03:04:44 +03:00
fsp - > delete_on_close = true ;
2007-01-19 00:51:52 +03:00
if ( became_user ) {
2019-07-19 12:14:13 +03:00
unbecome_user_without_service ( ) ;
2007-01-19 00:51:52 +03:00
}
}
2019-09-09 11:42:59 +03:00
delete_dir = get_delete_on_close_token (
lck , fsp - > name_hash , & del_nt_token , & del_token ) & &
! has_other_nonposix_opens ( lck , fsp ) ;
2007-01-04 19:26:15 +03:00
2006-02-02 23:44:50 +03:00
if ( ( close_type = = NORMAL_CLOSE | | close_type = = SHUTDOWN_CLOSE ) & &
2011-01-26 01:23:19 +03:00
delete_dir ) {
2006-02-02 23:44:50 +03:00
/* Become the user who requested the delete. */
if ( ! push_sec_ctx ( ) ) {
smb_panic ( " close_directory: failed to push sec_ctx. \n " ) ;
}
2011-01-26 01:23:19 +03:00
set_sec_ctx ( del_token - > uid ,
del_token - > gid ,
del_token - > ngroups ,
del_token - > groups ,
2012-04-05 01:54:02 +04:00
del_nt_token ) ;
2006-02-02 23:44:50 +03:00
2012-06-02 16:06:29 +04:00
if ( ! del_share_mode ( lck , fsp ) ) {
DEBUG ( 0 , ( " close_directory: Could not delete share entry for "
" %s \n " , fsp_str_dbg ( fsp ) ) ) ;
}
2006-02-28 09:41:07 +03:00
TALLOC_FREE ( lck ) ;
2012-02-01 01:26:23 +04:00
if ( ( fsp - > conn - > fs_capabilities & FILE_NAMED_STREAMS )
& & ! is_ntfs_stream_smb_fname ( fsp - > fsp_name ) ) {
2016-03-05 01:07:04 +03:00
status = delete_all_streams ( fsp - > conn , fsp - > fsp_name ) ;
2012-02-01 01:26:23 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 5 , ( " delete_all_streams failed: %s \n " ,
nt_errstr ( status ) ) ) ;
2018-09-28 00:12:47 +03:00
file_free ( req , fsp ) ;
2012-06-03 17:17:29 +04:00
return status ;
2012-02-01 01:26:23 +04:00
}
}
2009-12-04 00:01:10 +03:00
status = rmdir_internals ( talloc_tos ( ) , fsp ) ;
2006-02-02 23:44:50 +03:00
2007-02-11 17:55:21 +03:00
DEBUG ( 5 , ( " close_directory: %s. Delete on close was set - "
" deleting directory returned %s. \n " ,
2009-07-11 01:50:37 +04:00
fsp_str_dbg ( fsp ) , nt_errstr ( status ) ) ) ;
1999-12-13 16:27:58 +03:00
2006-02-02 23:44:50 +03:00
/* unbecome user. */
pop_sec_ctx ( ) ;
1999-12-13 16:27:58 +03:00
/*
* Ensure we remove any change notify requests that would
* now fail as the directory has been deleted .
*/
2015-05-01 21:02:38 +03:00
if ( NT_STATUS_IS_OK ( status ) ) {
notify_status = NT_STATUS_DELETE_PENDING ;
2005-07-08 08:51:27 +04:00
}
2005-10-28 03:30:25 +04:00
} else {
2012-06-02 16:06:29 +04:00
if ( ! del_share_mode ( lck , fsp ) ) {
DEBUG ( 0 , ( " close_directory: Could not delete share entry for "
" %s \n " , fsp_str_dbg ( fsp ) ) ) ;
}
2006-02-28 09:41:07 +03:00
TALLOC_FREE ( lck ) ;
2001-11-13 04:35:20 +03:00
}
1999-12-13 16:27:58 +03:00
2015-05-01 21:02:38 +03:00
remove_pending_change_notify_requests_by_fid ( fsp , notify_status ) ;
2010-01-13 03:55:31 +03:00
status1 = fd_close ( fsp ) ;
2008-11-27 03:47:14 +03:00
2010-01-13 03:55:31 +03:00
if ( ! NT_STATUS_IS_OK ( status1 ) ) {
2008-11-27 03:47:14 +03:00
DEBUG ( 0 , ( " Could not close dir! fname=%s, fd=%d, err=%d=%s \n " ,
2009-07-11 01:50:37 +04:00
fsp_str_dbg ( fsp ) , fsp - > fh - > fd , errno ,
2009-07-02 20:27:44 +04:00
strerror ( errno ) ) ) ;
2008-11-27 03:47:14 +03:00
}
1998-08-17 17:11:34 +04:00
/*
* Do the code common to files and directories .
*/
2008-10-09 18:27:49 +04:00
file_free ( req , fsp ) ;
2009-07-02 20:27:44 +04:00
2010-01-13 03:55:31 +03:00
if ( NT_STATUS_IS_OK ( status ) & & ! NT_STATUS_IS_OK ( status1 ) ) {
status = status1 ;
}
2007-02-07 00:05:34 +03:00
return status ;
2003-01-03 21:50:13 +03:00
}
1999-12-13 16:27:58 +03:00
/****************************************************************************
2003-01-03 21:50:13 +03:00
Close a files_struct .
1999-12-13 16:27:58 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-10-09 18:27:49 +04:00
NTSTATUS close_file ( struct smb_request * req , files_struct * fsp ,
enum file_close_type close_type )
1999-12-13 16:27:58 +03:00
{
2008-01-20 01:25:36 +03:00
NTSTATUS status ;
struct files_struct * base_fsp = fsp - > base_fsp ;
2007-02-07 00:05:34 +03:00
if ( fsp - > is_directory ) {
2008-10-09 18:27:49 +04:00
status = close_directory ( req , fsp , close_type ) ;
2007-02-07 00:05:34 +03:00
} else if ( fsp - > fake_file_handle ! = NULL ) {
2008-10-09 18:27:49 +04:00
status = close_fake_file ( req , fsp ) ;
2008-01-20 01:25:36 +03:00
} else {
2008-10-09 18:27:49 +04:00
status = close_normal_file ( req , fsp , close_type ) ;
2008-01-20 01:25:36 +03:00
}
if ( ( base_fsp ! = NULL ) & & ( close_type ! = SHUTDOWN_CLOSE ) ) {
/*
* fsp was a stream , the base fsp can ' t be a stream as well
*
* For SHUTDOWN_CLOSE this is not possible here , because
* SHUTDOWN_CLOSE only happens from files . c which walks the
* complete list of files . If we mess with more than one fsp
* those loops will become confused .
*/
SMB_ASSERT ( base_fsp - > base_fsp = = NULL ) ;
2008-10-09 18:27:49 +04:00
close_file ( req , base_fsp , close_type ) ;
2008-01-20 01:25:36 +03:00
}
return status ;
1999-12-13 16:27:58 +03:00
}
2008-05-27 22:23:59 +04:00
/****************************************************************************
Deal with an ( authorized ) message to close a file given the share mode
entry .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void msg_close_file ( struct messaging_context * msg_ctx ,
void * private_data ,
uint32_t msg_type ,
struct server_id server_id ,
DATA_BLOB * data )
{
files_struct * fsp = NULL ;
2018-02-07 13:40:58 +03:00
struct file_id id ;
2008-05-27 22:23:59 +04:00
struct share_mode_entry e ;
2011-12-12 18:45:07 +04:00
struct smbd_server_connection * sconn =
2011-12-14 12:50:24 +04:00
talloc_get_type_abort ( private_data ,
2011-12-12 18:45:07 +04:00
struct smbd_server_connection ) ;
2008-05-27 22:23:59 +04:00
2018-02-07 13:40:58 +03:00
message_to_share_mode_entry ( & id , & e , ( char * ) data - > data ) ;
2008-05-27 22:23:59 +04:00
if ( DEBUGLVL ( 10 ) ) {
2018-02-07 13:40:58 +03:00
char * sm_str = share_mode_str ( NULL , 0 , & id , & e ) ;
2008-05-27 22:23:59 +04:00
if ( ! sm_str ) {
smb_panic ( " talloc failed " ) ;
}
DEBUG ( 10 , ( " msg_close_file: got request to close share mode "
" entry %s \n " , sm_str ) ) ;
TALLOC_FREE ( sm_str ) ;
}
2018-02-07 13:40:58 +03:00
fsp = file_find_dif ( sconn , id , e . share_file_id ) ;
2008-05-27 22:23:59 +04:00
if ( ! fsp ) {
DEBUG ( 10 , ( " msg_close_file: failed to find file. \n " ) ) ;
return ;
}
2008-10-09 18:27:49 +04:00
close_file ( NULL , fsp , NORMAL_CLOSE ) ;
2008-05-27 22:23:59 +04:00
}