LCOV - code coverage report
Current view: top level - source3/modules - vfs_worm.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 4 21 19.0 %
Date: 2021-09-23 10:06:22 Functions: 1 2 50.0 %

          Line data    Source code
       1             : /*
       2             :  * VFS module to disallow writes for older files
       3             :  *
       4             :  * Copyright (C) 2013, Volker Lendecke
       5             :  *
       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.
      10             :  *
      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.
      15             :  *
      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/>.
      18             :  */
      19             : 
      20             : #include "includes.h"
      21             : #include "smbd/smbd.h"
      22             : #include "system/filesys.h"
      23             : #include "libcli/security/security.h"
      24             : 
      25           0 : static NTSTATUS vfs_worm_create_file(vfs_handle_struct *handle,
      26             :                                      struct smb_request *req,
      27             :                                      struct smb_filename *smb_fname,
      28             :                                      uint32_t access_mask,
      29             :                                      uint32_t share_access,
      30             :                                      uint32_t create_disposition,
      31             :                                      uint32_t create_options,
      32             :                                      uint32_t file_attributes,
      33             :                                      uint32_t oplock_request,
      34             :                                      const struct smb2_lease *lease,
      35             :                                      uint64_t allocation_size,
      36             :                                      uint32_t private_flags,
      37             :                                      struct security_descriptor *sd,
      38             :                                      struct ea_list *ea_list,
      39             :                                      files_struct **result,
      40             :                                      int *pinfo,
      41             :                                      const struct smb2_create_blobs *in_context_blobs,
      42             :                                      struct smb2_create_blobs *out_context_blobs)
      43             : {
      44           0 :         bool readonly = false;
      45           0 :         const uint32_t write_access_flags =
      46             :                 FILE_WRITE_DATA | FILE_APPEND_DATA |
      47             :                 FILE_WRITE_ATTRIBUTES | DELETE_ACCESS |
      48             :                 WRITE_DAC_ACCESS | WRITE_OWNER_ACCESS;
      49             :         NTSTATUS status;
      50             : 
      51           0 :         if (VALID_STAT(smb_fname->st)) {
      52             :                 double age;
      53           0 :                 age = timespec_elapsed(&smb_fname->st.st_ex_ctime);
      54           0 :                 if (age > lp_parm_int(SNUM(handle->conn), "worm",
      55             :                                       "grace_period", 3600)) {
      56           0 :                         readonly = true;
      57             :                 }
      58             :         }
      59             : 
      60           0 :         if (readonly && (access_mask & write_access_flags)) {
      61           0 :                 return NT_STATUS_ACCESS_DENIED;
      62             :         }
      63             : 
      64           0 :         status = SMB_VFS_NEXT_CREATE_FILE(
      65             :                 handle, req, smb_fname, access_mask,
      66             :                 share_access, create_disposition, create_options,
      67             :                 file_attributes, oplock_request, lease, allocation_size,
      68             :                 private_flags, sd, ea_list, result, pinfo,
      69             :                 in_context_blobs, out_context_blobs);
      70           0 :         if (!NT_STATUS_IS_OK(status)) {
      71           0 :                 return status;
      72             :         }
      73             : 
      74             :         /*
      75             :          * Access via MAXIMUM_ALLOWED_ACCESS?
      76             :          */
      77           0 :         if (readonly && ((*result)->access_mask & write_access_flags)) {
      78           0 :                 close_file(req, *result, NORMAL_CLOSE);
      79           0 :                 return NT_STATUS_ACCESS_DENIED;
      80             :         }
      81           0 :         return NT_STATUS_OK;
      82             : }
      83             : 
      84             : static struct vfs_fn_pointers vfs_worm_fns = {
      85             :         .create_file_fn = vfs_worm_create_file,
      86             : };
      87             : 
      88             : static_decl_vfs;
      89          20 : NTSTATUS vfs_worm_init(TALLOC_CTX *ctx)
      90             : {
      91             :         NTSTATUS ret;
      92             : 
      93          20 :         ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "worm",
      94             :                                &vfs_worm_fns);
      95          20 :         if (!NT_STATUS_IS_OK(ret)) {
      96           0 :                 return ret;
      97             :         }
      98             : 
      99          20 :         return ret;
     100             : }

Generated by: LCOV version 1.13