The branch, master has been updated
       via  1c8ea2448ea s3: smbd: In SMB1 call_trans2findnext() add and use a 
helper variable to ensure we don't call mangle_is_mangled() with a posix name.
       via  761c9190454 s3: smbd: In unlink_internals() ensure we never call 
mangle_is_mangled for a posix path.
       via  e2c45a09263 s3: smbd: SMB1 reply_copy(). Posix pathnames always 
means case_sensitive = true.
       via  e3c40250fb1 s3: smbd: SMB1 reply_copy(). Posix pathnames should 
never call into mangle_is_mangled().
       via  d0d8f32d8f7 s3: smbd: In SMB1 reply_copy(), make 
req->posix_pathnames a helper variable.
       via  826ae5c8069 s3: smbd: Add and use helper variables for 
case_sensitive, case_preserve, short_case_preserve to rename_internals().
       via  395acac7b46 s3: smbd: Ensure we never call mangle_is_mangled() for 
a posix path.
       via  23be0565dc7 s3: smbd: Add and use helper variable posix_pathname in 
rename_internals().
       via  026b4318967 s3: smbd: Add and use helper variables case_sensitive, 
case_preserve in rename_internals_fsp().
       via  836d6f8a226 s3: smbd: Add and use case_sensitive helper variable to 
unlink_internals().
       via  89d986ec130 s3: smbd: Use a helper variable in 
smbd_smb2_query_directory_send().
       via  db6902a3c58 s3: smbd: In open_file() use the helper variable to 
select correct case_sensitive setting to is_in_path().
       via  51b582546b5 s3: smbd: In open_file(), use a helper variable instead 
of always checking sp->posix_flags & FSP_POSIX_FLAGS_OPEN.
       via  df8abb5aa76 s3: smbd: Use dptr_case_sensitive() in directory 
listing code.
       via  e163f22e81d s3: smbd: Add dptr_case_sensitive(). Not yet used.
       via  ab1e97f87b1 s3: smbd: In OpenDir_fsp(), set dir_hnd->case_sensitive 
to true if FSP_POSIX_FLAGS_OPEN is set.
       via  ede3a45dfca s3: smbd: Use dir_hnd->case_sensitive instead of 
conn->case_sensitive.
       via  af35c684a39 s3: smbd: Add case_sensitive to struct smb_Dir.
       via  1b130decc2b s3: smbd: Use state->case_sensitive instead of 
state->conn->case_sensitive.
       via  1240f741e66 s3: smbd: Add 'bool case_sensitive' to struct 
smbd_dirptr_lanman2_state.
       via  1cc5a394209 s3: smbd: In unix_convert() component_was_mangled is 
always false for posix.
       via  3911ca59f48 s3: smbd: In unix_convert_step_search_fail() ensure 
posix names don't call into name mangling functions.
       via  d650d9ad8ae s3: smbd: Add comment to unix_convert() explaining why 
posix never calls into mangle_is_mangled() here.
       via  77f54fc14f2 s3: smbd: Turn on case sensitivity for a posix filename 
lookup.
       via  f4354571d61 s3: smbd: Use state->short_case_preserve instead of 
state->conn->short_case_preserve.
       via  598c07b106e s3: smbd: Use state->case_preserve instead of 
state->conn->case_preserve.
       via  2910657694e s3: smbd: Use state->case_sensitive instead of 
state->conn->case_sensitive.
       via  35ee8a7b6c7 s3: smbd: Add case_sensitive, case_preserve, 
short_case_preserve to state struct.
       via  b460c534272 s3: smbd: Ensure normalize_filename_case() doesn't 
modify posix names.
       via  86e42fb4841 s3: smbd: Add ucf_flags parameter to 
normalize_filename_case().
       via  3f0935b369e s3: smbd: get_real_filename() is actually static to 
filename.c
      from  a8c0c2c9e3a smbd: get rid of get_file_handle_for_metadata()

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


- Log -----------------------------------------------------------------
commit 1c8ea2448eaacb84c1c134e9597a5f873779b0a4
Author: Jeremy Allison <j...@samba.org>
Date:   Tue Nov 9 14:57:18 2021 -0800

    s3: smbd: In SMB1 call_trans2findnext() add and use a helper variable to 
ensure we don't call mangle_is_mangled() with a posix name.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>
    
    Autobuild-User(master): Ralph Böhme <s...@samba.org>
    Autobuild-Date(master): Tue Nov 16 21:06:38 UTC 2021 on sn-devel-184

commit 761c9190454ce1704a041275723e23025bf62cf3
Author: Jeremy Allison <j...@samba.org>
Date:   Tue Nov 9 14:55:05 2021 -0800

    s3: smbd: In unlink_internals() ensure we never call mangle_is_mangled for 
