Upgrade res_update(3) and the friends to BIND9's one excluding TSIG
support. X-MFC after: never
This commit is contained in:
parent
135a67244d
commit
d808369aa1
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=158787
@ -507,7 +507,9 @@ typedef enum __ns_cert_types {
|
||||
#define ns_verify __ns_verify
|
||||
#define ns_verify_tcp __ns_verify_tcp
|
||||
#define ns_verify_tcp_init __ns_verify_tcp_init
|
||||
#endif
|
||||
#define ns_samedomain __ns_samedomain
|
||||
#if 0
|
||||
#define ns_subdomain __ns_subdomain
|
||||
#endif
|
||||
#define ns_makecanon __ns_makecanon
|
||||
@ -567,7 +569,9 @@ int ns_verify(u_char *, int *, void *,
|
||||
int ns_verify_tcp(u_char *, int *, ns_tcp_tsig_state *, int);
|
||||
int ns_verify_tcp_init(void *, const u_char *, int,
|
||||
ns_tcp_tsig_state *);
|
||||
#endif
|
||||
int ns_samedomain(const char *, const char *);
|
||||
#if 0
|
||||
int ns_subdomain(const char *, const char *);
|
||||
#endif
|
||||
int ns_makecanon(const char *, char *, size_t);
|
||||
|
@ -1,79 +1,71 @@
|
||||
/*-
|
||||
* Copyright (c) 1983, 1987, 1989, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
/*
|
||||
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
|
||||
* Copyright (c) 1999 by Internet Software Consortium, Inc.
|
||||
*
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* $FreeBSD$ */
|
||||
/*
|
||||
* $Id: res_update.h,v 1.1.206.1 2004/03/09 08:33:29 marka Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _RES_UPDATE_H_
|
||||
#define _RES_UPDATE_H_
|
||||
#ifndef __RES_UPDATE_H
|
||||
#define __RES_UPDATE_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <arpa/nameser.h>
|
||||
#include <resolv.h>
|
||||
|
||||
/*
|
||||
* This RR-like structure is particular to UPDATE.
|
||||
*/
|
||||
struct ns_updrec {
|
||||
struct ns_updrec *r_prev; /* prev record */
|
||||
struct ns_updrec *r_next; /* next record */
|
||||
u_int8_t r_section; /* ZONE/PREREQUISITE/UPDATE */
|
||||
struct {
|
||||
struct ns_updrec *prev;
|
||||
struct ns_updrec *next;
|
||||
} r_link, r_glink;
|
||||
ns_sect r_section; /* ZONE/PREREQUISITE/UPDATE */
|
||||
char * r_dname; /* owner of the RR */
|
||||
u_int16_t r_class; /* class number */
|
||||
u_int16_t r_type; /* type number */
|
||||
ns_class r_class; /* class number */
|
||||
ns_type r_type; /* type number */
|
||||
u_int32_t r_ttl; /* time to live */
|
||||
u_char * r_data; /* rdata fields as text string */
|
||||
u_int16_t r_size; /* size of r_data field */
|
||||
u_int r_size; /* size of r_data field */
|
||||
int r_opcode; /* type of operation */
|
||||
/* following fields for private use by the resolver/server routines */
|
||||
struct ns_updrec *r_grpnext; /* next record when grouped */
|
||||
struct databuf *r_dp; /* databuf to process */
|
||||
struct databuf *r_deldp; /* databuf's deleted/overwritten */
|
||||
u_int16_t r_zone; /* zone number on server */
|
||||
u_int r_zone; /* zone number on server */
|
||||
};
|
||||
typedef struct ns_updrec ns_updrec;
|
||||
typedef struct {
|
||||
ns_updrec *head;
|
||||
ns_updrec *tail;
|
||||
} ns_updque;
|
||||
|
||||
#define res_freeupdrec __res_freeupdrec
|
||||
#define res_mkupdate __res_mkupdate
|
||||
#define res_update __res_update
|
||||
#define res_mkupdrec __res_mkupdrec
|
||||
#define res_freeupdrec __res_freeupdrec
|
||||
#define res_nmkupdate __res_nmkupdate
|
||||
#define res_nupdate __res_nupdate
|
||||
#if 0
|
||||
#define res_update __res_update
|
||||
#endif
|
||||
|
||||
__BEGIN_DECLS
|
||||
void res_freeupdrec(ns_updrec *);
|
||||
int res_mkupdate(ns_updrec *, u_char *, int);
|
||||
int res_update(ns_updrec *);
|
||||
ns_updrec * res_mkupdrec(int, const char *, u_int, u_int, u_long);
|
||||
void res_freeupdrec(ns_updrec *);
|
||||
int res_nmkupdate(res_state, ns_updrec *, u_char *, int);
|
||||
int res_nupdate(res_state, ns_updrec *, ns_tsig_key *);
|
||||
int res_update(ns_updrec *);
|
||||
__END_DECLS
|
||||
|
||||
#endif /* _RES_UPDATE_H_ */
|
||||
#endif /*__RES_UPDATE_H*/
|
||||
|
@ -363,8 +363,8 @@ extern const struct res_sym __p_rcode_syms[];
|
||||
#define res_dnok __res_dnok
|
||||
#if 0
|
||||
#define res_findzonecut __res_findzonecut
|
||||
#define res_findzonecut2 __res_findzonecut2
|
||||
#endif
|
||||
#define res_findzonecut2 __res_findzonecut2
|
||||
#define res_hnok __res_hnok
|
||||
#define res_hostalias __res_hostalias
|
||||
#define res_mailok __res_mailok
|
||||
@ -470,10 +470,10 @@ int res_nsendsigned(res_state, const u_char *, int,
|
||||
ns_tsig_key *, u_char *, int);
|
||||
int res_findzonecut(res_state, const char *, ns_class, int,
|
||||
char *, size_t, struct in_addr *, int);
|
||||
#endif
|
||||
int res_findzonecut2(res_state, const char *, ns_class, int,
|
||||
char *, size_t,
|
||||
union res_sockaddr_union *, int);
|
||||
#endif
|
||||
void res_nclose(res_state);
|
||||
int res_nopt(res_state, int, u_char *, int, int);
|
||||
void res_send_setqhook(res_send_qhook);
|
||||
|
@ -15,9 +15,16 @@
|
||||
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $FreeBSD$ */
|
||||
|
||||
#ifndef LIST_H
|
||||
#define LIST_H 1
|
||||
#ifdef _LIBC
|
||||
#include <assert.h>
|
||||
#define INSIST(cond) assert(cond)
|
||||
#else
|
||||
#include <isc/assertions.h>
|
||||
#endif
|
||||
|
||||
#define LIST(type) struct { type *head, *tail; }
|
||||
#define INIT_LIST(list) \
|
||||
|
@ -19,6 +19,7 @@ FBSD_1.0 {
|
||||
__ns_initparse;
|
||||
__ns_parserr;
|
||||
_ns_flagdata;
|
||||
__ns_samedomain;
|
||||
__ns_samename;
|
||||
__ns_skiprr;
|
||||
__ns_sprintrr;
|
||||
|
@ -30,7 +30,6 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#include "port_after.h"
|
||||
|
||||
#ifndef _LIBC
|
||||
/*
|
||||
* int
|
||||
* ns_samedomain(a, b)
|
||||
@ -143,6 +142,7 @@ ns_samedomain(const char *a, const char *b) {
|
||||
return (strncasecmp(cp, b, lb) == 0);
|
||||
}
|
||||
|
||||
#ifndef _LIBC
|
||||
/*
|
||||
* int
|
||||
* ns_subdomain(a, b)
|
||||
|
@ -19,9 +19,6 @@ SRCS+= addr2ascii.c ascii2addr.c base64.c ether_addr.c eui64.c \
|
||||
SRCS+= nscache.c nscachedcli.c
|
||||
.endif
|
||||
|
||||
# for binary backward compatibility against FreeBSD 6.X and earlier
|
||||
SRCS+= res_mkupdate.c res_update.c
|
||||
|
||||
SYM_MAPS+=${.CURDIR}/net/Symbol.map
|
||||
|
||||
CFLAGS+=-DINET6 -I${.OBJDIR}
|
||||
|
@ -103,10 +103,6 @@ FBSD_1.0 {
|
||||
iruserok_sa;
|
||||
rcmdsh;
|
||||
recv;
|
||||
__res_freeupdrec;
|
||||
__res_mkupdrec;
|
||||
__res_nmkupdate;
|
||||
__res_nupdate;
|
||||
inet6_rthdr_space;
|
||||
inet6_rthdr_init;
|
||||
inet6_rthdr_add;
|
||||
|
@ -1,406 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1996 by 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Based on the Dynamic DNS reference implementation by Viraj Bais
|
||||
* <viraj_bais@ccm.fm.intel.com>
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/nameser.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <netdb.h>
|
||||
#include <resolv.h>
|
||||
#include <res_update.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "res_config.h"
|
||||
|
||||
static int getnum_str(u_char **, u_char *);
|
||||
static int getword_str(char *, int, u_char **, u_char *);
|
||||
|
||||
#define ShrinkBuffer(x) if ((buflen -= x) < 0) return (-2);
|
||||
|
||||
/*
|
||||
* Form update packets.
|
||||
* Returns the size of the resulting packet if no error
|
||||
* On error,
|
||||
* returns -1 if error in reading a word/number in rdata
|
||||
* portion for update packets
|
||||
* -2 if length of buffer passed is insufficient
|
||||
* -3 if zone section is not the first section in
|
||||
* the linked list, or section order has a problem
|
||||
* -4 on a number overflow
|
||||
* -5 unknown operation or no records
|
||||
*/
|
||||
int
|
||||
res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf, int buflen) {
|
||||
ns_updrec *rrecp_start = rrecp_in;
|
||||
HEADER *hp;
|
||||
u_char *cp, *sp2, *startp, *endp;
|
||||
int n, i, soanum, multiline;
|
||||
ns_updrec *rrecp;
|
||||
struct in_addr ina;
|
||||
char buf2[MAXDNAME];
|
||||
int section, numrrs = 0, counts[ns_s_max];
|
||||
u_int16_t rtype, rclass;
|
||||
u_int32_t n1, rttl;
|
||||
u_char *dnptrs[20], **dpp, **lastdnptr;
|
||||
|
||||
/*
|
||||
* Initialize header fields.
|
||||
*/
|
||||
if ((buf == NULL) || (buflen < HFIXEDSZ))
|
||||
return (-1);
|
||||
memset(buf, 0, HFIXEDSZ);
|
||||
hp = (HEADER *) buf;
|
||||
hp->id = htons(++statp->id);
|
||||
hp->opcode = ns_o_update;
|
||||
hp->rcode = NOERROR;
|
||||
cp = buf + HFIXEDSZ;
|
||||
buflen -= HFIXEDSZ;
|
||||
dpp = dnptrs;
|
||||
*dpp++ = buf;
|
||||
*dpp++ = NULL;
|
||||
lastdnptr = dnptrs + sizeof dnptrs / sizeof dnptrs[0];
|
||||
|
||||
if (rrecp_start == NULL)
|
||||
return (-5);
|
||||
else if (rrecp_start->r_section != S_ZONE)
|
||||
return (-3);
|
||||
|
||||
memset(counts, 0, sizeof counts);
|
||||
for (rrecp = rrecp_start; rrecp; rrecp = rrecp->r_grpnext) {
|
||||
numrrs++;
|
||||
section = rrecp->r_section;
|
||||
if (section < 0 || section >= ns_s_max)
|
||||
return (-1);
|
||||
counts[section]++;
|
||||
for (i = section + 1; i < ns_s_max; i++)
|
||||
if (counts[i])
|
||||
return (-3);
|
||||
rtype = rrecp->r_type;
|
||||
rclass = rrecp->r_class;
|
||||
rttl = rrecp->r_ttl;
|
||||
/* overload class and type */
|
||||
if (section == S_PREREQ) {
|
||||
rttl = 0;
|
||||
switch (rrecp->r_opcode) {
|
||||
case YXDOMAIN:
|
||||
rclass = C_ANY;
|
||||
rtype = T_ANY;
|
||||
rrecp->r_size = 0;
|
||||
break;
|
||||
case NXDOMAIN:
|
||||
rclass = C_NONE;
|
||||
rtype = T_ANY;
|
||||
rrecp->r_size = 0;
|
||||
break;
|
||||
case NXRRSET:
|
||||
rclass = C_NONE;
|
||||
rrecp->r_size = 0;
|
||||
break;
|
||||
case YXRRSET:
|
||||
if (rrecp->r_size == 0)
|
||||
rclass = C_ANY;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,
|
||||
"res_nmkupdate: incorrect opcode: %d\n",
|
||||
rrecp->r_opcode);
|
||||
fflush(stderr);
|
||||
return (-1);
|
||||
}
|
||||
} else if (section == S_UPDATE) {
|
||||
switch (rrecp->r_opcode) {
|
||||
case DELETE:
|
||||
rclass = rrecp->r_size == 0 ? C_ANY : C_NONE;
|
||||
break;
|
||||
case ADD:
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,
|
||||
"res_nmkupdate: incorrect opcode: %d\n",
|
||||
rrecp->r_opcode);
|
||||
fflush(stderr);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX appending default domain to owner name is omitted,
|
||||
* fqdn must be provided
|
||||
*/
|
||||
if ((n = dn_comp(rrecp->r_dname, cp, buflen, dnptrs,
|
||||
lastdnptr)) < 0)
|
||||
return (-1);
|
||||
cp += n;
|
||||
ShrinkBuffer(n + 2*INT16SZ);
|
||||
PUTSHORT(rtype, cp);
|
||||
PUTSHORT(rclass, cp);
|
||||
if (section == S_ZONE) {
|
||||
if (numrrs != 1 || rrecp->r_type != T_SOA)
|
||||
return (-3);
|
||||
continue;
|
||||
}
|
||||
ShrinkBuffer(INT32SZ + INT16SZ);
|
||||
PUTLONG(rttl, cp);
|
||||
sp2 = cp; /* save pointer to length byte */
|
||||
cp += INT16SZ;
|
||||
if (rrecp->r_size == 0) {
|
||||
if (section == S_UPDATE && rclass != C_ANY)
|
||||
return (-1);
|
||||
else {
|
||||
PUTSHORT(0, sp2);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
startp = rrecp->r_data;
|
||||
endp = startp + rrecp->r_size - 1;
|
||||
/* XXX this should be done centrally. */
|
||||
switch (rrecp->r_type) {
|
||||
case T_A:
|
||||
if (!getword_str(buf2, sizeof buf2, &startp, endp))
|
||||
return (-1);
|
||||
if (!inet_aton(buf2, &ina))
|
||||
return (-1);
|
||||
n1 = ntohl(ina.s_addr);
|
||||
ShrinkBuffer(INT32SZ);
|
||||
PUTLONG(n1, cp);
|
||||
break;
|
||||
case T_CNAME:
|
||||
case T_MB:
|
||||
case T_MG:
|
||||
case T_MR:
|
||||
case T_NS:
|
||||
case T_PTR:
|
||||
if (!getword_str(buf2, sizeof buf2, &startp, endp))
|
||||
return (-1);
|
||||
n = dn_comp(buf2, cp, buflen, dnptrs, lastdnptr);
|
||||
if (n < 0)
|
||||
return (-1);
|
||||
cp += n;
|
||||
ShrinkBuffer(n);
|
||||
break;
|
||||
case T_MINFO:
|
||||
case T_SOA:
|
||||
case T_RP:
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (!getword_str(buf2, sizeof buf2, &startp,
|
||||
endp))
|
||||
return (-1);
|
||||
n = dn_comp(buf2, cp, buflen,
|
||||
dnptrs, lastdnptr);
|
||||
if (n < 0)
|
||||
return (-1);
|
||||
cp += n;
|
||||
ShrinkBuffer(n);
|
||||
}
|
||||
if (rrecp->r_type == T_SOA) {
|
||||
ShrinkBuffer(5 * INT32SZ);
|
||||
while (isspace(*startp) || !*startp)
|
||||
startp++;
|
||||
if (*startp == '(') {
|
||||
multiline = 1;
|
||||
startp++;
|
||||
} else
|
||||
multiline = 0;
|
||||
/* serial, refresh, retry, expire, minimum */
|
||||
for (i = 0; i < 5; i++) {
|
||||
soanum = getnum_str(&startp, endp);
|
||||
if (soanum < 0)
|
||||
return (-1);
|
||||
PUTLONG(soanum, cp);
|
||||
}
|
||||
if (multiline) {
|
||||
while (isspace(*startp) || !*startp)
|
||||
startp++;
|
||||
if (*startp != ')')
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case T_MX:
|
||||
case T_AFSDB:
|
||||
case T_RT:
|
||||
n = getnum_str(&startp, endp);
|
||||
if (n < 0)
|
||||
return (-1);
|
||||
PUTSHORT(n, cp);
|
||||
ShrinkBuffer(INT16SZ);
|
||||
if (!getword_str(buf2, sizeof buf2, &startp, endp))
|
||||
return (-1);
|
||||
n = dn_comp(buf2, cp, buflen, dnptrs, lastdnptr);
|
||||
if (n < 0)
|
||||
return (-1);
|
||||
cp += n;
|
||||
ShrinkBuffer(n);
|
||||
break;
|
||||
case T_PX:
|
||||
n = getnum_str(&startp, endp);
|
||||
if (n < 0)
|
||||
return (-1);
|
||||
PUTSHORT(n, cp);
|
||||
ShrinkBuffer(INT16SZ);
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (!getword_str(buf2, sizeof buf2, &startp,
|
||||
endp))
|
||||
return (-1);
|
||||
n = dn_comp(buf2, cp, buflen, dnptrs,
|
||||
lastdnptr);
|
||||
if (n < 0)
|
||||
return (-1);
|
||||
cp += n;
|
||||
ShrinkBuffer(n);
|
||||
}
|
||||
break;
|
||||
case T_WKS:
|
||||
case T_HINFO:
|
||||
case T_TXT:
|
||||
case T_X25:
|
||||
case T_ISDN:
|
||||
case T_NSAP:
|
||||
case T_LOC:
|
||||
/* XXX - more fine tuning needed here */
|
||||
ShrinkBuffer(rrecp->r_size);
|
||||
memcpy(cp, rrecp->r_data, rrecp->r_size);
|
||||
cp += rrecp->r_size;
|
||||
break;
|
||||
default:
|
||||
return (-1);
|
||||
} /*switch*/
|
||||
n = (u_int16_t)((cp - sp2) - INT16SZ);
|
||||
PUTSHORT(n, sp2);
|
||||
} /*for*/
|
||||
|
||||
hp->qdcount = htons(counts[0]);
|
||||
hp->ancount = htons(counts[1]);
|
||||
hp->nscount = htons(counts[2]);
|
||||
hp->arcount = htons(counts[3]);
|
||||
return (cp - buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get a whitespace delimited word from a string (not file)
|
||||
* into buf. modify the start pointer to point after the
|
||||
* word in the string.
|
||||
*/
|
||||
static int
|
||||
getword_str(char *buf, int size, u_char **startpp, u_char *endp) {
|
||||
char *cp;
|
||||
int c;
|
||||
|
||||
for (cp = buf; *startpp <= endp; ) {
|
||||
c = **startpp;
|
||||
if (isspace(c) || c == '\0') {
|
||||
if (cp != buf) /* trailing whitespace */
|
||||
break;
|
||||
else { /* leading whitespace */
|
||||
(*startpp)++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
(*startpp)++;
|
||||
if (cp >= buf+size-1)
|
||||
break;
|
||||
*cp++ = (u_char)c;
|
||||
}
|
||||
*cp = '\0';
|
||||
return (cp != buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get a whitespace delimited number from a string (not file) into buf
|
||||
* update the start pointer to point after the number in the string.
|
||||
*/
|
||||
static int
|
||||
getnum_str(u_char **startpp, u_char *endp) {
|
||||
int c, n;
|
||||
int seendigit = 0;
|
||||
int m = 0;
|
||||
|
||||
for (n = 0; *startpp <= endp; ) {
|
||||
c = **startpp;
|
||||
if (isspace(c) || c == '\0') {
|
||||
if (seendigit) /* trailing whitespace */
|
||||
break;
|
||||
else { /* leading whitespace */
|
||||
(*startpp)++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (c == ';') {
|
||||
while ((*startpp <= endp) &&
|
||||
((c = **startpp) != '\n'))
|
||||
(*startpp)++;
|
||||
if (seendigit)
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
if (!isdigit(c)) {
|
||||
if (c == ')' && seendigit) {
|
||||
(*startpp)--;
|
||||
break;
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
(*startpp)++;
|
||||
n = n * 10 + (c - '0');
|
||||
seendigit = 1;
|
||||
}
|
||||
return (n + m);
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate a resource record buffer & save rr info.
|
||||
*/
|
||||
ns_updrec *
|
||||
res_mkupdrec(int section, const char *dname,
|
||||
u_int class, u_int type, u_long ttl) {
|
||||
ns_updrec *rrecp = (ns_updrec *)calloc(1, sizeof(ns_updrec));
|
||||
|
||||
if (!rrecp || !(rrecp->r_dname = strdup(dname)))
|
||||
return (NULL);
|
||||
rrecp->r_class = class;
|
||||
rrecp->r_type = type;
|
||||
rrecp->r_ttl = ttl;
|
||||
rrecp->r_section = section;
|
||||
return (rrecp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Free a resource record buffer created by res_mkupdrec.
|
||||
*/
|
||||
void
|
||||
res_freeupdrec(ns_updrec *rrecp) {
|
||||
/* Note: freeing r_dp is the caller's responsibility. */
|
||||
if (rrecp->r_dname != NULL)
|
||||
free(rrecp->r_dname);
|
||||
free(rrecp);
|
||||
}
|
@ -1,522 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1996 by 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Based on the Dynamic DNS reference implementation by Viraj Bais
|
||||
* <viraj_bais@ccm.fm.intel.com>
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/time.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <arpa/nameser.h>
|
||||
#include <limits.h>
|
||||
#include <netdb.h>
|
||||
#include <resolv.h>
|
||||
#include <res_update.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Separate a linked list of records into groups so that all records
|
||||
* in a group will belong to a single zone on the nameserver.
|
||||
* Create a dynamic update packet for each zone and send it to the
|
||||
* nameservers for that zone, and await answer.
|
||||
* Abort if error occurs in updating any zone.
|
||||
* Return the number of zones updated on success, < 0 on error.
|
||||
*
|
||||
* On error, caller must deal with the unsynchronized zones
|
||||
* eg. an A record might have been successfully added to the forward
|
||||
* zone but the corresponding PTR record would be missing if error
|
||||
* was encountered while updating the reverse zone.
|
||||
*/
|
||||
|
||||
#define NSMAX 16
|
||||
|
||||
struct ns1 {
|
||||
char nsname[MAXDNAME];
|
||||
struct in_addr nsaddr1;
|
||||
};
|
||||
|
||||
struct zonegrp {
|
||||
char z_origin[MAXDNAME];
|
||||
int16_t z_class;
|
||||
char z_soardata[MAXDNAME + 5 * INT32SZ];
|
||||
struct ns1 z_ns[NSMAX];
|
||||
int z_nscount;
|
||||
ns_updrec * z_rr;
|
||||
struct zonegrp *z_next;
|
||||
};
|
||||
|
||||
|
||||
int
|
||||
res_nupdate(res_state statp, ns_updrec *rrecp_in, ns_tsig_key *key) {
|
||||
ns_updrec *rrecp, *tmprrecp;
|
||||
u_char buf[PACKETSZ], answer[PACKETSZ], packet[2*PACKETSZ];
|
||||
char name[MAXDNAME], zname[MAXDNAME], primary[MAXDNAME],
|
||||
mailaddr[MAXDNAME];
|
||||
u_char soardata[2*MAXCDNAME+5*INT32SZ];
|
||||
char *dname, *svdname, *cp1, *target;
|
||||
u_char *cp, *eom;
|
||||
HEADER *hp = (HEADER *) answer;
|
||||
struct zonegrp *zptr = NULL, *tmpzptr, *prevzptr, *zgrp_start = NULL;
|
||||
int i, j, k = 0, n, ancount, nscount, arcount, rcode, rdatasize,
|
||||
newgroup, done, myzone, seen_before, numzones = 0;
|
||||
u_int16_t dlen, class, qclass, type, qtype;
|
||||
u_int32_t ttl;
|
||||
|
||||
if (key != NULL) {
|
||||
/* TSIG is not supported. */
|
||||
RES_SET_H_ERRNO(statp, NO_RECOVERY);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
for (rrecp = rrecp_in; rrecp; rrecp = rrecp->r_next) {
|
||||
dname = rrecp->r_dname;
|
||||
n = strlen(dname);
|
||||
if (dname[n-1] == '.')
|
||||
dname[n-1] = '\0';
|
||||
qtype = T_SOA;
|
||||
qclass = rrecp->r_class;
|
||||
done = 0;
|
||||
seen_before = 0;
|
||||
|
||||
while (!done && dname) {
|
||||
if (qtype == T_SOA) {
|
||||
for (tmpzptr = zgrp_start;
|
||||
tmpzptr && !seen_before;
|
||||
tmpzptr = tmpzptr->z_next) {
|
||||
if (strcasecmp(dname,
|
||||
tmpzptr->z_origin) == 0 &&
|
||||
tmpzptr->z_class == qclass)
|
||||
seen_before++;
|
||||
for (tmprrecp = tmpzptr->z_rr;
|
||||
tmprrecp && !seen_before;
|
||||
tmprrecp = tmprrecp->r_grpnext)
|
||||
if (strcasecmp(dname, tmprrecp->r_dname) == 0
|
||||
&& tmprrecp->r_class == qclass) {
|
||||
seen_before++;
|
||||
break;
|
||||
}
|
||||
if (seen_before) {
|
||||
/*
|
||||
* Append to the end of
|
||||
* current group.
|
||||
*/
|
||||
for (tmprrecp = tmpzptr->z_rr;
|
||||
tmprrecp->r_grpnext;
|
||||
tmprrecp = tmprrecp->r_grpnext)
|
||||
(void)NULL;
|
||||
tmprrecp->r_grpnext = rrecp;
|
||||
rrecp->r_grpnext = NULL;
|
||||
done = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (qtype == T_A) {
|
||||
for (tmpzptr = zgrp_start;
|
||||
tmpzptr && !done;
|
||||
tmpzptr = tmpzptr->z_next)
|
||||
for (i = 0; i < tmpzptr->z_nscount; i++)
|
||||
if (tmpzptr->z_class == qclass &&
|
||||
strcasecmp(tmpzptr->z_ns[i].nsname,
|
||||
dname) == 0 &&
|
||||
tmpzptr->z_ns[i].nsaddr1.s_addr != 0) {
|
||||
zptr->z_ns[k].nsaddr1.s_addr =
|
||||
tmpzptr->z_ns[i].nsaddr1.s_addr;
|
||||
done = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (done)
|
||||
break;
|
||||
n = res_nmkquery(statp, QUERY, dname, qclass, qtype, NULL,
|
||||
0, NULL, buf, sizeof buf);
|
||||
if (n <= 0) {
|
||||
fprintf(stderr, "res_nupdate: mkquery failed\n");
|
||||
return (n);
|
||||
}
|
||||
n = res_nsend(statp, buf, n, answer, sizeof answer);
|
||||
if (n < 0) {
|
||||
fprintf(stderr, "res_nupdate: send error for %s\n",
|
||||
rrecp->r_dname);
|
||||
return (n);
|
||||
} else if (n > sizeof(answer)) {
|
||||
fprintf(stderr, "res_nupdate: buffer too small\n");
|
||||
return (-1);
|
||||
}
|
||||
if (n < HFIXEDSZ)
|
||||
return (-1);
|
||||
ancount = ntohs(hp->ancount);
|
||||
nscount = ntohs(hp->nscount);
|
||||
arcount = ntohs(hp->arcount);
|
||||
rcode = hp->rcode;
|
||||
cp = answer + HFIXEDSZ;
|
||||
eom = answer + n;
|
||||
/* skip the question section */
|
||||
n = dn_skipname(cp, eom);
|
||||
if (n < 0 || cp + n + 2 * INT16SZ > eom)
|
||||
return (-1);
|
||||
cp += n + 2 * INT16SZ;
|
||||
|
||||
if (qtype == T_SOA) {
|
||||
if (ancount == 0 && nscount == 0 && arcount == 0) {
|
||||
/*
|
||||
* if (rcode == NOERROR) then the dname exists but
|
||||
* has no soa record associated with it.
|
||||
* if (rcode == NXDOMAIN) then the dname does not
|
||||
* exist and the server is replying out of NCACHE.
|
||||
* in either case, proceed with the next try
|
||||
*/
|
||||
dname = strchr(dname, '.');
|
||||
if (dname != NULL)
|
||||
dname++;
|
||||
continue;
|
||||
} else if ((rcode == NOERROR || rcode == NXDOMAIN) &&
|
||||
ancount == 0 &&
|
||||
nscount == 1 && arcount == 0) {
|
||||
/*
|
||||
* name/data does not exist, soa record supplied in the
|
||||
* authority section
|
||||
*/
|
||||
/* authority section must contain the soa record */
|
||||
if ((n = dn_expand(answer, eom, cp, zname,
|
||||
sizeof zname)) < 0)
|
||||
return (n);
|
||||
cp += n;
|
||||
if (cp + 2 * INT16SZ > eom)
|
||||
return (-1);
|
||||
GETSHORT(type, cp);
|
||||
GETSHORT(class, cp);
|
||||
if (type != T_SOA || class != qclass) {
|
||||
fprintf(stderr, "unknown answer\n");
|
||||
return (-1);
|
||||
}
|
||||
myzone = 0;
|
||||
svdname = dname;
|
||||
while (dname)
|
||||
if (strcasecmp(dname, zname) == 0) {
|
||||
myzone = 1;
|
||||
break;
|
||||
} else if ((dname = strchr(dname, '.')) != NULL)
|
||||
dname++;
|
||||
if (!myzone) {
|
||||
dname = strchr(svdname, '.');
|
||||
if (dname != NULL)
|
||||
dname++;
|
||||
continue;
|
||||
}
|
||||
nscount = 0;
|
||||
/* fallthrough */
|
||||
} else if (rcode == NOERROR && ancount == 1) {
|
||||
/*
|
||||
* found the zone name
|
||||
* new servers will supply NS records for the zone
|
||||
* in authority section and A records for those
|
||||
* nameservers in the additional section
|
||||
* older servers have to be explicitly queried for
|
||||
* NS records for the zone
|
||||
*/
|
||||
/* answer section must contain the soa record */
|
||||
if ((n = dn_expand(answer, eom, cp, zname,
|
||||
sizeof zname)) < 0)
|
||||
return (n);
|
||||
else
|
||||
cp += n;
|
||||
if (cp + 2 * INT16SZ > eom)
|
||||
return (-1);
|
||||
GETSHORT(type, cp);
|
||||
GETSHORT(class, cp);
|
||||
if (type == T_CNAME) {
|
||||
dname = strchr(dname, '.');
|
||||
if (dname != NULL)
|
||||
dname++;
|
||||
continue;
|
||||
}
|
||||
if (strcasecmp(dname, zname) != 0 ||
|
||||
type != T_SOA ||
|
||||
class != rrecp->r_class) {
|
||||
fprintf(stderr, "unknown answer\n");
|
||||
return (-1);
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
} else {
|
||||
fprintf(stderr,
|
||||
"unknown response: ans=%d, auth=%d, add=%d, rcode=%d\n",
|
||||
ancount, nscount, arcount, hp->rcode);
|
||||
return (-1);
|
||||
}
|
||||
if (cp + INT32SZ + INT16SZ > eom)
|
||||
return (-1);
|
||||
/* continue processing the soa record */
|
||||
GETLONG(ttl, cp);
|
||||
GETSHORT(dlen, cp);
|
||||
if (cp + dlen > eom)
|
||||
return (-1);
|
||||
newgroup = 1;
|
||||
zptr = zgrp_start;
|
||||
prevzptr = NULL;
|
||||
while (zptr) {
|
||||
if (strcasecmp(zname, zptr->z_origin) == 0 &&
|
||||
type == T_SOA && class == qclass) {
|
||||
newgroup = 0;
|
||||
break;
|
||||
}
|
||||
prevzptr = zptr;
|
||||
zptr = zptr->z_next;
|
||||
}
|
||||
if (!newgroup) {
|
||||
for (tmprrecp = zptr->z_rr;
|
||||
tmprrecp->r_grpnext;
|
||||
tmprrecp = tmprrecp->r_grpnext)
|
||||
;
|
||||
tmprrecp->r_grpnext = rrecp;
|
||||
rrecp->r_grpnext = NULL;
|
||||
done = 1;
|
||||
cp += dlen;
|
||||
break;
|
||||
} else {
|
||||
if ((n = dn_expand(answer, eom, cp, primary,
|
||||
sizeof primary)) < 0)
|
||||
return (n);
|
||||
cp += n;
|
||||
/*
|
||||
* We don't have to bounds check here because the
|
||||
* next use of 'cp' is in dn_expand().
|
||||
*/
|
||||
cp1 = (char *)soardata;
|
||||
strcpy(cp1, primary);
|
||||
cp1 += strlen(cp1) + 1;
|
||||
if ((n = dn_expand(answer, eom, cp, mailaddr,
|
||||
sizeof mailaddr)) < 0)
|
||||
return (n);
|
||||
cp += n;
|
||||
strcpy(cp1, mailaddr);
|
||||
cp1 += strlen(cp1) + 1;
|
||||
if (cp + 5*INT32SZ > eom)
|
||||
return (-1);
|
||||
memcpy(cp1, cp, 5*INT32SZ);
|
||||
cp += 5*INT32SZ;
|
||||
cp1 += 5*INT32SZ;
|
||||
rdatasize = (u_char *)cp1 - soardata;
|
||||
zptr = calloc(1, sizeof(struct zonegrp));
|
||||
if (zptr == NULL)
|
||||
return (-1);
|
||||
if (zgrp_start == NULL)
|
||||
zgrp_start = zptr;
|
||||
else
|
||||
prevzptr->z_next = zptr;
|
||||
zptr->z_rr = rrecp;
|
||||
rrecp->r_grpnext = NULL;
|
||||
strcpy(zptr->z_origin, zname);
|
||||
zptr->z_class = class;
|
||||
memcpy(zptr->z_soardata, soardata, rdatasize);
|
||||
/* fallthrough to process NS and A records */
|
||||
}
|
||||
} else if (qtype == T_NS) {
|
||||
if (rcode == NOERROR && ancount > 0) {
|
||||
strcpy(zname, dname);
|
||||
for (zptr = zgrp_start; zptr; zptr = zptr->z_next) {
|
||||
if (strcasecmp(zname, zptr->z_origin) == 0)
|
||||
break;
|
||||
}
|
||||
if (zptr == NULL)
|
||||
/* should not happen */
|
||||
return (-1);
|
||||
if (nscount > 0) {
|
||||
/*
|
||||
* answer and authority sections contain
|
||||
* the same information, skip answer section
|
||||
*/
|
||||
for (j = 0; j < ancount; j++) {
|
||||
n = dn_skipname(cp, eom);
|
||||
if (n < 0)
|
||||
return (-1);
|
||||
n += 2*INT16SZ + INT32SZ;
|
||||
if (cp + n + INT16SZ > eom)
|
||||
return (-1);
|
||||
cp += n;
|
||||
GETSHORT(dlen, cp);
|
||||
cp += dlen;
|
||||
}
|
||||
} else
|
||||
nscount = ancount;
|
||||
/* fallthrough to process NS and A records */
|
||||
} else {
|
||||
fprintf(stderr, "cannot determine nameservers for %s:\
|
||||
ans=%d, auth=%d, add=%d, rcode=%d\n",
|
||||
dname, ancount, nscount, arcount, hp->rcode);
|
||||
return (-1);
|
||||
}
|
||||
} else if (qtype == T_A) {
|
||||
if (rcode == NOERROR && ancount > 0) {
|
||||
arcount = ancount;
|
||||
ancount = nscount = 0;
|
||||
/* fallthrough to process A records */
|
||||
} else {
|
||||
fprintf(stderr, "cannot determine address for %s:\
|
||||
ans=%d, auth=%d, add=%d, rcode=%d\n",
|
||||
dname, ancount, nscount, arcount, hp->rcode);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
/* process NS records for the zone */
|
||||
j = 0;
|
||||
for (i = 0; i < nscount; i++) {
|
||||
if ((n = dn_expand(answer, eom, cp, name,
|
||||
sizeof name)) < 0)
|
||||
return (n);
|
||||
cp += n;
|
||||
if (cp + 3 * INT16SZ + INT32SZ > eom)
|
||||
return (-1);
|
||||
GETSHORT(type, cp);
|
||||
GETSHORT(class, cp);
|
||||
GETLONG(ttl, cp);
|
||||
GETSHORT(dlen, cp);
|
||||
if (cp + dlen > eom)
|
||||
return (-1);
|
||||
if (strcasecmp(name, zname) == 0 &&
|
||||
type == T_NS && class == qclass) {
|
||||
if ((n = dn_expand(answer, eom, cp,
|
||||
name, sizeof name)) < 0)
|
||||
return (n);
|
||||
target = zptr->z_ns[j++].nsname;
|
||||
strcpy(target, name);
|
||||
}
|
||||
cp += dlen;
|
||||
}
|
||||
if (zptr->z_nscount == 0)
|
||||
zptr->z_nscount = j;
|
||||
/* get addresses for the nameservers */
|
||||
for (i = 0; i < arcount; i++) {
|
||||
if ((n = dn_expand(answer, eom, cp, name,
|
||||
sizeof name)) < 0)
|
||||
return (n);
|
||||
cp += n;
|
||||
if (cp + 3 * INT16SZ + INT32SZ > eom)
|
||||
return (-1);
|
||||
GETSHORT(type, cp);
|
||||
GETSHORT(class, cp);
|
||||
GETLONG(ttl, cp);
|
||||
GETSHORT(dlen, cp);
|
||||
if (cp + dlen > eom)
|
||||
return (-1);
|
||||
if (type == T_A && dlen == INT32SZ && class == qclass) {
|
||||
for (j = 0; j < zptr->z_nscount; j++)
|
||||
if (strcasecmp(name, zptr->z_ns[j].nsname) == 0) {
|
||||
memcpy(&zptr->z_ns[j].nsaddr1.s_addr, cp,
|
||||
INT32SZ);
|
||||
break;
|
||||
}
|
||||
}
|
||||
cp += dlen;
|
||||
}
|
||||
if (zptr->z_nscount == 0) {
|
||||
dname = zname;
|
||||
qtype = T_NS;
|
||||
continue;
|
||||
}
|
||||
done = 1;
|
||||
for (k = 0; k < zptr->z_nscount; k++)
|
||||
if (zptr->z_ns[k].nsaddr1.s_addr == 0) {
|
||||
done = 0;
|
||||
dname = zptr->z_ns[k].nsname;
|
||||
qtype = T_A;
|
||||
}
|
||||
|
||||
} /* while */
|
||||
}
|
||||
|
||||
statp->options |= RES_DEBUG;
|
||||
for (zptr = zgrp_start; zptr; zptr = zptr->z_next) {
|
||||
|
||||
/* append zone section */
|
||||
rrecp = res_mkupdrec(ns_s_zn, zptr->z_origin,
|
||||
zptr->z_class, ns_t_soa, 0);
|
||||
if (rrecp == NULL) {
|
||||
fprintf(stderr, "saverrec error\n");
|
||||
fflush(stderr);
|
||||
return (-1);
|
||||
}
|
||||
rrecp->r_grpnext = zptr->z_rr;
|
||||
zptr->z_rr = rrecp;
|
||||
|
||||
n = res_nmkupdate(statp, zptr->z_rr, packet, sizeof packet);
|
||||
if (n < 0) {
|
||||
fprintf(stderr, "res_nmkupdate error\n");
|
||||
fflush(stderr);
|
||||
return (-1);
|
||||
} else
|
||||
fprintf(stdout, "res_nmkupdate: packet size = %d\n", n);
|
||||
|
||||
/*
|
||||
* Override the list of NS records from res_ninit() with
|
||||
* the authoritative nameservers for the zone being updated.
|
||||
* Sort primary to be the first in the list of nameservers.
|
||||
*/
|
||||
for (i = 0; i < zptr->z_nscount; i++) {
|
||||
if (strcasecmp(zptr->z_ns[i].nsname,
|
||||
zptr->z_soardata) == 0) {
|
||||
struct in_addr tmpaddr;
|
||||
|
||||
if (i != 0) {
|
||||
strcpy(zptr->z_ns[i].nsname,
|
||||
zptr->z_ns[0].nsname);
|
||||
strcpy(zptr->z_ns[0].nsname,
|
||||
zptr->z_soardata);
|
||||
tmpaddr = zptr->z_ns[i].nsaddr1;
|
||||
zptr->z_ns[i].nsaddr1 =
|
||||
zptr->z_ns[0].nsaddr1;
|
||||
zptr->z_ns[0].nsaddr1 = tmpaddr;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < MAXNS; i++) {
|
||||
statp->nsaddr_list[i].sin_addr = zptr->z_ns[i].nsaddr1;
|
||||
statp->nsaddr_list[i].sin_family = AF_INET;
|
||||
statp->nsaddr_list[i].sin_port = htons(NAMESERVER_PORT);
|
||||
}
|
||||
statp->nscount = (zptr->z_nscount < MAXNS) ?
|
||||
zptr->z_nscount : MAXNS;
|
||||
n = res_nsend(statp, packet, n, answer, sizeof(answer));
|
||||
if (n < 0) {
|
||||
fprintf(stderr, "res_nsend: send error, n=%d\n", n);
|
||||
break;
|
||||
} else if (n > sizeof(answer)) {
|
||||
fprintf(stderr, "res_nsend: buffer too small\n");
|
||||
break;
|
||||
}
|
||||
numzones++;
|
||||
}
|
||||
|
||||
/* free malloc'ed memory */
|
||||
while(zgrp_start) {
|
||||
zptr = zgrp_start;
|
||||
zgrp_start = zgrp_start->z_next;
|
||||
res_freeupdrec(zptr->z_rr); /* Zone section we allocated. */
|
||||
free((char *)zptr);
|
||||
}
|
||||
|
||||
return (numzones);
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
.PATH: ${.CURDIR}/resolv
|
||||
|
||||
SRCS+= herror.c h_errno.c mtctxres.c res_comp.c res_data.c res_debug.c \
|
||||
res_init.c res_mkquery.c res_query.c res_send.c res_state.c
|
||||
res_findzonecut.c res_init.c res_mkquery.c res_mkupdate.c \
|
||||
res_query.c res_send.c res_state.c res_update.c
|
||||
|
||||
SYM_MAPS+= ${.CURDIR}/resolv/Symbol.map
|
||||
|
@ -61,10 +61,13 @@ FBSD_1.0 {
|
||||
__h_error;
|
||||
h_errno;
|
||||
res_init;
|
||||
__res_findzonecut2;
|
||||
__res_freeupdrec;
|
||||
__res_mkquery;
|
||||
res_mkquery;
|
||||
__res_mkupdrec;
|
||||
__res_mkupdate;
|
||||
__res_opt;
|
||||
__res_freeupdrec;
|
||||
#__res_get_nibblesuffix; # Excluded
|
||||
#__res_get_nibblesuffix2; # Excluded
|
||||
__res_getservers;
|
||||
@ -75,11 +78,13 @@ FBSD_1.0 {
|
||||
__res_ndestroy;
|
||||
__res_ninit;
|
||||
__res_nmkquery;
|
||||
__res_nmkupdate;
|
||||
__res_nopt;
|
||||
__res_nquery;
|
||||
__res_nquerydomain;
|
||||
__res_nsearch;
|
||||
__res_nsend;
|
||||
__res_nupdate;
|
||||
__res_ourserver_p;
|
||||
__res_pquery;
|
||||
__res_query;
|
||||
@ -100,6 +105,5 @@ FBSD_1.0 {
|
||||
__res_close;
|
||||
_res_close;
|
||||
res_send;
|
||||
__res_mkupdate;
|
||||
res_update; # Why is this not __res_update?
|
||||
__res_update;
|
||||
};
|
||||
|
@ -19,6 +19,9 @@ static const char rcsid[] = "$Id: res_findzonecut.c,v 1.2.2.3.4.4 2005/10/11 00:
|
||||
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/* Import. */
|
||||
|
||||
#include "port_before.h"
|
||||
@ -149,6 +152,7 @@ static void res_dprintf(const char *, ...) ISC_FORMAT_PRINTF(1, 2);
|
||||
* keep going. for the NS and A queries this means we just give up.
|
||||
*/
|
||||
|
||||
#ifndef _LIBC
|
||||
int
|
||||
res_findzonecut(res_state statp, const char *dname, ns_class class, int opts,
|
||||
char *zname, size_t zsize, struct in_addr *addrs, int naddrs)
|
||||
@ -173,6 +177,7 @@ res_findzonecut(res_state statp, const char *dname, ns_class class, int opts,
|
||||
free(u);
|
||||
return (result);
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
res_findzonecut2(res_state statp, const char *dname, ns_class class, int opts,
|
||||
|
@ -23,6 +23,8 @@
|
||||
#if !defined(lint) && !defined(SABER)
|
||||
static const char rcsid[] = "$Id: res_mkupdate.c,v 1.1.2.1.4.5 2005/10/14 05:43:47 marka Exp $";
|
||||
#endif /* not lint */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "port_before.h"
|
||||
|
||||
@ -44,6 +46,10 @@ static const char rcsid[] = "$Id: res_mkupdate.c,v 1.1.2.1.4.5 2005/10/14 05:43:
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef _LIBC
|
||||
#include <isc/list.h>
|
||||
#endif
|
||||
|
||||
#include "port_after.h"
|
||||
|
||||
/* Options. Leave them on. */
|
||||
@ -59,7 +65,13 @@ static int getstr_str(char *, int, u_char **, u_char *);
|
||||
|
||||
/* Forward. */
|
||||
|
||||
#ifdef _LIBC
|
||||
static
|
||||
#endif
|
||||
int res_protocolnumber(const char *);
|
||||
#ifdef _LIBC
|
||||
static
|
||||
#endif
|
||||
int res_servicenumber(const char *);
|
||||
|
||||
/*
|
||||
@ -89,7 +101,10 @@ res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf, int buflen) {
|
||||
u_int16_t rtype, rclass;
|
||||
u_int32_t n1, rttl;
|
||||
u_char *dnptrs[20], **dpp, **lastdnptr;
|
||||
int siglen, keylen, certlen;
|
||||
#ifndef _LIBC
|
||||
int siglen;
|
||||
#endif
|
||||
int keylen, certlen;
|
||||
|
||||
/*
|
||||
* Initialize header fields.
|
||||
@ -445,6 +460,9 @@ res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf, int buflen) {
|
||||
return (-1);
|
||||
break;
|
||||
case ns_t_sig:
|
||||
#ifdef _LIBC
|
||||
return (-1);
|
||||
#else
|
||||
{
|
||||
int sig_type, success, dateerror;
|
||||
u_int32_t exptime, timesigned;
|
||||
@ -535,6 +553,7 @@ res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf, int buflen) {
|
||||
cp += siglen;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
case ns_t_key:
|
||||
/* flags */
|
||||
n = gethexnum_str(&startp, endp);
|
||||
@ -980,6 +999,7 @@ res_buildservicelist() {
|
||||
endservent();
|
||||
}
|
||||
|
||||
#ifndef _LIBC
|
||||
void
|
||||
res_destroyservicelist() {
|
||||
struct valuelist *slp, *slp_next;
|
||||
@ -992,7 +1012,11 @@ res_destroyservicelist() {
|
||||
}
|
||||
servicelist = (struct valuelist *)0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef _LIBC
|
||||
static
|
||||
#endif
|
||||
void
|
||||
res_buildprotolist(void) {
|
||||
struct protoent *pp;
|
||||
@ -1022,6 +1046,7 @@ res_buildprotolist(void) {
|
||||
endprotoent();
|
||||
}
|
||||
|
||||
#ifndef _LIBC
|
||||
void
|
||||
res_destroyprotolist(void) {
|
||||
struct valuelist *plp, *plp_next;
|
||||
@ -1033,6 +1058,7 @@ res_destroyprotolist(void) {
|
||||
}
|
||||
protolist = (struct valuelist *)0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
findservice(const char *s, struct valuelist **list) {
|
||||
@ -1059,6 +1085,9 @@ findservice(const char *s, struct valuelist **list) {
|
||||
/*
|
||||
* Convert service name or (ascii) number to int.
|
||||
*/
|
||||
#ifdef _LIBC
|
||||
static
|
||||
#endif
|
||||
int
|
||||
res_servicenumber(const char *p) {
|
||||
if (servicelist == (struct valuelist *)0)
|
||||
@ -1069,6 +1098,9 @@ res_servicenumber(const char *p) {
|
||||
/*
|
||||
* Convert protocol name or (ascii) number to int.
|
||||
*/
|
||||
#ifdef _LIBC
|
||||
static
|
||||
#endif
|
||||
int
|
||||
res_protocolnumber(const char *p) {
|
||||
if (protolist == (struct valuelist *)0)
|
||||
@ -1076,6 +1108,7 @@ res_protocolnumber(const char *p) {
|
||||
return (findservice(p, &protolist));
|
||||
}
|
||||
|
||||
#ifndef _LIBC
|
||||
static struct servent *
|
||||
cgetservbyport(u_int16_t port, const char *proto) { /* Host byte order. */
|
||||
struct valuelist **list = &servicelist;
|
||||
@ -1156,3 +1189,4 @@ res_servicename(u_int16_t port, const char *proto) { /* Host byte order. */
|
||||
}
|
||||
return (ss->s_name);
|
||||
}
|
||||
#endif
|
||||
|
@ -24,6 +24,9 @@ static const char rcsid[] = "$Id: res_update.c,v 1.6.2.4.4.2 2004/03/16 12:34:20
|
||||
* <viraj_bais@ccm.fm.intel.com>
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "port_before.h"
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -166,10 +169,16 @@ res_nupdate(res_state statp, ns_updrec *rrecp_in, ns_tsig_key *key) {
|
||||
res_setservers(statp, zptr->z_nsaddrs, zptr->z_nscount);
|
||||
|
||||
/* Send the update and remember the result. */
|
||||
if (key != NULL)
|
||||
if (key != NULL) {
|
||||
#ifdef _LIBC
|
||||
DPRINTF(("TSIG is not supported\n"));
|
||||
RES_SET_H_ERRNO(statp, NO_RECOVERY);
|
||||
goto done;
|
||||
#else
|
||||
n = res_nsendsigned(statp, packet, n, key,
|
||||
answer, sizeof answer);
|
||||
else
|
||||
#endif
|
||||
} else
|
||||
n = res_nsend(statp, packet, n, answer, sizeof answer);
|
||||
if (n < 0) {
|
||||
DPRINTF(("res_nsend: send error, n=%d (%s)\n",
|
||||
|
Loading…
Reference in New Issue
Block a user