diff options
author | dm <dm@cvs.openbsd.org> | 1996-02-19 20:55:23 +0000 |
---|---|---|
committer | dm <dm@cvs.openbsd.org> | 1996-02-19 20:55:23 +0000 |
commit | 8c5eae3c0d85c8f8e9b2aba89dc944b39974a710 (patch) | |
tree | 484d0a91211302dff9aed3e96d6aeda804a331b7 /usr.sbin | |
parent | 34dfcd3c571a64de57872aa758d1b228d7b22a02 (diff) |
netbsd: bind 4.9.3
Diffstat (limited to 'usr.sbin')
45 files changed, 0 insertions, 16525 deletions
diff --git a/usr.sbin/named/Version.c b/usr.sbin/named/Version.c deleted file mode 100644 index b2d8c987927..00000000000 --- a/usr.sbin/named/Version.c +++ /dev/null @@ -1,136 +0,0 @@ -/*- - * Copyright (c) 1986, 1987, 1990 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)Version.c 4.10 (Berkeley) 4/24/91 - */ - -#ifndef lint -/*char sccsid[] = "from: @(#)named 4.8.3 %WHEN% %WHOANDWHERE%\n";*/ -static char rcsid[] = "$Id: Version.c,v 1.1 1995/10/18 08:47:49 deraadt Exp $"; -#endif /* not lint */ - -char Version[] = "named 4.8.3 %WHEN%\n\t%WHOANDWHERE%\n"; - -#ifdef COMMENT - -SCCS/s.Version.c: - -D 4.8.3 90/08/15 09:21:21 bloom 37 35 00031/00028/00079 -Version distributed with 4.3 Reno tape (June 1990) -(with additional changes for backward compat. after Reno) - -D 4.8.2 89/09/18 13:57:11 bloom 35 34 00020/00014/00087 -Interim fixes release - -D 4.8.1 89/02/08 17:12:15 karels 34 33 00026/00017/00075 -branch for 4.8.1 - -D 4.8 88/07/09 14:27:00 karels 33 28 00043/00031/00049 -4.8 is here! - -D 4.7 87/11/20 13:15:52 karels 25 24 00000/00000/00062 -4.7.3 beta - -D 4.6 87/07/21 12:15:52 karels 25 24 00000/00000/00062 -4.6 declared stillborn - -D 4.5 87/02/10 12:33:25 kjd 24 18 00000/00000/00062 -February 1987, Network Release. Child (bind) grows up, parent (kevin) leaves home. - -D 4.4 86/10/01 10:06:26 kjd 18 12 00020/00017/00042 -October 1, 1986 Network Distribution - -D 4.3 86/06/04 12:12:18 kjd 12 7 00015/00028/00044 -Version distributed with 4.3BSD - -D 4.2 86/04/30 20:57:16 kjd 7 1 00056/00000/00016 -Network distribution Freeze and one more version until 4.3BSD - -D 1.1 86/04/30 19:30:00 kjd 1 0 00016/00000/00000 -date and time created 86/04/30 19:30:00 by kjd - -code versions: - -Makefile - Makefile.dist 5.4 (Berkeley) 8/15/90 -Makefile.reno - Makefile 5.8 (Berkeley) 7/28/90 -Version.c - Version.c 4.9 (Berkeley) 7/21/90 -db.h - db.h 4.16 (Berkeley) 6/1/90 -db_dump.c - db_dump.c 4.30 (Berkeley) 6/1/90 -db_glue.c - db_glue.c 4.4 (Berkeley) 6/1/90 -db_load.c - db_load.c 4.37 (Berkeley) 6/1/90 -db_lookup.c - db_lookup.c 4.17 (Berkeley) 6/1/90 -db_reload.c - db_reload.c 4.21 (Berkeley) 6/1/90 -db_save.c - db_save.c 4.15 (Berkeley) 6/1/90 -db_update.c - db_update.c 4.26 (Berkeley) 6/1/90 -named-xfer.c - named-xfer.c 4.16 (Berkeley) 8/15/90 -named.reload - named.reload 5.1 (Berkeley) 2/8/89 -named.reload.reno - named.reload 5.2 (Berkeley) 6/27/89 -named.restart - named.restart 5.2 (Berkeley) 2/5/89 -named.restart.reno - named.restart 5.4 (Berkeley) 6/27/89 -ns.h - ns.h 4.32 (Berkeley) 8/15/90 -ns_forw.c - ns_forw.c 4.30 (Berkeley) 6/27/90 -ns_init.c - ns_init.c 4.35 (Berkeley) 6/27/90 -ns_main.c - ns_main.c 4.51 (Berkeley) 8/15/90 -ns_maint.c - ns_maint.c 4.38 (Berkeley) 8/15/90 -ns_req.c - ns_req.c 4.44 (Berkeley) 6/27/90 -ns_resp.c - ns_resp.c 4.63 (Berkeley) 6/1/90 -ns_sort.c - ns_sort.c 4.8 (Berkeley) 6/1/90 -ns_stats.c - ns_stats.c 4.10 (Berkeley) 6/27/90 -pathnames.h - pathnames.h 5.4 (Berkeley) 6/1/90 - -#endif COMMENT diff --git a/usr.sbin/named/Version.self b/usr.sbin/named/Version.self deleted file mode 100644 index cd65debe7cd..00000000000 --- a/usr.sbin/named/Version.self +++ /dev/null @@ -1 +0,0 @@ -D 4.8 %E% %U% karels 26 25 00000/00000/00062 diff --git a/usr.sbin/named/adb.scripts/databuf b/usr.sbin/named/adb.scripts/databuf deleted file mode 100644 index d6f1e2cf260..00000000000 --- a/usr.sbin/named/adb.scripts/databuf +++ /dev/null @@ -1 +0,0 @@ -./"next"16t"ttl"16t"flags"8t"zone"8t"class"8t"type"nXDx3dn"mark"8t"size"8t"nstime"nddD diff --git a/usr.sbin/named/adb.scripts/databufs b/usr.sbin/named/adb.scripts/databufs deleted file mode 100644 index c1f8938d725..00000000000 --- a/usr.sbin/named/adb.scripts/databufs +++ /dev/null @@ -1,2 +0,0 @@ -./"next"16t"ttl"16t"flags"8t"zone"8t"class"8t"type"nXDx3dn"mark"8t"size"8t"nstime"nddD -*.,<9-1$<databuf diff --git a/usr.sbin/named/adb.scripts/namebuf b/usr.sbin/named/adb.scripts/namebuf deleted file mode 100644 index f5170b63552..00000000000 --- a/usr.sbin/named/adb.scripts/namebuf +++ /dev/null @@ -1,2 +0,0 @@ -./"dname"16t"hashval"16t"next"n3Xn"data"16t"parent"16t"hashbuf"n3X -*./"name"16ts diff --git a/usr.sbin/named/db.h b/usr.sbin/named/db.h deleted file mode 100644 index 7e3bb3e9217..00000000000 --- a/usr.sbin/named/db.h +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 1985, 1990 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * from: @(#)db.h 4.16 (Berkeley) 6/1/90 - * $Id: db.h,v 1.1 1995/10/18 08:47:49 deraadt Exp $ - */ - -/* - * Global structures and variables for data base routines. - */ - -#define INVBLKSZ 7 /* # of namebuf pointers per block */ -#define INVHASHSZ 919 /* size of inverse hash table */ - - /* max length of data in RR data field */ -#define MAXDATA 2048 - -/* - * Hash table structures. - */ -struct databuf { - struct databuf *d_next; /* linked list */ - u_long d_ttl; /* time to live */ - short d_flags; - short d_zone; /* zone number */ - short d_class; /* class number */ - short d_type; /* type number */ - short d_mark; /* place to mark data */ - short d_size; /* size of data area */ - u_long d_nstime; /* NS response time, milliseconds */ - char d_data[1]; /* the data is malloc'ed to size */ -}; -#define DATASIZE(n) (sizeof(struct databuf) - 1 + n) - -/* - * d_flags definitions - */ -#define DB_F_HINT 0x01 /* databuf belongs to fcachetab */ - -struct namebuf { - char *n_dname; /* domain name */ - u_int n_hashval; /* hash value of n_dname */ - struct namebuf *n_next; /* linked list */ - struct databuf *n_data; /* data records */ - struct namebuf *n_parent; /* parent domain */ - struct hashbuf *n_hash; /* hash table for children */ -}; - -struct invbuf { - struct invbuf *i_next; /* linked list */ - struct namebuf *i_dname[INVBLKSZ]; /* domain name */ -}; - -struct hashbuf { - int h_size; /* size of hash table */ - int h_cnt; /* number of entries */ - struct namebuf *h_tab[1]; /* malloc'ed as needed */ -}; -#define HASHSIZE(s) (s*sizeof(struct namebuf *) + 2*sizeof(int)) - -#define HASHSHIFT 3 -#define HASHMASK 0x1f - -/* - * Flags to updatedb - */ -#define DB_NODATA 0x01 /* data should not exist */ -#define DB_MEXIST 0x02 /* data must exist */ -#define DB_DELETE 0x04 /* delete data if it exists */ -#define DB_NOTAUTH 0x08 /* must not update authoritative data */ -#define DB_NOHINTS 0x10 /* don't reflect update in fcachetab */ - -#define DB_Z_CACHE (0) /* cache-zone-only db_dump() */ -#define DB_Z_ALL (-1) /* normal db_dump() */ - -/* - * Error return codes - */ -#define OK 0 -#define NONAME -1 -#define NOCLASS -2 -#define NOTYPE -3 -#define NODATA -4 -#define DATAEXISTS -5 -#define NODBFILE -6 -#define TOOMANYZONES -7 -#define GOODDB -8 -#define NEWDB -9 -#define AUTH -10 - -extern struct hashbuf *hashtab; /* root hash table */ -extern struct invbuf *invtab[]; /* inverse hash table */ -extern struct hashbuf *fcachetab; /* hash table for cache read from file*/ - -extern struct namebuf *nlookup(); -extern struct namebuf *savename(); -extern struct databuf *savedata(); -extern struct databuf *rm_datum(); -extern struct hashbuf *savehash(); -extern struct invbuf *saveinv(); -extern char *savestr(); -extern char *malloc(), *realloc(), *calloc(); diff --git a/usr.sbin/named/db_dump.c b/usr.sbin/named/db_dump.c deleted file mode 100644 index c38f5b85e02..00000000000 --- a/usr.sbin/named/db_dump.c +++ /dev/null @@ -1,787 +0,0 @@ -/* - * Copyright (c) 1986, 1988, 1990 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -/*static char sccsid[] = "from: @(#)db_dump.c 4.33 (Berkeley) 3/3/91";*/ -static char rcsid[] = "$Id: db_dump.c,v 1.1 1995/10/18 08:47:49 deraadt Exp $"; -#endif /* not lint */ - -#include <sys/param.h> -#include <sys/time.h> -#include <sys/stat.h> -#include <netinet/in.h> -#include <netdb.h> -#include <stdio.h> -#include <syslog.h> -#include <arpa/nameser.h> -#include <resolv.h> -#include "ns.h" -#include "db.h" -#include "pathnames.h" - -#ifdef DUMPFILE -char *dumpfile = DUMPFILE; -#else -char *dumpfile = _PATH_DUMPFILE; -#endif - -extern char *cache_file; - -/* - * Dump current cache in a format similar to RFC 883. - * - * We try to be careful and determine whether the operation succeeded - * so that the new cache file can be installed. - */ - -#define DB_ROOT_TIMBUF 3600 - -doachkpt() -{ - extern int errno; - FILE *fp; - time_t dumptime; - char tmpcheckfile[256]; - - /* nowhere to checkpoint cache... */ - if (cache_file == NULL) { -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"doachkpt(to where?)\n"); -#endif - return; - } - -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"doachkpt()\n"); -#endif - - (void) sprintf(tmpcheckfile, "%s.chk", cache_file); - if ((fp = fopen(tmpcheckfile, "w")) == NULL) { -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"doachkpt(can't open %s for write)\n", tmpcheckfile); -#endif - return; - } - - (void) gettime(&tt); - dumptime = tt.tv_sec; - fprintf(fp, "; Dumped at %s", ctime(&dumptime)); - fflush(fp); - if (ferror(fp)) { -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"doachkpt(write to checkpoint file failed)\n"); -#endif - return; - } - - if (fcachetab != NULL) { - int n; - if ((n = scan_root(hashtab)) < MINROOTS) { - syslog(LOG_ERR, "%d root hints... (too low)", n); - fprintf(fp, "; ---- Root hint cache dump ----\n"); - (void) db_dump(fcachetab, fp, DB_Z_CACHE, ""); - } - } - - if (hashtab != NULL) { - fprintf(fp, "; ---- Cache dump ----\n"); - if (db_dump(hashtab, fp, DB_Z_CACHE, "") == NODBFILE) { -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"doachkpt(checkpoint failed)\n"); -#endif - (void) fclose(fp); - return; - } - } - - (void) fsync(fileno(fp)); - if (fclose(fp) == EOF) { -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"doachkpt(close failed)\n"); -#endif - return; - } - - if (rename(tmpcheckfile, cache_file)) { -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"doachkpt(install %s to %s failed, %d)\n", - tmpcheckfile,cache_file, errno); -#endif - } -} - -/* - * What we do is scan the root hint cache to make sure there are at least - * MINROOTS root pointers with non-0 TTL's so that the checkpoint will not - * lose the root. Failing this, all pointers are written out w/ TTL ~0 - * (root pointers timed out and prime_cache() not done or failed). - */ -#define TIMBUF 300 - -int -scan_root(htp) - struct hashbuf *htp; -{ - register struct databuf *dp; - register struct namebuf *np; - struct timeval soon; - int roots = 0; - -#ifdef DEBUG - if (debug) - fprintf(ddt,"scan_root(0x%x)\n", htp); -#endif - - /* metric by which we determine whether a root NS pointer is still */ - /* valid (will be written out if we do a dump). we also add some */ - /* time buffer for safety... */ - (void) gettime(&soon); - soon.tv_sec += TIMBUF; - - for (np = htp->h_tab[0]; np != NULL; np = np->n_next) { - if (np->n_dname[0] == '\0') { - dp = np->n_data; - while (dp != NULL) { - if (dp->d_type == T_NS && - dp->d_ttl > soon.tv_sec) { - roots++; - if (roots >= MINROOTS) - return (roots); - } - dp = dp->d_next; - } - } - } - return (roots); -} - -#ifdef notdef -mark_cache(htp, ttl) - struct hashbuf *htp; - int ttl; -{ - register struct databuf *dp; - register struct namebuf *np; - struct namebuf **npp, **nppend; - struct timeval soon; - -#ifdef DEBUG - if (debug) - fprintf(ddt,"mark_cache()\n"); -#endif - - (void) gettime(&soon); - soon.tv_sec += TIMBUF; - - npp = htp->h_tab; - nppend = npp + htp->h_size; - while (npp < nppend) { - for (np = *npp++; np != NULL; np = np->n_next) { - if (np->n_data == NULL) - continue; - for (dp = np->n_data; dp != NULL; dp = dp->d_next) { - if (dp->d_ttl < soon.tv_sec) - dp->d_ttl = ttl; - } - } - } - - npp = htp->h_tab; - nppend = npp + htp->h_size; - while (npp < nppend) { - for (np = *npp++; np != NULL; np = np->n_next) { - if (np->n_hash == NULL) - continue; - mark_cache(np->n_hash, ttl); - } - } -} -#endif notdef - -/* - * Dump current data base in a format similar to RFC 883. - */ - -doadump() -{ - FILE *fp; - time_t dumptime; - -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"doadump()\n"); -#endif - - if ((fp = fopen(dumpfile, "w")) == NULL) - return; - gettime(&tt); - dumptime = tt.tv_sec; - fprintf(fp, "; Dumped at %s", ctime(&dumptime)); - fprintf(fp, "; --- Cache & Data ---\n"); - if (hashtab != NULL) - (void) db_dump(hashtab, fp, DB_Z_ALL, ""); - fprintf(fp, "; --- Hints ---\n"); - if (fcachetab != NULL) - (void) db_dump(fcachetab, fp, DB_Z_ALL, ""); - (void) fclose(fp); -} - -#ifdef ALLOW_UPDATES -/* Create a disk database to back up zones - */ -zonedump(zp) - register struct zoneinfo *zp; -{ - FILE *fp; - char *fname; - struct hashbuf *htp; - char *op; - struct stat st; - - /* Only dump zone if there is a cache specified */ - if (zp->z_source && *(zp->z_source)) { -#ifdef DEBUG - if (debug) - fprintf(ddt, "zonedump(%s)\n", zp->z_source); -#endif - - if ((fp = fopen(zp->z_source, "w")) == NULL) - return; - if (op = index(zp->z_origin, '.')) - op++; - gettime(&tt); - htp = hashtab; - if (nlookup(zp->z_origin, &htp, &fname, 0) != NULL) { - db_dump(htp, fp, zp-zones, (op == NULL ? "" : op)); -#ifdef ALLOW_UPDATES - zp->hasChanged = 0; /* Checkpointed */ -#endif ALLOW_UPDATES - } - (void) fclose(fp); - if (stat(zp->z_source, &st) == 0) - zp->z_ftime = st.st_mtime; - } -#ifdef DEBUG - else if (debug) - fprintf(ddt, "zonedump: no zone to dump\n"); -#endif -} -#endif - -int -db_dump(htp, fp, zone, origin) - int zone; - struct hashbuf *htp; - FILE *fp; - char *origin; -{ - register struct databuf *dp; - register struct namebuf *np; - struct namebuf **npp, **nppend; - char dname[MAXDNAME]; - u_long n; - u_long addr; - u_short i; - int j; - register u_char *cp; - u_char *end; - char *proto; - extern char *inet_ntoa(), *protocolname(), *servicename(); - int found_data, tab, printed_origin = 0; - - npp = htp->h_tab; - nppend = npp + htp->h_size; - while (npp < nppend) { - for (np = *npp++; np != NULL; np = np->n_next) { - if (np->n_data == NULL) - continue; - /* Blecch - can't tell if there is data here for the - * right zone, so can't print name yet - */ - found_data = 0; - /* we want a snapshot in time... */ - for (dp = np->n_data; dp != NULL; dp = dp->d_next) { - /* Is the data for this zone? */ - if (zone != DB_Z_ALL && dp->d_zone != zone) - continue; - if (dp->d_zone == DB_Z_CACHE && - dp->d_ttl <= tt.tv_sec && - (dp->d_flags & DB_F_HINT) == 0) - continue; - if (!printed_origin) { - fprintf(fp, "$ORIGIN %s.\n", origin); - printed_origin++; - } - tab = 0; - if (!found_data) { - if (np->n_dname[0] == 0) { - if (origin[0] == 0) - fprintf(fp, ".\t"); - else - fprintf(fp, ".%s.\t", origin); /* ??? */ - } else - fprintf(fp, "%s\t", np->n_dname); - if (strlen(np->n_dname) < 8) - tab = 1; - found_data++; - } else { - (void) putc('\t', fp); - tab = 1; - } - if (dp->d_zone == DB_Z_CACHE) { - if (dp->d_flags & DB_F_HINT && - (long)(dp->d_ttl - tt.tv_sec) < DB_ROOT_TIMBUF) - fprintf(fp, "%d\t", DB_ROOT_TIMBUF); - else - fprintf(fp, "%d\t", - (int)(dp->d_ttl - tt.tv_sec)); - } else if (dp->d_ttl != 0 && - dp->d_ttl != zones[dp->d_zone].z_minimum) - fprintf(fp, "%d\t", (int)dp->d_ttl); - else if (tab) - (void) putc('\t', fp); - fprintf(fp, "%s\t%s\t", p_class(dp->d_class), - p_type(dp->d_type)); - cp = (u_char *)dp->d_data; - /* - * Print type specific data - */ - switch (dp->d_type) { - case T_A: - switch (dp->d_class) { - case C_IN: - case C_HS: - GETLONG(n, cp); - n = htonl(n); - fprintf(fp, "%s", - inet_ntoa(*(struct in_addr *)&n)); - break; - } - if (dp->d_nstime) - fprintf(fp, "\t; %d", dp->d_nstime); - fprintf(fp, "\n"); - break; - case T_CNAME: - case T_MB: - case T_MG: - case T_MR: - case T_PTR: - if (cp[0] == '\0') - fprintf(fp, ".\n"); - else - fprintf(fp, "%s.\n", cp); - break; - - case T_NS: - cp = (u_char *)dp->d_data; - if (cp[0] == '\0') - fprintf(fp, ".\t"); - else - fprintf(fp, "%s.", cp); - if (dp->d_nstime) - fprintf(fp, "\t; %d???", dp->d_nstime); - fprintf(fp, "\n"); - break; - - case T_HINFO: - if (n = *cp++) { - fprintf(fp, "\"%.*s\"", (int)n, cp); - cp += n; - } else - fprintf(fp, "\"\""); - if (n = *cp++) - fprintf(fp, " \"%.*s\"", (int)n, cp); - else - fprintf(fp, " \"\""); - (void) putc('\n', fp); - break; - - case T_SOA: - fprintf(fp, "%s.", cp); - cp += strlen((char *)cp) + 1; - fprintf(fp, " %s. (\n", cp); - cp += strlen((char *)cp) + 1; - GETLONG(n, cp); - fprintf(fp, "\t\t%lu", n); - GETLONG(n, cp); - fprintf(fp, " %lu", n); - GETLONG(n, cp); - fprintf(fp, " %lu", n); - GETLONG(n, cp); - fprintf(fp, " %lu", n); - GETLONG(n, cp); - fprintf(fp, " %lu )\n", n); - break; - - case T_MX: - GETSHORT(n, cp); - fprintf(fp,"%lu", n); - fprintf(fp," %s.\n", cp); - break; - - case T_TXT: - end = (u_char *)dp->d_data + dp->d_size; - (void) putc('"', fp); - while (cp < end) { - if (n = *cp++) { - for (j = n ; j > 0 && cp < end ; j--) - if (*cp == '\n') { - (void) putc('\\', fp); - (void) putc(*cp++, fp); - } else - (void) putc(*cp++, fp); - } - } - (void) fputs("\"\n", fp); - break; - - case T_UINFO: - fprintf(fp, "\"%s\"\n", cp); - break; - - case T_UID: - case T_GID: - if (dp->d_size == sizeof(u_long)) { - GETLONG(n, cp); - fprintf(fp, "%lu\n", n); - } - break; - - case T_WKS: - GETLONG(addr, cp); - addr = htonl(addr); - fprintf(fp,"%s ", - inet_ntoa(*(struct in_addr *)&addr)); - proto = protocolname(*cp); - cp += sizeof(char); - fprintf(fp, "%s ", proto); - i = 0; - while(cp < (u_char *)dp->d_data + dp->d_size) { - j = *cp++; - do { - if (j & 0200) - fprintf(fp," %s", - servicename(i, proto)); - j <<= 1; - } while(++i & 07); - } - fprintf(fp,"\n"); - break; - - case T_MINFO: - fprintf(fp, "%s.", cp); - cp += strlen((char *)cp) + 1; - fprintf(fp, " %s.\n", cp); - break; -#ifdef ALLOW_T_UNSPEC - case T_UNSPEC: - /* Dump binary data out in an ASCII-encoded - format */ - { - /* Allocate more than enough space: - * actually need 5/4 size + 20 or so - */ - int TmpSize = 2 * dp->d_size + 30; - char *TmpBuf = (char *) malloc(TmpSize); - if (TmpBuf == NULL) { -#ifdef DEBUG - if (debug) - fprintf(ddt, "Dump T_UNSPEC: malloc returned NULL\n"); -#endif DEBUG - syslog(LOG_ERR, "Dump T_UNSPEC: malloc: %m"); - } - if (btoa(cp, dp->d_size, TmpBuf, - TmpSize) == CONV_OVERFLOW) { -#ifdef DEBUG - if (debug) - fprintf(ddt, "Dump T_UNSPEC: Output buffer overflow\n"); -#endif DEBUG - syslog(LOG_ERR, "Dump T_UNSPEC: Output buffer overflow\n"); - } else - fprintf(fp, "%s\n", TmpBuf); - } - break; -#endif ALLOW_T_UNSPEC - default: - fprintf(fp, "???\n"); - } - } - } - } - if (ferror(fp)) - return(NODBFILE); - - npp = htp->h_tab; - nppend = npp + htp->h_size; - while (npp < nppend) { - for (np = *npp++; np != NULL; np = np->n_next) { - if (np->n_hash == NULL) - continue; - getname(np, dname, sizeof(dname)); - if (db_dump(np->n_hash, fp, zone, dname) == NODBFILE) - return(NODBFILE); - } - } - return(OK); -} - -#ifdef ALLOW_T_UNSPEC -/* - * Subroutines to convert between 8 bit binary bytes and printable ASCII. - * Computes the number of bytes, and three kinds of simple checksums. - * Incoming bytes are collected into 32-bit words, then printed in base 85: - * exp(85,5) > exp(2,32) - * The ASCII characters used are between '!' and 'u'; - * 'z' encodes 32-bit zero; 'x' is used to mark the end of encoded data. - * - * Originally by Paul Rutter (philabs!per) and Joe Orost (petsd!joe) for - * the atob/btoa programs, released with the compress program, in mod.sources. - * Modified by Mike Schwartz 8/19/86 for use in BIND. - */ - -/* Make sure global variable names are unique */ -#define Ceor T_UNSPEC_Ceor -#define Csum T_UNSPEC_Csum -#define Crot T_UNSPEC_Crot -#define word T_UNSPEC_word -#define bcount T_UNSPEC_bcount - -static long int Ceor, Csum, Crot, word, bcount; - -#define EN(c) ((int) ((c) + '!')) -#define DE(c) ((c) - '!') -#define AddToBuf(bufp, c) **bufp = c; (*bufp)++; -#define streq(s0, s1) strcmp(s0, s1) == 0 -#define times85(x) ((((((x<<2)+x)<<2)+x)<<2)+x) - - -/* Decode ASCII-encoded byte c into binary representation and - * place into *bufp, advancing bufp - */ -static int -byte_atob(c, bufp) - register c; - char **bufp; -{ - if (c == 'z') { - if (bcount != 0) - return(CONV_BADFMT); - else { - putbyte(0, bufp); - putbyte(0, bufp); - putbyte(0, bufp); - putbyte(0, bufp); - } - } else if ((c >= '!') && (c < ('!' + 85))) { - if (bcount == 0) { - word = DE(c); - ++bcount; - } else if (bcount < 4) { - word = times85(word); - word += DE(c); - ++bcount; - } else { - word = times85(word) + DE(c); - putbyte((int)((word >> 24) & 255), bufp); - putbyte((int)((word >> 16) & 255), bufp); - putbyte((int)((word >> 8) & 255), bufp); - putbyte((int)(word & 255), bufp); - word = 0; - bcount = 0; - } - } else - return(CONV_BADFMT); - return(CONV_SUCCESS); -} - -/* Compute checksum info and place c into *bufp, advancing bufp */ -static -putbyte(c, bufp) - register c; - char **bufp; -{ - Ceor ^= c; - Csum += c; - Csum += 1; - if ((Crot & 0x80000000)) { - Crot <<= 1; - Crot += 1; - } else { - Crot <<= 1; - } - Crot += c; - AddToBuf(bufp, c); -} - -/* Read the ASCII-encoded data from inbuf, of length inbuflen, and convert - it into T_UNSPEC (binary data) in outbuf, not to exceed outbuflen bytes; - outbuflen must be divisible by 4. (Note: this is because outbuf is filled - in 4 bytes at a time. If the actual data doesn't end on an even 4-byte - boundary, there will be no problem...it will be padded with 0 bytes, and - numbytes will indicate the correct number of bytes. The main point is - that since the buffer is filled in 4 bytes at a time, even if there is - not a full 4 bytes of data at the end, there has to be room to 0-pad the - data, so the buffer must be of size divisible by 4). Place the number of - output bytes in numbytes, and return a failure/success status */ -int -atob(inbuf, inbuflen, outbuf, outbuflen, numbytes) - char *inbuf; - int inbuflen; - char *outbuf; - int outbuflen; - int *numbytes; -{ - int inc, nb; - long int oeor, osum, orot; - char *inp, *outp = outbuf, *endoutp = &outbuf[outbuflen]; - - if ( (outbuflen % 4) != 0) - return(CONV_BADBUFLEN); - Ceor = Csum = Crot = word = bcount = 0; - for (inp = inbuf, inc = 0; inc < inbuflen; inp++, inc++) { - if (outp > endoutp) - return(CONV_OVERFLOW); - if (*inp == 'x') { - inp +=2; - break; - } else { - if (byte_atob(*inp, &outp) == CONV_BADFMT) - return(CONV_BADFMT); - } - } - - /* Get byte count and checksum information from end of buffer */ - if(sscanf(inp, "%ld %lx %lx %lx", numbytes, &oeor, &osum, &orot) != 4) - return(CONV_BADFMT); - if ((oeor != Ceor) || (osum != Csum) || (orot != Crot)) - return(CONV_BADCKSUM); - return(CONV_SUCCESS); -} - -/* Encode binary byte c into ASCII representation and place into *bufp, - advancing bufp */ -static -byte_btoa(c, bufp) - register c; - char **bufp; -{ - Ceor ^= c; - Csum += c; - Csum += 1; - if ((Crot & 0x80000000)) { - Crot <<= 1; - Crot += 1; - } else { - Crot <<= 1; - } - Crot += c; - - word <<= 8; - word |= c; - if (bcount == 3) { - if (word == 0) { - AddToBuf(bufp, 'z'); - } else { - register int tmp = 0; - register long int tmpword = word; - - if (tmpword < 0) { - /* Because some don't support unsigned long */ - tmp = 32; - tmpword -= (long)(85 * 85 * 85 * 85 * 32); - } - if (tmpword < 0) { - tmp = 64; - tmpword -= (long)(85 * 85 * 85 * 85 * 32); - } - AddToBuf(bufp, - EN((tmpword / (long)(85 * 85 * 85 * 85)) + tmp)); - tmpword %= (long)(85 * 85 * 85 * 85); - AddToBuf(bufp, EN(tmpword / (85 * 85 * 85))); - tmpword %= (85 * 85 * 85); - AddToBuf(bufp, EN(tmpword / (85 * 85))); - tmpword %= (85 * 85); - AddToBuf(bufp, EN(tmpword / 85)); - tmpword %= 85; - AddToBuf(bufp, EN(tmpword)); - } - bcount = 0; - } else { - bcount += 1; - } -} - - -/* - * Encode the binary data from inbuf, of length inbuflen, into a - * null-terminated ASCII representation in outbuf, not to exceed outbuflen - * bytes. Return success/failure status - */ -int -btoa(inbuf, inbuflen, outbuf, outbuflen) - char *inbuf; - int inbuflen; - char *outbuf; - int outbuflen; -{ - long int inc, nb; - long int oeor, osum, orot; - char *inp, *outp = outbuf, *endoutp = &outbuf[outbuflen -1]; - - Ceor = Csum = Crot = word = bcount = 0; - for (inp = inbuf, inc = 0; inc < inbuflen; inp++, inc++) { - byte_btoa((unsigned char) (*inp), &outp); - if (outp >= endoutp) - return(CONV_OVERFLOW); - } - while (bcount != 0) { - byte_btoa(0, &outp); - if (outp >= endoutp) - return(CONV_OVERFLOW); - } - /* Put byte count and checksum information at end of buffer, delimited - by 'x' */ - (void) sprintf(outp, "x %ld %lx %lx %lx", inbuflen, Ceor, Csum, Crot); - if (&outp[strlen(outp) - 1] >= endoutp) - return(CONV_OVERFLOW); - else - return(CONV_SUCCESS); -} -#endif ALLOW_T_UNSPEC diff --git a/usr.sbin/named/db_glue.c b/usr.sbin/named/db_glue.c deleted file mode 100644 index de113390586..00000000000 --- a/usr.sbin/named/db_glue.c +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Copyright (c) 1986, 1988 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -/*static char sccsid[] = "from: @(#)db_glue.c 4.4 (Berkeley) 6/1/90";*/ -static char rcsid[] = "$Id: db_glue.c,v 1.1 1995/10/18 08:47:49 deraadt Exp $"; -#endif /* not lint */ - -#include <sys/param.h> -#include <sys/time.h> -#include <sys/stat.h> -#include <netinet/in.h> -#include <stdio.h> -#include <syslog.h> -#include <ctype.h> -#include <netdb.h> -#include <arpa/nameser.h> -#include "ns.h" -#include "db.h" - -struct valuelist { - struct valuelist *next, *prev; - char *name; - char *proto; - short port; -} *servicelist, *protolist; - -buildservicelist() -{ - struct servent *sp; - struct valuelist *slp; - - setservent(1); - while (sp = getservent()) { - slp = (struct valuelist *)malloc(sizeof(struct valuelist)); - slp->name = savestr(sp->s_name); - slp->proto = savestr(sp->s_proto); - slp->port = ntohs((u_short)sp->s_port); - slp->next = servicelist; - slp->prev = NULL; - if (servicelist) - servicelist->prev = slp; - servicelist = slp; - } - endservent(); -} - -buildprotolist() -{ - struct protoent *pp; - struct valuelist *slp; - - setprotoent(1); - while (pp = getprotoent()) { - slp = (struct valuelist *)malloc(sizeof(struct valuelist)); - slp->name = savestr(pp->p_name); - slp->port = pp->p_proto; - slp->next = protolist; - slp->prev = NULL; - if (protolist) - protolist->prev = slp; - protolist = slp; - } - endprotoent(); -} - -/* - * Convert service name or (ascii) number to int. - */ -servicenumber(p) - char *p; -{ - - return (findservice(p, &servicelist)); -} - -/* - * Convert protocol name or (ascii) number to int. - */ -protocolnumber(p) - char *p; -{ - - return (findservice(p, &protolist)); -} - -findservice(s, list) - register char *s; - register struct valuelist **list; -{ - register struct valuelist *lp = *list; - int n; - - for (; lp != NULL; lp = lp->next) - if (strcasecmp(lp->name, s) == 0) { - if (lp != *list) { - lp->prev->next = lp->next; - if (lp->next) - lp->next->prev = lp->prev; - (*list)->prev = lp; - lp->next = *list; - *list = lp; - } - return(lp->port); - } - if (sscanf(s, "%d", &n) != 1 || n <= 0) - n = -1; - return(n); -} - -struct servent * -cgetservbyport(port, proto) - u_short port; - char *proto; -{ - register struct valuelist **list = &servicelist; - register struct valuelist *lp = *list; - static struct servent serv; - - port = htons(port); - for (; lp != NULL; lp = lp->next) { - if (port != lp->port) - continue; - if (strcasecmp(lp->proto, proto) == 0) { - if (lp != *list) { - lp->prev->next = lp->next; - if (lp->next) - lp->next->prev = lp->prev; - (*list)->prev = lp; - lp->next = *list; - *list = lp; - } - serv.s_name = lp->name; - serv.s_port = htons((u_short)lp->port); - serv.s_proto = lp->proto; - return(&serv); - } - } - return(0); -} - -struct protoent * -cgetprotobynumber(proto) - register int proto; -{ - - register struct valuelist **list = &protolist; - register struct valuelist *lp = *list; - static struct protoent prot; - - for (; lp != NULL; lp = lp->next) - if (lp->port == proto) { - if (lp != *list) { - lp->prev->next = lp->next; - if (lp->next) - lp->next->prev = lp->prev; - (*list)->prev = lp; - lp->next = *list; - *list = lp; - } - prot.p_name = lp->name; - prot.p_proto = lp->port; - return(&prot); - } - return(0); -} - -char * -protocolname(num) - int num; -{ - static char number[8]; - struct protoent *pp; - - pp = cgetprotobynumber(num); - if(pp == 0) { - (void) sprintf(number, "%d", num); - return(number); - } - return(pp->p_name); -} - -char * -servicename(port, proto) - u_short port; - char *proto; -{ - static char number[8]; - struct servent *ss; - - ss = cgetservbyport(htons(port), proto); - if(ss == 0) { - (void) sprintf(number, "%d", port); - return(number); - } - return(ss->s_name); -} diff --git a/usr.sbin/named/db_load.c b/usr.sbin/named/db_load.c deleted file mode 100644 index fb65b892729..00000000000 --- a/usr.sbin/named/db_load.c +++ /dev/null @@ -1,969 +0,0 @@ -/* - * Copyright (c) 1986, 1988, 1990 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -/*static char sccsid[] = "from: @(#)db_load.c 4.38 (Berkeley) 3/2/91";*/ -static char rcsid[] = "$Id: db_load.c,v 1.1 1995/10/18 08:47:49 deraadt Exp $"; -#endif /* not lint */ - -/* - * Load data base from ascii backupfile. Format similar to RFC 883. - */ - -#include <sys/param.h> -#include <sys/time.h> -#include <sys/stat.h> -#include <netinet/in.h> -#include <stdio.h> -#include <syslog.h> -#include <ctype.h> -#include <netdb.h> -#include <arpa/nameser.h> -#include "ns.h" -#include "db.h" - -extern char *index(); -extern int max_cache_ttl; - -/* - * Map class and type names to number - */ -struct map { - char token[8]; - int val; -}; - -struct map m_class[] = { - "in", C_IN, -#ifdef notdef - "any", C_ANY, /* any is a QCLASS, not CLASS */ -#endif - "chaos", C_CHAOS, - "hs", C_HS, -}; -#define NCLASS (sizeof(m_class)/sizeof(struct map)) - -struct map m_type[] = { - "a", T_A, - "ns", T_NS, - "cname", T_CNAME, - "soa", T_SOA, - "mb", T_MB, - "mg", T_MG, - "mr", T_MR, - "null", T_NULL, - "wks", T_WKS, - "ptr", T_PTR, - "hinfo", T_HINFO, - "minfo", T_MINFO, - "mx", T_MX, - "uinfo", T_UINFO, - "txt", T_TXT, - "uid", T_UID, - "gid", T_GID, -#ifdef notdef - "any", T_ANY, /* any is a QTYPE, not TYPE */ -#endif -#ifdef ALLOW_T_UNSPEC - "unspec", T_UNSPEC, -#endif ALLOW_T_UNSPEC -}; -#define NTYPE (sizeof(m_type)/sizeof(struct map)) - -/* - * Parser token values - */ -#define CURRENT 1 -#define DOT 2 -#define AT 3 -#define DNAME 4 -#define INCLUDE 5 -#define ORIGIN 6 -#define ERROR 7 - -int lineno; /* current line number */ - -/* - * Load the database from 'filename'. Origin is appended to all domain - * names in the file. - */ -db_load(filename, in_origin, zp, doinginclude) - char *filename, *in_origin; - struct zoneinfo *zp; -{ - register u_char *cp; - register struct map *mp; - char domain[MAXDNAME]; - char origin[MAXDNAME]; - char tmporigin[MAXDNAME]; - u_char buf[MAXDATA]; - u_char data[MAXDATA]; - u_char *cp1; - char *op; - int c; - int class, type, ttl, dbflags, dataflags; - int read_soa = 0; /* number of soa's read */ - struct databuf *dp; - FILE *fp; - int slineno, i, errs = 0, didinclude = 0; - register u_long n; - struct stat sb; - -#ifdef DEBUG - if (debug) - fprintf(ddt,"db_load(%s, %s, %d, %d)\n", - filename, in_origin, zp - zones, doinginclude); -#endif - - (void) strcpy(origin, in_origin); - if ((fp = fopen(filename, "r")) == NULL) { - syslog(LOG_ERR, "%s: %m", filename); -#ifdef DEBUG - if (debug) - fprintf(ddt,"db_load: error opening file %s\n", filename); -#endif - return (-1); - } - if (zp->z_type == Z_CACHE) { - dbflags = DB_NODATA | DB_NOHINTS; - dataflags = DB_F_HINT; - } else { - dbflags = DB_NODATA; - dataflags = 0; - } - gettime(&tt); - if (fstat(fileno(fp), &sb) < 0) { - syslog(LOG_ERR, "%s: %m", filename); - sb.st_mtime = (int)tt.tv_sec; - } - slineno = lineno; - lineno = 1; - domain[0] = '\0'; - class = C_IN; - zp->z_state &= ~(Z_INCLUDE|Z_DB_BAD); - while ((c = gettoken(fp)) != EOF) { - switch (c) { - case INCLUDE: - if (!getword(buf, sizeof(buf), fp)) /* file name */ - break; - if (!getword(tmporigin, sizeof(tmporigin), fp)) - strcpy(tmporigin, origin); - else { - makename(tmporigin, origin); - endline(fp); - } - didinclude = 1; - errs += db_load(buf, tmporigin, zp, 1); - continue; - - case ORIGIN: - (void) strcpy((char *)buf, origin); - if (!getword(origin, sizeof(origin), fp)) - break; -#ifdef DEBUG - if (debug > 3) - fprintf(ddt,"db_load: origin %s, buf %s\n", - origin, buf); -#endif - makename(origin, buf); -#ifdef DEBUG - if (debug > 3) - fprintf(ddt,"db_load: origin now %s\n", origin); -#endif - continue; - - case DNAME: - if (!getword(domain, sizeof(domain), fp)) - break; - n = strlen(domain) - 1; - if (domain[n] == '.') - domain[n] = '\0'; - else if (*origin) { - (void) strcat(domain, "."); - (void) strcat(domain, origin); - } - goto gotdomain; - - case AT: - (void) strcpy(domain, origin); - goto gotdomain; - - case DOT: - domain[0] = '\0'; - /* fall thru ... */ - case CURRENT: - gotdomain: - if (!getword(buf, sizeof(buf), fp)) { - if (c == CURRENT) - continue; - break; - } - cp = buf; - ttl = 0; - if (isdigit(*cp)) { - n = 0; - do - n = n * 10 + (*cp++ - '0'); - while (isdigit(*cp)); - if (zp->z_type == Z_CACHE) { - /* this allows the cache entry to age */ - /* while sitting on disk (powered off) */ - if (n > max_cache_ttl) - n = max_cache_ttl; - n += sb.st_mtime; - } - ttl = n; - if (!getword(buf, sizeof(buf), fp)) - break; - } - for (mp = m_class; mp < m_class+NCLASS; mp++) - if (!strcasecmp((char *)buf, mp->token)) { - class = mp->val; - (void) getword(buf, sizeof(buf), fp); - break; - } - for (mp = m_type; mp < m_type+NTYPE; mp++) - if (!strcasecmp((char *)buf, mp->token)) { - type = mp->val; - goto fndtype; - } -#ifdef DEBUG - if (debug) - fprintf(ddt,"Line %d: Unknown type: %s.\n", - lineno, buf); -#endif - errs++; - syslog(LOG_ERR, "Line %d: Unknown type: %s.\n", - lineno, buf); - break; - fndtype: -#ifdef ALLOW_T_UNSPEC - /* Don't do anything here for T_UNSPEC... - * read input separately later - */ - if (type != T_UNSPEC) { -#endif ALLOW_T_UNSPEC - if (!getword(buf, sizeof(buf), fp)) - break; -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt, - "d='%s', c=%d, t=%d, ttl=%d, data='%s'\n", - domain, class, type, ttl, buf); -#endif -#ifdef ALLOW_T_UNSPEC - } -#endif ALLOW_T_UNSPEC - /* - * Convert the ascii data 'buf' to the proper format - * based on the type and pack into 'data'. - */ - switch (type) { - case T_A: - n = ntohl((u_long)inet_addr((char *)buf)); - cp = data; - PUTLONG(n, cp); - n = sizeof(u_long); - break; - - case T_HINFO: - n = strlen((char *)buf); - if (n > 255) { - syslog(LOG_WARNING, - "%s: line %d: CPU type too long", - filename, lineno); - n = 255; - } - data[0] = n; - bcopy(buf, (char *)data + 1, (int)n); - n++; - if (!getword(buf, sizeof(buf), fp)) - break; - i = strlen((char *)buf); - if (i > 255) { - syslog(LOG_WARNING, - "%s: line %d: OS type too long", - filename, lineno); - i = 255; - } - data[n] = i; - bcopy(buf, data + n + 1, i); - n += i + 1; - endline(fp); - break; - - case T_SOA: - case T_MINFO: - (void) strcpy((char *)data, (char *)buf); - makename(data, origin); - cp = data + strlen((char *)data) + 1; - if (!getword(cp, - sizeof(data) - (cp - data),fp)) { - n = cp - data; - break; - } - makename(cp, origin); - cp += strlen((char *)cp) + 1; - if (type == T_MINFO) { - n = cp - data; - break; - } - if (getnonblank(fp) != '(') - goto err; - zp->z_serial = getnum(fp); - n = (u_long) zp->z_serial; - PUTLONG(n, cp); - zp->z_refresh = getnum(fp); - n = (u_long) zp->z_refresh; - PUTLONG(n, cp); - if (zp->z_type == Z_SECONDARY) - zp->z_time = sb.st_mtime + zp->z_refresh; - zp->z_retry = getnum(fp); - n = (u_long) zp->z_retry; - PUTLONG(n, cp); - zp->z_expire = getnum(fp); - n = (u_long) zp->z_expire; - PUTLONG (n, cp); - zp->z_minimum = getnum(fp); - n = (u_long) zp->z_minimum; - PUTLONG (n, cp); - n = cp - data; - if (getnonblank(fp) != ')') - goto err; - read_soa++; - endline(fp); - break; - - case T_UID: - case T_GID: - n = 0; - cp = buf; - while (isdigit(*cp)) - n = n * 10 + (*cp++ - '0'); - if (cp == buf) - goto err; - cp = data; - PUTLONG(n, cp); - n = sizeof(long); - break; - - case T_WKS: - /* Address */ - n = ntohl((u_long)inet_addr((char *)buf)); - cp = data; - PUTLONG(n, cp); - *cp = getprotocol(fp, filename); - /* Protocol */ - n = sizeof(u_long) + sizeof(char); - /* Services */ - n = getservices((int)n, data, fp, filename); - break; - - case T_NS: - case T_CNAME: - case T_MB: - case T_MG: - case T_MR: - case T_PTR: - (void) strcpy((char *)data, (char *)buf); - makename(data, origin); - n = strlen((char *)data) + 1; - break; - - case T_UINFO: - cp = (u_char *)index((char *)buf, '&'); - bzero(data, sizeof(data)); - if ( cp != NULL) { - (void) strncpy((char *)data, - (char *)buf, cp - buf); - op = index(domain, '.'); - if ( op != NULL) - (void) strncat((char *)data, - domain,op-domain); - else - (void) strcat((char *)data, - domain); - (void) strcat((char *)data, - (char *)++cp); - } else - (void) strcpy((char *)data, - (char *)buf); - n = strlen((char *)data) + 1; - break; - case T_MX: - n = 0; - cp = buf; - while (isdigit(*cp)) - n = n * 10 + (*cp++ - '0'); - /* catch bad values */ - if ((cp == buf) || (n > 65535)) - goto err; - - cp = data; - PUTSHORT((u_short)n, cp); - - if (!getword(buf, sizeof(buf), fp)) - break; - (void) strcpy((char *)cp, (char *)buf); - makename(cp, origin); - /* get pointer to place in data */ - cp += strlen((char *)cp) +1; - - /* now save length */ - n = (cp - data); - break; - - case T_TXT: - i = strlen((char *)buf); - cp = data; - cp1 = buf; - /* - * there is expansion here so make sure we - * don't overflow data - */ - if (i > sizeof(data) * 255 / 256) { - syslog(LOG_WARNING, - "%s: line %d: TXT record truncated", - filename, lineno); - i = sizeof(data) * 255 / 256; - } - while (i > 255) { - *cp++ = 255; - bcopy(cp1, cp, 255); - cp += 255; - cp1 += 255; - i -= 255; - } - *cp++ = i; - bcopy(cp1, cp, i); - cp += i; - n = cp - data; - endline(fp); - break; -#ifdef ALLOW_T_UNSPEC - case T_UNSPEC: - { - int rcode; - fgets(buf, sizeof(buf), fp); -#ifdef DEBUG - if (debug) - fprintf(ddt, "loading T_UNSPEC\n"); -#endif DEBUG - if (rcode = atob(buf, - strlen((char *)buf), data, - sizeof(data), &n)) { - if (rcode == CONV_OVERFLOW) { -#ifdef DEBUG - if (debug) - fprintf(ddt, - "Load T_UNSPEC: input buffer overflow\n"); -#endif DEBUG - errs++; - syslog(LOG_ERR, - "Load T_UNSPEC: input buffer overflow"); - } else { -#ifdef DEBUG - if (debug) - fprintf(ddt, - "Load T_UNSPEC: Data in bad atob format\n"); -#endif DEBUG - errs++; - syslog(LOG_ERR, - "Load T_UNSPEC: Data in bad atob format"); - } - } - } - break; -#endif ALLOW_T_UNSPEC - - default: - goto err; - } - dp = savedata(class, type, (u_long)ttl, data, (int)n); - dp->d_zone = zp - zones; - dp->d_flags = dataflags; - if ((c = db_update(domain, dp, dp, dbflags, - (zp->z_type == Z_CACHE)? fcachetab : hashtab)) < 0) { -#ifdef DEBUG - if (debug && (c != DATAEXISTS)) - fprintf(ddt,"update failed\n"); -#endif - } - continue; - - case ERROR: - break; - } - err: - errs++; - syslog(LOG_ERR, "%s: line %d: database format error (%s)", - filename, lineno, buf); -#ifdef DEBUG - if (debug) - fprintf(ddt,"%s: line %d: database format error ('%s', %d)\n", - filename, lineno, buf, n); -#endif - while ((c = getc(fp)) != EOF && c != '\n') - ; - if (c == '\n') - lineno++; - } - (void) fclose(fp); - lineno = slineno; - if (doinginclude == 0) { - if (didinclude) { - zp->z_state |= Z_INCLUDE; - zp->z_ftime = 0; - } else - zp->z_ftime = sb.st_mtime; - zp->z_lastupdate = sb.st_mtime; - if (zp->z_type != Z_CACHE && read_soa != 1) { - errs++; - if (read_soa == 0) - syslog(LOG_ERR, "%s: no SOA record", filename); - else - syslog(LOG_ERR, "%s: multiple SOA records", - filename); - } - } - if (errs) - zp->z_state |= Z_DB_BAD; - return (errs); -} - -int gettoken(fp) - register FILE *fp; -{ - register int c; - char op[32]; - - for (;;) { - c = getc(fp); - top: - switch (c) { - case EOF: - return (EOF); - - case '$': - if (getword(op, sizeof(op), fp)) { - if (!strcasecmp("include", op)) - return (INCLUDE); - if (!strcasecmp("origin", op)) - return (ORIGIN); - } -#ifdef DEBUG - if (debug) - fprintf(ddt,"Line %d: Unknown $ option: $%s\n", - lineno, op); -#endif - syslog(LOG_ERR,"Line %d: Unknown $ option: $%s\n", - lineno, op); - return (ERROR); - - case ';': - while ((c = getc(fp)) != EOF && c != '\n') - ; - goto top; - - case ' ': - case '\t': - return (CURRENT); - - case '.': - return (DOT); - - case '@': - return (AT); - - case '\n': - lineno++; - continue; - - default: - (void) ungetc(c, fp); - return (DNAME); - } - } -} - -/* - * Get next word, skipping blanks & comments. - */ -getword(buf, size, fp) - char *buf; - int size; - FILE *fp; -{ - register char *cp; - register int c; - - for (cp = buf; (c = getc(fp)) != EOF; ) { - if (c == ';') { - while ((c = getc(fp)) != EOF && c != '\n') - ; - c = '\n'; - } - if (c == '\n') { - if (cp != buf) - ungetc(c, fp); - else - lineno++; - break; - } - if (isspace(c)) { - while (isspace(c = getc(fp)) && c != '\n') - ; - ungetc(c, fp); - if (cp != buf) /* Trailing whitespace */ - break; - continue; /* Leading whitespace */ - } - if (c == '"') { - while ((c = getc(fp)) != EOF && c != '"' && c != '\n') { - if (c == '\\') { - if ((c = getc(fp)) == EOF) - c = '\\'; - if (c == '\n') - lineno++; - } - if (cp >= buf+size-1) - break; - *cp++ = c; - } - if (c == '\n') { - lineno++; - break; - } - continue; - } - if (c == '\\') { - if ((c = getc(fp)) == EOF) - c = '\\'; - if (c == '\n') - lineno++; - } - if (cp >= buf+size-1) - break; - *cp++ = c; - } - *cp = '\0'; - return (cp != buf); -} - -getnum(fp) - FILE *fp; -{ - register int c, n; - int seendigit = 0; - int seendecimal = 0; - - for (n = 0; (c = getc(fp)) != EOF; ) { - if (isspace(c)) { - if (c == '\n') - lineno++; - if (seendigit) - break; - continue; - } - if (c == ';') { - while ((c = getc(fp)) != EOF && c != '\n') - ; - if (c == '\n') - lineno++; - if (seendigit) - break; - continue; - } - if (!isdigit(c)) { - if (c == ')' && seendigit) { - (void) ungetc(c, fp); - break; - } - if (seendecimal || c != '.') { - syslog(LOG_ERR, "line %d: expected a number", - lineno); -#ifdef DEBUG - if (debug) - fprintf(ddt,"line %d: expected a number", - lineno); -#endif - exit(1); /* XXX why exit */ - } else { - if (!seendigit) - n = 1; - n = n * 1000 ; - seendigit = 1; - seendecimal = 1; - } - continue; - } - n = n * 10 + (c - '0'); - seendigit = 1; - } - return (n); -} - -getnonblank(fp) - FILE *fp; -{ - register int c; - - while ( (c = getc(fp)) != EOF ) { - if (isspace(c)) { - if (c == '\n') - lineno++; - continue; - } - if (c == ';') { - while ((c = getc(fp)) != EOF && c != '\n') - ; - if (c == '\n') - lineno++; - continue; - } - return(c); - } - syslog(LOG_ERR, "line %d: unexpected EOF", lineno); -#ifdef DEBUG - if (debug) - fprintf(ddt, "line %d: unexpected EOF", lineno); -#endif - return (EOF); -} - -/* - * Take name and fix it according to following rules: - * "." means root. - * "@" means current origin. - * "name." means no changes. - * "name" means append origin. - */ -makename(name, origin) - char *name, *origin; -{ - int n; - - if (origin[0] == '.') - origin++; - n = strlen(name); - if (n == 1) { - if (name[0] == '.') { - name[0] = '\0'; - return; - } - if (name[0] == '@') { - (void) strcpy(name, origin); - return; - } - } - if (n > 0) { - if (name[n - 1] == '.') - name[n - 1] = '\0'; - else if (origin[0] != '\0') { - name[n] = '.'; - (void) strcpy(name + n + 1, origin); - } - } -} - -endline(fp) - register FILE *fp; -{ - register int c; - while (c = getc(fp)) - if (c == '\n') { - (void) ungetc(c,fp); - break; - } else if (c == EOF) - break; -} - -#define MAXPORT 256 -#define MAXLEN 24 - -getprotocol(fp, src) - FILE *fp; - char *src; -{ - int k; - char b[MAXLEN]; - - (void) getword(b, sizeof(b), fp); - - k = protocolnumber(b); - if(k == -1) - syslog(LOG_ERR, "%s: line %d: unknown protocol: %s.", - src, lineno, b); - return(k); -} - -int -getservices(n, data, fp, src) - int n; - char *data, *src; - FILE *fp; -{ - int j, ch; - int k; - int maxl; - int bracket; - char b[MAXLEN]; - char bm[MAXPORT/8]; - - for (j = 0; j < MAXPORT/8; j++) - bm[j] = 0; - maxl = 0; - bracket = 0; - while (getword(b, sizeof(b), fp) || bracket) { - if (feof(fp) || ferror(fp)) - break; - if (strlen(b) == 0) - continue; - if ( b[0] == '(') { - bracket++; - continue; - } - if ( b[0] == ')') { - bracket = 0; - while ((ch = getc(fp)) != EOF && ch != '\n') - ; - if (ch == '\n') - lineno++; - break; - } - k = servicenumber(b); - if (k == -1) { - syslog(LOG_WARNING, "%s: line %d: Unknown service '%s'", - src, lineno, b); - continue; - } - if ((k < MAXPORT) && (k)) { - bm[k/8] |= (0x80>>(k%8)); - if (k > maxl) - maxl=k; - } - else { - syslog(LOG_WARNING, - "%s: line %d: port no. (%d) too big\n", - src, lineno, k); -#ifdef DEBUG - if (debug) - fprintf(ddt, - "%s: line %d: port no. (%d) too big\n", - src, lineno, k); -#endif - } - } - if (bracket) - syslog(LOG_WARNING, "%s: line %d: missing close paren\n", - src, lineno); - maxl = maxl/8+1; - bcopy(bm, data+n, maxl); - return(maxl+n); -} - -get_sort_list(fp) - FILE *fp; -{ - extern struct netinfo **enettab; - register struct netinfo *ntp, **end = enettab; - extern struct netinfo *findnetinfo(); - struct in_addr addr; - char buf[BUFSIZ]; - -#ifdef DEBUG - if (debug) - fprintf(ddt,"sortlist "); -#endif - while (getword(buf, sizeof(buf), fp)) { - if (strlen(buf) == 0) - break; -#ifdef DEBUG - if (debug) - fprintf(ddt," %s",buf); -#endif - addr.s_addr = inet_addr(buf); - if (addr.s_addr == (unsigned)-1) { - /* resolve name to address - XXX */ - continue; - } - /* Check for duplicates, then add to linked list */ - if (findnetinfo(addr)) - continue; - ntp = (struct netinfo *)malloc(sizeof(struct netinfo)); - ntp->my_addr = addr; - ntp->next = NULL; - ntp->mask = net_mask(ntp->my_addr); - ntp->net = ntp->my_addr.s_addr & ntp->mask; - if (ntp->net != addr.s_addr) { - struct in_addr tmpaddr; - - tmpaddr.s_addr = ntp->net; - syslog(LOG_WARNING, "sortlist: addr %s != %s", buf, - inet_ntoa(tmpaddr)); -#ifdef DEBUG - if (debug) - fprintf(ddt, "\nsortlist: addr %s != %s\n", buf, - inet_ntoa(tmpaddr)); -#endif - } - - *end = ntp; - end = &ntp->next; - } - -#ifdef DEBUG - if (debug) - fprintf(ddt,"\n"); - if (debug > 2) - printnetinfo(*enettab); - if (debug > 4) { - extern struct netinfo *nettab; - - fprintf(ddt, "\nFull sort list:\n"); - printnetinfo(nettab); - } -#endif -} - -free_sort_list() -{ - extern struct netinfo **enettab; - register struct netinfo *ntp, *next; - - for (ntp = *enettab; ntp != NULL; ntp = next) { - next = ntp->next; - free((char *)ntp); - } - *enettab = NULL; -} diff --git a/usr.sbin/named/db_lookup.c b/usr.sbin/named/db_lookup.c deleted file mode 100644 index 62280fb9030..00000000000 --- a/usr.sbin/named/db_lookup.c +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (c) 1986 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -/*static char sccsid[] = "from: @(#)db_lookup.c 4.18 (Berkeley) 3/21/91";*/ -static char rcsid[] = "$Id: db_lookup.c,v 1.1 1995/10/18 08:47:50 deraadt Exp $"; -#endif /* not lint */ - -/* - * Table lookup routines. - */ - -#include <sys/param.h> -#include <arpa/nameser.h> -#include <stdio.h> -#include "db.h" - -struct hashbuf *hashtab; /* root hash table */ -struct hashbuf *fcachetab; /* hash table of cache read from file */ - -#ifdef DEBUG -extern int debug; -extern FILE *ddt; -#endif - -/* - * Lookup 'name' and return a pointer to the namebuf; - * NULL otherwise. If 'insert', insert name into tables. - * Wildcard lookups are handled. - */ -struct namebuf * -nlookup(name, htpp, fname, insert) - char *name; - struct hashbuf **htpp; - char **fname; - int insert; -{ - register struct namebuf *np; - register char *cp; - register int c; - register unsigned hval; - register struct hashbuf *htp; - struct namebuf *parent = NULL; - - htp = *htpp; - hval = 0; - *fname = "???"; - for (cp = name; c = *cp++; ) { - if (c == '.') { - parent = np = nlookup(cp, htpp, fname, insert); - if (np == NULL) - return (NULL); - if (*fname != cp) - return (np); - if ((htp = np->n_hash) == NULL) { - if (!insert) { - if (np->n_dname[0] == '*' && - np->n_dname[1] == '\0') - *fname = name; - return (np); - } - htp = savehash((struct hashbuf *)NULL); - np->n_hash = htp; - } - *htpp = htp; - break; - } - hval <<= HASHSHIFT; - hval += c & HASHMASK; - } - c = *--cp; - *cp = '\0'; - /* - * Lookup this label in current hash table. - */ - for (np = htp->h_tab[hval % htp->h_size]; np != NULL; np = np->n_next) { - if (np->n_hashval == hval && - strcasecmp(name, np->n_dname) == 0) { - *cp = c; - *fname = name; - return (np); - } - } - if (!insert) { - /* - * Look for wildcard in this hash table. - * Don't use a cached "*" name as a wildcard, - * only authoritative. - */ - hval = ('*' & HASHMASK) % htp->h_size; - for (np = htp->h_tab[hval]; np != NULL; np = np->n_next) { - if (np->n_dname[0] == '*' && np->n_dname[1] == '\0' && - np->n_data && np->n_data->d_zone != 0) { - *cp = c; - *fname = name; - return (np); - } - } - *cp = c; - return (parent); - } - np = savename(name); - np->n_parent = parent; - np->n_hashval = hval; - hval %= htp->h_size; - np->n_next = htp->h_tab[hval]; - htp->h_tab[hval] = np; - /* increase hash table size */ - if (++htp->h_cnt > htp->h_size * 2) { - *htpp = savehash(htp); - if (parent == NULL) { - if (htp == hashtab) - hashtab = *htpp; - else - fcachetab = *htpp; - } - else - parent->n_hash = *htpp; - htp = *htpp; - } - *cp = c; - *fname = name; - return (np); -} - -/* - * Does the data record match the class and type? - */ -match(dp, class, type) - register struct databuf *dp; - register int class, type; -{ -#ifdef DEBUG - if (debug >= 5) - fprintf(ddt,"match(0x%x, %d, %d) %d, %d\n", dp, class, type, - dp->d_class, dp->d_type); -#endif - if (dp->d_class != class && class != C_ANY) - return (0); - if (dp->d_type != type && type != T_ANY) - return (0); - return (1); -} diff --git a/usr.sbin/named/db_reload.c b/usr.sbin/named/db_reload.c deleted file mode 100644 index 3f3b0d241b4..00000000000 --- a/usr.sbin/named/db_reload.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 1986, 1988 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -/*static char sccsid[] = "from: @(#)db_reload.c 4.22 (Berkeley) 3/21/91";*/ -static char rcsid[] = "$Id: db_reload.c,v 1.1 1995/10/18 08:47:50 deraadt Exp $"; -#endif /* not lint */ - -#include <sys/param.h> -#include <sys/time.h> -#include <netinet/in.h> -#include <arpa/nameser.h> -#include <stdio.h> -#include <syslog.h> -#include "ns.h" -#include "db.h" - -extern time_t resettime; - -/* - * Flush and reload data base. - */ - -db_reload() -{ - extern char *bootfile; - -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"reload()\n"); -#endif - syslog(LOG_NOTICE, "reloading nameserver\n"); - - qflush(); - sqflush(); - fwdtab_free(); - free_sort_list(); - getnetconf(); - ns_init(bootfile); - time(&resettime); -} - -db_free(htp) - struct hashbuf *htp; -{ - register struct databuf *dp, *nextdp; - register struct namebuf *np, *nextnp; - struct namebuf **npp, **nppend; - - npp = htp->h_tab; - nppend = npp + htp->h_size; - while (npp < nppend) { - for (np = *npp++; np != NULL; np = nextnp) { - if (np->n_hash != NULL) - db_free(np->n_hash); - (void) free((char *)np->n_dname); - for (dp = np->n_data; dp != NULL; ) { - nextdp = dp->d_next; - (void) free((char *)dp); - dp = nextdp; - } - nextnp = np->n_next; - free((char *)np); - } - } - (void) free((char *)htp); -} - -db_inv_free() -{ - register struct invbuf *ip; - register int i, j; - - for (i = 0; i < INVHASHSZ; i++) - for (ip = invtab[i]; ip != NULL; ip = ip->i_next) - for (j = 0; j < INVBLKSZ; j++) - ip->i_dname[j] = NULL; -} - -fwdtab_free() -{ - extern struct fwdinfo *fwdtab; - struct fwdinfo *fp, *nextfp; - - for (fp = fwdtab; fp != NULL; fp = nextfp) { - nextfp = fp->next; - free((char *)fp); - } - fwdtab = NULL; -} diff --git a/usr.sbin/named/db_save.c b/usr.sbin/named/db_save.c deleted file mode 100644 index d70ecf31f87..00000000000 --- a/usr.sbin/named/db_save.c +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Copyright (c) 1986 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -/*static char sccsid[] = "from: @(#)db_save.c 4.16 (Berkeley) 3/21/91";*/ -static char rcsid[] = "$Id: db_save.c,v 1.1 1995/10/18 08:47:50 deraadt Exp $"; -#endif /* not lint */ - -/* - * Buffer allocation and deallocation routines. - */ - -#include <sys/param.h> -#include <arpa/nameser.h> -#include <syslog.h> -#include <stdio.h> -#include <string.h> -#include "db.h" - -#ifdef DEBUG -extern int debug; -extern FILE *ddt; -#endif - -/* - * Allocate a name buffer & save name. - */ -struct namebuf * -savename(name) - char *name; -{ - register struct namebuf *np; - - np = (struct namebuf *) malloc(sizeof(struct namebuf)); - if (np == NULL) { - syslog(LOG_ERR, "savename: %m"); - exit(1); - } - np->n_dname = savestr(name); - np->n_next = NULL; - np->n_data = NULL; - np->n_hash = NULL; - return (np); -} - -/* - * Allocate a data buffer & save data. - */ -struct databuf * -savedata(class, type, ttl, data, size) - int class, type; - u_long ttl; - char *data; - int size; -{ - register struct databuf *dp; - - if (type == T_NS) - dp = (struct databuf *) - malloc((unsigned)DATASIZE(size)+sizeof(u_long)); - else - dp = (struct databuf *) malloc((unsigned)DATASIZE(size)); - if (dp == NULL) { - syslog(LOG_ERR, "savedata: %m"); - exit(1); - } - dp->d_next = NULL; - dp->d_type = type; - dp->d_class = class; - dp->d_ttl = ttl; - dp->d_size = size; - dp->d_mark = 0; - dp->d_flags = 0; - dp->d_nstime = 0; - bcopy(data, dp->d_data, dp->d_size); - return (dp); -} - -int hashsizes[] = { /* hashtable sizes */ - 2, - 11, - 113, - 337, - 977, - 2053, - 4073, - 8011, - 16001, - 0 -}; - -/* - * Allocate a data buffer & save data. - */ -struct hashbuf * -savehash(oldhtp) - register struct hashbuf *oldhtp; -{ - register struct hashbuf *htp; - register struct namebuf *np, *nnp, **hp; - register int n; - int newsize; - - if (oldhtp == NULL) - newsize = hashsizes[0]; - else { - for (n = 0; newsize = hashsizes[n++]; ) - if (oldhtp->h_size == newsize) { - newsize = hashsizes[n]; - break; - } - if (newsize == 0) - newsize = oldhtp->h_size * 2 + 1; - } -#ifdef DEBUG - if(debug > 3) - fprintf(ddt, "savehash GROWING to %d\n", newsize); -#endif - htp = (struct hashbuf *) malloc((unsigned)HASHSIZE(newsize)); - if (htp == NULL) { - syslog(LOG_ERR, "savehash: %m"); - exit(1); - } - htp->h_size = newsize; - bzero((char *) htp->h_tab, newsize * sizeof(struct hashbuf *)); - if (oldhtp == NULL) { - htp->h_cnt = 0; - return (htp); - } -#ifdef DEBUG - if (debug > 3) - fprintf(ddt,"savehash(%#x) cnt=%d, sz=%d, newsz=%d\n", - oldhtp, oldhtp->h_cnt, oldhtp->h_size, newsize); -#endif - htp->h_cnt = oldhtp->h_cnt; - for (n = 0; n < oldhtp->h_size; n++) { - for (np = oldhtp->h_tab[n]; np != NULL; np = nnp) { - nnp = np->n_next; - hp = &htp->h_tab[np->n_hashval % htp->h_size]; - np->n_next = *hp; - *hp = np; - } - } - free((char *) oldhtp); - return (htp); -} - -/* - * Allocate an inverse query buffer. - */ -struct invbuf * -saveinv() -{ - register struct invbuf *ip; - - ip = (struct invbuf *) malloc(sizeof(struct invbuf)); - if (ip == NULL) { - syslog(LOG_ERR, "saveinv: %m"); - exit(1); - } - ip->i_next = NULL; - bzero((char *)ip->i_dname, sizeof(ip->i_dname)); - return (ip); -} - -/* - * Make a copy of a string and return a pointer to it. - */ -char * -savestr(str) - char *str; -{ - char *cp; - - cp = malloc((unsigned)strlen(str) + 1); - if (cp == NULL) { - syslog(LOG_ERR, "savestr: %m"); - exit(1); - } - (void) strcpy(cp, str); - return (cp); -} diff --git a/usr.sbin/named/db_update.c b/usr.sbin/named/db_update.c deleted file mode 100644 index 60702cc5d9e..00000000000 --- a/usr.sbin/named/db_update.c +++ /dev/null @@ -1,404 +0,0 @@ -/* - * Copyright (c) 1986, 1990 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -/*static char sccsid[] = "from: @(#)db_update.c 4.28 (Berkeley) 3/21/91";*/ -static char rcsid[] = "$Id: db_update.c,v 1.1 1995/10/18 08:47:50 deraadt Exp $"; -#endif /* not lint */ - -#include <sys/param.h> -#include <sys/socket.h> -#include <sys/time.h> -#include <netinet/in.h> -#include <arpa/nameser.h> -#include <stdio.h> -#include <syslog.h> -#include "ns.h" -#include "db.h" - -extern struct timeval tt; -extern FILE *ddt; -extern struct sockaddr_in from_addr; /* Source addr of last packet */ -extern int needs_prime_cache; - -int max_cache_ttl = (7*24*60*60); /* ONE_WEEK maximum ttl */ -int min_cache_ttl = (5*60); /* 5 minute minimum ttl */ - -/* - * Update data base. Flags control the action. - * Inverse query tables modified. - */ -db_update(name, odp, newdp, flags, htp) - char name[]; - struct databuf *odp, *newdp; - int flags; - struct hashbuf *htp; -{ - register struct namebuf *np; - register struct databuf *dp, *pdp; - char *fname; - int foundRR = 0; - -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"db_update(%s, 0x%x, 0x%x, 0%o, 0x%x)%s\n", - name, odp, newdp, flags, htp, - (odp && (odp->d_flags&DB_F_HINT)) ? " hint":"" ); -#endif - np = nlookup(name, &htp, &fname, newdp != NULL); - if (np == NULL || fname != name) - return (NONAME); - - /* Reflect certain updates in hint cache also... */ - /* Don't stick data we are authoritative for in hints. */ - if (!(flags & DB_NOHINTS) && (odp != NULL) && - (odp->d_zone <= 0) && !(odp->d_flags & DB_F_HINT) && - ((name[0] == '\0' && odp->d_type == T_NS) || - (odp->d_type == T_A))) - { - register struct databuf *dp; -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"db_update: hint '%s' %d\n", - name, odp->d_ttl); -#endif - dp = savedata(odp->d_class, odp->d_type, odp->d_ttl, - odp->d_data, odp->d_size); - dp->d_zone = DB_Z_CACHE; - dp->d_flags = DB_F_HINT; - if (db_update(name, dp,dp, (flags|DB_NOHINTS), fcachetab) != OK) { -#ifdef DEBUG - if (debug > 2) - fprintf(ddt, "db_update: hint %x freed\n", dp); -#endif - (void) free((char *)dp); - } - } - - if (odp != NULL) { - pdp = NULL; - for (dp = np->n_data; dp != NULL; ) { - if (!match(dp, odp->d_class, odp->d_type)) { - if ((dp->d_type == T_CNAME || - odp->d_type == T_CNAME) && - odp->d_mark == dp->d_mark && - zones[odp->d_zone].z_type != Z_CACHE) { - syslog(LOG_ERR, - "%s has CNAME and other data (illegal)\n", - name); -#ifdef DEBUG - if (debug) - fprintf(ddt, - "db_update: %s: CNAME and more (%d, %d)\n", - name, odp->d_type, dp->d_type); -#endif - } - goto skip; - } -#ifdef DEBUG - if (debug >= 5) - fprintf(ddt,"db_update: flags = %#x, sizes = %d, %d (%d)\n", - flags, odp->d_size, dp->d_size, - db_cmp(dp, odp)); -#endif - if (flags & DB_NOTAUTH && dp->d_zone) { -#ifdef DEBUG - if (debug) - fprintf(ddt, - "%s attempted update to auth zone %d '%s'\n", - inet_ntoa(from_addr.sin_addr), - dp->d_zone, zones[dp->d_zone].z_origin); -#endif - return (AUTH); - } - if ((flags & DB_NODATA) && !db_cmp(dp, odp)) { - /* refresh ttl if cache entry */ - if (dp->d_zone == 0) { - if (odp->d_zone != 0) { /* XXX */ - /* changing cache->auth */ - dp->d_zone = odp->d_zone; - dp->d_ttl = odp->d_ttl; -#ifdef DEBUG - if (debug > 3) - fprintf(ddt, - "db_update: cache entry now in auth zone\n"); -#endif - return (DATAEXISTS); - } - fixttl(odp); - if (odp->d_ttl > dp->d_ttl) - dp->d_ttl = odp->d_ttl; -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"db_update: new ttl %d, +%d\n", - dp->d_ttl, dp->d_ttl - tt.tv_sec); -#endif - } - return (DATAEXISTS); - } - /* - * If the old databuf has some data, check that the - * data matches that in the new databuf (so UPDATED - * will delete only the matching RR) - */ - if (odp->d_size > 0) { - if (db_cmp(dp, odp)) - goto skip; - } - foundRR = 1; - if (flags & DB_DELETE) - dp = rm_datum(dp, np, pdp); - else { -skip: pdp = dp; - dp = dp->d_next; - } - } - if (!foundRR) { - if (flags & DB_DELETE) - return(NODATA); - if (flags & DB_MEXIST) - return(NODATA); - } - } - if (newdp == NULL) - return (OK); - fixttl(newdp); -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"db_update: adding%s %x\n", - (newdp->d_flags&DB_F_HINT) ? " hint":"", newdp); -#endif - if (!(newdp->d_flags & DB_F_HINT)) - addinv(np, newdp); /* modify inverse query tables */ - - /* Add to end of list, generally preserving order */ - newdp->d_next = NULL; - if ((dp = np->n_data) == NULL) { - np->n_data = newdp; - return (OK); - } - /* XXX: need to check for duplicate WKS records and flag error */ - while (dp->d_next != NULL) { - if ((flags & DB_NODATA) && !db_cmp(dp, newdp)) - return (DATAEXISTS); - dp = dp->d_next; - } - if ((flags & DB_NODATA) && !db_cmp(dp, newdp)) - return (DATAEXISTS); - dp->d_next = newdp; - return (OK); -} - -fixttl(dp) -register struct databuf *dp; -{ - if (dp->d_zone == 0 && !(dp->d_flags & DB_F_HINT)) { - if (dp->d_ttl <= tt.tv_sec) - return; - else if (dp->d_ttl < tt.tv_sec+min_cache_ttl) - dp->d_ttl = tt.tv_sec+min_cache_ttl; - else if (dp->d_ttl > tt.tv_sec+max_cache_ttl) - dp->d_ttl = tt.tv_sec+max_cache_ttl; - } - return; -} - -struct invbuf *invtab[INVHASHSZ]; /* Inverse query hash table */ - -/* - * Add data 'dp' to inverse query tables for name 'np'. - */ -addinv(np, dp) - struct namebuf *np; - struct databuf *dp; -{ - register struct invbuf *ip; - register int hval, i; - - switch (dp->d_type) { - case T_A: - case T_UID: - case T_GID: - break; - - default: - return; - } - - hval = dhash(dp->d_data, dp->d_size); - for (ip = invtab[hval]; ip != NULL; ip = ip->i_next) - for (i = 0; i < INVBLKSZ; i++) - if (ip->i_dname[i] == NULL) { - ip->i_dname[i] = np; - return; - } - ip = saveinv(); - ip->i_next = invtab[hval]; - invtab[hval] = ip; - ip->i_dname[0] = np; -} - -/* - * Remove data 'odp' from inverse query table. - */ -rminv(odp) - struct databuf *odp; -{ - register struct invbuf *ip; - register struct databuf *dp; - struct namebuf *np; - register int i; - - for (ip = invtab[dhash(odp->d_data, odp->d_size)]; ip != NULL; - ip = ip->i_next) { - for (i = 0; i < INVBLKSZ; i++) { - if ((np = ip->i_dname[i]) == NULL) - break; - for (dp = np->n_data; dp != NULL; dp = dp->d_next) { - if (!match(dp, odp->d_class, odp->d_type)) - continue; - if (db_cmp(dp, odp)) - continue; - while (i < INVBLKSZ-1) { - ip->i_dname[i] = ip->i_dname[i+1]; - i++; - } - ip->i_dname[i] = NULL; - return; - } - } - } -} - -/* - * Compute hash value from data. - */ -dhash(dp, dlen) - char *dp; - int dlen; -{ - register char *cp; - register unsigned hval; - register int n; - - n = dlen; - if (n > 8) - n = 8; - hval = 0; - for (cp = dp; --n >= 0; ) { - hval <<= 1; - hval += *cp++; - } - return (hval % INVHASHSZ); -} - -/* - * Compare type, class and data from databufs for equivalence. - * Must be case insensitive for some domain names. - * Return 0 if equivalent, nonzero otherwise. - */ -db_cmp(dp1, dp2) - register struct databuf *dp1, *dp2; - -{ - register char *cp1, *cp2; - int len; - - if (dp1->d_type != dp2->d_type || dp1->d_class != dp2->d_class) - return(1); - if (dp1->d_size != dp2->d_size) - return(1); - if (dp1->d_mark != dp2->d_mark) - return(1); /* old and new RR's are distinct */ - switch (dp1->d_type) { - - case T_A: - case T_UID: - case T_GID: - case T_WKS: - case T_NULL: -#ifdef ALLOW_T_UNSPEC - case T_UNSPEC: -#endif ALLOW_T_UNSPEC - return(bcmp(dp1->d_data, dp2->d_data, dp1->d_size)); - - case T_NS: - case T_CNAME: - case T_PTR: - case T_MB: - case T_MG: - case T_MR: - case T_UINFO: - return(strcasecmp(dp1->d_data, dp2->d_data)); - - case T_HINFO: - cp1 = dp1->d_data; - cp2 = dp2->d_data; - len = *cp1; - if (strncasecmp(++cp1, ++cp2, len)) - return(1); - cp1 += len; - cp2 += len; - len = *cp1; - return(strncasecmp(++cp1, ++cp2, len)); - - case T_SOA: - case T_MINFO: - if (strcasecmp(dp1->d_data, dp2->d_data)) - return(1); - cp1 = dp1->d_data + strlen(dp1->d_data) + 1; - cp2 = dp2->d_data + strlen(dp2->d_data) + 1; - if (dp1->d_type != T_SOA) - return(strcasecmp(cp1, cp2)); - if (strcasecmp(cp1, cp2)) - return(1); - cp1 += strlen(cp1) + 1; - cp2 += strlen(cp2) + 1; - return(bcmp(cp1, cp2, sizeof(u_long) * 5)); - - case T_MX: - cp1 = dp1->d_data; - cp2 = dp2->d_data; - if (*cp1++ != *cp2++ || *cp1++ != *cp2++) /* cmp prio */ - return(1); - return(strcasecmp(cp1, cp2)); - - case T_TXT: - if (dp1->d_size != dp2->d_size) - return(1); - return(bcmp(dp1->d_data, dp2->d_data, dp1->d_size)); - - default: - return (1); - } -} diff --git a/usr.sbin/named/named.8 b/usr.sbin/named/named.8 deleted file mode 100644 index 06a9b089088..00000000000 --- a/usr.sbin/named/named.8 +++ /dev/null @@ -1,440 +0,0 @@ -.\" Copyright (c) 1985, 1991 The Regents of the University of California. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" from: @(#)named.8 6.9 (Berkeley) 3/16/91 -.\" $Id: named.8,v 1.1 1995/10/18 08:47:50 deraadt Exp $ -.\" -.Dd March 16, 1991 -.Dt NAMED 8 -.Os BSD 4 -.Sh NAME -.Nm named -.Nd Internet domain name server -.Sh SYNOPSIS -.Nm named -.Op Fl d Ar debuglevel -.Op Fl p Ar port# -.Oo Op Fl b -.Ar bootfile Oc -.Sh DESCRIPTION -.Nm Named -is the Internet domain name server. -See -.%T RFC883 -for more information on the Internet name-domain system. -Without any arguments, -.Nm named -will read the default boot file -.Pa /etc/named.boot , -read any initial data and listen for queries. -.Pp -Options are: -.Bl -tag -width Ds -.It Fl d -Print debugging information. -A number after the -.Fl d -determines the level of -messages printed. -.It Fl p -Use a different port number. The default is the standard port number -as listed in -.Pa /etc/services . -.It Fl b -Use an alternate boot file. This is optional and allows you to -specify a file with a leading dash. -.El -.Pp -Any additional argument is taken as the name of the boot file. -The boot file contains information about where the name server is to get -its initial data. If multiple boot files are specified, only the last -is used. -Lines in the boot file cannot be continued on subsequent lines. -The following is a small example: -.Bd -literal -; -; boot file for name server -; -directory /etc/namedb - -; type domain source host/file backup file - -cache . root.cache -primary Berkeley.EDU berkeley.edu.zone -primary 32.128.IN-ADDR.ARPA ucbhosts.rev -secondary CC.Berkeley.EDU 128.32.137.8 128.32.137.3 cc.zone.bak -secondary 6.32.128.IN-ADDR.ARPA 128.32.137.8 128.32.137.3 cc.rev.bak -primary 0.0.127.IN-ADDR.ARPA localhost.rev -forwarders 10.0.0.78 10.2.0.78 -; slave -.Ed -.Pp -The ``directory'' line causes the server to change its -working directory to the directory specified. This can -be important for the correct processing of -.Li $INCLUDE -files -in primary zone files. -.Pp -The -.Dq cache -line specifies that data in -.Dq Pa root.cache -is to be -placed in the backup cache. -Its main use is to specify data such as locations of root domain servers. -This cache is not used during normal operation, -but is used as -.Dq hints -to find the current root servers. -The file -.Dq Pa root.cache -is in the same format as -.Dq Pa berkeley.edu.zone . -There can be more than one -.Dq cache -file specified. -.\"The first such file will be updated under certain conditions to snapshot the -.\"cache (see -.\" .Dv SIGQUIT -.\" below). -.\"The cache line can also have an optional interval argument after -.\"the filename. -.\"If an interval is listed, -.\"it requests the nameserver to dump the cache contents -.\"at that interval (in seconds). -.\"The example above requests the nameserver to dump the cache content -.\"every 3600 seconds (once an hour). -.\"The use of automatic cache file updates is not currently recommended -.\"because of the way the cache is currently managed by the server; -.\"although the entire cache will be dumped for later reloading, -.\"most of the cache contents will be ignored when reloaded. -.\"The exact dump interval will vary -.\"based on the minimum maintence interval time which is typically about -.\"5 minutes. -The cache files are processed in such a way as to preserve the -time-to-live's -of data dumped out. Data for the root nameservers is kept artificially -valid if necessary. -.Pp -The first -.Dq primary -line states that the file -.Dq Pa berkeley.edu.zone -contains -authoritative data for the -.Dq Berkeley. Ns Em EDU -zone. -The file -.Dq Pa berkeley.edu.zone -contains data in the master file format described in -.%T RFC883 . -All domain names are relative to the origin, in this -case, -.Dq Berkeley. Ns Em EDU -(see below for a more detailed description). -The second -.Dq primary -line states that the file -.Dq Pa ucbhosts.rev -contains -authoritative data for the domain -.Dq 32.128.IN-ADDR.ARPA , -which is used -to translate addresses in network 128.32 to hostnames. -Each master file should begin with an -.Tn SOA -record for the zone -(see below). -.Pp -The first ``secondary'' line specifies that all authoritative data -under -.Dq CC.Berkeley. Ns Em EDU -is to be transferred from the name server -at 128.32.137.8. If the transfer fails it will try 128.32.137.3 and -continue trying the addresses, up to 10, listed on this line. -The secondary copy is also authoritative for the specified domain. -The first non-dotted-quad address on this line will be taken -as a filename in which to backup the transfered zone. -The name server will load the zone from this backup file if it exists -when it boots, providing a complete copy even if the master servers -are unreachable. -Whenever a new copy of the domain is received by automatic zone transfer -from one of the master servers, this file will be updated. -The second -.Dq secondary -line states that the address-to-hostname -mapping for the subnet 128.32.136 should be obtained from the same list -of master servers as the previous zone. -.Pp -The -.Dq forwarders -line specifies the addresses of sitewide servers -that will accept recursive queries from other servers. -If the boot file specifies one or more forwarders, then the -server will send all queries for data not in the cache to the forwarders first. -Each forwarder will be asked in turn until an answer is returned -or the list is exhausted. If no answer is forthcoming from a -forwarder, the server will continue as it would have without -the forwarders line unless it is in ``slave'' mode. -The forwarding facility is useful -to cause a large sitewide cache to be generated on a master, -and to reduce traffic over links to outside servers. -It can also be used to allow servers to run that do not have -access directly to the Internet, but wish to act as though -they do. -.Pp -The ``slave'' line (shown commented out) is used to put the server -in slave mode. In this mode, the server will only make queries to -forwarders. This option is normally used on machine that wish to -run a server but for physical or administrative reasons cannot -be given access to the Internet, but have access to a host that -does have access. -.Pp -The ``sortlist'' line can be used to indicate networks that are to be -preferred over other, unlisted networks. -Queries for host addresses from hosts on the same network as the server -will receive responses with local network addresses listed first, -then addresses on the sort list, then other addresses. -This line is only acted on at initial startup. -When reloading the nameserver with -a -.Dv SIGHUP , -this line will be ignored. -.Pp -The master file consists of control information -and a list of resource records for objects in the zone -of the forms: -.Bd -literal -$INCLUDE <filename> <opt_domain> -$ORIGIN <domain> -<domain> <opt_ttl> <opt_class> <type> <resource_record_data> -.Ed -.Pp -where -.Em domain -is -.Ql \&. -for root, -.Ql \&@ -for the current origin, or a standard domain -name. If -.Em domain -is a standard domain name that does not end with -.Ql \&. , -the current origin -is appended to the domain. Domain names ending with -.Ql \&. -are -unmodified. -The -.Em opt_domain -field is used to define an origin for the data in an included file. -It is equivalent to placing a -.Li $ORIGIN -statement before the first -line of the included file. The field is optional. -Neither the -.Em opt_domain -field nor -.Li $ORIGIN -statements in the included file modify the current origin -for this file. -The -.Em opt_ttl -field is an optional integer number for the time-to-live field. -It defaults to zero, meaning the minimum value specified in the -SOA record for the zone. -The -.Em opt_class -field is the object address type; currently only one type is supported, -.Sy IN , -for objects connected to the -.Tn DARPA -Internet. -The -.Em type -field contains one of the following tokens; the data expected in the -.Em resource_record_data -field is in parentheses. -.Bl -tag -width Fl -.It A -a host address (dotted quad) -.It \&NS -an authoritative name server (domain) -.It \&MX -a mail exchanger (domain) -.It CNAME -the canonical name for an alias (domain) -.It SOA -marks the start of a zone of authority (domain of originating host, -domain address of maintainer, a serial number and the following -parameters in seconds: refresh, retry, expire and minimum TTL -(see -.%T RFC883 ) ) -.It \&MB -a mailbox domain name (domain) -.It \&MG -a mail group member (domain) -.It \&MR -a mail rename domain name (domain) -.It NULL -ra null resource record (no format or data) -.It \&WKS -a well know service description (not implemented yet) -.It \&PTR -a domain name pointer (domain) -.It HINFO -host information (cpu_type OS_type ) -.It MINFO -mailbox or mail list information (request_domain error_domain) -.El -.Pp -Resource records normally end at the end of a line, -but may be continued across lines between opening and closing parentheses. -Comments are introduced by semicolons and continue to the end of the line. -.Pp -Each master zone file should begin with an SOA -record for the zone. -An example SOA -record is as follows: -.Bd -literal -@ IN SOA ucbvax.Berkeley.EDU. rwh.ucbvax.Berkeley.EDU. ( - 2.89 ; serial - 10800 ; refresh - 3600 ; retry - 3600000 ; expire - 86400 ) ; minimum -.Ed -.Pp -The SOA -lists a serial number, which should be changed each time the master -file is changed. -Secondary servers check the serial number at intervals specified by the refresh -time in seconds; if the serial number changes, a zone transfer will be done -to load the new data. -If a master server cannot be contacted when a refresh is due, the retry time -specifies the interval at which refreshes should be attempted until successful. -If a master server cannot be contacted within the interval given by the -expire time, all data from the zone is discarded by secondary servers. -The minimum value is the time-to-live used by records in the file -with no explicit time-to-live value. -.Sh NOTES -The boot file directives ``domain'' and ``suffixes'' have been -obsoleted by a more useful resolver based implementation of -suffixing for partially qualified domain names. The prior mechanisms -could fail under a number of situations, especially when then local -nameserver did not have complete information. -.Pp -The following signals have the specified effect when sent to the -server process using the -.Xr kill 1 -command. -.Bl -tag -width Fl -.It Dv SIGHUP -Causes server to read -.Pa named.boot -and reload database. -.It Dv SIGINT -Dumps current data base and cache to -.Pa /var/tmp/named_dump.db -.\".IP -.\" .Dv SIGQUIT -.\"Causes the server to checkpoint the cache into the first ``cache'' file. -.It Dv SIGIOT -Dumps statistics data into -.Pa /var/tmp/named.stats -if the server is -compiled -.Dv \-DSTATS . -Statistics data is appended to the file. -.It Dv SIGSYS -Dumps the profiling data in -.Pa /var/tmp -if the server is compiled -with profiling (server forks, chdirs and exits). -.It Dv SIGTERM -Dumps the primary and secondary database files. -Used to save modified data on shutdown if the -server is compiled with dynamic updating enabled. -.It Dv SIGUSR1 -Turns on debugging; each -.Dv SIGUSR1 -increments debug level. -.Pf ( Dv SIGEMT -on older systems without -.Dv SIGUSR1 ) -.It Dv SIGUSR2 -Turns off debugging completely. -.Pf ( Dv SIGFPE -on older systems without -.Dv SIGUSR2 ) -.El -.Sh FILES -.Bl -tag -width /var/tmp/named_dump.db -compact -.It Pa /etc/named.boot -name server configuration boot file -.It Pa /var/run/named.pid -the process id -.It Pa /var/tmp/named.run -debug output -.It Pa /var/tmp/named_dump.db -dump of the name server database -.It Pa /var/tmp/named.stats -nameserver statistics data -.El -.Sh SEE ALSO -.Xr kill 1 , -.Xr gethostbyname 3 , -.Xr signal 3 , -.Xr resolver 3 , -.Xr resolv.conf 5 , -.Xr hostname 7 , -.Rs -.%T RFC882 -.Re -.Rs -.%T RFC883 -.Re -.Rs -.%T RFC973 -.Re -.Rs -.%T RFC974 -.Re -.Rs -.%T "Name Server Operations Guide for BIND" -.Re -.Sh HISTORY -The -.Nm -command appeared in -.Bx 4.3 . diff --git a/usr.sbin/named/named.reload b/usr.sbin/named/named.reload deleted file mode 100644 index d0c45eb9cfb..00000000000 --- a/usr.sbin/named/named.reload +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -# -# @(#)named.reload 5.2 (Berkeley) 6/27/89 -# - -kill -s HUP `cat /var/run/named.pid` diff --git a/usr.sbin/named/named.restart b/usr.sbin/named/named.restart deleted file mode 100644 index dc215fd1926..00000000000 --- a/usr.sbin/named/named.restart +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -# -# @(#)named.restart 5.4 (Berkeley) 6/27/89 -# - -PATH=/bin:/sbin:/usr/sbin:/usr/bin - -kill -s KILL `cat /var/run/named.pid` -named diff --git a/usr.sbin/named/ns.h b/usr.sbin/named/ns.h deleted file mode 100644 index 92c5cd34d5b..00000000000 --- a/usr.sbin/named/ns.h +++ /dev/null @@ -1,285 +0,0 @@ -/* - * Copyright (c) 1985, 1990 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * from: @(#)ns.h 4.33 (Berkeley) 8/23/90 - * $Id: ns.h,v 1.1 1995/10/18 08:47:50 deraadt Exp $ - */ - -/* - * Global definitions and variables for the name server. - */ - -#include <arpa/inet.h> -#include <string.h> - -/* - * Timeout time should be around 1 minute or so. Using the - * the current simplistic backoff strategy, the sequence - * retrys after 4, 8, and 16 seconds. With 3 servers, this - * dies out in a little more than a minute. - * (sequence RETRYBASE, 2*RETRYBASE, 4*RETRYBASE... for MAXRETRY) - */ -#define MINROOTS 2 /* min number of root hints */ -#define NSMAX 16 /* max number of NS addrs to try */ -#define RETRYBASE 4 /* base time between retries */ -#define MAXRETRY 3 /* max number of retries per addr */ -#define MAXCNAMES 8 /* max # of CNAMES tried per addr */ -#define MAXQUERIES 20 /* max # of queries to be made */ - /* (prevent "recursive" loops) */ -#define INIT_REFRESH 600 /* retry time for initial secondary */ - /* contact (10 minutes) */ - -#define ALPHA 0.7 /* How much to preserver of old response time */ -#define BETA 1.2 /* How much to penalize response time on failure */ -#define GAMMA 0.98 /* How much to decay unused response times */ - -struct zoneinfo { - int z_type; /* type of zone */ - int z_auth; /* zone is authoritative */ - char *z_origin; /* root domain name of zone */ - time_t z_time; /* time for next refresh */ - time_t z_lastupdate; /* time of last refresh */ - u_long z_refresh; /* refresh interval */ - u_long z_retry; /* refresh retry interval */ - u_long z_expire; /* expiration time for cached info */ - u_long z_minimum; /* minimum TTL value */ - u_long z_serial; /* changes if zone modified */ - char *z_source; /* source location of data */ - time_t z_ftime; /* modification time of source file */ - int z_addrcnt; /* address count */ - struct in_addr z_addr[NSMAX]; /* list of master servers for zone */ - int z_state; /* state bits; see below */ - u_short z_xferpid; /* xfer child pid */ -#ifdef ALLOW_UPDATES - int hasChanged; /* non-zero if zone has been updated - * since last checkpoint - */ -#endif ALLOW_UPDATES -}; - - /* zone types (z_type) */ -#define Z_PRIMARY 1 -#define Z_SECONDARY 2 -#define Z_CACHE 3 - - /* zone state bits */ -#define Z_AUTH 0x01 /* should replace z_auth */ -#define Z_NEED_XFER 0x02 /* waiting to do xfer */ -#define Z_XFER_RUNNING 0x04 /* asynch. xfer is running */ -#define Z_NEED_RELOAD 0x08 /* waiting to do reload */ -#define Z_SYSLOGGED 0x10 /* have logged timeout */ -#define Z_CHANGED 0x20 /* should replace hasChanged */ -#define Z_FOUND 0x40 /* found in boot file when reloading */ -#define Z_INCLUDE 0x80 /* set if include used in file */ -#define Z_DB_BAD 0x100 /* errors when loading file */ -#define Z_TMP_FILE 0x200 /* backup file for xfer is temporary */ -#ifdef ALLOW_UPDATES -#define Z_DYNAMIC 0x400 /* allow dynamic updates */ -#define Z_DYNADDONLY 0x800 /* dynamic mode: add new data only */ -#endif ALLOW_UPDATES - - /* xfer exit codes */ -#define XFER_UPTODATE 0 /* zone is up-to-date */ -#define XFER_SUCCESS 1 /* performed transfer successfully */ -#define XFER_TIMEOUT 2 /* no server reachable/xfer timeout */ -#define XFER_FAIL 3 /* other failure, has been logged */ - -/* - * Structure for recording info on forwarded queries. - */ -struct qinfo { - u_short q_id; /* id of query */ - u_short q_nsid; /* id of forwarded query */ - int q_dfd; /* UDP file descriptor */ - struct sockaddr_in q_from; /* requestor's address */ - char *q_msg; /* the message */ - int q_msglen; /* len of message */ - int q_naddr; /* number of addr's in q_addr */ - int q_curaddr; /* last addr sent to */ - struct fwdinfo *q_fwd; /* last forwarder used */ - time_t q_time; /* time to retry */ - struct qinfo *q_next; /* rexmit list (sorted by time) */ - struct qinfo *q_link; /* storage list (random order) */ - struct qserv { - struct sockaddr_in ns_addr; /* addresses of NS's */ - struct databuf *ns; /* databuf for NS record */ - struct databuf *nsdata; /* databuf for server address */ - struct timeval stime; /* time first query started */ - int nretry; /* # of times addr retried */ - } q_addr[NSMAX]; /* addresses of NS's */ - struct databuf *q_usedns[NSMAX]; /* databuf for NS that we've tried */ - int q_nusedns; - int q_cname; /* # of cnames found */ - int q_nqueries; /* # of queries required */ - char *q_cmsg; /* the cname message */ - int q_cmsglen; /* len of cname message */ - struct qstream *q_stream; /* TCP stream, null if UDP */ - int q_system; /* boolean, system query */ -}; - -#define Q_NEXTADDR(qp,n) \ - (((qp)->q_fwd == (struct fwdinfo *)0) ? \ - &(qp)->q_addr[n].ns_addr : &(qp)->q_fwd->fwdaddr) - -#define PRIMING_CACHE 42 -#define QINFO_NULL ((struct qinfo *)0) - -#ifndef XFER -extern struct qinfo *qfindid(); -extern struct qinfo *qnew(); -extern struct qinfo *retryqp; /* next query to retry */ -#endif /* XFER */ - -/* - * Return codes from ns_forw: - */ -#define FW_OK 0 -#define FW_DUP 1 -#define FW_NOSERVER 2 -#define FW_SERVFAIL 3 - -struct qstream { - int s_rfd; /* stream file descriptor */ - int s_size; /* expected amount of data to recive */ - int s_bufsize; /* amount of data recived in s_buf */ - char *s_buf; /* buffer of recived data */ - char *s_bufp; /* pointer into s_buf of recived data */ - struct qstream *s_next; /* next stream */ - struct sockaddr_in s_from; /* address query came from */ - u_long s_time; /* time stamp of last transaction */ - int s_refcnt; /* number of outstanding queries */ - u_short s_tempsize; /* temporary for size from net */ -}; - -#define QSTREAM_NULL ((struct qstream *)0) -extern struct qstream *streamq; /* stream queue */ - -struct qdatagram { - int dq_dfd; /* datagram file descriptor */ - struct qdatagram *dq_next; /* next datagram */ - struct in_addr dq_addr; /* address of interface */ -}; - -#define QDATAGRAM_NULL ((struct qdatagram *)0) -extern struct qdatagram *datagramq; /* datagram queue */ - -struct netinfo { - struct netinfo *next; - u_long net; - u_long mask; - struct in_addr my_addr; -}; - -struct fwdinfo { - struct fwdinfo *next; - struct sockaddr_in fwdaddr; -}; - -struct nets { - char *name; - long net; - struct nets *next; -}; - -/* - * Statistics Defines - */ -struct stats { - unsigned long cnt; - char *description; -}; - -/* gross count of UDP packets in and out */ -#define S_INPKTS 0 -#define S_OUTPKTS 1 -/* gross count of queries and inverse queries received */ -#define S_QUERIES 2 -#define S_IQUERIES 3 -#define S_DUPQUERIES 4 -#define S_RESPONSES 5 -#define S_DUPRESP 6 -#define S_RESPOK 7 -#define S_RESPFAIL 8 -#define S_RESPFORMERR 9 -#define S_SYSQUERIES 10 -#define S_PRIMECACHE 11 -#define S_CHECKNS 12 -#define S_BADRESPONSES 13 -#define S_MARTIANS 14 -#define S_NSTATS 15 /* Careful! */ -#ifdef STATS -extern struct stats stats[S_NSTATS]; -extern unsigned long typestats[T_ANY+1]; -#endif - -/* - * Attempt to configure for type of function returned by signal-catching - * functions (which signal and sigvec.sv_handler take a pointer to). - * This can guess for BSD; otherwise, define SIG_FN externally. - */ -#ifndef SIG_FN -#ifdef BSD -#if BSD >= 199006 -#define SIG_FN void /* signal-catching functions return void */ -#else -#define SIG_FN int /* signal-catching functions return int */ -#endif -#else /* BSD */ -#define SIG_FN void /* signal-catching functions return void */ -#endif /* BSD */ -#endif - - -#ifdef DEBUG -extern int debug; /* debug flag */ -extern FILE *ddt; /* debug file discriptor */ -#endif -#ifndef XFER -extern int ds; /* datagram socket */ -extern struct qdatagram *dqp; -extern struct timeval tt; /* place to store time */ - -extern struct itimerval ival; /* maintenance interval */ -extern struct zoneinfo *zones; /* zone information */ -extern int nzones; /* number of zones in use */ - -extern int forward_only; /* true on slave server */ -#endif /* XFER */ - -#define MAX_XFER_TIME 60 * 60 * 2 /* max seconds for an xfer */ -#define XFER_TIME_FUDGE 10 /* MAX_XFER_TIME fudge */ - -#ifndef XFER -extern int xfer_running_cnt; /* number of xfers running */ -extern int xfer_deferred_cnt; /* number of deferred xfers */ -#define MAX_XFERS_RUNNING 4 /* max value of xfer_running_cnt */ -#endif /* XFER */ diff --git a/usr.sbin/named/ns_forw.c b/usr.sbin/named/ns_forw.c deleted file mode 100644 index 9f2e8202050..00000000000 --- a/usr.sbin/named/ns_forw.c +++ /dev/null @@ -1,579 +0,0 @@ -/*- - * Copyright (c) 1986 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -/*static char sccsid[] = "from: @(#)ns_forw.c 4.32 (Berkeley) 3/3/91";*/ -static char rcsid[] = "$Id: ns_forw.c,v 1.1 1995/10/18 08:47:50 deraadt Exp $"; -#endif /* not lint */ - -#include <sys/param.h> -#include <sys/time.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <syslog.h> -#include <arpa/nameser.h> -#include <resolv.h> -#include <stdio.h> -#include "ns.h" -#include "db.h" - -struct qinfo *qhead = QINFO_NULL; /* head of allocated queries */ -struct qinfo *retryqp = QINFO_NULL; /* list of queries to retry */ -struct fwdinfo *fwdtab; /* list of forwarding hosts */ - -int nsid; /* next forwarded query id */ -extern int forward_only; /* you are only a slave */ -extern int errno; -extern u_short ns_port; - -time_t retrytime(); - -/* - * Forward the query to get the answer since its not in the database. - * Returns FW_OK if a request struct is allocated and the query sent. - * Returns FW_DUP if this is a duplicate of a pending request. - * Returns FW_NOSERVER if there were no addresses for the nameservers. - * Returns FW_SERVFAIL on malloc error. - * (no action is taken on errors and qpp is not filled in.) - */ -ns_forw(nsp, msg, msglen, fp, qsp, dfd, qpp) - struct databuf *nsp[]; - char *msg; - int msglen; - struct sockaddr_in *fp; - struct qstream *qsp; - int dfd; - struct qinfo **qpp; -{ - register struct qinfo *qp; - HEADER *hp; - u_short id; - extern char *calloc(); - -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"ns_forw()\n"); -#endif - - /* Don't forward if we're already working on it. */ - hp = (HEADER *) msg; - id = hp->id; - /* Look at them all */ - for (qp = qhead; qp!=QINFO_NULL; qp = qp->q_link) { - if (qp->q_id == id && - bcmp((char *)&qp->q_from, fp, sizeof(qp->q_from)) == 0 && - ((qp->q_cmsglen == 0 && qp->q_msglen == msglen && - bcmp((char *)qp->q_msg+2, msg+2, msglen-2) == 0) || - (qp->q_cmsglen == msglen && - bcmp((char *)qp->q_cmsg+2, msg+2, msglen-2) == 0))) { -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"forw: dropped DUP id=%d\n", ntohs(id)); -#endif -#ifdef STATS - stats[S_DUPQUERIES].cnt++; -#endif - return (FW_DUP); - } - } - - qp = qnew(); - if (nslookup(nsp, qp) == 0) { -#ifdef DEBUG - if (debug >= 2) - fprintf(ddt,"forw: no nameservers found\n"); -#endif - qfree(qp); - return (FW_NOSERVER); - } - qp->q_stream = qsp; - qp->q_curaddr = 0; - qp->q_fwd = fwdtab; - qp->q_dfd = dfd; - qp->q_id = id; - hp->id = qp->q_nsid = htons((u_short)++nsid); - hp->ancount = 0; - hp->nscount = 0; - hp->arcount = 0; - qp->q_from = *fp; - if ((qp->q_msg = malloc((unsigned)msglen)) == NULL) { - syslog(LOG_ERR, "forw: %m"); - qfree(qp); - return (FW_SERVFAIL); - } - bcopy(msg, qp->q_msg, qp->q_msglen = msglen); - if (!qp->q_fwd) { - hp->rd = 0; - qp->q_addr[0].stime = tt; - } - - schedretry(qp, retrytime(qp)); -#ifdef DEBUG - if (debug) - fprintf(ddt, - "forw: forw -> %s %d (%d) nsid=%d id=%d %dms retry %d sec\n", - inet_ntoa(Q_NEXTADDR(qp,0)->sin_addr), - ds, ntohs(Q_NEXTADDR(qp,0)->sin_port), - ntohs(qp->q_nsid), ntohs(qp->q_id), - qp->q_addr[0].nsdata->d_nstime, - qp->q_time - tt.tv_sec); - if ( debug >= 10) - fp_query(msg, ddt); -#endif - if (sendto(ds, msg, msglen, 0, (struct sockaddr *)Q_NEXTADDR(qp,0), - sizeof(struct sockaddr_in)) < 0){ -#ifdef DEBUG - if (debug >= 5) - fprintf(ddt,"error returning msg errno=%d\n",errno); -#endif - } -#ifdef STATS - stats[S_OUTPKTS].cnt++; -#endif - if (qpp) - *qpp = qp; - hp->rd = 1; - return (0); -} - -/* - * Lookup the address for each nameserver in `nsp' and add it to - * the list saved in the qinfo structure. - */ -nslookup(nsp, qp) - struct databuf *nsp[]; - register struct qinfo *qp; -{ - register struct namebuf *np; - register struct databuf *dp, *nsdp; - register struct qserv *qs; - register int n, i; - struct hashbuf *tmphtp; - char *dname, *fname; - int oldn, naddr, class, found_arr; - time_t curtime; - int qcomp(); - -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"nslookup(nsp=x%x,qp=x%x)\n",nsp,qp); -#endif - - naddr = n = qp->q_naddr; - curtime = (u_long) tt.tv_sec; - while ((nsdp = *nsp++) != NULL) { - class = nsdp->d_class; - dname = nsdp->d_data; -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"nslookup: NS %s c%d t%d (x%x)\n", - dname, class, nsdp->d_type, nsdp->d_flags); -#endif - /* don't put in people we have tried */ - for (i = 0; i < qp->q_nusedns; i++) - if (qp->q_usedns[i] == nsdp) { -#ifdef DEBUG - if (debug >= 2) -fprintf(ddt, "skipping used NS w/name %s\n", nsdp->d_data); -#endif DEBUG - goto skipserver; - } - - tmphtp = ((nsdp->d_flags & DB_F_HINT) ? fcachetab : hashtab); - np = nlookup(dname, &tmphtp, &fname, 1); - if (np == NULL || fname != dname) { -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"%s: not found %s %x\n",dname,fname,np); -#endif - continue; - } - found_arr = 0; - oldn = n; - /* look for name server addresses */ - for (dp = np->n_data; dp != NULL; dp = dp->d_next) { - if (dp->d_type != T_A || dp->d_class != class) - continue; - /* - * Don't use records that may become invalid to - * reference later when we do the rtt computation. - * Never delete our safety-belt information! - */ - if ((dp->d_zone == 0) && - (dp->d_ttl < (curtime+900)) && - !(dp->d_flags & DB_F_HINT) ) - { -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"nslookup: stale entry '%s'\n", - np->n_dname); -#endif - /* Cache invalidate the NS RR's */ - if (dp->d_ttl < curtime) - delete_all(np, class, T_A); - n = oldn; - break; - } - - found_arr++; - /* don't put in duplicates */ - qs = qp->q_addr; - for (i = 0; i < n; i++, qs++) - if (bcmp((char *)&qs->ns_addr.sin_addr, - dp->d_data, sizeof(struct in_addr)) == 0) - goto skipaddr; - qs->ns_addr.sin_family = AF_INET; - qs->ns_addr.sin_port = ns_port; - qs->ns_addr.sin_addr = - *(struct in_addr *)dp->d_data; - qs->ns = nsdp; - qs->nsdata = dp; - qp->q_addr[n].nretry = 0; - n++; - if (n >= NSMAX) - goto out; - skipaddr: ; - } -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"nslookup: %d ns addrs\n", n); -#endif - if (found_arr == 0 && qp->q_system == 0) - (void) sysquery(dname, class, T_A); -skipserver: ; - } -out: -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"nslookup: %d ns addrs total\n", n); -#endif - qp->q_naddr = n; - if (n > 1) - qsort((char *)qp->q_addr, n, sizeof(struct qserv), qcomp); - return (n - naddr); -} - -qcomp(qs1, qs2) - struct qserv *qs1, *qs2; -{ - - return (qs1->nsdata->d_nstime - qs2->nsdata->d_nstime); -} - -/* - * Arrange that forwarded query (qp) is retried after t seconds. - */ -schedretry(qp, t) - struct qinfo *qp; - time_t t; -{ - register struct qinfo *qp1, *qp2; - -#ifdef DEBUG - if (debug > 3) { - fprintf(ddt,"schedretry(%#x, %dsec)\n", qp, t); - if (qp->q_time) - fprintf(ddt,"WARNING: schedretry(%x,%d) q_time already %d\n", qp->q_time); - } -#endif - t += (u_long) tt.tv_sec; - qp->q_time = t; - - if ((qp1 = retryqp) == NULL) { - retryqp = qp; - qp->q_next = NULL; - return; - } - if (t < qp1->q_time) { - qp->q_next = qp1; - retryqp = qp; - return; - } - while ((qp2 = qp1->q_next) != NULL && qp2->q_time < t) - qp1 = qp2; - qp1->q_next = qp; - qp->q_next = qp2; -} - -/* - * Unsched is called to remove a forwarded query entry. - */ -unsched(qp) - struct qinfo *qp; -{ - register struct qinfo *np; - -#ifdef DEBUG - if (debug > 3) { - fprintf(ddt,"unsched(%#x, %d )\n", qp, ntohs(qp->q_id)); - } -#endif - if( retryqp == qp ) { - retryqp = qp->q_next; - } else { - for( np=retryqp; np->q_next != QINFO_NULL; np = np->q_next ) { - if( np->q_next != qp) - continue; - np->q_next = qp->q_next; /* dequeue */ - break; - } - } - qp->q_next = QINFO_NULL; /* sanity check */ - qp->q_time = 0; -} - -/* - * Retry is called to retransmit query 'qp'. - */ -retry(qp) - register struct qinfo *qp; -{ - register int n; - register HEADER *hp; - -#ifdef DEBUG - if (debug > 3) - fprintf(ddt,"retry(x%x) id=%d\n", qp, ntohs(qp->q_id)); -#endif - if((HEADER *)qp->q_msg == NULL) { /*** XXX ***/ - qremove(qp); - return; - } /*** XXX ***/ - - /* try next address */ - n = qp->q_curaddr; - if (qp->q_fwd) { - qp->q_fwd = qp->q_fwd->next; - if (qp->q_fwd) - goto found; - /* out of forwarders, try direct queries */ - } else - ++qp->q_addr[n].nretry; - if (!forward_only) { - do { - if (++n >= qp->q_naddr) - n = 0; - if (qp->q_addr[n].nretry < MAXRETRY) - goto found; - } while (n != qp->q_curaddr); - } - /* - * Give up. Can't reach destination. - */ - hp = (HEADER *)(qp->q_cmsg ? qp->q_cmsg : qp->q_msg); - if (qp->q_system == PRIMING_CACHE) { - /* Can't give up priming */ - unsched(qp); - schedretry(qp, (time_t)60*60); /* 1 hour */ - hp->rcode = NOERROR; /* Lets be safe, reset the query */ - hp->qr = hp->aa = 0; - qp->q_fwd = fwdtab; - for (n = 0; n < qp->q_naddr; n++) - qp->q_addr[n].nretry = 0; - return; - } -#ifdef DEBUG - if (debug >= 5) - fprintf(ddt,"give up\n"); -#endif - n = ((HEADER *)qp->q_cmsg ? qp->q_cmsglen : qp->q_msglen); - hp->id = qp->q_id; - hp->qr = 1; - hp->ra = 1; - hp->rd = 1; - hp->rcode = SERVFAIL; -#ifdef DEBUG - if (debug >= 10) - fp_query(qp->q_msg, ddt); -#endif - if (send_msg((char *)hp, n, qp)) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"gave up retry(x%x) nsid=%d id=%d\n", - qp, ntohs(qp->q_nsid), ntohs(qp->q_id)); -#endif - } - qremove(qp); - return; - -found: - if (qp->q_fwd == 0 && qp->q_addr[n].nretry == 0) - qp->q_addr[n].stime = tt; - qp->q_curaddr = n; - hp = (HEADER *)qp->q_msg; - hp->rd = (qp->q_fwd ? 1 : 0); -#ifdef DEBUG - if (debug) - fprintf(ddt,"%s(addr=%d n=%d) -> %s %d (%d) nsid=%d id=%d %dms\n", - (qp->q_fwd ? "reforw" : "resend"), - n, qp->q_addr[n].nretry, - inet_ntoa(Q_NEXTADDR(qp,n)->sin_addr), - ds, ntohs(Q_NEXTADDR(qp,n)->sin_port), - ntohs(qp->q_nsid), ntohs(qp->q_id), - qp->q_addr[n].nsdata->d_nstime); - if ( debug >= 10) - fp_query(qp->q_msg, ddt); -#endif - /* NOSTRICT */ - if (sendto(ds, qp->q_msg, qp->q_msglen, 0, - (struct sockaddr *)Q_NEXTADDR(qp,n), - sizeof(struct sockaddr_in)) < 0){ -#ifdef DEBUG - if (debug > 3) - fprintf(ddt,"error resending msg errno=%d\n",errno); -#endif - } - hp->rd = 1; /* leave set to 1 for dup detection */ -#ifdef STATS - stats[S_OUTPKTS].cnt++; -#endif - unsched(qp); - schedretry(qp, qp->q_fwd ? (2*RETRYBASE) : retrytime(qp)); -} - -/* - * Compute retry time for the next server for a query. - * Use a minimum time of RETRYBASE (4 sec.) or twice the estimated - * service time; * back off exponentially on retries, but place a 45-sec. - * ceiling on retry times for now. (This is because we don't hold a reference - * on servers or their addresses, and we have to finish before they time out.) - */ -time_t -retrytime(qp) -register struct qinfo *qp; -{ - time_t t; - struct qserv *ns = &qp->q_addr[qp->q_curaddr]; - -#ifdef DEBUG - if (debug > 3) - fprintf(ddt,"retrytime: nstime %dms.\n", - ns->nsdata->d_nstime / 1000); -#endif - t = (time_t) MAX(RETRYBASE, 2 * ns->nsdata->d_nstime / 1000); - t <<= ns->nretry; - t = MIN(t, 45); /* max. retry timeout for now */ -#ifdef notdef - if (qp->q_system) - return ((2 * t) + 5); /* system queries can wait. */ -#endif - return (t); -} - -qflush() -{ - while (qhead) - qremove(qhead); - qhead = QINFO_NULL; -} - -qremove(qp) -register struct qinfo *qp; -{ -#ifdef DEBUG - if(debug > 3) - fprintf(ddt,"qremove(x%x)\n", qp); -#endif - unsched(qp); /* get off queue first */ - qfree(qp); -} - -struct qinfo * -qfindid(id) -register u_short id; -{ - register struct qinfo *qp; - -#ifdef DEBUG - if(debug > 3) - fprintf(ddt,"qfindid(%d)\n", ntohs(id)); -#endif - for (qp = qhead; qp!=QINFO_NULL; qp = qp->q_link) { - if (qp->q_nsid == id) - return(qp); - } -#ifdef DEBUG - if (debug >= 5) - fprintf(ddt,"qp not found\n"); -#endif - return(NULL); -} - -struct qinfo * -qnew() -{ - register struct qinfo *qp; - - if ((qp = (struct qinfo *)calloc(1, sizeof(struct qinfo))) == NULL) { -#ifdef DEBUG - if (debug >= 5) - fprintf(ddt,"qnew: calloc error\n"); -#endif - syslog(LOG_ERR, "forw: %m"); - exit(12); - } -#ifdef DEBUG - if (debug >= 5) - fprintf(ddt,"qnew(x%x)\n", qp); -#endif - qp->q_link = qhead; - qhead = qp; - return( qp ); -} - -qfree(qp) -struct qinfo *qp; -{ - register struct qinfo *np; - -#ifdef DEBUG - if(debug > 3) - fprintf(ddt,"qfree( x%x )\n", qp); - if(debug && qp->q_next) - fprintf(ddt,"WARNING: qfree of linked ptr x%x\n", qp); -#endif - if (qp->q_msg) - free(qp->q_msg); - if (qp->q_cmsg) - free(qp->q_cmsg); - if( qhead == qp ) { - qhead = qp->q_link; - } else { - for( np=qhead; np->q_link != QINFO_NULL; np = np->q_link ) { - if( np->q_link != qp ) continue; - np->q_link = qp->q_link; /* dequeue */ - break; - } - } - (void)free((char *)qp); -} diff --git a/usr.sbin/named/ns_init.c b/usr.sbin/named/ns_init.c deleted file mode 100644 index 0e99b972d35..00000000000 --- a/usr.sbin/named/ns_init.c +++ /dev/null @@ -1,704 +0,0 @@ -/*- - * Copyright (c) 1986, 1990 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -/*static char sccsid[] = "from: @(#)ns_init.c 4.38 (Berkeley) 3/21/91";*/ -static char rcsid[] = "$Id: ns_init.c,v 1.1 1995/10/18 08:47:50 deraadt Exp $"; -#endif /* not lint */ - -#include <sys/param.h> -#include <sys/socket.h> -#include <sys/time.h> -#include <sys/stat.h> -#include <netinet/in.h> -#include <arpa/nameser.h> -#include <syslog.h> -#include <signal.h> -#include <resolv.h> -#include <stdio.h> -#include <errno.h> -#include <ctype.h> -#include <string.h> -#undef nsaddr -#include "pathnames.h" -#include "ns.h" -#include "db.h" - -struct zoneinfo *zones; /* zone information */ -int nzones; /* number of zones in use */ -int forward_only = 0; /* run only as a slave */ -char *cache_file; -char *localdomain; /* "default" for non-dotted names */ -int maint_interval = 15*60; /* minimum ns_maint() interval */ - -extern int lineno; - - -/* - * Read boot file for configuration info. - */ - -ns_init(bootfile) - char *bootfile; -{ - register struct zoneinfo *zp; - struct zoneinfo *find_zone(); - char buf[BUFSIZ], obuf[BUFSIZ], *source; - extern char *calloc(); - FILE *fp; - int type; - extern int needmaint; - struct stat f_time; - static int loads = 0; /* number of times loaded */ - static int tmpnum = 0; /* unique number for tmp zone files */ -#ifdef ALLOW_UPDATES - char *cp, *flag; -#endif - -#ifdef DEBUG - if (debug) - fprintf(ddt,"\nns_init(%s)\n", bootfile); -#endif - gettime(&tt); - - if ((fp = fopen(bootfile, "r")) == NULL) { - syslog(LOG_ERR, "%s: %m", bootfile); - exit(1); - } - lineno = 0; - if (loads == 0) { - if ((zones = - (struct zoneinfo *)calloc(64, sizeof(struct zoneinfo))) - == NULL) { - syslog(LOG_ERR, - "Not enough memory to allocate initial zones array"); - exit(1); - } - nzones = 1; /* zone zero is cache data */ - /* allocate cache hash table, formerly the root hash table. */ - hashtab = savehash((struct hashbuf *)NULL); - - /* allocate root-hints/file-cache hash table */ - fcachetab = savehash((struct hashbuf *)NULL); - /* init zone data */ - zones[0].z_type = Z_CACHE; - } else { - /* Mark previous zones as not yet found in boot file. */ - for (zp = &zones[1]; zp < &zones[nzones]; zp++) - zp->z_state &= ~Z_FOUND; - if (localdomain) - free(localdomain); - localdomain = NULL; - free_forwarders(); - forward_only = 0; - } - -#ifdef DEBUG - if (debug >= 3) { - fprintf(ddt,"\n content of zones before loading \n"); - content_zone(nzones - 1); - } -#endif - while (!feof(fp) && !ferror(fp)) { - if (!getword(buf, sizeof(buf), fp)) - continue; - /* read named.boot keyword and process args */ - if (strcasecmp(buf, "directory") == 0) { - (void) getword(buf, sizeof(buf), fp); - if (chdir(buf) < 0) { - syslog(LOG_CRIT, "directory %s: %m\n", - buf); - exit(1); - } - continue; - } else if (strcasecmp(buf, "sortlist") == 0) { - get_sort_list(fp); - continue; - } else if (strcasecmp(buf, "forwarders") == 0) { - get_forwarders(fp); - continue; - } else if (strcasecmp(buf, "slave") == 0) { - forward_only++; - endline(fp); - continue; - } else if (strcasecmp(buf, "domain") == 0) { - if (getword(buf, sizeof(buf), fp)) - localdomain = savestr(buf); - endline(fp); - continue; - } else if (strcasecmp(buf, "cache") == 0) - type = Z_CACHE; - else if (strcasecmp(buf, "primary") == 0) - type = Z_PRIMARY; - else if (strcasecmp(buf, "secondary") == 0) - type = Z_SECONDARY; - else { - syslog(LOG_ERR, "%s: line %d: unknown field '%s'\n", - bootfile, lineno, buf); - endline(fp); - continue; - } - - /* - * read zone origin - */ - if (!getword(obuf, sizeof(obuf), fp)) { - syslog(LOG_ERR, "%s: line %d: missing origin\n", - bootfile, lineno); - continue; - } -#ifdef DEBUG - if (debug) - fprintf(ddt, "zone origin %s", obuf); -#endif - if (obuf[0] == '.' && obuf[1] == '\0') - obuf[0] = '\0'; - /* - * read source file or host address - */ - if (!getword(buf, sizeof(buf), fp)) { - syslog(LOG_ERR, - "%s: line %d: missing source or addr\n", - bootfile, lineno); - continue; - } - - /* check for previous instance of this zone (reload) */ - if ((zp = find_zone(obuf, type)) == 0) { - if (type == Z_CACHE) { - zp = &zones[0]; - zp->z_origin = ""; - goto gotzone; - } - for (zp = &zones[1]; zp < &zones[nzones]; zp++) - if (zp->z_type == 0) - goto gotzone; - /* - * this code assume that nzones never decreases - */ - if (nzones % 64 == 0) { -#ifdef DEBUG - if (debug > 1) - fprintf(ddt, "Reallocating zones structure\n"); -#endif DEBUG - /* - * Realloc() not used since it might damage zones - * if an error occurs - */ - if ((zp = (struct zoneinfo *) - malloc((64 + nzones) * sizeof(struct zoneinfo))) - == NULL) { - syslog(LOG_ERR, "no memory for more zones"); -#ifdef DEBUG - if (debug) - fprintf(ddt, - "Out of memory for new zones\n"); -#endif DEBUG - endline(fp); - continue; - } - bcopy((char *)zones, (char *)zp, - nzones * sizeof(struct zoneinfo)); - bzero((char *)&zp[nzones], - 64 * sizeof(struct zoneinfo)); - free(zones); - zones = zp; - } - zp = &zones[nzones++]; - gotzone: - zp->z_origin = savestr(obuf); - zp->z_type = type; - } - zp->z_addrcnt = 0; - - switch (type) { - case Z_CACHE: - source = savestr(buf); -#ifdef DEBUG - if (debug) - fprintf(ddt,", source = %s\n", source); -#endif - zp->z_refresh = 0; /* by default, no dumping */ - if (getword(buf, sizeof(buf), fp)) { -#ifdef notyet - zp->z_refresh = atoi(buf); - if (zp->z_refresh <= 0) { - syslog(LOG_ERR, - "%s: line %d: bad refresh time '%s', ignored\n", - bootfile, lineno, buf); - zp->z_refresh = 0; - } else if (cache_file == NULL) - cache_file = source; -#else - syslog(LOG_WARNING, - "%s: line %d: cache refresh ignored\n", - bootfile, lineno); -#endif - endline(fp); - } - /* - * If we've loaded this file, and the file has - * not been modified and contains no $include, - * then there's no need to reload. - */ - if (zp->z_source && strcmp(source, zp->z_source) == 0 && - (zp->z_state & Z_INCLUDE) == 0 && - stat(zp->z_source, &f_time) == 0 && - zp->z_ftime == f_time.st_mtime) { -#ifdef DEBUG - if (debug) - fprintf(ddt, "cache is up to date\n"); -#endif - break; /* zone is already up to date */ - } - - /* file has changed, or hasn't been loaded yet */ - if (zp->z_source) { - free(zp->z_source); - remove_zone(fcachetab, 0); - } - zp->z_source = source; -#ifdef DEBUG - if (debug) - fprintf(ddt, "reloading zone\n"); -#endif - (void) db_load(zp->z_source, zp->z_origin, zp, 0); - break; - - case Z_PRIMARY: - source = savestr(buf); -#ifdef ALLOW_UPDATES - if (getword(buf, sizeof(buf), fp)) { - endline(fp); - flag = buf; - while (flag) { - cp = index(flag, ','); - if (cp) - *cp++ = 0; - if (strcasecmp(flag, "dynamic") == 0) - zp->z_state |= Z_DYNAMIC; - else if (strcasecmp(flag, "addonly") == 0) - zp->z_state |= Z_DYNADDONLY; - else { - syslog(LOG_ERR, - "%s: line %d: bad flag '%s'\n", - bootfile, lineno, flag); - } - flag = cp; - } - } -#else ALLOW_UPDATES - endline(fp); -#endif - -#ifdef DEBUG - if (debug) - fprintf(ddt,", source = %s\n", source); -#endif - /* - * If we've loaded this file, and the file has - * not been modified and contains no $include, - * then there's no need to reload. - */ - if (zp->z_source && strcmp(source, zp->z_source) == 0 && - (zp->z_state & Z_INCLUDE) == 0 && - stat(zp->z_source, &f_time) == 0 && - zp->z_ftime == f_time.st_mtime) { -#ifdef DEBUG - if (debug) - fprintf(ddt, "zone is up to date\n"); -#endif - break; /* zone is already up to date */ - } - if (zp->z_source) { - free(zp->z_source); - remove_zone(hashtab, zp - zones); - } - zp->z_source = source; - zp->z_auth = 0; -#ifdef DEBUG - if (debug) - fprintf(ddt, "reloading zone\n"); -#endif - if (db_load(zp->z_source, zp->z_origin, zp, 0) == 0) - zp->z_auth = 1; -#ifdef ALLOW_UPDATES - /* Guarantee calls to ns_maint() */ - zp->z_refresh = maint_interval; -#else ALLOW_UPDATES - zp->z_refresh = 0; /* no maintenance needed */ - zp->z_time = 0; -#endif ALLOW_UPDATES - break; - - case Z_SECONDARY: - source = 0; -#ifdef DEBUG - if (debug) - fprintf(ddt,"\n\taddrs: "); -#endif - do { - zp->z_addr[zp->z_addrcnt].s_addr = - inet_addr(buf); - if (zp->z_addr[zp->z_addrcnt].s_addr == - (u_long)-1) { - source = savestr(buf); - endline(fp); - break; - } -#ifdef DEBUG - if (debug) - fprintf(ddt,"%s, ",buf); -#endif - if (++zp->z_addrcnt > NSMAX - 1) { - zp->z_addrcnt = NSMAX - 1; -#ifdef DEBUG - if (debug) - fprintf(ddt, - "\nns.h NSMAX reached\n"); -#endif - } - } while (getword(buf, sizeof(buf), fp)); -#ifdef DEBUG - if (debug) - fprintf(ddt,"addrcnt = %d\n", zp->z_addrcnt); -#endif - if (source == 0) { - /* - * We will always transfer this zone again - * after a reload. - */ - sprintf(buf, "/%s/NsTmp%d", _PATH_TMPDIR, - tmpnum++); - source = savestr(buf); - zp->z_state |= Z_TMP_FILE; - } else - zp->z_state &= ~Z_TMP_FILE; - /* - * If we had a backup file name, and it was changed, - * free old zone and start over. If we don't have - * current zone contents, try again now in case - * we have a new server on the list. - */ - if (zp->z_source && strcmp(source, zp->z_source)) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"backup file changed\n"); -#endif - free(zp->z_source); - zp->z_source = 0; - zp->z_auth = 0; - zp->z_serial = 0; /* force xfer */ - remove_zone(hashtab, zp - zones); - } - if (zp->z_source) - free(source); - else - zp->z_source = source; - if (zp->z_auth == 0) - zoneinit(zp); - break; - - } - zp->z_state |= Z_FOUND; -#ifdef DEBUG - if (debug) - fprintf(ddt,"zone[%d] type %d: '%s'", - zp-zones, type, - *(zp->z_origin) == '\0' ? "." : zp->z_origin); -#endif - if (zp->z_refresh && zp->z_time == 0) - zp->z_time = zp->z_refresh + tt.tv_sec; - if (zp->z_time <= tt.tv_sec) - needmaint = 1; -#ifdef DEBUG - if (debug) - fprintf(ddt, " z_time %d, z_refresh %d\n", - zp->z_time, zp->z_refresh); -#endif - } - (void) fclose(fp); - /* erase all old zones that were not found */ - for (zp = &zones[1]; zp < &zones[nzones]; zp++) - if (zp->z_type && (zp->z_state & Z_FOUND) == 0) { - remove_zone(hashtab, zp - zones); - bzero((char *) zp, sizeof(*zp)); -#ifdef DEBUG - if(debug >=2) - fprintf(ddt,"\n zone no %d was removed \n", zp - zones); -#endif - } -#ifdef DEBUG - if(debug >= 2) { - fprintf(ddt,"\n content of zones after loading \n"); - content_zone(nzones-1); - } -#endif - - /* - * Schedule calls to ns_maint(). - */ - if (needmaint == 0) - sched_maint(); -#ifdef DEBUG - if (debug) - fprintf(ddt,"exit ns_init()%s\n", needmaint ? - ", need maintenance immediately" : ""); -#endif - loads++; -} - -zoneinit(zp) - register struct zoneinfo *zp; -{ - extern int needmaint; - struct stat sb; - - /* - * Try to load zone from backup file, - * if one was specified and it exists. - * If not, or if the data are out of date, - * we will refresh the zone from a primary - * immediately. - */ - if (zp->z_source == NULL) - return; - if (stat(zp->z_source, &sb) == -1 || - db_load(zp->z_source, zp->z_origin, zp, 0) != 0) { - /* - * Set zone to be refreshed immediately. - */ - zp->z_refresh = INIT_REFRESH; - zp->z_retry = INIT_REFRESH; - zp->z_time = tt.tv_sec; - needmaint = 1; - } else - zp->z_auth = 1; -} - -#ifdef ALLOW_UPDATES -/* - * Look for the authoritative zone with the longest matching RHS of dname - * and return its zone # or zero if not found. - */ -findzone(dname, class) - char *dname; - int class; -{ - char *dZoneName, *zoneName, *index(); - int dZoneNameLen, zoneNameLen; - int maxMatchLen = 0; - int maxMatchZoneNum = 0; - int zoneNum; - -#ifdef DEBUG - if (debug >= 4) - fprintf(ddt, "findzone(dname=%s, class=%d)\n", dname, class); - if (debug >= 5) { - fprintf(ddt, "zone dump:\n"); - for (zoneNum = 1; zoneNum < nzones; zoneNum++) - printzoneinfo(zoneNum); - } -#endif DEBUG - - dZoneName = index(dname, '.'); - if (dZoneName == NULL) - dZoneName = ""; /* root */ - else - dZoneName++; /* There is a '.' in dname, so use remainder of - string as the zone name */ - dZoneNameLen = strlen(dZoneName); - for (zoneNum = 1; zoneNum < nzones; zoneNum++) { - zoneName = (zones[zoneNum]).z_origin; - zoneNameLen = strlen(zoneName); - /* The zone name may or may not end with a '.' */ - if (zoneName[zoneNameLen - 1] == '.') - zoneNameLen--; - if (dZoneNameLen != zoneNameLen) - continue; -#ifdef DEBUG - if (debug >= 5) - fprintf(ddt, "about to strncasecmp('%s', '%s', %d)\n", - dZoneName, zoneName, dZoneNameLen); -#endif - if (strncasecmp(dZoneName, zoneName, dZoneNameLen) == 0) { -#ifdef DEBUG - if (debug >= 5) - fprintf(ddt, "match\n"); -#endif - /* - * See if this is as long a match as any so far. - * Check if "<=" instead of just "<" so that if - * root domain (whose name length is 0) matches, - * we use it's zone number instead of just 0 - */ - if (maxMatchLen <= zoneNameLen) { - maxMatchZoneNum = zoneNum; - maxMatchLen = zoneNameLen; - } - } -#ifdef DEBUG - else - if (debug >= 5) - fprintf(ddt, "no match\n"); -#endif - } -#ifdef DEBUG - if (debug >= 4) - fprintf(ddt, "findzone: returning %d\n", maxMatchZoneNum); -#endif DEBUG - return (maxMatchZoneNum); -} -#endif ALLOW_UPDATES - -soa_zinfo(zp, cp, eom) - register struct zoneinfo *zp; - register u_char *cp; - u_char *eom; -{ - cp += 3 * sizeof(u_short); - cp += sizeof(u_long); - cp += dn_skipname(cp, eom); - cp += dn_skipname(cp, eom); - GETLONG(zp->z_serial, cp); - GETLONG(zp->z_refresh, cp); - gettime(&tt); - zp->z_time = tt.tv_sec + zp->z_refresh; - GETLONG(zp->z_retry, cp); - GETLONG(zp->z_expire, cp); - GETLONG(zp->z_minimum, cp); -} - -get_forwarders(fp) - FILE *fp; -{ - char buf[BUFSIZ]; - register struct fwdinfo *fip = NULL, *ftp = NULL; - extern struct sockaddr_in nsaddr; - extern struct fwdinfo *fwdtab; - -#ifdef DEBUG - if (debug) - fprintf(ddt,"forwarders "); -#endif - - /* on mulitple forwarder lines, move to end of the list */ - if (fwdtab != NULL) - for (fip = fwdtab; fip->next != NULL; fip = fip->next) - ; - - while (getword(buf, sizeof(buf), fp)) { - if (strlen(buf) == 0) - break; -#ifdef DEBUG - if (debug) - fprintf(ddt," %s",buf); -#endif - if (ftp == NULL) - ftp = (struct fwdinfo *)malloc(sizeof(struct fwdinfo)); - if (isdigit(buf[0]) && - (ftp->fwdaddr.sin_addr.s_addr = inet_addr(buf)) != - (u_long)-1) { - ftp->fwdaddr.sin_port = nsaddr.sin_port; - ftp->fwdaddr.sin_family = AF_INET; - } else { - syslog(LOG_ERR, "'%s' (ignored, NOT dotted quad)", buf); -#ifdef DEBUG - if (debug) - fprintf(ddt," (ignored, NOT dotted quad)"); -#endif - continue; - } - ftp->next = NULL; - if (fwdtab == NULL) - fwdtab = ftp; /* First time only */ - else - fip->next = ftp; - fip = ftp; - ftp = NULL; - } - if (ftp) - free((char *)ftp); - -#ifdef DEBUG - if (debug) - fprintf(ddt,"\n"); - if (debug > 2) - for (ftp = fwdtab; ftp != NULL; ftp = ftp->next) - fprintf(ddt,"ftp x%x %s next x%x\n", ftp, - inet_ntoa(ftp->fwdaddr.sin_addr), ftp->next); -#endif -} - -free_forwarders() -{ - extern struct fwdinfo *fwdtab; - register struct fwdinfo *ftp, *fnext; - - for (ftp = fwdtab; ftp != NULL; ftp = fnext) { - fnext = ftp->next; - free((char *)ftp); - } - fwdtab = NULL; -} - -struct zoneinfo * -find_zone(name, type) - char *name; - int type; -{ - register struct zoneinfo *zp; - - for (zp = &zones[1]; zp < &zones[nzones]; zp++) - if (zp->z_type == type && strcasecmp(name, zp->z_origin) == 0) { -#ifdef DEBUG - if (debug > 1) - fprintf(ddt, ", old zone (%d)", zp - zones); -#endif - return (zp); - } -#ifdef DEBUG - if(debug > 1) - fprintf(ddt, ", new zone"); -#endif - return ((struct zoneinfo *)NULL); -} - -/* prints out the content of zones */ -content_zone(end) - int end; -{ - int i; - for (i = 1; i <= end; i++) - printzoneinfo(i); -} diff --git a/usr.sbin/named/ns_main.c b/usr.sbin/named/ns_main.c deleted file mode 100644 index ec0c429b002..00000000000 --- a/usr.sbin/named/ns_main.c +++ /dev/null @@ -1,1301 +0,0 @@ -/* - * Copyright (c) 1986, 1989, 1990 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -char copyright[] = -"@(#) Copyright (c) 1986, 1989, 1990 Regents of the University of California.\n\ - All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -/*static char sccsid[] = "from: @(#)ns_main.c 4.55 (Berkeley) 7/1/91";*/ -static char rcsid[] = "$Id: ns_main.c,v 1.1 1995/10/18 08:47:50 deraadt Exp $"; -#endif /* not lint */ - -/* -* Internet Name server (see rfc883 & others). -*/ - -#include <sys/param.h> -#if defined(SYSV) -#include <fcntl.h> -#endif SYSV -#include <sys/file.h> -#include <sys/time.h> -#if !defined(SYSV) -#include <sys/wait.h> -#endif !SYSV -#include <sys/resource.h> -#include <sys/ioctl.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <net/if.h> -#include <stdio.h> -#include <syslog.h> -#include <errno.h> -#include <signal.h> -#include <netdb.h> -#include <arpa/nameser.h> -#include <arpa/inet.h> -#include <resolv.h> -#undef nsaddr /* XXX */ -#include "ns.h" -#include "db.h" -#include "pathnames.h" - -#ifdef BOOTFILE /* default boot file */ -char *bootfile = BOOTFILE; -#else -char *bootfile = _PATH_BOOT; -#endif - -#ifdef DEBUGFILE /* default debug output file */ -char *debugfile = DEBUGFILE; -#else -char *debugfile = _PATH_DEBUG; -#endif - -#ifdef PIDFILE /* file to store current named PID */ -char *PidFile = PIDFILE; -#else -char *PidFile = _PATH_PIDFILE; -#endif - -#ifndef FD_SET -#define NFDBITS 32 -#define FD_SETSIZE 32 -#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS))) -#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS))) -#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS))) -#define FD_ZERO(p) bzero((char *)(p), sizeof(*(p))) -#endif - -FILE *fp; /* file descriptor for pid file */ - -#ifdef DEBUG -FILE *ddt; -#endif - -int debug = 0; /* debugging flag */ -int ds; /* datagram socket */ -int needreload = 0; /* received SIGHUP, need to reload db */ -int needmaint = 0; /* need to call ns_maint()*/ -int needzoneload = 0; /* need to reload secondary zone(s) */ -int needToDoadump = 0; /* need to dump database */ -int needToChkpt = 0; /* need to checkpoint cache */ -int needStatsDump = 0; /* need to dump statistics */ -#ifdef ALLOW_UPDATES -int needToExit = 0; /* need to exit (may need to doadump - * first, if database has changed since - * it was last dumped/booted). Gets - * set by shutdown signal handler - * (onintr) - */ -#endif ALLOW_UPDATES - -int priming = 0; /* is cache being primed */ - -#ifdef SO_RCVBUF -int rbufsize = 8 * 1024; /* UDP recive buffer size */ -#endif - -struct qstream *streamq = QSTREAM_NULL; /* list of open streams */ -struct qdatagram *datagramq = QDATAGRAM_NULL; /* list of datagram interfaces */ -struct sockaddr_in nsaddr; -struct timeval tt; -/* - * We keep a list of favored networks headed by nettab. - * There are three (possibly empty) parts to this list, in this order: - * 1. directly attached (sub)nets. - * 2. logical networks for directly attached subnetted networks. - * 3. networks from the sort list. - * The value (*elocal) points at the first entry in the second part of the list, - * if any, while (*enettab) points at the first entry in the sort list. - */ -struct netinfo *nettab = NULL; -struct netinfo **elocal = &nettab; -struct netinfo **enettab = &nettab; -struct netinfo netloop; -struct netinfo *findnetinfo(); -u_long net_mask(); -u_short ns_port; -struct sockaddr_in from_addr; /* Source addr of last packet */ -int from_len; /* Source addr size of last packet */ -time_t boottime, resettime; /* Used by ns_stats */ -static fd_set mask; /* select mask of open descriptors */ -static int nfds; /* number of fds for select */ -static int vs; /* listening TCP socket */ - -char **Argv = NULL; /* pointer to argument vector */ -char *LastArg = NULL; /* end of argv */ - -extern int errno; - -#if defined(SYSV) -getdtablesize() -{ - return(FD_SETSIZE); -} -#endif SYSV - -main(argc, argv, envp) - int argc; - char *argv[], *envp[]; -{ - register int n, udpcnt; - register char *arg; - register struct qstream *sp; - register struct qdatagram *dqp; - struct qstream *nextsp; - int on = 1; - int rfd, size; - u_long lasttime, maxctime; - char buf[BUFSIZ]; -#ifndef SYSV - struct sigvec vec; -#endif - - fd_set tmpmask; - - struct timeval t, *tp; - struct qstream *candidate = QSTREAM_NULL; - extern SIG_FN onintr(), maint_alarm(), endxfer(); - extern SIG_FN setdumpflg(), onhup(); - extern SIG_FN setIncrDbgFlg(), setNoDbgFlg(), sigprof(); - extern SIG_FN setchkptflg(), setstatsflg(); - extern int loadxfer(); - extern struct qstream *sqadd(); - extern struct qinfo *qhead; - extern char Version[]; - - ns_port = htons(NAMESERVER_PORT); - - /* - ** Save start and extent of argv for setproctitle. - */ - - Argv = argv; - if (envp == 0 || *envp == 0) - envp = argv; - while (*envp) - envp++; - LastArg = envp[-1] + strlen(envp[-1]); - - (void) umask(022); - while (--argc > 0) { - arg = *++argv; - if (*arg == '-') { - while (*++arg) - switch (*arg) { - case 'b': - if (--argc <= 0) - usage(); - bootfile = *++argv; - break; - - case 'd': - ++argv; - - if (*argv != 0) { - if (**argv == '-') { - argv--; - break; - } - debug = atoi(*argv); - --argc; - } - if (debug <= 0) - debug = 1; - setdebug(1); - break; - - case 'p': - if (--argc <= 0) - usage(); - ns_port = htons((u_short)atoi(*++argv)); - break; - - default: - usage(); - } - } else - bootfile = *argv; - } - - if (!debug) - for (n = getdtablesize() - 1; n > 2; n--) - (void) close(n); -#ifdef DEBUG - else { - fprintf(ddt,"Debug turned ON, Level %d\n",debug); - fprintf(ddt,"Version = %s\t",Version); - fprintf(ddt,"bootfile = %s\n",bootfile); - } -#endif - -#ifdef LOG_DAEMON - openlog("named", LOG_PID|LOG_CONS|LOG_NDELAY, LOG_DAEMON); -#else - openlog("named", LOG_PID); -#endif - - /* tuck my process id away */ - fp = fopen(PidFile, "w"); - if (fp != NULL) { - fprintf(fp, "%d\n", getpid()); - (void) fclose(fp); - } - syslog(LOG_NOTICE, "restarted\n"); - - _res.options &= ~(RES_DEFNAMES | RES_DNSRCH | RES_RECURSE); - - nsaddr.sin_family = AF_INET; - nsaddr.sin_addr.s_addr = INADDR_ANY; - nsaddr.sin_port = ns_port; - - /* - ** Open stream port. - */ - if ((vs = socket(AF_INET, SOCK_STREAM, 0)) < 0) { - syslog(LOG_ERR, "socket(SOCK_STREAM): %m"); - exit(1); - } - (void)setsockopt(vs, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)); - if (bind(vs, (struct sockaddr *)&nsaddr, sizeof(nsaddr))) { - syslog(LOG_ERR, "bind(vs, %s[%d]): %m", - inet_ntoa(nsaddr.sin_addr), ntohs(nsaddr.sin_port)); - exit(1); - } - (void) listen(vs, 5); - - /* - * Get list of local addresses and set up datagram sockets. - */ - getnetconf(); - - /* - ** Initialize and load database. - */ - gettime(&tt); - buildservicelist(); - buildprotolist(); - ns_init(bootfile); -#ifdef DEBUG - if (debug) { - fprintf(ddt, "Network and sort list:\n"); - printnetinfo(nettab); - } -#endif DEBUG - - time(&boottime); - resettime = boottime; - - (void) signal(SIGHUP, onhup); -#if defined(SYSV) - (void) signal(SIGCLD, endxfer); - (void) signal(SIGALRM, maint_alarm); -#else - bzero((char *)&vec, sizeof(vec)); - vec.sv_handler = maint_alarm; - vec.sv_mask = sigmask(SIGCHLD); - (void) sigvec(SIGALRM, &vec, (struct sigvec *)NULL); - - vec.sv_handler = endxfer; - vec.sv_mask = sigmask(SIGALRM); - (void) sigvec(SIGCHLD, &vec, (struct sigvec *)NULL); -#endif SYSV - (void) signal(SIGPIPE, SIG_IGN); - (void) signal(SIGSYS, sigprof); - (void) signal(SIGINT, setdumpflg); - (void) signal(SIGQUIT, setchkptflg); - (void) signal(SIGIOT, setstatsflg); - -#ifdef ALLOW_UPDATES - /* Catch SIGTERM so we can dump the database upon shutdown if it - has changed since it was last dumped/booted */ - (void) signal(SIGTERM, onintr); -#endif ALLOW_UPDATES - -#if defined(SIGUSR1) && defined(SIGUSR2) - (void) signal(SIGUSR1, setIncrDbgFlg); - (void) signal(SIGUSR2, setNoDbgFlg); -#else SIGUSR1&&SIGUSR2 - (void) signal(SIGEMT, setIncrDbgFlg); - (void) signal(SIGFPE, setNoDbgFlg); -#endif SIGUSR1&&SIGUSR2 - -#ifdef DEBUG - if (debug) { - fprintf(ddt,"database initialized\n"); - } -#endif - - t.tv_usec = 0; - - /* - * Fork and go into background now that - * we've done any slow initialization - * and are ready to answer queries. - */ - if (!debug) { -#if defined(BSD) && BSD >= 199006 - daemon(1, 0); -#else - if (fork() > 0) - exit(0); - n = open(_PATH_DEVNULL, O_RDONLY); - (void) dup2(n, 0); - (void) dup2(n, 1); - (void) dup2(n, 2); - if (n > 2) - (void) close(n); -#ifdef SYSV - setpgrp(); -#else - { - struct itimerval ival; - - /* - * The open below may hang on pseudo ttys if the person - * who starts named logs out before this point. - * - * needmaint may get set inapropriately if the open - * hangs, but all that will happen is we will see that - * no maintenance is required. - */ - bzero((char *)&ival, sizeof(ival)); - ival.it_value.tv_sec = 120; - (void) setitimer(ITIMER_REAL, &ival, - (struct itimerval *)NULL); - n = open(_PATH_TTY, O_RDWR); - ival.it_value.tv_sec = 0; - (void) setitimer(ITIMER_REAL, &ival, - (struct itimerval *)NULL); - if (n > 0) { - (void) ioctl(n, TIOCNOTTY, (char *)NULL); - (void) close(n); - } - } -#endif /* SYSV */ -#endif /* BSD > 199006 */ - } - /* tuck my process id away again */ - fp = fopen(PidFile, "w"); - if (fp != NULL) { - fprintf(fp, "%d\n", getpid()); - (void) fclose(fp); - } - -#ifdef DEBUG - if (debug) - fprintf(ddt,"Ready to answer queries.\n"); -#endif - prime_cache(); - FD_ZERO(&mask); - FD_SET(vs, &mask); - if (vs >= nfds) - nfds = vs + 1; - for (dqp = datagramq; dqp != QDATAGRAM_NULL; dqp = dqp->dq_next) { - FD_SET(dqp->dq_dfd, &mask); - if (dqp->dq_dfd >= nfds) - nfds = dqp->dq_dfd + 1; - } - for (;;) { -#ifdef DEBUG - if (ddt && debug == 0) { - fprintf(ddt,"Debug turned OFF\n"); - (void) fclose(ddt); - ddt = 0; - } -#endif -#ifdef ALLOW_UPDATES - if (needToExit) { - struct zoneinfo *zp; - sigblock(~0); /* - * Block all blockable signals - * to ensure a consistant - * state during final dump - */ -#ifdef DEBUG - if (debug) - fprintf(ddt, "Received shutdown signal\n"); -#endif DEBUG - for (zp = zones; zp < &zones[nzones]; zp++) { - if (zp->hasChanged) - zonedump(zp); - } - exit(0); - } -#endif ALLOW_UPDATES - if (needreload) { - needreload = 0; - db_reload(); - } -#ifdef STATS - if (needStatsDump) { - needStatsDump = 0; - ns_stats(); - } -#endif STATS - if (needzoneload) { - needzoneload = 0; - loadxfer(); - } - if (needmaint) { - needmaint = 0; - ns_maint(); - } - if(needToChkpt) { - needToChkpt = 0; - doachkpt(); - } - if(needToDoadump) { - needToDoadump = 0; - doadump(); - } - /* - ** Wait until a query arrives - */ - if (retryqp != NULL) { - gettime(&tt); - t.tv_sec = (long) retryqp->q_time - tt.tv_sec; - if (t.tv_sec <= 0) { - retry(retryqp); - continue; - } - tp = &t; - } else - tp = NULL; - tmpmask = mask; - n = select(nfds, &tmpmask, (fd_set *)NULL, (fd_set *)NULL, tp); - if (n < 0) { - if (errno == EINTR) - continue; - syslog(LOG_ERR, "select: %m"); -#ifdef DEBUG - if (debug) - fprintf(ddt,"select error\n"); -#endif - ; - } - if (n == 0) - continue; - - for (dqp = datagramq; dqp != QDATAGRAM_NULL; - dqp = dqp->dq_next) { - if (FD_ISSET(dqp->dq_dfd, &tmpmask)) - for(udpcnt = 0; udpcnt < 25; udpcnt++) { - from_len = sizeof(from_addr); - if ((n = recvfrom(dqp->dq_dfd, buf, sizeof(buf), 0, - (struct sockaddr *)&from_addr, &from_len)) < 0) - { - if ((n == -1) && (errno == EWOULDBLOCK)) - break; - syslog(LOG_WARNING, "recvfrom: %m"); - break; - } -#ifdef STATS - stats[S_INPKTS].cnt++; -#endif -#ifdef DEBUG - if (debug) - fprintf(ddt, - "\ndatagram from %s port %d, fd %d, len %d\n", - inet_ntoa(from_addr.sin_addr), - ntohs(from_addr.sin_port), dqp->dq_dfd, n); - if (debug >= 10) - fp_query(buf, ddt); -#endif - /* - * Consult database to get the answer. - */ - gettime(&tt); - ns_req(buf, n, PACKETSZ, QSTREAM_NULL, &from_addr, - dqp->dq_dfd); - } - } - /* - ** Process stream connection - */ - if (FD_ISSET(vs, &tmpmask)) { - from_len = sizeof(from_addr); - rfd = accept(vs, (struct sockaddr *)&from_addr, &from_len); - gettime(&tt); - if (rfd < 0 && errno == EMFILE && streamq != NULL) { - maxctime = 0; - candidate = QSTREAM_NULL; - for (sp = streamq; sp != QSTREAM_NULL; - sp = nextsp) { - nextsp = sp->s_next; - if (sp->s_refcnt != 0) - continue; - lasttime = tt.tv_sec - sp->s_time; - if (lasttime >= 900) - sqrm(sp); - else if (lasttime > maxctime) { - candidate = sp; - maxctime = lasttime; - } - } - rfd = accept(vs, (struct sockaddr *)&from_addr, &from_len); - if ((rfd < 0) && (errno == EMFILE) && - candidate != QSTREAM_NULL) { - sqrm(candidate); - rfd = accept(vs, (struct sockaddr *)&from_addr, &from_len); - } - } - if (rfd < 0) { - syslog(LOG_WARNING, "accept: %m"); - continue; - } - (void) fcntl(rfd, F_SETFL, O_NONBLOCK); - (void) setsockopt(rfd, SOL_SOCKET, SO_KEEPALIVE, - (char *)&on, sizeof(on)); - if ((sp = sqadd()) == QSTREAM_NULL) { - (void) close(rfd); - continue; - } - sp->s_rfd = rfd; /* stream file descriptor */ - sp->s_size = -1; /* amount of data to receive */ - gettime(&tt); - sp->s_time = tt.tv_sec; /* last transaction time */ - sp->s_from = from_addr; /* address to respond to */ - sp->s_bufp = (char *)&sp->s_tempsize; - FD_SET(rfd, &mask); - FD_SET(rfd, &tmpmask); - if (rfd >= nfds) - nfds = rfd + 1; -#ifdef DEBUG - if (debug) { - fprintf(ddt, - "\nTCP connection from %s port %d (fd %d)\n", - inet_ntoa(sp->s_from.sin_addr), - ntohs(sp->s_from.sin_port), rfd); - } -#endif - } -#ifdef DEBUG - if (debug > 2 && streamq) - fprintf(ddt,"streamq = x%x\n",streamq); -#endif - if (streamq != NULL) { - for (sp = streamq; sp != QSTREAM_NULL; sp = nextsp) { - nextsp = sp->s_next; - if (FD_ISSET(sp->s_rfd, &tmpmask)) { -#ifdef DEBUG - if (debug > 5) { - fprintf(ddt, - "sp x%x rfd %d size %d time %d ", - sp, sp->s_rfd, sp->s_size, - sp->s_time ); - fprintf(ddt," next x%x \n", sp->s_next ); - fprintf(ddt,"\tbufsize %d",sp->s_bufsize); - fprintf(ddt," buf x%x ",sp->s_buf); - fprintf(ddt," bufp x%x\n",sp->s_bufp); - } -#endif DEBUG - if (sp->s_size < 0) { - size = sizeof(u_short) - - (sp->s_bufp - (char *)&sp->s_tempsize); - while (size > 0 && - (n = read(sp->s_rfd, sp->s_bufp, size)) > 0){ - sp->s_bufp += n; - size -= n; - } - if ((n == -1) && (errno == EWOULDBLOCK)) - continue; - if (n <= 0) { - sqrm(sp); - continue; - } - if ((sp->s_bufp - (char *)&sp->s_tempsize) == - sizeof(u_short)) { - sp->s_size = htons(sp->s_tempsize); - if (sp->s_bufsize == 0) { - if ( (sp->s_buf = malloc(BUFSIZ)) - == NULL) { - sp->s_buf = buf; - sp->s_size = sizeof(buf); - } else { - sp->s_bufsize = BUFSIZ; - } - } - if (sp->s_size > sp->s_bufsize && - sp->s_bufsize != 0) { - if ((sp->s_buf = realloc( - (char *)sp->s_buf, - (unsigned)sp->s_size)) == NULL){ - sp->s_buf = buf; - sp->s_bufsize = 0; - sp->s_size = sizeof(buf); - } else { - sp->s_bufsize = sp->s_size; - } - } - sp->s_bufp = sp->s_buf; - } - } - gettime(&tt); - sp->s_time = tt.tv_sec; - while (sp->s_size > 0 && - (n = read(sp->s_rfd, sp->s_bufp, sp->s_size)) > 0) - { - sp->s_bufp += n; - sp->s_size -= n; - } - /* - * we don't have enough memory for the query. - * if we have a query id, then we will send an - * error back to the user. - */ - if (sp->s_bufsize == 0 && - (sp->s_bufp - sp->s_buf > sizeof(u_short))) { - HEADER *hp; - - hp = (HEADER *)sp->s_buf; - hp->qr = 1; - hp->ra = 1; - hp->ancount = 0; - hp->qdcount = 0; - hp->nscount = 0; - hp->arcount = 0; - hp->rcode = SERVFAIL; - (void) writemsg(sp->s_rfd, sp->s_buf, - sizeof(HEADER)); - continue; - } - if ((n == -1) && (errno == EWOULDBLOCK)) - continue; - if (n <= 0) { - sqrm(sp); - continue; - } - /* - * Consult database to get the answer. - */ - if (sp->s_size == 0) { - sq_query(sp); - ns_req(sp->s_buf, - sp->s_bufp - sp->s_buf, - sp->s_bufsize, sp, - &sp->s_from, -1); - sp->s_bufp = (char *)&sp->s_tempsize; - sp->s_size = -1; - continue; - } - } - } - } - } - /* NOTREACHED */ -} - -usage() -{ - fprintf(stderr, "Usage: named [-d #] [-p port] [{-b} bootfile]\n"); - exit(1); -} - -getnetconf() -{ - register struct netinfo *ntp; - struct netinfo *ontp; - struct ifconf ifc; - struct ifreq ifreq, *ifr; - struct qdatagram *dqp; - static int first = 1; - char buf[BUFSIZ], *cp, *cplim; - u_long nm; - - ifc.ifc_len = sizeof(buf); - ifc.ifc_buf = buf; - if (ioctl(vs, SIOCGIFCONF, (char *)&ifc) < 0) { - syslog(LOG_ERR, "get interface configuration: %m"); - exit(1); - } - ntp = NULL; -#ifdef AF_LINK -#define max(a, b) (a > b ? a : b) -#define size(p) max((p).sa_len, sizeof(p)) -#else -#define size(p) (sizeof (p)) -#endif - cplim = buf + ifc.ifc_len; /*skip over if's with big ifr_addr's */ - for (cp = buf; cp < cplim; - cp += sizeof (ifr->ifr_name) + size(ifr->ifr_addr)) { -#undef size - ifr = (struct ifreq *)cp; - if (ifr->ifr_addr.sa_family != AF_INET || - ((struct sockaddr_in *)&ifr->ifr_addr)->sin_addr.s_addr == 0) - continue; - ifreq = *ifr; - /* - * Don't test IFF_UP, packets may still be received at this - * address if any other interface is up. - */ - if (ioctl(vs, SIOCGIFADDR, (char *)&ifreq) < 0) { - syslog(LOG_ERR, "get interface addr: %m"); - continue; - } - /* build datagram queue */ - /* - * look for an already existing source interface address. - * This happens mostly when reinitializing. Also, if - * the machine has multiple point to point interfaces, then - * the local address may appear more than once. - */ - for (dqp=datagramq; dqp != NULL; dqp = dqp->dq_next) - if (((struct sockaddr_in *)&ifreq.ifr_addr)->sin_addr.s_addr - == dqp->dq_addr.s_addr) { -#ifdef DEBUG - if (debug) - fprintf(ddt, "dup interface address %s on %s\n", - inet_ntoa(dqp->dq_addr), ifreq.ifr_name); -#endif - break; - } - if (dqp != NULL) - continue; - - if ((dqp = (struct qdatagram *)calloc(1, - sizeof(struct qdatagram))) == NULL) { -#ifdef DEBUG - if (debug >= 5) - fprintf(ddt,"getnetconf: malloc error\n"); -#endif - syslog(LOG_ERR, "getnetconf: Out Of Memory"); - exit(12); - } - dqp->dq_next = datagramq; - datagramq = dqp; - dqp->dq_addr = ((struct sockaddr_in *)&ifreq.ifr_addr)->sin_addr; - opensocket(dqp); - - /* - * Add interface to list of directly-attached (sub)nets - * for use in sorting addresses. - */ - if (ntp == NULL) - ntp = (struct netinfo *)malloc(sizeof(struct netinfo)); - ntp->my_addr = - ((struct sockaddr_in *)&ifreq.ifr_addr)->sin_addr; -#ifdef SIOCGIFNETMASK - if (ioctl(vs, SIOCGIFNETMASK, (char *)&ifreq) < 0) { - syslog(LOG_ERR, "get netmask: %m"); - ntp->mask = net_mask(ntp->my_addr); - } else - ntp->mask = ((struct sockaddr_in *) - &ifreq.ifr_addr)->sin_addr.s_addr; -#else - /* 4.2 does not support subnets */ - ntp->mask = net_mask(ntp->my_addr); -#endif - if (ioctl(vs, SIOCGIFFLAGS, (char *)&ifreq) < 0) { - syslog(LOG_ERR, "get interface flags: %m"); - continue; - } -#ifdef IFF_LOOPBACK - if (ifreq.ifr_flags & IFF_LOOPBACK) -#else - /* test against 127.0.0.1 (yuck!!) */ - if (ntp->my_addr.s_addr == htonl(0x7F000001)) -#endif - { - if (netloop.my_addr.s_addr == 0) { - netloop.my_addr = ntp->my_addr; - netloop.mask = 0xffffffff; - netloop.net = ntp->my_addr.s_addr; -#ifdef DEBUG - if (debug) - fprintf(ddt,"loopback address: x%lx\n", - netloop.my_addr.s_addr); -#endif DEBUG - } - continue; - } else if ((ifreq.ifr_flags & IFF_POINTOPOINT)) { - if (ioctl(vs, SIOCGIFDSTADDR, (char *)&ifreq) < 0) { - syslog(LOG_ERR, "get dst addr: %m"); - continue; - } - ntp->mask = 0xffffffff; - ntp->net = ((struct sockaddr_in *) - &ifreq.ifr_addr)->sin_addr.s_addr; - } else { - ntp->net = ntp->mask & ntp->my_addr.s_addr; - } - /* - * Place on end of list of locally-attached (sub)nets, - * but before logical nets for subnetted nets. - */ - ntp->next = *elocal; - *elocal = ntp; - if (elocal == enettab) - enettab = &ntp->next; - elocal = &ntp->next; - ntp = NULL; - } - if (ntp) - (void) free((char *)ntp); - - /* - * Create separate qdatagram structure for socket - * wildcard address. - */ - if (first) { - if ((dqp = (struct qdatagram *)calloc(1, sizeof(*dqp))) == NULL) { -#ifdef DEBUG - if (debug >= 5) - fprintf(ddt,"getnetconf: malloc error\n"); -#endif - syslog(LOG_ERR, "getnetconf: Out Of Memory"); - exit(12); - } - dqp->dq_next = datagramq; - datagramq = dqp; - dqp->dq_addr.s_addr = INADDR_ANY; - opensocket(dqp); - ds = dqp->dq_dfd; /* used externally */ - } - - /* - * Compute logical networks to which we're connected - * based on attached subnets; - * used for sorting based on network configuration. - */ - for (ntp = nettab; ntp != NULL; ntp = ntp->next) { - nm = net_mask(ntp->my_addr); - if (nm != ntp->mask) { - if (findnetinfo(ntp->my_addr)) - continue; - ontp = (struct netinfo *)malloc(sizeof(struct netinfo)); - if (ontp == NULL) { -#ifdef DEBUG - if (debug >= 5) - fprintf(ddt,"getnetconf: malloc error\n"); -#endif - syslog(LOG_ERR, "getnetconf: Out Of Memory"); - exit(12); - } - ontp->my_addr = ntp->my_addr; - ontp->mask = nm; - ontp->net = ontp->my_addr.s_addr & nm; - ontp->next = *enettab; - *enettab = ontp; - enettab = &ontp->next; - } - } - first = 0; -} - -/* - * Find netinfo structure for logical network implied by address "addr", - * if it's on list of local/favored networks. - */ -struct netinfo * -findnetinfo(addr) - struct in_addr addr; -{ - register struct netinfo *ntp; - u_long net, mask; - - mask = net_mask(addr); - net = addr.s_addr & mask; - for (ntp = nettab; ntp != NULL; ntp = ntp->next) - if (ntp->net == net && ntp->mask == mask) - return (ntp); - return ((struct netinfo *) NULL); -} - -#ifdef DEBUG -printnetinfo(ntp) - register struct netinfo *ntp; -{ - for ( ; ntp != NULL; ntp = ntp->next) { - fprintf(ddt,"net x%lx mask x%lx", ntp->net, ntp->mask); - fprintf(ddt," my_addr x%lx", ntp->my_addr.s_addr); - fprintf(ddt," %s\n", inet_ntoa(ntp->my_addr)); - } -} -#endif - -opensocket(dqp) - register struct qdatagram *dqp; -{ - int on = 1; - - /* - * Open datagram sockets bound to interface address. - */ - if ((dqp->dq_dfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { - syslog(LOG_ERR, "socket(SOCK_DGRAM): %m"); - exit(1); - } -#ifdef DEBUG - if (debug) - fprintf(ddt,"dqp->dq_addr %s d_dfd %d\n", - inet_ntoa(dqp->dq_addr), dqp->dq_dfd); -#endif DEBUG - (void)setsockopt(dqp->dq_dfd, SOL_SOCKET, SO_REUSEADDR, - (char *)&on, sizeof(on)); -#ifdef SO_RCVBUF - (void)setsockopt(dqp->dq_dfd, SOL_SOCKET, SO_RCVBUF, - (char *)&rbufsize, sizeof(rbufsize)); -#endif SO_RCVBUF - (void) fcntl(dqp->dq_dfd, F_SETFL, O_NONBLOCK); - /* - * NOTE: Some versions of SunOS have problems with the following - * call to bind. Bind still seems to function on these systems - * if you comment out the exit inside the if. This may cause - * Suns with multiple interfaces to reply strangely. - */ - nsaddr.sin_addr = dqp->dq_addr; - if (bind(dqp->dq_dfd, (struct sockaddr *)&nsaddr, sizeof(nsaddr))) { - syslog(LOG_ERR, "bind(dfd %d, %s[%d]): %m", - dqp->dq_dfd, inet_ntoa(nsaddr.sin_addr), - ntohs(nsaddr.sin_port)); -#if !defined(sun) - exit(1); -#endif - } -} - -/* -** Set flag saying to reload database upon receiving SIGHUP. -** Must make sure that someone isn't walking through a data -** structure at the time. -*/ - -SIG_FN -onhup() -{ -#if defined(SYSV) - (void)signal(SIGHUP, onhup); -#endif SYSV - needreload = 1; -} - -/* -** Set flag saying to call ns_maint() -** Must make sure that someone isn't walking through a data -** structure at the time. -*/ - -SIG_FN -maint_alarm() -{ -#if defined(SYSV) - (void)signal(SIGALRM, maint_alarm); -#endif SYSV - needmaint = 1; - } - - -#ifdef ALLOW_UPDATES -/* - * Signal handler to schedule shutdown. Just set flag, to ensure a consistent - * state during dump. - */ -SIG_FN -onintr() -{ - needToExit = 1; -} -#endif ALLOW_UPDATES - -/* - * Signal handler to schedule a data base dump. Do this instead of dumping the - * data base immediately, to avoid seeing it in a possibly inconsistent state - * (due to updates), and to avoid long disk I/O delays at signal-handler - * level - */ -SIG_FN -setdumpflg() -{ -#if defined(SYSV) - (void)signal(SIGINT, setdumpflg); -#endif SYSV - needToDoadump = 1; -} - -/* -** Turn on or off debuging by open or closeing the debug file -*/ - -setdebug(code) -int code; -{ -#if defined(lint) && !defined(DEBUG) - code = code; -#endif -#ifdef DEBUG - - if (code) { - ddt = freopen(debugfile, "w+", stderr); - if ( ddt == NULL) { - syslog(LOG_WARNING, "can't open debug file %s: %m", - debugfile); - debug = 0; - } else { -#if defined(SYSV) - setvbuf(ddt, NULL, _IOLBF, BUFSIZ); -#else - setlinebuf(ddt); -#endif - (void) fcntl(fileno(ddt), F_SETFL, FAPPEND); - } - } else - debug = 0; - /* delay closing ddt, we might interrupt someone */ -#endif -} - -/* -** Catch a special signal and set debug level. -** -** If debuging is off then turn on debuging else increment the level. -** -** Handy for looking in on long running name servers. -*/ - -SIG_FN -setIncrDbgFlg() -{ -#if defined(SYSV) - (void)signal(SIGUSR1, setIncrDbgFlg); -#endif SYSV -#ifdef DEBUG - if (debug == 0) { - debug++; - setdebug(1); - } - else { - debug++; - } - fprintf(ddt,"Debug turned ON, Level %d\n",debug); -#endif -} - -/* -** Catch a special signal to turn off debugging -*/ - -SIG_FN -setNoDbgFlg() -{ -#if defined(SYSV) - (void)signal(SIGUSR2, setNoDbgFlg); -#endif SYSV - setdebug(0); -} - -/* -** Set flag for statistics dump -*/ -SIG_FN -setstatsflg() -{ -#if defined(SYSV) - (void)signal(SIGIOT, setstatsflg); -#endif SYSV - needStatsDump = 1; -} - -SIG_FN -setchkptflg() -{ -#if defined(SYSV) - (void)signal(SIGQUIT, setchkptflg); -#endif SYSV - needToChkpt = 1; -} - -/* -** Catch a special signal SIGSYS -** -** this is setup to fork and exit to drop to /usr/tmp/gmon.out -** and keep the server running -*/ - -SIG_FN -sigprof() -{ -#if defined(SYSV) - (void)signal(SIGSYS, sigprof); -#endif SYSV -#ifdef DEBUG - if (debug) - fprintf(ddt,"sigprof()\n"); -#endif - if ( fork() == 0) - { - (void) chdir(_PATH_TMPDIR); - exit(1); - } -} - -/* -** Routines for managing stream queue -*/ - -struct qstream * -sqadd() -{ - register struct qstream *sqp; - - if ((sqp = (struct qstream *)calloc(1, sizeof(struct qstream))) - == NULL ) { -#ifdef DEBUG - if (debug >= 5) - fprintf(ddt,"sqadd: malloc error\n"); -#endif - syslog(LOG_ERR, "sqadd: Out Of Memory"); - return(QSTREAM_NULL); - } -#ifdef DEBUG - if (debug > 3) - fprintf(ddt,"sqadd(x%x)\n", sqp); -#endif - - sqp->s_next = streamq; - streamq = sqp; - return(sqp); -} - -/* - * Remove stream queue structure. - * No current queries may refer to this stream when it is removed. - */ -sqrm(qp) - register struct qstream *qp; -{ - register struct qstream *qsp; - -#ifdef DEBUG - if (debug > 1) { - fprintf(ddt,"sqrm(%#x, %d ) rfcnt=%d\n", - qp, qp->s_rfd, qp->s_refcnt); - } -#endif - - if (qp->s_bufsize != 0) - (void) free(qp->s_buf); - FD_CLR(qp->s_rfd, &mask); - (void) close(qp->s_rfd); - if (qp == streamq) { - streamq = qp->s_next; - } else { - for (qsp = streamq; qsp->s_next != qp; qsp = qsp->s_next) - ; - qsp->s_next = qp->s_next; - } - (void)free((char *)qp); -} - -sqflush() -{ - register struct qstream *sp, *spnext; - - for (sp = streamq; sp != QSTREAM_NULL; sp = spnext) { - spnext = sp->s_next; - sqrm(sp); - } -} - -/* - * Initiate query on stream; - * mark as referenced and stop selecting for input. - */ -sq_query(sp) - register struct qstream *sp; -{ - sp->s_refcnt++; - FD_CLR(sp->s_rfd, &mask); -} - -/* - * Note that the current request on a stream has completed, - * and that we should continue looking for requests on the stream. - */ -sq_done(sp) - register struct qstream *sp; -{ - - sp->s_refcnt = 0; - sp->s_time = tt.tv_sec; - FD_SET(sp->s_rfd, &mask); -} - -setproctitle(a, s) - char *a; - int s; -{ - int size; - register char *cp; - struct sockaddr_in sin; - char buf[80]; - - cp = Argv[0]; - size = sizeof(sin); - if (getpeername(s, (struct sockaddr *)&sin, &size) == 0) - (void) sprintf(buf, "-%s [%s]", a, inet_ntoa(sin.sin_addr)); - else { - syslog(LOG_DEBUG, "getpeername: %m"); - (void) sprintf(buf, "-%s", a); - } - (void) strncpy(cp, buf, LastArg - cp); - cp += strlen(cp); - while (cp < LastArg) - *cp++ = ' '; -} - -u_long -net_mask(in) -struct in_addr in; -{ - register u_long i = ntohl(in.s_addr); - - if (IN_CLASSA(i)) - return (htonl(IN_CLASSA_NET)); - else if (IN_CLASSB(i)) - return (htonl(IN_CLASSB_NET)); - else - return (htonl(IN_CLASSC_NET)); -} - -gettime(ttp) -struct timeval *ttp; -{ - if (gettimeofday(ttp, (struct timezone *)0) < 0) - syslog(LOG_ERR, "gettimeofday failed: %m"); - return; -} diff --git a/usr.sbin/named/ns_maint.c b/usr.sbin/named/ns_maint.c deleted file mode 100644 index 716be8d1198..00000000000 --- a/usr.sbin/named/ns_maint.c +++ /dev/null @@ -1,544 +0,0 @@ -/* - * Copyright (c) 1986, 1988 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -/*static char sccsid[] = "from: @(#)ns_maint.c 4.39 (Berkeley) 3/2/91";*/ -static char rcsid[] = "$Id: ns_maint.c,v 1.1 1995/10/18 08:47:50 deraadt Exp $"; -#endif /* not lint */ - -#include <sys/param.h> -#include <sys/socket.h> -#include <sys/time.h> -#if defined(SYSV) -#include <unistd.h> -#endif SYSV -#include <netinet/in.h> -#include <stdio.h> -#include <syslog.h> -#include <signal.h> -#include <errno.h> -#include <arpa/nameser.h> -#include <sys/wait.h> -#include "ns.h" -#include "db.h" -#include "pathnames.h" - -extern int errno; -extern int maint_interval; -extern int needzoneload; -extern u_short ns_port; -extern char *ctime(); - -int xfers_running; /* number of xfers running */ -int xfers_deferred; /* number of needed xfers not run yet */ -static int alarm_pending; - - -/* - * Invoked at regular intervals by signal interrupt; refresh all secondary - * zones from primary name server and remove old cache entries. Also, - * ifdef'd ALLOW_UPDATES, dump database if it has changed since last - * dump/bootup. - */ -ns_maint() -{ - register struct zoneinfo *zp; - struct itimerval ival; - time_t next_refresh = 0; - int zonenum; - - gettime(&tt); - -#ifdef DEBUG - if (debug) { - time_t now; - - now = tt.tv_sec; - fprintf(ddt,"\nns_maint(); now %s", ctime(&now)); - } -#endif - - xfers_deferred = 0; - alarm_pending = 0; - for (zp = zones, zonenum = 0; zp < &zones[nzones]; zp++, zonenum++) { -#ifdef DEBUG - if (debug >= 2) - printzoneinfo(zonenum); -#endif - if (tt.tv_sec >= zp->z_time && zp->z_refresh > 0) { - /* - * Set default time for next action first, - * so that it can be changed later if necessary. - */ - zp->z_time = tt.tv_sec + zp->z_refresh; - - switch (zp->z_type) { - - case Z_CACHE: - doachkpt(); - break; - - case Z_SECONDARY: - if ((zp->z_state & Z_NEED_RELOAD) == 0) { - if (zp->z_state & Z_XFER_RUNNING) - abortxfer(zp); - else if (xfers_running < MAX_XFERS_RUNNING) - startxfer(zp); - else { - zp->z_state |= Z_NEED_XFER; - ++xfers_deferred; -#ifdef DEBUG - if (debug > 1) - fprintf(ddt, - "xfer deferred for %s\n", - zp->z_origin); -#endif - } - } - break; -#ifdef ALLOW_UPDATES - case Z_PRIMARY: - /* - * Checkpoint the zone if it has changed - * since we last checkpointed - */ - if (zp->hasChanged) - zonedump(zp); - break; -#endif ALLOW_UPDATES - } - gettime(&tt); - } - } - sched_maint(); -#ifdef DEBUG - if (debug) - fprintf(ddt,"exit ns_maint()\n"); -#endif -} - -/* - * Find when the next refresh needs to be and set - * interrupt time accordingly. - */ -sched_maint() -{ - register struct zoneinfo *zp; - struct itimerval ival; - time_t next_refresh = 0; - static time_t next_alarm; - - for (zp = zones; zp < &zones[nzones]; zp++) - if (zp->z_time != 0 && - (next_refresh == 0 || next_refresh > zp->z_time)) - next_refresh = zp->z_time; - /* - * Schedule the next call to ns_maint. - * Don't visit any sooner than maint_interval. - */ - bzero((char *)&ival, sizeof (ival)); - if (next_refresh != 0) { - if (next_refresh == next_alarm && alarm_pending) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"sched_maint: no schedule change\n"); -#endif - return; - } - ival.it_value.tv_sec = next_refresh - tt.tv_sec; - if (ival.it_value.tv_sec < maint_interval) - ival.it_value.tv_sec = maint_interval; - next_alarm = next_refresh; - alarm_pending = 1; - } - (void) setitimer(ITIMER_REAL, &ival, (struct itimerval *)NULL); -#ifdef DEBUG - if (debug) - fprintf(ddt,"sched_maint: Next interrupt in %d sec\n", - ival.it_value.tv_sec); -#endif -} - -/* - * Start an asynchronous zone transfer for a zone. - * Depends on current time being in tt. - * The caller must call sched_maint after startxfer. - */ -startxfer(zp) - struct zoneinfo *zp; -{ - static char *argv[NSMAX + 20], argv_ns[NSMAX][MAXDNAME]; - int cnt, argc = 0, argc_ns = 0, pid, omask; - char debug_str[10]; - char serial_str[10]; - char port_str[10]; - -#ifdef DEBUG - if (debug) - fprintf(ddt,"startxfer() %s\n", zp->z_origin); -#endif - - argv[argc++] = "named-xfer"; - argv[argc++] = "-z"; - argv[argc++] = zp->z_origin; - argv[argc++] = "-f"; - argv[argc++] = zp->z_source; - argv[argc++] = "-s"; - sprintf(serial_str, "%d", zp->z_serial); - argv[argc++] = serial_str; - if (zp->z_state & Z_SYSLOGGED) - argv[argc++] = "-q"; - argv[argc++] = "-P"; - sprintf(port_str, "%d", ns_port); - argv[argc++] = port_str; -#ifdef DEBUG - if (debug) { - argv[argc++] = "-d"; - sprintf(debug_str, "%d", debug); - argv[argc++] = debug_str; - argv[argc++] = "-l"; - argv[argc++] = "/usr/tmp/xfer.ddt"; - if (debug > 5) { - argv[argc++] = "-t"; - argv[argc++] = "/usr/tmp/xfer.trace"; - } - } -#endif - - /* - * Copy the server ip addresses into argv, after converting - * to ascii and saving the static inet_ntoa result - */ - for (cnt = 0; cnt < zp->z_addrcnt; cnt++) - argv[argc++] = strcpy(argv_ns[argc_ns++], - inet_ntoa(zp->z_addr[cnt])); - - argv[argc] = 0; - -#ifdef DEBUG -#ifdef ECHOARGS - if (debug) { - int i; - for (i = 0; i < argc; i++) - fprintf(ddt, "Arg %d=%s\n", i, argv[i]); - } -#endif /* ECHOARGS */ -#endif /* DEBUG */ - -#ifdef SYSV -#define vfork fork -#else - gettime(&tt); - omask = sigblock(sigmask(SIGCHLD)); -#endif - if ((pid = vfork()) == -1) { -#ifdef DEBUG - if (debug) - fprintf(ddt, "xfer [v]fork: %d\n", errno); -#endif - syslog(LOG_ERR, "xfer [v]fork: %m"); -#ifndef SYSV - (void) sigsetmask(omask); -#endif - zp->z_time = tt.tv_sec + 10; - return; - } - - if (pid) { -#ifdef DEBUG - if (debug) - fprintf(ddt, "started xfer child %d\n", pid); -#endif - zp->z_state &= ~Z_NEED_XFER; - zp->z_state |= Z_XFER_RUNNING; - zp->z_xferpid = pid; - xfers_running++; - zp->z_time = tt.tv_sec + MAX_XFER_TIME; -#ifndef SYSV - (void) sigsetmask(omask); -#endif - } else { - execve(_PATH_XFER, argv, NULL); - syslog(LOG_ERR, "can't exec %s: %m", _PATH_XFER); - _exit(XFER_FAIL); /* avoid duplicate buffer flushes */ - } -} - -#ifdef DEBUG -printzoneinfo(zonenum) -int zonenum; -{ - struct timeval tt; - struct zoneinfo *zp = &zones[zonenum]; - char *ZoneType; - - if (!debug) - return; /* Else fprintf to ddt will bomb */ - fprintf(ddt, "printzoneinfo(%d):\n", zonenum); - - gettime(&tt); - switch (zp->z_type) { - case Z_PRIMARY: ZoneType = "Primary"; break; - case Z_SECONDARY: ZoneType = "Secondary"; break; - case Z_CACHE: ZoneType = "Cache"; break; - default: ZoneType = "Unknown"; - } - if (zp->z_origin[0] == '\0') - fprintf(ddt,"origin ='.'"); - else - fprintf(ddt,"origin ='%s'", zp->z_origin); - fprintf(ddt,", type = %s", ZoneType); - fprintf(ddt,", source = %s\n", zp->z_source); - fprintf(ddt,"z_refresh = %ld", zp->z_refresh); - fprintf(ddt,", retry = %ld", zp->z_retry); - fprintf(ddt,", expire = %ld", zp->z_expire); - fprintf(ddt,", minimum = %ld", zp->z_minimum); - fprintf(ddt,", serial = %ld\n", zp->z_serial); - fprintf(ddt,"z_time = %d", zp->z_time); - if (zp->z_time) { - fprintf(ddt,", now time : %d sec", tt.tv_sec); - fprintf(ddt,", time left: %d sec", zp->z_time - tt.tv_sec); - } - fprintf(ddt,"; state %x\n", zp->z_state); -} -#endif DEBUG - -/* - * remove_zone (htp, zone) -- - * Delete all RR's in the zone "zone" under specified hash table. - */ -remove_zone(htp, zone) - register struct hashbuf *htp; - register int zone; -{ - register struct databuf *dp, *pdp; - register struct namebuf *np; - struct namebuf **npp, **nppend; - - nppend = htp->h_tab + htp->h_size; - for (npp = htp->h_tab; npp < nppend; npp++) - for (np = *npp; np != NULL; np = np->n_next) { - for (pdp = NULL, dp = np->n_data; dp != NULL; ) { - if (dp->d_zone == zone) - dp = rm_datum(dp, np, pdp); - else { - pdp = dp; - dp = dp->d_next; - } - } - /* Call recursively to remove subdomains. */ - if (np->n_hash) - remove_zone(np->n_hash, zone); - } -} - -/* - * Abort an xfer that has taken too long. - */ -abortxfer(zp) - register struct zoneinfo *zp; -{ - - kill(zp->z_xferpid, SIGKILL); /* don't trust it at all */ -#ifdef DEBUG - if (debug) - fprintf(ddt, "Killed child %d (zone %s) due to timeout\n", - zp->z_xferpid, zp->z_origin); -#endif /* DEBUG */ - zp->z_time = tt.tv_sec + zp->z_retry; -} - -#ifdef SYSV -union wait { - unsigned short w_termsig:7; /* termination signal */ - unsigned short w_coredump:1; /* core dump indicator */ - unsigned short w_retcode:8; /* exit code if w_termsig==0 */ -}; -#endif - -/* - * SIGCHLD signal handler: process exit of xfer's. - * (Note: also called when outgoing transfer completes.) - */ -SIG_FN -endxfer() -{ - register struct zoneinfo *zp; - int pid, xfers = 0; - union wait status; - - gettime(&tt); -#if defined(SYSV) - { int stat; - pid = wait(&stat); - status.w_termsig = stat & 0x7f; - status.w_retcode = stat >> 8; - } -#else /* SYSV */ - while ((pid = - wait3((int *)&status, WNOHANG, (struct rusage *)NULL)) > 0) { -#endif /* SYSV */ - for (zp = zones; zp < &zones[nzones]; zp++) - if (zp->z_xferpid == pid) { - xfers++; - xfers_running--; - zp->z_xferpid = 0; - zp->z_state &= ~Z_XFER_RUNNING; -#ifdef DEBUG - if (debug) - fprintf(ddt, - "\nendxfer: child %d zone %s returned status=%d termsig=%d\n", - pid, zp->z_origin, status.w_retcode, - status.w_termsig); -#endif - if (status.w_termsig != 0) { - if (status.w_termsig != SIGKILL) { - syslog(LOG_ERR, - "named-xfer exited with signal %d\n", - status.w_termsig); -#ifdef DEBUG - if (debug) - fprintf(ddt, - "\tchild termination with signal %d\n", - status.w_termsig); -#endif - } - zp->z_time = tt.tv_sec + zp->z_retry; - } else switch (status.w_retcode) { - case XFER_UPTODATE: - zp->z_state &= ~Z_SYSLOGGED; - zp->z_lastupdate = tt.tv_sec; - zp->z_time = tt.tv_sec + zp->z_refresh; - /* - * Restore z_auth in case expired, - * but only if there were no errors - * in the zone file. - */ - if ((zp->z_state & Z_DB_BAD) == 0) - zp->z_auth = 1; - if (zp->z_source) { -#if defined(SYSV) - struct utimbuf t; - - t.actime = tt.tv_sec; - t.modtime = tt.tv_sec; - (void) utime(zp->z_source, &t); -#else - struct timeval t[2]; - - t[0] = tt; - t[1] = tt; - (void) utimes(zp->z_source, t); -#endif /* SYSV */ - } - break; - - case XFER_SUCCESS: - zp->z_state |= Z_NEED_RELOAD; - zp->z_state &= ~Z_SYSLOGGED; - needzoneload++; - break; - - case XFER_TIMEOUT: -#ifdef DEBUG - if (debug) fprintf(ddt, - "zoneref: Masters for secondary zone %s unreachable\n", - zp->z_origin); -#endif - if ((zp->z_state & Z_SYSLOGGED) == 0) { - zp->z_state |= Z_SYSLOGGED; - syslog(LOG_WARNING, - "zoneref: Masters for secondary zone %s unreachable", - zp->z_origin); - } - zp->z_time = tt.tv_sec + zp->z_retry; - break; - - default: - if ((zp->z_state & Z_SYSLOGGED) == 0) { - zp->z_state |= Z_SYSLOGGED; - syslog(LOG_ERR, - "named-xfer exit code %d", - status.w_retcode); - } - /* FALLTHROUGH */ - case XFER_FAIL: - zp->z_state |= Z_SYSLOGGED; - zp->z_time = tt.tv_sec + zp->z_retry; - break; - } - break; - } -#ifndef SYSV - } -#endif /* SYSV */ - if (xfers) { - for (zp = zones; - xfers_deferred != 0 && xfers_running < MAX_XFERS_RUNNING && - zp < &zones[nzones]; zp++) - if (zp->z_state & Z_NEED_XFER) { - xfers_deferred--; - startxfer(zp); - } - sched_maint(); - } -#if defined(SYSV) - (void)signal(SIGCLD, endxfer); -#endif -} - -/* - * Reload zones whose transfers have completed. - */ -loadxfer() -{ - register struct zoneinfo *zp; - - gettime(&tt); - for (zp = zones; zp < &zones[nzones]; zp++) - if (zp->z_state & Z_NEED_RELOAD) { -#ifdef DEBUG - if (debug) - fprintf(ddt, "loadxfer() '%s'\n", - zp->z_origin[0] ? zp->z_origin : "."); -#endif - zp->z_state &= ~Z_NEED_RELOAD; - zp->z_auth = 0; - remove_zone(hashtab, zp - zones); - if (db_load(zp->z_source, zp->z_origin, zp, 0) == 0) - zp->z_auth = 1; - if (zp->z_state & Z_TMP_FILE) - (void) unlink(zp->z_source); - } - sched_maint(); -} diff --git a/usr.sbin/named/ns_req.c b/usr.sbin/named/ns_req.c deleted file mode 100644 index 50e40d6b00e..00000000000 --- a/usr.sbin/named/ns_req.c +++ /dev/null @@ -1,1353 +0,0 @@ -/* - * Copyright (c) 1986, 1988, 1990 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -/*static char sccsid[] = "from: @(#)ns_req.c 4.47 (Berkeley) 7/1/91";*/ -static char rcsid[] = "$Id: ns_req.c,v 1.1 1995/10/18 08:47:50 deraadt Exp $"; -#endif /* not lint */ - -#include <sys/param.h> -#include <sys/uio.h> -#include <sys/time.h> -#include <sys/file.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <syslog.h> -#include <arpa/nameser.h> -#include <resolv.h> -#include <stdio.h> -#include "ns.h" -#include "db.h" - -#define NADDRECS 20 - -extern int debug; -extern FILE *ddt; - -struct addinfo { - char *a_dname; /* domain name */ - u_short a_class; /* class for address */ -}; - -struct addinfo addinfo[NADDRECS]; /* additional info records */ -int addcount; /* number of names in addinfo */ -int xfr_disabled = 0; /* set to disable zone xfrs */ -int needs_prime_cache = 0; /* set if we need a priming */ - -u_char *dnptrs[20]; /* ptrs to dnames in message for dn_comp */ - -extern time_t retrytime(); -extern struct qinfo *sysquery(); -extern char *localdomain; /* XXX */ -extern int errno; -/* - * Process request using database; assemble and send response. - */ -ns_req(msg, msglen, buflen, qsp, from, dfd) - u_char *msg; - int msglen, buflen; - struct qstream *qsp; - struct sockaddr_in *from; - int dfd; -{ - register HEADER *hp; - register u_char *cp; - struct namebuf *np; - register struct databuf *dp; - struct hashbuf *htp; - struct netinfo *lp; - char *fname, *answers; - u_char *eom, *omsg; - char dnbuf[MAXDNAME], *dname; - u_char **dpp; - int n, class, type, count, foundname, founddata, omsglen, cname = 0; - u_short id; - struct databuf *nsp[NSMAX]; - struct qinfo *qp; - extern struct qinfo *qhead; - extern struct netinfo *local(); - extern int nsid; - -#ifdef DEBUG - if (debug > 3) { - fprintf(ddt,"ns_req()\n"); - fp_query((char *)msg, ddt); - } -#endif - - hp = (HEADER *) msg; - if (hp->qr) { - ns_resp(msg, msglen); - - /* Now is a safe time for housekeeping */ - if (needs_prime_cache) - prime_cache(); - return; - } - - hp->rcode = NOERROR; - cp = msg + sizeof(HEADER); - eom = msg + msglen; - dpp = dnptrs; - *dpp++ = msg; - addcount = 0; - - switch (hp->opcode) { - case QUERY: -#ifdef STATS - stats[S_QUERIES].cnt++; -#endif - if (ntohs(hp->qdcount) != 1 || - hp->ancount || hp->nscount || hp->arcount) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"FORMERR Query header counts wrong\n"); -#endif - hp->qdcount = 0; - hp->ancount = 0; - hp->nscount = 0; - hp->arcount = 0; - hp->rcode = FORMERR; - goto finish; - } - /* - * Get domain name, class, and type. - */ - if ((*cp & INDIR_MASK) == 0) - *dpp++ = cp; /* remember name for compression */ - *dpp = NULL; - if ((n = dn_expand(msg, eom, cp, (u_char *)dnbuf, - sizeof(dnbuf))) < 0) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"FORMERR Query expand name failed\n"); -#endif - hp->rcode = FORMERR; - goto finish; - } - cp += n; - GETSHORT(type, cp); - GETSHORT(class, cp); - if (cp > eom) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"FORMERR Query message length short\n"); -#endif - hp->rcode = FORMERR; - goto finish; - } -#ifdef DEBUG - if (cp < eom) - if (debug > 5) - fprintf(ddt,"message length > received message\n"); -#endif - -#ifdef STATS - if ((type > T_ANY) || (type < 0)) - typestats[0]++; /* Bad type */ - else - typestats[type]++; -#endif - /* - * Process query. - */ - if (type == T_AXFR) { - /* refuse request if not a TCP connection */ - if (qsp == QSTREAM_NULL || xfr_disabled) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"T_AXFR via UDP refused\n"); -#endif - hp->rcode = REFUSED; - goto finish; - } - dnptrs[0] = NULL; /* don't compress names */ - hp->rd = 0; /* recursion not possible */ - } - buflen -= msglen; - count = 0; - foundname = 0; - founddata = 0; - dname = dnbuf; -try_again: -#ifdef DEBUG - if (debug) - fprintf(ddt,"req: nlookup(%s) id %d type=%d\n", - dname, hp->id, type); -#endif - htp = hashtab; /* lookup relative to root */ - if ((np = nlookup(dname, &htp, &fname, 0)) == NULL) - fname = ""; -#ifdef DEBUG - if (debug) - fprintf(ddt,"req: %s '%s' as '%s' (cname=%d)\n", - np == NULL ? "missed" : "found", - dname, fname, cname); -#endif - /* START XXX */ - /* - * if nlookup failed to find address then - * see if there are any '.''s in the name - * if not then add local domain name to the - * name and try again. - */ - if (np == NULL && localdomain && index(dname, '.') == NULL) { - (void) strcat(dname,"."); - (void) strcat(dname, localdomain); -#ifdef DEBUG - if (debug) - fprintf(ddt,"req: nlookup(%s) type=%d\n", - dname, type); -#endif - htp = hashtab; - np = nlookup(dname, &htp, &fname, 0); - } - /* END XXX */ - if (np == NULL || fname != dname) - goto fetchns; - - foundname++; - answers = (char *)cp; - count = cp - msg; - n = finddata(np, class, type, hp, &dname, &buflen, &count); - if (n == 0) - goto fetchns; /* NO data available */ - cp += n; - buflen -= n; - msglen += n; - hp->ancount += count; - if (fname != dname && type != T_CNAME && type != T_ANY) { - if (cname++ >= MAXCNAMES) { -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt, - "resp: leaving, MAXCNAMES exceeded\n"); -#endif - hp->rcode = SERVFAIL; - goto finish; - } - goto try_again; - } - founddata = 1; -#ifdef DEBUG - if (debug >= 3) { - fprintf(ddt,"req: foundname = %d count = %d ", foundname, count); - fprintf(ddt,"founddata = %d cname = %d\n",founddata, cname); - } -#endif - if ((lp = local(from)) != NULL) - sort_response(answers, count, lp, cp); - if (type == T_AXFR) { - if (founddata) { - hp->ancount = htons(hp->ancount); - startxfr(qsp, np, msg, cp - msg); - return; - } - hp->rcode = REFUSED; /* No go if unauthoritative */ - goto finish; - } -#ifdef notdef - /* - * If we found an authoritative answer, - * we're done. - */ - if (hp->aa) - goto finish; -#endif - -fetchns: - /* - * Look for name servers to refer to and fill in the authority - * section or record the address for forwarding the query - * (recursion desired). - */ - nsp[0] = NULL; - switch (findns(&np, class, nsp, &count)) { - case NXDOMAIN: - if (!foundname) - hp->rcode = NXDOMAIN; -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"req: leaving (%s, rcode %d)\n", - dname, hp->rcode); -#endif - if (class != C_ANY) { - hp->aa = 1; - /* XXX - * should return SOA if founddata == 0, - * but old named's are confused by an SOA - * in the auth. section if there's no error. - */ - if (foundname == 0 && np) { - n = doaddauth(hp, cp, buflen, np, nsp[0]); - cp += n; - buflen -= n; - } - } - goto finish; - - case SERVFAIL: - if (!founddata) { - hp->rcode = SERVFAIL; - goto finish; - } - } - - /* - * If we successfully found the answer in the cache - * or this is not a recursive query, then add the - * nameserver references here and return. - */ - if (founddata || (!hp->rd)) { - n = add_data(np, nsp, cp, buflen); - if (n < 0) { - hp->tc = 1; - n = (-n); - } - cp += n; - buflen -= n; - hp->nscount = htons((u_short)count); - goto finish; - } - - /* - * At this point, we don't have the answer, but we do - * have some NS's to try. If the user would like us - * to recurse, create the initial query. If a cname - * is involved, we need to build a new query and save - * the old one in cmsg/cmsglen. - */ - if (cname) { - omsg = (u_char *)malloc((unsigned)msglen); - if (omsg == (u_char *)NULL) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"ns_req: malloc fail\n"); -#endif - syslog(LOG_ERR, "ns_req: Out Of Memory"); - hp->rcode = SERVFAIL; - break; - } - id = hp->id; - hp->ancount = htons(hp->ancount); - bcopy(msg, omsg, omsglen = msglen); - msglen = res_mkquery(QUERY, dname, class, type, - (char *)NULL, 0, NULL, (char *)msg, - msglen+buflen); - } - n = ns_forw(nsp, msg, msglen, from, qsp, dfd, &qp); - if (n != FW_OK && cname) - free(omsg); - switch (n) { - case FW_OK: - if (cname) { - qp->q_cname = cname; - qp->q_cmsg = (char *)omsg; - qp->q_cmsglen = omsglen; - qp->q_id = id; - } - break; - case FW_DUP: - break; /* Duplicate request dropped */ - case FW_NOSERVER: - if(np) - np = np->n_parent; - goto fetchns; /* Try again. */ - case FW_SERVFAIL: - hp->rcode = SERVFAIL; - goto finish; - } - /* Now is a safe time for housekeeping */ - if (needs_prime_cache) - prime_cache(); - return; - - case IQUERY: { - register struct invbuf *ip; - register int i; - int dlen, alen; - char anbuf[PACKETSZ], *data; - -#ifdef STATS - stats[S_IQUERIES].cnt++; -#endif - hp->ancount = htons(hp->ancount); - if (hp->ancount != 1 || - hp->qdcount || hp->nscount || hp->arcount) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"FORMERR IQuery header counts wrong\n"); -#endif - hp->qdcount = 0; - hp->ancount = 0; - hp->nscount = 0; - hp->arcount = 0; - hp->rcode = FORMERR; - goto finish; - } - /* - * Skip domain name, get class, and type. - */ - if ((n = dn_skipname(cp, eom)) < 0) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"FORMERR IQuery packet name problem\n"); -#endif - hp->rcode = FORMERR; - goto finish; - } - cp += n; - GETSHORT(type, cp); - GETSHORT(class, cp); - cp += sizeof(u_long); - GETSHORT(dlen, cp); - cp += dlen; - if (cp != eom) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"FORMERR IQuery message length off\n"); -#endif - hp->rcode = FORMERR; - goto finish; - } - /* not all inverse queries are handled. */ - switch (type) { - case T_A: - case T_UID: - case T_GID: - break; - - default: - hp->rcode = REFUSED; - goto finish; - } -#ifdef DEBUG - if (debug) - fprintf(ddt,"req: IQuery class %d type %d\n", - class, type); -#endif - fname = (char *)msg + sizeof(HEADER); - bcopy(fname, anbuf, alen = (char *)cp - fname); - data = anbuf + alen - dlen; - cp = (u_char *)fname; - buflen -= sizeof(HEADER); - count = 0; - for (ip = invtab[dhash(data, dlen)]; ip != NULL; - ip = ip->i_next) { - for (i = 0; i < INVBLKSZ; i++) { - if ((np = ip->i_dname[i]) == NULL) - break; -#ifdef DEBUG - if (debug >= 5) - fprintf(ddt,"dname = %d\n", np->n_dname); -#endif - for (dp = np->n_data; dp != NULL; dp = dp->d_next) { - if (!match(dp, class, type)) - continue; - if (dp->d_size != dlen || - bcmp(dp->d_data, data, dlen)) - continue; - getname(np, dnbuf, sizeof(dnbuf)); -#ifdef DEBUG - if (debug > 2) - fprintf(ddt,"req: IQuery found %s\n", - dnbuf); -#endif - buflen -= QFIXEDSZ; - if ((n = dn_comp((u_char *)dnbuf, cp, buflen, - (u_char **)NULL, (u_char **)NULL)) < 0) - { - hp->tc = 1; - goto finish; - } - cp += n; - PUTSHORT((u_short)dp->d_type, cp); - PUTSHORT((u_short)dp->d_class, cp); - buflen -= n; - count++; - } - } - } -#ifdef DEBUG - if (debug) - fprintf(ddt,"req: IQuery %d records\n", count); -#endif - hp->qdcount = htons((u_short)count); - if (alen > buflen) { - hp->tc = 1; - break; - } - bcopy(anbuf, cp, alen); - cp += alen; - break; - } - -#ifdef ALLOW_UPDATES -/* - * In a sense the following constant should be defined in <arpa/nameser.h>, - * since it is returned here in place of a response code if the update was - * forwarded, and the response codes are defined in nameser.h. On the other - * hand, though, this constant is only seen in this file. The assumption - * here is that none of the other return codes equals this one (a good - * assumption, since they only occupy 4 bits over-the-wire) - */ -#define FORWARDED 1000 - /* Call InitDynUpdate for all dynamic update requests */ - case UPDATEM: - case UPDATEMA: - case UPDATED: - case UPDATEDA: - case UPDATEA: - n = InitDynUpdate(hp, nsp, msg, msglen, cp, from, qsp, dfd); - if (n == FORWARDED) - return; /* Return directly because InitDynUpdate - * forwarded the query to the primary, so we - * will send response later - */ - else - break; /* Either sucessful primary update or failure; - * return response code to client - */ -#endif ALLOW_UPDATES - - case ZONEREF: -#ifdef DEBUG - if (debug) - fprintf(ddt,"Refresh Zone\n"); -#endif - - default: -#ifdef DEBUG - if (debug >= 2) - fprintf(ddt,"Opcode %d not implemented\n", hp->opcode); -#endif - hp->qdcount = 0; - hp->ancount = 0; - hp->nscount = 0; - hp->arcount = 0; - hp->rcode = NOTIMP; - } -finish: -#ifdef STATS - switch(hp->rcode) { - case NOERROR: - stats[S_RESPOK].cnt++; - break; - case FORMERR: - stats[S_RESPFORMERR].cnt++; - break; - default: - stats[S_RESPFAIL].cnt++; - break; - } -#endif - hp->qr = 1; /* set Response flag */ - hp->ra = 1; /* Recursion is Available */ - hp->ancount = htons(hp->ancount); - if (addcount) { - n = doaddinfo(hp, cp, buflen); - cp += n; - buflen -= n; - } - -#ifdef DEBUG - if (debug) { - fprintf(ddt,"req: answer -> %s %d (%d) id=%d %s\n", - inet_ntoa(from->sin_addr), - qsp == QSTREAM_NULL ? dfd : qsp->s_rfd, - ntohs(from->sin_port), - ntohs(hp->id), local(from) == NULL ? "Remote" : "Local"); - } - if (debug >= 10) - fp_query((char *)msg, ddt); -#endif DEBUG - if (qsp == QSTREAM_NULL) { - if (sendto(dfd, msg, cp-msg, 0, (struct sockaddr *)from, - sizeof(*from))< 0){ -#ifdef DEBUG - if (debug) - fprintf(ddt,"error returning msg errno=%d\n",errno); -#endif DEBUG - } -#ifdef STATS - stats[S_OUTPKTS].cnt++; -#endif - } else { - (void) writemsg(qsp->s_rfd, msg, cp - msg); - sq_done(qsp); - } - if (needs_prime_cache) - prime_cache(); /* Now is a safe time */ -} - -fwritemsg(rfp, msg, msglen) - FILE *rfp; - char *msg; - int msglen; -{ - u_short len = htons((u_short)msglen); - - if (fwrite((char *)&len, sizeof(len), 1, rfp) != 1 || - fwrite(msg, msglen, 1, rfp) != 1) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"fwrite failed %d\n", errno); -#endif - } - return; -} - -writemsg(rfd, msg, msglen) - int rfd; - char *msg; - int msglen; -{ - struct iovec iov[2]; - u_short len = htons((u_short)msglen); - - iov[0].iov_base = (caddr_t)&len; - iov[0].iov_len = sizeof(len); - iov[1].iov_base = msg; - iov[1].iov_len = msglen; - if (writev(rfd, iov, 2) != sizeof(len) + msglen) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"write failed %d\n", errno); -#endif - return (-1); - } - return (0); -} - -/* - * Test a datum for validity and return non-zero if it is out of date. - */ -stale(dp) -register struct databuf *dp; -{ - register struct zoneinfo *zp = &zones[dp->d_zone]; - - switch (zp->z_type) { - - case Z_PRIMARY: - return (0); - - case Z_SECONDARY: - /* - * Check to see whether a secondary zone - * has expired; if so clear authority flag - * for zone and return true. If lastupdate - * is in the future, assume zone is up-to-date. - */ - if ((long)(tt.tv_sec - zp->z_lastupdate) > (long)zp->z_expire) { -#ifdef DEBUG - if (debug) - fprintf(ddt, - "stale: secondary zone %s expired\n", - zp->z_origin); -#endif - syslog(LOG_ERR, "secondary zone \"%s\" expired\n", - zp->z_origin); - zp->z_auth = 0; - return (1); - } - return (0); - - case Z_CACHE: -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"stale: ttl %d %d (x%x)\n", - dp->d_ttl, dp->d_ttl - tt.tv_sec, dp->d_flags); -#endif - if (dp->d_flags & DB_F_HINT) - return(0); - return(dp->d_ttl < tt.tv_sec); - - } - /* NOTREACHED */ -} - -/* - * Copy databuf into a resource record for replies. - * Return size of RR if OK, -1 if buffer is full. - */ -make_rr(name, dp, buf, buflen, doadd) - char *name; - register struct databuf *dp; - char *buf; - int buflen, doadd; -{ - register char *cp; - char *cp1, *sp; - struct zoneinfo *zp; - register long n; - register long ttl; - u_char **edp = dnptrs + sizeof(dnptrs)/sizeof(dnptrs[0]); - -#ifdef DEBUG - if (debug >= 5) - fprintf(ddt,"make_rr(%s, %x, %x, %d, %d) %d zone %d ttl %d\n", - name, dp, buf, - buflen, doadd, dp->d_size, dp->d_zone, dp->d_ttl); -#endif - - zp = &zones[dp->d_zone]; - /* check for outdated RR before updating dnptrs by dn_comp() (???) */ - if (zp->z_type == Z_CACHE) { - ttl = dp->d_ttl - (u_long) tt.tv_sec; - if ((dp->d_flags & DB_F_HINT) || (ttl < 0)) { -#ifdef DEBUG -/*XXX*/if (debug >= 3) fprintf(ddt,"make_rr: %d=>0, x%x\n", ttl, dp->d_flags); -#endif - ttl = 0; - } - } else { - if (dp->d_ttl) - ttl = dp->d_ttl; - else - ttl = zp->z_minimum; /* really default */ -#ifdef notdef /* don't decrease ttl based on time since verification */ - if (zp->z_type == Z_SECONDARY) { - /* - * Set ttl to value received from primary, - * less time since we verified it (but never - * less than a small positive value). - */ - ttl -= tt.tv_sec - zp->z_lastupdate; - if (ttl <= 0) - ttl = 120; - } -#endif - } - - buflen -= RRFIXEDSZ; - if ((n = dn_comp((u_char *)name, (u_char *)buf, buflen, - (u_char **)dnptrs, (u_char **)edp)) < 0) - return (-1); - cp = buf + n; - buflen -= n; - PUTSHORT((u_short)dp->d_type, cp); - PUTSHORT((u_short)dp->d_class, cp); - PUTLONG(ttl, cp); - sp = cp; - cp += sizeof(u_short); - switch (dp->d_type) { - case T_CNAME: - case T_MG: - case T_MR: - case T_PTR: - if ((n = dn_comp((u_char *)dp->d_data, (u_char *)cp, buflen, - (u_char **)dnptrs, (u_char **)edp)) < 0) - return (-1); - PUTSHORT((u_short)n, sp); - cp += n; - break; - - case T_MB: - case T_NS: - /* Store domain name in answer */ - if ((n = dn_comp((u_char *)dp->d_data, (u_char *)cp, buflen, - (u_char **)dnptrs, (u_char **)edp)) < 0) - return (-1); - PUTSHORT((u_short)n, sp); - cp += n; - if (doadd) - addname(dp->d_data, dp->d_class); - break; - - case T_SOA: - case T_MINFO: - cp1 = dp->d_data; - if ((n = dn_comp((u_char *)cp1, (u_char *)cp, buflen, - (u_char **)dnptrs, (u_char **)edp)) < 0) - return (-1); - cp += n; - buflen -= dp->d_type == T_MINFO ? n : n + 5 * sizeof(u_long); - cp1 += strlen(cp1) + 1; - if ((n = dn_comp((u_char *)cp1, (u_char *)cp, buflen, - (u_char **)dnptrs, (u_char **)edp)) < 0) - return (-1); - cp += n; - if (dp->d_type == T_SOA) { - cp1 += strlen(cp1) + 1; - bcopy(cp1, cp, - (int)(n = dp->d_size - (cp1 - dp->d_data))); - cp += n; - } - n = (u_short)(cp - sp) - sizeof(u_short); - PUTSHORT((u_short)n, sp); - break; - - case T_MX: - /* cp1 == our data/ cp == data of RR */ - cp1 = dp->d_data; - - /* copy preference */ - bcopy(cp1,cp,sizeof(u_short)); - cp += sizeof(u_short); - cp1 += sizeof(u_short); - buflen -= sizeof(u_short); - - if ((n = dn_comp((u_char *)cp1, (u_char *)cp, buflen, - (u_char **)dnptrs, (u_char **)edp)) < 0) - return(-1); - cp += n; - - /* save data length */ - n = (u_short)(cp - sp) - sizeof(u_short); - PUTSHORT((u_short)n, sp); - if (doadd) - addname(cp1, dp->d_class); - break; - - default: - if (dp->d_size > buflen) - return (-1); - bcopy(dp->d_data, cp, dp->d_size); - PUTSHORT((u_short)dp->d_size, sp); - cp += dp->d_size; - } - return (cp - buf); -} - -addname(name, class) -register char *name; -short class; -{ - register struct addinfo *ap; - register int n; - - for (ap = addinfo, n = addcount; --n >= 0; ap++) - if (strcasecmp(ap->a_dname, name) == 0) - return; - /* add domain name to additional section */ - if (addcount < NADDRECS) { - addcount++; - ap->a_dname = name; - ap->a_class = class; - } -} - -/* - * Lookup addresses for names in addinfo and put into the message's - * additional section. - */ -doaddinfo(hp, msg, msglen) - HEADER *hp; - char *msg; - int msglen; -{ - register struct namebuf *np; - register struct databuf *dp; - register struct addinfo *ap; - register char *cp; - struct hashbuf *htp; - char *fname; - int n, count, foundstale; - -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"doaddinfo() addcount = %d\n", addcount); -#endif - - count = 0; - cp = msg; - for (ap = addinfo; --addcount >= 0; ap++) { -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"do additional '%s'\n", ap->a_dname); -#endif - htp = hashtab; /* because "nlookup" stomps on arg. */ - np = nlookup(ap->a_dname, &htp, &fname, 0); - if (np == NULL || fname != ap->a_dname) - continue; -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"found it\n"); -#endif - foundstale = 0; - /* look for the data */ - for (dp = np->n_data; dp != NULL; dp = dp->d_next) { - if (!match(dp, (int)ap->a_class, T_A)) - continue; - if (stale(dp)) { - foundstale++; -#ifdef DEBUG - if (debug) - fprintf(ddt,"doaddinfo: stale entry '%s'%s\n", - np->n_dname, - (dp->d_flags&DB_F_HINT) ? " hint":"" ); -#endif - continue; - } - /* - * Should be smart and eliminate duplicate - * data here. XXX - */ - if ((n = make_rr(ap->a_dname, dp, cp, msglen, 0)) < 0) - break; -#ifdef DEBUG - if (debug >= 5) - fprintf(ddt,"addinfo: adding address data n = %d\n", - n); -#endif - cp += n; - msglen -= n; - count++; - } - if (foundstale) { - /* Cache invalidate the address RR's */ - delete_all(np, (int)ap->a_class, T_A); - (void) sysquery(ap->a_dname, (int)ap->a_class, T_A); - } - } - hp->arcount = htons((u_short)count); - return (cp - msg); -} - -doaddauth(hp, cp, buflen, np, dp) - register HEADER *hp; - char *cp; - int buflen; - struct namebuf *np; - struct databuf *dp; -{ - char dnbuf[MAXDNAME]; - int n; - - getname(np, dnbuf, sizeof(dnbuf)); - if (stale(dp) || (n = make_rr(dnbuf, dp, cp, buflen, 1)) <= 0) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"doaddauth: can't add '%s' (%d)\n", - dnbuf, buflen); -#endif - return(0); - } else { - hp->nscount = htons(1); - return(n); - } -} - - -/* - * Get the domain name of 'np' and put in 'buf'. Bounds checking is done. - */ -getname(np, buf, buflen) - struct namebuf *np; - char *buf; - int buflen; -{ - register char *cp; - register int i; - - cp = buf; - while (np != NULL) { - if ((i = strlen(np->n_dname))+1 >= buflen) { - *cp = '\0'; - syslog(LOG_ERR, "domain name too long: %s...\n", buf); - strcpy(buf, "Name_Too_Long"); - return; - } - if (cp != buf) - *cp++ = '.'; - (void) strcpy(cp, np->n_dname); - cp += i; - buflen -= (i+1); - np = np->n_parent; - } - *cp = '\0'; -} - -/* - * Do a zone transfer. SOA record already sent. - */ -doaxfr(np, rfp, isroot) - register struct namebuf *np; - FILE *rfp; - int isroot; -{ - register struct databuf *dp; - register int n; - struct hashbuf *htp; - struct databuf *gdp; /* glue databuf */ - struct namebuf *gnp; /* glue namebuf */ - struct namebuf **npp, **nppend; - char msg[PACKETSZ]; - char *cp; - char *fname; - char dname[MAXDNAME]; - HEADER *hp = (HEADER *) msg; - int fndns; - -#ifdef DEBUG - if (debug && isroot) - fprintf(ddt,"doaxfr()\n"); -#endif - fndns = 0; - hp->id = 0; - hp->opcode = QUERY; - hp->aa = hp->tc = hp->ra = hp->pr = hp->rd = 0; - hp->qr = 1; - hp->rcode = NOERROR; - hp->qdcount = 0; - hp->ancount = htons(1); - hp->nscount = 0; - hp->arcount = 0; - cp = msg + sizeof(HEADER); - getname(np, dname, sizeof(dname)); - - /* first do data records */ - for (dp = np->n_data; dp != NULL; dp = dp->d_next) { - /* - * Skip the root SOA record (marks end of data); - * don't send SOA for subdomains, as we're not sending them. - */ - if (dp->d_type == T_SOA) - continue; - if (dp->d_type == T_NS) - fndns = 1; - if (dp->d_zone == 0 || stale(dp)) - continue; - if ((n = make_rr(dname, dp, cp, sizeof(msg)-sizeof(HEADER), 0)) < 0) - continue; - fwritemsg(rfp, msg, n + sizeof(HEADER)); - - if (dp->d_type == T_NS) { - /* Glue the sub domains together by sending - * the address records for the sub domain - * name servers along. - */ - htp = hashtab; - cp = msg + sizeof(HEADER); - gnp = nlookup(dp->d_data, &htp, &fname, 0); - if (gnp == NULL || fname != dp->d_data) - continue; - for(gdp=gnp->n_data; gdp != NULL; gdp=gdp->d_next) { - if (gdp->d_type != T_A || stale(gdp)) - continue; - if ((n = make_rr(fname, gdp, cp, - sizeof(msg)-sizeof(HEADER), 0)) < 0) - continue; - fwritemsg(rfp, msg, n + sizeof(HEADER)); - } - } - } - - /* next do subdomains, unless delegated */ - if ((isroot == 0 && fndns) || np->n_hash == NULL) - return; - npp = np->n_hash->h_tab; - nppend = npp + np->n_hash->h_size; - while (npp < nppend) { - for (np = *npp++; np != NULL; np = np->n_next) { - doaxfr(np, rfp, 0); - } - } -#ifdef DEBUG - if (debug && isroot) - fprintf(ddt,"exit doaxfr()\n"); -#endif -} - -#ifdef ALLOW_UPDATES -/* - * Called by UPDATE{A,D,DA,M,MA} to initiate a dynamic update. If this is the - * primary server for the zone being updated, we update the zone's serial - * number and then call doupdate directly. If this is a secondary, we just - * forward the update; this way, if the primary update fails (e.g., if the - * primary is unavailable), we don't update the secondary; if the primary - * update suceeds, ns_resp will get called with the response (when it comes - * in), and then update the secondary's copy. - */ -InitDynUpdate(hp, nsp, msg, msglen, startcp, from, qsp, dfd) - register HEADER *hp; - struct databuf *nsp[]; - char *msg; - int msglen; - u_char *startcp; - struct sockaddr_in *from; - struct qstream *qsp; - int dfd; -{ - struct zoneinfo *zp; - char dnbuf[MAXDNAME]; - struct hashbuf *htp = hashtab; /* lookup relative to root */ - struct namebuf *np; - struct databuf *olddp, *newdp, *dp; - struct databuf **nspp; - char *fname; - register u_char *cp = startcp; - short class, type; - int n, size, zonenum; - char ZoneName[MAXDNAME], *znp; - - if ((n = dn_expand(msg, msg + msglen, cp, dnbuf, sizeof(dnbuf))) < 0) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"FORMERR InitDynUpdate expand name failed\n"); -#endif - hp->rcode = FORMERR; - return(FORMERR); - } - cp += n; - GETSHORT(type, cp); - if (type == T_SOA) { /* T_SOA updates not allowed */ - hp->rcode = REFUSED; -#ifdef DEBUG - if (debug) - fprintf(ddt, "InitDynUpdate: REFUSED - SOA update\n"); -#endif - return(REFUSED); - } - GETSHORT(class, cp); - cp += sizeof(u_long); - GETSHORT(size, cp); -/****XXX - need bounds checking here ****/ - cp += size; - - if ((zonenum = findzone(dnbuf, class)) == 0) { /* zone not found */ - hp->rcode = NXDOMAIN; - return(NXDOMAIN); - } - zp = &zones[zonenum]; - - /* Disallow updates for which we aren't authoratative. Note: the - following test doesn't work right: If it's for a non-local zone, - we will think it's a primary but be unable to lookup the namebuf, - thus returning 'NXDOMAIN' */ - if (zp->z_type != Z_PRIMARY && zp->z_type != Z_SECONDARY) { - hp->rcode = REFUSED; -#ifdef DEBUG - if (debug) - fprintf(ddt, "InitDynUpdate: REFUSED - non-primary, non-sedondary update\n"); -#endif - return(REFUSED); - } - if (!(zp->z_state & Z_DYNAMIC)) { - hp->rcode = REFUSED; -#ifdef DEBUG - if (debug) - fprintf(ddt, "InitDynUpdate: REFUSED - dynamic flag not set for zone\n"); -#endif - return(REFUSED); - } - - /* - * Lookup the zone namebuf. Lookup "xyz" not "xyz.", since - * otherwise the lookup fails, because '.' may have a nil n_hash - * associated with it. - */ - strcpy(ZoneName, zp->z_origin); - znp = &ZoneName[strlen(ZoneName) - 1]; - if (*znp == '.') - *znp = NULL; - np = nlookup(ZoneName, &htp, &fname, 0); - if ((np == NULL) || (fname != ZoneName)) { -#ifdef DEBUG - if (debug) - fprintf(ddt, "InitDynUpdate: lookup failed on zone (%s)\n", - ZoneName); -#endif DEBUG - syslog(LOG_ERR, "InitDynUpdate: lookup failed on zone (%s)\n", - ZoneName); - hp->rcode = NXDOMAIN; - return(NXDOMAIN); - } - - /* - * If this is the primary copy increment the serial number. Don't - * increment the serial number if this is a secondary; this way, if 2 - * different secondaries both update the primary, they will both have - * lower serial numbers than the primary has, and hence eventually - * refresh and get all updates and become consistent. - * - * Note that the serial number must be incremented in both the zone - * data structure and the zone's namebuf. - */ - switch (zp->z_type) { - case Z_SECONDARY: /* forward update to primary */ - nspp = nsp; - dp = np->n_data; - while (dp != NULL) { - if (match(dp, class, T_NS)) { - if (nspp < &nsp[NSMAX-1]) - *nspp++ = dp; - else - break; - } - dp = dp->d_next; - } - *nspp = NULL; /* Delimiter */ - if (ns_forw(nsp, msg, msglen, from, qsp, dfd, NULL) < 0) { - hp->rcode = SERVFAIL; - return(SERVFAIL); - } - return(FORWARDED); - - case Z_PRIMARY: - zp->z_serial++; - olddp = np->n_data; /* old databuf */ - /* Find the SOA record */ - for (olddp = np->n_data; olddp != NULL; olddp = olddp->d_next) - if (match(olddp, class, T_SOA)) - break; - if (olddp == NULL) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"InitDynUpdate: Couldn't find SOA record for '%s'\n", - ZoneName); -#endif DEBUG - syslog(LOG_ERR, - "InitDynUpdate: Couldn't find SOA record for '%s'\n" -, - ZoneName); - hp->rcode = NXDOMAIN; - return(NXDOMAIN); - } - newdp = savedata(olddp->d_class, olddp->d_type, olddp->d_ttl, - olddp->d_data, olddp->d_size); - newdp->d_zone = olddp->d_zone; - cp = (u_char *)newdp->d_data; - cp += strlen(cp) + 1; /* skip origin string */ - cp += strlen(cp) + 1; /* skip in-charge string */ - putlong((u_long)(zp->z_serial), cp); -#ifdef DEBUG - if (debug >= 4) { - fprintf(ddt, "after stuffing data into newdp:\n"); - printSOAdata(newdp); - } -#endif DEBUG - - if ((n = db_update(ZoneName, olddp, newdp, DB_DELETE, - hashtab)) != NOERROR) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"InitDynUpdate: SOA update failed\n"); -#endif DEBUG - hp->rcode = NOCHANGE; - return(NOCHANGE); - } - - /* Now update the RR itself */ - if (doupdate(msg, msglen, msg + sizeof(HEADER), - zonenum, (struct databuf *)0, DB_NODATA) < 0) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"InitDynUpdate: doupdate failed\n"); -#endif DEBUG - /* doupdate fills in rcode */ - return(hp->rcode); - } - zp->hasChanged++; - return(NOERROR); - } -} - -#ifdef DEBUG -/* - * Print the contents of the data in databuf pointed to by dp for an SOA record - */ -printSOAdata(dp) - struct databuf *dp; -{ - register u_char *cp; - - if (!debug) - return; /* Otherwise fprintf to ddt will bomb */ - cp = (u_char *)dp->d_data; - fprintf(ddt, "printSOAdata(%x): origin(%x)='%s'\n", dp, cp, cp); - cp += strlen(cp) + 1; /* skip origin string */ - fprintf(ddt, "printSOAdata: in-charge(%x)='%s'\n", cp, cp); - cp += strlen(cp) + 1; /* skip in-charge string */ - fprintf(ddt, "printSOAdata: serial(%x)=%d\n", cp, _getlong(cp)); -} -#endif DEBUG -#endif ALLOW_UPDATES - -struct databuf * -rm_datum(dp, np, pdp) -register struct databuf *pdp, *dp; -register struct namebuf *np; -{ - register struct databuf *ndp = dp->d_next; - -#ifdef DEBUG - if (debug > 2) - fprintf(ddt, "rm_datum(%x, %x, %x) -> %x\n", - dp, np->n_data, pdp, ndp); -#endif DEBUG - if (pdp == NULL) - np->n_data = ndp; - else - pdp->d_next = ndp; - rminv(dp); - (void) free((char *)dp); - return(ndp); -} - -startxfr(qsp, np, msg, msglen) - struct qstream *qsp; - struct namebuf *np; - char *msg; - int msglen; -{ - register FILE *rfp; - int fdstat; - -#ifdef DEBUG - if (debug >= 5) - fprintf(ddt,"startxfr()\n"); -#endif - /* - * child does the work while - * the parent continues - */ - if (fork() == 0) { -#ifdef DEBUG - if (debug >= 5) - fprintf(ddt,"startxfr: child pid %d\n", getpid()); -#endif - rfp = fdopen(qsp->s_rfd, "w"); - setproctitle("zone XFR to", qsp->s_rfd); - fdstat = fcntl(qsp->s_rfd, F_GETFL, 0); - if (fdstat != -1) - (void) fcntl(qsp->s_rfd, F_SETFL, fdstat & ~O_NONBLOCK); - fwritemsg(rfp, msg, msglen); - doaxfr(np, rfp, 1); - fwritemsg(rfp, msg, msglen); - (void) fflush(rfp); - exit(0); - } - sqrm(qsp); -} diff --git a/usr.sbin/named/ns_resp.c b/usr.sbin/named/ns_resp.c deleted file mode 100644 index 4a8f786b5ca..00000000000 --- a/usr.sbin/named/ns_resp.c +++ /dev/null @@ -1,1704 +0,0 @@ -/* - * Copyright (c) 1986, 1988, 1990 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -/*static char sccsid[] = "from: @(#)ns_resp.c 4.65 (Berkeley) 3/3/91";*/ -static char rcsid[] = "$Id: ns_resp.c,v 1.1 1995/10/18 08:47:51 deraadt Exp $"; -#endif /* not lint */ - -#include <sys/param.h> -#include <sys/time.h> -#include <sys/socket.h> -#include <sys/file.h> -#include <netinet/in.h> -#include <syslog.h> -#include <arpa/nameser.h> -#include <resolv.h> -#include <stdio.h> -#include "ns.h" -#include "db.h" - -extern int debug; -extern FILE *ddt; -extern int errno; -extern u_char *dnptrs[]; -extern time_t retrytime(); -extern struct fwdinfo *fwdtab; -extern struct sockaddr_in from_addr; /* Source addr of last packet */ -extern int needs_prime_cache; -extern int priming; - -struct qinfo *sysquery(); - -ns_resp(msg, msglen) - u_char *msg; - int msglen; -{ - register struct qinfo *qp; - register HEADER *hp; - register struct qserv *qs; - register struct databuf *ns, *ns2; - register u_char *cp; - struct databuf *nsp[NSMAX], **nspp; - int i, c, n, ancount, aucount, nscount, arcount; - int type, class, dbflags; - int cname = 0; /* flag for processing cname response */ - int count, founddata, foundname; - int buflen; - int newmsglen; - char name[MAXDNAME], *dname; - char *fname; - u_char newmsg[BUFSIZ]; - u_char **dpp, *tp; - time_t rtrip; - - struct hashbuf *htp; - struct namebuf *np; - struct netinfo *lp; - extern struct netinfo *local(); - extern int nsid; - extern int addcount; - struct fwdinfo *fwd; - -#ifdef STATS - stats[S_RESPONSES].cnt++; -#endif - hp = (HEADER *) msg; - if ((qp = qfindid(hp->id)) == NULL ) { -#ifdef DEBUG - if (debug > 1) - fprintf(ddt,"DUP? dropped (id %d)\n", ntohs(hp->id)); -#endif -#ifdef STATS - stats[S_DUPRESP].cnt++; -#endif - return; - } - -#ifdef DEBUG - if (debug >= 2) - fprintf(ddt,"%s response nsid=%d id=%d\n", - qp->q_system ? "SYSTEM" : "USER", - ntohs(qp->q_nsid), ntohs(qp->q_id)); -#endif - - /* - * Here we handle bad responses from servers. - * Several possibilities come to mind: - * The server is sick and returns SERVFAIL - * The server returns some garbage opcode (its sick) - * The server can't understand our query and return FORMERR - * In all these cases, we simply drop the packet and force - * a retry. This will make him look bad due to unresponsiveness. - * Be sure not to include authoritative NXDOMAIN - */ - if ((hp->rcode != NOERROR && hp->rcode != NXDOMAIN) - || (hp->rcode == NXDOMAIN && !hp->aa) - || hp->opcode != QUERY) { -#ifdef DEBUG - if (debug >= 2) - fprintf(ddt,"resp: error (ret %d, op %d), dropped\n", - hp->rcode, hp->opcode); -#endif -#ifdef STATS - stats[S_BADRESPONSES].cnt++; -#endif - return; - } - -#ifdef ALLOW_UPDATES - if ( (hp->rcode == NOERROR) && - (hp->opcode == UPDATEA || hp->opcode == UPDATED || - hp->opcode == UPDATEDA || hp->opcode == UPDATEM || - hp->opcode == UPDATEMA) ) { - /* - * Update the secondary's copy, now that the primary - * successfully completed the update. Zone doesn't matter - * for dyn. update -- doupdate calls findzone to find it - */ - doupdate(qp->q_msg, qp->q_msglen, qp->q_msg + sizeof(HEADER), - 0, (struct databuf *)0, 0); -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"resp: leaving, UPDATE*\n"); -#endif - /* return code filled in by doupdate */ - goto return_msg; - } -#endif ALLOW_UPDATES - - /* - * Determine if the response came from a forwarder. Packets from - * anyplace not listed as a forwarder or as a server to whom we - * might have forwarded the query will be dropped. - */ - for (fwd = fwdtab; fwd != (struct fwdinfo *)NULL; fwd = fwd->next) - if (bcmp((char *)&fwd->fwdaddr.sin_addr, &from_addr.sin_addr, - sizeof(struct in_addr)) == 0) - break; - /* - * If we were using nameservers, find the qinfo pointer and update - * the rtt and fact that we have called on this server before. - */ - if (fwd == (struct fwdinfo *)NULL) { - struct timeval *stp; - - for (n = 0, qs = qp->q_addr; n < qp->q_naddr; n++, qs++) - if (bcmp((char *)&qs->ns_addr.sin_addr, - &from_addr.sin_addr, sizeof(struct in_addr)) == 0) - break; - if (n >= qp->q_naddr) { -#ifdef DEBUG - if (debug) - fprintf(ddt, "Response from unexpected source %s\n", - inet_ntoa(from_addr.sin_addr)); -#endif DEBUG -#ifdef STATS - stats[S_MARTIANS].cnt++; -#endif - /* - * We don't know who this response came from so it - * gets dropped on the floor. - */ - return; - } - stp = &qs->stime; - - /* Handle response from different (untried) interface */ - if (stp->tv_sec == 0) { - ns = qs->ns; - while (qs > qp->q_addr && - (qs->stime.tv_sec == 0 || qs->ns != ns)) - qs--; - *stp = qs->stime; -#ifdef DEBUG - if (debug) - fprintf(ddt, - "Response from unused address %s, assuming %s\n", - inet_ntoa(from_addr.sin_addr), - inet_ntoa(qs->ns_addr.sin_addr)); -#endif DEBUG - } - - /* compute query round trip time */ - rtrip = ((tt.tv_sec - stp->tv_sec) * 1000 + - (tt.tv_usec - stp->tv_usec) / 1000); - -#ifdef DEBUG - if (debug > 2) - fprintf(ddt,"stime %d/%d now %d/%d rtt %d\n", - stp->tv_sec, stp->tv_usec, - tt.tv_sec, tt.tv_usec, rtrip); -#endif - /* prevent floating point overflow, limit to 1000 sec */ - if (rtrip > 1000000) - rtrip = 1000000; - ns = qs->nsdata; - /* - * Don't update nstime if this doesn't look - * like an address databuf now. XXX - */ - if (ns->d_type == T_A && ns->d_class == qs->ns->d_class) { - if (ns->d_nstime == 0) - ns->d_nstime = (u_long)rtrip; - else - ns->d_nstime = ns->d_nstime * ALPHA + - (1-ALPHA) * (u_long)rtrip; - /* prevent floating point overflow, limit to 1000 sec */ - if (ns->d_nstime > 1000000) - ns->d_nstime = 1000000; - } - - /* - * Record the source so that we do not use this NS again. - */ - if(qp->q_nusedns < NSMAX) { - qp->q_usedns[qp->q_nusedns++] = qs->ns; -#ifdef DEBUG - if(debug > 1) - fprintf(ddt, "NS #%d addr %s used, rtt %d\n", - n, inet_ntoa(qs->ns_addr.sin_addr), - ns->d_nstime); -#endif DEBUG - } - - /* - * Penalize those who had earlier chances but failed - * by multiplying round-trip times by BETA (>1). - * Improve nstime for unused addresses by applying GAMMA. - * The GAMMA factor makes unused entries slowly - * improve, so they eventually get tried again. - * GAMMA should be slightly less than 1. - * Watch out for records that may have timed out - * and are no longer the correct type. XXX - */ - - for (n = 0, qs = qp->q_addr; n < qp->q_naddr; n++, qs++) { - ns2 = qs->nsdata; - if (ns2 == ns) - continue; - if (ns2->d_type != T_A || - ns2->d_class != qs->ns->d_class) /* XXX */ - continue; - if (qs->stime.tv_sec) { - if (ns2->d_nstime == 0) - ns2->d_nstime = rtrip * BETA; - else - ns2->d_nstime = - ns2->d_nstime * BETA + (1-ALPHA) * rtrip; - if (ns2->d_nstime > 1000000) - ns2->d_nstime = 1000000; - } else - ns2->d_nstime = ns2->d_nstime * GAMMA; -#ifdef DEBUG - if(debug > 1) - fprintf(ddt, "NS #%d %s rtt now %d\n", n, - inet_ntoa(qs->ns_addr.sin_addr), - ns2->d_nstime); -#endif DEBUG - } - } - - /* - * Skip query section - */ - addcount = 0; - cp = msg + sizeof(HEADER); - dpp = dnptrs; - *dpp++ = msg; - if ((*cp & INDIR_MASK) == 0) - *dpp++ = cp; - *dpp = NULL; - if (hp->qdcount) { - n = dn_skipname(cp, msg + msglen); - if (n <= 0) - goto formerr; - cp += n; - GETSHORT(type, cp); - GETSHORT(class, cp); - if (cp - msg > msglen) - goto formerr; - } - - /* - * Save answers, authority, and additional records for future use. - */ - ancount = ntohs(hp->ancount); - aucount = ntohs(hp->nscount); - arcount = ntohs(hp->arcount); - nscount = 0; - tp = cp; -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"resp: ancount %d, aucount %d, arcount %d\n", - ancount, aucount, arcount); -#endif - - /* - * If there's an answer, check if it's a CNAME response; - * if no answer but aucount > 0, see if there is an NS - * or just an SOA. (NOTE: ancount might be 1 with a CNAME, - * and NS records may still be in the authority section; - * we don't bother counting them, as we only use nscount - * if ancount == 0.) - */ - if (ancount == 1 || (ancount == 0 && aucount > 0)) { - c = aucount; - do { - if (tp - msg >= msglen) - goto formerr; - n = dn_skipname(tp, msg + msglen); - if (n <= 0) - goto formerr; - tp += n; /* name */ - GETSHORT(i, tp); /* type */ - tp += sizeof(u_short); /* class */ - tp += sizeof(u_long); /* ttl */ - GETSHORT(count, tp); /* dlen */ - if (tp - msg > msglen - count) - goto formerr; - tp += count; - if (ancount && i == T_CNAME) { - cname++; -#ifdef DEBUG - if (debug) - fprintf(ddt,"CNAME - needs more processing\n"); -#endif - if (!qp->q_cmsglen) { - qp->q_cmsg = qp->q_msg; - qp->q_cmsglen = qp->q_msglen; - qp->q_msg = NULL; - qp->q_msglen = 0; - } - } - /* - * See if authority record is a nameserver. - */ - if (ancount == 0 && i == T_NS) - nscount++; - } while (--c > 0); - tp = cp; - } - - /* - * Add the info received in the response to the Data Base - */ - c = ancount + aucount + arcount; -#ifdef notdef - /* - * If the request was for a CNAME that doesn't exist, - * but the name is valid, fetch any other data for the name. - * DON'T do this now, as it will requery if data are already - * in the cache (maybe later with negative caching). - */ - if (hp->qdcount && type == T_CNAME && c == 0 && hp->rcode == NOERROR && - !qp->q_system) { -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"resp: leaving, no CNAME\n"); -#endif - /* Cause us to put it in the cache later */ - prime(class, T_ANY, qp); - - /* Nothing to store, just give user the answer */ - goto return_msg; - } -#endif /* notdef */ - - nspp = nsp; - if (qp->q_system) - dbflags = DB_NOTAUTH | DB_NODATA; - else - dbflags = DB_NOTAUTH | DB_NODATA | DB_NOHINTS; - for (i = 0; i < c; i++) { - struct databuf *ns3; - - if (cp >= msg + msglen) - goto formerr; - ns3 = 0; - if ((n = doupdate(msg, msglen, cp, 0, &ns3, dbflags)) < 0) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"resp: leaving, doupdate failed\n"); -#endif - /* return code filled in by doupdate */ - goto return_msg; - } - /* - * Remember nameservers from the authority section - * for referrals. - * (This is usually overwritten by findns below(?). XXX - */ - if (ns3 && i >= ancount && i < ancount + aucount && - nspp < &nsp[NSMAX-1]) - *nspp++ = ns3; - cp += n; - } - - if (qp->q_system && ancount) { - if (qp->q_system == PRIMING_CACHE) - check_root(); -#ifdef DEBUG - if (debug > 2) - fprintf(ddt,"resp: leaving, SYSQUERY ancount %d\n", ancount); -#endif - qremove(qp); - return; - } - - if (cp > msg + msglen) - goto formerr; - - /* - * If there are addresses and this is a local query, - * sort them appropriately for the local context. - */ - if (ancount > 1 && (lp = local(&qp->q_from)) != NULL) - sort_response(tp, ancount, lp, msg + msglen); - - /* - * An answer to a T_ANY query or a successful answer to a - * regular query with no indirection, then just return answer. - */ - if ((hp->qdcount && type == T_ANY && ancount) || - (!cname && !qp->q_cmsglen && ancount)) { -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"resp: got as much answer as there is\n"); -#endif - goto return_msg; - } - - /* - * Eventually we will want to cache this negative answer. - */ - if (ancount == 0 && nscount == 0 && - (hp->aa || fwd || class == C_ANY)) { - /* We have an authoritative NO */ -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"resp: leaving auth NO\n"); -#endif - if (qp->q_cmsglen) { - msg = (u_char *)qp->q_cmsg; - msglen = qp->q_cmsglen; - hp = (HEADER *)msg; - } - goto return_msg; - } - - /* - * All messages in here need further processing. i.e. they - * are either CNAMEs or we got referred again. - */ - count = 0; - founddata = 0; - foundname = 0; - dname = name; - if (!cname && qp->q_cmsglen && ancount) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"Cname second pass\n"); -#endif - newmsglen = qp->q_cmsglen; - bcopy(qp->q_cmsg, newmsg, newmsglen); - } else { - newmsglen = msglen; - bcopy(msg, newmsg, newmsglen); - } - hp = (HEADER *) newmsg; - hp->ancount = 0; - hp->nscount = 0; - hp->arcount = 0; - dnptrs[0] = newmsg; - dnptrs[1] = NULL; - cp = newmsg + sizeof(HEADER); - if (cname) - cp += dn_skipname(cp, newmsg + newmsglen) + QFIXEDSZ; - if ((n = dn_expand(newmsg, newmsg + newmsglen, - cp, (u_char *)dname, sizeof(name))) < 0) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"dn_expand failed\n" ); -#endif - goto servfail; - } - if (!cname) - cp += n + QFIXEDSZ; - buflen = sizeof(newmsg) - (cp - newmsg); - -try_again: -#ifdef DEBUG - if (debug) - fprintf(ddt,"resp: nlookup(%s) type=%d\n",dname, type); -#endif - fname = ""; - htp = hashtab; /* lookup relative to root */ - np = nlookup(dname, &htp, &fname, 0); -#ifdef DEBUG - if (debug) - fprintf(ddt,"resp: %s '%s' as '%s' (cname=%d)\n", - np == NULL ? "missed" : "found", dname, fname, cname); -#endif - if (np == NULL || fname != dname) - goto fetch_ns; - - foundname++; - count = cp - newmsg; - n = finddata(np, class, type, hp, &dname, &buflen, &count); - if (n == 0) - goto fetch_ns; /* NO data available */ - cp += n; - buflen -= n; - hp->ancount += count; - if (fname != dname && type != T_CNAME && type != T_ANY) { - cname++; - goto try_again; - } - founddata = 1; - -#ifdef DEBUG - if (debug >= 3) { - fprintf(ddt,"resp: foundname = %d count = %d ", foundname, count); - fprintf(ddt,"founddata = %d cname = %d\n", founddata, cname); - } -#endif - -fetch_ns: - hp->ancount = htons(hp->ancount); - /* - * Look for name servers to refer to and fill in the authority - * section or record the address for forwarding the query - * (recursion desired). - */ - switch (findns(&np, class, nsp, &count)) { - case NXDOMAIN: /* shouldn't happen */ -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"req: leaving (%s, rcode %d)\n", - dname, hp->rcode); -#endif - if (!foundname) - hp->rcode = NXDOMAIN; - if (class != C_ANY) { - hp->aa = 1; - /* - * should return SOA if founddata == 0, - * but old named's are confused by an SOA - * in the auth. section if there's no error. - */ - if (foundname == 0 && np) { - n = doaddauth(hp, cp, buflen, np, nsp[0]); - cp += n; - buflen -= n; - } - } - goto return_newmsg; - - case SERVFAIL: - goto servfail; - } - - if (founddata) { - hp = (HEADER *)newmsg; - n = add_data(np, nsp, cp, buflen); - if (n < 0) { - hp->tc = 1; - n = (-n); - } - cp += n; - buflen -= n; - hp->nscount = htons((u_short)count); - goto return_newmsg; - } - - /* - * If we get here, we don't have the answer yet and are about - * to iterate to try and get it. First, infinite loop avoidance. - */ - if (qp->q_nqueries++ > MAXQUERIES) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"resp: MAXQUERIES exceeded (%s, class %d, type %d)\n", - dname, class, type); -#endif - syslog(LOG_NOTICE, - "MAXQUERIES exceeded, possible data loop in resolving (%s)", - dname); - goto servfail; - } - - /* Reset the query control structure */ - qp->q_naddr = 0; - qp->q_curaddr = 0; - qp->q_fwd = fwdtab; - if (nslookup(nsp, qp) == 0) { -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"resp: no addrs found for NS's\n"); -#endif - goto servfail; - } - for (n = 0; n < qp->q_naddr; n++) - qp->q_addr[n].stime.tv_sec = 0; - if (!qp->q_fwd) - qp->q_addr[0].stime = tt; - if (cname) { - if (qp->q_cname++ == MAXCNAMES) { -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"resp: leaving, MAXCNAMES exceeded\n"); -#endif - goto servfail; - } -#ifdef DEBUG - if (debug) - fprintf(ddt,"q_cname = %d\n",qp->q_cname); - if (debug >= 3) - fprintf(ddt,"resp: building recursive query; nslookup\n"); -#endif - if (qp->q_msg) - (void) free(qp->q_msg); - if ((qp->q_msg = malloc(BUFSIZ)) == NULL) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"resp: malloc error\n"); -#endif - goto servfail; - } - qp->q_msglen = res_mkquery(QUERY, dname, class, - type, (char *)NULL, 0, NULL, qp->q_msg, BUFSIZ); - hp = (HEADER *) qp->q_msg; - hp->rd = 0; - } else - hp = (HEADER *)qp->q_msg; - hp->id = qp->q_nsid = htons((u_short)++nsid); - if (qp->q_fwd) - hp->rd = 1; - unsched(qp); - schedretry(qp, retrytime(qp)); -#ifdef DEBUG - if (debug) - fprintf(ddt,"resp: forw -> %s %d (%d) nsid=%d id=%d %dms\n", - inet_ntoa(Q_NEXTADDR(qp,0)->sin_addr), - ds, ntohs(Q_NEXTADDR(qp,0)->sin_port), - ntohs(qp->q_nsid), ntohs(qp->q_id), - qp->q_addr[0].nsdata->d_nstime); - if ( debug >= 10) - fp_query((char *)msg, ddt); -#endif - if (sendto(ds, qp->q_msg, qp->q_msglen, 0, - (struct sockaddr *)Q_NEXTADDR(qp,0), - sizeof(struct sockaddr_in)) < 0) { -#ifdef DEBUG - if (debug >= 5) - fprintf(ddt, "sendto error = %d\n", errno); -#endif - } - hp->rd = 0; /* leave set to 0 for dup detection */ -#ifdef STATS - stats[S_OUTPKTS].cnt++; -#endif -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"resp: Query sent.\n"); -#endif - return; - -formerr: -#ifdef DEBUG - if (debug) - fprintf(ddt,"FORMERR resp() from %s size err %d, msglen %d\n", - inet_ntoa(from_addr.sin_addr), - cp-msg, msglen); -#endif - syslog(LOG_INFO, "Malformed response from %s\n", - inet_ntoa(from_addr.sin_addr)); -#ifdef STATS - stats[S_RESPFORMERR].cnt++; -#endif - return; - -return_msg: -#ifdef STATS - stats[S_RESPOK].cnt++; -#endif - /* The "standard" return code */ - hp->qr = 1; - hp->id = qp->q_id; - hp->rd = 1; - hp->ra = 1; - (void) send_msg(msg, msglen, qp); - qremove(qp); - return; - -return_newmsg: -#ifdef STATS - stats[S_RESPOK].cnt++; -#endif - if (addcount) { - n = doaddinfo(hp, cp, buflen); - cp += n; - buflen -= n; - } - - hp->id = qp->q_id; - hp->rd = 1; - hp->ra = 1; - hp->qr = 1; - (void) send_msg(newmsg, cp - newmsg, qp); - qremove(qp); - return; - -servfail: -#ifdef STATS - stats[S_RESPFAIL].cnt++; -#endif - hp = (HEADER *)(cname ? qp->q_cmsg : qp->q_msg); - hp->rcode = SERVFAIL; - hp->id = qp->q_id; - hp->rd = 1; - hp->ra = 1; - hp->qr = 1; - (void) send_msg((char *)hp, (cname ? qp->q_cmsglen : qp->q_msglen), qp); - qremove(qp); - return; -} - -/* - * Decode the resource record 'rrp' and update the database. - * If savens is true, record pointer for forwarding queries a second time. - */ -doupdate(msg, msglen, rrp, zone, savens, flags) - char *msg; - u_char *rrp; - struct databuf **savens; - int msglen, zone, flags; -{ - register u_char *cp; - register int n; - int class, type, dlen, n1; - u_long ttl; - struct databuf *dp; - char dname[MAXDNAME]; - u_char *cp1; - u_char data[BUFSIZ]; - register HEADER *hp = (HEADER *) msg; -#ifdef ALLOW_UPDATES - int zonenum; -#endif - -#ifdef DEBUG - if (debug > 2) - fprintf(ddt,"doupdate(zone %d, savens %x, flags %x)\n", - zone, savens, flags); -#endif - - cp = rrp; - if ((n = dn_expand((u_char *)msg, (u_char *)msg + msglen, cp, - (u_char *)dname, sizeof(dname))) < 0) { - hp->rcode = FORMERR; - return (-1); - } - cp += n; - GETSHORT(type, cp); - GETSHORT(class, cp); - GETLONG(ttl, cp); - GETSHORT(dlen, cp); -#ifdef DEBUG - if (debug > 2) - fprintf(ddt,"doupdate: dname %s type %d class %d ttl %d\n", - dname, type, class, ttl); -#endif - /* - * Convert the resource record data into the internal - * database format. - */ - switch (type) { - case T_A: - case T_WKS: - case T_HINFO: - case T_UINFO: - case T_UID: - case T_GID: - case T_TXT: -#ifdef ALLOW_T_UNSPEC - case T_UNSPEC: -#endif ALLOW_T_UNSPEC - cp1 = cp; - n = dlen; - cp += n; - break; - - case T_CNAME: - case T_MB: - case T_MG: - case T_MR: - case T_NS: - case T_PTR: - if ((n = dn_expand((u_char *)msg, (u_char *)msg + msglen, - cp, data, sizeof(data))) < 0) { - hp->rcode = FORMERR; - return (-1); - } - cp += n; - cp1 = data; - n = strlen((char *)data) + 1; - break; - - case T_MINFO: - case T_SOA: - if ((n = dn_expand((u_char *)msg, (u_char *)msg + msglen, - cp, data, sizeof(data))) < 0) { - hp->rcode = FORMERR; - return (-1); - } - cp += n; - cp1 = data + (n = strlen((char *)data) + 1); - n1 = sizeof(data) - n; - if (type == T_SOA) - n1 -= 5 * sizeof(u_long); - if ((n = dn_expand((u_char *)msg, (u_char *)msg + msglen, - cp, cp1, n1)) < 0) { - hp->rcode = FORMERR; - return (-1); - } - cp += n; - cp1 += strlen((char *)cp1) + 1; - if (type == T_SOA) { - bcopy(cp, cp1, n = 5 * sizeof(u_long)); - cp += n; - cp1 += n; - } - n = cp1 - data; - cp1 = data; - break; - - case T_MX: - /* grab preference */ - bcopy(cp,data,sizeof(u_short)); - cp1 = data + sizeof(u_short); - cp += sizeof(u_short); - - /* get name */ - if ((n = dn_expand((u_char *)msg, (u_char *)msg + msglen, - cp, cp1, sizeof(data) - sizeof(u_short))) < 0) - return(-1); - cp += n; - - /* compute end of data */ - cp1 += strlen((char *)cp1) + 1; - /* compute size of data */ - n = cp1 - data; - cp1 = data; - break; - - default: -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"unknown type %d\n", type); -#endif - return ((cp - rrp) + dlen); - } - if (n > MAXDATA) { -#ifdef DEBUG - if (debug) - fprintf(ddt, - "update type %d: %d bytes is too much data\n", - type, n); -#endif - hp->rcode = NOCHANGE; /* XXX - FORMERR ??? */ - return(-1); - } - -#ifdef ALLOW_UPDATES - /* - * If this is a dynamic update request, process it specially; else, - * execute normal update code. - */ - switch(hp->opcode) { - - /* For UPDATEM and UPDATEMA, do UPDATED/UPDATEDA followed by UPDATEA */ - case UPDATEM: - case UPDATEMA: - - /* - * The named code for UPDATED and UPDATEDA is the same except that for - * UPDATEDA we we ignore any data that was passed: we just delete all - * RRs whose name, type, and class matches - */ - case UPDATED: - case UPDATEDA: - if (type == T_SOA) { /* Not allowed */ -#ifdef DEBUG - if (debug) - fprintf(ddt, "UDPATE: REFUSED - SOA delete\n"); -#endif - hp->rcode = REFUSED; - return(-1); - } - /* - * Don't check message length if doing UPDATEM/UPDATEMA, - * since the whole message wont have been demarshalled until - * we reach the code for UPDATEA - */ - if ( (hp->opcode == UPDATED) || (hp->opcode == UPDATEDA) ) { - if (cp != (u_char *)(msg + msglen)) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"FORMERR UPDATE message length off\n"); -#endif - hp->rcode = FORMERR; - return(-1); - } - } - if ((zonenum = findzone(dname, class)) == 0) { - hp->rcode = NXDOMAIN; - return(-1); - } - if (zones[zonenum].z_state & Z_DYNADDONLY) { - hp->rcode = NXDOMAIN; - return(-1); - } - if ( (hp->opcode == UPDATED) || (hp->opcode == UPDATEM) ) { - /* Make a dp for use in db_update, as old dp */ - dp = savedata(class, type, 0, cp1, n); - dp->d_zone = zonenum; - n = db_update(dname, dp, NULL, DB_MEXIST | DB_DELETE, - hashtab); - if (n != OK) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"UPDATE: db_update failed\n"); -#endif DEBUG - free( (struct databuf *) dp); - hp->rcode = NOCHANGE; - return(-1); - } - } else { /* UPDATEDA or UPDATEMA */ - int DeletedOne = 0; - /* Make a dp for use in db_update, as old dp */ - dp = savedata(class, type, 0, NULL, 0); - dp->d_zone = zonenum; - do { /* Loop and delete all matching RR(s) */ - n = db_update(dname, dp, NULL, DB_DELETE, - hashtab); - if (n != OK) - break; - DeletedOne++; - } while (1); - free( (struct databuf *) dp); - /* Ok for UPDATEMA not to have deleted any RRs */ - if (!DeletedOne && hp->opcode == UPDATEDA) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"UPDATE: db_update failed\n"); -#endif DEBUG - hp->rcode = NOCHANGE; - return(-1); - } - } - if ( (hp->opcode == UPDATED) || (hp->opcode == UPDATEDA) ) - return (cp - rrp);; - /* - * Else unmarshal the RR to be added and continue on to - * UPDATEA code for UPDATEM/UPDATEMA - */ - if ((n = - dn_expand(msg, msg+msglen, cp, dname, sizeof(dname))) < 0) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"FORMERR UPDATE expand name failed\n"); -#endif - hp->rcode = FORMERR; - return(-1); - } - cp += n; - GETSHORT(type, cp); - GETSHORT(class, cp); - GETLONG(ttl, cp); - GETSHORT(n, cp); - cp1 = cp; -/**** XXX - need bounds checking here ****/ - cp += n; - - case UPDATEA: - if (n > MAXDATA) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"UPDATE: too much data\n"); -#endif - hp->rcode = NOCHANGE; - return(-1); - } - if (cp != (u_char *)(msg + msglen)) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"FORMERR UPDATE message length off\n"); -#endif - hp->rcode = FORMERR; - return(-1); - } - if ((zonenum = findzone(dname, class)) == 0) { - hp->rcode = NXDOMAIN; - return(-1); - } - if (zones[zonenum].z_state & Z_DYNADDONLY) { - struct hashbuf *htp = hashtab; - char *fname; - if (nlookup(dname, &htp, &fname, 0) && - !strcmp(dname, fname)) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"refusing add of existing name\n"); -#endif - hp->rcode = REFUSED; - return(-1); - } - } - dp = savedata(class, type, ttl, cp1, n); - dp->d_zone = zonenum; - if ((n = db_update(dname, NULL, dp, DB_NODATA, - hashtab)) != OK) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"UPDATE: db_update failed\n"); -#endif - hp->rcode = NOCHANGE; - return (-1); - } - else - return (cp - rrp); - } -#endif ALLOW_UPDATES - - if (zone == 0) - ttl += tt.tv_sec; - dp = savedata(class, type, ttl, cp1, n); - dp->d_zone = zone; - if ((n = db_update(dname, dp, dp, flags, hashtab)) < 0) { -#ifdef DEBUG - if (debug && (n != DATAEXISTS)) - fprintf(ddt,"update failed (%d)\n", n); - else if (debug >= 3) - fprintf(ddt,"update failed (DATAEXISTS)\n"); -#endif - (void) free((char *)dp); - } else if (type == T_NS && savens != NULL) - *savens = dp; - return (cp - rrp); -} - -send_msg(msg, msglen, qp) - char *msg; - int msglen; - struct qinfo *qp; -{ - extern struct qinfo *qhead; -#ifdef DEBUG - struct qinfo *tqp; -#endif DEBUG - - if (qp->q_system) - return(1); -#ifdef DEBUG - if (debug) { - fprintf(ddt,"send_msg -> %s (%s %d %d) id=%d\n", - inet_ntoa(qp->q_from.sin_addr), - qp->q_stream == QSTREAM_NULL ? "UDP" : "TCP", - qp->q_stream == QSTREAM_NULL ? qp->q_dfd - : qp->q_stream->s_rfd, - ntohs(qp->q_from.sin_port), - ntohs(qp->q_id)); - } - if (debug>4) - for (tqp = qhead; tqp!=QINFO_NULL; tqp = tqp->q_link) { - fprintf(ddt, "qp %x q_id: %d q_nsid: %d q_msglen: %d ", - tqp, tqp->q_id,tqp->q_nsid,tqp->q_msglen); - fprintf(ddt,"q_naddr: %d q_curaddr: %d\n", tqp->q_naddr, - tqp->q_curaddr); - fprintf(ddt,"q_next: %x q_link: %x\n", qp->q_next, - qp->q_link); - } - if (debug >= 10) - fp_query(msg, ddt); -#endif DEBUG - if (qp->q_stream == QSTREAM_NULL) { - if (sendto(qp->q_dfd, msg, msglen, 0, - (struct sockaddr *)&qp->q_from, sizeof(qp->q_from)) < 0) { -#ifdef DEBUG - if (debug) - fprintf(ddt, "sendto error errno= %d\n",errno); -#endif - return(1); - } -#ifdef STATS - stats[S_OUTPKTS].cnt++; -#endif - } else { - (void) writemsg(qp->q_stream->s_rfd, msg, msglen); - sq_done(qp->q_stream); - } - return(0); -} - -prime(class, type, oqp) - int class, type; - register struct qinfo *oqp; -{ - char dname[BUFSIZ]; - - if (oqp->q_msg == NULL) - return; - if (dn_expand((u_char *)oqp->q_msg, - (u_char *)oqp->q_msg + oqp->q_msglen, - (u_char *)oqp->q_msg + sizeof(HEADER), (u_char *)dname, - sizeof(dname)) < 0) - return; -#ifdef DEBUG - if (debug >= 2) - fprintf(ddt,"prime: %s\n", dname); -#endif - (void) sysquery(dname, class, type); -} - - -prime_cache() -{ - register struct qinfo *qp; - -#ifdef DEBUG - if (debug) - fprintf(ddt,"prime_cache: priming = %d\n", priming); -#endif -#ifdef STATS - stats[S_PRIMECACHE].cnt++; -#endif - if (!priming && fcachetab->h_tab[0] != NULL && !forward_only) { - priming++; - if ((qp = sysquery("", C_IN, T_NS)) == NULL) - priming = 0; - else - qp->q_system = PRIMING_CACHE; - } - needs_prime_cache = 0; - return; -} - -struct qinfo * -sysquery(dname, class, type) - char *dname; - int class, type; -{ - extern struct qinfo *qhead; - extern int nsid; - register struct qinfo *qp, *oqp; - register HEADER *hp; - struct namebuf *np; - struct databuf *nsp[NSMAX]; - struct hashbuf *htp; - char *fname; - int count; - -#ifdef DEBUG - if (debug > 2) - fprintf(ddt,"sysquery(%s, %d, %d)\n", dname, class, type); -#endif -#ifdef STATS - stats[S_SYSQUERIES].cnt++; -#endif - htp = hashtab; - if (priming && dname[0] == '\0') - np = NULL; - else if ((np = nlookup(dname, &htp, &fname, 1)) == NULL) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"sysquery: nlookup error on %s?\n", dname); -#endif - return(0); - } - - switch (findns(&np, class, nsp, &count)) { - case NXDOMAIN: - case SERVFAIL: -#ifdef DEBUG - if (debug) - fprintf(ddt,"sysquery: findns error on %s?\n", dname); -#endif - return(0); - } - - /* build new qinfo struct */ - qp = qnew(); - qp->q_cmsg = qp->q_msg = NULL; - qp->q_dfd = ds; - qp->q_fwd = fwdtab; - qp->q_system++; - - if ((qp->q_msg = malloc(BUFSIZ)) == NULL) { - qfree(qp); - return(0); - } - qp->q_msglen = res_mkquery(QUERY, dname, class, - type, (char *)NULL, 0, NULL, qp->q_msg, BUFSIZ); - hp = (HEADER *) qp->q_msg; - hp->id = qp->q_nsid = htons((u_short)++nsid); - hp->rd = (qp->q_fwd ? 1 : 0); - - /* First check for an already pending query for this data */ - for (oqp = qhead; oqp!=QINFO_NULL; oqp = oqp->q_link) { - if (oqp != qp && oqp->q_msglen == qp->q_msglen && - bcmp((char *)oqp->q_msg+2, qp->q_msg+2, qp->q_msglen-2) == 0) { -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt, "sysquery: duplicate\n"); -#endif - qfree(qp); - return(0); - } - } - - if (nslookup(nsp, qp) == 0) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"resp: no addrs found for NS's\n"); -#endif - qfree(qp); - return(0); - } - - schedretry(qp, retrytime(qp)); - if (qp->q_fwd == 0) - qp->q_addr[0].stime = tt; - -#ifdef DEBUG - if (debug) - fprintf(ddt,"sysquery: send -> %s %d (%d), nsid=%d id=%d %dms\n", - inet_ntoa(Q_NEXTADDR(qp,0)->sin_addr), - qp->q_dfd, ntohs(Q_NEXTADDR(qp,0)->sin_port), - ntohs(qp->q_nsid), ntohs(qp->q_id), - qp->q_addr[0].nsdata->d_nstime); - if ( debug >= 10) - fp_query(qp->q_msg, ddt); -#endif - if (sendto(qp->q_dfd, qp->q_msg, qp->q_msglen, 0, - (struct sockaddr *)Q_NEXTADDR(qp,0), - sizeof(struct sockaddr_in)) < 0){ -#ifdef DEBUG - if (debug) - fprintf(ddt, "sendto error errno= %d\n",errno); -#endif - } -#ifdef STATS - stats[S_OUTPKTS].cnt++; -#endif - return(qp); -} - -/* - * Check the list of root servers after receiving a response - * to a query for the root servers. - */ -check_root() -{ - register struct databuf *dp, *pdp; - register struct namebuf *np; - int count = 0; - - priming = 0; - for (np = hashtab->h_tab[0]; np != NULL; np = np->n_next) - if (np->n_dname[0] == '\0') - break; - if (np == NULL) { - syslog(LOG_ERR, "check_root: Can't find root!\n"); - return; - } - for (dp = np->n_data; dp != NULL; dp = dp->d_next) - if (dp->d_type == T_NS) - count++; -#ifdef DEBUG - if (debug) - fprintf(ddt,"%d root servers\n", count); -#endif - if (count < MINROOTS) { - syslog(LOG_WARNING, - "check_root: %d root servers after query to root server < min", - count); - return; - } - pdp = NULL; - dp = np->n_data; - while (dp != NULL) { - if (dp->d_type == T_NS && dp->d_zone == 0 && - dp->d_ttl < tt.tv_sec) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"deleting old root server '%s'\n", - dp->d_data); -#endif - dp = rm_datum(dp, np, pdp); - /* SHOULD DELETE FROM HINTS ALSO */ - continue; - } - pdp = dp; - dp = dp->d_next; - } - check_ns(); -} - -/* - * Check the root to make sure that for each NS record we have a A RR - */ -check_ns() -{ - register struct databuf *dp, *tdp; - register struct namebuf *np, *tnp; - struct hashbuf *htp; - char *dname; - int found_arr; - char *fname; - time_t curtime; - -#ifdef DEBUG - if (debug >= 2) - fprintf(ddt,"check_ns()\n"); -#endif -#ifdef STATS - stats[S_CHECKNS].cnt++; -#endif - - curtime = (u_long) tt.tv_sec; - for (np = hashtab->h_tab[0]; np != NULL; np = np->n_next) { - if (np->n_dname[0] != 0) - continue; - for (dp = np->n_data; dp != NULL; dp = dp->d_next) { - if (dp->d_type != T_NS) - continue; - - /* look for A records */ - dname = dp->d_data; - htp = hashtab; - tnp = nlookup(dname, &htp, &fname, 0); - if (tnp == NULL || fname != dname) { -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"check_ns: %s: not found %s %x\n", - dname, fname, tnp); -#endif - (void) sysquery(dname, dp->d_class, T_A); - continue; - } - /* look for name server addresses */ - found_arr = 0; - for (tdp=tnp->n_data; tdp!=NULL; tdp=tdp->d_next) { - if (tdp->d_type != T_A || - tdp->d_class != dp->d_class) - continue; - if ((tdp->d_zone == 0) && - (tdp->d_ttl < curtime)) { -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"check_ns: stale entry '%s'\n", - tnp->n_dname); -#endif - /* Cache invalidate the address RR's */ - delete_all(tnp, dp->d_class, T_A); - found_arr = 0; - break; - } - found_arr++; - } - if (!found_arr) - (void) sysquery(dname, dp->d_class, T_A); - } - } -} - -#define MAXCLASS 255 /* belongs elsewhere */ -int norootlogged[MAXCLASS]; - -/* - * Find NS's or an SOA for the given dname (np) and fill in the - * nsp array. Returns OK on success, and SERVFAIL on error. - * We return NXDOMAIN to indicate we are authoritative. - */ -findns(npp, class, nsp, countp) - register struct namebuf **npp; - struct databuf **nsp; - int *countp; -{ - register struct namebuf *np = *npp; - register struct databuf *dp; - register struct databuf **nspp; - struct hashbuf *htp = hashtab; - - if (priming && (np == NULL || np->n_dname[0] == '\0')) - htp = fcachetab; -try_again: - if (htp == fcachetab) - needs_prime_cache = 1; - while (np == NULL && htp != NULL) { -#ifdef DEBUG - if (debug > 2) - fprintf(ddt, "findns: using %s\n", htp == hashtab ? - "cache" : "hints"); -#endif - for (np = htp->h_tab[0]; np != NULL; np = np->n_next) - if (np->n_dname[0] == '\0') - break; - htp = (htp == hashtab ? fcachetab : NULL); /* Fallback */ - } - while(np != NULL) { -#ifdef DEBUG - if (debug >= 5) - fprintf(ddt, "findns: np 0x%x\n", np); -#endif - /* Look first for SOA records. */ - for (dp = np->n_data; dp != NULL; dp = dp->d_next) { - if (dp->d_zone != 0 && match(dp, class, T_SOA)) { -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"findns: SOA found\n"); -#endif - if (zones[dp->d_zone].z_auth) { - *npp = np; - nsp[0] = dp; - return(NXDOMAIN); - } else - return (SERVFAIL); - } - } - - /* If no SOA records, look for NS records. */ - nspp = &nsp[0]; - *nspp = NULL; - for (dp = np->n_data; dp != NULL; dp = dp->d_next) { - if (dp->d_type != T_NS || - (dp->d_class != class && class != C_ANY)) - continue; - /* - * Don't use records that may become invalid to - * reference later when we do the rtt computation. - * Never delete our safety-belt information! - */ - if ((dp->d_zone == 0) && - (dp->d_ttl < (tt.tv_sec+900)) && - !(dp->d_flags & DB_F_HINT)) { -#ifdef DEBUG - if (debug) - fprintf(ddt,"findns: stale entry '%s'\n", - np->n_dname); -#endif - /* Cache invalidate the NS RR's */ - if (dp->d_ttl < tt.tv_sec) - delete_all(np, class, T_NS); - goto try_parent; - } - if (nspp < &nsp[NSMAX-1]) - *nspp++ = dp; - } - - *countp = nspp - nsp; - if (*countp > 0) { -#ifdef DEBUG - if (debug >= 3) - fprintf(ddt,"findns: %d NS's added for '%s'\n", - *countp, np->n_dname); -#endif - *nspp = NULL; - *npp = np; - return(OK); /* Success, got some NS's */ - } -try_parent: - np = np->n_parent; - } - if (htp) - goto try_again; -#ifdef DEBUG - if (debug) - fprintf(ddt, "findns: No root nameservers for class %d?\n", - class); -#endif - if ((unsigned)class < MAXCLASS && norootlogged[class] == 0) { - norootlogged[class] = 1; - syslog(LOG_ERR, "No root nameservers for class %d\n", class); - } - return(SERVFAIL); -} - -/* - * Extract RR's from the given node that match class and type. - * Return number of bytes added to response. - * If no matching data is found, then 0 is returned. - */ -finddata(np, class, type, hp, dnamep, lenp, countp) - struct namebuf *np; - int class, type; - register HEADER *hp; - char **dnamep; - int *lenp, *countp; -{ - register struct databuf *dp; - register char *cp; - int buflen, n, count = 0, foundstale = 0; - - buflen = *lenp; - cp = ((char *)hp) + *countp; - for (dp = np->n_data; dp != NULL; dp = dp->d_next) { - if (!wanted(dp, class, type)) { - if (type == T_CNAME && class == dp->d_class) { - /* any data means no CNAME exists */ - *countp = 0; - return(0); - } - continue; - } - if (stale(dp)) { - /* - * Don't use stale data. - * Would like to call delete_all here - * and continue, but the data chain would get - * munged; can't restart, as make_rr has side - * effects (leaving pointers in dnptr). - * Just skip this entry for now - * and call delete_all at the end. - */ -#ifdef DEBUG - if (debug >=3) - fprintf(ddt,"finddata: stale entry '%s'\n",np->n_dname); -#endif - if (dp->d_zone == 0) - foundstale++; - continue; - } - if ((n = make_rr(*dnamep, dp, cp, buflen, 1)) < 0) { - hp->tc = 1; - *countp = count; - return(*lenp - buflen); - } - - cp += n; - buflen -= n; - count++; -#ifdef notdef - /* this isn't right for glue records, aa is set in ns_req */ - if (dp->d_zone && zones[dp->d_zone].z_auth && class != C_ANY) - hp->aa = 1; /* XXX */ -#endif - if (dp->d_type == T_CNAME) { - if (type != T_ANY) { /* or T_NS? */ - *dnamep = dp->d_data; - if (dp->d_zone && zones[dp->d_zone].z_auth && - class != C_ANY) /* XXX */ - hp->aa = 1; /* XXX */ - } - break; - } - } - /* - * Cache invalidate the other RR's of same type - * if some have timed out - */ - if (foundstale) - delete_all(np, class, type); -#ifdef DEBUG - if (debug >=3) - fprintf(ddt,"finddata: added %d class %d type %d RRs\n", - count, class, type); -#endif - *countp = count; - return(*lenp - buflen); -} - -/* - * Do we want this data record based on the class and type? - */ -wanted(dp, class, type) - struct databuf *dp; - int class, type; -{ - -#ifdef DEBUG - if (debug > 3) - fprintf(ddt,"wanted(%x, %d, %d) %d, %d\n", dp, class, type, - dp->d_class, dp->d_type); -#endif - - if (dp->d_class != class && class != C_ANY) - return (0); - if (type == dp->d_type) - return (1); - switch (dp->d_type) { - case T_ANY: - case T_CNAME: - return (1); - } - switch (type) { - case T_ANY: - return (1); - - case T_MAILB: - switch (dp->d_type) { - case T_MR: - case T_MB: - case T_MG: - case T_MINFO: - return (1); - } - break; - - case T_AXFR: - if (dp->d_type == T_SOA) - return (1); - } - return (0); -} - -/* - * Add RR entries from dpp array to a query/response. - * Return the number of bytes added or negative the amount - * added if truncation was required. Typically you are - * adding NS records to a response. - */ -add_data(np, dpp, cp, buflen) - struct namebuf *np; - struct databuf **dpp; - register char *cp; - int buflen; -{ - register struct databuf *dp; - char dname[MAXDNAME]; - register int n, count = 0; - - getname(np, dname, sizeof(dname)); - for(dp = *dpp++; dp != NULL; dp = *dpp++) { - if (stale(dp)) - continue; /* ignore old cache entry */ - if ((n = make_rr(dname, dp, cp, buflen, 1)) < 0) - return(-count); /* Truncation */ - cp += n; - buflen -= n; - count += n; - } - return(count); -} - -/* - * This is best thought of as a "cache invalidate" function. - * It is called whenever a piece of data is determined to have - * timed out. It is better to have no information, than to - * have partial information you pass off as complete. - */ -delete_all(np, class, type) -register struct namebuf *np; -int class, type; -{ - register struct databuf *dp, *pdp; - -#ifdef DEBUG - if (debug > 2) - fprintf(ddt,"delete_all: '%s' 0x%x class %d type %d\n", - np->n_dname, np, class, type); -#endif - pdp = NULL; - dp = np->n_data; - while (dp != NULL) { - if ((dp->d_zone == 0) && !(dp->d_flags & DB_F_HINT) - && match(dp, class, type)) { - dp = rm_datum(dp, np, pdp); - continue; - } - pdp = dp; - dp = dp->d_next; - } -} diff --git a/usr.sbin/named/ns_sort.c b/usr.sbin/named/ns_sort.c deleted file mode 100644 index ea30eb5c3f5..00000000000 --- a/usr.sbin/named/ns_sort.c +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright (c) 1986, 1990 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -/*static char sccsid[] = "from: @(#)ns_sort.c 4.10 (Berkeley) 3/3/91";*/ -static char rcsid[] = "$Id: ns_sort.c,v 1.1 1995/10/18 08:47:51 deraadt Exp $"; -#endif /* not lint */ - -#include <stdio.h> -#include <sys/types.h> -#include <sys/time.h> -#include <sys/socket.h> -#include <sys/file.h> -#include <netinet/in.h> -#include <syslog.h> -#include <arpa/nameser.h> -#include <resolv.h> -#include "ns.h" -#include "db.h" - -extern int debug; -extern FILE *ddt; - -struct netinfo* -local(from) - struct sockaddr_in *from; -{ - extern struct netinfo *nettab, netloop, **enettab; - struct netinfo *ntp; - - if (from->sin_addr.s_addr == netloop.my_addr.s_addr) - return( &netloop); - for (ntp = nettab; ntp != *enettab; ntp = ntp->next) { - if (ntp->net == (from->sin_addr.s_addr & ntp->mask)) - return(ntp); - } - return(NULL); -} - - -sort_response(cp, ancount, lp, eom) - register char *cp; - register int ancount; - struct netinfo *lp; - u_char *eom; -{ - register struct netinfo *ntp; - extern struct netinfo *nettab; - -#ifdef DEBUG - if (debug > 2) - fprintf(ddt,"sort_response(%d)\n", ancount); -#endif DEBUG - if (ancount > 1) { - if (sort_rr(cp, ancount, lp, eom)) - return; - for (ntp = nettab; ntp != NULL; ntp = ntp->next) { - if ((ntp->net == lp->net) && (ntp->mask == lp->mask)) - continue; - if (sort_rr(cp, ancount, ntp, eom)) - break; - } - } -} - -int -sort_rr(cp, count, ntp, eom) - register u_char *cp; - int count; - register struct netinfo *ntp; - u_char *eom; -{ - int type, class, dlen, n, c; - struct in_addr inaddr; - u_char *rr1; - -#ifdef DEBUG - if (debug > 2) { - inaddr.s_addr = ntp->net; - fprintf(ddt,"sort_rr( x%x, %d, %s)\n",cp, count, - inet_ntoa(inaddr)); - } -#endif DEBUG - rr1 = NULL; - for (c = count; c > 0; --c) { - n = dn_skipname(cp, eom); - if (n < 0) - return (1); /* bogus, stop processing */ - cp += n; - if (cp + QFIXEDSZ > eom) - return (1); - GETSHORT(type, cp); - GETSHORT(class, cp); - cp += sizeof(u_long); - GETSHORT(dlen, cp); - if (dlen > eom - cp) - return (1); /* bogus, stop processing */ - switch (type) { - case T_A: - switch (class) { - case C_IN: - case C_HS: - bcopy(cp, (char *)&inaddr, sizeof(inaddr)); - if (rr1 == NULL) - rr1 = cp; - if ((ntp->mask & inaddr.s_addr) == ntp->net) { -#ifdef DEBUG - if (debug > 1) { - fprintf(ddt,"net %s best choice\n", - inet_ntoa(inaddr)); - } -#endif DEBUG - if (rr1 != cp) { - bcopy(rr1, cp, sizeof(inaddr)); - bcopy((char *)&inaddr, rr1, sizeof(inaddr)); - } - return(1); - } - break; - } - break; - } - cp += dlen; - } - return(0); -} diff --git a/usr.sbin/named/ns_stats.c b/usr.sbin/named/ns_stats.c deleted file mode 100644 index 9a222f312e6..00000000000 --- a/usr.sbin/named/ns_stats.c +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (c) 1986 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -/*static char sccsid[] = "from: @(#)ns_stats.c 4.10 (Berkeley) 6/27/90";*/ -static char rcsid[] = "$Id: ns_stats.c,v 1.1 1995/10/18 08:47:51 deraadt Exp $"; -#endif /* not lint */ - -/**************************************************************************/ -/* simple monitoring of named behavior */ -/* dumps a bunch of values into a well-know file */ -/* */ -/**************************************************************************/ - -#ifdef STATS - -#include <sys/param.h> -#include <sys/time.h> -#include <netinet/in.h> -#include <stdio.h> -#include <syslog.h> -#include <arpa/nameser.h> -#include "ns.h" -#include "pathnames.h" - -#ifdef STATSFILE -char *statsfile = STATSFILE; -#else -char *statsfile = _PATH_STATS; -#endif /* STATSFILE */ - -extern time_t boottime, resettime; -extern int needStatsDump; - -/* - * General statistics gathered - */ -/* The position in this table must agree with the defines in ns.h */ -struct stats stats[S_NSTATS] = { - { 0, "input packets" }, - { 0, "output packets" }, - { 0, "queries" }, - { 0, "iqueries" }, - { 0, "duplicate queries" }, - { 0, "responses" }, - { 0, "duplicate responses" }, - { 0, "OK answers" }, - { 0, "FAIL answers" }, - { 0, "FORMERR answers" }, - { 0, "system queries" }, - { 0, "prime cache calls" }, - { 0, "check_ns calls" }, - { 0, "bad responses dropped" }, - { 0, "martian responses" }, -}; - -/* - * Statistics for queries (by type) - */ -unsigned long typestats[T_ANY+1]; -char *typenames[T_ANY+1] = { - /* 5 types per line */ - "Unknown", "A", "NS", "invalid(MD)", "invalid(MF)", - "CNAME", "SOA", "MB", "MG", "MR", - "NULL", "WKS", "PTR", "HINFO", "MINFO", - "MX", "TXT", 0, 0, 0, - /* 20 per line */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - /* 100 */ - "UINFO", "UID", "GID", "UNSPEC", 0, 0, 0, 0, 0, 0, - /* 110 */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - /* 120 */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - /* 200 */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - /* 240 */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - /* 250 */ - 0, 0, "AXFR", "MAILB", "MAILA", "ANY" -}; - -ns_stats() -{ - time_t timenow; - register FILE *f; - register int i; - - if ((f = fopen(statsfile,"a")) == 0) - { -#ifdef DEBUG - if (debug) - fprintf(ddt,"can't open stat file, \"%s\"\n",statsfile); -#endif - syslog(LOG_ERR, "cannot open stat file, \"%s\"\n",statsfile); - return; - } - - time(&timenow); - fprintf(f, "### %s", ctime(&timenow)); - fprintf(f, "%d\ttime since boot (secs)\n", timenow - boottime); - fprintf(f, "%d\ttime since reset (secs)\n", timenow - resettime); - - /* general statistics */ - for (i = 0; i < S_NSTATS; i++) - fprintf(f,"%lu\t%s\n", stats[i].cnt, stats[i].description); - - /* query type statistics */ - fprintf(f, "%d\tUnknown query types\n", typestats[0]); - for(i=1; i < T_ANY+1; i++) - if (typestats[i]) - if (typenames[i]) - fprintf(f, "%lu\t%s queries\n", typestats[i], - typenames[i]); - else - fprintf(f, "%lu\ttype %d queries\n", - typestats[i], i); - (void) fclose(f); -} -#endif STATS diff --git a/usr.sbin/named/pathnames.h b/usr.sbin/named/pathnames.h deleted file mode 100644 index 4726d00dc21..00000000000 --- a/usr.sbin/named/pathnames.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 1989 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * from: @(#)pathnames.h 5.4 (Berkeley) 6/1/90 - * $Id: pathnames.h,v 1.1 1995/10/18 08:47:51 deraadt Exp $ - */ - - -#define _PATH_BOOT "/etc/named.boot" - -#if defined(BSD) && BSD >= 198810 -#include <paths.h> -#define _PATH_XFER "/usr/libexec/named-xfer" -#define _PATH_DEBUG "/var/tmp/named.run" -#define _PATH_DUMPFILE "/var/tmp/named_dump.db" -#define _PATH_PIDFILE "/var/run/named.pid" -#define _PATH_STATS "/var/tmp/named.stats" -#define _PATH_TMPXFER "/var/tmp/xfer.ddt.XXXXXX" -#define _PATH_TMPDIR "/var/tmp" - -#else /* BSD */ -#define _PATH_DEVNULL "/dev/null" -#define _PATH_TTY "/dev/tty" -#define _PATH_XFER "/etc/named-xfer" -#define _PATH_DEBUG "/usr/tmp/named.run" -#define _PATH_DUMPFILE "/usr/tmp/named_dump.db" -#define _PATH_PIDFILE "/etc/named.pid" -#define _PATH_STATS "/usr/tmp/named.stats" -#define _PATH_TMPXFER "/usr/tmp/xfer.ddt.XXXXXX" -#define _PATH_TMPDIR "/usr/tmp" -#endif /* BSD */ diff --git a/usr.sbin/named/storage.c b/usr.sbin/named/storage.c deleted file mode 100644 index eaa18b5ae55..00000000000 --- a/usr.sbin/named/storage.c +++ /dev/null @@ -1,167 +0,0 @@ -/* - * S T O R A G E . C - * - * Ray Tracing program, storage manager. - * - * Functions - - * rt_malloc Allocate storage, with visibility & checking - * rt_free Similarly, free storage - * rt_prmem When debugging, print memory map - * calloc, cfree Which call rt_malloc, rt_free - * - * Author - - * Michael John Muuss - * - * Source - - * SECAD/VLD Computing Consortium, Bldg 394 - * The U. S. Army Ballistic Research Laboratory - * Aberdeen Proving Ground, Maryland 21005-5066 - * - * Copyright Notice - - * This software is Copyright (C) 1987 by the United States Army. - * All rights reserved. - */ - -#ifndef lint -static char rcsid[] = "$Id: storage.c,v 1.1 1995/10/18 08:47:51 deraadt Exp $"; -#endif - -#include <sys/param.h> -#if BSD >= 43 -#include <sys/syslog.h> -#else -#include <stdio.h> -#define LOG_ERR 0 -#endif BSD - -#undef malloc -#undef free - -#define MDB_SIZE 20000 -#define MDB_MAGIC 0x12348969 -struct memdebug { - char *mdb_addr; - char *mdb_str; - int mdb_len; -} rt_mdb[MDB_SIZE]; - -/* - * R T _ M A L L O C - */ -char * -rt_malloc(cnt) -unsigned int cnt; -{ - register char *ptr; - extern char *malloc(); - - cnt = (cnt+2*sizeof(int)-1)&(~(sizeof(int)-1)); - ptr = malloc(cnt); - - if( ptr==(char *)0 ) { - syslog(LOG_ERR, "rt_malloc: malloc failure"); - abort(); - } else { - register struct memdebug *mp = rt_mdb; - for( ; mp < &rt_mdb[MDB_SIZE]; mp++ ) { - if( mp->mdb_len > 0 ) continue; - mp->mdb_addr = ptr; - mp->mdb_len = cnt; - mp->mdb_str = "???"; - goto ok; - } - syslog(LOG_ERR, "rt_malloc: memdebug overflow\n"); - } -ok: ; - { - register int *ip = (int *)(ptr+cnt-sizeof(int)); - *ip = MDB_MAGIC; - } - return(ptr); -} - -/* - * R T _ F R E E - */ -void -rt_free(ptr) -char *ptr; -{ - register struct memdebug *mp = rt_mdb; - for( ; mp < &rt_mdb[MDB_SIZE]; mp++ ) { - if( mp->mdb_len <= 0 ) continue; - if( mp->mdb_addr != ptr ) continue; - { - register int *ip = (int *)(ptr+mp->mdb_len-sizeof(int)); - if( *ip != MDB_MAGIC ) { - syslog(LOG_ERR, "ERROR rt_free(x%x, %s) corrupted! x%x!=x%x\n", ptr, "???", *ip, MDB_MAGIC); - abort(); - } - } - mp->mdb_len = 0; /* successful free */ - goto ok; - } - syslog(LOG_ERR, "ERROR rt_free(x%x, %s) bad pointer!\n", ptr, "???"); - abort(); -ok: ; - - *((int *)ptr) = -1; /* zappo! */ - free(ptr); -} - -/* - * R T _ P R M E M - * - * Print map of memory currently in use. - */ -void -rt_prmem(str) -char *str; -{ - register struct memdebug *mp = rt_mdb; - register int *ip; - - printf("\nRT memory use\t\t%s\n", str); - for( ; mp < &rt_mdb[MDB_SIZE]; mp++ ) { - if( mp->mdb_len <= 0 ) continue; - ip = (int *)(mp->mdb_addr+mp->mdb_len-sizeof(int)); - printf("%7x %5x %s %s\n", - mp->mdb_addr, mp->mdb_len, mp->mdb_str, - *ip!=MDB_MAGIC ? "-BAD-" : "" ); - if( *ip != MDB_MAGIC ) - printf("\t%x\t%x\n", *ip, MDB_MAGIC); - } -} - -char * -calloc(num, size) - register unsigned num, size; -{ - extern char *malloc(); - register char *p; - - size *= num; - if (p = rt_malloc(size)) - bzero(p, size); - return (p); -} - -cfree(p, num, size) - char *p; - unsigned num; - unsigned size; -{ - rt_free(p); -} - -#if BSD < 43 -openlog() {} - -syslog(x, str, a, b, c, d, e, f) -int x; -char *str; -int a, b, c, d, e, f; -{ - fprintf(stderr, str, a, b, c, d, e, f); -} -#endif BSD diff --git a/usr.sbin/named/tools/Makefile b/usr.sbin/named/tools/Makefile deleted file mode 100644 index 4a75abb0df8..00000000000 --- a/usr.sbin/named/tools/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# from: @(#)Makefile 4.10 (Berkeley) 5/29/90 -# $Id: Makefile,v 1.1 1995/10/18 08:47:55 deraadt Exp $ - -SUBDIR= nslookup nsquery nstest - -.include <bsd.subdir.mk> diff --git a/usr.sbin/named/tools/nslookup/Makefile b/usr.sbin/named/tools/nslookup/Makefile deleted file mode 100644 index b58a3adbf00..00000000000 --- a/usr.sbin/named/tools/nslookup/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -# from: @(#)Makefile 5.23 (Berkeley) 6/24/90 -# $Id: Makefile,v 1.1 1995/10/18 08:47:55 deraadt Exp $ - -PROG= nslookup -SRCS= main.c getinfo.c debug.c send.c skip.c list.c subr.c -OBJS+= commands.o -MAN= nslookup.8 -LFLAGS= -I -CFLAGS+=-I${.CURDIR} -LDADD= -ll -DPADD= ${LIBL} -CLEANFILES+=commands.c lex.yy.c lex.yy.o - -beforeinstall: - install -c -o ${BINOWN} -g ${BINGRP} -m 444 ${.CURDIR}/nslookup.help \ - ${DESTDIR}/usr/share/misc - -.include "../../../Makefile.inc" -.include <bsd.prog.mk> diff --git a/usr.sbin/named/tools/nslookup/commands.l b/usr.sbin/named/tools/nslookup/commands.l deleted file mode 100644 index 4cc757da703..00000000000 --- a/usr.sbin/named/tools/nslookup/commands.l +++ /dev/null @@ -1,197 +0,0 @@ -%{ - -/*- - * Copyright (c) 1985 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -/*static char sccsid[] = "from: @(#)commands.l 5.13 (Berkeley) 7/24/90";*/ -static char rcsid[] = "$Id: commands.l,v 1.1 1995/10/18 08:47:55 deraadt Exp $"; -#endif /* not lint */ - -/* - ******************************************************************************* - * - * commands.l - * - * Andrew Cherenson CS298-26 Fall 1985 - * - * Lex input file for the nslookup program command interpreter. - * When a sequence is recognized, the associated action - * routine is called. The action routine may need to - * parse the string for additional information. - * - * Recognized commands: (identifiers are shown in uppercase) - * - * server NAME - set default server to NAME, using default server - * lserver NAME - set default server to NAME, using initial server - * finger [NAME] - finger the optional NAME - * exit - exit the program - * root - set default server to the root - * ls NAME - list the domain NAME - * view FILE - sorts and view the file with more - * set OPTION - set an option - * help - print help information - * ? - print help information - * NAME - print info about the host/domain NAME - * using default server. - * NAME1 NAME2 - as above, but use NAME2 as server - * - * - * yylex Results: - * 0 upon end-of-file. - * 1 after each command. - * - ******************************************************************************* - */ - -#include "res.h" -extern char rootServerName[]; - -%} -WS [ \t] -FLET [A-Za-z0-9.*\\] -LET [A-Za-z0-9.*] -NAME [A-Za-z0-9.*=_/-] -%% -^{WS}*server{WS}+{LET}{NAME}*{WS}*$ { - /* - * 0 == use current server to find - * the new one. - * 1 == use original server to find - * the new one. - */ - SetDefaultServer(yytext, 0); - return(1); - } -^{WS}*lserver{WS}+{LET}{NAME}*{WS}*$ { - SetDefaultServer(yytext, 1); - return(1); - } -^{WS}*exit{WS}*$ { - return(0); - } -^{WS}*root{WS}*$ { - SetDefaultServer(rootServerName, 1); - return(1); - } -^{WS}*finger({WS}+{LET}{NAME}*)?{WS}+>>?{WS}*{NAME}+{WS}*$ { - /* - * 2nd arg. - * 0 == output to stdout - * 1 == output to file - */ - Finger(yytext, 1); - return(1); - } -^{WS}*finger({WS}+{LET}{NAME}*)?{WS}*$ { - Finger(yytext, 0); - return(1); - } -^{WS}*view{WS}+{NAME}+{WS}*$ { - ViewList(yytext); - return(1); - } -^{WS}*ls{WS}+(("-a"|"-d"|"-h"|"-m"|"-s"){WS}+)?{LET}{NAME}*{WS}+>>?{WS}+{NAME}+{WS}*$ { - /* - * 2nd arg. - * 0 == output to stdout - * 1 == output to file - */ - ListHosts(yytext, 1); - return(1); - } -^{WS}*ls{WS}+(("-a"|"-d"|"-h"|"-m"|"-s"){WS}+)?{LET}{NAME}*{WS}*$ { - ListHosts(yytext, 0); - return(1); - } -^{WS}*ls{WS}+-t{WS}+({LET}{NAME}*{WS}+)?{LET}{NAME}*{WS}+>>?{WS}+{NAME}+{WS}*$ { - /* - * 2nd arg. - * 0 == output to stdout - * 1 == output to file - */ - ListHostsByType(yytext, 1); - return(1); - } -^{WS}*ls{WS}+-t{WS}+({LET}{NAME}*{WS}+)?{LET}{NAME}*{WS}*$ { - ListHostsByType(yytext, 0); - return(1); - } -^{WS}*set{WS}+{NAME}+{WS}*$ { - SetOption(yytext); - return(1); - } -^{WS}*help{WS}*$ { - extern void PrintHelp(); - PrintHelp(); - return(1); - } -^{WS}*"?"{WS}*$ { - extern void PrintHelp(); - PrintHelp(); - return(1); - } -^{WS}*{FLET}{NAME}*{WS}+>>?{WS}*{NAME}+{WS}*$ { - /* - * 0 == output to stdout - * 1 == output to file - */ - LookupHost(yytext, 1); - return(1); - } -^{WS}*{FLET}{NAME}*{WS}*$ { - LookupHost(yytext, 0); - return(1); - } -^{WS}*{FLET}{NAME}*{WS}+{LET}{NAME}*{WS}+>>?{WS}*{NAME}+{WS}*$ { - /* - * 0 == output to stdout - * 1 == output to file - */ - LookupHostWithServer(yytext, 1); - return(1); - } -^{WS}*{FLET}{NAME}*{WS}+{LET}{NAME}*{WS}*$ { - LookupHostWithServer(yytext, 0); - return(1); - } -^{WS}*\n { - return(1); - } -^.*\n { - printf("Unrecognized command: %s", - yytext); - return(1); - } -\n { ; } -%% diff --git a/usr.sbin/named/tools/nslookup/debug.c b/usr.sbin/named/tools/nslookup/debug.c deleted file mode 100644 index e025c6af245..00000000000 --- a/usr.sbin/named/tools/nslookup/debug.c +++ /dev/null @@ -1,463 +0,0 @@ -/* - * Copyright (c) 1985,1989 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -/*static char sccsid[] = "from: @(#)debug.c 5.26 (Berkeley) 3/21/91";*/ -static char rcsid[] = "$Id: debug.c,v 1.1 1995/10/18 08:47:55 deraadt Exp $"; -#endif /* not lint */ - -/* - ******************************************************************************* - * - * debug.c -- - * - * Routines to print out packets received from a name server query. - * - * Modified version of 4.3BSD BIND res_debug.c 5.30 6/27/90 - * - ******************************************************************************* - */ - -#include <sys/param.h> -#include <netinet/in.h> -#include <arpa/nameser.h> -#include <arpa/inet.h> -#include <resolv.h> -#include <netdb.h> -#include <stdio.h> -#include "res.h" - -extern char ctime(); - -/* - * Imported from res_debug.c - */ -extern char *_res_resultcodes[]; -extern char *_res_opcodes[]; - -/* - * Used to highlight the start of a record when printing it. - */ -#define INDENT " -> " - - - -/* - * Print the contents of a query. - * This is intended to be primarily a debugging routine. - */ - -Print_query(msg, eom, printHeader) - char *msg, *eom; - int printHeader; -{ - Fprint_query(msg, eom, printHeader,stdout); -} - -Fprint_query(msg, eom, printHeader,file) - char *msg, *eom; - int printHeader; - FILE *file; -{ - register char *cp; - register HEADER *hp; - register int n; - short class; - short type; - - /* - * Print header fields. - */ - hp = (HEADER *)msg; - cp = msg + sizeof(HEADER); - if (printHeader || (_res.options & RES_DEBUG2)) { - fprintf(file," HEADER:\n"); - fprintf(file,"\topcode = %s", _res_opcodes[hp->opcode]); - fprintf(file,", id = %d", ntohs(hp->id)); - fprintf(file,", rcode = %s\n", _res_resultcodes[hp->rcode]); - fprintf(file,"\theader flags: "); - if (hp->qr) { - fprintf(file," response"); - } else { - fprintf(file," query"); - } - if (hp->aa) - fprintf(file,", auth. answer"); - if (hp->tc) - fprintf(file,", truncation"); - if (hp->rd) - fprintf(file,", want recursion"); - if (hp->ra) - fprintf(file,", recursion avail."); - if (hp->pr) - fprintf(file,", primary"); - fprintf(file,"\n\tquestions = %d", ntohs(hp->qdcount)); - fprintf(file,", answers = %d", ntohs(hp->ancount)); - fprintf(file,", authority records = %d", ntohs(hp->nscount)); - fprintf(file,", additional = %d\n\n", ntohs(hp->arcount)); - } - - /* - * Print question records. - */ - if (n = ntohs(hp->qdcount)) { - fprintf(file," QUESTIONS:\n"); - while (--n >= 0) { - fprintf(file,"\t"); - cp = Print_cdname(cp, msg, eom, file); - if (cp == NULL) - return; - type = _getshort(cp); - cp += sizeof(u_short); - class = _getshort(cp); - cp += sizeof(u_short); - fprintf(file,", type = %s", p_type(type)); - fprintf(file,", class = %s\n", p_class(class)); - } - } - /* - * Print authoritative answer records - */ - if (n = ntohs(hp->ancount)) { - fprintf(file," ANSWERS:\n"); - while (--n >= 0) { - fprintf(file, INDENT); - cp = Print_rr(cp, msg, eom, file); - if (cp == NULL) - return; - } - } - /* - * print name server records - */ - if (n = ntohs(hp->nscount)) { - fprintf(file," AUTHORITY RECORDS:\n"); - while (--n >= 0) { - fprintf(file, INDENT); - cp = Print_rr(cp, msg, eom, file); - if (cp == NULL) - return; - } - } - /* - * print additional records - */ - if (n = ntohs(hp->arcount)) { - fprintf(file," ADDITIONAL RECORDS:\n"); - while (--n >= 0) { - fprintf(file, INDENT); - cp = Print_rr(cp, msg, eom, file); - if (cp == NULL) - return; - } - } - fprintf(file,"\n------------\n"); -} - - -char * -Print_cdname_sub(cp, msg, eom, file, format) - u_char *cp, *msg, *eom; - FILE *file; - int format; -{ - int n; - u_char name[MAXDNAME]; - extern char *strcpy(); - - if ((n = dn_expand(msg, eom, cp, name, sizeof(name))) < 0) - return (NULL); - if (name[0] == '\0') { - (void) strcpy(name, "(root)"); - } - if (format) { - fprintf(file, "%-30s", name); - } else { - fputs((char *)name, file); - } - return ((char *)cp + n); -} - -char * -Print_cdname(cp, msg, eom, file) - char *cp, *msg, *eom; - FILE *file; -{ - return(Print_cdname_sub(cp, msg, eom, file, 0)); -} - -char * -Print_cdname2(cp, msg, eom, file) - char *cp, *msg, *eom; - FILE *file; -{ - return(Print_cdname_sub(cp, msg, eom, file, 1)); -} - -/* - * Print resource record fields in human readable form. - */ -char * -Print_rr(cp, msg, eom, file) - char *cp, *msg, *eom; - FILE *file; -{ - int type, class, dlen, n, c; - unsigned long rrttl, ttl; - struct in_addr inaddr; - char *cp1, *cp2; - int debug; - - if ((cp = Print_cdname(cp, msg, eom, file)) == NULL) { - fprintf(file, "(name truncated?)\n"); - return (NULL); /* compression error */ - } - - type = _getshort(cp); - cp += sizeof(u_short); - class = _getshort(cp); - cp += sizeof(u_short); - rrttl = _getlong(cp); - cp += sizeof(u_long); - dlen = _getshort(cp); - cp += sizeof(u_short); - - debug = _res.options & (RES_DEBUG|RES_DEBUG2); - if (debug) { - if (_res.options & RES_DEBUG2) { - fprintf(file,"\n\ttype = %s, class = %s, dlen = %d", - p_type(type), p_class(class), dlen); - } - if (type == T_SOA) { - fprintf(file,"\n\tttl = %lu (%s)", rrttl, p_time(rrttl)); - } - (void) putc('\n', file); - } - - cp1 = cp; - - /* - * Print type specific data, if appropriate - */ - switch (type) { - case T_A: - switch (class) { - case C_IN: - case C_HS: - bcopy(cp, (char *)&inaddr, sizeof(inaddr)); - if (dlen == 4) { - fprintf(file,"\tinternet address = %s\n", - inet_ntoa(inaddr)); - cp += dlen; - } else if (dlen == 7) { - fprintf(file,"\tinternet address = %s", - inet_ntoa(inaddr)); - fprintf(file,", protocol = %d", cp[4]); - fprintf(file,", port = %d\n", - (cp[5] << 8) + cp[6]); - cp += dlen; - } - break; - default: - fprintf(file,"\taddress, class = %d, len = %d\n", - class, dlen); - cp += dlen; - } - break; - - case T_CNAME: - fprintf(file,"\tcanonical name = "); - goto doname; - - case T_MG: - fprintf(file,"\tmail group member = "); - goto doname; - case T_MB: - fprintf(file,"\tmail box = "); - goto doname; - case T_MR: - fprintf(file,"\tmailbox rename = "); - goto doname; - case T_MX: - fprintf(file,"\tpreference = %u",_getshort(cp)); - cp += sizeof(u_short); - fprintf(file,", mail exchanger = "); - goto doname; - case T_NS: - fprintf(file,"\tnameserver = "); - goto doname; - case T_PTR: - fprintf(file,"\tname = "); -doname: - cp = Print_cdname(cp, msg, eom, file); - (void) putc('\n', file); - break; - - case T_HINFO: - if (n = *cp++) { - fprintf(file,"\tCPU = %.*s", n, cp); - cp += n; - } - if (n = *cp++) { - fprintf(file,"\tOS = %.*s\n", n, cp); - cp += n; - } - break; - - case T_SOA: - if (!debug) - (void) putc('\n', file); - fprintf(file,"\torigin = "); - cp = Print_cdname(cp, msg, eom, file); - fprintf(file,"\n\tmail addr = "); - cp = Print_cdname(cp, msg, eom, file); - fprintf(file,"\n\tserial = %lu", _getlong(cp)); - cp += sizeof(u_long); - ttl = _getlong(cp); - fprintf(file,"\n\trefresh = %lu (%s)", ttl, p_time(ttl)); - cp += sizeof(u_long); - ttl = _getlong(cp); - fprintf(file,"\n\tretry = %lu (%s)", ttl, p_time(ttl)); - cp += sizeof(u_long); - ttl = _getlong(cp); - fprintf(file,"\n\texpire = %lu (%s)", ttl, p_time(ttl)); - cp += sizeof(u_long); - ttl = _getlong(cp); - fprintf(file, - "\n\tminimum ttl = %lu (%s)\n", ttl, p_time(ttl)); - cp += sizeof(u_long); - break; - - case T_MINFO: - if (!debug) - (void) putc('\n', file); - fprintf(file,"\trequests = "); - cp = Print_cdname(cp, msg, eom, file); - fprintf(file,"\n\terrors = "); - cp = Print_cdname(cp, msg, eom, file); - (void) putc('\n', file); - break; - - case T_TXT: - (void) fputs("\ttext = \"", file); - cp2 = cp1 + dlen; - while (cp < cp2) { - if (n = (unsigned char) *cp++) { - for (c = n; c > 0 && cp < cp2; c--) - if (*cp == '\n') { - (void) putc('\\', file); - (void) putc(*cp++, file); - } else - (void) putc(*cp++, file); - } - } - (void) fputs("\"\n", file); - break; - - case T_UINFO: - fprintf(file,"\tuser info = %s\n", cp); - cp += dlen; - break; - - case T_UID: - case T_GID: - if (dlen == 4) { - fprintf(file,"\t%cid = %lu\n",type == T_UID ? 'u' : 'g', - _getlong(cp)); - cp += sizeof(int); - } else { - fprintf(file,"\t%cid of length %d?\n", - type == T_UID ? 'u' : 'g', dlen); - cp += dlen; - } - break; - - case T_WKS: { - struct protoent *protoPtr; - - if (dlen < sizeof(u_long) + 1) - break; - if (!debug) - (void) putc('\n', file); - bcopy(cp, (char *)&inaddr, sizeof(inaddr)); - cp += sizeof(u_long); - if ((protoPtr = getprotobynumber(*cp)) != NULL) { - fprintf(file,"\tinet address = %s, protocol = %s\n\t", - inet_ntoa(inaddr), protoPtr->p_name); - } else { - fprintf(file,"\tinet address = %s, protocol = %d\n\t", - inet_ntoa(inaddr), *cp); - } - cp++; - n = 0; - while (cp < cp1 + dlen) { - c = *cp++; - do { - struct servent *s; - - if (c & 0200) { - s = getservbyport((int)htons(n), - protoPtr ? protoPtr->p_name : NULL); - if (s != NULL) { - fprintf(file," %s", s->s_name); - } else { - fprintf(file," #%d", n); - } - } - c <<= 1; - } while (++n & 07); - } - putc('\n',file); - } - break; - - case T_NULL: - fprintf(file, "\tNULL (dlen %d)\n", dlen); - cp += dlen; - break; - - default: - fprintf(file,"\t??? unknown type %d ???\n", type); - cp += dlen; - } - if (_res.options & RES_DEBUG && type != T_SOA) { - fprintf(file,"\tttl = %lu (%s)\n", rrttl, p_time(rrttl)); - } - if (cp != cp1 + dlen) { - fprintf(file, - "\n*** Error: record size incorrect (%d != %d)\n\n", - cp - cp1, dlen); - cp = NULL; - } - return (cp); -} diff --git a/usr.sbin/named/tools/nslookup/getinfo.c b/usr.sbin/named/tools/nslookup/getinfo.c deleted file mode 100644 index 0c275c14ba0..00000000000 --- a/usr.sbin/named/tools/nslookup/getinfo.c +++ /dev/null @@ -1,800 +0,0 @@ -/* - * Copyright (c) 1985,1989 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -/*static char sccsid[] = "from: @(#)getinfo.c 5.26 (Berkeley) 3/21/91";*/ -static char rcsid[] = "$Id: getinfo.c,v 1.1 1995/10/18 08:47:55 deraadt Exp $"; -#endif /* not lint */ - -/* - ******************************************************************************* - * - * getinfo.c -- - * - * Routines to create requests to name servers - * and interpret the answers. - * - * Adapted from 4.3BSD BIND gethostnamadr.c - * - ******************************************************************************* - */ - -#include <sys/param.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/nameser.h> -#include <arpa/inet.h> -#include <resolv.h> -#include <stdio.h> -#include <string.h> -#include <ctype.h> -#include "res.h" - -extern char *_res_resultcodes[]; -extern char *res_skip(); - -#define MAXALIASES 35 -#define MAXADDRS 35 -#define MAXDOMAINS 35 -#define MAXSERVERS 10 - -static char *addr_list[MAXADDRS + 1]; - -static char *host_aliases[MAXALIASES]; -static int host_aliases_len[MAXALIASES]; -static u_char hostbuf[BUFSIZ+1]; - -typedef struct { - char *name; - char *domain[MAXDOMAINS]; - int numDomains; - char *address[MAXADDRS]; - int numAddresses; -} ServerTable; - -ServerTable server[MAXSERVERS]; - -typedef union { - HEADER qb1; - char qb2[PACKETSZ]; -} querybuf; - -typedef union { - long al; - char ac; -} align; - -#define GetShort(cp) _getshort(cp); cp += sizeof(unsigned short); - - -/* - ******************************************************************************* - * - * GetAnswer -- - * - * Interprets an answer packet and retrieves the following - * information: - * - * Results: - * SUCCESS the info was retrieved. - * NO_INFO the packet did not contain an answer. - * NONAUTH non-authoritative information was found. - * ERROR the answer was malformed. - * Other errors returned in the packet header. - * - ******************************************************************************* - */ - -static int -GetAnswer(nsAddrPtr, queryType, msg, msglen, iquery, hostPtr, isServer) - struct in_addr *nsAddrPtr; - char *msg; - int queryType; - int msglen; - Boolean iquery; - register HostInfo *hostPtr; - Boolean isServer; -{ - register HEADER *headerPtr; - register u_char *cp; - querybuf answer; - char **aliasPtr; - u_char *eom, *bp; - char **addrPtr; - char *namePtr; - char *dnamePtr; - int type, class; - int qdcount, ancount, arcount, nscount, buflen; - int origClass; - int numAliases = 0; - int numAddresses = 0; - int n, i, j; - int len; - int dlen; - int status; - int numServers; - Boolean haveAnswer; - Boolean printedAnswers = FALSE; - - - /* - * If the hostPtr was used before, free up the calloc'd areas. - */ - FreeHostInfoPtr(hostPtr); - - status = SendRequest(nsAddrPtr, msg, msglen, (char *) &answer, - sizeof(answer), &n); - - if (status != SUCCESS) { - if (_res.options & RES_DEBUG2) - printf("SendRequest failed\n"); - return (status); - } - eom = (u_char *) &answer + n; - - headerPtr = (HEADER *) &answer; - - if (headerPtr->rcode != NOERROR) { - return (headerPtr->rcode); - } - - qdcount = ntohs(headerPtr->qdcount); - ancount = ntohs(headerPtr->ancount); - arcount = ntohs(headerPtr->arcount); - nscount = ntohs(headerPtr->nscount); - - /* - * If there are no answer, n.s. or additional records - * then return with an error. - */ - if (ancount == 0 && nscount == 0 && arcount == 0) { - return (NO_INFO); - } - - - bp = hostbuf; - buflen = sizeof(hostbuf); - cp = (u_char *) &answer + sizeof(HEADER); - - /* Skip over question section. */ - while (qdcount-- > 0) { - cp += dn_skipname(cp, eom) + QFIXEDSZ; - } - - aliasPtr = host_aliases; - addrPtr = addr_list; - haveAnswer = FALSE; - - /* - * Scan through the answer resource records. - * Answers for address query types are saved. - * Other query type answers are just printed. - */ - if (ancount != 0) { - if (!isServer && !headerPtr->aa) { - printf("Non-authoritative answer:\n"); - } - - if (queryType != T_A && !(iquery && queryType == T_PTR)) { - while (--ancount >= 0 && cp < eom) { - if ((cp = (u_char *)Print_rr(cp, - (char *)&answer, eom, stdout)) == NULL) { - return(ERROR); - } - } - printedAnswers = TRUE; - } else { - while (--ancount >= 0 && cp < eom) { - if ((n = - dn_expand((u_char *)&answer, eom, cp, bp, buflen)) < 0) { - return(ERROR); - } - cp += n; - type = GetShort(cp); - class = GetShort(cp); - cp += sizeof(u_long); /* skip TTL */ - dlen = GetShort(cp); - if (type == T_CNAME) { - /* - * Found an alias. - */ - cp += dlen; - if (aliasPtr >= &host_aliases[MAXALIASES-1]) { - continue; - } - *aliasPtr++ = (char *)bp; - n = strlen((char *)bp) + 1; - host_aliases_len[numAliases] = n; - numAliases++; - bp += n; - buflen -= n; - continue; - } else if (type == T_PTR) { - /* - * Found a "pointer" to the real name. - */ - if ((n = - dn_expand((u_char *)&answer, eom, cp, bp,buflen)) < 0) { - cp += n; - continue; - } - cp += n; - len = strlen(bp) + 1; - hostPtr->name = Calloc(1, len); - bcopy(bp, hostPtr->name, len); - haveAnswer = TRUE; - break; - } else if (type != T_A) { - cp += dlen; - continue; - } - if (haveAnswer) { - /* - * If we've already got 1 address, we aren't interested - * in addresses with a different length or class. - */ - if (dlen != hostPtr->addrLen) { - cp += dlen; - continue; - } - if (class != origClass) { - cp += dlen; - continue; - } - } else { - /* - * First address: record its length and class so we - * only save additonal ones with the same attributes. - */ - hostPtr->addrLen = dlen; - origClass = class; - hostPtr->addrType = (class == C_IN) ? AF_INET : AF_UNSPEC; - len = strlen(bp) + 1; - hostPtr->name = Calloc(1, len); - bcopy(bp, hostPtr->name, len); - } - bp += (((u_long)bp) % sizeof(align)); - - if (bp + dlen >= &hostbuf[sizeof(hostbuf)]) { - if (_res.options & RES_DEBUG) { - printf("Size (%d) too big\n", dlen); - } - break; - } - bcopy(cp, *addrPtr++ = (char *)bp, dlen); - bp +=dlen; - cp += dlen; - numAddresses++; - haveAnswer = TRUE; - } - } - } - - if ((queryType == T_A || queryType == T_PTR) && haveAnswer) { - - /* - * Go through the alias and address lists and return them - * in the hostPtr variable. - */ - - if (numAliases > 0) { - hostPtr->aliases = (char **) Calloc(1 + numAliases, sizeof(char *)); - for (i = 0; i < numAliases; i++) { - hostPtr->aliases[i] = Calloc(1, host_aliases_len[i]); - bcopy(host_aliases[i], hostPtr->aliases[i],host_aliases_len[i]); - } - hostPtr->aliases[i] = NULL; - } - if (numAddresses > 0) { - hostPtr->addrList = (char **)Calloc(1+numAddresses, sizeof(char *)); - for (i = 0; i < numAddresses; i++) { - hostPtr->addrList[i] = Calloc(1, hostPtr->addrLen); - bcopy(addr_list[i], hostPtr->addrList[i], hostPtr->addrLen); - } - hostPtr->addrList[i] = NULL; - } -#ifdef verbose - if (headerPtr->aa || nscount == 0) { - hostPtr->servers = NULL; - return (SUCCESS); - } -#else - hostPtr->servers = NULL; - return (SUCCESS); -#endif - } - - /* - * At this point, for the T_A query type, only empty answers remain. - * For other query types, additional information might be found - * in the additional resource records part. - */ - - if (!headerPtr->aa && (queryType != T_A) && (nscount > 0 || arcount > 0)) { - if (printedAnswers) { - putchar('\n'); - } - printf("Authoritative answers can be found from:\n"); - } - - cp = (u_char *)res_skip((char *) &answer, 2, eom); - - numServers = 0; - if (queryType != T_A) { - /* - * If we don't need to save the record, just print it. - */ - while (--nscount >= 0 && cp < eom) { - if ((cp = (u_char *)Print_rr(cp, - (char *) &answer, eom, stdout)) == NULL) { - return(ERROR); - } - } - } else { - while (--nscount >= 0 && cp < eom) { - /* - * Go through the NS records and retrieve the names of hosts - * that serve the requested domain. - */ - - if ((n = dn_expand((u_char *) &answer, eom, cp, bp, buflen)) < 0) { - return(ERROR); - } - cp += n; - len = strlen(bp) + 1; - dnamePtr = Calloc(1, len); /* domain name */ - bcopy(bp, dnamePtr, len); - - type = GetShort(cp); - class = GetShort(cp); - cp += sizeof(u_long); /* skip TTL */ - dlen = GetShort(cp); - - if (type != T_NS) { - cp += dlen; - } else { - Boolean found; - - if ((n = - dn_expand((u_char *) &answer, eom, cp, bp, buflen)) < 0) { - return(ERROR); - } - cp += n; - len = strlen(bp) + 1; - namePtr = Calloc(1, len); /* server host name */ - bcopy(bp, namePtr, len); - - /* - * Store the information keyed by the server host name. - */ - found = FALSE; - for (j = 0; j < numServers; j++) { - if (strcmp(namePtr, server[j].name) == 0) { - found = TRUE; - free(namePtr); - break; - } - } - if (found) { - server[j].numDomains++; - if (server[j].numDomains <= MAXDOMAINS) { - server[j].domain[server[j].numDomains-1] = dnamePtr; - } - } else { - if (numServers >= MAXSERVERS) { - break; - } - server[numServers].name = namePtr; - server[numServers].domain[0] = dnamePtr; - server[numServers].numDomains = 1; - server[numServers].numAddresses = 0; - numServers++; - } - } - } - } - - /* - * Additional resource records contain addresses of servers. - */ - cp = (u_char *)res_skip((char *) &answer, 3, eom); - - if (queryType != T_A) { - /* - * If we don't need to save the record, just print it. - */ - while (--arcount >= 0 && cp < eom) { - if ((cp = (u_char *)Print_rr(cp, - (char *) &answer, eom, stdout)) == NULL) { - return(ERROR); - } - } - } else { - while (--arcount >= 0 && cp < eom) { - if ((n = dn_expand((u_char *) &answer, eom, cp, bp, buflen)) < 0) { - break; - } - cp += n; - type = GetShort(cp); - class = GetShort(cp); - cp += sizeof(u_long); /* skip TTL */ - dlen = GetShort(cp); - - if (type != T_A) { - cp += dlen; - continue; - } else { - for (j = 0; j < numServers; j++) { - if (strcmp(bp, server[j].name) == 0) { - server[j].numAddresses++; - if (server[j].numAddresses <= MAXADDRS) { - server[j].address[server[j].numAddresses-1] = - Calloc(1,dlen); - bcopy(cp, - server[j].address[server[j].numAddresses-1],dlen); - break; - } - } - } - cp += dlen; - } - } - } - - /* - * If we are returning name server info, transfer it to the hostPtr. - */ - if (numServers > 0) { - hostPtr->servers = (ServerInfo **) - Calloc(numServers+1, sizeof(ServerInfo *)); - - for (i = 0; i < numServers; i++) { - hostPtr->servers[i] = (ServerInfo *) Calloc(1, sizeof(ServerInfo)); - hostPtr->servers[i]->name = server[i].name; - - - hostPtr->servers[i]->domains = (char **) - Calloc(server[i].numDomains+1,sizeof(char *)); - for (j = 0; j < server[i].numDomains; j++) { - hostPtr->servers[i]->domains[j] = server[i].domain[j]; - } - hostPtr->servers[i]->domains[j] = NULL; - - - hostPtr->servers[i]->addrList = (char **) - Calloc(server[i].numAddresses+1,sizeof(char *)); - for (j = 0; j < server[i].numAddresses; j++) { - hostPtr->servers[i]->addrList[j] = server[i].address[j]; - } - hostPtr->servers[i]->addrList[j] = NULL; - - } - hostPtr->servers[i] = NULL; - } - - switch (queryType) { - case T_A: - return NONAUTH; - case T_PTR: - if (iquery) - return NO_INFO; - /* fall through */ - default: - return SUCCESS; - } -} - -/* -******************************************************************************* -* -* GetHostInfo -- -* -* Retrieves host name, address and alias information -* for a domain. -* -* Algorithm from res_search(). -* -* Results: -* ERROR - res_mkquery failed. -* + return values from GetAnswer() -* -******************************************************************************* -*/ - -int -GetHostInfoByName(nsAddrPtr, queryClass, queryType, name, hostPtr, isServer) - struct in_addr *nsAddrPtr; - int queryClass; - int queryType; - char *name; - HostInfo *hostPtr; - Boolean isServer; -{ - int n; - register int result; - register char *cp, **domain; - Boolean got_nodata = FALSE; - struct in_addr ina; - - /* Catch explicit addresses */ - if ((queryType == T_A) && IsAddr(name, &ina)) { - hostPtr->name = Calloc(strlen(name)+3, 1); - (void)sprintf(hostPtr->name,"[%s]",name); - hostPtr->aliases = NULL; - hostPtr->servers = NULL; - hostPtr->addrType = AF_INET; - hostPtr->addrLen = sizeof(ina); - hostPtr->addrList = (char **)Calloc(2, sizeof(char *)); - hostPtr->addrList[0] = Calloc(1, sizeof(ina)); - bcopy((char *)&ina, hostPtr->addrList[0], sizeof(ina)); - hostPtr->addrList[1] = NULL; - return(SUCCESS); - } - - result = NXDOMAIN; - for (cp = name, n = 0; *cp; cp++) - if (*cp == '.') - n++; - if (n == 0 && (cp = hostalias(name))) { - printf("Aliased to \"%s\"\n\n", cp); - return (GetHostDomain(nsAddrPtr, queryClass, queryType, - cp, (char *)NULL, hostPtr, isServer)); - } - /* - * We do at least one level of search if - * - there is no dot and RES_DEFNAME is set, or - * - there is at least one dot, there is no trailing dot, - * and RES_DNSRCH is set. - */ - if ((n == 0 && _res.options & RES_DEFNAMES) || - (n != 0 && *--cp != '.' && _res.options & RES_DNSRCH)) - for (domain = _res.dnsrch; *domain; domain++) { - result = GetHostDomain(nsAddrPtr, queryClass, queryType, - name, *domain, hostPtr, isServer); - /* - * If no server present, give up. - * If name isn't found in this domain, - * keep trying higher domains in the search list - * (if that's enabled). - * On a NO_INFO error, keep trying, otherwise - * a wildcard entry of another type could keep us - * from finding this entry higher in the domain. - * If we get some other error (negative answer or - * server failure), then stop searching up, - * but try the input name below in case it's fully-qualified. - */ - if (result == SUCCESS || result == NO_RESPONSE) - return result; - if (result == NO_INFO) - got_nodata++; - if ((result != NXDOMAIN && result != NO_INFO) || - (_res.options & RES_DNSRCH) == 0) - break; - } - /* - * If the search/default failed, try the name as fully-qualified, - * but only if it contained at least one dot (even trailing). - * This is purely a heuristic; we assume that any reasonable query - * about a top-level domain (for servers, SOA, etc) will not use - * res_search. - */ - if (n && (result = GetHostDomain(nsAddrPtr, queryClass, queryType, - name, (char *)NULL, hostPtr, isServer)) == SUCCESS) - return result; - if (got_nodata) - result = NO_INFO; - return (result); -} - -/* - * Perform a query on the concatenation of name and domain, - * removing a trailing dot from name if domain is NULL. - */ -GetHostDomain(nsAddrPtr, queryClass, queryType, name, domain, hostPtr, isServer) - struct in_addr *nsAddrPtr; - int queryClass; - int queryType; - char *name, *domain; - HostInfo *hostPtr; - Boolean isServer; -{ - querybuf buf; - char nbuf[2*MAXDNAME+2]; - char *longname = nbuf; - int n; - - if (domain == NULL) { - /* - * Check for trailing '.'; - * copy without '.' if present. - */ - n = strlen(name) - 1; - if (name[n] == '.' && n < sizeof(nbuf) - 1) { - bcopy(name, nbuf, n); - nbuf[n] = '\0'; - } else - longname = name; - } else { - (void)sprintf(nbuf, "%.*s.%.*s", - MAXDNAME, name, MAXDNAME, domain); - longname = nbuf; - } - n = res_mkquery(QUERY, longname, queryClass, queryType, - (char *)0, 0, 0, (char *) &buf, sizeof(buf)); - if (n < 0) { - if (_res.options & RES_DEBUG) { - printf("Res_mkquery failed\n"); - } - return (ERROR); - } - - n = GetAnswer(nsAddrPtr, queryType, (char *)&buf, n, 0, hostPtr, isServer); - - /* - * GetAnswer didn't find a name, so set it to the specified one. - */ - if (n == NONAUTH) { - if (hostPtr->name == NULL) { - int len = strlen(longname) + 1; - hostPtr->name = Calloc(len, sizeof(char)); - bcopy(longname, hostPtr->name, len); - } - } - return(n); -} - - -/* -******************************************************************************* -* -* GetHostInfoByAddr -- -* -* Performs an inverse query to find the host name -* that corresponds to the given address. -* -* Results: -* ERROR - res_mkquery failed. -* + return values from GetAnswer() -* -******************************************************************************* -*/ - -int -GetHostInfoByAddr(nsAddrPtr, address, hostPtr) - struct in_addr *nsAddrPtr; - struct in_addr *address; - HostInfo *hostPtr; -{ - int n; - querybuf buf; - char qbuf[MAXDNAME]; - char *p = (char *) &address->s_addr; - - (void)sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa", - ((unsigned)p[3] & 0xff), - ((unsigned)p[2] & 0xff), - ((unsigned)p[1] & 0xff), - ((unsigned)p[0] & 0xff)); - n = res_mkquery(QUERY, qbuf, C_IN, T_PTR, - NULL, 0, NULL, (char *) &buf, sizeof(buf)); - if (n < 0) { - if (_res.options & RES_DEBUG) { - printf("res_mkquery() failed\n"); - } - return (ERROR); - } - n = GetAnswer(nsAddrPtr, T_PTR, (char *) &buf, n, 1, hostPtr, 1); - if (n == SUCCESS) { - hostPtr->addrType = AF_INET; - hostPtr->addrLen = 4; - hostPtr->addrList = (char **)Calloc(2, sizeof(char *)); - hostPtr->addrList[0] = Calloc(sizeof(long), sizeof(char)); - bcopy((char *)p, hostPtr->addrList[0], sizeof(struct in_addr)); - hostPtr->addrList[1] = NULL; - } - return n; -} - -/* -******************************************************************************* -* -* FreeHostInfoPtr -- -* -* Deallocates all the calloc'd areas for a HostInfo variable. -* -******************************************************************************* -*/ - -void -FreeHostInfoPtr(hostPtr) - register HostInfo *hostPtr; -{ - int i, j; - - if (hostPtr->name != NULL) { - free(hostPtr->name); - hostPtr->name = NULL; - } - - if (hostPtr->aliases != NULL) { - i = 0; - while (hostPtr->aliases[i] != NULL) { - free(hostPtr->aliases[i]); - i++; - } - free((char *)hostPtr->aliases); - hostPtr->aliases = NULL; - } - - if (hostPtr->addrList != NULL) { - i = 0; - while (hostPtr->addrList[i] != NULL) { - free(hostPtr->addrList[i]); - i++; - } - free((char *)hostPtr->addrList); - hostPtr->addrList = NULL; - } - - if (hostPtr->servers != NULL) { - i = 0; - while (hostPtr->servers[i] != NULL) { - - if (hostPtr->servers[i]->name != NULL) { - free(hostPtr->servers[i]->name); - } - - if (hostPtr->servers[i]->domains != NULL) { - j = 0; - while (hostPtr->servers[i]->domains[j] != NULL) { - free(hostPtr->servers[i]->domains[j]); - j++; - } - free((char *)hostPtr->servers[i]->domains); - } - - if (hostPtr->servers[i]->addrList != NULL) { - j = 0; - while (hostPtr->servers[i]->addrList[j] != NULL) { - free(hostPtr->servers[i]->addrList[j]); - j++; - } - free((char *)hostPtr->servers[i]->addrList); - } - free((char *)hostPtr->servers[i]); - i++; - } - free((char *)hostPtr->servers); - hostPtr->servers = NULL; - } -} diff --git a/usr.sbin/named/tools/nslookup/list.c b/usr.sbin/named/tools/nslookup/list.c deleted file mode 100644 index 640c7e58c7c..00000000000 --- a/usr.sbin/named/tools/nslookup/list.c +++ /dev/null @@ -1,945 +0,0 @@ -/* - * Copyright (c) 1985,1989 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -/*static char sccsid[] = "from: @(#)list.c 5.23 (Berkeley) 3/21/91";*/ -static char rcsid[] = "$Id: list.c,v 1.1 1995/10/18 08:47:55 deraadt Exp $"; -#endif /* not lint */ - -/* - ******************************************************************************* - * - * list.c -- - * - * Routines to obtain info from name and finger servers. - * - * Adapted from 4.3BSD BIND ns_init.c and from finger.c. - * - ******************************************************************************* - */ - -#include <sys/param.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/nameser.h> -#include <arpa/inet.h> -#include <resolv.h> -#include <netdb.h> -#include <stdio.h> -#include <string.h> -#include <ctype.h> -#include <errno.h> -#include "res.h" - -/* - * Imported from res_debug.c - */ -extern char *_res_resultcodes[]; - -extern int errno; - -typedef union { - HEADER qb1; - char qb2[PACKETSZ]; -} querybuf; - -extern HostInfo *defaultPtr; -extern HostInfo curHostInfo; -extern int curHostValid; -extern int queryType; -extern int queryClass; - -static int sockFD = -1; -static int ListSubr(); - -/* - * During a listing to a file, hash marks are printed - * every HASH_SIZE records. - */ - -#define HASH_SIZE 50 - - -/* - ******************************************************************************* - * - * ListHosts -- - * ListHostsByType -- - * - * Requests the name server to do a zone transfer so we - * find out what hosts it knows about. - * - * For ListHosts, there are five types of output: - * - Internet addresses (default) - * - cpu type and operating system (-h option) - * - canonical and alias names (-a option) - * - well-known service names (-s option) - * - ALL records (-d option) - * ListHostsByType prints records of the default type or of a speicific - * type. - * - * To see all types of information sorted by name, do the following: - * ls -d domain.edu > file - * view file - * - * Results: - * SUCCESS the listing was successful. - * ERROR the server could not be contacted because - * a socket could not be obtained or an error - * occured while receiving, or the output file - * could not be opened. - * - ******************************************************************************* - */ - -void -ListHostsByType(string, putToFile) - char *string; - int putToFile; -{ - int i, qtype, result; - char *namePtr; - char name[NAME_LEN]; - char option[NAME_LEN]; - - /* - * Parse the command line. It maybe of the form "ls -t domain" - * or "ls -t type domain". - */ - - i = sscanf(string, " ls -t %s %s", option, name); - if (putToFile && i == 2 && name[0] == '>') { - i--; - } - if (i == 2) { - qtype = StringToType(option, -1); - if (qtype == -1) - return; - namePtr = name; - } else if (i == 1) { - namePtr = option; - qtype = queryType; - } else { - fprintf(stderr, "*** ls: invalid request %s\n",string); - return; - } - result = ListSubr(qtype, namePtr, putToFile ? string : NULL); - if (result != SUCCESS) - fprintf(stderr, "*** Can't list domain %s: %s\n", - namePtr, DecodeError(result)); -} - -void -ListHosts(string, putToFile) - char *string; - int putToFile; -{ - int i, qtype, result; - char *namePtr; - char name[NAME_LEN]; - char option[NAME_LEN]; - - /* - * Parse the command line. It maybe of the form "ls domain", - * "ls -X domain". - */ - i = sscanf(string, " ls %s %s", option, name); - if (putToFile && i == 2 && name[0] == '>') { - i--; - } - if (i == 2) { - if (strcmp("-a", option) == 0) { - qtype = T_CNAME; - } else if (strcmp("-h", option) == 0) { - qtype = T_HINFO; - } else if (strcmp("-m", option) == 0) { - qtype = T_MX; - } else if (strcmp("-s", option) == 0) { - qtype = T_WKS; - } else if (strcmp("-d", option) == 0) { - qtype = T_ANY; - } else { - qtype = T_A; - } - namePtr = name; - } else if (i == 1) { - namePtr = option; - qtype = T_A; - } else { - fprintf(stderr, "*** ls: invalid request %s\n",string); - return; - } - result = ListSubr(qtype, namePtr, putToFile ? string : NULL); - if (result != SUCCESS) - fprintf(stderr, "*** Can't list domain %s: %s\n", - namePtr, DecodeError(result)); -} - -static int -ListSubr(qtype, domain, cmd) - int qtype; - char *domain; - char *cmd; -{ - querybuf buf; - struct sockaddr_in sin; - HEADER *headerPtr; - int msglen; - int amtToRead; - int numRead; - int numAnswers = 0; - int result; - int soacnt = 0; - u_short len; - char *cp, *nmp; - char dname[2][NAME_LEN]; - char file[NAME_LEN]; - static char *answer = NULL; - static int answerLen = 0; - enum { - NO_ERRORS, - ERR_READING_LEN, - ERR_READING_MSG, - ERR_PRINTING, - } error = NO_ERRORS; - - /* - * Create a query packet for the requested domain name. - */ - msglen = res_mkquery(QUERY, domain, queryClass, T_AXFR, - (char *)0, 0, 0, - (char *) &buf, sizeof(buf)); - if (msglen < 0) { - if (_res.options & RES_DEBUG) { - fprintf(stderr, "*** ls: res_mkquery failed\n"); - } - return (ERROR); - } - - bzero((char *)&sin, sizeof(sin)); - sin.sin_family = AF_INET; - sin.sin_port = htons(nsport); - - /* - * Check to see if we have the address of the server or the - * address of a server who knows about this domain. - * - * For now, just use the first address in the list. - */ - - if (defaultPtr->addrList != NULL) { - sin.sin_addr = *(struct in_addr *) defaultPtr->addrList[0]; - } else { - sin.sin_addr = *(struct in_addr *)defaultPtr->servers[0]->addrList[0]; - } - - /* - * Set up a virtual circuit to the server. - */ - if ((sockFD = socket(AF_INET, SOCK_STREAM, 0)) < 0) { - perror("ls: socket"); - return(ERROR); - } - if (connect(sockFD, (struct sockaddr *)&sin, sizeof(sin)) < 0) { - int e; - if (errno == ECONNREFUSED) { - e = NO_RESPONSE; - } else { - perror("ls: connect"); - e = ERROR; - } - (void) close(sockFD); - sockFD = -1; - return e; - } - - /* - * Send length & message for zone transfer - */ - - len = htons(msglen); - - if (write(sockFD, (char *)&len, sizeof(len)) != sizeof(len) || - write(sockFD, (char *) &buf, msglen) != msglen) { - perror("ls: write"); - (void) close(sockFD); - sockFD = -1; - return(ERROR); - } - - fprintf(stdout,"[%s]\n", - (defaultPtr->addrList != NULL) ? defaultPtr->name : - defaultPtr->servers[0]->name); - - if (cmd == NULL) { - filePtr = stdout; - } else { - filePtr = OpenFile(cmd, file); - if (filePtr == NULL) { - fprintf(stderr, "*** Can't open %s for writing\n", file); - (void) close(sockFD); - sockFD = -1; - return(ERROR); - } - fprintf(filePtr, "> %s\n", cmd); - fprintf(filePtr,"[%s]\n", - (defaultPtr->addrList != NULL) ? defaultPtr->name : - defaultPtr->servers[0]->name); - } - -#if 0 - if (qtype == T_CNAME) { - fprintf(filePtr, "%-30s", "Alias"); - } else if (qtype == T_TXT) { - fprintf(filePtr, "%-30s", "Key"); - } else { - fprintf(filePtr, "%-30s", "Host or domain name"); - } - switch (qtype) { - case T_A: - fprintf(filePtr, " %-30s\n", "Internet Address"); - break; - case T_HINFO: - fprintf(filePtr, " %-30s\n", "CPU & OS"); - break; - case T_CNAME: - fprintf(filePtr, " %-30s\n", "Canonical Name"); - break; - case T_MX: - fprintf(filePtr, " %-30s\n", "Metric & Host"); - break; - case T_WKS: - fprintf(filePtr, " %-4s %s\n", "Protocol", "Services"); - break; - case T_MB: - fprintf(filePtr, " %-30s\n", "Mailbox"); - break; - case T_MG: - fprintf(filePtr, " %-30s\n", "Mail Group"); - break; - case T_MR: - fprintf(filePtr, " %-30s\n", "Mail Rename"); - break; - case T_MINFO: - fprintf(filePtr, " %-30s\n", "Mail List Requests & Errors"); - break; - case T_UINFO: - fprintf(filePtr, " %-30s\n", "User Information"); - break; - case T_UID: - fprintf(filePtr, " %-30s\n", "User ID"); - break; - case T_GID: - fprintf(filePtr, " %-30s\n", "Group ID"); - break; - case T_TXT: - fprintf(filePtr, " %-30s\n", "Text"); - break; - case T_NS: - fprintf(filePtr, " %-30s\n", "Name Servers"); - break; - case T_PTR: - fprintf(filePtr, " %-30s\n", "Pointers"); - break; - case T_SOA: - fprintf(filePtr, " %-30s\n", "Start of Authority"); - break; - case T_ANY: - fprintf(filePtr, " %-30s\n", "Resource Record Info."); - break; - } -#endif - - - dname[0][0] = '\0'; - while (1) { - unsigned short tmp; - - /* - * Read the length of the response. - */ - - cp = (char *) &tmp; - amtToRead = sizeof(u_short); - while (amtToRead > 0 && (numRead=read(sockFD, cp, amtToRead)) > 0) { - cp += numRead; - amtToRead -= numRead; - } - if (numRead <= 0) { - error = ERR_READING_LEN; - break; - } - - if ((len = htons(tmp)) == 0) { - break; /* nothing left to read */ - } - - /* - * The server sent too much data to fit the existing buffer -- - * allocate a new one. - */ - if (len > answerLen) { - if (answerLen != 0) { - free(answer); - } - answerLen = len; - answer = Malloc(answerLen); - } - - /* - * Read the response. - */ - - amtToRead = len; - cp = answer; - while (amtToRead > 0 && (numRead=read(sockFD, cp, amtToRead)) > 0) { - cp += numRead; - amtToRead -= numRead; - } - if (numRead <= 0) { - error = ERR_READING_MSG; - break; - } - - result = PrintListInfo(filePtr, answer, cp, qtype, dname[0]); - if (result != SUCCESS) { - error = ERR_PRINTING; - break; - } - - numAnswers++; - if (cmd != NULL && ((numAnswers % HASH_SIZE) == 0)) { - fprintf(stdout, "#"); - fflush(stdout); - } - cp = answer + sizeof(HEADER); - if (ntohs(((HEADER* )answer)->qdcount) > 0) - cp += dn_skipname((u_char *)cp, - (u_char *)answer + len) + QFIXEDSZ; - nmp = cp; - cp += dn_skipname((u_char *)cp, (u_char *)answer + len); - if ((_getshort(cp) == T_SOA)) { - dn_expand((u_char *)answer, (u_char *)answer + len, - (u_char *)nmp, (u_char *)dname[soacnt], - sizeof(dname[0])); - if (soacnt) { - if (strcmp(dname[0], dname[1]) == 0) - break; - } else - soacnt++; - } - } - - if (cmd != NULL) { - fprintf(stdout, "%sReceived %d record%s.\n", - (numAnswers >= HASH_SIZE) ? "\n" : "", - numAnswers, - (numAnswers != 1) ? "s" : ""); - } - - (void) close(sockFD); - sockFD = -1; - if (cmd != NULL && filePtr != NULL) { - fclose(filePtr); - filePtr = NULL; - } - - switch (error) { - case NO_ERRORS: - return (SUCCESS); - - case ERR_READING_LEN: - return(ERROR); - - case ERR_PRINTING: - return(result); - - case ERR_READING_MSG: - headerPtr = (HEADER *) answer; - fprintf(stderr,"*** ls: error receiving zone transfer:\n"); - fprintf(stderr, - " result: %s, answers = %d, authority = %d, additional = %d\n", - _res_resultcodes[headerPtr->rcode], - ntohs(headerPtr->ancount), ntohs(headerPtr->nscount), - ntohs(headerPtr->arcount)); - return(ERROR); - default: - return(ERROR); - } -} - - -/* - ******************************************************************************* - * - * PrintListInfo -- - * - * Used by the ListInfo routine to print the answer - * received from the name server. Only the desired - * information is printed. - * - * Results: - * SUCCESS the answer was printed without a problem. - * NO_INFO the answer packet did not contain an answer. - * ERROR the answer was malformed. - * Misc. errors returned in the packet header. - * - ******************************************************************************* - */ - -#define NAME_FORMAT " %-30s" - -static Boolean -strip_domain(string, domain) - char *string, *domain; -{ - register char *dot; - - if (*domain != '\0') { - dot = string; - while ((dot = strchr(dot, '.')) != NULL && strcasecmp(domain, ++dot)) - ; - if (dot != NULL) { - dot[-1] = '\0'; - return TRUE; - } - } - return FALSE; -} - - -PrintListInfo(file, msg, eom, qtype, domain) - FILE *file; - u_char *msg, *eom; - int qtype; - char *domain; -{ - register u_char *cp; - HEADER *headerPtr; - int type, class, dlen, nameLen; - u_long ttl; - int n, pref; - struct in_addr inaddr; - char name[NAME_LEN]; - char name2[NAME_LEN]; - Boolean stripped; - - /* - * Read the header fields. - */ - headerPtr = (HEADER *)msg; - cp = msg + sizeof(HEADER); - if (headerPtr->rcode != NOERROR) { - return(headerPtr->rcode); - } - - /* - * We are looking for info from answer resource records. - * If there aren't any, return with an error. We assume - * there aren't any question records. - */ - - if (ntohs(headerPtr->ancount) == 0) { - return(NO_INFO); - } else { - if (ntohs(headerPtr->qdcount) > 0) { - nameLen = dn_skipname(cp, eom); - if (nameLen < 0) - return (ERROR); - cp += nameLen + QFIXEDSZ; - } - if ((nameLen = - dn_expand(msg, eom, cp, (u_char *)name, sizeof(name))) < 0) - return (ERROR); - cp += nameLen; - - type = _getshort(cp); - cp += sizeof(u_short); - - if (!(type == qtype || qtype == T_ANY) && - !((type == T_NS || type == T_PTR) && qtype == T_A)) - return(SUCCESS); - - class = _getshort(cp); - cp += sizeof(u_short); - ttl = _getlong(cp); - cp += sizeof(u_long); - dlen = _getshort(cp); - cp += sizeof(u_short); - - if (name[0] == 0) - strcpy(name, "(root)"); - - /* Strip the domain name from the data, if desired. */ - stripped = FALSE; - if ((_res.options & RES_DEBUG) == 0) { - if (type != T_SOA) { - stripped = strip_domain(name, domain); - } - } - if (!stripped && nameLen < sizeof(name)-1) { - strcat(name, "."); - } - - fprintf(file, NAME_FORMAT, name); - - if (qtype == T_ANY) { - if (_res.options & RES_DEBUG) { - fprintf(file,"\t%lu %-5s", ttl, p_class(queryClass)); - } - fprintf(file," %-5s", p_type(type)); - } - - /* XXX merge this into debug.c's print routines */ - - switch (type) { - case T_A: - if (class == C_IN) { - bcopy(cp, (char *)&inaddr, sizeof(inaddr)); - if (dlen == 4) { - fprintf(file," %s", inet_ntoa(inaddr)); - } else if (dlen == 7) { - fprintf(file," %s", inet_ntoa(inaddr)); - fprintf(file," (%d, %d)", cp[4],(cp[5] << 8) + cp[6]); - } else - fprintf(file, " (dlen = %d?)", dlen); - } - break; - - case T_CNAME: - case T_MB: - case T_MG: - case T_MR: - if ((nameLen = dn_expand(msg, eom, - cp, (u_char *)name2, sizeof(name2))) < 0) { - fprintf(file, " ***\n"); - return (ERROR); - } - fprintf(file, " %s", name2); - break; - - case T_NS: - case T_PTR: - putc(' ', file); - if (qtype != T_ANY) - fprintf(file,"%s = ", type == T_PTR ? "host" : "server"); - cp = (u_char *)Print_cdname2(cp, msg, eom, file); - break; - - case T_HINFO: - if (n = *cp++) { - (void)sprintf(name,"%.*s", n, cp); - fprintf(file," %-10s", name); - cp += n; - } else { - fprintf(file," %-10s", " "); - } - if (n = *cp++) { - fprintf(file," %.*s", n, cp); - cp += n; - } - break; - - case T_SOA: - if ((nameLen = dn_expand(msg, - eom, cp, (u_char *)name2, sizeof(name2))) < 0) { - fprintf(file, " ***\n"); - return (ERROR); - } - cp += nameLen; - fprintf(file, " %s", name2); - if ((nameLen = dn_expand(msg, - eom, cp, (u_char *)name2, sizeof(name2))) < 0) { - fprintf(file, " ***\n"); - return (ERROR); - } - cp += nameLen; - fprintf(file, " %s. (", name2); - for (n = 0; n < 5; n++) { - u_long u; - - u = _getlong(cp); - cp += sizeof(u_long); - fprintf(file,"%s%lu", n? " " : "", u); - } - fprintf(file, ")"); - break; - - case T_MX: - pref = _getshort(cp); - cp += sizeof(u_short); - fprintf(file," %-3d ",pref); - if ((nameLen = dn_expand(msg, - eom, cp, (u_char *)name2, sizeof(name2))) < 0) { - fprintf(file, " ***\n"); - return (ERROR); - } - fprintf(file, " %s", name2); - break; - - case T_TXT: - { - u_char *cp2 = cp + dlen; - int c; - - (void) fputs(" \"", file); - while (cp < cp2) { - if (n = (unsigned char) *cp++) { - for (c = n; c > 0 && cp < cp2; c--) - if (*cp == '\n') { - (void) putc('\\', file); - (void) putc(*cp++, file); - } else - (void) putc(*cp++, file); - } - } - (void) putc('"', file); - } - break; - - case T_MINFO: - (void) putc(' ', file); - cp = (u_char *)Print_cdname(cp, msg, eom, file); - fprintf(file, " "); - cp = (u_char *)Print_cdname(cp, msg, eom, file); - break; - - case T_UINFO: - fprintf(file, " %s", cp); - break; - - case T_UID: - case T_GID: - fprintf(file, " %lu", _getlong(cp)); - break; - - case T_WKS: - if (class == C_IN) { - struct protoent *pp; - struct servent *ss; - u_short port; - - cp += 4; /* skip inet address */ - dlen -= 4; - - setprotoent(1); - setservent(1); - n = *cp & 0377; - pp = getprotobynumber(n); - if (pp == 0) - fprintf(file," %-3d ", n); - else - fprintf(file," %-3s ", pp->p_name); - cp++; dlen--; - - port = 0; - while (dlen-- > 0) { - n = *cp++; - do { - if (n & 0200) { - ss = getservbyport((int)htons(port), - pp->p_name); - if (ss == 0) - fprintf(file," %u", port); - else - fprintf(file," %s", ss->s_name); - } - n <<= 1; - } while (++port & 07); - } - endprotoent(); - endservent(); - } - break; - } - fprintf(file,"\n"); - } - return(SUCCESS); -} - - -/* - ******************************************************************************* - * - * ViewList -- - * - * A hack to view the output of the ls command in sorted - * order using more. - * - ******************************************************************************* - */ - -ViewList(string) - char *string; -{ - char file[NAME_LEN]; - char command[NAME_LEN]; - - sscanf(string, " view %s", file); - (void)sprintf(command, "grep \"^ \" %s | sort | more", file); - system(command); -} - -/* - ******************************************************************************* - * - * Finger -- - * - * Connects with the finger server for the current host - * to request info on the specified person (long form) - * who is on the system (short form). - * - * Results: - * SUCCESS the finger server was contacted. - * ERROR the server could not be contacted because - * a socket could not be obtained or connected - * to or the service could not be found. - * - ******************************************************************************* - */ - -Finger(string, putToFile) - char *string; - int putToFile; -{ - struct servent *sp; - struct sockaddr_in sin; - register FILE *f; - register int c; - register int lastc; - char name[NAME_LEN]; - char file[NAME_LEN]; - - /* - * We need a valid current host info to get an inet address. - */ - if (!curHostValid) { - fprintf(stderr, "Finger: no current host defined.\n"); - return (ERROR); - } - - if (sscanf(string, " finger %s", name) == 1) { - if (putToFile && (name[0] == '>')) { - name[0] = '\0'; - } - } else { - name[0] = '\0'; - } - - sp = getservbyname("finger", "tcp"); - if (sp == 0) { - fprintf(stderr, "Finger: unknown service\n"); - return (ERROR); - } - - bzero((char *)&sin, sizeof(sin)); - sin.sin_family = curHostInfo.addrType; - sin.sin_port = sp->s_port; - bcopy(curHostInfo.addrList[0], (char *)&sin.sin_addr, - curHostInfo.addrLen); - - /* - * Set up a virtual circuit to the host. - */ - - sockFD = socket(curHostInfo.addrType, SOCK_STREAM, 0); - if (sockFD < 0) { - fflush(stdout); - perror("finger: socket"); - return (ERROR); - } - - if (connect(sockFD, (struct sockaddr *)&sin, sizeof (sin)) < 0) { - fflush(stdout); - perror("finger: connect"); - close(sockFD); - sockFD = -1; - return (ERROR); - } - - if (!putToFile) { - filePtr = stdout; - } else { - filePtr = OpenFile(string, file); - if (filePtr == NULL) { - fprintf(stderr, "*** Can't open %s for writing\n", file); - close(sockFD); - sockFD = -1; - return(ERROR); - } - fprintf(filePtr,"> %s\n", string); - } - fprintf(filePtr, "[%s]\n", curHostInfo.name); - - if (name[0] != '\0') { - write(sockFD, "/W ", 3); - } - write(sockFD, name, strlen(name)); - write(sockFD, "\r\n", 2); - f = fdopen(sockFD, "r"); - while ((c = getc(f)) != EOF) { - switch (c) { - case 0210: - case 0211: - case 0212: - case 0214: - c -= 0200; - break; - case 0215: - c = '\n'; - break; - } - putc(lastc = c, filePtr); - } - if (lastc != '\n') { - putc('\n', filePtr); - } - putc('\n', filePtr); - - close(sockFD); - sockFD = -1; - - if (putToFile) { - fclose(filePtr); - filePtr = NULL; - } - return (SUCCESS); -} - -ListHost_close() -{ - if (sockFD != -1) { - (void) close(sockFD); - sockFD = -1; - } -} diff --git a/usr.sbin/named/tools/nslookup/main.c b/usr.sbin/named/tools/nslookup/main.c deleted file mode 100644 index f49a49cd4d8..00000000000 --- a/usr.sbin/named/tools/nslookup/main.c +++ /dev/null @@ -1,1108 +0,0 @@ -/* - * Copyright (c) 1985,1989 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -char copyright[] = -"@(#) Copyright (c) 1985,1989 Regents of the University of California.\n\ - All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -/*static char sccsid[] = "from: @(#)main.c 5.42 (Berkeley) 3/3/91";*/ -static char rcsid[] = "$Id: main.c,v 1.1 1995/10/18 08:47:55 deraadt Exp $"; -#endif /* not lint */ - -/* - ******************************************************************************* - * - * main.c -- - * - * Main routine and some action routines for the name server - * lookup program. - * - * Andrew Cherenson - * U.C. Berkeley Computer Science Div. - * CS298-26, Fall 1985 - * - ******************************************************************************* - */ - -#include <sys/param.h> -#include <netdb.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/nameser.h> -#include <arpa/inet.h> -#include <resolv.h> -#include <signal.h> -#include <setjmp.h> -#include <ctype.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "res.h" -#include "pathnames.h" - -/* - * Default Internet address of the current host. - */ - -#if BSD < 43 -#define LOCALHOST "127.0.0.1" -#endif - - -/* - * Name of a top-level name server. Can be changed with - * the "set root" command. - */ - -#ifndef ROOT_SERVER -#define ROOT_SERVER "ns.nic.ddn.mil." -#endif -char rootServerName[NAME_LEN] = ROOT_SERVER; - - -/* - * Info about the most recently queried host. - */ - -HostInfo curHostInfo; -int curHostValid = FALSE; - - -/* - * Info about the default name server. - */ - -HostInfo *defaultPtr = NULL; -char defaultServer[NAME_LEN]; -struct in_addr defaultAddr; - - -/* - * Initial name server query type is Address. - */ - -int queryType = T_A; -int queryClass = C_IN; - -/* - * Stuff for Interrupt (control-C) signal handler. - */ - -extern void IntrHandler(); -FILE *filePtr; -jmp_buf env; - -static void CvtAddrToPtr(); -static void ReadRC(); - - -/* - ******************************************************************************* - * - * main -- - * - * Initializes the resolver library and determines the address - * of the initial name server. The yylex routine is used to - * read and perform commands. - * - ******************************************************************************* - */ - -main(argc, argv) - int argc; - char **argv; -{ - char *wantedHost = NULL; - Boolean useLocalServer; - int result; - int i; - struct hostent *hp; - extern int h_errno; - - /* - * Initialize the resolver library routines. - */ - - if (res_init() == -1) { - fprintf(stderr,"*** Can't initialize resolver.\n"); - exit(1); - } - - /* - * Allocate space for the default server's host info and - * find the server's address and name. If the resolver library - * already has some addresses for a potential name server, - * then use them. Otherwise, see if the current host has a server. - * Command line arguments may override the choice of initial server. - */ - - defaultPtr = (HostInfo *) Calloc(1, sizeof(HostInfo)); - - /* - * Parse the arguments: - * no args = go into interactive mode, use default host as server - * 1 arg = use as host name to be looked up, default host will be server - * non-interactive mode - * 2 args = 1st arg: - * if it is '-', then - * ignore but go into interactive mode - * else - * use as host name to be looked up, - * go into non-interactive mode - * 2nd arg: name or inet address of server - * - * "Set" options are specified with a leading - and must come before - * any arguments. For example, to find the well-known services for - * a host, type "nslookup -query=wks host" - */ - - ReadRC(); /* look for options file */ - - ++argv; --argc; /* skip prog name */ - - while (argc && *argv[0] == '-' && argv[0][1]) { - (void) SetOption (&(argv[0][1])); - ++argv; --argc; - } - if (argc > 2) { - Usage(); - } - if (argc && *argv[0] != '-') { - wantedHost = *argv; /* name of host to be looked up */ - } - - useLocalServer = FALSE; - if (argc == 2) { - struct in_addr addr; - - /* - * Use an explicit name server. If the hostname lookup fails, - * default to the server(s) in resolv.conf. - */ - - if (inet_aton(*++argv, &addr) != 0) { - _res.nscount = 1; - _res.nsaddr.sin_addr = addr; - } else { - hp = gethostbyname(*argv); - if (hp == NULL) { - fprintf(stderr, "*** Can't find server address for '%s': ", - *argv); - herror((char *)NULL); - fputc('\n', stderr); - } else { -#if BSD < 43 - bcopy(hp->h_addr, (char *)&_res.nsaddr.sin_addr, hp->h_length); - _res.nscount = 1; -#else - for (i = 0; i < MAXNS && hp->h_addr_list[i] != NULL; i++) { - bcopy(hp->h_addr_list[i], - (char *)&_res.nsaddr_list[i].sin_addr, - hp->h_length); - } - _res.nscount = i; -#endif - } - } - } - - - if (_res.nscount == 0 || useLocalServer) { - LocalServer(defaultPtr); - } else { - for (i = 0; i < _res.nscount; i++) { - if (_res.nsaddr_list[i].sin_addr.s_addr == INADDR_ANY) { - LocalServer(defaultPtr); - break; - } else { - result = GetHostInfoByAddr(&(_res.nsaddr_list[i].sin_addr), - &(_res.nsaddr_list[i].sin_addr), - defaultPtr); - if (result != SUCCESS) { - fprintf(stderr, - "*** Can't find server name for address %s: %s\n", - inet_ntoa(_res.nsaddr_list[i].sin_addr), - DecodeError(result)); - } else { - defaultAddr = _res.nsaddr_list[i].sin_addr; - break; - } - } - } - - /* - * If we have exhausted the list, tell the user about the - * command line argument to specify an address. - */ - - if (i == _res.nscount) { - fprintf(stderr, "*** Default servers are not available\n"); - exit(1); - } - - } - strcpy(defaultServer, defaultPtr->name); - - -#ifdef DEBUG -#ifdef DEBUG2 - _res.options |= RES_DEBUG2; -#endif - _res.options |= RES_DEBUG; - _res.retry = 2; -#endif DEBUG - - /* - * If we're in non-interactive mode, look up the wanted host and quit. - * Otherwise, print the initial server's name and continue with - * the initialization. - */ - - if (wantedHost != (char *) NULL) { - LookupHost(wantedHost, 0); - } else { - PrintHostInfo(stdout, "Default Server:", defaultPtr); - - /* - * Setup the environment to allow the interrupt handler to return here. - */ - - (void) setjmp(env); - - /* - * Return here after a longjmp. - */ - - signal(SIGINT, IntrHandler); - signal(SIGPIPE, SIG_IGN); - - /* - * Read and evaluate commands. The commands are described in commands.l - * Yylex returns 0 when ^D or 'exit' is typed. - */ - - printf("> "); - fflush(stdout); - while(yylex()) { - printf("> "); - fflush(stdout); - } - } - exit(0); -} - - -LocalServer(defaultPtr) - HostInfo *defaultPtr; -{ - char hostName[NAME_LEN]; -#if BSD < 43 - int result; -#endif - - gethostname(hostName, sizeof(hostName)); - -#if BSD < 43 - (void) inet_aton(LOCALHOST, &defaultAddr); - result = GetHostInfoByName(&defaultAddr, C_IN, T_A, - hostName, defaultPtr, 1); - if (result != SUCCESS) { - fprintf(stderr, - "*** Can't find initialize address for server %s: %s\n", - defaultServer, DecodeError(result)); - exit(1); - } -#else - defaultAddr.s_addr = htonl(INADDR_ANY); - (void) GetHostInfoByName(&defaultAddr, C_IN, T_A, "0.0.0.0", defaultPtr, 1); - free(defaultPtr->name); - defaultPtr->name = Calloc(1, sizeof(hostName)+1); - strcpy(defaultPtr->name, hostName); -#endif -} - - -/* - ******************************************************************************* - * - * Usage -- - * - * Lists the proper methods to run the program and exits. - * - ******************************************************************************* - */ - -Usage() -{ - fprintf(stderr, "Usage:\n"); - fprintf(stderr, -" nslookup [-opt ...] # interactive mode using default server\n"); - fprintf(stderr, -" nslookup [-opt ...] - server # interactive mode using 'server'\n"); - fprintf(stderr, -" nslookup [-opt ...] host # just look up 'host' using default server\n"); - fprintf(stderr, -" nslookup [-opt ...] host server # just look up 'host' using 'server'\n"); - exit(1); -} - -/* - ******************************************************************************* - * - * IsAddr -- - * - * Returns TRUE if the string looks like an Internet address. - * A string with a trailing dot is not an address, even if it looks - * like one. - * - ******************************************************************************* - */ - -Boolean -IsAddr(host, addrPtr) - char *host; - struct in_addr *addrPtr; /* If return TRUE, contains IP address */ -{ - register char *cp; - - if (isdigit(host[0])) { - /* Make sure it has only digits and dots. */ - for (cp = host; *cp; ++cp) { - if (!isdigit(*cp) && *cp != '.') - return FALSE; - } - /* If it has a trailing dot, don't treat it as an address. */ - if (*--cp != '.') { - if (inet_aton(host, addrPtr) != 0) - return TRUE; - } - } - return FALSE; -} - - -/* - ******************************************************************************* - * - * SetDefaultServer -- - * - * Changes the default name server to the one specified by - * the first argument. The command "server name" uses the current - * default server to lookup the info for "name". The command - * "lserver name" uses the original server to lookup "name". - * - * Side effects: - * This routine will cause a core dump if the allocation requests fail. - * - * Results: - * SUCCESS The default server was changed successfully. - * NONAUTH The server was changed but addresses of - * other servers who know about the requested server - * were returned. - * Errors No info about the new server was found or - * requests to the current server timed-out. - * - ******************************************************************************* - */ - -int -SetDefaultServer(string, local) - char *string; - Boolean local; -{ - register HostInfo *newDefPtr; - struct in_addr *servAddrPtr; - struct in_addr addr; - char newServer[NAME_LEN]; - int result; - int i; - - /* - * Parse the command line. It maybe of the form "server name", - * "lserver name" or just "name". - */ - - if (local) { - i = sscanf(string, " lserver %s", newServer); - } else { - i = sscanf(string, " server %s", newServer); - } - if (i != 1) { - i = sscanf(string, " %s", newServer); - if (i != 1) { - fprintf(stderr,"SetDefaultServer: invalid name: %s\n", string); - return(ERROR); - } - } - - /* - * Allocate space for a HostInfo variable for the new server. Don't - * overwrite the old HostInfo struct because info about the new server - * might not be found and we need to have valid default server info. - */ - - newDefPtr = (HostInfo *) Calloc(1, sizeof(HostInfo)); - - - /* - * A 'local' lookup uses the original server that the program was - * initialized with. - * - * Check to see if we have the address of the server or the - * address of a server who knows about this domain. - * XXX For now, just use the first address in the list. - */ - - if (local) { - servAddrPtr = &defaultAddr; - } else if (defaultPtr->addrList != NULL) { - servAddrPtr = (struct in_addr *) defaultPtr->addrList[0]; - } else { - servAddrPtr = (struct in_addr *) defaultPtr->servers[0]->addrList[0]; - } - - result = ERROR; - if (IsAddr(newServer, &addr)) { - result = GetHostInfoByAddr(servAddrPtr, &addr, newDefPtr); - /* If we can't get the name, fall through... */ - } - if (result != SUCCESS && result != NONAUTH) { - result = GetHostInfoByName(servAddrPtr, C_IN, T_A, - newServer, newDefPtr, 1); - } - - if (result == SUCCESS || result == NONAUTH) { - /* - * Found info about the new server. Free the resources for - * the old server. - */ - - FreeHostInfoPtr(defaultPtr); - free((char *)defaultPtr); - defaultPtr = newDefPtr; - strcpy(defaultServer, defaultPtr->name); - PrintHostInfo(stdout, "Default Server:", defaultPtr); - return(SUCCESS); - } else { - fprintf(stderr, "*** Can't find address for server %s: %s\n", - newServer, DecodeError(result)); - free((char *)newDefPtr); - - return(result); - } -} - -/* - ******************************************************************************* - * - * DoLoookup -- - * - * Common subroutine for LookupHost and LookupHostWithServer. - * - * Results: - * SUCCESS - the lookup was successful. - * Misc. Errors - an error message is printed if the lookup failed. - * - ******************************************************************************* - */ - -static int -DoLookup(host, servPtr, serverName) - char *host; - HostInfo *servPtr; - char *serverName; -{ - int result; - struct in_addr *servAddrPtr; - struct in_addr addr; - - /* Skip escape character */ - if (host[0] == '\\') - host++; - - /* - * If the user gives us an address for an address query, - * silently treat it as a PTR query. If the query type is already - * PTR, then convert the address into the in-addr.arpa format. - * - * Use the address of the server if it exists, otherwise use the - * address of a server who knows about this domain. - * XXX For now, just use the first address in the list. - */ - - if (servPtr->addrList != NULL) { - servAddrPtr = (struct in_addr *) servPtr->addrList[0]; - } else { - servAddrPtr = (struct in_addr *) servPtr->servers[0]->addrList[0]; - } - - /* - * RFC1123 says we "SHOULD check the string syntactically for a - * dotted-decimal number before looking it up [...]" (p. 13). - */ - if (queryType == T_A && IsAddr(host, &addr)) { - result = GetHostInfoByAddr(servAddrPtr, &addr, &curHostInfo); - } else { - if (queryType == T_PTR) { - CvtAddrToPtr(host); - } - result = GetHostInfoByName(servAddrPtr, queryClass, queryType, host, - &curHostInfo, 0); - } - - switch (result) { - case SUCCESS: - /* - * If the query was for an address, then the &curHostInfo - * variable can be used by Finger. - * There's no need to print anything for other query types - * because the info has already been printed. - */ - if (queryType == T_A) { - curHostValid = TRUE; - PrintHostInfo(filePtr, "Name:", &curHostInfo); - } - break; - - /* - * No Authoritative answer was available but we got names - * of servers who know about the host. - */ - case NONAUTH: - PrintHostInfo(filePtr, "Name:", &curHostInfo); - break; - - case NO_INFO: - fprintf(stderr, "*** No %s (%s) records available for %s\n", - DecodeType(queryType), p_type(queryType), host); - break; - - case TIME_OUT: - fprintf(stderr, "*** Request to %s timed-out\n", serverName); - break; - - default: - fprintf(stderr, "*** %s can't find %s: %s\n", serverName, host, - DecodeError(result)); - } - return result; -} - -/* - ******************************************************************************* - * - * LookupHost -- - * - * Asks the default name server for information about the - * specified host or domain. The information is printed - * if the lookup was successful. - * - * Results: - * ERROR - the output file could not be opened. - * + results of DoLookup - * - ******************************************************************************* - */ - -int -LookupHost(string, putToFile) - char *string; - Boolean putToFile; -{ - char host[NAME_LEN]; - char file[NAME_LEN]; - int result; - - /* - * Invalidate the current host information to prevent Finger - * from using bogus info. - */ - - curHostValid = FALSE; - - /* - * Parse the command string into the host and - * optional output file name. - * - */ - - sscanf(string, " %s", host); /* removes white space */ - if (!putToFile) { - filePtr = stdout; - } else { - filePtr = OpenFile(string, file); - if (filePtr == NULL) { - fprintf(stderr, "*** Can't open %s for writing\n", file); - return(ERROR); - } - fprintf(filePtr,"> %s\n", string); - } - - PrintHostInfo(filePtr, "Server:", defaultPtr); - - result = DoLookup(host, defaultPtr, defaultServer); - - if (putToFile) { - fclose(filePtr); - filePtr = NULL; - } - return(result); -} - -/* - ******************************************************************************* - * - * LookupHostWithServer -- - * - * Asks the name server specified in the second argument for - * information about the host or domain specified in the first - * argument. The information is printed if the lookup was successful. - * - * Address info about the requested name server is obtained - * from the default name server. This routine will return an - * error if the default server doesn't have info about the - * requested server. Thus an error return status might not - * mean the requested name server doesn't have info about the - * requested host. - * - * Comments from LookupHost apply here, too. - * - * Results: - * ERROR - the output file could not be opened. - * + results of DoLookup - * - ******************************************************************************* - */ - -int -LookupHostWithServer(string, putToFile) - char *string; - Boolean putToFile; -{ - char file[NAME_LEN]; - char host[NAME_LEN]; - char server[NAME_LEN]; - int result; - static HostInfo serverInfo; - - curHostValid = FALSE; - - sscanf(string, " %s %s", host, server); - if (!putToFile) { - filePtr = stdout; - } else { - filePtr = OpenFile(string, file); - if (filePtr == NULL) { - fprintf(stderr, "*** Can't open %s for writing\n", file); - return(ERROR); - } - fprintf(filePtr,"> %s\n", string); - } - - result = GetHostInfoByName( - defaultPtr->addrList ? - (struct in_addr *) defaultPtr->addrList[0] : - (struct in_addr *) defaultPtr->servers[0]->addrList[0], - C_IN, T_A, server, &serverInfo, 1); - - if (result != SUCCESS) { - fprintf(stderr,"*** Can't find address for server %s: %s\n", server, - DecodeError(result)); - } else { - PrintHostInfo(filePtr, "Server:", &serverInfo); - - result = DoLookup(host, &serverInfo, server); - } - if (putToFile) { - fclose(filePtr); - filePtr = NULL; - } - return(result); -} - -/* - ******************************************************************************* - * - * SetOption -- - * - * This routine is used to change the state information - * that affect the lookups. The command format is - * set keyword[=value] - * Most keywords can be abbreviated. Parsing is very simplistic-- - * A value must not be separated from its keyword by white space. - * - * Valid keywords: Meaning: - * all lists current values of options. - * ALL lists current values of options, including - * hidden options. - * [no]d2 turn on/off extra debugging mode. - * [no]debug turn on/off debugging mode. - * [no]defname use/don't use default domain name. - * [no]search use/don't use domain search list. - * domain=NAME set default domain name to NAME. - * [no]ignore ignore/don't ignore trunc. errors. - * query=value set default query type to value, - * value is one of the query types in RFC883 - * without the leading T_. (e.g., A, HINFO) - * [no]recurse use/don't use recursive lookup. - * retry=# set number of retries to #. - * root=NAME change root server to NAME. - * time=# set timeout length to #. - * [no]vc use/don't use virtual circuit. - * port TCP/UDP port to server. - * - * Deprecated: - * [no]primary use/don't use primary server. - * - * Results: - * SUCCESS the command was parsed correctly. - * ERROR the command was not parsed correctly. - * - ******************************************************************************* - */ - -int -SetOption(option) - register char *option; -{ - char type[NAME_LEN]; - char *ptr; - int tmp; - - while (isspace(*option)) - ++option; - if (strncmp (option, "set ", 4) == 0) - option += 4; - while (isspace(*option)) - ++option; - - if (*option == 0) { - fprintf(stderr, "*** Invalid set command\n"); - return(ERROR); - } else { - if (strncmp(option, "all", 3) == 0) { - ShowOptions(); - } else if (strncmp(option, "ALL", 3) == 0) { - ShowOptions(); - } else if (strncmp(option, "d2", 2) == 0) { /* d2 (more debug) */ - _res.options |= (RES_DEBUG | RES_DEBUG2); - } else if (strncmp(option, "nod2", 4) == 0) { - _res.options &= ~RES_DEBUG2; - printf("d2 mode disabled; still in debug mode\n"); - } else if (strncmp(option, "def", 3) == 0) { /* defname */ - _res.options |= RES_DEFNAMES; - } else if (strncmp(option, "nodef", 5) == 0) { - _res.options &= ~RES_DEFNAMES; - } else if (strncmp(option, "do", 2) == 0) { /* domain */ - ptr = strchr(option, '='); - if (ptr != NULL) { - sscanf(++ptr, "%s", _res.defdname); - res_re_init(); - } - } else if (strncmp(option, "deb", 1) == 0) { /* debug */ - _res.options |= RES_DEBUG; - } else if (strncmp(option, "nodeb", 5) == 0) { - _res.options &= ~(RES_DEBUG | RES_DEBUG2); - } else if (strncmp(option, "ig", 2) == 0) { /* ignore */ - _res.options |= RES_IGNTC; - } else if (strncmp(option, "noig", 4) == 0) { - _res.options &= ~RES_IGNTC; - } else if (strncmp(option, "po", 2) == 0) { /* port */ - ptr = strchr(option, '='); - if (ptr != NULL) { - sscanf(++ptr, "%hu", &nsport); - } -#ifdef deprecated - } else if (strncmp(option, "pri", 3) == 0) { /* primary */ - _res.options |= RES_PRIMARY; - } else if (strncmp(option, "nopri", 5) == 0) { - _res.options &= ~RES_PRIMARY; -#endif - } else if (strncmp(option, "q", 1) == 0 || /* querytype */ - strncmp(option, "ty", 2) == 0) { /* type */ - ptr = strchr(option, '='); - if (ptr != NULL) { - sscanf(++ptr, "%s", type); - queryType = StringToType(type, queryType); - } - } else if (strncmp(option, "cl", 2) == 0) { /* query class */ - ptr = strchr(option, '='); - if (ptr != NULL) { - sscanf(++ptr, "%s", type); - queryClass = StringToClass(type, queryClass); - } - } else if (strncmp(option, "rec", 3) == 0) { /* recurse */ - _res.options |= RES_RECURSE; - } else if (strncmp(option, "norec", 5) == 0) { - _res.options &= ~RES_RECURSE; - } else if (strncmp(option, "ret", 3) == 0) { /* retry */ - ptr = strchr(option, '='); - if (ptr != NULL) { - sscanf(++ptr, "%d", &tmp); - if (tmp >= 0) { - _res.retry = tmp; - } - } - } else if (strncmp(option, "ro", 2) == 0) { /* root */ - ptr = strchr(option, '='); - if (ptr != NULL) { - sscanf(++ptr, "%s", rootServerName); - } - } else if (strncmp(option, "sea", 3) == 0) { /* search list */ - _res.options |= RES_DNSRCH; - } else if (strncmp(option, "nosea", 5) == 0) { - _res.options &= ~RES_DNSRCH; - } else if (strncmp(option, "srchl", 5) == 0) { /* domain search list */ - ptr = strchr(option, '='); - if (ptr != NULL) { - res_dnsrch(++ptr); - } - } else if (strncmp(option, "ti", 2) == 0) { /* timeout */ - ptr = strchr(option, '='); - if (ptr != NULL) { - sscanf(++ptr, "%d", &tmp); - if (tmp >= 0) { - _res.retrans = tmp; - } - } - } else if (strncmp(option, "v", 1) == 0) { /* vc */ - _res.options |= RES_USEVC; - } else if (strncmp(option, "nov", 3) == 0) { - _res.options &= ~RES_USEVC; - } else { - fprintf(stderr, "*** Invalid option: %s\n", option); - return(ERROR); - } - } - return(SUCCESS); -} - -/* - * Fake a reinitialization when the domain is changed. - */ -res_re_init() -{ - register char *cp, **pp; - int n; - - /* find components of local domain that might be searched */ - pp = _res.dnsrch; - *pp++ = _res.defdname; - for (cp = _res.defdname, n = 0; *cp; cp++) - if (*cp == '.') - n++; - cp = _res.defdname; - for (; n >= LOCALDOMAINPARTS && pp < _res.dnsrch + MAXDFLSRCH; n--) { - cp = strchr(cp, '.'); - *pp++ = ++cp; - } - *pp = 0; - _res.options |= RES_INIT; -} - -#define SRCHLIST_SEP '/' - -res_dnsrch(cp) - register char *cp; -{ - register char **pp; - int n; - - (void)strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1); - if ((cp = strchr(_res.defdname, '\n')) != NULL) - *cp = '\0'; - /* - * Set search list to be blank-separated strings - * on rest of line. - */ - cp = _res.defdname; - pp = _res.dnsrch; - *pp++ = cp; - for (n = 0; *cp && pp < _res.dnsrch + MAXDNSRCH; cp++) { - if (*cp == SRCHLIST_SEP) { - *cp = '\0'; - n = 1; - } else if (n) { - *pp++ = cp; - n = 0; - } - } - if ((cp = strchr(pp[-1], SRCHLIST_SEP)) != NULL) { - *cp = '\0'; - } - *pp = NULL; -} - - -/* - ******************************************************************************* - * - * ShowOptions -- - * - * Prints out the state information used by the resolver - * library and other options set by the user. - * - ******************************************************************************* - */ - -void -ShowOptions() -{ - register char **cp; - - PrintHostInfo(stdout, "Default Server:", defaultPtr); - if (curHostValid) { - PrintHostInfo(stdout, "Host:", &curHostInfo); - } - - printf("Set options:\n"); - printf(" %sdebug \t", (_res.options & RES_DEBUG) ? "" : "no"); - printf(" %sdefname\t", (_res.options & RES_DEFNAMES) ? "" : "no"); - printf(" %ssearch\t", (_res.options & RES_DNSRCH) ? "" : "no"); - printf(" %srecurse\n", (_res.options & RES_RECURSE) ? "" : "no"); - - printf(" %sd2\t\t", (_res.options & RES_DEBUG2) ? "" : "no"); - printf(" %svc\t\t", (_res.options & RES_USEVC) ? "" : "no"); - printf(" %signoretc\t", (_res.options & RES_IGNTC) ? "" : "no"); - printf(" port=%u\n", nsport); - - printf(" querytype=%s\t", p_type(queryType)); - printf(" class=%s\t", p_class(queryClass)); - printf(" timeout=%d\t", _res.retrans); - printf(" retry=%d\n", _res.retry); - printf(" root=%s\n", rootServerName); - printf(" domain=%s\n", _res.defdname); - - if (cp = _res.dnsrch) { - printf(" srchlist=%s", *cp); - for (cp++; *cp; cp++) { - printf("%c%s", SRCHLIST_SEP, *cp); - } - putchar('\n'); - } - putchar('\n'); -} -#undef SRCHLIST_SEP - -/* - ******************************************************************************* - * - * PrintHelp -- - * - * Prints out the help file. - * (Code taken from Mail.) - * - ******************************************************************************* - */ - -void -PrintHelp() -{ - register int c; - register FILE *helpFilePtr; - - if ((helpFilePtr = fopen(_PATH_HELPFILE, "r")) == NULL) { - perror(_PATH_HELPFILE); - return; - } - while ((c = getc(helpFilePtr)) != EOF) { - putchar((char) c); - } - fclose(helpFilePtr); -} - -/* - ******************************************************************************* - * - * CvtAddrToPtr -- - * - * Convert a dotted-decimal Internet address into the standard - * PTR format (reversed address with .in-arpa. suffix). - * - * Assumes the argument buffer is large enougth to hold the result. - * - ******************************************************************************* - */ - -static void -CvtAddrToPtr(name) - char *name; -{ - char *p; - int ip[4]; - struct in_addr addr; - - if (IsAddr(name, &addr)) { - p = inet_ntoa(addr); - if (sscanf(p, "%d.%d.%d.%d", &ip[0], &ip[1], &ip[2], &ip[3]) == 4) { - sprintf(name, "%d.%d.%d.%d.in-addr.arpa.", - ip[3], ip[2], ip[1], ip[0]); - } - } -} - -/* - ******************************************************************************* - * - * ReadRC -- - * - * Use the contents of ~/.nslookuprc as options. - * - ******************************************************************************* - */ - -static void -ReadRC() -{ - register FILE *fp; - register char *cp; - char buf[NAME_LEN]; - - if ((cp = getenv("HOME")) != NULL) { - (void) strcpy(buf, cp); - (void) strcat(buf, "/.nslookuprc"); - - if ((fp = fopen(buf, "r")) != NULL) { - while (fgets(buf, sizeof(buf), fp) != NULL) { - if ((cp = strchr(buf, '\n')) != NULL) { - *cp = '\0'; - } - (void) SetOption(buf); - } - (void) fclose(fp); - } - } -} diff --git a/usr.sbin/named/tools/nslookup/nslookup.8 b/usr.sbin/named/tools/nslookup/nslookup.8 deleted file mode 100644 index fa8f87b3a18..00000000000 --- a/usr.sbin/named/tools/nslookup/nslookup.8 +++ /dev/null @@ -1,364 +0,0 @@ -.\" Copyright (c) 1986,1990 Regents of the University of California. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" from: @(#)nslookup.8 5.3 (Berkeley) 6/24/90 -.\" $Id: nslookup.8,v 1.1 1995/10/18 08:47:55 deraadt Exp $ -.\" -.TH NSLOOKUP 8 "June 24, 1990" -.UC 6 -.SH NAME -nslookup \- query Internet name servers interactively -.SH SYNOPSIS -.B nslookup -[ -.I \-option ... -] -[ -.I host-to-find -| \- [ -.I server -]] -.SH DESCRIPTION -.I Nslookup -is a program to query Internet domain name servers. -Nslookup has two modes: interactive and non-interactive. -Interactive mode allows the user to query name servers for -information about various hosts and domains or to print a list of hosts -in a domain. -Non-interactive mode is used to print just the name and requested information -for a host or domain. -.sp 1 -.SH ARGUMENTS -Interactive mode is entered in the following cases: -.IP a) 4 -when no arguments are given (the default name server will be used), -.IP b) 4 -when the first argument is a hyphen (\-) and the second argument -is the host name or Internet address of a name server. -.LP -Non-interactive mode is used when the name or Internet address -of the host to be looked up -is given as the first argument. The optional second argument specifies -the host name or address of a name server. -.LP -The options listed under the ``set'' command below can be specified in -the .nslookuprc file in the user's home directory if they are listed -one per line. Options can also be specified -on the command line if they precede the arguments and are prefixed with -a hyphen. For example, to change the default query type to host information, -and the initial timeout to 10 seconds, type: -.sp .5v - nslookup \-query=hinfo \-timeout=10 -.sp .5v -.SH "INTERACTIVE COMMANDS" -Commands may be interrupted at any time by typing a control-C. -To exit, type a control-D (EOF) or type exit. -The command line length must be less than 256 characters. -To treat a built-in command as a host name, -precede it with an escape character (\e). -\fBN.B.\fP an unrecognized command will be interpreted as a host name. -.sp .5v -.IP "\fIhost\fP [\fIserver\fP]" -Look up information for \fIhost\fP using the current default server -or using \fIserver\fP if specified. -If \fIhost\fP is an Internet address and the query type is A or PTR, the -name of the host is returned. -If \fIhost\fP is a name and does not have a trailing period, the default -domain name is appended to the name. (This behavior depends on the state of the -\fBset\fP options \fBdomain\fP, \fBsrchlist\fP, -\fBdefname\fP, and \fBsearch\fP). -To look up a host not in the current domain, append a period to -the name. -.sp 1 -.IP "\fBserver\fP \fIdomain\fP" -.ns -.IP "\fBlserver\fP \fIdomain\fP" -Change the default server to \fIdomain\fP. -\fBLserver\fP uses the initial server to look up -information about \fIdomain\fP while \fBserver\fP -uses the current default server. -If an authoritative answer can't be found, the names of servers -that might have the answer are returned. -.sp 1 -.IP \fBroot\fP -Changes the default server to the server for the root of the domain name space. -Currently, the host ns.nic.ddn.mil is used. -(This command is a synonym for \fBlserver ns.nic.ddn.mil.\fP) -The name of the root server can be changed with the \fBset root\fP command. -.sp 1 -.IP "\fBfinger\fP [\fIname\fP] [\fB>\fP \fIfilename\fP]" -.ns -.IP "\fBfinger\fP [\fIname\fP] [\fB>>\fP \fIfilename\fP]" -Connects with the finger server on the current host. -The current host is defined when a previous lookup for a host -was successful and returned address information (see the -\fBset querytype=A\fP command). -\fIName\fP is optional. -\fB>\fP and \fB>>\fP can be used to redirect output in the -usual manner. -.sp 1 -.IP "\fBls\fR [\fIoption\fR] \fIdomain\fR [\fB>\fR \fIfilename\fR]" -.ns -.IP "\fBls\fR [\fIoption\fR] \fIdomain\fR [\fB>>\fR \fIfilename\fR]" -List the information available for \fIdomain\fP, optionally creating -or appending to \fIfilename\fP. -The default output contains host names and their Internet addresses. -.I Option -can be one of the following: -.RS -.IP "\fB\-t \fIquerytype\fP" 4 -lists all records of the specified type (see \fIquerytype\fP below). -.IP \fB\-a\fP 4 -lists aliases of hosts in the domain. -synonym for \fB\-t\ \ CNAME\fP. -.IP \fB\-d\fP 4 -lists all records for the domain. -synonym for \fB\-t\ \ ANY\fP. -.IP \fB\-h\fP 4 -lists CPU and operating system information for the domain. -synonym for \fB\-t\ \ HINFO\fP. -.IP \fB\-s\fP 4 -lists well-known services of hosts in the domain. -synonym for \fB\-t\ \ WKS\fP. -.P -When output is directed to a file, hash marks are printed for every -50 records received from the server. -.RE -.sp 1 -.IP "\fBview\fP \fIfilename\fP" -Sorts and lists the output of previous \fBls\fP command(s) with \fImore\fP(1). -.sp 1 -.ne 4 -.IP "\fBhelp\fP" -.ns -.IP "\fB?\fP" -Prints a brief summary of commands. -.sp 1 -.IP "\fBexit\fP" -Exits the program. -.sp 1 -.IP "\fBset\fP \fIkeyword\fP[=\fIvalue\fP]" -This command is used to change state information that affects the lookups. -Valid keywords are: -.RS -.IP "\fBall\fP" -Prints the current values of the frequently-used options to \fBset\fP. -Information about the current default server and host is also printed. -.IP "\fBclass=\fIvalue\fR" -Change the query class to one of: -.RS -.IP IN 10 -the Internet class. -.IP CHAOS 10 -the Chaos class. -.IP HESIOD 10 -the MIT Athena Hesiod class. -.IP ANY 10 -wildcard (any of the above). -.P -The class specifies the protocol group of the information. -.br -(Default = IN, abbreviation = cl) -.RE -.IP "\fB[no]debug\fP" -Turn debugging mode on. A lot more information is printed about the -packet sent to the server and the resulting answer. -.br -(Default = nodebug, abbreviation = [no]deb) -.IP "\fB[no]d2\fP" -Turn exhaustive debugging mode on. -Essentially all fields of every packet are printed. -.br -(Default = nod2) -.IP "\fBdomain=\fIname\fR" -Change the default domain name to \fIname\fP. -The default domain name is appended to a lookup request depending on the -state of the \fBdefname\fP and \fBsearch\fP options. -The domain search list contains the parents of the default domain if it has -at least two components in its name. -For example, if the default domain -is CC.Berkeley.EDU, the search list is CC.Berkeley.EDU and Berkeley.EDU. -Use the \fBset srchlist\fP command to specify a different list. -Use the \fBset all\fP command to display the list. -.br -(Default = value from hostname, /etc/resolv.conf or LOCALDOMAIN, -abbreviation = do) -.IP "\fBsrchlist=\fIname1/name2/...\fR" -Change the default domain name to \fIname1\fP and the domain search list -to \fIname1\fP, \fIname2\fP, etc. A maximum of 6 names separated by slashes (/) -can be specified. -For example, -.sp .5v - set\ srchlist=lcs.MIT.EDU/ai.MIT.EDU/MIT.EDU -.sp .5v -sets the domain to lcs.MIT.EDU and the search list to the three names. -This command overrides the -default domain name and search list of the \fBset domain\fP command. -Use the \fBset all\fP command to display the list. -.br -(Default = value based on hostname, /etc/resolv.conf or LOCALDOMAIN, -abbreviation = srchl) -.IP "\fB[no]defname\fP" -If set, append the default domain name to a single-component lookup request -(i.e., one that does not contain a period). -.br -(Default = defname, abbreviation = [no]def) -.IP "\fB[no]search\fP" -If the lookup request contains at least one period but doesn't end -with a trailing period, -append the domain names in the domain search list -to the request until an answer is received. -.br -(Default = search, abbreviation = [no]sea) -.IP "\fBport=\fIvalue\fR" -Change the default TCP/UDP name server port to \fIvalue\fP. -.br -(Default = 53, abbreviation = po) -.IP "\fBquerytype=\fIvalue\fR" -.ns -.IP "\fBtype=\fIvalue\fR" -.ns -Change the type of information query to one of: -.RS -.IP A 10 -the host's Internet address. -.IP CNAME 10 -the canonical name for an alias. -.IP HINFO 10 -the host CPU and operating system type. -.IP MINFO 10 -the mailbox or mail list information. -.IP MX 10 -the mail exchanger. -.IP NS 10 -the name server for the named zone. -.IP PTR 10 -the host name if the query is an Internet address, -otherwise the pointer to other information. -.IP SOA 10 -the domain's ``start-of-authority'' information. -.IP TXT 10 -the text information. -.IP UINFO 10 -the user information. -.IP WKS 10 -the supported well-known services. -.P -Other types (ANY, AXFR, MB, MD, MF, NULL) are described in the -RFC-1035 document. -.br -(Default = A, abbreviations = q, ty) -.RE -.IP "\fB[no]recurse\fP" -Tell the name server to query other servers if it does not have the -information. -.br -(Default = recurse, abbreviation = [no]rec) -.IP \fBretry=\fInumber\fR -Set the number of retries to \fInumber\fP. -When a reply to a request is not received within a certain -amount of time (changed with \fBset timeout\fP), -the timeout period is doubled and the request is resent. -The retry value controls how many times a request is resent before giving up. -.br -(Default = 4, abbreviation = ret) -.IP \fBroot=\fIhost\fR -Change the name of the root server to \fIhost\fP. This -affects the \fBroot\fP command. -.br -(Default = ns.nic.ddn.mil., abbreviation = ro) -.IP \fBtimeout=\fInumber\fR -Change the initial timeout interval -for waiting for a reply -to \fInumber\fP seconds. -Each retry doubles the timeout period. -.br -(Default = 5 seconds, abbreviation = ti) -.IP "\fB[no]vc\fP" -Always use a virtual circuit when sending requests to the server. -.br -(Default = novc, abbreviation = [no]v) -.IP "\fB[no]ignoretc\fP" -Ignore packet truncation errors. -.br -(Default = noignoretc, abbreviation = [no]ig) -.RE -.SH DIAGNOSTICS -If the lookup request was not successful, an error message is printed. -Possible errors are: -.IP "Timed out" 5 -The server did not respond to a request after a certain amount of -time (changed with \fBset timeout=\fIvalue\fR) -and a certain number of retries (changed with \fBset retry=\fIvalue\fR). -.IP "No response from server" 5 -No name server is running on the server machine. -.IP "No records" 5 -The server does not have resource records of the current query type for the -host, although the host name is valid. -The query type is specified with the \fBset querytype\fP command. -.IP "Non-existent domain" 5 -The host or domain name does not exist. -.IP "Connection refused" 5 -.ns -.IP "Network is unreachable" 5 -The connection to the name or finger server could not be made -at the current time. -This error commonly occurs with \fBls\fP and \fBfinger\fP requests. -.IP "Server failure" 5 -The name server found an internal inconsistency in its database -and could not return a valid answer. -.IP "Refused" 5 -The name server refused to service the request. -.IP "Format error" 5 -The name server found that the request packet was not in the proper format. -It may indicate an error in \fInslookup\fP. -.sp 1 -.SH FILES -.ta \w'/usr/share/misc/nslookup.helpXXX'u -/etc/resolv.conf initial domain name and - name server addresses. -.br -$HOME/.nslookuprc user's initial options. -.br -/usr/share/misc/nslookup.help summary of commands. -.SH ENVIRONMENT -.ta \w'HOSTALIASESXXXX'u -HOSTALIASES file containing host aliases. -.br -LOCALDOMAIN overrides default domain. -.SH SEE ALSO -resolver(3), resolv.conf(5), named(8), -.br -RFC-1034 ``Domain Names \- Concepts and Facilities'' -.br -RFC-1035 ``Domain Names \- Implementation and Specification'' -.SH AUTHOR -Andrew Cherenson diff --git a/usr.sbin/named/tools/nslookup/nslookup.help b/usr.sbin/named/tools/nslookup/nslookup.help deleted file mode 100644 index 9c92635ebc1..00000000000 --- a/usr.sbin/named/tools/nslookup/nslookup.help +++ /dev/null @@ -1,31 +0,0 @@ -Commands: (identifiers are shown in uppercase, [] means optional) -NAME - print info about the host/domain NAME using default server -NAME1 NAME2 - as above, but use NAME2 as server -help or ? - print info on common commands; see nslookup(1) for details -set OPTION - set an option - all - print options, current server and host - [no]debug - print debugging information - [no]d2 - print exhaustive debugging information - [no]defname - append domain name to each query - [no]recurse - ask for recursive answer to query - [no]vc - always use a virtual circuit - domain=NAME - set default domain name to NAME - srchlist=N1[/N2/.../N6] - set domain to N1 and search list to N1,N2, etc. - root=NAME - set root server to NAME - retry=X - set number of retries to X - timeout=X - set initial time-out interval to X seconds - querytype=X - set query type, e.g., A,ANY,CNAME,HINFO,MX,NS,PTR,SOA,WKS - type=X - synonym for querytype - class=X - set query class to one of IN (Internet), CHAOS, HESIOD or ANY -server NAME - set default server to NAME, using current default server -lserver NAME - set default server to NAME, using initial server -finger [USER] - finger the optional NAME at the current default host -root - set current default server to the root -ls [opt] DOMAIN [> FILE] - list addresses in DOMAIN (optional: output to FILE) - -a - list canonical names and aliases - -h - list HINFO (CPU type and operating system) - -s - list well-known services - -d - list all records - -t TYPE - list records of the given type (e.g., A,CNAME,MX, etc.) -view FILE - sort an 'ls' output file and view it with more -exit - exit the program, ^D also exits diff --git a/usr.sbin/named/tools/nslookup/pathnames.h b/usr.sbin/named/tools/nslookup/pathnames.h deleted file mode 100644 index 6c681ad8355..00000000000 --- a/usr.sbin/named/tools/nslookup/pathnames.h +++ /dev/null @@ -1,37 +0,0 @@ -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * from: @(#)pathnames.h 5.1 (Berkeley) 5/28/90 - * $Id: pathnames.h,v 1.1 1995/10/18 08:47:55 deraadt Exp $ - */ - -#define _PATH_HELPFILE "/usr/share/misc/nslookup.help" diff --git a/usr.sbin/named/tools/nslookup/res.h b/usr.sbin/named/tools/nslookup/res.h deleted file mode 100644 index 639a6b6a4d2..00000000000 --- a/usr.sbin/named/tools/nslookup/res.h +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (c) 1985,1989 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * from: @(#)res.h 5.10 (Berkeley) 6/1/90 - * $Id: res.h,v 1.1 1995/10/18 08:47:55 deraadt Exp $ - */ - -/* - ******************************************************************************* - * - * res.h -- - * - * Definitions used by modules of the name server lookup program. - * - * Copyright (c) 1985 - * Andrew Cherenson - * U.C. Berkeley - * CS298-26 Fall 1985 - * - ******************************************************************************* - */ - -#define TRUE 1 -#define FALSE 0 -typedef int Boolean; - -/* - * Define return statuses in addtion to the ones defined in namserv.h - * let SUCCESS be a synonym for NOERROR - * - * TIME_OUT - a socket connection timed out. - * NO_INFO - the server didn't find any info about the host. - * ERROR - one of the following types of errors: - * dn_expand, res_mkquery failed - * bad command line, socket operation failed, etc. - * NONAUTH - the server didn't have the desired info but - * returned the name(s) of some servers who should. - * NO_RESPONSE - the server didn't respond. - * - */ - -#define SUCCESS 0 -#define TIME_OUT -1 -#define NO_INFO -2 -#define ERROR -3 -#define NONAUTH -4 -#define NO_RESPONSE -5 - -/* - * Define additional options for the resolver state structure. - * - * RES_DEBUG2 more verbose debug level - */ - -#define RES_DEBUG2 0x80000000 - -/* - * Maximum length of server, host and file names. - */ - -#define NAME_LEN 256 - - -/* - * Modified struct hostent from <netdb.h> - * - * "Structures returned by network data base library. All addresses - * are supplied in host order, and returned in network order (suitable - * for use in system calls)." - */ - -typedef struct { - char *name; /* official name of host */ - char **domains; /* domains it serves */ - char **addrList; /* list of addresses from name server */ -} ServerInfo; - -typedef struct { - char *name; /* official name of host */ - char **aliases; /* alias list */ - char **addrList; /* list of addresses from name server */ - int addrType; /* host address type */ - int addrLen; /* length of address */ - ServerInfo **servers; -} HostInfo; - - -/* - * FilePtr is used for directing listings to a file. - * It is global so the Control-C handler can close it. - */ - -extern FILE *filePtr; - -/* - * TCP/UDP port of server. - */ -extern unsigned short nsport; - -/* - * External routines: - */ - -extern Boolean IsAddr(); -extern int Print_query(); -extern char *Print_cdname(); -extern char *Print_cdname2(); /* fixed width */ -extern char *Print_rr(); -extern char *DecodeType(); /* descriptive version of p_type */ -extern char *DecodeError(); -extern char *Calloc(); -extern char *Malloc(); -extern void NsError(); -extern void PrintServer(); -extern void PrintHostInfo(); -extern void ShowOptions(); -extern void FreeHostInfoPtr(); -extern FILE *OpenFile(); -extern char *res_skip(); diff --git a/usr.sbin/named/tools/nslookup/send.c b/usr.sbin/named/tools/nslookup/send.c deleted file mode 100644 index 688d2ad13bd..00000000000 --- a/usr.sbin/named/tools/nslookup/send.c +++ /dev/null @@ -1,564 +0,0 @@ -/* - * Copyright (c) 1985, 1989 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -/*static char sccsid[] = "from: @(#)send.c 5.18 (Berkeley) 3/2/91";*/ -static char rcsid[] = "$Id: send.c,v 1.1 1995/10/18 08:47:55 deraadt Exp $"; -#endif /* not lint */ - -/* - ******************************************************************************* - * - * send.c -- - * - * Routine to send request packets to a name server. - * - * Based on "@(#)res_send.c 6.25 (Berkeley) 6/1/90". - * - ******************************************************************************* - */ - - -/* - * Send query to name server and wait for reply. - */ - -#include <sys/param.h> -#include <sys/time.h> -#include <sys/socket.h> -#include <sys/uio.h> -#include <netinet/in.h> -#include <stdio.h> -#include <errno.h> -#include <arpa/nameser.h> -#include <arpa/inet.h> -#include <resolv.h> -#include "res.h" - -extern int errno; - -static int s = -1; /* socket used for communications */ - - -#ifndef FD_SET -#define NFDBITS 32 -#define FD_SETSIZE 32 -#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS))) -#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS))) -#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS))) -#define FD_ZERO(p) bzero((char *)(p), sizeof(*(p))) -#endif - -#define SR 1 /* SendRequest style */ - -#ifndef DEBUG -#define DEBUG -#endif - -unsigned short nsport = NAMESERVER_PORT; - - - -/* - ******************************************************************************* - * - * SendRequest -- - * - * Sends a request packet to a name server whose address - * is specified by the first argument and returns with - * the answer packet. - * - * Results: - * SUCCESS - the request was sent and an answer - * was received. - * TIME_OUT - the virtual circuit connection timed-out - * or a reply to a datagram wasn't received. - * - * - ******************************************************************************* - */ - -int -SendRequest(nsAddrPtr, buf, buflen, answer, anslen, trueLenPtr) - struct in_addr *nsAddrPtr; - char *buf; - int buflen; - char *answer; - u_int anslen; - int *trueLenPtr; -{ - register int n; - int try, v_circuit, resplen, ns; - int gotsomewhere = 0, connected = 0; - int connreset = 0; - u_short id, len; - char *cp; - fd_set dsmask; - struct timeval timeout; - HEADER *hp = (HEADER *) buf; - HEADER *anhp = (HEADER *) answer; - struct iovec iov[2]; - int terrno = ETIMEDOUT; - char junk[512]; - -#if SR - struct sockaddr_in sin; - - if (_res.options & RES_DEBUG2) { - printf("------------\nSendRequest(), len %d\n", buflen); - Print_query(buf, buf+buflen, 1); - } - sin.sin_family = AF_INET; - sin.sin_port = htons(nsport); - sin.sin_addr = *nsAddrPtr; -#else -#ifdef DEBUG - if (_res.options & RES_DEBUG) { - printf("res_send()\n"); - p_query(buf); - } -#endif DEBUG - if (!(_res.options & RES_INIT)) - if (res_init() == -1) { - return(-1); - } -#endif /* SR */ - v_circuit = (_res.options & RES_USEVC) || buflen > PACKETSZ; - id = hp->id; - /* - * Send request, RETRY times, or until successful - */ - for (try = 0; try < _res.retry; try++) { -#if !SR - for (ns = 0; ns < _res.nscount; ns++) { -#ifdef DEBUG - if (_res.options & RES_DEBUG) - printf("Querying server (# %d) address = %s\n", ns+1, - inet_ntoa(_res.nsaddr_list[ns].sin_addr)); -#endif DEBUG -#endif /* !SR */ - usevc: - if (v_circuit) { - int truncated = 0; - - /* - * Use virtual circuit; - * at most one attempt per server. - */ - try = _res.retry; - if (s < 0) { - s = socket(AF_INET, SOCK_STREAM, 0); - if (s < 0) { - terrno = errno; -#ifdef DEBUG - if (_res.options & RES_DEBUG) - perror("socket (vc) failed"); -#endif DEBUG - continue; - } -#if SR - if (connect(s, (struct sockaddr *)&sin, -#else - if (connect(s, - (struct sockaddr *)&(_res.nsaddr_list[ns]), -#endif - sizeof(struct sockaddr)) < 0) { - terrno = errno; -#ifdef DEBUG - if (_res.options & RES_DEBUG) - perror("connect failed"); -#endif DEBUG - (void) close(s); - s = -1; - continue; - } - } - /* - * Send length & message - */ - len = htons((u_short)buflen); - iov[0].iov_base = (caddr_t)&len; - iov[0].iov_len = sizeof(len); - iov[1].iov_base = buf; - iov[1].iov_len = buflen; - if (writev(s, iov, 2) != sizeof(len) + buflen) { - terrno = errno; -#ifdef DEBUG - if (_res.options & RES_DEBUG) - perror("write failed"); -#endif DEBUG - (void) close(s); - s = -1; - continue; - } - /* - * Receive length & response - */ - cp = answer; - len = sizeof(short); - while (len != 0 && - (n = read(s, (char *)cp, (int)len)) > 0) { - cp += n; - len -= n; - } - if (n <= 0) { - terrno = errno; -#ifdef DEBUG - if (_res.options & RES_DEBUG) - perror("read failed"); -#endif DEBUG - (void) close(s); - s = -1; - /* - * A long running process might get its TCP - * connection reset if the remote server was - * restarted. Requery the server instead of - * trying a new one. When there is only one - * server, this means that a query might work - * instead of failing. We only allow one reset - * per query to prevent looping. - */ - if (terrno == ECONNRESET && !connreset) { - connreset = 1; - ns--; - } - continue; - } - cp = answer; - if ((resplen = ntohs(*(u_short *)cp)) > anslen) { -#ifdef DEBUG - if (_res.options & RES_DEBUG) - fprintf(stderr, "response truncated\n"); -#endif DEBUG - len = anslen; - truncated = 1; - } else - len = resplen; - while (len != 0 && - (n = read(s, (char *)cp, (int)len)) > 0) { - cp += n; - len -= n; - } - if (n <= 0) { - terrno = errno; -#ifdef DEBUG - if (_res.options & RES_DEBUG) - perror("read failed"); -#endif DEBUG - (void) close(s); - s = -1; - continue; - } - if (truncated) { - /* - * Flush rest of answer - * so connection stays in synch. - */ - anhp->tc = 1; - len = resplen - anslen; - while (len != 0) { - n = (len > sizeof(junk) ? - sizeof(junk) : len); - if ((n = read(s, junk, n)) > 0) - len -= n; - else - break; - } - } - } else { - /* - * Use datagrams. - */ - if (s < 0) { - s = socket(AF_INET, SOCK_DGRAM, 0); - if (s < 0) { - terrno = errno; -#ifdef DEBUG - if (_res.options & RES_DEBUG) - perror("socket (dg) failed"); -#endif DEBUG - continue; - } - } -#if SR - /* - * Special case the send code below - * since we have just 1 server. - */ -#if BSD >= 43 - if (connected == 0) { - if (connect(s, (struct sockaddr *)&sin, - sizeof(struct sockaddr)) < 0) { - if (_res.options & RES_DEBUG) - perror("connect"); - continue; - } - connected = 1; - } - if (send(s, buf, buflen, 0) != buflen) { - if (_res.options & RES_DEBUG) - perror("send"); - continue; - } -#else /* BSD */ - if (sendto(s, buf, buflen, 0, &sin, - sizeof(struct sockaddr)) != buflen) { - if (_res.options & RES_DEBUG) - perror("sendto"); - continue; - } -#endif -#else /* SR */ -#if BSD >= 43 - /* - * I'm tired of answering this question, so: - * On a 4.3BSD+ machine (client and server, - * actually), sending to a nameserver datagram - * port with no nameserver will cause an - * ICMP port unreachable message to be returned. - * If our datagram socket is "connected" to the - * server, we get an ECONNREFUSED error on the next - * socket operation, and select returns if the - * error message is received. We can thus detect - * the absence of a nameserver without timing out. - * If we have sent queries to at least two servers, - * however, we don't want to remain connected, - * as we wish to receive answers from the first - * server to respond. - */ - if (_res.nscount == 1 || (try == 0 && ns == 0)) { - /* - * Don't use connect if we might - * still receive a response - * from another server. - */ - if (connected == 0) { - if (connect(s, &_res.nsaddr_list[ns], - sizeof(struct sockaddr)) < 0) { -#ifdef DEBUG - if (_res.options & RES_DEBUG) - perror("connect"); -#endif DEBUG - continue; - } - connected = 1; - } - if (send(s, buf, buflen, 0) != buflen) { -#ifdef DEBUG - if (_res.options & RES_DEBUG) - perror("send"); -#endif DEBUG - continue; - } - } else { - /* - * Disconnect if we want to listen - * for responses from more than one server. - */ - if (connected) { - (void) connect(s, &no_addr, - sizeof(no_addr)); - connected = 0; - } -#endif BSD - if (sendto(s, buf, buflen, 0, - &_res.nsaddr_list[ns], - sizeof(struct sockaddr)) != buflen) { -#ifdef DEBUG - if (_res.options & RES_DEBUG) - perror("sendto"); -#endif DEBUG - continue; - } -#if BSD >= 43 - } -#endif -#endif /* SR */ - - /* - * Wait for reply - */ - timeout.tv_sec = (_res.retrans << try); -#if !SR - if (try > 0) - timeout.tv_sec /= _res.nscount; -#endif /* SR */ - if (timeout.tv_sec <= 0) - timeout.tv_sec = 1; - timeout.tv_usec = 0; -wait: - FD_ZERO(&dsmask); - FD_SET(s, &dsmask); - n = select(s+1, &dsmask, (fd_set *)NULL, - (fd_set *)NULL, &timeout); - if (n < 0) { -#ifdef DEBUG - if (_res.options & RES_DEBUG) - perror("select"); -#endif DEBUG - continue; - } - if (n == 0) { - /* - * timeout - */ -#ifdef DEBUG - if (_res.options & RES_DEBUG) - printf("timeout (%d secs)\n", - timeout.tv_sec); -#endif DEBUG -#if BSD >= 43 - gotsomewhere = 1; -#endif - continue; - } - if ((resplen = recv(s, answer, anslen, 0)) <= 0) { -#ifdef DEBUG - if (_res.options & RES_DEBUG) - perror("recvfrom"); -#endif DEBUG - continue; - } - gotsomewhere = 1; - if (id != anhp->id) { - /* - * response from old query, ignore it - */ -#if SR - if (_res.options & RES_DEBUG2) { - printf("------------\nOld answer:\n"); - Print_query(answer, answer+resplen, 1); - } -#else -#ifdef DEBUG - if (_res.options & RES_DEBUG) { - printf("old answer:\n"); - p_query(answer); - } -#endif DEBUG -#endif - goto wait; - } - if (!(_res.options & RES_IGNTC) && anhp->tc) { - /* - * get rest of answer; - * use TCP with same server. - */ -#ifdef DEBUG - if (_res.options & RES_DEBUG) - printf("truncated answer\n"); -#endif DEBUG - (void) close(s); - s = -1; - v_circuit = 1; - goto usevc; - } - } -#if SR - if (_res.options & RES_DEBUG) { - if (_res.options & RES_DEBUG2) - printf("------------\nGot answer (%d bytes):\n", - resplen); - else - printf("------------\nGot answer:\n"); - Print_query(answer, answer+resplen, 1); - } - (void) close(s); - s = -1; - *trueLenPtr = resplen; - return (SUCCESS); -#else -#ifdef DEBUG - if (_res.options & RES_DEBUG) { - printf("got answer:\n"); - p_query(answer); - } -#endif DEBUG - /* - * If using virtual circuits, we assume that the first server - * is preferred * over the rest (i.e. it is on the local - * machine) and only keep that one open. - * If we have temporarily opened a virtual circuit, - * or if we haven't been asked to keep a socket open, - * close the socket. - */ - if ((v_circuit && - ((_res.options & RES_USEVC) == 0 || ns != 0)) || - (_res.options & RES_STAYOPEN) == 0) { - (void) close(s); - s = -1; - } - return (resplen); - } -#endif /* SR */ - } - if (s >= 0) { - (void) close(s); - s = -1; - } -#if SR - if (v_circuit == 0) - if (gotsomewhere == 0) - return NO_RESPONSE; /* no nameservers found */ - else - return TIME_OUT; /* no answer obtained */ - else - if (errno == ECONNREFUSED) - return NO_RESPONSE; - else - return ERROR; -#else - if (v_circuit == 0) - if (gotsomewhere == 0) - errno = ECONNREFUSED; /* no nameservers found */ - else - errno = ETIMEDOUT; /* no answer obtained */ - else - errno = terrno; - return (-1); -#endif -} - -/* - * This routine is for closing the socket if a virtual circuit is used and - * the program wants to close it. - * - * Called from the interrupt handler. - */ -SendRequest_close() -{ - if (s != -1) { - (void) close(s); - s = -1; - } -} diff --git a/usr.sbin/named/tools/nslookup/skip.c b/usr.sbin/named/tools/nslookup/skip.c deleted file mode 100644 index 6f72f810f18..00000000000 --- a/usr.sbin/named/tools/nslookup/skip.c +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright (c) 1985 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -/*static char sccsid[] = "from: @(#)skip.c 5.12 (Berkeley) 3/21/91";*/ -static char rcsid[] = "$Id: skip.c,v 1.1 1995/10/18 08:47:55 deraadt Exp $"; -#endif /* not lint */ - -/* - ******************************************************************************* - * - * skip.c -- - * - * Routines to skip over portions of a query buffer. - * - * Note: this file has been submitted for inclusion in - * BIND resolver library. When this has been done, this file - * is no longer necessary (assuming there haven't been any - * changes). - * - * Adapted from 4.3BSD BIND res_debug.c - * - ******************************************************************************* - */ - -#include <sys/param.h> -#include <netinet/in.h> -#include <arpa/nameser.h> -#include <resolv.h> -#include <stdio.h> - -char *res_skip_rr(); - - -/* - ******************************************************************************* - * - * res_skip -- - * - * Skip the contents of a query. - * - * Interpretation of numFieldsToSkip argument: - * res_skip returns pointer to: - * 1 -> start of question records. - * 2 -> start of authoritative answer records. - * 3 -> start of additional records. - * 4 -> first byte after end of additional records. - * - * Results: - * (address) - success operation. - * NULL - a resource record had an incorrect format. - * - ******************************************************************************* - */ - -char * -res_skip(msg, numFieldsToSkip, eom) - char *msg; - int numFieldsToSkip; - char *eom; -{ - register char *cp; - register HEADER *hp; - register int tmp; - register int n; - - /* - * Skip the header fields. - */ - hp = (HEADER *)msg; - cp = msg + sizeof(HEADER); - - /* - * skip question records. - */ - if (n = ntohs(hp->qdcount) ) { - while (--n >= 0 && cp < eom) { - tmp = dn_skipname((u_char *)cp, (u_char *)eom); - if (tmp == -1) return(NULL); - cp += tmp; - cp += sizeof(u_short); /* type */ - cp += sizeof(u_short); /* class */ - } - } - if (--numFieldsToSkip <= 0) return(cp); - - /* - * skip authoritative answer records - */ - if (n = ntohs(hp->ancount)) { - while (--n >= 0 && cp < eom) { - cp = res_skip_rr(cp, eom); - if (cp == NULL) return(NULL); - } - } - if (--numFieldsToSkip == 0) return(cp); - - /* - * skip name server records - */ - if (n = ntohs(hp->nscount)) { - while (--n >= 0 && cp < eom) { - cp = res_skip_rr(cp, eom); - if (cp == NULL) return(NULL); - } - } - if (--numFieldsToSkip == 0) return(cp); - - /* - * skip additional records - */ - if (n = ntohs(hp->arcount)) { - while (--n >= 0 && cp < eom) { - cp = res_skip_rr(cp, eom); - if (cp == NULL) return(NULL); - } - } - - return(cp); -} - - -/* - ******************************************************************************* - * - * res_skip_rr -- - * - * Skip over resource record fields. - * - * Results: - * (address) - success operation. - * NULL - a resource record had an incorrect format. - ******************************************************************************* - */ - -char * -res_skip_rr(cp, eom) - char *cp; - char *eom; -{ - int tmp; - int dlen; - - if ((tmp = dn_skipname((u_char *)cp, (u_char *)eom)) == -1) - return (NULL); /* compression error */ - cp += tmp; - if ((cp + RRFIXEDSZ) > eom) - return (NULL); - cp += sizeof(u_short); /* type */ - cp += sizeof(u_short); /* class */ - cp += sizeof(u_long); /* ttl */ - dlen = _getshort(cp); - cp += sizeof(u_short); /* dlen */ - cp += dlen; - if (cp > eom) - return (NULL); - return (cp); -} diff --git a/usr.sbin/named/tools/nslookup/subr.c b/usr.sbin/named/tools/nslookup/subr.c deleted file mode 100644 index b0f3759f7aa..00000000000 --- a/usr.sbin/named/tools/nslookup/subr.c +++ /dev/null @@ -1,510 +0,0 @@ -/* - * Copyright (c) 1985,1989 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -/*static char sccsid[] = "from: @(#)subr.c 5.24 (Berkeley) 3/2/91";*/ -static char rcsid[] = "$Id: subr.c,v 1.1 1995/10/18 08:47:56 deraadt Exp $"; -#endif /* not lint */ - -/* - ******************************************************************************* - * - * subr.c -- - * - * Miscellaneous subroutines for the name server - * lookup program. - * - * Copyright (c) 1985 - * Andrew Cherenson - * U.C. Berkeley - * CS298-26 Fall 1985 - * - ******************************************************************************* - */ - -#include <sys/types.h> -#include <sys/param.h> -#include <netdb.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/nameser.h> -#include <arpa/inet.h> -#include <signal.h> -#include <setjmp.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "res.h" - - - -/* - ******************************************************************************* - * - * IntrHandler -- - * - * This routine is called whenever a control-C is typed. - * It performs three main functions: - * - closes an open socket connection, - * - closes an open output file (used by LookupHost, et al.), - * - jumps back to the main read-eval loop. - * - * If a user types a ^C in the middle of a routine that uses a socket, - * the routine would not be able to close the socket. To prevent an - * overflow of the process's open file table, the socket and output - * file descriptors are closed by the interrupt handler. - * - * Side effects: - * Open file descriptors are closed. - * If filePtr is valid, it is closed. - * Flow of control returns to the main() routine. - * - ******************************************************************************* - */ - -void -IntrHandler() -{ - extern jmp_buf env; -#if defined(BSD) && BSD >= 199006 - extern FILE *yyin; /* scanner input file */ - extern void yyrestart(); /* routine to restart scanner after interrupt */ -#endif - - SendRequest_close(); - ListHost_close(); - if (filePtr != NULL && filePtr != stdout) { - fclose(filePtr); - filePtr = NULL; - } - printf("\n"); -#if defined(BSD) && BSD >= 199006 - yyrestart(yyin); -#endif - longjmp(env, 1); -} - - -/* - ******************************************************************************* - * - * Malloc -- - * Calloc -- - * - * Calls the malloc library routine with SIGINT blocked to prevent - * corruption of malloc's data structures. We need to do this because - * a control-C doesn't kill the program -- it causes a return to the - * main command loop. - * - * NOTE: This method doesn't prevent the pointer returned by malloc - * from getting lost, so it is possible to get "core leaks". - * - * If malloc fails, the program exits. - * - * Results: - * (address) - address of new buffer. - * - ******************************************************************************* - */ - -char * -Malloc(size) - int size; -{ - char *ptr; - -#ifdef SYSV -#ifdef SVR3 - sighold(SIGINT); - ptr = malloc((unsigned) size); - sigrelse(SIGINT); -#else - { int (*old)(); - old = signal(SIGINT, SIG_IGN); - ptr = malloc((unsigned) size); - signal(SIGINT, old); - } -#endif -#else - { int saveMask; - saveMask = sigblock(sigmask(SIGINT)); - ptr = malloc((unsigned) size); - (void) sigsetmask(saveMask); - } -#endif - if (ptr == NULL) { - fflush(stdout); - fprintf(stderr, "*** Can't allocate memory\n"); - fflush(stderr); - abort(); - /*NOTREACHED*/ - } else { - return(ptr); - } -} - -char * -Calloc(num, size) - register int num, size; -{ - char *ptr = Malloc(num*size); - bzero(ptr, num*size); - return(ptr); -} - - -/* - ******************************************************************************* - * - * PrintHostInfo -- - * - * Prints out the HostInfo structure for a host. - * - ******************************************************************************* - */ - -void -PrintHostInfo(file, title, hp) - FILE *file; - char *title; - register HostInfo *hp; -{ - register char **cp; - register ServerInfo **sp; - char comma; - int i; - - fprintf(file, "%-7s %s", title, hp->name); - - if (hp->addrList != NULL) { - if (hp->addrList[1] != NULL) { - fprintf(file, "\nAddresses:"); - } else { - fprintf(file, "\nAddress:"); - } - comma = ' '; - i = 0; - for (cp = hp->addrList; cp && *cp; cp++) { - i++; - if (i > 4) { - fprintf(file, "\n\t"); - comma = ' '; - i = 0; - } - fprintf(file,"%c %s", comma, inet_ntoa(*(struct in_addr *)*cp)); - comma = ','; - } - } - - if (hp->aliases != NULL) { - fprintf(file, "\nAliases:"); - comma = ' '; - i = 10; - for (cp = hp->aliases; cp && *cp && **cp; cp++) { - i += strlen(*cp) + 2; - if (i > 75) { - fprintf(file, "\n\t"); - comma = ' '; - i = 10; - } - fprintf(file, "%c %s", comma, *cp); - comma = ','; - } - } - - if (hp->servers != NULL) { - fprintf(file, "\nServed by:\n"); - for (sp = hp->servers; *sp != NULL ; sp++) { - - fprintf(file, "- %s\n\t", (*sp)->name); - - comma = ' '; - i = 0; - for (cp = (*sp)->addrList; cp && *cp && **cp; cp++) { - i++; - if (i > 4) { - fprintf(file, "\n\t"); - comma = ' '; - i = 0; - } - fprintf(file, - "%c %s", comma, inet_ntoa(*(struct in_addr *)*cp)); - comma = ','; - } - fprintf(file, "\n\t"); - - comma = ' '; - i = 10; - for (cp = (*sp)->domains; cp && *cp && **cp; cp++) { - i += strlen(*cp) + 2; - if (i > 75) { - fprintf(file, "\n\t"); - comma = ' '; - i = 10; - } - fprintf(file, "%c %s", comma, *cp); - comma = ','; - } - fprintf(file, "\n"); - } - } - - fprintf(file, "\n\n"); -} - -/* - ******************************************************************************* - * - * OpenFile -- - * - * Parses a command string for a file name and opens - * the file. - * - * Results: - * file pointer - the open was successful. - * NULL - there was an error opening the file or - * the input string was invalid. - * - ******************************************************************************* - */ - -FILE * -OpenFile(string, file) - char *string; - char *file; -{ - char *redirect; - FILE *tmpPtr; - - /* - * Open an output file if we see '>' or >>'. - * Check for overwrite (">") or concatenation (">>"). - */ - - redirect = strchr(string, '>'); - if (redirect == NULL) { - return(NULL); - } - if (redirect[1] == '>') { - sscanf(redirect, ">> %s", file); - tmpPtr = fopen(file, "a+"); - } else { - sscanf(redirect, "> %s", file); - tmpPtr = fopen(file, "w"); - } - - if (tmpPtr != NULL) { - redirect[0] = '\0'; - } - - return(tmpPtr); -} - -/* - ******************************************************************************* - * - * DecodeError -- - * - * Converts an error code into a character string. - * - ******************************************************************************* - */ - -char * -DecodeError(result) - int result; -{ - switch (result) { - case NOERROR: return("Success"); break; - case FORMERR: return("Format error"); break; - case SERVFAIL: return("Server failed"); break; - case NXDOMAIN: return("Non-existent domain"); break; - case NOTIMP: return("Not implemented"); break; - case REFUSED: return("Query refused"); break; - case NOCHANGE: return("No change"); break; - case TIME_OUT: return("Timed out"); break; - case NO_INFO: return("No information"); break; - case ERROR: return("Unspecified error"); break; - case NONAUTH: return("Non-authoritative answer"); break; - case NO_RESPONSE: return("No response from server"); break; - default: break; - } - return("BAD ERROR VALUE"); -} - - -int -StringToClass(class, dflt) - char *class; - int dflt; -{ - if (strcasecmp(class, "IN") == 0) - return(C_IN); - if (strcasecmp(class, "HESIOD") == 0 || - strcasecmp(class, "HS") == 0) - return(C_HS); - if (strcasecmp(class, "CHAOS") == 0) - return(C_CHAOS); - if (strcasecmp(class, "ANY") == 0) - return(C_ANY); - fprintf(stderr, "unknown query class: %s\n", class); - return(dflt); -} - - -/* - ******************************************************************************* - * - * StringToType -- - * - * Converts a string form of a query type name to its - * corresponding integer value. - * - ******************************************************************************* - */ - -int -StringToType(type, dflt) - char *type; - int dflt; -{ - if (strcasecmp(type, "A") == 0) - return(T_A); - if (strcasecmp(type, "NS") == 0) - return(T_NS); /* authoritative server */ - if (strcasecmp(type, "MX") == 0) - return(T_MX); /* mail exchanger */ - if (strcasecmp(type, "CNAME") == 0) - return(T_CNAME); /* canonical name */ - if (strcasecmp(type, "SOA") == 0) - return(T_SOA); /* start of authority zone */ - if (strcasecmp(type, "MB") == 0) - return(T_MB); /* mailbox domain name */ - if (strcasecmp(type, "MG") == 0) - return(T_MG); /* mail group member */ - if (strcasecmp(type, "MR") == 0) - return(T_MR); /* mail rename name */ - if (strcasecmp(type, "WKS") == 0) - return(T_WKS); /* well known service */ - if (strcasecmp(type, "PTR") == 0) - return(T_PTR); /* domain name pointer */ - if (strcasecmp(type, "HINFO") == 0) - return(T_HINFO); /* host information */ - if (strcasecmp(type, "MINFO") == 0) - return(T_MINFO); /* mailbox information */ - if (strcasecmp(type, "AXFR") == 0) - return(T_AXFR); /* zone transfer */ - if (strcasecmp(type, "MAILA") == 0) - return(T_MAILA); /* mail agent */ - if (strcasecmp(type, "MAILB") == 0) - return(T_MAILB); /* mail box */ - if (strcasecmp(type, "ANY") == 0) - return(T_ANY); /* matches any type */ - if (strcasecmp(type, "UINFO") == 0) - return(T_UINFO); /* user info */ - if (strcasecmp(type, "UID") == 0) - return(T_UID); /* user id */ - if (strcasecmp(type, "GID") == 0) - return(T_GID); /* group id */ - if (strcasecmp(type, "TXT") == 0) - return(T_TXT); /* text */ - fprintf(stderr, "unknown query type: %s\n", type); - return(dflt); -} - -/* - ******************************************************************************* - * - * DecodeType -- - * - * Converts a query type to a descriptive name. - * (A more verbose form of p_type.) - * - * - ******************************************************************************* - */ - -static char nbuf[20]; - -char * -DecodeType(type) - int type; -{ - switch (type) { - case T_A: - return("address"); - case T_NS: - return("name server"); - case T_CNAME: - return("canonical name"); - case T_SOA: - return("start of authority"); - case T_MB: - return("mailbox"); - case T_MG: - return("mail group member"); - case T_MR: - return("mail rename"); - case T_NULL: - return("null"); - case T_WKS: - return("well-known service"); - case T_PTR: - return("domain name pointer"); - case T_HINFO: - return("host information"); - case T_MINFO: - return("mailbox information"); - case T_MX: - return("mail exchanger"); - case T_TXT: - return("text"); - case T_UINFO: - return("user information"); - case T_UID: - return("user ID"); - case T_GID: - return("group ID"); - case T_AXFR: - return("zone transfer"); - case T_MAILB: - return("mailbox-related data"); - case T_MAILA: - return("mail agent"); - case T_ANY: - return("\"any\""); - default: - (void) sprintf(nbuf, "%d", type); - return (nbuf); - } -} diff --git a/usr.sbin/named/tools/nsquery/Makefile b/usr.sbin/named/tools/nsquery/Makefile deleted file mode 100644 index a0cb559106a..00000000000 --- a/usr.sbin/named/tools/nsquery/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# from: @(#)Makefile 5.1 (Berkeley) 5/28/90 -# $Id: Makefile,v 1.1 1995/10/18 08:47:56 deraadt Exp $ - -PROG= nsquery -NOMAN= noman - -.include "../../../Makefile.inc" -.include <bsd.prog.mk> diff --git a/usr.sbin/named/tools/nsquery/nsquery.c b/usr.sbin/named/tools/nsquery/nsquery.c deleted file mode 100644 index a40a0fe7429..00000000000 --- a/usr.sbin/named/tools/nsquery/nsquery.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 1986 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -char copyright[] = -"@(#) Copyright (c) 1986 Regents of the University of California.\n\ - All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -/*static char sccsid[] = "from: @(#)nsquery.c 4.8 (Berkeley) 6/1/90";*/ -static char rcsid[] = "$Id: nsquery.c,v 1.1 1995/10/18 08:47:56 deraadt Exp $"; -#endif /* not lint */ - -#include <sys/param.h> -#include <arpa/nameser.h> -#include <netdb.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <resolv.h> -#include <stdio.h> - -main(argc, argv) - int argc; - char **argv; -{ - register struct hostent *hp; - register char *s; - - if (argc >= 2 && strcmp(argv[1], "-d") == 0) { - _res.options |= RES_DEBUG; - argc--; - argv++; - } - if (argc < 2) { - fprintf(stderr, "usage: nsquery [-d] host [server]\n"); - exit(1); - } - if (argc == 3) { - hp = gethostbyname(argv[2]); - if (hp == NULL) { - fprintf(stderr, "nsquery:"); - herror(argv[2]); - exit(1); - } - printf("\nServer:\n"); - printanswer(hp); - _res.nsaddr.sin_addr = *(struct in_addr *)hp->h_addr; - } - - hp = gethostbyname(argv[1]); - if (hp == NULL) { - fprintf(stderr, "nsquery: %s: ", argv[1]); - herror((char *)NULL); - exit(1); - } - printanswer(hp); - exit(0); -} - -printanswer(hp) - register struct hostent *hp; -{ - register char **cp; - extern char *inet_ntoa(); - - printf("Name: %s\n", hp->h_name); -#if BSD >= 43 || defined(h_addr) - printf("Addresses:"); - for (cp = hp->h_addr_list; cp && *cp; cp++) - printf(" %s", inet_ntoa(*(struct in_addr *)(*cp))); - printf("\n"); -#else - printf("Address: %s\n", inet_ntoa(*(struct in_addr *)hp->h_addr)); -#endif - printf("Aliases:"); - for (cp = hp->h_aliases; cp && *cp && **cp; cp++) - printf(" %s", *cp); - printf("\n\n"); -} diff --git a/usr.sbin/named/tools/nstest/Makefile b/usr.sbin/named/tools/nstest/Makefile deleted file mode 100644 index 033b534565d..00000000000 --- a/usr.sbin/named/tools/nstest/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# from: @(#)Makefile 5.1 (Berkeley) 5/28/90 -# $Id: Makefile,v 1.1 1995/10/18 08:47:56 deraadt Exp $ - -PROG= nstest -NOMAN= noman - -.include "../../../Makefile.inc" -.include <bsd.prog.mk> diff --git a/usr.sbin/named/tools/nstest/nstest.c b/usr.sbin/named/tools/nstest/nstest.c deleted file mode 100644 index 84c32a899d0..00000000000 --- a/usr.sbin/named/tools/nstest/nstest.c +++ /dev/null @@ -1,389 +0,0 @@ -/* - * Copyright (c) 1986, 1989 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -char copyright[] = -"@(#) Copyright (c) 1986 Regents of the University of California.\n\ - All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -/*static char sccsid[] = "from: @(#)nstest.c 4.15 (Berkeley) 3/21/91";*/ -static char rcsid[] = "$Id: nstest.c,v 1.1 1995/10/18 08:47:56 deraadt Exp $"; -#endif /* not lint */ - -#include <sys/param.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/nameser.h> -#include <resolv.h> -#include <stdio.h> -#include <stdlib.h> - -extern char *inet_ntoa(); -char *progname; -FILE *log; -#define MAXDATA 256 /* really should get definition from named/db.h */ -main(argc, argv) - char **argv; -{ - register char *cp; - struct hostent *hp; - u_short port = htons(NAMESERVER_PORT); - char buf[BUFSIZ]; - char packet[PACKETSZ]; - char answer[PACKETSZ]; - struct rrec NewRR; - char OldRRData[MAXDATA]; - int n, dump_packet; - - NewRR.r_data = (char *) malloc(MAXDATA); - NewRR.r_data = (char *) malloc(MAXDATA); - progname = argv[0]; - dump_packet = 0; - _res.options |= RES_DEBUG|RES_RECURSE; - (void) res_init(); - while (argc > 1 && argv[1][0] == '-') { - argc--; - cp = *++argv; - while (*++cp) - switch (*cp) { - case 'p': - if (--argc <= 0) - usage(); - port = htons(atoi(*++argv)); - break; - - case 'i': - _res.options |= RES_IGNTC; - break; - - case 'v': - _res.options |= RES_USEVC|RES_STAYOPEN; - break; - - case 'r': - _res.options &= ~RES_RECURSE; - break; - - case 'd': - dump_packet++; - break; - - default: - usage(); - } - } - _res.nsaddr.sin_family = AF_INET; - _res.nsaddr.sin_addr.s_addr = INADDR_ANY; - _res.nsaddr.sin_port = port; - if (argc > 1) { - _res.nsaddr.sin_addr.s_addr = inet_addr(argv[1]); - if (_res.nsaddr.sin_addr.s_addr == (u_long) -1) - usage(); - } - if (argc > 2) { - log = fopen(argv[2],"w"); - if (log == NULL) perror(argv[2]); - } - for (;;) { - printf("> "); - fflush(stdout); - if ((cp = (char *)gets(buf)) == NULL) - break; - switch (*cp++) { - case 'a': - n = res_mkquery(QUERY, cp, C_IN, T_A, (char *)0, 0, - NULL, packet, sizeof(packet)); - break; - - case 'A': - n = ntohl(inet_addr(cp)); - putlong((u_long)n, (u_char *)cp); - n = res_mkquery(IQUERY, "", C_IN, T_A, cp, sizeof(long), - NULL, packet, sizeof(packet)); - break; - - case 'f': - n = res_mkquery(QUERY, cp, C_ANY, T_UINFO, (char *)0, 0, - NULL, packet, sizeof(packet)); - break; - - case 'g': - n = res_mkquery(QUERY, cp, C_ANY, T_GID, (char *)0, 0, - NULL, packet, sizeof(packet)); - break; - - case 'G': - *(int *)cp = htonl(atoi(cp)); - n = res_mkquery(IQUERY, "", C_ANY, T_GID, cp, - sizeof(int), NULL, packet, sizeof(packet)); - break; - - case 'c': - n = res_mkquery(QUERY, cp, C_IN, T_CNAME, (char *)0, 0, - NULL, packet, sizeof(packet)); - break; - - case 'h': - n = res_mkquery(QUERY, cp, C_IN, T_HINFO, (char *)0, 0, - NULL, packet, sizeof(packet)); - break; - - case 'm': - n = res_mkquery(QUERY, cp, C_IN, T_MX, (char *)0, 0, - NULL, packet, sizeof(packet)); - break; - - case 'M': - n = res_mkquery(QUERY, cp, C_IN, T_MAILB, (char *)0, 0, - NULL, packet, sizeof(packet)); - break; - - case 'n': - n = res_mkquery(QUERY, cp, C_IN, T_NS, (char *)0, 0, - NULL, packet, sizeof(packet)); - break; - - case 'p': - n = res_mkquery(QUERY, cp, C_IN, T_PTR, (char *)0, 0, - NULL, packet, sizeof(packet)); - break; - - case 's': - n = res_mkquery(QUERY, cp, C_IN, T_SOA, (char *)0, 0, - NULL, packet, sizeof(packet)); - break; - - case 'T': - n = res_mkquery(QUERY, cp, C_IN, T_TXT, (char *)0, 0, - NULL, packet, sizeof(packet)); - break; - - case 'u': - n = res_mkquery(QUERY, cp, C_ANY, T_UID, (char *)0, 0, - NULL, packet, sizeof(packet)); - break; - - case 'U': - *(int *)cp = htonl(atoi(cp)); - n = res_mkquery(IQUERY, "", C_ANY, T_UID, cp, - sizeof(int), NULL, packet, sizeof(packet)); - break; - - case 'x': - n = res_mkquery(QUERY, cp, C_IN, T_AXFR, (char *)0, 0, - NULL, packet, sizeof(packet)); - break; - - case 'w': - n = res_mkquery(QUERY, cp, C_IN, T_WKS, (char *)0, 0, - NULL, packet, sizeof(packet)); - break; - - case 'b': - n = res_mkquery(QUERY, cp, C_IN, T_MB, (char *)0, 0, - NULL, packet, sizeof(packet)); - break; - - case 'B': - n = res_mkquery(QUERY, cp, C_IN, T_MG, (char *)0, 0, - NULL, packet, sizeof(packet)); - break; - - case 'i': - n = res_mkquery(QUERY, cp, C_IN, T_MINFO, (char *)0, 0, - NULL, packet, sizeof(packet)); - break; - - case 'r': - n = res_mkquery(QUERY, cp, C_IN, T_MR, (char *)0, 0, - NULL, packet, sizeof(packet)); - break; - - case '*': - n = res_mkquery(QUERY, cp, C_IN, T_ANY, (char *)0, 0, - NULL, packet, sizeof(packet)); - break; - -#ifdef ALLOW_UPDATES - case '^': - { - char IType[10], TempStr[50]; - int Type, oldnbytes, nbytes, i; -#ifdef ALLOW_T_UNSPEC - printf("Data type (a = T_A, u = T_UNSPEC): "); - gets(IType); - if (IType[0] == 'u') { - Type = T_UNSPEC; - printf("How many data bytes? "); - gets(TempStr); /* Throw away CR */ - sscanf(TempStr, "%d", &nbytes); - for (i = 0; i < nbytes; i++) { - (NewRR.r_data)[i] = (char) i; - } - } else { -#endif ALLOW_T_UNSPEC - Type = T_A; - nbytes = sizeof(u_long); - printf("Inet addr for new dname (e.g., 192.4.3.2): "); - gets(TempStr); - putlong(ntohl(inet_addr(TempStr)), - NewRR.r_data); -#ifdef ALLOW_T_UNSPEC - } -#endif ALLOW_T_UNSPEC - NewRR.r_class = C_IN; - NewRR.r_type = Type; - NewRR.r_size = nbytes; - NewRR.r_ttl = 99999999; - printf("Add, modify, or modify all (a/m/M)? "); - gets(TempStr); - if (TempStr[0] == 'a') { - n = res_mkquery(UPDATEA, cp, C_IN, Type, - OldRRData, nbytes, - &NewRR, packet, - sizeof(packet)); - } else { - if (TempStr[0] == 'm') { - printf("How many data bytes in old RR? "); - gets(TempStr); /* Throw away CR */ - sscanf(TempStr, "%d", &oldnbytes); - for (i = 0; i < oldnbytes; i++) { - OldRRData[i] = (char) i; - } - n = res_mkquery(UPDATEM, cp, C_IN, Type, - OldRRData, oldnbytes, - &NewRR, packet, - sizeof(packet)); - } else { /* Modify all */ - n = res_mkquery(UPDATEMA, cp, - C_IN, Type, NULL, 0, - &NewRR, packet, - sizeof(packet)); - - } - } - } - break; - -#ifdef ALLOW_T_UNSPEC - case 'D': - n = res_mkquery(UPDATEDA, cp, C_IN, T_UNSPEC, (char *)0, - 0, NULL, packet, sizeof(packet)); - break; - - case 'd': - { - char TempStr[100]; - int nbytes, i; - printf("How many data bytes in oldrr data? "); - gets(TempStr); /* Throw away CR */ - sscanf(TempStr, "%d", &nbytes); - for (i = 0; i < nbytes; i++) { - OldRRData[i] = (char) i; - } - n = res_mkquery(UPDATED, cp, C_IN, T_UNSPEC, - OldRRData, nbytes, NULL, packet, - sizeof(packet)); - } - break; -#endif ALLOW_T_UNSPEC -#endif ALLOW_UPDATES - - default: - printf("a{host} - query T_A\n"); - printf("A{addr} - iquery T_A\n"); - printf("b{user} - query T_MB\n"); - printf("B{user} - query T_MG\n"); - printf("f{host} - query T_UINFO\n"); - printf("g{host} - query T_GID\n"); - printf("G{gid} - iquery T_GID\n"); - printf("h{host} - query T_HINFO\n"); - printf("i{host} - query T_MINFO\n"); - printf("p{host} - query T_PTR\n"); - printf("m{host} - query T_MX\n"); - printf("M{host} - query T_MAILB\n"); - printf("n{host} - query T_NS\n"); - printf("r{host} - query T_MR\n"); - printf("s{host} - query T_SOA\n"); - printf("T{host} - query T_TXT\n"); - printf("u{host} - query T_UID\n"); - printf("U{uid} - iquery T_UID\n"); - printf("x{host} - query T_AXFR\n"); - printf("w{host} - query T_WKS\n"); - printf("c{host} - query T_CNAME\n"); - printf("*{host} - query T_ANY\n"); -#ifdef ALLOW_UPDATES - printf("^{host} - add/mod/moda (T_A/T_UNSPEC)\n"); -#ifdef ALLOW_T_UNSPEC - printf("D{host} - deletea T_UNSPEC\n"); - printf("d{host} - delete T_UNSPEC\n"); -#endif ALLOW_T_UNSPEC -#endif ALLOW_UPDATES - continue; - } - if (n < 0) { - printf("res_mkquery: buffer too small\n"); - continue; - } - if (log) { - fprintf(log,"SEND QUERY\n"); - fp_query(packet, log); - } - n = res_send(packet, n, answer, sizeof(answer)); - if (n < 0) { - printf("res_send: send error\n"); - if (log) fprintf(log, "res_send: send error\n"); - } - else { - if (dump_packet) { - int f; - f = creat("ns_packet.dump", 0644); - write(f, answer, n); - (void) close(f); - } - if (log) { - fprintf(log, "GOT ANSWER\n"); - fp_query(answer, log); - } - } - } -} - -usage() -{ - fprintf(stderr, "Usage: %s [-v] [-i] [-r] [-d] [-p port] hostaddr\n", - progname); - exit(1); -} |