From: Jeremy Allison Date: Fri, 19 Aug 2022 21:59:04 +0000 (-0700) Subject: s3: libsmb: Add cli_dfs_is_already_full_path() function. X-Git-Tag: talloc-2.4.0~1029 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=26b4a6951b6ae2a8ba2341d64fa888fe52f6463a;p=thirdparty%2Fsamba.git s3: libsmb: Add cli_dfs_is_already_full_path() function. Returns true if it's already a fully qualified DFS path. Not yet used. Signed-off-by: Jeremy Allison Reviewed-by: Noel Power --- diff --git a/source3/libsmb/clidfs.c b/source3/libsmb/clidfs.c index d8355f8058b..83e725d0abf 100644 --- a/source3/libsmb/clidfs.c +++ b/source3/libsmb/clidfs.c @@ -588,6 +588,46 @@ static char *cli_dfs_make_full_path(TALLOC_CTX *ctx, dir); } +/******************************************************************** + Check if a path has already been converted to DFS. +********************************************************************/ + +bool cli_dfs_is_already_full_path(struct cli_state *cli, const char *path) +{ + const char *server = smbXcli_conn_remote_name(cli->conn); + size_t server_len = strlen(server); + bool found_server = false; + const char *share = cli->share; + size_t share_len = strlen(share); + bool found_share = false; + + if (!IS_DIRECTORY_SEP(path[0])) { + return false; + } + path++; + found_server = (strncasecmp_m(path, server, server_len) == 0); + if (!found_server) { + return false; + } + path += server_len; + if (!IS_DIRECTORY_SEP(path[0])) { + return false; + } + path++; + found_share = (strncasecmp_m(path, share, share_len) == 0); + if (!found_share) { + return false; + } + path += share_len; + if (path[0] == '\0') { + return true; + } + if (IS_DIRECTORY_SEP(path[0])) { + return true; + } + return false; +} + /******************************************************************** Get the dfs referral link. ********************************************************************/ diff --git a/source3/libsmb/proto.h b/source3/libsmb/proto.h index df709dbb6ff..222fcafb5f4 100644 --- a/source3/libsmb/proto.h +++ b/source3/libsmb/proto.h @@ -135,6 +135,7 @@ NTSTATUS cli_cm_open(TALLOC_CTX *ctx, struct cli_state **pcli); void cli_cm_display(struct cli_state *c); struct client_dfs_referral; +bool cli_dfs_is_already_full_path(struct cli_state *cli, const char *path); NTSTATUS cli_dfs_get_referral_ex(TALLOC_CTX *ctx, struct cli_state *cli, const char *path,