s3: VFS: Change SMB_VFS_LINK to use const struct smb_filename * instead of const...
[kai/samba-autobuild/.git] / source3 / modules / vfs_snapper.c
index 7161b808275c83d6b29fc18e9b1c6f495332f27e..ec0c680124ea69e67334070e8a7b00a5cadec721 100644 (file)
@@ -1461,7 +1461,7 @@ static NTSTATUS snapper_snap_create(struct vfs_handle_struct *handle,
        NTSTATUS status;
        char *conf_name;
        char *base_path;
-       char *snap_path;
+       char *snap_path = NULL;
        TALLOC_CTX *tmp_ctx;
 
        tmp_ctx = talloc_new(mem_ctx);
@@ -1508,7 +1508,7 @@ static NTSTATUS snapper_delete_snap_call(TALLOC_CTX *mem_ctx,
                                         uint32_t snap_id)
 {
        NTSTATUS status;
-       DBusMessage *req_msg;
+       DBusMessage *req_msg = NULL;
        DBusMessage *rsp_msg;
 
        status = snapper_del_snap_pack(mem_ctx, conf_name, snap_id, &req_msg);
@@ -1603,7 +1603,7 @@ static int snapper_get_shadow_copy_data(struct vfs_handle_struct *handle,
        NTSTATUS status;
        char *conf_name;
        char *base_path;
-       DBusMessage *req_msg;
+       DBusMessage *req_msg = NULL;
        DBusMessage *rsp_msg;
        uint32_t num_snaps;
        struct snapper_snap *snaps;
@@ -1729,6 +1729,7 @@ static bool snapper_gmt_strip_snapshot(TALLOC_CTX *mem_ctx,
        char *q;
        char *stripped;
        size_t rest_len, dst_len;
+       ptrdiff_t len_before_gmt;
 
        p = strstr_m(name, "@GMT-");
        if (p == NULL) {
@@ -1737,6 +1738,7 @@ static bool snapper_gmt_strip_snapshot(TALLOC_CTX *mem_ctx,
        if ((p > name) && (p[-1] != '/')) {
                goto no_snapshot;
        }
+       len_before_gmt = p - name;
        q = strptime(p, GMT_FORMAT, &tm);
        if (q == NULL) {
                goto no_snapshot;
@@ -1746,9 +1748,23 @@ static bool snapper_gmt_strip_snapshot(TALLOC_CTX *mem_ctx,
        if (timestamp == (time_t)-1) {
                goto no_snapshot;
        }
-       if ((p == name) && (q[0] == '\0')) {
+       if (q[0] == '\0') {
+               /*
+                * The name consists of only the GMT token or the GMT
+                * token is at the end of the path. XP seems to send
+                * @GMT- at the end under certain circumstances even
+                * with a path prefix.
+                */
                if (pstripped != NULL) {
-                       stripped = talloc_strdup(mem_ctx, "");
+                       if (len_before_gmt > 0) {
+                               /*
+                                * There is a slash before
+                                * the @GMT-. Remove it.
+                                */
+                               len_before_gmt -= 1;
+                       }
+                       stripped = talloc_strndup(mem_ctx, name,
+                                       len_before_gmt);
                        if (stripped == NULL) {
                                return false;
                        }
@@ -1758,12 +1774,16 @@ static bool snapper_gmt_strip_snapshot(TALLOC_CTX *mem_ctx,
                return true;
        }
        if (q[0] != '/') {
+               /*
+                * It is not a complete path component, i.e. the path
+                * component continues after the gmt-token.
+                */
                goto no_snapshot;
        }
        q += 1;
 
        rest_len = strlen(q);
-       dst_len = (p-name) + rest_len;
+       dst_len = len_before_gmt + rest_len;
 
        if (pstripped != NULL) {
                stripped = talloc_array(mem_ctx, char, dst_len+1);
@@ -1772,10 +1792,10 @@ static bool snapper_gmt_strip_snapshot(TALLOC_CTX *mem_ctx,
                        return false;
                }
                if (p > name) {
-                       memcpy(stripped, name, p-name);
+                       memcpy(stripped, name, len_before_gmt);
                }
                if (rest_len > 0) {
-                       memcpy(stripped + (p-name), q, rest_len);
+                       memcpy(stripped + len_before_gmt, q, rest_len);
                }
                stripped[dst_len] = '\0';
                *pstripped = stripped;
@@ -1795,7 +1815,7 @@ static NTSTATUS snapper_get_snap_at_time_call(TALLOC_CTX *mem_ctx,
                                              char **snap_path_out)
 {
        NTSTATUS status;
-       DBusMessage *req_msg;
+       DBusMessage *req_msg = NULL;
        DBusMessage *rsp_msg;
        uint32_t num_snaps;
        struct snapper_snap *snaps;
@@ -1822,12 +1842,13 @@ static NTSTATUS snapper_get_snap_at_time_call(TALLOC_CTX *mem_ctx,
        }
 
        if (num_snaps == 0) {
-               DEBUG(4, ("no snapshots found with time: %lu\n", snaptime));
+               DEBUG(4, ("no snapshots found with time: %lu\n",
+                         (unsigned long)snaptime));
                status = NT_STATUS_INVALID_PARAMETER;
                goto err_snap_array_free;
        } else if (num_snaps > 0) {
                DEBUG(4, ("got %u snapshots for single time %lu, using top\n",
-                         num_snaps, snaptime));
+                         num_snaps, (unsigned long)snaptime));
        }
 
        status = snapper_snap_id_to_path(mem_ctx, base_path, snaps[0].id,
@@ -1856,7 +1877,7 @@ static NTSTATUS snapper_snap_path_expand(struct connection_struct *conn,
        NTSTATUS status;
        char *conf_name;
        char *base_path;
-       char *snap_path;
+       char *snap_path = NULL;
 
        dconn = snapper_dbus_conn_create();
        if (dconn == NULL) {
@@ -1943,7 +1964,7 @@ err_out:
 }
 
 static DIR *snapper_gmt_opendir(vfs_handle_struct *handle,
-                               const char *fname,
+                               const struct smb_filename *smb_fname,
                                const char *mask,
                                uint32_t attr)
 {
@@ -1952,22 +1973,38 @@ static DIR *snapper_gmt_opendir(vfs_handle_struct *handle,
        DIR *ret;
        int saved_errno;
        char *conv;
+       struct smb_filename *conv_smb_fname = NULL;
 
-       if (!snapper_gmt_strip_snapshot(talloc_tos(), handle, fname,
-                                       &timestamp, &stripped)) {
+       if (!snapper_gmt_strip_snapshot(talloc_tos(),
+                       handle,
+                       smb_fname->base_name,
+                       &timestamp,
+                       &stripped)) {
                return NULL;
        }
        if (timestamp == 0) {
-               return SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
+               return SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask, attr);
        }
        conv = snapper_gmt_convert(talloc_tos(), handle, stripped, timestamp);
        TALLOC_FREE(stripped);
        if (conv == NULL) {
                return NULL;
        }
-       ret = SMB_VFS_NEXT_OPENDIR(handle, conv, mask, attr);
+       conv_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       conv,
+                                       NULL,
+                                       NULL,
+                                       smb_fname->flags);
+       if (conv_smb_fname == NULL) {
+               TALLOC_FREE(conv);
+               errno = ENOMEM;
+               return NULL;
+       }
+
+       ret = SMB_VFS_NEXT_OPENDIR(handle, conv_smb_fname, mask, attr);
        saved_errno = errno;
        TALLOC_FREE(conv);
+       TALLOC_FREE(conv_smb_fname);
        errno = saved_errno;
        return ret;
 }
@@ -2020,23 +2057,31 @@ static int snapper_gmt_symlink(vfs_handle_struct *handle,
 }
 
 static int snapper_gmt_link(vfs_handle_struct *handle,
-                           const char *oldname, const char *newname)
+                               const struct smb_filename *old_smb_fname,
+                               const struct smb_filename *new_smb_fname)
 {
-       time_t timestamp_old, timestamp_new;
+       time_t timestamp_old = 0;
+       time_t timestamp_new = 0;
 
-       if (!snapper_gmt_strip_snapshot(talloc_tos(), handle, oldname,
-                                       &timestamp_old, NULL)) {
+       if (!snapper_gmt_strip_snapshot(talloc_tos(),
+                               handle,
+                               old_smb_fname->base_name,
+                               &timestamp_old,
+                               NULL)) {
                return -1;
        }
-       if (!snapper_gmt_strip_snapshot(talloc_tos(), handle, newname,
-                                       &timestamp_new, NULL)) {
+       if (!snapper_gmt_strip_snapshot(talloc_tos(),
+                               handle,
+                               new_smb_fname->base_name,
+                               &timestamp_new,
+                               NULL)) {
                return -1;
        }
        if ((timestamp_old != 0) || (timestamp_new != 0)) {
                errno = EROFS;
                return -1;
        }
-       return SMB_VFS_NEXT_LINK(handle, oldname, newname);
+       return SMB_VFS_NEXT_LINK(handle, old_smb_fname, new_smb_fname);
 }
 
 static int snapper_gmt_stat(vfs_handle_struct *handle,
@@ -2200,56 +2245,92 @@ static int snapper_gmt_unlink(vfs_handle_struct *handle,
        return ret;
 }
 
-static int snapper_gmt_chmod(vfs_handle_struct *handle, const char *fname,
-                            mode_t mode)
+static int snapper_gmt_chmod(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       mode_t mode)
 {
        time_t timestamp;
-       char *stripped;
+       char *stripped = NULL;
        int ret, saved_errno;
-       char *conv;
-
-       if (!snapper_gmt_strip_snapshot(talloc_tos(), handle, fname,
-                                       &timestamp, &stripped)) {
+       char *conv = NULL;
+       struct smb_filename *conv_smb_fname = NULL;
+
+       if (!snapper_gmt_strip_snapshot(talloc_tos(),
+                               handle,
+                               smb_fname->base_name,
+                               &timestamp,
+                               &stripped)) {
                return -1;
        }
        if (timestamp == 0) {
-               return SMB_VFS_NEXT_CHMOD(handle, fname, mode);
+               TALLOC_FREE(stripped);
+               return SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
        }
        conv = snapper_gmt_convert(talloc_tos(), handle, stripped, timestamp);
        TALLOC_FREE(stripped);
        if (conv == NULL) {
                return -1;
        }
-       ret = SMB_VFS_NEXT_CHMOD(handle, conv, mode);
+       conv_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       conv,
+                                       NULL,
+                                       NULL,
+                                       smb_fname->flags);
+       if (conv_smb_fname == NULL) {
+               TALLOC_FREE(conv);
+               errno = ENOMEM;
+               return -1;
+       }
+
+       ret = SMB_VFS_NEXT_CHMOD(handle, conv_smb_fname, mode);
        saved_errno = errno;
        TALLOC_FREE(conv);
+       TALLOC_FREE(conv_smb_fname);
        errno = saved_errno;
        return ret;
 }
 
-static int snapper_gmt_chown(vfs_handle_struct *handle, const char *fname,
-                            uid_t uid, gid_t gid)
+static int snapper_gmt_chown(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       uid_t uid,
+                       gid_t gid)
 {
        time_t timestamp;
-       char *stripped;
+       char *stripped = NULL;
        int ret, saved_errno;
-       char *conv;
-
-       if (!snapper_gmt_strip_snapshot(talloc_tos(), handle, fname,
-                                       &timestamp, &stripped)) {
+       char *conv = NULL;
+       struct smb_filename *conv_smb_fname = NULL;
+
+       if (!snapper_gmt_strip_snapshot(talloc_tos(),
+                               handle,
+                               smb_fname->base_name,
+                               &timestamp,
+                               &stripped)) {
                return -1;
        }
        if (timestamp == 0) {
-               return SMB_VFS_NEXT_CHOWN(handle, fname, uid, gid);
+               TALLOC_FREE(stripped);
+               return SMB_VFS_NEXT_CHOWN(handle, smb_fname, uid, gid);
        }
        conv = snapper_gmt_convert(talloc_tos(), handle, stripped, timestamp);
        TALLOC_FREE(stripped);
        if (conv == NULL) {
                return -1;
        }
-       ret = SMB_VFS_NEXT_CHOWN(handle, conv, uid, gid);
+       conv_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       conv,
+                                       NULL,
+                                       NULL,
+                                       smb_fname->flags);
+       if (conv_smb_fname == NULL) {
+               TALLOC_FREE(conv);
+               errno = ENOMEM;
+               return -1;
+       }
+       ret = SMB_VFS_NEXT_CHOWN(handle, conv_smb_fname, uid, gid);
        saved_errno = errno;
        TALLOC_FREE(conv);
+       TALLOC_FREE(conv_smb_fname);
        errno = saved_errno;
        return ret;
 }
@@ -2344,29 +2425,42 @@ static int snapper_gmt_readlink(vfs_handle_struct *handle,
 }
 
 static int snapper_gmt_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;
-       char *stripped;
-       int ret, saved_errno;
-       char *conv;
+       time_t timestamp = (time_t)0;
+       char *stripped = NULL;
+       int ret, saved_errno = 0;
+       struct smb_filename *conv_smb_fname = NULL;
 
-       if (!snapper_gmt_strip_snapshot(talloc_tos(), handle, fname,
+       if (!snapper_gmt_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 = snapper_gmt_convert(talloc_tos(), handle, stripped, timestamp);
+       conv_smb_fname = cp_smb_filename(talloc_tos(), smb_fname);
+       if (conv_smb_fname == NULL) {
+               errno = ENOMEM;
+               return -1;
+       }
+       conv_smb_fname->base_name = snapper_gmt_convert(conv_smb_fname, handle,
+                                             stripped, timestamp);
        TALLOC_FREE(stripped);
-       if (conv == NULL) {
+       if (conv_smb_fname->base_name == NULL) {
                return -1;
        }
-       ret = SMB_VFS_NEXT_MKNOD(handle, conv, mode, dev);
-       saved_errno = errno;
-       TALLOC_FREE(conv);
-       errno = saved_errno;
+       ret = SMB_VFS_NEXT_MKNOD(handle, conv_smb_fname, mode, dev);
+       if (ret == -1) {
+               saved_errno = errno;
+       }
+       TALLOC_FREE(conv_smb_fname);
+       if (saved_errno != 0) {
+               errno = saved_errno;
+       }
        return ret;
 }
 
@@ -2436,7 +2530,8 @@ static NTSTATUS snapper_gmt_fget_nt_acl(vfs_handle_struct *handle,
        smb_fname = synthetic_smb_fname(talloc_tos(),
                                        conv,
                                        NULL,
-                                       NULL);
+                                       NULL,
+                                       fsp->fsp_name->flags);
        TALLOC_FREE(conv);
        if (smb_fname == NULL) {
                return NT_STATUS_NO_MEMORY;
@@ -2476,7 +2571,8 @@ static NTSTATUS snapper_gmt_get_nt_acl(vfs_handle_struct *handle,
        smb_fname = synthetic_smb_fname(talloc_tos(),
                                        conv,
                                        NULL,
-                                       NULL);
+                                       NULL,
+                                       fname->flags);
        TALLOC_FREE(conv);
        if (smb_fname == NULL) {
                return NT_STATUS_NO_MEMORY;
@@ -2513,7 +2609,8 @@ static int snapper_gmt_mkdir(vfs_handle_struct *handle,
        smb_fname = synthetic_smb_fname(talloc_tos(),
                                        conv,
                                        NULL,
-                                       NULL);
+                                       NULL,
+                                       fname->flags);
        TALLOC_FREE(conv);
        if (smb_fname == NULL) {
                errno = ENOMEM;
@@ -2527,14 +2624,16 @@ static int snapper_gmt_mkdir(vfs_handle_struct *handle,
        return ret;
 }
 
-static int snapper_gmt_rmdir(vfs_handle_struct *handle, const char *fname)
+static int snapper_gmt_rmdir(vfs_handle_struct *handle,
+                               const struct smb_filename *fname)
 {
        time_t timestamp;
        char *stripped;
        int ret, saved_errno;
        char *conv;
+       struct smb_filename *smb_fname = NULL;
 
-       if (!snapper_gmt_strip_snapshot(talloc_tos(), handle, fname,
+       if (!snapper_gmt_strip_snapshot(talloc_tos(), handle, fname->base_name,
                                        &timestamp, &stripped)) {
                return -1;
        }
@@ -2546,56 +2645,89 @@ static int snapper_gmt_rmdir(vfs_handle_struct *handle, const char *fname)
        if (conv == NULL) {
                return -1;
        }
-       ret = SMB_VFS_NEXT_RMDIR(handle, conv);
-       saved_errno = errno;
+       smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       conv,
+                                       NULL,
+                                       NULL,
+                                       fname->flags);
        TALLOC_FREE(conv);
+       if (smb_fname == NULL) {
+               errno = ENOMEM;
+               return -1;
+       }
+       ret = SMB_VFS_NEXT_RMDIR(handle, smb_fname);
+       saved_errno = errno;
+       TALLOC_FREE(smb_fname);
        errno = saved_errno;
        return ret;
 }
 
-static int snapper_gmt_chflags(vfs_handle_struct *handle, const char *fname,
-                              unsigned int flags)
+static int snapper_gmt_chflags(vfs_handle_struct *handle,
+                               const struct smb_filename *smb_fname,
+                               unsigned int flags)
 {
-       time_t timestamp;
-       char *stripped;
-       int ret, saved_errno;
-       char *conv;
+       time_t timestamp = 0;
+       char *stripped = NULL;
+       int ret = -1;
+       int saved_errno = 0;
+       char *conv = NULL;
+       struct smb_filename *conv_smb_fname = NULL;
 
-       if (!snapper_gmt_strip_snapshot(talloc_tos(), handle, fname,
-                                       &timestamp, &stripped)) {
+       if (!snapper_gmt_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 = snapper_gmt_convert(talloc_tos(), handle, stripped, timestamp);
        TALLOC_FREE(stripped);
        if (conv == NULL) {
                return -1;
        }
-       ret = SMB_VFS_NEXT_CHFLAGS(handle, conv, flags);
-       saved_errno = errno;
+       conv_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       conv,
+                                       NULL,
+                                       NULL,
+                                       smb_fname->flags);
        TALLOC_FREE(conv);
-       errno = saved_errno;
+       if (conv_smb_fname == NULL) {
+               errno = ENOMEM;
+               return -1;
+       }
+       ret = SMB_VFS_NEXT_CHFLAGS(handle, conv_smb_fname, flags);
+       if (ret == -1) {
+               saved_errno = errno;
+       }
+       TALLOC_FREE(conv_smb_fname);
+       if (saved_errno != 0) {
+               errno = saved_errno;
+       }
        return ret;
 }
 
 static ssize_t snapper_gmt_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;
-       char *stripped;
+       time_t timestamp = 0;
+       char *stripped = NULL;
        ssize_t ret;
-       int saved_errno;
-       char *conv;
+       int saved_errno = 0;
+       char *conv = NULL;
+       struct smb_filename *conv_smb_fname = NULL;
 
-       if (!snapper_gmt_strip_snapshot(talloc_tos(), handle, fname,
-                                       &timestamp, &stripped)) {
+       if (!snapper_gmt_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 = snapper_gmt_convert(talloc_tos(), handle, stripped, timestamp);
@@ -2603,124 +2735,215 @@ static ssize_t snapper_gmt_getxattr(vfs_handle_struct *handle,
        if (conv == NULL) {
                return -1;
        }
-       ret = SMB_VFS_NEXT_GETXATTR(handle, conv, aname, value, size);
-       saved_errno = errno;
+       conv_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       conv,
+                                       NULL,
+                                       NULL,
+                                       smb_fname->flags);
        TALLOC_FREE(conv);
-       errno = saved_errno;
+       if (conv_smb_fname == NULL) {
+               errno = ENOMEM;
+               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;
+       }
        return ret;
 }
 
 static ssize_t snapper_gmt_listxattr(struct vfs_handle_struct *handle,
-                                    const char *fname,
+                                    const struct smb_filename *smb_fname,
                                     char *list, size_t size)
 {
-       time_t timestamp;
-       char *stripped;
+       time_t timestamp = 0;
+       char *stripped = NULL;
        ssize_t ret;
-       int saved_errno;
-       char *conv;
+       int saved_errno = 0;
+       char *conv = NULL;
+       struct smb_filename *conv_smb_fname = NULL;
 
-       if (!snapper_gmt_strip_snapshot(talloc_tos(), handle, fname,
-                                       &timestamp, &stripped)) {
+       if (!snapper_gmt_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 = snapper_gmt_convert(talloc_tos(), handle, stripped, timestamp);
        TALLOC_FREE(stripped);
        if (conv == NULL) {
                return -1;
        }
-       ret = SMB_VFS_NEXT_LISTXATTR(handle, conv, list, size);
-       saved_errno = errno;
+       conv_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       conv,
+                                       NULL,
+                                       NULL,
+                                       smb_fname->flags);
        TALLOC_FREE(conv);
-       errno = saved_errno;
+       if (conv_smb_fname == NULL) {
+               errno = ENOMEM;
+               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;
+       }
        return ret;
 }
 
 static int snapper_gmt_removexattr(vfs_handle_struct *handle,
-                                  const char *fname, const char *aname)
+                               const struct smb_filename *smb_fname,
+                               const char *aname)
 {
-       time_t timestamp;
-       char *stripped;
-       int ret, saved_errno;
-       char *conv;
+       time_t timestamp = 0;
+       char *stripped = NULL;
+       ssize_t ret;
+       int saved_errno = 0;
+       char *conv = NULL;
+       struct smb_filename *conv_smb_fname = NULL;
 
-       if (!snapper_gmt_strip_snapshot(talloc_tos(), handle, fname,
-                                       &timestamp, &stripped)) {
+       if (!snapper_gmt_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 = snapper_gmt_convert(talloc_tos(), handle, stripped, timestamp);
        TALLOC_FREE(stripped);
        if (conv == NULL) {
                return -1;
        }
-       ret = SMB_VFS_NEXT_REMOVEXATTR(handle, conv, aname);
-       saved_errno = errno;
+       conv_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       conv,
+                                       NULL,
+                                       NULL,
+                                       smb_fname->flags);
        TALLOC_FREE(conv);
-       errno = saved_errno;
+       if (conv_smb_fname == NULL) {
+               errno = ENOMEM;
+               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;
+       }
        return ret;
 }
 
 static int snapper_gmt_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)
 {
-       time_t timestamp;
-       char *stripped;
+       time_t timestamp = 0;
+       char *stripped = NULL;
        ssize_t ret;
-       int saved_errno;
-       char *conv;
+       int saved_errno = 0;
+       char *conv = NULL;
+       struct smb_filename *conv_smb_fname = NULL;
 
-       if (!snapper_gmt_strip_snapshot(talloc_tos(), handle, fname,
-                                       &timestamp, &stripped)) {
+       if (!snapper_gmt_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 = snapper_gmt_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);
-       saved_errno = errno;
+       conv_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       conv,
+                                       NULL,
+                                       NULL,
+                                       smb_fname->flags);
        TALLOC_FREE(conv);
-       errno = saved_errno;
+       if (conv_smb_fname == NULL) {
+               errno = ENOMEM;
+               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;
+       }
        return ret;
 }
 
 static int snapper_gmt_chmod_acl(vfs_handle_struct *handle,
-                                const char *fname, mode_t mode)
+                       const struct smb_filename *smb_fname,
+                       mode_t mode)
 {
        time_t timestamp;
        char *stripped;
        ssize_t ret;
        int saved_errno;
        char *conv;
+       struct smb_filename *conv_smb_fname = NULL;
 
-       if (!snapper_gmt_strip_snapshot(talloc_tos(), handle, fname,
-                                       &timestamp, &stripped)) {
+       if (!snapper_gmt_strip_snapshot(talloc_tos(),
+                               handle,
+                               smb_fname->base_name,
+                               &timestamp,
+                               &stripped)) {
                return -1;
        }
        if (timestamp == 0) {
-               return SMB_VFS_NEXT_CHMOD_ACL(handle, fname, mode);
+               return SMB_VFS_NEXT_CHMOD_ACL(handle, smb_fname, mode);
        }
        conv = snapper_gmt_convert(talloc_tos(), handle, stripped, timestamp);
        TALLOC_FREE(stripped);
        if (conv == NULL) {
                return -1;
        }
-       ret = SMB_VFS_NEXT_CHMOD_ACL(handle, conv, mode);
+       conv_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       conv,
+                                       NULL,
+                                       NULL,
+                                       smb_fname->flags);
+       if (conv_smb_fname == NULL) {
+               TALLOC_FREE(conv);
+               errno = ENOMEM;
+               return -1;
+       }
+       ret = SMB_VFS_NEXT_CHMOD_ACL(handle, conv_smb_fname, mode);
        saved_errno = errno;
        TALLOC_FREE(conv);
+       TALLOC_FREE(conv_smb_fname);
        errno = saved_errno;
        return ret;
 }
@@ -2767,55 +2990,75 @@ static int snapper_gmt_get_real_filename(struct vfs_handle_struct *handle,
 }
 
 static uint64_t snapper_gmt_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;
-       char *stripped;
-       ssize_t ret;
-       int saved_errno;
-       char *conv;
+       time_t timestamp = 0;
+       char *stripped = NULL;
+       uint64_t ret;
+       int saved_errno = 0;
+       char *conv = NULL;
+       struct smb_filename *conv_smb_fname = NULL;
 
-       if (!snapper_gmt_strip_snapshot(talloc_tos(), handle, path,
-                                       &timestamp, &stripped)) {
-               return -1;
+       if (!snapper_gmt_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 = snapper_gmt_convert(talloc_tos(), handle, stripped, timestamp);
        TALLOC_FREE(stripped);
        if (conv == NULL) {
-               return -1;
+               return (uint64_t)-1;
+       }
+       conv_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       conv,
+                                       NULL,
+                                       NULL,
+                                       smb_fname->flags);
+       if (conv_smb_fname == NULL) {
+               TALLOC_FREE(conv);
+               errno = ENOMEM;
+               return (uint64_t)-1;
        }
 
-       ret = SMB_VFS_NEXT_DISK_FREE(handle, conv, bsize, dfree, dsize);
-
-       saved_errno = errno;
-       TALLOC_FREE(conv);
-       errno = saved_errno;
+       ret = SMB_VFS_NEXT_DISK_FREE(handle, conv_smb_fname,
+                               bsize, dfree, dsize);
 
+       if (ret == (uint64_t)-1) {
+               saved_errno = errno;
+       }
+       TALLOC_FREE(conv_smb_fname);
+       if (saved_errno != 0) {
+               errno = saved_errno;
+       }
        return ret;
 }
 
-static int snapper_gmt_get_quota(vfs_handle_struct *handle, const char *path,
-                                enum SMB_QUOTA_TYPE qtype, unid_t id,
-                                SMB_DISK_QUOTA *dq)
+static int snapper_gmt_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;
-       char *stripped;
+       time_t timestamp = 0;
+       char *stripped = NULL;
        int ret;
-       int saved_errno;
-       char *conv;
+       int saved_errno = 0;
+       char *conv = NULL;
+       struct smb_filename *conv_smb_fname = NULL;
 
-       if (!snapper_gmt_strip_snapshot(talloc_tos(), handle, path, &timestamp,
-                                       &stripped)) {
+       if (!snapper_gmt_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 = snapper_gmt_convert(talloc_tos(), handle, stripped, timestamp);
@@ -2823,13 +3066,26 @@ static int snapper_gmt_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);
-
-       saved_errno = errno;
+       conv_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       conv,
+                                       NULL,
+                                       NULL,
+                                       smb_fname->flags);
        TALLOC_FREE(conv);
-       errno = saved_errno;
+       if (conv_smb_fname == NULL) {
+               errno = ENOMEM;
+               return -1;
+       }
+
+       ret = SMB_VFS_NEXT_GET_QUOTA(handle, conv_smb_fname, qtype, id, dq);
 
+       if (ret == -1) {
+               saved_errno = errno;
+       }
+       TALLOC_FREE(conv_smb_fname);
+       if (saved_errno != 0) {
+               errno = saved_errno;
+       }
        return ret;
 }
 
@@ -2870,8 +3126,8 @@ static struct vfs_fn_pointers snapper_fns = {
        .get_real_filename_fn = snapper_gmt_get_real_filename,
 };
 
-NTSTATUS vfs_snapper_init(void);
-NTSTATUS vfs_snapper_init(void)
+NTSTATUS vfs_snapper_init(TALLOC_CTX *);
+NTSTATUS vfs_snapper_init(TALLOC_CTX *ctx)
 {
        return smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
                                "snapper", &snapper_fns);