resolv: Deprecate the "inet6" option and RES_USE_INET6 [BZ #19582]

This commit is contained in:
Florian Weimer 2016-10-04 11:52:10 +02:00
parent 5840c75c2d
commit b76e065991
17 changed files with 133 additions and 62 deletions

View File

@ -1,3 +1,41 @@
2016-12-27 Florian Weimer <fweimer@redhat.com>
[BZ #19582]
Deprecate RES_USE_INET6.
* nis/nss_nis/nis-hosts.c (_nss_nis_gethostent_r)
(_nss_nis_gethostbyname2_r, _nss_nis_gethostbyname_r)
(_nss_nis_gethostbyaddr_r): Use res_use_inet6 instead of
RES_USE_INET6.
* nis/nss_nisplus/nisplus-hosts.c (internal_nisplus_gethostent_r)
(_nss_nisplus_gethostbyname2_r, _nss_nisplus_gethostbyname_r)
(_nss_nisplus_gethostbyaddr_r): Likewise.
* nscd/aicache.c (addhstaiX): Use DEPRECATED_RES_USE_INET6 instead
of res_use_inet6.
* nscd/nscd_gethst_r.c (__nscd_gethostbyname_r): Use res_use_inet6
instead of RES_USE_INET6.
* nss/digits_dots.c (__nss_hostname_digits_dots): Likewise.
* nss/nss_files/files-hosts.c (EXTRA_ARGS_VALUE)
(_nss_files_gethostbyname3_r, _nss_files_gethostbyname_r):
Likewise.
* resolv/compat-gethnamaddr.c (getanswer, res_gethostbyname)
(res_gethostbyname2, res_gethostbyaddr, _gethtent, _gethtbyname):
Likewise.
* resolv/nss_dns/dns-host.c (_nss_dns_gethostbyname3_r)
(_nss_dns_gethostbyname_r): Likewise.
(_nss_dns_gethostbyaddr2_r): Remove commented-out code for
alternate RES_USE_INET6 handling.
* resolv/res_debug.c (p_option): Use DEPRECATED_RES_USE_INET6
instead of RES_USE_INET6.
* resolv/res_init.c (res_setoptions): Likewise.
* resolv/resolv.h (RES_USE_INET6): Mark as deprecated.
* resolv/resolv-internal.h: New file.
* resolv/Makefile (CFLAGS-tst-res_use_inet6.c): Use -Wno-error to
make the deprecation warning non-fatal.
* resolv/README (Using the resolver in multi-threaded code): Drop
reference to RES_USE_INET6.
* sysdeps/posix/getaddrinfo.c (gethosts, gaih_inet): Use
DEPRECATED_RES_USE_INET6 instead of res_use_inet6.
2016-12-31 Florian Weimer <fweimer@redhat.com>
* resolv/Makefile (tests): Add tst-bug18665, tst-bug18665-tcp,

5
NEWS
View File

@ -148,6 +148,11 @@ Version 2.25
in the <resolv.h> header file have been deprecated. They were already
unimplemented.
* The "inet6" option in /etc/resolv.conf and the RES_USE_INET6 flag for
_res.flags are deprecated. The flag was standardized in RFC 2133, but
removed again from the IETF name lookup interface specification in RFC
2553. Applications should use getaddrinfo instead.
* DNSSEC-related declarations and definitions have been removed from the
<arpa/nameser.h> header file, and libresolv will no longer attempt to
decode the data part of DNSSEC record types. Previous versions of glibc

View File

@ -27,7 +27,7 @@
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <resolv.h>
#include <resolv/resolv-internal.h>
#include <libc-lock.h>
#include <rpcsvc/yp.h>
#include <rpcsvc/ypclnt.h>
@ -231,8 +231,8 @@ _nss_nis_gethostent_r (struct hostent *host, char *buffer, size_t buflen,
__libc_lock_lock (lock);
status = internal_nis_gethostent_r (host, buffer, buflen, errnop, h_errnop,
((_res.options & RES_USE_INET6) ? AF_INET6 : AF_INET),
((_res.options & RES_USE_INET6) ? AI_V4MAPPED : 0 ));
(res_use_inet6 () ? AF_INET6 : AF_INET),
(res_use_inet6 () ? AI_V4MAPPED : 0 ));
__libc_lock_unlock (lock);
@ -351,7 +351,7 @@ _nss_nis_gethostbyname2_r (const char *name, int af, struct hostent *host,
return internal_gethostbyname2_r (name, af, host, buffer, buflen, errnop,
h_errnop,
((_res.options & RES_USE_INET6) ? AI_V4MAPPED : 0));
(res_use_inet6 () ? AI_V4MAPPED : 0));
}
@ -359,7 +359,7 @@ enum nss_status
_nss_nis_gethostbyname_r (const char *name, struct hostent *host, char *buffer,
size_t buflen, int *errnop, int *h_errnop)
{
if (_res.options & RES_USE_INET6)
if (res_use_inet6 ())
{
enum nss_status status;
@ -433,8 +433,7 @@ _nss_nis_gethostbyaddr_r (const void *addr, socklen_t addrlen, int af,
free (result);
int parse_res = parse_line (p, host, data, buflen, errnop, af,
((_res.options & RES_USE_INET6)
? AI_V4MAPPED : 0));
(res_use_inet6 () ? AI_V4MAPPED : 0));
if (__glibc_unlikely (parse_res < 1))
{
if (parse_res == -1)

View File

@ -43,6 +43,7 @@ static u_long tablename_len;
(NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len)
/* Get implementation for some internal functions. */
#include <resolv/resolv-internal.h>
#include <resolv/mapv4v6addr.h>
@ -321,7 +322,7 @@ internal_nisplus_gethostent_r (struct hostent *host, char *buffer,
}
}
if (_res.options & RES_USE_INET6)
if (res_use_inet6 ())
parse_res = _nss_nisplus_parse_hostent (result, AF_INET6, host, buffer,
buflen, errnop, AI_V4MAPPED);
else
@ -488,7 +489,7 @@ _nss_nisplus_gethostbyname2_r (const char *name, int af, struct hostent *host,
return internal_gethostbyname2_r (name, af, host, buffer, buflen, errnop,
herrnop,
((_res.options & RES_USE_INET6) ? AI_V4MAPPED : 0));
(res_use_inet6 () ? AI_V4MAPPED : 0));
}
@ -497,7 +498,7 @@ _nss_nisplus_gethostbyname_r (const char *name, struct hostent *host,
char *buffer, size_t buflen, int *errnop,
int *h_errnop)
{
if (_res.options & RES_USE_INET6)
if (res_use_inet6 ())
{
enum nss_status status;
@ -558,7 +559,7 @@ _nss_nisplus_gethostbyaddr_r (const void *addr, socklen_t addrlen, int af,
parse_res = _nss_nisplus_parse_hostent (result, af, host,
buffer, buflen, errnop,
((_res.options & RES_USE_INET6)
(res_use_inet6 ()
? AI_V4MAPPED : 0));
nis_freeresult (result);

View File

@ -25,6 +25,7 @@
#include <time.h>
#include <unistd.h>
#include <sys/mman.h>
#include <resolv/resolv-internal.h>
#include <resolv/res_hconf.h>
#include "dbg_log.h"
@ -110,7 +111,7 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req,
IPv6 addresses. Currently this is decided by setting the
RES_USE_INET6 bit in _res.options. */
int old_res_options = _res.options;
_res.options &= ~RES_USE_INET6;
_res.options &= ~DEPRECATED_RES_USE_INET6;
size_t tmpbuf6len = 1024;
char *tmpbuf6 = alloca (tmpbuf6len);
@ -535,7 +536,7 @@ next_nip:
}
out:
_res.options |= old_res_options & RES_USE_INET6;
_res.options |= old_res_options & DEPRECATED_RES_USE_INET6;
if (dataset != NULL && !alloca_used)
{

View File

@ -17,7 +17,7 @@
<http://www.gnu.org/licenses/>. */
#include <errno.h>
#include <resolv.h>
#include <resolv/resolv-internal.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
@ -42,7 +42,7 @@ __nscd_gethostbyname_r (const char *name, struct hostent *resultbuf,
{
request_type reqtype;
reqtype = (_res.options & RES_USE_INET6) ? GETHOSTBYNAMEv6 : GETHOSTBYNAME;
reqtype = res_use_inet6 () ? GETHOSTBYNAMEv6 : GETHOSTBYNAME;
return nscd_gethst_r (name, strlen (name) + 1, reqtype, resultbuf,
buffer, buflen, result, h_errnop);

View File

@ -22,7 +22,7 @@
#include <stdlib.h>
#include <ctype.h>
#include <wctype.h>
#include <resolv.h>
#include <resolv/resolv-internal.h>
#include <netdb.h>
#include <arpa/inet.h>
#include "nsswitch.h"
@ -80,7 +80,7 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
break;
default:
af = (_res.options & RES_USE_INET6) ? AF_INET6 : AF_INET;
af = res_use_inet6 () ? AF_INET6 : AF_INET;
addr_size = af == AF_INET6 ? IN6ADDRSZ : INADDRSZ;
break;
}
@ -167,7 +167,7 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
(*h_addr_ptrs)[0] = (char *) host_addr;
(*h_addr_ptrs)[1] = NULL;
resbuf->h_addr_list = *h_addr_ptrs;
if (af == AF_INET && (_res.options & RES_USE_INET6))
if (af == AF_INET && res_use_inet6 ())
{
/* We need to change the IP v4 address into the
IP v6 address. */
@ -211,7 +211,7 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
switch (af)
{
default:
af = (_res.options & RES_USE_INET6) ? AF_INET6 : AF_INET;
af = res_use_inet6 () ? AF_INET6 : AF_INET;
if (af == AF_INET6)
{
addr_size = IN6ADDRSZ;

View File

@ -21,7 +21,7 @@
#include <arpa/inet.h>
#include <arpa/nameser.h>
#include <netdb.h>
#include <resolv.h>
#include <resolv/resolv-internal.h>
/* Get implementation for some internal functions. */
@ -98,8 +98,8 @@ LINE_PARSER
})
#define EXTRA_ARGS_VALUE \
, ((_res.options & RES_USE_INET6) ? AF_INET6 : AF_INET), \
((_res.options & RES_USE_INET6) ? AI_V4MAPPED : 0)
, (res_use_inet6 () ? AF_INET6 : AF_INET), \
(res_use_inet6 () ? AI_V4MAPPED : 0)
#include "files-XXX.c"
#undef EXTRA_ARGS_VALUE
@ -132,7 +132,7 @@ _nss_files_gethostbyname3_r (const char *name, int af, struct hostent *result,
{
/* XXX Is using _res to determine whether we want to convert IPv4
addresses to IPv6 addresses really the right thing to do? */
int flags = ((_res.options & RES_USE_INET6) ? AI_V4MAPPED : 0);
int flags = (res_use_inet6 () ? AI_V4MAPPED : 0);
while ((status = internal_getent (stream, result, buffer, buflen, errnop,
herrnop, af, flags))
@ -351,7 +351,7 @@ _nss_files_gethostbyname_r (const char *name, struct hostent *result,
char *buffer, size_t buflen, int *errnop,
int *herrnop)
{
int af = ((_res.options & RES_USE_INET6) ? AF_INET6 : AF_INET);
int af = (res_use_inet6 () ? AF_INET6 : AF_INET);
return _nss_files_gethostbyname3_r (name, af, result, buffer, buflen,
errnop, herrnop, NULL, NULL);

View File

@ -124,3 +124,6 @@ $(objpfx)tst-res_use_inet6: $(objpfx)libresolv.so $(shared-thread-library)
$(objpfx)tst-resolv-basic: $(objpfx)libresolv.so $(shared-thread-library)
$(objpfx)tst-resolv-network: $(objpfx)libresolv.so $(shared-thread-library)
$(objpfx)tst-resolv-search: $(objpfx)libresolv.so $(shared-thread-library)
# This test case uses the deprecated RES_USE_INET6 resolver option.
CFLAGS-tst-res_use_inet6.c += -Wno-error

View File

@ -80,11 +80,7 @@ code:
* In Multi-threaded that manipulate the _res structure, calls to
functions like `gethostbyname' in threads other than the "main"
thread won't be influenced by the those changes anymore. So if you
set RES_USE_INET6, a call to `gethostbyname' won't return any IPv6
hosts anymore. If you recompile such programs, manipulating the
_res structure will affect the thread in which you do so instead of
the "main" thread.
thread won't be influenced by the those changes anymore.
We recommend to use the new thread-safe interfaces in new code, since
the traditional interfaces have been deprecated by the BIND folks.

View File

@ -66,7 +66,7 @@
# include <stdio.h>
# include <netdb.h>
# include <resolv.h>
# include <resolv/resolv-internal.h>
# include <ctype.h>
# include <errno.h>
# include <stdlib.h>
@ -412,7 +412,7 @@ getanswer (const querybuf *answer, int anslen, const char *qname, int qtype)
bp += n;
buflen -= n;
}
if (_res.options & RES_USE_INET6)
if (res_use_inet6 ())
map_v4v6_hostent(&host, &bp, &buflen);
__set_h_errno (NETDB_SUCCESS);
return (&host);
@ -434,7 +434,7 @@ res_gethostbyname (const char *name)
__set_h_errno (NETDB_INTERNAL);
return (NULL);
}
if (_res.options & RES_USE_INET6) {
if (res_use_inet6 ()) {
hp = res_gethostbyname2(name, AF_INET6);
if (hp)
return (hp);
@ -516,7 +516,7 @@ res_gethostbyname2 (const char *name, int af)
h_addr_ptrs[0] = (char *)host_addr;
h_addr_ptrs[1] = NULL;
host.h_addr_list = h_addr_ptrs;
if (_res.options & RES_USE_INET6)
if (res_use_inet6 ())
map_v4v6_hostent(&host, &bp, &len);
__set_h_errno (NETDB_SUCCESS);
return (&host);
@ -665,7 +665,7 @@ res_gethostbyaddr (const void *addr, socklen_t len, int af)
memmove(host_addr, addr, len);
h_addr_ptrs[0] = (char *)host_addr;
h_addr_ptrs[1] = NULL;
if (af == AF_INET && (_res.options & RES_USE_INET6)) {
if (af == AF_INET && res_use_inet6 ()) {
map_v4v6_address((char*)host_addr, (char*)host_addr);
hp->h_addrtype = AF_INET6;
hp->h_length = IN6ADDRSZ;
@ -724,7 +724,7 @@ _gethtent (void)
af = AF_INET6;
len = IN6ADDRSZ;
} else if (inet_pton(AF_INET, p, host_addr) > 0) {
if (_res.options & RES_USE_INET6) {
if (res_use_inet6 ()) {
map_v4v6_address((char*)host_addr, (char*)host_addr);
af = AF_INET6;
len = IN6ADDRSZ;
@ -768,7 +768,7 @@ _gethtbyname (const char *name)
{
struct hostent *hp;
if (_res.options & RES_USE_INET6) {
if (res_use_inet6 ()) {
hp = _gethtbyname2(name, AF_INET6);
if (hp)
return (hp);

View File

@ -81,7 +81,8 @@
#include "nsswitch.h"
/* Get implementation for some internal functions. */
/* Get implementeation for some internal functions. */
#include <resolv/resolv-internal.h>
#include <resolv/mapv4v6addr.h>
#include <resolv/mapv4v6hostent.h>
@ -232,7 +233,7 @@ _nss_dns_gethostbyname3_r (const char *name, int af, struct hostent *result,
/* If we are looking for an IPv6 address and mapping is enabled
by having the RES_USE_INET6 bit in _res.options set, we try
another lookup. */
if (af == AF_INET6 && (_res.options & RES_USE_INET6))
if (af == AF_INET6 && res_use_inet6 ())
n = __libc_res_nsearch (&_res, name, C_IN, T_A, host_buffer.buf->buf,
host_buffer.buf != orig_host_buffer
? MAXPACKET : 1024, &host_buffer.ptr,
@ -277,7 +278,7 @@ _nss_dns_gethostbyname_r (const char *name, struct hostent *result,
{
enum nss_status status = NSS_STATUS_NOTFOUND;
if (_res.options & RES_USE_INET6)
if (res_use_inet6 ())
status = _nss_dns_gethostbyname3_r (name, AF_INET6, result, buffer,
buflen, errnop, h_errnop, NULL, NULL);
if (status == NSS_STATUS_NOTFOUND)
@ -503,17 +504,6 @@ _nss_dns_gethostbyaddr2_r (const void *addr, socklen_t len, int af,
memcpy (host_data->host_addr, addr, len);
host_data->h_addr_ptrs[0] = (char *) host_data->host_addr;
host_data->h_addr_ptrs[1] = NULL;
#if 0
/* XXX I think this is wrong. Why should an IPv4 address be
converted to IPv6 if the user explicitly asked for IPv4? */
if (af == AF_INET && (_res.options & RES_USE_INET6))
{
map_v4v6_address ((char *) host_data->host_addr,
(char *) host_data->host_addr);
result->h_addrtype = AF_INET6;
result->h_length = IN6ADDRSZ;
}
#endif
*h_errnop = NETDB_SUCCESS;
return NSS_STATUS_SUCCESS;
}

View File

@ -101,7 +101,7 @@
#include <errno.h>
#include <math.h>
#include <netdb.h>
#include <resolv.h>
#include <resolv/resolv-internal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -556,7 +556,7 @@ p_option(u_long option) {
case RES_INSECURE1: return "insecure1";
case RES_INSECURE2: return "insecure2";
case RES_NOALIASES: return "noaliases";
case RES_USE_INET6: return "inet6";
case DEPRECATED_RES_USE_INET6: return "inet6";
case RES_ROTATE: return "rotate";
case RES_BLAST: return "blast";
case RES_USE_EDNS0: return "edns0";

View File

@ -66,7 +66,7 @@
#include <ctype.h>
#include <netdb.h>
#include <resolv.h>
#include <resolv/resolv-internal.h>
#include <stdio.h>
#include <stdio_ext.h>
#include <stdlib.h>
@ -437,7 +437,7 @@ res_setoptions(res_state statp, const char *options, const char *source) {
unsigned long int flag;
} options[] = {
#define STRnLEN(str) str, sizeof (str) - 1
{ STRnLEN ("inet6"), 0, RES_USE_INET6 },
{ STRnLEN ("inet6"), 0, DEPRECATED_RES_USE_INET6 },
{ STRnLEN ("rotate"), 0, RES_ROTATE },
{ STRnLEN ("edns0"), 0, RES_USE_EDNS0 },
{ STRnLEN ("single-request-reopen"), 0, RES_SNGLKUPREOP },

35
resolv/resolv-internal.h Normal file
View File

@ -0,0 +1,35 @@
/* libresolv interfaces for internal use across glibc.
Copyright (C) 2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#ifndef _RESOLV_INTERNAL_H
#define _RESOLV_INTERNAL_H 1
#include <resolv.h>
#include <stdbool.h>
/* Internal version of RES_USE_INET6 which does not trigger a
deprecation warning. */
#define DEPRECATED_RES_USE_INET6 0x00002000
static inline bool
res_use_inet6 (void)
{
return _res.options & DEPRECATED_RES_USE_INET6;
}
#endif /* _RESOLV_INTERNAL_H */

View File

@ -190,7 +190,8 @@ struct res_sym {
#define RES_INSECURE1 0x00000400 /* type 1 security disabled */
#define RES_INSECURE2 0x00000800 /* type 2 security disabled */
#define RES_NOALIASES 0x00001000 /* shuts off HOSTALIASES feature */
#define RES_USE_INET6 0x00002000 /* use/map IPv6 in gethostbyname() */
#define RES_USE_INET6 \
__glibc_macro_warning ("RES_USE_INET6 is deprecated") 0x00002000
#define RES_ROTATE 0x00004000 /* rotate ns list after each query */
#define RES_NOCHECKNAME \
__glibc_macro_warning ("RES_NOCHECKNAME is deprecated") 0x00008000

View File

@ -59,7 +59,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <ifaddrs.h>
#include <netdb.h>
#include <nss.h>
#include <resolv.h>
#include <resolv/resolv-internal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdio_ext.h>
@ -267,7 +267,7 @@ convert_hostent_to_gaih_addrtuple (const struct addrinfo *req,
if (herrno == NETDB_INTERNAL) \
{ \
__set_h_errno (herrno); \
_res.options |= old_res_options & RES_USE_INET6; \
_res.options |= old_res_options & DEPRECATED_RES_USE_INET6; \
result = -EAI_SYSTEM; \
goto free_and_return; \
} \
@ -283,7 +283,7 @@ convert_hostent_to_gaih_addrtuple (const struct addrinfo *req,
addrmem = NULL; \
if (!convert_hostent_to_gaih_addrtuple (req, _family,h, &addrmem)) \
{ \
_res.options |= old_res_options & RES_USE_INET6; \
_res.options |= old_res_options & DEPRECATED_RES_USE_INET6; \
result = -EAI_SYSTEM; \
goto free_and_return; \
} \
@ -808,7 +808,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
addresses to IPv6 addresses. Currently this is decided
by setting the RES_USE_INET6 bit in _res.options. */
old_res_options = _res.options;
_res.options &= ~RES_USE_INET6;
_res.options &= ~DEPRECATED_RES_USE_INET6;
while (!no_more)
{
@ -845,7 +845,8 @@ gaih_inet (const char *name, const struct gaih_service *service,
if (!scratch_buffer_grow (tmpbuf))
{
_res.options |= old_res_options & RES_USE_INET6;
_res.options
|= old_res_options & DEPRECATED_RES_USE_INET6;
result = -EAI_MEMORY;
goto free_and_return;
}
@ -962,7 +963,8 @@ gaih_inet (const char *name, const struct gaih_service *service,
if (canonbuf == NULL)
{
_res.options
|= old_res_options & RES_USE_INET6;
|= old_res_options
& DEPRECATED_RES_USE_INET6;
result = -EAI_MEMORY;
goto free_and_return;
}
@ -1024,7 +1026,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
nip = nip->next;
}
_res.options |= old_res_options & RES_USE_INET6;
_res.options |= old_res_options & DEPRECATED_RES_USE_INET6;
if (h_errno == NETDB_INTERNAL)
{