⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ns_init.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
			if (zp->z_source && (!strcmp(source, zp->z_source)) &&			    (zp->z_state & Z_INCLUDE) == 0 && 			    stat(zp->z_source, &f_time) == 0 &&			    zp->z_ftime == f_time.st_mtime) {				dprintf(1, (ddt, "cache is up to date\n"));				if (source != cache_file)					free(source);				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;			dprintf(1, (ddt, "reloading zone\n"));			(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 = strchr(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			dprintf(1, (ddt, ", source = %s\n", source));			/*			 * 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) {				dprintf(1, (ddt, "zone is up to date\n"));				free(source);				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_state &= ~Z_AUTH;			dprintf(1, (ddt, "reloading zone\n"));			if (db_load(zp->z_source, zp->z_origin, zp, 0) == 0)				zp->z_state |= Z_AUTH;#ifdef ALLOW_UPDATES			/* Guarantee calls to ns_maint() */			zp->z_refresh = maint_interval;#else			zp->z_refresh = 0;	/* no maintenance needed */			zp->z_time = 0;#endif			break;		case Z_SECONDARY:#ifdef STUBS		case Z_STUB:#endif			source = NULL;			dprintf(1, (ddt, "\n\taddrs: "));			do {				if (!inet_aton(buf,					       &zp->z_addr[zp->z_addrcnt])				    ) {					source = savestr(buf);    		                        endline(fp);					break;				}				dprintf(1, (ddt, "%s, ", buf));				if (++zp->z_addrcnt > NSMAX - 1) {					zp->z_addrcnt = NSMAX - 1;					dprintf(1, (ddt,						    "\nns.h NSMAX reached\n"));				}			} while (getword(buf, sizeof(buf), fp));			dprintf(1, (ddt, "addrcnt = %d\n", zp->z_addrcnt));			if (!source) {				/*				 * We will always transfer this zone again				 * after a reload.				 */				sprintf(buf, "/%s/NsTmp%d.%d", _PATH_TMPDIR,					getpid(), 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)) {				dprintf(1, (ddt, "backup file changed\n"));				free(zp->z_source);				zp->z_source = 0;				zp->z_state &= ~Z_AUTH;				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_state & Z_AUTH))				zoneinit(zp);#ifdef FORCED_RELOAD			else {				/* 				** Force secondary to try transfer right away 				** after SIGHUP.				*/				if(reloading == 1)					zp->z_time = tt.tv_sec;			}#endif /* FORCED_RELOAD */			break;		}                zp->z_state |= Z_FOUND;		dprintf(1, (ddt, "zone[%d] type %d: '%s'",			    zp-zones, type,			    *(zp->z_origin) == '\0' ? "." : zp->z_origin));		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;		dprintf(1, (ddt, " z_time %d, z_refresh %d\n",			    zp->z_time, zp->z_refresh));	}	(void) my_fclose(fp);	lineno = slineno;}static voidzoneinit(zp)	register struct zoneinfo *zp;{	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_state |= Z_AUTH;	}}#ifdef ALLOW_UPDATES/* * Look for the authoritative zone with the longest matching RHS of dname * and return its zone # or zero if not found. */intfindzone(dname, class)	char *dname;	int class;{	char *dZoneName, *zoneName;	int dZoneNameLen, zoneNameLen;	int maxMatchLen = 0;	int maxMatchZoneNum = 0;	int zoneNum;	dprintf(4, (ddt, "findzone(dname=%s, class=%d)\n", dname, class));#ifdef DEBUG	if (debug >= 5) {		fprintf(ddt, "zone dump:\n");		for (zoneNum = 1; zoneNum < nzones; zoneNum++)			printzoneinfo(zoneNum);	}#endif	dZoneName = strchr(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;		dprintf(5, (ddt, "about to strncasecmp('%s', '%s', %d)\n",			    dZoneName, zoneName, dZoneNameLen));		if (strncasecmp(dZoneName, zoneName, dZoneNameLen) == 0) {			dprintf(5, (ddt, "match\n"));			/*			 * 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;			}		} else {			dprintf(5, (ddt, "no match\n"));		}	}	dprintf(4, (ddt, "findzone: returning %d\n", maxMatchZoneNum));	return (maxMatchZoneNum);}#endif /* ALLOW_UPDATES */static voidget_forwarders(fp)	FILE *fp;{	char buf[BUFSIZ];	register struct fwdinfo *fip = NULL, *ftp = NULL;#ifdef SLAVE_FORWARD	int forward_count = 0;#endif	dprintf(1, (ddt, "forwarders "));	/* on mulitple forwarder lines, move to end of the list */#ifdef SLAVE_FORWARD	if (fwdtab != NULL){		forward_count++;		for (fip = fwdtab; fip->next != NULL; fip = fip->next)			forward_count++;	}#else	if (fwdtab != NULL) {		for (fip = fwdtab; fip->next != NULL; fip = fip->next) {			;		}	}#endif /* SLAVE_FORWARD */	while (getword(buf, sizeof(buf), fp)) {		if (strlen(buf) == 0)			break;		dprintf(1, (ddt," %s",buf));		if (ftp == NULL)			ftp = (struct fwdinfo *)malloc(sizeof(struct fwdinfo));		if (inet_aton(buf, &ftp->fwdaddr.sin_addr)) {			ftp->fwdaddr.sin_port = ns_port;			ftp->fwdaddr.sin_family = AF_INET;		} else {			syslog(LOG_ERR, "'%s' (ignored, NOT dotted quad)",			       buf);			dprintf(1, (ddt, " (ignored, NOT dotted quad)"));			continue;			}#ifdef FWD_LOOP		if (aIsUs(ftp->fwdaddr.sin_addr)) {			syslog(LOG_ERR,			       "Forwarder '%s' ignored, my address",			       buf);			dprintf(1, (ddt, " (ignored, my address)"));			continue;		}#endif /* FWD_LOOP */		ftp->next = NULL;		if (fwdtab == NULL)			fwdtab = ftp;	/* First time only */		else			fip->next = ftp;		fip = ftp;		ftp = NULL;#ifdef SLAVE_FORWARD		forward_count++;#endif /* SLAVE_FORWARD */	}	if (ftp)		free((char *)ftp);	#ifdef SLAVE_FORWARD	/*	** Set the slave retry time to 60 seconds total divided	** between each forwarder	*/	if (forward_count != 0) {		slave_retry = (int) (60 / forward_count);		if(slave_retry <= 0)			slave_retry = 1;	}#endif	dprintf(1, (ddt, "\n"));#ifdef DEBUG	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}static voidfree_forwarders(){	register struct fwdinfo *ftp, *fnext;	for (ftp = fwdtab; ftp != NULL; ftp = fnext) {		fnext = ftp->next;		free((char *)ftp);	}	fwdtab = NULL;}static struct zoneinfo *find_zone(name, type, class) 	char *name;	int type, class;{	register struct zoneinfo *zp;        for (zp = &zones[1]; zp < &zones[nzones]; zp++) {		if (zp->z_type == type && zp->z_class == class &&		    strcasecmp(name, zp->z_origin) == 0) {			dprintf(2, (ddt, ", old zone (%d)", zp - zones));			return (zp);		}	}	dprintf(2, (ddt, ", new zone"));	return NULL;}#ifdef DEBUG/* prints out the content of zones */static voidcontent_zone(end) 	int end;{	int i;	for (i = 1;  i <= end;  i++) {		printzoneinfo(i);	}}#endif

⌨️ 快捷键说明

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