2003-08-12 08:35:47 +04:00
/*
Unix SMB / Netbios implementation .
Version 1.9 .
VFS module to perform read - only limitation based on a time period
Copyright ( C ) Alexander Bokovoy 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-08-12 08:35:47 +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-08-12 08:35:47 +04:00
This work was sponsored by Optifacio Software Services , Inc .
*/
# include "includes.h"
2011-03-23 00:34:22 +03:00
# include "smbd/smbd.h"
2003-08-12 08:35:47 +04:00
# include "getdate.h"
/*
This module performs a read - only limitation for specified share
( or all of them if it is loaded in a [ global ] section ) based on period
definition in smb . conf . You can stack this module multiple times under
different names to get multiple limit intervals .
The module uses get_date ( ) function from coreutils ' date utility to parse
specified dates according to date ( 1 ) rules . Look into info page for date ( 1 )
to understand the syntax .
The module accepts one parameter :
readonly : period = " begin date " , " end date "
where " begin date " and " end date " are mandatory and should comply with date ( 1 )
syntax for date strings .
Example :
readonly : period = " today 14:00 " , " today 15:00 "
Default :
readonly : period = " today 0:0:0 " , " tomorrow 0:0:0 "
The default covers whole day thus making the share readonly
*/
# define MODULE_NAME "readonly"
static int readonly_connect ( vfs_handle_struct * handle ,
const char * service ,
const char * user )
{
const char * period_def [ ] = { " today 0:0:0 " , " tomorrow 0:0:0 " } ;
const char * * period = lp_parm_string_list ( SNUM ( handle - > conn ) ,
( handle - > param ? handle - > param : MODULE_NAME ) ,
" period " , period_def ) ;
2009-12-01 02:53:04 +03:00
int ret = SMB_VFS_NEXT_CONNECT ( handle , service , user ) ;
if ( ret < 0 ) {
return ret ;
}
2003-08-12 08:35:47 +04:00
if ( period & & period [ 0 ] & & period [ 1 ] ) {
2008-11-18 01:13:20 +03:00
int i ;
2003-08-12 08:35:47 +04:00
time_t current_time = time ( NULL ) ;
time_t begin_period = get_date ( period [ 0 ] , & current_time ) ;
time_t end_period = get_date ( period [ 1 ] , & current_time ) ;
if ( ( current_time > = begin_period ) & & ( current_time < = end_period ) ) {
2008-11-18 01:13:20 +03:00
connection_struct * conn = handle - > conn ;
2006-07-11 22:01:26 +04:00
handle - > conn - > read_only = True ;
2008-11-18 01:13:20 +03:00
/* Wipe out the VUID cache. */
for ( i = 0 ; i < VUID_CACHE_SIZE ; i + + ) {
2012-12-21 02:42:55 +04:00
struct vuid_cache_entry * ent = & conn - > vuid_cache - > array [ i ] ;
2008-11-18 01:13:20 +03:00
ent - > vuid = UID_FIELD_INVALID ;
2018-07-05 14:09:53 +03:00
TALLOC_FREE ( ent - > user_vfs_evg ) ;
2011-02-21 12:25:52 +03:00
TALLOC_FREE ( ent - > session_info ) ;
2008-11-18 01:13:20 +03:00
ent - > read_only = false ;
2012-12-21 21:22:16 +04:00
ent - > share_access = 0 ;
2008-11-18 01:13:20 +03:00
}
2012-12-21 02:42:55 +04:00
conn - > vuid_cache - > next_entry = 0 ;
2003-08-12 08:35:47 +04:00
}
2009-12-01 02:53:04 +03:00
return 0 ;
2003-08-12 08:35:47 +04:00
} else {
2009-12-01 02:53:04 +03:00
return 0 ;
2003-08-12 08:35:47 +04:00
}
}
2009-07-24 04:28:58 +04:00
static struct vfs_fn_pointers vfs_readonly_fns = {
. connect_fn = readonly_connect
2003-08-12 08:35:47 +04:00
} ;
2017-04-20 22:24:43 +03:00
NTSTATUS vfs_readonly_init ( TALLOC_CTX * ) ;
NTSTATUS vfs_readonly_init ( TALLOC_CTX * ctx )
2003-08-12 08:35:47 +04:00
{
2009-07-24 04:28:58 +04:00
return smb_register_vfs ( SMB_VFS_INTERFACE_VERSION , MODULE_NAME ,
& vfs_readonly_fns ) ;
2003-08-12 08:35:47 +04:00
}