vfs_worm: factor out readonly check
authorBjörn Jacke <bjacke@samba.org>
Sat, 30 Dec 2023 19:45:31 +0000 (20:45 +0100)
committerVolker Lendecke <vl@samba.org>
Tue, 16 Jan 2024 14:37:31 +0000 (14:37 +0000)
Signed-off-by: Bjoern Jacke <bjacke@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
source3/modules/vfs_worm.c

index 402705e96e60e2d1c11a9859fbebf98232872147..f489c540c3a1c3e39dd2a65d5e811171a901c76d 100644 (file)
@@ -57,6 +57,31 @@ static int vfs_worm_connect(struct vfs_handle_struct *handle,
 
 }
 
+static bool is_readonly(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname)
+{
+       double age;
+       struct worm_config_data *config = NULL;
+
+       SMB_VFS_HANDLE_GET_DATA(handle,
+                               config,
+                               struct worm_config_data,
+                               return true);
+
+       if (!VALID_STAT(smb_fname->st)) {
+               goto out;
+       }
+
+       age = timespec_elapsed(&smb_fname->st.st_ex_ctime);
+
+       if (age > config->grace_period) {
+               return true;
+       }
+
+out:
+       return false;
+}
+
 static NTSTATUS vfs_worm_create_file(vfs_handle_struct *handle,
                                     struct smb_request *req,
                                     struct files_struct *dirfsp,
@@ -77,25 +102,14 @@ static NTSTATUS vfs_worm_create_file(vfs_handle_struct *handle,
                                     const struct smb2_create_blobs *in_context_blobs,
                                     struct smb2_create_blobs *out_context_blobs)
 {
-       bool readonly = false;
        const uint32_t write_access_flags =
                FILE_WRITE_DATA | FILE_APPEND_DATA |
                FILE_WRITE_ATTRIBUTES | DELETE_ACCESS |
                WRITE_DAC_ACCESS | WRITE_OWNER_ACCESS;
        NTSTATUS status;
-       struct worm_config_data *config = NULL;
+       bool readonly;
 
-       SMB_VFS_HANDLE_GET_DATA(handle, config,
-                               struct worm_config_data,
-                               return NT_STATUS_INTERNAL_ERROR);
-
-       if (VALID_STAT(smb_fname->st)) {
-               double age;
-               age = timespec_elapsed(&smb_fname->st.st_ex_ctime);
-               if (age > config->grace_period) {
-                       readonly = true;
-               }
-       }
+       readonly = is_readonly(handle, smb_fname);
 
        if (readonly && (access_mask & write_access_flags)) {
                return NT_STATUS_ACCESS_DENIED;