[SCM] Samba Shared Repository - branch v3-2-test updated - release-3-2-0pre2-1079-gdee57ad

Michael Adam obnox at samba.org
Tue Apr 22 23:54:43 GMT 2008


The branch, v3-2-test has been updated
       via  dee57ad025e7ad9971e44ea30b6aab3806c06fc6 (commit)
       via  03fd30eef803ff2718e7af618d38944d56ccd329 (commit)
       via  be4f8447ccd044563f6b12793ea64d9f38741861 (commit)
       via  17415e2dc457ce41793a7e28e71f72c538c19c61 (commit)
       via  8118a8348f36b28fa4d46b42a104097cefa33a4d (commit)
      from  c55094555aa2ece1a64b44cc4470da96393acbf3 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test


- Log -----------------------------------------------------------------
commit dee57ad025e7ad9971e44ea30b6aab3806c06fc6
Author: Michael Adam <obnox at samba.org>
Date:   Wed Apr 23 01:49:11 2008 +0200

    libsmbconf: remove unnecessary talloc success check from smbconf_txt.c
    
    talloc_stackframe() panics on NOMEM.
    
    Michael

commit 03fd30eef803ff2718e7af618d38944d56ccd329
Author: Michael Adam <obnox at samba.org>
Date:   Wed Apr 23 01:48:26 2008 +0200

    libsmbconf: remove unnecessary talloc success checks from smbconf_reg.c
    
    talloc_stackframe panics on NOMEM.
    
    Michael

commit be4f8447ccd044563f6b12793ea64d9f38741861
Author: Michael Adam <obnox at samba.org>
Date:   Wed Apr 23 01:47:33 2008 +0200

    libsmbconf: remove unnecessary talloc success checks from smbconf.c
    
    talloc_stackframe() panics on NOMEM.
    
    Michael

commit 17415e2dc457ce41793a7e28e71f72c538c19c61
Author: Michael Adam <obnox at samba.org>
Date:   Tue Apr 22 16:31:16 2008 +0200

    libsmbconf: rewrite API to use smbconf_service struct
    
    instead of lists of strings and counters directly...
    
    Michael

commit 8118a8348f36b28fa4d46b42a104097cefa33a4d
Author: Michael Adam <obnox at samba.org>
Date:   Tue Apr 22 16:16:28 2008 +0200

    libsmbconf: add a struct smbconf_service to hold the parameter names + values.
    
    Michael

-----------------------------------------------------------------------

Summary of changes:
 source/lib/smbconf/smbconf.c         |   48 +++++------------
 source/lib/smbconf/smbconf.h         |   14 ++++--
 source/lib/smbconf/smbconf_private.h |    4 +-
 source/lib/smbconf/smbconf_reg.c     |   46 ++++++++++------
 source/lib/smbconf/smbconf_txt.c     |   38 +++++++------
 source/param/loadparm.c              |   12 ++---
 source/utils/net_conf.c              |   96 +++++++++++++---------------------
 7 files changed, 115 insertions(+), 143 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/lib/smbconf/smbconf.c b/source/lib/smbconf/smbconf.c
