[PATCH] Small cleanups around name lookup

Volker Lendecke Volker.Lendecke at SerNet.DE
Fri Mar 30 13:51:13 UTC 2018


Hi!

Review appreciated!

Thanks, Volker

-- 
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
-------------- next part --------------
From c25ff11cdee5fff645c149da04094e0683744626 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 25 Jan 2018 14:07:53 +0100
Subject: [PATCH 1/8] nmbd: Fix a typo

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/nmbd/nmbd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c
index 9be708a9c02..73a3b8bf960 100644
--- a/source3/nmbd/nmbd.c
+++ b/source3/nmbd/nmbd.c
@@ -531,7 +531,7 @@ static void process(struct messaging_context *msg)
 		 * Process all incoming packets
 		 * read above. This calls the success and
 		 * failure functions registered when response
-		 * packets arrrive, and also deals with request
+		 * packets arrive, and also deals with request
 		 * packets from other sources.
 		 * (nmbd_packets.c)
 		 */
-- 
2.11.0


From 2af102e4916fe4adb2a8502386b3148922ff7610 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 25 Jan 2018 14:21:22 +0100
Subject: [PATCH 2/8] nmbd: Fix a typo

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/nmbd/nmbd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c
index 73a3b8bf960..7884ff8dd06 100644
--- a/source3/nmbd/nmbd.c
+++ b/source3/nmbd/nmbd.c
@@ -338,7 +338,7 @@ static void reload_interfaces(time_t t)
 			}
 		}
 		if (n == -1) {
-			/* oops, an interface has disapeared. This is
+			/* oops, an interface has disappeared. This is
 			 tricky, we don't dare actually free the
 			 interface as it could be being used, so
 			 instead we just wear the memory leak and
-- 
2.11.0


From eaead1cb4f6f44d625de3525d99c73731ca4dbe0 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 10 Mar 2018 15:35:43 +0100
Subject: [PATCH 3/8] libsmb: Remove unused trustdom_cache.c

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/include/proto.h         |   7 -
 source3/libsmb/trustdom_cache.c | 360 ----------------------------------------
 source3/wscript_build           |   1 -
 3 files changed, 368 deletions(-)
 delete mode 100644 source3/libsmb/trustdom_cache.c

diff --git a/source3/include/proto.h b/source3/include/proto.h
index fa87407ff24..778107a4d84 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -817,13 +817,6 @@ const char *get_dos_error_msg(WERROR result);
 const char *smb_dos_err_class(uint8_t e_class);
 WERROR map_werror_from_unix(int error);
 
-/* The following definitions come from libsmb/trustdom_cache.c  */
-
-bool trustdom_cache_store(const char *name, const struct dom_sid *sid);
-bool trustdom_cache_fetch(const char* name, struct dom_sid* sid);
-void trustdom_cache_flush(void);
-void update_trustdom_cache( void );
-
 /* The following definitions come from libsmb/trusts_util.c  */
 
 struct netlogon_creds_cli_context;
diff --git a/source3/libsmb/trustdom_cache.c b/source3/libsmb/trustdom_cache.c
deleted file mode 100644
index 54f959173c7..00000000000
--- a/source3/libsmb/trustdom_cache.c
+++ /dev/null
@@ -1,360 +0,0 @@
-/*
-   Unix SMB/CIFS implementation.
-
-   Trusted domain names cache on top of gencache.
-
-   Copyright (C) Rafal Szczesniak	2002
-
-   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/>.
-*/
-
-#include "includes.h"
-#include "../libcli/security/security.h"
-#include "../librpc/gen_ndr/ndr_lsa_c.h"
-#include "libsmb/libsmb.h"
-#include "rpc_client/cli_pipe.h"
-#include "rpc_client/cli_lsarpc.h"
-
-#undef DBGC_CLASS
-#define DBGC_CLASS DBGC_ALL	/* there's no proper class yet */
-
-#define TDOMKEY_FMT  "TDOM/%s"
-#define TDOMTSKEY    "TDOMCACHE/TIMESTAMP"
-#define TRUSTDOM_UPDATE_INTERVAL	600
-
-
-/**
- * @file trustdom_cache.c
- *
- * Implementation of trusted domain names cache useful when
- * samba acts as domain member server. In such case, caching
- * domain names currently trusted gives a performance gain
- * because there's no need to query PDC each time we need
- * list of trusted domains
- **/
-
-/**
- * Form up trustdom name key. It is based only
- * on domain name now.
- *
- * @param name trusted domain name
- * @return cache key for use in gencache mechanism
- **/
-
-static char *trustdom_cache_key(TALLOC_CTX *mem_ctx, const char *name)
-{
-	return talloc_asprintf_strupper_m(mem_ctx, TDOMKEY_FMT, name);
-}
-
-
-/**
- * Store trusted domain in gencache as the domain name (key)
- * and trusted domain's SID (value)
- *
- * @param name trusted domain name
- * @param alt_name alternative trusted domain name (used in ADS domains)
- * @param sid trusted domain's SID
- * @param timeout cache entry expiration time
- * @return true upon successful value storing or
- *         false if store attempt failed
- **/
-
-bool trustdom_cache_store(const char *name, const struct dom_sid *sid)
-{
-	char *key;
-	fstring sid_string;
-	bool ret;
-
-	DEBUG(5, ("trustdom_store: storing SID %s of domain %s\n",
-	          sid_string_dbg(sid), name));
-
-	key = trustdom_cache_key(talloc_tos(), name);
-
-	/* Generate string representation domain SID */
-	sid_to_fstring(sid_string, sid);
-
-	ret = gencache_set(key, sid_string,
-			   time(NULL) + TRUSTDOM_UPDATE_INTERVAL);
-	TALLOC_FREE(key);
-	return ret;
-}
-
-
-/**
- * Fetch trusted domain's SID from the gencache.
- * This routine can also be used to check whether given
- * domain is currently trusted one.
- *
- * @param name trusted domain name
- * @param sid trusted domain's SID to be returned
- * @return true if entry is found or
- *         false if has expired/doesn't exist
- **/
-
-bool trustdom_cache_fetch(const char* name, struct dom_sid* sid)
-{
-	char *key = NULL, *value = NULL;
-	time_t timeout;
-	bool ok;
-
-	/* exit now if null pointers were passed as they're required further */
-	if (sid == NULL) {
-		return false;
-	}
-
-	/* prepare a key and get the value */
-	key = trustdom_cache_key(talloc_tos(), name);
-	if (key == NULL) {
-		return false;
-	}
-
-	ok = gencache_get(key, talloc_tos(), &value, &timeout);
-	TALLOC_FREE(key);
-	if (!ok) {
-		DEBUG(5, ("no entry for trusted domain %s found.\n", name));
-		return false;
-	}
-
-	DEBUG(5, ("trusted domain %s found (%s)\n", name, value));
-
-	/* convert sid string representation into struct dom_sid structure */
-	ok = string_to_sid(sid, value);
-	TALLOC_FREE(value);
-	return ok;
-}
-
-/*******************************************************************
- fetch the timestamp from the last update
-*******************************************************************/
-
-static uint32_t trustdom_cache_fetch_timestamp(void)
-{
-	char *value = NULL;
-	time_t timeout;
-	uint32_t timestamp;
-
-	if (!gencache_get(TDOMTSKEY, talloc_tos(), &value, &timeout)) {
-		DEBUG(5, ("no timestamp for trusted domain cache located.\n"));
-		SAFE_FREE(value);
-		return 0;
-	}
-
-	timestamp = atoi(value);
-
-	TALLOC_FREE(value);
-	return timestamp;
-}
-
-/*******************************************************************
- store the timestamp from the last update
-*******************************************************************/
-
-static bool trustdom_cache_store_timestamp(uint32_t t, time_t timeout)
-{
-	fstring value;
-
-	fstr_sprintf(value, "%d", t );
-
-	if (!gencache_set(TDOMTSKEY, value, timeout)) {
-		DEBUG(5, ("failed to set timestamp for trustdom_cache\n"));
-		return False;
-	}
-
-	return True;
-}
-
-
-/**
- * Delete single trustdom entry. Look at the
- * gencache_iterate definition.
- *
- **/
-
-static void flush_trustdom_name(const char* key, const char *value, time_t timeout, void* dptr)
-{
-	gencache_del(key);
-	DEBUG(5, ("Deleting entry %s\n", key));
-}
-
-
-/**
- * Flush all the trusted domains entries from the cache.
- **/
-
-void trustdom_cache_flush(void)
-{
-	char *key = trustdom_cache_key(talloc_tos(), "*");
-	/*
-	 * iterate through each TDOM cache's entry and flush it
-	 * by flush_trustdom_name function
-	 */
-	gencache_iterate(flush_trustdom_name, NULL, key);
-	TALLOC_FREE(key);
-	DEBUG(5, ("Trusted domains cache flushed\n"));
-}
-
-/*********************************************************************
- Enumerate the list of trusted domains from a DC
-*********************************************************************/
-
-static bool enumerate_domain_trusts( TALLOC_CTX *mem_ctx, const char *domain,
-                                     char ***domain_names, uint32_t *num_domains,
-				     struct dom_sid **sids )
-{
-	struct policy_handle 	pol;
-	NTSTATUS status, result;
-	fstring 	dc_name;
-	struct sockaddr_storage	dc_ss;
-	uint32_t 		enum_ctx = 0;
-	struct cli_state *cli = NULL;
-	struct rpc_pipe_client *lsa_pipe = NULL;
-	struct lsa_DomainList dom_list;
-	int i;
-	struct dcerpc_binding_handle *b = NULL;
-
-	*domain_names = NULL;
-	*num_domains = 0;
-	*sids = NULL;
-
-	/* lookup a DC first */
-
-	if ( !get_dc_name(domain, NULL, dc_name, &dc_ss) ) {
-		DEBUG(3,("enumerate_domain_trusts: can't locate a DC for domain %s\n",
-			domain));
-		return False;
-	}
-
-	/* setup the anonymous connection */
-
-	status = cli_full_connection( &cli, lp_netbios_name(), dc_name, &dc_ss, 0, "IPC$", "IPC",
-		"", "", "", 0, Undefined);
-	if ( !NT_STATUS_IS_OK(status) )
-		goto done;
-
-	/* open the LSARPC_PIPE	*/
-
-	status = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc,
-					  &lsa_pipe);
-	if (!NT_STATUS_IS_OK(status)) {
-		goto done;
-	}
-
-	b = lsa_pipe->binding_handle;
-
-	/* get a handle */
-
-	status = rpccli_lsa_open_policy(lsa_pipe, mem_ctx, True,
-		LSA_POLICY_VIEW_LOCAL_INFORMATION, &pol);
-	if ( !NT_STATUS_IS_OK(status) )
-		goto done;
-
-	/* Lookup list of trusted domains */
-
-	status = dcerpc_lsa_EnumTrustDom(b, mem_ctx,
-					 &pol,
-					 &enum_ctx,
-					 &dom_list,
-					 (uint32_t)-1,
-					 &result);
-	if ( !NT_STATUS_IS_OK(status) )
-		goto done;
-	if (!NT_STATUS_IS_OK(result)) {
-		status = result;
-		goto done;
-	}
-
-	*num_domains = dom_list.count;
-
-	*domain_names = talloc_zero_array(mem_ctx, char *, *num_domains);
-	if (!*domain_names) {
-		status = NT_STATUS_NO_MEMORY;
-		goto done;
-	}
-
-	*sids = talloc_zero_array(mem_ctx, struct dom_sid, *num_domains);
-	if (!*sids) {
-		status = NT_STATUS_NO_MEMORY;
-		goto done;
-	}
-
-	for (i=0; i< *num_domains; i++) {
-		(*domain_names)[i] = discard_const_p(char, dom_list.domains[i].name.string);
-		(*sids)[i] = *dom_list.domains[i].sid;
-	}
-
-done:
-	/* cleanup */
-	if (cli) {
-		DEBUG(10,("enumerate_domain_trusts: shutting down connection...\n"));
-		cli_shutdown( cli );
-	}
-
-	return NT_STATUS_IS_OK(status);
-}
-
-/********************************************************************
- update the trustdom_cache if needed
-********************************************************************/
-
-void update_trustdom_cache( void )
-{
-	char **domain_names;
-	struct dom_sid *dom_sids;
-	uint32_t num_domains;
-	uint32_t last_check;
-	int time_diff;
-	TALLOC_CTX *mem_ctx = NULL;
-	time_t now = time(NULL);
-	int i;
-
-	/* get the timestamp.  We have to initialise it if the last timestamp == 0 */
-	if ( (last_check = trustdom_cache_fetch_timestamp()) == 0 )
-		trustdom_cache_store_timestamp(0, now+TRUSTDOM_UPDATE_INTERVAL);
-
-	time_diff = (int) (now - last_check);
-
-	if ( (time_diff > 0) && (time_diff < TRUSTDOM_UPDATE_INTERVAL) ) {
-		DEBUG(10,("update_trustdom_cache: not time to update trustdom_cache yet\n"));
-		return;
-	}
-
-	/* note that we don't lock the timestamp. This prevents this
-	   smbd from blocking all other smbd daemons while we
-	   enumerate the trusted domains */
-	trustdom_cache_store_timestamp(now, now+TRUSTDOM_UPDATE_INTERVAL);
-
-	if ( !(mem_ctx = talloc_init("update_trustdom_cache")) ) {
-		DEBUG(0,("update_trustdom_cache: talloc_init() failed!\n"));
-		goto done;
-	}
-
-	/* get the domains and store them */
-
-	if ( enumerate_domain_trusts(mem_ctx, lp_workgroup(), &domain_names,
-		&num_domains, &dom_sids)) {
-		for ( i=0; i<num_domains; i++ ) {
-			trustdom_cache_store(domain_names[i], &dom_sids[i]);
-		}
-	} else {
-		/* we failed to fetch the list of trusted domains - restore the old
-		   timestamp */
-		trustdom_cache_store_timestamp(last_check,
-					       last_check+TRUSTDOM_UPDATE_INTERVAL);
-	}
-
-done:
-	talloc_destroy( mem_ctx );
-
-	return;
-}
diff --git a/source3/wscript_build b/source3/wscript_build
index ed9ed24fae2..5080b2a114d 100644
--- a/source3/wscript_build
+++ b/source3/wscript_build
@@ -929,7 +929,6 @@ bld.SAMBA3_SUBSYSTEM('SLCACHE',
 bld.SAMBA3_SUBSYSTEM('DCUTIL',
                     source='''
                            libsmb/namequery_dc.c
-                           libsmb/trustdom_cache.c
                            libsmb/dsgetdcname.c
                            ''',
                     deps='''
-- 
2.11.0


From 1fc7a07967bd6101a9c28a7dd5ec21a3deb41ea6 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 10 Mar 2018 15:31:11 +0100
Subject: [PATCH 4/8] libsmb: Give namequery.c its own header

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/include/proto.h                     |  90 ----------------------
 source3/libads/kerberos.c                   |   1 +
 source3/libads/ldap.c                       |   1 +
 source3/libnet/libnet_join.c                |   1 +
 source3/libsmb/cliconnect.c                 |   1 +
 source3/libsmb/dsgetdcname.c                |   1 +
 source3/libsmb/libsmb_dir.c                 |   1 +
 source3/libsmb/namequery.c                  |   1 +
 source3/libsmb/namequery.h                  | 115 ++++++++++++++++++++++++++++
 source3/libsmb/namequery_dc.c               |   1 +
 source3/rpc_client/cli_pipe.c               |   1 +
 source3/rpc_server/spoolss/srv_spoolss_nt.c |   1 +
 source3/smbd/reply.c                        |   1 +
 source3/torture/torture.c                   |   1 +
 source3/utils/net_ads.c                     |   1 +
 source3/utils/net_lookup.c                  |   1 +
 source3/utils/net_rpc.c                     |   1 +
 source3/utils/net_time.c                    |   1 +
 source3/utils/net_util.c                    |   1 +
 source3/utils/nmblookup.c                   |   1 +
 source3/utils/smbfilter.c                   |   1 +
 source3/utils/smbtree.c                     |   1 +
 source3/winbindd/idmap_ad.c                 |   1 +
 source3/winbindd/winbindd_ads.c             |   1 +
 source3/winbindd/winbindd_cm.c              |   1 +
 source3/winbindd/winbindd_pam.c             |   1 +
 source3/winbindd/winbindd_wins_byip.c       |   1 +
 source3/winbindd/winbindd_wins_byname.c     |   1 +
 28 files changed, 141 insertions(+), 90 deletions(-)
 create mode 100644 source3/libsmb/namequery.h

diff --git a/source3/include/proto.h b/source3/include/proto.h
index 778107a4d84..3dab5d7ade6 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -713,96 +713,6 @@ bool namecache_status_fetch(const char *keyname,
 				const struct sockaddr_storage *keyip,
 				char *srvname_out);
 
-/* The following definitions come from libsmb/namequery.c  */
-
-bool saf_store( const char *domain, const char *servername );
-bool saf_join_store( const char *domain, const char *servername );
-bool saf_delete( const char *domain );
-char *saf_fetch(TALLOC_CTX *mem_ctx, const char *domain );
-struct tevent_req *node_status_query_send(TALLOC_CTX *mem_ctx,
-					  struct tevent_context *ev,
-					  struct nmb_name *name,
-					  const struct sockaddr_storage *addr);
-NTSTATUS node_status_query_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
-				struct node_status **pnode_status,
-				int *pnum_names,
-				struct node_status_extra *extra);
-NTSTATUS node_status_query(TALLOC_CTX *mem_ctx, struct nmb_name *name,
-			   const struct sockaddr_storage *addr,
-			   struct node_status **pnode_status,
-			   int *pnum_names,
-			   struct node_status_extra *extra);
-bool name_status_find(const char *q_name,
-			int q_type,
-			int type,
-			const struct sockaddr_storage *to_ss,
-			fstring name);
-int remove_duplicate_addrs2(struct ip_service *iplist, int count );
-struct tevent_req *name_query_send(TALLOC_CTX *mem_ctx,
-				   struct tevent_context *ev,
-				   const char *name, int name_type,
-				   bool bcast, bool recurse,
-				   const struct sockaddr_storage *addr);
-NTSTATUS name_query_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
-			 struct sockaddr_storage **addrs, int *num_addrs,
-			 uint8_t *flags);
-NTSTATUS name_query(const char *name, int name_type,
-		    bool bcast, bool recurse,
-		    const struct sockaddr_storage *to_ss,
-		    TALLOC_CTX *mem_ctx,
-		    struct sockaddr_storage **addrs,
-		    int *num_addrs, uint8_t *flags);
-struct tevent_req *name_resolve_bcast_send(TALLOC_CTX *mem_ctx,
-					   struct tevent_context *ev,
-					   const char *name,
-					   int name_type);
-NTSTATUS name_resolve_bcast_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
-				 struct sockaddr_storage **addrs,
-				 int *num_addrs);
-NTSTATUS name_resolve_bcast(const char *name,
-			int name_type,
-			TALLOC_CTX *mem_ctx,
-			struct sockaddr_storage **return_iplist,
-			int *return_count);
-struct tevent_req *resolve_wins_send(TALLOC_CTX *mem_ctx,
-				     struct tevent_context *ev,
-				     const char *name,
-				     int name_type);
-NTSTATUS resolve_wins_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
-			   struct sockaddr_storage **addrs,
-			   int *num_addrs, uint8_t *flags);
-NTSTATUS resolve_wins(const char *name,
-		int name_type,
-		TALLOC_CTX *mem_ctx,
-		struct sockaddr_storage **return_iplist,
-		int *return_count);
-NTSTATUS internal_resolve_name(const char *name,
-			        int name_type,
-				const char *sitename,
-				struct ip_service **return_iplist,
-				int *return_count,
-				const char **resolve_order);
-bool resolve_name(const char *name,
-		struct sockaddr_storage *return_ss,
-		int name_type,
-		bool prefer_ipv4);
-NTSTATUS resolve_name_list(TALLOC_CTX *ctx,
-		const char *name,
-		int name_type,
-		struct sockaddr_storage **return_ss_arr,
-		unsigned int *p_num_entries);
-bool find_master_ip(const char *group, struct sockaddr_storage *master_ss);
-bool get_pdc_ip(const char *domain, struct sockaddr_storage *pss);
-NTSTATUS get_sorted_dc_list( const char *domain,
-			const char *sitename,
-			struct ip_service **ip_list,
-			int *count,
-			bool ads_only );
-NTSTATUS get_kdc_list( const char *realm,
-			const char *sitename,
-			struct ip_service **ip_list,
-			int *count);
-
 /* The following definitions come from libsmb/namequery_dc.c  */
 
 bool get_dc_name(const char *domain,
diff --git a/source3/libads/kerberos.c b/source3/libads/kerberos.c
index 82f118a021e..e623f2456a8 100644
--- a/source3/libads/kerberos.c
+++ b/source3/libads/kerberos.c
@@ -22,6 +22,7 @@
 */
 
 #include "includes.h"
+#include "libsmb/namequery.h"
 #include "system/filesys.h"
 #include "smb_krb5.h"
 #include "../librpc/gen_ndr/ndr_misc.h"
diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c
index f9463043cc8..e8dcd1baa57 100644
--- a/source3/libads/ldap.c
+++ b/source3/libads/ldap.c
@@ -31,6 +31,7 @@
 #include "../libcli/security/security.h"
 #include "../librpc/gen_ndr/netlogon.h"
 #include "lib/param/loadparm.h"
+#include "libsmb/namequery.h"
 
 #ifdef HAVE_LDAP
 
diff --git a/source3/libnet/libnet_join.c b/source3/libnet/libnet_join.c
index bbe604b729e..5bf0b7fff2d 100644
--- a/source3/libnet/libnet_join.c
+++ b/source3/libnet/libnet_join.c
@@ -20,6 +20,7 @@
 
 #include "includes.h"
 #include "ads.h"
+#include "libsmb/namequery.h"
 #include "librpc/gen_ndr/ndr_libnet_join.h"
 #include "libnet/libnet_join.h"
 #include "libcli/auth/libcli_auth.h"
diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c
index 7689910fae9..837299d9220 100644
--- a/source3/libsmb/cliconnect.c
+++ b/source3/libsmb/cliconnect.c
@@ -22,6 +22,7 @@
 
 #include "includes.h"
 #include "libsmb/libsmb.h"
+#include "libsmb/namequery.h"
 #include "auth_info.h"
 #include "../libcli/auth/libcli_auth.h"
 #include "../libcli/auth/spnego.h"
diff --git a/source3/libsmb/dsgetdcname.c b/source3/libsmb/dsgetdcname.c
index a7fe5a1e748..98649006324 100644
--- a/source3/libsmb/dsgetdcname.c
+++ b/source3/libsmb/dsgetdcname.c
@@ -21,6 +21,7 @@
 */
 
 #include "includes.h"
+#include "libsmb/namequery.h"
 #include "libads/sitename_cache.h"
 #include "../librpc/gen_ndr/ndr_netlogon.h"
 #include "libads/cldap.h"
diff --git a/source3/libsmb/libsmb_dir.c b/source3/libsmb/libsmb_dir.c
index 72441c46736..8c3fed672f8 100644
--- a/source3/libsmb/libsmb_dir.c
+++ b/source3/libsmb/libsmb_dir.c
@@ -23,6 +23,7 @@
 */
 
 #include "includes.h"
+#include "libsmb/namequery.h"
 #include "libsmb/libsmb.h"
 #include "auth_info.h"
 #include "libsmbclient.h"
diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c
index b616a64b896..8c23f09f442 100644
--- a/source3/libsmb/namequery.c
+++ b/source3/libsmb/namequery.c
@@ -19,6 +19,7 @@
 */
 
 #include "includes.h"
+#include "libsmb/namequery.h"
 #include "../lib/util/tevent_ntstatus.h"
 #include "libads/sitename_cache.h"
 #include "../lib/addns/dnsquery.h"
diff --git a/source3/libsmb/namequery.h b/source3/libsmb/namequery.h
new file mode 100644
index 00000000000..d7bd4d338b4
--- /dev/null
+++ b/source3/libsmb/namequery.h
@@ -0,0 +1,115 @@
+/*
+ * 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_NAMEQUERY_H__
+#define __LIBSMB_NAMEQUERY_H__
+
+#include "includes.h"
+#include <tevent.h>
+
+/* The following definitions come from libsmb/namequery.c  */
+
+bool saf_store( const char *domain, const char *servername );
+bool saf_join_store( const char *domain, const char *servername );
+bool saf_delete( const char *domain );
+char *saf_fetch(TALLOC_CTX *mem_ctx, const char *domain );
+struct tevent_req *node_status_query_send(TALLOC_CTX *mem_ctx,
+					  struct tevent_context *ev,
+					  struct nmb_name *name,
+					  const struct sockaddr_storage *addr);
+NTSTATUS node_status_query_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
+				struct node_status **pnode_status,
+				int *pnum_names,
+				struct node_status_extra *extra);
+NTSTATUS node_status_query(TALLOC_CTX *mem_ctx, struct nmb_name *name,
+			   const struct sockaddr_storage *addr,
+			   struct node_status **pnode_status,
+			   int *pnum_names,
+			   struct node_status_extra *extra);
+bool name_status_find(const char *q_name,
+			int q_type,
+			int type,
+			const struct sockaddr_storage *to_ss,
+			fstring name);
+int remove_duplicate_addrs2(struct ip_service *iplist, int count );
+struct tevent_req *name_query_send(TALLOC_CTX *mem_ctx,
+				   struct tevent_context *ev,
+				   const char *name, int name_type,
+				   bool bcast, bool recurse,
+				   const struct sockaddr_storage *addr);
+NTSTATUS name_query_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
+			 struct sockaddr_storage **addrs, int *num_addrs,
+			 uint8_t *flags);
+NTSTATUS name_query(const char *name, int name_type,
+		    bool bcast, bool recurse,
+		    const struct sockaddr_storage *to_ss,
+		    TALLOC_CTX *mem_ctx,
+		    struct sockaddr_storage **addrs,
+		    int *num_addrs, uint8_t *flags);
+struct tevent_req *name_resolve_bcast_send(TALLOC_CTX *mem_ctx,
+					   struct tevent_context *ev,
+					   const char *name,
+					   int name_type);
+NTSTATUS name_resolve_bcast_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
+				 struct sockaddr_storage **addrs,
+				 int *num_addrs);
+NTSTATUS name_resolve_bcast(const char *name,
+			int name_type,
+			TALLOC_CTX *mem_ctx,
+			struct sockaddr_storage **return_iplist,
+			int *return_count);
+struct tevent_req *resolve_wins_send(TALLOC_CTX *mem_ctx,
+				     struct tevent_context *ev,
+				     const char *name,
+				     int name_type);
+NTSTATUS resolve_wins_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
+			   struct sockaddr_storage **addrs,
+			   int *num_addrs, uint8_t *flags);
+NTSTATUS resolve_wins(const char *name,
+		int name_type,
+		TALLOC_CTX *mem_ctx,
+		struct sockaddr_storage **return_iplist,
+		int *return_count);
+NTSTATUS internal_resolve_name(const char *name,
+			        int name_type,
+				const char *sitename,
+				struct ip_service **return_iplist,
+				int *return_count,
+				const char **resolve_order);
+bool resolve_name(const char *name,
+		struct sockaddr_storage *return_ss,
+		int name_type,
+		bool prefer_ipv4);
+NTSTATUS resolve_name_list(TALLOC_CTX *ctx,
+		const char *name,
+		int name_type,
+		struct sockaddr_storage **return_ss_arr,
+		unsigned int *p_num_entries);
+bool find_master_ip(const char *group, struct sockaddr_storage *master_ss);
+bool get_pdc_ip(const char *domain, struct sockaddr_storage *pss);
+NTSTATUS get_sorted_dc_list( const char *domain,
+			const char *sitename,
+			struct ip_service **ip_list,
+			int *count,
+			bool ads_only );
+NTSTATUS get_kdc_list( const char *realm,
+			const char *sitename,
+			struct ip_service **ip_list,
+			int *count);
+
+#endif
diff --git a/source3/libsmb/namequery_dc.c b/source3/libsmb/namequery_dc.c
index d08456590f6..4ee5b5278e4 100644
--- a/source3/libsmb/namequery_dc.c
+++ b/source3/libsmb/namequery_dc.c
@@ -23,6 +23,7 @@
 
 
 #include "includes.h"
+#include "libsmb/namequery.h"
 #include "libads/sitename_cache.h"
 #include "ads.h"
 #include "../librpc/gen_ndr/nbt.h"
diff --git a/source3/rpc_client/cli_pipe.c b/source3/rpc_client/cli_pipe.c
index d449a828b5a..81b6bfb75bf 100644
--- a/source3/rpc_client/cli_pipe.c
+++ b/source3/rpc_client/cli_pipe.c
@@ -20,6 +20,7 @@
  */
 
 #include "includes.h"
+#include "libsmb/namequery.h"
 #include "../lib/util/tevent_ntstatus.h"
 #include "librpc/gen_ndr/ndr_epmapper_c.h"
 #include "../librpc/gen_ndr/ndr_dssetup.h"
diff --git a/source3/rpc_server/spoolss/srv_spoolss_nt.c b/source3/rpc_server/spoolss/srv_spoolss_nt.c
index 2f42e6d4c39..296d8025429 100644
--- a/source3/rpc_server/spoolss/srv_spoolss_nt.c
+++ b/source3/rpc_server/spoolss/srv_spoolss_nt.c
@@ -28,6 +28,7 @@
    up, all the errors returned are DOS errors, not NT status codes. */
 
 #include "includes.h"
+#include "libsmb/namequery.h"
 #include "ntdomain.h"
 #include "nt_printing.h"
 #include "srv_spoolss_util.h"
diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index 881667a6b44..92a65f5b90b 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -25,6 +25,7 @@
 */
 
 #include "includes.h"
+#include "libsmb/namequery.h"
 #include "system/filesys.h"
 #include "printing.h"
 #include "smbd/smbd.h"
diff --git a/source3/torture/torture.c b/source3/torture/torture.c
index df6604de9fe..56cc6ff3628 100644
--- a/source3/torture/torture.c
+++ b/source3/torture/torture.c
@@ -20,6 +20,7 @@
 
 #include "includes.h"
 #include "system/shmem.h"
+#include "libsmb/namequery.h"
 #include "wbc_async.h"
 #include "torture/proto.h"
 #include "libcli/security/security.h"
diff --git a/source3/utils/net_ads.c b/source3/utils/net_ads.c
index c4c1a0d4051..ffa67d8f525 100644
--- a/source3/utils/net_ads.c
+++ b/source3/utils/net_ads.c
@@ -22,6 +22,7 @@
 
 #include "includes.h"
 #include "utils/net.h"
+#include "libsmb/namequery.h"
 #include "rpc_client/cli_pipe.h"
 #include "librpc/gen_ndr/ndr_krb5pac.h"
 #include "../librpc/gen_ndr/ndr_spoolss.h"
diff --git a/source3/utils/net_lookup.c b/source3/utils/net_lookup.c
index 597e098e2e1..4e7a74d1e00 100644
--- a/source3/utils/net_lookup.c
+++ b/source3/utils/net_lookup.c
@@ -18,6 +18,7 @@
 
 #include "includes.h"
 #include "utils/net.h"
+#include "libsmb/namequery.h"
 #include "libads/sitename_cache.h"
 #include "../lib/addns/dnsquery.h"
 #include "../librpc/gen_ndr/ndr_netlogon.h"
diff --git a/source3/utils/net_rpc.c b/source3/utils/net_rpc.c
index 8a989d790f2..52d313edfaa 100644
--- a/source3/utils/net_rpc.c
+++ b/source3/utils/net_rpc.c
@@ -22,6 +22,7 @@
 
 #include "includes.h"
 #include "utils/net.h"
+#include "libsmb/namequery.h"
 #include "rpc_client/cli_pipe.h"
 #include "../libcli/auth/libcli_auth.h"
 #include "../librpc/gen_ndr/ndr_samr_c.h"
diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c
index 595d903c0be..0091fc86333 100644
--- a/source3/utils/net_time.c
+++ b/source3/utils/net_time.c
@@ -19,6 +19,7 @@
 #include "includes.h"
 #include "utils/net.h"
 #include "libsmb/nmblib.h"
+#include "libsmb/namequery.h"
 #include "libsmb/libsmb.h"
 #include "../libcli/smb/smbXcli_base.h"
 
diff --git a/source3/utils/net_util.c b/source3/utils/net_util.c
index 86a46672f56..a84b4f5500e 100644
--- a/source3/utils/net_util.c
+++ b/source3/utils/net_util.c
@@ -21,6 +21,7 @@
 
 #include "includes.h"
 #include "utils/net.h"
+#include "libsmb/namequery.h"
 #include "rpc_client/cli_pipe.h"
 #include "../librpc/gen_ndr/ndr_lsa_c.h"
 #include "rpc_client/cli_lsarpc.h"
diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c
index dadd30fdb74..602f3cd4624 100644
--- a/source3/utils/nmblookup.c
+++ b/source3/utils/nmblookup.c
@@ -22,6 +22,7 @@
 #include "includes.h"
 #include "popt_common.h"
 #include "libsmb/nmblib.h"
+#include "libsmb/namequery.h"
 
 static bool give_flags = false;
 static bool use_bcast = true;
diff --git a/source3/utils/smbfilter.c b/source3/utils/smbfilter.c
index 85aca4f9334..35fb7521384 100644
--- a/source3/utils/smbfilter.c
+++ b/source3/utils/smbfilter.c
@@ -20,6 +20,7 @@
 #include "includes.h"
 #include "system/filesys.h"
 #include "system/select.h"
+#include "libsmb/namequery.h"
 #include "../lib/util/select.h"
 #include "libsmb/nmblib.h"
 #include "lib/util/sys_rw_data.h"
diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c
index fb0c130d350..3b539ef1045 100644
--- a/source3/utils/smbtree.c
+++ b/source3/utils/smbtree.c
@@ -24,6 +24,7 @@
 #include "rpc_client/cli_pipe.h"
 #include "../librpc/gen_ndr/ndr_srvsvc_c.h"
 #include "libsmb/libsmb.h"
+#include "libsmb/namequery.h"
 #include "libsmb/clirap.h"
 
 static int use_bcast;
diff --git a/source3/winbindd/idmap_ad.c b/source3/winbindd/idmap_ad.c
index 15304109a2d..8f1cb375dfb 100644
--- a/source3/winbindd/idmap_ad.c
+++ b/source3/winbindd/idmap_ad.c
@@ -19,6 +19,7 @@
 
 #include "includes.h"
 #include "winbindd.h"
+#include "libsmb/namequery.h"
 #include "idmap.h"
 #include "tldap_gensec_bind.h"
 #include "tldap_util.h"
diff --git a/source3/winbindd/winbindd_ads.c b/source3/winbindd/winbindd_ads.c
index 725fa4ff977..76d6a304366 100644
--- a/source3/winbindd/winbindd_ads.c
+++ b/source3/winbindd/winbindd_ads.c
@@ -24,6 +24,7 @@
 #include "includes.h"
 #include "winbindd.h"
 #include "winbindd_ads.h"
+#include "libsmb/namequery.h"
 #include "rpc_client/rpc_client.h"
 #include "../librpc/gen_ndr/ndr_netlogon_c.h"
 #include "../libds/common/flags.h"
diff --git a/source3/winbindd/winbindd_cm.c b/source3/winbindd/winbindd_cm.c
index bf5a2b4d7b1..30f65c66bc4 100644
--- a/source3/winbindd/winbindd_cm.c
+++ b/source3/winbindd/winbindd_cm.c
@@ -60,6 +60,7 @@
 
 #include "includes.h"
 #include "winbindd.h"
+#include "libsmb/namequery.h"
 #include "../libcli/auth/libcli_auth.h"
 #include "../librpc/gen_ndr/ndr_netlogon_c.h"
 #include "rpc_client/cli_pipe.h"
diff --git a/source3/winbindd/winbindd_pam.c b/source3/winbindd/winbindd_pam.c
index 8403d7d57b6..e273ab3b8be 100644
--- a/source3/winbindd/winbindd_pam.c
+++ b/source3/winbindd/winbindd_pam.c
@@ -24,6 +24,7 @@
 
 #include "includes.h"
 #include "winbindd.h"
+#include "libsmb/namequery.h"
 #include "../libcli/auth/libcli_auth.h"
 #include "../librpc/gen_ndr/ndr_samr_c.h"
 #include "rpc_client/cli_pipe.h"
diff --git a/source3/winbindd/winbindd_wins_byip.c b/source3/winbindd/winbindd_wins_byip.c
index c995dd1b0dc..4d3dddf0864 100644
--- a/source3/winbindd/winbindd_wins_byip.c
+++ b/source3/winbindd/winbindd_wins_byip.c
@@ -19,6 +19,7 @@
 
 #include "includes.h"
 #include "winbindd.h"
+#include "libsmb/namequery.h"
 #include "librpc/gen_ndr/ndr_winbind_c.h"
 #include "libsmb/nmblib.h"
 
diff --git a/source3/winbindd/winbindd_wins_byname.c b/source3/winbindd/winbindd_wins_byname.c
index db6a04d4ecb..8661401331a 100644
--- a/source3/winbindd/winbindd_wins_byname.c
+++ b/source3/winbindd/winbindd_wins_byname.c
@@ -19,6 +19,7 @@
 
 #include "includes.h"
 #include "winbindd.h"
+#include "libsmb/namequery.h"
 #include "librpc/gen_ndr/ndr_winbind_c.h"
 #include "libsmb/nmblib.h"
 #include "lib/util/string_wrappers.h"
-- 
2.11.0


From 196a8ef8c24d6b6d8dd7f6dfae10395ae0344628 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Fri, 5 Jan 2018 14:21:05 +0100
Subject: [PATCH 5/8] libsmb: Give dsgetdcname.c its own header

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/include/proto.h                     | 12 ----------
 source3/lib/netapi/getdc.c                  |  1 +
 source3/lib/netapi/joindomain.c             |  1 +
 source3/lib/netapi/serverinfo.c             |  1 +
 source3/libnet/libnet_join.c                |  1 +
 source3/libsmb/dsgetdcname.c                |  1 +
 source3/libsmb/dsgetdcname.h                | 37 +++++++++++++++++++++++++++++
 source3/rpc_server/netlogon/srv_netlog_nt.c |  1 +
 source3/utils/net_lookup.c                  |  1 +
 source3/utils/net_rpc.c                     |  1 +
 source3/winbindd/winbindd_dual_srv.c        |  1 +
 11 files changed, 46 insertions(+), 12 deletions(-)
 create mode 100644 source3/libsmb/dsgetdcname.h

diff --git a/source3/include/proto.h b/source3/include/proto.h
index 3dab5d7ade6..4c51e4d3059 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -676,18 +676,6 @@ NTSTATUS check_negative_conn_cache( const char *domain, const char *server);
 void add_failed_connection_entry(const char *domain, const char *server, NTSTATUS result) ;
 void flush_negative_conn_cache_for_domain(const char *domain);
 
-/* The following definitions come from libsmb/dsgetdcname.c  */
-
-struct netr_DsRGetDCNameInfo;
-
-NTSTATUS dsgetdcname(TALLOC_CTX *mem_ctx,
-		     struct messaging_context *msg_ctx,
-		     const char *domain_name,
-		     const struct GUID *domain_guid,
-		     const char *site_name,
-		     uint32_t flags,
-		     struct netr_DsRGetDCNameInfo **info);
-
 /* The following definitions come from libsmb/errormap.c  */
 
 NTSTATUS dos_to_ntstatus(uint8_t eclass, uint32_t ecode);
diff --git a/source3/lib/netapi/getdc.c b/source3/lib/netapi/getdc.c
index 2d47ee45840..d4633752c78 100644
--- a/source3/lib/netapi/getdc.c
+++ b/source3/lib/netapi/getdc.c
@@ -24,6 +24,7 @@
 #include "lib/netapi/netapi.h"
 #include "lib/netapi/netapi_private.h"
 #include "lib/netapi/libnetapi.h"
+#include "libsmb/dsgetdcname.h"
 
 /********************************************************************
 ********************************************************************/
diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c
index 7d27bd9d0fe..ff2154ba803 100644
--- a/source3/lib/netapi/joindomain.c
+++ b/source3/lib/netapi/joindomain.c
@@ -29,6 +29,7 @@
 #include "../librpc/gen_ndr/ndr_wkssvc_c.h"
 #include "rpc_client/cli_pipe.h"
 #include "secrets.h"
+#include "libsmb/dsgetdcname.h"
 
 /****************************************************************
 ****************************************************************/
diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c
index 2fd7668c682..7d9cc481c8c 100644
--- a/source3/lib/netapi/serverinfo.c
+++ b/source3/lib/netapi/serverinfo.c
@@ -26,6 +26,7 @@
 #include "../librpc/gen_ndr/ndr_srvsvc_c.h"
 #include "lib/smbconf/smbconf.h"
 #include "lib/smbconf/smbconf_reg.h"
+#include "libsmb/dsgetdcname.h"
 
 /****************************************************************
 ****************************************************************/
diff --git a/source3/libnet/libnet_join.c b/source3/libnet/libnet_join.c
index 5bf0b7fff2d..a9405e8d288 100644
--- a/source3/libnet/libnet_join.c
+++ b/source3/libnet/libnet_join.c
@@ -44,6 +44,7 @@
 #include "libcli/auth/netlogon_creds_cli.h"
 #include "auth/credentials/credentials.h"
 #include "krb5_env.h"
+#include "libsmb/dsgetdcname.h"
 
 /****************************************************************
 ****************************************************************/
diff --git a/source3/libsmb/dsgetdcname.c b/source3/libsmb/dsgetdcname.c
index 98649006324..3afe6a85b91 100644
--- a/source3/libsmb/dsgetdcname.c
+++ b/source3/libsmb/dsgetdcname.c
@@ -21,6 +21,7 @@
 */
 
 #include "includes.h"
+#include "libsmb/dsgetdcname.h"
 #include "libsmb/namequery.h"
 #include "libads/sitename_cache.h"
 #include "../librpc/gen_ndr/ndr_netlogon.h"
diff --git a/source3/libsmb/dsgetdcname.h b/source3/libsmb/dsgetdcname.h
new file mode 100644
index 00000000000..0aa06c32b83
--- /dev/null
+++ b/source3/libsmb/dsgetdcname.h
@@ -0,0 +1,37 @@
+/*
+ * 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_DSGETDCNAME_H__
+#define __LIBSMB_DSGETDCNAME_H__
+
+#include "replace.h"
+#include <talloc.h>
+#include "librpc/gen_ndr/misc.h"
+
+struct netr_DsRGetDCNameInfo;
+struct messaging_context;
+
+NTSTATUS dsgetdcname(TALLOC_CTX *mem_ctx,
+		     struct messaging_context *msg_ctx,
+		     const char *domain_name,
+		     const struct GUID *domain_guid,
+		     const char *site_name,
+		     uint32_t flags,
+		     struct netr_DsRGetDCNameInfo **info);
+
+#endif
diff --git a/source3/rpc_server/netlogon/srv_netlog_nt.c b/source3/rpc_server/netlogon/srv_netlog_nt.c
index 83e68417c76..9b9947455ed 100644
--- a/source3/rpc_server/netlogon/srv_netlog_nt.c
+++ b/source3/rpc_server/netlogon/srv_netlog_nt.c
@@ -47,6 +47,7 @@
 #include "messages.h"
 #include "../lib/tsocket/tsocket.h"
 #include "lib/param/param.h"
+#include "libsmb/dsgetdcname.h"
 
 extern userdom_struct current_user_info;
 
diff --git a/source3/utils/net_lookup.c b/source3/utils/net_lookup.c
index 4e7a74d1e00..05a3dbc6e2b 100644
--- a/source3/utils/net_lookup.c
+++ b/source3/utils/net_lookup.c
@@ -25,6 +25,7 @@
 #include "smb_krb5.h"
 #include "../libcli/security/security.h"
 #include "passdb/lookup_sid.h"
+#include "libsmb/dsgetdcname.h"
 
 int net_lookup_usage(struct net_context *c, int argc, const char **argv)
 {
diff --git a/source3/utils/net_rpc.c b/source3/utils/net_rpc.c
index 52d313edfaa..b99a036fca1 100644
--- a/source3/utils/net_rpc.c
+++ b/source3/utils/net_rpc.c
@@ -47,6 +47,7 @@
 #include "nsswitch/libwbclient/wbclient.h"
 #include "passdb.h"
 #include "../libcli/smb/smbXcli_base.h"
+#include "libsmb/dsgetdcname.h"
 
 static int net_mode_share;
 static NTSTATUS sync_files(struct copy_clistate *cp_clistate, const char *mask);
diff --git a/source3/winbindd/winbindd_dual_srv.c b/source3/winbindd/winbindd_dual_srv.c
index 4cea73feaf9..8cb05f06db6 100644
--- a/source3/winbindd/winbindd_dual_srv.c
+++ b/source3/winbindd/winbindd_dual_srv.c
@@ -35,6 +35,7 @@
 #include "../source4/dsdb/samdb/samdb.h"
 #include "rpc_client/cli_netlogon.h"
 #include "rpc_client/util_netlogon.h"
+#include "libsmb/dsgetdcname.h"
 
 void _wbint_Ping(struct pipes_struct *p, struct wbint_Ping *r)
 {
-- 
2.11.0


From 38a4621b466a46ee0c20a68264313bf99fbceed2 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 10 Mar 2018 18:01:08 +0100
Subject: [PATCH 6/8] libsmb: Introduce a helper variable

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/libsmb/clidgram.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/source3/libsmb/clidgram.c b/source3/libsmb/clidgram.c
index 4ae57a30d33..cb319b1a7e8 100644
--- a/source3/libsmb/clidgram.c
+++ b/source3/libsmb/clidgram.c
@@ -308,6 +308,7 @@ struct tevent_req *nbt_getdc_send(TALLOC_CTX *mem_ctx,
 	struct tevent_req *req, *subreq;
 	struct nbt_getdc_state *state;
 	uint16_t dgm_id;
+	bool ok;
 
 	req = tevent_req_create(mem_ctx, &state, struct nbt_getdc_state);
 	if (req == NULL) {
@@ -338,9 +339,10 @@ struct tevent_req *nbt_getdc_send(TALLOC_CTX *mem_ctx,
 
 	generate_random_buffer((uint8_t *)(void *)&dgm_id, sizeof(dgm_id));
 
-	if (!prep_getdc_request(dc_addr, domain_name, sid, nt_version,
+	ok = prep_getdc_request(dc_addr, domain_name, sid, nt_version,
 				state->my_mailslot, dgm_id & 0x7fff,
-				&state->p)) {
+				&state->p);
+	if (!ok) {
 		DEBUG(3, ("prep_getdc_request failed\n"));
 		tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
 		return tevent_req_post(req, ev);
-- 
2.11.0


From 862584ac8b39a6917a03542181d118e2f8fe6a58 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 10 Mar 2018 18:06:03 +0100
Subject: [PATCH 7/8] libsmb: Pass "account_name/flags" through
 prep_getdc_request

Don't hardcode values that we might want to change later

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/libsmb/clidgram.c | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/source3/libsmb/clidgram.c b/source3/libsmb/clidgram.c
index cb319b1a7e8..7b10f2601c6 100644
--- a/source3/libsmb/clidgram.c
+++ b/source3/libsmb/clidgram.c
@@ -120,6 +120,8 @@ static char *mailslot_name(TALLOC_CTX *mem_ctx, struct in_addr dc_ip)
 }
 
 static bool prep_getdc_request(const struct sockaddr_storage *dc_ss,
+			       const char *account_name,
+			       uint32_t account_flags,
 			       const char *domain_name,
 			       const struct dom_sid *sid,
 			       uint32_t nt_version,
@@ -128,7 +130,6 @@ static bool prep_getdc_request(const struct sockaddr_storage *dc_ss,
 			       struct packet_struct *p)
 {
 	TALLOC_CTX *frame = talloc_stackframe();
-	const char *my_acct_name;
 	struct nbt_netlogon_packet packet;
 	struct NETLOGON_SAM_LOGON_REQUEST *s;
 	enum ndr_err_code ndr_err;
@@ -143,19 +144,14 @@ static bool prep_getdc_request(const struct sockaddr_storage *dc_ss,
 		my_sid = *sid;
 	}
 
-	my_acct_name = talloc_asprintf(talloc_tos(), "%s$", lp_netbios_name());
-	if (my_acct_name == NULL) {
-		goto fail;
-	}
-
 	packet.command	= LOGON_SAM_LOGON_REQUEST;
 	s		= &packet.req.logon;
 
 	s->request_count	= 0;
 	s->computer_name	= lp_netbios_name();
-	s->user_name		= my_acct_name;
+	s->user_name		= account_name;
 	s->mailslot_name	= my_mailslot;
-	s->acct_control		= ACB_WSTRUST;
+	s->acct_control		= account_flags;
 	s->sid			= my_sid;
 	s->nt_version		= nt_version;
 	s->lmnt_token		= 0xffff;
@@ -339,9 +335,21 @@ struct tevent_req *nbt_getdc_send(TALLOC_CTX *mem_ctx,
 
 	generate_random_buffer((uint8_t *)(void *)&dgm_id, sizeof(dgm_id));
 
-	ok = prep_getdc_request(dc_addr, domain_name, sid, nt_version,
-				state->my_mailslot, dgm_id & 0x7fff,
-				&state->p);
+	{
+		size_t len = strlen(lp_netbios_name());
+		char my_acct_name[len+2];
+
+		snprintf(my_acct_name,
+			 sizeof(my_acct_name),
+			 "%s$",
+			 lp_netbios_name());
+
+		ok = prep_getdc_request(dc_addr, my_acct_name, ACB_WSTRUST,
+					domain_name, sid, nt_version,
+					state->my_mailslot, dgm_id & 0x7fff,
+					&state->p);
+	}
+
 	if (!ok) {
 		DEBUG(3, ("prep_getdc_request failed\n"));
 		tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
-- 
2.11.0


From e1a0256fed4ad33845037ef9f6ffbed301dcce1e Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sat, 10 Mar 2018 18:06:03 +0100
Subject: [PATCH 8/8] libsmb: Pass "account_name/flags" through nb_getdc

Don't hardcode values that we might want to change later

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/libsmb/clidgram.c      | 24 +++++++++---------------
 source3/libsmb/clidgram.h      |  4 ++++
 source3/libsmb/dsgetdcname.c   |  9 ++++++++-
 source3/winbindd/winbindd_cm.c | 18 +++++++++++++++---
 4 files changed, 36 insertions(+), 19 deletions(-)

diff --git a/source3/libsmb/clidgram.c b/source3/libsmb/clidgram.c
index 7b10f2601c6..bed507626c1 100644
--- a/source3/libsmb/clidgram.c
+++ b/source3/libsmb/clidgram.c
@@ -299,6 +299,8 @@ struct tevent_req *nbt_getdc_send(TALLOC_CTX *mem_ctx,
 				  const struct sockaddr_storage *dc_addr,
 				  const char *domain_name,
 				  const struct dom_sid *sid,
+				  const char *account_name,
+				  uint32_t account_flags,
 				  uint32_t nt_version)
 {
 	struct tevent_req *req, *subreq;
@@ -335,20 +337,10 @@ struct tevent_req *nbt_getdc_send(TALLOC_CTX *mem_ctx,
 
 	generate_random_buffer((uint8_t *)(void *)&dgm_id, sizeof(dgm_id));
 
-	{
-		size_t len = strlen(lp_netbios_name());
-		char my_acct_name[len+2];
-
-		snprintf(my_acct_name,
-			 sizeof(my_acct_name),
-			 "%s$",
-			 lp_netbios_name());
-
-		ok = prep_getdc_request(dc_addr, my_acct_name, ACB_WSTRUST,
-					domain_name, sid, nt_version,
-					state->my_mailslot, dgm_id & 0x7fff,
-					&state->p);
-	}
+	ok = prep_getdc_request(dc_addr, account_name, account_flags,
+				domain_name, sid, nt_version,
+				state->my_mailslot, dgm_id & 0x7fff,
+				&state->p);
 
 	if (!ok) {
 		DEBUG(3, ("prep_getdc_request failed\n"));
@@ -452,6 +444,8 @@ NTSTATUS nbt_getdc(struct messaging_context *msg_ctx,
 		   const struct sockaddr_storage *dc_addr,
 		   const char *domain_name,
 		   const struct dom_sid *sid,
+		   const char *account_name,
+		   uint32_t account_flags,
 		   uint32_t nt_version,
 		   TALLOC_CTX *mem_ctx,
 		   uint32_t *pnt_version,
@@ -468,7 +462,7 @@ NTSTATUS nbt_getdc(struct messaging_context *msg_ctx,
 		goto fail;
 	}
 	req = nbt_getdc_send(ev, ev, msg_ctx, dc_addr, domain_name,
-			     sid, nt_version);
+			     sid, account_name, account_flags, nt_version);
 	if (req == NULL) {
 		goto fail;
 	}
diff --git a/source3/libsmb/clidgram.h b/source3/libsmb/clidgram.h
index 6cd6222df68..46e11f42676 100644
--- a/source3/libsmb/clidgram.h
+++ b/source3/libsmb/clidgram.h
@@ -32,6 +32,8 @@ struct tevent_req *nbt_getdc_send(TALLOC_CTX *mem_ctx,
 				  const struct sockaddr_storage *dc_addr,
 				  const char *domain_name,
 				  const struct dom_sid *sid,
+				  const char *account_name,
+				  uint32_t account_flags,
 				  uint32_t nt_version);
 NTSTATUS nbt_getdc_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
 			uint32_t *nt_version, const char **dc_name,
@@ -41,6 +43,8 @@ NTSTATUS nbt_getdc(struct messaging_context *msg_ctx,
 		   const struct sockaddr_storage *dc_addr,
 		   const char *domain_name,
 		   const struct dom_sid *sid,
+		   const char *account_name,
+		   uint32_t account_flags,
 		   uint32_t nt_version,
 		   TALLOC_CTX *mem_ctx,
 		   uint32_t *pnt_version,
diff --git a/source3/libsmb/dsgetdcname.c b/source3/libsmb/dsgetdcname.c
index 3afe6a85b91..bf96a243379 100644
--- a/source3/libsmb/dsgetdcname.c
+++ b/source3/libsmb/dsgetdcname.c
@@ -911,6 +911,8 @@ static NTSTATUS process_dc_netbios(TALLOC_CTX *mem_ctx,
 	uint32_t nt_version = NETLOGON_NT_VERSION_1 |
 			      NETLOGON_NT_VERSION_5 |
 			      NETLOGON_NT_VERSION_5EX_WITH_IP;
+	size_t len = strlen(lp_netbios_name());
+	char my_acct_name[len+2];
 
 	if (msg_ctx == NULL) {
 		return NT_STATUS_INVALID_PARAMETER;
@@ -922,6 +924,11 @@ static NTSTATUS process_dc_netbios(TALLOC_CTX *mem_ctx,
 
 	nt_version |= map_ds_flags_to_nt_version(flags);
 
+	snprintf(my_acct_name,
+		 sizeof(my_acct_name),
+		 "%s$",
+		 lp_netbios_name());
+
 	DEBUG(10,("process_dc_netbios\n"));
 
 	for (i=0; i<num_dcs; i++) {
@@ -937,7 +944,7 @@ static NTSTATUS process_dc_netbios(TALLOC_CTX *mem_ctx,
 		}
 
 		status = nbt_getdc(msg_ctx, 10, &dclist[i].ss, domain_name,
-				   NULL, nt_version,
+				   NULL, my_acct_name, ACB_WSTRUST, nt_version,
 				   mem_ctx, &nt_version, &dc_name, &r);
 		if (NT_STATUS_IS_OK(status)) {
 			store_cache = true;
diff --git a/source3/winbindd/winbindd_cm.c b/source3/winbindd/winbindd_cm.c
index 30f65c66bc4..9c2773d5d67 100644
--- a/source3/winbindd/winbindd_cm.c
+++ b/source3/winbindd/winbindd_cm.c
@@ -1466,9 +1466,21 @@ static bool dcip_check_name(TALLOC_CTX *mem_ctx,
 	}
 #endif
 
-	status = nbt_getdc(server_messaging_context(), 10, pss, domain->name,
-			   &domain->sid, nt_version, mem_ctx, &nt_version,
-			   &dc_name, NULL);
+	{
+		size_t len = strlen(lp_netbios_name());
+		char my_acct_name[len+2];
+
+		snprintf(my_acct_name,
+			 sizeof(my_acct_name),
+			 "%s$",
+			 lp_netbios_name());
+
+		status = nbt_getdc(server_messaging_context(), 10, pss,
+				   domain->name, &domain->sid,
+				   my_acct_name, ACB_WSTRUST,
+				   nt_version, mem_ctx, &nt_version,
+				   &dc_name, NULL);
+	}
 	if (NT_STATUS_IS_OK(status)) {
 		*name = talloc_strdup(mem_ctx, dc_name);
 		if (*name == NULL) {
-- 
2.11.0



More information about the samba-technical mailing list