a posix path.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit e2c45a092639c56d4a6b615fecef6d85f13b87eb
Author: Jeremy Allison <j...@samba.org>
Date:   Tue Nov 9 14:28:34 2021 -0800

    s3: smbd: SMB1 reply_copy(). Posix pathnames always means case_sensitive = 
true.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit e3c40250fb1afafe833a02ff65474a76ea6e41eb
Author: Jeremy Allison <j...@samba.org>
Date:   Tue Nov 9 14:23:22 2021 -0800

    s3: smbd: SMB1 reply_copy(). Posix pathnames should never call into 
mangle_is_mangled().
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit d0d8f32d8f764bb2c9c00a3eda36367a7cd5a08f
Author: Jeremy Allison <j...@samba.org>
Date:   Tue Nov 9 14:21:41 2021 -0800

    s3: smbd: In SMB1 reply_copy(), make req->posix_pathnames a helper variable.
    
    I need to use it elsewhere in here.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit 826ae5c80694093f65809b314c72fd5e1cb45b47
Author: Jeremy Allison <j...@samba.org>
Date:   Mon Nov 8 16:37:26 2021 -0800

    s3: smbd: Add and use helper variables for case_sensitive, case_preserve, 
short_case_preserve to rename_internals().
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit 395acac7b465c5b8e9461d42f50e860003a98bad
Author: Jeremy Allison <j...@samba.org>
Date:   Mon Nov 8 16:31:40 2021 -0800

    s3: smbd: Ensure we never call mangle_is_mangled() for a posix path.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit 23be0565dc738e98d1619435dffb716726b62214
Author: Jeremy Allison <j...@samba.org>
Date:   Mon Nov 8 16:30:27 2021 -0800

    s3: smbd: Add and use helper variable posix_pathname in rename_internals().
    
    We're going to re-use it inside this function.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit 026b4318967eb923b8b5666e7b8e977b43b2dbcc
Author: Jeremy Allison <j...@samba.org>
Date:   Mon Nov 8 16:27:19 2021 -0800

    s3: smbd: Add and use helper variables case_sensitive, case_preserve in 
rename_internals_fsp().
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit 836d6f8a22696e1de4009dbde46bf355261f8e7a
Author: Jeremy Allison <j...@samba.org>
Date:   Mon Nov 8 16:22:50 2021 -0800

    s3: smbd: Add and use case_sensitive helper variable to unlink_internals().
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit 89d986ec13085f416e24276375cc1d2353077010
Author: Jeremy Allison <j...@samba.org>
Date:   Mon Nov 8 15:59:51 2021 -0800

    s3: smbd: Use a helper variable in smbd_smb2_query_directory_send().
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit db6902a3c5889112b5349b28b10df813fc747525
Author: Jeremy Allison <j...@samba.org>
Date:   Mon Nov 8 14:10:59 2021 -0800

    s3: smbd: In open_file() use the helper variable to select correct 
case_sensitive setting to is_in_path().
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit 51b582546b5d613a108f8b5a3ef4b7a1cd99df86
Author: Jeremy Allison <j...@samba.org>
Date:   Mon Nov 8 14:09:53 2021 -0800

    s3: smbd: In open_file(), use a helper variable instead of always checking 
sp->posix_flags & FSP_POSIX_FLAGS_OPEN.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit df8abb5aa760363391edd2def3f2edb667d66ba2
Author: Jeremy Allison <j...@samba.org>
Date:   Mon Nov 8 11:25:26 2021 -0800

    s3: smbd: Use dptr_case_sensitive() in directory listing code.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit e163f22e81d082e2ca161ee032eb14083154b70f
Author: Jeremy Allison <j...@samba.org>
Date:   Mon Nov 8 11:21:03 2021 -0800

    s3: smbd: Add dptr_case_sensitive(). Not yet used.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit ab1e97f87b10596a83794579ac0bfb4be39eded2
Author: Jeremy Allison <j...@samba.org>
Date:   Fri Nov 5 16:43:14 2021 -0700

    s3: smbd: In OpenDir_fsp(), set dir_hnd->case_sensitive to true if 
FSP_POSIX_FLAGS_OPEN is set.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit ede3a45dfcaa91bbf8c64683ec51eeba9054cfbb
Author: Jeremy Allison <j...@samba.org>
Date:   Fri Oct 15 16:52:10 2021 -0700

    s3: smbd: Use dir_hnd->case_sensitive instead of conn->case_sensitive.
    
    No logic change.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit af35c684a39ed59a750a03b71ef78522fc14ce13
