File samba-4.19-spoolss-subst-fix.patch of Package samba

diff --git a/source3/auth/auth_ntlmssp.c b/source3/auth/auth_ntlmssp.c
index 73938dc2b88..bfe3ac47eb3 100644
--- a/source3/auth/auth_ntlmssp.c
+++ b/source3/auth/auth_ntlmssp.c
@@ -171,7 +171,8 @@ struct tevent_req *auth3_check_password_send(
 	/* The client has given us its machine name (which we only get over NBT transport).
 	   We need to possibly reload smb.conf if smb.conf includes depend on the machine name. */
 
-	set_remote_machine_name(user_info->workstation_name, True);
+	DEBUG(2, ("user_info->workstation_name %s\n", user_info->workstation_name));
+	set_remote_machine_name(user_info->workstation_name, False);
 
 	nt_status = make_user_info_map(talloc_tos(),
                                        &mapped_user_info,
diff --git a/source3/lib/substitute.c b/source3/lib/substitute.c
index 40eb15aee04..5fc8cf0de3c 100644
--- a/source3/lib/substitute.c
+++ b/source3/lib/substitute.c
@@ -90,7 +90,9 @@ bool set_remote_machine_name(const char *remote_name, bool perm)
 	static bool already_perm = False;
 	char tmp[MACHINE_NAME_SIZE];
 
+	DEBUG(2, ("set_remote_machine_name/perm=%s: %s\n", perm ? "true" : "false", remote_name));
 	if (already_perm) {
+		DEBUG(2, ("set_remote_machine_name/already_perm=true: %s\n", remote_machine));
 		return true;
 	}
 
diff --git a/source3/rpc_server/spoolss/srv_spoolss_nt.c b/source3/rpc_server/spoolss/srv_spoolss_nt.c
index 883eebc6474..72d0c1cd452 100644
--- a/source3/rpc_server/spoolss/srv_spoolss_nt.c
+++ b/source3/rpc_server/spoolss/srv_spoolss_nt.c
@@ -65,6 +65,7 @@
 #include "printing/nt_printing_migrate_internal.h"
 #include "lib/util/string_wrappers.h"
 #include "lib/global_contexts.h"
+#include "source3/lib/substitute.h"
 
 /* macros stolen from s4 spoolss server */
 #define SPOOLSS_BUFFER_UNION(fn,info,level) \
@@ -1681,11 +1682,14 @@ WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
 {
 	struct dcesrv_call_state *dce_call = p->dce_call;
 	struct dcesrv_connection *dcesrv_conn = dce_call->conn;
+	const struct tsocket_address *local_address =
+		dcesrv_connection_get_local_address(dcesrv_conn);
 	const struct tsocket_address *remote_address =
 		dcesrv_connection_get_remote_address(dcesrv_conn);
 	struct auth_session_info *session_info =
 		dcesrv_call_session_info(dce_call);
 	int snum;
+	char *laddr;
 	char *raddr;
 	char *rhost;
 	struct printer_handle *Printer=NULL;
@@ -1869,6 +1873,13 @@ WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
 		}
 
 		/* check smb.conf parameters and the the sec_desc */
+		laddr = tsocket_address_inet_addr_string(local_address,
+							 p->mem_ctx);
+		if (laddr == NULL) {
+			return WERR_NOT_ENOUGH_MEMORY;
+		}
+
+		DEBUG(2, ("remote:laddr = %s\n", laddr));
 		raddr = tsocket_address_inet_addr_string(remote_address,
 							 p->mem_ctx);
 		if (raddr == NULL) {
@@ -1881,6 +1892,8 @@ WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
 		if (rc < 0) {
 			return WERR_NOT_ENOUGH_MEMORY;
 		}
+		DEBUG(2, ("remote:raddr = %s\n", raddr));
+		DEBUG(2, ("remote:rhost = %s\n", rhost));
 		if (strequal(rhost, "UNKNOWN")) {
 			rhost = raddr;
 		}
@@ -1925,6 +1938,7 @@ WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
 				      p->msg_ctx,
 				      lp_const_servicename(snum));
 
+		sub_set_socket_ids(raddr, rhost, laddr);
 		break;
 
 	default:
openSUSE Build Service is sponsored by