1feee8
commit 7267341ec1b5c591c2e7946d0604d3cf1423db7d
1feee8
Author: Florian Weimer <fweimer@redhat.com>
1feee8
Date:   Tue Aug 30 10:02:49 2022 +0200
1feee8
1feee8
    nss_dns: Remove remnants of IPv6 address mapping
1feee8
    
1feee8
    res_use_inet6 always returns false since commit 3f8b44be0a658266adff5
1feee8
    ("resolv: Remove support for RES_USE_INET6 and the inet6 option").
1feee8
    
1feee8
    Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
1feee8
    (cherry picked from commit a7fc30b522a0cd7c8c5e7e285b9531b704e02f04)
1feee8
1feee8
diff --git a/resolv/README b/resolv/README
1feee8
index 514e9bb617e710f1..2146bc3b27a6dc56 100644
1feee8
--- a/resolv/README
1feee8
+++ b/resolv/README
1feee8
@@ -146,6 +146,3 @@ res_libc.c is home-brewn, although parts of it are taken from res_data.c.
1feee8
 
1feee8
 res_hconf.c and res_hconf.h were contributed by David Mosberger, and
1feee8
 do not come from BIND.
1feee8
-
1feee8
-The files gethnamaddr.c, mapv4v6addr.h and mapv4v6hostent.h are
1feee8
-leftovers from BIND 4.9.7.
1feee8
diff --git a/resolv/mapv4v6addr.h b/resolv/mapv4v6addr.h
1feee8
deleted file mode 100644
1feee8
index 7f85f7d5e393ec5f..0000000000000000
1feee8
--- a/resolv/mapv4v6addr.h
1feee8
+++ /dev/null
1feee8
@@ -1,69 +0,0 @@
1feee8
-/*
1feee8
- * ++Copyright++ 1985, 1988, 1993
1feee8
- * -
1feee8
- * Copyright (c) 1985, 1988, 1993
1feee8
- *    The Regents of the University of California.  All rights reserved.
1feee8
- *
1feee8
- * Redistribution and use in source and binary forms, with or without
1feee8
- * modification, are permitted provided that the following conditions
1feee8
- * are met:
1feee8
- * 1. Redistributions of source code must retain the above copyright
1feee8
- *    notice, this list of conditions and the following disclaimer.
1feee8
- * 2. Redistributions in binary form must reproduce the above copyright
1feee8
- *    notice, this list of conditions and the following disclaimer in the
1feee8
- *    documentation and/or other materials provided with the distribution.
1feee8
- * 4. Neither the name of the University nor the names of its contributors
1feee8
- *    may be used to endorse or promote products derived from this software
1feee8
- *    without specific prior written permission.
1feee8
- *
1feee8
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1feee8
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1feee8
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1feee8
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1feee8
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1feee8
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1feee8
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1feee8
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1feee8
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1feee8
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1feee8
- * SUCH DAMAGE.
1feee8
- * -
1feee8
- * Portions Copyright (c) 1993 by Digital Equipment Corporation.
1feee8
- *
1feee8
- * Permission to use, copy, modify, and distribute this software for any
1feee8
- * purpose with or without fee is hereby granted, provided that the above
1feee8
- * copyright notice and this permission notice appear in all copies, and that
1feee8
- * the name of Digital Equipment Corporation not be used in advertising or
1feee8
- * publicity pertaining to distribution of the document or software without
1feee8
- * specific, written prior permission.
1feee8
- *
1feee8
- * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
1feee8
- * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
1feee8
- * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
1feee8
- * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
1feee8
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
1feee8
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
1feee8
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
1feee8
- * SOFTWARE.
1feee8
- * -
1feee8
- * --Copyright--
1feee8
- */
1feee8
-
1feee8
-#include <string.h>
1feee8
-#include <arpa/nameser.h>
1feee8
-
1feee8
-static void
1feee8
-map_v4v6_address (const char *src, char *dst)
1feee8
-{
1feee8
-  u_char *p = (u_char *) dst;
1feee8
-  int i;
1feee8
-
1feee8
-  /* Move the IPv4 part to the right position.  */
1feee8
-  memcpy (dst + 12, src, INADDRSZ);
1feee8
-
1feee8
-  /* Mark this ipv6 addr as a mapped ipv4. */
1feee8
-  for (i = 0; i < 10; i++)
1feee8
-    *p++ = 0x00;
1feee8
-  *p++ = 0xff;
1feee8
-  *p = 0xff;
1feee8
-}
1feee8
diff --git a/resolv/mapv4v6hostent.h b/resolv/mapv4v6hostent.h
1feee8
deleted file mode 100644
1feee8
index c11038adf33f154d..0000000000000000
1feee8
--- a/resolv/mapv4v6hostent.h
1feee8
+++ /dev/null
1feee8
@@ -1,84 +0,0 @@
1feee8
-/*
1feee8
- * ++Copyright++ 1985, 1988, 1993
1feee8
- * -
1feee8
- * Copyright (c) 1985, 1988, 1993
1feee8
- *    The Regents of the University of California.  All rights reserved.
1feee8
- *
1feee8
- * Redistribution and use in source and binary forms, with or without
1feee8
- * modification, are permitted provided that the following conditions
1feee8
- * are met:
1feee8
- * 1. Redistributions of source code must retain the above copyright
1feee8
- *    notice, this list of conditions and the following disclaimer.
1feee8
- * 2. Redistributions in binary form must reproduce the above copyright
1feee8
- *    notice, this list of conditions and the following disclaimer in the
1feee8
- *    documentation and/or other materials provided with the distribution.
1feee8
- * 4. Neither the name of the University nor the names of its contributors
1feee8
- *    may be used to endorse or promote products derived from this software
1feee8
- *    without specific prior written permission.
1feee8
- *
1feee8
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1feee8
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1feee8
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1feee8
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1feee8
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1feee8
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1feee8
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1feee8
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1feee8
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1feee8
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1feee8
- * SUCH DAMAGE.
1feee8
- * -
1feee8
- * Portions Copyright (c) 1993 by Digital Equipment Corporation.
1feee8
- *
1feee8
- * Permission to use, copy, modify, and distribute this software for any
1feee8
- * purpose with or without fee is hereby granted, provided that the above
1feee8
- * copyright notice and this permission notice appear in all copies, and that
1feee8
- * the name of Digital Equipment Corporation not be used in advertising or
1feee8
- * publicity pertaining to distribution of the document or software without
1feee8
- * specific, written prior permission.
1feee8
- *
1feee8
- * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
1feee8
- * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
1feee8
- * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
1feee8
- * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
1feee8
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
1feee8
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
1feee8
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
1feee8
- * SOFTWARE.
1feee8
- * -
1feee8
- * --Copyright--
1feee8
- */
1feee8
-
1feee8
-#include <arpa/nameser.h>
1feee8
-#include <sys/socket.h>
1feee8
-
1feee8
-typedef union {
1feee8
-    int32_t al;
1feee8
-    char ac;
1feee8
-} align;
1feee8
-
1feee8
-static int
1feee8
-map_v4v6_hostent (struct hostent *hp, char **bpp, int *lenp)
1feee8
-{
1feee8
-  char **ap;
1feee8
-
1feee8
-  if (hp->h_addrtype != AF_INET || hp->h_length != INADDRSZ)
1feee8
-    return 0;
1feee8
-  hp->h_addrtype = AF_INET6;
1feee8
-  hp->h_length = IN6ADDRSZ;
1feee8
-  for (ap = hp->h_addr_list; *ap; ap++)
1feee8
-    {
1feee8
-      int i = sizeof (align) - ((u_long) *bpp % sizeof (align));
1feee8
-
1feee8
-      if (*lenp < (i + IN6ADDRSZ))
1feee8
-	/* Out of memory.  */
1feee8
-	return 1;
1feee8
-      *bpp += i;
1feee8
-      *lenp -= i;
1feee8
-      map_v4v6_address (*ap, *bpp);
1feee8
-      *ap = *bpp;
1feee8
-      *bpp += IN6ADDRSZ;
1feee8
-      *lenp -= IN6ADDRSZ;
1feee8
-    }
1feee8
-  return 0;
1feee8
-}
1feee8
diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c
1feee8
index 2cd7170f20b60588..f8dc5a0a7d1eb156 100644
1feee8
--- a/resolv/nss_dns/dns-host.c
1feee8
+++ b/resolv/nss_dns/dns-host.c
1feee8
@@ -88,10 +88,6 @@
1feee8
 #include <resolv/resolv-internal.h>