Author: Jeremy Allison <j...@samba.org>
Date:   Fri Oct 15 16:48:03 2021 -0700

    s3: smbd: Add case_sensitive to struct smb_Dir.
    
    Not yet used.
    
    This allows it to be independent of conn settings on
    a per-handle-basis for SMB2 posix.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit 1b130decc2bb17b058d57bbcd46babb5b2b939a6
Author: Jeremy Allison <j...@samba.org>
Date:   Fri Nov 5 16:55:06 2021 -0700

    s3: smbd: Use state->case_sensitive instead of state->conn->case_sensitive.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit 1240f741e6672a0bef036c8d1b1f89507ec0b599
Author: Jeremy Allison <j...@samba.org>
Date:   Fri Nov 5 16:53:26 2021 -0700

    s3: smbd: Add 'bool case_sensitive' to struct smbd_dirptr_lanman2_state.
    
    Initialize from conn->case_sensitive. Not yet used.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit 1cc5a394209f018f4c41d07bc0c790fb2bd5b29e
Author: Jeremy Allison <j...@samba.org>
Date:   Fri Oct 15 16:26:24 2021 -0700

    s3: smbd: In unix_convert() component_was_mangled is always false for posix.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit 3911ca59f48f5d7445195b09ba61f97374370f85
Author: Jeremy Allison <j...@samba.org>
Date:   Fri Oct 15 16:20:34 2021 -0700

    s3: smbd: In unix_convert_step_search_fail() ensure posix names don't call 
into name mangling functions.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit d650d9ad8aef9d39ed8eb960ec6d5fe409c3f6b3
Author: Jeremy Allison <j...@samba.org>
Date:   Fri Oct 15 15:03:16 2021 -0700

    s3: smbd: Add comment to unix_convert() explaining why posix never calls 
into mangle_is_mangled() here.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit 77f54fc14f2dcf9da6a68dd8880f0d31ac33c860
Author: Jeremy Allison <j...@samba.org>
Date:   Fri Oct 15 13:32:27 2021 -0700

    s3: smbd: Turn on case sensitivity for a posix filename lookup.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit f4354571d615c5b6ea64ed20cb880049c1b49053
Author: Jeremy Allison <j...@samba.org>
Date:   Fri Oct 15 12:08:25 2021 -0700

    s3: smbd: Use state->short_case_preserve instead of 
state->conn->short_case_preserve.
    
    No logic changes.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit 598c07b106edf47febc2319f923931542fa1c519
Author: Jeremy Allison <j...@samba.org>
Date:   Fri Oct 15 12:07:05 2021 -0700

    s3: smbd: Use state->case_preserve instead of state->conn->case_preserve.
    
    No logic change.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit 2910657694ed6843702b1f901674e0568e64846e
Author: Jeremy Allison <j...@samba.org>
Date:   Fri Oct 15 12:02:33 2021 -0700

    s3: smbd: Use state->case_sensitive instead of state->conn->case_sensitive.
    
    No logic change.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit 35ee8a7b6c7e68a6a48e2ecafae78d9f6f901040
Author: Jeremy Allison <j...@samba.org>
Date:   Fri Oct 15 11:59:56 2021 -0700

    s3: smbd: Add case_sensitive, case_preserve, short_case_preserve to state 
struct.
    
    Not yet used.
    
    This allows them to be independent of conn settings on
    a handle-basis for posix.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit b460c534272271b3f6c673ef544b7a5549ad11bb
Author: Jeremy Allison <j...@samba.org>
Date:   Fri Oct 15 11:54:38 2021 -0700

    s3: smbd: Ensure normalize_filename_case() doesn't modify posix names.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit 86e42fb484147ed687086cf3fcf8cd8eb07b7164
Author: Jeremy Allison <j...@samba.org>
Date:   Fri Sep 17 17:02:06 2021 -0700

    s3: smbd: Add ucf_flags parameter to normalize_filename_case().
    
    Not yet used.
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

commit 3f0935b369e79d67f7a42b9531b2c123f2410ccc
Author: Jeremy Allison <j...@samba.org>
Date:   Fri Oct 15 14:04:07 2021 -0700

    s3: smbd: get_real_filename() is actually static to filename.c
    
    Signed-off-by: Jeremy Allison <j...@samba.org>
    Reviewed-by: Ralph Boehme <s...@samba.org>

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

Summary of changes:
 source3/smbd/dir.c                  | 19 +++++++--
 source3/smbd/filename.c             | 79 +++++++++++++++++++++++++++++--------
 source3/smbd/open.c                 |  7 ++--
 source3/smbd/proto.h                |  6 +--
 source3/smbd/reply.c                | 34 ++++++++++++----
 source3/smbd/smb2_query_directory.c |  3 +-
 source3/smbd/trans2.c               | 19 +++++----
 7 files changed, 123 insertions(+), 44 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/smbd/dir.c b/source3/smbd/dir.c
