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

Jeremy Allison jra at samba.org
Fri Nov 7 04:51:02 GMT 2008


The branch, v3-3-test has been updated
       via  33013e40f5f4fb639ad0d3a9bd8565cd18062165 (commit)
      from  8d0cec27857762a2852eb2db3aec9ea9a19f549b (commit)

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


- Log -----------------------------------------------------------------
commit 33013e40f5f4fb639ad0d3a9bd8565cd18062165
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Nov 6 20:50:11 2008 -0800

    Make us clean under valgrind --leak-check=full by using talloc_autofree_context() instead of NULL.
    Remove the code in memcache that does a TALLOC_FREE on stored pointers. That's a disaster waiting
    to happen. If you're storing talloc'ed pointers, you can't know their lifecycle and they should
    be deleted when their parent context is deleted, so freeing them at some arbitrary point later
    will be a double-free.
    Jeremy.

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

Summary of changes:
 source/auth/token_util.c      |    2 +-
 source/lib/genrand.c          |    2 +-
 source/lib/memcache.c         |   26 --------------------------
 source/lib/util.c             |    6 +++---
 source/lib/util_pw.c          |    2 +-
 source/param/loadparm.c       |    8 ++++----
 source/passdb/passdb.c        |    2 +-
 source/passdb/pdb_interface.c |    4 ++--
 source/passdb/util_unixsids.c |    2 +-
 source/smbd/server.c          |    6 +++---
 source/smbd/uid.c             |    2 +-
 source/utils/net_sam.c        |    2 +-
 source/utils/pdbedit.c        |    4 ++--
 source/utils/smbpasswd.c      |    4 ++--
 source/web/cgi.c              |    4 ++--
 15 files changed, 25 insertions(+), 51 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/auth/token_util.c b/source/auth/token_util.c
index d6cd2ea..bb8f222 100644
--- a/source/auth/token_util.c
+++ b/source/auth/token_util.c
@@ -102,7 +102,7 @@ NT_USER_TOKEN *get_root_nt_token( void )
 	uid_to_sid(&u_sid, pw->pw_uid);
 	gid_to_sid(&g_sid, pw->pw_gid);
 
