s3: VFS: Change SMB_VFS_GET_QUOTA to use const struct smb_filename * instead of const...
[bbaumbach/samba-autobuild/.git] / source3 / modules / vfs_shadow_copy2.c
index 7cacac81c1c970b218ea917456b754e09703b197..faacc4591463a04d0b0770fa5836e1ef2da8d610 100644 (file)
@@ -1656,24 +1656,33 @@ static int shadow_copy2_readlink(vfs_handle_struct *handle,
 }
 
 static int shadow_copy2_mknod(vfs_handle_struct *handle,
-                             const char *fname, mode_t mode, SMB_DEV_T dev)
+                               const struct smb_filename *smb_fname,
+                               mode_t mode,
+                               SMB_DEV_T dev)
 {
        time_t timestamp = 0;
        char *stripped = NULL;
        int saved_errno = 0;
        int ret;
-       char *conv;
+       struct smb_filename *conv = NULL;
 
-       if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
+       if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
+                                        smb_fname->base_name,
                                         &timestamp, &stripped)) {
                return -1;
        }
        if (timestamp == 0) {
-               return SMB_VFS_NEXT_MKNOD(handle, fname, mode, dev);
+               return SMB_VFS_NEXT_MKNOD(handle, smb_fname, mode, dev);
        }
-       conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
-       TALLOC_FREE(stripped);
+       conv = cp_smb_filename(talloc_tos(), smb_fname);
        if (conv == NULL) {
+               errno = ENOMEM;
+               return -1;
+       }
+       conv->base_name = shadow_copy2_convert(
+               conv, handle, stripped, timestamp);
+       TALLOC_FREE(stripped);
+       if (conv->base_name == NULL) {
                return -1;
        }
        ret = SMB_VFS_NEXT_MKNOD(handle, conv, mode, dev);
@@ -2300,7 +2309,8 @@ static int shadow_copy2_rmdir(vfs_handle_struct *handle,
        return ret;
 }
 
