VFS: Modify opendir to take a const struct smb_filename * instead of const char *
authorJeremy Allison <jra@samba.org>
Fri, 26 Feb 2016 22:53:12 +0000 (14:53 -0800)
committerRalph Boehme <slow@samba.org>
Tue, 1 Mar 2016 14:25:22 +0000 (15:25 +0100)
Preparing to reduce use of lp_posix_pathnames().

Uses the same techniques as commit 616d068f0cebb8e50a855b6e30f36fccb7f5a3c8
(synthetic_smb_fname()) to cope with modules that
modify the incoming pathname.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
23 files changed:
examples/VFS/skel_opaque.c
examples/VFS/skel_transparent.c
source3/include/vfs.h
source3/include/vfs_macros.h
source3/modules/vfs_audit.c
source3/modules/vfs_cap.c
source3/modules/vfs_catia.c
source3/modules/vfs_default.c
source3/modules/vfs_dirsort.c
source3/modules/vfs_extd_audit.c
source3/modules/vfs_full_audit.c
source3/modules/vfs_media_harmony.c
source3/modules/vfs_netatalk.c
source3/modules/vfs_shadow_copy.c
source3/modules/vfs_shadow_copy2.c
source3/modules/vfs_snapper.c
source3/modules/vfs_streams_depot.c
source3/modules/vfs_time_audit.c
source3/modules/vfs_unityed_media.c
source3/smbd/dir.c
source3/smbd/msdfs.c
source3/smbd/vfs.c
source3/torture/cmd_vfs.c

index 8961627e41f0b72a2398674d0aeb59d8ef7f1b6a..ae165a6f5ab37724bf613d5816ce4f395052ef1a 100644 (file)
@@ -97,8 +97,10 @@ static NTSTATUS skel_get_dfs_referrals(struct vfs_handle_struct *handle,
        return NT_STATUS_NOT_IMPLEMENTED;
 }
 
-static DIR *skel_opendir(vfs_handle_struct *handle, const char *fname,
-                        const char *mask, uint32_t attr)
+static DIR *skel_opendir(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       const char *mask,
+                       uint32_t attr)
 {
        return NULL;
 }
index ac82432df89853e945563006c0c00833dedfb098..549d7d8d845378f008f6c242b9f3aa85288ff824 100644 (file)
@@ -95,10 +95,12 @@ static NTSTATUS skel_get_dfs_referrals(struct vfs_handle_struct *handle,
        return SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
 }
 
