Rev 5319: merge from upstream in http://samba.sernet.de/ma/bzr/SAMBA_3_0-registry.bzr/

Michael Adam ma at sernet.de
Mon Apr 2 10:52:42 GMT 2007


At http://samba.sernet.de/ma/bzr/SAMBA_3_0-registry.bzr/

------------------------------------------------------------
revno: 5319
revision-id: ma at sernet.de-20070402105238-159cb4e91b4c929d
parent: ma at sernet.de-20070402104821-fc7ac70680bb29af
parent: abartlet at samba.org-20070402050206-f4kg5lajjbejhnd1
committer: Michael Adam <ma at sernet.de>
branch nick: SAMBA_3_0-registry.bzr
timestamp: Mon 2007-04-02 12:52:38 +0200
message:
  merge from upstream
modified:
  REVISION                       REVISION-20060530022625-68239662668b41c3
  source/auth/auth_sam.c         auth_sam.c-20060530022627-a7a4ed7172cd076a
  source/auth/auth_util.c        auth_util.c-20060530022627-f9a3e5940d409fe9
  source/include/smb.h           smb.h-20060530022627-6c2e6fe4eb631e83
  source/lib/util_pw.c           util_pw.c-20060530022627-912c52afc587540f
  source/smbd/password.c         password.c-20060530022627-9a5472626c6d94bc
  source/smbd/session.c          session.c-20060530022627-ee3a7ddb747b92df
    ------------------------------------------------------------
    merged: abartlet at samba.org-20070402050206-f4kg5lajjbejhnd1
    parent: vlendec at samba.org-20070401170202-z94d06sla1xaneg8
    committer: abartlet at samba.org
    branch nick: SAMBA_3_0.bzr
    timestamp: Mon 2007-04-02 00:02:06 -0500
    message:
      abartlet at samba.org (r22020)  2007-04-01 22:46:13 -0500 (Sun, 01 Apr 2007)
          
          Make it more clear that both the vuser struct and it's contents are
          talloc_free()'ed at the end of a session.
          
          Rework the passwd cache code to use talloc_unlink and
          talloc_reference, to more carefully manage the cache.
          
          Andrew Bartlett
          
=== modified file 'REVISION'
--- a/REVISION	2007-04-01 17:02:02 +0000
+++ b/REVISION	2007-04-02 05:02:06 +0000
@@ -2,9 +2,9 @@
 URL: svn+ssh://svn.samba.org/home/svn/samba/branches/SAMBA_3_0
 Repository Root: svn+ssh://svn.samba.org/home/svn/samba
 Repository UUID: 0c0555d6-39d7-0310-84fc-f1cc0bd64818
-Revision: 22019
+Revision: 22020
 Node Kind: directory
-Last Changed Author: vlendec
-Last Changed Rev: 22019
-Last Changed Date: 2007-04-01 08:50:02 -0500 (Sun, 01 Apr 2007)
+Last Changed Author: abartlet
+Last Changed Rev: 22020
+Last Changed Date: 2007-04-01 22:46:13 -0500 (Sun, 01 Apr 2007)
 

=== modified file 'source/auth/auth_sam.c'
--- a/source/auth/auth_sam.c	2006-10-04 00:15:24 +0000
+++ b/source/auth/auth_sam.c	2007-04-02 05:02:06 +0000
@@ -266,7 +266,7 @@
 	/* Can't use the talloc version here, because the returned struct gets
 	   kept on the server_info */
 