-static int shadow_copy2_chflags(vfs_handle_struct *handle, const char *fname,
+static int shadow_copy2_chflags(vfs_handle_struct *handle,
+                               const struct smb_filename *smb_fname,
                                unsigned int flags)
 {
        time_t timestamp = 0;
@@ -2308,23 +2318,37 @@ static int shadow_copy2_chflags(vfs_handle_struct *handle, const char *fname,
        int saved_errno = 0;
        int ret;
        char *conv;
+       struct smb_filename *conv_smb_fname = NULL;
 
-       if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
-                                        &timestamp, &stripped)) {
+       if (!shadow_copy2_strip_snapshot(talloc_tos(),
+                                       handle,
+                                       smb_fname->base_name,
+                                       &timestamp,
+                                       &stripped)) {
                return -1;
        }
        if (timestamp == 0) {
-               return SMB_VFS_NEXT_CHFLAGS(handle, fname, flags);
+               return SMB_VFS_NEXT_CHFLAGS(handle, smb_fname, flags);
        }
        conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
        TALLOC_FREE(stripped);
        if (conv == NULL) {
                return -1;
        }
-       ret = SMB_VFS_NEXT_CHFLAGS(handle, conv, flags);
+       conv_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       conv,
+                                       NULL,
+                                       NULL,
+                                       smb_fname->flags);
+       if (conv_smb_fname == NULL) {
+               TALLOC_FREE(conv);
+               return -1;
+       }
+       ret = SMB_VFS_NEXT_CHFLAGS(handle, smb_fname, flags);
        if (ret == -1) {
                saved_errno = errno;
        }
+       TALLOC_FREE(conv_smb_fname);
        TALLOC_FREE(conv);
        if (saved_errno != 0) {
                errno = saved_errno;
@@ -2333,21 +2357,27 @@ static int shadow_copy2_chflags(vfs_handle_struct *handle, const char *fname,
 }
 
 static ssize_t shadow_copy2_getxattr(vfs_handle_struct *handle,
-                                    const char *fname, const char *aname,
-                                    void *value, size_t size)
+                               const struct smb_filename *smb_fname,
+                               const char *aname,
+                               void *value,
+                               size_t size)
 {
        time_t timestamp = 0;
        char *stripped = NULL;
        ssize_t ret;
        int saved_errno = 0;
        char *conv;
+       struct smb_filename *conv_smb_fname = NULL;
 
-       if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
-                                        &timestamp, &stripped)) {
+       if (!shadow_copy2_strip_snapshot(talloc_tos(),
+                               handle,
+                               smb_fname->base_name,
+                               &timestamp,
+                               &stripped)) {
                return -1;
        }
        if (timestamp == 0) {
-               return SMB_VFS_NEXT_GETXATTR(handle, fname, aname, value,
+               return SMB_VFS_NEXT_GETXATTR(handle, smb_fname, aname, value,
                                             size);
        }
        conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
@@ -2355,10 +2385,22 @@ static ssize_t shadow_copy2_getxattr(vfs_handle_struct *handle,
        if (conv == NULL) {
                return -1;
        }
-       ret = SMB_VFS_NEXT_GETXATTR(handle, conv, aname, value, size);
+
+       conv_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       conv,
+                                       NULL,
+                                       NULL,
+                                       smb_fname->flags);
+       if (conv_smb_fname == NULL) {
+               TALLOC_FREE(conv);
+               return -1;
+       }
+
+       ret = SMB_VFS_NEXT_GETXATTR(handle, conv_smb_fname, aname, value, size);
        if (ret == -1) {
                saved_errno = errno;
        }
+       TALLOC_FREE(conv_smb_fname);
        TALLOC_FREE(conv);
        if (saved_errno != 0) {
                errno = saved_errno;
@@ -2367,7 +2409,7 @@ static ssize_t shadow_copy2_getxattr(vfs_handle_struct *handle,
 }
 
 static ssize_t shadow_copy2_listxattr(struct vfs_handle_struct *handle,
-                                     const char *fname,
+                                     const struct smb_filename *smb_fname,
                                      char *list, size_t size)
 {
        time_t timestamp = 0;
@@ -2375,23 +2417,37 @@ static ssize_t shadow_copy2_listxattr(struct vfs_handle_struct *handle,
        ssize_t ret;
        int saved_errno = 0;
        char *conv;
+       struct smb_filename *conv_smb_fname = NULL;
 
-       if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
-                                        &timestamp, &stripped)) {
+       if (!shadow_copy2_strip_snapshot(talloc_tos(),
+                               handle,
+                               smb_fname->base_name,
+                               &timestamp,
+                               &stripped)) {
                return -1;
        }
        if (timestamp == 0) {
-               return SMB_VFS_NEXT_LISTXATTR(handle, fname, list, size);
+               return SMB_VFS_NEXT_LISTXATTR(handle, smb_fname, list, size);
        }
        conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
        TALLOC_FREE(stripped);
        if (conv == NULL) {
                return -1;
        }
-       ret = SMB_VFS_NEXT_LISTXATTR(handle, conv, list, size);
+       conv_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       conv,
+                                       NULL,
+                                       NULL,
+                                       smb_fname->flags);
+       if (conv_smb_fname == NULL) {
+               TALLOC_FREE(conv);
+               return -1;
+       }
+       ret = SMB_VFS_NEXT_LISTXATTR(handle, conv_smb_fname, list, size);
        if (ret == -1) {
                saved_errno = errno;
        }
+       TALLOC_FREE(conv_smb_fname);
        TALLOC_FREE(conv);
        if (saved_errno != 0) {
                errno = saved_errno;
@@ -2400,30 +2456,45 @@ static ssize_t shadow_copy2_listxattr(struct vfs_handle_struct *handle,
 }
 
 static int shadow_copy2_removexattr(vfs_handle_struct *handle,
-                                   const char *fname, const char *aname)
+                               const struct smb_filename *smb_fname,
+                               const char *aname)
 {
        time_t timestamp = 0;
        char *stripped = NULL;
        int saved_errno = 0;
        int ret;
        char *conv;
+       struct smb_filename *conv_smb_fname = NULL;
 
-       if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
-                                        &timestamp, &stripped)) {
+       if (!shadow_copy2_strip_snapshot(talloc_tos(),
+                               handle,
+                               smb_fname->base_name,
+                               &timestamp,
+                               &stripped)) {
                return -1;
        }
        if (timestamp == 0) {
-               return SMB_VFS_NEXT_REMOVEXATTR(handle, fname, aname);
+               return SMB_VFS_NEXT_REMOVEXATTR(handle, smb_fname, aname);
        }
        conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
        TALLOC_FREE(stripped);
        if (conv == NULL) {
                return -1;
        }
-       ret = SMB_VFS_NEXT_REMOVEXATTR(handle, conv, aname);
+       conv_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       conv,
+                                       NULL,
+                                       NULL,
+                                       smb_fname->flags);
+       if (conv_smb_fname == NULL) {
+               TALLOC_FREE(conv);
+               return -1;
+       }
+       ret = SMB_VFS_NEXT_REMOVEXATTR(handle, conv_smb_fname, aname);
        if (ret == -1) {
                saved_errno = errno;
        }
+       TALLOC_FREE(conv_smb_fname);
        TALLOC_FREE(conv);
        if (saved_errno != 0) {
                errno = saved_errno;
@@ -2432,7 +2503,7 @@ static int shadow_copy2_removexattr(vfs_handle_struct *handle,
 }
 
 static int shadow_copy2_setxattr(struct vfs_handle_struct *handle,
-                                const char *fname,
+                                const struct smb_filename *smb_fname,
                                 const char *aname, const void *value,
                                 size_t size, int flags)
 {
@@ -2441,24 +2512,39 @@ static int shadow_copy2_setxattr(struct vfs_handle_struct *handle,
        ssize_t ret;
        int saved_errno = 0;
        char *conv;
+       struct smb_filename *conv_smb_fname = NULL;
 
-       if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
-                                        &timestamp, &stripped)) {
+       if (!shadow_copy2_strip_snapshot(talloc_tos(),
+                               handle,
+                               smb_fname->base_name,
+                               &timestamp,
+                               &stripped)) {
                return -1;
        }
        if (timestamp == 0) {
-               return SMB_VFS_NEXT_SETXATTR(handle, fname, aname, value, size,
-                                            flags);
+               return SMB_VFS_NEXT_SETXATTR(handle, smb_fname,
+                                       aname, value, size, flags);
        }
        conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
        TALLOC_FREE(stripped);
        if (conv == NULL) {
                return -1;
        }
-       ret = SMB_VFS_NEXT_SETXATTR(handle, conv, aname, value, size, flags);
+       conv_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       conv,
+                                       NULL,
+                                       NULL,
+                                       smb_fname->flags);
+       if (conv_smb_fname == NULL) {
+               TALLOC_FREE(conv);
+               return -1;
+       }
+       ret = SMB_VFS_NEXT_SETXATTR(handle, conv_smb_fname,
+                               aname, value, size, flags);
        if (ret == -1) {
                saved_errno = errno;
        }
+       TALLOC_FREE(conv_smb_fname);
        TALLOC_FREE(conv);
        if (saved_errno != 0) {
                errno = saved_errno;
@@ -2656,59 +2742,78 @@ done:
 }
 
 static uint64_t shadow_copy2_disk_free(vfs_handle_struct *handle,
-                                      const char *path, uint64_t *bsize,
-                                      uint64_t *dfree, uint64_t *dsize)
+                               const struct smb_filename *smb_fname,
+                               uint64_t *bsize,
+                               uint64_t *dfree,
+                               uint64_t *dsize)
 {
        time_t timestamp = 0;
        char *stripped = NULL;
-       ssize_t ret;
        int saved_errno = 0;
-       char *conv;
+       char *conv = NULL;
+       struct smb_filename *conv_smb_fname = NULL;
+       uint64_t ret = (uint64_t)-1;
 
-       if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, path,
-                                        &timestamp, &stripped)) {
-               return -1;
+       if (!shadow_copy2_strip_snapshot(talloc_tos(),
+                               handle,
+                               smb_fname->base_name,
+                               &timestamp,
+                               &stripped)) {
+               return (uint64_t)-1;
        }
        if (timestamp == 0) {
-               return SMB_VFS_NEXT_DISK_FREE(handle, path,
+               return SMB_VFS_NEXT_DISK_FREE(handle, smb_fname,
                                              bsize, dfree, dsize);
        }
-
        conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
        TALLOC_FREE(stripped);
        if (conv == NULL) {
-               return -1;
+               return (uint64_t)-1;
        }
-
-       ret = SMB_VFS_NEXT_DISK_FREE(handle, conv, bsize, dfree, dsize);
-
-       if (ret == -1) {
+       conv_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       conv,
+                                       NULL,
+                                       NULL,
+                                       smb_fname->flags);
+       if (conv_smb_fname == NULL) {
+               TALLOC_FREE(conv);
+               return (uint64_t)-1;
+       }
+       ret = SMB_VFS_NEXT_DISK_FREE(handle, conv_smb_fname,
+                               bsize, dfree, dsize);
+       if (ret == (uint64_t)-1) {
                saved_errno = errno;
        }
        TALLOC_FREE(conv);
+       TALLOC_FREE(conv_smb_fname);
        if (saved_errno != 0) {
                errno = saved_errno;
        }
-
        return ret;
 }
 
-static int shadow_copy2_get_quota(vfs_handle_struct *handle, const char *path,
-                                 enum SMB_QUOTA_TYPE qtype, unid_t id,
-                                 SMB_DISK_QUOTA *dq)
+static int shadow_copy2_get_quota(vfs_handle_struct *handle,
+                               const struct smb_filename *smb_fname,
+                               enum SMB_QUOTA_TYPE qtype,
+                               unid_t id,
+                               SMB_DISK_QUOTA *dq)
 {
        time_t timestamp = 0;
        char *stripped = NULL;
        int ret;
        int saved_errno = 0;
        char *conv;
+       struct smb_filename *conv_smb_fname = NULL;
 
-       if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, path, &timestamp,
-                                        &stripped)) {
+       if (!shadow_copy2_strip_snapshot(talloc_tos(),
+                               handle,
+                               smb_fname->base_name,
+                               &timestamp,
+                               &stripped)) {
                return -1;
        }
        if (timestamp == 0) {
-               return SMB_VFS_NEXT_GET_QUOTA(handle, path, qtype, id, dq);
+               return SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname, qtype, id, dq);
        }
 
        conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
@@ -2716,13 +2821,22 @@ static int shadow_copy2_get_quota(vfs_handle_struct *handle, const char *path,
        if (conv == NULL) {
                return -1;
        }
-
-       ret = SMB_VFS_NEXT_GET_QUOTA(handle, conv, qtype, id, dq);
+       conv_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       conv,
+                                       NULL,
+                                       NULL,
+                                       smb_fname->flags);
+       if (conv_smb_fname == NULL) {
+               TALLOC_FREE(conv);
+               return -1;
+       }
+       ret = SMB_VFS_NEXT_GET_QUOTA(handle, conv_smb_fname, qtype, id, dq);
 
        if (ret == -1) {
                saved_errno = errno;
        }
        TALLOC_FREE(conv);
+       TALLOC_FREE(conv_smb_fname);
        if (saved_errno != 0) {
                errno = saved_errno;
        }
@@ -3104,8 +3218,8 @@ static struct vfs_fn_pointers vfs_shadow_copy2_fns = {
        .connectpath_fn = shadow_copy2_connectpath,
 };
 
-NTSTATUS vfs_shadow_copy2_init(void);
-NTSTATUS vfs_shadow_copy2_init(void)
+NTSTATUS vfs_shadow_copy2_init(TALLOC_CTX *);
+NTSTATUS vfs_shadow_copy2_init(TALLOC_CTX *ctx)
 {
        return smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
                                "shadow_copy2", &vfs_shadow_copy2_fns);