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

📄 updatedns.shar

📁 早期freebsd实现
💻 SHAR
📖 第 1 页 / 共 2 页
字号:
#From: gdmr@dcs.ed.ac.uk#Date: Mon, 26 Apr 93 11:03:57 BST#Message-Id: <5447.9304261003@bruray.dcs.ed.ac.uk>#To: Paul A Vixie <vixie>#Subject: Re: send me your tools##In article <9304251928.AA09770@cognition.pa.dec.com>, you write:#> ... if you have something which converts to/from /etc/hosts to/from#> hosts.txt to/from zone files ...##Here (appended) is my /etc/hosts-to-zonefiles converter.  There were a couple#of reasons I wrote it (apart from /etc/hosts format being well understood by#our system support people):##	it only generates stuff for configured-in networks (which doesn't#	actually matter to us now, but did at the time I wrote it); and##	it does something reasonable for multi-homed hosts##There's some documentation at the top of the source file, and an example#configuration file (which happens to be a copy of our working one).#-- #George D M Ross, Department of Computer Science, University of Edinburgh#     Kings Buildings, Mayfield Road, Edinburgh, Scotland, EH9 3JZ#Mail: gdmr@dcs.ed.ac.uk      Voice: 031-650 5147      Fax: 031-667 7209#! /bin/sh# This is a shell archive.  Remove anything before this line, then unpack# it by saving it into a file and typing "sh file".  To overwrite existing# files, type "sh file -c".  You can also feed this as standard input via# unshar, or by typing "sh <file", e.g..  If this archive is complete, you# will see the following message at the end:#		"End of shell archive."# Contents:  Configure-example Makefile makeDNS.c makeHS.c updateDNS# Wrapped by bind@bruray on Mon Apr 26 10:58:57 1993PATH=/bin:/usr/bin:/usr/ucb ; export PATHif test -f Configure-example -a "${1}" != "-c" ; then   echo shar: Will not over-write existing file \"Configure-example\"elseecho shar: Extracting \"Configure-example\" \(1831 characters\)sed "s/^X//" >Configure-example <<'END_OF_Configure-example'X# makeDNS configuration file for cs & cs1X#X# domains -- format isX#"0.0.0.0" domain zone-file headers-file "other"-zone-file MX-fileX0.0.0.0		dcs.ed.ac.uk New/zone.cs Headers/cs New/zone.cs.LXX# wires -- format isX# subnet mask zone-file reverse-headers-file domainX129.215.36.0	255.255.255.0	/dev/null     /dev/null		dcs.ed.ac.ukX129.215.56.0	255.255.255.0	/dev/null     /dev/null		dcs.ed.ac.ukX#X129.215.160.0	255.255.255.0	New/zone.160  Headers/reverse   dcs.ed.ac.ukX129.215.64.0	255.255.255.0	New/zone.64   Headers/reverse   dcs.ed.ac.ukX129.215.32.0	255.255.255.0	New/zone.32   Headers/reverse   dcs.ed.ac.ukX129.215.96.0	255.255.255.0	New/zone.96   Headers/reverse   dcs.ed.ac.ukX129.215.224.0   255.255.255.0   New/zone.224  Headers/reverse   dcs.ed.ac.ukX129.215.216.0	255.255.255.0	New/zone.216  Headers/reverse   dcs.ed.ac.ukX129.215.212.0	255.255.255.0	New/zone.212  Headers/reverse	dcs.ed.ac.ukX129.215.124.0	255.255.255.0	New/zone.124  Headers/reverse	dcs.ed.ac.ukX129.215.252.0	255.255.255.0	New/zone.252  Headers/reverse	dcs.ed.ac.ukX129.215.2.0	255.255.255.0   New/zone.2    Headers/reverse	dcs.ed.ac.ukX129.215.18.0	255.255.255.0	New/zone.18   Headers/reverse	dcs.ed.ac.ukX129.215.74.0	255.255.255.0	New/zone.74   Headers/reverse	dcs.ed.ac.ukX129.215.202.0	255.255.255.0	New/zone.202  Headers/reverse	dcs.ed.ac.ukX129.215.42.0	255.255.255.0	New/zone.42   Headers/reverse	dcs.ed.ac.ukX129.215.90.0	255.255.255.0	New/zone.90   Headers/reverse	dcs.ed.ac.ukX129.215.218.0	255.255.255.0	New/zone.218  Headers/reverse	dcs.ed.ac.ukX129.215.58.0	255.255.255.0	New/zone.58   Headers/reverse	dcs.ed.ac.ukX129.215.186.0	255.255.255.0	New/zone.186  Headers/reverse	dcs.ed.ac.ukX#X192.41.110.0	255.255.255.0	New/zone.41.110 Headers/reverse	dcs.ed.ac.ukX192.41.131.0	255.255.255.0	New/zone.41.131 Headers/reverse	dcs.ed.ac.ukEND_OF_Configure-exampleif test 1831 -ne `wc -c <Configure-example`; then    echo shar: \"Configure-example\" unpacked with wrong size!fi# end of overwriting checkfiif test -f Makefile -a "${1}" != "-c" ; then   echo shar: Will not over-write existing file \"Makefile\"elseecho shar: Extracting \"Makefile\" \(141 characters\)sed "s/^X//" >Makefile <<'END_OF_Makefile'Xall: makeDNS makeHSXXmakeDNS: makeDNS.cX	cc -O -o makeDNS makeDNS.cX	strip makeDNSXXmakeHS: makeHS.cX	cc -O -o makeHS makeHS.cX	strip makeHSEND_OF_Makefileif test 141 -ne `wc -c <Makefile`; then    echo shar: \"Makefile\" unpacked with wrong size!fi# end of overwriting checkfiif test -f makeDNS.c -a "${1}" != "-c" ; then   echo shar: Will not over-write existing file \"makeDNS.c\"elseecho shar: Extracting \"makeDNS.c\" \(13157 characters\)sed "s/^X//" >makeDNS.c <<'END_OF_makeDNS.c'X/* makeDNS.c -- generate DNS RRs from /etc/hostsX * Copyright (c) 1991, 1992 Department of Computer Science, University ofX * Edinburgh.  Non-commercial use and redistribution is permitted provided thisX * notice remains intact and any modifications are flagged.X *X * This software is offered "as is", with no warranty or support whatsoever.X * Please send comments to gdmr@dcs.ed.ac.uk.X */XX/* Generate a set of DNS RR files from /etc/hosts and some configurationX * files, under a reasonable set of assumptions.  The program expects toX * be running in the target directory.  It reads the file ".configure" inX * that directory.  The file consists of a sequence of "wire" records, oneX * per line, each one listing the network number, netmask, RR file, headerX * file and full domain name for all hosts on that wire.  Alternatively,X * a "domain" record consists of 0.0.0.0 as network number, domain, RR fileX * and header file.X *X * The /etc/hosts file is read in, and hosts are added to a 2-way linked list,X * sorted alphabetically by host name (ordering in the DNS doesn't matter,X * and this sorting allows the program's assumptions to be implemented).X * Primary names are held with their corresponding IP address, while aliasesX * have the name of the corresponding primary.X *X * Once the hosts file has been read in, the output files are opened andX * the constant header information is written (with the sequence numberX * properly updated).  The hosts list is then scanned in ascending orderX * and the corresponding entries written according to the followingX * heuristics: if a host name has as its leading component one of theX * preceding hosts then it is assumed to be a second interface on aX * multi-homed host, and an additional A record is written; and the domainX * of a host is taken to be that of its first A record, as defined in theX * corresponding "wire" entry.  Finally the program exits with a zero status.X *X * Should any errors occur, the program will exit with a non-zero status.X */XX#define HOSTS "/etc/hosts"X#define CONFIG "Configure"X#define LOG "Log"X#define MAXWIRE 63X#define MAXDOMAIN 5X#define LINEBUFFER 120XX#include <stdio.h>X#include <stdlib.h>X#include <ctype.h>X#include <pwd.h>X#include <sys/time.h>X#include <fcntl.h>X#include <time.h>XXtypedef struct _domain {X	char *domainname;X	char *RRfile;X	char *headerfile;X	char *otherZonefile;X	char *MXfile;X	FILE *file;X	FILE *other;X	char *MXdata;X} domain;XXtypedef struct _wire {X	long number;X	long netmask;X	char *RRfile;X	char *headerfile;X	char *domainname;X	FILE *file;X	domain *d;X} wire;XXtypedef struct _host {X	struct _host *forward;X	struct _host *backward;X	long IP;X	char *name;X	struct _host *primary;X	wire *w;X} host;XXstatic host *hostlist;Xstatic wire wireTable[MAXWIRE];Xstatic domain domainTable[MAXDOMAIN];Xstatic int domains, wires;XXvoid readconfig();Xvoid readhosts();Xvoid printhosts();Xvoid openfiles();Xvoid closefiles();XXmain()X{	readconfig();X	readhosts();X	openfiles();X	printhosts();X	closefiles();X	return 0;X}XXstatic void addhost(h)Xhost *h;X{	host *x;X	if (hostlist == NULL) {X		/* List empty, easy case */X		h->forward = NULL;X		h->backward = NULL;X		hostlist = h;X		return;X	}X	x = hostlist;X	/* Skip to insertion point */X	while (strcmp(x->name, h->name) < 0) {X		if (x->forward) {X			/* More, skip */X			x = x->forward;X		}X		else {X			/* Add at the tail of the list */X			h->forward = NULL;X			h->backward = x;X			x->forward = h;X			return;X		}X	}X	/* Sanity check: duplicate? */X	if (!strcmp(x->name, h->name)) {X		(void) fprintf(stderr, "%s duplicate!\n", h->name);X		return;X	}X	/* Insert before x */X	h->forward = x;X	h->backward = x->backward;X	if (x->backward) x->backward->forward = h;	/* Middle */X	else hostlist = h;				/* Head */X	x->backward = h;X}XXstatic long IPconvert(ch)Xchar **ch;X{	long N1, N2, N3, N4;X	N1 = strtol(*ch, ch, 10);  (*ch)++;X	N2 = strtol(*ch, ch, 10);  (*ch)++;X	N3 = strtol(*ch, ch, 10);  (*ch)++;X	N4 = strtol(*ch, ch, 10);  (*ch)++;X	return (N1 << 24) | (N2 << 16) | (N3 << 8) | N4;X}XXstatic char *extractname(ch)Xchar **ch;X{	char *it;X	char *name;X	int n = 0;X	while (isspace(**ch)) (*ch)++;X	if (**ch == '\0' || **ch == '#') return NULL;X	it = *ch;X	while (!isspace(**ch)) {X		(*ch)++;X		n++;X	}X	**ch = '\0';  (*ch)++;X	name = (char *) malloc(n + 1);X	strcpy(name, it);X	return name;X}XXstatic wire *findWire(IP)Xlong IP;X{	int n;X	wire *w;X	if (IP == 0) return NULL;X	for (n = 0, w = wireTable; n < wires; n++, w++) {X		if ((IP & w->netmask) == w->number) {X			return w;X		}X	}X	return NULL;X}XXstatic domain *findDomain(name)Xchar *name;X{	int n;X	domain *d;X	for (n = 0, d = domainTable; n < domains; n++, d++) {X		if (!strcmp(name, d->domainname)) {X			return d;X		}X	}X	return NULL;X}XXstatic void readhosts()X{	FILE *hosts;X	host *h, *ph;X	char *ch;X	char buffer[LINEBUFFER];X	long IP;X	char *primary;X	char *alias;X	wire *w;XX	if ((hosts = fopen(HOSTS, "r")) == NULL) {X		(void) fprintf(stderr, "Failed to open %s\n", HOSTS);X		exit(1);X	}XX	for (;;) {X		if ((ch = fgets(buffer, LINEBUFFER, hosts)) == NULL) break;X		while (isspace(*ch)) ch++;X		if (*ch == '\0' || *ch == '#') continue;X		IP = IPconvert(&ch);X		if ((w = findWire(IP)) == NULL) continue;X		primary = extractname(&ch);X		ph = (host *) malloc(sizeof(host));X		ph->IP = IP;X		ph->w = w;X		ph->name = primary;X		ph->primary = NULL;X		addhost(ph);X		while (*ch != '\0') {X			alias = extractname(&ch);X			if (alias == NULL) break;X			h = (host *) malloc(sizeof(host));X			h->IP = 0;X			h->w = w;X			h->name = alias;X			h->primary = ph;X			addhost(h);X		}X	}X	(void) fclose(hosts);X}XXstatic host *findPrincipal(like)Xhost *like;X{	host *h;X	int l, n;XX	h = like->backward;X	l = strlen(like->name);X	while (h) {X		if (*(h->name) != *(like->name)) return NULL;X		n = strlen(h->name);X		if ((n < l) && !isalnum(like->name[n]) &&X				!strncmp(h->name, like->name, n)) {X			return h;X		}X		h = h->backward;X	}X	return NULL;X}XX#define  printIP(file, IP) \

⌨️ 快捷键说明

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