From 3c77dcff9ebf51910b01ca770f7a8ffef52b617c Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Thu, 22 May 2008 21:30:28 +0000 Subject: 2008-05-22 Jeff Johnston * libc/include/sys/reent.h: Add _h_errno field. * libc/sys/linux/libc-symbols.h: Add default stubs for new libc macros now used in net directory. * libc/sys/linux/bits/libc-lock.h: Always define _IO_MTSAFE_IO. * libc/sys/linux/include/hesiod.h: Add needed macros for new code in net directory. * libc/sys/linux/include/netdb.h: Ditto. * libc/sys/linux/include/resolv.h: Ditto. * libc/sys/linux/include/stdint.h: Ditto. * libc/sys/linux/include/arpa/nameser.h: Ditto. * libc/sys/linux/include/net/ethernet.h: Ditto. * libc/sys/linux/include/net/if_ppp.h: Ditto. * libc/sys/linux/include/netinet/if_ether.h: Ditto. * libc/sys/linux/machine/i386/get_clockfreq.c: Remove static memmem. * libc/sys/linux/machine/i386/include/endian.h: Protect macros with flags to avoid duplicate definition. * libc/sys/linux/machine/i386/include/param.h: Ditto. * libc/sys/linux/net/Makefile.am: Modified to account for removed and added files. * libc/sys/linux/net/Makefile.in: Regenerated. * libc/sys/linux/net/base64.c: Replaced with glibc version of code. * libc/sys/linux/net/getaddrinfo.c: Ditto. * libc/sys/linux/net/getnameinfo.c: Ditto. * libc/sys/linux/net/getproto.c: Ditto. * libc/sys/linux/net/getservent.c: Ditto. * libc/sys/linux/net/inet_netof.c: Ditto. * libc/sys/linux/net/inet_lnaof.c: Ditto. * libc/sys/linux/net/ns_name.c: Ditto. * libc/sys/linux/net/ns_netint.c: Ditto. * libc/sys/linux/net/inet_ntoa.c: Ditto. * libc/sys/linux/net/ns_parse.c: Ditto. * libc/sys/linux/net/ns_print.c: Ditto. * libc/sys/linux/net/ns_ttl.c: Ditto. * libc/sys/linux/net/nsap_addr.c: Ditto. * libc/sys/linux/net/rcmd.c: Ditto. * libc/sys/linux/net/res_comp.c: Ditto. * libc/sys/linux/net/res_data.c: Ditto. * libc/sys/linux/net/res_debug.c: Ditto. * libc/sys/linux/net/res_init.c: Ditto. * libc/sys/linux/net/res_mkquery.c: Ditto. * libc/sys/linux/net/res_query.c: Ditto. * libc/sys/linux/net/res_send.c: Ditto. * libc/sys/linux/net/send.c: Ditto. * libc/sys/linux/stdlib/collate.c: Ditto. * libc/sys/linux/sys/ioctl.h: Ditto. * libc/sys/linux/sys/socket.h: Ditto. * libc/sys/linux/sys/unistd.h: Ditto. * libc/sys/linux/iconv/iconvconfig.c: Removed either because no longer used or because licensing includes advertising clause that cannot be ignored. * libc/sys/linux/iconv/strtab.c: Ditto. * libc/sys/linux/include/libc_private.h: Ditto. * libc/sys/linux/include/nsswitch.h: Ditto. * libc/sys/linux/include/net/if_atm.h: Ditto. * libc/sys/linux/include/net/if_media.h: Ditto. * libc/sys/linux/include/net/if_pppvar.h: Ditto. * libc/sys/linux/include/netinet/if_atm.h: Ditto. * libc/sys/linux/include/netinet/ip_flow.h: Ditto. * libc/sys/linux/intl/locale.alias: Ditto. * libc/sys/linux/net/addr2ascii.3: Ditto. * libc/sys/linux/net/bindresvport.c: Ditto. * libc/sys/linux/net/byteorder.3: Ditto. * libc/sys/linux/net/res_config.h: Ditto. * libc/sys/linux/net/ether_addr.c: Ditto. * libc/sys/linux/net/ethers.3: Ditto. * libc/sys/linux/net/getaddrinfo.3: Ditto. * libc/sys/linux/net/gethostbydns.c: Ditto. * libc/sys/linux/net/gethostbyht.c: Ditto. * libc/sys/linux/net/gethostbyname.3: Ditto. * libc/sys/linux/net/gethostbynis.c: Ditto. * libc/sys/linux/net/gethostnamadr.c: Ditto. * libc/sys/linux/net/getifaddrs.3: Ditto. * libc/sys/linux/net/getifaddrs.c: Ditto. * libc/sys/linux/net/getipnodebyname.3: Ditto. * libc/sys/linux/net/getnameinfo.3: Ditto. * libc/sys/linux/net/getnetbydns.c: Ditto. * libc/sys/linux/net/getnetbyht.c: Ditto. * libc/sys/linux/net/getnetbynis.c: Ditto. * libc/sys/linux/net/getnetent.3: Ditto. * libc/sys/linux/net/getnetnamadr.c: Ditto. * libc/sys/linux/net/getprotoent.3: Ditto. * libc/sys/linux/net/getprotoent.c: Ditto. * libc/sys/linux/net/getprotoname.c: Ditto. * libc/sys/linux/net/getservbyname.c: Ditto. * libc/sys/linux/net/getservbyport.c: Ditto. * libc/sys/linux/net/getservent.3: Ditto. * libc/sys/linux/net/herror.c: Ditto. * libc/sys/linux/net/hesiod.3: Ditto. * libc/sys/linux/net/hesiod.c: Ditto. * libc/sys/linux/net/if_indextoname.3: Ditto. * libc/sys/linux/net/inet.3: Ditto. * libc/sys/linux/net/inet6_option_space.3: Ditto. * libc/sys/linux/net/inet6_rthdr_space.3: Ditto. * libc/sys/linux/net/inet_makeaddr.c: Ditto. * libc/sys/linux/net/inet_net.3: Ditto. * libc/sys/linux/net/inet_network.c: Ditto. * libc/sys/linux/net/innetgr-stub.c: Ditto. * libc/sys/linux/net/ip6opt.c: Ditto. * libc/sys/linux/net/iso_addr.3: Ditto. * libc/sys/linux/net/iso_addr.c: Ditto. * libc/sys/linux/net/linkaddr.3: Ditto. * libc/sys/linux/net/linkaddr.c: Ditto. * libc/sys/linux/net/map_v4v6.c: Ditto. * libc/sys/linux/net/name6.c: Ditto. * libc/sys/linux/net/namespace.h: Ditto. * libc/sys/linux/net/ns.3: Ditto. * libc/sys/linux/net/ns_addr.c: Ditto. * libc/sys/linux/net/ns_ntoa.c: Ditto. * libc/sys/linux/net/nsdispatch.3: Ditto. * libc/sys/linux/net/nsdispatch.c: Ditto. * libc/sys/linux/net/nslexer.c: Ditto. * libc/sys/linux/net/nslexer.l: Ditto. * libc/sys/linux/net/nsparser.c: Ditto. * libc/sys/linux/net/nsparser.h: Ditto. * libc/sys/linux/net/nsparser.y: Ditto. * libc/sys/linux/net/rcmd.3: Ditto. * libc/sys/linux/net/rcmdsh.3: Ditto. * libc/sys/linux/net/res_mkupdate.c: Ditto. * libc/sys/linux/net/res_update.c: Ditto. * libc/sys/linux/net/resolver.3: Ditto. * libc/sys/linux/net/rthdr.c: Ditto. * libc/sys/linux/net/vars.c: Ditto. * libc/sys/linux/shlib-compat.h: New file. * libc/sys/linux/machine/i386/atomic.h: Ditto. * libc/sys/linux/net/XXX-lookup.c: Ditto. * libc/sys/linux/net/alias-lookup.c: Ditto. * libc/sys/linux/net/res_libc.c: Ditto. * libc/sys/linux/net/aliases.h: Ditto. * libc/sys/linux/net/check_pf.c: Ditto. * libc/sys/linux/net/databases.def: Ditto. * libc/sys/linux/net/digits_dots.c: Ditto. * libc/sys/linux/net/ether_aton.c: Ditto. * libc/sys/linux/net/ether_aton_r.c: Ditto. * libc/sys/linux/net/ether_hton.c: Ditto. * libc/sys/linux/net/ether_line.c: Ditto. * libc/sys/linux/net/ether_ntoa.c: Ditto. * libc/sys/linux/net/ether_ntoa_r.c: Ditto. * libc/sys/linux/net/ether_ntoh.c: Ditto. * libc/sys/linux/net/etherent.h: Ditto. * libc/sys/linux/net/ethers-lookup.c: Ditto. * libc/sys/linux/net/function.def: Ditto. * libc/sys/linux/net/getXXbyYY.c: Ditto. * libc/sys/linux/net/getXXbyYY_r.c: Ditto. * libc/sys/linux/net/getXXent.c: Ditto. * libc/sys/linux/net/getXXent_r.c: Ditto. * libc/sys/linux/net/getaliasent.c: Ditto. * libc/sys/linux/net/getaliasent_r.c: Ditto. * libc/sys/linux/net/getaliasname.c: Ditto. * libc/sys/linux/net/getaliasname_r.c: Ditto. * libc/sys/linux/net/gethstbyad.c: Ditto. * libc/sys/linux/net/gethstbyad_r.c: Ditto. * libc/sys/linux/net/gethstbynm.c: Ditto. * libc/sys/linux/net/gethstbynm2.c: Ditto. * libc/sys/linux/net/gethstbynm2_r.c: Ditto. * libc/sys/linux/net/gethstbynm_r.c: Ditto. * libc/sys/linux/net/gethstent.c: Ditto. * libc/sys/linux/net/gethstent_r.c: Ditto. * libc/sys/linux/net/getnetbyad.c: Ditto. * libc/sys/linux/net/getnetbyad_r.c: Ditto. * libc/sys/linux/net/getnetbynm.c: Ditto. * libc/sys/linux/net/getnetbynm_r.c: Ditto. * libc/sys/linux/net/getnetent.c: Ditto. * libc/sys/linux/net/getnetent_r.c: Ditto. * libc/sys/linux/net/getnetgrent.c: Ditto. * libc/sys/linux/net/getnetgrent_r.c: Ditto. * libc/sys/linux/net/getnssent.c: Ditto. * libc/sys/linux/net/getnssent_r.c: Ditto. * libc/sys/linux/net/getproto_r.c: Ditto. * libc/sys/linux/net/getprtent.c: Ditto. * libc/sys/linux/net/getprtent_r.c: Ditto. * libc/sys/linux/net/getprtname.c: Ditto. * libc/sys/linux/net/getprtname_r.c: Ditto. * libc/sys/linux/net/getrpcbyname.c: Ditto. * libc/sys/linux/net/getrpcbyname_r.c: Ditto. * libc/sys/linux/net/getrpcbynumber.c: Ditto. * libc/sys/linux/net/getrpcbynumber_r.c: Ditto. * libc/sys/linux/net/getrpcent.c: Ditto. * libc/sys/linux/net/getrpcent_r.c: Ditto. * libc/sys/linux/net/getservent_r.c: Ditto. * libc/sys/linux/net/getsrvbynm.c: Ditto. * libc/sys/linux/net/getsrvbynm_r.c: Ditto. * libc/sys/linux/net/getsrvbypt.c: Ditto. * libc/sys/linux/net/getsrvbypt_r.c: Ditto. * libc/sys/linux/net/grp-lookup.c: Ditto. * libc/sys/linux/net/herrno.c: Ditto. * libc/sys/linux/net/hosts-lookup.c: Ditto. * libc/sys/linux/net/ifaddrs.h: Ditto. * libc/sys/linux/net/ifreq.c: Ditto. * libc/sys/linux/net/ifreq.h: Ditto. * libc/sys/linux/net/in6_addr.c: Ditto. * libc/sys/linux/net/inet6_option.c: Ditto. * libc/sys/linux/net/inet_mkadr.c: Ditto. * libc/sys/linux/net/inet_net.c: Ditto. * libc/sys/linux/net/key-lookup.c: Ditto. * libc/sys/linux/net/local.h: Ditto. * libc/sys/linux/net/netgroup.h: Ditto. * libc/sys/linux/net/netgrp-lookup.c: Ditto. * libc/sys/linux/net/network-lookup.c: Ditto. * libc/sys/linux/net/not-cancel.h: Ditto. * libc/sys/linux/net/ns_samedomain.c: Ditto. * libc/sys/linux/net/nscd-types.h: Ditto. * libc/sys/linux/net/nss.h: Ditto. * libc/sys/linux/net/nsswitch.c: Ditto. * libc/sys/linux/net/nsswitch.h: Ditto. * libc/sys/linux/net/opensock.c: Ditto. * libc/sys/linux/net/proto-lookup.c: Ditto. * libc/sys/linux/net/pwd-lookup.c: Ditto. * libc/sys/linux/net/res_debug.h: Ditto. * libc/sys/linux/net/res_hconf.c: Ditto. * libc/sys/linux/net/res_hconf.h: Ditto. * libc/sys/linux/net/rexec.c: Ditto. * libc/sys/linux/net/rpc-lookup.c: Ditto. * libc/sys/linux/net/ruserpass.c: Ditto. * libc/sys/linux/net/service-lookup.c: Ditto. * libc/sys/linux/net/spwd-lookup.c: Ditto. * libc/sys/linux/net/nscd/nscd-client.h: Ditto. * libc/sys/linux/net/nscd/nscd_proto.h: Ditto. --- newlib/libc/sys/linux/net/gethostbydns.c | 815 ------------------------------- 1 file changed, 815 deletions(-) delete mode 100644 newlib/libc/sys/linux/net/gethostbydns.c (limited to 'newlib/libc/sys/linux/net/gethostbydns.c') diff --git a/newlib/libc/sys/linux/net/gethostbydns.c b/newlib/libc/sys/linux/net/gethostbydns.c deleted file mode 100644 index 9c80539f2..000000000 --- a/newlib/libc/sys/linux/net/gethostbydns.c +++ /dev/null @@ -1,815 +0,0 @@ -/* - * ++Copyright++ 1985, 1988, 1993 - * - - * Copyright (c) 1985, 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * 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. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 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. - * - * 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. - * - - * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * - * 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. - * - * 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. - * - - * --Copyright-- - */ - - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93"; -static char fromrcsid[] = "From: Id: gethnamaddr.c,v 8.23 1998/04/07 04:59:46 vixie Exp $"; -#endif /* LIBC_SCCS and not lint */ -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "res_config.h" - -#define SPRINTF(x) ((size_t)sprintf x) - -static const char AskedForGot[] = - "gethostby*.gethostanswer: asked for \"%s\", got \"%s\""; - -#ifdef RESOLVSORT -static void addrsort(char **, int); -#endif - -u_int32_t _getlong(const u_char *src); -u_int16_t _getshort(const u_char *src); - -#ifdef DEBUG -static void dbgprintf(char *, int); -#endif - -#if PACKETSZ > 1024 -#define MAXPACKET PACKETSZ -#else -#define MAXPACKET 1024 -#endif - -typedef union { - HEADER hdr; - u_char buf[MAXPACKET]; -} querybuf; - -typedef union { - int32_t al; - char ac; -} align; - -extern int h_errno; -int _dns_ttl_; - -#ifdef DEBUG -static void -dbgprintf(msg, num) - char *msg; - int num; -{ - if (_res.options & RES_DEBUG) { - int save = errno; - - printf(msg, num); - errno = save; - } -} -#else -# define dbgprintf(msg, num) /*nada*/ -#endif - -#define BOUNDED_INCR(x) \ - do { \ - cp += x; \ - if (cp > eom) { \ - *herr = NO_RECOVERY; \ - return (NULL); \ - } \ - } while (0) - -#define BOUNDS_CHECK(ptr, count) \ - do { \ - if ((ptr) + (count) > eom) { \ - *herr = NO_RECOVERY; \ - return (NULL); \ - } \ - } while (0) - -static struct hostent * -gethostanswer(answer, anslen, qname, qtype, host, hostbuf, hostbuflen, herr) - const querybuf *answer; - int anslen; - const char *qname; - int qtype; - struct hostent *host; - char *hostbuf; - int hostbuflen; - int *herr; -{ - const HEADER *hp; - const u_char *cp; - int n; - const u_char *eom, *erdata; - char *bp, **ap, **hap; - int type, class, buflen, ancount, qdcount; - int haveanswer, had_error; - int toobig = 0; - char tbuf[MAXDNAME]; - const char *tname; - int (*name_ok)(const char *); - - tname = qname; - host->h_name = NULL; - eom = answer->buf + anslen; - switch (qtype) { - case T_A: - case T_AAAA: - name_ok = res_hnok; - break; - case T_PTR: - name_ok = res_dnok; - break; - default: - *herr = NO_RECOVERY; - return (NULL); /* XXX should be abort(); */ - } - /* - * find first satisfactory answer - */ - hp = &answer->hdr; - ancount = ntohs(hp->ancount); - qdcount = ntohs(hp->qdcount); - bp = hostbuf; - buflen = hostbuflen; - cp = answer->buf; - BOUNDED_INCR(HFIXEDSZ); - if (qdcount != 1) { - *herr = NO_RECOVERY; - return (NULL); - } - n = dn_expand(answer->buf, eom, cp, bp, buflen); - if ((n < 0) || !(*name_ok)(bp)) { - *herr = NO_RECOVERY; - return (NULL); - } - BOUNDED_INCR(n + QFIXEDSZ); - if (qtype == T_A || qtype == T_AAAA) { - /* res_send() has already verified that the query name is the - * same as the one we sent; this just gets the expanded name - * (i.e., with the succeeding search-domain tacked on). - */ - n = strlen(bp) + 1; /* for the \0 */ - if (n >= MAXHOSTNAMELEN) { - *herr = NO_RECOVERY; - return (NULL); - } - host->h_name = bp; - bp += n; - buflen -= n; - /* The qname can be abbreviated, but h_name is now absolute. */ - qname = host->h_name; - } - ap = host->__host_aliases; - *ap = NULL; - host->h_aliases = host->__host_aliases; - hap = host->__host_addrs; - *hap = NULL; - host->h_addr_list = host->__host_addrs; - haveanswer = 0; - had_error = 0; - _dns_ttl_ = -1; - while (ancount-- > 0 && cp < eom && !had_error) { - n = dn_expand(answer->buf, eom, cp, bp, buflen); - if ((n < 0) || !(*name_ok)(bp)) { - had_error++; - continue; - } - cp += n; /* name */ - BOUNDS_CHECK(cp, 3 * INT16SZ + INT32SZ); - type = _getshort(cp); - cp += INT16SZ; /* type */ - class = _getshort(cp); - cp += INT16SZ; /* class */ - if (qtype == T_A && type == T_A) - _dns_ttl_ = _getlong(cp); - cp += INT32SZ; /* TTL */ - n = _getshort(cp); - cp += INT16SZ; /* len */ - BOUNDS_CHECK(cp, n); - erdata = cp + n; - if (class != C_IN) { - /* XXX - debug? syslog? */ - cp += n; - continue; /* XXX - had_error++ ? */ - } - if ((qtype == T_A || qtype == T_AAAA) && type == T_CNAME) { - if (ap >= &host->__host_aliases[MAXALIASES-1]) - continue; - n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf); - if ((n < 0) || !(*name_ok)(tbuf)) { - had_error++; - continue; - } - cp += n; - if (cp != erdata) { - *herr = NO_RECOVERY; - return (NULL); - } - /* Store alias. */ - *ap++ = bp; - n = strlen(bp) + 1; /* for the \0 */ - if (n >= MAXHOSTNAMELEN) { - had_error++; - continue; - } - bp += n; - buflen -= n; - /* Get canonical name. */ - n = strlen(tbuf) + 1; /* for the \0 */ - if (n > buflen || n >= MAXHOSTNAMELEN) { - had_error++; - continue; - } - strcpy(bp, tbuf); - host->h_name = bp; - bp += n; - buflen -= n; - continue; - } - if (qtype == T_PTR && type == T_CNAME) { - n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf); - if (n < 0 || !res_dnok(tbuf)) { - had_error++; - continue; - } - cp += n; - if (cp != erdata) { - *herr = NO_RECOVERY; - return (NULL); - } - /* Get canonical name. */ - n = strlen(tbuf) + 1; /* for the \0 */ - if (n > buflen || n >= MAXHOSTNAMELEN) { - had_error++; - continue; - } - strcpy(bp, tbuf); - tname = bp; - bp += n; - buflen -= n; - continue; - } - if (type != qtype) { - if (type != T_SIG) - syslog(LOG_NOTICE|LOG_AUTH, - "gethostby*.gethostanswer: asked for \"%s %s %s\", got type \"%s\"", - qname, p_class(C_IN), p_type(qtype), - p_type(type)); - cp += n; - continue; /* XXX - had_error++ ? */ - } - switch (type) { - case T_PTR: - if (strcasecmp(tname, bp) != 0) { - syslog(LOG_NOTICE|LOG_AUTH, - AskedForGot, qname, bp); - cp += n; - continue; /* XXX - had_error++ ? */ - } - n = dn_expand(answer->buf, eom, cp, bp, buflen); - if ((n < 0) || !res_hnok(bp)) { - had_error++; - break; - } -#if MULTI_PTRS_ARE_ALIASES - cp += n; - if (cp != erdata) { - *herr = NO_RECOVERY; - return (NULL); - } - if (!haveanswer) - host->h_name = bp; - else if (ap < &host->__host_aliases[MAXALIASES-1]) - *ap++ = bp; - else - n = -1; - if (n != -1) { - n = strlen(bp) + 1; /* for the \0 */ - if (n >= MAXHOSTNAMELEN) { - had_error++; - break; - } - bp += n; - buflen -= n; - } - break; -#else - host->h_name = bp; - if (_res.options & RES_USE_INET6) { - n = strlen(bp) + 1; /* for the \0 */ - if (n >= MAXHOSTNAMELEN) { - had_error++; - break; - } - bp += n; - buflen -= n; - _map_v4v6_hostent(host, &bp, &buflen); - } - *herr = NETDB_SUCCESS; - return host; -#endif - case T_A: - case T_AAAA: - if (strcasecmp(host->h_name, bp) != 0) { - syslog(LOG_NOTICE|LOG_AUTH, - AskedForGot, host->h_name, bp); - cp += n; - continue; /* XXX - had_error++ ? */ - } - if (n != host->h_length) { - cp += n; - continue; - } - if (!haveanswer) { - int nn; - - host->h_name = bp; - nn = strlen(bp) + 1; /* for the \0 */ - bp += nn; - buflen -= nn; - } - - bp += sizeof(align) - ((u_long)bp % sizeof(align)); - - if (bp + n >= &hostbuf[hostbuflen]) { - dbgprintf("size (%d) too big\n", n); - had_error++; - continue; - } - if (hap >= &host->__host_addrs[MAXADDRS-1]) { - if (!toobig++) - dbgprintf("Too many addresses (%d)\n", - MAXADDRS); - cp += n; - continue; - } - bcopy(cp, *hap++ = bp, n); - bp += n; - buflen -= n; - cp += n; - if (cp != erdata) { - *herr = NO_RECOVERY; - return (NULL); - } - break; - default: - dbgprintf("Impossible condition (type=%d)\n", type); - *herr = NO_RECOVERY; - return (NULL); - /* BIND has abort() here, too risky on bad data */ - } - if (!had_error) - haveanswer++; - } - if (haveanswer) { - *ap = NULL; - *hap = NULL; -# if defined(RESOLVSORT) - /* - * Note: we sort even if host can take only one address - * in its return structures - should give it the "best" - * address in that case, not some random one - */ - if (_res.nsort && haveanswer > 1 && qtype == T_A) - addrsort(host->__host_addrs, haveanswer); -# endif /*RESOLVSORT*/ - if (!host->h_name) { - n = strlen(qname) + 1; /* for the \0 */ - if (n > buflen || n >= MAXHOSTNAMELEN) - goto no_recovery; - strcpy(bp, qname); - host->h_name = bp; - bp += n; - buflen -= n; - } - if (_res.options & RES_USE_INET6) - _map_v4v6_hostent(host, &bp, &buflen); - *herr = NETDB_SUCCESS; - return host; - } - no_recovery: - *herr = NO_RECOVERY; - return (NULL); -} - -struct hostent * -__dns_getanswer(answer, anslen, qname, qtype, host, hostbuf, hostbuflen, herr) - const char *answer; - int anslen; - const char *qname; - int qtype; - struct hostent *host; - char *hostbuf; - int hostbuflen; - int *herr; -{ - switch(qtype) { - case T_AAAA: - host->h_addrtype = AF_INET6; - host->h_length = IN6ADDRSZ; - break; - case T_A: - default: - host->h_addrtype = AF_INET; - host->h_length = INADDRSZ; - break; - } - - return(gethostanswer((const querybuf *)answer, anslen, qname, qtype, host, hostbuf, hostbuflen, herr)); -} - -int -_dns_gethostbyname(void *rval, void *cb_data, va_list ap) -{ - const char *name; - int af; - querybuf buf; - const char *cp; - char *bp; - int n, size, type, len; - struct hostent *resultbuf; - char *hostbuf; - int buflen; - int *herr; - - name = va_arg(ap, const char *); - af = va_arg(ap, int); - resultbuf = va_arg(ap, struct hostent *); - hostbuf = va_arg(ap, char *); - buflen = va_arg(ap, int); - herr = va_arg(ap, int *); - - if ((_res.options & RES_INIT) == 0 && res_init() == -1) { - *herr = NETDB_INTERNAL; - return NS_UNAVAIL; - } - - switch (af) { - case AF_INET: - size = INADDRSZ; - type = T_A; - break; - case AF_INET6: - size = IN6ADDRSZ; - type = T_AAAA; - break; - default: - *herr = NETDB_INTERNAL; - errno = EAFNOSUPPORT; - return NS_UNAVAIL; - } - - resultbuf->h_addrtype = af; - resultbuf->h_length = size; - - /* - * if there aren't any dots, it could be a user-level alias. - * this is also done in res_query() since we are not the only - * function that looks up host names. - */ - if (!strchr(name, '.') && (cp = __hostalias(name))) - name = cp; - - /* - * disallow names consisting only of digits/dots, unless - * they end in a dot. - */ - if (isdigit((unsigned char)name[0])) - for (cp = name;; ++cp) { - if (!*cp) { - if (*--cp == '.') - break; - /* - * All-numeric, no dot at the end. - * Fake up a hostent as if we'd actually - * done a lookup. - */ - if (inet_pton(af, name, resultbuf->__host_addr) <= 0) { - *herr = HOST_NOT_FOUND; - return NS_NOTFOUND; - } - strncpy(hostbuf, name, MAXDNAME); - hostbuf[MAXDNAME] = '\0'; - bp = hostbuf + MAXDNAME; - len = buflen - MAXDNAME; - resultbuf->h_name = hostbuf; - resultbuf->h_aliases = resultbuf->__host_aliases; - resultbuf->__host_aliases[0] = NULL; - resultbuf->__host_addrs[0] = (char *)resultbuf->__host_addr; - resultbuf->__host_addrs[1] = NULL; - resultbuf->h_addr_list = resultbuf->__host_addrs; - if (_res.options & RES_USE_INET6) - _map_v4v6_hostent(resultbuf, &bp, &len); - *herr = NETDB_SUCCESS; - *(struct hostent **)rval = resultbuf; - return NS_SUCCESS; - } - if (!isdigit((unsigned char)*cp) && *cp != '.') - break; - } - if ((isxdigit((unsigned char)name[0]) && strchr(name, ':') != NULL) || - name[0] == ':') - for (cp = name;; ++cp) { - if (!*cp) { - if (*--cp == '.') - break; - /* - * All-IPv6-legal, no dot at the end. - * Fake up a hostent as if we'd actually - * done a lookup. - */ - if (inet_pton(af, name, resultbuf->__host_addr) <= 0) { - *herr = HOST_NOT_FOUND; - return NS_NOTFOUND; - } - strncpy(hostbuf, name, MAXDNAME); - hostbuf[MAXDNAME] = '\0'; - bp = hostbuf + MAXDNAME; - len = buflen - MAXDNAME; - resultbuf->h_name = hostbuf; - resultbuf->h_aliases = resultbuf->__host_aliases; - resultbuf->__host_aliases[0] = NULL; - resultbuf->__host_addrs[0] = (char *)resultbuf->__host_addr; - resultbuf->__host_addrs[1] = NULL; - resultbuf->h_addr_list = resultbuf->__host_addrs; - *herr = NETDB_SUCCESS; - *(struct hostent **)rval = resultbuf; - return NS_SUCCESS; - } - if (!isxdigit((unsigned char)*cp) && *cp != ':' && *cp != '.') - break; - } - - if ((n = res_search(name, C_IN, type, buf.buf, sizeof(buf))) < 0) { - dbgprintf("res_search failed (%d)\n", n); - return NS_UNAVAIL; - } - *(struct hostent **)rval = gethostanswer(&buf, n, name, type, resultbuf, hostbuf, buflen, herr); - return (*(struct hostent **)rval != NULL) ? NS_SUCCESS : NS_NOTFOUND; -} - -int -_dns_gethostbyaddr(void *rval, void *cb_data, va_list ap) -{ - const char *addr; /* XXX should have been def'd as u_char! */ - int len, af; - const u_char *uaddr; - static const u_char mapped[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0xff,0xff }; - static const u_char tunnelled[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 }; - int n, size; - querybuf buf; - struct hostent *hp; - char qbuf[MAXDNAME+1], *qp; -#ifdef SUNSECURITY - struct hostent *rhp; - char **haddr; - u_long old_options; - char hname2[MAXDNAME+1]; -#endif /*SUNSECURITY*/ - struct hostent *resultbuf; - char *hostbuf; - int buflen; - int *herr; - - addr = va_arg(ap, const char *); - uaddr = (const u_char *)addr; - len = va_arg(ap, int); - af = va_arg(ap, int); - resultbuf = va_arg(ap, struct hostent *); - hostbuf = va_arg(ap, char *); - buflen = va_arg(ap, int); - herr = va_arg(ap, int *); - - if ((_res.options & RES_INIT) == 0 && res_init() == -1) { - *herr = NETDB_INTERNAL; - return NS_UNAVAIL; - } - if (af == AF_INET6 && len == IN6ADDRSZ && - (!memcmp(uaddr, mapped, sizeof mapped) || - !memcmp(uaddr, tunnelled, sizeof tunnelled))) { - /* Unmap. */ - addr += sizeof mapped; - uaddr += sizeof mapped; - af = AF_INET; - len = INADDRSZ; - } - switch (af) { - case AF_INET: - size = INADDRSZ; - break; - case AF_INET6: - size = IN6ADDRSZ; - break; - default: - errno = EAFNOSUPPORT; - *herr = NETDB_INTERNAL; - return NS_UNAVAIL; - } - if (size != len) { - errno = EINVAL; - *herr = NETDB_INTERNAL; - return NS_UNAVAIL; - } - switch (af) { - case AF_INET: - (void) sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa", - (uaddr[3] & 0xff), - (uaddr[2] & 0xff), - (uaddr[1] & 0xff), - (uaddr[0] & 0xff)); - break; - case AF_INET6: - qp = qbuf; - for (n = IN6ADDRSZ - 1; n >= 0; n--) { - qp += SPRINTF((qp, "%x.%x.", - uaddr[n] & 0xf, - (uaddr[n] >> 4) & 0xf)); - } - strcpy(qp, "ip6.int"); - break; - default: - abort(); - } - n = res_query(qbuf, C_IN, T_PTR, (u_char *)buf.buf, sizeof buf.buf); - if (n < 0) { - dbgprintf("res_query failed (%d)\n", n); - return NS_UNAVAIL; - } - if (n > sizeof buf.buf) { - dbgprintf("static buffer is too small (%d)\n", n); - return NS_UNAVAIL; - } - if (!(hp = gethostanswer(&buf, n, qbuf, T_PTR, resultbuf, hostbuf, buflen, herr))) - return NS_NOTFOUND; /* *herr was set by gethostanswer() */ -#ifdef SUNSECURITY - if (af == AF_INET) { - /* - * turn off search as the name should be absolute, - * 'localhost' should be matched by defnames - */ - strncpy(hname2, hp->h_name, MAXDNAME); - hname2[MAXDNAME] = '\0'; - old_options = _res.options; - _res.options &= ~RES_DNSRCH; - _res.options |= RES_DEFNAMES; - if (!(rhp = gethostbyname(hname2))) { - syslog(LOG_NOTICE|LOG_AUTH, - "gethostbyaddr: No A record for %s (verifying [%s])", - hname2, inet_ntoa(*((struct in_addr *)addr))); - _res.options = old_options; - *herr = HOST_NOT_FOUND; - return NS_NOTFOUND; - } - _res.options = old_options; - for (haddr = rhp->h_addr_list; *haddr; haddr++) - if (!memcmp(*haddr, addr, INADDRSZ)) - break; - if (!*haddr) { - syslog(LOG_NOTICE|LOG_AUTH, - "gethostbyaddr: A record of %s != PTR record [%s]", - hname2, inet_ntoa(*((struct in_addr *)addr))); - *herr = HOST_NOT_FOUND; - return NS_NOTFOUND; - } - } -#endif /*SUNSECURITY*/ - hp->h_addrtype = af; - hp->h_length = len; - bcopy(addr, resultbuf->__host_addr, len); - resultbuf->__host_addrs[0] = (char *)resultbuf->__host_addr; - resultbuf->__host_addrs[1] = NULL; - if (af == AF_INET && (_res.options & RES_USE_INET6)) { - _map_v4v6_address((char*)resultbuf->__host_addr, (char*)resultbuf->__host_addr); - hp->h_addrtype = AF_INET6; - hp->h_length = IN6ADDRSZ; - } - *herr = NETDB_SUCCESS; - *(struct hostent **)rval = hp; - return (hp != NULL) ? NS_SUCCESS : NS_NOTFOUND; -} - -#ifdef RESOLVSORT -static void -addrsort(ap, num) - char **ap; - int num; -{ - int i, j; - char **p; - short aval[MAXADDRS]; - int needsort = 0; - - p = ap; - for (i = 0; i < num; i++, p++) { - for (j = 0 ; (unsigned)j < _res.nsort; j++) - if (_res.sort_list[j].addr.s_addr == - (((struct in_addr *)(*p))->s_addr & _res.sort_list[j].mask)) - break; - aval[i] = j; - if (needsort == 0 && i > 0 && j < aval[i-1]) - needsort = i; - } - if (!needsort) - return; - - while (needsort < num) { - for (j = needsort - 1; j >= 0; j--) { - if (aval[j] > aval[j+1]) { - char *hp; - - i = aval[j]; - aval[j] = aval[j+1]; - aval[j+1] = i; - - hp = ap[j]; - ap[j] = ap[j+1]; - ap[j+1] = hp; - - } else - break; - } - needsort++; - } -} -#endif -void -_sethostdnsent(stayopen) - int stayopen; -{ - if ((_res.options & RES_INIT) == 0 && res_init() == -1) - return; - if (stayopen) - _res.options |= RES_STAYOPEN | RES_USEVC; -} - -void -_endhostdnsent() -{ - _res.options &= ~(RES_STAYOPEN | RES_USEVC); - res_close(); -} -- cgit v1.2.3