~zulcss/samba/server-dailies-3.4

« back to all changes in this revision

Viewing changes to source3/modules/vfs_readonly.c

  • Committer: Chuck Short
  • Date: 2010-09-28 20:38:39 UTC
  • Revision ID: zulcss@ubuntu.com-20100928203839-pgjulytsi9ue63x1
Initial version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "getdate.h"
 
25
 
 
26
/*
 
27
  This module performs a read-only limitation for specified share 
 
28
  (or all of them if it is loaded in a [global] section) based on period
 
29
  definition in smb.conf. You can stack this module multiple times under 
 
30
  different names to get multiple limit intervals.
 
31
 
 
32
  The module uses get_date() function from coreutils' date utility to parse
 
33
  specified dates according to date(1) rules. Look into info page for date(1)
 
34
  to understand the syntax.
 
35
 
 
36
  The module accepts one parameter: 
 
37
 
 
38
  readonly: period = "begin date","end date"
 
39
 
 
40
  where "begin date" and "end date" are mandatory and should comply with date(1) 
 
41
  syntax for date strings.
 
42
 
 
43
  Example:
 
44
 
 
45
  readonly: period = "today 14:00","today 15:00"
 
46
 
 
47
  Default:
 
48
 
 
49
  readonly: period = "today 0:0:0","tomorrow 0:0:0"
 
50
 
 
51
  The default covers whole day thus making the share readonly
 
52
 
 
53
 */
 
54
 
 
55
#define MODULE_NAME "readonly"
 
56
static int readonly_connect(vfs_handle_struct *handle, 
 
57
                            const char *service, 
 
58
                            const char *user)    
 
59
{
 
60
  const char *period_def[] = {"today 0:0:0", "tomorrow 0:0:0"};
 
61
 
 
62
  const char **period = lp_parm_string_list(SNUM(handle->conn),
 
63
                                             (handle->param ? handle->param : MODULE_NAME),
 
64
                                             "period", period_def); 
 
65
 
 
66
  if (period && period[0] && period[1]) {
 
67
    int i;
 
68
    time_t current_time = time(NULL);
 
69
    time_t begin_period = get_date(period[0], &current_time);
 
70
    time_t end_period   = get_date(period[1], &current_time);
 
71
 
 
72
    if ((current_time >= begin_period) && (current_time <= end_period)) {
 
73
      connection_struct *conn = handle->conn;
 
74
 
 
75
      handle->conn->read_only = True;
 
76
 
 
77
      /* Wipe out the VUID cache. */
 
78
      for (i=0; i< VUID_CACHE_SIZE; i++) {
 
79
        struct vuid_cache_entry *ent = ent = &conn->vuid_cache.array[i];
 
80
        ent->vuid = UID_FIELD_INVALID;
 
81
        TALLOC_FREE(ent->server_info);
 
82
        ent->read_only = false;
 
83
        ent->admin_user = false;
 
84
      }
 
85
      conn->vuid_cache.next_entry = 0;
 
86
    }
 
87
 
 
88
    return SMB_VFS_NEXT_CONNECT(handle, service, user);
 
89
 
 
90
  } else {
 
91
    
 
92
    return 1;
 
93
    
 
94
  }
 
95
}
 
96
 
 
97
 
 
98
/* VFS operations structure */
 
99
 
 
100
static vfs_op_tuple readonly_op_tuples[] = {
 
101
        /* Disk operations */
 
102
  {SMB_VFS_OP(readonly_connect),        SMB_VFS_OP_CONNECT, SMB_VFS_LAYER_TRANSPARENT},
 
103
  {SMB_VFS_OP(NULL),            SMB_VFS_OP_NOOP,    SMB_VFS_LAYER_NOOP}
 
104
};
 
105
 
 
106
NTSTATUS vfs_readonly_init(void);
 
107
NTSTATUS vfs_readonly_init(void)
 
108
{
 
109
  return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, MODULE_NAME, readonly_op_tuples);
 
110
}