summaryrefslogtreecommitdiffstats
path: root/contrib/bind/lib
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2004-09-24 19:48:50 +0000
committerdes <des@FreeBSD.org>2004-09-24 19:48:50 +0000
commitbd20f820eed84d93e9324f7de3865ce58a0c7731 (patch)
treebb3edb8dcc07615d426eb359f46c1741e4c22575 /contrib/bind/lib
parent3fe60073ff63db1d6dc640928a53105d35a80da4 (diff)
downloadFreeBSD-src-bd20f820eed84d93e9324f7de3865ce58a0c7731.zip
FreeBSD-src-bd20f820eed84d93e9324f7de3865ce58a0c7731.tar.gz
Retire the BIND 8 sources.
Diffstat (limited to 'contrib/bind/lib')
-rw-r--r--contrib/bind/lib/Makefile112
-rw-r--r--contrib/bind/lib/dst/Makefile98
-rw-r--r--contrib/bind/lib/dst/README27
-rw-r--r--contrib/bind/lib/dst/bsafe_link.c1123
-rw-r--r--contrib/bind/lib/dst/cylink_link.c672
-rw-r--r--contrib/bind/lib/dst/dst_api.c1092
-rw-r--r--contrib/bind/lib/dst/dst_internal.h168
-rw-r--r--contrib/bind/lib/dst/eay_dss_link.c630
-rw-r--r--contrib/bind/lib/dst/hmac_link.c490
-rw-r--r--contrib/bind/lib/dst/md5.h101
-rw-r--r--contrib/bind/lib/dst/md5_dgst.c370
-rw-r--r--contrib/bind/lib/dst/md5_locl.h190
-rw-r--r--contrib/bind/lib/dst/prandom.c853
-rw-r--r--contrib/bind/lib/dst/rsaref_link.c761
-rw-r--r--contrib/bind/lib/dst/support.c459
-rw-r--r--contrib/bind/lib/inet/Makefile97
-rw-r--r--contrib/bind/lib/inet/inet_addr.c206
-rw-r--r--contrib/bind/lib/inet/inet_cidr_ntop.c259
-rw-r--r--contrib/bind/lib/inet/inet_cidr_pton.c275
-rw-r--r--contrib/bind/lib/inet/inet_data.c44
-rw-r--r--contrib/bind/lib/inet/inet_lnaof.c63
-rw-r--r--contrib/bind/lib/inet/inet_makeaddr.c66
-rw-r--r--contrib/bind/lib/inet/inet_net_ntop.c277
-rw-r--r--contrib/bind/lib/inet/inet_net_pton.c399
-rw-r--r--contrib/bind/lib/inet/inet_neta.c87
-rw-r--r--contrib/bind/lib/inet/inet_netof.c62
-rw-r--r--contrib/bind/lib/inet/inet_network.c104
-rw-r--r--contrib/bind/lib/inet/inet_ntoa.c62
-rw-r--r--contrib/bind/lib/inet/inet_ntop.c203
-rw-r--r--contrib/bind/lib/inet/inet_pton.c222
-rw-r--r--contrib/bind/lib/inet/nsap_addr.c108
-rw-r--r--contrib/bind/lib/irs/Makefile119
-rw-r--r--contrib/bind/lib/irs/Makefile.BSD25
-rw-r--r--contrib/bind/lib/irs/README56
-rw-r--r--contrib/bind/lib/irs/dns.c153
-rw-r--r--contrib/bind/lib/irs/dns_gr.c293
-rw-r--r--contrib/bind/lib/irs/dns_ho.c1156
-rw-r--r--contrib/bind/lib/irs/dns_nw.c594
-rw-r--r--contrib/bind/lib/irs/dns_p.h50
-rw-r--r--contrib/bind/lib/irs/dns_pr.c266
-rw-r--r--contrib/bind/lib/irs/dns_pw.c231
-rw-r--r--contrib/bind/lib/irs/dns_sv.c298
-rw-r--r--contrib/bind/lib/irs/gai_strerror.c86
-rw-r--r--contrib/bind/lib/irs/gen.c430
-rw-r--r--contrib/bind/lib/irs/gen_gr.c482
-rw-r--r--contrib/bind/lib/irs/gen_ho.c391
-rw-r--r--contrib/bind/lib/irs/gen_ng.c172
-rw-r--r--contrib/bind/lib/irs/gen_nw.c262
-rw-r--r--contrib/bind/lib/irs/gen_p.h113
-rw-r--r--contrib/bind/lib/irs/gen_pr.c226
-rw-r--r--contrib/bind/lib/irs/gen_pw.c233
-rw-r--r--contrib/bind/lib/irs/gen_sv.c227
-rw-r--r--contrib/bind/lib/irs/getaddrinfo.c1229
-rw-r--r--contrib/bind/lib/irs/getgrent.c223
-rw-r--r--contrib/bind/lib/irs/getgrent_r.c229
-rw-r--r--contrib/bind/lib/irs/gethostent.c1069
-rw-r--r--contrib/bind/lib/irs/gethostent_r.c264
-rw-r--r--contrib/bind/lib/irs/getnameinfo.c322
-rw-r--r--contrib/bind/lib/irs/getnetent.c343
-rw-r--r--contrib/bind/lib/irs/getnetent_r.c227
-rw-r--r--contrib/bind/lib/irs/getnetgrent.c156
-rw-r--r--contrib/bind/lib/irs/getnetgrent_r.c165
-rw-r--r--contrib/bind/lib/irs/getprotoent.c174
-rw-r--r--contrib/bind/lib/irs/getprotoent_r.c216
-rw-r--r--contrib/bind/lib/irs/getpwent.c199
-rw-r--r--contrib/bind/lib/irs/getpwent_r.c275
-rw-r--r--contrib/bind/lib/irs/getservent.c177
-rw-r--r--contrib/bind/lib/irs/getservent_r.c237
-rw-r--r--contrib/bind/lib/irs/hesiod.c524
-rw-r--r--contrib/bind/lib/irs/hesiod_p.h48
-rw-r--r--contrib/bind/lib/irs/irp.c592
-rw-r--r--contrib/bind/lib/irs/irp_gr.c408
-rw-r--r--contrib/bind/lib/irs/irp_ho.c429
-rw-r--r--contrib/bind/lib/irs/irp_ng.c272
-rw-r--r--contrib/bind/lib/irs/irp_nw.c375
-rw-r--r--contrib/bind/lib/irs/irp_p.h59
-rw-r--r--contrib/bind/lib/irs/irp_pr.c353
-rw-r--r--contrib/bind/lib/irs/irp_pw.c358
-rw-r--r--contrib/bind/lib/irs/irp_sv.c369
-rw-r--r--contrib/bind/lib/irs/irpmarshall.c2344
-rw-r--r--contrib/bind/lib/irs/irs_data.c214
-rw-r--r--contrib/bind/lib/irs/irs_data.h62
-rw-r--r--contrib/bind/lib/irs/irs_p.h49
-rw-r--r--contrib/bind/lib/irs/lcl.c140
-rw-r--r--contrib/bind/lib/irs/lcl_gr.c354
-rw-r--r--contrib/bind/lib/irs/lcl_ho.c576
-rw-r--r--contrib/bind/lib/irs/lcl_ng.c444
-rw-r--r--contrib/bind/lib/irs/lcl_nw.c371
-rw-r--r--contrib/bind/lib/irs/lcl_p.h50
-rw-r--r--contrib/bind/lib/irs/lcl_pr.c284
-rw-r--r--contrib/bind/lib/irs/lcl_pw.c308
-rw-r--r--contrib/bind/lib/irs/lcl_sv.c431
-rw-r--r--contrib/bind/lib/irs/nis.c151
-rw-r--r--contrib/bind/lib/irs/nis_gr.c353
-rw-r--r--contrib/bind/lib/irs/nis_ho.c530
-rw-r--r--contrib/bind/lib/irs/nis_ng.c299
-rw-r--r--contrib/bind/lib/irs/nis_nw.c381
-rw-r--r--contrib/bind/lib/irs/nis_p.h46
-rw-r--r--contrib/bind/lib/irs/nis_pr.c297
-rw-r--r--contrib/bind/lib/irs/nis_pw.c287
-rw-r--r--contrib/bind/lib/irs/nis_sv.c305
-rw-r--r--contrib/bind/lib/irs/nul_ng.c126
-rw-r--r--contrib/bind/lib/irs/pathnames.h50
-rw-r--r--contrib/bind/lib/irs/util.c107
-rw-r--r--contrib/bind/lib/isc/Makefile99
-rw-r--r--contrib/bind/lib/isc/assertions.c91
-rw-r--r--contrib/bind/lib/isc/assertions.mdoc138
-rw-r--r--contrib/bind/lib/isc/base64.c320
-rw-r--r--contrib/bind/lib/isc/bitncmp.c66
-rw-r--r--contrib/bind/lib/isc/bitncmp.mdoc82
-rw-r--r--contrib/bind/lib/isc/ctl_clnt.c602
-rw-r--r--contrib/bind/lib/isc/ctl_p.c186
-rw-r--r--contrib/bind/lib/isc/ctl_p.h26
-rw-r--r--contrib/bind/lib/isc/ctl_srvr.c780
-rw-r--r--contrib/bind/lib/isc/ev_connects.c365
-rw-r--r--contrib/bind/lib/isc/ev_files.c283
-rw-r--r--contrib/bind/lib/isc/ev_streams.c306
-rw-r--r--contrib/bind/lib/isc/ev_timers.c415
-rw-r--r--contrib/bind/lib/isc/ev_waits.c245
-rw-r--r--contrib/bind/lib/isc/eventlib.c676
-rw-r--r--contrib/bind/lib/isc/eventlib.mdoc853
-rw-r--r--contrib/bind/lib/isc/eventlib_p.h214
-rw-r--r--contrib/bind/lib/isc/heap.c221
-rw-r--r--contrib/bind/lib/isc/heap.mdoc378
-rw-r--r--contrib/bind/lib/isc/hex.c116
-rw-r--r--contrib/bind/lib/isc/logging.c720
-rw-r--r--contrib/bind/lib/isc/logging.mdoc1056
-rw-r--r--contrib/bind/lib/isc/logging_p.h60
-rw-r--r--contrib/bind/lib/isc/memcluster.c545
-rw-r--r--contrib/bind/lib/isc/memcluster.mdoc376
-rw-r--r--contrib/bind/lib/isc/movefile.c35
-rw-r--r--contrib/bind/lib/isc/tree.c532
-rw-r--r--contrib/bind/lib/isc/tree.mdoc154
-rw-r--r--contrib/bind/lib/nameser/Makefile92
-rw-r--r--contrib/bind/lib/nameser/ns_date.c128
-rw-r--r--contrib/bind/lib/nameser/ns_name.c963
-rw-r--r--contrib/bind/lib/nameser/ns_netint.c56
-rw-r--r--contrib/bind/lib/nameser/ns_parse.c203
-rw-r--r--contrib/bind/lib/nameser/ns_print.c899
-rw-r--r--contrib/bind/lib/nameser/ns_samedomain.c206
-rw-r--r--contrib/bind/lib/nameser/ns_sign.c380
-rw-r--r--contrib/bind/lib/nameser/ns_ttl.c159
-rw-r--r--contrib/bind/lib/nameser/ns_verify.c480
-rw-r--r--contrib/bind/lib/resolv/Makefile95
-rw-r--r--contrib/bind/lib/resolv/herror.c125
-rw-r--r--contrib/bind/lib/resolv/res_comp.c251
-rw-r--r--contrib/bind/lib/resolv/res_data.c291
-rw-r--r--contrib/bind/lib/resolv/res_debug.c1159
-rw-r--r--contrib/bind/lib/resolv/res_debug.h34
-rw-r--r--contrib/bind/lib/resolv/res_findzonecut.c722
-rw-r--r--contrib/bind/lib/resolv/res_init.c732
-rw-r--r--contrib/bind/lib/resolv/res_mkquery.c256
-rw-r--r--contrib/bind/lib/resolv/res_mkupdate.c1158
-rw-r--r--contrib/bind/lib/resolv/res_mkupdate.h24
-rw-r--r--contrib/bind/lib/resolv/res_private.h20
-rw-r--r--contrib/bind/lib/resolv/res_query.c432
-rw-r--r--contrib/bind/lib/resolv/res_send.c1031
-rw-r--r--contrib/bind/lib/resolv/res_sendsigned.c134
-rw-r--r--contrib/bind/lib/resolv/res_update.c212
159 files changed, 0 insertions, 53576 deletions
diff --git a/contrib/bind/lib/Makefile b/contrib/bind/lib/Makefile
deleted file mode 100644
index 489169f..0000000
--- a/contrib/bind/lib/Makefile
+++ /dev/null
@@ -1,112 +0,0 @@
-# Copyright (c) 1996,1999 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.
-
-# $Id: Makefile,v 8.26 2001/08/14 05:57:58 marka Exp $
-
-SUBDIRS = resolv irs isc bsd inet nameser dst cylink dnssafe
-
-# these are only appropriate for FreeBSD or similar, and are used in
-# development. normal builds will be done in the top level directory and
-# this Makefile will be invoked with a lot of overrides for the following:
-SYSTYPE= freebsd
-SHELL= /bin/sh
-O=o
-A=a
-DESTDIR=
-DESTINC= /usr/local/bind/include
-DESTLIB= /usr/local/bind/lib
-TOP= ..
-INCL= ${TOP}/include
-PORTINCL= ${TOP}/port/${SYSTYPE}/include
-LIBBIND= ${TOP}/lib/libbind.${A}
-LIBBINDR= ${TOP}/lib/libbind_r.${A}
-LIBPORT= ${TOP}/port/libport.${A}
-RANLIB= ranlib
-AR= ar cru
-INSTALL= install
-CDEBUG= -g
-REENTRANT=-D_REENTRANT
-INSTALL_EXEC=
-INSTALL_LIB=-o bin -g bin
-
-# Warning: this MARGS has RANLIB=: to prevent submakes from running ranlib
-MARGS = "SYSTYPE=${SYSTYPE}" "SHELL=${SHELL}" "A=${A}" "O=${O}" \
- "CC=${CC}" "LEX=${LEX}" "YACC=${YACC}" "CDEBUG=${CDEBUG}" \
- "SYSLIBS=${SYSLIBS}" "LDFLAGS=${LDFLAGS}" \
- "DESTDIR=${DESTDIR}" "DESTMAN=${DESTMAN}" \
- "DESTBIN=${DESTBIN}" "DESTSBIN=${DESTSBIN}" "DESTEXEC=${DESTEXEC}" \
- "DESTLIB=${DESTLIB}" "DESTINC=${DESTINC}" "DESTHELP=${DESTHELP}" \
- "RANLIB=:" "AR=${AR}" "ARPREF=${ARPREF}" "ARSUFF=${ARSUFF}" \
- "INCL=../${INCL}" "PORTINCL=../${PORTINCL}" "EXE=${EXE}" \
- "LIBBIND=../${LIBBIND}" "LIBPORT=../${LIBPORT}" \
- "INSTALL=${INSTALL}" "TOP=../${TOP}" \
- "REENTRANT=${REENTRANT}" "INSTALL_LIB=${INSTALL_LIB}" \
- "INSTALL_EXEC=${INSTALL_EXEC}" "BOUNDS=${BOUNDS}"
-
-LIB = libbind.${A}
-LIBTS = ${TOP}/lib/libbind.ts
-LIBR = libbind_r.${A}
-LIBRTS = ${TOP}/lib/libbindr.ts
-
-.NOTPARALLEL:
-.NO_PARALLEL:
-
-all depend clean install distclean::
- @for x in ${SUBDIRS}; do \
- (cd $$x; pwd; ${MAKE} ${MARGS} $@) || exit 1; \
- done
-
-all:: ${LIBTS} ${LIBRTS}
-
-${LIBRTS}: ${LIBBINDR}
- ${RANLIB} ${LIBBINDR}
- sleep 1 && touch ${LIBRTS}
-
-${LIBTS}: ${LIBBIND}
- ${RANLIB} ${LIBBIND}
- sleep 1 && touch ${LIBTS}
-
-distclean:: clean
-
-clean:: FRC
- rm -f *~ *.BAK *.CKP *.orig
- rm -f ${LIBBIND} ${LIBTS}
- rm -f ${LIBBINDR} ${LIBRTS}
-
-install:: ${DESTDIR}${DESTLIB} ${DESTDIR}${DESTLIB}/${LIB}
-install:: ${DESTDIR}${DESTLIB} ${DESTDIR}${DESTLIB}/${LIBR}
-
-${DESTDIR}${DESTLIB}:
- mkdir -p ${DESTDIR}${DESTLIB}
-
-${DESTDIR}${DESTLIB}/${LIBR}: ${LIBBINDR}
- ${INSTALL} -c ${INSTALL_LIB} -m 644 ${LIBBINDR} \
- ${DESTDIR}${DESTLIB}/${LIBR}
- ( cd ${DESTDIR}${DESTLIB} ; ${RANLIB} ${LIBR} )
-
-${DESTDIR}${DESTLIB}/${LIB}: ${LIBBIND}
- ${INSTALL} -c ${INSTALL_LIB} -m 644 ${LIBBIND} \
- ${DESTDIR}${DESTLIB}/${LIB}
- ( cd ${DESTDIR}${DESTLIB} ; ${RANLIB} ${LIB} )
-
-links:: FRC
- @set -e; for x in ${SUBDIRS}; do \
- ( mkdir $$x; cd $$x; pwd; ln -s ../SRC/$$x SRC; \
- cp SRC/Makefile Makefile; chmod +w Makefile; \
- ${MAKE} ${MARGS} links; \
- ) || exit 1; \
- done
-
-FRC:
diff --git a/contrib/bind/lib/dst/Makefile b/contrib/bind/lib/dst/Makefile
deleted file mode 100644
index 5503afa..0000000
--- a/contrib/bind/lib/dst/Makefile
+++ /dev/null
@@ -1,98 +0,0 @@
-# Copyright (c) 1996,1999 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.
-
-# $Id: Makefile,v 1.19 2001/08/14 05:58:03 marka Exp $
-
-# these are only appropriate for BSD 4.4 or derivatives, and are used in
-# development. normal builds will be done in the top level directory and
-# this Makefile will be invoked with a lot of overrides for the following:
-SYSTYPE= freebsd
-DESTDIR =
-DESTLIB = /usr/local/lib
-O=o
-A=a
-CC= cc
-LD= ld
-SHELL= /bin/sh
-CDEBUG= -g -Wall
-TOP= ../..
-INCL = ${TOP}/include
-PORTINCL = ${TOP}/port/${SYSTYPE}/include
-LIBBIND = ${TOP}/lib/libbind.${A}
-LIBBINDR = ../${TOP}/lib/libbind_r.${A}
-CFLAGS= ${CDEBUG}
-CPPFLAGS= -I${PORTINCL} -I${INCL}
-LD_LIBFLAGS= -x -r
-AR= ar cru
-RANLIB= ranlib
-INSTALL= install
-INSTALL_EXEC=
-INSTALL_LIB=-o bin -g bin
-THREADED= threaded
-
-HDRS= md5.h md5_locl.h
-
-SRCS= dst_api.c prandom.c rsaref_link.c support.c bsafe_link.c \
- cylink_link.c hmac_link.c md5_dgst.c eay_dss_link.c
-
-OBJS= dst_api.${O} prandom.${O} rsaref_link.${O} support.${O} \
- bsafe_link.${O} cylink_link.${O} hmac_link.${O} md5_dgst.${O} \
- eay_dss_link.${O}
-
-CRYPTINCL= -I../cylink -I../dnssafe
-CRYPTFLAGS= -DCYLINK_DSS -DHMAC_MD5 -DUSE_MD5 -DDNSSAFE
-
-all: ${LIBBIND}
-
-${LIBBIND}: ${OBJS}
- ( cd ${THREADED} ; \
- ${AR} ${LIBBINDR} ${ARPREF} ${OBJS} ${ARSUFF} ; \
- ${RANLIB} ${LIBBINDR} )
- ${AR} ${LIBBIND} ${ARPREF} ${OBJS} ${ARSUFF}
- ${RANLIB} ${LIBBIND}
-
-.c.${O}:
- mkdir ${THREADED} 2> /dev/null || test -d ${THREADED} -a -w ${THREADED}
- ${CC} ${CPPFLAGS} ${CFLAGS} ${BOUNDS} ${REENTRANT} ${CRYPTINCL} ${CRYPTFLAGS} -c $*.c -o ${THREADED}/$*.${O}
- -${LDS} ${LD} ${LD_LIBFLAGS} ${THREADED}/$*.${O} \
- -o ${THREADED}/$*.out && \
- ${LDS} mv ${THREADED}/$*.out ${THREADED}/$*.${O}
- ${CC} ${CPPFLAGS} ${CFLAGS} ${CRYPTINCL} ${CRYPTFLAGS} -c $*.c
- -${LDS} ${LD} ${LD_LIBFLAGS} $*.${O} -o $*.out && \
- ${LDS} mv $*.out $*.${O}
-
-$(SRCS):: $(HDRS)
-
-distclean: clean
-
-clean: FRC
- rm -f .depend a.out core ${LIB} tags
- rm -f *.${O} *.BAK *.CKP *~
- rm -f prand_conf.h
- rm -f ${THREADED}/*.${O}
- -if test -d ${THREADED} ; then rmdir ${THREADED}; else true; fi
-
-depend: FRC
- mkdep -I${INCL} -I${PORTINCL} ${CPPFLAGS} ${SRCS}
-
-links: FRC
- @set -e; ln -s SRC/*.[ch] SRC/*.pl .
-
-install:
-
-FRC:
-
-# DO NOT DELETE THIS LINE -- mkdep uses it.
-# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
diff --git a/contrib/bind/lib/dst/README b/contrib/bind/lib/dst/README
deleted file mode 100644
index 6283e58..0000000
--- a/contrib/bind/lib/dst/README
+++ /dev/null
@@ -1,27 +0,0 @@
-This directory in BIND contains the Domain Signature Tools (dst)
-library. It was written by Trusted Information Systems, Inc. and
-integrated into BIND by John Gilmore. It is used as a generic
-crypto library interface by the DNS Security code in BIND.
-
- Installing Domain Signature Tools Library - dst
-
-1. Assess available crypto libraries:
-
- if you have DNSSAFE (the default)
- CRYPTFLAGS must include -DDNSSAFE
- CRYPTINCL must include -I../dnssafe
-
- if you have RSAREF
- CRYPTFLAGS must include -DRSAREF
- CRYPTINCL must include -I<path to rsa include files>
-
- if you have BSAFE
- CRYPTFLAGS must include -DBSAFE
- CRYPTINCL must include -I<path to bsafe include files>
-
- if you want HMAC-MD5 support
- CRYPTFLAGs must include -DHMAC
-
-2. Building BIND as usual will include the dst library routines into
- libbind.a, and link them into the BIND programs that use crypto
- support.
diff --git a/contrib/bind/lib/dst/bsafe_link.c b/contrib/bind/lib/dst/bsafe_link.c
deleted file mode 100644
index e1173c6..0000000
--- a/contrib/bind/lib/dst/bsafe_link.c
+++ /dev/null
@@ -1,1123 +0,0 @@
-#if defined(BSAFE) || defined(DNSSAFE)
-static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/bsafe_link.c,v 1.16 2002/12/03 05:26:49 marka Exp $";
-
-/*
- * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc.
- *
- * 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 TRUSTED INFORMATION SYSTEMS
- * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
- * TRUSTED INFORMATION SYSTEMS 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 THE SOFTWARE.
- */
-/*
- * This file contains two components
- * 1. Interface to the BSAFE library to allow compilation of Bind
- * with TIS/DNSSEC when BSAFE is not available
- * all calls to BSAFE are contained inside this file.
- * 2. The glue to connvert RSA KEYS to and from external formats
- */
-#include "port_before.h"
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <memory.h>
-#include <sys/param.h>
-#include <sys/time.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include "dst_internal.h"
-
-# ifdef __STDC__
-# define PROTOTYPES 1
-# else
-# define PROTOTYPES 0
-# endif
-
-# ifdef BSAFE
-# include <aglobal.h>
-# include <bsafe.h>
-# else
-# include <global.h>
-# include <bsafe2.h>
-# include <bigmaxes.h>
-# endif
-
-#include "port_after.h"
-
-typedef struct bsafekey {
- char *rk_signer;
- B_KEY_OBJ rk_Private_Key;
- B_KEY_OBJ rk_Public_Key;
-} RSA_Key;
-
-#ifndef MAX_RSA_MODULUS_BITS
-#define MAX_RSA_MODULUS_BITS 4096
-#define MAX_RSA_MODULUS_LEN (MAX_RSA_MODULUS_BITS/8)
-#define MAX_RSA_PRIME_LEN (MAX_RSA_MODULUS_LEN/2)
-#endif
-
-#define NULL_SURRENDER (A_SURRENDER_CTX *)NULL_PTR
-#define NULL_RANDOM (B_ALGORITHM_OBJ)NULL_PTR
-
-B_ALGORITHM_METHOD *CHOOSER[] =
-{
- &AM_MD5,
- &AM_MD5_RANDOM,
- &AM_RSA_KEY_GEN,
- &AM_RSA_ENCRYPT,
- &AM_RSA_DECRYPT,
- &AM_RSA_CRT_ENCRYPT,
- &AM_RSA_CRT_DECRYPT,
- (B_ALGORITHM_METHOD *) NULL_PTR
-};
-
-static u_char pkcs1[] =
-{
- 0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86,
- 0x48, 0x86, 0xf7, 0x0d, 0x02, 0x05, 0x05, 0x00,
- 0x04, 0x10
-};
-
-static int dst_bsafe_md5digest(const int mode, B_ALGORITHM_OBJ *digest_obj,
- const u_char *data, const int len,
- u_char *digest, const int digest_len);
-
-static int dst_bsafe_key_size(RSA_Key *r_key);
-
-static int dst_bsafe_sign(const int mode, DST_KEY *dkey, void **context,
- const u_char *data, const int len,
- u_char *signature, const int sig_len);
-static int dst_bsafe_verify(const int mode, DST_KEY *dkey, void **context,
- const u_char *data, const int len,
- const u_char *signature, const int sig_len);
-static int dst_bsafe_to_dns_key(const DST_KEY *in_key, u_char *out_str,
- const int out_len);
-static int dst_bsafe_from_dns_key(DST_KEY *s_key, const u_char *key,
- const int len);
-static int dst_bsafe_key_to_file_format(const DST_KEY *key, char *buff,
- const int buff_len);
-static int dst_bsafe_key_from_file_format(DST_KEY *d_key,
- const char *buff,
- const int buff_len);
-static int dst_bsafe_generate_keypair(DST_KEY *key, int exp);
-static int dst_bsafe_compare_keys(const DST_KEY *key1, const DST_KEY *key2);
-static void *dst_bsafe_free_key_structure(void *key);
-
-/*
- * dst_bsafe_init() Function to answer set up function pointers for
- * BSAFE/DNSSAFE related functions
- */
-int
-dst_bsafe_init(void)
-{
- if (dst_t_func[KEY_RSA] != NULL)
- return (1);
- dst_t_func[KEY_RSA] = malloc(sizeof(struct dst_func));
- if (dst_t_func[KEY_RSA] == NULL)
- return (0);
- memset(dst_t_func[KEY_RSA], 0, sizeof(struct dst_func));
- dst_t_func[KEY_RSA]->sign = dst_bsafe_sign;
- dst_t_func[KEY_RSA]->verify = dst_bsafe_verify;
- dst_t_func[KEY_RSA]->compare = dst_bsafe_compare_keys;
- dst_t_func[KEY_RSA]->generate = dst_bsafe_generate_keypair;
- dst_t_func[KEY_RSA]->destroy = dst_bsafe_free_key_structure;
- dst_t_func[KEY_RSA]->from_dns_key = dst_bsafe_from_dns_key;
- dst_t_func[KEY_RSA]->to_dns_key = dst_bsafe_to_dns_key;
- dst_t_func[KEY_RSA]->from_file_fmt = dst_bsafe_key_from_file_format;
- dst_t_func[KEY_RSA]->to_file_fmt = dst_bsafe_key_to_file_format;
- return (1);
-}
-
-/*
- * dst_bsafe_sign
- * Call BSAFE signing functions to sign a block of data.
- * There are three steps to signing, INIT (initialize structures),
- * UPDATE (hash (more) data), FINAL (generate a signature). This
- * routine performs one or more of these steps.
- * Parameters
- * mode SIG_MODE_INIT, SIG_MODE_UPDATE and/or SIG_MODE_FINAL.
- * dkey structure holds context for a sign done in multiple calls.
- * context the context to use for this computation
- * data data to be signed.
- * len length in bytes of data.
- * priv_key key to use for signing.
- * signature location to store signature.
- * sig_len size in bytes of signature field.
- * returns
- * N Success on SIG_MODE_FINAL = returns signature length in bytes
- * 0 Success on SIG_MODE_INIT and UPDATE
- * <0 Failure
- */
-
-static int
-dst_bsafe_sign(const int mode, DST_KEY *dkey, void **context,
- const u_char *data, const int len,
- u_char *signature, const int sig_len)
-{
- u_int sign_len = 0;
- int status = 0;
- B_ALGORITHM_OBJ *md5_ctx = NULL;
- int w_bytes = 0;
- u_int u_bytes = 0;
- u_char work_area[NS_MD5RSA_MAX_SIZE];
-
- if (mode & SIG_MODE_INIT) {
- md5_ctx = (B_ALGORITHM_OBJ *) malloc(sizeof(B_ALGORITHM_OBJ));
- if ((status = B_CreateAlgorithmObject(md5_ctx)))
- return (-1);
- if ((status = B_SetAlgorithmInfo(*md5_ctx, AI_MD5, NULL)))
- return (-1);
- }
- else if (context)
- md5_ctx = (B_ALGORITHM_OBJ *) *context;
- if (md5_ctx == NULL)
- return (-1);
-
- w_bytes = dst_bsafe_md5digest(mode, md5_ctx,
- data, len,work_area, sizeof(work_area));
- if (w_bytes < 0 || (mode & SIG_MODE_FINAL)) {
- B_DestroyAlgorithmObject(md5_ctx);
- SAFE_FREE(md5_ctx);
- if (w_bytes < 0)
- return (w_bytes);
- }
-
- if (mode & SIG_MODE_FINAL) {
- RSA_Key *key;
- int ret = 0;
- B_ALGORITHM_OBJ rsaEncryptor = (B_ALGORITHM_OBJ) NULL_PTR;
-
- if (dkey == NULL || dkey->dk_KEY_struct == NULL)
- return (-1);
- key = (RSA_Key *) dkey->dk_KEY_struct;
- if (key == NULL || key->rk_Private_Key == NULL)
- return (-1);
-
- if ((status = B_CreateAlgorithmObject(&rsaEncryptor)))
- return (SIGN_FINAL_FAILURE);
- if ((status = B_SetAlgorithmInfo(rsaEncryptor,
- AI_PKCS_RSAPrivate,
- NULL_PTR)))
-
- ret = SIGN_FINAL_FAILURE;
- if (ret == 0 &&
- (status = B_EncryptInit(rsaEncryptor,
- key->rk_Private_Key,
- CHOOSER, NULL_SURRENDER)))
- ret = SIGN_FINAL_FAILURE;
- if (ret == 0 &&
- (status = B_EncryptUpdate(rsaEncryptor, signature,
- &u_bytes, sig_len, pkcs1,
- sizeof(pkcs1), NULL_PTR,
- NULL_SURRENDER)))
- ret = SIGN_FINAL_FAILURE;
- if (ret == 0 &&
- (status = B_EncryptUpdate(rsaEncryptor, signature,
- &u_bytes, sig_len, work_area,
- w_bytes, NULL_PTR,
- NULL_SURRENDER)))
- ret = SIGN_FINAL_FAILURE;
-
- if (ret == 0 &&
- (status = B_EncryptFinal(rsaEncryptor, signature + u_bytes,
- &sign_len, sig_len - u_bytes,
- NULL_PTR, NULL_SURRENDER)))
- ret = SIGN_FINAL_FAILURE;
- B_DestroyAlgorithmObject(&rsaEncryptor);
- if (ret != 0)
- return (ret);
-
- }
- else {
- if (context == NULL)
- return (-1);
- *context = (void *) md5_ctx;
- }
- return (sign_len);
-}
-
-
-/*
- * Dst_bsafe_verify
- * Calls BSAFE verification routines. There are three steps to
- * verification, INIT (initialize structures), UPDATE (hash (more) data),
- * FINAL (generate a signature). This routine performs one or more of
- * these steps.
- * Parameters
- * mode SIG_MODE_INIT, SIG_MODE_UPDATE and/or SIG_MODE_FINAL.
- * dkey structure holds context for a verify done in multiple calls.
- * context the context to use for this computation
- * data data signed.
- * len length in bytes of data.
- * pub_key key to use for verify.
- * signature signature.
- * sig_len length in bytes of signature.
- * returns
- * 0 Success
- * <0 Failure
- */
-
-static int
-dst_bsafe_verify(const int mode, DST_KEY *dkey, void **context,
- const u_char *data, const int len,
- const u_char *signature, const int sig_len)
-{
- B_ALGORITHM_OBJ *md5_ctx = NULL;
- u_char digest[DST_HASH_SIZE];
- u_char work_area[DST_HASH_SIZE + sizeof(pkcs1)];
- int status = 0, w_bytes = 0;
- u_int u_bytes = 0;
-
- if (mode & SIG_MODE_INIT) {
- md5_ctx = (B_ALGORITHM_OBJ *) malloc(sizeof(B_ALGORITHM_OBJ));
- if ((status = B_CreateAlgorithmObject(md5_ctx)))
- return (-1);
- if ((status = B_SetAlgorithmInfo(*md5_ctx, AI_MD5, NULL)))
- return (-1);
- }
- else if (context)
- md5_ctx = (B_ALGORITHM_OBJ *) *context;
- if (md5_ctx == NULL)
- return (-1);
-
- w_bytes = dst_bsafe_md5digest(mode, md5_ctx, data, len,
- digest, sizeof(digest));
-
- if (w_bytes < 0 || (mode & SIG_MODE_FINAL)) {
- B_DestroyAlgorithmObject(md5_ctx);
- SAFE_FREE(md5_ctx);
- if (w_bytes < 0)
- return (-1);
- }
-
- if (mode & SIG_MODE_FINAL) {
- RSA_Key *key;
- int ret = 0;
- B_ALGORITHM_OBJ rsaEncryptor = (B_ALGORITHM_OBJ) NULL_PTR;
-
- if (dkey == NULL || dkey->dk_KEY_struct == NULL)
- return (-1);
- key = (RSA_Key *) dkey->dk_KEY_struct;
- if (key->rk_Public_Key == NULL)
- return (-2);
- if (rsaEncryptor == NULL_PTR) {
- if ((status = B_CreateAlgorithmObject(&rsaEncryptor)))
- ret = SIGN_FINAL_FAILURE;
- if (ret == 0 &&
- (status = B_SetAlgorithmInfo(rsaEncryptor,
- AI_PKCS_RSAPublic,
- NULL_PTR)))
- ret = VERIFY_FINAL_FAILURE;
- }
- if (ret == 0 &&
- (status = B_DecryptInit(rsaEncryptor, key->rk_Public_Key,
- CHOOSER, NULL_SURRENDER)))
- ret = VERIFY_FINAL_FAILURE;
-
- if (ret == 0 &&
- (status = B_DecryptUpdate(rsaEncryptor, work_area,
- &u_bytes, 0,
- (const u_char *) signature,
- sig_len,
- NULL_PTR, NULL_SURRENDER)))
- ret = VERIFY_FINAL_FAILURE;
-
- if (ret == 0 &&
- (status = B_DecryptFinal(rsaEncryptor, work_area + u_bytes,
- &u_bytes,
- sizeof(work_area) - u_bytes,
- NULL_PTR, NULL_SURRENDER)))
- ret = VERIFY_FINAL_FAILURE;
- B_DestroyAlgorithmObject(&rsaEncryptor);
- /* skip PKCS#1 header in output from Decrypt function */
- if (ret)
- return (ret);
- ret = memcmp(digest, &work_area[sizeof(pkcs1)], w_bytes);
- if (ret == 0)
- return(0);
- else
- return(VERIFY_FINAL_FAILURE);
- }
- else {
- if (context == NULL)
- return (-1);
- *context = (void *) md5_ctx;
- }
- return (0);
-}
-
-
-/*
- * dst_bsafe_to_dns_key
- * Converts key from RSA to DNS distribution format
- * This function gets in a pointer to the public key and a work area
- * to write the key into.
- * Parameters
- * public KEY structure
- * out_str buffer to write encoded key into
- * out_len size of out_str
- * Return
- * N >= 0 length of encoded key
- * n < 0 error
- */
-
-static int
-dst_bsafe_to_dns_key(const DST_KEY *in_key, u_char *out_str,
- const int out_len)
-{
- B_KEY_OBJ public;
- A_RSA_KEY *pub = NULL;
- u_char *op = out_str;
- int n = 0;
-
- if (in_key == NULL || in_key->dk_KEY_struct == NULL ||
- out_len <= 0 || out_str == NULL)
- return (-1);
- public = (B_KEY_OBJ)((RSA_Key *) in_key->dk_KEY_struct)->rk_Public_Key;
-
- n = B_GetKeyInfo((POINTER *) &pub, public, KI_RSAPublic);
- if (n != 0)
- return (-1);
-
- if (pub->exponent.len < 256) { /* key exponent is <= 2040 bits */
- if ((unsigned int)out_len < pub->exponent.len + 1)
- return (-1);
- *op++ = (u_int8_t) pub->exponent.len;
- } else { /* key exponent is > 2040 bits */
- u_int16_t e = (u_int16_t) pub->exponent.len;
- if ((unsigned int)out_len < pub->exponent.len + 3)
- return (-1);
- *op++ = 0; /* 3 byte length field */
- dst_s_put_int16(op, e);
- op += sizeof(e);
- n = 2;
- }
- n++;
- memcpy(op, pub->exponent.data, pub->exponent.len);
- op += pub->exponent.len;
- n += pub->exponent.len;
-
- if ((unsigned int)(out_len - n) >= pub->modulus.len) {
- /*copy exponent */
- memcpy(op, pub->modulus.data, pub->modulus.len);
- n += pub->modulus.len;
- }
- else
- n = -1;
- return (n);
-}
-
-
-/*
- * dst_bsafe_from_dns_key
- * Converts from a DNS KEY RR format to an RSA KEY.
- * Parameters
- * len Length in bytes of DNS key
- * key DNS key
- * name Key name
- * s_key DST structure that will point to the RSA key this routine
- * will build.
- * Return
- * 0 The input key, s_key or name was null.
- * 1 Success
- */
-static int
-dst_bsafe_from_dns_key(DST_KEY *s_key, const u_char *key, const int len)
-{
- int bytes;
- const u_char *key_ptr;
- RSA_Key *r_key;
- A_RSA_KEY *public;
-
- if (s_key == NULL || len < 0 || key == NULL)
- return (0);
-
- r_key = (RSA_Key *) s_key->dk_KEY_struct;
- if (r_key != NULL) /* do not reuse */
- s_key->dk_func->destroy(r_key);
-
- if (len == 0)
- return (1);
-
- if ((r_key = (RSA_Key *) malloc(sizeof(RSA_Key))) == NULL) {
- EREPORT(("dst_bsafe_from_dns_key(): Memory allocation error 1"));
- return (0);
- }
- memset(r_key, 0, sizeof(RSA_Key));
- s_key->dk_KEY_struct = (void *) r_key;
- r_key->rk_signer = strdup(s_key->dk_key_name);
-
- if (B_CreateKeyObject(&r_key->rk_Public_Key) != 0) {
- EREPORT(("dst_bsafe_from_dns_key(): Memory allocation error 3"));
- s_key->dk_func->destroy(r_key);
- return (0);
- }
- key_ptr = key;
- bytes = (int) *key_ptr++; /* length of exponent in bytes */
- if (bytes == 0) { /* special case for long exponents */
- bytes = (int) dst_s_get_int16(key_ptr);
- key_ptr += sizeof(u_int16_t);
- }
- if (bytes > MAX_RSA_MODULUS_LEN) {
- dst_bsafe_free_key_structure(r_key);
- return (-1);
- }
- if ((public = (A_RSA_KEY *) malloc(sizeof(A_RSA_KEY))) == NULL)
- return (0);
- memset(public, 0, sizeof(*public));
- public->exponent.len = bytes;
- if ((public->exponent.data = (u_char *) malloc(bytes)) == NULL)
- return (0);
- memcpy(public->exponent.data, key_ptr, bytes);
-
- key_ptr += bytes; /* beginning of modulus */
- bytes = len - bytes - 1; /* length of modulus */
-
- if (bytes > MAX_RSA_MODULUS_LEN) {
- dst_bsafe_free_key_structure(r_key);
- return (-1);
- }
- public->modulus.len = bytes;
- if ((public->modulus.data = (u_char *) malloc(bytes)) == NULL)
- return (0);
- memcpy(public->modulus.data, key_ptr, bytes);
-
- B_SetKeyInfo(r_key->rk_Public_Key, KI_RSAPublic, (POINTER) public);
-
- s_key->dk_key_size = dst_bsafe_key_size(r_key);
- SAFE_FREE(public->modulus.data);
- SAFE_FREE(public->exponent.data);
- SAFE_FREE(public);
- return (1);
-}
-
-
-/*
- * dst_bsafe_key_to_file_format
- * Encodes an RSA Key into the portable file format.
- * Parameters
- * rkey RSA KEY structure
- * buff output buffer
- * buff_len size of output buffer
- * Return
- * 0 Failure - null input rkey
- * -1 Failure - not enough space in output area
- * N Success - Length of data returned in buff
- */
-
-static int
-dst_bsafe_key_to_file_format(const DST_KEY *key, char *buff,
- const int buff_len)
-{
- char *bp;
- int len, b_len;
- B_KEY_OBJ rkey;
- A_PKCS_RSA_PRIVATE_KEY *private = NULL;
-
- if (key == NULL || key->dk_KEY_struct == NULL) /* no output */
- return (0);
- if (buff == NULL || buff_len <= (int) strlen(key_file_fmt_str))
- return (-1); /* no OR not enough space in output area */
-
- rkey = (B_KEY_OBJ)((RSA_Key *) key->dk_KEY_struct)->rk_Private_Key;
-
- B_GetKeyInfo((POINTER *) &private, rkey, KI_PKCS_RSAPrivate);
-
- memset(buff, 0, buff_len); /* just in case */
- /* write file header */
- sprintf(buff, key_file_fmt_str, KEY_FILE_FORMAT, KEY_RSA, "RSA");
-
- bp = strchr(buff, '\0');
- b_len = buff_len - (bp - buff);
- if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Modulus: ",
- private->modulus.data,
- private->modulus.len)) <= 0)
- return (-1);
-
- bp += len;
- b_len -= len;
- if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "PublicExponent: ",
- private->publicExponent.data,
- private->publicExponent.len)) <= 0)
- return (-2);
-
- bp += len;
- b_len -= len;
- if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "PrivateExponent: ",
- private->privateExponent.data,
- private->privateExponent.len)) <= 0)
- return (-3);
- bp += len;
- b_len -= len;
-
- if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Prime1: ",
- private->prime[0].data,
- private->prime[0].len)) < 0)
- return (-4);
- bp += len;
- b_len -= len;
-
- if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Prime2: ",
- private->prime[1].data,
- private->prime[1].len)) < 0)
- return (-5);
- bp += len;
- b_len -= len;
-
- if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Exponent1: ",
- private->primeExponent[0].data,
- private->primeExponent[0].len)) < 0)
- return (-6);
- bp += len;
- b_len -= len;
-
- if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Exponent2: ",
- private->primeExponent[1].data,
- private->primeExponent[1].len)) < 0)
- return (-7);
- bp += len;
- b_len -= len;
-
- if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Coefficient: ",
- private->coefficient.data,
- private->coefficient.len)) < 0)
- return (-8);
- bp += len;
- b_len -= len;
- return (buff_len - b_len);
-}
-
-
-/*
- * dst_bsafe_key_from_file_format
- * Converts contents of a private key file into a private RSA key.
- * Parameters
- * RSA_Key structure to put key into
- * buff buffer containing the encoded key
- * buff_len the length of the buffer
- * Return
- * n >= 0 Foot print of the key converted
- * n < 0 Error in conversion
- */
-
-static int
-dst_bsafe_key_from_file_format(DST_KEY *d_key, const char *buff,
- const int buff_len)
-{
- int status;
- char s[RAW_KEY_SIZE];
- int len, s_len = sizeof(s);
- const char *p = buff;
- RSA_Key *b_key;
- A_RSA_KEY *public;
- A_PKCS_RSA_PRIVATE_KEY *private;
-
- if (d_key == NULL || buff == NULL || buff_len <= 0)
- return (-1);
-
- b_key = (RSA_Key *) malloc(sizeof(RSA_Key));
- public = (A_RSA_KEY *) malloc(sizeof(A_RSA_KEY));
- private = (A_PKCS_RSA_PRIVATE_KEY *)
- malloc(sizeof(A_PKCS_RSA_PRIVATE_KEY));
- if (b_key == NULL || private == NULL || public == NULL) {
- SAFE_FREE(b_key);
- SAFE_FREE(public);
- SAFE_FREE(private);
- return (-2);
- }
- memset(b_key, 0, sizeof(*b_key));
- memset(public, 0, sizeof(A_RSA_KEY));
- memset(private, 0, sizeof(A_PKCS_RSA_PRIVATE_KEY));
- d_key->dk_KEY_struct = (void *) b_key;
- if (!dst_s_verify_str(&p, "Modulus: "))
- return (-3);
- memset(s, 0, s_len);
- if ((len = dst_s_conv_bignum_b64_to_u8(&p, (u_char *)s, s_len)) == 0)
- return (-4);
-
- private->modulus.len = len;
- if ((private->modulus.data = malloc(len)) == NULL)
- return (-5);
- memcpy(private->modulus.data, s + s_len - len, len);
-
- while (*(++p) && p < (const char *) &buff[buff_len]) {
- if (dst_s_verify_str(&p, "PublicExponent: ")) {
- if (!(len = dst_s_conv_bignum_b64_to_u8(&p, (u_char *)s, s_len)))
- return (-5);
- private->publicExponent.len = len;
- if ((private->publicExponent.data = malloc(len))
- == NULL)
- return (-6);
- memcpy(private->publicExponent.data,
- s + s_len - len, len);
- } else if (dst_s_verify_str(&p, "PrivateExponent: ")) {
- if (!(len = dst_s_conv_bignum_b64_to_u8(&p, (u_char *)s, s_len)))
- return (-6);
- private->privateExponent.len = len;
- if ((private->privateExponent.data = malloc(len))
- == NULL)
- return (-7);
- memcpy(private->privateExponent.data, s + s_len - len,
- len);
- } else if (dst_s_verify_str(&p, "Prime1: ")) {
- if (!(len = dst_s_conv_bignum_b64_to_u8(&p, (u_char *)s,
- MAX_RSA_PRIME_LEN)))
- return (-7);
- private->prime[0].len = len;
- if ((private->prime[0].data = malloc(len)) == NULL)
- return (-8);
- memcpy(private->prime[0].data,
- s + MAX_RSA_PRIME_LEN - len, len);
- } else if (dst_s_verify_str(&p, "Prime2: ")) {
- if (!(len = dst_s_conv_bignum_b64_to_u8(&p, (u_char *)s,
- MAX_RSA_PRIME_LEN)))
- return (-8);
- private->prime[1].len = len;
- if ((private->prime[1].data = malloc(len)) == NULL)
- return (-9);
- memcpy(private->prime[1].data,
- s + MAX_RSA_PRIME_LEN - len, len);
- } else if (dst_s_verify_str(&p, "Exponent1: ")) {
- if (!(len = dst_s_conv_bignum_b64_to_u8(&p, (u_char *)s,
- MAX_RSA_PRIME_LEN)))
- return (-9);
- private->primeExponent[0].len = len;
- if ((private->primeExponent[0].data = malloc(len))
- == NULL)
- return (-10);
- memcpy(private->primeExponent[0].data,
- s + MAX_RSA_PRIME_LEN - len, len);
- } else if (dst_s_verify_str(&p, "Exponent2: ")) {
- if (!(len = dst_s_conv_bignum_b64_to_u8(&p, (u_char *)s,
- MAX_RSA_PRIME_LEN)))
- return (-10);
- private->primeExponent[1].len = len;
- if ((private->primeExponent[1].data = malloc(len))
- == NULL)
- return (-11);
- memcpy(private->primeExponent[1].data,
- s + MAX_RSA_PRIME_LEN - len, len);
- } else if (dst_s_verify_str(&p, "Coefficient: ")) {
- if (!(len = dst_s_conv_bignum_b64_to_u8(&p, (u_char *)s,
- MAX_RSA_PRIME_LEN)))
- return (-11);
- private->coefficient.len = len;
- if ((private->coefficient.data = malloc(len)) == NULL)
- return (-12);
- memcpy(private->coefficient.data,
- s + MAX_RSA_PRIME_LEN - len, len);
- } else {
- EREPORT(("Decode_RSAKey(): Bad keyword %s\n", p));
- return (-12);
- }
- } /* while p */
-
- public->modulus.len = private->modulus.len;
- if ((public->modulus.data = (u_char *) malloc(public->modulus.len)) ==
- NULL)
- return (-13);
- memcpy(public->modulus.data, private->modulus.data,
- private->modulus.len);
-
- public->exponent.len = private->publicExponent.len;
- if ((public->exponent.data = (u_char *) malloc(public->exponent.len))
- == NULL)
- return (-14);
- memcpy(public->exponent.data, private->publicExponent.data,
- private->publicExponent.len);
-
- status = B_CreateKeyObject(&(b_key->rk_Public_Key));
- if (status)
- return (-1);
- status = B_SetKeyInfo(b_key->rk_Public_Key, KI_RSAPublic,
- (POINTER) public);
- if (status)
- return (-1);
-
- status = B_CreateKeyObject(&b_key->rk_Private_Key);
- if (status)
- return (-1);
- status = B_SetKeyInfo(b_key->rk_Private_Key, KI_PKCS_RSAPrivate,
- (POINTER) private);
- if (status)
- return (-1);
-
- d_key->dk_key_size = dst_bsafe_key_size(b_key);
-
- SAFE_FREE(private->modulus.data);
- SAFE_FREE(private->publicExponent.data);
- SAFE_FREE(private->privateExponent.data);
- SAFE_FREE(private->prime[0].data);
- SAFE_FREE(private->prime[1].data);
- SAFE_FREE(private->primeExponent[0].data);
- SAFE_FREE(private->primeExponent[1].data);
- SAFE_FREE(private->coefficient.data);
- SAFE_FREE(private); /* is this the right thing to do ??? XXXX */
- SAFE_FREE(public->modulus.data);
- SAFE_FREE(public->exponent.data);
- SAFE_FREE(public);
- return (0);
-}
-
-
-/*
- * dst_bsafe_free_key_structure
- * Frees all dynamicly allocated structures in RSA_Key.
- */
-
-static void *
-dst_bsafe_free_key_structure(void *key)
-{
- RSA_Key *r_key = (RSA_Key *) key;
- if (r_key != NULL) {
- if (r_key->rk_Private_Key)
- B_DestroyKeyObject(&r_key->rk_Private_Key);
- if (r_key->rk_Public_Key)
- B_DestroyKeyObject(&r_key->rk_Public_Key);
- SAFE_FREE2(r_key->rk_signer, strlen(r_key->rk_signer));
- SAFE_FREE(r_key);
- }
- return (NULL);
-}
-
-
-/*
- * dst_bsafe_generate_keypair
- * Generates unique keys that are hard to predict.
- * Parameters
- * key generic Key structure
- * exp the public exponent
- * Return
- * 0 Failure
- * 1 Success
- */
-
-static int
-dst_bsafe_generate_keypair(DST_KEY *key, int exp)
-{
- int i, status;
- B_KEY_OBJ private;
- B_KEY_OBJ public;
- B_ALGORITHM_OBJ keypairGenerator;
- B_ALGORITHM_OBJ randomAlgorithm;
- A_RSA_KEY_GEN_PARAMS keygenParams;
- char exponent[4];
- int exponent_len;
- RSA_Key *rsa;
- POINTER randomSeed = NULL_PTR;
- int randomSeedLen;
- A_RSA_KEY *pk_access = NULL;
-
- if (key == NULL || key->dk_alg != KEY_RSA)
- return (0);
-
- if ((rsa = (RSA_Key *) malloc(sizeof(RSA_Key))) == NULL) {
- EREPORT(("dst_bsafe_generate_keypair: Memory allocation error 3"));
- return (0);
- }
- memset(rsa, 0, sizeof(*rsa));
-
- if ((status = B_CreateAlgorithmObject(&keypairGenerator)) != 0)
- return (0);
-
- keygenParams.modulusBits = key->dk_key_size;
-
- /* exp = 0 or 1 are special (mean 3 or F4) */
- if (exp == 0)
- exp = 3;
- else if (exp == 1)
- exp = 65537;
-
- /* Now encode the exponent and its length */
- if (exp < 256) {
- exponent_len = 1;
- exponent[0] = exp;
- } else if (exp < (1 << 16)) {
- exponent_len = 2;
- exponent[0] = exp >> 8;
- exponent[1] = exp;
- } else if (exp < (1 << 24)) {
- exponent_len = 3;
- exponent[0] = exp >> 16;
- exponent[1] = exp >> 8;
- exponent[2] = exp;
- } else {
- exponent_len = 4;
- exponent[0] = exp >> 24;
- exponent[1] = exp >> 16;
- exponent[2] = exp >> 8;
- exponent[3] = exp;
- }
-
- if ((keygenParams.publicExponent.data = (u_char *) malloc(exponent_len))
- == NULL)
- return (0);
- memcpy(keygenParams.publicExponent.data, exponent, exponent_len);
- keygenParams.publicExponent.len = exponent_len;
- if ((status = B_SetAlgorithmInfo
- (keypairGenerator, AI_RSAKeyGen, (POINTER) &keygenParams)) != 0)
- return (0);
-
- if ((status = B_GenerateInit(keypairGenerator, CHOOSER,
- NULL_SURRENDER)) != 0)
- return (0);
-
- if ((status = B_CreateKeyObject(&public)) != 0)
- return (0);
-
- if ((status = B_CreateKeyObject(&private)) != 0)
- return (0);
-
- if ((status = B_CreateAlgorithmObject(&randomAlgorithm)) != 0)
- return (0);
-
- if ((status = B_SetAlgorithmInfo(randomAlgorithm, AI_MD5Random,
- NULL_PTR))
- != 0)
- return (0);
-
- if ((status = B_RandomInit(randomAlgorithm, CHOOSER,
- NULL_SURRENDER)) != 0)
- return (0);
-
- randomSeedLen = 256;
- if ((randomSeed = malloc(randomSeedLen)) == NULL)
- return (0);
- if ((status = (randomSeed == NULL_PTR)) != 0)
- return (0);
-
- /* gets random seed from /dev/random if present, generates random
- * values if it is not present.
- * first fill the buffer with semi random data
- * then fill as much as possible with good random data
- */
- i = dst_random(DST_RAND_SEMI, randomSeedLen, randomSeed);
- i += dst_random(DST_RAND_KEY, randomSeedLen, randomSeed);
-
- if (i <= randomSeedLen) {
- SAFE_FREE(rsa);
- return(0);
- }
- if ((status = B_RandomUpdate(randomAlgorithm, randomSeed,
- randomSeedLen, NULL_SURRENDER)) != 0) {
- SAFE_FREE(rsa);
- return (0);
- }
- SAFE_FREE2(randomSeed, randomSeedLen);
- if ((status = B_GenerateKeypair(keypairGenerator, public, private,
- randomAlgorithm, NULL_SURRENDER))
- != 0) {
- SAFE_FREE(rsa);
- return (0);
- }
- rsa->rk_signer = strdup(key->dk_key_name);
- rsa->rk_Private_Key = private;
- rsa->rk_Public_Key = public;
- key->dk_KEY_struct = (void *) rsa;
-
- B_GetKeyInfo((POINTER *) &pk_access, public, KI_RSAPublic);
- return (1);
-}
-
-
-/**************************************************************************
- * dst_bsafe_compare_keys
- * Compare two keys for equality.
- * Return
- * 0 The keys are equal
- * NON-ZERO The keys are not equal
- */
-
-static int
-dst_s_bsafe_itemcmp(ITEM i1, ITEM i2)
-{
- if (i1.len != i2.len || memcmp (i1.data, i2.data, i1.len))
- return (1);
- else
- return (0);
-}
-
-static int
-dst_bsafe_compare_keys(const DST_KEY *key1, const DST_KEY *key2)
-{
- int status, s1 = 0, s2 = 0;
- RSA_Key *rkey1 = (RSA_Key *) key1->dk_KEY_struct;
- RSA_Key *rkey2 = (RSA_Key *) key2->dk_KEY_struct;
- A_RSA_KEY *public1 = NULL, *public2 = NULL;
- A_PKCS_RSA_PRIVATE_KEY *p1 = NULL, *p2 = NULL;
-
- if (rkey1 == NULL && rkey2 == NULL)
- return(0);
- else if (rkey1 == NULL)
- return (1);
- else if (rkey2 == NULL)
- return (2);
-
- if (rkey1->rk_Public_Key)
- B_GetKeyInfo((POINTER *) &public1, rkey1->rk_Public_Key,
- KI_RSAPublic);
- if (rkey2->rk_Public_Key)
- B_GetKeyInfo((POINTER *) &public2, rkey2->rk_Public_Key,
- KI_RSAPublic);
- if (public1 == NULL && public2 == NULL)
- return (0);
- else if (public1 == NULL || public2 == NULL)
- return (1);
-
- status = dst_s_bsafe_itemcmp(public1->modulus, public2->modulus) ||
- dst_s_bsafe_itemcmp(public1->exponent, public2->exponent);
-
- if (status)
- return (status);
-
- if (rkey1->rk_Private_Key == NULL || rkey2->rk_Private_Key == NULL)
- /* if neither or only one is private key consider identical */
- return (status);
- if (rkey1->rk_Private_Key)
- s1 = B_GetKeyInfo((POINTER *) &p1, rkey1->rk_Private_Key,
- KI_PKCS_RSAPrivate);
- if (rkey2->rk_Private_Key)
- s2 = B_GetKeyInfo((POINTER *) &p2, rkey2->rk_Private_Key,
- KI_PKCS_RSAPrivate);
- if (p1 == NULL || p2 == NULL)
- return (0);
-
- status = dst_s_bsafe_itemcmp(p1->modulus, p2->modulus) ||
- dst_s_bsafe_itemcmp (p1->publicExponent,
- p2->publicExponent) ||
- dst_s_bsafe_itemcmp (p1->privateExponent,
- p2->privateExponent) ||
- dst_s_bsafe_itemcmp (p1->prime[0], p2->prime[0]) ||
- dst_s_bsafe_itemcmp (p1->prime[1], p2->prime[1]) ||
- dst_s_bsafe_itemcmp (p1->primeExponent[0],
- p2->primeExponent[0])||
- dst_s_bsafe_itemcmp (p1->primeExponent[1],
- p2->primeExponent[1])||
- dst_s_bsafe_itemcmp (p1->coefficient, p2->coefficient);
- return (status);
-}
-
-
-/*
- * dst_bsafe_key_size()
- * Function to calculate how the size of the key in bits
- */
-static int
-dst_bsafe_key_size(RSA_Key *r_key)
-{
- int size;
- A_PKCS_RSA_PRIVATE_KEY *private = NULL;
-
- if (r_key == NULL)
- return (-1);
- if (r_key->rk_Private_Key)
- B_GetKeyInfo((POINTER *) &private, r_key->rk_Private_Key,
- KI_PKCS_RSAPrivate);
- else if (r_key->rk_Public_Key)
- B_GetKeyInfo((POINTER *) &private, r_key->rk_Public_Key,
- KI_RSAPublic);
- size = dst_s_calculate_bits(private->modulus.data,
- private->modulus.len * 8);
- return (size);
-}
-
-/*
- * dst_bsafe_md5digest(): function to digest data using MD5 digest function
- * if needed
- */
-static int
-dst_bsafe_md5digest(const int mode, B_ALGORITHM_OBJ *digest_obj,
- const u_char *data, const int len,
- u_char *digest, const int digest_len)
-{
- int status = 0;
- u_int work_size = 0;
-
- if (digest_obj == NULL || *digest_obj == NULL) {
- printf("NO digest obj\n");
- exit(33);
- }
-
- if ((mode & SIG_MODE_INIT) &&
- (status = B_DigestInit(*digest_obj, (B_KEY_OBJ) NULL,
- CHOOSER, NULL_SURRENDER)))
- return (SIGN_INIT_FAILURE);
-
- if ((mode & SIG_MODE_UPDATE) && data && (len > 0) &&
- (status = B_DigestUpdate(*digest_obj, data, len, NULL_SURRENDER)))
- return (SIGN_UPDATE_FAILURE);
-
- if (mode & SIG_MODE_FINAL) {
- if (digest == NULL ||
- (status = B_DigestFinal(*digest_obj, digest, &work_size,
- digest_len, NULL_SURRENDER)))
- return (SIGN_FINAL_FAILURE);
- return (work_size);
- }
- return (0);
-}
-
-/*
- * just use the standard memory functions for bsafe
- */
-void
-T_free(POINTER block)
-{
- free(block);
-}
-
-POINTER
-T_malloc(unsigned int len)
-{
- return (malloc(len));
-}
-
-int
-T_memcmp(CPOINTER firstBlock, CPOINTER secondBlock, unsigned int len)
-{
- return (memcmp(firstBlock, secondBlock, len));
-}
-
-void
-T_memcpy(POINTER output, CPOINTER input, unsigned int len)
-{
- memcpy(output, input, len);
-}
-
-void
-T_memmove(POINTER output, POINTER input, unsigned int len)
-{
- memmove(output, input, len);
-}
-
-void
-T_memset(POINTER output, int value, unsigned int len)
-{
- memset(output, value, len);
-}
-
-POINTER
-T_realloc(POINTER block, unsigned int len)
-{
- return (realloc(block, len));
-}
-
-#else /* BSAFE NOT available */
-#define dst_bsafe_init __dst_bsafe_init
-
-int
-dst_bsafe_init()
-{
- return (0);
-}
-#endif /* BSAFE */
diff --git a/contrib/bind/lib/dst/cylink_link.c b/contrib/bind/lib/dst/cylink_link.c
deleted file mode 100644
index 5d22074..0000000
--- a/contrib/bind/lib/dst/cylink_link.c
+++ /dev/null
@@ -1,672 +0,0 @@
-#ifdef CYLINK_DSS
-static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/cylink_link.c,v 1.10 2002/12/03 05:26:49 marka Exp $";
-
-/*
- * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc.
- *
- * 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 TRUSTED INFORMATION SYSTEMS
- * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
- * TRUSTED INFORMATION SYSTEMS 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 THE SOFTWARE.
- */
-/*
- * This file contains two components
- * 1. Interface to the CYLINK library to allow compilation of Bind
- * with TIS/DNSSEC when CYLINK is not available
- * all calls to CYLINK are contained inside this file.
- * 2. The glue to connvert DSA KEYS to and from external formats
- */
-#include "port_before.h"
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <memory.h>
-#include <sys/param.h>
-#include <sys/time.h>
-#include <netinet/in.h>
-
-#include "dst_internal.h"
-#include <toolkit.h>
-
-#include "port_after.h"
-
-typedef struct cylinkkey {
- char *dk_signer;
- uchar *dk_p;
- uchar *dk_q;
- uchar *dk_g;
- uchar *dk_x;
- uchar *dk_y;
- ushort dk_p_bytes;
-} DSA_Key;
-
-#define NULL_PRIV_KEY(k)(k == NULL || k->dk_p == NULL || k->dk_q == NULL || \
- k->dk_g == NULL || k->dk_x == NULL)
-#define NULL_PUB_KEY(k)(k == NULL || k->dk_p == NULL || k->dk_q == NULL || \
- k->dk_g == NULL || k->dk_y == NULL)
-
-static int dst_cylink_sign(const int mode, DST_KEY *dkey, void **context,
- const u_char *data, const int len,
- u_char *signature, const int sig_len);
-
-static int dst_cylink_verify(const int mode, DST_KEY *dkey, void **context,
- const u_char *data, const int len,
- const u_char *signature, const int sig_len);
-
-static int dst_cylink_to_dns_key(const DST_KEY *in_key, u_char *out_str,
- const int out_len);
-static int dst_cylink_from_dns_key(DST_KEY *s_key, const u_char *key,
- const int len);
-static int dst_cylink_key_to_file_format(const DST_KEY *key, char *buff,
- const int buff_len);
-static int dst_cylink_key_from_file_format(DST_KEY *d_key,
- const char *buff,
- const int buff_len);
-static void *dst_cylink_free_key_structure(void *key);
-
-static int dst_cylink_generate_keypair(DST_KEY *key, int exp);
-static int dst_cylink_compare_keys(const DST_KEY *key1, const DST_KEY *key2);
-
-static void *memcpyend(void *dest, const void *src, size_t n, size_t size);
-
-/*
- * dst_cylink_init() Function to answer set up function pointers for
- * CYLINK related functions
- */
-int
-dst_cylink_init()
-{
- if (dst_t_func[KEY_DSA] != NULL)
- return (1);
- dst_t_func[KEY_DSA] = malloc(sizeof(struct dst_func));
- if (dst_t_func[KEY_DSA] == NULL)
- return (0);
- memset(dst_t_func[KEY_DSA], 0, sizeof(struct dst_func));
- dst_t_func[KEY_DSA]->sign = dst_cylink_sign;
- dst_t_func[KEY_DSA]->verify = dst_cylink_verify;
- dst_t_func[KEY_DSA]->compare = dst_cylink_compare_keys;
- dst_t_func[KEY_DSA]->generate = dst_cylink_generate_keypair;
- dst_t_func[KEY_DSA]->destroy = dst_cylink_free_key_structure;
- dst_t_func[KEY_DSA]->from_dns_key = dst_cylink_from_dns_key;
- dst_t_func[KEY_DSA]->to_dns_key = dst_cylink_to_dns_key;
- dst_t_func[KEY_DSA]->from_file_fmt = dst_cylink_key_from_file_format;
- dst_t_func[KEY_DSA]->to_file_fmt = dst_cylink_key_to_file_format;
- SetDataOrder(1);
- return (1);
-}
-
-/*
- * dst_cylink_sign
- * Call CYLINK signing functions to sign a block of data.
- * There are three steps to signing, INIT (initialize structures),
- * UPDATE (hash (more) data), FINAL (generate a signature). This
- * routine performs one or more of these steps.
- * Parameters
- * mode SIG_MODE_INIT, SIG_MODE_UPDATE and/or SIG_MODE_FINAL.
- * algobj structure holds context for a sign done in multiple calls.
- * context the context to use for this computation
- * data data to be signed.
- * len length in bytes of data.
- * priv_key key to use for signing.
- * signature location to store signature.
- * sig_len size in bytes of signature field.
- * returns
- * N Success on SIG_MODE_FINAL = returns signature length in bytes
- * N is 41 for DNS
- * 0 Success on SIG_MODE_INIT and UPDATE
- * <0 Failure
- */
-
-static int
-dst_cylink_sign(const int mode, DST_KEY *dkey, void **context,
- const u_char *data, const int len,
- u_char *signature, const int sig_len)
-{
- int sign_len = 0;
- int status;
- SHA_context *ctx = NULL;
-
- if (mode & SIG_MODE_INIT)
- ctx = (SHA_context *) malloc(sizeof(SHA_context));
- else if (context)
- ctx = (SHA_context *) *context;
- if (ctx == NULL)
- return (-1);
-
- if (mode & SIG_MODE_INIT)
- SHAInit(ctx);
-
- if ((mode & SIG_MODE_UPDATE) && (data && len > 0)) {
- status = SHAUpdate(ctx, data, len);
- if (status != SUCCESS)
- return (SIGN_UPDATE_FAILURE);
- }
- if (mode & SIG_MODE_FINAL) {
- DSA_Key *key;
- uchar digest[SHA_LENGTH];
- uchar rand[SHA_LENGTH];
- uchar r[SHA_LENGTH], s[SHA_LENGTH];
-
- if (signature == NULL || sig_len < 2 * SHA_LENGTH)
- return (SIGN_FINAL_FAILURE);
- if ((status = SHAFinal(ctx, digest)) != SUCCESS)
- return (SIGN_FINAL_FAILURE);
- SAFE_FREE(ctx);
- if (dkey == NULL || dkey->dk_KEY_struct == NULL)
- return (-1);
- key = (DSA_Key *) dkey->dk_KEY_struct;
- if (NULL_PRIV_KEY(key))
- return (-2);
- dst_random(DST_RAND_STD, sizeof(rand), rand);
- status = GenDSSSignature(key->dk_p_bytes, key->dk_p,
- key->dk_q, key->dk_g, key->dk_x,
- rand, r, s, digest);
- if (status != SUCCESS)
- return (SIGN_FINAL_FAILURE);
- *signature = (dkey->dk_key_size - 512)/64;
- sign_len = 1;
- memcpy(signature + sign_len, r, SHA_LENGTH);
- sign_len += SHA_LENGTH;
- memcpy(signature + sign_len, s, SHA_LENGTH);
- sign_len += SHA_LENGTH;
- }
- else {
- if (context == NULL)
- return (-1);
- *context = (void *) ctx;
- }
- return (sign_len);
-}
-
-
-/*
- * Dst_cylink_verify
- * Calls CYLINK verification routines. There are three steps to
- * verification, INIT (initialize structures), UPDATE (hash (more) data),
- * FINAL (generate a signature). This routine performs one or more of
- * these steps.
- * Parameters
- * mode SIG_MODE_INIT, SIG_MODE_UPDATE and/or SIG_MODE_FINAL.
- * dkey structure holds context for a verify done in multiple calls.
- * context algorithm specific context for the current context processing
- * data data signed.
- * len length in bytes of data.
- * pub_key key to use for verify.
- * signature signature.
- * sig_len length in bytes of signature.
- * returns
- * 0 Success
- * <0 Failure
- */
-
-static int
-dst_cylink_verify(const int mode, DST_KEY *dkey, void **context,
- const u_char *data, const int len,
- const u_char *signature, const int sig_len)
-{
- int status;
- SHA_context *ctx = NULL;
-
- if (mode & SIG_MODE_INIT)
- ctx = (SHA_context *) malloc(sizeof(SHA_context));
- else if (context)
- ctx = (SHA_context *) *context;
- if (ctx == NULL)
- return (-1);
-
- if (mode & SIG_MODE_INIT)
- SHAInit(ctx);
-
- if ((mode & SIG_MODE_UPDATE) && (data && len > 0)) {
- status = SHAUpdate(ctx, data, len);
- if (status != SUCCESS)
- return (VERIFY_UPDATE_FAILURE);
- }
- if (mode & SIG_MODE_FINAL) {
- DSA_Key *key;
- uchar digest[SHA_LENGTH];
- uchar r[SHA_LENGTH], s[SHA_LENGTH];
-
- if (dkey == NULL || dkey->dk_KEY_struct == NULL)
- return (-1);
- key = (DSA_Key *) dkey->dk_KEY_struct;
- if (NULL_PUB_KEY(key))
- return (-2);
- if (signature == NULL || sig_len != (2 * SHA_LENGTH +1))
- return (SIGN_FINAL_FAILURE);
- status = SHAFinal(ctx, digest);
- SAFE_FREE(ctx);
- if (status != SUCCESS)
- return (SIGN_FINAL_FAILURE);
- if (((int)*signature) != ((key->dk_p_bytes -64)/8))
- return(VERIFY_FINAL_FAILURE);
-
- memcpy(r, signature +1, SHA_LENGTH);
- memcpy(s, signature + SHA_LENGTH +1, SHA_LENGTH);
- status = VerDSSSignature(key->dk_p_bytes, key->dk_p,
- key->dk_q, key->dk_g, key->dk_y,
- r, s, digest);
- if (status != SUCCESS)
- return (VERIFY_FINAL_FAILURE);
- }
- else {
- if (context == NULL)
- return (-1);
- *context = (void *) ctx;
- }
- return (0);
-}
-
-
-/*
- * dst_cylink_to_dns_key
- * Converts key from DSA to DNS distribution format
- * This function gets in a pointer to the public key and a work area
- * to write the key into.
- * Parameters
- * public KEY structure
- * out_str buffer to write encoded key into
- * out_len size of out_str
- * Return
- * N >= 0 length of encoded key
- * n < 0 error
- */
-
-static int
-dst_cylink_to_dns_key(const DST_KEY *in_key, u_char *out_str,
- const int out_len)
-{
- u_char *op = out_str;
- int t;
- DSA_Key *key;
-
- if (in_key == NULL || in_key->dk_KEY_struct == NULL ||
- out_len <= 0 || out_str == NULL)
- return (-1);
- key = (DSA_Key *) in_key->dk_KEY_struct;
-
- t = (key->dk_p_bytes - 64) / 8;
-
- *op++ = t;
- memcpy(op, key->dk_q, SHA_LENGTH);
- op += SHA_LENGTH;
- memcpy(op, key->dk_p, key->dk_p_bytes);
- op += key->dk_p_bytes;
- memcpy(op, key->dk_g, key->dk_p_bytes);
- op += key->dk_p_bytes;
- memcpy(op, key->dk_y, key->dk_p_bytes);
- op += key->dk_p_bytes;
-
- return (op - out_str);
-}
-
-
-/*
- * dst_cylink_from_dns_key
- * Converts from a DNS KEY RR format to an RSA KEY.
- * Parameters
- * len Length in bytes of DNS key
- * key DNS key
- * name Key name
- * s_key DST structure that will point to the RSA key this routine
- * will build.
- * Return
- * 0 The input key, s_key or name was null.
- * 1 Success
- */
-static int
-dst_cylink_from_dns_key(DST_KEY *s_key, const u_char *key, const int len)
-{
- int t;
- const u_char *key_ptr = key;
- DSA_Key *d_key;
-
- if (s_key == NULL || len < 0 || key == NULL)
- return (0);
-
- if (len == 0) /* process null key */
- return (1);
-
- if (key_ptr == NULL)
- return (0);
- t = (int) *key_ptr++; /* length of exponent in bytes */
-
- if ((3 * (t * 8 + 64) + SHA_LENGTH + 1) != len)
- return (0);
-
- if ((d_key = (DSA_Key *) malloc(sizeof(DSA_Key))) == NULL) {
- EREPORT(("dst_cylink_from_dns_key(): Memory allocation error 1"));
- return (0);
- }
- memset(d_key, 0, sizeof(DSA_Key));
- s_key->dk_KEY_struct = (void *) d_key;
- d_key->dk_signer = strdup(s_key->dk_key_name);
- d_key->dk_p_bytes = 64 + 8 * t;
-
- if ((d_key->dk_q = (uchar *) malloc(SHA_LENGTH)) == NULL)
- return (0);
- memcpy(d_key->dk_q, key_ptr, SHA_LENGTH);
- key_ptr += SHA_LENGTH;
-
- if ((d_key->dk_p = (uchar *) malloc(d_key->dk_p_bytes)) == NULL)
- return (0);
- memcpy(d_key->dk_p, key_ptr, d_key->dk_p_bytes);
- key_ptr += d_key->dk_p_bytes;
-
- if ((d_key->dk_g = (uchar *) malloc(d_key->dk_p_bytes)) == NULL)
- return (0);
- memcpy(d_key->dk_g, key_ptr, d_key->dk_p_bytes);
- key_ptr += d_key->dk_p_bytes;
-
- if ((d_key->dk_y = (uchar *) malloc(d_key->dk_p_bytes)) == NULL)
- return (0);
- memcpy(d_key->dk_y, key_ptr, d_key->dk_p_bytes);
- key_ptr += d_key->dk_p_bytes;
-
- s_key->dk_key_size = d_key->dk_p_bytes * 8;
- return (1);
-}
-
-
-/**************************************************************************
- * dst_cylink_key_to_file_format
- * Encodes an DSA Key into the portable file format.
- * Parameters
- * key DSA KEY structure
- * buff output buffer
- * buff_len size of output buffer
- * Return
- * 0 Failure - null input rkey
- * -1 Failure - not enough space in output area
- * N Success - Length of data returned in buff
- */
-
-static int
-dst_cylink_key_to_file_format(const DST_KEY *key, char *buff,
- const int buff_len)
-{
- char *bp;
- int len, b_len;
- DSA_Key *dkey;
- u_char num[256]; /* More than long enough for DSA keys */
-
- if (key == NULL || key->dk_KEY_struct == NULL) /* no output */
- return (0);
- if (buff == NULL || buff_len <= (int) strlen(key_file_fmt_str))
- return (-1); /* no OR not enough space in output area */
-
- dkey = (DSA_Key *) key->dk_KEY_struct;
-
- memset(buff, 0, buff_len); /* just in case */
- /* write file header */
- sprintf(buff, key_file_fmt_str, KEY_FILE_FORMAT, KEY_DSA, "DSA");
-
- bp = (char *) strchr(buff, '\0');
- b_len = buff_len - (bp - buff);
- memcpy(num, dkey->dk_p, dkey->dk_p_bytes);
- if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Prime(p): ",
- num, dkey->dk_p_bytes)) <= 0)
- return (-1);
-
- bp = (char *) strchr(buff, '\0');
- b_len = buff_len - (bp - buff);
- memcpy(num, dkey->dk_q, dkey->dk_p_bytes);
- if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Subprime(q): ",
- num, SHA_LENGTH)) <= 0)
- return (-2);
-
- bp = (char *) strchr(buff, '\0');
- b_len = buff_len - (bp - buff);
- memcpy(num, dkey->dk_g, dkey->dk_p_bytes);
- if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Base(g): ",
- num, dkey->dk_p_bytes)) <= 0)
- return (-3);
-
- bp = (char *) strchr(buff, '\0');
- b_len = buff_len - (bp - buff);
- memcpy(num, dkey->dk_x, dkey->dk_p_bytes);
- if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Private_value(x): ",
- num, SHA_LENGTH)) <= 0)
- return (-4);
-
- bp = (char *) strchr(buff, '\0');
- b_len = buff_len - (bp - buff);
- memcpy(num, dkey->dk_y, dkey->dk_p_bytes);
- if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Public_value(y): ",
- num, dkey->dk_p_bytes)) <= 0)
- return (-4);
-
- bp += len;
- b_len -= len;
- return (buff_len - b_len);
-}
-
-
-/**************************************************************************
- * dst_cylink_key_from_file_format
- * Converts contents of a private key file into a private DSA key.
- * Parameters
- * DSA_Key structure to put key into
- * buff buffer containing the encoded key
- * buff_len the length of the buffer
- * Return
- * n >= 0 Foot print of the key converted
- * n < 0 Error in conversion
- */
-
-static int
-dst_cylink_key_from_file_format(DST_KEY *d_key, const char *buff,
- const int buff_len)
-{
- u_char s[DSS_LENGTH_MAX];
- int len, s_len = sizeof(s);
- const char *p = buff;
- DSA_Key *dsa_key;
-
- if (d_key == NULL || buff == NULL || buff_len <= 0)
- return (-1);
-
- dsa_key = (DSA_Key *) malloc(sizeof(DSA_Key));
- if (dsa_key == NULL) {
- return (-2);
- }
- memset(dsa_key, 0, sizeof(*dsa_key));
- d_key->dk_KEY_struct = (void *) dsa_key;
-
- if (!dst_s_verify_str(&p, "Prime(p): "))
- return (-3);
- memset(s, 0, s_len);
- if ((len = dst_s_conv_bignum_b64_to_u8(&p, s, s_len)) == 0)
- return (-4);
- dsa_key->dk_p_bytes = len;
- if ((dsa_key->dk_p = malloc(len)) == NULL)
- return (-5);
- memcpy(dsa_key->dk_p, s + s_len - len, len);
-
- while (*++p && p < (const char *) &buff[buff_len]) {
- if (dst_s_verify_str(&p, "Subprime(q): ")) {
- if (!(len = dst_s_conv_bignum_b64_to_u8(&p, s, s_len)))
- return (-6);
- if ((dsa_key->dk_q = malloc(SHA_LENGTH)) == NULL)
- return (-7);
- memcpyend(dsa_key->dk_q, s + s_len - len, len,
- SHA_LENGTH);
- } else if (dst_s_verify_str(&p, "Base(g): ")) {
- if (!(len = dst_s_conv_bignum_b64_to_u8(&p, s, s_len)))
- return (-8);
- if ((dsa_key->dk_g = malloc(dsa_key->dk_p_bytes))
- == NULL)
- return (-9);
- memcpyend(dsa_key->dk_g, s + s_len - len, len,
- dsa_key->dk_p_bytes);
- } else if (dst_s_verify_str(&p, "Private_value(x): ")) {
- if (!(len = dst_s_conv_bignum_b64_to_u8(&p, s, s_len)))
- return (-10);
- if ((dsa_key->dk_x = malloc(SHA_LENGTH)) == NULL)
- return (-11);
- memcpyend(dsa_key->dk_x, s + s_len - len, len,
- SHA_LENGTH);
- } else if (dst_s_verify_str(&p, "Public_value(y): ")) {
- if (!(len = dst_s_conv_bignum_b64_to_u8(&p, s, s_len)))
- return (-10);
- if ((dsa_key->dk_y = malloc(dsa_key->dk_p_bytes))
- == NULL)
- return (-11);
- memcpyend(dsa_key->dk_y, s + s_len - len, len,
- dsa_key->dk_p_bytes);
- } else {
- EREPORT(("Decode_DSAKey(): Bad keyword %s\n", p));
- return (-12);
- }
- } /* while p */
-
- d_key->dk_key_size = dsa_key->dk_p_bytes * 8;
-
- return (0);
-}
-
-
-/**************************************************************************
- * dst_cylink_free_key_structure
- * Frees all dynamicly allocated structures in DSA_Key.
- */
-
-static void *
-dst_cylink_free_key_structure(void *key)
-{
- DSA_Key *d_key = (DSA_Key *) key;
- if (d_key != NULL) {
- SAFE_FREE(d_key->dk_signer);
- SAFE_FREE(d_key->dk_p);
- SAFE_FREE(d_key->dk_q);
- SAFE_FREE(d_key->dk_g);
- SAFE_FREE(d_key->dk_x);
- SAFE_FREE(d_key->dk_y);
- SAFE_FREE(d_key);
- }
- return (NULL);
-}
-
-
-/**************************************************************************
- * dst_cylink_generate_keypair
- * Generates unique keys that are hard to predict.
- * Parameters
- * key generic Key structure
- * exp the public exponent
- * Return
- * 0 Failure
- * 1 Success
- */
-
-static int
-dst_cylink_generate_keypair(DST_KEY *key, int nothing)
-{
- int status, n;
- DSA_Key *dsa;
- u_char rand[SHA_LENGTH];
-
- UNUSED(nothing);
-
- if (key == NULL || key->dk_alg != KEY_DSA)
- return (0);
-
- if ((dsa = (DSA_Key *) malloc(sizeof(DSA_Key))) == NULL) {
- EREPORT(("dst_cylink_generate_keypair: Memory allocation error 3"));
- return (0);
- }
- memset(dsa, 0, sizeof(*dsa));
-
- dsa->dk_p_bytes = key->dk_key_size / 8;
- dsa->dk_p = (uchar *) malloc(dsa->dk_p_bytes);
- dsa->dk_q = (uchar *) malloc(SHA_LENGTH);
- dsa->dk_g = (uchar *) malloc(dsa->dk_p_bytes);
- dsa->dk_x = (uchar *) malloc(SHA_LENGTH);
- dsa->dk_y = (uchar *) malloc(dsa->dk_p_bytes);
- if (!dsa->dk_p || !dsa->dk_q || !dsa->dk_g || !dsa->dk_x || !dsa->dk_y) {
- EREPORT(("dst_cylink_generate_keypair: Memory allocation error 4"));
- return (0);
- }
- n = dst_random(DST_RAND_KEY, sizeof(rand), rand);
- if (n != sizeof(rand))
- return (0);
- status = GenDSSParameters(dsa->dk_p_bytes, dsa->dk_p, dsa->dk_q,
- dsa->dk_g, rand, NULL);
- if (status != SUCCESS)
- return (0);
-
- status = GenDSSKey(dsa->dk_p_bytes, dsa->dk_p, dsa->dk_q, dsa->dk_g,
- dsa->dk_x, dsa->dk_y, rand);
- if (status != SUCCESS)
- return (0);
- memset(rand, 0, sizeof(rand));
- key->dk_KEY_struct = (void *) dsa;
- return (1);
-}
-
-
-/*
- * dst_cylink_compare_keys
- * Compare two keys for equality.
- * Return
- * 0 The keys are equal
- * NON-ZERO The keys are not equal
- */
-
-static int
-dst_cylink_compare_keys(const DST_KEY *key1, const DST_KEY *key2)
-{
- int status;
- DSA_Key *dkey1 = (DSA_Key *) key1->dk_KEY_struct;
- DSA_Key *dkey2 = (DSA_Key *) key2->dk_KEY_struct;
-
- if (dkey1 == NULL && dkey2 == NULL)
- return (0);
- else if (dkey1 == NULL)
- return (2);
- else if (dkey2 == NULL)
- return(1);
-
- if (dkey1->dk_p_bytes != dkey2->dk_p_bytes)
- return (201);
- status = memcmp(dkey1->dk_p, dkey2->dk_p, dkey1->dk_p_bytes) ||
- memcmp(dkey1->dk_q, dkey2->dk_q, SHA_LENGTH) ||
- memcmp(dkey1->dk_g, dkey2->dk_g, dkey1->dk_p_bytes) ||
- memcmp(dkey1->dk_y, dkey2->dk_y, dkey1->dk_p_bytes);
- if (status)
- return (status);
- if (dkey1->dk_x || dkey2->dk_x) {
- if (dkey1->dk_x == NULL || dkey2->dk_x == NULL)
- return (202);
- return (memcmp(dkey1->dk_x, dkey2->dk_x, dkey1->dk_p_bytes));
- } else
- return (0);
-}
-
-static void *
-memcpyend(void *dest, const void *src, size_t n, size_t size) {
- if (n < size)
- memset(dest, 0, size - n);
- memcpy((char *)dest + size - n, src, n);
- return dest;
-}
-
-#else
-#define dst_cylink_init __dst_cylink_init
-
-int
-dst_cylink_init()
-{
- return (0);
-}
-#endif /* CYLINK */
diff --git a/contrib/bind/lib/dst/dst_api.c b/contrib/bind/lib/dst/dst_api.c
deleted file mode 100644
index e5f8cdb..0000000
--- a/contrib/bind/lib/dst/dst_api.c
+++ /dev/null
@@ -1,1092 +0,0 @@
-#ifndef LINT
-static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/dst_api.c,v 1.21 2002/06/28 06:58:19 marka Exp $";
-#endif
-
-/*
- * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc.
- *
- * 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 TRUSTED INFORMATION SYSTEMS
- * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
- * TRUSTED INFORMATION SYSTEMS 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 THE SOFTWARE.
- */
-/*
- * This file contains the interface between the DST API and the crypto API.
- * This is the only file that needs to be changed if the crypto system is
- * changed. Exported functions are:
- * void dst_init() Initialize the toolkit
- * int dst_check_algorithm() Function to determines if alg is suppored.
- * int dst_compare_keys() Function to compare two keys for equality.
- * int dst_sign_data() Incremental signing routine.
- * int dst_verify_data() Incremental verify routine.
- * int dst_generate_key() Function to generate new KEY
- * DST_KEY *dst_read_key() Function to retrieve private/public KEY.
- * void dst_write_key() Function to write out a key.
- * DST_KEY *dst_dnskey_to_key() Function to convert DNS KEY RR to a DST
- * KEY structure.
- * int dst_key_to_dnskey() Function to return a public key in DNS
- * format binary
- * DST_KEY *dst_buffer_to_key() Converst a data in buffer to KEY
- * int *dst_key_to_buffer() Writes out DST_KEY key matterial in buffer
- * void dst_free_key() Releases all memory referenced by key structure
- */
-
-#include "port_before.h"
-#include <stdio.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <memory.h>
-#include <ctype.h>
-#include <time.h>
-#include <sys/param.h>
-#include <sys/stat.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-
-#include "dst_internal.h"
-#include "port_after.h"
-
-/* static variables */
-static int done_init = 0;
-dst_func *dst_t_func[DST_MAX_ALGS];
-const char *key_file_fmt_str = "Private-key-format: v%s\nAlgorithm: %d (%s)\n";
-const char *dst_path = "";
-
-/* internal I/O functions */
-static DST_KEY *dst_s_read_public_key(const char *in_name,
- const u_int16_t in_id, int in_alg);
-static int dst_s_read_private_key_file(char *name, DST_KEY *pk_key,
- u_int16_t in_id, int in_alg);
-static int dst_s_write_public_key(const DST_KEY *key);
-static int dst_s_write_private_key(const DST_KEY *key);
-
-/* internal function to set up data structure */
-static DST_KEY *dst_s_get_key_struct(const char *name, const int alg,
- const int flags, const int protocol,
- const int bits);
-
-/*
- * dst_init
- * This function initializes the Digital Signature Toolkit.
- * Right now, it just checks the DSTKEYPATH environment variable.
- * Parameters
- * none
- * Returns
- * none
- */
-void
-dst_init()
-{
- char *s;
- int len;
-
- if (done_init != 0)
- return;
- done_init = 1;
-
- s = getenv("DSTKEYPATH");
- len = 0;
- if (s) {
- struct stat statbuf;
-
- len = strlen(s);
- if (len > PATH_MAX) {
- EREPORT(("%s is longer than %d characters, ignoring\n",
- s, PATH_MAX));
- } else if (stat(s, &statbuf) != 0 || !S_ISDIR(statbuf.st_mode)) {
- EREPORT(("%s is not a valid directory\n", s));
- } else {
- char *tmp;
- tmp = (char *) malloc(len + 2);
- memcpy(tmp, s, len + 1);
- if (tmp[strlen(tmp) - 1] != '/') {
- tmp[strlen(tmp) + 1] = 0;
- tmp[strlen(tmp)] = '/';
- }
- dst_path = tmp;
- }
- }
- memset(dst_t_func, 0, sizeof(dst_t_func));
- /* first one is selected */
- dst_bsafe_init();
- dst_rsaref_init();
- dst_hmac_md5_init();
- dst_eay_dss_init();
- dst_cylink_init();
-}
-
-/*
- * dst_check_algorithm
- * This function determines if the crypto system for the specified
- * algorithm is present.
- * Parameters
- * alg 1 KEY_RSA
- * 3 KEY_DSA
- * 157 KEY_HMAC_MD5
- * future algorithms TBD and registered with IANA.
- * Returns
- * 1 - The algorithm is available.
- * 0 - The algorithm is not available.
- */
-int
-dst_check_algorithm(const int alg)
-{
- return (dst_t_func[alg] != NULL);
-}
-
-/*
- * dst_s_get_key_struct
- * This function allocates key structure and fills in some of the
- * fields of the structure.
- * Parameters:
- * name: the name of the key
- * alg: the algorithm number
- * flags: the dns flags of the key
- * protocol: the dns protocol of the key
- * bits: the size of the key
- * Returns:
- * NULL if error
- * valid pointer otherwise
- */
-static DST_KEY *
-dst_s_get_key_struct(const char *name, const int alg, const int flags,
- const int protocol, const int bits)
-{
- DST_KEY *new_key = NULL;
-
- if (dst_check_algorithm(alg)) /* make sure alg is available */
- new_key = (DST_KEY *) malloc(sizeof(*new_key));
- if (new_key == NULL)
- return (NULL);
-
- memset(new_key, 0, sizeof(*new_key));
- new_key->dk_key_name = strdup(name);
- new_key->dk_alg = alg;
- new_key->dk_flags = flags;
- new_key->dk_proto = protocol;
- new_key->dk_KEY_struct = NULL;
- new_key->dk_key_size = bits;
- new_key->dk_func = dst_t_func[alg];
- return (new_key);
-}
-
-/*
- * dst_compare_keys
- * Compares two keys for equality.
- * Parameters
- * key1, key2 Two keys to be compared.
- * Returns
- * 0 The keys are equal.
- * non-zero The keys are not equal.
- */
-
-int
-dst_compare_keys(const DST_KEY *key1, const DST_KEY *key2)
-{
- if (key1 == key2)
- return (0);
- if (key1 == NULL || key2 == NULL)
- return (4);
- if (key1->dk_alg != key2->dk_alg)
- return (1);
- if (key1->dk_key_size != key2->dk_key_size)
- return (2);
- if (key1->dk_id != key2->dk_id)
- return (3);
- return (key1->dk_func->compare(key1, key2));
-}
-
-
-/*
- * dst_sign_data
- * An incremental signing function. Data is signed in steps.
- * First the context must be initialized (SIG_MODE_INIT).
- * Then data is hashed (SIG_MODE_UPDATE). Finally the signature
- * itself is created (SIG_MODE_FINAL). This function can be called
- * once with INIT, UPDATE and FINAL modes all set, or it can be
- * called separately with a different mode set for each step. The
- * UPDATE step can be repeated.
- * Parameters
- * mode A bit mask used to specify operation(s) to be performed.
- * SIG_MODE_INIT 1 Initialize digest
- * SIG_MODE_UPDATE 2 Add data to digest
- * SIG_MODE_FINAL 4 Generate signature
- * from signature
- * SIG_MODE_ALL (SIG_MODE_INIT,SIG_MODE_UPDATE,SIG_MODE_FINAL
- * data Data to be signed.
- * len The length in bytes of data to be signed.
- * in_key Contains a private key to sign with.
- * KEY structures should be handled (created, converted,
- * compared, stored, freed) by the DST.
- * signature
- * The location to which the signature will be written.
- * sig_len Length of the signature field in bytes.
- * Return
- * 0 Successfull INIT or Update operation
- * >0 success FINAL (sign) operation
- * <0 failure
- */
-
-int
-dst_sign_data(const int mode, DST_KEY *in_key, void **context,
- const u_char *data, const int len,
- u_char *signature, const int sig_len)
-{
- DUMP(data, mode, len, "dst_sign_data()");
-
- if (mode & SIG_MODE_FINAL &&
- (in_key->dk_KEY_struct == NULL || signature == NULL))
- return (MISSING_KEY_OR_SIGNATURE);
-
- if (in_key->dk_func && in_key->dk_func->sign)
- return (in_key->dk_func->sign(mode, in_key, context, data, len,
- signature, sig_len));
- return (UNKNOWN_KEYALG);
-}
-
-
-/*
- * dst_verify_data
- * An incremental verify function. Data is verified in steps.
- * First the context must be initialized (SIG_MODE_INIT).
- * Then data is hashed (SIG_MODE_UPDATE). Finally the signature
- * is verified (SIG_MODE_FINAL). This function can be called
- * once with INIT, UPDATE and FINAL modes all set, or it can be
- * called separately with a different mode set for each step. The
- * UPDATE step can be repeated.
- * Parameters
- * mode Operations to perform this time.
- * SIG_MODE_INIT 1 Initialize digest
- * SIG_MODE_UPDATE 2 add data to digest
- * SIG_MODE_FINAL 4 verify signature
- * SIG_MODE_ALL
- * (SIG_MODE_INIT,SIG_MODE_UPDATE,SIG_MODE_FINAL)
- * data Data to pass through the hash function.
- * len Length of the data in bytes.
- * in_key Key for verification.
- * signature Location of signature.
- * sig_len Length of the signature in bytes.
- * Returns
- * 0 Verify success
- * Non-Zero Verify Failure
- */
-
-int
-dst_verify_data(const int mode, DST_KEY *in_key, void **context,
- const u_char *data, const int len,
- const u_char *signature, const int sig_len)
-{
- DUMP(data, mode, len, "dst_verify_data()");
- if (mode & SIG_MODE_FINAL &&
- (in_key->dk_KEY_struct == NULL || signature == NULL))
- return (MISSING_KEY_OR_SIGNATURE);
-
- if (in_key->dk_func == NULL || in_key->dk_func->verify == NULL)
- return (UNSUPPORTED_KEYALG);
- return (in_key->dk_func->verify(mode, in_key, context, data, len,
- signature, sig_len));
-}
-
-
-/*
- * dst_read_private_key
- * Access a private key. First the list of private keys that have
- * already been read in is searched, then the key accessed on disk.
- * If the private key can be found, it is returned. If the key cannot
- * be found, a null pointer is returned. The options specify required
- * key characteristics. If the private key requested does not have
- * these characteristics, it will not be read.
- * Parameters
- * in_keyname The private key name.
- * in_id The id of the private key.
- * options DST_FORCE_READ Read from disk - don't use a previously
- * read key.
- * DST_CAN_SIGN The key must be useable for signing.
- * DST_NO_AUTHEN The key must be useable for authentication.
- * DST_STANDARD Return any key
- * Returns
- * NULL If there is no key found in the current directory or
- * this key has not been loaded before.
- * !NULL Success - KEY structure returned.
- */
-
-DST_KEY *
-dst_read_key(const char *in_keyname, const u_int16_t in_id,
- const int in_alg, const int type)
-{
- char keyname[PATH_MAX];
- DST_KEY *dg_key = NULL, *pubkey = NULL;
-
- if (!dst_check_algorithm(in_alg)) { /* make sure alg is available */
- EREPORT(("dst_read_private_key(): Algorithm %d not suppored\n",
- in_alg));
- return (NULL);
- }
- if ((type & (DST_PUBLIC | DST_PRIVATE)) == 0)
- return (NULL);
- if (in_keyname == NULL) {
- EREPORT(("dst_read_private_key(): Null key name passed in\n"));
- return (NULL);
- } else
- strcpy(keyname, in_keyname);
-
- /* before I read in the public key, check if it is allowed to sign */
- if ((pubkey = dst_s_read_public_key(keyname, in_id, in_alg)) == NULL)
- return (NULL);
-
- if (type == DST_PUBLIC)
- return pubkey;
-
- if (!(dg_key = dst_s_get_key_struct(keyname, pubkey->dk_alg,
- pubkey->dk_flags, pubkey->dk_proto,
- 0)))
- return (dg_key);
- /* Fill in private key and some fields in the general key structure */
- if (dst_s_read_private_key_file(keyname, dg_key, pubkey->dk_id,
- pubkey->dk_alg) == 0)
- dg_key = dst_free_key(dg_key);
-
- pubkey = dst_free_key(pubkey);
- return (dg_key);
-}
-
-int
-dst_write_key(const DST_KEY *key, const int type)
-{
- int pub = 0, priv = 0;
-
- if (key == NULL)
- return (0);
- if (!dst_check_algorithm(key->dk_alg)) { /* make sure alg is available */
- EREPORT(("dst_write_key(): Algorithm %d not suppored\n",
- key->dk_alg));
- return (UNSUPPORTED_KEYALG);
- }
- if ((type & (DST_PRIVATE|DST_PUBLIC)) == 0)
- return (0);
-
- if (type & DST_PUBLIC)
- if ((pub = dst_s_write_public_key(key)) < 0)
- return (pub);
- if (type & DST_PRIVATE)
- if ((priv = dst_s_write_private_key(key)) < 0)
- return (priv);
- return (priv+pub);
-}
-
-/*
- * dst_write_private_key
- * Write a private key to disk. The filename will be of the form:
- * K<key->dk_name>+<key->dk_alg>+<key->dk_id>.<private key suffix>.
- * If there is already a file with this name, an error is returned.
- *
- * Parameters
- * key A DST managed key structure that contains
- * all information needed about a key.
- * Return
- * >= 0 Correct behavior. Returns length of encoded key value
- * written to disk.
- * < 0 error.
- */
-
-static int
-dst_s_write_private_key(const DST_KEY *key)
-{
- u_char encoded_block[RAW_KEY_SIZE];
- char file[PATH_MAX];
- int len;
- FILE *fp;
-
- /* First encode the key into the portable key format */
- if (key == NULL)
- return (-1);
- if (key->dk_KEY_struct == NULL)
- return (0); /* null key has no private key */
-
- if (key->dk_func == NULL || key->dk_func->to_file_fmt == NULL) {
- EREPORT(("dst_write_private_key(): Unsupported operation %d\n",
- key->dk_alg));
- return (-5);
- } else if ((len = key->dk_func->to_file_fmt(key, (char *)encoded_block,
- sizeof(encoded_block))) <= 0) {
- EREPORT(("dst_write_private_key(): Failed encoding private RSA bsafe key %d\n", len));
- return (-8);
- }
- /* Now I can create the file I want to use */
- dst_s_build_filename(file, key->dk_key_name, key->dk_id, key->dk_alg,
- PRIVATE_KEY, PATH_MAX);
-
- /* Do not overwrite an existing file */
- if ((fp = dst_s_fopen(file, "w", 0600)) != NULL) {
- int nn;
- if ((nn = fwrite(encoded_block, 1, len, fp)) != len) {
- EREPORT(("dst_write_private_key(): Write failure on %s %d != %d errno=%d\n",
- file, len, nn, errno));
- return (-5);
- }
- fclose(fp);
- } else {
- EREPORT(("dst_write_private_key(): Can not create file %s\n"
- ,file));
- return (-6);
- }
- memset(encoded_block, 0, len);
- return (len);
-}
-
-/*
-*
- * dst_read_public_key
- * Read a public key from disk and store in a DST key structure.
- * Parameters
- * in_name K<in_name><in_id>.<public key suffix> is the
- * filename of the key file to be read.
- * Returns
- * NULL If the key does not exist or no name is supplied.
- * NON-NULL Initialized key structure if the key exists.
- */
-
-static DST_KEY *
-dst_s_read_public_key(const char *in_name, const u_int16_t in_id, int in_alg)
-{
- int flags, proto, alg, len, dlen;
- int c;
- char name[PATH_MAX], enckey[RAW_KEY_SIZE], *notspace;
- u_char deckey[RAW_KEY_SIZE];
- FILE *fp;
-
- if (in_name == NULL) {
- EREPORT(("dst_read_public_key(): No key name given\n"));
- return (NULL);
- }
- if (dst_s_build_filename(name, in_name, in_id, in_alg, PUBLIC_KEY,
- PATH_MAX) == -1) {
- EREPORT(("dst_read_public_key(): Cannot make filename from %s, %d, and %s\n",
- in_name, in_id, PUBLIC_KEY));
- return (NULL);
- }
- /*
- * Open the file and read it's formatted contents up to key
- * File format:
- * domain.name [ttl] [IN] KEY <flags> <protocol> <algorithm> <key>
- * flags, proto, alg stored as decimal (or hex numbers FIXME).
- * (FIXME: handle parentheses for line continuation.)
- */
- if ((fp = dst_s_fopen(name, "r", 0)) == NULL) {
- EREPORT(("dst_read_public_key(): Public Key not found %s\n",
- name));
- return (NULL);
- }
- /* Skip domain name, which ends at first blank */
- while ((c = getc(fp)) != EOF)
- if (isspace(c))
- break;
- /* Skip blank to get to next field */
- while ((c = getc(fp)) != EOF)
- if (!isspace(c))
- break;
-
- /* Skip optional TTL -- if initial digit, skip whole word. */
- if (isdigit(c)) {
- while ((c = getc(fp)) != EOF)
- if (isspace(c))
- break;
- while ((c = getc(fp)) != EOF)
- if (!isspace(c))
- break;
- }
- /* Skip optional "IN" */
- if (c == 'I' || c == 'i') {
- while ((c = getc(fp)) != EOF)
- if (isspace(c))
- break;
- while ((c = getc(fp)) != EOF)
- if (!isspace(c))
- break;
- }
- /* Locate and skip "KEY" */
- if (c != 'K' && c != 'k') {
- EREPORT(("\"KEY\" doesn't appear in file: %s", name));
- return NULL;
- }
- while ((c = getc(fp)) != EOF)
- if (isspace(c))
- break;
- while ((c = getc(fp)) != EOF)
- if (!isspace(c))
- break;
- ungetc(c, fp); /* return the charcter to the input field */
- /* Handle hex!! FIXME. */
-
- if (fscanf(fp, "%d %d %d", &flags, &proto, &alg) != 3) {
- EREPORT(("dst_read_public_key(): Can not read flag/proto/alg field from %s\n"
- ,name));
- return (NULL);
- }
- /* read in the key string */
- fgets(enckey, sizeof(enckey), fp);
-
- /* If we aren't at end-of-file, something is wrong. */
- while ((c = getc(fp)) != EOF)
- if (!isspace(c))
- break;
- if (!feof(fp)) {
- EREPORT(("Key too long in file: %s", name));
- return NULL;
- }
- fclose(fp);
-
- if ((len = strlen(enckey)) <= 0)
- return (NULL);
-
- /* discard \n */
- enckey[--len] = '\0';
-
- /* remove leading spaces */
- for (notspace = (char *) enckey; isspace((*notspace)&0xff); len--)
- notspace++;
-
- dlen = b64_pton(notspace, deckey, sizeof(deckey));
- if (dlen < 0) {
- EREPORT(("dst_read_public_key: bad return from b64_pton = %d",
- dlen));
- return (NULL);
- }
- /* store key and info in a key structure that is returned */
-/* return dst_store_public_key(in_name, alg, proto, 666, flags, deckey,
- dlen);*/
- return dst_buffer_to_key(in_name, alg, flags, proto, deckey, dlen);
-}
-
-
-/*
- * dst_write_public_key
- * Write a key to disk in DNS format.
- * Parameters
- * key Pointer to a DST key structure.
- * Returns
- * 0 Failure
- * 1 Success
- */
-
-static int
-dst_s_write_public_key(const DST_KEY *key)
-{
- FILE *fp;
- char filename[PATH_MAX];
- u_char out_key[RAW_KEY_SIZE];
- char enc_key[RAW_KEY_SIZE];
- int len = 0;
- int mode;
-
- memset(out_key, 0, sizeof(out_key));
- if (key == NULL) {
- EREPORT(("dst_write_public_key(): No key specified \n"));
- return (0);
- } else if ((len = dst_key_to_dnskey(key, out_key, sizeof(out_key)))< 0)
- return (0);
-
- /* Make the filename */
- if (dst_s_build_filename(filename, key->dk_key_name, key->dk_id,
- key->dk_alg, PUBLIC_KEY, PATH_MAX) == -1) {
- EREPORT(("dst_write_public_key(): Cannot make filename from %s, %d, and %s\n",
- key->dk_key_name, key->dk_id, PUBLIC_KEY));
- return (0);
- }
- /* XXX in general this should be a check for symmetric keys */
- mode = (key->dk_alg == KEY_HMAC_MD5) ? 0600 : 0644;
- /* create public key file */
- if ((fp = dst_s_fopen(filename, "w+", mode)) == NULL) {
- EREPORT(("DST_write_public_key: open of file:%s failed (errno=%d)\n",
- filename, errno));
- return (0);
- }
- /*write out key first base64 the key data */
- if (key->dk_flags & DST_EXTEND_FLAG)
- b64_ntop(&out_key[6], len - 6, enc_key, sizeof(enc_key));
- else
- b64_ntop(&out_key[4], len - 4, enc_key, sizeof(enc_key));
- fprintf(fp, "%s IN KEY %d %d %d %s\n",
- key->dk_key_name,
- key->dk_flags, key->dk_proto, key->dk_alg, enc_key);
- fclose(fp);
- return (1);
-}
-
-
-/*
- * dst_dnskey_to_public_key
- * This function converts the contents of a DNS KEY RR into a DST
- * key structure.
- * Paramters
- * len Length of the RDATA of the KEY RR RDATA
- * rdata A pointer to the the KEY RR RDATA.
- * in_name Key name to be stored in key structure.
- * Returns
- * NULL Failure
- * NON-NULL Success. Pointer to key structure.
- * Caller's responsibility to free() it.
- */
-
-DST_KEY *
-dst_dnskey_to_key(const char *in_name, const u_char *rdata, const int len)
-{
- DST_KEY *key_st;
- int alg ;
- int start = DST_KEY_START;
-
- if (rdata == NULL || len <= DST_KEY_ALG) /* no data */
- return (NULL);
- alg = (u_int8_t) rdata[DST_KEY_ALG];
- if (!dst_check_algorithm(alg)) { /* make sure alg is available */
- EREPORT(("dst_dnskey_to_key(): Algorithm %d not suppored\n",
- alg));
- return (NULL);
- }
- if ((key_st = dst_s_get_key_struct(in_name, alg, 0, 0, 0)) == NULL)
- return (NULL);
-
- if (in_name == NULL)
- return (NULL);
- key_st->dk_id = dst_s_dns_key_id(rdata, len);
- key_st->dk_flags = dst_s_get_int16(rdata);
- key_st->dk_proto = (u_int16_t) rdata[DST_KEY_PROT];
- if (key_st->dk_flags & DST_EXTEND_FLAG) {
- u_int32_t ext_flags;
- ext_flags = (u_int32_t) dst_s_get_int16(&rdata[DST_EXT_FLAG]);
- key_st->dk_flags = key_st->dk_flags | (ext_flags << 16);
- start += 2;
- }
- /*
- * now point to the begining of the data representing the encoding
- * of the key
- */
- if (key_st->dk_func && key_st->dk_func->from_dns_key) {
- if (key_st->dk_func->from_dns_key(key_st, &rdata[start],
- len - start) > 0)
- return (key_st);
- } else
- EREPORT(("dst_dnskey_to_public_key(): unsuppored alg %d\n",
- alg));
-
- SAFE_FREE(key_st);
- return (key_st);
-}
-
-
-/*
- * dst_public_key_to_dnskey
- * Function to encode a public key into DNS KEY wire format
- * Parameters
- * key Key structure to encode.
- * out_storage Location to write the encoded key to.
- * out_len Size of the output array.
- * Returns
- * <0 Failure
- * >=0 Number of bytes written to out_storage
- */
-
-int
-dst_key_to_dnskey(const DST_KEY *key, u_char *out_storage,
- const int out_len)
-{
- u_int16_t val;
- int loc = 0;
- int enc_len = 0;
- if (key == NULL)
- return (-1);
-
- if (!dst_check_algorithm(key->dk_alg)) { /* make sure alg is available */
- EREPORT(("dst_key_to_dnskey(): Algorithm %d not suppored\n",
- key->dk_alg));
- return (UNSUPPORTED_KEYALG);
- }
- memset(out_storage, 0, out_len);
- val = (u_int16_t)(key->dk_flags & 0xffff);
- dst_s_put_int16(out_storage, val);
- loc += 2;
-
- out_storage[loc++] = (u_char) key->dk_proto;
- out_storage[loc++] = (u_char) key->dk_alg;
-
- if (key->dk_flags > 0xffff) { /* Extended flags */
- val = (u_int16_t)((key->dk_flags >> 16) & 0xffff);
- dst_s_put_int16(&out_storage[loc], val);
- loc += 2;
- }
- if (key->dk_KEY_struct == NULL)
- return (loc);
- if (key->dk_func && key->dk_func->to_dns_key) {
- enc_len = key->dk_func->to_dns_key(key,
- (u_char *) &out_storage[loc],
- out_len - loc);
- if (enc_len > 0)
- return (enc_len + loc);
- else
- return (-1);
- } else
- EREPORT(("dst_key_to_dnskey(): Unsupported ALG %d\n",
- key->dk_alg));
- return (-1);
-}
-
-
-/*
- * dst_buffer_to_key
- * Function to encode a string of raw data into a DST key
- * Parameters
- * alg The algorithm (HMAC only)
- * key A pointer to the data
- * keylen The length of the data
- * Returns
- * NULL an error occurred
- * NON-NULL the DST key
- */
-DST_KEY *
-dst_buffer_to_key(const char *key_name, /* name of the key */
- const int alg, /* algorithm */
- const int flags, /* dns flags */
- const int protocol, /* dns protocol */
- const u_char *key_buf, /* key in dns wire fmt */
- const int key_len) /* size of key */
-{
-
- DST_KEY *dkey = NULL;
- int dnslen;
- u_char dns[2048];
-
- if (!dst_check_algorithm(alg)) { /* make sure alg is available */
- EREPORT(("dst_buffer_to_key(): Algorithm %d not suppored\n", alg));
- return (NULL);
- }
-
- dkey = dst_s_get_key_struct(key_name, alg, flags,
- protocol, -1);
-
- if (dkey == NULL)
- return (NULL);
- if (dkey->dk_func == NULL || dkey->dk_func->from_dns_key == NULL)
- return NULL;
-
- if (dkey->dk_func->from_dns_key(dkey, key_buf, key_len) < 0) {
- EREPORT(("dst_buffer_to_key(): dst_buffer_to_hmac failed\n"));
- return (dst_free_key(dkey));
- }
-
- dnslen = dst_key_to_dnskey(dkey, dns, sizeof(dns));
- dkey->dk_id = dst_s_dns_key_id(dns, dnslen);
- return (dkey);
-}
-
-int
-dst_key_to_buffer(DST_KEY *key, u_char *out_buff, int buf_len)
-{
- int len;
- /* this function will extrac the secret of HMAC into a buffer */
- if (key == NULL)
- return (0);
- if (key->dk_func != NULL && key->dk_func->to_dns_key != NULL) {
- len = key->dk_func->to_dns_key(key, out_buff, buf_len);
- if (len < 0)
- return (0);
- return (len);
- }
- return (0);
-}
-
-
-/*
- * dst_s_read_private_key_file
- * Function reads in private key from a file.
- * Fills out the KEY structure.
- * Parameters
- * name Name of the key to be read.
- * pk_key Structure that the key is returned in.
- * in_id Key identifier (tag)
- * Return
- * 1 if everthing works
- * 0 if there is any problem
- */
-
-static int
-dst_s_read_private_key_file(char *name, DST_KEY *pk_key, u_int16_t in_id,
- int in_alg)
-{
- int cnt, alg, len, major, minor, file_major, file_minor;
- int ret, id;
- char filename[PATH_MAX];
- u_char in_buff[RAW_KEY_SIZE], *p;
- FILE *fp;
- int dnslen;
- u_char dns[2048];
-
- if (name == NULL || pk_key == NULL) {
- EREPORT(("dst_read_private_key_file(): No key name given\n"));
- return (0);
- }
- /* Make the filename */
- if (dst_s_build_filename(filename, name, in_id, in_alg, PRIVATE_KEY,
- PATH_MAX) == -1) {
- EREPORT(("dst_read_private_key(): Cannot make filename from %s, %d, and %s\n",
- name, in_id, PRIVATE_KEY));
- return (0);
- }
- /* first check if we can find the key file */
- if ((fp = dst_s_fopen(filename, "r", 0)) == NULL) {
- EREPORT(("dst_s_read_private_key_file: Could not open file %s in directory %s\n",
- filename, dst_path[0] ? dst_path :
- (char *) getcwd(NULL, PATH_MAX - 1)));
- return (0);
- }
- /* now read the header info from the file */
- if ((cnt = fread(in_buff, 1, sizeof(in_buff), fp)) < 5) {
- fclose(fp);
- EREPORT(("dst_s_read_private_key_file: error reading file %s (empty file)\n",
- filename));
- return (0);
- }
- /* decrypt key */
- fclose(fp);
- if (memcmp(in_buff, "Private-key-format: v", 20) != 0)
- goto fail;
- len = cnt;
- p = in_buff;
-
- if (!dst_s_verify_str((const char **) &p, "Private-key-format: v")) {
- EREPORT(("dst_s_read_private_key_file(): Not a Key file/Decrypt failed %s\n", name));
- goto fail;
- }
- /* read in file format */
- sscanf((char *)p, "%d.%d", &file_major, &file_minor);
- sscanf(KEY_FILE_FORMAT, "%d.%d", &major, &minor);
- if (file_major < 1) {
- EREPORT(("dst_s_read_private_key_file(): Unknown keyfile %d.%d version for %s\n",
- file_major, file_minor, name));
- goto fail;
- } else if (file_major > major || file_minor > minor)
- EREPORT((
- "dst_s_read_private_key_file(): Keyfile %s version higher than mine %d.%d MAY FAIL\n",
- name, file_major, file_minor));
-
- while (*p++ != '\n') ; /* skip to end of line */
-
- if (!dst_s_verify_str((const char **) &p, "Algorithm: "))
- goto fail;
-
- if (sscanf((char *)p, "%d", &alg) != 1)
- goto fail;
- while (*p++ != '\n') ; /* skip to end of line */
-
- if (pk_key->dk_key_name && !strcmp(pk_key->dk_key_name, name))
- SAFE_FREE2(pk_key->dk_key_name, strlen(pk_key->dk_key_name));
- pk_key->dk_key_name = (char *) strdup(name);
-
- /* allocate and fill in key structure */
- if (pk_key->dk_func == NULL || pk_key->dk_func->from_file_fmt == NULL)
- goto fail;
-
- ret = pk_key->dk_func->from_file_fmt(pk_key, (char *)p, &in_buff[len] - p);
- if (ret < 0)
- goto fail;
-
- dnslen = dst_key_to_dnskey(pk_key, dns, sizeof(dns));
- id = dst_s_dns_key_id(dns, dnslen);
-
- /* Make sure the actual key tag matches the input tag used in the filename
- */
- if (id != in_id) {
- EREPORT(("dst_s_read_private_key_file(): actual tag of key read %d != input tag used to build filename %d.\n", id, in_id));
- goto fail;
- }
- pk_key->dk_id = (u_int16_t) id;
- pk_key->dk_alg = alg;
- memset(in_buff, 0, cnt);
- return (1);
-
- fail:
- memset(in_buff, 0, cnt);
- return (0);
-}
-
-
-/*
- * dst_generate_key
- * Generate and store a public/private keypair.
- * Keys will be stored in formatted files.
- * Parameters
- * name Name of the new key. Used to create key files
- * K<name>+<alg>+<id>.public and K<name>+<alg>+<id>.private.
- * bits Size of the new key in bits.
- * exp What exponent to use:
- * 0 use exponent 3
- * non-zero use Fermant4
- * flags The default value of the DNS Key flags.
- * The DNS Key RR Flag field is defined in RFC 2065,
- * section 3.3. The field has 16 bits.
- * protocol
- * Default value of the DNS Key protocol field.
- * The DNS Key protocol field is defined in RFC 2065,
- * section 3.4. The field has 8 bits.
- * alg What algorithm to use. Currently defined:
- * KEY_RSA 1
- * KEY_DSA 3
- * KEY_HMAC 157
- * out_id The key tag is returned.
- *
- * Return
- * NULL Failure
- * non-NULL the generated key pair
- * Caller frees the result, and its dk_name pointer.
- */
-DST_KEY *
-dst_generate_key(const char *name, const int bits, const int exp,
- const int flags, const int protocol, const int alg)
-{
- DST_KEY *new_key = NULL;
- int res;
- int dnslen;
- u_char dns[2048];
-
- if (name == NULL)
- return (NULL);
-
- if (!dst_check_algorithm(alg)) { /* make sure alg is available */
- EREPORT(("dst_generate_key(): Algorithm %d not suppored\n", alg));
- return (NULL);
- }
-
- new_key = dst_s_get_key_struct(name, alg, flags, protocol, bits);
- if (new_key == NULL)
- return (NULL);
- if (bits == 0) /* null key we are done */
- return (new_key);
- if (new_key->dk_func == NULL || new_key->dk_func->generate == NULL) {
- EREPORT(("dst_generate_key_pair():Unsupported algorithm %d\n",
- alg));
- return (dst_free_key(new_key));
- }
- if ((res = new_key->dk_func->generate(new_key, exp)) <= 0) {
- EREPORT(("dst_generate_key_pair(): Key generation failure %s %d %d %d\n",
- new_key->dk_key_name, new_key->dk_alg,
- new_key->dk_key_size, exp));
- return (dst_free_key(new_key));
- }
-
- dnslen = dst_key_to_dnskey(new_key, dns, sizeof(dns));
- if (dnslen != UNSUPPORTED_KEYALG)
- new_key->dk_id = dst_s_dns_key_id(dns, dnslen);
- else
- new_key->dk_id = 0;
-
- return (new_key);
-}
-
-
-/*
- * dst_free_key
- * Release all data structures pointed to by a key structure.
- * Parameters
- * f_key Key structure to be freed.
- */
-
-DST_KEY *
-dst_free_key(DST_KEY *f_key)
-{
-
- if (f_key == NULL)
- return (f_key);
- if (f_key->dk_func && f_key->dk_func->destroy)
- f_key->dk_KEY_struct =
- f_key->dk_func->destroy(f_key->dk_KEY_struct);
- else {
- EREPORT(("dst_free_key(): Unknown key alg %d\n",
- f_key->dk_alg));
- free(f_key->dk_KEY_struct); /* SHOULD NOT happen */
- }
- if (f_key->dk_KEY_struct) {
- free(f_key->dk_KEY_struct);
- f_key->dk_KEY_struct = NULL;
- }
- if (f_key->dk_key_name)
- SAFE_FREE(f_key->dk_key_name);
- SAFE_FREE(f_key);
- return (NULL);
-}
-
-/*
- * dst_sig_size
- * Return the maximim size of signature from the key specified in bytes
- * Parameters
- * key
- * Returns
- * bytes
- */
-int
-dst_sig_size(DST_KEY *key) {
- switch (key->dk_alg) {
- case KEY_HMAC_MD5:
- return (16);
- case KEY_HMAC_SHA1:
- return (20);
- case KEY_RSA:
- return (key->dk_key_size + 7) / 8;
- case KEY_DSA:
- return (40);
- default:
- EREPORT(("dst_sig_size(): Unknown key alg %d\n", key->dk_alg));
- return -1;
- }
-}
-
-/*
- * dst_random
- * function that multiplexes number of random number generators
- * Parameters
- * mode: select the random number generator
- * wanted is how many bytes of random data are requested
- * outran is a buffer of size at least wanted for the output data
- *
- * Returns
- * number of bytes written to outran
- */
-int
-dst_random(const int mode, int wanted, u_char *outran)
-{
- u_int32_t *buff = NULL, *bp = NULL;
- int i;
- if (wanted <= 0 || outran == NULL)
- return (0);
-
- switch (mode) {
- case DST_RAND_SEMI:
- bp = buff = (u_int32_t *) malloc(wanted+sizeof(u_int32_t));
- for (i = 0; i < wanted; i+= sizeof(u_int32_t), bp++) {
- *bp = dst_s_quick_random(i);
- }
- memcpy(outran, buff, wanted);
- SAFE_FREE(buff);
- return (wanted);
- case DST_RAND_STD:
- return (dst_s_semi_random(outran, wanted));
- case DST_RAND_KEY:
- return (dst_s_random(outran, wanted));
- case DST_RAND_DSS:
- default:
- /* need error case here XXX OG */
- return (0);
- }
-}
-
diff --git a/contrib/bind/lib/dst/dst_internal.h b/contrib/bind/lib/dst/dst_internal.h
deleted file mode 100644
index 0825109..0000000
--- a/contrib/bind/lib/dst/dst_internal.h
+++ /dev/null
@@ -1,168 +0,0 @@
-#ifndef DST_INTERNAL_H
-#define DST_INTERNAL_H
-
-/*
- * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc.
- *
- * 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 TRUSTED INFORMATION SYSTEMS
- * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
- * TRUSTED INFORMATION SYSTEMS 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 THE SOFTWARE.
- */
-#include <limits.h>
-#include <sys/param.h>
-#if (!defined(BSD)) || (BSD < 199306)
-# include <sys/bitypes.h>
-#else
-# include <sys/types.h>
-#endif
-
-#ifndef PATH_MAX
-# ifdef POSIX_PATH_MAX
-# define PATH_MAX POSIX_PATH_MAX
-# else
-# define PATH_MAX 255 /* this is the value of POSIX_PATH_MAX */
-# endif
-#endif
-
-typedef struct dst_key {
- char *dk_key_name; /* name of the key */
- int dk_key_size; /* this is the size of the key in bits */
- int dk_proto; /* what protocols this key can be used for */
- int dk_alg; /* algorithm number from key record */
- u_int32_t dk_flags; /* and the flags of the public key */
- u_int16_t dk_id; /* identifier of the key */
- void *dk_KEY_struct; /* pointer to key in crypto pkg fmt */
- struct dst_func *dk_func; /* point to cryptto pgk specific function table */
-} DST_KEY;
-#define HAS_DST_KEY
-
-#include <isc/dst.h>
-/*
- * define what crypto systems are supported for RSA,
- * BSAFE is prefered over RSAREF; only one can be set at any time
- */
-#if defined(BSAFE) && defined(RSAREF)
-# error "Cannot have both BSAFE and RSAREF defined"
-#endif
-
-/* Declare dst_lib specific constants */
-#define KEY_FILE_FORMAT "1.2"
-
-/* suffixes for key file names */
-#define PRIVATE_KEY "private"
-#define PUBLIC_KEY "key"
-
-/* error handling */
-#ifdef REPORT_ERRORS
-#define EREPORT(str) printf str
-#else
-#define EREPORT(str) (void)0
-#endif
-
-/* use our own special macro to FRRE memory */
-
-#ifndef SAFE_FREE
-#define SAFE_FREE(a) \
-do{if(a != NULL){memset(a,0, sizeof(*a)); free(a); a=NULL;}} while (0)
-#define SAFE_FREE2(a,s) if (a != NULL && s > 0){memset(a,0, s);free(a); a=NULL;}
-#endif
-
-typedef struct dst_func {
- int (*sign)(const int mode, DST_KEY *key, void **context,
- const u_int8_t *data, const int len,
- u_int8_t *signature, const int sig_len);
- int (*verify)(const int mode, DST_KEY *key, void **context,
- const u_int8_t *data, const int len,
- const u_int8_t *signature, const int sig_len);
- int (*compare)(const DST_KEY *key1, const DST_KEY *key2);
- int (*generate)(DST_KEY *key, int parms);
- void *(*destroy)(void *key);
- /* conversion functions */
- int (*to_dns_key)(const DST_KEY *key, u_int8_t *out,
- const int out_len);
- int (*from_dns_key)(DST_KEY *key, const u_int8_t *str,
- const int str_len);
- int (*to_file_fmt)(const DST_KEY *key, char *out,
- const int out_len);
- int (*from_file_fmt)(DST_KEY *key, const char *out,
- const int out_len);
-
-} dst_func;
-
-extern dst_func *dst_t_func[DST_MAX_ALGS];
-extern const char *key_file_fmt_str;
-extern const char *dst_path;
-
-#ifndef DST_HASH_SIZE
-#define DST_HASH_SIZE 20 /* RIPEMD160 and SHA-1 are 20 bytes MD5 is 16 */
-#endif
-
-int dst_bsafe_init(void);
-
-int dst_rsaref_init(void);
-
-int dst_hmac_md5_init(void);
-
-int dst_cylink_init(void);
-
-int dst_eay_dss_init(void);
-
-/* support functions */
-/* base64 to bignum conversion routines */
-int dst_s_conv_bignum_u8_to_b64( char *out_buf, const int out_len,
- const char *header,
- const u_int8_t *bin_data,
- const int bin_len);
-int dst_s_conv_bignum_b64_to_u8( const char **buf, u_int8_t *loc,
- const int loclen) ;
-/* from higher level support routines */
-int dst_s_calculate_bits( const u_int8_t *str, const int max_bits);
-int dst_s_verify_str( const char **buf, const char *str);
-
-
-/* conversion between dns names and key file names */
-size_t dst_s_filename_length( const char *name, const char *suffix);
-int dst_s_build_filename( char *filename, const char *name,
- u_int16_t id, int alg, const char *suffix,
- size_t filename_length);
-
-FILE *dst_s_fopen (const char *filename, const char *mode, int perm);
-
-/* from file prandom.c */
-int dst_s_random( u_int8_t *output, int size);
-int dst_s_semi_random( u_int8_t *output, int size);
-u_int32_t dst_s_quick_random( int inc);
-void dst_s_quick_random_set( u_int32_t val, u_int32_t cnt);
-
-/*
- * read and write network byte order into u_int?_t
- * all of these should be retired
- */
-u_int16_t dst_s_get_int16( const u_int8_t *buf);
-void dst_s_put_int16( u_int8_t *buf, const u_int16_t val);
-
-u_int32_t dst_s_get_int32( const u_int8_t *buf);
-void dst_s_put_int32( u_int8_t *buf, const u_int32_t val);
-
-#ifdef DUMP
-# undef DUMP
-# define DUMP(a,b,c,d) dst_s_dump(a,b,c,d)
-#else
-# define DUMP(a,b,c,d)
-#endif
-void
-dst_s_dump(const int mode, const u_char *data, const int size,
- const char *msg);
-
-
-
-#endif /* DST_INTERNAL_H */
diff --git a/contrib/bind/lib/dst/eay_dss_link.c b/contrib/bind/lib/dst/eay_dss_link.c
deleted file mode 100644
index b5c7caa..0000000
--- a/contrib/bind/lib/dst/eay_dss_link.c
+++ /dev/null
@@ -1,630 +0,0 @@
-#ifdef EAY_DSS
-static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/eay_dss_link.c,v 1.6 2001/05/29 05:48:09 marka Exp $";
-
-/*
- * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc.
- *
- * 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 TRUSTED INFORMATION SYSTEMS
- * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
- * TRUSTED INFORMATION SYSTEMS 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 THE SOFTWARE.
- */
-/*
- * This file contains two components
- * 1. Interface to the EAY libcrypto library to allow compilation of Bind
- * with TIS/DNSSEC when EAY libcrypto is not available
- * all calls to libcrypto are contained inside this file.
- * 2. The glue to connvert DSA KEYS to and from external formats
- */
-#include "port_before.h"
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <memory.h>
-#include <sys/param.h>
-#include <sys/time.h>
-#include <netinet/in.h>
-
-#include "dst_internal.h"
-
-#include "crypto.h"
-#include "bn.h"
-#include "dsa.h"
-#include "sha.h"
-
-#include "port_after.h"
-
-
-static int dst_eay_dss_sign(const int mode, DST_KEY *dkey, void **context,
- const u_char *data, const int len,
- u_char *signature, const int sig_len);
-
-static int dst_eay_dss_verify(const int mode, DST_KEY *dkey, void **context,
- const u_char *data, const int len,
- const u_char *signature, const int sig_len);
-
-static int dst_eay_dss_to_dns_key(const DST_KEY *in_key, u_char *out_str,
- const int out_len);
-static int dst_eay_dss_from_dns_key(DST_KEY *s_key, const u_char *key,
- const int len);
-static int dst_eay_dss_key_to_file_format(const DST_KEY *key, u_char *buff,
- const int buff_len);
-static int dst_eay_dss_key_from_file_format(DST_KEY *d_key,
- const u_char *buff,
- const int buff_len);
-static void *dst_eay_dss_free_key_structure(void *key);
-
-static int dst_eay_dss_generate_keypair(DST_KEY *key, int exp);
-static int dst_eay_dss_compare_keys(const DST_KEY *key1, const DST_KEY *key2);
-
-/*
- * dst_eay_dss_init() Function to answer set up function pointers for
- * EAY DSS related functions
- */
-int
-dst_eay_dss_init(void)
-{
- if (dst_t_func[KEY_DSA] != NULL)
- return (1);
- dst_t_func[KEY_DSA] = malloc(sizeof(struct dst_func));
- if (dst_t_func[KEY_DSA] == NULL)
- return (0);
- memset(dst_t_func[KEY_DSA], 0, sizeof(struct dst_func));
- dst_t_func[KEY_DSA]->sign = dst_eay_dss_sign;
- dst_t_func[KEY_DSA]->verify = dst_eay_dss_verify;
- dst_t_func[KEY_DSA]->compare = dst_eay_dss_compare_keys;
- dst_t_func[KEY_DSA]->generate = dst_eay_dss_generate_keypair;
- dst_t_func[KEY_DSA]->destroy = dst_eay_dss_free_key_structure;
- dst_t_func[KEY_DSA]->from_dns_key = dst_eay_dss_from_dns_key;
- dst_t_func[KEY_DSA]->to_dns_key = dst_eay_dss_to_dns_key;
- dst_t_func[KEY_DSA]->from_file_fmt = dst_eay_dss_key_from_file_format;
- dst_t_func[KEY_DSA]->to_file_fmt = dst_eay_dss_key_to_file_format;
- return (1);
-}
-
-/*
- * dst_eay_dss_sign
- * Call EAY DSS signing functions to sign a block of data.
- * There are three steps to signing, INIT (initialize structures),
- * UPDATE (hash (more) data), FINAL (generate a signature). This
- * routine performs one or more of these steps.
- * Parameters
- * mode SIG_MODE_INIT, SIG_MODE_UPDATE and/or SIG_MODE_FINAL.
- * algobj structure holds context for a sign done in multiple calls.
- * context the context to use for this computation
- * data data to be signed.
- * len length in bytes of data.
- * priv_key key to use for signing.
- * signature location to store signature.
- * sig_len size in bytes of signature field.
- * returns
- * N Success on SIG_MODE_FINAL = returns signature length in bytes
- * N is 41 for DNS
- * 0 Success on SIG_MODE_INIT and UPDATE
- * <0 Failure
- */
-
-static int
-dst_eay_dss_sign(const int mode, DST_KEY *dkey, void **context,
- const u_char *data, const int len,
- u_char *signature, const int sig_len)
-{
- int sign_len = 0;
- int status;
- SHA_CTX *ctx = NULL;
-
- if (mode & SIG_MODE_INIT)
- ctx = (SHA_CTX *) malloc(sizeof(SHA_CTX));
- else if (context)
- ctx = (SHA_CTX *) *context;
- if (ctx == NULL)
- return (-1);
-
- if (mode & SIG_MODE_INIT)
- SHA1_Init(ctx);
-
- if ((mode & SIG_MODE_UPDATE) && (data && len > 0)) {
- SHA1_Update(ctx, (u_char *) data, len);
- }
- if (mode & SIG_MODE_FINAL) {
- DSA *key;
- u_char digest[SHA_DIGEST_LENGTH];
- u_char rand[SHA_DIGEST_LENGTH];
- u_char r[SHA_DIGEST_LENGTH], s[SHA_DIGEST_LENGTH];
-
- if (dkey == NULL || dkey->dk_KEY_struct == NULL)
- return (-1);
- key = dkey->dk_KEY_struct;
- if (key == NULL)
- return(-2);
- SHA1_Final(digest, ctx);
- status = DSA_sign(0, digest, SHA_DIGEST_LENGTH,
- signature, &sign_len, key);
- if (status != 0)
- return (SIGN_FINAL_FAILURE);
-
- *signature = (dkey->dk_key_size - 512)/64;
- sign_len = 1;
- memcpy(signature + sign_len, r, SHA_DIGEST_LENGTH);
- sign_len += SHA_DIGEST_LENGTH;
- memcpy(signature + sign_len, s, SHA_DIGEST_LENGTH);
- sign_len += SHA_DIGEST_LENGTH;
- }
- else {
- if (context == NULL)
- return (-1);
- *context = (void *) ctx;
- }
- return (sign_len);
-}
-
-
-/*
- * dst_eay_dss_verify
- * Calls EAY DSS verification routines. There are three steps to
- * verification, INIT (initialize structures), UPDATE (hash (more) data),
- * FINAL (generate a signature). This routine performs one or more of
- * these steps.
- * Parameters
- * mode SIG_MODE_INIT, SIG_MODE_UPDATE and/or SIG_MODE_FINAL.
- * dkey structure holds context for a verify done in multiple calls.
- * context algorithm specific context for the current context processing
- * data data signed.
- * len length in bytes of data.
- * pub_key key to use for verify.
- * signature signature.
- * sig_len length in bytes of signature.
- * returns
- * 0 Success
- * <0 Failure
- */
-
-static int
-dst_eay_dss_verify(const int mode, DST_KEY *dkey, void **context,
- const u_char *data, const int len,
- const u_char *signature, const int sig_len)
-{
- int status;
- SHA_CTX *ctx = NULL;
-
- if (mode & SIG_MODE_INIT)
- ctx = (SHA_CTX *) malloc(sizeof(SHA_CTX));
- else if (context)
- ctx = (SHA_CTX *) *context;
- if (ctx == NULL)
- return (-1);
-
- if (mode & SIG_MODE_INIT)
- SHA1_Init(ctx);
-
- if ((mode & SIG_MODE_UPDATE) && (data && len > 0)) {
- SHA1_Update(ctx, (u_char *) data, len);
- }
- if (mode & SIG_MODE_FINAL) {
- DSA *key;
- u_char digest[SHA_DIGEST_LENGTH];
- u_char r[SHA_DIGEST_LENGTH], s[SHA_DIGEST_LENGTH];
-
- if (dkey == NULL || dkey->dk_KEY_struct == NULL)
- return (-1);
- key = (DSA *) dkey->dk_KEY_struct;
- if (key = NULL)
- return (-2);
- if (signature == NULL || sig_len != (2 * SHA_DIGEST_LENGTH +1))
- return (SIGN_FINAL_FAILURE);
- SHA1_Final(digest, ctx);
- SAFE_FREE(ctx);
- if (status != 0)
- return (SIGN_FINAL_FAILURE);
- if (((int)*signature) != ((BN_num_bytes(key->p) -64)/8))
- return(VERIFY_FINAL_FAILURE);
-
- memcpy(r, signature +1, SHA_DIGEST_LENGTH);
- memcpy(s, signature + SHA_DIGEST_LENGTH +1, SHA_DIGEST_LENGTH);
- status = DSA_verify(0, digest, SHA_DIGEST_LENGTH,
- (u_char *)signature, sig_len, key);
- if (status != 0)
- return (VERIFY_FINAL_FAILURE);
- }
- else {
- if (context == NULL)
- return (-1);
- *context = (void *) ctx;
- }
- return (0);
-}
-
-
-/*
- * dst_eay_dss_to_dns_key
- * Converts key from DSA to DNS distribution format
- * This function gets in a pointer to the public key and a work area
- * to write the key into.
- * Parameters
- * public KEY structure
- * out_str buffer to write encoded key into
- * out_len size of out_str
- * Return
- * N >= 0 length of encoded key
- * n < 0 error
- */
-
-static int
-dst_eay_dss_to_dns_key(const DST_KEY *in_key, u_char *out_str,
- const int out_len)
-{
- u_char *op = out_str;
- int t;
- DSA *key;
-
- if (in_key == NULL || in_key->dk_KEY_struct == NULL ||
- out_len <= 0 || out_str == NULL)
- return (-1);
- key = (DSA *) in_key->dk_KEY_struct;
-
- t = (BN_num_bytes(key->p) - 64) / 8;
-
- *op++ = t;
- BN_bn2bin(key->q, op);
- op += BN_num_bytes(key->q);
- BN_bn2bin(key->p, op);
- op += BN_num_bytes(key->p);
- BN_bn2bin(key->g, op);
- op += BN_num_bytes(key->g);
- BN_bn2bin(key->pub_key, op);
- op += BN_num_bytes(key->pub_key);
-
- return (op - out_str);
-}
-
-
-/*
- * dst_eay_dss_from_dns_key
- * Converts from a DNS KEY RR format to an RSA KEY.
- * Parameters
- * len Length in bytes of DNS key
- * key DNS key
- * name Key name
- * s_key DST structure that will point to the RSA key this routine
- * will build.
- * Return
- * 0 The input key, s_key or name was null.
- * 1 Success
- */
-static int
-dst_eay_dss_from_dns_key(DST_KEY *s_key, const u_char *key, const int len)
-{
- int t;
- u_char *key_ptr = (u_char *)key;
- DSA *d_key;
- int p_bytes;
-
- if (s_key == NULL || len < 0 || key == NULL)
- return (0);
-
- if (len == 0) /* process null key */
- return (1);
-
- if (key_ptr == NULL)
- return (0);
- t = (int) *key_ptr++; /* length of exponent in bytes */
- p_bytes = 64 + 8 * t;
-
- if ((3 * (t * 8 + 64) + SHA_DIGEST_LENGTH + 1) != len)
- return (0);
-
- if ((d_key = (DSA *) malloc(sizeof(DSA))) == NULL) {
- EREPORT(("dst_eay_dss_from_dns_key(): Memory allocation error 1"));
- return (0);
- }
- memset(d_key, 0, sizeof(DSA));
- s_key->dk_KEY_struct = (void *) d_key;
-
- d_key->q = BN_bin2bn(key_ptr, SHA_DIGEST_LENGTH, NULL);
- key_ptr += SHA_DIGEST_LENGTH;
-
- d_key->p = BN_bin2bn(key_ptr, p_bytes, NULL);
- key_ptr += p_bytes;
-
- d_key->g = BN_bin2bn(key_ptr, p_bytes, NULL);
- key_ptr += p_bytes;
-
- d_key->pub_key = BN_bin2bn(key_ptr, p_bytes, NULL);
- key_ptr += p_bytes;
-
- s_key->dk_key_size = p_bytes * 8;
- return (1);
-}
-
-
-/**************************************************************************
- * dst_eay_dss_key_to_file_format
- * Encodes an DSA Key into the portable file format.
- * Parameters
- * key DSA KEY structure
- * buff output buffer
- * buff_len size of output buffer
- * Return
- * 0 Failure - null input rkey
- * -1 Failure - not enough space in output area
- * N Success - Length of data returned in buff
- */
-
-static int
-dst_eay_dss_key_to_file_format(const DST_KEY *key, u_char *buff,
- const int buff_len)
-{
- u_char *bp;
- int len, b_len;
- DSA *dkey;
- char num[256]; /* More than long enough for DSA keys */
-
- if (key == NULL || key->dk_KEY_struct == NULL) /* no output */
- return (0);
- if (buff == NULL || buff_len <= (int) strlen(key_file_fmt_str))
- return (-1); /* no OR not enough space in output area */
-
- dkey = (DSA *) key->dk_KEY_struct;
-
- memset(buff, 0, buff_len); /* just in case */
- /* write file header */
- sprintf(buff, key_file_fmt_str, KEY_FILE_FORMAT, KEY_DSA, "DSA");
-
- bp = (char *) strchr(buff, '\0');
- b_len = buff_len - (bp - buff);
- memcpy(num, dkey->p, BN_num_bytes(dkey->p));
- if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Prime(p): ", num,
- BN_num_bytes(dkey->p))) <= 0)
- return (-1);
-
- bp = (char *) strchr(buff, '\0');
- b_len = buff_len - (bp - buff);
- memcpy(num, dkey->q, BN_num_bytes(dkey->q));
- if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Subprime(q): ", num,
- BN_num_bytes(dkey->q))) <= 0)
- return (-2);
-
- bp = (char *) strchr(buff, '\0');
- b_len = buff_len - (bp - buff);
- memcpy(num, dkey->g, BN_num_bytes(dkey->g));
- if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Base(g): ", num,
- BN_num_bytes(dkey->g))) <= 0)
- return (-3);
-
- bp = (char *) strchr(buff, '\0');
- b_len = buff_len - (bp - buff);
- memcpy(num, dkey->priv_key, BN_num_bytes(dkey->priv_key));
- if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Private_value(x): ",
- num,
- BN_num_bytes(dkey->priv_key)))
- <= 0)
- return (-4);
-
- bp = (char *) strchr(buff, '\0');
- b_len = buff_len - (bp - buff);
- memcpy(num, dkey->pub_key, BN_num_bytes(dkey->pub_key));
- if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Public_value(y): ",
- num,
- BN_num_bytes(dkey->pub_key)))
- <= 0)
- return (-5);
-
- bp += len;
- b_len -= len;
- return (buff_len - b_len);
-}
-
-
-/**************************************************************************
- * dst_eay_dss_key_from_file_format
- * Converts contents of a private key file into a private DSA key.
- * Parameters
- * d_key structure to put key into
- * buff buffer containing the encoded key
- * buff_len the length of the buffer
- * Return
- * n >= 0 Foot print of the key converted
- * n < 0 Error in conversion
- */
-
-static int
-dst_eay_dss_key_from_file_format(DST_KEY *d_key, const u_char *buff,
- const int buff_len)
-{
- char s[128];
- int len, s_len = sizeof(s);
- const char *p = buff;
- DSA *dsa_key;
-
- if (d_key == NULL || buff == NULL || buff_len <= 0)
- return (-1);
-
- dsa_key = (DSA *) malloc(sizeof(DSA));
- if (dsa_key == NULL) {
- return (-2);
- }
- memset(dsa_key, 0, sizeof(*dsa_key));
- d_key->dk_KEY_struct = (void *) dsa_key;
-
- if (!dst_s_verify_str(&p, "Prime(p): "))
- return (-3);
- memset(s, 0, s_len);
- if ((len = dst_s_conv_bignum_b64_to_u8(&p, s, s_len)) == 0)
- return (-4);
- dsa_key->p = BN_bin2bn (s, len, NULL);
- if (dsa_key->p == NULL)
- return(-5);
-
- while (*++p && p < (const char *) &buff[buff_len]) {
- if (dst_s_verify_str(&p, "Subprime(q): ")) {
- if (!(len = dst_s_conv_bignum_b64_to_u8(&p, s, s_len)))
- return (-6);
- dsa_key->q = BN_bin2bn (s, len, NULL);
- if (dsa_key->q == NULL)
- return (-7);
- } else if (dst_s_verify_str(&p, "Base(g): ")) {
- if (!(len = dst_s_conv_bignum_b64_to_u8(&p, s, s_len)))
- return (-8);
- dsa_key->g = BN_bin2bn (s, len, NULL);
- if (dsa_key->g == NULL)
- return (-9);
- } else if (dst_s_verify_str(&p, "Private_value(x): ")) {
- if (!(len = dst_s_conv_bignum_b64_to_u8(&p, s, s_len)))
- return (-10);
- dsa_key->priv_key = BN_bin2bn (s, len, NULL);
- if (dsa_key->priv_key == NULL)
- return (-11);
- } else if (dst_s_verify_str(&p, "Public_value(y): ")) {
- if (!(len = dst_s_conv_bignum_b64_to_u8(&p, s, s_len)))
- return (-12);
- dsa_key->pub_key = BN_bin2bn (s, len, NULL);
- if (dsa_key->pub_key == NULL)
- return (-13);
- } else {
- EREPORT(("Decode_DSAKey(): Bad keyword %s\n", p));
- return (-14);
- }
- } /* while p */
-
- d_key->dk_key_size = BN_num_bytes(dsa_key->p);
-
- return (0);
-}
-
-
-/**************************************************************************
- * dst_eay_dss_free_key_structure
- * Frees all dynamicly allocated structures in DSA.
- */
-
-static void *
-dst_eay_dss_free_key_structure(void *key)
-{
- DSA *d_key = (DSA *) key;
- if (d_key != NULL) {
- BN_free(d_key->p);
- BN_free(d_key->q);
- BN_free(d_key->g);
- if (d_key->pub_key)
- BN_free(d_key->pub_key);
- if (d_key->priv_key)
- BN_free(d_key->priv_key);
- SAFE_FREE(d_key);
- }
- return (NULL);
-}
-
-
-/**************************************************************************
- * dst_eay_dss_generate_keypair
- * Generates unique keys that are hard to predict.
- * Parameters
- * key generic Key structure
- * exp the public exponent
- * Return
- * 0 Failure
- * 1 Success
- */
-
-static int
-dst_eay_dss_generate_keypair(DST_KEY *key, int nothing)
-{
- int status, n;
- DSA *dsa;
- u_char rand[SHA_DIGEST_LENGTH];
-
- if (key == NULL || key->dk_alg != KEY_DSA)
- return (0);
-
- if ((dsa = (DSA *) malloc(sizeof(DSA))) == NULL) {
- EREPORT(("dst_eay_dss_generate_keypair: Memory allocation error 3"));
- return (0);
- }
- memset(dsa, 0, sizeof(*dsa));
-
- n = dst_random(DST_RAND_KEY, sizeof(rand), rand);
- if (n != sizeof(rand))
- return (0);
- dsa = DSA_generate_parameters(key->dk_key_size, rand, 20, NULL, NULL,
- NULL, NULL);
-
- if (!dsa) {
- EREPORT(("dst_eay_dss_generate_keypair: Generate Parameters failed"));
- return (0);
- }
- if (DSA_generate_key(dsa) == 0) {
- EREPORT(("dst_eay_dss_generate_keypair: Generate Key failed"));
- return(0);
- }
- key->dk_KEY_struct = (void *) dsa;
- return (1);
-}
-
-
-/*
- * dst_eay_dss_compare_keys
- * Compare two keys for equality.
- * Return
- * 0 The keys are equal
- * NON-ZERO The keys are not equal
- */
-
-static int
-dst_eay_dss_compare_keys(const DST_KEY *key1, const DST_KEY *key2)
-{
- int status;
- DSA *dkey1 = (DSA *) key1->dk_KEY_struct;
- DSA *dkey2 = (DSA *) key2->dk_KEY_struct;
-
- if (dkey1 == NULL && dkey2 == NULL)
- return (0);
- else if (dkey1 == NULL)
- return (2);
- else if (dkey2 == NULL)
- return(1);
-
- status = BN_cmp(dkey1->p, dkey2->p) ||
- BN_cmp(dkey1->q, dkey2->q) ||
- BN_cmp(dkey1->g, dkey2->g) ||
- BN_cmp(dkey1->pub_key, dkey2->pub_key);
-
- if (status)
- return (status);
-
- if (dkey1->priv_key || dkey2->priv_key) {
- if (dkey1->priv_key == NULL || dkey2->priv_key == NULL)
- return (202);
- return (BN_cmp(dkey1->priv_key, dkey2->priv_key));
- } else
- return (0);
-}
-#else
-#include "port_before.h"
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <memory.h>
-#include <sys/param.h>
-#include <sys/time.h>
-#include <netinet/in.h>
-
-#include "dst_internal.h"
-#include "port_after.h"
-int
-dst_eay_dss_init(void)
-{
- return (0);
-}
-#endif /* EAY_DSS */
diff --git a/contrib/bind/lib/dst/hmac_link.c b/contrib/bind/lib/dst/hmac_link.c
deleted file mode 100644
index b689524..0000000
--- a/contrib/bind/lib/dst/hmac_link.c
+++ /dev/null
@@ -1,490 +0,0 @@
-#ifdef HMAC_MD5
-#ifndef LINT
-static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/hmac_link.c,v 1.10 2002/12/03 05:26:49 marka Exp $";
-#endif
-/*
- * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc.
- *
- * 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 TRUSTED INFORMATION SYSTEMS
- * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
- * TRUSTED INFORMATION SYSTEMS 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 THE SOFTWARE.
- */
-
-/*
- * This file contains an implementation of the HMAC-MD5 algorithm.
- */
-#include "port_before.h"
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <memory.h>
-#include <sys/param.h>
-#include <sys/time.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-
-#include "dst_internal.h"
-#ifdef USE_MD5
-# include "md5.h"
-# ifndef _MD5_H_
-# define _MD5_H_ 1 /* make sure we do not include rsaref md5.h file */
-# endif
-#endif
-
-#include "port_after.h"
-
-
-#define HMAC_LEN 64
-#define HMAC_IPAD 0x36
-#define HMAC_OPAD 0x5c
-#define MD5_LEN 16
-
-
-typedef struct hmackey {
- u_char hk_ipad[64], hk_opad[64];
-} HMAC_Key;
-
-
-/**************************************************************************
- * dst_hmac_md5_sign
- * Call HMAC signing functions to sign a block of data.
- * There are three steps to signing, INIT (initialize structures),
- * UPDATE (hash (more) data), FINAL (generate a signature). This
- * routine performs one or more of these steps.
- * Parameters
- * mode SIG_MODE_INIT, SIG_MODE_UPDATE and/or SIG_MODE_FINAL.
- * priv_key key to use for signing.
- * context the context to be used in this digest
- * data data to be signed.
- * len length in bytes of data.
- * signature location to store signature.
- * sig_len size of the signature location
- * returns
- * N Success on SIG_MODE_FINAL = returns signature length in bytes
- * 0 Success on SIG_MODE_INIT and UPDATE
- * <0 Failure
- */
-
-static int
-dst_hmac_md5_sign(const int mode, DST_KEY *d_key, void **context,
- const u_char *data, const int len,
- u_char *signature, const int sig_len)
-{
- HMAC_Key *key;
- int sign_len = 0;
- MD5_CTX *ctx = NULL;
-
- if (mode & SIG_MODE_INIT)
- ctx = (MD5_CTX *) malloc(sizeof(*ctx));
- else if (context)
- ctx = (MD5_CTX *) *context;
- if (ctx == NULL)
- return (-1);
-
- if (d_key == NULL || d_key->dk_KEY_struct == NULL)
- return (-1);
- key = (HMAC_Key *) d_key->dk_KEY_struct;
-
- if (mode & SIG_MODE_INIT) {
- MD5Init(ctx);
- MD5Update(ctx, key->hk_ipad, HMAC_LEN);
- }
-
- if ((mode & SIG_MODE_UPDATE) && (data && len > 0))
- MD5Update(ctx, data, len);
-
- if (mode & SIG_MODE_FINAL) {
- if (signature == NULL || sig_len < MD5_LEN)
- return (SIGN_FINAL_FAILURE);
- MD5Final(signature, ctx);
-
- /* perform outer MD5 */
- MD5Init(ctx);
- MD5Update(ctx, key->hk_opad, HMAC_LEN);
- MD5Update(ctx, signature, MD5_LEN);
- MD5Final(signature, ctx);
- sign_len = MD5_LEN;
- SAFE_FREE(ctx);
- }
- else {
- if (context == NULL)
- return (-1);
- *context = (void *) ctx;
- }
- return (sign_len);
-}
-
-
-/**************************************************************************
- * dst_hmac_md5_verify()
- * Calls HMAC verification routines. There are three steps to
- * verification, INIT (initialize structures), UPDATE (hash (more) data),
- * FINAL (generate a signature). This routine performs one or more of
- * these steps.
- * Parameters
- * mode SIG_MODE_INIT, SIG_MODE_UPDATE and/or SIG_MODE_FINAL.
- * dkey key to use for verify.
- * data data signed.
- * len length in bytes of data.
- * signature signature.
- * sig_len length in bytes of signature.
- * returns
- * 0 Success
- * <0 Failure
- */
-
-static int
-dst_hmac_md5_verify(const int mode, DST_KEY *d_key, void **context,
- const u_char *data, const int len,
- const u_char *signature, const int sig_len)
-{
- HMAC_Key *key;
- MD5_CTX *ctx = NULL;
-
- if (mode & SIG_MODE_INIT)
- ctx = (MD5_CTX *) malloc(sizeof(*ctx));
- else if (context)
- ctx = (MD5_CTX *) *context;
- if (ctx == NULL)
- return (-1);
-
- if (d_key == NULL || d_key->dk_KEY_struct == NULL)
- return (-1);
-
- key = (HMAC_Key *) d_key->dk_KEY_struct;
- if (mode & SIG_MODE_INIT) {
- MD5Init(ctx);
- MD5Update(ctx, key->hk_ipad, HMAC_LEN);
- }
- if ((mode & SIG_MODE_UPDATE) && (data && len > 0))
- MD5Update(ctx, data, len);
-
- if (mode & SIG_MODE_FINAL) {
- u_char digest[MD5_LEN];
- if (signature == NULL || key == NULL || sig_len != MD5_LEN)
- return (VERIFY_FINAL_FAILURE);
- MD5Final(digest, ctx);
-
- /* perform outer MD5 */
- MD5Init(ctx);
- MD5Update(ctx, key->hk_opad, HMAC_LEN);
- MD5Update(ctx, digest, MD5_LEN);
- MD5Final(digest, ctx);
-
- SAFE_FREE(ctx);
- if (memcmp(digest, signature, MD5_LEN) != 0)
- return (VERIFY_FINAL_FAILURE);
- }
- else {
- if (context == NULL)
- return (-1);
- *context = (void *) ctx;
- }
- return (0);
-}
-
-
-/**************************************************************************
- * dst_buffer_to_hmac_md5
- * Converts key from raw data to an HMAC Key
- * This function gets in a pointer to the data
- * Parameters
- * hkey the HMAC key to be filled in
- * key the key in raw format
- * keylen the length of the key
- * Return
- * 0 Success
- * <0 Failure
- */
-static int
-dst_buffer_to_hmac_md5(DST_KEY *dkey, const u_char *key, const int keylen)
-{
- int i;
- HMAC_Key *hkey = NULL;
- MD5_CTX ctx;
- int local_keylen = keylen;
-
- if (dkey == NULL || key == NULL || keylen < 0)
- return (-1);
-
- if ((hkey = (HMAC_Key *) malloc(sizeof(HMAC_Key))) == NULL)
- return (-2);
-
- memset(hkey->hk_ipad, 0, sizeof(hkey->hk_ipad));
- memset(hkey->hk_opad, 0, sizeof(hkey->hk_opad));
-
- /* if key is longer than HMAC_LEN bytes reset it to key=MD5(key) */
- if (keylen > HMAC_LEN) {
- u_char tk[MD5_LEN];
- MD5Init(&ctx);
- MD5Update(&ctx, key, keylen);
- MD5Final(tk, &ctx);
- memset((void *) &ctx, 0, sizeof(ctx));
- key = tk;
- local_keylen = MD5_LEN;
- }
- /* start out by storing key in pads */
- memcpy(hkey->hk_ipad, key, local_keylen);
- memcpy(hkey->hk_opad, key, local_keylen);
-
- /* XOR key with hk_ipad and opad values */
- for (i = 0; i < HMAC_LEN; i++) {
- hkey->hk_ipad[i] ^= HMAC_IPAD;
- hkey->hk_opad[i] ^= HMAC_OPAD;
- }
- dkey->dk_key_size = local_keylen;
- dkey->dk_KEY_struct = (void *) hkey;
- return (1);
-}
-
-
-/**************************************************************************
- * dst_hmac_md5_key_to_file_format
- * Encodes an HMAC Key into the portable file format.
- * Parameters
- * hkey HMAC KEY structure
- * buff output buffer
- * buff_len size of output buffer
- * Return
- * 0 Failure - null input hkey
- * -1 Failure - not enough space in output area
- * N Success - Length of data returned in buff
- */
-
-static int
-dst_hmac_md5_key_to_file_format(const DST_KEY *dkey, char *buff,
- const int buff_len)
-{
- char *bp;
- int len, b_len, i, key_len;
- u_char key[HMAC_LEN];
- HMAC_Key *hkey;
-
- if (dkey == NULL || dkey->dk_KEY_struct == NULL)
- return (0);
- if (buff == NULL || buff_len <= (int) strlen(key_file_fmt_str))
- return (-1); /* no OR not enough space in output area */
-
- hkey = (HMAC_Key *) dkey->dk_KEY_struct;
- memset(buff, 0, buff_len); /* just in case */
- /* write file header */
- sprintf(buff, key_file_fmt_str, KEY_FILE_FORMAT, KEY_HMAC_MD5, "HMAC");
-
- bp = (char *) strchr(buff, '\0');
- b_len = buff_len - (bp - buff);
-
- memset(key, 0, HMAC_LEN);
- for (i = 0; i < HMAC_LEN; i++)
- key[i] = hkey->hk_ipad[i] ^ HMAC_IPAD;
- for (i = HMAC_LEN - 1; i >= 0; i--)
- if (key[i] != 0)
- break;
- key_len = i + 1;
-
- strcat(bp, "Key: ");
- bp += strlen("Key: ");
- b_len = buff_len - (bp - buff);
-
- len = b64_ntop(key, key_len, bp, b_len);
- if (len < 0)
- return (-1);
- bp += len;
- *(bp++) = '\n';
- *bp = '\0';
- b_len = buff_len - (bp - buff);
-
- return (buff_len - b_len);
-}
-
-
-/**************************************************************************
- * dst_hmac_md5_key_from_file_format
- * Converts contents of a key file into an HMAC key.
- * Parameters
- * hkey structure to put key into
- * buff buffer containing the encoded key
- * buff_len the length of the buffer
- * Return
- * n >= 0 Foot print of the key converted
- * n < 0 Error in conversion
- */
-
-static int
-dst_hmac_md5_key_from_file_format(DST_KEY *dkey, const char *buff,
- const int buff_len)
-{
- const char *p = buff, *eol;
- u_char key[HMAC_LEN+1]; /* b64_pton needs more than 64 bytes do decode
- * it should probably be fixed rather than doing
- * this
- */
- u_char *tmp;
- int key_len, len;
-
- if (dkey == NULL)
- return (-2);
- if (buff == NULL || buff_len < 0)
- return (-1);
-
- memset(key, 0, sizeof(key));
-
- if (!dst_s_verify_str(&p, "Key: "))
- return (-3);
-
- eol = strchr(p, '\n');
- if (eol == NULL)
- return (-4);
- len = eol - p;
- tmp = malloc(len + 2);
- memcpy(tmp, p, len);
- *(tmp + len) = 0x0;
- key_len = b64_pton((char *)tmp, key, HMAC_LEN+1); /* see above */
- SAFE_FREE2(tmp, len + 2);
-
- if (dst_buffer_to_hmac_md5(dkey, key, key_len) < 0) {
- return (-6);
- }
- return (0);
-}
-
-/*
- * dst_hmac_md5_to_dns_key()
- * function to extract hmac key from DST_KEY structure
- * intput:
- * in_key: HMAC-MD5 key
- * output:
- * out_str: buffer to write ot
- * out_len: size of output buffer
- * returns:
- * number of bytes written to output buffer
- */
-static int
-dst_hmac_md5_to_dns_key(const DST_KEY *in_key, u_char *out_str,
- const int out_len)
-{
-
- HMAC_Key *hkey;
- int i;
-
- if (in_key == NULL || in_key->dk_KEY_struct == NULL ||
- out_len <= in_key->dk_key_size || out_str == NULL)
- return (-1);
-
- hkey = (HMAC_Key *) in_key->dk_KEY_struct;
- for (i = 0; i < in_key->dk_key_size; i++)
- out_str[i] = hkey->hk_ipad[i] ^ HMAC_IPAD;
- return (i);
-}
-
-/**************************************************************************
- * dst_hmac_md5_compare_keys
- * Compare two keys for equality.
- * Return
- * 0 The keys are equal
- * NON-ZERO The keys are not equal
- */
-
-static int
-dst_hmac_md5_compare_keys(const DST_KEY *key1, const DST_KEY *key2)
-{
- HMAC_Key *hkey1 = (HMAC_Key *) key1->dk_KEY_struct;
- HMAC_Key *hkey2 = (HMAC_Key *) key2->dk_KEY_struct;
- return memcmp(hkey1->hk_ipad, hkey2->hk_ipad, HMAC_LEN);
-}
-
-/**************************************************************************
- * dst_hmac_md5_free_key_structure
- * Frees all (none) dynamically allocated structures in hkey
- */
-
-static void *
-dst_hmac_md5_free_key_structure(void *key)
-{
- HMAC_Key *hkey = key;
- SAFE_FREE(hkey);
- return (NULL);
-}
-
-
-/***************************************************************************
- * dst_hmac_md5_generate_key
- * Creates a HMAC key of size size with a maximum size of 63 bytes
- * generating a HMAC key larger than 63 bytes makes no sense as that key
- * is digested before use.
- */
-
-static int
-dst_hmac_md5_generate_key(DST_KEY *key, const int nothing)
-{
- u_char *buff;
- int i, n, size;
-
- i = nothing;
-
- if (key == NULL || key->dk_alg != KEY_HMAC_MD5)
- return (0);
- size = (key->dk_key_size + 7) / 8; /* convert to bytes */
- if (size <= 0)
- return(0);
-
- i = size > 64 ? 64 : size;
- buff = malloc(i+8);
-
- n = dst_random(DST_RAND_SEMI, i, buff);
- n += dst_random(DST_RAND_KEY, i, buff);
- if (n <= i) { /* failed getting anything */
- SAFE_FREE2(buff, i);
- return (-1);
- }
- n = dst_buffer_to_hmac_md5(key, buff, i);
- SAFE_FREE2(buff, i);
- if (n <= 0)
- return (n);
- return (1);
-}
-
-/*
- * dst_hmac_md5_init() Function to answer set up function pointers for HMAC
- * related functions
- */
-int
-dst_hmac_md5_init()
-{
- if (dst_t_func[KEY_HMAC_MD5] != NULL)
- return (1);
- dst_t_func[KEY_HMAC_MD5] = malloc(sizeof(struct dst_func));
- if (dst_t_func[KEY_HMAC_MD5] == NULL)
- return (0);
- memset(dst_t_func[KEY_HMAC_MD5], 0, sizeof(struct dst_func));
- dst_t_func[KEY_HMAC_MD5]->sign = dst_hmac_md5_sign;
- dst_t_func[KEY_HMAC_MD5]->verify = dst_hmac_md5_verify;
- dst_t_func[KEY_HMAC_MD5]->compare = dst_hmac_md5_compare_keys;
- dst_t_func[KEY_HMAC_MD5]->generate = dst_hmac_md5_generate_key;
- dst_t_func[KEY_HMAC_MD5]->destroy = dst_hmac_md5_free_key_structure;
- dst_t_func[KEY_HMAC_MD5]->to_dns_key = dst_hmac_md5_to_dns_key;
- dst_t_func[KEY_HMAC_MD5]->from_dns_key = dst_buffer_to_hmac_md5;
- dst_t_func[KEY_HMAC_MD5]->to_file_fmt = dst_hmac_md5_key_to_file_format;
- dst_t_func[KEY_HMAC_MD5]->from_file_fmt = dst_hmac_md5_key_from_file_format;
- return (1);
-}
-
-#else
-#define dst_hmac_md5_init __dst_hmac_md5_init
-
-int
-dst_hmac_md5_init(){
- return (0);
-}
-#endif
diff --git a/contrib/bind/lib/dst/md5.h b/contrib/bind/lib/dst/md5.h
deleted file mode 100644
index c886d17..0000000
--- a/contrib/bind/lib/dst/md5.h
+++ /dev/null
@@ -1,101 +0,0 @@
-/* crypto/md/md5.h */
-/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- *
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to. The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code. The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- *
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- *
- * 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 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 cryptographic software written by
- * Eric Young (eay@cryptsoft.com)"
- * The word 'cryptographic' can be left out if the rouines from the library
- * being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from
- * the apps directory (application code) you must include an acknowledgement:
- * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- *
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``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 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 licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed. i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-
-#ifndef HEADER_MD5_H
-#define HEADER_MD5_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define MD5_CBLOCK 64
-#define MD5_LBLOCK 16
-#define MD5_BLOCK 16
-#define MD5_LAST_BLOCK 56
-#define MD5_LENGTH_BLOCK 8
-#define MD5_DIGEST_LENGTH 16
-
-typedef struct MD5state_st
- {
- unsigned long A,B,C,D;
- unsigned long Nl,Nh;
- unsigned long data[MD5_LBLOCK];
- int num;
- } MD5_CTX;
-
-#ifndef NOPROTO
-void MD5_Init(MD5_CTX *c);
-void MD5_Update(MD5_CTX *c, const unsigned char *data, unsigned long len);
-void MD5_Final(unsigned char *md, MD5_CTX *c);
-unsigned char *MD5(unsigned char *d, unsigned long n, unsigned char *md);
-#else
-void MD5_Init();
-void MD5_Update();
-void MD5_Final();
-unsigned char *MD5();
-#endif
-
-/* to provide backward compatabilty to RSAREF calls ogud@tis.com 1997/11/14 */
-#define MD5Init(c) MD5_Init(c)
-#define MD5Update(c,data, len) MD5_Update(c,data,len)
-#define MD5Final(md, c) MD5_Final(md, c)
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/contrib/bind/lib/dst/md5_dgst.c b/contrib/bind/lib/dst/md5_dgst.c
deleted file mode 100644
index 78882d1..0000000
--- a/contrib/bind/lib/dst/md5_dgst.c
+++ /dev/null
@@ -1,370 +0,0 @@
-/* crypto/md/md5_dgst.c */
-/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- *
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to. The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code. The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- *
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- *
- * 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 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 cryptographic software written by
- * Eric Young (eay@cryptsoft.com)"
- * The word 'cryptographic' can be left out if the rouines from the library
- * being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from
- * the apps directory (application code) you must include an acknowledgement:
- * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- *
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``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 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 licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed. i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-
-#ifdef USE_MD5 /* Added by ogud@tis.com 1998/1/26 */
-#include <port_before.h>
-#include <stdio.h>
-#include "md5_locl.h"
-#include <port_after.h>
-
-const char *MD5_version="MD5 part of SSLeay 0.8.1 19-Jul-1997";
-
-/* Implemented from RFC1321 The MD5 Message-Digest Algorithm
- */
-
-#define INIT_DATA_A (unsigned long)0x67452301L
-#define INIT_DATA_B (unsigned long)0xefcdab89L
-#define INIT_DATA_C (unsigned long)0x98badcfeL
-#define INIT_DATA_D (unsigned long)0x10325476L
-
-#ifndef NOPROTO
-static void md5_block(MD5_CTX *c, unsigned long *p);
-#else
-static void md5_block();
-#endif
-
-void MD5_Init(c)
-MD5_CTX *c;
- {
- c->A=INIT_DATA_A;
- c->B=INIT_DATA_B;
- c->C=INIT_DATA_C;
- c->D=INIT_DATA_D;
- c->Nl=0;
- c->Nh=0;
- c->num=0;
- }
-
-void MD5_Update(c, data, len)
-MD5_CTX *c;
-register const unsigned char *data;
-unsigned long len;
- {
- register ULONG *p;
- int sw,sc;
- ULONG l;
-
- if (len == 0) return;
-
- l=(c->Nl+(len<<3))&0xffffffffL;
- /* 95-05-24 eay Fixed a bug with the overflow handling, thanks to
- * Wei Dai <weidai@eskimo.com> for pointing it out. */
- if (l < c->Nl) /* overflow */
- c->Nh++;
- c->Nh+=(len>>29);
- c->Nl=l;
-
- if (c->num != 0)
- {
- p=c->data;
- sw=c->num>>2;
- sc=c->num&0x03;
-
- if ((c->num+len) >= MD5_CBLOCK)
- {
- l= p[sw];
- p_c2l(data,l,sc);
- p[sw++]=l;
- for (; sw<MD5_LBLOCK; sw++)
- {
- c2l(data,l);
- p[sw]=l;
- }
- len-=(MD5_CBLOCK-c->num);
-
- md5_block(c,p);
- c->num=0;
- /* drop through and do the rest */
- }
- else
- {
- int ew,ec;
-
- c->num+=(int)len;
- if ((sc+len) < 4) /* ugly, add char's to a word */
- {
- l= p[sw];
- p_c2l_p(data,l,sc,len);
- p[sw]=l;
- }
- else
- {
- ew=(c->num>>2);
- ec=(c->num&0x03);
- l= p[sw];
- p_c2l(data,l,sc);
- p[sw++]=l;
- for (; sw < ew; sw++)
- { c2l(data,l); p[sw]=l; }
- if (ec)
- {
- c2l_p(data,l,ec);
- p[sw]=l;
- }
- }
- return;
- }
- }
- /* we now can process the input data in blocks of MD5_CBLOCK
- * chars and save the leftovers to c->data. */
- p=c->data;
- while (len >= MD5_CBLOCK)
- {
-#if defined(L_ENDIAN) || defined(B_ENDIAN)
- memcpy(p,data,MD5_CBLOCK);
- data+=MD5_CBLOCK;
-#ifdef B_ENDIAN
- for (sw=(MD5_LBLOCK/4); sw; sw--)
- {
- Endian_Reverse32(p[0]);
- Endian_Reverse32(p[1]);
- Endian_Reverse32(p[2]);
- Endian_Reverse32(p[3]);
- p+=4;
- }
-#endif
-#else
- for (sw=(MD5_LBLOCK/4); sw; sw--)
- {
- c2l(data,l); *(p++)=l;
- c2l(data,l); *(p++)=l;
- c2l(data,l); *(p++)=l;
- c2l(data,l); *(p++)=l;
- }
-#endif
- p=c->data;
- md5_block(c,p);
- len-=MD5_CBLOCK;
- }
- sc=(int)len;
- c->num=sc;
- if (sc)
- {
- sw=sc>>2; /* words to copy */
-#ifdef L_ENDIAN
- p[sw]=0;
- memcpy(p,data,sc);
-#else
- sc&=0x03;
- for ( ; sw; sw--)
- { c2l(data,l); *(p++)=l; }
- c2l_p(data,l,sc);
- *p=l;
-#endif
- }
- }
-
-static void md5_block(c, X)
-MD5_CTX *c;
-register ULONG *X;
- {
- register ULONG A,B,C,D;
-
- A=c->A;
- B=c->B;
- C=c->C;
- D=c->D;
-
- /* Round 0 */
- R0(A,B,C,D,X[ 0], 7,0xd76aa478L);
- R0(D,A,B,C,X[ 1],12,0xe8c7b756L);
- R0(C,D,A,B,X[ 2],17,0x242070dbL);
- R0(B,C,D,A,X[ 3],22,0xc1bdceeeL);
- R0(A,B,C,D,X[ 4], 7,0xf57c0fafL);
- R0(D,A,B,C,X[ 5],12,0x4787c62aL);
- R0(C,D,A,B,X[ 6],17,0xa8304613L);
- R0(B,C,D,A,X[ 7],22,0xfd469501L);
- R0(A,B,C,D,X[ 8], 7,0x698098d8L);
- R0(D,A,B,C,X[ 9],12,0x8b44f7afL);
- R0(C,D,A,B,X[10],17,0xffff5bb1L);
- R0(B,C,D,A,X[11],22,0x895cd7beL);
- R0(A,B,C,D,X[12], 7,0x6b901122L);
- R0(D,A,B,C,X[13],12,0xfd987193L);
- R0(C,D,A,B,X[14],17,0xa679438eL);
- R0(B,C,D,A,X[15],22,0x49b40821L);
- /* Round 1 */
- R1(A,B,C,D,X[ 1], 5,0xf61e2562L);
- R1(D,A,B,C,X[ 6], 9,0xc040b340L);
- R1(C,D,A,B,X[11],14,0x265e5a51L);
- R1(B,C,D,A,X[ 0],20,0xe9b6c7aaL);
- R1(A,B,C,D,X[ 5], 5,0xd62f105dL);
- R1(D,A,B,C,X[10], 9,0x02441453L);
- R1(C,D,A,B,X[15],14,0xd8a1e681L);
- R1(B,C,D,A,X[ 4],20,0xe7d3fbc8L);
- R1(A,B,C,D,X[ 9], 5,0x21e1cde6L);
- R1(D,A,B,C,X[14], 9,0xc33707d6L);
- R1(C,D,A,B,X[ 3],14,0xf4d50d87L);
- R1(B,C,D,A,X[ 8],20,0x455a14edL);
- R1(A,B,C,D,X[13], 5,0xa9e3e905L);
- R1(D,A,B,C,X[ 2], 9,0xfcefa3f8L);
- R1(C,D,A,B,X[ 7],14,0x676f02d9L);
- R1(B,C,D,A,X[12],20,0x8d2a4c8aL);
- /* Round 2 */
- R2(A,B,C,D,X[ 5], 4,0xfffa3942L);
- R2(D,A,B,C,X[ 8],11,0x8771f681L);
- R2(C,D,A,B,X[11],16,0x6d9d6122L);
- R2(B,C,D,A,X[14],23,0xfde5380cL);
- R2(A,B,C,D,X[ 1], 4,0xa4beea44L);
- R2(D,A,B,C,X[ 4],11,0x4bdecfa9L);
- R2(C,D,A,B,X[ 7],16,0xf6bb4b60L);
- R2(B,C,D,A,X[10],23,0xbebfbc70L);
- R2(A,B,C,D,X[13], 4,0x289b7ec6L);
- R2(D,A,B,C,X[ 0],11,0xeaa127faL);
- R2(C,D,A,B,X[ 3],16,0xd4ef3085L);
- R2(B,C,D,A,X[ 6],23,0x04881d05L);
- R2(A,B,C,D,X[ 9], 4,0xd9d4d039L);
- R2(D,A,B,C,X[12],11,0xe6db99e5L);
- R2(C,D,A,B,X[15],16,0x1fa27cf8L);
- R2(B,C,D,A,X[ 2],23,0xc4ac5665L);
- /* Round 3 */
- R3(A,B,C,D,X[ 0], 6,0xf4292244L);
- R3(D,A,B,C,X[ 7],10,0x432aff97L);
- R3(C,D,A,B,X[14],15,0xab9423a7L);
- R3(B,C,D,A,X[ 5],21,0xfc93a039L);
- R3(A,B,C,D,X[12], 6,0x655b59c3L);
- R3(D,A,B,C,X[ 3],10,0x8f0ccc92L);
- R3(C,D,A,B,X[10],15,0xffeff47dL);
- R3(B,C,D,A,X[ 1],21,0x85845dd1L);
- R3(A,B,C,D,X[ 8], 6,0x6fa87e4fL);
- R3(D,A,B,C,X[15],10,0xfe2ce6e0L);
- R3(C,D,A,B,X[ 6],15,0xa3014314L);
- R3(B,C,D,A,X[13],21,0x4e0811a1L);
- R3(A,B,C,D,X[ 4], 6,0xf7537e82L);
- R3(D,A,B,C,X[11],10,0xbd3af235L);
- R3(C,D,A,B,X[ 2],15,0x2ad7d2bbL);
- R3(B,C,D,A,X[ 9],21,0xeb86d391L);
-
- c->A+=A&0xffffffffL;
- c->B+=B&0xffffffffL;
- c->C+=C&0xffffffffL;
- c->D+=D&0xffffffffL;
- }
-
-void MD5_Final(md, c)
-unsigned char *md;
-MD5_CTX *c;
- {
- register int i,j;
- register ULONG l;
- register ULONG *p;
- static unsigned char end[4]={0x80,0x00,0x00,0x00};
- unsigned char *cp=end;
-
- /* c->num should definitly have room for at least one more byte. */
- p=c->data;
- j=c->num;
- i=j>>2;
-
- /* purify often complains about the following line as an
- * Uninitialized Memory Read. While this can be true, the
- * following p_c2l macro will reset l when that case is true.
- * This is because j&0x03 contains the number of 'valid' bytes
- * already in p[i]. If and only if j&0x03 == 0, the UMR will
- * occur but this is also the only time p_c2l will do
- * l= *(cp++) instead of l|= *(cp++)
- * Many thanks to Alex Tang <altitude@cic.net> for pickup this
- * 'potential bug' */
-#ifdef PURIFY
- if ((j&0x03) == 0) p[i]=0;
-#endif
- l=p[i];
- p_c2l(cp,l,j&0x03);
- p[i]=l;
- i++;
- /* i is the next 'undefined word' */
- if (c->num >= MD5_LAST_BLOCK)
- {
- for (; i<MD5_LBLOCK; i++)
- p[i]=0;
- md5_block(c,p);
- i=0;
- }
- for (; i<(MD5_LBLOCK-2); i++)
- p[i]=0;
- p[MD5_LBLOCK-2]=c->Nl;
- p[MD5_LBLOCK-1]=c->Nh;
- md5_block(c,p);
- cp=md;
- l=c->A; l2c(l,cp);
- l=c->B; l2c(l,cp);
- l=c->C; l2c(l,cp);
- l=c->D; l2c(l,cp);
-
- /* clear stuff, md5_block may be leaving some stuff on the stack
- * but I'm not worried :-) */
- c->num=0;
-/* memset((char *)&c,0,sizeof(c));*/
- }
-
-#ifdef undef
-int printit(l)
-unsigned long *l;
- {
- int i,ii;
-
- for (i=0; i<2; i++)
- {
- for (ii=0; ii<8; ii++)
- {
- fprintf(stderr,"%08lx ",l[i*8+ii]);
- }
- fprintf(stderr,"\n");
- }
- }
-#endif
-#endif /* USE_MD5 */
diff --git a/contrib/bind/lib/dst/md5_locl.h b/contrib/bind/lib/dst/md5_locl.h
deleted file mode 100644
index b2f0028..0000000
--- a/contrib/bind/lib/dst/md5_locl.h
+++ /dev/null
@@ -1,190 +0,0 @@
-/* crypto/md/md5_locl.h */
-/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
- * All rights reserved.
- *
- * This package is an SSL implementation written
- * by Eric Young (eay@cryptsoft.com).
- * The implementation was written so as to conform with Netscapes SSL.
- *
- * This library is free for commercial and non-commercial use as long as
- * the following conditions are aheared to. The following conditions
- * apply to all code found in this distribution, be it the RC4, RSA,
- * lhash, DES, etc., code; not just the SSL code. The SSL documentation
- * included with this distribution is covered by the same copyright terms
- * except that the holder is Tim Hudson (tjh@cryptsoft.com).
- *
- * Copyright remains Eric Young's, and as such any Copyright notices in
- * the code are not to be removed.
- * If this package is used in a product, Eric Young should be given attribution
- * as the author of the parts of the library used.
- * This can be in the form of a textual message at program startup or
- * in documentation (online or textual) provided with the package.
- *
- * 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 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 cryptographic software written by
- * Eric Young (eay@cryptsoft.com)"
- * The word 'cryptographic' can be left out if the rouines from the library
- * being used are not cryptographic related :-).
- * 4. If you include any Windows specific code (or a derivative thereof) from
- * the apps directory (application code) you must include an acknowledgement:
- * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
- *
- * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``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 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 licence and distribution terms for any publically available version or
- * derivative of this code cannot be changed. i.e. this code cannot simply be
- * copied and put under another distribution licence
- * [including the GNU Public Licence.]
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include "md5.h"
-
-#define ULONG unsigned long
-#define UCHAR unsigned char
-#define UINT unsigned int
-
-#if defined(NOCONST)
-#define const
-#endif
-
-#undef c2l
-#define c2l(c,l) (l = ((unsigned long)(*((c)++))) , \
- l|=(((unsigned long)(*((c)++)))<< 8), \
- l|=(((unsigned long)(*((c)++)))<<16), \
- l|=(((unsigned long)(*((c)++)))<<24))
-
-#undef p_c2l
-#define p_c2l(c,l,n) { \
- switch (n) { \
- case 0: l =((unsigned long)(*((c)++))); \
- case 1: l|=((unsigned long)(*((c)++)))<< 8; \
- case 2: l|=((unsigned long)(*((c)++)))<<16; \
- case 3: l|=((unsigned long)(*((c)++)))<<24; \
- } \
- }
-
-/* NOTE the pointer is not incremented at the end of this */
-#undef c2l_p
-#define c2l_p(c,l,n) { \
- l=0; \
- (c)+=n; \
- switch (n) { \
- case 3: l =((unsigned long)(*(--(c))))<<16; \
- case 2: l|=((unsigned long)(*(--(c))))<< 8; \
- case 1: l|=((unsigned long)(*(--(c)))) ; \
- } \
- }
-
-#undef p_c2l_p
-#define p_c2l_p(c,l,sc,len) { \
- switch (sc) \
- { \
- case 0: l =((unsigned long)(*((c)++))); \
- if (--len == 0) break; \
- case 1: l|=((unsigned long)(*((c)++)))<< 8; \
- if (--len == 0) break; \
- case 2: l|=((unsigned long)(*((c)++)))<<16; \
- } \
- }
-
-#undef l2c
-#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
- *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
- *((c)++)=(unsigned char)(((l)>>16)&0xff), \
- *((c)++)=(unsigned char)(((l)>>24)&0xff))
-
-/* NOTE - c is not incremented as per l2c */
-#undef l2cn
-#define l2cn(l1,l2,c,n) { \
- c+=n; \
- switch (n) { \
- case 8: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
- case 7: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
- case 6: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
- case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
- case 4: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
- case 3: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
- case 2: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
- case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
- } \
- }
-
-/* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */
-#if defined(WIN32)
-/* 5 instructions with rotate instruction, else 9 */
-#define Endian_Reverse32(a) \
- { \
- unsigned long l=(a); \
- (a)=((ROTATE(l,8)&0x00FF00FF)|(ROTATE(l,24)&0xFF00FF00)); \
- }
-#else
-/* 6 instructions with rotate instruction, else 8 */
-#define Endian_Reverse32(a) \
- { \
- unsigned long l=(a); \
- l=(((l&0xFF00FF00)>>8L)|((l&0x00FF00FF)<<8L)); \
- (a)=ROTATE(l,16L); \
- }
-#endif
-/*
-#define F(x,y,z) (((x) & (y)) | ((~(x)) & (z)))
-#define G(x,y,z) (((x) & (z)) | ((y) & (~(z))))
-*/
-
-/* As pointed out by Wei Dai <weidai@eskimo.com>, the above can be
- * simplified to the code below. Wei attributes these optimisations
- * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel.
- */
-#define F(x,y,z) ((((y) ^ (z)) & (x)) ^ (z))
-#define G(x,y,z) ((((x) ^ (y)) & (z)) ^ (y))
-#define H(x,y,z) ((x) ^ (y) ^ (z))
-#define I(x,y,z) (((x) | (~(z))) ^ (y))
-
-#undef ROTATE
-#if defined(WIN32)
-#define ROTATE(a,n) _lrotl(a,n)
-#else
-#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
-#endif
-
-
-#define R0(a,b,c,d,k,s,t) { \
- a+=((k)+(t)+F((b),(c),(d))); \
- a=ROTATE(a,s); \
- a+=b; };\
-
-#define R1(a,b,c,d,k,s,t) { \
- a+=((k)+(t)+G((b),(c),(d))); \
- a=ROTATE(a,s); \
- a+=b; };
-
-#define R2(a,b,c,d,k,s,t) { \
- a+=((k)+(t)+H((b),(c),(d))); \
- a=ROTATE(a,s); \
- a+=b; };
-
-#define R3(a,b,c,d,k,s,t) { \
- a+=((k)+(t)+I((b),(c),(d))); \
- a=ROTATE(a,s); \
- a+=b; };
diff --git a/contrib/bind/lib/dst/prandom.c b/contrib/bind/lib/dst/prandom.c
deleted file mode 100644
index 2236fe8..0000000
--- a/contrib/bind/lib/dst/prandom.c
+++ /dev/null
@@ -1,853 +0,0 @@
-#ifndef LINT
-static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/prandom.c,v 1.12 2001/07/26 01:20:09 marka Exp $";
-#endif
-/*
- * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc.
- *
- * 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 TRUSTED INFORMATION SYSTEMS
- * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
- * TRUSTED INFORMATION SYSTEMS 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 THE SOFTWARE.
- */
-
-#include "port_before.h"
-
-#include <assert.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <time.h>
-#include <dirent.h>
-#include <sys/param.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-
-#include "dst_internal.h"
-#include "prand_conf.h"
-
-#include "port_after.h"
-
-#ifndef DST_NUM_HASHES
-#define DST_NUM_HASHES 4
-#endif
-#ifndef DST_NUMBER_OF_COUNTERS
-#define DST_NUMBER_OF_COUNTERS 5 /* 32 * 5 == 160 == SHA(1) > MD5 */
-#endif
-
-/*
- * the constant below is a prime number to make fixed data structues like
- * stat and time wrap over blocks. This adds certain uncertanty to what is
- * in each digested block.
- * The prime number 2879 has the special property that when
- * divided by 2,4 and 6 the result is also a prime numbers
- */
-
-#ifndef DST_RANDOM_BLOCK_SIZE
-#define DST_RANDOM_BLOCK_SIZE 2879
-#endif
-
-/*
- * This constant dictatates how many bits we shift to the right before using a
- */
-#ifndef DST_SHIFT
-#define DST_SHIFT 9
-#endif
-
-/*
- * An initalizer that is as bad as any other with half the bits set
- */
-#ifndef DST_RANDOM_PATTERN
-#define DST_RANDOM_PATTERN 0x8765CA93
-#endif
-/*
- * things must have changed in the last 3600 seconds to be used
- */
-#define MAX_OLD 3600
-
-
-/*
- * these two data structure are used to process input data into digests,
- *
- * The first structure is containts a pointer to a DST HMAC key
- * the variables accompanying are used for
- * step : select every step byte from input data for the hash
- * block: number of data elements going into each hash
- * digested: number of data elements digested so far
- * curr: offset into the next input data for the first byte.
- */
-typedef struct hash {
- DST_KEY *key;
- void *ctx;
- int digested, block, step, curr;
-} prand_hash;
-
-/*
- * This data structure controlls number of hashes and keeps track of
- * overall progress in generating correct number of bytes of output.
- * output : array to store the output data in
- * needed : how many bytes of output are needed
- * filled : number of bytes in output so far.
- * bytes : total number of bytes processed by this structure
- * file_digest : the HMAC key used to digest files.
- */
-typedef struct work {
- int needed, filled, bytes;
- u_char *output;
- prand_hash *hash[DST_NUM_HASHES];
- DST_KEY *file_digest;
-} dst_work;
-
-
-/*
- * forward function declarations
- */
-static int get_dev_random(u_char *output, int size);
-static int do_time(dst_work *work);
-static int do_ls(dst_work *work);
-static int unix_cmd(dst_work *work);
-static int digest_file(dst_work *work);
-
-static void force_hash(dst_work *work, prand_hash *hash);
-static int do_hash(dst_work *work, prand_hash *hash, const u_char *input,
- int size);
-static int my_digest(dst_work *tmp, const u_char *input, int size);
-static prand_hash *get_hmac_key(int step, int block);
-
-static int own_random(dst_work *work);
-
-
-/*
- * variables used in the quick random number generator
- */
-static u_int32_t ran_val = DST_RANDOM_PATTERN;
-static u_int32_t ran_cnt = (DST_RANDOM_PATTERN >> 10);
-
-/*
- * setting the quick_random generator to particular values or if both
- * input parameters are 0 then set it to initial vlaues
- */
-
-void
-dst_s_quick_random_set(u_int32_t val, u_int32_t cnt)
-{
- ran_val = (val == 0) ? DST_RANDOM_PATTERN : val;
- ran_cnt = (cnt == 0) ? (DST_RANDOM_PATTERN >> 10) : cnt;
-}
-
-/*
- * this is a quick and random number generator that seems to generate quite
- * good distribution of data
- */
-u_int32_t
-dst_s_quick_random(int inc)
-{
- ran_val = ((ran_val >> 13) ^ (ran_val << 19)) ^
- ((ran_val >> 7) ^ (ran_val << 25));
- if (inc > 0) /* only increasing values accepted */
- ran_cnt += inc;
- ran_val += ran_cnt++;
- return (ran_val);
-}
-
-/*
- * get_dev_random: Function to read /dev/random reliably
- * this function returns how many bytes where read from the device.
- * port_after.h should set the control variable HAVE_DEV_RANDOM
- */
-static int
-get_dev_random(u_char *output, int size)
-{
-#ifdef HAVE_DEV_RANDOM
- struct stat st;
- int n = 0, fd = -1, s;
-
- s = stat("/dev/random", &st);
- if (s == 0 && S_ISCHR(st.st_mode)) {
- if ((fd = open("/dev/random", O_RDONLY | O_NONBLOCK)) != -1) {
- if ((n = read(fd, output, size)) < 0)
- n = 0;
- close(fd);
- }
- return (n);
- }
-#endif
- return (0);
-}
-
-/*
- * Portable way of getting the time values if gettimeofday is missing
- * then compile with -DMISSING_GETTIMEOFDAY time() is POSIX compliant but
- * gettimeofday() is not.
- * Time of day is predictable, we are looking for the randomness that comes
- * the last few bits in the microseconds in the timer are hard to predict when
- * this is invoked at the end of other operations
- */
-struct timeval *mtime;
-static int
-do_time(dst_work *work)
-{
- int cnt = 0;
- static u_char tmp[sizeof(struct timeval) + sizeof(struct timezone)];
- struct timezone *zone;
-
- zone = (struct timezone *) tmp;
- mtime = (struct timeval *)(tmp + sizeof(struct timezone));
- gettimeofday(mtime, zone);
- cnt = sizeof(tmp);
- my_digest(work, tmp, sizeof(tmp));
-
- return (cnt);
-}
-
-/*
- * this function simulates the ls command, but it uses stat which gives more
- * information and is harder to guess
- * Each call to this function will visit the next directory on the list of
- * directories, in a circular manner.
- * return value is the number of bytes added to the temp buffer
- *
- * do_ls() does not visit subdirectories
- * if attacker has access to machine it can guess most of the values seen
- * thus it is important to only visit directories that are freqently updated
- * Attacker that has access to the network can see network traffic
- * when NFS mounted directories are accessed and know exactly the data used
- * but may not know exactly in what order data is used.
- * Returns the number of bytes that where returned in stat structures
- */
-static int
-do_ls(dst_work *work)
-{
- struct dir_info {
- uid_t uid;
- gid_t gid;
- off_t size;
- time_t atime, mtime, ctime;
- };
- static struct dir_info dir_info;
- struct stat buf;
- struct dirent *entry;
- static int i = 0;
- static unsigned long d_round = 0;
- struct timeval tv;
- int n = 0, dir_len, tb_i = 0, out = 0;
-
- char file_name[1024];
- u_char tmp_buff[1024];
- DIR *dir = NULL;
-
- if (dirs[i] == NULL) /* if at the end of the list start over */
- i = 0;
- if (stat(dirs[i++], &buf)) /* directory does not exist */
- return (0);
-
- gettimeofday(&tv, NULL);
- if (d_round == 0)
- d_round = tv.tv_sec - MAX_OLD;
- else if (i==1) /* if starting a new round cut what we accept */
- d_round += (tv.tv_sec - d_round)/2;
-
- if (buf.st_atime < (time_t)d_round)
- return (0);
-
- EREPORT(("do_ls i %d filled %4d\n", i-1, work->filled));
- memcpy(tmp_buff, &buf, sizeof(buf));
- tb_i += sizeof(buf);
-
-
- if ((dir = opendir(dirs[i-1])) == NULL)/* open it for read */
- return (0);
- strcpy(file_name, dirs[i-1]);
- dir_len = strlen(file_name);
- file_name[dir_len++] = '/';
- while ((entry = readdir(dir))) {
- int len = strlen(entry->d_name);
- out += len;
- if (my_digest(work, (u_char *)entry->d_name, len))
- break;
-
- memcpy(&file_name[dir_len], entry->d_name, len);
- file_name[dir_len + len] = 0x0;
- /* for all entries in dir get the stats */
- if (stat(file_name, &buf) == 0) {
- n++; /* count successfull stat calls */
- /* copy non static fields */
- dir_info.uid += buf.st_uid;
- dir_info.gid += buf.st_gid;
- dir_info.size += buf.st_size;
- dir_info.atime += buf.st_atime;
- dir_info.mtime += buf.st_mtime;
- dir_info.ctime += buf.st_ctime;
- out += sizeof(dir_info);
- if(my_digest(work, (u_char *)&dir_info,
- sizeof(dir_info)))
- break;
- }
- }
- closedir(dir); /* done */
- out += do_time(work); /* add a time stamp */
- return (out);
-}
-
-
-/*
- * unix_cmd()
- * this function executes the a command from the cmds[] list of unix commands
- * configured in the prand_conf.h file
- * return value is the number of bytes added to the randomness temp buffer
- *
- * it returns the number of bytes that where read in
- * if more data is needed at the end time is added to the data.
- * This function maintains a state to selects the next command to run
- * returns the number of bytes read in from the command
- */
-static int
-unix_cmd(dst_work *work)
-{
- static int cmd_index = 0;
- int cnt = 0, n;
- FILE *pipe;
- u_char buffer[4096];
-
- if (cmds[cmd_index] == NULL)
- cmd_index = 0;
- EREPORT(("unix_cmd() i %d filled %4d\n", cmd_index, work->filled));
- pipe = popen(cmds[cmd_index++], "r"); /* execute the command */
-
- while ((n = fread(buffer, sizeof(char), sizeof(buffer), pipe)) > 0) {
- cnt += n; /* process the output */
- if (my_digest(work, buffer, n))
- break;
- /* this adds some randomness to the output */
- cnt += do_time(work);
- }
- while ((n = fread(buffer, sizeof(char), sizeof(buffer), pipe)) > 0)
- (void)NULL; /* drain the pipe */
- pclose(pipe);
- return (cnt); /* read how many bytes where read in */
-}
-
-/*
- * digest_file() This function will read a file and run hash over it
- * input is a file name
- */
-static int
-digest_file(dst_work *work)
-{
- static int f_cnt = 0;
- static unsigned long f_round = 0;
- FILE *fp;
- void *ctx;
- const char *name;
- int no, i;
- struct stat st;
- struct timeval tv;
- u_char buf[1024];
-
- if (f_round == 0 || files[f_cnt] == NULL || work->file_digest == NULL)
- if (gettimeofday(&tv, NULL)) /* only do this if needed */
- return (0);
- if (f_round == 0) /* first time called set to one hour ago */
- f_round = (tv.tv_sec - MAX_OLD);
- name = files[f_cnt++];
- if (files[f_cnt] == NULL) { /* end of list of files */
- if(f_cnt <= 1) /* list is too short */
- return (0);
- f_cnt = 0; /* start again on list */
- f_round += (tv.tv_sec - f_round)/2; /* set new cutoff */
- work->file_digest = dst_free_key(work->file_digest);
- }
- if (work->file_digest == NULL) {
- work->file_digest = dst_buffer_to_key("", KEY_HMAC_MD5, 0, 0,
- (u_char *)&tv, sizeof(tv));
- if (work->file_digest == NULL)
- return (0);
- }
- if (access(name, R_OK) || stat(name, &st))
- return (0); /* no such file or not allowed to read it */
- if (strncmp(name, "/proc/", 6) && st.st_mtime < (time_t)f_round)
- return(0); /* file has not changed recently enough */
- if (dst_sign_data(SIG_MODE_INIT, work->file_digest, &ctx,
- NULL, 0, NULL, 0)) {
- work->file_digest = dst_free_key(work->file_digest);
- return (0);
- }
- if ((fp = fopen(name, "r")) == NULL)
- return (0);
- for (no = 0; (i = fread(buf, sizeof(*buf), sizeof(buf), fp)) > 0;
- no += i)
- dst_sign_data(SIG_MODE_UPDATE, work->file_digest, &ctx,
- buf, i, NULL, 0);
-
- fclose(fp);
- if (no >= 64) {
- i = dst_sign_data(SIG_MODE_FINAL, work->file_digest, &ctx,
- NULL, 0, &work->output[work->filled],
- DST_HASH_SIZE);
- if (i > 0)
- work->filled += i;
- }
- else if (i > 0)
- my_digest(work, buf, i);
- my_digest(work, (const u_char *)name, strlen(name));
- return (no + strlen(name));
-}
-
-/*
- * function to perform the FINAL and INIT operation on a hash if allowed
- */
-static void
-force_hash(dst_work *work, prand_hash *hash)
-{
- int i = 0;
-
- /*
- * if more than half a block then add data to output
- * otherwise adde the digest to the next hash
- */
- if ((hash->digested * 2) > hash->block) {
- i = dst_sign_data(SIG_MODE_FINAL, hash->key, &hash->ctx,
- NULL, 0, &work->output[work->filled],
- DST_HASH_SIZE);
-
- hash->digested = 0;
- dst_sign_data(SIG_MODE_INIT, hash->key, &hash->ctx,
- NULL, 0, NULL, 0);
- if (i > 0)
- work->filled += i;
- }
- return;
-}
-
-/*
- * This function takes the input data does the selection of data specified
- * by the hash control block.
- * The step varialbe in the work sturcture determines which 1/step bytes
- * are used,
- *
- */
-static int
-do_hash(dst_work *work, prand_hash *hash, const u_char *input, int size)
-{
- const u_char *tmp = input;
- u_char *save = NULL, *tp;
- int i, cnt = size, n, needed, avail, dig, tmp_size = 0;
-
- if (cnt <= 0 || input == NULL)
- return (0);
-
- if (hash->step > 1) { /* if using subset of input data */
- tmp_size = size / hash->step + 2;
- tmp = tp = save = malloc(tmp_size);
- for (cnt = 0, i = hash->curr; i < size; i += hash->step, cnt++)
- *(tp++) = input[i];
- /* calcutate the starting point in the next input set */
- hash->curr = (hash->step - (i - size)) % hash->step;
- }
- /* digest the data in block sizes */
- for (n = 0; n < cnt; n += needed) {
- avail = (cnt - n);
- needed = hash->block - hash->digested;
- dig = (avail < needed) ? avail : needed;
- dst_sign_data(SIG_MODE_UPDATE, hash->key, &hash->ctx,
- &tmp[n], dig, NULL, 0);
- hash->digested += dig;
- if (hash->digested >= hash->block)
- force_hash(work, hash);
- if (work->needed < work->filled) {
- if (tmp_size > 0)
- SAFE_FREE2(save, tmp_size);
- return (1);
- }
- }
- if (tmp_size > 0)
- SAFE_FREE2(save, tmp_size);
- return (0);
-}
-
-/*
- * Copy data from INPUT for length SIZE into the work-block TMP.
- * If we fill the work-block, digest it; then,
- * if work-block needs more data, keep filling with the rest of the input.
- */
-static int
-my_digest(dst_work *work, const u_char *input, int size)
-{
-
- int i, full = 0;
- static unsigned counter;
-
- counter += size;
- /* first do each one of the hashes */
- for (i = 0; i < DST_NUM_HASHES && full == 0; i++)
- full = do_hash(work, work->hash[i], input, size) +
- do_hash(work, work->hash[i], (u_char *) &counter,
- sizeof(counter));
-/*
- * if enough data has be generated do final operation on all hashes
- * that have enough date for that
- */
- for (i = 0; full && (i < DST_NUM_HASHES); i++)
- force_hash(work, work->hash[i]);
-
- return (full);
-}
-
-/*
- * this function gets some semi random data and sets that as an HMAC key
- * If we get a valid key this function returns that key initalized
- * otherwise it returns NULL;
- */
-static prand_hash *
-get_hmac_key(int step, int block)
-{
-
- u_char *buff;
- int temp = 0, n = 0, size = 70;
- DST_KEY *new_key = NULL;
- prand_hash *new = NULL;
-
- /* use key that is larger than digest algorithms (64) for key size */
- buff = malloc(size);
- if (buff == NULL)
- return (NULL);
- /* do not memset the allocated memory to get random bytes there */
- /* time of day is somewhat random expecialy in the last bytes */
- gettimeofday((struct timeval *) &buff[n], NULL);
- n += sizeof(struct timeval);
-
-/* get some semi random stuff in here stir it with micro seconds */
- if (n < size) {
- temp = dst_s_quick_random((int) buff[n - 1]);
- memcpy(&buff[n], &temp, sizeof(temp));
- n += sizeof(temp);
- }
-/* get the pid of this process and its parent */
- if (n < size) {
- temp = (int) getpid();
- memcpy(&buff[n], &temp, sizeof(temp));
- n += sizeof(temp);
- }
- if (n < size) {
- temp = (int) getppid();
- memcpy(&buff[n], &temp, sizeof(temp));
- n += sizeof(temp);
- }
-/* get the user ID */
- if (n < size) {
- temp = (int) getuid();
- memcpy(&buff[n], &temp, sizeof(temp));
- n += sizeof(temp);
- }
-#ifndef GET_HOST_ID_MISSING
- if (n < size) {
- temp = (int) gethostid();
- memcpy(&buff[n], &temp, sizeof(temp));
- n += sizeof(temp);
- }
-#endif
-/* get some more random data */
- if (n < size) {
- temp = dst_s_quick_random((int) buff[n - 1]);
- memcpy(&buff[n], &temp, sizeof(temp));
- n += sizeof(temp);
- }
-/* covert this into a HMAC key */
- new_key = dst_buffer_to_key("", KEY_HMAC_MD5, 0, 0, buff, size);
- SAFE_FREE(buff);
-
-/* get the control structure */
- if ((new = malloc(sizeof(prand_hash))) == NULL)
- return (NULL);
- new->digested = new->curr = 0;
- new->step = step;
- new->block = block;
- new->key = new_key;
- if (dst_sign_data(SIG_MODE_INIT, new_key, &new->ctx, NULL, 0, NULL, 0))
- return (NULL);
-
- return (new);
-}
-
-/*
- * own_random()
- * This function goes out and from various sources tries to generate enough
- * semi random data that a hash function can generate a random data.
- * This function will iterate between the two main random source sources,
- * information from programs and directores in random order.
- * This function return the number of bytes added to the random output buffer.
- */
-static int
-own_random(dst_work *work)
-{
- int dir = 0, b;
- int bytes, n, cmd = 0, dig = 0;
- int start =0;
-/*
- * now get the initial seed to put into the quick random function from
- * the address of the work structure
- */
- bytes = (int) getpid();
-/*
- * proceed while needed
- */
- while (work->filled < work->needed) {
- EREPORT(("own_random r %08x b %6d f %6d\n",
- ran_val, bytes, work->filled));
-/* pick a random number in the range of 0..7 based on that random number
- * perform some operations that yield random data
- */
- start = work->filled;
- n = (dst_s_quick_random(bytes) >> DST_SHIFT) & 0x07;
- switch (n) {
- case 0:
- case 3:
- if (sizeof(cmds) > 2 *sizeof(*cmds)) {
- b = unix_cmd(work);
- cmd += b;
- }
- break;
-
- case 1:
- case 7:
- if (sizeof(dirs) > 2 *sizeof(*dirs)) {
- b = do_ls(work);
- dir += b;
- }
- break;
-
- case 4:
- case 5:
- /* retry getting data from /dev/random */
- b = get_dev_random(&work->output[work->filled],
- work->needed - work->filled);
- if (b > 0)
- work->filled += b;
- break;
-
- case 6:
- if (sizeof(files) > 2 * sizeof(*files)) {
- b = digest_file(work);
- dig += b;
- }
- break;
-
- case 2:
- default: /* to make sure we make some progress */
- work->output[work->filled++] = 0xff &
- dst_s_quick_random(bytes);
- b = 1;
- break;
- }
- if (b > 0)
- bytes += b;
- }
- return (work->filled);
-}
-
-
-/*
- * dst_s_random() This function will return the requested number of bytes
- * of randomness to the caller it will use the best available sources of
- * randomness.
- * The current order is to use /dev/random, precalculated randomness, and
- * finaly use some system calls and programs to generate semi random data that
- * is then digested to generate randomness.
- * This function is thread safe as each thread uses its own context, but
- * concurrent treads will affect each other as they update shared state
- * information.
- * It is strongly recommended that this function be called requesting a size
- * that is not a multiple of the output of the hash function used.
- *
- * If /dev/random is not available this function is not suitable to generate
- * large ammounts of data, rather it is suitable to seed a pseudo-random
- * generator
- * Returns the number of bytes put in the output buffer
- */
-int
-dst_s_random(u_char *output, int size)
-{
- int n = 0, s, i;
- static u_char old_unused[DST_HASH_SIZE * DST_NUM_HASHES];
- static int unused = 0;
-
- if (size <= 0 || output == NULL)
- return (0);
-
- if (size >= 2048)
- return (-1);
- /*
- * Read from /dev/random
- */
- n = get_dev_random(output, size);
- /*
- * If old data is available and needed use it
- */
- if (n < size && unused > 0) {
- int need = size - n;
- if (unused <= need) {
- memcpy(output, old_unused, unused);
- n += unused;
- unused = 0;
- } else {
- memcpy(output, old_unused, need);
- n += need;
- unused -= need;
- memcpy(old_unused, &old_unused[need], unused);
- }
- }
- /*
- * If we need more use the simulated randomness here.
- */
- if (n < size) {
- dst_work *my_work = (dst_work *) malloc(sizeof(dst_work));
- if (my_work == NULL)
- return (n);
- my_work->needed = size - n;
- my_work->filled = 0;
- my_work->output = (u_char *) malloc(my_work->needed +
- DST_HASH_SIZE *
- DST_NUM_HASHES);
- my_work->file_digest = NULL;
- if (my_work->output == NULL)
- return (n);
- memset(my_work->output, 0x0, my_work->needed);
-/* allocate upto 4 different HMAC hash functions out of order */
-#if DST_NUM_HASHES >= 3
- my_work->hash[2] = get_hmac_key(3, DST_RANDOM_BLOCK_SIZE / 2);
-#endif
-#if DST_NUM_HASHES >= 2
- my_work->hash[1] = get_hmac_key(7, DST_RANDOM_BLOCK_SIZE / 6);
-#endif
-#if DST_NUM_HASHES >= 4
- my_work->hash[3] = get_hmac_key(5, DST_RANDOM_BLOCK_SIZE / 4);
-#endif
- my_work->hash[0] = get_hmac_key(1, DST_RANDOM_BLOCK_SIZE);
- if (my_work->hash[0] == NULL) /* if failure bail out */
- return (n);
- s = own_random(my_work);
-/* if more generated than needed store it for future use */
- if (s >= my_work->needed) {
- EREPORT(("dst_s_random(): More than needed %d >= %d\n",
- s, my_work->needed));
- memcpy(&output[n], my_work->output, my_work->needed);
- n += my_work->needed;
- /* saving unused data for next time */
- unused = s - my_work->needed;
- memcpy(old_unused, &my_work->output[my_work->needed],
- unused);
- } else {
- /* XXXX This should not happen */
- EREPORT(("Not enough %d >= %d\n", s, my_work->needed));
- memcpy(&output[n], my_work->output, s);
- n += my_work->needed;
- }
-
-/* delete the allocated work area */
- for (i = 0; i < DST_NUM_HASHES; i++) {
- dst_free_key(my_work->hash[i]->key);
- SAFE_FREE(my_work->hash[i]);
- }
- SAFE_FREE(my_work->output);
- SAFE_FREE(my_work);
- }
- return (n);
-}
-
-/*
- * A random number generator that is fast and strong
- * this random number generator is based on HASHing data,
- * the input to the digest function is a collection of <NUMBER_OF_COUNTERS>
- * counters that is incremented between digest operations
- * each increment operation amortizes to 2 bits changed in that value
- * for 5 counters thus the input will amortize to have 10 bits changed
- * The counters are initaly set using the strong random function above
- * the HMAC key is selected by the same methold as the HMAC keys for the
- * strong random function.
- * Each set of counters is used for 2^25 operations
- *
- * returns the number of bytes written to the output buffer
- * or negative number in case of error
- */
-int
-dst_s_semi_random(u_char *output, int size)
-{
- static u_int32_t counter[DST_NUMBER_OF_COUNTERS];
- static u_char semi_old[DST_HASH_SIZE];
- static int semi_loc = 0, cnt = 0, hb_size = 0;
- static DST_KEY *my_key = NULL;
- prand_hash *hash;
- int out = 0, i, n;
-
- if (output == NULL || size <= 0)
- return (-2);
-
-/* check if we need a new key */
- if (my_key == NULL || cnt > (1 << 25)) { /* get HMAC KEY */
- if (my_key)
- my_key->dk_func->destroy(my_key);
- if ((hash = get_hmac_key(1, DST_RANDOM_BLOCK_SIZE)) == NULL)
- return (0);
- my_key = hash->key;
-/* check if the key works stir the new key using some old random data */
- hb_size = dst_sign_data(SIG_MODE_ALL, my_key, NULL,
- (u_char *) counter, sizeof(counter),
- semi_old, sizeof(semi_old));
- if (hb_size <= 0) {
- EREPORT(("dst_s_semi_random() Sign of alg %d failed %d\n",
- my_key->dk_alg, hb_size));
- return (-1);
- }
-/* new set the counters to random values */
- dst_s_random((u_char *) counter, sizeof(counter));
- cnt = 0;
- }
-/* if old data around use it first */
- if (semi_loc < hb_size) {
- if (size <= hb_size - semi_loc) { /* need less */
- memcpy(output, &semi_old[semi_loc], size);
- semi_loc += size;
- return (size); /* DONE */
- } else {
- out = hb_size - semi_loc;
- memcpy(output, &semi_old[semi_loc], out);
- semi_loc += out;
- }
- }
-/* generate more randome stuff */
- while (out < size) {
- /*
- * modify at least one bit by incrementing at least one counter
- * based on the last bit of the last counter updated update
- * the next one.
- * minimaly this operation will modify at least 1 bit,
- * amortized 2 bits
- */
- for (n = 0; n < DST_NUMBER_OF_COUNTERS; n++)
- i = (int) counter[n]++;
-
- i = dst_sign_data(SIG_MODE_ALL, my_key, NULL,
- (u_char *) counter, hb_size,
- semi_old, sizeof(semi_old));
-#ifdef REPORT_ERRORS
- if (i != hb_size)
- EREPORT(("HMAC SIGNATURE FAILURE %d\n", i));
-#endif
- cnt++;
- if (size - out < i) /* Not all data is needed */
- semi_loc = i = size - out;
- memcpy(&output[out], semi_old, i);
- out += i;
- }
- return (out);
-}
diff --git a/contrib/bind/lib/dst/rsaref_link.c b/contrib/bind/lib/dst/rsaref_link.c
deleted file mode 100644
index 8e09b86..0000000
--- a/contrib/bind/lib/dst/rsaref_link.c
+++ /dev/null
@@ -1,761 +0,0 @@
-#ifdef RSAREF
-static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/rsaref_link.c,v 1.10 2001/05/29 05:48:15 marka Exp $";
-
-/*
- * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc.
- *
- * 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 TRUSTED INFORMATION SYSTEMS
- * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
- * TRUSTED INFORMATION SYSTEMS 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 THE SOFTWARE.
- */
-
-/*
- * This file contains two components
- * 1. Interface to the rsaref library to allow compilation when RSAREF is
- * not available all calls to RSAREF are contained inside this file.
- * 2. The glue to connvert RSA{REF} KEYS to and from external formats
- */
-#include "port_before.h"
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <memory.h>
-#include <sys/param.h>
-#include <sys/time.h>
-#include <netinet/in.h>
-
-#include "dst_internal.h"
-
-# ifdef __STDC__
-# define PROTOTYPES 1
-# else
-# define PROTOTYPES 0
-# endif
-
-# include <global.h>
-# include <rsaref.h>
-
-#include "port_after.h"
-
-
-typedef struct rsakey {
- char *rk_signer;
- R_RSA_PRIVATE_KEY *rk_Private_Key;
- R_RSA_PUBLIC_KEY *rk_Public_Key;
-} RSA_Key;
-
-
-static int dst_rsaref_sign(const int mode, DST_KEY *key, void **context,
- const u_char *data, const int len,
- u_char *signature, const int sig_len);
-static int dst_rsaref_verify(const int mode, DST_KEY *key, void **context,
- const u_char *data, const int len,
- const u_char *signature, const int sig_len);
-
-static int dst_rsaref_to_dns_key(const DST_KEY *public, u_char *out_str,
- const int out_len);
-static int dst_rsaref_from_dns_key(DST_KEY *s_key, const u_char *key,
- const int len);
-
-static int dst_rsaref_key_to_file_format(const DST_KEY *dkey,
- u_char *buff,
- const int buff_len);
-static int dst_rsaref_key_from_file_format(DST_KEY *dkey,
- const u_char *buff,
- const int buff_len);
-
-static int dst_rsaref_compare_keys(const DST_KEY *rkey1,
- const DST_KEY *rkey2);
-static void *dst_rsaref_free_key_structure(void *d_key);
-
-static int dst_rsaref_generate_keypair(DST_KEY *key, const int exp);
-
-static void dst_rsaref_init_random_struct(R_RANDOM_STRUCT * randomstruct);
-
-/*
- * dst_rsaref_init() Function to answer set up function pointers for RSAREF
- * related functions
- */
-int
-dst_rsaref_init()
-{
- if (dst_t_func[KEY_RSA] != NULL)
- return (1);
- dst_t_func[KEY_RSA] = malloc(sizeof(struct dst_func));
- if (dst_t_func[KEY_RSA] == NULL)
- return (0);
- memset(dst_t_func[KEY_RSA], 0, sizeof(struct dst_func));
- dst_t_func[KEY_RSA]->sign = dst_rsaref_sign;
- dst_t_func[KEY_RSA]->verify = dst_rsaref_verify;
- dst_t_func[KEY_RSA]->compare = dst_rsaref_compare_keys;
- dst_t_func[KEY_RSA]->generate = dst_rsaref_generate_keypair;
- dst_t_func[KEY_RSA]->destroy = dst_rsaref_free_key_structure;
- dst_t_func[KEY_RSA]->to_dns_key = dst_rsaref_to_dns_key;
- dst_t_func[KEY_RSA]->from_dns_key = dst_rsaref_from_dns_key;
- dst_t_func[KEY_RSA]->to_file_fmt = dst_rsaref_key_to_file_format;
- dst_t_func[KEY_RSA]->from_file_fmt = dst_rsaref_key_from_file_format;
- return (1);
-}
-
-/*
- * dst_rsa_sign
- * Call RSAREF signing functions to sign a block of data.
- * There are three steps to signing, INIT (initialize structures),
- * UPDATE (hash (more) data), FINAL (generate a signature). This
- * routine performs one or more of these steps.
- * Parameters
- * mode SIG_MODE_INIT, SIG_MODE_UPDATE and/or SIG_MODE_FINAL.
- * key pointer to a RSA key structure that points to public key
- * and context to use.
- * data data to be signed.
- * len length in bytes of data.
- * signature location to store signature.
- * sig_len size of the signature storage area
- * returns
- * N Success on SIG_MODE_FINAL = returns signature length in bytes
- * 0 Success on SIG_MODE_INIT and UPDATE
- * <0 Failure
- */
-
-
-static int
-dst_rsaref_sign(const int mode, DST_KEY *dkey, void **context,
- const u_char *data, const int len,
- u_char *signature, const int sig_len)
-{
- int sign_len = 0;
- R_SIGNATURE_CTX *ctx = NULL;
-
- if (mode & SIG_MODE_INIT)
- ctx = malloc(sizeof(*ctx));
- else if (context)
- ctx = (R_SIGNATURE_CTX *) *context;
- if (ctx == NULL)
- return (-1);
-
- if ((mode & SIG_MODE_INIT) && R_SignInit(ctx, DA_MD5))
- return (SIGN_INIT_FAILURE);
-
- /* equivalent of SIG_MODE_UPDATE */
- if ((mode & SIG_MODE_UPDATE) && (data && len > 0) &&
- R_SignUpdate(ctx, (u_char *) data, len))
- return (SIGN_UPDATE_FAILURE);
-
- if (mode & SIG_MODE_FINAL) {
- RSA_Key *key = (RSA_Key *) dkey->dk_KEY_struct;
- if (signature == NULL ||
- sig_len < (int)(key->rk_Public_Key->bits + 7) / 8)
- return (SIGN_FINAL_FAILURE);
- if(key == NULL || key->rk_Private_Key == NULL)
- return (-1);
- if (R_SignFinal(ctx, signature, &sign_len,
- key->rk_Private_Key))
- return (SIGN_FINAL_FAILURE);
- SAFE_FREE(ctx);
- }
- else {
- if (context == NULL)
- return (-1);
- *context = (void *) ctx;
- }
- return (sign_len);
-}
-
-
-/*
- * dst_rsaref_verify()
- * Calls RSAREF verification routines. There are three steps to
- * verification, INIT (initialize structures), UPDATE (hash (more) data),
- * FINAL (generate a signature). This routine performs one or more of
- * these steps.
- * Parameters
- * mode SIG_MODE_INIT, SIG_MODE_UPDATE and/or SIG_MODE_FINAL.
- * key pointer to a RSA key structure that points to public key
- * and context to use.
- * data data signed.
- * len length in bytes of data.
- * signature signature.
- * sig_len length in bytes of signature.
- * returns
- * 0 Success
- * <0 Failure
- */
-
-static int
-dst_rsaref_verify(const int mode, DST_KEY *dkey, void **context,
- const u_char *data, const int len,
- const u_char *signature, const int sig_len)
-{
- R_SIGNATURE_CTX *ctx = NULL;
-
- if (mode & SIG_MODE_INIT)
- ctx = malloc(sizeof(*ctx));
- else if (context)
- ctx = (R_SIGNATURE_CTX *) *context;
- if (ctx == NULL)
- return (-1);
-
- if ((mode & SIG_MODE_INIT) && R_VerifyInit(ctx, DA_MD5))
- return (VERIFY_INIT_FAILURE);
-
- if ((mode & SIG_MODE_UPDATE) && (data && len > 0) &&
- R_VerifyUpdate(ctx, (u_char *) data, len))
- return (VERIFY_UPDATE_FAILURE);
-
- if ((mode & SIG_MODE_FINAL)) {
- RSA_Key *key = (RSA_Key *) dkey->dk_KEY_struct;
-
- if (key == NULL || key->rk_Public_Key == NULL)
- return (-1);
- if (signature == NULL || sig_len <= 0)
- return (VERIFY_FINAL_FAILURE);
- if (R_VerifyFinal(ctx, (u_char *) signature, sig_len,
- key->rk_Public_Key))
- return (VERIFY_FINAL_FAILURE);
- }
- else {
- if (context == NULL)
- return (-1);
- *context = (void *) ctx;
- }
-
- return (0);
-}
-
-
-/*
- * dst_rsaref_to_dns_key
- * Converts key in RSAREF to DNS distribution format
- * This function gets in a pointer to the public key and a work area
- * to write the key into.
- * Parameters
- * public KEY structure
- * out_str buffer to write encoded key into
- * out_len size of out_str
- * Return
- * N >= 0 length of encoded key
- * n < 0 error
- */
-
-static int
-dst_rsaref_to_dns_key(const DST_KEY *in_key, u_char *out_str,
- const int out_len)
-{
- int n, loc;
- R_RSA_PUBLIC_KEY *public;
- u_char *op = (u_char *) out_str;
-
- if (in_key == NULL || in_key->dk_KEY_struct == NULL ||
- out_len <= 0 || out_str == NULL)
- return (-1);
- public = (R_RSA_PUBLIC_KEY *)
- ((RSA_Key *) in_key->dk_KEY_struct)->rk_Public_Key;
- if (public == NULL)
- return (-1);
-
- memset(op, 0, out_len);
-
- /* find first non zero */
- for (n = 0; public->exponent[n] == 0x0; n++) ;
-
- n = (MAX_RSA_MODULUS_LEN - n); /* find lenght of exponent */
- *op++ = (u_int8_t) n;
-
- if (n > (out_len - (op-out_str)))
- return (-1);
- memcpy(op, &public->exponent[MAX_RSA_MODULUS_LEN - n], n);
- op += n;
- n++; /* include the lenght field in this count */
-
- /* find first non zero */
- for (loc = 0; public->modulus[loc] == 0x0; loc++) ;
-
- /*copy exponent */
- if ((MAX_RSA_MODULUS_LEN - loc) > (out_len - (op-out_str)))
- return (-1);
- memcpy(op, &public->modulus[loc], MAX_RSA_MODULUS_LEN - loc);
- n += (MAX_RSA_MODULUS_LEN - loc);
- return (n);
-}
-
-
-/*
- * dst_rsaref_from_dns_key
- * Converts from a DNS KEY RR format to an RSA KEY.
- * Parameters
- * len Length in bytes of DNS key
- * key DNS key
- * name Key name
- * s_key DST structure that will point to the RSA key this routine
- * will build.
- * Return
- * -1 The input key has fields that are larger than this package supports
- * 0 The input key, s_key or name was null.
- * 1 Success
- */
-static int
-dst_rsaref_from_dns_key(DST_KEY *s_key, const u_char *key, const int len)
-{
- int bytes;
- u_char *key_ptr;
- RSA_Key *r_key;
-
- if (key == NULL || s_key == NULL || len < 0)
- return (0);
-
- if (s_key->dk_KEY_struct) { /* do not reuse */
- dst_rsaref_free_key_structure(s_key->dk_KEY_struct);
- s_key->dk_KEY_struct = NULL;
- }
- if (len == 0) /* null key no conversion needed */
- return (1);
-
- if ((r_key = (RSA_Key *) malloc(sizeof(RSA_Key))) == NULL) {
- EREPORT(("dst_rsaref_from_dns_key(): Memory allocation error 1\n"));
- return (0);
- }
- memset(r_key, 0, sizeof(RSA_Key));
- s_key->dk_KEY_struct = (void *) r_key;
- r_key->rk_signer = strdup(s_key->dk_key_name);
- r_key->rk_Public_Key = (R_RSA_PUBLIC_KEY *)
- malloc(sizeof(R_RSA_PUBLIC_KEY));
- if (r_key->rk_Public_Key == NULL) {
- EREPORT(("dst_rsaref_from_dns_key(): Memory allocation error 3\n"));
- return (0);
- }
- memset(r_key->rk_Public_Key, 0, sizeof(R_RSA_PUBLIC_KEY));
- key_ptr = (u_char *) key;
- bytes = (int) *key_ptr++; /* length of exponent in bytes */
- if (bytes == 0) { /* special case for long exponents */
- bytes = (int) dst_s_get_int16(key_ptr);
- key_ptr += sizeof(u_int16_t);
- }
- if (bytes > MAX_RSA_MODULUS_LEN) {
- dst_rsaref_free_key_structure(r_key);
- return (-1);
- }
- memcpy(&r_key->rk_Public_Key->exponent[MAX_RSA_MODULUS_LEN - bytes],
- key_ptr, bytes);
-
- key_ptr += bytes; /* beginning of modulus */
- bytes = len - bytes - 1; /* length of modulus */
- if (bytes > MAX_RSA_MODULUS_LEN) {
- dst_rsaref_free_key_structure(r_key);
- return (-1);
- }
- memcpy(&r_key->rk_Public_Key->modulus[MAX_RSA_MODULUS_LEN - bytes],
- key_ptr, bytes);
- r_key->rk_Public_Key->bits = bytes * 8;
- s_key->dk_key_size = r_key->rk_Public_Key->bits;
-
- return (1);
-}
-
-
-/*
- * dst_rsaref_key_to_file_format
- * Encodes an RSA Key into the portable file format.
- * Parameters
- * rkey RSA KEY structure
- * buff output buffer
- * buff_len size of output buffer
- * Return
- * 0 Failure - null input rkey
- * -1 Failure - not enough space in output area
- * N Success - Length of data returned in buff
- */
-
-static int
-dst_rsaref_key_to_file_format(const DST_KEY *in_key, u_char *buff,
- const int buff_len)
-{
- u_char *bp;
- int len, b_len;
- R_RSA_PRIVATE_KEY *rkey;
-
- if (in_key == NULL || in_key->dk_KEY_struct == NULL)
- return (-1);
- rkey = (R_RSA_PRIVATE_KEY *)
- ((RSA_Key *) in_key->dk_KEY_struct)->rk_Private_Key;
- if (rkey == NULL) /* no output */
- return (0);
- if (buff == NULL || buff_len <= (int) strlen(key_file_fmt_str))
- return (-1); /* no OR not enough space in output area */
-
- memset(buff, 0, buff_len); /* just in case */
- /* write file header */
- sprintf(buff, key_file_fmt_str, KEY_FILE_FORMAT, KEY_RSA, "RSA");
-
- bp = (char *) strchr(buff, '\0');
- b_len = buff_len - (bp - buff);
- if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Modulus: ",
- rkey->modulus,
- MAX_RSA_MODULUS_LEN)) <= 0)
- return (-1);
-
- bp += len;
- b_len -= len;
- if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "PublicExponent: ",
- rkey->publicExponent,
- MAX_RSA_MODULUS_LEN)) <= 0)
- return (-2);
- bp += len;
- b_len -= len;
- if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "PrivateExponent: ",
- rkey->exponent,
- MAX_RSA_MODULUS_LEN)) <= 0)
- return (-3);
- bp += len;
- b_len -= len;
- if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Prime1: ",
- rkey->prime[0],
- MAX_RSA_PRIME_LEN)) < 0)
- return (-4);
- bp += len;
- b_len -= len;
- if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Prime2: ",
- rkey->prime[1],
- MAX_RSA_PRIME_LEN)) < 0)
- return (-5);
- bp += len;
- b_len -= len;
- if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Exponent1: ",
- rkey->primeExponent[0],
- MAX_RSA_PRIME_LEN)) < 0)
- return (-6);
- bp += len;
- b_len -= len;
- if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Exponent2: ",
- rkey->primeExponent[1],
- MAX_RSA_PRIME_LEN)) < 0)
- return (-7);
- bp += len;
- b_len -= len;
- if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Coefficient: ",
- rkey->coefficient,
- MAX_RSA_PRIME_LEN)) < 0)
- return (-8);
- bp += len;
- b_len -= len;
- return (buff_len - b_len);
-}
-
-
-/*
- * dst_rsaref_key_from_file_format
- * Converts contents of a private key file into a private RSA key.
- * Parameters
- * r_key structure to put key into
- * buff buffer containing the encoded key
- * buff_len the length of the buffer
- * Return
- * n >= 0 Foot print of the key converted
- * n < 0 Error in conversion
- */
-
-static int
-dst_rsaref_key_from_file_format(DST_KEY *d_key, const u_char *buff,
- const int buff_len)
-{
- const char *p = (char *) buff;
- R_RSA_PRIVATE_KEY key;
- int foot = -1;
- RSA_Key *r_key;
-
- if (d_key == NULL || buff == NULL || buff_len < 0)
- return (-1);
-
- memset(&key, 0, sizeof(key));
-
- if (!dst_s_verify_str(&p, "Modulus: "))
- return (-3);
-
- if (!dst_s_conv_bignum_b64_to_u8(&p, key.modulus, MAX_RSA_MODULUS_LEN))
- return (-4);
-
- key.bits = dst_s_calculate_bits(key.modulus, MAX_RSA_MODULUS_BITS);
-
- while (*++p && p < (char *) &buff[buff_len]) {
- if (dst_s_verify_str(&p, "PublicExponent: ")) {
- if (!dst_s_conv_bignum_b64_to_u8(&p,
- key.publicExponent,
- MAX_RSA_MODULUS_LEN))
- return (-5);
- } else if (dst_s_verify_str(&p, "PrivateExponent: ")) {
- if (!dst_s_conv_bignum_b64_to_u8(&p, key.exponent,
- MAX_RSA_MODULUS_LEN))
- return (-6);
- } else if (dst_s_verify_str(&p, "Prime1: ")) {
- if (!dst_s_conv_bignum_b64_to_u8(&p, key.prime[0],
- MAX_RSA_PRIME_LEN))
- return (-7);
- } else if (dst_s_verify_str(&p, "Prime2: ")) {
- if (!dst_s_conv_bignum_b64_to_u8(&p, key.prime[1],
- MAX_RSA_PRIME_LEN))
- return (-8);
- } else if (dst_s_verify_str(&p, "Exponent1: ")) {
- if (!dst_s_conv_bignum_b64_to_u8(&p,
- key.primeExponent[0],
- MAX_RSA_PRIME_LEN))
- return (-9);
- } else if (dst_s_verify_str(&p, "Exponent2: ")) {
- if (!dst_s_conv_bignum_b64_to_u8(&p,
- key.primeExponent[1],
- MAX_RSA_PRIME_LEN))
- return (-10);
- } else if (dst_s_verify_str(&p, "Coefficient: ")) {
- if (!dst_s_conv_bignum_b64_to_u8(&p, key.coefficient,
- MAX_RSA_PRIME_LEN))
- return (-11);
- } else {
- EREPORT(("dst_rsaref_key_from_file_format: Bad keyword %s\n", p));
- return (-12);
- }
- } /* while p */
-
- r_key = (RSA_Key *) malloc(sizeof(RSA_Key));
- if (r_key == NULL) {
- return (-2);
- }
- memset(r_key, 0, sizeof(*r_key));
-
- r_key->rk_Private_Key =
- (R_RSA_PRIVATE_KEY *) malloc(sizeof(R_RSA_PRIVATE_KEY));
- if (r_key->rk_Private_Key == NULL) {
- EREPORT(("dst_rsaref_key_from_file_format: Memory allocation error\n"));
- return (-13);
- }
- r_key->rk_Public_Key = (R_RSA_PUBLIC_KEY *) r_key->rk_Private_Key;
- memcpy(r_key->rk_Private_Key, &key, sizeof(R_RSA_PRIVATE_KEY));
-
- r_key->rk_signer = strdup(d_key->dk_key_name);
- d_key->dk_KEY_struct = (void *) r_key;
- d_key->dk_key_size = r_key->rk_Private_Key->bits;
-
- return (0);
-}
-
-
-
-/*
- * dst_rsaref_compare_keys
- * Compare two keys for equality.
- * Return
- * 0 The keys are equal
- * NON-ZERO The keys are not equal
- */
-
-static int
-dst_rsaref_compare_keys(const DST_KEY *dkey1, const DST_KEY *dkey2)
-{
- RSA_Key *rkey1 = (RSA_Key *) dkey1->dk_KEY_struct;
- RSA_Key *rkey2 = (RSA_Key *) dkey2->dk_KEY_struct;
-
- if (rkey1 == NULL && rkey2 == NULL)
- return (0); /* same */
- else if (rkey1 == NULL)
- return (1);
- else if (rkey2 == NULL)
- return (2);
- return (memcmp(rkey1->rk_Public_Key, rkey2->rk_Public_Key,
- sizeof(R_RSA_PUBLIC_KEY)));
-}
-
-/*
- * dst_rsaref_generate_keypair
- * Generates unique keys that are hard to predict.
- * Parameters
- * key generic Key structure
- * exp the public exponent
- * Return
- * 0 Failure
- * 1 Success
- */
-
-static int
-dst_rsaref_generate_keypair(DST_KEY *key, const int exp)
-{
- R_RSA_PUBLIC_KEY *public;
- R_RSA_PRIVATE_KEY *private;
- R_RSA_PROTO_KEY proto;
- R_RANDOM_STRUCT randomStruct;
- RSA_Key *rsa;
- int status;
-
- if (key == NULL || key->dk_alg != KEY_RSA)
- return (0);
- if (key->dk_key_size < MIN_RSA_MODULUS_BITS ||
- key->dk_key_size > MAX_RSA_MODULUS_BITS) {
- EREPORT(("dst_rsaref_generate_keypair: Invalid key size\n"));
- return (0); /* these are the limits on key size in RSAREF */
- }
- /* allocate space */
- if ((public = (R_RSA_PUBLIC_KEY *) malloc(sizeof(R_RSA_PUBLIC_KEY)))
- == NULL) {
- EREPORT(("dst_rsaref_generate_keypair: Memory allocation error 1\n"));
- return (0);
- }
- if ((private = (R_RSA_PRIVATE_KEY *) malloc(sizeof(R_RSA_PRIVATE_KEY)))
- == NULL) {
- EREPORT(("dst_rsaref_generate_keypair: Memory allocation error 2\n"));
- return (0);
- }
- if ((rsa = (RSA_Key *) malloc(sizeof(RSA_Key))) == NULL) {
- EREPORT(("dst_rsaref_generate_keypair: Memory allocation error 3\n"));
- return (0);
- }
- memset(public, 0, sizeof(*public));
- memset(private, 0, sizeof(*private));
-
- proto.bits = key->dk_key_size;
- proto.useFermat4 = exp ? 0x1 : 0x0; /* 1 for f4=65537, 0 for f0=3 */
- EREPORT(("\ndst_rsaref_generate_keypair: Generating KEY for %s Please wait\n",
- key->dk_key_name));
-
- /* set up random seed */
- dst_rsaref_init_random_struct(&randomStruct);
-
- /* generate keys */
- status = R_GeneratePEMKeys(public, private, &proto, &randomStruct);
- if (status) {
- EREPORT(("dst_rsaref_generate_keypair: No Key Pair generated %d\n",
- status));
- SAFE_FREE(public);
- SAFE_FREE(private);
- SAFE_FREE(rsa);
- return (0);
- }
- memset(rsa, 0, sizeof(*rsa));
- rsa->rk_signer = key->dk_key_name;
- rsa->rk_Private_Key = private;
- rsa->rk_Public_Key = public;
- key->dk_KEY_struct = (void *) rsa;
-
- return (1);
-}
-
-
-/*
- * dst_rsaref_free_key_structure
- * Frees all dynamicly allocated structures in r_key
- */
-
-static void *
-dst_rsaref_free_key_structure(void *v_key)
-{
- RSA_Key *r_key = (RSA_Key *) v_key;
-
- if (r_key != NULL) {
- if ((void *) r_key->rk_Private_Key == (void *) r_key->rk_Public_Key)
- r_key->rk_Public_Key = NULL;
- SAFE_FREE(r_key->rk_Private_Key);
- SAFE_FREE(r_key->rk_Public_Key);
- SAFE_FREE(r_key->rk_signer);
- SAFE_FREE(r_key);
- }
- return (NULL);
-}
-
-
-/*
- * dst_rsaref_init_random_struct
- * A random seed value is used in key generation.
- * This routine gets a bunch of system values to randomize the
- * randomstruct. A number of system calls are used to get somewhat
- * unpredicable values, then a special function dst_s_prandom() is called
- * that will do some magic depending on the system used.
- * If this function is executed on reasonably busy machine then the values
- * that prandom uses are hard to
- * 1. Predict
- * 2. Regenerate
- * 3. Hard to spy on as nothing is stored to disk and data is consumed
- * as fast as it is generated.
- */
-
-static void
-dst_rsaref_init_random_struct(R_RANDOM_STRUCT * randomstruct)
-{
- unsigned bytesNeeded;
- struct timeval tv;
- u_char *array;
- int n;
-
- R_RandomInit(randomstruct);
-
- /* The runtime of the script is unpredictable within some range
- * thus I'm getting the time of day again as this is an hard to guess
- * value and the number of characters of the output from the script is
- * hard to guess.
- * This must be the FIRST CALL
- */
- gettimeofday(&tv, 0);
- R_RandomUpdate(randomstruct, (u_char *) &tv,
- sizeof(struct timeval));
-
- /*
- * first find out how many bytes I need
- */
- R_GetRandomBytesNeeded(&bytesNeeded, randomstruct);
-
- /*
- * get a storage area for it addjust the area for the possible
- * side effects of digest functions writing out in blocks
- */
- array = (u_char *) malloc(bytesNeeded);
-
- /* extract the random data from /dev/random if present, generate
- * it if not present
- * first fill the buffer with semi random data
- * then fill as much as possible with good random data
- */
- n = dst_random(DST_RAND_SEMI, bytesNeeded, array);
- n += dst_random(DST_RAND_KEY, bytesNeeded, array);
- if (n <= bytesNeeded) {
- SAFE_FREE(array);
- return(0);
- }
-
- /* supply the random data (even if it is larger than requested) */
- R_RandomUpdate(randomstruct, array, bytesNeeded);
-
- SAFE_FREE(array);
-
- R_GetRandomBytesNeeded(&bytesNeeded, randomstruct);
- if (bytesNeeded) {
- EREPORT(("InitRandomStruct() didn't initialize enough randomness\n"));
- exit(33);
- }
-}
-
-
-#else
-#include "port_before.h"
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <memory.h>
-#include <sys/param.h>
-#include <sys/time.h>
-#include <netinet/in.h>
-
-#include "dst_internal.h"
-#include "port_after.h"
-int /* rsaref is not available */
-dst_rsaref_init()
-{
- return (0);
-}
-#endif /* RSAREF */
diff --git a/contrib/bind/lib/dst/support.c b/contrib/bind/lib/dst/support.c
deleted file mode 100644
index 6cc0bd1..0000000
--- a/contrib/bind/lib/dst/support.c
+++ /dev/null
@@ -1,459 +0,0 @@
-static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/support.c,v 1.11 2001/05/29 05:48:16 marka Exp $";
-
-
-/*
- * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc.
- *
- * 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 TRUSTED INFORMATION SYSTEMS
- * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
- * TRUSTED INFORMATION SYSTEMS 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 THE SOFTWARE.
- */
-
-#include "port_before.h"
-
-#include <stdio.h>
-#include <unistd.h>
-#include <memory.h>
-#include <string.h>
-#include <errno.h>
-#include <sys/stat.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-
-#include "dst_internal.h"
-
-#include "port_after.h"
-/*
- * dst_s_conv_bignum_u8_to_b64
- * This function converts binary data stored as a u_char[] to a
- * base-64 string. Leading zeroes are discarded. If a header is
- * supplied, it is prefixed to the input prior to encoding. The
- * output is \n\0 terminated (the \0 is not included in output length).
- * Parameters
- * out_buf binary data to convert
- * header character string to prefix to the output (label)
- * bin_data binary data
- * bin_len size of binary data
- * Return
- * -1 not enough space in output work area
- * 0 no output
- * >0 number of bytes written to output work area
- */
-
-int
-dst_s_conv_bignum_u8_to_b64(char *out_buf, const int out_len,
- const char *header, const u_char *bin_data,
- const int bin_len)
-{
- const u_char *bp = bin_data;
- char *op = out_buf;
- int lenh = 0, len64 = 0;
- int local_in_len = bin_len;
- int local_out_len = out_len;
-
- if (bin_data == NULL || bin_len <= 0) /* no data no */
- return (0);
-
- if (out_buf == NULL || out_len <= 0) /* no output_work area */
- return (-1);
-
- /* suppress leading \0 */
- for (; (*bp == 0x0) && (local_in_len > 0); local_in_len--)
- bp++;
-
- if (header) { /* add header to output string */
- lenh = strlen(header);
- if (lenh < out_len)
- memcpy(op, header, lenh);
- else
- return (-1);
- local_out_len -= lenh;
- op += lenh;
- }
- len64 = b64_ntop(bp, local_in_len, op, local_out_len - 2);
- if (len64 < 0)
- return (-1);
- op += len64++;
- *(op++) = '\n'; /* put CR in the output */
- *op = '\0'; /* make sure output is 0 terminated */
- return (lenh + len64);
-}
-
-
-/*
- * dst_s_verify_str()
- * Validate that the input string(*str) is at the head of the input
- * buffer(**buf). If so, move the buffer head pointer (*buf) to
- * the first byte of data following the string(*str).
- * Parameters
- * buf Input buffer.
- * str Input string.
- * Return
- * 0 *str is not the head of **buff
- * 1 *str is the head of **buff, *buf is is advanced to
- * the tail of **buf.
- */
-
-int
-dst_s_verify_str(const char **buf, const char *str)
-{
- int b, s;
- if (*buf == NULL) /* error checks */
- return (0);
- if (str == NULL || *str == '\0')
- return (1);
-
- b = strlen(*buf); /* get length of strings */
- s = strlen(str);
- if (s > b || strncmp(*buf, str, s)) /* check if same */
- return (0); /* not a match */
- (*buf) += s; /* advance pointer */
- return (1);
-}
-
-
-/*
- * dst_s_conv_bignum_b64_to_u8
- * Read a line of base-64 encoded string from the input buffer,
- * convert it to binary, and store it in an output area. The
- * input buffer is read until reaching a newline marker or the
- * end of the buffer. The binary data is stored in the last X
- * number of bytes of the output area where X is the size of the
- * binary output. If the operation is successful, the input buffer
- * pointer is advanced. This procedure does not do network to host
- * byte order conversion.
- * Parameters
- * buf Pointer to encoded input string. Pointer is updated if
- * function is successfull.
- * loc Output area.
- * loclen Size in bytes of output area.
- * Return
- * >0 Return = number of bytes of binary data stored in loc.
- * 0 Failure.
- */
-
-int
-dst_s_conv_bignum_b64_to_u8(const char **buf, u_char *loc, const int loclen)
-{
- int blen;
- char *bp;
- u_char bstr[RAW_KEY_SIZE];
-
- if (buf == NULL || *buf == NULL) { /* error checks */
- EREPORT(("dst_s_conv_bignum_b64_to_u8: null input buffer.\n"));
- return (0);
- }
- bp = strchr(*buf, '\n'); /* find length of input line */
- if (bp != NULL)
- *bp = (u_char) NULL;
-
- blen = b64_pton(*buf, bstr, sizeof(bstr));
- if (blen <= 0) {
- EREPORT(("dst_s_conv_bignum_b64_to_u8: decoded value is null.\n"));
- return (0);
- }
- else if (loclen < blen) {
- EREPORT(("dst_s_conv_bignum_b64_to_u8: decoded value is longer than output buffer.\n"));
- return (0);
- }
- if (bp)
- *buf = bp; /* advancing buffer past \n */
- memset(loc, 0, loclen - blen); /* clearing unused output area */
- memcpy(loc + loclen - blen, bstr, blen); /* write last blen bytes */
- return (blen);
-}
-
-
-/*
- * dst_s_calculate_bits
- * Given a binary number represented in a u_char[], determine
- * the number of significant bits used.
- * Parameters
- * str An input character string containing a binary number.
- * max_bits The maximum possible significant bits.
- * Return
- * N The number of significant bits in str.
- */
-
-int
-dst_s_calculate_bits(const u_char *str, const int max_bits)
-{
- const u_char *p = str;
- u_char i, j = 0x80;
- int bits;
- for (bits = max_bits; *p == 0x00 && bits > 0; p++)
- bits -= 8;
- for (i = *p; (i & j) != j; j >>= 1)
- bits--;
- return (bits);
-}
-
-
-/*
- * calculates a checksum used in dst for an id.
- * takes an array of bytes and a length.
- * returns a 16 bit checksum.
- */
-u_int16_t
-dst_s_id_calc(const u_char *key, const int keysize)
-{
- u_int32_t ac;
- const u_char *kp = key;
- int size = keysize;
-
- if (!key || (keysize <= 0))
- return (-1);
-
- for (ac = 0; size > 1; size -= 2, kp += 2)
- ac += ((*kp) << 8) + *(kp + 1);
-
- if (size > 0)
- ac += ((*kp) << 8);
- ac += (ac >> 16) & 0xffff;
-
- return (ac & 0xffff);
-}
-
-/*
- * dst_s_dns_key_id() Function to calculate DNSSEC footprint from KEY record
- * rdata
- * Input:
- * dns_key_rdata: the raw data in wire format
- * rdata_len: the size of the input data
- * Output:
- * the key footprint/id calculated from the key data
- */
-u_int16_t
-dst_s_dns_key_id(const u_char *dns_key_rdata, const int rdata_len)
-{
- if (!dns_key_rdata)
- return 0;
-
- /* compute id */
- if (dns_key_rdata[3] == KEY_RSA) /* Algorithm RSA */
- return dst_s_get_int16((const u_char *)
- &dns_key_rdata[rdata_len - 3]);
- else if (dns_key_rdata[3] == KEY_HMAC_MD5)
- /* compatibility */
- return 0;
- else
- /* compute a checksum on the key part of the key rr */
- return dst_s_id_calc(dns_key_rdata, rdata_len);
-}
-
-/*
- * dst_s_get_int16
- * This routine extracts a 16 bit integer from a two byte character
- * string. The character string is assumed to be in network byte
- * order and may be unaligned. The number returned is in host order.
- * Parameter
- * buf A two byte character string.
- * Return
- * The converted integer value.
- */
-
-u_int16_t
-dst_s_get_int16(const u_char *buf)
-{
- register u_int16_t a = 0;
- a = ((u_int16_t)(buf[0] << 8)) | ((u_int16_t)(buf[1]));
- return (a);
-}
-
-
-/*
- * dst_s_get_int32
- * This routine extracts a 32 bit integer from a four byte character
- * string. The character string is assumed to be in network byte
- * order and may be unaligned. The number returned is in host order.
- * Parameter
- * buf A four byte character string.
- * Return
- * The converted integer value.
- */
-
-u_int32_t
-dst_s_get_int32(const u_char *buf)
-{
- register u_int32_t a = 0;
- a = ((u_int32_t)(buf[0] << 24)) | ((u_int32_t)(buf[1] << 16)) |
- ((u_int32_t)(buf[2] << 8)) | ((u_int32_t)(buf[3]));
- return (a);
-}
-
-
-/*
- * dst_s_put_int16
- * Take a 16 bit integer and store the value in a two byte
- * character string. The integer is assumed to be in network
- * order and the string is returned in host order.
- *
- * Parameters
- * buf Storage for a two byte character string.
- * val 16 bit integer.
- */
-
-void
-dst_s_put_int16(u_int8_t *buf, const u_int16_t val)
-{
- buf[0] = (u_int8_t)(val >> 8);
- buf[1] = (u_int8_t)(val);
-}
-
-
-/*
- * dst_s_put_int32
- * Take a 32 bit integer and store the value in a four byte
- * character string. The integer is assumed to be in network
- * order and the string is returned in host order.
- *
- * Parameters
- * buf Storage for a four byte character string.
- * val 32 bit integer.
- */
-
-void
-dst_s_put_int32(u_int8_t *buf, const u_int32_t val)
-{
- buf[0] = (u_int8_t)(val >> 24);
- buf[1] = (u_int8_t)(val >> 16);
- buf[2] = (u_int8_t)(val >> 8);
- buf[3] = (u_int8_t)(val);
-}
-
-
-/*
- * dst_s_filename_length
- *
- * This function returns the number of bytes needed to hold the
- * filename for a key file. '/', '\' and ':' are not allowed.
- * form: K<keyname>+<alg>+<id>.<suffix>
- *
- * Returns 0 if the filename would contain either '\', '/' or ':'
- */
-size_t
-dst_s_filename_length(const char *name, const char *suffix)
-{
- if (name == NULL)
- return (0);
- if (strrchr(name, '\\'))
- return (0);
- if (strrchr(name, '/'))
- return (0);
- if (strrchr(name, ':'))
- return (0);
- if (suffix == NULL)
- return (0);
- if (strrchr(suffix, '\\'))
- return (0);
- if (strrchr(suffix, '/'))
- return (0);
- if (strrchr(suffix, ':'))
- return (0);
- return (1 + strlen(name) + 6 + strlen(suffix));
-}
-
-
-/*
- * dst_s_build_filename ()
- * Builds a key filename from the key name, it's id, and a
- * suffix. '\', '/' and ':' are not allowed. fA filename is of the
- * form: K<keyname><id>.<suffix>
- * form: K<keyname>+<alg>+<id>.<suffix>
- *
- * Returns -1 if the conversion fails:
- * if the filename would be too long for space allotted
- * if the filename would contain a '\', '/' or ':'
- * Returns 0 on success
- */
-
-int
-dst_s_build_filename(char *filename, const char *name, u_int16_t id,
- int alg, const char *suffix, size_t filename_length)
-{
- u_int32_t my_id;
- if (filename == NULL)
- return (-1);
- memset(filename, 0, filename_length);
- if (name == NULL)
- return (-1);
- if (suffix == NULL)
- return (-1);
- if (filename_length < 1 + strlen(name) + 4 + 6 + 1 + strlen(suffix))
- return (-1);
- my_id = id;
- sprintf(filename, "K%s+%03d+%05d.%s", name, alg, my_id,
- (const char *) suffix);
- if (strrchr(filename, '/'))
- return (-1);
- if (strrchr(filename, '\\'))
- return (-1);
- if (strrchr(filename, ':'))
- return (-1);
- return (0);
-}
-
-/*
- * dst_s_fopen ()
- * Open a file in the dst_path directory. If perm is specified, the
- * file is checked for existence first, and not opened if it exists.
- * Parameters
- * filename File to open
- * mode Mode to open the file (passed directly to fopen)
- * perm File permission, if creating a new file.
- * Returns
- * NULL Failure
- * NON-NULL (FILE *) of opened file.
- */
-FILE *
-dst_s_fopen(const char *filename, const char *mode, int perm)
-{
- FILE *fp;
- char pathname[PATH_MAX];
- size_t plen = sizeof(pathname);
-
- if (*dst_path != '\0') {
- strcpy(pathname, dst_path);
- plen -= strlen(pathname);
- }
- else
- pathname[0] = '\0';
-
- if (plen > strlen(filename))
- strncpy(&pathname[PATH_MAX - plen], filename, plen-1);
- else
- return (NULL);
-
- fp = fopen(pathname, mode);
- if (perm)
- chmod(pathname, perm);
- return (fp);
-}
-
-void
-dst_s_dump(const int mode, const u_char *data, const int size,
- const char *msg)
-{
- UNUSED(data);
-
- if (size > 0) {
-#ifdef LONG_TEST
- static u_char scratch[1000];
- int n ;
- n = b64_ntop(data, scratch, size, sizeof(scratch));
- printf("%s: %x %d %s\n", msg, mode, n, scratch);
-#else
- printf("%s,%x %d\n", msg, mode, size);
-#endif
- }
-}
diff --git a/contrib/bind/lib/inet/Makefile b/contrib/bind/lib/inet/Makefile
deleted file mode 100644
index a448e61..0000000
--- a/contrib/bind/lib/inet/Makefile
+++ /dev/null
@@ -1,97 +0,0 @@
-# Copyright (c) 1996,1999 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.
-
-# $Id: Makefile,v 8.23 2001/08/14 05:58:05 marka Exp $
-
-# these are only appropriate for BSD 4.4 or derivatives, and are used in
-# development. normal builds will be done in the top level directory and
-# this Makefile will be invoked with a lot of overrides for the following:
-SYSTYPE= freebsd
-DESTDIR =
-DESTLIB = /usr/local/lib
-O=o
-A=a
-CC= cc
-LD= ld
-SHELL= /bin/sh
-CDEBUG= -g -Wall
-TOP= ../..
-INCL = ${TOP}/include
-PORTINCL = ${TOP}/port/${SYSTYPE}/include
-LIBBIND = ${TOP}/lib/libbind.${A}
-LIBBINDR = ../${TOP}/lib/libbind_r.${A}
-CFLAGS= ${CDEBUG}
-CPPFLAGS= -I${PORTINCL} -I${INCL}
-LD_LIBFLAGS= -x -r
-AR= ar cru
-RANLIB= ranlib
-INSTALL= install
-INSTALL_EXEC=
-INSTALL_LIB=-o bin -g bin
-THREADED= threaded
-
-SRCS= nsap_addr.c inet_addr.c inet_ntop.c inet_pton.c \
- inet_ntoa.c inet_neta.c inet_net_ntop.c inet_net_pton.c \
- inet_cidr_ntop.c inet_cidr_pton.c \
- inet_lnaof.c inet_makeaddr.c inet_netof.c inet_network.c \
- inet_data.c
-
-OBJS= nsap_addr.${O} inet_addr.${O} inet_ntop.${O} inet_pton.${O} \
- inet_ntoa.${O} inet_neta.${O} inet_net_ntop.${O} inet_net_pton.${O} \
- inet_cidr_ntop.${O} inet_cidr_pton.${O} \
- inet_lnaof.${O} inet_makeaddr.${O} inet_netof.${O} inet_network.${O} \
- inet_data.${O}
-
-all: ${LIBBIND}
-
-${LIBBIND}: ${OBJS}
- ( cd ${THREADED} ; \
- ${AR} ${LIBBINDR} ${ARPREF} ${OBJS} ${ARSUFF} ; \
- ${RANLIB} ${LIBBINDR} )
- ${AR} ${LIBBIND} ${ARPREF} ${OBJS} ${ARSUFF}
- ${RANLIB} ${LIBBIND}
-
-.c.${O}:
- mkdir ${THREADED} 2> /dev/null || test -d ${THREADED} -a -w ${THREADED}
- ${CC} ${CPPFLAGS} ${CFLAGS} ${BOUNDS} ${REENTRANT} -c $*.c \
- -o ${THREADED}/$*.${O}
- -${LDS} ${LD} ${LD_LIBFLAGS} ${THREADED}/$*.${O} \
- -o ${THREADED}/$*.out && \
- ${LDS} mv ${THREADED}/$*.out ${THREADED}/$*.${O}
- ${CC} ${CPPFLAGS} ${CFLAGS} ${BOUNDS} -c $*.c
- -${LDS} ${LD} ${LD_LIBFLAGS} $*.${O} -o $*.out && \
- ${LDS} mv $*.out $*.${O}
-
-distclean: clean
-
-clean: FRC
- rm -f .depend a.out core ${LIB} tags
- rm -f *.${O} *.BAK *.CKP *~
- rm -f ${THREADED}/*.${O}
- -if test -d ${THREADED} ; then rmdir ${THREADED}; else true; fi
-
-
-depend: FRC
- mkdep -I${INCL} -I${PORTINCL} ${CPPFLAGS} ${SRCS}
-
-links: FRC
- @set -e; ln -s SRC/*.[ch] .
-
-install:
-
-FRC:
-
-# DO NOT DELETE THIS LINE -- mkdep uses it.
-# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
diff --git a/contrib/bind/lib/inet/inet_addr.c b/contrib/bind/lib/inet/inet_addr.c
deleted file mode 100644
index b68190c..0000000
--- a/contrib/bind/lib/inet/inet_addr.c
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Copyright (c) 1983, 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Portions Copyright (c) 1993 by Digital Equipment Corporation.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies, and that
- * the name of Digital Equipment Corporation not be used in advertising or
- * publicity pertaining to distribution of the document or software without
- * specific, written prior permission.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
- * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-/*
- * Portions Copyright (c) 1996-1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93";
-static const char rcsid[] = "$Id: inet_addr.c,v 8.12 2001/05/29 05:48:18 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <sys/param.h>
-
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include <ctype.h>
-
-#include "port_after.h"
-
-/*
- * Ascii internet address interpretation routine.
- * The value returned is in network order.
- */
-u_long
-inet_addr(const char *cp) {
- struct in_addr val;
-
- if (inet_aton(cp, &val))
- return (val.s_addr);
- return (INADDR_NONE);
-}
-
-/*
- * Check whether "cp" is a valid ascii representation
- * of an Internet address and convert to a binary address.
- * Returns 1 if the address is valid, 0 if not.
- * This replaces inet_addr, the return value from which
- * cannot distinguish between failure and a local broadcast address.
- */
-int
-inet_aton(const char *cp, struct in_addr *addr) {
- u_long val;
- int base, n;
- char c;
- u_int8_t parts[4];
- u_int8_t *pp = parts;
- int digit;
-
- c = *cp;
- for (;;) {
- /*
- * Collect number up to ``.''.
- * Values are specified as for C:
- * 0x=hex, 0=octal, isdigit=decimal.
- */
- if (!isdigit((unsigned char)c))
- return (0);
- val = 0; base = 10; digit = 0;
- if (c == '0') {
- c = *++cp;
- if (c == 'x' || c == 'X')
- base = 16, c = *++cp;
- else {
- base = 8;
- digit = 1 ;
- }
- }
- for (;;) {
- if (isascii(c) && isdigit((unsigned char)c)) {
- if (base == 8 && (c == '8' || c == '9'))
- return (0);
- val = (val * base) + (c - '0');
- c = *++cp;
- digit = 1;
- } else if (base == 16 && isascii(c) &&
- isxdigit((unsigned char)c)) {
- val = (val << 4) |
- (c + 10 - (islower((unsigned char)c) ? 'a' : 'A'));
- c = *++cp;
- digit = 1;
- } else
- break;
- }
- if (c == '.') {
- /*
- * Internet format:
- * a.b.c.d
- * a.b.c (with c treated as 16 bits)
- * a.b (with b treated as 24 bits)
- */
- if (pp >= parts + 3 || val > 0xff)
- return (0);
- *pp++ = val;
- c = *++cp;
- } else
- break;
- }
- /*
- * Check for trailing characters.
- */
- if (c != '\0' && (!isascii(c) || !isspace((unsigned char)c)))
- return (0);
- /*
- * Did we get a valid digit?
- */
- if (!digit)
- return (0);
- /*
- * Concoct the address according to
- * the number of parts specified.
- */
- n = pp - parts + 1;
- switch (n) {
- case 1: /* a -- 32 bits */
- break;
-
- case 2: /* a.b -- 8.24 bits */
- if (val > 0xffffff)
- return (0);
- val |= parts[0] << 24;
- break;
-
- case 3: /* a.b.c -- 8.8.16 bits */
- if (val > 0xffff)
- return (0);
- val |= (parts[0] << 24) | (parts[1] << 16);
- break;
-
- case 4: /* a.b.c.d -- 8.8.8.8 bits */
- if (val > 0xff)
- return (0);
- val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
- break;
- }
- if (addr != NULL)
- addr->s_addr = htonl(val);
- return (1);
-}
diff --git a/contrib/bind/lib/inet/inet_cidr_ntop.c b/contrib/bind/lib/inet/inet_cidr_ntop.c
deleted file mode 100644
index 0acff76..0000000
--- a/contrib/bind/lib/inet/inet_cidr_ntop.c
+++ /dev/null
@@ -1,259 +0,0 @@
-/*
- * Copyright (c) 1998,1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: inet_cidr_ntop.c,v 8.7 2001/09/28 05:19:36 marka Exp $";
-#endif
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <arpa/inet.h>
-
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include "port_after.h"
-
-#ifdef SPRINTF_CHAR
-# define SPRINTF(x) strlen(sprintf/**/x)
-#else
-# define SPRINTF(x) ((size_t)sprintf x)
-#endif
-
-static char * inet_cidr_ntop_ipv4 __P((const u_char *src, int bits,
- char *dst, size_t size));
-static char * inet_cidr_ntop_ipv6 __P((const u_char *src, int bits,
- char *dst, size_t size));
-
-/*
- * char *
- * inet_cidr_ntop(af, src, bits, dst, size)
- * convert network address from network to presentation format.
- * "src"'s size is determined from its "af".
- * return:
- * pointer to dst, or NULL if an error occurred (check errno).
- * note:
- * 192.5.5.1/28 has a nonzero host part, which means it isn't a network
- * as called for by inet_net_ntop() but it can be a host address with
- * an included netmask.
- * author:
- * Paul Vixie (ISC), October 1998
- */
-char *
-inet_cidr_ntop(int af, const void *src, int bits, char *dst, size_t size) {
- switch (af) {
- case AF_INET:
- return (inet_cidr_ntop_ipv4(src, bits, dst, size));
- case AF_INET6:
- return (inet_cidr_ntop_ipv6(src, bits, dst, size));
- default:
- errno = EAFNOSUPPORT;
- return (NULL);
- }
-}
-
-static int
-decoct(const u_char *src, int bytes, char *dst, size_t size) {
- char *odst = dst;
- char *t;
- int b;
-
- for (b = 1; b <= bytes; b++) {
- if (size < sizeof "255.")
- return (0);
- t = dst;
- dst += SPRINTF((dst, "%u", *src++));
- if (b != bytes) {
- *dst++ = '.';
- *dst = '\0';
- }
- size -= (size_t)(dst - t);
- }
- return (dst - odst);
-}
-
-/*
- * static char *
- * inet_cidr_ntop_ipv4(src, bits, dst, size)
- * convert IPv4 network address from network to presentation format.
- * "src"'s size is determined from its "af".
- * return:
- * pointer to dst, or NULL if an error occurred (check errno).
- * note:
- * network byte order assumed. this means 192.5.5.240/28 has
- * 0b11110000 in its fourth octet.
- * author:
- * Paul Vixie (ISC), October 1998
- */
-static char *
-inet_cidr_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size) {
- char *odst = dst;
- size_t len = 4;
- size_t b;
- size_t bytes;
-
- if ((bits < -1) || (bits > 32)) {
- errno = EINVAL;
- return (NULL);
- }
-
- /* Find number of significant bytes in address. */
- if (bits == -1)
- len = 4;
- else
- for (len = 1, b = 1 ; b < 4; b++)
- if (*(src + b))
- len = b + 1;
-
- /* Format whole octets plus nonzero trailing octets. */
- bytes = (((bits <= 0) ? 1 : bits) + 7) / 8;
- if (len > bytes)
- bytes = len;
- b = decoct(src, bytes, dst, size);
- if (b == 0)
- goto emsgsize;
- dst += b;
- size -= b;
-
- if (bits != -1) {
- /* Format CIDR /width. */
- if (size < sizeof "/32")
- goto emsgsize;
- dst += SPRINTF((dst, "/%u", bits));
- }
-
- return (odst);
-
- emsgsize:
- errno = EMSGSIZE;
- return (NULL);
-}
-
-static char *
-inet_cidr_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size) {
- /*
- * Note that int32_t and int16_t need only be "at least" large enough
- * to contain a value of the specified size. On some systems, like
- * Crays, there is no such thing as an integer variable with 16 bits.
- * Keep this in mind if you think this function should have been coded
- * to use pointer overlays. All the world's not a VAX.
- */
- char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255/128"];
- char *tp;
- struct { int base, len; } best, cur;
- u_int words[NS_IN6ADDRSZ / NS_INT16SZ];
- int i;
-
- if ((bits < -1) || (bits > 128)) {
- errno = EINVAL;
- return (NULL);
- }
-
- /*
- * Preprocess:
- * Copy the input (bytewise) array into a wordwise array.
- * Find the longest run of 0x00's in src[] for :: shorthanding.
- */
- memset(words, '\0', sizeof words);
- for (i = 0; i < NS_IN6ADDRSZ; i++)
- words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3));
- best.base = -1;
- cur.base = -1;
- for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
- if (words[i] == 0) {
- if (cur.base == -1)
- cur.base = i, cur.len = 1;
- else
- cur.len++;
- } else {
- if (cur.base != -1) {
- if (best.base == -1 || cur.len > best.len)
- best = cur;
- cur.base = -1;
- }
- }
- }
- if (cur.base != -1) {
- if (best.base == -1 || cur.len > best.len)
- best = cur;
- }
- if (best.base != -1 && best.len < 2)
- best.base = -1;
-
- /*
- * Format the result.
- */
- tp = tmp;
- for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
- /* Are we inside the best run of 0x00's? */
- if (best.base != -1 && i >= best.base &&
- i < (best.base + best.len)) {
- if (i == best.base)
- *tp++ = ':';
- continue;
- }
- /* Are we following an initial run of 0x00s or any real hex? */
- if (i != 0)
- *tp++ = ':';
- /* Is this address an encapsulated IPv4? */
- if (i == 6 && best.base == 0 && (best.len == 6 ||
- (best.len == 7 && words[7] != 0x0001) ||
- (best.len == 5 && words[5] == 0xffff))) {
- int n;
-
- if (src[15] || bits == -1 || bits > 120)
- n = 4;
- else if (src[14] || bits > 112)
- n = 3;
- else
- n = 2;
- n = decoct(src+12, n, tp, sizeof tmp - (tp - tmp));
- if (n == 0) {
- errno = EMSGSIZE;
- return (NULL);
- }
- tp += strlen(tp);
- break;
- }
- tp += SPRINTF((tp, "%x", words[i]));
- }
-
- /* Was it a trailing run of 0x00's? */
- if (best.base != -1 && (best.base + best.len) ==
- (NS_IN6ADDRSZ / NS_INT16SZ))
- *tp++ = ':';
- *tp = '\0';
-
- if (bits != -1)
- tp += SPRINTF((tp, "/%u", bits));
-
- /*
- * Check for overflow, copy, and we're done.
- */
- if ((size_t)(tp - tmp) > size) {
- errno = EMSGSIZE;
- return (NULL);
- }
- strcpy(dst, tmp);
- return (dst);
-}
diff --git a/contrib/bind/lib/inet/inet_cidr_pton.c b/contrib/bind/lib/inet/inet_cidr_pton.c
deleted file mode 100644
index b8a7226..0000000
--- a/contrib/bind/lib/inet/inet_cidr_pton.c
+++ /dev/null
@@ -1,275 +0,0 @@
-/*
- * Copyright (c) 1998,1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: inet_cidr_pton.c,v 8.7 2001/09/28 04:21:28 marka Exp $";
-#endif
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <arpa/inet.h>
-
-#include <isc/assertions.h>
-#include <ctype.h>
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include "port_after.h"
-
-#ifdef SPRINTF_CHAR
-# define SPRINTF(x) strlen(sprintf/**/x)
-#else
-# define SPRINTF(x) ((size_t)sprintf x)
-#endif
-
-static int inet_cidr_pton_ipv4 __P((const char *src, u_char *dst,
- int *bits, int ipv6));
-static int inet_cidr_pton_ipv6 __P((const char *src, u_char *dst,
- int *bits));
-
-static int getbits(const char *, int ipv6);
-
-/*
- * int
- * inet_cidr_pton(af, src, dst, *bits)
- * convert network address from presentation to network format.
- * accepts inet_pton()'s input for this "af" plus trailing "/CIDR".
- * "dst" is assumed large enough for its "af". "bits" is set to the
- * /CIDR prefix length, which can have defaults (like /32 for IPv4).
- * return:
- * -1 if an error occurred (inspect errno; ENOENT means bad format).
- * 0 if successful conversion occurred.
- * note:
- * 192.5.5.1/28 has a nonzero host part, which means it isn't a network
- * as called for by inet_net_pton() but it can be a host address with
- * an included netmask.
- * author:
- * Paul Vixie (ISC), October 1998
- */
-int
-inet_cidr_pton(int af, const char *src, void *dst, int *bits) {
- switch (af) {
- case AF_INET:
- return (inet_cidr_pton_ipv4(src, dst, bits, 0));
- case AF_INET6:
- return (inet_cidr_pton_ipv6(src, dst, bits));
- default:
- errno = EAFNOSUPPORT;
- return (-1);
- }
-}
-
-static const char digits[] = "0123456789";
-
-static int
-inet_cidr_pton_ipv4(const char *src, u_char *dst, int *pbits, int ipv6) {
- const u_char *odst = dst;
- int n, ch, tmp, bits;
- size_t size = 4;
-
- /* Get the mantissa. */
- while (ch = *src++, (isascii(ch) && isdigit(ch))) {
- tmp = 0;
- do {
- n = strchr(digits, ch) - digits;
- INSIST(n >= 0 && n <= 9);
- tmp *= 10;
- tmp += n;
- if (tmp > 255)
- goto enoent;
- } while ((ch = *src++) != '\0' && isascii(ch) && isdigit(ch));
- if (size-- == 0)
- goto emsgsize;
- *dst++ = (u_char) tmp;
- if (ch == '\0' || ch == '/')
- break;
- if (ch != '.')
- goto enoent;
- }
-
- /* Get the prefix length if any. */
- bits = -1;
- if (ch == '/' && dst > odst) {
- bits = getbits(src, ipv6);
- if (bits == -2)
- goto enoent;
- } else if (ch != '\0')
- goto enoent;
-
- /* Prefix length can default to /32 only if all four octets spec'd. */
- if (bits == -1) {
- if (dst - odst == 4)
- bits = ipv6 ? 128 : 32;
- else
- goto enoent;
- }
-
- /* If nothing was written to the destination, we found no address. */
- if (dst == odst)
- goto enoent;
-
- /* If prefix length overspecifies mantissa, life is bad. */
- if (((bits - (ipv6 ? 96 : 0)) / 8) > (dst - odst))
- goto enoent;
-
- /* Extend address to four octets. */
- while (size-- > 0)
- *dst++ = 0;
-
- *pbits = bits;
- return (0);
-
- enoent:
- errno = ENOENT;
- return (-1);
-
- emsgsize:
- errno = EMSGSIZE;
- return (-1);
-}
-
-static int
-inet_cidr_pton_ipv6(const char *src, u_char *dst, int *pbits) {
- static const char xdigits_l[] = "0123456789abcdef",
- xdigits_u[] = "0123456789ABCDEF";
- u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
- const char *xdigits, *curtok;
- int ch, saw_xdigit;
- u_int val;
- int bits;
-
- memset((tp = tmp), '\0', NS_IN6ADDRSZ);
- endp = tp + NS_IN6ADDRSZ;
- colonp = NULL;
- /* Leading :: requires some special handling. */
- if (*src == ':')
- if (*++src != ':')
- return (0);
- curtok = src;
- saw_xdigit = 0;
- val = 0;
- bits = -1;
- while ((ch = *src++) != '\0') {
- const char *pch;
-
- if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
- pch = strchr((xdigits = xdigits_u), ch);
- if (pch != NULL) {
- val <<= 4;
- val |= (pch - xdigits);
- if (val > 0xffff)
- return (0);
- saw_xdigit = 1;
- continue;
- }
- if (ch == ':') {
- curtok = src;
- if (!saw_xdigit) {
- if (colonp)
- return (0);
- colonp = tp;
- continue;
- } else if (*src == '\0') {
- return (0);
- }
- if (tp + NS_INT16SZ > endp)
- return (0);
- *tp++ = (u_char) (val >> 8) & 0xff;
- *tp++ = (u_char) val & 0xff;
- saw_xdigit = 0;
- val = 0;
- continue;
- }
- if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
- inet_cidr_pton_ipv4(curtok, tp, &bits, 1) == 0) {
- tp += NS_INADDRSZ;
- saw_xdigit = 0;
- break; /* '\0' was seen by inet_pton4(). */
- }
- if (ch == '/') {
- bits = getbits(src, 1);
- if (bits == -2)
- goto enoent;
- break;
- }
- goto enoent;
- }
- if (saw_xdigit) {
- if (tp + NS_INT16SZ > endp)
- goto emsgsize;
- *tp++ = (u_char) (val >> 8) & 0xff;
- *tp++ = (u_char) val & 0xff;
- }
- if (colonp != NULL) {
- /*
- * Since some memmove()'s erroneously fail to handle
- * overlapping regions, we'll do the shift by hand.
- */
- const int n = tp - colonp;
- int i;
-
- if (tp == endp)
- goto enoent;
- for (i = 1; i <= n; i++) {
- endp[- i] = colonp[n - i];
- colonp[n - i] = 0;
- }
- tp = endp;
- }
-
- memcpy(dst, tmp, NS_IN6ADDRSZ);
-
- *pbits = bits;
- return (0);
-
- enoent:
- errno = ENOENT;
- return (-1);
-
- emsgsize:
- errno = EMSGSIZE;
- return (-1);
-}
-
-int
-getbits(const char *src, int ipv6) {
- int bits = 0;
- char *cp, ch;
-
- if (*src == '\0') /* syntax */
- return (-2);
- do {
- ch = *src++;
- cp = strchr(digits, ch);
- if (cp == NULL) /* syntax */
- return (-2);
- bits *= 10;
- bits += cp - digits;
- if (bits == 0 && *src != '\0') /* no leading zeros */
- return (-2);
- if (bits > (ipv6 ? 128 : 32)) /* range error */
- return (-2);
- } while (*src != '\0');
-
- return (bits);
-}
diff --git a/contrib/bind/lib/inet/inet_data.c b/contrib/bind/lib/inet/inet_data.c
deleted file mode 100644
index 47b6d9b..0000000
--- a/contrib/bind/lib/inet/inet_data.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 1995-1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$Id: inet_data.c,v 1.2 2001/06/20 22:06:36 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#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 <ctype.h>
-#include <netdb.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "port_after.h"
-
-const struct in6_addr isc_in6addr_any = IN6ADDR_ANY_INIT;
-const struct in6_addr isc_in6addr_loopback = IN6ADDR_LOOPBACK_INIT;
diff --git a/contrib/bind/lib/inet/inet_lnaof.c b/contrib/bind/lib/inet/inet_lnaof.c
deleted file mode 100644
index 97b80cf..0000000
--- a/contrib/bind/lib/inet/inet_lnaof.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (c) 1983, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char sccsid[] = "@(#)inet_lnaof.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-
-#include "port_before.h"
-
-#include <sys/param.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include "port_after.h"
-
-/*
- * Return the local network address portion of an
- * internet address; handles class a/b/c network
- * number formats.
- */
-u_long
-inet_lnaof(in)
- struct in_addr in;
-{
- register u_long i = ntohl(in.s_addr);
-
- if (IN_CLASSA(i))
- return ((i)&IN_CLASSA_HOST);
- else if (IN_CLASSB(i))
- return ((i)&IN_CLASSB_HOST);
- else
- return ((i)&IN_CLASSC_HOST);
-}
diff --git a/contrib/bind/lib/inet/inet_makeaddr.c b/contrib/bind/lib/inet/inet_makeaddr.c
deleted file mode 100644
index 49ea023..0000000
--- a/contrib/bind/lib/inet/inet_makeaddr.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (c) 1983, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char sccsid[] = "@(#)inet_makeaddr.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-
-#include "port_before.h"
-
-#include <sys/param.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include "port_after.h"
-
-/*
- * Formulate an Internet address from network + host. Used in
- * building addresses stored in the ifnet structure.
- */
-struct in_addr
-inet_makeaddr(net, host)
- u_long net, host;
-{
- u_long addr;
-
- if (net < 128)
- addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST);
- else if (net < 65536)
- addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST);
- else if (net < 16777216L)
- addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST);
- else
- addr = net | host;
- addr = htonl(addr);
- return (*(struct in_addr *)&addr);
-}
diff --git a/contrib/bind/lib/inet/inet_net_ntop.c b/contrib/bind/lib/inet/inet_net_ntop.c
deleted file mode 100644
index b38a6ca..0000000
--- a/contrib/bind/lib/inet/inet_net_ntop.c
+++ /dev/null
@@ -1,277 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: inet_net_ntop.c,v 1.8 2001/09/27 15:08:36 marka Exp $";
-#endif
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include "port_after.h"
-
-#ifdef SPRINTF_CHAR
-# define SPRINTF(x) strlen(sprintf/**/x)
-#else
-# define SPRINTF(x) ((size_t)sprintf x)
-#endif
-
-static char * inet_net_ntop_ipv4 __P((const u_char *src, int bits,
- char *dst, size_t size));
-static char * inet_net_ntop_ipv6 __P((const u_char *src, int bits,
- char *dst, size_t size));
-
-/*
- * char *
- * inet_net_ntop(af, src, bits, dst, size)
- * convert network number from network to presentation format.
- * generates CIDR style result always.
- * return:
- * pointer to dst, or NULL if an error occurred (check errno).
- * author:
- * Paul Vixie (ISC), July 1996
- */
-char *
-inet_net_ntop(af, src, bits, dst, size)
- int af;
- const void *src;
- int bits;
- char *dst;
- size_t size;
-{
- switch (af) {
- case AF_INET:
- return (inet_net_ntop_ipv4(src, bits, dst, size));
- case AF_INET6:
- return (inet_net_ntop_ipv6(src, bits, dst, size));
- default:
- errno = EAFNOSUPPORT;
- return (NULL);
- }
-}
-
-/*
- * static char *
- * inet_net_ntop_ipv4(src, bits, dst, size)
- * convert IPv4 network number from network to presentation format.
- * generates CIDR style result always.
- * return:
- * pointer to dst, or NULL if an error occurred (check errno).
- * note:
- * network byte order assumed. this means 192.5.5.240/28 has
- * 0b11110000 in its fourth octet.
- * author:
- * Paul Vixie (ISC), July 1996
- */
-static char *
-inet_net_ntop_ipv4(src, bits, dst, size)
- const u_char *src;
- int bits;
- char *dst;
- size_t size;
-{
- char *odst = dst;
- char *t;
- u_int m;
- int b;
-
- if (bits < 0 || bits > 32) {
- errno = EINVAL;
- return (NULL);
- }
-
- if (bits == 0) {
- if (size < sizeof "0")
- goto emsgsize;
- *dst++ = '0';
- size--;
- *dst = '\0';
- }
-
- /* Format whole octets. */
- for (b = bits / 8; b > 0; b--) {
- if (size <= sizeof "255.")
- goto emsgsize;
- t = dst;
- dst += SPRINTF((dst, "%u", *src++));
- if (b > 1) {
- *dst++ = '.';
- *dst = '\0';
- }
- size -= (size_t)(dst - t);
- }
-
- /* Format partial octet. */
- b = bits % 8;
- if (b > 0) {
- if (size <= sizeof ".255")
- goto emsgsize;
- t = dst;
- if (dst != odst)
- *dst++ = '.';
- m = ((1 << b) - 1) << (8 - b);
- dst += SPRINTF((dst, "%u", *src & m));
- size -= (size_t)(dst - t);
- }
-
- /* Format CIDR /width. */
- if (size <= sizeof "/32")
- goto emsgsize;
- dst += SPRINTF((dst, "/%u", bits));
- return (odst);
-
- emsgsize:
- errno = EMSGSIZE;
- return (NULL);
-}
-
-/*
- * static char *
- * inet_net_ntop_ipv6(src, bits, fakebits, dst, size)
- * convert IPv6 network number from network to presentation format.
- * generates CIDR style result always. Picks the shortest representation
- * unless the IP is really IPv4.
- * always prints specified number of bits (bits).
- * return:
- * pointer to dst, or NULL if an error occurred (check errno).
- * note:
- * network byte order assumed. this means 192.5.5.240/28 has
- * 0x11110000 in its fourth octet.
- * author:
- * Vadim Kogan (UCB), June 2001
- * Original version (IPv4) by Paul Vixie (ISC), July 1996
- */
-
-static char *
-inet_net_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size) {
- u_int m;
- int b;
- int p;
- int zero_s, zero_l, tmp_zero_s, tmp_zero_l;
- int i;
- int is_ipv4 = 0;
- unsigned char inbuf[16];
- char outbuf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
- char *cp;
- int words;
- u_char *s;
-
- if (bits < 0 || bits > 128) {
- errno = EINVAL;
- return (NULL);
- }
-
- cp = outbuf;
-
- if (bits == 0) {
- *cp++ = ':';
- *cp++ = ':';
- *cp = '\0';
- } else {
- /* Copy src to private buffer. Zero host part. */
- p = (bits + 7) / 8;
- memcpy(inbuf, src, p);
- memset(inbuf + p, 0, 16 - p);
- b = bits % 8;
- if (b != 0) {
- m = ~0 << (8 - b);
- inbuf[p-1] &= m;
- }
-
- s = inbuf;
-
- /* how many words need to be displayed in output */
- words = (bits + 15) / 16;
- if (words == 1)
- words = 2;
-
- /* Find the longest substring of zero's */
- zero_s = zero_l = tmp_zero_s = tmp_zero_l = 0;
- for (i = 0; i < (words * 2); i += 2) {
- if ((s[i] | s[i+1]) == 0) {
- if (tmp_zero_l == 0)
- tmp_zero_s = i / 2;
- tmp_zero_l++;
- } else {
- if (tmp_zero_l && zero_l < tmp_zero_l) {
- zero_s = tmp_zero_s;
- zero_l = tmp_zero_l;
- tmp_zero_l = 0;
- }
- }
- }
-
- if (tmp_zero_l && zero_l < tmp_zero_l) {
- zero_s = tmp_zero_s;
- zero_l = tmp_zero_l;
- }
-
- if (zero_l != words && zero_s == 0 && ((zero_l == 6) ||
- ((zero_l == 5 && s[10] == 0xff && s[11] == 0xff) ||
- ((zero_l == 7 && s[14] != 0 && s[15] != 1)))))
- is_ipv4 = 1;
-
- /* Format whole words. */
- for (p = 0; p < words; p++) {
- if (zero_l != 0 && p >= zero_s && p < zero_s + zero_l) {
- /* Time to skip some zeros */
- if (p == zero_s)
- *cp++ = ':';
- if (p == words - 1)
- *cp++ = ':';
- s++;
- s++;
- continue;
- }
-
- if (is_ipv4 && p > 5 ) {
- *cp++ = (p == 6) ? ':' : '.';
- cp += SPRINTF((cp, "%u", *s++));
- /* we can potentially drop the last octet */
- if (p != 7 || bits > 120) {
- *cp++ = '.';
- cp += SPRINTF((cp, "%u", *s++));
- }
- } else {
- if (cp != outbuf)
- *cp++ = ':';
- cp += SPRINTF((cp, "%x", *s * 256 + s[1]));
- s += 2;
- }
- }
- }
- /* Format CIDR /width. */
- SPRINTF((cp, "/%u", bits));
- if (strlen(outbuf) + 1 > size)
- goto emsgsize;
- strcpy(dst, outbuf);
-
- return (dst);
-
-emsgsize:
- errno = EMSGSIZE;
- return (NULL);
-}
diff --git a/contrib/bind/lib/inet/inet_net_pton.c b/contrib/bind/lib/inet/inet_net_pton.c
deleted file mode 100644
index ff62a8b..0000000
--- a/contrib/bind/lib/inet/inet_net_pton.c
+++ /dev/null
@@ -1,399 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: inet_net_pton.c,v 1.13 2001/09/27 15:08:38 marka Exp $";
-#endif
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <arpa/inet.h>
-
-#include <isc/assertions.h>
-#include <ctype.h>
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include "port_after.h"
-
-#ifdef SPRINTF_CHAR
-# define SPRINTF(x) strlen(sprintf/**/x)
-#else
-# define SPRINTF(x) ((size_t)sprintf x)
-#endif
-
-/*
- * static int
- * inet_net_pton_ipv4(src, dst, size)
- * convert IPv4 network number from presentation to network format.
- * accepts hex octets, hex strings, decimal octets, and /CIDR.
- * "size" is in bytes and describes "dst".
- * return:
- * number of bits, either imputed classfully or specified with /CIDR,
- * or -1 if some failure occurred (check errno). ENOENT means it was
- * not an IPv4 network specification.
- * note:
- * network byte order assumed. this means 192.5.5.240/28 has
- * 0b11110000 in its fourth octet.
- * author:
- * Paul Vixie (ISC), June 1996
- */
-static int
-inet_net_pton_ipv4( const char *src, u_char *dst, size_t size) {
- static const char xdigits[] = "0123456789abcdef";
- static const char digits[] = "0123456789";
- int n, ch, tmp = 0, dirty, bits;
- const u_char *odst = dst;
-
- ch = *src++;
- if (ch == '0' && (src[0] == 'x' || src[0] == 'X')
- && isascii((unsigned char)(src[1]))
- && isxdigit((unsigned char)(src[1]))) {
- /* Hexadecimal: Eat nybble string. */
- if (size <= 0)
- goto emsgsize;
- dirty = 0;
- src++; /* skip x or X. */
- while ((ch = *src++) != '\0' && isascii(ch) && isxdigit(ch)) {
- if (isupper(ch))
- ch = tolower(ch);
- n = strchr(xdigits, ch) - xdigits;
- INSIST(n >= 0 && n <= 15);
- if (dirty == 0)
- tmp = n;
- else
- tmp = (tmp << 4) | n;
- if (++dirty == 2) {
- if (size-- <= 0)
- goto emsgsize;
- *dst++ = (u_char) tmp;
- dirty = 0;
- }
- }
- if (dirty) { /* Odd trailing nybble? */
- if (size-- <= 0)
- goto emsgsize;
- *dst++ = (u_char) (tmp << 4);
- }
- } else if (isascii(ch) && isdigit(ch)) {
- /* Decimal: eat dotted digit string. */
- for (;;) {
- tmp = 0;
- do {
- n = strchr(digits, ch) - digits;
- INSIST(n >= 0 && n <= 9);
- tmp *= 10;
- tmp += n;
- if (tmp > 255)
- goto enoent;
- } while ((ch = *src++) != '\0' &&
- isascii(ch) && isdigit(ch));
- if (size-- <= 0)
- goto emsgsize;
- *dst++ = (u_char) tmp;
- if (ch == '\0' || ch == '/')
- break;
- if (ch != '.')
- goto enoent;
- ch = *src++;
- if (!isascii(ch) || !isdigit(ch))
- goto enoent;
- }
- } else
- goto enoent;
-
- bits = -1;
- if (ch == '/' && isascii((unsigned char)(src[0])) &&
- isdigit((unsigned char)(src[0])) && dst > odst) {
- /* CIDR width specifier. Nothing can follow it. */
- ch = *src++; /* Skip over the /. */
- bits = 0;
- do {
- n = strchr(digits, ch) - digits;
- INSIST(n >= 0 && n <= 9);
- bits *= 10;
- bits += n;
- } while ((ch = *src++) != '\0' && isascii(ch) && isdigit(ch));
- if (ch != '\0')
- goto enoent;
- if (bits > 32)
- goto emsgsize;
- }
-
- /* Firey death and destruction unless we prefetched EOS. */
- if (ch != '\0')
- goto enoent;
-
- /* If nothing was written to the destination, we found no address. */
- if (dst == odst)
- goto enoent;
- /* If no CIDR spec was given, infer width from net class. */
- if (bits == -1) {
- if (*odst >= 240) /* Class E */
- bits = 32;
- else if (*odst >= 224) /* Class D */
- bits = 4;
- else if (*odst >= 192) /* Class C */
- bits = 24;
- else if (*odst >= 128) /* Class B */
- bits = 16;
- else /* Class A */
- bits = 8;
- /* If imputed mask is narrower than specified octets, widen. */
- if (bits >= 8 && bits < ((dst - odst) * 8))
- bits = (dst - odst) * 8;
- }
- /* Extend network to cover the actual mask. */
- while (bits > ((dst - odst) * 8)) {
- if (size-- <= 0)
- goto emsgsize;
- *dst++ = '\0';
- }
- return (bits);
-
- enoent:
- errno = ENOENT;
- return (-1);
-
- emsgsize:
- errno = EMSGSIZE;
- return (-1);
-}
-
-static int
-getbits(const char *src, int *bitsp) {
- static const char digits[] = "0123456789";
- int n;
- int val;
- char ch;
-
- val = 0;
- n = 0;
- while ((ch = *src++) != '\0') {
- const char *pch;
-
- pch = strchr(digits, ch);
- if (pch != NULL) {
- if (n++ != 0 && val == 0) /* no leading zeros */
- return (0);
- val *= 10;
- val += (pch - digits);
- if (val > 128) /* range */
- return (0);
- continue;
- }
- return (0);
- }
- if (n == 0)
- return (0);
- *bitsp = val;
- return (1);
-}
-
-static int
-getv4(const char *src, u_char *dst, int *bitsp) {
- static const char digits[] = "0123456789";
- u_char *odst = dst;
- int n;
- u_int val;
- char ch;
-
- val = 0;
- n = 0;
- while ((ch = *src++) != '\0') {
- const char *pch;
-
- pch = strchr(digits, ch);
- if (pch != NULL) {
- if (n++ != 0 && val == 0) /* no leading zeros */
- return (0);
- val *= 10;
- val += (pch - digits);
- if (val > 255) /* range */
- return (0);
- continue;
- }
- if (ch == '.' || ch == '/') {
- if (dst - odst > 3) /* too many octets? */
- return (0);
- *dst++ = val;
- if (ch == '/')
- return (getbits(src, bitsp));
- val = 0;
- n = 0;
- continue;
- }
- return (0);
- }
- if (n == 0)
- return (0);
- if (dst - odst > 3) /* too many octets? */
- return (0);
- *dst++ = val;
- return (1);
-}
-
-static int
-inet_net_pton_ipv6(const char *src, u_char *dst, size_t size) {
- static const char xdigits_l[] = "0123456789abcdef",
- xdigits_u[] = "0123456789ABCDEF";
- u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
- const char *xdigits, *curtok;
- int ch, saw_xdigit;
- u_int val;
- int digits;
- int bits;
- size_t bytes;
- int words;
- int ipv4;
-
- memset((tp = tmp), '\0', NS_IN6ADDRSZ);
- endp = tp + NS_IN6ADDRSZ;
- colonp = NULL;
- /* Leading :: requires some special handling. */
- if (*src == ':')
- if (*++src != ':')
- goto enoent;
- curtok = src;
- saw_xdigit = 0;
- val = 0;
- digits = 0;
- bits = -1;
- ipv4 = 0;
- while ((ch = *src++) != '\0') {
- const char *pch;
-
- if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
- pch = strchr((xdigits = xdigits_u), ch);
- if (pch != NULL) {
- val <<= 4;
- val |= (pch - xdigits);
- if (++digits > 4)
- goto enoent;
- saw_xdigit = 1;
- continue;
- }
- if (ch == ':') {
- curtok = src;
- if (!saw_xdigit) {
- if (colonp)
- goto enoent;
- colonp = tp;
- continue;
- } else if (*src == '\0')
- goto enoent;
- if (tp + NS_INT16SZ > endp)
- return (0);
- *tp++ = (u_char) (val >> 8) & 0xff;
- *tp++ = (u_char) val & 0xff;
- saw_xdigit = 0;
- digits = 0;
- val = 0;
- continue;
- }
- if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
- getv4(curtok, tp, &bits) > 0) {
- tp += NS_INADDRSZ;
- saw_xdigit = 0;
- ipv4 = 1;
- break; /* '\0' was seen by inet_pton4(). */
- }
- if (ch == '/' && getbits(src, &bits) > 0)
- break;
- goto enoent;
- }
- if (saw_xdigit) {
- if (tp + NS_INT16SZ > endp)
- goto enoent;
- *tp++ = (u_char) (val >> 8) & 0xff;
- *tp++ = (u_char) val & 0xff;
- }
- if (bits == -1)
- bits = 128;
-
- words = (bits + 15) / 16;
- if (words < 2)
- words = 2;
- if (ipv4)
- words = 8;
- endp = tmp + 2 * words;
-
- if (colonp != NULL) {
- /*
- * Since some memmove()'s erroneously fail to handle
- * overlapping regions, we'll do the shift by hand.
- */
- const int n = tp - colonp;
- int i;
-
- if (tp == endp)
- goto enoent;
- for (i = 1; i <= n; i++) {
- endp[- i] = colonp[n - i];
- colonp[n - i] = 0;
- }
- tp = endp;
- }
- if (tp != endp)
- goto enoent;
-
- bytes = (bits + 7) / 8;
- if (bytes > size)
- goto emsgsize;
- memcpy(dst, tmp, bytes);
- return (bits);
-
- enoent:
- errno = ENOENT;
- return (-1);
-
- emsgsize:
- errno = EMSGSIZE;
- return (-1);
-}
-
-/*
- * int
- * inet_net_pton(af, src, dst, size)
- * convert network number from presentation to network format.
- * accepts hex octets, hex strings, decimal octets, and /CIDR.
- * "size" is in bytes and describes "dst".
- * return:
- * number of bits, either imputed classfully or specified with /CIDR,
- * or -1 if some failure occurred (check errno). ENOENT means it was
- * not a valid network specification.
- * author:
- * Paul Vixie (ISC), June 1996
- */
-int
-inet_net_pton(int af, const char *src, void *dst, size_t size) {
- switch (af) {
- case AF_INET:
- return (inet_net_pton_ipv4(src, dst, size));
- case AF_INET6:
- return (inet_net_pton_ipv6(src, dst, size));
- default:
- errno = EAFNOSUPPORT;
- return (-1);
- }
-}
diff --git a/contrib/bind/lib/inet/inet_neta.c b/contrib/bind/lib/inet/inet_neta.c
deleted file mode 100644
index 8665a9a..0000000
--- a/contrib/bind/lib/inet/inet_neta.c
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: inet_neta.c,v 1.6 1999/01/08 19:23:45 vixie Exp $";
-#endif
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "port_after.h"
-
-#ifdef SPRINTF_CHAR
-# define SPRINTF(x) strlen(sprintf/**/x)
-#else
-# define SPRINTF(x) ((size_t)sprintf x)
-#endif
-
-/*
- * char *
- * inet_neta(src, dst, size)
- * format a u_long network number into presentation format.
- * return:
- * pointer to dst, or NULL if an error occurred (check errno).
- * note:
- * format of ``src'' is as for inet_network().
- * author:
- * Paul Vixie (ISC), July 1996
- */
-char *
-inet_neta(src, dst, size)
- u_long src;
- char *dst;
- size_t size;
-{
- char *odst = dst;
- char *tp;
-
- while (src & 0xffffffff) {
- u_char b = (src & 0xff000000) >> 24;
-
- src <<= 8;
- if (b) {
- if (size < sizeof "255.")
- goto emsgsize;
- tp = dst;
- dst += SPRINTF((dst, "%u", b));
- if (src != 0L) {
- *dst++ = '.';
- *dst = '\0';
- }
- size -= (size_t)(dst - tp);
- }
- }
- if (dst == odst) {
- if (size < sizeof "0.0.0.0")
- goto emsgsize;
- strcpy(dst, "0.0.0.0");
- }
- return (odst);
-
- emsgsize:
- errno = EMSGSIZE;
- return (NULL);
-}
diff --git a/contrib/bind/lib/inet/inet_netof.c b/contrib/bind/lib/inet/inet_netof.c
deleted file mode 100644
index e887530..0000000
--- a/contrib/bind/lib/inet/inet_netof.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (c) 1983, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char sccsid[] = "@(#)inet_netof.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-
-#include "port_before.h"
-
-#include <sys/param.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include "port_after.h"
-
-/*
- * Return the network number from an internet
- * address; handles class a/b/c network #'s.
- */
-u_long
-inet_netof(in)
- struct in_addr in;
-{
- register u_long i = ntohl(in.s_addr);
-
- if (IN_CLASSA(i))
- return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT);
- else if (IN_CLASSB(i))
- return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT);
- else
- return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT);
-}
diff --git a/contrib/bind/lib/inet/inet_network.c b/contrib/bind/lib/inet/inet_network.c
deleted file mode 100644
index 9090d13..0000000
--- a/contrib/bind/lib/inet/inet_network.c
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright (c) 1983, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char sccsid[] = "@(#)inet_network.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <ctype.h>
-
-#include "port_after.h"
-
-/*
- * Internet network address interpretation routine.
- * The library routines call this routine to interpret
- * network numbers.
- */
-u_long
-inet_network(cp)
- register const char *cp;
-{
- register u_long val, base, n, i;
- register char c;
- u_long parts[4], *pp = parts;
- int digit;
-
-again:
- val = 0; base = 10; digit = 0;
- if (*cp == '0')
- digit = 1, base = 8, cp++;
- if (*cp == 'x' || *cp == 'X')
- base = 16, cp++;
- while ((c = *cp) != 0) {
- if (isdigit((unsigned char)c)) {
- if (base == 8 && (c == '8' || c == '9'))
- return (INADDR_NONE);
- val = (val * base) + (c - '0');
- cp++;
- digit = 1;
- continue;
- }
- if (base == 16 && isxdigit((unsigned char)c)) {
- val = (val << 4) +
- (c + 10 - (islower((unsigned char)c) ? 'a' : 'A'));
- cp++;
- digit = 1;
- continue;
- }
- break;
- }
- if (!digit)
- return (INADDR_NONE);
- if (*cp == '.') {
- if (pp >= parts + 4 || val > 0xff)
- return (INADDR_NONE);
- *pp++ = val, cp++;
- goto again;
- }
- if (*cp && !isspace(*cp&0xff))
- return (INADDR_NONE);
- *pp++ = val;
- n = pp - parts;
- if (n > 4)
- return (INADDR_NONE);
- for (val = 0, i = 0; i < n; i++) {
- val <<= 8;
- val |= parts[i] & 0xff;
- }
- return (val);
-}
diff --git a/contrib/bind/lib/inet/inet_ntoa.c b/contrib/bind/lib/inet/inet_ntoa.c
deleted file mode 100644
index aaedcb6..0000000
--- a/contrib/bind/lib/inet/inet_ntoa.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (c) 1983, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char sccsid[] = "@(#)inet_ntoa.c 8.1 (Berkeley) 6/4/93";
-static const char rcsid[] = "$Id: inet_ntoa.c,v 1.7 1999/05/14 18:16:55 vixie Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include <stdio.h>
-#include <string.h>
-
-#include "port_after.h"
-
-/*
- * Convert network-format internet address
- * to base 256 d.d.d.d representation.
- */
-/*const*/ char *
-inet_ntoa(struct in_addr in) {
- static char ret[18];
-
- strcpy(ret, "[inet_ntoa error]");
- (void) inet_ntop(AF_INET, &in, ret, sizeof ret);
- return (ret);
-}
diff --git a/contrib/bind/lib/inet/inet_ntop.c b/contrib/bind/lib/inet/inet_ntop.c
deleted file mode 100644
index e05812e..0000000
--- a/contrib/bind/lib/inet/inet_ntop.c
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * Copyright (c) 1996-1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: inet_ntop.c,v 1.11 2001/09/27 15:12:57 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include "port_before.h"
-
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "port_after.h"
-
-#ifdef SPRINTF_CHAR
-# define SPRINTF(x) strlen(sprintf/**/x)
-#else
-# define SPRINTF(x) ((size_t)sprintf x)
-#endif
-
-/*
- * WARNING: Don't even consider trying to compile this on a system where
- * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
- */
-
-static const char *inet_ntop4 __P((const u_char *src, char *dst, size_t size));
-static const char *inet_ntop6 __P((const u_char *src, char *dst, size_t size));
-
-/* char *
- * inet_ntop(af, src, dst, size)
- * convert a network format address to presentation format.
- * return:
- * pointer to presentation format address (`dst'), or NULL (see errno).
- * author:
- * Paul Vixie, 1996.
- */
-const char *
-inet_ntop(af, src, dst, size)
- int af;
- const void *src;
- char *dst;
- size_t size;
-{
- switch (af) {
- case AF_INET:
- return (inet_ntop4(src, dst, size));
- case AF_INET6:
- return (inet_ntop6(src, dst, size));
- default:
- errno = EAFNOSUPPORT;
- return (NULL);
- }
- /* NOTREACHED */
-}
-
-/* const char *
- * inet_ntop4(src, dst, size)
- * format an IPv4 address
- * return:
- * `dst' (as a const)
- * notes:
- * (1) uses no statics
- * (2) takes a u_char* not an in_addr as input
- * author:
- * Paul Vixie, 1996.
- */
-static const char *
-inet_ntop4(src, dst, size)
- const u_char *src;
- char *dst;
- size_t size;
-{
- static const char fmt[] = "%u.%u.%u.%u";
- char tmp[sizeof "255.255.255.255"];
-
- if (SPRINTF((tmp, fmt, src[0], src[1], src[2], src[3])) >= size) {
- errno = ENOSPC;
- return (NULL);
- }
- strcpy(dst, tmp);
- return (dst);
-}
-
-/* const char *
- * inet_ntop6(src, dst, size)
- * convert IPv6 binary address into presentation (printable) format
- * author:
- * Paul Vixie, 1996.
- */
-static const char *
-inet_ntop6(src, dst, size)
- const u_char *src;
- char *dst;
- size_t size;
-{
- /*
- * Note that int32_t and int16_t need only be "at least" large enough
- * to contain a value of the specified size. On some systems, like
- * Crays, there is no such thing as an integer variable with 16 bits.
- * Keep this in mind if you think this function should have been coded
- * to use pointer overlays. All the world's not a VAX.
- */
- char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
- struct { int base, len; } best, cur;
- u_int words[NS_IN6ADDRSZ / NS_INT16SZ];
- int i;
-
- /*
- * Preprocess:
- * Copy the input (bytewise) array into a wordwise array.
- * Find the longest run of 0x00's in src[] for :: shorthanding.
- */
- memset(words, '\0', sizeof words);
- for (i = 0; i < NS_IN6ADDRSZ; i++)
- words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3));
- best.base = -1;
- cur.base = -1;
- for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
- if (words[i] == 0) {
- if (cur.base == -1)
- cur.base = i, cur.len = 1;
- else
- cur.len++;
- } else {
- if (cur.base != -1) {
- if (best.base == -1 || cur.len > best.len)
- best = cur;
- cur.base = -1;
- }
- }
- }
- if (cur.base != -1) {
- if (best.base == -1 || cur.len > best.len)
- best = cur;
- }
- if (best.base != -1 && best.len < 2)
- best.base = -1;
-
- /*
- * Format the result.
- */
- tp = tmp;
- for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
- /* Are we inside the best run of 0x00's? */
- if (best.base != -1 && i >= best.base &&
- i < (best.base + best.len)) {
- if (i == best.base)
- *tp++ = ':';
- continue;
- }
- /* Are we following an initial run of 0x00s or any real hex? */
- if (i != 0)
- *tp++ = ':';
- /* Is this address an encapsulated IPv4? */
- if (i == 6 && best.base == 0 && (best.len == 6 ||
- (best.len == 7 && words[7] != 0x0001) ||
- (best.len == 5 && words[5] == 0xffff))) {
- if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp)))
- return (NULL);
- tp += strlen(tp);
- break;
- }
- tp += SPRINTF((tp, "%x", words[i]));
- }
- /* Was it a trailing run of 0x00's? */
- if (best.base != -1 && (best.base + best.len) ==
- (NS_IN6ADDRSZ / NS_INT16SZ))
- *tp++ = ':';
- *tp++ = '\0';
-
- /*
- * Check for overflow, copy, and we're done.
- */
- if ((size_t)(tp - tmp) > size) {
- errno = ENOSPC;
- return (NULL);
- }
- strcpy(dst, tmp);
- return (dst);
-}
diff --git a/contrib/bind/lib/inet/inet_pton.c b/contrib/bind/lib/inet/inet_pton.c
deleted file mode 100644
index a6b0a71..0000000
--- a/contrib/bind/lib/inet/inet_pton.c
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: inet_pton.c,v 1.8 2001/07/16 03:22:24 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include "port_before.h"
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-#include <string.h>
-#include <errno.h>
-#include "port_after.h"
-
-/*
- * WARNING: Don't even consider trying to compile this on a system where
- * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
- */
-
-static int inet_pton4 __P((const char *src, u_char *dst));
-static int inet_pton6 __P((const char *src, u_char *dst));
-
-/* int
- * inet_pton(af, src, dst)
- * convert from presentation format (which usually means ASCII printable)
- * to network format (which is usually some kind of binary format).
- * return:
- * 1 if the address was valid for the specified address family
- * 0 if the address wasn't valid (`dst' is untouched in this case)
- * -1 if some other error occurred (`dst' is untouched in this case, too)
- * author:
- * Paul Vixie, 1996.
- */
-int
-inet_pton(af, src, dst)
- int af;
- const char *src;
- void *dst;
-{
- switch (af) {
- case AF_INET:
- return (inet_pton4(src, dst));
- case AF_INET6:
- return (inet_pton6(src, dst));
- default:
- errno = EAFNOSUPPORT;
- return (-1);
- }
- /* NOTREACHED */
-}
-
-/* int
- * inet_pton4(src, dst)
- * like inet_aton() but without all the hexadecimal and shorthand.
- * return:
- * 1 if `src' is a valid dotted quad, else 0.
- * notice:
- * does not touch `dst' unless it's returning 1.
- * author:
- * Paul Vixie, 1996.
- */
-static int
-inet_pton4(src, dst)
- const char *src;
- u_char *dst;
-{
- static const char digits[] = "0123456789";
- int saw_digit, octets, ch;
- u_char tmp[NS_INADDRSZ], *tp;
-
- saw_digit = 0;
- octets = 0;
- *(tp = tmp) = 0;
- while ((ch = *src++) != '\0') {
- const char *pch;
-
- if ((pch = strchr(digits, ch)) != NULL) {
- u_int new = *tp * 10 + (pch - digits);
-
- if (saw_digit && *tp == 0)
- return (0);
- if (new > 255)
- return (0);
- *tp = new;
- if (!saw_digit) {
- if (++octets > 4)
- return (0);
- saw_digit = 1;
- }
- } else if (ch == '.' && saw_digit) {
- if (octets == 4)
- return (0);
- *++tp = 0;
- saw_digit = 0;
- } else
- return (0);
- }
- if (octets < 4)
- return (0);
- memcpy(dst, tmp, NS_INADDRSZ);
- return (1);
-}
-
-/* int
- * inet_pton6(src, dst)
- * convert presentation level address to network order binary form.
- * return:
- * 1 if `src' is a valid [RFC1884 2.2] address, else 0.
- * notice:
- * (1) does not touch `dst' unless it's returning 1.
- * (2) :: in a full address is silently ignored.
- * credit:
- * inspired by Mark Andrews.
- * author:
- * Paul Vixie, 1996.
- */
-static int
-inet_pton6(src, dst)
- const char *src;
- u_char *dst;
-{
- static const char xdigits_l[] = "0123456789abcdef",
- xdigits_u[] = "0123456789ABCDEF";
- u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
- const char *xdigits, *curtok;
- int ch, saw_xdigit;
- u_int val;
-
- memset((tp = tmp), '\0', NS_IN6ADDRSZ);
- endp = tp + NS_IN6ADDRSZ;
- colonp = NULL;
- /* Leading :: requires some special handling. */
- if (*src == ':')
- if (*++src != ':')
- return (0);
- curtok = src;
- saw_xdigit = 0;
- val = 0;
- while ((ch = *src++) != '\0') {
- const char *pch;
-
- if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
- pch = strchr((xdigits = xdigits_u), ch);
- if (pch != NULL) {
- val <<= 4;
- val |= (pch - xdigits);
- if (val > 0xffff)
- return (0);
- saw_xdigit = 1;
- continue;
- }
- if (ch == ':') {
- curtok = src;
- if (!saw_xdigit) {
- if (colonp)
- return (0);
- colonp = tp;
- continue;
- } else if (*src == '\0') {
- return (0);
- }
- if (tp + NS_INT16SZ > endp)
- return (0);
- *tp++ = (u_char) (val >> 8) & 0xff;
- *tp++ = (u_char) val & 0xff;
- saw_xdigit = 0;
- val = 0;
- continue;
- }
- if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
- inet_pton4(curtok, tp) > 0) {
- tp += NS_INADDRSZ;
- saw_xdigit = 0;
- break; /* '\0' was seen by inet_pton4(). */
- }
- return (0);
- }
- if (saw_xdigit) {
- if (tp + NS_INT16SZ > endp)
- return (0);
- *tp++ = (u_char) (val >> 8) & 0xff;
- *tp++ = (u_char) val & 0xff;
- }
- if (colonp != NULL) {
- /*
- * Since some memmove()'s erroneously fail to handle
- * overlapping regions, we'll do the shift by hand.
- */
- const int n = tp - colonp;
- int i;
-
- if (tp == endp)
- return (0);
- for (i = 1; i <= n; i++) {
- endp[- i] = colonp[n - i];
- colonp[n - i] = 0;
- }
- tp = endp;
- }
- if (tp != endp)
- return (0);
- memcpy(dst, tmp, NS_IN6ADDRSZ);
- return (1);
-}
diff --git a/contrib/bind/lib/inet/nsap_addr.c b/contrib/bind/lib/inet/nsap_addr.c
deleted file mode 100644
index 7198b9d..0000000
--- a/contrib/bind/lib/inet/nsap_addr.c
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright (c) 1996-1999 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 DISCLAI!
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANT!
- * 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 TH!
- * SOFTWARE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: nsap_addr.c,v 8.12 2001/05/28 07:37:46 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-
-#include <ctype.h>
-#include <resolv.h>
-
-#include "port_after.h"
-
-static char
-xtob(int c) {
- return (c - (((c >= '0') && (c <= '9')) ? '0' : '7'));
-}
-
-u_int
-inet_nsap_addr(const char *ascii, u_char *binary, int maxlen) {
- u_char c, nib;
- u_int len = 0;
-
- if (ascii[0] != '0' || (ascii[1] != 'x' && ascii[1] != 'X'))
- return (0);
- ascii += 2;
-
- while ((c = *ascii++) != '\0' && len < (u_int)maxlen) {
- if (c == '.' || c == '+' || c == '/')
- continue;
- if (!isascii(c))
- return (0);
- if (islower(c))
- c = toupper(c);
- if (isxdigit(c)) {
- nib = xtob(c);
- c = *ascii++;
- if (c != '\0') {
- c = toupper(c);
- if (isxdigit(c)) {
- *binary++ = (nib << 4) | xtob(c);
- len++;
- } else
- return (0);
- }
- else
- return (0);
- }
- else
- return (0);
- }
- return (len);
-}
-
-char *
-inet_nsap_ntoa(int binlen, const u_char *binary, char *ascii) {
- int nib;
- int i;
- static char tmpbuf[2+255*3];
- char *start;
-
- if (ascii)
- start = ascii;
- else {
- ascii = tmpbuf;
- start = tmpbuf;
- }
-
- *ascii++ = '0';
- *ascii++ = 'x';
-
- if (binlen > 255)
- binlen = 255;
-
- for (i = 0; i < binlen; i++) {
- nib = *binary >> 4;
- *ascii++ = nib + (nib < 10 ? '0' : '7');
- nib = *binary++ & 0x0f;
- *ascii++ = nib + (nib < 10 ? '0' : '7');
- if (((i % 2) == 0 && (i + 1) < binlen))
- *ascii++ = '.';
- }
- *ascii = '\0';
- return (start);
-}
diff --git a/contrib/bind/lib/irs/Makefile b/contrib/bind/lib/irs/Makefile
deleted file mode 100644
index 0c4e46d..0000000
--- a/contrib/bind/lib/irs/Makefile
+++ /dev/null
@@ -1,119 +0,0 @@
-# Copyright (c) 1996,1999 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.
-
-# $Id: Makefile,v 8.24 2001/08/14 05:58:07 marka Exp $
-
-# these are only appropriate for BSD 4.4 or derivatives, and are used in
-# development. normal builds will be done in the top level directory and
-# this Makefile will be invoked with a lot of overrides for the following:
-SYSTYPE= freebsd
-DESTDIR =
-DESTLIB = /usr/local/lib
-O=o
-A=a
-CC= cc
-LD= ld
-SHELL= /bin/sh
-CDEBUG= -g -Wall
-TOP= ../..
-INCL = ${TOP}/include
-PORTINCL = ${TOP}/port/${SYSTYPE}/include
-LIBBIND = ${TOP}/lib/libbind.${A}
-LIBBINDR = ../${TOP}/lib/libbind_r.${A}
-CFLAGS= ${CDEBUG}
-CPPFLAGS= -I${PORTINCL} -I${INCL}
-# -D__BIND_NOSTATIC -Wimplicit
-LD_LIBFLAGS= -x -r
-AR= ar cru
-RANLIB= ranlib
-INSTALL= install
-INSTALL_EXEC=
-INSTALL_LIB=-o bin -g bin
-THREADED= threaded
-
-SRCS= dns.c dns_gr.c dns_ho.c dns_nw.c dns_pr.c dns_pw.c \
- dns_sv.c gai_strerror.c gen.c gen_gr.c gen_ho.c \
- gen_ng.c gen_nw.c gen_pr.c gen_pw.c gen_sv.c \
- getaddrinfo.c getgrent.c getgrent_r.c gethostent.c \
- gethostent_r.c getnameinfo.c getnetent.c getnetent_r.c \
- getnetgrent.c getnetgrent_r.c getprotoent.c \
- getprotoent_r.c getpwent.c getpwent_r.c getservent.c \
- getservent_r.c hesiod.c irs_data.c \
- irp.c irp_gr.c irp_ho.c irp_ng.c irp_nw.c \
- irp_pr.c irp_pw.c irp_sv.c irpmarshall.c \
- lcl.c lcl_gr.c \
- lcl_ho.c lcl_ng.c lcl_nw.c lcl_pr.c lcl_pw.c \
- lcl_sv.c nis.c nis_gr.c nis_ho.c nis_ng.c nis_nw.c \
- nis_pr.c nis_pw.c nis_sv.c nul_ng.c util.c
-
-OBJS= dns.${O} dns_gr.${O} dns_ho.${O} dns_nw.${O} dns_pr.${O} dns_pw.${O} \
- dns_sv.${O} gai_strerror.${O} gen.${O} gen_gr.${O} gen_ho.${O} \
- gen_ng.${O} gen_nw.${O} gen_pr.${O} gen_pw.${O} gen_sv.${O} \
- getaddrinfo.${O} getgrent.${O} getgrent_r.${O} gethostent.${O} \
- gethostent_r.${O} getnameinfo.${O} getnetent.${O} getnetent_r.${O} \
- getnetgrent.${O} getnetgrent_r.${O} getprotoent.${O} \
- getprotoent_r.${O} getpwent.${O} getpwent_r.${O} getservent.${O} \
- getservent_r.${O} hesiod.${O} irs_data.${O} \
- irp.${O} irp_gr.${O} irp_ho.${O} irp_ng.${O} irp_nw.${O} \
- irp_pr.${O} irp_pw.${O} irp_sv.${O} irpmarshall.${O} \
- lcl.${O} lcl_gr.${O} \
- lcl_ho.${O} lcl_ng.${O} lcl_nw.${O} lcl_pr.${O} lcl_pw.${O} \
- lcl_sv.${O} nis.${O} nis_gr.${O} nis_ho.${O} nis_ng.${O} nis_nw.${O} \
- nis_pr.${O} nis_pw.${O} nis_sv.${O} nul_ng.${O} util.${O}
-
-all: ${LIBBIND}
-
-${LIBBIND}: ${OBJS}
- -( cd ${THREADED} ; \
- ${AR} ${LIBBINDR} ${ARPREF} ${OBJS} ${ARSUFF} ; \
- ${RANLIB} ${LIBBINDR} )
- ${AR} ${LIBBIND} ${ARPREF} ${OBJS} ${ARSUFF}
- ${RANLIB} ${LIBBIND}
-
-.c.${O}:
- mkdir ${THREADED} 2> /dev/null || test -d ${THREADED} -a -w ${THREADED}
- -(${CC} ${CPPFLAGS} ${CFLAGS} ${BOUNDS} ${REENTRANT} -c $*.c \
- -o ${THREADED}/$*.${O} ; \
- ${LDS} ${LD} ${LD_LIBFLAGS} ${THREADED}/$*.${O} \
- -o ${THREADED}/$*.out && \
- ${LDS} mv ${THREADED}/$*.out ${THREADED}/$*.${O})
- ${CC} ${CPPFLAGS} ${CFLAGS} ${BOUNDS} -c $*.c
- -${LDS} ${LD} ${LD_LIBFLAGS} $*.${O} -o $*.out && \
- ${LDS} mv $*.out $*.${O}
-
-distclean: clean
-
-clean: FRC
- rm -f .depend a.out core ${LIB} tags
- rm -f *.${O} *.BAK *.CKP *~
- rm -f ${THREADED}/*.${O}
- -if test -d ${THREADED} ; then rmdir ${THREADED}; else true; fi
-
-depend: FRC
- mkdep -I${INCL} -I${PORTINCL} ${CPPFLAGS} ${SRCS}
-
-links: FRC
- @set -e; ln -s SRC/*.[ch] .
-
-testirpd: testirpd.o ${LIBBIND}
- ${CC} ${CDEBUG} ${LDFLAGS} -o testirpd testirpd.o ${LIBBIND} ${SYSLIBS}
-
-
-install:
-
-FRC:
-
-# DO NOT DELETE THIS LINE -- mkdep uses it.
-# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
diff --git a/contrib/bind/lib/irs/Makefile.BSD b/contrib/bind/lib/irs/Makefile.BSD
deleted file mode 100644
index d30c417..0000000
--- a/contrib/bind/lib/irs/Makefile.BSD
+++ /dev/null
@@ -1,25 +0,0 @@
-# BSDI $Id: Makefile.BSD,v 1.5 1999/01/18 07:46:47 vixie Exp $
-#
-# @(#)Makefile 5.12 (Berkeley) 7/15/92
-
-CFLAGS= -g
-
-CC= gcc2
-CFLAGS+= -Wall -Wno-unused
-
-LIB= irs
-CFLAGS+= -I${.CURDIR}/..
-SRCS= lcl.c lcl_gr.c lcl_pw.c lcl_sv.c lcl_pr.c lcl_ho.c lcl_nw.c lcl_ng.c \
- dns.c dns_gr.c dns_pw.c dns_sv.c dns_pr.c dns_ho.c dns_nw.c \
- nis.c nis_gr.c nis_pw.c nis_sv.c nis_pr.c nis_ho.c nis_nw.c nis_ng.c \
- gen.c gen_gr.c gen_pw.c gen_sv.c gen_pr.c gen_ho.c gen_nw.c gen_ng.c \
- getgrent.c getpwent.c getservent.c getprotoent.c gethostent.c \
- getnetent.c getnetgrent.c \
- nul_ng.c irs_data.c irp.c irp_gr.c irp_ho.c irp_ng.c irp_nw.c \
- irp_pr.c irp_pw.c irp_sv.c irpd.c irpmarshall.c \
- hesiod.c util.c bitncmp.c
-NOMAN=
-
-all: libirs.a
-
-.include <bsd.lib.mk>
diff --git a/contrib/bind/lib/irs/README b/contrib/bind/lib/irs/README
deleted file mode 100644
index cb81a9a..0000000
--- a/contrib/bind/lib/irs/README
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-This is the Information Retrieval Service (IRS).
-Designed by Paul Vixie (ISC) and Ted T'so (MIT), 1995.
-Written by Paul Vixie, Ted T'so and Sam Stoller, 1996.
-$Id: README,v 1.5 1999/01/08 19:23:52 vixie Exp $
-
-Introduction:
-
- The /etc/irs.conf file defines access methods (like DNS or NIS or
-LOCAL) for each map (like PASSWD or GROUP or HOSTS). One of the access
-methods is "generic" in that it uses the rules from /etc/irs.conf to decide
-which of potentially several different access methods to use for any given
-map. Stubs have been written for all of the system getXbyY() functions so
-that old programs can get this new "multiple access method" capability without
-any source code changes.
-
-Thread Safety:
-
- It is possible for a thread safe program to be altered to call the
-underlying interface (rather than the standard getXbyY() stubs) and get some
-reentrance capabilities. Note that the underlying libraries (which we call)
-are not all thread-safe, for example, the YP and DNS resolvers. A lot more
-work will need to be done before we have full thread safety. But we believe
-that the native API for this system does not impose any reentrancy problems.
-We don't use global or static variables anywhere except in the getXbyY() stubs.
-
-Apologies:
-
- We did cheap object orientation without using C++. This stuff is
-standard C, and it suffers from some of the defects shared by all object
-systems implemented in C. Even so, this is the smallest design we could
-think of that would be extensible to more access methods, more map types,
-and more map operations (like BYNAME or BYGID or whatever) in the future.
-
- There's a fair amount of duplicated code between the different
-access methods for a given map. For example, the code that parses the
-passwd entries is almost identical between the DNS and NIS map objects. To
-clean this up, the almost-identical functions need to be split into similar
-and dissimilar parts, and some parts of the "struct pvt"'s need to be made
-shared via substructures.
diff --git a/contrib/bind/lib/irs/dns.c b/contrib/bind/lib/irs/dns.c
deleted file mode 100644
index 3feed26..0000000
--- a/contrib/bind/lib/irs/dns.c
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Copyright (c) 1996-1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: dns.c,v 1.16 2001/05/29 05:48:26 marka Exp $";
-#endif
-
-/*
- * dns.c --- this is the top-level accessor function for the dns
- */
-
-#include "port_before.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-
-#include <resolv.h>
-
-#include <isc/memcluster.h>
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "hesiod.h"
-#include "dns_p.h"
-
-/* forward */
-
-static void dns_close(struct irs_acc *);
-static struct __res_state * dns_res_get(struct irs_acc *);
-static void dns_res_set(struct irs_acc *, struct __res_state *,
- void (*)(void *));
-
-/* public */
-
-struct irs_acc *
-irs_dns_acc(const char *options) {
- struct irs_acc *acc;
- struct dns_p *dns;
-
- UNUSED(options);
-
- if (!(acc = memget(sizeof *acc))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(acc, 0x5e, sizeof *acc);
- if (!(dns = memget(sizeof *dns))) {
- errno = ENOMEM;
- memput(acc, sizeof *acc);
- return (NULL);
- }
- memset(dns, 0x5e, sizeof *dns);
- dns->res = NULL;
- dns->free_res = NULL;
- if (hesiod_init(&dns->hes_ctx) < 0) {
- /*
- * We allow the dns accessor class to initialize
- * despite hesiod failing to initialize correctly,
- * since dns host queries don't depend on hesiod.
- */
- dns->hes_ctx = NULL;
- }
- acc->private = dns;
-#ifdef WANT_IRS_GR
- acc->gr_map = irs_dns_gr;
-#else
- acc->gr_map = NULL;
-#endif
-#ifdef WANT_IRS_PW
- acc->pw_map = irs_dns_pw;
-#else
- acc->pw_map = NULL;
-#endif
- acc->sv_map = irs_dns_sv;
- acc->pr_map = irs_dns_pr;
- acc->ho_map = irs_dns_ho;
- acc->nw_map = irs_dns_nw;
- acc->ng_map = irs_nul_ng;
- acc->res_get = dns_res_get;
- acc->res_set = dns_res_set;
- acc->close = dns_close;
- return (acc);
-}
-
-/* methods */
-static struct __res_state *
-dns_res_get(struct irs_acc *this) {
- struct dns_p *dns = (struct dns_p *)this->private;
-
- if (dns->res == NULL) {
- struct __res_state *res;
- res = (struct __res_state *)malloc(sizeof *res);
- if (res == NULL)
- return (NULL);
- memset(dns->res, 0, sizeof *dns->res);
- dns_res_set(this, res, free);
- }
-
- if ((dns->res->options & RES_INIT) == 0 &&
- res_ninit(dns->res) < 0)
- return (NULL);
-
- return (dns->res);
-}
-
-static void
-dns_res_set(struct irs_acc *this, struct __res_state *res,
- void (*free_res)(void *)) {
- struct dns_p *dns = (struct dns_p *)this->private;
-
- if (dns->res && dns->free_res) {
- res_nclose(dns->res);
- (*dns->free_res)(dns->res);
- }
- dns->res = res;
- dns->free_res = free_res;
-}
-
-static void
-dns_close(struct irs_acc *this) {
- struct dns_p *dns;
-
- dns = (struct dns_p *)this->private;
- if (dns->res && dns->free_res)
- (*dns->free_res)(dns->res);
- if (dns->hes_ctx)
- hesiod_end(dns->hes_ctx);
- memput(dns, sizeof *dns);
- memput(this, sizeof *this);
-}
-
diff --git a/contrib/bind/lib/irs/dns_gr.c b/contrib/bind/lib/irs/dns_gr.c
deleted file mode 100644
index b314f11..0000000
--- a/contrib/bind/lib/irs/dns_gr.c
+++ /dev/null
@@ -1,293 +0,0 @@
-/*
- * Copyright (c) 1996-1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: dns_gr.c,v 1.21 2002/07/08 06:26:09 marka Exp $";
-#endif
-
-/*
- * dns_gr.c --- this file contains the functions for accessing
- * group information from Hesiod.
- */
-
-#include "port_before.h"
-
-#ifndef WANT_IRS_GR
-static int __bind_irs_gr_unneeded;
-#else
-
-#include <sys/param.h>
-#include <sys/types.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-
-#include <isc/memcluster.h>
-
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "hesiod.h"
-#include "dns_p.h"
-
-/* Types. */
-
-struct pvt {
- /*
- * This is our private accessor data. It has a shared hesiod context.
- */
- struct dns_p * dns;
- /*
- * Need space to store the entries read from the group file.
- * The members list also needs space per member, and the
- * strings making up the user names must be allocated
- * somewhere. Rather than doing lots of small allocations,
- * we keep one buffer and resize it as needed.
- */
- struct group group;
- size_t nmemb; /* Malloc'd max index of gr_mem[]. */
- char * membuf;
- size_t membufsize;
-};
-
-/* Forward. */
-
-static struct group * gr_next(struct irs_gr *);
-static struct group * gr_byname(struct irs_gr *, const char *);
-static struct group * gr_bygid(struct irs_gr *, gid_t);
-static void gr_rewind(struct irs_gr *);
-static void gr_close(struct irs_gr *);
-static int gr_list(struct irs_gr *, const char *,
- gid_t, gid_t *, int *);
-static void gr_minimize(struct irs_gr *);
-static struct __res_state * gr_res_get(struct irs_gr *);
-static void gr_res_set(struct irs_gr *,
- struct __res_state *,
- void (*)(void *));
-
-static struct group * get_hes_group(struct irs_gr *this,
- const char *name,
- const char *type);
-
-/* Public. */
-
-struct irs_gr *
-irs_dns_gr(struct irs_acc *this) {
- struct dns_p *dns = (struct dns_p *)this->private;
- struct irs_gr *gr;
- struct pvt *pvt;
-
- if (!dns || !dns->hes_ctx) {
- errno = ENODEV;
- return (NULL);
- }
- if (!(pvt = memget(sizeof *pvt))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- pvt->dns = dns;
- if (!(gr = memget(sizeof *gr))) {
- memput(pvt, sizeof *pvt);
- errno = ENOMEM;
- return (NULL);
- }
- memset(gr, 0x5e, sizeof *gr);
- gr->private = pvt;
- gr->next = gr_next;
- gr->byname = gr_byname;
- gr->bygid = gr_bygid;
- gr->rewind = gr_rewind;
- gr->close = gr_close;
- gr->list = gr_list;
- gr->minimize = gr_minimize;
- gr->res_get = gr_res_get;
- gr->res_set = gr_res_set;
- return (gr);
-}
-
-/* methods */
-
-static void
-gr_close(struct irs_gr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->group.gr_mem)
- free(pvt->group.gr_mem);
- if (pvt->membuf)
- free(pvt->membuf);
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-static struct group *
-gr_next(struct irs_gr *this) {
-
- UNUSED(this);
-
- return (NULL);
-}
-
-static struct group *
-gr_byname(struct irs_gr *this, const char *name) {
- return (get_hes_group(this, name, "group"));
-}
-
-static struct group *
-gr_bygid(struct irs_gr *this, gid_t gid) {
- char name[32];
-
- sprintf(name, "%ld", (long)gid);
- return (get_hes_group(this, name, "gid"));
-}
-
-static void
-gr_rewind(struct irs_gr *this) {
-
- UNUSED(this);
-
- /* NOOP */
-}
-
-static int
-gr_list(struct irs_gr *this, const char *name,
- gid_t basegid, gid_t *groups, int *ngroups)
-{
- UNUSED(this);
- UNUSED(name);
- UNUSED(basegid);
- UNUSED(groups);
-
- *ngroups = 0;
- /* There's some way to do this in Hesiod. */
- return (-1);
-}
-
-static void
-gr_minimize(struct irs_gr *this) {
-
- UNUSED(this);
- /* NOOP */
-}
-
-/* Private. */
-
-static struct group *
-get_hes_group(struct irs_gr *this, const char *name, const char *type) {
- struct pvt *pvt = (struct pvt *)this->private;
- char **hes_list, *cp, **new;
- size_t num_members = 0;
- u_long t;
-
- hes_list = hesiod_resolve(pvt->dns->hes_ctx, name, type);
- if (!hes_list)
- return (NULL);
-
- /*
- * Copy the returned hesiod string into storage space.
- */
- if (pvt->membuf)
- free(pvt->membuf);
- pvt->membuf = strdup(*hes_list);
- hesiod_free_list(pvt->dns->hes_ctx, hes_list);
-
- cp = pvt->membuf;
- pvt->group.gr_name = cp;
- if (!(cp = strchr(cp, ':')))
- goto cleanup;
- *cp++ = '\0';
-
- pvt->group.gr_passwd = cp;
- if (!(cp = strchr(cp, ':')))
- goto cleanup;
- *cp++ = '\0';
-
- errno = 0;
- t = strtoul(cp, NULL, 10);
- if (errno == ERANGE)
- goto cleanup;
- pvt->group.gr_gid = (gid_t) t;
- if (!(cp = strchr(cp, ':')))
- goto cleanup;
- cp++;
-
- /*
- * Parse the members out.
- */
- while (*cp) {
- if (num_members+1 >= pvt->nmemb || pvt->group.gr_mem == NULL) {
- pvt->nmemb += 10;
- new = realloc(pvt->group.gr_mem,
- pvt->nmemb * sizeof(char *));
- if (new == NULL)
- goto cleanup;
- pvt->group.gr_mem = new;
- }
- pvt->group.gr_mem[num_members++] = cp;
- if (!(cp = strchr(cp, ',')))
- break;
- *cp++ = '\0';
- }
- if (!pvt->group.gr_mem) {
- pvt->group.gr_mem = malloc(sizeof(char*));
- if (!pvt->group.gr_mem)
- goto cleanup;
- }
- pvt->group.gr_mem[num_members] = NULL;
-
- return (&pvt->group);
-
- cleanup:
- if (pvt->group.gr_mem) {
- free(pvt->group.gr_mem);
- pvt->group.gr_mem = NULL;
- }
- if (pvt->membuf) {
- free(pvt->membuf);
- pvt->membuf = NULL;
- }
- return (NULL);
-}
-
-static struct __res_state *
-gr_res_get(struct irs_gr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct dns_p *dns = pvt->dns;
-
- return (__hesiod_res_get(dns->hes_ctx));
-}
-
-static void
-gr_res_set(struct irs_gr *this, struct __res_state * res,
- void (*free_res)(void *)) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct dns_p *dns = pvt->dns;
-
- __hesiod_res_set(dns->hes_ctx, res, free_res);
-}
-
-#endif /* WANT_IRS_GR */
diff --git a/contrib/bind/lib/irs/dns_ho.c b/contrib/bind/lib/irs/dns_ho.c
deleted file mode 100644
index 1b37e3d..0000000
--- a/contrib/bind/lib/irs/dns_ho.c
+++ /dev/null
@@ -1,1156 +0,0 @@
-/*
- * Copyright (c) 1985, 1988, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Portions Copyright (c) 1996-1999 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.
- */
-
-/* from gethostnamadr.c 8.1 (Berkeley) 6/4/93 */
-/* BIND Id: gethnamaddr.c,v 8.15 1996/05/22 04:56:30 vixie Exp $ */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: dns_ho.c,v 1.42.6.1 2003/06/02 09:24:40 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-/* Imports. */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.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
-# define SPRINTF(x) strlen(sprintf/**/x)
-#else
-# define SPRINTF(x) sprintf x
-#endif
-
-/* Definitions. */
-
-#define MAXALIASES 35
-#define MAXADDRS 35
-
-#define MAXPACKET (65535) /* Maximum TCP message size */
-
-#define BOUNDS_CHECK(ptr, count) \
- if ((ptr) + (count) > eom) { \
- had_error++; \
- continue; \
- } else (void)0
-
-typedef union {
- HEADER hdr;
- u_char buf[MAXPACKET];
-} querybuf;
-
-struct dns_res_target {
- struct dns_res_target *next;
- querybuf qbuf; /* query buffer */
- u_char *answer; /* buffer to put answer */
- int anslen; /* size of answer buffer */
- int qclass, qtype; /* class and type of query */
- int action; /* condition whether query is really issued */
- char qname[MAXDNAME +1]; /* domain name */
-#if 0
- int n; /* result length */
-#endif
-};
-enum {RESTGT_DOALWAYS, RESTGT_AFTERFAILURE, RESTGT_IGNORE};
-enum {RESQRY_SUCCESS, RESQRY_FAIL};
-
-struct pvt {
- struct hostent host;
- char * h_addr_ptrs[MAXADDRS + 1];
- char * host_aliases[MAXALIASES];
- char hostbuf[8*1024];
- u_char host_addr[16]; /* IPv4 or IPv6 */
- struct __res_state *res;
- void (*free_res)(void *);
-};
-
-typedef union {
- int32_t al;
- char ac;
-} align;
-
-static const u_char mapped[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0xff,0xff };
-static const u_char tunnelled[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 };
-/* Note: the IPv6 loopback address is in the "tunnel" space */
-static const u_char v6local[] = { 0,0, 0,1 }; /* last 4 bytes of IPv6 addr */
-
-/* Forwards. */
-
-static void ho_close(struct irs_ho *this);
-static struct hostent * ho_byname(struct irs_ho *this, const char *name);
-static struct hostent * ho_byname2(struct irs_ho *this, const char *name,
- int af);
-static struct hostent * ho_byaddr(struct irs_ho *this, const void *addr,
- int len, int af);
-static struct hostent * ho_next(struct irs_ho *this);
-static void ho_rewind(struct irs_ho *this);
-static void ho_minimize(struct irs_ho *this);
-static struct __res_state * ho_res_get(struct irs_ho *this);
-static void ho_res_set(struct irs_ho *this,
- struct __res_state *res,
- void (*free_res)(void *));
-static struct addrinfo * ho_addrinfo(struct irs_ho *this, const char *name,
- const struct addrinfo *pai);
-
-static void map_v4v6_hostent(struct hostent *hp, char **bp,
- char *ep);
-static void addrsort(res_state, char **, int);
-static struct hostent * gethostans(struct irs_ho *this,
- const u_char *ansbuf, int anslen,
- const char *qname, int qtype,
- int af, int size,
- struct addrinfo **ret_aip,
- const struct addrinfo *pai);
-static int add_hostent(struct pvt *pvt, char *bp, char **hap,
- struct addrinfo *ai);
-static int init(struct irs_ho *this);
-
-/* Exports. */
-
-struct irs_ho *
-irs_dns_ho(struct irs_acc *this) {
- struct irs_ho *ho;
- struct pvt *pvt;
-
- UNUSED(this);
-
- if (!(pvt = memget(sizeof *pvt))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
-
- if (!(ho = memget(sizeof *ho))) {
- memput(pvt, sizeof *pvt);
- errno = ENOMEM;
- return (NULL);
- }
- memset(ho, 0x5e, sizeof *ho);
- ho->private = pvt;
- ho->close = ho_close;
- ho->byname = ho_byname;
- ho->byname2 = ho_byname2;
- ho->byaddr = ho_byaddr;
- ho->next = ho_next;
- ho->rewind = ho_rewind;
- ho->minimize = ho_minimize;
- ho->res_get = ho_res_get;
- ho->res_set = ho_res_set;
- ho->addrinfo = ho_addrinfo;
- return (ho);
-}
-
-/* Methods. */
-
-static void
-ho_close(struct irs_ho *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- ho_minimize(this);
- if (pvt->res && pvt->free_res)
- (*pvt->free_res)(pvt->res);
- if (pvt)
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-static struct hostent *
-ho_byname(struct irs_ho *this, const char *name) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct hostent *hp;
-
- if (init(this) == -1)
- return (NULL);
-
- if (pvt->res->options & RES_USE_INET6) {
- hp = ho_byname2(this, name, AF_INET6);
- if (hp)
- return (hp);
- }
- return (ho_byname2(this, name, AF_INET));
-}
-
-static struct hostent *
-ho_byname2(struct irs_ho *this, const char *name, int af)
-{
- struct pvt *pvt = (struct pvt *)this->private;
- struct hostent *hp = NULL;
- int n, size;
- char tmp[NS_MAXDNAME];
- const char *cp;
- struct addrinfo ai;
- struct dns_res_target *q, *p;
- int querystate = RESQRY_FAIL;
-
- if (init(this) == -1)
- return (NULL);
-
- q = memget(sizeof(*q));
- if (q == NULL) {
- RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
- errno = ENOMEM;
- goto cleanup;
- }
- memset(q, 0, sizeof(q));
-
- switch (af) {
- case AF_INET:
- size = INADDRSZ;
- q->qclass = C_IN;
- q->qtype = T_A;
- q->answer = q->qbuf.buf;
- q->anslen = sizeof(q->qbuf);
- q->action = RESTGT_DOALWAYS;
- break;
- case AF_INET6:
- size = IN6ADDRSZ;
- q->qclass = C_IN;
- q->qtype = T_AAAA;
- q->answer = q->qbuf.buf;
- q->anslen = sizeof(q->qbuf);
- q->action = RESTGT_DOALWAYS;
- break;
- default:
- RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
- errno = EAFNOSUPPORT;
- hp = NULL;
- 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.
- */
- if (!strchr(name, '.') && (cp = res_hostalias(pvt->res, name,
- tmp, sizeof tmp)))
- name = cp;
-
- 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;
- }
-
- if ((n = res_nsearch(pvt->res, name, p->qclass, p->qtype,
- p->answer, p->anslen)) < 0) {
- querystate = RESQRY_FAIL;
- continue;
- }
-
- memset(&ai, 0, sizeof(ai));
- ai.ai_family = af;
- if ((hp = gethostans(this, p->answer, n, name, p->qtype,
- af, size, NULL,
- (const struct addrinfo *)&ai)) != NULL)
- goto cleanup; /* no more loop is necessary */
-
- querystate = RESQRY_FAIL;
- continue;
- }
-
- cleanup:
- if (q != NULL)
- memput(q, sizeof(*q));
- return(hp);
-}
-
-static struct hostent *
-ho_byaddr(struct irs_ho *this, const void *addr, int len, int af)
-{
- struct pvt *pvt = (struct pvt *)this->private;
- const u_char *uaddr = addr;
- char *qp;
- struct hostent *hp = NULL;
- struct addrinfo ai;
- struct dns_res_target *q, *q2, *p;
- int n, size, i;
- int querystate = RESQRY_FAIL;
-
- if (init(this) == -1)
- return (NULL);
-
- q = memget(sizeof(*q));
- q2 = memget(sizeof(*q2));
- if (q == NULL || q2 == NULL) {
- RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
- errno = ENOMEM;
- goto cleanup;
- }
- memset(q, 0, sizeof(q));
- memset(q2, 0, sizeof(q2));
-
- if (af == AF_INET6 && len == IN6ADDRSZ &&
- (!memcmp(uaddr, mapped, sizeof mapped) ||
- (!memcmp(uaddr, tunnelled, sizeof tunnelled) &&
- memcmp(&uaddr[sizeof tunnelled], v6local, sizeof(v6local))))) {
- /* Unmap. */
- addr = (const char *)addr + sizeof mapped;
- uaddr += sizeof mapped;
- af = AF_INET;
- len = INADDRSZ;
- }
- switch (af) {
- case AF_INET:
- size = INADDRSZ;
- q->qclass = C_IN;
- q->qtype = T_PTR;
- q->answer = q->qbuf.buf;
- q->anslen = sizeof(q->qbuf);
- q->action = RESTGT_DOALWAYS;
- break;
- case AF_INET6:
- size = IN6ADDRSZ;
- q->qclass = C_IN;
- q->qtype = T_PTR;
- q->answer = q->qbuf.buf;
- q->anslen = sizeof(q->qbuf);
- q->next = q2;
- q->action = RESTGT_DOALWAYS;
- q2->qclass = C_IN;
- q2->qtype = T_PTR;
- q2->answer = q2->qbuf.buf;
- q2->anslen = sizeof(q2->qbuf);
- if ((pvt->res->options & RES_NO_NIBBLE2) != 0)
- q2->action = RESTGT_IGNORE;
- else
- q2->action = RESTGT_AFTERFAILURE;
- break;
- default:
- errno = EAFNOSUPPORT;
- RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
- hp = NULL;
- goto cleanup;
- }
- if (size > len) {
- errno = EINVAL;
- RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
- hp = NULL;
- goto cleanup;
- }
- switch (af) {
- case AF_INET:
- qp = q->qname;
- (void) sprintf(qp, "%u.%u.%u.%u.in-addr.arpa",
- (uaddr[3] & 0xff),
- (uaddr[2] & 0xff),
- (uaddr[1] & 0xff),
- (uaddr[0] & 0xff));
- break;
- case AF_INET6:
- if (q->action != RESTGT_IGNORE) {
- qp = q->qname;
- for (n = IN6ADDRSZ - 1; n >= 0; n--) {
- i = SPRINTF((qp, "%x.%x.",
- uaddr[n] & 0xf,
- (uaddr[n] >> 4) & 0xf));
- if (i < 0)
- abort();
- qp += i;
- }
-#ifdef HAVE_STRLCAT
- strlcat(q->qname, res_get_nibblesuffix(pvt->res),
- sizeof(q->qname));
-#else
- strcpy(qp, res_get_nibblesuffix(pvt->res));
-#endif
- }
- if (q2->action != RESTGT_IGNORE) {
- qp = q2->qname;
- for (n = IN6ADDRSZ - 1; n >= 0; n--) {
- i = SPRINTF((qp, "%x.%x.",
- uaddr[n] & 0xf,
- (uaddr[n] >> 4) & 0xf));
- if (i < 0)
- abort();
- qp += i;
- }
-#ifdef HAVE_STRLCAT
- strlcat(q->qname, res_get_nibblesuffix2(pvt->res),
- sizeof(q->qname));
-#else
- strcpy(qp, res_get_nibblesuffix2(pvt->res));
-#endif
- }
- 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;
- }
-
- if ((n = res_nquery(pvt->res, p->qname, p->qclass, p->qtype,
- p->answer, p->anslen)) < 0) {
- querystate = RESQRY_FAIL;
- continue;
- }
-
- memset(&ai, 0, sizeof(ai));
- ai.ai_family = af;
- hp = gethostans(this, p->answer, n, p->qname, T_PTR, af, size,
- NULL, (const struct addrinfo *)&ai);
- if (!hp) {
- querystate = RESQRY_FAIL;
- continue;
- }
-
- memcpy(pvt->host_addr, addr, len);
- pvt->h_addr_ptrs[0] = (char *)pvt->host_addr;
- pvt->h_addr_ptrs[1] = NULL;
- if (af == AF_INET && (pvt->res->options & RES_USE_INET6)) {
- map_v4v6_address((char*)pvt->host_addr,
- (char*)pvt->host_addr);
- pvt->host.h_addrtype = AF_INET6;
- pvt->host.h_length = IN6ADDRSZ;
- }
-
- RES_SET_H_ERRNO(pvt->res, NETDB_SUCCESS);
- goto cleanup; /* no more loop is necessary. */
- }
- hp = NULL; /* H_ERRNO was set by subroutines */
-
- cleanup:
- if (q != NULL)
- memput(q, sizeof(*q));
- if (q2 != NULL)
- memput(q2, sizeof(*q2));
- return(hp);
-}
-
-static struct hostent *
-ho_next(struct irs_ho *this) {
-
- UNUSED(this);
-
- return (NULL);
-}
-
-static void
-ho_rewind(struct irs_ho *this) {
-
- UNUSED(this);
-
- /* NOOP */
-}
-
-static void
-ho_minimize(struct irs_ho *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->res)
- res_nclose(pvt->res);
-}
-
-static struct __res_state *
-ho_res_get(struct irs_ho *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (!pvt->res) {
- struct __res_state *res;
- res = (struct __res_state *)malloc(sizeof *res);
- if (!res) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(res, 0, sizeof *res);
- ho_res_set(this, res, free);
- }
-
- return (pvt->res);
-}
-
-/* XXX */
-extern struct addrinfo *addr2addrinfo __P((const struct addrinfo *,
- const char *));
-
-static struct addrinfo *
-ho_addrinfo(struct irs_ho *this, const char *name, const struct addrinfo *pai)
-{
- struct pvt *pvt = (struct pvt *)this->private;
- int n;
- char tmp[NS_MAXDNAME];
- const char *cp;
- struct dns_res_target *q, *q2, *p;
- struct addrinfo sentinel, *cur;
- int querystate = RESQRY_FAIL;
-
- if (init(this) == -1)
- return (NULL);
-
- memset(&sentinel, 0, sizeof(sentinel));
- cur = &sentinel;
-
- q = memget(sizeof(*q));
- q2 = memget(sizeof(*q2));
- if (q == NULL || q2 == NULL) {
- RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
- errno = ENOMEM;
- goto cleanup;
- }
- memset(q, 0, sizeof(q2));
- memset(q2, 0, sizeof(q2));
-
- switch (pai->ai_family) {
- case AF_UNSPEC:
- /* prefer IPv6 */
- q->qclass = C_IN;
- q->qtype = T_AAAA;
- q->answer = q->qbuf.buf;
- q->anslen = sizeof(q->qbuf);
- q->next = q2;
- q->action = RESTGT_DOALWAYS;
- q2->qclass = C_IN;
- q2->qtype = T_A;
- q2->answer = q2->qbuf.buf;
- q2->anslen = sizeof(q2->qbuf);
- q2->action = RESTGT_DOALWAYS;
- break;
- case AF_INET:
- q->qclass = C_IN;
- q->qtype = T_A;
- q->answer = q->qbuf.buf;
- q->anslen = sizeof(q->qbuf);
- q->action = RESTGT_DOALWAYS;
- break;
- case AF_INET6:
- q->qclass = C_IN;
- q->qtype = T_AAAA;
- q->answer = q->qbuf.buf;
- q->anslen = sizeof(q->qbuf);
- q->action = RESTGT_DOALWAYS;
- break;
- default:
- RES_SET_H_ERRNO(pvt->res, NO_RECOVERY); /* better error? */
- 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.
- */
- if (!strchr(name, '.') && (cp = res_hostalias(pvt->res, name,
- tmp, sizeof tmp)))
- name = cp;
-
- for (p = q; p; p = p->next) {
- struct addrinfo *ai;
-
- switch(p->action) {
- case RESTGT_DOALWAYS:
- break;
- case RESTGT_AFTERFAILURE:
- if (querystate == RESQRY_SUCCESS)
- continue;
- break;
- case RESTGT_IGNORE:
- continue;
- }
-
- if ((n = res_nsearch(pvt->res, name, p->qclass, p->qtype,
- p->answer, p->anslen)) < 0) {
- querystate = RESQRY_FAIL;
- continue;
- }
- (void)gethostans(this, p->answer, n, name, p->qtype,
- pai->ai_family, /* XXX: meaningless */
- 0, &ai, pai);
- if (ai) {
- querystate = RESQRY_SUCCESS;
- cur->ai_next = ai;
- while (cur && cur->ai_next)
- cur = cur->ai_next;
- }
- else
- querystate = RESQRY_FAIL;
- }
-
- cleanup:
- if (q != NULL)
- memput(q, sizeof(*q));
- if (q2 != NULL)
- memput(q2, sizeof(*q2));
- return(sentinel.ai_next);
-}
-
-static void
-ho_res_set(struct irs_ho *this, struct __res_state *res,
- void (*free_res)(void *)) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->res && pvt->free_res) {
- res_nclose(pvt->res);
- (*pvt->free_res)(pvt->res);
- }
-
- pvt->res = res;
- pvt->free_res = free_res;
-}
-
-/* Private. */
-
-static struct hostent *
-gethostans(struct irs_ho *this,
- const u_char *ansbuf, int anslen, const char *qname, int qtype,
- int af, int size, /* meaningless for addrinfo cases */
- struct addrinfo **ret_aip, const struct addrinfo *pai)
-{
- struct pvt *pvt = (struct pvt *)this->private;
- int type, class, ancount, qdcount, n, haveanswer, had_error;
- int error = NETDB_SUCCESS, arcount;
- int (*name_ok)(const char *);
- const HEADER *hp;
- const u_char *eom;
- const u_char *eor;
- const u_char *cp;
- const char *tname;
- const char *hname;
- char *bp, *ep, **ap, **hap;
- char tbuf[MAXDNAME+1];
- struct addrinfo sentinel, *cur, ai;
-
- if (pai == NULL) abort();
- if (ret_aip != NULL)
- *ret_aip = NULL;
- memset(&sentinel, 0, sizeof(sentinel));
- cur = &sentinel;
-
- tname = qname;
- eom = ansbuf + anslen;
- switch (qtype) {
- case T_A:
- case T_AAAA:
- case T_ANY: /* use T_ANY only for T_A/T_AAAA lookup */
- name_ok = res_hnok;
- break;
- case T_PTR:
- name_ok = res_dnok;
- break;
- default:
- abort();
- }
-
- pvt->host.h_addrtype = af;
- pvt->host.h_length = size;
- hname = pvt->host.h_name = NULL;
-
- /*
- * Find first satisfactory answer.
- */
- if (ansbuf + HFIXEDSZ > eom) {
- RES_SET_H_ERRNO(pvt->res, NO_RECOVERY);
- return (NULL);
- }
- hp = (const HEADER *)ansbuf;
- ancount = ntohs(hp->ancount);
- qdcount = ntohs(hp->qdcount);
- arcount = ntohs(hp->arcount);
- bp = pvt->hostbuf;
- ep = pvt->hostbuf + sizeof(pvt->hostbuf);
- cp = ansbuf + HFIXEDSZ;
- if (qdcount != 1) {
- RES_SET_H_ERRNO(pvt->res, NO_RECOVERY);
- return (NULL);
- }
- n = dn_expand(ansbuf, eom, cp, bp, ep - bp);
- if (n < 0 || !maybe_ok(pvt->res, bp, name_ok)) {
- RES_SET_H_ERRNO(pvt->res, NO_RECOVERY);
- return (NULL);
- }
- cp += n + QFIXEDSZ;
- if (cp > eom) {
- RES_SET_H_ERRNO(pvt->res, NO_RECOVERY);
- return (NULL);
- }
- if (qtype == T_A || qtype == T_AAAA || qtype == T_ANY) {
- /* 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).
- */
- n = strlen(bp) + 1; /* for the \0 */
- if (n > MAXHOSTNAMELEN) {
- RES_SET_H_ERRNO(pvt->res, NO_RECOVERY);
- return (NULL);
- }
- pvt->host.h_name = bp;
- hname = bp;
- bp += n;
- /* The qname can be abbreviated, but hname is now absolute. */
- qname = pvt->host.h_name;
- }
- ap = pvt->host_aliases;
- *ap = NULL;
- pvt->host.h_aliases = pvt->host_aliases;
- hap = pvt->h_addr_ptrs;
- *hap = NULL;
- pvt->host.h_addr_list = pvt->h_addr_ptrs;
- haveanswer = 0;
- had_error = 0;
- while (ancount-- > 0 && cp < eom && !had_error) {
- n = dn_expand(ansbuf, eom, cp, bp, ep - bp);
- if (n < 0 || !maybe_ok(pvt->res, bp, name_ok)) {
- had_error++;
- continue;
- }
- cp += n; /* name */
- BOUNDS_CHECK(cp, 3 * INT16SZ + INT32SZ);
- type = ns_get16(cp);
- cp += INT16SZ; /* type */
- class = ns_get16(cp);
- cp += INT16SZ + INT32SZ; /* class, TTL */
- n = ns_get16(cp);
- cp += INT16SZ; /* len */
- BOUNDS_CHECK(cp, n);
- if (class != C_IN) {
- cp += n;
- continue;
- }
- eor = cp + n;
- if ((qtype == T_A || qtype == T_AAAA || qtype == T_ANY) &&
- type == T_CNAME) {
- if (haveanswer) {
- int level = LOG_CRIT;
-#ifdef LOG_SECURITY
- level |= LOG_SECURITY;
-#endif
- syslog(level,
- "gethostans: possible attempt to exploit buffer overflow while looking up %s",
- *qname ? qname : ".");
- }
- n = dn_expand(ansbuf, eor, cp, tbuf, sizeof tbuf);
- if (n < 0 || !maybe_ok(pvt->res, tbuf, name_ok)) {
- had_error++;
- continue;
- }
- cp += n;
- /* Store alias. */
- if (ap >= &pvt->host_aliases[MAXALIASES-1])
- continue;
- *ap++ = bp;
- n = strlen(bp) + 1; /* for the \0 */
- bp += n;
- /* Get canonical name. */
- n = strlen(tbuf) + 1; /* for the \0 */
- if (n > (ep - bp) || n > MAXHOSTNAMELEN) {
- had_error++;
- continue;
- }
-#ifdef HAVE_STRLCPY
- strlcpy(bp, tbuf, ep - bp);
-#else
- strcpy(bp, tbuf);
-#endif
- pvt->host.h_name = bp;
- hname = bp;
- bp += n;
- continue;
- }
- if (qtype == T_PTR && type == T_CNAME) {
- n = dn_expand(ansbuf, eor, cp, tbuf, sizeof tbuf);
- if (n < 0 || !maybe_dnok(pvt->res, tbuf)) {
- had_error++;
- continue;
- }
- cp += n;
-#ifdef RES_USE_DNAME
- if ((pvt->res->options & RES_USE_DNAME) != 0)
-#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.
- */
- if (ns_samename(tname, bp) != 1)
- continue;
- }
- /* Get canonical name. */
- n = strlen(tbuf) + 1; /* for the \0 */
- if (n > (ep - bp)) {
- had_error++;
- continue;
- }
-#ifdef HAVE_STRLCPY
- strlcpy(bp, tbuf, ep - bp);
-#else
- strcpy(bp, tbuf);
-#endif
- tname = bp;
- bp += n;
- continue;
- }
- if (qtype == T_ANY) {
- if (!(type == T_A || type == T_AAAA)) {
- cp += n;
- continue;
- }
- } else if (type != qtype) {
- cp += n;
- continue;
- }
- switch (type) {
- case T_PTR:
- if (ret_aip != NULL) {
- /* addrinfo never needs T_PTR */
- cp += n;
- continue;
- }
- if (ns_samename(tname, bp) != 1) {
- cp += n;
- continue;
- }
- n = dn_expand(ansbuf, eor, cp, bp, ep - bp);
- if (n < 0 || !maybe_hnok(pvt->res, bp) ||
- n >= MAXHOSTNAMELEN) {
- had_error++;
- break;
- }
- cp += n;
- if (!haveanswer) {
- pvt->host.h_name = bp;
- hname = bp;
- }
- else if (ap < &pvt->host_aliases[MAXALIASES-1])
- *ap++ = bp;
- else
- n = -1;
- if (n != -1) {
- n = strlen(bp) + 1; /* for the \0 */
- bp += n;
- }
- break;
- case T_A:
- case T_AAAA:
- if (ns_samename(hname, bp) != 1) {
- cp += n;
- continue;
- }
- if (type == T_A && n != INADDRSZ) {
- cp += n;
- continue;
- }
- if (type == T_AAAA && n != IN6ADDRSZ) {
- cp += n;
- continue;
- }
-
- /* make addrinfo. don't overwrite constant PAI */
- ai = *pai;
- ai.ai_family = (type == T_AAAA) ? AF_INET6 : AF_INET;
- cur->ai_next = addr2addrinfo(
- (const struct addrinfo *)&ai,
- (const char *)cp);
- if (cur->ai_next == NULL)
- had_error++;
-
- if (!haveanswer) {
- int nn;
-
- nn = strlen(bp) + 1; /* for the \0 */
- if (nn >= MAXHOSTNAMELEN) {
- cp += n;
- had_error++;
- continue;
- }
- pvt->host.h_name = bp;
- hname = bp;
- bp += nn;
- }
- /* Ensure alignment. */
- bp = (char *)(((u_long)bp + (sizeof(align) - 1)) &
- ~(sizeof(align) - 1));
- /* Avoid overflows. */
- if (bp + n >= &pvt->hostbuf[sizeof pvt->hostbuf]) {
- had_error++;
- continue;
- }
- if (ret_aip) { /* need addrinfo. keep it. */
- while (cur && cur->ai_next)
- cur = cur->ai_next;
- } else if (cur->ai_next) { /* need hostent */
- struct addrinfo *aip = cur->ai_next;
-
- for (aip = cur->ai_next; aip;
- aip = aip->ai_next) {
- int m;
-
- m = add_hostent(pvt, bp, hap, aip);
- if (m < 0) {
- had_error++;
- break;
- }
- if (m == 0)
- continue;
- if (hap < &pvt->h_addr_ptrs[MAXADDRS-1])
- hap++;
- *hap = NULL;
- bp += m;
- }
-
- freeaddrinfo(cur->ai_next);
- cur->ai_next = NULL;
- }
- cp += n;
- break;
- default:
- abort();
- }
- if (!had_error)
- haveanswer++;
- }
- if (haveanswer) {
- if (ret_aip == NULL) {
- *ap = NULL;
- *hap = NULL;
-
- if (pvt->res->nsort && haveanswer > 1 && qtype == T_A)
- addrsort(pvt->res, pvt->h_addr_ptrs,
- haveanswer);
- if (pvt->host.h_name == NULL) {
- n = strlen(qname) + 1; /* for the \0 */
- if (n > (ep - bp) || n >= MAXHOSTNAMELEN)
- goto no_recovery;
-#ifdef HAVE_STRLCPY
- strlcpy(bp, qname, ep - bp);
-#else
- strcpy(bp, qname);
-#endif
- pvt->host.h_name = bp;
- bp += n;
- }
- if (pvt->res->options & RES_USE_INET6)
- map_v4v6_hostent(&pvt->host, &bp, ep);
- RES_SET_H_ERRNO(pvt->res, NETDB_SUCCESS);
- return (&pvt->host);
- } else {
- if ((pai->ai_flags & AI_CANONNAME) != 0) {
- if (pvt->host.h_name == NULL) {
- sentinel.ai_next->ai_canonname =
- strdup(qname);
- }
- else {
- sentinel.ai_next->ai_canonname =
- strdup(pvt->host.h_name);
- }
- }
- *ret_aip = sentinel.ai_next;
- return(NULL);
- }
- }
- no_recovery:
- if (sentinel.ai_next) {
- /* this should be impossible, but check it for safety */
- freeaddrinfo(sentinel.ai_next);
- }
- if (error == NETDB_SUCCESS)
- RES_SET_H_ERRNO(pvt->res, NO_RECOVERY);
- else
- RES_SET_H_ERRNO(pvt->res, error);
- return(NULL);
-}
-
-static int
-add_hostent(struct pvt *pvt, char *bp, char **hap, struct addrinfo *ai)
-{
- int addrlen;
- char *addrp;
- const char **tap;
- char *obp = bp;
-
- switch(ai->ai_addr->sa_family) {
- case AF_INET6:
- addrlen = IN6ADDRSZ;
- addrp = (char *)&((struct sockaddr_in6 *)ai->ai_addr)->sin6_addr;
- break;
- case AF_INET:
- addrlen = INADDRSZ;
- addrp = (char *)&((struct sockaddr_in *)ai->ai_addr)->sin_addr;
- break;
- default:
- return(-1); /* abort? */
- }
-
- /* Ensure alignment. */
- bp = (char *)(((u_long)bp + (sizeof(align) - 1)) &
- ~(sizeof(align) - 1));
- /* Avoid overflows. */
- if (bp + addrlen >= &pvt->hostbuf[sizeof pvt->hostbuf])
- return(-1);
- if (hap >= &pvt->h_addr_ptrs[MAXADDRS-1])
- return(0); /* fail, but not treat it as an error. */
-
- /* Suppress duplicates. */
- for (tap = (const char **)pvt->h_addr_ptrs;
- *tap != NULL;
- tap++)
- if (memcmp(*tap, addrp, addrlen) == 0)
- break;
- if (*tap != NULL)
- return (0);
-
- memcpy(*hap = bp, addrp, addrlen);
- return((bp + addrlen) - obp);
-}
-
-static void
-map_v4v6_hostent(struct hostent *hp, char **bpp, char *ep) {
- char **ap;
-
- if (hp->h_addrtype != AF_INET || hp->h_length != INADDRSZ)
- return;
- hp->h_addrtype = AF_INET6;
- hp->h_length = IN6ADDRSZ;
- for (ap = hp->h_addr_list; *ap; ap++) {
- int i = (u_long)*bpp % sizeof(align);
-
- if (i != 0)
- i = sizeof(align) - i;
-
- if ((ep - *bpp) < (i + IN6ADDRSZ)) {
- /* Out of memory. Truncate address list here. */
- *ap = NULL;
- return;
- }
- *bpp += i;
- map_v4v6_address(*ap, *bpp);
- *ap = *bpp;
- *bpp += IN6ADDRSZ;
- }
-}
-
-static void
-addrsort(res_state statp, char **ap, int num) {
- int i, j, needsort = 0, aval[MAXADDRS];
- char **p;
-
- p = ap;
- for (i = 0; i < num; i++, p++) {
- for (j = 0 ; (unsigned)j < statp->nsort; j++)
- if (statp->sort_list[j].addr.s_addr ==
- (((struct in_addr *)(*p))->s_addr &
- statp->sort_list[j].mask))
- break;
- aval[i] = j;
- if (needsort == 0 && i > 0 && j < aval[i-1])
- needsort = i;
- }
- if (!needsort)
- return;
-
- while (needsort < num) {
- for (j = needsort - 1; j >= 0; j--) {
- if (aval[j] > aval[j+1]) {
- char *hp;
-
- i = aval[j];
- aval[j] = aval[j+1];
- aval[j+1] = i;
-
- hp = ap[j];
- ap[j] = ap[j+1];
- ap[j+1] = hp;
-
- } else
- break;
- }
- needsort++;
- }
-}
-
-static int
-init(struct irs_ho *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (!pvt->res && !ho_res_get(this))
- return (-1);
- if (((pvt->res->options & RES_INIT) == 0) &&
- res_ninit(pvt->res) == -1)
- return (-1);
- return (0);
-}
diff --git a/contrib/bind/lib/irs/dns_nw.c b/contrib/bind/lib/irs/dns_nw.c
deleted file mode 100644
index a322f449..0000000
--- a/contrib/bind/lib/irs/dns_nw.c
+++ /dev/null
@@ -1,594 +0,0 @@
-/*
- * Copyright (c) 1996-1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: dns_nw.c,v 1.25 2002/07/18 02:07:43 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-/* Imports. */
-
-#include "port_before.h"
-
-#include <sys/param.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <netdb.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <isc/memcluster.h>
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "dns_p.h"
-
-#ifdef SPRINTF_CHAR
-# define SPRINTF(x) strlen(sprintf/**/x)
-#else
-# define SPRINTF(x) sprintf x
-#endif
-
-/* Definitions. */
-
-#define MAXALIASES 35
-
-#define MAXPACKET (64*1024)
-
-struct pvt {
- struct nwent net;
- char * ali[MAXALIASES];
- char buf[BUFSIZ+1];
- struct __res_state * res;
- void (*free_res)(void *);
-};
-
-typedef union {
- long al;
- char ac;
-} align;
-
-enum by_what { by_addr, by_name };
-
-/* Forwards. */
-
-static void nw_close(struct irs_nw *);
-static struct nwent * nw_byname(struct irs_nw *, const char *, int);
-static struct nwent * nw_byaddr(struct irs_nw *, void *, int, int);
-static struct nwent * nw_next(struct irs_nw *);
-static void nw_rewind(struct irs_nw *);
-static void nw_minimize(struct irs_nw *);
-static struct __res_state * nw_res_get(struct irs_nw *this);
-static void nw_res_set(struct irs_nw *this,
- struct __res_state *res,
- void (*free_res)(void *));
-
-static struct nwent * get1101byaddr(struct irs_nw *, u_char *, int);
-static struct nwent * get1101byname(struct irs_nw *, const char *);
-static struct nwent * get1101answer(struct irs_nw *,
- u_char *ansbuf, int anslen,
- enum by_what by_what,
- int af, const char *name,
- const u_char *addr, int addrlen);
-static struct nwent * get1101mask(struct irs_nw *this, struct nwent *);
-static int make1101inaddr(const u_char *, int, char *, int);
-static void normalize_name(char *name);
-static int init(struct irs_nw *this);
-
-/* Exports. */
-
-struct irs_nw *
-irs_dns_nw(struct irs_acc *this) {
- struct irs_nw *nw;
- struct pvt *pvt;
-
- UNUSED(this);
-
- if (!(pvt = memget(sizeof *pvt))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- if (!(nw = memget(sizeof *nw))) {
- memput(pvt, sizeof *pvt);
- errno = ENOMEM;
- return (NULL);
- }
- memset(nw, 0x5e, sizeof *nw);
- nw->private = pvt;
- nw->close = nw_close;
- nw->byname = nw_byname;
- nw->byaddr = nw_byaddr;
- nw->next = nw_next;
- nw->rewind = nw_rewind;
- nw->minimize = nw_minimize;
- nw->res_get = nw_res_get;
- nw->res_set = nw_res_set;
- return (nw);
-}
-
-/* Methods. */
-
-static void
-nw_close(struct irs_nw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- nw_minimize(this);
-
- if (pvt->res && pvt->free_res)
- (*pvt->free_res)(pvt->res);
-
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-static struct nwent *
-nw_byname(struct irs_nw *this, const char *name, int af) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (init(this) == -1)
- return (NULL);
-
- switch (af) {
- case AF_INET:
- return (get1101byname(this, name));
- default:
- (void)NULL;
- }
- RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
- errno = EAFNOSUPPORT;
- return (NULL);
-}
-
-static struct nwent *
-nw_byaddr(struct irs_nw *this, void *net, int len, int af) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (init(this) == -1)
- return (NULL);
-
- switch (af) {
- case AF_INET:
- return (get1101byaddr(this, net, len));
- default:
- (void)NULL;
- }
- RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
- errno = EAFNOSUPPORT;
- return (NULL);
-}
-
-static struct nwent *
-nw_next(struct irs_nw *this) {
-
- UNUSED(this);
-
- return (NULL);
-}
-
-static void
-nw_rewind(struct irs_nw *this) {
- UNUSED(this);
- /* NOOP */
-}
-
-static void
-nw_minimize(struct irs_nw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->res)
- res_nclose(pvt->res);
-}
-
-static struct __res_state *
-nw_res_get(struct irs_nw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (!pvt->res) {
- struct __res_state *res;
- res = (struct __res_state *)malloc(sizeof *res);
- if (!res) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(res, 0, sizeof *res);
- nw_res_set(this, res, free);
- }
-
- return (pvt->res);
-}
-
-static void
-nw_res_set(struct irs_nw *this, struct __res_state *res,
- void (*free_res)(void *)) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->res && pvt->free_res) {
- res_nclose(pvt->res);
- (*pvt->free_res)(pvt->res);
- }
-
- pvt->res = res;
- pvt->free_res = free_res;
-}
-
-/* Private. */
-
-static struct nwent *
-get1101byname(struct irs_nw *this, const char *name) {
- struct pvt *pvt = (struct pvt *)this->private;
- u_char *ansbuf;
- int anslen;
- struct nwent *result;
-
- ansbuf = memget(MAXPACKET);
- if (ansbuf == NULL) {
- errno = ENOMEM;
- RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
- return (NULL);
- }
- anslen = res_nsearch(pvt->res, name, C_IN, T_PTR, ansbuf, MAXPACKET);
- if (anslen < 0) {
- memput(ansbuf, MAXPACKET);
- return (NULL);
- }
- result = get1101mask(this, get1101answer(this, ansbuf, anslen, by_name,
- AF_INET, name, NULL, 0));
- memput(ansbuf, MAXPACKET);
- return (result);
-}
-
-static struct nwent *
-get1101byaddr(struct irs_nw *this, u_char *net, int len) {
- struct pvt *pvt = (struct pvt *)this->private;
- char qbuf[sizeof "255.255.255.255.in-addr.arpa"];
- struct nwent *result;
- u_char *ansbuf;
- int anslen;
-
- if (len < 1 || len > 32) {
- errno = EINVAL;
- RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
- return (NULL);
- }
- if (make1101inaddr(net, len, qbuf, sizeof qbuf) < 0)
- return (NULL);
- ansbuf = memget(MAXPACKET);
- if (ansbuf == NULL) {
- errno = ENOMEM;
- RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
- return (NULL);
- }
- anslen = res_nquery(pvt->res, qbuf, C_IN, T_PTR, ansbuf, MAXPACKET);
- if (anslen < 0) {
- memput(ansbuf, MAXPACKET);
- return (NULL);
- }
- result = get1101mask(this, get1101answer(this, ansbuf, anslen, by_addr,
- AF_INET, NULL, net, len));
- memput(ansbuf, MAXPACKET);
- return (result);
-}
-
-static struct nwent *
-get1101answer(struct irs_nw *this,
- u_char *ansbuf, int anslen, enum by_what by_what,
- int af, const char *name, const u_char *addr, int addrlen)
-{
- struct pvt *pvt = (struct pvt *)this->private;
- int type, class, ancount, qdcount, haveanswer;
- char *bp, *ep, **ap;
- u_char *cp, *eom;
- HEADER *hp;
-
- /* Initialize, and parse header. */
- eom = ansbuf + anslen;
- if (ansbuf + HFIXEDSZ > eom) {
- RES_SET_H_ERRNO(pvt->res, NO_RECOVERY);
- return (NULL);
- }
- hp = (HEADER *)ansbuf;
- cp = ansbuf + HFIXEDSZ;
- qdcount = ntohs(hp->qdcount);
- while (qdcount-- > 0) {
- int n = dn_skipname(cp, eom);
- cp += n + QFIXEDSZ;
- if (n < 0 || cp > eom) {
- RES_SET_H_ERRNO(pvt->res, NO_RECOVERY);
- return (NULL);
- }
- }
- ancount = ntohs(hp->ancount);
- if (!ancount) {
- if (hp->aa)
- RES_SET_H_ERRNO(pvt->res, HOST_NOT_FOUND);
- else
- RES_SET_H_ERRNO(pvt->res, TRY_AGAIN);
- return (NULL);
- }
-
- /* Prepare a return structure. */
- bp = pvt->buf;
- ep = pvt->buf + sizeof(pvt->buf);
- pvt->net.n_name = NULL;
- pvt->net.n_aliases = pvt->ali;
- pvt->net.n_addrtype = af;
- pvt->net.n_addr = NULL;
- pvt->net.n_length = addrlen;
-
- /* Save input key if given. */
- switch (by_what) {
- case by_name:
- if (name != NULL) {
- int n = strlen(name) + 1;
-
- if (n > (ep - bp)) {
- RES_SET_H_ERRNO(pvt->res, NO_RECOVERY);
- return (NULL);
- }
-#ifdef HAVE_STRLCPY
- strlcpy(bp, name, ep - bp);
- pvt->net.n_name = bp;
-#else
- pvt->net.n_name = strcpy(bp, name);
-#endif
- bp += n;
- }
- break;
- case by_addr:
- if (addr != NULL && addrlen != 0) {
- int n = addrlen / 8 + ((addrlen % 8) != 0);
-
- if (INADDRSZ > (ep - bp)) {
- RES_SET_H_ERRNO(pvt->res, NO_RECOVERY);
- return (NULL);
- }
- memset(bp, 0, INADDRSZ);
- memcpy(bp, addr, n);
- pvt->net.n_addr = bp;
- bp += INADDRSZ;
- }
- break;
- default:
- abort();
- }
-
- /* Parse the answer, collect aliases. */
- ap = pvt->ali;
- haveanswer = 0;
- while (--ancount >= 0 && cp < eom) {
- int n = dn_expand(ansbuf, eom, cp, bp, ep - bp);
-
- cp += n; /* Owner */
- if (n < 0 || !maybe_dnok(pvt->res, bp) ||
- cp + 3 * INT16SZ + INT32SZ > eom) {
- RES_SET_H_ERRNO(pvt->res, NO_RECOVERY);
- return (NULL);
- }
- GETSHORT(type, cp); /* Type */
- GETSHORT(class, cp); /* Class */
- cp += INT32SZ; /* TTL */
- GETSHORT(n, cp); /* RDLENGTH */
- if (class == C_IN && type == T_PTR) {
- int nn;
-
- nn = dn_expand(ansbuf, eom, cp, bp, ep - bp);
- if (nn < 0 || !maybe_hnok(pvt->res, bp) || nn != n) {
- RES_SET_H_ERRNO(pvt->res, NO_RECOVERY);
- return (NULL);
- }
- normalize_name(bp);
- switch (by_what) {
- case by_addr: {
- if (pvt->net.n_name == NULL)
- pvt->net.n_name = bp;
- else if (ns_samename(pvt->net.n_name, bp) == 1)
- break;
- else
- *ap++ = bp;
- nn = strlen(bp) + 1;
- bp += nn;
- haveanswer++;
- break;
- }
- case by_name: {
- u_int b1, b2, b3, b4;
-
- if (pvt->net.n_addr != NULL ||
- sscanf(bp, "%u.%u.%u.%u.in-addr.arpa",
- &b1, &b2, &b3, &b4) != 4)
- break;
- if ((ep - bp) < INADDRSZ) {
- RES_SET_H_ERRNO(pvt->res, NO_RECOVERY);
- return (NULL);
- }
- pvt->net.n_addr = bp;
- *bp++ = b4;
- *bp++ = b3;
- *bp++ = b2;
- *bp++ = b1;
- pvt->net.n_length = INADDRSZ * 8;
- haveanswer++;
- }
- }
- }
- cp += n; /* RDATA */
- }
- if (!haveanswer) {
- RES_SET_H_ERRNO(pvt->res, TRY_AGAIN);
- return (NULL);
- }
- *ap = NULL;
-
- return (&pvt->net);
-}
-
-static struct nwent *
-get1101mask(struct irs_nw *this, struct nwent *nwent) {
- struct pvt *pvt = (struct pvt *)this->private;
- char qbuf[sizeof "255.255.255.255.in-addr.arpa"], owner[MAXDNAME];
- int anslen, type, class, ancount, qdcount;
- u_char *ansbuf, *cp, *eom;
- HEADER *hp;
-
- if (!nwent)
- return (NULL);
- if (make1101inaddr(nwent->n_addr, nwent->n_length, qbuf, sizeof qbuf)
- < 0) {
- /* "First, do no harm." */
- return (nwent);
- }
-
- ansbuf = memget(MAXPACKET);
- if (ansbuf == NULL) {
- errno = ENOMEM;
- RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
- return (NULL);
- }
- /* Query for the A RR that would hold this network's mask. */
- anslen = res_nquery(pvt->res, qbuf, C_IN, T_A, ansbuf, MAXPACKET);
- if (anslen < HFIXEDSZ) {
- memput(ansbuf, MAXPACKET);
- return (nwent);
- }
-
- /* Initialize, and parse header. */
- hp = (HEADER *)ansbuf;
- cp = ansbuf + HFIXEDSZ;
- eom = ansbuf + anslen;
- qdcount = ntohs(hp->qdcount);
- while (qdcount-- > 0) {
- int n = dn_skipname(cp, eom);
- cp += n + QFIXEDSZ;
- if (n < 0 || cp > eom) {
- memput(ansbuf, MAXPACKET);
- return (nwent);
- }
- }
- ancount = ntohs(hp->ancount);
-
- /* Parse the answer, collect aliases. */
- while (--ancount >= 0 && cp < eom) {
- int n = dn_expand(ansbuf, eom, cp, owner, sizeof owner);
-
- if (n < 0 || !maybe_dnok(pvt->res, owner))
- break;
- cp += n; /* Owner */
- if (cp + 3 * INT16SZ + INT32SZ > eom)
- break;
- GETSHORT(type, cp); /* Type */
- GETSHORT(class, cp); /* Class */
- cp += INT32SZ; /* TTL */
- GETSHORT(n, cp); /* RDLENGTH */
- if (cp + n > eom)
- break;
- if (n == INADDRSZ && class == C_IN && type == T_A &&
- ns_samename(qbuf, owner) == 1) {
- /* This A RR indicates the actual netmask. */
- int nn, mm;
-
- nwent->n_length = 0;
- for (nn = 0; nn < INADDRSZ; nn++)
- for (mm = 7; mm >= 0; mm--)
- if (cp[nn] & (1 << mm))
- nwent->n_length++;
- else
- break;
- }
- cp += n; /* RDATA */
- }
- memput(ansbuf, MAXPACKET);
- return (nwent);
-}
-
-static int
-make1101inaddr(const u_char *net, int bits, char *name, int size) {
- int n, m;
- char *ep;
-
- ep = name + size;
-
- /* Zero fill any whole bytes left out of the prefix. */
- for (n = (32 - bits) / 8; n > 0; n--) {
- if (ep - name < (int)(sizeof "0."))
- goto emsgsize;
- m = SPRINTF((name, "0."));
- name += m;
- }
-
- /* Format the partial byte, if any, within the prefix. */
- if ((n = bits % 8) != 0) {
- if (ep - name < (int)(sizeof "255."))
- goto emsgsize;
- m = SPRINTF((name, "%u.",
- net[bits / 8] & ~((1 << (8 - n)) - 1)));
- name += m;
- }
-
- /* Format the whole bytes within the prefix. */
- for (n = bits / 8; n > 0; n--) {
- if (ep - name < (int)(sizeof "255."))
- goto emsgsize;
- m = SPRINTF((name, "%u.", net[n - 1]));
- name += m;
- }
-
- /* Add the static text. */
- if (ep - name < (int)(sizeof "in-addr.arpa"))
- goto emsgsize;
- (void) SPRINTF((name, "in-addr.arpa"));
- return (0);
-
- emsgsize:
- errno = EMSGSIZE;
- return (-1);
-}
-
-static void
-normalize_name(char *name) {
- char *t;
-
- /* Make lower case. */
- for (t = name; *t; t++)
- if (isascii((unsigned char)*t) && isupper((unsigned char)*t))
- *t = tolower(*t);
-
- /* Remove trailing dots. */
- while (t > name && t[-1] == '.')
- *--t = '\0';
-}
-
-static int
-init(struct irs_nw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (!pvt->res && !nw_res_get(this))
- return (-1);
- if (((pvt->res->options & RES_INIT) == 0) &&
- res_ninit(pvt->res) == -1)
- return (-1);
- return (0);
-}
diff --git a/contrib/bind/lib/irs/dns_p.h b/contrib/bind/lib/irs/dns_p.h
deleted file mode 100644
index 6b5fe11..0000000
--- a/contrib/bind/lib/irs/dns_p.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 1996-1999 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.
- */
-
-/*
- * $Id: dns_p.h,v 1.11 1999/06/03 20:50:36 vixie Exp $
- */
-
-#ifndef _DNS_P_H_INCLUDED
-#define _DNS_P_H_INCLUDED
-
-#define maybe_ok(res, nm, ok) (((res)->options & RES_NOCHECKNAME) != 0 || \
- (ok)(nm) != 0)
-#define maybe_hnok(res, hn) maybe_ok((res), (hn), res_hnok)
-#define maybe_dnok(res, dn) maybe_ok((res), (dn), res_dnok)
-
-/*
- * Object state.
- */
-struct dns_p {
- void *hes_ctx;
- struct __res_state *res;
- void (*free_res) __P((void *));
-};
-
-/*
- * Methods.
- */
-
-extern struct irs_gr * irs_dns_gr __P((struct irs_acc *));
-extern struct irs_pw * irs_dns_pw __P((struct irs_acc *));
-extern struct irs_sv * irs_dns_sv __P((struct irs_acc *));
-extern struct irs_pr * irs_dns_pr __P((struct irs_acc *));
-extern struct irs_ho * irs_dns_ho __P((struct irs_acc *));
-extern struct irs_nw * irs_dns_nw __P((struct irs_acc *));
-
-#endif /*_DNS_P_H_INCLUDED*/
diff --git a/contrib/bind/lib/irs/dns_pr.c b/contrib/bind/lib/irs/dns_pr.c
deleted file mode 100644
index 64de35a..0000000
--- a/contrib/bind/lib/irs/dns_pr.c
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: dns_pr.c,v 1.15 2001/05/29 05:48:31 marka Exp $";
-#endif
-
-/* Imports */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-
-#include <stdio.h>
-#include <string.h>
-#include <netdb.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <errno.h>
-
-#include <isc/memcluster.h>
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "hesiod.h"
-#include "dns_p.h"
-
-/* Types. */
-
-struct pvt {
- struct dns_p * dns;
- struct protoent proto;
- char * prbuf;
-};
-
-/* Forward. */
-
-static void pr_close(struct irs_pr *);
-static struct protoent * pr_byname(struct irs_pr *, const char *);
-static struct protoent * pr_bynumber(struct irs_pr *, int);
-static struct protoent * pr_next(struct irs_pr *);
-static void pr_rewind(struct irs_pr *);
-static void pr_minimize(struct irs_pr *);
-static struct __res_state * pr_res_get(struct irs_pr *);
-static void pr_res_set(struct irs_pr *,
- struct __res_state *,
- void (*)(void *));
-
-static struct protoent * parse_hes_list(struct irs_pr *, char **);
-
-/* Public. */
-
-struct irs_pr *
-irs_dns_pr(struct irs_acc *this) {
- struct dns_p *dns = (struct dns_p *)this->private;
- struct pvt *pvt;
- struct irs_pr *pr;
-
- if (!dns->hes_ctx) {
- errno = ENODEV;
- return (NULL);
- }
- if (!(pvt = memget(sizeof *pvt))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- if (!(pr = memget(sizeof *pr))) {
- memput(pvt, sizeof *pvt);
- errno = ENOMEM;
- return (NULL);
- }
- memset(pr, 0x5e, sizeof *pr);
- pvt->dns = dns;
- pr->private = pvt;
- pr->byname = pr_byname;
- pr->bynumber = pr_bynumber;
- pr->next = pr_next;
- pr->rewind = pr_rewind;
- pr->close = pr_close;
- pr->minimize = pr_minimize;
- pr->res_get = pr_res_get;
- pr->res_set = pr_res_set;
- return (pr);
-}
-
-/* Methods. */
-
-static void
-pr_close(struct irs_pr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->proto.p_aliases)
- free(pvt->proto.p_aliases);
- if (pvt->prbuf)
- free(pvt->prbuf);
-
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-static struct protoent *
-pr_byname(struct irs_pr *this, const char *name) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct dns_p *dns = pvt->dns;
- struct protoent *proto;
- char **hes_list;
-
- if (!(hes_list = hesiod_resolve(dns->hes_ctx, name, "protocol")))
- return (NULL);
-
- proto = parse_hes_list(this, hes_list);
- hesiod_free_list(dns->hes_ctx, hes_list);
- return (proto);
-}
-
-static struct protoent *
-pr_bynumber(struct irs_pr *this, int num) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct dns_p *dns = pvt->dns;
- struct protoent *proto;
- char numstr[16];
- char **hes_list;
-
- sprintf(numstr, "%d", num);
- if (!(hes_list = hesiod_resolve(dns->hes_ctx, numstr, "protonum")))
- return (NULL);
-
- proto = parse_hes_list(this, hes_list);
- hesiod_free_list(dns->hes_ctx, hes_list);
- return (proto);
-}
-
-static struct protoent *
-pr_next(struct irs_pr *this) {
- UNUSED(this);
- errno = ENODEV;
- return (NULL);
-}
-
-static void
-pr_rewind(struct irs_pr *this) {
- UNUSED(this);
- /* NOOP */
-}
-
-static void
-pr_minimize(struct irs_pr *this) {
- UNUSED(this);
- /* NOOP */
-}
-
-static struct __res_state *
-pr_res_get(struct irs_pr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct dns_p *dns = pvt->dns;
-
- return (__hesiod_res_get(dns->hes_ctx));
-}
-
-static void
-pr_res_set(struct irs_pr *this, struct __res_state * res,
- void (*free_res)(void *)) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct dns_p *dns = pvt->dns;
-
- __hesiod_res_set(dns->hes_ctx, res, free_res);
-}
-
-/* Private. */
-
-static struct protoent *
-parse_hes_list(struct irs_pr *this, char **hes_list) {
- struct pvt *pvt = (struct pvt *)this->private;
- char *p, *cp, **cpp, **new;
- int num = 0;
- int max = 0;
-
- for (cpp = hes_list; *cpp; cpp++) {
- cp = *cpp;
-
- /* Strip away comments, if any. */
- if ((p = strchr(cp, '#')))
- *p = 0;
-
- /* Skip blank lines. */
- p = cp;
- while (*p && !isspace((unsigned char)*p))
- p++;
- if (!*p)
- continue;
-
- /* OK, we've got a live one. Let's parse it for real. */
- if (pvt->prbuf)
- free(pvt->prbuf);
- pvt->prbuf = strdup(cp);
-
- p = pvt->prbuf;
- pvt->proto.p_name = p;
- while (*p && !isspace((unsigned char)*p))
- p++;
- if (!*p)
- continue;
- *p++ = '\0';
-
- pvt->proto.p_proto = atoi(p);
- while (*p && !isspace((unsigned char)*p))
- p++;
- if (*p)
- *p++ = '\0';
-
- while (*p) {
- if ((num + 1) >= max || !pvt->proto.p_aliases) {
- max += 10;
- new = realloc(pvt->proto.p_aliases,
- max * sizeof(char *));
- if (!new) {
- errno = ENOMEM;
- goto cleanup;
- }
- pvt->proto.p_aliases = new;
- }
- pvt->proto.p_aliases[num++] = p;
- while (*p && !isspace((unsigned char)*p))
- p++;
- if (*p)
- *p++ = '\0';
- }
- if (!pvt->proto.p_aliases)
- pvt->proto.p_aliases = malloc(sizeof(char *));
- if (!pvt->proto.p_aliases)
- goto cleanup;
- pvt->proto.p_aliases[num] = NULL;
- return (&pvt->proto);
- }
-
- cleanup:
- if (pvt->proto.p_aliases) {
- free(pvt->proto.p_aliases);
- pvt->proto.p_aliases = NULL;
- }
- if (pvt->prbuf) {
- free(pvt->prbuf);
- pvt->prbuf = NULL;
- }
- return (NULL);
-}
diff --git a/contrib/bind/lib/irs/dns_pw.c b/contrib/bind/lib/irs/dns_pw.c
deleted file mode 100644
index b3f7e05..0000000
--- a/contrib/bind/lib/irs/dns_pw.c
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: dns_pw.c,v 1.19 2001/05/29 05:48:32 marka Exp $";
-#endif
-
-#include "port_before.h"
-
-#ifndef WANT_IRS_PW
-static int __bind_irs_pw_unneeded;
-#else
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-
-#include <isc/memcluster.h>
-
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "hesiod.h"
-#include "dns_p.h"
-
-/* Types. */
-
-struct pvt {
- struct dns_p * dns;
- struct passwd passwd;
- char * pwbuf;
-};
-
-/* Forward. */
-
-static void pw_close(struct irs_pw *);
-static struct passwd * pw_byname(struct irs_pw *, const char *);
-static struct passwd * pw_byuid(struct irs_pw *, uid_t);
-static struct passwd * pw_next(struct irs_pw *);
-static void pw_rewind(struct irs_pw *);
-static void pw_minimize(struct irs_pw *);
-static struct __res_state * pw_res_get(struct irs_pw *);
-static void pw_res_set(struct irs_pw *,
- struct __res_state *,
- void (*)(void *));
-
-static struct passwd * getpwcommon(struct irs_pw *, const char *,
- const char *);
-
-/* Public. */
-
-struct irs_pw *
-irs_dns_pw(struct irs_acc *this) {
- struct dns_p *dns = (struct dns_p *)this->private;
- struct irs_pw *pw;
- struct pvt *pvt;
-
- if (!dns || !dns->hes_ctx) {
- errno = ENODEV;
- return (NULL);
- }
- if (!(pvt = memget(sizeof *pvt))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- pvt->dns = dns;
- if (!(pw = memget(sizeof *pw))) {
- memput(pvt, sizeof *pvt);
- errno = ENOMEM;
- return (NULL);
- }
- memset(pw, 0x5e, sizeof *pw);
- pw->private = pvt;
- pw->close = pw_close;
- pw->byname = pw_byname;
- pw->byuid = pw_byuid;
- pw->next = pw_next;
- pw->rewind = pw_rewind;
- pw->minimize = pw_minimize;
- pw->res_get = pw_res_get;
- pw->res_set = pw_res_set;
- return (pw);
-}
-
-/* Methods. */
-
-static void
-pw_close(struct irs_pw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->pwbuf)
- free(pvt->pwbuf);
-
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-static struct passwd *
-pw_byname(struct irs_pw *this, const char *nam) {
- return (getpwcommon(this, nam, "passwd"));
-}
-
-static struct passwd *
-pw_byuid(struct irs_pw *this, uid_t uid) {
- char uidstr[16];
-
- sprintf(uidstr, "%lu", (u_long)uid);
- return (getpwcommon(this, uidstr, "uid"));
-}
-
-static struct passwd *
-pw_next(struct irs_pw *this) {
- UNUSED(this);
- errno = ENODEV;
- return (NULL);
-}
-
-static void
-pw_rewind(struct irs_pw *this) {
- UNUSED(this);
- /* NOOP */
-}
-
-static void
-pw_minimize(struct irs_pw *this) {
- UNUSED(this);
- /* NOOP */
-}
-
-static struct __res_state *
-pw_res_get(struct irs_pw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct dns_p *dns = pvt->dns;
-
- return (__hesiod_res_get(dns->hes_ctx));
-}
-
-static void
-pw_res_set(struct irs_pw *this, struct __res_state * res,
- void (*free_res)(void *)) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct dns_p *dns = pvt->dns;
-
- __hesiod_res_set(dns->hes_ctx, res, free_res);
-}
-
-/* Private. */
-
-static struct passwd *
-getpwcommon(struct irs_pw *this, const char *arg, const char *type) {
- struct pvt *pvt = (struct pvt *)this->private;
- char **hes_list, *cp;
-
- if (!(hes_list = hesiod_resolve(pvt->dns->hes_ctx, arg, type)))
- return (NULL);
- if (!*hes_list) {
- hesiod_free_list(pvt->dns->hes_ctx, hes_list);
- errno = ENOENT;
- return (NULL);
- }
-
- memset(&pvt->passwd, 0, sizeof pvt->passwd);
- if (pvt->pwbuf)
- free(pvt->pwbuf);
- pvt->pwbuf = strdup(*hes_list);
- hesiod_free_list(pvt->dns->hes_ctx, hes_list);
-
- cp = pvt->pwbuf;
- pvt->passwd.pw_name = cp;
- if (!(cp = strchr(cp, ':')))
- goto cleanup;
- *cp++ = '\0';
-
- pvt->passwd.pw_passwd = cp;
- if (!(cp = strchr(cp, ':')))
- goto cleanup;
- *cp++ = '\0';
-
- pvt->passwd.pw_uid = atoi(cp);
- if (!(cp = strchr(cp, ':')))
- goto cleanup;
- *cp++ = '\0';
-
- pvt->passwd.pw_gid = atoi(cp);
- if (!(cp = strchr(cp, ':')))
- goto cleanup;
- *cp++ = '\0';
-
- pvt->passwd.pw_gecos = cp;
- if (!(cp = strchr(cp, ':')))
- goto cleanup;
- *cp++ = '\0';
-
- pvt->passwd.pw_dir = cp;
- if (!(cp = strchr(cp, ':')))
- goto cleanup;
- *cp++ = '\0';
-
- pvt->passwd.pw_shell = cp;
- return (&pvt->passwd);
-
- cleanup:
- free(pvt->pwbuf);
- pvt->pwbuf = NULL;
- return (NULL);
-}
-
-#endif /* WANT_IRS_PW */
diff --git a/contrib/bind/lib/irs/dns_sv.c b/contrib/bind/lib/irs/dns_sv.c
deleted file mode 100644
index b3244a7..0000000
--- a/contrib/bind/lib/irs/dns_sv.c
+++ /dev/null
@@ -1,298 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: dns_sv.c,v 1.20 2001/05/29 05:48:33 marka Exp $";
-#endif
-
-/* Imports */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <netinet/in.h>
-
-#include <stdio.h>
-#include <string.h>
-#include <netdb.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <errno.h>
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-
-#include <isc/memcluster.h>
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "hesiod.h"
-#include "dns_p.h"
-
-/* Definitions */
-
-struct pvt {
- struct dns_p * dns;
- struct servent serv;
- char * svbuf;
- struct __res_state * res;
- void (*free_res)(void *);
-};
-
-/* Forward. */
-
-static void sv_close(struct irs_sv *);
-static struct servent * sv_byname(struct irs_sv *,
- const char *, const char *);
-static struct servent * sv_byport(struct irs_sv *, int, const char *);
-static struct servent * sv_next(struct irs_sv *);
-static void sv_rewind(struct irs_sv *);
-static void sv_minimize(struct irs_sv *);
-#ifdef SV_RES_SETGET
-static struct __res_state * sv_res_get(struct irs_sv *);
-static void sv_res_set(struct irs_sv *,
- struct __res_state *,
- void (*)(void *));
-#endif
-
-static struct servent * parse_hes_list(struct irs_sv *,
- char **, const char *);
-
-/* Public */
-
-struct irs_sv *
-irs_dns_sv(struct irs_acc *this) {
- struct dns_p *dns = (struct dns_p *)this->private;
- struct irs_sv *sv;
- struct pvt *pvt;
-
- if (!dns || !dns->hes_ctx) {
- errno = ENODEV;
- return (NULL);
- }
- if (!(pvt = memget(sizeof *pvt))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- pvt->dns = dns;
- if (!(sv = memget(sizeof *sv))) {
- memput(pvt, sizeof *pvt);
- errno = ENOMEM;
- return (NULL);
- }
- memset(sv, 0x5e, sizeof *sv);
- sv->private = pvt;
- sv->byname = sv_byname;
- sv->byport = sv_byport;
- sv->next = sv_next;
- sv->rewind = sv_rewind;
- sv->close = sv_close;
- sv->minimize = sv_minimize;
-#ifdef SV_RES_SETGET
- sv->res_get = sv_res_get;
- sv->res_set = sv_res_set;
-#else
- sv->res_get = NULL; /* sv_res_get; */
- sv->res_set = NULL; /* sv_res_set; */
-#endif
- return (sv);
-}
-
-/* Methods */
-
-static void
-sv_close(struct irs_sv *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->serv.s_aliases)
- free(pvt->serv.s_aliases);
- if (pvt->svbuf)
- free(pvt->svbuf);
-
- if (pvt->res && pvt->free_res)
- (*pvt->free_res)(pvt->res);
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-static struct servent *
-sv_byname(struct irs_sv *this, const char *name, const char *proto) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct dns_p *dns = pvt->dns;
- struct servent *s;
- char **hes_list;
-
- if (!(hes_list = hesiod_resolve(dns->hes_ctx, name, "service")))
- return (NULL);
-
- s = parse_hes_list(this, hes_list, proto);
- hesiod_free_list(dns->hes_ctx, hes_list);
- return (s);
-}
-
-static struct servent *
-sv_byport(struct irs_sv *this, int port, const char *proto) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct dns_p *dns = pvt->dns;
- struct servent *s;
- char portstr[16];
- char **hes_list;
-
- sprintf(portstr, "%d", ntohs(port));
- if (!(hes_list = hesiod_resolve(dns->hes_ctx, portstr, "port")))
- return (NULL);
-
- s = parse_hes_list(this, hes_list, proto);
- hesiod_free_list(dns->hes_ctx, hes_list);
- return (s);
-}
-
-static struct servent *
-sv_next(struct irs_sv *this) {
- UNUSED(this);
- errno = ENODEV;
- return (NULL);
-}
-
-static void
-sv_rewind(struct irs_sv *this) {
- UNUSED(this);
- /* NOOP */
-}
-
-/* Private */
-
-static struct servent *
-parse_hes_list(struct irs_sv *this, char **hes_list, const char *proto) {
- struct pvt *pvt = (struct pvt *)this->private;
- char *p, *cp, **cpp, **new;
- int proto_len;
- int num = 0;
- int max = 0;
-
- for (cpp = hes_list; *cpp; cpp++) {
- cp = *cpp;
-
- /* Strip away comments, if any. */
- if ((p = strchr(cp, '#')))
- *p = 0;
-
- /* Check to make sure the protocol matches. */
- p = cp;
- while (*p && !isspace((unsigned char)*p))
- p++;
- if (!*p)
- continue;
- if (proto) {
- proto_len = strlen(proto);
- if (strncasecmp(++p, proto, proto_len) != 0)
- continue;
- if (p[proto_len] && !isspace(p[proto_len]&0xff))
- continue;
- }
- /* OK, we've got a live one. Let's parse it for real. */
- if (pvt->svbuf)
- free(pvt->svbuf);
- pvt->svbuf = strdup(cp);
-
- p = pvt->svbuf;
- pvt->serv.s_name = p;
- while (*p && !isspace(*p&0xff))
- p++;
- if (!*p)
- continue;
- *p++ = '\0';
-
- pvt->serv.s_proto = p;
- while (*p && !isspace(*p&0xff))
- p++;
- if (!*p)
- continue;
- *p++ = '\0';
-
- pvt->serv.s_port = htons((u_short) atoi(p));
- while (*p && !isspace(*p&0xff))
- p++;
- if (*p)
- *p++ = '\0';
-
- while (*p) {
- if ((num + 1) >= max || !pvt->serv.s_aliases) {
- max += 10;
- new = realloc(pvt->serv.s_aliases,
- max * sizeof(char *));
- if (!new) {
- errno = ENOMEM;
- goto cleanup;
- }
- pvt->serv.s_aliases = new;
- }
- pvt->serv.s_aliases[num++] = p;
- while (*p && !isspace(*p&0xff))
- p++;
- if (*p)
- *p++ = '\0';
- }
- if (!pvt->serv.s_aliases)
- pvt->serv.s_aliases = malloc(sizeof(char *));
- if (!pvt->serv.s_aliases)
- goto cleanup;
- pvt->serv.s_aliases[num] = NULL;
- return (&pvt->serv);
- }
-
- cleanup:
- if (pvt->serv.s_aliases) {
- free(pvt->serv.s_aliases);
- pvt->serv.s_aliases = NULL;
- }
- if (pvt->svbuf) {
- free(pvt->svbuf);
- pvt->svbuf = NULL;
- }
- return (NULL);
-}
-
-static void
-sv_minimize(struct irs_sv *this) {
- UNUSED(this);
- /* NOOP */
-}
-
-#ifdef SV_RES_SETGET
-static struct __res_state *
-sv_res_get(struct irs_sv *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct dns_p *dns = pvt->dns;
-
- return (__hesiod_res_get(dns->hes_ctx));
-}
-
-static void
-sv_res_set(struct irs_sv *this, struct __res_state * res,
- void (*free_res)(void *)) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct dns_p *dns = pvt->dns;
-
- __hesiod_res_set(dns->hes_ctx, res, free_res);
-}
-#endif
diff --git a/contrib/bind/lib/irs/gai_strerror.c b/contrib/bind/lib/irs/gai_strerror.c
deleted file mode 100644
index c487e68..0000000
--- a/contrib/bind/lib/irs/gai_strerror.c
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright (c) 2001 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.
- */
-
-#include <port_before.h>
-#include <netdb.h>
-#include <port_after.h>
-
-#ifdef DO_PTHREADS
-#include <pthread.h>
-#include <stdlib.h>
-#endif
-
-static const char *gai_errlist[] = {
- "no error",
- "address family not supported for name",/* EAI_ADDRFAMILY */
- "temporary failure", /* EAI_AGAIN */
- "invalid flags", /* EAI_BADFLAGS */
- "permanent failure", /* EAI_FAIL */
- "address family not supported", /* EAI_FAMILY */
- "memory failure", /* EAI_MEMORY */
- "no address", /* EAI_NODATA */
- "unknown name or service", /* EAI_NONAME */
- "service not supported for socktype", /* EAI_SERVICE */
- "socktype not supported", /* EAI_SOCKTYPE */
- "system failure", /* EAI_SYSTEM */
- "bad hints", /* EAI_BADHINTS */
- "bad protocol", /* EAI_PROTOCOL */
-
- "unknown error" /* Must be last. */
-};
-
-static const int gai_nerr = (sizeof(gai_errlist)/sizeof(*gai_errlist));
-
-#define EAI_BUFSIZE 128
-
-const char *
-gai_strerror(int ecode) {
-#ifndef DO_PTHREADS
- static char buf[EAI_BUFSIZE];
-#else /* DO_PTHREADS */
- static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
- static pthread_key_t key;
- static int once = 0;
- char *buf;
-#endif
-
- if (ecode >= 0 && ecode < (gai_nerr - 1))
- return (gai_errlist[ecode]);
-
-#ifdef DO_PTHREADS
- if (!once) {
- pthread_mutex_lock(&lock);
- if (!once++)
- pthread_key_create(&key, free);
- pthread_mutex_unlock(&lock);
- }
-
- buf = pthread_getspecific(key);
- if (buf == NULL) {
- buf = malloc(EAI_BUFSIZE);
- if (buf == NULL)
- return ("unknown error");
- pthread_setspecific(key, buf);
- }
-#endif
- /*
- * XXX This really should be snprintf(buf, EAI_BUFSIZE, ...).
- * It is safe until message catalogs are used.
- */
- sprintf(buf, "%s: %d", gai_errlist[gai_nerr - 1], ecode);
- return (buf);
-}
diff --git a/contrib/bind/lib/irs/gen.c b/contrib/bind/lib/irs/gen.c
deleted file mode 100644
index 5ba7d52..0000000
--- a/contrib/bind/lib/irs/gen.c
+++ /dev/null
@@ -1,430 +0,0 @@
-/*
- * Copyright (c) 1996-1999 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.
- */
-
-#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: gen.c,v 1.26 2001/05/29 05:48:35 marka Exp $";
-#endif
-
-/*
- * this is the top level dispatcher
- *
- * The dispatcher is implemented as an accessor class; it is an
- * accessor class that calls other accessor classes, as controlled by a
- * configuration file.
- *
- * A big difference between this accessor class and others is that the
- * map class initializers are NULL, and the map classes are already
- * filled in with method functions that will do the right thing.
- */
-
-/* Imports */
-
-#include "port_before.h"
-
-#include <isc/assertions.h>
-#include <ctype.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-
-#include <isc/memcluster.h>
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "gen_p.h"
-
-/* Definitions */
-
-struct nameval {
- const char * name;
- int val;
-};
-
-static const struct nameval acc_names[irs_nacc+1] = {
- { "local", irs_lcl },
- { "dns", irs_dns },
- { "nis", irs_nis },
- { "irp", irs_irp },
- { NULL, irs_nacc }
-};
-
-typedef struct irs_acc *(*accinit) __P((const char *options));
-
-static const accinit accs[irs_nacc+1] = {
- irs_lcl_acc,
- irs_dns_acc,
-#ifdef WANT_IRS_NIS
- irs_nis_acc,
-#else
- NULL,
-#endif
- irs_irp_acc,
- NULL
-};
-
-static const struct nameval map_names[irs_nmap+1] = {
- { "group", irs_gr },
- { "passwd", irs_pw },
- { "services", irs_sv },
- { "protocols", irs_pr },
- { "hosts", irs_ho },
- { "networks", irs_nw },
- { "netgroup", irs_ng },
- { NULL, irs_nmap }
-};
-
-static const struct nameval option_names[] = {
- { "merge", IRS_MERGE },
- { "continue", IRS_CONTINUE },
- { NULL, 0 }
-};
-
-/* Forward */
-
-static void gen_close(struct irs_acc *);
-static struct __res_state * gen_res_get(struct irs_acc *);
-static void gen_res_set(struct irs_acc *, struct __res_state *,
- void (*)(void *));
-static int find_name(const char *, const struct nameval nv[]);
-static void init_map_rules(struct gen_p *, const char *conf_file);
-static struct irs_rule *release_rule(struct irs_rule *);
-static int add_rule(struct gen_p *,
- enum irs_map_id, enum irs_acc_id,
- const char *);
-
-/* Public */
-
-struct irs_acc *
-irs_gen_acc(const char *options, const char *conf_file) {
- struct irs_acc *acc;
- struct gen_p *irs;
-
- if (!(acc = memget(sizeof *acc))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(acc, 0x5e, sizeof *acc);
- if (!(irs = memget(sizeof *irs))) {
- errno = ENOMEM;
- memput(acc, sizeof *acc);
- return (NULL);
- }
- memset(irs, 0x5e, sizeof *irs);
- irs->options = strdup(options);
- irs->res = NULL;
- irs->free_res = NULL;
- memset(irs->accessors, 0, sizeof irs->accessors);
- memset(irs->map_rules, 0, sizeof irs->map_rules);
- init_map_rules(irs, conf_file);
- acc->private = irs;
-#ifdef WANT_IRS_GR
- acc->gr_map = irs_gen_gr;
-#else
- acc->gr_map = NULL;
-#endif
-#ifdef WANT_IRS_PW
- acc->pw_map = irs_gen_pw;
-#else
- acc->pw_map = NULL;
-#endif
- acc->sv_map = irs_gen_sv;
- acc->pr_map = irs_gen_pr;
- acc->ho_map = irs_gen_ho;
- acc->nw_map = irs_gen_nw;
- acc->ng_map = irs_gen_ng;
- acc->res_get = gen_res_get;
- acc->res_set = gen_res_set;
- acc->close = gen_close;
- return (acc);
-}
-
-/* Methods */
-
-static struct __res_state *
-gen_res_get(struct irs_acc *this) {
- struct gen_p *irs = (struct gen_p *)this->private;
-
- if (irs->res == NULL) {
- struct __res_state *res;
- res = (struct __res_state *)malloc(sizeof *res);
- if (res == NULL)
- return (NULL);
- memset(res, 0, sizeof *res);
- gen_res_set(this, res, free);
- }
-
- if (((irs->res->options & RES_INIT) == 0) && res_ninit(irs->res) < 0)
- return (NULL);
-
- return (irs->res);
-}
-
-static void
-gen_res_set(struct irs_acc *this, struct __res_state *res,
- void (*free_res)(void *)) {
- struct gen_p *irs = (struct gen_p *)this->private;
-#if 0
- struct irs_rule *rule;
- struct irs_ho *ho;
- struct irs_nw *nw;
-#endif
-
- if (irs->res && irs->free_res) {
- res_nclose(irs->res);
- (*irs->free_res)(irs->res);
- }
-
- irs->res = res;
- irs->free_res = free_res;
-
-#if 0
- for (rule = irs->map_rules[irs_ho]; rule; rule = rule->next) {
- ho = rule->inst->ho;
-
- (*ho->res_set)(ho, res, NULL);
- }
- for (rule = irs->map_rules[irs_nw]; rule; rule = rule->next) {
- nw = rule->inst->nw;
-
- (*nw->res_set)(nw, res, NULL);
- }
-#endif
-}
-
-static void
-gen_close(struct irs_acc *this) {
- struct gen_p *irs = (struct gen_p *)this->private;
- int n;
-
- /* Search rules. */
- for (n = 0; n < irs_nmap; n++)
- while (irs->map_rules[n] != NULL)
- irs->map_rules[n] = release_rule(irs->map_rules[n]);
-
- /* Access methods. */
- for (n = 0; n < irs_nacc; n++) {
- /* Map objects. */
- if (irs->accessors[n].gr != NULL)
- (*irs->accessors[n].gr->close)(irs->accessors[n].gr);
- if (irs->accessors[n].pw != NULL)
- (*irs->accessors[n].pw->close)(irs->accessors[n].pw);
- if (irs->accessors[n].sv != NULL)
- (*irs->accessors[n].sv->close)(irs->accessors[n].sv);
- if (irs->accessors[n].pr != NULL)
- (*irs->accessors[n].pr->close)(irs->accessors[n].pr);
- if (irs->accessors[n].ho != NULL)
- (*irs->accessors[n].ho->close)(irs->accessors[n].ho);
- if (irs->accessors[n].nw != NULL)
- (*irs->accessors[n].nw->close)(irs->accessors[n].nw);
- if (irs->accessors[n].ng != NULL)
- (*irs->accessors[n].ng->close)(irs->accessors[n].ng);
- /* Enclosing accessor. */
- if (irs->accessors[n].acc != NULL)
- (*irs->accessors[n].acc->close)(irs->accessors[n].acc);
- }
-
- /* The options string was strdup'd. */
- free((void*)irs->options);
-
- if (irs->res && irs->free_res)
- (*irs->free_res)(irs->res);
-
- /* The private data container. */
- memput(irs, sizeof *irs);
-
- /* The object. */
- memput(this, sizeof *this);
-}
-
-/* Private */
-
-static int
-find_name(const char *name, const struct nameval names[]) {
- int n;
-
- for (n = 0; names[n].name != NULL; n++)
- if (strcmp(name, names[n].name) == 0)
- return (names[n].val);
- return (-1);
-}
-
-static struct irs_rule *
-release_rule(struct irs_rule *rule) {
- struct irs_rule *next = rule->next;
-
- memput(rule, sizeof *rule);
- return (next);
-}
-
-static int
-add_rule(struct gen_p *irs,
- enum irs_map_id map, enum irs_acc_id acc,
- const char *options)
-{
- struct irs_rule **rules, *last, *tmp, *new;
- struct irs_inst *inst;
- const char *cp;
- int n;
-
-#ifndef WANT_IRS_GR
- if (map == irs_gr)
- return (-1);
-#endif
-#ifndef WANT_IRS_PW
- if (map == irs_pw)
- return (-1);
-#endif
-#ifndef WANT_IRS_NIS
- if (acc == irs_nis)
- return (-1);
-#endif
- new = memget(sizeof *new);
- if (new == NULL)
- return (-1);
- memset(new, 0x5e, sizeof *new);
- new->next = NULL;
-
- new->inst = &irs->accessors[acc];
-
- new->flags = 0;
- cp = options;
- while (cp && *cp) {
- char option[50], *next;
-
- next = strchr(cp, ',');
- if (next)
- n = next++ - cp;
- else
- n = strlen(cp);
- if ((size_t)n > sizeof option - 1)
- n = sizeof option - 1;
- strncpy(option, cp, n);
- option[n] = '\0';
-
- n = find_name(option, option_names);
- if (n >= 0)
- new->flags |= n;
-
- cp = next;
- }
-
- rules = &irs->map_rules[map];
- for (last = NULL, tmp = *rules;
- tmp != NULL;
- last = tmp, tmp = tmp->next)
- (void)NULL;
- if (last == NULL)
- *rules = new;
- else
- last->next = new;
-
- /* Try to instantiate map accessors for this if necessary & approp. */
- inst = &irs->accessors[acc];
- if (inst->acc == NULL && accs[acc] != NULL)
- inst->acc = (*accs[acc])(irs->options);
- if (inst->acc != NULL) {
- if (inst->gr == NULL && inst->acc->gr_map != NULL)
- inst->gr = (*inst->acc->gr_map)(inst->acc);
- if (inst->pw == NULL && inst->acc->pw_map != NULL)
- inst->pw = (*inst->acc->pw_map)(inst->acc);
- if (inst->sv == NULL && inst->acc->sv_map != NULL)
- inst->sv = (*inst->acc->sv_map)(inst->acc);
- if (inst->pr == NULL && inst->acc->pr_map != NULL)
- inst->pr = (*inst->acc->pr_map)(inst->acc);
- if (inst->ho == NULL && inst->acc->ho_map != NULL)
- inst->ho = (*inst->acc->ho_map)(inst->acc);
- if (inst->nw == NULL && inst->acc->nw_map != NULL)
- inst->nw = (*inst->acc->nw_map)(inst->acc);
- if (inst->ng == NULL && inst->acc->ng_map != NULL)
- inst->ng = (*inst->acc->ng_map)(inst->acc);
- }
-
- return (0);
-}
-
-static void
-default_map_rules(struct gen_p *irs) {
- /* Install time honoured and proved BSD style rules as default. */
- add_rule(irs, irs_gr, irs_lcl, "");
- add_rule(irs, irs_pw, irs_lcl, "");
- add_rule(irs, irs_sv, irs_lcl, "");
- add_rule(irs, irs_pr, irs_lcl, "");
- add_rule(irs, irs_ho, irs_dns, "continue");
- add_rule(irs, irs_ho, irs_lcl, "");
- add_rule(irs, irs_nw, irs_dns, "continue");
- add_rule(irs, irs_nw, irs_lcl, "");
- add_rule(irs, irs_ng, irs_lcl, "");
-}
-
-static void
-init_map_rules(struct gen_p *irs, const char *conf_file) {
- char line[1024], pattern[40], mapname[20], accname[20], options[100];
- FILE *conf;
-
- if (conf_file == NULL)
- conf_file = _PATH_IRS_CONF ;
-
- /* A conf file of "" means compiled in defaults. Irpd wants this */
- if (conf_file[0] == '\0' || (conf = fopen(conf_file, "r")) == NULL) {
- default_map_rules(irs);
- return;
- }
- (void) sprintf(pattern, "%%%ds %%%ds %%%ds\n",
- sizeof mapname, sizeof accname, sizeof options);
- while (fgets(line, sizeof line, conf)) {
- enum irs_map_id map;
- enum irs_acc_id acc;
- char *tmp;
- int n;
-
- for (tmp = line;
- isascii((unsigned char)*tmp) &&
- isspace((unsigned char)*tmp);
- tmp++)
- (void)NULL;
- if (*tmp == '#' || *tmp == '\n' || *tmp == '\0')
- continue;
- n = sscanf(tmp, pattern, mapname, accname, options);
- if (n < 2)
- continue;
- if (n < 3)
- options[0] = '\0';
-
- n = find_name(mapname, map_names);
- INSIST(n < irs_nmap);
- if (n < 0)
- continue;
- map = (enum irs_map_id) n;
-
- n = find_name(accname, acc_names);
- INSIST(n < irs_nacc);
- if (n < 0)
- continue;
- acc = (enum irs_acc_id) n;
-
- add_rule(irs, map, acc, options);
- }
- fclose(conf);
-}
diff --git a/contrib/bind/lib/irs/gen_gr.c b/contrib/bind/lib/irs/gen_gr.c
deleted file mode 100644
index 9a7af3d..0000000
--- a/contrib/bind/lib/irs/gen_gr.c
+++ /dev/null
@@ -1,482 +0,0 @@
-/*
- * Copyright (c) 1996-1999 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.
- */
-
-#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: gen_gr.c,v 1.26 2002/07/18 02:07:44 marka Exp $";
-#endif
-
-/* Imports */
-
-#include "port_before.h"
-
-#ifndef WANT_IRS_GR
-static int __bind_irs_gr_unneeded;
-#else
-
-#include <sys/types.h>
-
-#include <isc/assertions.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-
-#include <isc/memcluster.h>
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "gen_p.h"
-
-/* Definitions */
-
-struct pvt {
- struct irs_rule * rules;
- struct irs_rule * rule;
- struct irs_gr * gr;
- /*
- * Need space to store the entries read from the group file.
- * The members list also needs space per member, and the
- * strings making up the user names must be allocated
- * somewhere. Rather than doing lots of small allocations,
- * we keep one buffer and resize it as needed.
- */
- struct group group;
- size_t nmemb; /* Malloc'd max index of gr_mem[]. */
- char * membuf;
- size_t membufsize;
- struct __res_state * res;
- void (*free_res)(void *);
-};
-
-/* Forward */
-
-static void gr_close(struct irs_gr *);
-static struct group * gr_next(struct irs_gr *);
-static struct group * gr_byname(struct irs_gr *, const char *);
-static struct group * gr_bygid(struct irs_gr *, gid_t);
-static void gr_rewind(struct irs_gr *);
-static int gr_list(struct irs_gr *, const char *,
- gid_t, gid_t *, int *);
-static void gr_minimize(struct irs_gr *);
-static struct __res_state * gr_res_get(struct irs_gr *);
-static void gr_res_set(struct irs_gr *,
- struct __res_state *,
- void (*)(void *));
-
-static void grmerge(struct irs_gr *gr, const struct group *src,
- int preserve);
-
-static int countvec(char **vec);
-static int isnew(char **old, char *new);
-static int countnew(char **old, char **new);
-static size_t sizenew(char **old, char **new);
-static int newgid(int, gid_t *, gid_t);
-
-/* Public */
-
-struct irs_gr *
-irs_gen_gr(struct irs_acc *this) {
- struct gen_p *accpvt = (struct gen_p *)this->private;
- struct irs_gr *gr;
- struct pvt *pvt;
-
- if (!(gr = memget(sizeof *gr))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(gr, 0x5e, sizeof *gr);
- if (!(pvt = memget(sizeof *pvt))) {
- memput(gr, sizeof *gr);
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- pvt->rules = accpvt->map_rules[irs_gr];
- pvt->rule = pvt->rules;
- gr->private = pvt;
- gr->close = gr_close;
- gr->next = gr_next;
- gr->byname = gr_byname;
- gr->bygid = gr_bygid;
- gr->rewind = gr_rewind;
- gr->list = gr_list;
- gr->minimize = gr_minimize;
- gr->res_get = gr_res_get;
- gr->res_set = gr_res_set;
- return (gr);
-}
-
-/* Methods. */
-
-static void
-gr_close(struct irs_gr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-static struct group *
-gr_next(struct irs_gr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct group *rval;
- struct irs_gr *gr;
-
- while (pvt->rule) {
- gr = pvt->rule->inst->gr;
- rval = (*gr->next)(gr);
- if (rval)
- return (rval);
- if (!(pvt->rule->flags & IRS_CONTINUE))
- break;
- pvt->rule = pvt->rule->next;
- if (pvt->rule) {
- gr = pvt->rule->inst->gr;
- (*gr->rewind)(gr);
- }
- }
- return (NULL);
-}
-
-static struct group *
-gr_byname(struct irs_gr *this, const char *name) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_rule *rule;
- struct group *tval;
- struct irs_gr *gr;
- int dirty;
-
- dirty = 0;
- for (rule = pvt->rules; rule; rule = rule->next) {
- gr = rule->inst->gr;
- tval = (*gr->byname)(gr, name);
- if (tval) {
- grmerge(this, tval, dirty++);
- if (!(rule->flags & IRS_MERGE))
- break;
- } else {
- if (!(rule->flags & IRS_CONTINUE))
- break;
- }
- }
- if (dirty)
- return (&pvt->group);
- return (NULL);
-}
-
-static struct group *
-gr_bygid(struct irs_gr *this, gid_t gid) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_rule *rule;
- struct group *tval;
- struct irs_gr *gr;
- int dirty;
-
- dirty = 0;
- for (rule = pvt->rules; rule; rule = rule->next) {
- gr = rule->inst->gr;
- tval = (*gr->bygid)(gr, gid);
- if (tval) {
- grmerge(this, tval, dirty++);
- if (!(rule->flags & IRS_MERGE))
- break;
- } else {
- if (!(rule->flags & IRS_CONTINUE))
- break;
- }
- }
- if (dirty)
- return (&pvt->group);
- return (NULL);
-}
-
-static void
-gr_rewind(struct irs_gr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_gr *gr;
-
- pvt->rule = pvt->rules;
- if (pvt->rule) {
- gr = pvt->rule->inst->gr;
- (*gr->rewind)(gr);
- }
-}
-
-static int
-gr_list(struct irs_gr *this, const char *name,
- gid_t basegid, gid_t *groups, int *ngroups)
-{
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_rule *rule;
- struct irs_gr *gr;
- int t_ngroups, maxgroups;
- gid_t *t_groups;
- int n, t, rval = 0;
-
- maxgroups = *ngroups;
- *ngroups = 0;
- t_groups = (gid_t *)malloc(maxgroups * sizeof(gid_t));
- if (!t_groups) {
- errno = ENOMEM;
- return (-1);
- }
-
- for (rule = pvt->rules; rule; rule = rule->next) {
- t_ngroups = maxgroups;
- gr = rule->inst->gr;
- t = (*gr->list)(gr, name, basegid, t_groups, &t_ngroups);
- for (n = 0; n < t_ngroups; n++) {
- if (newgid(*ngroups, groups, t_groups[n])) {
- if (*ngroups == maxgroups) {
- rval = -1;
- goto done;
- }
- groups[(*ngroups)++] = t_groups[n];
- }
- }
- if (t == 0) {
- if (!(rule->flags & IRS_MERGE))
- break;
- } else {
- if (!(rule->flags & IRS_CONTINUE))
- break;
- }
- }
- done:
- free(t_groups);
- return (rval);
-}
-
-static void
-gr_minimize(struct irs_gr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_rule *rule;
-
- for (rule = pvt->rules; rule != NULL; rule = rule->next) {
- struct irs_gr *gr = rule->inst->gr;
-
- (*gr->minimize)(gr);
- }
-}
-
-static struct __res_state *
-gr_res_get(struct irs_gr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (!pvt->res) {
- struct __res_state *res;
- res = (struct __res_state *)malloc(sizeof *res);
- if (!res) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(res, 0, sizeof *res);
- gr_res_set(this, res, free);
- }
-
- return (pvt->res);
-}
-
-static void
-gr_res_set(struct irs_gr *this, struct __res_state *res,
- void (*free_res)(void *)) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_rule *rule;
-
- if (pvt->res && pvt->free_res) {
- res_nclose(pvt->res);
- (*pvt->free_res)(pvt->res);
- }
-
- pvt->res = res;
- pvt->free_res = free_res;
-
- for (rule = pvt->rules; rule != NULL; rule = rule->next) {
- struct irs_gr *gr = rule->inst->gr;
-
- if (gr->res_set)
- (*gr->res_set)(gr, pvt->res, NULL);
- }
-}
-
-/* Private. */
-
-static void
-grmerge(struct irs_gr *this, const struct group *src, int preserve) {
- struct pvt *pvt = (struct pvt *)this->private;
- char *cp, **m, **p, *oldmembuf, *ep;
- int n, ndst, nnew;
- size_t used;
-
- if (!preserve) {
- pvt->group.gr_gid = src->gr_gid;
- if (pvt->nmemb < 1) {
- m = malloc(sizeof *m);
- if (!m) {
- /* No harm done, no work done. */
- return;
- }
- pvt->group.gr_mem = m;
- pvt->nmemb = 1;
- }
- pvt->group.gr_mem[0] = NULL;
- }
- ndst = countvec(pvt->group.gr_mem);
- nnew = countnew(pvt->group.gr_mem, src->gr_mem);
-
- /*
- * Make sure destination member array is large enough.
- * p points to new portion.
- */
- n = ndst + nnew + 1;
- if ((size_t)n > pvt->nmemb) {
- m = realloc(pvt->group.gr_mem, n * sizeof *m);
- if (!m) {
- /* No harm done, no work done. */
- return;
- }
- pvt->group.gr_mem = m;
- pvt->nmemb = n;
- }
- p = pvt->group.gr_mem + ndst;
-
- /*
- * Enlarge destination membuf; cp points at new portion.
- */
- n = sizenew(pvt->group.gr_mem, src->gr_mem);
- INSIST((nnew == 0) == (n == 0));
- if (!preserve) {
- n += strlen(src->gr_name) + 1;
- n += strlen(src->gr_passwd) + 1;
- }
- if (n == 0) {
- /* No work to do. */
- return;
- }
- used = preserve ? pvt->membufsize : 0;
- cp = malloc(used + n);
- if (!cp) {
- /* No harm done, no work done. */
- return;
- }
- ep = cp + used + n;
- if (used != 0)
- memcpy(cp, pvt->membuf, used);
- oldmembuf = pvt->membuf;
- pvt->membuf = cp;
- pvt->membufsize = used + n;
- cp += used;
-
- /*
- * Adjust group.gr_mem.
- */
- if (pvt->membuf != oldmembuf)
- for (m = pvt->group.gr_mem; *m; m++)
- *m = pvt->membuf + (*m - oldmembuf);
-
- /*
- * Add new elements.
- */
- for (m = src->gr_mem; *m; m++)
- if (isnew(pvt->group.gr_mem, *m)) {
- *p++ = cp;
- *p = NULL;
-#ifdef HAVE_STRLCPY
- strlcpy(cp, *m, ep - cp);
-#else
- strcpy(cp, *m);
-#endif
- cp += strlen(cp) + 1;
- }
- if (preserve) {
- pvt->group.gr_name = pvt->membuf +
- (pvt->group.gr_name - oldmembuf);
- pvt->group.gr_passwd = pvt->membuf +
- (pvt->group.gr_passwd - oldmembuf);
- } else {
- pvt->group.gr_name = cp;
-#ifdef HAVE_STRLCPY
- strlcpy(cp, src->gr_name, ep - cp);
-#else
- strcpy(cp, src->gr_name);
-#endif
- cp += strlen(src->gr_name) + 1;
- pvt->group.gr_passwd = cp;
-#ifdef HAVE_STRLCPY
- strlcpy(cp, src->gr_passwd, ep - cp);
-#else
- strcpy(cp, src->gr_passwd);
-#endif
- cp += strlen(src->gr_passwd) + 1;
- }
- if (oldmembuf != NULL)
- free(oldmembuf);
- INSIST(cp >= pvt->membuf && cp <= &pvt->membuf[pvt->membufsize]);
-}
-
-static int
-countvec(char **vec) {
- int n = 0;
-
- while (*vec++)
- n++;
- return (n);
-}
-
-static int
-isnew(char **old, char *new) {
- for (; *old; old++)
- if (strcmp(*old, new) == 0)
- return (0);
- return (1);
-}
-
-static int
-countnew(char **old, char **new) {
- int n = 0;
-
- for (; *new; new++)
- n += isnew(old, *new);
- return (n);
-}
-
-static size_t
-sizenew(char **old, char **new) {
- size_t n = 0;
-
- for (; *new; new++)
- if (isnew(old, *new))
- n += strlen(*new) + 1;
- return (n);
-}
-
-static int
-newgid(int ngroups, gid_t *groups, gid_t group) {
- ngroups--, groups++;
- for (; ngroups-- > 0; groups++)
- if (*groups == group)
- return (0);
- return (1);
-}
-
-#endif /* WANT_IRS_GR */
diff --git a/contrib/bind/lib/irs/gen_ho.c b/contrib/bind/lib/irs/gen_ho.c
deleted file mode 100644
index 12ed7cd..0000000
--- a/contrib/bind/lib/irs/gen_ho.c
+++ /dev/null
@@ -1,391 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: gen_ho.c,v 1.16 2001/05/29 05:48:36 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-/* Imports */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-
-#include <errno.h>
-#include <stdlib.h>
-#include <netdb.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <isc/memcluster.h>
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "gen_p.h"
-
-/* Definitions */
-
-struct pvt {
- struct irs_rule * rules;
- struct irs_rule * rule;
- struct irs_ho * ho;
- struct __res_state * res;
- void (*free_res)(void *);
-};
-
-/* Forwards */
-
-static void ho_close(struct irs_ho *this);
-static struct hostent * ho_byname(struct irs_ho *this, const char *name);
-static struct hostent * ho_byname2(struct irs_ho *this, const char *name,
- int af);
-static struct hostent * ho_byaddr(struct irs_ho *this, const void *addr,
- int len, int af);
-static struct hostent * ho_next(struct irs_ho *this);
-static void ho_rewind(struct irs_ho *this);
-static void ho_minimize(struct irs_ho *this);
-static struct __res_state * ho_res_get(struct irs_ho *this);
-static void ho_res_set(struct irs_ho *this,
- struct __res_state *res,
- void (*free_res)(void *));
-static struct addrinfo * ho_addrinfo(struct irs_ho *this, const char *name,
- const struct addrinfo *pai);
-
-static int init(struct irs_ho *this);
-
-/* Exports */
-
-struct irs_ho *
-irs_gen_ho(struct irs_acc *this) {
- struct gen_p *accpvt = (struct gen_p *)this->private;
- struct irs_ho *ho;
- struct pvt *pvt;
-
- if (!(pvt = memget(sizeof *pvt))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- if (!(ho = memget(sizeof *ho))) {
- memput(pvt, sizeof *pvt);
- errno = ENOMEM;
- return (NULL);
- }
- memset(ho, 0x5e, sizeof *ho);
- pvt->rules = accpvt->map_rules[irs_ho];
- pvt->rule = pvt->rules;
- ho->private = pvt;
- ho->close = ho_close;
- ho->byname = ho_byname;
- ho->byname2 = ho_byname2;
- ho->byaddr = ho_byaddr;
- ho->next = ho_next;
- ho->rewind = ho_rewind;
- ho->minimize = ho_minimize;
- ho->res_get = ho_res_get;
- ho->res_set = ho_res_set;
- ho->addrinfo = ho_addrinfo;
- return (ho);
-}
-
-/* Methods. */
-
-static void
-ho_close(struct irs_ho *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- ho_minimize(this);
- if (pvt->res && pvt->free_res)
- (*pvt->free_res)(pvt->res);
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-static struct hostent *
-ho_byname(struct irs_ho *this, const char *name) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_rule *rule;
- struct hostent *rval;
- struct irs_ho *ho;
- int therrno = NETDB_INTERNAL;
- int softerror = 0;
-
- if (init(this) == -1)
- return (NULL);
-
- for (rule = pvt->rules; rule; rule = rule->next) {
- ho = rule->inst->ho;
- RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
- errno = 0;
- rval = (*ho->byname)(ho, name);
- if (rval != NULL)
- return (rval);
- if (softerror == 0 &&
- pvt->res->res_h_errno != HOST_NOT_FOUND &&
- pvt->res->res_h_errno != NETDB_INTERNAL) {
- softerror = 1;
- therrno = pvt->res->res_h_errno;
- }
- if (rule->flags & IRS_CONTINUE)
- continue;
- /*
- * The value TRY_AGAIN can mean that the service
- * is not available, or just that this particular name
- * cannot be resolved now. We use the errno ECONNREFUSED
- * to distinguish. If a lookup sets that errno when
- * H_ERRNO is TRY_AGAIN, we continue to try other lookup
- * functions, otherwise we return the TRY_AGAIN error.
- */
- if (pvt->res->res_h_errno != TRY_AGAIN || errno != ECONNREFUSED)
- break;
- }
- if (softerror != 0 && pvt->res->res_h_errno == HOST_NOT_FOUND)
- RES_SET_H_ERRNO(pvt->res, therrno);
- return (NULL);
-}
-
-static struct hostent *
-ho_byname2(struct irs_ho *this, const char *name, int af) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_rule *rule;
- struct hostent *rval;
- struct irs_ho *ho;
- int therrno = NETDB_INTERNAL;
- int softerror = 0;
-
- if (init(this) == -1)
- return (NULL);
-
- for (rule = pvt->rules; rule; rule = rule->next) {
- ho = rule->inst->ho;
- RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
- errno = 0;
- rval = (*ho->byname2)(ho, name, af);
- if (rval != NULL)
- return (rval);
- if (softerror == 0 &&
- pvt->res->res_h_errno != HOST_NOT_FOUND &&
- pvt->res->res_h_errno != NETDB_INTERNAL) {
- softerror = 1;
- therrno = pvt->res->res_h_errno;
- }
- if (rule->flags & IRS_CONTINUE)
- continue;
- /*
- * See the comments in ho_byname() explaining
- * the interpretation of TRY_AGAIN and ECONNREFUSED.
- */
- if (pvt->res->res_h_errno != TRY_AGAIN || errno != ECONNREFUSED)
- break;
- }
- if (softerror != 0 && pvt->res->res_h_errno == HOST_NOT_FOUND)
- RES_SET_H_ERRNO(pvt->res, therrno);
- return (NULL);
-}
-
-static struct hostent *
-ho_byaddr(struct irs_ho *this, const void *addr, int len, int af) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_rule *rule;
- struct hostent *rval;
- struct irs_ho *ho;
- int therrno = NETDB_INTERNAL;
- int softerror = 0;
-
-
- if (init(this) == -1)
- return (NULL);
-
- for (rule = pvt->rules; rule; rule = rule->next) {
- ho = rule->inst->ho;
- RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
- errno = 0;
- rval = (*ho->byaddr)(ho, addr, len, af);
- if (rval != NULL)
- return (rval);
- if (softerror == 0 &&
- pvt->res->res_h_errno != HOST_NOT_FOUND &&
- pvt->res->res_h_errno != NETDB_INTERNAL) {
- softerror = 1;
- therrno = pvt->res->res_h_errno;
- }
-
- if (rule->flags & IRS_CONTINUE)
- continue;
- /*
- * See the comments in ho_byname() explaining
- * the interpretation of TRY_AGAIN and ECONNREFUSED.
- */
- if (pvt->res->res_h_errno != TRY_AGAIN || errno != ECONNREFUSED)
- break;
- }
- if (softerror != 0 && pvt->res->res_h_errno == HOST_NOT_FOUND)
- RES_SET_H_ERRNO(pvt->res, therrno);
- return (NULL);
-}
-
-static struct hostent *
-ho_next(struct irs_ho *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct hostent *rval;
- struct irs_ho *ho;
-
- while (pvt->rule) {
- ho = pvt->rule->inst->ho;
- rval = (*ho->next)(ho);
- if (rval)
- return (rval);
- if (!(pvt->rule->flags & IRS_CONTINUE))
- break;
- pvt->rule = pvt->rule->next;
- if (pvt->rule) {
- ho = pvt->rule->inst->ho;
- (*ho->rewind)(ho);
- }
- }
- return (NULL);
-}
-
-static void
-ho_rewind(struct irs_ho *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_ho *ho;
-
- pvt->rule = pvt->rules;
- if (pvt->rule) {
- ho = pvt->rule->inst->ho;
- (*ho->rewind)(ho);
- }
-}
-
-static void
-ho_minimize(struct irs_ho *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_rule *rule;
-
- if (pvt->res)
- res_nclose(pvt->res);
- for (rule = pvt->rules; rule != NULL; rule = rule->next) {
- struct irs_ho *ho = rule->inst->ho;
-
- (*ho->minimize)(ho);
- }
-}
-
-static struct __res_state *
-ho_res_get(struct irs_ho *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (!pvt->res) {
- struct __res_state *res;
- res = (struct __res_state *)malloc(sizeof *res);
- if (!res) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(res, 0, sizeof *res);
- ho_res_set(this, res, free);
- }
-
- return (pvt->res);
-}
-
-static void
-ho_res_set(struct irs_ho *this, struct __res_state *res,
- void (*free_res)(void *)) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_rule *rule;
-
- if (pvt->res && pvt->free_res) {
- res_nclose(pvt->res);
- (*pvt->free_res)(pvt->res);
- }
-
- pvt->res = res;
- pvt->free_res = free_res;
-
- for (rule = pvt->rules; rule != NULL; rule = rule->next) {
- struct irs_ho *ho = rule->inst->ho;
-
- (*ho->res_set)(ho, pvt->res, NULL);
- }
-}
-
-static struct addrinfo *
-ho_addrinfo(struct irs_ho *this, const char *name, const struct addrinfo *pai)
-{
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_rule *rule;
- struct addrinfo *rval = NULL;
- struct irs_ho *ho;
- int therrno = NETDB_INTERNAL;
- int softerror = 0;
-
- if (init(this) == -1)
- return (NULL);
-
- for (rule = pvt->rules; rule; rule = rule->next) {
- ho = rule->inst->ho;
- RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
- errno = 0;
- if (ho->addrinfo == NULL) /* for safety */
- continue;
- rval = (*ho->addrinfo)(ho, name, pai);
- if (rval != NULL)
- return (rval);
- if (softerror == 0 &&
- pvt->res->res_h_errno != HOST_NOT_FOUND &&
- pvt->res->res_h_errno != NETDB_INTERNAL) {
- softerror = 1;
- therrno = pvt->res->res_h_errno;
- }
- if (rule->flags & IRS_CONTINUE)
- continue;
- /*
- * See the comments in ho_byname() explaining
- * the interpretation of TRY_AGAIN and ECONNREFUSED.
- */
- if (pvt->res->res_h_errno != TRY_AGAIN ||
- errno != ECONNREFUSED)
- break;
- }
- if (softerror != 0 && pvt->res->res_h_errno == HOST_NOT_FOUND)
- RES_SET_H_ERRNO(pvt->res, therrno);
- if (rval)
- freeaddrinfo(rval);
- return (NULL);
-}
-
-static int
-init(struct irs_ho *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (!pvt->res && !ho_res_get(this))
- return (-1);
-
- if (((pvt->res->options & RES_INIT) == 0) &&
- (res_ninit(pvt->res) == -1))
- return (-1);
-
- return (0);
-}
diff --git a/contrib/bind/lib/irs/gen_ng.c b/contrib/bind/lib/irs/gen_ng.c
deleted file mode 100644
index c28b510..0000000
--- a/contrib/bind/lib/irs/gen_ng.c
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: gen_ng.c,v 1.15 2001/05/29 05:48:38 marka Exp $";
-#endif
-
-/* Imports */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <isc/memcluster.h>
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "gen_p.h"
-
-/* Types */
-
-struct pvt {
- struct irs_rule * rules;
- struct irs_rule * rule;
- char * curgroup;
-};
-
-/* Forward */
-
-static void ng_close(struct irs_ng *);
-static int ng_next(struct irs_ng *, const char **,
- const char **, const char **);
-static int ng_test(struct irs_ng *, const char *,
- const char *, const char *,
- const char *);
-static void ng_rewind(struct irs_ng *, const char *);
-static void ng_minimize(struct irs_ng *);
-
-/* Public */
-
-struct irs_ng *
-irs_gen_ng(struct irs_acc *this) {
- struct gen_p *accpvt = (struct gen_p *)this->private;
- struct irs_ng *ng;
- struct pvt *pvt;
-
- if (!(ng = memget(sizeof *ng))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(ng, 0x5e, sizeof *ng);
- if (!(pvt = memget(sizeof *pvt))) {
- memput(ng, sizeof *ng);
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- pvt->rules = accpvt->map_rules[irs_ng];
- pvt->rule = pvt->rules;
- ng->private = pvt;
- ng->close = ng_close;
- ng->next = ng_next;
- ng->test = ng_test;
- ng->rewind = ng_rewind;
- ng->minimize = ng_minimize;
- return (ng);
-}
-
-/* Methods */
-
-static void
-ng_close(struct irs_ng *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- ng_minimize(this);
- if (pvt->curgroup)
- free(pvt->curgroup);
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-static int
-ng_next(struct irs_ng *this, const char **host, const char **user,
- const char **domain)
-{
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_ng *ng;
-
- while (pvt->rule) {
- ng = pvt->rule->inst->ng;
- if ((*ng->next)(ng, host, user, domain) == 1)
- return (1);
- if (!(pvt->rule->flags & IRS_CONTINUE))
- break;
- pvt->rule = pvt->rule->next;
- if (pvt->rule) {
- ng = pvt->rule->inst->ng;
- (*ng->rewind)(ng, pvt->curgroup);
- }
- }
- return (0);
-}
-
-static int
-ng_test(struct irs_ng *this, const char *name,
- const char *user, const char *host, const char *domain)
-{
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_rule *rule;
- struct irs_ng *ng;
- int rval;
-
- rval = 0;
- for (rule = pvt->rules; rule; rule = rule->next) {
- ng = rule->inst->ng;
- rval = (*ng->test)(ng, name, user, host, domain);
- if (rval || !(rule->flags & IRS_CONTINUE))
- break;
- }
- return (rval);
-}
-
-static void
-ng_rewind(struct irs_ng *this, const char *group) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_ng *ng;
-
- pvt->rule = pvt->rules;
- if (pvt->rule) {
- if (pvt->curgroup)
- free(pvt->curgroup);
- pvt->curgroup = strdup(group);
- ng = pvt->rule->inst->ng;
- (*ng->rewind)(ng, pvt->curgroup);
- }
-}
-
-static void
-ng_minimize(struct irs_ng *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_rule *rule;
-
- for (rule = pvt->rules; rule != NULL; rule = rule->next) {
- struct irs_ng *ng = rule->inst->ng;
-
- (*ng->minimize)(ng);
- }
-}
diff --git a/contrib/bind/lib/irs/gen_nw.c b/contrib/bind/lib/irs/gen_nw.c
deleted file mode 100644
index fad436c..0000000
--- a/contrib/bind/lib/irs/gen_nw.c
+++ /dev/null
@@ -1,262 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: gen_nw.c,v 1.13 1999/10/13 16:39:29 vixie Exp $";
-#endif
-
-/* Imports */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-
-#include <errno.h>
-#include <resolv.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <isc/memcluster.h>
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "gen_p.h"
-
-/* Types */
-
-struct pvt {
- struct irs_rule * rules;
- struct irs_rule * rule;
- struct __res_state * res;
- void (*free_res)(void *);
-};
-
-/* Forward */
-
-static void nw_close(struct irs_nw*);
-static struct nwent * nw_next(struct irs_nw *);
-static struct nwent * nw_byname(struct irs_nw *, const char *, int);
-static struct nwent * nw_byaddr(struct irs_nw *, void *, int, int);
-static void nw_rewind(struct irs_nw *);
-static void nw_minimize(struct irs_nw *);
-static struct __res_state * nw_res_get(struct irs_nw *this);
-static void nw_res_set(struct irs_nw *this,
- struct __res_state *res,
- void (*free_res)(void *));
-
-static int init(struct irs_nw *this);
-
-/* Public */
-
-struct irs_nw *
-irs_gen_nw(struct irs_acc *this) {
- struct gen_p *accpvt = (struct gen_p *)this->private;
- struct irs_nw *nw;
- struct pvt *pvt;
-
- if (!(pvt = memget(sizeof *pvt))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- if (!(nw = memget(sizeof *nw))) {
- memput(pvt, sizeof *pvt);
- errno = ENOMEM;
- return (NULL);
- }
- memset(nw, 0x5e, sizeof *nw);
- pvt->rules = accpvt->map_rules[irs_nw];
- pvt->rule = pvt->rules;
- nw->private = pvt;
- nw->close = nw_close;
- nw->next = nw_next;
- nw->byname = nw_byname;
- nw->byaddr = nw_byaddr;
- nw->rewind = nw_rewind;
- nw->minimize = nw_minimize;
- nw->res_get = nw_res_get;
- nw->res_set = nw_res_set;
- return (nw);
-}
-
-/* Methods */
-
-static void
-nw_close(struct irs_nw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- nw_minimize(this);
-
- if (pvt->res && pvt->free_res)
- (*pvt->free_res)(pvt->res);
-
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-static struct nwent *
-nw_next(struct irs_nw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct nwent *rval;
- struct irs_nw *nw;
-
- if (init(this) == -1)
- return(NULL);
-
- while (pvt->rule) {
- nw = pvt->rule->inst->nw;
- rval = (*nw->next)(nw);
- if (rval)
- return (rval);
- if (!(pvt->rules->flags & IRS_CONTINUE))
- break;
- pvt->rule = pvt->rule->next;
- if (pvt->rule) {
- nw = pvt->rule->inst->nw;
- (*nw->rewind)(nw);
- }
- }
- return (NULL);
-}
-
-static struct nwent *
-nw_byname(struct irs_nw *this, const char *name, int type) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_rule *rule;
- struct nwent *rval;
- struct irs_nw *nw;
-
- if (init(this) == -1)
- return(NULL);
-
- for (rule = pvt->rules; rule; rule = rule->next) {
- nw = rule->inst->nw;
- RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
- rval = (*nw->byname)(nw, name, type);
- if (rval != NULL)
- return (rval);
- if (pvt->res->res_h_errno != TRY_AGAIN &&
- !(rule->flags & IRS_CONTINUE))
- break;
- }
- return (NULL);
-}
-
-static struct nwent *
-nw_byaddr(struct irs_nw *this, void *net, int length, int type) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_rule *rule;
- struct nwent *rval;
- struct irs_nw *nw;
-
- if (init(this) == -1)
- return(NULL);
-
- for (rule = pvt->rules; rule; rule = rule->next) {
- nw = rule->inst->nw;
- RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
- rval = (*nw->byaddr)(nw, net, length, type);
- if (rval != NULL)
- return (rval);
- if (pvt->res->res_h_errno != TRY_AGAIN &&
- !(rule->flags & IRS_CONTINUE))
- break;
- }
- return (NULL);
-}
-
-static void
-nw_rewind(struct irs_nw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_nw *nw;
-
- pvt->rule = pvt->rules;
- if (pvt->rule) {
- nw = pvt->rule->inst->nw;
- (*nw->rewind)(nw);
- }
-}
-
-static void
-nw_minimize(struct irs_nw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_rule *rule;
-
- if (pvt->res)
- res_nclose(pvt->res);
- for (rule = pvt->rules; rule != NULL; rule = rule->next) {
- struct irs_nw *nw = rule->inst->nw;
-
- (*nw->minimize)(nw);
- }
-}
-
-static struct __res_state *
-nw_res_get(struct irs_nw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (!pvt->res) {
- struct __res_state *res;
- res = (struct __res_state *)malloc(sizeof *res);
- if (!res) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(res, 0, sizeof *res);
- nw_res_set(this, res, free);
- }
-
- return (pvt->res);
-}
-
-static void
-nw_res_set(struct irs_nw *this, struct __res_state *res,
- void (*free_res)(void *)) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_rule *rule;
-
- if (pvt->res && pvt->free_res) {
- res_nclose(pvt->res);
- (*pvt->free_res)(pvt->res);
- }
-
- pvt->res = res;
- pvt->free_res = free_res;
-
- for (rule = pvt->rules; rule != NULL; rule = rule->next) {
- struct irs_nw *nw = rule->inst->nw;
-
- (*nw->res_set)(nw, pvt->res, NULL);
- }
-}
-
-static int
-init(struct irs_nw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (!pvt->res && !nw_res_get(this))
- return (-1);
- if (((pvt->res->options & RES_INIT) == 0) &&
- res_ninit(pvt->res) == -1)
- return (-1);
- return (0);
-}
diff --git a/contrib/bind/lib/irs/gen_p.h b/contrib/bind/lib/irs/gen_p.h
deleted file mode 100644
index 35ef439..0000000
--- a/contrib/bind/lib/irs/gen_p.h
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-/*
- * $Id: gen_p.h,v 1.11 2001/05/29 05:48:39 marka Exp $
- */
-
-/* Notes:
- * We hope to create a complete set of thread-safe entry points someday,
- * which will mean a set of getXbyY() functions that take as an argument
- * a pointer to the map class, which will have a pointer to the private
- * data, which will be used preferentially to the static variables that
- * are necessary to support the "classic" interface. This "classic"
- * interface will then be reimplemented as stubs on top of the thread
- * safe modules, and will keep the map class pointers as their only
- * static data. HOWEVER, we are not there yet. So while we will call
- * the just-barely-converted map class methods with map class pointers,
- * right now they probably all still use statics. We're not fooling
- * anybody, and we're not trying to (yet).
- */
-
-#ifndef _GEN_P_H_INCLUDED
-#define _GEN_P_H_INCLUDED
-
-/*
- * These are the access methods.
- */
-enum irs_acc_id {
- irs_lcl, /* Local. */
- irs_dns, /* DNS or Hesiod. */
- irs_nis, /* Sun NIS ("YP"). */
- irs_irp, /* IR protocol. */
- irs_nacc
-};
-
-/*
- * These are the map types.
- */
-enum irs_map_id {
- irs_gr, /* "group" */
- irs_pw, /* "passwd" */
- irs_sv, /* "services" */
- irs_pr, /* "protocols" */
- irs_ho, /* "hosts" */
- irs_nw, /* "networks" */
- irs_ng, /* "netgroup" */
- irs_nmap
-};
-
-/*
- * This is an accessor instance.
- */
-struct irs_inst {
- struct irs_acc *acc;
- struct irs_gr * gr;
- struct irs_pw * pw;
- struct irs_sv * sv;
- struct irs_pr * pr;
- struct irs_ho * ho;
- struct irs_nw * nw;
- struct irs_ng * ng;
-};
-
-/*
- * This is a search rule for some map type.
- */
-struct irs_rule {
- struct irs_rule * next;
- struct irs_inst * inst;
- int flags;
-};
-#define IRS_MERGE 0x0001 /* Don't stop if acc. has data? */
-#define IRS_CONTINUE 0x0002 /* Don't stop if acc. has no data? */
-
-/*
- * This is the private data for a search access class.
- */
-struct gen_p {
- char * options;
- struct irs_rule * map_rules[(int)irs_nmap];
- struct irs_inst accessors[(int)irs_nacc];
- struct __res_state * res;
- void (*free_res) __P((void *));
-};
-
-/*
- * Externs.
- */
-
-extern struct irs_acc * irs_gen_acc __P((const char *, const char *conf_file));
-extern struct irs_gr * irs_gen_gr __P((struct irs_acc *));
-extern struct irs_pw * irs_gen_pw __P((struct irs_acc *));
-extern struct irs_sv * irs_gen_sv __P((struct irs_acc *));
-extern struct irs_pr * irs_gen_pr __P((struct irs_acc *));
-extern struct irs_ho * irs_gen_ho __P((struct irs_acc *));
-extern struct irs_nw * irs_gen_nw __P((struct irs_acc *));
-extern struct irs_ng * irs_gen_ng __P((struct irs_acc *));
-
-#endif /*_IRS_P_H_INCLUDED*/
diff --git a/contrib/bind/lib/irs/gen_pr.c b/contrib/bind/lib/irs/gen_pr.c
deleted file mode 100644
index de09571..0000000
--- a/contrib/bind/lib/irs/gen_pr.c
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: gen_pr.c,v 1.12 1999/10/13 16:39:30 vixie Exp $";
-#endif
-
-/* Imports */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-
-#include <errno.h>
-#include <resolv.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <isc/memcluster.h>
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "gen_p.h"
-
-/* Types */
-
-struct pvt {
- struct irs_rule * rules;
- struct irs_rule * rule;
- struct __res_state * res;
- void (*free_res)(void *);
-};
-
-/* Forward */
-
-static void pr_close(struct irs_pr*);
-static struct protoent * pr_next(struct irs_pr *);
-static struct protoent * pr_byname(struct irs_pr *, const char *);
-static struct protoent * pr_bynumber(struct irs_pr *, int);
-static void pr_rewind(struct irs_pr *);
-static void pr_minimize(struct irs_pr *);
-static struct __res_state * pr_res_get(struct irs_pr *);
-static void pr_res_set(struct irs_pr *,
- struct __res_state *,
- void (*)(void *));
-
-/* Public */
-
-struct irs_pr *
-irs_gen_pr(struct irs_acc *this) {
- struct gen_p *accpvt = (struct gen_p *)this->private;
- struct irs_pr *pr;
- struct pvt *pvt;
-
- if (!(pr = memget(sizeof *pr))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(pr, 0x5e, sizeof *pr);
- if (!(pvt = memget(sizeof *pvt))) {
- memput(pr, sizeof *pr);
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- pvt->rules = accpvt->map_rules[irs_pr];
- pvt->rule = pvt->rules;
- pr->private = pvt;
- pr->close = pr_close;
- pr->next = pr_next;
- pr->byname = pr_byname;
- pr->bynumber = pr_bynumber;
- pr->rewind = pr_rewind;
- pr->minimize = pr_minimize;
- pr->res_get = pr_res_get;
- pr->res_set = pr_res_set;
- return (pr);
-}
-
-/* Methods */
-
-static void
-pr_close(struct irs_pr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-static struct protoent *
-pr_next(struct irs_pr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct protoent *rval;
- struct irs_pr *pr;
-
- while (pvt->rule) {
- pr = pvt->rule->inst->pr;
- rval = (*pr->next)(pr);
- if (rval)
- return (rval);
- if (!(pvt->rules->flags & IRS_CONTINUE))
- break;
- pvt->rule = pvt->rule->next;
- if (pvt->rule) {
- pr = pvt->rule->inst->pr;
- (*pr->rewind)(pr);
- }
- }
- return (NULL);
-}
-
-static struct protoent *
-pr_byname(struct irs_pr *this, const char *name) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_rule *rule;
- struct protoent *rval;
- struct irs_pr *pr;
-
- rval = NULL;
- for (rule = pvt->rules; rule; rule = rule->next) {
- pr = rule->inst->pr;
- rval = (*pr->byname)(pr, name);
- if (rval || !(rule->flags & IRS_CONTINUE))
- break;
- }
- return (rval);
-}
-
-static struct protoent *
-pr_bynumber(struct irs_pr *this, int proto) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_rule *rule;
- struct protoent *rval;
- struct irs_pr *pr;
-
- rval = NULL;
- for (rule = pvt->rules; rule; rule = rule->next) {
- pr = rule->inst->pr;
- rval = (*pr->bynumber)(pr, proto);
- if (rval || !(rule->flags & IRS_CONTINUE))
- break;
- }
- return (rval);
-}
-
-static void
-pr_rewind(struct irs_pr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_pr *pr;
-
- pvt->rule = pvt->rules;
- if (pvt->rule) {
- pr = pvt->rule->inst->pr;
- (*pr->rewind)(pr);
- }
-}
-
-static void
-pr_minimize(struct irs_pr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_rule *rule;
-
- for (rule = pvt->rules; rule != NULL; rule = rule->next) {
- struct irs_pr *pr = rule->inst->pr;
-
- (*pr->minimize)(pr);
- }
-}
-
-static struct __res_state *
-pr_res_get(struct irs_pr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (!pvt->res) {
- struct __res_state *res;
- res = (struct __res_state *)malloc(sizeof *res);
- if (!res) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(res, 0, sizeof *res);
- pr_res_set(this, res, free);
- }
-
- return (pvt->res);
-}
-
-static void
-pr_res_set(struct irs_pr *this, struct __res_state *res,
- void (*free_res)(void *)) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_rule *rule;
-
- if (pvt->res && pvt->free_res) {
- res_nclose(pvt->res);
- (*pvt->free_res)(pvt->res);
- }
-
- pvt->res = res;
- pvt->free_res = free_res;
-
- for (rule = pvt->rules; rule != NULL; rule = rule->next) {
- struct irs_pr *pr = rule->inst->pr;
-
- if (pr->res_set)
- (*pr->res_set)(pr, pvt->res, NULL);
- }
-}
diff --git a/contrib/bind/lib/irs/gen_pw.c b/contrib/bind/lib/irs/gen_pw.c
deleted file mode 100644
index d80a64b..0000000
--- a/contrib/bind/lib/irs/gen_pw.c
+++ /dev/null
@@ -1,233 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: gen_pw.c,v 1.14 1999/10/13 16:39:30 vixie Exp $";
-#endif
-
-/* Imports */
-
-#include "port_before.h"
-
-#ifndef WANT_IRS_PW
-static int __bind_irs_pw_unneeded;
-#else
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-
-#include <errno.h>
-#include <pwd.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <isc/memcluster.h>
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "gen_p.h"
-
-/* Types */
-
-struct pvt {
- struct irs_rule * rules;
- struct irs_rule * rule;
- struct __res_state * res;
- void (*free_res)(void *);
-};
-
-/* Forward */
-
-static void pw_close(struct irs_pw *);
-static struct passwd * pw_next(struct irs_pw *);
-static struct passwd * pw_byname(struct irs_pw *, const char *);
-static struct passwd * pw_byuid(struct irs_pw *, uid_t);
-static void pw_rewind(struct irs_pw *);
-static void pw_minimize(struct irs_pw *);
-static struct __res_state * pw_res_get(struct irs_pw *);
-static void pw_res_set(struct irs_pw *,
- struct __res_state *,
- void (*)(void *));
-
-/* Public */
-
-struct irs_pw *
-irs_gen_pw(struct irs_acc *this) {
- struct gen_p *accpvt = (struct gen_p *)this->private;
- struct irs_pw *pw;
- struct pvt *pvt;
-
- if (!(pw = memget(sizeof *pw))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(pw, 0x5e, sizeof *pw);
- if (!(pvt = memget(sizeof *pvt))) {
- memput(pw, sizeof *pvt);
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- pvt->rules = accpvt->map_rules[irs_pw];
- pvt->rule = pvt->rules;
- pw->private = pvt;
- pw->close = pw_close;
- pw->next = pw_next;
- pw->byname = pw_byname;
- pw->byuid = pw_byuid;
- pw->rewind = pw_rewind;
- pw->minimize = pw_minimize;
- pw->res_get = pw_res_get;
- pw->res_set = pw_res_set;
- return (pw);
-}
-
-/* Methods */
-
-static void
-pw_close(struct irs_pw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-static struct passwd *
-pw_next(struct irs_pw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct passwd *rval;
- struct irs_pw *pw;
-
- while (pvt->rule) {
- pw = pvt->rule->inst->pw;
- rval = (*pw->next)(pw);
- if (rval)
- return (rval);
- if (!(pvt->rule->flags & IRS_CONTINUE))
- break;
- pvt->rule = pvt->rule->next;
- if (pvt->rule) {
- pw = pvt->rule->inst->pw;
- (*pw->rewind)(pw);
- }
- }
- return (NULL);
-}
-
-static void
-pw_rewind(struct irs_pw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_pw *pw;
-
- pvt->rule = pvt->rules;
- if (pvt->rule) {
- pw = pvt->rule->inst->pw;
- (*pw->rewind)(pw);
- }
-}
-
-static struct passwd *
-pw_byname(struct irs_pw *this, const char *name) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_rule *rule;
- struct passwd *rval;
- struct irs_pw *pw;
-
- rval = NULL;
- for (rule = pvt->rules; rule; rule = rule->next) {
- pw = rule->inst->pw;
- rval = (*pw->byname)(pw, name);
- if (rval || !(rule->flags & IRS_CONTINUE))
- break;
- }
- return (rval);
-}
-
-static struct passwd *
-pw_byuid(struct irs_pw *this, uid_t uid) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_rule *rule;
- struct passwd *rval;
- struct irs_pw *pw;
-
- rval = NULL;
- for (rule = pvt->rules; rule; rule = rule->next) {
- pw = rule->inst->pw;
- rval = (*pw->byuid)(pw, uid);
- if (rval || !(rule->flags & IRS_CONTINUE))
- break;
- }
- return (rval);
-}
-
-static void
-pw_minimize(struct irs_pw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_rule *rule;
-
- for (rule = pvt->rules; rule != NULL; rule = rule->next) {
- struct irs_pw *pw = rule->inst->pw;
-
- (*pw->minimize)(pw);
- }
-}
-
-static struct __res_state *
-pw_res_get(struct irs_pw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (!pvt->res) {
- struct __res_state *res;
- res = (struct __res_state *)malloc(sizeof *res);
- if (!res) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(res, 0, sizeof *res);
- pw_res_set(this, res, free);
- }
-
- return (pvt->res);
-}
-
-static void
-pw_res_set(struct irs_pw *this, struct __res_state *res,
- void (*free_res)(void *)) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_rule *rule;
-
- if (pvt->res && pvt->free_res) {
- res_nclose(pvt->res);
- (*pvt->free_res)(pvt->res);
- }
-
- pvt->res = res;
- pvt->free_res = free_res;
-
- for (rule = pvt->rules; rule != NULL; rule = rule->next) {
- struct irs_pw *pw = rule->inst->pw;
-
- if (pw->res_set)
- (*pw->res_set)(pw, pvt->res, NULL);
- }
-}
-
-#endif /* WANT_IRS_PW */
diff --git a/contrib/bind/lib/irs/gen_sv.c b/contrib/bind/lib/irs/gen_sv.c
deleted file mode 100644
index e0c1cb6..0000000
--- a/contrib/bind/lib/irs/gen_sv.c
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: gen_sv.c,v 1.12 1999/10/13 16:39:30 vixie Exp $";
-#endif
-
-/* Imports */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <isc/memcluster.h>
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "gen_p.h"
-
-/* Types */
-
-struct pvt {
- struct irs_rule * rules;
- struct irs_rule * rule;
- struct __res_state * res;
- void (*free_res)(void *);
-};
-
-/* Forward */
-
-static void sv_close(struct irs_sv*);
-static struct servent * sv_next(struct irs_sv *);
-static struct servent * sv_byname(struct irs_sv *, const char *,
- const char *);
-static struct servent * sv_byport(struct irs_sv *, int, const char *);
-static void sv_rewind(struct irs_sv *);
-static void sv_minimize(struct irs_sv *);
-static struct __res_state * sv_res_get(struct irs_sv *);
-static void sv_res_set(struct irs_sv *,
- struct __res_state *,
- void (*)(void *));
-
-/* Public */
-
-struct irs_sv *
-irs_gen_sv(struct irs_acc *this) {
- struct gen_p *accpvt = (struct gen_p *)this->private;
- struct irs_sv *sv;
- struct pvt *pvt;
-
- if (!(sv = memget(sizeof *sv))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(sv, 0x5e, sizeof *sv);
- if (!(pvt = memget(sizeof *pvt))) {
- memput(sv, sizeof *sv);
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- pvt->rules = accpvt->map_rules[irs_sv];
- pvt->rule = pvt->rules;
- sv->private = pvt;
- sv->close = sv_close;
- sv->next = sv_next;
- sv->byname = sv_byname;
- sv->byport = sv_byport;
- sv->rewind = sv_rewind;
- sv->minimize = sv_minimize;
- sv->res_get = sv_res_get;
- sv->res_set = sv_res_set;
- return (sv);
-}
-
-/* Methods */
-
-static void
-sv_close(struct irs_sv *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-static struct servent *
-sv_next(struct irs_sv *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct servent *rval;
- struct irs_sv *sv;
-
- while (pvt->rule) {
- sv = pvt->rule->inst->sv;
- rval = (*sv->next)(sv);
- if (rval)
- return (rval);
- if (!(pvt->rule->flags & IRS_CONTINUE))
- break;
- pvt->rule = pvt->rule->next;
- if (pvt->rule) {
- sv = pvt->rule->inst->sv;
- (*sv->rewind)(sv);
- }
- }
- return (NULL);
-}
-
-static struct servent *
-sv_byname(struct irs_sv *this, const char *name, const char *proto) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_rule *rule;
- struct servent *rval;
- struct irs_sv *sv;
-
- rval = NULL;
- for (rule = pvt->rules; rule; rule = rule->next) {
- sv = rule->inst->sv;
- rval = (*sv->byname)(sv, name, proto);
- if (rval || !(rule->flags & IRS_CONTINUE))
- break;
- }
- return (rval);
-}
-
-static struct servent *
-sv_byport(struct irs_sv *this, int port, const char *proto) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_rule *rule;
- struct servent *rval;
- struct irs_sv *sv;
-
- rval = NULL;
- for (rule = pvt->rules; rule; rule = rule->next) {
- sv = rule->inst->sv;
- rval = (*sv->byport)(sv, port, proto);
- if (rval || !(rule->flags & IRS_CONTINUE))
- break;
- }
- return (rval);
-}
-
-static void
-sv_rewind(struct irs_sv *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_sv *sv;
-
- pvt->rule = pvt->rules;
- if (pvt->rule) {
- sv = pvt->rule->inst->sv;
- (*sv->rewind)(sv);
- }
-}
-
-static void
-sv_minimize(struct irs_sv *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_rule *rule;
-
- for (rule = pvt->rules; rule != NULL; rule = rule->next) {
- struct irs_sv *sv = rule->inst->sv;
-
- (*sv->minimize)(sv);
- }
-}
-
-static struct __res_state *
-sv_res_get(struct irs_sv *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (!pvt->res) {
- struct __res_state *res;
- res = (struct __res_state *)malloc(sizeof *res);
- if (!res) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(res, 0, sizeof *res);
- sv_res_set(this, res, free);
- }
-
- return (pvt->res);
-}
-
-static void
-sv_res_set(struct irs_sv *this, struct __res_state *res,
- void (*free_res)(void *)) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct irs_rule *rule;
-
- if (pvt->res && pvt->free_res) {
- res_nclose(pvt->res);
- (*pvt->free_res)(pvt->res);
- }
-
- pvt->res = res;
- pvt->free_res = free_res;
-
- for (rule = pvt->rules; rule != NULL; rule = rule->next) {
- struct irs_sv *sv = rule->inst->sv;
-
- if (sv->res_set)
- (*sv->res_set)(sv, pvt->res, NULL);
- }
-}
diff --git a/contrib/bind/lib/irs/getaddrinfo.c b/contrib/bind/lib/irs/getaddrinfo.c
deleted file mode 100644
index 89db519..0000000
--- a/contrib/bind/lib/irs/getaddrinfo.c
+++ /dev/null
@@ -1,1229 +0,0 @@
-/* $KAME: getaddrinfo.c,v 1.14 2001/01/06 09:41:15 jinmei Exp $ */
-
-/*
- * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the project 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 PROJECT 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 PROJECT 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.
- */
-
-/*
- * Issues to be discussed:
- * - Thread safe-ness must be checked.
- * - Return values. There are nonstandard return values defined and used
- * in the source code. This is because RFC2553 is silent about which error
- * code must be returned for which situation.
- * - IPv4 classful (shortened) form. RFC2553 is silent about it. XNET 5.2
- * says to use inet_aton() to convert IPv4 numeric to binary (allows
- * classful form as a result).
- * current code - disallow classful form for IPv4 (due to use of inet_pton).
- * - freeaddrinfo(NULL). RFC2553 is silent about it. XNET 5.2 says it is
- * invalid.
- * current code - SEGV on freeaddrinfo(NULL)
- * Note:
- * - We use getipnodebyname() just for thread-safeness. There's no intent
- * to let it do PF_UNSPEC (actually we never pass PF_UNSPEC to
- * getipnodebyname().
- * - The code filters out AFs that are not supported by the kernel,
- * when globbing NULL hostname (to loopback, or wildcard). Is it the right
- * thing to do? What is the relationship with post-RFC2553 AI_ADDRCONFIG
- * in ai_flags?
- * - (post-2553) semantics of AI_ADDRCONFIG itself is too vague.
- * (1) what should we do against numeric hostname (2) what should we do
- * against NULL hostname (3) what is AI_ADDRCONFIG itself. AF not ready?
- * non-loopback address configured? global address configured?
- * - To avoid search order issue, we have a big amount of code duplicate
- * from gethnamaddr.c and some other places. The issues that there's no
- * lower layer function to lookup "IPv4 or IPv6" record. Calling
- * gethostbyname2 from getaddrinfo will end up in wrong search order, as
- * follows:
- * - The code makes use of following calls when asked to resolver with
- * ai_family = PF_UNSPEC:
- * getipnodebyname(host, AF_INET6);
- * getipnodebyname(host, AF_INET);
- * This will result in the following queries if the node is configure to
- * prefer /etc/hosts than DNS:
- * lookup /etc/hosts for IPv6 address
- * lookup DNS for IPv6 address
- * lookup /etc/hosts for IPv4 address
- * lookup DNS for IPv4 address
- * which may not meet people's requirement.
- * The right thing to happen is to have underlying layer which does
- * PF_UNSPEC lookup (lookup both) and return chain of addrinfos.
- * This would result in a bit of code duplicate with _dns_ghbyname() and
- * friends.
- */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-
-#include <net/if.h>
-#include <netinet/in.h>
-
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-
-#include <netdb.h>
-#include <resolv.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stddef.h>
-#include <ctype.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <errno.h>
-
-#include <stdarg.h>
-
-#include <irs.h>
-#include <isc/assertions.h>
-
-#include "port_after.h"
-
-#include "irs_data.h"
-
-#define SUCCESS 0
-#define ANY 0
-#define YES 1
-#define NO 0
-
-static const char in_addrany[] = { 0, 0, 0, 0 };
-static const char in6_addrany[] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-};
-static const char in_loopback[] = { 127, 0, 0, 1 };
-static const char in6_loopback[] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
-};
-
-static const struct afd {
- int a_af;
- int a_addrlen;
- int a_socklen;
- int a_off;
- const char *a_addrany;
- const char *a_loopback;
- int a_scoped;
-} afdl [] = {
- {PF_INET6, sizeof(struct in6_addr),
- sizeof(struct sockaddr_in6),
- offsetof(struct sockaddr_in6, sin6_addr),
- in6_addrany, in6_loopback, 1},
- {PF_INET, sizeof(struct in_addr),
- sizeof(struct sockaddr_in),
- offsetof(struct sockaddr_in, sin_addr),
- in_addrany, in_loopback, 0},
- {0, 0, 0, 0, NULL, NULL, 0},
-};
-
-struct explore {
- int e_af;
- int e_socktype;
- int e_protocol;
- const char *e_protostr;
- int e_wild;
-#define WILD_AF(ex) ((ex)->e_wild & 0x01)
-#define WILD_SOCKTYPE(ex) ((ex)->e_wild & 0x02)
-#define WILD_PROTOCOL(ex) ((ex)->e_wild & 0x04)
-};
-
-static const struct explore explore[] = {
-#if 0
- { PF_LOCAL, 0, ANY, ANY, NULL, 0x01 },
-#endif
- { PF_INET6, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 },
- { PF_INET6, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 },
- { PF_INET6, SOCK_RAW, ANY, NULL, 0x05 },
- { PF_INET, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 },
- { PF_INET, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 },
- { PF_INET, SOCK_RAW, ANY, NULL, 0x05 },
- { -1, 0, 0, NULL, 0 },
-};
-
-#define PTON_MAX 16
-
-static int str_isnumber __P((const char *));
-static int explore_fqdn __P((const struct addrinfo *, const char *,
- const char *, struct addrinfo **));
-static int explore_copy __P((const struct addrinfo *, const struct addrinfo *,
- struct addrinfo **));
-static int explore_null __P((const struct addrinfo *,
- const char *, struct addrinfo **));
-static int explore_numeric __P((const struct addrinfo *, const char *,
- const char *, struct addrinfo **));
-static int explore_numeric_scope __P((const struct addrinfo *, const char *,
- const char *, struct addrinfo **));
-static int get_canonname __P((const struct addrinfo *,
- struct addrinfo *, const char *));
-static struct addrinfo *get_ai __P((const struct addrinfo *,
- const struct afd *, const char *));
-static struct addrinfo *copy_ai __P((const struct addrinfo *));
-static int get_portmatch __P((const struct addrinfo *, const char *));
-static int get_port __P((const struct addrinfo *, const char *, int));
-static const struct afd *find_afd __P((int));
-static int addrconfig __P((int));
-static int ip6_str2scopeid __P((char *, struct sockaddr_in6 *,
- u_int32_t *scopeidp));
-static struct net_data *init __P((void));
-
-struct addrinfo *hostent2addrinfo __P((struct hostent *,
- const struct addrinfo *));
-struct addrinfo *addr2addrinfo __P((const struct addrinfo *,
- const char *));
-
-#if 0
-static const char *ai_errlist[] = {
- "Success",
- "Address family for hostname not supported", /* EAI_ADDRFAMILY */
- "Temporary failure in name resolution", /* EAI_AGAIN */
- "Invalid value for ai_flags", /* EAI_BADFLAGS */
- "Non-recoverable failure in name resolution", /* EAI_FAIL */
- "ai_family not supported", /* EAI_FAMILY */
- "Memory allocation failure", /* EAI_MEMORY */
- "No address associated with hostname", /* EAI_NODATA */
- "hostname nor servname provided, or not known", /* EAI_NONAME */
- "servname not supported for ai_socktype", /* EAI_SERVICE */
- "ai_socktype not supported", /* EAI_SOCKTYPE */
- "System error returned in errno", /* EAI_SYSTEM */
- "Invalid value for hints", /* EAI_BADHINTS */
- "Resolved protocol is unknown", /* EAI_PROTOCOL */
- "Unknown error", /* EAI_MAX */
-};
-#endif
-
-/* XXX macros that make external reference is BAD. */
-
-#define GET_AI(ai, afd, addr) \
-do { \
- /* external reference: pai, error, and label free */ \
- (ai) = get_ai(pai, (afd), (addr)); \
- if ((ai) == NULL) { \
- error = EAI_MEMORY; \
- goto free; \
- } \
-} while (/*CONSTCOND*/0)
-
-#define GET_PORT(ai, serv) \
-do { \
- /* external reference: error and label free */ \
- error = get_port((ai), (serv), 0); \
- if (error != 0) \
- goto free; \
-} while (/*CONSTCOND*/0)
-
-#define GET_CANONNAME(ai, str) \
-do { \
- /* external reference: pai, error and label free */ \
- error = get_canonname(pai, (ai), (str)); \
- if (error != 0) \
- goto free; \
-} while (/*CONSTCOND*/0)
-
-#define ERR(err) \
-do { \
- /* external reference: error, and label bad */ \
- error = (err); \
- goto bad; \
- /*NOTREACHED*/ \
-} while (/*CONSTCOND*/0)
-
-#define MATCH_FAMILY(x, y, w) \
- ((x) == (y) || (/*CONSTCOND*/(w) && ((x) == PF_UNSPEC || (y) == PF_UNSPEC)))
-#define MATCH(x, y, w) \
- ((x) == (y) || (/*CONSTCOND*/(w) && ((x) == ANY || (y) == ANY)))
-
-#if 0 /* bind8 has its own version */
-char *
-gai_strerror(ecode)
- int ecode;
-{
- if (ecode < 0 || ecode > EAI_MAX)
- ecode = EAI_MAX;
- return ai_errlist[ecode];
-}
-#endif
-
-void
-freeaddrinfo(ai)
- struct addrinfo *ai;
-{
- struct addrinfo *next;
-
- do {
- next = ai->ai_next;
- if (ai->ai_canonname)
- free(ai->ai_canonname);
- /* no need to free(ai->ai_addr) */
- free(ai);
- ai = next;
- } while (ai);
-}
-
-static int
-str_isnumber(p)
- const char *p;
-{
- char *ep;
-
- if (*p == '\0')
- return NO;
- ep = NULL;
- errno = 0;
- (void)strtoul(p, &ep, 10);
- if (errno == 0 && ep && *ep == '\0')
- return YES;
- else
- return NO;
-}
-
-int
-getaddrinfo(hostname, servname, hints, res)
- const char *hostname, *servname;
- const struct addrinfo *hints;
- struct addrinfo **res;
-{
- struct addrinfo sentinel;
- struct addrinfo *cur;
- int error = 0;
- struct addrinfo ai, ai0, *afai = NULL;
- struct addrinfo *pai;
- const struct explore *ex;
-
- memset(&sentinel, 0, sizeof(sentinel));
- cur = &sentinel;
- pai = &ai;
- pai->ai_flags = 0;
- pai->ai_family = PF_UNSPEC;
- pai->ai_socktype = ANY;
- pai->ai_protocol = ANY;
- pai->ai_addrlen = 0;
- pai->ai_canonname = NULL;
- pai->ai_addr = NULL;
- pai->ai_next = NULL;
-
- if (hostname == NULL && servname == NULL)
- return EAI_NONAME;
- if (hints) {
- /* error check for hints */
- if (hints->ai_addrlen || hints->ai_canonname ||
- hints->ai_addr || hints->ai_next)
- ERR(EAI_BADHINTS); /* xxx */
- if (hints->ai_flags & ~AI_MASK)
- ERR(EAI_BADFLAGS);
- switch (hints->ai_family) {
- case PF_UNSPEC:
- case PF_INET:
- case PF_INET6:
- break;
- default:
- ERR(EAI_FAMILY);
- }
- memcpy(pai, hints, sizeof(*pai));
-
- /*
- * if both socktype/protocol are specified, check if they
- * are meaningful combination.
- */
- if (pai->ai_socktype != ANY && pai->ai_protocol != ANY) {
- for (ex = explore; ex->e_af >= 0; ex++) {
- if (pai->ai_family != ex->e_af)
- continue;
- if (ex->e_socktype == ANY)
- continue;
- if (ex->e_protocol == ANY)
- continue;
- if (pai->ai_socktype == ex->e_socktype &&
- pai->ai_protocol != ex->e_protocol) {
- ERR(EAI_BADHINTS);
- }
- }
- }
- }
-
- /*
- * post-2553: AI_ALL and AI_V4MAPPED are effective only against
- * AF_INET6 query. They needs to be ignored if specified in other
- * occassions.
- */
- switch (pai->ai_flags & (AI_ALL | AI_V4MAPPED)) {
- case AI_V4MAPPED:
- case AI_ALL | AI_V4MAPPED:
- if (pai->ai_family != AF_INET6)
- pai->ai_flags &= ~(AI_ALL | AI_V4MAPPED);
- break;
- case AI_ALL:
-#if 1
- /* illegal */
- ERR(EAI_BADFLAGS);
-#else
- pai->ai_flags &= ~(AI_ALL | AI_V4MAPPED);
- break;
-#endif
- }
-
- /*
- * check for special cases. (1) numeric servname is disallowed if
- * socktype/protocol are left unspecified. (2) servname is disallowed
- * for raw and other inet{,6} sockets.
- */
- if (MATCH_FAMILY(pai->ai_family, PF_INET, 1)
-#ifdef PF_INET6
- || MATCH_FAMILY(pai->ai_family, PF_INET6, 1)
-#endif
- ) {
- ai0 = *pai; /* backup *pai */
-
- if (pai->ai_family == PF_UNSPEC) {
-#ifdef PF_INET6
- pai->ai_family = PF_INET6;
-#else
- pai->ai_family = PF_INET;
-#endif
- }
- error = get_portmatch(pai, servname);
- if (error)
- ERR(error);
-
- *pai = ai0;
- }
-
- ai0 = *pai;
-
- /* NULL hostname, or numeric hostname */
- for (ex = explore; ex->e_af >= 0; ex++) {
- *pai = ai0;
-
- if (!MATCH_FAMILY(pai->ai_family, ex->e_af, WILD_AF(ex)))
- continue;
- if (!MATCH(pai->ai_socktype, ex->e_socktype, WILD_SOCKTYPE(ex)))
- continue;
- if (!MATCH(pai->ai_protocol, ex->e_protocol, WILD_PROTOCOL(ex)))
- continue;
-
- if (pai->ai_family == PF_UNSPEC)
- pai->ai_family = ex->e_af;
- if (pai->ai_socktype == ANY && ex->e_socktype != ANY)
- pai->ai_socktype = ex->e_socktype;
- if (pai->ai_protocol == ANY && ex->e_protocol != ANY)
- pai->ai_protocol = ex->e_protocol;
-
- /*
- * if the servname does not match socktype/protocol, ignore it.
- */
- if (get_portmatch(pai, servname) != 0)
- continue;
-
- if (hostname == NULL) {
- /*
- * filter out AFs that are not supported by the kernel
- * XXX errno?
- */
- if (!addrconfig(pai->ai_family))
- continue;
- error = explore_null(pai, servname, &cur->ai_next);
- } else
- error = explore_numeric_scope(pai, hostname, servname,
- &cur->ai_next);
-
- if (error)
- goto free;
-
- while (cur && cur->ai_next)
- cur = cur->ai_next;
- }
-
- /*
- * XXX
- * If numreic representation of AF1 can be interpreted as FQDN
- * representation of AF2, we need to think again about the code below.
- */
- if (sentinel.ai_next)
- goto good;
-
- if (pai->ai_flags & AI_NUMERICHOST)
- ERR(EAI_NONAME);
- if (hostname == NULL)
- ERR(EAI_NONAME);
-
- /*
- * hostname as alphabetical name.
- * We'll make sure that
- * - if returning addrinfo list is empty, return non-zero error
- * value (already known one or EAI_NONAME).
- * - otherwise,
- * + if we haven't had any errors, return 0 (i.e. success).
- * + if we've had an error, free the list and return the error.
- * without any assumption on the behavior of explore_fqdn().
- */
-
- /* first, try to query DNS for all possible address families. */
- *pai = ai0;
- error = explore_fqdn(pai, hostname, servname, &afai);
- if (error) {
- if (afai != NULL)
- freeaddrinfo(afai);
- goto free;
- }
- if (afai == NULL) {
- error = EAI_NONAME; /* we've had no errors. */
- goto free;
- }
-
- /*
- * we would like to prefer AF_INET6 than AF_INET, so we'll make an
- * outer loop by AFs.
- */
- for (ex = explore; ex->e_af >= 0; ex++) {
- *pai = ai0;
-
- if (pai->ai_family == PF_UNSPEC)
- pai->ai_family = ex->e_af;
-
- if (!MATCH_FAMILY(pai->ai_family, ex->e_af, WILD_AF(ex)))
- continue;
- if (!MATCH(pai->ai_socktype, ex->e_socktype,
- WILD_SOCKTYPE(ex))) {
- continue;
- }
- if (!MATCH(pai->ai_protocol, ex->e_protocol,
- WILD_PROTOCOL(ex))) {
- continue;
- }
-
-#ifdef AI_ADDRCONFIG
- /*
- * If AI_ADDRCONFIG is specified, check if we are
- * expected to return the address family or not.
- */
- if ((pai->ai_flags & AI_ADDRCONFIG) != 0 &&
- !addrconfig(pai->ai_family))
- continue;
-#endif
-
- if (pai->ai_family == PF_UNSPEC)
- pai->ai_family = ex->e_af;
- if (pai->ai_socktype == ANY && ex->e_socktype != ANY)
- pai->ai_socktype = ex->e_socktype;
- if (pai->ai_protocol == ANY && ex->e_protocol != ANY)
- pai->ai_protocol = ex->e_protocol;
-
- /*
- * if the servname does not match socktype/protocol, ignore it.
- */
- if (get_portmatch(pai, servname) != 0)
- continue;
-
- if ((error = explore_copy(pai, afai, &cur->ai_next)) != 0) {
- freeaddrinfo(afai);
- goto free;
- }
-
- while (cur && cur->ai_next)
- cur = cur->ai_next;
- }
-
- freeaddrinfo(afai); /* afai must not be NULL at this point. */
-
- /* we must not have got any errors. */
- if (error != 0) /* just for diagnosis */
- abort();
-
- if (sentinel.ai_next) {
-good:
- *res = sentinel.ai_next;
- return(SUCCESS);
- } else {
- /*
- * All the process succeeded, but we've had an empty list.
- * This can happen if the given hints do not match our
- * candidates.
- */
- error = EAI_NONAME;
- }
-
-free:
-bad:
- if (sentinel.ai_next)
- freeaddrinfo(sentinel.ai_next);
- *res = NULL;
- return(error);
-}
-
-/*
- * FQDN hostname, DNS lookup
- */
-static int
-explore_fqdn(pai, hostname, servname, res)
- const struct addrinfo *pai;
- const char *hostname;
- const char *servname;
- struct addrinfo **res;
-{
- struct addrinfo *result;
- struct addrinfo *cur;
- struct net_data *net_data = init();
- struct irs_ho *ho;
- int error = 0;
- char tmp[NS_MAXDNAME];
- const char *cp;
-
- INSIST(res != NULL && *res == NULL);
-
- /*
- * if the servname does not match socktype/protocol, ignore it.
- */
- if (get_portmatch(pai, servname) != 0)
- return(0);
-
- if (!net_data || !(ho = net_data->ho))
- return(0);
-#if 0 /* XXX (notyet) */
- if (net_data->ho_stayopen && net_data->ho_last &&
- net_data->ho_last->h_addrtype == af) {
- if (ns_samename(name, net_data->ho_last->h_name) == 1)
- return (net_data->ho_last);
- for (hap = net_data->ho_last->h_aliases; hap && *hap; hap++)
- if (ns_samename(name, *hap) == 1)
- return (net_data->ho_last);
- }
-#endif
- if (!strchr(hostname, '.') &&
- (cp = res_hostalias(net_data->res, hostname,
- tmp, sizeof(tmp))))
- hostname = cp;
- result = (*ho->addrinfo)(ho, hostname, pai);
- if (!net_data->ho_stayopen) {
- (*ho->minimize)(ho);
- }
- if (result == NULL) {
- int e = h_errno;
-
- switch(e) {
- case NETDB_INTERNAL:
- error = EAI_SYSTEM;
- break;
- case TRY_AGAIN:
- error = EAI_AGAIN;
- break;
- case NO_RECOVERY:
- error = EAI_FAIL;
- break;
- case HOST_NOT_FOUND:
- case NO_DATA:
- error = EAI_NONAME;
- break;
- default:
- case NETDB_SUCCESS: /* should be impossible... */
- error = EAI_NONAME;
- break;
- }
- goto free;
- }
-
- for (cur = result; cur; cur = cur->ai_next) {
- GET_PORT(cur, servname); /* XXX: redundant lookups... */
- /* canonname should already be filled. */
- }
-
- *res = result;
-
- return(0);
-
-free:
- if (result)
- freeaddrinfo(result);
- return error;
-}
-
-static int
-explore_copy(pai, src0, res)
- const struct addrinfo *pai; /* seed */
- const struct addrinfo *src0; /* source */
- struct addrinfo **res;
-{
- int error;
- struct addrinfo sentinel, *cur;
- const struct addrinfo *src;
-
- error = 0;
- sentinel.ai_next = NULL;
- cur = &sentinel;
-
- for (src = src0; src != NULL; src = src->ai_next) {
- if (src->ai_family != pai->ai_family)
- continue;
-
- cur->ai_next = copy_ai(src);
- if (!cur->ai_next) {
- error = EAI_MEMORY;
- goto fail;
- }
-
- cur->ai_next->ai_socktype = pai->ai_socktype;
- cur->ai_next->ai_protocol = pai->ai_protocol;
- cur = cur->ai_next;
- }
-
- *res = sentinel.ai_next;
- return 0;
-
-fail:
- freeaddrinfo(sentinel.ai_next);
- return error;
-}
-
-/*
- * hostname == NULL.
- * passive socket -> anyaddr (0.0.0.0 or ::)
- * non-passive socket -> localhost (127.0.0.1 or ::1)
- */
-static int
-explore_null(pai, servname, res)
- const struct addrinfo *pai;
- const char *servname;
- struct addrinfo **res;
-{
- const struct afd *afd;
- struct addrinfo *cur;
- struct addrinfo sentinel;
- int error;
-
- *res = NULL;
- sentinel.ai_next = NULL;
- cur = &sentinel;
-
- afd = find_afd(pai->ai_family);
- if (afd == NULL)
- return 0;
-
- if (pai->ai_flags & AI_PASSIVE) {
- GET_AI(cur->ai_next, afd, afd->a_addrany);
- /* xxx meaningless?
- * GET_CANONNAME(cur->ai_next, "anyaddr");
- */
- GET_PORT(cur->ai_next, servname);
- } else {
- GET_AI(cur->ai_next, afd, afd->a_loopback);
- /* xxx meaningless?
- * GET_CANONNAME(cur->ai_next, "localhost");
- */
- GET_PORT(cur->ai_next, servname);
- }
- cur = cur->ai_next;
-
- *res = sentinel.ai_next;
- return 0;
-
-free:
- if (sentinel.ai_next)
- freeaddrinfo(sentinel.ai_next);
- return error;
-}
-
-/*
- * numeric hostname
- */
-static int
-explore_numeric(pai, hostname, servname, res)
- const struct addrinfo *pai;
- const char *hostname;
- const char *servname;
- struct addrinfo **res;
-{
- const struct afd *afd;
- struct addrinfo *cur;
- struct addrinfo sentinel;
- int error;
- char pton[PTON_MAX];
-
- *res = NULL;
- sentinel.ai_next = NULL;
- cur = &sentinel;
-
- afd = find_afd(pai->ai_family);
- if (afd == NULL)
- return 0;
-
- switch (afd->a_af) {
-#if 0 /*X/Open spec*/
- case AF_INET:
- if (inet_aton(hostname, (struct in_addr *)pton) == 1) {
- if (pai->ai_family == afd->a_af ||
- pai->ai_family == PF_UNSPEC /*?*/) {
- GET_AI(cur->ai_next, afd, pton);
- GET_PORT(cur->ai_next, servname);
- while (cur && cur->ai_next)
- cur = cur->ai_next;
- } else
- ERR(EAI_FAMILY); /*xxx*/
- }
- break;
-#endif
- default:
- if (inet_pton(afd->a_af, hostname, pton) == 1) {
- if (pai->ai_family == afd->a_af ||
- pai->ai_family == PF_UNSPEC /*?*/) {
- GET_AI(cur->ai_next, afd, pton);
- GET_PORT(cur->ai_next, servname);
- while (cur && cur->ai_next)
- cur = cur->ai_next;
- } else
- ERR(EAI_FAMILY); /*xxx*/
- }
- break;
- }
-
- *res = sentinel.ai_next;
- return 0;
-
-free:
-bad:
- if (sentinel.ai_next)
- freeaddrinfo(sentinel.ai_next);
- return error;
-}
-
-/*
- * numeric hostname with scope
- */
-static int
-explore_numeric_scope(pai, hostname, servname, res)
- const struct addrinfo *pai;
- const char *hostname;
- const char *servname;
- struct addrinfo **res;
-{
-#ifndef SCOPE_DELIMITER
- return explore_numeric(pai, hostname, servname, res);
-#else
- const struct afd *afd;
- struct addrinfo *cur;
- int error;
- char *cp, *hostname2 = NULL, *scope, *addr;
- struct sockaddr_in6 *sin6;
-
- afd = find_afd(pai->ai_family);
- if (afd == NULL)
- return 0;
-
- if (!afd->a_scoped)
- return explore_numeric(pai, hostname, servname, res);
-
- cp = strchr(hostname, SCOPE_DELIMITER);
- if (cp == NULL)
- return explore_numeric(pai, hostname, servname, res);
-
- /*
- * Handle special case of <scoped_address><delimiter><scope id>
- */
- hostname2 = strdup(hostname);
- if (hostname2 == NULL)
- return EAI_MEMORY;
- /* terminate at the delimiter */
- hostname2[cp - hostname] = '\0';
- addr = hostname2;
- scope = cp + 1;
-
- error = explore_numeric(pai, addr, servname, res);
- if (error == 0) {
- u_int32_t scopeid = 0;
-
- for (cur = *res; cur; cur = cur->ai_next) {
- if (cur->ai_family != AF_INET6)
- continue;
- sin6 = (struct sockaddr_in6 *)(void *)cur->ai_addr;
- if (!ip6_str2scopeid(scope, sin6, &scopeid)) {
- free(hostname2);
- return(EAI_NONAME); /* XXX: is return OK? */
- }
-#ifdef HAVE_SIN6_SCOPE_ID
- sin6->sin6_scope_id = scopeid;
-#endif
- }
- }
-
- free(hostname2);
-
- return error;
-#endif
-}
-
-static int
-get_canonname(pai, ai, str)
- const struct addrinfo *pai;
- struct addrinfo *ai;
- const char *str;
-{
- if ((pai->ai_flags & AI_CANONNAME) != 0) {
- ai->ai_canonname = (char *)malloc(strlen(str) + 1);
- if (ai->ai_canonname == NULL)
- return EAI_MEMORY;
- strcpy(ai->ai_canonname, str);
- }
- return 0;
-}
-
-static struct addrinfo *
-get_ai(pai, afd, addr)
- const struct addrinfo *pai;
- const struct afd *afd;
- const char *addr;
-{
- char *p;
- struct addrinfo *ai;
-
- ai = (struct addrinfo *)malloc(sizeof(struct addrinfo)
- + (afd->a_socklen));
- if (ai == NULL)
- return NULL;
-
- memcpy(ai, pai, sizeof(struct addrinfo));
- ai->ai_addr = (struct sockaddr *)(void *)(ai + 1);
- memset(ai->ai_addr, 0, (size_t)afd->a_socklen);
-#ifdef HAVE_SA_LEN
- ai->ai_addr->sa_len = afd->a_socklen;
-#endif
- ai->ai_addrlen = afd->a_socklen;
- ai->ai_addr->sa_family = ai->ai_family = afd->a_af;
- p = (char *)(void *)(ai->ai_addr);
- memcpy(p + afd->a_off, addr, (size_t)afd->a_addrlen);
- return ai;
-}
-
-/* XXX need to malloc() the same way we do from other functions! */
-static struct addrinfo *
-copy_ai(pai)
- const struct addrinfo *pai;
-{
- struct addrinfo *ai;
- size_t l;
-
- l = sizeof(*ai) + pai->ai_addrlen;
- if ((ai = (struct addrinfo *)malloc(l)) == NULL)
- return NULL;
- memset(ai, 0, l);
- memcpy(ai, pai, sizeof(*ai));
- ai->ai_addr = (struct sockaddr *)(void *)(ai + 1);
- memcpy(ai->ai_addr, pai->ai_addr, pai->ai_addrlen);
-
- if (pai->ai_canonname) {
- l = strlen(pai->ai_canonname) + 1;
- if ((ai->ai_canonname = malloc(l)) == NULL) {
- free(ai);
- return NULL;
- }
-#ifdef HAVE_STRLCPY
- strlcpy(ai->ai_canonname, pai->ai_canonname, l);
-#else
- strncpy(ai->ai_canonname, pai->ai_canonname, l);
-#endif
- } else {
- /* just to make sure */
- ai->ai_canonname = NULL;
- }
-
- ai->ai_next = NULL;
-
- return ai;
-}
-
-static int
-get_portmatch(const struct addrinfo *ai, const char *servname) {
-
- /* get_port does not touch first argument. when matchonly == 1. */
- /* LINTED const cast */
- return get_port((const struct addrinfo *)ai, servname, 1);
-}
-
-static int
-get_port(const struct addrinfo *ai, const char *servname, int matchonly) {
- const char *proto;
- struct servent *sp;
- int port;
- int allownumeric;
-
- if (servname == NULL)
- return 0;
- switch (ai->ai_family) {
- case AF_INET:
-#ifdef AF_INET6
- case AF_INET6:
-#endif
- break;
- default:
- return 0;
- }
-
- switch (ai->ai_socktype) {
- case SOCK_RAW:
- return EAI_SERVICE;
- case SOCK_DGRAM:
- case SOCK_STREAM:
- allownumeric = 1;
- break;
- case ANY:
- switch (ai->ai_family) {
- case AF_INET:
-#ifdef AF_INET6
- case AF_INET6:
-#endif
- allownumeric = 1;
- break;
- default:
- allownumeric = 0;
- break;
- }
- break;
- default:
- return EAI_SOCKTYPE;
- }
-
- if (str_isnumber(servname)) {
- if (!allownumeric)
- return EAI_SERVICE;
- port = atoi(servname);
- if (port < 0 || port > 65535)
- return EAI_SERVICE;
- port = htons(port);
- } else {
- switch (ai->ai_socktype) {
- case SOCK_DGRAM:
- proto = "udp";
- break;
- case SOCK_STREAM:
- proto = "tcp";
- break;
- default:
- proto = NULL;
- break;
- }
-
- if ((sp = getservbyname(servname, proto)) == NULL)
- return EAI_SERVICE;
- port = sp->s_port;
- }
-
- if (!matchonly) {
- switch (ai->ai_family) {
- case AF_INET:
- ((struct sockaddr_in *)(void *)
- ai->ai_addr)->sin_port = port;
- break;
- case AF_INET6:
- ((struct sockaddr_in6 *)(void *)
- ai->ai_addr)->sin6_port = port;
- break;
- }
- }
-
- return 0;
-}
-
-static const struct afd *
-find_afd(af)
- int af;
-{
- const struct afd *afd;
-
- if (af == PF_UNSPEC)
- return NULL;
- for (afd = afdl; afd->a_af; afd++) {
- if (afd->a_af == af)
- return afd;
- }
- return NULL;
-}
-
-/*
- * post-2553: AI_ADDRCONFIG check. if we use getipnodeby* as backend, backend
- * will take care of it.
- * the semantics of AI_ADDRCONFIG is not defined well. we are not sure
- * if the code is right or not.
- */
-static int
-addrconfig(af)
- int af;
-{
- int s;
-
- /* XXX errno */
- s = socket(af, SOCK_DGRAM, 0);
- if (s < 0) {
- if (errno != EMFILE)
- return 0;
- } else
- close(s);
- return 1;
-}
-
-/* convert a string to a scope identifier. XXX: IPv6 specific */
-static int
-ip6_str2scopeid(char *scope, struct sockaddr_in6 *sin6,
- u_int32_t *scopeidp)
-{
- u_int32_t scopeid;
- u_long lscopeid;
- struct in6_addr *a6 = &sin6->sin6_addr;
- char *ep;
-
- /* empty scopeid portion is invalid */
- if (*scope == '\0')
- return (0);
-
-#ifdef USE_IFNAMELINKID
- if (IN6_IS_ADDR_LINKLOCAL(a6) || IN6_IS_ADDR_MC_LINKLOCAL(a6)) {
- /*
- * Using interface names as link indices can be allowed
- * only when we can assume a one-to-one mappings between
- * links and interfaces. See comments in getnameinfo.c.
- */
- scopeid = if_nametoindex(scope);
- if (scopeid == 0)
- *scopeidp = scopeid;
- return (1);
- }
-#endif
-
- /* still unclear about literal, allow numeric only - placeholder */
- if (IN6_IS_ADDR_SITELOCAL(a6) || IN6_IS_ADDR_MC_SITELOCAL(a6))
- goto trynumeric;
- if (IN6_IS_ADDR_MC_ORGLOCAL(a6))
- goto trynumeric;
- else
- goto trynumeric; /* global */
-
- /* try to convert to a numeric id as a last resort */
-trynumeric:
- errno = 0;
- lscopeid = strtoul(scope, &ep, 10);
- scopeid = lscopeid & 0xffffffff;
- if (errno == 0 && ep && *ep == '\0' && scopeid == lscopeid) {
- *scopeidp = scopeid;
- return (1);
- } else
- return (0);
-}
-
-struct addrinfo *
-hostent2addrinfo(hp, pai)
- struct hostent *hp;
- const struct addrinfo *pai;
-{
- int i, af, error = 0;
- char **aplist = NULL, *ap;
- struct addrinfo sentinel, *cur;
- const struct afd *afd;
-
- af = hp->h_addrtype;
- if (pai->ai_family != AF_UNSPEC && af != pai->ai_family)
- return(NULL);
-
- afd = find_afd(af);
- if (afd == NULL)
- return(NULL);
-
- aplist = hp->h_addr_list;
-
- memset(&sentinel, 0, sizeof(sentinel));
- cur = &sentinel;
-
- for (i = 0; (ap = aplist[i]) != NULL; i++) {
-#if 0 /* the trick seems too much */
- af = hp->h_addr_list;
- if (af == AF_INET6 &&
- IN6_IS_ADDR_V4MAPPED((struct in6_addr *)ap)) {
- af = AF_INET;
- ap = ap + sizeof(struct in6_addr)
- - sizeof(struct in_addr);
- }
- afd = find_afd(af);
- if (afd == NULL)
- continue;
-#endif /* 0 */
-
- GET_AI(cur->ai_next, afd, ap);
-
- /* GET_PORT(cur->ai_next, servname); */
- if ((pai->ai_flags & AI_CANONNAME) != 0) {
- /*
- * RFC2553 says that ai_canonname will be set only for
- * the first element. we do it for all the elements,
- * just for convenience.
- */
- GET_CANONNAME(cur->ai_next, hp->h_name);
- }
- while (cur && cur->ai_next) /* no need to loop, actually. */
- cur = cur->ai_next;
- continue;
-
- free:
- if (cur->ai_next)
- freeaddrinfo(cur->ai_next);
- cur->ai_next = NULL;
- /* continue, without tht pointer CUR advanced. */
- }
-
- return(sentinel.ai_next);
-}
-
-struct addrinfo *
-addr2addrinfo(pai, cp)
- const struct addrinfo *pai;
- const char *cp;
-{
- const struct afd *afd;
-
- afd = find_afd(pai->ai_family);
- if (afd == NULL)
- return(NULL);
-
- return(get_ai(pai, afd, cp));
-}
-
-static struct net_data *
-init()
-{
- struct net_data *net_data;
-
- if (!(net_data = net_data_init(NULL)))
- goto error;
- if (!net_data->ho) {
- net_data->ho = (*net_data->irs->ho_map)(net_data->irs);
- if (!net_data->ho || !net_data->res) {
-error:
- errno = EIO;
- if (net_data && net_data->res)
- RES_SET_H_ERRNO(net_data->res, NETDB_INTERNAL);
- return (NULL);
- }
-
- (*net_data->ho->res_set)(net_data->ho, net_data->res, NULL);
- }
-
- return (net_data);
-}
diff --git a/contrib/bind/lib/irs/getgrent.c b/contrib/bind/lib/irs/getgrent.c
deleted file mode 100644
index f6eea13..0000000
--- a/contrib/bind/lib/irs/getgrent.c
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- * Copyright (c) 1996-1999 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.
- */
-
-#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: getgrent.c,v 1.20 2001/05/29 05:48:41 marka Exp $";
-#endif
-
-/* Imports */
-
-#include "port_before.h"
-
-#if !defined(WANT_IRS_GR) || defined(__BIND_NOSTATIC)
-static int __bind_irs_gr_unneeded;
-#else
-
-#include <sys/types.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-
-#include <errno.h>
-#include <grp.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_data.h"
-
-/* Forward */
-
-static struct net_data *init(void);
-void endgrent(void);
-
-/* Public */
-
-struct group *
-getgrent() {
- struct net_data *net_data = init();
-
- return (getgrent_p(net_data));
-}
-
-struct group *
-getgrnam(const char *name) {
- struct net_data *net_data = init();
-
- return (getgrnam_p(name, net_data));
-}
-
-struct group *
-getgrgid(gid_t gid) {
- struct net_data *net_data = init();
-
- return (getgrgid_p(gid, net_data));
-}
-
-int
-setgroupent(int stayopen) {
- struct net_data *net_data = init();
-
- return (setgroupent_p(stayopen, net_data));
-}
-
-#ifdef SETGRENT_VOID
-void
-setgrent(void) {
- struct net_data *net_data = init();
-
- setgrent_p(net_data);
-}
-#else
-int
-setgrent(void) {
- struct net_data *net_data = init();
-
- return (setgrent_p(net_data));
-}
-#endif /* SETGRENT_VOID */
-
-void
-endgrent() {
- struct net_data *net_data = init();
-
- endgrent_p(net_data);
-}
-
-int
-getgrouplist(GETGROUPLIST_ARGS) {
- struct net_data *net_data = init();
-
- return (getgrouplist_p(name, basegid, groups, ngroups, net_data));
-}
-
-/* Shared private. */
-
-struct group *
-getgrent_p(struct net_data *net_data) {
- struct irs_gr *gr;
-
- if (!net_data || !(gr = net_data->gr))
- return (NULL);
- net_data->gr_last = (*gr->next)(gr);
- return (net_data->gr_last);
-}
-
-struct group *
-getgrnam_p(const char *name, struct net_data *net_data) {
- struct irs_gr *gr;
-
- if (!net_data || !(gr = net_data->gr))
- return (NULL);
- if (net_data->gr_stayopen && net_data->gr_last &&
- !strcmp(net_data->gr_last->gr_name, name))
- return (net_data->gr_last);
- net_data->gr_last = (*gr->byname)(gr, name);
- if (!net_data->gr_stayopen)
- endgrent();
- return (net_data->gr_last);
-}
-
-struct group *
-getgrgid_p(gid_t gid, struct net_data *net_data) {
- struct irs_gr *gr;
-
- if (!net_data || !(gr = net_data->gr))
- return (NULL);
- if (net_data->gr_stayopen && net_data->gr_last &&
- (gid_t)net_data->gr_last->gr_gid == gid)
- return (net_data->gr_last);
- net_data->gr_last = (*gr->bygid)(gr, gid);
- if (!net_data->gr_stayopen)
- endgrent();
- return (net_data->gr_last);
-}
-
-int
-setgroupent_p(int stayopen, struct net_data *net_data) {
- struct irs_gr *gr;
-
- if (!net_data || !(gr = net_data->gr))
- return (0);
- (*gr->rewind)(gr);
- net_data->gr_stayopen = (stayopen != 0);
- if (stayopen == 0)
- net_data_minimize(net_data);
- return (1);
-}
-
-#ifdef SETGRENT_VOID
-void
-setgrent_p(struct net_data *net_data) {
- (void)setgroupent_p(0, net_data);
-}
-#else
-int
-setgrent_p(struct net_data *net_data) {
- return (setgroupent_p(0, net_data));
-}
-#endif /* SETGRENT_VOID */
-
-void
-endgrent_p(struct net_data *net_data) {
- struct irs_gr *gr;
-
- if ((net_data != NULL) && ((gr = net_data->gr) != NULL))
- (*gr->minimize)(gr);
-}
-
-int
-getgrouplist_p(const char *name, gid_t basegid, gid_t *groups, int *ngroups,
- struct net_data *net_data) {
- struct irs_gr *gr;
-
- if (!net_data || !(gr = net_data->gr)) {
- *ngroups = 0;
- return (-1);
- }
- return ((*gr->list)(gr, name, basegid, groups, ngroups));
-}
-
-/* Private */
-
-static struct net_data *
-init() {
- struct net_data *net_data;
-
- if (!(net_data = net_data_init(NULL)))
- goto error;
- if (!net_data->gr) {
- net_data->gr = (*net_data->irs->gr_map)(net_data->irs);
-
- if (!net_data->gr || !net_data->res) {
- error:
- errno = EIO;
- return (NULL);
- }
- (*net_data->gr->res_set)(net_data->gr, net_data->res,
- NULL);
- }
-
- return (net_data);
-}
-
-#endif /* WANT_IRS_GR */
diff --git a/contrib/bind/lib/irs/getgrent_r.c b/contrib/bind/lib/irs/getgrent_r.c
deleted file mode 100644
index 641a2b2..0000000
--- a/contrib/bind/lib/irs/getgrent_r.c
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
- * Copyright (c) 1998-1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: getgrent_r.c,v 8.7 2001/11/01 08:02:08 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include <port_before.h>
-#if !defined(_REENTRANT) || !defined(DO_PTHREADS) || !defined(WANT_IRS_PW)
- static int getgrent_r_not_required = 0;
-#else
-#include <errno.h>
-#include <string.h>
-#include <stdio.h>
-#include <sys/types.h>
-#if (defined(POSIX_GETGRNAM_R) || defined(POSIX_GETGRGID_R)) && \
- defined(_POSIX_PTHREAD_SEMANTICS)
- /* turn off solaris remapping in <grp.h> */
-#define _UNIX95
-#undef _POSIX_PTHREAD_SEMANTICS
-#include <grp.h>
-#define _POSIX_PTHREAD_SEMANTICS 1
-#else
-#include <grp.h>
-#endif
-#include <sys/param.h>
-#include <port_after.h>
-
-#ifdef GROUP_R_RETURN
-
-static int
-copy_group(struct group *, struct group *, char *buf, int buflen);
-
-/* POSIX 1003.1c */
-#ifdef POSIX_GETGRNAM_R
-int
-__posix_getgrnam_r(const char *name, struct group *gptr,
- char *buf, int buflen, struct group **result) {
-#else
-int
-getgrnam_r(const char *name, struct group *gptr,
- char *buf, size_t buflen, struct group **result) {
-#endif
- struct group *ge = getgrnam(name);
- int res;
-
- if (ge == NULL) {
- *result = NULL;
- return (0);
- }
-
- res = copy_group(ge, gptr, buf, buflen);
- *result = res ? NULL : gptr;
- return (res);
-}
-
-#ifdef POSIX_GETGRNAM_R
-struct group *
-getgrnam_r(const char *name, struct group *gptr,
- char *buf, int buflen) {
- struct group *ge = getgrnam(name);
- int res;
-
- if (ge == NULL)
- return (NULL);
- res = copy_group(ge, gptr, buf, buflen);
- return (res ? NULL : gptr);
-}
-#endif /* POSIX_GETGRNAM_R */
-
-/* POSIX 1003.1c */
-#ifdef POSIX_GETGRGID_R
-int
-__posix_getgrgid_r(gid_t gid, struct group *gptr,
- char *buf, int buflen, struct group **result) {
-#else /* POSIX_GETGRGID_R */
-int
-getgrgid_r(gid_t gid, struct group *gptr,
- char *buf, size_t buflen, struct group **result) {
-#endif /* POSIX_GETGRGID_R */
- struct group *ge = getgrgid(gid);
- int res;
-
- if (ge == NULL) {
- *result = NULL;
- return (0);
- }
-
- res = copy_group(ge, gptr, buf, buflen);
- *result = res ? NULL : gptr;
- return (res);
-}
-
-#ifdef POSIX_GETGRGID_R
-struct group *
-getgrgid_r(gid_t gid, struct group *gptr,
- char *buf, int buflen) {
- struct group *ge = getgrgid(gid);
- int res;
-
- if (ge == NULL)
- return (NULL);
-
- res = copy_group(ge, gptr, buf, buflen);
- return (res ? NULL : gptr);
-}
-#endif
-
-/*
- * These assume a single context is in operation per thread.
- * If this is not the case we will need to call irs directly
- * rather than through the base functions.
- */
-
-GROUP_R_RETURN
-getgrent_r(struct group *gptr, GROUP_R_ARGS) {
- struct group *ge = getgrent();
- int res;
-
- if (ge == NULL) {
- return (GROUP_R_BAD);
- }
-
- res = copy_group(ge, gptr, buf, buflen);
- return (res ? GROUP_R_BAD : GROUP_R_OK);
-}
-
-GROUP_R_SET_RETURN
-setgrent_r(GROUP_R_ENT_ARGS) {
-
- setgrent();
-#ifdef GROUP_R_SET_RESULT
- return (GROUP_R_SET_RESULT);
-#endif
-}
-
-GROUP_R_END_RETURN
-endgrent_r(GROUP_R_ENT_ARGS) {
-
- endgrent();
- GROUP_R_END_RESULT(GROUP_R_OK);
-}
-
-
-#if 0
- /* XXX irs does not have a fgetgrent() */
-GROUP_R_RETURN
-fgetgrent_r(FILE *f, struct group *gptr, GROUP_R_ARGS) {
- struct group *ge = fgetgrent(f);
- int res;
-
- if (ge == NULL)
- return (GROUP_R_BAD);
-
- res = copy_group(ge, gptr, buf, buflen);
- return (res ? GROUP_R_BAD : GROUP_R_OK);
-}
-#endif
-
-/* Private */
-
-static int
-copy_group(struct group *ge, struct group *gptr, char *buf, int buflen) {
- char *cp;
- int i, n;
- int numptr, len;
-
- /* Find out the amount of space required to store the answer. */
- numptr = 1; /* NULL ptr */
- len = (char *)ALIGN(buf) - buf;
- for (i = 0; ge->gr_mem[i]; i++, numptr++) {
- len += strlen(ge->gr_mem[i]) + 1;
- }
- len += strlen(ge->gr_name) + 1;
- len += strlen(ge->gr_passwd) + 1;
- len += numptr * sizeof(char*);
-
- if (len > buflen) {
- errno = ERANGE;
- return (ERANGE);
- }
-
- /* copy group id */
- gptr->gr_gid = ge->gr_gid;
-
- cp = (char *)ALIGN(buf) + numptr * sizeof(char *);
-
- /* copy official name */
- n = strlen(ge->gr_name) + 1;
- strcpy(cp, ge->gr_name);
- gptr->gr_name = cp;
- cp += n;
-
- /* copy member list */
- gptr->gr_mem = (char **)ALIGN(buf);
- for (i = 0 ; ge->gr_mem[i]; i++) {
- n = strlen(ge->gr_mem[i]) + 1;
- strcpy(cp, ge->gr_mem[i]);
- gptr->gr_mem[i] = cp;
- cp += n;
- }
- gptr->gr_mem[i] = NULL;
-
- /* copy password */
- n = strlen(ge->gr_passwd) + 1;
- strcpy(cp, ge->gr_passwd);
- gptr->gr_passwd = cp;
- cp += n;
-
- return (0);
-}
-#else /* GROUP_R_RETURN */
- static int getgrent_r_unknown_system = 0;
-#endif /* GROUP_R_RETURN */
-#endif /* !def(_REENTRANT) || !def(DO_PTHREADS) || !def(WANT_IRS_PW) */
diff --git a/contrib/bind/lib/irs/gethostent.c b/contrib/bind/lib/irs/gethostent.c
deleted file mode 100644
index 3964b5f..0000000
--- a/contrib/bind/lib/irs/gethostent.c
+++ /dev/null
@@ -1,1069 +0,0 @@
-/*
- * Copyright (c) 1996-1999 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.
- */
-
-#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: gethostent.c,v 1.32.10.2 2003/06/04 01:09:43 marka Exp $";
-#endif
-
-/* Imports */
-
-#include "port_before.h"
-
-#if !defined(__BIND_NOSTATIC)
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#include <netinet/in.h>
-#include <net/if.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <netdb.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <irs.h>
-#include <isc/memcluster.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "irs_data.h"
-
-/* Definitions */
-
-struct pvt {
- char * aliases[1];
- char * addrs[2];
- char addr[NS_IN6ADDRSZ];
- char name[NS_MAXDNAME + 1];
- struct hostent host;
-};
-
-/* Forward */
-
-static struct net_data *init(void);
-static void freepvt(struct net_data *);
-static struct hostent *fakeaddr(const char *, int, struct net_data *);
-
-
-/* Public */
-
-struct hostent *
-gethostbyname(const char *name) {
- struct net_data *net_data = init();
-
- return (gethostbyname_p(name, net_data));
-}
-
-struct hostent *
-gethostbyname2(const char *name, int af) {
- struct net_data *net_data = init();
-
- return (gethostbyname2_p(name, af, net_data));
-}
-
-struct hostent *
-gethostbyaddr(const char *addr, int len, int af) {
- struct net_data *net_data = init();
-
- return (gethostbyaddr_p(addr, len, af, net_data));
-}
-
-struct hostent *
-gethostent() {
- struct net_data *net_data = init();
-
- return (gethostent_p(net_data));
-}
-
-void
-sethostent(int stayopen) {
- struct net_data *net_data = init();
- sethostent_p(stayopen, net_data);
-}
-
-
-void
-endhostent() {
- struct net_data *net_data = init();
- endhostent_p(net_data);
-}
-
-/* Shared private. */
-
-struct hostent *
-gethostbyname_p(const char *name, struct net_data *net_data) {
- struct hostent *hp;
-
- if (!net_data)
- return (NULL);
-
- if (net_data->res->options & RES_USE_INET6) {
- hp = gethostbyname2_p(name, AF_INET6, net_data);
- if (hp)
- return (hp);
- }
- return (gethostbyname2_p(name, AF_INET, net_data));
-}
-
-struct hostent *
-gethostbyname2_p(const char *name, int af, struct net_data *net_data) {
- struct irs_ho *ho;
- char tmp[NS_MAXDNAME];
- struct hostent *hp;
- const char *cp;
- char **hap;
-
- if (!net_data || !(ho = net_data->ho))
- return (NULL);
- if (net_data->ho_stayopen && net_data->ho_last &&
- net_data->ho_last->h_addrtype == af) {
- if (ns_samename(name, net_data->ho_last->h_name) == 1)
- return (net_data->ho_last);
- for (hap = net_data->ho_last->h_aliases; hap && *hap; hap++)
- if (ns_samename(name, *hap) == 1)
- return (net_data->ho_last);
- }
- if (!strchr(name, '.') && (cp = res_hostalias(net_data->res, name,
- tmp, sizeof tmp)))
- name = cp;
- if ((hp = fakeaddr(name, af, net_data)) != NULL)
- return (hp);
- net_data->ho_last = (*ho->byname2)(ho, name, af);
- if (!net_data->ho_stayopen)
- endhostent();
- return (net_data->ho_last);
-}
-
-struct hostent *
-gethostbyaddr_p(const char *addr, int len, int af, struct net_data *net_data) {
- struct irs_ho *ho;
- char **hap;
-
- if (!net_data || !(ho = net_data->ho))
- return (NULL);
- if (net_data->ho_stayopen && net_data->ho_last &&
- net_data->ho_last->h_length == len)
- for (hap = net_data->ho_last->h_addr_list;
- hap && *hap;
- hap++)
- if (!memcmp(addr, *hap, len))
- return (net_data->ho_last);
- net_data->ho_last = (*ho->byaddr)(ho, addr, len, af);
- if (!net_data->ho_stayopen)
- endhostent();
- return (net_data->ho_last);
-}
-
-
-struct hostent *
-gethostent_p(struct net_data *net_data) {
- struct irs_ho *ho;
- struct hostent *hp;
-
- if (!net_data || !(ho = net_data->ho))
- return (NULL);
- while ((hp = (*ho->next)(ho)) != NULL &&
- hp->h_addrtype == AF_INET6 &&
- (net_data->res->options & RES_USE_INET6) == 0)
- continue;
- net_data->ho_last = hp;
- return (net_data->ho_last);
-}
-
-
-void
-sethostent_p(int stayopen, struct net_data *net_data) {
- struct irs_ho *ho;
-
- if (!net_data || !(ho = net_data->ho))
- return;
- freepvt(net_data);
- (*ho->rewind)(ho);
- net_data->ho_stayopen = (stayopen != 0);
- if (stayopen == 0)
- net_data_minimize(net_data);
-}
-
-void
-endhostent_p(struct net_data *net_data) {
- struct irs_ho *ho;
-
- if ((net_data != NULL) && ((ho = net_data->ho) != NULL))
- (*ho->minimize)(ho);
-}
-
-#ifndef IN6_IS_ADDR_V4COMPAT
-static const unsigned char in6addr_compat[12] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-#define IN6_IS_ADDR_V4COMPAT(x) (!memcmp((x)->s6_addr, in6addr_compat, 12) && \
- ((x)->s6_addr[12] != 0 || \
- (x)->s6_addr[13] != 0 || \
- (x)->s6_addr[14] != 0 || \
- ((x)->s6_addr[15] != 0 && \
- (x)->s6_addr[15] != 1)))
-#endif
-#ifndef IN6_IS_ADDR_V4MAPPED
-#define IN6_IS_ADDR_V4MAPPED(x) (!memcmp((x)->s6_addr, in6addr_mapped, 12))
-#endif
-
-static const unsigned char in6addr_mapped[12] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff };
-
-static int scan_interfaces(int *, int *);
-static struct hostent *copyandmerge(struct hostent *, struct hostent *, int, int *);
-
-/*
- * Public functions
- */
-
-/*
- * AI_V4MAPPED + AF_INET6
- * If no IPv6 address then a query for IPv4 and map returned values.
- *
- * AI_ALL + AI_V4MAPPED + AF_INET6
- * Return IPv6 and IPv4 mapped.
- *
- * AI_ADDRCONFIG
- * Only return IPv6 / IPv4 address if there is an interface of that
- * type active.
- */
-
-struct hostent *
-getipnodebyname(const char *name, int af, int flags, int *error_num) {
- int have_v4 = 1, have_v6 = 1;
- struct in_addr in4;
- struct in6_addr in6;
- struct hostent he, *he1 = NULL, *he2 = NULL, *he3;
- int v4 = 0, v6 = 0;
- struct net_data *net_data = init();
- u_long options;
- int tmp_err;
-
- if (net_data == NULL) {
- *error_num = NO_RECOVERY;
- return (NULL);
- }
-
- /* If we care about active interfaces then check. */
- if ((flags & AI_ADDRCONFIG) != 0)
- if (scan_interfaces(&have_v4, &have_v6) == -1) {
- *error_num = NO_RECOVERY;
- return (NULL);
- }
-
- /* Check for literal address. */
- if ((v4 = inet_pton(AF_INET, name, &in4)) != 1)
- v6 = inet_pton(AF_INET6, name, &in6);
-
- /* Impossible combination? */
-
- if ((af == AF_INET6 && (flags & AI_V4MAPPED) == 0 && v4 == 1) ||
- (af == AF_INET && v6 == 1) ||
- (have_v4 == 0 && v4 == 1) ||
- (have_v6 == 0 && v6 == 1) ||
- (have_v4 == 0 && af == AF_INET) ||
- (have_v6 == 0 && af == AF_INET6)) {
- *error_num = HOST_NOT_FOUND;
- return (NULL);
- }
-
- /* Literal address? */
- if (v4 == 1 || v6 == 1) {
- char *addr_list[2];
- char *aliases[1];
-
- DE_CONST(name, he.h_name);
- he.h_addr_list = addr_list;
- he.h_addr_list[0] = (v4 == 1) ? (char *)&in4 : (char *)&in6;
- he.h_addr_list[1] = NULL;
- he.h_aliases = aliases;
- he.h_aliases[0] = NULL;
- he.h_length = (v4 == 1) ? INADDRSZ : IN6ADDRSZ;
- he.h_addrtype = (v4 == 1) ? AF_INET : AF_INET6;
- return (copyandmerge(&he, NULL, af, error_num));
- }
-
- options = net_data->res->options;
- net_data->res->options &= ~RES_USE_INET6;
-
- tmp_err = NO_RECOVERY;
- if (have_v6 && af == AF_INET6) {
- he2 = gethostbyname2_p(name, AF_INET6, net_data);
- if (he2 != NULL) {
- he1 = copyandmerge(he2, NULL, af, error_num);
- if (he1 == NULL)
- return (NULL);
- he2 = NULL;
- } else {
- tmp_err = net_data->res->res_h_errno;
- }
- }
-
- if (have_v4 &&
- ((af == AF_INET) ||
- (af == AF_INET6 && (flags & AI_V4MAPPED) != 0 &&
- (he1 == NULL || (flags & AI_ALL) != 0)))) {
- he2 = gethostbyname2_p(name, AF_INET, net_data);
- if (he1 == NULL && he2 == NULL) {
- *error_num = net_data->res->res_h_errno;
- return (NULL);
- }
- } else
- *error_num = tmp_err;
-
- net_data->res->options = options;
-
- he3 = copyandmerge(he1, he2, af, error_num);
-
- if (he1 != NULL)
- freehostent(he1);
- return (he3);
-}
-
-struct hostent *
-getipnodebyaddr(const void *src, size_t len, int af, int *error_num) {
- struct hostent *he1, *he2;
- struct net_data *net_data = init();
-
- /* Sanity Checks. */
- if (src == NULL) {
- *error_num = NO_RECOVERY;
- return (NULL);
- }
-
- switch (af) {
- case AF_INET:
- if (len != INADDRSZ) {
- *error_num = NO_RECOVERY;
- return (NULL);
- }
- break;
- case AF_INET6:
- if (len != IN6ADDRSZ) {
- *error_num = NO_RECOVERY;
- return (NULL);
- }
- break;
- default:
- *error_num = NO_RECOVERY;
- return (NULL);
- }
-
- /*
- * Lookup IPv4 and IPv4 mapped/compatible addresses
- */
- if ((af == AF_INET6 &&
- IN6_IS_ADDR_V4COMPAT((const struct in6_addr *)src)) ||
- (af == AF_INET6 &&
- IN6_IS_ADDR_V4MAPPED((const struct in6_addr *)src)) ||
- (af == AF_INET)) {
- const char *cp = src;
-
- if (af == AF_INET6)
- cp += 12;
- he1 = gethostbyaddr_p(cp, 4, AF_INET, net_data);
- if (he1 == NULL) {
- *error_num = net_data->res->res_h_errno;
- return (NULL);
- }
- he2 = copyandmerge(he1, NULL, af, error_num);
- if (he2 == NULL)
- return (NULL);
- /*
- * Restore original address if mapped/compatible.
- */
- if (af == AF_INET6)
- memcpy(he1->h_addr, src, len);
- return (he2);
- }
-
- /*
- * Lookup IPv6 address.
- */
- if (memcmp((const struct in6_addr *)src, &in6addr_any, 16) == 0) {
- *error_num = HOST_NOT_FOUND;
- return (NULL);
- }
-
- he1 = gethostbyaddr_p(src, 16, AF_INET6, net_data);
- if (he1 == NULL) {
- *error_num = net_data->res->res_h_errno;
- return (NULL);
- }
- return (copyandmerge(he1, NULL, af, error_num));
-}
-
-void
-freehostent(struct hostent *he) {
- char **cpp;
- int names = 1;
- int addresses = 1;
-
- memput(he->h_name, strlen(he->h_name) + 1);
-
- cpp = he->h_addr_list;
- while (*cpp != NULL) {
- memput(*cpp, (he->h_addrtype == AF_INET) ?
- INADDRSZ : IN6ADDRSZ);
- *cpp = NULL;
- cpp++;
- addresses++;
- }
-
- cpp = he->h_aliases;
- while (*cpp != NULL) {
- memput(*cpp, strlen(*cpp) + 1);
- cpp++;
- names++;
- }
-
- memput(he->h_aliases, sizeof(char *) * (names));
- memput(he->h_addr_list, sizeof(char *) * (addresses));
- memput(he, sizeof *he);
-}
-
-/*
- * Private
- */
-
-/*
- * Scan the interface table and set have_v4 and have_v6 depending
- * upon whether there are IPv4 and IPv6 interface addresses.
- *
- * Returns:
- * 0 on success
- * -1 on failure.
- */
-
-#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR) && \
- !defined(IRIX_EMUL_IOCTL_SIOCGIFCONF)
-
-#ifdef __hpux
-#define lifc_len iflc_len
-#define lifc_buf iflc_buf
-#define lifc_req iflc_req
-#define LIFCONF if_laddrconf
-#else
-#define SETFAMILYFLAGS
-#define LIFCONF lifconf
-#endif
-
-#ifdef __hpux
-#define lifr_addr iflr_addr
-#define lifr_name iflr_name
-#define lifr_dstaddr iflr_dstaddr
-#define lifr_flags iflr_flags
-#define ss_family sa_family
-#define LIFREQ if_laddrreq
-#else
-#define LIFREQ lifreq
-#endif
-
-static void
-scan_interfaces6(int *have_v4, int *have_v6) {
- struct LIFCONF lifc;
- struct LIFREQ lifreq;
- struct in_addr in4;
- struct in6_addr in6;
- char *buf = NULL, *cp, *cplim;
- static unsigned int bufsiz = 4095;
- int s, cpsize, n;
-
- /* Get interface list from system. */
- if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) == -1)
- goto cleanup;
-
- /*
- * Grow buffer until large enough to contain all interface
- * descriptions.
- */
- for (;;) {
- buf = memget(bufsiz);
- if (buf == NULL)
- goto cleanup;
-#ifdef SETFAMILYFLAGS
- lifc.lifc_family = AF_UNSPEC; /* request all families */
- lifc.lifc_flags = 0;
-#endif
- lifc.lifc_len = bufsiz;
- lifc.lifc_buf = buf;
- if ((n = ioctl(s, SIOCGLIFCONF, (char *)&lifc)) != -1) {
- /*
- * Some OS's just return what will fit rather
- * than set EINVAL if the buffer is too small
- * to fit all the interfaces in. If
- * lifc.lifc_len is too near to the end of the
- * buffer we will grow it just in case and
- * retry.
- */
- if (lifc.lifc_len + 2 * sizeof(lifreq) < bufsiz)
- break;
- }
- if ((n == -1) && errno != EINVAL)
- goto cleanup;
-
- if (bufsiz > 1000000)
- goto cleanup;
-
- memput(buf, bufsiz);
- bufsiz += 4096;
- }
-
- /* Parse system's interface list. */
- cplim = buf + lifc.lifc_len; /* skip over if's with big ifr_addr's */
- for (cp = buf;
- (*have_v4 == 0 || *have_v6 == 0) && cp < cplim;
- cp += cpsize) {
- memcpy(&lifreq, cp, sizeof lifreq);
-#ifdef HAVE_SA_LEN
-#ifdef FIX_ZERO_SA_LEN
- if (lifreq.lifr_addr.sa_len == 0)
- lifreq.lifr_addr.sa_len = 16;
-#endif
-#ifdef HAVE_MINIMUM_IFREQ
- cpsize = sizeof lifreq;
- if (lifreq.lifr_addr.sa_len > sizeof (struct sockaddr))
- cpsize += (int)lifreq.lifr_addr.sa_len -
- (int)(sizeof (struct sockaddr));
-#else
- cpsize = sizeof lifreq.lifr_name + lifreq.lifr_addr.sa_len;
-#endif /* HAVE_MINIMUM_IFREQ */
-#elif defined SIOCGIFCONF_ADDR
- cpsize = sizeof lifreq;
-#else
- cpsize = sizeof lifreq.lifr_name;
- /* XXX maybe this should be a hard error? */
- if (ioctl(s, SIOCGLIFADDR, (char *)&lifreq) < 0)
- continue;
-#endif
- switch (lifreq.lifr_addr.ss_family) {
- case AF_INET:
- if (*have_v4 == 0) {
- memcpy(&in4,
- &((struct sockaddr_in *)
- &lifreq.lifr_addr)->sin_addr,
- sizeof in4);
- if (in4.s_addr == INADDR_ANY)
- break;
- n = ioctl(s, SIOCGLIFFLAGS, (char *)&lifreq);
- if (n < 0)
- break;
- if ((lifreq.lifr_flags & IFF_UP) == 0)
- break;
- *have_v4 = 1;
- }
- break;
- case AF_INET6:
- if (*have_v6 == 0) {
- memcpy(&in6,
- &((struct sockaddr_in6 *)
- &lifreq.lifr_addr)->sin6_addr, sizeof in6);
- if (memcmp(&in6, &in6addr_any, sizeof in6) == 0)
- break;
- n = ioctl(s, SIOCGLIFFLAGS, (char *)&lifreq);
- if (n < 0)
- break;
- if ((lifreq.lifr_flags & IFF_UP) == 0)
- break;
- *have_v6 = 1;
- }
- break;
- }
- }
- if (buf != NULL)
- memput(buf, bufsiz);
- close(s);
- /* printf("scan interface -> 4=%d 6=%d\n", *have_v4, *have_v6); */
- return;
- cleanup:
- if (buf != NULL)
- memput(buf, bufsiz);
- if (s != -1)
- close(s);
- /* printf("scan interface -> 4=%d 6=%d\n", *have_v4, *have_v6); */
- return;
-}
-#endif
-
-#ifdef __linux
-#ifndef IF_NAMESIZE
-# ifdef IFNAMSIZ
-# define IF_NAMESIZE IFNAMSIZ
-# else
-# define IF_NAMESIZE 16
-# endif
-#endif
-static void
-scan_linux6(int *have_v6) {
- FILE *proc = NULL;
- char address[33];
- char name[IF_NAMESIZE+1];
- int ifindex, prefix, flag3, flag4;
-
- proc = fopen("/proc/net/if_inet6", "r");
- if (proc == NULL)
- return;
-
- if (fscanf(proc, "%32[a-f0-9] %x %x %x %x %16s\n",
- address, &ifindex, &prefix, &flag3, &flag4, name) == 6)
- *have_v6 = 1;
- fclose(proc);
- return;
-}
-#endif
-
-static int
-scan_interfaces(int *have_v4, int *have_v6) {
- struct ifconf ifc;
- union {
- char _pad[256]; /* leave space for IPv6 addresses */
- struct ifreq ifreq;
- } u;
- struct in_addr in4;
- struct in6_addr in6;
- char *buf = NULL, *cp, *cplim;
- static unsigned int bufsiz = 4095;
- int s, n;
- size_t cpsize;
-
- /* Set to zero. Used as loop terminators below. */
- *have_v4 = *have_v6 = 0;
-
-#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR) && \
- !defined(IRIX_EMUL_IOCTL_SIOCGIFCONF)
- /*
- * Try to scan the interfaces using IPv6 ioctls().
- */
- scan_interfaces6(have_v4, have_v6);
- if (*have_v4 != 0 && *have_v6 != 0)
- return (0);
-#endif
-#ifdef __linux
- scan_linux6(have_v6);
-#endif
-
- /* Get interface list from system. */
- if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
- goto err_ret;
-
- /*
- * Grow buffer until large enough to contain all interface
- * descriptions.
- */
- for (;;) {
- buf = memget(bufsiz);
- if (buf == NULL)
- goto err_ret;
- ifc.ifc_len = bufsiz;
- ifc.ifc_buf = buf;
-#ifdef IRIX_EMUL_IOCTL_SIOCGIFCONF
- /*
- * This is a fix for IRIX OS in which the call to ioctl with
- * the flag SIOCGIFCONF may not return an entry for all the
- * interfaces like most flavors of Unix.
- */
- if (emul_ioctl(&ifc) >= 0)
- break;
-#else
- if ((n = ioctl(s, SIOCGIFCONF, (char *)&ifc)) != -1) {
- /*
- * Some OS's just return what will fit rather
- * than set EINVAL if the buffer is too small
- * to fit all the interfaces in. If
- * ifc.ifc_len is too near to the end of the
- * buffer we will grow it just in case and
- * retry.
- */
- if (ifc.ifc_len + 2 * sizeof(u.ifreq) < bufsiz)
- break;
- }
-#endif
- if ((n == -1) && errno != EINVAL)
- goto err_ret;
-
- if (bufsiz > 1000000)
- goto err_ret;
-
- memput(buf, bufsiz);
- bufsiz += 4096;
- }
-
- /* Parse system's interface list. */
- cplim = buf + ifc.ifc_len; /* skip over if's with big ifr_addr's */
- for (cp = buf;
- (*have_v4 == 0 || *have_v6 == 0) && cp < cplim;
- cp += cpsize) {
- memcpy(&u.ifreq, cp, sizeof u.ifreq);
-#ifdef HAVE_SA_LEN
-#ifdef FIX_ZERO_SA_LEN
- if (u.ifreq.ifr_addr.sa_len == 0)
- u.ifreq.ifr_addr.sa_len = 16;
-#endif
-#ifdef HAVE_MINIMUM_IFREQ
- cpsize = sizeof u.ifreq;
- if (u.ifreq.ifr_addr.sa_len > sizeof (struct sockaddr))
- cpsize += (int)u.ifreq.ifr_addr.sa_len -
- (int)(sizeof (struct sockaddr));
-#else
- cpsize = sizeof u.ifreq.ifr_name + u.ifreq.ifr_addr.sa_len;
-#endif /* HAVE_MINIMUM_IFREQ */
- if (cpsize > sizeof u.ifreq && cpsize <= sizeof u)
- memcpy(&u.ifreq, cp, cpsize);
-#elif defined SIOCGIFCONF_ADDR
- cpsize = sizeof u.ifreq;
-#else
- cpsize = sizeof u.ifreq.ifr_name;
- /* XXX maybe this should be a hard error? */
- if (ioctl(s, SIOCGIFADDR, (char *)&u.ifreq) < 0)
- continue;
-#endif
- switch (u.ifreq.ifr_addr.sa_family) {
- case AF_INET:
- if (*have_v4 == 0) {
- memcpy(&in4,
- &((struct sockaddr_in *)
- &u.ifreq.ifr_addr)->sin_addr,
- sizeof in4);
- if (in4.s_addr == INADDR_ANY)
- break;
- n = ioctl(s, SIOCGIFFLAGS, (char *)&u.ifreq);
- if (n < 0)
- break;
- if ((u.ifreq.ifr_flags & IFF_UP) == 0)
- break;
- *have_v4 = 1;
- }
- break;
- case AF_INET6:
- if (*have_v6 == 0) {
- memcpy(&in6,
- &((struct sockaddr_in6 *)
- &u.ifreq.ifr_addr)->sin6_addr,
- sizeof in6);
- if (memcmp(&in6, &in6addr_any, sizeof in6) == 0)
- break;
- n = ioctl(s, SIOCGIFFLAGS, (char *)&u.ifreq);
- if (n < 0)
- break;
- if ((u.ifreq.ifr_flags & IFF_UP) == 0)
- break;
- *have_v6 = 1;
- }
- break;
- }
- }
- if (buf != NULL)
- memput(buf, bufsiz);
- close(s);
- /* printf("scan interface -> 4=%d 6=%d\n", *have_v4, *have_v6); */
- return (0);
- err_ret:
- if (buf != NULL)
- memput(buf, bufsiz);
- if (s != -1)
- close(s);
- /* printf("scan interface -> 4=%d 6=%d\n", *have_v4, *have_v6); */
- return (-1);
-}
-
-static struct hostent *
-copyandmerge(struct hostent *he1, struct hostent *he2, int af, int *error_num) {
- struct hostent *he = NULL;
- int addresses = 1; /* NULL terminator */
- int names = 1; /* NULL terminator */
- int len = 0;
- char **cpp, **npp;
-
- /*
- * Work out array sizes;
- */
- if (he1 != NULL) {
- cpp = he1->h_addr_list;
- while (*cpp != NULL) {
- addresses++;
- cpp++;
- }
- cpp = he1->h_aliases;
- while (*cpp != NULL) {
- names++;
- cpp++;
- }
- }
-
- if (he2 != NULL) {
- cpp = he2->h_addr_list;
- while (*cpp != NULL) {
- addresses++;
- cpp++;
- }
- if (he1 == NULL) {
- cpp = he2->h_aliases;
- while (*cpp != NULL) {
- names++;
- cpp++;
- }
- }
- }
-
- if (addresses == 1) {
- *error_num = NO_ADDRESS;
- return (NULL);
- }
-
- he = memget(sizeof *he);
- if (he == NULL)
- goto no_recovery;
-
- he->h_addr_list = memget(sizeof(char *) * (addresses));
- if (he->h_addr_list == NULL)
- goto cleanup0;
- memset(he->h_addr_list, 0, sizeof(char *) * (addresses));
-
- /* copy addresses */
- npp = he->h_addr_list;
- if (he1 != NULL) {
- cpp = he1->h_addr_list;
- while (*cpp != NULL) {
- *npp = memget((af == AF_INET) ? INADDRSZ : IN6ADDRSZ);
- if (*npp == NULL)
- goto cleanup1;
- /* convert to mapped if required */
- if (af == AF_INET6 && he1->h_addrtype == AF_INET) {
- memcpy(*npp, in6addr_mapped,
- sizeof in6addr_mapped);
- memcpy(*npp + sizeof in6addr_mapped, *cpp,
- INADDRSZ);
- } else {
- memcpy(*npp, *cpp,
- (af == AF_INET) ? INADDRSZ : IN6ADDRSZ);
- }
- cpp++;
- npp++;
- }
- }
-
- if (he2 != NULL) {
- cpp = he2->h_addr_list;
- while (*cpp != NULL) {
- *npp = memget((af == AF_INET) ? INADDRSZ : IN6ADDRSZ);
- if (*npp == NULL)
- goto cleanup1;
- /* convert to mapped if required */
- if (af == AF_INET6 && he2->h_addrtype == AF_INET) {
- memcpy(*npp, in6addr_mapped,
- sizeof in6addr_mapped);
- memcpy(*npp + sizeof in6addr_mapped, *cpp,
- INADDRSZ);
- } else {
- memcpy(*npp, *cpp,
- (af == AF_INET) ? INADDRSZ : IN6ADDRSZ);
- }
- cpp++;
- npp++;
- }
- }
-
- he->h_aliases = memget(sizeof(char *) * (names));
- if (he->h_aliases == NULL)
- goto cleanup1;
- memset(he->h_aliases, 0, sizeof(char *) * (names));
-
- /* copy aliases */
- npp = he->h_aliases;
- cpp = (he1 != NULL) ? he1->h_aliases : he2->h_aliases;
- while (*cpp != NULL) {
- len = strlen (*cpp) + 1;
- *npp = memget(len);
- if (*npp == NULL)
- goto cleanup2;
- strcpy(*npp, *cpp);
- npp++;
- cpp++;
- }
-
- /* copy hostname */
- he->h_name = memget(strlen((he1 != NULL) ?
- he1->h_name : he2->h_name) + 1);
- if (he->h_name == NULL)
- goto cleanup2;
- strcpy(he->h_name, (he1 != NULL) ? he1->h_name : he2->h_name);
-
- /* set address type and length */
- he->h_addrtype = af;
- he->h_length = (af == AF_INET) ? INADDRSZ : IN6ADDRSZ;
- return(he);
-
- cleanup2:
- cpp = he->h_aliases;
- while (*cpp != NULL) {
- memput(*cpp, strlen(*cpp) + 1);
- cpp++;
- }
- memput(he->h_aliases, sizeof(char *) * (names));
-
- cleanup1:
- cpp = he->h_addr_list;
- while (*cpp != NULL) {
- memput(*cpp, (af == AF_INET) ? INADDRSZ : IN6ADDRSZ);
- *cpp = NULL;
- cpp++;
- }
- memput(he->h_addr_list, sizeof(char *) * (addresses));
-
- cleanup0:
- memput(he, sizeof *he);
-
- no_recovery:
- *error_num = NO_RECOVERY;
- return (NULL);
-}
-
-static struct net_data *
-init() {
- struct net_data *net_data;
-
- if (!(net_data = net_data_init(NULL)))
- goto error;
- if (!net_data->ho) {
- net_data->ho = (*net_data->irs->ho_map)(net_data->irs);
- if (!net_data->ho || !net_data->res) {
- error:
- errno = EIO;
- if (net_data && net_data->res)
- RES_SET_H_ERRNO(net_data->res, NETDB_INTERNAL);
- return (NULL);
- }
-
- (*net_data->ho->res_set)(net_data->ho, net_data->res, NULL);
- }
-
- return (net_data);
-}
-
-static void
-freepvt(struct net_data *net_data) {
- if (net_data->ho_data) {
- free(net_data->ho_data);
- net_data->ho_data = NULL;
- }
-}
-
-static struct hostent *
-fakeaddr(const char *name, int af, struct net_data *net_data) {
- struct pvt *pvt;
-
- freepvt(net_data);
- net_data->ho_data = malloc(sizeof (struct pvt));
- if (!net_data->ho_data) {
- errno = ENOMEM;
- RES_SET_H_ERRNO(net_data->res, NETDB_INTERNAL);
- return (NULL);
- }
- pvt = net_data->ho_data;
-#ifndef __bsdi__
- /*
- * Unlike its forebear(inet_aton), our friendly inet_pton() is strict
- * in its interpretation of its input, and it will only return "1" if
- * the input string is a formally valid(and thus unambiguous with
- * respect to host names) internet address specification for this AF.
- *
- * This means "telnet 0xdeadbeef" and "telnet 127.1" are dead now.
- */
- if (inet_pton(af, name, pvt->addr) != 1) {
-#else
- /* BSDI XXX
- * We put this back to inet_aton -- we really want the old behavior
- * Long live 127.1...
- */
- if ((af != AF_INET ||
- inet_aton(name, (struct in_addr *)pvt->addr) != 1) &&
- inet_pton(af, name, pvt->addr) != 1) {
-#endif
- RES_SET_H_ERRNO(net_data->res, HOST_NOT_FOUND);
- return (NULL);
- }
- strncpy(pvt->name, name, NS_MAXDNAME);
- pvt->name[NS_MAXDNAME] = '\0';
- if (af == AF_INET && (net_data->res->options & RES_USE_INET6) != 0) {
- map_v4v6_address(pvt->addr, pvt->addr);
- af = AF_INET6;
- }
- pvt->host.h_addrtype = af;
- switch(af) {
- case AF_INET:
- pvt->host.h_length = NS_INADDRSZ;
- break;
- case AF_INET6:
- pvt->host.h_length = NS_IN6ADDRSZ;
- break;
- default:
- errno = EAFNOSUPPORT;
- RES_SET_H_ERRNO(net_data->res, NETDB_INTERNAL);
- return (NULL);
- }
- pvt->host.h_name = pvt->name;
- pvt->host.h_aliases = pvt->aliases;
- pvt->aliases[0] = NULL;
- pvt->addrs[0] = (char *)pvt->addr;
- pvt->addrs[1] = NULL;
- pvt->host.h_addr_list = pvt->addrs;
- RES_SET_H_ERRNO(net_data->res, NETDB_SUCCESS);
- return (&pvt->host);
-}
-
-#ifdef grot /* for future use in gethostbyaddr(), for "SUNSECURITY" */
- struct hostent *rhp;
- char **haddr;
- u_long old_options;
- char hname2[MAXDNAME+1];
-
- if (af == AF_INET) {
- /*
- * turn off search as the name should be absolute,
- * 'localhost' should be matched by defnames
- */
- strncpy(hname2, hp->h_name, MAXDNAME);
- hname2[MAXDNAME] = '\0';
- old_options = net_data->res->options;
- net_data->res->options &= ~RES_DNSRCH;
- net_data->res->options |= RES_DEFNAMES;
- if (!(rhp = gethostbyname(hname2))) {
- net_data->res->options = old_options;
- RES_SET_H_ERRNO(net_data->res, HOST_NOT_FOUND);
- return (NULL);
- }
- net_data->res->options = old_options;
- for (haddr = rhp->h_addr_list; *haddr; haddr++)
- if (!memcmp(*haddr, addr, INADDRSZ))
- break;
- if (!*haddr) {
- RES_SET_H_ERRNO(net_data->res, HOST_NOT_FOUND);
- return (NULL);
- }
- }
-#endif /* grot */
-
-#endif /*__BIND_NOSTATIC*/
diff --git a/contrib/bind/lib/irs/gethostent_r.c b/contrib/bind/lib/irs/gethostent_r.c
deleted file mode 100644
index e8017ac..0000000
--- a/contrib/bind/lib/irs/gethostent_r.c
+++ /dev/null
@@ -1,264 +0,0 @@
-/*
- * Copyright (c) 1998-1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: gethostent_r.c,v 8.7 2001/11/01 08:02:09 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include <port_before.h>
-#if !defined(_REENTRANT) || !defined(DO_PTHREADS)
- static int gethostent_r_not_required = 0;
-#else
-#include <errno.h>
-#include <string.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <sys/param.h>
-#include <port_after.h>
-
-#ifdef HOST_R_RETURN
-
-static HOST_R_RETURN
-copy_hostent(struct hostent *, struct hostent *, HOST_R_COPY_ARGS);
-
-HOST_R_RETURN
-gethostbyname_r(const char *name, struct hostent *hptr, HOST_R_ARGS) {
- struct hostent *he = gethostbyname(name);
-#ifdef HOST_R_SETANSWER
- int n = 0;
-#endif
-
- HOST_R_ERRNO;
-
-#ifdef HOST_R_SETANSWER
- if (he == NULL || (n = copy_hostent(he, hptr, HOST_R_COPY)) == 0)
- *answerp = NULL;
- else
- *answerp = hptr;
-
- return (n);
-#else
- if (he == NULL)
- return (HOST_R_BAD);
-
- return (copy_hostent(he, hptr, HOST_R_COPY));
-#endif
-}
-
-HOST_R_RETURN
-gethostbyaddr_r(const char *addr, int len, int type,
- struct hostent *hptr, HOST_R_ARGS) {
- struct hostent *he = gethostbyaddr(addr, len, type);
-#ifdef HOST_R_SETANSWER
- int n = 0;
-#endif
-
- HOST_R_ERRNO;
-
-#ifdef HOST_R_SETANSWER
- if (he == NULL || (n = copy_hostent(he, hptr, HOST_R_COPY)) == 0)
- *answerp = NULL;
- else
- *answerp = hptr;
-
- return (n);
-#else
- if (he == NULL)
- return (HOST_R_BAD);
-
- return (copy_hostent(he, hptr, HOST_R_COPY));
-#endif
-}
-
-/*
- * These assume a single context is in operation per thread.
- * If this is not the case we will need to call irs directly
- * rather than through the base functions.
- */
-
-HOST_R_RETURN
-gethostent_r(struct hostent *hptr, HOST_R_ARGS) {
- struct hostent *he = gethostent();
-#ifdef HOST_R_SETANSWER
- int n = 0;
-#endif
-
- HOST_R_ERRNO;
-
-#ifdef HOST_R_SETANSWER
- if (he == NULL || (n = copy_hostent(he, hptr, HOST_R_COPY)) == 0)
- *answerp = NULL;
- else
- *answerp = hptr;
-
- return (n);
-#else
- if (he == NULL)
- return (HOST_R_BAD);
-
- return (copy_hostent(he, hptr, HOST_R_COPY));
-#endif
-}
-
-HOST_R_SET_RETURN
-#ifdef HOST_R_ENT_ARGS
-sethostent_r(int stay_open, HOST_R_ENT_ARGS)
-#else
-sethostent_r(int stay_open)
-#endif
-{
- sethostent(stay_open);
-#ifdef HOST_R_SET_RESULT
- return (HOST_R_SET_RESULT);
-#endif
-}
-
-HOST_R_END_RETURN
-#ifdef HOST_R_ENT_ARGS
-endhostent_r(HOST_R_ENT_ARGS)
-#else
-endhostent_r(void)
-#endif
-{
- endhostent();
- HOST_R_END_RESULT(HOST_R_OK);
-}
-
-/* Private */
-
-#ifndef HOSTENT_DATA
-static HOST_R_RETURN
-copy_hostent(struct hostent *he, struct hostent *hptr, HOST_R_COPY_ARGS) {
- char *cp;
- char **ptr;
- int i, n;
- int nptr, len;
-
- /* Find out the amount of space required to store the answer. */
- nptr = 2; /* NULL ptrs */
- len = (char *)ALIGN(buf) - buf;
- for (i = 0; he->h_addr_list[i]; i++, nptr++) {
- len += he->h_length;
- }
- for (i = 0; he->h_aliases[i]; i++, nptr++) {
- len += strlen(he->h_aliases[i]) + 1;
- }
- len += strlen(he->h_name) + 1;
- len += nptr * sizeof(char*);
-
- if (len > buflen) {
- errno = ERANGE;
- return (HOST_R_BAD);
- }
-
- /* copy address size and type */
- hptr->h_addrtype = he->h_addrtype;
- n = hptr->h_length = he->h_length;
-
- ptr = (char **)ALIGN(buf);
- cp = (char *)ALIGN(buf) + nptr * sizeof(char *);
-
- /* copy address list */
- hptr->h_addr_list = ptr;
- for (i = 0; he->h_addr_list[i]; i++ , ptr++) {
- memcpy(cp, he->h_addr_list[i], n);
- hptr->h_addr_list[i] = cp;
- cp += n;
- }
- hptr->h_addr_list[i] = NULL;
- ptr++;
-
- /* copy official name */
- n = strlen(he->h_name) + 1;
- strcpy(cp, he->h_name);
- hptr->h_name = cp;
- cp += n;
-
- /* copy aliases */
- hptr->h_aliases = ptr;
- for (i = 0 ; he->h_aliases[i]; i++) {
- n = strlen(he->h_aliases[i]) + 1;
- strcpy(cp, he->h_aliases[i]);
- hptr->h_aliases[i] = cp;
- cp += n;
- }
- hptr->h_aliases[i] = NULL;
-
- return (HOST_R_OK);
-}
-#else /* !HOSTENT_DATA */
-static int
-copy_hostent(struct hostent *he, struct hostent *hptr, HOST_R_COPY_ARGS) {
- char *cp, *eob;
- int i, n;
-
- /* copy address size and type */
- hptr->h_addrtype = he->h_addrtype;
- n = hptr->h_length = he->h_length;
-
- /* copy up to first 35 addresses */
- i = 0;
- cp = hdptr->hostaddr;
- eob = hdptr->hostaddr + sizeof(hdptr->hostaddr);
- hptr->h_addr_list = hdptr->h_addr_ptrs;
- while (he->h_addr_list[i] && i < (_MAXADDRS)) {
- if (n < (eob - cp)) {
- memcpy(cp, he->h_addr_list[i], n);
- hptr->h_addr_list[i] = cp;
- cp += n;
- } else {
- break;
- }
- i++;
- }
- hptr->h_addr_list[i] = NULL;
-
- /* copy official name */
- cp = hdptr->hostbuf;
- eob = hdptr->hostbuf + sizeof(hdptr->hostbuf);
- if ((n = strlen(he->h_name) + 1) < (eob - cp)) {
- strcpy(cp, he->h_name);
- hptr->h_name = cp;
- cp += n;
- } else {
- return (-1);
- }
-
- /* copy aliases */
- i = 0;
- hptr->h_aliases = hdptr->host_aliases;
- while (he->h_aliases[i] && i < (_MAXALIASES-1)) {
- if ((n = strlen(he->h_aliases[i]) + 1) < (eob - cp)) {
- strcpy(cp, he->h_aliases[i]);
- hptr->h_aliases[i] = cp;
- cp += n;
- } else {
- break;
- }
- i++;
- }
- hptr->h_aliases[i] = NULL;
-
- return (HOST_R_OK);
-}
-#endif /* !HOSTENT_DATA */
-#else /* HOST_R_RETURN */
- static int gethostent_r_unknown_system = 0;
-#endif /* HOST_R_RETURN */
-#endif /* !defined(_REENTRANT) || !defined(DO_PTHREADS) */
diff --git a/contrib/bind/lib/irs/getnameinfo.c b/contrib/bind/lib/irs/getnameinfo.c
deleted file mode 100644
index 702b932..0000000
--- a/contrib/bind/lib/irs/getnameinfo.c
+++ /dev/null
@@ -1,322 +0,0 @@
-/*
- * Issues to be discussed:
- * - Thread safe-ness must be checked
- */
-
-/*
- * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by WIDE Project and
- * its contributors.
- * 4. Neither the name of the project 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 PROJECT 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 PROJECT 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.
- */
-
-#include <port_before.h>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <arpa/inet.h>
-#include <net/if.h>
-
-#include <netdb.h>
-#include <resolv.h>
-#include <string.h>
-#include <stddef.h>
-
-#include <port_after.h>
-
-/*
- * Note that a_off will be dynamically adjusted so that to be consistent
- * with the definition of sockaddr_in{,6}.
- * The value presented below is just a guess.
- */
-static struct afd {
- int a_af;
- int a_addrlen;
- size_t a_socklen;
- int a_off;
-} afdl [] = {
- /* first entry is linked last... */
- {PF_INET, sizeof(struct in_addr), sizeof(struct sockaddr_in),
- offsetof(struct sockaddr_in, sin_addr)},
- {PF_INET6, sizeof(struct in6_addr), sizeof(struct sockaddr_in6),
- offsetof(struct sockaddr_in6, sin6_addr)},
- {0, 0, 0, 0},
-};
-
-struct sockinet {
-#ifdef HAVE_SA_LEN
- u_char si_len;
-#endif
- u_char si_family;
- u_short si_port;
-};
-
-static int ip6_parsenumeric __P((const struct sockaddr *, const char *, char *,
- size_t, int));
-#ifdef HAVE_SIN6_SCOPE_ID
-static int ip6_sa2str __P((const struct sockaddr_in6 *, char *, size_t, int));
-#endif
-
-int
-getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
- const struct sockaddr *sa;
- size_t salen;
- char *host;
- size_t hostlen;
- char *serv;
- size_t servlen;
- int flags;
-{
- struct afd *afd;
- struct servent *sp;
- struct hostent *hp;
- u_short port;
-#ifdef HAVE_SA_LEN
- size_t len;
-#endif
- int family, i;
- const char *addr;
- char *p;
- char numserv[512];
- char numaddr[512];
- const struct sockaddr_in6 *sin6;
-
- if (sa == NULL)
- return EAI_FAIL;
-
-#ifdef HAVE_SA_LEN
- len = sa->sa_len;
- if (len != salen) return EAI_FAIL;
-#endif
-
- family = sa->sa_family;
- for (i = 0; afdl[i].a_af; i++)
- if (afdl[i].a_af == family) {
- afd = &afdl[i];
- goto found;
- }
- return EAI_FAMILY;
-
- found:
- if (salen != afd->a_socklen) return EAI_FAIL;
-
- port = ((const struct sockinet *)sa)->si_port; /* network byte order */
- addr = (const char *)sa + afd->a_off;
-
- if (serv == NULL || servlen == 0) {
- /*
- * rfc2553bis says that serv == NULL or servlen == 0 means that
- * the caller does not want the result.
- */
- } else if (flags & NI_NUMERICSERV) {
- sprintf(numserv, "%d", ntohs(port));
- if (strlen(numserv) > servlen)
- return EAI_MEMORY;
- strcpy(serv, numserv);
- } else {
- sp = getservbyport(port, (flags & NI_DGRAM) ? "udp" : "tcp");
- if (sp) {
- if (strlen(sp->s_name) + 1 > servlen)
- return EAI_MEMORY;
- strcpy(serv, sp->s_name);
- } else
- return EAI_NONAME;
- }
-
- switch (sa->sa_family) {
- case AF_INET:
- if (ntohl(*(const u_long *)addr) >> IN_CLASSA_NSHIFT == 0)
- flags |= NI_NUMERICHOST;
- break;
- case AF_INET6:
- sin6 = (const struct sockaddr_in6 *)sa;
- switch (sin6->sin6_addr.s6_addr[0]) {
- case 0x00:
- if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr))
- ;
- else if (IN6_IS_ADDR_LOOPBACK(&sin6->sin6_addr))
- ;
- else
- flags |= NI_NUMERICHOST;
- break;
- default:
- if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))
- flags |= NI_NUMERICHOST;
- else if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
- flags |= NI_NUMERICHOST;
- break;
- }
- break;
- }
- if (host == NULL || hostlen == 0) {
- /*
- * rfc2553bis says that host == NULL or hostlen == 0 means that
- * the caller does not want the result.
- */
- } else if (flags & NI_NUMERICHOST) {
- goto numeric;
- } else {
- hp = gethostbyaddr(addr, afd->a_addrlen, afd->a_af);
-
- if (hp) {
- if (flags & NI_NOFQDN) {
- p = strchr(hp->h_name, '.');
- if (p) *p = '\0';
- }
- if (strlen(hp->h_name) + 1 > hostlen)
- return EAI_MEMORY;
- strcpy(host, hp->h_name);
- } else {
- if (flags & NI_NAMEREQD)
- return EAI_NONAME;
- numeric:
- switch(afd->a_af) {
- case AF_INET6:
- {
- int error;
-
- if ((error = ip6_parsenumeric(sa, addr, host,
- hostlen,
- flags)) != 0)
- return(error);
- break;
- }
-
- default:
- if (inet_ntop(afd->a_af, addr, numaddr,
- sizeof(numaddr)) == NULL)
- return EAI_NONAME;
- if (strlen(numaddr) + 1 > hostlen)
- return EAI_MEMORY;
- strcpy(host, numaddr);
- }
- }
- }
- return(0);
-}
-
-static int
-ip6_parsenumeric(const struct sockaddr *sa, const char *addr, char *host,
- size_t hostlen, int flags)
-{
- size_t numaddrlen;
- char numaddr[512];
-
-#ifndef HAVE_SIN6_SCOPE_ID
- UNUSED(sa);
- UNUSED(flags);
-#endif
-
- if (inet_ntop(AF_INET6, addr, numaddr, sizeof(numaddr))
- == NULL)
- return EAI_SYSTEM;
-
- numaddrlen = strlen(numaddr);
- if (numaddrlen + 1 > hostlen) /* don't forget terminator */
- return EAI_MEMORY;
- strcpy(host, numaddr);
-
-#ifdef HAVE_SIN6_SCOPE_ID
- if (((const struct sockaddr_in6 *)sa)->sin6_scope_id) {
- char scopebuf[MAXHOSTNAMELEN]; /* XXX */
- int scopelen;
-
- /* ip6_sa2str never fails */
- scopelen = ip6_sa2str((const struct sockaddr_in6 *)sa,
- scopebuf, sizeof(scopebuf), flags);
-
- if (scopelen + 1 + numaddrlen + 1 > hostlen)
- return EAI_MEMORY;
-
- /* construct <numeric-addr><delim><scopeid> */
- memcpy(host + numaddrlen + 1, scopebuf,
- scopelen);
- host[numaddrlen] = SCOPE_DELIMITER;
- host[numaddrlen + 1 + scopelen] = '\0';
- }
-#endif
-
- return 0;
-}
-
-#ifdef HAVE_SIN6_SCOPE_ID
-/* ARGSUSED */
-static int
-ip6_sa2str(const struct sockaddr_in6 *sa6, char *buf,
- size_t bufsiz, int flags)
-{
-#ifdef USE_IFNAMELINKID
- unsigned int ifindex = (unsigned int)sa6->sin6_scope_id;
- const struct in6_addr *a6 = &sa6->sin6_addr;
-#endif
- char tmp[64];
-
-#ifdef NI_NUMERICSCOPE
- if (flags & NI_NUMERICSCOPE) {
- sprintf(tmp, "%u", sa6->sin6_scope_id);
- if (bufsiz != 0) {
- strncpy(buf, tmp, bufsiz - 1);
- buf[bufsiz - 1] = '\0';
- }
- return(strlen(tmp));
- }
-#endif
-
-#ifdef USE_IFNAMELINKID
- /*
- * For a link-local address, convert the index to an interface
- * name, assuming a one-to-one mapping between links and interfaces.
- * Note, however, that this assumption is stronger than the
- * specification of the scoped address architecture; the
- * specficication says that more than one interfaces can belong to
- * a single link.
- */
-
- /* if_indextoname() does not take buffer size. not a good api... */
- if ((IN6_IS_ADDR_LINKLOCAL(a6) || IN6_IS_ADDR_MC_LINKLOCAL(a6)) &&
- bufsiz >= IF_NAMESIZE) {
- char *p = if_indextoname(ifindex, buf);
- if (p) {
- return(strlen(p));
- }
- }
-#endif
-
- /* last resort */
- sprintf(tmp, "%u", sa6->sin6_scope_id);
- if (bufsiz != 0) {
- strncpy(buf, tmp, bufsiz - 1);
- buf[bufsiz - 1] = '\0';
- }
- return(strlen(tmp));
-}
-#endif
diff --git a/contrib/bind/lib/irs/getnetent.c b/contrib/bind/lib/irs/getnetent.c
deleted file mode 100644
index 49810b7..0000000
--- a/contrib/bind/lib/irs/getnetent.c
+++ /dev/null
@@ -1,343 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: getnetent.c,v 1.19 2001/05/29 05:48:47 marka Exp $";
-#endif
-
-/* Imports */
-
-#include "port_before.h"
-
-#if !defined(__BIND_NOSTATIC)
-
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <arpa/inet.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <netdb.h>
-#include <resolv.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "irs_data.h"
-
-/* Definitions */
-
-struct pvt {
- struct netent netent;
- char * aliases[1];
- char name[MAXDNAME + 1];
-};
-
-/* Forward */
-
-static struct net_data *init(void);
-static struct netent *nw_to_net(struct nwent *, struct net_data *);
-static void freepvt(struct net_data *);
-static struct netent *fakeaddr(const char *, int af, struct net_data *);
-
-/* Portability */
-
-#ifndef INADDR_NONE
-# define INADDR_NONE 0xffffffff
-#endif
-
-/* Public */
-
-struct netent *
-getnetent() {
- struct net_data *net_data = init();
-
- return (getnetent_p(net_data));
-}
-
-struct netent *
-getnetbyname(const char *name) {
- struct net_data *net_data = init();
-
- return (getnetbyname_p(name, net_data));
-}
-
-struct netent *
-getnetbyaddr(unsigned long net, int type) {
- struct net_data *net_data = init();
-
- return (getnetbyaddr_p(net, type, net_data));
-}
-
-void
-setnetent(int stayopen) {
- struct net_data *net_data = init();
-
- setnetent_p(stayopen, net_data);
-}
-
-
-void
-endnetent() {
- struct net_data *net_data = init();
-
- endnetent_p(net_data);
-}
-
-/* Shared private. */
-
-struct netent *
-getnetent_p(struct net_data *net_data) {
- struct irs_nw *nw;
-
- if (!net_data || !(nw = net_data->nw))
- return (NULL);
- net_data->nww_last = (*nw->next)(nw);
- net_data->nw_last = nw_to_net(net_data->nww_last, net_data);
- return (net_data->nw_last);
-}
-
-struct netent *
-getnetbyname_p(const char *name, struct net_data *net_data) {
- struct irs_nw *nw;
- struct netent *np;
- char **nap;
-
- if (!net_data || !(nw = net_data->nw))
- return (NULL);
- if (net_data->nw_stayopen && net_data->nw_last) {
- if (!strcmp(net_data->nw_last->n_name, name))
- return (net_data->nw_last);
- for (nap = net_data->nw_last->n_aliases; nap && *nap; nap++)
- if (!strcmp(name, *nap))
- return (net_data->nw_last);
- }
- if ((np = fakeaddr(name, AF_INET, net_data)) != NULL)
- return (np);
- net_data->nww_last = (*nw->byname)(nw, name, AF_INET);
- net_data->nw_last = nw_to_net(net_data->nww_last, net_data);
- if (!net_data->nw_stayopen)
- endnetent();
- return (net_data->nw_last);
-}
-
-struct netent *
-getnetbyaddr_p(unsigned long net, int type, struct net_data *net_data) {
- struct irs_nw *nw;
- u_char addr[4];
- int bits;
-
- if (!net_data || !(nw = net_data->nw))
- return (NULL);
- if (net_data->nw_stayopen && net_data->nw_last)
- if (type == net_data->nw_last->n_addrtype &&
- net == net_data->nw_last->n_net)
- return (net_data->nw_last);
-
- /* cannonize net(host order) */
- if (net < 256) {
- net <<= 24;
- bits = 8;
- } else if (net < 65536) {
- net <<= 16;
- bits = 16;
- } else if (net < 16777216) {
- net <<= 8;
- bits = 24;
- } else
- bits = 32;
-
- /* convert to net order */
- addr[0] = (0xFF000000 & net) >> 24;
- addr[1] = (0x00FF0000 & net) >> 16;
- addr[2] = (0x0000FF00 & net) >> 8;
- addr[3] = (0x000000FF & net);
-
- /* reduce bits to as close to natural number as possible */
- if ((bits == 32) && (addr[0] < 224) && (addr[3] == 0)) {
- if ((addr[0] < 192) && (addr[2] == 0)) {
- if ((addr[0] < 128) && (addr[1] == 0))
- bits = 8;
- else
- bits = 16;
- } else {
- bits = 24;
- }
- }
-
- net_data->nww_last = (*nw->byaddr)(nw, addr, bits, AF_INET);
- net_data->nw_last = nw_to_net(net_data->nww_last, net_data);
- if (!net_data->nw_stayopen)
- endnetent();
- return (net_data->nw_last);
-}
-
-
-
-
-void
-setnetent_p(int stayopen, struct net_data *net_data) {
- struct irs_nw *nw;
-
- if (!net_data || !(nw = net_data->nw))
- return;
- freepvt(net_data);
- (*nw->rewind)(nw);
- net_data->nw_stayopen = (stayopen != 0);
- if (stayopen == 0)
- net_data_minimize(net_data);
-}
-
-void
-endnetent_p(struct net_data *net_data) {
- struct irs_nw *nw;
-
- if ((net_data != NULL) && ((nw = net_data->nw) != NULL))
- (*nw->minimize)(nw);
-}
-
-/* Private */
-
-static struct net_data *
-init() {
- struct net_data *net_data;
-
- if (!(net_data = net_data_init(NULL)))
- goto error;
- if (!net_data->nw) {
- net_data->nw = (*net_data->irs->nw_map)(net_data->irs);
-
- if (!net_data->nw || !net_data->res) {
- error:
- errno = EIO;
- return (NULL);
- }
- (*net_data->nw->res_set)(net_data->nw, net_data->res, NULL);
- }
-
- return (net_data);
-}
-
-static void
-freepvt(struct net_data *net_data) {
- if (net_data->nw_data) {
- free(net_data->nw_data);
- net_data->nw_data = NULL;
- }
-}
-
-static struct netent *
-fakeaddr(const char *name, int af, struct net_data *net_data) {
- struct pvt *pvt;
- const char *cp;
- u_long tmp;
-
- if (af != AF_INET) {
- /* XXX should support IPv6 some day */
- errno = EAFNOSUPPORT;
- RES_SET_H_ERRNO(net_data->res, NETDB_INTERNAL);
- return (NULL);
- }
- if (!isascii((unsigned char)(name[0])) ||
- !isdigit((unsigned char)(name[0])))
- return (NULL);
- for (cp = name; *cp; ++cp)
- if (!isascii(*cp) || (!isdigit((unsigned char)*cp) && *cp != '.'))
- return (NULL);
- if (*--cp == '.')
- return (NULL);
-
- /* All-numeric, no dot at the end. */
-
- tmp = inet_network(name);
- if (tmp == INADDR_NONE) {
- RES_SET_H_ERRNO(net_data->res, HOST_NOT_FOUND);
- return (NULL);
- }
-
- /* Valid network number specified.
- * Fake up a netent as if we'd actually
- * done a lookup.
- */
- freepvt(net_data);
- net_data->nw_data = malloc(sizeof (struct pvt));
- if (!net_data->nw_data) {
- errno = ENOMEM;
- RES_SET_H_ERRNO(net_data->res, NETDB_INTERNAL);
- return (NULL);
- }
- pvt = net_data->nw_data;
-
- strncpy(pvt->name, name, MAXDNAME);
- pvt->name[MAXDNAME] = '\0';
- pvt->netent.n_name = pvt->name;
- pvt->netent.n_addrtype = AF_INET;
- pvt->netent.n_aliases = pvt->aliases;
- pvt->aliases[0] = NULL;
- pvt->netent.n_net = tmp;
-
- return (&pvt->netent);
-}
-
-static struct netent *
-nw_to_net(struct nwent *nwent, struct net_data *net_data) {
- struct pvt *pvt;
- u_long addr = 0;
- int i;
- int msbyte;
-
- if (!nwent || nwent->n_addrtype != AF_INET)
- return (NULL);
- freepvt(net_data);
- net_data->nw_data = malloc(sizeof (struct pvt));
- if (!net_data->nw_data) {
- errno = ENOMEM;
- RES_SET_H_ERRNO(net_data->res, NETDB_INTERNAL);
- return (NULL);
- }
- pvt = net_data->nw_data;
- pvt->netent.n_name = nwent->n_name;
- pvt->netent.n_aliases = nwent->n_aliases;
- pvt->netent.n_addrtype = nwent->n_addrtype;
-
-/*
- * What this code does: Converts net addresses from network to host form.
- *
- * msbyte: the index of the most significant byte in the n_addr array.
- *
- * Shift bytes in significant order into addr. When all signicant
- * bytes are in, zero out bits in the LSB that are not part of the network.
- */
- msbyte = nwent->n_length / 8 +
- ((nwent->n_length % 8) != 0 ? 1 : 0) - 1;
- for (i = 0; i <= msbyte; i++)
- addr = (addr << 8) | ((unsigned char *)nwent->n_addr)[i];
- i = (32 - nwent->n_length) % 8;
- if (i != 0)
- addr &= ~((1 << (i + 1)) - 1);
- pvt->netent.n_net = addr;
- return (&pvt->netent);
-}
-
-#endif /*__BIND_NOSTATIC*/
diff --git a/contrib/bind/lib/irs/getnetent_r.c b/contrib/bind/lib/irs/getnetent_r.c
deleted file mode 100644
index 1472eb5..0000000
--- a/contrib/bind/lib/irs/getnetent_r.c
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * Copyright (c) 1998-1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: getnetent_r.c,v 8.6 2001/11/01 08:02:11 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include <port_before.h>
-#if !defined(_REENTRANT) || !defined(DO_PTHREADS)
- static int getnetent_r_not_required = 0;
-#else
-#include <errno.h>
-#include <string.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <sys/param.h>
-#include <port_after.h>
-
-#ifdef NET_R_RETURN
-
-static NET_R_RETURN
-copy_netent(struct netent *, struct netent *, NET_R_COPY_ARGS);
-
-NET_R_RETURN
-getnetbyname_r(const char *name, struct netent *nptr, NET_R_ARGS) {
- struct netent *ne = getnetbyname(name);
-#ifdef NET_R_SETANSWER
- int n = 0;
-
- if (ne == NULL || (n = copy_netent(ne, nptr, NET_R_COPY)) != 0)
- *answerp = NULL;
- else
- *answerp = ne;
- if (ne == NULL)
- *h_errnop = h_errno;
- return (n);
-#else
- if (ne == NULL)
- return (NET_R_BAD);
-
- return (copy_netent(ne, nptr, NET_R_COPY));
-#endif
-}
-
-#ifndef GETNETBYADDR_ADDR_T
-#define GETNETBYADDR_ADDR_T long
-#endif
-NET_R_RETURN
-getnetbyaddr_r(GETNETBYADDR_ADDR_T addr, int type, struct netent *nptr, NET_R_ARGS) {
- struct netent *ne = getnetbyaddr(addr, type);
-#ifdef NET_R_SETANSWER
- int n = 0;
-
- if (ne == NULL || (n = copy_netent(ne, nptr, NET_R_COPY)) != 0)
- *answerp = NULL;
- else
- *answerp = ne;
- if (ne == NULL)
- *h_errnop = h_errno;
- return (n);
-#else
-
- if (ne == NULL)
- return (NET_R_BAD);
-
- return (copy_netent(ne, nptr, NET_R_COPY));
-#endif
-}
-
-/*
- * These assume a single context is in operation per thread.
- * If this is not the case we will need to call irs directly
- * rather than through the base functions.
- */
-
-NET_R_RETURN
-getnetent_r(struct netent *nptr, NET_R_ARGS) {
- struct netent *ne = getnetent();
-#ifdef NET_R_SETANSWER
- int n = 0;
-
- if (ne == NULL || (n = copy_netent(ne, nptr, NET_R_COPY)) != 0)
- *answerp = NULL;
- else
- *answerp = ne;
- if (ne == NULL)
- *h_errnop = h_errno;
- return (n);
-#else
-
- if (ne == NULL)
- return (NET_R_BAD);
-
- return (copy_netent(ne, nptr, NET_R_COPY));
-#endif
-}
-
-NET_R_SET_RETURN
-#ifdef NET_R_ENT_ARGS
-setnetent_r(int stay_open, NET_R_ENT_ARGS)
-#else
-setnetent_r(int stay_open)
-#endif
-{
- setnetent(stay_open);
-#ifdef NET_R_SET_RESULT
- return (NET_R_SET_RESULT);
-#endif
-}
-
-NET_R_END_RETURN
-#ifdef NET_R_ENT_ARGS
-endnetent_r(NET_R_ENT_ARGS)
-#else
-endnetent_r()
-#endif
-{
- endnetent();
- NET_R_END_RESULT(NET_R_OK);
-}
-
-/* Private */
-
-#ifndef NETENT_DATA
-static NET_R_RETURN
-copy_netent(struct netent *ne, struct netent *nptr, NET_R_COPY_ARGS) {
- char *cp;
- int i, n;
- int numptr, len;
-
- /* Find out the amount of space required to store the answer. */
- numptr = 1; /* NULL ptr */
- len = (char *)ALIGN(buf) - buf;
- for (i = 0; ne->n_aliases[i]; i++, numptr++) {
- len += strlen(ne->n_aliases[i]) + 1;
- }
- len += strlen(ne->n_name) + 1;
- len += numptr * sizeof(char*);
-
- if (len > (int)buflen) {
- errno = ERANGE;
- return (NET_R_BAD);
- }
-
- /* copy net value and type */
- nptr->n_addrtype = ne->n_addrtype;
- nptr->n_net = ne->n_net;
-
- cp = (char *)ALIGN(buf) + numptr * sizeof(char *);
-
- /* copy official name */
- n = strlen(ne->n_name) + 1;
- strcpy(cp, ne->n_name);
- nptr->n_name = cp;
- cp += n;
-
- /* copy aliases */
- nptr->n_aliases = (char **)ALIGN(buf);
- for (i = 0 ; ne->n_aliases[i]; i++) {
- n = strlen(ne->n_aliases[i]) + 1;
- strcpy(cp, ne->n_aliases[i]);
- nptr->n_aliases[i] = cp;
- cp += n;
- }
- nptr->n_aliases[i] = NULL;
-
- return (NET_R_OK);
-}
-#else /* !NETENT_DATA */
-static int
-copy_netent(struct netent *ne, struct netent *nptr, NET_R_COPY_ARGS) {
- char *cp, *eob;
- int i, n;
-
- /* copy net value and type */
- nptr->n_addrtype = ne->n_addrtype;
- nptr->n_net = ne->n_net;
-
- /* copy official name */
- cp = ndptr->line;
- eob = ndptr->line + sizeof(ndptr->line);
- if ((n = strlen(ne->n_name) + 1) < (eob - cp)) {
- strcpy(cp, ne->n_name);
- nptr->n_name = cp;
- cp += n;
- } else {
- return (-1);
- }
-
- /* copy aliases */
- i = 0;
- nptr->n_aliases = ndptr->net_aliases;
- while (ne->n_aliases[i] && i < (_MAXALIASES-1)) {
- if ((n = strlen(ne->n_aliases[i]) + 1) < (eob - cp)) {
- strcpy(cp, ne->n_aliases[i]);
- nptr->n_aliases[i] = cp;
- cp += n;
- } else {
- break;
- }
- i++;
- }
- nptr->n_aliases[i] = NULL;
-
- return (NET_R_OK);
-}
-#endif /* !NETENT_DATA */
-#else /* NET_R_RETURN */
- static int getnetent_r_unknown_system = 0;
-#endif /* NET_R_RETURN */
-#endif /* !defined(_REENTRANT) || !defined(DO_PTHREADS) */
diff --git a/contrib/bind/lib/irs/getnetgrent.c b/contrib/bind/lib/irs/getnetgrent.c
deleted file mode 100644
index 9c13b01..0000000
--- a/contrib/bind/lib/irs/getnetgrent.c
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: getnetgrent.c,v 1.16.6.1 2003/06/02 06:06:58 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-/* Imports */
-
-#include "port_before.h"
-
-#if !defined(__BIND_NOSTATIC)
-
-#include <sys/types.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-
-#include <errno.h>
-#include <resolv.h>
-#include <stdio.h>
-
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_data.h"
-
-/* Forward */
-
-static struct net_data *init(void);
-
-
-/* Public */
-
-#ifndef SETNETGRENT_ARGS
-#define SETNETGRENT_ARGS const char *netgroup
-#endif
-void
-setnetgrent(SETNETGRENT_ARGS) {
- struct net_data *net_data = init();
-
- setnetgrent_p(netgroup, net_data);
-}
-
-void
-endnetgrent(void) {
- struct net_data *net_data = init();
-
- endnetgrent_p(net_data);
-}
-
-#ifndef INNETGR_ARGS
-#define INNETGR_ARGS const char *netgroup, const char *host, \
- const char *user, const char *domain
-#endif
-int
-innetgr(INNETGR_ARGS) {
- struct net_data *net_data = init();
-
- return (innetgr_p(netgroup, host, user, domain, net_data));
-}
-
-int
-getnetgrent(char **host, char **user, char **domain) {
- struct net_data *net_data = init();
- const char *ch, *cu, *cd;
- int ret;
-
- ret = getnetgrent_p(&ch, &cu, &cd, net_data);
- if (ret != 1)
- return (ret);
-
- DE_CONST(ch, *host);
- DE_CONST(cu, *user);
- DE_CONST(cd, *domain);
- return (ret);
-}
-
-/* Shared private. */
-
-void
-setnetgrent_p(const char *netgroup, struct net_data *net_data) {
- struct irs_ng *ng;
-
- if ((net_data != NULL) && ((ng = net_data->ng) != NULL))
- (*ng->rewind)(ng, netgroup);
-}
-
-void
-endnetgrent_p(struct net_data *net_data) {
- struct irs_ng *ng;
-
- if (!net_data)
- return;
- if ((ng = net_data->ng) != NULL)
- (*ng->close)(ng);
- net_data->ng = NULL;
-}
-
-int
-innetgr_p(const char *netgroup, const char *host,
- const char *user, const char *domain,
- struct net_data *net_data) {
- struct irs_ng *ng;
-
- if (!net_data || !(ng = net_data->ng))
- return (0);
- return ((*ng->test)(ng, netgroup, host, user, domain));
-}
-
-int
-getnetgrent_p(const char **host, const char **user, const char **domain,
- struct net_data *net_data ) {
- struct irs_ng *ng;
-
- if (!net_data || !(ng = net_data->ng))
- return (0);
- return ((*ng->next)(ng, host, user, domain));
-}
-
-/* Private */
-
-static struct net_data *
-init(void) {
- struct net_data *net_data;
-
- if (!(net_data = net_data_init(NULL)))
- goto error;
- if (!net_data->ng) {
- net_data->ng = (*net_data->irs->ng_map)(net_data->irs);
- if (!net_data->ng) {
- error:
- errno = EIO;
- return (NULL);
- }
- }
-
- return (net_data);
-}
-
-#endif /*__BIND_NOSTATIC*/
diff --git a/contrib/bind/lib/irs/getnetgrent_r.c b/contrib/bind/lib/irs/getnetgrent_r.c
deleted file mode 100644
index 0a88ea4..0000000
--- a/contrib/bind/lib/irs/getnetgrent_r.c
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Copyright (c) 1998-1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: getnetgrent_r.c,v 8.6.10.1 2003/06/02 06:06:58 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include <port_before.h>
-#if !defined(_REENTRANT) || !defined(DO_PTHREADS)
- static int getnetgrent_r_not_required = 0;
-#else
-#include <errno.h>
-#include <string.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <netgroup.h>
-#include <stdlib.h>
-#include <port_after.h>
-
-#ifdef NGR_R_RETURN
-
-static NGR_R_RETURN
-copy_protoent(char **, char **, char **, const char *, const char *,
- const char *, NGR_R_COPY_ARGS);
-
-NGR_R_RETURN
-innetgr_r(const char *netgroup, const char *host, const char *user,
- const char *domain) {
- char *ng, *ho, *us, *dom;
-
- DE_CONST(netgroup, ng);
- DE_CONST(host, ho);
- DE_CONST(user, us);
- DE_CONST(domain, dom);
-
- return (innetgr(ng, ho, us, dom));
-}
-
-/*
- * These assume a single context is in operation per thread.
- * If this is not the case we will need to call irs directly
- * rather than through the base functions.
- */
-
-NGR_R_RETURN
-getnetgrent_r(char **machinep, char **userp, char **domainp, NGR_R_ARGS) {
- char *mp, *up, *dp;
- int res = getnetgrent(&mp, &up, &dp);
-
- if (res != 1)
- return (res);
-
- return (copy_protoent(machinep, userp, domainp,
- mp, up, dp, NGR_R_COPY));
-}
-
-NGR_R_SET_RETURN
-#ifdef NGR_R_ENT_ARGS
-setnetgrent_r(const char *netgroup, NGR_R_ENT_ARGS)
-#else
-setnetgrent_r(const char *netgroup)
-#endif
-{
- setnetgrent(netgroup);
-#ifdef NGR_R_PRIVATE
- *buf = NULL;
-#endif
-#ifdef NGR_R_SET_RESULT
- return (NGR_R_SET_RESULT);
-#endif
-}
-
-NGR_R_END_RETURN
-#ifdef NGR_R_ENT_ARGS
-endnetgrent_r(NGR_R_ENT_ARGS)
-#else
-endnetgrent_r(void)
-#endif
-{
- endnetgrent();
-#ifdef NGR_R_PRIVATE
- if (*buf != NULL)
- free(*buf);
- *buf = NULL;
-#endif
- NGR_R_END_RESULT(NGR_R_OK);
-}
-
-/* Private */
-
-static int
-copy_protoent(char **machinep, char **userp, char **domainp,
- const char *mp, const char *up, const char *dp,
- NGR_R_COPY_ARGS) {
- char *cp;
- int n;
- int len;
-
- /* Find out the amount of space required to store the answer. */
- len = 0;
- if (mp != NULL) len += strlen(mp) + 1;
- if (up != NULL) len += strlen(up) + 1;
- if (dp != NULL) len += strlen(dp) + 1;
-
-#ifdef NGR_R_PRIVATE
- free(*buf);
- *buf = malloc(len);
- if (*buf == NULL)
- return(NGR_R_BAD);
- cp = *buf;
-#else
- if (len > (int)buflen) {
- errno = ERANGE;
- return (NGR_R_BAD);
- }
- cp = buf;
-#endif
-
-
- if (mp != NULL) {
- n = strlen(mp) + 1;
- strcpy(cp, mp);
- *machinep = cp;
- cp += n;
- } else
- *machinep = NULL;
-
- if (up != NULL) {
- n = strlen(up) + 1;
- strcpy(cp, up);
- *userp = cp;
- cp += n;
- } else
- *userp = NULL;
-
- if (dp != NULL) {
- n = strlen(dp) + 1;
- strcpy(cp, dp);
- *domainp = cp;
- cp += n;
- } else
- *domainp = NULL;
-
- return (NGR_R_OK);
-}
-#else /* NGR_R_RETURN */
- static int getnetgrent_r_unknown_system = 0;
-#endif /* NGR_R_RETURN */
-#endif /* !defined(_REENTRANT) || !defined(DO_PTHREADS) */
diff --git a/contrib/bind/lib/irs/getprotoent.c b/contrib/bind/lib/irs/getprotoent.c
deleted file mode 100644
index 724b0ad..0000000
--- a/contrib/bind/lib/irs/getprotoent.c
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: getprotoent.c,v 1.16 2001/11/01 07:34:33 marka Exp $";
-#endif
-
-/* Imports */
-
-#include "port_before.h"
-
-#if !defined(__BIND_NOSTATIC)
-
-#include <sys/types.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-
-#include <errno.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_data.h"
-
-/* Forward */
-
-static struct net_data *init(void);
-
-/* Public */
-
-struct protoent *
-getprotoent() {
- struct net_data *net_data = init();
-
- return (getprotoent_p(net_data));
-}
-
-struct protoent *
-getprotobyname(const char *name) {
- struct net_data *net_data = init();
-
- return (getprotobyname_p(name, net_data));
-}
-
-struct protoent *
-getprotobynumber(int proto) {
- struct net_data *net_data = init();
-
- return (getprotobynumber_p(proto, net_data));
-}
-
-void
-setprotoent(int stayopen) {
- struct net_data *net_data = init();
-
- setprotoent_p(stayopen, net_data);
-}
-
-void
-endprotoent() {
- struct net_data *net_data = init();
-
- endprotoent_p(net_data);
-}
-
-/* Shared private. */
-
-struct protoent *
-getprotoent_p(struct net_data *net_data) {
- struct irs_pr *pr;
-
- if (!net_data || !(pr = net_data->pr))
- return (NULL);
- net_data->pr_last = (*pr->next)(pr);
- return (net_data->pr_last);
-}
-
-struct protoent *
-getprotobyname_p(const char *name, struct net_data *net_data) {
- struct irs_pr *pr;
- char **pap;
-
- if (!net_data || !(pr = net_data->pr))
- return (NULL);
- if (net_data->pr_stayopen && net_data->pr_last) {
- if (!strcmp(net_data->pr_last->p_name, name))
- return (net_data->pr_last);
- for (pap = net_data->pr_last->p_aliases; pap && *pap; pap++)
- if (!strcmp(name, *pap))
- return (net_data->pr_last);
- }
- net_data->pr_last = (*pr->byname)(pr, name);
- if (!net_data->pr_stayopen)
- endprotoent();
- return (net_data->pr_last);
-}
-
-struct protoent *
-getprotobynumber_p(int proto, struct net_data *net_data) {
- struct irs_pr *pr;
-
- if (!net_data || !(pr = net_data->pr))
- return (NULL);
- if (net_data->pr_stayopen && net_data->pr_last)
- if (net_data->pr_last->p_proto == proto)
- return (net_data->pr_last);
- net_data->pr_last = (*pr->bynumber)(pr, proto);
- if (!net_data->pr_stayopen)
- endprotoent();
- return (net_data->pr_last);
-}
-
-void
-setprotoent_p(int stayopen, struct net_data *net_data) {
- struct irs_pr *pr;
-
- if (!net_data || !(pr = net_data->pr))
- return;
- (*pr->rewind)(pr);
- net_data->pr_stayopen = (stayopen != 0);
- if (stayopen == 0)
- net_data_minimize(net_data);
-}
-
-void
-endprotoent_p(struct net_data *net_data) {
- struct irs_pr *pr;
-
- if ((net_data != NULL) && ((pr = net_data->pr) != NULL))
- (*pr->minimize)(pr);
-}
-
-/* Private */
-
-static struct net_data *
-init() {
- struct net_data *net_data;
-
- if (!(net_data = net_data_init(NULL)))
- goto error;
- if (!net_data->pr) {
- net_data->pr = (*net_data->irs->pr_map)(net_data->irs);
-
- if (!net_data->pr || !net_data->res) {
- error:
- errno = EIO;
- return (NULL);
- }
- (*net_data->pr->res_set)(net_data->pr, net_data->res, NULL);
- }
-
- return (net_data);
-}
-
-#endif /*__BIND_NOSTATIC*/
diff --git a/contrib/bind/lib/irs/getprotoent_r.c b/contrib/bind/lib/irs/getprotoent_r.c
deleted file mode 100644
index fc3b17e..0000000
--- a/contrib/bind/lib/irs/getprotoent_r.c
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- * Copyright (c) 1998-1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: getprotoent_r.c,v 8.6 2001/11/01 08:02:14 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include <port_before.h>
-#if !defined(_REENTRANT) || !defined(DO_PTHREADS)
- static int getprotoent_r_not_required = 0;
-#else
-#include <errno.h>
-#include <string.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <port_after.h>
-
-#ifdef PROTO_R_RETURN
-
-static PROTO_R_RETURN
-copy_protoent(struct protoent *, struct protoent *, PROTO_R_COPY_ARGS);
-
-PROTO_R_RETURN
-getprotobyname_r(const char *name, struct protoent *pptr, PROTO_R_ARGS) {
- struct protoent *pe = getprotobyname(name);
-#ifdef PROTO_R_SETANSWER
- int n = 0;
-
- if (pe == NULL || (n = copy_protoent(pe, pptr, PROTO_R_COPY)) != 0)
- *answerp = NULL;
- else
- *answerp = pptr;
-
- return (n);
-#else
- if (pe == NULL)
- return (PROTO_R_BAD);
-
- return (copy_protoent(pe, pptr, PROTO_R_COPY));
-#endif
-}
-
-PROTO_R_RETURN
-getprotobynumber_r(int proto, struct protoent *pptr, PROTO_R_ARGS) {
- struct protoent *pe = getprotobynumber(proto);
-#ifdef PROTO_R_SETANSWER
- int n = 0;
-
- if (pe == NULL || (n = copy_protoent(pe, pptr, PROTO_R_COPY)) != 0)
- *answerp = NULL;
- else
- *answerp = pptr;
-
- return (n);
-#else
- if (pe == NULL)
- return (PROTO_R_BAD);
-
- return (copy_protoent(pe, pptr, PROTO_R_COPY));
-#endif
-}
-
-/*
- * These assume a single context is in operation per thread.
- * If this is not the case we will need to call irs directly
- * rather than through the base functions.
- */
-
-PROTO_R_RETURN
-getprotoent_r(struct protoent *pptr, PROTO_R_ARGS) {
- struct protoent *pe = getprotoent();
-#ifdef PROTO_R_SETANSWER
- int n = 0;
-
- if (pe == NULL || (n = copy_protoent(pe, pptr, PROTO_R_COPY)) != 0)
- *answerp = NULL;
- else
- *answerp = pptr;
-
- return (n);
-#else
- if (pe == NULL)
- return (PROTO_R_BAD);
-
- return (copy_protoent(pe, pptr, PROTO_R_COPY));
-#endif
-}
-
-PROTO_R_SET_RETURN
-#ifdef PROTO_R_ENT_ARGS
-setprotoent_r(int stay_open, PROTO_R_ENT_ARGS)
-#else
-setprotoent_r(int stay_open)
-#endif
-{
- setprotoent(stay_open);
-#ifdef PROTO_R_SET_RESULT
- return (PROTO_R_SET_RESULT);
-#endif
-}
-
-PROTO_R_END_RETURN
-#ifdef PROTO_R_ENT_ARGS
-endprotoent_r(PROTO_R_ENT_ARGS)
-#else
-endprotoent_r()
-#endif
-{
- endprotoent();
- PROTO_R_END_RESULT(PROTO_R_OK);
-}
-
-/* Private */
-
-#ifndef PROTOENT_DATA
-static PROTO_R_RETURN
-copy_protoent(struct protoent *pe, struct protoent *pptr, PROTO_R_COPY_ARGS) {
- char *cp;
- int i, n;
- int numptr, len;
-
- /* Find out the amount of space required to store the answer. */
- numptr = 1; /* NULL ptr */
- len = (char *)ALIGN(buf) - buf;
- for (i = 0; pe->p_aliases[i]; i++, numptr++) {
- len += strlen(pe->p_aliases[i]) + 1;
- }
- len += strlen(pe->p_name) + 1;
- len += numptr * sizeof(char*);
-
- if (len > (int)buflen) {
- errno = ERANGE;
- return (PROTO_R_BAD);
- }
-
- /* copy protocol value*/
- pptr->p_proto = pe->p_proto;
-
- cp = (char *)ALIGN(buf) + numptr * sizeof(char *);
-
- /* copy official name */
- n = strlen(pe->p_name) + 1;
- strcpy(cp, pe->p_name);
- pptr->p_name = cp;
- cp += n;
-
- /* copy aliases */
- pptr->p_aliases = (char **)ALIGN(buf);
- for (i = 0 ; pe->p_aliases[i]; i++) {
- n = strlen(pe->p_aliases[i]) + 1;
- strcpy(cp, pe->p_aliases[i]);
- pptr->p_aliases[i] = cp;
- cp += n;
- }
- pptr->p_aliases[i] = NULL;
-
- return (PROTO_R_OK);
-}
-#else /* !PROTOENT_DATA */
-static int
-copy_protoent(struct protoent *pe, struct protoent *pptr, PROTO_R_COPY_ARGS) {
- char *cp, *eob;
- int i, n;
-
- /* copy protocol value */
- pptr->p_proto = pe->p_proto;
-
- /* copy official name */
- cp = pdptr->line;
- eob = pdptr->line + sizeof(pdptr->line);
- if ((n = strlen(pe->p_name) + 1) < (eob - cp)) {
- strcpy(cp, pe->p_name);
- pptr->p_name = cp;
- cp += n;
- } else {
- return (-1);
- }
-
- /* copy aliases */
- i = 0;
- pptr->p_aliases = pdptr->proto_aliases;
- while (pe->p_aliases[i] && i < (_MAXALIASES-1)) {
- if ((n = strlen(pe->p_aliases[i]) + 1) < (eob - cp)) {
- strcpy(cp, pe->p_aliases[i]);
- pptr->p_aliases[i] = cp;
- cp += n;
- } else {
- break;
- }
- i++;
- }
- pptr->p_aliases[i] = NULL;
-
- return (PROTO_R_OK);
-}
-#endif /* PROTOENT_DATA */
-#else /* PROTO_R_RETURN */
- static int getprotoent_r_unknown_system = 0;
-#endif /* PROTO_R_RETURN */
-#endif /* !defined(_REENTRANT) || !defined(DO_PTHREADS) */
diff --git a/contrib/bind/lib/irs/getpwent.c b/contrib/bind/lib/irs/getpwent.c
deleted file mode 100644
index 7f536a4..0000000
--- a/contrib/bind/lib/irs/getpwent.c
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: getpwent.c,v 1.21 2000/02/21 21:40:56 vixie Exp $";
-#endif
-
-/* Imports */
-
-#include "port_before.h"
-
-#if !defined(WANT_IRS_PW) || defined(__BIND_NOSTATIC)
-static int __bind_irs_pw_unneeded;
-#else
-
-#include <sys/types.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-
-#include <errno.h>
-#include <pwd.h>
-#include <resolv.h>
-#include <stdio.h>
-
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_data.h"
-
-/* Forward */
-
-static struct net_data * init(void);
-
-/* Public */
-
-struct passwd *
-getpwent(void) {
- struct net_data *net_data = init();
-
- return (getpwent_p(net_data));
-}
-
-struct passwd *
-getpwnam(const char *name) {
- struct net_data *net_data = init();
-
- return (getpwnam_p(name, net_data));
-}
-
-struct passwd *
-getpwuid(uid_t uid) {
- struct net_data *net_data = init();
-
- return (getpwuid_p(uid, net_data));
-}
-
-int
-setpassent(int stayopen) {
- struct net_data *net_data = init();
-
- return (setpassent_p(stayopen, net_data));
-}
-
-#ifdef SETPWENT_VOID
-void
-setpwent() {
- struct net_data *net_data = init();
-
- setpwent_p(net_data);
-}
-#else
-int
-setpwent() {
- struct net_data *net_data = init();
-
- return (setpwent_p(net_data));
-}
-#endif
-
-void
-endpwent() {
- struct net_data *net_data = init();
-
- endpwent_p(net_data);
-}
-
-/* Shared private. */
-
-struct passwd *
-getpwent_p(struct net_data *net_data) {
- struct irs_pw *pw;
-
- if (!net_data || !(pw = net_data->pw))
- return (NULL);
- net_data->pw_last = (*pw->next)(pw);
- return (net_data->pw_last);
-}
-
-struct passwd *
-getpwnam_p(const char *name, struct net_data *net_data) {
- struct irs_pw *pw;
-
- if (!net_data || !(pw = net_data->pw))
- return (NULL);
- if (net_data->pw_stayopen && net_data->pw_last &&
- !strcmp(net_data->pw_last->pw_name, name))
- return (net_data->pw_last);
- net_data->pw_last = (*pw->byname)(pw, name);
- if (!net_data->pw_stayopen)
- endpwent();
- return (net_data->pw_last);
-}
-
-struct passwd *
-getpwuid_p(uid_t uid, struct net_data *net_data) {
- struct irs_pw *pw;
-
- if (!net_data || !(pw = net_data->pw))
- return (NULL);
- if (net_data->pw_stayopen && net_data->pw_last &&
- net_data->pw_last->pw_uid == uid)
- return (net_data->pw_last);
- net_data->pw_last = (*pw->byuid)(pw, uid);
- if (!net_data->pw_stayopen)
- endpwent();
- return (net_data->pw_last);
-}
-
-int
-setpassent_p(int stayopen, struct net_data *net_data) {
- struct irs_pw *pw;
-
- if (!net_data || !(pw = net_data->pw))
- return (0);
- (*pw->rewind)(pw);
- net_data->pw_stayopen = (stayopen != 0);
- if (stayopen == 0)
- net_data_minimize(net_data);
- return (1);
-}
-
-#ifdef SETPWENT_VOID
-void
-setpwent_p(struct net_data *net_data) {
- (void) setpassent_p(0, net_data);
-}
-#else
-int
-setpwent_p(struct net_data *net_data) {
- return (setpassent_p(0, net_data));
-}
-#endif
-
-void
-endpwent_p(struct net_data *net_data) {
- struct irs_pw *pw;
-
- if ((net_data != NULL) && ((pw = net_data->pw) != NULL))
- (*pw->minimize)(pw);
-}
-
-/* Private */
-
-static struct net_data *
-init() {
- struct net_data *net_data;
- if (!(net_data = net_data_init(NULL)))
- goto error;
- if (!net_data->pw) {
- net_data->pw = (*net_data->irs->pw_map)(net_data->irs);
-
- if (!net_data->pw || !net_data->res) {
- error:
- errno = EIO;
- return (NULL);
- }
- (*net_data->pw->res_set)(net_data->pw, net_data->res, NULL);
- }
-
- return (net_data);
-}
-
-#endif /* WANT_IRS_PW */
diff --git a/contrib/bind/lib/irs/getpwent_r.c b/contrib/bind/lib/irs/getpwent_r.c
deleted file mode 100644
index ee2d8a7..0000000
--- a/contrib/bind/lib/irs/getpwent_r.c
+++ /dev/null
@@ -1,275 +0,0 @@
-/*
- * Copyright (c) 1998-1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: getpwent_r.c,v 8.6 2001/11/01 08:02:15 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include <port_before.h>
-#if !defined(_REENTRANT) || !defined(DO_PTHREADS) || !defined(WANT_IRS_PW)
- static int getpwent_r_not_required = 0;
-#else
-#include <errno.h>
-#include <string.h>
-#include <stdio.h>
-#include <sys/types.h>
-#if (defined(POSIX_GETPWNAM_R) || defined(POSIX_GETPWUID_R))
-#if defined(_POSIX_PTHREAD_SEMANTICS)
- /* turn off solaris remapping in <grp.h> */
-#undef _POSIX_PTHREAD_SEMANTICS
-#include <pwd.h>
-#define _POSIX_PTHREAD_SEMANTICS 1
-#else
-#define _UNIX95 1
-#include <pwd.h>
-#endif
-#else
-#include <pwd.h>
-#endif
-#include <port_after.h>
-
-#ifdef PASS_R_RETURN
-
-static int
-copy_passwd(struct passwd *, struct passwd *, char *buf, int buflen);
-
-/* POSIX 1003.1c */
-#ifdef POSIX_GETPWNAM_R
-int
-__posix_getpwnam_r(const char *login, struct passwd *pwptr,
- char *buf, size_t buflen, struct passwd **result) {
-#else
-int
-getpwnam_r(const char *login, struct passwd *pwptr,
- char *buf, size_t buflen, struct passwd **result) {
-#endif
- struct passwd *pw = getpwnam(login);
- int res;
-
- if (pw == NULL) {
- *result = NULL;
- return (0);
- }
-
- res = copy_passwd(pw, pwptr, buf, buflen);
- *result = res ? NULL : pwptr;
- return (res);
-}
-
-#ifdef POSIX_GETPWNAM_R
-struct passwd *
-getpwnam_r(const char *login, struct passwd *pwptr, char *buf, int buflen) {
- struct passwd *pw = getpwnam(login);
- int res;
-
- if (pw == NULL)
- return (NULL);
-
- res = copy_passwd(pw, pwptr, buf, buflen);
- return (res ? NULL : pwptr);
-}
-#endif
-
-/* POSIX 1003.1c */
-#ifdef POSIX_GETPWUID_R
-int
-__posix_getpwuid_r(uid_t uid, struct passwd *pwptr,
- char *buf, int buflen, struct passwd **result) {
-#else
-int
-getpwuid_r(uid_t uid, struct passwd *pwptr,
- char *buf, size_t buflen, struct passwd **result) {
-#endif
- struct passwd *pw = getpwuid(uid);
- int res;
-
- if (pw == NULL) {
- *result = NULL;
- return (0);
- }
-
- res = copy_passwd(pw, pwptr, buf, buflen);
- *result = res ? NULL : pwptr;
- return (res);
-}
-
-#ifdef POSIX_GETPWUID_R
-struct passwd *
-getpwuid_r(uid_t uid, struct passwd *pwptr, char *buf, int buflen) {
- struct passwd *pw = getpwuid(uid);
- int res;
-
- if (pw == NULL)
- return (NULL);
-
- res = copy_passwd(pw, pwptr, buf, buflen);
- return (res ? NULL : pwptr);
-}
-#endif
-
-/*
- * These assume a single context is in operation per thread.
- * If this is not the case we will need to call irs directly
- * rather than through the base functions.
- */
-
-PASS_R_RETURN
-getpwent_r(struct passwd *pwptr, PASS_R_ARGS) {
- struct passwd *pw = getpwent();
- int res;
-
- if (pw == NULL)
- return (PASS_R_BAD);
-
- res = copy_passwd(pw, pwptr, buf, buflen);
- return (res ? PASS_R_BAD : PASS_R_OK);
-}
-
-PASS_R_SET_RETURN
-#ifdef PASS_R_ENT_ARGS
-setpassent_r(int stayopen, PASS_R_ENT_ARGS)
-#else
-setpassent_r(int stayopen)
-#endif
-{
-
- setpassent(stayopen);
-#ifdef PASS_R_SET_RESULT
- return (PASS_R_SET_RESULT);
-#endif
-}
-
-PASS_R_SET_RETURN
-#ifdef PASS_R_ENT_ARGS
-setpwent_r(PASS_R_ENT_ARGS)
-#else
-setpwent_r(void)
-#endif
-{
-
- setpwent();
-#ifdef PASS_R_SET_RESULT
- return (PASS_R_SET_RESULT);
-#endif
-}
-
-PASS_R_END_RETURN
-#ifdef PASS_R_ENT_ARGS
-endpwent_r(PASS_R_ENT_ARGS)
-#else
-endpwent_r(void)
-#endif
-{
-
- endpwent();
- PASS_R_END_RESULT(PASS_R_OK);
-}
-
-
-#ifdef HAS_FGETPWENT
-PASS_R_RETURN
-fgetpwent_r(FILE *f, struct passwd *pwptr, PASS_R_COPY_ARGS) {
- struct passwd *pw = fgetpwent(f);
- int res;
-
- if (pw == NULL)
- return (PASS_R_BAD);
-
- res = copy_passwd(pw, pwptr, PASS_R_COPY);
- return (res ? PASS_R_BAD : PASS_R_OK );
-}
-#endif
-
-/* Private */
-
-static int
-copy_passwd(struct passwd *pw, struct passwd *pwptr, char *buf, int buflen) {
- char *cp;
- int n;
- int len;
-
- /* Find out the amount of space required to store the answer. */
- len = strlen(pw->pw_name) + 1;
- len += strlen(pw->pw_passwd) + 1;
-#ifdef HAVE_PW_CLASS
- len += strlen(pw->pw_class) + 1;
-#endif
- len += strlen(pw->pw_gecos) + 1;
- len += strlen(pw->pw_dir) + 1;
- len += strlen(pw->pw_shell) + 1;
-
- if (len > buflen) {
- errno = ERANGE;
- return (ERANGE);
- }
-
- /* copy fixed atomic values*/
- pwptr->pw_uid = pw->pw_uid;
- pwptr->pw_gid = pw->pw_gid;
-#ifdef HAVE_PW_CHANGE
- pwptr->pw_change = pw->pw_change;
-#endif
-#ifdef HAVE_PW_EXPIRE
- pwptr->pw_expire = pw->pw_expire;
-#endif
-
- cp = buf;
-
- /* copy official name */
- n = strlen(pw->pw_name) + 1;
- strcpy(cp, pw->pw_name);
- pwptr->pw_name = cp;
- cp += n;
-
- /* copy password */
- n = strlen(pw->pw_passwd) + 1;
- strcpy(cp, pw->pw_passwd);
- pwptr->pw_passwd = cp;
- cp += n;
-
-#ifdef HAVE_PW_CLASS
- /* copy class */
- n = strlen(pw->pw_class) + 1;
- strcpy(cp, pw->pw_class);
- pwptr->pw_class = cp;
- cp += n;
-#endif
-
- /* copy gecos */
- n = strlen(pw->pw_gecos) + 1;
- strcpy(cp, pw->pw_gecos);
- pwptr->pw_gecos = cp;
- cp += n;
-
- /* copy directory */
- n = strlen(pw->pw_dir) + 1;
- strcpy(cp, pw->pw_dir);
- pwptr->pw_dir = cp;
- cp += n;
-
- /* copy login shell */
- n = strlen(pw->pw_shell) + 1;
- strcpy(cp, pw->pw_shell);
- pwptr->pw_shell = cp;
- cp += n;
-
- return (0);
-}
-#else /* PASS_R_RETURN */
- static int getpwent_r_unknown_system = 0;
-#endif /* PASS_R_RETURN */
-#endif /* !def(_REENTRANT) || !def(DO_PTHREADS) || !def(WANT_IRS_PW) */
diff --git a/contrib/bind/lib/irs/getservent.c b/contrib/bind/lib/irs/getservent.c
deleted file mode 100644
index d63ae1d..0000000
--- a/contrib/bind/lib/irs/getservent.c
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: getservent.c,v 1.17 2001/11/01 07:33:16 marka Exp $";
-#endif
-
-/* Imports */
-
-#include "port_before.h"
-
-#if !defined(__BIND_NOSTATIC)
-
-#include <sys/types.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-
-#include <errno.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_data.h"
-
-/* Forward */
-
-static struct net_data *init(void);
-
-/* Public */
-
-struct servent *
-getservent(void) {
- struct net_data *net_data = init();
-
- return (getservent_p(net_data));
-}
-
-struct servent *
-getservbyname(const char *name, const char *proto) {
- struct net_data *net_data = init();
-
- return (getservbyname_p(name, proto, net_data));
-}
-
-struct servent *
-getservbyport(int port, const char *proto) {
- struct net_data *net_data = init();
-
- return (getservbyport_p(port, proto, net_data));
-}
-
-void
-setservent(int stayopen) {
- struct net_data *net_data = init();
-
- setservent_p(stayopen, net_data);
-}
-
-void
-endservent() {
- struct net_data *net_data = init();
-
- endservent_p(net_data);
-}
-
-/* Shared private. */
-
-struct servent *
-getservent_p(struct net_data *net_data) {
- struct irs_sv *sv;
-
- if (!net_data || !(sv = net_data->sv))
- return (NULL);
- net_data->sv_last = (*sv->next)(sv);
- return (net_data->sv_last);
-}
-
-struct servent *
-getservbyname_p(const char *name, const char *proto,
- struct net_data *net_data) {
- struct irs_sv *sv;
- char **sap;
-
- if (!net_data || !(sv = net_data->sv))
- return (NULL);
- if (net_data->sv_stayopen && net_data->sv_last)
- if (!proto || !strcmp(net_data->sv_last->s_proto, proto)) {
- if (!strcmp(net_data->sv_last->s_name, name))
- return (net_data->sv_last);
- for (sap = net_data->sv_last->s_aliases;
- sap && *sap; sap++)
- if (!strcmp(name, *sap))
- return (net_data->sv_last);
- }
- net_data->sv_last = (*sv->byname)(sv, name, proto);
- if (!net_data->sv_stayopen)
- endservent();
- return (net_data->sv_last);
-}
-
-struct servent *
-getservbyport_p(int port, const char *proto, struct net_data *net_data) {
- struct irs_sv *sv;
-
- if (!net_data || !(sv = net_data->sv))
- return (NULL);
- if (net_data->sv_stayopen && net_data->sv_last)
- if (port == net_data->sv_last->s_port &&
- ( !proto ||
- !strcmp(net_data->sv_last->s_proto, proto)))
- return (net_data->sv_last);
- net_data->sv_last = (*sv->byport)(sv, port, proto);
- return (net_data->sv_last);
-}
-
-void
-setservent_p(int stayopen, struct net_data *net_data) {
- struct irs_sv *sv;
-
- if (!net_data || !(sv = net_data->sv))
- return;
- (*sv->rewind)(sv);
- net_data->sv_stayopen = (stayopen != 0);
- if (stayopen == 0)
- net_data_minimize(net_data);
-}
-
-void
-endservent_p(struct net_data *net_data) {
- struct irs_sv *sv;
-
- if ((net_data != NULL) && ((sv = net_data->sv) != NULL))
- (*sv->minimize)(sv);
-}
-
-/* Private */
-
-static struct net_data *
-init() {
- struct net_data *net_data;
-
- if (!(net_data = net_data_init(NULL)))
- goto error;
- if (!net_data->sv) {
- net_data->sv = (*net_data->irs->sv_map)(net_data->irs);
-
- if (!net_data->sv || !net_data->res) {
- error:
- errno = EIO;
- return (NULL);
- }
- (*net_data->sv->res_set)(net_data->sv, net_data->res, NULL);
- }
-
- return (net_data);
-}
-
-#endif /*__BIND_NOSTATIC*/
diff --git a/contrib/bind/lib/irs/getservent_r.c b/contrib/bind/lib/irs/getservent_r.c
deleted file mode 100644
index b4897ae..0000000
--- a/contrib/bind/lib/irs/getservent_r.c
+++ /dev/null
@@ -1,237 +0,0 @@
-/*
- * Copyright (c) 1998-1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: getservent_r.c,v 8.5 2001/11/01 08:02:16 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include <port_before.h>
-#if !defined(_REENTRANT) || !defined(DO_PTHREADS)
- static int getservent_r_not_required = 0;
-#else
-#include <errno.h>
-#include <string.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <sys/param.h>
-#include <port_after.h>
-
-#ifdef SERV_R_RETURN
-
-static SERV_R_RETURN
-copy_servent(struct servent *, struct servent *, SERV_R_COPY_ARGS);
-
-SERV_R_RETURN
-getservbyname_r(const char *name, const char *proto,
- struct servent *sptr, SERV_R_ARGS) {
- struct servent *se = getservbyname(name, proto);
-#ifdef SERV_R_SETANSWER
- int n = 0;
-
- if (se == NULL || (n = copy_servent(se, sptr, SERV_R_COPY)) != 0)
- *answerp = NULL;
- else
- *answerp = sptr;
-
- return (n);
-#else
- if (se == NULL)
- return (SERV_R_BAD);
-
- return (copy_servent(se, sptr, SERV_R_COPY));
-#endif
-}
-
-SERV_R_RETURN
-getservbyport_r(int port, const char *proto,
- struct servent *sptr, SERV_R_ARGS) {
- struct servent *se = getservbyport(port, proto);
-#ifdef SERV_R_SETANSWER
- int n = 0;
-
- if (se == NULL || (n = copy_servent(se, sptr, SERV_R_COPY)) != 0)
- *answerp = NULL;
- else
- *answerp = sptr;
-
- return (n);
-#else
- if (se == NULL)
- return (SERV_R_BAD);
-
- return (copy_servent(se, sptr, SERV_R_COPY));
-#endif
-}
-
-/*
- * These assume a single context is in operation per thread.
- * If this is not the case we will need to call irs directly
- * rather than through the base functions.
- */
-
-SERV_R_RETURN
-getservent_r(struct servent *sptr, SERV_R_ARGS) {
- struct servent *se = getservent();
-#ifdef SERV_R_SETANSWER
- int n = 0;
-
- if (se == NULL || (n = copy_servent(se, sptr, SERV_R_COPY)) != 0)
- *answerp = NULL;
- else
- *answerp = sptr;
-
- return (n);
-#else
- if (se == NULL)
- return (SERV_R_BAD);
-
- return (copy_servent(se, sptr, SERV_R_COPY));
-#endif
-}
-
-SERV_R_SET_RETURN
-#ifdef SERV_R_ENT_ARGS
-setservent_r(int stay_open, SERV_R_ENT_ARGS)
-#else
-setservent_r(int stay_open)
-#endif
-{
-
- setservent(stay_open);
-#ifdef SERV_R_SET_RESULT
- return (SERV_R_SET_RESULT);
-#endif
-}
-
-SERV_R_END_RETURN
-#ifdef SERV_R_ENT_ARGS
-endservent_r(SERV_R_ENT_ARGS)
-#else
-endservent_r()
-#endif
-{
-
- endservent();
- SERV_R_END_RESULT(SERV_R_OK);
-}
-
-/* Private */
-
-#ifndef SERVENT_DATA
-static SERV_R_RETURN
-copy_servent(struct servent *se, struct servent *sptr, SERV_R_COPY_ARGS) {
- char *cp;
- int i, n;
- int numptr, len;
-
- /* Find out the amount of space required to store the answer. */
- numptr = 1; /* NULL ptr */
- len = (char *)ALIGN(buf) - buf;
- for (i = 0; se->s_aliases[i]; i++, numptr++) {
- len += strlen(se->s_aliases[i]) + 1;
- }
- len += strlen(se->s_name) + 1;
- len += strlen(se->s_proto) + 1;
- len += numptr * sizeof(char*);
-
- if (len > (int)buflen) {
- errno = ERANGE;
- return (SERV_R_BAD);
- }
-
- /* copy port value */
- sptr->s_port = se->s_port;
-
- cp = (char *)ALIGN(buf) + numptr * sizeof(char *);
-
- /* copy official name */
- n = strlen(se->s_name) + 1;
- strcpy(cp, se->s_name);
- sptr->s_name = cp;
- cp += n;
-
- /* copy aliases */
- sptr->s_aliases = (char **)ALIGN(buf);
- for (i = 0 ; se->s_aliases[i]; i++) {
- n = strlen(se->s_aliases[i]) + 1;
- strcpy(cp, se->s_aliases[i]);
- sptr->s_aliases[i] = cp;
- cp += n;
- }
- sptr->s_aliases[i] = NULL;
-
- /* copy proto */
- n = strlen(se->s_proto) + 1;
- strcpy(cp, se->s_proto);
- sptr->s_proto = cp;
- cp += n;
-
- return (SERV_R_OK);
-}
-#else /* !SERVENT_DATA */
-static int
-copy_servent(struct servent *se, struct servent *sptr, SERV_R_COPY_ARGS) {
- char *cp, *eob;
- int i, n;
-
- /* copy port value */
- sptr->s_port = se->s_port;
-
- /* copy official name */
- cp = ndptr->line;
- eob = ndptr->line + sizeof(ndptr->line);
- if ((n = strlen(se->s_name) + 1) < (eob - cp)) {
- strcpy(cp, se->s_name);
- sptr->s_name = cp;
- cp += n;
- } else {
- return (-1);
- }
-
- /* copy aliases */
- i = 0;
- sptr->s_aliases = ndptr->serv_aliases;
- while (se->s_aliases[i] && i < (_MAXALIASES-1)) {
- if ((n = strlen(se->s_aliases[i]) + 1) < (eob - cp)) {
- strcpy(cp, se->s_aliases[i]);
- sptr->s_aliases[i] = cp;
- cp += n;
- } else {
- break;
- }
- i++;
- }
- sptr->s_aliases[i] = NULL;
-
- /* copy proto */
- if ((n = strlen(se->s_proto) + 1) < (eob - cp)) {
- strcpy(cp, se->s_proto);
- sptr->s_proto = cp;
- cp += n;
- } else {
- return (-1);
- }
-
- return (SERV_R_OK);
-}
-#endif /* !SERVENT_DATA */
-#else /*SERV_R_RETURN */
- static int getservent_r_unknown_system = 0;
-#endif /*SERV_R_RETURN */
-#endif /* !defined(_REENTRANT) || !defined(DO_PTHREADS) */
diff --git a/contrib/bind/lib/irs/hesiod.c b/contrib/bind/lib/irs/hesiod.c
deleted file mode 100644
index 5afe661..0000000
--- a/contrib/bind/lib/irs/hesiod.c
+++ /dev/null
@@ -1,524 +0,0 @@
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: hesiod.c,v 1.23 2002/07/18 02:07:45 marka Exp $";
-#endif
-
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-/*
- * This file is primarily maintained by <tytso@mit.edu> and <ghudson@mit.edu>.
- */
-
-/*
- * hesiod.c --- the core portion of the hesiod resolver.
- *
- * 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.
- */
-
-/* Imports */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-
-#include <errno.h>
-#include <netdb.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "port_after.h"
-
-#include "pathnames.h"
-#include "hesiod.h"
-#include "hesiod_p.h"
-
-/* Forward */
-
-int hesiod_init(void **context);
-void hesiod_end(void *context);
-char * hesiod_to_bind(void *context, const char *name,
- const char *type);
-char ** hesiod_resolve(void *context, const char *name,
- const char *type);
-void hesiod_free_list(void *context, char **list);
-
-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);
-static int init(struct hesiod_p *ctx);
-
-/* Public */
-
-/*
- * This function is called to initialize a hesiod_p.
- */
-int
-hesiod_init(void **context) {
- struct hesiod_p *ctx;
- char *cp;
-
- ctx = malloc(sizeof(struct hesiod_p));
- if (ctx == 0) {
- errno = ENOMEM;
- return (-1);
- }
-
- ctx->LHS = NULL;
- ctx->RHS = NULL;
- ctx->res = NULL;
-
- if (parse_config_file(ctx, _PATH_HESIOD_CONF) < 0) {
-#ifdef DEF_RHS
- /*
- * Use compiled in defaults.
- */
- ctx->LHS = malloc(strlen(DEF_LHS)+1);
- ctx->RHS = malloc(strlen(DEF_RHS)+1);
- if (ctx->LHS == 0 || ctx->RHS == 0) {
- errno = ENOMEM;
- goto cleanup;
- }
-#ifdef HAVE_STRLCPY
- strlcpy(ctx->LHS, DEF_LHS, strlen(DEF_LHS) + 1);
- strlcpy(ctx->RHS, DEF_RHS, strlen(DEF_RHS) + 1);
-#else
- strcpy(ctx->LHS, DEF_LHS);
- strcpy(ctx->RHS, DEF_RHS);
-#endif
-#else
- goto cleanup;
-#endif
- }
- /*
- * The default RHS can be overridden by an environment
- * variable.
- */
- if ((cp = getenv("HES_DOMAIN")) != NULL) {
- size_t RHSlen = strlen(cp) + 2;
- if (ctx->RHS)
- free(ctx->RHS);
- ctx->RHS = malloc(RHSlen);
- if (!ctx->RHS) {
- errno = ENOMEM;
- goto cleanup;
- }
- if (cp[0] == '.') {
-#ifdef HAVE_STRLCPY
- strlcpy(ctx->RHS, cp, RHSlen);
-#else
- strcpy(ctx->RHS, cp);
-#endif
- } else {
-#ifdef HAVE_STRLCPY
- strlcpy(ctx->RHS, ".", RHSlen);
-#else
- strcpy(ctx->RHS, ".");
-#endif
-#ifdef HAVE_STRLCAT
- strlcat(ctx->RHS, cp, RHSlen);
-#else
- strcat(ctx->RHS, cp);
-#endif
- }
- }
-
- /*
- * If there is no default hesiod realm set, we return an
- * error.
- */
- if (!ctx->RHS) {
- errno = ENOEXEC;
- goto cleanup;
- }
-
-#if 0
- if (res_ninit(ctx->res) < 0)
- goto cleanup;
-#endif
-
- *context = ctx;
- return (0);
-
- cleanup:
- hesiod_end(ctx);
- return (-1);
-}
-
-/*
- * This function deallocates the hesiod_p
- */
-void
-hesiod_end(void *context) {
- struct hesiod_p *ctx = (struct hesiod_p *) context;
- int save_errno = errno;
-
- if (ctx->res)
- res_nclose(ctx->res);
- if (ctx->RHS)
- free(ctx->RHS);
- if (ctx->LHS)
- free(ctx->LHS);
- if (ctx->res && ctx->free_res)
- (*ctx->free_res)(ctx->res);
- free(ctx);
- errno = save_errno;
-}
-
-/*
- * This function takes a hesiod (name, type) and returns a DNS
- * name which is to be resolved.
- */
-char *
-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;
-
- /* 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 {
- 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) {
- errno = ENOMEM;
- if (rhs_list)
- hesiod_free_list(context, rhs_list);
- return NULL;
- }
-
- /* Now put together the DNS name. */
- memcpy(bindname, name, cp - name);
- bindname[cp - name] = '\0';
- strcat(bindname, ".");
- strcat(bindname, type);
- if (ctx->LHS) {
- if (ctx->LHS[0] != '.')
- strcat(bindname, ".");
- strcat(bindname, ctx->LHS);
- }
- if (RHS[0] != '.')
- strcat(bindname, ".");
- strcat(bindname, RHS);
-
- if (rhs_list)
- hesiod_free_list(context, rhs_list);
-
- return (bindname);
-}
-
-/*
- * This is the core function. Given a hesiod (name, type), it
- * returns an array of strings returned by the resolver.
- */
-char **
-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);
- if (init(ctx) == -1) {
- free(bindname);
- return (NULL);
- }
-
- if ((retvec = get_txt_records(ctx, C_IN, bindname))) {
- free(bindname);
- return (retvec);
- }
-
- if (errno != ENOENT)
- return (NULL);
-
- retvec = get_txt_records(ctx, C_HS, bindname);
- free(bindname);
- return (retvec);
-}
-
-void
-hesiod_free_list(void *context, char **list) {
- char **p;
-
- UNUSED(context);
-
- for (p = list; *p; p++)
- free(*p);
- free(list);
-}
-
-/*
- * This function parses the /etc/hesiod.conf file
- */
-static int
-parse_config_file(struct hesiod_p *ctx, const char *filename) {
- char *key, *data, *cp, **cpp;
- char buf[MAXDNAME+7];
- FILE *fp;
-
- /*
- * Clear the existing configuration variable, just in case
- * they're set.
- */
- if (ctx->RHS)
- free(ctx->RHS);
- if (ctx->LHS)
- free(ctx->LHS);
- ctx->RHS = ctx->LHS = 0;
-
- /*
- * Now open and parse the file...
- */
- if (!(fp = fopen(filename, "r")))
- return (-1);
-
- while (fgets(buf, sizeof(buf), fp) != NULL) {
- cp = buf;
- if (*cp == '#' || *cp == '\n' || *cp == '\r')
- continue;
- while(*cp == ' ' || *cp == '\t')
- cp++;
- key = cp;
- while(*cp != ' ' && *cp != '\t' && *cp != '=')
- cp++;
- *cp++ = '\0';
-
- while(*cp == ' ' || *cp == '\t' || *cp == '=')
- cp++;
- data = cp;
- while(*cp != ' ' && *cp != '\n' && *cp != '\r')
- cp++;
- *cp++ = '\0';
-
- if (strcmp(key, "lhs") == 0)
- cpp = &ctx->LHS;
- else if (strcmp(key, "rhs") == 0)
- cpp = &ctx->RHS;
- else
- continue;
-
- *cpp = malloc(strlen(data) + 1);
- if (!*cpp) {
- errno = ENOMEM;
- goto cleanup;
- }
- strcpy(*cpp, data);
- }
- fclose(fp);
- return (0);
-
- cleanup:
- fclose(fp);
- if (ctx->RHS)
- free(ctx->RHS);
- if (ctx->LHS)
- free(ctx->LHS);
- ctx->RHS = ctx->LHS = 0;
- return (-1);
-}
-
-/*
- * Given a DNS class and a DNS name, do a lookup for TXT records, and
- * return a list of them.
- */
-static char **
-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.
- */
- n = res_nmkquery(ctx->res, QUERY, name, class, T_TXT, NULL, 0,
- NULL, qbuf, MAX_HESRESP);
- if (n < 0) {
- errno = EMSGSIZE;
- return (NULL);
- }
- n = res_nsend(ctx->res, qbuf, n, abuf, MAX_HESRESP);
- if (n < 0) {
- errno = ECONNREFUSED;
- return (NULL);
- }
- if (n < HFIXEDSZ) {
- errno = EMSGSIZE;
- return (NULL);
- }
-
- /*
- * 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) {
- errno = EMSGSIZE;
- return (NULL);
- }
- cp += skip + QFIXEDSZ;
- }
-
- list = malloc((ancount + 1) * sizeof(char *));
- if (!list) {
- errno = ENOMEM;
- return (NULL);
- }
- j = 0;
- for (i = 0; i < ancount; i++) {
- skip = dn_skipname(cp, eom);
- if (skip < 0) {
- errno = EMSGSIZE;
- goto cleanup;
- }
- cp += skip;
- if (cp + 3 * INT16SZ + INT32SZ > eom) {
- 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;
- if (cp + rr.dlen > eom) {
- 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) {
- errno = EMSGSIZE;
- goto cleanup;
- }
- memcpy(dst, cp, n);
- cp += n;
- dst += n;
- }
- if (cp != erdata) {
- errno = EMSGSIZE;
- goto cleanup;
- }
- *dst = '\0';
- }
- list[j] = NULL;
- if (j == 0) {
- errno = ENOENT;
- goto cleanup;
- }
- return (list);
-
- cleanup:
- for (i = 0; i < j; i++)
- free(list[i]);
- free(list);
- return (NULL);
-}
-
-struct __res_state *
-__hesiod_res_get(void *context) {
- struct hesiod_p *ctx = context;
-
- if (!ctx->res) {
- struct __res_state *res;
- res = (struct __res_state *)malloc(sizeof *res);
- if (res == NULL) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(res, 0, sizeof *res);
- __hesiod_res_set(ctx, res, free);
- }
-
- return (ctx->res);
-}
-
-void
-__hesiod_res_set(void *context, struct __res_state *res,
- void (*free_res)(void *)) {
- struct hesiod_p *ctx = context;
-
- if (ctx->res && ctx->free_res) {
- res_nclose(ctx->res);
- (*ctx->free_res)(ctx->res);
- }
-
- ctx->res = res;
- ctx->free_res = free_res;
-}
-
-static int
-init(struct hesiod_p *ctx) {
-
- if (!ctx->res && !__hesiod_res_get(ctx))
- return (-1);
-
- if (((ctx->res->options & RES_INIT) == 0) &&
- (res_ninit(ctx->res) == -1))
- return (-1);
-
- return (0);
-}
diff --git a/contrib/bind/lib/irs/hesiod_p.h b/contrib/bind/lib/irs/hesiod_p.h
deleted file mode 100644
index eb32166..0000000
--- a/contrib/bind/lib/irs/hesiod_p.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-/*
- * This file is primarily maintained by <tytso@mit.edu> and <ghudson@mit.edu>.
- */
-
-/*
- * $Id: hesiod_p.h,v 1.9 1999/01/08 19:24:39 vixie Exp $
- */
-
-/*
- * hesiod_p.h -- private definitions for the hesiod library
- */
-
-#ifndef _HESIOD_P_H_INCLUDED
-#define _HESIOD_P_H_INCLUDED
-
-#define DEF_RHS ".Athena.MIT.EDU" /* Defaults if HESIOD_CONF */
-#define DEF_LHS ".ns" /* file is not */
- /* present. */
-struct hesiod_p {
- char * LHS; /* normally ".ns" */
- char * RHS; /* AKA the default hesiod domain */
- struct __res_state * res; /* resolver context */
- void (*free_res)(void *);
- void (*res_set)(struct hesiod_p *, struct __res_state *,
- void (*)(void *));
- struct __res_state * (*res_get)(struct hesiod_p *);
-};
-
-#define MAX_HESRESP 1024
-
-#endif /*_HESIOD_P_H_INCLUDED*/
diff --git a/contrib/bind/lib/irs/irp.c b/contrib/bind/lib/irs/irp.c
deleted file mode 100644
index fa28b3f..0000000
--- a/contrib/bind/lib/irs/irp.c
+++ /dev/null
@@ -1,592 +0,0 @@
-/*
- * Copyright (c) 1996, 1998 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.
- */
-
-#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: irp.c,v 8.8 2001/09/25 04:50:29 marka Exp $";
-#endif
-
-/* Imports */
-
-#include "port_before.h"
-
-#include <syslog.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-#include <stdarg.h>
-#include <fcntl.h>
-#include <syslog.h>
-#include <ctype.h>
-#include <unistd.h>
-
-#include <isc/memcluster.h>
-
-#include <irs.h>
-#include <irp.h>
-
-#include "irs_p.h"
-#include "irp_p.h"
-
-#include "port_after.h"
-
-/* Forward. */
-
-static void irp_close(struct irs_acc *);
-
-#define LINEINCR 128
-
-#if !defined(SUN_LEN)
-#define SUN_LEN(su) \
- (sizeof (*(su)) - sizeof ((su)->sun_path) + strlen((su)->sun_path))
-#endif
-
-
-/* Public */
-
-
-/* send errors to syslog if true. */
-int irp_log_errors = 1;
-
-/*
- * This module handles the irp module connection to irpd.
- *
- * The client expects a synchronous interface to functions like
- * getpwnam(3), so we can't use the ctl_* i/o library on this end of
- * the wire (it's used in the server).
- */
-
-/*
- * irs_acc *irs_irp_acc(const char *options);
- *
- * Initialize the irp module.
- */
-struct irs_acc *
-irs_irp_acc(const char *options) {
- struct irs_acc *acc;
- struct irp_p *irp;
-
- UNUSED(options);
-
- if (!(acc = memget(sizeof *acc))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(acc, 0x5e, sizeof *acc);
- if (!(irp = memget(sizeof *irp))) {
- errno = ENOMEM;
- free(acc);
- return (NULL);
- }
- irp->inlast = 0;
- irp->incurr = 0;
- irp->fdCxn = -1;
- acc->private = irp;
-
-#ifdef WANT_IRS_GR
- acc->gr_map = irs_irp_gr;
-#else
- acc->gr_map = NULL;
-#endif
-#ifdef WANT_IRS_PW
- acc->pw_map = irs_irp_pw;
-#else
- acc->pw_map = NULL;
-#endif
- acc->sv_map = irs_irp_sv;
- acc->pr_map = irs_irp_pr;
- acc->ho_map = irs_irp_ho;
- acc->nw_map = irs_irp_nw;
- acc->ng_map = irs_irp_ng;
- acc->close = irp_close;
- return (acc);
-}
-
-
-int
-irs_irp_connection_setup(struct irp_p *cxndata, int *warned) {
- if (irs_irp_is_connected(cxndata)) {
- return (0);
- } else if (irs_irp_connect(cxndata) != 0) {
- if (warned != NULL && !*warned) {
- syslog(LOG_ERR, "irpd connection failed: %m\n");
- (*warned)++;
- }
-
- return (-1);
- }
-
- return (0);
-}
-
-
-/*
- * int irs_irp_connect(void);
- *
- * Sets up the connection to the remote irpd server.
- *
- * Returns:
- *
- * 0 on success, -1 on failure.
- *
- */
-int
-irs_irp_connect(struct irp_p *pvt) {
- int flags;
- struct sockaddr *addr;
- struct sockaddr_in iaddr;
-#ifndef NO_SOCKADDR_UN
- struct sockaddr_un uaddr;
-#endif
- long ipaddr;
- const char *irphost;
- int code;
- char text[256];
- int socklen = 0;
-
- if (pvt->fdCxn != -1) {
- perror("fd != 1");
- return (-1);
- }
-
-#ifndef NO_SOCKADDR_UN
- memset(&uaddr, 0, sizeof uaddr);
-#endif
- memset(&iaddr, 0, sizeof iaddr);
-
- irphost = getenv(IRPD_HOST_ENV);
- if (irphost == NULL) {
- irphost = "127.0.0.1";
- }
-
-#ifndef NO_SOCKADDR_UN
- if (irphost[0] == '/') {
- addr = (struct sockaddr *)&uaddr;
- strncpy(uaddr.sun_path, irphost, sizeof uaddr.sun_path);
- uaddr.sun_family = AF_UNIX;
- socklen = SUN_LEN(&uaddr);
-#ifdef HAVE_SA_LEN
- uaddr.sun_len = socklen;
-#endif
- } else
-#endif
- {
- if (inet_pton(AF_INET, irphost, &ipaddr) != 1) {
- errno = EADDRNOTAVAIL;
- perror("inet_pton");
- return (-1);
- }
-
- addr = (struct sockaddr *)&iaddr;
- socklen = sizeof iaddr;
-#ifdef HAVE_SA_LEN
- iaddr.sin_len = socklen;
-#endif
- iaddr.sin_family = AF_INET;
- iaddr.sin_port = htons(IRPD_PORT);
- iaddr.sin_addr.s_addr = ipaddr;
- }
-
-
- pvt->fdCxn = socket(addr->sa_family, SOCK_STREAM, PF_UNSPEC);
- if (pvt->fdCxn < 0) {
- perror("socket");
- return (-1);
- }
-
- if (connect(pvt->fdCxn, addr, socklen) != 0) {
- perror("connect");
- return (-1);
- }
-
- flags = fcntl(pvt->fdCxn, F_GETFL, 0);
- if (flags < 0) {
- close(pvt->fdCxn);
- perror("close");
- return (-1);
- }
-
-#if 0
- flags |= O_NONBLOCK;
- if (fcntl(pvt->fdCxn, F_SETFL, flags) < 0) {
- close(pvt->fdCxn);
- perror("fcntl");
- return (-1);
- }
-#endif
-
- code = irs_irp_read_response(pvt, text, sizeof text);
- if (code != IRPD_WELCOME_CODE) {
- if (irp_log_errors) {
- syslog(LOG_WARNING, "Connection failed: %s", text);
- }
- irs_irp_disconnect(pvt);
- return (-1);
- }
-
- return (0);
-}
-
-
-
-/*
- * int irs_irp_is_connected(struct irp_p *pvt);
- *
- * Returns:
- *
- * Non-zero if streams are setup to remote.
- *
- */
-
-int
-irs_irp_is_connected(struct irp_p *pvt) {
- return (pvt->fdCxn >= 0);
-}
-
-
-
-/*
- * void
- * irs_irp_disconnect(struct irp_p *pvt);
- *
- * Closes streams to remote.
- */
-
-void
-irs_irp_disconnect(struct irp_p *pvt) {
- if (pvt->fdCxn != -1) {
- close(pvt->fdCxn);
- pvt->fdCxn = -1;
- }
-}
-
-
-
-int
-irs_irp_read_line(struct irp_p *pvt, char *buffer, int len) {
- char *realstart = &pvt->inbuffer[0];
- char *p, *start, *end;
- int spare;
- int i;
- int buffpos = 0;
- int left = len - 1;
-
- while (left > 0) {
- start = p = &pvt->inbuffer[pvt->incurr];
- end = &pvt->inbuffer[pvt->inlast];
-
- while (p != end && *p != '\n')
- p++;
-
- if (p == end) {
- /* Found no newline so shift data down if necessary
- * and append new data to buffer
- */
- if (start > realstart) {
- memmove(realstart, start, end - start);
- pvt->inlast = end - start;
- start = realstart;
- pvt->incurr = 0;
- end = &pvt->inbuffer[pvt->inlast];
- }
-
- spare = sizeof (pvt->inbuffer) - pvt->inlast;
-
- p = end;
- i = read(pvt->fdCxn, end, spare);
- if (i < 0) {
- close(pvt->fdCxn);
- pvt->fdCxn = -1;
- return (buffpos > 0 ? buffpos : -1);
- } else if (i == 0) {
- return (buffpos);
- }
-
- end += i;
- pvt->inlast += i;
-
- while (p != end && *p != '\n')
- p++;
- }
-
- if (p == end) {
- /* full buffer and still no newline */
- i = sizeof pvt->inbuffer;
- } else {
- /* include newline */
- i = p - start + 1;
- }
-
- if (i > left)
- i = left;
- memcpy(buffer + buffpos, start, i);
- pvt->incurr += i;
- buffpos += i;
- buffer[buffpos] = '\0';
-
- if (p != end) {
- left = 0;
- } else {
- left -= i;
- }
- }
-
-#if 0
- fprintf(stderr, "read line: %s\n", buffer);
-#endif
- return (buffpos);
-}
-
-
-
-
-
-/*
- * int irp_read_response(struct irp_p *pvt);
- *
- * Returns:
- *
- * The number found at the beginning of the line read from
- * FP. 0 on failure(0 is not a legal response code). The
- * rest of the line is discarded.
- *
- */
-
-int
-irs_irp_read_response(struct irp_p *pvt, char *text, size_t textlen) {
- char line[1024];
- int code;
- char *p;
-
- if (irs_irp_read_line(pvt, line, sizeof line) <= 0) {
- return (0);
- }
-
- p = strchr(line, '\n');
- if (p == NULL) {
- return (0);
- }
-
- if (sscanf(line, "%d", &code) != 1) {
- code = 0;
- } else if (text != NULL && textlen > 0) {
- p = line;
- while (isspace((unsigned char)*p)) p++;
- while (isdigit((unsigned char)*p)) p++;
- while (isspace((unsigned char)*p)) p++;
- strncpy(text, p, textlen - 1);
- p[textlen - 1] = '\0';
- }
-
- return (code);
-}
-
-
-
-/*
- * char *irp_read_body(struct irp_p *pvt, size_t *size);
- *
- * Read in the body of a response. Terminated by a line with
- * just a dot on it. Lines should be terminated with a CR-LF
- * sequence, but we're nt piccky if the CR is missing.
- * No leading dot escaping is done as the protcol doesn't
- * use leading dots anywhere.
- *
- * Returns:
- *
- * Pointer to null-terminated buffer allocated by memget.
- * *SIZE is set to the length of the buffer.
- *
- */
-
-char *
-irs_irp_read_body(struct irp_p *pvt, size_t *size) {
- char line[1024];
- u_int linelen;
- size_t len = LINEINCR;
- char *buffer = memget(len);
- int idx = 0;
-
- for (;;) {
- if (irs_irp_read_line(pvt, line, sizeof line) <= 0 ||
- strchr(line, '\n') == NULL)
- goto death;
-
- linelen = strlen(line);
-
- if (line[linelen - 1] != '\n')
- goto death;
-
- /* We're not strict about missing \r. Should we be?? */
- if (linelen > 2 && line[linelen - 2] == '\r') {
- line[linelen - 2] = '\n';
- line[linelen - 1] = '\0';
- linelen--;
- }
-
- if (linelen == 2 && line[0] == '.') {
- *size = len;
- buffer[idx] = '\0';
-
- return (buffer);
- }
-
- if (linelen > (len - (idx + 1))) {
- char *p = memget(len + LINEINCR);
-
- if (p == NULL)
- goto death;
- memcpy(p, buffer, len);
- memput(buffer, len);
- buffer = p;
- len += LINEINCR;
- }
-
- memcpy(buffer + idx, line, linelen);
- idx += linelen;
- }
- death:
- memput(buffer, len);
- return (NULL);
-}
-
-
-/*
- * int irs_irp_get_full_response(struct irp_p *pvt, int *code,
- * char **body, size_t *bodylen);
- *
- * Gets the response to a command. If the response indicates
- * there's a body to follow(code % 10 == 1), then the
- * body buffer is allcoated with memget and stored in
- * *BODY. The length of the allocated body buffer is stored
- * in *BODY. The caller must give the body buffer back to
- * memput when done. The results code is stored in *CODE.
- *
- * Returns:
- *
- * 0 if a result was read. -1 on some sort of failure.
- *
- */
-
-int
-irs_irp_get_full_response(struct irp_p *pvt, int *code, char *text,
- size_t textlen, char **body, size_t *bodylen) {
- int result = irs_irp_read_response(pvt, text, textlen);
-
- *body = NULL;
-
- if (result == 0) {
- return (-1);
- }
-
- *code = result;
-
- /* Code that matches 2xx is a good result code.
- * Code that matches xx1 means there's a response body coming.
- */
- if ((result / 100) == 2 && (result % 10) == 1) {
- *body = irs_irp_read_body(pvt, bodylen);
- if (*body == NULL) {
- return (-1);
- }
- }
-
- return (0);
-}
-
-
-/*
- * int irs_irp_send_command(struct irp_p *pvt, const char *fmt, ...);
- *
- * Sends command to remote connected via the PVT
- * struture. FMT and args after it are fprintf-like
- * arguments for formatting.
- *
- * Returns:
- *
- * 0 on success, -1 on failure.
- */
-
-int
-irs_irp_send_command(struct irp_p *pvt, const char *fmt, ...) {
- va_list ap;
- char buffer[1024];
- int pos = 0;
- int i, todo;
-
-
- if (pvt->fdCxn < 0) {
- return (-1);
- }
-
- va_start(ap, fmt);
- todo = vsprintf(buffer, fmt, ap);
- va_end(ap);
- if (todo > (int)sizeof(buffer) - 3) {
- syslog(LOG_CRIT, "memory overrun in irs_irp_send_command()");
- exit(1);
- }
- strcat(buffer, "\r\n");
- todo = strlen(buffer);
-
- while (todo > 0) {
- i = write(pvt->fdCxn, buffer + pos, todo);
-#if 0
- /* XXX brister */
- fprintf(stderr, "Wrote: \"");
- fwrite(buffer + pos, sizeof (char), todo, stderr);
- fprintf(stderr, "\"\n");
-#endif
- if (i < 0) {
- close(pvt->fdCxn);
- pvt->fdCxn = -1;
- return (-1);
- }
- todo -= i;
- }
-
- return (0);
-}
-
-
-/* Methods */
-
-
-
-/*
- * void irp_close(struct irs_acc *this)
- *
- */
-
-static void
-irp_close(struct irs_acc *this) {
- struct irp_p *irp = (struct irp_p *)this->private;
-
- if (irp != NULL) {
- irs_irp_disconnect(irp);
- memput(irp, sizeof *irp);
- }
-
- memput(this, sizeof *this);
-}
-
-
-
diff --git a/contrib/bind/lib/irs/irp_gr.c b/contrib/bind/lib/irs/irp_gr.c
deleted file mode 100644
index c235e19..0000000
--- a/contrib/bind/lib/irs/irp_gr.c
+++ /dev/null
@@ -1,408 +0,0 @@
-/*
- * Portions Copyright(c) 1996, 1998 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: irp_gr.c,v 8.3 2001/05/29 05:48:57 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-/* extern */
-
-#include "port_before.h"
-
-#ifndef WANT_IRS_PW
-static int __bind_irs_gr_unneeded;
-#else
-
-#include <syslog.h>
-#include <sys/param.h>
-#include <sys/types.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <grp.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <syslog.h>
-
-#include <irs.h>
-#include <irp.h>
-#include <isc/memcluster.h>
-#include <isc/irpmarshall.h>
-
-#include "irs_p.h"
-#include "lcl_p.h"
-#include "irp_p.h"
-
-#include "port_after.h"
-
-
-/* Types. */
-
-/*
- * Module for the getnetgrent(3) family to use when connected to a
- * remote irp daemon.
- *
- * See irpd.c for justification of caching done here.
- *
- */
-
-struct pvt {
- struct irp_p *girpdata; /* global IRP data */
- int warned;
- struct group group;
-};
-
-/* Forward. */
-
-static void gr_close(struct irs_gr *);
-static struct group * gr_next(struct irs_gr *);
-static struct group * gr_byname(struct irs_gr *, const char *);
-static struct group * gr_bygid(struct irs_gr *, gid_t);
-static void gr_rewind(struct irs_gr *);
-static void gr_minimize(struct irs_gr *);
-
-/* Private */
-static void free_group(struct group *gr);
-
-
-/* Public. */
-
-
-
-
-
-/*
- * struct irs_gr * irs_irp_gr(struct irs_acc *this)
- *
- * Notes:
- *
- * Initialize the group sub-module.
- *
- * Notes:
- *
- * Module data.
- *
- */
-
-struct irs_gr *
-irs_irp_gr(struct irs_acc *this) {
- struct irs_gr *gr;
- struct pvt *pvt;
-
- if (!(gr = memget(sizeof *gr))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(gr, 0x0, sizeof *gr);
-
- if (!(pvt = memget(sizeof *pvt))) {
- memput(gr, sizeof *gr);
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0x0, sizeof *pvt);
- pvt->girpdata = this->private;
-
- gr->private = pvt;
- gr->close = gr_close;
- gr->next = gr_next;
- gr->byname = gr_byname;
- gr->bygid = gr_bygid;
- gr->rewind = gr_rewind;
- gr->list = make_group_list;
- gr->minimize = gr_minimize;
- return (gr);
-}
-
-/* Methods. */
-
-
-
-/*
- * void gr_close(struct irs_gr *this)
- *
- * Notes:
- *
- * Close the sub-module.
- *
- */
-
-static void
-gr_close(struct irs_gr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- gr_minimize(this);
-
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-
-
-
-/*
- * struct group * gr_next(struct irs_gr *this)
- *
- * Notes:
- *
- * Gets the next group out of the cached data and returns it.
- *
- */
-
-static struct group *
-gr_next(struct irs_gr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct group *gr = &pvt->group;
- char *body;
- size_t bodylen;
- int code;
- char text[256];
-
- if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
- return (NULL);
- }
-
- if (irs_irp_send_command(pvt->girpdata, "getgrent") != 0) {
- return (NULL);
- }
-
- if (irs_irp_get_full_response(pvt->girpdata, &code,
- text, sizeof text,
- &body, &bodylen) != 0) {
- if (irp_log_errors) {
- syslog(LOG_WARNING, "getgrent failed: %s", text);
- }
- return (NULL);
- }
-
- if (code == IRPD_GETGROUP_OK) {
- free_group(gr);
- if (irp_unmarshall_gr(gr, body) != 0) {
- gr = NULL;
- }
- } else {
- gr = NULL;
- }
-
- if (body != NULL) {
- memput(body, bodylen);
- }
-
- return (gr);
-}
-
-
-
-
-
-/*
- * struct group * gr_byname(struct irs_gr *this, const char *name)
- *
- * Notes:
- *
- * Gets a group by name from irpd and returns it.
- *
- */
-
-static struct group *
-gr_byname(struct irs_gr *this, const char *name) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct group *gr = &pvt->group;
- char *body;
- size_t bodylen;
- int code;
- char text[256];
-
-
- if (gr->gr_name != NULL && strcmp(name, gr->gr_name) == 0) {
- return (gr);
- }
-
- if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
- return (NULL);
- }
-
- if (irs_irp_send_command(pvt->girpdata, "getgrnam %s", name) != 0)
- return (NULL);
-
- if (irs_irp_get_full_response(pvt->girpdata, &code,
- text, sizeof text,
- &body, &bodylen) != 0) {
- return (NULL);
- }
-
- if (code == IRPD_GETGROUP_OK) {
- free_group(gr);
- if (irp_unmarshall_gr(gr, body) != 0) {
- gr = NULL;
- }
- } else {
- gr = NULL;
- }
-
- if (body != NULL) {
- memput(body, bodylen);
- }
-
- return (gr);
-}
-
-
-
-
-
-/*
- * struct group * gr_bygid(struct irs_gr *this, gid_t gid)
- *
- * Notes:
- *
- * Gets a group by gid from irpd and returns it.
- *
- */
-
-static struct group *
-gr_bygid(struct irs_gr *this, gid_t gid) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct group *gr = &pvt->group;
- char *body;
- size_t bodylen;
- int code;
- char text[256];
-
- if (gr->gr_name != NULL && (gid_t)gr->gr_gid == gid) {
- return (gr);
- }
-
- if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
- return (NULL);
- }
-
- if (irs_irp_send_command(pvt->girpdata, "getgrgid %d", gid) != 0)
- return (NULL);
-
- if (irs_irp_get_full_response(pvt->girpdata, &code,
- text, sizeof text,
- &body, &bodylen) != 0) {
- return (NULL);
- }
-
- if (code == IRPD_GETGROUP_OK) {
- free_group(gr);
- if (irp_unmarshall_gr(gr, body) != 0) {
- gr = NULL;
- }
- } else {
- gr = NULL;
- }
-
- if (body != NULL) {
- memput(body, bodylen);
- }
-
- return (gr);
-}
-
-
-
-
-/*
- * void gr_rewind(struct irs_gr *this)
- *
- */
-
-static void
-gr_rewind(struct irs_gr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- char text[256];
- int code;
-
- if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
- return;
- }
-
- if (irs_irp_send_command(pvt->girpdata, "setgrent") != 0) {
- return;
- }
-
- code = irs_irp_read_response(pvt->girpdata, text, sizeof text);
- if (code != IRPD_GETGROUP_SETOK) {
- if (irp_log_errors) {
- syslog(LOG_WARNING, "setgrent failed: %s", text);
- }
- }
-
- return;
-}
-
-
-
-
-/*
- * void gr_minimize(struct irs_gr *this)
- *
- * Notes:
- *
- * Frees up cached data and disconnects(if necessary) from the remote.
- *
- */
-
-static void
-gr_minimize(struct irs_gr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- free_group(&pvt->group);
- irs_irp_disconnect(pvt->girpdata);
-}
-
-/* Private. */
-
-
-
-/*
- * static void free_group(struct group *gr);
- *
- * Deallocate all the memory irp_unmarshall_gr allocated.
- *
- */
-
-static void
-free_group(struct group *gr) {
- char **p;
-
- if (gr == NULL)
- return;
-
- if (gr->gr_name != NULL)
- free(gr->gr_name);
-
- if (gr->gr_passwd != NULL)
- free(gr->gr_passwd);
-
- for (p = gr->gr_mem ; p != NULL && *p != NULL ; p++)
- free(*p);
-
- if (gr->gr_mem)
- free(gr->gr_mem);
-
- if (p != NULL)
- free(p);
-}
-
-
-#endif /* WANT_IRS_GR */
diff --git a/contrib/bind/lib/irs/irp_ho.c b/contrib/bind/lib/irs/irp_ho.c
deleted file mode 100644
index 2124017..0000000
--- a/contrib/bind/lib/irs/irp_ho.c
+++ /dev/null
@@ -1,429 +0,0 @@
-/*
- * Portions Copyright (c) 1996,1998 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: irp_ho.c,v 8.3 2001/05/29 05:48:59 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-/* Imports. */
-
-#include "port_before.h"
-
-#include <syslog.h>
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <netdb.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <syslog.h>
-
-#include <irs.h>
-#include <irp.h>
-#include <isc/irpmarshall.h>
-#include <isc/memcluster.h>
-
-#include "irs_p.h"
-#include "dns_p.h"
-#include "irp_p.h"
-
-#include "port_after.h"
-
-/* Definitions. */
-
-#define MAXALIASES 35
-#define MAXADDRS 35
-#define Max(a,b) ((a) > (b) ? (a) : (b))
-
-
-struct pvt {
- struct irp_p *girpdata;
- int warned;
- struct hostent host;
-};
-
-/* Forward. */
-
-static void ho_close(struct irs_ho *this);
-static struct hostent * ho_byname(struct irs_ho *this, const char *name);
-static struct hostent * ho_byname2(struct irs_ho *this, const char *name,
- int af);
-static struct hostent * ho_byaddr(struct irs_ho *this, const void *addr,
- int len, int af);
-static struct hostent * ho_next(struct irs_ho *this);
-static void ho_rewind(struct irs_ho *this);
-static void ho_minimize(struct irs_ho *this);
-
-static void free_host(struct hostent *ho);
-static struct addrinfo * ho_addrinfo(struct irs_ho *this, const char *name,
- const struct addrinfo *pai);
-
-/* Public. */
-
-
-
-/*
- * struct irs_ho * irs_irp_ho(struct irs_acc *this)
- *
- * Notes:
- *
- * Initializes the irp_ho module.
- *
- */
-
-struct irs_ho *
-irs_irp_ho(struct irs_acc *this) {
- struct irs_ho *ho;
- struct pvt *pvt;
-
- if (!(ho = memget(sizeof *ho))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(ho, 0x0, sizeof *ho);
-
- if (!(pvt = memget(sizeof *pvt))) {
- memput(ho, sizeof *ho);
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- pvt->girpdata = this->private;
-
- ho->private = pvt;
- ho->close = ho_close;
- ho->byname = ho_byname;
- ho->byname2 = ho_byname2;
- ho->byaddr = ho_byaddr;
- ho->next = ho_next;
- ho->rewind = ho_rewind;
- ho->minimize = ho_minimize;
- ho->addrinfo = ho_addrinfo;
-
- return (ho);
-}
-
-/* Methods. */
-
-
-
-/*
- * void ho_close(struct irs_ho *this)
- *
- * Notes:
- *
- * Closes down the module.
- *
- */
-
-static void
-ho_close(struct irs_ho *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- ho_minimize(this);
-
- free_host(&pvt->host);
-
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-
-
-/*
- * struct hostent * ho_byname(struct irs_ho *this, const char *name)
- *
- */
-
-static struct hostent *
-ho_byname(struct irs_ho *this, const char *name) {
- return (ho_byname2(this, name, AF_INET));
-}
-
-
-
-
-
-/*
- * struct hostent * ho_byname2(struct irs_ho *this, const char *name, int af)
- *
- */
-
-static struct hostent *
-ho_byname2(struct irs_ho *this, const char *name, int af) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct hostent *ho = &pvt->host;
- char *body = NULL;
- size_t bodylen;
- int code;
- char text[256];
-
- if (ho->h_name != NULL &&
- strcmp(name, ho->h_name) == 0 &&
- af == ho->h_addrtype) {
- return (ho);
- }
-
- if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
- return (NULL);
- }
-
- if (irs_irp_send_command(pvt->girpdata, "gethostbyname2 %s %s",
- name, ADDR_T_STR(af)) != 0)
- return (NULL);
-
- if (irs_irp_get_full_response(pvt->girpdata, &code,
- text, sizeof text,
- &body, &bodylen) != 0) {
- return (NULL);
- }
-
- if (code == IRPD_GETHOST_OK) {
- free_host(ho);
- if (irp_unmarshall_ho(ho, body) != 0) {
- ho = NULL;
- }
- } else {
- ho = NULL;
- }
-
- if (body != NULL) {
- memput(body, bodylen);
- }
-
- return (ho);
-}
-
-
-
-/*
- * struct hostent * ho_byaddr(struct irs_ho *this, const void *addr,
- * int len, int af)
- *
- */
-
-static struct hostent *
-ho_byaddr(struct irs_ho *this, const void *addr, int len, int af) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct hostent *ho = &pvt->host;
- char *body = NULL;
- size_t bodylen;
- int code;
- char **p;
- char paddr[MAXPADDRSIZE];
- char text[256];
-
- if (ho->h_name != NULL &&
- af == ho->h_addrtype &&
- len == ho->h_length) {
- for (p = ho->h_addr_list ; *p != NULL ; p++) {
- if (memcmp(*p, addr, len) == 0)
- return (ho);
- }
- }
-
- if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
- return (NULL);
- }
-
- if (inet_ntop(af, addr, paddr, sizeof paddr) == NULL) {
- return (NULL);
- }
-
- if (irs_irp_send_command(pvt->girpdata, "gethostbyaddr %s %s",
- paddr, ADDR_T_STR(af)) != 0) {
- return (NULL);
- }
-
- if (irs_irp_get_full_response(pvt->girpdata, &code,
- text, sizeof text,
- &body, &bodylen) != 0) {
- return (NULL);
- }
-
- if (code == IRPD_GETHOST_OK) {
- free_host(ho);
- if (irp_unmarshall_ho(ho, body) != 0) {
- ho = NULL;
- }
- } else {
- ho = NULL;
- }
-
- if (body != NULL) {
- memput(body, bodylen);
- }
-
- return (ho);
-}
-
-
-
-
-
-/*
- * struct hostent * ho_next(struct irs_ho *this)
- *
- * Notes:
- *
- * The implementation for gethostent(3). The first time it's
- * called all the data is pulled from the remote(i.e. what
- * the maximum number of gethostent(3) calls would return)
- * and that data is cached.
- *
- */
-
-static struct hostent *
-ho_next(struct irs_ho *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct hostent *ho = &pvt->host;
- char *body;
- size_t bodylen;
- int code;
- char text[256];
-
- if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
- return (NULL);
- }
-
- if (irs_irp_send_command(pvt->girpdata, "gethostent") != 0) {
- return (NULL);
- }
-
- if (irs_irp_get_full_response(pvt->girpdata, &code,
- text, sizeof text,
- &body, &bodylen) != 0) {
- return (NULL);
- }
-
- if (code == IRPD_GETHOST_OK) {
- free_host(ho);
- if (irp_unmarshall_ho(ho, body) != 0) {
- ho = NULL;
- }
- } else {
- ho = NULL;
- }
-
- if (body != NULL) {
- memput(body, bodylen);
- }
-
- return (ho);
-}
-
-
-
-
-
-/*
- * void ho_rewind(struct irs_ho *this)
- *
- */
-
-static void
-ho_rewind(struct irs_ho *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- char text[256];
- int code;
-
- if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
- return;
- }
-
- if (irs_irp_send_command(pvt->girpdata, "sethostent") != 0) {
- return;
- }
-
- code = irs_irp_read_response(pvt->girpdata, text, sizeof text);
- if (code != IRPD_GETHOST_SETOK) {
- if (irp_log_errors) {
- syslog(LOG_WARNING, "sethostent failed: %s", text);
- }
- }
-
- return;
-}
-
-
-
-
-/*
- * void ho_minimize(struct irs_ho *this)
- *
- */
-
-static void
-ho_minimize(struct irs_ho *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- free_host(&pvt->host);
-
- irs_irp_disconnect(pvt->girpdata);
-}
-
-
-
-
-/*
- * void free_host(struct hostent *ho)
- *
- */
-
-static void
-free_host(struct hostent *ho) {
- char **p;
-
- if (ho == NULL) {
- return;
- }
-
- if (ho->h_name != NULL)
- free(ho->h_name);
-
- if (ho->h_aliases != NULL) {
- for (p = ho->h_aliases ; *p != NULL ; p++)
- free(*p);
- free(ho->h_aliases);
- }
-
- if (ho->h_addr_list != NULL) {
- for (p = ho->h_addr_list ; *p != NULL ; p++)
- free(*p);
- free(ho->h_addr_list);
- }
-}
-
-/* dummy */
-static struct addrinfo *
-ho_addrinfo(struct irs_ho *this, const char *name, const struct addrinfo *pai)
-{
- UNUSED(this);
- UNUSED(name);
- UNUSED(pai);
- return(NULL);
-}
diff --git a/contrib/bind/lib/irs/irp_ng.c b/contrib/bind/lib/irs/irp_ng.c
deleted file mode 100644
index b3cf0f4..0000000
--- a/contrib/bind/lib/irs/irp_ng.c
+++ /dev/null
@@ -1,272 +0,0 @@
-/*
- * Copyright (c) 1996, 1998 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.
- */
-
-#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: irp_ng.c,v 8.3 2001/05/29 05:49:00 marka Exp $";
-#endif
-
-/* Imports */
-
-#include "port_before.h"
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <syslog.h>
-
-#include <irs.h>
-#include <irp.h>
-#include <isc/memcluster.h>
-#include <isc/irpmarshall.h>
-
-#include "irs_p.h"
-#include "irp_p.h"
-
-#include "port_after.h"
-
-/* Definitions */
-
-struct pvt {
- struct irp_p *girpdata;
- int warned;
-};
-
-
-/* Forward */
-
-static void ng_rewind(struct irs_ng *, const char*);
-static void ng_close(struct irs_ng *);
-static int ng_next(struct irs_ng *, const char **, const char **,
- const char **);
-static int ng_test(struct irs_ng *, const char *,
- const char *, const char *,
- const char *);
-static void ng_minimize(struct irs_ng *);
-
-
-/* Public */
-
-
-
-/*
- * struct irs_ng * irs_irp_ng(struct irs_acc *this)
- *
- * Notes:
- *
- * Intialize the irp netgroup module.
- *
- */
-
-struct irs_ng *
-irs_irp_ng(struct irs_acc *this) {
- struct irs_ng *ng;
- struct pvt *pvt;
-
- if (!(ng = memget(sizeof *ng))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(ng, 0x5e, sizeof *ng);
-
- if (!(pvt = memget(sizeof *pvt))) {
- memput(ng, sizeof *ng);
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- pvt->girpdata = this->private;
-
- ng->private = pvt;
- ng->close = ng_close;
- ng->next = ng_next;
- ng->test = ng_test;
- ng->rewind = ng_rewind;
- ng->minimize = ng_minimize;
- return (ng);
-}
-
-/* Methods */
-
-
-
-/*
- * void ng_close(struct irs_ng *this)
- *
- */
-
-static void
-ng_close(struct irs_ng *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- ng_minimize(this);
-
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-
-
-
-/*
- * void ng_rewind(struct irs_ng *this, const char *group)
- *
- *
- */
-
-static void
-ng_rewind(struct irs_ng *this, const char *group) {
- struct pvt *pvt = (struct pvt *)this->private;
- char text[256];
- int code;
-
- if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
- return;
- }
-
- if (irs_irp_send_command(pvt->girpdata,
- "setnetgrent %s", group) != 0) {
- return;
- }
-
- code = irs_irp_read_response(pvt->girpdata, text, sizeof text);
- if (code != IRPD_GETNETGR_SETOK) {
- if (irp_log_errors) {
- syslog(LOG_WARNING, "setnetgrent(%s) failed: %s",
- group, text);
- }
- }
-
- return;
-}
-
-
-
-
-/*
- * int ng_next(struct irs_ng *this, const char **host, const char **user,
- * const char **domain)
- *
- * Notes:
- *
- * Get the next netgroup item from the cache.
- *
- */
-
-static int
-ng_next(struct irs_ng *this, const char **host, const char **user,
- const char **domain)
-{
- struct pvt *pvt = (struct pvt *)this->private;
- int code;
- char *body = NULL;
- size_t bodylen;
- int rval = 0;
- char text[256];
-
- if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
- return (0);
- }
-
- if (irs_irp_send_command(pvt->girpdata, "getnetgrent") != 0)
- return (0);
-
- if (irs_irp_get_full_response(pvt->girpdata, &code,
- text, sizeof text,
- &body, &bodylen) != 0) {
- return (0);
- }
-
- if (code == IRPD_GETNETGR_OK) {
- if (irp_unmarshall_ng(host, user, domain, body) == 0) {
- rval = 1;
- }
- }
-
- if (body != NULL) {
- memput(body, bodylen);
- }
-
- return (rval);
-}
-
-
-
-/*
- * int ng_test(struct irs_ng *this, const char *name, const char *host,
- * const char *user, const char *domain)
- *
- * Notes:
- *
- * Search for a match in a netgroup.
- *
- */
-
-static int
-ng_test(struct irs_ng *this, const char *name,
- const char *host, const char *user, const char *domain)
-{
- struct pvt *pvt = (struct pvt *)this->private;
- char *body = NULL;
- size_t bodylen = 0;
- int code;
- char text[256];
- int rval = 0;
-
- UNUSED(name);
-
- if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
- return (0);
- }
-
- if (irp_marshall_ng(host, user, domain, &body, &bodylen) != 0) {
- return (0);
- }
-
- if (irs_irp_send_command(pvt->girpdata, "innetgr %s", body) == 0) {
- memput(body, bodylen);
-
- code = irs_irp_read_response(pvt->girpdata, text, sizeof text);
- if (code == IRPD_GETNETGR_MATCHES) {
- rval = 1;
- }
- }
-
- return (rval);
-}
-
-
-
-
-/*
- * void ng_minimize(struct irs_ng *this)
- *
- */
-
-static void
-ng_minimize(struct irs_ng *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- irs_irp_disconnect(pvt->girpdata);
-}
-
-
-
-
-/* Private */
-
diff --git a/contrib/bind/lib/irs/irp_nw.c b/contrib/bind/lib/irs/irp_nw.c
deleted file mode 100644
index c0bcbfa..0000000
--- a/contrib/bind/lib/irs/irp_nw.c
+++ /dev/null
@@ -1,375 +0,0 @@
-/*
- * Portions Copyright (c) 1996,1998 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: irp_nw.c,v 8.1 1999/01/18 07:46:54 vixie Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#if 0
-
-#endif
-
-/* Imports */
-
-#include "port_before.h"
-
-#include <syslog.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <syslog.h>
-
-#include <irs.h>
-#include <irp.h>
-#include <isc/irpmarshall.h>
-
-#include <isc/memcluster.h>
-#include <isc/misc.h>
-
-#include "irs_p.h"
-#include "lcl_p.h"
-#include "irp_p.h"
-
-#include "port_after.h"
-
-#define MAXALIASES 35
-#define MAXADDRSIZE 4
-
-struct pvt {
- struct irp_p *girpdata;
- int warned;
- struct nwent net;
-};
-
-/* Forward */
-
-static void nw_close(struct irs_nw *);
-static struct nwent * nw_byname(struct irs_nw *, const char *, int);
-static struct nwent * nw_byaddr(struct irs_nw *, void *, int, int);
-static struct nwent * nw_next(struct irs_nw *);
-static void nw_rewind(struct irs_nw *);
-static void nw_minimize(struct irs_nw *);
-
-static void free_nw(struct nwent *nw);
-
-
-/* Public */
-
-
-
-/*
- * struct irs_nw * irs_irp_nw(struct irs_acc *this)
- *
- */
-
-struct irs_nw *
-irs_irp_nw(struct irs_acc *this) {
- struct irs_nw *nw;
- struct pvt *pvt;
-
- if (!(pvt = memget(sizeof *pvt))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
-
- if (!(nw = memget(sizeof *nw))) {
- memput(pvt, sizeof *pvt);
- errno = ENOMEM;
- return (NULL);
- }
- memset(nw, 0x0, sizeof *nw);
- pvt->girpdata = this->private;
-
- nw->private = pvt;
- nw->close = nw_close;
- nw->byname = nw_byname;
- nw->byaddr = nw_byaddr;
- nw->next = nw_next;
- nw->rewind = nw_rewind;
- nw->minimize = nw_minimize;
- return (nw);
-}
-
-/* Methods */
-
-
-
-/*
- * void nw_close(struct irs_nw *this)
- *
- */
-
-static void
-nw_close(struct irs_nw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- nw_minimize(this);
-
- free_nw(&pvt->net);
-
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-
-
-
-/*
- * struct nwent * nw_byaddr(struct irs_nw *this, void *net,
- * int length, int type)
- *
- */
-
-static struct nwent *
-nw_byaddr(struct irs_nw *this, void *net, int length, int type) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct nwent *nw = &pvt->net;
- char *body = NULL;
- size_t bodylen;
- int code;
- char paddr[24]; /* bigenough for ip4 w/ cidr spec. */
- char text[256];
-
- if (inet_net_ntop(type, net, length, paddr, sizeof paddr) == NULL) {
- return (NULL);
- }
-
- if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
- return (NULL);
- }
-
- if (irs_irp_send_command(pvt->girpdata, "getnetbyaddr %s %s",
- paddr, ADDR_T_STR(type)) != 0)
- return (NULL);
-
- if (irs_irp_get_full_response(pvt->girpdata, &code,
- text, sizeof text,
- &body, &bodylen) != 0) {
- return (NULL);
- }
-
- if (code == IRPD_GETNET_OK) {
- free_nw(nw);
- if (irp_unmarshall_nw(nw, body) != 0) {
- nw = NULL;
- }
- } else {
- nw = NULL;
- }
-
- if (body != NULL) {
- memput(body, bodylen);
- }
-
- return (nw);
-}
-
-
-
-
-/*
- * struct nwent * nw_byname(struct irs_nw *this, const char *name, int type)
- *
- */
-
-static struct nwent *
-nw_byname(struct irs_nw *this, const char *name, int type) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct nwent *nw = &pvt->net;
- char *body = NULL;
- size_t bodylen;
- int code;
- char text[256];
-
- if (nw->n_name != NULL &&
- strcmp(name, nw->n_name) == 0 &&
- nw->n_addrtype == type) {
- return (nw);
- }
-
- if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
- return (NULL);
- }
-
- if (irs_irp_send_command(pvt->girpdata, "getnetbyname %s", name) != 0)
- return (NULL);
-
- if (irs_irp_get_full_response(pvt->girpdata, &code,
- text, sizeof text,
- &body, &bodylen) != 0) {
- return (NULL);
- }
-
- if (code == IRPD_GETNET_OK) {
- free_nw(nw);
- if (irp_unmarshall_nw(nw, body) != 0) {
- nw = NULL;
- }
- } else {
- nw = NULL;
- }
-
- if (body != NULL) {
- memput(body, bodylen);
- }
-
- return (nw);
-}
-
-
-
-
-/*
- * void nw_rewind(struct irs_nw *this)
- *
- */
-
-static void
-nw_rewind(struct irs_nw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- char text[256];
- int code;
-
- if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
- return;
- }
-
- if (irs_irp_send_command(pvt->girpdata, "setnetent") != 0) {
- return;
- }
-
- code = irs_irp_read_response(pvt->girpdata, text, sizeof text);
- if (code != IRPD_GETNET_SETOK) {
- if (irp_log_errors) {
- syslog(LOG_WARNING, "setnetent failed: %s", text);
- }
- }
-
- return;
-}
-
-
-
-
-
-
-/*
- * struct nwent * nw_next(struct irs_nw *this)
- *
- * Notes:
- *
- * Prepares the cache if necessary and returns the first, or
- * next item from it.
- */
-
-static struct nwent *
-nw_next(struct irs_nw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct nwent *nw = &pvt->net;
- char *body;
- size_t bodylen;
- int code;
- char text[256];
-
- if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
- return (NULL);
- }
-
- if (irs_irp_send_command(pvt->girpdata, "getnetent") != 0) {
- return (NULL);
- }
-
- if (irs_irp_get_full_response(pvt->girpdata, &code,
- text, sizeof text,
- &body, &bodylen) != 0) {
- return (NULL);
- }
-
- if (code == IRPD_GETNET_OK) {
- free_nw(nw);
- if (irp_unmarshall_nw(nw, body) != 0) {
- nw = NULL;
- }
- } else {
- nw = NULL;
- }
-
- return (nw);
-}
-
-
-
-
-
-
-/*
- * void nw_minimize(struct irs_nw *this)
- *
- */
-
-static void
-nw_minimize(struct irs_nw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- irs_irp_disconnect(pvt->girpdata);
-}
-
-
-
-
-/* private. */
-
-
-
-/*
- * static void free_passwd(struct passwd *pw);
- *
- * deallocate all the memory irp_unmarshall_pw allocated.
- *
- */
-
-static void
-free_nw(struct nwent *nw) {
- char **p;
-
- if (nw == NULL)
- return;
-
- if (nw->n_name != NULL)
- free(nw->n_name);
-
- if (nw->n_aliases != NULL) {
- for (p = nw->n_aliases ; *p != NULL ; p++) {
- free(*p);
- }
- free(nw->n_aliases);
- }
-
- if (nw->n_addr != NULL)
- free(nw->n_addr);
-}
diff --git a/contrib/bind/lib/irs/irp_p.h b/contrib/bind/lib/irs/irp_p.h
deleted file mode 100644
index 8a02b1b..0000000
--- a/contrib/bind/lib/irs/irp_p.h
+++ /dev/null
@@ -1,59 +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.
- */
-
-/*
- * $Id: irp_p.h,v 8.2.10.1 2003/06/02 05:55:14 marka Exp $
- */
-
-#ifndef _IRP_P_H_INCLUDED
-#define _IRP_P_H_INCLUDED
-
-#include <stdio.h>
-
-struct irp_p {
- char inbuffer[1024];
- int inlast; /* index of one past the last char in buffer */
- int incurr; /* index of the next char to be read from buffer */
-
- int fdCxn;
-};
-
-/*
- * Externs.
- */
-
-extern struct irs_acc * irs_irp_acc __P((const char *));
-extern struct irs_gr * irs_irp_gr __P((struct irs_acc *));
-extern struct irs_pw * irs_irp_pw __P((struct irs_acc *));
-extern struct irs_sv * irs_irp_sv __P((struct irs_acc *));
-extern struct irs_pr * irs_irp_pr __P((struct irs_acc *));
-extern struct irs_ho * irs_irp_ho __P((struct irs_acc *));
-extern struct irs_nw * irs_irp_nw __P((struct irs_acc *));
-extern struct irs_ng * irs_irp_ng __P((struct irs_acc *));
-
-int irs_irp_connect(struct irp_p *pvt);
-int irs_irp_is_connected(struct irp_p *pvt);
-void irs_irp_disconnect(struct irp_p *pvt);
-int irs_irp_read_response(struct irp_p *pvt, char *text, size_t textlen);
-char *irs_irp_read_body(struct irp_p *pvt, size_t *size);
-int irs_irp_get_full_response(struct irp_p *pvt, int *code,
- char *text, size_t textlen,
- char **body, size_t *bodylen);
-
-extern int irp_log_errors;
-
-#endif
diff --git a/contrib/bind/lib/irs/irp_pr.c b/contrib/bind/lib/irs/irp_pr.c
deleted file mode 100644
index 1de304e..0000000
--- a/contrib/bind/lib/irs/irp_pr.c
+++ /dev/null
@@ -1,353 +0,0 @@
-/*
- * Portions 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: irp_pr.c,v 8.1 1999/01/18 07:46:54 vixie Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-/* extern */
-
-#include "port_before.h"
-
-#include <syslog.h>
-#include <sys/types.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <netdb.h>
-#include <syslog.h>
-
-#include <irs.h>
-#include <irp.h>
-#include <isc/memcluster.h>
-#include <isc/irpmarshall.h>
-
-#include "irs_p.h"
-#include "lcl_p.h"
-#include "irp_p.h"
-
-#include "port_after.h"
-
-
-#define MAXALIASES 35
-
-/* Types */
-
-struct pvt {
- struct irp_p *girpdata;
- int warned;
- struct protoent proto;
-};
-
-/* Forward */
-
-static void pr_close(struct irs_pr *);
-static struct protoent * pr_next(struct irs_pr *);
-static struct protoent * pr_byname(struct irs_pr *, const char *);
-static struct protoent * pr_bynumber(struct irs_pr *, int);
-static void pr_rewind(struct irs_pr *);
-static void pr_minimize(struct irs_pr *);
-
-static void free_proto(struct protoent *pr);
-
-/* Public */
-
-
-
-/*
- * struct irs_pr * irs_irp_pr(struct irs_acc *this)
- *
- */
-
-struct irs_pr *
-irs_irp_pr(struct irs_acc *this) {
- struct irs_pr *pr;
- struct pvt *pvt;
-
- if (!(pr = memget(sizeof *pr))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(pr, 0x0, sizeof *pr);
-
- if (!(pvt = memget(sizeof *pvt))) {
- memput(pr, sizeof *pr);
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- pvt->girpdata = this->private;
-
- pr->private = pvt;
- pr->close = pr_close;
- pr->byname = pr_byname;
- pr->bynumber = pr_bynumber;
- pr->next = pr_next;
- pr->rewind = pr_rewind;
- pr->minimize = pr_minimize;
- return (pr);
-}
-
-/* Methods */
-
-
-
-/*
- * void pr_close(struct irs_pr *this)
- *
- */
-
-static void
-pr_close(struct irs_pr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- pr_minimize(this);
-
- free_proto(&pvt->proto);
-
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-
-
-/*
- * struct protoent * pr_byname(struct irs_pr *this, const char *name)
- *
- */
-
-static struct protoent *
-pr_byname(struct irs_pr *this, const char *name) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct protoent *pr = &pvt->proto;
- char *body = NULL;
- size_t bodylen;
- int code;
- int i;
- char text[256];
-
- if (pr->p_name != NULL && strcmp(name, pr->p_name) == 0) {
- return (pr);
- }
-
- if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
- return (NULL);
- }
-
- i = irs_irp_send_command(pvt->girpdata, "getprotobyname %s", name);
- if (i != 0)
- return (NULL);
-
- if (irs_irp_get_full_response(pvt->girpdata, &code,
- text, sizeof text,
- &body, &bodylen) != 0) {
- return (NULL);
- }
-
- if (code == IRPD_GETPROTO_OK) {
- free_proto(pr);
- if (irp_unmarshall_pr(pr, body) != 0) {
- pr = NULL;
- }
- } else {
- pr = NULL;
- }
-
- if (body != NULL) {
- memput(body, bodylen);
- }
-
- return (pr);
-}
-
-
-
-/*
- * struct protoent * pr_bynumber(struct irs_pr *this, int proto)
- *
- */
-
-static struct protoent *
-pr_bynumber(struct irs_pr *this, int proto) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct protoent *pr = &pvt->proto;
- char *body = NULL;
- size_t bodylen;
- int code;
- int i;
- char text[256];
-
- if (pr->p_name != NULL && proto == pr->p_proto) {
- return (pr);
- }
-
- if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
- return (NULL);
- }
-
- i = irs_irp_send_command(pvt->girpdata, "getprotobynumber %d", proto);
- if (i != 0)
- return (NULL);
-
- if (irs_irp_get_full_response(pvt->girpdata, &code,
- text, sizeof text,
- &body, &bodylen) != 0) {
- return (NULL);
- }
-
- if (code == IRPD_GETPROTO_OK) {
- free_proto(pr);
- if (irp_unmarshall_pr(pr, body) != 0) {
- pr = NULL;
- }
- } else {
- pr = NULL;
- }
-
- if (body != NULL) {
- memput(body, bodylen);
- }
-
- return (pr);
-}
-
-
-
-
-/*
- * void pr_rewind(struct irs_pr *this)
- *
- */
-
-static void
-pr_rewind(struct irs_pr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- char text[256];
- int code;
-
- if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
- return;
- }
-
- if (irs_irp_send_command(pvt->girpdata, "setprotoent") != 0) {
- return;
- }
-
- code = irs_irp_read_response(pvt->girpdata, text, sizeof text);
- if (code != IRPD_GETPROTO_SETOK) {
- if (irp_log_errors) {
- syslog(LOG_WARNING, "setprotoent failed: %s", text);
- }
- }
-
- return;
-}
-
-
-
-
-/*
- * struct protoent * pr_next(struct irs_pr *this)
- *
- * Notes:
- *
- * Prepares the cache if necessary and returns the next item in it.
- *
- */
-
-static struct protoent *
-pr_next(struct irs_pr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct protoent *pr = &pvt->proto;
- char *body;
- size_t bodylen;
- int code;
- char text[256];
-
- if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
- return (NULL);
- }
-
- if (irs_irp_send_command(pvt->girpdata, "getprotoent") != 0) {
- return (NULL);
- }
-
- if (irs_irp_get_full_response(pvt->girpdata, &code,
- text, sizeof text,
- &body, &bodylen) != 0) {
- return (NULL);
- }
-
- if (code == IRPD_GETPROTO_OK) {
- free_proto(pr);
- if (irp_unmarshall_pr(pr, body) != 0) {
- pr = NULL;
- }
- } else {
- pr = NULL;
- }
-
- if (body != NULL) {
- memput(body, bodylen);
- }
-
- return (pr);
-}
-
-
-
-
-/*
- * void pr_minimize(struct irs_pr *this)
- *
- */
-
-static void
-pr_minimize(struct irs_pr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- irs_irp_disconnect(pvt->girpdata);
-}
-
-
-
-
-
-
-/*
- * static void free_proto(struct protoent *pw);
- *
- * Deallocate all the memory irp_unmarshall_pr allocated.
- *
- */
-
-static void
-free_proto(struct protoent *pr) {
- char **p;
-
- if (pr == NULL)
- return;
-
- if (pr->p_name != NULL)
- free(pr->p_name);
-
- for (p = pr->p_aliases ; p != NULL && *p != NULL ; p++)
- free(*p);
-}
diff --git a/contrib/bind/lib/irs/irp_pw.c b/contrib/bind/lib/irs/irp_pw.c
deleted file mode 100644
index b659caa..0000000
--- a/contrib/bind/lib/irs/irp_pw.c
+++ /dev/null
@@ -1,358 +0,0 @@
-/*
- * Portions 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: irp_pw.c,v 8.2 2001/11/01 07:29:26 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-/* Extern */
-
-#include "port_before.h"
-
-#ifndef WANT_IRS_PW
-static int __bind_irs_pw_unneeded;
-#else
-
-#include <syslog.h>
-#include <sys/param.h>
-
-#include <db.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <pwd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <syslog.h>
-#include <utmp.h>
-#include <unistd.h>
-
-#include <irs.h>
-#include <irp.h>
-#include <isc/memcluster.h>
-#include <isc/irpmarshall.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "irp_p.h"
-
-
-/* Types */
-
-struct pvt {
- struct irp_p *girpdata; /* global IRP data */
- int warned;
- struct passwd passwd; /* password structure */
-};
-
-/* Forward */
-
-static void pw_close(struct irs_pw *);
-static struct passwd * pw_next(struct irs_pw *);
-static struct passwd * pw_byname(struct irs_pw *, const char *);
-static struct passwd * pw_byuid(struct irs_pw *, uid_t);
-static void pw_rewind(struct irs_pw *);
-static void pw_minimize(struct irs_pw *);
-
-static void free_passwd(struct passwd *pw);
-
-/* Public */
-struct irs_pw *
-irs_irp_pw(struct irs_acc *this) {
- struct irs_pw *pw;
- struct pvt *pvt;
-
- if (!(pw = memget(sizeof *pw))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(pw, 0, sizeof *pw);
-
- if (!(pvt = memget(sizeof *pvt))) {
- memput(pw, sizeof *pw);
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- pvt->girpdata = this->private;
-
- pw->private = pvt;
- pw->close = pw_close;
- pw->next = pw_next;
- pw->byname = pw_byname;
- pw->byuid = pw_byuid;
- pw->rewind = pw_rewind;
- pw->minimize = pw_minimize;
-
- return (pw);
-}
-
-/* Methods */
-
-
-
-/*
- * void pw_close(struct irs_pw *this)
- *
- */
-
-static void
-pw_close(struct irs_pw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- pw_minimize(this);
-
- free_passwd(&pvt->passwd);
-
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-
-
-
-/*
- * struct passwd * pw_next(struct irs_pw *this)
- *
- */
-
-static struct passwd *
-pw_next(struct irs_pw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct passwd *pw = &pvt->passwd;
- char *body;
- size_t bodylen;
- int code;
- char text[256];
-
- if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
- return (NULL);
- }
-
- if (irs_irp_send_command(pvt->girpdata, "getpwent") != 0) {
- return (NULL);
- }
-
- if (irs_irp_get_full_response(pvt->girpdata, &code,
- text, sizeof text,
- &body, &bodylen) != 0) {
- return (NULL);
- }
-
- if (code == IRPD_GETUSER_OK) {
- free_passwd(pw);
- if (irp_unmarshall_pw(pw, body) != 0) {
- pw = NULL;
- }
- } else {
- pw = NULL;
- }
-
- if (body != NULL) {
- memput(body, bodylen);
- }
-
- return (pw);
-}
-
-
-
-
-/*
- * struct passwd * pw_byname(struct irs_pw *this, const char *name)
- *
- */
-
-static struct passwd *
-pw_byname(struct irs_pw *this, const char *name) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct passwd *pw = &pvt->passwd;
- char *body = NULL;
- char text[256];
- size_t bodylen;
- int code;
-
- if (pw->pw_name != NULL && strcmp(name, pw->pw_name) == 0) {
- return (pw);
- }
-
- if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
- return (NULL);
- }
-
- if (irs_irp_send_command(pvt->girpdata, "getpwnam %s", name) != 0) {
- return (NULL);
- }
-
- if (irs_irp_get_full_response(pvt->girpdata, &code,
- text, sizeof text,
- &body, &bodylen) != 0) {
- return (NULL);
- }
-
- if (code == IRPD_GETUSER_OK) {
- free_passwd(pw);
- if (irp_unmarshall_pw(pw, body) != 0) {
- pw = NULL;
- }
- } else {
- pw = NULL;
- }
-
- if (body != NULL) {
- memput(body, bodylen);
- }
-
- return (pw);
-}
-
-
-
-
-/*
- * struct passwd * pw_byuid(struct irs_pw *this, uid_t uid)
- *
- */
-
-static struct passwd *
-pw_byuid(struct irs_pw *this, uid_t uid) {
- struct pvt *pvt = (struct pvt *)this->private;
- char *body;
- char text[256];
- size_t bodylen;
- int code;
- struct passwd *pw = &pvt->passwd;
-
- if (pw->pw_name != NULL && pw->pw_uid == uid) {
- return (pw);
- }
-
- if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
- return (NULL);
- }
-
- if (irs_irp_send_command(pvt->girpdata, "getpwuid %d", uid) != 0) {
- return (NULL);
- }
-
- if (irs_irp_get_full_response(pvt->girpdata, &code,
- text, sizeof text,
- &body, &bodylen) != 0) {
- return (NULL);
- }
-
- if (code == IRPD_GETUSER_OK) {
- free_passwd(pw);
- if (irp_unmarshall_pw(pw, body) != 0) {
- pw = NULL;
- }
- } else {
- pw = NULL;
- }
-
- if (body != NULL) {
- memput(body, bodylen);
- }
-
- return (pw);
-}
-
-
-
-
-/*
- * void pw_rewind(struct irs_pw *this)
- *
- */
-
-static void
-pw_rewind(struct irs_pw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- char text[256];
- int code;
-
- if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
- return;
- }
-
- if (irs_irp_send_command(pvt->girpdata, "setpwent") != 0) {
- return;
- }
-
- code = irs_irp_read_response(pvt->girpdata, text, sizeof text);
- if (code != IRPD_GETUSER_SETOK) {
- if (irp_log_errors) {
- syslog(LOG_WARNING, "setpwent failed: %s", text);
- }
- }
-
- return;
-}
-
-
-/*
- * void pw_minimize(struct irs_pw *this)
- *
- */
-
-static void
-pw_minimize(struct irs_pw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- irs_irp_disconnect(pvt->girpdata);
-}
-
-
-/* Private. */
-
-
-
-/*
- * static void free_passwd(struct passwd *pw);
- *
- * Deallocate all the memory irp_unmarshall_pw allocated.
- *
- */
-
-static void
-free_passwd(struct passwd *pw) {
- if (pw == NULL)
- return;
-
- if (pw->pw_name != NULL)
- free(pw->pw_name);
-
- if (pw->pw_passwd != NULL)
- free(pw->pw_passwd);
-
-#ifdef HAVE_PW_CLASS
- if (pw->pw_class != NULL)
- free(pw->pw_class);
-#endif
-
- if (pw->pw_gecos != NULL)
- free(pw->pw_gecos);
-
- if (pw->pw_dir != NULL)
- free(pw->pw_dir);
-
- if (pw->pw_shell != NULL)
- free(pw->pw_shell);
-}
-
-#endif /* WANT_IRS_PW */
diff --git a/contrib/bind/lib/irs/irp_sv.c b/contrib/bind/lib/irs/irp_sv.c
deleted file mode 100644
index 6a12c5b..0000000
--- a/contrib/bind/lib/irs/irp_sv.c
+++ /dev/null
@@ -1,369 +0,0 @@
-/*
- * Portions Copyright (c) 1996,1998 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: irp_sv.c,v 8.1 1999/01/18 07:46:54 vixie Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-/* extern */
-
-#include "port_before.h"
-
-#include <syslog.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#ifdef IRS_LCL_SV_DB
-#include <db.h>
-#endif
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <syslog.h>
-
-#include <irs.h>
-#include <irp.h>
-#include <isc/irpmarshall.h>
-#include <isc/memcluster.h>
-
-#include "irs_p.h"
-#include "lcl_p.h"
-#include "irp_p.h"
-
-#include "port_after.h"
-
-/* Types */
-
-struct pvt {
- struct irp_p *girpdata;
- int warned;
- struct servent service;
-};
-
-/* Forward */
-
-static void sv_close(struct irs_sv*);
-static struct servent * sv_next(struct irs_sv *);
-static struct servent * sv_byname(struct irs_sv *, const char *,
- const char *);
-static struct servent * sv_byport(struct irs_sv *, int, const char *);
-static void sv_rewind(struct irs_sv *);
-static void sv_minimize(struct irs_sv *);
-
-static void free_service(struct servent *sv);
-
-
-
-/* Public */
-
-
-
-/*
- * struct irs_sv * irs_irp_sv(struct irs_acc *this)
- *
- */
-
-struct irs_sv *
-irs_irp_sv(struct irs_acc *this) {
- struct irs_sv *sv;
- struct pvt *pvt;
-
- if ((sv = memget(sizeof *sv)) == NULL) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(sv, 0x0, sizeof *sv);
-
- if ((pvt = memget(sizeof *pvt)) == NULL) {
- memput(sv, sizeof *sv);
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- pvt->girpdata = this->private;
-
- sv->private = pvt;
- sv->close = sv_close;
- sv->next = sv_next;
- sv->byname = sv_byname;
- sv->byport = sv_byport;
- sv->rewind = sv_rewind;
- sv->minimize = sv_minimize;
-
- return (sv);
-}
-
-/* Methods */
-
-
-
-/*
- * void sv_close(struct irs_sv *this)
- *
- */
-
-static void
-sv_close(struct irs_sv *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- sv_minimize(this);
-
- free_service(&pvt->service);
-
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-
-
-
-/*
- * struct servent * sv_next(struct irs_sv *this)
- *
- * Notes:
- *
- * Fills the cache if necessary and returns the next item from it.
- *
- */
-
-static struct servent *
-sv_next(struct irs_sv *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct servent *sv = &pvt->service;
- char *body;
- size_t bodylen;
- int code;
- char text[256];
-
- if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
- return (NULL);
- }
-
- if (irs_irp_send_command(pvt->girpdata, "getservent") != 0) {
- return (NULL);
- }
-
- if (irs_irp_get_full_response(pvt->girpdata, &code,
- text, sizeof text,
- &body, &bodylen) != 0) {
- return (NULL);
- }
-
- if (code == IRPD_GETSERVICE_OK) {
- free_service(sv);
- if (irp_unmarshall_sv(sv, body) != 0) {
- sv = NULL;
- }
- } else {
- sv = NULL;
- }
-
- if (body != NULL) {
- memput(body, bodylen);
- }
-
- return (sv);
-}
-
-
-
-
-/*
- * struct servent * sv_byname(struct irs_sv *this, const char *name,
- * const char *proto)
- *
- */
-
-static struct servent *
-sv_byname(struct irs_sv *this, const char *name, const char *proto) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct servent *sv = &pvt->service;
- char *body;
- char text[256];
- size_t bodylen;
- int code;
-
- if (sv->s_name != NULL &&
- strcmp(name, sv->s_name) == 0 &&
- strcasecmp(proto, sv->s_proto) == 0) {
- return (sv);
- }
-
- if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
- return (NULL);
- }
-
- if (irs_irp_send_command(pvt->girpdata, "getservbyname %s %s",
- name, proto) != 0)
- return (NULL);
-
- if (irs_irp_get_full_response(pvt->girpdata, &code,
- text, sizeof text,
- &body, &bodylen) != 0) {
- return (NULL);
- }
-
- if (code == IRPD_GETSERVICE_OK) {
- free_service(sv);
- if (irp_unmarshall_sv(sv, body) != 0) {
- sv = NULL;
- }
- } else {
- sv = NULL;
- }
-
- if (body != NULL) {
- memput(body, bodylen);
- }
-
- return (sv);
-}
-
-
-
-
-/*
- * struct servent * sv_byport(struct irs_sv *this, int port,
- * const char *proto)
- *
- */
-
-static struct servent *
-sv_byport(struct irs_sv *this, int port, const char *proto) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct servent *sv = &pvt->service;
- char *body;
- size_t bodylen;
- char text[256];
- int code;
-
- if (sv->s_name != NULL &&
- port == sv->s_port &&
- strcasecmp(proto, sv->s_proto) == 0) {
- return (sv);
- }
-
- if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
- return (NULL);
- }
-
- if (irs_irp_send_command(pvt->girpdata, "getservbyport %d %s",
- ntohs((short)port), proto) != 0) {
- return (NULL);
- }
-
- if (irs_irp_get_full_response(pvt->girpdata, &code,
- text, sizeof text,
- &body, &bodylen) != 0) {
- return (NULL);
- }
-
- if (code == IRPD_GETSERVICE_OK) {
- free_service(sv);
- if (irp_unmarshall_sv(sv, body) != 0) {
- sv = NULL;
- }
- } else {
- sv = NULL;
- }
-
- if (body != NULL) {
- memput(body, bodylen);
- }
-
- return (sv);
-}
-
-
-
-
-
-/*
- * void sv_rewind(struct irs_sv *this)
- *
- */
-
-static void
-sv_rewind(struct irs_sv *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- char text[256];
- int code;
-
- if (irs_irp_connection_setup(pvt->girpdata, &pvt->warned) != 0) {
- return;
- }
-
- if (irs_irp_send_command(pvt->girpdata, "setservent") != 0) {
- return;
- }
-
- code = irs_irp_read_response(pvt->girpdata, text, sizeof text);
- if (code != IRPD_GETSERVICE_SETOK) {
- if (irp_log_errors) {
- syslog(LOG_WARNING, "setservent failed: %s", text);
- }
- }
-
- return;
-}
-
-
-
-
-
-/*
- * void sv_minimize(struct irs_sv *this)
- *
- */
-
-static void
-sv_minimize(struct irs_sv *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- irs_irp_disconnect(pvt->girpdata);
-}
-
-
-
-
-
-
-static void
-free_service(struct servent *sv) {
- char **p;
-
- if (sv == NULL) {
- return;
- }
-
- if (sv->s_name != NULL) {
- free(sv->s_name);
- }
-
- for (p = sv->s_aliases ; p != NULL && *p != NULL ; p++) {
- free(*p);
- }
-
- if (sv->s_proto != NULL) {
- free(sv->s_proto);
- }
-}
-
-
diff --git a/contrib/bind/lib/irs/irpmarshall.c b/contrib/bind/lib/irs/irpmarshall.c
deleted file mode 100644
index 6331ce1..0000000
--- a/contrib/bind/lib/irs/irpmarshall.c
+++ /dev/null
@@ -1,2344 +0,0 @@
-/*
- * Copyright(c) 1989, 1993, 1995
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Portions Copyright (c) 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: irpmarshall.c,v 8.7 2001/05/29 05:49:01 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#if 0
-
-Check values are in approrpriate endian order.
-
-Double check memory allocations on unmarhsalling
-
-#endif
-
-
-/* Extern */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-
-#include <stdio.h>
-#include <ctype.h>
-#include <pwd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <syslog.h>
-#include <utmp.h>
-#include <unistd.h>
-#include <assert.h>
-#include <errno.h>
-
-#include <irs.h>
-#include <isc/memcluster.h>
-#include <isc/irpmarshall.h>
-
-#include "port_after.h"
-
-
-#ifndef HAVE_STRNDUP
-static char *strndup(const char *str, size_t len);
-#endif
-
-static char **splitarray(const char *buffer, const char *buffend, char delim);
-static int joinarray(char * const * argv, char *buffer, char delim);
-static char *getfield(char **res, size_t reslen, char **buffer, char delim);
-static size_t joinlength(char * const *argv);
-static void free_array(char **argv, size_t entries);
-
-#define ADDR_T_STR(x) (x == AF_INET ? "AF_INET" :\
- (x == AF_INET6 ? "AF_INET6" : "UNKNOWN"))
-
-#define MAXPADDRSIZE (sizeof "255.255.255.255" + 1)
-
-static char COMMA = ',';
-
-static const char *COMMASTR = ",";
-static const char *COLONSTR = ":";
-
-
-
-/* See big comment at bottom of irpmarshall.h for description. */
-
-
-#ifdef WANT_IRS_PW
-/* +++++++++++++++++++++++++ struct passwd +++++++++++++++++++++++++ */
-
-
-/*
- * int irp_marshall_pw(const struct passwd *pw, char **buffer, size_t *len)
- *
- * notes:
- *
- * See above
- *
- * return:
- *
- * 0 on sucess, -1 on failure.
- *
- */
-
-int
-irp_marshall_pw(const struct passwd *pw, char **buffer, size_t *len) {
- size_t need = 1 ; /* for null byte */
- char pwUid[24];
- char pwGid[24];
- char pwChange[24];
- char pwExpire[24];
- const char *pwClass;
- const char *fieldsep = COLONSTR;
-
- if (pw == NULL || len == NULL) {
- errno = EINVAL;
- return (-1);
- }
-
- sprintf(pwUid, "%ld", (long)pw->pw_uid);
- sprintf(pwGid, "%ld", (long)pw->pw_gid);
-
-#ifdef HAVE_PW_CHANGE
- sprintf(pwChange, "%ld", (long)pw->pw_change);
-#else
- pwChange[0] = '0';
- pwChange[1] = '\0';
-#endif
-
-#ifdef HAVE_PW_EXPIRE
- sprintf(pwExpire, "%ld", (long)pw->pw_expire);
-#else
- pwExpire[0] = '0';
- pwExpire[1] = '\0';
-#endif
-
-#ifdef HAVE_PW_CLASS
- pwClass = pw->pw_class;
-#else
- pwClass = "";
-#endif
-
- need += strlen(pw->pw_name) + 1; /* one for fieldsep */
- need += strlen(pw->pw_passwd) + 1;
- need += strlen(pwUid) + 1;
- need += strlen(pwGid) + 1;
- need += strlen(pwClass) + 1;
- need += strlen(pwChange) + 1;
- need += strlen(pwExpire) + 1;
- need += strlen(pw->pw_gecos) + 1;
- need += strlen(pw->pw_dir) + 1;
- need += strlen(pw->pw_shell) + 1;
-
- if (buffer == NULL) {
- *len = need;
- return (0);
- }
-
- if (*buffer != NULL && need > *len) {
- errno = EINVAL;
- return (-1);
- }
-
- if (*buffer == NULL) {
- need += 2; /* for CRLF */
- *buffer = memget(need);
- if (*buffer == NULL) {
- errno = ENOMEM;
- return (-1);
- }
-
- *len = need;
- }
-
- strcpy(*buffer, pw->pw_name); strcat(*buffer, fieldsep);
- strcat(*buffer, pw->pw_passwd); strcat(*buffer, fieldsep);
- strcat(*buffer, pwUid); strcat(*buffer, fieldsep);
- strcat(*buffer, pwGid); strcat(*buffer, fieldsep);
- strcat(*buffer, pwClass); strcat(*buffer, fieldsep);
- strcat(*buffer, pwChange); strcat(*buffer, fieldsep);
- strcat(*buffer, pwExpire); strcat(*buffer, fieldsep);
- strcat(*buffer, pw->pw_gecos); strcat(*buffer, fieldsep);
- strcat(*buffer, pw->pw_dir); strcat(*buffer, fieldsep);
- strcat(*buffer, pw->pw_shell); strcat(*buffer, fieldsep);
-
- return (0);
-}
-
-
-
-
-
-/*
- * int irp_unmarshall_pw(struct passwd *pw, char *buffer)
- *
- * notes:
- *
- * see above
- *
- * return:
- *
- * 0 on success, -1 on failure
- *
- */
-
-int
-irp_unmarshall_pw(struct passwd *pw, char *buffer) {
- char *name, *pass, *class, *gecos, *dir, *shell;
- uid_t pwuid;
- gid_t pwgid;
- time_t pwchange;
- time_t pwexpire;
- char *p;
- long t;
- char tmpbuf[24];
- char *tb = &tmpbuf[0];
- char fieldsep = ':';
- int myerrno = EINVAL;
-
- name = pass = class = gecos = dir = shell = NULL;
- p = buffer;
-
- /* pw_name field */
- name = NULL;
- if (getfield(&name, 0, &p, fieldsep) == NULL || strlen(name) == 0) {
- goto error;
- }
-
- /* pw_passwd field */
- pass = NULL;
- if (getfield(&pass, 0, &p, fieldsep) == NULL) { /* field can be empty */
- goto error;
- }
-
-
- /* pw_uid field */
- tb = tmpbuf;
- if (getfield(&tb, sizeof tmpbuf, &p, fieldsep) == NULL ||
- strlen(tb) == 0) {
- goto error;
- }
- t = strtol(tmpbuf, &tb, 10);
- if (*tb) {
- goto error; /* junk in value */
- }
- pwuid = (uid_t)t;
- if ((long) pwuid != t) { /* value must have been too big. */
- goto error;
- }
-
-
-
- /* pw_gid field */
- tb = tmpbuf;
- if (getfield(&tb, sizeof tmpbuf, &p, fieldsep) == NULL ||
- strlen(tb) == 0) {
- goto error;
- }
- t = strtol(tmpbuf, &tb, 10);
- if (*tb) {
- goto error; /* junk in value */
- }
- pwgid = (gid_t)t;
- if ((long)pwgid != t) { /* value must have been too big. */
- goto error;
- }
-
-
-
- /* pw_class field */
- class = NULL;
- if (getfield(&class, 0, &p, fieldsep) == NULL) {
- goto error;
- }
-
-
-
- /* pw_change field */
- tb = tmpbuf;
- if (getfield(&tb, sizeof tmpbuf, &p, fieldsep) == NULL ||
- strlen(tb) == 0) {
- goto error;
- }
- t = strtol(tmpbuf, &tb, 10);
- if (*tb) {
- goto error; /* junk in value */
- }
- pwchange = (time_t)t;
- if ((long)pwchange != t) { /* value must have been too big. */
- goto error;
- }
-
-
-
- /* pw_expire field */
- tb = tmpbuf;
- if (getfield(&tb, sizeof tmpbuf, &p, fieldsep) == NULL ||
- strlen(tb) == 0) {
- goto error;
- }
- t = strtol(tmpbuf, &tb, 10);
- if (*tb) {
- goto error; /* junk in value */
- }
- pwexpire = (time_t)t;
- if ((long) pwexpire != t) { /* value must have been too big. */
- goto error;
- }
-
-
-
- /* pw_gecos field */
- gecos = NULL;
- if (getfield(&gecos, 0, &p, fieldsep) == NULL) {
- goto error;
- }
-
-
-
- /* pw_dir field */
- dir = NULL;
- if (getfield(&dir, 0, &p, fieldsep) == NULL) {
- goto error;
- }
-
-
-
- /* pw_shell field */
- shell = NULL;
- if (getfield(&shell, 0, &p, fieldsep) == NULL) {
- goto error;
- }
-
-
-
- pw->pw_name = name;
- pw->pw_passwd = pass;
- pw->pw_uid = pwuid;
- pw->pw_gid = pwgid;
- pw->pw_gecos = gecos;
- pw->pw_dir = dir;
- pw->pw_shell = shell;
-
-#ifdef HAVE_PW_CHANGE
- pw->pw_change = pwchange;
-#endif
-#ifdef HAVE_PW_CLASS
- pw->pw_class = class;
-#endif
-#ifdef HAVE_PW_EXPIRE
- pw->pw_expire = pwexpire;
-#endif
-
- return (0);
-
- error:
- errno = myerrno;
-
- if (name != NULL) free(name);
- if (pass != NULL) free(pass);
- if (gecos != NULL) free(gecos);
- if (dir != NULL) free(dir);
- if (shell != NULL) free(shell);
-
- return (-1);
-}
-
-/* ------------------------- struct passwd ------------------------- */
-#endif /* WANT_IRS_PW */
-
-
-
-/* +++++++++++++++++++++++++ struct group +++++++++++++++++++++++++ */
-
-
-
-/*
- * int irp_marshall_gr(const struct group *gr, char **buffer, size_t *len)
- *
- * notes:
- *
- * see above.
- *
- * return:
- *
- * 0 on success, -1 on failure
- */
-
-int
-irp_marshall_gr(const struct group *gr, char **buffer, size_t *len) {
- size_t need = 1; /* for null byte */
- char grGid[24];
- const char *fieldsep = COLONSTR;
-
- if (gr == NULL || len == NULL) {
- errno = EINVAL;
- return (-1);
- }
-
- sprintf(grGid, "%ld", (long)gr->gr_gid);
-
- need += strlen(gr->gr_name) + 1;
-#ifndef MISSING_GR_PASSWD
- need += strlen(gr->gr_passwd) + 1;
-#else
- need++;
-#endif
- need += strlen(grGid) + 1;
- need += joinlength(gr->gr_mem) + 1;
-
- if (buffer == NULL) {
- *len = need;
- return (0);
- }
-
- if (*buffer != NULL && need > *len) {
- errno = EINVAL;
- return (-1);
- }
-
- if (*buffer == NULL) {
- need += 2; /* for CRLF */
- *buffer = memget(need);
- if (*buffer == NULL) {
- errno = ENOMEM;
- return (-1);
- }
-
- *len = need;
- }
-
- strcpy(*buffer, gr->gr_name); strcat(*buffer, fieldsep);
-#ifndef MISSING_GR_PASSWD
- strcat(*buffer, gr->gr_passwd);
-#endif
- strcat(*buffer, fieldsep);
- strcat(*buffer, grGid); strcat(*buffer, fieldsep);
- joinarray(gr->gr_mem, *buffer, COMMA) ; strcat(*buffer, fieldsep);
-
- return (0);
-}
-
-
-
-
-/*
- * int irp_unmarshall_gr(struct group *gr, char *buffer)
- *
- * notes:
- *
- * see above
- *
- * return:
- *
- * 0 on success and -1 on failure.
- *
- */
-
-int
-irp_unmarshall_gr(struct group *gr, char *buffer) {
- char *p, *q;
- gid_t grgid;
- long t;
- char *name = NULL;
- char *pass = NULL;
- char **members = NULL;
- char tmpbuf[24];
- char *tb;
- char fieldsep = ':';
- int myerrno = EINVAL;
-
- if (gr == NULL || buffer == NULL) {
- errno = EINVAL;
- return (-1);
- }
-
- p = buffer;
-
- /* gr_name field */
- name = NULL;
- if (getfield(&name, 0, &p, fieldsep) == NULL || strlen(name) == 0) {
- goto error;
- }
-
-
- /* gr_passwd field */
- pass = NULL;
- if (getfield(&pass, 0, &p, fieldsep) == NULL) {
- goto error;
- }
-
-
- /* gr_gid field */
- tb = tmpbuf;
- if (getfield(&tb, sizeof tmpbuf, &p, fieldsep) == NULL ||
- strlen(tb) == 0) {
- goto error;
- }
- t = strtol(tmpbuf, &tb, 10);
- if (*tb) {
- goto error; /* junk in value */
- }
- grgid = (gid_t)t;
- if ((long) grgid != t) { /* value must have been too big. */
- goto error;
- }
-
-
- /* gr_mem field. Member names are separated by commas */
- q = strchr(p, fieldsep);
- if (q == NULL) {
- goto error;
- }
- members = splitarray(p, q, COMMA);
- if (members == NULL) {
- myerrno = errno;
- goto error;
- }
- p = q + 1;
-
-
- gr->gr_name = name;
-#ifndef MISSING_GR_PASSWD
- gr->gr_passwd = pass;
-#endif
- gr->gr_gid = grgid;
- gr->gr_mem = members;
-
- return (0);
-
- error:
- errno = myerrno;
-
- if (name != NULL) free(name);
- if (pass != NULL) free(pass);
-
- return (-1);
-}
-
-
-/* ------------------------- struct group ------------------------- */
-
-
-
-
-/* +++++++++++++++++++++++++ struct servent +++++++++++++++++++++++++ */
-
-
-
-/*
- * int irp_marshall_sv(const struct servent *sv, char **buffer, size_t *len)
- *
- * notes:
- *
- * see above
- *
- * return:
- *
- * 0 on success, -1 on failure.
- *
- */
-
-int
-irp_marshall_sv(const struct servent *sv, char **buffer, size_t *len) {
- size_t need = 1; /* for null byte */
- char svPort[24];
- const char *fieldsep = COLONSTR;
- short realport;
-
- if (sv == NULL || len == NULL) {
- errno = EINVAL;
- return (-1);
- }
-
- /* the int s_port field is actually a short in network order. We
- want host order to make the marshalled data look correct */
- realport = ntohs((short)sv->s_port);
- sprintf(svPort, "%d", realport);
-
- need += strlen(sv->s_name) + 1;
- need += joinlength(sv->s_aliases) + 1;
- need += strlen(svPort) + 1;
- need += strlen(sv->s_proto) + 1;
-
- if (buffer == NULL) {
- *len = need;
- return (0);
- }
-
- if (*buffer != NULL && need > *len) {
- errno = EINVAL;
- return (-1);
- }
-
- if (*buffer == NULL) {
- need += 2; /* for CRLF */
- *buffer = memget(need);
- if (*buffer == NULL) {
- errno = ENOMEM;
- return (-1);
- }
-
- *len = need;
- }
-
- strcpy(*buffer, sv->s_name); strcat(*buffer, fieldsep);
- joinarray(sv->s_aliases, *buffer, COMMA); strcat(*buffer, fieldsep);
- strcat(*buffer, svPort); strcat(*buffer, fieldsep);
- strcat(*buffer, sv->s_proto); strcat(*buffer, fieldsep);
-
- return (0);
-}
-
-
-
-
-
-/*
- * int irp_unmarshall_sv(struct servent *sv, char *buffer)
- *
- * notes:
- *
- * see above
- *
- * return:
- *
- * 0 on success, -1 on failure.
- *
- */
-
-int
-irp_unmarshall_sv(struct servent *sv, char *buffer) {
- char *p, *q;
- short svport;
- long t;
- char *name = NULL;
- char *proto = NULL;
- char **aliases = NULL;
- char tmpbuf[24];
- char *tb;
- char fieldsep = ':';
- int myerrno = EINVAL;
-
- if (sv == NULL || buffer == NULL)
- return (-1);
-
- p = buffer;
-
-
- /* s_name field */
- name = NULL;
- if (getfield(&name, 0, &p, fieldsep) == NULL || strlen(name) == 0) {
- goto error;
- }
-
-
- /* s_aliases field */
- q = strchr(p, fieldsep);
- if (q == NULL) {
- goto error;
- }
- aliases = splitarray(p, q, COMMA);
- if (aliases == NULL) {
- myerrno = errno;
- goto error;
- }
- p = q + 1;
-
-
- /* s_port field */
- tb = tmpbuf;
- if (getfield(&tb, sizeof tmpbuf, &p, fieldsep) == NULL ||
- strlen(tb) == 0) {
- goto error;
- }
- t = strtol(tmpbuf, &tb, 10);
- if (*tb) {
- goto error; /* junk in value */
- }
- svport = (short)t;
- if ((long) svport != t) { /* value must have been too big. */
- goto error;
- }
- svport = htons(svport);
-
- /* s_proto field */
- proto = NULL;
- if (getfield(&proto, 0, &p, fieldsep) == NULL) {
- goto error;
- }
-
- sv->s_name = name;
- sv->s_aliases = aliases;
- sv->s_port = svport;
- sv->s_proto = proto;
-
- return (0);
-
- error:
- errno = myerrno;
-
- if (name != NULL) free(name);
- if (proto != NULL) free(proto);
- free_array(aliases, 0);
-
- return (-1);
-}
-
-
-/* ------------------------- struct servent ------------------------- */
-
-/* +++++++++++++++++++++++++ struct protoent +++++++++++++++++++++++++ */
-
-
-
-/*
- * int irp_marshall_pr(struct protoent *pr, char **buffer, size_t *len)
- *
- * notes:
- *
- * see above
- *
- * return:
- *
- * 0 on success and -1 on failure.
- *
- */
-
-int
-irp_marshall_pr(struct protoent *pr, char **buffer, size_t *len) {
- size_t need = 1; /* for null byte */
- char prProto[24];
- const char *fieldsep = COLONSTR;
-
- if (pr == NULL || len == NULL) {
- errno = EINVAL;
- return (-1);
- }
-
- sprintf(prProto, "%d", (int)pr->p_proto);
-
- need += strlen(pr->p_name) + 1;
- need += joinlength(pr->p_aliases) + 1;
- need += strlen(prProto) + 1;
-
- if (buffer == NULL) {
- *len = need;
- return (0);
- }
-
- if (*buffer != NULL && need > *len) {
- errno = EINVAL;
- return (-1);
- }
-
- if (*buffer == NULL) {
- need += 2; /* for CRLF */
- *buffer = memget(need);
- if (*buffer == NULL) {
- errno = ENOMEM;
- return (-1);
- }
-
- *len = need;
- }
-
- strcpy(*buffer, pr->p_name); strcat(*buffer, fieldsep);
- joinarray(pr->p_aliases, *buffer, COMMA); strcat(*buffer, fieldsep);
- strcat(*buffer, prProto); strcat(*buffer, fieldsep);
-
- return (0);
-
-}
-
-
-
-/*
- * int irp_unmarshall_pr(struct protoent *pr, char *buffer)
- *
- * notes:
- *
- * See above
- *
- * return:
- *
- * 0 on success, -1 on failure
- *
- */
-
-int irp_unmarshall_pr(struct protoent *pr, char *buffer) {
- char *p, *q;
- int prproto;
- long t;
- char *name = NULL;
- char **aliases = NULL;
- char tmpbuf[24];
- char *tb;
- char fieldsep = ':';
- int myerrno = EINVAL;
-
- if (pr == NULL || buffer == NULL) {
- errno = EINVAL;
- return (-1);
- }
-
- p = buffer;
-
- /* p_name field */
- name = NULL;
- if (getfield(&name, 0, &p, fieldsep) == NULL || strlen(name) == 0) {
- goto error;
- }
-
-
- /* p_aliases field */
- q = strchr(p, fieldsep);
- if (q == NULL) {
- goto error;
- }
- aliases = splitarray(p, q, COMMA);
- if (aliases == NULL) {
- myerrno = errno;
- goto error;
- }
- p = q + 1;
-
-
- /* p_proto field */
- tb = tmpbuf;
- if (getfield(&tb, sizeof tmpbuf, &p, fieldsep) == NULL ||
- strlen(tb) == 0) {
- goto error;
- }
- t = strtol(tmpbuf, &tb, 10);
- if (*tb) {
- goto error; /* junk in value */
- }
- prproto = (int)t;
- if ((long) prproto != t) { /* value must have been too big. */
- goto error;
- }
-
- pr->p_name = name;
- pr->p_aliases = aliases;
- pr->p_proto = prproto;
-
- return (0);
-
- error:
- errno = myerrno;
-
- if (name != NULL) free(name);
- free_array(aliases, 0);
-
- return (-1);
-}
-
-/* ------------------------- struct protoent ------------------------- */
-
-
-
-/* +++++++++++++++++++++++++ struct hostent +++++++++++++++++++++++++ */
-
-
-/*
- * int irp_marshall_ho(struct hostent *ho, char **buffer, size_t *len)
- *
- * notes:
- *
- * see above.
- *
- * return:
- *
- * 0 on success, -1 on failure.
- *
- */
-
-int
-irp_marshall_ho(struct hostent *ho, char **buffer, size_t *len) {
- size_t need = 1; /* for null byte */
- char hoaddrtype[24];
- char holength[24];
- char **av;
- char *p;
- int addrlen;
- int malloced = 0;
- size_t remlen;
- const char *fieldsep = "@";
-
- if (ho == NULL || len == NULL) {
- errno = EINVAL;
- return (-1);
- }
-
- switch(ho->h_addrtype) {
- case AF_INET:
- strcpy(hoaddrtype, "AF_INET");
- break;
-
- case AF_INET6:
- strcpy(hoaddrtype, "AF_INET6");
- break;
-
- default:
- errno = EINVAL;
- return (-1);
- }
-
- sprintf(holength, "%d", ho->h_length);
-
- need += strlen(ho->h_name) + 1;
- need += joinlength(ho->h_aliases) + 1;
- need += strlen(hoaddrtype) + 1;
- need += strlen(holength) + 1;
-
- /* we determine an upper bound on the string length needed, not an
- exact length. */
- addrlen = (ho->h_addrtype == AF_INET ? 16 : 46) ; /* XX other AF's?? */
- for (av = ho->h_addr_list; av != NULL && *av != NULL ; av++)
- need += addrlen;
-
- if (buffer == NULL) {
- *len = need;
- return (0);
- }
-
- if (*buffer != NULL && need > *len) {
- errno = EINVAL;
- return (-1);
- }
-
- if (*buffer == NULL) {
- need += 2; /* for CRLF */
- *buffer = memget(need);
- if (*buffer == NULL) {
- errno = ENOMEM;
- return (-1);
- }
-
- *len = need;
- malloced = 1;
- }
-
- strcpy(*buffer, ho->h_name); strcat(*buffer, fieldsep);
- joinarray(ho->h_aliases, *buffer, COMMA); strcat(*buffer, fieldsep);
- strcat(*buffer, hoaddrtype); strcat(*buffer, fieldsep);
- strcat(*buffer, holength); strcat(*buffer, fieldsep);
-
- p = *buffer + strlen(*buffer);
- remlen = need - strlen(*buffer);
- for (av = ho->h_addr_list ; av != NULL && *av != NULL ; av++) {
- if (inet_ntop(ho->h_addrtype, *av, p, remlen) == NULL) {
- goto error;
- }
- if (*(av + 1) != NULL)
- strcat(p, COMMASTR);
- remlen -= strlen(p);
- p += strlen(p);
- }
- strcat(*buffer, fieldsep);
-
- return (0);
-
- error:
- if (malloced) {
- memput(*buffer, need);
- }
-
- return (-1);
-}
-
-
-
-/*
- * int irp_unmarshall_ho(struct hostent *ho, char *buffer)
- *
- * notes:
- *
- * See above.
- *
- * return:
- *
- * 0 on success, -1 on failure.
- *
- */
-
-int
-irp_unmarshall_ho(struct hostent *ho, char *buffer) {
- char *p, *q, *r;
- int hoaddrtype;
- int holength;
- long t;
- char *name = NULL;
- char **aliases = NULL;
- char **hohaddrlist = NULL;
- size_t hoaddrsize;
- char tmpbuf[24];
- char *tb;
- char **alist;
- int addrcount;
- char fieldsep = '@';
- int myerrno = EINVAL;
-
- if (ho == NULL || buffer == NULL) {
- errno = EINVAL;
- return (-1);
- }
-
- p = buffer;
-
- /* h_name field */
- name = NULL;
- if (getfield(&name, 0, &p, fieldsep) == NULL || strlen(name) == 0) {
- goto error;
- }
-
-
- /* h_aliases field */
- q = strchr(p, fieldsep);
- if (q == NULL) {
- goto error;
- }
- aliases = splitarray(p, q, COMMA);
- if (aliases == NULL) {
- myerrno = errno;
- goto error;
- }
- p = q + 1;
-
-
- /* h_addrtype field */
- tb = tmpbuf;
- if (getfield(&tb, sizeof tmpbuf, &p, fieldsep) == NULL ||
- strlen(tb) == 0) {
- goto error;
- }
- if (strcmp(tmpbuf, "AF_INET") == 0)
- hoaddrtype = AF_INET;
- else if (strcmp(tmpbuf, "AF_INET6") == 0)
- hoaddrtype = AF_INET6;
- else
- goto error;
-
-
- /* h_length field */
- tb = tmpbuf;
- if (getfield(&tb, sizeof tmpbuf, &p, fieldsep) == NULL ||
- strlen(tb) == 0) {
- goto error;
- }
- t = strtol(tmpbuf, &tb, 10);
- if (*tb) {
- goto error; /* junk in value */
- }
- holength = (int)t;
- if ((long) holength != t) { /* value must have been too big. */
- goto error;
- }
-
-
- /* h_addr_list field */
- q = strchr(p, fieldsep);
- if (q == NULL)
- goto error;
-
- /* count how many addresss are in there */
- if (q > p + 1) {
- for (addrcount = 1, r = p ; r != q ; r++) {
- if (*r == COMMA)
- addrcount++;
- }
- } else {
- addrcount = 0;
- }
-
- hoaddrsize = (addrcount + 1) * sizeof (char *);
- hohaddrlist = malloc(hoaddrsize);
- if (hohaddrlist == NULL) {
- myerrno = ENOMEM;
- goto error;
- }
-
- memset(hohaddrlist, 0x0, hoaddrsize);
-
- alist = hohaddrlist;
- for (t = 0, r = p ; r != q ; p = r + 1, t++) {
- char saved;
- while (r != q && *r != COMMA) r++;
- saved = *r;
- *r = 0x0;
-
- alist[t] = malloc(hoaddrtype == AF_INET ? 4 : 16);
- if (alist[t] == NULL) {
- myerrno = ENOMEM;
- goto error;
- }
-
- if (inet_pton(hoaddrtype, p, alist[t]) == -1)
- goto error;
- *r = saved;
- }
- alist[t] = NULL;
-
- ho->h_name = name;
- ho->h_aliases = aliases;
- ho->h_addrtype = hoaddrtype;
- ho->h_length = holength;
- ho->h_addr_list = hohaddrlist;
-
- return (0);
-
- error:
- errno = myerrno;
-
- if (name != NULL) free(name);
- free_array(aliases, 0);
-
- return (-1);
-}
-
-/* ------------------------- struct hostent------------------------- */
-
-
-
-/* +++++++++++++++++++++++++ struct netgrp +++++++++++++++++++++++++ */
-
-
-/*
- * int irp_marshall_ng(const char *host, const char *user,
- * const char *domain, char *buffer, size_t *len)
- *
- * notes:
- *
- * See note for irp_marshall_ng_start
- *
- * return:
- *
- * 0 on success, 0 on failure.
- *
- */
-
-int
-irp_marshall_ng(const char *host, const char *user, const char *domain,
- char **buffer, size_t *len) {
- size_t need = 1; /* for nul byte */
- const char *fieldsep = ",";
-
- if (len == NULL) {
- errno = EINVAL;
- return (-1);
- }
-
- need += 4; /* two parens and two commas */
- need += (host == NULL ? 0 : strlen(host));
- need += (user == NULL ? 0 : strlen(user));
- need += (domain == NULL ? 0 : strlen(domain));
-
- if (buffer == NULL) {
- *len = need;
- return (0);
- } else if (*buffer != NULL && need > *len) {
- errno = EINVAL;
- return (-1);
- }
-
- if (*buffer == NULL) {
- need += 2; /* for CRLF */
- *buffer = memget(need);
- if (*buffer == NULL) {
- errno = ENOMEM;
- return (-1);
- }
-
- *len = need;
- }
-
- (*buffer)[0] = '(';
- (*buffer)[1] = '\0';
-
- if (host != NULL)
- strcat(*buffer, host);
- strcat(*buffer, fieldsep);
-
- if (user != NULL)
- strcat(*buffer, user);
- strcat(*buffer, fieldsep);
-
- if (domain != NULL)
- strcat(*buffer, domain);
- strcat(*buffer, ")");
-
- return (0);
-}
-
-
-
-/* ---------- */
-
-
-/*
- * int irp_unmarshall_ng(const char **host, const char **user,
- * const char **domain, char *buffer)
- *
- * notes:
- *
- * Unpacks the BUFFER into 3 character arrays it allocates and assigns
- * to *HOST, *USER and *DOMAIN. If any field of the value is empty,
- * then the corresponding paramater value will be set to NULL.
- *
- * return:
- *
- * 0 on success and -1 on failure.
- */
-
-int
-irp_unmarshall_ng(const char **hostp, const char **userp, const char **domainp,
- char *buffer)
-{
- char *p, *q;
- char fieldsep = ',';
- int myerrno = EINVAL;
- char *host, *user, *domain;
-
- if (userp == NULL || hostp == NULL ||
- domainp == NULL || buffer == NULL) {
- errno = EINVAL;
- return (-1);
- }
-
- host = user = domain = NULL;
-
- p = buffer;
- while (isspace((unsigned char)*p)) {
- p++;
- }
- if (*p != '(') {
- goto error;
- }
-
- q = p + 1;
- while (*q && *q != fieldsep)
- q++;
- if (!*q) {
- goto error;
- } else if (q > p + 1) {
- host = strndup(p, q - p);
- }
-
- p = q + 1;
- if (!*p) {
- goto error;
- } else if (*p != fieldsep) {
- q = p + 1;
- while (*q && *q != fieldsep)
- q++;
- if (!*q) {
- goto error;
- }
- user = strndup(p, q - p);
- } else {
- p++;
- }
-
- if (!*p) {
- goto error;
- } else if (*p != ')') {
- q = p + 1;
- while (*q && *q != ')')
- q++;
- if (!*q) {
- goto error;
- }
- domain = strndup(p, q - p);
- }
- *hostp = host;
- *userp = user;
- *domainp = domain;
-
- return (0);
-
- error:
- errno = myerrno;
-
- if (host != NULL) free(host);
- if (user != NULL) free(user);
- if (domain != NULL) free(domain);
-
- return (-1);
-}
-
-/* ------------------------- struct netgrp ------------------------- */
-
-
-
-
-/* +++++++++++++++++++++++++ struct nwent +++++++++++++++++++++++++ */
-
-
-/*
- * int irp_marshall_nw(struct nwent *ne, char **buffer, size_t *len)
- *
- * notes:
- *
- * See at top.
- *
- * return:
- *
- * 0 on success and -1 on failure.
- *
- */
-
-int
-irp_marshall_nw(struct nwent *ne, char **buffer, size_t *len) {
- size_t need = 1; /* for null byte */
- char nAddrType[24];
- char nNet[MAXPADDRSIZE];
- const char *fieldsep = COLONSTR;
-
- if (ne == NULL || len == NULL) {
- return (-1);
- }
-
- strcpy(nAddrType, ADDR_T_STR(ne->n_addrtype));
-
- if (inet_net_ntop(ne->n_addrtype, ne->n_addr, ne->n_length,
- nNet, sizeof nNet) == NULL) {
- return (-1);
- }
-
-
- need += strlen(ne->n_name) + 1;
- need += joinlength(ne->n_aliases) + 1;
- need += strlen(nAddrType) + 1;
- need += strlen(nNet) + 1;
-
- if (buffer == NULL) {
- *len = need;
- return (0);
- }
-
- if (*buffer != NULL && need > *len) {
- errno = EINVAL;
- return (-1);
- }
-
- if (*buffer == NULL) {
- need += 2; /* for CRLF */
- *buffer = memget(need);
- if (*buffer == NULL) {
- errno = ENOMEM;
- return (-1);
- }
-
- *len = need;
- }
-
- strcpy(*buffer, ne->n_name); strcat(*buffer, fieldsep);
- joinarray(ne->n_aliases, *buffer, COMMA) ; strcat(*buffer, fieldsep);
- strcat(*buffer, nAddrType); strcat(*buffer, fieldsep);
- strcat(*buffer, nNet); strcat(*buffer, fieldsep);
-
- return (0);
-}
-
-
-
-/*
- * int irp_unmarshall_nw(struct nwent *ne, char *buffer)
- *
- * notes:
- *
- * See note up top.
- *
- * return:
- *
- * 0 on success and -1 on failure.
- *
- */
-
-int
-irp_unmarshall_nw(struct nwent *ne, char *buffer) {
- char *p, *q;
- int naddrtype;
- long nnet;
- int bits;
- char *name = NULL;
- char **aliases = NULL;
- char tmpbuf[24];
- char *tb;
- char fieldsep = ':';
- int myerrno = EINVAL;
-
- if (ne == NULL || buffer == NULL) {
- goto error;
- }
-
- p = buffer;
-
- /* n_name field */
- name = NULL;
- if (getfield(&name, 0, &p, fieldsep) == NULL || strlen(name) == 0) {
- goto error;
- }
-
-
- /* n_aliases field. Aliases are separated by commas */
- q = strchr(p, fieldsep);
- if (q == NULL) {
- goto error;
- }
- aliases = splitarray(p, q, COMMA);
- if (aliases == NULL) {
- myerrno = errno;
- goto error;
- }
- p = q + 1;
-
-
- /* h_addrtype field */
- tb = tmpbuf;
- if (getfield(&tb, sizeof tmpbuf, &p, fieldsep) == NULL ||
- strlen(tb) == 0) {
- goto error;
- }
- if (strcmp(tmpbuf, "AF_INET") == 0)
- naddrtype = AF_INET;
- else if (strcmp(tmpbuf, "AF_INET6") == 0)
- naddrtype = AF_INET6;
- else
- goto error;
-
-
- /* n_net field */
- tb = tmpbuf;
- if (getfield(&tb, sizeof tmpbuf, &p, fieldsep) == NULL ||
- strlen(tb) == 0) {
- goto error;
- }
- nnet = 0;
- bits = inet_net_pton(naddrtype, tmpbuf, &nnet, sizeof nnet);
- if (bits < 0) {
- goto error;
- }
-
- /* nnet = ntohl(nnet); */ /* keep in network order for nwent */
-
- ne->n_name = name;
- ne->n_aliases = aliases;
- ne->n_addrtype = naddrtype;
- ne->n_length = bits;
- ne->n_addr = malloc(sizeof nnet);
- if (ne->n_addr == NULL) {
- goto error;
- }
-
- memcpy(ne->n_addr, &nnet, sizeof nnet);
-
- return (0);
-
- error:
- errno = myerrno;
-
- if (name != NULL) free(name);
- free_array(aliases, 0);
-
- return (-1);
-}
-
-
-/* ------------------------- struct nwent ------------------------- */
-
-
-/* +++++++++++++++++++++++++ struct netent +++++++++++++++++++++++++ */
-
-
-/*
- * int irp_marshall_ne(struct netent *ne, char **buffer, size_t *len)
- *
- * notes:
- *
- * See at top.
- *
- * return:
- *
- * 0 on success and -1 on failure.
- *
- */
-
-int
-irp_marshall_ne(struct netent *ne, char **buffer, size_t *len) {
- size_t need = 1; /* for null byte */
- char nAddrType[24];
- char nNet[MAXPADDRSIZE];
- const char *fieldsep = COLONSTR;
- long nval;
-
- if (ne == NULL || len == NULL) {
- return (-1);
- }
-
- strcpy(nAddrType, ADDR_T_STR(ne->n_addrtype));
-
- nval = htonl(ne->n_net);
- if (inet_ntop(ne->n_addrtype, &nval, nNet, sizeof nNet) == NULL) {
- return (-1);
- }
-
- need += strlen(ne->n_name) + 1;
- need += joinlength(ne->n_aliases) + 1;
- need += strlen(nAddrType) + 1;
- need += strlen(nNet) + 1;
-
- if (buffer == NULL) {
- *len = need;
- return (0);
- }
-
- if (*buffer != NULL && need > *len) {
- errno = EINVAL;
- return (-1);
- }
-
- if (*buffer == NULL) {
- need += 2; /* for CRLF */
- *buffer = memget(need);
- if (*buffer == NULL) {
- errno = ENOMEM;
- return (-1);
- }
-
- *len = need;
- }
-
- strcpy(*buffer, ne->n_name); strcat(*buffer, fieldsep);
- joinarray(ne->n_aliases, *buffer, COMMA) ; strcat(*buffer, fieldsep);
- strcat(*buffer, nAddrType); strcat(*buffer, fieldsep);
- strcat(*buffer, nNet); strcat(*buffer, fieldsep);
-
- return (0);
-}
-
-
-
-/*
- * int irp_unmarshall_ne(struct netent *ne, char *buffer)
- *
- * notes:
- *
- * See note up top.
- *
- * return:
- *
- * 0 on success and -1 on failure.
- *
- */
-
-int
-irp_unmarshall_ne(struct netent *ne, char *buffer) {
- char *p, *q;
- int naddrtype;
- long nnet;
- int bits;
- char *name = NULL;
- char **aliases = NULL;
- char tmpbuf[24];
- char *tb;
- char fieldsep = ':';
- int myerrno = EINVAL;
-
- if (ne == NULL || buffer == NULL) {
- goto error;
- }
-
- p = buffer;
-
- /* n_name field */
- name = NULL;
- if (getfield(&name, 0, &p, fieldsep) == NULL || strlen(name) == 0) {
- goto error;
- }
-
-
- /* n_aliases field. Aliases are separated by commas */
- q = strchr(p, fieldsep);
- if (q == NULL) {
- goto error;
- }
- aliases = splitarray(p, q, COMMA);
- if (aliases == NULL) {
- myerrno = errno;
- goto error;
- }
- p = q + 1;
-
-
- /* h_addrtype field */
- tb = tmpbuf;
- if (getfield(&tb, sizeof tmpbuf, &p, fieldsep) == NULL ||
- strlen(tb) == 0) {
- goto error;
- }
- if (strcmp(tmpbuf, "AF_INET") == 0)
- naddrtype = AF_INET;
- else if (strcmp(tmpbuf, "AF_INET6") == 0)
- naddrtype = AF_INET6;
- else
- goto error;
-
-
- /* n_net field */
- tb = tmpbuf;
- if (getfield(&tb, sizeof tmpbuf, &p, fieldsep) == NULL ||
- strlen(tb) == 0) {
- goto error;
- }
- bits = inet_net_pton(naddrtype, tmpbuf, &nnet, sizeof nnet);
- if (bits < 0) {
- goto error;
- }
- nnet = ntohl(nnet);
-
- ne->n_name = name;
- ne->n_aliases = aliases;
- ne->n_addrtype = naddrtype;
- ne->n_net = nnet;
-
- return (0);
-
- error:
- errno = myerrno;
-
- if (name != NULL) free(name);
- free_array(aliases, 0);
-
- return (-1);
-}
-
-
-/* ------------------------- struct netent ------------------------- */
-
-
-/* =========================================================================== */
-
-
-/*
- * static char ** splitarray(const char *buffer, const char *buffend, char delim)
- *
- * notes:
- *
- * Split a delim separated astring. Not allowed
- * to have two delims next to each other. BUFFER points to begining of
- * string, BUFFEND points to one past the end of the string
- * (i.e. points at where the null byte would be if null
- * terminated).
- *
- * return:
- *
- * Returns a malloced array of pointers, each pointer pointing to a
- * malloced string. If BUFEER is an empty string, then return values is
- * array of 1 pointer that is NULL. Returns NULL on failure.
- *
- */
-
-static char **
-splitarray(const char *buffer, const char *buffend, char delim) {
- const char *p, *q;
- int count = 0;
- char **arr = NULL;
- char **aptr;
-
- if (buffend < buffer)
- return (NULL);
- else if (buffend > buffer && *buffer == delim)
- return (NULL);
- else if (buffend > buffer && *(buffend - 1) == delim)
- return (NULL);
-
- /* count the number of field and make sure none are empty */
- if (buffend > buffer + 1) {
- for (count = 1, q = buffer ; q != buffend ; q++) {
- if (*q == delim) {
- if (q > buffer && (*(q - 1) == delim)) {
- errno = EINVAL;
- return (NULL);
- }
- count++;
- }
- }
- }
-
- if (count > 0) {
- count++ ; /* for NULL at end */
- aptr = arr = malloc(count * sizeof (char *));
- if (aptr == NULL) {
- errno = ENOMEM;
- return (NULL);
- }
-
- memset(arr, 0x0, count * sizeof (char *));
- for (p = buffer ; p < buffend ; p++) {
- for (q = p ; *q != delim && q != buffend ; q++)
- /* nothing */;
- *aptr = strndup(p, q - p);
-
- p = q;
- aptr++;
- }
- *aptr = NULL;
- } else {
- arr = malloc(sizeof (char *));
- if (arr == NULL) {
- errno = ENOMEM;
- return (NULL);
- }
-
- *arr = NULL;
- }
-
- return (arr);
-}
-
-
-
-
-/*
- * static size_t joinlength(char * const *argv)
- *
- * return:
- *
- * the number of bytes in all the arrays pointed at
- * by argv, including their null bytes(which will usually be turned
- * into commas).
- *
- *
- */
-
-static size_t
-joinlength(char * const *argv) {
- int len = 0;
-
- while (argv && *argv) {
- len += (strlen(*argv) + 1);
- argv++;
- }
-
- return (len);
-}
-
-
-
-/*
- * int joinarray(char * const *argv, char *buffer, char delim)
- *
- * notes:
- *
- * Copy all the ARGV strings into the end of BUFFER
- * separating them with DELIM. BUFFER is assumed to have
- * enough space to hold everything and to be already null-terminated.
- *
- * return:
- *
- * 0 unless argv or buffer is NULL.
- *
- *
- */
-
-static int
-joinarray(char * const *argv, char *buffer, char delim) {
- char * const *p;
- char sep[2];
-
- if (argv == NULL || buffer == NULL) {
- errno = EINVAL;
- return (-1);
- }
-
- sep[0] = delim;
- sep[1] = 0x0;
-
- for (p = argv ; *p != NULL ; p++) {
- strcat(buffer, *p);
- if (*(p + 1) != NULL) {
- strcat(buffer, sep);
- }
- }
-
- return (0);
-}
-
-
-/*
- * static char * getfield(char **res, size_t reslen, char **ptr, char delim)
- *
- * notes:
- *
- * Stores in *RES, which is a buffer of length RESLEN, a
- * copy of the bytes from *PTR up to and including the first
- * instance of DELIM. If *RES is NULL, then it will be
- * assigned a malloced buffer to hold the copy. *PTR is
- * modified to point at the found delimiter.
- *
- * return:
- *
- * If there was no delimiter, then NULL is returned,
- * otherewise *RES is returned.
- *
- */
-
-static char *
-getfield(char **res, size_t reslen, char **ptr, char delim) {
- char *q;
-
- if (res == NULL || ptr == NULL || *ptr == NULL) {
- errno = EINVAL;
- return (NULL);
- }
-
- q = strchr(*ptr, delim);
-
- if (q == NULL) {
- errno = EINVAL;
- return (NULL);
- } else {
- if (*res == NULL) {
- *res = strndup(*ptr, q - *ptr);
- } else {
- if ((size_t)(q - *ptr + 1) > reslen) { /* to big for res */
- errno = EINVAL;
- return (NULL);
- } else {
- strncpy(*res, *ptr, q - *ptr);
- (*res)[q - *ptr] = 0x0;
- }
- }
- *ptr = q + 1;
- }
-
- return (*res);
-}
-
-
-
-
-
-#ifndef HAVE_STRNDUP
-/*
- * static char * strndup(const char *str, size_t len)
- *
- * notes:
- *
- * like strdup, except do len bytes instead of the whole string. Always
- * null-terminates.
- *
- * return:
- *
- * The newly malloced string.
- *
- */
-
-static char *
-strndup(const char *str, size_t len) {
- char *p = malloc(len + 1);
-
- if (p == NULL)
- return (NULL);
- strncpy(p, str, len);
- p[len] = 0x0;
- return (p);
-}
-#endif
-
-#if WANT_MAIN
-
-/*
- * static int strcmp_nws(const char *a, const char *b)
- *
- * notes:
- *
- * do a strcmp, except uneven lengths of whitespace compare the same
- *
- * return:
- *
- */
-
-static int
-strcmp_nws(const char *a, const char *b) {
- while (*a && *b) {
- if (isspace(*a) && isspace(*b)) {
- do {
- a++;
- } while (isspace(*a));
- do {
- b++;
- } while (isspace(*b));
- }
- if (*a < *b)
- return (-1);
- else if (*a > *b)
- return (1);
-
- a++;
- b++;;
- }
-
- if (*a == *b)
- return (0);
- else if (*a > *b)
- return (1);
- else
- return (-1);
-}
-
-#endif
-
-
-
-
-
-/*
- * static void free_array(char **argv, size_t entries)
- *
- * notes:
- *
- * Free argv and each of the pointers inside it. The end of
- * the array is when a NULL pointer is found inside. If
- * entries is > 0, then NULL pointers inside the array do
- * not indicate the end of the array.
- *
- */
-
-static void
-free_array(char **argv, size_t entries) {
- char **p = argv;
- int useEntries = (entries > 0);
-
- if (argv == NULL)
- return;
-
- while ((useEntries && entries > 0) || *p) {
- if (*p)
- free(*p);
- p++;
- if (useEntries)
- entries--;
- }
- free(argv);
-}
-
-
-
-
-
-/* ************************************************** */
-
-#if WANT_MAIN
-
-/* takes an option to indicate what sort of marshalling(read the code) and
- an argument. If the argument looks like a marshalled buffer(has a ':'
- embedded) then it's unmarshalled and the remarshalled and the new string
- is compared to the old one.
-*/
-
-int
-main(int argc, char **argv) {
- char buffer[1024];
- char *b = &buffer[0];
- size_t len = sizeof buffer;
- char option;
-
- if (argc < 2 || argv[1][0] != '-')
- exit(1);
-
- option = argv[1][1];
- argv++;
- argc--;
-
-
-#if 0
- {
- char buff[10];
- char *p = argv[1], *q = &buff[0];
-
- while (getfield(&q, sizeof buff, &p, ':') != NULL) {
- printf("field: \"%s\"\n", q);
- p++;
- }
- printf("p is now \"%s\"\n", p);
- }
-#endif
-
-#if 0
- {
- char **x = splitarray(argv[1], argv[1] + strlen(argv[1]),
- argv[2][0]);
- char **p;
-
- if (x == NULL)
- printf("split failed\n");
-
- for (p = x ; p != NULL && *p != NULL ; p++) {
- printf("\"%s\"\n", *p);
- }
- }
-#endif
-
-#if 1
- switch(option) {
- case 'n': {
- struct nwent ne;
- int i;
-
- if (strchr(argv[1], ':') != NULL) {
- if (irp_unmarshall_nw(&ne, argv[1]) != 0) {
- printf("Unmarhsalling failed\n");
- exit(1);
- }
-
- printf("Name: \"%s\"\n", ne.n_name);
- printf("Aliases:");
- for (i = 0 ; ne.n_aliases[i] != NULL ; i++)
- printf("\n\t\"%s\"", ne.n_aliases[i]);
- printf("\nAddrtype: %s\n", ADDR_T_STR(ne.n_addrtype));
- inet_net_ntop(ne.n_addrtype, ne.n_addr, ne.n_length,
- buffer, sizeof buffer);
- printf("Net: \"%s\"\n", buffer);
- *((long*)ne.n_addr) = htonl(*((long*)ne.n_addr));
- inet_net_ntop(ne.n_addrtype, ne.n_addr, ne.n_length,
- buffer, sizeof buffer);
- printf("Corrected Net: \"%s\"\n", buffer);
- } else {
- struct netent *np1 = getnetbyname(argv[1]);
- ne.n_name = np1->n_name;
- ne.n_aliases = np1->n_aliases;
- ne.n_addrtype = np1->n_addrtype;
- ne.n_addr = &np1->n_net;
- ne.n_length = (IN_CLASSA(np1->n_net) ?
- 8 :
- (IN_CLASSB(np1->n_net) ?
- 16 :
- (IN_CLASSC(np1->n_net) ?
- 24 : -1)));
- np1->n_net = htonl(np1->n_net);
- if (irp_marshall_nw(&ne, &b, &len) != 0) {
- printf("Marshalling failed\n");
- }
- printf("%s\n", b);
- }
- break;
- }
-
-
- case 'r': {
- char **hosts, **users, **domains;
- size_t entries;
- int i;
- char *buff;
- size_t size;
- char *ngname;
-
- if (strchr(argv[1], '(') != NULL) {
- if (irp_unmarshall_ng(&ngname, &entries,
- &hosts, &users, &domains,
- argv[1]) != 0) {
- printf("unmarshall failed\n");
- exit(1);
- }
-
-#define STRVAL(x) (x == NULL ? "*" : x)
-
- printf("%s {\n", ngname);
- for (i = 0 ; i < entries ; i++)
- printf("\t\"%s\" : \"%s\" : \"%s\"\n",
- STRVAL(hosts[i]),
- STRVAL(users[i]),
- STRVAL(domains[i]));
- printf("}\n\n\n");
-
-
- irp_marshall_ng_start(ngname, NULL, &size);
- for (i = 0 ; i < entries ; i++)
- irp_marshall_ng_next(hosts[i], users[i],
- domains[i], NULL, &size);
- irp_marshall_ng_end(NULL, &size);
-
- buff = malloc(size);
-
- irp_marshall_ng_start(ngname, buff, &size);
- for (i = 0 ; i < entries ; i++) {
- if (irp_marshall_ng_next(hosts[i], users[i],
- domains[i], buff,
- &size) != 0)
- printf("next marshalling failed.\n");
- }
- irp_marshall_ng_end(buff, &size);
-
- if (strcmp_nws(argv[1], buff) != 0) {
- printf("compare failed:\n\t%s\n\t%s\n",
- buffer, argv[1]);
- } else {
- printf("compare ok\n");
- }
- } else {
- char *h, *u, *d, *buff;
- size_t size;
-
- /* run through two times. First to figure out how
- much of a buffer we need. Second to do the
- actual marshalling */
-
- setnetgrent(argv[1]);
- irp_marshall_ng_start(argv[1], NULL, &size);
- while (getnetgrent(&h, &u, &d) == 1)
- irp_marshall_ng_next(h, u, d, NULL, &size);
- irp_marshall_ng_end(NULL, &size);
- endnetgrent(argv[1]);
-
- buff = malloc(size);
-
- setnetgrent(argv[1]);
- if (irp_marshall_ng_start(argv[1], buff, &size) != 0)
- printf("Marshalling start failed\n");
-
- while (getnetgrent(&h, &u, &d) == 1) {
- if (irp_marshall_ng_next(h, u, d, buff, &size)
- != 0) {
- printf("Marshalling failed\n");
- }
- }
-
- irp_marshall_ng_end(buff, &size);
- endnetgrent();
-
- printf("success: %s\n", buff);
- }
- break;
- }
-
-
-
- case 'h': {
- struct hostent he, *hp;
- int i;
-
-
- if (strchr(argv[1], '@') != NULL) {
- if (irp_unmarshall_ho(&he, argv[1]) != 0) {
- printf("unmarshall failed\n");
- exit(1);
- }
-
- printf("Host: \"%s\"\nAliases:", he.h_name);
- for (i = 0 ; he.h_aliases[i] != NULL ; i++)
- printf("\n\t\t\"%s\"", he.h_aliases[i]);
- printf("\nAddr Type: \"%s\"\n",
- ADDR_T_STR(he.h_addrtype));
- printf("Length: %d\nAddresses:", he.h_length);
- for (i = 0 ; he.h_addr_list[i] != 0 ; i++) {
- inet_ntop(he.h_addrtype, he.h_addr_list[i],
- buffer, sizeof buffer);
- printf("\n\t\"%s\"\n", buffer);
- }
- printf("\n\n");
-
- irp_marshall_ho(&he, &b, &len);
- if (strcmp(argv[1], buffer) != 0) {
- printf("compare failed:\n\t\"%s\"\n\t\"%s\"\n",
- buffer, argv[1]);
- } else {
- printf("compare ok\n");
- }
- } else {
- if ((hp = gethostbyname(argv[1])) == NULL) {
- perror("gethostbyname");
- printf("\"%s\"\n", argv[1]);
- exit(1);
- }
-
- if (irp_marshall_ho(hp, &b, &len) != 0) {
- printf("irp_marshall_ho failed\n");
- exit(1);
- }
-
- printf("success: \"%s\"\n", buffer);
- }
- break;
- }
-
-
- case 's': {
- struct servent *sv;
- struct servent sv1;
-
- if (strchr(argv[1], ':') != NULL) {
- sv = &sv1;
- memset(sv, 0xef, sizeof (struct servent));
- if (irp_unmarshall_sv(sv, argv[1]) != 0) {
- printf("unmarshall failed\n");
-
- }
-
- irp_marshall_sv(sv, &b, &len);
- if (strcmp(argv[1], buffer) != 0) {
- printf("compare failed:\n\t\"%s\"\n\t\"%s\"\n",
- buffer, argv[1]);
- } else {
- printf("compare ok\n");
- }
- } else {
- if ((sv = getservbyname(argv[1], argv[2])) == NULL) {
- perror("getservent");
- exit(1);
- }
-
- if (irp_marshall_sv(sv, &b, &len) != 0) {
- printf("irp_marshall_sv failed\n");
- exit(1);
- }
-
- printf("success: \"%s\"\n", buffer);
- }
- break;
- }
-
- case 'g': {
- struct group *gr;
- struct group gr1;
-
- if (strchr(argv[1], ':') != NULL) {
- gr = &gr1;
- memset(gr, 0xef, sizeof (struct group));
- if (irp_unmarshall_gr(gr, argv[1]) != 0) {
- printf("unmarshall failed\n");
-
- }
-
- irp_marshall_gr(gr, &b, &len);
- if (strcmp(argv[1], buffer) != 0) {
- printf("compare failed:\n\t\"%s\"\n\t\"%s\"\n",
- buffer, argv[1]);
- } else {
- printf("compare ok\n");
- }
- } else {
- if ((gr = getgrnam(argv[1])) == NULL) {
- perror("getgrnam");
- exit(1);
- }
-
- if (irp_marshall_gr(gr, &b, &len) != 0) {
- printf("irp_marshall_gr failed\n");
- exit(1);
- }
-
- printf("success: \"%s\"\n", buffer);
- }
- break;
- }
-
-
- case 'p': {
- struct passwd *pw;
- struct passwd pw1;
-
- if (strchr(argv[1], ':') != NULL) {
- pw = &pw1;
- memset(pw, 0xef, sizeof (*pw));
- if (irp_unmarshall_pw(pw, argv[1]) != 0) {
- printf("unmarshall failed\n");
- exit(1);
- }
-
- printf("User: \"%s\"\nPasswd: \"%s\"\nUid: %ld\nGid: %ld\n",
- pw->pw_name, pw->pw_passwd, (long)pw->pw_uid,
- (long)pw->pw_gid);
- printf("Class: \"%s\"\nChange: %ld\nGecos: \"%s\"\n",
- pw->pw_class, (long)pw->pw_change, pw->pw_gecos);
- printf("Shell: \"%s\"\nDirectory: \"%s\"\n",
- pw->pw_shell, pw->pw_dir);
-
- pw = getpwnam(pw->pw_name);
- irp_marshall_pw(pw, &b, &len);
- if (strcmp(argv[1], buffer) != 0) {
- printf("compare failed:\n\t\"%s\"\n\t\"%s\"\n",
- buffer, argv[1]);
- } else {
- printf("compare ok\n");
- }
- } else {
- if ((pw = getpwnam(argv[1])) == NULL) {
- perror("getpwnam");
- exit(1);
- }
-
- if (irp_marshall_pw(pw, &b, &len) != 0) {
- printf("irp_marshall_pw failed\n");
- exit(1);
- }
-
- printf("success: \"%s\"\n", buffer);
- }
- break;
- }
-
- default:
- printf("Wrong option: %c\n", option);
- break;
- }
-
-#endif
-
- return (0);
-}
-
-#endif
diff --git a/contrib/bind/lib/irs/irs_data.c b/contrib/bind/lib/irs/irs_data.c
deleted file mode 100644
index f69a6b4..0000000
--- a/contrib/bind/lib/irs/irs_data.c
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: irs_data.c,v 1.20.2.1 2003/06/02 10:09:48 marka Exp $";
-#endif
-
-#include "port_before.h"
-
-#ifndef __BIND_NOSTATIC
-
-#include <sys/types.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-
-#include <resolv.h>
-#include <stdio.h>
-#include <string.h>
-#include <isc/memcluster.h>
-
-#ifdef DO_PTHREADS
-#include <pthread.h>
-#endif
-
-#include <irs.h>
-#include <stdlib.h>
-
-#include "port_after.h"
-
-#include "irs_data.h"
-#undef _res
-#undef h_errno
-
-extern struct __res_state _res;
-extern int h_errno;
-
-#ifdef DO_PTHREADS
-static pthread_key_t key;
-static int once = 0;
-#else
-static struct net_data *net_data;
-#endif
-
-void
-irs_destroy(void) {
-#ifndef DO_PTHREADS
- if (net_data != NULL)
- net_data_destroy(net_data);
- net_data = NULL;
-#endif
-}
-
-void
-net_data_destroy(void *p) {
- struct net_data *net_data = p;
-
- res_ndestroy(net_data->res);
- if (net_data->gr != NULL) {
- (*net_data->gr->close)(net_data->gr);
- net_data->gr = NULL;
- }
- if (net_data->pw != NULL) {
- (*net_data->pw->close)(net_data->pw);
- net_data->pw = NULL;
- }
- if (net_data->sv != NULL) {
- (*net_data->sv->close)(net_data->sv);
- net_data->sv = NULL;
- }
- if (net_data->pr != NULL) {
- (*net_data->pr->close)(net_data->pr);
- net_data->pr = NULL;
- }
- if (net_data->ho != NULL) {
- (*net_data->ho->close)(net_data->ho);
- net_data->ho = NULL;
- }
- if (net_data->nw != NULL) {
- (*net_data->nw->close)(net_data->nw);
- net_data->nw = NULL;
- }
- if (net_data->ng != NULL) {
- (*net_data->ng->close)(net_data->ng);
- net_data->ng = NULL;
- }
- if (net_data->ho_data != NULL) {
- free(net_data->ho_data);
- net_data->ho_data = NULL;
- }
- if (net_data->nw_data != NULL) {
- free(net_data->nw_data);
- net_data->nw_data = NULL;
- }
-
- (*net_data->irs->close)(net_data->irs);
- memput(net_data, sizeof *net_data);
-}
-
-/* applications that need a specific config file other than
- * _PATH_IRS_CONF should call net_data_init directly rather than letting
- * the various wrapper functions make the first call. - brister
- */
-
-struct net_data *
-net_data_init(const char *conf_file) {
-#ifdef DO_PTHREADS
- static pthread_mutex_t keylock = PTHREAD_MUTEX_INITIALIZER;
- struct net_data *net_data;
-
- if (!once) {
- pthread_mutex_lock(&keylock);
- if (!once++)
- pthread_key_create(&key, net_data_destroy);
- pthread_mutex_unlock(&keylock);
- }
- net_data = pthread_getspecific(key);
-#endif
-
- if (net_data == NULL) {
- net_data = net_data_create(conf_file);
- if (net_data == NULL)
- return (NULL);
-#ifdef DO_PTHREADS
- pthread_setspecific(key, net_data);
-#endif
- }
-
- return (net_data);
-}
-
-struct net_data *
-net_data_create(const char *conf_file) {
- struct net_data *net_data;
-
- net_data = memget(sizeof (struct net_data));
- if (net_data == NULL)
- return (NULL);
- memset(net_data, 0, sizeof (struct net_data));
-
- if ((net_data->irs = irs_gen_acc("", conf_file)) == NULL) {
- memput(net_data, sizeof (struct net_data));
- return (NULL);
- }
-#ifndef DO_PTHREADS
- (*net_data->irs->res_set)(net_data->irs, &_res, NULL);
-#endif
-
- net_data->res = (*net_data->irs->res_get)(net_data->irs);
- if (net_data->res == NULL) {
- (*net_data->irs->close)(net_data->irs);
- memput(net_data, sizeof (struct net_data));
- return (NULL);
- }
-
- if ((net_data->res->options & RES_INIT) == 0 &&
- res_ninit(net_data->res) == -1) {
- (*net_data->irs->close)(net_data->irs);
- memput(net_data, sizeof (struct net_data));
- return (NULL);
- }
-
- return (net_data);
-}
-
-
-
-void
-net_data_minimize(struct net_data *net_data) {
- res_nclose(net_data->res);
-}
-
-#ifdef _REENTRANT
-struct __res_state *
-__res_state(void) {
- /* NULL param here means use the default config file. */
- struct net_data *net_data = net_data_init(NULL);
- if (net_data && net_data->res)
- return (net_data->res);
-
- return (&_res);
-}
-#endif
-
-int *
-__h_errno(void) {
- /* NULL param here means use the default config file. */
- struct net_data *net_data = net_data_init(NULL);
- if (net_data && net_data->res)
- return (&net_data->res->res_h_errno);
- return (&h_errno);
-}
-
-void
-__h_errno_set(struct __res_state *res, int err) {
-
- h_errno = res->res_h_errno = err;
-}
-
-#endif /*__BIND_NOSTATIC*/
diff --git a/contrib/bind/lib/irs/irs_data.h b/contrib/bind/lib/irs/irs_data.h
deleted file mode 100644
index c82d767..0000000
--- a/contrib/bind/lib/irs/irs_data.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-/*
- * $Id: irs_data.h,v 1.12 1999/01/18 07:46:55 vixie Exp $
- */
-
-#ifndef __BIND_NOSTATIC
-
-#define net_data_init __net_data_init
-
-struct net_data {
- struct irs_acc * irs;
-
- struct irs_gr * gr;
- struct irs_pw * pw;
- struct irs_sv * sv;
- struct irs_pr * pr;
- struct irs_ho * ho;
- struct irs_nw * nw;
- struct irs_ng * ng;
-
- struct group * gr_last;
- struct passwd * pw_last;
- struct servent * sv_last;
- struct protoent * pr_last;
- struct netent * nw_last; /* should have been ne_last */
- struct nwent * nww_last;
- struct hostent * ho_last;
-
- unsigned int gr_stayopen :1;
- unsigned int pw_stayopen :1;
- unsigned int sv_stayopen :1;
- unsigned int pr_stayopen :1;
- unsigned int ho_stayopen :1;
- unsigned int nw_stayopen :1;
-
- void * nw_data;
- void * ho_data;
-
- struct __res_state * res; /* for gethostent.c */
-
-};
-
-extern struct net_data * net_data_init(const char *conf_file);
-extern void net_data_minimize(struct net_data *);
-
-#endif /*__BIND_NOSTATIC*/
diff --git a/contrib/bind/lib/irs/irs_p.h b/contrib/bind/lib/irs/irs_p.h
deleted file mode 100644
index d14f7d1..0000000
--- a/contrib/bind/lib/irs/irs_p.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-/*
- * $Id: irs_p.h,v 1.8 1999/01/08 19:24:42 vixie Exp $
- */
-
-#ifndef _IRS_P_H_INCLUDED
-#define _IRS_P_H_INCLUDED
-
-#include <stdio.h>
-
-#include "pathnames.h"
-
-#define IRS_SV_MAXALIASES 35
-
-struct lcl_sv {
- FILE * fp;
- char line[BUFSIZ+1];
- struct servent serv;
- char * serv_aliases[IRS_SV_MAXALIASES];
-};
-
-#define irs_nul_ng __irs_nul_ng
-#define map_v4v6_address __map_v4v6_address
-#define make_group_list __make_group_list
-#define irs_lclsv_fnxt __irs_lclsv_fnxt
-
-extern void map_v4v6_address(const char *src, char *dst);
-extern int make_group_list(struct irs_gr *, const char *,
- gid_t, gid_t *, int *);
-extern struct irs_ng * irs_nul_ng(struct irs_acc *);
-extern struct servent * irs_lclsv_fnxt(struct lcl_sv *);
-
-#endif
diff --git a/contrib/bind/lib/irs/lcl.c b/contrib/bind/lib/irs/lcl.c
deleted file mode 100644
index ed9e6b4..0000000
--- a/contrib/bind/lib/irs/lcl.c
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Copyright (c) 1996-1999 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.
- */
-
-#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: lcl.c,v 1.17 2001/05/29 05:49:02 marka Exp $";
-#endif
-
-/* Imports */
-
-#include "port_before.h"
-
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-
-#include <isc/memcluster.h>
-
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "lcl_p.h"
-
-/* Forward. */
-
-static void lcl_close(struct irs_acc *);
-static struct __res_state * lcl_res_get(struct irs_acc *);
-static void lcl_res_set(struct irs_acc *, struct __res_state *,
- void (*)(void *));
-
-/* Public */
-
-struct irs_acc *
-irs_lcl_acc(const char *options) {
- struct irs_acc *acc;
- struct lcl_p *lcl;
-
- UNUSED(options);
-
- if (!(acc = memget(sizeof *acc))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(acc, 0x5e, sizeof *acc);
- if (!(lcl = memget(sizeof *lcl))) {
- errno = ENOMEM;
- free(acc);
- return (NULL);
- }
- memset(lcl, 0x5e, sizeof *lcl);
- lcl->res = NULL;
- lcl->free_res = NULL;
- acc->private = lcl;
-#ifdef WANT_IRS_GR
- acc->gr_map = irs_lcl_gr;
-#else
- acc->gr_map = NULL;
-#endif
-#ifdef WANT_IRS_PW
- acc->pw_map = irs_lcl_pw;
-#else
- acc->pw_map = NULL;
-#endif
- acc->sv_map = irs_lcl_sv;
- acc->pr_map = irs_lcl_pr;
- acc->ho_map = irs_lcl_ho;
- acc->nw_map = irs_lcl_nw;
- acc->ng_map = irs_lcl_ng;
- acc->res_get = lcl_res_get;
- acc->res_set = lcl_res_set;
- acc->close = lcl_close;
- return (acc);
-}
-
-/* Methods */
-static struct __res_state *
-lcl_res_get(struct irs_acc *this) {
- struct lcl_p *lcl = (struct lcl_p *)this->private;
-
- if (lcl->res == NULL) {
- struct __res_state *res;
- res = (struct __res_state *)malloc(sizeof *res);
- if (res == NULL)
- return (NULL);
- memset(res, 0, sizeof *res);
- lcl_res_set(this, res, free);
- }
-
- if ((lcl->res->options & RES_INIT) == 0 &&
- res_ninit(lcl->res) < 0)
- return (NULL);
-
- return (lcl->res);
-}
-
-static void
-lcl_res_set(struct irs_acc *this, struct __res_state *res,
- void (*free_res)(void *)) {
- struct lcl_p *lcl = (struct lcl_p *)this->private;
-
- if (lcl->res && lcl->free_res) {
- res_nclose(lcl->res);
- (*lcl->free_res)(lcl->res);
- }
-
- lcl->res = res;
- lcl->free_res = free_res;
-}
-
-static void
-lcl_close(struct irs_acc *this) {
- struct lcl_p *lcl = (struct lcl_p *)this->private;
-
- if (lcl) {
- if (lcl->free_res)
- (*lcl->free_res)(lcl->res);
- memput(lcl, sizeof *lcl);
- }
- memput(this, sizeof *this);
-}
diff --git a/contrib/bind/lib/irs/lcl_gr.c b/contrib/bind/lib/irs/lcl_gr.c
deleted file mode 100644
index 7536c27..0000000
--- a/contrib/bind/lib/irs/lcl_gr.c
+++ /dev/null
@@ -1,354 +0,0 @@
-/*
- * Copyright (c) 1989, 1993, 1995
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Portions Copyright (c) 1996-1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: lcl_gr.c,v 1.26 2001/05/29 05:49:03 marka Exp $";
-/* from getgrent.c 8.2 (Berkeley) 3/21/94"; */
-/* from BSDI Id: getgrent.c,v 2.8 1996/05/28 18:15:14 bostic Exp $ */
-#endif /* LIBC_SCCS and not lint */
-
-/* extern */
-
-#include "port_before.h"
-
-#ifndef WANT_IRS_PW
-static int __bind_irs_gr_unneeded;
-#else
-
-#include <sys/param.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <grp.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <irs.h>
-#include <isc/memcluster.h>
-
-#include "irs_p.h"
-#include "lcl_p.h"
-#include "irp_p.h"
-
-#include "port_after.h"
-
-
-/* Types. */
-
-struct pvt {
- FILE * fp;
- /*
- * Need space to store the entries read from the group file.
- * The members list also needs space per member, and the
- * strings making up the user names must be allocated
- * somewhere. Rather than doing lots of small allocations,
- * we keep one buffer and resize it as needed.
- */
- struct group group;
- size_t nmemb; /* Malloc'd max index of gr_mem[]. */
- char * membuf;
- size_t membufsize;
-};
-
-/* Forward. */
-
-static void gr_close(struct irs_gr *);
-static struct group * gr_next(struct irs_gr *);
-static struct group * gr_byname(struct irs_gr *, const char *);
-static struct group * gr_bygid(struct irs_gr *, gid_t);
-static void gr_rewind(struct irs_gr *);
-static void gr_minimize(struct irs_gr *);
-
-static int grstart(struct pvt *);
-static char * grnext(struct pvt *);
-static struct group * grscan(struct irs_gr *, int, gid_t, const char *);
-
-/* Portability. */
-
-#ifndef SEEK_SET
-# define SEEK_SET 0
-#endif
-
-/* Public. */
-
-struct irs_gr *
-irs_lcl_gr(struct irs_acc *this) {
- struct irs_gr *gr;
- struct pvt *pvt;
-
- UNUSED(this);
-
- if (!(gr = memget(sizeof *gr))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(gr, 0x5e, sizeof *gr);
- if (!(pvt = memget(sizeof *pvt))) {
- memput(gr, sizeof *gr);
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- gr->private = pvt;
- gr->close = gr_close;
- gr->next = gr_next;
- gr->byname = gr_byname;
- gr->bygid = gr_bygid;
- gr->rewind = gr_rewind;
- gr->list = make_group_list;
- gr->minimize = gr_minimize;
- gr->res_get = NULL;
- gr->res_set = NULL;
- return (gr);
-}
-
-/* Methods. */
-
-static void
-gr_close(struct irs_gr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->fp)
- (void)fclose(pvt->fp);
- if (pvt->group.gr_mem)
- free(pvt->group.gr_mem);
- if (pvt->membuf)
- free(pvt->membuf);
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-static struct group *
-gr_next(struct irs_gr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (!pvt->fp && !grstart(pvt))
- return (NULL);
- return (grscan(this, 0, 0, NULL));
-}
-
-static struct group *
-gr_byname(struct irs_gr *this, const char *name) {
- if (!grstart((struct pvt *)this->private))
- return (NULL);
- return (grscan(this, 1, 0, name));
-}
-
-static struct group *
-gr_bygid(struct irs_gr *this, gid_t gid) {
- if (!grstart((struct pvt *)this->private))
- return (NULL);
- return (grscan(this, 1, gid, NULL));
-}
-
-static void
-gr_rewind(struct irs_gr *this) {
- (void) grstart((struct pvt *)this->private);
-}
-
-static void
-gr_minimize(struct irs_gr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->fp != NULL) {
- (void)fclose(pvt->fp);
- pvt->fp = NULL;
- }
-}
-
-/* Private. */
-
-static int
-grstart(struct pvt *pvt) {
- if (pvt->fp) {
- if (fseek(pvt->fp, 0L, SEEK_SET) == 0)
- return (1);
- (void)fclose(pvt->fp);
- }
- if (!(pvt->fp = fopen(_PATH_GROUP, "r")))
- return (0);
- if (fcntl(fileno(pvt->fp), F_SETFD, 1) < 0) {
- fclose(pvt->fp);
- return (0);
- }
- return (1);
-}
-
-#define INITIAL_NMEMB 30 /* about 120 bytes */
-#define INITIAL_BUFSIZ (INITIAL_NMEMB * 8) /* about 240 bytes */
-
-static char *
-grnext(struct pvt *pvt) {
- char *w, *e;
- int ch;
-
- /* Make sure we have a buffer. */
- if (pvt->membuf == NULL) {
- pvt->membuf = malloc(INITIAL_BUFSIZ);
- if (pvt->membuf == NULL) {
- enomem:
- errno = ENOMEM;
- return (NULL);
- }
- pvt->membufsize = INITIAL_BUFSIZ;
- }
-
- /* Read until EOF or EOL. */
- w = pvt->membuf;
- e = pvt->membuf + pvt->membufsize;
- while ((ch = fgetc(pvt->fp)) != EOF && ch != '\n') {
- /* Make sure we have room for this character and a \0. */
- if (w + 1 == e) {
- size_t o = w - pvt->membuf;
- size_t n = pvt->membufsize * 2;
- char *t = realloc(pvt->membuf, n);
-
- if (t == NULL)
- goto enomem;
- pvt->membuf = t;
- pvt->membufsize = n;
- w = pvt->membuf + o;
- e = pvt->membuf + pvt->membufsize;
- }
- /* Store it. */
- *w++ = (char)ch;
- }
-
- /* Hitting EOF on the first character really does mean EOF. */
- if (w == pvt->membuf && ch == EOF) {
- errno = ENOENT;
- return (NULL);
- }
-
- /* Last line of /etc/group need not end with \n; we don't care. */
- *w = '\0';
- return (pvt->membuf);
-}
-
-static struct group *
-grscan(struct irs_gr *this, int search, gid_t gid, const char *name) {
- struct pvt *pvt = (struct pvt *)this->private;
- size_t n;
- char *bp, **m, *p;
-
- /* Read lines until we find one that matches our search criteria. */
- for (;;) {
- if ((bp = grnext(pvt)) == NULL)
- return (NULL);
-
- /* Optimize the usual case of searching for a name. */
- pvt->group.gr_name = strsep(&bp, ":");
- if (search && name != NULL &&
- strcmp(pvt->group.gr_name, name) != 0)
- continue;
- if (bp == NULL || *bp == '\0')
- goto corrupt;
-
- /* Skip past the password field. */
- pvt->group.gr_passwd = strsep(&bp, ":");
- if (bp == NULL || *bp == '\0')
- goto corrupt;
-
- /* Checking for a gid. */
- if ((p = strsep(&bp, ":")) == NULL)
- continue;
- /*
- * Unlike the tests above, the test below is supposed to be
- * testing 'p' and not 'bp', in case you think it's a typo.
- */
- if (p == NULL || *p == '\0') {
- corrupt:
- /* warning: corrupted %s file!", _PATH_GROUP */
- continue;
- }
- pvt->group.gr_gid = atoi(p);
- if (search && name == NULL && (gid_t)pvt->group.gr_gid != gid)
- continue;
-
- /* We want this record. */
- break;
- }
-
- /*
- * Count commas to find out how many members there might be.
- * Note that commas separate, so if there is one comma there
- * can be two members (group:*:id:user1,user2). Add another
- * to account for the NULL terminator. As above, allocate
- * largest of INITIAL_NMEMB, or 2*n.
- */
- n = 1;
- if (bp != NULL)
- for (n = 2, p = bp; (p = strpbrk(p, ", ")) != NULL; ++n)
- p += strspn(p, ", ");
- if (n > pvt->nmemb || pvt->group.gr_mem == NULL) {
- if ((n *= 2) < INITIAL_NMEMB)
- n = INITIAL_NMEMB;
- if ((m = realloc(pvt->group.gr_mem, n * sizeof *m)) == NULL)
- return (NULL);
- pvt->group.gr_mem = m;
- pvt->nmemb = n;
- }
-
- /* Set the name pointers. */
- for (m = pvt->group.gr_mem; (p = strsep(&bp, ", ")) != NULL;)
- if (p[0] != '\0')
- *m++ = p;
- *m = NULL;
-
- return (&pvt->group);
-}
-
-#endif /* WANT_IRS_GR */
diff --git a/contrib/bind/lib/irs/lcl_ho.c b/contrib/bind/lib/irs/lcl_ho.c
deleted file mode 100644
index e9685a3..0000000
--- a/contrib/bind/lib/irs/lcl_ho.c
+++ /dev/null
@@ -1,576 +0,0 @@
-/*
- * Copyright (c) 1985, 1988, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Portions Copyright (c) 1996-1999 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.
- */
-
-/* from gethostnamadr.c 8.1 (Berkeley) 6/4/93 */
-/* BIND Id: gethnamaddr.c,v 8.15 1996/05/22 04:56:30 vixie Exp $ */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: lcl_ho.c,v 1.26 2001/05/29 05:49:04 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-/* Imports. */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <netdb.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <irs.h>
-#include <isc/memcluster.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "dns_p.h"
-#include "lcl_p.h"
-
-#ifdef SPRINTF_CHAR
-# define SPRINTF(x) strlen(sprintf/**/x)
-#else
-# define SPRINTF(x) sprintf x
-#endif
-
-/* Definitions. */
-
-#define MAXALIASES 35
-#define MAXADDRS 35
-#define Max(a,b) ((a) > (b) ? (a) : (b))
-
-#if PACKETSZ > 1024
-#define MAXPACKET PACKETSZ
-#else
-#define MAXPACKET 1024
-#endif
-
-struct pvt {
- FILE * fp;
- struct hostent host;
- char * h_addr_ptrs[MAXADDRS + 1];
- char * host_aliases[MAXALIASES];
- char hostbuf[8*1024];
- u_char host_addr[16]; /* IPv4 or IPv6 */
- struct __res_state *res;
- void (*free_res)(void *);
-};
-
-typedef union {
- int32_t al;
- char ac;
-} align;
-
-static const u_char mapped[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0xff,0xff };
-static const u_char tunnelled[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 };
-
-/* Forward. */
-
-static void ho_close(struct irs_ho *this);
-static struct hostent * ho_byname(struct irs_ho *this, const char *name);
-static struct hostent * ho_byname2(struct irs_ho *this, const char *name,
- int af);
-static struct hostent * ho_byaddr(struct irs_ho *this, const void *addr,
- int len, int af);
-static struct hostent * ho_next(struct irs_ho *this);
-static void ho_rewind(struct irs_ho *this);
-static void ho_minimize(struct irs_ho *this);
-static struct __res_state * ho_res_get(struct irs_ho *this);
-static void ho_res_set(struct irs_ho *this,
- struct __res_state *res,
- void (*free_res)(void *));
-static struct addrinfo * ho_addrinfo(struct irs_ho *this, const char *name,
- const struct addrinfo *pai);
-
-static size_t ns_namelen(const char *);
-static int init(struct irs_ho *this);
-
-/* Portability. */
-
-#ifndef SEEK_SET
-# define SEEK_SET 0
-#endif
-
-/* Public. */
-
-struct irs_ho *
-irs_lcl_ho(struct irs_acc *this) {
- struct irs_ho *ho;
- struct pvt *pvt;
-
- UNUSED(this);
-
- if (!(pvt = memget(sizeof *pvt))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- if (!(ho = memget(sizeof *ho))) {
- memput(pvt, sizeof *pvt);
- errno = ENOMEM;
- return (NULL);
- }
- memset(ho, 0x5e, sizeof *ho);
- ho->private = pvt;
- ho->close = ho_close;
- ho->byname = ho_byname;
- ho->byname2 = ho_byname2;
- ho->byaddr = ho_byaddr;
- ho->next = ho_next;
- ho->rewind = ho_rewind;
- ho->minimize = ho_minimize;
- ho->res_get = ho_res_get;
- ho->res_set = ho_res_set;
- ho->addrinfo = ho_addrinfo;
- return (ho);
-}
-
-/* Methods. */
-
-static void
-ho_close(struct irs_ho *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- ho_minimize(this);
- if (pvt->fp)
- (void) fclose(pvt->fp);
- if (pvt->res && pvt->free_res)
- (*pvt->free_res)(pvt->res);
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-static struct hostent *
-ho_byname(struct irs_ho *this, const char *name) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct hostent *hp;
-
- if (init(this) == -1)
- return (NULL);
-
- if (pvt->res->options & RES_USE_INET6) {
- hp = ho_byname2(this, name, AF_INET6);
- if (hp)
- return (hp);
- }
- return (ho_byname2(this, name, AF_INET));
-}
-
-static struct hostent *
-ho_byname2(struct irs_ho *this, const char *name, int af) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct hostent *hp;
- char **hap;
- size_t n;
-
- if (init(this) == -1)
- return (NULL);
-
- ho_rewind(this);
- n = ns_namelen(name);
- while ((hp = ho_next(this)) != NULL) {
- size_t nn;
-
- if (hp->h_addrtype != af)
- continue;
- nn = ns_namelen(hp->h_name);
- if (strncasecmp(hp->h_name, name, Max(n, nn)) == 0)
- goto found;
- for (hap = hp->h_aliases; *hap; hap++) {
- nn = ns_namelen(*hap);
- if (strncasecmp(*hap, name, Max(n, nn)) == 0)
- goto found;
- }
- }
- found:
- if (!hp) {
- RES_SET_H_ERRNO(pvt->res, HOST_NOT_FOUND);
- return (NULL);
- }
- RES_SET_H_ERRNO(pvt->res, NETDB_SUCCESS);
- return (hp);
-}
-
-static struct hostent *
-ho_byaddr(struct irs_ho *this, const void *addr, int len, int af) {
- struct pvt *pvt = (struct pvt *)this->private;
- const u_char *uaddr = addr;
- struct hostent *hp;
- int size;
-
- if (init(this) == -1)
- return (NULL);
-
- if (af == AF_INET6 && len == IN6ADDRSZ &&
- (!memcmp(uaddr, mapped, sizeof mapped) ||
- !memcmp(uaddr, tunnelled, sizeof tunnelled))) {
- /* Unmap. */
- addr = (const u_char *)addr + sizeof mapped;
- uaddr += sizeof mapped;
- af = AF_INET;
- len = INADDRSZ;
- }
- switch (af) {
- case AF_INET:
- size = INADDRSZ;
- break;
- case AF_INET6:
- size = IN6ADDRSZ;
- break;
- default:
- errno = EAFNOSUPPORT;
- RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
- return (NULL);
- }
- if (size > len) {
- errno = EINVAL;
- RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
- return (NULL);
- }
-
- /*
- * Do the search.
- */
- ho_rewind(this);
- while ((hp = ho_next(this)) != NULL) {
- char **hap;
-
- for (hap = hp->h_addr_list; *hap; hap++) {
- const u_char *taddr = (const u_char *)*hap;
- int taf = hp->h_addrtype;
- int tlen = hp->h_length;
-
- if (taf == AF_INET6 && tlen == IN6ADDRSZ &&
- (!memcmp(taddr, mapped, sizeof mapped) ||
- !memcmp(taddr, tunnelled, sizeof tunnelled))) {
- /* Unmap. */
- taddr += sizeof mapped;
- taf = AF_INET;
- tlen = INADDRSZ;
- }
- if (taf == af && tlen == len &&
- !memcmp(taddr, uaddr, tlen))
- goto found;
- }
- }
- found:
- if (!hp) {
- RES_SET_H_ERRNO(pvt->res, HOST_NOT_FOUND);
- return (NULL);
- }
- RES_SET_H_ERRNO(pvt->res, NETDB_SUCCESS);
- return (hp);
-}
-
-static struct hostent *
-ho_next(struct irs_ho *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- char *cp, **q, *p;
- char *bufp, *ndbuf, *dbuf = NULL;
- int c, af, len, bufsiz, offset;
-
- if (init(this) == -1)
- return (NULL);
-
- if (!pvt->fp)
- ho_rewind(this);
- if (!pvt->fp) {
- RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
- return (NULL);
- }
- bufp = pvt->hostbuf;
- bufsiz = sizeof pvt->hostbuf;
- offset = 0;
- again:
- if (!(p = fgets(bufp + offset, bufsiz - offset, pvt->fp))) {
- RES_SET_H_ERRNO(pvt->res, HOST_NOT_FOUND);
- if (dbuf)
- free(dbuf);
- return (NULL);
- }
- if (!strchr(p, '\n') && !feof(pvt->fp)) {
-#define GROWBUF 1024
- /* allocate space for longer line */
- if (dbuf == NULL) {
- if ((ndbuf = malloc(bufsiz + GROWBUF)) != NULL)
- strcpy(ndbuf, bufp);
- } else
- ndbuf = realloc(dbuf, bufsiz + GROWBUF);
- if (ndbuf) {
- dbuf = ndbuf;
- bufp = dbuf;
- bufsiz += GROWBUF;
- offset = strlen(dbuf);
- } else {
- /* allocation failed; skip this long line */
- while ((c = getc(pvt->fp)) != EOF)
- if (c == '\n')
- break;
- if (c != EOF)
- ungetc(c, pvt->fp);
- }
- goto again;
- }
-
- p -= offset;
- offset = 0;
-
- if (*p == '#')
- goto again;
- if ((cp = strpbrk(p, "#\n")) != NULL)
- *cp = '\0';
- if (!(cp = strpbrk(p, " \t")))
- goto again;
- *cp++ = '\0';
- if (inet_pton(AF_INET6, p, pvt->host_addr) > 0) {
- af = AF_INET6;
- len = IN6ADDRSZ;
- } else if (inet_aton(p, (struct in_addr *)pvt->host_addr) > 0) {
- if (pvt->res->options & RES_USE_INET6) {
- map_v4v6_address((char*)pvt->host_addr,
- (char*)pvt->host_addr);
- af = AF_INET6;
- len = IN6ADDRSZ;
- } else {
- af = AF_INET;
- len = INADDRSZ;
- }
- } else {
- goto again;
- }
- pvt->h_addr_ptrs[0] = (char *)pvt->host_addr;
- pvt->h_addr_ptrs[1] = NULL;
- pvt->host.h_addr_list = pvt->h_addr_ptrs;
- pvt->host.h_length = len;
- pvt->host.h_addrtype = af;
- while (*cp == ' ' || *cp == '\t')
- cp++;
- pvt->host.h_name = cp;
- q = pvt->host.h_aliases = pvt->host_aliases;
- if ((cp = strpbrk(cp, " \t")) != NULL)
- *cp++ = '\0';
- while (cp && *cp) {
- if (*cp == ' ' || *cp == '\t') {
- cp++;
- continue;
- }
- if (q < &pvt->host_aliases[MAXALIASES - 1])
- *q++ = cp;
- if ((cp = strpbrk(cp, " \t")) != NULL)
- *cp++ = '\0';
- }
- *q = NULL;
- if (dbuf)
- free(dbuf);
- RES_SET_H_ERRNO(pvt->res, NETDB_SUCCESS);
- return (&pvt->host);
-}
-
-static void
-ho_rewind(struct irs_ho *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->fp) {
- if (fseek(pvt->fp, 0L, SEEK_SET) == 0)
- return;
- (void)fclose(pvt->fp);
- }
- if (!(pvt->fp = fopen(_PATH_HOSTS, "r")))
- return;
- if (fcntl(fileno(pvt->fp), F_SETFD, 1) < 0) {
- (void)fclose(pvt->fp);
- pvt->fp = NULL;
- }
-}
-
-static void
-ho_minimize(struct irs_ho *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->fp != NULL) {
- (void)fclose(pvt->fp);
- pvt->fp = NULL;
- }
- if (pvt->res)
- res_nclose(pvt->res);
-}
-
-static struct __res_state *
-ho_res_get(struct irs_ho *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (!pvt->res) {
- struct __res_state *res;
- res = (struct __res_state *)malloc(sizeof *res);
- if (!res) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(res, 0, sizeof *res);
- ho_res_set(this, res, free);
- }
-
- return (pvt->res);
-}
-
-static void
-ho_res_set(struct irs_ho *this, struct __res_state *res,
- void (*free_res)(void *)) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->res && pvt->free_res) {
- res_nclose(pvt->res);
- (*pvt->free_res)(pvt->res);
- }
-
- pvt->res = res;
- pvt->free_res = free_res;
-}
-
-struct lcl_res_target {
- struct lcl_res_target *next;
- int family;
-};
-
-/* XXX */
-extern struct addrinfo *hostent2addrinfo __P((struct hostent *,
- const struct addrinfo *pai));
-
-static struct addrinfo *
-ho_addrinfo(struct irs_ho *this, const char *name, const struct addrinfo *pai)
-{
- struct pvt *pvt = (struct pvt *)this->private;
- struct hostent *hp;
- struct lcl_res_target q, q2, *p;
- struct addrinfo sentinel, *cur;
-
- memset(&q, 0, sizeof(q2));
- memset(&q2, 0, sizeof(q2));
- memset(&sentinel, 0, sizeof(sentinel));
- cur = &sentinel;
-
- switch(pai->ai_family) {
- case AF_UNSPEC: /* INET6 then INET4 */
- q.family = AF_INET6;
- q.next = &q2;
- q2.family = AF_INET;
- break;
- case AF_INET6:
- q.family = AF_INET6;
- break;
- case AF_INET:
- q.family = AF_INET;
- break;
- default:
- RES_SET_H_ERRNO(pvt->res, NO_RECOVERY); /* ??? */
- return(NULL);
- }
-
- for (p = &q; p; p = p->next) {
- struct addrinfo *ai;
-
- hp = (*this->byname2)(this, name, p->family);
- if (hp == NULL) {
- /* byname2 should've set an appropriate error */
- continue;
- }
- if ((hp->h_name == NULL) || (hp->h_name[0] == 0) ||
- (hp->h_addr_list[0] == NULL)) {
- RES_SET_H_ERRNO(pvt->res, NO_RECOVERY);
- continue;
- }
-
- ai = hostent2addrinfo(hp, pai);
- if (ai) {
- cur->ai_next = ai;
- while (cur && cur->ai_next)
- cur = cur->ai_next;
- }
- }
-
- if (sentinel.ai_next == NULL)
- RES_SET_H_ERRNO(pvt->res, HOST_NOT_FOUND);
-
- return(sentinel.ai_next);
-}
-
-/* Private. */
-
-static size_t
-ns_namelen(const char *s) {
- int i;
-
- for (i = strlen(s); i > 0 && s[i-1] == '.'; i--)
- (void)NULL;
- return ((size_t) i);
-}
-
-static int
-init(struct irs_ho *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (!pvt->res && !ho_res_get(this))
- return (-1);
- if (((pvt->res->options & RES_INIT) == 0) &&
- res_ninit(pvt->res) == -1)
- return (-1);
- return (0);
-}
diff --git a/contrib/bind/lib/irs/lcl_ng.c b/contrib/bind/lib/irs/lcl_ng.c
deleted file mode 100644
index 239b63e..0000000
--- a/contrib/bind/lib/irs/lcl_ng.c
+++ /dev/null
@@ -1,444 +0,0 @@
-/*
- * Copyright (c) 1996-1999 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.
- */
-
-#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: lcl_ng.c,v 1.17 2001/05/29 05:49:05 marka Exp $";
-#endif
-
-/* Imports */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <irs.h>
-#include <isc/memcluster.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "lcl_p.h"
-
-/* Definitions */
-
-#define NG_HOST 0 /* Host name */
-#define NG_USER 1 /* User name */
-#define NG_DOM 2 /* and Domain name */
-#define LINSIZ 1024 /* Length of netgroup file line */
-
-/*
- * XXX Warning XXX
- * This code is a hack-and-slash special. It realy needs to be
- * rewritten with things like strdup, and realloc in mind.
- * More reasonable data structures would not be a bad thing.
- */
-
-/*
- * Static Variables and functions used by setnetgrent(), getnetgrent() and
- * endnetgrent().
- * There are two linked lists:
- * - linelist is just used by setnetgrent() to parse the net group file via.
- * parse_netgrp()
- * - netgrp is the list of entries for the current netgroup
- */
-struct linelist {
- struct linelist *l_next; /* Chain ptr. */
- int l_parsed; /* Flag for cycles */
- char * l_groupname; /* Name of netgroup */
- char * l_line; /* Netgroup entrie(s) to be parsed */
-};
-
-struct ng_old_struct {
- struct ng_old_struct *ng_next; /* Chain ptr */
- char * ng_str[3]; /* Field pointers, see below */
-};
-
-struct pvt {
- FILE *fp;
- struct linelist *linehead;
- struct ng_old_struct *nextgrp;
- struct {
- struct ng_old_struct *gr;
- char *grname;
- } grouphead;
-};
-
-/* Forward */
-
-static void ng_rewind(struct irs_ng *, const char*);
-static void ng_close(struct irs_ng *);
-static int ng_next(struct irs_ng *, const char **,
- const char **, const char **);
-static int ng_test(struct irs_ng *, const char *,
- const char *, const char *,
- const char *);
-static void ng_minimize(struct irs_ng *);
-
-static int parse_netgrp(struct irs_ng *, const char*);
-static struct linelist *read_for_group(struct irs_ng *, const char *);
-static void freelists(struct irs_ng *);
-
-/* Public */
-
-struct irs_ng *
-irs_lcl_ng(struct irs_acc *this) {
- struct irs_ng *ng;
- struct pvt *pvt;
-
- UNUSED(this);
-
- if (!(ng = memget(sizeof *ng))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(ng, 0x5e, sizeof *ng);
- if (!(pvt = memget(sizeof *pvt))) {
- memput(ng, sizeof *ng);
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- ng->private = pvt;
- ng->close = ng_close;
- ng->next = ng_next;
- ng->test = ng_test;
- ng->rewind = ng_rewind;
- ng->minimize = ng_minimize;
- return (ng);
-}
-
-/* Methods */
-
-static void
-ng_close(struct irs_ng *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->fp != NULL)
- fclose(pvt->fp);
- freelists(this);
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-/*
- * Parse the netgroup file looking for the netgroup and build the list
- * of netgrp structures. Let parse_netgrp() and read_for_group() do
- * most of the work.
- */
-static void
-ng_rewind(struct irs_ng *this, const char *group) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->fp != NULL && fseek(pvt->fp, SEEK_CUR, 0L) == -1) {
- fclose(pvt->fp);
- pvt->fp = NULL;
- }
-
- if (pvt->fp == NULL || pvt->grouphead.gr == NULL ||
- strcmp(group, pvt->grouphead.grname)) {
- freelists(this);
- if (pvt->fp != NULL)
- fclose(pvt->fp);
- pvt->fp = fopen(_PATH_NETGROUP, "r");
- if (pvt->fp != NULL) {
- if (parse_netgrp(this, group))
- freelists(this);
- if (!(pvt->grouphead.grname = strdup(group)))
- freelists(this);
- fclose(pvt->fp);
- pvt->fp = NULL;
- }
- }
- pvt->nextgrp = pvt->grouphead.gr;
-}
-
-/*
- * Get the next netgroup off the list.
- */
-static int
-ng_next(struct irs_ng *this, const char **host, const char **user,
- const char **domain)
-{
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->nextgrp) {
- *host = pvt->nextgrp->ng_str[NG_HOST];
- *user = pvt->nextgrp->ng_str[NG_USER];
- *domain = pvt->nextgrp->ng_str[NG_DOM];
- pvt->nextgrp = pvt->nextgrp->ng_next;
- return (1);
- }
- return (0);
-}
-
-/*
- * Search for a match in a netgroup.
- */
-static int
-ng_test(struct irs_ng *this, const char *name,
- const char *host, const char *user, const char *domain)
-{
- const char *ng_host, *ng_user, *ng_domain;
-
- ng_rewind(this, name);
- while (ng_next(this, &ng_host, &ng_user, &ng_domain))
- if ((host == NULL || ng_host == NULL ||
- !strcmp(host, ng_host)) &&
- (user == NULL || ng_user == NULL ||
- !strcmp(user, ng_user)) &&
- (domain == NULL || ng_domain == NULL ||
- !strcmp(domain, ng_domain))) {
- freelists(this);
- return (1);
- }
- freelists(this);
- return (0);
-}
-
-static void
-ng_minimize(struct irs_ng *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->fp != NULL) {
- (void)fclose(pvt->fp);
- pvt->fp = NULL;
- }
-}
-
-/* Private */
-
-/*
- * endnetgrent() - cleanup
- */
-static void
-freelists(struct irs_ng *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct linelist *lp, *olp;
- struct ng_old_struct *gp, *ogp;
-
- lp = pvt->linehead;
- while (lp) {
- olp = lp;
- lp = lp->l_next;
- free(olp->l_groupname);
- free(olp->l_line);
- free((char *)olp);
- }
- pvt->linehead = NULL;
- if (pvt->grouphead.grname) {
- free(pvt->grouphead.grname);
- pvt->grouphead.grname = NULL;
- }
- gp = pvt->grouphead.gr;
- while (gp) {
- ogp = gp;
- gp = gp->ng_next;
- if (ogp->ng_str[NG_HOST])
- free(ogp->ng_str[NG_HOST]);
- if (ogp->ng_str[NG_USER])
- free(ogp->ng_str[NG_USER]);
- if (ogp->ng_str[NG_DOM])
- free(ogp->ng_str[NG_DOM]);
- free((char *)ogp);
- }
- pvt->grouphead.gr = NULL;
-}
-
-/*
- * Parse the netgroup file setting up the linked lists.
- */
-static int
-parse_netgrp(struct irs_ng *this, const char *group) {
- struct pvt *pvt = (struct pvt *)this->private;
- char *spos, *epos;
- int len, strpos;
- char *pos, *gpos;
- struct ng_old_struct *grp;
- struct linelist *lp = pvt->linehead;
-
- /*
- * First, see if the line has already been read in.
- */
- while (lp) {
- if (!strcmp(group, lp->l_groupname))
- break;
- lp = lp->l_next;
- }
- if (lp == NULL &&
- (lp = read_for_group(this, group)) == NULL)
- return (1);
- if (lp->l_parsed) {
- /*fprintf(stderr, "Cycle in netgroup %s\n", lp->l_groupname);*/
- return (1);
- } else
- lp->l_parsed = 1;
- pos = lp->l_line;
- while (*pos != '\0') {
- if (*pos == '(') {
- if (!(grp = malloc(sizeof (struct ng_old_struct)))) {
- freelists(this);
- errno = ENOMEM;
- return (1);
- }
- memset(grp, 0, sizeof (struct ng_old_struct));
- grp->ng_next = pvt->grouphead.gr;
- pvt->grouphead.gr = grp;
- pos++;
- gpos = strsep(&pos, ")");
- for (strpos = 0; strpos < 3; strpos++) {
- if ((spos = strsep(&gpos, ","))) {
- while (*spos == ' ' || *spos == '\t')
- spos++;
- if ((epos = strpbrk(spos, " \t"))) {
- *epos = '\0';
- len = epos - spos;
- } else
- len = strlen(spos);
- if (len > 0) {
- if(!(grp->ng_str[strpos]
- = (char *)
- malloc(len + 1))) {
- freelists(this);
- return (1);
- }
- memcpy(grp->ng_str[strpos],
- spos,
- len + 1);
- }
- } else
- goto errout;
- }
- } else {
- spos = strsep(&pos, ", \t");
- if (spos != NULL && parse_netgrp(this, spos)) {
- freelists(this);
- return (1);
- }
- }
- if (pos == NULL)
- break;
- while (*pos == ' ' || *pos == ',' || *pos == '\t')
- pos++;
- }
- return (0);
- errout:
- /*fprintf(stderr, "Bad netgroup %s at ..%s\n", lp->l_groupname,
- spos);*/
- return (1);
-}
-
-/*
- * Read the netgroup file and save lines until the line for the netgroup
- * is found. Return 1 if eof is encountered.
- */
-static struct linelist *
-read_for_group(struct irs_ng *this, const char *group) {
- struct pvt *pvt = (struct pvt *)this->private;
- char *pos, *spos, *linep = NULL, *olinep;
- int len, olen, cont;
- struct linelist *lp;
- char line[LINSIZ + 1];
-
- while (fgets(line, LINSIZ, pvt->fp) != NULL) {
- pos = line;
- if (*pos == '#')
- continue;
- while (*pos == ' ' || *pos == '\t')
- pos++;
- spos = pos;
- while (*pos != ' ' && *pos != '\t' && *pos != '\n' &&
- *pos != '\0')
- pos++;
- len = pos - spos;
- while (*pos == ' ' || *pos == '\t')
- pos++;
- if (*pos != '\n' && *pos != '\0') {
- if (!(lp = malloc(sizeof (*lp)))) {
- freelists(this);
- return (NULL);
- }
- lp->l_parsed = 0;
- if (!(lp->l_groupname = malloc(len + 1))) {
- free(lp);
- freelists(this);
- return (NULL);
- }
- memcpy(lp->l_groupname, spos, len);
- *(lp->l_groupname + len) = '\0';
- len = strlen(pos);
- olen = 0;
- olinep = NULL;
-
- /*
- * Loop around handling line continuations.
- */
- do {
- if (*(pos + len - 1) == '\n')
- len--;
- if (*(pos + len - 1) == '\\') {
- len--;
- cont = 1;
- } else
- cont = 0;
- if (len > 0) {
- if (!(linep = malloc(olen + len + 1))){
- if (olen > 0)
- free(olinep);
- free(lp->l_groupname);
- free(lp);
- freelists(this);
- errno = ENOMEM;
- return (NULL);
- }
- if (olen > 0) {
- memcpy(linep, olinep, olen);
- free(olinep);
- }
- memcpy(linep + olen, pos, len);
- olen += len;
- *(linep + olen) = '\0';
- olinep = linep;
- }
- if (cont) {
- if (fgets(line, LINSIZ, pvt->fp)) {
- pos = line;
- len = strlen(pos);
- } else
- cont = 0;
- }
- } while (cont);
- lp->l_line = linep;
- lp->l_next = pvt->linehead;
- pvt->linehead = lp;
-
- /*
- * If this is the one we wanted, we are done.
- */
- if (!strcmp(lp->l_groupname, group))
- return (lp);
- }
- }
- return (NULL);
-}
diff --git a/contrib/bind/lib/irs/lcl_nw.c b/contrib/bind/lib/irs/lcl_nw.c
deleted file mode 100644
index 457621b..0000000
--- a/contrib/bind/lib/irs/lcl_nw.c
+++ /dev/null
@@ -1,371 +0,0 @@
-/*
- * Copyright (c) 1989, 1993, 1995
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Portions Copyright (c) 1996-1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: lcl_nw.c,v 1.22 2001/05/29 05:49:07 marka Exp $";
-/* from getgrent.c 8.2 (Berkeley) 3/21/94"; */
-/* from BSDI Id: getgrent.c,v 2.8 1996/05/28 18:15:14 bostic Exp $ */
-#endif /* LIBC_SCCS and not lint */
-
-/* Imports */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <irs.h>
-#include <isc/memcluster.h>
-
-#include "port_after.h"
-
-#include <isc/misc.h>
-#include "irs_p.h"
-#include "lcl_p.h"
-
-#define MAXALIASES 35
-#define MAXADDRSIZE 4
-
-struct pvt {
- FILE * fp;
- char line[BUFSIZ+1];
- struct nwent net;
- char * aliases[MAXALIASES];
- char addr[MAXADDRSIZE];
- struct __res_state * res;
- void (*free_res)(void *);
-};
-
-/* Forward */
-
-static void nw_close(struct irs_nw *);
-static struct nwent * nw_byname(struct irs_nw *, const char *, int);
-static struct nwent * nw_byaddr(struct irs_nw *, void *, int, int);
-static struct nwent * nw_next(struct irs_nw *);
-static void nw_rewind(struct irs_nw *);
-static void nw_minimize(struct irs_nw *);
-static struct __res_state * nw_res_get(struct irs_nw *this);
-static void nw_res_set(struct irs_nw *this,
- struct __res_state *res,
- void (*free_res)(void *));
-
-static int init(struct irs_nw *this);
-
-/* Portability. */
-
-#ifndef SEEK_SET
-# define SEEK_SET 0
-#endif
-
-/* Public */
-
-struct irs_nw *
-irs_lcl_nw(struct irs_acc *this) {
- struct irs_nw *nw;
- struct pvt *pvt;
-
- UNUSED(this);
-
- if (!(pvt = memget(sizeof *pvt))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- if (!(nw = memget(sizeof *nw))) {
- memput(pvt, sizeof *pvt);
- errno = ENOMEM;
- return (NULL);
- }
- memset(nw, 0x5e, sizeof *nw);
- nw->private = pvt;
- nw->close = nw_close;
- nw->byname = nw_byname;
- nw->byaddr = nw_byaddr;
- nw->next = nw_next;
- nw->rewind = nw_rewind;
- nw->minimize = nw_minimize;
- nw->res_get = nw_res_get;
- nw->res_set = nw_res_set;
- return (nw);
-}
-
-/* Methods */
-
-static void
-nw_close(struct irs_nw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- nw_minimize(this);
- if (pvt->res && pvt->free_res)
- (*pvt->free_res)(pvt->res);
- if (pvt->fp)
- (void)fclose(pvt->fp);
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-static struct nwent *
-nw_byaddr(struct irs_nw *this, void *net, int length, int type) {
- struct nwent *p;
-
- if (init(this) == -1)
- return(NULL);
-
- nw_rewind(this);
- while ((p = nw_next(this)) != NULL)
- if (p->n_addrtype == type && p->n_length == length)
- if (bitncmp(p->n_addr, net, length) == 0)
- break;
- return (p);
-}
-
-static struct nwent *
-nw_byname(struct irs_nw *this, const char *name, int type) {
- struct nwent *p;
- char **ap;
-
- if (init(this) == -1)
- return(NULL);
-
- nw_rewind(this);
- while ((p = nw_next(this)) != NULL) {
- if (ns_samename(p->n_name, name) == 1 &&
- p->n_addrtype == type)
- break;
- for (ap = p->n_aliases; *ap; ap++)
- if ((ns_samename(*ap, name) == 1) &&
- (p->n_addrtype == type))
- goto found;
- }
- found:
- return (p);
-}
-
-static void
-nw_rewind(struct irs_nw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->fp) {
- if (fseek(pvt->fp, 0L, SEEK_SET) == 0)
- return;
- (void)fclose(pvt->fp);
- }
- if (!(pvt->fp = fopen(_PATH_NETWORKS, "r")))
- return;
- if (fcntl(fileno(pvt->fp), F_SETFD, 1) < 0) {
- (void)fclose(pvt->fp);
- pvt->fp = NULL;
- }
-}
-
-static struct nwent *
-nw_next(struct irs_nw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct nwent *ret = NULL;
- char *p, *cp, **q;
- char *bufp, *ndbuf, *dbuf = NULL;
- int c, bufsiz, offset = 0;
-
- if (init(this) == -1)
- return(NULL);
-
- if (pvt->fp == NULL)
- nw_rewind(this);
- if (pvt->fp == NULL) {
- RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
- return (NULL);
- }
- bufp = pvt->line;
- bufsiz = sizeof(pvt->line);
-
- again:
- p = fgets(bufp + offset, bufsiz - offset, pvt->fp);
- if (p == NULL)
- goto cleanup;
- if (!strchr(p, '\n') && !feof(pvt->fp)) {
-#define GROWBUF 1024
- /* allocate space for longer line */
- if (dbuf == NULL) {
- if ((ndbuf = malloc(bufsiz + GROWBUF)) != NULL)
- strcpy(ndbuf, bufp);
- } else
- ndbuf = realloc(dbuf, bufsiz + GROWBUF);
- if (ndbuf) {
- dbuf = ndbuf;
- bufp = dbuf;
- bufsiz += GROWBUF;
- offset = strlen(dbuf);
- } else {
- /* allocation failed; skip this long line */
- while ((c = getc(pvt->fp)) != EOF)
- if (c == '\n')
- break;
- if (c != EOF)
- ungetc(c, pvt->fp);
- }
- goto again;
- }
-
- p -= offset;
- offset = 0;
-
- if (*p == '#')
- goto again;
-
- cp = strpbrk(p, "#\n");
- if (cp != NULL)
- *cp = '\0';
- pvt->net.n_name = p;
- cp = strpbrk(p, " \t");
- if (cp == NULL)
- goto again;
- *cp++ = '\0';
- while (*cp == ' ' || *cp == '\t')
- cp++;
- p = strpbrk(cp, " \t");
- if (p != NULL)
- *p++ = '\0';
- pvt->net.n_length = inet_net_pton(AF_INET, cp, pvt->addr,
- sizeof pvt->addr);
- if (pvt->net.n_length < 0)
- goto again;
- pvt->net.n_addrtype = AF_INET;
- pvt->net.n_addr = pvt->addr;
- q = pvt->net.n_aliases = pvt->aliases;
- if (p != NULL) {
- cp = p;
- while (cp && *cp) {
- if (*cp == ' ' || *cp == '\t') {
- cp++;
- continue;
- }
- if (q < &pvt->aliases[MAXALIASES - 1])
- *q++ = cp;
- cp = strpbrk(cp, " \t");
- if (cp != NULL)
- *cp++ = '\0';
- }
- }
- *q = NULL;
- ret = &pvt->net;
-
- cleanup:
- if (dbuf)
- free(dbuf);
-
- return (ret);
-}
-
-static void
-nw_minimize(struct irs_nw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->res)
- res_nclose(pvt->res);
- if (pvt->fp != NULL) {
- (void)fclose(pvt->fp);
- pvt->fp = NULL;
- }
-}
-
-static struct __res_state *
-nw_res_get(struct irs_nw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (!pvt->res) {
- struct __res_state *res;
- res = (struct __res_state *)malloc(sizeof *res);
- if (!res) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(res, 0, sizeof *res);
- nw_res_set(this, res, free);
- }
-
- return (pvt->res);
-}
-
-static void
-nw_res_set(struct irs_nw *this, struct __res_state *res,
- void (*free_res)(void *)) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->res && pvt->free_res) {
- res_nclose(pvt->res);
- (*pvt->free_res)(pvt->res);
- }
-
- pvt->res = res;
- pvt->free_res = free_res;
-}
-
-static int
-init(struct irs_nw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (!pvt->res && !nw_res_get(this))
- return (-1);
- if (((pvt->res->options & RES_INIT) == 0) &&
- res_ninit(pvt->res) == -1)
- return (-1);
- return (0);
-}
diff --git a/contrib/bind/lib/irs/lcl_p.h b/contrib/bind/lib/irs/lcl_p.h
deleted file mode 100644
index b9e3b3e..0000000
--- a/contrib/bind/lib/irs/lcl_p.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-/*
- * $Id: lcl_p.h,v 1.7 1999/01/08 19:24:51 vixie Exp $
- */
-
-/*
- * lcl_p.h - private include file for the local accessor functions.
- */
-
-#ifndef _LCL_P_H_INCLUDED
-#define _LCL_P_H_INCLUDED
-
-/*
- * Object state.
- */
-struct lcl_p {
- struct __res_state * res;
- void (*free_res) __P((void *));
-};
-
-/*
- * Externs.
- */
-
-extern struct irs_acc * irs_lcl_acc __P((const char *));
-extern struct irs_gr * irs_lcl_gr __P((struct irs_acc *));
-extern struct irs_pw * irs_lcl_pw __P((struct irs_acc *));
-extern struct irs_sv * irs_lcl_sv __P((struct irs_acc *));
-extern struct irs_pr * irs_lcl_pr __P((struct irs_acc *));
-extern struct irs_ho * irs_lcl_ho __P((struct irs_acc *));
-extern struct irs_nw * irs_lcl_nw __P((struct irs_acc *));
-extern struct irs_ng * irs_lcl_ng __P((struct irs_acc *));
-
-#endif /*_LCL_P_H_INCLUDED*/
diff --git a/contrib/bind/lib/irs/lcl_pr.c b/contrib/bind/lib/irs/lcl_pr.c
deleted file mode 100644
index 5162115..0000000
--- a/contrib/bind/lib/irs/lcl_pr.c
+++ /dev/null
@@ -1,284 +0,0 @@
-/*
- * Copyright (c) 1989, 1993, 1995
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Portions Copyright (c) 1996,1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: lcl_pr.c,v 1.18 1999/10/13 17:11:20 vixie Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-/* extern */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <irs.h>
-#include <isc/memcluster.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "lcl_p.h"
-
-#ifndef _PATH_PROTOCOLS
-#define _PATH_PROTOCOLS "/etc/protocols"
-#endif
-#define MAXALIASES 35
-
-/* Types */
-
-struct pvt {
- FILE * fp;
- char line[BUFSIZ+1];
- struct protoent proto;
- char * proto_aliases[MAXALIASES];
-};
-
-/* Forward */
-
-static void pr_close(struct irs_pr *);
-static struct protoent * pr_next(struct irs_pr *);
-static struct protoent * pr_byname(struct irs_pr *, const char *);
-static struct protoent * pr_bynumber(struct irs_pr *, int);
-static void pr_rewind(struct irs_pr *);
-static void pr_minimize(struct irs_pr *);
-
-/* Portability. */
-
-#ifndef SEEK_SET
-# define SEEK_SET 0
-#endif
-
-/* Public */
-
-struct irs_pr *
-irs_lcl_pr(struct irs_acc *this) {
- struct irs_pr *pr;
- struct pvt *pvt;
-
- if (!(pr = memget(sizeof *pr))) {
- errno = ENOMEM;
- return (NULL);
- }
- if (!(pvt = memget(sizeof *pvt))) {
- memput(pr, sizeof *this);
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- pr->private = pvt;
- pr->close = pr_close;
- pr->byname = pr_byname;
- pr->bynumber = pr_bynumber;
- pr->next = pr_next;
- pr->rewind = pr_rewind;
- pr->minimize = pr_minimize;
- pr->res_get = NULL;
- pr->res_set = NULL;
- return (pr);
-}
-
-/* Methods */
-
-static void
-pr_close(struct irs_pr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->fp)
- (void) fclose(pvt->fp);
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-static struct protoent *
-pr_byname(struct irs_pr *this, const char *name) {
-
- struct protoent *p;
- char **cp;
-
- pr_rewind(this);
- while ((p = pr_next(this))) {
- if (!strcmp(p->p_name, name))
- goto found;
- for (cp = p->p_aliases; *cp; cp++)
- if (!strcmp(*cp, name))
- goto found;
- }
- found:
- return (p);
-}
-
-static struct protoent *
-pr_bynumber(struct irs_pr *this, int proto) {
- struct protoent *p;
-
- pr_rewind(this);
- while ((p = pr_next(this)))
- if (p->p_proto == proto)
- break;
- return (p);
-}
-
-static void
-pr_rewind(struct irs_pr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->fp) {
- if (fseek(pvt->fp, 0L, SEEK_SET) == 0)
- return;
- (void)fclose(pvt->fp);
- }
- if (!(pvt->fp = fopen(_PATH_PROTOCOLS, "r" )))
- return;
- if (fcntl(fileno(pvt->fp), F_SETFD, 1) < 0) {
- (void)fclose(pvt->fp);
- pvt->fp = NULL;
- }
-}
-
-static struct protoent *
-pr_next(struct irs_pr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- char *p, *cp, **q;
- char *bufp, *ndbuf, *dbuf = NULL;
- int c, bufsiz, offset;
-
- if (!pvt->fp)
- pr_rewind(this);
- if (!pvt->fp)
- return (NULL);
- bufp = pvt->line;
- bufsiz = BUFSIZ;
- offset = 0;
- again:
- if ((p = fgets(bufp + offset, bufsiz - offset, pvt->fp)) == NULL) {
- if (dbuf)
- free(dbuf);
- return (NULL);
- }
- if (!strchr(p, '\n') && !feof(pvt->fp)) {
-#define GROWBUF 1024
- /* allocate space for longer line */
- if (dbuf == NULL) {
- if ((ndbuf = malloc(bufsiz + GROWBUF)) != NULL)
- strcpy(ndbuf, bufp);
- } else
- ndbuf = realloc(dbuf, bufsiz + GROWBUF);
- if (ndbuf) {
- dbuf = ndbuf;
- bufp = dbuf;
- bufsiz += GROWBUF;
- offset = strlen(dbuf);
- } else {
- /* allocation failed; skip this long line */
- while ((c = getc(pvt->fp)) != EOF)
- if (c == '\n')
- break;
- if (c != EOF)
- ungetc(c, pvt->fp);
- }
- goto again;
- }
-
- p -= offset;
- offset = 0;
-
- if (*p == '#')
- goto again;
- cp = strpbrk(p, "#\n");
- if (cp != NULL)
- *cp = '\0';
- pvt->proto.p_name = p;
- cp = strpbrk(p, " \t");
- if (cp == NULL)
- goto again;
- *cp++ = '\0';
- while (*cp == ' ' || *cp == '\t')
- cp++;
- p = strpbrk(cp, " \t");
- if (p != NULL)
- *p++ = '\0';
- pvt->proto.p_proto = atoi(cp);
- q = pvt->proto.p_aliases = pvt->proto_aliases;
- if (p != NULL) {
- cp = p;
- while (cp && *cp) {
- if (*cp == ' ' || *cp == '\t') {
- cp++;
- continue;
- }
- if (q < &pvt->proto_aliases[MAXALIASES - 1])
- *q++ = cp;
- cp = strpbrk(cp, " \t");
- if (cp != NULL)
- *cp++ = '\0';
- }
- }
- *q = NULL;
- return (&pvt->proto);
-}
-
-static void
-pr_minimize(struct irs_pr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->fp != NULL) {
- (void)fclose(pvt->fp);
- pvt->fp = NULL;
- }
-}
diff --git a/contrib/bind/lib/irs/lcl_pw.c b/contrib/bind/lib/irs/lcl_pw.c
deleted file mode 100644
index 31c1ed0..0000000
--- a/contrib/bind/lib/irs/lcl_pw.c
+++ /dev/null
@@ -1,308 +0,0 @@
-/*
- * Copyright (c) 1989, 1993, 1995
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Portions Copyright (c) 1996,1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: lcl_pw.c,v 1.20 2001/05/29 05:49:08 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-/* Extern */
-
-#include "port_before.h"
-
-#ifndef WANT_IRS_PW
-static int __bind_irs_pw_unneeded;
-#else
-
-#include <sys/param.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-
-#include <db.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <pwd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <syslog.h>
-#include <utmp.h>
-#include <unistd.h>
-
-#include <isc/memcluster.h>
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "lcl_p.h"
-
-/*
- * The lookup techniques and data extraction code here must be kept
- * in sync with that in `pwd_mkdb'.
- */
-
-
-/* Types */
-
-struct pvt {
- struct passwd passwd; /* password structure */
- DB *pw_db; /* password database */
- int pw_keynum; /* key counter */
- int warned;
- u_int max;
- char * line;
-};
-
-/* Forward */
-
-static void pw_close(struct irs_pw *);
-static struct passwd * pw_next(struct irs_pw *);
-static struct passwd * pw_byname(struct irs_pw *, const char *);
-static struct passwd * pw_byuid(struct irs_pw *, uid_t);
-static void pw_rewind(struct irs_pw *);
-static void pw_minimize(struct irs_pw *);
-
-static int initdb(struct pvt *);
-static int hashpw(struct irs_pw *, DBT *);
-
-/* Public */
-struct irs_pw *
-irs_lcl_pw(struct irs_acc *this) {
- struct irs_pw *pw;
- struct pvt *pvt;
-
- UNUSED(this);
-
- if (!(pw = memget(sizeof *pw))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(pw, 0x5e, sizeof *pw);
- if (!(pvt = memget(sizeof *pvt))) {
- free(pw);
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- pw->private = pvt;
- pw->close = pw_close;
- pw->next = pw_next;
- pw->byname = pw_byname;
- pw->byuid = pw_byuid;
- pw->rewind = pw_rewind;
- pw->minimize = pw_minimize;
- pw->res_get = NULL;
- pw->res_set = NULL;
- return (pw);
-}
-
-/* Methods */
-
-static void
-pw_close(struct irs_pw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->pw_db) {
- (void)(pvt->pw_db->close)(pvt->pw_db);
- pvt->pw_db = NULL;
- }
- if (pvt->line)
- memput(pvt->line, pvt->max);
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-static struct passwd *
-pw_next(struct irs_pw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- DBT key;
- char bf[sizeof(pvt->pw_keynum) + 1];
-
- if (!initdb(pvt))
- return (NULL);
-
- ++pvt->pw_keynum;
- bf[0] = _PW_KEYBYNUM;
- memcpy(bf + 1, (char *)&pvt->pw_keynum, sizeof(pvt->pw_keynum));
- key.data = (u_char *)bf;
- key.size = sizeof(pvt->pw_keynum) + 1;
- return (hashpw(this, &key) ? &pvt->passwd : NULL);
-}
-
-static struct passwd *
-pw_byname(struct irs_pw *this, const char *name) {
- struct pvt *pvt = (struct pvt *)this->private;
- DBT key;
- int len, rval;
- char bf[UT_NAMESIZE + 1];
-
- if (!initdb(pvt))
- return (NULL);
-
- bf[0] = _PW_KEYBYNAME;
- len = strlen(name);
- memcpy(bf + 1, name, MIN(len, UT_NAMESIZE));
- key.data = (u_char *)bf;
- key.size = len + 1;
- rval = hashpw(this, &key);
-
- return (rval ? &pvt->passwd : NULL);
-}
-
-
-static struct passwd *
-pw_byuid(struct irs_pw *this, uid_t uid) {
- struct pvt *pvt = (struct pvt *)this->private;
- DBT key;
- int keyuid, rval;
- char bf[sizeof(keyuid) + 1];
-
- if (!initdb(pvt))
- return (NULL);
-
- bf[0] = _PW_KEYBYUID;
- keyuid = uid;
- memcpy(bf + 1, &keyuid, sizeof(keyuid));
- key.data = (u_char *)bf;
- key.size = sizeof(keyuid) + 1;
- rval = hashpw(this, &key);
-
- return (rval ? &pvt->passwd : NULL);
-}
-
-static void
-pw_rewind(struct irs_pw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- pvt->pw_keynum = 0;
-}
-
-static void
-pw_minimize(struct irs_pw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->pw_db != NULL) {
- (void) (*pvt->pw_db->close)(pvt->pw_db);
- pvt->pw_db = NULL;
- }
-}
-
-/* Private. */
-
-static int
-initdb(struct pvt *pvt) {
- const char *p;
-
- if (pvt->pw_db) {
- if (lseek((*pvt->pw_db->fd)(pvt->pw_db), 0L, SEEK_CUR) >= 0L)
- return (1);
- else
- (void) (*pvt->pw_db->close)(pvt->pw_db);
- }
- pvt->pw_db = dbopen((p = _PATH_SMP_DB), O_RDONLY, 0, DB_HASH, NULL);
- if (!pvt->pw_db)
- pvt->pw_db = dbopen((p =_PATH_MP_DB), O_RDONLY,
- 0, DB_HASH, NULL);
- if (pvt->pw_db)
- return (1);
- if (!pvt->warned) {
- syslog(LOG_ERR, "%s: %m", p);
- pvt->warned++;
- }
- return (0);
-}
-
-static int
-hashpw(struct irs_pw *this, DBT *key) {
- struct pvt *pvt = (struct pvt *)this->private;
- char *p, *t, *l;
- DBT data;
-
- if ((pvt->pw_db->get)(pvt->pw_db, key, &data, 0))
- return (0);
- p = (char *)data.data;
- if (data.size > pvt->max) {
- size_t newlen = pvt->max + 1024;
- char *p = memget(newlen);
- if (p == NULL) {
- return (0);
- }
- if (pvt->line != NULL) {
- memcpy(p, pvt->line, pvt->max);
- memput(pvt->line, pvt->max);
- }
- pvt->max = newlen;
- pvt->line = p;
- }
-
- /* THIS CODE MUST MATCH THAT IN pwd_mkdb. */
- t = pvt->line;
- l = pvt->line + pvt->max;
-#define EXPAND(e) if ((e = t) == NULL) return (0); else \
- do if (t >= l) return (0); while ((*t++ = *p++) != '\0')
-#define SCALAR(v) if (t + sizeof v >= l) return (0); else \
- (memmove(&(v), p, sizeof v), p += sizeof v)
- EXPAND(pvt->passwd.pw_name);
- EXPAND(pvt->passwd.pw_passwd);
- SCALAR(pvt->passwd.pw_uid);
- SCALAR(pvt->passwd.pw_gid);
- SCALAR(pvt->passwd.pw_change);
- EXPAND(pvt->passwd.pw_class);
- EXPAND(pvt->passwd.pw_gecos);
- EXPAND(pvt->passwd.pw_dir);
- EXPAND(pvt->passwd.pw_shell);
- SCALAR(pvt->passwd.pw_expire);
- return (1);
-}
-
-#endif /* WANT_IRS_PW */
diff --git a/contrib/bind/lib/irs/lcl_sv.c b/contrib/bind/lib/irs/lcl_sv.c
deleted file mode 100644
index d94366b..0000000
--- a/contrib/bind/lib/irs/lcl_sv.c
+++ /dev/null
@@ -1,431 +0,0 @@
-/*
- * Copyright (c) 1989, 1993, 1995
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Portions Copyright (c) 1996-1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: lcl_sv.c,v 1.22 2001/06/18 14:43:59 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-/* extern */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-
-#ifdef IRS_LCL_SV_DB
-#include <db.h>
-#endif
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include <irs.h>
-#include <isc/memcluster.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "lcl_p.h"
-
-#ifdef SPRINTF_CHAR
-# define SPRINTF(x) strlen(sprintf/**/x)
-#else
-# define SPRINTF(x) ((size_t)sprintf x)
-#endif
-
-/* Types */
-
-struct pvt {
-#ifdef IRS_LCL_SV_DB
- DB * dbh;
- int dbf;
-#endif
- struct lcl_sv sv;
-};
-
-/* Forward */
-
-static void sv_close(struct irs_sv*);
-static struct servent * sv_next(struct irs_sv *);
-static struct servent * sv_byname(struct irs_sv *, const char *,
- const char *);
-static struct servent * sv_byport(struct irs_sv *, int, const char *);
-static void sv_rewind(struct irs_sv *);
-static void sv_minimize(struct irs_sv *);
-/*global*/ struct servent * irs_lclsv_fnxt(struct lcl_sv *);
-#ifdef IRS_LCL_SV_DB
-static struct servent * sv_db_rec(struct lcl_sv *, DBT *, DBT *);
-#endif
-
-/* Portability */
-
-#ifndef SEEK_SET
-# define SEEK_SET 0
-#endif
-
-/* Public */
-
-struct irs_sv *
-irs_lcl_sv(struct irs_acc *this) {
- struct irs_sv *sv;
- struct pvt *pvt;
-
- UNUSED(this);
-
- if ((sv = memget(sizeof *sv)) == NULL) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(sv, 0x5e, sizeof *sv);
- if ((pvt = memget(sizeof *pvt)) == NULL) {
- memput(sv, sizeof *sv);
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- sv->private = pvt;
- sv->close = sv_close;
- sv->next = sv_next;
- sv->byname = sv_byname;
- sv->byport = sv_byport;
- sv->rewind = sv_rewind;
- sv->minimize = sv_minimize;
- sv->res_get = NULL;
- sv->res_set = NULL;
-#ifdef IRS_LCL_SV_DB
- pvt->dbf = R_FIRST;
-#endif
- return (sv);
-}
-
-/* Methods */
-
-static void
-sv_close(struct irs_sv *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
-#ifdef IRS_LCL_SV_DB
- if (pvt->dbh != NULL)
- (*pvt->dbh->close)(pvt->dbh);
-#endif
- if (pvt->sv.fp)
- fclose(pvt->sv.fp);
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-static struct servent *
-sv_byname(struct irs_sv *this, const char *name, const char *proto) {
-#ifdef IRS_LCL_SV_DB
- struct pvt *pvt = (struct pvt *)this->private;
-#endif
- struct servent *p;
- char **cp;
-
- sv_rewind(this);
-#ifdef IRS_LCL_SV_DB
- if (pvt->dbh != NULL) {
- DBT key, data;
-
- /* Note that (sizeof "/") == 2. */
- if ((strlen(name) + sizeof "/" + proto ? strlen(proto) : 0)
- > sizeof pvt->sv.line)
- goto try_local;
- key.data = pvt->sv.line;
- key.size = SPRINTF((pvt->sv.line, "%s/%s", name,
- proto ? proto : "")) + 1;
- if (proto != NULL) {
- if ((*pvt->dbh->get)(pvt->dbh, &key, &data, 0) != 0)
- return (NULL);
- } else if ((*pvt->dbh->seq)(pvt->dbh, &key, &data, R_CURSOR)
- != 0)
- return (NULL);
- return (sv_db_rec(&pvt->sv, &key, &data));
- }
- try_local:
-#endif
-
- while ((p = sv_next(this))) {
- if (strcmp(name, p->s_name) == 0)
- goto gotname;
- for (cp = p->s_aliases; *cp; cp++)
- if (strcmp(name, *cp) == 0)
- goto gotname;
- continue;
- gotname:
- if (proto == NULL || strcmp(p->s_proto, proto) == 0)
- break;
- }
- return (p);
-}
-
-static struct servent *
-sv_byport(struct irs_sv *this, int port, const char *proto) {
-#ifdef IRS_LCL_SV_DB
- struct pvt *pvt = (struct pvt *)this->private;
-#endif
- struct servent *p;
-
- sv_rewind(this);
-#ifdef IRS_LCL_SV_DB
- if (pvt->dbh != NULL) {
- DBT key, data;
- u_short *ports;
-
- ports = (u_short *)pvt->sv.line;
- ports[0] = 0;
- ports[1] = port;
- key.data = ports;
- key.size = sizeof(u_short) * 2;
- if (proto && *proto) {
- strncpy((char *)ports + key.size, proto,
- BUFSIZ - key.size);
- key.size += strlen((char *)ports + key.size) + 1;
- if ((*pvt->dbh->get)(pvt->dbh, &key, &data, 0) != 0)
- return (NULL);
- } else {
- if ((*pvt->dbh->seq)(pvt->dbh, &key, &data, R_CURSOR)
- != 0)
- return (NULL);
- }
- return (sv_db_rec(&pvt->sv, &key, &data));
- }
-#endif
- while ((p = sv_next(this))) {
- if (p->s_port != port)
- continue;
- if (proto == NULL || strcmp(p->s_proto, proto) == 0)
- break;
- }
- return (p);
-}
-
-static void
-sv_rewind(struct irs_sv *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->sv.fp) {
- if (fseek(pvt->sv.fp, 0L, SEEK_SET) == 0)
- return;
- (void)fclose(pvt->sv.fp);
- pvt->sv.fp = NULL;
- }
-#ifdef IRS_LCL_SV_DB
- pvt->dbf = R_FIRST;
- if (pvt->dbh != NULL)
- return;
- pvt->dbh = dbopen(_PATH_SERVICES_DB, O_RDONLY,O_RDONLY,DB_BTREE, NULL);
- if (pvt->dbh != NULL) {
- if (fcntl((*pvt->dbh->fd)(pvt->dbh), F_SETFD, 1) < 0) {
- (*pvt->dbh->close)(pvt->dbh);
- pvt->dbh = NULL;
- }
- return;
- }
-#endif
- if ((pvt->sv.fp = fopen(_PATH_SERVICES, "r")) == NULL)
- return;
- if (fcntl(fileno(pvt->sv.fp), F_SETFD, 1) < 0) {
- (void)fclose(pvt->sv.fp);
- pvt->sv.fp = NULL;
- }
-}
-
-static struct servent *
-sv_next(struct irs_sv *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
-#ifdef IRS_LCL_SV_DB
- if (pvt->dbh == NULL && pvt->sv.fp == NULL)
-#else
- if (pvt->sv.fp == NULL)
-#endif
- sv_rewind(this);
-
-#ifdef IRS_LCL_SV_DB
- if (pvt->dbh != NULL) {
- DBT key, data;
-
- while ((*pvt->dbh->seq)(pvt->dbh, &key, &data, pvt->dbf) == 0){
- pvt->dbf = R_NEXT;
- if (((char *)key.data)[0])
- continue;
- return (sv_db_rec(&pvt->sv, &key, &data));
- }
- }
-#endif
-
- if (pvt->sv.fp == NULL)
- return (NULL);
- return (irs_lclsv_fnxt(&pvt->sv));
-}
-
-static void
-sv_minimize(struct irs_sv *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
-#ifdef IRS_LCL_SV_DB
- if (pvt->dbh != NULL) {
- (*pvt->dbh->close)(pvt->dbh);
- pvt->dbh = NULL;
- }
-#endif
- if (pvt->sv.fp != NULL) {
- (void)fclose(pvt->sv.fp);
- pvt->sv.fp = NULL;
- }
-}
-
-/* Quasipublic. */
-
-struct servent *
-irs_lclsv_fnxt(struct lcl_sv *sv) {
- char *p, *cp, **q;
-
- again:
- if ((p = fgets(sv->line, BUFSIZ, sv->fp)) == NULL)
- return (NULL);
- if (*p == '#')
- goto again;
- sv->serv.s_name = p;
- while (*p && *p != '\n' && *p != ' ' && *p != '\t' && *p != '#')
- ++p;
- if (*p == '\0' || *p == '#' || *p == '\n')
- goto again;
- *p++ = '\0';
- while (*p == ' ' || *p == '\t')
- p++;
- if (*p == '\0' || *p == '#' || *p == '\n')
- goto again;
- sv->serv.s_port = htons((u_short)strtol(p, &cp, 10));
- if (cp == p || (*cp != '/' && *cp != ','))
- goto again;
- p = cp + 1;
- sv->serv.s_proto = p;
-
- q = sv->serv.s_aliases = sv->serv_aliases;
-
- while (*p && *p != '\n' && *p != ' ' && *p != '\t' && *p != '#')
- ++p;
-
- while (*p == ' ' || *p == '\t') {
- *p++ = '\0';
- while (*p == ' ' || *p == '\t')
- ++p;
- if (*p == '\0' || *p == '#' || *p == '\n')
- break;
- if (q < &sv->serv_aliases[IRS_SV_MAXALIASES - 1])
- *q++ = p;
- while (*p && *p != '\n' && *p != ' ' && *p != '\t' && *p != '#')
- ++p;
- }
-
- *p = '\0';
- *q = NULL;
- return (&sv->serv);
-}
-
-/* Private. */
-
-#ifdef IRS_LCL_SV_DB
-static struct servent *
-sv_db_rec(struct lcl_sv *sv, DBT *key, DBT *data) {
- char *p, **q;
- int n;
-
- p = data->data;
- p[data->size - 1] = '\0'; /* should be, but we depend on it */
-
- if (((char *)key->data)[0] == '\0') {
- if (key->size < sizeof(u_short)*2 || data->size < 2)
- return (NULL);
- sv->serv.s_port = ((u_short *)key->data)[1];
- n = strlen(p) + 1;
- if ((size_t)n > sizeof(sv->line)) {
- n = sizeof(sv->line);
- }
- memcpy(sv->line, p, n);
- sv->serv.s_name = sv->line;
- if ((sv->serv.s_proto = strchr(sv->line, '/')) != NULL)
- *(sv->serv.s_proto)++ = '\0';
- p += n;
- data->size -= n;
- } else {
- if (data->size < sizeof(u_short) + 1)
- return (NULL);
- if (key->size > sizeof(sv->line))
- key->size = sizeof(sv->line);
- ((char *)key->data)[key->size - 1] = '\0';
- memcpy(sv->line, key->data, key->size);
- sv->serv.s_name = sv->line;
- if ((sv->serv.s_proto = strchr(sv->line, '/')) != NULL)
- *(sv->serv.s_proto)++ = '\0';
- sv->serv.s_port = *(u_short *)data->data;
- p += sizeof(u_short);
- data->size -= sizeof(u_short);
- }
- q = sv->serv.s_aliases = sv->serv_aliases;
- while (data->size > 0 && q < &sv->serv_aliases[IRS_SV_MAXALIASES - 1]) {
-
- *q++ = p;
- n = strlen(p) + 1;
- data->size -= n;
- p += n;
- }
- *q = NULL;
- return (&sv->serv);
-}
-#endif
diff --git a/contrib/bind/lib/irs/nis.c b/contrib/bind/lib/irs/nis.c
deleted file mode 100644
index aa10fba..0000000
--- a/contrib/bind/lib/irs/nis.c
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * Copyright (c) 1996-1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: nis.c,v 1.15 2001/05/29 05:49:11 marka Exp $";
-#endif
-
-/* Imports */
-
-#include "port_before.h"
-
-#ifdef WANT_IRS_NIS
-
-#include <rpc/rpc.h>
-#include <rpc/xdr.h>
-#include <rpcsvc/yp_prot.h>
-#include <rpcsvc/ypclnt.h>
-
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-
-#include <isc/memcluster.h>
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "hesiod.h"
-#include "nis_p.h"
-
-/* Forward */
-
-static void nis_close(struct irs_acc *);
-static struct __res_state * nis_res_get(struct irs_acc *);
-static void nis_res_set(struct irs_acc *, struct __res_state *,
- void (*)(void *));
-
-/* Public */
-
-struct irs_acc *
-irs_nis_acc(const char *options) {
- struct nis_p *nis;
- struct irs_acc *acc;
- char *domain;
-
- UNUSED(options);
-
- if (yp_get_default_domain(&domain) != 0)
- return (NULL);
- if (!(nis = memget(sizeof *nis))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(nis, 0, sizeof *nis);
- if (!(acc = memget(sizeof *acc))) {
- memput(nis, sizeof *nis);
- errno = ENOMEM;
- return (NULL);
- }
- memset(acc, 0x5e, sizeof *acc);
- acc->private = nis;
- nis->domain = strdup(domain);
-#ifdef WANT_IRS_GR
- acc->gr_map = irs_nis_gr;
-#else
- acc->gr_map = NULL;
-#endif
-#ifdef WANT_IRS_PW
- acc->pw_map = irs_nis_pw;
-#else
- acc->pw_map = NULL;
-#endif
- acc->sv_map = irs_nis_sv;
- acc->pr_map = irs_nis_pr;
- acc->ho_map = irs_nis_ho;
- acc->nw_map = irs_nis_nw;
- acc->ng_map = irs_nis_ng;
- acc->res_get = nis_res_get;
- acc->res_set = nis_res_set;
- acc->close = nis_close;
- return (acc);
-}
-
-/* Methods */
-
-static struct __res_state *
-nis_res_get(struct irs_acc *this) {
- struct nis_p *nis = (struct nis_p *)this->private;
-
- if (nis->res == NULL) {
- struct __res_state *res;
- res = (struct __res_state *)malloc(sizeof *res);
- if (res == NULL)
- return (NULL);
- memset(res, 0, sizeof *res);
- nis_res_set(this, res, free);
- }
-
- if ((nis->res->options & RES_INIT) == 0 &&
- res_ninit(nis->res) < 0)
- return (NULL);
-
- return (nis->res);
-}
-
-static void
-nis_res_set(struct irs_acc *this, struct __res_state *res,
- void (*free_res)(void *)) {
- struct nis_p *nis = (struct nis_p *)this->private;
-
- if (nis->res && nis->free_res) {
- res_nclose(nis->res);
- (*nis->free_res)(nis->res);
- }
-
- nis->res = res;
- nis->free_res = free_res;
-}
-
-static void
-nis_close(struct irs_acc *this) {
- struct nis_p *nis = (struct nis_p *)this->private;
-
- if (nis->res && nis->free_res)
- (*nis->free_res)(nis->res);
- free(nis->domain);
- memput(nis, sizeof *nis);
- memput(this, sizeof *this);
-}
-
-#endif /*WANT_IRS_NIS*/
diff --git a/contrib/bind/lib/irs/nis_gr.c b/contrib/bind/lib/irs/nis_gr.c
deleted file mode 100644
index 0ea50f5..0000000
--- a/contrib/bind/lib/irs/nis_gr.c
+++ /dev/null
@@ -1,353 +0,0 @@
-/*
- * Copyright (c) 1989, 1993, 1995
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Portions Copyright (c) 1996-1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: nis_gr.c,v 1.22 2002/07/08 06:26:11 marka Exp $";
-/* from getgrent.c 8.2 (Berkeley) 3/21/94"; */
-/* from BSDI Id: getgrent.c,v 2.8 1996/05/28 18:15:14 bostic Exp $ */
-#endif /* LIBC_SCCS and not lint */
-
-/* Imports */
-
-#include "port_before.h"
-
-#if !defined(WANT_IRS_GR) || !defined(WANT_IRS_NIS)
-static int __bind_irs_gr_unneeded;
-#else
-
-#include <sys/param.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-#include <isc/memcluster.h>
-
-#include <rpc/rpc.h>
-#include <rpc/xdr.h>
-#include <rpcsvc/yp_prot.h>
-#include <rpcsvc/ypclnt.h>
-
-#include <errno.h>
-#include <grp.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <isc/memcluster.h>
-
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "nis_p.h"
-
-/* Definitions */
-
-struct pvt {
- int needrewind;
- char * nis_domain;
- char * curkey_data;
- int curkey_len;
- char * curval_data;
- int curval_len;
- /*
- * Need space to store the entries read from the group file.
- * The members list also needs space per member, and the
- * strings making up the user names must be allocated
- * somewhere. Rather than doing lots of small allocations,
- * we keep one buffer and resize it as needed.
- */
- struct group group;
- size_t nmemb; /* Malloc'd max index of gr_mem[]. */
- char * membuf;
- size_t membufsize;
-};
-
-enum do_what { do_none = 0x0, do_key = 0x1, do_val = 0x2, do_all = 0x3 };
-
-static /*const*/ char group_bygid[] = "group.bygid";
-static /*const*/ char group_byname[] = "group.byname";
-
-/* Forward */
-
-static void gr_close(struct irs_gr *);
-static struct group * gr_next(struct irs_gr *);
-static struct group * gr_byname(struct irs_gr *, const char *);
-static struct group * gr_bygid(struct irs_gr *, gid_t);
-static void gr_rewind(struct irs_gr *);
-static void gr_minimize(struct irs_gr *);
-
-static struct group * makegroupent(struct irs_gr *);
-static void nisfree(struct pvt *, enum do_what);
-
-/* Public */
-
-struct irs_gr *
-irs_nis_gr(struct irs_acc *this) {
- struct irs_gr *gr;
- struct pvt *pvt;
-
- if (!(gr = memget(sizeof *gr))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(gr, 0x5e, sizeof *gr);
- if (!(pvt = memget(sizeof *pvt))) {
- memput(gr, sizeof *gr);
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- pvt->needrewind = 1;
- pvt->nis_domain = ((struct nis_p *)this->private)->domain;
- gr->private = pvt;
- gr->close = gr_close;
- gr->next = gr_next;
- gr->byname = gr_byname;
- gr->bygid = gr_bygid;
- gr->rewind = gr_rewind;
- gr->list = make_group_list;
- gr->minimize = gr_minimize;
- gr->res_get = NULL;
- gr->res_set = NULL;
- return (gr);
-}
-
-/* Methods */
-
-static void
-gr_close(struct irs_gr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->group.gr_mem)
- free(pvt->group.gr_mem);
- if (pvt->membuf)
- free(pvt->membuf);
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-static struct group *
-gr_next(struct irs_gr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct group *rval;
- int r;
-
- do {
- if (pvt->needrewind) {
- nisfree(pvt, do_all);
- r = yp_first(pvt->nis_domain, group_byname,
- &pvt->curkey_data, &pvt->curkey_len,
- &pvt->curval_data, &pvt->curval_len);
- pvt->needrewind = 0;
- } else {
- char *newkey_data;
- int newkey_len;
-
- nisfree(pvt, do_val);
- r = yp_next(pvt->nis_domain, group_byname,
- pvt->curkey_data, pvt->curkey_len,
- &newkey_data, &newkey_len,
- &pvt->curval_data, &pvt->curval_len);
- nisfree(pvt, do_key);
- pvt->curkey_data = newkey_data;
- pvt->curkey_len = newkey_len;
- }
- if (r != 0) {
- errno = ENOENT;
- return (NULL);
- }
- rval = makegroupent(this);
- } while (rval == NULL);
- return (rval);
-}
-
-static struct group *
-gr_byname(struct irs_gr *this, const char *name) {
- struct pvt *pvt = (struct pvt *)this->private;
- int r;
-
- nisfree(pvt, do_val);
- r = yp_match(pvt->nis_domain, group_byname, name, strlen(name),
- &pvt->curval_data, &pvt->curval_len);
- if (r != 0) {
- errno = ENOENT;
- return (NULL);
- }
- return (makegroupent(this));
-}
-
-static struct group *
-gr_bygid(struct irs_gr *this, gid_t gid) {
- struct pvt *pvt = (struct pvt *)this->private;
- char tmp[sizeof "4294967295"];
- int r;
-
- nisfree(pvt, do_val);
- (void) sprintf(tmp, "%u", (unsigned int)gid);
- r = yp_match(pvt->nis_domain, group_bygid, tmp, strlen(tmp),
- &pvt->curval_data, &pvt->curval_len);
- if (r != 0) {
- errno = ENOENT;
- return (NULL);
- }
- return (makegroupent(this));
-}
-
-static void
-gr_rewind(struct irs_gr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- pvt->needrewind = 1;
-}
-
-static void
-gr_minimize(struct irs_gr *this) {
- UNUSED(this);
- /* NOOP */
-}
-
-/* Private */
-
-static struct group *
-makegroupent(struct irs_gr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- unsigned int num_members = 0;
- char *cp, **new;
- u_long t;
-
- if (pvt->group.gr_mem) {
- free(pvt->group.gr_mem);
- pvt->group.gr_mem = NULL;
- pvt->nmemb = 0;
- }
- if (pvt->membuf)
- free(pvt->membuf);
- pvt->membuf = pvt->curval_data;
- pvt->curval_data = NULL;
-
- cp = pvt->membuf;
- pvt->group.gr_name = cp;
- if (!(cp = strchr(cp, ':')))
- goto cleanup;
- *cp++ = '\0';
-
- pvt->group.gr_passwd = cp;
- if (!(cp = strchr(cp, ':')))
- goto cleanup;
- *cp++ = '\0';
-
- errno = 0;
- t = strtoul(cp, NULL, 10);
- if (errno == ERANGE)
- goto cleanup;
- pvt->group.gr_gid = (gid_t) t;
- if (!(cp = strchr(cp, ':')))
- goto cleanup;
- cp++;
-
- if (*cp && cp[strlen(cp)-1] == '\n')
- cp[strlen(cp)-1] = '\0';
-
- /*
- * Parse the members out.
- */
- while (*cp) {
- if (num_members+1 >= pvt->nmemb || pvt->group.gr_mem == NULL) {
- pvt->nmemb += 10;
- new = realloc(pvt->group.gr_mem,
- pvt->nmemb * sizeof(char *));
- if (new == NULL)
- goto cleanup;
- pvt->group.gr_mem = new;
- }
- pvt->group.gr_mem[num_members++] = cp;
- if (!(cp = strchr(cp, ',')))
- break;
- *cp++ = '\0';
- }
- if (pvt->group.gr_mem == NULL) {
- pvt->group.gr_mem = malloc(sizeof(char*));
- if (!pvt->group.gr_mem)
- goto cleanup;
- pvt->nmemb = 1;
- }
- pvt->group.gr_mem[num_members] = NULL;
-
- return (&pvt->group);
-
- cleanup:
- if (pvt->group.gr_mem) {
- free(pvt->group.gr_mem);
- pvt->group.gr_mem = NULL;
- pvt->nmemb = 0;
- }
- if (pvt->membuf) {
- free(pvt->membuf);
- pvt->membuf = NULL;
- }
- return (NULL);
-}
-
-static void
-nisfree(struct pvt *pvt, enum do_what do_what) {
- if ((do_what & do_key) && pvt->curkey_data) {
- free(pvt->curkey_data);
- pvt->curkey_data = NULL;
- }
- if ((do_what & do_val) && pvt->curval_data) {
- free(pvt->curval_data);
- pvt->curval_data = NULL;
- }
-}
-
-#endif /* WANT_IRS_GR && WANT_IRS_NIS */
diff --git a/contrib/bind/lib/irs/nis_ho.c b/contrib/bind/lib/irs/nis_ho.c
deleted file mode 100644
index 7158f4c..0000000
--- a/contrib/bind/lib/irs/nis_ho.c
+++ /dev/null
@@ -1,530 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: nis_ho.c,v 1.18.10.1 2003/06/02 05:50:57 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-/* Imports */
-
-#include "port_before.h"
-
-#ifndef WANT_IRS_NIS
-static int __bind_irs_nis_unneeded;
-#else
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-#include <rpc/rpc.h>
-#include <rpc/xdr.h>
-#include <rpcsvc/yp_prot.h>
-#include <rpcsvc/ypclnt.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <netdb.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <isc/memcluster.h>
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "nis_p.h"
-
-/* Definitions */
-
-#define MAXALIASES 35
-#define MAXADDRS 35
-
-#if PACKETSZ > 1024
-#define MAXPACKET PACKETSZ
-#else
-#define MAXPACKET 1024
-#endif
-
-struct pvt {
- int needrewind;
- char * nis_domain;
- char * curkey_data;
- int curkey_len;
- char * curval_data;
- int curval_len;
- struct hostent host;
- char * h_addr_ptrs[MAXADDRS + 1];
- char * host_aliases[MAXALIASES + 1];
- char hostbuf[8*1024];
- u_char host_addr[16]; /* IPv4 or IPv6 */
- struct __res_state *res;
- void (*free_res)(void *);
-};
-
-enum do_what { do_none = 0x0, do_key = 0x1, do_val = 0x2, do_all = 0x3 };
-
-static const u_char mapped[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0xff,0xff };
-static const u_char tunnelled[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 };
-static /*const*/ char hosts_byname[] = "hosts.byname";
-static /*const*/ char hosts_byaddr[] = "hosts.byaddr";
-static /*const*/ char ipnode_byname[] = "ipnode.byname";
-static /*const*/ char ipnode_byaddr[] = "ipnode.byaddr";
-static /*const*/ char yp_multi[] = "YP_MULTI_";
-
-/* Forwards */
-
-static void ho_close(struct irs_ho *this);
-static struct hostent * ho_byname(struct irs_ho *this, const char *name);
-static struct hostent * ho_byname2(struct irs_ho *this, const char *name,
- int af);
-static struct hostent * ho_byaddr(struct irs_ho *this, const void *addr,
- int len, int af);
-static struct hostent * ho_next(struct irs_ho *this);
-static void ho_rewind(struct irs_ho *this);
-static void ho_minimize(struct irs_ho *this);
-static struct __res_state * ho_res_get(struct irs_ho *this);
-static void ho_res_set(struct irs_ho *this,
- struct __res_state *res,
- void (*free_res)(void *));
-static struct addrinfo * ho_addrinfo(struct irs_ho *this, const char *name,
- const struct addrinfo *pai);
-
-static struct hostent * makehostent(struct irs_ho *this);
-static void nisfree(struct pvt *, enum do_what);
-static int init(struct irs_ho *this);
-
-/* Public */
-
-struct irs_ho *
-irs_nis_ho(struct irs_acc *this) {
- struct irs_ho *ho;
- struct pvt *pvt;
-
- if (!(pvt = memget(sizeof *pvt))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- if (!(ho = memget(sizeof *ho))) {
- memput(pvt, sizeof *pvt);
- errno = ENOMEM;
- return (NULL);
- }
- memset(ho, 0x5e, sizeof *ho);
- pvt->needrewind = 1;
- pvt->nis_domain = ((struct nis_p *)this->private)->domain;
- ho->private = pvt;
- ho->close = ho_close;
- ho->byname = ho_byname;
- ho->byname2 = ho_byname2;
- ho->byaddr = ho_byaddr;
- ho->next = ho_next;
- ho->rewind = ho_rewind;
- ho->minimize = ho_minimize;
- ho->res_set = ho_res_set;
- ho->res_get = ho_res_get;
- ho->addrinfo = ho_addrinfo;
- return (ho);
-}
-
-/* Methods */
-
-static void
-ho_close(struct irs_ho *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- ho_minimize(this);
- nisfree(pvt, do_all);
- if (pvt->res && pvt->free_res)
- (*pvt->free_res)(pvt->res);
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-static struct hostent *
-ho_byname(struct irs_ho *this, const char *name) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct hostent *hp;
-
- if (init(this) == -1)
- return (NULL);
-
- if (pvt->res->options & RES_USE_INET6) {
- hp = ho_byname2(this, name, AF_INET6);
- if (hp)
- return (hp);
- }
- return (ho_byname2(this, name, AF_INET));
-}
-
-static struct hostent *
-ho_byname2(struct irs_ho *this, const char *name, int af) {
- struct pvt *pvt = (struct pvt *)this->private;
- int r;
- char *tmp;
-
- UNUSED(af);
-
- if (init(this) == -1)
- return (NULL);
-
- nisfree(pvt, do_val);
-
- strcpy(pvt->hostbuf, yp_multi);
- strncat(pvt->hostbuf, name, sizeof(pvt->hostbuf) - sizeof(yp_multi));
- pvt->hostbuf[sizeof(pvt->hostbuf) - 1] = '\0';
- for (r = sizeof(yp_multi) - 1; pvt->hostbuf[r] != '\0'; r++)
- if (isupper((unsigned char)pvt->hostbuf[r]))
- tolower(pvt->hostbuf[r]);
-
- tmp = pvt->hostbuf;
- r = yp_match(pvt->nis_domain, ipnode_byname, tmp,
- strlen(tmp), &pvt->curval_data, &pvt->curval_len);
- if (r != 0) {
- tmp = pvt->hostbuf + sizeof(yp_multi) - 1;
- r = yp_match(pvt->nis_domain, ipnode_byname, tmp,
- strlen(tmp), &pvt->curval_data, &pvt->curval_len);
- }
- if (r != 0) {
- tmp = pvt->hostbuf;
- r = yp_match(pvt->nis_domain, hosts_byname, tmp,
- strlen(tmp), &pvt->curval_data, &pvt->curval_len);
- }
- if (r != 0) {
- tmp = pvt->hostbuf + sizeof(yp_multi) - 1;
- r = yp_match(pvt->nis_domain, hosts_byname, tmp,
- strlen(tmp), &pvt->curval_data, &pvt->curval_len);
- }
- if (r != 0) {
- RES_SET_H_ERRNO(pvt->res, HOST_NOT_FOUND);
- return (NULL);
- }
- return (makehostent(this));
-}
-
-static struct hostent *
-ho_byaddr(struct irs_ho *this, const void *addr, int len, int af) {
- struct pvt *pvt = (struct pvt *)this->private;
- char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"];
- const u_char *uaddr = addr;
- int r;
-
- if (init(this) == -1)
- return (NULL);
-
- if (af == AF_INET6 && len == IN6ADDRSZ &&
- (!memcmp(uaddr, mapped, sizeof mapped) ||
- !memcmp(uaddr, tunnelled, sizeof tunnelled))) {
- /* Unmap. */
- addr = (const u_char *)addr + sizeof mapped;
- uaddr += sizeof mapped;
- af = AF_INET;
- len = INADDRSZ;
- }
- if (inet_ntop(af, uaddr, tmp, sizeof tmp) == NULL) {
- RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
- return (NULL);
- }
- nisfree(pvt, do_val);
- r = yp_match(pvt->nis_domain, ipnode_byaddr, tmp, strlen(tmp),
- &pvt->curval_data, &pvt->curval_len);
- if (r != 0)
- r = yp_match(pvt->nis_domain, hosts_byaddr, tmp, strlen(tmp),
- &pvt->curval_data, &pvt->curval_len);
- if (r != 0) {
- RES_SET_H_ERRNO(pvt->res, HOST_NOT_FOUND);
- return (NULL);
- }
- return (makehostent(this));
-}
-
-static struct hostent *
-ho_next(struct irs_ho *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct hostent *rval;
- int r;
-
- if (init(this) == -1)
- return (NULL);
-
- do {
- if (pvt->needrewind) {
- nisfree(pvt, do_all);
- r = yp_first(pvt->nis_domain, hosts_byaddr,
- &pvt->curkey_data, &pvt->curkey_len,
- &pvt->curval_data, &pvt->curval_len);
- pvt->needrewind = 0;
- } else {
- char *newkey_data;
- int newkey_len;
-
- nisfree(pvt, do_val);
- r = yp_next(pvt->nis_domain, hosts_byaddr,
- pvt->curkey_data, pvt->curkey_len,
- &newkey_data, &newkey_len,
- &pvt->curval_data, &pvt->curval_len);
- nisfree(pvt, do_key);
- pvt->curkey_data = newkey_data;
- pvt->curkey_len = newkey_len;
- }
- if (r != 0) {
- RES_SET_H_ERRNO(pvt->res, HOST_NOT_FOUND);
- return (NULL);
- }
- rval = makehostent(this);
- } while (rval == NULL);
- return (rval);
-}
-
-static void
-ho_rewind(struct irs_ho *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- pvt->needrewind = 1;
-}
-
-static void
-ho_minimize(struct irs_ho *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->res)
- res_nclose(pvt->res);
-}
-
-static struct __res_state *
-ho_res_get(struct irs_ho *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (!pvt->res) {
- struct __res_state *res;
- res = (struct __res_state *)malloc(sizeof *res);
- if (!res) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(res, 0, sizeof *res);
- ho_res_set(this, res, free);
- }
-
- return (pvt->res);
-}
-
-static void
-ho_res_set(struct irs_ho *this, struct __res_state *res,
- void (*free_res)(void *)) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->res && pvt->free_res) {
- res_nclose(pvt->res);
- (*pvt->free_res)(pvt->res);
- }
-
- pvt->res = res;
- pvt->free_res = free_res;
-}
-
-struct nis_res_target {
- struct nis_res_target *next;
- int family;
-};
-
-/* XXX */
-extern struct addrinfo *hostent2addrinfo __P((struct hostent *,
- const struct addrinfo *pai));
-
-static struct addrinfo *
-ho_addrinfo(struct irs_ho *this, const char *name, const struct addrinfo *pai)
-{
- struct pvt *pvt = (struct pvt *)this->private;
- struct hostent *hp;
- struct nis_res_target q, q2, *p;
- struct addrinfo sentinel, *cur;
-
- memset(&q, 0, sizeof(q2));
- memset(&q2, 0, sizeof(q2));
- memset(&sentinel, 0, sizeof(sentinel));
- cur = &sentinel;
-
- switch(pai->ai_family) {
- case AF_UNSPEC: /* INET6 then INET4 */
- q.family = AF_INET6;
- q.next = &q2;
- q2.family = AF_INET;
- break;
- case AF_INET6:
- q.family = AF_INET6;
- break;
- case AF_INET:
- q.family = AF_INET;
- break;
- default:
- RES_SET_H_ERRNO(pvt->res, NO_RECOVERY); /* ??? */
- return(NULL);
- }
-
- for (p = &q; p; p = p->next) {
- struct addrinfo *ai;
-
- hp = (*this->byname2)(this, name, p->family);
- if (hp == NULL) {
- /* byname2 should've set an appropriate error */
- continue;
- }
- if ((hp->h_name == NULL) || (hp->h_name[0] == 0) ||
- (hp->h_addr_list[0] == NULL)) {
- RES_SET_H_ERRNO(pvt->res, NO_RECOVERY);
- continue;
- }
- ai = hostent2addrinfo(hp, pai);
- if (ai) {
- cur->ai_next = ai;
- while (cur && cur->ai_next)
- cur = cur->ai_next;
- }
- }
-
- if (sentinel.ai_next == NULL)
- RES_SET_H_ERRNO(pvt->res, HOST_NOT_FOUND);
-
- return(sentinel.ai_next);
-}
-
-/* Private */
-
-/*
-ipnodes:
-::1 localhost
-127.0.0.1 localhost
-1.2.3.4 FOO bar
-1.2.6.4 FOO bar
-1.2.6.5 host
-
-ipnodes.byname:
-YP_MULTI_localhost ::1,127.0.0.1 localhost
-YP_MULTI_foo 1.2.3.4,1.2.6.4 FOO bar
-YP_MULTI_bar 1.2.3.4,1.2.6.4 FOO bar
-host 1.2.6.5 host
-
-hosts.byname:
-localhost 127.0.0.1 localhost
-host 1.2.6.5 host
-YP_MULTI_foo 1.2.3.4,1.2.6.4 FOO bar
-YP_MULTI_bar 1.2.3.4,1.2.6.4 FOO bar
-*/
-
-static struct hostent *
-makehostent(struct irs_ho *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- static const char spaces[] = " \t";
- char *cp, **q, *p, *comma, *ap;
- int af = 0, len = 0;
- int multi = 0;
- int addr = 0;
-
- p = pvt->curval_data;
- if ((cp = strpbrk(p, "#\n")) != NULL)
- *cp = '\0';
- if (!(cp = strpbrk(p, spaces)))
- return (NULL);
- *cp++ = '\0';
- ap = pvt->hostbuf;
- do {
- if ((comma = strchr(p, ',')) != NULL) {
- *comma++ = '\0';
- multi = 1;
- }
- if ((ap + IN6ADDRSZ) > (pvt->hostbuf + sizeof(pvt->hostbuf)))
- break;
- if ((pvt->res->options & RES_USE_INET6) &&
- inet_pton(AF_INET6, p, ap) > 0) {
- af = AF_INET6;
- len = IN6ADDRSZ;
- } else if (inet_pton(AF_INET, p, pvt->host_addr) > 0) {
- if (pvt->res->options & RES_USE_INET6) {
- map_v4v6_address((char*)pvt->host_addr, ap);
- af = AF_INET6;
- len = IN6ADDRSZ;
- } else {
- af = AF_INET;
- len = INADDRSZ;
- }
- } else {
- if (!multi)
- return (NULL);
- continue;
- }
- if (addr < MAXADDRS) {
- pvt->h_addr_ptrs[addr++] = ap;
- pvt->h_addr_ptrs[addr] = NULL;
- ap += len;
- }
- } while ((p = comma) != NULL);
- if (ap == pvt->hostbuf)
- return (NULL);
- pvt->host.h_addr_list = pvt->h_addr_ptrs;
- pvt->host.h_length = len;
- pvt->host.h_addrtype = af;
- cp += strspn(cp, spaces);
- pvt->host.h_name = cp;
- q = pvt->host.h_aliases = pvt->host_aliases;
- if ((cp = strpbrk(cp, spaces)) != NULL)
- *cp++ = '\0';
- while (cp && *cp) {
- if (*cp == ' ' || *cp == '\t') {
- cp++;
- continue;
- }
- if (q < &pvt->host_aliases[MAXALIASES])
- *q++ = cp;
- if ((cp = strpbrk(cp, spaces)) != NULL)
- *cp++ = '\0';
- }
- *q = NULL;
- RES_SET_H_ERRNO(pvt->res, NETDB_SUCCESS);
- return (&pvt->host);
-}
-
-static void
-nisfree(struct pvt *pvt, enum do_what do_what) {
- if ((do_what & do_key) && pvt->curkey_data) {
- free(pvt->curkey_data);
- pvt->curkey_data = NULL;
- }
- if ((do_what & do_val) && pvt->curval_data) {
- free(pvt->curval_data);
- pvt->curval_data = NULL;
- }
-}
-
-static int
-init(struct irs_ho *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (!pvt->res && !ho_res_get(this))
- return (-1);
- if (((pvt->res->options & RES_INIT) == 0) &&
- res_ninit(pvt->res) == -1)
- return (-1);
- return (0);
-}
-#endif /*WANT_IRS_NIS*/
diff --git a/contrib/bind/lib/irs/nis_ng.c b/contrib/bind/lib/irs/nis_ng.c
deleted file mode 100644
index a42d994..0000000
--- a/contrib/bind/lib/irs/nis_ng.c
+++ /dev/null
@@ -1,299 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: nis_ng.c,v 1.17 2001/05/29 05:49:14 marka Exp $";
-#endif
-
-/* Imports */
-
-#include "port_before.h"
-
-#ifndef WANT_IRS_NIS
-static int __bind_irs_nis_unneeded;
-#else
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <rpc/rpc.h>
-#include <rpc/xdr.h>
-#include <rpcsvc/yp_prot.h>
-#include <rpcsvc/ypclnt.h>
-
-#include <isc/assertions.h>
-#include <ctype.h>
-#include <errno.h>
-#include <netdb.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-
-#include <isc/memcluster.h>
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "nis_p.h"
-
-/* Definitions */
-
-struct tmpgrp {
- const char * name;
- const char * host;
- const char * user;
- const char * domain;
- struct tmpgrp * next;
-};
-
-struct pvt {
- char * nis_domain;
- struct tmpgrp * tmp;
- struct tmpgrp * cur;
- char * tmpgroup;
-};
-
-enum do_what { do_none = 0x0, do_key = 0x1, do_val = 0x2, do_all = 0x3 };
-
-static /*const*/ char netgroup_map[] = "netgroup";
-
-/* Forward */
-
-static void ng_close(struct irs_ng *);
-static int ng_next(struct irs_ng *, const char **,
- const char **, const char **);
-static int ng_test(struct irs_ng *,
- const char *, const char *,
- const char *, const char *);
-static void ng_rewind(struct irs_ng *, const char *);
-static void ng_minimize(struct irs_ng *);
-
-static void add_group_to_list(struct pvt *, const char *, int);
-static void add_tuple_to_list(struct pvt *, const char *, char *);
-static void tmpfree(struct pvt *);
-
-/* Public */
-
-struct irs_ng *
-irs_nis_ng(struct irs_acc *this) {
- struct irs_ng *ng;
- struct pvt *pvt;
-
- if (!(ng = memget(sizeof *ng))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(ng, 0x5e, sizeof *ng);
- if (!(pvt = memget(sizeof *pvt))) {
- memput(ng, sizeof *ng);
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- pvt->nis_domain = ((struct nis_p *)this->private)->domain;
- ng->private = pvt;
- ng->close = ng_close;
- ng->next = ng_next;
- ng->test = ng_test;
- ng->rewind = ng_rewind;
- ng->minimize = ng_minimize;
- return (ng);
-}
-
-/* Methods */
-
-static void
-ng_close(struct irs_ng *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- tmpfree(pvt);
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-static int
-ng_next(struct irs_ng *this, const char **host, const char **user, const char **domain) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (!pvt->cur)
- return (0);
- *host = pvt->cur->host;
- *user = pvt->cur->user;
- *domain = pvt->cur->domain;
- pvt->cur = pvt->cur->next;
- return (1);
-}
-
-static int
-ng_test(struct irs_ng *this, const char *name,
- const char *host, const char *user, const char *domain)
-{
- struct pvt *pvt = (struct pvt *)this->private;
- struct tmpgrp *cur;
-
- tmpfree(pvt);
- add_group_to_list(pvt, name, strlen(name));
- for (cur = pvt->tmp; cur; cur = cur->next) {
- if ((!host || !cur->host || !strcmp(host, cur->host)) &&
- (!user || !cur->user || !strcmp(user, cur->user)) &&
- (!domain || !cur->domain || !strcmp(domain, cur->domain)))
- break;
- }
- tmpfree(pvt);
- return ((cur == NULL) ? 0 : 1);
-}
-
-static void
-ng_rewind(struct irs_ng *this, const char *name) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- /* Either hand back or free the existing list. */
- if (pvt->tmpgroup) {
- if (pvt->tmp && !strcmp(pvt->tmpgroup, name))
- goto reset;
- tmpfree(pvt);
- }
- pvt->tmpgroup = strdup(name);
- add_group_to_list(pvt, name, strlen(name));
- reset:
- pvt->cur = pvt->tmp;
-}
-
-static void
-ng_minimize(struct irs_ng *this) {
- UNUSED(this);
- /* NOOP */
-}
-
-/* Private */
-
-static void
-add_group_to_list(struct pvt *pvt, const char *name, int len) {
- char *vdata, *cp, *np;
- struct tmpgrp *tmp;
- int vlen, r;
- char *nametmp;
-
- /* Don't add the same group to the list more than once. */
- for (tmp = pvt->tmp; tmp; tmp = tmp->next)
- if (!strcmp(tmp->name, name))
- return;
-
- DE_CONST(name, nametmp);
- r = yp_match(pvt->nis_domain, netgroup_map, nametmp, len,
- &vdata, &vlen);
- if (r == 0) {
- cp = vdata;
- if (*cp && cp[strlen(cp)-1] == '\n')
- cp[strlen(cp)-1] = '\0';
- for ( ; cp; cp = np) {
- np = strchr(cp, ' ');
- if (np)
- *np++ = '\0';
- if (*cp == '(')
- add_tuple_to_list(pvt, name, cp);
- else
- add_group_to_list(pvt, cp, strlen(cp));
- }
- free(vdata);
- }
-}
-
-static void
-add_tuple_to_list(struct pvt *pvt, const char *name, char *cp) {
- struct tmpgrp *tmp;
- char *tp, *np;
-
- INSIST(*cp++ == '(');
-
- tmp = malloc(sizeof *tmp + strlen(name) + sizeof '\0' +
- strlen(cp) - sizeof ')');
- if (!tmp)
- return;
- memset(tmp, 0, sizeof *tmp);
- tp = ((char *)tmp) + sizeof *tmp;
-
- /* Name */
- strcpy(tp, name);
- tmp->name = tp;
- tp += strlen(tp) + 1;
-
- /* Host */
- if (!(np = strchr(cp, ',')))
- goto cleanup;
- *np++ = '\0';
- strcpy(tp, cp);
- tmp->host = tp;
- tp += strlen(tp) + 1;
- cp = np;
-
- /* User */
- if (!(np = strchr(cp, ',')))
- goto cleanup;
- *np++ = '\0';
- strcpy(tp, cp);
- tmp->user = tp;
- tp += strlen(tp) + 1;
- cp = np;
-
- /* Domain */
- if (!(np = strchr(cp, ')')))
- goto cleanup;
- *np++ = '\0';
- strcpy(tp, cp);
- tmp->domain = tp;
-
- /*
- * Empty string in file means wildcard, but
- * NULL string in return value means wildcard.
- */
- if (!*tmp->host)
- tmp->host = NULL;
- if (!*tmp->user)
- tmp->user = NULL;
- if (!*tmp->domain)
- tmp->domain = NULL;
-
- /* Add to list (LIFO). */
- tmp->next = pvt->tmp;
- pvt->tmp = tmp;
- return;
-
- cleanup:
- free(tmp);
-}
-
-static void
-tmpfree(struct pvt *pvt) {
- struct tmpgrp *cur, *next;
-
- if (pvt->tmpgroup) {
- free(pvt->tmpgroup);
- pvt->tmpgroup = NULL;
- }
- for (cur = pvt->tmp; cur; cur = next) {
- next = cur->next;
- free(cur);
- }
- pvt->tmp = NULL;
-}
-
-#endif /*WANT_IRS_NIS*/
diff --git a/contrib/bind/lib/irs/nis_nw.c b/contrib/bind/lib/irs/nis_nw.c
deleted file mode 100644
index bc659f3..0000000
--- a/contrib/bind/lib/irs/nis_nw.c
+++ /dev/null
@@ -1,381 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: nis_nw.c,v 1.16 2001/05/29 05:49:15 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-/* Imports */
-
-#include "port_before.h"
-
-#ifndef WANT_IRS_NIS
-static int __bind_irs_nis_unneeded;
-#else
-
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-
-#include <rpc/rpc.h>
-#include <rpc/xdr.h>
-#include <rpcsvc/yp_prot.h>
-#include <rpcsvc/ypclnt.h>
-
-#include <errno.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <isc/memcluster.h>
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "nis_p.h"
-
-/* Definitions */
-
-#define MAXALIASES 35
-#define MAXADDRSIZE 4
-
-struct pvt {
- int needrewind;
- char * nis_domain;
- char * curkey_data;
- int curkey_len;
- char * curval_data;
- int curval_len;
-
- struct nwent nwent;
- char * nwbuf;
-
- char * aliases[MAXALIASES + 1];
- u_char addr[MAXADDRSIZE];
-
- struct __res_state * res;
- void (*free_res)(void *);
-};
-
-enum do_what { do_none = 0x0, do_key = 0x1, do_val = 0x2, do_all = 0x3 };
-
-static /*const*/ char networks_byname[] = "networks.byname";
-static /*const*/ char networks_byaddr[] = "networks.byaddr";
-
-/* Forward */
-
-static void nw_close(struct irs_nw *);
-static struct nwent * nw_byname(struct irs_nw *, const char *, int);
-static struct nwent * nw_byaddr(struct irs_nw *, void *, int, int);
-static struct nwent * nw_next(struct irs_nw *);
-static void nw_rewind(struct irs_nw *);
-static void nw_minimize(struct irs_nw *);
-static struct __res_state * nw_res_get(struct irs_nw *this);
-static void nw_res_set(struct irs_nw *this,
- struct __res_state *res,
- void (*free_res)(void *));
-
-static struct nwent * makenwent(struct irs_nw *this);
-static void nisfree(struct pvt *, enum do_what);
-static int init(struct irs_nw *this);
-
-/* Public */
-
-struct irs_nw *
-irs_nis_nw(struct irs_acc *this) {
- struct irs_nw *nw;
- struct pvt *pvt;
-
- if (!(pvt = memget(sizeof *pvt))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- if (!(nw = memget(sizeof *nw))) {
- memput(pvt, sizeof *pvt);
- errno = ENOMEM;
- return (NULL);
- }
- memset(nw, 0x5e, sizeof *nw);
- pvt->needrewind = 1;
- pvt->nis_domain = ((struct nis_p *)this->private)->domain;
- nw->private = pvt;
- nw->close = nw_close;
- nw->byname = nw_byname;
- nw->byaddr = nw_byaddr;
- nw->next = nw_next;
- nw->rewind = nw_rewind;
- nw->minimize = nw_minimize;
- nw->res_get = nw_res_get;
- nw->res_set = nw_res_set;
- return (nw);
-}
-
-/* Methods */
-
-static void
-nw_close(struct irs_nw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- nw_minimize(this);
- if (pvt->res && pvt->free_res)
- (*pvt->free_res)(pvt->res);
- if (pvt->nwbuf)
- free(pvt->nwbuf);
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-static struct nwent *
-nw_byaddr(struct irs_nw *this, void *net, int length, int af) {
- struct pvt *pvt = (struct pvt *)this->private;
- char tmp[sizeof "255.255.255.255/32"], *t;
- int r;
-
- if (init(this) == -1)
- return (NULL);
-
- if (af != AF_INET) {
- RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
- errno = EAFNOSUPPORT;
- return (NULL);
- }
- nisfree(pvt, do_val);
- /* Try it with /CIDR first. */
- if (inet_net_ntop(AF_INET, net, length, tmp, sizeof tmp) == NULL) {
- RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
- return (NULL);
- }
- r = yp_match(pvt->nis_domain, networks_byaddr, tmp, strlen(tmp),
- &pvt->curval_data, &pvt->curval_len);
- if (r != 0) {
- /* Give it a shot without the /CIDR. */
- if ((t = strchr(tmp, '/')) != NULL) {
- *t = '\0';
- r = yp_match(pvt->nis_domain, networks_byaddr,
- tmp, strlen(tmp),
- &pvt->curval_data, &pvt->curval_len);
- }
- if (r != 0) {
- RES_SET_H_ERRNO(pvt->res, HOST_NOT_FOUND);
- return (NULL);
- }
- }
- return (makenwent(this));
-}
-
-static struct nwent *
-nw_byname(struct irs_nw *this, const char *name, int af) {
- struct pvt *pvt = (struct pvt *)this->private;
- int r;
- char *tmp;
-
- if (init(this) == -1)
- return (NULL);
-
- if (af != AF_INET) {
- RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL);
- errno = EAFNOSUPPORT;
- return (NULL);
- }
- nisfree(pvt, do_val);
- DE_CONST(name, tmp);
- r = yp_match(pvt->nis_domain, networks_byname, tmp,
- strlen(tmp), &pvt->curval_data, &pvt->curval_len);
- if (r != 0) {
- RES_SET_H_ERRNO(pvt->res, HOST_NOT_FOUND);
- return (NULL);
- }
- return (makenwent(this));
-}
-
-static void
-nw_rewind(struct irs_nw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- pvt->needrewind = 1;
-}
-
-static struct nwent *
-nw_next(struct irs_nw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct nwent *rval;
- int r;
-
- if (init(this) == -1)
- return (NULL);
-
- do {
- if (pvt->needrewind) {
- nisfree(pvt, do_all);
- r = yp_first(pvt->nis_domain, networks_byaddr,
- &pvt->curkey_data, &pvt->curkey_len,
- &pvt->curval_data, &pvt->curval_len);
- pvt->needrewind = 0;
- } else {
- char *newkey_data;
- int newkey_len;
-
- nisfree(pvt, do_val);
- r = yp_next(pvt->nis_domain, networks_byaddr,
- pvt->curkey_data, pvt->curkey_len,
- &newkey_data, &newkey_len,
- &pvt->curval_data, &pvt->curval_len);
- nisfree(pvt, do_key);
- pvt->curkey_data = newkey_data;
- pvt->curkey_len = newkey_len;
- }
- if (r != 0) {
- RES_SET_H_ERRNO(pvt->res, HOST_NOT_FOUND);
- return (NULL);
- }
- rval = makenwent(this);
- } while (rval == NULL);
- return (rval);
-}
-
-static void
-nw_minimize(struct irs_nw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->res)
- res_nclose(pvt->res);
-}
-
-static struct __res_state *
-nw_res_get(struct irs_nw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (!pvt->res) {
- struct __res_state *res;
- res = (struct __res_state *)malloc(sizeof *res);
- if (!res) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(res, 0, sizeof *res);
- nw_res_set(this, res, free);
- }
-
- return (pvt->res);
-}
-
-static void
-nw_res_set(struct irs_nw *this, struct __res_state *res,
- void (*free_res)(void *)) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->res && pvt->free_res) {
- res_nclose(pvt->res);
- (*pvt->free_res)(pvt->res);
- }
-
- pvt->res = res;
- pvt->free_res = free_res;
-}
-
-/* Private */
-
-static struct nwent *
-makenwent(struct irs_nw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- static const char spaces[] = " \t";
- char *t, *cp, **ap;
-
- if (pvt->nwbuf)
- free(pvt->nwbuf);
- pvt->nwbuf = pvt->curval_data;
- pvt->curval_data = NULL;
-
- if ((cp = strpbrk(pvt->nwbuf, "#\n")) != NULL)
- *cp = '\0';
- cp = pvt->nwbuf;
-
- /* Name */
- pvt->nwent.n_name = cp;
- cp += strcspn(cp, spaces);
- if (!*cp)
- goto cleanup;
- *cp++ = '\0';
- cp += strspn(cp, spaces);
-
- /* Network */
- pvt->nwent.n_addrtype = AF_INET;
- t = cp + strcspn(cp, spaces);
- if (*t)
- *t++ = '\0';
- pvt->nwent.n_length = inet_net_pton(AF_INET, cp,
- pvt->addr, sizeof pvt->addr);
- if (pvt->nwent.n_length < 0)
- goto cleanup;
- pvt->nwent.n_addr = pvt->addr;
- cp = t;
-
- /* Aliases */
- ap = pvt->nwent.n_aliases = pvt->aliases;
- while (*cp) {
- if (ap >= &pvt->aliases[MAXALIASES])
- break;
- *ap++ = cp;
- cp += strcspn(cp, spaces);
- if (!*cp)
- break;
- *cp++ = '\0';
- cp += strspn(cp, spaces);
- }
- *ap = NULL;
-
- return (&pvt->nwent);
-
- cleanup:
- if (pvt->nwbuf) {
- free(pvt->nwbuf);
- pvt->nwbuf = NULL;
- }
- return (NULL);
-}
-
-static void
-nisfree(struct pvt *pvt, enum do_what do_what) {
- if ((do_what & do_key) && pvt->curkey_data) {
- free(pvt->curkey_data);
- pvt->curkey_data = NULL;
- }
- if ((do_what & do_val) && pvt->curval_data) {
- free(pvt->curval_data);
- pvt->curval_data = NULL;
- }
-}
-
-static int
-init(struct irs_nw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (!pvt->res && !nw_res_get(this))
- return (-1);
- if (((pvt->res->options & RES_INIT) == 0) &&
- res_ninit(pvt->res) == -1)
- return (-1);
- return (0);
-}
-
-#endif /*WANT_IRS_NIS*/
diff --git a/contrib/bind/lib/irs/nis_p.h b/contrib/bind/lib/irs/nis_p.h
deleted file mode 100644
index d3dc126..0000000
--- a/contrib/bind/lib/irs/nis_p.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-/*
- * $Id: nis_p.h,v 1.6 1999/01/08 19:25:03 vixie Exp $
- */
-
-/*
- * nis_p.h - private include file for the NIS functions.
- */
-
-/*
- * Object state.
- */
-struct nis_p {
- char * domain;
- struct __res_state * res;
- void (*free_res) __P((void *));
-};
-
-
-/*
- * Methods.
- */
-
-extern struct irs_gr * irs_nis_gr __P((struct irs_acc *));
-extern struct irs_pw * irs_nis_pw __P((struct irs_acc *));
-extern struct irs_sv * irs_nis_sv __P((struct irs_acc *));
-extern struct irs_pr * irs_nis_pr __P((struct irs_acc *));
-extern struct irs_ho * irs_nis_ho __P((struct irs_acc *));
-extern struct irs_nw * irs_nis_nw __P((struct irs_acc *));
-extern struct irs_ng * irs_nis_ng __P((struct irs_acc *));
diff --git a/contrib/bind/lib/irs/nis_pr.c b/contrib/bind/lib/irs/nis_pr.c
deleted file mode 100644
index bc09075..0000000
--- a/contrib/bind/lib/irs/nis_pr.c
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: nis_pr.c,v 1.14 2001/05/29 05:49:16 marka Exp $";
-#endif
-
-/* Imports */
-
-#include "port_before.h"
-
-#ifndef WANT_IRS_NIS
-static int __bind_irs_nis_unneeded;
-#else
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-#include <rpc/rpc.h>
-#include <rpc/xdr.h>
-#include <rpcsvc/yp_prot.h>
-#include <rpcsvc/ypclnt.h>
-
-#include <stdio.h>
-#include <string.h>
-#include <netdb.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <errno.h>
-
-#include <isc/memcluster.h>
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "nis_p.h"
-
-/* Definitions */
-
-struct pvt {
- int needrewind;
- char * nis_domain;
- char * curkey_data;
- int curkey_len;
- char * curval_data;
- int curval_len;
- struct protoent proto;
- char * prbuf;
-};
-
-enum do_what { do_none = 0x0, do_key = 0x1, do_val = 0x2, do_all = 0x3 };
-
-static /*const*/ char protocols_byname[] = "protocols.byname";
-static /*const*/ char protocols_bynumber[] = "protocols.bynumber";
-
-/* Forward */
-
-static void pr_close(struct irs_pr *);
-static struct protoent * pr_byname(struct irs_pr *, const char *);
-static struct protoent * pr_bynumber(struct irs_pr *, int);
-static struct protoent * pr_next(struct irs_pr *);
-static void pr_rewind(struct irs_pr *);
-static void pr_minimize(struct irs_pr *);
-
-static struct protoent * makeprotoent(struct irs_pr *this);
-static void nisfree(struct pvt *, enum do_what);
-
-/* Public */
-
-struct irs_pr *
-irs_nis_pr(struct irs_acc *this) {
- struct irs_pr *pr;
- struct pvt *pvt;
-
- if (!(pr = memget(sizeof *pr))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(pr, 0x5e, sizeof *pr);
- if (!(pvt = memget(sizeof *pvt))) {
- memput(pr, sizeof *pr);
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- pvt->needrewind = 1;
- pvt->nis_domain = ((struct nis_p *)this->private)->domain;
- pr->private = pvt;
- pr->byname = pr_byname;
- pr->bynumber = pr_bynumber;
- pr->next = pr_next;
- pr->rewind = pr_rewind;
- pr->close = pr_close;
- pr->minimize = pr_minimize;
- pr->res_get = NULL;
- pr->res_set = NULL;
- return (pr);
-}
-
-/* Methods. */
-
-static void
-pr_close(struct irs_pr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- nisfree(pvt, do_all);
- if (pvt->proto.p_aliases)
- free(pvt->proto.p_aliases);
- if (pvt->prbuf)
- free(pvt->prbuf);
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-static struct protoent *
-pr_byname(struct irs_pr *this, const char *name) {
- struct pvt *pvt = (struct pvt *)this->private;
- int r;
- char *tmp;
-
- nisfree(pvt, do_val);
- DE_CONST(name, tmp);
- r = yp_match(pvt->nis_domain, protocols_byname, tmp,
- strlen(tmp), &pvt->curval_data, &pvt->curval_len);
- if (r != 0) {
- errno = ENOENT;
- return (NULL);
- }
- return (makeprotoent(this));
-}
-
-static struct protoent *
-pr_bynumber(struct irs_pr *this, int num) {
- struct pvt *pvt = (struct pvt *)this->private;
- char tmp[sizeof "-4294967295"];
- int r;
-
- nisfree(pvt, do_val);
- (void) sprintf(tmp, "%d", num);
- r = yp_match(pvt->nis_domain, protocols_bynumber, tmp, strlen(tmp),
- &pvt->curval_data, &pvt->curval_len);
- if (r != 0) {
- errno = ENOENT;
- return (NULL);
- }
- return (makeprotoent(this));
-}
-
-static struct protoent *
-pr_next(struct irs_pr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct protoent *rval;
- int r;
-
- do {
- if (pvt->needrewind) {
- nisfree(pvt, do_all);
- r = yp_first(pvt->nis_domain, protocols_bynumber,
- &pvt->curkey_data, &pvt->curkey_len,
- &pvt->curval_data, &pvt->curval_len);
- pvt->needrewind = 0;
- } else {
- char *newkey_data;
- int newkey_len;
-
- nisfree(pvt, do_val);
- r = yp_next(pvt->nis_domain, protocols_bynumber,
- pvt->curkey_data, pvt->curkey_len,
- &newkey_data, &newkey_len,
- &pvt->curval_data, &pvt->curval_len);
- nisfree(pvt, do_key);
- pvt->curkey_data = newkey_data;
- pvt->curkey_len = newkey_len;
- }
- if (r != 0) {
- errno = ENOENT;
- return (NULL);
- }
- rval = makeprotoent(this);
- } while (rval == NULL);
- return (rval);
-}
-
-static void
-pr_rewind(struct irs_pr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- pvt->needrewind = 1;
-}
-
-static void
-pr_minimize(struct irs_pr *this) {
- UNUSED(this);
- /* NOOP */
-}
-
-/* Private */
-
-static struct protoent *
-makeprotoent(struct irs_pr *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- char *p, **t;
- int n, m;
-
- if (pvt->prbuf)
- free(pvt->prbuf);
- pvt->prbuf = pvt->curval_data;
- pvt->curval_data = NULL;
-
- for (p = pvt->prbuf; *p && *p != '#';)
- p++;
- while (p > pvt->prbuf && isspace((unsigned char)(p[-1])))
- p--;
- *p = '\0';
-
- p = pvt->prbuf;
- n = m = 0;
-
- pvt->proto.p_name = p;
- while (*p && !isspace((unsigned char)*p))
- p++;
- if (!*p)
- return (NULL);
- *p++ = '\0';
-
- while (*p && isspace((unsigned char)*p))
- p++;
- pvt->proto.p_proto = atoi(p);
- while (*p && !isspace((unsigned char)*p))
- p++;
- *p++ = '\0';
-
- while (*p) {
- if ((n + 1) >= m || !pvt->proto.p_aliases) {
- m += 10;
- t = realloc(pvt->proto.p_aliases,
- m * sizeof(char *));
- if (!t) {
- errno = ENOMEM;
- goto cleanup;
- }
- pvt->proto.p_aliases = t;
- }
- pvt->proto.p_aliases[n++] = p;
- while (*p && !isspace((unsigned char)*p))
- p++;
- if (*p)
- *p++ = '\0';
- }
- if (!pvt->proto.p_aliases)
- pvt->proto.p_aliases = malloc(sizeof(char *));
- if (!pvt->proto.p_aliases)
- goto cleanup;
- pvt->proto.p_aliases[n] = NULL;
- return (&pvt->proto);
-
- cleanup:
- if (pvt->proto.p_aliases) {
- free(pvt->proto.p_aliases);
- pvt->proto.p_aliases = NULL;
- }
- if (pvt->prbuf) {
- free(pvt->prbuf);
- pvt->prbuf = NULL;
- }
- return (NULL);
-}
-
-static void
-nisfree(struct pvt *pvt, enum do_what do_what) {
- if ((do_what & do_key) && pvt->curkey_data) {
- free(pvt->curkey_data);
- pvt->curkey_data = NULL;
- }
- if ((do_what & do_val) && pvt->curval_data) {
- free(pvt->curval_data);
- pvt->curval_data = NULL;
- }
-}
-
-#endif /*WANT_IRS_NIS*/
diff --git a/contrib/bind/lib/irs/nis_pw.c b/contrib/bind/lib/irs/nis_pw.c
deleted file mode 100644
index 1d345a5..0000000
--- a/contrib/bind/lib/irs/nis_pw.c
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: nis_pw.c,v 1.17 2001/05/29 05:49:18 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-/* Imports */
-
-#include "port_before.h"
-
-#if !defined(WANT_IRS_PW) || !defined(WANT_IRS_NIS)
-static int __bind_irs_pw_unneeded;
-#else
-
-#include <sys/param.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-#include <isc/memcluster.h>
-#include <rpc/rpc.h>
-#include <rpc/xdr.h>
-#include <rpcsvc/yp_prot.h>
-#include <rpcsvc/ypclnt.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <pwd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <isc/memcluster.h>
-
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "nis_p.h"
-
-/* Definitions */
-
-struct pvt {
- int needrewind;
- char * nis_domain;
- char * curkey_data;
- int curkey_len;
- char * curval_data;
- int curval_len;
- struct passwd passwd;
- char * pwbuf;
-};
-
-enum do_what { do_none = 0x0, do_key = 0x1, do_val = 0x2, do_all = 0x3 };
-
-static /*const*/ char passwd_byname[] = "passwd.byname";
-static /*const*/ char passwd_byuid[] = "passwd.byuid";
-
-/* Forward */
-
-static void pw_close(struct irs_pw *);
-static struct passwd * pw_next(struct irs_pw *);
-static struct passwd * pw_byname(struct irs_pw *, const char *);
-static struct passwd * pw_byuid(struct irs_pw *, uid_t);
-static void pw_rewind(struct irs_pw *);
-static void pw_minimize(struct irs_pw *);
-
-static struct passwd * makepasswdent(struct irs_pw *);
-static void nisfree(struct pvt *, enum do_what);
-
-/* Public */
-
-struct irs_pw *
-irs_nis_pw(struct irs_acc *this) {
- struct irs_pw *pw;
- struct pvt *pvt;
-
- if (!(pw = memget(sizeof *pw))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(pw, 0x5e, sizeof *pw);
- if (!(pvt = memget(sizeof *pvt))) {
- memput(pw, sizeof *pw);
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- pvt->needrewind = 1;
- pvt->nis_domain = ((struct nis_p *)this->private)->domain;
- pw->private = pvt;
- pw->close = pw_close;
- pw->next = pw_next;
- pw->byname = pw_byname;
- pw->byuid = pw_byuid;
- pw->rewind = pw_rewind;
- pw->minimize = pw_minimize;
- pw->res_get = NULL;
- pw->res_set = NULL;
- return (pw);
-}
-
-/* Methods */
-
-static void
-pw_close(struct irs_pw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- if (pvt->pwbuf)
- free(pvt->pwbuf);
- nisfree(pvt, do_all);
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-static struct passwd *
-pw_next(struct irs_pw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct passwd *rval;
- int r;
-
- do {
- if (pvt->needrewind) {
- nisfree(pvt, do_all);
- r = yp_first(pvt->nis_domain, passwd_byname,
- &pvt->curkey_data, &pvt->curkey_len,
- &pvt->curval_data, &pvt->curval_len);
- pvt->needrewind = 0;
- } else {
- char *newkey_data;
- int newkey_len;
-
- nisfree(pvt, do_val);
- r = yp_next(pvt->nis_domain, passwd_byname,
- pvt->curkey_data, pvt->curkey_len,
- &newkey_data, &newkey_len,
- &pvt->curval_data, &pvt->curval_len);
- nisfree(pvt, do_key);
- pvt->curkey_data = newkey_data;
- pvt->curkey_len = newkey_len;
- }
- if (r != 0) {
- errno = ENOENT;
- return (NULL);
- }
- rval = makepasswdent(this);
- } while (rval == NULL);
- return (rval);
-}
-
-static struct passwd *
-pw_byname(struct irs_pw *this, const char *name) {
- struct pvt *pvt = (struct pvt *)this->private;
- int r;
- char *tmp;
-
- nisfree(pvt, do_val);
- DE_CONST(name, tmp);
- r = yp_match(pvt->nis_domain, passwd_byname, tmp, strlen(tmp),
- &pvt->curval_data, &pvt->curval_len);
- if (r != 0) {
- errno = ENOENT;
- return (NULL);
- }
- return (makepasswdent(this));
-}
-
-static struct passwd *
-pw_byuid(struct irs_pw *this, uid_t uid) {
- struct pvt *pvt = (struct pvt *)this->private;
- char tmp[sizeof "4294967295"];
- int r;
-
- nisfree(pvt, do_val);
- (void) sprintf(tmp, "%u", (unsigned int)uid);
- r = yp_match(pvt->nis_domain, passwd_byuid, tmp, strlen(tmp),
- &pvt->curval_data, &pvt->curval_len);
- if (r != 0) {
- errno = ENOENT;
- return (NULL);
- }
- return (makepasswdent(this));
-}
-
-static void
-pw_rewind(struct irs_pw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- pvt->needrewind = 1;
-}
-
-static void
-pw_minimize(struct irs_pw *this) {
- UNUSED(this);
- /* NOOP */
-}
-
-/* Private */
-
-static struct passwd *
-makepasswdent(struct irs_pw *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- char *cp;
-
- memset(&pvt->passwd, 0, sizeof pvt->passwd);
- if (pvt->pwbuf)
- free(pvt->pwbuf);
- pvt->pwbuf = pvt->curval_data;
- pvt->curval_data = NULL;
-
- cp = pvt->pwbuf;
- pvt->passwd.pw_name = cp;
- if (!(cp = strchr(cp, ':')))
- goto cleanup;
-#ifdef HAS_PW_CLASS
- pvt->passwd.pw_class = cp; /* Needs to point at a \0. */
-#endif
- *cp++ = '\0';
-
- pvt->passwd.pw_passwd = cp;
- if (!(cp = strchr(cp, ':')))
- goto cleanup;
- *cp++ = '\0';
-
- pvt->passwd.pw_uid = atoi(cp);
- if (!(cp = strchr(cp, ':')))
- goto cleanup;
- *cp++ = '\0';
-
- pvt->passwd.pw_gid = atoi(cp);
- if (!(cp = strchr(cp, ':')))
- goto cleanup;
- *cp++ = '\0';
-
- pvt->passwd.pw_gecos = cp;
- if (!(cp = strchr(cp, ':')))
- goto cleanup;
- *cp++ = '\0';
-
- pvt->passwd.pw_dir = cp;
- if (!(cp = strchr(cp, ':')))
- goto cleanup;
- *cp++ = '\0';
-
- pvt->passwd.pw_shell = cp;
-
- if ((cp = strchr(cp, '\n')) != NULL)
- *cp = '\0';
-
- return (&pvt->passwd);
-
- cleanup:
- free(pvt->pwbuf);
- pvt->pwbuf = NULL;
- return (NULL);
-}
-
-static void
-nisfree(struct pvt *pvt, enum do_what do_what) {
- if ((do_what & do_key) && pvt->curkey_data) {
- free(pvt->curkey_data);
- pvt->curkey_data = NULL;
- }
- if ((do_what & do_val) && pvt->curval_data) {
- free(pvt->curval_data);
- pvt->curval_data = NULL;
- }
-}
-
-#endif /* WANT_IRS_PW && WANT_IRS_NIS */
diff --git a/contrib/bind/lib/irs/nis_sv.c b/contrib/bind/lib/irs/nis_sv.c
deleted file mode 100644
index 40bfda5..0000000
--- a/contrib/bind/lib/irs/nis_sv.c
+++ /dev/null
@@ -1,305 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: nis_sv.c,v 1.15 2001/05/29 05:49:19 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-/* Imports */
-
-#include "port_before.h"
-
-#ifndef WANT_IRS_NIS
-static int __bind_irs_nis_unneeded;
-#else
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-#include <sys/socket.h>
-#include <rpc/rpc.h>
-#include <rpc/xdr.h>
-#include <rpcsvc/yp_prot.h>
-#include <rpcsvc/ypclnt.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <isc/memcluster.h>
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "nis_p.h"
-
-/* Definitions */
-
-struct pvt {
- int needrewind;
- char * nis_domain;
- char * curkey_data;
- int curkey_len;
- char * curval_data;
- int curval_len;
- char line[BUFSIZ+1];
- struct servent serv;
- char * svbuf;
-};
-
-enum do_what { do_none = 0x0, do_key = 0x1, do_val = 0x2, do_all = 0x3 };
-
-static /*const*/ char services_byname[] = "services.byname";
-
-/* Forward */
-
-static void sv_close(struct irs_sv*);
-static struct servent * sv_next(struct irs_sv *);
-static struct servent * sv_byname(struct irs_sv *, const char *,
- const char *);
-static struct servent * sv_byport(struct irs_sv *, int, const char *);
-static void sv_rewind(struct irs_sv *);
-static void sv_minimize(struct irs_sv *);
-
-static struct servent * makeservent(struct irs_sv *this);
-static void nisfree(struct pvt *, enum do_what);
-
-/* Public */
-
-struct irs_sv *
-irs_nis_sv(struct irs_acc *this) {
- struct irs_sv *sv;
- struct pvt *pvt;
-
- if (!(sv = memget(sizeof *sv))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(sv, 0x5e, sizeof *sv);
- if (!(pvt = memget(sizeof *pvt))) {
- memput(sv, sizeof *sv);
- errno = ENOMEM;
- return (NULL);
- }
- memset(pvt, 0, sizeof *pvt);
- pvt->needrewind = 1;
- pvt->nis_domain = ((struct nis_p *)this->private)->domain;
- sv->private = pvt;
- sv->close = sv_close;
- sv->next = sv_next;
- sv->byname = sv_byname;
- sv->byport = sv_byport;
- sv->rewind = sv_rewind;
- sv->minimize = sv_minimize;
- sv->res_get = NULL;
- sv->res_set = NULL;
- return (sv);
-}
-
-/* Methods */
-
-static void
-sv_close(struct irs_sv *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- nisfree(pvt, do_all);
- if (pvt->serv.s_aliases)
- free(pvt->serv.s_aliases);
- if (pvt->svbuf)
- free(pvt->svbuf);
- memput(pvt, sizeof *pvt);
- memput(this, sizeof *this);
-}
-
-static struct servent *
-sv_byname(struct irs_sv *this, const char *name, const char *proto) {
- struct servent *serv;
- char **sap;
-
- sv_rewind(this);
- while ((serv = sv_next(this)) != NULL) {
- if (proto != NULL && strcmp(proto, serv->s_proto))
- continue;
- if (!strcmp(name, serv->s_name))
- break;
- for (sap = serv->s_aliases; sap && *sap; sap++)
- if (!strcmp(name, *sap))
- break;
- }
- return (serv);
-}
-
-static struct servent *
-sv_byport(struct irs_sv *this, int port, const char *proto) {
- struct servent *serv;
-
- sv_rewind(this);
- while ((serv = sv_next(this)) != NULL) {
- if (proto != NULL && strcmp(proto, serv->s_proto))
- continue;
- if (serv->s_port == port)
- break;
- }
- return (serv);
-}
-
-static void
-sv_rewind(struct irs_sv *this) {
- struct pvt *pvt = (struct pvt *)this->private;
-
- pvt->needrewind = 1;
-}
-
-static struct servent *
-sv_next(struct irs_sv *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- struct servent *rval;
- int r;
-
- do {
- if (pvt->needrewind) {
- nisfree(pvt, do_all);
- r = yp_first(pvt->nis_domain, services_byname,
- &pvt->curkey_data, &pvt->curkey_len,
- &pvt->curval_data, &pvt->curval_len);
- pvt->needrewind = 0;
- } else {
- char *newkey_data;
- int newkey_len;
-
- nisfree(pvt, do_val);
- r = yp_next(pvt->nis_domain, services_byname,
- pvt->curkey_data, pvt->curkey_len,
- &newkey_data, &newkey_len,
- &pvt->curval_data, &pvt->curval_len);
- nisfree(pvt, do_key);
- pvt->curkey_data = newkey_data;
- pvt->curkey_len = newkey_len;
- }
- if (r != 0) {
- errno = ENOENT;
- return (NULL);
- }
- rval = makeservent(this);
- } while (rval == NULL);
- return (rval);
-}
-
-static void
-sv_minimize(struct irs_sv *this) {
- UNUSED(this);
- /* NOOP */
-}
-
-/* Private */
-
-static struct servent *
-makeservent(struct irs_sv *this) {
- struct pvt *pvt = (struct pvt *)this->private;
- static const char spaces[] = " \t";
- char *p, **t;
- int n, m;
-
- if (pvt->svbuf)
- free(pvt->svbuf);
- pvt->svbuf = pvt->curval_data;
- pvt->curval_data = NULL;
-
- if (pvt->serv.s_aliases) {
- free(pvt->serv.s_aliases);
- pvt->serv.s_aliases = NULL;
- }
-
- if ((p = strpbrk(pvt->svbuf, "#\n")))
- *p = '\0';
-
- p = pvt->svbuf;
-
- pvt->serv.s_name = p;
- p += strcspn(p, spaces);
- if (!*p)
- goto cleanup;
- *p++ = '\0';
- p += strspn(p, spaces);
-
- pvt->serv.s_port = htons((u_short) atoi(p));
- pvt->serv.s_proto = NULL;
-
- while (*p && !isspace((unsigned char)*p))
- if (*p++ == '/')
- pvt->serv.s_proto = p;
- if (!pvt->serv.s_proto)
- goto cleanup;
- if (*p) {
- *p++ = '\0';
- p += strspn(p, spaces);
- }
-
- n = m = 0;
- while (*p) {
- if ((n + 1) >= m || !pvt->serv.s_aliases) {
- m += 10;
- t = realloc(pvt->serv.s_aliases, m * sizeof(char *));
- if (!t) {
- errno = ENOMEM;
- goto cleanup;
- }
- pvt->serv.s_aliases = t;
- }
- pvt->serv.s_aliases[n++] = p;
- p += strcspn(p, spaces);
- if (!*p)
- break;
- *p++ = '\0';
- p += strspn(p, spaces);
- }
- if (!pvt->serv.s_aliases)
- pvt->serv.s_aliases = malloc(sizeof(char *));
- if (!pvt->serv.s_aliases)
- goto cleanup;
- pvt->serv.s_aliases[n] = NULL;
- return (&pvt->serv);
-
- cleanup:
- if (pvt->serv.s_aliases) {
- free(pvt->serv.s_aliases);
- pvt->serv.s_aliases = NULL;
- }
- if (pvt->svbuf) {
- free(pvt->svbuf);
- pvt->svbuf = NULL;
- }
- return (NULL);
-}
-
-static void
-nisfree(struct pvt *pvt, enum do_what do_what) {
- if ((do_what & do_key) && pvt->curkey_data) {
- free(pvt->curkey_data);
- pvt->curkey_data = NULL;
- }
- if ((do_what & do_val) && pvt->curval_data) {
- free(pvt->curval_data);
- pvt->curval_data = NULL;
- }
-}
-
-#endif /*WANT_IRS_NIS*/
diff --git a/contrib/bind/lib/irs/nul_ng.c b/contrib/bind/lib/irs/nul_ng.c
deleted file mode 100644
index 1a61d8c..0000000
--- a/contrib/bind/lib/irs/nul_ng.c
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: nul_ng.c,v 1.11 2001/05/29 05:49:20 marka Exp $";
-#endif
-
-/*
- * nul_ng.c - the netgroup accessor null map
- */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-
-#include <stdio.h>
-#include <string.h>
-#include <netdb.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <errno.h>
-
-#include <irs.h>
-#include <isc/memcluster.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-#include "hesiod.h"
-#include "dns_p.h"
-
-/* Forward. */
-
-static void ng_close(struct irs_ng *);
-static int ng_next(struct irs_ng *, const char **,
- const char **, const char **);
-static int ng_test(struct irs_ng *,
- const char *, const char *,
- const char *, const char *);
-static void ng_rewind(struct irs_ng *, const char *);
-static void ng_minimize(struct irs_ng *);
-
-/* Public. */
-
-struct irs_ng *
-irs_nul_ng(struct irs_acc *this) {
- struct irs_ng *ng;
-
- UNUSED(this);
-
- if (!(ng = memget(sizeof *ng))) {
- errno = ENOMEM;
- return (NULL);
- }
- memset(ng, 0x5e, sizeof *ng);
- ng->private = NULL;
- ng->close = ng_close;
- ng->next = ng_next;
- ng->test = ng_test;
- ng->rewind = ng_rewind;
- ng->minimize = ng_minimize;
- return (ng);
-}
-
-/* Methods. */
-
-static void
-ng_close(struct irs_ng *this) {
- memput(this, sizeof *this);
-}
-
-/* ARGSUSED */
-static int
-ng_next(struct irs_ng *this, const char **host, const char **user,
- const char **domain)
-{
- UNUSED(this);
- UNUSED(host);
- UNUSED(user);
- UNUSED(domain);
- errno = ENOENT;
- return (-1);
-}
-
-static int
-ng_test(struct irs_ng *this, const char *name,
- const char *user, const char *host, const char *domain)
-{
- UNUSED(this);
- UNUSED(name);
- UNUSED(user);
- UNUSED(host);
- UNUSED(domain);
- errno = ENODEV;
- return (-1);
-}
-
-static void
-ng_rewind(struct irs_ng *this, const char *netgroup) {
- UNUSED(this);
- UNUSED(netgroup);
- /* NOOP */
-}
-
-static void
-ng_minimize(struct irs_ng *this) {
- UNUSED(this);
- /* NOOP */
-}
diff --git a/contrib/bind/lib/irs/pathnames.h b/contrib/bind/lib/irs/pathnames.h
deleted file mode 100644
index 1a225e5..0000000
--- a/contrib/bind/lib/irs/pathnames.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-/*
- * $Id: pathnames.h,v 1.7 1999/01/08 19:25:10 vixie Exp $
- */
-
-#ifndef _PATH_IRS_CONF
-#define _PATH_IRS_CONF "/etc/irs.conf"
-#endif
-
-#ifndef _PATH_NETWORKS
-#define _PATH_NETWORKS "/etc/networks"
-#endif
-
-#ifndef _PATH_GROUP
-#define _PATH_GROUP "/etc/group"
-#endif
-
-#ifndef _PATH_NETGROUP
-#define _PATH_NETGROUP "/etc/netgroup"
-#endif
-
-#ifndef _PATH_SERVICES
-#define _PATH_SERVICES "/etc/services"
-#endif
-
-#ifdef IRS_LCL_SV_DB
-#ifndef _PATH_SERVICES_DB
-#define _PATH_SERVICES_DB _PATH_SERVICES ".db"
-#endif
-#endif
-
-#ifndef _PATH_HESIOD_CONF
-#define _PATH_HESIOD_CONF "/etc/hesiod.conf"
-#endif
diff --git a/contrib/bind/lib/irs/util.c b/contrib/bind/lib/irs/util.c
deleted file mode 100644
index e37f4d9..0000000
--- a/contrib/bind/lib/irs/util.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: util.c,v 1.12 2001/05/29 05:49:21 marka Exp $";
-#endif
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include <irs.h>
-
-#include "port_after.h"
-
-#include "irs_p.h"
-
-#ifdef SPRINTF_CHAR
-# define SPRINTF(x) strlen(sprintf/**/x)
-#else
-# define SPRINTF(x) sprintf x
-#endif
-
-void
-map_v4v6_address(const char *src, char *dst) {
- u_char *p = (u_char *)dst;
- char tmp[NS_INADDRSZ];
- int i;
-
- /* Stash a temporary copy so our caller can update in place. */
- memcpy(tmp, src, NS_INADDRSZ);
- /* Mark this ipv6 addr as a mapped ipv4. */
- for (i = 0; i < 10; i++)
- *p++ = 0x00;
- *p++ = 0xff;
- *p++ = 0xff;
- /* Retrieve the saved copy and we're done. */
- memcpy((void*)p, tmp, NS_INADDRSZ);
-}
-
-int
-make_group_list(struct irs_gr *this, const char *name,
- gid_t basegid, gid_t *groups, int *ngroups)
-{
- struct group *grp;
- int i, ng;
- int ret, maxgroups;
-
- ret = -1;
- ng = 0;
- maxgroups = *ngroups;
- /*
- * When installing primary group, duplicate it;
- * the first element of groups is the effective gid
- * and will be overwritten when a setgid file is executed.
- */
- if (ng >= maxgroups)
- goto done;
- groups[ng++] = basegid;
- if (ng >= maxgroups)
- goto done;
- groups[ng++] = basegid;
- /*
- * Scan the group file to find additional groups.
- */
- (*this->rewind)(this);
- while ((grp = (*this->next)(this)) != NULL) {
- if ((gid_t)grp->gr_gid == basegid)
- continue;
- for (i = 0; grp->gr_mem[i]; i++) {
- if (!strcmp(grp->gr_mem[i], name)) {
- if (ng >= maxgroups)
- goto done;
- groups[ng++] = grp->gr_gid;
- break;
- }
- }
- }
- ret = 0;
- done:
- *ngroups = ng;
- return (ret);
-}
diff --git a/contrib/bind/lib/isc/Makefile b/contrib/bind/lib/isc/Makefile
deleted file mode 100644
index 0127c6d..0000000
--- a/contrib/bind/lib/isc/Makefile
+++ /dev/null
@@ -1,99 +0,0 @@
-# Copyright (c) 1996,1999 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.
-
-# $Id: Makefile,v 8.30 2001/08/14 05:58:08 marka Exp $
-
-# these are only appropriate for BSD 4.4 or derivatives, and are used in
-# development. normal builds will be done in the top level directory and
-# this Makefile will be invoked with a lot of overrides for the following:
-SYSTYPE= freebsd
-DESTDIR =
-DESTLIB = /usr/local/lib
-O=o
-A=a
-CC= cc
-LD= ld
-SHELL= /bin/sh
-CDEBUG= -g -Wall
-TOP= ../..
-INCL = ${TOP}/include
-PORTINCL = ${TOP}/port/${SYSTYPE}/include
-LIBBIND = ${TOP}/lib/libbind.${A}
-LIBBINDR = ../${TOP}/lib/libbind_r.${A}
-CFLAGS= ${CDEBUG}
-CPPFLAGS= -I${PORTINCL} -I${INCL}
-# -Wimplicit
-LD_LIBFLAGS= -x -r
-AR= ar cru
-RANLIB= ranlib
-INSTALL= install
-INSTALL_EXEC=
-INSTALL_LIB=-o bin -g bin
-THREADED= threaded
-
-SRCS= tree.c base64.c bitncmp.c assertions.c \
- memcluster.c logging.c heap.c \
- ctl_p.c ctl_srvr.c ctl_clnt.c \
- eventlib.c ev_connects.c ev_files.c \
- ev_timers.c ev_streams.c ev_waits.c \
- hex.c movefile.c
-
-OBJS= tree.${O} base64.${O} bitncmp.${O} assertions.${O} \
- memcluster.${O} logging.${O} heap.${O} \
- ctl_p.${O} ctl_srvr.${O} ctl_clnt.${O} \
- eventlib.${O} ev_connects.${O} ev_files.${O} \
- ev_timers.${O} ev_streams.${O} ev_waits.${O} \
- hex.${O} movefile.${O}
-
-all: ${LIBBIND}
-
-${LIBBIND}: ${OBJS}
- ( cd ${THREADED} ; \
- ${AR} ${LIBBINDR} ${ARPREF} ${OBJS} ${ARSUFF} ; \
- ${RANLIB} ${LIBBINDR} )
- ${AR} ${LIBBIND} ${ARPREF} ${OBJS} ${ARSUFF}
- ${RANLIB} ${LIBBIND}
-
-.c.${O}:
- mkdir ${THREADED} 2> /dev/null || test -d ${THREADED} -a -w ${THREADED}
- ${CC} ${CPPFLAGS} ${CFLAGS} ${BOUNDS} ${REENTRANT} -c $*.c \
- -o ${THREADED}/$*.${O}
- -${LDS} ${LD} ${LD_LIBFLAGS} ${THREADED}/$*.${O} \
- -o ${THREADED}/$*.out && \
- ${LDS} mv ${THREADED}/$*.out ${THREADED}/$*.${O}
- ${CC} ${CPPFLAGS} ${CFLAGS} ${BOUNDS} -c $*.c
- -${LDS} ${LD} ${LD_LIBFLAGS} $*.${O} -o $*.out && \
- ${LDS} mv $*.out $*.${O}
-
-distclean: clean
-
-clean: FRC
- rm -f .depend a.out core ${LIB} tags
- rm -f *.${O} *.BAK *.CKP *~
- rm -f ${THREADED}/*.${O}
- -if test -d ${THREADED} ; then rmdir ${THREADED}; else true; fi
-
-depend: FRC
- mkdep -I${INCL} -I${PORTINCL} ${CPPFLAGS} ${SRCS}
-
-links: FRC
- @set -e; ln -s SRC/*.[ch] .
-
-install:
-
-FRC:
-
-# DO NOT DELETE THIS LINE -- mkdep uses it.
-# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
diff --git a/contrib/bind/lib/isc/assertions.c b/contrib/bind/lib/isc/assertions.c
deleted file mode 100644
index 704801c..0000000
--- a/contrib/bind/lib/isc/assertions.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright (c) 1997,1999 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.
- */
-
-#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: assertions.c,v 8.4 2001/05/29 05:49:22 marka Exp $";
-#endif
-
-#include "port_before.h"
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <isc/assertions.h>
-
-#include "port_after.h"
-
-/*
- * Forward.
- */
-
-static void default_assertion_failed(const char *, int, assertion_type,
- const char *, int);
-
-/*
- * Public.
- */
-
-assertion_failure_callback __assertion_failed = default_assertion_failed;
-
-void
-set_assertion_failure_callback(assertion_failure_callback f) {
- if (f == NULL)
- __assertion_failed = default_assertion_failed;
- else
- __assertion_failed = f;
-}
-
-const char *
-assertion_type_to_text(assertion_type type) {
- const char *result;
-
- switch (type) {
- case assert_require:
- result = "REQUIRE";
- break;
- case assert_ensure:
- result = "ENSURE";
- break;
- case assert_insist:
- result = "INSIST";
- break;
- case assert_invariant:
- result = "INVARIANT";
- break;
- default:
- result = NULL;
- }
- return (result);
-}
-
-/*
- * Private.
- */
-
-static void
-default_assertion_failed(const char *file, int line, assertion_type type,
- const char *cond, int print_errno)
-{
- fprintf(stderr, "%s:%d: %s(%s)%s%s failed.\n",
- file, line, assertion_type_to_text(type), cond,
- (print_errno) ? ": " : "",
- (print_errno) ? strerror(errno) : "");
- abort();
- /* NOTREACHED */
-}
diff --git a/contrib/bind/lib/isc/assertions.mdoc b/contrib/bind/lib/isc/assertions.mdoc
deleted file mode 100644
index 863829a..0000000
--- a/contrib/bind/lib/isc/assertions.mdoc
+++ /dev/null
@@ -1,138 +0,0 @@
-.\" $Id: assertions.mdoc,v 8.3 2001/08/08 07:50:20 marka Exp $
-.\"
-.\"Copyright (c) 1997,1999 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.
-.\"
-.Dd November 17, 1997
-.Dt ASSERTIONS 3
-.Os ISC
-.Sh NAME
-.Nm REQUIRE ,
-.Nm REQUIRE_ERR ,
-.Nm ENSURE ,
-.Nm ENSURE_ERR ,
-.Nm INSIST ,
-.Nm INSIST_ERR ,
-.Nm INVARIANT ,
-.Nm INVARIANT_ERR ,
-.Nm set_assertion_failure_callback
-.Nd assertion system
-.Sh SYNOPSIS
-.Fd #include <isc/assertions.h>
-.Fo "typedef void (*assertion_failure_callback)"
-.Fa "char *filename"
-.Fa "int line"
-.Fa "assertion_type type"
-.Fa "char *condition"
-.Fa "int print_errno"
-.Fc
-.Fn REQUIRE "int boolean_expression"
-.Fn REQUIRE_ERR "int boolean_expression"
-.Fn ENSURE "int boolean_expression"
-.Fn ENSURE_ERR "int boolean_expression"
-.Fn INSIST "int boolean_expression"
-.Fn INSIST_ERR "int boolean_expression"
-.Fn INVARIANT "int boolean_expression"
-.Fn INVARIANT_ERR "int boolean_expression"
-.Ft void
-.Fn set_assertion_failure_callback "assertion_failure_callback callback"
-.Ft char *
-.Fn assertion_type_to_text "assertion_type type"
-.Sh DESCRIPTION
-The
-.Fn REQUIRE ,
-.Fn ENSURE ,
-.Fn INSIST ,
-and
-.Fn INVARIANT
-macros evaluate a boolean expression, and if it is false, they invoke the
-current assertion failure callback. The default callback will print a message
-to
-.Li stderr
-describing the failure, and then cause the program to dump core.
-If the
-.Dq Fn _ERR
-variant of the assertion is used, the callback will include
-.Fn strerror "errno"
-in its message.
-.Pp
-Each assertion type has an associated
-.Li CHECK
-macro. If this macro's value is
-.Dq 0
-when
-.Dq "<isc/assertions.h>"
-is included, then assertions of that type will not be checked. E.g.
-.Pp
-.Dl #define CHECK_ENSURE 0
-.Pp
-will disable checking of
-.Fn ENSURE
-and
-.Fn ENSURE_ERR .
-The macros
-.Li CHECK_ALL
-and
-.Li CHECK_NONE
-may also be used, respectively specifying that either all or none of the
-assertion types should be checked.
-.Pp
-.Fn set_assertion_failure_callback
-specifies the function to call when an assertion fails.
-.Pp
-When an
-.Fn assertion_failure_callback
-is called, the
-.Fa filename
-and
-.Fa line
-arguments specify the filename and line number of the failing assertion.
-The
-.Fa type
-is one of:
-.Bd -literal -offset indent
-assert_require
-assert_ensure
-assert_insist
-assert_invariant
-.Ed
-.Pp
-and may be used by the callback to determine the type of the failing
-assertion.
-.Fa condition
-is the literal text of the assertion that failed.
-.Fa print_errno
-will be non-zero if the callback should print
-.Fa strerror "errno"
-as part of its output.
-.Pp
-.Fn assertion_type_to_text
-returns a textual representation of
-.Fa type .
-For example,
-.Fn assertion_type_to_text "assert_require"
-returns the string
-.Dq REQUIRE .
-.Sh SEE ALSO
-.Rs
-.%A Bertrand Meyer
-.%B Object-Oriented Software Construction, 2nd edition
-.%Q Prentice\-Hall
-.%D 1997
-.%O ISBN 0\-13\-629155\-4
-.%P chapter 11
-.Re
-.Sh AUTHOR
-Bob Halley (ISC).
diff --git a/contrib/bind/lib/isc/base64.c b/contrib/bind/lib/isc/base64.c
deleted file mode 100644
index c1eebe6..0000000
--- a/contrib/bind/lib/isc/base64.c
+++ /dev/null
@@ -1,320 +0,0 @@
-/*
- * Copyright (c) 1996-1999 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.
- */
-
-/*
- * Portions Copyright (c) 1995 by International Business Machines, Inc.
- *
- * International Business Machines, Inc. (hereinafter called IBM) grants
- * permission under its copyrights to use, copy, modify, and distribute this
- * Software with or without fee, provided that the above copyright notice and
- * all paragraphs of this notice appear in all copies, and that the name of IBM
- * not be used in connection with the marketing of any product incorporating
- * the Software or modifications thereof, without specific, written prior
- * permission.
- *
- * To the extent it has a right to do so, IBM grants an immunity from suit
- * under its patents, if any, for the use, sale or manufacture of products to
- * the extent that such products are used for performing Domain Name System
- * dynamic updates in TCP/IP networks by means of the Software. No immunity is
- * granted for any product per se or for any other function of any product.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
- * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
- * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
- */
-
-#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: base64.c,v 8.7 1999/10/13 16:39:33 vixie Exp $";
-#endif /* not lint */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-
-#include <ctype.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "port_after.h"
-
-#define Assert(Cond) if (!(Cond)) abort()
-
-static const char Base64[] =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-static const char Pad64 = '=';
-
-/* (From RFC1521 and draft-ietf-dnssec-secext-03.txt)
- The following encoding technique is taken from RFC 1521 by Borenstein
- and Freed. It is reproduced here in a slightly edited form for
- convenience.
-
- A 65-character subset of US-ASCII is used, enabling 6 bits to be
- represented per printable character. (The extra 65th character, "=",
- is used to signify a special processing function.)
-
- The encoding process represents 24-bit groups of input bits as output
- strings of 4 encoded characters. Proceeding from left to right, a
- 24-bit input group is formed by concatenating 3 8-bit input groups.
- These 24 bits are then treated as 4 concatenated 6-bit groups, each
- of which is translated into a single digit in the base64 alphabet.
-
- Each 6-bit group is used as an index into an array of 64 printable
- characters. The character referenced by the index is placed in the
- output string.
-
- Table 1: The Base64 Alphabet
-
- Value Encoding Value Encoding Value Encoding Value Encoding
- 0 A 17 R 34 i 51 z
- 1 B 18 S 35 j 52 0
- 2 C 19 T 36 k 53 1
- 3 D 20 U 37 l 54 2
- 4 E 21 V 38 m 55 3
- 5 F 22 W 39 n 56 4
- 6 G 23 X 40 o 57 5
- 7 H 24 Y 41 p 58 6
- 8 I 25 Z 42 q 59 7
- 9 J 26 a 43 r 60 8
- 10 K 27 b 44 s 61 9
- 11 L 28 c 45 t 62 +
- 12 M 29 d 46 u 63 /
- 13 N 30 e 47 v
- 14 O 31 f 48 w (pad) =
- 15 P 32 g 49 x
- 16 Q 33 h 50 y
-
- Special processing is performed if fewer than 24 bits are available
- at the end of the data being encoded. A full encoding quantum is
- always completed at the end of a quantity. When fewer than 24 input
- bits are available in an input group, zero bits are added (on the
- right) to form an integral number of 6-bit groups. Padding at the
- end of the data is performed using the '=' character.
-
- Since all base64 input is an integral number of octets, only the
- -------------------------------------------------
- following cases can arise:
-
- (1) the final quantum of encoding input is an integral
- multiple of 24 bits; here, the final unit of encoded
- output will be an integral multiple of 4 characters
- with no "=" padding,
- (2) the final quantum of encoding input is exactly 8 bits;
- here, the final unit of encoded output will be two
- characters followed by two "=" padding characters, or
- (3) the final quantum of encoding input is exactly 16 bits;
- here, the final unit of encoded output will be three
- characters followed by one "=" padding character.
- */
-
-int
-b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize) {
- size_t datalength = 0;
- u_char input[3];
- u_char output[4];
- size_t i;
-
- while (2 < srclength) {
- input[0] = *src++;
- input[1] = *src++;
- input[2] = *src++;
- srclength -= 3;
-
- output[0] = input[0] >> 2;
- output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
- output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
- output[3] = input[2] & 0x3f;
- Assert(output[0] < 64);
- Assert(output[1] < 64);
- Assert(output[2] < 64);
- Assert(output[3] < 64);
-
- if (datalength + 4 > targsize)
- return (-1);
- target[datalength++] = Base64[output[0]];
- target[datalength++] = Base64[output[1]];
- target[datalength++] = Base64[output[2]];
- target[datalength++] = Base64[output[3]];
- }
-
- /* Now we worry about padding. */
- if (0 != srclength) {
- /* Get what's left. */
- input[0] = input[1] = input[2] = '\0';
- for (i = 0; i < srclength; i++)
- input[i] = *src++;
-
- output[0] = input[0] >> 2;
- output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
- output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
- Assert(output[0] < 64);
- Assert(output[1] < 64);
- Assert(output[2] < 64);
-
- if (datalength + 4 > targsize)
- return (-1);
- target[datalength++] = Base64[output[0]];
- target[datalength++] = Base64[output[1]];
- if (srclength == 1)
- target[datalength++] = Pad64;
- else
- target[datalength++] = Base64[output[2]];
- target[datalength++] = Pad64;
- }
- if (datalength >= targsize)
- return (-1);
- target[datalength] = '\0'; /* Returned value doesn't count \0. */
- return (datalength);
-}
-
-/* skips all whitespace anywhere.
- converts characters, four at a time, starting at (or after)
- src from base - 64 numbers into three 8 bit bytes in the target area.
- it returns the number of data bytes stored at the target, or -1 on error.
- */
-
-int
-b64_pton(src, target, targsize)
- char const *src;
- u_char *target;
- size_t targsize;
-{
- int tarindex, state, ch;
- char *pos;
-
- state = 0;
- tarindex = 0;
-
- while ((ch = *src++) != '\0') {
- if (isspace(ch)) /* Skip whitespace anywhere. */
- continue;
-
- if (ch == Pad64)
- break;
-
- pos = strchr(Base64, ch);
- if (pos == 0) /* A non-base64 character. */
- return (-1);
-
- switch (state) {
- case 0:
- if (target) {
- if ((size_t)tarindex >= targsize)
- return (-1);
- target[tarindex] = (pos - Base64) << 2;
- }
- state = 1;
- break;
- case 1:
- if (target) {
- if ((size_t)tarindex + 1 >= targsize)
- return (-1);
- target[tarindex] |= (pos - Base64) >> 4;
- target[tarindex+1] = ((pos - Base64) & 0x0f)
- << 4 ;
- }
- tarindex++;
- state = 2;
- break;
- case 2:
- if (target) {
- if ((size_t)tarindex + 1 >= targsize)
- return (-1);
- target[tarindex] |= (pos - Base64) >> 2;
- target[tarindex+1] = ((pos - Base64) & 0x03)
- << 6;
- }
- tarindex++;
- state = 3;
- break;
- case 3:
- if (target) {
- if ((size_t)tarindex >= targsize)
- return (-1);
- target[tarindex] |= (pos - Base64);
- }
- tarindex++;
- state = 0;
- break;
- default:
- abort();
- }
- }
-
- /*
- * We are done decoding Base-64 chars. Let's see if we ended
- * on a byte boundary, and/or with erroneous trailing characters.
- */
-
- if (ch == Pad64) { /* We got a pad char. */
- ch = *src++; /* Skip it, get next. */
- switch (state) {
- case 0: /* Invalid = in first position */
- case 1: /* Invalid = in second position */
- return (-1);
-
- case 2: /* Valid, means one byte of info */
- /* Skip any number of spaces. */
- for ((void)NULL; ch != '\0'; ch = *src++)
- if (!isspace(ch))
- break;
- /* Make sure there is another trailing = sign. */
- if (ch != Pad64)
- return (-1);
- ch = *src++; /* Skip the = */
- /* Fall through to "single trailing =" case. */
- /* FALLTHROUGH */
-
- case 3: /* Valid, means two bytes of info */
- /*
- * We know this char is an =. Is there anything but
- * whitespace after it?
- */
- for ((void)NULL; ch != '\0'; ch = *src++)
- if (!isspace(ch))
- return (-1);
-
- /*
- * Now make sure for cases 2 and 3 that the "extra"
- * bits that slopped past the last full byte were
- * zeros. If we don't check them, they become a
- * subliminal channel.
- */
- if (target && target[tarindex] != 0)
- return (-1);
- }
- } else {
- /*
- * We ended by seeing the end of the string. Make sure we
- * have no partial bytes lying around.
- */
- if (state != 0)
- return (-1);
- }
-
- return (tarindex);
-}
diff --git a/contrib/bind/lib/isc/bitncmp.c b/contrib/bind/lib/isc/bitncmp.c
deleted file mode 100644
index c86db62..0000000
--- a/contrib/bind/lib/isc/bitncmp.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: bitncmp.c,v 1.7 2001/05/29 05:49:23 marka Exp $";
-#endif
-
-#include "port_before.h"
-
-#include <sys/types.h>
-
-#include <string.h>
-
-#include "port_after.h"
-
-#include <isc/misc.h>
-
-/*
- * int
- * bitncmp(l, r, n)
- * compare bit masks l and r, for n bits.
- * return:
- * -1, 1, or 0 in the libc tradition.
- * note:
- * network byte order assumed. this means 192.5.5.240/28 has
- * 0x11110000 in its fourth octet.
- * author:
- * Paul Vixie (ISC), June 1996
- */
-int
-bitncmp(const void *l, const void *r, int n) {
- u_int lb, rb;
- int x, b;
-
- b = n / 8;
- x = memcmp(l, r, b);
- if (x)
- return (x);
-
- lb = ((const u_char *)l)[b];
- rb = ((const u_char *)r)[b];
- for (b = n % 8; b > 0; b--) {
- if ((lb & 0x80) != (rb & 0x80)) {
- if (lb & 0x80)
- return (1);
- return (-1);
- }
- lb <<= 1;
- rb <<= 1;
- }
- return (0);
-}
diff --git a/contrib/bind/lib/isc/bitncmp.mdoc b/contrib/bind/lib/isc/bitncmp.mdoc
deleted file mode 100644
index d3cff2e..0000000
--- a/contrib/bind/lib/isc/bitncmp.mdoc
+++ /dev/null
@@ -1,82 +0,0 @@
-.\" $Id: bitncmp.mdoc,v 8.3 2001/08/08 07:50:21 marka Exp $
-.\"
-.\"Copyright (c) 1996,1999 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.
-.\"
-.Dd June 1, 1996
-.Dt BITNCMP 3
-.Os BSD 4
-.Sh NAME
-.Nm bitncmp
-.Nd compare bit masks
-.Sh SYNOPSIS
-.Ft int
-.Fn bitncmp "const void *l" "const void *r" "int n"
-.Sh DESCRIPTION
-The function
-.Fn bitncmp
-compares the
-.Dq Fa n
-most-significant bits of the two masks pointed to by
-.Dq Fa l
-and
-.Dq Fa r ,
-and returns an integer less than, equal to, or greater than 0, according to
-whether or not
-.Dq Fa l
-is lexicographically less than, equal to, or greater than
-.Dq Fa r
-when taken to be unsigned characters (this behaviour is just like that of
-.Xr memcmp 3 ) .
-.Pp
-.Sy NOTE :
-.Fn Bitncmp
-assumes
-.Sy network byte order ;
-this means that the fourth octet of
-.Li 192.5.5.240/28
-.Li 0x11110000 .
-.Sh RETURN VALUES
-.Fn Bitncmp
-returns values in the manner of
-.Xr memcmp 3 :
-.Bd -ragged -offset indent
-+1 if
-.Dq Fa 1
-is greater than
-.Dq Fa r ;
-.Pp
--1 if
-.Dq Fa l
-is less than
-.Dq Fa r ;
-and
-.Pp
-0 if
-.Dq Fa l
-is equal to
-.Dq Fa r ,
-.Ed
-.Pp
-where
-.Dq Fa l
-and
-.Dq Fa r
-are both interpreted as strings of unsigned characters (through bit
-.Dq Fa n . )
-.Sh SEE ALSO
-.Xr memcmp 3 .
-.Sh AUTHOR
-Paul Vixie (ISC).
diff --git a/contrib/bind/lib/isc/ctl_clnt.c b/contrib/bind/lib/isc/ctl_clnt.c
deleted file mode 100644
index 13d71d5..0000000
--- a/contrib/bind/lib/isc/ctl_clnt.c
+++ /dev/null
@@ -1,602 +0,0 @@
-#if !defined(lint) && !defined(SABER)
-static const char rcsid[] = "$Id: ctl_clnt.c,v 8.18 2002/07/08 05:10:23 marka Exp $";
-#endif /* not lint */
-
-/*
- * Copyright (c) 1998,1999 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.
- */
-
-/* Extern. */
-
-#include "port_before.h"
-
-#include <sys/param.h>
-#include <sys/file.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <arpa/inet.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-
-#include <isc/assertions.h>
-#include <isc/ctl.h>
-#include <isc/eventlib.h>
-#include <isc/list.h>
-#include <isc/memcluster.h>
-
-#include "ctl_p.h"
-
-#include "port_after.h"
-
-/* Constants. */
-
-
-/* Macros. */
-
-#define donefunc_p(ctx) ((ctx).donefunc != NULL)
-#define arpacode_p(line) (isdigit((unsigned char)(line[0])) && \
- isdigit((unsigned char)(line[1])) && \
- isdigit((unsigned char)(line[2])))
-#define arpacont_p(line) (line[3] == '-')
-#define arpadone_p(line) (line[3] == ' ' || line[3] == '\t' || \
- line[3] == '\r' || line[3] == '\0')
-
-/* Types. */
-
-enum state {
- initializing = 0, connecting, connected, destroyed
-};
-
-struct ctl_tran {
- LINK(struct ctl_tran) link;
- LINK(struct ctl_tran) wlink;
- struct ctl_cctx * ctx;
- struct ctl_buf outbuf;
- ctl_clntdone donefunc;
- void * uap;
-};
-
-struct ctl_cctx {
- enum state state;
- evContext ev;
- int sock;
- ctl_logfunc logger;
- ctl_clntdone donefunc;
- void * uap;
- evConnID coID;
- evTimerID tiID;
- evFileID rdID;
- evStreamID wrID;
- struct ctl_buf inbuf;
- struct timespec timeout;
- LIST(struct ctl_tran) tran;
- LIST(struct ctl_tran) wtran;
-};
-
-/* Forward. */
-
-static struct ctl_tran *new_tran(struct ctl_cctx *, ctl_clntdone, void *, int);
-static void start_write(struct ctl_cctx *);
-static void destroy(struct ctl_cctx *, int);
-static void error(struct ctl_cctx *);
-static void new_state(struct ctl_cctx *, enum state);
-static void conn_done(evContext, void *, int,
- const void *, int,
- const void *, int);
-static void write_done(evContext, void *, int, int);
-static void start_read(struct ctl_cctx *);
-static void stop_read(struct ctl_cctx *);
-static void readable(evContext, void *, int, int);
-static void start_timer(struct ctl_cctx *);
-static void stop_timer(struct ctl_cctx *);
-static void touch_timer(struct ctl_cctx *);
-static void timer(evContext, void *,
- struct timespec, struct timespec);
-
-/* Private data. */
-
-static const char * const state_names[] = {
- "initializing", "connecting", "connected", "destroyed"
-};
-
-/* Public. */
-
-/*
- * void
- * ctl_client()
- * create, condition, and connect to a listener on the control port.
- */
-struct ctl_cctx *
-ctl_client(evContext lev, const struct sockaddr *cap, size_t cap_len,
- const struct sockaddr *sap, size_t sap_len,
- ctl_clntdone donefunc, void *uap,
- u_int timeout, ctl_logfunc logger)
-{
- static const char me[] = "ctl_client";
- static const int on = 1;
- struct ctl_cctx *ctx;
- struct sockaddr *captmp;
-
- if (logger == NULL)
- logger = ctl_logger;
- ctx = memget(sizeof *ctx);
- if (ctx == NULL) {
- (*logger)(ctl_error, "%s: getmem: %s", me, strerror(errno));
- goto fatal;
- }
- ctx->state = initializing;
- ctx->ev = lev;
- ctx->logger = logger;
- ctx->timeout = evConsTime(timeout, 0);
- ctx->donefunc = donefunc;
- ctx->uap = uap;
- ctx->coID.opaque = NULL;
- ctx->tiID.opaque = NULL;
- ctx->rdID.opaque = NULL;
- ctx->wrID.opaque = NULL;
- buffer_init(ctx->inbuf);
- INIT_LIST(ctx->tran);
- INIT_LIST(ctx->wtran);
- ctx->sock = socket(sap->sa_family, SOCK_STREAM, PF_UNSPEC);
- if (ctx->sock > evHighestFD(ctx->ev)) {
- ctx->sock = -1;
- errno = ENOTSOCK;
- }
- if (ctx->sock < 0) {
- (*ctx->logger)(ctl_error, "%s: socket: %s",
- me, strerror(errno));
- goto fatal;
- }
- if (cap != NULL) {
- if (setsockopt(ctx->sock, SOL_SOCKET, SO_REUSEADDR,
- (const char *)&on, sizeof on) != 0) {
- (*ctx->logger)(ctl_warning,
- "%s: setsockopt(REUSEADDR): %s",
- me, strerror(errno));
- }
- DE_CONST(cap, captmp);
- if (bind(ctx->sock, captmp, cap_len) < 0) {
- (*ctx->logger)(ctl_error, "%s: bind: %s", me,
- strerror(errno));
- goto fatal;
- }
- }
- if (evConnect(lev, ctx->sock, (const struct sockaddr *)sap, sap_len,
- conn_done, ctx, &ctx->coID) < 0) {
- (*ctx->logger)(ctl_error, "%s: evConnect(fd %d): %s",
- me, ctx->sock, strerror(errno));
- fatal:
- if (ctx != NULL) {
- if (ctx->sock >= 0)
- close(ctx->sock);
- memput(ctx, sizeof *ctx);
- }
- return (NULL);
- }
- new_state(ctx, connecting);
- return (ctx);
-}
-
-/*
- * void
- * ctl_endclient(ctx)
- * close a client and release all of its resources.
- */
-void
-ctl_endclient(struct ctl_cctx *ctx) {
- if (ctx->state != destroyed)
- destroy(ctx, 0);
- memput(ctx, sizeof *ctx);
-}
-
-/*
- * int
- * ctl_command(ctx, cmd, len, donefunc, uap)
- * Queue a transaction, which will begin with sending cmd
- * and complete by calling donefunc with the answer.
- */
-int
-ctl_command(struct ctl_cctx *ctx, const char *cmd, size_t len,
- ctl_clntdone donefunc, void *uap)
-{
- struct ctl_tran *tran;
- char *pc;
- unsigned int n;
-
- switch (ctx->state) {
- case destroyed:
- errno = ENOTCONN;
- return (-1);
- case connecting:
- case connected:
- break;
- default:
- abort();
- }
- if (len >= MAX_LINELEN) {
- errno = EMSGSIZE;
- return (-1);
- }
- tran = new_tran(ctx, donefunc, uap, 1);
- if (tran == NULL)
- return (-1);
- if (ctl_bufget(&tran->outbuf, ctx->logger) < 0)
- return (-1);
- memcpy(tran->outbuf.text, cmd, len);
- tran->outbuf.used = len;
- for (pc = tran->outbuf.text, n = 0; n < tran->outbuf.used; pc++, n++)
- if (!isascii((unsigned char)*pc) ||
- !isprint((unsigned char)*pc))
- *pc = '\040';
- start_write(ctx);
- return (0);
-}
-
-/* Private. */
-
-static struct ctl_tran *
-new_tran(struct ctl_cctx *ctx, ctl_clntdone donefunc, void *uap, int w) {
- struct ctl_tran *new = memget(sizeof *new);
-
- if (new == NULL)
- return (NULL);
- new->ctx = ctx;
- buffer_init(new->outbuf);
- new->donefunc = donefunc;
- new->uap = uap;
- INIT_LINK(new, link);
- INIT_LINK(new, wlink);
- APPEND(ctx->tran, new, link);
- if (w)
- APPEND(ctx->wtran, new, wlink);
- return (new);
-}
-
-static void
-start_write(struct ctl_cctx *ctx) {
- static const char me[] = "isc/ctl_clnt::start_write";
- struct ctl_tran *tran;
- struct iovec iov[2], *iovp = iov;
- char * tmp;
-
- REQUIRE(ctx->state == connecting || ctx->state == connected);
- /* If there is a write in progress, don't try to write more yet. */
- if (ctx->wrID.opaque != NULL)
- return;
- /* If there are no trans, make sure timer is off, and we're done. */
- if (EMPTY(ctx->wtran)) {
- if (ctx->tiID.opaque != NULL)
- stop_timer(ctx);
- return;
- }
- /* Pull it off the head of the write queue. */
- tran = HEAD(ctx->wtran);
- UNLINK(ctx->wtran, tran, wlink);
- /* Since there are some trans, make sure timer is successfully "on". */
- if (ctx->tiID.opaque != NULL)
- touch_timer(ctx);
- else
- start_timer(ctx);
- if (ctx->state == destroyed)
- return;
- /* Marshall a newline-terminated message and clock it out. */
- *iovp++ = evConsIovec(tran->outbuf.text, tran->outbuf.used);
- DE_CONST("\r\n", tmp);
- *iovp++ = evConsIovec(tmp, 2);
- if (evWrite(ctx->ev, ctx->sock, iov, iovp - iov,
- write_done, tran, &ctx->wrID) < 0) {
- (*ctx->logger)(ctl_error, "%s: evWrite: %s", me,
- strerror(errno));
- error(ctx);
- return;
- }
- if (evTimeRW(ctx->ev, ctx->wrID, ctx->tiID) < 0) {
- (*ctx->logger)(ctl_error, "%s: evTimeRW: %s", me,
- strerror(errno));
- error(ctx);
- return;
- }
-}
-
-static void
-destroy(struct ctl_cctx *ctx, int notify) {
- struct ctl_tran *this, *next;
-
- if (ctx->sock != -1) {
- (void) close(ctx->sock);
- ctx->sock = -1;
- }
- switch (ctx->state) {
- case connecting:
- REQUIRE(ctx->wrID.opaque == NULL);
- REQUIRE(EMPTY(ctx->tran));
- /*
- * This test is nec'y since destroy() can be called from
- * start_read() while the state is still "connecting".
- */
- if (ctx->coID.opaque != NULL) {
- (void)evCancelConn(ctx->ev, ctx->coID);
- ctx->coID.opaque = NULL;
- }
- break;
- case connected:
- REQUIRE(ctx->coID.opaque == NULL);
- if (ctx->wrID.opaque != NULL) {
- (void)evCancelRW(ctx->ev, ctx->wrID);
- ctx->wrID.opaque = NULL;
- }
- if (ctx->rdID.opaque != NULL)
- stop_read(ctx);
- break;
- case destroyed:
- break;
- default:
- abort();
- }
- if (allocated_p(ctx->inbuf))
- ctl_bufput(&ctx->inbuf);
- for (this = HEAD(ctx->tran); this != NULL; this = next) {
- next = NEXT(this, link);
- if (allocated_p(this->outbuf))
- ctl_bufput(&this->outbuf);
- if (notify && this->donefunc != NULL)
- (*this->donefunc)(ctx, this->uap, NULL, 0);
- memput(this, sizeof *this);
- }
- if (ctx->tiID.opaque != NULL)
- stop_timer(ctx);
- new_state(ctx, destroyed);
-}
-
-static void
-error(struct ctl_cctx *ctx) {
- REQUIRE(ctx->state != destroyed);
- destroy(ctx, 1);
-}
-
-static void
-new_state(struct ctl_cctx *ctx, enum state new_state) {
- static const char me[] = "isc/ctl_clnt::new_state";
-
- (*ctx->logger)(ctl_debug, "%s: %s -> %s", me,
- state_names[ctx->state], state_names[new_state]);
- ctx->state = new_state;
-}
-
-static void
-conn_done(evContext ev, void *uap, int fd,
- const void *la, int lalen,
- const void *ra, int ralen)
-{
- static const char me[] = "isc/ctl_clnt::conn_done";
- struct ctl_cctx *ctx = uap;
- struct ctl_tran *tran;
-
- UNUSED(ev);
- UNUSED(la);
- UNUSED(lalen);
- UNUSED(ra);
- UNUSED(ralen);
-
- ctx->coID.opaque = NULL;
- if (fd < 0) {
- (*ctx->logger)(ctl_error, "%s: evConnect: %s", me,
- strerror(errno));
- error(ctx);
- return;
- }
- new_state(ctx, connected);
- tran = new_tran(ctx, ctx->donefunc, ctx->uap, 0);
- if (tran == NULL) {
- (*ctx->logger)(ctl_error, "%s: new_tran failed: %s", me,
- strerror(errno));
- error(ctx);
- return;
- }
- start_read(ctx);
- if (ctx->state == destroyed) {
- (*ctx->logger)(ctl_error, "%s: start_read failed: %s",
- me, strerror(errno));
- error(ctx);
- return;
- }
-}
-
-static void
-write_done(evContext lev, void *uap, int fd, int bytes) {
- struct ctl_tran *tran = (struct ctl_tran *)uap;
- struct ctl_cctx *ctx = tran->ctx;
-
- UNUSED(lev);
- UNUSED(fd);
-
- ctx->wrID.opaque = NULL;
- if (ctx->tiID.opaque != NULL)
- touch_timer(ctx);
- ctl_bufput(&tran->outbuf);
- start_write(ctx);
- if (bytes < 0)
- destroy(ctx, 1);
- else
- start_read(ctx);
-}
-
-static void
-start_read(struct ctl_cctx *ctx) {
- static const char me[] = "isc/ctl_clnt::start_read";
-
- REQUIRE(ctx->state == connecting || ctx->state == connected);
- REQUIRE(ctx->rdID.opaque == NULL);
- if (evSelectFD(ctx->ev, ctx->sock, EV_READ, readable, ctx,
- &ctx->rdID) < 0)
- {
- (*ctx->logger)(ctl_error, "%s: evSelect(fd %d): %s", me,
- ctx->sock, strerror(errno));
- error(ctx);
- return;
- }
-}
-
-static void
-stop_read(struct ctl_cctx *ctx) {
- REQUIRE(ctx->coID.opaque == NULL);
- REQUIRE(ctx->rdID.opaque != NULL);
- (void)evDeselectFD(ctx->ev, ctx->rdID);
- ctx->rdID.opaque = NULL;
-}
-
-static void
-readable(evContext ev, void *uap, int fd, int evmask) {
- static const char me[] = "isc/ctl_clnt::readable";
- struct ctl_cctx *ctx = uap;
- struct ctl_tran *tran;
- ssize_t n;
- char *eos;
-
- UNUSED(ev);
-
- REQUIRE(ctx != NULL);
- REQUIRE(fd >= 0);
- REQUIRE(evmask == EV_READ);
- REQUIRE(ctx->state == connected);
- REQUIRE(!EMPTY(ctx->tran));
- tran = HEAD(ctx->tran);
- if (!allocated_p(ctx->inbuf) &&
- ctl_bufget(&ctx->inbuf, ctx->logger) < 0) {
- (*ctx->logger)(ctl_error, "%s: can't get an input buffer", me);
- error(ctx);
- return;
- }
- n = read(ctx->sock, ctx->inbuf.text + ctx->inbuf.used,
- MAX_LINELEN - ctx->inbuf.used);
- if (n <= 0) {
- (*ctx->logger)(ctl_warning, "%s: read: %s", me,
- (n == 0) ? "Unexpected EOF" : strerror(errno));
- error(ctx);
- return;
- }
- if (ctx->tiID.opaque != NULL)
- touch_timer(ctx);
- ctx->inbuf.used += n;
- (*ctx->logger)(ctl_debug, "%s: read %d, used %d", me,
- n, ctx->inbuf.used);
- again:
- eos = memchr(ctx->inbuf.text, '\n', ctx->inbuf.used);
- if (eos != NULL && eos != ctx->inbuf.text && eos[-1] == '\r') {
- int done = 0;
-
- eos[-1] = '\0';
- if (!arpacode_p(ctx->inbuf.text)) {
- /* XXX Doesn't FTP do this sometimes? Is it legal? */
- (*ctx->logger)(ctl_error, "%s: no arpa code (%s)", me,
- ctx->inbuf.text);
- error(ctx);
- return;
- }
- if (arpadone_p(ctx->inbuf.text))
- done = 1;
- else if (arpacont_p(ctx->inbuf.text))
- done = 0;
- else {
- /* XXX Doesn't FTP do this sometimes? Is it legal? */
- (*ctx->logger)(ctl_error, "%s: no arpa flag (%s)", me,
- ctx->inbuf.text);
- error(ctx);
- return;
- }
- (*tran->donefunc)(ctx, tran->uap, ctx->inbuf.text,
- (done ? 0 : CTL_MORE));
- ctx->inbuf.used -= ((eos - ctx->inbuf.text) + 1);
- if (ctx->inbuf.used == 0)
- ctl_bufput(&ctx->inbuf);
- else
- memmove(ctx->inbuf.text, eos + 1, ctx->inbuf.used);
- if (done) {
- UNLINK(ctx->tran, tran, link);
- memput(tran, sizeof *tran);
- stop_read(ctx);
- start_write(ctx);
- return;
- }
- if (allocated_p(ctx->inbuf))
- goto again;
- return;
- }
- if (ctx->inbuf.used == MAX_LINELEN) {
- (*ctx->logger)(ctl_error, "%s: line too long (%-10s...)", me,
- ctx->inbuf.text);
- error(ctx);
- }
-}
-
-/* Timer related stuff. */
-
-static void
-start_timer(struct ctl_cctx *ctx) {
- static const char me[] = "isc/ctl_clnt::start_timer";
-
- REQUIRE(ctx->tiID.opaque == NULL);
- if (evSetIdleTimer(ctx->ev, timer, ctx, ctx->timeout, &ctx->tiID) < 0){
- (*ctx->logger)(ctl_error, "%s: evSetIdleTimer: %s", me,
- strerror(errno));
- error(ctx);
- return;
- }
-}
-
-static void
-stop_timer(struct ctl_cctx *ctx) {
- static const char me[] = "isc/ctl_clnt::stop_timer";
-
- REQUIRE(ctx->tiID.opaque != NULL);
- if (evClearIdleTimer(ctx->ev, ctx->tiID) < 0) {
- (*ctx->logger)(ctl_error, "%s: evClearIdleTimer: %s", me,
- strerror(errno));
- error(ctx);
- return;
- }
- ctx->tiID.opaque = NULL;
-}
-
-static void
-touch_timer(struct ctl_cctx *ctx) {
- REQUIRE(ctx->tiID.opaque != NULL);
-
- evTouchIdleTimer(ctx->ev, ctx->tiID);
-}
-
-static void
-timer(evContext ev, void *uap, struct timespec due, struct timespec itv) {
- static const char me[] = "isc/ctl_clnt::timer";
- struct ctl_cctx *ctx = uap;
-
- UNUSED(ev);
- UNUSED(due);
- UNUSED(itv);
-
- ctx->tiID.opaque = NULL;
- (*ctx->logger)(ctl_error, "%s: timeout after %u seconds while %s", me,
- ctx->timeout.tv_sec, state_names[ctx->state]);
- error(ctx);
-}
diff --git a/contrib/bind/lib/isc/ctl_p.c b/contrib/bind/lib/isc/ctl_p.c
deleted file mode 100644
index 4f22f9f..0000000
--- a/contrib/bind/lib/isc/ctl_p.c
+++ /dev/null
@@ -1,186 +0,0 @@
-#if !defined(lint) && !defined(SABER)
-static const char rcsid[] = "$Id: ctl_p.c,v 8.8 2001/05/29 05:49:26 marka Exp $";
-#endif /* not lint */
-
-/*
- * Copyright (c) 1998,1999 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.
- */
-
-/* Extern. */
-
-#include "port_before.h"
-
-#include <sys/param.h>
-#include <sys/file.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <arpa/inet.h>
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-
-#include <isc/assertions.h>
-#include <isc/eventlib.h>
-#include <isc/logging.h>
-#include <isc/memcluster.h>
-#include <isc/ctl.h>
-
-#include "ctl_p.h"
-
-#include "port_after.h"
-
-/* Constants. */
-
-const char * const ctl_sevnames[] = {
- "debug", "warning", "error"
-};
-
-/* Public. */
-
-/*
- * ctl_logger()
- * if ctl_startup()'s caller didn't specify a logger, this one
- * is used. this pollutes stderr with all kinds of trash so it will
- * probably never be used in real applications.
- */
-void
-ctl_logger(enum ctl_severity severity, const char *format, ...) {
- va_list ap;
- static const char me[] = "ctl_logger";
-
- fprintf(stderr, "%s(%s): ", me, ctl_sevnames[severity]);
- va_start(ap, format);
- vfprintf(stderr, format, ap);
- va_end(ap);
- fputc('\n', stderr);
-}
-
-int
-ctl_bufget(struct ctl_buf *buf, ctl_logfunc logger) {
- static const char me[] = "ctl_bufget";
-
- REQUIRE(!allocated_p(*buf) && buf->used == 0);
- buf->text = memget(MAX_LINELEN);
- if (!allocated_p(*buf)) {
- (*logger)(ctl_error, "%s: getmem: %s", me, strerror(errno));
- return (-1);
- }
- buf->used = 0;
- return (0);
-}
-
-void
-ctl_bufput(struct ctl_buf *buf) {
-
- REQUIRE(allocated_p(*buf));
- memput(buf->text, MAX_LINELEN);
- buf->text = NULL;
- buf->used = 0;
-}
-
-const char *
-ctl_sa_ntop(const struct sockaddr *sa,
- char *buf, size_t size,
- ctl_logfunc logger)
-{
- static const char me[] = "ctl_sa_ntop";
- static const char punt[] = "[0].-1";
- char tmp[INET6_ADDRSTRLEN];
-
- switch (sa->sa_family) {
- case AF_INET6: {
- const struct sockaddr_in6 *in6 =
- (const struct sockaddr_in6 *) sa;
-
- if (inet_ntop(in6->sin6_family, &in6->sin6_addr, tmp, sizeof tmp)
- == NULL) {
- (*logger)(ctl_error, "%s: inet_ntop(%u %04x): %s",
- me, in6->sin6_family,
- in6->sin6_port, strerror(errno));
- return (punt);
- }
- if (strlen(tmp) + sizeof "[].65535" > size) {
- (*logger)(ctl_error, "%s: buffer overflow", me);
- return (punt);
- }
- (void) sprintf(buf, "[%s].%u", tmp, ntohs(in6->sin6_port));
- return (buf);
- }
- case AF_INET: {
- const struct sockaddr_in *in =
- (const struct sockaddr_in *) sa;
-
- if (inet_ntop(in->sin_family, &in->sin_addr, tmp, sizeof tmp)
- == NULL) {
- (*logger)(ctl_error, "%s: inet_ntop(%u %04x %08x): %s",
- me, in->sin_family,
- in->sin_port, in->sin_addr.s_addr,
- strerror(errno));
- return (punt);
- }
- if (strlen(tmp) + sizeof "[].65535" > size) {
- (*logger)(ctl_error, "%s: buffer overflow", me);
- return (punt);
- }
- (void) sprintf(buf, "[%s].%u", tmp, ntohs(in->sin_port));
- return (buf);
- }
-#ifndef NO_SOCKADDR_UN
- case AF_UNIX: {
- const struct sockaddr_un *un =
- (const struct sockaddr_un *) sa;
- unsigned int x = sizeof un->sun_path;
-
- if (x > size)
- x = size;
- strncpy(buf, un->sun_path, x - 1);
- buf[x - 1] = '\0';
- return (buf);
- }
-#endif
- default:
- return (punt);
- }
-}
-
-void
-ctl_sa_copy(const struct sockaddr *src, struct sockaddr *dst) {
- switch (src->sa_family) {
- case AF_INET6:
- *((struct sockaddr_in6 *)dst) =
- *((const struct sockaddr_in6 *)src);
- break;
- case AF_INET:
- *((struct sockaddr_in *)dst) =
- *((const struct sockaddr_in *)src);
- break;
-#ifndef NO_SOCKADDR_UN
- case AF_UNIX:
- *((struct sockaddr_un *)dst) =
- *((const struct sockaddr_un *)src);
- break;
-#endif
- default:
- *dst = *src;
- break;
- }
-}
diff --git a/contrib/bind/lib/isc/ctl_p.h b/contrib/bind/lib/isc/ctl_p.h
deleted file mode 100644
index 42aade7..0000000
--- a/contrib/bind/lib/isc/ctl_p.h
+++ /dev/null
@@ -1,26 +0,0 @@
-struct ctl_buf {
- char * text;
- size_t used;
-};
-
-#define MAX_LINELEN 990 /* Like SMTP. */
-#ifndef NO_SOCKADDR_UN
-#define MAX_NTOP PATH_MAX
-#else
-#define MAX_NTOP (sizeof "[255.255.255.255].65535")
-#endif
-
-#define allocated_p(Buf) ((Buf).text != NULL)
-#define buffer_init(Buf) ((Buf).text = 0, (Buf.used) = 0)
-
-#define ctl_bufget __ctl_bufget
-#define ctl_bufput __ctl_bufput
-#define ctl_sa_ntop __ctl_sa_ntop
-#define ctl_sa_copy __ctl_sa_copy
-
-int ctl_bufget(struct ctl_buf *, ctl_logfunc);
-void ctl_bufput(struct ctl_buf *);
-const char * ctl_sa_ntop(const struct sockaddr *, char *, size_t,
- ctl_logfunc);
-void ctl_sa_copy(const struct sockaddr *,
- struct sockaddr *);
diff --git a/contrib/bind/lib/isc/ctl_srvr.c b/contrib/bind/lib/isc/ctl_srvr.c
deleted file mode 100644
index 835bcd4..0000000
--- a/contrib/bind/lib/isc/ctl_srvr.c
+++ /dev/null
@@ -1,780 +0,0 @@
-#if !defined(lint) && !defined(SABER)
-static const char rcsid[] = "$Id: ctl_srvr.c,v 8.26 2002/07/08 05:10:25 marka Exp $";
-#endif /* not lint */
-
-/*
- * Copyright (c) 1998,1999 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.
- */
-
-/* Extern. */
-
-#include "port_before.h"
-
-#include <sys/param.h>
-#include <sys/file.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <arpa/inet.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-#include <fcntl.h>
-
-#include <isc/assertions.h>
-#include <isc/ctl.h>
-#include <isc/eventlib.h>
-#include <isc/list.h>
-#include <isc/logging.h>
-#include <isc/memcluster.h>
-
-#include "ctl_p.h"
-
-#include "port_after.h"
-
-#ifdef SPRINTF_CHAR
-# define SPRINTF(x) strlen(sprintf/**/x)
-#else
-# define SPRINTF(x) ((size_t)sprintf x)
-#endif
-
-/* Macros. */
-
-#define lastverb_p(verb) (verb->name == NULL || verb->func == NULL)
-#define address_expr ctl_sa_ntop((struct sockaddr *)&sess->sa, \
- tmp, sizeof tmp, ctx->logger)
-
-/* Types. */
-
-enum state {
- available = 0, initializing, writing, reading, reading_data,
- processing, idling, quitting, closing
-};
-
-union sa_un {
- struct sockaddr_in in;
-#ifndef NO_SOCKADDR_UN
- struct sockaddr_un un;
-#endif
-};
-
-struct ctl_sess {
- LINK(struct ctl_sess) link;
- struct ctl_sctx * ctx;
- enum state state;
- int sock;
- union sa_un sa;
- evFileID rdID;
- evStreamID wrID;
- evTimerID rdtiID;
- evTimerID wrtiID;
- struct ctl_buf inbuf;
- struct ctl_buf outbuf;
- const struct ctl_verb * verb;
- u_int helpcode;
- const void * respctx;
- u_int respflags;
- ctl_srvrdone donefunc;
- void * uap;
- void * csctx;
-};
-
-struct ctl_sctx {
- evContext ev;
- void * uctx;
- u_int unkncode;
- u_int timeoutcode;
- const struct ctl_verb * verbs;
- const struct ctl_verb * connverb;
- int sock;
- int max_sess;
- int cur_sess;
- struct timespec timeout;
- ctl_logfunc logger;
- evConnID acID;
- LIST(struct ctl_sess) sess;
-};
-
-/* Forward. */
-
-static void ctl_accept(evContext, void *, int,
- const void *, int,
- const void *, int);
-static void ctl_close(struct ctl_sess *);
-static void ctl_new_state(struct ctl_sess *,
- enum state,
- const char *);
-static void ctl_start_read(struct ctl_sess *);
-static void ctl_stop_read(struct ctl_sess *);
-static void ctl_readable(evContext, void *, int, int);
-static void ctl_rdtimeout(evContext, void *,
- struct timespec,
- struct timespec);
-static void ctl_wrtimeout(evContext, void *,
- struct timespec,
- struct timespec);
-static void ctl_docommand(struct ctl_sess *);
-static void ctl_writedone(evContext, void *, int, int);
-static void ctl_morehelp(struct ctl_sctx *,
- struct ctl_sess *,
- const struct ctl_verb *,
- const char *,
- u_int, const void *, void *);
-static void ctl_signal_done(struct ctl_sctx *,
- struct ctl_sess *);
-
-/* Private data. */
-
-static const char * state_names[] = {
- "available", "initializing", "writing", "reading",
- "reading_data", "processing", "idling", "quitting", "closing"
-};
-
-static const char space[] = " ";
-
-static const struct ctl_verb fakehelpverb = {
- "fakehelp", ctl_morehelp , NULL
-};
-
-/* Public. */
-
-/*
- * void
- * ctl_server()
- * create, condition, and start a listener on the control port.
- */
-struct ctl_sctx *
-ctl_server(evContext lev, const struct sockaddr *sap, size_t sap_len,
- const struct ctl_verb *verbs,
- u_int unkncode, u_int timeoutcode,
- u_int timeout, int backlog, int max_sess,
- ctl_logfunc logger, void *uctx)
-{
- static const char me[] = "ctl_server";
- static const int on = 1;
- const struct ctl_verb *connverb;
- struct ctl_sctx *ctx;
- int save_errno;
-
- if (logger == NULL)
- logger = ctl_logger;
- for (connverb = verbs;
- connverb->name != NULL && connverb->func != NULL;
- connverb++)
- if (connverb->name[0] == '\0')
- break;
- if (connverb->func == NULL) {
- (*logger)(ctl_error, "%s: no connection verb found", me);
- return (NULL);
- }
- ctx = memget(sizeof *ctx);
- if (ctx == NULL) {
- (*logger)(ctl_error, "%s: getmem: %s", me, strerror(errno));
- return (NULL);
- }
- ctx->ev = lev;
- ctx->uctx = uctx;
- ctx->unkncode = unkncode;
- ctx->timeoutcode = timeoutcode;
- ctx->verbs = verbs;
- ctx->timeout = evConsTime(timeout, 0);
- ctx->logger = logger;
- ctx->connverb = connverb;
- ctx->max_sess = max_sess;
- ctx->cur_sess = 0;
- INIT_LIST(ctx->sess);
- ctx->sock = socket(sap->sa_family, SOCK_STREAM, PF_UNSPEC);
- if (ctx->sock > evHighestFD(ctx->ev)) {
- ctx->sock = -1;
- errno = ENOTSOCK;
- }
- if (ctx->sock < 0) {
- save_errno = errno;
- (*ctx->logger)(ctl_error, "%s: socket: %s",
- me, strerror(errno));
- memput(ctx, sizeof *ctx);
- errno = save_errno;
- return (NULL);
- }
- if (ctx->sock > evHighestFD(lev)) {
- close(ctx->sock);
- (*ctx->logger)(ctl_error, "%s: file descriptor > evHighestFD");
- errno = ENFILE;
- memput(ctx, sizeof *ctx);
- return (NULL);
- }
-#ifdef NO_UNIX_REUSEADDR
- if (sap->sa_family != AF_UNIX)
-#endif
- if (setsockopt(ctx->sock, SOL_SOCKET, SO_REUSEADDR,
- (const char *)&on, sizeof on) != 0) {
- (*ctx->logger)(ctl_warning,
- "%s: setsockopt(REUSEADDR): %s",
- me, strerror(errno));
- }
- if (bind(ctx->sock, sap, sap_len) < 0) {
- char tmp[MAX_NTOP];
- save_errno = errno;
- (*ctx->logger)(ctl_error, "%s: bind: %s: %s",
- me, ctl_sa_ntop((const struct sockaddr *)sap,
- tmp, sizeof tmp, ctx->logger),
- strerror(save_errno));
- close(ctx->sock);
- memput(ctx, sizeof *ctx);
- errno = save_errno;
- return (NULL);
- }
- if (fcntl(ctx->sock, F_SETFD, 1) < 0) {
- (*ctx->logger)(ctl_warning, "%s: fcntl: %s", me,
- strerror(errno));
- }
- if (evListen(lev, ctx->sock, backlog, ctl_accept, ctx,
- &ctx->acID) < 0) {
- save_errno = errno;
- (*ctx->logger)(ctl_error, "%s: evListen(fd %d): %s",
- me, ctx->sock, strerror(errno));
- close(ctx->sock);
- memput(ctx, sizeof *ctx);
- errno = save_errno;
- return (NULL);
- }
- (*ctx->logger)(ctl_debug, "%s: new ctx %p, sock %d",
- me, ctx, ctx->sock);
- return (ctx);
-}
-
-/*
- * void
- * ctl_endserver(ctx)
- * if the control listener is open, close it. clean out all eventlib
- * stuff. close all active sessions.
- */
-void
-ctl_endserver(struct ctl_sctx *ctx) {
- static const char me[] = "ctl_endserver";
- struct ctl_sess *this, *next;
-
- (*ctx->logger)(ctl_debug, "%s: ctx %p, sock %d, acID %p, sess %p",
- me, ctx, ctx->sock, ctx->acID.opaque, ctx->sess);
- if (ctx->acID.opaque != NULL) {
- (void)evCancelConn(ctx->ev, ctx->acID);
- ctx->acID.opaque = NULL;
- }
- if (ctx->sock != -1) {
- (void) close(ctx->sock);
- ctx->sock = -1;
- }
- for (this = HEAD(ctx->sess); this != NULL; this = next) {
- next = NEXT(this, link);
- ctl_close(this);
- }
- memput(ctx, sizeof *ctx);
-}
-
-/*
- * If body is non-NULL then it we add a "." line after it.
- * Caller must have escaped lines with leading ".".
- */
-void
-ctl_response(struct ctl_sess *sess, u_int code, const char *text,
- u_int flags, const void *respctx, ctl_srvrdone donefunc,
- void *uap, const char *body, size_t bodylen)
-{
- static const char me[] = "ctl_response";
- struct iovec iov[3], *iovp = iov;
- struct ctl_sctx *ctx = sess->ctx;
- char tmp[MAX_NTOP], *pc;
- int n;
-
- REQUIRE(sess->state == initializing ||
- sess->state == processing ||
- sess->state == reading_data ||
- sess->state == writing);
- REQUIRE(sess->wrtiID.opaque == NULL);
- REQUIRE(sess->wrID.opaque == NULL);
- ctl_new_state(sess, writing, me);
- sess->donefunc = donefunc;
- sess->uap = uap;
- if (!allocated_p(sess->outbuf) &&
- ctl_bufget(&sess->outbuf, ctx->logger) < 0) {
- (*ctx->logger)(ctl_error, "%s: %s: cant get an output buffer",
- me, address_expr);
- goto untimely;
- }
- if (sizeof "000-\r\n" + strlen(text) > MAX_LINELEN) {
- (*ctx->logger)(ctl_error, "%s: %s: output buffer ovf, closing",
- me, address_expr);
- goto untimely;
- }
- sess->outbuf.used = SPRINTF((sess->outbuf.text, "%03d%c%s\r\n",
- code, (flags & CTL_MORE) != 0 ? '-' : ' ',
- text));
- for (pc = sess->outbuf.text, n = 0;
- n < (int)sess->outbuf.used-2; pc++, n++)
- if (!isascii((unsigned char)*pc) ||
- !isprint((unsigned char)*pc))
- *pc = '\040';
- *iovp++ = evConsIovec(sess->outbuf.text, sess->outbuf.used);
- if (body != NULL) {
- char *tmp;
- DE_CONST(body, tmp);
- *iovp++ = evConsIovec(tmp, bodylen);
- DE_CONST(".\r\n", tmp);
- *iovp++ = evConsIovec(tmp, 3);
- }
- (*ctx->logger)(ctl_debug, "%s: [%d] %s", me,
- sess->outbuf.used, sess->outbuf.text);
- if (evWrite(ctx->ev, sess->sock, iov, iovp - iov,
- ctl_writedone, sess, &sess->wrID) < 0) {
- (*ctx->logger)(ctl_error, "%s: %s: evWrite: %s", me,
- address_expr, strerror(errno));
- goto untimely;
- }
- if (evSetIdleTimer(ctx->ev, ctl_wrtimeout, sess, ctx->timeout,
- &sess->wrtiID) < 0)
- {
- (*ctx->logger)(ctl_error, "%s: %s: evSetIdleTimer: %s", me,
- address_expr, strerror(errno));
- goto untimely;
- }
- if (evTimeRW(ctx->ev, sess->wrID, sess->wrtiID) < 0) {
- (*ctx->logger)(ctl_error, "%s: %s: evTimeRW: %s", me,
- address_expr, strerror(errno));
- untimely:
- ctl_signal_done(ctx, sess);
- ctl_close(sess);
- return;
- }
- sess->respctx = respctx;
- sess->respflags = flags;
-}
-
-void
-ctl_sendhelp(struct ctl_sess *sess, u_int code) {
- static const char me[] = "ctl_sendhelp";
- struct ctl_sctx *ctx = sess->ctx;
-
- sess->helpcode = code;
- sess->verb = &fakehelpverb;
- ctl_morehelp(ctx, sess, NULL, me, CTL_MORE,
- (const void *)ctx->verbs, NULL);
-}
-
-void *
-ctl_getcsctx(struct ctl_sess *sess) {
- return (sess->csctx);
-}
-
-void *
-ctl_setcsctx(struct ctl_sess *sess, void *csctx) {
- void *old = sess->csctx;
-
- sess->csctx = csctx;
- return (old);
-}
-
-/* Private functions. */
-
-static void
-ctl_accept(evContext lev, void *uap, int fd,
- const void *lav, int lalen,
- const void *rav, int ralen)
-{
- static const char me[] = "ctl_accept";
- struct ctl_sctx *ctx = uap;
- struct ctl_sess *sess = NULL;
- char tmp[MAX_NTOP];
-
- UNUSED(lev);
- UNUSED(lalen);
- UNUSED(ralen);
-
- if (fd < 0) {
- (*ctx->logger)(ctl_error, "%s: accept: %s",
- me, strerror(errno));
- return;
- }
- if (ctx->cur_sess == ctx->max_sess) {
- (*ctx->logger)(ctl_error, "%s: %s: too many control sessions",
- me, ctl_sa_ntop((const struct sockaddr *)rav,
- tmp, sizeof tmp,
- ctx->logger));
- (void) close(fd);
- return;
- }
- sess = memget(sizeof *sess);
- if (sess == NULL) {
- (*ctx->logger)(ctl_error, "%s: memget: %s", me,
- strerror(errno));
- (void) close(fd);
- return;
- }
- if (fcntl(fd, F_SETFD, 1) < 0) {
- (*ctx->logger)(ctl_warning, "%s: fcntl: %s", me,
- strerror(errno));
- }
- ctx->cur_sess++;
- INIT_LINK(sess, link);
- APPEND(ctx->sess, sess, link);
- sess->ctx = ctx;
- sess->sock = fd;
- sess->wrID.opaque = NULL;
- sess->rdID.opaque = NULL;
- sess->wrtiID.opaque = NULL;
- sess->rdtiID.opaque = NULL;
- sess->respctx = NULL;
- sess->csctx = NULL;
- if (((const struct sockaddr *)rav)->sa_family == AF_UNIX)
- ctl_sa_copy((const struct sockaddr *)lav,
- (struct sockaddr *)&sess->sa);
- else
- ctl_sa_copy((const struct sockaddr *)rav,
- (struct sockaddr *)&sess->sa);
- sess->donefunc = NULL;
- buffer_init(sess->inbuf);
- buffer_init(sess->outbuf);
- sess->state = available;
- ctl_new_state(sess, initializing, me);
- sess->verb = ctx->connverb;
- (*ctx->logger)(ctl_debug, "%s: %s: accepting (fd %d)",
- me, address_expr, sess->sock);
- (*ctx->connverb->func)(ctx, sess, ctx->connverb, "", 0,
- (const struct sockaddr *)rav, ctx->uctx);
-}
-
-static void
-ctl_new_state(struct ctl_sess *sess, enum state new_state, const char *reason)
-{
- static const char me[] = "ctl_new_state";
- struct ctl_sctx *ctx = sess->ctx;
- char tmp[MAX_NTOP];
-
- (*ctx->logger)(ctl_debug, "%s: %s: %s -> %s (%s)",
- me, address_expr,
- state_names[sess->state],
- state_names[new_state], reason);
- sess->state = new_state;
-}
-
-static void
-ctl_close(struct ctl_sess *sess) {
- static const char me[] = "ctl_close";
- struct ctl_sctx *ctx = sess->ctx;
- char tmp[MAX_NTOP];
-
- REQUIRE(sess->state == initializing ||
- sess->state == writing ||
- sess->state == reading ||
- sess->state == processing ||
- sess->state == reading_data ||
- sess->state == idling);
- REQUIRE(sess->sock != -1);
- if (sess->state == reading || sess->state == reading_data)
- ctl_stop_read(sess);
- else if (sess->state == writing) {
- if (sess->wrID.opaque != NULL) {
- (void) evCancelRW(ctx->ev, sess->wrID);
- sess->wrID.opaque = NULL;
- }
- if (sess->wrtiID.opaque != NULL) {
- (void) evClearIdleTimer(ctx->ev, sess->wrtiID);
- sess->wrtiID.opaque = NULL;
- }
- }
- ctl_new_state(sess, closing, me);
- (void) close(sess->sock);
- if (allocated_p(sess->inbuf))
- ctl_bufput(&sess->inbuf);
- if (allocated_p(sess->outbuf))
- ctl_bufput(&sess->outbuf);
- (*ctx->logger)(ctl_debug, "%s: %s: closed (fd %d)",
- me, address_expr, sess->sock);
- UNLINK(ctx->sess, sess, link);
- memput(sess, sizeof *sess);
- ctx->cur_sess--;
-}
-
-static void
-ctl_start_read(struct ctl_sess *sess) {
- static const char me[] = "ctl_start_read";
- struct ctl_sctx *ctx = sess->ctx;
- char tmp[MAX_NTOP];
-
- REQUIRE(sess->state == initializing ||
- sess->state == writing ||
- sess->state == processing ||
- sess->state == idling);
- REQUIRE(sess->rdtiID.opaque == NULL);
- REQUIRE(sess->rdID.opaque == NULL);
- sess->inbuf.used = 0;
- if (evSetIdleTimer(ctx->ev, ctl_rdtimeout, sess, ctx->timeout,
- &sess->rdtiID) < 0)
- {
- (*ctx->logger)(ctl_error, "%s: %s: evSetIdleTimer: %s", me,
- address_expr, strerror(errno));
- ctl_close(sess);
- return;
- }
- if (evSelectFD(ctx->ev, sess->sock, EV_READ,
- ctl_readable, sess, &sess->rdID) < 0) {
- (*ctx->logger)(ctl_error, "%s: %s: evSelectFD: %s", me,
- address_expr, strerror(errno));
- return;
- }
- ctl_new_state(sess, reading, me);
-}
-
-static void
-ctl_stop_read(struct ctl_sess *sess) {
- static const char me[] = "ctl_stop_read";
- struct ctl_sctx *ctx = sess->ctx;
-
- REQUIRE(sess->state == reading || sess->state == reading_data);
- REQUIRE(sess->rdID.opaque != NULL);
- (void) evDeselectFD(ctx->ev, sess->rdID);
- sess->rdID.opaque = NULL;
- if (sess->rdtiID.opaque != NULL) {
- (void) evClearIdleTimer(ctx->ev, sess->rdtiID);
- sess->rdtiID.opaque = NULL;
- }
- ctl_new_state(sess, idling, me);
-}
-
-static void
-ctl_readable(evContext lev, void *uap, int fd, int evmask) {
- static const char me[] = "ctl_readable";
- struct ctl_sess *sess = uap;
- struct ctl_sctx *ctx = sess->ctx;
- char *eos, tmp[MAX_NTOP];
- ssize_t n;
-
- REQUIRE(sess != NULL);
- REQUIRE(fd >= 0);
- REQUIRE(evmask == EV_READ);
- REQUIRE(sess->state == reading || sess->state == reading_data);
- evTouchIdleTimer(lev, sess->rdtiID);
- if (!allocated_p(sess->inbuf) &&
- ctl_bufget(&sess->inbuf, ctx->logger) < 0) {
- (*ctx->logger)(ctl_error, "%s: %s: cant get an input buffer",
- me, address_expr);
- ctl_close(sess);
- return;
- }
- n = read(sess->sock, sess->inbuf.text + sess->inbuf.used,
- MAX_LINELEN - sess->inbuf.used);
- if (n <= 0) {
- (*ctx->logger)(ctl_debug, "%s: %s: read: %s",
- me, address_expr,
- (n == 0) ? "Unexpected EOF" : strerror(errno));
- ctl_close(sess);
- return;
- }
- sess->inbuf.used += n;
- eos = memchr(sess->inbuf.text, '\n', sess->inbuf.used);
- if (eos != NULL && eos != sess->inbuf.text && eos[-1] == '\r') {
- eos[-1] = '\0';
- if ((sess->respflags & CTL_DATA) != 0) {
- INSIST(sess->verb != NULL);
- (*sess->verb->func)(sess->ctx, sess, sess->verb,
- sess->inbuf.text,
- CTL_DATA, sess->respctx,
- sess->ctx->uctx);
- } else {
- ctl_stop_read(sess);
- ctl_docommand(sess);
- }
- sess->inbuf.used -= ((eos - sess->inbuf.text) + 1);
- if (sess->inbuf.used == 0)
- ctl_bufput(&sess->inbuf);
- else
- memmove(sess->inbuf.text, eos + 1, sess->inbuf.used);
- return;
- }
- if (sess->inbuf.used == MAX_LINELEN) {
- (*ctx->logger)(ctl_error, "%s: %s: line too long, closing",
- me, address_expr);
- ctl_close(sess);
- }
-}
-
-static void
-ctl_wrtimeout(evContext lev, void *uap,
- struct timespec due,
- struct timespec itv)
-{
- static const char me[] = "ctl_wrtimeout";
- struct ctl_sess *sess = uap;
- struct ctl_sctx *ctx = sess->ctx;
- char tmp[MAX_NTOP];
-
- UNUSED(lev);
- UNUSED(due);
- UNUSED(itv);
-
- REQUIRE(sess->state == writing);
- sess->wrtiID.opaque = NULL;
- (*ctx->logger)(ctl_warning, "%s: %s: write timeout, closing",
- me, address_expr);
- if (sess->wrID.opaque != NULL) {
- (void) evCancelRW(ctx->ev, sess->wrID);
- sess->wrID.opaque = NULL;
- }
- ctl_signal_done(ctx, sess);
- ctl_new_state(sess, processing, me);
- ctl_close(sess);
-}
-
-static void
-ctl_rdtimeout(evContext lev, void *uap,
- struct timespec due,
- struct timespec itv)
-{
- static const char me[] = "ctl_rdtimeout";
- struct ctl_sess *sess = uap;
- struct ctl_sctx *ctx = sess->ctx;
- char tmp[MAX_NTOP];
-
- UNUSED(lev);
- UNUSED(due);
- UNUSED(itv);
-
- REQUIRE(sess->state == reading);
- sess->rdtiID.opaque = NULL;
- (*ctx->logger)(ctl_warning, "%s: %s: timeout, closing",
- me, address_expr);
- if (sess->state == reading || sess->state == reading_data)
- ctl_stop_read(sess);
- ctl_signal_done(ctx, sess);
- ctl_new_state(sess, processing, me);
- ctl_response(sess, ctx->timeoutcode, "Timeout.", CTL_EXIT, NULL,
- NULL, NULL, NULL, 0);
-}
-
-static void
-ctl_docommand(struct ctl_sess *sess) {
- static const char me[] = "ctl_docommand";
- char *name, *rest, tmp[MAX_NTOP];
- struct ctl_sctx *ctx = sess->ctx;
- const struct ctl_verb *verb;
-
- REQUIRE(allocated_p(sess->inbuf));
- (*ctx->logger)(ctl_debug, "%s: %s: \"%s\" [%u]",
- me, address_expr,
- sess->inbuf.text, (u_int)sess->inbuf.used);
- ctl_new_state(sess, processing, me);
- name = sess->inbuf.text + strspn(sess->inbuf.text, space);
- rest = name + strcspn(name, space);
- if (*rest != '\0') {
- *rest++ = '\0';
- rest += strspn(rest, space);
- }
- for (verb = ctx->verbs;
- verb != NULL && verb->name != NULL && verb->func != NULL;
- verb++)
- if (verb->name[0] != '\0' && strcasecmp(name, verb->name) == 0)
- break;
- if (verb != NULL && verb->name != NULL && verb->func != NULL) {
- sess->verb = verb;
- (*verb->func)(ctx, sess, verb, rest, 0, NULL, ctx->uctx);
- } else {
- char buf[1100];
-
- if (sizeof "Unrecognized command \"\" (args \"\")" +
- strlen(name) + strlen(rest) > sizeof buf)
- strcpy(buf, "Unrecognized command (buf ovf)");
- else
- sprintf(buf,
- "Unrecognized command \"%s\" (args \"%s\")",
- name, rest);
- ctl_response(sess, ctx->unkncode, buf, 0, NULL, NULL, NULL,
- NULL, 0);
- }
-}
-
-static void
-ctl_writedone(evContext lev, void *uap, int fd, int bytes) {
- static const char me[] = "ctl_writedone";
- struct ctl_sess *sess = uap;
- struct ctl_sctx *ctx = sess->ctx;
- char tmp[MAX_NTOP];
- int save_errno = errno;
-
- UNUSED(lev);
- UNUSED(uap);
-
- REQUIRE(sess->state == writing);
- REQUIRE(fd == sess->sock);
- REQUIRE(sess->wrtiID.opaque != NULL);
- sess->wrID.opaque = NULL;
- (void) evClearIdleTimer(ctx->ev, sess->wrtiID);
- sess->wrtiID.opaque = NULL;
- if (bytes < 0) {
- (*ctx->logger)(ctl_error, "%s: %s: %s",
- me, address_expr, strerror(save_errno));
- ctl_close(sess);
- return;
- }
-
- INSIST(allocated_p(sess->outbuf));
- ctl_bufput(&sess->outbuf);
- if ((sess->respflags & CTL_EXIT) != 0) {
- ctl_signal_done(ctx, sess);
- ctl_close(sess);
- return;
- } else if ((sess->respflags & CTL_MORE) != 0) {
- INSIST(sess->verb != NULL);
- (*sess->verb->func)(sess->ctx, sess, sess->verb, "",
- CTL_MORE, sess->respctx, sess->ctx->uctx);
- } else {
- ctl_signal_done(ctx, sess);
- ctl_start_read(sess);
- }
-}
-
-static void
-ctl_morehelp(struct ctl_sctx *ctx, struct ctl_sess *sess,
- const struct ctl_verb *verb, const char *text,
- u_int respflags, const void *respctx, void *uctx)
-{
- const struct ctl_verb *this = respctx, *next = this + 1;
-
- UNUSED(ctx);
- UNUSED(verb);
- UNUSED(text);
- UNUSED(uctx);
-
- REQUIRE(!lastverb_p(this));
- REQUIRE((respflags & CTL_MORE) != 0);
- if (lastverb_p(next))
- respflags &= ~CTL_MORE;
- ctl_response(sess, sess->helpcode, this->help, respflags, next,
- NULL, NULL, NULL, 0);
-}
-
-static void
-ctl_signal_done(struct ctl_sctx *ctx, struct ctl_sess *sess) {
- if (sess->donefunc != NULL) {
- (*sess->donefunc)(ctx, sess, sess->uap);
- sess->donefunc = NULL;
- }
-}
diff --git a/contrib/bind/lib/isc/ev_connects.c b/contrib/bind/lib/isc/ev_connects.c
deleted file mode 100644
index 5be432a..0000000
--- a/contrib/bind/lib/isc/ev_connects.c
+++ /dev/null
@@ -1,365 +0,0 @@
-/*
- * Copyright (c) 1995-1999 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.
- */
-
-/* ev_connects.c - implement asynch connect/accept for the eventlib
- * vix 16sep96 [initial]
- */
-
-#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: ev_connects.c,v 8.32 2001/07/03 13:26:35 marka Exp $";
-#endif
-
-/* Import. */
-
-#include "port_before.h"
-#include "fd_setsize.h"
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-
-#include <unistd.h>
-
-#include <isc/eventlib.h>
-#include <isc/assertions.h>
-#include "eventlib_p.h"
-
-#include "port_after.h"
-
-/* Macros. */
-
-#define GETXXXNAME(f, s, sa, len) ( \
- (f((s), (&sa), (&len)) >= 0) ? 0 : \
- (errno != EAFNOSUPPORT && errno != EOPNOTSUPP) ? -1 : ( \
- memset(&(sa), 0, sizeof (sa)), \
- (len) = sizeof (sa), \
- (sa).sa_family = AF_UNIX, \
- 0 \
- ) \
- )
-
-/* Forward. */
-
-static void listener(evContext ctx, void *uap, int fd, int evmask);
-static void connector(evContext ctx, void *uap, int fd, int evmask);
-
-/* Public. */
-
-int
-evListen(evContext opaqueCtx, int fd, int maxconn,
- evConnFunc func, void *uap, evConnID *id)
-{
- evContext_p *ctx = opaqueCtx.opaque;
- evConn *new;
- int mode;
-
- OKNEW(new);
- new->flags = EV_CONN_LISTEN;
- OK(mode = fcntl(fd, F_GETFL, NULL)); /* side effect: validate fd. */
- /*
- * Remember the nonblocking status. We assume that either evSelectFD
- * has not been done to this fd, or that if it has then the caller
- * will evCancelConn before they evDeselectFD. If our assumptions
- * are not met, then we might restore the old nonblocking status
- * incorrectly.
- */
- if ((mode & PORT_NONBLOCK) == 0) {
-#ifdef USE_FIONBIO_IOCTL
- int on = 1;
- OK(ioctl(fd, FIONBIO, (char *)&on));
-#else
- OK(fcntl(fd, F_SETFL, mode | PORT_NONBLOCK));
-#endif
- new->flags |= EV_CONN_BLOCK;
- }
- OK(listen(fd, maxconn));
- if (evSelectFD(opaqueCtx, fd, EV_READ, listener, new, &new->file) < 0){
- int save = errno;
-
- FREE(new);
- errno = save;
- return (-1);
- }
- new->flags |= EV_CONN_SELECTED;
- new->func = func;
- new->uap = uap;
- new->fd = fd;
- if (ctx->conns != NULL)
- ctx->conns->prev = new;
- new->prev = NULL;
- new->next = ctx->conns;
- ctx->conns = new;
- if (id)
- id->opaque = new;
- return (0);
-}
-
-int
-evConnect(evContext opaqueCtx, int fd, const void *ra, int ralen,
- evConnFunc func, void *uap, evConnID *id)
-{
- evContext_p *ctx = opaqueCtx.opaque;
- evConn *new;
-
- OKNEW(new);
- new->flags = 0;
- /* Do the select() first to get the socket into nonblocking mode. */
- if (evSelectFD(opaqueCtx, fd, EV_MASK_ALL,
- connector, new, &new->file) < 0) {
- int save = errno;
-
- FREE(new);
- errno = save;
- return (-1);
- }
- new->flags |= EV_CONN_SELECTED;
- if (connect(fd, ra, ralen) < 0 &&
- errno != EWOULDBLOCK &&
- errno != EAGAIN &&
- errno != EINPROGRESS) {
- int save = errno;
-
- (void) evDeselectFD(opaqueCtx, new->file);
- FREE(new);
- errno = save;
- return (-1);
- }
- /* No error, or EWOULDBLOCK. select() tells when it's ready. */
- new->func = func;
- new->uap = uap;
- new->fd = fd;
- if (ctx->conns != NULL)
- ctx->conns->prev = new;
- new->prev = NULL;
- new->next = ctx->conns;
- ctx->conns = new;
- if (id)
- id->opaque = new;
- return (0);
-}
-
-int
-evCancelConn(evContext opaqueCtx, evConnID id) {
- evContext_p *ctx = opaqueCtx.opaque;
- evConn *this = id.opaque;
- evAccept *acc, *nxtacc;
- int mode;
-
- if ((this->flags & EV_CONN_SELECTED) != 0)
- (void) evDeselectFD(opaqueCtx, this->file);
- if ((this->flags & EV_CONN_BLOCK) != 0) {
- mode = fcntl(this->fd, F_GETFL, NULL);
- if (mode == -1) {
- if (errno != EBADF)
- return (-1);
- } else {
-#ifdef USE_FIONBIO_IOCTL
- int on = 1;
- OK(ioctl(this->fd, FIONBIO, (char *)&on));
-#else
- OK(fcntl(this->fd, F_SETFL, mode | PORT_NONBLOCK));
-#endif
- }
- }
-
- /* Unlink from ctx->conns. */
- if (this->prev != NULL)
- this->prev->next = this->next;
- else
- ctx->conns = this->next;
- if (this->next != NULL)
- this->next->prev = this->prev;
-
- /*
- * Remove `this' from the ctx->accepts list (zero or more times).
- */
- for (acc = HEAD(ctx->accepts), nxtacc = NULL;
- acc != NULL;
- acc = nxtacc)
- {
- nxtacc = NEXT(acc, link);
- if (acc->conn == this) {
- UNLINK(ctx->accepts, acc, link);
- close(acc->fd);
- FREE(acc);
- }
- }
-
- /* Wrap up and get out. */
- FREE(this);
- return (0);
-}
-
-int evHold(evContext opaqueCtx, evConnID id) {
- evConn *this = id.opaque;
-
- if ((this->flags & EV_CONN_LISTEN) == 0) {
- errno = EINVAL;
- return (-1);
- }
- if ((this->flags & EV_CONN_SELECTED) == 0)
- return (0);
- this->flags &= ~EV_CONN_SELECTED;
- return (evDeselectFD(opaqueCtx, this->file));
-}
-
-int evUnhold(evContext opaqueCtx, evConnID id) {
- evConn *this = id.opaque;
- int ret;
-
- if ((this->flags & EV_CONN_LISTEN) == 0) {
- errno = EINVAL;
- return (-1);
- }
- if ((this->flags & EV_CONN_SELECTED) != 0)
- return (0);
- ret = evSelectFD(opaqueCtx, this->fd, EV_READ, listener, this,
- &this->file);
- if (ret == 0)
- this->flags |= EV_CONN_SELECTED;
- return (ret);
-}
-
-int
-evTryAccept(evContext opaqueCtx, evConnID id, int *sys_errno) {
- evContext_p *ctx = opaqueCtx.opaque;
- evConn *conn = id.opaque;
- evAccept *new;
-
- if ((conn->flags & EV_CONN_LISTEN) == 0) {
- errno = EINVAL;
- return (-1);
- }
- OKNEW(new);
- new->conn = conn;
- new->ralen = sizeof new->ra;
- new->fd = accept(conn->fd, &new->ra.sa, &new->ralen);
- if (new->fd > ctx->highestFD) {
- close(new->fd);
- new->fd = -1;
- new->ioErrno = ENOTSOCK;
- }
- if (new->fd >= 0) {
- new->lalen = sizeof new->la;
- if (GETXXXNAME(getsockname, new->fd, new->la.sa, new->lalen) < 0) {
- new->ioErrno = errno;
- (void) close(new->fd);
- new->fd = -1;
- } else
- new->ioErrno = 0;
- } else {
- new->ioErrno = errno;
- if (errno == EAGAIN || errno == EWOULDBLOCK) {
- FREE(new);
- return (-1);
- }
- }
- INIT_LINK(new, link);
- APPEND(ctx->accepts, new, link);
- *sys_errno = new->ioErrno;
- return (0);
-}
-
-/* Private. */
-
-static void
-listener(evContext opaqueCtx, void *uap, int fd, int evmask) {
- evContext_p *ctx = opaqueCtx.opaque;
- evConn *conn = uap;
- union {
- struct sockaddr sa;
- struct sockaddr_in in;
-#ifndef NO_SOCKADDR_UN
- struct sockaddr_un un;
-#endif
- } la, ra;
- int new;
- ISC_SOCKLEN_T lalen = 0, ralen;
-
- REQUIRE((evmask & EV_READ) != 0);
- ralen = sizeof ra;
- new = accept(fd, &ra.sa, &ralen);
- if (new > ctx->highestFD) {
- close(new);
- new = -1;
- errno = ENOTSOCK;
- }
- if (new >= 0) {
- lalen = sizeof la;
- if (GETXXXNAME(getsockname, new, la.sa, lalen) < 0) {
- int save = errno;
-
- (void) close(new);
- errno = save;
- new = -1;
- }
- } else if (errno == EAGAIN || errno == EWOULDBLOCK)
- return;
- (*conn->func)(opaqueCtx, conn->uap, new, &la.sa, lalen, &ra.sa, ralen);
-}
-
-static void
-connector(evContext opaqueCtx, void *uap, int fd, int evmask) {
- evConn *conn = uap;
- union {
- struct sockaddr sa;
- struct sockaddr_in in;
-#ifndef NO_SOCKADDR_UN
- struct sockaddr_un un;
-#endif
- } la, ra;
- ISC_SOCKLEN_T lalen, ralen;
- char buf[1];
- void *conn_uap;
- evConnFunc conn_func;
- evConnID id;
- int socket_errno = 0;
- ISC_SOCKLEN_T optlen;
-
- UNUSED(evmask);
-
- lalen = sizeof la;
- ralen = sizeof ra;
- conn_uap = conn->uap;
- conn_func = conn->func;
- id.opaque = conn;
-#ifdef SO_ERROR
- optlen = sizeof socket_errno;
- if (fd < 0 &&
- getsockopt(conn->fd, SOL_SOCKET, SO_ERROR, (char *)&socket_errno,
- &optlen) < 0)
- socket_errno = errno;
- else
- errno = socket_errno;
-#endif
- if (evCancelConn(opaqueCtx, id) < 0 ||
- socket_errno ||
-#ifdef NETREAD_BROKEN
- 0 ||
-#else
- read(fd, buf, 0) < 0 ||
-#endif
- GETXXXNAME(getsockname, fd, la.sa, lalen) < 0 ||
- GETXXXNAME(getpeername, fd, ra.sa, ralen) < 0) {
- int save = errno;
-
- (void) close(fd); /* XXX closing caller's fd */
- errno = save;
- fd = -1;
- }
- (*conn_func)(opaqueCtx, conn_uap, fd, &la.sa, lalen, &ra.sa, ralen);
-}
diff --git a/contrib/bind/lib/isc/ev_files.c b/contrib/bind/lib/isc/ev_files.c
deleted file mode 100644
index 3a6894b..0000000
--- a/contrib/bind/lib/isc/ev_files.c
+++ /dev/null
@@ -1,283 +0,0 @@
-/*
- * Copyright (c) 1995-1999 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.
- */
-
-/* ev_files.c - implement asynch file IO for the eventlib
- * vix 11sep95 [initial]
- */
-
-#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: ev_files.c,v 1.22 2002/07/08 05:50:07 marka Exp $";
-#endif
-
-#include "port_before.h"
-#include "fd_setsize.h"
-
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/ioctl.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <unistd.h>
-
-#include <isc/eventlib.h>
-#include "eventlib_p.h"
-
-#include "port_after.h"
-
-static evFile *FindFD(const evContext_p *ctx, int fd, int eventmask);
-
-int
-evSelectFD(evContext opaqueCtx,
- int fd,
- int eventmask,
- evFileFunc func,
- void *uap,
- evFileID *opaqueID
-) {
- evContext_p *ctx = opaqueCtx.opaque;
- evFile *id;
- int mode;
-
- evPrintf(ctx, 1,
- "evSelectFD(ctx %p, fd %d, mask 0x%x, func %p, uap %p)\n",
- ctx, fd, eventmask, func, uap);
- if (eventmask == 0 || (eventmask & ~EV_MASK_ALL) != 0)
- EV_ERR(EINVAL);
- if (fd > ctx->highestFD)
- EV_ERR(EINVAL);
- OK(mode = fcntl(fd, F_GETFL, NULL)); /* side effect: validate fd. */
-
- /*
- * The first time we touch a file descriptor, we need to check to see
- * if the application already had it in O_NONBLOCK mode and if so, all
- * of our deselect()'s have to leave it in O_NONBLOCK. If not, then
- * all but our last deselect() has to leave it in O_NONBLOCK.
- */
- id = FindFD(ctx, fd, EV_MASK_ALL);
- if (id == NULL) {
- if (mode & PORT_NONBLOCK)
- FD_SET(fd, &ctx->nonblockBefore);
- else {
-#ifdef USE_FIONBIO_IOCTL
- int on = 1;
- OK(ioctl(fd, FIONBIO, (char *)&on));
-#else
- OK(fcntl(fd, F_SETFL, mode | PORT_NONBLOCK));
-#endif
- FD_CLR(fd, &ctx->nonblockBefore);
- }
- }
-
- /*
- * If this descriptor is already in use, search for it again to see
- * if any of the eventmask bits we want to set are already captured.
- * We cannot usefully capture the same fd event more than once in the
- * same context.
- */
- if (id != NULL && FindFD(ctx, fd, eventmask) != NULL)
- EV_ERR(ETOOMANYREFS);
-
- /* Allocate and fill. */
- OKNEW(id);
- id->func = func;
- id->uap = uap;
- id->fd = fd;
- id->eventmask = eventmask;
-
- /*
- * Insert at head. Order could be important for performance if we
- * believe that evGetNext()'s accesses to the fd_sets will be more
- * serial and therefore more cache-lucky if the list is ordered by
- * ``fd.'' We do not believe these things, so we don't do it.
- *
- * The interesting sequence is where GetNext() has cached a select()
- * result and the caller decides to evSelectFD() on some descriptor.
- * Since GetNext() starts at the head, it can miss new entries we add
- * at the head. This is not a serious problem since the event being
- * evSelectFD()'d for has to occur before evSelectFD() is called for
- * the file event to be considered "missed" -- a real corner case.
- * Maintaining a "tail" pointer for ctx->files would fix this, but I'm
- * not sure it would be ``more correct.''
- */
- if (ctx->files != NULL)
- ctx->files->prev = id;
- id->prev = NULL;
- id->next = ctx->files;
- ctx->files = id;
-
- /* Insert into fd table. */
- if (ctx->fdTable[fd] != NULL)
- ctx->fdTable[fd]->fdprev = id;
- id->fdprev = NULL;
- id->fdnext = ctx->fdTable[fd];
- ctx->fdTable[fd] = id;
-
- /* Turn on the appropriate bits in the {rd,wr,ex}Next fd_set's. */
- if (eventmask & EV_READ)
- FD_SET(fd, &ctx->rdNext);
- if (eventmask & EV_WRITE)
- FD_SET(fd, &ctx->wrNext);
- if (eventmask & EV_EXCEPT)
- FD_SET(fd, &ctx->exNext);
-
- /* Update fdMax. */
- if (fd > ctx->fdMax)
- ctx->fdMax = fd;
-
- /* Remember the ID if the caller provided us a place for it. */
- if (opaqueID)
- opaqueID->opaque = id;
-
- evPrintf(ctx, 5,
- "evSelectFD(fd %d, mask 0x%x): new masks: 0x%lx 0x%lx 0x%lx\n",
- fd, eventmask,
- (u_long)ctx->rdNext.fds_bits[0],
- (u_long)ctx->wrNext.fds_bits[0],
- (u_long)ctx->exNext.fds_bits[0]);
-
- return (0);
-}
-
-int
-evDeselectFD(evContext opaqueCtx, evFileID opaqueID) {
- evContext_p *ctx = opaqueCtx.opaque;
- evFile *del = opaqueID.opaque;
- evFile *cur;
- int mode, eventmask;
-
- if (!del) {
- evPrintf(ctx, 11, "evDeselectFD(NULL) ignored\n");
- errno = EINVAL;
- return (-1);
- }
-
- evPrintf(ctx, 1, "evDeselectFD(fd %d, mask 0x%x)\n",
- del->fd, del->eventmask);
-
- /* Get the mode. Unless the file has been closed, errors are bad. */
- mode = fcntl(del->fd, F_GETFL, NULL);
- if (mode == -1 && errno != EBADF)
- EV_ERR(errno);
-
- /* Remove from the list of files. */
- if (del->prev != NULL)
- del->prev->next = del->next;
- else
- ctx->files = del->next;
- if (del->next != NULL)
- del->next->prev = del->prev;
-
- /* Remove from the fd table. */
- if (del->fdprev != NULL)
- del->fdprev->fdnext = del->fdnext;
- else
- ctx->fdTable[del->fd] = del->fdnext;
- if (del->fdnext != NULL)
- del->fdnext->fdprev = del->fdprev;
-
- /*
- * If the file descriptor does not appear in any other select() entry,
- * and if !EV_WASNONBLOCK, and if we got no EBADF when we got the mode
- * earlier, then: restore the fd to blocking status.
- */
- if (!(cur = FindFD(ctx, del->fd, EV_MASK_ALL)) &&
- !FD_ISSET(del->fd, &ctx->nonblockBefore) &&
- mode != -1) {
- /*
- * Note that we won't return an error status to the caller if
- * this fcntl() fails since (a) we've already done the work
- * and (b) the caller didn't ask us anything about O_NONBLOCK.
- */
-#ifdef USE_FIONBIO_IOCTL
- int off = 1;
- (void) ioctl(del->fd, FIONBIO, (char *)&off);
-#else
- (void) fcntl(del->fd, F_SETFL, mode & ~PORT_NONBLOCK);
-#endif
- }
-
- /*
- * Now find all other uses of this descriptor and OR together an event
- * mask so that we don't turn off {rd,wr,ex}Next bits that some other
- * file event is using. As an optimization, stop if the event mask
- * fills.
- */
- eventmask = 0;
- for ((void)NULL;
- cur != NULL && eventmask != EV_MASK_ALL;
- cur = cur->next)
- if (cur->fd == del->fd)
- eventmask |= cur->eventmask;
-
- /* OK, now we know which bits we can clear out. */
- if (!(eventmask & EV_READ)) {
- FD_CLR(del->fd, &ctx->rdNext);
- if (FD_ISSET(del->fd, &ctx->rdLast)) {
- FD_CLR(del->fd, &ctx->rdLast);
- ctx->fdCount--;
- }
- }
- if (!(eventmask & EV_WRITE)) {
- FD_CLR(del->fd, &ctx->wrNext);
- if (FD_ISSET(del->fd, &ctx->wrLast)) {
- FD_CLR(del->fd, &ctx->wrLast);
- ctx->fdCount--;
- }
- }
- if (!(eventmask & EV_EXCEPT)) {
- FD_CLR(del->fd, &ctx->exNext);
- if (FD_ISSET(del->fd, &ctx->exLast)) {
- FD_CLR(del->fd, &ctx->exLast);
- ctx->fdCount--;
- }
- }
-
- /* If this was the maxFD, find the new one. */
- if (del->fd == ctx->fdMax) {
- ctx->fdMax = -1;
- for (cur = ctx->files; cur; cur = cur->next)
- if (cur->fd > ctx->fdMax)
- ctx->fdMax = cur->fd;
- }
-
- /* If this was the fdNext, cycle that to the next entry. */
- if (del == ctx->fdNext)
- ctx->fdNext = del->next;
-
- evPrintf(ctx, 5,
- "evDeselectFD(fd %d, mask 0x%x): new masks: 0x%lx 0x%lx 0x%lx\n",
- del->fd, eventmask,
- (u_long)ctx->rdNext.fds_bits[0],
- (u_long)ctx->wrNext.fds_bits[0],
- (u_long)ctx->exNext.fds_bits[0]);
-
- /* Couldn't free it before now since we were using fields out of it. */
- FREE(del);
-
- return (0);
-}
-
-static evFile *
-FindFD(const evContext_p *ctx, int fd, int eventmask) {
- evFile *id;
-
- for (id = ctx->fdTable[fd]; id != NULL; id = id->fdnext)
- if (id->fd == fd && (id->eventmask & eventmask) != 0)
- break;
- return (id);
-}
diff --git a/contrib/bind/lib/isc/ev_streams.c b/contrib/bind/lib/isc/ev_streams.c
deleted file mode 100644
index a301720..0000000
--- a/contrib/bind/lib/isc/ev_streams.c
+++ /dev/null
@@ -1,306 +0,0 @@
-/*
- * Copyright (c) 1996-1999 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.
- */
-
-/* ev_streams.c - implement asynch stream file IO for the eventlib
- * vix 04mar96 [initial]
- */
-
-#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: ev_streams.c,v 8.22 2001/05/29 05:49:29 marka Exp $";
-#endif
-
-#include "port_before.h"
-#include "fd_setsize.h"
-
-#include <sys/types.h>
-#include <sys/uio.h>
-
-#include <errno.h>
-
-#include <isc/eventlib.h>
-#include <isc/assertions.h>
-#include "eventlib_p.h"
-
-#include "port_after.h"
-
-static int copyvec(evStream *str, const struct iovec *iov, int iocnt);
-static void consume(evStream *str, size_t bytes);
-static void done(evContext opaqueCtx, evStream *str);
-static void writable(evContext opaqueCtx, void *uap, int fd, int evmask);
-static void readable(evContext opaqueCtx, void *uap, int fd, int evmask);
-
-struct iovec
-evConsIovec(void *buf, size_t cnt) {
- struct iovec ret;
-
- memset(&ret, 0xf5, sizeof ret);
- ret.iov_base = buf;
- ret.iov_len = cnt;
- return (ret);
-}
-
-int
-evWrite(evContext opaqueCtx, int fd, const struct iovec *iov, int iocnt,
- evStreamFunc func, void *uap, evStreamID *id)
-{
- evContext_p *ctx = opaqueCtx.opaque;
- evStream *new;
- int save;
-
- OKNEW(new);
- new->func = func;
- new->uap = uap;
- new->fd = fd;
- new->flags = 0;
- if (evSelectFD(opaqueCtx, fd, EV_WRITE, writable, new, &new->file) < 0)
- goto free;
- if (copyvec(new, iov, iocnt) < 0)
- goto free;
- new->prevDone = NULL;
- new->nextDone = NULL;
- if (ctx->streams != NULL)
- ctx->streams->prev = new;
- new->prev = NULL;
- new->next = ctx->streams;
- ctx->streams = new;
- if (id != NULL)
- id->opaque = new;
- return (0);
- free:
- save = errno;
- FREE(new);
- errno = save;
- return (-1);
-}
-
-int
-evRead(evContext opaqueCtx, int fd, const struct iovec *iov, int iocnt,
- evStreamFunc func, void *uap, evStreamID *id)
-{
- evContext_p *ctx = opaqueCtx.opaque;
- evStream *new;
- int save;
-
- OKNEW(new);
- new->func = func;
- new->uap = uap;
- new->fd = fd;
- new->flags = 0;
- if (evSelectFD(opaqueCtx, fd, EV_READ, readable, new, &new->file) < 0)
- goto free;
- if (copyvec(new, iov, iocnt) < 0)
- goto free;
- new->prevDone = NULL;
- new->nextDone = NULL;
- if (ctx->streams != NULL)
- ctx->streams->prev = new;
- new->prev = NULL;
- new->next = ctx->streams;
- ctx->streams = new;
- if (id)
- id->opaque = new;
- return (0);
- free:
- save = errno;
- FREE(new);
- errno = save;
- return (-1);
-}
-
-int
-evTimeRW(evContext opaqueCtx, evStreamID id, evTimerID timer) /*ARGSUSED*/ {
- evStream *str = id.opaque;
-
- UNUSED(opaqueCtx);
-
- str->timer = timer;
- str->flags |= EV_STR_TIMEROK;
- return (0);
-}
-
-int
-evUntimeRW(evContext opaqueCtx, evStreamID id) /*ARGSUSED*/ {
- evStream *str = id.opaque;
-
- UNUSED(opaqueCtx);
-
- str->flags &= ~EV_STR_TIMEROK;
- return (0);
-}
-
-int
-evCancelRW(evContext opaqueCtx, evStreamID id) {
- evContext_p *ctx = opaqueCtx.opaque;
- evStream *old = id.opaque;
-
- /*
- * The streams list is doubly threaded. First, there's ctx->streams
- * that's used by evDestroy() to find and cancel all streams. Second,
- * there's ctx->strDone (head) and ctx->strLast (tail) which thread
- * through the potentially smaller number of "IO completed" streams,
- * used in evGetNext() to avoid scanning the entire list.
- */
-
- /* Unlink from ctx->streams. */
- if (old->prev != NULL)
- old->prev->next = old->next;
- else
- ctx->streams = old->next;
- if (old->next != NULL)
- old->next->prev = old->prev;
-
- /*
- * If 'old' is on the ctx->strDone list, remove it. Update
- * ctx->strLast if necessary.
- */
- if (old->prevDone == NULL && old->nextDone == NULL) {
- /*
- * Either 'old' is the only item on the done list, or it's
- * not on the done list. If the former, then we unlink it
- * from the list. If the latter, we leave the list alone.
- */
- if (ctx->strDone == old) {
- ctx->strDone = NULL;
- ctx->strLast = NULL;
- }
- } else {
- if (old->prevDone != NULL)
- old->prevDone->nextDone = old->nextDone;
- else
- ctx->strDone = old->nextDone;
- if (old->nextDone != NULL)
- old->nextDone->prevDone = old->prevDone;
- else
- ctx->strLast = old->prevDone;
- }
-
- /* Deallocate the stream. */
- if (old->file.opaque)
- evDeselectFD(opaqueCtx, old->file);
- memput(old->iovOrig, sizeof (struct iovec) * old->iovOrigCount);
- FREE(old);
- return (0);
-}
-
-/* Copy a scatter/gather vector and initialize a stream handler's IO. */
-static int
-copyvec(evStream *str, const struct iovec *iov, int iocnt) {
- int i;
-
- str->iovOrig = (struct iovec *)memget(sizeof(struct iovec) * iocnt);
- if (str->iovOrig == NULL) {
- errno = ENOMEM;
- return (-1);
- }
- str->ioTotal = 0;
- for (i = 0; i < iocnt; i++) {
- str->iovOrig[i] = iov[i];
- str->ioTotal += iov[i].iov_len;
- }
- str->iovOrigCount = iocnt;
- str->iovCur = str->iovOrig;
- str->iovCurCount = str->iovOrigCount;
- str->ioDone = 0;
- return (0);
-}
-
-/* Pull off or truncate lead iovec(s). */
-static void
-consume(evStream *str, size_t bytes) {
- while (bytes > 0) {
- if (bytes < (size_t)str->iovCur->iov_len) {
- str->iovCur->iov_len -= bytes;
- str->iovCur->iov_base = (void *)
- ((u_char *)str->iovCur->iov_base + bytes);
- str->ioDone += bytes;
- bytes = 0;
- } else {
- bytes -= str->iovCur->iov_len;
- str->ioDone += str->iovCur->iov_len;
- str->iovCur++;
- str->iovCurCount--;
- }
- }
-}
-
-/* Add a stream to Done list and deselect the FD. */
-static void
-done(evContext opaqueCtx, evStream *str) {
- evContext_p *ctx = opaqueCtx.opaque;
-
- if (ctx->strLast != NULL) {
- str->prevDone = ctx->strLast;
- ctx->strLast->nextDone = str;
- ctx->strLast = str;
- } else {
- INSIST(ctx->strDone == NULL);
- ctx->strDone = ctx->strLast = str;
- }
- evDeselectFD(opaqueCtx, str->file);
- str->file.opaque = NULL;
- /* evDrop() will call evCancelRW() on us. */
-}
-
-/* Dribble out some bytes on the stream. (Called by evDispatch().) */
-static void
-writable(evContext opaqueCtx, void *uap, int fd, int evmask) {
- evStream *str = uap;
- int bytes;
-
- UNUSED(evmask);
-
- bytes = writev(fd, str->iovCur, str->iovCurCount);
- if (bytes > 0) {
- if ((str->flags & EV_STR_TIMEROK) != 0)
- evTouchIdleTimer(opaqueCtx, str->timer);
- consume(str, bytes);
- } else {
- if (bytes < 0 && errno != EINTR) {
- str->ioDone = -1;
- str->ioErrno = errno;
- }
- }
- if (str->ioDone == -1 || str->ioDone == str->ioTotal)
- done(opaqueCtx, str);
-}
-
-/* Scoop up some bytes from the stream. (Called by evDispatch().) */
-static void
-readable(evContext opaqueCtx, void *uap, int fd, int evmask) {
- evStream *str = uap;
- int bytes;
-
- UNUSED(evmask);
-
- bytes = readv(fd, str->iovCur, str->iovCurCount);
- if (bytes > 0) {
- if ((str->flags & EV_STR_TIMEROK) != 0)
- evTouchIdleTimer(opaqueCtx, str->timer);
- consume(str, bytes);
- } else {
- if (bytes == 0)
- str->ioDone = 0;
- else {
- if (errno != EINTR) {
- str->ioDone = -1;
- str->ioErrno = errno;
- }
- }
- }
- if (str->ioDone <= 0 || str->ioDone == str->ioTotal)
- done(opaqueCtx, str);
-}
diff --git a/contrib/bind/lib/isc/ev_timers.c b/contrib/bind/lib/isc/ev_timers.c
deleted file mode 100644
index 0f3c56f..0000000
--- a/contrib/bind/lib/isc/ev_timers.c
+++ /dev/null
@@ -1,415 +0,0 @@
-/*
- * Copyright (c) 1995-1999 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.
- */
-
-/* ev_timers.c - implement timers for the eventlib
- * vix 09sep95 [initial]
- */
-
-#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: ev_timers.c,v 1.33 2002/07/08 05:50:09 marka Exp $";
-#endif
-
-/* Import. */
-
-#include "port_before.h"
-#include "fd_setsize.h"
-
-#include <errno.h>
-
-#include <isc/assertions.h>
-#include <isc/eventlib.h>
-#include "eventlib_p.h"
-
-#include "port_after.h"
-
-/* Constants. */
-
-#define MILLION 1000000
-#define BILLION 1000000000
-
-/* Forward. */
-
-static int due_sooner(void *, void *);
-static void set_index(void *, int);
-static void free_timer(void *, void *);
-static void print_timer(void *, void *);
-static void idle_timeout(evContext, void *, struct timespec, struct timespec);
-
-/* Private type. */
-
-typedef struct {
- evTimerFunc func;
- void * uap;
- struct timespec lastTouched;
- struct timespec max_idle;
- evTimer * timer;
-} idle_timer;
-
-/* Public. */
-
-struct timespec
-evConsTime(time_t sec, long nsec) {
- struct timespec x;
-
- x.tv_sec = sec;
- x.tv_nsec = nsec;
- return (x);
-}
-
-struct timespec
-evAddTime(struct timespec addend1, struct timespec addend2) {
- struct timespec x;
-
- x.tv_sec = addend1.tv_sec + addend2.tv_sec;
- x.tv_nsec = addend1.tv_nsec + addend2.tv_nsec;
- if (x.tv_nsec >= BILLION) {
- x.tv_sec++;
- x.tv_nsec -= BILLION;
- }
- return (x);
-}
-
-struct timespec
-evSubTime(struct timespec minuend, struct timespec subtrahend) {
- struct timespec x;
-
- x.tv_sec = minuend.tv_sec - subtrahend.tv_sec;
- if (minuend.tv_nsec >= subtrahend.tv_nsec)
- x.tv_nsec = minuend.tv_nsec - subtrahend.tv_nsec;
- else {
- x.tv_nsec = BILLION - subtrahend.tv_nsec + minuend.tv_nsec;
- x.tv_sec--;
- }
- return (x);
-}
-
-int
-evCmpTime(struct timespec a, struct timespec b) {
- long x = a.tv_sec - b.tv_sec;
-
- if (x == 0L)
- x = a.tv_nsec - b.tv_nsec;
- return (x < 0L ? (-1) : x > 0L ? (1) : (0));
-}
-
-struct timespec
-evNowTime() {
- struct timeval now;
-
- if (gettimeofday(&now, NULL) < 0)
- return (evConsTime(0, 0));
- return (evTimeSpec(now));
-}
-
-struct timespec
-evLastEventTime(evContext opaqueCtx) {
- evContext_p *ctx = opaqueCtx.opaque;
-
- return (ctx->lastEventTime);
-}
-
-struct timespec
-evTimeSpec(struct timeval tv) {
- struct timespec ts;
-
- ts.tv_sec = tv.tv_sec;
- ts.tv_nsec = tv.tv_usec * 1000;
- return (ts);
-}
-
-struct timeval
-evTimeVal(struct timespec ts) {
- struct timeval tv;
-
- tv.tv_sec = ts.tv_sec;
- tv.tv_usec = ts.tv_nsec / 1000;
- return (tv);
-}
-
-int
-evSetTimer(evContext opaqueCtx,
- evTimerFunc func,
- void *uap,
- struct timespec due,
- struct timespec inter,
- evTimerID *opaqueID
-) {
- evContext_p *ctx = opaqueCtx.opaque;
- evTimer *id;
-
- evPrintf(ctx, 1,
-"evSetTimer(ctx %p, func %p, uap %p, due %ld.%09ld, inter %ld.%09ld)\n",
- ctx, func, uap,
- (long)due.tv_sec, due.tv_nsec,
- (long)inter.tv_sec, inter.tv_nsec);
-
- /* due={0,0} is a magic cookie meaning "now." */
- if (due.tv_sec == 0 && due.tv_nsec == 0L)
- due = evNowTime();
-
- /* Allocate and fill. */
- OKNEW(id);
- id->func = func;
- id->uap = uap;
- id->due = due;
- id->inter = inter;
-
- if (heap_insert(ctx->timers, id) < 0)
- return (-1);
-
- /* Remember the ID if the caller provided us a place for it. */
- if (opaqueID)
- opaqueID->opaque = id;
-
- if (ctx->debug > 7) {
- evPrintf(ctx, 7, "timers after evSetTimer:\n");
- (void) heap_for_each(ctx->timers, print_timer, (void *)ctx);
- }
-
- return (0);
-}
-
-int
-evClearTimer(evContext opaqueCtx, evTimerID id) {
- evContext_p *ctx = opaqueCtx.opaque;
- evTimer *del = id.opaque;
-
- if (ctx->cur != NULL &&
- ctx->cur->type == Timer &&
- ctx->cur->u.timer.this == del) {
- evPrintf(ctx, 8, "deferring delete of timer (executing)\n");
- /*
- * Setting the interval to zero ensures that evDrop() will
- * clean up the timer.
- */
- del->inter = evConsTime(0, 0);
- return (0);
- }
-
- if (heap_element(ctx->timers, del->index) != del)
- EV_ERR(ENOENT);
-
- if (heap_delete(ctx->timers, del->index) < 0)
- return (-1);
- FREE(del);
-
- if (ctx->debug > 7) {
- evPrintf(ctx, 7, "timers after evClearTimer:\n");
- (void) heap_for_each(ctx->timers, print_timer, (void *)ctx);
- }
-
- return (0);
-}
-
-int
-evResetTimer(evContext opaqueCtx,
- evTimerID id,
- evTimerFunc func,
- void *uap,
- struct timespec due,
- struct timespec inter
-) {
- evContext_p *ctx = opaqueCtx.opaque;
- evTimer *timer = id.opaque;
- struct timespec old_due;
- int result=0;
-
- if (heap_element(ctx->timers, timer->index) != timer)
- EV_ERR(ENOENT);
-
- old_due = timer->due;
-
- timer->func = func;
- timer->uap = uap;
- timer->due = due;
- timer->inter = inter;
-
- switch (evCmpTime(due, old_due)) {
- case -1:
- result = heap_increased(ctx->timers, timer->index);
- break;
- case 0:
- result = 0;
- break;
- case 1:
- result = heap_decreased(ctx->timers, timer->index);
- break;
- }
-
- if (ctx->debug > 7) {
- evPrintf(ctx, 7, "timers after evResetTimer:\n");
- (void) heap_for_each(ctx->timers, print_timer, (void *)ctx);
- }
-
- return (result);
-}
-
-int
-evSetIdleTimer(evContext opaqueCtx,
- evTimerFunc func,
- void *uap,
- struct timespec max_idle,
- evTimerID *opaqueID
-) {
- evContext_p *ctx = opaqueCtx.opaque;
- idle_timer *tt;
-
- /* Allocate and fill. */
- OKNEW(tt);
- tt->func = func;
- tt->uap = uap;
- tt->lastTouched = ctx->lastEventTime;
- tt->max_idle = max_idle;
-
- if (evSetTimer(opaqueCtx, idle_timeout, tt,
- evAddTime(ctx->lastEventTime, max_idle),
- max_idle, opaqueID) < 0) {
- FREE(tt);
- return (-1);
- }
-
- tt->timer = opaqueID->opaque;
-
- return (0);
-}
-
-int
-evClearIdleTimer(evContext opaqueCtx, evTimerID id) {
- evTimer *del = id.opaque;
- idle_timer *tt = del->uap;
-
- FREE(tt);
- return (evClearTimer(opaqueCtx, id));
-}
-
-int
-evResetIdleTimer(evContext opaqueCtx,
- evTimerID opaqueID,
- evTimerFunc func,
- void *uap,
- struct timespec max_idle
-) {
- evContext_p *ctx = opaqueCtx.opaque;
- evTimer *timer = opaqueID.opaque;
- idle_timer *tt = timer->uap;
-
- tt->func = func;
- tt->uap = uap;
- tt->lastTouched = ctx->lastEventTime;
- tt->max_idle = max_idle;
-
- return (evResetTimer(opaqueCtx, opaqueID, idle_timeout, tt,
- evAddTime(ctx->lastEventTime, max_idle),
- max_idle));
-}
-
-int
-evTouchIdleTimer(evContext opaqueCtx, evTimerID id) {
- evContext_p *ctx = opaqueCtx.opaque;
- evTimer *t = id.opaque;
- idle_timer *tt = t->uap;
-
- tt->lastTouched = ctx->lastEventTime;
-
- return (0);
-}
-
-/* Public to the rest of eventlib. */
-
-heap_context
-evCreateTimers(const evContext_p *ctx) {
-
- UNUSED(ctx);
-
- return (heap_new(due_sooner, set_index, 2048));
-}
-
-void
-evDestroyTimers(const evContext_p *ctx) {
- (void) heap_for_each(ctx->timers, free_timer, NULL);
- (void) heap_free(ctx->timers);
-}
-
-/* Private. */
-
-static int
-due_sooner(void *a, void *b) {
- evTimer *a_timer, *b_timer;
-
- a_timer = a;
- b_timer = b;
- return (evCmpTime(a_timer->due, b_timer->due) < 0);
-}
-
-static void
-set_index(void *what, int index) {
- evTimer *timer;
-
- timer = what;
- timer->index = index;
-}
-
-static void
-free_timer(void *what, void *uap) {
- evTimer *t = what;
-
- UNUSED(uap);
-
- FREE(t);
-}
-
-static void
-print_timer(void *what, void *uap) {
- evTimer *cur = what;
- evContext_p *ctx = uap;
-
- cur = what;
- evPrintf(ctx, 7,
- " func %p, uap %p, due %ld.%09ld, inter %ld.%09ld\n",
- cur->func, cur->uap,
- (long)cur->due.tv_sec, cur->due.tv_nsec,
- (long)cur->inter.tv_sec, cur->inter.tv_nsec);
-}
-
-static void
-idle_timeout(evContext opaqueCtx,
- void *uap,
- struct timespec due,
- struct timespec inter
-) {
- evContext_p *ctx = opaqueCtx.opaque;
- idle_timer *this = uap;
- struct timespec idle;
-
- UNUSED(due);
- UNUSED(inter);
-
- idle = evSubTime(ctx->lastEventTime, this->lastTouched);
- if (evCmpTime(idle, this->max_idle) >= 0) {
- (this->func)(opaqueCtx, this->uap, this->timer->due,
- this->max_idle);
- /*
- * Setting the interval to zero will cause the timer to
- * be cleaned up in evDrop().
- */
- this->timer->inter = evConsTime(0, 0);
- FREE(this);
- } else {
- /* evDrop() will reschedule the timer. */
- this->timer->inter = evSubTime(this->max_idle, idle);
- }
-}
diff --git a/contrib/bind/lib/isc/ev_waits.c b/contrib/bind/lib/isc/ev_waits.c
deleted file mode 100644
index 8d9fa8d..0000000
--- a/contrib/bind/lib/isc/ev_waits.c
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- * Copyright (c) 1996-1999 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.
- */
-
-/* ev_waits.c - implement deferred function calls for the eventlib
- * vix 05dec95 [initial]
- */
-
-#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: ev_waits.c,v 8.12 2002/07/08 05:50:10 marka Exp $";
-#endif
-
-#include "port_before.h"
-#include "fd_setsize.h"
-
-#include <errno.h>
-
-#include <isc/eventlib.h>
-#include <isc/assertions.h>
-#include "eventlib_p.h"
-
-#include "port_after.h"
-
-/* Forward. */
-
-static void print_waits(evContext_p *ctx);
-static evWaitList * evNewWaitList(evContext_p *);
-static void evFreeWaitList(evContext_p *, evWaitList *);
-static evWaitList * evGetWaitList(evContext_p *, const void *, int);
-
-
-/* Public. */
-
-/*
- * Enter a new wait function on the queue.
- */
-int
-evWaitFor(evContext opaqueCtx, const void *tag,
- evWaitFunc func, void *uap, evWaitID *id)
-{
- evContext_p *ctx = opaqueCtx.opaque;
- evWait *new;
- evWaitList *wl = evGetWaitList(ctx, tag, 1);
-
- OKNEW(new);
- new->func = func;
- new->uap = uap;
- new->tag = tag;
- new->next = NULL;
- if (wl->last != NULL)
- wl->last->next = new;
- else
- wl->first = new;
- wl->last = new;
- if (id != NULL)
- id->opaque = new;
- if (ctx->debug >= 9)
- print_waits(ctx);
- return (0);
-}
-
-/*
- * Mark runnable all waiting functions having a certain tag.
- */
-int
-evDo(evContext opaqueCtx, const void *tag) {
- evContext_p *ctx = opaqueCtx.opaque;
- evWaitList *wl = evGetWaitList(ctx, tag, 0);
- evWait *first;
-
- if (!wl) {
- errno = ENOENT;
- return (-1);
- }
-
- first = wl->first;
- INSIST(first != NULL);
-
- if (ctx->waitDone.last != NULL)
- ctx->waitDone.last->next = first;
- else
- ctx->waitDone.first = first;
- ctx->waitDone.last = wl->last;
- evFreeWaitList(ctx, wl);
-
- return (0);
-}
-
-/*
- * Remove a waiting (or ready to run) function from the queue.
- */
-int
-evUnwait(evContext opaqueCtx, evWaitID id) {
- evContext_p *ctx = opaqueCtx.opaque;
- evWait *this, *prev;
- evWaitList *wl;
- int found = 0;
-
- this = id.opaque;
- INSIST(this != NULL);
- wl = evGetWaitList(ctx, this->tag, 0);
- if (wl != NULL) {
- for (prev = NULL, this = wl->first;
- this != NULL;
- prev = this, this = this->next)
- if (this == (evWait *)id.opaque) {
- found = 1;
- if (prev != NULL)
- prev->next = this->next;
- else
- wl->first = this->next;
- if (wl->last == this)
- wl->last = prev;
- if (wl->first == NULL)
- evFreeWaitList(ctx, wl);
- break;
- }
- }
-
- if (!found) {
- /* Maybe it's done */
- for (prev = NULL, this = ctx->waitDone.first;
- this != NULL;
- prev = this, this = this->next)
- if (this == (evWait *)id.opaque) {
- found = 1;
- if (prev != NULL)
- prev->next = this->next;
- else
- ctx->waitDone.first = this->next;
- if (ctx->waitDone.last == this)
- ctx->waitDone.last = prev;
- break;
- }
- }
-
- if (!found) {
- errno = ENOENT;
- return (-1);
- }
-
- FREE(this);
-
- if (ctx->debug >= 9)
- print_waits(ctx);
-
- return (0);
-}
-
-int
-evDefer(evContext opaqueCtx, evWaitFunc func, void *uap) {
- evContext_p *ctx = opaqueCtx.opaque;
- evWait *new;
-
- OKNEW(new);
- new->func = func;
- new->uap = uap;
- new->tag = NULL;
- new->next = NULL;
- if (ctx->waitDone.last != NULL)
- ctx->waitDone.last->next = new;
- else
- ctx->waitDone.first = new;
- ctx->waitDone.last = new;
- if (ctx->debug >= 9)
- print_waits(ctx);
- return (0);
-}
-
-/* Private. */
-
-static void
-print_waits(evContext_p *ctx) {
- evWaitList *wl;
- evWait *this;
-
- evPrintf(ctx, 9, "wait waiting:\n");
- for (wl = ctx->waitLists; wl != NULL; wl = wl->next) {
- INSIST(wl->first != NULL);
- evPrintf(ctx, 9, " tag %p:", wl->first->tag);
- for (this = wl->first; this != NULL; this = this->next)
- evPrintf(ctx, 9, " %p", this);
- evPrintf(ctx, 9, "\n");
- }
- evPrintf(ctx, 9, "wait done:");
- for (this = ctx->waitDone.first; this != NULL; this = this->next)
- evPrintf(ctx, 9, " %p", this);
- evPrintf(ctx, 9, "\n");
-}
-
-static evWaitList *
-evNewWaitList(evContext_p *ctx) {
- evWaitList *new;
-
- NEW(new);
- if (new == NULL)
- return (NULL);
- new->first = new->last = NULL;
- new->prev = NULL;
- new->next = ctx->waitLists;
- if (new->next != NULL)
- new->next->prev = new;
- ctx->waitLists = new;
- return (new);
-}
-
-static void
-evFreeWaitList(evContext_p *ctx, evWaitList *this) {
-
- INSIST(this != NULL);
-
- if (this->prev != NULL)
- this->prev->next = this->next;
- else
- ctx->waitLists = this->next;
- if (this->next != NULL)
- this->next->prev = this->prev;
- FREE(this);
-}
-
-static evWaitList *
-evGetWaitList(evContext_p *ctx, const void *tag, int should_create) {
- evWaitList *this;
-
- for (this = ctx->waitLists; this != NULL; this = this->next) {
- if (this->first != NULL && this->first->tag == tag)
- break;
- }
- if (this == NULL && should_create)
- this = evNewWaitList(ctx);
- return (this);
-}
diff --git a/contrib/bind/lib/isc/eventlib.c b/contrib/bind/lib/isc/eventlib.c
deleted file mode 100644
index c7b1272..0000000
--- a/contrib/bind/lib/isc/eventlib.c
+++ /dev/null
@@ -1,676 +0,0 @@
-/*
- * Copyright (c) 1995-1999 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.
- */
-
-/* eventlib.c - implement glue for the eventlib
- * vix 09sep95 [initial]
- */
-
-#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: eventlib.c,v 1.48 2002/07/17 07:37:34 marka Exp $";
-#endif
-
-#include "port_before.h"
-#include "fd_setsize.h"
-
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/stat.h>
-
-#include <errno.h>
-#include <signal.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include <isc/eventlib.h>
-#include <isc/assertions.h>
-#include "eventlib_p.h"
-
-#include "port_after.h"
-
-/* Forward. */
-
-#ifdef NEED_PSELECT
-static int pselect(int, void *, void *, void *,
- struct timespec *,
- const sigset_t *);
-#endif
-
-/* Public. */
-
-int
-evCreate(evContext *opaqueCtx) {
- evContext_p *ctx;
-
- /* Make sure the memory heap is initialized. */
- if (meminit(0, 0) < 0 && errno != EEXIST)
- return (-1);
-
- OKNEW(ctx);
-
- /* Global. */
- ctx->cur = NULL;
-
- /* Debugging. */
- ctx->debug = 0;
- ctx->output = NULL;
-
- /* Connections. */
- ctx->conns = NULL;
- INIT_LIST(ctx->accepts);
-
- /* Files. */
- ctx->files = NULL;
- FD_ZERO(&ctx->rdNext);
- FD_ZERO(&ctx->wrNext);
- FD_ZERO(&ctx->exNext);
- FD_ZERO(&ctx->nonblockBefore);
- ctx->fdMax = -1;
- ctx->fdNext = NULL;
- ctx->fdCount = 0; /* Invalidate {rd,wr,ex}Last. */
- ctx->highestFD = FD_SETSIZE - 1;
-#ifdef EVENTLIB_TIME_CHECKS
- ctx->lastFdCount = 0;
-#endif
- memset(ctx->fdTable, 0, sizeof ctx->fdTable);
-
- /* Streams. */
- ctx->streams = NULL;
- ctx->strDone = NULL;
- ctx->strLast = NULL;
-
- /* Timers. */
- ctx->lastEventTime = evNowTime();
-#ifdef EVENTLIB_TIME_CHECKS
- ctx->lastSelectTime = ctx->lastEventTime;
-#endif
- ctx->timers = evCreateTimers(ctx);
- if (ctx->timers == NULL)
- return (-1);
-
- /* Waits. */
- ctx->waitLists = NULL;
- ctx->waitDone.first = ctx->waitDone.last = NULL;
- ctx->waitDone.prev = ctx->waitDone.next = NULL;
-
- opaqueCtx->opaque = ctx;
- return (0);
-}
-
-void
-evSetDebug(evContext opaqueCtx, int level, FILE *output) {
- evContext_p *ctx = opaqueCtx.opaque;
-
- ctx->debug = level;
- ctx->output = output;
-}
-
-int
-evDestroy(evContext opaqueCtx) {
- evContext_p *ctx = opaqueCtx.opaque;
- int revs = 424242; /* Doug Adams. */
- evWaitList *this_wl, *next_wl;
- evWait *this_wait, *next_wait;
-
- /* Connections. */
- while (revs-- > 0 && ctx->conns != NULL) {
- evConnID id;
-
- id.opaque = ctx->conns;
- (void) evCancelConn(opaqueCtx, id);
- }
- INSIST(revs >= 0);
-
- /* Streams. */
- while (revs-- > 0 && ctx->streams != NULL) {
- evStreamID id;
-
- id.opaque = ctx->streams;
- (void) evCancelRW(opaqueCtx, id);
- }
-
- /* Files. */
- while (revs-- > 0 && ctx->files != NULL) {
- evFileID id;
-
- id.opaque = ctx->files;
- (void) evDeselectFD(opaqueCtx, id);
- }
- INSIST(revs >= 0);
-
- /* Timers. */
- evDestroyTimers(ctx);
-
- /* Waits. */
- for (this_wl = ctx->waitLists;
- revs-- > 0 && this_wl != NULL;
- this_wl = next_wl) {
- next_wl = this_wl->next;
- for (this_wait = this_wl->first;
- revs-- > 0 && this_wait != NULL;
- this_wait = next_wait) {
- next_wait = this_wait->next;
- FREE(this_wait);
- }
- FREE(this_wl);
- }
- for (this_wait = ctx->waitDone.first;
- revs-- > 0 && this_wait != NULL;
- this_wait = next_wait) {
- next_wait = this_wait->next;
- FREE(this_wait);
- }
-
- FREE(ctx);
- return (0);
-}
-
-int
-evGetNext(evContext opaqueCtx, evEvent *opaqueEv, int options) {
- evContext_p *ctx = opaqueCtx.opaque;
- struct timespec nextTime;
- evTimer *nextTimer;
- evEvent_p *new;
- int x, pselect_errno, timerPast;
-#ifdef EVENTLIB_TIME_CHECKS
- struct timespec interval;
-#endif
-
- /* Ensure that exactly one of EV_POLL or EV_WAIT was specified. */
- x = ((options & EV_POLL) != 0) + ((options & EV_WAIT) != 0);
- if (x != 1)
- EV_ERR(EINVAL);
-
- /* Get the time of day. We'll do this again after select() blocks. */
- ctx->lastEventTime = evNowTime();
-
- again:
- /* Finished accept()'s do not require a select(). */
- if (!EMPTY(ctx->accepts)) {
- OKNEW(new);
- new->type = Accept;
- new->u.accept.this = HEAD(ctx->accepts);
- UNLINK(ctx->accepts, HEAD(ctx->accepts), link);
- opaqueEv->opaque = new;
- return (0);
- }
-
- /* Stream IO does not require a select(). */
- if (ctx->strDone != NULL) {
- OKNEW(new);
- new->type = Stream;
- new->u.stream.this = ctx->strDone;
- ctx->strDone = ctx->strDone->nextDone;
- if (ctx->strDone == NULL)
- ctx->strLast = NULL;
- opaqueEv->opaque = new;
- return (0);
- }
-
- /* Waits do not require a select(). */
- if (ctx->waitDone.first != NULL) {
- OKNEW(new);
- new->type = Wait;
- new->u.wait.this = ctx->waitDone.first;
- ctx->waitDone.first = ctx->waitDone.first->next;
- if (ctx->waitDone.first == NULL)
- ctx->waitDone.last = NULL;
- opaqueEv->opaque = new;
- return (0);
- }
-
- /* Get the status and content of the next timer. */
- if ((nextTimer = heap_element(ctx->timers, 1)) != NULL) {
- nextTime = nextTimer->due;
- timerPast = (evCmpTime(nextTime, ctx->lastEventTime) <= 0);
- } else
- timerPast = 0; /* Make gcc happy. */
-
- evPrintf(ctx, 9, "evGetNext: fdCount %d\n", ctx->fdCount);
- if (ctx->fdCount == 0) {
- static const struct timespec NoTime = {0, 0L};
- enum { JustPoll, Block, Timer } m;
- struct timespec t, *tp;
-
- /* Are there any events at all? */
- if ((options & EV_WAIT) != 0 && !nextTimer && ctx->fdMax == -1)
- EV_ERR(ENOENT);
-
- /* Figure out what select()'s timeout parameter should be. */
- if ((options & EV_POLL) != 0) {
- m = JustPoll;
- t = NoTime;
- tp = &t;
- } else if (nextTimer == NULL) {
- m = Block;
- /* ``t'' unused. */
- tp = NULL;
- } else if (timerPast) {
- m = JustPoll;
- t = NoTime;
- tp = &t;
- } else {
- m = Timer;
- /* ``t'' filled in later. */
- tp = &t;
- }
-#ifdef EVENTLIB_TIME_CHECKS
- if (ctx->debug > 0) {
- interval = evSubTime(ctx->lastEventTime,
- ctx->lastSelectTime);
- if (interval.tv_sec > 0)
- evPrintf(ctx, 1,
- "time between pselect() %u.%09u count %d\n",
- interval.tv_sec, interval.tv_nsec,
- ctx->lastFdCount);
- }
-#endif
- do {
- /* XXX need to copy only the bits we are using. */
- ctx->rdLast = ctx->rdNext;
- ctx->wrLast = ctx->wrNext;
- ctx->exLast = ctx->exNext;
-
- if (m == Timer) {
- INSIST(tp == &t);
- t = evSubTime(nextTime, ctx->lastEventTime);
- }
-
- evPrintf(ctx, 4,
- "pselect(%d, 0x%lx, 0x%lx, 0x%lx, %ld.%09ld)\n",
- ctx->fdMax+1,
- (u_long)ctx->rdLast.fds_bits[0],
- (u_long)ctx->wrLast.fds_bits[0],
- (u_long)ctx->exLast.fds_bits[0],
- tp ? (long)tp->tv_sec : -1L,
- tp ? tp->tv_nsec : -1);
-
- /* XXX should predict system's earliness and adjust. */
- x = pselect(ctx->fdMax+1,
- &ctx->rdLast, &ctx->wrLast, &ctx->exLast,
- tp, NULL);
- pselect_errno = errno;
-
- evPrintf(ctx, 4, "select() returns %d (err: %s)\n",
- x, (x == -1) ? strerror(errno) : "none");
-
- /* Anything but a poll can change the time. */
- if (m != JustPoll)
- ctx->lastEventTime = evNowTime();
-
- /* Select() likes to finish about 10ms early. */
- } while (x == 0 && m == Timer &&
- evCmpTime(ctx->lastEventTime, nextTime) < 0);
-#ifdef EVENTLIB_TIME_CHECKS
- ctx->lastSelectTime = ctx->lastEventTime;
-#endif
- if (x < 0) {
- if (pselect_errno == EINTR) {
- if ((options & EV_NULL) != 0)
- goto again;
- OKNEW(new);
- new->type = Null;
- /* No data. */
- opaqueEv->opaque = new;
- return (0);
- }
- if (pselect_errno == EBADF) {
- for (x = 0; x <= ctx->fdMax; x++) {
- struct stat sb;
-
- if (FD_ISSET(x, &ctx->rdNext) == 0 &&
- FD_ISSET(x, &ctx->wrNext) == 0 &&
- FD_ISSET(x, &ctx->exNext) == 0)
- continue;
- if (fstat(x, &sb) == -1 &&
- errno == EBADF)
- evPrintf(ctx, 1, "EBADF: %d\n",
- x);
- }
- abort();
- }
- EV_ERR(pselect_errno);
- }
- if (x == 0 && (nextTimer == NULL || !timerPast) &&
- (options & EV_POLL))
- EV_ERR(EWOULDBLOCK);
- ctx->fdCount = x;
-#ifdef EVENTLIB_TIME_CHECKS
- ctx->lastFdCount = x;
-#endif
- }
- INSIST(nextTimer || ctx->fdCount);
-
- /* Timers go first since we'd like them to be accurate. */
- if (nextTimer && !timerPast) {
- /* Has anything happened since we blocked? */
- timerPast = (evCmpTime(nextTime, ctx->lastEventTime) <= 0);
- }
- if (nextTimer && timerPast) {
- OKNEW(new);
- new->type = Timer;
- new->u.timer.this = nextTimer;
- opaqueEv->opaque = new;
- return (0);
- }
-
- /* No timers, so there should be a ready file descriptor. */
- x = 0;
- while (ctx->fdCount > 0) {
- evFile *fid;
- int fd, eventmask;
-
- if (ctx->fdNext == NULL) {
- if (++x == 2) {
- /*
- * Hitting the end twice means that the last
- * select() found some FD's which have since
- * been deselected.
- *
- * On some systems, the count returned by
- * selects is the total number of bits in
- * all masks that are set, and on others it's
- * the number of fd's that have some bit set,
- * and on others, it's just broken. We
- * always assume that it's the number of
- * bits set in all masks, because that's what
- * the man page says it should do, and
- * the worst that can happen is we do an
- * extra select().
- */
- ctx->fdCount = 0;
- break;
- }
- ctx->fdNext = ctx->files;
- }
- fid = ctx->fdNext;
- ctx->fdNext = fid->next;
-
- fd = fid->fd;
- eventmask = 0;
- if (FD_ISSET(fd, &ctx->rdLast))
- eventmask |= EV_READ;
- if (FD_ISSET(fd, &ctx->wrLast))
- eventmask |= EV_WRITE;
- if (FD_ISSET(fd, &ctx->exLast))
- eventmask |= EV_EXCEPT;
- eventmask &= fid->eventmask;
- if (eventmask != 0) {
- if ((eventmask & EV_READ) != 0) {
- FD_CLR(fd, &ctx->rdLast);
- ctx->fdCount--;
- }
- if ((eventmask & EV_WRITE) != 0) {
- FD_CLR(fd, &ctx->wrLast);
- ctx->fdCount--;
- }
- if ((eventmask & EV_EXCEPT) != 0) {
- FD_CLR(fd, &ctx->exLast);
- ctx->fdCount--;
- }
- OKNEW(new);
- new->type = File;
- new->u.file.this = fid;
- new->u.file.eventmask = eventmask;
- opaqueEv->opaque = new;
- return (0);
- }
- }
- if (ctx->fdCount < 0) {
- /*
- * select()'s count is off on a number of systems, and
- * can result in fdCount < 0.
- */
- evPrintf(ctx, 4, "fdCount < 0 (%d)\n", ctx->fdCount);
- ctx->fdCount = 0;
- }
-
- /* We get here if the caller deselect()'s an FD. Gag me with a goto. */
- goto again;
-}
-
-int
-evDispatch(evContext opaqueCtx, evEvent opaqueEv) {
- evContext_p *ctx = opaqueCtx.opaque;
- evEvent_p *ev = opaqueEv.opaque;
-#ifdef EVENTLIB_TIME_CHECKS
- void *func;
- struct timespec start_time;
- struct timespec interval;
-#endif
-
-#ifdef EVENTLIB_TIME_CHECKS
- if (ctx->debug > 0)
- start_time = evNowTime();
-#endif
- ctx->cur = ev;
- switch (ev->type) {
- case Accept: {
- evAccept *this = ev->u.accept.this;
-
- evPrintf(ctx, 5,
- "Dispatch.Accept: fd %d -> %d, func %p, uap %p\n",
- this->conn->fd, this->fd,
- this->conn->func, this->conn->uap);
- errno = this->ioErrno;
- (this->conn->func)(opaqueCtx, this->conn->uap, this->fd,
- &this->la, this->lalen,
- &this->ra, this->ralen);
-#ifdef EVENTLIB_TIME_CHECKS
- func = this->conn->func;
-#endif
- break;
- }
- case File: {
- evFile *this = ev->u.file.this;
- int eventmask = ev->u.file.eventmask;
-
- evPrintf(ctx, 5,
- "Dispatch.File: fd %d, mask 0x%x, func %p, uap %p\n",
- this->fd, this->eventmask, this->func, this->uap);
- (this->func)(opaqueCtx, this->uap, this->fd, eventmask);
-#ifdef EVENTLIB_TIME_CHECKS
- func = this->func;
-#endif
- break;
- }
- case Stream: {
- evStream *this = ev->u.stream.this;
-
- evPrintf(ctx, 5,
- "Dispatch.Stream: fd %d, func %p, uap %p\n",
- this->fd, this->func, this->uap);
- errno = this->ioErrno;
- (this->func)(opaqueCtx, this->uap, this->fd, this->ioDone);
-#ifdef EVENTLIB_TIME_CHECKS
- func = this->func;
-#endif
- break;
- }
- case Timer: {
- evTimer *this = ev->u.timer.this;
-
- evPrintf(ctx, 5, "Dispatch.Timer: func %p, uap %p\n",
- this->func, this->uap);
- (this->func)(opaqueCtx, this->uap, this->due, this->inter);
-#ifdef EVENTLIB_TIME_CHECKS
- func = this->func;
-#endif
- break;
- }
- case Wait: {
- evWait *this = ev->u.wait.this;
-
- evPrintf(ctx, 5,
- "Dispatch.Wait: tag %p, func %p, uap %p\n",
- this->tag, this->func, this->uap);
- (this->func)(opaqueCtx, this->uap, this->tag);
-#ifdef EVENTLIB_TIME_CHECKS
- func = this->func;
-#endif
- break;
- }
- case Null: {
- /* No work. */
-#ifdef EVENTLIB_TIME_CHECKS
- func = NULL;
-#endif
- break;
- }
- default: {
- abort();
- }
- }
-#ifdef EVENTLIB_TIME_CHECKS
- if (ctx->debug > 0) {
- interval = evSubTime(evNowTime(), start_time);
- /*
- * Complain if it took longer than 50 milliseconds.
- *
- * We call getuid() to make an easy to find mark in a kernel
- * trace.
- */
- if (interval.tv_sec > 0 || interval.tv_nsec > 50000000)
- evPrintf(ctx, 1,
- "dispatch interval %u.%09u uid %d type %d func %p\n",
- interval.tv_sec, interval.tv_nsec,
- getuid(), ev->type, func);
- }
-#endif
- ctx->cur = NULL;
- evDrop(opaqueCtx, opaqueEv);
- return (0);
-}
-
-void
-evDrop(evContext opaqueCtx, evEvent opaqueEv) {
- evContext_p *ctx = opaqueCtx.opaque;
- evEvent_p *ev = opaqueEv.opaque;
-
- switch (ev->type) {
- case Accept: {
- FREE(ev->u.accept.this);
- break;
- }
- case File: {
- /* No work. */
- break;
- }
- case Stream: {
- evStreamID id;
-
- id.opaque = ev->u.stream.this;
- (void) evCancelRW(opaqueCtx, id);
- break;
- }
- case Timer: {
- evTimer *this = ev->u.timer.this;
- evTimerID opaque;
-
- /* Check to see whether the user func cleared the timer. */
- if (heap_element(ctx->timers, this->index) != this) {
- evPrintf(ctx, 5, "Dispatch.Timer: timer rm'd?\n");
- break;
- }
- /*
- * Timer is still there. Delete it if it has expired,
- * otherwise set it according to its next interval.
- */
- if (this->inter.tv_sec == 0 && this->inter.tv_nsec == 0L) {
- opaque.opaque = this;
- (void) evClearTimer(opaqueCtx, opaque);
- } else {
- opaque.opaque = this;
- (void) evResetTimer(opaqueCtx, opaque, this->func,
- this->uap,
- evAddTime(ctx->lastEventTime,
- this->inter),
- this->inter);
- }
- break;
- }
- case Wait: {
- FREE(ev->u.wait.this);
- break;
- }
- case Null: {
- /* No work. */
- break;
- }
- default: {
- abort();
- }
- }
- FREE(ev);
-}
-
-int
-evMainLoop(evContext opaqueCtx) {
- evEvent event;
- int x;
-
- while ((x = evGetNext(opaqueCtx, &event, EV_WAIT)) == 0)
- if ((x = evDispatch(opaqueCtx, event)) < 0)
- break;
- return (x);
-}
-
-int
-evHighestFD(evContext opaqueCtx) {
- evContext_p *ctx = opaqueCtx.opaque;
-
- return (ctx->highestFD);
-}
-
-void
-evPrintf(const evContext_p *ctx, int level, const char *fmt, ...) {
- va_list ap;
-
- va_start(ap, fmt);
- if (ctx->output != NULL && ctx->debug >= level) {
- vfprintf(ctx->output, fmt, ap);
- fflush(ctx->output);
- }
- va_end(ap);
-}
-
-#ifdef NEED_PSELECT
-/* XXX needs to move to the porting library. */
-static int
-pselect(int nfds, void *rfds, void *wfds, void *efds,
- struct timespec *tsp,
- const sigset_t *sigmask)
-{
- struct timeval tv, *tvp;
- sigset_t sigs;
- int n;
-
- if (tsp) {
- tvp = &tv;
- tv = evTimeVal(*tsp);
- } else
- tvp = NULL;
- if (sigmask)
- sigprocmask(SIG_SETMASK, sigmask, &sigs);
- n = select(nfds, rfds, wfds, efds, tvp);
- if (sigmask)
- sigprocmask(SIG_SETMASK, &sigs, NULL);
- if (tsp)
- *tsp = evTimeSpec(tv);
- return (n);
-}
-#endif
diff --git a/contrib/bind/lib/isc/eventlib.mdoc b/contrib/bind/lib/isc/eventlib.mdoc
deleted file mode 100644
index e95871c..0000000
--- a/contrib/bind/lib/isc/eventlib.mdoc
+++ /dev/null
@@ -1,853 +0,0 @@
-.\" $Id: eventlib.mdoc,v 1.22 2001/12/28 04:24:22 marka Exp $
-.\"
-.\"Copyright (c) 1995-1999 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.
-.\"
-.Dd March 6, 1996
-.Dt EVENTLIB 3
-.Os BSD 4
-.Sh NAME
-.Nm evConnFunc ,
-.Nm evFileFunc ,
-.Nm evStreamFunc ,
-.Nm evTimerFunc ,
-.Nm evWaitFunc ,
-.Nm evCreate ,
-.Nm evDestroy ,
-.Nm evGetNext ,
-.Nm evDispatch ,
-.Nm evDrop ,
-.Nm evMainLoop ,
-.Nm evConsTime ,
-.Nm evTimeSpec ,
-.Nm evTimeVal ,
-.Nm evAddTime ,
-.Nm evSubTime ,
-.Nm evCmpTime ,
-.Nm evNowTime ,
-.Nm evLastEventTime ,
-.Nm evSetTimer ,
-.Nm evResetTimer ,
-.Nm evClearTimer ,
-.Nm evSetIdleTimer ,
-.Nm evTouchIdleTimer ,
-.Nm evClearIdleTimer ,
-.Nm evWaitFor ,
-.Nm evDo ,
-.Nm evUnwait ,
-.Nm evDefer ,
-.Nm evSelectFD ,
-.Nm evDeselectFD ,
-.Nm evWrite ,
-.Nm evRead ,
-.Nm evCancelRW ,
-.Nm evTimeRW ,
-.Nm evUntimeRW ,
-.Nm evListen ,
-.Nm evConnect ,
-.Nm evCancelConn ,
-.Nm evHold ,
-.Nm evUnhold ,
-.Nm evTryAccept ,
-.Nm evConsIovec ,
-.Nm evSetDebug ,
-.Nm evPrintf ,
-.Nm evInitID ,
-.Nm evTestID
-.Nd event handling library
-.Sh SYNOPSIS
-.Fd #include <isc/eventlib.h>
-.Ft typedef void
-.Fn \*(lp*evConnFunc\*(rp "evContext ctx" "void *uap" "int fd" \
-"const void *la" "int lalen" "const void *ra" "int ralen"
-.Ft typedef void
-.Fn \*(lp*evTimerFunc\*(rp "evContext ctx" "void *uap" \
-"struct timespec due" "struct timespec inter"
-.Ft typedef void
-.Fn \*(lp*evFileFunc\*(rp "evContext ctx" "void *uap" "int fd" "int eventmask"
-.Ft typedef void
-.Fn \*(lp*evStreamFunc\*(rp "evContext ctx" "void *uap" "int fd" "int bytes"
-.Ft typedef void
-.Fn \*(lp*evWaitFunc\*(rp "evContext ctx" "void *uap" "const void *tag"
-.Ft int
-.Fn evCreate "evContext *ctx"
-.Ft int
-.Fn evDestroy "evContext ctx"
-.Ft int
-.Fn evGetNext "evContext ctx" "evEvent *ev" "int options"
-.Ft int
-.Fn evDispatch "evContext ctx" "evEvent ev"
-.Ft void
-.Fn evDrop "evContext ctx" "evEvent ev"
-.Ft int
-.Fn evMainLoop "evContext ctx"
-.Ft struct timespec
-.Fn evConsTime "int sec" "int usec"
-.Ft struct timespec
-.Fn evTimeSpec "struct timeval tv"
-.Ft struct timeval
-.Fn evTimeVal "struct timespec ts"
-.Ft struct timespec
-.Fn evAddTime "struct timespec addend1" "struct timespec addend2"
-.Ft struct timespec
-.Fn evSubTime "struct timespec minuend" "struct timespec subtrahend"
-.Ft struct timespec
-.Fn evCmpTime "struct timespec a" "struct timespec b"
-.Ft struct timespec
-.Fn evNowTime "void"
-.Ft struct timespec
-.Fn evLastEventTime "evContext opaqueCtx"
-.Ft int
-.Fn evSetTimer "evContext ctx" "evTimerFunc func" "void *uap" \
-"struct timespec due" "struct timespec inter" "evTimerID *id"
-.Ft int
-.Fn evResetTimer "evContext ctx" "evTimerID id" "evTimerFunc func" \
-"void *uap" "struct timespec due" "struct timespec inter"
-.Ft int
-.Fn evClearTimer "evContext ctx" "evTimerID id"
-.Ft int
-.Fn evSetIdleTimer "evContext opaqueCtx" "evTimerFunc func" "void *uap" \
-"struct timespec max_idle" "evTimerID *opaqueID"
-.Ft int
-.Fn evTouchIdleTimer "evContext opaqueCtx" "evTimerID id"
-.Ft int
-.Fn evResetIdleTimer "evContext opaqueCtx" "evTimerID id" "evTimerFunc func" \
-"void *uap" "struct timespec max_idle"
-.Ft int
-.Fn evClearIdleTimer "evContext opaqueCtx" "evTimerID id"
-.Ft int
-.Fn evWaitFor "evContext opaqueCtx" "const void *tag" \
-"evWaitFunc func" "void *uap" "evWaitID *id"
-.Ft int
-.Fn evDo "evContext opaqueCtx" "const void *tag"
-.Ft int
-.Fn evUnwait "evContext opaqueCtx" "evWaitID id"
-.Ft int
-.Fn evDefer "evContext opaqueCtx" "evWaitFunc func" "void *uap"
-.Ft int
-.Fn evSelectFD "evContext ctx" "int fd" "int eventmask" \
-"evFileFunc func" "void *uap" "evFileID *id"
-.Ft int
-.Fn evDeselectFD "evContext ctx" "evFileID id"
-.Ft struct iovec
-.Fn evConsIovec "void *buf" "size_t cnt"
-.Ft int
-.Fn evWrite "evContext ctx" "int fd" "const struct iovec *iov" "int cnt" \
-"evStreamFunc func" "void *uap" "evStreamID *id"
-.Ft int
-.Fn evRead "evContext ctx" "int fd" "const struct iovec *iov" "int cnt" \
-"evStreamFunc func" "void *uap" "evStreamID *id"
-.Ft int
-.Fn evCancelRW "evContext ctx" "evStreamID id"
-.Ft int
-.Fn evTimeRW "evContext opaqueCtx" "evStreamID id" "evTimerID timer"
-.Ft int
-.Fn evUntimeRW "evContext opaqueCtx" "evStreamID id"
-.Ft int
-.Fn evListen "evContext ctx" "int fd" "int maxconn" \
-"evConnFunc func" "void *uap" "evConnID *id"
-.Ft int
-.Fn evConnect "evContext ctx" "int fd" "void *ra" "int ralen" \
-"evConnFunc func" "void *uap" "evConnID *id"
-.Ft int
-.Fn evCancelConn "evContext ctx" "evConnID id"
-.Ft int
-.Fn evHold "evContext ctx" "evConnID id"
-.Ft int
-.Fn evUnhold "evContext ctx" "evConnID id"
-.Ft int
-.Fn evTryAccept "evContext ctx" "evConnID id" "int *sys_errno"
-.Ft void
-.Fn evSetDebug "evContext ctx" "int level" "FILE *output"
-.Ft void
-.Fn evPrintf "const evContext_p *ctx" "int level" "const char *fmt" "..."
-.Ft void
-.Fn evInitID "*\s-1ID\s+1"
-.Ft int
-.Fn evTestID "\s-1ID\s+1"
-.Sh DESCRIPTION
-This library provides multiple outstanding asynchronous timers and I/O
-to a cooperating application. The model is similar to that of the X
-Toolkit, in that events are registered with the library and the application
-spends most of its time in the
-.Fn evMainLoop
-function. If an application already has a main loop, it can safely register
-events with this library as long as it periodically calls the
-.Fn evGetNext
-and
-.Fn evDispatch
-functions. (Note that
-.Fn evGetNext
-has both polling and blocking modes.)
-.Pp
-The function
-.Fn evCreate
-creates an event context which is needed by all the other functions in this
-library. All information used internally by this library is bound to this
-context, rather than to static storage. This makes the library
-.Dq thread safe ,
-and permits other library functions to use events without
-disrupting the application's use of events.
-.Pp
-The function
-.Fn evDestroy
-destroys a context that has been created by
-.Fn evCreate .
-All dynamic memory bound to this context will be freed. An implicit
-.Fn evTimerClear
-will be done on all timers set in this event context. An implicit
-.Fn evDeselectFD
-will be done on all file descriptors selected in this event context.
-.Pp
-The function
-.Fn evGetNext
-potentially waits for and then retrieves the next asynchronous event,
-placing it in the object of the
-.Fa ev
-pointer argument. The following
-.Fa options
-are available:
-.Fa EV_POLL ,
-meaning that
-.Fn evGetNext
-should not block, but rather return
-.Dq Fa -1
-with
-.Fa errno
-set to
-.Fa EWOULDBLOCK
-if no events have occurred;
-.Fa EV_WAIT ,
-which tells
-.Fn evGetNext
-to block internally until the next event occurs; and
-.Fa EV_NULL ,
-which tells
-.Fn evGetNext
-that it should return a special
-.Dq no-op
-event, which is ignored by
-.Fn evDispatch
-but handled correctly by
-.Fn evDrop .
-.Fa EV_NULL
-can be necessary to the correct functioning of a caller\-written equivilent to
-.Fn evMainLoop ,
-wherein perterbations caused by external system events must be polled for, and
-the default behaviour of internally ignoring such events is undesirable.
-Note that
-.Fa EV_POLL
-and
-.Fa EV_WAIT
-are mutually exclusive.
-.Pp
-The function
-.Fn evDispatch
-dispatches an event retrieved by
-.Fn evGetNext .
-This usually involves calling the function that was associated with the event
-when the event was registered with
-.Fn evSetTimer ,
-.Fn evResetTimer ,
-or
-.Fn evSelectFD .
-All events retrieved by
-.Fn evGetNext
-must be given over to
-.Fn evDispatch
-at some point, since there is some dynamic memory associated with each event.
-.Pp
-The function
-.Fn evDrop
-deallocates dynamic memory that has been allocated by
-.Fn evGetNext .
-Calling
-.Fn evDispatch
-has the side effect of calling
-.Fn evDrop ,
-but if you are going to drop the event rather than dispatch it, you will have
-to call
-.Fn evDrop
-directly.
-.Pp
-The function
-.Fn evMainLoop
-is just:
-.Bd -literal -offset indent
-while ((x = evGetNext(opaqueCtx, &event, EV_WAIT)) == 0)
- if ((x = evDispatch(opaqueCtx, event)) < 0)
- break;
-return (x);
-.Ed
-.Pp
-In other words, get events and dispatch them until an error occurs. One such
-error would be that all the events under this context become unregistered; in
-that event, there will be nothing to wait for and
-.Fn evGetNext
-becomes an undefined operation.
-.Pp
-The function
-.Fn evConsTime
-is a constructor for
-.Dq Fa struct timespec
-which allows these structures to be created and then passed as arguments to
-other functions without the use of temporary variables. (If C had inline
-constructors, there would be no need for this function.)
-.Pp
-The functions
-.Fn evTimeSpec
-and
-.Fn evTimeVal
-are utilities which allow the caller to convert a
-.Dq Fa struct timeval
-to a
-.Dq Fa struct timespec
-(the function of
-.Fn evTimeSpec )
-or vice versa (the function of
-.Fn evTimeVal ) .
-Note that the name of the function indicates the type of the return value.
-.Pp
-The function
-.Fn evAddTime
-adds two
-.Dq Fa struct timespec
-values and returns the result as a
-.Dq Fa struct timespec .
-.Pp
-The function
-.Fn evSubTime
-subtracts its second
-.Dq Fa struct timespec
-argument from its first
-.Dq Fa struct timespec
-argument and returns the result as a
-.Dq Fa struct timespec .
-.Pp
-The function
-.Fn evCmpTime
-compares its two
-.Dq Fa struct timespec
-arguments and returns an
-.Dq Fa int
-that is less than zero if the first argument specifies an earlier time than
-the second, or more than zero if the first argument specifies a later time
-than the second, or equal to zero if both arguments specify the same time.
-.Pp
-The function
-.Fn evNowTime
-returns a
-.Dq Fa struct timespec
-which either describes the current time (using
-.Xr gettimeofday 2 ) ,
-if successful, or has its fields set to zero, if there is an error.
-(In the latter case, the caller can check
-.Va errno ,
-since it will be set by
-.Xr gettimeofday 2 . )
-.Pp
-The function
-.Fn evLastEventTime
-returns the
-.Dq Fa struct timespec
-which describes the last time that certain events happened to the
-event context indicated by
-.Fa opaqueCtx .
-This value is updated by
-.Fn evCreate
-and
-.Fn evGetNext
-(upon entry and after
-.Xr select 2
-returns); it is routinely compared with other times in the internal handling
-of, e.g., timers.
-.Pp
-The function
-.Fn evSetTimer
-registers a timer event, which will be delivered as a function call to the
-function specified by the
-.Fa func
-argument. The event will be delivered at absolute time
-.Fa due ,
-and then if time
-.Fa inter
-is not equal to
-.Dq Fn evConsTime 0 0 ,
-subsequently at intervals equal to time
-.Fa inter .
-As a special case, specifying a
-.Fa due
-argument equal to
-.Dq Fn evConsTime 0 0
-means
-.Dq due immediately .
-The
-.Fa opaqueID
-argument, if specified as a value other than
-.Fa NULL ,
-will be used to store the resulting
-.Dq timer \s-1ID\s+1 ,
-useful as an argument to
-.Fn evClearTimer .
-Note that in a
-.Dq one\-shot
-timer (which has an
-.Fa inter
-argument equal to
-.Dq Fa evConsTime(0,0) )
-the user function
-.Fa func
-should deallocate any dynamic memory that is uniquely bound to the
-.Fa uap ,
-since no handles to this memory will exist within the event library
-after a one\-shot timer has been delivered.
-.Pp
-The function
-.Fn evResetTimer
-resets the values of the timer specified by
-.Fa id
-to the given arguments. The arguments are the same as in the description of
-.Fn evSetTimer
-above.
-.Pp
-The function
-.Fn evClearTimer
-will unregister the timer event specified by
-.Fa id .
-Note that if the
-.Fa uap
-specified in the corresponding
-.Fn evSetTimer
-call is uniquely bound to any dynamic memory, then that dynamic memory should
-be freed by the caller before the handle is lost. After a call to
-.Fn evClearTimer ,
-no handles to this
-.Fa uap
-will exist within the event library.
-.Pp
-The function
-.Fn evSetIdleTimer
-is similar to (and built on)
-.Fn evSetTimer ;
-it registers an idle timer event which provides for the function call to
-.Fa func
-to occur. However, for an
-.Em idle
-timer, the call will occur after at least
-.Dq Fa max_idle
-time has passed since the time the idle timer was
-.Dq last touched ;
-originally, this is set to the time returned by
-.Fn evLastEventTime
-(described above) for the event context specified by
-.Fa opaqueCtx .
-This is a
-.Dq one\-shot
-timer, but the time at which the
-.Fa func
-is actually called can be changed by recourse to
-.Fn evTouchIdleTimer
-(described below). The pointer to the underlying
-.Dq timer \s-1ID\s+1
-is returned in
-.Fa opaqueID ,
-if it is
-.No non- Ns Dv NULL .
-.Pp
-The
-.Fn evTouchIdleTimer
-function updates the idle timer associated with
-.Fa id ,
-setting its idea of the time it was last accessed to the value returned by
-.Fn evLastEventTime
-(described above) for the event context specified by
-.Fa opaqueCtx .
-This means that the idle timer will expire after at least
-.Fa max_idle
-time has passed since this (possibly new) time, providing a caller mechanism
-for resetting the call to the
-.Fa func
-associated with the idle timer. (See the description of
-.Fn evSetIdleTimer ,
-above, for information about
-.Fa func
-and
-.Fa max_idle . )
-.Pp
-The
-.Fn evResetIdleTimer
-function reschedules a timer and resets the callback function and its argument.
-Note that resetting a timer also ``touches'' it.
-.Pp
-The
-.Fn evClearIdleTimer
-function unregisters the idle timer associated with
-.Fa id .
-See the discussion under
-.Fn evClearTimer ,
-above, for information regarding caller handling of the
-.Fa uap
-associated with the corresponding
-.Fn evSetIdleTimer
-call.
-.Pp
-The function
-.Fn evWaitFor
-places the function
-.Fa func
-on the given event context's wait queue with the associated (possibly
-.Dv NULL )
-.Dq Fa tag ;
-if
-.Fa id
-is
-.No non- Ns Dv NULL ,
-then it will contain the
-.Dq wait \s-1ID\s+1
-associated with the created queue element.
-.Pp
-The function
-.Fn evDo
-marks
-.Em all
-of the
-.Dq waiting
-functions in the given event context's wait queue with the associated (possibly
-.Dv NULL )
-.Dq Fa tag
-as runnable. This places these functions in a
-.Dq done
-queue which will be read by
-.Fn evGetNext .
-.Pp
-The function
-.Fn evUnwait
-will search for the
-.Dq wait \s-1ID\s+1
-.Fa id
-in the wait queue of the given event context; if an element with the given
-.Fa id
-is not found, then the
-.Dq done
-queue of that context is searched. If found, the queue element is removed
-from the appropriate list.
-.Pp
-The function
-.Fn evDefer
-causes a function (specified as
-.Fa func ,
-with argument
-.Fa uap )
-to be dispatched at some later time. Note that the
-.Fa tag
-argument to
-.Fa func
-will always be
-.Fa NULL
-when dispatched.
-.Pp
-The function
-.Fn evSelectFD
-registers a file I/O event for the file descriptor specified by
-.Fa fd .
-Bits in the
-.Fa eventmask
-argument are named
-.Fa EV_READ ,
-.Fa EV_WRITE ,
-and
-.Fa EV_EXCEPT .
-At least one of these bits must be specified. If the
-.Fa id
-argument is not equal to
-.Fa NULL ,
-it will be used to store a unique ``file event \s-1ID\s+1'' for this event,
-which is useful in subsequent calls to
-.Fn evDeselectFD .
-A file descriptor will be made nonblocking using the
-.Fa O_NONBLOCK
-flag with
-.Xr fcntl 2
-on its first concurrent registration via
-.Fn evSelectFD .
-An
-.Fn evSelectFD
-remains in effect until cancelled via
-.Fn evDeselectFD .
-.Pp
-The function
-.Fn evDeselectFD
-unregisters the ``file event'' specified by the
-.Fa id
-argument. If the corresponding
-.Fa uap
-uniquely points to dynamic memory, that memory should be freed before its
-handle is lost, since after a call to
-.Fn evDeselectFD ,
-no handles to this event's
-.Fa uap
-will remain within the event library. A file descriptor will be taken out of
-nonblocking mode (see
-.Fa O_NONBLOCK
-and
-.Xr fcntl 2 )
-when its last event registration is removed via
-.Fn evDeselectFD ,
-if it was in blocking mode before the first registration via
-.Fn evSelectFD .
-.Pp
-The function
-.Fn evConsIovec
-is a constructor for a single
-.Ft struct iovec
-structure, which is useful for
-.Fn evWrite
-and
-.Fn evRead .
-.Pp
-The functions
-.Fn evWrite
-and
-.Fn evRead
-start asynchronous stream I/O operations on file descriptor
-.Fa fd .
-The data to be written or read is in the scatter/gather descriptor specified by
-.Fa iov
-and
-.Fa cnt .
-The supplied function
-.Fa func
-will be called with argument
-.Fa uap
-when the I/O operation is complete. If
-.Fa id
-is not
-.Fa NULL ,
-it will be filled a with the stream event identifier suitable for use with
-.Fn evCancelRW .
-.Pp
-The function
-.Fn evCancelRW
-extinguishes an outstanding
-.Fn evWrite
-or
-.Fn evRead
-call. System I/O calls cannot always be cancelled, but you are guaranteed
-that the
-.Fa func
-function supplied to
-.Fn evWrite
-or
-.Fn evRead
-will not be called after a call to
-.Fn evCancelRW .
-Care should be taken not to deallocate or otherwise reuse the space pointed
-to by the segment descriptors in
-.Fa iov
-unless the underlying file descriptor is closed first.
-.Pp
-The function
-.Fn evTimeRW
-sets the stream associated with the given stream \s-1ID\s+1
-.Dq Fa id
-to have the idle timer associated with the timer \s-1ID\s+1
-.Dq Fa timer .
-.Pp
-The function
-.Fn evUntimeRW
-says that the stream associated with the given stream \s-1ID\s+1
-.Dq Fa id
-should ignore its idle timer, if present.
-.Pp
-The functions
-.Fn evListen ,
-.Fn evConnect ,
-and
-.Fn evCancelConn
-can be used to manage asynchronous incoming and outgoing socket connections.
-Sockets to be used with these functions should first be created with
-.Xr socket 2
-and given a local name with
-.Xr bind 2 .
-It is extremely unlikely that the same socket will ever be
-useful for both incoming and outgoing connections. The
-.Fa id
-argument to
-.Fn evListen
-and
-.Fn evConnect
-is either
-.Fa NULL
-or the address of a
-.Ft evFileID
-variable which can then be used in a subsequent call to
-.Fn evCancelConn .
-.Pp
-After a call to
-.Fn evListen ,
-each incoming connection arriving on
-.Fa fd
-will cause
-.Fa func
-to be called with
-.Fa uap
-as one of its arguments.
-.Fn evConnect
-initiates an outgoing connection on
-.Fa fd
-to destination address
-.Fa ra
-(whose length is
-.Fa ralen ) .
-When the connection is complete,
-.Fa func
-will be called with
-.Fa uap
-as one of its arguments. The argument
-.Fa fd
-to
-.Fn \*(lp*func\*(rp
-will be
-.Fa -1
-if an error occurred that prevented this connection from completing
-successfully. In this case
-.Fn errno
-will have been set and the socket described by
-.Fa fd
-will have been closed. The
-.Fn evCancelConn
-function will prevent delivery of all pending and subsequent
-events for the outstanding connection. The
-.Fn evHold
-function will suspend the acceptance of new connections on the listener
-specified by
-.Fa id .
-Connections will be queued by the protocol stack up to the system's limit. The
-.Fn evUnhold
-function will reverse the effects of
-.Fn evHold ,
-allowing incoming connections to be delivered for listener
-.Fa id .
-The
-.Fn evTryAccept
-function will poll the listener specified by
-.Fa id ,
-accepting a new connection if one is available, and queuing a connection event
-for later retrieval by
-.Fn evGetNext .
-If the connection event queued is an accept error(), sys_errno will contain
-the error code; otherwise it will be zero. All connection events queued by
-.Fn evTryAccept
-will be delivered by
-.Fn evGetNext
-before a new select is done on the listener.
-.Pp
-The function
-.Fn evSetDebug
-sets the debugging
-.Fa level
-and diagnostic
-.Fa output
-file handle for an event context. Greater numeric levels will
-result in more verbose output being sent to the output FILE during program
-execution.
-.Pp
-The function
-.Fn evPrintf
-prints a message with the format
-.Dq Fa fmt
-and the following arguments (if any), on the output stream associated
-with the event context pointed to by
-.Fa ctx .
-The message is output if the event context's debug level is greater than
-or equal to the indicated
-.Fa level .
-.Pp
-The function
-.Fn evInitID
-will initialize an opaque
-.Dq evConn \s-1ID\s+1 ,
-.Dq evFile \s-1ID\s+1 ,
-.Dq evStream \s-1ID\s+1 ,
-.Dq evTimer \s-1ID\s+1 ,
-.Dq evWait \s-1ID\s+1 ,
-.Dq evContext ,
-or
-.Dq evEvent ,
-which is passed by reference.
-.Pp
-The function
-.Fn evTestID
-will examine an opaque \s-1ID\s+1 and return
-.Dq TRUE
-only if it is not in its initialized state.
-.Sh RETURN VALUES
-All the functions whose return type is
-.Dq Fa int
-use the standard convention of returning zero (0) to indicate success, or
-returning
-.Dq Fa -1
-and setting
-.Fa errno
-to indicate failure.
-.Sh FILE
-.Pa heap.h ,
-which is in the
-.Pa src/lib/isc
-directory of the current
-.Sy BIND
-distribution.
-.Sh ERRORS
-The possible values for
-.Fa errno
-when one of the
-.Dq Fa int
-functions in this library returns
-.Dq Fa -1
-include those of the Standard C Library and also:
-.Bl -tag -width EWOULDBLOCKAA
-.It Bq Er EINVAL
-Some function argument has an unreasonable value.
-.It Bq Er EINVAL
-The specified file descriptor has an integer value greater than the default
-.Fa FD_SETSIZE ,
-meaning that the application's limit is higher than the library's.
-.It Bq Er ENOENT
-The specified
-.Dq event \s-1ID\s+1
-does not exist.
-.It Bq Er EWOULDBLOCK
-No events have occurred and the
-.Fa EV_POLL
-option was specified.
-.It Bq Er EBADF
-The specified signal was unblocked outside the library.
-.El
-.Sh SEE ALSO
-.Xr gettimeofday 2 ,
-.Xr select 2 ,
-.Xr fcntl 3 ,
-.Xr malloc 3 ,
-.Xr @INDOT@named @SYS_OPS_EXT@ ,
-.Xr readv 3 ,
-.Xr writev 3 .
-.Sh BUGS
-This huge man page needs to be broken up into a handful of smaller ones.
-.Sh HISTORY
-The
-.Nm eventlib
-library was designed by Paul Vixie with excellent advice from his friends
-and with tips 'o the cap to the X Consortium and the implementors of DEC SRC
-Modula-3.
diff --git a/contrib/bind/lib/isc/eventlib_p.h b/contrib/bind/lib/isc/eventlib_p.h
deleted file mode 100644
index 71b95ed..0000000
--- a/contrib/bind/lib/isc/eventlib_p.h
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * Copyright (c) 1995-1999 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.
- */
-
-/* eventlib_p.h - private interfaces for eventlib
- * vix 09sep95 [initial]
- *
- * $Id: eventlib_p.h,v 1.31 2003/04/03 05:37:56 marka Exp $
- */
-
-#ifndef _EVENTLIB_P_H
-#define _EVENTLIB_P_H
-
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <sys/un.h>
-
-#define EVENTLIB_DEBUG 1
-
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <isc/heap.h>
-#include <isc/list.h>
-#include <isc/memcluster.h>
-
-#define EV_MASK_ALL (EV_READ | EV_WRITE | EV_EXCEPT)
-#define EV_ERR(e) return (errno = (e), -1)
-#define OK(x) if ((x) < 0) EV_ERR(errno); else (void)NULL
-
-#define NEW(p) if (((p) = memget(sizeof *(p))) != NULL) \
- FILL(p); \
- else \
- (void)NULL;
-#define OKNEW(p) if (!((p) = memget(sizeof *(p)))) { \
- errno = ENOMEM; \
- return (-1); \
- } else \
- FILL(p)
-#define FREE(p) memput((p), sizeof *(p))
-
-#if EVENTLIB_DEBUG
-#define FILL(p) memset((p), 0xF5, sizeof *(p))
-#else
-#define FILL(p)
-#endif
-
-typedef struct evConn {
- evConnFunc func;
- void * uap;
- int fd;
- int flags;
-#define EV_CONN_LISTEN 0x0001 /* Connection is a listener. */
-#define EV_CONN_SELECTED 0x0002 /* evSelectFD(conn->file). */
-#define EV_CONN_BLOCK 0x0004 /* Listener fd was blocking. */
- evFileID file;
- struct evConn * prev;
- struct evConn * next;
-} evConn;
-
-typedef struct evAccept {
- int fd;
- union {
- struct sockaddr sa;
- struct sockaddr_in in;
-#ifndef NO_SOCKADDR_UN
- struct sockaddr_un un;
-#endif
- } la;
- ISC_SOCKLEN_T lalen;
- union {
- struct sockaddr sa;
- struct sockaddr_in in;
-#ifndef NO_SOCKADDR_UN
- struct sockaddr_un un;
-#endif
- } ra;
- ISC_SOCKLEN_T ralen;
- int ioErrno;
- evConn * conn;
- LINK(struct evAccept) link;
-} evAccept;
-
-typedef struct evFile {
- evFileFunc func;
- void * uap;
- int fd;
- int eventmask;
- int preemptive;
- struct evFile * prev;
- struct evFile * next;
- struct evFile * fdprev;
- struct evFile * fdnext;
-} evFile;
-
-typedef struct evStream {
- evStreamFunc func;
- void * uap;
- evFileID file;
- evTimerID timer;
- int flags;
-#define EV_STR_TIMEROK 0x0001 /* IFF timer valid. */
- int fd;
- struct iovec * iovOrig;
- int iovOrigCount;
- struct iovec * iovCur;
- int iovCurCount;
- int ioTotal;
- int ioDone;
- int ioErrno;
- struct evStream *prevDone, *nextDone;
- struct evStream *prev, *next;
-} evStream;
-
-typedef struct evTimer {
- evTimerFunc func;
- void * uap;
- struct timespec due, inter;
- int index;
-} evTimer;
-
-typedef struct evWait {
- evWaitFunc func;
- void * uap;
- const void * tag;
- struct evWait * next;
-} evWait;
-
-typedef struct evWaitList {
- evWait * first;
- evWait * last;
- struct evWaitList * prev;
- struct evWaitList * next;
-} evWaitList;
-
-typedef struct evEvent_p {
- enum { Accept, File, Stream, Timer, Wait, Free, Null } type;
- union {
- struct { evAccept *this; } accept;
- struct { evFile *this; int eventmask; } file;
- struct { evStream *this; } stream;
- struct { evTimer *this; } timer;
- struct { evWait *this; } wait;
- struct { struct evEvent_p *next; } free;
- struct { const void *placeholder; } null;
- } u;
-} evEvent_p;
-
-typedef struct {
- /* Global. */
- const evEvent_p *cur;
- /* Debugging. */
- int debug;
- FILE *output;
- /* Connections. */
- evConn *conns;
- LIST(evAccept) accepts;
- /* Files. */
- evFile *files, *fdNext;
- fd_set rdLast, rdNext;
- fd_set wrLast, wrNext;
- fd_set exLast, exNext;
- fd_set nonblockBefore;
- int fdMax, fdCount, highestFD;
- evFile *fdTable[FD_SETSIZE];
-#ifdef EVENTLIB_TIME_CHECKS
- struct timespec lastSelectTime;
- int lastFdCount;
-#endif
- /* Streams. */
- evStream *streams;
- evStream *strDone, *strLast;
- /* Timers. */
- struct timespec lastEventTime;
- heap_context timers;
- /* Waits. */
- evWaitList *waitLists;
- evWaitList waitDone;
-} evContext_p;
-
-/* eventlib.c */
-#define evPrintf __evPrintf
-void evPrintf(const evContext_p *ctx, int level, const char *fmt, ...)
- ISC_FORMAT_PRINTF(3, 4);
-
-/* ev_timers.c */
-#define evCreateTimers __evCreateTimers
-heap_context evCreateTimers(const evContext_p *);
-#define evDestroyTimers __evDestroyTimers
-void evDestroyTimers(const evContext_p *);
-
-/* ev_waits.c */
-#define evFreeWait __evFreeWait
-evWait *evFreeWait(evContext_p *ctx, evWait *old);
-
-#endif /*_EVENTLIB_P_H*/
diff --git a/contrib/bind/lib/isc/heap.c b/contrib/bind/lib/isc/heap.c
deleted file mode 100644
index ba9c503..0000000
--- a/contrib/bind/lib/isc/heap.c
+++ /dev/null
@@ -1,221 +0,0 @@
-/*
- * Copyright (c) 1997,1999 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.
- */
-
-/*
- * Heap implementation of priority queues adapted from the following:
- *
- * _Introduction to Algorithms_, Cormen, Leiserson, and Rivest,
- * MIT Press / McGraw Hill, 1990, ISBN 0-262-03141-8, chapter 7.
- *
- * _Algorithms_, Second Edition, Sedgewick, Addison-Wesley, 1988,
- * ISBN 0-201-06673-4, chapter 11.
- */
-
-#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: heap.c,v 8.7 1999/10/13 16:39:34 vixie Exp $";
-#endif /* not lint */
-
-#include "port_before.h"
-
-#include <stddef.h>
-#include <stdlib.h>
-#include <errno.h>
-
-#include "port_after.h"
-
-#include <isc/heap.h>
-
-/*
- * Note: to make heap_parent and heap_left easy to compute, the first
- * element of the heap array is not used; i.e. heap subscripts are 1-based,
- * not 0-based.
- */
-#define heap_parent(i) ((i) >> 1)
-#define heap_left(i) ((i) << 1)
-
-#define ARRAY_SIZE_INCREMENT 512
-
-heap_context
-heap_new(heap_higher_priority_func higher_priority, heap_index_func index,
- int array_size_increment) {
- heap_context ctx;
-
- ctx = (heap_context)malloc(sizeof (struct heap_context));
- if (ctx == NULL || higher_priority == NULL)
- return (NULL);
- ctx->array_size = 0;
- if (array_size_increment == 0)
- ctx->array_size_increment = ARRAY_SIZE_INCREMENT;
- else
- ctx->array_size_increment = array_size_increment;
- ctx->heap_size = 0;
- ctx->heap = NULL;
- ctx->higher_priority = higher_priority;
- ctx->index = index;
- return (ctx);
-}
-
-int
-heap_free(heap_context ctx) {
- if (ctx == NULL) {
- errno = EINVAL;
- return (-1);
- }
-
- if (ctx->heap != NULL)
- free(ctx->heap);
- free(ctx);
-
- return (0);
-}
-
-static int
-heap_resize(heap_context ctx) {
- void **new_heap;
-
- ctx->array_size += ctx->array_size_increment;
- new_heap = (void **)realloc(ctx->heap,
- (ctx->array_size) * (sizeof (void *)));
- if (new_heap == NULL) {
- errno = ENOMEM;
- return (-1);
- }
- ctx->heap = new_heap;
- return (0);
-}
-
-static void
-float_up(heap_context ctx, int i, void *elt) {
- int p;
-
- for ( p = heap_parent(i);
- i > 1 && ctx->higher_priority(elt, ctx->heap[p]);
- i = p, p = heap_parent(i) ) {
- ctx->heap[i] = ctx->heap[p];
- if (ctx->index != NULL)
- (ctx->index)(ctx->heap[i], i);
- }
- ctx->heap[i] = elt;
- if (ctx->index != NULL)
- (ctx->index)(ctx->heap[i], i);
-}
-
-static void
-sink_down(heap_context ctx, int i, void *elt) {
- int j, size, half_size;
-
- size = ctx->heap_size;
- half_size = size / 2;
- while (i <= half_size) {
- /* find smallest of the (at most) two children */
- j = heap_left(i);
- if (j < size && ctx->higher_priority(ctx->heap[j+1],
- ctx->heap[j]))
- j++;
- if (ctx->higher_priority(elt, ctx->heap[j]))
- break;
- ctx->heap[i] = ctx->heap[j];
- if (ctx->index != NULL)
- (ctx->index)(ctx->heap[i], i);
- i = j;
- }
- ctx->heap[i] = elt;
- if (ctx->index != NULL)
- (ctx->index)(ctx->heap[i], i);
-}
-
-int
-heap_insert(heap_context ctx, void *elt) {
- int i;
-
- if (ctx == NULL || elt == NULL) {
- errno = EINVAL;
- return (-1);
- }
-
- i = ++ctx->heap_size;
- if (ctx->heap_size >= ctx->array_size && heap_resize(ctx) < 0)
- return (-1);
-
- float_up(ctx, i, elt);
-
- return (0);
-}
-
-int
-heap_delete(heap_context ctx, int i) {
- void *elt;
-
- if (ctx == NULL || i < 1 || i > ctx->heap_size) {
- errno = EINVAL;
- return (-1);
- }
-
- elt = ctx->heap[ctx->heap_size];
- if (--ctx->heap_size > 0)
- sink_down(ctx, i, elt);
-
- return (0);
-}
-
-int
-heap_increased(heap_context ctx, int i) {
- if (ctx == NULL || i < 1 || i > ctx->heap_size) {
- errno = EINVAL;
- return (-1);
- }
-
- float_up(ctx, i, ctx->heap[i]);
-
- return (0);
-}
-
-int
-heap_decreased(heap_context ctx, int i) {
- if (ctx == NULL || i < 1 || i > ctx->heap_size) {
- errno = EINVAL;
- return (-1);
- }
-
- sink_down(ctx, i, ctx->heap[i]);
-
- return (0);
-}
-
-void *
-heap_element(heap_context ctx, int i) {
- if (ctx == NULL || i < 1 || i > ctx->heap_size) {
- errno = EINVAL;
- return (NULL);
- }
-
- return (ctx->heap[i]);
-}
-
-int
-heap_for_each(heap_context ctx, heap_for_each_func action, void *uap) {
- int i;
-
- if (ctx == NULL || action == NULL) {
- errno = EINVAL;
- return (-1);
- }
-
- for (i = 1; i <= ctx->heap_size; i++)
- (action)(ctx->heap[i], uap);
- return (0);
-}
diff --git a/contrib/bind/lib/isc/heap.mdoc b/contrib/bind/lib/isc/heap.mdoc
deleted file mode 100644
index 4b60e91..0000000
--- a/contrib/bind/lib/isc/heap.mdoc
+++ /dev/null
@@ -1,378 +0,0 @@
-.\" $Id: heap.mdoc,v 8.7 2001/08/08 07:50:24 marka Exp $
-.\"
-.\"Copyright (c) 1997,1999 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.
-.\"
-.Dd January 1, 1997
-.\"Os OPERATING_SYSTEM [version/release]
-.Os BSD 4
-.Dt HEAP @SYSCALL_EXT@
-.Sh NAME
-.Nm heap_new ,
-.Nm heap_free ,
-.Nm heap_insert ,
-.Nm heap_delete ,
-.Nm heap_increased ,
-.Nm heap_decreased ,
-.Nm heap_element ,
-.Nm heap_for_each
-.Nd heap implementation of priority queues
-.Sh SYNOPSIS
-.Fd #include \&"heap.h\&"
-.Ft heap_context
-.Fn heap_new "heap_higher_priority_func higher_priority" \
-"heap_index_func index" "int array_size_increment"
-.Ft int
-.Fn heap_free "heap_context ctx"
-.Ft int
-.Fn heap_insert "heap_context ctx" "void *elt"
-.Ft int
-.Fn heap_delete "heap_context ctx" "int i"
-.Ft int
-.Fn heap_increased "heap_context ctx" "int i"
-.Ft int
-.Fn heap_decreased "heap_context ctx" "int i"
-.Ft void *
-.Fn heap_element "heap_context ctx" "int i"
-.Ft int
-.Fn heap_for_each "heap_context ctx" "heap_for_each_func action" "void *uap"
-.Sh DESCRIPTION
-These functions implement heap\-based priority queues. The user defines a
-priority scheme, and provides a function for comparison of the priority
-of heap elements
-(see the description of the
-.Ft heap_higher_priority_func
-function pointer, below).
-.Pp
-Each of the functions depends upon the
-.Ft heap_context
-type, which is a pointer to a
-.Ft struct heap_context
-.Pq see Pa heap.h No for more information .
-.Pp
-The
-.Pa heap.h
-header file also defines the following set of function
-function pointers:
-.Bd -literal -offset indent
-typedef int (*heap_higher_priority_func)(void *, void *);
-typedef void (*heap_index_func)(void *, int);
-typedef void (*heap_for_each_func)(void *, void *);
-.Ed
-.Pp
-These are pointers to user-defined functions.
-The
-.Ft heap_higher_priority_func
-type is a pointer to a function which compares two
-different heap (queue) elements and returns an
-.Ft int
-which answers the question, "Does the first queue element
-have a higher priority than the second?" In other words,
-a function pointer of this type
-.Em must
-return a number greater than zero
-if the element indicated by the first argument is of a higher priority than
-that indicated by the second element, and zero otherwise.
-.Pp
-The other two function pointers are documented in the descriptions
-of
-.Fn heap_new
-.Pq Va heap_index_func
-and
-.Fn heap_for_each
-.Pq Va heap_for_each_func ,
-below.
-.Pp
-The function
-.Fn heap_new
-initializes a
-.Ft struct heap_context
-and returns a pointer to it. The
-.Fa higher_priority
-function pointer
-.Em must
-be
-.No non\- Ns Dv NULL .
-As explained above, this refers to a
-function supplied by the user which compares the priority of two different
-queue or heap elements; see above for more information.
-The second argument,
-.Fa index ,
-is a pointer to a user-defined function whose arguments are
-a heap element and its index in the heap.
-.Fa Index
-is intended to provide the user a means of knowing the internal index
-of an element in the heap while maintaining the opacity of the implementation;
-since the user has to know the actual indexes of heap elements in order to use,
-e.g.,
-.Fn heap_delete
-or
-.Fn heap_element ,
-the user
-.Fa index
-function could store the index in the heap element, itself. If
-.Fa index
-is
-.No non\- Ns Dv NULL ,
-then it is called
-.Em whenever
-the index of an element changes, allowing the user to stay up\-to\-date
-with index changes.
-The last argument,
-.Fa array_size_increment
-will be used, as its name suggests, by
-.Xr malloc 3
-or
-.Xr realloc 3
-to increment the array which implements the heap; if zero, a default value
-will be used.
-.Pp
-The
-.Fn heap_free
-function frees the given
-.Ft heap_context
-argument
-.Pq Fa ctx ,
-which also frees the entire
-.Nm heap ,
-if it is
-.No non\- Ns Dv NULL .
-The argument
-.Fa ctx
-should be
-.No non\- Ns Dv NULL .
-.Pp
-The
-.Fn heap_insert
-function is used to insert the new heap element
-.Fa elt
-into the appropriate place (priority\-wise) in the
-.Ft heap
-indicated by
-.Fa ctx
-(a pointer to a
-.Ft heap_context ) .
-If
-.No non\- Ns Dv NULL ,
-the user-defined
-.Ft higher_priority
-function pointer associated with the indicated
-.Nm heap
-is used to determine that
-.Dq appropriate place ;
-the highest\-priority elements are at the front of the queue (top of
-the heap).
-(See the description of
-.Fn heap_new ,
-above, for more information.)
-.Pp
-The function
-.Fn heap_delete
-is used to delete the
-.Fa i\- Ns th
-element of the queue (heap), and fixing up the queue (heap) from that
-element onward via the priority as determined by the user function
-pointed to by
-.Ft higher_priority
-function pointer
-(see description of
-.Fn heap_new ,
-above).
-.Pp
-.Fn heap_increased
-.Pp
-.Fn heap_decreased
-.Pp
-The
-.Fn heap_element
-function returns the
-.Fa i\- Ns th
-element of the queue/heap indicated by
-.Fa ctx ,
-if possible.
-.Pp
-The
-.Fn heap_for_each
-function provides a mechanism for the user to increment through the entire
-queue (heap) and perform some
-.Fa action
-upon each of the queue elements. This
-.Fa action
-is pointer to a user\-defined function with two arguments, the first of
-which should be interpreted by the user's function as a heap element. The
-second value passed to the user function is just the
-.Fa uap
-argument to
-.Fn heap_for_each ;
-this allows the user to specify additional arguments, if necessary, to
-the function pointed to by
-.Fa action .
-.\" The following requests should be uncommented and
-.\" used where appropriate. This next request is
-.\" for sections 2 and 3 function return values only.
-.Sh RETURN VALUES
-.Bl -tag -width "heap_decreased()"
-.It Fn heap_new
-.Dv NULL
-if unable to
-.Xr malloc 3
-a
-.Ft struct heap_context
-or if the
-.Fa higher_priority
-function pointer is
-.Dv NULL ;
-otherwise, a valid
-.Ft heap_context
-.Ns .
-.It Fn heap_free
--1 if
-.Fa ctx
-is
-.Dv NULL
-(with
-.Va errno
-set to
-.Dv EINVAL ) ;
-otherwise, 0.
-.It Fn heap_insert
--1
-if either
-.Fa ctx
-or
-.Fa elt
-is
-.Dv NULL ,
-or if an attempt to
-.Xr malloc 3
-or
-.Xr realloc 3
-the heap array fails (with
-.Va errno
-set to
-.Dv EINVAL
-or
-.Dv ENOMEM ,
-respectively).
-Otherwise, 0.
-.It Fn heap_delete
--1 if
-.Fa ctx
-is
-.Dv NULL
-or
-.Fa i
-is out\-of\-range (with
-.Va errno
-set to
-.Dv EINVAL ) ;
-0 otherwise.
-.It Fn heap_increased
-As for
-.Fn heap_delete .
-.It Fn heap_decreased
-As for
-.Fn heap_delete .
-.It Fn heap_element
-NULL if
-.Fa ctx
-is
-.Dv NULL
-or
-.Fa i
-out\-of-bounds (with
-.Va errno
-set to
-.Dv EINVAL ) ;
-otherwise, a pointer to the
-.Fa i\- Ns th
-queue element.
-.It Fn heap_for_each
--1 if either
-.Fa ctx
-or
-.Fa action
-is
-.Dv NULL
-(with
-.Va errno
-set to
-.Dv EINVAL ) ;
-0 otherwise.
-.El
-.\" This next request is for sections 1, 6, 7 & 8 only
-.\" .Sh ENVIRONMENT
-.Sh FILES
-.Bl -tag -width "heap.h000"
-.It Pa heap.h
- heap library header file
-.El
-.\" .Sh EXAMPLES
-.\" This next request is for sections 1, 6, 7 & 8 only
-.\" (command return values (to shell) and
-.\" fprintf/stderr type diagnostics)
-.Sh DIAGNOSTICS
-Please refer to
-.Sx RETURN VALUES .
-.\" The next request is for sections 2 and 3 error
-.\" and signal handling only.
-.Sh ERRORS
-The variable
-.Va errno
-is set by
-.Fn heap_free ,
-.Fn heap_insert ,
-.Fn heap_delete ,
-.Fn heap_increased ,
-and
-.Fn heap_decreased
-under the conditions of invalid input
-.Pq Dv EINVAL
-or lack of memory
-.Pq Dv ENOMEM ;
-please refer to
-.Sx RETURN VALUES .
-.Sh SEE ALSO
-.Xr malloc 3 ,
-.Xr realloc 3 .
-.Rs
-.%A Cormen
-.%A Leiserson
-.%A Rivest
-.%B Introduction to Algorithms
-.%Q "MIT Press / McGraw Hill"
-.%D 1990
-.%O ISBN 0\-262\-03141\-8
-.%P chapter 7
-.Re
-.Rs
-.%A Sedgewick
-.%B Algorithms, 2nd ed'n
-.%Q Addison\-Wesley
-.%D 1988
-.%O ISBN 0\-201\-06673\-4
-.%P chapter 11
-.Re
-.\" .Sh STANDARDS
-.\" .Sh HISTORY
-.Sh AUTHORS
-The
-.Nm heap
-library was implemented by Bob Halley (halley@vix.com) of Vixie Enterprises,
-Inc., for the Internet Software consortium, and was adapted from
-the two books listed in the
-.Sx SEE ALSO
-section, above.
-.\" .Sh BUGS
diff --git a/contrib/bind/lib/isc/hex.c b/contrib/bind/lib/isc/hex.c
deleted file mode 100644
index 2239796..0000000
--- a/contrib/bind/lib/isc/hex.c
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright (c) 2001 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.
- */
-
-#include <port_before.h>
-#include <ctype.h>
-#include <stdio.h>
-#include <string.h>
-#include <isc/misc.h>
-#include <port_after.h>
-
-static const char hex[17] = "0123456789abcdef";
-
-int
-isc_gethexstring(unsigned char *buf, size_t len, int count, FILE *fp,
- int *multiline)
-{
- int c, n;
- unsigned char x;
- char *s;
- int result = count;
-
- x = 0; /* silence compiler */
- n = 0;
- while (count > 0) {
- c = fgetc(fp);
-
- if ((c == EOF) ||
- (c == '\n' && !*multiline) ||
- (c == '(' && *multiline) ||
- (c == ')' && !*multiline))
- goto formerr;
- /* comment */
- if (c == ';') {
- while ((c = fgetc(fp)) != EOF && c != '\n')
- /* empty */
- if (c == '\n' && *multiline)
- continue;
- goto formerr;
- }
- /* white space */
- if (c == ' ' || c == '\t' || c == '\n' || c == '\r')
- continue;
- /* multiline */
- if ('(' == c || c == ')') {
- *multiline = (c == '(' /*)*/);
- continue;
- }
- if ((s = strchr(hex, tolower(c))) == NULL)
- goto formerr;
- x = (x<<4) | (s - hex);
- if (++n == 2) {
- if (len > 0) {
- *buf++ = x;
- len--;
- } else
- result = -1;
- count--;
- n = 0;
- }
- }
- return (result);
-
- formerr:
- if (c == '\n')
- ungetc(c, fp);
- return (-1);
-}
-
-void
-isc_puthexstring(FILE *fp, const unsigned char *buf, size_t buflen,
- size_t len1, size_t len2, const char *sep)
-{
- size_t i = 0;
-
- if (len1 < 4)
- len1 = 4;
- if (len2 < 4)
- len2 = 4;
- while (buflen > 0) {
- fputc(hex[(buf[0]>>4)&0xf], fp);
- fputc(hex[buf[0]&0xf], fp);
- i += 2;
- buflen--;
- buf++;
- if (i >= len1 && sep != NULL) {
- fputs(sep, fp);
- i = 0;
- len1 = len2;
- }
- }
-}
-
-void
-isc_tohex(const unsigned char *buf, size_t buflen, char *t) {
- while (buflen > 0) {
- *t++ = hex[(buf[0]>>4)&0xf];
- *t++ = hex[buf[0]&0xf];
- buf++;
- buflen--;
- }
- *t = '\0';
-}
diff --git a/contrib/bind/lib/isc/logging.c b/contrib/bind/lib/isc/logging.c
deleted file mode 100644
index f0a4940..0000000
--- a/contrib/bind/lib/isc/logging.c
+++ /dev/null
@@ -1,720 +0,0 @@
-/*
- * Copyright (c) 1996-1999 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.
- */
-
-#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: logging.c,v 8.32 2003/01/02 00:35:42 marka Exp $";
-#endif /* not lint */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/stat.h>
-
-#include <fcntl.h>
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-#include <syslog.h>
-#include <errno.h>
-#include <time.h>
-#include <unistd.h>
-
-#include <isc/assertions.h>
-#include <isc/logging.h>
-#include <isc/memcluster.h>
-#include <isc/misc.h>
-
-#include "port_after.h"
-
-#ifdef VSPRINTF_CHAR
-# define VSPRINTF(x) strlen(vsprintf/**/x)
-#else
-# define VSPRINTF(x) ((size_t)vsprintf x)
-#endif
-
-#include "logging_p.h"
-
-static const int syslog_priority[] = { LOG_DEBUG, LOG_INFO, LOG_NOTICE,
- LOG_WARNING, LOG_ERR, LOG_CRIT };
-
-static const char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
-
-static const char *level_text[] = {
- "info: ", "notice: ", "warning: ", "error: ", "critical: "
-};
-
-static void
-version_rename(log_channel chan) {
- unsigned int ver;
- char old_name[PATH_MAX+1];
- char new_name[PATH_MAX+1];
-
- ver = chan->out.file.versions;
- if (ver < 1)
- return;
- if (ver > LOG_MAX_VERSIONS)
- ver = LOG_MAX_VERSIONS;
- /*
- * Need to have room for '.nn' (XXX assumes LOG_MAX_VERSIONS < 100)
- */
- if (strlen(chan->out.file.name) > (PATH_MAX-3))
- return;
- for (ver--; ver > 0; ver--) {
- sprintf(old_name, "%s.%d", chan->out.file.name, ver-1);
- sprintf(new_name, "%s.%d", chan->out.file.name, ver);
- (void)isc_movefile(old_name, new_name);
- }
- sprintf(new_name, "%s.0", chan->out.file.name);
- (void)isc_movefile(chan->out.file.name, new_name);
-}
-
-FILE *
-log_open_stream(log_channel chan) {
- FILE *stream;
- int fd, flags;
- struct stat sb;
- int regular;
-
- if (chan == NULL || chan->type != log_file) {
- errno = EINVAL;
- return (NULL);
- }
-
- /*
- * Don't open already open streams
- */
- if (chan->out.file.stream != NULL)
- return (chan->out.file.stream);
-
- if (stat(chan->out.file.name, &sb) < 0) {
- if (errno != ENOENT) {
- syslog(LOG_ERR,
- "log_open_stream: stat of %s failed: %s",
- chan->out.file.name, strerror(errno));
- chan->flags |= LOG_CHANNEL_BROKEN;
- return (NULL);
- }
- regular = 1;
- } else
- regular = (sb.st_mode & S_IFREG);
-
- if (chan->out.file.versions) {
- if (!regular) {
- syslog(LOG_ERR,
- "log_open_stream: want versions but %s isn't a regular file",
- chan->out.file.name);
- chan->flags |= LOG_CHANNEL_BROKEN;
- errno = EINVAL;
- return (NULL);
- }
- }
-
- flags = O_WRONLY|O_CREAT|O_APPEND;
-
- if ((chan->flags & LOG_TRUNCATE) != 0) {
- if (regular) {
- (void)unlink(chan->out.file.name);
- flags |= O_EXCL;
- } else {
- syslog(LOG_ERR,
- "log_open_stream: want truncation but %s isn't a regular file",
- chan->out.file.name);
- chan->flags |= LOG_CHANNEL_BROKEN;
- errno = EINVAL;
- return (NULL);
- }
- }
-
- fd = open(chan->out.file.name, flags,
- S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
- if (fd < 0) {
- syslog(LOG_ERR, "log_open_stream: open(%s) failed: %s",
- chan->out.file.name, strerror(errno));
- chan->flags |= LOG_CHANNEL_BROKEN;
- return (NULL);
- }
- stream = fdopen(fd, "a");
- if (stream == NULL) {
- syslog(LOG_ERR, "log_open_stream: fdopen() failed");
- chan->flags |= LOG_CHANNEL_BROKEN;
- return (NULL);
- }
- (void) fchown(fd, chan->out.file.owner, chan->out.file.group);
-
- chan->out.file.stream = stream;
- return (stream);
-}
-
-int
-log_close_stream(log_channel chan) {
- FILE *stream;
-
- if (chan == NULL || chan->type != log_file) {
- errno = EINVAL;
- return (0);
- }
- stream = chan->out.file.stream;
- chan->out.file.stream = NULL;
- if (stream != NULL && fclose(stream) == EOF)
- return (-1);
- return (0);
-}
-
-void
-log_close_debug_channels(log_context lc) {
- log_channel_list lcl;
- int i;
-
- for (i = 0; i < lc->num_categories; i++)
- for (lcl = lc->categories[i]; lcl != NULL; lcl = lcl->next)
- if (lcl->channel->type == log_file &&
- lcl->channel->out.file.stream != NULL &&
- lcl->channel->flags & LOG_REQUIRE_DEBUG)
- (void)log_close_stream(lcl->channel);
-}
-
-FILE *
-log_get_stream(log_channel chan) {
- if (chan == NULL || chan->type != log_file) {
- errno = EINVAL;
- return (NULL);
- }
- return (chan->out.file.stream);
-}
-
-char *
-log_get_filename(log_channel chan) {
- if (chan == NULL || chan->type != log_file) {
- errno = EINVAL;
- return (NULL);
- }
- return (chan->out.file.name);
-}
-
-int
-log_check_channel(log_context lc, int level, log_channel chan) {
- int debugging, chan_level;
-
- REQUIRE(lc != NULL);
-
- debugging = ((lc->flags & LOG_OPTION_DEBUG) != 0);
-
- /*
- * If not debugging, short circuit debugging messages very early.
- */
- if (level > 0 && !debugging)
- return (0);
-
- if ((chan->flags & (LOG_CHANNEL_BROKEN|LOG_CHANNEL_OFF)) != 0)
- return (0);
-
- /* Some channels only log when debugging is on. */
- if ((chan->flags & LOG_REQUIRE_DEBUG) && !debugging)
- return (0);
-
- /* Some channels use the global level. */
- if ((chan->flags & LOG_USE_CONTEXT_LEVEL) != 0) {
- chan_level = lc->level;
- } else
- chan_level = chan->level;
-
- if (level > chan_level)
- return (0);
-
- return (1);
-}
-
-int
-log_check(log_context lc, int category, int level) {
- log_channel_list lcl;
- int debugging;
-
- REQUIRE(lc != NULL);
-
- debugging = ((lc->flags & LOG_OPTION_DEBUG) != 0);
-
- /*
- * If not debugging, short circuit debugging messages very early.
- */
- if (level > 0 && !debugging)
- return (0);
-
- if (category < 0 || category > lc->num_categories)
- category = 0; /* use default */
- lcl = lc->categories[category];
- if (lcl == NULL) {
- category = 0;
- lcl = lc->categories[0];
- }
-
- for ( /* nothing */; lcl != NULL; lcl = lcl->next) {
- if (log_check_channel(lc, level, lcl->channel))
- return (1);
- }
- return (0);
-}
-
-void
-log_vwrite(log_context lc, int category, int level, const char *format,
- va_list args) {
- log_channel_list lcl;
- int pri, debugging, did_vsprintf = 0;
- int original_category;
- FILE *stream;
- log_channel chan;
- struct timeval tv;
- struct tm *local_tm;
-#ifdef HAVE_TIME_R
- struct tm tm_tmp;
-#endif
- time_t tt;
- const char *category_name;
- const char *level_str;
- char time_buf[256];
- char level_buf[256];
-
- REQUIRE(lc != NULL);
-
- debugging = (lc->flags & LOG_OPTION_DEBUG);
-
- /*
- * If not debugging, short circuit debugging messages very early.
- */
- if (level > 0 && !debugging)
- return;
-
- if (category < 0 || category > lc->num_categories)
- category = 0; /* use default */
- original_category = category;
- lcl = lc->categories[category];
- if (lcl == NULL) {
- category = 0;
- lcl = lc->categories[0];
- }
-
- /*
- * Get the current time and format it.
- */
- time_buf[0]='\0';
- if (gettimeofday(&tv, NULL) < 0) {
- syslog(LOG_INFO, "gettimeofday failed in log_vwrite()");
- } else {
- tt = tv.tv_sec;
-#ifdef HAVE_TIME_R
- local_tm = localtime_r(&tt, &tm_tmp);
-#else
- local_tm = localtime(&tt);
-#endif
- if (local_tm != NULL) {
- sprintf(time_buf, "%02d-%s-%4d %02d:%02d:%02d.%03ld ",
- local_tm->tm_mday, months[local_tm->tm_mon],
- local_tm->tm_year+1900, local_tm->tm_hour,
- local_tm->tm_min, local_tm->tm_sec,
- (long)tv.tv_usec/1000);
- }
- }
-
- /*
- * Make a string representation of the current category and level
- */
-
- if (lc->category_names != NULL &&
- lc->category_names[original_category] != NULL)
- category_name = lc->category_names[original_category];
- else
- category_name = "";
-
- if (level >= log_critical) {
- if (level >= 0) {
- sprintf(level_buf, "debug %d: ", level);
- level_str = level_buf;
- } else
- level_str = level_text[-level-1];
- } else {
- sprintf(level_buf, "level %d: ", level);
- level_str = level_buf;
- }
-
- /*
- * Write the message to channels.
- */
- for ( /* nothing */; lcl != NULL; lcl = lcl->next) {
- chan = lcl->channel;
-
- if (!log_check_channel(lc, level, chan))
- continue;
-
- if (!did_vsprintf) {
- if (VSPRINTF((lc->buffer, format, args)) >
- LOG_BUFFER_SIZE) {
- syslog(LOG_CRIT,
- "memory overrun in log_vwrite()");
- exit(1);
- }
- did_vsprintf = 1;
- }
-
- switch (chan->type) {
- case log_syslog:
- if (level >= log_critical)
- pri = (level >= 0) ? 0 : -level;
- else
- pri = -log_critical;
- syslog(chan->out.facility|syslog_priority[pri],
- "%s%s%s%s",
- (chan->flags & LOG_TIMESTAMP) ? time_buf : "",
- (chan->flags & LOG_PRINT_CATEGORY) ?
- category_name : "",
- (chan->flags & LOG_PRINT_LEVEL) ?
- level_str : "",
- lc->buffer);
- break;
- case log_file:
- stream = chan->out.file.stream;
- if (stream == NULL) {
- stream = log_open_stream(chan);
- if (stream == NULL)
- break;
- }
- if (chan->out.file.max_size != ULONG_MAX) {
- long pos;
-
- pos = ftell(stream);
- if (pos >= 0 &&
- (unsigned long)pos >
- chan->out.file.max_size) {
- /*
- * try to roll over the log files,
- * ignoring all all return codes
- * except the open (we don't want
- * to write any more anyway)
- */
- log_close_stream(chan);
- version_rename(chan);
- stream = log_open_stream(chan);
- if (stream == NULL)
- break;
- }
- }
- fprintf(stream, "%s%s%s%s\n",
- (chan->flags & LOG_TIMESTAMP) ? time_buf : "",
- (chan->flags & LOG_PRINT_CATEGORY) ?
- category_name : "",
- (chan->flags & LOG_PRINT_LEVEL) ?
- level_str : "",
- lc->buffer);
- fflush(stream);
- break;
- case log_null:
- break;
- default:
- syslog(LOG_ERR,
- "unknown channel type in log_vwrite()");
- }
- }
-}
-
-void
-log_write(log_context lc, int category, int level, const char *format, ...) {
- va_list args;
-
- va_start(args, format);
- log_vwrite(lc, category, level, format, args);
- va_end(args);
-}
-
-/*
- * Functions to create, set, or destroy contexts
- */
-
-int
-log_new_context(int num_categories, char **category_names, log_context *lc) {
- log_context nlc;
-
- nlc = memget(sizeof (struct log_context));
- if (nlc == NULL) {
- errno = ENOMEM;
- return (-1);
- }
- nlc->num_categories = num_categories;
- nlc->category_names = category_names;
- nlc->categories = memget(num_categories * sizeof (log_channel_list));
- if (nlc->categories == NULL) {
- memput(nlc, sizeof (struct log_context));
- errno = ENOMEM;
- return (-1);
- }
- memset(nlc->categories, '\0',
- num_categories * sizeof (log_channel_list));
- nlc->flags = 0U;
- nlc->level = 0;
- *lc = nlc;
- return (0);
-}
-
-void
-log_free_context(log_context lc) {
- log_channel_list lcl, lcl_next;
- log_channel chan;
- int i;
-
- REQUIRE(lc != NULL);
-
- for (i = 0; i < lc->num_categories; i++)
- for (lcl = lc->categories[i]; lcl != NULL; lcl = lcl_next) {
- lcl_next = lcl->next;
- chan = lcl->channel;
- (void)log_free_channel(chan);
- memput(lcl, sizeof (struct log_channel_list));
- }
- memput(lc->categories,
- lc->num_categories * sizeof (log_channel_list));
- memput(lc, sizeof (struct log_context));
-}
-
-int
-log_add_channel(log_context lc, int category, log_channel chan) {
- log_channel_list lcl;
-
- if (lc == NULL || category < 0 || category >= lc->num_categories) {
- errno = EINVAL;
- return (-1);
- }
-
- lcl = memget(sizeof (struct log_channel_list));
- if (lcl == NULL) {
- errno = ENOMEM;
- return(-1);
- }
- lcl->channel = chan;
- lcl->next = lc->categories[category];
- lc->categories[category] = lcl;
- chan->references++;
- return (0);
-}
-
-int
-log_remove_channel(log_context lc, int category, log_channel chan) {
- log_channel_list lcl, prev_lcl, next_lcl;
- int found = 0;
-
- if (lc == NULL || category < 0 || category >= lc->num_categories) {
- errno = EINVAL;
- return (-1);
- }
-
- for (prev_lcl = NULL, lcl = lc->categories[category];
- lcl != NULL;
- lcl = next_lcl) {
- next_lcl = lcl->next;
- if (lcl->channel == chan) {
- log_free_channel(chan);
- if (prev_lcl != NULL)
- prev_lcl->next = next_lcl;
- else
- lc->categories[category] = next_lcl;
- memput(lcl, sizeof (struct log_channel_list));
- /*
- * We just set found instead of returning because
- * the channel might be on the list more than once.
- */
- found = 1;
- } else
- prev_lcl = lcl;
- }
- if (!found) {
- errno = ENOENT;
- return (-1);
- }
- return (0);
-}
-
-int
-log_option(log_context lc, int option, int value) {
- if (lc == NULL) {
- errno = EINVAL;
- return (-1);
- }
- switch (option) {
- case LOG_OPTION_DEBUG:
- if (value)
- lc->flags |= option;
- else
- lc->flags &= ~option;
- break;
- case LOG_OPTION_LEVEL:
- lc->level = value;
- break;
- default:
- errno = EINVAL;
- return (-1);
- }
- return (0);
-}
-
-int
-log_category_is_active(log_context lc, int category) {
- if (lc == NULL) {
- errno = EINVAL;
- return (-1);
- }
- if (category >= 0 && category < lc->num_categories &&
- lc->categories[category] != NULL)
- return (1);
- return (0);
-}
-
-log_channel
-log_new_syslog_channel(unsigned int flags, int level, int facility) {
- log_channel chan;
-
- chan = memget(sizeof (struct log_channel));
- if (chan == NULL) {
- errno = ENOMEM;
- return (NULL);
- }
- chan->type = log_syslog;
- chan->flags = flags;
- chan->level = level;
- chan->out.facility = facility;
- chan->references = 0;
- return (chan);
-}
-
-log_channel
-log_new_file_channel(unsigned int flags, int level,
- const char *name, FILE *stream, unsigned int versions,
- unsigned long max_size) {
- log_channel chan;
-
- chan = memget(sizeof (struct log_channel));
- if (chan == NULL) {
- errno = ENOMEM;
- return (NULL);
- }
- chan->type = log_file;
- chan->flags = flags;
- chan->level = level;
- if (name != NULL) {
- size_t len;
-
- len = strlen(name);
- /*
- * Quantize length to a multiple of 256. There's space for the
- * NUL, since if len is a multiple of 256, the size chosen will
- * be the next multiple.
- */
- chan->out.file.name_size = ((len / 256) + 1) * 256;
- chan->out.file.name = memget(chan->out.file.name_size);
- if (chan->out.file.name == NULL) {
- memput(chan, sizeof (struct log_channel));
- errno = ENOMEM;
- return (NULL);
- }
- /* This is safe. */
- strcpy(chan->out.file.name, name);
- } else {
- chan->out.file.name_size = 0;
- chan->out.file.name = NULL;
- }
- chan->out.file.stream = stream;
- chan->out.file.versions = versions;
- chan->out.file.max_size = max_size;
- chan->out.file.owner = getuid();
- chan->out.file.group = getgid();
- chan->references = 0;
- return (chan);
-}
-
-int
-log_set_file_owner(log_channel chan, uid_t owner, gid_t group) {
- if (chan->type != log_file) {
- errno = EBADF;
- return (-1);
- }
- chan->out.file.owner = owner;
- chan->out.file.group = group;
- return (0);
-}
-
-log_channel
-log_new_null_channel() {
- log_channel chan;
-
- chan = memget(sizeof (struct log_channel));
- if (chan == NULL) {
- errno = ENOMEM;
- return (NULL);
- }
- chan->type = log_null;
- chan->flags = LOG_CHANNEL_OFF;
- chan->level = log_info;
- chan->references = 0;
- return (chan);
-}
-
-int
-log_inc_references(log_channel chan) {
- if (chan == NULL) {
- errno = EINVAL;
- return (-1);
- }
- chan->references++;
- return (0);
-}
-
-int
-log_dec_references(log_channel chan) {
- if (chan == NULL || chan->references <= 0) {
- errno = EINVAL;
- return (-1);
- }
- chan->references--;
- return (0);
-}
-
-log_channel_type
-log_get_channel_type(log_channel chan) {
- REQUIRE(chan != NULL);
-
- return (chan->type);
-}
-
-int
-log_free_channel(log_channel chan) {
- if (chan == NULL || chan->references <= 0) {
- errno = EINVAL;
- return (-1);
- }
- chan->references--;
- if (chan->references == 0) {
- if (chan->type == log_file) {
- if ((chan->flags & LOG_CLOSE_STREAM) &&
- chan->out.file.stream != NULL)
- (void)fclose(chan->out.file.stream);
- if (chan->out.file.name != NULL)
- memput(chan->out.file.name,
- chan->out.file.name_size);
- }
- memput(chan, sizeof (struct log_channel));
- }
- return (0);
-}
diff --git a/contrib/bind/lib/isc/logging.mdoc b/contrib/bind/lib/isc/logging.mdoc
deleted file mode 100644
index 8d8d27e..0000000
--- a/contrib/bind/lib/isc/logging.mdoc
+++ /dev/null
@@ -1,1056 +0,0 @@
-.\" $Id: logging.mdoc,v 8.6 2001/12/28 04:24:23 marka Exp $
-.\"
-.\"Copyright (c) 1995-1999 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.
-.\"
-.\" The following six UNCOMMENTED lines are required.
-.Dd January 1, 1996
-.\"Os OPERATING_SYSTEM [version/release]
-.Os BSD 4
-.\"Dt DOCUMENT_TITLE [section number] [volume]
-.Dt LOGGING @SYSCALL_EXT@
-.Sh NAME
-.Nm log_open_stream ,
-.Nm log_close_stream ,
-.Nm log_get_stream ,
-.Nm log_get_filename ,
-.Nm log_vwrite ,
-.Nm log_write ,
-.Nm log_new_context ,
-.Nm log_free_context ,
-.Nm log_add_channel ,
-.Nm log_remove_channel ,
-.Nm log_option ,
-.Nm log_category_is_active ,
-.Nm log_new_syslog_channel ,
-.Nm log_new_file_channel ,
-.Nm log_set_file_owner ,
-.Nm log_new_null_channel ,
-.Nm log_inc_references ,
-.Nm log_dec_references ,
-.Nm log_free_channel
-.Nd logging system
-.Sh SYNOPSIS
-.Fd #include <isc/logging.h>
-.Ft FILE *
-.Fn log_open_stream "log_channel chan"
-.Ft int
-.Fn log_close_stream "log_channel chan"
-.Ft FILE *
-.Fn log_get_stream "log_channel chan"
-.Ft char *
-.Fn log_get_filename "log_channel chan"
-.Ft void
-.Fn log_vwrite "log_context lc" "int category" "int level" \
- "const char *format" va_list args"
-.Ft void
-.Fn log_write "log_context lc" "int category" "int level" \
- "const char *format" "..."
-.Ft int
-.Fn log_check_channel "log_context lc" "int level" "log_channel chan"
-.Ft int
-.Fn log_check "log_context lc" "int category" "int level"
-.Ft int
-.Fn log_new_context "int num_categories" "char **category_names" \
- "log_context *lc"
-.Ft void
-.Fn log_free_context "log_context lc"
-.Ft int
-.Fn log_add_channel "log_context lc" "int category" "log_channel chan"
-.Ft int
-.Fn log_remove_channel "log_context lc" "int category" "log_channel chan"
-.Ft int
-.Fn log_option "log_context lc" "int option" "int value"
-.Ft int
-.Fn log_category_is_active "log_context lc" "int category"
-.Ft log_channel
-.Fn log_new_syslog_channel "unsigned int flags" "int level" "int facility"
-.Ft log_channel
-.Fn log_new_file_channel "unsigned int flags" "int level" \
- "char *name" "FILE *stream" "unsigned int versions" \
- "unsigned long max_size"
-.Ft int
-.Fn log_set_file_owner "log_channel chan" "uid_t owner" "gid_t group"
-.Ft log_channel
-.Fn log_new_null_channel "void"
-.Ft int
-.Fn log_inc_references "log_channel chan"
-.Ft int
-.Fn log_dec_references "log_channel chan"
-.Ft int
-.Fn log_free_channel "log_channel chan"
-.Sh DESCRIPTION
-The
-.Sy ISC
-.Nm logging library
-is flexible logging system which is based upon a set of concepts:
-.Nm logging channels ,
-.Nm categories ,
-and
-.Nm logging contexts .
-.Pp
-The basic building block is the
-.Dq Nm logging channel ,
-which includes a
-.Nm priority
-(logging level), which type of logging is to occur, and other
-flags and information associated with technical aspects of the logging.
-The set of priorities which are supported is shown below, in the section
-.Sx Message Priorities .
-A priority sets a threshold for message logging; a logging channel will
-.Em only
-log those messages which are
-.Em at least as important
-as its priority indicates. (The fact that
-.Dq more important
-means
-.Dq more negative ,
-under the current scheme, is an implementation detail; if a channel has
-a priority of
-.Dv log_error ,
-then it will
-.Em not
-log messages with the
-.Dv log_warning
-priority, but it
-.Em will
-log messages with the
-.Dv log_error
-or
-.Dv log_critical
-priority.)
-.Pp
-The
-.Nm logging channel
-also has an indication of the type of logging performed. Currently,
-the supported
-.Nm logging types
-include (see also
-.Sx Logging Types ,
-below):
-.Bl -tag -width "log_syslog" -compact -offset indent
-.It Dv log_syslog
-for
-.Xr syslog 3 Ns -style
-logging
-.It Dv log_file
-for use of a file
-.It Dv log_null
-for
-.Em no
-logging
-.El
-A new logging channel is created by calling either
-.Fn log_new_syslog_channel ,
-.Fn log_new_file_channel ,
-or
-.Fn log_new_null_channel ,
-respectively.
-When a channel is no longer to be used, it can be freed using
-.Fn log_free_channel .
-.Pp
-Both
-.Dv log_syslog
-and
-.Dv log_file
-channel types can include more information; for instance, a
-.Dv log_syslog Ns -type
-channel allows the specification of a
-.Xr syslog 3 Ns -style
-.Dq facility ,
-and a
-.Dv log_file Ns -type
-channels allows the caller to set a maximum file size and number
-of versions. (See
-.Fn log_new_syslog_channel
-or
-.Fn log_new_file_channel ,
-below.)
-Additionally, once a logging channel of type
-.Dv log_file
-is defined, the functions
-.Fn log_open_stream
-and
-.Fn log_close_stream
-can open or close the stream associated with the logging channel's logging
-filename. The
-.Fn log_get_stream
-and
-.Fn log_get_filename
-functions return the stream or filename, respectively, of such a logging
-channel. Also unique to logging channels of type
-.Dv log_file
-is the
-.Fn log_set_file_owner
-function, which tells the logging system what user and group ought to own
-newly created files (which is only effective if the caller is privileged.)
-.Pp
-Callers provide
-.Dq Nm categories ,
-determining both the number of such categories and any (optional) names.
-Categories are like array indexes in C; if the caller declares
-.Dq Va n
-categories, then they are considered to run from 0 to
-.Va n-1 ;
-with this scheme, a category number would be invalid if it were negative or
-greater than/equal to
-.Va n .
-Each category can have its own list of
-.Nm logging channels
-associated with it; we say that such a channel is
-.Dq in
-the particular category.
-.Sy NOTE :
-Individual logging channels can appear in more than one category.
-.Pp
-A
-.Dq Nm logging context
-is the set of all
-.Nm logging channels
-associated with the context's
-.Nm categories ;
-thus, a particular
-.Nm category
-scheme is associated with a particular
-.Nm logging context .
-.Sy NOTE :
-A logging channel may appear in more than one logging context, and in
-multiple categories within each logging context.
-.Pp
-Use
-.Fn log_add_channel
-and
-.Fn log_remove_channel
-to add or remove a logging channel to some category in a logging context.
-To see if a given category in a logging context is being used, use the
-Boolean test
-.Fn log_category_is_active .
-.Pp
-A
-.Nm logging context
-can also have a
-.Nm priority
-(logging level)
-and various flags associated with the whole context; in order to alter the
-flags or change the priority of a context, use
-.Fn log_option .
-.Ss Message Priorities
-Currently, five
-.Nm priorities
-(logging levels) are supported (they can also be found in the header file):
-.Bd -literal -offset indent
-#define log_critical (-5)
-#define log_error (-4)
-#define log_warning (-3)
-#define log_notice (-2)
-#define log_info (-1)
-.Ed
-.Pp
-In the current implementation, logging messages which have a level greater
-than 0 are considered to be debugging messages.
-.Ss Logging Types
-The three different
-.Nm logging types
-currently supported are different values of the enumerated type
-.Ft log_output_type
-(these are also listed in the header file):
-.Bd -literal -offset indent
-typedef enum { log_syslog, log_file, log_null } log_output_type;
-.Ed
-.Ss Logging Channel Flags
-There are several flags which can be set on a logging channel; the flags
-and their meanings are as follows (they are also found in the header file):
-.Bl -tag -width "LOG_USE_CONTEXT_LEVEL " -offset indent
-.It Dv LOG_CHANNEL_BROKEN
-This is set only when some portion of
-.Fn log_open_stream
-fails:
-.Xr open 2
-or
-.Xr fdopen 3
-fail;
-.Xr stat 2
-fails in a
-.Dq bad
-way; versioning or truncation is requested on a non-normal file.
-.It Dv LOG_CHANNEL_OFF
-This is set for channels opened by
-.Fn log_new_null_channel .
-.It Dv LOG_CLOSE_STREAM
-If this flag is set, then
-.Fn log_free_channel
-will free a
-.No non- Dv NULL
-stream of a logging channel which is being
-.Xr free 3 Ns -d
-(if the logging channel is of type
-.Dv log_file ,
-of course).
-.It Dv LOG_PRINT_CATEGORY
-If set,
-.Fn log_vwrite
-will insert the category name, if available, into logging messages which are
-logged to channels of type
-.Dv log_syslog
-or
-.Dv log_file .
-.It Dv LOG_PRINT_LEVEL
-If set,
-.Fn log_vwrite
-will insert a string identifying the message priority level into the
-information logged to channels of type
-.Dv log_syslog
-or
-.Dv log_file .
-.It Dv LOG_REQUIRE_DEBUG
-Only log debugging messages (i.e., those with a priority greater than zero).
-.It Dv LOG_TIMESTAMP
-If set,
-.Fn log_vwrite
-will insert a timestamp into logging messages which are logged to channels of
-type
-.Dv log_syslog
-or
-.Dv log_file .
-.It Dv LOG_TRUNCATE
-Truncate logging file when re-opened
-.Fn ( log_open_stream
-will
-.Xr unlink 2
-the file and then
-.Xr open 2
-a new file of the same name with the
-.Dv O_EXCL
-bit set).
-.It Dv LOG_USE_CONTEXT_LEVEL
-Use the logging context's priority or logging level, rather than the logging
-channel's own priority. This can be useful for those channels which are
-included in multiple logging contexts.
-.El
-.Ss FUNCTION DESCRIPTIONS
-The function
-.Fn log_open_stream
-is for use with channels which log to a file; i.e., logging channels with a
-.Va type
-field set to
-.Dq Dv log_file .
-If the logging channel pointed to by
-.Dq Fa chan
-is valid, it attempts to open (and return) the stream associated with that
-channel. If the stream is already opened, then it is returned; otherwise,
-.Xr stat 2
-is used to test the filename for the stream.
-.Pp
-At this point, if the logging file is supposed to have different
-.Va versions
-(i.e., incremented version numbers; higher numbers indicate older versions
-of the logging file). If so, then any existing versions are
-.Xr rename 2 Ns -d
-to have one version-number higher than previously, and the
-.Dq current
-filename for the stream is set to the
-.Dq \&.0
-form of the name. Next, if the logging file is supposed to be truncated
-(i.e., the
-.Dv LOG_TRUNCATE
-bit of the
-.Va flags
-field of the logging channel structure is set), then any file with the
-.Dq current
-filename for the stream is
-.Xr unlink 2 Ns -d .
-.Sy NOTE :
-If the logging file is
-.Em not
-a regular file, and either of the above operations (version numbering
-or truncation) is supposed to take place, a
-.Dv NULL
-file pointer is returned.
-.Pp
-Finally, the filename associated with the logging channel is
-.Xr open 2 Ns -d
-using the appropriate flags and a mode which sets the read/write permissions
-for the user, group, and others. The file descriptor returned by
-.Xr open 2
-is then passed to
-.Xr fopen 3 ,
-with the append mode set, and the stream returned by this call is stored
-in the
-.Fa chan
-structure and returned.
-.Pp
-If
-.Fn log_open_stream
-fails at any point, then the
-.Dv LOG_CHANNEL_BROKEN
-bit of the
-.Va flags
-field of the logging channel pointed to by
-.Fa chan
-is set, a
-.Dv NULL
-is returned, and
-.Va errno
-contains pertinent information.
-.Pp
-The
-.Fn log_close_stream
-function closes the stream associated with the logging channel pointed to by
-.Dq Fa chan
-(if
-.Fa chan
-is valid and the stream exists and can be closed properly by
-.Xr fclose 3 ) .
-The stream is set to
-.Dv NULL
-even if the call to
-.Xr fclose 3
-fails.
-.Pp
-The function
-.Fn log_get_stream
-returns the stream associated with the logging channel pointed to by
-.Dq Fa chan ,
-if it is
-.No non- Ns Dv NULL
-and specifies a logging channel which has a
-.Dv FILE *
-or stream associated with it.
-.Pp
-The
-.Fn log_get_filename
-function returns the name of the file associated with the logging channel
-pointed to by
-.Dq Fa chan ,
-if it is
-.No non- Ns Dv NULL
-and specifies a logging channel which has a file associated with it.
-.Pp
-The
-.Fn log_vwrite
-function performs the actual logging of a message to the various logging
-channels of a logging context
-.Fa lc .
-The message consists of an
-.Xr fprint 3 Ns -style
-.Fa format
-and its associated
-.Fa args
-(if any); it will be written to all logging channels in the given
-.Fa category
-which have a priority set to
-.Fa level
-or any
-.Em less important
-priority value. If the
-.Fa category
-is not valid or has no logging channels, then the category defaults to 0.
-.Pp
-There are a number of conditions under which a call to
-.Fn log_vwrite
-will not result in actually logging the message: if there is no logging channel
-at even the default category (0), or if a given channel is either
-.Dq broken
-or
-.Dq off
-(i.e., its flags have
-.Dv LOG_CHANNEL_BROKEN
-or
-.Dv LOG_CHANNEL_OFF
-set, respectively), or if the logging channel channel is of type
-.Dv log_null .
-Additionally, if the logging channel's flag has
-.Dv LOG_REQUIRE_DEBUG
-set and the message is not a debugging message (i.e., has a level greater
-than 0), then it will not be logged.
-Finally, if the message's priority is less important than the
-channel's logging level (the priority threshold), will not be logged.
-.Sy NOTE :
-If a logging channel's flag has
-.Dv LOG_USE_CONTEXT_LEVEL
-set, it will use the logging context's priority, rather than its own.
-.Pp
-If all of these hurdles are passed, then only
-.Dv log_syslog
-and
-.Dv log_file
-channels actually can have logging. For channels which use
-.Xr syslog 3 ,
-the channel's
-.Xr syslog 3
-facility is used in conjunction with a potentially modified form of the
-message's priority level, since
-.Xr syslog 3
-has its own system of priorities
-.Pq Pa /usr/include/syslog.h .
-All debug messages (priority >= 0) are mapped to
-.Xr syslog 3 Ns 's
-.Dv LOG_DEBUG
-priority, all messages
-.Dq more important
-than
-.Dv log_critical
-are mapped to
-.Dv LOG_CRIT ,
-and the priorities corresponding to the ones listed in the section
-.Sx Message Priorities
-are given the obvious corresponding
-.Xr syslog 3
-priority.
-.Pp
-For
-.Dv log_file
-type logging channels, if the file size is greater than the maximum file
-size, then no logging occurs. (The same thing happens if a
-.Dv NULL
-stream is encountered and
-.Fn log_open_stream
-fails to open the channel's stream.)
-.Pp
-For both logging to normal files and logging via
-.Xr syslog 3 ,
-the value of the flags
-.Dv LOG_TIMESTAMP ,
-.Dv LOG_PRINT_CATEGORY ,
-and
-.Dv LOG_PRINT_LEVEL
-are used in determining whether or not these items are included in the logged
-information.
-.Pp
-The
-.Fn log_write
-function is merely a front-end to a call to
-.Fn log_vwrite ;
-see the description of that function, above, for more information.
-.Pp
-.Fn log_check
-and
-.Fn log_check_channel
-are used to see if a contemplated logging call will actually generate any
-output, which is useful when creating a log message involves non-trivial
-work.
-.Fn log_check
-will return non-zero if a call to
-.Fn log_vwrite
-with the given
-.Fa category
-and
-.Fa level
-would generate output on any channels, and zero otherwise.
-.Fn log_check_channel
-will return non-zero if writing to the
-.Fa chan
-at the given
-.Fa level
-would generate output.
-.Pp
-The function
-.Fn log_new_context
-creates a new
-.Nm logging context ,
-and stores this in the
-.Dq Va opaque
-field of the argument
-.Dq Fa lc ,
-and opaque structure used internally. This new
-.Nm context
-will include the
-.Dq Fa num_categories
-and
-.Dq Fa category_names
-which are supplied; the latter can be
-.Dv NULL .
-.Sy NOTE :
-Since
-.Dq Fa category_names
-is used directly, it
-.Em must not
-be freed by the caller, if it is
-.No non- Ns Dv NULL .
-The initial logging flags and priority are both set to zero.
-.Pp
-The
-.Fn log_free_context
-function is used to free the opaque structure
-.Dq Va lc.opaque
-and its components.
-.Sy NOTE :
-The
-.Dq Va opaque
-field of
-.Dq Fa lc
-.Em must
-be
-.No non- Ns Dv NULL .
-For each of the various
-.Dq categories
-(indicated by the
-.Dq Va num_categories
-which were in the corresponding call to
-.Fn log_new_context )
-associated with the given
-.Nm logging context ,
-.Em all
-of the
-.Nm logging channels
-are
-.Xr free 3 Ns -d .
-The opaque structure itself is then
-.Xr free 3 Ns -d ,
-and
-.Dq Va lc.opaque
-is set to
-.Dv NULL .
-.Pp
-.Sy NOTE :
-The function
-.Fn log_free_context
-does
-.Em not
-free the memory associated with
-.Fa category_names ,
-since the logging library did not allocate the memory for it, originally;
-it was supplied in the call to
-.Fn log_new_context .
-.Pp
-The function
-.Fn log_add_channel
-adds the
-.Nm logging channel
-.Dq Fa chan
-to the list of logging channels in the given
-.Fa category
-of the
-.Nm logging context
-.Dq Fa lc .
-No checking is performed to see whether or not
-.Fa chan
-is already present in the given
-.Fa category ,
-so multiple instances in a single
-.Fa category
-can occur (but see
-.Fn log_remove_channel ,
-below).
-.Pp
-The
-.Fn log_remove_channel
-function
-removes
-.Em all
-occurrences of the
-.Nm logging channel
-.Dq Fa chan
-from the list of logging channels in the given
-.Fa category
-of the
-.Nm logging context
-.Dq Fa lc .
-It also attempts to free the channel by calling
-.Fn log_free_channel
-(see its description, below).
-.Pp
-The
-.Fn log_option
-function is used to change the
-.Fa option
-of the indicated logging context
-.Fa lc
-to the given
-.Fa value .
-The
-.Fa option
-can be either
-.Dv LOG_OPTION_LEVEL
-or
-.Dv LOG_OPTION_DEBUG ;
-in the first case, the log context's debugging level is reset to the
-indicated level. If the
-.Fa option
-is
-.Dv LOG_OPTION_DEBUG ,
-then a non-zero
-.Fa value
-results in setting the debug flag of the logging context, while a zero
-.Fa value
-means that the debug flag is reset.
-.Pp
-The
-.Fn log_category_is_active
-test returns a 1 if the given
-.Fa category
-of the indicated logging context
-.Fa lc
-has at least one logging channel, and 0, otherwise.
-.Pp
-The functions
-.Fn log_new_syslog_channel ,
-.Fn log_new_file_channel ,
-and
-.Fn log_new_null_channel
-create a new channel of the type specified (thus, the difference in arguments);
-the
-.Dq Va type
-field of the new
-.Do
-.Ft struct log_channel
-.Dc
-is always set to the appropriate value.
-.Pp
-The
-.Fn log_new_syslog_channel
-function
-.Xr malloc 3 Ns -s
-a new
-.Ft struct log_channel
-of
-.Va type
-.Dv log_syslog ,
-i.e., a logging channel which will use
-.Xr syslog 3 .
-The new structure is filled out with the
-.Dq Fa flags ,
-.Dq Fa level ,
-and
-.Dq Fa facility
-which are given; the
-.Va references
-field is initialized to zero.
-See
-.Sx Logging Channel Flags
-and
-.Sx Message Priorities ,
-above, or the header file for information about acceptable values for
-.Dq Fa flags ,
-and
-.Dq Fa level .
-The
-.Dq Fa facility .
-can be any valid
-.Xr syslog 3
-facility; see the appropriate system header file or manpage for more
-information.
-.Pp
-.Ft log_channel
-.Fn log_new_file_channel "unsigned int flags" "int level" \
- "char *name" "FILE *stream" "unsigned int versions" \
- "unsigned long max_size"
-.Pp
-.Fn log_new_null_channel
-.Pp
-The functions
-.Fn log_inc_references
-and
-.Fn log_dec_references
-increment or decrements, respectively, the
-.Va references
-field of the logging channel pointed to by
-.Dq Fa chan ,
-if it is a valid channel (and if the
-.Va references
-field is strictly positive, in the case of
-.Fn log_dec_references ) .
-These functions are meant to track changes in the number of different clients
-which refer to the given logging channel.
-.Pp
-The
-.Fn log_free_channel
-function frees the
-field of the logging channel pointed to by
-.Dq Fa chan
-if there are no more outstanding references to it. If the channel uses a file,
-the stream is
-.Xr fclose 3 Ns -d
-(if the
-.Dv LOG_CLOSE_STREAM
-flag is set), and the filename, if
-.No non- Ns Dv NULL ,
-is
-.Xr free 3 Ns -d
-before
-.Dq Fa chan
-is
-.Xr free 3 Ns -d .
-.Pp
-.\" The following requests should be uncommented and
-.\" used where appropriate. This next request is
-.\" for sections 2 and 3 function return values only.
-.Sh RETURN VALUES
-.\" This next request is for sections 1, 6, 7 & 8 only
-.Bl -tag -width "log_category_is_active()"
-.It Fn log_open_stream
-.Dv NULL
-is returned under any of several error conditions:
-a) if
-.Dq Fa chan
-is either
-.Dv NULL
-or a
-.No non- Ns Dv log_file
-channel
-.Pq Va errno No is set to Dv EINVAL ;
-b) if either versioning or truncation is requested for a non-normal file
-.Pq Va errno No is set to Dv EINVAL ;
-c) if any of
-.Xr stat 2 ,
-.Xr open 2 ,
-or
-.Xr fdopen 3
-fails
-.Po
-.Va errno
-is set by the call which failed
-.Pc .
-If some value other than
-.Dv NULL
-is returned, then it is a valid logging stream (either newly-opened or
-already-open).
-.It Fn log_close_stream
--1 if the stream associated with
-.Dq Fa chan
-is
-.No non- Ns Dv NULL
-and the call to
-.Xr fclose 3
-fails.
-0 if successful or the logging channel pointed to by
-.Dq Fa chan
-is invalid (i.e.,
-.Dv NULL
-or not a logging channel which has uses a file); in the latter case,
-.Va errno
-is set to
-.Dv EINVAL .
-.It Fn log_get_stream
-.Dv NULL
-under the same conditions as those under which
-.Fn log_close_stream ,
-above, returns 0 (including the setting of
-.Va errno ) .
-Otherwise, the stream associated with the logging channel is returned.
-.It Fn log_get_filename
-.Dv NULL
-under the same conditions as those under which
-.Fn log_close_stream ,
-above, returns 0 (including the setting of
-.Va errno ) .
-Otherwise, the name of the file associated with the logging channel is
-returned.
-.It Fn log_new_context
--1 if
-.Xr malloc 3
-fails
-.Pq with Va errno No set to Dv ENOMEM .
-Otherwise, 0, with
-.Dq Va lc->opaque
-containing the new structures and information.
-.It Fn log_add_channel
--1 if
-a) either
-.Dq Va lc.opaque
-is
-.Dv NULL
-or
-.Fa category
-is invalid (negative or greater than or equal to
-.Va lcp->num_categories ) ,
-with
-.Va errno
-set to
-.Dv EINVAL ;
-b)
-.Xr malloc 3
-fails
-.Pq with Va errno No set to Dv ENOMEM .
-Otherwise, 0.
-.It Fn log_remove_channel
--1 if
-a) either
-.Dq Va lc.opaque
-is
-.Dv NULL
-or
-.Fa category
-is invalid, as under failure condition a) for
-.Fn log_add_channel ,
-above, including the setting of
-.Va errno ;
-b) no channel numbered
-.Fa chan
-is found in the logging context indicated by
-.Fa lc
-.Pq with Va errno No set to Dv ENOENT .
-Otherwise, 0.
-.It Fn log_option
--1 if
-a)
-.Dq Va lc.opaque
-is
-.Dv NULL ,
-b)
-.Fa option
-specifies an unknown logging option;
-in either case,
-.Va errno
-is set to
-.Dv EINVAL .
-Otherwise, 0.
-.It Fn log_category_is_active
--1 if
-.Dq Va lc.opaque
-is
-.Dv NULL
-.Pq with Va errno No set to Dv EINVAL ;
-1 if the
-.Fa category
-number is valid and there are logging channels in this
-.Fa category
-within the indicated logging context; 0 if the
-.Fa category
-number is invalid or there are no logging channels in this
-.Fa category
-within the indicated logging context.
-.It Fn log_new_syslog_channel
-.Dv NULL
-if
-.Xr malloc 3
-fails
-.Pq with Va errno No set to ENOMEM ;
-otherwise, a valid
-.Dv log_syslog Ns -type
-.Ft log_channel .
-.It Fn log_new_file_channel
-.Dv NULL
-if
-.Xr malloc 3
-fails
-.Pq with Va errno No set to ENOMEM ;
-otherwise, a valid
-.Dv log_file Ns -type
-.Ft log_channel .
-.It Fn log_new_null_channel
-.Dv NULL
-if
-.Xr malloc 3
-fails
-.Pq with Va errno No set to ENOMEM ;
-otherwise, a valid
-.Dv log_null Ns -type
-.Ft log_channel .
-.It Fn log_inc_references
--1 if
-.Dq Fa chan
-is
-.Dv NULL
-.Pq with Va errno set to Dv EINVAL .
-Otherwise, 0.
-.It Fn log_dec_references
--1 if
-.Dq Fa chan
-is
-.Dv NULL
-or its
-.Va references
-field is already <= 0
-.Pq with Va errno set to Dv EINVAL .
-Otherwise, 0.
-.It Fn log_free_channel
--1 under the same conditions as
-.Fn log_dec_references ,
-above, including the setting of
-.Va errno ;
-0 otherwise.
-.El
-.\" .Sh ENVIRONMENT
-.Sh FILES
-.Bl -tag -width "isc/logging.h"
-.It Pa isc/logging.h
-include file for logging library
-.It Pa syslog.h
-.Xr syslog 3 Ns -style
-priorities
-.El
-.\" .Sh EXAMPLES
-.\" This next request is for sections 1, 6, 7 & 8 only
-.\" (command return values (to shell) and
-.\" fprintf/stderr type diagnostics)
-.\" .Sh DIAGNOSTICS
-.\" The next request is for sections 2 and 3 error
-.\" and signal handling only.
-.Sh ERRORS
-This table shows which functions can return the indicated error in the
-.Va errno
-variable; see the
-.Sx RETURN VALUES
-section, above, for more information.
-.Bl -tag -width "(any0other0value)0"
-.It Dv EINVAL
-.Fn log_open_stream ,
-.Fn log_close_stream ,
-.Fn log_get_stream ,
-.Fn log_get_filename ,
-.Fn log_add_channel ,
-.Fn log_remove_channel ,
-.Fn log_option ,
-.Fn log_category_is_active ,
-.Fn log_inc_references ,
-.Fn log_dec_references ,
-.Fn log_free_channel .
-.It Dv ENOENT
-.Fn log_remove_channel .
-.It Dv ENOMEM
-.Fn log_new_context ,
-.Fn log_add_channel ,
-.Fn log_new_syslog_channel ,
-.Fn log_new_file_channel ,
-.Fn log_new_null_channel .
-.It (any other value)
-returned via a pass-through of an error code from
-.Xr stat 2 ,
-.Xr open 2 ,
-or
-.Xr fdopen 3 ,
-which can occur in
-.Fn log_open_stream
-and functions which call it
-.Pq currently, only Fn log_vwrite .
-.El
-.Pp
-Additionally,
-.Fn log_vwrite
-and
-.Fn log_free_context
-will fail via
-.Fn assert
-if
-.Dq Va lc.opaque
-is
-.Dv NULL .
-The function
-.Fn log_vwrite
-can also exit with a critical error logged via
-.Xr syslog 3
-indicating a memory overrun
-.Sh SEE ALSO
-.Xr @INDOT@named @SYS_OPS_EXT@ ,
-.Xr syslog 3 .
-The HTML documentation includes a file,
-.Pa logging.html ,
-which has more information about this logging system.
-.\" .Sh STANDARDS
-.\" .Sh HISTORY
-.Sh AUTHORS
-Bob Halley...TODO
-.\" .Sh BUGS
diff --git a/contrib/bind/lib/isc/logging_p.h b/contrib/bind/lib/isc/logging_p.h
deleted file mode 100644
index 875da0e..0000000
--- a/contrib/bind/lib/isc/logging_p.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 1996-1999 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.
- */
-
-#ifndef LOGGING_P_H
-#define LOGGING_P_H
-
-typedef struct log_file_desc {
- char *name;
- size_t name_size;
- FILE *stream;
- unsigned int versions;
- unsigned long max_size;
- uid_t owner;
- gid_t group;
-} log_file_desc;
-
-typedef union log_output {
- int facility;
- log_file_desc file;
-} log_output;
-
-struct log_channel {
- int level; /* don't log messages > level */
- log_channel_type type;
- log_output out;
- unsigned int flags;
- int references;
-};
-
-typedef struct log_channel_list {
- log_channel channel;
- struct log_channel_list *next;
-} *log_channel_list;
-
-#define LOG_BUFFER_SIZE 20480
-
-struct log_context {
- int num_categories;
- char **category_names;
- log_channel_list *categories;
- int flags;
- int level;
- char buffer[LOG_BUFFER_SIZE];
-};
-
-#endif /* !LOGGING_P_H */
diff --git a/contrib/bind/lib/isc/memcluster.c b/contrib/bind/lib/isc/memcluster.c
deleted file mode 100644
index fcba1a3..0000000
--- a/contrib/bind/lib/isc/memcluster.c
+++ /dev/null
@@ -1,545 +0,0 @@
-/*
- * Copyright (c) 1997,1999 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.
- */
-
-
-/* When this symbol is defined allocations via memget are made slightly
- bigger and some debugging info stuck before and after the region given
- back to the caller. */
-/* #define DEBUGGING_MEMCLUSTER */
-#define MEMCLUSTER_ATEND
-
-
-#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: memcluster.c,v 8.23 2001/06/18 14:44:05 marka Exp $";
-#endif /* not lint */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <sys/uio.h>
-#include <sys/param.h>
-#include <sys/stat.h>
-
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-
-#include <isc/memcluster.h>
-#include <isc/assertions.h>
-
-#include "port_after.h"
-
-#ifdef MEMCLUSTER_RECORD
-#ifndef DEBUGGING_MEMCLUSTER
-#define DEBUGGING_MEMCLUSTER
-#endif
-#endif
-
-#define DEF_MAX_SIZE 1100
-#define DEF_MEM_TARGET 4096
-
-typedef u_int32_t fence_t;
-
-typedef struct {
- void * next;
-#if defined(DEBUGGING_MEMCLUSTER)
-#if defined(MEMCLUSTER_RECORD)
- const char * file;
- int line;
-#endif
- size_t size;
- fence_t fencepost;
-#endif
-} memcluster_element;
-
-#define SMALL_SIZE_LIMIT sizeof(memcluster_element)
-#define P_SIZE sizeof(void *)
-#define FRONT_FENCEPOST 0xfebafeba
-#define BACK_FENCEPOST 0xabefabef
-#define FENCEPOST_SIZE 4
-
-#ifndef MEMCLUSTER_LITTLE_MALLOC
-#define MEMCLUSTER_BIG_MALLOC 1
-#define NUM_BASIC_BLOCKS 64
-#endif
-
-struct stats {
- u_long gets;
- u_long totalgets;
- u_long blocks;
- u_long freefrags;
-};
-
-/* Private data. */
-
-static size_t max_size;
-static size_t mem_target;
-static size_t mem_target_half;
-static size_t mem_target_fudge;
-static memcluster_element ** freelists;
-#ifdef MEMCLUSTER_RECORD
-static memcluster_element ** activelists;
-#endif
-#ifdef MEMCLUSTER_BIG_MALLOC
-static memcluster_element * basic_blocks;
-#endif
-static struct stats * stats;
-
-/* Forward. */
-
-static size_t quantize(size_t);
-#if defined(DEBUGGING_MEMCLUSTER)
-static void check(unsigned char *, int, size_t);
-#endif
-
-/* Public. */
-
-int
-meminit(size_t init_max_size, size_t target_size) {
-
-#if defined(DEBUGGING_MEMCLUSTER)
- INSIST(sizeof(fence_t) == FENCEPOST_SIZE);
-#endif
- if (freelists != NULL) {
- errno = EEXIST;
- return (-1);
- }
- if (init_max_size == 0)
- max_size = DEF_MAX_SIZE;
- else
- max_size = init_max_size;
- if (target_size == 0)
- mem_target = DEF_MEM_TARGET;
- else
- mem_target = target_size;
- mem_target_half = mem_target / 2;
- mem_target_fudge = mem_target + mem_target / 4;
- freelists = malloc(max_size * sizeof (memcluster_element *));
- stats = malloc((max_size+1) * sizeof (struct stats));
- if (freelists == NULL || stats == NULL) {
- errno = ENOMEM;
- return (-1);
- }
- memset(freelists, 0,
- max_size * sizeof (memcluster_element *));
- memset(stats, 0, (max_size + 1) * sizeof (struct stats));
-#ifdef MEMCLUSTER_RECORD
- activelists = malloc((max_size + 1) * sizeof (memcluster_element *));
- if (activelists == NULL) {
- errno = ENOMEM;
- return (-1);
- }
- memset(activelists, 0,
- (max_size + 1) * sizeof (memcluster_element *));
-#endif
-#ifdef MEMCLUSTER_BIG_MALLOC
- basic_blocks = NULL;
-#endif
- return (0);
-}
-
-void *
-__memget(size_t size) {
- return (__memget_record(size, NULL, 0));
-}
-
-void *
-__memget_record(size_t size, const char *file, int line) {
- size_t new_size = quantize(size);
-#if defined(DEBUGGING_MEMCLUSTER)
- memcluster_element *e;
- char *p;
- fence_t fp = BACK_FENCEPOST;
-#endif
- void *ret;
-
-#if !defined(MEMCLUSTER_RECORD)
- UNUSED(file);
- UNUSED(line);
-#endif
- if (freelists == NULL)
- if (meminit(0, 0) == -1)
- return (NULL);
- if (size == 0) {
- errno = EINVAL;
- return (NULL);
- }
- if (size >= max_size || new_size >= max_size) {
- /* memget() was called on something beyond our upper limit. */
- stats[max_size].gets++;
- stats[max_size].totalgets++;
-#if defined(DEBUGGING_MEMCLUSTER)
- e = malloc(new_size);
- if (e == NULL) {
- errno = ENOMEM;
- return (NULL);
- }
- e->next = NULL;
- e->size = size;
-#ifdef MEMCLUSTER_RECORD
- e->file = file;
- e->line = line;
- e->next = activelists[max_size];
- activelists[max_size] = e;
-#endif
- e->fencepost = FRONT_FENCEPOST;
- p = (char *)e + sizeof *e + size;
- memcpy(p, &fp, sizeof fp);
- return ((char *)e + sizeof *e);
-#else
- return (malloc(size));
-#endif
- }
-
- /*
- * If there are no blocks in the free list for this size, get a chunk
- * of memory and then break it up into "new_size"-sized blocks, adding
- * them to the free list.
- */
- if (freelists[new_size] == NULL) {
- int i, frags;
- size_t total_size;
- void *new;
- char *curr, *next;
-
-#ifdef MEMCLUSTER_BIG_MALLOC
- if (basic_blocks == NULL) {
- new = malloc(NUM_BASIC_BLOCKS * mem_target);
- if (new == NULL) {
- errno = ENOMEM;
- return (NULL);
- }
- curr = new;
- next = curr + mem_target;
- for (i = 0; i < (NUM_BASIC_BLOCKS - 1); i++) {
- ((memcluster_element *)curr)->next = next;
- curr = next;
- next += mem_target;
- }
- /*
- * curr is now pointing at the last block in the
- * array.
- */
- ((memcluster_element *)curr)->next = NULL;
- basic_blocks = new;
- }
- total_size = mem_target;
- new = basic_blocks;
- basic_blocks = basic_blocks->next;
-#else
- if (new_size > mem_target_half)
- total_size = mem_target_fudge;
- else
- total_size = mem_target;
- new = malloc(total_size);
- if (new == NULL) {
- errno = ENOMEM;
- return (NULL);
- }
-#endif
- frags = total_size / new_size;
- stats[new_size].blocks++;
- stats[new_size].freefrags += frags;
- /* Set up a linked-list of blocks of size "new_size". */
- curr = new;
- next = curr + new_size;
- for (i = 0; i < (frags - 1); i++) {
-#if defined (DEBUGGING_MEMCLUSTER)
- memset(curr, 0xa5, new_size);
-#endif
- ((memcluster_element *)curr)->next = next;
- curr = next;
- next += new_size;
- }
- /* curr is now pointing at the last block in the array. */
-#if defined (DEBUGGING_MEMCLUSTER)
- memset(curr, 0xa5, new_size);
-#endif
- ((memcluster_element *)curr)->next = freelists[new_size];
- freelists[new_size] = new;
- }
-
- /* The free list uses the "rounded-up" size "new_size". */
-#if defined (DEBUGGING_MEMCLUSTER)
- e = freelists[new_size];
- ret = (char *)e + sizeof *e;
- /*
- * Check to see if this buffer has been written to while on free list.
- */
- check(ret, 0xa5, new_size - sizeof *e);
- /*
- * Mark memory we are returning.
- */
- memset(ret, 0xe5, size);
-#else
- ret = freelists[new_size];
-#endif
- freelists[new_size] = freelists[new_size]->next;
-#if defined(DEBUGGING_MEMCLUSTER)
- e->next = NULL;
- e->size = size;
- e->fencepost = FRONT_FENCEPOST;
-#ifdef MEMCLUSTER_RECORD
- e->file = file;
- e->line = line;
- e->next = activelists[size];
- activelists[size] = e;
-#endif
- p = (char *)e + sizeof *e + size;
- memcpy(p, &fp, sizeof fp);
-#endif
-
- /*
- * The stats[] uses the _actual_ "size" requested by the
- * caller, with the caveat (in the code above) that "size" >= the
- * max. size (max_size) ends up getting recorded as a call to
- * max_size.
- */
- stats[size].gets++;
- stats[size].totalgets++;
- stats[new_size].freefrags--;
-#if defined(DEBUGGING_MEMCLUSTER)
- return ((char *)e + sizeof *e);
-#else
- return (ret);
-#endif
-}
-
-/*
- * This is a call from an external caller,
- * so we want to count this as a user "put".
- */
-void
-__memput(void *mem, size_t size) {
- __memput_record(mem, size, NULL, 0);
-}
-
-void
-__memput_record(void *mem, size_t size, const char *file, int line) {
- size_t new_size = quantize(size);
-#if defined (DEBUGGING_MEMCLUSTER)
- memcluster_element *e;
- memcluster_element *el;
-#ifdef MEMCLUSTER_RECORD
- memcluster_element *prev;
-#endif
- fence_t fp;
- char *p;
-#endif
-
-#if !defined (MEMCLUSTER_RECORD)
- UNUSED(file);
- UNUSED(line);
-#endif
-
- REQUIRE(freelists != NULL);
-
- if (size == 0) {
- errno = EINVAL;
- return;
- }
-
-#if defined (DEBUGGING_MEMCLUSTER)
- e = (memcluster_element *) ((char *)mem - sizeof *e);
- INSIST(e->fencepost == FRONT_FENCEPOST);
- INSIST(e->size == size);
- p = (char *)e + sizeof *e + size;
- memcpy(&fp, p, sizeof fp);
- INSIST(fp == BACK_FENCEPOST);
- INSIST(((int)mem % 4) == 0);
-#ifdef MEMCLUSTER_RECORD
- prev = NULL;
- if (size == max_size || new_size >= max_size)
- el = activelists[max_size];
- else
- el = activelists[size];
- while (el != NULL && el != e) {
- prev = el;
- el = el->next;
- }
- INSIST(el != NULL); /* double free */
- if (prev == NULL) {
- if (size == max_size || new_size >= max_size)
- activelists[max_size] = el->next;
- else
- activelists[size] = el->next;
- } else
- prev->next = el->next;
-#endif
-#endif
-
- if (size == max_size || new_size >= max_size) {
- /* memput() called on something beyond our upper limit */
-#if defined(DEBUGGING_MEMCLUSTER)
- free(e);
-#else
- free(mem);
-#endif
-
- INSIST(stats[max_size].gets != 0);
- stats[max_size].gets--;
- return;
- }
-
- /* The free list uses the "rounded-up" size "new_size": */
-#if defined(DEBUGGING_MEMCLUSTER)
- memset(mem, 0xa5, new_size - sizeof *e); /* catch write after free */
- e->size = 0; /* catch double memput() */
-#ifdef MEMCLUSTER_RECORD
- e->file = file;
- e->line = line;
-#endif
-#ifdef MEMCLUSTER_ATEND
- e->next = NULL;
- el = freelists[new_size];
- while (el != NULL && el->next != NULL)
- el = el->next;
- if (el)
- el->next = e;
- else
- freelists[new_size] = e;
-#else
- e->next = freelists[new_size];
- freelists[new_size] = (void *)e;
-#endif
-#else
- ((memcluster_element *)mem)->next = freelists[new_size];
- freelists[new_size] = (memcluster_element *)mem;
-#endif
-
- /*
- * The stats[] uses the _actual_ "size" requested by the
- * caller, with the caveat (in the code above) that "size" >= the
- * max. size (max_size) ends up getting recorded as a call to
- * max_size.
- */
- INSIST(stats[size].gets != 0);
- stats[size].gets--;
- stats[new_size].freefrags++;
-}
-
-void *
-__memget_debug(size_t size, const char *file, int line) {
- void *ptr;
- ptr = __memget_record(size, file, line);
- fprintf(stderr, "%s:%d: memget(%lu) -> %p\n", file, line,
- (u_long)size, ptr);
- return (ptr);
-}
-
-void
-__memput_debug(void *ptr, size_t size, const char *file, int line) {
- fprintf(stderr, "%s:%d: memput(%p, %lu)\n", file, line, ptr,
- (u_long)size);
- __memput_record(ptr, size, file, line);
-}
-
-/*
- * Print the stats[] on the stream "out" with suitable formatting.
- */
-void
-memstats(FILE *out) {
- size_t i;
-#ifdef MEMCLUSTER_RECORD
- memcluster_element *e;
-#endif
-
- if (freelists == NULL)
- return;
- for (i = 1; i <= max_size; i++) {
- const struct stats *s = &stats[i];
-
- if (s->totalgets == 0 && s->gets == 0)
- continue;
- fprintf(out, "%s%5d: %11lu gets, %11lu rem",
- (i == max_size) ? ">=" : " ",
- i, s->totalgets, s->gets);
- if (s->blocks != 0)
- fprintf(out, " (%lu bl, %lu ff)",
- s->blocks, s->freefrags);
- fputc('\n', out);
- }
-#ifdef MEMCLUSTER_RECORD
- fprintf(out, "Active Memory:\n");
- for (i = 1; i <= max_size; i++) {
- if ((e = activelists[i]) != NULL)
- while (e != NULL) {
- fprintf(out, "%s:%d %p:%d\n",
- e->file != NULL ? e->file :
- "<UNKNOWN>", e->line,
- (char *)e + sizeof *e, e->size);
- e = e->next;
- }
- }
-#endif
-}
-
-int
-memactive(void) {
- size_t i;
-
- if (stats == NULL)
- return (0);
- for (i = 1; i <= max_size; i++)
- if (stats[i].gets != 0)
- return (1);
- return (0);
-}
-
-/* Private. */
-
-/*
- * Round up size to a multiple of sizeof(void *). This guarantees that a
- * block is at least sizeof void *, and that we won't violate alignment
- * restrictions, both of which are needed to make lists of blocks.
- */
-static size_t
-quantize(size_t size) {
- int remainder;
- /*
- * If there is no remainder for the integer division of
- *
- * (rightsize/P_SIZE)
- *
- * then we already have a good size; if not, then we need
- * to round up the result in order to get a size big
- * enough to satisfy the request _and_ aligned on P_SIZE boundaries.
- */
- remainder = size % P_SIZE;
- if (remainder != 0)
- size += P_SIZE - remainder;
-#if defined(DEBUGGING_MEMCLUSTER)
- return (size + SMALL_SIZE_LIMIT + sizeof (int));
-#else
- return (size);
-#endif
-}
-
-#if defined(DEBUGGING_MEMCLUSTER)
-static void
-check(unsigned char *a, int value, size_t len) {
- size_t i;
- for (i = 0; i < len; i++)
- INSIST(a[i] == value);
-}
-#endif
diff --git a/contrib/bind/lib/isc/memcluster.mdoc b/contrib/bind/lib/isc/memcluster.mdoc
deleted file mode 100644
index c4c4588..0000000
--- a/contrib/bind/lib/isc/memcluster.mdoc
+++ /dev/null
@@ -1,376 +0,0 @@
-.\" $Id: memcluster.mdoc,v 8.3 2001/08/08 07:50:27 marka Exp $
-.\"
-.\"Copyright (c) 1995-1999 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.
-.\"
-.\" The following six UNCOMMENTED lines are required.
-.Dd Month day, year
-.\"Os OPERATING_SYSTEM [version/release]
-.Os BSD 4
-.\"Dt DOCUMENT_TITLE [section number] [volume]
-.Dt MEMCLUSTER 3
-.Sh NAME
-.Nm meminit ,
-.Nm memget ,
-.Nm memput ,
-.Nm memstats
-.Nd memory allocation/deallocation system
-.Sh SYNOPSIS
-.Fd #include \&<isc/memcluster.h\&>
-.Ft void *
-.Fn memget "size_t size"
-.Ft void
-.Fn memput "void *mem" "size_t size"
-.Ft void
-.Fn memstats "FILE *out"
-.Sh DESCRIPTION
-These functions access a memory management system which allows callers to not
-fragment memory to the extent which can ordinarily occur through many random
-calls to
-.Xr malloc 3 .
-Instead,
-.Fn memget
-gets a large contiguous chunk of blocks of the requested
-.Fa size
-and parcels out these blocks as requested. The symmetric call is
-.Fn memput ,
-which callers use to return a piece of memory obtained from
-.Fn memget .
-Statistics about memory usage are returned by
-.Fn memstats ,
-which prints a report on the stream
-.Fa out .
-.Ss INTERNALS
-Internally, linked lists of free memory blocks are stored in an array.
-The size of this array is determined by the value
-.Dv MEM_FREECOUNT ,
-currently set to 1100. In general, for any requested blocksize
-.Dq Fa size ,
-any free blocks will be stored on the linked list at that index.
-No free lists are managed for blocks greater than or equal to
-.Dv MEM_FREECOUNT
-bytes; instead, calls to
-.Xr malloc 3
-or
-.Xr free 3
-are made, directly.
-.Pp
-Since the blocks are actually stored as linked lists, they must at least
-be large enough to hold a pointer to the next block. This size, which is
-.Dv SMALL_SIZE_LIMIT ,
-is currently defined as
-.Bd -literal -offset indent
-#define SMALL_SIZE_LIMIT sizeof(struct { void *next; })
-.Ed
-.Pp
-Both
-.Fn memget
-and
-.Fn memput
-enforce this limit; for example, any call to
-.Fn memget
-requesting a block smaller than
-.Dv SMALL_SIZE_LIMIT
-bytes will actually be considered to be of size
-.Dv SMALL_SIZE_LIMIT
-internally. (Such a caller request will be logged for
-.Fn memstats
-purposes using the caller-requested
-.Fa size ;
-see the discussion of
-.Fn memstats ,
-below, for more information.)
-.Pp
-Additionally, the requested
-.Fa size
-will be adjusted so that when a large
-.Xr malloc 3 Ns No -d
-chunk of memory is broken up into a linked list, the blocks will all fall on
-the correct memory alignment boundaries. Thus, one can conceptualize a call
-which mentions
-.Fa size
-as resulting in a
-.Fa new_size
-which is used internally.
-.Pp
-In order to more efficiently allocate memory, there is a
-.Dq target
-size for calls to
-.Xr malloc 3 .
-It is given by the pre-defined value
-.Dv MEM_TARGET ,
-which is currently 4096 bytes.
-For any requested block
-.Fa size ,
-enough memory is
-.Xr malloc 3 Ns No -d
-in order to fill up a block of about
-.Dv MEM_TARGET
-bytes.
-.No [ Ns Sy NOTE :
-For allocations larger than
-.Dv MEM_TARGET Ns No /2
-bytes, there is a
-.Dq fudge factor
-introduced which boosts the target size by 25% of
-.Dv MEM_TARGET .
-This means that enough memory for two blocks
-will actually be allocated for any
-.Fa size
-such that
-.Pq Dv MEM_TARGET Ns No / 3
-.No < Fa size No <
-.Pq Dv MEM_TARGET Ns No *5/8 ,
-provided that the value of
-.Dv MEM_FREECOUNT
-is at least as large as the upper limit shown above.]
-.Pp
-.Ss FUNCTION DESCRIPTIONS
-.Pp
-The function
-.Fn memget
-returns a pointer to a block of memory of at least the requested
-.Fa size .
-After adjusting
-.Fa size
-to the value
-.Va new_size
-as mentioned above in the
-.Sx INTERNALS
-subsection, the internal array of free lists is checked.
-If there is no block of the needed
-.Va new_size ,
-then
-.Fn memget
-will
-.Xr malloc 3
-a chunk of memory which is as many times as
-.Va new_size
-will fit into the target size. This memory is then turned into a linked list
-of
-.Va new_size Ns No -sized
-blocks which are given out as requested; the last such block is the first one
-returned by
-.Fn memget .
-If the requested
-.Fa size
-is zero or negative, then
-.Dv NULL
-is returned and
-.Va errno
-is set to
-.Dv EINVAL ;
-if
-.Fa size
-is larger than or equal to the pre-defined maximum size
-.Dv MEM_FREECOUNT ,
-then only a single block of exactly
-.Fa size
-will be
-.Xr malloc 3 Ns No -d
-and returned.
-.Pp
-The
-.Fn memput
-call is used to return memory once the caller is finished with it.
-After adjusting
-.Fa size
-the the value
-.Va new_size
-as mentioned in the
-.Sx INTERNALS
-subsection, above, the block is placed at the head of the free list of
-.Va new_size Ns -sized
-blocks.
-If the given
-.Fa size
-is zero or negative, then
-.Va errno
-is set to
-.Dv EINVAL ,
-as for
-.Fn memget .
-If
-.Fa size
-is larger than or equal to the pre-defined maximum size
-.Dv MEM_FREECOUNT ,
-then the block is immediately
-.Xr free 3 Ns No -d .
-.Pp
-.Sy NOTE :
-It is important that callers give
-.Fn memput
-.Em only
-blocks of memory which were previously obtained from
-.Fn memget
-if the block is
-.Em actually
-less than
-.Dv SMALL_SIZE_LIMIT
-bytes in size. Since all blocks will be added to a free list, any block
-which is not at least
-.Dv SMALL_SIZE_LIMIT
-bytes long will not be able to hold a pointer to the next block in the
-free list.
-.Pp
-The
-.Fn memstats
-function will summarize the number of calls to
-.Fn memget
-and
-.Fn memput
-for any block size from 1 byte up to
-.Pq Dv MEM_FREECOUNT No - 1
-bytes, followed by a single line for any calls using a
-.Fa size
-greater than or equal to
-.Dv MEM_FREECOUNT ;
-a brief header with shell-style comment lines prefaces the report and
-explains the information. The
-.Dv FILE
-pointer
-.Fa out
-identifies the stream which is used for this report. Currently,
-.Fn memstat
-reports the number of calls to
-.Fn memget
-and
-.Fn memput
-using the caller-supplied value
-.Fa size ;
-the percentage of outstanding blocks of a given size (i.e., the percentage
-by which calls to
-.Fn memget
-exceed
-.Fn memput )
-are also reported on the line for blocks of the given
-.Fa size .
-However, the percent of blocks used is computed using the number of
-blocks allocated according to the internal parameter
-.Va new_size ;
-it is the percentage of blocks used to those available at a given
-.Va new_size ,
-and is computed using the
-.Em total
-number of caller
-.Dq gets
-for any caller
-.Fa size Ns No -s
-which map to the internally-computed
-.Va new_size .
-Keep in mind that
-.Va new_size
-is generally
-.Em not
-equal to
-.Fa size ,
-which has these implications:
-.Bl -enum -offset indent
-.It
-For
-.Fa size
-smaller than
-.Dv SMALL_SIZE_LIMIT ,
-.Fn memstat
-.Em will
-show statistics for caller requests under
-.Fa size ,
-but "percent used" information about such blocks will be reported under
-.Dv SMALL_SIZE_LIMIT Ns No -sized
-blocks.
-.It
-As a general case of point 1, internal statistics are reported on the the
-line corresponding to
-.Va new_size ,
-so that, for a given caller-supplied
-.Fa size ,
-the associated internal information will appear on that line or on the next
-line which shows "percent used" information.
-.El
-.Pp
-.Sy NOTE :
-If the caller returns blocks of a given
-.Fa size
-and requests others of
-.Fa size Ns No -s
-which map to the same internal
-.Va new_size ,
-it is possible for
-.Fn memstats
-to report usage of greater than 100% for blocks of size
-.Va new_size .
-This should be viewed as A Good Thing.
-.Sh RETURN VALUES
-The function
-.Fn memget
-returns a
-.No non- Ns Dv NULL
-pointer to a block of memory of the requested
-.Fa size .
-It returns
-.Dv NULL
-if either the
-.Fa size
-is invalid (less than or equal to zero) or a
-.Xr malloc 3
-of a new block of memory fails. In the former case,
-.Va errno
-is set to
-.Dv EINVAL ;
-in the latter, it is set to
-.Dv ENOMEM .
-.Pp
-Neither
-.Fn memput
-nor
-.Fn memstats
-return a value.
-.\" This next request is for sections 1, 6, 7 & 8 only
-.\" .Sh ENVIRONMENT
-.\" .Sh FILES
-.\" .Sh EXAMPLES
-.\" This next request is for sections 1, 6, 7 & 8 only
-.\" (command return values (to shell) and
-.\" fprintf/stderr type diagnostics)
-.\" .Sh DIAGNOSTICS
-.\" The next request is for sections 2 and 3 error
-.\" and signal handling only.
-.Sh ERRORS
-.Va errno
-is set as follows:
-.Bl -tag -width "ENOMEM " -offset indent
-.It Dv EINVAL
-set by both
-.Fn memget
-and
-.Fn memput
-if the
-.Fa size
-is zero or negative
-.It Dv ENOMEM
-set by
-.Fn memget
-if a call to
-.Xr malloc 3
-fails
-.El
-.Sh SEE ALSO
-.Xr free 3 ,
-.Xr malloc 3 .
-.\" .Sh STANDARDS
-.\" .Sh HISTORY
-.Sh AUTHORS
-Steven J. Richardson and Paul Vixie, Vixie Enterprises.
-.\" .Sh BUGS
diff --git a/contrib/bind/lib/isc/movefile.c b/contrib/bind/lib/isc/movefile.c
deleted file mode 100644
index 1b64b6c..0000000
--- a/contrib/bind/lib/isc/movefile.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 2000 by Internet Software Consortium, Inc.
- *
- * 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 <port_before.h>
-#include <stdio.h>
-#include <isc/misc.h>
-#include <port_after.h>
-#ifndef HAVE_MOVEFILE
-/*
- * rename() is lame (can't overwrite an existing file) on some systems.
- * use movefile() instead, and let lame OS ports do what they need to.
- */
-
-int
-isc_movefile(const char *oldname, const char *newname) {
- return (rename(oldname, newname));
-}
-#else
- static int os_port_has_isc_movefile = 1;
-#endif
diff --git a/contrib/bind/lib/isc/tree.c b/contrib/bind/lib/isc/tree.c
deleted file mode 100644
index 65025e4..0000000
--- a/contrib/bind/lib/isc/tree.c
+++ /dev/null
@@ -1,532 +0,0 @@
-#ifndef LINT
-static const char rcsid[] = "$Id: tree.c,v 8.10 2001/11/01 05:33:46 marka Exp $";
-#endif
-
-/*
- * tree - balanced binary tree library
- *
- * vix 05apr94 [removed vixie.h dependencies; cleaned up formatting, names]
- * vix 22jan93 [revisited; uses RCS, ANSI, POSIX; has bug fixes]
- * vix 23jun86 [added delete uar to add for replaced nodes]
- * vix 20jun86 [added tree_delete per wirth a+ds (mod2 v.) p. 224]
- * vix 06feb86 [added tree_mung()]
- * vix 02feb86 [added tree balancing from wirth "a+ds=p" p. 220-221]
- * vix 14dec85 [written]
- */
-
-/*
- * This program text was created by Paul Vixie using examples from the book:
- * "Algorithms & Data Structures," Niklaus Wirth, Prentice-Hall, 1986, ISBN
- * 0-13-022005-1. Any errors in the conversion from Modula-2 to C are Paul
- * Vixie's.
- */
-
-/*
- * Portions Copyright (c) 1996-1999 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.
- */
-
-/*#define DEBUG "tree"*/
-
-#include "port_before.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "port_after.h"
-
-#include <isc/memcluster.h>
-#include <isc/tree.h>
-
-#ifdef DEBUG
-static int debugDepth = 0;
-static char *debugFuncs[256];
-# define ENTER(proc) { \
- debugFuncs[debugDepth] = proc; \
- fprintf(stderr, "ENTER(%d:%s.%s)\n", \
- debugDepth, DEBUG, \
- debugFuncs[debugDepth]); \
- debugDepth++; \
- }
-# define RET(value) { \
- debugDepth--; \
- fprintf(stderr, "RET(%d:%s.%s)\n", \
- debugDepth, DEBUG, \
- debugFuncs[debugDepth]); \
- return (value); \
- }
-# define RETV { \
- debugDepth--; \
- fprintf(stderr, "RETV(%d:%s.%s)\n", \
- debugDepth, DEBUG, \
- debugFuncs[debugDepth]); \
- return; \
- }
-# define MSG(msg) fprintf(stderr, "MSG(%s)\n", msg);
-#else
-# define ENTER(proc) ;
-# define RET(value) return (value);
-# define RETV return;
-# define MSG(msg) ;
-#endif
-
-#ifndef TRUE
-# define TRUE 1
-# define FALSE 0
-#endif
-
-static tree * sprout(tree **, tree_t, int *, int (*)(), void (*)());
-static int delete(tree **, int (*)(), tree_t, void (*)(), int *, int *);
-static void del(tree **, int *, tree **, void (*)(), int *);
-static void bal_L(tree **, int *);
-static void bal_R(tree **, int *);
-
-void
-tree_init(tree **ppr_tree) {
- ENTER("tree_init")
- *ppr_tree = NULL;
- RETV
-}
-
-tree_t
-tree_srch(tree **ppr_tree, int (*pfi_compare)(tree_t, tree_t), tree_t p_user) {
- ENTER("tree_srch")
-
- if (*ppr_tree) {
- int i_comp = (*pfi_compare)(p_user, (**ppr_tree).data);
-
- if (i_comp > 0)
- RET(tree_srch(&(**ppr_tree).right,
- pfi_compare,
- p_user))
-
- if (i_comp < 0)
- RET(tree_srch(&(**ppr_tree).left,
- pfi_compare,
- p_user))
-
- /* not higher, not lower... this must be the one.
- */
- RET((**ppr_tree).data)
- }
-
- /* grounded. NOT found.
- */
- RET(NULL)
-}
-
-tree_t
-tree_add(tree **ppr_tree, int (*pfi_compare)(tree_t, tree_t),
- tree_t p_user, void (*pfv_uar)())
-{
- int i_balance = FALSE;
-
- ENTER("tree_add")
- if (!sprout(ppr_tree, p_user, &i_balance, pfi_compare, pfv_uar))
- RET(NULL)
- RET(p_user)
-}
-
-int
-tree_delete(tree **ppr_p, int (*pfi_compare)(tree_t, tree_t),
- tree_t p_user, void (*pfv_uar)())
-{
- int i_balance = FALSE, i_uar_called = FALSE;
-
- ENTER("tree_delete");
- RET(delete(ppr_p, pfi_compare, p_user, pfv_uar,
- &i_balance, &i_uar_called))
-}
-
-int
-tree_trav(tree **ppr_tree, int (*pfi_uar)(tree_t)) {
- ENTER("tree_trav")
-
- if (!*ppr_tree)
- RET(TRUE)
-
- if (!tree_trav(&(**ppr_tree).left, pfi_uar))
- RET(FALSE)
- if (!(*pfi_uar)((**ppr_tree).data))
- RET(FALSE)
- if (!tree_trav(&(**ppr_tree).right, pfi_uar))
- RET(FALSE)
- RET(TRUE)
-}
-
-void
-tree_mung(tree **ppr_tree, void (*pfv_uar)(tree_t)) {
- ENTER("tree_mung")
- if (*ppr_tree) {
- tree_mung(&(**ppr_tree).left, pfv_uar);
- tree_mung(&(**ppr_tree).right, pfv_uar);
- if (pfv_uar)
- (*pfv_uar)((**ppr_tree).data);
- memput(*ppr_tree, sizeof(tree));
- *ppr_tree = NULL;
- }
- RETV
-}
-
-static tree *
-sprout(tree **ppr, tree_t p_data, int *pi_balance,
- int (*pfi_compare)(tree_t, tree_t), void (*pfv_delete)(tree_t))
-{
- tree *p1, *p2, *sub;
- int cmp;
-
- ENTER("sprout")
-
- /* are we grounded? if so, add the node "here" and set the rebalance
- * flag, then exit.
- */
- if (!*ppr) {
- MSG("grounded. adding new node, setting h=true")
- *ppr = (tree *) memget(sizeof(tree));
- if (*ppr) {
- (*ppr)->left = NULL;
- (*ppr)->right = NULL;
- (*ppr)->bal = 0;
- (*ppr)->data = p_data;
- *pi_balance = TRUE;
- }
- RET(*ppr);
- }
-
- /* compare the data using routine passed by caller.
- */
- cmp = (*pfi_compare)(p_data, (*ppr)->data);
-
- /* if LESS, prepare to move to the left.
- */
- if (cmp < 0) {
- MSG("LESS. sprouting left.")
- sub = sprout(&(*ppr)->left, p_data, pi_balance,
- pfi_compare, pfv_delete);
- if (sub && *pi_balance) { /* left branch has grown */
- MSG("LESS: left branch has grown")
- switch ((*ppr)->bal) {
- case 1:
- /* right branch WAS longer; bal is ok now */
- MSG("LESS: case 1.. bal restored implicitly")
- (*ppr)->bal = 0;
- *pi_balance = FALSE;
- break;
- case 0:
- /* balance WAS okay; now left branch longer */
- MSG("LESS: case 0.. balnce bad but still ok")
- (*ppr)->bal = -1;
- break;
- case -1:
- /* left branch was already too long. rebal */
- MSG("LESS: case -1: rebalancing")
- p1 = (*ppr)->left;
- if (p1->bal == -1) { /* LL */
- MSG("LESS: single LL")
- (*ppr)->left = p1->right;
- p1->right = *ppr;
- (*ppr)->bal = 0;
- *ppr = p1;
- } else { /* double LR */
- MSG("LESS: double LR")
-
- p2 = p1->right;
- p1->right = p2->left;
- p2->left = p1;
-
- (*ppr)->left = p2->right;
- p2->right = *ppr;
-
- if (p2->bal == -1)
- (*ppr)->bal = 1;
- else
- (*ppr)->bal = 0;
-
- if (p2->bal == 1)
- p1->bal = -1;
- else
- p1->bal = 0;
- *ppr = p2;
- } /*else*/
- (*ppr)->bal = 0;
- *pi_balance = FALSE;
- } /*switch*/
- } /*if*/
- RET(sub)
- } /*if*/
-
- /* if MORE, prepare to move to the right.
- */
- if (cmp > 0) {
- MSG("MORE: sprouting to the right")
- sub = sprout(&(*ppr)->right, p_data, pi_balance,
- pfi_compare, pfv_delete);
- if (sub && *pi_balance) {
- MSG("MORE: right branch has grown")
-
- switch ((*ppr)->bal) {
- case -1:
- MSG("MORE: balance was off, fixed implicitly")
- (*ppr)->bal = 0;
- *pi_balance = FALSE;
- break;
- case 0:
- MSG("MORE: balance was okay, now off but ok")
- (*ppr)->bal = 1;
- break;
- case 1:
- MSG("MORE: balance was off, need to rebalance")
- p1 = (*ppr)->right;
- if (p1->bal == 1) { /* RR */
- MSG("MORE: single RR")
- (*ppr)->right = p1->left;
- p1->left = *ppr;
- (*ppr)->bal = 0;
- *ppr = p1;
- } else { /* double RL */
- MSG("MORE: double RL")
-
- p2 = p1->left;
- p1->left = p2->right;
- p2->right = p1;
-
- (*ppr)->right = p2->left;
- p2->left = *ppr;
-
- if (p2->bal == 1)
- (*ppr)->bal = -1;
- else
- (*ppr)->bal = 0;
-
- if (p2->bal == -1)
- p1->bal = 1;
- else
- p1->bal = 0;
-
- *ppr = p2;
- } /*else*/
- (*ppr)->bal = 0;
- *pi_balance = FALSE;
- } /*switch*/
- } /*if*/
- RET(sub)
- } /*if*/
-
- /* not less, not more: this is the same key! replace...
- */
- MSG("FOUND: Replacing data value")
- *pi_balance = FALSE;
- if (pfv_delete)
- (*pfv_delete)((*ppr)->data);
- (*ppr)->data = p_data;
- RET(*ppr)
-}
-
-static int
-delete(tree **ppr_p, int (*pfi_compare)(tree_t, tree_t), tree_t p_user,
- void (*pfv_uar)(tree_t), int *pi_balance, int *pi_uar_called)
-{
- tree *pr_q;
- int i_comp, i_ret;
-
- ENTER("delete")
-
- if (*ppr_p == NULL) {
- MSG("key not in tree")
- RET(FALSE)
- }
-
- i_comp = (*pfi_compare)((*ppr_p)->data, p_user);
- if (i_comp > 0) {
- MSG("too high - scan left")
- i_ret = delete(&(*ppr_p)->left, pfi_compare, p_user, pfv_uar,
- pi_balance, pi_uar_called);
- if (*pi_balance)
- bal_L(ppr_p, pi_balance);
- } else if (i_comp < 0) {
- MSG("too low - scan right")
- i_ret = delete(&(*ppr_p)->right, pfi_compare, p_user, pfv_uar,
- pi_balance, pi_uar_called);
- if (*pi_balance)
- bal_R(ppr_p, pi_balance);
- } else {
- MSG("equal")
- pr_q = *ppr_p;
- if (pr_q->right == NULL) {
- MSG("right subtree null")
- *ppr_p = pr_q->left;
- *pi_balance = TRUE;
- } else if (pr_q->left == NULL) {
- MSG("right subtree non-null, left subtree null")
- *ppr_p = pr_q->right;
- *pi_balance = TRUE;
- } else {
- MSG("neither subtree null")
- del(&pr_q->left, pi_balance, &pr_q,
- pfv_uar, pi_uar_called);
- if (*pi_balance)
- bal_L(ppr_p, pi_balance);
- }
- if (!*pi_uar_called && pfv_uar)
- (*pfv_uar)(pr_q->data);
- /* Thanks to wuth@castrov.cuc.ab.ca for the following stmt. */
- memput(pr_q, sizeof(tree));
- i_ret = TRUE;
- }
- RET(i_ret)
-}
-
-static void
-del(tree **ppr_r, int *pi_balance, tree **ppr_q,
- void (*pfv_uar)(tree_t), int *pi_uar_called)
-{
- ENTER("del")
-
- if ((*ppr_r)->right != NULL) {
- del(&(*ppr_r)->right, pi_balance, ppr_q,
- pfv_uar, pi_uar_called);
- if (*pi_balance)
- bal_R(ppr_r, pi_balance);
- } else {
- if (pfv_uar)
- (*pfv_uar)((*ppr_q)->data);
- *pi_uar_called = TRUE;
- (*ppr_q)->data = (*ppr_r)->data;
- *ppr_q = *ppr_r;
- *ppr_r = (*ppr_r)->left;
- *pi_balance = TRUE;
- }
-
- RETV
-}
-
-static void
-bal_L(tree **ppr_p, int *pi_balance) {
- tree *p1, *p2;
- int b1, b2;
-
- ENTER("bal_L")
- MSG("left branch has shrunk")
-
- switch ((*ppr_p)->bal) {
- case -1:
- MSG("was imbalanced, fixed implicitly")
- (*ppr_p)->bal = 0;
- break;
- case 0:
- MSG("was okay, is now one off")
- (*ppr_p)->bal = 1;
- *pi_balance = FALSE;
- break;
- case 1:
- MSG("was already off, this is too much")
- p1 = (*ppr_p)->right;
- b1 = p1->bal;
- if (b1 >= 0) {
- MSG("single RR")
- (*ppr_p)->right = p1->left;
- p1->left = *ppr_p;
- if (b1 == 0) {
- MSG("b1 == 0")
- (*ppr_p)->bal = 1;
- p1->bal = -1;
- *pi_balance = FALSE;
- } else {
- MSG("b1 != 0")
- (*ppr_p)->bal = 0;
- p1->bal = 0;
- }
- *ppr_p = p1;
- } else {
- MSG("double RL")
- p2 = p1->left;
- b2 = p2->bal;
- p1->left = p2->right;
- p2->right = p1;
- (*ppr_p)->right = p2->left;
- p2->left = *ppr_p;
- if (b2 == 1)
- (*ppr_p)->bal = -1;
- else
- (*ppr_p)->bal = 0;
- if (b2 == -1)
- p1->bal = 1;
- else
- p1->bal = 0;
- *ppr_p = p2;
- p2->bal = 0;
- }
- }
- RETV
-}
-
-static void
-bal_R(tree **ppr_p, int *pi_balance) {
- tree *p1, *p2;
- int b1, b2;
-
- ENTER("bal_R")
- MSG("right branch has shrunk")
- switch ((*ppr_p)->bal) {
- case 1:
- MSG("was imbalanced, fixed implicitly")
- (*ppr_p)->bal = 0;
- break;
- case 0:
- MSG("was okay, is now one off")
- (*ppr_p)->bal = -1;
- *pi_balance = FALSE;
- break;
- case -1:
- MSG("was already off, this is too much")
- p1 = (*ppr_p)->left;
- b1 = p1->bal;
- if (b1 <= 0) {
- MSG("single LL")
- (*ppr_p)->left = p1->right;
- p1->right = *ppr_p;
- if (b1 == 0) {
- MSG("b1 == 0")
- (*ppr_p)->bal = -1;
- p1->bal = 1;
- *pi_balance = FALSE;
- } else {
- MSG("b1 != 0")
- (*ppr_p)->bal = 0;
- p1->bal = 0;
- }
- *ppr_p = p1;
- } else {
- MSG("double LR")
- p2 = p1->right;
- b2 = p2->bal;
- p1->right = p2->left;
- p2->left = p1;
- (*ppr_p)->left = p2->right;
- p2->right = *ppr_p;
- if (b2 == -1)
- (*ppr_p)->bal = 1;
- else
- (*ppr_p)->bal = 0;
- if (b2 == 1)
- p1->bal = -1;
- else
- p1->bal = 0;
- *ppr_p = p2;
- p2->bal = 0;
- }
- }
- RETV
-}
diff --git a/contrib/bind/lib/isc/tree.mdoc b/contrib/bind/lib/isc/tree.mdoc
deleted file mode 100644
index 43d1b7e..0000000
--- a/contrib/bind/lib/isc/tree.mdoc
+++ /dev/null
@@ -1,154 +0,0 @@
-.\" $Id: tree.mdoc,v 8.3 2001/08/08 07:50:28 marka Exp $
-.\"
-.\"Copyright (c) 1995-1999 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.
-.\"
-.Dd April 5, 1994
-.Dt TREE 3
-.Os BSD 4
-.Sh NAME
-.Nm tree_init ,
-.Nm tree_mung ,
-.Nm tree_srch ,
-.Nm tree_add ,
-.Nm tree_delete ,
-.Nm tree_trav
-.Nd balanced binary tree routines
-.Sh SYNOPSIS
-.Ft void
-.Fn tree_init "void **tree"
-.Ft void *
-.Fn tree_srch "void **tree" "int (*compare)()" "void *data"
-.Ft void
-.Fn tree_add "void **tree" "int (*compare)()" \
-"void *data" "void (*del_uar)()"
-.Ft int
-.Fn tree_delete "void **tree" "int (*compare)()" \
-"void *data" "void (*del_uar)()"
-.Ft int
-.Fn tree_trav "void **tree" "int (*trav_uar)()"
-.Ft void
-.Fn tree_mung "void **tree" "void (*del_uar)()"
-.Sh DESCRIPTION
-These functions create and manipulate a balanced binary (AVL) tree. Each node
-of the tree contains the expected left & right subtree pointers, a short int
-balance indicator, and a pointer to the user data. On a 32 bit system, this
-means an overhead of 4+4+2+4 bytes per node (or, on a RISC or otherwise
-alignment constrained system with implied padding, 4+4+4+4 bytes per node).
-There is no key data type enforced by this package; a caller supplied
-compare routine is used to compare user data blocks.
-.Pp
-Balanced binary trees are very fast on searches and replacements, but have a
-moderately high cost for additions and deletions. If your application does a
-lot more searches and replacements than it does additions and deletions, the
-balanced (AVL) binary tree is a good choice for a data structure.
-.Pp
-.Fn Tree_init
-creates an empty tree and binds it to
-.Dq Fa tree
-(which for this and all other routines in this package should be declared as
-a pointer to void or int, and passed by reference), which can then be used by
-other routines in this package. Note that more than one
-.Dq Fa tree
-variable can exist at once; thus multiple trees can be manipulated
-simultaneously.
-.Pp
-.Fn Tree_srch
-searches a tree for a specific node and returns either
-.Fa NULL
-if no node was found, or the value of the user data pointer if the node
-was found.
-.Fn compare
-is the address of a function to compare two user data blocks. This routine
-should work much the way
-.Xr strcmp 3
-does; in fact,
-.Xr strcmp
-could be used if the user data was a \s-2NUL\s+2 terminated string.
-.Dq Fa Data
-is the address of a user data block to be used by
-.Fn compare
-as the search criteria. The tree is searched for a node where
-.Fn compare
-returns 0.
-.Pp
-.Fn Tree_add
-inserts or replaces a node in the specified tree. The tree specified by
-.Dq Fa tree
-is searched as in
-.Fn tree_srch ,
-and if a node is found to match
-.Dq Fa data ,
-then the
-.Fn del_uar
-function, if non\-\s-2NULL\s+2, is called with the address of the user data
-block for the node (this routine should deallocate any dynamic memory which
-is referenced exclusively by the node); the user data pointer for the node
-is then replaced by the value of
-.Dq Fa data .
-If no node is found to match, a new node is added (which may or may not
-cause a transparent rebalance operation), with a user data pointer equal to
-.Dq Fa data .
-A rebalance may or may not occur, depending on where the node is added
-and what the rest of the tree looks like.
-.Fn Tree_add
-will return the
-.Dq Fa data
-pointer unless catastrophe occurs in which case it will return \s-2NULL\s+2.
-.Pp
-.Fn Tree_delete
-deletes a node from
-.Dq Fa tree .
-A rebalance may or may not occur, depending on where the node is removed from
-and what the rest of the tree looks like.
-.Fn Tree_delete
-returns TRUE if a node was deleted, FALSE otherwise.
-.Pp
-.Fn Tree_trav
-traverses all of
-.Dq Fa tree ,
-calling
-.Fn trav_uar
-with the address of each user data block. If
-.Fn trav_uar
-returns FALSE at any time,
-.Fn tree_trav
-will immediately return FALSE to its caller. Otherwise all nodes will be
-reached and
-.Fn tree_trav
-will return TRUE.
-.Pp
-.Fn Tree_mung
-deletes every node in
-.Dq Fa tree ,
-calling
-.Fn del_uar
-(if it is not \s-2NULL\s+2) with the user data address from each node (see
-.Fn tree_add
-and
-.Fn tree_delete
-above). The tree is left in the same state that
-.Fn tree_init
-leaves it in \- i.e., empty.
-.Sh BUGS
-Should have a way for the caller to specify application-specific
-.Xr malloc
-and
-.Xr free
-functions to be used internally when allocating meta data.
-.Sh AUTHOR
-Paul Vixie, converted and augumented from Modula\-2 examples in
-.Dq Algorithms & Data Structures ,
-Niklaus Wirth, Prentice\-Hall, ISBN 0\-13\-022005\-1.
diff --git a/contrib/bind/lib/nameser/Makefile b/contrib/bind/lib/nameser/Makefile
deleted file mode 100644
index f283e1c..0000000
--- a/contrib/bind/lib/nameser/Makefile
+++ /dev/null
@@ -1,92 +0,0 @@
-#
-# Copyright (c) 1996,1999 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.
-#
-
-# $Id: Makefile,v 8.22 2001/08/14 05:58:09 marka Exp $
-
-# these are only appropriate for BSD 4.4 or derivatives, and are used in
-# development. normal builds will be done in the top level directory and
-# this Makefile will be invoked with a lot of overrides for the following:
-SYSTYPE= freebsd
-DESTDIR =
-DESTLIB = /usr/local/lib
-O=o
-A=a
-CC= cc
-LD= ld
-SHELL= /bin/sh
-CDEBUG= -g -Wall
-TOP= ../..
-INCL = ${TOP}/include
-PORTINCL = ${TOP}/port/${SYSTYPE}/include
-LIBBIND = ${TOP}/lib/libbind.${A}
-LIBBINDR = ../${TOP}/lib/libbind_r.${A}
-CFLAGS= ${CDEBUG}
-CPPFLAGS= -I${PORTINCL} -I${INCL}
-LD_LIBFLAGS= -x -r
-AR= ar cru
-RANLIB= ranlib
-INSTALL= install
-INSTALL_EXEC=
-INSTALL_LIB=-o bin -g bin
-THREADED= threaded
-
-SRCS= ns_parse.c ns_print.c ns_netint.c ns_ttl.c ns_name.c \
- ns_sign.c ns_verify.c ns_date.c ns_samedomain.c
-
-OBJS= ns_parse.${O} ns_print.${O} ns_netint.${O} ns_ttl.${O} ns_name.${O} \
- ns_sign.${O} ns_verify.${O} ns_date.${O} ns_samedomain.${O}
-
-all: ${LIBBIND}
-
-${LIBBIND}: ${OBJS}
- ( cd ${THREADED} ; \
- ${AR} ${LIBBINDR} ${ARPREF} ${OBJS} ${ARSUFF} ; \
- ${RANLIB} ${LIBBINDR} )
- ${AR} ${LIBBIND} ${ARPREF} ${OBJS} ${ARSUFF}
- ${RANLIB} ${LIBBIND}
-
-.c.${O}:
- mkdir ${THREADED} 2> /dev/null || test -d ${THREADED} -a -w ${THREADED}
- ${CC} ${CPPFLAGS} ${CFLAGS} ${BOUNDS} ${REENTRANT} -c $*.c \
- -o ${THREADED}/$*.${O}
- -${LDS} ${LD} ${LD_LIBFLAGS} ${THREADED}/$*.${O} \
- -o ${THREADED}/$*.out && \
- ${LDS} mv ${THREADED}/$*.out ${THREADED}/$*.${O}
- ${CC} ${CPPFLAGS} ${CFLAGS} ${BOUNDS} -c $*.c
- -${LDS} ${LD} ${LD_LIBFLAGS} $*.${O} -o $*.out && \
- ${LDS} mv $*.out $*.${O}
-
-distclean: clean
-
-clean: FRC
- rm -f .depend a.out core ${LIB} tags
- rm -f *.${O} *.BAK *.CKP *~
- rm -f ${THREADED}/*.${O}
- -if test -d ${THREADED} ; then rmdir ${THREADED}; else true; fi
-
-depend: FRC
- mkdep -I${INCL} -I${PORTINCL} ${CPPFLAGS} ${SRCS}
-
-links: FRC
- @set -e; ln -s SRC/*.[ch] .
-
-install:
-
-FRC:
-
-# DO NOT DELETE THIS LINE -- mkdep uses it.
-# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
diff --git a/contrib/bind/lib/nameser/ns_date.c b/contrib/bind/lib/nameser/ns_date.c
deleted file mode 100644
index d4ec49e..0000000
--- a/contrib/bind/lib/nameser/ns_date.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright (c) 1999 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.
- */
-
-#ifndef lint
-static const char rcsid[] = "$Id: ns_date.c,v 1.3 2001/05/29 05:49:34 marka Exp $";
-#endif
-
-/* Import. */
-
-#include "port_before.h"
-
-#include <arpa/nameser.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-
-#include "port_after.h"
-
-#ifdef SPRINTF_CHAR
-# define SPRINTF(x) strlen(sprintf/**/x)
-#else
-# define SPRINTF(x) ((size_t)sprintf x)
-#endif
-
-/* Forward. */
-
-static int datepart(const char *, int, int, int, int *);
-
-/* Public. */
-
-/* Convert a date in ASCII into the number of seconds since
- 1 January 1970 (GMT assumed). Format is yyyymmddhhmmss, all
- digits required, no spaces allowed. */
-
-u_int32_t
-ns_datetosecs(const char *cp, int *errp) {
- struct tm time;
- u_int32_t result;
- int mdays, i;
- static const int days_per_month[12] =
- {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
-
- if (strlen(cp) != 14) {
- *errp = 1;
- return (0);
- }
- *errp = 0;
-
- memset(&time, 0, sizeof time);
- time.tm_year = datepart(cp + 0, 4, 1990, 9999, errp) - 1900;
- time.tm_mon = datepart(cp + 4, 2, 01, 12, errp) - 1;
- time.tm_mday = datepart(cp + 6, 2, 01, 31, errp);
- time.tm_hour = datepart(cp + 8, 2, 00, 23, errp);
- time.tm_min = datepart(cp + 10, 2, 00, 59, errp);
- time.tm_sec = datepart(cp + 12, 2, 00, 59, errp);
- if (*errp) /* Any parse errors? */
- return (0);
-
- /*
- * OK, now because timegm() is not available in all environments,
- * we will do it by hand. Roll up sleeves, curse the gods, begin!
- */
-
-#define SECS_PER_DAY ((u_int32_t)24*60*60)
-#define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
-
- result = time.tm_sec; /* Seconds */
- result += time.tm_min * 60; /* Minutes */
- result += time.tm_hour * (60*60); /* Hours */
- result += (time.tm_mday - 1) * SECS_PER_DAY; /* Days */
-
- /* Months are trickier. Look without leaping, then leap */
- mdays = 0;
- for (i = 0; i < time.tm_mon; i++)
- mdays += days_per_month[i];
- result += mdays * SECS_PER_DAY; /* Months */
- if (time.tm_mon > 1 && isleap(1900+time.tm_year))
- result += SECS_PER_DAY; /* Add leapday for this year */
-
- /* First figure years without leapdays, then add them in. */
- /* The loop is slow, FIXME, but simple and accurate. */
- result += (time.tm_year - 70) * (SECS_PER_DAY*365); /* Years */
- for (i = 70; i < time.tm_year; i++)
- if (isleap(1900+i))
- result += SECS_PER_DAY; /* Add leapday for prev year */
-
- return (result);
-}
-
-/* Private. */
-
-/*
- * Parse part of a date. Set error flag if any error.
- * Don't reset the flag if there is no error.
- */
-static int
-datepart(const char *buf, int size, int min, int max, int *errp) {
- int result = 0;
- int i;
-
- for (i = 0; i < size; i++) {
- if (!isdigit((unsigned char)(buf[i])))
- *errp = 1;
- result = (result * 10) + buf[i] - '0';
- }
- if (result < min)
- *errp = 1;
- if (result > max)
- *errp = 1;
- return (result);
-}
diff --git a/contrib/bind/lib/nameser/ns_name.c b/contrib/bind/lib/nameser/ns_name.c
deleted file mode 100644
index c57ac3b..0000000
--- a/contrib/bind/lib/nameser/ns_name.c
+++ /dev/null
@@ -1,963 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#ifndef lint
-static const char rcsid[] = "$Id: ns_name.c,v 8.20 2003/04/03 06:00:07 marka Exp $";
-#endif
-
-#include "port_before.h"
-
-#include <sys/types.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-
-#include <errno.h>
-#include <resolv.h>
-#include <string.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <limits.h>
-
-#include "port_after.h"
-
-#ifdef SPRINTF_CHAR
-# define SPRINTF(x) strlen(sprintf/**/x)
-#else
-# define SPRINTF(x) ((size_t)sprintf x)
-#endif
-
-#define NS_TYPE_ELT 0x40 /* EDNS0 extended label type */
-#define DNS_LABELTYPE_BITSTRING 0x41
-
-/* Data. */
-
-static const char digits[] = "0123456789";
-
-static const char digitvalue[256] = {
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*16*/
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*32*/
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*48*/
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /*64*/
- -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*80*/
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*96*/
- -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*112*/
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*128*/
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*256*/
-};
-
-/* Forward. */
-
-static int special(int);
-static int printable(int);
-static int dn_find(const u_char *, const u_char *,
- const u_char * const *,
- const u_char * const *);
-static int encode_bitsring(const char **, const char *,
- char **, char **, const char *);
-static int labellen(const u_char *);
-static int decode_bitstring(const char **, char *, const char *);
-
-/* Public. */
-
-/*
- * ns_name_ntop(src, dst, dstsiz)
- * Convert an encoded domain name to printable ascii as per RFC1035.
- * return:
- * Number of bytes written to buffer, or -1 (with errno set)
- * notes:
- * The root is returned as "."
- * All other domains are returned in non absolute form
- */
-int
-ns_name_ntop(const u_char *src, char *dst, size_t dstsiz)
-{
- const u_char *cp;
- char *dn, *eom;
- u_char c;
- u_int n;
- int l;
-
- cp = src;
- dn = dst;
- eom = dst + dstsiz;
-
- while ((n = *cp++) != 0) {
- if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) {
- /* Some kind of compression pointer. */
- errno = EMSGSIZE;
- return (-1);
- }
- if (dn != dst) {
- if (dn >= eom) {
- errno = EMSGSIZE;
- return (-1);
- }
- *dn++ = '.';
- }
- if ((l = labellen(cp - 1)) < 0) {
- errno = EMSGSIZE; /* XXX */
- return(-1);
- }
- if (dn + l >= eom) {
- errno = EMSGSIZE;
- return (-1);
- }
- if ((n & NS_CMPRSFLGS) == NS_TYPE_ELT) {
- int m;
-
- if (n != DNS_LABELTYPE_BITSTRING) {
- /* XXX: labellen should reject this case */
- errno = EINVAL;
- return(-1);
- }
- if ((m = decode_bitstring((const char **)&cp, dn, eom)) < 0)
- {
- errno = EMSGSIZE;
- return(-1);
- }
- dn += m;
- continue;
- }
- for ((void)NULL; l > 0; l--) {
- c = *cp++;
- if (special(c)) {
- if (dn + 1 >= eom) {
- errno = EMSGSIZE;
- return (-1);
- }
- *dn++ = '\\';
- *dn++ = (char)c;
- } else if (!printable(c)) {
- if (dn + 3 >= eom) {
- errno = EMSGSIZE;
- return (-1);
- }
- *dn++ = '\\';
- *dn++ = digits[c / 100];
- *dn++ = digits[(c % 100) / 10];
- *dn++ = digits[c % 10];
- } else {
- if (dn >= eom) {
- errno = EMSGSIZE;
- return (-1);
- }
- *dn++ = (char)c;
- }
- }
- }
- if (dn == dst) {
- if (dn >= eom) {
- errno = EMSGSIZE;
- return (-1);
- }
- *dn++ = '.';
- }
- if (dn >= eom) {
- errno = EMSGSIZE;
- return (-1);
- }
- *dn++ = '\0';
- return (dn - dst);
-}
-
-/*
- * ns_name_pton(src, dst, dstsiz)
- * Convert a ascii string into an encoded domain name as per RFC1035.
- * return:
- * -1 if it fails
- * 1 if string was fully qualified
- * 0 is string was not fully qualified
- * notes:
- * Enforces label and domain length limits.
- */
-
-int
-ns_name_pton(const char *src, u_char *dst, size_t dstsiz)
-{
- u_char *label, *bp, *eom;
- int c, n, escaped, e = 0;
- char *cp;
-
- escaped = 0;
- bp = dst;
- eom = dst + dstsiz;
- label = bp++;
-
- while ((c = *src++) != 0) {
- if (escaped) {
- if (c == '[') { /* start a bit string label */
- if ((cp = strchr(src, ']')) == NULL) {
- errno = EINVAL; /* ??? */
- return(-1);
- }
- if ((e = encode_bitsring(&src,
- cp + 2,
- (char **)&label,
- (char **)&bp,
- (const char *)eom))
- != 0) {
- errno = e;
- return(-1);
- }
- escaped = 0;
- label = bp++;
- if ((c = *src++) == 0)
- goto done;
- else if (c != '.') {
- errno = EINVAL;
- return(-1);
- }
- continue;
- }
- else if ((cp = strchr(digits, c)) != NULL) {
- n = (cp - digits) * 100;
- if ((c = *src++) == 0 ||
- (cp = strchr(digits, c)) == NULL) {
- errno = EMSGSIZE;
- return (-1);
- }
- n += (cp - digits) * 10;
- if ((c = *src++) == 0 ||
- (cp = strchr(digits, c)) == NULL) {
- errno = EMSGSIZE;
- return (-1);
- }
- n += (cp - digits);
- if (n > 255) {
- errno = EMSGSIZE;
- return (-1);
- }
- c = n;
- }
- escaped = 0;
- } else if (c == '\\') {
- escaped = 1;
- continue;
- } else if (c == '.') {
- c = (bp - label - 1);
- if ((c & NS_CMPRSFLGS) != 0) { /* Label too big. */
- errno = EMSGSIZE;
- return (-1);
- }
- if (label >= eom) {
- errno = EMSGSIZE;
- return (-1);
- }
- *label = c;
- /* Fully qualified ? */
- if (*src == '\0') {
- if (c != 0) {
- if (bp >= eom) {
- errno = EMSGSIZE;
- return (-1);
- }
- *bp++ = '\0';
- }
- if ((bp - dst) > MAXCDNAME) {
- errno = EMSGSIZE;
- return (-1);
- }
- return (1);
- }
- if (c == 0 || *src == '.') {
- errno = EMSGSIZE;
- return (-1);
- }
- label = bp++;
- continue;
- }
- if (bp >= eom) {
- errno = EMSGSIZE;
- return (-1);
- }
- *bp++ = (u_char)c;
- }
- c = (bp - label - 1);
- if ((c & NS_CMPRSFLGS) != 0) { /* Label too big. */
- errno = EMSGSIZE;
- return (-1);
- }
- done:
- if (label >= eom) {
- errno = EMSGSIZE;
- return (-1);
- }
- *label = c;
- if (c != 0) {
- if (bp >= eom) {
- errno = EMSGSIZE;
- return (-1);
- }
- *bp++ = 0;
- }
- if ((bp - dst) > MAXCDNAME) { /* src too big */
- errno = EMSGSIZE;
- return (-1);
- }
- return (0);
-}
-
-/*
- * ns_name_ntol(src, dst, dstsiz)
- * Convert a network strings labels into all lowercase.
- * return:
- * Number of bytes written to buffer, or -1 (with errno set)
- * notes:
- * Enforces label and domain length limits.
- */
-
-int
-ns_name_ntol(const u_char *src, u_char *dst, size_t dstsiz)
-{
- const u_char *cp;
- u_char *dn, *eom;
- u_char c;
- u_int n;
- int l;
-
- cp = src;
- dn = dst;
- eom = dst + dstsiz;
-
- if (dn >= eom) {
- errno = EMSGSIZE;
- return (-1);
- }
- while ((n = *cp++) != 0) {
- if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) {
- /* Some kind of compression pointer. */
- errno = EMSGSIZE;
- return (-1);
- }
- *dn++ = n;
- if ((l = labellen(cp - 1)) < 0) {
- errno = EMSGSIZE;
- return (-1);
- }
- if (dn + l >= eom) {
- errno = EMSGSIZE;
- return (-1);
- }
- for ((void)NULL; l > 0; l--) {
- c = *cp++;
- if (isupper(c))
- *dn++ = tolower(c);
- else
- *dn++ = c;
- }
- }
- *dn++ = '\0';
- return (dn - dst);
-}
-
-/*
- * ns_name_unpack(msg, eom, src, dst, dstsiz)
- * Unpack a domain name from a message, source may be compressed.
- * return:
- * -1 if it fails, or consumed octets if it succeeds.
- */
-int
-ns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src,
- u_char *dst, size_t dstsiz)
-{
- const u_char *srcp, *dstlim;
- u_char *dstp;
- int n, len, checked, l;
-
- len = -1;
- checked = 0;
- dstp = dst;
- srcp = src;
- dstlim = dst + dstsiz;
- if (srcp < msg || srcp >= eom) {
- errno = EMSGSIZE;
- return (-1);
- }
- /* Fetch next label in domain name. */
- while ((n = *srcp++) != 0) {
- /* Check for indirection. */
- switch (n & NS_CMPRSFLGS) {
- case 0:
- case NS_TYPE_ELT:
- /* Limit checks. */
- if ((l = labellen(srcp - 1)) < 0) {
- errno = EMSGSIZE;
- return(-1);
- }
- if (dstp + l + 1 >= dstlim || srcp + l >= eom) {
- errno = EMSGSIZE;
- return (-1);
- }
- checked += l + 1;
- *dstp++ = n;
- memcpy(dstp, srcp, l);
- dstp += l;
- srcp += l;
- break;
-
- case NS_CMPRSFLGS:
- if (srcp >= eom) {
- errno = EMSGSIZE;
- return (-1);
- }
- if (len < 0)
- len = srcp - src + 1;
- srcp = msg + (((n & 0x3f) << 8) | (*srcp & 0xff));
- if (srcp < msg || srcp >= eom) { /* Out of range. */
- errno = EMSGSIZE;
- return (-1);
- }
- checked += 2;
- /*
- * Check for loops in the compressed name;
- * if we've looked at the whole message,
- * there must be a loop.
- */
- if (checked >= eom - msg) {
- errno = EMSGSIZE;
- return (-1);
- }
- break;
-
- default:
- errno = EMSGSIZE;
- return (-1); /* flag error */
- }
- }
- *dstp = '\0';
- if (len < 0)
- len = srcp - src;
- return (len);
-}
-
-/*
- * ns_name_pack(src, dst, dstsiz, dnptrs, lastdnptr)
- * Pack domain name 'domain' into 'comp_dn'.
- * return:
- * Size of the compressed name, or -1.
- * notes:
- * 'dnptrs' is an array of pointers to previous compressed names.
- * dnptrs[0] is a pointer to the beginning of the message. The array
- * ends with NULL.
- * 'lastdnptr' is a pointer to the end of the array pointed to
- * by 'dnptrs'.
- * Side effects:
- * The list of pointers in dnptrs is updated for labels inserted into
- * the message as we compress the name. If 'dnptr' is NULL, we don't
- * try to compress names. If 'lastdnptr' is NULL, we don't update the
- * list.
- */
-int
-ns_name_pack(const u_char *src, u_char *dst, int dstsiz,
- const u_char **dnptrs, const u_char **lastdnptr)
-{
- u_char *dstp;
- const u_char **cpp, **lpp, *eob, *msg;
- const u_char *srcp;
- int n, l, first = 1;
-
- srcp = src;
- dstp = dst;
- eob = dstp + dstsiz;
- lpp = cpp = NULL;
- if (dnptrs != NULL) {
- if ((msg = *dnptrs++) != NULL) {
- for (cpp = dnptrs; *cpp != NULL; cpp++)
- (void)NULL;
- lpp = cpp; /* end of list to search */
- }
- } else
- msg = NULL;
-
- /* make sure the domain we are about to add is legal */
- l = 0;
- do {
- int l0;
-
- n = *srcp;
- if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) {
- errno = EMSGSIZE;
- return (-1);
- }
- if ((l0 = labellen(srcp)) < 0) {
- errno = EINVAL;
- return(-1);
- }
- l += l0 + 1;
- if (l > MAXCDNAME) {
- errno = EMSGSIZE;
- return (-1);
- }
- srcp += l0 + 1;
- } while (n != 0);
-
- /* from here on we need to reset compression pointer array on error */
- srcp = src;
- do {
- /* Look to see if we can use pointers. */
- n = *srcp;
- if (n != 0 && msg != NULL) {
- l = dn_find(srcp, msg, (const u_char * const *)dnptrs,
- (const u_char * const *)lpp);
- if (l >= 0) {
- if (dstp + 1 >= eob) {
- goto cleanup;
- }
- *dstp++ = (l >> 8) | NS_CMPRSFLGS;
- *dstp++ = l % 256;
- return (dstp - dst);
- }
- /* Not found, save it. */
- if (lastdnptr != NULL && cpp < lastdnptr - 1 &&
- (dstp - msg) < 0x4000 && first) {
- *cpp++ = dstp;
- *cpp = NULL;
- first = 0;
- }
- }
- /* copy label to buffer */
- if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) {
- /* Should not happen. */
- goto cleanup;
- }
- n = labellen(srcp);
- if (dstp + 1 + n >= eob) {
- goto cleanup;
- }
- memcpy(dstp, srcp, n + 1);
- srcp += n + 1;
- dstp += n + 1;
- } while (n != 0);
-
- if (dstp > eob) {
-cleanup:
- if (msg != NULL)
- *lpp = NULL;
- errno = EMSGSIZE;
- return (-1);
- }
- return (dstp - dst);
-}
-
-/*
- * ns_name_uncompress(msg, eom, src, dst, dstsiz)
- * Expand compressed domain name to presentation format.
- * return:
- * Number of bytes read out of `src', or -1 (with errno set).
- * note:
- * Root domain returns as "." not "".
- */
-int
-ns_name_uncompress(const u_char *msg, const u_char *eom, const u_char *src,
- char *dst, size_t dstsiz)
-{
- u_char tmp[NS_MAXCDNAME];
- int n;
-
- if ((n = ns_name_unpack(msg, eom, src, tmp, sizeof tmp)) == -1)
- return (-1);
- if (ns_name_ntop(tmp, dst, dstsiz) == -1)
- return (-1);
- return (n);
-}
-
-/*
- * ns_name_compress(src, dst, dstsiz, dnptrs, lastdnptr)
- * Compress a domain name into wire format, using compression pointers.
- * return:
- * Number of bytes consumed in `dst' or -1 (with errno set).
- * notes:
- * 'dnptrs' is an array of pointers to previous compressed names.
- * dnptrs[0] is a pointer to the beginning of the message.
- * The list ends with NULL. 'lastdnptr' is a pointer to the end of the
- * array pointed to by 'dnptrs'. Side effect is to update the list of
- * pointers for labels inserted into the message as we compress the name.
- * If 'dnptr' is NULL, we don't try to compress names. If 'lastdnptr'
- * is NULL, we don't update the list.
- */
-int
-ns_name_compress(const char *src, u_char *dst, size_t dstsiz,
- const u_char **dnptrs, const u_char **lastdnptr)
-{
- u_char tmp[NS_MAXCDNAME];
-
- if (ns_name_pton(src, tmp, sizeof tmp) == -1)
- return (-1);
- return (ns_name_pack(tmp, dst, dstsiz, dnptrs, lastdnptr));
-}
-
-/*
- * Reset dnptrs so that there are no active references to pointers at or
- * after src.
- */
-void
-ns_name_rollback(const u_char *src, const u_char **dnptrs,
- const u_char **lastdnptr)
-{
- while (dnptrs < lastdnptr && *dnptrs != NULL) {
- if (*dnptrs >= src) {
- *dnptrs = NULL;
- break;
- }
- dnptrs++;
- }
-}
-
-/*
- * ns_name_skip(ptrptr, eom)
- * Advance *ptrptr to skip over the compressed name it points at.
- * return:
- * 0 on success, -1 (with errno set) on failure.
- */
-int
-ns_name_skip(const u_char **ptrptr, const u_char *eom)
-{
- const u_char *cp;
- u_int n;
- int l;
-
- cp = *ptrptr;
- while (cp < eom && (n = *cp++) != 0) {
- /* Check for indirection. */
- switch (n & NS_CMPRSFLGS) {
- case 0: /* normal case, n == len */
- cp += n;
- continue;
- case NS_TYPE_ELT: /* EDNS0 extended label */
- if ((l = labellen(cp - 1)) < 0) {
- errno = EMSGSIZE; /* XXX */
- return(-1);
- }
- cp += l;
- continue;
- case NS_CMPRSFLGS: /* indirection */
- cp++;
- break;
- default: /* illegal type */
- errno = EMSGSIZE;
- return (-1);
- }
- break;
- }
- if (cp > eom) {
- errno = EMSGSIZE;
- return (-1);
- }
- *ptrptr = cp;
- return (0);
-}
-
-/* Private. */
-
-/*
- * special(ch)
- * Thinking in noninternationalized USASCII (per the DNS spec),
- * is this characted special ("in need of quoting") ?
- * return:
- * boolean.
- */
-static int
-special(int ch) {
- switch (ch) {
- case 0x22: /* '"' */
- case 0x2E: /* '.' */
- case 0x3B: /* ';' */
- case 0x5C: /* '\\' */
- case 0x28: /* '(' */
- case 0x29: /* ')' */
- /* Special modifiers in zone files. */
- case 0x40: /* '@' */
- case 0x24: /* '$' */
- return (1);
- default:
- return (0);
- }
-}
-
-/*
- * printable(ch)
- * Thinking in noninternationalized USASCII (per the DNS spec),
- * is this character visible and not a space when printed ?
- * return:
- * boolean.
- */
-static int
-printable(int ch) {
- return (ch > 0x20 && ch < 0x7f);
-}
-
-/*
- * Thinking in noninternationalized USASCII (per the DNS spec),
- * convert this character to lower case if it's upper case.
- */
-static int
-mklower(int ch) {
- if (ch >= 0x41 && ch <= 0x5A)
- return (ch + 0x20);
- return (ch);
-}
-
-/*
- * dn_find(domain, msg, dnptrs, lastdnptr)
- * Search for the counted-label name in an array of compressed names.
- * return:
- * offset from msg if found, or -1.
- * notes:
- * dnptrs is the pointer to the first name on the list,
- * not the pointer to the start of the message.
- */
-static int
-dn_find(const u_char *domain, const u_char *msg,
- const u_char * const *dnptrs,
- const u_char * const *lastdnptr)
-{
- const u_char *dn, *cp, *sp;
- const u_char * const *cpp;
- u_int n;
-
- for (cpp = dnptrs; cpp < lastdnptr; cpp++) {
- sp = *cpp;
- /*
- * terminate search on:
- * root label
- * compression pointer
- * unusable offset
- */
- while (*sp != 0 && (*sp & NS_CMPRSFLGS) == 0 &&
- (sp - msg) < 0x4000) {
- dn = domain;
- cp = sp;
- while ((n = *cp++) != 0) {
- /*
- * check for indirection
- */
- switch (n & NS_CMPRSFLGS) {
- case 0: /* normal case, n == len */
- n = labellen(cp - 1); /* XXX */
-
- if (n != *dn++)
- goto next;
-
- for ((void)NULL; n > 0; n--)
- if (mklower(*dn++) !=
- mklower(*cp++))
- goto next;
- /* Is next root for both ? */
- if (*dn == '\0' && *cp == '\0')
- return (sp - msg);
- if (*dn)
- continue;
- goto next;
- case NS_CMPRSFLGS: /* indirection */
- cp = msg + (((n & 0x3f) << 8) | *cp);
- break;
-
- default: /* illegal type */
- errno = EMSGSIZE;
- return (-1);
- }
- }
- next: ;
- sp += *sp + 1;
- }
- }
- errno = ENOENT;
- return (-1);
-}
-
-static int
-decode_bitstring(const char **cpp, char *dn, const char *eom)
-{
- const char *cp = *cpp;
- char *beg = dn, tc;
- int b, blen, plen, i;
-
- if ((blen = (*cp & 0xff)) == 0)
- blen = 256;
- plen = (blen + 3) / 4;
- plen += sizeof("\\[x/]") + (blen > 99 ? 3 : (blen > 9) ? 2 : 1);
- if (dn + plen >= eom)
- return(-1);
-
- cp++;
- i = SPRINTF((dn, "\\[x"));
- if (i < 0)
- return (-1);
- dn += i;
- for (b = blen; b > 7; b -= 8, cp++) {
- i = SPRINTF((dn, "%02x", *cp & 0xff));
- if (i < 0)
- return (-1);
- dn += i;
- }
- if (b > 4) {
- tc = *cp++;
- i = SPRINTF((dn, "%02x", tc & (0xff << (8 - b))));
- if (i < 0)
- return (-1);
- dn += i;
- } else if (b > 0) {
- tc = *cp++;
- i = SPRINTF((dn, "%1x",
- ((tc >> 4) & 0x0f) & (0x0f << (4 - b))));
- if (i < 0)
- return (-1);
- dn += i;
- }
- i = SPRINTF((dn, "/%d]", blen));
- if (i < 0)
- return (-1);
- dn += i;
-
- *cpp = cp;
- return(dn - beg);
-}
-
-static int
-encode_bitsring(const char **bp, const char *end, char **labelp,
- char ** dst, const char *eom)
-{
- int afterslash = 0;
- const char *cp = *bp;
- char *tp, c;
- const char *beg_blen;
- char *end_blen = NULL;
- int value = 0, count = 0, tbcount = 0, blen = 0;
-
- beg_blen = end_blen = NULL;
-
- /* a bitstring must contain at least 2 characters */
- if (end - cp < 2)
- return(EINVAL);
-
- /* XXX: currently, only hex strings are supported */
- if (*cp++ != 'x')
- return(EINVAL);
- if (!isxdigit((*cp) & 0xff)) /* reject '\[x/BLEN]' */
- return(EINVAL);
-
- for (tp = *dst + 1; cp < end && tp < eom; cp++) {
- switch((c = *cp)) {
- case ']': /* end of the bitstring */
- if (afterslash) {
- if (beg_blen == NULL)
- return(EINVAL);
- blen = (int)strtol(beg_blen, &end_blen, 10);
- if (*end_blen != ']')
- return(EINVAL);
- }
- if (count)
- *tp++ = ((value << 4) & 0xff);
- cp++; /* skip ']' */
- goto done;
- case '/':
- afterslash = 1;
- break;
- default:
- if (afterslash) {
- if (!isdigit(c&0xff))
- return(EINVAL);
- if (beg_blen == NULL) {
-
- if (c == '0') {
- /* blen never begings with 0 */
- return(EINVAL);
- }
- beg_blen = cp;
- }
- } else {
- if (!isxdigit(c&0xff))
- return(EINVAL);
- value <<= 4;
- value += digitvalue[(int)c];
- count += 4;
- tbcount += 4;
- if (tbcount > 256)
- return(EINVAL);
- if (count == 8) {
- *tp++ = value;
- count = 0;
- }
- }
- break;
- }
- }
- done:
- if (cp >= end || tp >= eom)
- return(EMSGSIZE);
-
- /*
- * bit length validation:
- * If a <length> is present, the number of digits in the <bit-data>
- * MUST be just sufficient to contain the number of bits specified
- * by the <length>. If there are insignificant bits in a final
- * hexadecimal or octal digit, they MUST be zero.
- * RFC 2673, Section 3.2.
- */
- if (blen > 0) {
- int traillen;
-
- if (((blen + 3) & ~3) != tbcount)
- return(EINVAL);
- traillen = tbcount - blen; /* between 0 and 3 */
- if (((value << (8 - traillen)) & 0xff) != 0)
- return(EINVAL);
- }
- else
- blen = tbcount;
- if (blen == 256)
- blen = 0;
-
- /* encode the type and the significant bit fields */
- **labelp = DNS_LABELTYPE_BITSTRING;
- **dst = blen;
-
- *bp = cp;
- *dst = tp;
-
- return(0);
-}
-
-static int
-labellen(const u_char *lp)
-{
- int bitlen;
- u_char l = *lp;
-
- if ((l & NS_CMPRSFLGS) == NS_CMPRSFLGS) {
- /* should be avoided by the caller */
- return(-1);
- }
-
- if ((l & NS_CMPRSFLGS) == NS_TYPE_ELT) {
- if (l == DNS_LABELTYPE_BITSTRING) {
- if ((bitlen = *(lp + 1)) == 0)
- bitlen = 256;
- return((bitlen + 7 ) / 8 + 1);
- }
- return(-1); /* unknwon ELT */
- }
- return(l);
-}
diff --git a/contrib/bind/lib/nameser/ns_netint.c b/contrib/bind/lib/nameser/ns_netint.c
deleted file mode 100644
index 030a2d0..0000000
--- a/contrib/bind/lib/nameser/ns_netint.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#ifndef lint
-static const char rcsid[] = "$Id: ns_netint.c,v 8.4 1999/10/13 16:39:35 vixie Exp $";
-#endif
-
-/* Import. */
-
-#include "port_before.h"
-
-#include <arpa/nameser.h>
-
-#include "port_after.h"
-
-/* Public. */
-
-u_int
-ns_get16(const u_char *src) {
- u_int dst;
-
- NS_GET16(dst, src);
- return (dst);
-}
-
-u_long
-ns_get32(const u_char *src) {
- u_long dst;
-
- NS_GET32(dst, src);
- return (dst);
-}
-
-void
-ns_put16(u_int src, u_char *dst) {
- NS_PUT16(src, dst);
-}
-
-void
-ns_put32(u_long src, u_char *dst) {
- NS_PUT32(src, dst);
-}
diff --git a/contrib/bind/lib/nameser/ns_parse.c b/contrib/bind/lib/nameser/ns_parse.c
deleted file mode 100644
index abd48f2..0000000
--- a/contrib/bind/lib/nameser/ns_parse.c
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#ifndef lint
-static const char rcsid[] = "$Id: ns_parse.c,v 8.18 2003/04/03 06:10:10 marka Exp $";
-#endif
-
-/* Import. */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-
-#include <errno.h>
-#include <resolv.h>
-#include <string.h>
-
-#include "port_after.h"
-
-/* Forward. */
-
-static void setsection(ns_msg *msg, ns_sect sect);
-
-/* Macros. */
-
-#define RETERR(err) do { errno = (err); return (-1); } while (0)
-
-/* Public. */
-
-/* These need to be in the same order as the nres.h:ns_flag enum. */
-struct _ns_flagdata _ns_flagdata[16] = {
- { 0x8000, 15 }, /* qr. */
- { 0x7800, 11 }, /* opcode. */
- { 0x0400, 10 }, /* aa. */
- { 0x0200, 9 }, /* tc. */
- { 0x0100, 8 }, /* rd. */
- { 0x0080, 7 }, /* ra. */
- { 0x0040, 6 }, /* z. */
- { 0x0020, 5 }, /* ad. */
- { 0x0010, 4 }, /* cd. */
- { 0x000f, 0 }, /* rcode. */
- { 0x0000, 0 }, /* expansion (1/6). */
- { 0x0000, 0 }, /* expansion (2/6). */
- { 0x0000, 0 }, /* expansion (3/6). */
- { 0x0000, 0 }, /* expansion (4/6). */
- { 0x0000, 0 }, /* expansion (5/6). */
- { 0x0000, 0 }, /* expansion (6/6). */
-};
-
-int ns_msg_getflag(ns_msg handle, int flag) {
- return(((handle)._flags & _ns_flagdata[flag].mask) >> _ns_flagdata[flag].shift);
-}
-
-int
-ns_skiprr(const u_char *ptr, const u_char *eom, ns_sect section, int count) {
- const u_char *optr = ptr;
-
- for ((void)NULL; count > 0; count--) {
- int b, rdlength;
-
- b = dn_skipname(ptr, eom);
- if (b < 0)
- RETERR(EMSGSIZE);
- ptr += b/*Name*/ + NS_INT16SZ/*Type*/ + NS_INT16SZ/*Class*/;
- if (section != ns_s_qd) {
- if (ptr + NS_INT32SZ + NS_INT16SZ > eom)
- RETERR(EMSGSIZE);
- ptr += NS_INT32SZ/*TTL*/;
- NS_GET16(rdlength, ptr);
- ptr += rdlength/*RData*/;
- }
- }
- if (ptr > eom)
- RETERR(EMSGSIZE);
- return (ptr - optr);
-}
-
-int
-ns_initparse(const u_char *msg, int msglen, ns_msg *handle) {
- const u_char *eom = msg + msglen;
- int i;
-
- memset(handle, 0x5e, sizeof *handle);
- handle->_msg = msg;
- handle->_eom = eom;
- if (msg + NS_INT16SZ > eom)
- RETERR(EMSGSIZE);
- NS_GET16(handle->_id, msg);
- if (msg + NS_INT16SZ > eom)
- RETERR(EMSGSIZE);
- NS_GET16(handle->_flags, msg);
- for (i = 0; i < ns_s_max; i++) {
- if (msg + NS_INT16SZ > eom)
- RETERR(EMSGSIZE);
- NS_GET16(handle->_counts[i], msg);
- }
- for (i = 0; i < ns_s_max; i++)
- if (handle->_counts[i] == 0)
- handle->_sections[i] = NULL;
- else {
- int b = ns_skiprr(msg, eom, (ns_sect)i,
- handle->_counts[i]);
-
- if (b < 0)
- return (-1);
- handle->_sections[i] = msg;
- msg += b;
- }
- if (msg != eom)
- RETERR(EMSGSIZE);
- setsection(handle, ns_s_max);
- return (0);
-}
-
-int
-ns_parserr(ns_msg *handle, ns_sect section, int rrnum, ns_rr *rr) {
- int b;
- int tmp;
-
- /* Make section right. */
- if ((tmp = section) < 0 || section >= ns_s_max)
- RETERR(ENODEV);
- if (section != handle->_sect)
- setsection(handle, section);
-
- /* Make rrnum right. */
- if (rrnum == -1)
- rrnum = handle->_rrnum;
- if (rrnum < 0 || rrnum >= handle->_counts[(int)section])
- RETERR(ENODEV);
- if (rrnum < handle->_rrnum)
- setsection(handle, section);
- if (rrnum > handle->_rrnum) {
- b = ns_skiprr(handle->_msg_ptr, handle->_eom, section,
- rrnum - handle->_rrnum);
-
- if (b < 0)
- return (-1);
- handle->_msg_ptr += b;
- handle->_rrnum = rrnum;
- }
-
- /* Do the parse. */
- b = dn_expand(handle->_msg, handle->_eom,
- handle->_msg_ptr, rr->name, NS_MAXDNAME);
- if (b < 0)
- return (-1);
- handle->_msg_ptr += b;
- if (handle->_msg_ptr + NS_INT16SZ + NS_INT16SZ > handle->_eom)
- RETERR(EMSGSIZE);
- NS_GET16(rr->type, handle->_msg_ptr);
- NS_GET16(rr->rr_class, handle->_msg_ptr);
- if (section == ns_s_qd) {
- rr->ttl = 0;
- rr->rdlength = 0;
- rr->rdata = NULL;
- } else {
- if (handle->_msg_ptr + NS_INT32SZ + NS_INT16SZ > handle->_eom)
- RETERR(EMSGSIZE);
- NS_GET32(rr->ttl, handle->_msg_ptr);
- NS_GET16(rr->rdlength, handle->_msg_ptr);
- if (handle->_msg_ptr + rr->rdlength > handle->_eom)
- RETERR(EMSGSIZE);
- rr->rdata = handle->_msg_ptr;
- handle->_msg_ptr += rr->rdlength;
- }
- if (++handle->_rrnum > handle->_counts[(int)section])
- setsection(handle, (ns_sect)((int)section + 1));
-
- /* All done. */
- return (0);
-}
-
-/* Private. */
-
-static void
-setsection(ns_msg *msg, ns_sect sect) {
- msg->_sect = sect;
- if (sect == ns_s_max) {
- msg->_rrnum = -1;
- msg->_msg_ptr = NULL;
- } else {
- msg->_rrnum = 0;
- msg->_msg_ptr = msg->_sections[(int)sect];
- }
-}
diff --git a/contrib/bind/lib/nameser/ns_print.c b/contrib/bind/lib/nameser/ns_print.c
deleted file mode 100644
index f8a85e7..0000000
--- a/contrib/bind/lib/nameser/ns_print.c
+++ /dev/null
@@ -1,899 +0,0 @@
-/*
- * Copyright (c) 1996-1999 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.
- */
-
-#ifndef lint
-static const char rcsid[] = "$Id: ns_print.c,v 8.26 2003/02/24 23:56:35 vixie Exp $";
-#endif
-
-/* Import. */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <arpa/inet.h>
-
-#include <isc/assertions.h>
-#include <isc/dst.h>
-#include <errno.h>
-#include <resolv.h>
-#include <string.h>
-#include <ctype.h>
-
-#include "port_after.h"
-
-#ifdef SPRINTF_CHAR
-# define SPRINTF(x) strlen(sprintf/**/x)
-#else
-# define SPRINTF(x) ((size_t)sprintf x)
-#endif
-
-/* Forward. */
-
-static size_t prune_origin(const char *name, const char *origin);
-static int charstr(const u_char *rdata, const u_char *edata,
- char **buf, size_t *buflen);
-static int addname(const u_char *msg, size_t msglen,
- const u_char **p, const char *origin,
- char **buf, size_t *buflen);
-static void addlen(size_t len, char **buf, size_t *buflen);
-static int addstr(const char *src, size_t len,
- char **buf, size_t *buflen);
-static int addtab(size_t len, size_t target, int spaced,
- char **buf, size_t *buflen);
-
-/* Macros. */
-
-#define T(x) \
- do { \
- if ((x) < 0) \
- return (-1); \
- } while (0)
-
-/* Public. */
-
-/*
- * int
- * ns_sprintrr(handle, rr, name_ctx, origin, buf, buflen)
- * Convert an RR to presentation format.
- * return:
- * Number of characters written to buf, or -1 (check errno).
- */
-int
-ns_sprintrr(const ns_msg *handle, const ns_rr *rr,
- const char *name_ctx, const char *origin,
- char *buf, size_t buflen)
-{
- int n;
-
- n = ns_sprintrrf(ns_msg_base(*handle), ns_msg_size(*handle),
- ns_rr_name(*rr), ns_rr_class(*rr), ns_rr_type(*rr),
- ns_rr_ttl(*rr), ns_rr_rdata(*rr), ns_rr_rdlen(*rr),
- name_ctx, origin, buf, buflen);
- return (n);
-}
-
-/*
- * int
- * ns_sprintrrf(msg, msglen, name, class, type, ttl, rdata, rdlen,
- * name_ctx, origin, buf, buflen)
- * Convert the fields of an RR into presentation format.
- * return:
- * Number of characters written to buf, or -1 (check errno).
- */
-int
-ns_sprintrrf(const u_char *msg, size_t msglen,
- const char *name, ns_class class, ns_type type,
- u_long ttl, const u_char *rdata, size_t rdlen,
- const char *name_ctx, const char *origin,
- char *buf, size_t buflen)
-{
- const char *obuf = buf;
- const u_char *edata = rdata + rdlen;
- int spaced = 0;
-
- const char *comment;
- char tmp[100];
- int len, x;
-
- /*
- * Owner.
- */
- if (name_ctx != NULL && ns_samename(name_ctx, name) == 1) {
- T(addstr("\t\t\t", 3, &buf, &buflen));
- } else {
- len = prune_origin(name, origin);
- if (*name == '\0') {
- goto root;
- } else if (len == 0) {
- T(addstr("@\t\t\t", 4, &buf, &buflen));
- } else {
- T(addstr(name, len, &buf, &buflen));
- /* Origin not used or not root, and no trailing dot? */
- if (((origin == NULL || origin[0] == '\0') ||
- (origin[0] != '.' && origin[1] != '\0' &&
- name[len] == '\0')) && name[len - 1] != '.') {
- root:
- T(addstr(".", 1, &buf, &buflen));
- len++;
- }
- T(spaced = addtab(len, 24, spaced, &buf, &buflen));
- }
- }
-
- /*
- * TTL, Class, Type.
- */
- T(x = ns_format_ttl(ttl, buf, buflen));
- addlen(x, &buf, &buflen);
- len = SPRINTF((tmp, " %s %s", p_class(class), p_type(type)));
- T(addstr(tmp, len, &buf, &buflen));
- if (rdlen == 0)
- return (buf - obuf);
- T(spaced = addtab(x + len, 16, spaced, &buf, &buflen));
-
- /*
- * RData.
- */
- switch (type) {
- case ns_t_a:
- if (rdlen != NS_INADDRSZ)
- goto formerr;
- (void) inet_ntop(AF_INET, rdata, buf, buflen);
- addlen(strlen(buf), &buf, &buflen);
- break;
-
- case ns_t_cname:
- case ns_t_mb:
- case ns_t_mg:
- case ns_t_mr:
- case ns_t_ns:
- case ns_t_ptr:
- case ns_t_dname:
- T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
- break;
-
- case ns_t_hinfo:
- case ns_t_isdn:
- /* First word. */
- T(len = charstr(rdata, edata, &buf, &buflen));
- if (len == 0)
- goto formerr;
- rdata += len;
- T(addstr(" ", 1, &buf, &buflen));
-
-
- /* Second word, optional in ISDN records. */
- if (type == ns_t_isdn && rdata == edata)
- break;
-
- T(len = charstr(rdata, edata, &buf, &buflen));
- if (len == 0)
- goto formerr;
- rdata += len;
- break;
-
- case ns_t_soa: {
- u_long t;
-
- /* Server name. */
- T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
- T(addstr(" ", 1, &buf, &buflen));
-
- /* Administrator name. */
- T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
- T(addstr(" (\n", 3, &buf, &buflen));
- spaced = 0;
-
- if ((edata - rdata) != 5*NS_INT32SZ)
- goto formerr;
-
- /* Serial number. */
- t = ns_get32(rdata); rdata += NS_INT32SZ;
- T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
- len = SPRINTF((tmp, "%lu", t));
- T(addstr(tmp, len, &buf, &buflen));
- T(spaced = addtab(len, 16, spaced, &buf, &buflen));
- T(addstr("; serial\n", 9, &buf, &buflen));
- spaced = 0;
-
- /* Refresh interval. */
- t = ns_get32(rdata); rdata += NS_INT32SZ;
- T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
- T(len = ns_format_ttl(t, buf, buflen));
- addlen(len, &buf, &buflen);
- T(spaced = addtab(len, 16, spaced, &buf, &buflen));
- T(addstr("; refresh\n", 10, &buf, &buflen));
- spaced = 0;
-
- /* Retry interval. */
- t = ns_get32(rdata); rdata += NS_INT32SZ;
- T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
- T(len = ns_format_ttl(t, buf, buflen));
- addlen(len, &buf, &buflen);
- T(spaced = addtab(len, 16, spaced, &buf, &buflen));
- T(addstr("; retry\n", 8, &buf, &buflen));
- spaced = 0;
-
- /* Expiry. */
- t = ns_get32(rdata); rdata += NS_INT32SZ;
- T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
- T(len = ns_format_ttl(t, buf, buflen));
- addlen(len, &buf, &buflen);
- T(spaced = addtab(len, 16, spaced, &buf, &buflen));
- T(addstr("; expiry\n", 9, &buf, &buflen));
- spaced = 0;
-
- /* Minimum TTL. */
- t = ns_get32(rdata); rdata += NS_INT32SZ;
- T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
- T(len = ns_format_ttl(t, buf, buflen));
- addlen(len, &buf, &buflen);
- T(addstr(" )", 2, &buf, &buflen));
- T(spaced = addtab(len, 16, spaced, &buf, &buflen));
- T(addstr("; minimum\n", 10, &buf, &buflen));
-
- break;
- }
-
- case ns_t_mx:
- case ns_t_afsdb:
- case ns_t_rt: {
- u_int t;
-
- if (rdlen < NS_INT16SZ)
- goto formerr;
-
- /* Priority. */
- t = ns_get16(rdata);
- rdata += NS_INT16SZ;
- len = SPRINTF((tmp, "%u ", t));
- T(addstr(tmp, len, &buf, &buflen));
-
- /* Target. */
- T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-
- break;
- }
-
- case ns_t_px: {
- u_int t;
-
- if (rdlen < NS_INT16SZ)
- goto formerr;
-
- /* Priority. */
- t = ns_get16(rdata);
- rdata += NS_INT16SZ;
- len = SPRINTF((tmp, "%u ", t));
- T(addstr(tmp, len, &buf, &buflen));
-
- /* Name1. */
- T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
- T(addstr(" ", 1, &buf, &buflen));
-
- /* Name2. */
- T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-
- break;
- }
-
- case ns_t_x25:
- T(len = charstr(rdata, edata, &buf, &buflen));
- if (len == 0)
- goto formerr;
- rdata += len;
- break;
-
- case ns_t_txt:
- while (rdata < edata) {
- T(len = charstr(rdata, edata, &buf, &buflen));
- if (len == 0)
- goto formerr;
- rdata += len;
- if (rdata < edata)
- T(addstr(" ", 1, &buf, &buflen));
- }
- break;
-
- case ns_t_nsap: {
- char t[2+255*3];
-
- (void) inet_nsap_ntoa(rdlen, rdata, t);
- T(addstr(t, strlen(t), &buf, &buflen));
- break;
- }
-
- case ns_t_aaaa:
- if (rdlen != NS_IN6ADDRSZ)
- goto formerr;
- (void) inet_ntop(AF_INET6, rdata, buf, buflen);
- addlen(strlen(buf), &buf, &buflen);
- break;
-
- case ns_t_loc: {
- char t[255];
-
- /* XXX protocol format checking? */
- (void) loc_ntoa(rdata, t);
- T(addstr(t, strlen(t), &buf, &buflen));
- break;
- }
-
- case ns_t_naptr: {
- u_int order, preference;
- char t[50];
-
- if (rdlen < 2*NS_INT16SZ)
- goto formerr;
-
- /* Order, Precedence. */
- order = ns_get16(rdata); rdata += NS_INT16SZ;
- preference = ns_get16(rdata); rdata += NS_INT16SZ;
- len = SPRINTF((t, "%u %u ", order, preference));
- T(addstr(t, len, &buf, &buflen));
-
- /* Flags. */
- T(len = charstr(rdata, edata, &buf, &buflen));
- if (len == 0)
- goto formerr;
- rdata += len;
- T(addstr(" ", 1, &buf, &buflen));
-
- /* Service. */
- T(len = charstr(rdata, edata, &buf, &buflen));
- if (len == 0)
- goto formerr;
- rdata += len;
- T(addstr(" ", 1, &buf, &buflen));
-
- /* Regexp. */
- T(len = charstr(rdata, edata, &buf, &buflen));
- if (len < 0)
- return (-1);
- if (len == 0)
- goto formerr;
- rdata += len;
- T(addstr(" ", 1, &buf, &buflen));
-
- /* Server. */
- T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
- break;
- }
-
- case ns_t_srv: {
- u_int priority, weight, port;
- char t[50];
-
- if (rdlen < NS_INT16SZ*3)
- goto formerr;
-
- /* Priority, Weight, Port. */
- priority = ns_get16(rdata); rdata += NS_INT16SZ;
- weight = ns_get16(rdata); rdata += NS_INT16SZ;
- port = ns_get16(rdata); rdata += NS_INT16SZ;
- len = SPRINTF((t, "%u %u %u ", priority, weight, port));
- T(addstr(t, len, &buf, &buflen));
-
- /* Server. */
- T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
- break;
- }
-
- case ns_t_minfo:
- case ns_t_rp:
- /* Name1. */
- T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
- T(addstr(" ", 1, &buf, &buflen));
-
- /* Name2. */
- T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-
- break;
-
- case ns_t_wks: {
- int n, lcnt;
-
- if (rdlen < NS_INT32SZ + 1)
- goto formerr;
-
- /* Address. */
- (void) inet_ntop(AF_INET, rdata, buf, buflen);
- addlen(strlen(buf), &buf, &buflen);
- rdata += NS_INADDRSZ;
-
- /* Protocol. */
- len = SPRINTF((tmp, " %u ( ", *rdata));
- T(addstr(tmp, len, &buf, &buflen));
- rdata += NS_INT8SZ;
-
- /* Bit map. */
- n = 0;
- lcnt = 0;
- while (rdata < edata) {
- u_int c = *rdata++;
- do {
- if (c & 0200) {
- if (lcnt == 0) {
- T(addstr("\n\t\t\t\t", 5,
- &buf, &buflen));
- lcnt = 10;
- spaced = 0;
- }
- len = SPRINTF((tmp, "%d ", n));
- T(addstr(tmp, len, &buf, &buflen));
- lcnt--;
- }
- c <<= 1;
- } while (++n & 07);
- }
- T(addstr(")", 1, &buf, &buflen));
-
- break;
- }
-
- case ns_t_key: {
- char base64_key[NS_MD5RSA_MAX_BASE64];
- u_int keyflags, protocol, algorithm, key_id;
- const char *leader;
- int n;
-
- if (rdlen < NS_INT16SZ + NS_INT8SZ + NS_INT8SZ)
- goto formerr;
-
- /* Key flags, Protocol, Algorithm. */
- key_id = dst_s_dns_key_id(rdata, edata-rdata);
- keyflags = ns_get16(rdata); rdata += NS_INT16SZ;
- protocol = *rdata++;
- algorithm = *rdata++;
- len = SPRINTF((tmp, "0x%04x %u %u",
- keyflags, protocol, algorithm));
- T(addstr(tmp, len, &buf, &buflen));
-
- /* Public key data. */
- len = b64_ntop(rdata, edata - rdata,
- base64_key, sizeof base64_key);
- if (len < 0)
- goto formerr;
- if (len > 15) {
- T(addstr(" (", 2, &buf, &buflen));
- leader = "\n\t\t";
- spaced = 0;
- } else
- leader = " ";
- for (n = 0; n < len; n += 48) {
- T(addstr(leader, strlen(leader), &buf, &buflen));
- T(addstr(base64_key + n, MIN(len - n, 48),
- &buf, &buflen));
- }
- if (len > 15)
- T(addstr(" )", 2, &buf, &buflen));
- n = SPRINTF((tmp, " ; key_tag= %u", key_id));
- T(addstr(tmp, n, &buf, &buflen));
-
- break;
- }
-
- case ns_t_sig: {
- char base64_key[NS_MD5RSA_MAX_BASE64];
- u_int type, algorithm, labels, footprint;
- const char *leader;
- u_long t;
- int n;
-
- if (rdlen < 22)
- goto formerr;
-
- /* Type covered, Algorithm, Label count, Original TTL. */
- type = ns_get16(rdata); rdata += NS_INT16SZ;
- algorithm = *rdata++;
- labels = *rdata++;
- t = ns_get32(rdata); rdata += NS_INT32SZ;
- len = SPRINTF((tmp, "%s %d %d %lu ",
- p_type(type), algorithm, labels, t));
- T(addstr(tmp, len, &buf, &buflen));
- if (labels > (u_int)dn_count_labels(name))
- goto formerr;
-
- /* Signature expiry. */
- t = ns_get32(rdata); rdata += NS_INT32SZ;
- len = SPRINTF((tmp, "%s ", p_secstodate(t)));
- T(addstr(tmp, len, &buf, &buflen));
-
- /* Time signed. */
- t = ns_get32(rdata); rdata += NS_INT32SZ;
- len = SPRINTF((tmp, "%s ", p_secstodate(t)));
- T(addstr(tmp, len, &buf, &buflen));
-
- /* Signature Footprint. */
- footprint = ns_get16(rdata); rdata += NS_INT16SZ;
- len = SPRINTF((tmp, "%u ", footprint));
- T(addstr(tmp, len, &buf, &buflen));
-
- /* Signer's name. */
- T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-
- /* Signature. */
- len = b64_ntop(rdata, edata - rdata,
- base64_key, sizeof base64_key);
- if (len > 15) {
- T(addstr(" (", 2, &buf, &buflen));
- leader = "\n\t\t";
- spaced = 0;
- } else
- leader = " ";
- if (len < 0)
- goto formerr;
- for (n = 0; n < len; n += 48) {
- T(addstr(leader, strlen(leader), &buf, &buflen));
- T(addstr(base64_key + n, MIN(len - n, 48),
- &buf, &buflen));
- }
- if (len > 15)
- T(addstr(" )", 2, &buf, &buflen));
- break;
- }
-
- case ns_t_nxt: {
- int n, c;
-
- /* Next domain name. */
- T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-
- /* Type bit map. */
- n = edata - rdata;
- for (c = 0; c < n*8; c++)
- if (NS_NXT_BIT_ISSET(c, rdata)) {
- len = SPRINTF((tmp, " %s", p_type(c)));
- T(addstr(tmp, len, &buf, &buflen));
- }
- break;
- }
-
- case ns_t_cert: {
- u_int c_type, key_tag, alg;
- int n;
- unsigned int siz;
- char base64_cert[8192], tmp[40];
- const char *leader;
-
- c_type = ns_get16(rdata); rdata += NS_INT16SZ;
- key_tag = ns_get16(rdata); rdata += NS_INT16SZ;
- alg = (u_int) *rdata++;
-
- len = SPRINTF((tmp, "%d %d %d ", c_type, key_tag, alg));
- T(addstr(tmp, len, &buf, &buflen));
- siz = (edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */
- if (siz > sizeof(base64_cert) * 3/4) {
- const char *str = "record too long to print";
- T(addstr(str, strlen(str), &buf, &buflen));
- }
- else {
- len = b64_ntop(rdata, edata-rdata, base64_cert, siz);
-
- if (len < 0)
- goto formerr;
- else if (len > 15) {
- T(addstr(" (", 2, &buf, &buflen));
- leader = "\n\t\t";
- spaced = 0;
- }
- else
- leader = " ";
-
- for (n = 0; n < len; n += 48) {
- T(addstr(leader, strlen(leader),
- &buf, &buflen));
- T(addstr(base64_cert + n, MIN(len - n, 48),
- &buf, &buflen));
- }
- if (len > 15)
- T(addstr(" )", 2, &buf, &buflen));
- }
- break;
- }
-
- case ns_t_tkey: {
- /* KJD - need to complete this */
- u_long t;
- int mode, err, keysize;
-
- /* Algorithm name. */
- T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
- T(addstr(" ", 1, &buf, &buflen));
-
- /* Inception. */
- t = ns_get32(rdata); rdata += NS_INT32SZ;
- len = SPRINTF((tmp, "%s ", p_secstodate(t)));
- T(addstr(tmp, len, &buf, &buflen));
-
- /* Experation. */
- t = ns_get32(rdata); rdata += NS_INT32SZ;
- len = SPRINTF((tmp, "%s ", p_secstodate(t)));
- T(addstr(tmp, len, &buf, &buflen));
-
- /* Mode , Error, Key Size. */
- /* Priority, Weight, Port. */
- mode = ns_get16(rdata); rdata += NS_INT16SZ;
- err = ns_get16(rdata); rdata += NS_INT16SZ;
- keysize = ns_get16(rdata); rdata += NS_INT16SZ;
- len = SPRINTF((tmp, "%u %u %u ", mode, err, keysize));
- T(addstr(tmp, len, &buf, &buflen));
-
- /* XXX need to dump key, print otherdata length & other data */
- break;
- }
-
- case ns_t_tsig: {
- /* BEW - need to complete this */
- int n;
-
- T(len = addname(msg, msglen, &rdata, origin, &buf, &buflen));
- T(addstr(" ", 1, &buf, &buflen));
- rdata += 8; /* time */
- n = ns_get16(rdata); rdata += INT16SZ;
- rdata += n; /* sig */
- n = ns_get16(rdata); rdata += INT16SZ; /* original id */
- sprintf(buf, "%d", ns_get16(rdata));
- rdata += INT16SZ;
- addlen(strlen(buf), &buf, &buflen);
- break;
- }
-
- case ns_t_a6: {
- struct in6_addr a;
- int pbyte, pbit;
-
- /* prefix length */
- if (rdlen == 0) goto formerr;
- len = SPRINTF((tmp, "%d ", *rdata));
- T(addstr(tmp, len, &buf, &buflen));
- pbit = *rdata;
- if (pbit > 128) goto formerr;
- pbyte = (pbit & ~7) / 8;
- rdata++;
-
- /* address suffix: provided only when prefix len != 128 */
- if (pbit < 128) {
- if (rdata + pbyte >= edata) goto formerr;
- memset(&a, 0, sizeof(a));
- memcpy(&a.s6_addr[pbyte], rdata, sizeof(a) - pbyte);
- (void) inet_ntop(AF_INET6, &a, buf, buflen);
- addlen(strlen(buf), &buf, &buflen);
- rdata += sizeof(a) - pbyte;
- }
-
- /* prefix name: provided only when prefix len > 0 */
- if (pbit == 0)
- break;
- if (rdata >= edata) goto formerr;
- T(addstr(" ", 1, &buf, &buflen));
- T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
-
- break;
- }
-
- case ns_t_opt: {
- len = SPRINTF((tmp, "%u bytes", class));
- T(addstr(tmp, len, &buf, &buflen));
- break;
- }
-
- default:
- comment = "unknown RR type";
- goto hexify;
- }
- return (buf - obuf);
- formerr:
- comment = "RR format error";
- hexify: {
- int n, m;
- char *p;
-
- len = SPRINTF((tmp, "\\# %u (\t; %s", edata - rdata, comment));
- T(addstr(tmp, len, &buf, &buflen));
- while (rdata < edata) {
- p = tmp;
- p += SPRINTF((p, "\n\t"));
- spaced = 0;
- n = MIN(16, edata - rdata);
- for (m = 0; m < n; m++)
- p += SPRINTF((p, "%02x ", rdata[m]));
- T(addstr(tmp, p - tmp, &buf, &buflen));
- if (n < 16) {
- T(addstr(")", 1, &buf, &buflen));
- T(addtab(p - tmp + 1, 48, spaced, &buf, &buflen));
- }
- p = tmp;
- p += SPRINTF((p, "; "));
- for (m = 0; m < n; m++)
- *p++ = (isascii(rdata[m]) && isprint(rdata[m]))
- ? rdata[m]
- : '.';
- T(addstr(tmp, p - tmp, &buf, &buflen));
- rdata += n;
- }
- return (buf - obuf);
- }
-}
-
-/* Private. */
-
-/*
- * size_t
- * prune_origin(name, origin)
- * Find out if the name is at or under the current origin.
- * return:
- * Number of characters in name before start of origin,
- * or length of name if origin does not match.
- * notes:
- * This function should share code with samedomain().
- */
-static size_t
-prune_origin(const char *name, const char *origin) {
- const char *oname = name;
-
- while (*name != '\0') {
- if (origin != NULL && ns_samename(name, origin) == 1)
- return (name - oname - (name > oname));
- while (*name != '\0') {
- if (*name == '\\') {
- name++;
- /* XXX need to handle \nnn form. */
- if (*name == '\0')
- break;
- } else if (*name == '.') {
- name++;
- break;
- }
- name++;
- }
- }
- return (name - oname);
-}
-
-/*
- * int
- * charstr(rdata, edata, buf, buflen)
- * Format a <character-string> into the presentation buffer.
- * return:
- * Number of rdata octets consumed
- * 0 for protocol format error
- * -1 for output buffer error
- * side effects:
- * buffer is advanced on success.
- */
-static int
-charstr(const u_char *rdata, const u_char *edata, char **buf, size_t *buflen) {
- const u_char *odata = rdata;
- size_t save_buflen = *buflen;
- char *save_buf = *buf;
-
- if (addstr("\"", 1, buf, buflen) < 0)
- goto enospc;
- if (rdata < edata) {
- int n = *rdata;
-
- if (rdata + 1 + n <= edata) {
- rdata++;
- while (n-- > 0) {
- if (strchr("\n\"\\", *rdata) != NULL)
- if (addstr("\\", 1, buf, buflen) < 0)
- goto enospc;
- if (addstr((const char *)rdata, 1,
- buf, buflen) < 0)
- goto enospc;
- rdata++;
- }
- }
- }
- if (addstr("\"", 1, buf, buflen) < 0)
- goto enospc;
- return (rdata - odata);
- enospc:
- errno = ENOSPC;
- *buf = save_buf;
- *buflen = save_buflen;
- return (-1);
-}
-
-static int
-addname(const u_char *msg, size_t msglen,
- const u_char **pp, const char *origin,
- char **buf, size_t *buflen)
-{
- size_t newlen, save_buflen = *buflen;
- char *save_buf = *buf;
- int n;
-
- n = dn_expand(msg, msg + msglen, *pp, *buf, *buflen);
- if (n < 0)
- goto enospc; /* Guess. */
- newlen = prune_origin(*buf, origin);
- if (**buf == '\0') {
- goto root;
- } else if (newlen == 0) {
- /* Use "@" instead of name. */
- if (newlen + 2 > *buflen)
- goto enospc; /* No room for "@\0". */
- (*buf)[newlen++] = '@';
- (*buf)[newlen] = '\0';
- } else {
- if (((origin == NULL || origin[0] == '\0') ||
- (origin[0] != '.' && origin[1] != '\0' &&
- (*buf)[newlen] == '\0')) && (*buf)[newlen - 1] != '.') {
- /* No trailing dot. */
- root:
- if (newlen + 2 > *buflen)
- goto enospc; /* No room for ".\0". */
- (*buf)[newlen++] = '.';
- (*buf)[newlen] = '\0';
- }
- }
- *pp += n;
- addlen(newlen, buf, buflen);
- **buf = '\0';
- return (newlen);
- enospc:
- errno = ENOSPC;
- *buf = save_buf;
- *buflen = save_buflen;
- return (-1);
-}
-
-static void
-addlen(size_t len, char **buf, size_t *buflen) {
- INSIST(len <= *buflen);
- *buf += len;
- *buflen -= len;
-}
-
-static int
-addstr(const char *src, size_t len, char **buf, size_t *buflen) {
- if (len >= *buflen) {
- errno = ENOSPC;
- return (-1);
- }
- memcpy(*buf, src, len);
- addlen(len, buf, buflen);
- **buf = '\0';
- return (0);
-}
-
-static int
-addtab(size_t len, size_t target, int spaced, char **buf, size_t *buflen) {
- size_t save_buflen = *buflen;
- char *save_buf = *buf;
- int t;
-
- if (spaced || len >= target - 1) {
- T(addstr(" ", 2, buf, buflen));
- spaced = 1;
- } else {
- for (t = (target - len - 1) / 8; t >= 0; t--)
- if (addstr("\t", 1, buf, buflen) < 0) {
- *buflen = save_buflen;
- *buf = save_buf;
- return (-1);
- }
- spaced = 0;
- }
- return (spaced);
-}
diff --git a/contrib/bind/lib/nameser/ns_samedomain.c b/contrib/bind/lib/nameser/ns_samedomain.c
deleted file mode 100644
index 6394701..0000000
--- a/contrib/bind/lib/nameser/ns_samedomain.c
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Copyright (c) 1995,1999 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.
- */
-
-#ifndef lint
-static const char rcsid[] = "$Id: ns_samedomain.c,v 8.10.8.1 2003/06/02 05:05:05 marka Exp $";
-#endif
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <arpa/nameser.h>
-#include <errno.h>
-#include <string.h>
-
-#include "port_after.h"
-
-/*
- * int
- * ns_samedomain(a, b)
- * Check whether a name belongs to a domain.
- * Inputs:
- * a - the domain whose ancestory is being verified
- * b - the potential ancestor we're checking against
- * Return:
- * boolean - is a at or below b?
- * Notes:
- * Trailing dots are first removed from name and domain.
- * Always compare complete subdomains, not only whether the
- * domain name is the trailing string of the given name.
- *
- * "host.foobar.top" lies in "foobar.top" and in "top" and in ""
- * but NOT in "bar.top"
- */
-
-int
-ns_samedomain(const char *a, const char *b) {
- size_t la, lb;
- int diff, i, escaped;
- const char *cp;
-
- la = strlen(a);
- lb = strlen(b);
-
- /* Ignore a trailing label separator (i.e. an unescaped dot) in 'a'. */
- if (la != 0 && a[la - 1] == '.') {
- escaped = 0;
- /* Note this loop doesn't get executed if la==1. */
- for (i = la - 2; i >= 0; i--)
- if (a[i] == '\\') {
- if (escaped)
- escaped = 0;
- else
- escaped = 1;
- } else
- break;
- if (!escaped)
- la--;
- }
-
- /* Ignore a trailing label separator (i.e. an unescaped dot) in 'b'. */
- if (lb != 0 && b[lb - 1] == '.') {
- escaped = 0;
- /* note this loop doesn't get executed if lb==1 */
- for (i = lb - 2; i >= 0; i--)
- if (b[i] == '\\') {
- if (escaped)
- escaped = 0;
- else
- escaped = 1;
- } else
- break;
- if (!escaped)
- lb--;
- }
-
- /* lb == 0 means 'b' is the root domain, so 'a' must be in 'b'. */
- if (lb == 0)
- return (1);
-
- /* 'b' longer than 'a' means 'a' can't be in 'b'. */
- if (lb > la)
- return (0);
-
- /* 'a' and 'b' being equal at this point indicates sameness. */
- if (lb == la)
- return (strncasecmp(a, b, lb) == 0);
-
- /* Ok, we know la > lb. */
-
- diff = la - lb;
-
- /*
- * If 'a' is only 1 character longer than 'b', then it can't be
- * a subdomain of 'b' (because of the need for the '.' label
- * separator).
- */
- if (diff < 2)
- return (0);
-
- /*
- * If the character before the last 'lb' characters of 'b'
- * isn't '.', then it can't be a match (this lets us avoid
- * having "foobar.com" match "bar.com").
- */
- if (a[diff - 1] != '.')
- return (0);
-
- /*
- * We're not sure about that '.', however. It could be escaped
- * and thus not a really a label separator.
- */
- escaped = 0;
- for (i = diff - 2; i >= 0; i--)
- if (a[i] == '\\') {
- if (escaped)
- escaped = 0;
- else
- escaped = 1;
- } else
- break;
- if (escaped)
- return (0);
-
- /* Now compare aligned trailing substring. */
- cp = a + diff;
- return (strncasecmp(cp, b, lb) == 0);
-}
-
-/*
- * int
- * ns_subdomain(a, b)
- * is "a" a subdomain of "b"?
- */
-int
-ns_subdomain(const char *a, const char *b) {
- return (ns_samename(a, b) != 1 && ns_samedomain(a, b));
-}
-
-/*
- * int
- * ns_makecanon(src, dst, dstsize)
- * make a canonical copy of domain name "src"
- * notes:
- * foo -> foo.
- * foo. -> foo.
- * foo.. -> foo.
- * foo\. -> foo\..
- * foo\\. -> foo\\.
- */
-
-int
-ns_makecanon(const char *src, char *dst, size_t dstsize) {
- size_t n = strlen(src);
-
- if (n + sizeof "." > dstsize) { /* Note: sizeof == 2 */
- errno = EMSGSIZE;
- return (-1);
- }
- strcpy(dst, src);
- while (n >= 1 && dst[n - 1] == '.') /* Ends in "." */
- if (n >= 2 && dst[n - 2] == '\\' && /* Ends in "\." */
- (n < 3 || dst[n - 3] != '\\')) /* But not "\\." */
- break;
- else
- dst[--n] = '\0';
- dst[n++] = '.';
- dst[n] = '\0';
- return (0);
-}
-
-/*
- * int
- * ns_samename(a, b)
- * determine whether domain name "a" is the same as domain name "b"
- * return:
- * -1 on error
- * 0 if names differ
- * 1 if names are the same
- */
-
-int
-ns_samename(const char *a, const char *b) {
- char ta[NS_MAXDNAME], tb[NS_MAXDNAME];
-
- if (ns_makecanon(a, ta, sizeof ta) < 0 ||
- ns_makecanon(b, tb, sizeof tb) < 0)
- return (-1);
- if (strcasecmp(ta, tb) == 0)
- return (1);
- else
- return (0);
-}
diff --git a/contrib/bind/lib/nameser/ns_sign.c b/contrib/bind/lib/nameser/ns_sign.c
deleted file mode 100644
index de8cd14..0000000
--- a/contrib/bind/lib/nameser/ns_sign.c
+++ /dev/null
@@ -1,380 +0,0 @@
-/*
- * Copyright (c) 1999 by Internet Software Consortium, Inc.
- *
- * 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 lint
-static const char rcsid[] = "$Id: ns_sign.c,v 8.12 2002/10/01 06:48:37 marka Exp $";
-#endif
-
-/* Import. */
-
-#include "port_before.h"
-#include "fd_setsize.h"
-
-#include <sys/types.h>
-#include <sys/param.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <arpa/inet.h>
-
-#include <errno.h>
-#include <netdb.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-
-#include <isc/dst.h>
-#include <isc/assertions.h>
-
-#include "port_after.h"
-
-#define BOUNDS_CHECK(ptr, count) \
- do { \
- if ((ptr) + (count) > eob) { \
- errno = EMSGSIZE; \
- return(NS_TSIG_ERROR_NO_SPACE); \
- } \
- } while (0)
-
-/* ns_sign
- * Parameters:
- * msg message to be sent
- * msglen input - length of message
- * output - length of signed message
- * msgsize length of buffer containing message
- * error value to put in the error field
- * key tsig key used for signing
- * querysig (response), the signature in the query
- * querysiglen (response), the length of the signature in the query
- * sig a buffer to hold the generated signature
- * siglen input - length of signature buffer
- * output - length of signature
- *
- * Errors:
- * - bad input data (-1)
- * - bad key / sign failed (-BADKEY)
- * - not enough space (NS_TSIG_ERROR_NO_SPACE)
- */
-int
-ns_sign(u_char *msg, int *msglen, int msgsize, int error, void *k,
- const u_char *querysig, int querysiglen, u_char *sig, int *siglen,
- time_t in_timesigned)
-{
- return(ns_sign2(msg, msglen, msgsize, error, k,
- querysig, querysiglen, sig, siglen,
- in_timesigned, NULL, NULL));
-}
-
-int
-ns_sign2(u_char *msg, int *msglen, int msgsize, int error, void *k,
- const u_char *querysig, int querysiglen, u_char *sig, int *siglen,
- time_t in_timesigned, u_char **dnptrs, u_char **lastdnptr)
-{
- HEADER *hp = (HEADER *)msg;
- DST_KEY *key = (DST_KEY *)k;
- u_char *cp = msg + *msglen, *eob = msg + msgsize;
- u_char *lenp;
- u_char *alg;
- int n;
- time_t timesigned;
- u_char name[NS_MAXCDNAME];
-
- dst_init();
- if (msg == NULL || msglen == NULL || sig == NULL || siglen == NULL)
- return (-1);
-
- /* Name. */
- if (key != NULL && error != ns_r_badsig && error != ns_r_badkey) {
- n = ns_name_pton(key->dk_key_name, name, sizeof name);
- if (n != -1)
- n = ns_name_pack(name, cp, eob - cp,
- (const u_char **)dnptrs,
- (const u_char **)lastdnptr);
-
- } else {
- n = ns_name_pton("", name, sizeof name);
- if (n != -1)
- n = ns_name_pack(name, cp, eob - cp, NULL, NULL);
- }
- if (n < 0)
- return (NS_TSIG_ERROR_NO_SPACE);
- cp += n;
-
- /* Type, class, ttl, length (not filled in yet). */
- BOUNDS_CHECK(cp, INT16SZ + INT16SZ + INT32SZ + INT16SZ);
- PUTSHORT(ns_t_tsig, cp);
- PUTSHORT(ns_c_any, cp);
- PUTLONG(0, cp); /* TTL */
- lenp = cp;
- cp += 2;
-
- /* Alg. */
- if (key != NULL && error != ns_r_badsig && error != ns_r_badkey) {
- if (key->dk_alg != KEY_HMAC_MD5)
- return (-ns_r_badkey);
- n = dn_comp(NS_TSIG_ALG_HMAC_MD5, cp, eob - cp, NULL, NULL);
- }
- else
- n = dn_comp("", cp, eob - cp, NULL, NULL);
- if (n < 0)
- return (NS_TSIG_ERROR_NO_SPACE);
- alg = cp;
- cp += n;
-
- /* Time. */
- BOUNDS_CHECK(cp, INT16SZ + INT32SZ + INT16SZ);
- PUTSHORT(0, cp);
- timesigned = time(NULL);
- if (error != ns_r_badtime)
- PUTLONG(timesigned, cp);
- else
- PUTLONG(in_timesigned, cp);
- PUTSHORT(NS_TSIG_FUDGE, cp);
-
- /* Compute the signature. */
- if (key != NULL && error != ns_r_badsig && error != ns_r_badkey) {
- void *ctx;
- u_char buf[NS_MAXCDNAME], *cp2;
- int n;
-
- dst_sign_data(SIG_MODE_INIT, key, &ctx, NULL, 0, NULL, 0);
-
- /* Digest the query signature, if this is a response. */
- if (querysiglen > 0 && querysig != NULL) {
- u_int16_t len_n = htons(querysiglen);
- dst_sign_data(SIG_MODE_UPDATE, key, &ctx,
- (u_char *)&len_n, INT16SZ, NULL, 0);
- dst_sign_data(SIG_MODE_UPDATE, key, &ctx,
- querysig, querysiglen, NULL, 0);
- }
-
- /* Digest the message. */
- dst_sign_data(SIG_MODE_UPDATE, key, &ctx, msg, *msglen,
- NULL, 0);
-
- /* Digest the key name. */
- n = ns_name_ntol(name, buf, sizeof(buf));
- INSIST(n > 0);
- dst_sign_data(SIG_MODE_UPDATE, key, &ctx, buf, n, NULL, 0);
-
- /* Digest the class and TTL. */
- cp2 = buf;
- PUTSHORT(ns_c_any, cp2);
- PUTLONG(0, cp2);
- dst_sign_data(SIG_MODE_UPDATE, key, &ctx, buf, cp2-buf,
- NULL, 0);
-
- /* Digest the algorithm. */
- n = ns_name_ntol(alg, buf, sizeof(buf));
- INSIST(n > 0);
- dst_sign_data(SIG_MODE_UPDATE, key, &ctx, buf, n, NULL, 0);
-
- /* Digest the time signed, fudge, error, and other data */
- cp2 = buf;
- PUTSHORT(0, cp2); /* Top 16 bits of time */
- if (error != ns_r_badtime)
- PUTLONG(timesigned, cp2);
- else
- PUTLONG(in_timesigned, cp2);
- PUTSHORT(NS_TSIG_FUDGE, cp2);
- PUTSHORT(error, cp2); /* Error */
- if (error != ns_r_badtime)
- PUTSHORT(0, cp2); /* Other data length */
- else {
- PUTSHORT(INT16SZ+INT32SZ, cp2); /* Other data length */
- PUTSHORT(0, cp2); /* Top 16 bits of time */
- PUTLONG(timesigned, cp2);
- }
- dst_sign_data(SIG_MODE_UPDATE, key, &ctx, buf, cp2-buf,
- NULL, 0);
-
- n = dst_sign_data(SIG_MODE_FINAL, key, &ctx, NULL, 0,
- sig, *siglen);
- if (n < 0)
- return (-ns_r_badkey);
- *siglen = n;
- } else
- *siglen = 0;
-
- /* Add the signature. */
- BOUNDS_CHECK(cp, INT16SZ + (*siglen));
- PUTSHORT(*siglen, cp);
- memcpy(cp, sig, *siglen);
- cp += (*siglen);
-
- /* The original message ID & error. */
- BOUNDS_CHECK(cp, INT16SZ + INT16SZ);
- PUTSHORT(ntohs(hp->id), cp); /* already in network order */
- PUTSHORT(error, cp);
-
- /* Other data. */
- BOUNDS_CHECK(cp, INT16SZ);
- if (error != ns_r_badtime)
- PUTSHORT(0, cp); /* Other data length */
- else {
- PUTSHORT(INT16SZ+INT32SZ, cp); /* Other data length */
- BOUNDS_CHECK(cp, INT32SZ+INT16SZ);
- PUTSHORT(0, cp); /* Top 16 bits of time */
- PUTLONG(timesigned, cp);
- }
-
- /* Go back and fill in the length. */
- PUTSHORT(cp - lenp - INT16SZ, lenp);
-
- hp->arcount = htons(ntohs(hp->arcount) + 1);
- *msglen = (cp - msg);
- return (0);
-}
-
-int
-ns_sign_tcp_init(void *k, const u_char *querysig, int querysiglen,
- ns_tcp_tsig_state *state)
-{
- dst_init();
- if (state == NULL || k == NULL || querysig == NULL || querysiglen < 0)
- return (-1);
- state->counter = -1;
- state->key = k;
- if (state->key->dk_alg != KEY_HMAC_MD5)
- return (-ns_r_badkey);
- if (querysiglen > (int)sizeof(state->sig))
- return (-1);
- memcpy(state->sig, querysig, querysiglen);
- state->siglen = querysiglen;
- return (0);
-}
-
-int
-ns_sign_tcp(u_char *msg, int *msglen, int msgsize, int error,
- ns_tcp_tsig_state *state, int done)
-{
- return (ns_sign_tcp2(msg, msglen, msgsize, error, state,
- done, NULL, NULL));
-}
-
-int
-ns_sign_tcp2(u_char *msg, int *msglen, int msgsize, int error,
- ns_tcp_tsig_state *state, int done,
- u_char **dnptrs, u_char **lastdnptr)
-{
- u_char *cp, *eob, *lenp;
- u_char buf[MAXDNAME], *cp2;
- HEADER *hp = (HEADER *)msg;
- time_t timesigned;
- int n;
-
- if (msg == NULL || msglen == NULL || state == NULL)
- return (-1);
-
- state->counter++;
- if (state->counter == 0)
- return (ns_sign2(msg, msglen, msgsize, error, state->key,
- state->sig, state->siglen,
- state->sig, &state->siglen, 0,
- dnptrs, lastdnptr));
-
- if (state->siglen > 0) {
- u_int16_t siglen_n = htons(state->siglen);
- dst_sign_data(SIG_MODE_INIT, state->key, &state->ctx,
- NULL, 0, NULL, 0);
- dst_sign_data(SIG_MODE_UPDATE, state->key, &state->ctx,
- (u_char *)&siglen_n, INT16SZ, NULL, 0);
- dst_sign_data(SIG_MODE_UPDATE, state->key, &state->ctx,
- state->sig, state->siglen, NULL, 0);
- state->siglen = 0;
- }
-
- dst_sign_data(SIG_MODE_UPDATE, state->key, &state->ctx, msg, *msglen,
- NULL, 0);
-
- if (done == 0 && (state->counter % 100 != 0))
- return (0);
-
- cp = msg + *msglen;
- eob = msg + msgsize;
-
- /* Name. */
- n = dn_comp(state->key->dk_key_name, cp, eob - cp, dnptrs, lastdnptr);
- if (n < 0)
- return (NS_TSIG_ERROR_NO_SPACE);
- cp += n;
-
- /* Type, class, ttl, length (not filled in yet). */
- BOUNDS_CHECK(cp, INT16SZ + INT16SZ + INT32SZ + INT16SZ);
- PUTSHORT(ns_t_tsig, cp);
- PUTSHORT(ns_c_any, cp);
- PUTLONG(0, cp); /* TTL */
- lenp = cp;
- cp += 2;
-
- /* Alg. */
- n = dn_comp(NS_TSIG_ALG_HMAC_MD5, cp, eob - cp, NULL, NULL);
- if (n < 0)
- return (NS_TSIG_ERROR_NO_SPACE);
- cp += n;
-
- /* Time. */
- BOUNDS_CHECK(cp, INT16SZ + INT32SZ + INT16SZ);
- PUTSHORT(0, cp);
- timesigned = time(NULL);
- PUTLONG(timesigned, cp);
- PUTSHORT(NS_TSIG_FUDGE, cp);
-
- /*
- * Compute the signature.
- */
-
- /* Digest the time signed and fudge. */
- cp2 = buf;
- PUTSHORT(0, cp2); /* Top 16 bits of time */
- PUTLONG(timesigned, cp2);
- PUTSHORT(NS_TSIG_FUDGE, cp2);
-
- dst_sign_data(SIG_MODE_UPDATE, state->key, &state->ctx,
- buf, cp2 - buf, NULL, 0);
-
- n = dst_sign_data(SIG_MODE_FINAL, state->key, &state->ctx, NULL, 0,
- state->sig, sizeof(state->sig));
- if (n < 0)
- return (-ns_r_badkey);
- state->siglen = n;
-
- /* Add the signature. */
- BOUNDS_CHECK(cp, INT16SZ + state->siglen);
- PUTSHORT(state->siglen, cp);
- memcpy(cp, state->sig, state->siglen);
- cp += state->siglen;
-
- /* The original message ID & error. */
- BOUNDS_CHECK(cp, INT16SZ + INT16SZ);
- PUTSHORT(ntohs(hp->id), cp); /* already in network order */
- PUTSHORT(error, cp);
-
- /* Other data. */
- BOUNDS_CHECK(cp, INT16SZ);
- PUTSHORT(0, cp);
-
- /* Go back and fill in the length. */
- PUTSHORT(cp - lenp - INT16SZ, lenp);
-
- hp->arcount = htons(ntohs(hp->arcount) + 1);
- *msglen = (cp - msg);
- return (0);
-}
diff --git a/contrib/bind/lib/nameser/ns_ttl.c b/contrib/bind/lib/nameser/ns_ttl.c
deleted file mode 100644
index 67cd976..0000000
--- a/contrib/bind/lib/nameser/ns_ttl.c
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * Copyright (c) 1996,1999 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.
- */
-
-#ifndef lint
-static const char rcsid[] = "$Id: ns_ttl.c,v 8.8 1999/10/13 16:39:36 vixie Exp $";
-#endif
-
-/* Import. */
-
-#include "port_before.h"
-
-#include <arpa/nameser.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "port_after.h"
-
-#ifdef SPRINTF_CHAR
-# define SPRINTF(x) strlen(sprintf/**/x)
-#else
-# define SPRINTF(x) ((size_t)sprintf x)
-#endif
-
-/* Forward. */
-
-static int fmt1(int t, char s, char **buf, size_t *buflen);
-
-/* Macros. */
-
-#define T(x) if ((x) < 0) return (-1); else (void)NULL
-
-/* Public. */
-
-int
-ns_format_ttl(u_long src, char *dst, size_t dstlen) {
- char *odst = dst;
- int secs, mins, hours, days, weeks, x;
- char *p;
-
- secs = src % 60; src /= 60;
- mins = src % 60; src /= 60;
- hours = src % 24; src /= 24;
- days = src % 7; src /= 7;
- weeks = src; src = 0;
-
- x = 0;
- if (weeks) {
- T(fmt1(weeks, 'W', &dst, &dstlen));
- x++;
- }
- if (days) {
- T(fmt1(days, 'D', &dst, &dstlen));
- x++;
- }
- if (hours) {
- T(fmt1(hours, 'H', &dst, &dstlen));
- x++;
- }
- if (mins) {
- T(fmt1(mins, 'M', &dst, &dstlen));
- x++;
- }
- if (secs || !(weeks || days || hours || mins)) {
- T(fmt1(secs, 'S', &dst, &dstlen));
- x++;
- }
-
- if (x > 1) {
- int ch;
-
- for (p = odst; (ch = *p) != '\0'; p++)
- if (isascii(ch) && isupper(ch))
- *p = tolower(ch);
- }
-
- return (dst - odst);
-}
-
-int
-ns_parse_ttl(const char *src, u_long *dst) {
- u_long ttl, tmp;
- int ch, digits, dirty;
-
- ttl = 0;
- tmp = 0;
- digits = 0;
- dirty = 0;
- while ((ch = *src++) != '\0') {
- if (!isascii(ch) || !isprint(ch))
- goto einval;
- if (isdigit(ch)) {
- tmp *= 10;
- tmp += (ch - '0');
- digits++;
- continue;
- }
- if (digits == 0)
- goto einval;
- if (islower(ch))
- ch = toupper(ch);
- switch (ch) {
- case 'W': tmp *= 7;
- case 'D': tmp *= 24;
- case 'H': tmp *= 60;
- case 'M': tmp *= 60;
- case 'S': break;
- default: goto einval;
- }
- ttl += tmp;
- tmp = 0;
- digits = 0;
- dirty = 1;
- }
- if (digits > 0) {
- if (dirty)
- goto einval;
- else
- ttl += tmp;
- }
- *dst = ttl;
- return (0);
-
- einval:
- errno = EINVAL;
- return (-1);
-}
-
-/* Private. */
-
-static int
-fmt1(int t, char s, char **buf, size_t *buflen) {
- char tmp[50];
- size_t len;
-
- len = SPRINTF((tmp, "%d%c", t, s));
- if (len + 1 > *buflen)
- return (-1);
- strcpy(*buf, tmp);
- *buf += len;
- *buflen -= len;
- return (0);
-}
diff --git a/contrib/bind/lib/nameser/ns_verify.c b/contrib/bind/lib/nameser/ns_verify.c
deleted file mode 100644
index 9fd8782..0000000
--- a/contrib/bind/lib/nameser/ns_verify.c
+++ /dev/null
@@ -1,480 +0,0 @@
-/*
- * Copyright (c) 1999 by Internet Software Consortium, Inc.
- *
- * 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 lint
-static const char rcsid[] = "$Id: ns_verify.c,v 8.14 2001/05/29 05:49:40 marka Exp $";
-#endif
-
-/* Import. */
-
-#include "port_before.h"
-#include "fd_setsize.h"
-
-#include <sys/types.h>
-#include <sys/param.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <arpa/inet.h>
-
-#include <errno.h>
-#include <netdb.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-
-#include <isc/dst.h>
-
-#include "port_after.h"
-
-/* Private. */
-
-#define BOUNDS_CHECK(ptr, count) \
- do { \
- if ((ptr) + (count) > eom) { \
- return (NS_TSIG_ERROR_FORMERR); \
- } \
- } while (0)
-
-/* Public. */
-
-u_char *
-ns_find_tsig(u_char *msg, u_char *eom) {
- HEADER *hp = (HEADER *)msg;
- int n, type;
- u_char *cp = msg, *start;
-
- if (msg == NULL || eom == NULL || msg > eom)
- return (NULL);
-
- if (cp + HFIXEDSZ >= eom)
- return (NULL);
-
- if (hp->arcount == 0)
- return (NULL);
-
- cp += HFIXEDSZ;
-
- n = ns_skiprr(cp, eom, ns_s_qd, ntohs(hp->qdcount));
- if (n < 0)
- return (NULL);
- cp += n;
-
- n = ns_skiprr(cp, eom, ns_s_an, ntohs(hp->ancount));
- if (n < 0)
- return (NULL);
- cp += n;
-
- n = ns_skiprr(cp, eom, ns_s_ns, ntohs(hp->nscount));
- if (n < 0)
- return (NULL);
- cp += n;
-
- n = ns_skiprr(cp, eom, ns_s_ar, ntohs(hp->arcount) - 1);
- if (n < 0)
- return (NULL);
- cp += n;
-
- start = cp;
- n = dn_skipname(cp, eom);
- if (n < 0)
- return (NULL);
- cp += n;
- if (cp + INT16SZ >= eom)
- return (NULL);
-
- GETSHORT(type, cp);
- if (type != ns_t_tsig)
- return (NULL);
- return (start);
-}
-
-/* ns_verify
- * Parameters:
- * statp res stuff
- * msg received message
- * msglen length of message
- * key tsig key used for verifying.
- * querysig (response), the signature in the query
- * querysiglen (response), the length of the signature in the query
- * sig (query), a buffer to hold the signature
- * siglen (query), input - length of signature buffer
- * output - length of signature
- *
- * Errors:
- * - bad input (-1)
- * - invalid dns message (NS_TSIG_ERROR_FORMERR)
- * - TSIG is not present (NS_TSIG_ERROR_NO_TSIG)
- * - key doesn't match (-ns_r_badkey)
- * - TSIG verification fails with BADKEY (-ns_r_badkey)
- * - TSIG verification fails with BADSIG (-ns_r_badsig)
- * - TSIG verification fails with BADTIME (-ns_r_badtime)
- * - TSIG verification succeeds, error set to BAKEY (ns_r_badkey)
- * - TSIG verification succeeds, error set to BADSIG (ns_r_badsig)
- * - TSIG verification succeeds, error set to BADTIME (ns_r_badtime)
- */
-int
-ns_verify(u_char *msg, int *msglen, void *k,
- const u_char *querysig, int querysiglen, u_char *sig, int *siglen,
- time_t *timesigned, int nostrip)
-{
- HEADER *hp = (HEADER *)msg;
- DST_KEY *key = (DST_KEY *)k;
- u_char *cp = msg, *eom;
- char name[MAXDNAME], alg[MAXDNAME];
- u_char *recstart, *rdatastart;
- u_char *sigstart, *otherstart;
- int n;
- int error;
- u_int16_t type, length;
- u_int16_t fudge, sigfieldlen, id, otherfieldlen;
-
- dst_init();
- if (msg == NULL || msglen == NULL || *msglen < 0)
- return (-1);
-
- eom = msg + *msglen;
-
- recstart = ns_find_tsig(msg, eom);
- if (recstart == NULL)
- return (NS_TSIG_ERROR_NO_TSIG);
-
- cp = recstart;
-
- /* Read the key name. */
- n = dn_expand(msg, eom, cp, name, MAXDNAME);
- if (n < 0)
- return (NS_TSIG_ERROR_FORMERR);
- cp += n;
-
- /* Read the type. */
- BOUNDS_CHECK(cp, 2*INT16SZ + INT32SZ + INT16SZ);
- GETSHORT(type, cp);
- if (type != ns_t_tsig)
- return (NS_TSIG_ERROR_NO_TSIG);
-
- /* Skip the class and TTL, save the length. */
- cp += INT16SZ + INT32SZ;
- GETSHORT(length, cp);
- if (eom - cp != length)
- return (NS_TSIG_ERROR_FORMERR);
-
- /* Read the algorithm name. */
- rdatastart = cp;
- n = dn_expand(msg, eom, cp, alg, MAXDNAME);
- if (n < 0)
- return (NS_TSIG_ERROR_FORMERR);
- if (ns_samename(alg, NS_TSIG_ALG_HMAC_MD5) != 1)
- return (-ns_r_badkey);
- cp += n;
-
- /* Read the time signed and fudge. */
- BOUNDS_CHECK(cp, INT16SZ + INT32SZ + INT16SZ);
- cp += INT16SZ;
- GETLONG((*timesigned), cp);
- GETSHORT(fudge, cp);
-
- /* Read the signature. */
- BOUNDS_CHECK(cp, INT16SZ);
- GETSHORT(sigfieldlen, cp);
- BOUNDS_CHECK(cp, sigfieldlen);
- sigstart = cp;
- cp += sigfieldlen;
-
- /* Read the original id and error. */
- BOUNDS_CHECK(cp, 2*INT16SZ);
- GETSHORT(id, cp);
- GETSHORT(error, cp);
-
- /* Parse the other data. */
- BOUNDS_CHECK(cp, INT16SZ);
- GETSHORT(otherfieldlen, cp);
- BOUNDS_CHECK(cp, otherfieldlen);
- otherstart = cp;
- cp += otherfieldlen;
-
- if (cp != eom)
- return (NS_TSIG_ERROR_FORMERR);
-
- /* Verify that the key used is OK. */
- if (key != NULL) {
- if (key->dk_alg != KEY_HMAC_MD5)
- return (-ns_r_badkey);
- if (error != ns_r_badsig && error != ns_r_badkey) {
- if (ns_samename(key->dk_key_name, name) != 1)
- return (-ns_r_badkey);
- }
- }
-
- hp->arcount = htons(ntohs(hp->arcount) - 1);
-
- /*
- * Do the verification.
- */
-
- if (key != NULL && error != ns_r_badsig && error != ns_r_badkey) {
- void *ctx;
- u_char buf[MAXDNAME];
- u_char buf2[MAXDNAME];
-
- /* Digest the query signature, if this is a response. */
- dst_verify_data(SIG_MODE_INIT, key, &ctx, NULL, 0, NULL, 0);
- if (querysiglen > 0 && querysig != NULL) {
- u_int16_t len_n = htons(querysiglen);
- dst_verify_data(SIG_MODE_UPDATE, key, &ctx,
- (u_char *)&len_n, INT16SZ, NULL, 0);
- dst_verify_data(SIG_MODE_UPDATE, key, &ctx,
- querysig, querysiglen, NULL, 0);
- }
-
- /* Digest the message. */
- dst_verify_data(SIG_MODE_UPDATE, key, &ctx, msg, recstart - msg,
- NULL, 0);
-
- /* Digest the key name. */
- n = ns_name_pton(name, buf2, sizeof(buf2));
- if (n < 0)
- return (-1);
- n = ns_name_ntol(buf2, buf, sizeof(buf));
- if (n < 0)
- return (-1);
- dst_verify_data(SIG_MODE_UPDATE, key, &ctx, buf, n, NULL, 0);
-
- /* Digest the class and TTL. */
- dst_verify_data(SIG_MODE_UPDATE, key, &ctx,
- recstart + dn_skipname(recstart, eom) + INT16SZ,
- INT16SZ + INT32SZ, NULL, 0);
-
- /* Digest the algorithm. */
- n = ns_name_pton(alg, buf2, sizeof(buf2));
- if (n < 0)
- return (-1);
- n = ns_name_ntol(buf2, buf, sizeof(buf));
- if (n < 0)
- return (-1);
- dst_verify_data(SIG_MODE_UPDATE, key, &ctx, buf, n, NULL, 0);
-
- /* Digest the time signed and fudge. */
- dst_verify_data(SIG_MODE_UPDATE, key, &ctx,
- rdatastart + dn_skipname(rdatastart, eom),
- INT16SZ + INT32SZ + INT16SZ, NULL, 0);
-
- /* Digest the error and other data. */
- dst_verify_data(SIG_MODE_UPDATE, key, &ctx,
- otherstart - INT16SZ - INT16SZ,
- otherfieldlen + INT16SZ + INT16SZ, NULL, 0);
-
- n = dst_verify_data(SIG_MODE_FINAL, key, &ctx, NULL, 0,
- sigstart, sigfieldlen);
-
- if (n < 0)
- return (-ns_r_badsig);
-
- if (sig != NULL && siglen != NULL) {
- if (*siglen < sigfieldlen)
- return (NS_TSIG_ERROR_NO_SPACE);
- memcpy(sig, sigstart, sigfieldlen);
- *siglen = sigfieldlen;
- }
- } else {
- if (sigfieldlen > 0)
- return (NS_TSIG_ERROR_FORMERR);
- if (sig != NULL && siglen != NULL)
- *siglen = 0;
- }
-
- /* Reset the counter, since we still need to check for badtime. */
- hp->arcount = htons(ntohs(hp->arcount) + 1);
-
- /* Verify the time. */
- if (abs((*timesigned) - time(NULL)) > fudge)
- return (-ns_r_badtime);
-
- if (nostrip == 0) {
- *msglen = recstart - msg;
- hp->arcount = htons(ntohs(hp->arcount) - 1);
- }
-
- if (error != NOERROR)
- return (error);
-
- return (0);
-}
-
-int
-ns_verify_tcp_init(void *k, const u_char *querysig, int querysiglen,
- ns_tcp_tsig_state *state)
-{
- dst_init();
- if (state == NULL || k == NULL || querysig == NULL || querysiglen < 0)
- return (-1);
- state->counter = -1;
- state->key = k;
- if (state->key->dk_alg != KEY_HMAC_MD5)
- return (-ns_r_badkey);
- if (querysiglen > (int)sizeof(state->sig))
- return (-1);
- memcpy(state->sig, querysig, querysiglen);
- state->siglen = querysiglen;
- return (0);
-}
-
-int
-ns_verify_tcp(u_char *msg, int *msglen, ns_tcp_tsig_state *state,
- int required)
-{
- HEADER *hp = (HEADER *)msg;
- u_char *recstart, *rdatastart, *sigstart;
- unsigned int sigfieldlen, otherfieldlen;
- u_char *cp, *eom = msg + *msglen, *cp2;
- char name[MAXDNAME], alg[MAXDNAME];
- u_char buf[MAXDNAME];
- int n, type, length, fudge, id, error;
- time_t timesigned;
-
- if (msg == NULL || msglen == NULL || state == NULL)
- return (-1);
-
- state->counter++;
- if (state->counter == 0)
- return (ns_verify(msg, msglen, state->key,
- state->sig, state->siglen,
- state->sig, &state->siglen, &timesigned, 0));
-
- if (state->siglen > 0) {
- u_int16_t siglen_n = htons(state->siglen);
-
- dst_verify_data(SIG_MODE_INIT, state->key, &state->ctx,
- NULL, 0, NULL, 0);
- dst_verify_data(SIG_MODE_UPDATE, state->key, &state->ctx,
- (u_char *)&siglen_n, INT16SZ, NULL, 0);
- dst_verify_data(SIG_MODE_UPDATE, state->key, &state->ctx,
- state->sig, state->siglen, NULL, 0);
- state->siglen = 0;
- }
-
- cp = recstart = ns_find_tsig(msg, eom);
-
- if (recstart == NULL) {
- if (required)
- return (NS_TSIG_ERROR_NO_TSIG);
- dst_verify_data(SIG_MODE_UPDATE, state->key, &state->ctx,
- msg, *msglen, NULL, 0);
- return (0);
- }
-
- hp->arcount = htons(ntohs(hp->arcount) - 1);
- dst_verify_data(SIG_MODE_UPDATE, state->key, &state->ctx,
- msg, recstart - msg, NULL, 0);
-
- /* Read the key name. */
- n = dn_expand(msg, eom, cp, name, MAXDNAME);
- if (n < 0)
- return (NS_TSIG_ERROR_FORMERR);
- cp += n;
-
- /* Read the type. */
- BOUNDS_CHECK(cp, 2*INT16SZ + INT32SZ + INT16SZ);
- GETSHORT(type, cp);
- if (type != ns_t_tsig)
- return (NS_TSIG_ERROR_NO_TSIG);
-
- /* Skip the class and TTL, save the length. */
- cp += INT16SZ + INT32SZ;
- GETSHORT(length, cp);
- if (eom - cp != length)
- return (NS_TSIG_ERROR_FORMERR);
-
- /* Read the algorithm name. */
- rdatastart = cp;
- n = dn_expand(msg, eom, cp, alg, MAXDNAME);
- if (n < 0)
- return (NS_TSIG_ERROR_FORMERR);
- if (ns_samename(alg, NS_TSIG_ALG_HMAC_MD5) != 1)
- return (-ns_r_badkey);
- cp += n;
-
- /* Verify that the key used is OK. */
- if ((ns_samename(state->key->dk_key_name, name) != 1 ||
- state->key->dk_alg != KEY_HMAC_MD5))
- return (-ns_r_badkey);
-
- /* Read the time signed and fudge. */
- BOUNDS_CHECK(cp, INT16SZ + INT32SZ + INT16SZ);
- cp += INT16SZ;
- GETLONG(timesigned, cp);
- GETSHORT(fudge, cp);
-
- /* Read the signature. */
- BOUNDS_CHECK(cp, INT16SZ);
- GETSHORT(sigfieldlen, cp);
- BOUNDS_CHECK(cp, sigfieldlen);
- sigstart = cp;
- cp += sigfieldlen;
-
- /* Read the original id and error. */
- BOUNDS_CHECK(cp, 2*INT16SZ);
- GETSHORT(id, cp);
- GETSHORT(error, cp);
-
- /* Parse the other data. */
- BOUNDS_CHECK(cp, INT16SZ);
- GETSHORT(otherfieldlen, cp);
- BOUNDS_CHECK(cp, otherfieldlen);
- cp += otherfieldlen;
-
- if (cp != eom)
- return (NS_TSIG_ERROR_FORMERR);
-
- /*
- * Do the verification.
- */
-
- /* Digest the time signed and fudge. */
- cp2 = buf;
- PUTSHORT(0, cp2); /* Top 16 bits of time. */
- PUTLONG(timesigned, cp2);
- PUTSHORT(NS_TSIG_FUDGE, cp2);
-
- dst_verify_data(SIG_MODE_UPDATE, state->key, &state->ctx,
- buf, cp2 - buf, NULL, 0);
-
- n = dst_verify_data(SIG_MODE_FINAL, state->key, &state->ctx, NULL, 0,
- sigstart, sigfieldlen);
- if (n < 0)
- return (-ns_r_badsig);
-
- if (sigfieldlen > sizeof(state->sig))
- return (NS_TSIG_ERROR_NO_SPACE);
-
- memcpy(state->sig, sigstart, sigfieldlen);
- state->siglen = sigfieldlen;
-
- /* Verify the time. */
- if (abs(timesigned - time(NULL)) > fudge)
- return (-ns_r_badtime);
-
- *msglen = recstart - msg;
-
- if (error != NOERROR)
- return (error);
-
- return (0);
-}
diff --git a/contrib/bind/lib/resolv/Makefile b/contrib/bind/lib/resolv/Makefile
deleted file mode 100644
index 3f98a20..0000000
--- a/contrib/bind/lib/resolv/Makefile
+++ /dev/null
@@ -1,95 +0,0 @@
-# Copyright (c) 1996,1999 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.
-
-# $Id: Makefile,v 8.36 2001/08/14 05:58:11 marka Exp $
-
-# these are only appropriate for BSD 4.4 or derivatives, and are used in
-# development. normal builds will be done in the top level directory and
-# this Makefile will be invoked with a lot of overrides for the following:
-SYSTYPE= freebsd
-DESTDIR =
-DESTLIB = /usr/local/lib
-O=o
-A=a
-CC= cc
-LD= ld
-SHELL= /bin/sh
-CDEBUG= -g -Wall
-TOP= ../..
-INCL = ${TOP}/include
-PORTINCL = ${TOP}/port/${SYSTYPE}/include
-LIBBIND = ${TOP}/lib/libbind.${A}
-LIBBINDR = ../${TOP}/lib/libbind_r.${A}
-CFLAGS= ${CDEBUG}
-CPPFLAGS= -I${PORTINCL} -I${INCL}
-# -D__BIND_NOSTATIC
-LD_LIBFLAGS= -x -r
-AR= ar cru
-RANLIB= ranlib
-INSTALL= install
-INSTALL_EXEC=
-INSTALL_LIB=-o bin -g bin
-THREADED= threaded
-
-SRCS= herror.c res_debug.c res_data.c res_comp.c res_init.c \
- res_mkquery.c res_query.c res_send.c res_sendsigned.c \
- res_mkupdate.c res_update.c \
- res_findzonecut.c
-
-OBJS= herror.${O} res_debug.${O} res_data.${O} res_comp.${O} res_init.${O} \
- res_mkquery.${O} res_query.${O} res_send.${O} res_sendsigned.${O} \
- res_mkupdate.${O} res_update.${O} \
- res_findzonecut.${O}
-
-all: ${LIBBIND}
-
-${LIBBIND}: ${OBJS}
- ( cd ${THREADED} ; \
- ${AR} ${LIBBINDR} ${ARPREF} ${OBJS} ${ARSUFF} ; \
- ${RANLIB} ${LIBBINDR} )
- ${AR} ${LIBBIND} ${ARPREF} ${OBJS} ${ARSUFF}
- ${RANLIB} ${LIBBIND}
-
-.c.${O}:
- mkdir ${THREADED} 2> /dev/null || test -d ${THREADED} -a -w ${THREADED}
- ${CC} ${CPPFLAGS} ${CFLAGS} ${BOUNDS} ${REENTRANT} -c $*.c \
- -o ${THREADED}/$*.${O}
- -${LDS} ${LD} ${LD_LIBFLAGS} ${THREADED}/$*.${O} \
- -o ${THREADED}/$*.out && \
- ${LDS} mv ${THREADED}/$*.out ${THREADED}/$*.${O}
- ${CC} ${CPPFLAGS} ${CFLAGS} ${BOUNDS} -c $*.c
- -${LDS} ${LD} ${LD_LIBFLAGS} $*.${O} -o $*.out && \
- ${LDS} mv $*.out $*.${O}
-
-distclean: clean
-
-clean: FRC
- rm -f .depend a.out core ${LIB} tags
- rm -f *.${O} *.BAK *.CKP *~
- rm -f ${THREADED}/*.${O}
- -if test -d ${THREADED} ; then rmdir ${THREADED}; else true; fi
-
-depend: FRC
- mkdep -I${INCL} -I${PORTINCL} ${CPPFLAGS} ${SRCS}
-
-links: FRC
- @set -e; ln -s SRC/*.[ch] .
-
-install:
-
-FRC:
-
-# DO NOT DELETE THIS LINE -- mkdep uses it.
-# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
diff --git a/contrib/bind/lib/resolv/herror.c b/contrib/bind/lib/resolv/herror.c
deleted file mode 100644
index 8265597..0000000
--- a/contrib/bind/lib/resolv/herror.c
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright (c) 1987, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Portions Copyright (c) 1996-1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char sccsid[] = "@(#)herror.c 8.1 (Berkeley) 6/4/93";
-static const char rcsid[] = "$Id: herror.c,v 8.13 2001/06/18 14:44:06 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/uio.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-
-#include <netdb.h>
-#include <resolv.h>
-#include <string.h>
-#include <unistd.h>
-#include <irs.h>
-
-#include "port_after.h"
-#undef h_errno
-
-const char *h_errlist[] = {
- "Resolver Error 0 (no error)",
- "Unknown host", /* 1 HOST_NOT_FOUND */
- "Host name lookup failure", /* 2 TRY_AGAIN */
- "Unknown server error", /* 3 NO_RECOVERY */
- "No address associated with name", /* 4 NO_ADDRESS */
-};
-int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] };
-
-int h_errno;
-
-/*
- * herror --
- * print the error indicated by the h_errno value.
- */
-void
-herror(const char *s) {
- struct iovec iov[4], *v = iov;
- char *t;
-
- if (s != NULL && *s != '\0') {
- DE_CONST(s, t);
- v->iov_base = t;
- v->iov_len = strlen(t);
- v++;
- DE_CONST(": ", t);
- v->iov_base = t;
- v->iov_len = 2;
- v++;
- }
- DE_CONST(hstrerror(*__h_errno()), t);
- v->iov_base = t;
- v->iov_len = strlen(v->iov_base);
- v++;
- DE_CONST("\n", t);
- v->iov_base = t;
- v->iov_len = 1;
- writev(STDERR_FILENO, iov, (v - iov) + 1);
-}
-
-/*
- * hstrerror --
- * return the string associated with a given "host" errno value.
- */
-const char *
-hstrerror(int err) {
- if (err < 0)
- return ("Resolver internal error");
- else if (err < h_nerr)
- return (h_errlist[err]);
- return ("Unknown resolver error");
-}
diff --git a/contrib/bind/lib/resolv/res_comp.c b/contrib/bind/lib/resolv/res_comp.c
deleted file mode 100644
index 15de91a..0000000
--- a/contrib/bind/lib/resolv/res_comp.c
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * Copyright (c) 1985, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Portions Copyright (c) 1993 by Digital Equipment Corporation.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies, and that
- * the name of Digital Equipment Corporation not be used in advertising or
- * publicity pertaining to distribution of the document or software without
- * specific, written prior permission.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
- * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-/*
- * Portions Copyright (c) 1996-1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93";
-static const char rcsid[] = "$Id: res_comp.c,v 8.16 2002/08/07 03:47:34 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include "port_before.h"
-#include <sys/types.h>
-#include <sys/param.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <ctype.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include "port_after.h"
-
-/*
- * Expand compressed domain name 'src' to full domain name.
- * 'msg' is a pointer to the begining of the message,
- * 'eom' points to the first location after the message,
- * 'dst' is a pointer to a buffer of size 'dstsiz' for the result.
- * Return size of compressed name or -1 if there was an error.
- */
-int
-dn_expand(const u_char *msg, const u_char *eom, const u_char *src,
- char *dst, int dstsiz)
-{
- int n = ns_name_uncompress(msg, eom, src, dst, (size_t)dstsiz);
-
- if (n > 0 && dst[0] == '.')
- dst[0] = '\0';
- return (n);
-}
-
-/*
- * Pack domain name 'exp_dn' in presentation form into 'comp_dn'.
- * Return the size of the compressed name or -1.
- * 'length' is the size of the array pointed to by 'comp_dn'.
- */
-int
-dn_comp(const char *src, u_char *dst, int dstsiz,
- u_char **dnptrs, u_char **lastdnptr)
-{
- return (ns_name_compress(src, dst, (size_t)dstsiz,
- (const u_char **)dnptrs,
- (const u_char **)lastdnptr));
-}
-
-/*
- * Skip over a compressed domain name. Return the size or -1.
- */
-int
-dn_skipname(const u_char *ptr, const u_char *eom) {
- const u_char *saveptr = ptr;
-
- if (ns_name_skip(&ptr, eom) == -1)
- return (-1);
- return (ptr - saveptr);
-}
-
-/*
- * Verify that a domain name uses an acceptable character set.
- */
-
-/*
- * Note the conspicuous absence of ctype macros in these definitions. On
- * non-ASCII hosts, we can't depend on string literals or ctype macros to
- * tell us anything about network-format data. The rest of the BIND system
- * is not careful about this, but for some reason, we're doing it right here.
- */
-#define PERIOD 0x2e
-#define hyphenchar(c) ((c) == 0x2d)
-#define bslashchar(c) ((c) == 0x5c)
-#define periodchar(c) ((c) == PERIOD)
-#define asterchar(c) ((c) == 0x2a)
-#define alphachar(c) (((c) >= 0x41 && (c) <= 0x5a) \
- || ((c) >= 0x61 && (c) <= 0x7a))
-#define digitchar(c) ((c) >= 0x30 && (c) <= 0x39)
-
-#define borderchar(c) (alphachar(c) || digitchar(c))
-#define middlechar(c) (borderchar(c) || hyphenchar(c))
-#define domainchar(c) ((c) > 0x20 && (c) < 0x7f)
-
-int
-res_hnok(const char *dn) {
- int ppch = '\0', pch = PERIOD, ch = *dn++;
-
- while (ch != '\0') {
- int nch = *dn++;
-
- if (periodchar(ch)) {
- (void)NULL;
- } else if (periodchar(pch)) {
- if (!borderchar(ch))
- return (0);
- } else if (periodchar(nch) || nch == '\0') {
- if (!borderchar(ch))
- return (0);
- } else {
- if (!middlechar(ch))
- return (0);
- }
- ppch = pch, pch = ch, ch = nch;
- }
- return (1);
-}
-
-/*
- * hostname-like (A, MX, WKS) owners can have "*" as their first label
- * but must otherwise be as a host name.
- */
-int
-res_ownok(const char *dn) {
- if (asterchar(dn[0])) {
- if (periodchar(dn[1]))
- return (res_hnok(dn+2));
- if (dn[1] == '\0')
- return (1);
- }
- return (res_hnok(dn));
-}
-
-/*
- * SOA RNAMEs and RP RNAMEs can have any printable character in their first
- * label, but the rest of the name has to look like a host name.
- */
-int
-res_mailok(const char *dn) {
- int ch, escaped = 0;
-
- /* "." is a valid missing representation */
- if (*dn == '\0')
- return (1);
-
- /* otherwise <label>.<hostname> */
- while ((ch = *dn++) != '\0') {
- if (!domainchar(ch))
- return (0);
- if (!escaped && periodchar(ch))
- break;
- if (escaped)
- escaped = 0;
- else if (bslashchar(ch))
- escaped = 1;
- }
- if (periodchar(ch))
- return (res_hnok(dn));
- return (0);
-}
-
-/*
- * This function is quite liberal, since RFC 1034's character sets are only
- * recommendations.
- */
-int
-res_dnok(const char *dn) {
- int ch;
-
- while ((ch = *dn++) != '\0')
- if (!domainchar(ch))
- return (0);
- return (1);
-}
-
-#ifdef BIND_4_COMPAT
-/*
- * This module must export the following externally-visible symbols:
- * ___putlong
- * ___putshort
- * __getlong
- * __getshort
- * Note that one _ comes from C and the others come from us.
- */
-void __putlong(u_int32_t src, u_char *dst) { ns_put32(src, dst); }
-void __putshort(u_int16_t src, u_char *dst) { ns_put16(src, dst); }
-#ifndef __ultrix__
-u_int32_t _getlong(const u_char *src) { return (ns_get32(src)); }
-u_int16_t _getshort(const u_char *src) { return (ns_get16(src)); }
-#endif /*__ultrix__*/
-#endif /*BIND_4_COMPAT*/
diff --git a/contrib/bind/lib/resolv/res_data.c b/contrib/bind/lib/resolv/res_data.c
deleted file mode 100644
index 559e860..0000000
--- a/contrib/bind/lib/resolv/res_data.c
+++ /dev/null
@@ -1,291 +0,0 @@
-/*
- * Copyright (c) 1995-1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: res_data.c,v 8.18 2000/12/23 08:14:58 vixie Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#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 <ctype.h>
-#include <netdb.h>
-#include <resolv.h>
-#include <res_update.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "port_after.h"
-#undef _res
-
-const char *_res_opcodes[] = {
- "QUERY",
- "IQUERY",
- "CQUERYM",
- "CQUERYU", /* experimental */
- "NOTIFY", /* experimental */
- "UPDATE",
- "6",
- "7",
- "8",
- "9",
- "10",
- "11",
- "12",
- "13",
- "ZONEINIT",
- "ZONEREF",
-};
-
-#ifdef BIND_UPDATE
-const char *_res_sectioncodes[] = {
- "ZONE",
- "PREREQUISITES",
- "UPDATE",
- "ADDITIONAL",
-};
-#endif
-
-#ifndef __BIND_NOSTATIC
-struct __res_state _res
-# if defined(__BIND_RES_TEXT)
- = { RES_TIMEOUT, } /* Motorola, et al. */
-# endif
- ;
-
-/* Proto. */
-
-int res_ourserver_p(const res_state, const struct sockaddr_in *);
-
-int
-res_init(void) {
- extern int __res_vinit(res_state, int);
-
- /*
- * These three fields used to be statically initialized. This made
- * it hard to use this code in a shared library. It is necessary,
- * now that we're doing dynamic initialization here, that we preserve
- * the old semantics: if an application modifies one of these three
- * fields of _res before res_init() is called, res_init() will not
- * alter them. Of course, if an application is setting them to
- * _zero_ before calling res_init(), hoping to override what used
- * to be the static default, we can't detect it and unexpected results
- * will follow. Zero for any of these fields would make no sense,
- * so one can safely assume that the applications were already getting
- * unexpected results.
- *
- * _res.options is tricky since some apps were known to diddle the bits
- * before res_init() was first called. We can't replicate that semantic
- * with dynamic initialization (they may have turned bits off that are
- * set in RES_DEFAULT). Our solution is to declare such applications
- * "broken". They could fool us by setting RES_INIT but none do (yet).
- */
- if (!_res.retrans)
- _res.retrans = RES_TIMEOUT;
- if (!_res.retry)
- _res.retry = 4;
- if (!(_res.options & RES_INIT))
- _res.options = RES_DEFAULT;
-
- /*
- * This one used to initialize implicitly to zero, so unless the app
- * has set it to something in particular, we can randomize it now.
- */
- if (!_res.id)
- _res.id = res_randomid();
-
- return (__res_vinit(&_res, 1));
-}
-
-void
-p_query(const u_char *msg) {
- fp_query(msg, stdout);
-}
-
-void
-fp_query(const u_char *msg, FILE *file) {
- fp_nquery(msg, PACKETSZ, file);
-}
-
-void
-fp_nquery(const u_char *msg, int len, FILE *file) {
- if ((_res.options & RES_INIT) == 0 && res_init() == -1)
- return;
-
- res_pquery(&_res, msg, len, file);
-}
-
-int
-res_mkquery(int op, /* opcode of query */
- const char *dname, /* domain name */
- int class, int type, /* class and type of query */
- const u_char *data, /* resource record data */
- int datalen, /* length of data */
- const u_char *newrr_in, /* new rr for modify or append */
- u_char *buf, /* buffer to put query */
- int buflen) /* size of buffer */
-{
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
- RES_SET_H_ERRNO(&_res, NETDB_INTERNAL);
- return (-1);
- }
- return (res_nmkquery(&_res, op, dname, class, type,
- data, datalen,
- newrr_in, buf, buflen));
-}
-
-int
-res_mkupdate(ns_updrec *rrecp_in, u_char *buf, int buflen) {
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
- RES_SET_H_ERRNO(&_res, NETDB_INTERNAL);
- return (-1);
- }
-
- return (res_nmkupdate(&_res, rrecp_in, buf, buflen));
-}
-
-int
-res_query(const char *name, /* domain name */
- int class, int type, /* class and type of query */
- u_char *answer, /* buffer to put answer */
- int anslen) /* size of answer buffer */
-{
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
- RES_SET_H_ERRNO(&_res, NETDB_INTERNAL);
- return (-1);
- }
- return (res_nquery(&_res, name, class, type, answer, anslen));
-}
-
-void
-res_send_setqhook(res_send_qhook hook) {
- _res.qhook = hook;
-}
-
-void
-res_send_setrhook(res_send_rhook hook) {
- _res.rhook = hook;
-}
-
-int
-res_isourserver(const struct sockaddr_in *inp) {
- return (res_ourserver_p(&_res, inp));
-}
-
-int
-res_send(const u_char *buf, int buflen, u_char *ans, int anssiz) {
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
- /* errno should have been set by res_init() in this case. */
- return (-1);
- }
-
- return (res_nsend(&_res, buf, buflen, ans, anssiz));
-}
-
-int
-res_sendsigned(const u_char *buf, int buflen, ns_tsig_key *key,
- u_char *ans, int anssiz)
-{
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
- /* errno should have been set by res_init() in this case. */
- return (-1);
- }
-
- return (res_nsendsigned(&_res, buf, buflen, key, ans, anssiz));
-}
-
-void
-res_close(void) {
- res_nclose(&_res);
-}
-
-int
-res_update(ns_updrec *rrecp_in) {
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
- RES_SET_H_ERRNO(&_res, NETDB_INTERNAL);
- return (-1);
- }
-
- return (res_nupdate(&_res, rrecp_in, NULL));
-}
-
-int
-res_search(const char *name, /* domain name */
- int class, int type, /* class and type of query */
- u_char *answer, /* buffer to put answer */
- int anslen) /* size of answer */
-{
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
- RES_SET_H_ERRNO(&_res, NETDB_INTERNAL);
- return (-1);
- }
-
- return (res_nsearch(&_res, name, class, type, answer, anslen));
-}
-
-int
-res_querydomain(const char *name,
- const char *domain,
- int class, int type, /* class and type of query */
- u_char *answer, /* buffer to put answer */
- int anslen) /* size of answer */
-{
- if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
- RES_SET_H_ERRNO(&_res, NETDB_INTERNAL);
- return (-1);
- }
-
- return (res_nquerydomain(&_res, name, domain,
- class, type,
- answer, anslen));
-}
-
-const char *
-hostalias(const char *name) {
- static char abuf[MAXDNAME];
-
- return (res_hostalias(&_res, name, abuf, sizeof abuf));
-}
-
-#ifdef ultrix
-int
-local_hostname_length(const char *hostname) {
- int len_host, len_domain;
-
- if (!*_res.defdname)
- res_init();
- len_host = strlen(hostname);
- len_domain = strlen(_res.defdname);
- if (len_host > len_domain &&
- !strcasecmp(hostname + len_host - len_domain, _res.defdname) &&
- hostname[len_host - len_domain - 1] == '.')
- return (len_host - len_domain - 1);
- return (0);
-}
-#endif /*ultrix*/
-
-#endif
diff --git a/contrib/bind/lib/resolv/res_debug.c b/contrib/bind/lib/resolv/res_debug.c
deleted file mode 100644
index 392796a..0000000
--- a/contrib/bind/lib/resolv/res_debug.c
+++ /dev/null
@@ -1,1159 +0,0 @@
-/*
- * Copyright (c) 1985
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Portions Copyright (c) 1993 by Digital Equipment Corporation.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies, and that
- * the name of Digital Equipment Corporation not be used in advertising or
- * publicity pertaining to distribution of the document or software without
- * specific, written prior permission.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
- * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-/*
- * Portions Copyright (c) 1995 by International Business Machines, Inc.
- *
- * International Business Machines, Inc. (hereinafter called IBM) grants
- * permission under its copyrights to use, copy, modify, and distribute this
- * Software with or without fee, provided that the above copyright notice and
- * all paragraphs of this notice appear in all copies, and that the name of IBM
- * not be used in connection with the marketing of any product incorporating
- * the Software or modifications thereof, without specific, written prior
- * permission.
- *
- * To the extent it has a right to do so, IBM grants an immunity from suit
- * under its patents, if any, for the use, sale or manufacture of products to
- * the extent that such products are used for performing Domain Name System
- * dynamic updates in TCP/IP networks by means of the Software. No immunity is
- * granted for any product per se or for any other function of any product.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
- * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
- * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
- */
-
-/*
- * Portions Copyright (c) 1996-1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93";
-static const char rcsid[] = "$Id: res_debug.c,v 8.49.6.1 2003/06/04 01:09:43 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <math.h>
-#include <netdb.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-
-#include "port_after.h"
-
-#ifdef SPRINTF_CHAR
-# define SPRINTF(x) strlen(sprintf/**/x)
-#else
-# define SPRINTF(x) sprintf x
-#endif
-
-extern const char *_res_opcodes[];
-extern const char *_res_sectioncodes[];
-
-/*
- * Print the current options.
- */
-void
-fp_resstat(const res_state statp, FILE *file) {
- u_long mask;
-
- fprintf(file, ";; res options:");
- for (mask = 1; mask != 0; mask <<= 1)
- if (statp->options & mask)
- fprintf(file, " %s", p_option(mask));
- putc('\n', file);
-}
-
-static void
-do_section(const res_state statp,
- ns_msg *handle, ns_sect section,
- int pflag, FILE *file)
-{
- int n, sflag, rrnum;
- static int buflen = 2048;
- char *buf;
- ns_opcode opcode;
- ns_rr rr;
-
- /*
- * Print answer records.
- */
- sflag = (statp->pfcode & pflag);
- if (statp->pfcode && !sflag)
- return;
-
- buf = malloc(buflen);
- if (buf == NULL) {
- fprintf(file, ";; memory allocation failure\n");
- return;
- }
-
- opcode = (ns_opcode) ns_msg_getflag(*handle, ns_f_opcode);
- rrnum = 0;
- for (;;) {
- if (ns_parserr(handle, section, rrnum, &rr)) {
- if (errno != ENODEV)
- fprintf(file, ";; ns_parserr: %s\n",
- strerror(errno));
- else if (rrnum > 0 && sflag != 0 &&
- (statp->pfcode & RES_PRF_HEAD1))
- putc('\n', file);
- goto cleanup;
- }
- if (rrnum == 0 && sflag != 0 && (statp->pfcode & RES_PRF_HEAD1))
- fprintf(file, ";; %s SECTION:\n",
- p_section(section, opcode));
- if (section == ns_s_qd)
- fprintf(file, ";;\t%s, type = %s, class = %s\n",
- ns_rr_name(rr),
- p_type(ns_rr_type(rr)),
- p_class(ns_rr_class(rr)));
- else if (section == ns_s_ar && ns_rr_type(rr) == ns_t_opt) {
- u_int32_t ttl = ns_rr_ttl(rr);
- fprintf(file,
- "; EDNS: version: %u, udp=%u, flags=%04x\n",
- (ttl>>16)&0xff, ns_rr_class(rr), ttl&0xffff);
- } else {
- n = ns_sprintrr(handle, &rr, NULL, NULL,
- buf, buflen);
- if (n < 0) {
- if (errno == ENOSPC) {
- free(buf);
- buf = NULL;
- if (buflen < 131072)
- buf = malloc(buflen += 1024);
- if (buf == NULL) {
- fprintf(file,
- ";; memory allocation failure\n");
- return;
- }
- continue;
- }
- fprintf(file, ";; ns_sprintrr: %s\n",
- strerror(errno));
- goto cleanup;
- }
- fputs(buf, file);
- fputc('\n', file);
- }
- rrnum++;
- }
- cleanup:
- if (buf != NULL)
- free(buf);
-}
-
-/*
- * Print the contents of a query.
- * This is intended to be primarily a debugging routine.
- */
-void
-res_pquery(const res_state statp, const u_char *msg, int len, FILE *file) {
- ns_msg handle;
- int qdcount, ancount, nscount, arcount;
- u_int opcode, rcode, id;
-
- if (ns_initparse(msg, len, &handle) < 0) {
- fprintf(file, ";; ns_initparse: %s\n", strerror(errno));
- return;
- }
- opcode = ns_msg_getflag(handle, ns_f_opcode);
- rcode = ns_msg_getflag(handle, ns_f_rcode);
- id = ns_msg_id(handle);
- qdcount = ns_msg_count(handle, ns_s_qd);
- ancount = ns_msg_count(handle, ns_s_an);
- nscount = ns_msg_count(handle, ns_s_ns);
- arcount = ns_msg_count(handle, ns_s_ar);
-
- /*
- * Print header fields.
- */
- if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEADX) || rcode)
- fprintf(file,
- ";; ->>HEADER<<- opcode: %s, status: %s, id: %d\n",
- _res_opcodes[opcode], p_rcode(rcode), id);
- if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEADX))
- putc(';', file);
- if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEAD2)) {
- fprintf(file, "; flags:");
- if (ns_msg_getflag(handle, ns_f_qr))
- fprintf(file, " qr");
- if (ns_msg_getflag(handle, ns_f_aa))
- fprintf(file, " aa");
- if (ns_msg_getflag(handle, ns_f_tc))
- fprintf(file, " tc");
- if (ns_msg_getflag(handle, ns_f_rd))
- fprintf(file, " rd");
- if (ns_msg_getflag(handle, ns_f_ra))
- fprintf(file, " ra");
- if (ns_msg_getflag(handle, ns_f_z))
- fprintf(file, " ??");
- if (ns_msg_getflag(handle, ns_f_ad))
- fprintf(file, " ad");
- if (ns_msg_getflag(handle, ns_f_cd))
- fprintf(file, " cd");
- }
- if ((!statp->pfcode) || (statp->pfcode & RES_PRF_HEAD1)) {
- fprintf(file, "; %s: %d",
- p_section(ns_s_qd, opcode), qdcount);
- fprintf(file, ", %s: %d",
- p_section(ns_s_an, opcode), ancount);
- fprintf(file, ", %s: %d",
- p_section(ns_s_ns, opcode), nscount);
- fprintf(file, ", %s: %d",
- p_section(ns_s_ar, opcode), arcount);
- }
- if ((!statp->pfcode) || (statp->pfcode &
- (RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) {
- putc('\n',file);
- }
- /*
- * Print the various sections.
- */
- do_section(statp, &handle, ns_s_qd, RES_PRF_QUES, file);
- do_section(statp, &handle, ns_s_an, RES_PRF_ANS, file);
- do_section(statp, &handle, ns_s_ns, RES_PRF_AUTH, file);
- do_section(statp, &handle, ns_s_ar, RES_PRF_ADD, file);
- if (qdcount == 0 && ancount == 0 &&
- nscount == 0 && arcount == 0)
- putc('\n', file);
-}
-
-const u_char *
-p_cdnname(const u_char *cp, const u_char *msg, int len, FILE *file) {
- char name[MAXDNAME];
- int n;
-
- if ((n = dn_expand(msg, msg + len, cp, name, sizeof name)) < 0)
- return (NULL);
- if (name[0] == '\0')
- putc('.', file);
- else
- fputs(name, file);
- return (cp + n);
-}
-
-const u_char *
-p_cdname(const u_char *cp, const u_char *msg, FILE *file) {
- return (p_cdnname(cp, msg, PACKETSZ, file));
-}
-
-/* Return a fully-qualified domain name from a compressed name (with
- length supplied). */
-
-const u_char *
-p_fqnname(cp, msg, msglen, name, namelen)
- const u_char *cp, *msg;
- int msglen;
- char *name;
- int namelen;
-{
- int n, newlen;
-
- if ((n = dn_expand(msg, cp + msglen, cp, name, namelen)) < 0)
- return (NULL);
- newlen = strlen(name);
- if (newlen == 0 || name[newlen - 1] != '.') {
- if (newlen + 1 >= namelen) /* Lack space for final dot */
- return (NULL);
- else
- strcpy(name + newlen, ".");
- }
- return (cp + n);
-}
-
-/* XXX: the rest of these functions need to become length-limited, too. */
-
-const u_char *
-p_fqname(const u_char *cp, const u_char *msg, FILE *file) {
- char name[MAXDNAME];
- const u_char *n;
-
- n = p_fqnname(cp, msg, MAXCDNAME, name, sizeof name);
- if (n == NULL)
- return (NULL);
- fputs(name, file);
- return (n);
-}
-
-/*
- * Names of RR classes and qclasses. Classes and qclasses are the same, except
- * that C_ANY is a qclass but not a class. (You can ask for records of class
- * C_ANY, but you can't have any records of that class in the database.)
- */
-const struct res_sym __p_class_syms[] = {
- {C_IN, "IN", (char *)0},
- {C_CHAOS, "CHAOS", (char *)0},
- {C_HS, "HS", (char *)0},
- {C_HS, "HESIOD", (char *)0},
- {C_ANY, "ANY", (char *)0},
- {C_NONE, "NONE", (char *)0},
- {C_IN, (char *)0, (char *)0}
-};
-
-/*
- * Names of message sections.
- */
-const struct res_sym __p_default_section_syms[] = {
- {ns_s_qd, "QUERY", (char *)0},
- {ns_s_an, "ANSWER", (char *)0},
- {ns_s_ns, "AUTHORITY", (char *)0},
- {ns_s_ar, "ADDITIONAL", (char *)0},
- {0, (char *)0, (char *)0}
-};
-
-const struct res_sym __p_update_section_syms[] = {
- {S_ZONE, "ZONE", (char *)0},
- {S_PREREQ, "PREREQUISITE", (char *)0},
- {S_UPDATE, "UPDATE", (char *)0},
- {S_ADDT, "ADDITIONAL", (char *)0},
- {0, (char *)0, (char *)0}
-};
-
-const struct res_sym __p_key_syms[] = {
- {NS_ALG_MD5RSA, "RSA", "RSA KEY with MD5 hash"},
- {NS_ALG_DH, "DH", "Diffie Hellman"},
- {NS_ALG_DSA, "DSA", "Digital Signature Algorithm"},
- {NS_ALG_EXPIRE_ONLY, "EXPIREONLY", "No algorithm"},
- {NS_ALG_PRIVATE_OID, "PRIVATE", "Algorithm obtained from OID"},
- {0, NULL, NULL}
-};
-
-const struct res_sym __p_cert_syms[] = {
- {cert_t_pkix, "PKIX", "PKIX (X.509v3) Certificate"},
- {cert_t_spki, "SPKI", "SPKI certificate"},
- {cert_t_pgp, "PGP", "PGP certificate"},
- {cert_t_url, "URL", "URL Private"},
- {cert_t_oid, "OID", "OID Private"},
- {0, NULL, NULL}
-};
-
-/*
- * Names of RR types and qtypes. Types and qtypes are the same, except
- * that T_ANY is a qtype but not a type. (You can ask for records of type
- * T_ANY, but you can't have any records of that type in the database.)
- */
-const struct res_sym __p_type_syms[] = {
- {ns_t_a, "A", "address"},
- {ns_t_ns, "NS", "name server"},
- {ns_t_md, "MD", "mail destination (deprecated)"},
- {ns_t_mf, "MF", "mail forwarder (deprecated)"},
- {ns_t_cname, "CNAME", "canonical name"},
- {ns_t_soa, "SOA", "start of authority"},
- {ns_t_mb, "MB", "mailbox"},
- {ns_t_mg, "MG", "mail group member"},
- {ns_t_mr, "MR", "mail rename"},
- {ns_t_null, "NULL", "null"},
- {ns_t_wks, "WKS", "well-known service (deprecated)"},
- {ns_t_ptr, "PTR", "domain name pointer"},
- {ns_t_hinfo, "HINFO", "host information"},
- {ns_t_minfo, "MINFO", "mailbox information"},
- {ns_t_mx, "MX", "mail exchanger"},
- {ns_t_txt, "TXT", "text"},
- {ns_t_rp, "RP", "responsible person"},
- {ns_t_afsdb, "AFSDB", "DCE or AFS server"},
- {ns_t_x25, "X25", "X25 address"},
- {ns_t_isdn, "ISDN", "ISDN address"},
- {ns_t_rt, "RT", "router"},
- {ns_t_nsap, "NSAP", "nsap address"},
- {ns_t_nsap_ptr, "NSAP_PTR", "domain name pointer"},
- {ns_t_sig, "SIG", "signature"},
- {ns_t_key, "KEY", "key"},
- {ns_t_px, "PX", "mapping information"},
- {ns_t_gpos, "GPOS", "geographical position (withdrawn)"},
- {ns_t_aaaa, "AAAA", "IPv6 address"},
- {ns_t_loc, "LOC", "location"},
- {ns_t_nxt, "NXT", "next valid name (unimplemented)"},
- {ns_t_eid, "EID", "endpoint identifier (unimplemented)"},
- {ns_t_nimloc, "NIMLOC", "NIMROD locator (unimplemented)"},
- {ns_t_srv, "SRV", "server selection"},
- {ns_t_atma, "ATMA", "ATM address (unimplemented)"},
- {ns_t_tkey, "TKEY", "tkey"},
- {ns_t_tsig, "TSIG", "transaction signature"},
- {ns_t_ixfr, "IXFR", "incremental zone transfer"},
- {ns_t_axfr, "AXFR", "zone transfer"},
- {ns_t_zxfr, "ZXFR", "compressed zone transfer"},
- {ns_t_mailb, "MAILB", "mailbox-related data (deprecated)"},
- {ns_t_maila, "MAILA", "mail agent (deprecated)"},
- {ns_t_naptr, "NAPTR", "URN Naming Authority"},
- {ns_t_kx, "KX", "Key Exchange"},
- {ns_t_cert, "CERT", "Certificate"},
- {ns_t_a6, "A6", "IPv6 Address"},
- {ns_t_dname, "DNAME", "dname"},
- {ns_t_sink, "SINK", "Kitchen Sink (experimental)"},
- {ns_t_opt, "OPT", "EDNS Options"},
- {ns_t_any, "ANY", "\"any\""},
- {0, NULL, NULL}
-};
-
-/*
- * Names of DNS rcodes.
- */
-const struct res_sym __p_rcode_syms[] = {
- {ns_r_noerror, "NOERROR", "no error"},
- {ns_r_formerr, "FORMERR", "format error"},
- {ns_r_servfail, "SERVFAIL", "server failed"},
- {ns_r_nxdomain, "NXDOMAIN", "no such domain name"},
- {ns_r_notimpl, "NOTIMP", "not implemented"},
- {ns_r_refused, "REFUSED", "refused"},
- {ns_r_yxdomain, "YXDOMAIN", "domain name exists"},
- {ns_r_yxrrset, "YXRRSET", "rrset exists"},
- {ns_r_nxrrset, "NXRRSET", "rrset doesn't exist"},
- {ns_r_notauth, "NOTAUTH", "not authoritative"},
- {ns_r_notzone, "NOTZONE", "Not in zone"},
- {ns_r_max, "", ""},
- {ns_r_badsig, "BADSIG", "bad signature"},
- {ns_r_badkey, "BADKEY", "bad key"},
- {ns_r_badtime, "BADTIME", "bad time"},
- {0, NULL, NULL}
-};
-
-int
-sym_ston(const struct res_sym *syms, const char *name, int *success) {
- for ((void)NULL; syms->name != 0; syms++) {
- if (strcasecmp (name, syms->name) == 0) {
- if (success)
- *success = 1;
- return (syms->number);
- }
- }
- if (success)
- *success = 0;
- return (syms->number); /* The default value. */
-}
-
-const char *
-sym_ntos(const struct res_sym *syms, int number, int *success) {
- static char unname[20];
-
- for ((void)NULL; syms->name != 0; syms++) {
- if (number == syms->number) {
- if (success)
- *success = 1;
- return (syms->name);
- }
- }
-
- sprintf(unname, "%d", number); /* XXX nonreentrant */
- if (success)
- *success = 0;
- return (unname);
-}
-
-const char *
-sym_ntop(const struct res_sym *syms, int number, int *success) {
- static char unname[20];
-
- for ((void)NULL; syms->name != 0; syms++) {
- if (number == syms->number) {
- if (success)
- *success = 1;
- return (syms->humanname);
- }
- }
- sprintf(unname, "%d", number); /* XXX nonreentrant */
- if (success)
- *success = 0;
- return (unname);
-}
-
-/*
- * Return a string for the type.
- */
-const char *
-p_type(int type) {
- int success;
- const char *result;
- static char typebuf[20];
-
- result = sym_ntos(__p_type_syms, type, &success);
- if (success)
- return (result);
- if (type < 0 || type > 0xfff)
- return ("BADTYPE");
- sprintf(typebuf, "TYPE%d", type);
- return (typebuf);
-}
-
-/*
- * Return a string for the type.
- */
-const char *
-p_section(int section, int opcode) {
- const struct res_sym *symbols;
-
- switch (opcode) {
- case ns_o_update:
- symbols = __p_update_section_syms;
- break;
- default:
- symbols = __p_default_section_syms;
- break;
- }
- return (sym_ntos(symbols, section, (int *)0));
-}
-
-/*
- * Return a mnemonic for class.
- */
-const char *
-p_class(int class) {
- int success;
- const char *result;
- static char classbuf[20];
-
- result = sym_ntos(__p_class_syms, class, &success);
- if (success)
- return (result);
- if (class < 0 || class > 0xfff)
- return ("BADCLASS");
- sprintf(classbuf, "CLASS%d", class);
- return (classbuf);
-}
-
-/*
- * Return a mnemonic for an option
- */
-const char *
-p_option(u_long option) {
- static char nbuf[40];
-
- switch (option) {
- case RES_INIT: return "init";
- case RES_DEBUG: return "debug";
- case RES_AAONLY: return "aaonly(unimpl)";
- case RES_USEVC: return "usevc";
- case RES_PRIMARY: return "primry(unimpl)";
- case RES_IGNTC: return "igntc";
- case RES_RECURSE: return "recurs";
- case RES_DEFNAMES: return "defnam";
- case RES_STAYOPEN: return "styopn";
- case RES_DNSRCH: return "dnsrch";
- case RES_INSECURE1: return "insecure1";
- case RES_INSECURE2: return "insecure2";
- case RES_NOALIASES: return "noaliases";
- case RES_USE_INET6: return "inet6";
-#ifdef RES_USE_EDNS0 /* KAME extension */
- case RES_USE_EDNS0: return "edns0";
-#endif
-#ifdef RES_USE_DNAME
- case RES_USE_DNAME: return "dname";
-#endif
-#ifdef RES_USE_DNSSEC
- case RES_USE_DNSSEC: return "dnssec";
-#endif
-#ifdef RES_NOTLDQUERY
- case RES_NOTLDQUERY: return "no-tld-query";
-#endif
-
- /* XXX nonreentrant */
- default: sprintf(nbuf, "?0x%lx?", (u_long)option);
- return (nbuf);
- }
-}
-
-/*
- * Return a mnemonic for a time to live.
- */
-const char *
-p_time(u_int32_t value) {
- static char nbuf[40]; /* XXX nonreentrant */
-
- if (ns_format_ttl(value, nbuf, sizeof nbuf) < 0)
- sprintf(nbuf, "%u", value);
- return (nbuf);
-}
-
-/*
- * Return a string for the rcode.
- */
-const char *
-p_rcode(int rcode) {
- return (sym_ntos(__p_rcode_syms, rcode, (int *)0));
-}
-
-/*
- * Return a string for a res_sockaddr_union.
- */
-const char *
-p_sockun(union res_sockaddr_union u, char *buf, size_t size) {
- char ret[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:123.123.123.123"];
-
- switch (u.sin.sin_family) {
- case AF_INET:
- inet_ntop(AF_INET, &u.sin.sin_addr, ret, sizeof ret);
- break;
-#ifdef HAS_INET6_STRUCTS
- case AF_INET6:
- inet_ntop(AF_INET6, &u.sin6.sin6_addr, ret, sizeof ret);
- break;
-#endif
- default:
- sprintf(ret, "[af%d]", u.sin.sin_family);
- break;
- }
- if (size > 0) {
- strncpy(buf, ret, size - 1);
- buf[size - 1] = '0';
- }
- return (buf);
-}
-
-/*
- * routines to convert between on-the-wire RR format and zone file format.
- * Does not contain conversion to/from decimal degrees; divide or multiply
- * by 60*60*1000 for that.
- */
-
-static unsigned int poweroften[10] = {1, 10, 100, 1000, 10000, 100000,
- 1000000,10000000,100000000,1000000000};
-
-/* takes an XeY precision/size value, returns a string representation. */
-static const char *
-precsize_ntoa(prec)
- u_int8_t prec;
-{
- static char retbuf[sizeof "90000000.00"]; /* XXX nonreentrant */
- unsigned long val;
- int mantissa, exponent;
-
- mantissa = (int)((prec >> 4) & 0x0f) % 10;
- exponent = (int)((prec >> 0) & 0x0f) % 10;
-
- val = mantissa * poweroften[exponent];
-
- (void) sprintf(retbuf, "%lu.%.2lu", val/100, val%100);
- return (retbuf);
-}
-
-/* converts ascii size/precision X * 10**Y(cm) to 0xXY. moves pointer. */
-static u_int8_t
-precsize_aton(const char **strptr) {
- unsigned int mval = 0, cmval = 0;
- u_int8_t retval = 0;
- const char *cp;
- int exponent;
- int mantissa;
-
- cp = *strptr;
-
- while (isdigit((unsigned char)*cp))
- mval = mval * 10 + (*cp++ - '0');
-
- if (*cp == '.') { /* centimeters */
- cp++;
- if (isdigit((unsigned char)*cp)) {
- cmval = (*cp++ - '0') * 10;
- if (isdigit((unsigned char)*cp)) {
- cmval += (*cp++ - '0');
- }
- }
- }
- cmval = (mval * 100) + cmval;
-
- for (exponent = 0; exponent < 9; exponent++)
- if (cmval < poweroften[exponent+1])
- break;
-
- mantissa = cmval / poweroften[exponent];
- if (mantissa > 9)
- mantissa = 9;
-
- retval = (mantissa << 4) | exponent;
-
- *strptr = cp;
-
- return (retval);
-}
-
-/* converts ascii lat/lon to unsigned encoded 32-bit number. moves pointer. */
-static u_int32_t
-latlon2ul(const char **latlonstrptr, int *which) {
- const char *cp;
- u_int32_t retval;
- int deg = 0, min = 0, secs = 0, secsfrac = 0;
-
- cp = *latlonstrptr;
-
- while (isdigit((unsigned char)*cp))
- deg = deg * 10 + (*cp++ - '0');
-
- while (isspace((unsigned char)*cp))
- cp++;
-
- if (!(isdigit((unsigned char)*cp)))
- goto fndhemi;
-
- while (isdigit((unsigned char)*cp))
- min = min * 10 + (*cp++ - '0');
-
- while (isspace((unsigned char)*cp))
- cp++;
-
- if (!(isdigit((unsigned char)*cp)))
- goto fndhemi;
-
- while (isdigit((unsigned char)*cp))
- secs = secs * 10 + (*cp++ - '0');
-
- if (*cp == '.') { /* decimal seconds */
- cp++;
- if (isdigit((unsigned char)*cp)) {
- secsfrac = (*cp++ - '0') * 100;
- if (isdigit((unsigned char)*cp)) {
- secsfrac += (*cp++ - '0') * 10;
- if (isdigit((unsigned char)*cp)) {
- secsfrac += (*cp++ - '0');
- }
- }
- }
- }
-
- while (!isspace((unsigned char)*cp)) /* if any trailing garbage */
- cp++;
-
- while (isspace((unsigned char)*cp))
- cp++;
-
- fndhemi:
- switch (*cp) {
- case 'N': case 'n':
- case 'E': case 'e':
- retval = ((unsigned)1<<31)
- + (((((deg * 60) + min) * 60) + secs) * 1000)
- + secsfrac;
- break;
- case 'S': case 's':
- case 'W': case 'w':
- retval = ((unsigned)1<<31)
- - (((((deg * 60) + min) * 60) + secs) * 1000)
- - secsfrac;
- break;
- default:
- retval = 0; /* invalid value -- indicates error */
- break;
- }
-
- switch (*cp) {
- case 'N': case 'n':
- case 'S': case 's':
- *which = 1; /* latitude */
- break;
- case 'E': case 'e':
- case 'W': case 'w':
- *which = 2; /* longitude */
- break;
- default:
- *which = 0; /* error */
- break;
- }
-
- cp++; /* skip the hemisphere */
-
- while (!isspace((unsigned char)*cp)) /* if any trailing garbage */
- cp++;
-
- while (isspace((unsigned char)*cp)) /* move to next field */
- cp++;
-
- *latlonstrptr = cp;
-
- return (retval);
-}
-
-/* converts a zone file representation in a string to an RDATA on-the-wire
- * representation. */
-int
-loc_aton(ascii, binary)
- const char *ascii;
- u_char *binary;
-{
- const char *cp, *maxcp;
- u_char *bcp;
-
- u_int32_t latit = 0, longit = 0, alt = 0;
- u_int32_t lltemp1 = 0, lltemp2 = 0;
- int altmeters = 0, altfrac = 0, altsign = 1;
- u_int8_t hp = 0x16; /* default = 1e6 cm = 10000.00m = 10km */
- u_int8_t vp = 0x13; /* default = 1e3 cm = 10.00m */
- u_int8_t siz = 0x12; /* default = 1e2 cm = 1.00m */
- int which1 = 0, which2 = 0;
-
- cp = ascii;
- maxcp = cp + strlen(ascii);
-
- lltemp1 = latlon2ul(&cp, &which1);
-
- lltemp2 = latlon2ul(&cp, &which2);
-
- switch (which1 + which2) {
- case 3: /* 1 + 2, the only valid combination */
- if ((which1 == 1) && (which2 == 2)) { /* normal case */
- latit = lltemp1;
- longit = lltemp2;
- } else if ((which1 == 2) && (which2 == 1)) { /* reversed */
- longit = lltemp1;
- latit = lltemp2;
- } else { /* some kind of brokenness */
- return (0);
- }
- break;
- default: /* we didn't get one of each */
- return (0);
- }
-
- /* altitude */
- if (*cp == '-') {
- altsign = -1;
- cp++;
- }
-
- if (*cp == '+')
- cp++;
-
- while (isdigit((unsigned char)*cp))
- altmeters = altmeters * 10 + (*cp++ - '0');
-
- if (*cp == '.') { /* decimal meters */
- cp++;
- if (isdigit((unsigned char)*cp)) {
- altfrac = (*cp++ - '0') * 10;
- if (isdigit((unsigned char)*cp)) {
- altfrac += (*cp++ - '0');
- }
- }
- }
-
- alt = (10000000 + (altsign * (altmeters * 100 + altfrac)));
-
- while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */
- cp++;
-
- while (isspace((unsigned char)*cp) && (cp < maxcp))
- cp++;
-
- if (cp >= maxcp)
- goto defaults;
-
- siz = precsize_aton(&cp);
-
- while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */
- cp++;
-
- while (isspace((unsigned char)*cp) && (cp < maxcp))
- cp++;
-
- if (cp >= maxcp)
- goto defaults;
-
- hp = precsize_aton(&cp);
-
- while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */
- cp++;
-
- while (isspace((unsigned char)*cp) && (cp < maxcp))
- cp++;
-
- if (cp >= maxcp)
- goto defaults;
-
- vp = precsize_aton(&cp);
-
- defaults:
-
- bcp = binary;
- *bcp++ = (u_int8_t) 0; /* version byte */
- *bcp++ = siz;
- *bcp++ = hp;
- *bcp++ = vp;
- PUTLONG(latit,bcp);
- PUTLONG(longit,bcp);
- PUTLONG(alt,bcp);
-
- return (16); /* size of RR in octets */
-}
-
-/* takes an on-the-wire LOC RR and formats it in a human readable format. */
-const char *
-loc_ntoa(binary, ascii)
- const u_char *binary;
- char *ascii;
-{
- static const char *error = "?";
- static char tmpbuf[sizeof
-"1000 60 60.000 N 1000 60 60.000 W -12345678.00m 90000000.00m 90000000.00m 90000000.00m"];
- const u_char *cp = binary;
-
- int latdeg, latmin, latsec, latsecfrac;
- int longdeg, longmin, longsec, longsecfrac;
- char northsouth, eastwest;
- const char *altsign;
- int altmeters, altfrac;
-
- const u_int32_t referencealt = 100000 * 100;
-
- int32_t latval, longval, altval;
- u_int32_t templ;
- u_int8_t sizeval, hpval, vpval, versionval;
-
- char *sizestr, *hpstr, *vpstr;
-
- versionval = *cp++;
-
- if (ascii == NULL)
- ascii = tmpbuf;
-
- if (versionval) {
- (void) sprintf(ascii, "; error: unknown LOC RR version");
- return (ascii);
- }
-
- sizeval = *cp++;
-
- hpval = *cp++;
- vpval = *cp++;
-
- GETLONG(templ, cp);
- latval = (templ - ((unsigned)1<<31));
-
- GETLONG(templ, cp);
- longval = (templ - ((unsigned)1<<31));
-
- GETLONG(templ, cp);
- if (templ < referencealt) { /* below WGS 84 spheroid */
- altval = referencealt - templ;
- altsign = "-";
- } else {
- altval = templ - referencealt;
- altsign = "";
- }
-
- if (latval < 0) {
- northsouth = 'S';
- latval = -latval;
- } else
- northsouth = 'N';
-
- latsecfrac = latval % 1000;
- latval = latval / 1000;
- latsec = latval % 60;
- latval = latval / 60;
- latmin = latval % 60;
- latval = latval / 60;
- latdeg = latval;
-
- if (longval < 0) {
- eastwest = 'W';
- longval = -longval;
- } else
- eastwest = 'E';
-
- longsecfrac = longval % 1000;
- longval = longval / 1000;
- longsec = longval % 60;
- longval = longval / 60;
- longmin = longval % 60;
- longval = longval / 60;
- longdeg = longval;
-
- altfrac = altval % 100;
- altmeters = (altval / 100);
-
- sizestr = strdup(precsize_ntoa(sizeval));
- hpstr = strdup(precsize_ntoa(hpval));
- vpstr = strdup(precsize_ntoa(vpval));
-
- sprintf(ascii,
- "%d %.2d %.2d.%.3d %c %d %.2d %.2d.%.3d %c %s%d.%.2dm %sm %sm %sm",
- latdeg, latmin, latsec, latsecfrac, northsouth,
- longdeg, longmin, longsec, longsecfrac, eastwest,
- altsign, altmeters, altfrac,
- (sizestr != NULL) ? sizestr : error,
- (hpstr != NULL) ? hpstr : error,
- (vpstr != NULL) ? vpstr : error);
-
- if (sizestr != NULL)
- free(sizestr);
- if (hpstr != NULL)
- free(hpstr);
- if (vpstr != NULL)
- free(vpstr);
-
- return (ascii);
-}
-
-
-/* Return the number of DNS hierarchy levels in the name. */
-int
-dn_count_labels(const char *name) {
- int i, len, count;
-
- len = strlen(name);
- for (i = 0, count = 0; i < len; i++) {
- /* XXX need to check for \. or use named's nlabels(). */
- if (name[i] == '.')
- count++;
- }
-
- /* don't count initial wildcard */
- if (name[0] == '*')
- if (count)
- count--;
-
- /* don't count the null label for root. */
- /* if terminating '.' not found, must adjust */
- /* count to include last label */
- if (len > 0 && name[len-1] != '.')
- count++;
- return (count);
-}
-
-
-/*
- * Make dates expressed in seconds-since-Jan-1-1970 easy to read.
- * SIG records are required to be printed like this, by the Secure DNS RFC.
- */
-char *
-p_secstodate (u_long secs) {
- /* XXX nonreentrant */
- static char output[15]; /* YYYYMMDDHHMMSS and null */
- time_t clock = secs;
- struct tm *time;
-
-#ifdef HAVE_TIME_R
- gmtime_r(&clock, &time);
-#else
- time = gmtime(&clock);
-#endif
- time->tm_year += 1900;
- time->tm_mon += 1;
- sprintf(output, "%04d%02d%02d%02d%02d%02d",
- time->tm_year, time->tm_mon, time->tm_mday,
- time->tm_hour, time->tm_min, time->tm_sec);
- return (output);
-}
-
-u_int16_t
-res_nametoclass(const char *buf, int *successp) {
- unsigned long result;
- char *endptr;
- int success;
-
- result = sym_ston(__p_class_syms, buf, &success);
- if (success)
- goto done;
-
- if (strncasecmp(buf, "CLASS", 5) != 0 ||
- !isdigit((unsigned char)buf[5]))
- goto done;
- errno = 0;
- result = strtoul(buf + 5, &endptr, 10);
- if (errno == 0 && *endptr == '\0' && result <= 0xffff)
- success = 1;
- done:
- if (successp)
- *successp = success;
- return (result);
-}
-
-u_int16_t
-res_nametotype(const char *buf, int *successp) {
- unsigned long result;
- char *endptr;
- int success;
-
- result = sym_ston(__p_type_syms, buf, &success);
- if (success)
- goto done;
-
- if (strncasecmp(buf, "type", 4) != 0 ||
- !isdigit((unsigned char)buf[4]))
- goto done;
- errno = 0;
- result = strtoul(buf + 4, &endptr, 10);
- if (errno == 0 && *endptr == '\0' && result <= 0xffff)
- success = 1;
- done:
- if (successp)
- *successp = success;
- return (result);
-}
diff --git a/contrib/bind/lib/resolv/res_debug.h b/contrib/bind/lib/resolv/res_debug.h
deleted file mode 100644
index 4a0aa99..0000000
--- a/contrib/bind/lib/resolv/res_debug.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) 1999 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.
- */
-
-#ifndef _RES_DEBUG_H_
-#define _RES_DEBUG_H_
-
-#ifndef DEBUG
-# define Dprint(cond, args) /*empty*/
-# define DprintQ(cond, args, query, size) /*empty*/
-# define Aerror(statp, file, string, error, address) /*empty*/
-# define Perror(statp, file, string, error) /*empty*/
-#else
-# define Dprint(cond, args) if (cond) {fprintf args;} else {}
-# define DprintQ(cond, args, query, size) if (cond) {\
- fprintf args;\
- res_pquery(statp, query, size, stdout);\
- } else {}
-#endif
-
-#endif /* _RES_DEBUG_H_ */
diff --git a/contrib/bind/lib/resolv/res_findzonecut.c b/contrib/bind/lib/resolv/res_findzonecut.c
deleted file mode 100644
index 018ec4d..0000000
--- a/contrib/bind/lib/resolv/res_findzonecut.c
+++ /dev/null
@@ -1,722 +0,0 @@
-#if !defined(lint) && !defined(SABER)
-static const char rcsid[] = "$Id: res_findzonecut.c,v 8.17.6.2 2003/06/02 09:24:40 marka Exp $";
-#endif /* not lint */
-
-/*
- * Copyright (c) 1999 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.
- */
-
-/* Import. */
-
-#include "port_before.h"
-
-#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 <errno.h>
-#include <limits.h>
-#include <netdb.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <isc/list.h>
-
-#include "port_after.h"
-
-#include <resolv.h>
-
-/* Data structures. */
-
-typedef struct rr_a {
- LINK(struct rr_a) link;
- union res_sockaddr_union addr;
-} rr_a;
-typedef LIST(rr_a) rrset_a;
-
-typedef struct rr_ns {
- LINK(struct rr_ns) link;
- const char * name;
- unsigned int flags;
- rrset_a addrs;
-} rr_ns;
-typedef LIST(rr_ns) rrset_ns;
-
-#define RR_NS_HAVE_V4 0x01
-#define RR_NS_HAVE_V6 0x02
-
-/* Forward. */
-
-static int satisfy(res_state, const char *, rrset_ns *,
- union res_sockaddr_union *, int);
-static int add_addrs(res_state, rr_ns *,
- union res_sockaddr_union *, int);
-static int get_soa(res_state, const char *, ns_class, int,
- char *, size_t, char *, size_t,
- rrset_ns *);
-static int get_ns(res_state, const char *, ns_class, int, rrset_ns *);
-static int get_glue(res_state, ns_class, int, rrset_ns *);
-static int save_ns(res_state, ns_msg *, ns_sect,
- const char *, ns_class, int, rrset_ns *);
-static int save_a(res_state, ns_msg *, ns_sect,
- const char *, ns_class, int, rr_ns *);
-static void free_nsrrset(rrset_ns *);
-static void free_nsrr(rrset_ns *, rr_ns *);
-static rr_ns * find_ns(rrset_ns *, const char *);
-static int do_query(res_state, const char *, ns_class, ns_type,
- u_char *, ns_msg *);
-static void res_dprintf(const char *, ...) ISC_FORMAT_PRINTF(1, 2);
-
-/* Macros. */
-
-#define DPRINTF(x) do {\
- int save_errno = errno; \
- if ((statp->options & RES_DEBUG) != 0) res_dprintf x; \
- errno = save_errno; \
- } while (0)
-
-/* Public. */
-
-/*
- * int
- * res_findzonecut(res, dname, class, zname, zsize, addrs, naddrs)
- * find enclosing zone for a <dname,class>, and some server addresses
- * parameters:
- * res - resolver context to work within (is modified)
- * dname - domain name whose enclosing zone is desired
- * class - class of dname (and its enclosing zone)
- * zname - found zone name
- * zsize - allocated size of zname
- * addrs - found server addresses
- * naddrs - max number of addrs
- * return values:
- * < 0 - an error occurred (check errno)
- * = 0 - zname is now valid, but addrs[] wasn't changed
- * > 0 - zname is now valid, and return value is number of addrs[] found
- * notes:
- * this function calls res_nsend() which means it depends on correctly
- * functioning recursive nameservers (usually defined in /etc/resolv.conf
- * or its local equivilent).
- *
- * we start by asking for an SOA<dname,class>. if we get one as an
- * answer, that just means <dname,class> is a zone top, which is fine.
- * more than likely we'll be told to go pound sand, in the form of a
- * negative answer.
- *
- * note that we are not prepared to deal with referrals since that would
- * only come from authority servers and our correctly functioning local
- * recursive server would have followed the referral and got us something
- * more definite.
- *
- * if the authority section contains an SOA, this SOA should also be the
- * closest enclosing zone, since any intermediary zone cuts would've been
- * returned as referrals and dealt with by our correctly functioning local
- * recursive name server. but an SOA in the authority section should NOT
- * match our dname (since that would have been returned in the answer
- * section). an authority section SOA has to be "above" our dname.
- *
- * however, since authority section SOA's were once optional, it's
- * possible that we'll have to go hunting for the enclosing SOA by
- * ripping labels off the front of our dname -- this is known as "doing
- * it the hard way."
- *
- * ultimately we want some server addresses, which are ideally the ones
- * pertaining to the SOA.MNAME, but only if there is a matching NS RR.
- * so the second phase (after we find an SOA) is to go looking for the
- * NS RRset for that SOA's zone.
- *
- * no answer section processed by this code is allowed to contain CNAME
- * or DNAME RR's. for the SOA query this means we strip a label and
- * keep going. for the NS and A queries this means we just give up.
- */
-
-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)
-{
- int result, i;
- union res_sockaddr_union *u;
-
-
- opts |= RES_IPV4ONLY;
- opts &= ~RES_IPV6ONLY;
-
- u = calloc(naddrs, sizeof(*u));
- if (u == NULL)
- return(-1);
-
- result = res_findzonecut2(statp, dname, class, opts, zname, zsize,
- u, naddrs);
-
- for (i = 0; i < result; i++) {
- addrs[i] = u[i].sin.sin_addr;
- }
- free(u);
- return (result);
-}
-
-int
-res_findzonecut2(res_state statp, const char *dname, ns_class class, int opts,
- char *zname, size_t zsize, union res_sockaddr_union *addrs,
- int naddrs)
-{
- char mname[NS_MAXDNAME];
- u_long save_pfcode;
- rrset_ns nsrrs;
- int n;
-
- DPRINTF(("START dname='%s' class=%s, zsize=%ld, naddrs=%d",
- dname, p_class(class), (long)zsize, naddrs));
- save_pfcode = statp->pfcode;
- statp->pfcode |= RES_PRF_HEAD2 | RES_PRF_HEAD1 | RES_PRF_HEADX |
- RES_PRF_QUES | RES_PRF_ANS |
- RES_PRF_AUTH | RES_PRF_ADD;
- INIT_LIST(nsrrs);
-
- DPRINTF(("get the soa, and see if it has enough glue"));
- if ((n = get_soa(statp, dname, class, opts, zname, zsize,
- mname, sizeof mname, &nsrrs)) < 0 ||
- ((opts & RES_EXHAUSTIVE) == 0 &&
- (n = satisfy(statp, mname, &nsrrs, addrs, naddrs)) > 0))
- goto done;
-
- DPRINTF(("get the ns rrset and see if it has enough glue"));
- if ((n = get_ns(statp, zname, class, opts, &nsrrs)) < 0 ||
- ((opts & RES_EXHAUSTIVE) == 0 &&
- (n = satisfy(statp, mname, &nsrrs, addrs, naddrs)) > 0))
- goto done;
-
- DPRINTF(("get the missing glue and see if it's finally enough"));
- if ((n = get_glue(statp, class, opts, &nsrrs)) >= 0)
- n = satisfy(statp, mname, &nsrrs, addrs, naddrs);
-
- done:
- DPRINTF(("FINISH n=%d (%s)", n, (n < 0) ? strerror(errno) : "OK"));
- free_nsrrset(&nsrrs);
- statp->pfcode = save_pfcode;
- return (n);
-}
-
-/* Private. */
-
-static int
-satisfy(res_state statp, const char *mname, rrset_ns *nsrrsp,
- union res_sockaddr_union *addrs, int naddrs)
-{
- rr_ns *nsrr;
- int n, x;
-
- n = 0;
- nsrr = find_ns(nsrrsp, mname);
- if (nsrr != NULL) {
- x = add_addrs(statp, nsrr, addrs, naddrs);
- addrs += x;
- naddrs -= x;
- n += x;
- }
- for (nsrr = HEAD(*nsrrsp);
- nsrr != NULL && naddrs > 0;
- nsrr = NEXT(nsrr, link))
- if (ns_samename(nsrr->name, mname) != 1) {
- x = add_addrs(statp, nsrr, addrs, naddrs);
- addrs += x;
- naddrs -= x;
- n += x;
- }
- DPRINTF(("satisfy(%s): %d", mname, n));
- return (n);
-}
-
-static int
-add_addrs(res_state statp, rr_ns *nsrr,
- union res_sockaddr_union *addrs, int naddrs)
-{
- rr_a *arr;
- int n = 0;
-
- for (arr = HEAD(nsrr->addrs); arr != NULL; arr = NEXT(arr, link)) {
- if (naddrs <= 0)
- return (0);
- *addrs++ = arr->addr;
- naddrs--;
- n++;
- }
- DPRINTF(("add_addrs: %d", n));
- return (n);
-}
-
-static int
-get_soa(res_state statp, const char *dname, ns_class class, int opts,
- char *zname, size_t zsize, char *mname, size_t msize,
- rrset_ns *nsrrsp)
-{
- char tname[NS_MAXDNAME];
- u_char *resp = NULL;
- int n, i, ancount, nscount;
- ns_sect sect;
- ns_msg msg;
- u_int rcode;
-
- /*
- * Find closest enclosing SOA, even if it's for the root zone.
- */
-
- /* First canonicalize dname (exactly one unescaped trailing "."). */
- if (ns_makecanon(dname, tname, sizeof tname) < 0)
- goto cleanup;
- dname = tname;
-
- resp = malloc(NS_MAXMSG);
- if (resp == NULL)
- goto cleanup;
-
- /* Now grovel the subdomains, hunting for an SOA answer or auth. */
- for (;;) {
- /* Leading or inter-label '.' are skipped here. */
- while (*dname == '.')
- dname++;
-
- /* Is there an SOA? */
- n = do_query(statp, dname, class, ns_t_soa, resp, &msg);
- if (n < 0) {
- DPRINTF(("get_soa: do_query('%s', %s) failed (%d)",
- dname, p_class(class), n));
- goto cleanup;
- }
- if (n > 0) {
- DPRINTF(("get_soa: CNAME or DNAME found"));
- sect = ns_s_max, n = 0;
- } else {
- rcode = ns_msg_getflag(msg, ns_f_rcode);
- ancount = ns_msg_count(msg, ns_s_an);
- nscount = ns_msg_count(msg, ns_s_ns);
- if (ancount > 0 && rcode == ns_r_noerror)
- sect = ns_s_an, n = ancount;
- else if (nscount > 0)
- sect = ns_s_ns, n = nscount;
- else
- sect = ns_s_max, n = 0;
- }
- for (i = 0; i < n; i++) {
- const char *t;
- const u_char *rdata;
- int rdlen;
- ns_rr rr;
-
- if (ns_parserr(&msg, sect, i, &rr) < 0) {
- DPRINTF(("get_soa: ns_parserr(%s, %d) failed",
- p_section(sect, ns_o_query), i));
- goto cleanup;
- }
- if (ns_rr_type(rr) == ns_t_cname ||
- ns_rr_type(rr) == ns_t_dname)
- break;
- if (ns_rr_type(rr) != ns_t_soa ||
- ns_rr_class(rr) != class)
- continue;
- t = ns_rr_name(rr);
- switch (sect) {
- case ns_s_an:
- if (ns_samedomain(dname, t) == 0) {
- DPRINTF(
- ("get_soa: ns_samedomain('%s', '%s') == 0",
- dname, t)
- );
- errno = EPROTOTYPE;
- goto cleanup;
- }
- break;
- case ns_s_ns:
- if (ns_samename(dname, t) == 1 ||
- ns_samedomain(dname, t) == 0) {
- DPRINTF(
- ("get_soa: ns_samename() || !ns_samedomain('%s', '%s')",
- dname, t)
- );
- errno = EPROTOTYPE;
- goto cleanup;
- }
- break;
- default:
- abort();
- }
- if (strlen(t) + 1 > zsize) {
- DPRINTF(("get_soa: zname(%d) too small (%d)",
- zsize, strlen(t) + 1));
- errno = EMSGSIZE;
- goto cleanup;
- }
- strcpy(zname, t);
- rdata = ns_rr_rdata(rr);
- rdlen = ns_rr_rdlen(rr);
- if (ns_name_uncompress(resp, ns_msg_end(msg), rdata,
- mname, msize) < 0) {
- DPRINTF(("get_soa: ns_name_uncompress failed")
- );
- goto cleanup;
- }
- if (save_ns(statp, &msg, ns_s_ns,
- zname, class, opts, nsrrsp) < 0) {
- DPRINTF(("get_soa: save_ns failed"));
- goto cleanup;
- }
- free(resp);
- return (0);
- }
-
- /* If we're out of labels, then not even "." has an SOA! */
- if (*dname == '\0')
- break;
-
- /* Find label-terminating "."; top of loop will skip it. */
- while (*dname != '.') {
- if (*dname == '\\')
- if (*++dname == '\0') {
- errno = EMSGSIZE;
- goto cleanup;
- }
- dname++;
- }
- }
- DPRINTF(("get_soa: out of labels"));
- errno = EDESTADDRREQ;
- cleanup:
- if (resp != NULL)
- free(resp);
- return (-1);
-}
-
-static int
-get_ns(res_state statp, const char *zname, ns_class class, int opts,
- rrset_ns *nsrrsp)
-{
- u_char *resp;
- ns_msg msg;
- int n;
-
- resp = malloc(NS_MAXMSG);
- if (resp == NULL)
- return (-1);
-
- /* Go and get the NS RRs for this zone. */
- n = do_query(statp, zname, class, ns_t_ns, resp, &msg);
- if (n != 0) {
- DPRINTF(("get_ns: do_query('%s', %s) failed (%d)",
- zname, p_class(class), n));
- free(resp);
- return (-1);
- }
-
- /* Remember the NS RRs and associated A RRs that came back. */
- if (save_ns(statp, &msg, ns_s_an, zname, class, opts, nsrrsp) < 0) {
- DPRINTF(("get_ns save_ns('%s', %s) failed",
- zname, p_class(class)));
- free(resp);
- return (-1);
- }
-
- free(resp);
- return (0);
-}
-
-static int
-get_glue(res_state statp, ns_class class, int opts, rrset_ns *nsrrsp) {
- rr_ns *nsrr, *nsrr_n;
- u_char *resp;
-
- resp = malloc(NS_MAXMSG);
- if (resp == NULL)
- return(-1);
-
- /* Go and get the A RRs for each empty NS RR on our list. */
- for (nsrr = HEAD(*nsrrsp); nsrr != NULL; nsrr = nsrr_n) {
- ns_msg msg;
- int n;
-
- nsrr_n = NEXT(nsrr, link);
-
- if ((nsrr->flags & RR_NS_HAVE_V4) == 0) {
- n = do_query(statp, nsrr->name, class, ns_t_a,
- resp, &msg);
- if (n < 0) {
- DPRINTF(
- ("get_glue: do_query('%s', %s') failed",
- nsrr->name, p_class(class)));
- goto cleanup;
- }
- if (n > 0) {
- DPRINTF((
- "get_glue: do_query('%s', %s') CNAME or DNAME found",
- nsrr->name, p_class(class)));
- }
- if (save_a(statp, &msg, ns_s_an, nsrr->name, class,
- opts, nsrr) < 0) {
- DPRINTF(("get_glue: save_r('%s', %s) failed",
- nsrr->name, p_class(class)));
- goto cleanup;
- }
- }
-
- if ((nsrr->flags & RR_NS_HAVE_V6) == 0) {
- n = do_query(statp, nsrr->name, class, ns_t_aaaa,
- resp, &msg);
- if (n < 0) {
- DPRINTF(
- ("get_glue: do_query('%s', %s') failed",
- nsrr->name, p_class(class)));
- goto cleanup;
- }
- if (n > 0) {
- DPRINTF((
- "get_glue: do_query('%s', %s') CNAME or DNAME found",
- nsrr->name, p_class(class)));
- }
- if (save_a(statp, &msg, ns_s_an, nsrr->name, class,
- opts, nsrr) < 0) {
- DPRINTF(("get_glue: save_r('%s', %s) failed",
- nsrr->name, p_class(class)));
- goto cleanup;
- }
- }
-
- /* If it's still empty, it's just chaff. */
- if (EMPTY(nsrr->addrs)) {
- DPRINTF(("get_glue: removing empty '%s' NS",
- nsrr->name));
- free_nsrr(nsrrsp, nsrr);
- }
- }
- free(resp);
- return (0);
-
- cleanup:
- free(resp);
- return (-1);
-}
-
-static int
-save_ns(res_state statp, ns_msg *msg, ns_sect sect,
- const char *owner, ns_class class, int opts,
- rrset_ns *nsrrsp)
-{
- int i;
-
- for (i = 0; i < ns_msg_count(*msg, sect); i++) {
- char tname[MAXDNAME];
- const u_char *rdata;
- rr_ns *nsrr;
- ns_rr rr;
- int rdlen;
-
- if (ns_parserr(msg, sect, i, &rr) < 0) {
- DPRINTF(("save_ns: ns_parserr(%s, %d) failed",
- p_section(sect, ns_o_query), i));
- return (-1);
- }
- if (ns_rr_type(rr) != ns_t_ns ||
- ns_rr_class(rr) != class ||
- ns_samename(ns_rr_name(rr), owner) != 1)
- continue;
- nsrr = find_ns(nsrrsp, ns_rr_name(rr));
- if (nsrr == NULL) {
- nsrr = malloc(sizeof *nsrr);
- if (nsrr == NULL) {
- DPRINTF(("save_ns: malloc failed"));
- return (-1);
- }
- rdata = ns_rr_rdata(rr);
- rdlen = ns_rr_rdlen(rr);
- if (ns_name_uncompress(ns_msg_base(*msg),
- ns_msg_end(*msg), rdata,
- tname, sizeof tname) < 0) {
- DPRINTF(("save_ns: ns_name_uncompress failed")
- );
- free(nsrr);
- return (-1);
- }
- nsrr->name = strdup(tname);
- if (nsrr->name == NULL) {
- DPRINTF(("save_ns: strdup failed"));
- free(nsrr);
- return (-1);
- }
- INIT_LINK(nsrr, link);
- INIT_LIST(nsrr->addrs);
- nsrr->flags = 0;
- APPEND(*nsrrsp, nsrr, link);
- }
- if (save_a(statp, msg, ns_s_ar,
- nsrr->name, class, opts, nsrr) < 0) {
- DPRINTF(("save_ns: save_r('%s', %s) failed",
- nsrr->name, p_class(class)));
- return (-1);
- }
- }
- return (0);
-}
-
-static int
-save_a(res_state statp, ns_msg *msg, ns_sect sect,
- const char *owner, ns_class class, int opts,
- rr_ns *nsrr)
-{
- int i;
-
- for (i = 0; i < ns_msg_count(*msg, sect); i++) {
- ns_rr rr;
- rr_a *arr;
-
- if (ns_parserr(msg, sect, i, &rr) < 0) {
- DPRINTF(("save_a: ns_parserr(%s, %d) failed",
- p_section(sect, ns_o_query), i));
- return (-1);
- }
- if ((ns_rr_type(rr) != ns_t_a &&
- ns_rr_type(rr) != ns_t_aaaa) ||
- ns_rr_class(rr) != class ||
- ns_samename(ns_rr_name(rr), owner) != 1 ||
- ns_rr_rdlen(rr) != NS_INADDRSZ)
- continue;
- if ((opts & RES_IPV6ONLY) != 0 && ns_rr_type(rr) != ns_t_aaaa)
- continue;
- if ((opts & RES_IPV4ONLY) != 0 && ns_rr_type(rr) != ns_t_a)
- continue;
- arr = malloc(sizeof *arr);
- if (arr == NULL) {
- DPRINTF(("save_a: malloc failed"));
- return (-1);
- }
- INIT_LINK(arr, link);
- memset(&arr->addr, 0, sizeof(arr->addr));
- switch (ns_rr_type(rr)) {
- case ns_t_a:
- arr->addr.sin.sin_family = AF_INET;
-#ifdef HAVE_SA_LEN
- arr->addr.sin.sin_len = sizeof(arr->addr.sin);
-#endif
- memcpy(&arr->addr.sin.sin_addr, ns_rr_rdata(rr),
- NS_INADDRSZ);
- arr->addr.sin.sin_port = htons(NAMESERVER_PORT);
- nsrr->flags |= RR_NS_HAVE_V4;
- break;
- case ns_t_aaaa:
- arr->addr.sin6.sin6_family = AF_INET6;
-#ifdef HAVE_SA_LEN
- arr->addr.sin6.sin6_len = sizeof(arr->addr.sin6);
-#endif
- memcpy(&arr->addr.sin6.sin6_addr, ns_rr_rdata(rr), 16);
- arr->addr.sin.sin_port = htons(NAMESERVER_PORT);
- nsrr->flags |= RR_NS_HAVE_V6;
- break;
- default:
- abort();
- }
- APPEND(nsrr->addrs, arr, link);
- }
- return (0);
-}
-
-static void
-free_nsrrset(rrset_ns *nsrrsp) {
- rr_ns *nsrr;
-
- while ((nsrr = HEAD(*nsrrsp)) != NULL)
- free_nsrr(nsrrsp, nsrr);
-}
-
-static void
-free_nsrr(rrset_ns *nsrrsp, rr_ns *nsrr) {
- rr_a *arr;
- char *tmp;
-
- while ((arr = HEAD(nsrr->addrs)) != NULL) {
- UNLINK(nsrr->addrs, arr, link);
- free(arr);
- }
- DE_CONST(nsrr->name, tmp);
- free(tmp);
- UNLINK(*nsrrsp, nsrr, link);
- free(nsrr);
-}
-
-static rr_ns *
-find_ns(rrset_ns *nsrrsp, const char *dname) {
- rr_ns *nsrr;
-
- for (nsrr = HEAD(*nsrrsp); nsrr != NULL; nsrr = NEXT(nsrr, link))
- if (ns_samename(nsrr->name, dname) == 1)
- return (nsrr);
- return (NULL);
-}
-
-static int
-do_query(res_state statp, const char *dname, ns_class class, ns_type qtype,
- u_char *resp, ns_msg *msg)
-{
- u_char req[NS_PACKETSZ];
- int i, n;
-
- n = res_nmkquery(statp, ns_o_query, dname, class, qtype,
- NULL, 0, NULL, req, NS_PACKETSZ);
- if (n < 0) {
- DPRINTF(("do_query: res_nmkquery failed"));
- return (-1);
- }
- n = res_nsend(statp, req, n, resp, NS_MAXMSG);
- if (n < 0) {
- DPRINTF(("do_query: res_nsend failed"));
- return (-1);
- }
- if (n == 0) {
- DPRINTF(("do_query: res_nsend returned 0"));
- errno = EMSGSIZE;
- return (-1);
- }
- if (ns_initparse(resp, n, msg) < 0) {
- DPRINTF(("do_query: ns_initparse failed"));
- return (-1);
- }
- n = 0;
- for (i = 0; i < ns_msg_count(*msg, ns_s_an); i++) {
- ns_rr rr;
-
- if (ns_parserr(msg, ns_s_an, i, &rr) < 0) {
- DPRINTF(("do_query: ns_parserr failed"));
- return (-1);
- }
- n += (ns_rr_class(rr) == class &&
- (ns_rr_type(rr) == ns_t_cname ||
- ns_rr_type(rr) == ns_t_dname));
- }
- return (n);
-}
-
-static void
-res_dprintf(const char *fmt, ...) {
- va_list ap;
-
- va_start(ap, fmt);
- fputs(";; res_findzonecut: ", stderr);
- vfprintf(stderr, fmt, ap);
- fputc('\n', stderr);
- va_end(ap);
-}
diff --git a/contrib/bind/lib/resolv/res_init.c b/contrib/bind/lib/resolv/res_init.c
deleted file mode 100644
index 7e507be..0000000
--- a/contrib/bind/lib/resolv/res_init.c
+++ /dev/null
@@ -1,732 +0,0 @@
-/*
- * Copyright (c) 1985, 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Portions Copyright (c) 1993 by Digital Equipment Corporation.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies, and that
- * the name of Digital Equipment Corporation not be used in advertising or
- * publicity pertaining to distribution of the document or software without
- * specific, written prior permission.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
- * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-/*
- * Portions Copyright (c) 1996-1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93";
-static const char rcsid[] = "$Id: res_init.c,v 8.32 2003/04/03 06:31:10 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#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 <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <netdb.h>
-
-#include "port_after.h"
-
-/* ensure that sockaddr_in6 and IN6ADDR_ANY_INIT are declared / defined */
-#include <resolv.h>
-
-#include "res_private.h"
-
-/* Options. Should all be left alone. */
-#define RESOLVSORT
-#define DEBUG
-
-static void res_setoptions __P((res_state, const char *, const char *));
-
-#ifdef RESOLVSORT
-static const char sort_mask[] = "/&";
-#define ISSORTMASK(ch) (strchr(sort_mask, ch) != NULL)
-static u_int32_t net_mask __P((struct in_addr));
-#endif
-
-#if !defined(isascii) /* XXX - could be a function */
-# define isascii(c) (!(c & 0200))
-#endif
-
-/*
- * Resolver state default settings.
- */
-
-/*
- * Set up default settings. If the configuration file exist, the values
- * there will have precedence. Otherwise, the server address is set to
- * INADDR_ANY and the default domain name comes from the gethostname().
- *
- * An interrim version of this code (BIND 4.9, pre-4.4BSD) used 127.0.0.1
- * rather than INADDR_ANY ("0.0.0.0") as the default name server address
- * since it was noted that INADDR_ANY actually meant ``the first interface
- * you "ifconfig"'d at boot time'' and if this was a SLIP or PPP interface,
- * it had to be "up" in order for you to reach your own name server. It
- * was later decided that since the recommended practice is to always
- * install local static routes through 127.0.0.1 for all your network
- * interfaces, that we could solve this problem without a code change.
- *
- * The configuration file should always be used, since it is the only way
- * to specify a default domain. If you are running a server on your local
- * machine, you should say "nameserver 0.0.0.0" or "nameserver 127.0.0.1"
- * in the configuration file.
- *
- * Return 0 if completes successfully, -1 on error
- */
-int
-res_ninit(res_state statp) {
- extern int __res_vinit(res_state, int);
-
- return (__res_vinit(statp, 0));
-}
-
-/* This function has to be reachable by res_data.c but not publically. */
-int
-__res_vinit(res_state statp, int preinit) {
- register FILE *fp;
- register char *cp, **pp;
- register int n;
- char buf[BUFSIZ];
- int nserv = 0; /* number of nameserver records read from file */
- int haveenv = 0;
- int havesearch = 0;
-#ifdef RESOLVSORT
- int nsort = 0;
- char *net;
-#endif
- int dots;
- union res_sockaddr_union u[2];
-
- if (!preinit) {
- statp->retrans = RES_TIMEOUT;
- statp->retry = RES_DFLRETRY;
- statp->options = RES_DEFAULT;
- statp->id = res_randomid();
- }
-
- if ((statp->options & RES_INIT) != 0)
- res_ndestroy(statp);
-
- memset(u, 0, sizeof(u));
-#ifdef USELOOPBACK
- u[nserv].sin.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1);
-#else
- u[nserv].sin.sin_addr.s_addr = INADDR_ANY;
-#endif
- u[nserv].sin.sin_family = AF_INET;
- u[nserv].sin.sin_port = htons(NAMESERVER_PORT);
-#ifdef HAVE_SA_LEN
- u[nserv].sin.sin_len = sizeof(struct sockaddr_in);
-#endif
- nserv++;
-#ifdef HAS_INET6_STRUCTS
-#ifdef USELOOPBACK
- u[nserv].sin6.sin6_addr = in6addr_loopback;
-#else
- u[nserv].sin6.sin6_addr = in6addr_any;
-#endif
- u[nserv].sin6.sin6_family = AF_INET6;
- u[nserv].sin6.sin6_port = htons(NAMESERVER_PORT);
-#ifdef HAVE_SA_LEN
- u[nserv].sin6.sin6_len = sizeof(struct sockaddr_in6);
-#endif
- nserv++;
-#endif
- statp->nscount = 0;
- statp->ndots = 1;
- statp->pfcode = 0;
- statp->_vcsock = -1;
- statp->_flags = 0;
- statp->qhook = NULL;
- statp->rhook = NULL;
- statp->_u._ext.nscount = 0;
- statp->_u._ext.ext = malloc(sizeof(*statp->_u._ext.ext));
- if (statp->_u._ext.ext != NULL) {
- memset(statp->_u._ext.ext, 0, sizeof(*statp->_u._ext.ext));
- statp->_u._ext.ext->nsaddrs[0].sin = statp->nsaddr;
- strcpy(statp->_u._ext.ext->nsuffix, "ip6.arpa");
- strcpy(statp->_u._ext.ext->nsuffix2, "ip6.int");
- }
-#ifdef RESOLVSORT
- statp->nsort = 0;
-#endif
- res_setservers(statp, u, nserv);
-
- /* Allow user to override the local domain definition */
- if ((cp = getenv("LOCALDOMAIN")) != NULL) {
- (void)strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1);
- statp->defdname[sizeof(statp->defdname) - 1] = '\0';
- haveenv++;
-
- /*
- * Set search list to be blank-separated strings
- * from rest of env value. Permits users of LOCALDOMAIN
- * to still have a search list, and anyone to set the
- * one that they want to use as an individual (even more
- * important now that the rfc1535 stuff restricts searches)
- */
- cp = statp->defdname;
- pp = statp->dnsrch;
- *pp++ = cp;
- for (n = 0; *cp && pp < statp->dnsrch + MAXDNSRCH; cp++) {
- if (*cp == '\n') /* silly backwards compat */
- break;
- else if (*cp == ' ' || *cp == '\t') {
- *cp = 0;
- n = 1;
- } else if (n) {
- *pp++ = cp;
- n = 0;
- havesearch = 1;
- }
- }
- /* null terminate last domain if there are excess */
- while (*cp != '\0' && *cp != ' ' && *cp != '\t' && *cp != '\n')
- cp++;
- *cp = '\0';
- *pp++ = 0;
- }
-
-#define MATCH(line, name) \
- (!strncmp(line, name, sizeof(name) - 1) && \
- (line[sizeof(name) - 1] == ' ' || \
- line[sizeof(name) - 1] == '\t'))
-
- nserv = 0;
- if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) {
- /* read the config file */
- while (fgets(buf, sizeof(buf), fp) != NULL) {
- /* skip comments */
- if (*buf == ';' || *buf == '#')
- continue;
- /* read default domain name */
- if (MATCH(buf, "domain")) {
- if (haveenv) /* skip if have from environ */
- continue;
- cp = buf + sizeof("domain") - 1;
- while (*cp == ' ' || *cp == '\t')
- cp++;
- if ((*cp == '\0') || (*cp == '\n'))
- continue;
- strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1);
- statp->defdname[sizeof(statp->defdname) - 1] = '\0';
- if ((cp = strpbrk(statp->defdname, " \t\n")) != NULL)
- *cp = '\0';
- havesearch = 0;
- continue;
- }
- /* set search list */
- if (MATCH(buf, "search")) {
- if (haveenv) /* skip if have from environ */
- continue;
- cp = buf + sizeof("search") - 1;
- while (*cp == ' ' || *cp == '\t')
- cp++;
- if ((*cp == '\0') || (*cp == '\n'))
- continue;
- strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1);
- statp->defdname[sizeof(statp->defdname) - 1] = '\0';
- if ((cp = strchr(statp->defdname, '\n')) != NULL)
- *cp = '\0';
- /*
- * Set search list to be blank-separated strings
- * on rest of line.
- */
- cp = statp->defdname;
- pp = statp->dnsrch;
- *pp++ = cp;
- for (n = 0; *cp && pp < statp->dnsrch + MAXDNSRCH; cp++) {
- if (*cp == ' ' || *cp == '\t') {
- *cp = 0;
- n = 1;
- } else if (n) {
- *pp++ = cp;
- n = 0;
- }
- }
- /* null terminate last domain if there are excess */
- while (*cp != '\0' && *cp != ' ' && *cp != '\t')
- cp++;
- *cp = '\0';
- *pp++ = 0;
- havesearch = 1;
- continue;
- }
- /* read nameservers to query */
- if (MATCH(buf, "nameserver") && nserv < MAXNS) {
- struct addrinfo hints, *ai;
- char sbuf[NI_MAXSERV];
- const size_t minsiz =
- sizeof(statp->_u._ext.ext->nsaddrs[0]);
-
- cp = buf + sizeof("nameserver") - 1;
- while (*cp == ' ' || *cp == '\t')
- cp++;
- cp[strcspn(cp, ";# \t\n")] = '\0';
- if ((*cp != '\0') && (*cp != '\n')) {
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = PF_UNSPEC;
- hints.ai_socktype = SOCK_DGRAM; /*dummy*/
- hints.ai_flags = AI_NUMERICHOST;
- sprintf(sbuf, "%u", NAMESERVER_PORT);
- if (getaddrinfo(cp, sbuf, &hints, &ai) == 0 &&
- ai->ai_addrlen <= minsiz) {
- if (statp->_u._ext.ext != NULL) {
- memcpy(&statp->_u._ext.ext->nsaddrs[nserv],
- ai->ai_addr, ai->ai_addrlen);
- }
- if (ai->ai_addrlen <=
- sizeof(statp->nsaddr_list[nserv])) {
- memcpy(&statp->nsaddr_list[nserv],
- ai->ai_addr, ai->ai_addrlen);
- } else
- statp->nsaddr_list[nserv].sin_family = 0;
- freeaddrinfo(ai);
- nserv++;
- }
- }
- continue;
- }
-#ifdef RESOLVSORT
- if (MATCH(buf, "sortlist")) {
- struct in_addr a;
-
- cp = buf + sizeof("sortlist") - 1;
- while (nsort < MAXRESOLVSORT) {
- while (*cp == ' ' || *cp == '\t')
- cp++;
- if (*cp == '\0' || *cp == '\n' || *cp == ';')
- break;
- net = cp;
- while (*cp && !ISSORTMASK(*cp) && *cp != ';' &&
- isascii(*cp) && !isspace((unsigned char)*cp))
- cp++;
- n = *cp;
- *cp = 0;
- if (inet_aton(net, &a)) {
- statp->sort_list[nsort].addr = a;
- if (ISSORTMASK(n)) {
- *cp++ = n;
- net = cp;
- while (*cp && *cp != ';' &&
- isascii(*cp) &&
- !isspace((unsigned char)*cp))
- cp++;
- n = *cp;
- *cp = 0;
- if (inet_aton(net, &a)) {
- statp->sort_list[nsort].mask = a.s_addr;
- } else {
- statp->sort_list[nsort].mask =
- net_mask(statp->sort_list[nsort].addr);
- }
- } else {
- statp->sort_list[nsort].mask =
- net_mask(statp->sort_list[nsort].addr);
- }
- nsort++;
- }
- *cp = n;
- }
- continue;
- }
-#endif
- if (MATCH(buf, "options")) {
- res_setoptions(statp, buf + sizeof("options") - 1, "conf");
- continue;
- }
- }
- if (nserv > 1)
- statp->nscount = nserv;
-#ifdef RESOLVSORT
- statp->nsort = nsort;
-#endif
- (void) fclose(fp);
- }
-/*
- * Last chance to get a nameserver. This should not normally
- * be necessary
- */
-#ifdef NO_RESOLV_CONF
- if(nserv == 0)
- nserv = get_nameservers(statp);
-#endif
-
- if (statp->defdname[0] == 0 &&
- gethostname(buf, sizeof(statp->defdname) - 1) == 0 &&
- (cp = strchr(buf, '.')) != NULL)
- strcpy(statp->defdname, cp + 1);
-
- /* find components of local domain that might be searched */
- if (havesearch == 0) {
- pp = statp->dnsrch;
- *pp++ = statp->defdname;
- *pp = NULL;
-
- dots = 0;
- for (cp = statp->defdname; *cp; cp++)
- dots += (*cp == '.');
-
- cp = statp->defdname;
- while (pp < statp->dnsrch + MAXDFLSRCH) {
- if (dots < LOCALDOMAINPARTS)
- break;
- cp = strchr(cp, '.') + 1; /* we know there is one */
- *pp++ = cp;
- dots--;
- }
- *pp = NULL;
-#ifdef DEBUG
- if (statp->options & RES_DEBUG) {
- printf(";; res_init()... default dnsrch list:\n");
- for (pp = statp->dnsrch; *pp; pp++)
- printf(";;\t%s\n", *pp);
- printf(";;\t..END..\n");
- }
-#endif
- }
-
- if ((cp = getenv("RES_OPTIONS")) != NULL)
- res_setoptions(statp, cp, "env");
- statp->options |= RES_INIT;
- return (0);
-}
-
-static void
-res_setoptions(res_state statp, const char *options, const char *source)
-{
- const char *cp = options;
- int i;
- struct __res_state_ext *ext = statp->_u._ext.ext;
-
-#ifdef DEBUG
- if (statp->options & RES_DEBUG)
- printf(";; res_setoptions(\"%s\", \"%s\")...\n",
- options, source);
-#endif
- while (*cp) {
- /* skip leading and inner runs of spaces */
- while (*cp == ' ' || *cp == '\t')
- cp++;
- /* search for and process individual options */
- if (!strncmp(cp, "ndots:", sizeof("ndots:") - 1)) {
- i = atoi(cp + sizeof("ndots:") - 1);
- if (i <= RES_MAXNDOTS)
- statp->ndots = i;
- else
- statp->ndots = RES_MAXNDOTS;
-#ifdef DEBUG
- if (statp->options & RES_DEBUG)
- printf(";;\tndots=%d\n", statp->ndots);
-#endif
- } else if (!strncmp(cp, "timeout:", sizeof("timeout:") - 1)) {
- i = atoi(cp + sizeof("timeout:") - 1);
- if (i <= RES_MAXRETRANS)
- statp->retrans = i;
- else
- statp->retrans = RES_MAXRETRANS;
- } else if (!strncmp(cp, "attempts:", sizeof("attempts:") - 1)){
- i = atoi(cp + sizeof("attempts:") - 1);
- if (i <= RES_MAXRETRY)
- statp->retry = i;
- else
- statp->retry = RES_MAXRETRY;
- } else if (!strncmp(cp, "debug", sizeof("debug") - 1)) {
-#ifdef DEBUG
- if (!(statp->options & RES_DEBUG)) {
- printf(";; res_setoptions(\"%s\", \"%s\")..\n",
- options, source);
- statp->options |= RES_DEBUG;
- }
- printf(";;\tdebug\n");
-#endif
- } else if (!strncmp(cp, "no_tld_query",
- sizeof("no_tld_query") - 1) ||
- !strncmp(cp, "no-tld-query",
- sizeof("no-tld-query") - 1)) {
- statp->options |= RES_NOTLDQUERY;
- } else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) {
- statp->options |= RES_USE_INET6;
- } else if (!strncmp(cp, "rotate", sizeof("rotate") - 1)) {
- statp->options |= RES_ROTATE;
- } else if (!strncmp(cp, "no-check-names",
- sizeof("no-check-names") - 1)) {
- statp->options |= RES_NOCHECKNAME;
- }
-#ifdef RES_USE_EDNS0
- else if (!strncmp(cp, "edns0", sizeof("edns0") - 1)) {
- statp->options |= RES_USE_EDNS0;
- }
-#endif
- else if (!strncmp(cp, "dname", sizeof("dname") - 1)) {
- statp->options |= RES_USE_DNAME;
- }
- else if (!strncmp(cp, "nibble:", sizeof("nibble:") - 1)) {
- if (ext == NULL)
- goto skip;
- cp += sizeof("nibble:") - 1;
- i = MIN(strcspn(cp, " \t"), sizeof(ext->nsuffix) - 1);
- strncpy(ext->nsuffix, cp, i);
- ext->nsuffix[i] = '\0';
- }
- else if (!strncmp(cp, "nibble2:", sizeof("nibble2:") - 1)) {
- if (ext == NULL)
- goto skip;
- cp += sizeof("nibble2:") - 1;
- i = MIN(strcspn(cp, " \t"), sizeof(ext->nsuffix2) - 1);
- strncpy(ext->nsuffix2, cp, i);
- ext->nsuffix2[i] = '\0';
- }
- else if (!strncmp(cp, "v6revmode:", sizeof("v6revmode:") - 1)) {
- cp += sizeof("v6revmode:") - 1;
- /* "nibble" and "bitstring" used to be valid */
- if (!strncmp(cp, "single", sizeof("single") - 1)) {
- statp->options |= RES_NO_NIBBLE2;
- } else if (!strncmp(cp, "both", sizeof("both") - 1)) {
- statp->options &=
- ~RES_NO_NIBBLE2;
- }
- }
- else {
- /* XXX - print a warning here? */
- }
- skip:
- /* skip to next run of spaces */
- while (*cp && *cp != ' ' && *cp != '\t')
- cp++;
- }
-}
-
-#ifdef RESOLVSORT
-/* XXX - should really support CIDR which means explicit masks always. */
-static u_int32_t
-net_mask(in) /* XXX - should really use system's version of this */
- struct in_addr in;
-{
- register u_int32_t i = ntohl(in.s_addr);
-
- if (IN_CLASSA(i))
- return (htonl(IN_CLASSA_NET));
- else if (IN_CLASSB(i))
- return (htonl(IN_CLASSB_NET));
- return (htonl(IN_CLASSC_NET));
-}
-#endif
-
-u_int
-res_randomid(void) {
- struct timeval now;
-
- gettimeofday(&now, NULL);
- return (0xffff & (now.tv_sec ^ now.tv_usec ^ getpid()));
-}
-
-/*
- * This routine is for closing the socket if a virtual circuit is used and
- * the program wants to close it. This provides support for endhostent()
- * which expects to close the socket.
- *
- * This routine is not expected to be user visible.
- */
-void
-res_nclose(res_state statp) {
- int ns;
-
- if (statp->_vcsock >= 0) {
- (void) close(statp->_vcsock);
- statp->_vcsock = -1;
- statp->_flags &= ~(RES_F_VC | RES_F_CONN);
- }
- for (ns = 0; ns < statp->_u._ext.nscount; ns++) {
- if (statp->_u._ext.nssocks[ns] != -1) {
- (void) close(statp->_u._ext.nssocks[ns]);
- statp->_u._ext.nssocks[ns] = -1;
- }
- }
-}
-
-void
-res_ndestroy(res_state statp) {
- res_nclose(statp);
- if (statp->_u._ext.ext != NULL)
- free(statp->_u._ext.ext);
- statp->options &= ~RES_INIT;
- statp->_u._ext.ext = NULL;
-}
-
-const char *
-res_get_nibblesuffix(res_state statp) {
- if (statp->_u._ext.ext)
- return (statp->_u._ext.ext->nsuffix);
- return ("ip6.arpa");
-}
-
-const char *
-res_get_nibblesuffix2(res_state statp) {
- if (statp->_u._ext.ext)
- return (statp->_u._ext.ext->nsuffix2);
- return ("ip6.int");
-}
-
-void
-res_setservers(res_state statp, const union res_sockaddr_union *set, int cnt) {
- int i, nserv;
- size_t size;
-
- /* close open servers */
- res_nclose(statp);
-
- /* cause rtt times to be forgotten */
- statp->_u._ext.nscount = 0;
-
- nserv = 0;
- for (i = 0; i < cnt && nserv < MAXNS; i++) {
- switch (set->sin.sin_family) {
- case AF_INET:
- size = sizeof(set->sin);
- if (statp->_u._ext.ext)
- memcpy(&statp->_u._ext.ext->nsaddrs[nserv],
- &set->sin, size);
- if (size <= sizeof(statp->nsaddr_list[nserv]))
- memcpy(&statp->nsaddr_list[nserv],
- &set->sin, size);
- else
- statp->nsaddr_list[nserv].sin_family = 0;
- nserv++;
- break;
-
-#ifdef HAS_INET6_STRUCTS
- case AF_INET6:
- size = sizeof(set->sin6);
- if (statp->_u._ext.ext)
- memcpy(&statp->_u._ext.ext->nsaddrs[nserv],
- &set->sin6, size);
- if (size <= sizeof(statp->nsaddr_list[nserv]))
- memcpy(&statp->nsaddr_list[nserv],
- &set->sin6, size);
- else
- statp->nsaddr_list[nserv].sin_family = 0;
- nserv++;
- break;
-#endif
-
- default:
- break;
- }
- set++;
- }
- statp->nscount = nserv;
-
-}
-
-int
-res_getservers(res_state statp, union res_sockaddr_union *set, int cnt) {
- int i;
- size_t size;
- u_int16_t family;
-
- for (i = 0; i < statp->nscount && i < cnt; i++) {
- if (statp->_u._ext.ext)
- family = statp->_u._ext.ext->nsaddrs[i].sin.sin_family;
- else
- family = statp->nsaddr_list[i].sin_family;
-
- switch (family) {
- case AF_INET:
- size = sizeof(set->sin);
- if (statp->_u._ext.ext)
- memcpy(&set->sin,
- &statp->_u._ext.ext->nsaddrs[i],
- size);
- else
- memcpy(&set->sin, &statp->nsaddr_list[i],
- size);
- break;
-
-#ifdef HAS_INET6_STRUCTS
- case AF_INET6:
- size = sizeof(set->sin6);
- if (statp->_u._ext.ext)
- memcpy(&set->sin6,
- &statp->_u._ext.ext->nsaddrs[i],
- size);
- else
- memcpy(&set->sin6, &statp->nsaddr_list[i],
- size);
- break;
-#endif
-
- default:
- set->sin.sin_family = 0;
- break;
- }
- set++;
- }
- return (statp->nscount);
-}
diff --git a/contrib/bind/lib/resolv/res_mkquery.c b/contrib/bind/lib/resolv/res_mkquery.c
deleted file mode 100644
index a45d89b..0000000
--- a/contrib/bind/lib/resolv/res_mkquery.c
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- * Copyright (c) 1985, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Portions Copyright (c) 1993 by Digital Equipment Corporation.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies, and that
- * the name of Digital Equipment Corporation not be used in advertising or
- * publicity pertaining to distribution of the document or software without
- * specific, written prior permission.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
- * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-/*
- * Portions Copyright (c) 1996-1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char sccsid[] = "@(#)res_mkquery.c 8.1 (Berkeley) 6/4/93";
-static const char rcsid[] = "$Id: res_mkquery.c,v 8.15.8.1 2003/06/02 05:59:57 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include "port_before.h"
-#include <sys/types.h>
-#include <sys/param.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <netdb.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <string.h>
-#include "port_after.h"
-
-/* Options. Leave them on. */
-#define DEBUG
-
-extern const char *_res_opcodes[];
-
-/*
- * Form all types of queries.
- * Returns the size of the result or -1.
- */
-int
-res_nmkquery(res_state statp,
- int op, /* opcode of query */
- const char *dname, /* domain name */
- int class, int type, /* class and type of query */
- const u_char *data, /* resource record data */
- int datalen, /* length of data */
- const u_char *newrr_in, /* new rr for modify or append */
- u_char *buf, /* buffer to put query */
- int buflen) /* size of buffer */
-{
- register HEADER *hp;
- register u_char *cp, *ep;
- register int n;
- u_char *dnptrs[20], **dpp, **lastdnptr;
-
- UNUSED(newrr_in);
-
-#ifdef DEBUG
- if (statp->options & RES_DEBUG)
- printf(";; res_nmkquery(%s, %s, %s, %s)\n",
- _res_opcodes[op], dname, p_class(class), p_type(type));
-#endif
- /*
- * Initialize header fields.
- */
- if ((buf == NULL) || (buflen < HFIXEDSZ))
- return (-1);
- memset(buf, 0, HFIXEDSZ);
- hp = (HEADER *) buf;
- hp->id = htons(++statp->id);
- hp->opcode = op;
- hp->rd = (statp->options & RES_RECURSE) != 0;
- hp->rcode = NOERROR;
- cp = buf + HFIXEDSZ;
- ep = buf + buflen;
- dpp = dnptrs;
- *dpp++ = buf;
- *dpp++ = NULL;
- lastdnptr = dnptrs + sizeof dnptrs / sizeof dnptrs[0];
- /*
- * perform opcode specific processing
- */
- switch (op) {
- case QUERY: /*FALLTHROUGH*/
- case NS_NOTIFY_OP:
- if (ep - cp < QFIXEDSZ)
- return (-1);
- if ((n = dn_comp(dname, cp, ep - cp - QFIXEDSZ, dnptrs,
- lastdnptr)) < 0)
- return (-1);
- cp += n;
- ns_put16(type, cp);
- cp += INT16SZ;
- ns_put16(class, cp);
- cp += INT16SZ;
- hp->qdcount = htons(1);
- if (op == QUERY || data == NULL)
- break;
- /*
- * Make an additional record for completion domain.
- */
- if ((ep - cp) < RRFIXEDSZ)
- return (-1);
- n = dn_comp((const char *)data, cp, ep - cp - RRFIXEDSZ,
- dnptrs, lastdnptr);
- if (n < 0)
- return (-1);
- cp += n;
- ns_put16(T_NULL, cp);
- cp += INT16SZ;
- ns_put16(class, cp);
- cp += INT16SZ;
- ns_put32(0, cp);
- cp += INT32SZ;
- ns_put16(0, cp);
- cp += INT16SZ;
- hp->arcount = htons(1);
- break;
-
- case IQUERY:
- /*
- * Initialize answer section
- */
- if (ep - cp < 1 + RRFIXEDSZ + datalen)
- return (-1);
- *cp++ = '\0'; /* no domain name */
- ns_put16(type, cp);
- cp += INT16SZ;
- ns_put16(class, cp);
- cp += INT16SZ;
- ns_put32(0, cp);
- cp += INT32SZ;
- ns_put16(datalen, cp);
- cp += INT16SZ;
- if (datalen) {
- memcpy(cp, data, datalen);
- cp += datalen;
- }
- hp->ancount = htons(1);
- break;
-
- default:
- return (-1);
- }
- return (cp - buf);
-}
-
-#ifdef RES_USE_EDNS0
-/* attach OPT pseudo-RR, as documented in RFC2671 (EDNS0). */
-#ifndef T_OPT
-#define T_OPT 41
-#endif
-
-int
-res_nopt(res_state statp,
- int n0, /* current offset in buffer */
- u_char *buf, /* buffer to put query */
- int buflen, /* size of buffer */
- int anslen) /* UDP answer buffer size */
-{
- register HEADER *hp;
- register u_char *cp, *ep;
- u_int16_t flags = 0;
-
-#ifdef DEBUG
- if ((statp->options & RES_DEBUG) != 0)
- printf(";; res_nopt()\n");
-#endif
-
- hp = (HEADER *) buf;
- cp = buf + n0;
- ep = buf + buflen;
-
- if ((ep - cp) < 1 + RRFIXEDSZ)
- return (-1);
-
- *cp++ = 0; /* "." */
-
- ns_put16(T_OPT, cp); /* TYPE */
- cp += INT16SZ;
- ns_put16(anslen & 0xffff, cp); /* CLASS = UDP payload size */
- cp += INT16SZ;
- *cp++ = NOERROR; /* extended RCODE */
- *cp++ = 0; /* EDNS version */
- if (statp->options & RES_USE_DNSSEC) {
-#ifdef DEBUG
- if (statp->options & RES_DEBUG)
- printf(";; res_opt()... ENDS0 DNSSEC\n");
-#endif
- flags |= NS_OPT_DNSSEC_OK;
- }
- ns_put16(flags, cp);
- cp += INT16SZ;
- ns_put16(0, cp); /* RDLEN */
- cp += INT16SZ;
- hp->arcount = htons(ntohs(hp->arcount) + 1);
-
- return (cp - buf);
-}
-#endif
diff --git a/contrib/bind/lib/resolv/res_mkupdate.c b/contrib/bind/lib/resolv/res_mkupdate.c
deleted file mode 100644
index 3928f9f..0000000
--- a/contrib/bind/lib/resolv/res_mkupdate.c
+++ /dev/null
@@ -1,1158 +0,0 @@
-/*
- * Copyright (c) 1996-1999 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>
- */
-
-#if !defined(lint) && !defined(SABER)
-static const char rcsid[] = "$Id: res_mkupdate.c,v 1.27.8.1 2003/06/02 04:56:28 marka Exp $";
-#endif /* not lint */
-
-#include "port_before.h"
-
-#include <sys/types.h>
-#include <sys/param.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <arpa/inet.h>
-
-#include <errno.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 "port_after.h"
-
-/* Options. Leave them on. */
-#define DEBUG
-#define MAXPORT 1024
-
-static int getnum_str(u_char **, u_char *);
-static int gethexnum_str(u_char **, u_char *);
-static int getword_str(char *, int, u_char **, u_char *);
-static int getstr_str(char *, int, u_char **, u_char *);
-
-#define ShrinkBuffer(x) if ((buflen -= x) < 0) return (-2);
-
-/* Forward. */
-
-int res_protocolnumber(const char *);
-int res_servicenumber(const char *);
-
-/*
- * 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, *sp1, *sp2, *startp, *endp;
- int n, i, soanum, multiline;
- ns_updrec *rrecp;
- struct in_addr ina;
- struct in6_addr in6a;
- char buf2[MAXDNAME];
- u_char buf3[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;
- int siglen, keylen, certlen;
-
- /*
- * 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;
- sp1 = buf + 2*INT16SZ; /* save pointer to zocount */
- 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 = NEXT(rrecp, r_glink)) {
- 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_mkupdate: 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_mkupdate: 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);
- ShrinkBuffer(INT16SZ);
- PUTSHORT(n, cp);
- 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_SRV:
- n = getnum_str(&startp, endp);
- if (n < 0)
- return (-1);
- ShrinkBuffer(INT16SZ);
- PUTSHORT(n, cp);
-
- n = getnum_str(&startp, endp);
- if (n < 0)
- return (-1);
- ShrinkBuffer(INT16SZ);
- PUTSHORT(n, cp);
-
- n = getnum_str(&startp, endp);
- if (n < 0)
- return (-1);
- ShrinkBuffer(INT16SZ);
- PUTSHORT(n, cp);
-
- if (!getword_str(buf2, sizeof buf2, &startp, endp))
- return (-1);
- n = dn_comp(buf2, cp, buflen, NULL, NULL);
- 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: {
- char bm[MAXPORT/8];
- unsigned int maxbm = 0;
-
- 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);
-
- if (!getword_str(buf2, sizeof buf2, &startp, endp))
- return (-1);
- if ((i = res_protocolnumber(buf2)) < 0)
- return (-1);
- ShrinkBuffer(1);
- *cp++ = i & 0xff;
-
- for (i = 0; i < MAXPORT/8 ; i++)
- bm[i] = 0;
-
- while (getword_str(buf2, sizeof buf2, &startp, endp)) {
- if ((n1 = res_servicenumber(buf2)) <= 0)
- return (-1);
-
- if (n1 < MAXPORT) {
- bm[n1/8] |= (0x80>>(n1%8));
- if (n1 > maxbm)
- maxbm = n1;
- } else
- return (-1);
- }
- maxbm = maxbm/8 + 1;
- ShrinkBuffer(maxbm);
- memcpy(cp, bm, maxbm);
- cp += maxbm;
- break;
- }
- case T_HINFO:
- for (i = 0; i < 2; i++) {
- if ((n = getstr_str(buf2, sizeof buf2,
- &startp, endp)) < 0)
- return (-1);
- if (n > 255)
- return (-1);
- ShrinkBuffer(n+1);
- *cp++ = n;
- memcpy(cp, buf2, n);
- cp += n;
- }
- break;
- case T_TXT:
- while (1) {
- if ((n = getstr_str(buf2, sizeof buf2,
- &startp, endp)) < 0) {
- if (cp != (sp2 + INT16SZ))
- break;
- return (-1);
- }
- if (n > 255)
- return (-1);
- ShrinkBuffer(n+1);
- *cp++ = n;
- memcpy(cp, buf2, n);
- cp += n;
- }
- break;
- case T_X25:
- /* RFC 1183 */
- if ((n = getstr_str(buf2, sizeof buf2, &startp,
- endp)) < 0)
- return (-1);
- if (n > 255)
- return (-1);
- ShrinkBuffer(n+1);
- *cp++ = n;
- memcpy(cp, buf2, n);
- cp += n;
- break;
- case T_ISDN:
- /* RFC 1183 */
- if ((n = getstr_str(buf2, sizeof buf2, &startp,
- endp)) < 0)
- return (-1);
- if ((n > 255) || (n == 0))
- return (-1);
- ShrinkBuffer(n+1);
- *cp++ = n;
- memcpy(cp, buf2, n);
- cp += n;
- if ((n = getstr_str(buf2, sizeof buf2, &startp,
- endp)) < 0)
- n = 0;
- if (n > 255)
- return (-1);
- ShrinkBuffer(n+1);
- *cp++ = n;
- memcpy(cp, buf2, n);
- cp += n;
- break;
- case T_NSAP:
- if ((n = inet_nsap_addr((char *)startp, (u_char *)buf2, sizeof(buf2))) != 0) {
- ShrinkBuffer(n);
- memcpy(cp, buf2, n);
- cp += n;
- } else {
- return (-1);
- }
- break;
- case T_LOC:
- if ((n = loc_aton((char *)startp, (u_char *)buf2)) != 0) {
- ShrinkBuffer(n);
- memcpy(cp, buf2, n);
- cp += n;
- } else
- return (-1);
- break;
- case ns_t_sig:
- {
- int sig_type, success, dateerror;
- u_int32_t exptime, timesigned;
-
- /* type */
- if ((n = getword_str(buf2, sizeof buf2,
- &startp, endp)) < 0)
- return (-1);
- sig_type = sym_ston(__p_type_syms, buf2, &success);
- if (!success || sig_type == ns_t_any)
- return (-1);
- ShrinkBuffer(INT16SZ);
- PUTSHORT(sig_type, cp);
- /* alg */
- n = getnum_str(&startp, endp);
- if (n < 0)
- return (-1);
- ShrinkBuffer(1);
- *cp++ = n;
- /* labels */
- n = getnum_str(&startp, endp);
- if (n <= 0 || n > 255)
- return (-1);
- ShrinkBuffer(1);
- *cp++ = n;
- /* ottl & expire */
- if (!getword_str(buf2, sizeof buf2, &startp, endp))
- return (-1);
- exptime = ns_datetosecs(buf2, &dateerror);
- if (!dateerror) {
- ShrinkBuffer(INT32SZ);
- PUTLONG(rttl, cp);
- }
- else {
- char *ulendp;
- u_int32_t ottl;
-
- errno = 0;
- ottl = strtoul(buf2, &ulendp, 10);
- if (errno != 0 ||
- (ulendp != NULL && *ulendp != '\0'))
- return (-1);
- ShrinkBuffer(INT32SZ);
- PUTLONG(ottl, cp);
- if (!getword_str(buf2, sizeof buf2, &startp,
- endp))
- return (-1);
- exptime = ns_datetosecs(buf2, &dateerror);
- if (dateerror)
- return (-1);
- }
- /* expire */
- ShrinkBuffer(INT32SZ);
- PUTLONG(exptime, cp);
- /* timesigned */
- if (!getword_str(buf2, sizeof buf2, &startp, endp))
- return (-1);
- timesigned = ns_datetosecs(buf2, &dateerror);
- if (!dateerror) {
- ShrinkBuffer(INT32SZ);
- PUTLONG(timesigned, cp);
- }
- else
- return (-1);
- /* footprint */
- n = getnum_str(&startp, endp);
- if (n < 0)
- return (-1);
- ShrinkBuffer(INT16SZ);
- PUTSHORT(n, cp);
- /* signer name */
- 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);
- /* sig */
- if ((n = getword_str(buf2, sizeof buf2,
- &startp, endp)) < 0)
- return (-1);
- siglen = b64_pton(buf2, buf3, sizeof(buf3));
- if (siglen < 0)
- return (-1);
- ShrinkBuffer(siglen);
- memcpy(cp, buf3, siglen);
- cp += siglen;
- break;
- }
- case ns_t_key:
- /* flags */
- n = gethexnum_str(&startp, endp);
- if (n < 0)
- return (-1);
- ShrinkBuffer(INT16SZ);
- PUTSHORT(n, cp);
- /* proto */
- n = getnum_str(&startp, endp);
- if (n < 0)
- return (-1);
- ShrinkBuffer(1);
- *cp++ = n;
- /* alg */
- n = getnum_str(&startp, endp);
- if (n < 0)
- return (-1);
- ShrinkBuffer(1);
- *cp++ = n;
- /* key */
- if ((n = getword_str(buf2, sizeof buf2,
- &startp, endp)) < 0)
- return (-1);
- keylen = b64_pton(buf2, buf3, sizeof(buf3));
- if (keylen < 0)
- return (-1);
- ShrinkBuffer(keylen);
- memcpy(cp, buf3, keylen);
- cp += keylen;
- break;
- case ns_t_nxt:
- {
- int success, nxt_type;
- u_char data[32];
- int maxtype;
-
- /* next name */
- if (!getword_str(buf2, sizeof buf2, &startp, endp))
- return (-1);
- n = dn_comp(buf2, cp, buflen, NULL, NULL);
- if (n < 0)
- return (-1);
- cp += n;
- ShrinkBuffer(n);
- maxtype = 0;
- memset(data, 0, sizeof data);
- while (1) {
- if (!getword_str(buf2, sizeof buf2, &startp,
- endp))
- break;
- nxt_type = sym_ston(__p_type_syms, buf2,
- &success);
- if (!success || !ns_t_rr_p(nxt_type))
- return (-1);
- NS_NXT_BIT_SET(nxt_type, data);
- if (nxt_type > maxtype)
- maxtype = nxt_type;
- }
- n = maxtype/NS_NXT_BITS+1;
- ShrinkBuffer(n);
- memcpy(cp, data, n);
- cp += n;
- break;
- }
- case ns_t_cert:
- /* type */
- n = getnum_str(&startp, endp);
- if (n < 0)
- return (-1);
- ShrinkBuffer(INT16SZ);
- PUTSHORT(n, cp);
- /* key tag */
- n = getnum_str(&startp, endp);
- if (n < 0)
- return (-1);
- ShrinkBuffer(INT16SZ);
- PUTSHORT(n, cp);
- /* alg */
- n = getnum_str(&startp, endp);
- if (n < 0)
- return (-1);
- ShrinkBuffer(1);
- *cp++ = n;
- /* cert */
- if ((n = getword_str(buf2, sizeof buf2,
- &startp, endp)) < 0)
- return (-1);
- certlen = b64_pton(buf2, buf3, sizeof(buf3));
- if (certlen < 0)
- return (-1);
- ShrinkBuffer(certlen);
- memcpy(cp, buf3, certlen);
- cp += certlen;
- break;
- case ns_t_aaaa:
- if (!getword_str(buf2, sizeof buf2, &startp, endp))
- return (-1);
- if (inet_pton(AF_INET6, buf2, &in6a) <= 0)
- return (-1);
- ShrinkBuffer(NS_IN6ADDRSZ);
- memcpy(cp, &in6a, NS_IN6ADDRSZ);
- cp += NS_IN6ADDRSZ;
- break;
- case ns_t_naptr:
- /* Order Preference Flags Service Replacement Regexp */
- /* Order */
- n = getnum_str(&startp, endp);
- if (n < 0 || n > 65535)
- return (-1);
- ShrinkBuffer(INT16SZ);
- PUTSHORT(n, cp);
- /* Preference */
- n = getnum_str(&startp, endp);
- if (n < 0 || n > 65535)
- return (-1);
- ShrinkBuffer(INT16SZ);
- PUTSHORT(n, cp);
- /* Flags */
- if ((n = getstr_str(buf2, sizeof buf2,
- &startp, endp)) < 0) {
- return (-1);
- }
- if (n > 255)
- return (-1);
- ShrinkBuffer(n+1);
- *cp++ = n;
- memcpy(cp, buf2, n);
- cp += n;
- /* Service Classes */
- if ((n = getstr_str(buf2, sizeof buf2,
- &startp, endp)) < 0) {
- return (-1);
- }
- if (n > 255)
- return (-1);
- ShrinkBuffer(n+1);
- *cp++ = n;
- memcpy(cp, buf2, n);
- cp += n;
- /* Pattern */
- if ((n = getstr_str(buf2, sizeof buf2,
- &startp, endp)) < 0) {
- return (-1);
- }
- if (n > 255)
- return (-1);
- ShrinkBuffer(n+1);
- *cp++ = n;
- memcpy(cp, buf2, n);
- cp += n;
- /* Replacement */
- if (!getword_str(buf2, sizeof buf2, &startp, endp))
- return (-1);
- n = dn_comp(buf2, cp, buflen, NULL, NULL);
- if (n < 0)
- return (-1);
- cp += n;
- ShrinkBuffer(n);
- 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 white spae delimited string from memory. Process quoted strings
- * and \DDD escapes. Return length or -1 on error. Returned string may
- * contain nulls.
- */
-static char digits[] = "0123456789";
-static int
-getstr_str(char *buf, int size, u_char **startpp, u_char *endp) {
- char *cp;
- int c, c1 = 0;
- int inquote = 0;
- int seen_quote = 0;
- int escape = 0;
- int dig = 0;
-
- for (cp = buf; *startpp <= endp; ) {
- if ((c = **startpp) == '\0')
- break;
- /* leading white space */
- if ((cp == buf) && !seen_quote && isspace(c)) {
- (*startpp)++;
- continue;
- }
-
- switch (c) {
- case '\\':
- if (!escape) {
- escape = 1;
- dig = 0;
- c1 = 0;
- (*startpp)++;
- continue;
- }
- goto do_escape;
- case '"':
- if (!escape) {
- inquote = !inquote;
- seen_quote = 1;
- (*startpp)++;
- continue;
- }
- /* fall through */
- default:
- do_escape:
- if (escape) {
- switch (c) {
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- c1 = c1 * 10 +
- (strchr(digits, c) - digits);
-
- if (++dig == 3) {
- c = c1 &0xff;
- break;
- }
- (*startpp)++;
- continue;
- }
- escape = 0;
- } else if (!inquote && isspace(c))
- goto done;
- if (cp >= buf+size-1)
- goto done;
- *cp++ = (u_char)c;
- (*startpp)++;
- }
- }
- done:
- *cp = '\0';
- return ((cp == buf)? (seen_quote? 0: -1): (cp - buf));
-}
-/*
- * Get a whitespace delimited base 16 number from a string (not file) into buf
- * update the start pointer to point after the number in the string.
- */
-static int
-gethexnum_str(u_char **startpp, u_char *endp) {
- int c, n;
- int seendigit = 0;
- int m = 0;
-
- if (*startpp + 2 >= endp || strncasecmp((char *)*startpp, "0x", 2) != 0)
- return getnum_str(startpp, endp);
- (*startpp)+=2;
- 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 (!isxdigit(c)) {
- if (c == ')' && seendigit) {
- (*startpp)--;
- break;
- }
- return (-1);
- }
- (*startpp)++;
- if (isdigit(c))
- n = n * 16 + (c - '0');
- else
- n = n * 16 + (tolower(c) - 'a' + 10);
- seendigit = 1;
- }
- return (n + m);
-}
-
-/*
- * Get a whitespace delimited base 10 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))) {
- if (rrecp)
- free((char *)rrecp);
- return (NULL);
- }
- INIT_LINK(rrecp, r_link);
- INIT_LINK(rrecp, r_glink);
- 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);
-}
-
-struct valuelist {
- struct valuelist * next;
- struct valuelist * prev;
- char * name;
- char * proto;
- int port;
-};
-static struct valuelist *servicelist, *protolist;
-
-static void
-res_buildservicelist() {
- struct servent *sp;
- struct valuelist *slp;
-
-#ifdef MAYBE_HESIOD
- setservent(0);
-#else
- setservent(1);
-#endif
- while ((sp = getservent()) != NULL) {
- slp = (struct valuelist *)malloc(sizeof(struct valuelist));
- if (!slp)
- break;
- slp->name = strdup(sp->s_name);
- slp->proto = strdup(sp->s_proto);
- if ((slp->name == NULL) || (slp->proto == NULL)) {
- if (slp->name) free(slp->name);
- if (slp->proto) free(slp->proto);
- free(slp);
- break;
- }
- slp->port = ntohs((u_int16_t)sp->s_port); /* host byt order */
- slp->next = servicelist;
- slp->prev = NULL;
- if (servicelist)
- servicelist->prev = slp;
- servicelist = slp;
- }
- endservent();
-}
-
-void
-res_destroyservicelist() {
- struct valuelist *slp, *slp_next;
-
- for (slp = servicelist; slp != NULL; slp = slp_next) {
- slp_next = slp->next;
- free(slp->name);
- free(slp->proto);
- free(slp);
- }
- servicelist = (struct valuelist *)0;
-}
-
-void
-res_buildprotolist(void) {
- struct protoent *pp;
- struct valuelist *slp;
-
-#ifdef MAYBE_HESIOD
- setprotoent(0);
-#else
- setprotoent(1);
-#endif
- while ((pp = getprotoent()) != NULL) {
- slp = (struct valuelist *)malloc(sizeof(struct valuelist));
- if (!slp)
- break;
- slp->name = strdup(pp->p_name);
- if (slp->name == NULL) {
- free(slp);
- break;
- }
- slp->port = pp->p_proto; /* host byte order */
- slp->next = protolist;
- slp->prev = NULL;
- if (protolist)
- protolist->prev = slp;
- protolist = slp;
- }
- endprotoent();
-}
-
-void
-res_destroyprotolist(void) {
- struct valuelist *plp, *plp_next;
-
- for (plp = protolist; plp != NULL; plp = plp_next) {
- plp_next = plp->next;
- free(plp->name);
- free(plp);
- }
- protolist = (struct valuelist *)0;
-}
-
-static int
-findservice(const char *s, struct valuelist **list) {
- struct valuelist *lp = *list;
- int n;
-
- for (; lp != NULL; lp = lp->next)
- if (strcasecmp(lp->name, s) == 0) {
- if (lp != *list) {
- lp->prev->next = lp->next;
- if (lp->next)
- lp->next->prev = lp->prev;
- (*list)->prev = lp;
- lp->next = *list;
- *list = lp;
- }
- return (lp->port); /* host byte order */
- }
- if (sscanf(s, "%d", &n) != 1 || n <= 0)
- n = -1;
- return (n);
-}
-
-/*
- * Convert service name or (ascii) number to int.
- */
-int
-res_servicenumber(const char *p) {
- if (servicelist == (struct valuelist *)0)
- res_buildservicelist();
- return (findservice(p, &servicelist));
-}
-
-/*
- * Convert protocol name or (ascii) number to int.
- */
-int
-res_protocolnumber(const char *p) {
- if (protolist == (struct valuelist *)0)
- res_buildprotolist();
- return (findservice(p, &protolist));
-}
-
-static struct servent *
-cgetservbyport(u_int16_t port, const char *proto) { /* Host byte order. */
- struct valuelist **list = &servicelist;
- struct valuelist *lp = *list;
- static struct servent serv;
-
- port = ntohs(port);
- for (; lp != NULL; lp = lp->next) {
- if (port != (u_int16_t)lp->port) /* Host byte order. */
- continue;
- if (strcasecmp(lp->proto, proto) == 0) {
- if (lp != *list) {
- lp->prev->next = lp->next;
- if (lp->next)
- lp->next->prev = lp->prev;
- (*list)->prev = lp;
- lp->next = *list;
- *list = lp;
- }
- serv.s_name = lp->name;
- serv.s_port = htons((u_int16_t)lp->port);
- serv.s_proto = lp->proto;
- return (&serv);
- }
- }
- return (0);
-}
-
-static struct protoent *
-cgetprotobynumber(int proto) { /* Host byte order. */
- struct valuelist **list = &protolist;
- struct valuelist *lp = *list;
- static struct protoent prot;
-
- for (; lp != NULL; lp = lp->next)
- if (lp->port == proto) { /* Host byte order. */
- if (lp != *list) {
- lp->prev->next = lp->next;
- if (lp->next)
- lp->next->prev = lp->prev;
- (*list)->prev = lp;
- lp->next = *list;
- *list = lp;
- }
- prot.p_name = lp->name;
- prot.p_proto = lp->port; /* Host byte order. */
- return (&prot);
- }
- return (0);
-}
-
-const char *
-res_protocolname(int num) {
- static char number[8];
- struct protoent *pp;
-
- if (protolist == (struct valuelist *)0)
- res_buildprotolist();
- pp = cgetprotobynumber(num);
- if (pp == 0) {
- (void) sprintf(number, "%d", num);
- return (number);
- }
- return (pp->p_name);
-}
-
-const char *
-res_servicename(u_int16_t port, const char *proto) { /* Host byte order. */
- static char number[8];
- struct servent *ss;
-
- if (servicelist == (struct valuelist *)0)
- res_buildservicelist();
- ss = cgetservbyport(htons(port), proto);
- if (ss == 0) {
- (void) sprintf(number, "%d", port);
- return (number);
- }
- return (ss->s_name);
-}
diff --git a/contrib/bind/lib/resolv/res_mkupdate.h b/contrib/bind/lib/resolv/res_mkupdate.h
deleted file mode 100644
index 48edf63..0000000
--- a/contrib/bind/lib/resolv/res_mkupdate.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (c) 1998,1999 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.
- */
-
-#ifndef _RES_MKUPDATE_H_
-#define _RES_MKUPDATE_H_
-
-__BEGIN_DECLS
-__END_DECLS
-
-#endif /* _RES_MKUPDATE_H_ */
diff --git a/contrib/bind/lib/resolv/res_private.h b/contrib/bind/lib/resolv/res_private.h
deleted file mode 100644
index d7b66cd..0000000
--- a/contrib/bind/lib/resolv/res_private.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#ifndef res_private_h
-#define res_private_h
-
-struct __res_state_ext {
- union res_sockaddr_union nsaddrs[MAXNS];
- struct sort_list {
- int af;
- union {
- struct in_addr ina;
- struct in6_addr in6a;
- } addr, mask;
- } sort_list[MAXRESOLVSORT];
- char nsuffix[64];
- char nsuffix2[64];
-};
-
-extern int
-res_ourserver_p(const res_state statp, const struct sockaddr *sa);
-
-#endif
diff --git a/contrib/bind/lib/resolv/res_query.c b/contrib/bind/lib/resolv/res_query.c
deleted file mode 100644
index cda076c..0000000
--- a/contrib/bind/lib/resolv/res_query.c
+++ /dev/null
@@ -1,432 +0,0 @@
-/*
- * Copyright (c) 1988, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Portions Copyright (c) 1993 by Digital Equipment Corporation.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies, and that
- * the name of Digital Equipment Corporation not be used in advertising or
- * publicity pertaining to distribution of the document or software without
- * specific, written prior permission.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
- * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-/*
- * Portions Copyright (c) 1996-1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93";
-static const char rcsid[] = "$Id: res_query.c,v 8.24 2003/01/31 15:25:58 vixie Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include "port_before.h"
-#include <sys/types.h>
-#include <sys/param.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-#include <ctype.h>
-#include <errno.h>
-#include <netdb.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "port_after.h"
-
-/* Options. Leave them on. */
-#define DEBUG
-
-#if PACKETSZ > 1024
-#define MAXPACKET PACKETSZ
-#else
-#define MAXPACKET 1024
-#endif
-
-/*
- * Formulate a normal query, send, and await answer.
- * Returned answer is placed in supplied buffer "answer".
- * Perform preliminary check of answer, returning success only
- * if no error is indicated and the answer count is nonzero.
- * Return the size of the response on success, -1 on error.
- * Error number is left in H_ERRNO.
- *
- * Caller must parse answer and determine whether it answers the question.
- */
-int
-res_nquery(res_state statp,
- const char *name, /* domain name */
- int class, int type, /* class and type of query */
- u_char *answer, /* buffer to put answer */
- int anslen) /* size of answer buffer */
-{
- u_char buf[MAXPACKET];
- HEADER *hp = (HEADER *) answer;
- int n;
- u_int oflags;
-
- oflags = statp->_flags;
-
-again:
- hp->rcode = NOERROR; /* default */
-
-#ifdef DEBUG
- if (statp->options & RES_DEBUG)
- printf(";; res_query(%s, %d, %d)\n", name, class, type);
-#endif
-
- n = res_nmkquery(statp, QUERY, name, class, type, NULL, 0, NULL,
- buf, sizeof(buf));
-#ifdef RES_USE_EDNS0
- if (n > 0 && (statp->_flags & RES_F_EDNS0ERR) == 0 &&
- (statp->options & (RES_USE_EDNS0|RES_USE_DNSSEC)) != 0)
- n = res_nopt(statp, n, buf, sizeof(buf), anslen);
-#endif
- if (n <= 0) {
-#ifdef DEBUG
- if (statp->options & RES_DEBUG)
- printf(";; res_query: mkquery failed\n");
-#endif
- RES_SET_H_ERRNO(statp, NO_RECOVERY);
- return (n);
- }
- n = res_nsend(statp, buf, n, answer, anslen);
- if (n < 0) {
-#ifdef RES_USE_EDNS0
- /* if the query choked with EDNS0, retry without EDNS0 */
- if ((statp->options & (RES_USE_EDNS0|RES_USE_DNSSEC)) != 0 &&
- ((oflags ^ statp->_flags) & RES_F_EDNS0ERR) != 0) {
- statp->_flags |= RES_F_EDNS0ERR;
- if (statp->options & RES_DEBUG)
- printf(";; res_nquery: retry without EDNS0\n");
- goto again;
- }
-#endif
-#ifdef DEBUG
- if (statp->options & RES_DEBUG)
- printf(";; res_query: send error\n");
-#endif
- RES_SET_H_ERRNO(statp, TRY_AGAIN);
- return (n);
- }
-
- if (hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
-#ifdef DEBUG
- if (statp->options & RES_DEBUG)
- printf(";; rcode = (%s), counts = an:%d ns:%d ar:%d\n",
- p_rcode(hp->rcode),
- ntohs(hp->ancount),
- ntohs(hp->nscount),
- ntohs(hp->arcount));
-#endif
- switch (hp->rcode) {
- case NXDOMAIN:
- RES_SET_H_ERRNO(statp, HOST_NOT_FOUND);
- break;
- case SERVFAIL:
- RES_SET_H_ERRNO(statp, TRY_AGAIN);
- break;
- case NOERROR:
- RES_SET_H_ERRNO(statp, NO_DATA);
- break;
- case FORMERR:
- case NOTIMP:
- case REFUSED:
- default:
- RES_SET_H_ERRNO(statp, NO_RECOVERY);
- break;
- }
- return (-1);
- }
- return (n);
-}
-
-/*
- * Formulate a normal query, send, and retrieve answer in supplied buffer.
- * Return the size of the response on success, -1 on error.
- * If enabled, implement search rules until answer or unrecoverable failure
- * is detected. Error code, if any, is left in H_ERRNO.
- */
-int
-res_nsearch(res_state statp,
- const char *name, /* domain name */
- int class, int type, /* class and type of query */
- u_char *answer, /* buffer to put answer */
- int anslen) /* size of answer */
-{
- const char *cp, * const *domain;
- HEADER *hp = (HEADER *) answer;
- char tmp[NS_MAXDNAME];
- u_int dots;
- int trailing_dot, ret, saved_herrno;
- int got_nodata = 0, got_servfail = 0, root_on_list = 0;
- int tried_as_is = 0;
- int searched = 0;
-
- errno = 0;
- RES_SET_H_ERRNO(statp, HOST_NOT_FOUND); /* True if we never query. */
-
- dots = 0;
- for (cp = name; *cp != '\0'; cp++)
- dots += (*cp == '.');
- trailing_dot = 0;
- if (cp > name && *--cp == '.')
- trailing_dot++;
-
- /* If there aren't any dots, it could be a user-level alias. */
- if (!dots && (cp = res_hostalias(statp, name, tmp, sizeof tmp))!= NULL)
- return (res_nquery(statp, cp, class, type, answer, anslen));
-
- /*
- * If there are enough dots in the name, let's just give it a
- * try 'as is'. The threshold can be set with the "ndots" option.
- * Also, query 'as is', if there is a trailing dot in the name.
- */
- saved_herrno = -1;
- if (dots >= statp->ndots || trailing_dot) {
- ret = res_nquerydomain(statp, name, NULL, class, type,
- answer, anslen);
- if (ret > 0 || trailing_dot)
- return (ret);
- saved_herrno = h_errno;
- tried_as_is++;
- }
-
- /*
- * We do at least one level of search if
- * - there is no dot and RES_DEFNAME is set, or
- * - there is at least one dot, there is no trailing dot,
- * and RES_DNSRCH is set.
- */
- if ((!dots && (statp->options & RES_DEFNAMES) != 0) ||
- (dots && !trailing_dot && (statp->options & RES_DNSRCH) != 0)) {
- int done = 0;
-
- for (domain = (const char * const *)statp->dnsrch;
- *domain && !done;
- domain++) {
- searched = 1;
-
- if (domain[0][0] == '\0' ||
- (domain[0][0] == '.' && domain[0][1] == '\0'))
- root_on_list++;
-
- ret = res_nquerydomain(statp, name, *domain,
- class, type,
- answer, anslen);
- if (ret > 0)
- return (ret);
-
- /*
- * If no server present, give up.
- * If name isn't found in this domain,
- * keep trying higher domains in the search list
- * (if that's enabled).
- * On a NO_DATA error, keep trying, otherwise
- * a wildcard entry of another type could keep us
- * from finding this entry higher in the domain.
- * If we get some other error (negative answer or
- * server failure), then stop searching up,
- * but try the input name below in case it's
- * fully-qualified.
- */
- if (errno == ECONNREFUSED) {
- RES_SET_H_ERRNO(statp, TRY_AGAIN);
- return (-1);
- }
-
- switch (statp->res_h_errno) {
- case NO_DATA:
- got_nodata++;
- /* FALLTHROUGH */
- case HOST_NOT_FOUND:
- /* keep trying */
- break;
- case TRY_AGAIN:
- if (hp->rcode == SERVFAIL) {
- /* try next search element, if any */
- got_servfail++;
- break;
- }
- /* FALLTHROUGH */
- default:
- /* anything else implies that we're done */
- done++;
- }
-
- /* if we got here for some reason other than DNSRCH,
- * we only wanted one iteration of the loop, so stop.
- */
- if ((statp->options & RES_DNSRCH) == 0)
- done++;
- }
- }
-
- /*
- * If the query has not already been tried as is then try it
- * unless RES_NOTLDQUERY is set and there were no dots.
- */
- if ((dots || !searched || (statp->options & RES_NOTLDQUERY) == 0) &&
- !(tried_as_is || root_on_list)) {
- ret = res_nquerydomain(statp, name, NULL, class, type,
- answer, anslen);
- if (ret > 0)
- return (ret);
- }
-
- /* if we got here, we didn't satisfy the search.
- * if we did an initial full query, return that query's H_ERRNO
- * (note that we wouldn't be here if that query had succeeded).
- * else if we ever got a nodata, send that back as the reason.
- * else send back meaningless H_ERRNO, that being the one from
- * the last DNSRCH we did.
- */
- if (saved_herrno != -1)
- RES_SET_H_ERRNO(statp, saved_herrno);
- else if (got_nodata)
- RES_SET_H_ERRNO(statp, NO_DATA);
- else if (got_servfail)
- RES_SET_H_ERRNO(statp, TRY_AGAIN);
- return (-1);
-}
-
-/*
- * Perform a call on res_query on the concatenation of name and domain,
- * removing a trailing dot from name if domain is NULL.
- */
-int
-res_nquerydomain(res_state statp,
- const char *name,
- const char *domain,
- int class, int type, /* class and type of query */
- u_char *answer, /* buffer to put answer */
- int anslen) /* size of answer */
-{
- char nbuf[MAXDNAME];
- const char *longname = nbuf;
- int n, d;
-
-#ifdef DEBUG
- if (statp->options & RES_DEBUG)
- printf(";; res_nquerydomain(%s, %s, %d, %d)\n",
- name, domain?domain:"<Nil>", class, type);
-#endif
- if (domain == NULL) {
- /*
- * Check for trailing '.';
- * copy without '.' if present.
- */
- n = strlen(name);
- if (n >= MAXDNAME) {
- RES_SET_H_ERRNO(statp, NO_RECOVERY);
- return (-1);
- }
- n--;
- if (n >= 0 && name[n] == '.') {
- strncpy(nbuf, name, n);
- nbuf[n] = '\0';
- } else
- longname = name;
- } else {
- n = strlen(name);
- d = strlen(domain);
- if (n + d + 1 >= MAXDNAME) {
- RES_SET_H_ERRNO(statp, NO_RECOVERY);
- return (-1);
- }
- sprintf(nbuf, "%s.%s", name, domain);
- }
- return (res_nquery(statp, longname, class, type, answer, anslen));
-}
-
-const char *
-res_hostalias(const res_state statp, const char *name, char *dst, size_t siz) {
- char *file, *cp1, *cp2;
- char buf[BUFSIZ];
- FILE *fp;
-
- if (statp->options & RES_NOALIASES)
- return (NULL);
- file = getenv("HOSTALIASES");
- if (file == NULL || (fp = fopen(file, "r")) == NULL)
- return (NULL);
- setbuf(fp, NULL);
- buf[sizeof(buf) - 1] = '\0';
- while (fgets(buf, sizeof(buf), fp)) {
- for (cp1 = buf; *cp1 && !isspace((unsigned char)*cp1); ++cp1)
- ;
- if (!*cp1)
- break;
- *cp1 = '\0';
- if (ns_samename(buf, name) == 1) {
- while (isspace((unsigned char)*++cp1))
- ;
- if (!*cp1)
- break;
- for (cp2 = cp1 + 1; *cp2 &&
- !isspace((unsigned char)*cp2); ++cp2)
- ;
- *cp2 = '\0';
- strncpy(dst, cp1, siz - 1);
- dst[siz - 1] = '\0';
- fclose(fp);
- return (dst);
- }
- }
- fclose(fp);
- return (NULL);
-}
diff --git a/contrib/bind/lib/resolv/res_send.c b/contrib/bind/lib/resolv/res_send.c
deleted file mode 100644
index 2adc608..0000000
--- a/contrib/bind/lib/resolv/res_send.c
+++ /dev/null
@@ -1,1031 +0,0 @@
-/*
- * Copyright (c) 1985, 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Portions Copyright (c) 1993 by Digital Equipment Corporation.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies, and that
- * the name of Digital Equipment Corporation not be used in advertising or
- * publicity pertaining to distribution of the document or software without
- * specific, written prior permission.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
- * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- */
-
-/*
- * Portions Copyright (c) 1996-1999 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93";
-static const char rcsid[] = "$Id: res_send.c,v 8.51.2.1 2003/06/02 05:59:57 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-/*
- * Send query to name server and wait for reply.
- */
-
-#include "port_before.h"
-#include "fd_setsize.h"
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/time.h>
-#include <sys/socket.h>
-#include <sys/uio.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <arpa/inet.h>
-
-#include <errno.h>
-#include <netdb.h>
-#include <resolv.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <isc/eventlib.h>
-
-#include "port_after.h"
-
-/* Options. Leave them on. */
-#define DEBUG
-#include "res_debug.h"
-#include "res_private.h"
-
-#define EXT(res) ((res)->_u._ext)
-
-static const int highestFD = FD_SETSIZE - 1;
-
-/* Forward. */
-
-static int get_salen __P((const struct sockaddr *));
-static struct sockaddr * get_nsaddr __P((res_state, size_t));
-static int send_vc(res_state, const u_char *, int,
- u_char *, int, int *, int);
-static int send_dg(res_state, const u_char *, int,
- u_char *, int, int *, int,
- int *, int *);
-static void Aerror(const res_state, FILE *, const char *, int,
- const struct sockaddr *, int);
-static void Perror(const res_state, FILE *, const char *, int);
-static int sock_eq(struct sockaddr *, struct sockaddr *);
-#ifdef NEED_PSELECT
-static int pselect(int, void *, void *, void *,
- struct timespec *,
- const sigset_t *);
-#endif
-void res_pquery(const res_state, const u_char *, int, FILE *);
-
-static const int niflags = NI_NUMERICHOST | NI_NUMERICSERV;
-
-/* Public. */
-
-/* int
- * res_isourserver(ina)
- * looks up "ina" in _res.ns_addr_list[]
- * returns:
- * 0 : not found
- * >0 : found
- * author:
- * paul vixie, 29may94
- */
-int
-res_ourserver_p(const res_state statp, const struct sockaddr *sa) {
- const struct sockaddr_in *inp, *srv;
- const struct sockaddr_in6 *in6p, *srv6;
- int ns;
-
- switch (sa->sa_family) {
- case AF_INET:
- inp = (const struct sockaddr_in *)sa;
- for (ns = 0; ns < statp->nscount; ns++) {
- srv = (struct sockaddr_in *)get_nsaddr(statp, ns);
- if (srv->sin_family == inp->sin_family &&
- srv->sin_port == inp->sin_port &&
- (srv->sin_addr.s_addr == INADDR_ANY ||
- srv->sin_addr.s_addr == inp->sin_addr.s_addr))
- return (1);
- }
- break;
- case AF_INET6:
- if (EXT(statp).ext == NULL)
- break;
- in6p = (const struct sockaddr_in6 *)sa;
- for (ns = 0; ns < statp->nscount; ns++) {
- srv6 = (struct sockaddr_in6 *)get_nsaddr(statp, ns);
- if (srv6->sin6_family == in6p->sin6_family &&
- srv6->sin6_port == in6p->sin6_port &&
-#ifdef HAVE_SIN6_SCOPE_ID
- srv6->sin6_scope_id == in6p->sin6_scope_id &&
-#endif
- (IN6_IS_ADDR_UNSPECIFIED(&srv6->sin6_addr) ||
- IN6_ARE_ADDR_EQUAL(&srv6->sin6_addr, &in6p->sin6_addr)))
- return (1);
- }
- break;
- default:
- break;
- }
- return (0);
-}
-
-/* int
- * res_nameinquery(name, type, class, buf, eom)
- * look for (name,type,class) in the query section of packet (buf,eom)
- * requires:
- * buf + HFIXEDSZ <= eom
- * returns:
- * -1 : format error
- * 0 : not found
- * >0 : found
- * author:
- * paul vixie, 29may94
- */
-int
-res_nameinquery(const char *name, int type, int class,
- const u_char *buf, const u_char *eom)
-{
- const u_char *cp = buf + HFIXEDSZ;
- int qdcount = ntohs(((const HEADER*)buf)->qdcount);
-
- while (qdcount-- > 0) {
- char tname[MAXDNAME+1];
- int n, ttype, tclass;
-
- n = dn_expand(buf, eom, cp, tname, sizeof tname);
- if (n < 0)
- return (-1);
- cp += n;
- if (cp + 2 * INT16SZ > eom)
- return (-1);
- ttype = ns_get16(cp); cp += INT16SZ;
- tclass = ns_get16(cp); cp += INT16SZ;
- if (ttype == type && tclass == class &&
- ns_samename(tname, name) == 1)
- return (1);
- }
- return (0);
-}
-
-/* int
- * res_queriesmatch(buf1, eom1, buf2, eom2)
- * is there a 1:1 mapping of (name,type,class)
- * in (buf1,eom1) and (buf2,eom2)?
- * returns:
- * -1 : format error
- * 0 : not a 1:1 mapping
- * >0 : is a 1:1 mapping
- * author:
- * paul vixie, 29may94
- */
-int
-res_queriesmatch(const u_char *buf1, const u_char *eom1,
- const u_char *buf2, const u_char *eom2)
-{
- const u_char *cp = buf1 + HFIXEDSZ;
- int qdcount = ntohs(((const HEADER*)buf1)->qdcount);
-
- if (buf1 + HFIXEDSZ > eom1 || buf2 + HFIXEDSZ > eom2)
- return (-1);
-
- /*
- * Only header section present in replies to
- * dynamic update packets.
- */
- if ((((const HEADER *)buf1)->opcode == ns_o_update) &&
- (((const HEADER *)buf2)->opcode == ns_o_update))
- return (1);
-
- if (qdcount != ntohs(((const HEADER*)buf2)->qdcount))
- return (0);
- while (qdcount-- > 0) {
- char tname[MAXDNAME+1];
- int n, ttype, tclass;
-
- n = dn_expand(buf1, eom1, cp, tname, sizeof tname);
- if (n < 0)
- return (-1);
- cp += n;
- if (cp + 2 * INT16SZ > eom1)
- return (-1);
- ttype = ns_get16(cp); cp += INT16SZ;
- tclass = ns_get16(cp); cp += INT16SZ;
- if (!res_nameinquery(tname, ttype, tclass, buf2, eom2))
- return (0);
- }
- return (1);
-}
-
-int
-res_nsend(res_state statp,
- const u_char *buf, int buflen, u_char *ans, int anssiz)
-{
- int gotsomewhere, terrno, try, v_circuit, resplen, ns, n;
- char abuf[NI_MAXHOST];
-
- if (statp->nscount == 0) {
- errno = ESRCH;
- return (-1);
- }
- if (anssiz < HFIXEDSZ) {
- errno = EINVAL;
- return (-1);
- }
- DprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_QUERY),
- (stdout, ";; res_send()\n"), buf, buflen);
- v_circuit = (statp->options & RES_USEVC) || buflen > PACKETSZ;
- gotsomewhere = 0;
- terrno = ETIMEDOUT;
-
- /*
- * If the ns_addr_list in the resolver context has changed, then
- * invalidate our cached copy and the associated timing data.
- */
- if (EXT(statp).nscount != 0) {
- int needclose = 0;
- struct sockaddr_storage peer;
- ISC_SOCKLEN_T peerlen;
-
- if (EXT(statp).nscount != statp->nscount)
- needclose++;
- else
- for (ns = 0; ns < statp->nscount; ns++) {
- if (statp->nsaddr_list[ns].sin_family &&
- !sock_eq((struct sockaddr *)&statp->nsaddr_list[ns],
- (struct sockaddr *)&EXT(statp).ext->nsaddrs[ns])) {
- needclose++;
- break;
- }
-
- if (EXT(statp).nssocks[ns] == -1)
- continue;
- peerlen = sizeof(peer);
- if (getsockname(EXT(statp).nssocks[ns],
- (struct sockaddr *)&peer, &peerlen) < 0) {
- needclose++;
- break;
- }
- if (!sock_eq((struct sockaddr *)&peer,
- get_nsaddr(statp, ns))) {
- needclose++;
- break;
- }
- }
- if (needclose) {
- res_nclose(statp);
- EXT(statp).nscount = 0;
- }
- }
-
- /*
- * Maybe initialize our private copy of the ns_addr_list.
- */
- if (EXT(statp).nscount == 0) {
- for (ns = 0; ns < statp->nscount; ns++) {
- EXT(statp).nstimes[ns] = RES_MAXTIME;
- EXT(statp).nssocks[ns] = -1;
- if (!statp->nsaddr_list[ns].sin_family)
- continue;
- EXT(statp).ext->nsaddrs[ns].sin =
- statp->nsaddr_list[ns];
- }
- EXT(statp).nscount = statp->nscount;
- }
-
- /*
- * Some resolvers want to even out the load on their nameservers.
- * Note that RES_BLAST overrides RES_ROTATE.
- */
- if ((statp->options & RES_ROTATE) != 0 &&
- (statp->options & RES_BLAST) == 0) {
- union res_sockaddr_union inu;
- struct sockaddr_in ina;
- int lastns = statp->nscount - 1;
- int fd;
- u_int16_t nstime;
-
- if (EXT(statp).ext != NULL)
- inu = EXT(statp).ext->nsaddrs[0];
- ina = statp->nsaddr_list[0];
- fd = EXT(statp).nssocks[0];
- nstime = EXT(statp).nstimes[0];
- for (ns = 0; ns < lastns; ns++) {
- if (EXT(statp).ext != NULL)
- EXT(statp).ext->nsaddrs[ns] =
- EXT(statp).ext->nsaddrs[ns + 1];
- statp->nsaddr_list[ns] = statp->nsaddr_list[ns + 1];
- EXT(statp).nssocks[ns] = EXT(statp).nssocks[ns + 1];
- EXT(statp).nstimes[ns] = EXT(statp).nstimes[ns + 1];
- }
- if (EXT(statp).ext != NULL)
- EXT(statp).ext->nsaddrs[lastns] = inu;
- statp->nsaddr_list[lastns] = ina;
- EXT(statp).nssocks[lastns] = fd;
- EXT(statp).nstimes[lastns] = nstime;
- }
-
- /*
- * Send request, RETRY times, or until successful.
- */
- for (try = 0; try < statp->retry; try++) {
- for (ns = 0; ns < statp->nscount; ns++) {
- struct sockaddr *nsap;
- int nsaplen;
- nsap = get_nsaddr(statp, ns);
- nsaplen = get_salen(nsap);
- statp->_flags &= ~RES_F_LASTMASK;
- statp->_flags |= (ns << RES_F_LASTSHIFT);
- same_ns:
- if (statp->qhook) {
- int done = 0, loops = 0;
-
- do {
- res_sendhookact act;
-
- act = (*statp->qhook)(&nsap, &buf, &buflen,
- ans, anssiz, &resplen);
- switch (act) {
- case res_goahead:
- done = 1;
- break;
- case res_nextns:
- res_nclose(statp);
- goto next_ns;
- case res_done:
- return (resplen);
- case res_modified:
- /* give the hook another try */
- if (++loops < 42) /*doug adams*/
- break;
- /*FALLTHROUGH*/
- case res_error:
- /*FALLTHROUGH*/
- default:
- goto fail;
- }
- } while (!done);
- }
-
- Dprint(((statp->options & RES_DEBUG) &&
- getnameinfo(nsap, nsaplen, abuf, sizeof(abuf),
- NULL, 0, niflags) == 0),
- (stdout, ";; Querying server (# %d) address = %s\n",
- ns + 1, abuf));
-
-
- if (v_circuit) {
- /* Use VC; at most one attempt per server. */
- try = statp->retry;
- n = send_vc(statp, buf, buflen, ans, anssiz, &terrno,
- ns);
- if (n < 0)
- goto fail;
- if (n == 0)
- goto next_ns;
- resplen = n;
- } else {
- /* Use datagrams. */
- n = send_dg(statp, buf, buflen, ans, anssiz, &terrno,
- ns, &v_circuit, &gotsomewhere);
- if (n < 0)
- goto fail;
- if (n == 0)
- goto next_ns;
- if (v_circuit)
- goto same_ns;
- resplen = n;
- }
-
- Dprint((statp->options & RES_DEBUG) ||
- ((statp->pfcode & RES_PRF_REPLY) &&
- (statp->pfcode & RES_PRF_HEAD1)),
- (stdout, ";; got answer:\n"));
-
- DprintQ((statp->options & RES_DEBUG) ||
- (statp->pfcode & RES_PRF_REPLY),
- (stdout, "%s", ""),
- ans, (resplen > anssiz) ? anssiz : resplen);
-
- /*
- * If we have temporarily opened a virtual circuit,
- * or if we haven't been asked to keep a socket open,
- * close the socket.
- */
- if ((v_circuit && (statp->options & RES_USEVC) == 0) ||
- (statp->options & RES_STAYOPEN) == 0) {
- res_nclose(statp);
- }
- if (statp->rhook) {
- int done = 0, loops = 0;
-
- do {
- res_sendhookact act;
-
- act = (*statp->rhook)(nsap, buf, buflen,
- ans, anssiz, &resplen);
- switch (act) {
- case res_goahead:
- case res_done:
- done = 1;
- break;
- case res_nextns:
- res_nclose(statp);
- goto next_ns;
- case res_modified:
- /* give the hook another try */
- if (++loops < 42) /*doug adams*/
- break;
- /*FALLTHROUGH*/
- case res_error:
- /*FALLTHROUGH*/
- default:
- goto fail;
- }
- } while (!done);
-
- }
- return (resplen);
- next_ns: ;
- } /*foreach ns*/
- } /*foreach retry*/
- res_nclose(statp);
- if (!v_circuit) {
- if (!gotsomewhere)
- errno = ECONNREFUSED; /* no nameservers found */
- else
- errno = ETIMEDOUT; /* no answer obtained */
- } else
- errno = terrno;
- return (-1);
- fail:
- res_nclose(statp);
- return (-1);
-}
-
-/* Private */
-
-static int
-get_salen(sa)
- const struct sockaddr *sa;
-{
-
-#ifdef HAVE_SA_LEN
- /* There are people do not set sa_len. Be forgiving to them. */
- if (sa->sa_len)
- return (sa->sa_len);
-#endif
-
- if (sa->sa_family == AF_INET)
- return (sizeof(struct sockaddr_in));
- else if (sa->sa_family == AF_INET6)
- return (sizeof(struct sockaddr_in6));
- else
- return (0); /* unknown, die on connect */
-}
-
-/*
- * pick appropriate nsaddr_list for use. see res_init() for initialization.
- */
-static struct sockaddr *
-get_nsaddr(statp, n)
- res_state statp;
- size_t n;
-{
-
- if (!statp->nsaddr_list[n].sin_family && EXT(statp).ext) {
- /*
- * - EXT(statp).ext->nsaddrs[n] holds an address that is larger
- * than struct sockaddr, and
- * - user code did not update statp->nsaddr_list[n].
- */
- return (struct sockaddr *)(void *)&EXT(statp).ext->nsaddrs[n];
- } else {
- /*
- * - user code updated statp->nsaddr_list[n], or
- * - statp->nsaddr_list[n] has the same content as
- * EXT(statp).ext->nsaddrs[n].
- */
- return (struct sockaddr *)(void *)&statp->nsaddr_list[n];
- }
-}
-
-static int
-send_vc(res_state statp,
- const u_char *buf, int buflen, u_char *ans, int anssiz,
- int *terrno, int ns)
-{
- const HEADER *hp = (const HEADER *) buf;
- HEADER *anhp = (HEADER *) ans;
- struct sockaddr *nsap;
- int nsaplen;
- int truncating, connreset, resplen, n;
- struct iovec iov[2];
- u_short len;
- u_char *cp;
- void *tmp;
-
- nsap = get_nsaddr(statp, ns);
- nsaplen = get_salen(nsap);
-
- connreset = 0;
- same_ns:
- truncating = 0;
-
- /* Are we still talking to whom we want to talk to? */
- if (statp->_vcsock >= 0 && (statp->_flags & RES_F_VC) != 0) {
- struct sockaddr_storage peer;
- ISC_SOCKLEN_T size = sizeof peer;
-
- if (getpeername(statp->_vcsock,
- (struct sockaddr *)&peer, &size) < 0 ||
- !sock_eq((struct sockaddr *)&peer, nsap)) {
- res_nclose(statp);
- statp->_flags &= ~RES_F_VC;
- }
- }
-
- if (statp->_vcsock < 0 || (statp->_flags & RES_F_VC) == 0) {
- if (statp->_vcsock >= 0)
- res_nclose(statp);
-
- statp->_vcsock = socket(nsap->sa_family, SOCK_STREAM, 0);
- if (statp->_vcsock > highestFD) {
- res_nclose(statp);
- errno = ENOTSOCK;
- }
- if (statp->_vcsock < 0) {
- *terrno = errno;
- Perror(statp, stderr, "socket(vc)", errno);
- return (-1);
- }
- errno = 0;
- if (connect(statp->_vcsock, nsap, nsaplen) < 0) {
- *terrno = errno;
- Aerror(statp, stderr, "connect/vc", errno, nsap,
- nsaplen);
- res_nclose(statp);
- return (0);
- }
- statp->_flags |= RES_F_VC;
- }
-
- /*
- * Send length & message
- */
- ns_put16((u_short)buflen, (u_char*)&len);
- iov[0] = evConsIovec(&len, INT16SZ);
- DE_CONST(buf, tmp);
- iov[1] = evConsIovec(tmp, buflen);
- if (writev(statp->_vcsock, iov, 2) != (INT16SZ + buflen)) {
- *terrno = errno;
- Perror(statp, stderr, "write failed", errno);
- res_nclose(statp);
- return (0);
- }
- /*
- * Receive length & response
- */
- read_len:
- cp = ans;
- len = INT16SZ;
- while ((n = read(statp->_vcsock, (char *)cp, (int)len)) > 0) {
- cp += n;
- if ((len -= n) <= 0)
- break;
- }
- if (n <= 0) {
- *terrno = errno;
- Perror(statp, stderr, "read failed", errno);
- res_nclose(statp);
- /*
- * A long running process might get its TCP
- * connection reset if the remote server was
- * restarted. Requery the server instead of
- * trying a new one. When there is only one
- * server, this means that a query might work
- * instead of failing. We only allow one reset
- * per query to prevent looping.
- */
- if (*terrno == ECONNRESET && !connreset) {
- connreset = 1;
- res_nclose(statp);
- goto same_ns;
- }
- res_nclose(statp);
- return (0);
- }
- resplen = ns_get16(ans);
- if (resplen > anssiz) {
- Dprint(statp->options & RES_DEBUG,
- (stdout, ";; response truncated\n")
- );
- truncating = 1;
- len = anssiz;
- } else
- len = resplen;
- if (len < HFIXEDSZ) {
- /*
- * Undersized message.
- */
- Dprint(statp->options & RES_DEBUG,
- (stdout, ";; undersized: %d\n", len));
- *terrno = EMSGSIZE;
- res_nclose(statp);
- return (0);
- }
- cp = ans;
- while (len != 0 && (n = read(statp->_vcsock, (char *)cp, (int)len)) > 0){
- cp += n;
- len -= n;
- }
- if (n <= 0) {
- *terrno = errno;
- Perror(statp, stderr, "read(vc)", errno);
- res_nclose(statp);
- return (0);
- }
- if (truncating) {
- /*
- * Flush rest of answer so connection stays in synch.
- */
- anhp->tc = 1;
- len = resplen - anssiz;
- while (len != 0) {
- char junk[PACKETSZ];
-
- n = read(statp->_vcsock, junk,
- (len > sizeof junk) ? sizeof junk : len);
- if (n > 0)
- len -= n;
- else
- break;
- }
- }
- /*
- * If the calling applicating has bailed out of
- * a previous call and failed to arrange to have
- * the circuit closed or the server has got
- * itself confused, then drop the packet and
- * wait for the correct one.
- */
- if (hp->id != anhp->id) {
- DprintQ((statp->options & RES_DEBUG) ||
- (statp->pfcode & RES_PRF_REPLY),
- (stdout, ";; old answer (unexpected):\n"),
- ans, (resplen > anssiz) ? anssiz: resplen);
- goto read_len;
- }
-
- /*
- * All is well, or the error is fatal. Signal that the
- * next nameserver ought not be tried.
- */
- return (resplen);
-}
-
-static int
-send_dg(res_state statp,
- const u_char *buf, int buflen, u_char *ans, int anssiz,
- int *terrno, int ns, int *v_circuit, int *gotsomewhere)
-{
- const HEADER *hp = (const HEADER *) buf;
- HEADER *anhp = (HEADER *) ans;
- const struct sockaddr *nsap;
- int nsaplen;
- struct timespec now, timeout, finish;
- fd_set dsmask;
- struct sockaddr_storage from;
- ISC_SOCKLEN_T fromlen;
- int resplen, seconds, n, s;
-
- nsap = get_nsaddr(statp, ns);
- nsaplen = get_salen(nsap);
- if (EXT(statp).nssocks[ns] == -1) {
- EXT(statp).nssocks[ns] = socket(nsap->sa_family, SOCK_DGRAM, 0);
- if (EXT(statp).nssocks[ns] > highestFD) {
- res_nclose(statp);
- errno = ENOTSOCK;
- }
- if (EXT(statp).nssocks[ns] < 0) {
- *terrno = errno;
- Perror(statp, stderr, "socket(dg)", errno);
- return (-1);
- }
-#ifndef CANNOT_CONNECT_DGRAM
- /*
- * On a 4.3BSD+ machine (client and server,
- * actually), sending to a nameserver datagram
- * port with no nameserver will cause an
- * ICMP port unreachable message to be returned.
- * If our datagram socket is "connected" to the
- * server, we get an ECONNREFUSED error on the next
- * socket operation, and select returns if the
- * error message is received. We can thus detect
- * the absence of a nameserver without timing out.
- */
- if (connect(EXT(statp).nssocks[ns], nsap, nsaplen) < 0) {
- Aerror(statp, stderr, "connect(dg)", errno, nsap,
- nsaplen);
- res_nclose(statp);
- return (0);
- }
-#endif /* !CANNOT_CONNECT_DGRAM */
- Dprint(statp->options & RES_DEBUG,
- (stdout, ";; new DG socket\n"))
- }
- s = EXT(statp).nssocks[ns];
-#ifndef CANNOT_CONNECT_DGRAM
- if (send(s, (const char*)buf, buflen, 0) != buflen) {
- Perror(statp, stderr, "send", errno);
- res_nclose(statp);
- return (0);
- }
-#else /* !CANNOT_CONNECT_DGRAM */
- if (sendto(s, (const char*)buf, buflen, 0, nsap, nsaplen) != buflen)
- {
- Aerror(statp, stderr, "sendto", errno, nsap, nsaplen);
- res_nclose(statp);
- return (0);
- }
-#endif /* !CANNOT_CONNECT_DGRAM */
-
- /*
- * Wait for reply.
- */
- seconds = (statp->retrans << ns);
- if (ns > 0)
- seconds /= statp->nscount;
- if (seconds <= 0)
- seconds = 1;
- now = evNowTime();
- timeout = evConsTime(seconds, 0);
- finish = evAddTime(now, timeout);
- goto nonow;
- wait:
- now = evNowTime();
- nonow:
- FD_ZERO(&dsmask);
- FD_SET(s, &dsmask);
- if (evCmpTime(finish, now) > 0)
- timeout = evSubTime(finish, now);
- else
- timeout = evConsTime(0, 0);
- n = pselect(s + 1, &dsmask, NULL, NULL, &timeout, NULL);
- if (n == 0) {
- Dprint(statp->options & RES_DEBUG, (stdout, ";; timeout\n"));
- *gotsomewhere = 1;
- return (0);
- }
- if (n < 0) {
- if (errno == EINTR)
- goto wait;
- Perror(statp, stderr, "select", errno);
- res_nclose(statp);
- return (0);
- }
- errno = 0;
- fromlen = sizeof(from);
- resplen = recvfrom(s, (char*)ans, anssiz,0,
- (struct sockaddr *)&from, &fromlen);
- if (resplen <= 0) {
- Perror(statp, stderr, "recvfrom", errno);
- res_nclose(statp);
- return (0);
- }
- *gotsomewhere = 1;
- if (resplen < HFIXEDSZ) {
- /*
- * Undersized message.
- */
- Dprint(statp->options & RES_DEBUG,
- (stdout, ";; undersized: %d\n",
- resplen));
- *terrno = EMSGSIZE;
- res_nclose(statp);
- return (0);
- }
- if (hp->id != anhp->id) {
- /*
- * response from old query, ignore it.
- * XXX - potential security hazard could
- * be detected here.
- */
- DprintQ((statp->options & RES_DEBUG) ||
- (statp->pfcode & RES_PRF_REPLY),
- (stdout, ";; old answer:\n"),
- ans, (resplen > anssiz) ? anssiz : resplen);
- goto wait;
- }
- if (!(statp->options & RES_INSECURE1) &&
- !res_ourserver_p(statp, (struct sockaddr *)&from)) {
- /*
- * response from wrong server? ignore it.
- * XXX - potential security hazard could
- * be detected here.
- */
- DprintQ((statp->options & RES_DEBUG) ||
- (statp->pfcode & RES_PRF_REPLY),
- (stdout, ";; not our server:\n"),
- ans, (resplen > anssiz) ? anssiz : resplen);
- goto wait;
- }
-#ifdef RES_USE_EDNS0
- if (anhp->rcode == FORMERR && (statp->options & RES_USE_EDNS0) != 0) {
- /*
- * Do not retry if the server do not understand EDNS0.
- * The case has to be captured here, as FORMERR packet do not
- * carry query section, hence res_queriesmatch() returns 0.
- */
- DprintQ(statp->options & RES_DEBUG,
- (stdout, "server rejected query with EDNS0:\n"),
- ans, (resplen > anssiz) ? anssiz : resplen);
- /* record the error */
- statp->_flags |= RES_F_EDNS0ERR;
- res_nclose(statp);
- return (0);
- }
-#endif
- if (!(statp->options & RES_INSECURE2) &&
- !res_queriesmatch(buf, buf + buflen,
- ans, ans + anssiz)) {
- /*
- * response contains wrong query? ignore it.
- * XXX - potential security hazard could
- * be detected here.
- */
- DprintQ((statp->options & RES_DEBUG) ||
- (statp->pfcode & RES_PRF_REPLY),
- (stdout, ";; wrong query name:\n"),
- ans, (resplen > anssiz) ? anssiz : resplen);
- goto wait;
- }
- if (anhp->rcode == SERVFAIL ||
- anhp->rcode == NOTIMP ||
- anhp->rcode == REFUSED) {
- DprintQ(statp->options & RES_DEBUG,
- (stdout, "server rejected query:\n"),
- ans, (resplen > anssiz) ? anssiz : resplen);
- res_nclose(statp);
- /* don't retry if called from dig */
- if (!statp->pfcode)
- return (0);
- }
- if (!(statp->options & RES_IGNTC) && anhp->tc) {
- /*
- * To get the rest of answer,
- * use TCP with same server.
- */
- Dprint(statp->options & RES_DEBUG,
- (stdout, ";; truncated answer\n"));
- *v_circuit = 1;
- res_nclose(statp);
- return (1);
- }
- /*
- * All is well, or the error is fatal. Signal that the
- * next nameserver ought not be tried.
- */
- return (resplen);
-}
-
-static void
-Aerror(const res_state statp, FILE *file, const char *string, int error,
- const struct sockaddr *address, int alen)
-{
- int save = errno;
- char hbuf[NI_MAXHOST];
- char sbuf[NI_MAXSERV];
-
- alen = alen;
-
- if ((statp->options & RES_DEBUG) != 0) {
- if (getnameinfo(address, alen, hbuf, sizeof(hbuf),
- sbuf, sizeof(sbuf), niflags)) {
- strncpy(hbuf, "?", sizeof(hbuf) - 1);
- hbuf[sizeof(hbuf) - 1] = '\0';
- strncpy(sbuf, "?", sizeof(sbuf) - 1);
- sbuf[sizeof(sbuf) - 1] = '\0';
- }
- fprintf(file, "res_send: %s ([%s].%s): %s\n",
- string, hbuf, sbuf, strerror(error));
- }
- errno = save;
-}
-
-static void
-Perror(const res_state statp, FILE *file, const char *string, int error) {
- int save = errno;
-
- if ((statp->options & RES_DEBUG) != 0)
- fprintf(file, "res_send: %s: %s\n",
- string, strerror(error));
- errno = save;
-}
-
-static int
-sock_eq(struct sockaddr *a, struct sockaddr *b) {
- struct sockaddr_in *a4, *b4;
- struct sockaddr_in6 *a6, *b6;
-
- if (a->sa_family != b->sa_family)
- return 0;
- switch (a->sa_family) {
- case AF_INET:
- a4 = (struct sockaddr_in *)a;
- b4 = (struct sockaddr_in *)b;
- return a4->sin_port == b4->sin_port &&
- a4->sin_addr.s_addr == b4->sin_addr.s_addr;
- case AF_INET6:
- a6 = (struct sockaddr_in6 *)a;
- b6 = (struct sockaddr_in6 *)b;
- return a6->sin6_port == b6->sin6_port &&
-#ifdef HAVE_SIN6_SCOPE_ID
- a6->sin6_scope_id == b6->sin6_scope_id &&
-#endif
- IN6_ARE_ADDR_EQUAL(&a6->sin6_addr, &b6->sin6_addr);
- default:
- return 0;
- }
-}
-
-#ifdef NEED_PSELECT
-/* XXX needs to move to the porting library. */
-static int
-pselect(int nfds, void *rfds, void *wfds, void *efds,
- struct timespec *tsp, const sigset_t *sigmask)
-{
- struct timeval tv, *tvp;
- sigset_t sigs;
- int n;
-
- if (tsp) {
- tvp = &tv;
- tv = evTimeVal(*tsp);
- } else
- tvp = NULL;
- if (sigmask)
- sigprocmask(SIG_SETMASK, sigmask, &sigs);
- n = select(nfds, rfds, wfds, efds, tvp);
- if (sigmask)
- sigprocmask(SIG_SETMASK, &sigs, NULL);
- if (tsp)
- *tsp = evTimeSpec(tv);
- return (n);
-}
-#endif
diff --git a/contrib/bind/lib/resolv/res_sendsigned.c b/contrib/bind/lib/resolv/res_sendsigned.c
deleted file mode 100644
index b450926..0000000
--- a/contrib/bind/lib/resolv/res_sendsigned.c
+++ /dev/null
@@ -1,134 +0,0 @@
-#include "port_before.h"
-#include "fd_setsize.h"
-
-#include <sys/types.h>
-#include <sys/param.h>
-
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <arpa/inet.h>
-
-#include <isc/dst.h>
-
-#include <errno.h>
-#include <netdb.h>
-#include <resolv.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "port_after.h"
-
-#define DEBUG
-#include "res_debug.h"
-
-
-/* res_nsendsigned */
-int
-res_nsendsigned(res_state statp, const u_char *msg, int msglen,
- ns_tsig_key *key, u_char *answer, int anslen)
-{
- res_state nstatp;
- DST_KEY *dstkey;
- int usingTCP = 0;
- u_char *newmsg;
- int newmsglen, bufsize, siglen;
- u_char sig[64];
- HEADER *hp;
- time_t tsig_time;
- int ret;
-
- dst_init();
-
- nstatp = (res_state) malloc(sizeof(*statp));
- if (nstatp == NULL) {
- errno = ENOMEM;
- return (-1);
- }
- memcpy(nstatp, statp, sizeof(*statp));
-
- bufsize = msglen + 1024;
- newmsg = (u_char *) malloc(bufsize);
- if (newmsg == NULL) {
- errno = ENOMEM;
- return (-1);
- }
- memcpy(newmsg, msg, msglen);
- newmsglen = msglen;
-
- if (ns_samename(key->alg, NS_TSIG_ALG_HMAC_MD5) != 1)
- dstkey = NULL;
- else
- dstkey = dst_buffer_to_key(key->name, KEY_HMAC_MD5,
- NS_KEY_TYPE_AUTH_ONLY,
- NS_KEY_PROT_ANY,
- key->data, key->len);
- if (dstkey == NULL) {
- errno = EINVAL;
- free(nstatp);
- free(newmsg);
- return (-1);
- }
-
- nstatp->nscount = 1;
- siglen = sizeof(sig);
- ret = ns_sign(newmsg, &newmsglen, bufsize, NOERROR, dstkey, NULL, 0,
- sig, &siglen, 0);
- if (ret < 0) {
- free (nstatp);
- free (newmsg);
- dst_free_key(dstkey);
- if (ret == NS_TSIG_ERROR_NO_SPACE)
- errno = EMSGSIZE;
- else if (ret == -1)
- errno = EINVAL;
- return (ret);
- }
-
- if (newmsglen > PACKETSZ || (nstatp->options & RES_IGNTC))
- usingTCP = 1;
- if (usingTCP == 0)
- nstatp->options |= RES_IGNTC;
- else
- nstatp->options |= RES_USEVC;
-
-retry:
-
- ret = res_nsend(nstatp, newmsg, newmsglen, answer, anslen);
- if (ret < 0) {
- free (nstatp);
- free (newmsg);
- dst_free_key(dstkey);
- return (ret);
- }
-
- anslen = ret;
- ret = ns_verify(answer, &anslen, dstkey, sig, siglen,
- NULL, NULL, &tsig_time, nstatp->options & RES_KEEPTSIG);
- if (ret != 0) {
- Dprint(nstatp->pfcode & RES_PRF_REPLY,
- (stdout, ";; TSIG invalid (%s)\n", p_rcode(ret)));
- free (nstatp);
- free (newmsg);
- dst_free_key(dstkey);
- if (ret == -1)
- errno = EINVAL;
- else
- errno = ENOTTY;
- return (-1);
- }
- Dprint(nstatp->pfcode & RES_PRF_REPLY, (stdout, ";; TSIG ok\n"));
-
- hp = (HEADER *) answer;
- if (hp->tc && usingTCP == 0) {
- nstatp->options &= ~RES_IGNTC;
- usingTCP = 1;
- goto retry;
- }
-
- free (nstatp);
- free (newmsg);
- dst_free_key(dstkey);
- return (anslen);
-}
diff --git a/contrib/bind/lib/resolv/res_update.c b/contrib/bind/lib/resolv/res_update.c
deleted file mode 100644
index 35c9b07..0000000
--- a/contrib/bind/lib/resolv/res_update.c
+++ /dev/null
@@ -1,212 +0,0 @@
-#if !defined(lint) && !defined(SABER)
-static const char rcsid[] = "$Id: res_update.c,v 1.35.8.2 2003/06/02 09:24:40 marka Exp $";
-#endif /* not lint */
-
-/*
- * Copyright (c) 1996-1999 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 "port_before.h"
-
-#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 <errno.h>
-#include <limits.h>
-#include <netdb.h>
-#include <res_update.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <isc/list.h>
-#include <resolv.h>
-
-#include "port_after.h"
-#include "res_private.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.
- */
-
-struct zonegrp {
- char z_origin[MAXDNAME];
- ns_class z_class;
- union res_sockaddr_union z_nsaddrs[MAXNS];
- int z_nscount;
- int z_flags;
- LIST(ns_updrec) z_rrlist;
- LINK(struct zonegrp) z_link;
-};
-
-#define ZG_F_ZONESECTADDED 0x0001
-
-/* Forward. */
-
-static void res_dprintf(const char *, ...) ISC_FORMAT_PRINTF(1, 2);
-
-/* Macros. */
-
-#define DPRINTF(x) do {\
- int save_errno = errno; \
- if ((statp->options & RES_DEBUG) != 0) res_dprintf x; \
- errno = save_errno; \
- } while (0)
-
-/* Public. */
-
-int
-res_nupdate(res_state statp, ns_updrec *rrecp_in, ns_tsig_key *key) {
- ns_updrec *rrecp;
- u_char answer[PACKETSZ];
- u_char *packet;
- struct zonegrp *zptr, tgrp;
- LIST(struct zonegrp) zgrps;
- int nzones = 0, nscount = 0, n;
- union res_sockaddr_union nsaddrs[MAXNS];
-
- packet = malloc(NS_MAXMSG);
- if (packet == NULL) {
- DPRINTF(("malloc failed"));
- return (0);
- }
- /* Thread all of the updates onto a list of groups. */
- INIT_LIST(zgrps);
- memset(&tgrp, 0, sizeof (tgrp));
- for (rrecp = rrecp_in; rrecp;
- rrecp = LINKED(rrecp, r_link) ? NEXT(rrecp, r_link) : NULL) {
- int nscnt;
- /* Find the origin for it if there is one. */
- tgrp.z_class = rrecp->r_class;
- nscnt = res_findzonecut2(statp, rrecp->r_dname, tgrp.z_class,
- RES_EXHAUSTIVE, tgrp.z_origin,
- sizeof tgrp.z_origin,
- tgrp.z_nsaddrs, MAXNS);
- if (nscnt <= 0) {
- DPRINTF(("res_findzonecut failed (%d)", nscnt));
- goto done;
- }
- tgrp.z_nscount = nscnt;
- /* Find the group for it if there is one. */
- for (zptr = HEAD(zgrps); zptr != NULL; zptr = NEXT(zptr, z_link))
- if (ns_samename(tgrp.z_origin, zptr->z_origin) == 1 &&
- tgrp.z_class == zptr->z_class)
- break;
- /* Make a group for it if there isn't one. */
- if (zptr == NULL) {
- zptr = malloc(sizeof *zptr);
- if (zptr == NULL) {
- DPRINTF(("malloc failed"));
- goto done;
- }
- *zptr = tgrp;
- zptr->z_flags = 0;
- INIT_LINK(zptr, z_link);
- INIT_LIST(zptr->z_rrlist);
- APPEND(zgrps, zptr, z_link);
- }
- /* Thread this rrecp onto the right group. */
- APPEND(zptr->z_rrlist, rrecp, r_glink);
- }
-
- for (zptr = HEAD(zgrps); zptr != NULL; zptr = NEXT(zptr, z_link)) {
- /* Construct zone section and prepend it. */
- rrecp = res_mkupdrec(ns_s_zn, zptr->z_origin,
- zptr->z_class, ns_t_soa, 0);
- if (rrecp == NULL) {
- DPRINTF(("res_mkupdrec failed"));
- goto done;
- }
- PREPEND(zptr->z_rrlist, rrecp, r_glink);
- zptr->z_flags |= ZG_F_ZONESECTADDED;
-
- /* Marshall the update message. */
- n = res_nmkupdate(statp, HEAD(zptr->z_rrlist),
- packet, NS_MAXMSG);
- DPRINTF(("res_mkupdate -> %d", n));
- if (n < 0)
- goto done;
-
- /* Temporarily replace the resolver's nameserver set. */
- nscount = res_getservers(statp, nsaddrs, MAXNS);
- res_setservers(statp, zptr->z_nsaddrs, zptr->z_nscount);
-
- /* Send the update and remember the result. */
- if (key != NULL)
- n = res_nsendsigned(statp, packet, n, key,
- answer, sizeof answer);
- else
- n = res_nsend(statp, packet, n, answer, sizeof answer);
- if (n < 0) {
- DPRINTF(("res_nsend: send error, n=%d (%s)\n",
- n, strerror(errno)));
- goto done;
- }
- if (((HEADER *)answer)->rcode == NOERROR)
- nzones++;
-
- /* Restore resolver's nameserver set. */
- res_setservers(statp, nsaddrs, nscount);
- nscount = 0;
- }
- done:
- while (!EMPTY(zgrps)) {
- zptr = HEAD(zgrps);
- if ((zptr->z_flags & ZG_F_ZONESECTADDED) != 0)
- res_freeupdrec(HEAD(zptr->z_rrlist));
- UNLINK(zgrps, zptr, z_link);
- free(zptr);
- }
- if (nscount != 0)
- res_setservers(statp, nsaddrs, nscount);
-
- free(packet);
- return (nzones);
-}
-
-/* Private. */
-
-static void
-res_dprintf(const char *fmt, ...) {
- va_list ap;
-
- va_start(ap, fmt);
- fputs(";; res_nupdate: ", stderr);
- vfprintf(stderr, fmt, ap);
- fputc('\n', stderr);
- va_end(ap);
-}
OpenPOWER on IntegriCloud