The branch, master has been updated
       via  46418dddda9 s3: smbd: Convert driver_unix_convert() to use 
filename_convert_dirfsp().
       via  f42b5be4127 s3: smbd: Add dirfsp return parameter to 
driver_unix_convert().
       via  87835c69ccf s3: smbd: In filename_convert_dirfsp_nosymlink() only 
use synthetic_smb_fname_split() for fake_files, not printer shares too.
       via  ffc19ac9859 s3: smbd: Remove filename_convert().
       via  68483583630 s3: smbd: Convert filename_convert_smb1_search_path() 
to use filename_convert_dirfsp().
       via  7bd5c05fbd9 s3: smbd: Add returned dirfsp pointer to 
filename_convert_smb1_search_path().
       via  5a923ae36ab s3: smbd: We now know get_original_lcomp() never has to 
deal with an MSDFS pathname.
       via  4112bab9aeb s3: smbd: In filename_convert_smb1_search_path(), after 
we have called dfs_redirect(), the path separator is always '/'.
       via  2d9938dac32 s3: smbd: Remove TWRP handing inside 
get_original_lcomp().
       via  acff075a725 s3: smbd: In reply_ntrename(), move the call to 
get_original_lcomp(..newname..) after the call to 
extract_snapshot_token(..newname..).
       via  5eed3f48b6e s3: smbd: Remove code for unused 
strip_gmt_from_raw_dfs().
       via  df5455c438d s3: smbd: Change filename_convert_smb1_search_path() to 
use extract_snapshot_token().
       via  2ad3e63fe02 s3: smbd: Remove const from name_in parameter to 
filename_convert_smb1_search_path().
       via  74715a75053 s3: smbd: Remove separate talloc_stackframe() from 
filename_convert_smb1_search_path().
       via  7a823d44d23 s3: smbd: Allow extract_snapshot_token() to cope with 
MSDFS paths.
       via  8b9fdc8ab1b s3: smbd: Add ucf_flags parameter to 
extract_snapshot_token().
      from  2120b215872 testprogs: Reformat test_ktpass.sh

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 46418dddda9128c8fad8c68f6aa2212b7ad566c9
Author: Jeremy Allison <j...@samba.org>
Date:   Tue Aug 2 14:06:44 2022 -0700

    s3: smbd: Convert driver_unix_convert() to use filename_convert_dirfsp().
    
    There is now only one user left of unix_convert(), inside
    the MSDFS code. I have plans to get rid of this soon.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Volker Lendecke <v...@samba.org>
    
    Autobuild-User(master): Jeremy Allison <j...@samba.org>
    Autobuild-Date(master): Thu Aug  4 18:10:43 UTC 2022 on sn-devel-184

commit f42b5be412717cdec67d86fe97314d5c0daa4e71
Author: Jeremy Allison <j...@samba.org>
Date:   Tue Aug 2 14:01:59 2022 -0700

    s3: smbd: Add dirfsp return parameter to driver_unix_convert().
    
    Not yet used, but (dirfsp=NULL) value passed to functions
    called after driver_unix_convert().
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Volker Lendecke <v...@samba.org>

commit 87835c69ccf44ddf422f332caa5f00780634a48a
Author: Jeremy Allison <j...@samba.org>
Date:   Tue Aug 2 18:13:52 2022 -0700

    s3: smbd: In filename_convert_dirfsp_nosymlink() only use 
synthetic_smb_fname_split() for fake_files, not printer shares too.
    
    Printer shares can have real filenames.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Volker Lendecke <v...@samba.org>

