[PATCH] namequery: suppress bogus warning "resolve_name: unknown name switch type"

Volker Lendecke Volker.Lendecke at SerNet.DE
Wed May 13 03:44:32 MDT 2015


On Wed, May 13, 2015 at 12:38:29PM +0300, Uri Simchoni wrote:
> I think your approach is better. Do note that removal of the nbt resolvers
> must occur after allocating the stack frame.

New patch attachedd

> What do you think of the root cause? Would you agree that the fallback in
> ads_find_dc() needs fixing too?

Probably yes, I haven't looked that far yet. I just
concentrated on the review of the patch you sent.

But I agree that our name lookup routines could benefit from
some care.

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 b6c3f38a803164aeb9c975483423eb5eafa1ac43 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 13 May 2015 08:53:43 +0200
Subject: [PATCH] namequery: namequery: suppress bogus warning "resolve_name:
 unknown name switch type"

Based on a patch by Uri Simchoni <urisimchoni at gmail.com>

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/libsmb/namequery.c | 61 +++++++++++++++++++++++++++++++++++-----------
 1 file changed, 47 insertions(+), 14 deletions(-)

diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c
index 977c4ce..68cac3f 100644
--- a/source3/libsmb/namequery.c
+++ b/source3/libsmb/namequery.c
@@ -2544,6 +2544,38 @@ static NTSTATUS resolve_ads(const char *name,
 	return NT_STATUS_OK;
 }
 
+static const char **filter_out_nbt_lookup(TALLOC_CTX *mem_ctx,
+					  const char **resolve_order)
+{
+	size_t i, len, result_idx;
+	const char **result;
+
+	len = 0;
+	while (resolve_order[len] != NULL) {
+		len += 1;
+	}
+
+	result = talloc_array(mem_ctx, const char *, len+1);
+	if (result == NULL) {
+		return NULL;
+	}
+
+	result_idx = 0;
+
+	for (i=0; i<len; i++) {
+		const char *tok = resolve_order[i];
+
+		if (strequal(tok, "lmhosts") || strequal(tok, "wins") ||
+		    strequal(tok, "bcast")) {
+			continue;
+		}
+		result[result_idx++] = tok;
+	}
+	result[result_idx] = NULL;
+
+	return result;
+}
+
 /*******************************************************************
  Internal interface to resolve a name into an IP address.
  Use this function if the string is either an IP address, DNS
@@ -2566,8 +2598,6 @@ NTSTATUS internal_resolve_name(const char *name,
 	NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
 	int i;
 	TALLOC_CTX *frame = NULL;
-	bool do_nbt_lookup = true;
-	size_t nbt_len;
 
 	*return_iplist = NULL;
 	*return_count = 0;
@@ -2627,18 +2657,21 @@ NTSTATUS internal_resolve_name(const char *name,
 		resolve_order = host_order;
 	}
 
-	/* iterate through the name resolution backends */
-	nbt_len = strlen(name);
-	if (nbt_len > MAX_NETBIOSNAME_LEN - 1) {
-		do_nbt_lookup = false;
-	} else {
-		const char *p = strchr(name, '.');
-		if (p != NULL) {
-			do_nbt_lookup = false;
+	frame = talloc_stackframe();
+
+	if ((strlen(name) > MAX_NETBIOSNAME_LEN - 1) ||
+	    (strchr(name, '.') != NULL)) {
+		/*
+		 * Don't do NBT lookup, the name would not fit anyway
+		 */
+		resolve_order = filter_out_nbt_lookup(frame, resolve_order);
+		if (resolve_order == NULL) {
+			return NT_STATUS_NO_MEMORY;
 		}
 	}
 
-	frame = talloc_stackframe();
+	/* iterate through the name resolution backends */
+
 	for (i=0; resolve_order[i]; i++) {
 		tok = resolve_order[i];
 
@@ -2667,13 +2700,13 @@ NTSTATUS internal_resolve_name(const char *name,
 			if (NT_STATUS_IS_OK(status)) {
 				goto done;
 			}
-		} else if (do_nbt_lookup && strequal(tok, "lmhosts")) {
+		} else if (strequal(tok, "lmhosts")) {
 			status = resolve_lmhosts(name, name_type,
 						 return_iplist, return_count);
 			if (NT_STATUS_IS_OK(status)) {
 				goto done;
 			}
-		} else if (do_nbt_lookup && strequal(tok, "wins")) {
+		} else if (strequal(tok, "wins")) {
 			/* don't resolve 1D via WINS */
 			struct sockaddr_storage *ss_list;
 			if (name_type != 0x1D) {
@@ -2690,7 +2723,7 @@ NTSTATUS internal_resolve_name(const char *name,
 					goto done;
 				}
 			}
-		} else if (do_nbt_lookup && strequal(tok, "bcast")) {
+		} else if (strequal(tok, "bcast")) {
 			struct sockaddr_storage *ss_list;
 			status = name_resolve_bcast(
 				name, name_type, talloc_tos(),
-- 
1.9.1



More information about the samba-technical mailing list