[SCM] Samba Shared Repository - branch v3-2-test updated - initial-v3-2-unstable-344-g15074de

Jeremy Allison jra at samba.org
Wed Nov 21 01:18:52 GMT 2007


The branch, v3-2-test has been updated
       via  15074de938539e7a9c527d9a6d81792adc2ac3d0 (commit)
      from  bac3bb2f6e9e15b3a9a6a6511c484f8509918ca1 (commit)

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


- Log -----------------------------------------------------------------
commit 15074de938539e7a9c527d9a6d81792adc2ac3d0
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Nov 20 17:18:16 2007 -0800

    More pstring elimination.
    Jeremy.

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

Summary of changes:
 source/passdb/passdb.c         |   26 +++++-----
 source/passdb/pdb_get_set.c    |    2 +-
 source/passdb/pdb_interface.c  |   47 ++++++++++++------
 source/passdb/pdb_smbpasswd.c  |   72 ++++++++++++++++----------
 source/passdb/pdb_tdb.c        |  109 ++++++++++++++++++++++++---------------
 source/passdb/secrets.c        |   94 ++++++++++++++++++++++++++++-------
 source/rpc_client/cli_lsarpc.c |    3 +-
 source/rpc_client/cli_pipe.c   |   12 +++--
 source/rpc_parse/parse_prs.c   |    6 +-
 source/winbindd/winbindd.c     |   22 +++++---
 10 files changed, 257 insertions(+), 136 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/passdb/passdb.c b/source/passdb/passdb.c
index a9dd90e..754702e 100644
--- a/source/passdb/passdb.c
+++ b/source/passdb/passdb.c
@@ -864,7 +864,7 @@ bool init_sam_from_buffer_v3(struct samu *sampass, uint8 *buf, uint32 buflen)
 	uint32		lm_pw_len, nt_pw_len, nt_pw_hist_len, hourslen;
 	uint32 pwHistLen = 0;
 	bool ret = True;
