selftest/Samba4: make use of get_cmd_env_vars() to setup all relevant env variables
[samba.git] / source3 / modules / vfs_readonly.c
index 721e59430c25508cec20f0ad0ba7a0a634ad42d2..cde8ef973ca158075b227dd5ae07984fc8b52e69 100644 (file)
@@ -6,7 +6,7 @@
 
    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
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    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.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
    This work was sponsored by Optifacio Software Services, Inc.
 */
 
 #include "includes.h"
+#include "smbd/smbd.h"
 #include "getdate.h"
 
 /*
@@ -63,36 +63,51 @@ static int readonly_connect(vfs_handle_struct *handle,
   const char **period = lp_parm_string_list(SNUM(handle->conn),
                                             (handle->param ? handle->param : MODULE_NAME),
                                             "period", period_def); 
+  int ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
+
+  if (ret < 0) {
+    return ret;
+  }
 
   if (period && period[0] && period[1]) {
+    int i;
     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)) {
+      connection_struct *conn = handle->conn;
+
       handle->conn->read_only = True;
+
+      /* Wipe out the VUID cache. */
+      for (i=0; i< VUID_CACHE_SIZE; i++) {
+        struct vuid_cache_entry *ent = &conn->vuid_cache->array[i];
+        ent->vuid = UID_FIELD_INVALID;
+        TALLOC_FREE(ent->session_info);
+        ent->read_only = false;
+        ent->share_access = 0;
+      }
+      conn->vuid_cache->next_entry = 0;
     }
 
-    return SMB_VFS_NEXT_CONNECT(handle, service, user);
+    return 0;
 
   } else {
     
-    return 1;
+    return 0;
     
   }
 }
 
 
-/* VFS operations structure */
-
-static vfs_op_tuple readonly_op_tuples[] = {
-       /* Disk operations */
-  {SMB_VFS_OP(readonly_connect),       SMB_VFS_OP_CONNECT, SMB_VFS_LAYER_TRANSPARENT},
-  {SMB_VFS_OP(NULL),                   SMB_VFS_OP_NOOP,    SMB_VFS_LAYER_NOOP}
+static struct vfs_fn_pointers vfs_readonly_fns = {
+       .connect_fn = readonly_connect
 };
 
-NTSTATUS vfs_readonly_init(void);
-NTSTATUS vfs_readonly_init(void)
+NTSTATUS vfs_readonly_init(TALLOC_CTX *);
+NTSTATUS vfs_readonly_init(TALLOC_CTX *ctx)
 {
-  return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, MODULE_NAME, readonly_op_tuples);
+  return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, MODULE_NAME,
+                         &vfs_readonly_fns);
 }