887a65
From f7046a874ce3ab5d9b4024442daf03e79f25956b Mon Sep 17 00:00:00 2001
887a65
From: Andreas Schneider <asn@samba.org>
887a65
Date: Fri, 18 Aug 2017 16:08:46 +0200
887a65
Subject: [PATCH 1/6] s3:libsmb: Pass domain to remote_password_change()
887a65
887a65
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12975
887a65
887a65
Signed-off-by: Andreas Schneider <asn@samba.org>
887a65
Reviewed-by: Andrew Bartlet <abartlet@samba.org>
887a65
(cherry picked from commit 7a554ee7dcefdff599ebc6fbf4e128b33ffccf29)
887a65
---
887a65
 source3/include/proto.h     | 3 ++-
887a65
 source3/libsmb/passchange.c | 5 +++--
887a65
 source3/utils/smbpasswd.c   | 3 ++-
887a65
 3 files changed, 7 insertions(+), 4 deletions(-)
887a65
887a65
diff --git a/source3/include/proto.h b/source3/include/proto.h
887a65
index baa579995a5..9deb27b416b 100644
887a65
--- a/source3/include/proto.h
887a65
+++ b/source3/include/proto.h
887a65
@@ -834,7 +834,8 @@ bool get_dc_name(const char *domain,
887a65
 
887a65
 /* The following definitions come from libsmb/passchange.c  */
887a65
 
887a65
-NTSTATUS remote_password_change(const char *remote_machine, const char *user_name, 
887a65
+NTSTATUS remote_password_change(const char *remote_machine,
887a65
+				const char *domain, const char *user_name,
887a65
 				const char *old_passwd, const char *new_passwd,
887a65
 				char **err_str);
887a65
 
887a65
diff --git a/source3/libsmb/passchange.c b/source3/libsmb/passchange.c
887a65
index c89b7ca85d1..48ffba8036f 100644
887a65
--- a/source3/libsmb/passchange.c
887a65
+++ b/source3/libsmb/passchange.c
887a65
@@ -30,7 +30,8 @@
887a65
  Change a password on a remote machine using IPC calls.
887a65
 *************************************************************/
887a65
 
887a65
-NTSTATUS remote_password_change(const char *remote_machine, const char *user_name, 
887a65
+NTSTATUS remote_password_change(const char *remote_machine,
887a65
+				const char *domain, const char *user_name,
887a65
 				const char *old_passwd, const char *new_passwd,
887a65
 				char **err_str)
887a65
 {
887a65
@@ -55,7 +56,7 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
887a65
 
887a65
 	creds = cli_session_creds_init(cli,
887a65
 				       user_name,
887a65
-				       NULL, /* domain */
887a65
+				       domain,
887a65
 				       NULL, /* realm */
887a65
 				       old_passwd,
887a65
 				       false, /* use_kerberos */
887a65
diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c
887a65
index 437a5e551bb..4d7a3c739bc 100644
887a65
--- a/source3/utils/smbpasswd.c
887a65
+++ b/source3/utils/smbpasswd.c
887a65
@@ -258,7 +258,8 @@ static NTSTATUS password_change(const char *remote_mach, char *username,
887a65
 			fprintf(stderr, "Invalid remote operation!\n");
887a65
 			return NT_STATUS_UNSUCCESSFUL;
887a65
 		}
887a65
-		ret = remote_password_change(remote_mach, username,
887a65
+		ret = remote_password_change(remote_mach,
887a65
+					     NULL, username,
887a65
 					     old_passwd, new_pw, &err_str);
887a65
 	} else {
887a65
 		ret = local_password_change(username, local_flags, new_pw,
887a65
-- 
887a65
2.14.1
887a65
887a65
887a65
From f215f7c53032689dbdaac96a3a16fa7d3fe3d3c5 Mon Sep 17 00:00:00 2001
887a65
From: Andreas Schneider <asn@samba.org>
887a65
Date: Fri, 18 Aug 2017 16:10:06 +0200
887a65
Subject: [PATCH 2/6] s3:libsmb: Move prototye of remote_password_change()
887a65
887a65
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12975
887a65
887a65
Signed-off-by: Andreas Schneider <asn@samba.org>
887a65
Reviewed-by: Andrew Bartlet <abartlet@samba.org>
887a65
(cherry picked from commit c773844e7529b83b2633671c7bcf1e7b84ad7950)
887a65
---
887a65
 source3/include/proto.h   |  7 -------
887a65
 source3/libsmb/proto.h    | 10 ++++++++++
887a65
 source3/utils/smbpasswd.c |  1 +
887a65
 3 files changed, 11 insertions(+), 7 deletions(-)
887a65
887a65
diff --git a/source3/include/proto.h b/source3/include/proto.h
887a65
index 9deb27b416b..67e1a9d750e 100644
887a65
--- a/source3/include/proto.h
887a65
+++ b/source3/include/proto.h
887a65
@@ -832,13 +832,6 @@ bool get_dc_name(const char *domain,
887a65
 		fstring srv_name,
887a65
 		struct sockaddr_storage *ss_out);
887a65
 
887a65
-/* The following definitions come from libsmb/passchange.c  */
887a65
-
887a65
-NTSTATUS remote_password_change(const char *remote_machine,
887a65
-				const char *domain, const char *user_name,
887a65
-				const char *old_passwd, const char *new_passwd,
887a65
-				char **err_str);
887a65
-
887a65
 /* The following definitions come from libsmb/smberr.c  */
887a65
 
887a65
 const char *smb_dos_err_name(uint8_t e_class, uint16_t num);
887a65
diff --git a/source3/libsmb/proto.h b/source3/libsmb/proto.h
887a65
index a583a8ee159..44f4d04cff5 100644
887a65
--- a/source3/libsmb/proto.h
887a65
+++ b/source3/libsmb/proto.h
887a65
@@ -31,6 +31,9 @@
887a65
 
887a65
 struct smb_trans_enc_state;
887a65
 struct cli_credentials;
887a65
+struct cli_state;
887a65
+struct file_info;
887a65
+struct print_job_info;
887a65
 
887a65
 /* The following definitions come from libsmb/cliconnect.c  */
887a65
 
887a65
@@ -964,4 +967,11 @@ NTSTATUS cli_readlink(struct cli_state *cli, const char *fname,
887a65
 		       TALLOC_CTX *mem_ctx, char **psubstitute_name,
887a65
 		      char **pprint_name, uint32_t *pflags);
887a65
 
887a65
+/* The following definitions come from libsmb/passchange.c  */
887a65
+
887a65
+NTSTATUS remote_password_change(const char *remote_machine,
887a65
+				const char *domain, const char *user_name,
887a65
+				const char *old_passwd, const char *new_passwd,
887a65
+				char **err_str);
887a65
+
887a65
 #endif /* _LIBSMB_PROTO_H_ */
887a65
diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c
887a65
index 4d7a3c739bc..6eb2deb7a3b 100644
887a65
--- a/source3/utils/smbpasswd.c
887a65
+++ b/source3/utils/smbpasswd.c
887a65
@@ -21,6 +21,7 @@
887a65
 #include "secrets.h"
887a65
 #include "../librpc/gen_ndr/samr.h"
887a65
 #include "../lib/util/util_pw.h"
887a65
+#include "libsmb/proto.h"
887a65
 #include "passdb.h"
887a65
 
887a65
 /*
887a65
-- 
887a65
2.14.1
887a65
887a65
887a65
From 7e6e01b965c838494203c964fa5ac55b355bd58a Mon Sep 17 00:00:00 2001
887a65
From: Andreas Schneider <asn@samba.org>
887a65
Date: Fri, 18 Aug 2017 16:13:15 +0200
887a65
Subject: [PATCH 3/6] s3:utils: Make strings const passed to password_change()
887a65
 in smbpasswd
887a65
887a65
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12975
887a65
887a65
Signed-off-by: Andreas Schneider <asn@samba.org>
887a65
Reviewed-by: Andrew Bartlet <abartlet@samba.org>
887a65
(cherry picked from commit 41a31a71abe144362fc7483fabba39aafa866373)
887a65
---
887a65
 source3/utils/smbpasswd.c | 5 +++--
887a65
 1 file changed, 3 insertions(+), 2 deletions(-)
887a65
887a65
diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c
887a65
index 6eb2deb7a3b..b0e08cc0e58 100644
887a65
--- a/source3/utils/smbpasswd.c
887a65
+++ b/source3/utils/smbpasswd.c
887a65
@@ -243,8 +243,9 @@ static char *prompt_for_new_password(bool stdin_get)
887a65
  Change a password either locally or remotely.
887a65
 *************************************************************/
887a65
 
887a65
-static NTSTATUS password_change(const char *remote_mach, char *username, 
887a65
-				char *old_passwd, char *new_pw,
887a65
+static NTSTATUS password_change(const char *remote_mach,
887a65
+				const char *username,
887a65
+				const char *old_passwd, const char *new_pw,
887a65
 				int local_flags)
887a65
 {
887a65
 	NTSTATUS ret;
887a65
-- 
887a65
2.14.1
887a65
887a65
887a65
From bec5dc7c8b1bca092fa4ea87016bbfdb2750896c Mon Sep 17 00:00:00 2001
887a65
From: Andreas Schneider <asn@samba.org>
887a65
Date: Fri, 18 Aug 2017 16:14:57 +0200
887a65
Subject: [PATCH 4/6] s3:utils: Pass domain to password_change() in smbpasswd
887a65
887a65
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12975
887a65
887a65
Signed-off-by: Andreas Schneider <asn@samba.org>
887a65
Reviewed-by: Andrew Bartlet <abartlet@samba.org>
887a65
(cherry picked from commit b483340639157fe95777672f5723455c48c3c616)
887a65
---
887a65
 source3/utils/smbpasswd.c | 12 +++++++-----
887a65
 1 file changed, 7 insertions(+), 5 deletions(-)
887a65
887a65
diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c
887a65
index b0e08cc0e58..92712e38f6b 100644
887a65
--- a/source3/utils/smbpasswd.c
887a65
+++ b/source3/utils/smbpasswd.c
887a65
@@ -244,7 +244,7 @@ static char *prompt_for_new_password(bool stdin_get)
887a65
 *************************************************************/
887a65
 
887a65
 static NTSTATUS password_change(const char *remote_mach,
887a65
-				const char *username,
887a65
+				const char *domain, const char *username,
887a65
 				const char *old_passwd, const char *new_pw,
887a65
 				int local_flags)
887a65
 {
887a65
@@ -261,7 +261,7 @@ static NTSTATUS password_change(const char *remote_mach,
887a65
 			return NT_STATUS_UNSUCCESSFUL;
887a65
 		}
887a65
 		ret = remote_password_change(remote_mach,
887a65
-					     NULL, username,
887a65
+					     domain, username,
887a65
 					     old_passwd, new_pw, &err_str);
887a65
 	} else {
887a65
 		ret = local_password_change(username, local_flags, new_pw,
887a65
@@ -466,7 +466,8 @@ static int process_root(int local_flags)
887a65
 		}
887a65
 	}
887a65
 
887a65
-	if (!NT_STATUS_IS_OK(password_change(remote_machine, user_name,
887a65
+	if (!NT_STATUS_IS_OK(password_change(remote_machine,
887a65
+					     NULL, user_name,
887a65
 					     old_passwd, new_passwd,
887a65
 					     local_flags))) {
887a65
 		result = 1;
887a65
@@ -566,8 +567,9 @@ static int process_nonroot(int local_flags)
887a65
 		exit(1);
887a65
 	}
887a65
 
887a65
-	if (!NT_STATUS_IS_OK(password_change(remote_machine, user_name, old_pw,
887a65
-					     new_pw, 0))) {
887a65
+	if (!NT_STATUS_IS_OK(password_change(remote_machine,
887a65
+					     NULL, user_name,
887a65
+					     old_pw, new_pw, 0))) {
887a65
 		result = 1;
887a65
 		goto done;
887a65
 	}
887a65
-- 
887a65
2.14.1
887a65
887a65
887a65
From 72dd200ce430b23a887ddfa73c2b618bf387c583 Mon Sep 17 00:00:00 2001
887a65
From: Andreas Schneider <asn@samba.org>
887a65
Date: Fri, 18 Aug 2017 16:17:08 +0200
887a65
Subject: [PATCH 5/6] s3:utils: Make sure we authenticate against our SAM name
887a65
 in smbpasswd
887a65
887a65
If a local user wants to change his password using smbpasswd and the
887a65
machine is a domain member, we need to make sure we authenticate against
887a65
our SAM and not ask winbind.
887a65
887a65
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12975
887a65
887a65
Signed-off-by: Andreas Schneider <asn@samba.org>
887a65
Reviewed-by: Andrew Bartlet <abartlet@samba.org>
887a65
(cherry picked from commit dc129a968afdac8be70f9756bd18a7bf1f4c3b02)
887a65
---
887a65
 source3/utils/smbpasswd.c | 32 +++++++++++++++++++++++++++-----
887a65
 1 file changed, 27 insertions(+), 5 deletions(-)
887a65
887a65
diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c
887a65
index 92712e38f6b..556e6869da7 100644
887a65
--- a/source3/utils/smbpasswd.c
887a65
+++ b/source3/utils/smbpasswd.c
887a65
@@ -58,7 +58,7 @@ static void usage(void)
887a65
 	printf("  -c smb.conf file     Use the given path to the smb.conf file\n");
887a65
 	printf("  -D LEVEL             debug level\n");
887a65
 	printf("  -r MACHINE           remote machine\n");
887a65
-	printf("  -U USER              remote username\n");
887a65
+	printf("  -U USER              remote username (e.g. SAM/user)\n");
887a65
 
887a65
 	printf("extra options when run by root or in local mode:\n");
887a65
 	printf("  -a                   add user\n");
887a65
@@ -95,7 +95,7 @@ static int process_options(int argc, char **argv, int local_flags)
887a65
 
887a65
 	user_name[0] = '\0';
887a65
 
887a65
-	while ((ch = getopt(argc, argv, "c:axdehminjr:sw:R:D:U:LW")) != EOF) {
887a65
+	while ((ch = getopt(argc, argv, "c:axdehminjr:sw:R:D:U:LWS:")) != EOF) {
887a65
 		switch(ch) {
887a65
 		case 'L':
887a65
 			if (getuid() != 0) {
887a65
@@ -519,6 +519,9 @@ static int process_nonroot(int local_flags)
887a65
 	int result = 0;
887a65
 	char *old_pw = NULL;
887a65
 	char *new_pw = NULL;
887a65
+	const char *username = user_name;
887a65
+	const char *domain = NULL;
887a65
+	char *p = NULL;
887a65
 
887a65
 	if (local_flags & ~(LOCAL_AM_ROOT | LOCAL_SET_PASSWORD)) {
887a65
 		/* Extra flags that we can't honor non-root */
887a65
@@ -536,6 +539,15 @@ static int process_nonroot(int local_flags)
887a65
 		}
887a65
 	}
887a65
 
887a65
+	/* Allow domain as part of the username */
887a65
+	if ((p = strchr_m(user_name, '\\')) ||
887a65
+	    (p = strchr_m(user_name, '/')) ||
887a65
+	    (p = strchr_m(user_name, *lp_winbind_separator()))) {
887a65
+		*p = '\0';
887a65
+		username = p + 1;
887a65
+		domain = user_name;
887a65
+	}
887a65
+
887a65
 	/*
887a65
 	 * A non-root user is always setting a password
887a65
 	 * via a remote machine (even if that machine is
887a65
@@ -544,8 +556,18 @@ static int process_nonroot(int local_flags)
887a65
 
887a65
 	load_interfaces(); /* Delayed from main() */
887a65
 
887a65
-	if (remote_machine == NULL) {
887a65
+	if (remote_machine != NULL) {
887a65
+		if (!is_ipaddress(remote_machine)) {
887a65
+			domain = remote_machine;
887a65
+		}
887a65
+	} else {
887a65
 		remote_machine = "127.0.0.1";
887a65
+
887a65
+		/*
887a65
+		 * If we deal with a local user, change the password for the
887a65
+		 * user in our SAM.
887a65
+		 */
887a65
+		domain = get_global_sam_name();
887a65
 	}
887a65
 
887a65
 	if (remote_machine != NULL) {
887a65
@@ -568,13 +590,13 @@ static int process_nonroot(int local_flags)
887a65
 	}
887a65
 
887a65
 	if (!NT_STATUS_IS_OK(password_change(remote_machine,
887a65
-					     NULL, user_name,
887a65
+					     domain, username,
887a65
 					     old_pw, new_pw, 0))) {
887a65
 		result = 1;
887a65
 		goto done;
887a65
 	}
887a65
 
887a65
-	printf("Password changed for user %s\n", user_name);
887a65
+	printf("Password changed for user %s\n", username);
887a65
 
887a65
  done:
887a65
 	SAFE_FREE(old_pw);
887a65
-- 
887a65
2.14.1
887a65
887a65
887a65
From 7d8aae447a411eb4903850c30366a18d1714f7c0 Mon Sep 17 00:00:00 2001
887a65
From: Andreas Schneider <asn@samba.org>
887a65
Date: Tue, 22 Aug 2017 15:46:07 +0200
887a65
Subject: [PATCH 6/6] s3:utils: Remove pointless if-clause for remote_machine
887a65
887a65
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12975
887a65
887a65
Review with: git show -U20
887a65
887a65
Signed-off-by: Andreas Schneider <asn@samba.org>
887a65
Reviewed-by: Andrew Bartlet <abartlet@samba.org>
887a65
(cherry picked from commit 4a4bfcb539b4489f397b2bc9369215b7e03e620e)
887a65
---
887a65
 source3/utils/smbpasswd.c | 10 ++++------
887a65
 1 file changed, 4 insertions(+), 6 deletions(-)
887a65
887a65
diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c
887a65
index 556e6869da7..fb7ad283995 100644
887a65
--- a/source3/utils/smbpasswd.c
887a65
+++ b/source3/utils/smbpasswd.c
887a65
@@ -570,12 +570,10 @@ static int process_nonroot(int local_flags)
887a65
 		domain = get_global_sam_name();
887a65
 	}
887a65
 
887a65
-	if (remote_machine != NULL) {
887a65
-		old_pw = get_pass("Old SMB password:",stdin_passwd_get);
887a65
-		if (old_pw == NULL) {
887a65
-			fprintf(stderr, "Unable to get old password.\n");
887a65
-			exit(1);
887a65
-		}
887a65
+	old_pw = get_pass("Old SMB password:",stdin_passwd_get);
887a65
+	if (old_pw == NULL) {
887a65
+		fprintf(stderr, "Unable to get old password.\n");
887a65
+		exit(1);
887a65
 	}
887a65
 
887a65
 	if (!new_passwd) {
887a65
-- 
887a65
2.14.1
887a65