[patch] consistency

James E. Flemer jflemer at acm.jhu.edu
Fri Mar 7 22:41:27 GMT 2003


These patches fix a some small annoyances in some debug code.
They also make some code more consistent: in
rpc_server/srv_samr_nt.c the memory is zeroed sometimes and not
others, and two nearly identical functions have considerably
different code styles.  Similar justification for
smbd/chgpasswd.c.

Like the previous patches these don't "fix" anything, but tidy
up things and make the code more consistent.

-James

-------------- next part --------------
Index: smbd/chgpasswd.c
===================================================================
RCS file: /cvsroot/samba/source/smbd/chgpasswd.c,v
retrieving revision 1.64.4.18
diff -u -r1.64.4.18 chgpasswd.c
--- smbd/chgpasswd.c	4 Mar 2003 23:35:59 -0000	1.64.4.18
+++ smbd/chgpasswd.c	7 Mar 2003 21:19:52 -0000
@@ -492,7 +492,7 @@
 	for (i = 0; i < len; i++) {
 		if (iscntrl((int)oldpass[i])) {
 			DEBUG(0,
-			      ("chat_with_program: oldpass contains control characters (disallowed).\n"));
+			      ("chgpasswd: oldpass contains control characters (disallowed).\n"));
 			return False;
 		}
 	}
@@ -501,7 +501,7 @@
 	for (i = 0; i < len; i++) {
 		if (iscntrl((int)newpass[i])) {
 			DEBUG(0,
-			      ("chat_with_program: newpass contains control characters (disallowed).\n"));
+			      ("chgpasswd: newpass contains control characters (disallowed).\n"));
 			return False;
 		}
 	}
@@ -802,7 +802,7 @@
 		}
 	}
 
