vfs_snapper: implement SMB_VFS_OPENAT()
authorRalph Boehme <slow@samba.org>
Wed, 20 May 2020 20:02:48 +0000 (22:02 +0200)
committerJeremy Allison <jra@samba.org>
Thu, 21 May 2020 20:38:33 +0000 (20:38 +0000)
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/modules/vfs_snapper.c

index 9108422df49603103fef0d2ae61a282412888c32..20d2dd6d3698349270077ccd60b083fd54b0309b 100644 (file)
@@ -2110,6 +2110,60 @@ static int snapper_gmt_open(vfs_handle_struct *handle,
        return ret;
 }
 
+static int snapper_gmt_openat(struct vfs_handle_struct *handle,
+                             const struct files_struct *dirfsp,
+                             const struct smb_filename *smb_fname_in,
+                             struct files_struct *fsp,
+                             int flags,
+                             mode_t mode)
+{
+       struct smb_filename *smb_fname = NULL;
+       time_t timestamp;
+       char *stripped = NULL;
+       int ret;
+       int saved_errno = 0;
+
+       if (!snapper_gmt_strip_snapshot(talloc_tos(), handle,
+                                       smb_fname_in,
+                                       &timestamp, &stripped)) {
+               return -1;
+       }
+       if (timestamp == 0) {
+               return SMB_VFS_NEXT_OPENAT(handle,
+                                          dirfsp,
+                                          smb_fname_in,
+                                          fsp,
+                                          flags,
+                                          mode);
+       }
+
+       smb_fname = cp_smb_filename(talloc_tos(), smb_fname_in);
+       if (smb_fname == NULL) {
+               TALLOC_FREE(stripped);
+               return -1;
+       }
+
+       smb_fname->base_name = snapper_gmt_convert(smb_fname, handle,
+                                                  stripped, timestamp);
+       TALLOC_FREE(stripped);
+
+       if (smb_fname->base_name == NULL) {
+               TALLOC_FREE(smb_fname);
+               errno = ENOMEM;
+               return -1;
+       }
+
+       ret = SMB_VFS_NEXT_OPENAT(handle, dirfsp, smb_fname, fsp, flags, mode);
+       if (ret == -1) {
+               saved_errno = errno;
+       }
+       TALLOC_FREE(smb_fname);
+       if (saved_errno != 0) {
+               errno = saved_errno;
+       }
+       return ret;
+}
+
 static int snapper_gmt_unlinkat(vfs_handle_struct *handle,
                        struct files_struct *dirfsp,
                        const struct smb_filename *smb_fname,
@@ -2764,6 +2818,7 @@ static struct vfs_fn_pointers snapper_fns = {
        .stat_fn = snapper_gmt_stat,
        .lstat_fn = snapper_gmt_lstat,
        .open_fn = snapper_gmt_open,
+       .openat_fn = snapper_gmt_openat,
        .unlinkat_fn = snapper_gmt_unlinkat,
        .chmod_fn = snapper_gmt_chmod,
        .chdir_fn = snapper_gmt_chdir,