- (djm) Import getrrsetbyname() function from OpenBSD libc (for DNS support)
This commit is contained in:
parent
2aa0ab463f
commit
d9ec370ac3
|
@ -21,6 +21,7 @@
|
|||
always parse kerberos options. ok djm@ markus@
|
||||
- (djm) Always parse UsePAM
|
||||
- (djm) Configure glue for DNS support (code doesn't work in portable yet)
|
||||
- (djm) Import getrrsetbyname() function from OpenBSD libc (for DNS support)
|
||||
|
||||
20030514
|
||||
- (djm) Bug #117: Don't lie to PAM about username
|
||||
|
@ -1496,4 +1497,4 @@
|
|||
save auth method before monitor_reset_key_state(); bugzilla bug #284;
|
||||
ok provos@
|
||||
|
||||
$Id: ChangeLog,v 1.2706 2003/05/15 02:05:28 djm Exp $
|
||||
$Id: ChangeLog,v 1.2707 2003/05/15 02:27:08 djm Exp $
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $Id: acconfig.h,v 1.152 2003/05/15 00:53:49 djm Exp $ */
|
||||
/* $Id: acconfig.h,v 1.153 2003/05/15 02:27:08 djm Exp $ */
|
||||
|
||||
#ifndef _CONFIG_H
|
||||
#define _CONFIG_H
|
||||
|
@ -383,8 +383,8 @@
|
|||
/* Define if DNS support is to be activated */
|
||||
#undef DNS
|
||||
|
||||
/* Define if -llwres is to be used */
|
||||
#undef LWRES
|
||||
/* Define if getrrsetbyname() exists */
|
||||
#undef HAVE_GETRRSETBYNAME
|
||||
|
||||
@BOTTOM@
|
||||
|
||||
|
|
11
configure.ac
11
configure.ac
|
@ -1,4 +1,4 @@
|
|||
# $Id: configure.ac,v 1.119 2003/05/15 01:12:19 djm Exp $
|
||||
# $Id: configure.ac,v 1.120 2003/05/15 02:27:08 djm Exp $
|
||||
|
||||
AC_INIT
|
||||
AC_CONFIG_SRCDIR([ssh.c])
|
||||
|
@ -1859,11 +1859,10 @@ AC_ARG_WITH(dns,
|
|||
[ --with-dns Support for fetching keys from DNS (experimental)],
|
||||
[
|
||||
if test "x$withval" != "xno" ; then
|
||||
DNS_MSG="no (system lacks getrrsetbyname)"
|
||||
AC_SEARCH_LIBS(getrrsetbyname, resolv, [
|
||||
AC_DEFINE(DNS)
|
||||
DNS_MSG="yes"
|
||||
])
|
||||
DNS_MSG="yes"
|
||||
AC_DEFINE(DNS)
|
||||
AC_SEARCH_LIBS(getrrsetbyname, resolv,
|
||||
[AC_DEFINE(HAVE_GETRRSETBYNAME)])
|
||||
fi
|
||||
]
|
||||
)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# $Id: Makefile.in,v 1.25 2003/02/24 01:55:56 djm Exp $
|
||||
# $Id: Makefile.in,v 1.26 2003/05/15 02:27:08 djm Exp $
|
||||
|
||||
sysconfdir=@sysconfdir@
|
||||
piddir=@piddir@
|
||||
|
@ -16,7 +16,7 @@ RANLIB=@RANLIB@
|
|||
INSTALL=@INSTALL@
|
||||
LDFLAGS=-L. @LDFLAGS@
|
||||
|
||||
OPENBSD=base64.o basename.o bindresvport.o daemon.o dirname.o getcwd.o getgrouplist.o getopt.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sigact.o strlcat.o strlcpy.o strmode.o strsep.o vis.o
|
||||
OPENBSD=base64.o basename.o bindresvport.o daemon.o dirname.o getcwd.o getgrouplist.o getopt.o getrrsetbyname.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sigact.o strlcat.o strlcpy.o strmode.o strsep.o vis.o
|
||||
|
||||
COMPAT=bsd-arc4random.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o bsd-misc.o bsd-nextstep.o bsd-snprintf.o bsd-waitpid.o fake-getaddrinfo.o fake-getnameinfo.o xmmap.o
|
||||
|
||||
|
|
|
@ -0,0 +1,567 @@
|
|||
/* $OpenBSD: getrrsetbyname.c,v 1.4 2001/08/16 18:16:43 ho Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001 Jakob Schlyter. 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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) 1999-2001 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.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
|
||||
#ifndef HAVE_GETRRSETBYNAME
|
||||
|
||||
#include "getrrsetbyname.h"
|
||||
|
||||
#define ANSWER_BUFFER_SIZE 1024*64
|
||||
|
||||
struct dns_query {
|
||||
char *name;
|
||||
u_int16_t type;
|
||||
u_int16_t class;
|
||||
struct dns_query *next;
|
||||
};
|
||||
|
||||
struct dns_rr {
|
||||
char *name;
|
||||
u_int16_t type;
|
||||
u_int16_t class;
|
||||
u_int16_t ttl;
|
||||
u_int16_t size;
|
||||
void *rdata;
|
||||
struct dns_rr *next;
|
||||
};
|
||||
|
||||
struct dns_response {
|
||||
HEADER header;
|
||||
struct dns_query *query;
|
||||
struct dns_rr *answer;
|
||||
struct dns_rr *authority;
|
||||
struct dns_rr *additional;
|
||||
};
|
||||
|
||||
static struct dns_response *parse_dns_response(const char *, int);
|
||||
static struct dns_query *parse_dns_qsection(const char *, int, const char **,
|
||||
int);
|
||||
static struct dns_rr *parse_dns_rrsection(const char *, int, const char **,
|
||||
int);
|
||||
|
||||
static void free_dns_query(struct dns_query *);
|
||||
static void free_dns_rr(struct dns_rr *);
|
||||
static void free_dns_response(struct dns_response *);
|
||||
|
||||
static int count_dns_rr(struct dns_rr *, u_int16_t, u_int16_t);
|
||||
|
||||
/*
|
||||
* Inline versions of get/put short/long. Pointer is advanced.
|
||||
*
|
||||
* These macros demonstrate the property of C whereby it can be
|
||||
* portable or it can be elegant but rarely both.
|
||||
*/
|
||||
|
||||
#ifndef INT32SZ
|
||||
# define INT32SZ 4
|
||||
#endif
|
||||
#ifndef INT16SZ
|
||||
# define INT16SZ 2
|
||||
#endif
|
||||
|
||||
#ifndef GETSHORT
|
||||
#define GETSHORT(s, cp) { \
|
||||
register u_char *t_cp = (u_char *)(cp); \
|
||||
(s) = ((u_int16_t)t_cp[0] << 8) \
|
||||
| ((u_int16_t)t_cp[1]) \
|
||||
; \
|
||||
(cp) += INT16SZ; \
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef GETLONG
|
||||
#define GETLONG(l, cp) { \
|
||||
register u_char *t_cp = (u_char *)(cp); \
|
||||
(l) = ((u_int32_t)t_cp[0] << 24) \
|
||||
| ((u_int32_t)t_cp[1] << 16) \
|
||||
| ((u_int32_t)t_cp[2] << 8) \
|
||||
| ((u_int32_t)t_cp[3]) \
|
||||
; \
|
||||
(cp) += INT32SZ; \
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Routines to insert/extract short/long's.
|
||||
*/
|
||||
|
||||
static u_int16_t
|
||||
_getshort(msgp)
|
||||
register const u_char *msgp;
|
||||
{
|
||||
register u_int16_t u;
|
||||
|
||||
GETSHORT(u, msgp);
|
||||
return (u);
|
||||
}
|
||||
|
||||
static u_int32_t
|
||||
_getlong(msgp)
|
||||
register const u_char *msgp;
|
||||
{
|
||||
register u_int32_t u;
|
||||
|
||||
GETLONG(u, msgp);
|
||||
return (u);
|
||||
}
|
||||
|
||||
int
|
||||
getrrsetbyname(const char *hostname, unsigned int rdclass,
|
||||
unsigned int rdtype, unsigned int flags,
|
||||
struct rrsetinfo **res)
|
||||
{
|
||||
int result;
|
||||
struct rrsetinfo *rrset = NULL;
|
||||
struct dns_response *response;
|
||||
struct dns_rr *rr;
|
||||
struct rdatainfo *rdata;
|
||||
unsigned int length, index_ans, index_sig;
|
||||
char answer[ANSWER_BUFFER_SIZE];
|
||||
|
||||
/* check for invalid class and type */
|
||||
if (rdclass > 0xffff || rdtype > 0xffff) {
|
||||
result = ERRSET_INVAL;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* don't allow queries of class or type ANY */
|
||||
if (rdclass == 0xff || rdtype == 0xff) {
|
||||
result = ERRSET_INVAL;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* don't allow flags yet, unimplemented */
|
||||
if (flags) {
|
||||
result = ERRSET_INVAL;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* initialize resolver */
|
||||
if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
|
||||
result = ERRSET_FAIL;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
_res.options |= RES_DEBUG;
|
||||
#endif /* DEBUG */
|
||||
|
||||
#ifdef RES_USE_DNSSEC
|
||||
/* turn on DNSSEC if EDNS0 is configured */
|
||||
if (_res.options & RES_USE_EDNS0)
|
||||
_res.options |= RES_USE_DNSSEC;
|
||||
#endif /* RES_USE_DNSEC */
|
||||
|
||||
/* make query */
|
||||
length = res_query(hostname, rdclass, rdtype, answer, sizeof(answer));
|
||||
if (length < 0) {
|
||||
switch(h_errno) {
|
||||
case HOST_NOT_FOUND:
|
||||
result = ERRSET_NONAME;
|
||||
goto fail;
|
||||
case NO_DATA:
|
||||
result = ERRSET_NODATA;
|
||||
goto fail;
|
||||
default:
|
||||
result = ERRSET_FAIL;
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
/* parse result */
|
||||
response = parse_dns_response(answer, length);
|
||||
if (response == NULL) {
|
||||
result = ERRSET_FAIL;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (response->header.qdcount != 1) {
|
||||
result = ERRSET_FAIL;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* initialize rrset */
|
||||
rrset = calloc(1, sizeof(struct rrsetinfo));
|
||||
if (rrset == NULL) {
|
||||
result = ERRSET_NOMEMORY;
|
||||
goto fail;
|
||||
}
|
||||
rrset->rri_rdclass = response->query->class;
|
||||
rrset->rri_rdtype = response->query->type;
|
||||
rrset->rri_ttl = response->answer->ttl;
|
||||
rrset->rri_nrdatas = response->header.ancount;
|
||||
|
||||
/* check for authenticated data */
|
||||
if (response->header.ad == 1)
|
||||
rrset->rri_flags |= RRSET_VALIDATED;
|
||||
|
||||
/* copy name from answer section */
|
||||
length = strlen(response->answer->name);
|
||||
rrset->rri_name = malloc(length + 1);
|
||||
if (rrset->rri_name == NULL) {
|
||||
result = ERRSET_NOMEMORY;
|
||||
goto fail;
|
||||
}
|
||||
strlcpy(rrset->rri_name, response->answer->name, length + 1);
|
||||
|
||||
/* count answers */
|
||||
rrset->rri_nrdatas = count_dns_rr(response->answer, rrset->rri_rdclass,
|
||||
rrset->rri_rdtype);
|
||||
rrset->rri_nsigs = count_dns_rr(response->answer, rrset->rri_rdclass,
|
||||
T_SIG);
|
||||
|
||||
/* allocate memory for answers */
|
||||
rrset->rri_rdatas = calloc(rrset->rri_nrdatas,
|
||||
sizeof(struct rdatainfo));
|
||||
if (rrset->rri_rdatas == NULL) {
|
||||
result = ERRSET_NOMEMORY;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* allocate memory for signatures */
|
||||
rrset->rri_sigs = calloc(rrset->rri_nsigs, sizeof(struct rdatainfo));
|
||||
if (rrset->rri_sigs == NULL) {
|
||||
result = ERRSET_NOMEMORY;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* copy answers & signatures */
|
||||
for (rr = response->answer, index_ans = 0, index_sig = 0;
|
||||
rr; rr = rr->next) {
|
||||
|
||||
rdata = NULL;
|
||||
|
||||
if (rr->class == rrset->rri_rdclass &&
|
||||
rr->type == rrset->rri_rdtype)
|
||||
rdata = &rrset->rri_rdatas[index_ans++];
|
||||
|
||||
if (rr->class == rrset->rri_rdclass &&
|
||||
rr->type == T_SIG)
|
||||
rdata = &rrset->rri_sigs[index_sig++];
|
||||
|
||||
if (rdata) {
|
||||
rdata->rdi_length = rr->size;
|
||||
rdata->rdi_data = malloc(rr->size);
|
||||
|
||||
if (rdata->rdi_data == NULL) {
|
||||
result = ERRSET_NOMEMORY;
|
||||
goto fail;
|
||||
}
|
||||
memcpy(rdata->rdi_data, rr->rdata, rr->size);
|
||||
}
|
||||
}
|
||||
|
||||
*res = rrset;
|
||||
return (ERRSET_SUCCESS);
|
||||
|
||||
fail:
|
||||
if (rrset != NULL)
|
||||
freerrset(rrset);
|
||||
return (result);
|
||||
}
|
||||
|
||||
void
|
||||
freerrset(struct rrsetinfo *rrset)
|
||||
{
|
||||
u_int16_t i;
|
||||
|
||||
if (rrset == NULL)
|
||||
return;
|
||||
|
||||
if (rrset->rri_rdatas) {
|
||||
for (i = 0; i < rrset->rri_nrdatas; i++) {
|
||||
if (rrset->rri_rdatas[i].rdi_data == NULL)
|
||||
break;
|
||||
free(rrset->rri_rdatas[i].rdi_data);
|
||||
}
|
||||
free(rrset->rri_rdatas);
|
||||
}
|
||||
|
||||
if (rrset->rri_sigs) {
|
||||
for (i = 0; i < rrset->rri_nsigs; i++) {
|
||||
if (rrset->rri_sigs[i].rdi_data == NULL)
|
||||
break;
|
||||
free(rrset->rri_sigs[i].rdi_data);
|
||||
}
|
||||
free(rrset->rri_sigs);
|
||||
}
|
||||
|
||||
if (rrset->rri_name)
|
||||
free(rrset->rri_name);
|
||||
free(rrset);
|
||||
}
|
||||
|
||||
/*
|
||||
* DNS response parsing routines
|
||||
*/
|
||||
static struct dns_response *
|
||||
parse_dns_response(const char *answer, int size)
|
||||
{
|
||||
struct dns_response *resp;
|
||||
const char *cp;
|
||||
|
||||
/* allocate memory for the response */
|
||||
resp = calloc(1, sizeof(*resp));
|
||||
if (resp == NULL)
|
||||
return (NULL);
|
||||
|
||||
/* initialize current pointer */
|
||||
cp = answer;
|
||||
|
||||
/* copy header */
|
||||
memcpy(&resp->header, cp, HFIXEDSZ);
|
||||
cp += HFIXEDSZ;
|
||||
|
||||
/* fix header byte order */
|
||||
resp->header.qdcount = ntohs(resp->header.qdcount);
|
||||
resp->header.ancount = ntohs(resp->header.ancount);
|
||||
resp->header.nscount = ntohs(resp->header.nscount);
|
||||
resp->header.arcount = ntohs(resp->header.arcount);
|
||||
|
||||
/* there must be at least one query */
|
||||
if (resp->header.qdcount < 1) {
|
||||
free_dns_response(resp);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* parse query section */
|
||||
resp->query = parse_dns_qsection(answer, size, &cp,
|
||||
resp->header.qdcount);
|
||||
if (resp->header.qdcount && resp->query == NULL) {
|
||||
free_dns_response(resp);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* parse answer section */
|
||||
resp->answer = parse_dns_rrsection(answer, size, &cp,
|
||||
resp->header.ancount);
|
||||
if (resp->header.ancount && resp->answer == NULL) {
|
||||
free_dns_response(resp);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* parse authority section */
|
||||
resp->authority = parse_dns_rrsection(answer, size, &cp,
|
||||
resp->header.nscount);
|
||||
if (resp->header.nscount && resp->authority == NULL) {
|
||||
free_dns_response(resp);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* parse additional section */
|
||||
resp->additional = parse_dns_rrsection(answer, size, &cp,
|
||||
resp->header.arcount);
|
||||
if (resp->header.arcount && resp->additional == NULL) {
|
||||
free_dns_response(resp);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
return (resp);
|
||||
}
|
||||
|
||||
static struct dns_query *
|
||||
parse_dns_qsection(const char *answer, int size, const char **cp, int count)
|
||||
{
|
||||
struct dns_query *head, *curr, *prev;
|
||||
int i, length;
|
||||
char name[MAXDNAME];
|
||||
|
||||
for (i = 1, head = NULL, prev = NULL; i <= count; i++, prev = curr) {
|
||||
|
||||
/* allocate and initialize struct */
|
||||
curr = calloc(1, sizeof(struct dns_query));
|
||||
if (curr == NULL) {
|
||||
free_dns_query(head);
|
||||
return (NULL);
|
||||
}
|
||||
if (head == NULL)
|
||||
head = curr;
|
||||
if (prev != NULL)
|
||||
prev->next = curr;
|
||||
|
||||
/* name */
|
||||
length = dn_expand(answer, answer + size, *cp, name,
|
||||
sizeof(name));
|
||||
if (length < 0) {
|
||||
free_dns_query(head);
|
||||
return (NULL);
|
||||
}
|
||||
curr->name = strdup(name);
|
||||
if (curr->name == NULL) {
|
||||
free_dns_query(head);
|
||||
return (NULL);
|
||||
}
|
||||
*cp += length;
|
||||
|
||||
/* type */
|
||||
curr->type = _getshort(*cp);
|
||||
*cp += INT16SZ;
|
||||
|
||||
/* class */
|
||||
curr->class = _getshort(*cp);
|
||||
*cp += INT16SZ;
|
||||
}
|
||||
|
||||
return (head);
|
||||
}
|
||||
|
||||
static struct dns_rr *
|
||||
parse_dns_rrsection(const char *answer, int size, const char **cp, int count)
|
||||
{
|
||||
struct dns_rr *head, *curr, *prev;
|
||||
int i, length;
|
||||
char name[MAXDNAME];
|
||||
|
||||
for (i = 1, head = NULL, prev = NULL; i <= count; i++, prev = curr) {
|
||||
|
||||
/* allocate and initialize struct */
|
||||
curr = calloc(1, sizeof(struct dns_rr));
|
||||
if (curr == NULL) {
|
||||
free_dns_rr(head);
|
||||
return (NULL);
|
||||
}
|
||||
if (head == NULL)
|
||||
head = curr;
|
||||
if (prev != NULL)
|
||||
prev->next = curr;
|
||||
|
||||
/* name */
|
||||
length = dn_expand(answer, answer + size, *cp, name,
|
||||
sizeof(name));
|
||||
if (length < 0) {
|
||||
free_dns_rr(head);
|
||||
return (NULL);
|
||||
}
|
||||
curr->name = strdup(name);
|
||||
if (curr->name == NULL) {
|
||||
free_dns_rr(head);
|
||||
return (NULL);
|
||||
}
|
||||
*cp += length;
|
||||
|
||||
/* type */
|
||||
curr->type = _getshort(*cp);
|
||||
*cp += INT16SZ;
|
||||
|
||||
/* class */
|
||||
curr->class = _getshort(*cp);
|
||||
*cp += INT16SZ;
|
||||
|
||||
/* ttl */
|
||||
curr->ttl = _getlong(*cp);
|
||||
*cp += INT32SZ;
|
||||
|
||||
/* rdata size */
|
||||
curr->size = _getshort(*cp);
|
||||
*cp += INT16SZ;
|
||||
|
||||
/* rdata itself */
|
||||
curr->rdata = malloc(curr->size);
|
||||
if (curr->rdata == NULL) {
|
||||
free_dns_rr(head);
|
||||
return (NULL);
|
||||
}
|
||||
memcpy(curr->rdata, *cp, curr->size);
|
||||
*cp += curr->size;
|
||||
}
|
||||
|
||||
return (head);
|
||||
}
|
||||
|
||||
static void
|
||||
free_dns_query(struct dns_query *p)
|
||||
{
|
||||
if (p == NULL)
|
||||
return;
|
||||
|
||||
if (p->name)
|
||||
free(p->name);
|
||||
free_dns_query(p->next);
|
||||
free(p);
|
||||
}
|
||||
|
||||
static void
|
||||
free_dns_rr(struct dns_rr *p)
|
||||
{
|
||||
if (p == NULL)
|
||||
return;
|
||||
|
||||
if (p->name)
|
||||
free(p->name);
|
||||
if (p->rdata)
|
||||
free(p->rdata);
|
||||
free_dns_rr(p->next);
|
||||
free(p);
|
||||
}
|
||||
|
||||
static void
|
||||
free_dns_response(struct dns_response *p)
|
||||
{
|
||||
if (p == NULL)
|
||||
return;
|
||||
|
||||
free_dns_query(p->query);
|
||||
free_dns_rr(p->answer);
|
||||
free_dns_rr(p->authority);
|
||||
free_dns_rr(p->additional);
|
||||
free(p);
|
||||
}
|
||||
|
||||
static int
|
||||
count_dns_rr(struct dns_rr *p, u_int16_t class, u_int16_t type)
|
||||
{
|
||||
int n = 0;
|
||||
|
||||
while(p) {
|
||||
if (p->class == class && p->type == type)
|
||||
n++;
|
||||
p = p->next;
|
||||
}
|
||||
|
||||
return (n);
|
||||
}
|
||||
|
||||
#endif /* HAVE_GETRRSETBYNAME */
|
|
@ -0,0 +1,99 @@
|
|||
/* $OpenBSD: getrrsetbyname.c,v 1.4 2001/08/16 18:16:43 ho Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001 Jakob Schlyter. 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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) 1999-2001 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.
|
||||
*/
|
||||
|
||||
#ifndef _GETRRSETBYNAME_H
|
||||
#define _GETRRSETBYNAME_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifndef HAVE_GETRRSETBYNAME
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/nameser.h>
|
||||
#include <netdb.h>
|
||||
#include <resolv.h>
|
||||
|
||||
/*
|
||||
* Flags for getrrsetbyname()
|
||||
*/
|
||||
#ifndef RRSET_VALIDATED
|
||||
# define RRSET_VALIDATED 1
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Return codes for getrrsetbyname()
|
||||
*/
|
||||
#ifndef ERRSET_SUCCESS
|
||||
# define ERRSET_SUCCESS 0
|
||||
# define ERRSET_NOMEMORY 1
|
||||
# define ERRSET_FAIL 2
|
||||
# define ERRSET_INVAL 3
|
||||
# define ERRSET_NONAME 4
|
||||
# define ERRSET_NODATA 5
|
||||
#endif
|
||||
|
||||
struct rdatainfo {
|
||||
unsigned int rdi_length; /* length of data */
|
||||
unsigned char *rdi_data; /* record data */
|
||||
};
|
||||
|
||||
struct rrsetinfo {
|
||||
unsigned int rri_flags; /* RRSET_VALIDATED ... */
|
||||
unsigned int rri_rdclass; /* class number */
|
||||
unsigned int rri_rdtype; /* RR type number */
|
||||
unsigned int rri_ttl; /* time to live */
|
||||
unsigned int rri_nrdatas; /* size of rdatas array */
|
||||
unsigned int rri_nsigs; /* size of sigs array */
|
||||
char *rri_name; /* canonical name */
|
||||
struct rdatainfo *rri_rdatas; /* individual records */
|
||||
struct rdatainfo *rri_sigs; /* individual signatures */
|
||||
};
|
||||
|
||||
int getrrsetbyname(const char *, unsigned int, unsigned int, unsigned int, struct rrsetinfo **);
|
||||
void freerrset(struct rrsetinfo *);
|
||||
|
||||
#endif /* HAVE_GETRRSETBYNAME */
|
||||
#endif /* _GETRRSETBYNAME_H */
|
|
@ -1,4 +1,4 @@
|
|||
/* $Id: openbsd-compat.h,v 1.20 2003/05/04 00:41:20 dtucker Exp $ */
|
||||
/* $Id: openbsd-compat.h,v 1.21 2003/05/15 02:27:08 djm Exp $ */
|
||||
|
||||
#ifndef _OPENBSD_H
|
||||
#define _OPENBSD_H
|
||||
|
@ -28,6 +28,7 @@
|
|||
#include "readpassphrase.h"
|
||||
#include "getopt.h"
|
||||
#include "vis.h"
|
||||
#include "getrrsetbyname.h"
|
||||
|
||||
/* Home grown routines */
|
||||
#include "bsd-arc4random.h"
|
||||
|
|
Loading…
Reference in New Issue