[SCM] Samba Shared Repository - branch v3-2-test updated - initial-v3-2-test-1855-gfeddc14

Volker Lendecke vl at samba.org
Mon Feb 4 20:47:09 GMT 2008


The branch, v3-2-test has been updated
       via  feddc1447d585fd108d22a36bccc576fa81197ef (commit)
       via  e2c9fc4cf5f0ff725330fa44f53782db65fca37e (commit)
       via  d471dd4adb79d480c89436b2ed98f9ec6812aaa0 (commit)
      from  c9472ae61039adf178e047d89dbcc698dfa57059 (commit)

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


- Log -----------------------------------------------------------------
commit feddc1447d585fd108d22a36bccc576fa81197ef
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Feb 4 21:05:41 2008 +0100

    str_list_free is not needed anymore

commit e2c9fc4cf5f0ff725330fa44f53782db65fca37e
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Feb 4 20:57:35 2008 +0100

    Always pass a TALLOC_CTX to str_list_make and str_list_copy

commit d471dd4adb79d480c89436b2ed98f9ec6812aaa0
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Feb 4 18:49:19 2008 +0100

    Simplify str_list_xxx

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

Summary of changes:
 source/auth/auth.c         |   36 +++++++---
 source/lib/debug.c         |    6 +-
 source/lib/util_str.c      |  177 +++++++++++---------------------------------
 source/libads/ldap.c       |    8 +-
 source/libgpo/gpo_ldap.c   |   19 ++---
 source/param/loadparm.c    |   42 ++++++-----
 source/smbd/map_username.c |    6 +-
 source/smbd/password.c     |   15 ++--
 source/web/neg_lang.c      |    4 +-
 9 files changed, 119 insertions(+), 194 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/auth/auth.c b/source/auth/auth.c
index e136fc2..05bb6a5 100644
--- a/source/auth/auth.c
+++ b/source/auth/auth.c
@@ -458,7 +458,9 @@ NTSTATUS make_auth_context_subsystem(struct auth_context **auth_context)
 	char **auth_method_list = NULL; 
 	NTSTATUS nt_status;
 