1feee8
 #include <resolv/resolv_context.h>
1feee8
 
1feee8
-/* Get implementations of some internal functions.  */
1feee8
-#include <resolv/mapv4v6addr.h>
1feee8
-#include <resolv/mapv4v6hostent.h>
1feee8
-
1feee8
 #define RESOLVSORT
1feee8
 
1feee8
 #if PACKETSZ > 65536
1feee8
@@ -117,7 +113,7 @@ static enum nss_status getanswer_r (struct resolv_context *ctx,
1feee8
 				    const char *qname, int qtype,
1feee8
 				    struct hostent *result, char *buffer,
1feee8
 				    size_t buflen, int *errnop, int *h_errnop,
1feee8
-				    int map, int32_t *ttlp, char **canonp);
1feee8
+				    int32_t *ttlp, char **canonp);
1feee8
 static enum nss_status getanswer_ptr (unsigned char *packet, size_t packetlen,
1feee8
 				      struct alloc_buffer *abuf,
1feee8
 				      char **hnamep, int *errnop,
1feee8
@@ -198,7 +194,6 @@ gethostbyname3_context (struct resolv_context *ctx,
1feee8
   char tmp[NS_MAXDNAME];
1feee8
   int size, type, n;
1feee8
   const char *cp;
1feee8
-  int map = 0;
1feee8
   int olderr = errno;
1feee8
   enum nss_status status;
1feee8
 
1feee8
@@ -259,32 +254,12 @@ gethostbyname3_context (struct resolv_context *ctx,
1feee8
 	*errnop = EAGAIN;
1feee8
       else
1feee8
 	__set_errno (olderr);
1feee8
-
1feee8
-      /* If we are looking for an IPv6 address and mapping is enabled
1feee8
-	 by having the RES_USE_INET6 bit in _res.options set, we try
1feee8
-	 another lookup.  */
1feee8
-      if (af == AF_INET6 && res_use_inet6 ())
1feee8
-	n = __res_context_search (ctx, name, C_IN, T_A, host_buffer.buf->buf,
1feee8
-				  host_buffer.buf != orig_host_buffer
1feee8
-				  ? MAXPACKET : 1024, &host_buffer.ptr,
1feee8
-				  NULL, NULL, NULL, NULL);
1feee8
-
1feee8
-      if (n < 0)
1feee8
-	{
1feee8
-	  if (host_buffer.buf != orig_host_buffer)
1feee8
-	    free (host_buffer.buf);
1feee8
-	  return status;
1feee8
-	}
1feee8
-
1feee8
-      map = 1;
1feee8
-
1feee8
-      result->h_addrtype = AF_INET;
1feee8
-      result->h_length = INADDRSZ;
1feee8
     }
1feee8
+  else
1feee8
+    status = getanswer_r
1feee8
+      (ctx, host_buffer.buf, n, name, type, result, buffer, buflen,
1feee8
+       errnop, h_errnop, ttlp, canonp);
1feee8
 
1feee8
-  status = getanswer_r
1feee8
-    (ctx, host_buffer.buf, n, name, type, result, buffer, buflen,
1feee8
-     errnop, h_errnop, map, ttlp, canonp);
1feee8
   if (host_buffer.buf != orig_host_buffer)
1feee8
     free (host_buffer.buf);
1feee8
   return status;
1feee8
@@ -330,13 +305,8 @@ _nss_dns_gethostbyname_r (const char *name, struct hostent *result,
1feee8
       *h_errnop = NETDB_INTERNAL;
1feee8
       return NSS_STATUS_UNAVAIL;
1feee8
     }
1feee8
-  status = NSS_STATUS_NOTFOUND;
1feee8
-  if (res_use_inet6 ())
1feee8
-    status = gethostbyname3_context (ctx, name, AF_INET6, result, buffer,
1feee8
-				     buflen, errnop, h_errnop, NULL, NULL);
1feee8
-  if (status == NSS_STATUS_NOTFOUND)
1feee8
-    status = gethostbyname3_context (ctx, name, AF_INET, result, buffer,
1feee8
-				     buflen, errnop, h_errnop, NULL, NULL);
1feee8
+  status = gethostbyname3_context (ctx, name, AF_INET, result, buffer,
1feee8
+				   buflen, errnop, h_errnop, NULL, NULL);
1feee8
   __resolv_context_put (ctx);
1feee8
   return status;
1feee8
 }
1feee8
@@ -649,7 +619,7 @@ static enum nss_status
1feee8
 getanswer_r (struct resolv_context *ctx,
1feee8
 	     const querybuf *answer, int anslen, const char *qname, int qtype,
1feee8
 	     struct hostent *result, char *buffer, size_t buflen,
1feee8
-	     int *errnop, int *h_errnop, int map, int32_t *ttlp, char **canonp)
1feee8
+	     int *errnop, int *h_errnop, int32_t *ttlp, char **canonp)
1feee8
 {
1feee8
   struct host_data
1feee8
   {
1feee8
@@ -665,7 +635,6 @@ getanswer_r (struct resolv_context *ctx,
1feee8
   char *bp, **ap, **hap;
1feee8
   char tbuf[MAXDNAME];
1feee8
   u_char packtmp[NS_MAXCDNAME];
1feee8
-  int have_to_map = 0;
1feee8
   uintptr_t pad = -(uintptr_t) buffer % __alignof__ (struct host_data);
1feee8
   buffer += pad;
1feee8
   buflen = buflen > pad ? buflen - pad : 0;
1feee8
@@ -846,9 +815,7 @@ getanswer_r (struct resolv_context *ctx,
1feee8
 	  continue;
1feee8
 	}
1feee8
 
1feee8
-      if (type == T_A && qtype == T_AAAA && map)
1feee8
-	have_to_map = 1;
1feee8
-      else if (__glibc_unlikely (type != qtype))
1feee8
+      if (__glibc_unlikely (type != qtype))
1feee8
 	{
1feee8
 	  cp += n;
1feee8
 	  continue;			/* XXX - had_error++ ? */
1feee8
@@ -945,9 +912,6 @@ getanswer_r (struct resolv_context *ctx,
1feee8
 	  linebuflen -= n;
1feee8
 	}
1feee8
 
1feee8
-      if (have_to_map)
1feee8
-	if (map_v4v6_hostent (result, &bp, &linebuflen))
1feee8
-	  goto too_small;
1feee8
       *h_errnop = NETDB_SUCCESS;
1feee8
       return NSS_STATUS_SUCCESS;
1feee8
     }