index 856a3625a75..3bf2f79f3fa 100644
--- a/source3/smbd/dir.c
+++ b/source3/smbd/dir.c
@@ -59,6 +59,7 @@ struct smb_Dir {
        struct name_cache_entry *name_cache;
        unsigned int name_cache_index;
        unsigned int file_number;
+       bool case_sensitive;
        files_struct *fsp; /* Back pointer to containing fsp, only
                              set from OpenDir_fsp(). */
 };
@@ -396,6 +397,11 @@ void dptr_set_priv(struct dptr_struct *dptr)
        dptr->priv = true;
 }
 
+bool dptr_case_sensitive(struct dptr_struct *dptr)
+{
+       return dptr->dir_hnd->case_sensitive;
+}
+
 /****************************************************************************
  Return the next visible file name, skipping veto'd and invisible files.
 ****************************************************************************/
@@ -476,7 +482,7 @@ static char *dptr_ReadDirName(TALLOC_CTX *ctx,
         * providing case sensitive semantics or the underlying
         * filesystem is case sensitive.
         */
-       if (dptr->conn->case_sensitive ||
+       if (dptr->dir_hnd->case_sensitive ||
            !(dptr->conn->fs_capabilities & FILE_CASE_SENSITIVE_SEARCH))
        {
                goto clean;
@@ -1549,6 +1555,11 @@ static struct smb_Dir *OpenDir_fsp(TALLOC_CTX *mem_ctx, 
connection_struct *conn,
                goto fail;
        }
        dir_hnd->fsp = fsp;
+       if (fsp->posix_flags & FSP_POSIX_FLAGS_OPEN) {
+               dir_hnd->case_sensitive = true;
+       } else {
+               dir_hnd->case_sensitive = conn->case_sensitive;
+       }
 
        talloc_set_destructor(dir_hnd, smb_Dir_destructor);
 
@@ -1715,7 +1726,7 @@ static bool SearchDir(struct smb_Dir *dir_hnd, const char 
*name, long *poffset)
        if (dir_hnd->name_cache_size && dir_hnd->name_cache) {
                for (i = dir_hnd->name_cache_index; i >= 0; i--) {
                        struct name_cache_entry *e = &dir_hnd->name_cache[i];
-                       if (e->name && (conn->case_sensitive ? (strcmp(e->name, 
name) == 0) : strequal(e->name, name))) {
+                       if (e->name && (dir_hnd->case_sensitive ? 
(strcmp(e->name, name) == 0) : strequal(e->name, name))) {
                                *poffset = e->offset;
                                SeekDir(dir_hnd, e->offset);
                                return True;
@@ -1724,7 +1735,7 @@ static bool SearchDir(struct smb_Dir *dir_hnd, const char 
*name, long *poffset)
                for (i = dir_hnd->name_cache_size - 1;
                                i > dir_hnd->name_cache_index; i--) {
                        struct name_cache_entry *e = &dir_hnd->name_cache[i];
-                       if (e->name && (conn->case_sensitive ? (strcmp(e->name, 
name) == 0) : strequal(e->name, name))) {
+                       if (e->name && (dir_hnd->case_sensitive ? 
(strcmp(e->name, name) == 0) : strequal(e->name, name))) {
                                *poffset = e->offset;
                                SeekDir(dir_hnd, e->offset);
                                return True;
@@ -1737,7 +1748,7 @@ static bool SearchDir(struct smb_Dir *dir_hnd, const char 
*name, long *poffset)
        dir_hnd->file_number = 0;
        *poffset = START_OF_DIRECTORY_OFFSET;
        while ((entry = ReadDirName(dir_hnd, poffset, NULL, &talloced))) {
-               if (conn->case_sensitive ? (strcmp(entry, name) == 0) : 
strequal(entry, name)) {
+               if (dir_hnd->case_sensitive ? (strcmp(entry, name) == 0) : 
strequal(entry, name)) {
                        TALLOC_FREE(talloced);
                        return True;
                }
diff --git a/source3/smbd/filename.c b/source3/smbd/filename.c
index eec7877b38b..6ea0687d763 100644
--- a/source3/smbd/filename.c
+++ b/source3/smbd/filename.c
@@ -30,6 +30,12 @@
 #include "smbd/smbd.h"
 #include "smbd/globals.h"
 
+static int get_real_filename(connection_struct *conn,
+                            struct smb_filename *path,
+                            const char *name,
+                            TALLOC_CTX *mem_ctx,
+                            char **found_name);
+
 uint32_t ucf_flags_from_smb_request(struct smb_request *req)
 {
        uint32_t ucf_flags = 0;
@@ -458,10 +464,18 @@ NTSTATUS canonicalize_snapshot_path(struct smb_filename 
*smb_fname,
  * Performs an in-place case conversion guaranteed to stay the same size.
  */
 
-static NTSTATUS normalize_filename_case(connection_struct *conn, char 
*filename)
+static NTSTATUS normalize_filename_case(connection_struct *conn,
+                                       char *filename,
+                                       uint32_t ucf_flags)
 {
        bool ok;
 
+       if (ucf_flags & UCF_POSIX_PATHNAMES) {
+               /*
+                * POSIX never normalizes filename case.
+                */
+               return NT_STATUS_OK;
+       }
        if (!conn->case_sensitive) {
                return NT_STATUS_OK;
        }
@@ -526,6 +540,9 @@ struct uc_state {
        bool posix_pathnames;
        bool allow_wcard_last_component;
        bool done;
+       bool case_sensitive;
+       bool case_preserve;
+       bool short_case_preserve;
 };
 
 static NTSTATUS unix_convert_step_search_fail(struct uc_state *state)
@@ -602,6 +619,13 @@ static NTSTATUS unix_convert_step_search_fail(struct 
uc_state *state)
                return map_nt_error_from_unix(errno);
        }
 
+       /*
+        * POSIX pathnames must never call into mangling.
+        */
+       if (state->posix_pathnames) {
+               goto done;
+       }
+
        /*
         * Just the last part of the name doesn't exist.
         * We need to strupper() or strlower() it as
@@ -609,10 +633,10 @@ static NTSTATUS unix_convert_step_search_fail(struct 
uc_state *state)
         * purposes. Fix inspired by
         * Thomas Neumann <t.neum...@iku-ag.de>.
         */
-       if (!state->conn->case_preserve ||
+       if (!state->case_preserve ||
            (mangle_is_8_3(state->name, false,
                           state->conn->params) &&
-            !state->conn->short_case_preserve)) {
+            !state->short_case_preserve)) {
                if (!strnorm(state->name,
                             lp_default_case(SNUM(state->conn)))) {
                        DBG_DEBUG("strnorm %s failed\n",
@@ -655,6 +679,8 @@ static NTSTATUS unix_convert_step_search_fail(struct 
uc_state *state)
                state->end = state->name + strlen(state->name);
        }
 
+  done:
+
        DBG_DEBUG("New file [%s]\n", state->name);
        state->done = true;
        return NT_STATUS_OK;
@@ -931,7 +957,7 @@ static NTSTATUS unix_convert_step(struct uc_state *state)
                stat_cache_add(state->orig_path,
                               state->dirpath,
                               state->smb_fname->twrp,
-                              state->conn->case_sensitive);
+                              state->case_sensitive);
        }
 
        /*
@@ -963,10 +989,20 @@ NTSTATUS unix_convert(TALLOC_CTX *mem_ctx,
                .ucf_flags = ucf_flags,
                .posix_pathnames = (ucf_flags & UCF_POSIX_PATHNAMES),
                .allow_wcard_last_component = (ucf_flags & 
UCF_ALWAYS_ALLOW_WCARD_LCOMP),
+               .case_sensitive = conn->case_sensitive,
+               .case_preserve = conn->case_preserve,
+               .short_case_preserve = conn->short_case_preserve,
        };
 
        *smb_fname_out = NULL;
 
+       if (state->posix_pathnames) {
+               /* POSIX means ignore case settings on share. */
+               state->case_sensitive = true;
+               state->case_preserve = true;
+               state->short_case_preserve = true;
+       }
+
        state->smb_fname = talloc_zero(state->mem_ctx, struct smb_filename);
        if (state->smb_fname == NULL) {
                return NT_STATUS_NO_MEMORY;
@@ -1053,7 +1089,9 @@ NTSTATUS unix_convert(TALLOC_CTX *mem_ctx,
         * the man page. Thanks to j...@samba.org for finding this. JRA.
         */
 
-       status = normalize_filename_case(state->conn, 
state->smb_fname->base_name);
+       status = normalize_filename_case(state->conn,
+                                        state->smb_fname->base_name,
+                                        ucf_flags);
        if (!NT_STATUS_IS_OK(status)) {
                DBG_ERR("normalize_filename_case %s failed\n",
                                state->smb_fname->base_name);
@@ -1123,7 +1161,7 @@ NTSTATUS unix_convert(TALLOC_CTX *mem_ctx,
         * added and verified in build_stream_path().
         */
 
-       if (!state->conn->case_sensitive ||
+       if (!state->case_sensitive ||
            !(state->conn->fs_capabilities & FILE_CASE_SENSITIVE_SEARCH))
        {
                bool found;
@@ -1191,7 +1229,7 @@ NTSTATUS unix_convert(TALLOC_CTX *mem_ctx,
                        stat_cache_add(state->orig_path,
                                       state->smb_fname->base_name,
                                       state->smb_fname->twrp,
-                                      state->conn->case_sensitive);
+                                      state->case_sensitive);
                        DBG_DEBUG("Conversion of base_name finished "
                                  "[%s] -> [%s]\n",
                                  state->orig_path, 
state->smb_fname->base_name);
@@ -1231,9 +1269,12 @@ NTSTATUS unix_convert(TALLOC_CTX *mem_ctx,
                 * A special case - if we don't have any wildcards or mangling 
chars and are case
                 * sensitive or the underlying filesystem is case insensitive 
then searching
                 * won't help.
+                *
+                * NB. As POSIX sets state->case_sensitive as
+                * true we will never call into mangle_is_mangled() here.
                 */
 
-               if ((state->conn->case_sensitive || 
!(state->conn->fs_capabilities &
+               if ((state->case_sensitive || !(state->conn->fs_capabilities &
                                        FILE_CASE_SENSITIVE_SEARCH)) &&
                                !mangle_is_mangled(state->smb_fname->base_name, 
state->conn->params)) {
 
@@ -1315,7 +1356,13 @@ NTSTATUS unix_convert(TALLOC_CTX *mem_ctx,
         * just a component. JRA.
         */
 
-       if (mangle_is_mangled(state->name, state->conn->params)) {
+       if (state->posix_pathnames) {
+               /*
+                * POSIX names are never mangled and we must not
+                * call into mangling functions.
+                */
+               state->component_was_mangled = false;
+       } else if (mangle_is_mangled(state->name, state->conn->params)) {
                state->component_was_mangled = true;
        }
 
@@ -1351,7 +1398,7 @@ NTSTATUS unix_convert(TALLOC_CTX *mem_ctx,
                stat_cache_add(state->orig_path,
                               state->smb_fname->base_name,
                               state->smb_fname->twrp,
-                              state->conn->case_sensitive);
+                              state->case_sensitive);
        }
 
        /*
@@ -1685,11 +1732,11 @@ int get_real_filename_full_scan(connection_struct *conn,
  fallback.
 ****************************************************************************/
 
-int get_real_filename(connection_struct *conn,
-                     struct smb_filename *path,
-                     const char *name,
-                     TALLOC_CTX *mem_ctx,
-                     char **found_name)
+static int get_real_filename(connection_struct *conn,
+                            struct smb_filename *path,
+                            const char *name,
+                            TALLOC_CTX *mem_ctx,
+                            char **found_name)
 {
        int ret;
        bool mangled;
@@ -1907,7 +1954,7 @@ char *get_original_lcomp(TALLOC_CTX *ctx,
        if (orig_lcomp == NULL) {
                return NULL;
        }
-       status = normalize_filename_case(conn, orig_lcomp);
+       status = normalize_filename_case(conn, orig_lcomp, ucf_flags);
        if (!NT_STATUS_IS_OK(status)) {
                TALLOC_FREE(orig_lcomp);
                return NULL;
diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index df24f8d1b0e..7f1aedbd1fb 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -1283,6 +1283,7 @@ static NTSTATUS open_file(files_struct *fsp,
        bool creating = !file_existed && (flags & O_CREAT);
        bool truncating = (flags & O_TRUNC);
        bool open_fd = false;
+       bool posix_open = (fsp->posix_flags & FSP_POSIX_FLAGS_OPEN);
 
        /*
         * Catch early an attempt to open an existing
@@ -1531,7 +1532,7 @@ static NTSTATUS open_file(files_struct *fsp,
                }
 
                if (S_ISLNK(smb_fname->st.st_ex_mode) &&
-                   !(fsp->posix_flags & FSP_POSIX_FLAGS_OPEN))
+                   !posix_open)
                {
                        /*
                         * Don't allow stat opens on symlinks directly unless
@@ -1573,7 +1574,7 @@ static NTSTATUS open_file(files_struct *fsp,
                                                      access_mask);
 
                if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND) &&
-                               (fsp->posix_flags & FSP_POSIX_FLAGS_OPEN) &&
+                               posix_open &&
                                S_ISLNK(smb_fname->st.st_ex_mode)) {
                        /* This is a POSIX stat open for delete
                         * or rename on a symlink that points
@@ -1607,7 +1608,7 @@ static NTSTATUS open_file(files_struct *fsp,
        fsp->fsp_flags.is_directory = false;
        if (conn->aio_write_behind_list &&
            is_in_path(smb_fname->base_name, conn->aio_write_behind_list,
-                      conn->case_sensitive)) {
+                      posix_open ? true: conn->case_sensitive)) {
                fsp->fsp_flags.aio_write_behind = true;
        }
 
diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h
index bf7401f5191..ea86515a925 100644
--- a/source3/smbd/proto.h
+++ b/source3/smbd/proto.h
@@ -208,6 +208,7 @@ bool dptr_has_wild(struct dptr_struct *dptr);
 int dptr_dnum(struct dptr_struct *dptr);
 bool dptr_get_priv(struct dptr_struct *dptr);
 void dptr_set_priv(struct dptr_struct *dptr);
+bool dptr_case_sensitive(struct dptr_struct *dptr);
 bool dptr_SearchDir(struct dptr_struct *dptr, const char *name, long *poffset, 
SMB_STRUCT_STAT *pst);
 bool dptr_fill(struct smbd_server_connection *sconn,
               char *buf1,unsigned int key);
@@ -363,11 +364,6 @@ NTSTATUS check_name(connection_struct *conn,
 NTSTATUS canonicalize_snapshot_path(struct smb_filename *smb_fname,
                                    uint32_t ucf_flags,
                                    NTTIME twrp);
-int get_real_filename(connection_struct *conn,
-                     struct smb_filename *path,
-                     const char *name,
-                     TALLOC_CTX *mem_ctx,
-                     char **found_name);
 int get_real_filename_full_scan(connection_struct *conn,
                                const char *path,
                                const char *name,
diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index 6e576552fcd..b0101f667a8 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -3289,6 +3289,7 @@ NTSTATUS unlink_internals(connection_struct *conn,
        struct smb_filename *smb_fname_dir = NULL;
        TALLOC_CTX *ctx = talloc_tos();
        int ret;
+       bool posix_pathname = (smb_fname->flags & SMB_FILENAME_POSIX_PATH);
 
        /* Split up the directory from the filename/mask. */
        status = split_fname_dir_mask(ctx, smb_fname->base_name,
@@ -3307,6 +3308,7 @@ NTSTATUS unlink_internals(connection_struct *conn,
         */
 
        if (!VALID_STAT(smb_fname->st) &&
+           !posix_pathname &&
            mangle_is_mangled(fname_mask, conn->params)) {
                char *new_mask = NULL;
                mangle_lookup_name_from_8_3(ctx, fname_mask,
@@ -3359,6 +3361,9 @@ NTSTATUS unlink_internals(connection_struct *conn,
                long offset = 0;
                const char *dname = NULL;
                char *talloced = NULL;
+               bool case_sensitive =
+                       (smb_fname->flags & SMB_FILENAME_POSIX_PATH) ?
+                       true : conn->case_sensitive;
 
                if ((dirtype & SAMBA_ATTRIBUTES_MASK) == 
FILE_ATTRIBUTE_DIRECTORY) {
                        status = NT_STATUS_OBJECT_NAME_INVALID;
@@ -3427,7 +3432,7 @@ NTSTATUS unlink_internals(connection_struct *conn,
                        }
 
                        if(!mask_match(dname, fname_mask,
-                                      conn->case_sensitive)) {
+                                      case_sensitive)) {
                                TALLOC_FREE(frame);
                                TALLOC_FREE(talloced);
                                continue;
@@ -7579,6 +7584,10 @@ NTSTATUS rename_internals_fsp(connection_struct *conn,
        uint32_t access_mask = SEC_DIR_ADD_FILE;
        bool dst_exists, old_is_stream, new_is_stream;
        int ret;
+       bool case_sensitive = (fsp->posix_flags & FSP_POSIX_FLAGS_OPEN) ?
+                               true : conn->case_sensitive;
+       bool case_preserve = (fsp->posix_flags & FSP_POSIX_FLAGS_OPEN) ?
+                               true : conn->case_preserve;
 
        status = check_name(conn, smb_fname_dst_in);
        if (!NT_STATUS_IS_OK(status)) {
@@ -7609,7 +7618,7 @@ NTSTATUS rename_internals_fsp(connection_struct *conn,
         * the rename (user is trying to change the case of the
         * filename).
         */
-       if (!conn->case_sensitive && conn->case_preserve &&
+       if (!case_sensitive && case_preserve &&
            strequal(fsp->fsp_name->base_name, smb_fname_dst->base_name) &&
            strequal(fsp->fsp_name->stream_name, smb_fname_dst->stream_name)) {
                char *fname_dst_parent = NULL;
@@ -8033,6 +8042,11 @@ NTSTATUS rename_internals(TALLOC_CTX *ctx,
        int rc;
        bool src_has_wild = false;
        bool dest_has_wild = false;
+       bool posix_pathname = (smb_fname_src->flags & SMB_FILENAME_POSIX_PATH);
+       bool case_sensitive = posix_pathname ? true : conn->case_sensitive;
+       bool case_preserve = posix_pathname ? true : conn->case_preserve;
+       bool short_case_preserve = posix_pathname ? true :
+                                       conn->short_case_preserve;
 
        /*
         * Split the old name into directory and last component
@@ -8075,6 +8089,7 @@ NTSTATUS rename_internals(TALLOC_CTX *ctx,
         */
 
        if (!VALID_STAT(smb_fname_src->st) &&
+           !posix_pathname &&
            mangle_is_mangled(fname_src_mask, conn->params)) {
                char *new_mask = NULL;
                mangle_lookup_name_from_8_3(ctx, fname_src_mask, &new_mask,
@@ -8085,7 +8100,7 @@ NTSTATUS rename_internals(TALLOC_CTX *ctx,
                }
        }
 
-       if (smb_fname_src->flags & SMB_FILENAME_POSIX_PATH) {
+       if (posix_pathname) {
                status = make_smb2_posix_create_ctx(talloc_tos(), &posx, 0777);
                if (!NT_STATUS_IS_OK(status)) {
                        DBG_WARNING("make_smb2_posix_create_ctx failed: %s\n",
@@ -8122,8 +8137,8 @@ NTSTATUS rename_internals(TALLOC_CTX *ctx,
                          "case_preserve = %d, short case preserve = %d, "
                          "directory = %s, newname = %s, "
                          "last_component_dest = %s\n",
-                         conn->case_sensitive, conn->case_preserve,
-                         conn->short_case_preserve,
+                         case_sensitive, case_preserve,
+                         short_case_preserve,
                          smb_fname_str_dbg(smb_fname_src),
                          smb_fname_str_dbg(smb_fname_dst),
                          dst_original_lcomp));
@@ -8276,7 +8291,7 @@ NTSTATUS rename_internals(TALLOC_CTX *ctx,
                        }
                }
 
-               if(!mask_match(dname, fname_src_mask, conn->case_sensitive)) {
+               if(!mask_match(dname, fname_src_mask, case_sensitive)) {
                        TALLOC_FREE(talloced);
                        continue;
                }
@@ -8793,6 +8808,7 @@ void reply_copy(struct smb_request *req)
                ucf_flags_from_smb_request(req);
        uint32_t ucf_flags_dst = UCF_ALWAYS_ALLOW_WCARD_LCOMP |
                ucf_flags_from_smb_request(req);
+       bool posix_pathnames = req->posix_pathnames;
        TALLOC_CTX *ctx = talloc_tos();
 
        START_PROFILE(SMBcopy);
@@ -8886,7 +8902,7 @@ void reply_copy(struct smb_request *req)
                goto out;
        }
 
-       if (!req->posix_pathnames) {
+       if (!posix_pathnames) {
                char *orig_src_lcomp = NULL;
                char *orig_dst_lcomp = NULL;
                /*
@@ -8927,6 +8943,7 @@ void reply_copy(struct smb_request *req)
         * Tine Smukavec <valentin.smuka...@hermes.si>.
         */
        if (!VALID_STAT(smb_fname_src->st) &&
+           !posix_pathnames &&
            mangle_is_mangled(fname_src_mask, conn->params)) {
                char *new_mask = NULL;
                mangle_lookup_name_from_8_3(ctx, fname_src_mask,
@@ -9069,7 +9086,8 @@ void reply_copy(struct smb_request *req)
                        }
 
                        if(!mask_match(dname, fname_src_mask,
-                                      conn->case_sensitive)) {
+                                      posix_pathnames ?
+                                       true : conn->case_sensitive)) {
                                TALLOC_FREE(talloced);
                                continue;
                        }
diff --git a/source3/smbd/smb2_query_directory.c 
b/source3/smbd/smb2_query_directory.c
index 1eb2b395d4c..794041df7e8 100644
--- a/source3/smbd/smb2_query_directory.c
+++ b/source3/smbd/smb2_query_directory.c
@@ -272,6 +272,7 @@ static struct tevent_req 
*smbd_smb2_query_directory_send(TALLOC_CTX *mem_ctx,
        char *p;
        bool stop = false;
        bool ok;
+       bool posix_dir_handle = (fsp->posix_flags & FSP_POSIX_FLAGS_OPEN);
 
        req = tevent_req_create(mem_ctx, &state,
                                struct smbd_smb2_query_directory_state);
@@ -467,7 +468,7 @@ static struct tevent_req 
*smbd_smb2_query_directory_send(TALLOC_CTX *mem_ctx,
                 fsp->fsp_name->base_name, lp_dont_descend(talloc_tos(), 
lp_sub, SNUM(conn)),
                (unsigned int)in_output_buffer_length ));
        if (in_list(fsp->fsp_name->base_name,lp_dont_descend(talloc_tos(), 
lp_sub, SNUM(conn)),


-- 
Samba Shared Repository

Reply via email to