[SCM] Samba Shared Repository - branch master updated

Andreas Schneider asn at samba.org
Tue Feb 27 13:11:02 UTC 2018


The branch, master has been updated
       via  4da56e9 nbt_server: Factor out packet generation for netlogon reply
       via  39827b7 nbt_server: nbtd_netlogon_getdc doesn't need "src"
       via  7b06eac nbt_server: Avoid a talloc call
       via  1655701 nbt_server: Avoid an "else" branch
       via  5f9a090 nbt_server: nbtd_netlogon_samlogon needs the dst_name, not the packet
       via  33991e5 nbt_server: nbtd_netlogon_getdc needs just the dst_name
       via  28f7a1f nbt_server: Fix a typo ("domian->domain")
       via  d673ca0 nbt_server: nbtd_netlogon_samlogon needs the nbtsrv, not the inteface
       via  e49e347 nbt_server: nbtd_netlogon_getdc needs the nbtsrv, not the interface
       via  7de9613 nbt_server: Centralize a consistency check
       via  211a607 nbt_server: Make nbtd_mailslot_netlogon_handler a bit more idiomatic
       via  7243490 nbt_server: Factor out dgram sending from reply construction
       via  f604c98 nbt_server: Remove a pointless assignment
       via  4897f86 nbt_server: Remove some unused parameters
       via  5ec14fd libdgram: Remove an unused parameter
       via  92580b3 libdgram: Remove an unused parameter
       via  d88f826 libsocket: Add "mem_ctx" to socket_create()
      from  3508268 replace: Only warn if rpc/rpc.h haven't been found

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 4da56e9f049c5aaa9e5573786cc5c490cfbfac96
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Feb 17 21:02:41 2018 +0100

    nbt_server: Factor out packet generation for netlogon reply
    
    This also fixes an inaccuracy (or even a bug?):
    The previous code pulled the reply mailslot always through
    req.logon.mailslot_name, which is the union for
    LOGON_SAM_LOGON_REQUESTs. The LOGON_PRIMARY_QUERY must be referenced by
    req.pdc.mailslot_name. It might have worked by chance, but this should
    be more correct.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    
    Autobuild-User(master): Andreas Schneider <asn at cryptomilk.org>
    Autobuild-Date(master): Tue Feb 27 14:10:14 CET 2018 on sn-devel-144

commit 39827b7582932baa9d71390096204e5f2f5afb3d
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Feb 17 20:09:03 2018 +0100

    nbt_server: nbtd_netlogon_getdc doesn't need "src"
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 7b06eacd59137711728fab17ff3517e7dbb3a5ef
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Feb 17 20:06:36 2018 +0100

    nbt_server: Avoid a talloc call
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 165570192310e3a51c070bbcc3222664e683887f
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Feb 17 20:04:23 2018 +0100

    nbt_server: Avoid an "else" branch
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 5f9a0903a2ddc10aab4c7f07387ed53d728089c7
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Feb 17 17:33:32 2018 +0100

    nbt_server: nbtd_netlogon_samlogon needs the dst_name, not the packet
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 33991e5c9086d5d437d1d408be1b54cb55333856
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Feb 17 17:25:03 2018 +0100

    nbt_server: nbtd_netlogon_getdc needs just the dst_name
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 28f7a1f754e0939870f2798dfe0e811b42dd83eb
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Feb 17 17:22:11 2018 +0100

    nbt_server: Fix a typo ("domian->domain")
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit d673ca0c350c85bcf0b804690adce5cffa7a5f0b
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Feb 17 17:18:29 2018 +0100

    nbt_server: nbtd_netlogon_samlogon needs the nbtsrv, not the inteface
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit e49e3470783275d00c6c386675ff8ac2c3aa7c24
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Feb 17 17:16:07 2018 +0100

    nbt_server: nbtd_netlogon_getdc needs the nbtsrv, not the interface
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 7de96133858edee309102976fd7265d6e480e778
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Feb 17 17:11:41 2018 +0100

    nbt_server: Centralize a consistency check
    
    This is a "should NEVER happen" and applies to both
    LOGON_PRIMARY_QUERY and LOGON_SAM_LOGON_REQUEST
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 211a6072adb05cb74b1012cbd3637fdfe377c4f2
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Feb 17 17:09:31 2018 +0100

    nbt_server: Make nbtd_mailslot_netlogon_handler a bit more idiomatic
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 724349090c096efe32887a92059aae42232caeab
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Feb 17 17:05:09 2018 +0100

    nbt_server: Factor out dgram sending from reply construction
    
    Separation of concerns. Only one call to dgram_mailslot_netlogon_reply, which
    does the UDP send.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit f604c98ac2be8f86029d4abc350774807f75501a
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Feb 17 16:49:00 2018 +0100

    nbt_server: Remove a pointless assignment
    
    I don't see how data.msg.dest_name.type is accessed further down
    
    dgram_mailslot_netlogon_reply only accesses packet->src_addr, packet->src_port
    and packet->data.msg.source_name, *not* data.msg.dest_name. Also, "packet" is
    thrown away after this call.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 4897f8605622d9acda1996d3c39da6f51fec654e
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Feb 16 20:21:17 2018 +0100

    nbt_server: Remove some unused parameters
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 5ec14fd981c27f9a3ce64922b54252ec5cabbc18
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Feb 17 20:45:22 2018 +0100

    libdgram: Remove an unused parameter
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 92580b3f2fb1e23e5bfcc0e8ab19ee02e9ea5958
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Feb 17 20:42:19 2018 +0100

    libdgram: Remove an unused parameter
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit d88f826c7b78d84fef87ab1301b266f11b4162fb
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Feb 15 16:43:59 2018 +0100

    libsocket: Add "mem_ctx" to socket_create()
    
    Every caller did a talloc_steal() after socket_create(). Just pass in the
    correct memory context.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

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

