2024-01-01 18:12:26 +00:00
|
|
|
/* Copyright (C) 1997-2024 Free Software Foundation, Inc.
|
2016-05-02 13:25:20 +00: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 05:40:42 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2016-05-02 13:25:20 +00:00
|
|
|
|
2000-07-21 04:12:25 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1996,1999 by Internet Software Consortium.
|
1997-09-16 00:42:43 +00: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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2000-07-21 04:12:25 +00:00
|
|
|
/*
|
|
|
|
* This file is primarily maintained by <tytso@mit.edu> and <ghudson@mit.edu>.
|
1997-09-16 00:42:43 +00:00
|
|
|
*/
|
|
|
|
|
2000-07-21 04:12:25 +00:00
|
|
|
/*
|
|
|
|
* hesiod.c --- the core portion of the hesiod resolver.
|
1997-09-16 00:42:43 +00:00
|
|
|
*
|
2000-07-21 04:12:25 +00:00
|
|
|
* This file is derived from the hesiod library from Project Athena;
|
|
|
|
* It has been extensively rewritten by Theodore Ts'o to have a more
|
|
|
|
* thread-safe interface.
|
1997-09-16 00:42:43 +00:00
|
|
|
*/
|
|
|
|
|
2000-07-21 04:12:25 +00:00
|
|
|
/* Imports */
|
1997-09-16 00:42:43 +00:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/nameser.h>
|
2000-07-21 04:12:25 +00:00
|
|
|
|
1997-09-16 00:42:43 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <resolv.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2000-07-21 04:12:25 +00:00
|
|
|
|
1997-09-16 00:42:43 +00:00
|
|
|
#include "hesiod.h"
|
|
|
|
#include "hesiod_p.h"
|
|
|
|
|
2000-07-21 04:12:25 +00:00
|
|
|
#define _PATH_HESIOD_CONF "/etc/hesiod.conf"
|
1997-09-16 00:42:43 +00:00
|
|
|
|
2000-07-21 04:12:25 +00:00
|
|
|
/* Forward */
|
|
|
|
|
|
|
|
static int parse_config_file(struct hesiod_p *ctx, const char *filename);
|
|
|
|
static char ** get_txt_records(struct hesiod_p *ctx, int class,
|
|
|
|
const char *name);
|
|
|
|
|
|
|
|
/* Public */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is called to initialize a hesiod_p.
|
|
|
|
*/
|
1998-02-20 18:45:36 +00:00
|
|
|
int
|
2000-07-21 04:12:25 +00:00
|
|
|
hesiod_init(void **context) {
|
|
|
|
struct hesiod_p *ctx;
|
|
|
|
const char *configname;
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
ctx = malloc(sizeof(struct hesiod_p));
|
2001-02-03 08:30:32 +00:00
|
|
|
if (ctx == 0)
|
2000-07-21 04:12:25 +00:00
|
|
|
return (-1);
|
|
|
|
|
|
|
|
ctx->LHS = NULL;
|
|
|
|
ctx->RHS = NULL;
|
2005-06-15 04:14:52 +00:00
|
|
|
/* Set default query classes. */
|
|
|
|
ctx->classes[0] = C_IN;
|
|
|
|
ctx->classes[1] = C_HS;
|
2000-07-21 04:12:25 +00:00
|
|
|
|
2012-07-25 17:46:22 +00:00
|
|
|
configname = __libc_secure_getenv("HESIOD_CONFIG");
|
2000-07-21 04:12:25 +00:00
|
|
|
if (!configname)
|
|
|
|
configname = _PATH_HESIOD_CONF;
|
|
|
|
if (parse_config_file(ctx, configname) < 0) {
|
|
|
|
goto cleanup;
|
1997-09-16 00:42:43 +00:00
|
|
|
}
|
2000-07-21 04:12:25 +00:00
|
|
|
/*
|
|
|
|
* The default RHS can be overridden by an environment
|
|
|
|
* variable.
|
|
|
|
*/
|
2012-07-25 17:46:22 +00:00
|
|
|
if ((cp = __libc_secure_getenv("HES_DOMAIN")) != NULL) {
|
2001-02-03 08:30:32 +00:00
|
|
|
free(ctx->RHS);
|
2000-07-21 04:12:25 +00:00
|
|
|
ctx->RHS = malloc(strlen(cp)+2);
|
2001-02-03 08:30:32 +00:00
|
|
|
if (!ctx->RHS)
|
2000-07-21 04:12:25 +00:00
|
|
|
goto cleanup;
|
|
|
|
if (cp[0] == '.')
|
|
|
|
strcpy(ctx->RHS, cp);
|
|
|
|
else {
|
2001-02-03 08:30:32 +00:00
|
|
|
ctx->RHS[0] = '.';
|
|
|
|
strcpy(ctx->RHS + 1, cp);
|
2000-07-21 04:12:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there is no default hesiod realm set, we return an
|
|
|
|
* error.
|
|
|
|
*/
|
2005-06-15 06:44:01 +00:00
|
|
|
if (!ctx->RHS) {
|
2000-07-21 04:12:25 +00:00
|
|
|
__set_errno(ENOEXEC);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2001-02-03 07:01:11 +00:00
|
|
|
|
2000-07-21 04:12:25 +00:00
|
|
|
*context = ctx;
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
hesiod_end(ctx);
|
|
|
|
return (-1);
|
1997-09-16 00:42:43 +00:00
|
|
|
}
|
|
|
|
|
2000-07-21 04:12:25 +00:00
|
|
|
/*
|
|
|
|
* This function deallocates the hesiod_p
|
|
|
|
*/
|
1998-02-20 18:45:36 +00:00
|
|
|
void
|
2000-07-21 04:12:25 +00:00
|
|
|
hesiod_end(void *context) {
|
|
|
|
struct hesiod_p *ctx = (struct hesiod_p *) context;
|
|
|
|
int save_errno = errno;
|
|
|
|
|
2001-02-03 08:30:32 +00:00
|
|
|
free(ctx->RHS);
|
|
|
|
free(ctx->LHS);
|
2000-07-21 04:12:25 +00:00
|
|
|
free(ctx);
|
|
|
|
__set_errno(save_errno);
|
1997-09-16 00:42:43 +00:00
|
|
|
}
|
|
|
|
|
2000-07-21 04:12:25 +00:00
|
|
|
/*
|
|
|
|
* This function takes a hesiod (name, type) and returns a DNS
|
1997-09-16 00:42:43 +00:00
|
|
|
* name which is to be resolved.
|
|
|
|
*/
|
1998-02-20 18:45:36 +00:00
|
|
|
char *
|
2000-07-21 04:12:25 +00:00
|
|
|
hesiod_to_bind(void *context, const char *name, const char *type) {
|
|
|
|
struct hesiod_p *ctx = (struct hesiod_p *) context;
|
|
|
|
char *bindname;
|
|
|
|
char **rhs_list = NULL;
|
|
|
|
const char *RHS, *cp;
|
2001-02-03 08:30:32 +00:00
|
|
|
char *endp;
|
2000-07-21 04:12:25 +00:00
|
|
|
|
|
|
|
/* Decide what our RHS is, and set cp to the end of the actual name. */
|
|
|
|
if ((cp = strchr(name, '@')) != NULL) {
|
|
|
|
if (strchr(cp + 1, '.'))
|
|
|
|
RHS = cp + 1;
|
|
|
|
else if ((rhs_list = hesiod_resolve(context, cp + 1,
|
|
|
|
"rhs-extension")) != NULL)
|
|
|
|
RHS = *rhs_list;
|
|
|
|
else {
|
|
|
|
__set_errno(ENOENT);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
RHS = ctx->RHS;
|
|
|
|
cp = name + strlen(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate the space we need, including up to three periods and
|
|
|
|
* the terminating NUL.
|
|
|
|
*/
|
|
|
|
if ((bindname = malloc((cp - name) + strlen(type) + strlen(RHS) +
|
|
|
|
(ctx->LHS ? strlen(ctx->LHS) : 0) + 4)) == NULL) {
|
|
|
|
if (rhs_list)
|
|
|
|
hesiod_free_list(context, rhs_list);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now put together the DNS name. */
|
2001-02-03 08:30:32 +00:00
|
|
|
endp = (char *) __mempcpy (bindname, name, cp - name);
|
|
|
|
*endp++ = '.';
|
|
|
|
endp = (char *) __stpcpy (endp, type);
|
2000-07-21 04:12:25 +00:00
|
|
|
if (ctx->LHS) {
|
|
|
|
if (ctx->LHS[0] != '.')
|
2001-02-03 08:30:32 +00:00
|
|
|
*endp++ = '.';
|
|
|
|
endp = __stpcpy (endp, ctx->LHS);
|
1997-09-16 00:42:43 +00:00
|
|
|
}
|
2000-07-21 04:12:25 +00:00
|
|
|
if (RHS[0] != '.')
|
2001-02-03 08:30:32 +00:00
|
|
|
*endp++ = '.';
|
|
|
|
strcpy (endp, RHS);
|
2000-07-21 04:12:25 +00:00
|
|
|
|
|
|
|
if (rhs_list)
|
|
|
|
hesiod_free_list(context, rhs_list);
|
|
|
|
|
|
|
|
return (bindname);
|
1997-09-16 00:42:43 +00:00
|
|
|
}
|
|
|
|
|
2000-07-21 04:12:25 +00:00
|
|
|
/*
|
|
|
|
* This is the core function. Given a hesiod (name, type), it
|
1997-09-16 00:42:43 +00:00
|
|
|
* returns an array of strings returned by the resolver.
|
|
|
|
*/
|
1998-02-20 18:45:36 +00:00
|
|
|
char **
|
2000-07-21 04:12:25 +00:00
|
|
|
hesiod_resolve(void *context, const char *name, const char *type) {
|
|
|
|
struct hesiod_p *ctx = (struct hesiod_p *) context;
|
|
|
|
char *bindname = hesiod_to_bind(context, name, type);
|
|
|
|
char **retvec;
|
|
|
|
|
|
|
|
if (bindname == NULL)
|
|
|
|
return (NULL);
|
1997-09-16 00:42:43 +00:00
|
|
|
|
2005-06-15 04:14:52 +00:00
|
|
|
retvec = get_txt_records(ctx, ctx->classes[0], bindname);
|
|
|
|
|
|
|
|
if (retvec == NULL && (errno == ENOENT || errno == ECONNREFUSED) && ctx->classes[1])
|
|
|
|
retvec = get_txt_records(ctx, ctx->classes[1], bindname);
|
2001-02-03 07:01:11 +00:00
|
|
|
|
1997-09-16 00:42:43 +00:00
|
|
|
|
2000-07-21 04:12:25 +00:00
|
|
|
free(bindname);
|
|
|
|
return (retvec);
|
1997-09-16 00:42:43 +00:00
|
|
|
}
|
|
|
|
|
1998-02-20 18:45:36 +00:00
|
|
|
void
|
2000-07-21 04:12:25 +00:00
|
|
|
hesiod_free_list(void *context, char **list) {
|
|
|
|
char **p;
|
1997-09-16 00:42:43 +00:00
|
|
|
|
2000-07-21 04:12:25 +00:00
|
|
|
for (p = list; *p; p++)
|
|
|
|
free(*p);
|
|
|
|
free(list);
|
1997-09-16 00:42:43 +00:00
|
|
|
}
|
|
|
|
|
2000-07-21 04:12:25 +00:00
|
|
|
/*
|
|
|
|
* This function parses the /etc/hesiod.conf file
|
|
|
|
*/
|
1998-02-20 18:45:36 +00:00
|
|
|
static int
|
2000-07-21 04:12:25 +00:00
|
|
|
parse_config_file(struct hesiod_p *ctx, const char *filename) {
|
|
|
|
char buf[MAXDNAME+7];
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear the existing configuration variable, just in case
|
|
|
|
* they're set.
|
|
|
|
*/
|
2001-02-03 08:30:32 +00:00
|
|
|
free(ctx->RHS);
|
|
|
|
free(ctx->LHS);
|
2000-07-21 04:12:25 +00:00
|
|
|
ctx->RHS = ctx->LHS = 0;
|
2005-06-15 04:14:52 +00:00
|
|
|
/* Set default query classes. */
|
|
|
|
ctx->classes[0] = C_IN;
|
|
|
|
ctx->classes[1] = C_HS;
|
2000-07-21 04:12:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now open and parse the file...
|
|
|
|
*/
|
2011-11-15 09:24:42 +00:00
|
|
|
if (!(fp = fopen(filename, "rce")))
|
2000-07-21 04:12:25 +00:00
|
|
|
return (-1);
|
2001-02-03 07:01:11 +00:00
|
|
|
|
2000-07-21 04:12:25 +00:00
|
|
|
while (fgets(buf, sizeof(buf), fp) != NULL) {
|
2005-06-15 04:14:52 +00:00
|
|
|
char *key, *data, *cp, **cpp;
|
|
|
|
|
2000-07-21 04:12:25 +00:00
|
|
|
cp = buf;
|
|
|
|
if (*cp == '#' || *cp == '\n' || *cp == '\r')
|
|
|
|
continue;
|
|
|
|
while(*cp == ' ' || *cp == '\t')
|
|
|
|
cp++;
|
|
|
|
key = cp;
|
|
|
|
while(*cp != ' ' && *cp != '\t' && *cp != '=')
|
|
|
|
cp++;
|
|
|
|
*cp++ = '\0';
|
2001-02-03 07:01:11 +00:00
|
|
|
|
2000-07-21 04:12:25 +00:00
|
|
|
while(*cp == ' ' || *cp == '\t' || *cp == '=')
|
|
|
|
cp++;
|
|
|
|
data = cp;
|
|
|
|
while(*cp != ' ' && *cp != '\n' && *cp != '\r')
|
|
|
|
cp++;
|
|
|
|
*cp++ = '\0';
|
|
|
|
|
2005-06-15 04:14:52 +00:00
|
|
|
cpp = NULL;
|
|
|
|
if (strcasecmp(key, "lhs") == 0)
|
2000-07-21 04:12:25 +00:00
|
|
|
cpp = &ctx->LHS;
|
2005-06-15 04:14:52 +00:00
|
|
|
else if (strcasecmp(key, "rhs") == 0)
|
2000-07-21 04:12:25 +00:00
|
|
|
cpp = &ctx->RHS;
|
2005-06-15 04:14:52 +00:00
|
|
|
if (cpp) {
|
|
|
|
*cpp = strdup(data);
|
|
|
|
if (!*cpp)
|
|
|
|
goto cleanup;
|
|
|
|
} else if (strcasecmp(key, "classes") == 0) {
|
|
|
|
int n = 0;
|
|
|
|
while (*data && n < 2) {
|
|
|
|
cp = strchrnul(data, ',');
|
|
|
|
if (*cp != '\0')
|
|
|
|
*cp++ = '\0';
|
|
|
|
if (strcasecmp(data, "IN") == 0)
|
|
|
|
ctx->classes[n++] = C_IN;
|
|
|
|
else if (strcasecmp(data, "HS") == 0)
|
|
|
|
ctx->classes[n++] = C_HS;
|
|
|
|
data = cp;
|
|
|
|
}
|
|
|
|
if (n == 0) {
|
|
|
|
/* Restore the default. Better than
|
|
|
|
nother at all. */
|
|
|
|
ctx->classes[0] = C_IN;
|
|
|
|
ctx->classes[1] = C_HS;
|
2005-06-15 06:44:01 +00:00
|
|
|
} else if (n == 1
|
|
|
|
|| ctx->classes[0] == ctx->classes[1])
|
2005-06-15 04:14:52 +00:00
|
|
|
ctx->classes[1] = 0;
|
|
|
|
}
|
1997-09-16 00:42:43 +00:00
|
|
|
}
|
2000-07-21 04:12:25 +00:00
|
|
|
fclose(fp);
|
|
|
|
return (0);
|
2001-02-03 07:01:11 +00:00
|
|
|
|
2000-07-21 04:12:25 +00:00
|
|
|
cleanup:
|
|
|
|
fclose(fp);
|
2001-02-03 08:30:32 +00:00
|
|
|
free(ctx->RHS);
|
|
|
|
free(ctx->LHS);
|
2000-07-21 04:12:25 +00:00
|
|
|
ctx->RHS = ctx->LHS = 0;
|
|
|
|
return (-1);
|
1997-09-16 21:51:15 +00:00
|
|
|
}
|
1997-09-16 00:42:43 +00:00
|
|
|
|
2000-07-21 04:12:25 +00:00
|
|
|
/*
|
|
|
|
* Given a DNS class and a DNS name, do a lookup for TXT records, and
|
1997-09-16 00:42:43 +00:00
|
|
|
* return a list of them.
|
|
|
|
*/
|
1998-02-20 18:45:36 +00:00
|
|
|
static char **
|
2000-07-21 04:12:25 +00:00
|
|
|
get_txt_records(struct hesiod_p *ctx, int class, const char *name) {
|
|
|
|
struct {
|
|
|
|
int type; /* RR type */
|
|
|
|
int class; /* RR class */
|
|
|
|
int dlen; /* len of data section */
|
|
|
|
u_char *data; /* pointer to data */
|
|
|
|
} rr;
|
|
|
|
HEADER *hp;
|
|
|
|
u_char qbuf[MAX_HESRESP], abuf[MAX_HESRESP];
|
|
|
|
u_char *cp, *erdata, *eom;
|
|
|
|
char *dst, *edst, **list;
|
|
|
|
int ancount, qdcount;
|
|
|
|
int i, j, n, skip;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Construct the query and send it.
|
|
|
|
*/
|
2016-05-02 13:25:20 +00:00
|
|
|
n = res_mkquery(QUERY, name, class, T_TXT, NULL, 0,
|
2000-07-21 04:12:25 +00:00
|
|
|
NULL, qbuf, MAX_HESRESP);
|
|
|
|
if (n < 0) {
|
|
|
|
__set_errno(EMSGSIZE);
|
|
|
|
return (NULL);
|
1997-09-16 00:42:43 +00:00
|
|
|
}
|
2016-05-02 13:25:20 +00:00
|
|
|
n = res_send(qbuf, n, abuf, MAX_HESRESP);
|
2000-07-21 04:12:25 +00:00
|
|
|
if (n < 0) {
|
|
|
|
__set_errno(ECONNREFUSED);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (n < HFIXEDSZ) {
|
|
|
|
__set_errno(EMSGSIZE);
|
|
|
|
return (NULL);
|
1997-09-16 00:42:43 +00:00
|
|
|
}
|
|
|
|
|
2000-07-21 04:12:25 +00:00
|
|
|
/*
|
|
|
|
* OK, parse the result.
|
|
|
|
*/
|
|
|
|
hp = (HEADER *) abuf;
|
|
|
|
ancount = ntohs(hp->ancount);
|
|
|
|
qdcount = ntohs(hp->qdcount);
|
|
|
|
cp = abuf + sizeof(HEADER);
|
|
|
|
eom = abuf + n;
|
|
|
|
|
|
|
|
/* Skip query, trying to get to the answer section which follows. */
|
|
|
|
for (i = 0; i < qdcount; i++) {
|
|
|
|
skip = dn_skipname(cp, eom);
|
|
|
|
if (skip < 0 || cp + skip + QFIXEDSZ > eom) {
|
|
|
|
__set_errno(EMSGSIZE);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
cp += skip + QFIXEDSZ;
|
1997-09-16 00:42:43 +00:00
|
|
|
}
|
|
|
|
|
2000-07-21 04:12:25 +00:00
|
|
|
list = malloc((ancount + 1) * sizeof(char *));
|
2001-02-03 08:30:32 +00:00
|
|
|
if (!list)
|
2000-07-21 04:12:25 +00:00
|
|
|
return (NULL);
|
|
|
|
j = 0;
|
|
|
|
for (i = 0; i < ancount; i++) {
|
|
|
|
skip = dn_skipname(cp, eom);
|
|
|
|
if (skip < 0) {
|
|
|
|
__set_errno(EMSGSIZE);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
cp += skip;
|
|
|
|
if (cp + 3 * INT16SZ + INT32SZ > eom) {
|
|
|
|
__set_errno(EMSGSIZE);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
rr.type = ns_get16(cp);
|
|
|
|
cp += INT16SZ;
|
|
|
|
rr.class = ns_get16(cp);
|
|
|
|
cp += INT16SZ + INT32SZ; /* skip the ttl, too */
|
|
|
|
rr.dlen = ns_get16(cp);
|
|
|
|
cp += INT16SZ;
|
2016-05-02 14:04:32 +00:00
|
|
|
if (rr.dlen == 0 || cp + rr.dlen > eom) {
|
2000-07-21 04:12:25 +00:00
|
|
|
__set_errno(EMSGSIZE);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
rr.data = cp;
|
|
|
|
cp += rr.dlen;
|
|
|
|
if (rr.class != class || rr.type != T_TXT)
|
|
|
|
continue;
|
|
|
|
if (!(list[j] = malloc(rr.dlen)))
|
|
|
|
goto cleanup;
|
|
|
|
dst = list[j++];
|
|
|
|
edst = dst + rr.dlen;
|
|
|
|
erdata = rr.data + rr.dlen;
|
|
|
|
cp = rr.data;
|
|
|
|
while (cp < erdata) {
|
|
|
|
n = (unsigned char) *cp++;
|
|
|
|
if (cp + n > eom || dst + n > edst) {
|
|
|
|
__set_errno(EMSGSIZE);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
memcpy(dst, cp, n);
|
|
|
|
cp += n;
|
|
|
|
dst += n;
|
|
|
|
}
|
|
|
|
if (cp != erdata) {
|
|
|
|
__set_errno(EMSGSIZE);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
*dst = '\0';
|
1997-09-16 00:42:43 +00:00
|
|
|
}
|
2000-07-21 04:12:25 +00:00
|
|
|
list[j] = NULL;
|
|
|
|
if (j == 0) {
|
|
|
|
__set_errno(ENOENT);
|
|
|
|
goto cleanup;
|
1997-09-16 00:42:43 +00:00
|
|
|
}
|
2000-07-21 04:12:25 +00:00
|
|
|
return (list);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
for (i = 0; i < j; i++)
|
|
|
|
free(list[i]);
|
|
|
|
free(list);
|
|
|
|
return (NULL);
|
|
|
|
}
|