-static DIR *skel_opendir(vfs_handle_struct *handle, const char *fname,
-                        const char *mask, uint32_t attr)
+static DIR *skel_opendir(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       const char *mask,
+                       uint32_t attr)
 {
-       return SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
+       return SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask, attr);
 }
 
 static NTSTATUS skel_snap_check_path(struct vfs_handle_struct *handle,
index b291206af1cbaeaa7dff747f410e1f4cca87f1f7..2f34c22c3aebec99c9ea4dec790f49a5f8cb599c 100644 (file)
                const struct smb_filename * */
 /* Version 35 - Change rmdir from const char *, to
                const struct smb_filename * */
+/* Version 35 - Change opendir from const char *, to
+               const struct smb_filename * */
 
 #define SMB_VFS_INTERFACE_VERSION 35
 
@@ -550,7 +552,10 @@ struct vfs_fn_pointers {
 
        /* Directory operations */
 
-       DIR *(*opendir_fn)(struct vfs_handle_struct *handle, const char *fname, const char *mask, uint32_t attributes);
+       DIR *(*opendir_fn)(struct vfs_handle_struct *handle,
+                                       const struct smb_filename *smb_fname,
+                                       const char *mask,
+                                       uint32_t attributes);
        DIR *(*fdopendir_fn)(struct vfs_handle_struct *handle, files_struct *fsp, const char *mask, uint32_t attributes);
        struct dirent *(*readdir_fn)(struct vfs_handle_struct *handle,
                                         DIR *dirp,
@@ -963,8 +968,9 @@ uint32_t smb_vfs_call_fs_capabilities(struct vfs_handle_struct *handle,
 NTSTATUS smb_vfs_call_get_dfs_referrals(struct vfs_handle_struct *handle,
                                        struct dfs_GetDFSReferral *r);
 DIR *smb_vfs_call_opendir(struct vfs_handle_struct *handle,
-                                    const char *fname, const char *mask,
-                                    uint32_t attributes);
+                       const struct smb_filename *smb_fname,
+                       const char *mask,
+                       uint32_t attributes);
 DIR *smb_vfs_call_fdopendir(struct vfs_handle_struct *handle,
                                        struct files_struct *fsp,
                                        const char *mask,
index e50c6a69797927dbcf74ce8be53fff2ef94ee45e..2e8ca1877b7df11a17055c851a0a05f5b24e59bc 100644 (file)
        smb_vfs_call_get_dfs_referrals((handle)->next, (r))
 
 /* Directory operations */
-#define SMB_VFS_OPENDIR(conn, fname, mask, attr) \
-       smb_vfs_call_opendir((conn)->vfs_handles, (fname), (mask), (attr))
-#define SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr) \
-       smb_vfs_call_opendir((handle)->next, (fname), (mask), (attr))
+#define SMB_VFS_OPENDIR(conn, smb_fname, mask, attr) \
+       smb_vfs_call_opendir((conn)->vfs_handles, (smb_fname), (mask), (attr))
+#define SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask, attr) \
+       smb_vfs_call_opendir((handle)->next, (smb_fname), (mask), (attr))
 
 #define SMB_VFS_FDOPENDIR(fsp, mask, attr) \
        smb_vfs_call_fdopendir((fsp)->conn->vfs_handles, (fsp), (mask), (attr))
index e16355ab859de0e26aaea6b9d78967576c930504..fa47b3c25a934bf2a9921bf907e9cbd2513b7f4d 100644 (file)
@@ -106,14 +106,17 @@ static void audit_disconnect(vfs_handle_struct *handle)
        return;
 }
 
-static DIR *audit_opendir(vfs_handle_struct *handle, const char *fname, const char *mask, uint32_t attr)
+static DIR *audit_opendir(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       const char *mask,
+                       uint32_t attr)
 {
        DIR *result;
        
-       result = SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
+       result = SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask, attr);
 
        syslog(audit_syslog_priority(handle), "opendir %s %s%s\n",
-              fname,
+              smb_fname->base_name,
               (result == NULL) ? "failed: " : "",
               (result == NULL) ? strerror(errno) : "");
 
index fb974124fdba528d5e4b567ed79b9fa1a1ee61ac..f96455cfb0430b120cac42065e7f752743326ec5 100644 (file)
@@ -54,15 +54,28 @@ static int cap_get_quota(vfs_handle_struct *handle, const char *path,
        return SMB_VFS_NEXT_GET_QUOTA(handle, cappath, qtype, id, dq);
 }
 
-static DIR *cap_opendir(vfs_handle_struct *handle, const char *fname, const char *mask, uint32_t attr)
+static DIR *cap_opendir(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       const char *mask,
+                       uint32_t attr)
 {
-       char *capname = capencode(talloc_tos(), fname);
+       char *capname = capencode(talloc_tos(), smb_fname->base_name);
+       struct smb_filename *cap_smb_fname = NULL;
 
        if (!capname) {
                errno = ENOMEM;
                return NULL;
        }
-       return SMB_VFS_NEXT_OPENDIR(handle, capname, mask, attr);
+       cap_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       capname,
+                                       NULL,
+                                       NULL);
+       if (cap_smb_fname == NULL) {
+               TALLOC_FREE(capname);
+               errno = ENOMEM;
+               return NULL;
+       }
+       return SMB_VFS_NEXT_OPENDIR(handle, cap_smb_fname, mask, attr);
 }
 
 static struct dirent *cap_readdir(vfs_handle_struct *handle,
index f65ed4c7e7855bec5347339c18f13e6d2ca9c705..9f42e5f52a32cf59d084564d93f3019d791e5e5c 100644 (file)
@@ -269,23 +269,38 @@ static NTSTATUS catia_string_replace_allocate(connection_struct *conn,
 }
 
 static DIR *catia_opendir(vfs_handle_struct *handle,
-                                    const char *fname,
-                                    const char *mask,
-                                    uint32_t attr)
+                       const struct smb_filename *smb_fname,
+                       const char *mask,
+                       uint32_t attr)
 {
        char *name_mapped = NULL;
        NTSTATUS status;
        DIR *ret;
+       struct smb_filename *mapped_smb_fname = NULL;
 
-       status = catia_string_replace_allocate(handle->conn, fname,
-                                       &name_mapped, vfs_translate_to_unix);
+       status = catia_string_replace_allocate(handle->conn,
+                               smb_fname->base_name,
+                               &name_mapped,
+                               vfs_translate_to_unix);
        if (!NT_STATUS_IS_OK(status)) {
                errno = map_errno_from_nt_status(status);
                return NULL;
        }
 
-       ret = SMB_VFS_NEXT_OPENDIR(handle, name_mapped, mask, attr);
+       mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
+                               name_mapped,
+                               NULL,
+                               NULL);
+       if (mapped_smb_fname == NULL) {
+               TALLOC_FREE(mapped_smb_fname);
+               errno = ENOMEM;
+               return NULL;
+       }
+
+       ret = SMB_VFS_NEXT_OPENDIR(handle, mapped_smb_fname, mask, attr);
+
        TALLOC_FREE(name_mapped);
+       TALLOC_FREE(mapped_smb_fname);
 
        return ret;
 }
index b13b5173bb39058db8e18ef76fde62699d522269..c96bd0db270cd15ed40a7d9a90dad68e00720e69 100644 (file)
@@ -375,12 +375,15 @@ static NTSTATUS vfswrap_snap_delete(struct vfs_handle_struct *handle,
 
 /* Directory operations */
 
-static DIR *vfswrap_opendir(vfs_handle_struct *handle, const char *fname, const char *mask, uint32_t attr)
+static DIR *vfswrap_opendir(vfs_handle_struct *handle,
+                               const struct smb_filename *smb_fname,
+                               const char *mask,
+                               uint32_t attr)
 {
        DIR *result;
 
        START_PROFILE(syscall_opendir);
-       result = opendir(fname);
+       result = opendir(smb_fname->base_name);
        END_PROFILE(syscall_opendir);
        return result;
 }
index d1640880e7180c6423ab0b1b7223b3c8cd5db145..f8568353bd9048bd14302d2916a9709bf5705e42 100644 (file)
@@ -113,8 +113,9 @@ static bool open_and_sort_dir(vfs_handle_struct *handle,
 }
 
 static DIR *dirsort_opendir(vfs_handle_struct *handle,
-                                      const char *fname, const char *mask,
-                                      uint32_t attr)
+                               const struct smb_filename *smb_fname,
+                               const char *mask,
+                               uint32_t attr)
 {
        struct dirsort_privates *list_head = NULL;
        struct dirsort_privates *data = NULL;
@@ -131,14 +132,14 @@ static DIR *dirsort_opendir(vfs_handle_struct *handle,
                return NULL;
        }
 
-       data->smb_fname = synthetic_smb_fname(data, fname, NULL, NULL);
+       data->smb_fname = cp_smb_filename(data, smb_fname);
        if (data->smb_fname == NULL) {
                TALLOC_FREE(data);
                return NULL;
        }
 
        /* Open the underlying directory and count the number of entries */
-       data->source_directory = SMB_VFS_NEXT_OPENDIR(handle, fname, mask,
+       data->source_directory = SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask,
                                                      attr);
 
        if (data->source_directory == NULL) {
index 6429370d71bcbc9d04a38cfd85b916165c6dfc0f..137bf72a093c67d77875827b657c9275c9efdf4d 100644 (file)
@@ -116,20 +116,23 @@ static void audit_disconnect(vfs_handle_struct *handle)
        return;
 }
 
-static DIR *audit_opendir(vfs_handle_struct *handle, const char *fname, const char *mask, uint32_t attr)
+static DIR *audit_opendir(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       const char *mask,
+                       uint32_t attr)
 {
        DIR *result;
 
-       result = SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
+       result = SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask, attr);
 
        if (lp_syslog() > 0) {
                syslog(audit_syslog_priority(handle), "opendir %s %s%s\n",
-                      fname,
+                      smb_fname->base_name,
                       (result == NULL) ? "failed: " : "",
                       (result == NULL) ? strerror(errno) : "");
        }
        DEBUG(1, ("vfs_extd_audit: opendir %s %s %s\n",
-              fname,
+              smb_fname->base_name,
               (result == NULL) ? "failed: " : "",
               (result == NULL) ? strerror(errno) : ""));
 
index 3dd200510cc5208d4e9c3159c208c338d021f1c9..311c760ca193ecb3a6bd40ecc2888777b4bd2365 100644 (file)
@@ -776,13 +776,16 @@ static NTSTATUS smb_full_audit_snap_delete(struct vfs_handle_struct *handle,
 }
 
 static DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
-                         const char *fname, const char *mask, uint32_t attr)
+                       const struct smb_filename *smb_fname,
+                       const char *mask,
+                       uint32_t attr)
 {
        DIR *result;
 
-       result = SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
+       result = SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask, attr);
 