commit ffc19ac98594c1b41731c7c5fe2e33f3224616c6
Author: Jeremy Allison <j...@samba.org>
Date:   Wed Aug 3 10:04:37 2022 -0700

    s3: smbd: Remove filename_convert().
    
                                (\  _  /)
                                ( \ O / )
                                 (// \\)
                                    X
                                   / \
                                  /___\
                           _____/      \\_____
                          |         +         ||
                          |                   ||
                          |  filename_convert ||
                          |                   ||
                          |                   ||
                          |                   ||
                          |                   ||
                          |  _     ___   _    ||
                          | | \     |   | \   ||
                          | |  |    |   |  |  ||
                          | |_/     |   |_/   ||
                          | | \     |   |     ||
                          | |  \    |   |     ||
                          | |   \. _|_. | .   ||
                          |                   ||
                  *     * | *   **    * **    |**     **
                   \)),.,\(/.,(//,,..,,\||(,,.,\\,.((//
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Volker Lendecke <v...@samba.org>

commit 684835836305cb0ffd144516320a81811fe78ac4
Author: Jeremy Allison <j...@samba.org>
Date:   Wed Aug 3 10:02:42 2022 -0700

    s3: smbd: Convert filename_convert_smb1_search_path() to use 
filename_convert_dirfsp().
    
    There are now no more users of filename_convert().
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Volker Lendecke <v...@samba.org>

commit 7bd5c05fbd9e4c1a1fc99dd8d673636aa19578e7
Author: Jeremy Allison <j...@samba.org>
Date:   Wed Aug 3 09:58:54 2022 -0700

    s3: smbd: Add returned dirfsp pointer to 
filename_convert_smb1_search_path().
    
    Preparation for convertion of the last filename_convert() -> 
filename_convert_dirfsp().
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Volker Lendecke <v...@samba.org>

commit 5a923ae36ab6e458987dbb0296b8dae1de35bd87
Author: Jeremy Allison <j...@samba.org>
Date:   Wed Aug 3 11:45:39 2022 -0700

    s3: smbd: We now know get_original_lcomp() never has to deal with an MSDFS 
pathname.
    
    Remove the call to dfs_redirect() within it.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Volker Lendecke <v...@samba.org>

commit 4112bab9aeb9816c6a7a753cc4f82a7136902896
Author: Jeremy Allison <j...@samba.org>
Date:   Wed Aug 3 11:42:17 2022 -0700

    s3: smbd: In filename_convert_smb1_search_path(), after we have called 
dfs_redirect(), the path separator is always '/'.
    
    This will allow us to remove the call to dfs_redirect() from 
get_original_lcomp().
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Volker Lendecke <v...@samba.org>

commit 2d9938dac32ff4afb1dee840bcab50dc84b76bb4
Author: Jeremy Allison <j...@samba.org>
Date:   Tue Aug 2 14:24:46 2022 -0700

    s3: smbd: Remove TWRP handing inside get_original_lcomp().
    
    Now we know all @GMT paths are removed before get_original_lcomp()
    is called, we can eliminate this code.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Volker Lendecke <v...@samba.org>

commit acff075a725118d42dc61b64c5ddb6f3178baf2f
Author: Jeremy Allison <j...@samba.org>
Date:   Tue Aug 2 14:16:15 2022 -0700

    s3: smbd: In reply_ntrename(), move the call to 
get_original_lcomp(..newname..) after the call to 
extract_snapshot_token(..newname..).
    
    This was the last case where the snapshot TWRP token could be
    passed into get_original_lcomp(). get_original_lcomp() can now
    be changed to ignore TWRP tokens.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Volker Lendecke <v...@samba.org>

commit 5eed3f48b6e07c1f6463750922f4bea82e1448ab
Author: Jeremy Allison <j...@samba.org>
Date:   Wed Aug 3 09:50:57 2022 -0700

    s3: smbd: Remove code for unused strip_gmt_from_raw_dfs().
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Volker Lendecke <v...@samba.org>

commit df5455c438d1b8f0751d042d56e999c6960af173
Author: Jeremy Allison <j...@samba.org>
Date:   Wed Aug 3 09:50:02 2022 -0700

    s3: smbd: Change filename_convert_smb1_search_path() to use 
extract_snapshot_token().
    
    strip_gmt_from_raw_dfs() is now no longer used.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Volker Lendecke <v...@samba.org>

commit 2ad3e63fe02e6ca3ff4d5b70b0f3795e8cd414ba
Author: Jeremy Allison <j...@samba.org>
Date:   Wed Aug 3 09:27:37 2022 -0700

    s3: smbd: Remove const from name_in parameter to 
filename_convert_smb1_search_path().
    
    We're going to need to convert in place if it's an MSDFS path
    with an SMB1 @GMT token.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Volker Lendecke <v...@samba.org>

commit 74715a750533cb350dc1f48e7e9d5ebd121c68ba
Author: Jeremy Allison <j...@samba.org>
Date:   Wed Aug 3 09:33:48 2022 -0700

    s3: smbd: Remove separate talloc_stackframe() from 
filename_convert_smb1_search_path().
    
    We're soon going to change this to return dirfsp and use 
convert_filename_dirfsp()
    so we need to return values on the passed in talloc ctx.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Volker Lendecke <v...@samba.org>

commit 7a823d44d23ae6693f3abd6a0fca6a4e41c51298
Author: Jeremy Allison <j...@samba.org>
Date:   Wed Aug 3 09:20:36 2022 -0700

    s3: smbd: Allow extract_snapshot_token() to cope with MSDFS paths.
    
    "raw" MSDFS paths are passed here as \server\share\path.
    
    find_snapshot_token() only looks for a '/' as a separator
    in SMB1 shapshot paths.
    
    Allow extract_snapshot_token() to cope with SMB1 MSDFS paths by
    converting in place, looking for the @GMT token with a '/'
    separator via find_snapshot_token(), and then converting back.
    
    Note, this a temporary measure until we handle DFS paths better
    and will be removed in the next patchset.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Reviewed-by: Volker Lendecke <v...@samba.org>

commit 8b9fdc8ab1b06a3bf75ff3757b3e40ddd0d1eb9f
Author: Jeremy Allison <j...@samba.org>
Date:   Wed Aug 3 09:08:48 2022 -0700

    s3: smbd: Add ucf_flags parameter to extract_snapshot_token().
    
    Will be needed to cope with MSDFS paths which can be passed in
    to this function.
    
    Note, this a temporary measure until we handle DFS paths better
    and will be removed in the next patchset.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Reviewed-by: Volker Lendecke <v...@samba.org>

-----------------------------------------------------------------------

Summary of changes:
 source3/printing/nt_printing.c |  41 +++--
 source3/smbd/filename.c        | 369 ++++++-----------------------------------
 source3/smbd/proto.h           |  11 +-
 source3/smbd/smb1_nttrans.c    |  31 ++--
 source3/smbd/smb1_reply.c      |  28 ++--
 source3/smbd/smb1_trans2.c     |  12 +-
 source3/smbd/smb2_trans2.c     |   8 +-
 7 files changed, 130 insertions(+), 370 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c
index dc54a194f65..4b4d12f25d5 100644
--- a/source3/printing/nt_printing.c
+++ b/source3/printing/nt_printing.c
@@ -242,7 +242,8 @@ bool nt_printing_init(struct messaging_context *msg_ctx)
 
 static NTSTATUS driver_unix_convert(connection_struct *conn,
                                    const char *old_name,
-                                   struct smb_filename **smb_fname)
+                                   struct files_struct **pdirfsp,
+                                   struct smb_filename **psmb_fname)
 {
        NTSTATUS status;
        TALLOC_CTX *ctx = talloc_tos();
@@ -258,9 +259,15 @@ static NTSTATUS driver_unix_convert(connection_struct 
*conn,
        }
        trim_string(name,"/","/");
 
-       status = unix_convert(ctx, conn, name, 0, smb_fname, 0);
+       status = filename_convert_dirfsp(ctx,
+                                        conn,
+                                        name,
+                                        0, /* ucf_flags */
+                                        0, /* twrp */
+                                        pdirfsp,
+                                        psmb_fname);
        if (!NT_STATUS_IS_OK(status)) {
-               return NT_STATUS_NO_MEMORY;
+               return status;
        }
 
        return NT_STATUS_OK;
@@ -806,6 +813,7 @@ static int file_version_is_newer(connection_struct *conn, 
fstring new_file, fstr
 
        struct smb_filename *smb_fname = NULL;
        files_struct    *fsp = NULL;
+       struct files_struct *dirfsp = NULL;
        SMB_STRUCT_STAT st;
 
        NTSTATUS status;
@@ -816,7 +824,7 @@ static int file_version_is_newer(connection_struct *conn, 
fstring new_file, fstr
        old_create_time = (time_t)0;
 
        /* Get file version info (if available) for previous file (if it 
exists) */
-       status = driver_unix_convert(conn, old_file, &smb_fname);
+       status = driver_unix_convert(conn, old_file, &dirfsp, &smb_fname);
        if (!NT_STATUS_IS_OK(status)) {
                goto error_exit;
        }
@@ -830,7 +838,7 @@ static int file_version_is_newer(connection_struct *conn, 
fstring new_file, fstr
        status = SMB_VFS_CREATE_FILE(
                conn,                                   /* conn */
                NULL,                                   /* req */
-               NULL,                                   /* dirfsp */
+               dirfsp,                                 /* dirfsp */
                smb_fname,                              /* fname */
                FILE_GENERIC_READ,                      /* access_mask */
                FILE_SHARE_READ | FILE_SHARE_WRITE,     /* share_access */
@@ -878,7 +886,7 @@ static int file_version_is_newer(connection_struct *conn, 
fstring new_file, fstr
        close_file_free(NULL, &fsp, NORMAL_CLOSE);
 
        /* Get file version info (if available) for new file */
-       status = driver_unix_convert(conn, new_file, &smb_fname);
+       status = driver_unix_convert(conn, new_file, &dirfsp, &smb_fname);
        if (!NT_STATUS_IS_OK(status)) {
                goto error_exit;
        }
@@ -893,7 +901,7 @@ static int file_version_is_newer(connection_struct *conn, 
fstring new_file, fstr
        status = SMB_VFS_CREATE_FILE(
                conn,                                   /* conn */
                NULL,                                   /* req */
-               NULL,                                   /* dirfsp */
+               dirfsp,                                 /* dirfsp */
                smb_fname,                              /* fname */
                FILE_GENERIC_READ,                      /* access_mask */
                FILE_SHARE_READ | FILE_SHARE_WRITE,     /* share_access */
@@ -992,6 +1000,7 @@ static uint32_t get_correct_cversion(const struct 
auth_session_info *session_inf
        NTSTATUS          nt_status;
        struct smb_filename *smb_fname = NULL;
        files_struct      *fsp = NULL;
+       struct files_struct *dirfsp = NULL;
        struct conn_struct_tos *c = NULL;
        connection_struct *conn = NULL;
        char *printdollar = NULL;
@@ -1085,7 +1094,10 @@ static uint32_t get_correct_cversion(const struct 
auth_session_info *session_inf
         * We switch to the directory where the driver files are located,
         * so only work on the file names
         */
-       nt_status = driver_unix_convert(conn, driverpath_in, &smb_fname);
+       nt_status = driver_unix_convert(conn,
+                                       driverpath_in,
+                                       &dirfsp,
+                                       &smb_fname);
        if (!NT_STATUS_IS_OK(nt_status)) {
                *perr = ntstatus_to_werror(nt_status);
                goto error_exit;
@@ -1110,7 +1122,7 @@ static uint32_t get_correct_cversion(const struct 
auth_session_info *session_inf
        nt_status = SMB_VFS_CREATE_FILE(
                conn,                                   /* conn */
                NULL,                                   /* req */
-               NULL,                                   /* dirfsp */
+               dirfsp,                                 /* dirfsp */
                smb_fname,                              /* fname */
                FILE_GENERIC_READ,                      /* access_mask */
                FILE_SHARE_READ | FILE_SHARE_WRITE,     /* share_access */
@@ -1439,8 +1451,12 @@ static WERROR 
move_driver_file_to_download_area(TALLOC_CTX *mem_ctx,
        }
 
        if (version != -1 && (version = file_version_is_newer(conn, old_name, 
new_name)) > 0) {
+               struct files_struct *dirfsp = NULL;
 
-               status = driver_unix_convert(conn, old_name, &smb_fname_old);
+               status = driver_unix_convert(conn,
+                                            old_name,
+                                            &dirfsp,
+                                            &smb_fname_old);
                if (!NT_STATUS_IS_OK(status)) {
                        ret = WERR_NOT_ENOUGH_MEMORY;
                        goto out;
@@ -1489,6 +1505,7 @@ WERROR move_driver_to_download_area(const struct 
auth_session_info *session_info
        struct spoolss_AddDriverInfo3 *driver;
        struct spoolss_AddDriverInfo3 converted_driver;
        const char *short_architecture;
+       struct files_struct *dirfsp = NULL;
        struct smb_filename *smb_dname = NULL;
        char *new_dir = NULL;
        struct conn_struct_tos *c = NULL;
@@ -1569,7 +1586,7 @@ WERROR move_driver_to_download_area(const struct 
auth_session_info *session_info
                err = WERR_NOT_ENOUGH_MEMORY;
                goto err_exit;
        }
-       nt_status = driver_unix_convert(conn, new_dir, &smb_dname);
+       nt_status = driver_unix_convert(conn, new_dir, &dirfsp, &smb_dname);
        if (!NT_STATUS_IS_OK(nt_status)) {
                err = WERR_NOT_ENOUGH_MEMORY;
                goto err_exit;
@@ -1577,7 +1594,7 @@ WERROR move_driver_to_download_area(const struct 
auth_session_info *session_info
 
        DEBUG(5,("Creating first directory: %s\n", smb_dname->base_name));
 
-       nt_status = create_directory(conn, NULL, NULL, smb_dname);
+       nt_status = create_directory(conn, NULL, dirfsp, smb_dname);
        if (!NT_STATUS_IS_OK(nt_status)
         && !NT_STATUS_EQUAL(nt_status, NT_STATUS_OBJECT_NAME_COLLISION)) {
                DEBUG(0, ("failed to create driver destination directory: %s\n",
diff --git a/source3/smbd/filename.c b/source3/smbd/filename.c
index 3e90b8dd71b..e378bb72b32 100644
--- a/source3/smbd/filename.c
+++ b/source3/smbd/filename.c
@@ -300,14 +300,28 @@ static bool find_snapshot_token(
        return true;
 }
 
-bool extract_snapshot_token(char *fname, NTTIME *twrp)
+bool extract_snapshot_token(char *fname, uint32_t ucf_flags, NTTIME *twrp)
 {
        const char *start = NULL;
        const char *next = NULL;
        size_t remaining;
        bool found;
+       bool posix_path = (ucf_flags & UCF_POSIX_PATHNAMES);
+       bool msdfs_path = (ucf_flags & UCF_DFS_PATHNAME);
 
+       if (msdfs_path && !posix_path) {
+               /*
+                * A raw (non-POSIX) MSDFS path looks like \server\share\path.
+                * find_snapshot_token only looks for '/' separators.
+                * Convert the separator characters in place.
+                */
+               string_replace(fname, '\\', '/');
+       }
        found = find_snapshot_token(fname, &start, &next, twrp);
+       if (msdfs_path && !posix_path) {
+               /* Put the original separators back. */
+               string_replace(fname, '/', '\\');
+       }
        if (!found) {
                return false;
        }
@@ -346,7 +360,7 @@ NTSTATUS canonicalize_snapshot_path(struct smb_filename 
*smb_fname,
                return NT_STATUS_OK;
        }
 
-       found = extract_snapshot_token(smb_fname->base_name, &twrp);
+       found = extract_snapshot_token(smb_fname->base_name, ucf_flags, &twrp);
        if (!found) {
                return NT_STATUS_OK;
        }
@@ -1879,73 +1893,16 @@ char *get_original_lcomp(TALLOC_CTX *ctx,
                        const char *filename_in,
                        uint32_t ucf_flags)
 {
-       struct smb_filename *smb_fname = NULL;
        char *last_slash = NULL;
        char *orig_lcomp;
-       char *fname = NULL;
-       NTTIME twrp = 0;
        NTSTATUS status;
 
-       if (ucf_flags & UCF_DFS_PATHNAME) {
-               status = dfs_redirect(ctx,
-                               conn,
-                               filename_in,
-                               ucf_flags,
-                               !conn->sconn->using_smb2,
-                               &twrp,
-                               &fname);
-               if (!NT_STATUS_IS_OK(status)) {
-                       DBG_DEBUG("dfs_redirect "
-                               "failed for name %s with %s\n",
-                               filename_in,
-                               nt_errstr(status));
-                       return NULL;
-               }
-               filename_in = fname;
-               ucf_flags &= ~UCF_DFS_PATHNAME;
-       }
-
-       /*
-        * NB. We don't need to care about
-        * is_fake_file_path(filename_in) here as these
-        * code paths don't ever return original_lcomp
-        * or use it anyway.
-        */
-
-       if (ucf_flags & UCF_GMT_PATHNAME) {
-               /*
-                * Ensure we don't return a @GMT
-                * value as the last component.
-                */
-               smb_fname = synthetic_smb_fname(ctx,
-                                       filename_in,
-                                       NULL,
-                                       NULL,
-                                       twrp,
-                                       0);
-               if (smb_fname == NULL) {
-                       TALLOC_FREE(fname);
-                       return NULL;
-               }
-               status = canonicalize_snapshot_path(smb_fname,
-                                                   ucf_flags,
-                                                   twrp);
-               if (!NT_STATUS_IS_OK(status)) {
-                       TALLOC_FREE(fname);
-                       TALLOC_FREE(smb_fname);
-                       return NULL;
-               }
-               filename_in = smb_fname->base_name;
-       }
        last_slash = strrchr(filename_in, '/');
        if (last_slash != NULL) {
                orig_lcomp = talloc_strdup(ctx, last_slash+1);
        } else {
                orig_lcomp = talloc_strdup(ctx, filename_in);
        }
-       /* We're done with any temp names here. */
-       TALLOC_FREE(smb_fname);
-       TALLOC_FREE(fname);
        if (orig_lcomp == NULL) {
                return NULL;
        }
@@ -1957,188 +1914,6 @@ char *get_original_lcomp(TALLOC_CTX *ctx,
        return orig_lcomp;
 }
 
-/**
- * Go through all the steps to validate a filename.
- *
- * @param ctx          talloc_ctx to allocate memory with.
- * @param conn         connection struct for vfs calls.
- * @param smbreq       SMB request if we're using privileges.
- * @param name_in      The unconverted name.
- * @param ucf_flags    flags to pass through to unix_convert().
- * @param twrp         Optional VSS time
- * @param p_cont_wcard If not NULL, will be set to true if the dfs path
- *                     resolution detects a wildcard.
- * @param _smb_fname   The final converted name will be allocated if the
- *                     return is NT_STATUS_OK.
- *
- * @return NT_STATUS_OK if all operations completed successfully, appropriate
- *        error otherwise.
- */
-NTSTATUS filename_convert(TALLOC_CTX *ctx,
-                         connection_struct *conn,
-                         const char *name_in,
-                         uint32_t ucf_flags,
-                         NTTIME twrp,
-                         struct smb_filename **_smb_fname)
-{
-       struct smb_filename *smb_fname = NULL;
-       NTSTATUS status;
-
-       *_smb_fname = NULL;
-
-       if (ucf_flags & UCF_DFS_PATHNAME) {
-               char *fname = NULL;
-               NTTIME dfs_twrp = 0;
-               status = dfs_redirect(ctx, conn,
-                               name_in,
-                               ucf_flags,
-                               !conn->sconn->using_smb2,
-                               &dfs_twrp,
-                               &fname);
-               if (!NT_STATUS_IS_OK(status)) {
-                       DBG_DEBUG("dfs_redirect "
-                               "failed for name %s with %s\n",
-                               name_in,
-                               nt_errstr(status));
-                       return status;
-               }
-               name_in = fname;
-               ucf_flags &= ~UCF_DFS_PATHNAME;
-               if (twrp == 0 && dfs_twrp != 0) {
-                       twrp = dfs_twrp;
-               }
-       }
-
-       if (is_fake_file_path(name_in)) {
-               smb_fname = synthetic_smb_fname_split(ctx,
-                                       name_in,
-                                       (ucf_flags & UCF_POSIX_PATHNAMES));
-               if (smb_fname == NULL) {
-                       return NT_STATUS_NO_MEMORY;
-               }
-               smb_fname->st = (SMB_STRUCT_STAT) { .st_ex_nlink = 1 };
-               smb_fname->st.st_ex_btime = (struct timespec){0, 
SAMBA_UTIME_OMIT};
-               smb_fname->st.st_ex_atime = (struct timespec){0, 
SAMBA_UTIME_OMIT};
-               smb_fname->st.st_ex_mtime = (struct timespec){0, 
SAMBA_UTIME_OMIT};
-               smb_fname->st.st_ex_ctime = (struct timespec){0, 
SAMBA_UTIME_OMIT};
-
-               *_smb_fname = smb_fname;
-               return NT_STATUS_OK;
-       }
-
-       status = unix_convert(ctx, conn, name_in, twrp, &smb_fname, ucf_flags);
-       if (!NT_STATUS_IS_OK(status)) {
-               DBG_DEBUG("unix_convert failed "
-                       "for name %s with %s\n",
-                       name_in,
-                       nt_errstr(status));
-               return status;
-       }
-
-       if ((ucf_flags & UCF_POSIX_PATHNAMES) &&
-           VALID_STAT(smb_fname->st) &&
-           S_ISLNK(smb_fname->st.st_ex_mode))
-       {
-               status = check_veto_path(conn, smb_fname);
-               if (!NT_STATUS_IS_OK(status)) {
-                       TALLOC_FREE(smb_fname);
-                       return status;
-               }
-       } else {
-               status = check_name(conn, smb_fname);
-       }
-       if (!NT_STATUS_IS_OK(status)) {
-               DBG_NOTICE("check_name failed "
-                       "for name %s with %s\n",
-                       smb_fname_str_dbg(smb_fname),
-                       nt_errstr(status));
-               TALLOC_FREE(smb_fname);
-               return status;
-       }
-
-       if (!VALID_STAT(smb_fname->st)) {
-               DBG_DEBUG("[%s] does not exist, skipping pathref fsp\n",
-                         smb_fname_str_dbg(smb_fname));
-               *_smb_fname = smb_fname;
-               return NT_STATUS_OK;
-       }
-
-       status = openat_pathref_fsp(conn->cwd_fsp, smb_fname);
-       if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
-               /*
-                * We deal with symlinks here as we do in
-                * SMB_VFS_CREATE_FILE(): return success for POSIX clients with
-                * the notable difference that there will be no fsp in
-                * smb_fname->fsp.
-                *
-                * For Windows (non POSIX) clients fail with
-                * NT_STATUS_OBJECT_NAME_NOT_FOUND.
-                */
-               if (smb_fname->flags & SMB_FILENAME_POSIX_PATH &&
-                   S_ISLNK(smb_fname->st.st_ex_mode))
-               {
-                       status = NT_STATUS_OK;
-               }
-       }
-       if (!NT_STATUS_IS_OK(status)) {
-               DBG_DEBUG("openat_pathref_fsp [%s] failed: %s\n",
-                         smb_fname_str_dbg(smb_fname),
-                         nt_errstr(status));
-               return status;
-       }
-
-       *_smb_fname = smb_fname;
-       return status;
-}
-
-/*
- * Strip a @GMT component from an SMB1-DFS path. Could be anywhere
- * in the path.
- */
-
-static char *strip_gmt_from_raw_dfs(TALLOC_CTX *ctx,
-                                   const char *name_in,
-                                   bool posix_pathnames,
-                                   NTTIME *_twrp)
-{
-       NTSTATUS status;
-       struct smb_filename *smb_fname = NULL;
-       char *name_out = NULL;
-
-       smb_fname = synthetic_smb_fname(ctx,
-                                       name_in,
-                                       NULL,
-                                       NULL,
-                                       0,
-                                       0);
-       if (smb_fname == NULL) {
-               return NULL;
-       }
-       if (!posix_pathnames) {
-               /*
-                * Raw DFS names are still '\\' separated.
-                * canonicalize_snapshot_path() only works
-                * on '/' separated paths. Convert.
-                */
-               string_replace(smb_fname->base_name, '\\', '/');
-       }
-       status = canonicalize_snapshot_path(smb_fname,
-                                           UCF_GMT_PATHNAME,
-                                           0);
-       if (!NT_STATUS_IS_OK(status)) {
-               TALLOC_FREE(smb_fname);
-               return NULL;
-       }
-       if (!posix_pathnames) {
-               /* Replace as raw DFS names. */
-               string_replace(smb_fname->base_name, '/', '\\');
-       }
-       name_out = talloc_strdup(ctx, smb_fname->base_name);
-       *_twrp = smb_fname->twrp;
-       TALLOC_FREE(smb_fname);
-       return name_out;
-}
-
 /*
  * Deal with the SMB1 semantics of sending a pathname with a
  * wildcard as the terminal component for a SMB1search or
@@ -2147,8 +1922,9 @@ static char *strip_gmt_from_raw_dfs(TALLOC_CTX *ctx,
 
 NTSTATUS filename_convert_smb1_search_path(TALLOC_CTX *ctx,
                                           connection_struct *conn,
-                                          const char *name_in,
+                                          char *name_in,
                                           uint32_t ucf_flags,
+                                          struct files_struct **_dirfsp,
                                           struct smb_filename **_smb_fname_out,
                                           char **_mask_out)
 {
@@ -2158,24 +1934,23 @@ NTSTATUS filename_convert_smb1_search_path(TALLOC_CTX 
*ctx,
        struct smb_filename *smb_fname = NULL;
        bool posix_pathnames = (ucf_flags & UCF_POSIX_PATHNAMES);
        NTTIME twrp = 0;
-       TALLOC_CTX *frame = talloc_stackframe();
 
        *_smb_fname_out = NULL;
+       *_dirfsp = NULL;
        *_mask_out = NULL;
 
        DBG_DEBUG("name_in: %s\n", name_in);
 
+       if (ucf_flags & UCF_GMT_PATHNAME) {
+               extract_snapshot_token(name_in, ucf_flags, &twrp);
+               ucf_flags &= ~UCF_GMT_PATHNAME;
+       }
+
        if (ucf_flags & UCF_DFS_PATHNAME) {
                /*
                 * We've been given a raw DFS pathname.
-                * In Windows mode this is separated by '\\'
-                * characters.
-                *
-                * We need to remove the last component
-                * which must be a wildcard before passing
-                * to dfs_redirect(). But the last component
-                * may also be a @GMT- token so we have to
-                * remove that first.
+                * In Windows mode this is separated by '\'
+                * characters, in POSIX by '/' characters.
                 */
                char path_sep = posix_pathnames ? '/' : '\\';
                char *fname = NULL;
@@ -2183,17 +1958,8 @@ NTSTATUS filename_convert_smb1_search_path(TALLOC_CTX 
*ctx,
                char *last_component = NULL;
 
                /* Work on a copy of name_in. */
-               if (ucf_flags & UCF_GMT_PATHNAME) {


-- 
Samba Shared Repository

Reply via email to