-	fstring tmpstring;
+	fstring tmp_string;
 	bool expand_explicit = lp_passdb_expand_explicit();
 	
 	if(sampass == NULL || buf == NULL) {
@@ -930,12 +930,12 @@ bool init_sam_from_buffer_v3(struct samu *sampass, uint8 *buf, uint32 buflen)
 	pdb_set_fullname(sampass, fullname, PDB_SET);
 
 	if (homedir) {
-		fstrcpy( tmpstring, homedir );
+		fstrcpy( tmp_string, homedir );
 		if (expand_explicit) {
-			standard_sub_basic( username, domain, tmpstring,
-					    sizeof(tmpstring) );
+			standard_sub_basic( username, domain, tmp_string,
+					    sizeof(tmp_string) );
 		}
-		pdb_set_homedir(sampass, tmpstring, PDB_SET);
+		pdb_set_homedir(sampass, tmp_string, PDB_SET);
 	}
 	else {
 		pdb_set_homedir(sampass, 
@@ -950,12 +950,12 @@ bool init_sam_from_buffer_v3(struct samu *sampass, uint8 *buf, uint32 buflen)
 		pdb_set_dir_drive(sampass, lp_logon_drive(), PDB_DEFAULT );
 
 	if (logon_script) {
-		fstrcpy( tmpstring, logon_script );
+		fstrcpy( tmp_string, logon_script );
 		if (expand_explicit) {
-			standard_sub_basic( username, domain, tmpstring,
-					    sizeof(tmpstring) );
+			standard_sub_basic( username, domain, tmp_string,
+					    sizeof(tmp_string) );
 		}
-		pdb_set_logon_script(sampass, tmpstring, PDB_SET);
+		pdb_set_logon_script(sampass, tmp_string, PDB_SET);
 	}
 	else {
 		pdb_set_logon_script(sampass, 
@@ -965,12 +965,12 @@ bool init_sam_from_buffer_v3(struct samu *sampass, uint8 *buf, uint32 buflen)
 	}
 	
 	if (profile_path) {	
-		fstrcpy( tmpstring, profile_path );
+		fstrcpy( tmp_string, profile_path );
 		if (expand_explicit) {
-			standard_sub_basic( username, domain, tmpstring,
-					    sizeof(tmpstring) );
+			standard_sub_basic( username, domain, tmp_string,
+					    sizeof(tmp_string) );
 		}
-		pdb_set_profile_path(sampass, tmpstring, PDB_SET);
+		pdb_set_profile_path(sampass, tmp_string, PDB_SET);
 	} 
 	else {
 		pdb_set_profile_path(sampass, 
diff --git a/source/passdb/pdb_get_set.c b/source/passdb/pdb_get_set.c
index aaba916..e8bea19 100644
--- a/source/passdb/pdb_get_set.c
+++ b/source/passdb/pdb_get_set.c
@@ -29,7 +29,7 @@
 /**
  * @todo Redefine this to NULL, but this changes the API because
  *       much of samba assumes that the pdb_get...() funtions 
- *       return pstrings.  (ie not null-pointers).
+ *       return strings.  (ie not null-pointers).
  *       See also pdb_fill_default_sam().
  */
 
diff --git a/source/passdb/pdb_interface.c b/source/passdb/pdb_interface.c
index c55d325..0159932 100644
--- a/source/passdb/pdb_interface.c
+++ b/source/passdb/pdb_interface.c
@@ -182,18 +182,20 @@ static struct pdb_methods *pdb_get_methods_reload( bool reload )
 	if ( pdb && reload ) {
 		pdb->free_private_data( &(pdb->private_data) );
 		if ( !NT_STATUS_IS_OK( make_pdb_method_name( &pdb, lp_passdb_backend() ) ) ) {
-			pstring msg;
-			slprintf(msg, sizeof(msg)-1, "pdb_get_methods_reload: failed to get pdb methods for backend %s\n",
-				lp_passdb_backend() );
+			char *msg = NULL;
+			asprintf(&msg, "pdb_get_methods_reload: "
+				"failed to get pdb methods for backend %s\n",
+				lp_passdb_backend());
 			smb_panic(msg);
 		}
 	}
 
 	if ( !pdb ) {
 		if ( !NT_STATUS_IS_OK( make_pdb_method_name( &pdb, lp_passdb_backend() ) ) ) {
-			pstring msg;
-			slprintf(msg, sizeof(msg)-1, "pdb_get_methods_reload: failed to get pdb methods for backend %s\n",
-				lp_passdb_backend() );
+			char *msg = NULL;
+			asprintf(&msg, "pdb_get_methods_reload: "
+				"failed to get pdb methods for backend %s\n",
+				lp_passdb_backend());
 			smb_panic(msg);
 		}
 	}
@@ -319,17 +321,19 @@ static NTSTATUS pdb_default_create_user(struct pdb_methods *methods,
 	}
 
 	if ( !(pwd = Get_Pwnam_alloc(tmp_ctx, name)) ) {
-		pstring add_script;
+		char *add_script = NULL;
 		int add_ret;
 		fstring name2;
 
 		if ((acb_info & ACB_NORMAL) && name[strlen(name)-1] != '$') {
-			pstrcpy(add_script, lp_adduser_script());
+			add_script = talloc_strdup(tmp_ctx,
+					lp_adduser_script());
 		} else {
-			pstrcpy(add_script, lp_addmachine_script());
+			add_script = talloc_strdup(tmp_ctx,
+					lp_addmachine_script());
 		}
 
-		if (add_script[0] == '\0') {
+		if (!add_script || add_script[0] == '\0') {
 			DEBUG(3, ("Could not find user %s and no add script "
 				  "defined\n", name));
 			return NT_STATUS_NO_SUCH_USER;
@@ -339,7 +343,13 @@ static NTSTATUS pdb_default_create_user(struct pdb_methods *methods,
 		   compatibility with previous Samba releases */
 		fstrcpy( name2, name );
 		strlower_m( name2 );
-		all_string_sub(add_script, "%u", name2, sizeof(add_script));
+		add_script = talloc_all_string_sub(tmp_ctx,
+					add_script,
+					"%u",
+					name2);
+		if (!add_script) {
+			return NT_STATUS_NO_MEMORY;
+		}
 		add_ret = smbrun(add_script,NULL);
 		DEBUG(add_ret ? 0 : 3, ("_samr_create_user: Running the command `%s' gave %d\n",
 					add_script, add_ret));
@@ -399,7 +409,7 @@ NTSTATUS pdb_create_user(TALLOC_CTX *mem_ctx, const char *name, uint32 flags,
 
 static int smb_delete_user(const char *unix_user)
 {
-	pstring del_script;
+	char *del_script = NULL;
 	int ret;
 
 	/* safety check */
@@ -409,10 +419,17 @@ static int smb_delete_user(const char *unix_user)
 		return -1;
 	}
 
-	pstrcpy(del_script, lp_deluser_script());
-	if (! *del_script)
+	del_script = talloc_strdup(talloc_tos(), lp_deluser_script());
+	if (!del_script || !*del_script) {
+		return -1;
+	}
+	del_script = talloc_all_string_sub(talloc_tos(),
+				del_script,
+				"%u",
+				unix_user);
+	if (!del_script) {
 		return -1;
-	all_string_sub(del_script, "%u", unix_user, sizeof(del_script));
+	}
 	ret = smbrun(del_script,NULL);
 	flush_pwnam_cache();
 	if (ret == 0) {
diff --git a/source/passdb/pdb_smbpasswd.c b/source/passdb/pdb_smbpasswd.c
index 0cec762..139aa14 100644
--- a/source/passdb/pdb_smbpasswd.c
+++ b/source/passdb/pdb_smbpasswd.c
@@ -53,7 +53,7 @@ struct smbpasswd_privates
 	
 	/* formerly static variables */
 	struct smb_passwd pw_buf;
-	pstring  user_name;
+	fstring user_name;
 	unsigned char smbpwd[16];
 	unsigned char smbntpwd[16];
 
@@ -437,12 +437,6 @@ static struct smb_passwd *getsmbfilepwent(struct smbpasswd_privates *smbpasswd_s
 			continue;
 		}
 
-		/*
-		 * As 256 is shorter than a pstring we don't need to check
-		 * length here - if this ever changes....
-		 */
-		SMB_ASSERT(sizeof(pstring) > sizeof(linebuf));
-
 		strncpy(user_name, linebuf, PTR_DIFF(p, linebuf));
 		user_name[PTR_DIFF(p, linebuf)] = '\0';
 
@@ -731,7 +725,7 @@ Error was %s. Password file may be corrupt ! Please examine by hand !\n",
 static bool mod_smbfilepwd_entry(struct smbpasswd_privates *smbpasswd_state, const struct smb_passwd* pwd)
 {
 	/* Static buffers we will return. */
-	pstring user_name;
+	fstring user_name;
 
 	char *status;
 	char linebuf[256];
@@ -847,13 +841,6 @@ static bool mod_smbfilepwd_entry(struct smbpasswd_privates *smbpasswd_state, con
 			continue;
 		}
 
-		/*
-		 * As 256 is shorter than a pstring we don't need to check
-		 * length here - if this ever changes....
-		 */
-
-		SMB_ASSERT(sizeof(user_name) > sizeof(linebuf));
-
 		strncpy(user_name, linebuf, PTR_DIFF(p, linebuf));
 		user_name[PTR_DIFF(p, linebuf)] = '\0';
 		if (strequal(user_name, pwd->smb_name)) {
@@ -1091,13 +1078,18 @@ This is no longer supported.!\n", pwd->smb_name));
 static bool del_smbfilepwd_entry(struct smbpasswd_privates *smbpasswd_state, const char *name)
 {
 	const char *pfile = smbpasswd_state->smbpasswd_file;
-	pstring pfile2;
+	char *pfile2 = NULL;
 	struct smb_passwd *pwd = NULL;
 	FILE *fp = NULL;
 	FILE *fp_write = NULL;
 	int pfile2_lockdepth = 0;
 
-	slprintf(pfile2, sizeof(pfile2)-1, "%s.%u", pfile, (unsigned)sys_getpid() );
+	pfile2 = talloc_asprintf(talloc_tos(),
+			"%s.%u",
+			pfile, (unsigned)sys_getpid());
+	if (!pfile2) {
+		return false;
+	}
 
 	/*
 	 * Open the smbpassword file - for update. It needs to be update
@@ -1179,7 +1171,7 @@ Error was %s\n", pwd->smb_name, pfile2, strerror(errno)));
 	if(rename(pfile2,pfile) != 0) {
 		unlink(pfile2);
 	}
-  
+
 	endsmbfilepwent(fp, &smbpasswd_state->pw_file_lock_depth);
 	endsmbfilepwent(fp_write,&pfile2_lockdepth);
 	return True;
@@ -1511,9 +1503,10 @@ static NTSTATUS smbpasswd_rename_sam_account (struct pdb_methods *my_methods,
 					      struct samu *old_acct,
 					      const char *newname)
 {
-	pstring rename_script;
+	char *rename_script = NULL;
 	struct samu *new_acct = NULL;
 	bool interim_account = False;
+	TALLOC_CTX *ctx = talloc_tos();
 	NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
 
 	if (!*(lp_renameuser_script()))
@@ -1528,7 +1521,7 @@ static NTSTATUS smbpasswd_rename_sam_account (struct pdb_methods *my_methods,
 	{
 		goto done;
 	}
-	
+
 	ret = smbpasswd_add_sam_account(my_methods, new_acct);
 	if (!NT_STATUS_IS_OK(ret))
 		goto done;
@@ -1536,15 +1529,38 @@ static NTSTATUS smbpasswd_rename_sam_account (struct pdb_methods *my_methods,
 	interim_account = True;
 
 	/* rename the posix user */
-	pstrcpy(rename_script, lp_renameuser_script());
+	rename_script = talloc_strdup(ctx,
+				lp_renameuser_script());
+	if (!rename_script) {
+		ret = NT_STATUS_NO_MEMORY;
+		goto done;
+	}
 
 	if (*rename_script) {
 	        int rename_ret;
 
-		string_sub2(rename_script, "%unew", newname, sizeof(pstring), 
-			    True, False, True);
-		string_sub2(rename_script, "%uold", pdb_get_username(old_acct), 
-			    sizeof(pstring), True, False, True);
+		rename_script = talloc_string_sub2(ctx,
+					rename_script,
+					"%unew",
+					newname,
+					true,
+					false,
+					true);
+		if (!rename_script) {
+			ret = NT_STATUS_NO_MEMORY;
+			goto done;
+		}
+		rename_script = talloc_string_sub2(ctx,
+					rename_script,
+					"%uold",
+					pdb_get_username(old_acct),
+					true,
+					false,
+					true);
+		if (!rename_script) {
+			ret = NT_STATUS_NO_MEMORY;
+			goto done;
+		}
 
 		rename_ret = smbrun(rename_script, NULL);
 
@@ -1554,8 +1570,8 @@ static NTSTATUS smbpasswd_rename_sam_account (struct pdb_methods *my_methods,
 			smb_nscd_flush_user_cache();
 		}
 
-		if (rename_ret) 
-			goto done; 
+		if (rename_ret)
+			goto done;
         } else {
 		goto done;
 	}
@@ -1563,7 +1579,7 @@ static NTSTATUS smbpasswd_rename_sam_account (struct pdb_methods *my_methods,
 	smbpasswd_delete_sam_account(my_methods, old_acct);
 	interim_account = False;
 
-done:	
+done:
 	/* cleanup */
 	if (interim_account)
 		smbpasswd_delete_sam_account(my_methods, new_acct);
diff --git a/source/passdb/pdb_tdb.c b/source/passdb/pdb_tdb.c
index 099b443..fe8497c 100644
--- a/source/passdb/pdb_tdb.c
+++ b/source/passdb/pdb_tdb.c
@@ -481,7 +481,7 @@ bool init_sam_from_buffer_v2(struct samu *sampass, uint8 *buf, uint32 buflen)
 	uint32		lm_pw_len, nt_pw_len, nt_pw_hist_len, hourslen;
 	uint32 pwHistLen = 0;
 	bool ret = True;
-	fstring tmpstring;
+	fstring tmp_string;
 	bool expand_explicit = lp_passdb_expand_explicit();
 	
 	if(sampass == NULL || buf == NULL) {
@@ -546,12 +546,12 @@ bool init_sam_from_buffer_v2(struct samu *sampass, uint8 *buf, uint32 buflen)
 	pdb_set_fullname(sampass, fullname, PDB_SET);
 
 	if (homedir) {
-		fstrcpy( tmpstring, homedir );
+		fstrcpy( tmp_string, homedir );
 		if (expand_explicit) {
-			standard_sub_basic( username, domain, tmpstring,
-					    sizeof(tmpstring) );
+			standard_sub_basic( username, domain, tmp_string,
+					    sizeof(tmp_string) );
 		}
-		pdb_set_homedir(sampass, tmpstring, PDB_SET);
+		pdb_set_homedir(sampass, tmp_string, PDB_SET);
 	}
 	else {
 		pdb_set_homedir(sampass, 
@@ -566,12 +566,12 @@ bool init_sam_from_buffer_v2(struct samu *sampass, uint8 *buf, uint32 buflen)
 		pdb_set_dir_drive(sampass, lp_logon_drive(), PDB_DEFAULT );
 
 	if (logon_script) {
-		fstrcpy( tmpstring, logon_script );
+		fstrcpy( tmp_string, logon_script );
 		if (expand_explicit) {
-			standard_sub_basic( username, domain, tmpstring,
-					    sizeof(tmpstring) );
+			standard_sub_basic( username, domain, tmp_string,
+					    sizeof(tmp_string) );
 		}
-		pdb_set_logon_script(sampass, tmpstring, PDB_SET);
+		pdb_set_logon_script(sampass, tmp_string, PDB_SET);
 	}
 	else {
 		pdb_set_logon_script(sampass, 
@@ -581,12 +581,12 @@ bool init_sam_from_buffer_v2(struct samu *sampass, uint8 *buf, uint32 buflen)
 	}
 	
 	if (profile_path) {	
-		fstrcpy( tmpstring, profile_path );
+		fstrcpy( tmp_string, profile_path );
 		if (expand_explicit) {
-			standard_sub_basic( username, domain, tmpstring,
-					    sizeof(tmpstring) );
+			standard_sub_basic( username, domain, tmp_string,
+					    sizeof(tmp_string) );
 		}
-		pdb_set_profile_path(sampass, tmpstring, PDB_SET);
+		pdb_set_profile_path(sampass, tmp_string, PDB_SET);
 	} 
 	else {
 		pdb_set_profile_path(sampass, 
@@ -1375,40 +1375,43 @@ static NTSTATUS tdbsam_add_sam_account (struct pdb_methods *my_methods, struct s
  - unlock the new user record
 ***************************************************************************/
 static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods,
-					  struct samu *old_acct, 
+					  struct samu *old_acct,
 					  const char *newname)
 {
+	TALLOC_CTX *ctx = talloc_tos();
 	struct samu      *new_acct = NULL;
-	pstring          rename_script;
+	char *rename_script = NULL;
 	bool             interim_account = False;
 	int              rename_ret;
 	fstring          oldname_lower;
 	fstring          newname_lower;
 
 	/* can't do anything without an external script */
-	
-	pstrcpy(rename_script, lp_renameuser_script() );
-	if ( ! *rename_script ) {
+
+	rename_script = talloc_strdup(ctx, lp_renameuser_script());
+	if (!rename_script) {
+		return NT_STATUS_NO_MEMORY;
+	}
+	if (!*rename_script) {
 		return NT_STATUS_ACCESS_DENIED;
 	}
 
 	/* invalidate the existing TDB iterator if it is open */
-	
+
 	tdbsam_endsampwent( my_methods );
 
 	if ( !(new_acct = samu_new( NULL )) ) {
 		return NT_STATUS_NO_MEMORY;
 	}
-	
-	if ( !pdb_copy_sam_account(new_acct, old_acct) 
-		|| !pdb_set_username(new_acct, newname, PDB_CHANGED)) 
+
+	if ( !pdb_copy_sam_account(new_acct, old_acct)
+		|| !pdb_set_username(new_acct, newname, PDB_CHANGED))
 	{
 		TALLOC_FREE(new_acct );
 		return NT_STATUS_NO_MEMORY;
 	}
 
 	/* open the database */
-		
 	if ( !tdbsam_open( tdbsam_filename ) ) {
 		DEBUG(0,("tdbsam_getsampwnam: failed to open %s!\n", tdbsam_filename));
 		TALLOC_FREE(new_acct );
@@ -1416,11 +1419,10 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods,
 	}
 
 	/* add the new account and lock it */
-	
 	if ( !tdb_update_samacct_only(new_acct, TDB_INSERT) ) {
 		goto done;
 	}
-	
+
 	interim_account = True;
 
 	if ( tdb_lock_bystring_with_timeout(tdbsam, newname, 30) == -1 ) {
@@ -1436,24 +1438,41 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods,
 	fstrcpy( newname_lower, newname );
 	strlower_m( newname_lower );
 
-	string_sub2(rename_script, "%unew", newname_lower, sizeof(pstring), 
-		True, False, True);
-	string_sub2(rename_script, "%uold", oldname_lower, sizeof(pstring), 
-		True, False, True);
+	rename_script = talloc_string_sub2(ctx,
+				rename_script,
+				"%unew",
+				newname_lower,
+				true,
+				false,
+				true);
+	if (!rename_script) {
+		goto done;
+	}
+	rename_script = talloc_string_sub2(ctx,
+				rename_script,
+				"%uold",
+				oldname_lower,
+				true,
+				false,
+				true);
+	if (!rename_script) {
+		goto done;
+	}


-- 
Samba Shared Repository


More information about the samba-cvs mailing list