-	if (pdb_get_nt_passwd(sampass) == NULL && nt_pass_set) {
+	if (nt_pw == NULL && nt_pass_set) {
 		if (acct_ctrl & ACB_PWNOTREQ) {
 			pdb_set_nt_passwd(sampass, null_ntpw);
 			nt_pw = pdb_get_nt_passwd(sampass);
@@ -941,6 +941,7 @@
 {
 	SAM_ACCOUNT  *sampass = NULL;
 	uchar old_pw[16], old_ntpw[16];
+	uint8 *nt_pw, *lanman_pw;
 	BOOL ret;
 
 	*hnd = NULL;
@@ -963,21 +964,30 @@
 		return (False);
 	}
 
+	nt_pw = pdb_get_nt_passwd(sampass);
+	lanman_pw = pdb_get_lanman_passwd(sampass);
+
+	if (nt_pw == NULL && lanman_pw == NULL) {
+		DEBUG(0,("check_plaintext_password: account %s has NULL nt/lm hashes.\n", user));
+		pdb_free_sam(sampass);
+		return (False);
+	}
+
 	nt_lm_owf_gen(old_passwd, old_ntpw, old_pw);
 
 #ifdef DEBUG_PASSWORD
 	DEBUG(100, ("check_plaintext_password: nt_passwd \n"));
-	dump_data(100, pdb_get_nt_passwd(sampass), 16);
+	dump_data(100, nt_pw, 16);
 	DEBUG(100, ("check_plaintext_password: old_ntpw \n"));
 	dump_data(100, old_ntpw, 16);
 	DEBUG(100, ("check_plaintext_password: lanman_passwd \n"));
-	dump_data(100, pdb_get_lanman_passwd(sampass), 16);
+	dump_data(100, lanman_pw, 16);
 	DEBUG(100, ("check_plaintext_password: old_pw\n"));
 	dump_data(100, old_pw, 16);
 #endif
 
-	if (memcmp(pdb_get_nt_passwd(sampass), old_ntpw, 16)
-	    && memcmp(pdb_get_lanman_passwd(sampass), old_pw, 16)) {
+	if (memcmp(nt_pw, old_ntpw, 16)
+	    && memcmp(lanman_pw, old_pw, 16)) {
 		pdb_free_sam(sampass);
 		return (False);
 	} else {
-------------- next part --------------
Index: rpc_server/srv_samr_nt.c
===================================================================
RCS file: /cvsroot/samba/source/rpc_server/srv_samr_nt.c,v
retrieving revision 1.1.2.70
diff -u -r1.1.2.70 srv_samr_nt.c
--- rpc_server/srv_samr_nt.c	4 Mar 2003 23:35:57 -0000	1.1.2.70
+++ rpc_server/srv_samr_nt.c	7 Mar 2003 21:13:53 -0000
@@ -2345,14 +2345,14 @@
 			}
 	}
  
-	memset(buf, 0, sizeof(buf));
- 
 	if(!pdb_update_sam_account(pwd, True)) {
 		result = False;
 		goto done;
 	}
  
 done:
+	memset(buf, 0, sizeof(buf));
+ 
 	pdb_free_sam(pwd);
 	return result;
 }
@@ -2369,12 +2369,13 @@
 	uint32 len;
 	pstring buf;
 	uint16 acct_ctrl;
+	BOOL result = True;
  
  	pdb_init_sam(&pwd);
  
 	if (!pdb_getsampwrid(pwd, rid)) {
-		pdb_free_sam(pwd);
-		return False;
+		result = False;
+		goto done;
  	}
 	
 	acct_ctrl = pdb_get_acct_ctrl(pwd);
@@ -2382,17 +2383,17 @@
 	memset(buf, 0, sizeof(buf));
  
 	if (!decode_pw_buffer(pass, buf, 256, &len, nt_hash, lm_hash)) {
-		pdb_free_sam(pwd);
-		return False;
+		result = False;
+		goto done;
  	}
 
 	if (!pdb_set_lanman_passwd (pwd, lm_hash)) {
-		pdb_free_sam(pwd);
-		return False;
+		result = False;
+		goto done;
 	}
 	if (!pdb_set_nt_passwd(pwd, nt_hash)) {
-		pdb_free_sam(pwd);
-		return False;
+		result = False;
+		goto done;
 	}
  
 	/* if it's a trust account, don't update /etc/passwd */
@@ -2404,24 +2405,24 @@
 		/* update the UNIX password */
 		if (lp_unix_password_sync())
 			if(!chgpasswd(pdb_get_username(pwd), "", buf, True)) {
-				pdb_free_sam(pwd);
-				return False;
+				result = False;
+				goto done;
 			}
 	}
  
-	memset(buf, 0, sizeof(buf));
- 
 	DEBUG(5,("set_user_info_pw: pdb_update_sam_account()\n"));
  
 	/* update the SAMBA password */
 	if(!pdb_update_sam_account(pwd, True)) {
-		pdb_free_sam(pwd);
-		return False;
+		result = False;
+		goto done;
  	}
 
-	pdb_free_sam(pwd);
+done:
+	memset(buf, 0, sizeof(buf));
 
-	return True;
+	pdb_free_sam(pwd);
+	return result;
 }
 
 /*******************************************************************
-------------- next part --------------
Index: libsmb/smbencrypt.c
===================================================================
RCS file: /cvsroot/samba/source/libsmb/smbencrypt.c,v
retrieving revision 1.47.6.11
diff -u -r1.47.6.11 smbencrypt.c
--- libsmb/smbencrypt.c	5 Nov 2002 19:05:05 -0000	1.47.6.11
+++ libsmb/smbencrypt.c	7 Mar 2003 21:02:19 -0000
@@ -275,9 +275,8 @@
 	mdfour(nt_p16, (unsigned char *)unicode_passwd, byte_len);
 	
 #ifdef DEBUG_PASSWORD
-	DEBUG(100,("nt_lm_owf_gen: nt#:"));
+	DEBUG(100,("nt_lm_owf_gen: nt#:\n"));
 	dump_data(100, (char *)nt_p16, 16);
-	DEBUG(100,("\n"));
 #endif
 	
 	/* Mangle the passwords into Lanman format */
@@ -289,9 +288,8 @@
 	E_P16((uchar *) lm_ascii_passwd, (uchar *)p16);
 
 #ifdef DEBUG_PASSWORD
-	DEBUG(100,("nt_lm_owf_gen: lm#:"));
+	DEBUG(100,("nt_lm_owf_gen: lm#:\n"));
 	dump_data(100, (char *)p16, 16);
-	DEBUG(100,("\n"));
 #endif
 
 	/* copy the password and it's length to the return buffer */	


More information about the samba-technical mailing list