Summary of changes:
 libcli/nbt/nbtsocket.c                    |   5 +-
 source4/auth/kerberos/krb5_init_context.c |  10 +-
 source4/lib/socket/connect_multi.c        |   7 +-
 source4/lib/socket/socket.c               |   5 +-
 source4/lib/socket/socket.h               |   3 +-
 source4/lib/socket/testsuite.c            |  12 +-
 source4/libcli/dgram/dgramsocket.c        |   5 +-
 source4/libcli/dgram/libdgram.h           |   6 +-
 source4/libcli/dgram/netlogon.c           |  10 +-
 source4/libcli/ldap/ldap_client.c         |   5 +-
 source4/librpc/rpc/dcerpc_sock.c          |   5 +-
 source4/nbt_server/dgram/netlogon.c       | 273 +++++++++++++++++++-----------
 source4/nbt_server/irpc.c                 |   2 +-
 source4/smbd/service_stream.c             |  10 +-
 source4/torture/nbt/dgram.c               |   3 +-
 15 files changed, 220 insertions(+), 141 deletions(-)


Changeset truncated at 500 lines:

diff --git a/libcli/nbt/nbtsocket.c b/libcli/nbt/nbtsocket.c
index d7abb1b..711e39c 100644
--- a/libcli/nbt/nbtsocket.c
+++ b/libcli/nbt/nbtsocket.c
@@ -339,13 +339,12 @@ _PUBLIC_ struct nbt_name_socket *nbt_name_socket_init(TALLOC_CTX *mem_ctx,
 	nbtsock->event_ctx = event_ctx;
 	if (nbtsock->event_ctx == NULL) goto failed;
 
-	status = socket_create("ip", SOCKET_TYPE_DGRAM, &nbtsock->sock, 0);
+	status = socket_create(nbtsock, "ip", SOCKET_TYPE_DGRAM,
+			       &nbtsock->sock, 0);
 	if (!NT_STATUS_IS_OK(status)) goto failed;
 
 	socket_set_option(nbtsock->sock, "SO_BROADCAST", "1");
 
-	talloc_steal(nbtsock, nbtsock->sock);
-
 	nbtsock->idr = idr_init(nbtsock);
 	if (nbtsock->idr == NULL) goto failed;
 
diff --git a/source4/auth/kerberos/krb5_init_context.c b/source4/auth/kerberos/krb5_init_context.c
index e2c837a..5e771a8 100644
--- a/source4/auth/kerberos/krb5_init_context.c
+++ b/source4/auth/kerberos/krb5_init_context.c
@@ -261,10 +261,14 @@ static krb5_error_code smb_krb5_send_and_recv_func_int(krb5_context context,
 		status = NT_STATUS_INVALID_PARAMETER;
 		switch (hi->proto) {
 		case KRB5_KRBHST_UDP:
-			status = socket_create(name, SOCKET_TYPE_DGRAM, &smb_krb5->sock, 0);
+			status = socket_create(smb_krb5, name,
+					       SOCKET_TYPE_DGRAM,
+					       &smb_krb5->sock, 0);
 			break;
 		case KRB5_KRBHST_TCP:
-			status = socket_create(name, SOCKET_TYPE_STREAM, &smb_krb5->sock, 0);
+			status = socket_create(smb_krb5, name,
+					       SOCKET_TYPE_STREAM,
+					       &smb_krb5->sock, 0);
 			break;
 		case KRB5_KRBHST_HTTP:
 			TALLOC_FREE(frame);
@@ -275,8 +279,6 @@ static krb5_error_code smb_krb5_send_and_recv_func_int(krb5_context context,
 			continue;
 		}
 
-		talloc_steal(smb_krb5, smb_krb5->sock);
-
 		remote_addr = socket_address_from_sockaddr(smb_krb5, a->ai_addr, a->ai_addrlen);
 		if (!remote_addr) {
 			talloc_free(smb_krb5);
diff --git a/source4/lib/socket/connect_multi.c b/source4/lib/socket/connect_multi.c
index c8231b3..b29fffb 100644
--- a/source4/lib/socket/connect_multi.c
+++ b/source4/lib/socket/connect_multi.c
@@ -152,8 +152,9 @@ static void connect_multi_next_socket(struct composite_context *result)
 	if (composite_nomem(state, result)) return;
 
 	state->result = result;
-	result->status = socket_create(multi->server_address[multi->current_address]->family,
-					SOCKET_TYPE_STREAM, &state->sock, 0);
+	result->status = socket_create(
+		state, multi->server_address[multi->current_address]->family,
+		SOCKET_TYPE_STREAM, &state->sock, 0);
 	if (!composite_is_ok(result)) return;
 
 	state->addr = socket_address_copy(state, multi->server_address[multi->current_address]);
@@ -161,8 +162,6 @@ static void connect_multi_next_socket(struct composite_context *result)
 
 	socket_address_set_port(state->addr, multi->ports[multi->current_port]);
 
-	talloc_steal(state, state->sock);
-
 	creq = socket_connect_send(state->sock, NULL, 
 				   state->addr, 0,
 				   result->event_ctx);
diff --git a/source4/lib/socket/socket.c b/source4/lib/socket/socket.c
index 42eb53a..98f796e 100644
--- a/source4/lib/socket/socket.c
+++ b/source4/lib/socket/socket.c
@@ -96,7 +96,8 @@ _PUBLIC_ NTSTATUS socket_create_with_ops(TALLOC_CTX *mem_ctx, const struct socke
 	return NT_STATUS_OK;
 }
 
-_PUBLIC_ NTSTATUS socket_create(const char *name, enum socket_type type, 
+_PUBLIC_ NTSTATUS socket_create(TALLOC_CTX *mem_ctx,
+				const char *name, enum socket_type type,
 			        struct socket_context **new_sock, uint32_t flags)
 {
 	const struct socket_ops *ops;
@@ -106,7 +107,7 @@ _PUBLIC_ NTSTATUS socket_create(const char *name, enum socket_type type,
 		return NT_STATUS_INVALID_PARAMETER;
 	}
 
-	return socket_create_with_ops(NULL, ops, new_sock, type, flags);
+	return socket_create_with_ops(mem_ctx, ops, new_sock, type, flags);
 }
 
 _PUBLIC_ NTSTATUS socket_connect(struct socket_context *sock,
diff --git a/source4/lib/socket/socket.h b/source4/lib/socket/socket.h
index 50a20d9..a492bc1 100644
--- a/source4/lib/socket/socket.h
+++ b/source4/lib/socket/socket.h
@@ -133,7 +133,8 @@ struct tsocket_address;
 NTSTATUS socket_create_with_ops(TALLOC_CTX *mem_ctx, const struct socket_ops *ops,
 				struct socket_context **new_sock, 
 				enum socket_type type, uint32_t flags);
-NTSTATUS socket_create(const char *name, enum socket_type type, 
+NTSTATUS socket_create(TALLOC_CTX *mem_ctx,
+		       const char *name, enum socket_type type,
 		       struct socket_context **new_sock, uint32_t flags);
 NTSTATUS socket_connect(struct socket_context *sock,
 			const struct socket_address *my_address, 
diff --git a/source4/lib/socket/testsuite.c b/source4/lib/socket/testsuite.c
index 6ebbd12..1df96e3 100644
--- a/source4/lib/socket/testsuite.c
+++ b/source4/lib/socket/testsuite.c
@@ -45,13 +45,11 @@ static bool test_udp(struct torture_context *tctx)
 
 	load_interface_list(tctx, tctx->lp_ctx, &ifaces);
 
-	status = socket_create("ip", SOCKET_TYPE_DGRAM, &sock1, 0);
+	status = socket_create(mem_ctx, "ip", SOCKET_TYPE_DGRAM, &sock1, 0);
 	torture_assert_ntstatus_ok(tctx, status, "creating DGRAM IP socket 1");
-	talloc_steal(mem_ctx, sock1);
 
-	status = socket_create("ip", SOCKET_TYPE_DGRAM, &sock2, 0);
+	status = socket_create(mem_ctx, "ip", SOCKET_TYPE_DGRAM, &sock2, 0);
 	torture_assert_ntstatus_ok(tctx, status, "creating DGRAM IP socket 1");
-	talloc_steal(mem_ctx, sock2);
 
 	localhost = socket_address_from_strings(sock1, sock1->backend_name, 
 						iface_list_best_ip(ifaces, "127.0.0.1"), 0);
@@ -128,13 +126,11 @@ static bool test_tcp(struct torture_context *tctx)
 	struct tevent_context *ev = tctx->ev;
 	struct interface *ifaces;
 
-	status = socket_create("ip", SOCKET_TYPE_STREAM, &sock1, 0);
+	status = socket_create(mem_ctx, "ip", SOCKET_TYPE_STREAM, &sock1, 0);
 	torture_assert_ntstatus_ok(tctx, status, "creating IP stream socket 1");
-	talloc_steal(mem_ctx, sock1);
 
-	status = socket_create("ip", SOCKET_TYPE_STREAM, &sock2, 0);
+	status = socket_create(mem_ctx, "ip", SOCKET_TYPE_STREAM, &sock2, 0);
 	torture_assert_ntstatus_ok(tctx, status, "creating IP stream socket 1");
-	talloc_steal(mem_ctx, sock2);
 
 	load_interface_list(tctx, tctx->lp_ctx, &ifaces);
 	localhost = socket_address_from_strings(sock1, sock1->backend_name, 
diff --git a/source4/libcli/dgram/dgramsocket.c b/source4/libcli/dgram/dgramsocket.c
index b6e7dd1..154a667 100644
--- a/source4/libcli/dgram/dgramsocket.c
+++ b/source4/libcli/dgram/dgramsocket.c
@@ -168,13 +168,12 @@ struct nbt_dgram_socket *nbt_dgram_socket_init(TALLOC_CTX *mem_ctx,
 	dgmsock->event_ctx = event_ctx;
 	if (dgmsock->event_ctx == NULL) goto failed;
 
-	status = socket_create("ip", SOCKET_TYPE_DGRAM, &dgmsock->sock, 0);
+	status = socket_create(dgmsock, "ip", SOCKET_TYPE_DGRAM,
+			       &dgmsock->sock, 0);
 	if (!NT_STATUS_IS_OK(status)) goto failed;
 
 	socket_set_option(dgmsock->sock, "SO_BROADCAST", "1");
 
-	talloc_steal(dgmsock, dgmsock->sock);
-
 	dgmsock->fde = tevent_add_fd(dgmsock->event_ctx, dgmsock,
 				    socket_get_fd(dgmsock->sock), 0,
 				    dgm_socket_handler, dgmsock);
diff --git a/source4/libcli/dgram/libdgram.h b/source4/libcli/dgram/libdgram.h
index 280c27d..0f313a6 100644
--- a/source4/libcli/dgram/libdgram.h
+++ b/source4/libcli/dgram/libdgram.h
@@ -127,13 +127,11 @@ NTSTATUS dgram_mailslot_netlogon_reply(struct nbt_dgram_socket *dgmsock,
 				       const char *my_netbios_name,
 				       const char *mailslot_name,
 				       struct nbt_netlogon_response *reply);
-NTSTATUS dgram_mailslot_netlogon_parse_request(struct dgram_mailslot_handler *dgmslot,
-					       TALLOC_CTX *mem_ctx,
+NTSTATUS dgram_mailslot_netlogon_parse_request(TALLOC_CTX *mem_ctx,
 					       struct nbt_dgram_packet *dgram,
 					       struct nbt_netlogon_packet *netlogon);
 
-NTSTATUS dgram_mailslot_netlogon_parse_response(struct dgram_mailslot_handler *dgmslot,
-						TALLOC_CTX *mem_ctx,
+NTSTATUS dgram_mailslot_netlogon_parse_response(TALLOC_CTX *mem_ctx,
 						struct nbt_dgram_packet *dgram,
 						struct nbt_netlogon_response *netlogon);
 
diff --git a/source4/libcli/dgram/netlogon.c b/source4/libcli/dgram/netlogon.c
index a16a3b9..25612ac 100644
--- a/source4/libcli/dgram/netlogon.c
+++ b/source4/libcli/dgram/netlogon.c
@@ -99,8 +99,7 @@ NTSTATUS dgram_mailslot_netlogon_reply(struct nbt_dgram_socket *dgmsock,
 /*
   parse a netlogon request. The packet must be a valid mailslot packet
 */
-NTSTATUS dgram_mailslot_netlogon_parse_request(struct dgram_mailslot_handler *dgmslot,
-					       TALLOC_CTX *mem_ctx,
+NTSTATUS dgram_mailslot_netlogon_parse_request(TALLOC_CTX *mem_ctx,
 					       struct nbt_dgram_packet *dgram,
 					       struct nbt_netlogon_packet *netlogon)
 {
@@ -124,10 +123,9 @@ NTSTATUS dgram_mailslot_netlogon_parse_request(struct dgram_mailslot_handler *dg
 /*
   parse a netlogon response. The packet must be a valid mailslot packet
 */
-NTSTATUS dgram_mailslot_netlogon_parse_response(struct dgram_mailslot_handler *dgmslot,
-				       TALLOC_CTX *mem_ctx,
-				       struct nbt_dgram_packet *dgram,
-				       struct nbt_netlogon_response *netlogon)
+NTSTATUS dgram_mailslot_netlogon_parse_response(TALLOC_CTX *mem_ctx,
+						struct nbt_dgram_packet *dgram,
+						struct nbt_netlogon_response *netlogon)
 {
 	NTSTATUS status;
 	DATA_BLOB data = dgram_mailslot_data(dgram);
diff --git a/source4/libcli/ldap/ldap_client.c b/source4/libcli/ldap/ldap_client.c
index b5f5da6..1cbcd0d 100644
--- a/source4/libcli/ldap/ldap_client.c
+++ b/source4/libcli/ldap/ldap_client.c
@@ -413,11 +413,12 @@ _PUBLIC_ struct composite_context *ldap_connect_send(struct ldap_connection *con
 		struct socket_address *unix_addr;
 		char path[1025];
 		char *end = NULL;
-		NTSTATUS status = socket_create("unix", SOCKET_TYPE_STREAM, &state->sock, 0);
+		NTSTATUS status = socket_create(state, "unix",
+						SOCKET_TYPE_STREAM,
+						&state->sock, 0);
 		if (!NT_STATUS_IS_OK(status)) {
 			return NULL;
 		}
-		talloc_steal(state, state->sock);
 		SMB_ASSERT(sizeof(protocol)>10);
 		SMB_ASSERT(sizeof(path)>1024);
 	
diff --git a/source4/librpc/rpc/dcerpc_sock.c b/source4/librpc/rpc/dcerpc_sock.c
index 6401534..e7ecca7 100644
--- a/source4/librpc/rpc/dcerpc_sock.c
+++ b/source4/librpc/rpc/dcerpc_sock.c
@@ -151,11 +151,10 @@ static struct composite_context *dcerpc_pipe_open_socket_send(TALLOC_CTX *mem_ct
 		if (composite_nomem(s->target_hostname, c)) return c;
 	}
 
-	c->status = socket_create(server->family, SOCKET_TYPE_STREAM, &s->socket_ctx, 0);
+	c->status = socket_create(s, server->family, SOCKET_TYPE_STREAM,
+				  &s->socket_ctx, 0);
 	if (!composite_is_ok(c)) return c;
 
-	talloc_steal(s, s->socket_ctx);
-
 	conn_req = socket_connect_send(s->socket_ctx, s->localaddr, s->server, 0,
 				       c->event_ctx);
 	composite_continue(c, conn_req, continue_socket_connect, c);
diff --git a/source4/nbt_server/dgram/netlogon.c b/source4/nbt_server/dgram/netlogon.c
index c88ffb5..1fee1d8 100644
--- a/source4/nbt_server/dgram/netlogon.c
+++ b/source4/nbt_server/dgram/netlogon.c
@@ -36,166 +36,249 @@
 /*
   reply to a GETDC request
  */
-static void nbtd_netlogon_getdc(struct dgram_mailslot_handler *dgmslot, 
-				struct nbtd_interface *iface,
-				struct nbt_dgram_packet *packet, 
-				const struct socket_address *src,
-				struct nbt_netlogon_packet *netlogon)
+static NTSTATUS nbtd_netlogon_getdc(struct nbtd_server *nbtsrv,
+				    struct nbt_name *dst_name,
+				    struct nbt_netlogon_packet *netlogon,
+				    TALLOC_CTX *mem_ctx,
+				    struct nbt_netlogon_response **presponse,
+				    char **preply_mailslot)
 {
-	struct nbt_name *name = &packet->data.msg.dest_name;
-	struct nbtd_interface *reply_iface = nbtd_find_reply_iface(iface, src->addr, false);
 	struct nbt_netlogon_response_from_pdc *pdc;
 	struct ldb_context *samctx;
-	struct nbt_netlogon_response netlogon_response;
+	struct nbt_netlogon_response *response = NULL;
+	char *reply_mailslot = NULL;
 
 	/* only answer getdc requests on the PDC or LOGON names */
-	if (name->type != NBT_NAME_PDC && name->type != NBT_NAME_LOGON) {
-		return;
+	if ((dst_name->type != NBT_NAME_PDC) &&
+	    (dst_name->type != NBT_NAME_LOGON)) {
+		return NT_STATUS_NOT_SUPPORTED;
 	}
 
-	samctx = iface->nbtsrv->sam_ctx;
+	samctx = nbtsrv->sam_ctx;
 
-	if (lpcfg_server_role(iface->nbtsrv->task->lp_ctx) != ROLE_ACTIVE_DIRECTORY_DC
+	if (lpcfg_server_role(nbtsrv->task->lp_ctx) != ROLE_ACTIVE_DIRECTORY_DC
 	    || !samdb_is_pdc(samctx)) {
 		DEBUG(2, ("Not a PDC, so not processing LOGON_PRIMARY_QUERY\n"));
-		return;		
+		return NT_STATUS_NOT_SUPPORTED;
 	}
 
-	if (strcasecmp_m(name->name, lpcfg_workgroup(iface->nbtsrv->task->lp_ctx)) != 0) {
-		DEBUG(5,("GetDC requested for a domian %s that we don't host\n", name->name));
-		return;
+	if (strcasecmp_m(dst_name->name,
+			 lpcfg_workgroup(nbtsrv->task->lp_ctx)) != 0) {
+		DBG_INFO("GetDC requested for a domain %s that we don't "
+			 "host\n", dst_name->name);
+		return NT_STATUS_NOT_SUPPORTED;
+	}
+
+	reply_mailslot = talloc_strdup(
+		mem_ctx, netlogon->req.pdc.mailslot_name);
+	if (reply_mailslot == NULL) {
+		goto nomem;
 	}
 
 	/* setup a GETDC reply */
-	ZERO_STRUCT(netlogon_response);
-	netlogon_response.response_type = NETLOGON_GET_PDC;
-	pdc = &netlogon_response.data.get_pdc;
+	response = talloc_zero(mem_ctx, struct nbt_netlogon_response);
+	if (response == NULL) {
+		goto nomem;
+	}
+	response->response_type = NETLOGON_GET_PDC;
+	pdc = &response->data.get_pdc;
 
 	pdc->command = NETLOGON_RESPONSE_FROM_PDC;
-	pdc->pdc_name         = lpcfg_netbios_name(iface->nbtsrv->task->lp_ctx);
+
+	pdc->pdc_name = talloc_strdup(
+		response, lpcfg_netbios_name(nbtsrv->task->lp_ctx));
+	if (pdc->pdc_name == NULL) {
+		goto nomem;
+	}
+
 	pdc->unicode_pdc_name = pdc->pdc_name;
-	pdc->domain_name      = lpcfg_workgroup(iface->nbtsrv->task->lp_ctx);
+
+	pdc->domain_name = talloc_strdup(
+		response, lpcfg_workgroup(nbtsrv->task->lp_ctx));
+	if (pdc->domain_name == NULL) {
+		goto nomem;
+	}
+
 	pdc->nt_version       = 1;
 	pdc->lmnt_token       = 0xFFFF;
 	pdc->lm20_token       = 0xFFFF;
 
-	dgram_mailslot_netlogon_reply(reply_iface->dgmsock, 
-				      packet, 
-				      lpcfg_netbios_name(iface->nbtsrv->task->lp_ctx),
-				      netlogon->req.pdc.mailslot_name,
-				      &netlogon_response);
-}
+	*presponse = response;
+	*preply_mailslot = reply_mailslot;
+	return NT_STATUS_OK;
 
+nomem:
+	TALLOC_FREE(response);
+	TALLOC_FREE(reply_mailslot);
+	return NT_STATUS_NO_MEMORY;
+}
 
 /*
   reply to a ADS style GETDC request
  */
-static void nbtd_netlogon_samlogon(struct dgram_mailslot_handler *dgmslot,
-				   struct nbtd_interface *iface,
-				   struct nbt_dgram_packet *packet, 
-				   const struct socket_address *src,
-				   struct nbt_netlogon_packet *netlogon)
+static NTSTATUS nbtd_netlogon_samlogon(
+	struct nbtd_server *nbtsrv,
+	struct nbt_name *dst_name,
+	const struct socket_address *src,
+	struct nbt_netlogon_packet *netlogon,
+	TALLOC_CTX *mem_ctx,
+	struct nbt_netlogon_response **presponse,
+	char **preply_mailslot)
 {
-	struct nbt_name *name = &packet->data.msg.dest_name;
-	struct nbtd_interface *reply_iface = nbtd_find_reply_iface(iface, src->addr, false);
 	struct ldb_context *samctx;
-	const char *my_ip = reply_iface->ip_address; 
-	struct dom_sid *sid;
-	struct nbt_netlogon_response netlogon_response;
+	struct dom_sid *sid = NULL;
+	struct nbt_netlogon_response *response = NULL;
+	char *reply_mailslot = NULL;
 	NTSTATUS status;
 
-	if (!my_ip) {
-		DEBUG(0, ("Could not obtain own IP address for datagram socket\n"));
-		return;
-	}
-
 	/* only answer getdc requests on the PDC or LOGON names */
-	if (name->type != NBT_NAME_PDC && name->type != NBT_NAME_LOGON) {
-		return;
+	if ((dst_name->type != NBT_NAME_PDC) &&
+	    (dst_name->type != NBT_NAME_LOGON)) {
+		return NT_STATUS_NOT_SUPPORTED;
 	}
 
-	samctx = iface->nbtsrv->sam_ctx;
+	samctx = nbtsrv->sam_ctx;
 
-	if (netlogon->req.logon.sid_size) {
+	if (netlogon->req.logon.sid_size != 0) {
 		sid = &netlogon->req.logon.sid;
-	} else {
-		sid = NULL;
 	}
 
-	status = fill_netlogon_samlogon_response(samctx, packet, NULL, name->name, sid, NULL, 
-						 netlogon->req.logon.user_name, netlogon->req.logon.acct_control, src->addr, 
-						 netlogon->req.logon.nt_version, iface->nbtsrv->task->lp_ctx, &netlogon_response.data.samlogon, false);
-	if (!NT_STATUS_IS_OK(status)) {
-		DEBUG(2,("NBT netlogon query failed domain=%s sid=%s version=%d - %s\n",
-			 name->name, dom_sid_string(packet, sid), netlogon->req.logon.nt_version, nt_errstr(status)));
-		return;
+	reply_mailslot = talloc_strdup(
+		mem_ctx, netlogon->req.logon.mailslot_name);
+	if (reply_mailslot == NULL) {
+		return NT_STATUS_NO_MEMORY;
 	}
 
-	netlogon_response.response_type = NETLOGON_SAMLOGON;
+	response = talloc_zero(mem_ctx, struct nbt_netlogon_response);
+	if (response == NULL) {
+		TALLOC_FREE(reply_mailslot);
+		return NT_STATUS_NO_MEMORY;
+	}
+	response->response_type = NETLOGON_SAMLOGON;
 
-	packet->data.msg.dest_name.type = 0;
+	status = fill_netlogon_samlogon_response(
+		samctx, response, NULL, dst_name->name, sid, NULL,
+		netlogon->req.logon.user_name,
+		netlogon->req.logon.acct_control, src->addr,
+		netlogon->req.logon.nt_version, nbtsrv->task->lp_ctx,
+		&response->data.samlogon, false);
+	if (!NT_STATUS_IS_OK(status)) {
+		char buf[DOM_SID_STR_BUFLEN];
+		dom_sid_string_buf(sid, buf, sizeof(buf));
 
-	dgram_mailslot_netlogon_reply(reply_iface->dgmsock, 
-				      packet, 
-				      lpcfg_netbios_name(iface->nbtsrv->task->lp_ctx),
-				      netlogon->req.logon.mailslot_name,
-				      &netlogon_response);
-}
+		DBG_NOTICE("NBT netlogon query failed domain=%s sid=%s "
+			   "version=%d - %s\n", dst_name->name, buf,
+			   netlogon->req.logon.nt_version, nt_errstr(status));
+		TALLOC_FREE(reply_mailslot);
+		TALLOC_FREE(response);
+		return status;
+	}
 
+	*presponse = response;
+	*preply_mailslot = reply_mailslot;
+	return NT_STATUS_OK;
+}
 
-/*
-  handle incoming netlogon mailslot requests
-*/
-void nbtd_mailslot_netlogon_handler(struct dgram_mailslot_handler *dgmslot, 
-				    struct nbt_dgram_packet *packet, 
-				    struct socket_address *src)
+static NTSTATUS nbtd_mailslot_netlogon_reply(
+	struct nbtd_interface *iface,
+	struct nbt_dgram_packet *packet,
+	struct socket_address *src,
+	TALLOC_CTX *mem_ctx,
+	struct nbt_netlogon_response **presponse,
+	char **preply_mailslot)
 {
-	NTSTATUS status = NT_STATUS_NO_MEMORY;
-	struct nbtd_interface *iface = 
-		talloc_get_type(dgmslot->private_data, struct nbtd_interface);
-	struct nbt_netlogon_packet *netlogon = 
-		talloc(dgmslot, struct nbt_netlogon_packet);
+	struct nbt_netlogon_packet *netlogon;
+	struct nbt_name *dst_name = &packet->data.msg.dest_name;
+	struct nbt_netlogon_response *response = NULL;
 	struct nbtd_iface_name *iname;
-	struct nbt_name *name = &packet->data.msg.dest_name;
-
-	if (netlogon == NULL) goto failed;
+	char *reply_mailslot = NULL;
+	NTSTATUS status;
 
 	/*
 	  see if the we are listening on the destination netbios name
 	*/
-	iname = nbtd_find_iname(iface, name, 0);


-- 
Samba Shared Repository



More information about the samba-cvs mailing list