Compare commits

..

1 Commits

Author SHA1 Message Date
cvs2git
c04a3d879c This commit was manufactured by cvs2git to create tag 'v9_0_0a2'. 1999-09-08 18:25:35 +00:00
1434 changed files with 1115 additions and 443948 deletions

View File

@@ -1,7 +0,0 @@
Makefile
config.log
config.h
config.cache
config.status
libtool
isc-config.sh

1701
CHANGES

File diff suppressed because it is too large Load Diff

View File

@@ -1,14 +0,0 @@
Copyright (C) 1996-2000 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.

View File

@@ -1,69 +0,0 @@
# Copyright (C) 1998-2000 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.in,v 1.21.2.6 2000/07/27 01:48:49 gson Exp $
srcdir = @srcdir@
VPATH = @srcdir@
top_srcdir = @top_srcdir@
@BIND9_VERSION@
SUBDIRS = make lib bin
TARGETS =
DISTFILES = CHANGES COPYRIGHT Makefile.in README \
acconfig.h aclocal.m4 config.guess config.h.in config.h.win32 \
config.status.win32 config.sub configure configure.in \
isc-config.sh.in install-sh libtool.m4 ltconfig ltmain.sh \
lib make contrib \
version
DOCDISTFILES = arm draft misc rfc
DOCMANDISTFILES = bin dnssec
BINDISTFILES = Makefile.in dig dnssec named nsupdate rndc tests
@BIND9_MAKE_RULES@
distclean::
rm -f config.cache config.h config.log config.status TAGS
rm -f libtool isc-config.sh
rm -f util/conf.sh
cleandir: distclean
install:: isc-config.sh
${INSTALL_PROGRAM} isc-config.sh ${DESTDIR}${bindir}
kit: kitclean
mkdir bind-${VERSION}
@(cd bind-${VERSION}; for i in ${DISTFILES}; do ln -s ../$$i $$i; done)
mkdir bind-${VERSION}/doc
@(cd bind-${VERSION}/doc; for i in ${DOCDISTFILES}; do \
ln -s ../../doc/$$i $$i; done)
mkdir bind-${VERSION}/doc/man
@(cd bind-${VERSION}/doc/man; for i in ${DOCMANDISTFILES}; do \
ln -s ../../../doc/man/$$i $$i; done)
mkdir bind-${VERSION}/bin
@(cd bind-${VERSION}/bin; for i in ${BINDISTFILES}; do \
ln -s ../../bin/$$i $$i; done)
gtar -c -v -z -h --exclude '*CVS*' -f bind-${VERSION}.tar.gz \
bind-${VERSION}
rm -rf bind-${VERSION}
kitclean: distclean
rm -rf bind-${VERSION}
tags:
rm -f TAGS
find lib bin -name "*.[ch]" -print | @ETAGS@ -

215
README
View File

@@ -1,215 +0,0 @@
BIND 9
BIND version 9 is a major rewrite of nearly all aspects of the
underlying BIND architecture. Some of the important features of
BIND 9 are:
- DNS Security
DNSSEC (signed zones)
TSIG (signed DNS requests)
- IP version 6
Answers DNS queries on IPv6 sockets
IPv6 resource records (A6, DNAME, etc.)
Bitstring Labels
Experimental IPv6 Resolver Library
- DNS Protocol Enhancements
IXFR, DDNS, Notify, EDNS0
Improved standards conformance
- Views
One server process can provide multiple "views" of
the DNS namespace, e.g. an "inside" view to certain
clients, and an "outside" view to others.
- Multiprocessor Support
- Improved Portability Architecture
BIND version 9 development has been underwritten by the following
organizations:
Sun Microsystems, Inc.
Hewlett Packard
Compaq Computer Corporation
IBM
Process Software Corporation
Silicon Graphics, Inc.
Network Associates, Inc.
U.S. Defense Information Systems Agency
USENIX Association
Stichting NLnet - NLnet Foundation
BIND 9.0.1
BIND 9.0.1 is a maintenance release, containing fixes for a
number of bugs in BIND 9.0.0 but no new features (with the
exception of a few minor features added to dig, host, and
nslookup).
Like BIND 9.0.0, BIND 9.0.1 is primarily a name server software
distribution. In addition to the name server, it also includes
a new lightweight stub resolver library and associated resolver
daemon that fully support forward and reverse lookups of both
IPv4 and IPv6 addresses. This library is still considered
experimental and is not a complete replacement for the BIND 8
resolver library. In particular, applications that use the
BIND 8 res_* functions to perform DNS queries or dynamic
updates still need to be linked against the BIND 8 libraries.
BIND 9.0.1 is capable of acting as an authoritative server
for DNSSEC secured zones. This functionality is believed to
be stable and complete except for lacking support for wildcard
records in secure zones.
When acting as a caching server, BIND 9.0.1 can be configured
to perform DNSSEC secure resolution on behalf of its clients.
This part of the DNSSEC implementation is still considered
experimental. For detailed information about the state of the
DNSSEC implementation, see the file doc/misc/dnssec.
There are a few known bugs:
The option "query-source * port 53;" will not work as
expected. Instead of the wildcard address "*", you need
to use an explicit source IP address.
On some systems, IPv6 and IPv4 sockets interact in
unexpected ways. For details, see doc/misc/ipv6.
To reduce the impact of these problems, the server
no longer listens for requests on IPv6 addresses
by default. If you need to accept DNS queries over
IPv6, you must specify "listen-on-v6 { any; };"
in the named.conf options statement.
There are known problems with thread signal handling
under Solaris 2.6.
The "isc_timer_reset" test sometimes fails on HP-UX 11
for unknown reasons, but the server itself seems to
run fine.
On FreeBSD systems, the server logs error messages
like "fcntl(8, F_SETFL, 4): Inappropriate ioctl for
device". This is due to a bug in the FreeBSD
/dev/random device. The bug has been reported
to the FreeBSD maintainers. Versions of OpenBSD
prior to 2.8 have a similar problem.
The configure option --disable-ipv6 is not functional.
--with-libtool does not work on AIX.
Due to bugs in the dnssafe library, RSA keys longer
than 2000 bits are not supported.
Building
BIND 9 currently requires a UNIX system with an ANSI C compiler,
basic POSIX support, and a good pthreads implementation.
We've had successful builds and tests on the following systems:
AIX 4.3
COMPAQ Tru64 UNIX 4.0D
COMPAQ Tru64 UNIX 5 (with IPv6 EAK)
FreeBSD 3.4-STABLE
HP-UX 11
IRIX64 6.5
NetBSD-current (with unproven-pthreads-0.17)
Red Hat Linux 6.0, 6.1, 6.2
Solaris 2.6, 7, 8
Additionally, we have unverified reports of success from users
of the following systems:
Slackware Linux 7.0 with 2.4.0-test6 kernel and glibc 2.1.3
Slackware Linux 7.0.1 with glibc 2.1.3
OpenBSD 2.6, 2.8, -current
To build, just
./configure
make
Several environment variables that can be set before running
configure will affect compilation:
CC
The C compiler to use. configure tries to figure
out the right one for supported systems.
CFLAGS
C compiler flags. Defaults to include -g and/or -O2
as supported by the compiler.
STD_CINCLUDES
System header file directories. Can be used to specify
where add-on thread or IPv6 support is, for example.
Defaults to empty string.
STD_CDEFINES
Any additional preprocessor symbols you want defined.
Defaults to empty string.
To build shared libraries, specify "--with-libtool" on the
configure command line.
If your operating system has integrated support for IPv6, it
will be used automatically. If you have installed KAME IPv6
separately, use "--with-kame[=PATH]" to specify its location.
To see additional configure options, run "configure --help".
"make install" will install "named" and the various BIND 9 libraries.
By default, installation is into /usr/local, but this can be changed
with the "--prefix" option when running "configure".
If you're planning on making changes to the BIND 9 source, you
should also "make depend". If you're using Emacs, you might find
"make tags" helpful.
Building with gcc is not supported, unless gcc is the vendor's usual
compiler (e.g. the various BSD systems, Linux).
Parts of the library can be tested by running "make test" from the
bin/tests subdirectory.
Documentation
The BIND 9 Administrator Reference Manual is included with the
source distribution in DocBook XML and HTML format, in the
doc/arm directory.
Some of the programs in the BIND 9 distribution have man pages
under the doc/man directory. In particular, the command line
options of "named" are documented in doc/man/bind/named.8.
The man pages are currently not installed automatically by
"make install".
If you are upgrading from BIND 8, please read the migration
notes in doc/misc/migration.
Bug Reports and Mailing Lists
Bugs reports should be sent to
bind9-bugs@isc.org
To join the BIND 9 Users mailing list, send mail to
bind9-users-request@isc.org
If you're planning on making changes to the BIND 9 source
code, you might want to join the BIND 9 Workers mailing list.
Send mail to
bind9-workers-request@isc.org

18
TODO
View File

@@ -1,18 +0,0 @@
1. Rdataset/Rdatalist Union
2. ev_ prefix for ISC_EVENT_COMMON
3. Finish mempool conversion of message.c
4. Improve buffer & region APIs (inline?)
5. isc/util.h publish or perish
6. magic number listing
7. Eliminate dns_result_t and old DNS_R_ codes
8. Check base 64 code; does it have the problems that
the BIND 8 code does?
9. Authority is optional if we have answers?
10. AD bit setting.
11. KEY duplication (answer + additional) in any query
12. Fix rdata META flag to be set for TSIG, TKEY, OPT
13. Intergrate (replace?) old per zone SOA timers with zomemgr
14. RWlock for zonemgr zone list
15. CHAOS A's
16. implement "doc" checks out of zonemgr.

View File

@@ -1,104 +0,0 @@
/*
* Copyright (C) 1999, 2000 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: acconfig.h,v 1.23 2000/06/22 21:48:56 tale Exp $ */
/***
*** This file is not to be included by any public header files, because
*** it does not get installed.
***/
@TOP@
/* define on DEC OSF to enable 4.4BSD style sa_len support */
#undef _SOCKADDR_LEN
/* define if your system needs pthread_init() before using pthreads */
#undef NEED_PTHREAD_INIT
/* define if your system has sigwait() */
#undef HAVE_SIGWAIT
/* define if sigwait() is the UnixWare flavor */
#undef HAVE_UNIXWARE_SIGWAIT
/* define on Solaris to get sigwait() to work using pthreads semantics */
#undef _POSIX_PTHREAD_SEMANTICS
/* define if LinuxThreads is in use */
#undef HAVE_LINUXTHREADS
/* define if sysconf() is available */
#undef HAVE_SYSCONF
/* define if catgets() is available */
#undef HAVE_CATGETS
/* define if you have the NET_RT_IFLIST sysctl variable. */
#undef HAVE_IFLIST_SYSCTL
/* define if you need to #define _XPG4_2 before including sys/socket.h */
#undef NEED_XPG4_2_BEFORE_SOCKET_H
/* define if you need to #define _XOPEN_SOURCE_ENTENDED before including
* sys/socket.h
*/
#undef NEED_XSE_BEFORE_SOCKET_H
/* define if chroot() is available */
#undef HAVE_CHROOT
/* define if struct addrinfo exists */
#undef HAVE_ADDRINFO
/* define is getaddrinfo() exists */
#undef HAVE_GETADDRINFO
/* define if pthread_setconcurrency() should be called to tell the
* OS how many threads we might want to run.
*/
#undef CALL_PTHREAD_SETCONCURRENCY
/* Shut up warnings about sputaux in stdio.h on BSD/OS pre-4.1 */
#undef SHUTUP_SPUTAUX
#ifdef SHUTUP_SPUTAUX
struct __sFILE;
extern __inline int __sputaux(int _c, struct __sFILE *_p);
#endif
/* Shut up warnings about missing sigwait prototype on BSD/OS 4.0* */
#undef SHUTUP_SIGWAIT
#ifdef SHUTUP_SIGWAIT
int sigwait(const unsigned int *set, int *sig);
#endif
/* Shut up warnings from gcc -Wcast-qual on BSD/OS 4.1. */
#undef SHUTUP_STDARG_CAST
#if defined(SHUTUP_STDARG_CAST) && defined(__GNUC__)
#include <stdarg.h> /* Grr. Must be included *every time*. */
/*
* The silly continuation line is to keep configure from
* commenting out the #undef.
*/
#undef \
va_start
#define va_start(ap, last) \
do { \
union { const void *konst; long *var; } _u; \
_u.konst = &(last); \
ap = (va_list)(_u.var + __va_words(__typeof(last))); \
} while (0)
#endif /* SHUTUP_STDARG_CAST && __GNUC__ */

2
aclocal.m4 vendored
View File

@@ -1,2 +0,0 @@
sinclude(./libtool.m4)dnl

View File

@@ -1 +0,0 @@
Makefile

View File

@@ -1,25 +0,0 @@
# Copyright (C) 1998-2000 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.in,v 1.15.2.2 2000/06/29 00:05:25 gson Exp $
srcdir = @srcdir@
VPATH = @srcdir@
top_srcdir = @top_srcdir@
SUBDIRS = named rndc dig dnssec tests nsupdate
TARGETS =
@BIND9_MAKE_RULES@

View File

@@ -1,4 +0,0 @@
Makefile
dig
host
nslookup

View File

@@ -1,73 +0,0 @@
# Copyright (C) 2000 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.in,v 1.10.2.4 2000/10/21 01:35:17 gson Exp $
srcdir = @srcdir@
VPATH = @srcdir@
top_srcdir = @top_srcdir@
@BIND9_VERSION@
@BIND9_INCLUDES@
CINCLUDES = -I${srcdir}/include ${DNS_INCLUDES} ${ISC_INCLUDES}
CDEFINES = -DVERSION=\"${VERSION}\"
CWARNINGS =
DNSLIBS = ../../lib/dns/libdns.@A@ @DNS_OPENSSL_LIBS@
ISCLIBS = ../../lib/isc/libisc.@A@
DNSDEPLIBS = ../../lib/dns/libdns.@A@
ISCDEPLIBS = ../../lib/isc/libisc.@A@
DEPLIBS = ${DNSDEPLIBS} ${ISCDEPLIBS}
LIBS = ${DNSLIBS} ${ISCLIBS} @LIBS@
SUBDIRS =
TARGETS = dig host nslookup
OBJS = dig.@O@ dighost.@O@ host.@O@ nslookup.@O@
UOBJS =
SRCS = dig.c dighost.c host.c nslookup.c
@BIND9_MAKE_RULES@
dig: dig.@O@ dighost.@O@ ${UOBJS} ${DEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ dig.@O@ dighost.@O@ ${UOBJS} ${LIBS}
host: host.@O@ dighost.@O@ ${UOBJS} ${DEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ host.@O@ dighost.@O@ ${UOBJS} ${LIBS}
nslookup: nslookup.@O@ dighost.@O@ ${UOBJS} ${DEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ nslookup.@O@ dighost.@O@ ${UOBJS} ${LIBS}
clean distclean::
rm -f ${TARGETS}
installdirs:
if [ ! -d ${DESTDIR}${bindir} ]; then \
mkdir ${DESTDIR}${bindir}; \
fi
install:: dig host nslookup installdirs
${LIBTOOL} ${INSTALL_PROGRAM} dig ${DESTDIR}${bindir}
${LIBTOOL} ${INSTALL_PROGRAM} host ${DESTDIR}${bindir}
${LIBTOOL} ${INSTALL_PROGRAM} nslookup ${DESTDIR}${bindir}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,721 +0,0 @@
/*
* Copyright (C) 2000 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: host.c,v 1.29.2.8 2000/10/20 21:54:11 gson Exp $ */
#include <config.h>
#include <stdlib.h>
#include <limits.h>
extern int h_errno;
#include <isc/app.h>
#include <isc/commandline.h>
#include <isc/netaddr.h>
#include <isc/string.h>
#include <isc/util.h>
#include <isc/task.h>
#include <dns/byaddr.h>
#include <dns/fixedname.h>
#include <dns/message.h>
#include <dns/name.h>
#include <dns/rdata.h>
#include <dns/rdataclass.h>
#include <dns/rdataset.h>
#include <dns/rdatatype.h>
#include <dig/dig.h>
extern ISC_LIST(dig_lookup_t) lookup_list;
extern ISC_LIST(dig_server_t) server_list;
extern ISC_LIST(dig_searchlist_t) search_list;
extern isc_boolean_t debugging;
extern unsigned int timeout;
extern isc_mem_t *mctx;
extern int ndots;
extern int tries;
extern isc_boolean_t usesearch;
extern int lookup_counter;
extern char *progname;
extern isc_task_t *global_task;
isc_boolean_t short_form = ISC_TRUE, listed_server = ISC_FALSE;
static const char *opcodetext[] = {
"QUERY",
"IQUERY",
"STATUS",
"RESERVED3",
"NOTIFY",
"UPDATE",
"RESERVED6",
"RESERVED7",
"RESERVED8",
"RESERVED9",
"RESERVED10",
"RESERVED11",
"RESERVED12",
"RESERVED13",
"RESERVED14",
"RESERVED15"
};
static const char *rcodetext[] = {
"NOERROR",
"FORMERR",
"SERVFAIL",
"NXDOMAIN",
"NOTIMPL",
"REFUSED",
"YXDOMAIN",
"YXRRSET",
"NXRRSET",
"NOTAUTH",
"NOTZONE",
"RESERVED11",
"RESERVED12",
"RESERVED13",
"RESERVED14",
"RESERVED15",
"BADVERS"
};
static const char *rtypetext[] = {
"zero", /* 0 */
"has address", /* 1 */
"name server", /* 2 */
"MD", /* 3 */
"MF", /* 4 */
"is an alias for", /* 5 */
"SOA", /* 6 */
"MB", /* 7 */
"MG", /* 8 */
"MR", /* 9 */
"NULL", /* 10 */
"has well known services", /* 11 */
"domain name pointer", /* 12 */
"host information", /* 13 */
"MINFO", /* 14 */
"mail is handled by", /* 15 */
"text", /* 16 */
"RP", /* 17 */
"AFSDB", /* 18 */
"x25 address", /* 19 */
"isdn address", /* 20 */
"RT", /* 21 */
"NSAP", /* 22 */
"NSAP_PTR", /* 23 */
"has signature", /* 24 */
"has key", /* 25 */
"PX", /* 26 */
"GPOS", /* 27 */
"has AAAA address", /* 28 */
"LOC", /* 29 */
"has next record", /* 30 */
"EID", /* 31 */
"NIMLOC", /* 32 */
"SRV", /* 33 */
"ATMA", /* 34 */
"NAPTR", /* 35 */
"KX", /* 36 */
"CERT", /* 37 */
"has v6 address", /* 38 */
"DNAME", /* 39 */
"has optional information", /* 41 */
"has 42 record", /* 42 */
"has 43 record", /* 43 */
"has 44 record", /* 44 */
"has 45 record", /* 45 */
"has 46 record", /* 46 */
"has 47 record", /* 47 */
"has 48 record", /* 48 */
"has 49 record", /* 49 */
"has 50 record", /* 50 */
"has 51 record", /* 51 */
"has 52 record", /* 52 */
"has 53 record", /* 53 */
"has 54 record", /* 54 */
"has 55 record", /* 55 */
"has 56 record", /* 56 */
"has 57 record", /* 57 */
"has 58 record", /* 58 */
"has 59 record", /* 59 */
"has 60 record", /* 60 */
"has 61 record", /* 61 */
"has 62 record", /* 62 */
"has 63 record", /* 63 */
"has 64 record", /* 64 */
"has 65 record", /* 65 */
"has 66 record", /* 66 */
"has 67 record", /* 67 */
"has 68 record", /* 68 */
"has 69 record", /* 69 */
"has 70 record", /* 70 */
"has 71 record", /* 71 */
"has 72 record", /* 72 */
"has 73 record", /* 73 */
"has 74 record", /* 74 */
"has 75 record", /* 75 */
"has 76 record", /* 76 */
"has 77 record", /* 77 */
"has 78 record", /* 78 */
"has 79 record", /* 79 */
"has 80 record", /* 80 */
"has 81 record", /* 81 */
"has 82 record", /* 82 */
"has 83 record", /* 83 */
"has 84 record", /* 84 */
"has 85 record", /* 85 */
"has 86 record", /* 86 */
"has 87 record", /* 87 */
"has 88 record", /* 88 */
"has 89 record", /* 89 */
"has 90 record", /* 90 */
"has 91 record", /* 91 */
"has 92 record", /* 92 */
"has 93 record", /* 93 */
"has 94 record", /* 94 */
"has 95 record", /* 95 */
"has 96 record", /* 96 */
"has 97 record", /* 97 */
"has 98 record", /* 98 */
"has 99 record", /* 99 */
"UINFO", /* 100 */
"UID", /* 101 */
"GID", /* 102 */
"UNSPEC"}; /* 103 */
static void
show_usage(void) {
fputs(
"Usage: host [-aCdlrTwv] [-c class] [-n] [-N ndots] [-t type] [-W time]\n"
" [-R number] hostname [server]\n"
" -a is equivalent to -v -t *\n"
" -c specifies query class for non-IN data\n"
" -C compares SOA records on authorative nameservers\n"
" -d is equivalent to -v\n"
" -l lists all hosts in a domain, using AXFR\n"
" -n Use the nibble form of IPv6 reverse lookup\n"
" -N changes the number of dots allowed before root lookup is done\n"
" -r disables recursive processing\n"
" -R specifies number of retries for UDP packets\n"
" -t specifies the query type\n"
" -T enables TCP/IP mode\n"
" -v enables verbose output\n"
" -w specifies to wait forever for a reply\n"
" -W specifies how long to wait for a reply\n", stderr);
exit(1);
}
void
dighost_shutdown(void) {
isc_app_shutdown();
}
void
received(int bytes, int frmsize, char *frm, dig_query_t *query) {
isc_time_t now;
isc_result_t result;
int diff;
if (!short_form) {
result = isc_time_now(&now);
check_result(result, "isc_time_now");
diff = isc_time_microdiff(&now, &query->time_sent);
printf("Received %u bytes from %.*s in %d ms\n",
bytes, frmsize, frm, diff/1000);
}
}
void
trying(int frmsize, char *frm, dig_lookup_t *lookup) {
UNUSED(lookup);
if (!short_form)
printf ("Trying \"%.*s\"\n", frmsize, frm);
}
static void
say_message(dns_name_t *name, const char *msg, dns_rdata_t *rdata,
dig_query_t *query)
{
isc_buffer_t *b = NULL, *b2 = NULL;
isc_region_t r, r2;
isc_result_t result;
result = isc_buffer_allocate(mctx, &b, BUFSIZE);
check_result(result, "isc_buffer_allocate");
result = isc_buffer_allocate(mctx, &b2, BUFSIZE);
check_result(result, "isc_buffer_allocate");
result = dns_name_totext(name, ISC_FALSE, b);
check_result(result, "dns_name_totext");
isc_buffer_usedregion(b, &r);
result = dns_rdata_totext(rdata, NULL, b2);
check_result(result, "dns_rdata_totext");
isc_buffer_usedregion(b2, &r2);
printf ( "%.*s %s %.*s", (int)r.length, (char *)r.base,
msg, (int)r2.length, (char *)r2.base);
if (query->lookup->identify) {
printf (" on server %s", query->servname);
}
printf ("\n");
isc_buffer_free(&b);
isc_buffer_free(&b2);
}
static isc_result_t
printsection(dns_message_t *msg, dns_section_t sectionid,
const char *section_name, isc_boolean_t headers,
dig_query_t *query)
{
dns_name_t *name, *print_name;
dns_rdataset_t *rdataset;
dns_rdata_t rdata;
isc_buffer_t target;
isc_result_t result, loopresult;
isc_region_t r;
dns_name_t empty_name;
char t[4096];
isc_boolean_t first;
isc_boolean_t no_rdata;
const char *rtt;
if (sectionid == DNS_SECTION_QUESTION)
no_rdata = ISC_TRUE;
else
no_rdata = ISC_FALSE;
if (headers)
printf(";; %s SECTION:\n", section_name);
dns_name_init(&empty_name, NULL);
result = dns_message_firstname(msg, sectionid);
if (result == ISC_R_NOMORE)
return (ISC_R_SUCCESS);
else if (result != ISC_R_SUCCESS)
return (result);
for (;;) {
name = NULL;
dns_message_currentname(msg, sectionid, &name);
isc_buffer_init(&target, t, sizeof(t));
first = ISC_TRUE;
print_name = name;
for (rdataset = ISC_LIST_HEAD(name->list);
rdataset != NULL;
rdataset = ISC_LIST_NEXT(rdataset, link)) {
if (!short_form) {
result = dns_rdataset_totext(rdataset,
print_name,
ISC_FALSE,
no_rdata,
&target);
if (result != ISC_R_SUCCESS)
return (result);
#ifdef USEINITALWS
if (first) {
print_name = &empty_name;
first = ISC_FALSE;
}
#else
UNUSED(first); /* Shut up compiler. */
#endif
} else {
loopresult = dns_rdataset_first(rdataset);
while (loopresult == ISC_R_SUCCESS) {
dns_rdataset_current(rdataset, &rdata);
if (rdata.type <= 103)
rtt=rtypetext[rdata.type];
else if (rdata.type == 249)
rtt = "key";
else if (rdata.type == 250)
rtt = "signature";
else
rtt = "unknown";
say_message(print_name, rtt,
&rdata, query);
loopresult =
dns_rdataset_next(rdataset);
}
}
}
if (!short_form) {
isc_buffer_usedregion(&target, &r);
if (no_rdata)
printf(";%.*s", (int)r.length,
(char *)r.base);
else
printf("%.*s", (int)r.length, (char *)r.base);
}
result = dns_message_nextname(msg, sectionid);
if (result == ISC_R_NOMORE)
break;
else if (result != ISC_R_SUCCESS)
return (result);
}
return (ISC_R_SUCCESS);
}
static isc_result_t
printrdata(dns_message_t *msg, dns_rdataset_t *rdataset, dns_name_t *owner,
const char *set_name, isc_boolean_t headers)
{
isc_buffer_t target;
isc_result_t result;
isc_region_t r;
char t[4096];
UNUSED(msg);
if (headers)
printf(";; %s SECTION:\n", set_name);
isc_buffer_init(&target, t, sizeof(t));
result = dns_rdataset_totext(rdataset, owner, ISC_FALSE, ISC_FALSE,
&target);
if (result != ISC_R_SUCCESS)
return (result);
isc_buffer_usedregion(&target, &r);
printf("%.*s", (int)r.length, (char *)r.base);
return (ISC_R_SUCCESS);
}
isc_result_t
printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
isc_boolean_t did_flag = ISC_FALSE;
dns_rdataset_t *opt, *tsig = NULL;
dns_name_t *tsigname;
isc_result_t result = ISC_R_SUCCESS;
isc_buffer_t *b = NULL;
isc_region_t r;
UNUSED(headers);
if (listed_server) {
printf("Using domain server:\n");
printf("Name: %s\n", query->servname);
result = isc_buffer_allocate(mctx, &b, MXNAME);
check_result(result, "isc_buffer_allocate");
result = isc_sockaddr_totext(&query->sockaddr, b);
check_result(result, "isc_sockaddr_totext");
printf("Address: %.*s\n",
(int)isc_buffer_usedlength(b),
(char*)isc_buffer_base(b));
isc_buffer_free(&b);
printf("Aliases: \n\n");
}
if (msg->rcode != 0) {
result = isc_buffer_allocate(mctx, &b, MXNAME);
check_result(result, "isc_buffer_allocate");
result = dns_name_totext(query->lookup->name, ISC_FALSE,
b);
check_result(result, "dns_name_totext");
isc_buffer_usedregion(b, &r);
printf("Host %.*s not found: %d(%s)\n",
(int)r.length, (char *)r.base,
msg->rcode, rcodetext[msg->rcode]);
isc_buffer_free(&b);
return (ISC_R_SUCCESS);
}
if (!short_form) {
printf(";; ->>HEADER<<- opcode: %s, status: %s, id: %u\n",
opcodetext[msg->opcode], rcodetext[msg->rcode],
msg->id);
printf(";; flags: ");
if ((msg->flags & DNS_MESSAGEFLAG_QR) != 0) {
printf("qr");
did_flag = ISC_TRUE;
}
if ((msg->flags & DNS_MESSAGEFLAG_AA) != 0) {
printf("%saa", did_flag ? " " : "");
did_flag = ISC_TRUE;
}
if ((msg->flags & DNS_MESSAGEFLAG_TC) != 0) {
printf("%stc", did_flag ? " " : "");
did_flag = ISC_TRUE;
}
if ((msg->flags & DNS_MESSAGEFLAG_RD) != 0) {
printf("%srd", did_flag ? " " : "");
did_flag = ISC_TRUE;
}
if ((msg->flags & DNS_MESSAGEFLAG_RA) != 0) {
printf("%sra", did_flag ? " " : "");
did_flag = ISC_TRUE;
}
if ((msg->flags & DNS_MESSAGEFLAG_AD) != 0) {
printf("%sad", did_flag ? " " : "");
did_flag = ISC_TRUE;
}
if ((msg->flags & DNS_MESSAGEFLAG_CD) != 0) {
printf("%scd", did_flag ? " " : "");
did_flag = ISC_TRUE;
}
printf("; QUERY: %u, ANSWER: %u, "
"AUTHORITY: %u, ADDITIONAL: %u\n",
msg->counts[DNS_SECTION_QUESTION],
msg->counts[DNS_SECTION_ANSWER],
msg->counts[DNS_SECTION_AUTHORITY],
msg->counts[DNS_SECTION_ADDITIONAL]);
opt = dns_message_getopt(msg);
if (opt != NULL)
printf(";; EDNS: version: %u, udp=%u\n",
(unsigned int)((opt->ttl & 0x00ff0000) >> 16),
(unsigned int)opt->rdclass);
tsigname = NULL;
tsig = dns_message_gettsig(msg, &tsigname);
if (tsig != NULL)
printf(";; PSEUDOSECTIONS: TSIG\n");
}
if (! ISC_LIST_EMPTY(msg->sections[DNS_SECTION_QUESTION]) &&
!short_form) {
printf("\n");
result = printsection(msg, DNS_SECTION_QUESTION, "QUESTION",
ISC_TRUE, query);
if (result != ISC_R_SUCCESS)
return (result);
}
if (! ISC_LIST_EMPTY(msg->sections[DNS_SECTION_ANSWER])) {
if (!short_form)
printf("\n");
result = printsection(msg, DNS_SECTION_ANSWER, "ANSWER",
ISC_TF(!short_form), query);
if (result != ISC_R_SUCCESS)
return (result);
}
if (! ISC_LIST_EMPTY(msg->sections[DNS_SECTION_AUTHORITY]) &&
!short_form) {
printf("\n");
result = printsection(msg, DNS_SECTION_AUTHORITY, "AUTHORITY",
ISC_TRUE, query);
if (result != ISC_R_SUCCESS)
return (result);
}
if (! ISC_LIST_EMPTY(msg->sections[DNS_SECTION_ADDITIONAL]) &&
!short_form) {
printf("\n");
result = printsection(msg, DNS_SECTION_ADDITIONAL,
"ADDITIONAL", ISC_TRUE, query);
if (result != ISC_R_SUCCESS)
return (result);
}
if ((tsig != NULL) && !short_form) {
printf("\n");
result = printrdata(msg, tsig, tsigname,
"PSEUDOSECTION TSIG", ISC_TRUE);
if (result != ISC_R_SUCCESS)
return (result);
}
if (!short_form)
printf("\n");
return (result);
}
static void
parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
char hostname[MXNAME];
dig_server_t *srv;
dig_lookup_t *lookup;
int i, c, n, adrs[4];
char store[MXNAME];
isc_textregion_t tr;
isc_result_t result;
dns_rdatatype_t rdtype;
dns_rdataclass_t rdclass;
UNUSED(is_batchfile);
lookup = make_empty_lookup();
while ((c = isc_commandline_parse(argc, argv, "lvwrdt:c:aTCN:R:W:Dn"))
!= EOF) {
switch (c) {
case 'l':
lookup->tcp_mode = ISC_TRUE;
lookup->rdtype = dns_rdatatype_axfr;
break;
case 'v':
case 'd':
short_form = ISC_FALSE;
break;
case 'r':
lookup->recurse = ISC_FALSE;
break;
case 't':
tr.base = isc_commandline_argument;
tr.length = strlen(isc_commandline_argument);
result = dns_rdatatype_fromtext(&rdtype,
(isc_textregion_t *)&tr);
if (result != ISC_R_SUCCESS)
fprintf (stderr,"Warning: invalid type: %s\n",
isc_commandline_argument);
else
lookup->rdtype = rdtype;
break;
case 'c':
tr.base = isc_commandline_argument;
tr.length = strlen(isc_commandline_argument);
result = dns_rdataclass_fromtext(&rdclass,
(isc_textregion_t *)&tr);
if (result != ISC_R_SUCCESS)
fprintf (stderr,"Warning: invalid class: %s\n",
isc_commandline_argument);
else
lookup->rdclass = rdclass;
break;
case 'a':
lookup->rdtype = dns_rdatatype_any;
short_form = ISC_FALSE;
break;
case 'n':
lookup->nibble = ISC_TRUE;
break;
case 'w':
/*
* The timer routines are coded such that
* timeout==MAXINT doesn't enable the timer
*/
timeout = INT_MAX;
break;
case 'W':
timeout = atoi(isc_commandline_argument);
if (timeout < 1)
timeout = 1;
break;
case 'R':
tries = atoi(isc_commandline_argument);
if (tries < 1)
tries = 1;
break;
case 'T':
lookup->tcp_mode = ISC_TRUE;
break;
case 'C':
debug("showing all SOAs");
lookup->rdtype = dns_rdatatype_soa;
lookup->rdclass = dns_rdataclass_in;
lookup->ns_search_only = ISC_TRUE;
lookup->trace_root = ISC_TRUE;
break;
case 'N':
debug("setting NDOTS to %s",
isc_commandline_argument);
ndots = atoi(isc_commandline_argument);
break;
case 'D':
debugging = ISC_TRUE;
break;
}
}
if (isc_commandline_index >= argc) {
show_usage();
}
strncpy(hostname, argv[isc_commandline_index], sizeof(hostname));
hostname[sizeof(hostname)-1]=0;
if (argc > isc_commandline_index + 1) {
srv = make_server(argv[isc_commandline_index+1]);
debug("server is %s", srv->servername);
ISC_LIST_APPEND(server_list, srv, link);
listed_server = ISC_TRUE;
}
lookup->pending = ISC_FALSE;
if (strspn(hostname, "0123456789.") == strlen(hostname)) {
lookup->textname[0] = 0;
n = sscanf(hostname, "%d.%d.%d.%d", &adrs[0], &adrs[1],
&adrs[2], &adrs[3]);
if (n == 0) {
show_usage();
}
for (i = n - 1; i >= 0; i--) {
snprintf(store, MXNAME/8, "%d.",
adrs[i]);
strncat(lookup->textname, store, MXNAME);
}
strncat(lookup->textname, "in-addr.arpa.", MXNAME);
lookup->rdtype = dns_rdatatype_ptr;
} else if (strspn(hostname, "0123456789abcdef.:") == strlen(hostname))
{
isc_netaddr_t addr;
dns_fixedname_t fname;
isc_buffer_t b;
addr.family = AF_INET6;
n = inet_pton(AF_INET6, hostname, &addr.type.in6);
if (n <= 0)
goto notv6;
dns_fixedname_init(&fname);
result = dns_byaddr_createptrname(&addr, lookup->nibble,
dns_fixedname_name(&fname));
if (result != ISC_R_SUCCESS)
show_usage();
isc_buffer_init(&b, lookup->textname, sizeof lookup->textname);
result = dns_name_totext(dns_fixedname_name(&fname),
ISC_FALSE, &b);
isc_buffer_putuint8(&b, 0);
if (result != ISC_R_SUCCESS)
show_usage();
lookup->rdtype = dns_rdatatype_ptr;
} else {
notv6:
strncpy(lookup->textname, hostname, sizeof(lookup->textname));
lookup->textname[sizeof(lookup->textname)-1]=0;
}
lookup->new_search = ISC_TRUE;
ISC_LIST_APPEND(lookup_list, lookup, link);
usesearch = ISC_TRUE;
}
int
main(int argc, char **argv) {
isc_result_t result;
ISC_LIST_INIT(lookup_list);
ISC_LIST_INIT(server_list);
ISC_LIST_INIT(search_list);
debug("main()");
progname = argv[0];
result = isc_app_start();
check_result(result, "isc_app_start");
setup_libs();
parse_args(ISC_FALSE, argc, argv);
setup_system();
result = isc_app_onrun(mctx, global_task, onrun_callback, NULL);
check_result(result, "isc_app_onrun");
isc_app_run();
cancel_all();
destroy_libs();
isc_app_finish();
return (0);
}

View File

@@ -1,247 +0,0 @@
/*
* Copyright (C) 2000 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: dig.h,v 1.25.2.5 2000/10/06 19:08:08 mws Exp $ */
#ifndef DIG_H
#define DIG_H
#include <dns/rdatalist.h>
#include <dst/dst.h>
#include <isc/boolean.h>
#include <isc/buffer.h>
#include <isc/bufferlist.h>
#include <isc/lang.h>
#include <isc/list.h>
#include <isc/mem.h>
#include <isc/print.h>
#include <isc/sockaddr.h>
#include <isc/socket.h>
#define MXSERV 6
#define MXNAME (1024)
#define MXRD 32
#define BUFSIZE 512
#define COMMSIZE 0xffff
#define RESOLVCONF "/etc/resolv.conf"
#define OUTPUTBUF 32767
/*
* Default timeout values
*/
#define TCP_TIMEOUT 10
#define UDP_TIMEOUT 5
#define SERVER_TIMEOUT 1
#define LOOKUP_LIMIT 64
/*
* Lookup_limit is just a limiter, keeping too many lookups from being
* created. It's job is mainly to prevent the program from running away
* in a tight loop of constant lookups. It's value is arbitrary.
*/
#define ROOTNS 1
/*
* Set the number of root servers to ask for information when running in
* trace mode.
* XXXMWS -- trace mode is currently semi-broken, and this number *MUST*
* be 1.
*/
ISC_LANG_BEGINDECLS
typedef struct dig_lookup dig_lookup_t;
typedef struct dig_query dig_query_t;
typedef struct dig_server dig_server_t;
typedef ISC_LIST(dig_server_t) dig_serverlist_t;
typedef struct dig_searchlist dig_searchlist_t;
struct dig_lookup {
isc_boolean_t
pending, /* Pending a successful answer */
waiting_connect,
doing_xfr,
ns_search_only,
identify,
ignore,
recurse,
aaonly,
adflag,
cdflag,
trace,
trace_root,
defname,
tcp_mode,
nibble,
comments,
stats,
section_question,
section_answer,
section_authority,
section_additional,
servfail_stops,
new_search;
char textname[MXNAME]; /* Name we're going to be looking up */
char cmdline[MXNAME];
dns_rdatatype_t rdtype;
dns_rdataclass_t rdclass;
char namespace[BUFSIZE];
char onamespace[BUFSIZE];
isc_buffer_t namebuf;
isc_buffer_t onamebuf;
isc_buffer_t sendbuf;
char *sendspace;
dns_name_t *name;
isc_timer_t *timer;
isc_interval_t interval;
dns_message_t *sendmsg;
dns_name_t *oname;
ISC_LINK(dig_lookup_t) link;
ISC_LIST(dig_query_t) q;
dig_query_t *current_query;
dig_serverlist_t my_server_list;
dig_searchlist_t *origin;
dig_query_t *xfr_q;
int retries;
int nsfound;
isc_uint16_t udpsize;
isc_uint32_t ixfr_serial;
isc_buffer_t rdatabuf;
char rdatastore[MXNAME];
dst_context_t *tsigctx;
isc_buffer_t *querysig;
isc_uint32_t msgcounter;
};
struct dig_query {
dig_lookup_t *lookup;
isc_boolean_t waiting_connect,
first_pass,
first_soa_rcvd,
second_rr_rcvd,
first_repeat_rcvd,
recv_made;
isc_uint32_t first_rr_serial;
isc_uint32_t second_rr_serial;
isc_uint32_t rr_count;
isc_uint32_t name_count;
char *servname;
isc_bufferlist_t sendlist,
recvlist,
lengthlist;
isc_buffer_t recvbuf,
lengthbuf,
slbuf;
char *recvspace,
lengthspace[4],
slspace[4];
isc_socket_t *sock;
ISC_LINK(dig_query_t) link;
isc_sockaddr_t sockaddr;
isc_time_t time_sent;
};
struct dig_server {
char servername[MXNAME];
ISC_LINK(dig_server_t) link;
};
struct dig_searchlist {
char origin[MXNAME];
ISC_LINK(dig_searchlist_t) link;
};
/*
* Routines in dighost.c.
*/
void
get_address(char *host, in_port_t port, isc_sockaddr_t *sockaddr);
void
fatal(const char *format, ...);
void
debug(const char *format, ...);
void
check_result(isc_result_t result, const char *msg);
void
setup_lookup(dig_lookup_t *lookup);
void
do_lookup(dig_lookup_t *lookup);
void
start_lookup(void);
void
onrun_callback(isc_task_t *task, isc_event_t *event);
int
dhmain(int argc, char **argv);
void
setup_libs(void);
void
setup_system(void);
dig_lookup_t *
requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
dig_lookup_t *
make_empty_lookup(void);
dig_lookup_t *
clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
dig_server_t *
make_server(const char *servname);
void
clone_server_list(dig_serverlist_t src,
dig_serverlist_t *dest);
void
cancel_all(void);
void
destroy_libs(void);
/*
* Routines needed in dig.c and host.c.
*/
isc_result_t
printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers);
void
received(int bytes, int frmsize, char *frm, dig_query_t *query);
void
trying(int frmsize, char *frm, dig_lookup_t *lookup);
void
dighost_shutdown(void);
char *
next_token(char **stringp, const char *delim);
ISC_LANG_ENDDECLS
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +0,0 @@
Makefile
dnssec-keygen
dnssec-makekeyset
dnssec-signkey
dnssec-signzone

View File

@@ -1,74 +0,0 @@
# Copyright (C) 2000 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.in,v 1.7.2.1 2000/11/13 22:11:47 gson Exp $
srcdir = @srcdir@
VPATH = @srcdir@
top_srcdir = @top_srcdir@
@BIND9_INCLUDES@
CINCLUDES = ${DNS_INCLUDES} ${ISC_INCLUDES}
CDEFINES =
CWARNINGS =
DNSLIBS = ../../lib/dns/libdns.@A@ @DNS_OPENSSL_LIBS@
ISCLIBS = ../../lib/isc/libisc.@A@
DNSDEPLIBS = ../../lib/dns/libdns.@A@
ISCDEPLIBS = ../../lib/isc/libisc.@A@
DEPLIBS = ${DNSDEPLIBS} ${ISCDEPLIBS}
LIBS = ${DNSLIBS} ${ISCLIBS} @LIBS@
# Alphabetically
TARGETS = dnssec-keygen \
dnssec-makekeyset \
dnssec-signkey \
dnssec-signzone
OBJS = dnssectool.@O@
SRCS = dnssec-keygen.c dnssec-makekeyset.c \
dnssec-signkey.c dnssec-signzone.c \
dnssectool.c
@BIND9_MAKE_RULES@
dnssec-keygen: dnssec-keygen.@O@ ${OBJS} ${DEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ dnssec-keygen.@O@ ${OBJS} ${LIBS}
dnssec-makekeyset: dnssec-makekeyset.@O@ ${OBJS} ${DEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ dnssec-makekeyset.@O@ ${OBJS} ${LIBS}
dnssec-signkey: dnssec-signkey.@O@ ${OBJS} ${DEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ dnssec-signkey.@O@ ${OBJS} ${LIBS}
dnssec-signzone: dnssec-signzone.@O@ ${OBJS} ${DEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ dnssec-signzone.@O@ ${OBJS} ${LIBS}
clean distclean::
rm -f ${TARGETS}
installdirs:
if [ ! -d ${DESTDIR}${sbindir} ]; then \
mkdir ${DESTDIR}${sbindir}; \
fi
install:: ${TARGETS} installdirs
for t in ${TARGETS}; do ${LIBTOOL} ${INSTALL_PROGRAM} $$t ${DESTDIR}${sbindir}; done

View File

@@ -1,393 +0,0 @@
/*
* Portions Copyright (C) 2000 Internet Software Consortium.
* Portions Copyright (C) 1995-2000 by Network Associates, 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 AND
* NETWORK ASSOCIATES DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
* SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE CONSORTIUM OR NETWORK
* ASSOCIATES 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: dnssec-keygen.c,v 1.36.2.2 2000/11/09 00:39:14 gson Exp $ */
#include <config.h>
#include <stdlib.h>
#include <isc/buffer.h>
#include <isc/commandline.h>
#include <isc/entropy.h>
#include <isc/mem.h>
#include <isc/region.h>
#include <isc/string.h>
#include <isc/util.h>
#include <dns/fixedname.h>
#include <dns/keyvalues.h>
#include <dns/log.h>
#include <dns/name.h>
#include <dns/result.h>
#include <dns/secalg.h>
#include <dst/dst.h>
#include <dst/result.h>
#include "dnssectool.h"
#define MAX_RSA 2000 /* XXXBEW dnssafe is broken */
const char *program = "dnssec-keygen";
int verbose;
static isc_boolean_t
dsa_size_ok(int size) {
return (ISC_TF(size >= 512 && size <= 1024 && size % 64 == 0));
}
static void
usage(void) {
printf("Usage:\n");
printf(" %s -a alg -b bits -n type [options] name\n\n", program);
printf("Required options:\n");
printf(" -a algorithm: RSA | RSAMD5 | DH | DSA | HMAC-MD5\n");
printf(" -b key size, in bits:\n");
printf(" RSA:\t\t[512..%d]\n", MAX_RSA);
printf(" DH:\t\t[128..4096]\n");
printf(" DSA:\t\t[512..1024] and dividable by 64\n");
printf(" HMAC-MD5:\t[1..512]\n");
printf(" -n nametype: ZONE | HOST | ENTITY | USER\n");
printf(" name: owner of the key\n");
printf("Other options:\n");
printf(" -e use large exponent (RSA only)\n");
printf(" -g use specified generator (DH only)\n");
printf(" -t type: AUTHCONF | NOAUTHCONF | NOAUTH | NOCONF "
"(default: AUTHCONF)\n");
printf(" -p protocol value "
"(default: 2 [email] for USER, 3 [dnssec] otherwise)\n");
printf(" -s strength value this key signs DNS records with "
"(default: 0)\n");
printf(" -r randomdev (a file containing random data)\n");
printf(" -v verbose level\n");
exit (-1);
}
int
main(int argc, char **argv) {
char *algname = NULL, *nametype = NULL, *type = NULL;
char *randomfile = NULL;
char *prog, *endp;
dst_key_t *key = NULL, *oldkey;
dns_fixedname_t fname;
dns_name_t *name;
isc_uint16_t flags = 0;
dns_secalg_t alg;
isc_boolean_t conflict = ISC_FALSE, null_key = ISC_FALSE;
isc_mem_t *mctx = NULL;
int ch, rsa_exp = 0, generator = 0, param = 0;
int protocol = -1, size = -1, signatory = 0;
isc_result_t ret;
isc_textregion_t r;
char filename[255];
isc_buffer_t buf;
isc_log_t *log = NULL;
isc_entropy_t *ectx = NULL;
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
if ((prog = strrchr(argv[0],'/')) == NULL)
prog = isc_mem_strdup(mctx, argv[0]);
else
prog = isc_mem_strdup(mctx, ++prog);
if (prog == NULL)
fatal("out of memory");
if (argc == 1)
usage();
dns_result_register();
while ((ch = isc_commandline_parse(argc, argv,
"a:b:eg:n:t:p:s:hr:v:")) != -1)
{
switch (ch) {
case 'a':
algname = isc_mem_strdup(mctx,
isc_commandline_argument);
if (algname == NULL)
fatal("out of memory");
break;
case 'b':
size = strtol(isc_commandline_argument, &endp, 10);
if (*endp != '\0' || size < 0)
fatal("-b requires a non-negative number");
break;
case 'e':
rsa_exp = 1;
break;
case 'g':
generator = strtol(isc_commandline_argument,
&endp, 10);
if (*endp != '\0' || generator <= 0)
fatal("-g requires a positive number");
break;
case 'n':
nametype = isc_mem_strdup(mctx,
isc_commandline_argument);
if (nametype == NULL)
fatal("out of memory");
break;
case 't':
type = isc_mem_strdup(mctx, isc_commandline_argument);
if (type == NULL)
fatal("out of memory");
break;
case 'p':
protocol = strtol(isc_commandline_argument, &endp, 10);
if (*endp != '\0' || protocol < 0 || protocol > 255)
fatal("-p must be followed by a number "
"[0..255]");
break;
case 's':
signatory = strtol(isc_commandline_argument,
&endp, 10);
if (*endp != '\0' || signatory < 0 || signatory > 15)
fatal("-s must be followed by a number "
"[0..15]");
break;
case 'r':
randomfile = isc_mem_strdup(mctx,
isc_commandline_argument);
if (randomfile == NULL)
fatal("out of memory");
break;
case 'v':
endp = NULL;
verbose = strtol(isc_commandline_argument, &endp, 0);
if (*endp != '\0')
fatal("-v must be followed by a number");
break;
case 'h':
usage();
default:
fprintf(stderr, "%s: invalid argument -%c\n",
program, ch);
usage();
}
}
setup_entropy(mctx, randomfile, &ectx);
if (randomfile != NULL)
isc_mem_free(mctx, randomfile);
ret = dst_lib_init(mctx, ectx,
ISC_ENTROPY_BLOCKING | ISC_ENTROPY_GOODONLY);
if (ret != ISC_R_SUCCESS)
fatal("could not initialize dst");
setup_logging(verbose, mctx, &log);
if (argc < isc_commandline_index + 1)
fatal("the key name was not specified");
if (argc > isc_commandline_index + 1)
fatal("extraneous arguments");
if (algname == NULL)
fatal("no algorithm was specified");
if (strcasecmp(algname, "RSA") == 0)
alg = DNS_KEYALG_RSA;
else if (strcasecmp(algname, "HMAC-MD5") == 0)
alg = DST_ALG_HMACMD5;
else {
r.base = algname;
r.length = strlen(algname);
ret = dns_secalg_fromtext(&alg, &r);
if (ret != ISC_R_SUCCESS)
fatal("unknown algorithm %s", algname);
}
if (dst_algorithm_supported(alg) == ISC_FALSE)
fatal("unsupported algorithm %s", algname);
if (type != NULL) {
if (strcasecmp(type, "NOAUTH") == 0)
flags |= DNS_KEYTYPE_NOAUTH;
else if (strcasecmp(type, "NOCONF") == 0)
flags |= DNS_KEYTYPE_NOCONF;
else if (strcasecmp(type, "NOAUTHCONF") == 0) {
flags |= (DNS_KEYTYPE_NOAUTH | DNS_KEYTYPE_NOCONF);
if (size < 0)
size = 0;
}
else if (strcasecmp(type, "AUTHCONF") == 0)
/* nothing */;
else
fatal("invalid type %s", type);
}
if (size < 0)
fatal("key size not specified (-b option)");
switch (alg) {
case DNS_KEYALG_RSA:
if (size != 0 && (size < 512 || size > MAX_RSA))
fatal("RSA key size %d out of range", size);
break;
case DNS_KEYALG_DH:
if (size != 0 && (size < 128 || size > 4096))
fatal("DH key size %d out of range", size);
break;
case DNS_KEYALG_DSA:
if (size != 0 && !dsa_size_ok(size))
fatal("Invalid DSS key size: %d", size);
break;
case DST_ALG_HMACMD5:
if (size < 1 || size > 512)
fatal("HMAC-MD5 key size %d out of range", size);
break;
}
if (alg != DNS_KEYALG_RSA && rsa_exp != 0)
fatal("specified RSA exponent without RSA");
if (alg != DNS_KEYALG_DH && generator != 0)
fatal("specified DH generator without DH");
if (nametype == NULL)
fatal("no nametype specified");
if (strcasecmp(nametype, "zone") == 0)
flags |= DNS_KEYOWNER_ZONE;
else if (strcasecmp(nametype, "host") == 0 ||
strcasecmp(nametype, "entity") == 0)
flags |= DNS_KEYOWNER_ENTITY;
else if (strcasecmp(nametype, "user") == 0)
flags |= DNS_KEYOWNER_USER;
else
fatal("invalid nametype %s", nametype);
flags |= signatory;
if (protocol == -1) {
if ((flags & DNS_KEYFLAG_OWNERMASK) == DNS_KEYOWNER_USER)
protocol = DNS_KEYPROTO_EMAIL;
else
protocol = DNS_KEYPROTO_DNSSEC;
}
if ((flags & DNS_KEYFLAG_TYPEMASK) == DNS_KEYTYPE_NOKEY) {
if (size > 0)
fatal("Specified null key with non-zero size");
if ((flags & DNS_KEYFLAG_SIGNATORYMASK) != 0)
fatal("Specified null key with signing authority");
}
dns_fixedname_init(&fname);
name = dns_fixedname_name(&fname);
isc_buffer_init(&buf, argv[isc_commandline_index],
strlen(argv[isc_commandline_index]));
isc_buffer_add(&buf, strlen(argv[isc_commandline_index]));
ret = dns_name_fromtext(name, &buf, dns_rootname, ISC_FALSE, NULL);
if (ret != ISC_R_SUCCESS)
fatal("Invalid key name %s: %s", argv[isc_commandline_index],
isc_result_totext(ret));
switch(alg) {
case DNS_KEYALG_RSA:
param = rsa_exp;
break;
case DNS_KEYALG_DH:
param = generator;
break;
case DNS_KEYALG_DSA:
case DST_ALG_HMACMD5:
param = 0;
break;
}
if ((flags & DNS_KEYFLAG_TYPEMASK) == DNS_KEYTYPE_NOKEY)
null_key = ISC_TRUE;
isc_buffer_init(&buf, filename, sizeof(filename) - 1);
do {
conflict = ISC_FALSE;
oldkey = NULL;
/* generate the key */
ret = dst_key_generate(name, alg, size, param, flags, protocol,
mctx, &key);
isc_entropy_stopcallbacksources(ectx);
if (ret != ISC_R_SUCCESS) {
fatal("failed to generate key %s/%s: %s\n",
nametostr(name), algtostr(alg),
dst_result_totext(ret));
exit(-1);
}
/*
* Try to read a key with the same name, alg and id from disk.
* If there is one we must continue generating a new one
* unless we were asked to generate a null key, in which
* case we return failure.
*/
ret = dst_key_fromfile(name, dst_key_id(key), alg,
DST_TYPE_PRIVATE, NULL, mctx, &oldkey);
/* do not overwrite an existing key */
if (ret == ISC_R_SUCCESS) {
dst_key_free(&oldkey);
conflict = ISC_TRUE;
if (null_key)
break;
}
if (conflict == ISC_TRUE) {
if (verbose > 0) {
isc_buffer_clear(&buf);
ret = dst_key_buildfilename(key, 0, NULL, &buf);
fprintf(stderr,
"%s: %s already exists, "
"generating a new key\n",
program, filename);
}
dst_key_free(&key);
}
} while (conflict == ISC_TRUE);
if (conflict)
fatal("cannot generate a null key when a key with id 0 "
"already exists");
ret = dst_key_tofile(key, DST_TYPE_PUBLIC | DST_TYPE_PRIVATE, NULL);
if (ret != ISC_R_SUCCESS)
fatal("failed to write key %s/%s/%d: %s\n", nametostr(name),
algtostr(alg), dst_key_id(key), isc_result_totext(ret));
isc_buffer_clear(&buf);
ret = dst_key_buildfilename(key, 0, NULL, &buf);
printf("%s\n", filename);
isc_mem_free(mctx, algname);
isc_mem_free(mctx, nametype);
isc_mem_free(mctx, prog);
if (type != NULL)
isc_mem_free(mctx, type);
dst_key_free(&key);
if (log != NULL)
isc_log_destroy(&log);
cleanup_entropy(&ectx);
dst_lib_destroy();
if (verbose > 10)
isc_mem_stats(mctx, stdout);
isc_mem_destroy(&mctx);
return (0);
}

View File

@@ -1,424 +0,0 @@
/*
* Portions Copyright (C) 2000 Internet Software Consortium.
* Portions Copyright (C) 1995-2000 by Network Associates, 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 AND
* NETWORK ASSOCIATES DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
* SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE CONSORTIUM OR NETWORK
* ASSOCIATES 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: dnssec-makekeyset.c,v 1.28.2.2 2000/08/15 01:20:32 gson Exp $ */
#include <config.h>
#include <stdlib.h>
#include <isc/commandline.h>
#include <isc/entropy.h>
#include <isc/mem.h>
#include <isc/string.h>
#include <isc/util.h>
#include <dns/db.h>
#include <dns/dnssec.h>
#include <dns/fixedname.h>
#include <dns/log.h>
#include <dns/rdata.h>
#include <dns/rdatalist.h>
#include <dns/rdataset.h>
#include <dns/result.h>
#include <dns/secalg.h>
#include <dns/time.h>
#include <dst/dst.h>
#include "dnssectool.h"
#define BUFSIZE 2048
const char *program = "dnssec-makekeyset";
int verbose;
typedef struct keynode keynode_t;
struct keynode {
dst_key_t *key;
ISC_LINK(keynode_t) link;
};
typedef ISC_LIST(keynode_t) keylist_t;
static isc_stdtime_t starttime = 0, endtime = 0, now;
static int ttl = -1;
static isc_mem_t *mctx = NULL;
static isc_entropy_t *ectx = NULL;
static keylist_t keylist;
static isc_stdtime_t
strtotime(char *str, isc_int64_t now, isc_int64_t base) {
isc_int64_t val, offset;
isc_result_t result;
char *endp;
if (str[0] == '+') {
offset = strtol(str + 1, &endp, 0);
if (*endp != '\0')
fatal("time value %s is invalid", str);
val = base + offset;
} else if (strncmp(str, "now+", 4) == 0) {
offset = strtol(str + 4, &endp, 0);
if (*endp != '\0')
fatal("time value %s is invalid", str);
val = now + offset;
} else {
result = dns_time64_fromtext(str, &val);
if (result != ISC_R_SUCCESS)
fatal("time %s must be numeric", str);
}
return ((isc_stdtime_t) val);
}
static void
usage(void) {
fprintf(stderr, "Usage:\n");
fprintf(stderr, "\t%s [options] keys\n", program);
fprintf(stderr, "\n");
fprintf(stderr, "Options: (default value in parenthesis) \n");
fprintf(stderr, "\t-s YYYYMMDDHHMMSS|+offset:\n");
fprintf(stderr, "\t\tSIG start time - absolute|offset (now)\n");
fprintf(stderr, "\t-e YYYYMMDDHHMMSS|+offset|\"now\"+offset]:\n");
fprintf(stderr, "\t\tSIG end time - "
"absolute|from start|from now (now + 30 days)\n");
fprintf(stderr, "\t-t ttl\n");
fprintf(stderr, "\t-r randomdev:\n");
fprintf(stderr, "\t\ta file containing random data\n");
fprintf(stderr, "\t-v level:\n");
fprintf(stderr, "\t\tverbose level (0)\n");
fprintf(stderr, "\n");
fprintf(stderr, "keys:\n");
fprintf(stderr, "\tkeyfile (Kname+alg+tag)\n");
exit(0);
}
int
main(int argc, char *argv[]) {
int i, ch;
char *startstr = NULL, *endstr = NULL;
char *randomfile = NULL;
dns_fixedname_t fdomain;
dns_name_t *domain = NULL;
char *output = NULL;
char *endp;
unsigned char *data;
dns_db_t *db;
dns_dbnode_t *node;
dns_dbversion_t *version;
dst_key_t *key = NULL;
dns_rdata_t *rdata;
dns_rdatalist_t rdatalist, sigrdatalist;
dns_rdataset_t rdataset, sigrdataset;
isc_result_t result;
isc_buffer_t b;
isc_region_t r;
isc_log_t *log = NULL;
keynode_t *keynode;
dns_name_t *savedname = NULL;
result = isc_mem_create(0, 0, &mctx);
if (result != ISC_R_SUCCESS)
fatal("failed to create memory context: %s",
isc_result_totext(result));
dns_result_register();
while ((ch = isc_commandline_parse(argc, argv, "s:e:t:r:v:h")) != -1)
{
switch (ch) {
case 's':
startstr = isc_mem_strdup(mctx,
isc_commandline_argument);
if (startstr == NULL)
fatal("out of memory");
break;
case 'e':
endstr = isc_mem_strdup(mctx,
isc_commandline_argument);
if (endstr == NULL)
fatal("out of memory");
break;
case 't':
endp = NULL;
ttl = strtol(isc_commandline_argument, &endp, 0);
if (*endp != '\0')
fatal("TTL must be numeric");
break;
case 'r':
randomfile = isc_mem_strdup(mctx,
isc_commandline_argument);
if (randomfile == NULL)
fatal("out of memory");
break;
case 'v':
endp = NULL;
verbose = strtol(isc_commandline_argument, &endp, 0);
if (*endp != '\0')
fatal("verbose level must be numeric");
break;
case 'h':
default:
usage();
}
}
argc -= isc_commandline_index;
argv += isc_commandline_index;
if (argc < 1)
usage();
setup_entropy(mctx, randomfile, &ectx);
if (randomfile != NULL)
isc_mem_free(mctx, randomfile);
result = dst_lib_init(mctx, ectx,
ISC_ENTROPY_BLOCKING | ISC_ENTROPY_GOODONLY);
if (result != ISC_R_SUCCESS)
fatal("could not initialize dst");
isc_stdtime_get(&now);
if (startstr != NULL) {
starttime = strtotime(startstr, now, now);
isc_mem_free(mctx, startstr);
}
else
starttime = now;
if (endstr != NULL) {
endtime = strtotime(endstr, now, starttime);
isc_mem_free(mctx, endstr);
}
else
endtime = starttime + (30 * 24 * 60 * 60);
if (ttl == -1) {
ttl = 3600;
fprintf(stderr, "%s: TTL not specified, assuming 3600\n",
program);
}
setup_logging(verbose, mctx, &log);
dns_rdatalist_init(&rdatalist);
rdatalist.rdclass = dns_rdataclass_in;
rdatalist.type = dns_rdatatype_key;
rdatalist.covers = 0;
rdatalist.ttl = ttl;
ISC_LIST_INIT(keylist);
for (i = 0; i < argc; i++) {
char namestr[1025];
key = NULL;
result = dst_key_fromnamedfile(argv[i], DST_TYPE_PUBLIC,
mctx, &key);
if (result != ISC_R_SUCCESS)
fatal("error loading key from %s", argv[i]);
strncpy(namestr, nametostr(dst_key_name(key)),
sizeof(namestr) - 1);
namestr[sizeof(namestr) - 1] = 0;
if (savedname == NULL) {
savedname = isc_mem_get(mctx, sizeof(dns_name_t));
if (savedname == NULL)
fatal("out of memory");
dns_name_init(savedname, NULL);
result = dns_name_dup(dst_key_name(key), mctx,
savedname);
if (result != ISC_R_SUCCESS)
fatal("out of memory");
} else {
if (!dns_name_equal(savedname, dst_key_name(key)) != 0)
fatal("all keys must have the same owner - %s "
"and %s do not match",
nametostr(savedname), namestr);
}
if (output == NULL) {
output = isc_mem_allocate(mctx,
strlen(namestr) +
strlen("keyset") + 1);
if (output == NULL)
fatal("out of memory");
strcpy(output, namestr);
strcat(output, "keyset");
}
if (domain == NULL) {
dns_fixedname_init(&fdomain);
domain = dns_fixedname_name(&fdomain);
isc_buffer_init(&b, namestr, strlen(namestr));
isc_buffer_add(&b, strlen(namestr));
result = dns_name_fromtext(domain, &b, dns_rootname,
ISC_FALSE, NULL);
if (result != ISC_R_SUCCESS)
fatal("%s is not a valid name: %s",
namestr, isc_result_totext(result));
}
if (dst_key_iszonekey(key)) {
dst_key_t *zonekey = NULL;
result = dst_key_fromnamedfile(argv[i],
DST_TYPE_PRIVATE,
mctx, &zonekey);
if (result != ISC_R_SUCCESS)
fatal("failed to read key %s: %s",
argv[i], isc_result_totext(result));
keynode = isc_mem_get(mctx, sizeof (keynode_t));
if (keynode == NULL)
fatal("out of memory");
keynode->key = zonekey;
ISC_LINK_INIT(keynode, link);
ISC_LIST_APPEND(keylist, keynode, link);
}
rdata = isc_mem_get(mctx, sizeof(dns_rdata_t));
if (rdata == NULL)
fatal("out of memory");
data = isc_mem_get(mctx, BUFSIZE);
if (data == NULL)
fatal("out of memory");
isc_buffer_init(&b, data, BUFSIZE);
result = dst_key_todns(key, &b);
if (result != ISC_R_SUCCESS)
fatal("failed to convert key %s to a DNS KEY: %s",
argv[i], isc_result_totext(result));
isc_buffer_usedregion(&b, &r);
dns_rdata_fromregion(rdata, dns_rdataclass_in,
dns_rdatatype_key, &r);
ISC_LIST_APPEND(rdatalist.rdata, rdata, link);
dst_key_free(&key);
}
dns_rdataset_init(&rdataset);
result = dns_rdatalist_tordataset(&rdatalist, &rdataset);
check_result(result, "dns_rdatalist_tordataset()");
dns_rdatalist_init(&sigrdatalist);
sigrdatalist.rdclass = dns_rdataclass_in;
sigrdatalist.type = dns_rdatatype_sig;
sigrdatalist.covers = dns_rdatatype_key;
sigrdatalist.ttl = ttl;
if (ISC_LIST_EMPTY(keylist))
fprintf(stderr,
"%s: no private zone key found; not self-signing\n",
program);
for (keynode = ISC_LIST_HEAD(keylist);
keynode != NULL;
keynode = ISC_LIST_NEXT(keynode, link))
{
rdata = isc_mem_get(mctx, sizeof(dns_rdata_t));
if (rdata == NULL)
fatal("out of memory");
data = isc_mem_get(mctx, BUFSIZE);
if (data == NULL)
fatal("out of memory");
isc_buffer_init(&b, data, BUFSIZE);
result = dns_dnssec_sign(domain, &rdataset, keynode->key,
&starttime, &endtime, mctx, &b,
rdata);
isc_entropy_stopcallbacksources(ectx);
if (result != ISC_R_SUCCESS)
fatal("failed to sign keyset with key %s/%s/%d: %s",
nametostr(dst_key_name(keynode->key)),
algtostr(dst_key_alg(keynode->key)),
dst_key_id(keynode->key),
isc_result_totext(result));
ISC_LIST_APPEND(sigrdatalist.rdata, rdata, link);
dns_rdataset_init(&sigrdataset);
result = dns_rdatalist_tordataset(&sigrdatalist, &sigrdataset);
check_result(result, "dns_rdatalist_tordataset()");
}
db = NULL;
result = dns_db_create(mctx, "rbt", domain, dns_dbtype_zone,
dns_rdataclass_in, 0, NULL, &db);
if (result != ISC_R_SUCCESS)
fatal("failed to create a database for %s", nametostr(domain));
version = NULL;
dns_db_newversion(db, &version);
node = NULL;
result = dns_db_findnode(db, domain, ISC_TRUE, &node);
check_result(result, "dns_db_findnode()");
dns_db_addrdataset(db, node, version, 0, &rdataset, 0, NULL);
if (!ISC_LIST_EMPTY(keylist))
dns_db_addrdataset(db, node, version, 0, &sigrdataset, 0,
NULL);
dns_db_detachnode(db, &node);
dns_db_closeversion(db, &version, ISC_TRUE);
result = dns_db_dump(db, version, output);
if (result != ISC_R_SUCCESS)
fatal("failed to write database for %s to %s",
nametostr(domain), output);
dns_db_detach(&db);
dns_rdataset_disassociate(&rdataset);
while (!ISC_LIST_EMPTY(rdatalist.rdata)) {
rdata = ISC_LIST_HEAD(rdatalist.rdata);
ISC_LIST_UNLINK(rdatalist.rdata, rdata, link);
isc_mem_put(mctx, rdata->data, BUFSIZE);
isc_mem_put(mctx, rdata, sizeof *rdata);
}
while (!ISC_LIST_EMPTY(sigrdatalist.rdata)) {
rdata = ISC_LIST_HEAD(sigrdatalist.rdata);
ISC_LIST_UNLINK(sigrdatalist.rdata, rdata, link);
isc_mem_put(mctx, rdata->data, BUFSIZE);
isc_mem_put(mctx, rdata, sizeof *rdata);
}
while (!ISC_LIST_EMPTY(keylist)) {
keynode = ISC_LIST_HEAD(keylist);
ISC_LIST_UNLINK(keylist, keynode, link);
dst_key_free(&keynode->key);
isc_mem_put(mctx, keynode, sizeof(keynode_t));
}
if (savedname != NULL) {
dns_name_free(savedname, mctx);
isc_mem_put(mctx, savedname, sizeof(dns_name_t));
}
if (log != NULL)
isc_log_destroy(&log);
cleanup_entropy(&ectx);
isc_mem_free(mctx, output);
dst_lib_destroy();
if (verbose > 10)
isc_mem_stats(mctx, stdout);
isc_mem_destroy(&mctx);
return (0);
}

View File

@@ -1,385 +0,0 @@
/*
* Portions Copyright (C) 2000 Internet Software Consortium.
* Portions Copyright (C) 1995-2000 by Network Associates, 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 AND
* NETWORK ASSOCIATES DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
* SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE CONSORTIUM OR NETWORK
* ASSOCIATES 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: dnssec-signkey.c,v 1.28.2.1 2000/08/15 01:20:34 gson Exp $ */
#include <config.h>
#include <stdlib.h>
#include <isc/string.h>
#include <isc/commandline.h>
#include <isc/entropy.h>
#include <isc/mem.h>
#include <isc/util.h>
#include <dns/db.h>
#include <dns/dnssec.h>
#include <dns/log.h>
#include <dns/rdata.h>
#include <dns/rdatalist.h>
#include <dns/rdataset.h>
#include <dns/rdatastruct.h>
#include <dns/result.h>
#include <dns/secalg.h>
#include <dst/dst.h>
#include "dnssectool.h"
const char *program = "dnssec-signkey";
int verbose;
#define BUFSIZE 2048
typedef struct keynode keynode_t;
struct keynode {
dst_key_t *key;
isc_boolean_t verified;
ISC_LINK(keynode_t) link;
};
typedef ISC_LIST(keynode_t) keylist_t;
static isc_stdtime_t now;
static isc_mem_t *mctx = NULL;
static isc_entropy_t *ectx = NULL;
static keylist_t keylist;
static void
usage(void) {
fprintf(stderr, "Usage:\n");
fprintf(stderr, "\t%s [options] keyset keys\n", program);
fprintf(stderr, "\n");
fprintf(stderr, "Options: (default value in parenthesis) \n");
fprintf(stderr, "\t-v level:\n");
fprintf(stderr, "\t\tverbose level (0)\n");
fprintf(stderr, "\t-p\n");
fprintf(stderr, "\t\tuse pseudorandom data (faster but less secure)\n");
fprintf(stderr, "\t-r randomdev:\n");
fprintf(stderr, "\t\ta file containing random data\n");
fprintf(stderr, "\n");
fprintf(stderr, "keyset:\n");
fprintf(stderr, "\tfile name of key set to be signed\n");
fprintf(stderr, "keys:\n");
fprintf(stderr, "\tkeyfile (Kname+alg+tag)\n");
exit(0);
}
static void
loadkeys(dns_name_t *name, dns_rdataset_t *rdataset) {
dst_key_t *key;
dns_rdata_t rdata;
keynode_t *keynode;
isc_result_t result;
ISC_LIST_INIT(keylist);
result = dns_rdataset_first(rdataset);
check_result(result, "dns_rdataset_first");
for (; result == ISC_R_SUCCESS; result = dns_rdataset_next(rdataset)) {
dns_rdataset_current(rdataset, &rdata);
key = NULL;
result = dns_dnssec_keyfromrdata(name, &rdata, mctx, &key);
if (result != ISC_R_SUCCESS)
continue;
if (!dst_key_iszonekey(key))
continue;
keynode = isc_mem_get(mctx, sizeof (keynode_t));
if (keynode == NULL)
fatal("out of memory");
keynode->key = key;
keynode->verified = ISC_FALSE;
ISC_LINK_INIT(keynode, link);
ISC_LIST_APPEND(keylist, keynode, link);
}
if (result != ISC_R_NOMORE)
fatal("failure traversing key list");
}
static dst_key_t *
findkey(dns_rdata_sig_t *sig) {
keynode_t *keynode;
for (keynode = ISC_LIST_HEAD(keylist);
keynode != NULL;
keynode = ISC_LIST_NEXT(keynode, link))
{
if (dst_key_id(keynode->key) == sig->keyid &&
dst_key_alg(keynode->key) == sig->algorithm) {
keynode->verified = ISC_TRUE;
return (keynode->key);
}
}
fatal("signature generated by non-zone or missing key");
return (NULL);
}
int
main(int argc, char *argv[]) {
int i, ch;
char tdomain[1025];
dns_fixedname_t fdomain;
dns_name_t *domain;
char *output = NULL;
char *endp;
unsigned char *data;
char *randomfile = NULL;
dns_db_t *db;
dns_dbnode_t *node;
dns_dbversion_t *version;
dst_key_t *key = NULL;
dns_rdata_t *rdata, sigrdata;
dns_rdatalist_t sigrdatalist;
dns_rdataset_t rdataset, sigrdataset, newsigrdataset;
dns_rdata_sig_t sig;
isc_result_t result;
isc_buffer_t b;
isc_region_t r;
isc_log_t *log = NULL;
keynode_t *keynode;
isc_boolean_t pseudorandom = ISC_FALSE;
unsigned int eflags;
result = isc_mem_create(0, 0, &mctx);
check_result(result, "isc_mem_create()");
dns_result_register();
while ((ch = isc_commandline_parse(argc, argv, "pr:v:h")) != -1)
{
switch (ch) {
case 'p':
pseudorandom = ISC_TRUE;
break;
case 'r':
randomfile = isc_mem_strdup(mctx,
isc_commandline_argument);
if (randomfile == NULL)
fatal("out of memory");
break;
case 'v':
endp = NULL;
verbose = strtol(isc_commandline_argument, &endp, 0);
if (*endp != '\0')
fatal("verbose level must be numeric");
break;
case 'h':
default:
usage();
}
}
argc -= isc_commandline_index;
argv += isc_commandline_index;
if (argc < 2)
usage();
setup_entropy(mctx, randomfile, &ectx);
if (randomfile != NULL)
isc_mem_free(mctx, randomfile);
eflags = ISC_ENTROPY_BLOCKING;
if (!pseudorandom)
eflags |= ISC_ENTROPY_GOODONLY;
result = dst_lib_init(mctx, ectx, eflags);
if (result != ISC_R_SUCCESS)
fatal("could not initialize dst");
isc_stdtime_get(&now);
setup_logging(verbose, mctx, &log);
if (strlen(argv[0]) < 8 ||
strcmp(argv[0] + strlen(argv[0]) - 7, ".keyset") != 0)
fatal("keyset file must end in .keyset");
dns_fixedname_init(&fdomain);
domain = dns_fixedname_name(&fdomain);
isc_buffer_init(&b, argv[0], strlen(argv[0]) - 7);
isc_buffer_add(&b, strlen(argv[0]) - 7);
result = dns_name_fromtext(domain, &b, dns_rootname, ISC_FALSE, NULL);
if (result != ISC_R_SUCCESS)
fatal("'%s' does not contain a valid domain name", argv[0]);
isc_buffer_init(&b, tdomain, sizeof(tdomain) - 1);
result = dns_name_totext(domain, ISC_FALSE, &b);
check_result(result, "dns_name_totext()");
isc_buffer_usedregion(&b, &r);
tdomain[r.length] = 0;
output = isc_mem_allocate(mctx,
strlen(tdomain) + strlen("signedkey") + 1);
if (output == NULL)
fatal("out of memory");
strcpy(output, tdomain);
strcat(output, "signedkey");
db = NULL;
result = dns_db_create(mctx, "rbt", domain, dns_dbtype_zone,
dns_rdataclass_in, 0, NULL, &db);
check_result(result, "dns_db_create()");
result = dns_db_load(db, argv[0]);
if (result != ISC_R_SUCCESS)
fatal("failed to load database from '%s': %s", argv[0],
isc_result_totext(result));
version = NULL;
dns_db_newversion(db, &version);
node = NULL;
result = dns_db_findnode(db, domain, ISC_FALSE, &node);
if (result != ISC_R_SUCCESS)
fatal("failed to find database node '%s': %s",
nametostr(domain), isc_result_totext(result));
dns_rdataset_init(&rdataset);
dns_rdataset_init(&sigrdataset);
result = dns_db_findrdataset(db, node, version, dns_rdatatype_key, 0,
0, &rdataset, &sigrdataset);
if (result != ISC_R_SUCCESS)
fatal("failed to find rdataset '%s KEY': %s",
nametostr(domain), isc_result_totext(result));
loadkeys(domain, &rdataset);
if (!dns_rdataset_isassociated(&sigrdataset))
fatal("no SIG KEY set present");
result = dns_rdataset_first(&sigrdataset);
check_result(result, "dns_rdataset_first()");
do {
dns_rdataset_current(&sigrdataset, &sigrdata);
result = dns_rdata_tostruct(&sigrdata, &sig, mctx);
check_result(result, "dns_rdata_tostruct()");
key = findkey(&sig);
result = dns_dnssec_verify(domain, &rdataset, key,
ISC_TRUE, mctx, &sigrdata);
if (result != ISC_R_SUCCESS)
fatal("signature by key '%s/%s/%d' did not verify: %s",
nametostr(dst_key_name(key)),
algtostr(dst_key_alg(key)),
dst_key_id(key), isc_result_totext(result));
dns_rdata_freestruct(&sig);
result = dns_rdataset_next(&sigrdataset);
} while (result == ISC_R_SUCCESS);
for (keynode = ISC_LIST_HEAD(keylist);
keynode != NULL;
keynode = ISC_LIST_NEXT(keynode, link))
if (!keynode->verified)
fatal("Not all zone keys self signed the key set");
result = dns_rdataset_first(&sigrdataset);
check_result(result, "dns_rdataset_first()");
dns_rdataset_current(&sigrdataset, &sigrdata);
result = dns_rdata_tostruct(&sigrdata, &sig, mctx);
check_result(result, "dns_rdata_tostruct()");
dns_rdataset_disassociate(&sigrdataset);
argc -= 1;
argv += 1;
dns_rdatalist_init(&sigrdatalist);
sigrdatalist.rdclass = rdataset.rdclass;
sigrdatalist.type = dns_rdatatype_sig;
sigrdatalist.covers = dns_rdatatype_key;
sigrdatalist.ttl = rdataset.ttl;
for (i = 0; i < argc; i++) {
key = NULL;
result = dst_key_fromnamedfile(argv[i], DST_TYPE_PRIVATE,
mctx, &key);
if (result != ISC_R_SUCCESS)
fatal("failed to read key %s from disk: %s",
argv[i], isc_result_totext(result));
rdata = isc_mem_get(mctx, sizeof(dns_rdata_t));
if (rdata == NULL)
fatal("out of memory");
data = isc_mem_get(mctx, BUFSIZE);
if (data == NULL)
fatal("out of memory");
isc_buffer_init(&b, data, BUFSIZE);
result = dns_dnssec_sign(domain, &rdataset, key,
&sig.timesigned, &sig.timeexpire,
mctx, &b, rdata);
isc_entropy_stopcallbacksources(ectx);
if (result != ISC_R_SUCCESS)
fatal("key '%s/%s/%d' failed to sign data: %s",
nametostr(dst_key_name(key)),
algtostr(dst_key_alg(key)),
dst_key_id(key), isc_result_totext(result));
ISC_LIST_APPEND(sigrdatalist.rdata, rdata, link);
dst_key_free(&key);
}
dns_rdataset_init(&newsigrdataset);
result = dns_rdatalist_tordataset(&sigrdatalist, &newsigrdataset);
check_result (result, "dns_rdatalist_tordataset()");
dns_db_addrdataset(db, node, version, 0, &newsigrdataset, 0, NULL);
check_result (result, "dns_db_addrdataset()");
dns_db_detachnode(db, &node);
dns_db_closeversion(db, &version, ISC_TRUE);
result = dns_db_dump(db, version, output);
if (result != ISC_R_SUCCESS)
fatal("failed to write database to '%s': %s",
output, isc_result_totext(result));
dns_rdataset_disassociate(&rdataset);
dns_rdataset_disassociate(&newsigrdataset);
dns_rdata_freestruct(&sig);
while (!ISC_LIST_EMPTY(sigrdatalist.rdata)) {
rdata = ISC_LIST_HEAD(sigrdatalist.rdata);
ISC_LIST_UNLINK(sigrdatalist.rdata, rdata, link);
isc_mem_put(mctx, rdata->data, BUFSIZE);
isc_mem_put(mctx, rdata, sizeof *rdata);
}
dns_db_detach(&db);
while (!ISC_LIST_EMPTY(keylist)) {
keynode = ISC_LIST_HEAD(keylist);
ISC_LIST_UNLINK(keylist, keynode, link);
dst_key_free(&keynode->key);
isc_mem_put(mctx, keynode, sizeof(keynode_t));
}
if (log != NULL)
isc_log_destroy(&log);
isc_mem_free(mctx, output);
cleanup_entropy(&ectx);
dst_lib_destroy();
if (verbose > 10)
isc_mem_stats(mctx, stdout);
isc_mem_destroy(&mctx);
return (0);
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,280 +0,0 @@
/*
* Copyright (C) 2000 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: dnssectool.c,v 1.12.2.1 2000/08/07 16:41:38 gson Exp $ */
#include <config.h>
#include <stdlib.h>
#include <isc/buffer.h>
#include <isc/entropy.h>
#include <isc/keyboard.h>
#include <isc/string.h>
#include <isc/time.h>
#include <isc/util.h>
#include <dns/log.h>
#include <dns/name.h>
#include <dns/rdatatype.h>
#include <dns/result.h>
#include <dns/secalg.h>
#include "dnssectool.h"
extern int verbose;
extern const char *program;
static isc_entropysource_t *source = NULL;
static isc_keyboard_t kbd;
static isc_boolean_t wantkeyboard = ISC_FALSE;
void
fatal(const char *format, ...) {
va_list args;
fprintf(stderr, "%s: ", program);
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
fprintf(stderr, "\n");
exit(1);
}
void
check_result(isc_result_t result, const char *message) {
if (result != ISC_R_SUCCESS) {
fprintf(stderr, "%s: %s: %s\n", program, message,
isc_result_totext(result));
exit(1);
}
}
void
vbprintf(int level, const char *fmt, ...) {
va_list ap;
if (level > verbose)
return;
va_start(ap, fmt);
fprintf(stderr, "%s: ", program);
vfprintf(stderr, fmt, ap);
va_end(ap);
}
char *
nametostr(dns_name_t *name) {
isc_buffer_t b;
isc_region_t r;
isc_result_t result;
static char data[1025];
isc_buffer_init(&b, data, sizeof(data));
result = dns_name_totext(name, ISC_FALSE, &b);
check_result(result, "dns_name_totext()");
isc_buffer_usedregion(&b, &r);
r.base[r.length] = 0;
return (char *) r.base;
}
char *
typetostr(const dns_rdatatype_t type) {
isc_buffer_t b;
isc_region_t r;
isc_result_t result;
static char data[20];
isc_buffer_init(&b, data, sizeof(data));
result = dns_rdatatype_totext(type, &b);
check_result(result, "dns_rdatatype_totext()");
isc_buffer_usedregion(&b, &r);
r.base[r.length] = 0;
return (char *) r.base;
}
char *
algtostr(const dns_secalg_t alg) {
isc_buffer_t b;
isc_region_t r;
isc_result_t result;
static char data[10];
isc_buffer_init(&b, data, sizeof(data));
result = dns_secalg_totext(alg, &b);
check_result(result, "dns_secalg_totext()");
isc_buffer_usedregion(&b, &r);
r.base[r.length] = 0;
return ((char *)r.base);
}
void
setup_logging(int verbose, isc_mem_t *mctx, isc_log_t **logp) {
isc_result_t result;
isc_logdestination_t destination;
isc_logconfig_t *logconfig;
isc_log_t *log = 0;
int level;
switch (verbose) {
case 0:
/*
* We want to see warnings about things like out-of-zone
* data in the master file even when not verbose.
*/
level = ISC_LOG_WARNING;
break;
case 1:
level = ISC_LOG_INFO;
break;
default:
level = ISC_LOG_DEBUG(verbose - 2 + 1);
break;
}
RUNTIME_CHECK(isc_log_create(mctx, &log, &logconfig) == ISC_R_SUCCESS);
isc_log_setcontext(log);
dns_log_init(log);
dns_log_setcontext(log);
RUNTIME_CHECK(isc_log_settag(logconfig, program) == ISC_R_SUCCESS);
/*
* Set up a channel similar to default_stderr except:
* - the logging level is passed in
* - the program name and logging level are printed
* - no time stamp is printed
*/
destination.file.stream = stderr;
destination.file.name = NULL;
destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0;
result = isc_log_createchannel(logconfig, "stderr",
ISC_LOG_TOFILEDESC,
level,
&destination,
ISC_LOG_PRINTTAG|ISC_LOG_PRINTLEVEL);
check_result(result, "isc_log_createchannel()");
RUNTIME_CHECK(isc_log_usechannel(logconfig, "stderr",
NULL, NULL) == ISC_R_SUCCESS);
*logp = log;
}
static isc_result_t
kbdstart(isc_entropysource_t *source, void *arg, isc_boolean_t blocking) {
isc_keyboard_t *kbd = (isc_keyboard_t *)arg;
static isc_boolean_t first = ISC_TRUE;
UNUSED(source);
if (!blocking)
return (ISC_R_NOENTROPY);
if (first) {
if (!wantkeyboard) {
fprintf(stderr, "You must use the keyboard to create "
"entropy, since your system is lacking\n");
fprintf(stderr, "/dev/random\n\n");
}
first = ISC_FALSE;
}
fprintf(stderr, "start typing:\n");
return (isc_keyboard_open(kbd));
}
static void
kbdstop(isc_entropysource_t *source, void *arg) {
isc_keyboard_t *kbd = (isc_keyboard_t *)arg;
UNUSED(source);
if (!isc_keyboard_canceled(kbd))
fprintf(stderr, "stop typing.\r\n");
(void)isc_keyboard_close(kbd, 3);
}
static isc_result_t
kbdget(isc_entropysource_t *source, void *arg, isc_boolean_t blocking) {
isc_keyboard_t *kbd = (isc_keyboard_t *)arg;
isc_result_t result;
isc_time_t t;
isc_uint32_t sample;
isc_uint32_t extra;
unsigned char c;
if (!blocking)
return (ISC_R_NOENTROPY);
result = isc_keyboard_getchar(kbd, &c);
if (result != ISC_R_SUCCESS)
return (result);
result = isc_time_now(&t);
if (result != ISC_R_SUCCESS)
return (result);
sample = isc_time_nanoseconds(&t);
extra = c;
result = isc_entropy_addcallbacksample(source, sample, extra);
if (result != ISC_R_SUCCESS) {
fprintf(stderr, "\r\n");
return (result);
}
fprintf(stderr, ".");
fflush(stderr);
return (result);
}
void
setup_entropy(isc_mem_t *mctx, const char *randomfile, isc_entropy_t **ectx) {
isc_result_t result;
result = isc_entropy_create(mctx, ectx);
if (result != ISC_R_SUCCESS)
fatal("could not create entropy object");
if (randomfile != NULL && strcasecmp(randomfile, "keyboard") != 0) {
result = isc_entropy_createfilesource(*ectx, randomfile);
if (result != ISC_R_SUCCESS)
fatal("could not open randomdev %s: %s", randomfile,
isc_result_totext(result));
}
else {
if (randomfile == NULL) {
result = isc_entropy_createfilesource(*ectx,
"/dev/random");
if (result == ISC_R_SUCCESS)
return;
}
else
wantkeyboard = ISC_TRUE;
result = isc_entropy_createcallbacksource(*ectx, kbdstart,
kbdget, kbdstop,
&kbd, &source);
if (result != ISC_R_SUCCESS)
fatal("failed to open keyboard: %s\n",
isc_result_totext(result));
}
}
void
cleanup_entropy(isc_entropy_t **ectx) {
if (source != NULL)
isc_entropy_destroysource(&source);
isc_entropy_detach(ectx);
}

View File

@@ -1,52 +0,0 @@
/*
* Copyright (C) 2000 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: dnssectool.h,v 1.6 2000/06/22 21:49:07 tale Exp $ */
#ifndef DNSSECTOOL_H
#define DNSSECTOOL_H 1
#include <isc/log.h>
void
fatal(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
void
check_result(isc_result_t result, const char *message);
void
vbprintf(int level, const char *fmt, ...);
char *
nametostr(dns_name_t *name);
char *
typetostr(const dns_rdatatype_t type);
char *
algtostr(const dns_secalg_t alg);
void
setup_logging(int verbose, isc_mem_t *mctx, isc_log_t **logp);
void
setup_entropy(isc_mem_t *mctx, const char *randomfile, isc_entropy_t **ectx);
void
cleanup_entropy(isc_entropy_t **ectx);
#endif /* DNSSEC_DNSSECTOOL_H */

View File

@@ -1,5 +0,0 @@
Makefile
.libs
*.la
*.lo
lwresd

View File

@@ -1,57 +0,0 @@
# Copyright (C) 2000 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.in,v 1.10 2000/06/22 21:49:08 tale Exp $
srcdir = @srcdir@
VPATH = @srcdir@
top_srcdir = @top_srcdir@
@BIND9_VERSION@
@BIND9_INCLUDES@
CINCLUDES = ${LWRES_INCLUDES} ${DNS_INCLUDES} ${ISC_INCLUDES}
CDEFINES =
CWARNINGS =
DNSLIBS = ../../lib/dns/libdns.@A@ @DNS_OPENSSL_LIBS@
ISCLIBS = ../../lib/isc/libisc.@A@
LWRESLIBS = ../../lib/lwres/liblwres.@A@
DNSDEPLIBS = ../../lib/dns/libdns.@A@
ISCDEPLIBS = ../../lib/isc/libisc.@A@
LWRESDEPLIBS = ../../lib/lwres/liblwres.@A@
DEPLIBS = ${DNSDEPLIBS} ${ISCDEPLIBS} ${LWRESDEPLIBS}
LIBS = ${DNSLIBS} ${ISCLIBS} ${LWRESLIBS} @LIBS@
TARGETS = lwresd
OBJS = main.@O@ client.@O@ err_pkt.@O@ \
process_gabn.@O@ process_gnba.@O@ process_noop.@O@
SRCS = main.c client.c err_pkt.c \
process_gabn.c process_gnba.c process_noop.c
@BIND9_MAKE_RULES@
lwresd: ${OBJS} ${UOBJS} ${DEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ ${OBJS} ${UOBJS} ${LIBS}
clean distclean::
rm -f ${TARGETS}

View File

@@ -1,387 +0,0 @@
/*
* Copyright (C) 2000 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: client.c,v 1.28 2000/06/22 21:49:09 tale Exp $ */
#include <config.h>
#include <isc/socket.h>
#include <isc/string.h>
#include <isc/task.h>
#include <isc/util.h>
#include <dns/view.h>
#include <dns/log.h>
#include "client.h"
void
DP(int level, const char *format, ...) {
va_list args;
va_start(args, format);
isc_log_vwrite(dns_lctx,
DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_ADB,
ISC_LOG_DEBUG(level), format, args);
va_end(args);
}
void
hexdump(char *msg, void *base, size_t len) {
unsigned char *p;
unsigned int cnt;
char buffer[180];
char *n;
p = base;
cnt = 0;
n = buffer;
*n = 0;
printf("*** %s (%u bytes @ %p)\n", msg, len, base);
while (cnt < len) {
if (cnt % 16 == 0) {
n = buffer;
n += sprintf(buffer, "%p: ", p);
} else if (cnt % 8 == 0) {
*n++ = ' ';
*n++ = '|';
*n = 0;
}
n += sprintf(n, " %02x", *p++);
cnt++;
if (cnt % 16 == 0) {
DP(80, buffer);
n = buffer;
*n = 0;
}
}
if (n != buffer) {
DP(80, buffer);
n = buffer;
*n = 0;
}
}
static void
clientmgr_can_die(clientmgr_t *cm) {
if ((cm->flags & CLIENTMGR_FLAG_SHUTTINGDOWN) == 0)
return;
if (ISC_LIST_HEAD(cm->running) != NULL)
return;
lwres_context_destroy(&cm->lwctx);
dns_view_detach(&cm->view);
isc_task_detach(&cm->task);
}
static void
process_request(client_t *client) {
lwres_buffer_t b;
isc_result_t result;
lwres_buffer_init(&b, client->buffer, client->recvlength);
lwres_buffer_add(&b, client->recvlength);
result = lwres_lwpacket_parseheader(&b, &client->pkt);
if (result != ISC_R_SUCCESS) {
DP(50, "invalid packet header received");
goto restart;
}
DP(50, "opcode %08x", client->pkt.opcode);
switch (client->pkt.opcode) {
case LWRES_OPCODE_GETADDRSBYNAME:
process_gabn(client, &b);
return;
case LWRES_OPCODE_GETNAMEBYADDR:
process_gnba(client, &b);
return;
case LWRES_OPCODE_NOOP:
process_noop(client, &b);
return;
default:
DP(50, "unknown opcode %08x", client->pkt.opcode);
goto restart;
}
/*
* Drop the packet.
*/
restart:
DP(50, "restarting client %p...", client);
client_state_idle(client);
}
void
client_recv(isc_task_t *task, isc_event_t *ev) {
client_t *client = ev->ev_arg;
clientmgr_t *cm = client->clientmgr;
isc_socketevent_t *dev = (isc_socketevent_t *)ev;
INSIST(dev->region.base == client->buffer);
INSIST(CLIENT_ISRECV(client));
CLIENT_SETRECVDONE(client);
INSIST((cm->flags & CLIENTMGR_FLAG_RECVPENDING) != 0);
cm->flags &= ~CLIENTMGR_FLAG_RECVPENDING;
DP(50, "event received: task %p, length %u, result %u (%s)",
task, dev->n, dev->result, isc_result_totext(dev->result));
if (dev->result != ISC_R_SUCCESS) {
isc_event_free(&ev);
dev = NULL;
/*
* Go idle.
*/
client_state_idle(client);
return;
}
/*
* XXXMLG If we wanted to run on ipv6 as well, we'd need the pktinfo
* bits. Right now we don't, so don't remember them.
*/
client->recvlength = dev->n;
client->address = dev->address;
isc_event_free(&ev);
dev = NULL;
client_start_recv(cm);
process_request(client);
}
/*
* This function will start a new recv() on a socket for this client manager.
*/
isc_result_t
client_start_recv(clientmgr_t *cm) {
client_t *client;
isc_result_t result;
isc_region_t r;
if ((cm->flags & CLIENTMGR_FLAG_SHUTTINGDOWN) != 0)
return (ISC_R_SUCCESS);
/*
* If a recv is already running, don't bother.
*/
if ((cm->flags & CLIENTMGR_FLAG_RECVPENDING) != 0)
return (ISC_R_SUCCESS);
/*
* If we have no idle slots, just return success.
*/
client = ISC_LIST_HEAD(cm->idle);
if (client == NULL)
return (ISC_R_SUCCESS);
INSIST(CLIENT_ISIDLE(client));
/*
* Issue the recv. If it fails, return that it did.
*/
r.base = client->buffer;
r.length = LWRES_RECVLENGTH;
result = isc_socket_recv(cm->sock, &r, 0, cm->task, client_recv,
client);
if (result != ISC_R_SUCCESS)
return (result);
/*
* Set the flag to say we've issued a recv() call.
*/
cm->flags |= CLIENTMGR_FLAG_RECVPENDING;
/*
* Remove the client from the idle list, and put it on the running
* list.
*/
CLIENT_SETRECV(client);
ISC_LIST_UNLINK(cm->idle, client, link);
ISC_LIST_APPEND(cm->running, client, link);
return (ISC_R_SUCCESS);
}
void
client_shutdown(isc_task_t *task, isc_event_t *ev) {
clientmgr_t *cm = ev->ev_arg;
REQUIRE(task == cm->task);
REQUIRE(ev->ev_type == LWRD_SHUTDOWN);
REQUIRE((cm->flags & CLIENTMGR_FLAG_SHUTTINGDOWN) == 0);
DP(50, "got shutdown event, task %p", task);
/*
* Cancel any pending I/O.
*/
if ((cm->flags & CLIENTMGR_FLAG_RECVPENDING) != 0)
isc_socket_cancel(cm->sock, task, ISC_SOCKCANCEL_ALL);
/*
* Run through the running client list and kill off any finds
* in progress.
*/
/* XXXMLG */
cm->flags |= CLIENTMGR_FLAG_SHUTTINGDOWN;
}
/*
* Do all the crap needed to move a client from the run queue to the idle
* queue.
*/
void
client_state_idle(client_t *client) {
clientmgr_t *cm;
cm = client->clientmgr;
INSIST(client->sendbuf == NULL);
INSIST(client->sendlength == 0);
INSIST(client->arg == NULL);
INSIST(client->v4find == NULL);
INSIST(client->v6find == NULL);
ISC_LIST_UNLINK(cm->running, client, link);
ISC_LIST_PREPEND(cm->idle, client, link);
CLIENT_SETIDLE(client);
clientmgr_can_die(cm);
client_start_recv(cm);
}
void
client_send(isc_task_t *task, isc_event_t *ev) {
client_t *client = ev->ev_arg;
clientmgr_t *cm = client->clientmgr;
isc_socketevent_t *dev = (isc_socketevent_t *)ev;
UNUSED(task);
UNUSED(dev);
INSIST(CLIENT_ISSEND(client));
INSIST(client->sendbuf == dev->region.base);
DP(50, "task %p for client %p got send-done event", task, client);
if (client->sendbuf != client->buffer)
lwres_context_freemem(cm->lwctx, client->sendbuf,
client->sendlength);
client->sendbuf = NULL;
client->sendlength = 0;
client_state_idle(client);
isc_event_free(&ev);
}
void
client_initialize(client_t *client, clientmgr_t *cmgr) {
client->clientmgr = cmgr;
ISC_LINK_INIT(client, link);
CLIENT_SETIDLE(client);
client->arg = NULL;
client->recvlength = 0;
client->sendbuf = NULL;
client->sendlength = 0;
client->find = NULL;
client->v4find = NULL;
client->v6find = NULL;
client->find_wanted = 0;
client->options = 0;
client->byaddr = NULL;
client->addrinfo = NULL;
ISC_LIST_APPEND(cmgr->idle, client, link);
}
void
client_init_aliases(client_t *client) {
int i;
for (i = 0 ; i < LWRES_MAX_ALIASES ; i++) {
client->aliases[i] = NULL;
client->aliaslen[i] = 0;
}
for (i = 0 ; i < LWRES_MAX_ADDRS ; i++) {
client->addrs[i].family = 0;
client->addrs[i].length = 0;
memset(client->addrs[i].address, 0, LWRES_ADDR_MAXLEN);
LWRES_LINK_INIT(&client->addrs[i], link);
}
}
void
client_init_gabn(client_t *client) {
/*
* Initialize the real name and alias arrays in the reply we're
* going to build up.
*/
client_init_aliases(client);
client->gabn.naliases = 0;
client->gabn.naddrs = 0;
client->gabn.realname = NULL;
client->gabn.aliases = client->aliases;
client->gabn.realnamelen = 0;
client->gabn.aliaslen = client->aliaslen;
LWRES_LIST_INIT(client->gabn.addrs);
client->gabn.base = NULL;
client->gabn.baselen = 0;
/*
* Set up the internal buffer to point to the receive region.
*/
isc_buffer_init(&client->recv_buffer, client->buffer,
LWRES_RECVLENGTH);
}
void
client_init_gnba(client_t *client) {
/*
* Initialize the real name and alias arrays in the reply we're
* going to build up.
*/
client_init_aliases(client);
client->gnba.naliases = 0;
client->gnba.realname = NULL;
client->gnba.aliases = client->aliases;
client->gnba.realnamelen = 0;
client->gnba.aliaslen = client->aliaslen;
client->gnba.base = NULL;
client->gnba.baselen = 0;
isc_buffer_init(&client->recv_buffer, client->buffer,
LWRES_RECVLENGTH);
}

View File

@@ -1,194 +0,0 @@
/*
* Copyright (C) 2000 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: client.h,v 1.16 2000/06/22 21:49:10 tale Exp $ */
#ifndef LWD_CLIENT_H
#define LWD_CLIENT_H 1
#include <isc/event.h>
#include <isc/eventclass.h>
#include <isc/netaddr.h>
#include <isc/sockaddr.h>
#include <isc/types.h>
#include <dns/fixedname.h>
#include <dns/types.h>
#include <lwres/lwres.h>
#define LWRD_EVENTCLASS ISC_EVENTCLASS(4242)
#define LWRD_SHUTDOWN (LWRD_EVENTCLASS + 0x0001)
typedef struct client_s client_t;
typedef struct clientmgr_s clientmgr_t;
struct client_s {
isc_sockaddr_t address; /* where to reply */
clientmgr_t *clientmgr; /* our parent */
ISC_LINK(client_t) link;
unsigned int state;
void *arg; /* packet processing state */
/*
* Received data info.
*/
unsigned char buffer[LWRES_RECVLENGTH]; /* receive buffer */
isc_uint32_t recvlength; /* length recv'd */
lwres_lwpacket_t pkt;
/*
* Send data state. If sendbuf != buffer (that is, the send buffer
* isn't our receive buffer) it will be freed to the lwres_context_t.
*/
unsigned char *sendbuf;
isc_uint32_t sendlength;
isc_buffer_t recv_buffer;
/*
* gabn (get address by name) state info.
*/
dns_adbfind_t *find;
dns_adbfind_t *v4find;
dns_adbfind_t *v6find;
unsigned int find_wanted; /* Addresses we want */
dns_fixedname_t target_name;
lwres_gabnresponse_t gabn;
/*
* gnba (get name by address) state info.
*/
lwres_gnbaresponse_t gnba;
dns_byaddr_t *byaddr;
unsigned int options;
isc_netaddr_t na;
dns_adbaddrinfo_t *addrinfo;
/*
* Alias and address info. This is copied up to the gabn/gnba
* structures eventually.
*
* XXXMLG We can keep all of this in a client since we only service
* three packet types right now. If we started handling more,
* we'd need to use "arg" above and allocate/destroy things.
*/
char *aliases[LWRES_MAX_ALIASES];
isc_uint16_t aliaslen[LWRES_MAX_ALIASES];
lwres_addr_t addrs[LWRES_MAX_ADDRS];
};
/*
* Client states.
*
* _IDLE The client is not doing anything at all.
*
* _RECV The client is waiting for data after issuing a socket recv().
*
* _RECVDONE Data has been received, and is being processed.
*
* _FINDWAIT An adb (or other) request was made that cannot be satisfied
* immediately. An event will wake the client up.
*
* _SEND All data for a response has completed, and a reply was
* sent via a socket send() call.
*
* Badly formatted state table:
*
* IDLE -> RECV when client has a recv() queued.
*
* RECV -> RECVDONE when recvdone event received.
*
* RECVDONE -> SEND if the data for a reply is at hand.
* RECVDONE -> FINDWAIT if more searching is needed, and events will
* eventually wake us up again.
*
* FINDWAIT -> SEND when enough data was received to reply.
*
* SEND -> IDLE when a senddone event was received.
*
* At any time -> IDLE on error. Sometimes this will be -> SEND
* instead, if enough data is on hand to reply with a meaningful
* error.
*
* Packets which are badly formatted may or may not get error returns.
*/
#define CLIENT_STATE_IDLE 1
#define CLIENT_STATE_RECV 2
#define CLIENT_STATE_RECVDONE 3
#define CLIENT_STATE_FINDWAIT 4
#define CLIENT_STATE_SEND 5
#define CLIENT_STATE_SENDDONE 6
#define CLIENT_ISIDLE(c) ((c)->state == CLIENT_STATE_IDLE)
#define CLIENT_ISRECV(c) ((c)->state == CLIENT_STATE_RECV)
#define CLIENT_ISRECVDONE(c) ((c)->state == CLIENT_STATE_RECVDONE)
#define CLIENT_ISFINDWAIT(c) ((c)->state == CLIENT_STATE_FINDWAIT)
#define CLIENT_ISSEND(c) ((c)->state == CLIENT_STATE_SEND)
/*
* Overall magic test that means we're not idle.
*/
#define CLIENT_ISRUNNING(c) (!CLIENT_ISIDLE(c))
#define CLIENT_SETIDLE(c) ((c)->state = CLIENT_STATE_IDLE)
#define CLIENT_SETRECV(c) ((c)->state = CLIENT_STATE_RECV)
#define CLIENT_SETRECVDONE(c) ((c)->state = CLIENT_STATE_RECVDONE)
#define CLIENT_SETFINDWAIT(c) ((c)->state = CLIENT_STATE_FINDWAIT)
#define CLIENT_SETSEND(c) ((c)->state = CLIENT_STATE_SEND)
#define CLIENT_SETSENDDONE(c) ((c)->state = CLIENT_STATE_SENDDONE)
struct clientmgr_s {
isc_mem_t *mctx;
isc_task_t *task; /* owning task */
isc_socket_t *sock; /* socket to use */
dns_view_t *view;
unsigned int flags;
isc_event_t sdev; /* shutdown event */
lwres_context_t *lwctx; /* lightweight proto context */
ISC_LIST(client_t) idle; /* idle client slots */
ISC_LIST(client_t) running; /* running clients */
};
#define CLIENTMGR_FLAG_RECVPENDING 0x00000001
#define CLIENTMGR_FLAG_SHUTTINGDOWN 0x00000002
void client_initialize(client_t *, clientmgr_t *);
isc_result_t client_start_recv(clientmgr_t *);
void client_state_idle(client_t *);
void client_recv(isc_task_t *, isc_event_t *);
void client_shutdown(isc_task_t *, isc_event_t *);
void client_send(isc_task_t *, isc_event_t *);
/*
* Processing functions of various types.
*/
void process_gabn(client_t *, lwres_buffer_t *);
void process_gnba(client_t *, lwres_buffer_t *);
void process_noop(client_t *, lwres_buffer_t *);
void error_pkt_send(client_t *, isc_uint32_t);
void client_init_aliases(client_t *);
void client_init_gabn(client_t *);
void client_init_gnba(client_t *);
void DP(int level, const char *format, ...);
void hexdump(char *msg, void *base, size_t len);
#endif /* LWD_CLIENT_H */

View File

@@ -1,81 +0,0 @@
/*
* Copyright (C) 2000 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: err_pkt.c,v 1.5 2000/06/22 21:49:11 tale Exp $ */
#include <config.h>
#include <isc/socket.h>
#include <isc/util.h>
#include "client.h"
/*
* Generate an error packet for the client, schedule a send, and put us in
* the SEND state.
*
* The client->pkt structure will be modified to form an error return.
* The receiver needs to verify that it is in fact an error, and do the
* right thing with it. The opcode will be unchanged. The result needs
* to be set before calling this function.
*
* The only change this code makes is to set the receive buffer size to the
* size we use, set the reply bit, and recompute any security information.
*/
void
error_pkt_send(client_t *client, isc_uint32_t _result) {
isc_result_t result;
int lwres;
isc_region_t r;
lwres_buffer_t b;
clientmgr_t *cm;
cm = client->clientmgr;
REQUIRE(CLIENT_ISRUNNING(client));
/*
* Since we are only sending the packet header, we can safely toss
* the receive buffer. This means we won't need to allocate space
* for sending an error reply. This is a Good Thing.
*/
client->pkt.length = LWRES_LWPACKET_LENGTH;
client->pkt.pktflags |= LWRES_LWPACKETFLAG_RESPONSE;
client->pkt.recvlength = LWRES_RECVLENGTH;
client->pkt.authtype = 0; /* XXXMLG */
client->pkt.authlength = 0;
client->pkt.result = _result;
lwres_buffer_init(&b, client->buffer, LWRES_RECVLENGTH);
lwres = lwres_lwpacket_renderheader(&b, &client->pkt);
if (lwres != LWRES_R_SUCCESS) {
client_state_idle(client);
return;
}
r.base = client->buffer;
r.length = b.used;
client->sendbuf = client->buffer;
result = isc_socket_sendto(cm->sock, &r, cm->task, client_send, client,
&client->address, NULL);
if (result != ISC_R_SUCCESS) {
client_state_idle(client);
return;
}
CLIENT_SETSEND(client);
}

View File

@@ -1,509 +0,0 @@
/*
* Copyright (C) 2000 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: main.c,v 1.43 2000/06/22 21:49:12 tale Exp $ */
/*
* Main program for the Lightweight Resolver Daemon.
*
* To paraphrase the old saying about X11, "It's not a lightweight deamon
* for resolvers, it's a deamon for lightweight resolvers".
*/
#include <config.h>
#include <stdlib.h>
#include <isc/app.h>
#include <isc/mem.h>
#include <isc/string.h>
#include <isc/task.h>
#include <isc/timer.h>
#include <isc/util.h>
#include <dns/cache.h>
#include <dns/db.h>
#include <dns/dispatch.h>
#include <dns/log.h>
#include <dns/resolver.h>
#include <dns/result.h>
#include <dns/rootns.h>
#include <dns/view.h>
#include "client.h"
/*
* The goal number of clients we can handle will be NTASKS * NRECVS.
*/
#define NTASKS 20 /* tasks to create to handle lwres queries */
#define NRECVS 5 /* max clients per task */
#define NTHREADS 1 /* # threads to create in thread manager */
/*
* Array of client managers. Each of these will have a task associated
* with it.
*/
clientmgr_t *cmgr;
unsigned int ntasks; /* number of tasks actually created */
dns_view_t *view;
isc_taskmgr_t *taskmgr;
isc_socketmgr_t *sockmgr;
isc_timermgr_t *timermgr;
dns_dispatchmgr_t *dispatchmgr;
isc_sockaddrlist_t forwarders;
static isc_logmodule_t logmodules[] = {
{ "main", 0 },
{ NULL, 0 }
};
#define LWRES_LOGMODULE_MAIN (&logmodules[0])
static isc_logcategory_t logcategories[] = {
{ "network", 0 },
{ NULL, 0 }
};
#define LWRES_LOGCATEGORY_NETWORK (&logcategories[0])
static isc_result_t
create_view(isc_mem_t *mctx) {
dns_cache_t *cache;
isc_result_t result;
dns_db_t *rootdb;
unsigned int attrs;
dns_dispatch_t *disp4 = NULL;
dns_dispatch_t *disp6 = NULL;
view = NULL;
cache = NULL;
/*
* View.
*/
result = dns_view_create(mctx, dns_rdataclass_in, "_default", &view);
if (result != ISC_R_SUCCESS)
goto out;
/*
* Cache.
*/
result = dns_cache_create(mctx, taskmgr, timermgr, dns_rdataclass_in,
"rbt", 0, NULL, &cache);
if (result != ISC_R_SUCCESS)
goto out;
dns_view_setcache(view, cache);
dns_cache_detach(&cache);
/*
* Resolver.
*
* XXXMLG hardwired number of tasks.
*/
if (isc_net_probeipv4() == ISC_R_SUCCESS) {
isc_sockaddr_t any4;
isc_sockaddr_any(&any4);
attrs = DNS_DISPATCHATTR_IPV4 | DNS_DISPATCHATTR_UDP;
result = dns_dispatch_getudp(dispatchmgr, sockmgr,
taskmgr, &any4, 512, 6, 1024,
17, 19, attrs, attrs, &disp4);
if (result != ISC_R_SUCCESS)
goto out;
}
if (isc_net_probeipv6() == ISC_R_SUCCESS) {
isc_sockaddr_t any6;
isc_sockaddr_any6(&any6);
attrs = DNS_DISPATCHATTR_IPV6 | DNS_DISPATCHATTR_UDP;
result = dns_dispatch_getudp(dispatchmgr, sockmgr,
taskmgr, &any6, 512, 6, 1024,
17, 19, attrs, attrs, &disp6);
if (result != ISC_R_SUCCESS)
goto out;
}
result = dns_view_createresolver(view, taskmgr, 16, sockmgr,
timermgr, 0, dispatchmgr,
disp4, disp6);
if (disp4 != NULL)
dns_dispatch_detach(&disp4);
if (disp6 != NULL)
dns_dispatch_detach(&disp6);
if (result != ISC_R_SUCCESS)
goto out;
rootdb = NULL;
result = dns_rootns_create(mctx, dns_rdataclass_in, NULL, &rootdb);
if (result != ISC_R_SUCCESS)
goto out;
dns_view_sethints(view, rootdb);
dns_db_detach(&rootdb);
/*
* If we have forwarders, set them here.
*/
if (ISC_LIST_HEAD(forwarders) != NULL) {
isc_sockaddr_t *sa;
dns_resolver_setforwarders(view->resolver, &forwarders);
dns_resolver_setfwdpolicy(view->resolver, dns_fwdpolicy_only);
sa = ISC_LIST_HEAD(forwarders);
while (sa != NULL) {
ISC_LIST_UNLINK(forwarders, sa, link);
isc_mem_put(mctx, sa, sizeof (*sa));
sa = ISC_LIST_HEAD(forwarders);
}
}
dns_view_freeze(view);
return (ISC_R_SUCCESS);
out:
if (view != NULL)
dns_view_detach(&view);
return (result);
}
/*
* Wrappers around our memory management stuff, for the lwres functions.
*/
static void *
mem_alloc(void *arg, size_t size) {
return (isc_mem_get(arg, size));
}
static void
mem_free(void *arg, void *mem, size_t size) {
isc_mem_put(arg, mem, size);
}
static void
parse_resolv_conf(isc_mem_t *mem) {
lwres_context_t *lwctx;
lwres_conf_t *lwc;
int lwresult;
struct in_addr ina;
struct in6_addr ina6;
isc_sockaddr_t *sa;
int i;
lwctx = NULL;
lwresult = lwres_context_create(&lwctx, mem, mem_alloc, mem_free,
LWRES_CONTEXT_SERVERMODE);
if (lwresult != LWRES_R_SUCCESS)
return;
lwresult = lwres_conf_parse(lwctx, "/etc/resolv.conf");
if (lwresult != LWRES_R_SUCCESS)
goto out;
#if 1
lwres_conf_print(lwctx, stderr);
#endif
lwc = lwres_conf_get(lwctx);
INSIST(lwc != NULL);
/*
* Run through the list of nameservers, and set them to be our
* forwarders.
*/
for (i = 0 ; i < lwc->nsnext ; i++) {
switch (lwc->nameservers[i].family) {
case AF_INET:
sa = isc_mem_get(mem, sizeof *sa);
INSIST(sa != NULL);
memcpy(&ina.s_addr, lwc->nameservers[i].address, 4);
isc_sockaddr_fromin(sa, &ina, 53);
ISC_LIST_APPEND(forwarders, sa, link);
sa = NULL;
break;
case AF_INET6:
sa = isc_mem_get(mem, sizeof *sa);
INSIST(sa != NULL);
memcpy(&ina6.s6_addr, lwc->nameservers[i].address, 16);
isc_sockaddr_fromin6(sa, &ina6, 53);
ISC_LIST_APPEND(forwarders, sa, link);
sa = NULL;
break;
default:
break;
}
}
out:
lwres_conf_clear(lwctx);
lwres_context_destroy(&lwctx);
}
int
main(int argc, char **argv) {
isc_mem_t *mem;
isc_socket_t *sock;
isc_sockaddr_t localhost;
struct in_addr lh_addr;
isc_result_t result;
unsigned int i, j;
client_t *client;
isc_logdestination_t destination;
isc_log_t *lctx;
isc_logconfig_t *lcfg;
UNUSED(argc);
UNUSED(argv);
dns_result_register();
result = isc_app_start();
INSIST(result == ISC_R_SUCCESS);
mem = NULL;
result = isc_mem_create(0, 0, &mem);
INSIST(result == ISC_R_SUCCESS);
/*
* Set up logging.
*/
lctx = NULL;
result = isc_log_create(mem, &lctx, &lcfg);
INSIST(result == ISC_R_SUCCESS);
isc_log_registermodules(lctx, logmodules);
isc_log_registercategories(lctx, logcategories);
isc_log_setcontext(lctx);
dns_log_init(lctx);
dns_log_setcontext(lctx);
destination.file.stream = stderr;
destination.file.name = NULL;
destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0;
result = isc_log_createchannel(lcfg, "_default",
ISC_LOG_TOFILEDESC,
ISC_LOG_DYNAMIC,
&destination, ISC_LOG_PRINTTIME);
INSIST(result == ISC_R_SUCCESS);
result = isc_log_usechannel(lcfg, "_default", NULL, NULL);
INSIST(result == ISC_R_SUCCESS);
/*
* Set the initial debug level.
*/
isc_log_setdebuglevel(lctx, 99);
/*
* Create a task manager.
*/
taskmgr = NULL;
result = isc_taskmgr_create(mem, NTHREADS, 0, &taskmgr);
INSIST(result == ISC_R_SUCCESS);
/*
* Create a socket manager.
*/
sockmgr = NULL;
result = isc_socketmgr_create(mem, &sockmgr);
INSIST(result == ISC_R_SUCCESS);
/*
* Create a timer manager.
*/
timermgr = NULL;
result = isc_timermgr_create(mem, &timermgr);
INSIST(result == ISC_R_SUCCESS);
/*
* Create a dispatch manager.
*/
dispatchmgr = NULL;
result = dns_dispatchmgr_create(mem, NULL, &dispatchmgr);
INSIST(result == ISC_R_SUCCESS);
/*
* Read resolv.conf to get our forwarders.
*/
ISC_LIST_INIT(forwarders);
parse_resolv_conf(mem);
/*
* Initialize the DNS bits. Start by loading our built-in
* root hints.
*/
result = create_view(mem);
INSIST(result == ISC_R_SUCCESS);
/*
* We'll need a socket. It will be a UDP socket, and bound to
* 127.0.0.1 port LWRES_UDP_PORT.
*/
sock = NULL;
result = isc_socket_create(sockmgr, AF_INET, isc_sockettype_udp,
&sock);
INSIST(result == ISC_R_SUCCESS);
lh_addr.s_addr = htonl(INADDR_LOOPBACK);
isc_sockaddr_fromin(&localhost, &lh_addr, LWRES_UDP_PORT);
result = isc_socket_bind(sock, &localhost);
if (result != ISC_R_SUCCESS) {
isc_log_write(lctx, LWRES_LOGCATEGORY_NETWORK,
LWRES_LOGMODULE_MAIN, ISC_LOG_ERROR,
"binding lwres protocol socket to port %d: %s",
LWRES_UDP_PORT,
isc_result_totext(result));
exit(1);
}
INSIST(result == ISC_R_SUCCESS);
cmgr = isc_mem_get(mem, sizeof(clientmgr_t) * NTASKS);
INSIST(cmgr != NULL);
/*
* Create one task for each client manager.
*/
for (i = 0 ; i < NTASKS ; i++) {
cmgr[i].task = NULL;
cmgr[i].sock = sock;
cmgr[i].view = NULL;
cmgr[i].flags = 0;
result = isc_task_create(taskmgr, 0, &cmgr[i].task);
if (result != ISC_R_SUCCESS)
break;
ISC_EVENT_INIT(&cmgr[i].sdev, sizeof(isc_event_t),
ISC_EVENTATTR_NOPURGE,
0, LWRD_SHUTDOWN,
client_shutdown, &cmgr[i], cmgr[i].task,
NULL, NULL);
ISC_LIST_INIT(cmgr[i].idle);
ISC_LIST_INIT(cmgr[i].running);
isc_task_setname(cmgr[i].task, "lwresd client", &cmgr[i]);
cmgr[i].mctx = mem;
cmgr[i].lwctx = NULL;
result = lwres_context_create(&cmgr[i].lwctx, mem,
mem_alloc, mem_free,
LWRES_CONTEXT_SERVERMODE);
if (result != ISC_R_SUCCESS) {
isc_task_detach(&cmgr[i].task);
break;
}
dns_view_attach(view, &cmgr[i].view);
}
INSIST(i > 0);
ntasks = i; /* remember how many we managed to create */
/*
* Now, run through each client manager and populate it with
* client structures. Do this by creating one receive for each
* task, in a loop, so each task has a chance of getting at least
* one client structure.
*/
for (i = 0 ; i < NRECVS ; i++) {
client = isc_mem_get(mem, sizeof(client_t) * ntasks);
if (client == NULL)
break;
for (j = 0 ; j < ntasks ; j++)
client_initialize(&client[j], &cmgr[j]);
}
INSIST(i > 0);
/*
* Issue one read request for each task we have.
*/
for (j = 0 ; j < ntasks ; j++) {
result = client_start_recv(&cmgr[j]);
INSIST(result == ISC_R_SUCCESS);
}
/*
* Wait for ^c or kill.
*/
isc_app_run();
/*
* Send a shutdown event to every task.
*/
for (j = 0 ; j < ntasks ; j++) {
isc_event_t *ev;
ev = &cmgr[j].sdev;
isc_task_send(cmgr[j].task, &ev);
}
/*
* Kill off the view.
*/
dns_view_detach(&view);
/*
* Wait for the tasks to all die.
*/
isc_taskmgr_destroy(&taskmgr);
/*
* Wait for everything to die off by waiting for the sockets
* to be detached.
*/
isc_socket_detach(&sock);
isc_socketmgr_destroy(&sockmgr);
isc_timermgr_destroy(&timermgr);
/*
* Free up memory allocated. This is somewhat magical. We allocated
* the client_t's in blocks, but the first task always has the
* first pointer. Just loop here, freeing them.
*/
client = ISC_LIST_HEAD(cmgr[0].idle);
while (client != NULL) {
ISC_LIST_UNLINK(cmgr[0].idle, client, link);
isc_mem_put(mem, client, sizeof(client_t) * ntasks);
client = ISC_LIST_HEAD(cmgr[0].idle);
}
INSIST(ISC_LIST_EMPTY(cmgr[0].running));
/*
* Now, kill off the client manager structures.
*/
isc_mem_put(mem, cmgr, sizeof(clientmgr_t) * NTASKS);
cmgr = NULL;
dns_dispatchmgr_destroy(&dispatchmgr);
isc_log_destroy(&lctx);
/*
* Kill the memory system.
*/
isc_mem_destroy(&mem);
isc_app_finish();
return (0);
}

View File

@@ -1,526 +0,0 @@
/*
* Copyright (C) 2000 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: process_gabn.c,v 1.29 2000/06/22 21:49:13 tale Exp $ */
#include <config.h>
#include <isc/socket.h>
#include <isc/string.h> /* Required for HP/UX (and others?) */
#include <isc/util.h>
#include <dns/adb.h>
#include <dns/events.h>
#include <dns/result.h>
#include "client.h"
#define NEED_V4(c) ((((c)->find_wanted & LWRES_ADDRTYPE_V4) != 0) \
&& ((c)->v4find == NULL))
#define NEED_V6(c) ((((c)->find_wanted & LWRES_ADDRTYPE_V6) != 0) \
&& ((c)->v6find == NULL))
static void start_find(client_t *);
/*
* Destroy any finds. This can be used to "start over from scratch" and
* should only be called when events are _not_ being generated by the finds.
*/
static void
cleanup_gabn(client_t *client) {
dns_adbfind_t *v4;
DP(50, "cleaning up client %p", client);
v4 = client->v4find;
if (client->v4find != NULL)
dns_adb_destroyfind(&client->v4find);
if (client->v6find != NULL) {
if (client->v6find == v4)
client->v6find = NULL;
else
dns_adb_destroyfind(&client->v6find);
}
}
static void
setup_addresses(client_t *client, dns_adbfind_t *find, unsigned int at) {
dns_adbaddrinfo_t *ai;
lwres_addr_t *addr;
int af;
const struct sockaddr *sa;
const struct sockaddr_in *sin;
const struct sockaddr_in6 *sin6;
if (at == DNS_ADBFIND_INET)
af = AF_INET;
else
af = AF_INET6;
ai = ISC_LIST_HEAD(find->list);
while (ai != NULL && client->gabn.naddrs < LWRES_MAX_ADDRS) {
sa = &ai->sockaddr.type.sa;
if (sa->sa_family != af)
goto next;
addr = &client->addrs[client->gabn.naddrs];
switch (sa->sa_family) {
case AF_INET:
sin = &ai->sockaddr.type.sin;
addr->family = LWRES_ADDRTYPE_V4;
memcpy(addr->address, &sin->sin_addr, 4);
addr->length = 4;
break;
case AF_INET6:
sin6 = &ai->sockaddr.type.sin6;
addr->family = LWRES_ADDRTYPE_V6;
memcpy(addr->address, &sin6->sin6_addr, 16);
addr->length = 16;
break;
default:
goto next;
}
DP(50, "adding address %p, family %d, length %d",
addr->address, addr->family, addr->length);
client->gabn.naddrs++;
REQUIRE(!LWRES_LINK_LINKED(addr, link));
LWRES_LIST_APPEND(client->gabn.addrs, addr, link);
next:
ai = ISC_LIST_NEXT(ai, publink);
}
}
static void
generate_reply(client_t *client) {
isc_result_t result;
int lwres;
isc_region_t r;
lwres_buffer_t lwb;
clientmgr_t *cm;
cm = client->clientmgr;
lwb.base = NULL;
DP(50, "generating gabn reply for client %p", client);
/*
* We must make certain the client->find is not still active.
* If it is either the v4 or v6 answer, just set it to NULL and
* let the cleanup code destroy it. Otherwise, destroy it now.
*/
if (client->find == client->v4find || client->find == client->v6find)
client->find = NULL;
else
if (client->find != NULL)
dns_adb_destroyfind(&client->find);
/*
* perhaps there are some here?
*/
if (NEED_V6(client) && client->v4find != NULL)
client->v6find = client->v4find;
/*
* Run through the finds we have and wire them up to the gabn
* structure.
*/
LWRES_LIST_INIT(client->gabn.addrs);
if (client->v4find != NULL)
setup_addresses(client, client->v4find, DNS_ADBFIND_INET);
if (client->v6find != NULL)
setup_addresses(client, client->v6find, DNS_ADBFIND_INET6);
/*
* Render the packet.
*/
client->pkt.recvlength = LWRES_RECVLENGTH;
client->pkt.authtype = 0; /* XXXMLG */
client->pkt.authlength = 0;
/*
* If there are no addresses and no aliases, return failure.
*/
if (client->gabn.naddrs == 0 && client->gabn.naliases == 0)
client->pkt.result = LWRES_R_NOTFOUND;
else
client->pkt.result = LWRES_R_SUCCESS;
lwres = lwres_gabnresponse_render(cm->lwctx, &client->gabn,
&client->pkt, &lwb);
if (lwres != LWRES_R_SUCCESS)
goto out;
r.base = lwb.base;
r.length = lwb.used;
client->sendbuf = r.base;
client->sendlength = r.length;
result = isc_socket_sendto(cm->sock, &r, cm->task, client_send, client,
&client->address, NULL);
if (result != ISC_R_SUCCESS)
goto out;
CLIENT_SETSEND(client);
/*
* All done!
*/
cleanup_gabn(client);
return;
out:
cleanup_gabn(client);
if (lwb.base != NULL)
lwres_context_freemem(client->clientmgr->lwctx,
lwb.base, lwb.length);
error_pkt_send(client, LWRES_R_FAILURE);
}
/*
* Take the current real name, move it to an alias slot (if any are
* open) then put this new name in as the real name for the target.
*
* Return success if it can be rendered, otherwise failure. Note that
* not having enough alias slots open is NOT a failure.
*/
static isc_result_t
add_alias(client_t *client) {
isc_buffer_t b;
isc_result_t result;
isc_uint16_t naliases;
b = client->recv_buffer;
/*
* Render the new name to the buffer.
*/
result = dns_name_totext(dns_fixedname_name(&client->target_name),
ISC_TRUE, &client->recv_buffer);
if (result != ISC_R_SUCCESS)
return (result);
/*
* Are there any open slots?
*/
naliases = client->gabn.naliases;
if (naliases < LWRES_MAX_ALIASES) {
client->gabn.aliases[naliases] = client->gabn.realname;
client->gabn.aliaslen[naliases] = client->gabn.realnamelen;
client->gabn.naliases++;
}
/*
* Save this name away as the current real name.
*/
client->gabn.realname = (char *)(b.base) + b.used;
client->gabn.realnamelen = client->recv_buffer.used - b.used;
return (ISC_R_SUCCESS);
}
static isc_result_t
store_realname(client_t *client) {
isc_buffer_t b;
isc_result_t result;
b = client->recv_buffer;
/*
* Render the new name to the buffer.
*/
result = dns_name_totext(dns_fixedname_name(&client->target_name),
ISC_TRUE, &client->recv_buffer);
if (result != ISC_R_SUCCESS)
return (result);
/*
* Save this name away as the current real name.
*/
client->gabn.realname = (char *) b.base + b.used;
client->gabn.realnamelen = client->recv_buffer.used - b.used;
return (ISC_R_SUCCESS);
}
static void
process_gabn_finddone(isc_task_t *task, isc_event_t *ev) {
client_t *client = ev->ev_arg;
isc_eventtype_t evtype;
isc_boolean_t claimed;
DP(50, "find done for task %p, client %p", task, client);
evtype = ev->ev_type;
isc_event_free(&ev);
/*
* No more info to be had? If so, we have all the good stuff
* right now, so we can render things.
*/
claimed = ISC_FALSE;
if (evtype == DNS_EVENT_ADBNOMOREADDRESSES) {
if (NEED_V4(client)) {
client->v4find = client->find;
claimed = ISC_TRUE;
}
if (NEED_V6(client)) {
client->v6find = client->find;
claimed = ISC_TRUE;
}
if (client->find != NULL) {
if (claimed)
client->find = NULL;
else
dns_adb_destroyfind(&client->find);
}
generate_reply(client);
return;
}
/*
* We probably don't need this find anymore. We're either going to
* reissue it, or an error occurred. Either way, we're done with
* it.
*/
if ((client->find != client->v4find)
&& (client->find != client->v6find)) {
dns_adb_destroyfind(&client->find);
} else {
client->find = NULL;
}
/*
* We have some new information we can gather. Run off and fetch
* it.
*/
if (evtype == DNS_EVENT_ADBMOREADDRESSES) {
start_find(client);
return;
}
/*
* An error or other strangeness happened. Drop this query.
*/
cleanup_gabn(client);
error_pkt_send(client, LWRES_R_FAILURE);
}
static void
start_find(client_t *client) {
unsigned int options;
isc_result_t result;
isc_boolean_t claimed;
DP(50, "starting find for client %p", client);
/*
* Issue a find for the name contained in the request. We won't
* set the bit that says "anything is good enough" -- we want it
* all.
*/
options = 0;
options |= DNS_ADBFIND_WANTEVENT;
options |= DNS_ADBFIND_RETURNLAME;
/*
* Set the bits up here to mark that we want this address family
* and that we do not currently have a find pending. We will
* set that bit again below if it turns out we will get an event.
*/
if (NEED_V4(client))
options |= DNS_ADBFIND_INET;
if (NEED_V6(client))
options |= DNS_ADBFIND_INET6;
find_again:
INSIST(client->find == NULL);
result = dns_adb_createfind(client->clientmgr->view->adb,
client->clientmgr->task,
process_gabn_finddone, client,
dns_fixedname_name(&client->target_name),
dns_rootname, options, 0,
dns_fixedname_name(&client->target_name),
client->clientmgr->view->dstport,
&client->find);
/*
* Did we get an alias? If so, save it and re-issue the query.
*/
if (result == DNS_R_ALIAS) {
DP(50, "found alias, restarting query");
dns_adb_destroyfind(&client->find);
cleanup_gabn(client);
result = add_alias(client);
if (result != ISC_R_SUCCESS) {
DP(50, "out of buffer space adding alias");
error_pkt_send(client, LWRES_R_FAILURE);
return;
}
goto find_again;
}
DP(50, "find returned %d (%s)", result, isc_result_totext(result));
/*
* Did we get an error?
*/
if (result != ISC_R_SUCCESS) {
if (client->find != NULL)
dns_adb_destroyfind(&client->find);
cleanup_gabn(client);
error_pkt_send(client, LWRES_R_FAILURE);
return;
}
claimed = ISC_FALSE;
/*
* Did we get our answer to V4 addresses?
*/
if (NEED_V4(client)
&& ((client->find->query_pending & DNS_ADBFIND_INET) == 0)) {
DP(50, "client %p ipv4 satisfied by find %p", client,
client->find);
claimed = ISC_TRUE;
client->v4find = client->find;
}
/*
* Did we get our answer to V6 addresses?
*/
if (NEED_V6(client)
&& ((client->find->query_pending & DNS_ADBFIND_INET6) == 0)) {
DP(50, "client %p ipv6 satisfied by find %p", client,
client->find);
claimed = ISC_TRUE;
client->v6find = client->find;
}
/*
* If we're going to get an event, set our internal pending flag
* and return. When we get an event back we'll do the right
* thing, basically by calling this function again, perhaps with a
* new target name.
*
* If we have both v4 and v6, and we are still getting an event,
* we have a programming error, so die hard.
*/
if ((client->find->options & DNS_ADBFIND_WANTEVENT) != 0) {
DP(50, "event will be sent");
INSIST(client->v4find == NULL || client->v6find == NULL);
return;
}
DP(50, "no event will be sent");
if (claimed)
client->find = NULL;
else
dns_adb_destroyfind(&client->find);
/*
* We seem to have everything we asked for, or at least we are
* able to respond with things we've learned.
*/
generate_reply(client);
}
/*
* When we are called, we can be assured that:
*
* client->sockaddr contains the address we need to reply to,
*
* client->pkt contains the packet header data,
*
* the packet "checks out" overall -- any MD5 hashes or crypto
* bits have been verified,
*
* "b" points to the remaining data after the packet header
* was parsed off.
*
* We are in a the RECVDONE state.
*
* From this state we will enter the SEND state if we happen to have
* everything we need or we need to return an error packet, or to the
* FINDWAIT state if we need to look things up.
*/
void
process_gabn(client_t *client, lwres_buffer_t *b) {
isc_result_t result;
lwres_gabnrequest_t *req;
isc_buffer_t namebuf;
REQUIRE(CLIENT_ISRECVDONE(client));
req = NULL;
result = lwres_gabnrequest_parse(client->clientmgr->lwctx,
b, &client->pkt, &req);
if (result != LWRES_R_SUCCESS)
goto out;
isc_buffer_init(&namebuf, req->name, req->namelen);
isc_buffer_add(&namebuf, req->namelen);
dns_fixedname_init(&client->target_name);
result = dns_name_fromtext(dns_fixedname_name(&client->target_name),
&namebuf, dns_rootname, ISC_FALSE, NULL);
if (result != ISC_R_SUCCESS)
goto out;
client->find_wanted = req->addrtypes;
DP(50, "client %p looking for addrtypes %08x",
client, client->find_wanted);
/*
* We no longer need to keep this around.
*/
lwres_gabnrequest_free(client->clientmgr->lwctx, &req);
/*
* Initialize the real name and alias arrays in the reply we're
* going to build up.
*/
client_init_gabn(client);
result = store_realname(client);
if (result != ISC_R_SUCCESS)
goto out;
/*
* Start the find.
*/
start_find(client);
return;
/*
* We're screwed. Return an error packet to our caller.
*/
out:
if (req != NULL)
lwres_gabnrequest_free(client->clientmgr->lwctx, &req);
error_pkt_send(client, LWRES_R_FAILURE);
}

View File

@@ -1,264 +0,0 @@
/*
* Copyright (C) 2000 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: process_gnba.c,v 1.24 2000/06/22 21:49:15 tale Exp $ */
#include <config.h>
#include <isc/socket.h>
#include <isc/string.h> /* Required for HP/UX (and others?) */
#include <isc/util.h>
#include <dns/adb.h>
#include <dns/byaddr.h>
#include <dns/result.h>
#include "client.h"
static void start_byaddr(client_t *);
static void
byaddr_done(isc_task_t *task, isc_event_t *event) {
client_t *client;
clientmgr_t *cm;
dns_byaddrevent_t *bevent;
int lwres;
lwres_buffer_t lwb;
dns_name_t *name;
isc_result_t result;
isc_region_t r;
isc_buffer_t b;
lwres_gnbaresponse_t *gnba;
isc_uint16_t naliases;
isc_stdtime_t now;
UNUSED(task);
lwb.base = NULL;
client = event->ev_arg;
cm = client->clientmgr;
INSIST(client->byaddr == (dns_byaddr_t *)event->ev_sender);
bevent = (dns_byaddrevent_t *)event;
gnba = &client->gnba;
DP(50, "byaddr event result = %s",
isc_result_totext(bevent->result));
result = bevent->result;
if (result != ISC_R_SUCCESS) {
dns_byaddr_destroy(&client->byaddr);
isc_event_free(&event);
bevent = NULL;
/*
* Were we trying bitstring or nibble mode? If bitstring,
* and we got FORMERROR or SERVFAIL, set the flag to
* avoid bitstring lables for 10 minutes. If we got any
* other error (NXDOMAIN, etc) just try again without
* bitstrings, and let our cache handle the negative answer
* for bitstrings.
*/
if ((client->options & DNS_BYADDROPT_IPV6NIBBLE) != 0) {
dns_adb_freeaddrinfo(cm->view->adb, &client->addrinfo);
error_pkt_send(client, LWRES_R_FAILURE);
return;
}
isc_stdtime_get(&now);
if (result == DNS_R_FORMERR ||
result == DNS_R_SERVFAIL ||
result == ISC_R_FAILURE)
dns_adb_setavoidbitstring(cm->view->adb,
client->addrinfo, now + 600);
/*
* Fall back to nibble reverse if the default of bitstrings
* fails.
*/
client->options |= DNS_BYADDROPT_IPV6NIBBLE;
start_byaddr(client);
return;
}
name = ISC_LIST_HEAD(bevent->names);
while (name != NULL) {
b = client->recv_buffer;
result = dns_name_totext(name, ISC_TRUE, &client->recv_buffer);
if (result != ISC_R_SUCCESS)
goto out;
DP(50, "found name '%.*s'",
client->recv_buffer.used - b.used,
(char *)(b.base) + b.used);
if (gnba->realname == NULL) {
gnba->realname = (char *)(b.base) + b.used;
gnba->realnamelen = client->recv_buffer.used - b.used;
} else {
naliases = gnba->naliases;
if (naliases >= LWRES_MAX_ALIASES)
break;
gnba->aliases[naliases] = (char *)(b.base) + b.used;
gnba->aliaslen[naliases] =
client->recv_buffer.used - b.used;
gnba->naliases++;
}
name = ISC_LIST_NEXT(name, link);
}
dns_byaddr_destroy(&client->byaddr);
dns_adb_freeaddrinfo(cm->view->adb, &client->addrinfo);
isc_event_free(&event);
/*
* Render the packet.
*/
client->pkt.recvlength = LWRES_RECVLENGTH;
client->pkt.authtype = 0; /* XXXMLG */
client->pkt.authlength = 0;
client->pkt.result = LWRES_R_SUCCESS;
lwres = lwres_gnbaresponse_render(cm->lwctx,
gnba, &client->pkt, &lwb);
if (lwres != LWRES_R_SUCCESS)
goto out;
r.base = lwb.base;
r.length = lwb.used;
client->sendbuf = r.base;
client->sendlength = r.length;
result = isc_socket_sendto(cm->sock, &r,
cm->task, client_send,
client, &client->address, NULL);
if (result != ISC_R_SUCCESS)
goto out;
CLIENT_SETSEND(client);
return;
out:
if (client->byaddr != NULL)
dns_byaddr_destroy(&client->byaddr);
if (client->addrinfo != NULL)
dns_adb_freeaddrinfo(cm->view->adb, &client->addrinfo);
if (lwb.base != NULL)
lwres_context_freemem(cm->lwctx,
lwb.base, lwb.length);
isc_event_free(&event);
}
static void
start_byaddr(client_t *client) {
isc_result_t result;
clientmgr_t *cm;
cm = client->clientmgr;
INSIST(client->byaddr == NULL);
result = dns_byaddr_create(cm->mctx, &client->na, cm->view,
client->options, cm->task, byaddr_done,
client, &client->byaddr);
if (result != ISC_R_SUCCESS) {
dns_adb_freeaddrinfo(cm->view->adb, &client->addrinfo);
error_pkt_send(client, LWRES_R_FAILURE);
return;
}
}
void
process_gnba(client_t *client, lwres_buffer_t *b) {
lwres_gnbarequest_t *req;
isc_result_t result;
isc_sockaddr_t sa;
clientmgr_t *cm;
REQUIRE(CLIENT_ISRECVDONE(client));
INSIST(client->byaddr == NULL);
cm = client->clientmgr;
req = NULL;
result = lwres_gnbarequest_parse(cm->lwctx,
b, &client->pkt, &req);
if (result != LWRES_R_SUCCESS)
goto out;
if (req->addr.address == NULL)
goto out;
client->options = 0;
if (req->addr.family == LWRES_ADDRTYPE_V4) {
client->na.family = AF_INET;
if (req->addr.length != 4)
goto out;
memcpy(&client->na.type.in, req->addr.address, 4);
} else if (req->addr.family == LWRES_ADDRTYPE_V6) {
client->na.family = AF_INET6;
if (req->addr.length != 16)
goto out;
memcpy(&client->na.type.in6, req->addr.address, 16);
} else {
goto out;
}
isc_sockaddr_fromnetaddr(&sa, &client->na, 53);
DP(50, "client %p looking for addrtype %08x",
client, req->addr.family);
/*
* We no longer need to keep this around.
*/
lwres_gnbarequest_free(cm->lwctx, &req);
/*
* Initialize the real name and alias arrays in the reply we're
* going to build up.
*/
client_init_gnba(client);
client->options = 0;
/*
* See if we should skip the byaddr bit.
*/
INSIST(client->addrinfo == NULL);
result = dns_adb_findaddrinfo(cm->view->adb, &sa,
&client->addrinfo, 0);
if (result != ISC_R_SUCCESS)
goto out;
if (client->addrinfo->avoid_bitstring > 0)
client->options |= DNS_BYADDROPT_IPV6NIBBLE;
/*
* Start the find.
*/
start_byaddr(client);
return;
/*
* We're screwed. Return an error packet to our caller.
*/
out:
if (req != NULL)
lwres_gnbarequest_free(cm->lwctx, &req);
error_pkt_send(client, LWRES_R_FAILURE);
}

View File

@@ -1,87 +0,0 @@
/*
* Copyright (C) 2000 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: process_noop.c,v 1.7 2000/06/22 21:49:16 tale Exp $ */
#include <config.h>
#include <isc/socket.h>
#include <isc/util.h>
#include "client.h"
void
process_noop(client_t *client, lwres_buffer_t *b) {
lwres_nooprequest_t *req;
lwres_noopresponse_t resp;
isc_result_t result;
lwres_result_t lwres;
isc_region_t r;
lwres_buffer_t lwb;
REQUIRE(CLIENT_ISRECVDONE(client));
INSIST(client->byaddr == NULL);
req = NULL;
result = lwres_nooprequest_parse(client->clientmgr->lwctx,
b, &client->pkt, &req);
if (result != LWRES_R_SUCCESS)
goto out;
client->pkt.recvlength = LWRES_RECVLENGTH;
client->pkt.authtype = 0; /* XXXMLG */
client->pkt.authlength = 0;
client->pkt.result = LWRES_R_SUCCESS;
resp.datalength = req->datalength;
resp.data = req->data;
lwres = lwres_noopresponse_render(client->clientmgr->lwctx, &resp,
&client->pkt, &lwb);
if (lwres != LWRES_R_SUCCESS)
goto out;
r.base = lwb.base;
r.length = lwb.used;
client->sendbuf = r.base;
client->sendlength = r.length;
result = isc_socket_sendto(client->clientmgr->sock, &r,
client->clientmgr->task, client_send,
client, &client->address, NULL);
if (result != ISC_R_SUCCESS)
goto out;
/*
* We can now destroy request.
*/
lwres_nooprequest_free(client->clientmgr->lwctx, &req);
CLIENT_SETSEND(client);
return;
out:
if (req != NULL)
lwres_nooprequest_free(client->clientmgr->lwctx, &req);
if (lwb.base != NULL)
lwres_context_freemem(client->clientmgr->lwctx,
lwb.base, lwb.length);
error_pkt_send(client, LWRES_R_FAILURE);
}

View File

@@ -1,6 +0,0 @@
Makefile
.libs
*.la
*.lo
named
lwresd

View File

@@ -1,89 +0,0 @@
# Copyright (C) 1998-2000 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.in,v 1.49.2.2 2000/07/11 17:23:01 gson Exp $
srcdir = @srcdir@
VPATH = @srcdir@
top_srcdir = @top_srcdir@
@BIND9_VERSION@
@BIND9_INCLUDES@
CINCLUDES = -I${srcdir}/include -I${srcdir}/unix/include \
${LWRES_INCLUDES} ${DNS_INCLUDES} ${ISC_INCLUDES} \
${OMAPI_INCLUDES}
CDEFINES =
CWARNINGS =
OMAPILIBS = ../../lib/omapi/libomapi.@A@
DNSLIBS = ../../lib/dns/libdns.@A@ @DNS_OPENSSL_LIBS@
ISCLIBS = ../../lib/isc/libisc.@A@
LWRESLIBS = ../../lib/lwres/liblwres.@A@
OMAPIDEPLIBS = ../../lib/omapi/libomapi.@A@
DNSDEPLIBS = ../../lib/dns/libdns.@A@
ISCDEPLIBS = ../../lib/isc/libisc.@A@
LWRESDEPLIBS = ../../lib/lwres/liblwres.@A@
DEPLIBS = ${LWRESDEPLIBS} ${OMAPIDEPLIBS} ${DNSDEPLIBS} ${ISCDEPLIBS}
LIBS = ${LWRESLIBS} ${OMAPILIBS} ${DNSLIBS} ${ISCLIBS} @LIBS@
SUBDIRS = unix
TARGETS = named lwresd
OBJS = client.@O@ interfacemgr.@O@ listenlist.@O@ \
log.@O@ logconf.@O@ main.@O@ notify.@O@ omapi.@O@ \
omapiconf.@O@ query.@O@ server.@O@ update.@O@ xfrout.@O@ \
lwresd.@O@ lwdclient.@O@ lwderror.@O@ lwdgabn.@O@ \
lwdgnba.@O@ lwdnoop.@O@
UOBJS = unix/os.@O@
SRCS = client.c interfacemgr.c listenlist.c \
log.c logconf.c main.c notify.c omapi.c \
omapiconf.c query.c server.c update.c xfrout.c \
lwresd.c lwdclient.c lwderror.c lwdgabn.c \
lwdgnba.c lwdnoop.c
@BIND9_MAKE_RULES@
main.@O@: main.c
${LIBTOOL} ${CC} ${ALL_CFLAGS} -DVERSION=\"${VERSION}\" \
-DNS_LOCALSTATEDIR=\"${localstatedir}\" \
-DNS_SYSCONFDIR=\"${sysconfdir}\" -c ${srcdir}/main.c
named: ${OBJS} ${UOBJS} ${DEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ ${OBJS} ${UOBJS} ${LIBS}
lwresd: named
rm -f lwresd
@LN@ named lwresd
clean distclean::
rm -f ${TARGETS}
installdirs:
if [ ! -d ${DESTDIR}${sbindir} ]; then \
mkdir ${DESTDIR}${sbindir}; \
fi
install:: named lwresd installdirs
${LIBTOOL} ${INSTALL_PROGRAM} named ${DESTDIR}${sbindir}
(cd ${DESTDIR}${sbindir}; rm -f lwresd; @LN@ named lwresd)

File diff suppressed because it is too large Load Diff

View File

@@ -1,264 +0,0 @@
/*
* Copyright (C) 1999, 2000 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: client.h,v 1.37.2.1 2000/07/26 23:51:33 bwelling Exp $ */
#ifndef NAMED_CLIENT_H
#define NAMED_CLIENT_H 1
/*****
***** Module Info
*****/
/*
* Client
*
* This module defines two objects, ns_client_t and ns_clientmgr_t.
*
* An ns_client_t object handles incoming DNS requests from clients
* on a given network interface.
*
* Each ns_client_t object can handle only one TCP connection or UDP
* request at a time. Therefore, several ns_client_t objects are
* typically created to serve each network interface, e.g., one
* for handling TCP requests and a few (one per CPU) for handling
* UDP requests.
*
* Incoming requests are classified as queries, zone transfer
* requests, update requests, notify requests, etc, and handed off
* to the appropriate request handler. When the request has been
* fully handled (which can be much later), the ns_client_t must be
* notified of this by calling one of the following functions
* exactly once in the context of its task:
*
* ns_client_send() (sending a non-error response)
* ns_client_error() (sending an error response)
* ns_client_next() (sending no response)
*
* This will release any resources used by the request and
* and allow the ns_client_t to listen for the next request.
*
* A ns_clientmgr_t manages a number of ns_client_t objects.
* New ns_client_t objects are created by calling
* ns_clientmgr_createclients(). They are destroyed by
* destroying their manager.
*/
/***
*** Imports
***/
#include <isc/buffer.h>
#include <isc/stdtime.h>
#include <isc/quota.h>
#include <dns/name.h>
#include <dns/types.h>
#include <dns/tcpmsg.h>
#include <named/types.h>
#include <named/query.h>
/***
*** Types
***/
typedef ISC_LIST(ns_client_t) client_list_t;
struct ns_client {
unsigned int magic;
isc_mem_t * mctx;
ns_clientmgr_t * manager;
int state;
int newstate;
isc_boolean_t disconnect;
int naccepts;
int nreads;
int nsends;
int references;
unsigned int attributes;
isc_task_t * task;
dns_view_t * view;
dns_view_t * lockview;
dns_dispatch_t * dispatch;
dns_dispentry_t * dispentry;
dns_dispatchevent_t * dispevent;
isc_socket_t * tcplistener;
isc_socket_t * tcpsocket;
unsigned char * tcpbuf;
dns_tcpmsg_t tcpmsg;
isc_boolean_t tcpmsg_valid;
isc_timer_t * timer;
dns_message_t * message;
unsigned char * sendbuf;
dns_rdataset_t * opt;
isc_uint16_t udpsize;
void (*next)(ns_client_t *);
void (*shutdown)(void *arg, isc_result_t result);
void *shutdown_arg;
ns_query_t query;
isc_stdtime_t requesttime;
isc_stdtime_t now;
dns_name_t signername; /* [T]SIG key name */
dns_name_t * signer; /* NULL if not valid sig */
isc_boolean_t mortal; /* Die after handling request */
isc_quota_t *tcpquota;
isc_quota_t *recursionquota;
ns_interface_t *interface;
isc_sockaddr_t peeraddr;
isc_boolean_t peeraddr_valid;
struct in6_pktinfo pktinfo;
isc_event_t ctlevent;
ISC_LINK(ns_client_t) link;
/*
* The list 'link' is part of, or NULL if not on any list.
*/
client_list_t *list;
};
#define NS_CLIENT_MAGIC 0x4E534363U /* NSCc */
#define NS_CLIENT_VALID(c) ISC_MAGIC_VALID(c, NS_CLIENT_MAGIC)
#define NS_CLIENTATTR_TCP 0x01
#define NS_CLIENTATTR_RA 0x02 /* Client gets recusive service */
#define NS_CLIENTATTR_PKTINFO 0x04 /* pktinfo is valid */
#define NS_CLIENTATTR_MULTICAST 0x08 /* recv'd from multicast */
/***
*** Functions
***/
/*
* Note! These ns_client_ routines MUST be called ONLY from the client's
* task in order to ensure synchronization.
*/
void
ns_client_send(ns_client_t *client);
/*
* Finish processing the current client request and
* send client->message as a response.
*/
void
ns_client_error(ns_client_t *client, isc_result_t result);
/*
* Finish processing the current client request and return
* an error response to the client. The error response
* will have an RCODE determined by 'result'.
*/
void
ns_client_next(ns_client_t *client, isc_result_t result);
/*
* Finish processing the current client request,
* return no response to the client.
*/
isc_boolean_t
ns_client_shuttingdown(ns_client_t *client);
/*
* Return ISC_TRUE iff the client is currently shutting down.
*/
void
ns_client_attach(ns_client_t *source, ns_client_t **target);
/*
* Attach '*targetp' to 'source'.
*/
void
ns_client_detach(ns_client_t **clientp);
/*
* Detach '*clientp' from its client.
*/
isc_result_t
ns_client_replace(ns_client_t *client);
/*
* Try to replace the current client with a new one, so that the
* current one can go off and do some lengthy work without
* leaving the dispatch/socket without service.
*/
isc_result_t
ns_clientmgr_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
isc_timermgr_t *timermgr, ns_clientmgr_t **managerp);
/*
* Create a client manager.
*/
void
ns_clientmgr_destroy(ns_clientmgr_t **managerp);
/*
* Destroy a client manager and all ns_client_t objects
* managed by it.
*/
isc_result_t
ns_clientmgr_createclients(ns_clientmgr_t *manager, unsigned int n,
ns_interface_t *ifp, isc_boolean_t tcp);
/*
* Create up to 'n' clients listening on interface 'ifp'.
* If 'tcp' is ISC_TRUE, the clients will listen for TCP connections,
* otherwise for UDP requests.
*/
isc_sockaddr_t *
ns_client_getsockaddr(ns_client_t *client);
/*
* Get the socket address of the client whose request is
* currently being processed.
*/
isc_result_t
ns_client_checkacl(ns_client_t *client,
const char *opname, dns_acl_t *acl,
isc_boolean_t default_allow,
isc_boolean_t logfailure);
/*
* Convenience function for client request ACL checking.
*
* Check the current client request against 'acl'. If 'acl'
* is NULL, allow the request iff 'default_allow' is ISC_TRUE.
* Log the outcome of the check if deemed appropriate.
* Log messages will refer to the request as an 'opname' request.
*
* Notes:
* This is appropriate for checking allow-update,
* allow-query, allow-transfer, etc. It is not appropriate
* for checking the blackhole list because we treat positive
* matches as "allow" and negative matches as "deny"; in
* the case of the blackhole list this would be backwards.
*
* Requires:
* 'client' points to a valid client.
* 'opname' points to a null-terminated string.
* 'acl' points to a valid ACL, or is NULL.
*
* Returns:
* ISC_R_SUCCESS if the request should be allowed
* ISC_R_REFUSED if the request should be denied
* No other return values are possible.
*/
void
ns_client_log(ns_client_t *client, isc_logcategory_t *category,
isc_logmodule_t *module, int level,
const char *fmt, ...);
#endif /* NAMED_CLIENT_H */

View File

@@ -1,98 +0,0 @@
/*
* Copyright (C) 1999, 2000 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: globals.h,v 1.42 2000/06/22 21:49:39 tale Exp $ */
#ifndef NAMED_GLOBALS_H
#define NAMED_GLOBALS_H 1
#include <isc/rwlock.h>
#include <isc/log.h>
#include <isc/net.h>
#include <omapi/types.h>
#include <named/types.h>
#undef EXTERN
#undef INIT
#ifdef NS_MAIN
#define EXTERN
#define INIT(v) = (v)
#else
#define EXTERN extern
#define INIT(v)
#endif
EXTERN isc_mem_t * ns_g_mctx INIT(NULL);
EXTERN unsigned int ns_g_cpus INIT(0);
EXTERN isc_taskmgr_t * ns_g_taskmgr INIT(NULL);
EXTERN dns_dispatchmgr_t * ns_g_dispatchmgr INIT(NULL);
EXTERN isc_entropy_t * ns_g_entropy INIT(NULL);
/*
* XXXRTH We're going to want multiple timer managers eventually. One
* for really short timers, another for client timers, and one
* for zone timers.
*/
EXTERN isc_timermgr_t * ns_g_timermgr INIT(NULL);
EXTERN isc_socketmgr_t * ns_g_socketmgr INIT(NULL);
EXTERN omapi_object_t * ns_g_omapimgr INIT(NULL);
EXTERN const char * ns_g_version INIT(VERSION);
EXTERN in_port_t ns_g_port INIT(0);
EXTERN in_port_t lwresd_g_queryport INIT(0);
EXTERN ns_server_t * ns_g_server INIT(NULL);
EXTERN ns_lwresd_t * ns_g_lwresd INIT(NULL);
/*
* Logging.
*/
EXTERN isc_log_t * ns_g_lctx INIT(NULL);
EXTERN isc_logcategory_t * ns_g_categories INIT(NULL);
EXTERN isc_logmodule_t * ns_g_modules INIT(NULL);
EXTERN unsigned int ns_g_debuglevel INIT(0);
/*
* Current config information
*/
EXTERN const char * ns_g_conffile INIT(NS_SYSCONFDIR
"/named.conf");
EXTERN const char * lwresd_g_conffile INIT("/etc/resolv.conf");
/*
* Misc.
*/
EXTERN isc_boolean_t ns_g_coreok INIT(ISC_TRUE);
EXTERN const char * ns_g_chrootdir INIT(NULL);
EXTERN isc_boolean_t ns_g_foreground INIT(ISC_FALSE);
EXTERN isc_boolean_t ns_g_logstderr INIT(ISC_FALSE);
EXTERN const char * ns_g_defaultpidfile INIT(NS_LOCALSTATEDIR
"/run/named.pid");
EXTERN const char * lwresd_g_defaultpidfile INIT(NS_LOCALSTATEDIR
"/run/lwresd.pid");
EXTERN const char * ns_g_username INIT(NULL);
/*
* XXX Temporary.
*/
EXTERN const char * ns_g_cachefile INIT(NULL);
#undef EXTERN
#undef INIT
#endif /* NAMED_GLOBALS_H */

View File

@@ -1,155 +0,0 @@
/*
* Copyright (C) 1999, 2000 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: interfacemgr.h,v 1.17 2000/06/22 21:49:40 tale Exp $ */
#ifndef NAMED_INTERFACEMGR_H
#define NAMED_INTERFACEMGR_H 1
/*****
***** Module Info
*****/
/*
* Interface manager
*
* The interface manager monitors the operating system's list
* of network interfaces, creating and destroying listeners
* as needed.
*
* Reliability:
* No impact expected.
*
* Resources:
*
* Security:
* The server will only be able to bind to the DNS port on
* newly discovered interfaces if it is running as root.
*
* Standards:
* The API for scanning varies greatly among operating systems.
* This module attempts to hide the differences.
*/
/***
*** Imports
***/
#include <isc/magic.h>
#include <isc/mem.h>
#include <isc/socket.h>
#include <dns/result.h>
#include <named/listenlist.h>
#include <named/types.h>
/***
*** Types
***/
#define IFACE_MAGIC 0x493A2D29U /* I:-). */
#define NS_INTERFACE_VALID(t) ISC_MAGIC_VALID(t, IFACE_MAGIC)
struct ns_interface {
unsigned int magic; /* Magic number. */
ns_interfacemgr_t * mgr; /* Interface manager. */
isc_mutex_t lock;
int references; /* Locked */
unsigned int generation; /* Generation number. */
isc_sockaddr_t addr; /* Address and port. */
char name[32]; /* Null terminated. */
isc_socket_t * udpsocket; /* UDP socket. */
dns_dispatch_t * udpdispatch; /* UDP dispatcher. */
isc_socket_t * tcpsocket; /* TCP socket. */
isc_task_t * task;
int ntcptarget; /* Desired number of concurrent
TCP accepts */
int ntcpcurrent; /* Current ditto, locked */
ISC_LINK(ns_interface_t) link;
};
/***
*** Functions
***/
isc_result_t
ns_interfacemgr_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
isc_socketmgr_t *socketmgr,
dns_dispatchmgr_t *dispatchmgr,
ns_clientmgr_t *clientmgr, ns_interfacemgr_t **mgrp);
/*
* Create a new interface manager.
*
* Initially, the new manager will not listen on any interfaces.
* Call ns_interfacemgr_setlistenon() and/or ns_interfacemgr_setlistenon6()
* to set nonempty listen-on lists.
*/
void
ns_interfacemgr_attach(ns_interfacemgr_t *source, ns_interfacemgr_t **target);
void
ns_interfacemgr_detach(ns_interfacemgr_t **targetp);
void
ns_interfacemgr_shutdown(ns_interfacemgr_t *mgr);
void
ns_interfacemgr_scan(ns_interfacemgr_t *mgr, isc_boolean_t verbose);
/*
* Scan the operatings system's list of network interfaces
* and create listeners when new interfaces are discovered.
* Shut down the sockets for interfaces that go away.
*
* This should be called once on server startup and then
* periodically according to the 'interface-interval' option
* in named.conf.
*/
void
ns_interfacemgr_setlistenon4(ns_interfacemgr_t *mgr, ns_listenlist_t *value);
/*
* Set the IPv4 "listen-on" list of 'mgr' to 'value'.
* The previous IPv4 listen-on list is freed.
*/
void
ns_interfacemgr_setlistenon6(ns_interfacemgr_t *mgr, ns_listenlist_t *value);
/*
* Set the IPv6 "listen-on" list of 'mgr' to 'value'.
* The previous IPv6 listen-on list is freed.
*/
isc_result_t
ns_interfacemgr_findudpdispatcher(ns_interfacemgr_t *mgr,
isc_sockaddr_t *address,
dns_dispatch_t **dispatchp);
/*
* Find a UDP dispatcher matching 'address', if it exists.
*/
dns_aclenv_t *
ns_interfacemgr_getaclenv(ns_interfacemgr_t *mgr);
void
ns_interface_attach(ns_interface_t *source, ns_interface_t **target);
void
ns_interface_detach(ns_interface_t **targetp);
#endif /* NAMED_INTERFACEMGR_H */

View File

@@ -1,104 +0,0 @@
/*
* Copyright (C) 2000 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: listenlist.h,v 1.7 2000/06/23 01:34:38 gson Exp $ */
#ifndef NAMED_LISTENLIST_H
#define NAMED_LISTENLIST_H 1
/*****
***** Module Info
*****/
/*
* "Listen lists", as in the "listen-on" configuration statement.
*/
/***
*** Imports
***/
#include <isc/net.h>
#include <dns/types.h>
/***
*** Types
***/
typedef struct ns_listenelt ns_listenelt_t;
typedef struct ns_listenlist ns_listenlist_t;
struct ns_listenelt {
isc_mem_t * mctx;
in_port_t port;
dns_acl_t * acl;
ISC_LINK(ns_listenelt_t) link;
};
struct ns_listenlist {
isc_mem_t * mctx;
int refcount;
ISC_LIST(ns_listenelt_t) elts;
};
/***
*** Functions
***/
isc_result_t
ns_listenelt_create(isc_mem_t *mctx, in_port_t port,
dns_acl_t *acl, ns_listenelt_t **target);
/*
* Create a listen-on list element.
*/
void
ns_listenelt_destroy(ns_listenelt_t *elt);
/*
* Destroy a listen-on list element.
*/
isc_result_t
ns_listenlist_create(isc_mem_t *mctx, ns_listenlist_t **target);
/*
* Create a new, empty listen-on list.
*/
void
ns_listenlist_attach(ns_listenlist_t *source, ns_listenlist_t **target);
/*
* Attach '*target' to '*source'.
*/
void
ns_listenlist_detach(ns_listenlist_t **listp);
/*
* Detach 'listp'.
*/
isc_result_t
ns_listenlist_default(isc_mem_t *mctx, in_port_t port,
isc_boolean_t enabled, ns_listenlist_t **target);
/*
* Create a listen-on list with default contents, matching
* all addresses with port 'port' (if 'enabled' is ISC_TRUE),
* or no addresses (if 'enabled' is ISC_FALSE).
*/
#endif /* NAMED_LISTENLIST_H */

View File

@@ -1,87 +0,0 @@
/*
* Copyright (C) 1999, 2000 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: log.h,v 1.13 2000/06/22 21:49:43 tale Exp $ */
#ifndef NAMED_LOG_H
#define NAMED_LOG_H 1
#include <isc/log.h>
#include <isc/types.h>
#include <dns/log.h>
#include <named/globals.h> /* Required for ns_g_(categories|modules). */
/* Unused slot 0. */
#define NS_LOGCATEGORY_CLIENT (&ns_g_categories[1])
#define NS_LOGCATEGORY_NETWORK (&ns_g_categories[2])
#define NS_LOGCATEGORY_UPDATE (&ns_g_categories[3])
/*
* Backwards compatibility.
*/
#define NS_LOGCATEGORY_GENERAL ISC_LOGCATEGORY_GENERAL
#define NS_LOGMODULE_MAIN (&ns_g_modules[0])
#define NS_LOGMODULE_CLIENT (&ns_g_modules[1])
#define NS_LOGMODULE_SERVER (&ns_g_modules[2])
#define NS_LOGMODULE_QUERY (&ns_g_modules[3])
#define NS_LOGMODULE_INTERFACEMGR (&ns_g_modules[4])
#define NS_LOGMODULE_UPDATE (&ns_g_modules[5])
#define NS_LOGMODULE_XFER_IN (&ns_g_modules[6])
#define NS_LOGMODULE_XFER_OUT (&ns_g_modules[7])
#define NS_LOGMODULE_NOTIFY (&ns_g_modules[8])
#define NS_LOGMODULE_OMAPI (&ns_g_modules[9])
#define NS_LOGMODULE_LWRESD (&ns_g_modules[10])
isc_result_t
ns_log_init(isc_boolean_t safe);
/*
* Initialize the logging system and set up an initial default
* logging default configuration that will be used until the
* config file has been read.
*
* If 'safe' is true, use a default configuration that refrains
* from opening files. This is to avoid creating log files
* as root.
*/
isc_result_t
ns_log_setdefaultchannels(isc_logconfig_t *lcfg);
/*
* Set up logging channels according to the named defaults, which
* may differ from the logging library defaults. Currently,
* this just means setting up default_debug.
*/
isc_result_t
ns_log_setsafechannels(isc_logconfig_t *lcfg);
/*
* Like ns_log_setdefaultchannels(), but omits any logging to files.
*/
isc_result_t
ns_log_setdefaultcategory(isc_logconfig_t *lcfg);
/*
* Set up "category default" to go to the right places.
*/
void
ns_log_shutdown(void);
#endif /* NAMED_LOG_H */

View File

@@ -1,34 +0,0 @@
/*
* Copyright (C) 1999, 2000 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: logconf.h,v 1.6 2000/06/22 21:49:44 tale Exp $ */
#ifndef NAMED_LOGCONF_H
#define NAMED_LOGCONF_H 1
#include <isc/log.h>
#include <dns/conflog.h>
isc_result_t
ns_log_configure(isc_logconfig_t *logconf, dns_c_logginglist_t *clog);
/*
* Set up the logging configuration in '*logconf' according to
* the named.conf data in 'clog'.
*/
#endif /* NAMED_LOGCONF_H */

View File

@@ -1,206 +0,0 @@
/*
* Copyright (C) 2000 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: lwdclient.h,v 1.2.2.1 2000/06/26 21:47:36 gson Exp $ */
#ifndef NAMED_LWDCLIENT_H
#define NAMED_LWDCLIENT_H 1
#include <isc/event.h>
#include <isc/eventclass.h>
#include <isc/netaddr.h>
#include <isc/sockaddr.h>
#include <isc/types.h>
#include <dns/fixedname.h>
#include <dns/types.h>
#include <lwres/lwres.h>
#define LWRD_EVENTCLASS ISC_EVENTCLASS(4242)
#define LWRD_SHUTDOWN (LWRD_EVENTCLASS + 0x0001)
struct ns_lwdclient {
isc_sockaddr_t address; /* where to reply */
ns_lwdclientmgr_t *clientmgr; /* our parent */
ISC_LINK(ns_lwdclient_t) link;
unsigned int state;
void *arg; /* packet processing state */
/*
* Received data info.
*/
unsigned char buffer[LWRES_RECVLENGTH]; /* receive buffer */
isc_uint32_t recvlength; /* length recv'd */
lwres_lwpacket_t pkt;
/*
* Send data state. If sendbuf != buffer (that is, the send buffer
* isn't our receive buffer) it will be freed to the lwres_context_t.
*/
unsigned char *sendbuf;
isc_uint32_t sendlength;
isc_buffer_t recv_buffer;
/*
* gabn (get address by name) state info.
*/
dns_adbfind_t *find;
dns_adbfind_t *v4find;
dns_adbfind_t *v6find;
unsigned int find_wanted; /* Addresses we want */
dns_fixedname_t target_name;
lwres_gabnresponse_t gabn;
/*
* gnba (get name by address) state info.
*/
lwres_gnbaresponse_t gnba;
dns_byaddr_t *byaddr;
unsigned int options;
isc_netaddr_t na;
dns_adbaddrinfo_t *addrinfo;
/*
* Alias and address info. This is copied up to the gabn/gnba
* structures eventually.
*
* XXXMLG We can keep all of this in a client since we only service
* three packet types right now. If we started handling more,
* we'd need to use "arg" above and allocate/destroy things.
*/
char *aliases[LWRES_MAX_ALIASES];
isc_uint16_t aliaslen[LWRES_MAX_ALIASES];
lwres_addr_t addrs[LWRES_MAX_ADDRS];
};
/*
* Client states.
*
* _IDLE The client is not doing anything at all.
*
* _RECV The client is waiting for data after issuing a socket recv().
*
* _RECVDONE Data has been received, and is being processed.
*
* _FINDWAIT An adb (or other) request was made that cannot be satisfied
* immediately. An event will wake the client up.
*
* _SEND All data for a response has completed, and a reply was
* sent via a socket send() call.
*
* Badly formatted state table:
*
* IDLE -> RECV when client has a recv() queued.
*
* RECV -> RECVDONE when recvdone event received.
*
* RECVDONE -> SEND if the data for a reply is at hand.
* RECVDONE -> FINDWAIT if more searching is needed, and events will
* eventually wake us up again.
*
* FINDWAIT -> SEND when enough data was received to reply.
*
* SEND -> IDLE when a senddone event was received.
*
* At any time -> IDLE on error. Sometimes this will be -> SEND
* instead, if enough data is on hand to reply with a meaningful
* error.
*
* Packets which are badly formatted may or may not get error returns.
*/
#define NS_LWDCLIENT_STATEIDLE 1
#define NS_LWDCLIENT_STATERECV 2
#define NS_LWDCLIENT_STATERECVDONE 3
#define NS_LWDCLIENT_STATEFINDWAIT 4
#define NS_LWDCLIENT_STATESEND 5
#define NS_LWDCLIENT_STATESENDDONE 6
#define NS_LWDCLIENT_ISIDLE(c) \
((c)->state == NS_LWDCLIENT_STATEIDLE)
#define NS_LWDCLIENT_ISRECV(c) \
((c)->state == NS_LWDCLIENT_STATERECV)
#define NS_LWDCLIENT_ISRECVDONE(c) \
((c)->state == NS_LWDCLIENT_STATERECVDONE)
#define NS_LWDCLIENT_ISFINDWAIT(c) \
((c)->state == NS_LWDCLIENT_STATEFINDWAIT)
#define NS_LWDCLIENT_ISSEND(c) \
((c)->state == NS_LWDCLIENT_STATESEND)
/*
* Overall magic test that means we're not idle.
*/
#define NS_LWDCLIENT_ISRUNNING(c) (!NS_LWDCLIENT_ISIDLE(c))
#define NS_LWDCLIENT_SETIDLE(c) \
((c)->state = NS_LWDCLIENT_STATEIDLE)
#define NS_LWDCLIENT_SETRECV(c) \
((c)->state = NS_LWDCLIENT_STATERECV)
#define NS_LWDCLIENT_SETRECVDONE(c) \
((c)->state = NS_LWDCLIENT_STATERECVDONE)
#define NS_LWDCLIENT_SETFINDWAIT(c) \
((c)->state = NS_LWDCLIENT_STATEFINDWAIT)
#define NS_LWDCLIENT_SETSEND(c) \
((c)->state = NS_LWDCLIENT_STATESEND)
#define NS_LWDCLIENT_SETSENDDONE(c) \
((c)->state = NS_LWDCLIENT_STATESENDDONE)
struct ns_lwdclientmgr {
isc_mem_t *mctx;
isc_task_t *task; /* owning task */
isc_socket_t *sock; /* socket to use */
dns_view_t *view;
unsigned int flags;
lwres_context_t *lwctx; /* lightweight proto context */
ISC_LIST(ns_lwdclient_t) idle; /* idle client slots */
ISC_LIST(ns_lwdclient_t) running; /* running clients */
};
#define NS_LWDCLIENTMGR_FLAGRECVPENDING 0x00000001
#define NS_LWDCLIENTMGR_FLAGSHUTTINGDOWN 0x00000002
void
ns_lwdclient_initialize(ns_lwdclient_t *, ns_lwdclientmgr_t *);
isc_result_t
ns_lwdclient_startrecv(ns_lwdclientmgr_t *);
void
ns_lwdclient_stateidle(ns_lwdclient_t *);
void
ns_lwdclient_recv(isc_task_t *, isc_event_t *);
void
ns_lwdclient_shutdown(isc_task_t *, isc_event_t *);
void
ns_lwdclient_send(isc_task_t *, isc_event_t *);
/*
* Processing functions of various types.
*/
void ns_lwdclient_processgabn(ns_lwdclient_t *, lwres_buffer_t *);
void ns_lwdclient_processgnba(ns_lwdclient_t *, lwres_buffer_t *);
void ns_lwdclient_processnoop(ns_lwdclient_t *, lwres_buffer_t *);
void ns_lwdclient_errorpktsend(ns_lwdclient_t *, isc_uint32_t);
void ns_lwdclient_log(int level, const char *format, ...);
#endif /* NAMED_LWDCLIENT_H */

View File

@@ -1,45 +0,0 @@
/*
* Copyright (C) 2000 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: lwresd.h,v 1.2.2.1 2000/06/28 00:19:06 gson Exp $ */
#ifndef NAMED_LWRESD_H
#define NAMED_LWRESD_H 1
#include <isc/types.h>
#include <isc/sockaddr.h>
#include <dns/types.h>
struct ns_lwresd {
isc_uint32_t magic;
ns_lwdclientmgr_t *cmgr;
isc_socket_t *sock;
unsigned int ntasks;
dns_view_t *view;
isc_mem_t *mctx;
isc_task_t *task;
dns_dispatchmgr_t *dispmgr;
};
void
ns_lwresd_create(isc_mem_t *mctx, dns_view_t *view, ns_lwresd_t **lwresdp);
void
ns_lwresd_destroy(ns_lwresd_t **lwresdp);
#endif /* NAMED_LWRESD_H */

View File

@@ -1,26 +0,0 @@
/*
* Copyright (C) 1999, 2000 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: main.h,v 1.4 2000/06/22 21:49:47 tale Exp $ */
#ifndef NAMED_MAIN_H
#define NAMED_MAIN_H 1
void
ns_main_earlyfatal(const char *format, ...);
#endif /* NAMED_MAIN_H */

View File

@@ -1,54 +0,0 @@
/*
* Copyright (C) 1999, 2000 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: notify.h,v 1.6 2000/06/22 21:49:48 tale Exp $ */
#ifndef NAMED_NOTIFY_H
#define NAMED_NOTIFY_H 1
#include <named/types.h>
#include <named/client.h>
/***
*** Module Info
***/
/*
* RFC 1996
* A Mechanism for Prompt Notification of Zone Changes (DNS NOTIFY)
*/
/***
*** Functions.
***/
void
ns_notify_start(ns_client_t *client);
/*
* Examines the incoming message to determine apporiate zone.
* Returns FORMERR if there is not exactly one question.
* Returns REFUSED if we do not serve the listed zone.
* Pass the message to the zone module for processing
* and returns the return status.
*
* Requires
* client to be valid.
*/
#endif /* NAMED_NOTIFY_H */

View File

@@ -1,49 +0,0 @@
/*
* Copyright (C) 2000 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: omapi.h,v 1.7.2.1 2000/07/11 17:23:07 gson Exp $ */
#ifndef NAMED_OMAPI_H
#define NAMED_OMAPI_H 1
#include <dns/aclconf.h>
#include <dns/confctx.h>
#include <omapi/omapi.h>
#define NS_OMAPI_PORT 953
/*
* This string is the registration name of objects of type control_object_t.
*/
#define NS_OMAPI_CONTROL "control"
#define NS_OMAPI_COMMAND_RELOAD "reload"
#define NS_OMAPI_COMMAND_RELOADCONFIG "reload-config"
#define NS_OMAPI_COMMAND_RELOADZONES "reload-zones"
isc_result_t
ns_omapi_init(void);
isc_result_t
ns_omapi_configure(isc_mem_t *mctx, dns_c_ctx_t *cctx,
dns_aclconfctx_t *aclconfctx);
void
ns_omapi_shutdown(isc_boolean_t exiting);
#endif /* NAMED_OMAPI_H */

View File

@@ -1,72 +0,0 @@
/*
* Copyright (C) 1999, 2000 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: query.h,v 1.17.2.1 2000/07/28 17:56:09 gson Exp $ */
#ifndef NAMED_QUERY_H
#define NAMED_QUERY_H 1
#include <isc/types.h>
#include <isc/buffer.h>
#include <dns/types.h>
#include <dns/a6.h>
#include <named/types.h>
typedef struct ns_dbversion {
dns_db_t *db;
dns_dbversion_t *version;
isc_boolean_t queryok;
ISC_LINK(struct ns_dbversion) link;
} ns_dbversion_t;
struct ns_query {
unsigned int attributes;
unsigned int restarts;
dns_name_t * qname;
dns_name_t * origqname;
dns_rdataset_t * qrdataset;
unsigned int dboptions;
unsigned int fetchoptions;
dns_db_t * gluedb;
dns_fetch_t * fetch;
dns_a6context_t a6ctx;
isc_bufferlist_t namebufs;
ISC_LIST(ns_dbversion_t) activeversions;
ISC_LIST(ns_dbversion_t) freeversions;
};
#define NS_QUERYATTR_RECURSIONOK 0x01
#define NS_QUERYATTR_CACHEOK 0x02
#define NS_QUERYATTR_PARTIALANSWER 0x04
#define NS_QUERYATTR_NAMEBUFUSED 0x08
#define NS_QUERYATTR_RECURSING 0x10
#define NS_QUERYATTR_CACHEGLUEOK 0x20
#define NS_QUERYATTR_QUERYOKVALID 0x40
#define NS_QUERYATTR_QUERYOK 0x80
isc_result_t
ns_query_init(ns_client_t *client);
void
ns_query_free(ns_client_t *client);
void
ns_query_start(ns_client_t *client);
#endif /* NAMED_QUERY_H */

View File

@@ -1,96 +0,0 @@
/*
* Copyright (C) 1999, 2000 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: server.h,v 1.32.2.1 2000/07/26 23:51:35 bwelling Exp $ */
#ifndef NAMED_SERVER_H
#define NAMED_SERVER_H 1
#include <isc/log.h>
#include <isc/sockaddr.h>
#include <isc/types.h>
#include <isc/quota.h>
#include <dns/types.h>
#include <dns/acl.h>
#define NS_EVENTCLASS ISC_EVENTCLASS(0x4E43)
#define NS_EVENT_RELOAD (NS_EVENTCLASS + 0)
#define NS_EVENT_CLIENTCONTROL (NS_EVENTCLASS + 1)
/*
* Name server state. Better here than in lots of separate global variables.
*/
struct ns_server {
isc_uint32_t magic;
isc_mem_t * mctx;
isc_task_t * task;
/* Common rwlock for the server's configurable data. */
isc_rwlock_t conflock;
/* Configurable data. */
isc_quota_t xfroutquota;
isc_quota_t tcpquota;
isc_quota_t recursionquota;
/* Not really configurable, but covered by conflock. */
dns_aclenv_t aclenv;
/* Server data structures. */
dns_zonemgr_t * zonemgr;
ns_clientmgr_t * clientmgr;
dns_viewlist_t viewlist;
ns_interfacemgr_t * interfacemgr;
dns_db_t * in_roothints;
dns_tkeyctx_t * tkeyctx;
isc_timer_t * interface_timer;
isc_mutex_t reload_event_lock;
isc_event_t * reload_event;
};
#define NS_SERVER_MAGIC 0x53564552 /* SVER */
#define NS_SERVER_VALID(s) ((s) != NULL && \
(s)->magic == NS_SERVER_MAGIC)
void
ns_server_create(isc_mem_t *mctx, ns_server_t **serverp);
/*
* Create a server object with default settings.
* This function either succeeds or causes the program to exit
* with a fatal error.
*/
void
ns_server_destroy(ns_server_t **serverp);
/*
* Destroy a server object, freeing its memory.
*/
void
ns_server_reloadwanted(ns_server_t *server);
/*
* Inform a server that a reload is wanted. This function
* may be called asynchronously, from outside the server's task.
* If a reload is already scheduled or in progress, the call
* is ignored.
*/
#endif /* NAMED_SERVER_H */

View File

@@ -1,35 +0,0 @@
/*
* Copyright (C) 1999, 2000 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: types.h,v 1.13 2000/06/22 21:49:52 tale Exp $ */
#ifndef NAMED_TYPES_H
#define NAMED_TYPES_H 1
#include <dns/types.h>
typedef struct ns_client ns_client_t;
typedef struct ns_clientmgr ns_clientmgr_t;
typedef struct ns_query ns_query_t;
typedef struct ns_server ns_server_t;
typedef struct ns_interface ns_interface_t;
typedef struct ns_interfacemgr ns_interfacemgr_t;
typedef struct ns_lwresd ns_lwresd_t;
typedef struct ns_lwdclient ns_lwdclient_t;
typedef struct ns_lwdclientmgr ns_lwdclientmgr_t;
#endif /* NAMED_TYPES_H */

View File

@@ -1,49 +0,0 @@
/*
* Copyright (C) 1999, 2000 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: update.h,v 1.4 2000/06/22 21:49:54 tale Exp $ */
#ifndef NAMED_UPDATE_H
#define NAMED_UPDATE_H 1
/*****
***** Module Info
*****/
/*
* RFC2136 Dynamic Update
*/
/***
*** Imports
***/
#include <dns/types.h>
#include <dns/result.h>
/***
*** Types.
***/
/***
*** Functions
***/
void
ns_update_start(ns_client_t *client);
#endif /* NAMED_UPDATE_H */

View File

@@ -1,38 +0,0 @@
/*
* Copyright (C) 1999, 2000 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: xfrout.h,v 1.4 2000/06/22 21:49:55 tale Exp $ */
#ifndef NAMED_XFROUT_H
#define NAMED_XFROUT_H 1
/*****
***** Module Info
*****/
/*
* Outgoing zone transfers (AXFR + IXFR).
*/
/***
*** Functions
***/
void
ns_xfr_start(ns_client_t *client, dns_rdatatype_t xfrtype);
#endif /* NAMED_XFROUT_H */

View File

@@ -1,729 +0,0 @@
/*
* Copyright (C) 1999, 2000 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: interfacemgr.c,v 1.44.2.2 2000/07/10 23:32:02 gson Exp $ */
#include <config.h>
#include <isc/interfaceiter.h>
#include <isc/string.h>
#include <isc/task.h>
#include <isc/util.h>
#include <dns/acl.h>
#include <dns/dispatch.h>
#include <named/client.h>
#include <named/log.h>
#include <named/interfacemgr.h>
#define IFMGR_MAGIC 0x49464D47U /* IFMG. */
#define NS_INTERFACEMGR_VALID(t) ISC_MAGIC_VALID(t, IFMGR_MAGIC)
#define IFMGR_COMMON_LOGARGS \
ns_g_lctx, NS_LOGCATEGORY_NETWORK, NS_LOGMODULE_INTERFACEMGR
struct ns_interfacemgr {
unsigned int magic; /* Magic number. */
int references;
isc_mutex_t lock;
isc_mem_t * mctx; /* Memory context. */
isc_taskmgr_t * taskmgr; /* Task manager. */
isc_socketmgr_t * socketmgr; /* Socket manager. */
dns_dispatchmgr_t * dispatchmgr;
ns_clientmgr_t * clientmgr; /* Client manager. */
unsigned int generation; /* Current generation no. */
ns_listenlist_t * listenon4;
ns_listenlist_t * listenon6;
dns_aclenv_t aclenv; /* Localhost/localnets ACLs */
ISC_LIST(ns_interface_t) interfaces; /* List of interfaces. */
};
static void
purge_old_interfaces(ns_interfacemgr_t *mgr);
isc_result_t
ns_interfacemgr_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
isc_socketmgr_t *socketmgr,
dns_dispatchmgr_t *dispatchmgr,
ns_clientmgr_t *clientmgr, ns_interfacemgr_t **mgrp)
{
isc_result_t result;
ns_interfacemgr_t *mgr;
REQUIRE(mctx != NULL);
REQUIRE(mgrp != NULL);
REQUIRE(*mgrp == NULL);
mgr = isc_mem_get(mctx, sizeof(*mgr));
if (mgr == NULL)
return (ISC_R_NOMEMORY);
result = isc_mutex_init(&mgr->lock);
if (result != ISC_R_SUCCESS)
goto cleanup_mem;
mgr->mctx = mctx;
mgr->taskmgr = taskmgr;
mgr->socketmgr = socketmgr;
mgr->dispatchmgr = dispatchmgr;
mgr->clientmgr = clientmgr;
mgr->generation = 1;
mgr->listenon4 = NULL;
mgr->listenon6 = NULL;
ISC_LIST_INIT(mgr->interfaces);
/*
* The listen-on lists are initially empty.
*/
result = ns_listenlist_create(mctx, &mgr->listenon4);
if (result != ISC_R_SUCCESS)
goto cleanup_mem;
ns_listenlist_attach(mgr->listenon4, &mgr->listenon6);
result = dns_aclenv_init(mctx, &mgr->aclenv);
if (result != ISC_R_SUCCESS)
goto cleanup_listenon;
mgr->references = 1;
mgr->magic = IFMGR_MAGIC;
*mgrp = mgr;
return (ISC_R_SUCCESS);
cleanup_listenon:
ns_listenlist_detach(&mgr->listenon4);
ns_listenlist_detach(&mgr->listenon6);
cleanup_mem:
isc_mem_put(mctx, mgr, sizeof(*mgr));
return (result);
}
static void
ns_interfacemgr_destroy(ns_interfacemgr_t *mgr) {
REQUIRE(NS_INTERFACEMGR_VALID(mgr));
dns_aclenv_destroy(&mgr->aclenv);
ns_listenlist_detach(&mgr->listenon4);
ns_listenlist_detach(&mgr->listenon6);
isc_mutex_destroy(&mgr->lock);
mgr->magic = 0;
isc_mem_put(mgr->mctx, mgr, sizeof *mgr);
}
dns_aclenv_t *
ns_interfacemgr_getaclenv(ns_interfacemgr_t *mgr) {
return (&mgr->aclenv);
}
void
ns_interfacemgr_attach(ns_interfacemgr_t *source, ns_interfacemgr_t **target) {
REQUIRE(NS_INTERFACEMGR_VALID(source));
LOCK(&source->lock);
INSIST(source->references > 0);
source->references++;
UNLOCK(&source->lock);
*target = source;
}
void
ns_interfacemgr_detach(ns_interfacemgr_t **targetp) {
isc_result_t need_destroy = ISC_FALSE;
ns_interfacemgr_t *target = *targetp;
REQUIRE(target != NULL);
REQUIRE(NS_INTERFACEMGR_VALID(target));
LOCK(&target->lock);
REQUIRE(target->references > 0);
target->references--;
if (target->references == 0)
need_destroy = ISC_TRUE;
UNLOCK(&target->lock);
if (need_destroy)
ns_interfacemgr_destroy(target);
*targetp = NULL;
}
void
ns_interfacemgr_shutdown(ns_interfacemgr_t *mgr) {
REQUIRE(NS_INTERFACEMGR_VALID(mgr));
/*
* Shut down and detach all interfaces.
* By incrementing the generation count, we make purge_old_interfaces()
* consider all interfaces "old".
*/
mgr->generation++;
purge_old_interfaces(mgr);
}
static isc_result_t
ns_interface_create(ns_interfacemgr_t *mgr, isc_sockaddr_t *addr,
const char *name, ns_interface_t **ifpret)
{
ns_interface_t *ifp;
isc_result_t result;
REQUIRE(NS_INTERFACEMGR_VALID(mgr));
ifp = isc_mem_get(mgr->mctx, sizeof(*ifp));
if (ifp == NULL)
return (ISC_R_NOMEMORY);
ifp->mgr = NULL;
ifp->generation = mgr->generation;
ifp->addr = *addr;
strncpy(ifp->name, name, sizeof(ifp->name));
ifp->name[sizeof(ifp->name)-1] = '\0';
result = isc_mutex_init(&ifp->lock);
if (result != ISC_R_SUCCESS)
goto lock_create_failure;
/*
* Create a task.
*/
ifp->task = NULL;
result = isc_task_create(mgr->taskmgr, 0, &ifp->task);
if (result != ISC_R_SUCCESS) {
isc_log_write(IFMGR_COMMON_LOGARGS, ISC_LOG_ERROR,
"isc_task_create() failed: %s",
isc_result_totext(result));
goto task_create_failure;
}
isc_task_setname(ifp->task, "ifp", ifp);
ifp->udpdispatch = NULL;
ifp->tcpsocket = NULL;
/*
* Create a single TCP client object. It will replace itself
* with a new one as soon as it gets a connection, so the actual
* connections will be handled in parallel even though there is
* only one client initially.
*/
ifp->ntcptarget = 1;
ifp->ntcpcurrent = 0;
ns_interfacemgr_attach(mgr, &ifp->mgr);
ISC_LIST_APPEND(mgr->interfaces, ifp, link);
ifp->references = 1;
ifp->magic = IFACE_MAGIC;
*ifpret = ifp;
return (ISC_R_SUCCESS);
task_create_failure:
isc_mutex_destroy(&ifp->lock);
lock_create_failure:
ifp->magic = 0;
isc_mem_put(mgr->mctx, ifp, sizeof(*ifp));
return (ISC_R_UNEXPECTED);
}
static isc_result_t
ns_interface_listenudp(ns_interface_t *ifp) {
isc_result_t result;
unsigned int attrs;
unsigned int attrmask;
attrs = 0;
attrs |= DNS_DISPATCHATTR_UDP;
if (isc_sockaddr_pf(&ifp->addr) == AF_INET)
attrs |= DNS_DISPATCHATTR_IPV4;
else
attrs |= DNS_DISPATCHATTR_IPV6;
attrmask = 0;
attrmask |= DNS_DISPATCHATTR_UDP | DNS_DISPATCHATTR_TCP;
attrmask |= DNS_DISPATCHATTR_IPV4 | DNS_DISPATCHATTR_IPV6;
result = dns_dispatch_getudp(ifp->mgr->dispatchmgr, ns_g_socketmgr,
ns_g_taskmgr, &ifp->addr,
4096, 1000, 32768, 8219, 8237,
attrs, attrmask, &ifp->udpdispatch);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"UDP dns_dispatch_create(): %s",
isc_result_totext(result));
goto udp_dispatch_failure;
}
result = ns_clientmgr_createclients(ifp->mgr->clientmgr, ns_g_cpus,
ifp, ISC_FALSE);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"UDP ns_clientmgr_createclients(): %s",
isc_result_totext(result));
goto addtodispatch_failure;
}
return (ISC_R_SUCCESS);
addtodispatch_failure:
dns_dispatch_detach(&ifp->udpdispatch);
udp_dispatch_failure:
return (result);
}
static isc_result_t
ns_interface_accepttcp(ns_interface_t *ifp) {
isc_result_t result;
/*
* Open a TCP socket.
*/
result = isc_socket_create(ifp->mgr->socketmgr,
isc_sockaddr_pf(&ifp->addr),
isc_sockettype_tcp,
&ifp->tcpsocket);
if (result != ISC_R_SUCCESS) {
isc_log_write(IFMGR_COMMON_LOGARGS, ISC_LOG_ERROR,
"creating TCP socket: %s",
isc_result_totext(result));
goto tcp_socket_failure;
}
result = isc_socket_bind(ifp->tcpsocket, &ifp->addr);
if (result != ISC_R_SUCCESS) {
isc_log_write(IFMGR_COMMON_LOGARGS, ISC_LOG_ERROR,
"binding TCP socket: %s",
isc_result_totext(result));
goto tcp_bind_failure;
}
result = isc_socket_listen(ifp->tcpsocket, 0);
if (result != ISC_R_SUCCESS) {
isc_log_write(IFMGR_COMMON_LOGARGS, ISC_LOG_ERROR,
"listening on TCP socket: %s",
isc_result_totext(result));
goto tcp_listen_failure;
}
result = ns_clientmgr_createclients(ifp->mgr->clientmgr,
ifp->ntcptarget, ifp,
ISC_TRUE);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"TCP ns_clientmgr_createclients(): %s",
isc_result_totext(result));
goto accepttcp_failure;
}
return (ISC_R_SUCCESS);
accepttcp_failure:
tcp_listen_failure:
tcp_bind_failure:
isc_socket_detach(&ifp->tcpsocket);
tcp_socket_failure:
return (ISC_R_SUCCESS);
}
static isc_result_t
ns_interface_setup(ns_interfacemgr_t *mgr, isc_sockaddr_t *addr,
const char *name, ns_interface_t **ifpret)
{
isc_result_t result;
ns_interface_t *ifp = NULL;
REQUIRE(ifpret != NULL && *ifpret == NULL);
result = ns_interface_create(mgr, addr, name, &ifp);
if (result != ISC_R_SUCCESS)
return (result);
result = ns_interface_listenudp(ifp);
if (result != ISC_R_SUCCESS)
goto cleanup_interface;
result = ns_interface_accepttcp(ifp);
if (result != ISC_R_SUCCESS) {
/*
* XXXRTH We don't currently have a way to easily stop dispatch
* service, so we return currently return ISC_R_SUCCESS (the
* UDP stuff will work even if TCP creation failed). This will
* be fixed later.
*/
result = ISC_R_SUCCESS;
}
*ifpret = ifp;
return (ISC_R_SUCCESS);
cleanup_interface:
ISC_LIST_UNLINK(ifp->mgr->interfaces, ifp, link);
ns_interface_detach(&ifp);
return (result);
}
static void
ns_interface_destroy(ns_interface_t *ifp) {
isc_mem_t *mctx = ifp->mgr->mctx;
REQUIRE(NS_INTERFACE_VALID(ifp));
if (ifp->udpdispatch != NULL)
dns_dispatch_detach(&ifp->udpdispatch);
if (ifp->tcpsocket != NULL) {
isc_socket_cancel(ifp->tcpsocket, NULL, ISC_SOCKCANCEL_ALL);
isc_socket_detach(&ifp->tcpsocket);
}
isc_task_detach(&ifp->task);
isc_mutex_destroy(&ifp->lock);
ns_interfacemgr_detach(&ifp->mgr);
ifp->magic = 0;
isc_mem_put(mctx, ifp, sizeof(*ifp));
}
void
ns_interface_attach(ns_interface_t *source, ns_interface_t **target) {
REQUIRE(NS_INTERFACE_VALID(source));
LOCK(&source->lock);
INSIST(source->references > 0);
source->references++;
UNLOCK(&source->lock);
*target = source;
}
void
ns_interface_detach(ns_interface_t **targetp) {
isc_result_t need_destroy = ISC_FALSE;
ns_interface_t *target = *targetp;
REQUIRE(target != NULL);
REQUIRE(NS_INTERFACE_VALID(target));
LOCK(&target->lock);
REQUIRE(target->references > 0);
target->references--;
if (target->references == 0)
need_destroy = ISC_TRUE;
UNLOCK(&target->lock);
if (need_destroy)
ns_interface_destroy(target);
*targetp = NULL;
}
/*
* Search the interface list for an interface whose address and port
* both match those of 'addr'. Return a pointer to it, or NULL if not found.
*/
static ns_interface_t *
find_matching_interface(ns_interfacemgr_t *mgr, isc_sockaddr_t *addr) {
ns_interface_t *ifp;
for (ifp = ISC_LIST_HEAD(mgr->interfaces); ifp != NULL;
ifp = ISC_LIST_NEXT(ifp, link)) {
if (isc_sockaddr_equal(&ifp->addr, addr))
break;
}
return (ifp);
}
/*
* Remove any interfaces whose generation number is not the current one.
*/
static void
purge_old_interfaces(ns_interfacemgr_t *mgr) {
ns_interface_t *ifp, *next;
for (ifp = ISC_LIST_HEAD(mgr->interfaces); ifp != NULL; ifp = next) {
INSIST(NS_INTERFACE_VALID(ifp));
next = ISC_LIST_NEXT(ifp, link);
if (ifp->generation != mgr->generation) {
char sabuf[256];
ISC_LIST_UNLINK(ifp->mgr->interfaces, ifp, link);
isc_sockaddr_format(&ifp->addr, sabuf, sizeof(sabuf));
isc_log_write(IFMGR_COMMON_LOGARGS,
ISC_LOG_INFO,
"no longer listening on %s", sabuf);
ns_interface_detach(&ifp);
}
}
}
static isc_result_t
clearacl(isc_mem_t *mctx, dns_acl_t **aclp) {
dns_acl_t *newacl = NULL;
isc_result_t result;
result = dns_acl_create(mctx, 10, &newacl);
if (result != ISC_R_SUCCESS)
return (result);
dns_acl_detach(aclp);
dns_acl_attach(newacl, aclp);
dns_acl_detach(&newacl);
return (ISC_R_SUCCESS);
}
static void
do_ipv4(ns_interfacemgr_t *mgr) {
isc_interfaceiter_t *iter = NULL;
isc_result_t result;
result = isc_interfaceiter_create(mgr->mctx, &iter);
if (result != ISC_R_SUCCESS)
return;
result = clearacl(mgr->mctx, &mgr->aclenv.localhost);
if (result != ISC_R_SUCCESS)
goto cleanup_iter;
result = clearacl(mgr->mctx, &mgr->aclenv.localnets);
if (result != ISC_R_SUCCESS)
goto cleanup_iter;
for (result = isc_interfaceiter_first(iter);
result == ISC_R_SUCCESS;
result = isc_interfaceiter_next(iter))
{
ns_interface_t *ifp;
isc_interface_t interface;
ns_listenelt_t *le;
dns_aclelement_t elt;
unsigned int prefixlen;
result = isc_interfaceiter_current(iter, &interface);
if (result != ISC_R_SUCCESS)
break;
if (interface.address.family != AF_INET)
continue;
if ((interface.flags & INTERFACE_F_UP) == 0)
continue;
result = isc_netaddr_masktoprefixlen(&interface.netmask,
&prefixlen);
if (result != ISC_R_SUCCESS)
goto ignore_interface;
elt.type = dns_aclelementtype_ipprefix;
elt.negative = ISC_FALSE;
elt.u.ip_prefix.address = interface.address;
elt.u.ip_prefix.prefixlen = prefixlen;
/* XXX suppress duplicates */
result = dns_acl_appendelement(mgr->aclenv.localnets, &elt);
if (result != ISC_R_SUCCESS)
goto ignore_interface;
elt.u.ip_prefix.prefixlen = 32;
result = dns_acl_appendelement(mgr->aclenv.localhost, &elt);
if (result != ISC_R_SUCCESS)
goto ignore_interface;
for (le = ISC_LIST_HEAD(mgr->listenon4->elts);
le != NULL;
le = ISC_LIST_NEXT(le, link))
{
int match;
isc_netaddr_t listen_netaddr;
isc_sockaddr_t listen_sockaddr;
/*
* Construct a socket address for this IP/port
* combination.
*/
isc_netaddr_fromin(&listen_netaddr,
&interface.address.type.in);
isc_sockaddr_fromnetaddr(&listen_sockaddr,
&listen_netaddr,
le->port);
/*
* See if the address matches the listen-on statement;
* if not, ignore the interface.
*/
result = dns_acl_match(&listen_netaddr, NULL,
le->acl, &mgr->aclenv,
&match, NULL);
if (match <= 0)
continue;
ifp = find_matching_interface(mgr, &listen_sockaddr);
if (ifp != NULL) {
ifp->generation = mgr->generation;
} else {
char sabuf[256];
isc_sockaddr_format(&listen_sockaddr,
sabuf, sizeof(sabuf));
isc_log_write(IFMGR_COMMON_LOGARGS,
ISC_LOG_INFO,
"listening on IPv4 interface "
"%s, %s", interface.name, sabuf);
result = ns_interface_setup(mgr,
&listen_sockaddr,
interface.name,
&ifp);
if (result != ISC_R_SUCCESS) {
isc_log_write(IFMGR_COMMON_LOGARGS,
ISC_LOG_ERROR,
"creating IPv4 interface %s "
"failed; interface ignored",
interface.name);
}
/* Continue. */
}
}
continue;
ignore_interface:
isc_log_write(IFMGR_COMMON_LOGARGS,
ISC_LOG_ERROR,
"ignoring IPv4 interface %s: %s",
interface.name, isc_result_totext(result));
continue;
}
if (result != ISC_R_NOMORE)
UNEXPECTED_ERROR(__FILE__, __LINE__,
"IPv4: interface iteration failed: %s",
isc_result_totext(result));
cleanup_iter:
isc_interfaceiter_destroy(&iter);
}
static isc_boolean_t
listenon_is_ip6_none(ns_listenlist_t *p) {
ns_listenelt_t *elt;
if (ISC_LIST_EMPTY(p->elts))
return (ISC_TRUE); /* No listen-on-v6 statements */
elt = ISC_LIST_HEAD(p->elts);
if (ISC_LIST_NEXT(elt, link) != NULL)
return (ISC_FALSE); /* More than one listen-on-v6 stmt */
if (elt->acl->length == 0)
return (ISC_TRUE); /* listen-on-v6 { } */
if (elt->acl->length > 1)
return (ISC_FALSE); /* listen-on-v6 { ...; ...; } */
if (elt->acl->elements[0].negative == ISC_TRUE &&
elt->acl->elements[0].type == dns_aclelementtype_any)
return (ISC_TRUE); /* listen-on-v6 { none; } */
return (ISC_FALSE); /* All others */
}
static isc_boolean_t
listenon_is_ip6_any(ns_listenlist_t *p, in_port_t *portp) {
ns_listenelt_t *elt;
if (ISC_LIST_EMPTY(p->elts))
return (ISC_FALSE); /* No listen-on-v6 statements */
elt = ISC_LIST_HEAD(p->elts);
if (ISC_LIST_NEXT(elt, link) != NULL)
return (ISC_FALSE); /* More than one listen-on-v6 stmt */
if (elt->acl->length != 1)
return (ISC_FALSE);
if (elt->acl->elements[0].negative == ISC_FALSE &&
elt->acl->elements[0].type == dns_aclelementtype_any) {
*portp = elt->port;
return (ISC_TRUE); /* listen-on-v6 { any; } */
}
return (ISC_FALSE); /* All others */
}
static void
do_ipv6(ns_interfacemgr_t *mgr) {
isc_result_t result;
ns_interface_t *ifp;
isc_sockaddr_t listen_addr;
struct in6_addr in6a;
in_port_t port;
if (listenon_is_ip6_none(mgr->listenon6))
return;
if (! listenon_is_ip6_any(mgr->listenon6, &port)) {
isc_log_write(IFMGR_COMMON_LOGARGS,
ISC_LOG_ERROR,
"bad IPv6 listen-on list: must be 'any' or 'none'");
return;
}
in6a = in6addr_any;
isc_sockaddr_fromin6(&listen_addr, &in6a, port);
ifp = find_matching_interface(mgr, &listen_addr);
if (ifp != NULL) {
ifp->generation = mgr->generation;
} else {
isc_log_write(IFMGR_COMMON_LOGARGS, ISC_LOG_INFO,
"listening on IPv6 interfaces, port %u", port);
result = ns_interface_setup(mgr, &listen_addr, "<any>", &ifp);
if (result != ISC_R_SUCCESS) {
isc_log_write(IFMGR_COMMON_LOGARGS,
ISC_LOG_ERROR,
"listening on IPv6 interfaces failed");
/* Continue. */
}
}
}
void
ns_interfacemgr_scan(ns_interfacemgr_t *mgr, isc_boolean_t verbose) {
REQUIRE(NS_INTERFACEMGR_VALID(mgr));
mgr->generation++; /* Increment the generation count. */
if (isc_net_probeipv6() == ISC_R_SUCCESS) {
do_ipv6(mgr);
} else
isc_log_write(IFMGR_COMMON_LOGARGS,
verbose ? ISC_LOG_INFO : ISC_LOG_DEBUG(1),
"no IPv6 interfaces found");
if (isc_net_probeipv4() == ISC_R_SUCCESS)
do_ipv4(mgr);
else
isc_log_write(IFMGR_COMMON_LOGARGS,
verbose ? ISC_LOG_INFO : ISC_LOG_DEBUG(1),
"no IPv4 interfaces found");
/*
* Now go through the interface list and delete anything that
* does not have the current generation number. This is
* how we catch interfaces that go away or change their
* addresses.
*/
purge_old_interfaces(mgr);
if (ISC_LIST_EMPTY(mgr->interfaces)) {
isc_log_write(IFMGR_COMMON_LOGARGS, ISC_LOG_WARNING,
"not listening on any interfaces");
/*
* Continue anyway.
*/
}
}
void
ns_interfacemgr_setlistenon4(ns_interfacemgr_t *mgr, ns_listenlist_t *value) {
LOCK(&mgr->lock);
ns_listenlist_detach(&mgr->listenon4);
ns_listenlist_attach(value, &mgr->listenon4);
UNLOCK(&mgr->lock);
}
void
ns_interfacemgr_setlistenon6(ns_interfacemgr_t *mgr, ns_listenlist_t *value) {
LOCK(&mgr->lock);
ns_listenlist_detach(&mgr->listenon6);
ns_listenlist_attach(value, &mgr->listenon6);
UNLOCK(&mgr->lock);
}
isc_result_t
ns_interfacemgr_findudpdispatcher(ns_interfacemgr_t *mgr,
isc_sockaddr_t *address,
dns_dispatch_t **dispatchp)
{
ns_interface_t *ifp;
/*
* Find a UDP dispatcher matching 'address', if it exists.
*/
ifp = find_matching_interface(mgr, address);
if (ifp == NULL || ifp->udpdispatch == NULL)
return (ISC_R_NOTFOUND);
dns_dispatch_attach(ifp->udpdispatch, dispatchp);
return (ISC_R_SUCCESS);
}

View File

@@ -1,136 +0,0 @@
/*
* Copyright (C) 2000 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: listenlist.c,v 1.6 2000/06/23 01:34:36 gson Exp $ */
#include <config.h>
#include <isc/mem.h>
#include <isc/util.h>
#include <dns/acl.h>
#include <named/listenlist.h>
static void
destroy(ns_listenlist_t *list);
isc_result_t
ns_listenelt_create(isc_mem_t *mctx, in_port_t port,
dns_acl_t *acl, ns_listenelt_t **target)
{
ns_listenelt_t *elt = NULL;
REQUIRE(target != NULL && *target == NULL);
elt = isc_mem_get(mctx, sizeof(*elt));
if (elt == NULL)
return (ISC_R_NOMEMORY);
elt->mctx = mctx;
ISC_LINK_INIT(elt, link);
elt->port = port;
elt->acl = acl;
*target = elt;
return (ISC_R_SUCCESS);
}
void
ns_listenelt_destroy(ns_listenelt_t *elt) {
if (elt->acl != NULL)
dns_acl_detach(&elt->acl);
isc_mem_put(elt->mctx, elt, sizeof(*elt));
}
isc_result_t
ns_listenlist_create(isc_mem_t *mctx, ns_listenlist_t **target) {
ns_listenlist_t *list = NULL;
REQUIRE(target != NULL && *target == NULL);
list = isc_mem_get(mctx, sizeof(*list));
if (list == NULL)
return (ISC_R_NOMEMORY);
list->mctx = mctx;
list->refcount = 1;
ISC_LIST_INIT(list->elts);
*target = list;
return (ISC_R_SUCCESS);
}
static void
destroy(ns_listenlist_t *list) {
ns_listenelt_t *elt, *next;
for (elt = ISC_LIST_HEAD(list->elts);
elt != NULL;
elt = next)
{
next = ISC_LIST_NEXT(elt, link);
ns_listenelt_destroy(elt);
}
isc_mem_put(list->mctx, list, sizeof(*list));
}
void
ns_listenlist_attach(ns_listenlist_t *source, ns_listenlist_t **target) {
INSIST(source->refcount > 0);
source->refcount++;
*target = source;
}
void
ns_listenlist_detach(ns_listenlist_t **listp) {
ns_listenlist_t *list = *listp;
INSIST(list->refcount > 0);
list->refcount--;
if (list->refcount == 0)
destroy(list);
*listp = NULL;
}
isc_result_t
ns_listenlist_default(isc_mem_t *mctx, in_port_t port,
isc_boolean_t enabled, ns_listenlist_t **target)
{
isc_result_t result;
dns_acl_t *acl = NULL;
ns_listenelt_t *elt = NULL;
ns_listenlist_t *list = NULL;
REQUIRE(target != NULL && *target == NULL);
if (enabled)
result = dns_acl_any(mctx, &acl);
else
result = dns_acl_none(mctx, &acl);
if (result != ISC_R_SUCCESS)
goto cleanup;
result = ns_listenelt_create(mctx, port, acl, &elt);
if (result != ISC_R_SUCCESS)
goto cleanup_acl;
result = ns_listenlist_create(mctx, &list);
if (result != ISC_R_SUCCESS)
goto cleanup_listenelt;
ISC_LIST_APPEND(list->elts, elt, link);
*target = list;
return (ISC_R_SUCCESS);
cleanup_listenelt:
ns_listenelt_destroy(elt);
cleanup_acl:
dns_acl_detach(&acl);
cleanup:
return (result);
}

View File

@@ -1,179 +0,0 @@
/*
* Copyright (C) 1999, 2000 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: log.c,v 1.20 2000/06/22 21:49:22 tale Exp $ */
#include <config.h>
#include <named/log.h>
/*
* When adding a new category, be sure to add the appropriate
* #define to <named/log.h>.
*/
static isc_logcategory_t categories[] = {
{ "", 0 },
{ "client", 0 },
{ "network", 0 },
{ "update", 0 },
{ NULL, 0 }
};
/*
* When adding a new module, be sure to add the appropriate
* #define to <dns/log.h>.
*/
static isc_logmodule_t modules[] = {
{ "main", 0 },
{ "client", 0 },
{ "server", 0 },
{ "query", 0 },
{ "interfacemgr", 0 },
{ "update", 0 },
{ "xfer-in", 0 },
{ "xfer-out", 0 },
{ "notify", 0 },
{ "omapi", 0 },
{ "lwresd", 0 },
{ NULL, 0 }
};
isc_result_t
ns_log_init(isc_boolean_t safe) {
isc_result_t result;
isc_logconfig_t *lcfg;
ns_g_categories = categories;
ns_g_modules = modules;
/*
* Setup a logging context.
*/
result = isc_log_create(ns_g_mctx, &ns_g_lctx, &lcfg);
if (result != ISC_R_SUCCESS)
return (result);
isc_log_registercategories(ns_g_lctx, ns_g_categories);
isc_log_registermodules(ns_g_lctx, ns_g_modules);
isc_log_setcontext(ns_g_lctx);
dns_log_init(ns_g_lctx);
dns_log_setcontext(ns_g_lctx);
if (safe)
result = ns_log_setsafechannels(lcfg);
else
result = ns_log_setdefaultchannels(lcfg);
if (result != ISC_R_SUCCESS)
goto cleanup;
result = ns_log_setdefaultcategory(lcfg);
if (result != ISC_R_SUCCESS)
goto cleanup;
return (ISC_R_SUCCESS);
cleanup:
isc_log_destroy(&ns_g_lctx);
return (result);
}
isc_result_t
ns_log_setdefaultchannels(isc_logconfig_t *lcfg) {
isc_result_t result;
isc_logdestination_t destination;
/*
* By default, the logging library makes "default_debug" log to
* stderr. In BIND, we want to override this and log to named.run
* instead, unless the the -g option was given.
*/
if (! ns_g_logstderr) {
destination.file.stream = NULL;
destination.file.name = "named.run";
destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0;
result = isc_log_createchannel(lcfg, "default_debug",
ISC_LOG_TOFILE,
ISC_LOG_DYNAMIC,
&destination,
ISC_LOG_PRINTTIME|
ISC_LOG_DEBUGONLY);
if (result != ISC_R_SUCCESS)
goto cleanup;
}
/*
* Set the initial debug level.
*/
isc_log_setdebuglevel(ns_g_lctx, ns_g_debuglevel);
result = ISC_R_SUCCESS;
cleanup:
return (result);
}
isc_result_t
ns_log_setsafechannels(isc_logconfig_t *lcfg) {
isc_result_t result;
if (! ns_g_logstderr) {
result = isc_log_createchannel(lcfg, "default_debug",
ISC_LOG_TONULL,
ISC_LOG_DYNAMIC,
NULL, 0);
if (result != ISC_R_SUCCESS)
goto cleanup;
}
/*
* Setting the debug level to zero should get the output
* discarded a bit faster.
*/
isc_log_setdebuglevel(ns_g_lctx, 0);
result = ISC_R_SUCCESS;
cleanup:
return (result);
}
isc_result_t
ns_log_setdefaultcategory(isc_logconfig_t *lcfg) {
isc_result_t result;
result = isc_log_usechannel(lcfg, "default_syslog",
ISC_LOGCATEGORY_DEFAULT, NULL);
if (result != ISC_R_SUCCESS)
goto cleanup;
result = isc_log_usechannel(lcfg, "default_debug",
ISC_LOGCATEGORY_DEFAULT, NULL);
if (result != ISC_R_SUCCESS)
goto cleanup;
result = ISC_R_SUCCESS;
cleanup:
return (result);
}
void
ns_log_shutdown(void) {
isc_log_destroy(&ns_g_lctx);
}

View File

@@ -1,244 +0,0 @@
/*
* Copyright (C) 1999, 2000 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: logconf.c,v 1.22.2.1 2000/11/29 20:18:57 gson Exp $ */
#include <config.h>
#include <isc/string.h>
#include <named/log.h>
#include <named/logconf.h>
#define CHECK(op) \
do { result = (op); \
if (result != ISC_R_SUCCESS) goto cleanup; \
} while (0)
/*
* Set up a logging category according to the named.conf data
* in 'ccat' and add it to 'lctx'.
*/
static isc_result_t
category_fromconf(dns_c_logcat_t *ccat, isc_logconfig_t *lctx) {
isc_result_t result;
unsigned int i;
isc_logcategory_t *category;
isc_logmodule_t *module;
category = isc_log_categorybyname(ns_g_lctx, ccat->catname);
if (category == NULL) {
isc_log_write(ns_g_lctx, DNS_LOGCATEGORY_CONFIG,
NS_LOGMODULE_SERVER, ISC_LOG_ERROR,
"unknown logging category '%s' ignored",
ccat->catname);
/*
* Allow further processing by returning success.
*/
return (ISC_R_SUCCESS);
}
#ifdef notyet
module = isc_log_modulebyname(ns_g_lctx, ccat->modname);
if (module == NULL) {
isc_log_write(ns_g_lctx, DNS_LOGCATEGORY_CONFIG,
NS_LOGMODULE_SERVER, ISC_LOG_ERROR,
"unknown logging module '%s' ignored",
ccat->modname);
/*
* Allow further processing by returning success.
*/
return (ISC_R_SUCCESS);
}
#else
module = NULL;
#endif
for (i = 0; i < ccat->nextcname; i++) {
char *channelname = ccat->channel_names[i];
result = isc_log_usechannel(lctx, channelname, category,
module);
if (result != ISC_R_SUCCESS) {
isc_log_write(ns_g_lctx, DNS_LOGCATEGORY_CONFIG,
NS_LOGMODULE_SERVER, ISC_LOG_ERROR,
"logging channel '%s': %s", channelname,
isc_result_totext(result));
return (result);
}
}
return (ISC_R_SUCCESS);
}
/*
* Set up a logging channel according to the named.conf data
* in 'cchan' and add it to 'lctx'.
*/
static isc_result_t
channel_fromconf(dns_c_logchan_t *cchan, isc_logconfig_t *lctx) {
isc_result_t result;
isc_logdestination_t dest;
unsigned int type;
unsigned int flags = 0;
int level;
dns_c_logseverity_t severity;
type = ISC_LOG_TONULL;
switch (cchan->ctype) {
case dns_c_logchan_file:
type = ISC_LOG_TOFILE;
{
const char *path = NULL;
isc_int32_t versions = ISC_LOG_ROLLNEVER;
/*
* XXXDCL should be isc_offset_t, but that
* is incompatible with dns_c_logchan_getsize.
*/
isc_uint32_t size = 0;
(void)dns_c_logchan_getpath(cchan, &path);
if (path == NULL) {
isc_log_write(ns_g_lctx,
DNS_LOGCATEGORY_CONFIG,
NS_LOGMODULE_SERVER,
ISC_LOG_ERROR,
"file log channel has "
"no file name");
return (ISC_R_UNEXPECTED);
}
(void)dns_c_logchan_getversions(cchan,
(isc_uint32_t *)
&versions);
(void)dns_c_logchan_getsize(cchan, &size);
dest.file.stream = NULL;
dest.file.name = cchan->u.filec.path;
dest.file.versions = versions;
dest.file.maximum_size = size;
}
break;
case dns_c_logchan_syslog:
type = ISC_LOG_TOSYSLOG;
{
int facility = LOG_DAEMON;
(void)dns_c_logchan_getfacility(cchan, &facility);
dest.facility = facility;
}
break;
case dns_c_logchan_stderr:
type = ISC_LOG_TOFILEDESC;
{
dest.file.stream = stderr;
dest.file.name = NULL;
dest.file.versions = ISC_LOG_ROLLNEVER;
dest.file.maximum_size = 0;
}
case dns_c_logchan_null:
break;
}
/*
* Munge flags.
*/
{
isc_boolean_t printcat = ISC_FALSE;
isc_boolean_t printsev = ISC_FALSE;
isc_boolean_t printtime = ISC_FALSE;
(void)dns_c_logchan_getprintcat(cchan, &printcat);
(void)dns_c_logchan_getprintsev(cchan, &printsev);
(void)dns_c_logchan_getprinttime(cchan, &printtime);
if (printcat)
flags |= ISC_LOG_PRINTCATEGORY;
if (printtime)
flags |= ISC_LOG_PRINTTIME;
if (printsev)
flags |= ISC_LOG_PRINTLEVEL;
/* XXX ISC_LOG_PRINTMODULE */
}
level = ISC_LOG_INFO;
if (dns_c_logchan_getseverity(cchan, &severity) == ISC_R_SUCCESS) {
switch (severity) {
case dns_c_log_critical:
level = ISC_LOG_CRITICAL;
break;
case dns_c_log_error:
level = ISC_LOG_ERROR;
break;
case dns_c_log_warn:
level = ISC_LOG_WARNING;
break;
case dns_c_log_notice:
level = ISC_LOG_NOTICE;
break;
case dns_c_log_info:
level = ISC_LOG_INFO;
break;
case dns_c_log_debug:
(void)dns_c_logchan_getdebuglevel(cchan, &level);
break;
case dns_c_log_dynamic:
level = ISC_LOG_DYNAMIC;
break;
default:
level = ISC_LOG_INFO;
break;
}
}
result = isc_log_createchannel(lctx, cchan->name,
type, level, &dest, flags);
return (result);
}
isc_result_t
ns_log_configure(isc_logconfig_t *lcctx, dns_c_logginglist_t *clog) {
isc_result_t result;
dns_c_logchan_t *cchan;
dns_c_logcat_t *ccat;
isc_boolean_t default_set = ISC_FALSE;
CHECK(ns_log_setdefaultchannels(lcctx));
for (cchan = ISC_LIST_HEAD(clog->channels);
cchan != NULL;
cchan = ISC_LIST_NEXT(cchan, next)) {
CHECK(channel_fromconf(cchan, lcctx));
}
for (ccat = ISC_LIST_HEAD(clog->categories);
ccat != NULL;
ccat = ISC_LIST_NEXT(ccat, next)) {
CHECK(category_fromconf(ccat, lcctx));
if (! default_set)
default_set =
ISC_TF(strcmp(ccat->catname, "default") == 0);
}
if (! default_set)
CHECK(ns_log_setdefaultcategory(lcctx));
return (ISC_R_SUCCESS);
cleanup:
if (lcctx != NULL)
isc_logconfig_destroy(&lcctx);
return (result);
}

View File

@@ -1,293 +0,0 @@
/*
* Copyright (C) 2000 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: lwdclient.c,v 1.3.2.1 2000/06/26 21:47:32 gson Exp $ */
#include <config.h>
#include <isc/socket.h>
#include <isc/string.h>
#include <isc/task.h>
#include <isc/util.h>
#include <dns/view.h>
#include <dns/log.h>
#include <named/types.h>
#include <named/lwdclient.h>
void
ns_lwdclient_log(int level, const char *format, ...) {
va_list args;
va_start(args, format);
isc_log_vwrite(dns_lctx,
DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_ADB,
ISC_LOG_DEBUG(level), format, args);
va_end(args);
}
static void
clientmgr_can_die(ns_lwdclientmgr_t *cm) {
if ((cm->flags & NS_LWDCLIENTMGR_FLAGSHUTTINGDOWN) == 0)
return;
if (ISC_LIST_HEAD(cm->running) != NULL)
return;
lwres_context_destroy(&cm->lwctx);
isc_socket_detach(&cm->sock);
dns_view_detach(&cm->view);
isc_task_detach(&cm->task);
}
static void
process_request(ns_lwdclient_t *client) {
lwres_buffer_t b;
isc_result_t result;
lwres_buffer_init(&b, client->buffer, client->recvlength);
lwres_buffer_add(&b, client->recvlength);
result = lwres_lwpacket_parseheader(&b, &client->pkt);
if (result != ISC_R_SUCCESS) {
ns_lwdclient_log(50, "invalid packet header received");
goto restart;
}
ns_lwdclient_log(50, "opcode %08x", client->pkt.opcode);
switch (client->pkt.opcode) {
case LWRES_OPCODE_GETADDRSBYNAME:
ns_lwdclient_processgabn(client, &b);
return;
case LWRES_OPCODE_GETNAMEBYADDR:
ns_lwdclient_processgnba(client, &b);
return;
case LWRES_OPCODE_NOOP:
ns_lwdclient_processnoop(client, &b);
return;
default:
ns_lwdclient_log(50, "unknown opcode %08x", client->pkt.opcode);
goto restart;
}
/*
* Drop the packet.
*/
restart:
ns_lwdclient_log(50, "restarting client %p...", client);
ns_lwdclient_stateidle(client);
}
void
ns_lwdclient_recv(isc_task_t *task, isc_event_t *ev) {
ns_lwdclient_t *client = ev->ev_arg;
ns_lwdclientmgr_t *cm = client->clientmgr;
isc_socketevent_t *dev = (isc_socketevent_t *)ev;
INSIST(dev->region.base == client->buffer);
INSIST(NS_LWDCLIENT_ISRECV(client));
NS_LWDCLIENT_SETRECVDONE(client);
INSIST((cm->flags & NS_LWDCLIENTMGR_FLAGRECVPENDING) != 0);
cm->flags &= ~NS_LWDCLIENTMGR_FLAGRECVPENDING;
ns_lwdclient_log(50,
"event received: task %p, length %u, result %u (%s)",
task, dev->n, dev->result,
isc_result_totext(dev->result));
if (dev->result != ISC_R_SUCCESS) {
isc_event_free(&ev);
dev = NULL;
/*
* Go idle.
*/
ns_lwdclient_stateidle(client);
return;
}
/*
* XXXMLG If we wanted to run on ipv6 as well, we'd need the pktinfo
* bits. Right now we don't, so don't remember them.
*/
client->recvlength = dev->n;
client->address = dev->address;
isc_event_free(&ev);
dev = NULL;
ns_lwdclient_startrecv(cm);
process_request(client);
}
/*
* This function will start a new recv() on a socket for this client manager.
*/
isc_result_t
ns_lwdclient_startrecv(ns_lwdclientmgr_t *cm) {
ns_lwdclient_t *client;
isc_result_t result;
isc_region_t r;
if ((cm->flags & NS_LWDCLIENTMGR_FLAGSHUTTINGDOWN) != 0)
return (ISC_R_SUCCESS);
/*
* If a recv is already running, don't bother.
*/
if ((cm->flags & NS_LWDCLIENTMGR_FLAGRECVPENDING) != 0)
return (ISC_R_SUCCESS);
/*
* If we have no idle slots, just return success.
*/
client = ISC_LIST_HEAD(cm->idle);
if (client == NULL)
return (ISC_R_SUCCESS);
INSIST(NS_LWDCLIENT_ISIDLE(client));
/*
* Issue the recv. If it fails, return that it did.
*/
r.base = client->buffer;
r.length = LWRES_RECVLENGTH;
result = isc_socket_recv(cm->sock, &r, 0, cm->task, ns_lwdclient_recv,
client);
if (result != ISC_R_SUCCESS)
return (result);
/*
* Set the flag to say we've issued a recv() call.
*/
cm->flags |= NS_LWDCLIENTMGR_FLAGRECVPENDING;
/*
* Remove the client from the idle list, and put it on the running
* list.
*/
NS_LWDCLIENT_SETRECV(client);
ISC_LIST_UNLINK(cm->idle, client, link);
ISC_LIST_APPEND(cm->running, client, link);
return (ISC_R_SUCCESS);
}
void
ns_lwdclient_shutdown(isc_task_t *task, isc_event_t *ev) {
ns_lwdclientmgr_t *cm = ev->ev_arg;
REQUIRE((cm->flags & NS_LWDCLIENTMGR_FLAGSHUTTINGDOWN) == 0);
ns_lwdclient_log(50, "got shutdown event, task %p", task);
/*
* Cancel any pending I/O.
*/
if ((cm->flags & NS_LWDCLIENTMGR_FLAGRECVPENDING) != 0)
isc_socket_cancel(cm->sock, task, ISC_SOCKCANCEL_ALL);
/*
* Run through the running client list and kill off any finds
* in progress.
*/
/* XXXMLG */
cm->flags |= NS_LWDCLIENTMGR_FLAGSHUTTINGDOWN;
isc_event_free(&ev);
}
/*
* Do all the crap needed to move a client from the run queue to the idle
* queue.
*/
void
ns_lwdclient_stateidle(ns_lwdclient_t *client) {
ns_lwdclientmgr_t *cm;
cm = client->clientmgr;
INSIST(client->sendbuf == NULL);
INSIST(client->sendlength == 0);
INSIST(client->arg == NULL);
INSIST(client->v4find == NULL);
INSIST(client->v6find == NULL);
ISC_LIST_UNLINK(cm->running, client, link);
ISC_LIST_PREPEND(cm->idle, client, link);
NS_LWDCLIENT_SETIDLE(client);
clientmgr_can_die(cm);
ns_lwdclient_startrecv(cm);
}
void
ns_lwdclient_send(isc_task_t *task, isc_event_t *ev) {
ns_lwdclient_t *client = ev->ev_arg;
ns_lwdclientmgr_t *cm = client->clientmgr;
isc_socketevent_t *dev = (isc_socketevent_t *)ev;
UNUSED(task);
UNUSED(dev);
INSIST(NS_LWDCLIENT_ISSEND(client));
INSIST(client->sendbuf == dev->region.base);
ns_lwdclient_log(50, "task %p for client %p got send-done event",
task, client);
if (client->sendbuf != client->buffer)
lwres_context_freemem(cm->lwctx, client->sendbuf,
client->sendlength);
client->sendbuf = NULL;
client->sendlength = 0;
ns_lwdclient_stateidle(client);
isc_event_free(&ev);
}
void
ns_lwdclient_initialize(ns_lwdclient_t *client, ns_lwdclientmgr_t *cmgr) {
client->clientmgr = cmgr;
ISC_LINK_INIT(client, link);
NS_LWDCLIENT_SETIDLE(client);
client->arg = NULL;
client->recvlength = 0;
client->sendbuf = NULL;
client->sendlength = 0;
client->find = NULL;
client->v4find = NULL;
client->v6find = NULL;
client->find_wanted = 0;
client->options = 0;
client->byaddr = NULL;
client->addrinfo = NULL;
ISC_LIST_APPEND(cmgr->idle, client, link);
}

View File

@@ -1,82 +0,0 @@
/*
* Copyright (C) 2000 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: lwderror.c,v 1.2 2000/06/22 21:49:25 tale Exp $ */
#include <config.h>
#include <isc/socket.h>
#include <isc/util.h>
#include <named/types.h>
#include <named/lwdclient.h>
/*
* Generate an error packet for the client, schedule a send, and put us in
* the SEND state.
*
* The client->pkt structure will be modified to form an error return.
* The receiver needs to verify that it is in fact an error, and do the
* right thing with it. The opcode will be unchanged. The result needs
* to be set before calling this function.
*
* The only change this code makes is to set the receive buffer size to the
* size we use, set the reply bit, and recompute any security information.
*/
void
ns_lwdclient_errorpktsend(ns_lwdclient_t *client, isc_uint32_t _result) {
isc_result_t result;
int lwres;
isc_region_t r;
lwres_buffer_t b;
ns_lwdclientmgr_t *cm;
cm = client->clientmgr;
REQUIRE(NS_LWDCLIENT_ISRUNNING(client));
/*
* Since we are only sending the packet header, we can safely toss
* the receive buffer. This means we won't need to allocate space
* for sending an error reply. This is a Good Thing.
*/
client->pkt.length = LWRES_LWPACKET_LENGTH;
client->pkt.pktflags |= LWRES_LWPACKETFLAG_RESPONSE;
client->pkt.recvlength = LWRES_RECVLENGTH;
client->pkt.authtype = 0; /* XXXMLG */
client->pkt.authlength = 0;
client->pkt.result = _result;
lwres_buffer_init(&b, client->buffer, LWRES_RECVLENGTH);
lwres = lwres_lwpacket_renderheader(&b, &client->pkt);
if (lwres != LWRES_R_SUCCESS) {
ns_lwdclient_stateidle(client);
return;
}
r.base = client->buffer;
r.length = b.used;
client->sendbuf = client->buffer;
result = isc_socket_sendto(cm->sock, &r, cm->task, ns_lwdclient_send,
client, &client->address, NULL);
if (result != ISC_R_SUCCESS) {
ns_lwdclient_stateidle(client);
return;
}
NS_LWDCLIENT_SETSEND(client);
}

View File

@@ -1,568 +0,0 @@
/*
* Copyright (C) 2000 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: lwdgabn.c,v 1.3.2.1 2000/06/26 21:47:33 gson Exp $ */
#include <config.h>
#include <isc/socket.h>
#include <isc/string.h> /* Required for HP/UX (and others?) */
#include <isc/util.h>
#include <dns/adb.h>
#include <dns/events.h>
#include <dns/result.h>
#include <named/types.h>
#include <named/lwdclient.h>
#define NEED_V4(c) ((((c)->find_wanted & LWRES_ADDRTYPE_V4) != 0) \
&& ((c)->v4find == NULL))
#define NEED_V6(c) ((((c)->find_wanted & LWRES_ADDRTYPE_V6) != 0) \
&& ((c)->v6find == NULL))
static void start_find(ns_lwdclient_t *);
/*
* Destroy any finds. This can be used to "start over from scratch" and
* should only be called when events are _not_ being generated by the finds.
*/
static void
cleanup_gabn(ns_lwdclient_t *client) {
dns_adbfind_t *v4;
ns_lwdclient_log(50, "cleaning up client %p", client);
v4 = client->v4find;
if (client->v4find != NULL)
dns_adb_destroyfind(&client->v4find);
if (client->v6find != NULL) {
if (client->v6find == v4)
client->v6find = NULL;
else
dns_adb_destroyfind(&client->v6find);
}
}
static void
setup_addresses(ns_lwdclient_t *client, dns_adbfind_t *find, unsigned int at) {
dns_adbaddrinfo_t *ai;
lwres_addr_t *addr;
int af;
const struct sockaddr *sa;
const struct sockaddr_in *sin;
const struct sockaddr_in6 *sin6;
if (at == DNS_ADBFIND_INET)
af = AF_INET;
else
af = AF_INET6;
ai = ISC_LIST_HEAD(find->list);
while (ai != NULL && client->gabn.naddrs < LWRES_MAX_ADDRS) {
sa = &ai->sockaddr.type.sa;
if (sa->sa_family != af)
goto next;
addr = &client->addrs[client->gabn.naddrs];
switch (sa->sa_family) {
case AF_INET:
sin = &ai->sockaddr.type.sin;
addr->family = LWRES_ADDRTYPE_V4;
memcpy(addr->address, &sin->sin_addr, 4);
addr->length = 4;
break;
case AF_INET6:
sin6 = &ai->sockaddr.type.sin6;
addr->family = LWRES_ADDRTYPE_V6;
memcpy(addr->address, &sin6->sin6_addr, 16);
addr->length = 16;
break;
default:
goto next;
}
ns_lwdclient_log(50, "adding address %p, family %d, length %d",
addr->address, addr->family, addr->length);
client->gabn.naddrs++;
REQUIRE(!LWRES_LINK_LINKED(addr, link));
LWRES_LIST_APPEND(client->gabn.addrs, addr, link);
next:
ai = ISC_LIST_NEXT(ai, publink);
}
}
static void
generate_reply(ns_lwdclient_t *client) {
isc_result_t result;
int lwres;
isc_region_t r;
lwres_buffer_t lwb;
ns_lwdclientmgr_t *cm;
cm = client->clientmgr;
lwb.base = NULL;
ns_lwdclient_log(50, "generating gabn reply for client %p", client);
/*
* We must make certain the client->find is not still active.
* If it is either the v4 or v6 answer, just set it to NULL and
* let the cleanup code destroy it. Otherwise, destroy it now.
*/
if (client->find == client->v4find || client->find == client->v6find)
client->find = NULL;
else
if (client->find != NULL)
dns_adb_destroyfind(&client->find);
/*
* perhaps there are some here?
*/
if (NEED_V6(client) && client->v4find != NULL)
client->v6find = client->v4find;
/*
* Run through the finds we have and wire them up to the gabn
* structure.
*/
LWRES_LIST_INIT(client->gabn.addrs);
if (client->v4find != NULL)
setup_addresses(client, client->v4find, DNS_ADBFIND_INET);
if (client->v6find != NULL)
setup_addresses(client, client->v6find, DNS_ADBFIND_INET6);
/*
* Render the packet.
*/
client->pkt.recvlength = LWRES_RECVLENGTH;
client->pkt.authtype = 0; /* XXXMLG */
client->pkt.authlength = 0;
/*
* If there are no addresses, return incomplete or failure , depending
* on whether or not there are aliases.
*/
if (client->gabn.naddrs != 0)
client->pkt.result = LWRES_R_SUCCESS;
else if (client->gabn.naliases != 0)
client->pkt.result = LWRES_R_INCOMPLETE;
else
client->pkt.result = LWRES_R_NOTFOUND;
lwres = lwres_gabnresponse_render(cm->lwctx, &client->gabn,
&client->pkt, &lwb);
if (lwres != LWRES_R_SUCCESS)
goto out;
r.base = lwb.base;
r.length = lwb.used;
client->sendbuf = r.base;
client->sendlength = r.length;
result = isc_socket_sendto(cm->sock, &r, cm->task, ns_lwdclient_send,
client, &client->address, NULL);
if (result != ISC_R_SUCCESS)
goto out;
NS_LWDCLIENT_SETSEND(client);
/*
* All done!
*/
cleanup_gabn(client);
return;
out:
cleanup_gabn(client);
if (lwb.base != NULL)
lwres_context_freemem(client->clientmgr->lwctx,
lwb.base, lwb.length);
ns_lwdclient_errorpktsend(client, LWRES_R_FAILURE);
}
/*
* Take the current real name, move it to an alias slot (if any are
* open) then put this new name in as the real name for the target.
*
* Return success if it can be rendered, otherwise failure. Note that
* not having enough alias slots open is NOT a failure.
*/
static isc_result_t
add_alias(ns_lwdclient_t *client) {
isc_buffer_t b;
isc_result_t result;
isc_uint16_t naliases;
b = client->recv_buffer;
/*
* Render the new name to the buffer.
*/
result = dns_name_totext(dns_fixedname_name(&client->target_name),
ISC_TRUE, &client->recv_buffer);
if (result != ISC_R_SUCCESS)
return (result);
/*
* Are there any open slots?
*/
naliases = client->gabn.naliases;
if (naliases < LWRES_MAX_ALIASES) {
client->gabn.aliases[naliases] = client->gabn.realname;
client->gabn.aliaslen[naliases] = client->gabn.realnamelen;
client->gabn.naliases++;
}
/*
* Save this name away as the current real name.
*/
client->gabn.realname = (char *)(b.base) + b.used;
client->gabn.realnamelen = client->recv_buffer.used - b.used;
return (ISC_R_SUCCESS);
}
static isc_result_t
store_realname(ns_lwdclient_t *client) {
isc_buffer_t b;
isc_result_t result;
b = client->recv_buffer;
/*
* Render the new name to the buffer.
*/
result = dns_name_totext(dns_fixedname_name(&client->target_name),
ISC_TRUE, &client->recv_buffer);
if (result != ISC_R_SUCCESS)
return (result);
/*
* Save this name away as the current real name.
*/
client->gabn.realname = (char *) b.base + b.used;
client->gabn.realnamelen = client->recv_buffer.used - b.used;
return (ISC_R_SUCCESS);
}
static void
process_gabn_finddone(isc_task_t *task, isc_event_t *ev) {
ns_lwdclient_t *client = ev->ev_arg;
isc_eventtype_t evtype;
isc_boolean_t claimed;
ns_lwdclient_log(50, "find done for task %p, client %p", task, client);
evtype = ev->ev_type;
isc_event_free(&ev);
/*
* No more info to be had? If so, we have all the good stuff
* right now, so we can render things.
*/
claimed = ISC_FALSE;
if (evtype == DNS_EVENT_ADBNOMOREADDRESSES) {
if (NEED_V4(client)) {
client->v4find = client->find;
claimed = ISC_TRUE;
}
if (NEED_V6(client)) {
client->v6find = client->find;
claimed = ISC_TRUE;
}
if (client->find != NULL) {
if (claimed)
client->find = NULL;
else
dns_adb_destroyfind(&client->find);
}
generate_reply(client);
return;
}
/*
* We probably don't need this find anymore. We're either going to
* reissue it, or an error occurred. Either way, we're done with
* it.
*/
if ((client->find != client->v4find)
&& (client->find != client->v6find)) {
dns_adb_destroyfind(&client->find);
} else {
client->find = NULL;
}
/*
* We have some new information we can gather. Run off and fetch
* it.
*/
if (evtype == DNS_EVENT_ADBMOREADDRESSES) {
start_find(client);
return;
}
/*
* An error or other strangeness happened. Drop this query.
*/
cleanup_gabn(client);
ns_lwdclient_errorpktsend(client, LWRES_R_FAILURE);
}
static void
start_find(ns_lwdclient_t *client) {
unsigned int options;
isc_result_t result;
isc_boolean_t claimed;
ns_lwdclient_log(50, "starting find for client %p", client);
/*
* Issue a find for the name contained in the request. We won't
* set the bit that says "anything is good enough" -- we want it
* all.
*/
options = 0;
options |= DNS_ADBFIND_WANTEVENT;
options |= DNS_ADBFIND_RETURNLAME;
/*
* Set the bits up here to mark that we want this address family
* and that we do not currently have a find pending. We will
* set that bit again below if it turns out we will get an event.
*/
if (NEED_V4(client))
options |= DNS_ADBFIND_INET;
if (NEED_V6(client))
options |= DNS_ADBFIND_INET6;
find_again:
INSIST(client->find == NULL);
result = dns_adb_createfind(client->clientmgr->view->adb,
client->clientmgr->task,
process_gabn_finddone, client,
dns_fixedname_name(&client->target_name),
dns_rootname, options, 0,
dns_fixedname_name(&client->target_name),
client->clientmgr->view->dstport,
&client->find);
/*
* Did we get an alias? If so, save it and re-issue the query.
*/
if (result == DNS_R_ALIAS) {
ns_lwdclient_log(50, "found alias, restarting query");
dns_adb_destroyfind(&client->find);
cleanup_gabn(client);
result = add_alias(client);
if (result != ISC_R_SUCCESS) {
ns_lwdclient_log(50,
"out of buffer space adding alias");
ns_lwdclient_errorpktsend(client, LWRES_R_FAILURE);
return;
}
goto find_again;
}
ns_lwdclient_log(50, "find returned %d (%s)", result,
isc_result_totext(result));
/*
* Did we get an error?
*/
if (result != ISC_R_SUCCESS) {
if (client->find != NULL)
dns_adb_destroyfind(&client->find);
cleanup_gabn(client);
ns_lwdclient_errorpktsend(client, LWRES_R_FAILURE);
return;
}
claimed = ISC_FALSE;
/*
* Did we get our answer to V4 addresses?
*/
if (NEED_V4(client)
&& ((client->find->query_pending & DNS_ADBFIND_INET) == 0)) {
ns_lwdclient_log(50, "client %p ipv4 satisfied by find %p",
client, client->find);
claimed = ISC_TRUE;
client->v4find = client->find;
}
/*
* Did we get our answer to V6 addresses?
*/
if (NEED_V6(client)
&& ((client->find->query_pending & DNS_ADBFIND_INET6) == 0)) {
ns_lwdclient_log(50, "client %p ipv6 satisfied by find %p",
client, client->find);
claimed = ISC_TRUE;
client->v6find = client->find;
}
/*
* If we're going to get an event, set our internal pending flag
* and return. When we get an event back we'll do the right
* thing, basically by calling this function again, perhaps with a
* new target name.
*
* If we have both v4 and v6, and we are still getting an event,
* we have a programming error, so die hard.
*/
if ((client->find->options & DNS_ADBFIND_WANTEVENT) != 0) {
ns_lwdclient_log(50, "event will be sent");
INSIST(client->v4find == NULL || client->v6find == NULL);
return;
}
ns_lwdclient_log(50, "no event will be sent");
if (claimed)
client->find = NULL;
else
dns_adb_destroyfind(&client->find);
/*
* We seem to have everything we asked for, or at least we are
* able to respond with things we've learned.
*/
generate_reply(client);
}
static void
init_gabn(ns_lwdclient_t *client) {
int i;
/*
* Initialize the real name and alias arrays in the reply we're
* going to build up.
*/
for (i = 0 ; i < LWRES_MAX_ALIASES ; i++) {
client->aliases[i] = NULL;
client->aliaslen[i] = 0;
}
for (i = 0 ; i < LWRES_MAX_ADDRS ; i++) {
client->addrs[i].family = 0;
client->addrs[i].length = 0;
memset(client->addrs[i].address, 0, LWRES_ADDR_MAXLEN);
LWRES_LINK_INIT(&client->addrs[i], link);
}
client->gabn.naliases = 0;
client->gabn.naddrs = 0;
client->gabn.realname = NULL;
client->gabn.aliases = client->aliases;
client->gabn.realnamelen = 0;
client->gabn.aliaslen = client->aliaslen;
LWRES_LIST_INIT(client->gabn.addrs);
client->gabn.base = NULL;
client->gabn.baselen = 0;
/*
* Set up the internal buffer to point to the receive region.
*/
isc_buffer_init(&client->recv_buffer, client->buffer, LWRES_RECVLENGTH);
}
/*
* When we are called, we can be assured that:
*
* client->sockaddr contains the address we need to reply to,
*
* client->pkt contains the packet header data,
*
* the packet "checks out" overall -- any MD5 hashes or crypto
* bits have been verified,
*
* "b" points to the remaining data after the packet header
* was parsed off.
*
* We are in a the RECVDONE state.
*
* From this state we will enter the SEND state if we happen to have
* everything we need or we need to return an error packet, or to the
* FINDWAIT state if we need to look things up.
*/
void
ns_lwdclient_processgabn(ns_lwdclient_t *client, lwres_buffer_t *b) {
isc_result_t result;
lwres_gabnrequest_t *req;
isc_buffer_t namebuf;
REQUIRE(NS_LWDCLIENT_ISRECVDONE(client));
req = NULL;
result = lwres_gabnrequest_parse(client->clientmgr->lwctx,
b, &client->pkt, &req);
if (result != LWRES_R_SUCCESS)
goto out;
isc_buffer_init(&namebuf, req->name, req->namelen);
isc_buffer_add(&namebuf, req->namelen);
dns_fixedname_init(&client->target_name);
result = dns_name_fromtext(dns_fixedname_name(&client->target_name),
&namebuf, dns_rootname, ISC_FALSE, NULL);
if (result != ISC_R_SUCCESS)
goto out;
client->find_wanted = req->addrtypes;
ns_lwdclient_log(50, "client %p looking for addrtypes %08x",
client, client->find_wanted);
/*
* We no longer need to keep this around.
*/
lwres_gabnrequest_free(client->clientmgr->lwctx, &req);
/*
* Initialize the real name and alias arrays in the reply we're
* going to build up.
*/
init_gabn(client);
result = store_realname(client);
if (result != ISC_R_SUCCESS)
goto out;
/*
* Start the find.
*/
start_find(client);
return;
/*
* We're screwed. Return an error packet to our caller.
*/
out:
if (req != NULL)
lwres_gabnrequest_free(client->clientmgr->lwctx, &req);
ns_lwdclient_errorpktsend(client, LWRES_R_FAILURE);
}

View File

@@ -1,303 +0,0 @@
/*
* Copyright (C) 2000 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: lwdgnba.c,v 1.3.2.2 2000/10/17 18:40:10 gson Exp $ */
#include <config.h>
#include <isc/socket.h>
#include <isc/string.h> /* Required for HP/UX (and others?) */
#include <isc/util.h>
#include <dns/adb.h>
#include <dns/byaddr.h>
#include <dns/result.h>
#include <named/types.h>
#include <named/lwdclient.h>
static void start_byaddr(ns_lwdclient_t *);
static void
byaddr_done(isc_task_t *task, isc_event_t *event) {
ns_lwdclient_t *client;
ns_lwdclientmgr_t *cm;
dns_byaddrevent_t *bevent;
int lwres;
lwres_buffer_t lwb;
dns_name_t *name;
isc_result_t result;
lwres_result_t lwresult;
isc_region_t r;
isc_buffer_t b;
lwres_gnbaresponse_t *gnba;
isc_uint16_t naliases;
isc_stdtime_t now;
UNUSED(task);
lwb.base = NULL;
client = event->ev_arg;
cm = client->clientmgr;
INSIST(client->byaddr == (dns_byaddr_t *)event->ev_sender);
bevent = (dns_byaddrevent_t *)event;
gnba = &client->gnba;
ns_lwdclient_log(50, "byaddr event result = %s",
isc_result_totext(bevent->result));
result = bevent->result;
if (result != ISC_R_SUCCESS) {
dns_byaddr_destroy(&client->byaddr);
isc_event_free(&event);
bevent = NULL;
/*
* Were we trying bitstring or nibble mode? If bitstring,
* and we got FORMERROR or SERVFAIL, set the flag to
* avoid bitstring labels for 10 minutes. If we got any
* other error (NXDOMAIN, etc) just try again without
* bitstrings, and let our cache handle the negative answer
* for bitstrings.
*/
if ((client->options & DNS_BYADDROPT_IPV6NIBBLE) != 0) {
dns_adb_freeaddrinfo(cm->view->adb, &client->addrinfo);
if (result == DNS_R_NCACHENXDOMAIN ||
result == DNS_R_NCACHENXRRSET ||
result == DNS_R_NXDOMAIN ||
result == DNS_R_NXRRSET)
lwresult = LWRES_R_NOTFOUND;
else
lwresult = LWRES_R_FAILURE;
ns_lwdclient_errorpktsend(client, lwresult);
return;
}
isc_stdtime_get(&now);
if (result == DNS_R_FORMERR ||
result == DNS_R_SERVFAIL ||
result == ISC_R_FAILURE)
dns_adb_setavoidbitstring(cm->view->adb,
client->addrinfo, now + 600);
/*
* Fall back to nibble reverse if the default of bitstrings
* fails.
*/
client->options |= DNS_BYADDROPT_IPV6NIBBLE;
start_byaddr(client);
return;
}
name = ISC_LIST_HEAD(bevent->names);
while (name != NULL) {
b = client->recv_buffer;
result = dns_name_totext(name, ISC_TRUE, &client->recv_buffer);
if (result != ISC_R_SUCCESS)
goto out;
ns_lwdclient_log(50, "found name '%.*s'",
client->recv_buffer.used - b.used,
(char *)(b.base) + b.used);
if (gnba->realname == NULL) {
gnba->realname = (char *)(b.base) + b.used;
gnba->realnamelen = client->recv_buffer.used - b.used;
} else {
naliases = gnba->naliases;
if (naliases >= LWRES_MAX_ALIASES)
break;
gnba->aliases[naliases] = (char *)(b.base) + b.used;
gnba->aliaslen[naliases] =
client->recv_buffer.used - b.used;
gnba->naliases++;
}
name = ISC_LIST_NEXT(name, link);
}
dns_byaddr_destroy(&client->byaddr);
dns_adb_freeaddrinfo(cm->view->adb, &client->addrinfo);
isc_event_free(&event);
/*
* Render the packet.
*/
client->pkt.recvlength = LWRES_RECVLENGTH;
client->pkt.authtype = 0; /* XXXMLG */
client->pkt.authlength = 0;
client->pkt.result = LWRES_R_SUCCESS;
lwres = lwres_gnbaresponse_render(cm->lwctx,
gnba, &client->pkt, &lwb);
if (lwres != LWRES_R_SUCCESS)
goto out;
r.base = lwb.base;
r.length = lwb.used;
client->sendbuf = r.base;
client->sendlength = r.length;
result = isc_socket_sendto(cm->sock, &r,
cm->task, ns_lwdclient_send,
client, &client->address, NULL);
if (result != ISC_R_SUCCESS)
goto out;
NS_LWDCLIENT_SETSEND(client);
return;
out:
if (client->byaddr != NULL)
dns_byaddr_destroy(&client->byaddr);
if (client->addrinfo != NULL)
dns_adb_freeaddrinfo(cm->view->adb, &client->addrinfo);
if (lwb.base != NULL)
lwres_context_freemem(cm->lwctx,
lwb.base, lwb.length);
if (event != NULL)
isc_event_free(&event);
}
static void
start_byaddr(ns_lwdclient_t *client) {
isc_result_t result;
ns_lwdclientmgr_t *cm;
cm = client->clientmgr;
INSIST(client->byaddr == NULL);
result = dns_byaddr_create(cm->mctx, &client->na, cm->view,
client->options, cm->task, byaddr_done,
client, &client->byaddr);
if (result != ISC_R_SUCCESS) {
dns_adb_freeaddrinfo(cm->view->adb, &client->addrinfo);
ns_lwdclient_errorpktsend(client, LWRES_R_FAILURE);
return;
}
}
static void
init_gnba(ns_lwdclient_t *client) {
int i;
/*
* Initialize the real name and alias arrays in the reply we're
* going to build up.
*/
for (i = 0 ; i < LWRES_MAX_ALIASES ; i++) {
client->aliases[i] = NULL;
client->aliaslen[i] = 0;
}
for (i = 0 ; i < LWRES_MAX_ADDRS ; i++) {
client->addrs[i].family = 0;
client->addrs[i].length = 0;
memset(client->addrs[i].address, 0, LWRES_ADDR_MAXLEN);
LWRES_LINK_INIT(&client->addrs[i], link);
}
client->gnba.naliases = 0;
client->gnba.realname = NULL;
client->gnba.aliases = client->aliases;
client->gnba.realnamelen = 0;
client->gnba.aliaslen = client->aliaslen;
client->gnba.base = NULL;
client->gnba.baselen = 0;
isc_buffer_init(&client->recv_buffer, client->buffer, LWRES_RECVLENGTH);
}
void
ns_lwdclient_processgnba(ns_lwdclient_t *client, lwres_buffer_t *b) {
lwres_gnbarequest_t *req;
isc_result_t result;
isc_sockaddr_t sa;
ns_lwdclientmgr_t *cm;
REQUIRE(NS_LWDCLIENT_ISRECVDONE(client));
INSIST(client->byaddr == NULL);
cm = client->clientmgr;
req = NULL;
result = lwres_gnbarequest_parse(cm->lwctx,
b, &client->pkt, &req);
if (result != LWRES_R_SUCCESS)
goto out;
if (req->addr.address == NULL)
goto out;
client->options = 0;
if (req->addr.family == LWRES_ADDRTYPE_V4) {
client->na.family = AF_INET;
if (req->addr.length != 4)
goto out;
memcpy(&client->na.type.in, req->addr.address, 4);
} else if (req->addr.family == LWRES_ADDRTYPE_V6) {
client->na.family = AF_INET6;
if (req->addr.length != 16)
goto out;
memcpy(&client->na.type.in6, req->addr.address, 16);
} else {
goto out;
}
isc_sockaddr_fromnetaddr(&sa, &client->na, 53);
ns_lwdclient_log(50, "client %p looking for addrtype %08x",
client, req->addr.family);
/*
* We no longer need to keep this around.
*/
lwres_gnbarequest_free(cm->lwctx, &req);
/*
* Initialize the real name and alias arrays in the reply we're
* going to build up.
*/
init_gnba(client);
client->options = 0;
/*
* See if we should skip the byaddr bit.
*/
INSIST(client->addrinfo == NULL);
result = dns_adb_findaddrinfo(cm->view->adb, &sa,
&client->addrinfo, 0);
if (result != ISC_R_SUCCESS)
goto out;
if (client->addrinfo->avoid_bitstring > 0)
client->options |= DNS_BYADDROPT_IPV6NIBBLE;
/*
* Start the find.
*/
start_byaddr(client);
return;
/*
* We're screwed. Return an error packet to our caller.
*/
out:
if (req != NULL)
lwres_gnbarequest_free(cm->lwctx, &req);
ns_lwdclient_errorpktsend(client, LWRES_R_FAILURE);
}

View File

@@ -1,88 +0,0 @@
/*
* Copyright (C) 2000 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: lwdnoop.c,v 1.2 2000/06/22 21:49:29 tale Exp $ */
#include <config.h>
#include <isc/socket.h>
#include <isc/util.h>
#include <named/types.h>
#include <named/lwdclient.h>
void
ns_lwdclient_processnoop(ns_lwdclient_t *client, lwres_buffer_t *b) {
lwres_nooprequest_t *req;
lwres_noopresponse_t resp;
isc_result_t result;
lwres_result_t lwres;
isc_region_t r;
lwres_buffer_t lwb;
REQUIRE(NS_LWDCLIENT_ISRECVDONE(client));
INSIST(client->byaddr == NULL);
req = NULL;
result = lwres_nooprequest_parse(client->clientmgr->lwctx,
b, &client->pkt, &req);
if (result != LWRES_R_SUCCESS)
goto out;
client->pkt.recvlength = LWRES_RECVLENGTH;
client->pkt.authtype = 0; /* XXXMLG */
client->pkt.authlength = 0;
client->pkt.result = LWRES_R_SUCCESS;
resp.datalength = req->datalength;
resp.data = req->data;
lwres = lwres_noopresponse_render(client->clientmgr->lwctx, &resp,
&client->pkt, &lwb);
if (lwres != LWRES_R_SUCCESS)
goto out;
r.base = lwb.base;
r.length = lwb.used;
client->sendbuf = r.base;
client->sendlength = r.length;
result = isc_socket_sendto(client->clientmgr->sock, &r,
client->clientmgr->task, ns_lwdclient_send,
client, &client->address, NULL);
if (result != ISC_R_SUCCESS)
goto out;
/*
* We can now destroy request.
*/
lwres_nooprequest_free(client->clientmgr->lwctx, &req);
NS_LWDCLIENT_SETSEND(client);
return;
out:
if (req != NULL)
lwres_nooprequest_free(client->clientmgr->lwctx, &req);
if (lwb.base != NULL)
lwres_context_freemem(client->clientmgr->lwctx,
lwb.base, lwb.length);
ns_lwdclient_errorpktsend(client, LWRES_R_FAILURE);
}

View File

@@ -1,450 +0,0 @@
/*
* Copyright (C) 2000 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: lwresd.c,v 1.8.2.3 2000/07/21 22:46:47 gson Exp $ */
/*
* Main program for the Lightweight Resolver Daemon.
*
* To paraphrase the old saying about X11, "It's not a lightweight deamon
* for resolvers, it's a deamon for lightweight resolvers".
*/
#include <config.h>
#include <stdlib.h>
#include <isc/app.h>
#include <isc/magic.h>
#include <isc/mem.h>
#include <isc/print.h>
#include <isc/string.h>
#include <isc/task.h>
#include <isc/timer.h>
#include <isc/util.h>
#include <dns/cache.h>
#include <dns/db.h>
#include <dns/dispatch.h>
#include <dns/log.h>
#include <dns/resolver.h>
#include <dns/result.h>
#include <dns/rootns.h>
#include <dns/view.h>
#include <named/globals.h>
#include <named/log.h>
#include <named/lwresd.h>
#include <named/lwdclient.h>
#include <named/server.h>
#include <named/os.h>
#define LWRESD_MAGIC ISC_MAGIC('L', 'W', 'R', 'D')
#define VALID_LWRESD(l) ISC_MAGIC_VALID(l, LWRESD_MAGIC)
/*
* The goal number of clients we can handle will be NTASKS * NRECVS.
*/
#define NTASKS 20 /* tasks to create to handle lwres queries */
#define NRECVS 5 /* max clients per task */
#define NTHREADS 1 /* # threads to create in thread manager */
static void
fatal(const char *msg, isc_result_t result) {
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_LWRESD,
ISC_LOG_CRITICAL, "%s: %s", msg,
isc_result_totext(result));
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_LWRESD,
ISC_LOG_CRITICAL, "exiting (due to fatal error)");
exit(1);
}
/*
* Wrappers around our memory management stuff, for the lwres functions.
*/
static void *
mem_alloc(void *arg, size_t size) {
return (isc_mem_get(arg, size));
}
static void
mem_free(void *arg, void *mem, size_t size) {
isc_mem_put(arg, mem, size);
}
static void
shutdown_lwresd(isc_task_t *task, isc_event_t *event) {
ns_lwresd_t *lwresd = event->ev_arg;
UNUSED(task);
dns_dispatchmgr_destroy(&lwresd->dispmgr);
/*
* Wait for everything to die off by waiting for the sockets
* to be detached.
*/
isc_socket_detach(&lwresd->sock);
/*
* Kill off the view.
*/
dns_view_detach(&lwresd->view);
isc_task_detach(&lwresd->task);
isc_event_free(&event);
}
static void
parse_resolv_conf(isc_mem_t *mctx, isc_sockaddrlist_t *forwarders) {
lwres_context_t *lwctx;
lwres_conf_t *lwc;
int lwresult;
struct in_addr ina;
struct in6_addr ina6;
isc_sockaddr_t *sa;
int i;
in_port_t port;
lwctx = NULL;
lwresult = lwres_context_create(&lwctx, mctx, mem_alloc, mem_free,
LWRES_CONTEXT_SERVERMODE);
if (lwresult != LWRES_R_SUCCESS)
return;
lwresult = lwres_conf_parse(lwctx, lwresd_g_conffile);
if (lwresult != LWRES_R_SUCCESS)
goto out;
lwc = lwres_conf_get(lwctx);
INSIST(lwc != NULL);
if (lwresd_g_queryport == 0)
port = 53;
else
port = lwresd_g_queryport;
/*
* Run through the list of nameservers, and set them to be our
* forwarders.
*/
for (i = 0 ; i < lwc->nsnext ; i++) {
switch (lwc->nameservers[i].family) {
case LWRES_ADDRTYPE_V4:
sa = isc_mem_get(mctx, sizeof *sa);
INSIST(sa != NULL);
memcpy(&ina.s_addr, lwc->nameservers[i].address, 4);
isc_sockaddr_fromin(sa, &ina, port);
ISC_LIST_APPEND(*forwarders, sa, link);
sa = NULL;
break;
case LWRES_ADDRTYPE_V6:
sa = isc_mem_get(mctx, sizeof *sa);
INSIST(sa != NULL);
memcpy(&ina6.s6_addr, lwc->nameservers[i].address, 16);
isc_sockaddr_fromin6(sa, &ina6, port);
ISC_LIST_APPEND(*forwarders, sa, link);
sa = NULL;
break;
default:
break;
}
}
out:
lwres_conf_clear(lwctx);
lwres_context_destroy(&lwctx);
}
static isc_result_t
ns_lwresd_createview(ns_lwresd_t *lwresd, dns_view_t **viewp) {
dns_cache_t *cache;
isc_result_t result;
dns_db_t *rootdb;
unsigned int attrs;
isc_sockaddr_t any4, any6;
dns_dispatch_t *disp4 = NULL;
dns_dispatch_t *disp6 = NULL;
isc_sockaddrlist_t forwarders;
dns_view_t *view;
REQUIRE(viewp != NULL && *viewp == NULL);
cache = NULL;
result = dns_dispatchmgr_create(lwresd->mctx, ns_g_entropy,
&lwresd->dispmgr);
if (result != ISC_R_SUCCESS)
fatal("creating dispatch manager", result);
/*
* View.
*/
view = NULL;
result = dns_view_create(lwresd->mctx, dns_rdataclass_in, "_default",
&view);
if (result != ISC_R_SUCCESS)
return (result);
/*
* Cache.
*/
result = dns_cache_create(lwresd->mctx, ns_g_taskmgr, ns_g_timermgr,
dns_rdataclass_in, "rbt", 0, NULL, &cache);
if (result != ISC_R_SUCCESS)
goto out;
dns_view_setcache(view, cache);
dns_cache_detach(&cache);
/*
* Resolver.
*
* XXXMLG hardwired number of tasks.
*/
if (isc_net_probeipv6() == ISC_R_SUCCESS) {
isc_sockaddr_any6(&any6);
attrs = DNS_DISPATCHATTR_IPV6 | DNS_DISPATCHATTR_UDP;
result = dns_dispatch_getudp(lwresd->dispmgr, ns_g_socketmgr,
ns_g_taskmgr, &any6, 512, 6, 1024,
17, 19, attrs, attrs, &disp6);
if (result != ISC_R_SUCCESS)
goto out;
}
if (isc_net_probeipv4() == ISC_R_SUCCESS) {
isc_sockaddr_any(&any4);
attrs = DNS_DISPATCHATTR_IPV4 | DNS_DISPATCHATTR_UDP;
result = dns_dispatch_getudp(lwresd->dispmgr, ns_g_socketmgr,
ns_g_taskmgr, &any4, 512, 6, 1024,
17, 19, attrs, attrs, &disp4);
if (result != ISC_R_SUCCESS)
goto out;
}
if (disp4 == NULL && disp6 == NULL)
fatal("not listening on IPv4 or IPv6", ISC_R_FAILURE);
result = dns_view_createresolver(view, ns_g_taskmgr, 16,
ns_g_socketmgr, ns_g_timermgr, 0,
lwresd->dispmgr, disp4, disp6);
if (disp4 != NULL)
dns_dispatch_detach(&disp4);
if (disp6 != NULL)
dns_dispatch_detach(&disp6);
if (result != ISC_R_SUCCESS)
goto out;
rootdb = NULL;
result = dns_rootns_create(lwresd->mctx, dns_rdataclass_in, NULL,
&rootdb);
if (result != ISC_R_SUCCESS)
goto out;
dns_view_sethints(view, rootdb);
dns_db_detach(&rootdb);
/*
* If we have forwarders, set them here.
*/
ISC_LIST_INIT(forwarders);
parse_resolv_conf(lwresd->mctx, &forwarders);
if (ISC_LIST_HEAD(forwarders) != NULL) {
isc_sockaddr_t *sa;
dns_resolver_setforwarders(view->resolver, &forwarders);
dns_resolver_setfwdpolicy(view->resolver, dns_fwdpolicy_only);
sa = ISC_LIST_HEAD(forwarders);
while (sa != NULL) {
ISC_LIST_UNLINK(forwarders, sa, link);
isc_mem_put(lwresd->mctx, sa, sizeof (*sa));
sa = ISC_LIST_HEAD(forwarders);
}
}
dns_view_freeze(view);
*viewp = view;
return (ISC_R_SUCCESS);
out:
dns_view_detach(&view);
return (result);
}
void
ns_lwresd_create(isc_mem_t *mctx, dns_view_t *view, ns_lwresd_t **lwresdp) {
ns_lwresd_t *lwresd;
isc_sockaddr_t localhost;
struct in_addr lh_addr;
unsigned int i, j;
ns_lwdclient_t *client;
isc_socket_t *sock;
isc_result_t result;
sock = NULL;
result = isc_socket_create(ns_g_socketmgr, AF_INET, isc_sockettype_udp,
&sock);
if (result != ISC_R_SUCCESS)
fatal("failed to create socket", result);
lh_addr.s_addr = htonl(INADDR_LOOPBACK);
if (ns_g_port != 0)
lwres_udp_port = ns_g_port;
isc_sockaddr_fromin(&localhost, &lh_addr, lwres_udp_port);
result = isc_socket_bind(sock, &localhost);
if (result != ISC_R_SUCCESS) {
isc_socket_detach(&sock);
fatal("failed to bind lwresd protocol socket", result);
}
ns_os_writepidfile(lwresd_g_defaultpidfile);
lwresd = isc_mem_get(mctx, sizeof(*lwresd));
if (lwresd == NULL)
fatal("allocating lightweight resolver object", ISC_R_NOMEMORY);
lwresd->mctx = NULL;
isc_mem_attach(mctx, &lwresd->mctx);
lwresd->sock = sock;
lwresd->view = NULL;
lwresd->dispmgr = NULL;
if (view != NULL)
dns_view_attach(view, &lwresd->view);
else {
result = ns_lwresd_createview(lwresd, &lwresd->view);
if (result != ISC_R_SUCCESS)
fatal("failed to create default view", result);
}
lwresd->task = NULL;
result = isc_task_create(ns_g_taskmgr, 0, &lwresd->task);
if (result != ISC_R_SUCCESS)
fatal("allocating lightweight resolver task", result);
isc_task_setname(lwresd->task, "lwresd", lwresd);
result = isc_task_onshutdown(lwresd->task, shutdown_lwresd, lwresd);
if (result != ISC_R_SUCCESS)
fatal("allocating lwresd onshutdown event", result);
lwresd->cmgr = isc_mem_get(lwresd->mctx,
sizeof(ns_lwdclientmgr_t) * NTASKS);
if (lwresd->cmgr == NULL)
fatal("allocating lwresd client manager", ISC_R_NOMEMORY);
/*
* Create one task for each client manager.
*/
for (i = 0 ; i < NTASKS ; i++) {
char name[16];
lwresd->cmgr[i].task = NULL;
lwresd->cmgr[i].sock = NULL;
isc_socket_attach(lwresd->sock, &lwresd->cmgr[i].sock);
lwresd->cmgr[i].view = NULL;
lwresd->cmgr[i].flags = 0;
result = isc_task_create(ns_g_taskmgr, 0,
&lwresd->cmgr[i].task);
if (result != ISC_R_SUCCESS)
break;
result = isc_task_onshutdown(lwresd->cmgr[i].task,
ns_lwdclient_shutdown,
&lwresd->cmgr[i]);
if (result != ISC_R_SUCCESS)
break;
ISC_LIST_INIT(lwresd->cmgr[i].idle);
ISC_LIST_INIT(lwresd->cmgr[i].running);
snprintf(name, sizeof(name), "lwd client %d", i);
isc_task_setname(lwresd->cmgr[i].task, name, &lwresd->cmgr[i]);
lwresd->cmgr[i].mctx = lwresd->mctx;
lwresd->cmgr[i].lwctx = NULL;
result = lwres_context_create(&lwresd->cmgr[i].lwctx,
lwresd->mctx,
mem_alloc, mem_free,
LWRES_CONTEXT_SERVERMODE);
if (result != ISC_R_SUCCESS) {
isc_task_detach(&lwresd->cmgr[i].task);
break;
}
dns_view_attach(lwresd->view, &lwresd->cmgr[i].view);
}
INSIST(i > 0);
lwresd->ntasks = i; /* remember how many we managed to create */
/*
* Now, run through each client manager and populate it with
* client structures. Do this by creating one receive for each
* task, in a loop, so each task has a chance of getting at least
* one client structure.
*/
for (i = 0 ; i < NRECVS ; i++) {
client = isc_mem_get(lwresd->mctx,
sizeof(ns_lwdclient_t) * lwresd->ntasks);
if (client == NULL)
break;
for (j = 0 ; j < lwresd->ntasks ; j++)
ns_lwdclient_initialize(&client[j], &lwresd->cmgr[j]);
}
INSIST(i > 0);
/*
* Issue one read request for each task we have.
*/
for (j = 0 ; j < lwresd->ntasks ; j++) {
result = ns_lwdclient_startrecv(&lwresd->cmgr[j]);
INSIST(result == ISC_R_SUCCESS);
}
lwresd->magic = LWRESD_MAGIC;
*lwresdp = lwresd;
}
void
ns_lwresd_destroy(ns_lwresd_t **lwresdp) {
ns_lwresd_t *lwresd;
ns_lwdclient_t *client;
isc_mem_t *mctx;
REQUIRE(lwresdp != NULL);
lwresd = *lwresdp;
REQUIRE(VALID_LWRESD(lwresd));
mctx = lwresd->mctx;
/*
* Free up memory allocated. This is somewhat magical. We allocated
* the ns_lwdclient_t's in blocks, but the first task always has the
* first pointer. Just loop here, freeing them.
*/
client = ISC_LIST_HEAD(lwresd->cmgr[0].idle);
while (client != NULL) {
ISC_LIST_UNLINK(lwresd->cmgr[0].idle, client, link);
isc_mem_put(mctx, client,
sizeof(ns_lwdclient_t) * lwresd->ntasks);
client = ISC_LIST_HEAD(lwresd->cmgr[0].idle);
}
INSIST(ISC_LIST_EMPTY(lwresd->cmgr[0].running));
isc_mem_put(mctx, lwresd->cmgr, sizeof(ns_lwdclientmgr_t) * NTASKS);
lwresd->magic = 0;
isc_mem_put(mctx, lwresd, sizeof(*lwresd));
isc_mem_detach(&mctx);
*lwresdp = NULL;
}

View File

@@ -1,536 +0,0 @@
/*
* Copyright (C) 1999, 2000 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: main.c,v 1.71.2.2 2000/07/11 17:23:02 gson Exp $ */
#include <config.h>
#include <stdlib.h>
#include <string.h>
#include <isc/app.h>
#include <isc/commandline.h>
#include <isc/entropy.h>
#include <isc/os.h>
#include <isc/task.h>
#include <isc/timer.h>
#include <isc/util.h>
#include <dns/dispatch.h>
#include <dst/result.h>
#include <dns/view.h>
/*
* Defining NS_MAIN provides storage declaratons (rather than extern)
* for variables in named/globals.h.
*/
#define NS_MAIN 1
#include <named/globals.h> /* Explicit, though named/log.h includes it. */
#include <named/interfacemgr.h>
#include <named/log.h>
#include <named/omapi.h>
#include <named/os.h>
#include <named/server.h>
#include <named/lwresd.h>
#include <named/main.h>
static isc_boolean_t want_stats = ISC_FALSE;
static isc_boolean_t lwresd_only = ISC_FALSE;
static const char * program_name = "named";
void
ns_main_earlyfatal(const char *format, ...) {
va_list args;
va_start(args, format);
if (ns_g_lctx != NULL) {
isc_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
format, args);
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
"exiting (due to early fatal error)");
} else {
fprintf(stderr, "%s: ", program_name);
vfprintf(stderr, format, args);
fprintf(stderr, "\n");
fflush(stderr);
}
va_end(args);
exit(1);
}
static void
assertion_failed(const char *file, int line, isc_assertiontype_t type,
const char *cond)
{
/*
* Handle assertion failures.
*/
if (ns_g_lctx != NULL) {
/*
* Reset the assetion callback in case it is the log
* routines causing the assertion.
*/
isc_assertion_setcallback(NULL);
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
"%s:%d: %s(%s) failed", file, line,
isc_assertion_typetotext(type), cond);
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
"exiting (due assertion failure)");
} else {
fprintf(stderr, "%s:%d: %s(%s) failed\n",
file, line, isc_assertion_typetotext(type), cond);
fflush(stderr);
}
if (ns_g_coreok)
abort();
exit(1);
}
static void
library_fatal_error(const char *file, int line, const char *format,
va_list args)
{
/*
* Handle isc_error_fatal() calls from our libraries.
*/
if (ns_g_lctx != NULL) {
/*
* Reset the error callback in case it is the log
* routines causing the assertion.
*/
isc_error_setfatal(NULL);
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
"%s:%d: fatal error:", file, line);
isc_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
format, args);
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
"exiting (due to fatal error in library)");
} else {
fprintf(stderr, "%s:%d: fatal error: ", file, line);
vfprintf(stderr, format, args);
fprintf(stderr, "\n");
fflush(stderr);
}
if (ns_g_coreok)
abort();
exit(1);
}
static void
library_unexpected_error(const char *file, int line, const char *format,
va_list args)
{
/*
* Handle isc_error_unexpected() calls from our libraries.
*/
if (ns_g_lctx != NULL) {
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_MAIN, ISC_LOG_ERROR,
"%s:%d: unexpected error:", file, line);
isc_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_MAIN, ISC_LOG_ERROR,
format, args);
} else {
fprintf(stderr, "%s:%d: fatal error: ", file, line);
vfprintf(stderr, format, args);
fprintf(stderr, "\n");
fflush(stderr);
}
}
static void
lwresd_usage(void) {
fprintf(stderr,
"usage: lwresd [-C conffile] [-d debuglevel] "
"[-f|-g] [-n number_of_cpus]\n"
" [-p listen-port] [-P query-port] [-s] "
"[-t chrootdir] [-u username] [-i pidfile]\n");
}
static void
usage(void) {
fprintf(stderr,
"usage: named [-c conffile] [-d debuglevel] "
"[-f|-g] [-n number_of_cpus]\n"
" [-p port] [-s] [-t chrootdir] [-u username]\n");
}
static void
parse_lwresd_command_line(int argc, char *argv[]) {
int ch;
unsigned int port;
isc_commandline_errprint = ISC_FALSE;
while ((ch = isc_commandline_parse(argc, argv,
"C:d:fgi:n:p:P:st:u:")) !=
-1) {
switch (ch) {
case 'C':
lwresd_g_conffile = isc_commandline_argument;
break;
case 'd':
ns_g_debuglevel = atoi(isc_commandline_argument);
break;
case 'f':
ns_g_foreground = ISC_TRUE;
break;
case 'g':
ns_g_foreground = ISC_TRUE;
ns_g_logstderr = ISC_TRUE;
break;
case 'i':
lwresd_g_defaultpidfile = isc_commandline_argument;
break;
case 'n':
ns_g_cpus = atoi(isc_commandline_argument);
if (ns_g_cpus == 0)
ns_g_cpus = 1;
break;
case 'p':
port = atoi(isc_commandline_argument);
if (port < 1 || port > 65535)
ns_main_earlyfatal("port '%s' out of range",
isc_commandline_argument);
ns_g_port = port;
break;
case 'P':
port = atoi(isc_commandline_argument);
if (port < 1 || port > 65535)
ns_main_earlyfatal("port '%s' out of range",
isc_commandline_argument);
lwresd_g_queryport = port;
break;
case 's':
/* XXXRTH temporary syntax */
want_stats = ISC_TRUE;
break;
case 't':
/* XXXJAB should we make a copy? */
ns_g_chrootdir = isc_commandline_argument;
break;
case 'u':
ns_g_username = isc_commandline_argument;
break;
case '?':
lwresd_usage();
ns_main_earlyfatal("unknown option '-%c'",
isc_commandline_option);
default:
ns_main_earlyfatal("parsing options returned %d", ch);
}
}
argc -= isc_commandline_index;
argv += isc_commandline_index;
if (argc > 0) {
lwresd_usage();
ns_main_earlyfatal("extra command line arguments");
}
}
static void
parse_command_line(int argc, char *argv[]) {
int ch;
unsigned int port;
char *s;
s = strrchr(argv[0], '/');
if (s == NULL)
s = argv[0];
else
s++;
if (strcmp(s, "lwresd") == 0) {
lwresd_only = ISC_TRUE;
parse_lwresd_command_line(argc, argv);
return;
}
isc_commandline_errprint = ISC_FALSE;
while ((ch = isc_commandline_parse(argc, argv,
"c:d:fgn:N:p:st:u:x:")) !=
-1) {
switch (ch) {
case 'c':
ns_g_conffile = isc_commandline_argument;
break;
case 'd':
ns_g_debuglevel = atoi(isc_commandline_argument);
break;
case 'f':
ns_g_foreground = ISC_TRUE;
break;
case 'g':
ns_g_foreground = ISC_TRUE;
ns_g_logstderr = ISC_TRUE;
break;
case 'N': /* Deprecated. */
case 'n':
ns_g_cpus = atoi(isc_commandline_argument);
if (ns_g_cpus == 0)
ns_g_cpus = 1;
break;
case 'p':
port = atoi(isc_commandline_argument);
if (port < 1 || port > 65535)
ns_main_earlyfatal("port '%s' out of range",
isc_commandline_argument);
ns_g_port = port;
break;
case 's':
/* XXXRTH temporary syntax */
want_stats = ISC_TRUE;
break;
case 't':
/* XXXJAB should we make a copy? */
ns_g_chrootdir = isc_commandline_argument;
break;
case 'u':
ns_g_username = isc_commandline_argument;
break;
case 'x':
/* XXXRTH temporary syntax */
ns_g_cachefile = isc_commandline_argument;
break;
case '?':
usage();
ns_main_earlyfatal("unknown option '-%c'",
isc_commandline_option);
default:
ns_main_earlyfatal("parsing options returned %d", ch);
}
}
argc -= isc_commandline_index;
argv += isc_commandline_index;
if (argc > 0) {
usage();
ns_main_earlyfatal("extra command line arguments");
}
}
static isc_result_t
create_managers(void) {
isc_result_t result;
if (ns_g_cpus == 0)
ns_g_cpus = isc_os_ncpus();
result = isc_taskmgr_create(ns_g_mctx, ns_g_cpus, 0, &ns_g_taskmgr);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"ns_taskmgr_create() failed: %s",
isc_result_totext(result));
return (ISC_R_UNEXPECTED);
}
result = isc_timermgr_create(ns_g_mctx, &ns_g_timermgr);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"ns_timermgr_create() failed: %s",
isc_result_totext(result));
return (ISC_R_UNEXPECTED);
}
result = isc_socketmgr_create(ns_g_mctx, &ns_g_socketmgr);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_socketmgr_create() failed: %s",
isc_result_totext(result));
return (ISC_R_UNEXPECTED);
}
result = isc_entropy_create(ns_g_mctx, &ns_g_entropy);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_entropy_create() failed: %s",
isc_result_totext(result));
return (ISC_R_UNEXPECTED);
}
(void)isc_entropy_createfilesource(ns_g_entropy, "/dev/random");
return (ISC_R_SUCCESS);
}
static void
destroy_managers(void) {
if (!lwresd_only)
/*
* The omapi listeners need to be stopped here so that
* isc_taskmgr_destroy() won't block on the omapi task.
*/
ns_omapi_shutdown(ISC_TRUE);
isc_entropy_detach(&ns_g_entropy);
/*
* isc_taskmgr_destroy() will block until all tasks have exited,
*/
isc_taskmgr_destroy(&ns_g_taskmgr);
isc_timermgr_destroy(&ns_g_timermgr);
isc_socketmgr_destroy(&ns_g_socketmgr);
}
static void
setup(void) {
isc_result_t result;
/*
* Get the user and group information before changing the root
* directory, so the administrator does not need to keep a copy
* of the user and group databases in the chroot'ed environment.
*/
ns_os_inituserinfo(ns_g_username);
ns_os_chroot(ns_g_chrootdir);
/*
* For operating systems which have a capability mechanism, now
* is the time to switch to minimal privs and change our user id.
* On traditional UNIX systems, this call will be a no-op, and we
* will change the user ID after reading the config file the first
* time. (We need to read the config file to know which possibly
* privileged ports to bind() to.)
*/
ns_os_minprivs();
result = ns_log_init(ISC_TF(ns_g_username != NULL));
if (result != ISC_R_SUCCESS)
ns_main_earlyfatal("ns_log_init() failed: %s",
isc_result_totext(result));
/*
* Now is the time to daemonize (if we're not running in the
* foreground). We waited until now because we wanted to get
* a valid logging context setup. We cannot daemonize any later,
* because calling create_managers() will create threads, which
* would be lost after fork().
*/
if (!ns_g_foreground)
ns_os_daemonize();
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
ISC_LOG_NOTICE, "starting BIND %s", ns_g_version);
result = create_managers();
if (result != ISC_R_SUCCESS)
ns_main_earlyfatal("create_managers() failed: %s",
isc_result_totext(result));
if (lwresd_only)
ns_lwresd_create(ns_g_mctx, NULL, &ns_g_lwresd);
else
ns_server_create(ns_g_mctx, &ns_g_server);
if (!lwresd_only) {
result = ns_omapi_init();
if (result != ISC_R_SUCCESS)
ns_main_earlyfatal("ns_omapi_init() failed: %s",
isc_result_totext(result));
}
}
static void
cleanup(void) {
destroy_managers();
if (lwresd_only)
ns_lwresd_destroy(&ns_g_lwresd);
else
ns_server_destroy(&ns_g_server);
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
ISC_LOG_NOTICE, "exiting");
ns_log_shutdown();
}
int
main(int argc, char *argv[]) {
isc_result_t result;
program_name = argv[0];
isc_assertion_setcallback(assertion_failed);
isc_error_setfatal(library_fatal_error);
isc_error_setunexpected(library_unexpected_error);
ns_os_init();
result = isc_app_start();
if (result != ISC_R_SUCCESS)
ns_main_earlyfatal("isc_app_start() failed: %s",
isc_result_totext(result));
result = isc_mem_create(0, 0, &ns_g_mctx);
if (result != ISC_R_SUCCESS)
ns_main_earlyfatal("isc_mem_create() failed: %s",
isc_result_totext(result));
dns_result_register();
dst_result_register();
parse_command_line(argc, argv);
setup();
/*
* Start things running and then wait for a shutdown request
* or reload.
*/
do {
result = isc_app_run();
if (result == ISC_R_RELOAD) {
ns_server_reloadwanted(ns_g_server);
} else if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_app_run(): %s",
isc_result_totext(result));
/*
* Force exit.
*/
result = ISC_R_SUCCESS;
}
} while (result != ISC_R_SUCCESS);
cleanup();
if (want_stats)
isc_mem_stats(ns_g_mctx, stdout);
isc_mem_destroy(&ns_g_mctx);
isc_app_finish();
ns_os_shutdown();
return (0);
}

View File

@@ -1,28 +0,0 @@
/*
* Copyright (C) 1999, 2000 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: named.conf.test,v 1.3 2000/06/22 21:49:32 tale Exp $ */
options {
directory "/var/named";
};
zone "vix.com" {
type master;
file "whatever";
};

View File

@@ -1,196 +0,0 @@
/*
* Copyright (C) 1999, 2000 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: notify.c,v 1.18 2000/06/23 17:26:36 marka Exp $ */
#include <config.h>
#include <dns/message.h>
#include <dns/rdataset.h>
#include <dns/result.h>
#include <dns/view.h>
#include <dns/zone.h>
#include <dns/zt.h>
#include <named/log.h>
#include <named/notify.h>
/*
* This module implements notify as in RFC 1996.
*/
/**************************************************************************/
/*
* Convenience macro of common isc_log_write() arguments
* to use in reportings server errors.
*/
#define NOTIFY_ERROR_LOGARGS \
ns_g_lctx, DNS_LOGCATEGORY_NOTIFY, NS_LOGMODULE_NOTIFY, \
ISC_LOG_ERROR
/*
* Convenience macro of common isc_log_write() arguments
* to use in tracing notify protocol requests.
*/
#define NOTIFY_PROTOCOL_LOGARGS \
ns_g_lctx, DNS_LOGCATEGORY_NOTIFY, NS_LOGMODULE_NOTIFY, \
ISC_LOG_INFO
/*
* Convenience macro of common isc_log_write() arguments
* to use in low-level debug tracing.
*/
#define NOTIFY_DEBUG_LOGARGS \
ns_g_lctx, DNS_LOGCATEGORY_NOTIFY, NS_LOGMODULE_NOTIFY, \
ISC_LOG_DEBUG(8)
/*
* Check an operation for failure. These macros all assume that
* the function using them has a 'result' variable and a 'failure'
* label.
*/
#define CHECK(op) \
do { result = (op); \
if (result != ISC_R_SUCCESS) goto failure; \
} while (0)
/*
* Fail unconditionally with result 'code', which must not
* be ISC_R_SUCCESS. The reason for failure presumably has
* been logged already.
*
* The test is there to keep the Solaris compiler from complaining
* about "end-of-loop code not reached".
*/
#define FAIL(code) \
do { \
result = (code); \
if (code != ISC_R_SUCCESS) goto failure; \
} while (0)
/*
* Fail unconditionally and log as a client error.
* The test against ISC_R_SUCCESS is there to keep the Solaris compiler
* from complaining about "end-of-loop code not reached".
*/
#define FAILC(code, msg) \
do { \
result = (code); \
isc_log_write(NOTIFY_PROTOCOL_LOGARGS, \
"notify failed: %s (%s)", \
msg, isc_result_totext(code)); \
if (result != ISC_R_SUCCESS) goto failure; \
} while (0)
/*
* Fail unconditionally and log as a server error.
* The test against ISC_R_SUCCESS is there to keep the Solaris compiler
* from complaining about "end-of-loop code not reached".
*/
#define FAILS(code, msg) \
do { \
result = (code); \
isc_log_write(NOTIFY_PROTOCOL_LOGARGS, \
"notify error: %s: %s", \
msg, isc_result_totext(code)); \
if (result != ISC_R_SUCCESS) goto failure; \
} while (0)
/**************************************************************************/
static void
respond(ns_client_t *client, isc_result_t result) {
dns_rcode_t rcode;
dns_message_t *message;
isc_result_t msg_result;
message = client->message;
rcode = dns_result_torcode(result);
msg_result = dns_message_reply(message, ISC_TRUE);
if (msg_result != ISC_R_SUCCESS)
msg_result = dns_message_reply(message, ISC_FALSE);
if (msg_result != ISC_R_SUCCESS) {
ns_client_next(client, msg_result);
return;
}
message->rcode = rcode;
if (rcode == dns_rcode_noerror)
message->flags |= DNS_MESSAGEFLAG_AA;
else
message->flags &= ~DNS_MESSAGEFLAG_AA;
ns_client_send(client);
}
void
ns_notify_start(ns_client_t *client) {
dns_message_t *request = client->message;
isc_result_t result;
dns_name_t *zonename;
dns_rdataset_t *zone_rdataset;
dns_zone_t *zone = NULL;
/*
* Interpret the question section.
*/
result = dns_message_firstname(request, DNS_SECTION_QUESTION);
if (result != ISC_R_SUCCESS)
FAILC(DNS_R_FORMERR,
"notify question section empty");
/*
* The question section must contain exactly one question.
*/
zonename = NULL;
dns_message_currentname(request, DNS_SECTION_QUESTION, &zonename);
zone_rdataset = ISC_LIST_HEAD(zonename->list);
if (ISC_LIST_NEXT(zone_rdataset, link) != NULL)
FAILC(DNS_R_FORMERR,
"notify question section contains multiple RRs");
/* The zone section must have exactly one name. */
result = dns_message_nextname(request, DNS_SECTION_ZONE);
if (result != ISC_R_NOMORE)
FAILC(DNS_R_FORMERR,
"notify question section contains multiple RRs");
result = dns_zt_find(client->view->zonetable, zonename, 0, NULL,
&zone);
if (result != ISC_R_SUCCESS)
FAILC(DNS_R_REFUSED,
"not authoritative for notify zone");
switch(dns_zone_gettype(zone)) {
case dns_zone_master:
case dns_zone_slave:
respond(client, dns_zone_notifyreceive(zone,
ns_client_getsockaddr(client), request));
break;
default:
FAILC(DNS_R_REFUSED,
"not authoritative for notify zone");
}
dns_zone_detach(&zone);
return;
failure:
if (zone != NULL)
dns_zone_detach(&zone);
respond(client, result);
}

View File

@@ -1,171 +0,0 @@
/*
* Copyright (C) 2000 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: omapi.c,v 1.13.2.1 2000/07/11 17:23:04 gson Exp $ */
/*
* Principal Author: DCL
*/
#include <config.h>
#include <isc/event.h>
#include <isc/util.h>
#include <named/log.h>
#include <named/omapi.h>
#include <named/server.h>
/*
* The control_object structure is used for receiving commands that
* request the server to perform some action, but that do not set or
* get any state.
*/
typedef struct control_object {
OMAPI_OBJECT_PREAMBLE;
} control_object_t;
static control_object_t control;
static omapi_objecttype_t *control_type;
#undef REGION_FMT
/*
* Ok, kind of gross. Sorry. A little.
*/
#define REGION_FMT(r) (int)(r)->length, (r)->base
/*
* This is the function that is called when an incoming OMAPI_OP_OPEN
* message is received with either the create or update option set.
* It is called once for each name/value pair in the message's object
* value list.
*/
static isc_result_t
control_setvalue(omapi_object_t *handle, omapi_string_t *name,
omapi_data_t *value)
{
isc_region_t region;
isc_result_t result;
INSIST(handle == (omapi_object_t *)&control);
omapi_string_totext(name, &region);
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_OMAPI, ISC_LOG_DEBUG(1),
"control_setvalue: '%.*s' control command received",
REGION_FMT(&region));
/*
* Compare the 'name' parameter against all known control commands.
*/
if (omapi_string_strcmp(name, NS_OMAPI_COMMAND_RELOAD) == 0) {
if (omapi_data_getint(value) != 0)
ns_server_reloadwanted(ns_g_server);
result = ISC_R_SUCCESS;
} else if (omapi_string_strcmp(name,
NS_OMAPI_COMMAND_RELOADCONFIG) == 0 ||
omapi_string_strcmp(name,
NS_OMAPI_COMMAND_RELOADZONES) == 0) {
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_OMAPI, ISC_LOG_WARNING,
"control_setvalue: '%.*s' not yet implemented",
REGION_FMT(&region));
result = ISC_R_NOTIMPLEMENTED;
} else {
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_OMAPI, ISC_LOG_WARNING,
"control_setvalue: unknown name: '%.*s'",
REGION_FMT(&region));
result = omapi_object_passsetvalue(handle, name, value);
}
return (result);
}
/*
* This is the function that is called by the library's internal
* message_process function when an incoming OMAPI_OP_OPEN message is received.
* It is supposed to look up the object in the server that corresponds to the
* key data (name/value pair(s)) in 'key'.
*/
static isc_result_t
control_lookup(omapi_object_t **control_object, omapi_object_t *key) {
/*
* There is only one control object so no key is needed to look it up.
*/
UNUSED(key);
omapi_object_reference(control_object, (omapi_object_t *)&control);
return (ISC_R_SUCCESS);
}
/*
* This function is called when the server is sending a reply to a client
* that opened an object of its type. It needs to output all published
* name/value pairs for the object, and will typically also put the data
* for any inner objects (but in this program, there will be no inner
* objects). The handle parameter is an object of the type registered
* in ns_omapi_listen.
*/
static isc_result_t
control_stuffvalues(omapi_object_t *connection, omapi_object_t *handle) {
/*
* Currently the server has no values to publish, but it needs
* to publish something for its OMAPI_OP_UPDATE function to work
* when received by the client.
*/
return (omapi_object_passstuffvalues(connection, handle));
}
isc_result_t
ns_omapi_init(void) {
isc_result_t result;
result = omapi_lib_init(ns_g_mctx, ns_g_taskmgr, ns_g_socketmgr);
if (result == ISC_R_SUCCESS)
/*
* Register the control_object. NS_OMAPI_CONTROL is
* what a client would need to specify as a value for
* the value of "type" in a message when contacting
* the server to perform a control function.
*/
result = omapi_object_register(&control_type, NS_OMAPI_CONTROL,
control_setvalue,
NULL, /* getvalue */
NULL, /* destroy */
NULL, /* signalhandler */
control_stuffvalues,
control_lookup,
NULL, /* create */
NULL); /* remove */
if (result == ISC_R_SUCCESS) {
/*
* Initialize the static control object.
*/
control.refcnt = 1;
control.type = control_type;
}
return (result);
}

View File

@@ -1,511 +0,0 @@
/*
* Copyright (C) 2000 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: omapiconf.c,v 1.4.2.6 2000/09/15 16:24:12 gson Exp $ */
/*
* Principal Author: DCL
*/
#include <config.h>
#include <isc/base64.h>
#include <isc/buffer.h>
#include <isc/event.h>
#include <isc/mem.h>
#include <isc/once.h>
#include <isc/string.h>
#include <isc/util.h>
#include <dst/result.h>
#include <named/log.h>
#include <named/omapi.h>
#include <named/server.h>
typedef struct ns_omapilistener ns_omapilistener_t;
typedef ISC_LIST(ns_omapilistener_t) ns_omapilistenerlist_t;
struct ns_omapilistener {
/* XXXDCL magic */
isc_mem_t * mctx;
omapi_object_t * manager;
isc_sockaddr_t address;
dns_acl_t * acl;
dns_c_kidlist_t * keyids;
LINK(ns_omapilistener_t) link;
};
static ns_omapilistenerlist_t listeners;
static isc_mutex_t listeners_lock;
static isc_once_t once = ISC_ONCE_INIT;
static isc_boolean_t server_exiting = ISC_FALSE;
static void
initialize_mutex(void) {
RUNTIME_CHECK(isc_mutex_init(&listeners_lock) == ISC_R_SUCCESS);
}
static void
free_listener(ns_omapilistener_t *listener) {
if (listener->keyids != NULL)
dns_c_kidlist_delete(&listener->keyids);
if (listener->acl != NULL)
dns_acl_detach(&listener->acl);
if (listener->manager != NULL)
omapi_object_dereference(&listener->manager);
isc_mem_put(listener->mctx, listener, sizeof(*listener));
}
static void
listen_done(isc_task_t *task, isc_event_t *event) {
ns_omapilistener_t *listener;
UNUSED(task);
listener = event->ev_arg;
LOCK(&listeners_lock);
ISC_LIST_UNLINK(listeners, listener, link);
free_listener(listener);
if (server_exiting && ISC_LIST_EMPTY(listeners))
omapi_lib_destroy();
UNLOCK(&listeners_lock);
isc_event_free(&event);
}
void
ns_omapi_shutdown(isc_boolean_t exiting) {
ns_omapilistener_t *listener;
RUNTIME_CHECK(isc_once_do(&once, initialize_mutex) == ISC_R_SUCCESS);
if (exiting) {
/*
* When not exiting, this function is called from
* ns_omapi_configure(), which already holds the lock.
*/
LOCK(&listeners_lock);
if (ISC_LIST_EMPTY(listeners))
omapi_lib_destroy();
else
server_exiting = exiting;
}
for (listener = ISC_LIST_HEAD(listeners);
listener != NULL;
listener = ISC_LIST_NEXT(listener, link))
/*
* This is asynchronous. As listeners shut down, they will
* call listen_done().
*/
omapi_listener_shutdown(listener->manager);
if (exiting)
UNLOCK(&listeners_lock);
}
static isc_boolean_t
verify_connection(isc_sockaddr_t *sockaddr, void *arg) {
ns_omapilistener_t *listener;
isc_netaddr_t netaddr;
isc_result_t result;
int match;
isc_netaddr_fromsockaddr(&netaddr, sockaddr);
listener = arg;
result = dns_acl_match(&netaddr, NULL, listener->acl,
&ns_g_server->aclenv, &match, NULL);
if (result != ISC_R_SUCCESS || match <= 0)
return (ISC_FALSE);
else
return (ISC_TRUE);
}
static isc_boolean_t
verify_key(const char *name, unsigned int algorithm, void *arg) {
ns_omapilistener_t *listener;
dns_c_kid_t *keyid = NULL;
/*
* XXXDCL Ideally algorithm would be checked, too, but the current
* config API makes this moderately hard, and omapi will check it
* anyway.
*/
UNUSED(algorithm);
listener = arg;
(void)dns_c_kidlist_find(listener->keyids, name, &keyid);
if (keyid != NULL)
return (ISC_TRUE);
else
return (ISC_FALSE);
}
static isc_result_t
ns_omapi_listen(ns_omapilistener_t *listener) {
isc_result_t result;
REQUIRE(listener->manager == NULL);
/*
* Create a generic object to be the manager for handling
* incoming server connections.
*/
result = omapi_object_create(&listener->manager, NULL, 0);
if (result == ISC_R_SUCCESS)
/*
* Start listening for connections.
*/
result = omapi_protocol_listen(listener->manager,
&listener->address,
verify_connection, verify_key,
listen_done, listener);
if (result != ISC_R_SUCCESS && listener->manager != NULL)
omapi_object_dereference(&listener->manager);
return (result);
}
static void
register_keys(dns_c_ctrl_t *control, dns_c_kdeflist_t *keydeflist,
char *socktext)
{
dns_c_kid_t *keyid;
dns_c_kdef_t *keydef;
char secret[1024];
isc_buffer_t b;
isc_result_t result;
/*
* Register the keys used by this listener. omapi_auth_deregister()
* is used to delete any existing key in case its secret or algorithm
* changed.
*
* XXXDCL but this means a little extra work overall when nothing
* changed. In fact, the same key will be register/deregistered/
* reregistered if it appears more than once in the controls statement.
*
* XXXDCL a separate problem is that keys that have been removed
* from the controls statement in a reconfiguration are not deleted
* until the server shuts down.
*/
for (keyid = ISC_LIST_HEAD(control->keyidlist->keyids);
keyid != NULL;
keyid = ISC_LIST_NEXT(keyid, next)) {
omapi_auth_deregister(keyid->keyid);
/*
* XXXDCL confparser.y apparently allows any keyid
* in the list even if it has not been defined with
* the keys statement.
*/
keydef = NULL;
result = dns_c_kdeflist_find(keydeflist, keyid->keyid,
&keydef);
if (result != ISC_R_SUCCESS)
isc_log_write(ns_g_lctx, ISC_LOGCATEGORY_GENERAL,
NS_LOGMODULE_OMAPI, ISC_LOG_WARNING,
"couldn't find key %s for "
"use with command channel %s",
keyid->keyid, socktext);
else if (strcasecmp(keydef->algorithm, "hmac-md5") != 0) {
isc_log_write(ns_g_lctx, ISC_LOGCATEGORY_GENERAL,
NS_LOGMODULE_OMAPI, ISC_LOG_WARNING,
"unsupported algorithm %s in "
"key %s for use with "
"command channel %s",
keydef->algorithm, keydef->keyid,
socktext);
result = DST_R_UNSUPPORTEDALG;
keydef = NULL; /* Prevent more error messages. */
}
if (result == ISC_R_SUCCESS) {
isc_buffer_init(&b, secret, sizeof(secret));
result = isc_base64_decodestring(ns_g_mctx,
keydef->secret,
&b);
}
if (keydef != NULL && result != ISC_R_SUCCESS) {
isc_log_write(ns_g_lctx, ISC_LOGCATEGORY_GENERAL,
NS_LOGMODULE_OMAPI, ISC_LOG_WARNING,
"can't use secret for key %s on "
"command channel %s: %s",
keydef->keyid, socktext,
isc_result_totext(result));
keydef = NULL; /* Prevent more error messages. */
} else if (result == ISC_R_SUCCESS)
result = omapi_auth_register(keydef->keyid,
OMAPI_AUTH_HMACMD5,
isc_buffer_base(&b),
isc_buffer_usedlength(&b));
if (keydef != NULL && result != ISC_R_SUCCESS)
isc_log_write(ns_g_lctx, ISC_LOGCATEGORY_GENERAL,
NS_LOGMODULE_OMAPI, ISC_LOG_WARNING,
"couldn't register key %s for"
"use with command channel %s: %s",
keydef->keyid, socktext,
isc_result_totext(result));
}
}
static void
update_listener(ns_omapilistener_t **listenerp, dns_c_ctrl_t *control,
dns_c_ctx_t *cctx, dns_aclconfctx_t *aclconfctx,
char *socktext)
{
ns_omapilistener_t *listener;
dns_acl_t *new_acl = NULL;
isc_result_t result;
for (listener = ISC_LIST_HEAD(listeners); listener != NULL;
listener = ISC_LIST_NEXT(listener, link)) {
if (isc_sockaddr_equal(&control->u.inet_v.addr,
&listener->address)) {
/*
* There is already a listener for this sockaddr.
* Update the access list and key information.
*
* First, keep the old access list unless
* a new one can be made.
*/
result = dns_acl_fromconfig(control->
u.inet_v.matchlist,
cctx, aclconfctx,
listener->mctx, &new_acl);
if (result == ISC_R_SUCCESS) {
dns_acl_detach(&listener->acl);
dns_acl_attach(new_acl,
&listener->acl);
dns_acl_detach(&new_acl);
} else
/* XXXDCL say the old acl is still used? */
isc_log_write(ns_g_lctx,
ISC_LOGCATEGORY_GENERAL,
NS_LOGMODULE_OMAPI,
ISC_LOG_WARNING,
"couldn't install new acl for "
"command channel %s: %s",
socktext,
isc_result_totext(result));
/*
* Now update the key id list.
* XXXDCL the API for this seems incomplete. For now,
* I just reassign the pointer and set the control
* keyidlist to NULL so dns_c_ctrl_delete will not
* free it.
*/
if (listener->keyids != NULL)
dns_c_kidlist_delete(&listener->keyids);
listener->keyids = control->keyidlist;
control->keyidlist = NULL;
break;
}
}
*listenerp = listener;
}
static void
add_listener(isc_mem_t *mctx, ns_omapilistener_t **listenerp,
dns_c_ctrl_t *control, dns_c_ctx_t *cctx,
dns_aclconfctx_t *aclconfctx, char *socktext)
{
ns_omapilistener_t *listener;
dns_acl_t *new_acl = NULL;
isc_result_t result = ISC_R_SUCCESS;
listener = isc_mem_get(mctx, sizeof(ns_omapilistener_t));
if (listener == NULL)
result = ISC_R_NOMEMORY;
if (result == ISC_R_SUCCESS) {
listener->mctx = mctx;
listener->manager = NULL;
listener->address = control->u.inet_v.addr;
/*
* Make the acl.
*/
result = dns_acl_fromconfig(control->u.inet_v.matchlist,
cctx, aclconfctx, mctx, &new_acl);
}
if (result == ISC_R_SUCCESS) {
dns_acl_attach(new_acl, &listener->acl);
dns_acl_detach(&new_acl);
/*
* Now update the key id list.
* XXXDCL the API for this seems incomplete. For now,
* I just reassign the pointer and set it to NULL so
* dns_c_ctrl_delete will not free it.
*/
listener->keyids = control->keyidlist;
control->keyidlist = NULL;
result = ns_omapi_listen(listener);
}
if (result == ISC_R_SUCCESS) {
isc_log_write(ns_g_lctx, ISC_LOGCATEGORY_GENERAL,
NS_LOGMODULE_OMAPI, ISC_LOG_NOTICE,
"command channel listening on %s", socktext);
*listenerp = listener;
} else {
if (listener != NULL)
free_listener(listener);
isc_log_write(ns_g_lctx, ISC_LOGCATEGORY_GENERAL,
NS_LOGMODULE_OMAPI, ISC_LOG_WARNING,
"couldn't add command channel %s: %s",
socktext, isc_result_totext(result));
*listenerp = NULL;
}
/* XXXDCL return error results? fail hard? */
}
isc_result_t
ns_omapi_configure(isc_mem_t *mctx, dns_c_ctx_t *cctx,
dns_aclconfctx_t *aclconfctx)
{
ns_omapilistener_t *listener;
ns_omapilistenerlist_t new_listeners;
dns_c_ctrllist_t *controls = NULL;
dns_c_ctrl_t *control;
dns_c_kdeflist_t *keydeflist = NULL;
char socktext[ISC_SOCKADDR_FORMATSIZE];
isc_result_t result;
RUNTIME_CHECK(isc_once_do(&once, initialize_mutex) == ISC_R_SUCCESS);
ISC_LIST_INIT(new_listeners);
/*
* Get a pointer to the named.conf ``controls'' statement information.
*/
result = dns_c_ctx_getcontrols(cctx, &controls);
LOCK(&listeners_lock);
/*
* Run through the new control channel list, noting sockets that
* are already being listened on and moving them to the new list.
*
* Identifying duplicates addr/port combinations is left to either
* the underlying config code, or to the bind attempt getting an
* address-in-use error.
*/
if (result == ISC_R_SUCCESS) {
(void)dns_c_ctx_getkdeflist(cctx, &keydeflist);
if (keydeflist == NULL)
isc_log_write(ns_g_lctx, ISC_LOGCATEGORY_GENERAL,
NS_LOGMODULE_OMAPI, ISC_LOG_WARNING,
"no key statements for use by "
"control channels");
for (control = dns_c_ctrllist_head(controls);
control != NULL;
control = dns_c_ctrl_next(control)) {
/*
* The parser handles BIND 8 configuration file syntax,
* so it allows a control_type of dns_c_unix_control,
* as well as an inet phrase with no keys{} clause.
* However, it already warned that those were
* unsupported, so there is no need to do so again.
* The keydeflist == NULL case was already warned
* about a few lines above.
*/
if (control->control_type != dns_c_inet_control ||
keydeflist == NULL || control->keyidlist == NULL)
continue;
isc_sockaddr_format(&control->u.inet_v.addr,
socktext, sizeof(socktext));
isc_log_write(ns_g_lctx, ISC_LOGCATEGORY_GENERAL,
NS_LOGMODULE_OMAPI, ISC_LOG_DEBUG(9),
"processing control channel %s",
socktext);
register_keys(control, keydeflist, socktext);
update_listener(&listener, control, cctx, aclconfctx,
socktext);
if (listener != NULL)
/*
* Remove the listener from the old list,
* so it won't be shut down.
*/
ISC_LIST_UNLINK(listeners, listener, link);
else
/*
* This is a new listener.
*/
add_listener(mctx, &listener, control, cctx,
aclconfctx, socktext);
if (listener != NULL)
ISC_LIST_APPEND(new_listeners, listener, link);
}
}
/*
* ns_omapi_shutdown() will stop whatever is on the global listeners
* list, which currently only has whatever sockaddr was in the previous
* configuration (if any) that does not remain in the current
* configuration.
*/
ns_omapi_shutdown(ISC_FALSE);
/*
* Put all of the valid listeners on the listeners list.
* Anything already on listeners in the process of shutting down
* will be taken care of by listen_done().
*/
ISC_LIST_APPENDLIST(listeners, new_listeners, link);
UNLOCK(&listeners_lock);
return (ISC_R_SUCCESS);
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1 +0,0 @@
Makefile

View File

@@ -1,36 +0,0 @@
# Copyright (C) 1999, 2000 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.in,v 1.3 2000/06/22 21:49:56 tale Exp $
srcdir = @srcdir@
VPATH = @srcdir@
top_srcdir = @top_srcdir@
@BIND9_INCLUDES@
CINCLUDES = -I${srcdir}/include -I${srcdir}/../include \
${DNS_INCLUDES} ${ISC_INCLUDES}
CDEFINES =
CWARNINGS =
OBJS = os.@O@
SRCS = os.c
TARGETS = ${OBJS}
@BIND9_MAKE_RULES@

View File

@@ -1,49 +0,0 @@
/*
* Copyright (C) 1999, 2000 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: os.h,v 1.7.2.1 2000/07/10 22:07:58 gson Exp $ */
#ifndef NS_OS_H
#define NS_OS_H 1
#include <isc/types.h>
void
ns_os_init(void);
void
ns_os_daemonize(void);
void
ns_os_chroot(const char *root);
void
ns_os_inituserinfo(const char *username);
void
ns_os_changeuser(void);
void
ns_os_minprivs(void);
void
ns_os_writepidfile(const char *filename);
void
ns_os_shutdown(void);
#endif /* NS_OS_H */

View File

@@ -1,400 +0,0 @@
/*
* Copyright (C) 1999, 2000 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: os.c,v 1.18.2.3 2000/08/15 00:20:57 gson Exp $ */
#include <config.h>
#include <sys/stat.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <grp.h> /* Required for initgroups() on IRIX. */
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
#include <unistd.h>
#include <isc/string.h>
#include <named/main.h>
#include <named/os.h>
static char *pidfile = NULL;
#ifdef HAVE_LINUXTHREADS
static pid_t mainpid = 0;
static isc_boolean_t non_root_caps = ISC_FALSE;
static isc_boolean_t non_root = ISC_FALSE;
#endif
static struct passwd *runas_pw = NULL;
static isc_boolean_t done_setuid = ISC_FALSE;
#ifdef HAVE_LINUX_CAPABILITY_H
/*
* We define _LINUX_FS_H to prevent it from being included. We don't need
* anything from it, and the files it includes cause warnings with 2.2
* kernels, and compilation failures (due to conflicts between <linux/string.h>
* and <string.h>) on 2.3 kernels.
*/
#define _LINUX_FS_H
#include <sys/syscall.h> /* Required for syscall(). */
#include <linux/capability.h> /* Required for _LINUX_CAPABILITY_VERSION. */
#ifdef HAVE_LINUX_PRCTL_H
#include <sys/prctl.h> /* Required for prctl(). */
/*
* If the value of PR_SET_KEEPCAPS is not in <linux/prctl.h>, define it
* here. This allows setuid() to work on systems running a new enough
* kernel but with /usr/include/linux pointing to "standard" kernel
* headers.
*/
#ifndef PR_SET_KEEPCAPS
#define PR_SET_KEEPCAPS 8
#endif
#endif /* HAVE_LINUX_PRCTL_H */
#ifndef SYS_capset
#define SYS_capset __NR_capset
#endif
static void
linux_setcaps(unsigned int caps) {
struct __user_cap_header_struct caphead;
struct __user_cap_data_struct cap;
if ((getuid() != 0 && !non_root_caps) || non_root)
return;
memset(&caphead, 0, sizeof caphead);
caphead.version = _LINUX_CAPABILITY_VERSION;
caphead.pid = 0;
memset(&cap, 0, sizeof cap);
cap.effective = caps;
cap.permitted = caps;
cap.inheritable = caps;
if (syscall(SYS_capset, &caphead, &cap) < 0)
ns_main_earlyfatal("capset failed: %s", strerror(errno));
}
static void
linux_initialprivs(void) {
unsigned int caps;
/*
* We don't need most privileges, so we drop them right away.
* Later on linux_minprivs() will be called, which will drop our
* capabilities to the minimum needed to run the server.
*/
caps = 0;
/*
* We need to be able to bind() to privileged ports, notably port 53!
*/
caps |= (1 << CAP_NET_BIND_SERVICE);
/*
* We need chroot() initially too.
*/
caps |= (1 << CAP_SYS_CHROOT);
#ifdef HAVE_LINUX_PRCTL_H
/*
* If the kernel supports keeping capabilities after setuid(), we
* also want the setuid capability. We don't know until we've tried.
*/
caps |= (1 << CAP_SETUID);
#endif
/*
* Since we call initgroups, we need this.
*/
caps |= (1 << CAP_SETGID);
/*
* XXX We might want to add CAP_SYS_RESOURCE, though it's not
* clear it would work right given the way linuxthreads work.
*/
linux_setcaps(caps);
}
static void
linux_minprivs(void) {
unsigned int caps;
/*
* Drop all privileges except the ability to bind() to privileged
* ports.
*
* It's important that we drop CAP_SYS_CHROOT. If we didn't, it
* chroot() could be used to escape from the chrooted area.
*/
caps = 0;
caps |= (1 << CAP_NET_BIND_SERVICE);
linux_setcaps(caps);
}
#ifdef HAVE_LINUX_PRCTL_H
static void
linux_keepcaps(void) {
/*
* Ask the kernel to allow us to keep our capabilities after we
* setuid().
*/
if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) < 0) {
if (errno != EINVAL)
ns_main_earlyfatal("prctl() failed: %s",
strerror(errno));
} else {
non_root_caps = ISC_TRUE;
if (getuid() != 0)
non_root = ISC_TRUE;
}
}
#endif
#endif /* HAVE_LINUX_CAPABILITY_H */
static void
setup_syslog(void) {
int options;
options = LOG_PID;
#ifdef LOG_NDELAY
options |= LOG_NDELAY;
#endif
openlog("named", options, LOG_DAEMON);
}
void
ns_os_init(void) {
setup_syslog();
#ifdef HAVE_LINUX_CAPABILITY_H
linux_initialprivs();
#endif
#ifdef HAVE_LINUXTHREADS
mainpid = getpid();
#endif
}
void
ns_os_daemonize(void) {
pid_t pid;
int fd;
pid = fork();
if (pid == -1)
ns_main_earlyfatal("fork(): %s", strerror(errno));
if (pid != 0)
_exit(0);
/*
* We're the child.
*/
#ifdef HAVE_LINUXTHREADS
mainpid = getpid();
#endif
if (setsid() == -1)
ns_main_earlyfatal("setsid(): %s", strerror(errno));
/*
* Try to set stdin, stdout, and stderr to /dev/null, but press
* on even if it fails.
*
* XXXMLG The close() calls here are unneeded on all but NetBSD, but
* are harmless to include everywhere. dup2() is supposed to close
* the FD if it is in use, but unproven-pthreads-0.16 is broken
* and will end up closing the wrong FD. This will be fixed eventually,
* and these calls will be removed.
*/
fd = open("/dev/null", O_RDWR, 0);
if (fd != -1) {
close(STDIN_FILENO);
(void)dup2(fd, STDIN_FILENO);
close(STDOUT_FILENO);
(void)dup2(fd, STDOUT_FILENO);
close(STDERR_FILENO);
(void)dup2(fd, STDERR_FILENO);
if (fd != STDIN_FILENO &&
fd != STDOUT_FILENO &&
fd != STDERR_FILENO)
(void)close(fd);
}
}
static isc_boolean_t
all_digits(const char *s) {
if (*s == '\0')
return (ISC_FALSE);
while (*s != '\0') {
if (!isdigit((*s)&0xff))
return (ISC_FALSE);
s++;
}
return (ISC_TRUE);
}
void
ns_os_chroot(const char *root) {
if (root != NULL) {
if (chroot(root) < 0)
ns_main_earlyfatal("chroot(): %s", strerror(errno));
if (chdir("/") < 0)
ns_main_earlyfatal("chdir(/): %s", strerror(errno));
}
}
void
ns_os_inituserinfo(const char *username) {
if (username == NULL)
return;
if (all_digits(username))
runas_pw = getpwuid((uid_t)atoi(username));
else
runas_pw = getpwnam(username);
endpwent();
if (runas_pw == NULL)
ns_main_earlyfatal("user '%s' unknown", username);
if (getuid() == 0) {
if (initgroups(runas_pw->pw_name, runas_pw->pw_gid) < 0)
ns_main_earlyfatal("initgroups(): %s", strerror(errno));
}
}
void
ns_os_changeuser(void) {
if (runas_pw == NULL || done_setuid)
return;
done_setuid = ISC_TRUE;
#ifdef HAVE_LINUXTHREADS
if (!non_root_caps)
ns_main_earlyfatal(
"-u not supported on Linux kernels older than 2.3.99-pre3");
#endif
if (setgid(runas_pw->pw_gid) < 0)
ns_main_earlyfatal("setgid(): %s", strerror(errno));
if (setuid(runas_pw->pw_uid) < 0)
ns_main_earlyfatal("setuid(): %s", strerror(errno));
}
void
ns_os_minprivs(void) {
#ifdef HAVE_LINUX_CAPABILITY_H
#ifdef HAVE_LINUX_PRCTL_H
linux_keepcaps();
ns_os_changeuser();
#endif
linux_minprivs();
#endif /* HAVE_LINUX_CAPABILITY_H */
}
static int
safe_open(const char *filename) {
struct stat sb;
if (stat(filename, &sb) == -1) {
if (errno != ENOENT)
return (-1);
} else if ((sb.st_mode & S_IFREG) == 0)
return (-1);
(void)unlink(filename);
return (open(filename, O_WRONLY|O_CREAT|O_EXCL,
S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH));
}
static void
cleanup_pidfile(void) {
if (pidfile != NULL)
(void)unlink(pidfile);
free(pidfile);
pidfile = NULL;
}
void
ns_os_writepidfile(const char *filename) {
int fd;
FILE *lockfile;
size_t len;
pid_t pid;
/*
* The caller must ensure any required synchronization.
*/
cleanup_pidfile();
len = strlen(filename);
pidfile = malloc(len + 1);
if (pidfile == NULL)
ns_main_earlyfatal("couldn't malloc '%s': %s",
filename, strerror(errno));
/* This is safe. */
strcpy(pidfile, filename);
fd = safe_open(filename);
if (fd < 0)
ns_main_earlyfatal("couldn't open pid file '%s': %s",
filename, strerror(errno));
lockfile = fdopen(fd, "w");
if (lockfile == NULL)
ns_main_earlyfatal("could not fdopen() pid file '%s': %s",
filename, strerror(errno));
#ifdef HAVE_LINUXTHREADS
pid = mainpid;
#else
pid = getpid();
#endif
if (fprintf(lockfile, "%ld\n", (long)pid) < 0)
ns_main_earlyfatal("fprintf() to pid file '%s' failed",
filename);
if (fflush(lockfile) == EOF)
ns_main_earlyfatal("fflush() to pid file '%s' failed",
filename);
(void)fclose(lockfile);
}
void
ns_os_shutdown(void) {
closelog();
cleanup_pidfile();
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,2 +0,0 @@
Makefile
nsupdate

View File

@@ -1,67 +0,0 @@
# Copyright (C) 2000 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.in,v 1.2.2.2 2000/07/10 19:10:32 bwelling Exp $
srcdir = @srcdir@
VPATH = @srcdir@
top_srcdir = @top_srcdir@
@BIND9_VERSION@
@BIND9_INCLUDES@
CINCLUDES = -I${srcdir}/include ${LWRES_INCLUDES} ${DNS_INCLUDES} ${ISC_INCLUDES}
CDEFINES =
CWARNINGS =
LWRESLIBS = ../../lib/lwres/liblwres.@A@
DNSLIBS = ../../lib/dns/libdns.@A@ @DNS_OPENSSL_LIBS@
ISCLIBS = ../../lib/isc/libisc.@A@
LWRESDEPLIBS = ../../lib/lwres/liblwres.@A@
DNSDEPLIBS = ../../lib/dns/libdns.@A@
ISCDEPLIBS = ../../lib/isc/libisc.@A@
DEPLIBS = ${DNSDEPLIBS} ${ISCDEPLIBS}
LIBS = ${LWRESLIBS} ${DNSLIBS} ${ISCLIBS} @LIBS@
SUBDIRS =
TARGETS = nsupdate
OBJS = nsupdate.@O@
UOBJS =
SRCS = nsupdate.c
@BIND9_MAKE_RULES@
nsupdate: nsupdate.@O@ ${UOBJS} ${DEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ nsupdate.@O@ ${UOBJS} ${LIBS}
clean distclean::
rm -f ${TARGETS}
installdirs:
if [ ! -d ${DESTDIR}${bindir} ]; then \
mkdir ${DESTDIR}${bindir}; \
fi
install:: nsupdate
${LIBTOOL} ${INSTALL_PROGRAM} nsupdate ${DESTDIR}${bindir}

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +0,0 @@
Makefile
.libs
*.la
*.lo
rndc

View File

@@ -1,68 +0,0 @@
# Copyright (C) 2000 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.in,v 1.7.2.3 2000/07/12 01:18:43 gson Exp $
srcdir = @srcdir@
VPATH = @srcdir@
top_srcdir = @top_srcdir@
@BIND9_VERSION@
@BIND9_INCLUDES@
CINCLUDES = -I${top_srcdir}/bin/named/include \
${ISC_INCLUDES} ${DNS_INCLUDES} ${OMAPI_INCLUDES}
CDEFINES =
CWARNINGS =
OMAPILIBS = ../../lib/omapi/libomapi.@A@
DNSLIBS = ../../lib/dns/libdns.@A@ @DNS_OPENSSL_LIBS@
ISCLIBS = ../../lib/isc/libisc.@A@
OMAPIDEPLIBS = ../../lib/omapi/libomapi.@A@
DNSDEPLIBS = ../../lib/dns/libdns.@A@
ISCDEPLIBS = ../../lib/isc/libisc.@A@
DEPLIBS = ${OMAPIDEPLIBS} ${DNSDEPLIBS} ${ISCDEPLIBS}
LIBS = ${OMAPILIBS} ${DNSLIBS} ${ISCLIBS} @LIBS@
TARGETS = rndc
OBJS = rndc.@O@
SRCS = rndc.c
@BIND9_MAKE_RULES@
rndc.@O@: rndc.c
${LIBTOOL} ${CC} ${ALL_CFLAGS} -DVERSION=\"${VERSION}\" \
-DRNDC_SYSCONFDIR=\"${sysconfdir}\" -c ${srcdir}/rndc.c
rndc: ${OBJS} ${DEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ ${OBJS} ${LIBS}
installdirs:
if [ ! -d ${DESTDIR}${sbindir} ]; then \
mkdir ${DESTDIR}${sbindir}; \
fi
install:: rndc
${LIBTOOL} ${INSTALL_PROGRAM} rndc ${DESTDIR}${sbindir}
clean distclean::
rm -f ${TARGETS}

View File

@@ -1,547 +0,0 @@
/*
* Copyright (C) 2000 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: rndc.c,v 1.12.2.6 2000/08/02 20:59:13 gson Exp $ */
/*
* Principal Author: DCL
*/
#include <config.h>
#include <stdlib.h>
#include <isc/base64.h>
#include <isc/buffer.h>
#include <isc/commandline.h>
#include <isc/entropy.h>
#include <isc/mem.h>
#include <isc/socket.h>
#include <isc/string.h>
#include <isc/task.h>
#include <isc/util.h>
#include <dns/confndc.h>
#include <dst/dst.h>
#include <named/omapi.h>
static const char *progname;
static const char *conffile = RNDC_SYSCONFDIR "/rndc.conf";
static const char *version = VERSION;
static isc_boolean_t verbose;
static isc_mem_t *mctx;
typedef struct ndc_object {
OMAPI_OBJECT_PREAMBLE;
} ndc_object_t;
static ndc_object_t ndc_g_ndc;
static omapi_objecttype_t *ndc_type;
static void
notify(const char *fmt, ...) {
va_list ap;
if (verbose) {
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
fputs("\n", stderr);
}
}
/*
* Send a control command to the server.
*/
static isc_result_t
send_command(omapi_object_t *manager, char *command) {
omapi_object_t *message = NULL;
isc_result_t result;
REQUIRE(manager != NULL && command != NULL);
/*
* Create a new message object to store the information that will
* be sent to the server.
*/
result = omapi_message_create(&message);
if (result != ISC_R_SUCCESS)
return (result);
/*
* Specify the OPEN operation, with the UPDATE option if requested.
*/
result = omapi_object_setinteger(message, "op", OMAPI_OP_OPEN);
if (result == ISC_R_SUCCESS)
result = omapi_object_setboolean(message, "update", ISC_TRUE);
/*
* Tell the server the type of the object being opened; it needs
* to know this so that it can apply the proper object methods
* for lookup/setvalue.
*/
if (result == ISC_R_SUCCESS)
result = omapi_object_setstring(message, "type",
NS_OMAPI_CONTROL);
/*
* Associate the ndc object with the message, so that it will have its
* values stuffed in the message. Without it, the OPEN operation will
* fail because there is no name/value pair to use as a key for looking
* up the desired object at the server; this is true even though the
* particular object being accessed on the server does not need a key
* to be found.
*
* This object will also have its signal handler called with a
* "status" signal that sends the result of the operation on the
* server.
*/
if (result == ISC_R_SUCCESS)
result = omapi_object_setobject(message, "object",
(omapi_object_t *)&ndc_g_ndc);
/*
* Create a generic object to be the outer object for ndc_g_ndc, to
* handle the job of storing the command and stuffing it into the
* message.
*
* XXXDCL provide API so client does not need to refer to the
* outer member -- does not even need to know about how the whole
* outer/inner thing works.
*/
if (result == ISC_R_SUCCESS)
result = omapi_object_create(&ndc_g_ndc.outer, NULL, 0);
/*
* Set the command being sent.
*/
if (result == ISC_R_SUCCESS)
result = omapi_object_setboolean((omapi_object_t *)&ndc_g_ndc,
command, ISC_TRUE);
if (result == ISC_R_SUCCESS) {
/*
* Add the new message to the list of known messages. When the
* server's response comes back, the client will verify that
* the response was for a message it really sent.
*/
omapi_message_register(message);
/*
* Deliver the message to the server and await its
* response.
*/
result = omapi_message_send(message, manager);
}
/*
* Free the generic object and the message.
*/
if (ndc_g_ndc.outer != NULL)
omapi_object_dereference(&ndc_g_ndc.outer);
omapi_message_unregister(message);
omapi_object_dereference(&message);
return (result);
}
/*
* The signal handler gets the "status" signals when the server's response
* is processed. It also gets the "updated" signal after all the values
* from the server have been incorporated via ndc_setvalue.
*/
static isc_result_t
ndc_signalhandler(omapi_object_t *handle, const char *name, va_list ap) {
ndc_object_t *ndc;
omapi_value_t *tv;
isc_region_t region;
isc_result_t result;
REQUIRE(handle->type == ndc_type);
ndc = (ndc_object_t *)handle;
if (strcmp(name, "status") == 0) {
/*
* "status" is signalled with the result of the message's
* operation.
*/
ndc->waitresult = va_arg(ap, isc_result_t);
if (ndc->waitresult != ISC_R_SUCCESS) {
fprintf(stderr, "%s: operation failed: %s",
progname, isc_result_totext(ndc->waitresult));
tv = va_arg(ap, omapi_value_t *);
if (tv != NULL) {
omapi_value_getregion(tv, &region);
fprintf(stderr, " (%.*s)",
(int)region.length, region.base);
}
fprintf(stderr, "\n");
}
/*
* Even if the waitresult was not ISC_R_SUCCESS, the processing
* by the function still was.
*/
result = ISC_R_SUCCESS;
} else if (strcmp(name, "updated") == 0) {
/*
* Nothing to do, really.
*/
result = ISC_R_SUCCESS;
} else {
/*
* Pass any unknown signal any internal object.
* (This normally does not happen; there is no
* inner object, nor anything else being signalled.)
*/
fprintf(stderr, "%s: ndc_signalhandler: unknown signal: %s",
progname, name);
result = omapi_object_passsignal(handle, name, ap);
}
return (result);
}
static void
usage(void) {
fprintf(stderr, "\
Usage: %s [-c config] [-s server] [-p port] [-y key] command [command ...]\n\
\n\
command is one of the following for named:\n\
\n\
*status Display ps(1) status of named.\n\
*dumpdb Dump database and cache to /var/tmp/named_dump.db.\n\
reload Reload configuration file and zones.\n\
*stats Dump statistics to /var/tmp/named.stats.\n\
*trace Increment debugging level by one.\n\
*notrace Set debugging level to 0.\n\
*querylog Toggle query logging.\n\
*stop Stop the server.\n\
*restart Restart the server.\n\
\n\
* == not yet implemented\n\
Version: %s\n",
progname, version);
}
#undef DO
#define DO(name, function) \
do { \
result = function; \
if (result != ISC_R_SUCCESS) { \
fprintf(stderr, "%s: %s: %s\n", progname, \
name, isc_result_totext(result)); \
exit(1); \
} else \
notify(name); \
} while (0)
int
main(int argc, char **argv) {
isc_boolean_t show_final_mem = ISC_FALSE;
isc_entropy_t *entropy = NULL;
isc_result_t result = ISC_R_SUCCESS;
isc_socketmgr_t *socketmgr = NULL;
isc_taskmgr_t *taskmgr = NULL;
omapi_object_t *omapimgr = NULL;
dns_c_ndcctx_t *config = NULL;
dns_c_ndcopts_t *configopts = NULL;
dns_c_ndcserver_t *server = NULL;
dns_c_kdeflist_t *keys = NULL;
dns_c_kdef_t *key = NULL;
const char *keyname = NULL;
char secret[1024];
isc_buffer_t secretbuf;
char *command;
const char *servername = NULL;
const char *host = NULL;
unsigned int port = NS_OMAPI_PORT;
unsigned int algorithm;
int ch;
progname = strrchr(*argv, '/');
if (progname != NULL)
progname++;
else
progname = *argv;
while ((ch = isc_commandline_parse(argc, argv, "c:Mmp:s:vy:")) != -1) {
switch (ch) {
case 'c':
conffile = isc_commandline_argument;
break;
case 'M':
isc_mem_debugging = ISC_TRUE;
break;
case 'm':
show_final_mem = ISC_TRUE;
break;
case 'p':
port = atoi(isc_commandline_argument);
if (port > 65535) {
fprintf(stderr, "%s: port out of range\n",
progname);
exit(1);
}
break;
case 's':
servername = isc_commandline_argument;
break;
case 'v':
/*
* Undocumented, for testing.
*/
verbose = ISC_TRUE;
break;
case 'y':
keyname = isc_commandline_argument;
break;
case '?':
usage();
exit(1);
break;
default:
fprintf(stderr, "%s: unexpected error parsing "
"command arguments: got %c\n", progname, ch);
exit(1);
break;
}
}
argc -= isc_commandline_index;
argv += isc_commandline_index;
if (argc < 1) {
usage();
exit(1);
}
DO("create memory context", isc_mem_create(0, 0, &mctx));
DO("create socket manager", isc_socketmgr_create(mctx, &socketmgr));
DO("create task manager", isc_taskmgr_create(mctx, 1, 0, &taskmgr));
DO("create entropy pool", isc_entropy_create(mctx, &entropy));
/* XXXDCL probably should use ISC_ENTROPY_GOOD. talk with graff. */
DO("initialize digital signatures",
dst_lib_init(mctx, entropy, 0));
DO(conffile, dns_c_ndcparseconf(conffile, mctx, &config));
(void)dns_c_ndcctx_getoptions(config, &configopts);
if (servername == NULL && configopts != NULL)
result = dns_c_ndcopts_getdefserver(configopts, &servername);
if (servername != NULL)
result = dns_c_ndcctx_getserver(config, servername, &server);
else {
fprintf(stderr, "%s: no server specified and no default\n",
progname);
exit(1);
}
/*
* Look for the name of the key to use.
*/
if (keyname != NULL)
; /* Was set on command line, do nothing. */
else if (server != NULL)
DO("get key for server", dns_c_ndcserver_getkey(server,
&keyname));
else if (configopts != NULL)
DO("get default key",
dns_c_ndcopts_getdefkey(configopts, &keyname));
else {
fprintf(stderr, "%s: no key for server and no default\n",
progname);
exit(1);
}
/*
* Get the key's definition.
*/
DO("get config key list", dns_c_ndcctx_getkeys(config, &keys));
DO("get key definition", dns_c_kdeflist_find(keys, keyname, &key));
/* XXX need methods for structure access? */
INSIST(key->secret != NULL);
INSIST(key->algorithm != NULL);
if (strcasecmp(key->algorithm, "hmac-md5") == 0)
algorithm = OMAPI_AUTH_HMACMD5;
else {
fprintf(stderr, "%s: unsupported algorithm: %s\n",
progname, key->algorithm);
exit(1);
}
isc_buffer_init(&secretbuf, secret, sizeof(secret));
DO("decode base64 secret",
isc_base64_decodestring(mctx, key->secret, &secretbuf));
if (server != NULL)
(void)dns_c_ndcserver_gethost(server, &host);
if (host == NULL)
host = servername;
DO("initialize omapi", omapi_lib_init(mctx, taskmgr, socketmgr));
DO("register omapi object",
omapi_object_register(&ndc_type, "ndc",
NULL, /* setvalue */
NULL, /* getvalue */
NULL, /* destroy */
ndc_signalhandler,
NULL, /* stuffvalues */
NULL, /* lookup */
NULL, /* create */
NULL)); /* remove */
/*
* Initialize the static ndc_g_ndc variable (normally this is done
* by omapi_object_create on a dynamic variable).
*/
ndc_g_ndc.refcnt = 1;
ndc_g_ndc.type = ndc_type;
DO("register local authenticator",
omapi_auth_register(keyname, algorithm, isc_buffer_base(&secretbuf),
isc_buffer_usedlength(&secretbuf)));
DO("create protocol manager", omapi_object_create(&omapimgr, NULL, 0));
DO("connect", omapi_protocol_connect(omapimgr, host, (in_port_t)port,
NULL));
DO("send remote authenticator",
omapi_auth_use(omapimgr, keyname, algorithm));
/*
* Preload the waitresult as successful.
*/
ndc_g_ndc.waitresult = ISC_R_SUCCESS;
while ((command = *argv++) != NULL &&
result == ISC_R_SUCCESS &&
ndc_g_ndc.waitresult == ISC_R_SUCCESS) {
notify(command);
if (strcmp(command, "dumpdb") == 0) {
result = ISC_R_NOTIMPLEMENTED;
} else if (strcmp(command, "notrace") == 0) {
result = ISC_R_NOTIMPLEMENTED;
} else if (strcmp(command, "querylog") == 0 ||
strcmp(command, "qrylog") == 0) {
result = ISC_R_NOTIMPLEMENTED;
} else if (strcmp(command, "reload") == 0) {
result = send_command(omapimgr, command);
} else if (strcmp(command, "restart") == 0) {
result = ISC_R_NOTIMPLEMENTED;
} else if (strcmp(command, "stats") == 0) {
result = ISC_R_NOTIMPLEMENTED;
} else if (strcmp(command, "status") == 0) {
result = ISC_R_NOTIMPLEMENTED;
} else if (strcmp(command, "stop") == 0) {
result = ISC_R_NOTIMPLEMENTED;
} else if (strcmp(command, "trace") == 0) {
result = ISC_R_NOTIMPLEMENTED;
}
if (result == ISC_R_NOTIMPLEMENTED)
fprintf(stderr, "%s: '%s' is not yet implemented\n",
progname, command);
else if (result != ISC_R_SUCCESS)
fprintf(stderr, "%s: protocol failure: %s\n",
progname, isc_result_totext(result));
else if (ndc_g_ndc.waitresult != ISC_R_SUCCESS)
fprintf(stderr, "%s: %s command failure: %s\n",
progname, command,
isc_result_totext(ndc_g_ndc.waitresult));
else
printf("%s: %s command successful\n",
progname, command);
}
notify("command loop done");
/*
* Close the connection and wait to be disconnected. The connection
* is only still open if the protocol object is still attached
* to the omapimgr.
*/
if (omapimgr != NULL) {
omapi_protocol_disconnect(omapimgr, OMAPI_CLEAN_DISCONNECT);
/*
* Free the protocol manager.
*/
omapi_object_dereference(&omapimgr);
}
dns_c_ndcctx_destroy(&config);
omapi_lib_destroy();
dst_lib_destroy();
isc_entropy_detach(&entropy);
isc_socketmgr_destroy(&socketmgr);
isc_taskmgr_destroy(&taskmgr);
if (mctx != NULL) {
if (show_final_mem)
isc_mem_stats(mctx, stderr);
isc_mem_destroy(&mctx);
}
if (result != ISC_R_SUCCESS || ndc_g_ndc.waitresult != ISC_R_SUCCESS)
exit(1);
return (0);
}

View File

@@ -1,36 +0,0 @@
/*
* Copyright (C) 2000 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: rndc.conf,v 1.3.2.1 2000/07/11 19:36:05 gson Exp $ */
/*
* Sample rndc configuration file.
*/
options {
default-server localhost;
default-key "key";
};
server localhost {
key "key";
};
key "key" {
algorithm hmac-md5;
secret "c3Ryb25nIGVub3VnaCBmb3IgYSBtYW4gYnV0IG1hZGUgZm9yIGEgd29tYW4K";
};

View File

@@ -1,50 +0,0 @@
Makefile
.libs
*.la
*.lo
adb_test
byaddr_test
byname_test
compress_test
db_test
dispatch_tcp_test
dispatch_test
entropy_test
entropy2_test
fsaccess_test
gxba_test
gxbn_test
headerdep_test.sh
hash_test
inter_test
keyboard_test
lex_test
lfsr_test
log_test
lwres_test
lwresconf_test
master_test
mem_test
mempool_test
name_test
ndcconf_test
nconf_test
nxtify
omapi_test
ratelimiter_test
rbt_test
rdata_test
res_test
rwlock_test
sdig
serial_test
shutdown_test
sock_test
sym_test
t_journal
task_test
timer_test
tkey_test
wire_test
zone2_test
zone_test

View File

@@ -1 +0,0 @@
client. IN KEY 512 3 2 AAEBAAAAYDD6OLNNCn5OvnpBzMKzinDEFwpPpRofgSOXX87uho4sdyYK eFpgvl5md5h7m6vWNNni6cVfMBkqOftcQzxxPN1FNnabc9sUu4MxLvyf usOrXtZ5Nsv/0ei2tmnuesXM/w==

View File

@@ -1,6 +0,0 @@
Private-key-format: v1.2
Algorithm: 2 (DH)
Prime(p): ///////////JD9qiIWjCNMTGYouA3BzRKQJOCIpnzHQCC76mOxObIlFKCHmONATd75UZs806QxswKwpt8l8UN0/hNW1tUcJF5IW1dmJefsb0TELppjo2IP//////////
Generator(g): Ag==
Private_value(x): XSrO/o1a0LHRp3JBT2N+vxjvHIkPL8Qz8s8ecKhaGr2DiXdYC2h8ifPE5v8l4sEKIfwq4xy0KIH/gfurmdmuHvCvgnFo33IzQARzaPXJWAqsnwhdY2vb8bxEB+OP/S0h
Public_value(y): MPo4s00Kfk6+ekHMwrOKcMQXCk+lGh+BI5dfzu6Gjix3Jgp4WmC+XmZ3mHubq9Y02eLpxV8wGSo5+1xDPHE83UU2dptz2xS7gzEu/J+6w6te1nk2y//R6La2ae56xcz/

View File

@@ -1,311 +0,0 @@
# Copyright (C) 1998-2000 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.in,v 1.96 2000/06/22 21:50:03 tale Exp $
srcdir = @srcdir@
VPATH = @srcdir@
top_srcdir = @top_srcdir@
@BIND9_INCLUDES@
CINCLUDES = ${DNS_INCLUDES} ${ISC_INCLUDES} ${LWRES_INCLUDES} \
${OMAPI_INCLUDES}
CDEFINES =
CWARNINGS =
DNSLIBS = ../../lib/dns/libdns.@A@ @DNS_OPENSSL_LIBS@
ISCLIBS = ../../lib/isc/libisc.@A@
OMAPILIBS = ../../lib/omapi/libomapi.@A@
LWRESLIBS = ../../lib/lwres/liblwres.@A@
DNSDEPLIBS = ../../lib/dns/libdns.@A@
ISCDEPLIBS = ../../lib/isc/libisc.@A@
OMAPIDEPLIBS = ../../lib/omapi/libomapi.@A@
LWRESDEPLIBS = ../../lib/lwres/liblwres.@A@
LIBS = @LIBS@
SUBDIRS = db dst master mem names net rbt sockaddr tasks timers system
# Alphabetically
TARGETS =
XTARGETS = adb_test \
byaddr_test \
byname_test \
compress_test \
db_test \
dispatch_tcp_test \
dispatch_test \
entropy_test \
entropy2_test \
gxba_test \
gxbn_test \
hash_test \
fsaccess_test \
inter_test \
keyboard_test \
lex_test \
lfsr_test \
log_test \
lwres_test \
lwresconf_test \
master_test \
mempool_test \
name_test \
nconf_test \
ndcconf_test \
nxtify \
omapi_test \
ratelimiter_test \
rbt_test \
rdata_test \
rwlock_test \
serial_test \
shutdown_test \
sock_test \
sym_test \
task_test \
timer_test \
tkey_test \
wire_test \
zone2_test
# Alphabetically
SRCS = adb_test.c \
byaddr_test.c \
byname_test.c \
compress_test.c \
db_test.c \
dispatch_tcp_test.c \
dispatch_test.c \
entropy_test.c \
entropy2_test.c \
gxba_test.c \
gxbn_test.c \
hash_test.c \
fsaccess_test.c \
inter_test.c \
keyboard_test.c \
lex_test.c \
lfsr_test.c \
log_test.c \
lwres_test.c \
lwresconf_test.c \
master_test.c \
mempool_test.c \
name_test.c \
nconf_test.c \
ndcconf_test.c \
nxtify.c \
omapi_test.c \
printmsg.c \
ratelimiter_test.c \
rbt_test.c \
rdata_test.c \
rwlock_test.c \
serial_test.c \
shutdown_test.c \
sock_test.c \
sym_test.c \
task_test.c \
timer_test.c \
tkey_test.c \
wire_test.c \
zone_test.c \
zone2_test.c
@BIND9_MAKE_RULES@
all_tests: ${XTARGETS}
adb_test: adb_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ adb_test.@O@ \
${DNSLIBS} ${ISCLIBS} ${LIBS}
nxtify: nxtify.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ nxtify.@O@ \
${DNSLIBS} ${ISCLIBS} ${LIBS}
byaddr_test: byaddr_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ byaddr_test.@O@ \
${DNSLIBS} ${ISCLIBS} ${LIBS}
byname_test: byname_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ byname_test.@O@ \
${DNSLIBS} ${ISCLIBS} ${LIBS}
lex_test: lex_test.@O@ ${ISCDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ lex_test.@O@ \
${ISCLIBS} ${LIBS}
lfsr_test: lfsr_test.@O@ ${ISCDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ lfsr_test.@O@ \
${ISCLIBS} ${LIBS}
log_test: log_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ log_test.@O@ \
${DNSLIBS} ${ISCLIBS} ${LIBS}
name_test: name_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ name_test.@O@ \
${DNSLIBS} ${ISCLIBS} ${LIBS}
omapi_test: omapi_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS} ${OMAPIDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ omapi_test.@O@ \
${OMAPILIBS} ${DNSLIBS} ${ISCLIBS} ${LIBS}
hash_test: hash_test.@O@ ${ISCDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ hash_test.@O@ \
${ISCLIBS} ${LIBS}
entropy_test: entropy_test.@O@ ${ISCDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ entropy_test.@O@ \
${ISCLIBS} ${LIBS}
entropy2_test: entropy2_test.@O@ ${ISCDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ entropy2_test.@O@ \
${ISCLIBS} ${LIBS}
sock_test: sock_test.@O@ ${ISCDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ sock_test.@O@ \
${ISCLIBS} ${LIBS}
sym_test: sym_test.@O@ ${ISCDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ sym_test.@O@ \
${ISCLIBS} ${LIBS}
task_test: task_test.@O@ ${ISCDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ task_test.@O@ \
${ISCLIBS} ${LIBS}
shutdown_test: shutdown_test.@O@ ${ISCDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ shutdown_test.@O@ \
${ISCLIBS} ${LIBS}
timer_test: timer_test.@O@ ${ISCDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ timer_test.@O@ \
${ISCLIBS} ${LIBS}
ratelimiter_test: ratelimiter_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ ratelimiter_test.@O@ \
${DNSLIBS} ${ISCLIBS} ${LIBS}
rbt_test: rbt_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ rbt_test.@O@ \
${DNSLIBS} ${ISCLIBS} ${LIBS}
rdata_test: rdata_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ rdata_test.@O@ \
${DNSLIBS} ${ISCLIBS} ${LIBS}
rwlock_test: rwlock_test.@O@ ${ISCDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ rwlock_test.@O@ \
${ISCLIBS} ${LIBS}
wire_test: wire_test.@O@ printmsg.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ wire_test.@O@ printmsg.@O@ \
${DNSLIBS} ${ISCLIBS} ${LIBS}
master_test: master_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ master_test.@O@ \
${DNSLIBS} ${ISCLIBS} ${LIBS}
db_test: db_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ db_test.@O@ \
${DNSLIBS} ${ISCLIBS} ${LIBS}
compress_test: compress_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ compress_test.@O@ \
${DNSLIBS} ${ISCLIBS} ${LIBS}
mempool_test: mempool_test.@O@ ${ISCDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ mempool_test.@O@ \
${ISCLIBS} ${LIBS}
serial_test: serial_test.@O@ ${ISCDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ serial_test.@O@ \
${ISCLIBS} ${LIBS}
zone2_test: zone2_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ zone2_test.@O@ \
${DNSLIBS} ${ISCLIBS} ${LIBS}
zone_test: zone_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ zone_test.@O@ \
${DNSLIBS} ${ISCLIBS} ${LIBS}
dispatch_test: dispatch_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ dispatch_test.@O@ \
${DNSLIBS} ${ISCLIBS} ${LIBS}
dispatch_tcp_test: dispatch_tcp_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ dispatch_tcp_test.@O@ \
${DNSLIBS} ${ISCLIBS} ${LIBS}
nconf_test: nconf_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ nconf_test.@O@ \
${DNSLIBS} ${ISCLIBS} ${LIBS}
ndcconf_test: ndcconf_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ ndcconf_test.@O@ \
${DNSLIBS} ${ISCLIBS} ${LIBS}
tkey_test: tkey_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ tkey_test.@O@ \
${DNSLIBS} ${ISCLIBS} ${LIBS}
fsaccess_test: fsaccess_test.@O@ ${ISCDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ fsaccess_test.@O@ \
${ISCLIBS} ${LIBS}
inter_test: inter_test.@O@ ${ISCDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ inter_test.@O@ \
${ISCLIBS} ${LIBS}
keyboard_test: keyboard_test.@O@ ${ISCDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ keyboard_test.@O@ \
${ISCLIBS} ${LIBS}
lwresconf_test: lwresconf_test.@O@ ${ISCDEPLIBS} ${LWRESDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ lwresconf_test.@O@ \
${LWRESLIBS} ${ISCLIBS} ${LIBS}
lwres_test: lwres_test.@O@ ${ISCDEPLIBS} ${LWRESDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ lwres_test.@O@ \
${LWRESLIBS} ${ISCLIBS} ${LIBS}
gxbn_test: gxbn_test.@O@ ${LWRESDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ gxbn_test.@O@ \
${LWRESLIBS} ${ISCLIBS} ${LIBS}
gxba_test: gxba_test.@O@ ${LWRESDEPLIBS}
${LIBTOOL} ${CC} ${CFLAGS} -o $@ gxba_test.@O@ \
${LWRESLIBS} ${ISCLIBS} ${LIBS}
distclean::
rm -f headerdep_test.sh
clean distclean::
rm -f ${TARGETS} ${XTARGETS}
rm -f t_journal
test:
@for dir in $(SUBDIRS) ;\
do \
( cd $$dir; $(MAKE) test ) ;\
done

View File

@@ -1,403 +0,0 @@
/*
* Copyright (C) 1999, 2000 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: adb_test.c,v 1.54.2.1 2000/06/28 16:45:22 gson Exp $ */
#include <config.h>
#include <stdlib.h>
#include <unistd.h>
#include <isc/app.h>
#include <isc/buffer.h>
#include <isc/task.h>
#include <isc/timer.h>
#include <isc/socket.h>
#include <isc/util.h>
#include <dns/adb.h>
#include <dns/cache.h>
#include <dns/dispatch.h>
#include <dns/db.h>
#include <dns/log.h>
#include <dns/rootns.h>
#include <dns/result.h>
typedef struct client client_t;
struct client {
dns_name_t name;
ISC_LINK(client_t) link;
dns_adbfind_t *find;
};
isc_mem_t *mctx;
isc_mempool_t *cmp;
isc_log_t *lctx;
isc_logconfig_t *lcfg;
isc_taskmgr_t *taskmgr;
isc_socketmgr_t *socketmgr;
isc_timermgr_t *timermgr;
dns_dispatchmgr_t *dispatchmgr;
isc_task_t *t1, *t2;
dns_view_t *view;
dns_db_t *rootdb;
ISC_LIST(client_t) clients;
isc_mutex_t client_lock;
isc_stdtime_t now;
dns_adb_t *adb;
static void
check_result(isc_result_t result, const char *format, ...) {
va_list args;
if (result == ISC_R_SUCCESS)
return;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
fprintf(stderr, "\n");
exit(1);
}
static client_t *
new_client(void) {
client_t *client;
client = isc_mempool_get(cmp);
INSIST(client != NULL);
dns_name_init(&client->name, NULL);
ISC_LINK_INIT(client, link);
client->find = NULL;
return (client);
}
static void
free_client(client_t **c) {
client_t *client;
INSIST(c != NULL);
client = *c;
*c = NULL;
INSIST(client != NULL);
dns_name_free(&client->name, mctx);
INSIST(!ISC_LINK_LINKED(client, link));
INSIST(client->find == NULL);
isc_mempool_put(cmp, client);
}
static inline void
CLOCK(void) {
RUNTIME_CHECK(isc_mutex_lock(&client_lock) == ISC_R_SUCCESS);
}
static inline void
CUNLOCK(void) {
RUNTIME_CHECK(isc_mutex_unlock(&client_lock) == ISC_R_SUCCESS);
}
static void
lookup_callback(isc_task_t *task, isc_event_t *ev) {
client_t *client;
client = ev->ev_arg;
INSIST(client->find == ev->ev_sender);
printf("Task %p got event %p type %08x from %p, client %p\n",
task, ev, ev->ev_type, client->find, client);
isc_event_free(&ev);
CLOCK();
dns_adb_dumpfind(client->find, stderr);
dns_adb_destroyfind(&client->find);
ISC_LIST_UNLINK(clients, client, link);
free_client(&client);
CUNLOCK();
}
static void
create_managers(void) {
isc_result_t result;
taskmgr = NULL;
result = isc_taskmgr_create(mctx, 2, 0, &taskmgr);
check_result(result, "isc_taskmgr_create");
timermgr = NULL;
result = isc_timermgr_create(mctx, &timermgr);
check_result(result, "isc_timermgr_create");
socketmgr = NULL;
result = isc_socketmgr_create(mctx, &socketmgr);
check_result(result, "isc_socketmgr_create");
dispatchmgr = NULL;
result = dns_dispatchmgr_create(mctx, NULL, &dispatchmgr);
check_result(result, "dns_dispatchmgr_create");
}
static void
create_view(void) {
dns_cache_t *cache;
isc_result_t result;
/*
* View.
*/
view = NULL;
result = dns_view_create(mctx, dns_rdataclass_in, "_default", &view);
check_result(result, "dns_view_create");
/*
* Cache.
*/
cache = NULL;
result = dns_cache_create(mctx, taskmgr, timermgr, dns_rdataclass_in,
"rbt", 0, NULL, &cache);
check_result(result, "dns_cache_create");
dns_view_setcache(view, cache);
dns_cache_detach(&cache);
{
unsigned int attrs;
isc_sockaddr_t any4, any6;
dns_dispatch_t *disp4 = NULL;
dns_dispatch_t *disp6 = NULL;
isc_sockaddr_any(&any4);
isc_sockaddr_any6(&any6);
attrs = DNS_DISPATCHATTR_IPV4 | DNS_DISPATCHATTR_UDP;
RUNTIME_CHECK(dns_dispatch_getudp(dispatchmgr, socketmgr,
taskmgr, &any4, 512, 6, 1024,
17, 19, attrs, attrs, &disp4)
== ISC_R_SUCCESS);
INSIST(disp4 != NULL);
attrs = DNS_DISPATCHATTR_IPV6 | DNS_DISPATCHATTR_UDP;
RUNTIME_CHECK(dns_dispatch_getudp(dispatchmgr, socketmgr,
taskmgr, &any6, 512, 6, 1024,
17, 19, attrs, attrs, &disp6)
== ISC_R_SUCCESS);
INSIST(disp6 != NULL);
RUNTIME_CHECK(dns_view_createresolver(view, taskmgr, 10,
socketmgr,
timermgr, 0,
dispatchmgr,
disp4, disp6) ==
ISC_R_SUCCESS);
}
rootdb = NULL;
result = dns_rootns_create(mctx, dns_rdataclass_in, NULL, &rootdb);
check_result(result, "dns_rootns_create()");
dns_view_sethints(view, rootdb);
dns_db_detach(&rootdb);
dns_view_freeze(view);
}
static void
lookup(const char *target) {
dns_name_t name;
unsigned char namedata[256];
client_t *client;
isc_buffer_t t, namebuf;
isc_result_t result;
unsigned int options;
INSIST(target != NULL);
client = new_client();
isc_buffer_init(&t, target, strlen(target));
isc_buffer_add(&t, strlen(target));
isc_buffer_init(&namebuf, namedata, sizeof(namedata));
dns_name_init(&name, NULL);
result = dns_name_fromtext(&name, &t, dns_rootname, ISC_FALSE,
&namebuf);
check_result(result, "dns_name_fromtext %s", target);
result = dns_name_dup(&name, mctx, &client->name);
check_result(result, "dns_name_dup %s", target);
options = 0;
options |= DNS_ADBFIND_INET;
options |= DNS_ADBFIND_INET6;
options |= DNS_ADBFIND_WANTEVENT;
options |= DNS_ADBFIND_HINTOK;
options |= DNS_ADBFIND_GLUEOK;
result = dns_adb_createfind(adb, t2, lookup_callback, client,
&client->name, dns_rootname, options,
now, NULL, view->dstport, &client->find);
check_result(result, "dns_adb_createfind()");
dns_adb_dumpfind(client->find, stderr);
if ((client->find->options & DNS_ADBFIND_WANTEVENT) != 0)
ISC_LIST_APPEND(clients, client, link);
else {
dns_adb_destroyfind(&client->find);
free_client(&client);
}
}
int
main(int argc, char **argv) {
isc_result_t result;
isc_logdestination_t destination;
UNUSED(argc);
UNUSED(argv);
dns_result_register();
result = isc_app_start();
check_result(result, "isc_app_start()");
isc_stdtime_get(&now);
result = isc_mutex_init(&client_lock);
check_result(result, "isc_mutex_init(&client_lock)");
ISC_LIST_INIT(clients);
/*
* EVERYTHING needs a memory context.
*/
mctx = NULL;
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
cmp = NULL;
RUNTIME_CHECK(isc_mempool_create(mctx, sizeof(client_t), &cmp)
== ISC_R_SUCCESS);
isc_mempool_setname(cmp, "adb test clients");
result = isc_log_create(mctx, &lctx, &lcfg);
check_result(result, "isc_log_create()");
isc_log_setcontext(lctx);
dns_log_init(lctx);
dns_log_setcontext(lctx);
/*
* Create and install the default channel.
*/
destination.file.stream = stderr;
destination.file.name = NULL;
destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0;
result = isc_log_createchannel(lcfg, "_default",
ISC_LOG_TOFILEDESC,
ISC_LOG_DYNAMIC,
&destination, ISC_LOG_PRINTTIME);
check_result(result, "isc_log_createchannel()");
result = isc_log_usechannel(lcfg, "_default", NULL, NULL);
check_result(result, "isc_log_usechannel()");
/*
* Set the initial debug level.
*/
isc_log_setdebuglevel(lctx, 2);
create_managers();
t1 = NULL;
result = isc_task_create(taskmgr, 0, &t1);
check_result(result, "isc_task_create t1");
t2 = NULL;
result = isc_task_create(taskmgr, 0, &t2);
check_result(result, "isc_task_create t2");
printf("task 1 = %p\n", t1);
printf("task 2 = %p\n", t2);
create_view();
adb = view->adb;
/*
* Lock the entire client list here. This will cause all events
* for found names to block as well.
*/
CLOCK();
lookup("f.root-servers.net."); /* Should be in hints */
lookup("www.iengines.com"); /* should fetch */
lookup("www.isc.org"); /* should fetch */
lookup("www.flame.org"); /* should fetch */
lookup("kechara.flame.org."); /* should fetch */
lookup("moghedien.flame.org."); /* should fetch */
lookup("mailrelay.flame.org."); /* should fetch */
lookup("ipv4v6.flame.org."); /* should fetch */
lookup("nonexistant.flame.org."); /* should fail to be found */
lookup("foobar.badns.flame.org."); /* should fail utterly (NS) */
lookup("i.root-servers.net."); /* Should be in hints */
CUNLOCK();
sleep(10);
dns_adb_dump(adb, stderr);
sleep(10);
CLOCK();
lookup("f.root-servers.net."); /* Should be in hints */
lookup("www.iengines.com"); /* should fetch */
lookup("www.isc.org"); /* should fetch */
lookup("www.flame.org"); /* should fetch */
lookup("kechara.flame.org."); /* should fetch */
lookup("moghedien.flame.org."); /* should fetch */
lookup("mailrelay.flame.org."); /* should fetch */
lookup("ipv4v6.flame.org."); /* should fetch */
lookup("nonexistant.flame.org."); /* should fail to be found */
lookup("foobar.badns.flame.org."); /* should fail utterly (NS) */
lookup("i.root-servers.net."); /* Should be in hints */
CUNLOCK();
dns_adb_dump(adb, stderr);
isc_task_detach(&t1);
isc_task_detach(&t2);
isc_mem_stats(mctx, stdout);
dns_adb_dump(adb, stderr);
isc_app_run();
dns_adb_dump(adb, stderr);
dns_view_detach(&view);
adb = NULL;
isc_socketmgr_destroy(&socketmgr);
isc_timermgr_destroy(&timermgr);
fprintf(stderr, "Destroying task manager\n");
isc_taskmgr_destroy(&taskmgr);
isc_log_destroy(&lctx);
isc_mempool_destroy(&cmp);
isc_mem_stats(mctx, stdout);
isc_mem_destroy(&mctx);
isc_app_finish();
return (0);
}

View File

@@ -1,524 +0,0 @@
# Copyright (C) 1999, 2000 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: b8status.pl,v 1.5 2000/06/22 21:50:05 tale Exp $
#
# aggregate reports from all bind8 build environments
# write a summary of results in html format
#
$Debug = 0;
$Home = $ENV{"HOME"};
$DebugFile = "$Home/b8t/b8tsummary.dbg";
$HasTests = 0;
$NoPort = 0;
$HaltLevel = 2;
$ConfigFile = ".config";
$BuildFile = ".build";
$BstatusFile = "bstatus.html";
$TestFile = ".test";
$TstatusFile = "tstatus.html";
$WkbpFile = ".wkbp";
$WktpFile = ".wktp";
$RxFile = ".b8trx";
$UnameFile = "uname";
$Nfbp = 0;
$Nobp = 0;
$Nftp = 0;
$Notp = 0;
$BadTest = 0;
$BadTestReason = "";
$Module = "bind8";
$MasterDir = "$Home/b8t";
$DataDir = "/proj/build-reports/$Module";
$HttpHomeURL = "http://status.isc.org/$Module";
#
# initialize the host array
#
open(DEBUG, "> $DebugFile") if ($Debug);
opendir(HDIR, "$MasterDir/hosts");
@entries = readdir(HDIR);
closedir(HDIR);
foreach $entry (@entries) {
next if $entry =~ /^\.\.*$/;
next unless -d "$MasterDir/hosts/$entry";
push(hosts, $entry);
}
#
# put the page top
#
$when = `date`;
chop $when;
$Ncols = 3;
$Ncols = 4 if ($HasTests);
printf("<?php \$title = \"ISC Status Server\"; ?>\n");
printf("<?php include(\"status-isc-header.inc\") ?>\n");
printf("\n");
printf("<CENTER>\n");
printf("<TABLE BORDER=0>\n");
printf("\t<TR HEIGHT=36><TD COLSPAN=4>&nbsp</TD></TR>\n");
printf("\t<TR><TD COLSPAN=%d ALIGN=CENTER><FONT SIZE=+1><EM>bind8 status %s</EM></FONT></TD></TR>\n", $Ncols, $when);
printf("\t<TR HEIGHT=36><TD COLSPAN=4>&nbsp</TD></TR>\n");
printf("\t<TR>\n");
printf("\t\t<TD WIDTH=150 ALIGN=LEFT><B>host</B></TD>\n");
printf("\t\t<TD WIDTH=100 ALIGN=LEFT><B>build status</B></TD>\n");
printf("\t\t<TD WIDTH=100 ALIGN=LEFT><B>fatal/other</B></TD>\n");
printf("\t\t<TD WIDTH=100 ALIGN=LEFT><B>test status</B></TD>\n") if ($HasTests);
printf("\t</TR>\n");
printf("<TR><TD COLSPAN=%d><HR></TD></TR>\n", $Ncols);
#
# produce status info for each host
#
foreach $host (sort @hosts) {
&doHost($host);
}
#
# output end of page
#
printf("\n");
printf("</TABLE>\n");
printf("\n");
printf("<?php include(\"isc-footer.inc\") ?>\n");
close(DEBUG) if ($Debug);
#
# produce status for host @ $hostpath
#
sub doHost {
local($hostid) = @_;
local($entry, $prob, $line, $bstatus, $tstatus);
local(@junk, $junk, $hostname, $bcolor, $tcolor);
local(%buildprobs, %testprobs);
local($severity, $filename, $linenumber, $message, $lastfilename);
#
# get the host name
#
$hostname = "n/a";
if ((-r "$MasterDir/hosts/$hostid/$UnameFile") && (-s _)) {
open(XXX, "< $MasterDir/hosts/$hostid/$UnameFile");
$junk = <XXX>;
close(XXX);
@junk = split(/\s/, $junk);
($hostname = $junk[1]) =~ s/\..*//;
}
print DEBUG "Host: $hostid, Hostname: $hostname\n" if ($Debug);
#
# scan the build and test results files for problems
#
$Nfbp = 0;
$Nobp = 0;
$Nftp = 0;
$Notp = 0;
$BadTest = 0;
$BadTestReason = "";
if ((-r "$DataDir/hosts/$hostid/$BuildFile") && (-s _ )) {
%buildprobs = &buildCheck("$hostid");
if ($NoPort) {
$bstatus = "none (no port)";
$bcolor = "black";
}
elsif ($Nfbp == 0) {
$bstatus = "ok";
$bcolor = "green";
$tstatus = "n/a";
if ($HasTests) {
if ((-r "$DataDir/hosts/$hostid/$TestFile") && (-s _)) {
%testprobs = &testCheck("$hostid");
if ($BadTest) {
$tstatus = "inspect ($BadTestReason)";
$tcolor = "blue";
}
else {
if ($Nftp) {
$tstatus = "fail";
$tcolor = "red";
}
else {
$tstatus = "pass";
$tcolor = "green";
}
}
}
else {
$tstatus = "none (no journal)";
$tcolor = "red";
}
}
}
else {
$bstatus = "broken";
$tstatus = "none (build status)";
$bcolor = "red";
$tcolor = "black";
}
}
else {
$bstatus = "none";
$tstatus = "none (build status)";
$bcolor = "red";
$tcolor = "black";
}
printf(DEBUG "Host %s(%s) STATUS: bstatus %s, tstatus %s, badtest %d, reason %s\n", $hostid, $hostname, $bstatus, $tstatus, $BadTest, $BadTestReason) if ($Debug);
printf("\t<TR>\n");
printf("\t\t<TD><B>%s</B>&nbsp;%s</TD>\n", $hostid, $hostname);
if ($bstatus =~ /none/) {
printf("\t\t<TD>%s</TD>\n", $bstatus);
printf("\t\t<TD>&nbsp</TD>\n");
}
else {
printf("\t\t<TD>");
printf("<A HREF=\"$HttpHomeURL/hosts/$hostid/$BuildFile\"><FONT COLOR=\"%s\">%s</FONT></A>", $bcolor, $bstatus);
printf("</TD>\n");
printf("\t\t<TD>");
printf("<A HREF=\"$HttpHomeURL/hosts/$hostid/$BstatusFile\"><FONT COLOR=\"%s\">%d/%d</FONT></A>", $bcolor, $Nfbp, $Nobp);
printf("</TD>\n");
}
if ($HasTests) {
if ($tstatus =~ /none/) {
printf("\t\t<TD><FONT COLOR=\"%s\">%s</FONT></TD>\n", $tcolor, $tstatus);
}
else {
printf("\t\t<TD><A HREF=\"$HttpHomeURL/hosts/$hostid/$TstatusFile\"><FONT COLOR=\"%s\">%s</FONT></A></TD>\n", $tcolor, $tstatus);
}
}
printf("\t</TR>\n");
#
# write the build problems file
#
&wbpf($hostid, %buildprobs);
}
#
# scan the build results file for hostid for build problems
# return %probs
# format key == filename:linenumber:severity, content == text of problem line
# set $Nfbp and $Nobp as a side effect
#
sub buildCheck {
local($hostid) = @_;
local($filename, $linenumber, $severity);
local(%probs, %wkbp, @rxset);
local($matched, $exp, $entry, $ccrx);
$NoPort = 0;
# initialize the well known build problems array, if available
if (-r "$MasterDir/hosts/$hostid/$WkbpFile") {
open(XXX, "< _");
while(<XXX>) {
next if /^\#/; # skip comments
next if /^\s*$/; # and blank lines
chop;
($filename, $linenumber) = split;
$wkbp{"$filename:$linenumber"} = 1;
}
close(XXX);
}
# initialize the host specific regex array, if available
if (-r "$MasterDir/hosts/$hostid/$RxFile") {
open(XXX, "< _");
while(<XXX>) {
next if /^\#/; # skip comments
next if /^\s*$/; # and blank lines
chop;
printf(DEBUG "RX: <%s>\n", $_) if ($Debug);
push(@rxset, $_);
}
close(XXX);
}
# scan stdout/stderr of make all for problems
open(XXX, "< $DataDir/hosts/$hostid/$BuildFile");
while (<XXX>) {
undef $filename;
undef $linenumber;
undef $severity;
undef $1;
undef $2;
$matched = 0;
chop;
if (/no BIND port/) {
$NoPort = 1;
last;
}
foreach $entry (@rxset) {
($severity, $exp) = split(/\s/, $entry, 2);
if (/$exp/) {
$filename = $1 if defined($1);
$linenumber = $2 if defined($2);
$matched = 1;
last;
}
}
next unless $matched;
if ($Debug) {
printf(DEBUG "LINE %d: %s\n", $., $_);
printf(DEBUG "MATCHES: exp<%s>\tfn<%s>\tln<%s>\tsev<%s>\n", $exp, $filename, $linenumber, $severity);
}
if (length($filename) && length($linenumber)) {
$filename = $1 if ($filename =~ /.*(bind.*)/);
# ignore it if its in the well known build problems list
if (defined($wkbp{"$filename:$linenumber"})) {
print DEBUG "IGNORED\n" if ($Debug);
# by convention, ignore all severity 0 problems
$severity = 0;
}
}
else {
$filename = "MISC";
$linenumber = "0";
}
# avoid duplicates
next if (index($probs{"$filename:$linenumber:$severity"}, $_) >= 0);
$probs{"$filename:$linenumber:$severity"} .= "$_\n";
if ($severity >= $HaltLevel) {
++$Nfbp;
}
else {
++$Nobp;
}
printf(DEBUG "PROBLEM: fn<%s>\tln<%s>\tsev<%s>\n\n", $filename, $linenumber, $severity) if ($Debug);
}
close(XXX);
return(%probs);
}
#
# run thru the test results file for hostid
# write the test results file
# return %probs
# format key == funcname:assertion_number, value == test_result
# set $Nftp and $Notp as a side effect
#
sub testCheck {
local($hostid) = @_;
local($funcname, $anum, $atext);
local(%probs, @junk, $junk);
local($intest, $intestcase, $inassert, $ininfo, $inresult, $ntestsets);
# initialize the well known test problems array
if (-f "$MasterDir/hosts/$hostid/$WktpFile") {
open(XXX, "< _");
while(<XXX>) {
next if /^\#/; # skip comments
chop;
($funcname, $anum) = split;
$wktp{"$funcname:$anum"} = 1;
}
close(XXX);
}
if (! -r "$MasterDir/hosts/$hostid/$TestFile") {
$BadTest = 1;
$BadTestReason = "no journal file";
printf(DEBUG "No test journal at %s\n", "$hostpath/$TestFile") if ($Debug);
return;
}
$intest = 0;
open(XXX, "< $DataDir/hosts/$hostid/$TestFile");
open(YYY, "> $DataDir/hosts/$hostid/$TstatusFile");
printf(YYY "<?php \$title = \"ISC Status Server $hostid Bind8 Test Results\"; ?>\n");
printf(YYY "<?php include(\"status-isc-header.inc\") ?>\n");
printf(YYY "\n");
while (<XXX>) {
next unless ($_ =~ /^(S|I|T|A|R|E):/);
chop;
if (/^S:([^:]*):(Mon|Tue|Wed|Thu|Fri|Sat|Sun)/) {
$intest = 1;
$testname = $1;
++$ntestsets;
printf(YYY "%s\n<BR>\n", $_);
next;
}
if (/^E:(Mon|Tue|Wed|Thu|Fri|Sat|Sun)/) {
$intest = 0;
printf(YYY "%s\n<BR>\n", $_);
next;
}
if (/^T:([^:]*):([^:]*):/) {
if ($intest == 0) {
$BadTest = 1;
$BadTestReason = "T$.";
}
$funcname = $1;
$anum = $2;
$intestcase = 1;
$inassert = 0;
$ininfo = 0;
$inresult = 0;
($junk = $funcname) =~ s/\//\\\//g;
s/$junk/<B>$1<\/B>/;
printf(YYY "%s\n<BR>\n", $_);
next;
}
if (/^A:(.*)$/) {
if (($intest == 0) || ($intestcase == 0) || ($inresult == 1)) {
$BadTest = 1;
$BadTestReason = "A$.";
}
$atext = $1;
$inassert = 1;
s/A:(.*)/A:<FONT COLOR=\"blue\">$1<\/FONT>/;
printf(YYY "%s\n<BR>\n", $_);
next;
}
if (/^I:(.*)$/) {
if (($intest == 0) || ($intestcase == 0) || ($inassert == 0)) {
$BadTest = 1;
$BadTestReason = "I$.";
}
$ininfo = 1;
s/</\&lt;/g;
s/>/\&gt;/g;
printf(YYY "%s\n<BR>\n", $_);
next;
}
if (/^R:(.*)$/) {
if (($intest == 0) || ($intestcase == 0) || ($inassert == 0)) {
$BadTest = 1;
$BadTestReason = "R:$intest:$intestcase:$inassert:$.";
}
$result = $1;
$inresult = 1;
if ($result =~ /FAIL|UNRESOLVED|UNINITIATED/) {
#
# skip if in the (ignorable) well known test problems list
#
if (defined($wktp{"$funcname:$anum"})) {
++$Notp;
}
else {
$probs{"$funcname:$anum"} = $result;
++$Nftp;
s/(FAIL|UNINITIATED)/<FONT COLOR=\"red\">$1<\/FONT>/;
s/(UNRESOLVED)/<FONT COLOR=\"yellow\">$1<\/FONT>/;
}
}
elsif ($result =~ /PASS|UNTESTED/) {
s/(PASS|UNTESTED)/<FONT COLOR=\"green\">$1<\/FONT>/;
}
printf(YYY "%s\n<BR>\n", $_);
next;
}
}
close(XXX);
printf(YYY "<?php include(\"isc-footer.inc\") ?>\n");
close(YYY);
if ($ntestsets == 0) {
$BadTest = 1;
$BadTestReason = "no tests";
}
return(%probs);
}
#
# write the build problems file
#
sub wbpf {
local($hostid, %buildprobs) = @_;
local($prob, $filename, $lastfilename, $linenumber, $severity);
local(@messageset, $message);
open(XXX, "> $DataDir/hosts/$hostid/$BstatusFile");
printf(XXX "<?php \$title = \"ISC Status Server $hostid Bind8 Build Problems\"; ?>\n");
printf(XXX "<?php include(\"status-isc-header.inc\") ?>\n");
printf(XXX "\n");
foreach $prob (sort keys %buildprobs) {
($filename, $linenumber, $severity) = split(/\:/, $prob);
printf(XXX "<P><B>%s</B>\n<BR>\n", $filename) if ($filename ne $lastfilename);
@messageset = split(/\n/, $buildprobs{$prob});
foreach $message (@messageset) {
if ($severity >= $HaltLevel) {
printf(XXX "<FONT COLOR=\"red\">%s</FONT>\n<BR>\n", $message);
}
elsif ($severity == 0) {
printf(XXX "<FONT COLOR=\"yellow\">%s</FONT>\n<BR>\n", $message);
}
else {
printf(XXX "%s\n<BR>\n", $message);
}
}
$lastfilename = $filename;
}
printf(XXX "<?php include(\"isc-footer.inc\") ?>\n");
close(XXX);
}

View File

@@ -1,63 +0,0 @@
# Copyright (C) 1999, 2000 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: b8t.mk,v 1.5 2000/06/22 21:50:06 tale Exp $
#
# bind 8 multi-host make
# PLATFORM set in the environment by cron
#
MODULE = bind
BASE = /build
BDIR = $(BASE)/$(MODULE)
RDIR = /proj/build-reports/bind8/hosts/$(PLATFORM)
SDIR = $(HOME)/b8t/src
CVSROOT = /proj/cvs/isc
all: clobber populate config build
clobber:
@echo "CLOBBBER `date`"
@if test ! -d $(BASE) ; then mkdir -p $(BASE) ; fi
@rm -fr $(BDIR)
@echo "DONE `date`"
populate:
@echo "POPULATE `date`"
@( cd $(BASE) && tar -xvf $(SDIR)/$(MODULE).tar ) > $(RDIR)/.populate 2>&1
@echo "DONE `date`"
tarsrc:
@echo "TARSRC `date`"
@rm -fr $(SDIR)/$(MODULE)
@( cd $(SDIR) && cvs -d $(CVSROOT) checkout $(MODULE) )
@( cd $(SDIR) && tar -cvf $(MODULE).tar $(MODULE) )
@echo "DONE `date`"
config:
@echo "CONFIG `date`"
@( cd $(BDIR)/src && make SRC=$(BDIR)/src DST=$(BDIR)/dst links ) > $(RDIR)/.config 2>&1
@echo "DONE `date`"
build:
@echo "BUILD `date`"
@( cd $(BDIR)/dst && make -k clean depend all ) > $(RDIR)/.build 2>&1
@echo "DONE `date`"
test:
@echo "TEST `date`"
@touch $(RDIR)/.test
@echo "DONE `date`"

View File

@@ -1,529 +0,0 @@
# Copyright (C) 1999, 2000 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: b9status.pl,v 1.8 2000/06/22 21:50:08 tale Exp $
#
# aggregate reports from all bind9 build environments
# write a summary of results in html format
#
$Debug = 1;
$Home = $ENV{"HOME"};
$DebugFile = "$Home/b9t/b9tsummary.dbg";
#
# level of severity at which a fatal error is considered to have occurred
#
$HaltLevel = 2;
$Module = "bind9";
$HttpHostURL = "http://status.isc.org/$Module/hosts";
# path to directory containing host specific control info
$HomePath = "$Home/b9t/hosts";
$WkbpFile = ".wkbp";
$WktpFile = ".wktp";
$RxFile = ".b9trx";
$UnameFile = "uname";
# path to directory containing host specific data files and www reports
$HostPath = "/proj/build-reports/$Module/hosts";
$ConfigFile = ".config";
$BuildFile = ".build";
$TestFile = ".test";
$TestStatusFile = "tstatus.html";
$BuildStatusFile = "bstatus.html";
# number of fatal build problems
$Nfbp = 0;
# number of other build problems
$Nobp = 0;
# number of fatal test problems
$Nftp = 0;
# number of other test problems
$Notp = 0;
# flag to signal bad test journal format
$BadTest = 0;
$BadTestReason = "";
#
# initialize the host array
#
open(DEBUG, "> $DebugFile") if ($Debug);
opendir(HDIR, $HostPath);
@entries = readdir(HDIR);
closedir(HDIR);
foreach $entry (@entries) {
next if $entry =~ /^\.\.*$/;
next unless -d "$HostPath/$entry";
push(hosts, $entry);
}
#
# put the page top
#
$when = `date`;
chop $when;
printf("<?php \$title = \"ISC Status Server\"; ?>\n");
printf("<?php include(\"status-isc-header.inc\") ?>\n");
printf("\n");
printf("<CENTER>\n");
printf("<TABLE BORDER=0>\n");
printf("\t<TR HEIGHT=36><TD COLSPAN=4>&nbsp</TD></TR>\n");
printf("\t<TR><TD COLSPAN=4 ALIGN=CENTER><FONT SIZE=+1><EM>bind9 status %s</EM></FONT></TD></TR>\n", $when);
printf("\t<TR HEIGHT=36><TD COLSPAN=4>&nbsp</TD></TR>\n");
printf("\t<TR>\n");
printf("\t\t<TD WIDTH=150 ALIGN=LEFT><B>host</B></TD>\n");
printf("\t\t<TD WIDTH=100 ALIGN=LEFT><B>build status</B></TD>\n");
printf("\t\t<TD WIDTH=100 ALIGN=LEFT><B>fatal/other</B></TD>\n");
printf("\t\t<TD WIDTH=100 ALIGN=LEFT><B>test status</B></TD>\n");
printf("\t</TR>\n");
printf("<TR><TD COLSPAN=4><HR></TD></TR>\n");
#
# produce status info for each host
#
foreach $host (sort @hosts) {
&doHost($host);
}
#
# output end of page
#
printf("\n");
printf("</TABLE>\n");
printf("\n");
printf("<?php include(\"isc-footer.inc\") ?>\n");
close(DEBUG) if ($Debug);
#
# produce status for host @ $hostpath
#
sub doHost {
local($hostid) = @_;
local($entry, $prob, $line, $bstatus, $tstatus);
local(@junk, $junk, $hostname, $bcolor, $tcolor);
local(%buildprobs, %testprobs);
local($severity, $filename, $linenumber, $message, $lastfilename);
mkdir("$HostPath/$hostid", 0755) if (! -d "$HostPath/$hostid");
#
# get the host name
#
$hostname = "n/a";
if ((-r "$HomePath/$hostid/$UnameFile") && (-s _)) {
open(XXX, "< $HomePath/$hostid/$UnameFile");
$junk = <XXX>;
close(XXX);
@junk = split(/\s/, $junk);
$hostname = $junk[1];
$hostname =~ s/\..*//;
}
print DEBUG "Host: $hostid, Hostname: $hostname\n" if ($Debug);
#
# scan the build and test results files for problems
#
$Nfbp = 0;
$Nobp = 0;
$Nftp = 0;
$Notp = 0;
$BadTest = 0;
$BadTestReason = "";
if ((-r "$HostPath/$hostid/$BuildFile") && (-s _)) {
%buildprobs = &buildCheck($hostid);
if ($Nfbp == 0) {
$bstatus = "ok";
$bcolor = "green";
if ((-r "$HostPath/$hostid/$TestFile") && (-s _)) {
%testprobs = &testCheck($hostid);
if ($BadTest) {
$tstatus = "inspect ($BadTestReason)";
$tcolor = "blue";
}
else {
if ($Nftp) {
$tstatus = "fail";
$tcolor = "red";
}
else {
$tstatus = "pass";
$tcolor = "green";
}
}
}
else {
$tstatus = "none (no journal)";
$tcolor = "red";
}
}
else {
$bstatus = "broken";
$tstatus = "none (build status)";
$bcolor = "red";
$tcolor = "black";
}
}
else {
$bstatus = "none";
$tstatus = "none (build status)";
$bcolor = "red";
$tcolor = "black";
}
printf(DEBUG "Host %s(%s) STATUS: bstatus %s, tstatus %s, badtest %d, reason %s\n", $hostid, $hostname, $bstatus, $tstatus, $BadTest, $BadTestReason) if ($Debug);
printf("\t<TR>\n");
printf("\t\t<TD><B>%s</B>&nbsp;%s</TD>\n", $hostid, $hostname);
if ($bstatus =~ /none/) {
printf("\t\t<TD>%s</TD>\n", $bstatus);
printf("\t\t<TD>&nbsp</TD>\n");
}
else {
printf("\t\t<TD>");
printf("<A HREF=\"$HttpHostURL/$hostid/$BuildFile\"><FONT COLOR=\"%s\">%s</FONT></A>", $bcolor, $bstatus);
printf("</TD>\n");
printf("\t\t<TD>");
printf("<A HREF=\"$HttpHostURL/$hostid/$BuildStatusFile\"><FONT COLOR=\"%s\">%d/%d</FONT></A>", $bcolor, $Nfbp, $Nobp);
printf("</TD>\n");
}
if ($tstatus =~ /none/) {
printf("\t\t<TD><FONT COLOR=\"%s\">%s</FONT></TD>\n", $tcolor, $tstatus);
}
else {
printf("\t\t<TD><A HREF=\"$HttpHostURL/$hostid/$TestStatusFile\"><FONT COLOR=\"%s\">%s</FONT></A></TD>\n", $tcolor, $tstatus);
}
printf("\t</TR>\n");
#
# write the build problems file
#
&wbpf($hostid, %buildprobs) if ($Nfbp + $Nobp);
}
#
# scan the build results file for host at $hostpath for build problems
# return %probs
# format key == filename:linenumber:severity, content == text of problem line
# set $Nfbp and $Nobp as a side effect
#
sub buildCheck {
local($hostid) = @_;
local($filename, $linenumber, $severity);
local(%probs, %wkbp, @rxset);
local($matched, $exp, $entry, $ccrx);
# initialize the well known build problems array, if available
if (-r "$HomePath/$hostid/$WkbpFile") {
open(XXX, "< $HomePath/$hostid/$WkbpFile");
while(<XXX>) {
next if /^\#/; # skip comments
next if /^\s*$/; # and blank lines
chop;
($filename, $linenumber) = split;
$wkbp{"$filename:$linenumber"} = 1;
}
close(XXX);
}
# initialize the host specific regex array, if available
if (-r "$HomePath/$hostid/$RxFile") {
open(XXX, "< $HomePath/$hostid/$RxFile");
while(<XXX>) {
next if /^\#/; # skip comments
next if /^\s*$/; # and blank lines
chop;
printf(DEBUG "RX: <%s>\n", $_) if ($Debug);
push(@rxset, $_);
}
close(XXX);
}
# scan stdout/stderr of make all for problems
open(XXX, "< $HostPath/$hostid/$BuildFile");
while (<XXX>) {
undef $filename;
undef $linenumber;
undef $severity;
undef $1;
undef $2;
$matched = 0;
chop;
foreach $entry (@rxset) {
($severity, $exp) = split(/\s/, $entry, 2);
if (/$exp/) {
$filename = $1 if defined($1);
$linenumber = $2 if defined($2);
$matched = 1;
last;
}
}
next unless $matched;
if ($Debug) {
printf(DEBUG "LINE %d: %s\n", $., $_);
printf(DEBUG "MATCHES: exp<%s>\tfn<%s>\tln<%s>\tsev<%s>\n", $exp, $filename, $linenumber, $severity);
}
if (length($filename) && length($linenumber)) {
$filename = $1 if ($filename =~ /.*(bind9.*)/);
# ignore it if its in the well known build problems list
if (defined($wkbp{"$filename:$linenumber"})) {
print DEBUG "IGNORED\n" if ($Debug);
# by convention, ignore all severity 0 problems
$severity = 0;
}
}
else {
$filename = "MISC";
$linenumber = "0";
}
# avoid duplicates
next if (index($probs{"$filename:$linenumber:$severity"}, $_) >= 0);
$probs{"$filename:$linenumber:$severity"} .= "$_\n";
if ($severity >= $HaltLevel) {
++$Nfbp;
}
else {
++$Nobp;
}
printf(DEBUG "PROBLEM: fn<%s>\tln<%s>\tsev<%s>\n\n", $filename, $linenumber, $severity) if ($Debug);
}
close(XXX);
return(%probs);
}
#
# run thru the test results file for $hostid
# write the test results file
# return %probs
# format key == funcname:assertion_number, value == test_result
# set $Nftp and $Notp as a side effect
#
sub testCheck {
local($hostid) = @_;
local($funcname, $anum, $atext);
local(%probs, @junk, $junk);
local($intest, $intestcase, $inassert, $ininfo, $inresult, $ntestsets);
# initialize the well known test problems array
if (-f "$HomePath/$hostid/$WktpFile") {
open(XXX, "< $HomePath/$hostid/$WktpFile");
while(<XXX>) {
next if /^\#/; # skip comments
chop;
($funcname, $anum) = split;
$wktp{"$funcname:$anum"} = 1;
}
close(XXX);
}
if (! -r "$HostPath/$hostid/$TestFile") {
$BadTest = 1;
$BadTestReason = "no journal file";
printf(DEBUG "No test journal at %s\n", "$hostpath/$TestFile") if ($Debug);
return;
}
$intest = 0;
open(XXX, "< $HostPath/$hostid/$TestFile");
open(YYY, "> $HostPath/$hostid/$TestStatusFile");
printf(YYY "<?php \$title = \"ISC Status Server $hostid Bind9 Test Results\"; ?>\n");
printf(YYY "<?php include(\"status-isc-header.inc\") ?>\n");
printf(YYY "\n");
while (<XXX>) {
next unless ($_ =~ /^(S|I|T|A|R|E):/);
chop;
if (/^S:([^:]*):(Mon|Tue|Wed|Thu|Fri|Sat|Sun)/) {
$intest = 1;
$testname = $1;
++$ntestsets;
printf(YYY "%s\n<BR>\n", $_);
next;
}
if (/^E:[^:]*:(Mon|Tue|Wed|Thu|Fri|Sat|Sun)/) {
if ($inresult == 0) {
# no reported result
$BadTest = 1;
$BadTestReason = "E$.";
}
$intest = 0;
printf(YYY "%s\n<BR>\n", $_);
next;
}
if (/^T:([^:]*):([^:]*):/) {
if ($intest == 0) {
$BadTest = 1;
$BadTestReason = "T$.";
}
$funcname = $1;
$anum = $2;
$intestcase = 1;
$inassert = 0;
$ininfo = 0;
$inresult = 0;
($junk = $funcname) =~ s/\//\\\//g;
s/$junk/<B>$1<\/B>/;
printf(YYY "%s\n<BR>\n", $_);
next;
}
if (/^A:(.*)$/) {
if (($intest == 0) || ($intestcase == 0) || ($inresult == 1)) {
$BadTest = 1;
$BadTestReason = "A$.";
}
$atext = $1;
$inassert = 1;
s/A:(.*)/A:<FONT COLOR=\"blue\">$1<\/FONT>/;
printf(YYY "%s\n<BR>\n", $_);
next;
}
if (/^I:(.*)$/) {
if (($intest == 0) || ($intestcase == 0) || ($inassert == 0)) {
$BadTest = 1;
$BadTestReason = "I$.";
}
$ininfo = 1;
s/</\&lt;/g;
s/>/\&gt;/g;
printf(YYY "%s\n<BR>\n", $_);
next;
}
if (/^R:(.*)$/) {
if (($intest == 0) || ($intestcase == 0) || ($inassert == 0)) {
$BadTest = 1;
$BadTestReason = "R:$intest:$intestcase:$inassert:$.";
}
$result = $1;
$inresult = 1;
if ($result =~ /FAIL|UNRESOLVED|UNINITIATED/) {
#
# skip if in the (ignorable) well known test problems list
#
if (defined($wktp{"$funcname:$anum"})) {
++$Notp;
}
else {
$probs{"$funcname:$anum"} = $result;
++$Nftp;
s/(FAIL|UNINITIATED)/<FONT COLOR=\"red\">$1<\/FONT>/;
s/(UNRESOLVED)/<FONT COLOR=\"orange\">$1<\/FONT>/;
}
}
elsif ($result =~ /PASS|UNTESTED/) {
s/(PASS|UNTESTED)/<FONT COLOR=\"green\">$1<\/FONT>/;
}
printf(YYY "%s\n<BR>\n", $_);
next;
}
}
close(XXX);
printf(YYY "<?php include(\"isc-footer.inc\") ?>\n");
close(YYY);
if ($ntestsets == 0) {
$BadTest = 1;
$BadTestReason = "no tests";
}
if ($intest) {
$BadTest = 1;
$BadTestReason = "incomplete";
}
return(%probs);
}
#
# write the build problems file
#
sub wbpf {
local($hostid, %buildprobs) = @_;
local($prob, $filename, $lastfilename, $linenumber, $severity);
local(@messageset, $message);
open(XXX, "> $HostPath/$hostid/$BuildStatusFile");
printf(XXX "<?php \$title = \"ISC Status Server $hostid Bind9 Build Problems\"; ?>\n");
printf(XXX "<?php include(\"status-isc-header.inc\") ?>\n");
printf(XXX "\n");
foreach $prob (sort keys %buildprobs) {
($filename, $linenumber, $severity) = split(/\:/, $prob);
printf(XXX "<P><B>%s</B>\n<BR>\n", $filename) if ($filename ne $lastfilename);
@messageset = split(/\n/, $buildprobs{$prob});
foreach $message (@messageset) {
if ($severity >= $HaltLevel) {
printf(XXX "<FONT COLOR=\"red\">%s</FONT>\n<BR>\n", $message);
}
elsif ($severity == 0) {
printf(XXX "<FONT COLOR=\"orange\">%s</FONT>\n<BR>\n", $message);
}
else {
printf(XXX "%s\n<BR>\n", $message);
}
}
$lastfilename = $filename;
}
printf(XXX "<?php include(\"isc-footer.inc\") ?>\n");
close(XXX);
}

View File

@@ -1,68 +0,0 @@
# Copyright (C) 1999, 2000 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: b9t.mk,v 1.7 2000/06/22 21:50:09 tale Exp $
#
# makefile to configure, build and test bind9
# this is run by cron (user wpk) on aa, sol, irix, hp and aix
# $PLATFORM is set in the environment by cron
#
BASE = /build
BDIR = $(BASE)
MODULE = bind9
SDIR = $(HOME)/b9t/src
# as it says
CVSROOT = /proj/cvs/isc
# where the config, build and test output goes
RDIR = /proj/build-reports/$(MODULE)/hosts/$(PLATFORM)
all: clobber populate config build test
clobber:
@echo "CLOBBBER `date`"
@if test ! -d $(BDIR) ; then mkdir -p $(BDIR) > /dev/null 2>&1 ; fi
@( cd $(BDIR) && rm -fr $(MODULE) )
@echo "DONE `date`"
populate:
@echo "POPULATE `date`"
@( cd $(BDIR) && tar -xvf $(SDIR)/$(MODULE).tar ) > $(RDIR)/.populate 2>&1
@echo "DONE `date`"
config:
@echo "CONFIG `date`"
@( cd $(BDIR)/$(MODULE) && ./configure ) > $(RDIR)/.config 2>&1
@echo "DONE `date`"
build:
@echo "BUILD `date`"
@( cd $(BDIR)/$(MODULE) && $(MAKE) -k all ) > $(RDIR)/.build 2>&1
@echo "DONE `date`"
test:
@echo "TEST `date`"
-@( cd $(BDIR)/$(MODULE)/bin/tests && $(MAKE) test ) > $(RDIR)/.test 2>&1
@echo "DONE `date`"
tarsrc:
@echo "TARSRC `date`"
@rm -fr $(SDIR)/$(MODULE)
@( cd $(SDIR) && cvs -d $(CVSROOT) checkout $(MODULE) && tar -cvf $(MODULE).tar $(MODULE) )
@echo "DONE `date`"

View File

@@ -1,262 +0,0 @@
/*
* Copyright (C) 2000 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: byaddr_test.c,v 1.16.2.1 2000/06/28 16:45:24 gson Exp $ */
/*
* Principal Author: Bob Halley
*/
#include <config.h>
#include <stdlib.h>
#include <isc/app.h>
#include <isc/commandline.h>
#include <isc/mem.h>
#include <isc/netaddr.h>
#include <isc/task.h>
#include <isc/timer.h>
#include <isc/util.h>
#include <dns/byaddr.h>
#include <dns/cache.h>
#include <dns/dispatch.h>
#include <dns/events.h>
#include <dns/resolver.h>
#include <dns/result.h>
#include <dns/view.h>
static void
done(isc_task_t *task, isc_event_t *event) {
dns_byaddrevent_t *bevent;
dns_byaddr_t *byaddr;
dns_name_t *name;
REQUIRE(event->ev_type == DNS_EVENT_BYADDRDONE);
bevent = (dns_byaddrevent_t *)event;
UNUSED(task);
printf("byaddr event result = %s\n",
isc_result_totext(bevent->result));
if (bevent->result == ISC_R_SUCCESS) {
for (name = ISC_LIST_HEAD(bevent->names);
name != NULL;
name = ISC_LIST_NEXT(name, link)) {
char text[1024];
dns_name_format(name, text, sizeof(text));
printf("%s\n", text);
}
}
byaddr = event->ev_sender;
dns_byaddr_destroy(&byaddr);
isc_event_free(&event);
isc_app_shutdown();
}
int
main(int argc, char *argv[]) {
isc_mem_t *mctx;
isc_boolean_t verbose = ISC_FALSE;
unsigned int workers = 2;
isc_taskmgr_t *taskmgr;
isc_task_t *task;
isc_timermgr_t *timermgr;
dns_view_t *view;
int ch;
isc_socketmgr_t *socketmgr;
dns_dispatchmgr_t *dispatchmgr;
isc_netaddr_t na;
dns_byaddr_t *byaddr;
isc_result_t result;
unsigned int options = 0;
dns_cache_t *cache;
RUNTIME_CHECK(isc_app_start() == ISC_R_SUCCESS);
dns_result_register();
mctx = NULL;
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
while ((ch = isc_commandline_parse(argc, argv, "nvw:")) != -1) {
switch (ch) {
case 'n':
options |= DNS_BYADDROPT_IPV6NIBBLE;
break;
case 'v':
verbose = ISC_TRUE;
break;
case 'w':
workers = (unsigned int)atoi(isc_commandline_argument);
break;
}
}
if (verbose) {
printf("%u workers\n", workers);
printf("IPv4: %s\n", isc_result_totext(isc_net_probeipv4()));
printf("IPv6: %s\n", isc_result_totext(isc_net_probeipv6()));
}
taskmgr = NULL;
RUNTIME_CHECK(isc_taskmgr_create(mctx, workers, 0, &taskmgr)
== ISC_R_SUCCESS);
task = NULL;
RUNTIME_CHECK(isc_task_create(taskmgr, 0, &task)
== ISC_R_SUCCESS);
isc_task_setname(task, "byaddr", NULL);
dispatchmgr = NULL;
RUNTIME_CHECK(dns_dispatchmgr_create(mctx, NULL, &dispatchmgr)
== ISC_R_SUCCESS);
timermgr = NULL;
RUNTIME_CHECK(isc_timermgr_create(mctx, &timermgr) == ISC_R_SUCCESS);
socketmgr = NULL;
RUNTIME_CHECK(isc_socketmgr_create(mctx, &socketmgr) == ISC_R_SUCCESS);
cache = NULL;
RUNTIME_CHECK(dns_cache_create(mctx, taskmgr, timermgr,
dns_rdataclass_in, "rbt", 0, NULL,
&cache) == ISC_R_SUCCESS);
view = NULL;
RUNTIME_CHECK(dns_view_create(mctx, dns_rdataclass_in, "default",
&view) == ISC_R_SUCCESS);
{
unsigned int attrs;
dns_dispatch_t *disp4 = NULL;
dns_dispatch_t *disp6 = NULL;
if (isc_net_probeipv4() == ISC_R_SUCCESS) {
isc_sockaddr_t any4;
isc_sockaddr_any(&any4);
attrs = DNS_DISPATCHATTR_IPV4 | DNS_DISPATCHATTR_UDP;
RUNTIME_CHECK(dns_dispatch_getudp(dispatchmgr,
socketmgr,
taskmgr, &any4,
512, 6, 1024,
17, 19, attrs,
attrs, &disp4)
== ISC_R_SUCCESS);
INSIST(disp4 != NULL);
}
if (isc_net_probeipv6() == ISC_R_SUCCESS) {
isc_sockaddr_t any6;
isc_sockaddr_any6(&any6);
attrs = DNS_DISPATCHATTR_IPV6 | DNS_DISPATCHATTR_UDP;
RUNTIME_CHECK(dns_dispatch_getudp(dispatchmgr,
socketmgr,
taskmgr, &any6,
512, 6, 1024,
17, 19, attrs,
attrs, &disp6)
== ISC_R_SUCCESS);
INSIST(disp6 != NULL);
}
RUNTIME_CHECK(dns_view_createresolver(view, taskmgr, 10,
socketmgr,
timermgr, 0,
dispatchmgr,
disp4, disp6) ==
ISC_R_SUCCESS);
if (disp4 != NULL)
dns_dispatch_detach(&disp4);
if (disp6 != NULL)
dns_dispatch_detach(&disp6);
}
{
struct in_addr ina;
isc_sockaddr_t sa;
isc_sockaddrlist_t sal;
ISC_LIST_INIT(sal);
ina.s_addr = inet_addr("127.0.0.1");
isc_sockaddr_fromin(&sa, &ina, 53);
ISC_LIST_APPEND(sal, &sa, link);
dns_resolver_setforwarders(view->resolver, &sal);
dns_resolver_setfwdpolicy(view->resolver, dns_fwdpolicy_only);
}
dns_view_setcache(view, cache);
dns_view_freeze(view);
dns_cache_detach(&cache);
printf("address = %s\n", argv[isc_commandline_index]);
na.family = AF_INET;
if (inet_pton(AF_INET, argv[isc_commandline_index],
(char *)&na.type.in) != 1) {
na.family = AF_INET6;
if (inet_pton(AF_INET6, argv[isc_commandline_index],
(char *)&na.type.in6) != 1) {
printf("unknown address format\n");
exit(1);
}
}
result = dns_byaddr_create(mctx, &na, view, options, task,
done, NULL, &byaddr);
if (result != ISC_R_SUCCESS) {
printf("dns_byaddr_create() returned %s\n",
isc_result_totext(result));
RUNTIME_CHECK(0);
}
(void)isc_app_run();
/*
* XXXRTH if we get a control-C before we get to isc_app_run(),
* we're in trouble (because we might try to destroy things before
* they've been created.
*/
dns_view_detach(&view);
isc_task_shutdown(task);
isc_task_detach(&task);
dns_dispatchmgr_destroy(&dispatchmgr);
isc_taskmgr_destroy(&taskmgr);
isc_socketmgr_destroy(&socketmgr);
isc_timermgr_destroy(&timermgr);
if (verbose)
isc_mem_stats(mctx, stdout);
isc_mem_destroy(&mctx);
isc_app_finish();
return (0);
}

View File

@@ -1,362 +0,0 @@
/*
* Copyright (C) 2000 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: byname_test.c,v 1.18.2.1 2000/06/28 16:45:25 gson Exp $ */
/*
* Principal Author: Bob Halley
*/
#include <config.h>
#include <stdlib.h>
#include <isc/app.h>
#include <isc/commandline.h>
#include <isc/netaddr.h>
#include <isc/task.h>
#include <isc/timer.h>
#include <isc/util.h>
#include <dns/adb.h>
#include <dns/cache.h>
#include <dns/dispatch.h>
#include <dns/events.h>
#include <dns/log.h>
#include <dns/resolver.h>
#include <dns/result.h>
static isc_mem_t *mctx = NULL;
static isc_taskmgr_t *taskmgr;
static dns_view_t *view = NULL;
static dns_adbfind_t *find = NULL;
static isc_task_t *task = NULL;
static dns_fixedname_t name;
static dns_fixedname_t target;
static isc_log_t *lctx;
static isc_logconfig_t *lcfg;
static unsigned int level = 0;
static void adb_callback(isc_task_t *task, isc_event_t *event);
static void
log_init(void) {
isc_logdestination_t destination;
unsigned int flags;
/*
* Setup a logging context.
*/
RUNTIME_CHECK(isc_log_create(mctx, &lctx, &lcfg) == ISC_R_SUCCESS);
isc_log_setcontext(lctx);
dns_log_init(lctx);
dns_log_setcontext(lctx);
/*
* Create and install the default channel.
*/
destination.file.stream = stderr;
destination.file.name = NULL;
destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0;
flags = ISC_LOG_PRINTTIME;
RUNTIME_CHECK(isc_log_createchannel(lcfg, "_default",
ISC_LOG_TOFILEDESC,
ISC_LOG_DYNAMIC,
&destination, flags) ==
ISC_R_SUCCESS);
RUNTIME_CHECK(isc_log_usechannel(lcfg, "_default", NULL, NULL) ==
ISC_R_SUCCESS);
isc_log_setdebuglevel(lctx, level);
}
static void
print_addresses(dns_adbfind_t *find) {
dns_adbaddrinfo_t *address;
for (address = ISC_LIST_HEAD(find->list);
address != NULL;
address = ISC_LIST_NEXT(address, publink)) {
isc_netaddr_t netaddr;
char text[ISC_NETADDR_FORMATSIZE];
isc_netaddr_fromsockaddr(&netaddr, &address->sockaddr);
isc_netaddr_format(&netaddr, text, sizeof(text));
printf("%s\n", text);
}
}
static void
print_name(dns_name_t *name) {
char text[1024];
dns_name_format(name, text, sizeof(text));
printf("%s\n", text);
}
static void
do_find(isc_boolean_t want_event) {
isc_result_t result;
isc_boolean_t done = ISC_FALSE;
unsigned int options;
options = DNS_ADBFIND_INET | DNS_ADBFIND_INET6;
if (want_event)
options |= DNS_ADBFIND_WANTEVENT | DNS_ADBFIND_EMPTYEVENT;
dns_fixedname_init(&target);
result = dns_adb_createfind(view->adb, task, adb_callback, NULL,
dns_fixedname_name(&name),
dns_rootname, options, 0,
dns_fixedname_name(&target), 0,
&find);
if (result == ISC_R_SUCCESS) {
if (!ISC_LIST_EMPTY(find->list)) {
/*
* We have at least some of the addresses for the
* name.
*/
INSIST((find->options & DNS_ADBFIND_WANTEVENT) == 0);
print_addresses(find);
done = ISC_TRUE;
} else {
/*
* We don't know any of the addresses for this
* name.
*/
if ((find->options & DNS_ADBFIND_WANTEVENT) == 0) {
/*
* And ADB isn't going to send us any events
* either. This query loses.
*/
done = ISC_TRUE;
}
/*
* If the DNS_ADBFIND_WANTEVENT flag was set, we'll
* get an event when something happens.
*/
}
} else if (result == DNS_R_ALIAS) {
print_name(dns_fixedname_name(&target));
done = ISC_TRUE;
} else {
printf("dns_adb_createfind() returned %s\n",
isc_result_totext(result));
done = ISC_TRUE;
}
if (done) {
if (find != NULL)
dns_adb_destroyfind(&find);
isc_app_shutdown();
}
}
static void
adb_callback(isc_task_t *etask, isc_event_t *event) {
unsigned int type = event->ev_type;
REQUIRE(etask == task);
isc_event_free(&event);
dns_adb_destroyfind(&find);
if (type == DNS_EVENT_ADBMOREADDRESSES)
do_find(ISC_FALSE);
else if (type == DNS_EVENT_ADBNOMOREADDRESSES) {
printf("no more addresses\n");
isc_app_shutdown();
} else {
printf("unexpected ADB event type %u\n", type);
isc_app_shutdown();
}
}
static void
run(isc_task_t *task, isc_event_t *event) {
UNUSED(task);
do_find(ISC_TRUE);
isc_event_free(&event);
}
int
main(int argc, char *argv[]) {
isc_boolean_t verbose = ISC_FALSE;
unsigned int workers = 2;
isc_timermgr_t *timermgr;
int ch;
isc_socketmgr_t *socketmgr;
dns_dispatchmgr_t *dispatchmgr;
dns_cache_t *cache;
isc_buffer_t b;
RUNTIME_CHECK(isc_app_start() == ISC_R_SUCCESS);
dns_result_register();
mctx = NULL;
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
while ((ch = isc_commandline_parse(argc, argv, "d:vw:")) != -1) {
switch (ch) {
case 'd':
level = (unsigned int)atoi(isc_commandline_argument);
break;
case 'v':
verbose = ISC_TRUE;
break;
case 'w':
workers = (unsigned int)atoi(isc_commandline_argument);
break;
}
}
log_init();
if (verbose) {
printf("%u workers\n", workers);
printf("IPv4: %s\n", isc_result_totext(isc_net_probeipv4()));
printf("IPv6: %s\n", isc_result_totext(isc_net_probeipv6()));
}
taskmgr = NULL;
RUNTIME_CHECK(isc_taskmgr_create(mctx, workers, 0, &taskmgr) ==
ISC_R_SUCCESS);
task = NULL;
RUNTIME_CHECK(isc_task_create(taskmgr, 0, &task) ==
ISC_R_SUCCESS);
isc_task_setname(task, "byname", NULL);
dispatchmgr = NULL;
RUNTIME_CHECK(dns_dispatchmgr_create(mctx, NULL, &dispatchmgr)
== ISC_R_SUCCESS);
timermgr = NULL;
RUNTIME_CHECK(isc_timermgr_create(mctx, &timermgr) == ISC_R_SUCCESS);
socketmgr = NULL;
RUNTIME_CHECK(isc_socketmgr_create(mctx, &socketmgr) == ISC_R_SUCCESS);
cache = NULL;
RUNTIME_CHECK(dns_cache_create(mctx, taskmgr, timermgr,
dns_rdataclass_in, "rbt", 0, NULL,
&cache) == ISC_R_SUCCESS);
view = NULL;
RUNTIME_CHECK(dns_view_create(mctx, dns_rdataclass_in, "default",
&view) == ISC_R_SUCCESS);
{
unsigned int attrs;
dns_dispatch_t *disp4 = NULL;
dns_dispatch_t *disp6 = NULL;
if (isc_net_probeipv4() == ISC_R_SUCCESS) {
isc_sockaddr_t any4;
isc_sockaddr_any(&any4);
attrs = DNS_DISPATCHATTR_IPV4 | DNS_DISPATCHATTR_UDP;
RUNTIME_CHECK(dns_dispatch_getudp(dispatchmgr,
socketmgr,
taskmgr, &any4,
512, 6, 1024,
17, 19, attrs,
attrs, &disp4)
== ISC_R_SUCCESS);
INSIST(disp4 != NULL);
}
if (isc_net_probeipv6() == ISC_R_SUCCESS) {
isc_sockaddr_t any6;
isc_sockaddr_any6(&any6);
attrs = DNS_DISPATCHATTR_IPV6 | DNS_DISPATCHATTR_UDP;
RUNTIME_CHECK(dns_dispatch_getudp(dispatchmgr,
socketmgr,
taskmgr, &any6,
512, 6, 1024,
17, 19, attrs,
attrs, &disp6)
== ISC_R_SUCCESS);
INSIST(disp6 != NULL);
}
RUNTIME_CHECK(dns_view_createresolver(view, taskmgr, 10,
socketmgr,
timermgr, 0,
dispatchmgr,
disp4, disp6) ==
ISC_R_SUCCESS);
if (disp4 != NULL)
dns_dispatch_detach(&disp4);
if (disp6 != NULL)
dns_dispatch_detach(&disp6);
}
{
struct in_addr ina;
isc_sockaddr_t sa;
isc_sockaddrlist_t sal;
ISC_LIST_INIT(sal);
ina.s_addr = inet_addr("127.0.0.1");
isc_sockaddr_fromin(&sa, &ina, 53);
ISC_LIST_APPEND(sal, &sa, link);
dns_resolver_setforwarders(view->resolver, &sal);
dns_resolver_setfwdpolicy(view->resolver, dns_fwdpolicy_only);
}
dns_view_setcache(view, cache);
dns_view_freeze(view);
dns_cache_detach(&cache);
printf("name = %s\n", argv[isc_commandline_index]);
isc_buffer_init(&b, argv[isc_commandline_index],
strlen(argv[isc_commandline_index]));
isc_buffer_add(&b, strlen(argv[isc_commandline_index]));
dns_fixedname_init(&name);
dns_fixedname_init(&target);
RUNTIME_CHECK(dns_name_fromtext(dns_fixedname_name(&name), &b,
dns_rootname, ISC_FALSE, NULL) ==
ISC_R_SUCCESS);
RUNTIME_CHECK(isc_app_onrun(mctx, task, run, NULL) == ISC_R_SUCCESS);
(void)isc_app_run();
dns_view_detach(&view);
isc_task_shutdown(task);
isc_task_detach(&task);
dns_dispatchmgr_destroy(&dispatchmgr);
isc_taskmgr_destroy(&taskmgr);
isc_socketmgr_destroy(&socketmgr);
isc_timermgr_destroy(&timermgr);
isc_log_destroy(&lctx);
if (verbose)
isc_mem_stats(mctx, stdout);
isc_mem_destroy(&mctx);
isc_app_finish();
return (0);
}

View File

@@ -1,219 +0,0 @@
/*
* Copyright (C) 1999, 2000 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: compress_test.c,v 1.18 2000/06/22 21:50:12 tale Exp $ */
#include <config.h>
#include <stdlib.h>
#include <isc/buffer.h>
#include <isc/commandline.h>
#include <isc/mem.h>
#include <isc/util.h>
#include <dns/compress.h>
#include <dns/name.h>
unsigned char plain1[] = "\003yyy\003foo";
unsigned char plain2[] = "\003bar\003yyy\003foo";
unsigned char plain3[] = "\003xxx\003bar\003foo";
unsigned char plain[] = "\003yyy\003foo\0\003bar\003yyy\003foo\0\003"
"bar\003yyy\003foo\0\003xxx\003bar\003foo";
/*
* Result concatenate (plain1, plain2, plain2, plain3).
*/
unsigned char bit1[] = "\101\010b";
unsigned char bit2[] = "\101\014b\260";
unsigned char bit3[] = "\101\020b\264";
unsigned char bit[] = "\101\010b\0\101\014b\260\0\101\014b\260\0\101\020b\264";
int raw = 0;
int verbose = 0;
void
test(unsigned int, dns_name_t *, dns_name_t *, dns_name_t *,
unsigned char *, unsigned int);
int
main(int argc, char *argv[]) {
dns_name_t name1;
dns_name_t name2;
dns_name_t name3;
isc_region_t region;
int c;
while ((c = isc_commandline_parse(argc, argv, "rv")) != -1) {
switch (c) {
case 'r':
raw++;
break;
case 'v':
verbose++;
break;
}
}
dns_name_init(&name1, NULL);
region.base = plain1;
region.length = sizeof plain1;
dns_name_fromregion(&name1, &region);
dns_name_init(&name2, NULL);
region.base = plain2;
region.length = sizeof plain2;
dns_name_fromregion(&name2, &region);
dns_name_init(&name3, NULL);
region.base = plain3;
region.length = sizeof plain3;
dns_name_fromregion(&name3, &region);
test(DNS_COMPRESS_NONE, &name1, &name2, &name3, plain, sizeof plain);
test(DNS_COMPRESS_GLOBAL14, &name1, &name2, &name3, plain,
sizeof plain);
test(DNS_COMPRESS_GLOBAL, &name1, &name2, &name3, plain, sizeof plain);
test(DNS_COMPRESS_ALL, &name1, &name2, &name3, plain, sizeof plain);
dns_name_init(&name1, NULL);
region.base = bit1;
region.length = sizeof bit1;
dns_name_fromregion(&name1, &region);
dns_name_init(&name2, NULL);
region.base = bit2;
region.length = sizeof bit2;
dns_name_fromregion(&name2, &region);
dns_name_init(&name3, NULL);
region.base = bit3;
region.length = sizeof bit3;
dns_name_fromregion(&name3, &region);
test(DNS_COMPRESS_NONE, &name1, &name2, &name3, bit, sizeof bit);
test(DNS_COMPRESS_GLOBAL14, &name1, &name2, &name3, bit, sizeof bit);
test(DNS_COMPRESS_GLOBAL, &name1, &name2, &name3, bit, sizeof bit);
test(DNS_COMPRESS_ALL, &name1, &name2, &name3, bit, sizeof bit);
return (0);
}
void
test(unsigned int allowed, dns_name_t *name1, dns_name_t *name2,
dns_name_t *name3, unsigned char *result, unsigned int length)
{
isc_mem_t *mctx = NULL;
dns_compress_t cctx;
dns_decompress_t dctx;
isc_buffer_t source;
isc_buffer_t target;
dns_name_t name;
unsigned char buf1[1024];
unsigned char buf2[1024];
if (verbose) {
const char *s;
switch (allowed) {
case DNS_COMPRESS_NONE: s = "DNS_COMPRESS_NONE"; break;
case DNS_COMPRESS_GLOBAL14: s = "DNS_COMPRESS_GLOBAL14"; break;
case DNS_COMPRESS_GLOBAL16: s = "DNS_COMPRESS_GLOBAL16"; break;
case DNS_COMPRESS_GLOBAL: s = "DNS_COMPRESS_GLOBAL"; break;
/* case DNS_COMPRESS_ALL: s = "DNS_COMPRESS_ALL"; break; */
default: s = "UNKOWN"; break;
}
fprintf(stdout, "Allowed = %s\n", s);
}
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
isc_buffer_init(&source, buf1, sizeof(buf1));
RUNTIME_CHECK(dns_compress_init(&cctx, -1, mctx) == ISC_R_SUCCESS);
RUNTIME_CHECK(dns_name_towire(name1, &cctx, &source) == ISC_R_SUCCESS);
/*
RUNTIME_CHECK(dns_compress_localinit(&cctx, name1, &source) ==
ISC_R_SUCCESS);
*/
dns_compress_setmethods(&cctx, allowed);
RUNTIME_CHECK(dns_name_towire(name2, &cctx, &source) == ISC_R_SUCCESS);
RUNTIME_CHECK(dns_name_towire(name2, &cctx, &source) == ISC_R_SUCCESS);
RUNTIME_CHECK(dns_name_towire(name3, &cctx, &source) == ISC_R_SUCCESS);
/*
dns_compress_localinvalidate(&cctx);
*/
dns_compress_rollback(&cctx, 0); /* testing only */
dns_compress_invalidate(&cctx);
if (raw) {
unsigned int i;
for (i = 0 ; i < source.used ; /* */ ) {
fprintf(stdout, "%02x",
((unsigned char *)source.base)[i]);
if ((++i % 20) == 0)
fputs("\n", stdout);
else
if (i == source.used)
fputs("\n", stdout);
else
fputs(" ", stdout);
}
}
isc_buffer_setactive(&source, source.used);
isc_buffer_init(&target, buf2, sizeof(buf2));
dns_decompress_init(&dctx, -1, ISC_TRUE);
dns_name_init(&name, NULL);
RUNTIME_CHECK(dns_name_fromwire(&name, &source, &dctx, ISC_FALSE,
&target) == ISC_R_SUCCESS);
dns_decompress_setmethods(&dctx, allowed);
/*
dns_decompress_localinit(&dctx, &name, &source);
*/
RUNTIME_CHECK(dns_name_fromwire(&name, &source, &dctx, ISC_FALSE,
&target) == ISC_R_SUCCESS);
RUNTIME_CHECK(dns_name_fromwire(&name, &source, &dctx, ISC_FALSE,
&target) == ISC_R_SUCCESS);
RUNTIME_CHECK(dns_name_fromwire(&name, &source, &dctx, ISC_FALSE,
&target) == ISC_R_SUCCESS);
/*
dns_decompress_localinvalidate(&dctx);
*/
dns_decompress_invalidate(&dctx);
if (raw) {
unsigned int i;
for (i = 0 ; i < target.used ; /* */ ) {
fprintf(stdout, "%02x",
((unsigned char *)target.base)[i]);
if ((++i % 20) == 0)
fputs("\n", stdout);
else
if (i == target.used)
fputs("\n", stdout);
else
fputs(" ", stdout);
}
fputs("\n", stdout);
fflush(stdout);
}
RUNTIME_CHECK(target.used == length);
RUNTIME_CHECK(memcmp(target.base, result, target.used) == 0);
isc_mem_destroy(&mctx);
}

View File

@@ -1,3 +0,0 @@
Makefile
t_db
.libs

View File

@@ -1,57 +0,0 @@
# Copyright (C) 1999, 2000 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.in,v 1.15 2000/06/22 21:51:02 tale Exp $
srcdir = @srcdir@
VPATH = @srcdir@
top_srcdir = @top_srcdir@
@BIND9_INCLUDES@
CINCLUDES = ${TEST_INCLUDES} ${DNS_INCLUDES} ${ISC_INCLUDES}
CDEFINES =
CWARNINGS =
DNSLIBS = ../../../lib/dns/libdns.@A@ @DNS_OPENSSL_LIBS@
ISCLIBS = ../../../lib/isc/libisc.@A@
DNSDEPLIBS = ../../../lib/dns/libdns.@A@
ISCDEPLIBS = ../../../lib/isc/libisc.@A@
DEPLIBS = ${DNSDEPLIBS} ${ISCDEPLIBS}
LIBS = ${DNSLIBS} ${ISCLIBS} @LIBS@
TLIB = ../../../lib/tests/libt_api.@A@
SRCS = t_db.c
TARGETS = t_db
@BIND9_MAKE_RULES@
t_db: t_db.@O@ ${DEPLIBS} ${TLIB}
${LIBTOOL} ${CC} -o $@ t_db.@O@ ${TLIB} ${LIBS}
test: t_db
-@./t_db -c @top_srcdir@/t_config -b @srcdir@ -a
testhelp:
@./t_db -h
clean distclean::
rm -f ${TARGETS}

View File

@@ -1,11 +0,0 @@
$TTL 1000
@ in soa localhost. postmaster.localhost. (
1993050801 ;serial
3600 ;refresh
1800 ;retry
604800 ;expiration
3600 ) ;minimum
a in ns ns.vix.com.
a in ns ns2.vix.com.
a in ns ns3.vix.com.
b in a 1.2.3.4

View File

@@ -1,9 +0,0 @@
#
# test data for dns_db_class
#
# format:
# filename class
#
#
dns_db_class_1.data in
# dns_db_class_1.data any

View File

@@ -1,11 +0,0 @@
$TTL 1000
@ in soa localhost. postmaster.localhost. (
1993050801 ;serial
3600 ;refresh
1800 ;retry
604800 ;expiration
3600 ) ;minimum
a in ns ns.vix.com.
a in ns ns2.vix.com.
a in ns ns3.vix.com.
b in a 1.2.3.4

Some files were not shown because too many files have changed in this diff Show More