From 017f90a03d0ab69641880d4fc2504c02259fa04e Mon Sep 17 00:00:00 2001 From: Vinit Agnihotri Date: Tue, 3 Dec 2024 11:19:09 +0530 Subject: [PATCH] sharesec: Add function to check existence of share from config Add function to detect if a share name exists in the registry or config file. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15780 Signed-off-by: Vinit Agnihotri Reviewed-by: John Mulligan Reviewed-by: Guenther Deschner (cherry picked from commit 78eb293e1cdd3635de0bcf46ffb9d842f27bcc9f) --- source3/utils/sharesec.c | 76 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/source3/utils/sharesec.c b/source3/utils/sharesec.c index 3c93893e178..6094746e3cc 100644 --- a/source3/utils/sharesec.c +++ b/source3/utils/sharesec.c @@ -31,6 +31,8 @@ struct cli_state; #include "cmdline_contexts.h" #include "lib/util/string_wrappers.h" #include "lib/param/param.h" +#include "lib/smbconf/smbconf.h" +#include "lib/smbconf/smbconf_init.h" static TALLOC_CTX *ctx; @@ -316,6 +318,80 @@ static int view_sharesec_sddl(const char *sharename) return 0; } +static bool registry_share(const char *sharename) +{ + sbcErr err; + TALLOC_CTX *mem_ctx = talloc_stackframe(); + struct smbconf_ctx *conf_ctx; + bool ret_status = true; + + err = smbconf_init(mem_ctx, &conf_ctx, "registry:"); + if (!SBC_ERROR_IS_OK(err)) { + DEBUG(0, ("Unable to init smbconf registry. Err:%s\n", + sbcErrorString(err))); + ret_status = false; + goto out; + } + + if(!smbconf_share_exists(conf_ctx, sharename)) { + ret_status = false; + goto done; + } +done: + smbconf_shutdown(conf_ctx); +out: + talloc_free(mem_ctx); + return ret_status; +} + +static bool txt_share(const char *sharename) +{ + sbcErr err; + TALLOC_CTX *mem_ctx = talloc_stackframe(); + struct smbconf_ctx *conf_ctx; + bool ret_status = true; + char *fconf_path; + + fconf_path = talloc_asprintf(mem_ctx, "file:%s", get_dyn_CONFIGFILE()); + if (fconf_path == NULL) { + DEBUG(0, ("Not enough memory for conf file path")); + ret_status = false; + goto out; + } + + err = smbconf_init(mem_ctx, &conf_ctx, fconf_path); + if (!SBC_ERROR_IS_OK(err)) { + DEBUG(0, ("Unable to init smbconf file. Err:%s\n", + sbcErrorString(err))); + ret_status = false; + goto out; + } + + if(!smbconf_share_exists(conf_ctx, sharename)) { + ret_status = false; + goto done; + } +done: + smbconf_shutdown(conf_ctx); +out: + talloc_free(mem_ctx); + return ret_status; +} + +static bool share_exists(const char *sharename) +{ + bool ret_status = false; + + if ((lp_config_backend() == CONFIG_BACKEND_REGISTRY) || + (lp_registry_shares() == true)) + ret_status = registry_share(sharename); + + if (!ret_status) { + ret_status = txt_share(sharename); + } + return ret_status; +} + /******************************************************************** main program ********************************************************************/ -- 2.47.2