-	token = create_local_nt_token(NULL, &u_sid, False,
+	token = create_local_nt_token(talloc_autofree_context(), &u_sid, False,
 				      1, &global_sid_Builtin_Administrators);
 
 	token->privileges = se_disk_operators;
diff --git a/source/lib/genrand.c b/source/lib/genrand.c
index 4590b81..3c513ea 100644
--- a/source/lib/genrand.c
+++ b/source/lib/genrand.c
@@ -113,7 +113,7 @@ static int do_reseed(bool use_fd, int fd)
 	 * seriously this will be secret.
 	 */
 
-	pw = getpwnam_alloc(NULL, "root");
+	pw = getpwnam_alloc(talloc_autofree_context(), "root");
 	if (pw && pw->pw_passwd) {
 		size_t i;
 		unsigned char md4_tmp[16];
diff --git a/source/lib/memcache.c b/source/lib/memcache.c
index e1426bc..74bc804 100644
--- a/source/lib/memcache.c
+++ b/source/lib/memcache.c
@@ -40,37 +40,11 @@ struct memcache {
 static void memcache_element_parse(struct memcache_element *e,
 				   DATA_BLOB *key, DATA_BLOB *value);
 
-static bool memcache_is_talloc(enum memcache_number n)
-{
-	bool result;
-
-	switch (n) {
-	case GETPWNAM_CACHE:
-	case PDB_GETPWSID_CACHE:
-	case SINGLETON_CACHE_TALLOC:
-		result = true;
-		break;
-	default:
-		result = false;
-		break;
-	}
-
-	return result;
-}
-
 static int memcache_destructor(struct memcache *cache) {
 	struct memcache_element *e, *next;
 
 	for (e = cache->mru; e != NULL; e = next) {
 		next = e->next;
-		if (memcache_is_talloc((enum memcache_number)e->n)
-		    && (e->valuelength == sizeof(void *))) {
-			DATA_BLOB key, value;
-			void *ptr;
-			memcache_element_parse(e, &key, &value);
-			memcpy(&ptr, value.data, sizeof(ptr));
-			TALLOC_FREE(ptr);
-		}
 		SAFE_FREE(e);
 	}
 	return 0;
diff --git a/source/lib/util.c b/source/lib/util.c
index 201d87a..4b8b597 100644
--- a/source/lib/util.c
+++ b/source/lib/util.c
@@ -1608,7 +1608,7 @@ uid_t nametouid(const char *name)
 	char *p;
 	uid_t u;
 
-	pass = getpwnam_alloc(NULL, name);
+	pass = getpwnam_alloc(talloc_autofree_context(), name);
 	if (pass) {
 		u = pass->pw_uid;
 		TALLOC_FREE(pass);
@@ -2541,8 +2541,8 @@ char *myhostname(void)
 	static char *ret;
 	if (ret == NULL) {
 		/* This is cached forever so
-		 * use NULL talloc ctx. */
-		ret = get_myname(NULL);
+		 * use autofree talloc ctx. */
+		ret = get_myname(talloc_autofree_context());
 	}
 	return ret;
 }
diff --git a/source/lib/util_pw.c b/source/lib/util_pw.c
index 4283785..4f2a032 100644
--- a/source/lib/util_pw.c
+++ b/source/lib/util_pw.c
@@ -57,7 +57,7 @@ struct passwd *getpwnam_alloc(TALLOC_CTX *mem_ctx, const char *name)
 		return NULL;
 	}
 
-	cached = tcopy_passwd(NULL, temp);
+	cached = tcopy_passwd(talloc_autofree_context(), temp);
 	if (cached == NULL) {
 		/*
 		 * Just don't add this into the cache, ignore the failure
diff --git a/source/param/loadparm.c b/source/param/loadparm.c
index 2612b09..99f2569 100644
--- a/source/param/loadparm.c
+++ b/source/param/loadparm.c
@@ -4858,7 +4858,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(NULL, "template", NULL);
+	Globals.szWinbindNssInfo = str_list_make(talloc_autofree_context(), "template", NULL);
 	Globals.bWinbindRefreshTickets = False;
 	Globals.bWinbindOfflineLogon = False;
 
@@ -5574,7 +5574,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(NULL, data->value, NULL);
+		data->list = str_list_make(talloc_autofree_context(), data->value, NULL);
 	}
 
 	return (const char **)data->list;
@@ -6842,7 +6842,7 @@ static bool handle_netbios_scope(int snum, const char *pszParmValue, char **ptr)
 static bool handle_netbios_aliases(int snum, const char *pszParmValue, char **ptr)
 {
 	TALLOC_FREE(Globals.szNetbiosAliases);
-	Globals.szNetbiosAliases = str_list_make(NULL, pszParmValue, NULL);
+	Globals.szNetbiosAliases = str_list_make(talloc_autofree_context(), pszParmValue, NULL);
 	return set_netbios_aliases((const char **)Globals.szNetbiosAliases);
 }
 
@@ -7277,7 +7277,7 @@ bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
 		case P_LIST:
 			TALLOC_FREE(*((char ***)parm_ptr));
 			*(char ***)parm_ptr = str_list_make(
-				NULL, pszParmValue, NULL);
+				talloc_autofree_context(), pszParmValue, NULL);
 			break;
 
 		case P_STRING:
diff --git a/source/passdb/passdb.c b/source/passdb/passdb.c
index 1606c64..16d5e0f 100644
--- a/source/passdb/passdb.c
+++ b/source/passdb/passdb.c
@@ -665,7 +665,7 @@ NTSTATUS local_password_change(const char *user_name,
 				DEBUGLEVEL = 1;
 			}
 
-			if ( !(pwd = getpwnam_alloc( NULL, user_name)) ) {
+			if ( !(pwd = getpwnam_alloc(talloc_autofree_context(), user_name)) ) {
 				return NT_STATUS_NO_SUCH_USER;
 			}
 
diff --git a/source/passdb/pdb_interface.c b/source/passdb/pdb_interface.c
index fcb38b4..6fe1058 100644
--- a/source/passdb/pdb_interface.c
+++ b/source/passdb/pdb_interface.c
@@ -242,7 +242,7 @@ bool guest_user_info( struct samu *user )
 	NTSTATUS result;
 	const char *guestname = lp_guestaccount();
 	
-	if ( !(pwd = getpwnam_alloc( NULL, guestname ) ) ) {
+	if ( !(pwd = getpwnam_alloc(talloc_autofree_context(), guestname ) ) ) {
 		DEBUG(0,("guest_user_info: Unable to locate guest account [%s]!\n", 
 			guestname));
 		return False;
@@ -2016,7 +2016,7 @@ NTSTATUS make_pdb_method( struct pdb_methods **methods )
 {
 	/* allocate memory for the structure as its own talloc CTX */
 
-	if ( !(*methods = TALLOC_ZERO_P(NULL, struct pdb_methods) ) ) {
+	if ( !(*methods = TALLOC_ZERO_P(talloc_autofree_context(), struct pdb_methods) ) ) {
 		return NT_STATUS_NO_MEMORY;
 	}
 
diff --git a/source/passdb/util_unixsids.c b/source/passdb/util_unixsids.c
index 1b674d0..ad4e702 100644
--- a/source/passdb/util_unixsids.c
+++ b/source/passdb/util_unixsids.c
@@ -56,7 +56,7 @@ bool lookup_unix_user_name(const char *name, DOM_SID *sid)
 {
 	struct passwd *pwd;
 
-	pwd = getpwnam_alloc(NULL, name);
+	pwd = getpwnam_alloc(talloc_autofree_context(), name);
 	if (pwd == NULL) {
 		return False;
 	}
diff --git a/source/smbd/server.c b/source/smbd/server.c
index 69a483e..ae36c7d 100644
--- a/source/smbd/server.c
+++ b/source/smbd/server.c
@@ -80,7 +80,7 @@ struct event_context *smbd_event_context(void)
 {
 	static struct event_context *ctx;
 
-	if (!ctx && !(ctx = event_context_init(NULL))) {
+	if (!ctx && !(ctx = event_context_init(talloc_autofree_context()))) {
 		smb_panic("Could not init smbd event context");
 	}
 	return ctx;
@@ -91,7 +91,7 @@ struct messaging_context *smbd_messaging_context(void)
 	static struct messaging_context *ctx;
 
 	if (ctx == NULL) {
-		ctx = messaging_init(NULL, server_id_self(),
+		ctx = messaging_init(talloc_autofree_context(), server_id_self(),
 				     smbd_event_context());
 	}
 	if (ctx == NULL) {
@@ -105,7 +105,7 @@ struct memcache *smbd_memcache(void)
 	static struct memcache *cache;
 
 	if (!cache
-	    && !(cache = memcache_init(NULL,
+	    && !(cache = memcache_init(talloc_autofree_context(),
 				       lp_max_stat_cache_size()*1024))) {
 
 		smb_panic("Could not init smbd memcache");
diff --git a/source/smbd/uid.c b/source/smbd/uid.c
index 8998f6a..045de6f 100644
--- a/source/smbd/uid.c
+++ b/source/smbd/uid.c
@@ -32,7 +32,7 @@ bool change_to_guest(void)
 
 	if (!pass) {
 		/* Don't need to free() this as its stored in a static */
-		pass = getpwnam_alloc(NULL, lp_guestaccount());
+		pass = getpwnam_alloc(talloc_autofree_context(), lp_guestaccount());
 		if (!pass)
 			return(False);
 	}
diff --git a/source/utils/net_sam.c b/source/utils/net_sam.c
index ce13213..e8ebb60 100644
--- a/source/utils/net_sam.c
+++ b/source/utils/net_sam.c
@@ -1735,7 +1735,7 @@ doma_done:
 
 	d_printf("Checking Guest's group.\n");
 
-	pwd = getpwnam_alloc(NULL, lp_guestaccount());
+	pwd = getpwnam_alloc(talloc_autofree_context(), lp_guestaccount());
 	if (!pwd) {
 		d_fprintf(stderr, "Failed to find just created Guest account!\n"
 				  "   Is nss properly configured?!\n");
diff --git a/source/utils/pdbedit.c b/source/utils/pdbedit.c
index e1d6709..5449c8b 100644
--- a/source/utils/pdbedit.c
+++ b/source/utils/pdbedit.c
@@ -564,7 +564,7 @@ static int new_user (struct pdb_methods *in, const char *username,
 
 	get_global_sam_sid();
 
-	if ( !(pwd = getpwnam_alloc( NULL, username )) ) {
+	if ( !(pwd = getpwnam_alloc(talloc_autofree_context(), username )) ) {
 		DEBUG(0,("Cannot locate Unix account for %s\n", username));
 		return -1;
 	}
@@ -668,7 +668,7 @@ static int new_machine (struct pdb_methods *in, const char *machine_in)
 	fstrcpy(machineaccount, machinename);
 	fstrcat(machineaccount, "$");
 
-	if ( !(pwd = getpwnam_alloc( NULL, machineaccount )) ) {
+	if ( !(pwd = getpwnam_alloc(talloc_autofree_context(), machineaccount )) ) {
 		DEBUG(0,("Cannot locate Unix account for %s\n", machineaccount));
 		return -1;
 	}
diff --git a/source/utils/smbpasswd.c b/source/utils/smbpasswd.c
index 493a249..b18ab55 100644
--- a/source/utils/smbpasswd.c
+++ b/source/utils/smbpasswd.c
@@ -337,7 +337,7 @@ static int process_root(int local_flags)
 		load_interfaces();
 	}
 
-	if (!user_name[0] && (pwd = getpwuid_alloc(NULL, geteuid()))) {
+	if (!user_name[0] && (pwd = getpwuid_alloc(talloc_autofree_context(), geteuid()))) {
 		fstrcpy(user_name, pwd->pw_name);
 		TALLOC_FREE(pwd);
 	} 
@@ -498,7 +498,7 @@ static int process_nonroot(int local_flags)
 	}
 
 	if (!user_name[0]) {
-		pwd = getpwuid_alloc(NULL, getuid());
+		pwd = getpwuid_alloc(talloc_autofree_context(), getuid());
 		if (pwd) {
 			fstrcpy(user_name,pwd->pw_name);
 			TALLOC_FREE(pwd);
diff --git a/source/web/cgi.c b/source/web/cgi.c
index 070e80c..bcb4ccd 100644
--- a/source/web/cgi.c
+++ b/source/web/cgi.c
@@ -314,7 +314,7 @@ static void cgi_web_auth(void)
 		exit(0);
 	}
 
-	pwd = getpwnam_alloc(NULL, user);
+	pwd = getpwnam_alloc(talloc_autofree_context(), user);
 	if (!pwd) {
 		printf("%sCannot find user %s<br>%s\n", head, user, tail);
 		exit(0);
@@ -367,7 +367,7 @@ static bool cgi_handle_authorization(char *line)
 	 * Try and get the user from the UNIX password file.
 	 */
 	
-	pass = getpwnam_alloc(NULL, user);
+	pass = getpwnam_alloc(talloc_autofree_context(), user);
 	
 	/*
 	 * Validate the password they have given.


-- 
Samba Shared Repository


More information about the samba-cvs mailing list