lib/param: Allow enum values to also be white-space insentive in comparison
[Samba.git] / source3 / modules / vfs_worm.c
blob3097419f309ebe85a453511f80e2ba6e84754767
1 /*
2 * VFS module to disallow writes for older files
4 * Copyright (C) 2013, Volker Lendecke
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "smbd/smbd.h"
22 #include "system/filesys.h"
23 #include "libcli/security/security.h"
25 static NTSTATUS vfs_worm_create_file(vfs_handle_struct *handle,
26 struct smb_request *req,
27 uint16_t root_dir_fid,
28 struct smb_filename *smb_fname,
29 uint32_t access_mask,
30 uint32_t share_access,
31 uint32_t create_disposition,
32 uint32_t create_options,
33 uint32_t file_attributes,
34 uint32_t oplock_request,
35 struct smb2_lease *lease,
36 uint64_t allocation_size,
37 uint32_t private_flags,
38 struct security_descriptor *sd,
39 struct ea_list *ea_list,
40 files_struct **result,
41 int *pinfo)
43 bool readonly = false;
44 const uint32_t write_access_flags =
45 FILE_WRITE_DATA | FILE_APPEND_DATA |
46 FILE_WRITE_ATTRIBUTES | DELETE_ACCESS |
47 WRITE_DAC_ACCESS | WRITE_OWNER_ACCESS;
48 NTSTATUS status;
50 if (VALID_STAT(smb_fname->st)) {
51 double age;
52 age = timespec_elapsed(&smb_fname->st.st_ex_ctime);
53 if (age > lp_parm_int(SNUM(handle->conn), "worm",
54 "grace_period", 3600)) {
55 readonly = true;
59 if (readonly && (access_mask & write_access_flags)) {
60 return NT_STATUS_ACCESS_DENIED;
63 status = SMB_VFS_NEXT_CREATE_FILE(
64 handle, req, root_dir_fid, smb_fname, access_mask,
65 share_access, create_disposition, create_options,
66 file_attributes, oplock_request, lease, allocation_size,
67 private_flags, sd, ea_list, result, pinfo);
68 if (!NT_STATUS_IS_OK(status)) {
69 return status;
73 * Access via MAXIMUM_ALLOWED_ACCESS?
75 if (readonly && ((*result)->access_mask & write_access_flags)) {
76 close_file(req, *result, NORMAL_CLOSE);
77 return NT_STATUS_ACCESS_DENIED;
79 return NT_STATUS_OK;
82 static struct vfs_fn_pointers vfs_worm_fns = {
83 .create_file_fn = vfs_worm_create_file,
86 NTSTATUS vfs_worm_init(void);
87 NTSTATUS vfs_worm_init(void)
89 NTSTATUS ret;
91 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "worm",
92 &vfs_worm_fns);
93 if (!NT_STATUS_IS_OK(ret)) {
94 return ret;
97 return ret;