mirror of
https://github.com/samba-team/samba.git
synced 2025-03-24 10:50:22 +03:00
Add vfs_readonly module which allows to enforce periodic read-only limit on a share based on a specified start and end dates according to date(1) format
(This used to be commit 8b263c2fda89ff6aa2dc3a60460c5d46cf0814c6)
This commit is contained in:
parent
4511b334a8
commit
7bc6f49fe4
@ -300,6 +300,7 @@ VFS_FAKE_PERMS_OBJ = modules/vfs_fake_perms.o
|
||||
VFS_RECYCLE_OBJ = modules/vfs_recycle.o
|
||||
VFS_NETATALK_OBJ = modules/vfs_netatalk.o
|
||||
VFS_DEFAULT_QUOTA_OBJ = modules/vfs_default_quota.o
|
||||
VFS_READONLY_OBJ = modules/vfs_readonly.o modules/getdate.o
|
||||
|
||||
PLAINTEXT_AUTH_OBJ = auth/pampass.o auth/pass_check.o
|
||||
|
||||
@ -1065,6 +1066,11 @@ bin/default_quota.@SHLIBEXT@: $(VFS_DEFAULT_QUOTA_OBJ:.o=.po)
|
||||
@$(SHLD) $(LDSHFLAGS) -o $@ $(VFS_DEFAULT_QUOTA_OBJ:.o=.po) \
|
||||
@SONAMEFLAG@`basename $@`
|
||||
|
||||
bin/readonly.@SHLIBEXT@: $(VFS_READONLY_OBJ:.o=.po)
|
||||
@echo "Building plugin $@"
|
||||
@$(SHLD) $(LDSHFLAGS) -o $@ $(VFS_READONLY_OBJ:.o=.po) \
|
||||
@SONAMEFLAG@`basename $@`
|
||||
|
||||
bin/wbinfo@EXEEXT@: $(WBINFO_OBJ) @BUILD_POPT@ bin/.dummy
|
||||
@echo Linking $@
|
||||
@$(LINK) -o $@ $(WBINFO_OBJ) $(LIBS) @POPTLIBS@
|
||||
|
@ -287,7 +287,7 @@ dnl These have to be built static:
|
||||
default_static_modules="pdb_smbpasswd pdb_tdbsam rpc_lsa rpc_samr rpc_reg rpc_wks rpc_net rpc_dfs rpc_srv rpc_spoolss auth_rhosts auth_sam auth_unix auth_winbind auth_server auth_domain auth_builtin"
|
||||
|
||||
dnl These are preferably build shared, and static if dlopen() is not available
|
||||
default_shared_modules="vfs_recycle vfs_audit vfs_extd_audit vfs_netatalk vfs_fake_perms vfs_default_quota"
|
||||
default_shared_modules="vfs_recycle vfs_audit vfs_extd_audit vfs_netatalk vfs_fake_perms vfs_default_quota vfs_readonly"
|
||||
|
||||
if test "x$developer" = xyes; then
|
||||
default_static_modules="$default_static_modules rpc_echo"
|
||||
@ -3957,6 +3957,7 @@ SMB_MODULE(vfs_extd_audit, \$(VFS_EXTD_AUDIT_OBJ), "bin/extd_audit.$SHLIBEXT", V
|
||||
SMB_MODULE(vfs_netatalk, \$(VFS_NETATALK_OBJ), "bin/netatalk.$SHLIBEXT", VFS)
|
||||
SMB_MODULE(vfs_fake_perms, \$(VFS_FAKE_PERMS_OBJ), "bin/fake_perms.$SHLIBEXT", VFS)
|
||||
SMB_MODULE(vfs_default_quota, \$(VFS_DEFAULT_QUOTA_OBJ), "bin/default_quota.$SHLIBEXT", VFS)
|
||||
SMB_MODULE(vfs_readonly, \$(VFS_READONLY_OBJ), "bin/readonly.$SHLIBEXT", VFS)
|
||||
SMB_SUBSYSTEM(VFS)
|
||||
|
||||
AC_DEFINE_UNQUOTED(STRING_STATIC_MODULES, "$string_static_modules", [String list of builtin modules])
|
||||
|
2459
source3/modules/getdate.c
Normal file
2459
source3/modules/getdate.c
Normal file
File diff suppressed because it is too large
Load Diff
46
source3/modules/getdate.h
Normal file
46
source3/modules/getdate.h
Normal file
@ -0,0 +1,46 @@
|
||||
/* Copyright (C) 1995, 1997, 1998 Free Software Foundation, Inc.
|
||||
|
||||
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
|
||||
the Free Software Foundation; either version 2, or (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
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifndef PARAMS
|
||||
# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
|
||||
# define PARAMS(Args) Args
|
||||
# else
|
||||
# define PARAMS(Args) ()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef vms
|
||||
# include <types.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# include <sys/types.h>
|
||||
# if TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
# else
|
||||
# if HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
# endif
|
||||
#endif /* defined (vms) */
|
||||
|
||||
time_t get_date PARAMS ((const char *p, const time_t *now));
|
1114
source3/modules/getdate.y
Normal file
1114
source3/modules/getdate.y
Normal file
File diff suppressed because it is too large
Load Diff
98
source3/modules/vfs_readonly.c
Normal file
98
source3/modules/vfs_readonly.c
Normal file
@ -0,0 +1,98 @@
|
||||
/*
|
||||
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
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(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
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
This work was sponsored by Optifacio Software Services, Inc.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
#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,
|
||||
connection_struct *conn,
|
||||
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);
|
||||
|
||||
if (period && period[0] && period[1]) {
|
||||
time_t current_time = time(NULL);
|
||||
time_t begin_period = get_date(period[0], ¤t_time);
|
||||
time_t end_period = get_date(period[1], ¤t_time);
|
||||
|
||||
if ((current_time >= begin_period) && (current_time <= end_period)) {
|
||||
conn->read_only = True;
|
||||
}
|
||||
|
||||
return SMB_VFS_NEXT_CONNECT(handle, conn, service, user);
|
||||
|
||||
} else {
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* VFS operations structure */
|
||||
|
||||
static vfs_op_tuple readonly_op_tuples[] = {
|
||||
/* Disk operations */
|
||||
{SMB_VFS_OP(readonly_connect), SMB_VFS_OP_CONNECT, SMB_VFS_LAYER_OPAQUE},
|
||||
{SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP}
|
||||
};
|
||||
|
||||
NTSTATUS init_module(void)
|
||||
{
|
||||
return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, MODULE_NAME, readonly_op_tuples);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user