/*
* Portions Copyright (C) 2004-2006, 2008 Internet Systems Consortium, Inc. ("ISC")
* Portions Copyright (C) 1996-2003 Internet Software Consortium.
*
* 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 ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC 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 (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
* 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.
*/
/* from gethostnamadr.c 8.1 (Berkeley) 6/4/93 */
/* BIND Id: gethnamaddr.c,v 8.15 1996/05/22 04:56:30 vixie Exp $ */
#endif /* LIBC_SCCS and not lint */
/* Imports. */
#include "port_before.h"
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
#include <netdb.h>
#include <resolv.h>
#include <stdio.h>
#include <string.h>
#include <syslog.h>
#include <isc/memcluster.h>
#include <irs.h>
#include "port_after.h"
#include "irs_p.h"
#include "dns_p.h"
#ifdef SPRINTF_CHAR
#else
#endif
/* Definitions. */
had_error++; \
continue; \
} else (void)0
typedef union {
} querybuf;
struct dns_res_target {
#if 0
int n; /*%< result length */
#endif
};
struct pvt {
void (*free_res)(void *);
};
typedef union {
char ac;
} align;
/* Note: the IPv6 loopback address is in the "tunnel" space */
/* Forwards. */
int af);
struct __res_state *res,
void (*free_res)(void *));
char *ep);
/* Exports. */
struct irs_ho *
return (NULL);
}
return (NULL);
}
return (ho);
}
/* Methods. */
static void
}
static struct hostent *
return (NULL);
if (hp)
return (hp);
}
}
static struct hostent *
{
int n, size;
const char *cp;
struct dns_res_target *q, *p;
return (NULL);
q = memget(sizeof(*q));
if (q == NULL) {
goto cleanup;
}
memset(q, 0, sizeof(*q));
switch (af) {
case AF_INET:
q->action = RESTGT_DOALWAYS;
break;
case AF_INET6:
q->action = RESTGT_DOALWAYS;
break;
default:
goto cleanup;
}
/*
* if there aren't any dots, it could be a user-level alias.
* this is also done in res_nquery() since we are not the only
* function that looks up host names.
*/
for (p = q; p; p = p->next) {
switch(p->action) {
case RESTGT_DOALWAYS:
break;
case RESTGT_AFTERFAILURE:
if (querystate == RESQRY_SUCCESS)
continue;
break;
case RESTGT_IGNORE:
continue;
}
continue;
}
goto cleanup; /*%< no more loop is necessary */
continue;
}
if (q != NULL)
memput(q, sizeof(*q));
return(hp);
}
static struct hostent *
{
char *qp;
int n, size, i;
return (NULL);
q = memget(sizeof(*q));
goto cleanup;
}
memset(q, 0, sizeof(*q));
/* Unmap. */
}
switch (af) {
case AF_INET:
q->action = RESTGT_DOALWAYS;
break;
case AF_INET6:
q->action = RESTGT_DOALWAYS;
else
break;
default:
goto cleanup;
}
goto cleanup;
}
switch (af) {
case AF_INET:
(uaddr[0] & 0xff));
break;
case AF_INET6:
if (q->action != RESTGT_IGNORE) {
for (n = IN6ADDRSZ - 1; n >= 0; n--) {
uaddr[n] & 0xf,
if (i != 4)
abort();
qp += i;
}
sizeof q->qname) {
goto cleanup;
}
}
for (n = IN6ADDRSZ - 1; n >= 0; n--) {
uaddr[n] & 0xf,
if (i != 4)
abort();
qp += i;
}
goto cleanup;
}
}
break;
default:
abort();
}
for (p = q; p; p = p->next) {
switch(p->action) {
case RESTGT_DOALWAYS:
break;
case RESTGT_AFTERFAILURE:
if (querystate == RESQRY_SUCCESS)
continue;
break;
case RESTGT_IGNORE:
continue;
}
continue;
}
if (!hp) {
continue;
}
}
goto cleanup; /*%< no more loop is necessary. */
}
if (q != NULL)
memput(q, sizeof(*q));
return(hp);
}
static struct hostent *
return (NULL);
}
static void
/* NOOP */
}
static void
}
static struct __res_state *
if (!res) {
return (NULL);
}
}
}
/* XXX */
const char *));
static struct addrinfo *
{
int n;
const char *cp;
return (NULL);
q = memget(sizeof(*q));
goto cleanup;
}
case AF_UNSPEC:
/* prefer IPv6 */
q->action = RESTGT_DOALWAYS;
break;
case AF_INET:
q->action = RESTGT_DOALWAYS;
break;
case AF_INET6:
q->action = RESTGT_DOALWAYS;
break;
default:
goto cleanup;
}
/*
* if there aren't any dots, it could be a user-level alias.
* this is also done in res_nquery() since we are not the only
* function that looks up host names.
*/
for (p = q; p; p = p->next) {
switch(p->action) {
case RESTGT_DOALWAYS:
break;
case RESTGT_AFTERFAILURE:
if (querystate == RESQRY_SUCCESS)
continue;
break;
case RESTGT_IGNORE:
continue;
}
continue;
}
if (ai) {
} else
}
if (q != NULL)
memput(q, sizeof(*q));
}
static void
void (*free_res)(void *)) {
}
}
/* Private. */
static struct hostent *
{
int (*name_ok)(const char *);
const char *tname;
const char *hname;
switch (qtype) {
case T_A:
case T_AAAA:
break;
case T_PTR:
break;
default:
abort();
}
/*
* Find first satisfactory answer.
*/
return (NULL);
}
if (qdcount != 1) {
return (NULL);
}
return (NULL);
}
return (NULL);
}
/* res_nsend() 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).
*/
if (n > MAXHOSTNAMELEN) {
return (NULL);
}
bp += n;
/* The qname can be abbreviated, but hname is now absolute. */
}
haveanswer = 0;
had_error = 0;
had_error++;
continue;
}
cp += n; /*%< name */
BOUNDS_CHECK(cp, n);
cp += n;
continue;
}
if (haveanswer) {
#ifdef LOG_SECURITY
level |= LOG_SECURITY;
#endif
"gethostans: possible attempt to exploit buffer overflow while looking up %s",
}
had_error++;
continue;
}
cp += n;
/* Store alias. */
continue;
bp += n;
/* Get canonical name. */
had_error++;
continue;
}
bp += n;
continue;
}
had_error++;
continue;
}
cp += n;
#ifdef RES_USE_DNAME
#endif
{
/*
* We may be able to check this regardless
* of the USE_DNAME bit, but we add the check
* for now since the DNAME support is
* experimental.
*/
continue;
}
/* Get canonical name. */
had_error++;
continue;
}
bp += n;
continue;
}
cp += n;
continue;
}
cp += n;
continue;
}
switch (type) {
case T_PTR:
/* addrinfo never needs T_PTR */
cp += n;
continue;
}
cp += n;
continue;
}
n >= MAXHOSTNAMELEN) {
had_error++;
break;
}
cp += n;
if (!haveanswer) {
}
else
n = -1;
if (n != -1) {
bp += n;
}
break;
case T_A:
case T_AAAA:
cp += n;
continue;
}
cp += n;
continue;
}
cp += n;
continue;
}
/* make addrinfo. don't overwrite constant PAI */
(const char *)cp);
had_error++;
if (!haveanswer) {
int nn;
if (nn >= MAXHOSTNAMELEN) {
cp += n;
had_error++;
continue;
}
}
/* Ensure alignment. */
~(sizeof(align) - 1));
/* Avoid overflows. */
had_error++;
continue;
}
if (ret_aip) { /*%< need addrinfo. keep it. */
int m;
if (m < 0) {
had_error++;
break;
}
if (m == 0)
continue;
hap++;
bp += m;
}
}
cp += n;
break;
default:
abort();
}
if (!had_error)
haveanswer++;
}
if (haveanswer) {
goto no_recovery;
bp += n;
}
} else {
}
else {
}
}
return(NULL);
}
}
/* this should be impossible, but check it for safety */
}
if (error == NETDB_SUCCESS)
else
return(NULL);
}
static int
{
int addrlen;
char *addrp;
const char **tap;
case AF_INET6:
break;
case AF_INET:
break;
default:
return(-1); /*%< abort? */
}
/* Ensure alignment. */
~(sizeof(align) - 1));
/* Avoid overflows. */
return(-1);
return(0); /*%< fail, but not treat it as an error. */
/* Suppress duplicates. */
tap++)
break;
return (0);
}
static void
char **ap;
return;
if (i != 0)
i = sizeof(align) - i;
/* Out of memory. Truncate address list here. */
return;
}
*bpp += i;
}
}
static void
char **p;
p = ap;
for (i = 0; i < num; i++, p++) {
break;
aval[i] = j;
needsort = i;
}
if (!needsort)
return;
for (j = needsort - 1; j >= 0; j--) {
char *hp;
i = aval[j];
aval[j+1] = i;
} else
break;
}
needsort++;
}
}
static int
return (-1);
return (-1);
return (0);
}