| 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
|
|---|
| 6 |
|
|---|
| 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 3 of the License, or
|
|---|
| 10 | (at your option) any later version.
|
|---|
| 11 |
|
|---|
| 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.
|
|---|
| 16 |
|
|---|
| 17 | You should have received a copy of the GNU General Public License
|
|---|
| 18 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 19 |
|
|---|
| 20 | This work was sponsored by Optifacio Software Services, Inc.
|
|---|
| 21 | */
|
|---|
| 22 |
|
|---|
| 23 | #include "includes.h"
|
|---|
| 24 | #include "smbd/smbd.h"
|
|---|
| 25 | #include "getdate.h"
|
|---|
| 26 |
|
|---|
| 27 | /*
|
|---|
| 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.
|
|---|
| 32 |
|
|---|
| 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.
|
|---|
| 36 |
|
|---|
| 37 | The module accepts one parameter:
|
|---|
| 38 |
|
|---|
| 39 | readonly: period = "begin date","end date"
|
|---|
| 40 |
|
|---|
| 41 | where "begin date" and "end date" are mandatory and should comply with date(1)
|
|---|
| 42 | syntax for date strings.
|
|---|
| 43 |
|
|---|
| 44 | Example:
|
|---|
| 45 |
|
|---|
| 46 | readonly: period = "today 14:00","today 15:00"
|
|---|
| 47 |
|
|---|
| 48 | Default:
|
|---|
| 49 |
|
|---|
| 50 | readonly: period = "today 0:0:0","tomorrow 0:0:0"
|
|---|
| 51 |
|
|---|
| 52 | The default covers whole day thus making the share readonly
|
|---|
| 53 |
|
|---|
| 54 | */
|
|---|
| 55 |
|
|---|
| 56 | #define MODULE_NAME "readonly"
|
|---|
| 57 | static int readonly_connect(vfs_handle_struct *handle,
|
|---|
| 58 | const char *service,
|
|---|
| 59 | const char *user)
|
|---|
| 60 | {
|
|---|
| 61 | const char *period_def[] = {"today 0:0:0", "tomorrow 0:0:0"};
|
|---|
| 62 |
|
|---|
| 63 | const char **period = lp_parm_string_list(SNUM(handle->conn),
|
|---|
| 64 | (handle->param ? handle->param : MODULE_NAME),
|
|---|
| 65 | "period", period_def);
|
|---|
| 66 | int ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
|
|---|
| 67 |
|
|---|
| 68 | if (ret < 0) {
|
|---|
| 69 | return ret;
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | if (period && period[0] && period[1]) {
|
|---|
| 73 | int i;
|
|---|
| 74 | time_t current_time = time(NULL);
|
|---|
| 75 | time_t begin_period = get_date(period[0], ¤t_time);
|
|---|
| 76 | time_t end_period = get_date(period[1], ¤t_time);
|
|---|
| 77 |
|
|---|
| 78 | if ((current_time >= begin_period) && (current_time <= end_period)) {
|
|---|
| 79 | connection_struct *conn = handle->conn;
|
|---|
| 80 |
|
|---|
| 81 | handle->conn->read_only = True;
|
|---|
| 82 |
|
|---|
| 83 | /* Wipe out the VUID cache. */
|
|---|
| 84 | for (i=0; i< VUID_CACHE_SIZE; i++) {
|
|---|
| 85 | struct vuid_cache_entry *ent = ent = &conn->vuid_cache.array[i];
|
|---|
| 86 | ent->vuid = UID_FIELD_INVALID;
|
|---|
| 87 | TALLOC_FREE(ent->session_info);
|
|---|
| 88 | ent->read_only = false;
|
|---|
| 89 | }
|
|---|
| 90 | conn->vuid_cache.next_entry = 0;
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | return 0;
|
|---|
| 94 |
|
|---|
| 95 | } else {
|
|---|
| 96 |
|
|---|
| 97 | return 0;
|
|---|
| 98 |
|
|---|
| 99 | }
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 | static struct vfs_fn_pointers vfs_readonly_fns = {
|
|---|
| 104 | .connect_fn = readonly_connect
|
|---|
| 105 | };
|
|---|
| 106 |
|
|---|
| 107 | NTSTATUS vfs_readonly_init(void);
|
|---|
| 108 | NTSTATUS vfs_readonly_init(void)
|
|---|
| 109 | {
|
|---|
| 110 | return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, MODULE_NAME,
|
|---|
| 111 | &vfs_readonly_fns);
|
|---|
| 112 | }
|
|---|