index 9565540..1a9b4e0 100644
--- a/source/lib/smbconf/smbconf.c
+++ b/source/lib/smbconf/smbconf.c
@@ -91,31 +91,21 @@ WERROR smbconf_drop(struct smbconf_ctx *ctx)
 WERROR smbconf_get_config(struct smbconf_ctx *ctx,
 			  TALLOC_CTX *mem_ctx,
 			  uint32_t *num_shares,
-			  char ***share_names, uint32_t **num_params,
-			  char ****param_names, char ****param_values)
+			  struct smbconf_service ***services)
 {
 	WERROR werr = WERR_OK;
 	TALLOC_CTX *tmp_ctx = NULL;
 	uint32_t tmp_num_shares;
 	char **tmp_share_names;
-	uint32_t *tmp_num_params;
-	char ***tmp_param_names;
-	char ***tmp_param_values;
+	struct smbconf_service **tmp_services;
 	uint32_t count;
 
-	if ((num_shares == NULL) || (share_names == NULL) ||
-	    (num_params == NULL) || (param_names == NULL) ||
-	    (param_values == NULL))
-	{
+	if ((num_shares == NULL) || (services == NULL)) {
 		werr = WERR_INVALID_PARAM;
 		goto done;
 	}
 
 	tmp_ctx = talloc_stackframe();
-	if (tmp_ctx == NULL) {
-		werr = WERR_NOMEM;
-		goto done;
-	}
 
 	werr = smbconf_get_share_names(ctx, tmp_ctx, &tmp_num_shares,
 				       &tmp_share_names);
@@ -123,23 +113,18 @@ WERROR smbconf_get_config(struct smbconf_ctx *ctx,
 		goto done;
 	}
 
-	tmp_num_params   = TALLOC_ARRAY(tmp_ctx, uint32_t, tmp_num_shares);
-	tmp_param_names  = TALLOC_ARRAY(tmp_ctx, char **, tmp_num_shares);
-	tmp_param_values = TALLOC_ARRAY(tmp_ctx, char **, tmp_num_shares);
+	tmp_services = TALLOC_ARRAY(tmp_ctx, struct smbconf_service *,
+				    tmp_num_shares);
 
-	if ((tmp_num_params == NULL) || (tmp_param_names == NULL) ||
-	    (tmp_param_values == NULL))
-	{
+	if (tmp_services == NULL) {
 		werr = WERR_NOMEM;
 		goto done;
 	}
 
 	for (count = 0; count < tmp_num_shares; count++) {
-		werr = smbconf_get_share(ctx, mem_ctx,
+		werr = smbconf_get_share(ctx, tmp_services,
 					 tmp_share_names[count],
-					 &tmp_num_params[count],
-					 &tmp_param_names[count],
-					 &tmp_param_values[count]);
+					 &tmp_services[count]);
 		if (!W_ERROR_IS_OK(werr)) {
 			goto done;
 		}
@@ -149,15 +134,9 @@ WERROR smbconf_get_config(struct smbconf_ctx *ctx,
 
 	*num_shares = tmp_num_shares;
 	if (tmp_num_shares > 0) {
-		*share_names = talloc_move(mem_ctx, &tmp_share_names);
-		*num_params = talloc_move(mem_ctx, &tmp_num_params);
-		*param_names = talloc_move(mem_ctx, &tmp_param_names);
-		*param_values = talloc_move(mem_ctx, &tmp_param_values);
+		*services = talloc_move(mem_ctx, &tmp_services);
 	} else {
-		*share_names = NULL;
-		*num_params = NULL;
-		*param_names = NULL;
-		*param_values = NULL;
+		*services = NULL;
 	}
 
 done:
@@ -204,15 +183,14 @@ WERROR smbconf_create_share(struct smbconf_ctx *ctx,
  */
 WERROR smbconf_get_share(struct smbconf_ctx *ctx,
 			 TALLOC_CTX *mem_ctx,
-			 const char *servicename, uint32_t *num_params,
-			 char ***param_names, char ***param_values)
+			 const char *servicename,
+			 struct smbconf_service **service)
 {
 	if (!smbconf_share_exists(ctx, servicename)) {
 		return WERR_NO_SUCH_SERVICE;
 	}
 
-	return ctx->ops->get_share(ctx, mem_ctx, servicename, num_params,
-				   param_names, param_values);
+	return ctx->ops->get_share(ctx, mem_ctx, servicename, service);
 }
 
 /**
diff --git a/source/lib/smbconf/smbconf.h b/source/lib/smbconf/smbconf.h
index 589d14e..e337476 100644
--- a/source/lib/smbconf/smbconf.h
+++ b/source/lib/smbconf/smbconf.h
@@ -27,6 +27,13 @@ struct smbconf_csn {
 	uint64_t csn;
 };
 
+struct smbconf_service {
+	char *name;
+	uint32_t num_params;
+	char **param_names;
+	char **param_values;
+};
+
 
 /**
  * intialization dispatcher function.
@@ -56,8 +63,7 @@ WERROR smbconf_drop(struct smbconf_ctx *ctx);
 WERROR smbconf_get_config(struct smbconf_ctx *ctx,
 			  TALLOC_CTX *mem_ctx,
 			  uint32_t *num_shares,
-			  char ***share_names, uint32_t **num_params,
-			  char ****param_names, char ****param_values);
+			  struct smbconf_service ***services);
 WERROR smbconf_get_share_names(struct smbconf_ctx *ctx,
 			       TALLOC_CTX *mem_ctx,
 			       uint32_t *num_shares,
@@ -66,8 +72,8 @@ bool smbconf_share_exists(struct smbconf_ctx *ctx, const char *servicename);
 WERROR smbconf_create_share(struct smbconf_ctx *ctx, const char *servicename);
 WERROR smbconf_get_share(struct smbconf_ctx *ctx,
 			 TALLOC_CTX *mem_ctx,
-			 const char *servicename, uint32_t *num_params,
-			 char ***param_names, char ***param_values);
+			 const char *servicename,
+			 struct smbconf_service **service);
 WERROR smbconf_delete_share(struct smbconf_ctx *ctx,
 			    const char *servicename);
 WERROR smbconf_set_parameter(struct smbconf_ctx *ctx,
diff --git a/source/lib/smbconf/smbconf_private.h b/source/lib/smbconf/smbconf_private.h
index 76f91f9..8e7d6a9 100644
--- a/source/lib/smbconf/smbconf_private.h
+++ b/source/lib/smbconf/smbconf_private.h
@@ -36,8 +36,8 @@ struct smbconf_ops {
 	WERROR (*create_share)(struct smbconf_ctx *ctx, const char *service);
 	WERROR (*get_share)(struct smbconf_ctx *ctx,
 			    TALLOC_CTX *mem_ctx,
-			    const char *servicename, uint32_t *num_params,
-			    char ***param_names, char ***param_values);
+			    const char *servicename,
+			    struct smbconf_service **service);
 	WERROR (*delete_share)(struct smbconf_ctx *ctx,
 				    const char *servicename);
 	WERROR (*set_parameter)(struct smbconf_ctx *ctx,
diff --git a/source/lib/smbconf/smbconf_reg.c b/source/lib/smbconf/smbconf_reg.c
index 930999c..b6d6d70 100644
--- a/source/lib/smbconf/smbconf_reg.c
+++ b/source/lib/smbconf/smbconf_reg.c
@@ -195,10 +195,7 @@ static WERROR smbconf_reg_create_service_key(TALLOC_CTX *mem_ctx,
 	/* create a new talloc ctx for creation. it will hold
 	 * the intermediate parent key (SMBCONF) for creation
 	 * and will be destroyed when leaving this function... */
-	if (!(create_ctx = talloc_stackframe())) {
-		werr = WERR_NOMEM;
-		goto done;
-	}
+	create_ctx = talloc_stackframe();
 
 	werr = smbconf_reg_open_base_key(create_ctx, ctx, REG_KEY_WRITE,
 					 &create_parent);
@@ -471,10 +468,6 @@ static WERROR smbconf_reg_get_values(TALLOC_CTX *mem_ctx,
 	}
 
 	tmp_ctx = talloc_stackframe();
-	if (tmp_ctx == NULL) {
-		werr = WERR_NOMEM;
-		goto done;
-	}
 
 	for (count = 0;
 	     werr = reg_enumvalue(tmp_ctx, key, count, &valname, &valvalue),
@@ -760,10 +753,6 @@ static WERROR smbconf_reg_get_share_names(struct smbconf_ctx *ctx,
 	}
 
 	tmp_ctx = talloc_stackframe();
-	if (tmp_ctx == NULL) {
-		werr = WERR_NOMEM;
-		goto done;
-	}
 
 	/* if there are values in the base key, return NULL as share name */
 	werr = smbconf_reg_open_base_key(tmp_ctx, ctx,
@@ -875,23 +864,44 @@ static WERROR smbconf_reg_create_share(struct smbconf_ctx *ctx,
 static WERROR smbconf_reg_get_share(struct smbconf_ctx *ctx,
 				    TALLOC_CTX *mem_ctx,
 				    const char *servicename,
-				    uint32_t *num_params,
-				    char ***param_names, char ***param_values)
+				    struct smbconf_service **service)
 {
 	WERROR werr = WERR_OK;
 	struct registry_key *key = NULL;
+	struct smbconf_service *tmp_service = NULL;
+	TALLOC_CTX *tmp_ctx = talloc_stackframe();
 
-	werr = smbconf_reg_open_service_key(mem_ctx, ctx, servicename,
+	werr = smbconf_reg_open_service_key(tmp_ctx, ctx, servicename,
 					    REG_KEY_READ, &key);
 	if (!W_ERROR_IS_OK(werr)) {
 		goto done;
 	}
 
-	werr = smbconf_reg_get_values(mem_ctx, key, num_params,
-				      param_names, param_values);
+	tmp_service = TALLOC_ZERO_P(tmp_ctx, struct smbconf_service);
+	if (tmp_service == NULL) {
+		werr =  WERR_NOMEM;
+		goto done;
+	}
+
+	if (servicename != NULL) {
+		tmp_service->name = talloc_strdup(tmp_service, servicename);
+		if (tmp_service->name == NULL) {
+			werr = WERR_NOMEM;
+			goto done;
+		}
+	}
+
+	werr = smbconf_reg_get_values(tmp_service, key,
+				      &(tmp_service->num_params),
+				      &(tmp_service->param_names),
+				      &(tmp_service->param_values));
+
+	if (W_ERROR_IS_OK(werr)) {
+		*service = talloc_move(mem_ctx, &tmp_service);
+	}
 
 done:
-	TALLOC_FREE(key);
+	TALLOC_FREE(tmp_ctx);
 	return werr;
 }
 
diff --git a/source/lib/smbconf/smbconf_txt.c b/source/lib/smbconf/smbconf_txt.c
index c511185..1a29f40 100644
--- a/source/lib/smbconf/smbconf_txt.c
+++ b/source/lib/smbconf/smbconf_txt.c
@@ -302,10 +302,6 @@ static WERROR smbconf_txt_get_share_names(struct smbconf_ctx *ctx,
 	}
 
 	tmp_ctx = talloc_stackframe();
-	if (tmp_ctx == NULL) {
-		werr = WERR_NOMEM;
-		goto done;
-	}
 
 	/* make sure "global" is always listed first,
 	 * possibly after NULL section */
@@ -389,15 +385,13 @@ static WERROR smbconf_txt_create_share(struct smbconf_ctx *ctx,
 static WERROR smbconf_txt_get_share(struct smbconf_ctx *ctx,
 				    TALLOC_CTX *mem_ctx,
 				    const char *servicename,
-				    uint32_t *num_params,
-				    char ***param_names, char ***param_values)
+				    struct smbconf_service **service)
 {
 	WERROR werr;
 	uint32_t sidx, count;
 	bool found;
 	TALLOC_CTX *tmp_ctx = NULL;
-	char **tmp_param_names = NULL;
-	char **tmp_param_values = NULL;
+	struct smbconf_service *tmp_service = NULL;
 
 	werr = smbconf_txt_load_file(ctx);
 	if (!W_ERROR_IS_OK(werr)) {
@@ -413,21 +407,31 @@ static WERROR smbconf_txt_get_share(struct smbconf_ctx *ctx,
 	}
 
 	tmp_ctx = talloc_stackframe();
-	if (tmp_ctx == NULL) {
+
+	tmp_service = TALLOC_ZERO_P(tmp_ctx, struct smbconf_service);
+	if (tmp_service == NULL) {
 		werr = WERR_NOMEM;
 		goto done;
 	}
 
+	if (servicename != NULL) {
+		tmp_service->name = talloc_strdup(tmp_service, servicename);
+		if (tmp_service->name == NULL) {
+			werr = WERR_NOMEM;
+			goto done;
+		}
+	}
+
 	for (count = 0; count < pd(ctx)->cache->num_params[sidx]; count++) {
-		werr = smbconf_add_string_to_array(tmp_ctx,
-				&tmp_param_names,
+		werr = smbconf_add_string_to_array(tmp_service,
+				&(tmp_service->param_names),
 				count,
 				pd(ctx)->cache->param_names[sidx][count]);
 		if (!W_ERROR_IS_OK(werr)) {
 			goto done;
 		}
-		werr = smbconf_add_string_to_array(tmp_ctx,
-				&tmp_param_values,
+		werr = smbconf_add_string_to_array(tmp_service,
+				&(tmp_service->param_values),
 				count,
 				pd(ctx)->cache->param_values[sidx][count]);
 		if (!W_ERROR_IS_OK(werr)) {
@@ -435,13 +439,11 @@ static WERROR smbconf_txt_get_share(struct smbconf_ctx *ctx,
 		}
 	}
 
-	*num_params = count;
+	tmp_service->num_params = count;
 	if (count > 0) {
-		*param_names = talloc_move(mem_ctx, &tmp_param_names);
-		*param_values = talloc_move(mem_ctx, &tmp_param_values);
+		*service = talloc_move(mem_ctx, &tmp_service);
 	} else {
-		*param_names = NULL;
-		*param_values = NULL;
+		*service = NULL;
 	}
 
 done:
diff --git a/source/param/loadparm.c b/source/param/loadparm.c
index 962c0a4..09049db 100644
--- a/source/param/loadparm.c
+++ b/source/param/loadparm.c
@@ -6497,9 +6497,7 @@ bool service_ok(int iService)
 static bool process_registry_globals(void)
 {
 	WERROR werr;
-	char **param_names;
-	char **param_values;
-	uint32_t num_params;
+	struct smbconf_service *service = NULL;
 	uint32_t count;
 	TALLOC_CTX *mem_ctx = talloc_stackframe();
 	bool ret = false;
@@ -6519,14 +6517,14 @@ static bool process_registry_globals(void)
 		goto done;
 	}
 
-	werr = smbconf_get_share(conf_ctx, mem_ctx, GLOBAL_NAME,
-				 &num_params, &param_names, &param_values);
+	werr = smbconf_get_share(conf_ctx, mem_ctx, GLOBAL_NAME, &service);
 	if (!W_ERROR_IS_OK(werr)) {
 		goto done;
 	}
 
-	for (count = 0; count < num_params; count++) {
-		ret = do_parameter(param_names[count], param_values[count],
+	for (count = 0; count < service->num_params; count++) {
+		ret = do_parameter(service->param_names[count],
+				   service->param_values[count],
 				   NULL);
 		if (ret != true) {
 			goto done;
diff --git a/source/utils/net_conf.c b/source/utils/net_conf.c
index 4fffcf8..08a06ea 100644
--- a/source/utils/net_conf.c
+++ b/source/utils/net_conf.c
@@ -138,10 +138,7 @@ static int net_conf_delincludes_usage(int argc, const char **argv)
  * This functions process a service previously loaded with libsmbconf.
  */
 static WERROR import_process_service(struct smbconf_ctx *conf_ctx,
-				     const char *servicename,
-				     const uint32_t num_params,
-				     const char **param_names,
-				     const char **param_values)
+				     struct smbconf_service *service)
 {
 	uint32_t idx;
 	WERROR werr = WERR_OK;
@@ -151,31 +148,32 @@ static WERROR import_process_service(struct smbconf_ctx *conf_ctx,
 
 	if (opt_testmode) {
 		const char *indent = "";
-		if (servicename != NULL) {
-			d_printf("[%s]\n", servicename);
+		if (service->name != NULL) {
+			d_printf("[%s]\n", service->name);
 			indent = "\t";
 		}
-		for (idx = 0; idx < num_params; idx++) {
-			d_printf("%s%s = %s\n", indent, param_names[idx],
-				 param_values[idx]);
+		for (idx = 0; idx < service->num_params; idx++) {
+			d_printf("%s%s = %s\n", indent,
+				 service->param_names[idx],
+				 service->param_values[idx]);
 		}
 		d_printf("\n");
 		goto done;
 	}
 
-	if (smbconf_share_exists(conf_ctx, servicename)) {
-		werr = smbconf_delete_share(conf_ctx, servicename);
+	if (smbconf_share_exists(conf_ctx, service->name)) {
+		werr = smbconf_delete_share(conf_ctx, service->name);
 		if (!W_ERROR_IS_OK(werr)) {
 			goto done;
 		}
 	}
-	werr = smbconf_create_share(conf_ctx, servicename);
+	werr = smbconf_create_share(conf_ctx, service->name);
 	if (!W_ERROR_IS_OK(werr)) {
 		goto done;
 	}
 
-	for (idx = 0; idx < num_params; idx ++) {
-		if (strequal(param_names[idx], "include")) {
+	for (idx = 0; idx < service->num_params; idx ++) {
+		if (strequal(service->param_names[idx], "include")) {
 			includes = TALLOC_REALLOC_ARRAY(mem_ctx,
 							includes,
 							char *,
@@ -185,7 +183,7 @@ static WERROR import_process_service(struct smbconf_ctx *conf_ctx,
 				goto done;
 			}
 			includes[num_includes] = talloc_strdup(includes,
-							param_values[idx]);
+						service->param_values[idx]);
 			if (includes[num_includes] == NULL) {
 				werr = WERR_NOMEM;
 				goto done;
@@ -193,16 +191,16 @@ static WERROR import_process_service(struct smbconf_ctx *conf_ctx,
 			num_includes++;
 		} else {
 			werr = smbconf_set_parameter(conf_ctx,
-						     servicename,
-						     param_names[idx],
-						     param_values[idx]);
+						     service->name,
+						     service->param_names[idx],
+						     service->param_values[idx]);
 			if (!W_ERROR_IS_OK(werr)) {
 				goto done;
 			}
 		}
 	}
 
-	werr = smbconf_set_includes(conf_ctx, servicename, num_includes,
+	werr = smbconf_set_includes(conf_ctx, service->name, num_includes,
 				    (const char **)includes);
 
 done:
@@ -224,11 +222,8 @@ static int net_conf_list(struct smbconf_ctx *conf_ctx,
 	int ret = -1;
 	TALLOC_CTX *mem_ctx;
 	uint32_t num_shares;
-	char **share_names;
-	uint32_t *num_params;
-	char ***param_names;
-	char ***param_values;
 	uint32_t share_count, param_count;
+	struct smbconf_service **shares = NULL;
 
 	mem_ctx = talloc_stackframe();
 
@@ -237,8 +232,7 @@ static int net_conf_list(struct smbconf_ctx *conf_ctx,
 		goto done;
 	}
 
-	werr = smbconf_get_config(conf_ctx, mem_ctx, &num_shares, &share_names,
-				  &num_params, &param_names, &param_values);
+	werr = smbconf_get_config(conf_ctx, mem_ctx, &num_shares, &shares);
 	if (!W_ERROR_IS_OK(werr)) {
 		d_fprintf(stderr, "Error getting config: %s\n",
 			  dos_errstr(werr));
@@ -247,17 +241,18 @@ static int net_conf_list(struct smbconf_ctx *conf_ctx,
 
 	for (share_count = 0; share_count < num_shares; share_count++) {
 		const char *indent = "";
-		if (share_names[share_count] != NULL) {
-			d_printf("[%s]\n", share_names[share_count]);
+		if (shares[share_count]->name != NULL) {
+			d_printf("[%s]\n", shares[share_count]->name);
 			indent = "\t";
 		}
-		for (param_count = 0; param_count < num_params[share_count];
+		for (param_count = 0;
+		     param_count < shares[share_count]->num_params;
 		     param_count++)
 		{
 			d_printf("%s%s = %s\n",
 				 indent,
-				 param_names[share_count][param_count],
-				 param_values[share_count][param_count]);


-- 
Samba Shared Repository


More information about the samba-cvs mailing list