[SCM] Samba Shared Repository - branch v3-2-test updated - initial-v3-2-unstable-366-g49949f0

Jeremy Allison jra at samba.org
Fri Nov 23 21:15:48 GMT 2007


The branch, v3-2-test has been updated
       via  49949f0b85007c7c2b3c340c12f3d18909862135 (commit)
      from  9751cc222c70fd669a1cc1ad61ffb4e2e8444019 (commit)

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


- Log -----------------------------------------------------------------
commit 49949f0b85007c7c2b3c340c12f3d18909862135
Author: Volker Lendecke <vl at sernet.de>
Date:   Fri Nov 23 12:04:35 2007 +0100

    Make remote_password_change return malloced error strings
    
    This fixes a segfault in smbpasswd -r

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

Summary of changes:
 source/libsmb/passchange.c |   69 ++++++++++++++++++++++++-------------------
 source/utils/smbpasswd.c   |    5 ++-
 source/web/swat.c          |    7 ++--
 3 files changed, 45 insertions(+), 36 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/libsmb/passchange.c b/source/libsmb/passchange.c
index f5057ec..9941b72 100644
--- a/source/libsmb/passchange.c
+++ b/source/libsmb/passchange.c
@@ -24,8 +24,8 @@
 *************************************************************/
 
 NTSTATUS remote_password_change(const char *remote_machine, const char *user_name, 
-			    const char *old_passwd, const char *new_passwd,
-			    char *err_str, size_t err_str_len)
+				const char *old_passwd, const char *new_passwd,
+				char **err_str)
 {
 	struct nmb_name calling, called;
 	struct cli_state *cli;
@@ -35,11 +35,11 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
 	NTSTATUS result;
 	bool pass_must_change = False;
 
-	*err_str = '\0';
+	*err_str = NULL;
 
 	if(!resolve_name( remote_machine, &ss, 0x20)) {
-		slprintf(err_str, err_str_len-1, "Unable to find an IP address for machine %s.\n",
-			remote_machine );
+		asprintf(err_str, "Unable to find an IP address for machine "
+			 "%s.\n", remote_machine);
 		return NT_STATUS_UNSUCCESSFUL;
 	}
  
@@ -50,8 +50,9 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
 
 	result = cli_connect(cli, remote_machine, &ss);
 	if (!NT_STATUS_IS_OK(result)) {
-		slprintf(err_str, err_str_len-1, "Unable to connect to SMB server on machine %s. Error was : %s.\n",
-			remote_machine, nt_errstr(result) );
+		asprintf(err_str, "Unable to connect to SMB server on "
+			 "machine %s. Error was : %s.\n",
+			 remote_machine, nt_errstr(result));
 		cli_shutdown(cli);
 		return result;
 	}
@@ -60,8 +61,9 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
 	make_nmb_name(&called , remote_machine, 0x20);
 	
 	if (!cli_session_request(cli, &calling, &called)) {
-		slprintf(err_str, err_str_len-1, "machine %s rejected the session setup. Error was : %s.\n",
-			remote_machine, cli_errstr(cli) );
+		asprintf(err_str, "machine %s rejected the session setup. "
+			 "Error was : %s.\n",
+			 remote_machine, cli_errstr(cli) );
 		result = cli_nt_error(cli);
 		cli_shutdown(cli);
 		return result;
@@ -70,8 +72,9 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
 	cli->protocol = PROTOCOL_NT1;
 
 	if (!cli_negprot(cli)) {
-		slprintf(err_str, err_str_len-1, "machine %s rejected the negotiate protocol. Error was : %s.\n",        
-			remote_machine, cli_errstr(cli) );
+		asprintf(err_str, "machine %s rejected the negotiate "
+			 "protocol. Error was : %s.\n",        
+			 remote_machine, cli_errstr(cli) );
 		result = cli_nt_error(cli);
 		cli_shutdown(cli);
 		return result;
@@ -92,9 +95,8 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
 
 		if (!NT_STATUS_EQUAL(result, NT_STATUS_PASSWORD_MUST_CHANGE) &&
 		    !NT_STATUS_EQUAL(result, NT_STATUS_PASSWORD_EXPIRED)) {
-			slprintf(err_str, err_str_len-1, "Could not "
-				 "connect to machine %s: %s\n",
-				 remote_machine, cli_errstr(cli));
+			asprintf(err_str, "Could not connect to machine %s: "
+				 "%s\n", remote_machine, cli_errstr(cli));
 			cli_shutdown(cli);
 			return result;
 		}
@@ -110,7 +112,8 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
 		result = cli_session_setup(cli, "", "", 0, "", 0, "");
 
 		if (!NT_STATUS_IS_OK(result)) {
-			slprintf(err_str, err_str_len-1, "machine %s rejected the session setup. Error was : %s.\n",        
+			asprintf(err_str, "machine %s rejected the session "
+				 "setup. Error was : %s.\n",        
 				 remote_machine, cli_errstr(cli) );
 			cli_shutdown(cli);
 			return result;
@@ -122,8 +125,9 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
 	}
 
 	if (!cli_send_tconX(cli, "IPC$", "IPC", "", 1)) {
-		slprintf(err_str, err_str_len-1, "machine %s rejected the tconX on the IPC$ share. Error was : %s.\n",
-			remote_machine, cli_errstr(cli) );
+		asprintf(err_str, "machine %s rejected the tconX on the IPC$ "
+			 "share. Error was : %s.\n",
+			 remote_machine, cli_errstr(cli) );
 		result = cli_nt_error(cli);
 		cli_shutdown(cli);
 		return result;
@@ -155,17 +159,18 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
 		if (lp_client_lanman_auth()) {
 			/* Use the old RAP method. */
 			if (!cli_oem_change_password(cli, user_name, new_passwd, old_passwd)) {
-				slprintf(err_str, err_str_len-1, "machine %s rejected the password change: Error was : %s.\n",
+				asprintf(err_str, "machine %s rejected the "
+					 "password change: Error was : %s.\n",
 					 remote_machine, cli_errstr(cli) );
 				result = cli_nt_error(cli);
 				cli_shutdown(cli);
 				return result;
 			}
 		} else {
-			slprintf(err_str, err_str_len-1,
-				"SAMR connection to machine %s failed. Error was %s, "
-				"but LANMAN password changed are disabled\n",
-				nt_errstr(result), remote_machine);
+			asprintf(err_str, "SAMR connection to machine %s "
+				 "failed. Error was %s, but LANMAN password "
+				 "changed are disabled\n",
+				 nt_errstr(result), remote_machine);
 			result = cli_nt_error(cli);
 			cli_shutdown(cli);
 			return result;
@@ -182,7 +187,8 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
 		     || NT_STATUS_EQUAL(result, NT_STATUS_UNSUCCESSFUL))) {
 		/* it failed, but for reasons such as wrong password, too short etc ... */
 		
-		slprintf(err_str, err_str_len-1, "machine %s rejected the password change: Error was : %s.\n",
+		asprintf(err_str, "machine %s rejected the password change: "
+			 "Error was : %s.\n",
 			 remote_machine, get_friendly_nt_error_msg(result));
 		cli_shutdown(cli);
 		return result;
@@ -213,9 +219,10 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
 		      || NT_STATUS_EQUAL(result, NT_STATUS_UNSUCCESSFUL))) {
 			/* it failed, but again it was due to things like new password too short */
 
-			slprintf(err_str, err_str_len-1, 
-				 "machine %s rejected the (anonymous) password change: Error was : %s.\n",
-				 remote_machine, get_friendly_nt_error_msg(result));
+			asprintf(err_str, "machine %s rejected the "
+				 "(anonymous) password change: Error was : "
+				 "%s.\n", remote_machine,
+				 get_friendly_nt_error_msg(result));
 			cli_shutdown(cli);
 			return result;
 		}
@@ -231,16 +238,16 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
 				cli_shutdown(cli);
 				return NT_STATUS_OK;
 			}
-			slprintf(err_str, err_str_len-1, 
-				 "machine %s rejected the password change: Error was : %s.\n",
+			asprintf(err_str, "machine %s rejected the password "
+				 "change: Error was : %s.\n",
 				 remote_machine, cli_errstr(cli) );
 			result = cli_nt_error(cli);
 			cli_shutdown(cli);
 			return result;
 		} else {
-			slprintf(err_str, err_str_len-1,
-				"SAMR connection to machine %s failed. Error was %s, "
-				"but LANMAN password changed are disabled\n",
+			asprintf(err_str, "SAMR connection to machine %s "
+				 "failed. Error was %s, but LANMAN password "
+				 "changed are disabled\n",
 				nt_errstr(result), remote_machine);
 			cli_shutdown(cli);
 			return NT_STATUS_UNSUCCESSFUL;
diff --git a/source/utils/smbpasswd.c b/source/utils/smbpasswd.c
index b7fc655..2154f5d 100644
--- a/source/utils/smbpasswd.c
+++ b/source/utils/smbpasswd.c
@@ -243,9 +243,10 @@ static NTSTATUS password_change(const char *remote_mach, char *username,
 			return NT_STATUS_UNSUCCESSFUL;
 		}
 		ret = remote_password_change(remote_mach, username, 
-					     old_passwd, new_pw, err_str, sizeof(err_str));
-		if(*err_str)
+					     old_passwd, new_pw, &err_str);
+		if (err_str != NULL)
 			fprintf(stderr, "%s", err_str);
+		SAFE_FREE(err_str);
 		return ret;
 	}
 	
diff --git a/source/web/swat.c b/source/web/swat.c
index 95921c0..65f8877 100644
--- a/source/web/swat.c
+++ b/source/web/swat.c
@@ -996,10 +996,11 @@ static bool change_password(const char *remote_machine, const char *user_name,
 	}
 	
 	if (remote_machine != NULL) {
-		ret = remote_password_change(remote_machine, user_name, old_passwd, 
-									 new_passwd, err_str, sizeof(err_str));
-		if(*err_str)
+		ret = remote_password_change(remote_machine, user_name,
+					     old_passwd, new_passwd, &err_str);
+		if (err_str != NULL)
 			printf("%s\n<p>", err_str);
+		SAFE_FREE(err_str);
 		return NT_STATUS_IS_OK(ret);
 	}
 


-- 
Samba Shared Repository


More information about the samba-cvs mailing list