ns_init.c

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

C
687
字号
#ifdef ALLOW_UPDATES			/* Guarantee calls to ns_maint() */			zp->z_refresh = maint_interval;#else#ifndef PRIMARY_MAINT			zp->z_refresh = 0;			zp->z_time = 0;#endif PRIMARY_MAINT#endif ALLOW_UPDATES			break;		case Z_SECONDARY:#ifdef DEBUG			if (debug)				fprintf(ddt,"\n\taddrs: %s, ", buf);#endif			zp->z_addr[zp->z_addrcnt].s_addr =				inet_addr(buf);#ifdef AUTHEN			if((host = gethostbyaddr_local(&(zp->z_addr[zp->z_addrcnt].s_addr),					    sizeof(struct in_addr),AF_INET)) == (struct hostent *)NULL){				syslog(LOG_ERR, "%s:", "address of primary server not in local db");				exit(1);			}			strcpy(zp->z_dname[zp->z_addrcnt], host->h_name);#endif AUTHEN							/* Indicate no cache for this zone yet */			zp->z_source = (char *) NULL;			if (zp->z_addr[zp->z_addrcnt].s_addr != (unsigned)-1)				zp->z_addrcnt++;			while (getword(buf, sizeof(buf), fp)) {				if (buf[0] == '\0')					break;				zp->z_addr[zp->z_addrcnt].s_addr =					inet_addr(buf);				if (zp->z_addr[zp->z_addrcnt].s_addr ==						(unsigned)-1) {					zp->z_source = savestr(buf);					break;				}#ifdef AUTHEN				if((host = gethostbyaddr_local(&(zp->z_addr[zp->z_addrcnt].s_addr),							       sizeof(struct in_addr),							       AF_INET))				   == (struct hostent *)NULL) {					syslog(LOG_ERR, "%s:", "address of primary server not in local db");					exit(1);				}				strcpy(zp->z_dname[zp->z_addrcnt],				       host->h_name);#endif AUTHEN#ifdef DEBUG				if (debug)					fprintf(ddt,"%s, ",buf);#endif				if (++zp->z_addrcnt >= NSMAX) {					zp->z_addrcnt = NSMAX;#ifdef DEBUG					if (debug)					    fprintf(ddt,						"\nns.h NSMAX reached\n");#endif					break;				}			}#ifdef DEBUG			if (debug)				fprintf(ddt,"addrcnt = %d\n", zp->z_addrcnt);#endif			zoneinit(zp);			break;		}		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);	/*	 * 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}zoneinit(zp)	register struct zoneinfo *zp;{	#ifdef ULTRIXFUNC	file_ref_st *load_info;	int slineno;	int status;	#ifdef DEBUG	if (debug)		fprintf(ddt,"zoneinit()\n");#endif	/*	 * 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 && ((load_info = load_prep(zp, zp->z_source,				zp->z_origin, zp - zones)) != NULL)) {		slineno = lineno;					if((status = db_load(load_info, NO_ITER_LIMIT)) == -1) {			lineno = slineno;		        replace_data(hashtab, zp - zones);			set_zp(load_info->zp, zp);			zp->z_files = load_info->files;			free(load_info->zp);			zp->z_load_info = NULL;			if(!load_info->format_errs) {				free(load_info);				zp->z_auth = 1;				return;			}			free(load_info);		} else if (status == -2) {			syslog(LOG_ERR,	"bootfile: line %d: Non-incremental load did not finish, abort.\n", lineno);			abortslowreload(zp, ALL_DATA);#ifdef DEBUG				if (debug)					fprintf(ddt, "bootfile: line %d: Non-incremental load did not finish, abort.\n", lineno);#endif		} else {			delete_zone(1, hashtab, zp - zones);			free_files(load_info->files);			free(load_info->zp);			zp->z_load_info = NULL;			free(load_info);			lineno = slineno;		}		  		lineno = slineno;	}	/*	 * Set zone to be refreshed immediately.	 */	zp->z_refresh = INIT_REFRESH;	zp->z_retry = INIT_REFRESH;	zp->z_time = tt.tv_sec;	zp->z_class = C_ANY;		#else ULTRIXFUNC#ifdef DEBUG	if (debug)		fprintf(ddt,"zoneinit()\n");#endif	/*	 * 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 ||	    db_load(zp->z_source, zp->z_origin, zp) != 0) {		/*		 * Set zone to be refreshed immediately.		 */		zp->z_refresh = INIT_REFRESH;		zp->z_retry = INIT_REFRESH;		zp->z_time = tt.tv_sec;	} else		zp->z_auth = 1;#endif ULTRIXFUNC}#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(), *dotPos;	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 '.' */		dotPos = index(zoneName, '.');		if (dotPos)			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_UPDATESget_forwarders(fp)	FILE *fp;{	char buf[BUFSIZ];	struct fwdinfo *fip = NULL, *ftp = NULL;#ifdef AUTHEN	struct hostent *host;#endif AUTHEN	extern struct	sockaddr_in nsaddr;	extern struct	fwdinfo *fwdtab;#ifdef DEBUG	if (debug)		fprintf(ddt,"forwarders ");#endif	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))		    != (unsigned)-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;			}#ifdef AUTHEN		if ((host = gethostbyaddr_local(&(ftp->fwdaddr.sin_addr.s_addr), sizeof(struct in_addr), AF_INET)) == (struct hostent *)NULL) {			syslog(LOG_ERR, "address of forwarder %s not in local hosts file",buf);			continue;		}		strcpy(ftp->fwdname, host->h_name);#endif AUTHEN		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}

⌨️ 快捷键说明

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