-	if ( !(sampass = samu_new( NULL )) ) {
+	if ( !(sampass = samu_new( mem_ctx )) ) {
 		return NT_STATUS_NO_MEMORY;
 	}
 

=== modified file 'source/auth/auth_util.c'
--- a/source/auth/auth_util.c	2007-03-30 20:34:06 +0000
+++ b/source/auth/auth_util.c	2007-04-02 10:52:38 +0000
@@ -523,19 +523,23 @@
 	DOM_SID unix_group_sid;
 	
 
-	if ( !(pwd = getpwnam_alloc(NULL, pdb_get_username(sampass))) ) {
+	if ( !(result = make_server_info(NULL)) ) {
+		TALLOC_FREE(pwd);
+		return NT_STATUS_NO_MEMORY;
+	}
+
+	if ( !(pwd = getpwnam_alloc(result, pdb_get_username(sampass))) ) {
 		DEBUG(1, ("User %s in passdb, but getpwnam() fails!\n",
 			  pdb_get_username(sampass)));
 		return NT_STATUS_NO_SUCH_USER;
 	}
 
-	if ( !(result = make_server_info(NULL)) ) {
-		TALLOC_FREE(pwd);
-		return NT_STATUS_NO_MEMORY;
-	}
-
 	result->sam_account = sampass;
-	result->unix_name = talloc_strdup(result, pwd->pw_name);
+	/* Ensure thaat the sampass will be freed with the result */
+	talloc_steal(result, sampass);
+	result->unix_name = pwd->pw_name;
+	/* Ensure that we keep pwd->pw_name, because we will free pwd below */
+	talloc_steal(result, pwd->pw_name);
 	result->gid = pwd->pw_gid;
 	result->uid = pwd->pw_uid;
 	

=== modified file 'source/include/smb.h'
--- a/source/include/smb.h	2007-03-17 05:00:51 +0000
+++ b/source/include/smb.h	2007-04-02 05:02:06 +0000
@@ -1737,9 +1737,9 @@
 	gid_t gid; /* gid of a validated user */
 
 	userdom_struct user;
-	char *homedir;
-	char *unix_homedir;
-	char *logon_script;
+	const char *homedir;
+	const char *unix_homedir;
+	const char *logon_script;
 	
 	BOOL guest;
 

=== modified file 'source/lib/util_pw.c'
--- a/source/lib/util_pw.c	2006-08-01 08:42:19 +0000
+++ b/source/lib/util_pw.c	2007-04-02 05:02:06 +0000
@@ -98,15 +98,15 @@
 		i = rand() % PWNAMCACHE_SIZE;
 
 	if (pwnam_cache[i] != NULL) {
-		TALLOC_FREE(pwnam_cache[i]);
+		/* Remove this old cache entry, from the cache.  We
+		 * use talloc_unlink here because we want to be very
+		 * clear which referece we are removing */
+		talloc_unlink(pwnam_cache, pwnam_cache[i]);
 	}
 
 	pwnam_cache[i] = tcopy_passwd(pwnam_cache, temp);
-	if (pwnam_cache[i]!= NULL && mem_ctx != NULL) {
-		return (struct passwd *)talloc_reference(mem_ctx, pwnam_cache[i]);
-	}
-
-	return tcopy_passwd(NULL, pwnam_cache[i]);
+	/* while keeping this in the cache, reference a copy for the caller */
+	return (struct passwd *)talloc_reference(mem_ctx, pwnam_cache[i]);
 }
 
 struct passwd *getpwuid_alloc(TALLOC_CTX *mem_ctx, uid_t uid) 

=== modified file 'source/smbd/password.c'
--- a/source/smbd/password.c	2007-02-21 13:14:33 +0000
+++ b/source/smbd/password.c	2007-04-02 05:02:06 +0000
@@ -92,14 +92,7 @@
 	if (vuser == NULL)
 		return;
 	
-	SAFE_FREE(vuser->homedir);
-	SAFE_FREE(vuser->unix_homedir);
-	SAFE_FREE(vuser->logon_script);
-	
 	session_yield(vuser);
-	SAFE_FREE(vuser->session_keystr);
-
-	TALLOC_FREE(vuser->server_info);
 
 	data_blob_free(&vuser->session_key);
 
@@ -109,10 +102,7 @@
 	   from the vuid 'owner' of connections */
 	conn_clear_vuid_cache(vuid);
 
-	SAFE_FREE(vuser->groups);
-	TALLOC_FREE(vuser->nt_user_token);
-
-	SAFE_FREE(vuser);
+	TALLOC_FREE(vuser);
 	num_validated_vuids--;
 }
 
