2020-01-01 00:14:33 +00:00
|
|
|
/* Copyright (C) 1998-2020 Free Software Foundation, Inc.
|
1998-10-18 15:16:22 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 04:58:11 +00:00
|
|
|
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.
|
1998-10-18 15:16:22 +00:00
|
|
|
|
|
|
|
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
|
2001-07-06 04:58:11 +00:00
|
|
|
Lesser General Public License for more details.
|
1998-10-18 15:16:22 +00:00
|
|
|
|
2001-07-06 04:58:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-09 23:18:22 +00:00
|
|
|
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 05:40:42 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
1998-10-18 15:16:22 +00:00
|
|
|
|
|
|
|
#include <errno.h>
|
2016-10-04 09:52:10 +00:00
|
|
|
#include <resolv/resolv-internal.h>
|
1998-10-18 15:16:22 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2013-05-01 15:46:34 +00:00
|
|
|
#include <stdint.h>
|
1998-10-18 15:16:22 +00:00
|
|
|
#include <arpa/nameser.h>
|
2004-06-06 06:06:02 +00:00
|
|
|
#include <not-cancel.h>
|
1998-10-18 15:16:22 +00:00
|
|
|
|
1998-10-19 00:40:00 +00:00
|
|
|
#include "nscd-client.h"
|
1998-10-18 15:16:22 +00:00
|
|
|
#include "nscd_proto.h"
|
|
|
|
|
|
|
|
int __nss_not_use_nscd_hosts;
|
|
|
|
|
|
|
|
static int nscd_gethst_r (const char *key, size_t keylen, request_type type,
|
|
|
|
struct hostent *resultbuf, char *buffer,
|
2004-02-27 00:55:39 +00:00
|
|
|
size_t buflen, struct hostent **result,
|
2017-08-31 13:56:32 +00:00
|
|
|
int *h_errnop);
|
1998-10-18 15:16:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
__nscd_gethostbyname_r (const char *name, struct hostent *resultbuf,
|
2004-02-27 00:55:39 +00:00
|
|
|
char *buffer, size_t buflen, struct hostent **result,
|
|
|
|
int *h_errnop)
|
1998-10-18 15:16:22 +00:00
|
|
|
{
|
2019-04-08 08:40:31 +00:00
|
|
|
return nscd_gethst_r (name, strlen (name) + 1, GETHOSTBYNAME, resultbuf,
|
2004-02-27 00:55:39 +00:00
|
|
|
buffer, buflen, result, h_errnop);
|
1998-10-18 15:16:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
__nscd_gethostbyname2_r (const char *name, int af, struct hostent *resultbuf,
|
2004-02-27 00:55:39 +00:00
|
|
|
char *buffer, size_t buflen, struct hostent **result,
|
|
|
|
int *h_errnop)
|
1998-10-18 15:16:22 +00:00
|
|
|
{
|
|
|
|
request_type reqtype;
|
|
|
|
|
|
|
|
reqtype = af == AF_INET6 ? GETHOSTBYNAMEv6 : GETHOSTBYNAME;
|
|
|
|
|
|
|
|
return nscd_gethst_r (name, strlen (name) + 1, reqtype, resultbuf,
|
2004-02-27 00:55:39 +00:00
|
|
|
buffer, buflen, result, h_errnop);
|
1998-10-18 15:16:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
Update.
* conform/conformtest.pl (@headers): Add sys/utsname.h, sys/un.h,
sys/socket.h, spawn.h, netinet/tcp.h, netinet/in.h, net/if.h, and
arpa/inet.h.
* conform/data/fcntl.h-data: Add F_GETOWN, F_SETOWN,
SEEK_SET, SEEK_CUR, SEEK_END, S_IFMT, S_IFBLK, S_IFCHR, S_IFIFO,
S_IFREG, S_IFDIR, S_IFLNK, S_IFSOCK, S_IRWXU, S_IRUSR S_IWUSR,
S_IXUSR, S_IRWXG, S_IRGRP, S_IWGRP, S_IXGRP, S_IRWXO, S_IROTH,
S_IWOTH, S_IXOTH, S_ISUID, S_ISGID, S_ISVTX, POSIX_FADV_NORMAL,
POSIX_FADV_SEQUENTIAL, POSIX_FADV_RANDOM, POSIX_FADV_WILLNEED,
POSIX_FADV_DONTNEED, POSIX_FADV_NOREUSE, posix_fadvise,
posix_fallocate, and posix_madvise.
* conform/data/netdb.h-data: New file.
* conform/data/pthread.h-data: Add pthread_barrier_t,
pthread_barrierattr_t, pthread_barrier_destroy,
pthread_barrier_init, pthread_barrier_wait,
pthread_barrierattr_destroy, pthread_barrierattr_getpshared,
pthread_barrierattr_init, pthread_barrierattr_setpshared,
pthread_condattr_getclock, pthread_condattr_setclock,
pthread_getcpuclockid, pthread_mutex_timedlock,
pthread_rwlock_timedrdlock, pthread_rwlock_timedwrlock,
pthread_sigmask, pthread_spin_destroy, pthread_spin_init,
pthread_spin_lock, pthread_spin_trylock, and pthread_spin_unlock.
* conform/data/sched.h-data: Add sched_ss_low_priority,
sched_ss_repl_period, sched_ss_init_budget, sched_ss_max_repl, and
SCHED_SPORADIC.
* conform/data/semaphore.h-data: Add sem_timedwait.
* conform/data/signal.h-data: Add SIGIO.
* conform/data/spawn.h-data: New file.
* conform/data/stdlib.h-data: Add posix_memalign, setenv, and unsetenv.
* conform/data/time.h-data: Add CLOCK_PROCESS_CPUTIME_ID,
CLOCK_THREAD_CPUTIME_ID, clock_getcpuclockid, and clock_nanosleep.
Fix typo in gmtime_r definition.
* conform/data/unistd.h-data: Add _POSIX_ADVISORY_INFO,
_POSIX_ASYNCHRONOUS_IO, _POSIX_BARRIERS, _POSIX_MONOTONIC_CLOCK,
_POSIX_READER_WRITER_LOCKS, _POSIX_SHELL, _POSIX_SPAWN,
_POSIX_SPIN_LOCKS, _POSIX_SPORADIC_SERVER, _POSIX_THREAD_CPUTIME,
_POSIX_TYPED_MEMORY_OBJECTS, _POSIX_THREAD_SPORADIC_SERVER,
_XOPEN_STREAMS, _POSIX_TIMEOUTS, _POSIX2_PBS,
_POSIX2_PBS_ACCOUNTING, _POSIX2_PBS_CHECKPOINT,
_POSIX2_PBS_LOCATE, _POSIX2_PBS_MESSAGE, _POSIX2_PBS_TRACK,
_SC_2_PBS, _SC_2_PBS_ACCOUNTING, _SC_2_PBS_CHECKPOINT,
_SC_2_PBS_LOCATE, _SC_2_PBS_MESSAGE, _SC_2_PBS_TRACK,
_SC_BARRIERS, _SC_BASE, _SC_CLOCK_SELECTION, _SC_DEVICE_IO,
_SC_DEVICE_SPECIFIC, _SC_DEVICE_SPECIFIC_R, _SC_FD_MGMT, _SC_FIFO,
_SC_FILE_ATTRIBUTES, _SC_FILE_LOCKING, _SC_FILE_SYSTEM,
_SC_MEMORY_PROTECTION, _SC_MESSAGE_PASSING, _SC_MONOTONIC_CLOCK,
_SC_MESSAGE_PASSING, _SC_MONOTONIC_CLOCK, _SC_MULTIPLE_PROCESS,
_SC_NETWORKING, _SC_PIPE, _SC_READER_WRITER_LOCKS, _SC_REGEXP,
_SC_SHELL, _SC_SIGNALS, _SC_SINGLE_PROCESS, _SC_SPIN_LOCKS,
_SC_TYPED_MEMORY_OBJECTS, _SC_USER_GROUPS, _SC_USER_GROUPS_R,
_SC_STREAMS, _PC_REC_INCR_XFER_SIZE, _PC_REC_MAX_XFER_SIZE,
_PC_REC_MIN_XFER_SIZE, _PC_REC_XFER_ALIGN, setegid, seteuid. Fix
typo in off_t definition.
* conform/data/net/if.h-data: New file.
* conform/data/netinet/in.h-data: New file.
* conform/data/netinet/tcp.h-data: New file.
* conform/data/sys/mman.h-data: Add POSIX_MADV_NORMAL,
POSIX_MADV_SEQUENTIAL, POSIX_MADV_RANDOM, POSIX_MADV_WILLNEED,
POSIX_MADV_DONTNEED, POSIX_TYPED_MEM_ALLOCATE,
POSIX_TYPED_MEM_ALLOCATE_CONTIG, POSIX_TYPED_MEM_MAP_ALLOCATABLE,
posix_typedmem_info, posix_mem_offset, posix_typed_mem_get_info,
and posix_typed_mem_open.
* conform/data/sys/socket.h-data: New file.
* conform/data/sys/stat.h-data: Add S_TYPEISTMO and isfdtype.
* conform/data/sys/types.h-data: Add pthread_barrier_t,
pthread_barrierattr_t, and pthread_spinlock_t.
* conform/data/sys/un.h-data: New file.
* conform/data/sys/utsname.h-data: New file.
* include/netdb.h (__gethostbyaddr_r): Fix types of first and second
parameter.
* inet/gethstbyad.c (gethostbyname): Likewise.
* inet/gethstbyad_t.c (gethostbyname_r): Likewise.
* inet/getipnodebyad.c (getipnodebyad): Likewise.
* nis/nss_nis/nis-hosts.c (_nss_nis_gethostbyaddr_r): Likewise.
* nis/nss_nisplus/nisplus-hosts.c (_nss_nisplus_gethostbyaddr_r):
Likewise.
* nscd/gethstbyad_r.c (gethostbyaddr_r): Likewise.
* nscd/nscd_gethst_r.c (__nscd_gethostbyaddr_r): Likewise.
* nscd/nscd_proto.h (__nscd_gethostbyaddr_r): Likewise.
* nss/nss_files/files-hosts.c (_nss_files_gethostbyaddr_r): Likewise.
* resolv/gethnamaddr.c (gethostbyname): Likewise.
* resolv/netdb.h (struct hostent): Fix type of h_length member.
(gethostbyaddr, getipnodebyaddr, gethostbyaddr_r): Fix types of first
and second parameter.
2000-04-29 Andreas Jaeger <aj@suse.de>
* conform/data/arpa/inet.h-data: New file.
2000-04-30 04:17:35 +00:00
|
|
|
__nscd_gethostbyaddr_r (const void *addr, socklen_t len, int type,
|
1998-10-18 15:16:22 +00:00
|
|
|
struct hostent *resultbuf, char *buffer, size_t buflen,
|
2004-02-27 00:55:39 +00:00
|
|
|
struct hostent **result, int *h_errnop)
|
1998-10-18 15:16:22 +00:00
|
|
|
{
|
|
|
|
request_type reqtype;
|
|
|
|
|
|
|
|
if (!((len == INADDRSZ && type == AF_INET)
|
|
|
|
|| (len == IN6ADDRSZ && type == AF_INET6)))
|
|
|
|
/* LEN and TYPE do not match. */
|
1999-06-17 12:33:08 +00:00
|
|
|
return -1;
|
1998-10-18 15:16:22 +00:00
|
|
|
|
|
|
|
reqtype = type == AF_INET6 ? GETHOSTBYADDRv6 : GETHOSTBYADDR;
|
|
|
|
|
2004-02-27 00:55:39 +00:00
|
|
|
return nscd_gethst_r (addr, len, reqtype, resultbuf, buffer, buflen, result,
|
1998-10-18 15:16:22 +00:00
|
|
|
h_errnop);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-15 20:46:12 +00:00
|
|
|
libc_locked_map_ptr (, __hst_map_handle) attribute_hidden;
|
2004-09-08 15:46:42 +00:00
|
|
|
/* Note that we only free the structure if necessary. The memory
|
|
|
|
mapping is not removed since it is not visible to the malloc
|
|
|
|
handling. */
|
2004-11-10 07:54:40 +00:00
|
|
|
libc_freeres_fn (hst_map_free)
|
1998-10-18 15:16:22 +00:00
|
|
|
{
|
2004-11-10 07:54:40 +00:00
|
|
|
if (__hst_map_handle.mapped != NO_MAPPING)
|
|
|
|
{
|
|
|
|
void *p = __hst_map_handle.mapped;
|
|
|
|
__hst_map_handle.mapped = NO_MAPPING;
|
|
|
|
free (p);
|
|
|
|
}
|
1998-10-18 15:16:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-31 05:51:16 +00:00
|
|
|
uint32_t
|
|
|
|
__nscd_get_nl_timestamp (void)
|
|
|
|
{
|
2012-05-15 18:35:53 +00:00
|
|
|
uint32_t retval;
|
2011-10-31 05:51:16 +00:00
|
|
|
if (__nss_not_use_nscd_hosts != 0)
|
|
|
|
return 0;
|
|
|
|
|
2012-05-15 18:35:53 +00:00
|
|
|
/* __nscd_get_mapping can change hst_map_handle.mapped to NO_MAPPING.
|
|
|
|
However, __nscd_get_mapping assumes the prior value was not NO_MAPPING.
|
|
|
|
Thus we have to acquire the lock to prevent this thread from changing
|
|
|
|
hst_map_handle.mapped to NO_MAPPING while another thread is inside
|
|
|
|
__nscd_get_mapping. */
|
|
|
|
if (!__nscd_acquire_maplock (&__hst_map_handle))
|
|
|
|
return 0;
|
|
|
|
|
2011-10-31 05:51:16 +00:00
|
|
|
struct mapped_database *map = __hst_map_handle.mapped;
|
|
|
|
|
|
|
|
if (map == NULL
|
|
|
|
|| (map != NO_MAPPING
|
|
|
|
&& map->head->nscd_certainly_running == 0
|
2019-10-24 21:01:40 +00:00
|
|
|
&& map->head->timestamp + MAPPING_TIMEOUT < time_now ()))
|
2011-10-31 05:51:16 +00:00
|
|
|
map = __nscd_get_mapping (GETFDHST, "hosts", &__hst_map_handle.mapped);
|
|
|
|
|
|
|
|
if (map == NO_MAPPING)
|
2012-05-15 18:35:53 +00:00
|
|
|
retval = 0;
|
|
|
|
else
|
|
|
|
retval = map->head->extra_data[NSCD_HST_IDX_CONF_TIMESTAMP];
|
|
|
|
|
|
|
|
/* Release the lock. */
|
|
|
|
__hst_map_handle.lock = 0;
|
2011-10-31 05:51:16 +00:00
|
|
|
|
2012-05-15 18:35:53 +00:00
|
|
|
return retval;
|
2011-10-31 05:51:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-29 20:56:13 +00:00
|
|
|
int __nss_have_localdomain attribute_hidden;
|
|
|
|
|
1998-10-18 15:16:22 +00:00
|
|
|
static int
|
|
|
|
nscd_gethst_r (const char *key, size_t keylen, request_type type,
|
|
|
|
struct hostent *resultbuf, char *buffer, size_t buflen,
|
2004-02-27 00:55:39 +00:00
|
|
|
struct hostent **result, int *h_errnop)
|
1998-10-18 15:16:22 +00:00
|
|
|
{
|
2014-02-10 13:45:42 +00:00
|
|
|
if (__glibc_unlikely (__nss_have_localdomain >= 0))
|
2008-12-29 20:56:13 +00:00
|
|
|
{
|
|
|
|
if (__nss_have_localdomain == 0)
|
|
|
|
__nss_have_localdomain = getenv ("LOCALDOMAIN") != NULL ? 1 : -1;
|
|
|
|
if (__nss_have_localdomain > 0)
|
|
|
|
{
|
|
|
|
__nss_not_use_nscd_hosts = 1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-30 08:08:40 +00:00
|
|
|
int gc_cycle;
|
|
|
|
int nretries = 0;
|
|
|
|
|
|
|
|
/* If the mapping is available, try to search there instead of
|
|
|
|
communicating with the nscd. */
|
|
|
|
struct mapped_database *mapped;
|
2004-11-10 07:54:40 +00:00
|
|
|
mapped = __nscd_get_map_ref (GETFDHST, "hosts", &__hst_map_handle,
|
|
|
|
&gc_cycle);
|
2004-09-30 08:08:40 +00:00
|
|
|
|
|
|
|
retry:;
|
2004-09-08 15:46:42 +00:00
|
|
|
const char *h_name = NULL;
|
|
|
|
const uint32_t *aliases_len = NULL;
|
|
|
|
const char *addr_list = NULL;
|
|
|
|
size_t addr_list_len = 0;
|
|
|
|
int retval = -1;
|
|
|
|
const char *recend = (const char *) ~UINTMAX_C (0);
|
|
|
|
int sock = -1;
|
2007-01-31 09:14:21 +00:00
|
|
|
hst_response_header hst_resp;
|
2004-09-30 05:16:40 +00:00
|
|
|
if (mapped != NO_MAPPING)
|
1998-10-18 15:16:22 +00:00
|
|
|
{
|
2007-01-31 09:14:21 +00:00
|
|
|
/* No const qualifier, as it can change during garbage collection. */
|
2009-05-16 04:17:08 +00:00
|
|
|
struct datahead *found = __nscd_cache_search (type, key, keylen, mapped,
|
|
|
|
sizeof hst_resp);
|
2004-09-08 15:46:42 +00:00
|
|
|
if (found != NULL)
|
|
|
|
{
|
2007-01-31 09:14:21 +00:00
|
|
|
h_name = (char *) (&found->data[0].hstdata + 1);
|
|
|
|
hst_resp = found->data[0].hstdata;
|
|
|
|
aliases_len = (uint32_t *) (h_name + hst_resp.h_name_len);
|
2004-09-08 15:46:42 +00:00
|
|
|
addr_list = ((char *) aliases_len
|
2007-01-31 09:14:21 +00:00
|
|
|
+ hst_resp.h_aliases_cnt * sizeof (uint32_t));
|
|
|
|
addr_list_len = hst_resp.h_addr_list_cnt * INADDRSZ;
|
|
|
|
recend = (const char *) found->data + found->recsize;
|
|
|
|
/* Now check if we can trust hst_resp fields. If GC is
|
|
|
|
in progress, it can contain anything. */
|
|
|
|
if (mapped->head->gc_cycle != gc_cycle)
|
|
|
|
{
|
|
|
|
retval = -2;
|
|
|
|
goto out;
|
|
|
|
}
|
2004-09-08 15:46:42 +00:00
|
|
|
|
2014-03-26 20:37:35 +00:00
|
|
|
#if !_STRING_ARCH_unaligned
|
2004-09-08 15:46:42 +00:00
|
|
|
/* The aliases_len array in the mapped database might very
|
|
|
|
well be unaligned. We will access it word-wise so on
|
|
|
|
platforms which do not tolerate unaligned accesses we
|
|
|
|
need to make an aligned copy. */
|
|
|
|
if (((uintptr_t) aliases_len & (__alignof__ (*aliases_len) - 1))
|
|
|
|
!= 0)
|
|
|
|
{
|
2007-01-31 09:14:21 +00:00
|
|
|
uint32_t *tmp = alloca (hst_resp.h_aliases_cnt
|
2004-09-08 15:46:42 +00:00
|
|
|
* sizeof (uint32_t));
|
|
|
|
aliases_len = memcpy (tmp, aliases_len,
|
2007-01-31 09:14:21 +00:00
|
|
|
hst_resp.h_aliases_cnt
|
2004-09-08 15:46:42 +00:00
|
|
|
* sizeof (uint32_t));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (type != GETHOSTBYADDR && type != GETHOSTBYNAME)
|
|
|
|
{
|
2007-01-31 09:14:21 +00:00
|
|
|
if (hst_resp.h_length == INADDRSZ)
|
2004-09-08 15:46:42 +00:00
|
|
|
addr_list += addr_list_len;
|
2007-01-31 09:14:21 +00:00
|
|
|
addr_list_len = hst_resp.h_addr_list_cnt * IN6ADDRSZ;
|
2004-09-08 15:46:42 +00:00
|
|
|
}
|
|
|
|
if (__builtin_expect ((const char *) addr_list + addr_list_len
|
|
|
|
> recend, 0))
|
2007-01-31 09:14:21 +00:00
|
|
|
goto out;
|
2004-09-08 15:46:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-31 09:14:21 +00:00
|
|
|
if (h_name == NULL)
|
2004-09-08 15:46:42 +00:00
|
|
|
{
|
2007-01-31 09:14:21 +00:00
|
|
|
sock = __nscd_open_socket (key, keylen, type, &hst_resp,
|
|
|
|
sizeof (hst_resp));
|
2004-09-08 15:46:42 +00:00
|
|
|
if (sock == -1)
|
|
|
|
{
|
|
|
|
__nss_not_use_nscd_hosts = 1;
|
2007-01-13 07:30:26 +00:00
|
|
|
goto out;
|
2004-09-08 15:46:42 +00:00
|
|
|
}
|
1998-10-18 15:16:22 +00:00
|
|
|
}
|
|
|
|
|
2004-03-01 22:35:28 +00:00
|
|
|
/* No value found so far. */
|
|
|
|
*result = NULL;
|
|
|
|
|
2014-02-10 13:45:42 +00:00
|
|
|
if (__glibc_unlikely (hst_resp.found == -1))
|
1998-10-18 15:16:22 +00:00
|
|
|
{
|
|
|
|
/* The daemon does not cache this database. */
|
|
|
|
__nss_not_use_nscd_hosts = 1;
|
2004-09-08 15:46:42 +00:00
|
|
|
goto out_close;
|
1998-10-18 15:16:22 +00:00
|
|
|
}
|
|
|
|
|
2007-01-31 09:14:21 +00:00
|
|
|
if (hst_resp.found == 1)
|
1998-10-18 15:16:22 +00:00
|
|
|
{
|
|
|
|
char *cp = buffer;
|
1999-06-02 11:05:06 +00:00
|
|
|
uintptr_t align1;
|
|
|
|
uintptr_t align2;
|
1998-10-18 15:16:22 +00:00
|
|
|
size_t total_len;
|
|
|
|
ssize_t cnt;
|
|
|
|
char *ignore;
|
|
|
|
int n;
|
|
|
|
|
2000-02-22 09:00:35 +00:00
|
|
|
/* A first check whether the buffer is sufficiently large is possible. */
|
1998-10-18 15:16:22 +00:00
|
|
|
/* Now allocate the buffer the array for the group members. We must
|
1999-06-02 11:05:06 +00:00
|
|
|
align the pointer and the base of the h_addr_list pointers. */
|
|
|
|
align1 = ((__alignof__ (char *) - (cp - ((char *) 0)))
|
|
|
|
& (__alignof__ (char *) - 1));
|
2007-01-31 09:14:21 +00:00
|
|
|
align2 = ((__alignof__ (char *) - ((cp + align1 + hst_resp.h_name_len)
|
1999-06-02 11:05:06 +00:00
|
|
|
- ((char *) 0)))
|
|
|
|
& (__alignof__ (char *) - 1));
|
2007-01-31 09:14:21 +00:00
|
|
|
if (buflen < (align1 + hst_resp.h_name_len + align2
|
|
|
|
+ ((hst_resp.h_aliases_cnt + hst_resp.h_addr_list_cnt
|
2004-09-08 15:46:42 +00:00
|
|
|
+ 2)
|
1998-10-18 15:16:22 +00:00
|
|
|
* sizeof (char *))
|
2007-01-31 09:14:21 +00:00
|
|
|
+ hst_resp.h_addr_list_cnt * (type == AF_INET
|
|
|
|
? INADDRSZ : IN6ADDRSZ)))
|
1998-10-18 15:16:22 +00:00
|
|
|
{
|
|
|
|
no_room:
|
2005-02-21 23:43:21 +00:00
|
|
|
*h_errnop = NETDB_INTERNAL;
|
1998-10-18 15:16:22 +00:00
|
|
|
__set_errno (ERANGE);
|
2004-02-27 00:55:39 +00:00
|
|
|
retval = ERANGE;
|
2004-09-08 15:46:42 +00:00
|
|
|
goto out_close;
|
1998-10-18 15:16:22 +00:00
|
|
|
}
|
1999-06-02 11:05:06 +00:00
|
|
|
cp += align1;
|
1998-10-18 15:16:22 +00:00
|
|
|
|
|
|
|
/* Prepare the result as far as we can. */
|
|
|
|
resultbuf->h_aliases = (char **) cp;
|
2007-01-31 09:14:21 +00:00
|
|
|
cp += (hst_resp.h_aliases_cnt + 1) * sizeof (char *);
|
1998-10-18 15:16:22 +00:00
|
|
|
resultbuf->h_addr_list = (char **) cp;
|
2007-01-31 09:14:21 +00:00
|
|
|
cp += (hst_resp.h_addr_list_cnt + 1) * sizeof (char *);
|
1998-10-18 15:16:22 +00:00
|
|
|
|
|
|
|
resultbuf->h_name = cp;
|
2007-01-31 09:14:21 +00:00
|
|
|
cp += hst_resp.h_name_len + align2;
|
1998-10-18 15:16:22 +00:00
|
|
|
|
|
|
|
if (type == GETHOSTBYADDR || type == GETHOSTBYNAME)
|
|
|
|
{
|
|
|
|
resultbuf->h_addrtype = AF_INET;
|
|
|
|
resultbuf->h_length = INADDRSZ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-09-08 15:46:42 +00:00
|
|
|
resultbuf->h_addrtype = AF_INET6;
|
|
|
|
resultbuf->h_length = IN6ADDRSZ;
|
|
|
|
}
|
2007-01-31 09:14:21 +00:00
|
|
|
for (cnt = 0; cnt < hst_resp.h_addr_list_cnt; ++cnt)
|
2004-09-08 15:46:42 +00:00
|
|
|
{
|
|
|
|
resultbuf->h_addr_list[cnt] = cp;
|
|
|
|
cp += resultbuf->h_length;
|
|
|
|
}
|
|
|
|
resultbuf->h_addr_list[cnt] = NULL;
|
1998-10-18 15:16:22 +00:00
|
|
|
|
2004-09-08 15:46:42 +00:00
|
|
|
if (h_name == NULL)
|
|
|
|
{
|
2007-01-13 07:30:26 +00:00
|
|
|
struct iovec vec[4];
|
|
|
|
|
2004-09-08 15:46:42 +00:00
|
|
|
vec[0].iov_base = resultbuf->h_name;
|
2007-01-31 09:14:21 +00:00
|
|
|
vec[0].iov_len = hst_resp.h_name_len;
|
|
|
|
total_len = hst_resp.h_name_len;
|
2004-09-08 15:46:42 +00:00
|
|
|
n = 1;
|
1998-10-18 15:16:22 +00:00
|
|
|
|
2007-01-31 09:14:21 +00:00
|
|
|
if (hst_resp.h_aliases_cnt > 0)
|
2004-09-08 15:46:42 +00:00
|
|
|
{
|
2007-01-31 09:14:21 +00:00
|
|
|
aliases_len = alloca (hst_resp.h_aliases_cnt
|
2004-09-08 15:46:42 +00:00
|
|
|
* sizeof (uint32_t));
|
|
|
|
vec[n].iov_base = (void *) aliases_len;
|
2007-01-31 09:14:21 +00:00
|
|
|
vec[n].iov_len = hst_resp.h_aliases_cnt * sizeof (uint32_t);
|
1998-10-18 15:16:22 +00:00
|
|
|
|
2007-01-31 09:14:21 +00:00
|
|
|
total_len += hst_resp.h_aliases_cnt * sizeof (uint32_t);
|
2004-09-08 15:46:42 +00:00
|
|
|
++n;
|
|
|
|
}
|
1998-10-18 15:16:22 +00:00
|
|
|
|
2004-09-08 15:46:42 +00:00
|
|
|
if (type == GETHOSTBYADDR || type == GETHOSTBYNAME)
|
1998-10-18 15:16:22 +00:00
|
|
|
{
|
2004-09-08 15:46:42 +00:00
|
|
|
vec[n].iov_base = resultbuf->h_addr_list[0];
|
2007-01-31 09:14:21 +00:00
|
|
|
vec[n].iov_len = hst_resp.h_addr_list_cnt * INADDRSZ;
|
2004-09-08 15:46:42 +00:00
|
|
|
|
2007-01-31 09:14:21 +00:00
|
|
|
total_len += hst_resp.h_addr_list_cnt * INADDRSZ;
|
2004-09-08 15:46:42 +00:00
|
|
|
|
|
|
|
++n;
|
1998-10-18 15:16:22 +00:00
|
|
|
}
|
2004-09-08 15:46:42 +00:00
|
|
|
else
|
|
|
|
{
|
2007-01-31 09:14:21 +00:00
|
|
|
if (hst_resp.h_length == INADDRSZ)
|
2004-09-08 15:46:42 +00:00
|
|
|
{
|
2007-01-31 09:14:21 +00:00
|
|
|
ignore = alloca (hst_resp.h_addr_list_cnt * INADDRSZ);
|
2004-09-08 15:46:42 +00:00
|
|
|
vec[n].iov_base = ignore;
|
2007-01-31 09:14:21 +00:00
|
|
|
vec[n].iov_len = hst_resp.h_addr_list_cnt * INADDRSZ;
|
1998-10-18 15:16:22 +00:00
|
|
|
|
2007-01-31 09:14:21 +00:00
|
|
|
total_len += hst_resp.h_addr_list_cnt * INADDRSZ;
|
1998-10-18 15:16:22 +00:00
|
|
|
|
2004-09-08 15:46:42 +00:00
|
|
|
++n;
|
|
|
|
}
|
1998-10-18 15:16:22 +00:00
|
|
|
|
2004-09-08 15:46:42 +00:00
|
|
|
vec[n].iov_base = resultbuf->h_addr_list[0];
|
2007-01-31 09:14:21 +00:00
|
|
|
vec[n].iov_len = hst_resp.h_addr_list_cnt * IN6ADDRSZ;
|
1998-10-18 15:16:22 +00:00
|
|
|
|
2007-01-31 09:14:21 +00:00
|
|
|
total_len += hst_resp.h_addr_list_cnt * IN6ADDRSZ;
|
2004-09-08 15:46:42 +00:00
|
|
|
|
|
|
|
++n;
|
|
|
|
}
|
|
|
|
|
2005-02-22 22:58:32 +00:00
|
|
|
if ((size_t) __readvall (sock, vec, n) != total_len)
|
2004-09-08 15:46:42 +00:00
|
|
|
goto out_close;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-01-31 09:14:21 +00:00
|
|
|
memcpy (resultbuf->h_name, h_name, hst_resp.h_name_len);
|
2004-09-08 15:46:42 +00:00
|
|
|
memcpy (resultbuf->h_addr_list[0], addr_list, addr_list_len);
|
|
|
|
}
|
1998-10-18 15:16:22 +00:00
|
|
|
|
|
|
|
/* Now we also can read the aliases. */
|
|
|
|
total_len = 0;
|
2007-01-31 09:14:21 +00:00
|
|
|
for (cnt = 0; cnt < hst_resp.h_aliases_cnt; ++cnt)
|
1998-10-18 15:16:22 +00:00
|
|
|
{
|
|
|
|
resultbuf->h_aliases[cnt] = cp;
|
|
|
|
cp += aliases_len[cnt];
|
|
|
|
total_len += aliases_len[cnt];
|
|
|
|
}
|
|
|
|
resultbuf->h_aliases[cnt] = NULL;
|
|
|
|
|
2004-09-08 15:46:42 +00:00
|
|
|
if (__builtin_expect ((const char *) addr_list + addr_list_len
|
|
|
|
+ total_len > recend, 0))
|
2007-01-31 09:14:21 +00:00
|
|
|
{
|
|
|
|
/* aliases_len array might contain garbage during nscd GC cycle,
|
|
|
|
retry rather than fail in that case. */
|
|
|
|
if (addr_list != NULL && mapped->head->gc_cycle != gc_cycle)
|
|
|
|
retval = -2;
|
|
|
|
goto out_close;
|
|
|
|
}
|
1998-10-18 15:16:22 +00:00
|
|
|
/* See whether this would exceed the buffer capacity. */
|
2014-02-10 13:45:42 +00:00
|
|
|
if (__glibc_unlikely (cp > buffer + buflen))
|
2007-01-31 09:14:21 +00:00
|
|
|
{
|
|
|
|
/* aliases_len array might contain garbage during nscd GC cycle,
|
|
|
|
retry rather than fail in that case. */
|
|
|
|
if (addr_list != NULL && mapped->head->gc_cycle != gc_cycle)
|
|
|
|
{
|
|
|
|
retval = -2;
|
|
|
|
goto out_close;
|
|
|
|
}
|
|
|
|
goto no_room;
|
|
|
|
}
|
1998-10-18 15:16:22 +00:00
|
|
|
|
|
|
|
/* And finally read the aliases. */
|
2004-09-08 15:46:42 +00:00
|
|
|
if (addr_list == NULL)
|
|
|
|
{
|
2005-11-19 17:09:03 +00:00
|
|
|
if (total_len == 0
|
|
|
|
|| ((size_t) __readall (sock, resultbuf->h_aliases[0], total_len)
|
|
|
|
== total_len))
|
2004-09-08 15:46:42 +00:00
|
|
|
{
|
|
|
|
retval = 0;
|
|
|
|
*result = resultbuf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2004-02-27 00:55:39 +00:00
|
|
|
{
|
2004-09-08 15:46:42 +00:00
|
|
|
memcpy (resultbuf->h_aliases[0],
|
|
|
|
(const char *) addr_list + addr_list_len, total_len);
|
|
|
|
|
2004-11-10 07:50:03 +00:00
|
|
|
/* Try to detect corrupt databases. */
|
2007-01-31 09:14:21 +00:00
|
|
|
if (resultbuf->h_name[hst_resp.h_name_len - 1] != '\0'
|
|
|
|
|| ({for (cnt = 0; cnt < hst_resp.h_aliases_cnt; ++cnt)
|
2004-11-10 07:50:03 +00:00
|
|
|
if (resultbuf->h_aliases[cnt][aliases_len[cnt] - 1]
|
|
|
|
!= '\0')
|
|
|
|
break;
|
2007-01-31 09:14:21 +00:00
|
|
|
cnt < hst_resp.h_aliases_cnt; }))
|
|
|
|
{
|
|
|
|
/* We cannot use the database. */
|
|
|
|
if (mapped->head->gc_cycle != gc_cycle)
|
|
|
|
retval = -2;
|
|
|
|
goto out_close;
|
|
|
|
}
|
2004-11-10 07:50:03 +00:00
|
|
|
|
2004-02-27 00:55:39 +00:00
|
|
|
retval = 0;
|
|
|
|
*result = resultbuf;
|
|
|
|
}
|
1998-10-18 15:16:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Store the error number. */
|
2007-01-31 09:14:21 +00:00
|
|
|
*h_errnop = hst_resp.error;
|
1998-10-18 15:16:22 +00:00
|
|
|
|
2007-10-13 23:04:40 +00:00
|
|
|
/* Set errno to 0 to indicate no error, just no found record. */
|
|
|
|
__set_errno (0);
|
2004-02-27 00:55:39 +00:00
|
|
|
/* Even though we have not found anything, the result is zero. */
|
|
|
|
retval = 0;
|
1998-10-18 15:16:22 +00:00
|
|
|
}
|
2003-04-28 08:17:29 +00:00
|
|
|
|
2004-09-08 15:46:42 +00:00
|
|
|
out_close:
|
|
|
|
if (sock != -1)
|
2017-07-03 18:22:58 +00:00
|
|
|
__close_nocancel_nostatus (sock);
|
2003-04-28 08:17:29 +00:00
|
|
|
out:
|
2007-01-31 09:14:21 +00:00
|
|
|
if (__nscd_drop_map_ref (mapped, &gc_cycle) != 0)
|
2004-09-30 08:08:40 +00:00
|
|
|
{
|
|
|
|
/* When we come here this means there has been a GC cycle while we
|
|
|
|
were looking for the data. This means the data might have been
|
|
|
|
inconsistent. Retry if possible. */
|
2007-01-31 09:14:21 +00:00
|
|
|
if ((gc_cycle & 1) != 0 || ++nretries == 5 || retval == -1)
|
2004-09-30 08:08:40 +00:00
|
|
|
{
|
|
|
|
/* nscd is just running gc now. Disable using the mapping. */
|
2007-01-31 09:14:21 +00:00
|
|
|
if (atomic_decrement_val (&mapped->counter) == 0)
|
|
|
|
__nscd_unmap (mapped);
|
2004-09-30 08:08:40 +00:00
|
|
|
mapped = NO_MAPPING;
|
|
|
|
}
|
|
|
|
|
2007-01-31 09:14:21 +00:00
|
|
|
if (retval != -1)
|
|
|
|
goto retry;
|
2004-09-30 08:08:40 +00:00
|
|
|
}
|
2003-04-28 08:17:29 +00:00
|
|
|
|
2004-02-27 00:55:39 +00:00
|
|
|
return retval;
|
1998-10-18 15:16:22 +00:00
|
|
|
}
|