Revert "s3: vfs: add user_vfs_evg to connection_struct"
[samba.git] / source3 / modules / vfs_readonly.c
index f1914b68414cf204746229ed100c38609d311ea1..e7e12747a2225dab74794a67583d6039c4607b9a 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"
 
 /*
@@ -55,7 +55,6 @@
 
 #define MODULE_NAME "readonly"
 static int readonly_connect(vfs_handle_struct *handle, 
-                           connection_struct *conn, 
                            const char *service, 
                            const char *user)    
 {
@@ -64,35 +63,52 @@ 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)) {
-      conn->read_only = True;
+      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->user_ev_ctx);
+        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, conn, 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_OPAQUE},
-  {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 init_module(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);
 }