r11123: * patches from Brian Moran for creating new eventlog
[Samba.git] / source / modules / vfs_readonly.c
blobee9e40c2fcaa7b51a6caab0af6161750d6eba993
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
4 VFS module to perform read-only limitation based on a time period
5 Copyright (C) Alexander Bokovoy 2003
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 This work was sponsored by Optifacio Software Services, Inc.
24 #include "includes.h"
25 #include "getdate.h"
28 This module performs a read-only limitation for specified share
29 (or all of them if it is loaded in a [global] section) based on period
30 definition in smb.conf. You can stack this module multiple times under
31 different names to get multiple limit intervals.
33 The module uses get_date() function from coreutils' date utility to parse
34 specified dates according to date(1) rules. Look into info page for date(1)
35 to understand the syntax.
37 The module accepts one parameter:
39 readonly: period = "begin date","end date"
41 where "begin date" and "end date" are mandatory and should comply with date(1)
42 syntax for date strings.
44 Example:
46 readonly: period = "today 14:00","today 15:00"
48 Default:
50 readonly: period = "today 0:0:0","tomorrow 0:0:0"
52 The default covers whole day thus making the share readonly
56 #define MODULE_NAME "readonly"
57 static int readonly_connect(vfs_handle_struct *handle,
58 connection_struct *conn,
59 const char *service,
60 const char *user)
62 const char *period_def[] = {"today 0:0:0", "tomorrow 0:0:0"};
64 const char **period = lp_parm_string_list(SNUM(handle->conn),
65 (handle->param ? handle->param : MODULE_NAME),
66 "period", period_def);
68 if (period && period[0] && period[1]) {
69 time_t current_time = time(NULL);
70 time_t begin_period = get_date(period[0], &current_time);
71 time_t end_period = get_date(period[1], &current_time);
73 if ((current_time >= begin_period) && (current_time <= end_period)) {
74 conn->read_only = True;
77 return SMB_VFS_NEXT_CONNECT(handle, conn, service, user);
79 } else {
81 return 1;
87 /* VFS operations structure */
89 static vfs_op_tuple readonly_op_tuples[] = {
90 /* Disk operations */
91 {SMB_VFS_OP(readonly_connect), SMB_VFS_OP_CONNECT, SMB_VFS_LAYER_TRANSPARENT},
92 {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP}
95 NTSTATUS vfs_readonly_init(void)
97 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, MODULE_NAME, readonly_op_tuples);