00001 /* 00002 Unix SMB/Netbios implementation. 00003 Version 1.9. 00004 VFS module to perform read-only limitation based on a time period 00005 Copyright (C) Alexander Bokovoy 2003 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 2 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software 00019 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00020 00021 This work was sponsored by Optifacio Software Services, Inc. 00022 */ 00023 00024 #include "includes.h" 00025 #include "getdate.h" 00026 00027 /* 00028 This module performs a read-only limitation for specified share 00029 (or all of them if it is loaded in a [global] section) based on period 00030 definition in smb.conf. You can stack this module multiple times under 00031 different names to get multiple limit intervals. 00032 00033 The module uses get_date() function from coreutils' date utility to parse 00034 specified dates according to date(1) rules. Look into info page for date(1) 00035 to understand the syntax. 00036 00037 The module accepts one parameter: 00038 00039 readonly: period = "begin date","end date" 00040 00041 where "begin date" and "end date" are mandatory and should comply with date(1) 00042 syntax for date strings. 00043 00044 Example: 00045 00046 readonly: period = "today 14:00","today 15:00" 00047 00048 Default: 00049 00050 readonly: period = "today 0:0:0","tomorrow 0:0:0" 00051 00052 The default covers whole day thus making the share readonly 00053 00054 */ 00055 00056 #define MODULE_NAME "readonly" 00057 static int readonly_connect(vfs_handle_struct *handle, 00058 const char *service, 00059 const char *user) 00060 { 00061 const char *period_def[] = {"today 0:0:0", "tomorrow 0:0:0"}; 00062 00063 const char **period = lp_parm_string_list(SNUM(handle->conn), 00064 (handle->param ? handle->param : MODULE_NAME), 00065 "period", period_def); 00066 00067 if (period && period[0] && period[1]) { 00068 time_t current_time = time(NULL); 00069 time_t begin_period = get_date(period[0], ¤t_time); 00070 time_t end_period = get_date(period[1], ¤t_time); 00071 00072 if ((current_time >= begin_period) && (current_time <= end_period)) { 00073 handle->conn->read_only = True; 00074 } 00075 00076 return SMB_VFS_NEXT_CONNECT(handle, service, user); 00077 00078 } else { 00079 00080 return 1; 00081 00082 } 00083 } 00084 00085 00086 /* VFS operations structure */ 00087 00088 static vfs_op_tuple readonly_op_tuples[] = { 00089 /* Disk operations */ 00090 {SMB_VFS_OP(readonly_connect), SMB_VFS_OP_CONNECT, SMB_VFS_LAYER_TRANSPARENT}, 00091 {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP} 00092 }; 00093 00094 NTSTATUS vfs_readonly_init(void); 00095 NTSTATUS vfs_readonly_init(void) 00096 { 00097 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, MODULE_NAME, readonly_op_tuples); 00098 }