Hi,

these patches together form the fix for bug #5593:
Make testparm list registry shares (which are otherwise
only loaded on demand by the server).

Karo: We talked about these, and it may look like a lot
of changes, but I rather did more atomic changes than
one bigger commit. The overall commit diff is not so bad:
2 files changed, 120 insertions(+), 26 deletions(-).

If you think it is not worth getting into 3.2.1 I will
revert it, but it mostly changes code that is new
anyways. And it renders a new feature more useful. :-)

Cheers - Michael

Michael Adam wrote:
> The branch, v3-2-test has been updated
> via dacd0f90f3706db6ffab0cd7662d22eb40811e05 (commit)
> via efb9a844e74b91d63fda98fa9cc12136bf1f172a (commit)
> via 6fd007905d4ba09309735a14635502008e082cb6 (commit)
> via e1bbcc6c5401c59726ca40dadff5760c2800b5c1 (commit)
> via dc04efa42104100e677bccc307726106d8ca4b31 (commit)
> via 661960e2bd73a6f773531608a635e17be28afeba (commit)
> via 02fa674dd62ad400502046fbe9e05a1578b4deab (commit)
> via fc60bc9389e5a0ca278b3622e96aed1626c4882e (commit)
> via e7362a769c4ad7b6715c87dc8ba77ffdd38a4824 (commit)
> via 7f38c280c821cc7950036a709e01383ab94ab55e (commit)
> from f4d26db5dfccb962f5ca2cc03e9012a9883e16d8 (commit)
>
> http://gitweb.samba.org/?p=samba.git...og;h=v3-2-test
>
>
> - Log -----------------------------------------------------------------
> commit dacd0f90f3706db6ffab0cd7662d22eb40811e05
> Author: Volker Lendecke
> Date: Tue Jun 3 20:51:42 2008 +0200
>
> Always set "registry shares = yes" for "include = registry"
>
> This fixes the case where "include = registry" is set in the smb.conf text file
> and *only* shares (no [global] settings) are present in the registry.
>
> Michael, please check!
>
> Thanks,
>
> Volker
> (cherry picked from commit 6c80362e291d8c5e748b987a583e8e32acc36354)
>
> commit efb9a844e74b91d63fda98fa9cc12136bf1f172a
> Author: Michael Adam
> Date: Tue May 27 10:59:11 2008 +0200
>
> loadparm: fix process_registry_shares() when there is only [global] in registry.
>
> This fixes testparm printing "Error loading services." when there is only
> the global section in registry and no other service definition.
>
> Michael
> (cherry picked from commit 28d197220038b9a47af177b88a8587f865e45de5)
>
> commit 6fd007905d4ba09309735a14635502008e082cb6
> Author: Michael Adam
> Date: Mon May 26 11:58:11 2008 +0200
>
> loadarm: fix testparm with "config backend = registry".
>
> Set the iServiceIndex to "-1" for starup with either config
> backend (originally only for text backend). Otherwise,
> process_registry_shares() will fail.
>
> Currently, the only user of lp_load_with_registry_shares() is testparm.
>
> Michael
> (cherry picked from commit 5e2b925367241c41793b2eb7a628e9fc9f3ac8ff)
>
> commit e1bbcc6c5401c59726ca40dadff5760c2800b5c1
> Author: Michael Adam
> Date: Thu May 15 02:41:05 2008 +0200
>
> testparm: list registry shares with testparm.
>
> I.e., use lp_load_with_registry_shares() instead of lp_load().
>
> Michael
> (cherry picked from commit 95339c0c1ecc49049f1fc176f72a1dcac639e06d)
>
> commit dc04efa42104100e677bccc307726106d8ca4b31
> Author: Michael Adam
> Date: Thu May 15 02:39:45 2008 +0200
>
> loadparm: add funcion lp_load_with_registry_shares().
>
> This is like lp_load(), except that it will load the
> registry shares into the services aarray when registry
> shares are activated.
>
> Michael
> (cherry picked from commit b387c614ba8d1d3960f6917f03f0fd433cf2b2ee)
>
> commit 661960e2bd73a6f773531608a635e17be28afeba
> Author: Michael Adam
> Date: Thu May 15 02:39:02 2008 +0200
>
> loadparm: add call to do_section() to process_registry_service().
>
> Michael
> (cherry picked from commit e1b76cd5d646bb9083cfca0d15a84183cad72882)
>
> commit 02fa674dd62ad400502046fbe9e05a1578b4deab
> Author: Michael Adam
> Date: Thu May 15 02:25:34 2008 +0200
>
> loadparm: add parameter allow_registry_shares to lp_load_ex().
>
> This allows for registry shares to be activated, i.e. loaded into
> the services array at lp_load() time.
>
> Michael
> (cherry picked from commit b3233ecefd5df745ba7e10511f9ab36064036b10)
>
> commit fc60bc9389e5a0ca278b3622e96aed1626c4882e
> Author: Michael Adam
> Date: Thu May 15 02:15:20 2008 +0200
>
> loadparm: add a function process_registry_shares()
>
> This loads the shares defined in registry into the services array.
>
> Michael
> (cherry picked from commit b3a90b72517c2e25d972796908aec4d2b85a030e)
>
> commit e7362a769c4ad7b6715c87dc8ba77ffdd38a4824
> Author: Michael Adam
> Date: Thu May 15 02:08:14 2008 +0200
>
> loadparm: refactor processing of service out of process_registry_globals()
>
> into new function process_registry_service().
>
> Michael
> (cherry picked from commit 2986e5174e69527465ae7ef8e108110416752b56)
>
> commit 7f38c280c821cc7950036a709e01383ab94ab55e
> Author: Michael Adam
> Date: Thu May 15 01:40:11 2008 +0200
>
> loadparm: refactor initalization of registry config out into lp_smbconf_ctx().
>
> Michael
> (cherry picked from commit 83cd9f74d57c462ad5c8956b3ce3c81bea429b67)
>
> -----------------------------------------------------------------------
>
> Summary of changes:
> source/param/loadparm.c | 144 ++++++++++++++++++++++++++++++++++++++--------
> source/utils/testparm.c | 2 +-
> 2 files changed, 120 insertions(+), 26 deletions(-)
>
>
> Changeset truncated at 500 lines:
>
> diff --git a/source/param/loadparm.c b/source/param/loadparm.c
> index d0b8e83..668a501 100644
> --- a/source/param/loadparm.c
> +++ b/source/param/loadparm.c
> @@ -80,7 +80,6 @@ extern userdom_struct current_user_info;
>
> static bool in_client = False; /* Not in the client by default */
> static struct smbconf_csn conf_last_csn;
> -static struct smbconf_ctx *conf_ctx = NULL;
>
> #define CONFIG_BACKEND_FILE 0
> #define CONFIG_BACKEND_REGISTRY 1
> @@ -6503,6 +6502,47 @@ bool service_ok(int iService)
> return (bRetval);
> }
>
> +static struct smbconf_ctx *lp_smbconf_ctx(void)
> +{
> + WERROR werr;
> + static struct smbconf_ctx *conf_ctx = NULL;
> +
> + if (conf_ctx == NULL) {
> + werr = smbconf_init(NULL, &conf_ctx, "registry:");
> + if (!W_ERROR_IS_OK(werr)) {
> + DEBUG(1, ("error initializing registry configuration: "
> + "%s\n", dos_errstr(werr)));
> + conf_ctx = NULL;
> + }
> + }
> +
> + return conf_ctx;
> +}
> +
> +static bool process_registry_service(struct smbconf_service *service)
> +{
> + uint32_t count;
> + bool ret;
> +
> + if (service == NULL) {
> + return false;
> + }
> +
> + ret = do_section(service->name, NULL);
> + if (ret != true) {
> + return false;
> + }
> + for (count = 0; count < service->num_params; count++) {
> + ret = do_parameter(service->param_names[count],
> + service->param_values[count],
> + NULL);
> + if (ret != true) {
> + return false;
> + }
> + }
> + return true;
> +}
> +
> /*
> * process_registry_globals
> */
> @@ -6510,16 +6550,17 @@ static bool process_registry_globals(void)
> {
> WERROR werr;
> struct smbconf_service *service = NULL;
> - uint32_t count;
> TALLOC_CTX *mem_ctx = talloc_stackframe();
> + struct smbconf_ctx *conf_ctx = lp_smbconf_ctx();
> bool ret = false;
>
> if (conf_ctx == NULL) {
> - /* first time */
> - werr = smbconf_init(NULL, &conf_ctx, "registry:");
> - if (!W_ERROR_IS_OK(werr)) {
> - goto done;
> - }
> + goto done;
> + }
> +
> + ret = do_parameter("registry shares", "yes", NULL);
> + if (!ret) {
> + goto done;
> }
>
> if (!smbconf_share_exists(conf_ctx, GLOBAL_NAME)) {
> @@ -6534,16 +6575,50 @@ static bool process_registry_globals(void)
> goto done;
> }
>
> - for (count = 0; count < service->num_params; count++) {
> - ret = do_parameter(service->param_names[count],
> - service->param_values[count],
> - NULL);
> - if (ret != true) {
> + ret = process_registry_service(service);
> + if (!ret) {
> + goto done;
> + }
> +
> + /* store the csn */
> + smbconf_changed(conf_ctx, &conf_last_csn, NULL, NULL);
> +
> +done:
> + TALLOC_FREE(mem_ctx);
> + return ret;
> +}
> +
> +static bool process_registry_shares(void)
> +{
> + WERROR werr;
> + uint32_t count;
> + struct smbconf_service **service = NULL;
> + uint32_t num_shares = 0;
> + TALLOC_CTX *mem_ctx = talloc_stackframe();
> + struct smbconf_ctx *conf_ctx = lp_smbconf_ctx();
> + bool ret = false;
> +
> + if (conf_ctx == NULL) {
> + goto done;
> + }
> +
> + werr = smbconf_get_config(conf_ctx, mem_ctx, &num_shares, &service);
> + if (!W_ERROR_IS_OK(werr)) {
> + goto done;
> + }
> +
> + ret = true;
> +
> + for (count = 0; count < num_shares; count++) {
> + if (strequal(service[count]->name, GLOBAL_NAME)) {
> + continue;
> + }
> + ret = process_registry_service(service[count]);
> + if (!ret) {
> goto done;
> }
> }
>
> - ret = do_parameter("registry shares", "yes", NULL);
> /* store the csn */
> smbconf_changed(conf_ctx, &conf_last_csn, NULL, NULL);
>
> @@ -6625,14 +6700,10 @@ bool lp_file_list_changed(void)
> DEBUG(6, ("lp_file_list_changed()\n"));
>
> if (lp_config_backend_is_registry()) {
> + struct smbconf_ctx *conf_ctx = lp_smbconf_ctx();
> +
> if (conf_ctx == NULL) {
> - WERROR werr;
> - werr = smbconf_init(NULL, &conf_ctx, "registry:");
> - if (!W_ERROR_IS_OK(werr)) {
> - DEBUG(0, ("error opening configuration: %s\n",
> - dos_errstr(werr)));
> - return false;
> - }
> + return false;
> }
> if (smbconf_changed(conf_ctx, &conf_last_csn, NULL, NULL)) {
> DEBUGADD(6, ("registry config changed\n"));
> @@ -8670,7 +8741,8 @@ bool lp_load_ex(const char *pszFname,
> bool save_defaults,
> bool add_ipc,
> bool initialize_globals,
> - bool allow_include_registry)
> + bool allow_include_registry,
> + bool allow_registry_shares)
> {
> char *n2 = NULL;
> bool bRetval;
> @@ -8692,6 +8764,9 @@ bool lp_load_ex(const char *pszFname,
> lp_save_defaults();
> }
>
> + /* We get sections first, so have to start 'behind' to make up */
> + iServiceIndex = -1;
> +
> if (Globals.param_opt != NULL) {
> data = Globals.param_opt;
> while (data) {
> @@ -8715,8 +8790,6 @@ bool lp_load_ex(const char *pszFname,
>
> add_to_file_list(pszFname, n2);
>
> - /* We get sections first, so have to start 'behind' to make up */
> - iServiceIndex = -1;
> bRetval = pm_process(n2, do_section, do_parameter, NULL);
> SAFE_FREE(n2);
>
> @@ -8744,7 +8817,8 @@ bool lp_load_ex(const char *pszFname,
> lp_kill_all_services();
> return lp_load_ex(pszFname, global_only, save_defaults,
> add_ipc, initialize_globals,
> - allow_include_registry);
> + allow_include_registry,
> + allow_registry_shares);
> }
> } else if (lp_config_backend_is_registry()) {
> bRetval = process_registry_globals();
> @@ -8754,6 +8828,10 @@ bool lp_load_ex(const char *pszFname,
> bRetval = false;
> }
>
> + if (bRetval && lp_registry_shares() && allow_registry_shares) {
> + bRetval = process_registry_shares();
> + }
> +
> lp_add_auto_services(lp_auto_services());
>
> if (add_ipc) {
> @@ -8795,7 +8873,7 @@ bool lp_load(const char *pszFname,
> save_defaults,
> add_ipc,
> initialize_globals,
> - true);
> + true, false);
> }
>
> bool lp_load_initial_only(const char *pszFname)
> @@ -8805,9 +8883,25 @@ bool lp_load_initial_only(const char *pszFname)
> false,
> false,
> true,
> + false,
> false);
> }
>
> +bool lp_load_with_registry_shares(const char *pszFname,
> + bool global_only,
> + bool save_defaults,
> + bool add_ipc,
> + bool initialize_globals)
> +{
> + return lp_load_ex(pszFname,
> + global_only,
> + save_defaults,
> + add_ipc,
> + initialize_globals,
> + true,
> + true);
> +}
> +
> /************************************************** *************************
> Reset the max number of services.
> ************************************************** *************************/
> diff --git a/source/utils/testparm.c b/source/utils/testparm.c
> index aded4a8..03291fe 100644
> --- a/source/utils/testparm.c
> +++ b/source/utils/testparm.c
> @@ -269,7 +269,7 @@ via the %%o substitution. With encrypted passwords this is not possible.\n", lp_
>
> fprintf(stderr,"Load smb config files from %s\n",config_file);
>
> - if (!lp_load(config_file,False,True,False,True)) {
> + if (!lp_load_with_registry_shares(config_file,False,T rue,False,True)) {
> fprintf(stderr,"Error loading services.\n");
> return(1);
> }
>
>
> --
> Samba Shared Repository


--

i.A. Michael Adam

--
Michael Adam
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.SerNet.DE, mailto: Info @ SerNet.DE

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: comment

iD8DBQFIdoLzyU9JOBhPkDQRAj0WAJwKgwn6YkkYsYOw2yBuJY Pq5RAp6QCfYoZc
N8HTxMUvBV55X9/a9XU7MII=
=GE1o
-----END PGP SIGNATURE-----