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

Volker Lendecke Volker.Lendecke at SerNet.DE
Wed May 13 00:58:28 MDT 2015


Hi!

On Wed, May 13, 2015 at 06:55:58AM +0300, Uri Simchoni wrote:
> This patch fixes a warning that gets issued if NBT name resolving
> methods are attempted on a name that cannot be an NBT name (e.g.
> longer than 15 characters).

This patch is entirely correct. Reviewed-by: Me.

Attached find an alternative approach: Instead of
introducing yet another boolean flag filter_out_nbt_lookup
makes us skip the corresponding lookup flavors right away.
It also removes the warning.

A few more lines than your patch, but from my point of view
less complexity.

What do you think?

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 94476d37ea2f9376f05a40a195965d710feb4df9 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 | 58 +++++++++++++++++++++++++++++++++++-----------
 1 file changed, 45 insertions(+), 13 deletions(-)

diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c
index 977c4ce..7657721 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,17 +2657,19 @@ 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;
+	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;
 		}
 	}
 
+	/* iterate through the name resolution backends */
+
 	frame = talloc_stackframe();
 	for (i=0; resolve_order[i]; i++) {
 		tok = resolve_order[i];
@@ -2667,13 +2699,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 +2722,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