smbd: Fix a typo in a few places
[samba.git] / source3 / modules / vfs_readonly.c
index d4ddf32e3ac9f29e6990011ceb86791bfda615f1..cde8ef973ca158075b227dd5ae07984fc8b52e69 100644 (file)
@@ -21,6 +21,7 @@
 */
 
 #include "includes.h"
+#include "smbd/smbd.h"
 #include "getdate.h"
 
 /*
@@ -62,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);
 }