ns_init.c

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· C语言 代码 · 共 687 行 · 第 1/2 页

C
687
字号
#ifndef lintstatic	char	*sccsid = "@(#)ns_init.c	4.1	(ULTRIX)	7/2/90";#endif lint/************************************************************************ *									* *			Copyright (c) 1984-1988 by			* *		Digital Equipment Corporation, Maynard, MA		* *			All rights reserved.				* *									* *   This software is furnished under a license and may be used and	* *   copied  only  in accordance with the terms of such license and	* *   with the  inclusion  of  the  above  copyright  notice.   This	* *   software  or  any  other copies thereof may not be provided or	* *   otherwise made available to any other person.  No title to and	* *   ownership of the software is hereby transferred.			* *									* *   This software is  derived  from  software  received  from  the	* *   University    of   California,   Berkeley,   and   from   Bell	* *   Laboratories.  Use, duplication, or disclosure is  subject  to	* *   restrictions  under  license  agreements  with  University  of	* *   California and with AT&T.						* *									* *   The information in this software is subject to change  without	* *   notice  and should not be construed as a commitment by Digital	* *   Equipment Corporation.						* *									* *   Digital assumes no responsibility for the use  or  reliability	* *   of its software on equipment which is not supplied by Digital.	* *									* ************************************************************************//* * Copyright (c) 1986 Regents of the University of California *	All Rights Reserved * static char sccsid[] = "@(#)ns_init.c	4.23 (Berkeley) 2/28/88"; *//* * Modification History: * * 18-Jan-88	logcher *	Added BIND 4.7.2. * * 26-Jan-88	logcher *	Added BIND 4.7.3. * * 17-May-89	logcher *	Added BIND 4.8. * */#include <sys/types.h>#include <sys/socket.h>#include <sys/time.h>#ifdef ULTRIXFUNC#include <sys/stat.h>#endif ULTRIXFUNC#include <netinet/in.h>#include <stdio.h>#include <errno.h>#include <signal.h>#include <syslog.h>#include <ctype.h>#include <arpa/nameser.h>#ifdef AUTHEN#include <netdb.h>	#endif AUTHEN#include "ns.h"#include "db.h"struct	zoneinfo zones[MAXZONES];	/* 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 = 30;		/* minimum ns_maint() interval */extern	int lineno;#ifdef AUTHENextern struct hostent *gethostbyaddr_local();#endif AUTHEN#ifdef ULTRIXFUNCextern file_ref_st *load_prep();#endif ULTRIXFUNC/* * Read boot file for configuration info. */ns_init(bootfile)	char *bootfile;{	register struct zoneinfo *zp;	char buf[BUFSIZ];	FILE *fp;	int type;	time_t next_refresh = 0;	struct itimerval ival;	extern int needmaint;#ifdef AUTHEN	struct hostent *host;#endif AUTHEN#ifdef ULTRIXFUNC	file_ref_st	*load_info;	int		slineno;	int		status;	int		zonenum;#endif ULTRIXFUNC#ifdef DEBUG	if (debug >= 3)		fprintf(ddt,"ns_init(%s)\n", bootfile);#endif	gettime(&tt);	if ((fp = fopen(bootfile, "r")) == NULL) {		syslog(LOG_ERR, "%s: %m", bootfile);		exit(1);	}	lineno = 0;	/* 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);	if (localdomain)		free(localdomain);	localdomain = NULL;	/* init zone data */	cache_file = NULL;	nzones = 1;		/* zone zero is cache data */	zones[0].z_type = Z_CACHE;	while (!feof(fp) && !ferror(fp)) {		if (!getword(buf, sizeof(buf), fp))			continue;		/* read named.boot keyword and process args */		if (strcasecmp(buf, "cache") == 0) {			type = Z_CACHE;			zp = zones;		}		else if (strcasecmp(buf, "primary") == 0)			type = Z_PRIMARY;		else if (strcasecmp(buf, "secondary") == 0)			type = Z_SECONDARY;		else 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 {			syslog(LOG_ERR, "%s: line %d: unknown field '%s'\n",				bootfile, lineno, buf);			endline(fp);			continue;		}		if (nzones >= MAXZONES) {			syslog(LOG_ERR, "too many zones (MAXZONES=%d)\n",				MAXZONES);			endline(fp);			continue;		}		if (type != Z_CACHE)			zp = &zones[nzones++];		if (zp->z_origin) {			free(zp->z_origin);			zp->z_origin = 0;		}		if (zp->z_source) {			free(zp->z_source);			zp->z_source = 0;		}		zp->z_type = type;		zp->z_addrcnt = 0;		zp->z_auth = 0;#ifdef ULTRIXFUNC		zp->z_state = 0;		zp->z_xferpid = 0;		zp->z_files = NULL;		zp->z_ftime = 0;		zp->z_load_info = NULL;#endif ULTRIXFUNC		/*		 * read zone origin		 */		if (!getword(buf, sizeof(buf), fp)) {			syslog(LOG_ERR, "%s: line %d: missing origin\n",						bootfile, lineno);			continue;		}		if (buf[0] == '.')			buf[0] = '\0';		zp->z_origin = savestr(buf);		/*		 * read source file or host address		 */		if (!getword(buf, sizeof(buf), fp)) {			syslog(LOG_ERR, "%s: line %d: missing origin\n",						bootfile, lineno);			continue;		}#ifdef DEBUG		if (debug)			fprintf(ddt,"zone[%d] type %d: '%s'",			        zp-zones, zp->z_type,				*(zp->z_origin) == '\0' ? "." : zp->z_origin);#endif		zp->z_time = 0;		zp->z_refresh = 0;	/* by default, no dumping */		switch (type) {		case Z_CACHE:			zp->z_source = savestr(buf);#ifdef DEBUG			if (debug)				fprintf(ddt,", source = %s\n", zp->z_source);#endif			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 '%s', ignored\n",						bootfile, lineno, buf);					zp->z_refresh = 0;				} else if (cache_file == NULL)					cache_file = zp->z_source;#else				syslog(LOG_WARNING,				"%s: line %d: cache refresh ignored\n",					bootfile, lineno);#endif				endline(fp);				continue;			}#ifdef ULTRIXFUNC			if((load_info = load_prep(zp, zp->z_source,			    zp->z_origin, zp - zones)) == NULL) {				endline(fp);				continue;			}							slineno = lineno;						if ((status = db_load(load_info, NO_ITER_LIMIT)) != -2 ) {				if(status == -1) {				    /* load is done */				    move_loaddb(fcachetab, ALL_DATA);				    set_zp(load_info->zp, zp);				    zp->z_files = load_info->files;										} else {				    delete_zone(1, fcachetab, ALL_DATA);				    free_files(load_info->files);				}				free(load_info->zp);				zp->z_load_info = NULL;				free(load_info);				lineno = slineno;			} else {				syslog(LOG_ERR,	"%s: line %d: Non-incremental load did not finish, abort.\n", bootfile, lineno);				abortslowreload(zp, ALL_DATA);#ifdef DEBUG				if (debug)					fprintf(ddt, "%s: line %d: Non-incremental load did not finish, abort.\n", bootfile, lineno);#endif			}#else ULTRIXFUNC			(void) db_load(zp->z_source, zp->z_origin, zp);#endif ULTRIXFUNC			break;		case Z_PRIMARY:			zp->z_source = savestr(buf);#ifdef DEBUG			if (debug)				fprintf(ddt,", source = %s\n", zp->z_source);#endif#ifdef ULTRIXFUNC			if((load_info = load_prep(zp, zp->z_source,			    zp->z_origin, zp - zones)) == NULL) {				endline(fp);				continue;			}							slineno = lineno;						if ((status = db_load(load_info, NO_ITER_LIMIT)) != -2 ) {				if(status == -1) {					/* load is done */					replace_data(hashtab, zp - zones);					set_zp(load_info->zp, zp);					if(!load_info->format_errs)						zp->z_auth = 1;					zp->z_files = load_info->files;				} else {				    delete_zone(1, hashtab, zonenum);				    free_files(load_info->files);				}				free(load_info->zp);				zp->z_load_info = NULL;				free(load_info);				lineno = slineno;			} else {				syslog(LOG_ERR,	"%s: line %d: Non-incremental load did not finish, abort.\n", bootfile, lineno);				abortslowreload(zp, ALL_DATA);#ifdef DEBUG				if (debug)					fprintf(ddt, "%s: line %d: Non-incremental load did not finish, abort.\n", bootfile, lineno);#endif			}#else ULTRIXFUNC			if (db_load(zp->z_source, zp->z_origin, zp) == 0)				zp->z_auth = 1;#endif ULTRIXFUNC

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?