@@ -153,7 +143,7 @@
 		  DATA_BLOB session_key, DATA_BLOB response_blob,
 		  const char *smb_name)
 {
-	user_struct *vuser = NULL;
+	user_struct *vuser;
 
 	/* Paranoia check. */
 	if(lp_security() == SEC_SHARE) {
@@ -166,14 +156,12 @@
 		return UID_FIELD_INVALID;
 	}
 
-	if((vuser = SMB_MALLOC_P(user_struct)) == NULL) {
-		DEBUG(0,("Failed to malloc users struct!\n"));
+	if((vuser = talloc_zero(NULL, user_struct)) == NULL) {
+		DEBUG(0,("Failed to talloc users struct!\n"));
 		data_blob_free(&session_key);
 		return UID_FIELD_INVALID;
 	}
 
-	ZERO_STRUCTP(vuser);
-
 	/* Allocate a free vuid. Yes this is a linear search... :-) */
 	while( get_valid_user_struct(next_vuid) != NULL ) {
 		next_vuid++;
@@ -203,6 +191,11 @@
 		return vuser->vuid;
 	}
 
+	/* use this to keep tabs on all our info from the authentication */
+	vuser->server_info = server_info;
+	/* Ensure that the server_info will dissapear with the vuser it is now attached to */
+	talloc_steal(vuser, vuser->server_info);
+
 	/* the next functions should be done by a SID mapping system (SMS) as
 	 * the new real sam db won't have reference to unix uids or gids
 	 */
@@ -212,14 +205,13 @@
 	
 	vuser->n_groups = server_info->n_groups;
 	if (vuser->n_groups) {
-		if (!(vuser->groups = (gid_t *)memdup(server_info->groups,
-						      sizeof(gid_t) *
-						      vuser->n_groups))) {
-			DEBUG(0,("register_vuid: failed to memdup "
+		if (!(vuser->groups = (gid_t *)talloc_memdup(vuser, server_info->groups,
+							     sizeof(gid_t) *
+							     vuser->n_groups))) {
+			DEBUG(0,("register_vuid: failed to talloc_memdup "
 				 "vuser->groups\n"));
 			data_blob_free(&session_key);
-			free(vuser);
-			TALLOC_FREE(server_info);
+			TALLOC_FREE(vuser);
 			return UID_FIELD_INVALID;
 		}
 	}
@@ -247,24 +239,26 @@
 			const char *unix_homedir =
 				pdb_get_unix_homedir(server_info->sam_account);
 			if (unix_homedir) {
-				vuser->unix_homedir =
-					smb_xstrdup(unix_homedir);
+				vuser->unix_homedir = unix_homedir;
 			}
 		} else {
 			struct passwd *passwd =
-				getpwnam_alloc(NULL, vuser->user.unix_name);
+				getpwnam_alloc(vuser, vuser->user.unix_name);
 			if (passwd) {
-				vuser->unix_homedir =
-					smb_xstrdup(passwd->pw_dir);
+				vuser->unix_homedir = passwd->pw_dir;
+				/* Ensure that the unix_homedir now
+				 * belongs to vuser, so it goes away
+				 * with it, not with passwd below: */
+				talloc_steal(vuser, vuser->unix_homedir);
 				TALLOC_FREE(passwd);
 			}
 		}
 		
 		if (homedir) {
-			vuser->homedir = smb_xstrdup(homedir);
+			vuser->homedir = homedir;
 		}
 		if (logon_script) {
-			vuser->logon_script = smb_xstrdup(logon_script);
+			vuser->logon_script = logon_script;
 		}
 	}
 
@@ -280,23 +274,15 @@
 		  vuser->user.full_name));	
 
  	if (server_info->ptok) {
-		vuser->nt_user_token = dup_nt_token(NULL, server_info->ptok);
+		vuser->nt_user_token = dup_nt_token(vuser, server_info->ptok);
 	} else {
 		DEBUG(1, ("server_info does not contain a user_token - "
 			  "cannot continue\n"));
-		TALLOC_FREE(server_info);
+		TALLOC_FREE(vuser);
 		data_blob_free(&session_key);
-		SAFE_FREE(vuser->homedir);
-		SAFE_FREE(vuser->unix_homedir);
-		SAFE_FREE(vuser->logon_script);
-
-		SAFE_FREE(vuser);
 		return UID_FIELD_INVALID;
 	}
 
-	/* use this to keep tabs on all our info from the authentication */
-	vuser->server_info = server_info;
-
 	DEBUG(3,("UNIX uid %d is UNIX user %s, and will be vuid %u\n",
 		 (int)vuser->uid,vuser->user.unix_name, vuser->vuid));
 

=== modified file 'source/smbd/session.c'
--- a/source/smbd/session.c	2007-03-30 15:43:31 +0000
+++ b/source/smbd/session.c	2007-04-02 05:02:06 +0000
@@ -153,9 +153,9 @@
 			       sessionid.id_str, sessionid.id_num);
 	}
 
-	vuser->session_keystr = SMB_STRDUP(keystr);
+	vuser->session_keystr = talloc_strdup(vuser, keystr);
 	if (!vuser->session_keystr) {
-		DEBUG(0, ("session_claim:  strdup() failed for session_keystr\n"));
+		DEBUG(0, ("session_claim:  talloc_strdup() failed for session_keystr\n"));
 		return False;
 	}
 	return True;



More information about the samba-cvs mailing list