From dd9cdfb3b1488a5f262767089d456ae9269f72f0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 1 Sep 2022 15:32:40 -0700 Subject: [PATCH] s3: libsmb: For SMB2 opens on a DFS share, convert to a DFS path if not already done. Signed-off-by: Jeremy Allison Reviewed-by: Noel Power --- source3/libsmb/cli_smb2_fnum.c | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/source3/libsmb/cli_smb2_fnum.c b/source3/libsmb/cli_smb2_fnum.c index 5a12fcbfb99..bd3d705a641 100644 --- a/source3/libsmb/cli_smb2_fnum.c +++ b/source3/libsmb/cli_smb2_fnum.c @@ -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 == '\\') { -- 2.47.3