-       do_log(SMB_VFS_OP_OPENDIR, (result != NULL), handle, "%s", fname);
+       do_log(SMB_VFS_OP_OPENDIR, (result != NULL), handle, "%s",
+               smb_fname->base_name);
 
        return result;
 }
index b5173af49890795ee68ea817cfeb3593eeeb2051..786cee9288ef1c910349087f5a70306444407b6c 100644 (file)
@@ -760,15 +760,16 @@ err:
  * Failure: set errno, return NULL
  */
 static DIR *mh_opendir(vfs_handle_struct *handle,
-               const char *fname,
+               const struct smb_filename *smb_fname,
                const char *mask,
                uint32_t attr)
 {
        struct mh_dirinfo_struct *dirInfo;
 
-       DEBUG(MH_INFO_DEBUG, ("Entering with fname '%s'\n", fname));
+       DEBUG(MH_INFO_DEBUG, ("Entering with fname '%s'\n",
+               smb_fname->base_name));
 
-       if (alloc_set_client_dirinfo(handle, fname, &dirInfo))
+       if (alloc_set_client_dirinfo(handle, smb_fname->base_name, &dirInfo))
        {
                goto err;
        }
@@ -776,10 +777,20 @@ static DIR *mh_opendir(vfs_handle_struct *handle,
        if (!dirInfo->isInMediaFiles)
        {
                dirInfo->dirstream = SMB_VFS_NEXT_OPENDIR(handle,
-                       fname, mask, attr);
+                       smb_fname, mask, attr);
        } else {
+               struct smb_filename *smb_fname_clientpath =
+                               synthetic_smb_fname(talloc_tos(),
+                                       dirInfo->clientPath,
+                                       NULL,
+                                       NULL);
+               if (smb_fname_clientpath == NULL) {
+                       goto err;
+               }
+
                dirInfo->dirstream = SMB_VFS_NEXT_OPENDIR(handle,
-                       dirInfo->clientPath, mask, attr);
+                       smb_fname_clientpath, mask, attr);
+               TALLOC_FREE(smb_fname_clientpath);
        }
 
        if (dirInfo->dirstream == NULL) {
@@ -794,7 +805,8 @@ static DIR *mh_opendir(vfs_handle_struct *handle,
        return (DIR*)dirInfo;
 err:
        /* Failure is freed here. */
-       DEBUG(MH_ERR_DEBUG, ("Failing with fname '%s'\n", fname));
+       DEBUG(MH_ERR_DEBUG, ("Failing with fname '%s'\n",
+               smb_fname->base_name));
        TALLOC_FREE(dirInfo);
        return NULL;
 }
index 487ab50189caebeb98bfc317725fcece48821900..d8f9f34fc7343c20006f38f71c0d31820ee92595 100644 (file)
@@ -177,11 +177,14 @@ static void atalk_rrmdir(TALLOC_CTX *ctx, char *path)
 
 /* Directory operations */
 
-static DIR *atalk_opendir(struct vfs_handle_struct *handle, const char *fname, const char *mask, uint32_t attr)
+static DIR *atalk_opendir(struct vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       const char *mask,
+                       uint32_t attr)
 {
        DIR *ret = 0;
 
-       ret = SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
+       ret = SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask, attr);
 
        /*
         * when we try to perform delete operation upon file which has fork
index 5c05e254a03be5e709cdb6eea1d16a46f4c4733b..77dc1636c91f8dd8835c34ddb7ec803a261e78b2 100644 (file)
@@ -73,13 +73,18 @@ static bool shadow_copy_match_name(const char *name)
        return False;
 }
 
-static DIR *shadow_copy_opendir(vfs_handle_struct *handle, const char *fname, const char *mask, uint32_t attr)
+static DIR *shadow_copy_opendir(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       const char *mask,
+                       uint32_t attr)
 {
        shadow_copy_Dir *dirp;
-       DIR *p = SMB_VFS_NEXT_OPENDIR(handle,fname,mask,attr);
+       DIR *p = SMB_VFS_NEXT_OPENDIR(handle,smb_fname,mask,attr);
 
        if (!p) {
-               DEBUG(0,("shadow_copy_opendir: SMB_VFS_NEXT_OPENDIR() failed for [%s]\n",fname));
+               DEBUG(0,("shadow_copy_opendir: SMB_VFS_NEXT_OPENDIR() "
+                       "failed for [%s]\n",
+                       smb_fname->base_name));
                return NULL;
        }
 
@@ -221,7 +226,19 @@ static int shadow_copy_get_shadow_copy_data(vfs_handle_struct *handle,
                                            struct shadow_copy_data *shadow_copy_data,
                                            bool labels)
 {
-       DIR *p = SMB_VFS_NEXT_OPENDIR(handle,fsp->conn->connectpath,NULL,0);
+       DIR *p = NULL;
+       struct smb_filename *smb_fname = synthetic_smb_fname(talloc_tos(),
+                                               fsp->conn->connectpath,
+                                               NULL,
+                                               NULL);
+       if (smb_fname == NULL) {
+               errno = ENOMEM;
+               return -1;
+       }
+
+       p = SMB_VFS_NEXT_OPENDIR(handle,smb_fname,NULL,0);
+
+       TALLOC_FREE(smb_fname);
 
        shadow_copy_data->num_volumes = 0;
        shadow_copy_data->labels = NULL;
index 7817168a52177e5b1e5571f14c6103b23a3566a2..27fc8a96cb80d47f9aa1343c889ff56a59f80352 100644 (file)
@@ -690,31 +690,44 @@ static void convert_sbuf(vfs_handle_struct *handle, const char *fname,
 }
 
 static DIR *shadow_copy2_opendir(vfs_handle_struct *handle,
-                                           const char *fname,
-                                           const char *mask,
-                                           uint32_t attr)
+                       const struct smb_filename *smb_fname,
+                       const char *mask,
+                       uint32_t attr)
 {
        time_t timestamp;
        char *stripped;
        DIR *ret;
        int saved_errno;
        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 NULL;
        }
        if (timestamp == 0) {
-               return SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
+               return SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask, attr);
        }
        conv = shadow_copy2_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);
+       if (conv_smb_fname == NULL) {
+               TALLOC_FREE(conv);
+               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;
 }
@@ -1372,6 +1385,7 @@ static int shadow_copy2_get_shadow_copy_data(
 {
        DIR *p;
        const char *snapdir;
+       struct smb_filename *snapdir_smb_fname = NULL;
        struct dirent *d;
        TALLOC_CTX *tmp_ctx = talloc_stackframe();
        bool ret;
@@ -1392,7 +1406,17 @@ static int shadow_copy2_get_shadow_copy_data(
                return -1;
        }
 
-       p = SMB_VFS_NEXT_OPENDIR(handle, snapdir, NULL, 0);
+       snapdir_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       snapdir,
+                                       NULL,
+                                       NULL);
+       if (snapdir_smb_fname == NULL) {
+               errno = ENOMEM;
+               talloc_free(tmp_ctx);
+               return -1;
+       }
+
+       p = SMB_VFS_NEXT_OPENDIR(handle, snapdir_smb_fname, NULL, 0);
 
        if (!p) {
                DEBUG(2,("shadow_copy2: SMB_VFS_NEXT_OPENDIR() failed for '%s'"
index 80396c4e7f09b1514cca403ab083b377551c1519..5f5e296fcf8f749e190b936c4b5b03251c883a3c 100644 (file)
@@ -1943,7 +1943,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 +1952,37 @@ 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);
+       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;
 }
index f6226e75abaf7ccc973d40daf951038dad7c03a4..d998dc51a347e60b151a86d1169c52b53c2762ed 100644 (file)
@@ -420,6 +420,7 @@ static NTSTATUS walk_streams(vfs_handle_struct *handle,
                             void *private_data)
 {
        char *dirname;
+       struct smb_filename *dir_smb_fname = NULL;
        DIR *dirhandle = NULL;
        const char *dirent = NULL;
        char *talloced = NULL;
@@ -439,7 +440,18 @@ static NTSTATUS walk_streams(vfs_handle_struct *handle,
 
        DEBUG(10, ("walk_streams: dirname=%s\n", dirname));
 
-       dirhandle = SMB_VFS_NEXT_OPENDIR(handle, dirname, NULL, 0);
+       dir_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       dirname,
+                                       NULL,
+                                       NULL);
+       if (dir_smb_fname == NULL) {
+               TALLOC_FREE(dirname);
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       dirhandle = SMB_VFS_NEXT_OPENDIR(handle, dir_smb_fname, NULL, 0);
+
+       TALLOC_FREE(dir_smb_fname);
 
        if (dirhandle == NULL) {
                TALLOC_FREE(dirname);
index 11866fa2f666565668788bbaf21fde18b53a3191..7998baca693124adf276c2c24657b6f3d4ffd193 100644 (file)
@@ -347,7 +347,7 @@ static NTSTATUS smb_time_audit_snap_delete(struct vfs_handle_struct *handle,
 }
 
 static DIR *smb_time_audit_opendir(vfs_handle_struct *handle,
-                                  const char *fname,
+                                  const struct smb_filename *smb_fname,
                                   const char *mask, uint32_t attr)
 {
        DIR *result;
@@ -355,12 +355,12 @@ static DIR *smb_time_audit_opendir(vfs_handle_struct *handle,
        double timediff;
 
        clock_gettime_mono(&ts1);
-       result = SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
+       result = SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask, attr);
        clock_gettime_mono(&ts2);
        timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
 
        if (timediff > audit_timeout) {
-               smb_time_audit_log_fname("opendir", timediff, fname);
+               smb_time_audit_log_smb_fname("opendir", timediff, smb_fname);
        }
 
        return result;
index 2e581e3cda49a1175e62b4158b7caf3e7d76beff..191d39feab970c5f0c0aece0d53a82cf3b709f63 100644 (file)
@@ -551,24 +551,35 @@ err:
  * Failure: set errno, return NULL
  */
 static DIR *um_opendir(vfs_handle_struct *handle,
-                      const char *fname,
+                      const struct smb_filename *smb_fname,
                       const char *mask,
                       uint32_t attr)
 {
        struct um_dirinfo_struct *dirInfo;
 
-       DEBUG(10, ("Entering with fname '%s'\n", fname));
+       DEBUG(10, ("Entering with fname '%s'\n", smb_fname->base_name));
 
-       if (alloc_set_client_dirinfo(handle, fname, &dirInfo)) {
+       if (alloc_set_client_dirinfo(handle, smb_fname->base_name, &dirInfo)) {
                goto err;
        }
 
        if (!dirInfo->isInMediaFiles) {
                dirInfo->dirstream = SMB_VFS_NEXT_OPENDIR(
-                       handle, fname, mask, attr);
+                       handle, smb_fname, mask, attr);
        } else {
+               struct smb_filename *client_smb_fname =
+                       synthetic_smb_fname(talloc_tos(),
+                                       dirInfo->clientPath,
+                                       NULL,
+                                       NULL);
+               if (client_smb_fname == NULL) {
+                       goto err;
+               }
+
                dirInfo->dirstream = SMB_VFS_NEXT_OPENDIR(
-                       handle, dirInfo->clientPath, mask, attr);
+                       handle, client_smb_fname, mask, attr);
+
+               TALLOC_FREE(client_smb_fname);
        }
 
        if (dirInfo->dirstream == NULL) {
@@ -582,7 +593,7 @@ static DIR *um_opendir(vfs_handle_struct *handle,
        return (DIR*)dirInfo;
 
 err:
-       DEBUG(1, ("Failing with fname '%s'\n", fname));
+       DEBUG(1, ("Failing with fname '%s'\n", smb_fname->base_name));
        TALLOC_FREE(dirInfo);
        return NULL;
 }
index a586edf8aa9d48413bc428ce12129d59bdc755cd..bdd79ca08ebcddf52e9e470f0c02df13b8edb147 100644 (file)
@@ -1595,6 +1595,7 @@ struct smb_Dir *OpenDir(TALLOC_CTX *mem_ctx, connection_struct *conn,
 {
        struct smb_Dir *dirp = talloc_zero(mem_ctx, struct smb_Dir);
        struct smbd_server_connection *sconn = conn->sconn;
+       struct smb_filename *smb_fname = NULL;
 
        if (!dirp) {
                return NULL;
@@ -1614,7 +1615,19 @@ struct smb_Dir *OpenDir(TALLOC_CTX *mem_ctx, connection_struct *conn,
        }
        talloc_set_destructor(dirp, smb_Dir_destructor);
 
-       dirp->dir = SMB_VFS_OPENDIR(conn, dirp->dir_path, mask, attr);
+       smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       dirp->dir_path,
+                                       NULL,
+                                       NULL);
+       if (smb_fname == NULL) {
+               errno = ENOMEM;
+               goto fail;
+       }
+
+       dirp->dir = SMB_VFS_OPENDIR(conn, smb_fname, mask, attr);
+
+       TALLOC_FREE(smb_fname);
+
        if (!dirp->dir) {
                DEBUG(5,("OpenDir: Can't open %s. %s\n", dirp->dir_path,
                         strerror(errno) ));
@@ -1675,7 +1688,7 @@ static struct smb_Dir *OpenDir_fsp(TALLOC_CTX *mem_ctx, connection_struct *conn,
 
        if (dirp->dir == NULL) {
                /* FDOPENDIR didn't work. Use OPENDIR instead. */
-               dirp->dir = SMB_VFS_OPENDIR(conn, dirp->dir_path, mask, attr);
+               dirp->dir = SMB_VFS_OPENDIR(conn, fsp->fsp_name, mask, attr);
        }
 
        if (!dirp->dir) {
index e895c1f7accf4a83e74dde13705dc52cb948df5e..fe95877fe8d7c7dd33a44be3356de7213e3aa87e 100644 (file)
@@ -1385,6 +1385,7 @@ static int count_dfs_links(TALLOC_CTX *ctx, int snum)
        connection_struct *conn;
        NTSTATUS status;
        char *cwd;
+       struct smb_filename *smb_fname = NULL;
 
        if(*connect_path == '\0') {
                return 0;
@@ -1413,8 +1414,16 @@ static int count_dfs_links(TALLOC_CTX *ctx, int snum)
                goto out;
        }
 
+       smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       ".",
+                                       NULL,
+                                       NULL);
+       if (smb_fname == NULL) {
+               goto out;
+       }
+
        /* Now enumerate all dfs links */
-       dirp = SMB_VFS_OPENDIR(conn, ".", NULL, 0);
+       dirp = SMB_VFS_OPENDIR(conn, smb_fname, NULL, 0);
        if(!dirp) {
                goto out;
        }
@@ -1432,6 +1441,7 @@ static int count_dfs_links(TALLOC_CTX *ctx, int snum)
        SMB_VFS_CLOSEDIR(conn,dirp);
 
 out:
+       TALLOC_FREE(smb_fname);
        vfs_ChDir(conn, cwd);
        SMB_VFS_DISCONNECT(conn);
        conn_free(conn);
@@ -1456,6 +1466,7 @@ static int form_junctions(TALLOC_CTX *ctx,
        connection_struct *conn;
        struct referral *ref = NULL;
        char *cwd;
+       struct smb_filename *smb_fname = NULL;
        NTSTATUS status;
 
        if (jn_remain == 0) {
@@ -1520,8 +1531,16 @@ static int form_junctions(TALLOC_CTX *ctx,
                goto out;
        }
 
+       smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       ".",
+                                       NULL,
+                                       NULL);
+       if (smb_fname == NULL) {
+               goto out;
+       }
+
        /* Now enumerate all dfs links */
-       dirp = SMB_VFS_OPENDIR(conn, ".", NULL, 0);
+       dirp = SMB_VFS_OPENDIR(conn, smb_fname, NULL, 0);
        if(!dirp) {
                goto out;
        }
@@ -1567,6 +1586,7 @@ out:
                SMB_VFS_CLOSEDIR(conn,dirp);
        }
 
+       TALLOC_FREE(smb_fname);
        vfs_ChDir(conn, cwd);
        conn_free(conn);
        return cnt;
index dfc22be9179f5b56883e1914077f702e85313190..d29586b3cc58e07aa62821e075eac68517c98ea9 100644 (file)
@@ -1452,11 +1452,12 @@ NTSTATUS smb_vfs_call_get_dfs_referrals(struct vfs_handle_struct *handle,
 }
 
 DIR *smb_vfs_call_opendir(struct vfs_handle_struct *handle,
-                                    const char *fname, const char *mask,
-                                    uint32_t attributes)
+                                       const struct smb_filename *smb_fname,
+                                       const char *mask,
+                                       uint32_t attributes)
 {
        VFS_FIND(opendir);
-       return handle->fns->opendir_fn(handle, fname, mask, attributes);
+       return handle->fns->opendir_fn(handle, smb_fname, mask, attributes);
 }
 
 DIR *smb_vfs_call_fdopendir(struct vfs_handle_struct *handle,
index 6dcf80544d5fd0f740c5d9ea2145c8304d4a77f8..0bc6dbcd5ac2ef47834f81471d0a36cf2a766d85 100644 (file)
@@ -129,17 +129,29 @@ static NTSTATUS cmd_disk_free(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int ar
 
 static NTSTATUS cmd_opendir(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
 {
+       struct smb_filename *smb_fname = NULL;
+
        if (argc != 2) {
                printf("Usage: opendir <fname>\n");
                return NT_STATUS_OK;
        }
 
-       vfs->currentdir = SMB_VFS_OPENDIR(vfs->conn, argv[1], NULL, 0);
+       smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       argv[1],
+                                       NULL,
+                                       NULL);
+       if (smb_fname == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       vfs->currentdir = SMB_VFS_OPENDIR(vfs->conn, smb_fname, NULL, 0);
        if (vfs->currentdir == NULL) {
                printf("opendir error=%d (%s)\n", errno, strerror(errno));
+               TALLOC_FREE(smb_fname);
                return NT_STATUS_UNSUCCESSFUL;
        }
 
+       TALLOC_FREE(smb_fname);
        printf("opendir: ok\n");
        return NT_STATUS_OK;
 }
@@ -1729,6 +1741,7 @@ static NTSTATUS cmd_translate_name(struct vfs_state *vfs, TALLOC_CTX *mem_ctx,
        SMB_STRUCT_STAT st;
        bool found = false;
        char *translated = NULL;
+       struct smb_filename *smb_fname = NULL;
        NTSTATUS status;
 
        if (argc != 2) {
@@ -1736,10 +1749,19 @@ static NTSTATUS cmd_translate_name(struct vfs_state *vfs, TALLOC_CTX *mem_ctx,
                return NT_STATUS_UNSUCCESSFUL;
        }
 
-       vfs->currentdir = SMB_VFS_OPENDIR(vfs->conn, ".", NULL, 0);
+       smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       ".",
+                                       NULL,
+                                       NULL);
+       if (smb_fname == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       vfs->currentdir = SMB_VFS_OPENDIR(vfs->conn, smb_fname, NULL, 0);
        if (vfs->currentdir == NULL) {
                DEBUG(0, ("cmd_translate_name: opendir error=%d (%s)\n",
                          errno, strerror(errno)));
+               TALLOC_FREE(smb_fname);
                return NT_STATUS_UNSUCCESSFUL;
        }
 
@@ -1775,9 +1797,11 @@ static NTSTATUS cmd_translate_name(struct vfs_state *vfs, TALLOC_CTX *mem_ctx,
        DEBUG(0, ("cmd_translate_name: file '%s' --> '%s'\n", 
                  argv[1], translated));
 
+       TALLOC_FREE(smb_fname);
        TALLOC_FREE(translated);
 
 cleanup:
+       TALLOC_FREE(smb_fname);
        ret = SMB_VFS_CLOSEDIR(vfs->conn, vfs->currentdir);
        if (ret == -1) {
                DEBUG(0, ("cmd_translate_name: closedir failure: %s\n",