2017-06-19 19:20:46 +08:00
|
|
|
/* Resolver state initialization and resolv.conf parsing.
|
2021-01-03 03:32:25 +08:00
|
|
|
Copyright (C) 1995-2021 Free Software Foundation, Inc.
|
2017-06-19 19:20:46 +08:00
|
|
|
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
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 13:40:42 +08:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2017-06-19 19:20:46 +08:00
|
|
|
|
1995-02-18 09:27:10 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1985, 1989, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
2000-08-21 12:18:25 +08:00
|
|
|
*
|
1995-02-18 09:27:10 +08:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
2000-08-21 12:18:25 +08:00
|
|
|
*
|
1995-02-18 09:27:10 +08:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
1999-12-05 02:05:55 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
1995-02-18 09:27:10 +08:00
|
|
|
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
|
2000-08-21 12:18:25 +08:00
|
|
|
*
|
1995-02-18 09:27:10 +08:00
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies, and that
|
|
|
|
* the name of Digital Equipment Corporation not be used in advertising or
|
|
|
|
* publicity pertaining to distribution of the document or software without
|
|
|
|
* specific, written prior permission.
|
2000-08-21 12:18:25 +08:00
|
|
|
*
|
1995-02-18 09:27:10 +08:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
|
|
|
|
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
|
|
|
|
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
|
|
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
|
|
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
|
|
* SOFTWARE.
|
1999-12-05 02:05:55 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Portions Copyright (c) 1996-1999 by Internet Software Consortium.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
|
|
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
|
|
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
|
|
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
|
|
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
|
|
* SOFTWARE.
|
1995-02-18 09:27:10 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <ctype.h>
|
2008-04-08 01:20:25 +08:00
|
|
|
#include <netdb.h>
|
2016-10-04 17:52:10 +08:00
|
|
|
#include <resolv/resolv-internal.h>
|
2017-06-27 15:26:46 +08:00
|
|
|
#include <res_hconf.h>
|
1999-12-05 02:05:55 +08:00
|
|
|
#include <stdio.h>
|
2001-07-17 16:32:35 +08:00
|
|
|
#include <stdio_ext.h>
|
1999-12-05 02:05:55 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2013-05-01 23:46:34 +08:00
|
|
|
#include <stdint.h>
|
2008-04-08 01:20:25 +08:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <arpa/nameser.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
2016-09-15 21:46:30 +08:00
|
|
|
#include <inet/net-internal.h>
|
2017-06-19 20:05:49 +08:00
|
|
|
#include <errno.h>
|
2017-07-04 02:31:23 +08:00
|
|
|
#include <resolv_conf.h>
|
2020-01-22 00:25:39 +08:00
|
|
|
#include <file_change_detection.h>
|
1995-02-18 09:27:10 +08:00
|
|
|
|
2017-06-19 19:20:46 +08:00
|
|
|
static uint32_t net_mask (struct in_addr);
|
1995-02-18 09:27:10 +08:00
|
|
|
|
1995-07-26 18:14:02 +08:00
|
|
|
int
|
2017-06-19 19:20:46 +08:00
|
|
|
res_ninit (res_state statp)
|
|
|
|
{
|
|
|
|
return __res_vinit (statp, 0);
|
1999-12-05 02:05:55 +08:00
|
|
|
}
|
Update.
2002-08-02 Ulrich Drepper <drepper@redhat.com>
* configure.in (HAVE_BROKEN_ALIAS_ATTRIBUTE): Add check for
broken alias attribute handling.
* config.h.in (HAVE_BROKEN_ALIAS_ATTRIBUTE): Add.
* assert/assert.c (__assert_fail): Fix typo in comment.
* include/rpc/rpc.h: Declare __libc_tsd_RPC_VARS if USE_TLS &&
HAVE___THREAD.
* sunrpc/rpc_thread.c: Don't define __libc_tsd_RPC_VARS as static
if USE_TLS && HAVE___THREAD.
* sunrpc/Versions [libc] (GLIBC_PRIVATE): Export __libc_tsd_RPC_VARS.
2002-08-02 Jakub Jelinek <jakub@redhat.com>
* assert/assert.c (__assert_fail): Remove undef.
Replace INTDEF with libc_hidden_def.
* assert/__assert.c (__assert): Remove INTUSE.
* elf/dl-minimal.c (__assert_fail): Replace INTDEF with
libc_hidden_weak.
* include/libc-symbols.h (hidden_proto, hidden_def, hidden_weak,
hidden_ver, libc_hidden_proto, libc_hidden_def, libc_hidden_weak,
libc_hidden_ver, rtld_hidden_proto, rtld_hidden_def, rtld_hidden_weak,
rltd_hidden_ver, libm_hidden_proto, libm_hidden_def, libm_hidden_weak,
libm_hiden_ver): Define.
* include/assert.h (__assert_fail_internal): Remove.
(__assert_fail): Add prototype. Add hidden_proto.
* include/libc-internal.h (__libc_freeres, __profile_frequency): Add
libc_hidden_proto.
* include/wchar.h (__mbrtowc_internal, __mbrlen_internal): Remove.
(__mbrtowc, __mbrlen): Use libc_hidden_proto. Remove macros.
* include/string.h (__mempcpy, __stpncpy, __rawmemchr, __strcasecmp):
Add libc_hidden_proto.
* include/fcntl.h (__open64, __libc_open, __libc_fcntl, __open,
__fcntl): Add libc_hidden_proto. Remove macros.
(__open_internal, __fcntl_internal): Remove.
* libio/iofdopen.c (_IO_fcntl): Remove INTUSE from __fcntl.
* malloc/set-freeres.c (__libc_freeres): Add libc_hidden_def.
* nss/nsswitch.h (__nss_database_lookup, __nss_next): Add
libc_hiden_proto.
* nss/nsswitch.c (__nss_database_lookup, __nss_next): Add
libc_hidden_def.
* sysdeps/generic/mempcpy.c (__mempcpy): Remove undef.
Add libc_hidden_def.
* sysdeps/generic/open64.c (__open64): Add libc_hidden_def.
* sysdeps/generic/open.c (__open): Remove undef.
Add libc_hidden_def. Remove INTDEF.
* sysdeps/generic/fcntl.c (__fcntl): Remove undef.
Add libc_hidden_def.
* sysdeps/mach/hurd/fcntl.c (__fcntl): Likewise.
* sysdeps/i386/i586/mempcpy.S (__mempcpy): Add libc_hidden_def.
* sysdeps/i386/i686/mempcpy.S (__mempcpy): Likewise.
* sysdeps/mach/hurd/fcntl.c (__libc_fcntl, __fcntl): Remove undef.
(__fcntl): Remove INTDEF2. Add libc_hidden_weak.
(__libc_fcntl): Add libc_hidden_def.
* sysdeps/mach/hurd/open.c (__libc_open, __open): Remove undef.
(__open): Remove INTDEF2. Add libc_hidden_weak.
(__libc_open): Add libc_hidden_def.
* sysdeps/posix/open64.c (__open64): Add libc_hidden_weak.
* sysdeps/standalone/open.c (__open): Add libc_hidden_def.
* sysdeps/unix/sysv/aix/fcntl.c (__libc_fcntl, __fcntl): Remove undef.
Add libc_hidden_def.
* sysdeps/unix/sysv/aix/open.c (__libc_open, __open): Remove undef.
Add libc_hidden_def.
* sysdeps/unix/sysv/linux/i386/fcntl.c (__libc_fcntl, __fcntl): Remove
undef.
(__fcntl): Remove INTDEF2. Add libc_hidden_weak.
(__libc_fcntl): Add libc_hidden_def.
* sysdeps/unix/sysv/linux/syscalls.list (__fcntl_internal,
__getpgid_internal, __chown_internal): Remove.
(__GI___fcntl, __GI___libc_fcntl, __GI___getpgid, __GI___pipe,
__GI___sched_setscheduler, __GI___select, __GI___setpgid,
__GI___chown): Add.
* sysdeps/unix/syscalls.list (__close_internal, __dup2_internal,
__getpid_internal, __open_internal, __write_internal): Remove.
(__GI___fcntl, __GI___libc_fcntl, __GI___open, __GI___libc_open,
__GI___chown, __GI___close, __GI___dup2, __GI___getpid,
__GI___libc_open, __GI___open, __GI___read, __GI___libc_read,
__GI___select, __GI___statfs, __GI___write, __GI___libc_write): Add.
* wcsmbs/mbrlen.c (__mbrlen): Remove undef.
Replace INTDEF with libc_hidden_def.
* wcsmbs/mbrtowc.c (__mbrtowc): Likewise.
* catgets/catgetsinfo.h (__open_catalog): Add libc_hidden_proto.
* catgets/open_catalog.c (__open_catalog): Add libc_hidden_def.
* elf/dl-profile.c (__profile_frequency): Add libc_hidden_proto.
* include/rpc/rpc.h (__rpc_thread_svc_fdset, __rpc_thread_createerr):
Add libc_hidden_proto.
* include/sys/poll.h (__poll): Add libc_hidden_proto.
* include/sys/select.h (__select): Likewise.
* include/sys/socket.h (__send): Likewise.
* include/sys/statfs.h (__statfs): Likewise.
* include/unistd.h (__pwrite64, __libc_read, __pipe, __chown, __dup2,
__getpid, __getpgid, __setpgid, __close, __read, __write,
__getpagesize, __sbrk): Likewise.
(__chown_internal, __dup2_internal, __getpid_internal,
__getpgid_internal, __close_internal, __write_internal,
__getpagesize_internal): Remove.
(__close, __dup2, __getpagesize, __getpgid, __getpid, __libc_write):
Remove macros.
* include/printf.h (__printf_fp): Add libc_hidden_proto.
* include/sched.h (__sched_setscheduler): Likewise.
* include/resolv.h (__res_ninit, __res_randomid): Likewise.
* include/stdlib.h (__secure_getenv): Likewise.
* include/signal.h (__sigaction, __sigsuspend): Likewise.
* inet/getaliasent_r.c (NSS_attribute_hidden): Remove.
* inet/getaliasname_r.c (NSS_attribute_hidden): Remove.
* inet/getnetbyad_r.c (NSS_attribute_hidden): Remove.
* inet/getnetbynm_r.c (NSS_attribute_hidden): Remove.
* inet/getnetent_r.c (NSS_attribute_hidden): Remove.
* inet/getproto_r.c (NSS_attribute_hidden): Remove.
* inet/getprtent_r.c (NSS_attribute_hidden): Remove.
* inet/getprtname_r.c (NSS_attribute_hidden): Remove.
* inet/getrpcbyname_r.c (NSS_attribute_hidden): Remove.
* inet/getrpcbynumber_r.c (NSS_attribute_hidden): Remove.
* inet/getrpcent_r.c (NSS_attribute_hidden): Remove.
* inet/getservent_r.c (NSS_attribute_hidden): Remove.
* inet/getsrvbynm_r.c (NSS_attribute_hidden): Remove.
* inet/getsrvbypt_r.c (NSS_attribute_hidden): Remove.
* inet/gethstbyad_r.c (DB_LOOKUP_FCT): Remove INTUSE.
* inet/gethstbynm2_r.c (DB_LOOKUP_FCT): Likewise.
* inet/gethstbynm_r.c (DB_LOOKUP_FCT): Likewise.
* inet/gethstent_r.c (DB_LOOKUP_FCT): Likewise.
* libio/genops.c (__overflow): Add libc_hidden_def.
* libio/iovdprintf.c: Remove libio.h include.
* libio/libioP.h (libc_hidden_proto, libc_hidden_def,
libc_hidden_weak): Define to nothing if not defined.
(__overflow, __woverflow): Add libc_hidden_proto.
* libio/wgenops.c (__woverflow): Add libc_hidden_def.
* nss/getXXent_r.c (NSS_attribute_hidden): Remove.
(DB_LOOKUP_FCT): Add libc_hidden_proto.
* nss/getXXbyYY_r.c (NSS_attribute_hidden): Remove.
(DB_LOOKUP_FCT): Add libc_hidden_proto.
* nss/XXX-lookup.c (DB_LOOKUP_FCT): Add libc_hidden_proto
and libc_hidden_def.
* nss/hosts-lookup.c (__nss_hosts_lookup): Remove INTDEF.
* posix/bsd-getpgrp.c (__getpgid_internal): Remove.
(__getpgid): Add libc_hidden_proto.
(__bsd_getpgrp): Remove INTUSE.
* resolv/res_init.c (__res_ninit, __res_randomid): Add
libc_hidden_def.
* shadow/getspent_r.c (NSS_attribute_hidden): Remove.
* shadow/getspnam_r.c (NSS_attribute_hidden): Remove.
* stdio-common/printf_fp.c (__printf_fp): Add libc_hidden_def.
* stdlib/strfmon.c (__printf_fp): Add libc_hidden_proto.
* stdlib/secure-getenv.c (__secure_getenv): Add libc_hidden_def.
* sunrpc/rpc_thread.c (__rpc_thread_svc_fdset,
__rpc_thread_createerr): Add libc_hidden_def.
* sysdeps/alpha/alphaev67/rawmemchr.S (__rawmemchr): Add
libc_hidden_def.
* sysdeps/alpha/alphaev67/stpncpy.S (__stpncpy): Likewise.
* sysdeps/alpha/rawmemchr.S (__rawmemchr): Likewise.
* sysdeps/alpha/stpncpy.S (__stpncpy): Likewise.
* sysdeps/generic/chown.c (__chown): Likewise.
* sysdeps/generic/close.c (__close): Likewise.
* sysdeps/generic/dup2.c (__dup2): Likewise.
* sysdeps/generic/pipe.c (__pipe): Likewise.
* sysdeps/generic/prof-freq.c (__profile_frequency): Likewise.
* sysdeps/generic/pwrite64.c (__pwrite64): Likewise.
* sysdeps/generic/rawmemchr.c (__rawmemchr): Likewise.
* sysdeps/generic/read.c (__libc_read): Likewise.
(__read): Add libc_hidden_weak.
* sysdeps/generic/sbrk.c (__sbrk): Add libc_hidden_def.
* sysdeps/generic/sched_sets.c (__sched_setscheduler): Likewise.
* sysdeps/generic/select.c (__select): Likewise.
* sysdeps/generic/send.c (__send): Likewise.
* sysdeps/generic/setpgid.c (__setpgid): Likewise.
* sysdeps/generic/sigaction.c (__sigaction): Likewise.
* sysdeps/generic/sigsuspend.c (__sigsuspend): Likewise.
* sysdeps/generic/statfs.c (__statfs): Likewise.
* sysdeps/generic/stpncpy.c (__stpncpy): Likewise.
* sysdeps/generic/strcasecmp.c (__strcasecmp): Likewise.
* sysdeps/generic/getpagesize.c (__getpagesize): Likewise.
Remove undef and INTDEF.
* sysdeps/generic/getpgid.c (__getpgid): Likewise.
* sysdeps/generic/getpid.c (__getpid): Likewise.
* sysdeps/generic/write.c (__libc_write): Likewise.
(__write): Add libc_hidden_weak. Remove undef and INTDEF.
* sysdeps/i386/rawmemchr.S (__rawmemchr): Add libc_hidden_def.
* sysdeps/i386/stpncpy.S (__stpncpy): Likewise.
* sysdeps/m68k/rawmemchr.S (__rawmemchr): Likewise.
* sysdeps/mach/hurd/chown.c (__chown): Likewise. Remove INTDEF.
* sysdeps/mach/hurd/close.c (__close): Add libc_hidden_def.
Remove undef and INTDEF.
* sysdeps/mach/hurd/dup2.c (__dup2): Likewise.
* sysdeps/mach/hurd/getpgid.c (__getpgid): Likewise.
* sysdeps/mach/hurd/getpid.c (__getpid): Likewise.
* sysdeps/mach/getpagesize.c (__getpagesize): Likewise.
* sysdeps/mach/hurd/write.c (__libc_write): Likewise.
(__write): Add libc_hidden_weak. Remove undef and INTDEF.
* sysdeps/mach/hurd/pipe.c: Include unistd.h.
(__pipe): Add libc_hidden_def.
* sysdeps/mach/hurd/dl-sysdep.c (__libc_read, __libc_write): Add
libc_hidden_weak.
* sysdeps/mach/hurd/poll.c (__poll): Add libc_hidden_def.
* sysdeps/mach/hurd/profil.c (__profile_frequency): Likewise.
* sysdeps/mach/hurd/read.c (__libc_read): Likewise.
(__read): Add libc_hidden_weak.
* sysdeps/mach/hurd/pwrite64.c (__pwrite64): Likewise.
(__libc_pwrite64): Add libc_hidden_def.
* sysdeps/mach/hurd/sbrk.c (__sbrk): Likewise.
* sysdeps/mach/hurd/select.c (__select): Likewise.
* sysdeps/mach/hurd/send.c (__send): Likewise.
* sysdeps/mach/hurd/setpgid.c (__setpgid): Likewise.
* sysdeps/mach/hurd/sigaction.c (__sigaction): Likewise.
* sysdeps/mach/hurd/sigsuspend.c (__sigsuspend): Likewise.
* sysdeps/mach/hurd/statfs.c (__statfs): Likewise.
* sysdeps/posix/dup2.c: Likewise.
Remove undef and INTDEF.
* sysdeps/posix/getpagesize.c (__getpagesize): Likewise.
* sysdeps/posix/pwrite64.c (__libc_pwrite64): Add libc_hidden_def.
(__pwrite64): Add libc_hidden_weak.
* sysdeps/posix/sigsuspend.c (__sigsuspend): Add libc_hidden_def.
* sysdeps/sparc/sparc64/rawmemchr.S (__rawmemchr): Likewise.
* sysdeps/sparc/sparc64/stpncpy.S (__stpncpy): Likewise.
* sysdeps/standalone/close.c (__close): Likewise.
* sysdeps/standalone/write.c (__libc_write): Likewise.
(__write): Add libc_hidden_weak.
* sysdeps/standalone/read.c (__read): Likewise.
(__libc_read): Add libc_hidden_def.
* sysdeps/unix/grantpt.c (grantpt): Remove INTUSE.
* sysdeps/unix/bsd/m68k/pipe.S (__pipe): Add libc_hidden_def.
* sysdeps/unix/bsd/osf/alpha/pipe.S (__pipe): Likewise.
* sysdeps/unix/bsd/vax/pipe.S (__pipe): Likewise.
* sysdeps/unix/bsd/syscalls.list (__GI___getpagesize): Likewise.
* sysdeps/unix/bsd/poll.c (__poll): Likewise.
* sysdeps/unix/bsd/sigaction.c (__sigaction): Likewise.
* sysdeps/unix/bsd/sigsuspend.c (__sigsuspend): Likewise.
* sysdeps/unix/common/syscalls.list (__GI___getpgid, __GI___setpgid,
__GI___sigaction): Add.
* sysdeps/unix/i386/pipe.S (__pipe): Add libc_hidden_def.
* sysdeps/unix/inet/syscalls.list (__GI___send): Add.
* sysdeps/unix/mips/pipe.S (__pipe): Add libc_hidden_def.
* sysdeps/unix/sparc/pipe.S (__pipe): Likewise.
* sysdeps/unix/sysv/irix4/syscalls.list (__GI___getpgid,
__GI___setpgid): Add.
* sysdeps/unix/sysv/aix/chown.c (__chown): Add libc_hidden_def.
Remove undef and INTDEF.
* sysdeps/unix/sysv/aix/getpgid.c (__getpgid): Likewise.
* sysdeps/unix/sysv/aix/write.c (__write, __libc_write): Likewise.
* sysdeps/unix/sysv/aix/close.c (__close): Add libc_hidden_def.
* sysdeps/unix/sysv/aix/getpid.c (__getpid): Likewise.
* sysdeps/unix/sysv/aix/pipe.c (__pipe): Likewise.
* sysdeps/unix/sysv/aix/read.c (__read, __libc_read): Likewise.
* sysdeps/unix/sysv/aix/poll.c (__poll): Likewise.
* sysdeps/unix/sysv/aix/sbrk.c (__sbrk): Likewise.
* sysdeps/unix/sysv/aix/sigaction.c (__sigaction): Likewise.
* sysdeps/unix/sysv/aix/sigsuspend.c (__sigsuspend): Likewise.
* sysdeps/unix/sysv/aix/statfs.c (__statfs): Likewise.
* sysdeps/unix/sysv/aix/select.c (__select): Likewise.
* sysdeps/unix/sysv/aix/setpgid.c (__setpgid): Likewise.
* sysdeps/unix/sysv/linux/alpha/pipe.S (__pipe): Likewise.
* sysdeps/unix/sysv/linux/alpha/syscalls.list (__GI___pwrite64,
__GI___statfs, __GI___send): Add.
* sysdeps/unix/sysv/linux/alpha/select.S (__select): Add
libc_hidden_ver resp. libc_hidden_def.
* sysdeps/unix/sysv/linux/alpha/sigsuspend.S (__sigsuspend): Add
libc_hidden_def.
* sysdeps/unix/sysv/linux/ia64/getpagesize.c (__getpagesize):
Likewise. Remove undef and INTDEF.
* sysdeps/unix/sysv/linux/ia64/pipe.S (__pipe): Add libc_hidden_def.
* sysdeps/unix/sysv/linux/ia64/syscalls.list (__GI___pwrite64,
__GI___statfs, __GI___send): Add.
* sysdeps/unix/sysv/linux/ia64/sigaction.c (__sigaction): Add
libc_hidden_def.
* sysdeps/unix/sysv/linux/ia64/sigsuspend.c (__sigsuspend):
Likewise.
* sysdeps/unix/sysv/linux/sh/pipe.S (__pipe): Likewise.
* sysdeps/unix/sysv/linux/s390/s390-32/chown.c (__chown): Add
libc_hidden_ver resp. libc_hidden_def.
* sysdeps/unix/sysv/linux/s390/s390-64/syscalls.list (__GI___pwrite64,
__GI___send): Add.
* sysdeps/unix/sysv/linux/s390/s390-64/sigaction.c (__sigaction):
Add libc_hidden_weak.
* sysdeps/unix/sysv/linux/s390/s390-64/sigsuspend.c (__sigsuspend):
Add libc_hidden_def.
* sysdeps/unix/sysv/linux/hppa/syscalls.list (__GI___send): Add.
* sysdeps/unix/sysv/linux/arm/sigaction.c (__sigaction): Add
libc_hidden_weak.
* sysdeps/unix/sysv/linux/i386/chown.c (__chown): Add libc_hidden_ver
resp. libc_hidden_def.
* sysdeps/unix/sysv/linux/i386/sigaction.c (__sigaction): Add
libc_hidden_weak.
* sysdeps/unix/sysv/linux/m68k/chown.c (__chown): Likewise. Remove
INTDEF.
* sysdeps/unix/sysv/linux/m68k/getpagesize.c (__getpagesize):
Likewise. Remove undef.
* sysdeps/unix/sysv/linux/mips/pwrite64.c (__pwrite64): Add
libc_hidden_weak.
* sysdeps/unix/sysv/linux/mips/syscalls.list (__GI___send): Add.
* sysdeps/unix/sysv/linux/mips/sigaction.c (__sigaction): Add
libc_hidden_weak.
* sysdeps/unix/sysv/linux/powerpc/chown.c (__chown): Add
libc_hidden_def.
* sysdeps/unix/sysv/linux/powerpc/pwrite64.c (__pwrite64): Likewise.
* sysdeps/unix/sysv/linux/sparc/sparc32/getpagesize.c (__getpagesize):
Likewise. Remove undef and INTDEF.
* sysdeps/unix/sysv/linux/sparc/sparc32/pipe.S (__pipe): Add
libc_hidden_def.
* sysdeps/unix/sysv/linux/sparc/sparc32/sigaction.c (__sigaction): Add
libc_hidden_weak.
* sysdeps/unix/sysv/linux/sparc/sparc64/pipe.S (__pipe): Add
libc_hidden_def.
* sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list
(__GI___pwrite64, __GI___statfs, __GI___select, __GI___send): Add.
* sysdeps/unix/sysv/linux/sparc/sparc64/sigaction.c (__sigaction): Add
libc_hidden_weak.
* sysdeps/unix/sysv/linux/sparc/sparc64/sigsuspend.c (__sigsuspend):
Add libc_hidden_def.
* sysdeps/unix/sysv/linux/x86_64/syscalls.list (__GI___pwrite64,
__GI___statfs): Add.
* sysdeps/unix/sysv/linux/x86_64/send.c (__send): Add
libc_hidden_weak.
* sysdeps/unix/sysv/linux/x86_64/sigaction.c (__sigaction): Likewise.
* sysdeps/unix/sysv/linux/getpagesize.c: Add libc_hidden_def.
Remove undef and INTDEF.
* sysdeps/unix/sysv/linux/poll.c (__poll): Add libc_hidden_def.
* sysdeps/unix/sysv/linux/pwrite64.c (__pwrite64): Add
libc_hidden_def.
* sysdeps/unix/sysv/linux/send.S (__send): Likewise.
* sysdeps/unix/sysv/linux/sigaction.c (__sigaction): Add
libc_hidden_weak.
* sysdeps/unix/sysv/linux/sigsuspend.c (__sigsuspend): Add
libc_hidden_def.
* sysdeps/unix/sysv/sco3.2.4/__setpgid.c (__setpgid): Likewise.
* sysdeps/unix/sysv/sco3.2.4/sigaction.S (__sigaction): Likewise.
* sysdeps/unix/sysv/sysv4/solaris2/syscalls.list (__GI___sigaction):
Add.
* sysdeps/unix/sysv/sysv4/__getpgid.c (__getpgid): Add
libc_hidden_def. Remove undef and INTDEF.
* sysdeps/unix/sysv/sysv4/getpgid.c (__getpgid): Likewise.
* sysdeps/unix/sysv/sysv4/__setpgid.c (__setpgid): Add
libc_hidden_def.
* sysdeps/unix/sysv/sysv4/setpgid.c (__setpgid): Likewise.
* sysdeps/unix/sysv/sysv4/sigaction.c (__sigaction): Likewise.
* sysdeps/unix/sysv/sigaction.c (__sigaction): Likewise.
* sysdeps/unix/getpagesize.c (__getpagesize): Add libc_hidden_def.
Remove undef and INTDEF.
* configure.in (HAVE_BROKEN_VISIBILITY_ATTRIBUTE): Add check for
broken visibility attribute handling.
* config.h.in (HAVE_BROKEN_VISIBILITY_ATTRIBUTE): Add.
2002-08-02 Ulrich Drepper <drepper@redhat.com>
2002-08-03 15:02:10 +08:00
|
|
|
libc_hidden_def (__res_ninit)
|
1999-12-05 02:05:55 +08:00
|
|
|
|
2017-06-19 19:19:00 +08:00
|
|
|
/* Return true if CH separates the netmask in the "sortlist"
|
|
|
|
directive. */
|
|
|
|
static inline bool
|
|
|
|
is_sort_mask (char ch)
|
|
|
|
{
|
|
|
|
return ch == '/' || ch == '&';
|
|
|
|
}
|
|
|
|
|
2017-07-01 02:19:10 +08:00
|
|
|
/* Array of name server addresses. */
|
|
|
|
#define DYNARRAY_STRUCT nameserver_list
|
|
|
|
#define DYNARRAY_ELEMENT const struct sockaddr *
|
|
|
|
#define DYNARRAY_ELEMENT_FREE(e) free ((struct sockaddr *) *(e))
|
|
|
|
#define DYNARRAY_INITIAL_SIZE 3
|
|
|
|
#define DYNARRAY_PREFIX nameserver_list_
|
|
|
|
#include <malloc/dynarray-skeleton.c>
|
|
|
|
|
2017-07-01 06:53:05 +08:00
|
|
|
/* Array of strings for the search array. The backing store is
|
|
|
|
managed separately. */
|
|
|
|
#define DYNARRAY_STRUCT search_list
|
|
|
|
#define DYNARRAY_ELEMENT const char *
|
2017-07-01 02:19:10 +08:00
|
|
|
#define DYNARRAY_INITIAL_SIZE 6
|
2017-07-01 06:53:05 +08:00
|
|
|
#define DYNARRAY_PREFIX search_list_
|
|
|
|
#include <malloc/dynarray-skeleton.c>
|
|
|
|
|
2017-07-01 02:19:10 +08:00
|
|
|
/* Array of name server addresses. */
|
|
|
|
#define DYNARRAY_STRUCT sort_list
|
|
|
|
#define DYNARRAY_ELEMENT struct resolv_sortlist_entry
|
|
|
|
#define DYNARRAY_INITIAL_SIZE 0
|
|
|
|
#define DYNARRAY_PREFIX sort_list_
|
|
|
|
#include <malloc/dynarray-skeleton.c>
|
|
|
|
|
2017-07-01 06:53:05 +08:00
|
|
|
/* resolv.conf parser state and results. */
|
|
|
|
struct resolv_conf_parser
|
|
|
|
{
|
|
|
|
char *buffer; /* Temporary buffer for reading lines. */
|
2017-07-01 02:19:10 +08:00
|
|
|
|
|
|
|
struct nameserver_list nameserver_list; /* Nameserver addresses. */
|
|
|
|
|
2017-07-01 06:53:05 +08:00
|
|
|
char *search_list_store; /* Backing storage for search list entries. */
|
|
|
|
struct search_list search_list; /* Points into search_list_store. */
|
2017-07-01 02:19:10 +08:00
|
|
|
|
|
|
|
struct sort_list sort_list; /* Address preference sorting list. */
|
|
|
|
|
|
|
|
/* Configuration template. The non-array elements are filled in
|
|
|
|
directly. The array elements are updated prior to the call to
|
|
|
|
__resolv_conf_attach. */
|
|
|
|
struct resolv_conf template;
|
2017-07-01 06:53:05 +08:00
|
|
|
};
|
|
|
|
|
2017-07-04 03:06:23 +08:00
|
|
|
/* Return true if *PREINIT contains actual preinitialization. */
|
|
|
|
static bool
|
|
|
|
has_preinit_values (const struct __res_state *preinit)
|
|
|
|
{
|
|
|
|
return (preinit->retrans != 0 && preinit->retrans != RES_TIMEOUT)
|
|
|
|
|| (preinit->retry != 0 && preinit->retry != RES_DFLRETRY)
|
|
|
|
|| (preinit->options != 0
|
|
|
|
&& (preinit->options & ~RES_INIT) != RES_DEFAULT);
|
|
|
|
}
|
|
|
|
|
2017-07-01 06:53:05 +08:00
|
|
|
static void
|
2017-07-01 02:19:10 +08:00
|
|
|
resolv_conf_parser_init (struct resolv_conf_parser *parser,
|
|
|
|
const struct __res_state *preinit)
|
2017-07-01 06:53:05 +08:00
|
|
|
{
|
|
|
|
parser->buffer = NULL;
|
|
|
|
parser->search_list_store = NULL;
|
2017-07-01 02:19:10 +08:00
|
|
|
nameserver_list_init (&parser->nameserver_list);
|
2017-07-01 06:53:05 +08:00
|
|
|
search_list_init (&parser->search_list);
|
2017-07-01 02:19:10 +08:00
|
|
|
sort_list_init (&parser->sort_list);
|
|
|
|
|
|
|
|
if (preinit != NULL)
|
|
|
|
{
|
|
|
|
parser->template.retrans = preinit->retrans;
|
|
|
|
parser->template.retry = preinit->retry;
|
|
|
|
parser->template.options = preinit->options | RES_INIT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
parser->template.retrans = RES_TIMEOUT;
|
|
|
|
parser->template.retry = RES_DFLRETRY;
|
|
|
|
parser->template.options = RES_DEFAULT | RES_INIT;
|
|
|
|
}
|
|
|
|
parser->template.ndots = 1;
|
2017-07-01 06:53:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
resolv_conf_parser_free (struct resolv_conf_parser *parser)
|
|
|
|
{
|
|
|
|
free (parser->buffer);
|
|
|
|
free (parser->search_list_store);
|
2017-07-01 02:19:10 +08:00
|
|
|
nameserver_list_free (&parser->nameserver_list);
|
2017-07-01 06:53:05 +08:00
|
|
|
search_list_free (&parser->search_list);
|
2017-07-01 02:19:10 +08:00
|
|
|
sort_list_free (&parser->sort_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate a struct sockaddr_in object on the heap, with the
|
|
|
|
specified address and port. */
|
|
|
|
static struct sockaddr *
|
|
|
|
allocate_address_v4 (struct in_addr a, uint16_t port)
|
|
|
|
{
|
|
|
|
struct sockaddr_in *sa4 = malloc (sizeof (*sa4));
|
|
|
|
if (sa4 == NULL)
|
|
|
|
return NULL;
|
|
|
|
sa4->sin_family = AF_INET;
|
|
|
|
sa4->sin_addr = a;
|
|
|
|
sa4->sin_port = htons (port);
|
|
|
|
return (struct sockaddr *) sa4;
|
2017-07-01 06:53:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to obtain the domain name from the host name and store it in
|
|
|
|
*RESULT. Return false on memory allocation failure. If the domain
|
|
|
|
name cannot be determined for any other reason, write NULL to
|
|
|
|
*RESULT and return true. */
|
|
|
|
static bool
|
|
|
|
domain_from_hostname (char **result)
|
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
/* gethostbyname may not terminate the buffer. */
|
|
|
|
buf[sizeof (buf) - 1] = '\0';
|
|
|
|
if (__gethostname (buf, sizeof (buf) - 1) == 0)
|
|
|
|
{
|
|
|
|
char *dot = strchr (buf, '.');
|
|
|
|
if (dot != NULL)
|
|
|
|
{
|
|
|
|
*result = __strdup (dot + 1);
|
|
|
|
if (*result == NULL)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*result = NULL;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-07-01 02:19:10 +08:00
|
|
|
static void res_setoptions (struct resolv_conf_parser *, const char *options);
|
|
|
|
|
2017-06-19 20:05:49 +08:00
|
|
|
/* Internal helper function for __res_vinit, to aid with resource
|
|
|
|
deallocation and error handling. Return true on success, false on
|
|
|
|
failure. */
|
|
|
|
static bool
|
2017-07-01 02:19:10 +08:00
|
|
|
res_vinit_1 (FILE *fp, struct resolv_conf_parser *parser)
|
2017-06-19 19:20:46 +08:00
|
|
|
{
|
2017-07-01 06:53:05 +08:00
|
|
|
char *cp;
|
2017-06-17 02:54:43 +08:00
|
|
|
size_t buffer_size = 0;
|
2017-06-19 19:20:46 +08:00
|
|
|
bool haveenv = false;
|
1995-02-18 09:27:10 +08:00
|
|
|
|
2017-06-19 19:20:46 +08:00
|
|
|
/* Allow user to override the local domain definition. */
|
|
|
|
if ((cp = getenv ("LOCALDOMAIN")) != NULL)
|
|
|
|
{
|
2017-07-01 06:53:05 +08:00
|
|
|
/* The code below splits the string in place. */
|
|
|
|
cp = __strdup (cp);
|
|
|
|
if (cp == NULL)
|
|
|
|
return false;
|
|
|
|
free (parser->search_list_store);
|
|
|
|
parser->search_list_store = cp;
|
2017-06-19 19:20:46 +08:00
|
|
|
haveenv = true;
|
1995-02-18 09:27:10 +08:00
|
|
|
|
2017-07-01 06:53:05 +08:00
|
|
|
/* The string will be truncated as needed below. */
|
|
|
|
search_list_add (&parser->search_list, cp);
|
|
|
|
|
2017-06-19 19:20:46 +08:00
|
|
|
/* Set search list to be blank-separated strings from rest of
|
|
|
|
env value. Permits users of LOCALDOMAIN to still have a
|
|
|
|
search list, and anyone to set the one that they want to use
|
|
|
|
as an individual (even more important now that the rfc1535
|
|
|
|
stuff restricts searches). */
|
2017-07-01 06:53:05 +08:00
|
|
|
for (bool in_name = true; *cp != '\0'; cp++)
|
2017-06-19 19:20:46 +08:00
|
|
|
{
|
|
|
|
if (*cp == '\n')
|
2017-07-01 06:53:05 +08:00
|
|
|
{
|
|
|
|
*cp = '\0';
|
|
|
|
break;
|
|
|
|
}
|
2017-06-19 19:20:46 +08:00
|
|
|
else if (*cp == ' ' || *cp == '\t')
|
|
|
|
{
|
2017-07-01 06:53:05 +08:00
|
|
|
*cp = '\0';
|
|
|
|
in_name = false;
|
2017-06-19 19:20:46 +08:00
|
|
|
}
|
2017-07-01 06:53:05 +08:00
|
|
|
else if (!in_name)
|
2017-06-19 19:20:46 +08:00
|
|
|
{
|
2017-07-01 06:53:05 +08:00
|
|
|
search_list_add (&parser->search_list, cp);
|
|
|
|
in_name = true;
|
2017-06-19 19:20:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1995-02-18 09:27:10 +08:00
|
|
|
|
2017-06-19 19:20:46 +08:00
|
|
|
#define MATCH(line, name) \
|
2017-06-17 02:54:43 +08:00
|
|
|
(!strncmp ((line), name, sizeof (name) - 1) \
|
|
|
|
&& ((line)[sizeof (name) - 1] == ' ' \
|
|
|
|
|| (line)[sizeof (name) - 1] == '\t'))
|
1995-02-18 09:27:10 +08:00
|
|
|
|
2017-06-19 19:20:46 +08:00
|
|
|
if (fp != NULL)
|
|
|
|
{
|
|
|
|
/* No threads use this stream. */
|
|
|
|
__fsetlocking (fp, FSETLOCKING_BYCALLER);
|
|
|
|
/* Read the config file. */
|
2017-06-17 02:54:43 +08:00
|
|
|
while (true)
|
2017-06-19 19:20:46 +08:00
|
|
|
{
|
2017-06-17 02:54:43 +08:00
|
|
|
{
|
2017-07-01 06:53:05 +08:00
|
|
|
ssize_t ret = __getline (&parser->buffer, &buffer_size, fp);
|
2017-06-17 02:54:43 +08:00
|
|
|
if (ret <= 0)
|
|
|
|
{
|
|
|
|
if (_IO_ferror_unlocked (fp))
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-19 19:20:46 +08:00
|
|
|
/* Skip comments. */
|
2017-07-01 06:53:05 +08:00
|
|
|
if (*parser->buffer == ';' || *parser->buffer == '#')
|
2017-06-19 19:20:46 +08:00
|
|
|
continue;
|
|
|
|
/* Read default domain name. */
|
2017-07-01 06:53:05 +08:00
|
|
|
if (MATCH (parser->buffer, "domain"))
|
2017-06-19 19:20:46 +08:00
|
|
|
{
|
|
|
|
if (haveenv)
|
|
|
|
/* LOCALDOMAIN overrides the configuration file. */
|
|
|
|
continue;
|
2017-07-01 06:53:05 +08:00
|
|
|
cp = parser->buffer + sizeof ("domain") - 1;
|
2017-06-19 19:20:46 +08:00
|
|
|
while (*cp == ' ' || *cp == '\t')
|
|
|
|
cp++;
|
|
|
|
if ((*cp == '\0') || (*cp == '\n'))
|
|
|
|
continue;
|
2017-07-01 06:53:05 +08:00
|
|
|
|
|
|
|
cp = __strdup (cp);
|
|
|
|
if (cp == NULL)
|
|
|
|
return false;
|
|
|
|
free (parser->search_list_store);
|
|
|
|
parser->search_list_store = cp;
|
|
|
|
search_list_clear (&parser->search_list);
|
|
|
|
search_list_add (&parser->search_list, cp);
|
|
|
|
/* Replace trailing whitespace. */
|
|
|
|
if ((cp = strpbrk (cp, " \t\n")) != NULL)
|
2017-06-19 19:20:46 +08:00
|
|
|
*cp = '\0';
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* Set search list. */
|
2017-07-01 06:53:05 +08:00
|
|
|
if (MATCH (parser->buffer, "search"))
|
2017-06-19 19:20:46 +08:00
|
|
|
{
|
|
|
|
if (haveenv)
|
|
|
|
/* LOCALDOMAIN overrides the configuration file. */
|
|
|
|
continue;
|
2017-07-01 06:53:05 +08:00
|
|
|
cp = parser->buffer + sizeof ("search") - 1;
|
2017-06-19 19:20:46 +08:00
|
|
|
while (*cp == ' ' || *cp == '\t')
|
|
|
|
cp++;
|
|
|
|
if ((*cp == '\0') || (*cp == '\n'))
|
|
|
|
continue;
|
2017-07-01 06:53:05 +08:00
|
|
|
|
|
|
|
{
|
|
|
|
char *p = strchr (cp, '\n');
|
|
|
|
if (p != NULL)
|
|
|
|
*p = '\0';
|
|
|
|
}
|
|
|
|
cp = __strdup (cp);
|
|
|
|
if (cp == NULL)
|
|
|
|
return false;
|
|
|
|
free (parser->search_list_store);
|
|
|
|
parser->search_list_store = cp;
|
|
|
|
|
|
|
|
/* The string is truncated below. */
|
|
|
|
search_list_clear (&parser->search_list);
|
|
|
|
search_list_add (&parser->search_list, cp);
|
|
|
|
|
2017-06-19 19:20:46 +08:00
|
|
|
/* Set search list to be blank-separated strings on rest
|
|
|
|
of line. */
|
2017-07-01 06:53:05 +08:00
|
|
|
for (bool in_name = true; *cp != '\0'; cp++)
|
2017-06-19 19:20:46 +08:00
|
|
|
{
|
|
|
|
if (*cp == ' ' || *cp == '\t')
|
|
|
|
{
|
2017-07-01 06:53:05 +08:00
|
|
|
*cp = '\0';
|
|
|
|
in_name = false;
|
2017-06-19 19:20:46 +08:00
|
|
|
}
|
2017-07-01 06:53:05 +08:00
|
|
|
else if (!in_name)
|
2017-06-19 19:20:46 +08:00
|
|
|
{
|
2017-07-01 06:53:05 +08:00
|
|
|
search_list_add (&parser->search_list, cp);
|
|
|
|
in_name = true;
|
2017-06-19 19:20:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* Read nameservers to query. */
|
2017-07-01 02:19:10 +08:00
|
|
|
if (MATCH (parser->buffer, "nameserver"))
|
2017-06-19 19:20:46 +08:00
|
|
|
{
|
|
|
|
struct in_addr a;
|
1995-02-18 09:27:10 +08:00
|
|
|
|
2017-07-01 06:53:05 +08:00
|
|
|
cp = parser->buffer + sizeof ("nameserver") - 1;
|
2017-06-19 19:20:46 +08:00
|
|
|
while (*cp == ' ' || *cp == '\t')
|
|
|
|
cp++;
|
2019-01-22 04:26:03 +08:00
|
|
|
|
|
|
|
/* Ignore trailing contents on the name server line. */
|
|
|
|
{
|
|
|
|
char *el;
|
|
|
|
if ((el = strpbrk (cp, " \t\n")) != NULL)
|
|
|
|
*el = '\0';
|
|
|
|
}
|
|
|
|
|
2017-07-01 02:19:10 +08:00
|
|
|
struct sockaddr *sa;
|
2019-01-22 04:26:03 +08:00
|
|
|
if ((*cp != '\0') && (*cp != '\n') && __inet_aton_exact (cp, &a))
|
2017-06-19 19:20:46 +08:00
|
|
|
{
|
2017-07-01 02:19:10 +08:00
|
|
|
sa = allocate_address_v4 (a, NAMESERVER_PORT);
|
|
|
|
if (sa == NULL)
|
|
|
|
return false;
|
2017-06-19 19:20:46 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct in6_addr a6;
|
|
|
|
char *el;
|
|
|
|
if ((el = strchr (cp, SCOPE_DELIMITER)) != NULL)
|
|
|
|
*el = '\0';
|
|
|
|
if ((*cp != '\0') && (__inet_pton (AF_INET6, cp, &a6) > 0))
|
|
|
|
{
|
|
|
|
struct sockaddr_in6 *sa6;
|
2010-08-25 22:43:53 +08:00
|
|
|
|
2017-06-19 19:20:46 +08:00
|
|
|
sa6 = malloc (sizeof (*sa6));
|
2017-06-19 20:05:49 +08:00
|
|
|
if (sa6 == NULL)
|
2017-06-17 02:54:43 +08:00
|
|
|
return false;
|
2008-04-08 01:20:25 +08:00
|
|
|
|
2017-06-19 20:05:49 +08:00
|
|
|
sa6->sin6_family = AF_INET6;
|
|
|
|
sa6->sin6_port = htons (NAMESERVER_PORT);
|
|
|
|
sa6->sin6_flowinfo = 0;
|
|
|
|
sa6->sin6_addr = a6;
|
2008-04-08 01:20:25 +08:00
|
|
|
|
2017-06-19 20:05:49 +08:00
|
|
|
sa6->sin6_scope_id = 0;
|
|
|
|
if (__glibc_likely (el != NULL))
|
|
|
|
/* Ignore errors, for backwards
|
|
|
|
compatibility. */
|
|
|
|
__inet6_scopeid_pton
|
|
|
|
(&a6, el + 1, &sa6->sin6_scope_id);
|
2017-07-01 02:19:10 +08:00
|
|
|
sa = (struct sockaddr *) sa6;
|
2017-06-19 19:20:46 +08:00
|
|
|
}
|
2017-07-01 02:19:10 +08:00
|
|
|
else
|
|
|
|
/* IPv6 address parse failure. */
|
|
|
|
sa = NULL;
|
|
|
|
}
|
|
|
|
if (sa != NULL)
|
|
|
|
{
|
|
|
|
const struct sockaddr **p = nameserver_list_emplace
|
|
|
|
(&parser->nameserver_list);
|
|
|
|
if (p != NULL)
|
|
|
|
*p = sa;
|
2017-09-06 21:20:25 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
free (sa);
|
|
|
|
return false;
|
|
|
|
}
|
2017-06-19 19:20:46 +08:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2017-07-01 06:53:05 +08:00
|
|
|
if (MATCH (parser->buffer, "sortlist"))
|
2017-06-19 19:20:46 +08:00
|
|
|
{
|
|
|
|
struct in_addr a;
|
1995-02-18 09:27:10 +08:00
|
|
|
|
2017-07-01 06:53:05 +08:00
|
|
|
cp = parser->buffer + sizeof ("sortlist") - 1;
|
2017-07-01 02:19:10 +08:00
|
|
|
while (true)
|
2017-06-19 19:20:46 +08:00
|
|
|
{
|
|
|
|
while (*cp == ' ' || *cp == '\t')
|
|
|
|
cp++;
|
|
|
|
if (*cp == '\0' || *cp == '\n' || *cp == ';')
|
|
|
|
break;
|
2017-07-01 02:19:10 +08:00
|
|
|
char *net = cp;
|
2017-06-19 19:20:46 +08:00
|
|
|
while (*cp && !is_sort_mask (*cp) && *cp != ';'
|
|
|
|
&& isascii (*cp) && !isspace (*cp))
|
|
|
|
cp++;
|
|
|
|
char separator = *cp;
|
|
|
|
*cp = 0;
|
2017-07-01 02:19:10 +08:00
|
|
|
struct resolv_sortlist_entry e;
|
2019-01-22 04:26:03 +08:00
|
|
|
if (__inet_aton_exact (net, &a))
|
2017-06-19 19:20:46 +08:00
|
|
|
{
|
2017-07-01 02:19:10 +08:00
|
|
|
e.addr = a;
|
2017-06-19 19:20:46 +08:00
|
|
|
if (is_sort_mask (separator))
|
|
|
|
{
|
|
|
|
*cp++ = separator;
|
|
|
|
net = cp;
|
|
|
|
while (*cp && *cp != ';'
|
|
|
|
&& isascii (*cp) && !isspace (*cp))
|
|
|
|
cp++;
|
|
|
|
separator = *cp;
|
|
|
|
*cp = 0;
|
2019-01-22 04:26:03 +08:00
|
|
|
if (__inet_aton_exact (net, &a))
|
2017-07-01 02:19:10 +08:00
|
|
|
e.mask = a.s_addr;
|
2017-06-19 19:20:46 +08:00
|
|
|
else
|
2017-07-01 02:19:10 +08:00
|
|
|
e.mask = net_mask (e.addr);
|
2017-06-19 19:20:46 +08:00
|
|
|
}
|
|
|
|
else
|
2017-07-01 02:19:10 +08:00
|
|
|
e.mask = net_mask (e.addr);
|
|
|
|
sort_list_add (&parser->sort_list, e);
|
2017-06-19 19:20:46 +08:00
|
|
|
}
|
|
|
|
*cp = separator;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2017-07-01 06:53:05 +08:00
|
|
|
if (MATCH (parser->buffer, "options"))
|
2017-06-19 19:20:46 +08:00
|
|
|
{
|
2017-07-01 02:19:10 +08:00
|
|
|
res_setoptions (parser, parser->buffer + sizeof ("options") - 1);
|
2017-06-19 19:20:46 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-01 02:19:10 +08:00
|
|
|
if (__glibc_unlikely (nameserver_list_size (&parser->nameserver_list) == 0))
|
2017-06-19 19:20:46 +08:00
|
|
|
{
|
2017-07-01 02:19:10 +08:00
|
|
|
const struct sockaddr **p
|
|
|
|
= nameserver_list_emplace (&parser->nameserver_list);
|
|
|
|
if (p == NULL)
|
|
|
|
return false;
|
|
|
|
*p = allocate_address_v4 (__inet_makeaddr (IN_LOOPBACKNET, 1),
|
|
|
|
NAMESERVER_PORT);
|
|
|
|
if (*p == NULL)
|
|
|
|
return false;
|
2017-06-19 19:20:46 +08:00
|
|
|
}
|
1995-02-18 09:27:10 +08:00
|
|
|
|
2017-07-01 06:53:05 +08:00
|
|
|
if (search_list_size (&parser->search_list) == 0)
|
2017-06-19 19:20:46 +08:00
|
|
|
{
|
2017-07-01 06:53:05 +08:00
|
|
|
char *domain;
|
|
|
|
if (!domain_from_hostname (&domain))
|
|
|
|
return false;
|
|
|
|
if (domain != NULL)
|
|
|
|
{
|
|
|
|
free (parser->search_list_store);
|
|
|
|
parser->search_list_store = domain;
|
|
|
|
search_list_add (&parser->search_list, domain);
|
|
|
|
}
|
2017-06-19 19:20:46 +08:00
|
|
|
}
|
1995-02-18 09:27:10 +08:00
|
|
|
|
2017-06-19 19:20:46 +08:00
|
|
|
if ((cp = getenv ("RES_OPTIONS")) != NULL)
|
2017-07-01 02:19:10 +08:00
|
|
|
res_setoptions (parser, cp);
|
2017-07-01 06:53:05 +08:00
|
|
|
|
2017-07-01 02:19:10 +08:00
|
|
|
if (nameserver_list_has_failed (&parser->nameserver_list)
|
|
|
|
|| search_list_has_failed (&parser->search_list)
|
|
|
|
|| sort_list_has_failed (&parser->sort_list))
|
2017-07-01 06:53:05 +08:00
|
|
|
{
|
|
|
|
__set_errno (ENOMEM);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-06-17 02:54:43 +08:00
|
|
|
return true;
|
1995-02-18 09:27:10 +08:00
|
|
|
}
|
|
|
|
|
2017-07-04 03:06:23 +08:00
|
|
|
struct resolv_conf *
|
2020-01-22 00:25:39 +08:00
|
|
|
__resolv_conf_load (struct __res_state *preinit,
|
|
|
|
struct file_change_detection *change)
|
2017-06-19 20:05:49 +08:00
|
|
|
{
|
2017-06-27 15:26:46 +08:00
|
|
|
/* Ensure that /etc/hosts.conf has been loaded (once). */
|
|
|
|
_res_hconf_init ();
|
|
|
|
|
2017-06-19 20:05:49 +08:00
|
|
|
FILE *fp = fopen (_PATH_RESCONF, "rce");
|
|
|
|
if (fp == NULL)
|
|
|
|
switch (errno)
|
|
|
|
{
|
|
|
|
case EACCES:
|
|
|
|
case EISDIR:
|
|
|
|
case ELOOP:
|
|
|
|
case ENOENT:
|
|
|
|
case ENOTDIR:
|
|
|
|
case EPERM:
|
|
|
|
/* Ignore these errors. They are persistent errors caused
|
|
|
|
by file system contents. */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Other errors refer to resource allocation problems and
|
|
|
|
need to be handled by the application. */
|
2017-07-04 03:06:23 +08:00
|
|
|
return NULL;
|
2017-06-19 20:05:49 +08:00
|
|
|
}
|
2017-06-17 02:54:43 +08:00
|
|
|
|
2017-07-01 06:53:05 +08:00
|
|
|
struct resolv_conf_parser parser;
|
2017-07-04 03:06:23 +08:00
|
|
|
resolv_conf_parser_init (&parser, preinit);
|
2017-06-17 02:54:43 +08:00
|
|
|
|
2017-07-04 03:06:23 +08:00
|
|
|
struct resolv_conf *conf = NULL;
|
2020-01-22 00:25:39 +08:00
|
|
|
bool ok = res_vinit_1 (fp, &parser);
|
|
|
|
if (ok && change != NULL)
|
|
|
|
/* Update the file change information if the configuration was
|
|
|
|
loaded successfully. */
|
2020-02-18 20:44:48 +08:00
|
|
|
ok = __file_change_detection_for_fp (change, fp);
|
2020-01-22 00:25:39 +08:00
|
|
|
|
|
|
|
if (ok)
|
2017-07-04 02:31:23 +08:00
|
|
|
{
|
2017-07-01 02:19:10 +08:00
|
|
|
parser.template.nameserver_list
|
|
|
|
= nameserver_list_begin (&parser.nameserver_list);
|
|
|
|
parser.template.nameserver_list_size
|
|
|
|
= nameserver_list_size (&parser.nameserver_list);
|
|
|
|
parser.template.search_list = search_list_begin (&parser.search_list);
|
|
|
|
parser.template.search_list_size
|
|
|
|
= search_list_size (&parser.search_list);
|
|
|
|
parser.template.sort_list = sort_list_begin (&parser.sort_list);
|
|
|
|
parser.template.sort_list_size = sort_list_size (&parser.sort_list);
|
2017-07-04 03:06:23 +08:00
|
|
|
conf = __resolv_conf_allocate (&parser.template);
|
2017-07-04 02:31:23 +08:00
|
|
|
}
|
2017-07-01 06:53:05 +08:00
|
|
|
resolv_conf_parser_free (&parser);
|
2017-07-04 02:31:23 +08:00
|
|
|
|
2020-01-22 00:11:01 +08:00
|
|
|
if (fp != NULL)
|
|
|
|
{
|
|
|
|
int saved_errno = errno;
|
|
|
|
fclose (fp);
|
|
|
|
__set_errno (saved_errno);
|
|
|
|
}
|
|
|
|
|
2017-07-04 03:06:23 +08:00
|
|
|
return conf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up default settings. If the /etc/resolv.conf configuration
|
|
|
|
file exist, the values there will have precedence. Otherwise, the
|
|
|
|
server address is set to INADDR_LOOPBACK and the default domain
|
|
|
|
name comes from gethostname. The RES_OPTIONS and LOCALDOMAIN
|
|
|
|
environment variables can be used to override some settings.
|
|
|
|
Return 0 if completes successfully, -1 on error. */
|
|
|
|
int
|
|
|
|
__res_vinit (res_state statp, int preinit)
|
|
|
|
{
|
|
|
|
struct resolv_conf *conf;
|
|
|
|
if (preinit && has_preinit_values (statp))
|
|
|
|
/* For the preinit case, we cannot use the cached configuration
|
|
|
|
because some settings could be different. */
|
2020-01-22 00:25:39 +08:00
|
|
|
conf = __resolv_conf_load (statp, NULL);
|
2017-07-04 03:06:23 +08:00
|
|
|
else
|
|
|
|
conf = __resolv_conf_get_current ();
|
|
|
|
if (conf == NULL)
|
2017-07-01 02:19:10 +08:00
|
|
|
return -1;
|
2017-07-04 03:06:23 +08:00
|
|
|
|
|
|
|
bool ok = __resolv_conf_attach (statp, conf);
|
|
|
|
__resolv_conf_put (conf);
|
|
|
|
if (ok)
|
|
|
|
{
|
|
|
|
if (preinit)
|
|
|
|
statp->id = res_randomid ();
|
|
|
|
return 0;
|
|
|
|
}
|
2017-07-01 02:19:10 +08:00
|
|
|
else
|
2017-07-04 03:06:23 +08:00
|
|
|
return -1;
|
2017-06-19 20:05:49 +08:00
|
|
|
}
|
|
|
|
|
1995-02-18 09:27:10 +08:00
|
|
|
static void
|
2017-07-01 02:19:10 +08:00
|
|
|
res_setoptions (struct resolv_conf_parser *parser, const char *options)
|
2017-06-19 19:20:46 +08:00
|
|
|
{
|
|
|
|
const char *cp = options;
|
1995-02-18 09:27:10 +08:00
|
|
|
|
2017-06-19 19:20:46 +08:00
|
|
|
while (*cp)
|
|
|
|
{
|
|
|
|
/* Skip leading and inner runs of spaces. */
|
|
|
|
while (*cp == ' ' || *cp == '\t')
|
|
|
|
cp++;
|
|
|
|
/* Search for and process individual options. */
|
|
|
|
if (!strncmp (cp, "ndots:", sizeof ("ndots:") - 1))
|
|
|
|
{
|
|
|
|
int i = atoi (cp + sizeof ("ndots:") - 1);
|
|
|
|
if (i <= RES_MAXNDOTS)
|
2017-07-01 02:19:10 +08:00
|
|
|
parser->template.ndots = i;
|
2017-06-19 19:20:46 +08:00
|
|
|
else
|
2017-07-01 02:19:10 +08:00
|
|
|
parser->template.ndots = RES_MAXNDOTS;
|
2017-06-19 19:20:46 +08:00
|
|
|
}
|
|
|
|
else if (!strncmp (cp, "timeout:", sizeof ("timeout:") - 1))
|
|
|
|
{
|
|
|
|
int i = atoi (cp + sizeof ("timeout:") - 1);
|
|
|
|
if (i <= RES_MAXRETRANS)
|
2017-07-01 02:19:10 +08:00
|
|
|
parser->template.retrans = i;
|
2017-06-19 19:20:46 +08:00
|
|
|
else
|
2017-07-01 02:19:10 +08:00
|
|
|
parser->template.retrans = RES_MAXRETRANS;
|
2017-06-19 19:20:46 +08:00
|
|
|
}
|
|
|
|
else if (!strncmp (cp, "attempts:", sizeof ("attempts:") - 1))
|
|
|
|
{
|
|
|
|
int i = atoi (cp + sizeof ("attempts:") - 1);
|
|
|
|
if (i <= RES_MAXRETRY)
|
2017-07-01 02:19:10 +08:00
|
|
|
parser->template.retry = i;
|
2017-06-19 19:20:46 +08:00
|
|
|
else
|
2017-07-01 02:19:10 +08:00
|
|
|
parser->template.retry = RES_MAXRETRY;
|
2017-06-19 19:20:46 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
char str[22];
|
|
|
|
uint8_t len;
|
|
|
|
uint8_t clear;
|
|
|
|
unsigned long int flag;
|
|
|
|
} options[] = {
|
2011-05-30 10:07:49 +08:00
|
|
|
#define STRnLEN(str) str, sizeof (str) - 1
|
2017-06-19 19:20:46 +08:00
|
|
|
{ STRnLEN ("rotate"), 0, RES_ROTATE },
|
|
|
|
{ STRnLEN ("edns0"), 0, RES_USE_EDNS0 },
|
|
|
|
{ STRnLEN ("single-request-reopen"), 0, RES_SNGLKUPREOP },
|
|
|
|
{ STRnLEN ("single-request"), 0, RES_SNGLKUP },
|
|
|
|
{ STRnLEN ("no_tld_query"), 0, RES_NOTLDQUERY },
|
|
|
|
{ STRnLEN ("no-tld-query"), 0, RES_NOTLDQUERY },
|
2017-07-04 03:06:23 +08:00
|
|
|
{ STRnLEN ("no-reload"), 0, RES_NORELOAD },
|
2019-10-31 00:26:58 +08:00
|
|
|
{ STRnLEN ("use-vc"), 0, RES_USEVC },
|
|
|
|
{ STRnLEN ("trust-ad"), 0, RES_TRUSTAD },
|
2017-06-19 19:20:46 +08:00
|
|
|
};
|
2011-05-30 10:07:49 +08:00
|
|
|
#define noptions (sizeof (options) / sizeof (options[0]))
|
2017-06-19 19:20:46 +08:00
|
|
|
for (int i = 0; i < noptions; ++i)
|
|
|
|
if (strncmp (cp, options[i].str, options[i].len) == 0)
|
|
|
|
{
|
|
|
|
if (options[i].clear)
|
2017-07-01 02:19:10 +08:00
|
|
|
parser->template.options &= options[i].flag;
|
2017-06-19 19:20:46 +08:00
|
|
|
else
|
2017-07-01 02:19:10 +08:00
|
|
|
parser->template.options |= options[i].flag;
|
2017-06-19 19:20:46 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Skip to next run of spaces. */
|
|
|
|
while (*cp && *cp != ' ' && *cp != '\t')
|
|
|
|
cp++;
|
|
|
|
}
|
1995-02-18 09:27:10 +08:00
|
|
|
}
|
|
|
|
|
2017-06-19 19:20:46 +08:00
|
|
|
static uint32_t
|
2015-10-21 19:57:23 +08:00
|
|
|
net_mask (struct in_addr in)
|
1995-02-18 09:27:10 +08:00
|
|
|
{
|
2017-06-19 19:20:46 +08:00
|
|
|
uint32_t i = ntohl (in.s_addr);
|
1995-02-18 09:27:10 +08:00
|
|
|
|
2017-06-19 19:20:46 +08:00
|
|
|
if (IN_CLASSA (i))
|
|
|
|
return htonl (IN_CLASSA_NET);
|
|
|
|
else if (IN_CLASSB (i))
|
|
|
|
return htonl (IN_CLASSB_NET);
|
|
|
|
return htonl (IN_CLASSC_NET);
|
1995-02-18 09:27:10 +08:00
|
|
|
}
|