-	if (lp_auth_methods() && !str_list_copy(&auth_method_list, lp_auth_methods())) {
+	if (lp_auth_methods()
+	    && !str_list_copy(talloc_tos(), &auth_method_list,
+			      lp_auth_methods())) {
 		return NT_STATUS_NO_MEMORY;
 	}
 
@@ -467,38 +469,52 @@ NTSTATUS make_auth_context_subsystem(struct auth_context **auth_context)
 		{
 		case SEC_DOMAIN:
 			DEBUG(5,("Making default auth method list for security=domain\n"));
-			auth_method_list = str_list_make("guest sam winbind:ntdomain", NULL);
+			auth_method_list = str_list_make(
+				talloc_tos(), "guest sam winbind:ntdomain",
+				NULL);
 			break;
 		case SEC_SERVER:
 			DEBUG(5,("Making default auth method list for security=server\n"));
-			auth_method_list = str_list_make("guest sam smbserver", NULL);
+			auth_method_list = str_list_make(
+				talloc_tos(), "guest sam smbserver",
+				NULL);
 			break;
 		case SEC_USER:
 			if (lp_encrypted_passwords()) {	
 				if ((lp_server_role() == ROLE_DOMAIN_PDC) || (lp_server_role() == ROLE_DOMAIN_BDC)) {
 					DEBUG(5,("Making default auth method list for DC, security=user, encrypt passwords = yes\n"));
-					auth_method_list = str_list_make("guest sam winbind:trustdomain", NULL);
+					auth_method_list = str_list_make(
+						talloc_tos(),
+						"guest sam winbind:trustdomain",
+						NULL);
 				} else {
 					DEBUG(5,("Making default auth method list for standalone security=user, encrypt passwords = yes\n"));
-					auth_method_list = str_list_make("guest sam", NULL);
+					auth_method_list = str_list_make(
+						talloc_tos(), "guest sam",
+						NULL);
 				}
 			} else {
 				DEBUG(5,("Making default auth method list for security=user, encrypt passwords = no\n"));
-				auth_method_list = str_list_make("guest unix", NULL);
+				auth_method_list = str_list_make(
+					talloc_tos(), "guest unix", NULL);
 			}
 			break;
 		case SEC_SHARE:
 			if (lp_encrypted_passwords()) {
 				DEBUG(5,("Making default auth method list for security=share, encrypt passwords = yes\n"));
-				auth_method_list = str_list_make("guest sam", NULL);
+				auth_method_list = str_list_make(
+					talloc_tos(), "guest sam", NULL);
 			} else {
 				DEBUG(5,("Making default auth method list for security=share, encrypt passwords = no\n"));
-				auth_method_list = str_list_make("guest unix", NULL);
+				auth_method_list = str_list_make(
+					talloc_tos(), "guest unix", NULL);
 			}
 			break;
 		case SEC_ADS:
 			DEBUG(5,("Making default auth method list for security=ADS\n"));
-			auth_method_list = str_list_make("guest sam winbind:ntdomain", NULL);
+			auth_method_list = str_list_make(
+				talloc_tos(), "guest sam winbind:ntdomain",
+				NULL);
 			break;
 		default:
 			DEBUG(5,("Unknown auth method!\n"));
@@ -511,7 +527,7 @@ NTSTATUS make_auth_context_subsystem(struct auth_context **auth_context)
 	nt_status = make_auth_context_text_list(auth_context,
 						auth_method_list);
 
-	str_list_free(&auth_method_list);
+	TALLOC_FREE(auth_method_list);
 	return nt_status;
 }
 
diff --git a/source/lib/debug.c b/source/lib/debug.c
index 51bb0d7..9ff267b 100644
--- a/source/lib/debug.c
+++ b/source/lib/debug.c
@@ -460,14 +460,14 @@ bool debug_parse_levels(const char *params_str)
 	if (AllowDebugChange == False)
 		return True;
 
-	params = str_list_make(params_str, NULL);
+	params = str_list_make(talloc_tos(), params_str, NULL);
 
 	if (debug_parse_params(params)) {
 		debug_dump_status(5);
-		str_list_free(&params);
+		TALLOC_FREE(params);
 		return True;
 	} else {
-		str_list_free(&params);
+		TALLOC_FREE(params);
 		return False;
 	}
 }
diff --git a/source/lib/util_str.c b/source/lib/util_str.c
index bcb9197..93ecad7 100644
--- a/source/lib/util_str.c
+++ b/source/lib/util_str.c
@@ -1841,149 +1841,93 @@ int fstr_sprintf(fstring s, const char *fmt, ...)
 
 #define S_LIST_ABS 16 /* List Allocation Block Size */
 
