]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3: libsmb: For SMB2 opens on a DFS share, convert to a DFS path if not already done.
authorJeremy Allison <jra@samba.org>
Thu, 1 Sep 2022 22:32:40 +0000 (15:32 -0700)
committerJeremy Allison <jra@samba.org>
Thu, 15 Sep 2022 18:43:32 +0000 (18:43 +0000)
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <npower@samba.org>
source3/libsmb/cli_smb2_fnum.c

index 5a12fcbfb99809431cde0aa934bd48b132c8f64c..bd3d705a641abea7ea5cfaddce3b36417ee3b2d2 100644 (file)
@@ -153,6 +153,42 @@ static uint8_t flags_to_smb2_oplock(uint32_t create_flags)
        return SMB2_OPLOCK_LEVEL_NONE;
 }
 
+/***************************************************************
+ If we're on a DFS share, ensure we convert to a full DFS path
+ if this hasn't already been done.
+***************************************************************/
+
+static const char *smb2_dfs_share_path(TALLOC_CTX *ctx,
+                                      struct cli_state *cli,
+                                      const char *path)
+{
+       bool is_dfs = smbXcli_conn_dfs_supported(cli->conn) &&
+                       smbXcli_tcon_is_dfs_share(cli->smb2.tcon);
+       bool is_already_dfs_path = false;
+
+       if (!is_dfs) {
+               return path;
+       }
+       is_already_dfs_path = cli_dfs_is_already_full_path(cli, path);
+       if (is_already_dfs_path) {
+               return path;
+       }
+       if (path[0] == '\0') {
+               return talloc_asprintf(ctx,
+                                      "%s\\%s",
+                                       smbXcli_conn_remote_name(cli->conn),
+                                       cli->share);
+       }
+       while (*path == '\\') {
+               path++;
+       }
+       return talloc_asprintf(ctx,
+                              "%s\\%s\\%s",
+                              smbXcli_conn_remote_name(cli->conn),
+                              cli->share,
+                              path);
+}
+
 /***************************************************************
  Small wrapper that allows SMB2 create to return a uint16_t fnum.
 ***************************************************************/
@@ -254,6 +290,11 @@ struct tevent_req *cli_smb2_create_fnum_send(
                }
        }
 
+       fname = smb2_dfs_share_path(state, cli, fname);
+       if (tevent_req_nomem(fname, req)) {
+               return tevent_req_post(req, ev);
+       }
+
        /* SMB2 is pickier about pathnames. Ensure it doesn't
           start in a '\' */
        if (*fname == '\\') {