2003-05-12 05:20:17 +04:00
/*
Unix SMB / CIFS implementation .
FAKE FILE suppport , for faking up special files windows want access to
Copyright ( C ) Stefan ( metze ) Metzmacher 2003
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
2003-05-12 05:20:17 +04: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 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2003-05-12 05:20:17 +04:00
*/
# include "includes.h"
2008-03-29 20:19:31 +03:00
struct fake_file_type {
const char * name ;
enum FAKE_FILE_TYPE type ;
void * ( * init_pd ) ( TALLOC_CTX * mem_ctx ) ;
} ;
2009-01-08 10:38:01 +03:00
static const struct fake_file_type fake_files [ ] = {
2003-05-12 05:20:17 +04:00
# ifdef WITH_QUOTAS
2008-03-29 20:19:31 +03:00
{ FAKE_FILE_NAME_QUOTA_UNIX , FAKE_FILE_TYPE_QUOTA , init_quota_handle } ,
2003-05-12 05:20:17 +04:00
# endif /* WITH_QUOTAS */
2008-03-29 20:19:31 +03:00
{ NULL , FAKE_FILE_TYPE_NONE , NULL }
2003-05-12 05:20:17 +04:00
} ;
2005-07-08 08:51:27 +04:00
/****************************************************************************
Create a fake file handle
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-05-12 05:20:17 +04:00
2008-03-29 20:19:31 +03:00
static struct fake_file_handle * init_fake_file_handle ( enum FAKE_FILE_TYPE type )
2003-05-12 05:20:17 +04:00
{
2008-03-29 20:19:31 +03:00
struct fake_file_handle * fh = NULL ;
2003-05-12 05:20:17 +04:00
int i ;
2008-03-29 20:19:31 +03:00
for ( i = 0 ; fake_files [ i ] . name ! = NULL ; i + + ) {
2003-05-12 05:20:17 +04:00
if ( fake_files [ i ] . type = = type ) {
2008-03-29 20:19:31 +03:00
break ;
}
}
2003-05-12 05:20:17 +04:00
2008-03-29 20:19:31 +03:00
if ( fake_files [ i ] . name = = NULL ) {
return NULL ;
}
2003-05-12 05:20:17 +04:00
2008-03-29 20:19:31 +03:00
DEBUG ( 5 , ( " init_fake_file_handle: for [%s] \n " , fake_files [ i ] . name ) ) ;
2003-05-12 05:20:17 +04:00
2008-03-29 20:19:31 +03:00
fh = talloc ( NULL , struct fake_file_handle ) ;
if ( fh = = NULL ) {
DEBUG ( 0 , ( " TALLOC_ZERO() failed. \n " ) ) ;
return NULL ;
}
2003-05-12 05:20:17 +04:00
2008-03-29 20:19:31 +03:00
fh - > type = type ;
2003-05-12 05:20:17 +04:00
2008-03-29 20:19:31 +03:00
if ( fake_files [ i ] . init_pd ) {
fh - > private_data = fake_files [ i ] . init_pd ( fh ) ;
2003-05-12 05:20:17 +04:00
}
2008-03-29 20:19:31 +03:00
return fh ;
2003-05-12 05:20:17 +04:00
}
2005-07-08 08:51:27 +04:00
/****************************************************************************
Does this name match a fake filename ?
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
enum FAKE_FILE_TYPE is_fake_file ( const char * fname )
{
# ifdef HAVE_SYS_QUOTAS
int i ;
# endif
if ( ! fname ) {
return FAKE_FILE_TYPE_NONE ;
}
# ifdef HAVE_SYS_QUOTAS
for ( i = 0 ; fake_files [ i ] . name ! = NULL ; i + + ) {
if ( strncmp ( fname , fake_files [ i ] . name , strlen ( fake_files [ i ] . name ) ) = = 0 ) {
DEBUG ( 5 , ( " is_fake_file: [%s] is a fake file \n " , fname ) ) ;
return fake_files [ i ] . type ;
}
}
# endif
return FAKE_FILE_TYPE_NONE ;
}
/****************************************************************************
Open a fake quota file with a share mode .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-10-09 17:38:53 +04:00
NTSTATUS open_fake_file ( struct smb_request * req , connection_struct * conn ,
2008-06-15 15:37:53 +04:00
uint16_t current_vuid ,
2005-07-08 08:51:27 +04:00
enum FAKE_FILE_TYPE fake_file_type ,
const char * fname ,
2006-07-11 22:01:26 +04:00
uint32 access_mask ,
files_struct * * result )
2005-07-08 08:51:27 +04:00
{
files_struct * fsp = NULL ;
2006-07-11 22:01:26 +04:00
NTSTATUS status ;
2005-07-08 08:51:27 +04:00
/* access check */
2008-06-19 18:54:12 +04:00
if ( conn - > server_info - > utok . uid ! = 0 ) {
2007-12-02 14:54:11 +03:00
DEBUG ( 3 , ( " open_fake_file_shared: access_denied to "
" service[%s] file[%s] user[%s] \n " ,
2008-05-08 18:06:42 +04:00
lp_servicename ( SNUM ( conn ) ) , fname ,
conn - > server_info - > unix_name ) ) ;
2006-07-11 22:01:26 +04:00
return NT_STATUS_ACCESS_DENIED ;
2005-07-08 08:51:27 +04:00
}
2008-10-09 17:38:53 +04:00
status = file_new ( req , conn , & fsp ) ;
2006-07-11 22:01:26 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
2005-07-08 08:51:27 +04:00
}
DEBUG ( 5 , ( " open_fake_file_shared: fname = %s, FID = %d, access_mask = 0x%x \n " ,
fname , fsp - > fnum , ( unsigned int ) access_mask ) ) ;
fsp - > conn = conn ;
fsp - > fh - > fd = - 1 ;
2008-06-15 15:37:53 +04:00
fsp - > vuid = current_vuid ;
2005-07-08 08:51:27 +04:00
fsp - > fh - > pos = - 1 ;
2006-07-11 22:01:26 +04:00
fsp - > can_lock = False ; /* Should this be true ? - No, JRA */
2005-07-08 08:51:27 +04:00
fsp - > access_mask = access_mask ;
string_set ( & fsp - > fsp_name , fname ) ;
fsp - > fake_file_handle = init_fake_file_handle ( fake_file_type ) ;
if ( fsp - > fake_file_handle = = NULL ) {
2008-10-09 18:27:49 +04:00
file_free ( req , fsp ) ;
2006-07-11 22:01:26 +04:00
return NT_STATUS_NO_MEMORY ;
2005-07-08 08:51:27 +04:00
}
2006-07-11 22:01:26 +04:00
* result = fsp ;
return NT_STATUS_OK ;
2005-07-08 08:51:27 +04:00
}
2008-10-09 18:27:49 +04:00
NTSTATUS close_fake_file ( struct smb_request * req , files_struct * fsp )
2006-05-17 19:01:57 +04:00
{
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-17 19:01:57 +04:00
}