-static char **str_list_make_internal(TALLOC_CTX *mem_ctx,
-		const char *string,
-		const char *sep)
+char **str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char *sep)
 {
-	char **list, **rlist;
+	char **list;
 	const char *str;
 	char *s;
 	int num, lsize;
 	char *tok;
-	TALLOC_CTX *frame = NULL;
 
 	if (!string || !*string)
 		return NULL;
-	if (mem_ctx) {
-		s = talloc_strdup(mem_ctx, string);
-	} else {
-		s = SMB_STRDUP(string);
+
+	list = TALLOC_ARRAY(mem_ctx, char *, S_LIST_ABS+1);
+	if (list == NULL) {
+		return NULL;
 	}
-	if (!s) {
+	lsize = S_LIST_ABS;
+
+	s = talloc_strdup(list, string);
+	if (s == NULL) {
 		DEBUG(0,("str_list_make: Unable to allocate memory"));
+		TALLOC_FREE(list);
 		return NULL;
 	}
 	if (!sep) sep = LIST_SEP;
 
-	num = lsize = 0;
-	list = NULL;
-
+	num = 0;
 	str = s;
-	frame = talloc_stackframe();
-	while (next_token_talloc(frame, &str, &tok, sep)) {
+
+	while (next_token_talloc(list, &str, &tok, sep)) {
+
 		if (num == lsize) {
+			char **tmp;
+
 			lsize += S_LIST_ABS;
-			if (mem_ctx) {
-				rlist = TALLOC_REALLOC_ARRAY(mem_ctx, list,
-						char *, lsize +1);
-			} else {
-				/* We need to keep the old list on
-				 * error so we can free the elements
-				   if the realloc fails. */
-				rlist =SMB_REALLOC_ARRAY_KEEP_OLD_ON_ERROR(list,
-						char *, lsize +1);
-			}
-			if (!rlist) {
+
+			tmp = TALLOC_REALLOC_ARRAY(mem_ctx, list, char *,
+						   lsize + 1);
+			if (tmp == NULL) {
 				DEBUG(0,("str_list_make: "
 					"Unable to allocate memory"));
-				str_list_free(&list);
-				if (mem_ctx) {
-					TALLOC_FREE(s);
-				} else {
-					SAFE_FREE(s);
-				}
-				TALLOC_FREE(frame);
+				TALLOC_FREE(list);
 				return NULL;
-			} else {
-				list = rlist;
 			}
-			memset (&list[num], 0,
-					((sizeof(char**)) * (S_LIST_ABS +1)));
-		}
 
-		if (mem_ctx) {
-			list[num] = talloc_strdup(mem_ctx, tok);
-		} else {
-			list[num] = SMB_STRDUP(tok);
-		}
+			list = tmp;
 
-		if (!list[num]) {
-			DEBUG(0,("str_list_make: Unable to allocate memory"));
-			str_list_free(&list);
-			if (mem_ctx) {
-				TALLOC_FREE(s);
-			} else {
-				SAFE_FREE(s);
-			}
-			TALLOC_FREE(frame);
-			return NULL;
+			memset (&list[num], 0,
+				((sizeof(char**)) * (S_LIST_ABS +1)));
 		}
 
-		num++;
+		list[num] = tok;
+		num += 1;
 	}
 
-	TALLOC_FREE(frame);
-
-	if (mem_ctx) {
-		TALLOC_FREE(s);
-	} else {
-		SAFE_FREE(s);
-	}
+	list[num] = NULL;
 
+	TALLOC_FREE(s);
 	return list;
 }
 
-char **str_list_make_talloc(TALLOC_CTX *mem_ctx,
-		const char *string,
-		const char *sep)
-{
-	return str_list_make_internal(mem_ctx, string, sep);
-}
-
-char **str_list_make(const char *string, const char *sep)
-{
-	return str_list_make_internal(NULL, string, sep);
-}
-
-bool str_list_copy(char ***dest, const char **src)
+bool str_list_copy(TALLOC_CTX *mem_ctx, char ***dest, const char **src)
 {
-	char **list, **rlist;
-	int num, lsize;
+	char **list;
+	int i, num;
 
 	*dest = NULL;
 	if (!src)
 		return false;
 
-	num = lsize = 0;
-	list = NULL;
+	num = 0;
+	while (src[num] != NULL) {
+		num += 1;
+	}
 
-	while (src[num]) {
-		if (num == lsize) {
-			lsize += S_LIST_ABS;
-			rlist = SMB_REALLOC_ARRAY_KEEP_OLD_ON_ERROR(list,
-					char *, lsize +1);
-			if (!rlist) {
-				DEBUG(0,("str_list_copy: "
-					"Unable to re-allocate memory"));
-				str_list_free(&list);
-				return false;
-			} else {
-				list = rlist;
-			}
-			memset (&list[num], 0,
-					((sizeof(char **)) * (S_LIST_ABS +1)));
-		}
+	list = TALLOC_ARRAY(mem_ctx, char *, num+1);
+	if (list == NULL) {
+		return false;
+	}
 
-		list[num] = SMB_STRDUP(src[num]);
-		if (!list[num]) {
-			DEBUG(0,("str_list_copy: Unable to allocate memory"));
-			str_list_free(&list);
+	for (i=0; i<num; i++) {
+		list[i] = talloc_strdup(list, src[i]);
+		if (list[i] == NULL) {
+			TALLOC_FREE(list);
 			return false;
 		}
-
-		num++;
 	}
-
+	list[i] = NULL;
 	*dest = list;
 	return true;
 }
@@ -2010,37 +1954,6 @@ bool str_list_compare(char **list1, char **list2)
 	return true;
 }
 
-static void str_list_free_internal(TALLOC_CTX *mem_ctx, char ***list)
-{
-	char **tlist;
-
-	if (!list || !*list)
-		return;
-	tlist = *list;
-	for(; *tlist; tlist++) {
-		if (mem_ctx) {
-			TALLOC_FREE(*tlist);
-		} else {
-			SAFE_FREE(*tlist);
-		}
-	}
-	if (mem_ctx) {
-		TALLOC_FREE(*tlist);
-	} else {
-		SAFE_FREE(*list);
-	}
-}
-
-void str_list_free_talloc(TALLOC_CTX *mem_ctx, char ***list)
-{
-	str_list_free_internal(mem_ctx, list);
-}
-
-void str_list_free(char ***list)
-{
-	str_list_free_internal(NULL, list);
-}
-
 /******************************************************************************
  *****************************************************************************/
 
diff --git a/source/libads/ldap.c b/source/libads/ldap.c
index 7b0adc2..d6b9ba6 100644
--- a/source/libads/ldap.c
+++ b/source/libads/ldap.c
@@ -664,7 +664,7 @@ static ADS_STATUS ads_do_paged_search_args(ADS_STRUCT *ads,
 	else {
 		/* This would be the utf8-encoded version...*/
 		/* if (!(search_attrs = ads_push_strvals(ctx, attrs))) */
-		if (!(str_list_copy(&search_attrs, attrs))) {
+		if (!(str_list_copy(talloc_tos(), &search_attrs, attrs))) {
 			rc = LDAP_NO_MEMORY;
 			goto done;
 		}
@@ -801,7 +801,7 @@ done:
 	}
  
 	/* if/when we decide to utf8-encode attrs, take out this next line */
-	str_list_free(&search_attrs);
+	TALLOC_FREE(search_attrs);
 
 	return ADS_ERROR(rc);
 }
@@ -974,7 +974,7 @@ ADS_STATUS ads_do_search_all_fn(ADS_STRUCT *ads, const char *bind_path,
 	else {
 		/* This would be the utf8-encoded version...*/
 		/* if (!(search_attrs = ads_push_strvals(ctx, attrs)))  */
-		if (!(str_list_copy(&search_attrs, attrs)))
+		if (!(str_list_copy(talloc_tos(), &search_attrs, attrs)))
 		{
 			DEBUG(1,("ads_do_search: str_list_copy() failed!"));
 			rc = LDAP_NO_MEMORY;
@@ -998,7 +998,7 @@ ADS_STATUS ads_do_search_all_fn(ADS_STRUCT *ads, const char *bind_path,
  done:
 	talloc_destroy(ctx);
 	/* if/when we decide to utf8-encode attrs, take out this next line */
-	str_list_free(&search_attrs);
+	TALLOC_FREE(search_attrs);
 	return ADS_ERROR(rc);
 }
 /**
diff --git a/source/libgpo/gpo_ldap.c b/source/libgpo/gpo_ldap.c
index 4e63b92..a34e686 100644
--- a/source/libgpo/gpo_ldap.c
+++ b/source/libgpo/gpo_ldap.c
@@ -44,7 +44,7 @@ bool ads_parse_gp_ext(TALLOC_CTX *mem_ctx,
 		goto parse_error;
 	}
 
-	ext_list = str_list_make_talloc(mem_ctx, extension_raw, "]");
+	ext_list = str_list_make(mem_ctx, extension_raw, "]");
 	if (!ext_list) {
 		goto parse_error;
 	}
@@ -87,7 +87,7 @@ bool ads_parse_gp_ext(TALLOC_CTX *mem_ctx,
 			p++;
 		}
 
-		ext_strings = str_list_make_talloc(mem_ctx, p, "}");
+		ext_strings = str_list_make(mem_ctx, p, "}");
 		if (ext_strings == NULL) {
 			goto parse_error;
 		}
@@ -137,12 +137,8 @@ bool ads_parse_gp_ext(TALLOC_CTX *mem_ctx,
 	ret = True;
 
  parse_error:
-	if (ext_list) {
-		str_list_free_talloc(mem_ctx, &ext_list);
-	}
-	if (ext_strings) {
-		str_list_free_talloc(mem_ctx, &ext_strings);
-	}
+	TALLOC_FREE(ext_list);
+	TALLOC_FREE(ext_strings);
 
 	return ret;
 }
@@ -166,7 +162,7 @@ static ADS_STATUS gpo_parse_gplink(TALLOC_CTX *mem_ctx,
 
 	DEBUG(10,("gpo_parse_gplink: gPLink: %s\n", gp_link_raw));
 
-	link_list = str_list_make_talloc(mem_ctx, gp_link_raw, "]");
+	link_list = str_list_make(mem_ctx, gp_link_raw, "]");
 	if (!link_list) {
 		goto parse_error;
 	}
@@ -226,10 +222,7 @@ static ADS_STATUS gpo_parse_gplink(TALLOC_CTX *mem_ctx,
 	status = ADS_SUCCESS;
 
  parse_error:
-
-	if (link_list) {
-		str_list_free_talloc(mem_ctx, &link_list);
-	}
+	TALLOC_FREE(link_list);
 
 	return status;
 }
diff --git a/source/param/loadparm.c b/source/param/loadparm.c
index c1d26af..8edd32e 100644
--- a/source/param/loadparm.c
+++ b/source/param/loadparm.c
@@ -1691,7 +1691,7 @@ static void init_globals(bool first_time_only)
 	Globals.bWinbindTrustedDomainsOnly = False;
 	Globals.bWinbindNestedGroups = True;
 	Globals.winbind_expand_groups = 1;
-	Globals.szWinbindNssInfo = str_list_make("template", NULL);
+	Globals.szWinbindNssInfo = str_list_make(NULL, "template", NULL);
 	Globals.bWinbindRefreshTickets = False;
 	Globals.bWinbindOfflineLogon = False;
 
@@ -2397,7 +2397,7 @@ const char **lp_parm_string_list(int snum, const char *type, const char *option,
 		return (const char **)def;
 		
 	if (data->list==NULL) {
-		data->list = str_list_make(data->value, NULL);
+		data->list = str_list_make(NULL, data->value, NULL);
 	}
 
 	return (const char **)data->list;
@@ -2494,9 +2494,10 @@ static void free_service(service *pservice)
 				     PTR_DIFF(parm_table[i].ptr, &sDefault)));
 		else if (parm_table[i].type == P_LIST &&
 			 parm_table[i].p_class == P_LOCAL)
-			     str_list_free((char ***)
-			     		    (((char *)pservice) +
-					     PTR_DIFF(parm_table[i].ptr, &sDefault)));
+			     TALLOC_FREE(*((char ***)
+					   (((char *)pservice) +
+					    PTR_DIFF(parm_table[i].ptr,
+						     &sDefault))));
 	}
 
 	data = pservice->param_opt;
@@ -2506,7 +2507,7 @@ static void free_service(service *pservice)
 		DEBUG(5,("[%s = %s]\n", data->key, data->value));
 		string_free(&data->key);
 		string_free(&data->value);
-		str_list_free(&data->list);
+		TALLOC_FREE(data->list);
 		pdata = data->next;
 		SAFE_FREE(data);
 		data = pdata;
@@ -2566,7 +2567,7 @@ static int add_a_service(const service *pservice, const char *name)
 			while (data) {
 				string_free(&data->key);
 				string_free(&data->value);
-				str_list_free(&data->list);
+				TALLOC_FREE(data->list);
 				pdata = data->next;
 				SAFE_FREE(data);
 				data = pdata;
@@ -3275,8 +3276,9 @@ static void copy_service(service * pserviceDest, service * pserviceSource,
 					strupper_m(*(char **)dest_ptr);
 					break;
 				case P_LIST:


-- 
Samba Shared Repository


More information about the samba-cvs mailing list