[PATCH] A few small ones around name lookup

Jeremy Allison jra at samba.org
Tue Jan 23 00:48:31 UTC 2018


On Mon, Jan 22, 2018 at 09:34:56PM +0100, Volker Lendecke via samba-technical wrote:
> Hi!
> 
> Review appreciated!

LGTM. RB+ and pushed !

> -- 
> Besuchen Sie die verinice.XP 2018 in Berlin,
> Anwenderkonferenz für Informationssicherheit
> vom 21.-23.03.2018 im Sofitel Kurfürstendamm
> Info & Anmeldung hier: http://veriniceXP.org
> 
> SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
> phone: +49-551-370000-0, fax: +49-551-370000-9
> AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
> http://www.sernet.de, mailto:kontakt at sernet.de

> From 9020ee9a53844136691c5ed673d7529415b910fd Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Mon, 15 Jan 2018 16:12:15 +0100
> Subject: [PATCH 1/8] libsmb: Give unexpected.c its own header
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source3/libsmb/clidgram.c   |  1 +
>  source3/libsmb/namequery.c  |  1 +
>  source3/libsmb/nmblib.h     | 22 --------------------
>  source3/libsmb/unexpected.c |  3 ++-
>  source3/libsmb/unexpected.h | 49 +++++++++++++++++++++++++++++++++++++++++++++
>  source3/nmbd/nmbd_packets.c |  1 +
>  6 files changed, 54 insertions(+), 23 deletions(-)
>  create mode 100644 source3/libsmb/unexpected.h
> 
> diff --git a/source3/libsmb/clidgram.c b/source3/libsmb/clidgram.c
> index d8fa1c6b935..8f0dba3e0d8 100644
> --- a/source3/libsmb/clidgram.c
> +++ b/source3/libsmb/clidgram.c
> @@ -24,6 +24,7 @@
>  #include "../lib/util/tevent_ntstatus.h"
>  #include "libsmb/clidgram.h"
>  #include "libsmb/nmblib.h"
> +#include "libsmb/unexpected.h"
>  #include "messages.h"
>  #include "librpc/gen_ndr/samr.h"
>  #include "../lib/util/pidfile.h"
> diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c
> index 4b41546b533..6107e8ff7b4 100644
> --- a/source3/libsmb/namequery.c
> +++ b/source3/libsmb/namequery.c
> @@ -26,6 +26,7 @@
>  #include "lib/async_req/async_sock.h"
>  #include "lib/tsocket/tsocket.h"
>  #include "libsmb/nmblib.h"
> +#include "libsmb/unexpected.h"
>  #include "../libcli/nbt/libnbt.h"
>  #include "libads/kerberos_proto.h"
>  
> diff --git a/source3/libsmb/nmblib.h b/source3/libsmb/nmblib.h
> index d8290dc0765..7e1e40c13e7 100644
> --- a/source3/libsmb/nmblib.h
> +++ b/source3/libsmb/nmblib.h
> @@ -27,28 +27,6 @@
>  
>  #include "nameserv.h"
>  
> -struct nb_packet_server;
> -struct nb_packet_reader;
> -
> -NTSTATUS nb_packet_server_create(TALLOC_CTX *mem_ctx,
> -				 struct tevent_context *ev,
> -				 int max_clients,
> -				 struct nb_packet_server **presult);
> -void nb_packet_dispatch(struct nb_packet_server *server,
> -			struct packet_struct *p);
> -struct tevent_req *nb_packet_reader_send(TALLOC_CTX *mem_ctx,
> -					 struct tevent_context *ev,
> -					 enum packet_type type,
> -					 int trn_id,
> -					 const char *mailslot_name);
> -NTSTATUS nb_packet_reader_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
> -			       struct nb_packet_reader **preader);
> -struct tevent_req *nb_packet_read_send(TALLOC_CTX *mem_ctx,
> -				       struct tevent_context *ev,
> -				       struct nb_packet_reader *reader);
> -NTSTATUS nb_packet_read_recv(struct tevent_req *req,
> -			     struct packet_struct **ppacket);
> -
>  /* The following definitions come from libsmb/nmblib.c  */
>  
>  void debug_nmb_packet(struct packet_struct *p);
> diff --git a/source3/libsmb/unexpected.c b/source3/libsmb/unexpected.c
> index dd9ff7a22e1..96de1445a67 100644
> --- a/source3/libsmb/unexpected.c
> +++ b/source3/libsmb/unexpected.c
> @@ -19,10 +19,11 @@
>  */
>  
>  #include "includes.h"
> +#include "libsmb/unexpected.h"
>  #include "../lib/util/tevent_ntstatus.h"
>  #include "lib/util_tsock.h"
> -#include "lib/tsocket/tsocket.h"
>  #include "libsmb/nmblib.h"
> +#include "lib/tsocket/tsocket.h"
>  #include "lib/util/sys_rw.h"
>  
>  static const char *nmbd_socket_dir(void)
> diff --git a/source3/libsmb/unexpected.h b/source3/libsmb/unexpected.h
> new file mode 100644
> index 00000000000..a40a507f6e5
> --- /dev/null
> +++ b/source3/libsmb/unexpected.h
> @@ -0,0 +1,49 @@
> +/*
> + * Unix SMB/CIFS implementation.
> + * Copyright (C) Volker Lendecke 2018
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 3 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#ifndef __LIBSMB_UNEXPECTED_H__
> +#define __LIBSMB_UNEXPECTED_H__
> +
> +#include "replace.h"
> +#include <tevent.h>
> +#include "libcli/util/ntstatus.h"
> +#include "nameserv.h"
> +
> +struct nb_packet_server;
> +struct nb_packet_reader;
> +
> +NTSTATUS nb_packet_server_create(TALLOC_CTX *mem_ctx,
> +				 struct tevent_context *ev,
> +				 int max_clients,
> +				 struct nb_packet_server **presult);
> +void nb_packet_dispatch(struct nb_packet_server *server,
> +			struct packet_struct *p);
> +struct tevent_req *nb_packet_reader_send(TALLOC_CTX *mem_ctx,
> +					 struct tevent_context *ev,
> +					 enum packet_type type,
> +					 int trn_id,
> +					 const char *mailslot_name);
> +NTSTATUS nb_packet_reader_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
> +			       struct nb_packet_reader **preader);
> +struct tevent_req *nb_packet_read_send(TALLOC_CTX *mem_ctx,
> +				       struct tevent_context *ev,
> +				       struct nb_packet_reader *reader);
> +NTSTATUS nb_packet_read_recv(struct tevent_req *req,
> +			     struct packet_struct **ppacket);
> +
> +#endif
> diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c
> index de5ae1efef1..2b7cc82f341 100644
> --- a/source3/nmbd/nmbd_packets.c
> +++ b/source3/nmbd/nmbd_packets.c
> @@ -24,6 +24,7 @@
>  #include "../lib/util/select.h"
>  #include "system/select.h"
>  #include "libsmb/libsmb.h"
> +#include "libsmb/unexpected.h"
>  
>  extern int ClientNMB;
>  extern int ClientDGRAM;
> -- 
> 2.11.0
> 
> 
> From 1883b77e8f951991708760d9b0b830361920428c Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Tue, 16 Jan 2018 15:07:47 +0100
> Subject: [PATCH 2/8] libnmb: Remove a pointless struct member
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source3/libsmb/unexpected.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/source3/libsmb/unexpected.c b/source3/libsmb/unexpected.c
> index 96de1445a67..cf531c00434 100644
> --- a/source3/libsmb/unexpected.c
> +++ b/source3/libsmb/unexpected.c
> @@ -481,7 +481,6 @@ struct nb_packet_reader_state {
>  	struct nb_packet_query query;
>  	const char *mailslot_name;
>  	struct iovec iov[2];
> -	char c;
>  	struct nb_packet_reader *reader;
>  };
>  
> @@ -602,7 +601,7 @@ static void nb_packet_reader_sent_query(struct tevent_req *subreq)
>  	}
>  	subreq = tstream_read_packet_send(state, state->ev,
>  					  state->reader->sock,
> -					  sizeof(state->c), NULL, NULL);
> +					  1, NULL, NULL);
>  	if (tevent_req_nomem(subreq, req)) {
>  		return;
>  	}
> @@ -627,9 +626,8 @@ static void nb_packet_reader_got_ack(struct tevent_req *subreq)
>  		tevent_req_nterror(req, map_nt_error_from_unix(err));
>  		return;
>  	}
> -	if (nread != sizeof(state->c)) {
> -		DEBUG(10, ("read = %d, expected %d\n", (int)nread,
> -			   (int)sizeof(state->c)));
> +	if (nread != 1) {
> +		DBG_DEBUG("read = %zd, expected 1\n", nread);
>  		tevent_req_nterror(req, NT_STATUS_UNEXPECTED_IO_ERROR);
>  		return;
>  	}
> -- 
> 2.11.0
> 
> 
> From 6e66081a7937106f010ec5fc6f8c36196c502da2 Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Tue, 16 Jan 2018 15:04:06 +0100
> Subject: [PATCH 3/8] libnmb: tsocket_address_unix_from_path deals fine with
>  NULL
> 
> Other callers use NULL instead of "". Streamline it a bit
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source3/libsmb/unexpected.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/source3/libsmb/unexpected.c b/source3/libsmb/unexpected.c
> index cf531c00434..b2211dd98bf 100644
> --- a/source3/libsmb/unexpected.c
> +++ b/source3/libsmb/unexpected.c
> @@ -520,7 +520,7 @@ struct tevent_req *nb_packet_reader_send(TALLOC_CTX *mem_ctx,
>  		return tevent_req_post(req, ev);
>  	}
>  
> -	ret = tsocket_address_unix_from_path(state, "", &laddr);
> +	ret = tsocket_address_unix_from_path(state, NULL, &laddr);
>  	if (ret != 0) {
>  		tevent_req_nterror(req, map_nt_error_from_unix(errno));
>  		return tevent_req_post(req, ev);
> -- 
> 2.11.0
> 
> 
> From 48e8b3d4f5697b17a1b3e32dc63d68c173e92654 Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Thu, 18 Jan 2018 13:28:30 +0100
> Subject: [PATCH 4/8] libnmb: Fix two signed/unsigned hickups
> 
> Two warnings less
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source3/libsmb/unexpected.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/source3/libsmb/unexpected.c b/source3/libsmb/unexpected.c
> index b2211dd98bf..16d1f677b94 100644
> --- a/source3/libsmb/unexpected.c
> +++ b/source3/libsmb/unexpected.c
> @@ -257,7 +257,8 @@ static void nb_packet_got_query(struct tevent_req *req)
>  	/* Take care of alignment */
>  	memcpy(&q, buf, sizeof(q));
>  
> -	if (nread != sizeof(struct nb_packet_query) + q.mailslot_namelen) {
> +	if ((size_t)nread !=
> +	    sizeof(struct nb_packet_query) + q.mailslot_namelen) {
>  		DEBUG(10, ("nb_packet_got_query: Invalid mailslot namelength\n"));
>  		TALLOC_FREE(client);
>  		return;
> @@ -595,7 +596,8 @@ static void nb_packet_reader_sent_query(struct tevent_req *subreq)
>  		tevent_req_nterror(req, map_nt_error_from_unix(err));
>  		return;
>  	}
> -	if (written != sizeof(state->query) + state->query.mailslot_namelen) {
> +	if ((size_t)written !=
> +	    sizeof(state->query) + state->query.mailslot_namelen) {
>  		tevent_req_nterror(req, NT_STATUS_UNEXPECTED_IO_ERROR);
>  		return;
>  	}
> -- 
> 2.11.0
> 
> 
> From b2d1ac5f0dad378e1985bde4f68e7da9ad93ad00 Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Fri, 5 Jan 2018 17:11:43 +0100
> Subject: [PATCH 5/8] dsgetdcname: Fix a signed/unsigned hickup
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source3/libsmb/dsgetdcname.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/source3/libsmb/dsgetdcname.c b/source3/libsmb/dsgetdcname.c
> index ce0cc89899c..f15456a8f4a 100644
> --- a/source3/libsmb/dsgetdcname.c
> +++ b/source3/libsmb/dsgetdcname.c
> @@ -500,7 +500,8 @@ static NTSTATUS discover_dc_dns(TALLOC_CTX *mem_ctx,
>  				struct ip_service_name **returned_dclist,
>  				int *return_count)
>  {
> -	int i, j;
> +	int i;
> +	size_t j;
>  	NTSTATUS status;
>  	struct dns_rr_srv *dcs = NULL;
>  	int numdcs = 0;
> -- 
> 2.11.0
> 
> 
> From 55efb0fbb48a71ab2422d15db1f42f9c651abb09 Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Sat, 13 Jan 2018 17:38:16 +0100
> Subject: [PATCH 6/8] libcli/resolve: Fix typos
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source4/libcli/resolve/lmhosts.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/source4/libcli/resolve/lmhosts.c b/source4/libcli/resolve/lmhosts.c
> index 21cc3e4f00b..9062da91881 100644
> --- a/source4/libcli/resolve/lmhosts.c
> +++ b/source4/libcli/resolve/lmhosts.c
> @@ -1,7 +1,7 @@
>  /*
>     Unix SMB/CIFS implementation.
>  
> -   broadcast name resolution module
> +   lmhosts name resolution module
>  
>     Copyright (C) Andrew Tridgell 1994-1998,2005
>     Copyright (C) Jeremy Allison 2007
> @@ -38,7 +38,7 @@ struct resolve_lmhosts_state {
>  };
>  
>  /**
> -  broadcast name resolution method - async send
> +  lmhosts name resolution method - async send
>   */
>  /*
>    general name resolution - async send
> -- 
> 2.11.0
> 
> 
> From f51995ae9d28b0b80e8437aa13bcf6577a6eae3b Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Sat, 13 Jan 2018 17:39:24 +0100
> Subject: [PATCH 7/8] libcli/resolve: Make functions static
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source4/libcli/resolve/lmhosts.c | 19 ++++++++++---------
>  1 file changed, 10 insertions(+), 9 deletions(-)
> 
> diff --git a/source4/libcli/resolve/lmhosts.c b/source4/libcli/resolve/lmhosts.c
> index 9062da91881..400cf79f68b 100644
> --- a/source4/libcli/resolve/lmhosts.c
> +++ b/source4/libcli/resolve/lmhosts.c
> @@ -43,11 +43,12 @@ struct resolve_lmhosts_state {
>  /*
>    general name resolution - async send
>   */
> -struct composite_context *resolve_name_lmhosts_send(TALLOC_CTX *mem_ctx,
> -						  struct tevent_context *event_ctx,
> -						  void *userdata, uint32_t flags,
> -						  uint16_t port,
> -						  struct nbt_name *name)
> +static struct composite_context *resolve_name_lmhosts_send(
> +	TALLOC_CTX *mem_ctx,
> +	struct tevent_context *event_ctx,
> +	void *userdata, uint32_t flags,
> +	uint16_t port,
> +	struct nbt_name *name)
>  {
>  	struct composite_context *c;
>  	struct resolve_lmhosts_state *state;
> @@ -101,10 +102,10 @@ struct composite_context *resolve_name_lmhosts_send(TALLOC_CTX *mem_ctx,
>  /*
>    general name resolution method - recv side
>   */
> -NTSTATUS resolve_name_lmhosts_recv(struct composite_context *c,
> -				 TALLOC_CTX *mem_ctx,
> -				 struct socket_address ***addrs,
> -				 char ***names)
> +static NTSTATUS resolve_name_lmhosts_recv(struct composite_context *c,
> +					  TALLOC_CTX *mem_ctx,
> +					  struct socket_address ***addrs,
> +					  char ***names)
>  {
>  	NTSTATUS status;
>  
> -- 
> 2.11.0
> 
> 
> From 86dd87ab9613d663c6bd41726e2f4fb1db791086 Mon Sep 17 00:00:00 2001
> From: Volker Lendecke <vl at samba.org>
> Date: Sat, 13 Jan 2018 17:41:01 +0100
> Subject: [PATCH 8/8] libcli/resolve: Make functions static
> 
> Signed-off-by: Volker Lendecke <vl at samba.org>
> ---
>  source4/libcli/resolve/bcast.c | 19 ++++++++++---------
>  1 file changed, 10 insertions(+), 9 deletions(-)
> 
> diff --git a/source4/libcli/resolve/bcast.c b/source4/libcli/resolve/bcast.c
> index 787d048a684..277a82d80e2 100644
> --- a/source4/libcli/resolve/bcast.c
> +++ b/source4/libcli/resolve/bcast.c
> @@ -35,11 +35,12 @@ struct resolve_bcast_data {
>  /**
>    broadcast name resolution method - async send
>   */
> -struct composite_context *resolve_name_bcast_send(TALLOC_CTX *mem_ctx, 
> -						  struct tevent_context *event_ctx,
> -						  void *userdata, uint32_t flags,
> -						  uint16_t port,
> -						  struct nbt_name *name)
> +static struct composite_context *resolve_name_bcast_send(
> +	TALLOC_CTX *mem_ctx,
> +	struct tevent_context *event_ctx,
> +	void *userdata, uint32_t flags,
> +	uint16_t port,
> +	struct nbt_name *name)
>  {
>  	int num_interfaces;
>  	const char **address_list;
> @@ -85,10 +86,10 @@ struct composite_context *resolve_name_bcast_send(TALLOC_CTX *mem_ctx,
>  /*
>    broadcast name resolution method - recv side
>   */
> -NTSTATUS resolve_name_bcast_recv(struct composite_context *c, 
> -				 TALLOC_CTX *mem_ctx,
> -				 struct socket_address ***addrs,
> -				 char ***names)
> +static NTSTATUS resolve_name_bcast_recv(struct composite_context *c,
> +					TALLOC_CTX *mem_ctx,
> +					struct socket_address ***addrs,
> +					char ***names)
>  {
>  	NTSTATUS status = resolve_name_nbtlist_recv(c, mem_ctx, addrs, names);
>  	if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
> -- 
> 2.11.0
> 




More information about the samba-technical mailing list