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

📄 updatedns.shar

📁 早期freebsd实现
💻 SHAR
📖 第 1 页 / 共 2 页
字号:
X	(void) fprintf(file, "%d.%d.%d.%d", \X		(IP >> 24) & 255, (IP >> 16) & 255, (IP >> 8) & 255, IP & 255)XX/* printhosts has four cases:X *   1	IP address, no principal entry -- write the name as it stands, plusX *	the reverse name, again as it stands.X *   2	IP address plus principal entry -- write out the address as for theX *	principal entry, plus the current name as another A RR.  Write theX *	reverse entry as pointing to the principal name.X *   3	alias, no principal entry -- write a CNAME RR pointing to the primary.X *   4	alias plus principal entry -- write an A RR with the primary's address.X *X * For example, suppose the /etc/hosts file has the following:X *	129.215.64.48  baleshare baleshare-b agfahostX *	29.215.160.155 baleshare-gw baleshare-aX * Then baleshare is case 1, baleshare-gw is case 2, baleshare-a andX * baleshare-b are case 4, and agfahost is case 3.  Confused?  BTW, changingX * baleshare-gw to fred, say, would break the algorithm -- the main name of theX * second interface better be related to the main name of the first!X */XXvoid printhosts()X{	host *h, *m, *x;X	wire *w;X	FILE *f;X	int dotted;XX	h = hostlist;X	while (h) {X		m = findPrincipal(h);X		if (h->IP) {X			if (m) {X				/* Case 2 */X				/* A RR for name */X				(void) fprintf(m->w->d->file,X					"%-23s IN\tA\t", h->name);X				printIP(m->w->d->file, h->IP);X				(void) putc('\n', m->w->d->file);X				if (m->w->d->MXdata) {X					(void) fputs(m->w->d->MXdata,X						m->w->d->file);X				}X				/* A RR for principal's name */X				(void) fprintf(m->w->d->file,X					"%-23s IN\tA\t", m->name);X				printIP(m->w->d->file, h->IP);X				(void) putc('\n', m->w->d->file);X				/* back-pointer -> principal */X				(void) fprintf(h->w->file,X					"%d\tIN\tPTR\t%s.%s.\n",X					h->IP & (~h->w->netmask),X					m->name, m->w->d->domainname);X				if (m->w->d->other) {X					(void) fprintf(m->w->d->other,X						"%-23s IN\tCNAME\t%s.%s.\n",X						h->name, m->name,X						m->w->d->domainname);X				}X			}X			else {X				/* Case 1 */X				dotted = (int) index(h->name, '.');X				if (!dotted) {X					(void) fprintf(h->w->d->file,X						"%-23s IN\tA\t", h->name);X					printIP(h->w->d->file, h->IP);X					(void) putc('\n', h->w->d->file);X					if (h->w->d->MXdata) {X						(void) fputs(h->w->d->MXdata,X							h->w->d->file);X					}X					if (h->w->d->other) {X						(void) fprintf(h->w->d->other,X							"%-23s IN\tCNAME\t%s.%s.\n",X							h->name, h->name,X							h->w->d->domainname);X					}X				}X				(void) fprintf(h->w->file,X					dotted ? "%d\tIN\tPTR\t%s\n"X						: "%d\tIN\tPTR\t%s.%s.\n",X					h->IP & (~h->w->netmask),X					h->name, h->w->d->domainname);X			}X		}X		else {X			if (m) {X				/* Case 4 */X				(void) fprintf(m->w->d->file,X					"%-23s IN\tA\t", h->name);X				printIP(m->w->d->file, h->primary->IP);X				(void) putc('\n', m->w->d->file);X				if (m->w->d->MXdata) {X					(void) fputs(m->w->d->MXdata,X						m->w->d->file);X				}X				if (m->w->d->other) {X					(void) fprintf(m->w->d->other,X						"%-23s IN\tCNAME\t%s.%s.\n",X						h->name, m->name,X						m->w->d->domainname);X				}X			}X			else {X				/* Case 3 */X				x = findPrincipal(h->primary);X				if (!x) x = h->primary;X				(void) fprintf(x->w->d->file,X					"%-23s IN\tCNAME\t%s.%s.\n",X					h->name, x->name,X					x->w->d->domainname);X				if (x->w->d->other) {X					(void) fprintf(x->w->d->other,X						"%-23s IN\tCNAME\t%s.%s.\n",X						h->name, x->name,X						x->w->d->domainname);X				}X			}X		}X		h = h->forward;X	}X}XXstatic void readconfig()X{	FILE *config;X	long IP;X	char *ch;X	char buffer[LINEBUFFER];X	wire *w;X	domain *d;XX	if ((config = fopen(CONFIG, "r")) == NULL) {X		(void) fprintf(stderr, "Failed to open %s\n", CONFIG);X		exit(1);X	}X	for (;;) {X		if ((ch = fgets(buffer, LINEBUFFER, config)) == NULL) break;X		while (isspace(*ch)) ch++;X		if (*ch == '\0' || *ch == '#') continue;X		IP = IPconvert(&ch);X		if (IP) {X			/* Wire record */X			w = wireTable + wires++;X			w->number = IP;X			w->netmask = IPconvert(&ch);X			w->RRfile = extractname(&ch);X			w->headerfile = extractname(&ch);X			w->domainname = extractname(&ch);X			w->file = stderr;  /* meantime */X			w->d = findDomain(w->domainname);X			if (!w->d) {X				(void) fprintf(stderr, "Undefined domain %s:\n",X					w->domainname);X				(void) fputs(buffer, stderr);X				(void) fputc('\n', stderr);X				exit(2);X			}X		}X		else {X			/* Domain record */X			d = domainTable + domains++;X			d->domainname = extractname(&ch);X			d->RRfile = extractname(&ch);X			d->headerfile = extractname(&ch);X			d->otherZonefile = extractname(&ch);X			d->MXfile = extractname(&ch);X			d->file = stderr;  /* meantime */X			d->other = NULL;X			d->MXdata = NULL;X		}X	}X	(void) fclose(config);X}XXstatic void writeheader(f, h, MXdata)XFILE *f;Xchar *h;Xchar *MXdata;X{	static struct passwd *pwd;X	time_t tt;X	static struct tm *ttm;X	static char *t;X	static char stamp[20];X	FILE *hf, *l;X	char buffer[LINEBUFFER];XX	if (!pwd) {X		pwd = getpwuid(getuid());X		endpwent();X		tt = time(NULL);X		ttm = localtime(&tt);X		(void) sprintf(stamp, "%d%3.3d%3.3d",X			ttm->tm_year, ttm->tm_yday,X			((60 * ttm->tm_hour) + ttm->tm_min) >> 1);X		t = asctime(ttm);X		if (l = fopen(LOG, "a")) {X			fprintf(l, "Generated by %s on %s", pwd->pw_name, t);X			fclose(l);X		}X	}X	(void) fprintf(f, ";; Generated by %s on %s\n", pwd->pw_name, t);X	if ((hf = fopen(h, "r")) == NULL) {X		(void) fprintf(stderr, "Can't open header file %s\n", h);X		exit(4);X	}X	(void) fprintf(f, ";; Including %s\n", h);X	for (;;) {X		if (fgets(buffer, LINEBUFFER, hf) == NULL) break;X		(void) fprintf(f, buffer, stamp);X	}X	(void) fclose(hf);X	(void) fprintf(f, ";; End of %s\n\n", h);X	if (MXdata) {X		(void) fputc('@', f);X		(void) fputs(MXdata, f);X		(void) fputc('\n', f);X	}X}XXstatic void openfiles()X{	int i;X	int MXfd;X	int MXsize;X	wire *w;X	domain *d;XX	for (i = 0, d = domainTable; i < domains; i++, d++) {X		if ((d->file = fopen(d->RRfile, "w")) == NULL) {X			(void) fprintf(stderr, "Can't open %s\n", d->RRfile);X			exit(3);X		}X		if (d->otherZonefile) {X			if ((d->other = fopen(d->otherZonefile, "w")) == NULL) {X				(void) fprintf(stderr, "Can't open %s\n",X						d->otherZonefile);X				exit(3);X			}X		}X		if (d->MXfile) {X			if ((MXfd = open(d->MXfile, O_RDONLY, 0)) < 0) {X				(void) fprintf(stderr, "Can't open %s\n",X						d->MXfile);X				exit(3);X			}X			d->MXdata = (char *) malloc(2048);X			if ((MXsize = read(MXfd, d->MXdata, 2048)) < 0) {X				(void) fprintf(stderr,X						"Couldn't read from %s\n",X						d->MXfile);X				exit(3);X			}X			(void) close(MXfd);X			*(d->MXdata + MXsize) = '\0';X		}X		writeheader(d->file, d->headerfile, d->MXdata);X		if (d->otherZonefile)X			writeheader(d->other, d->headerfile, d->MXdata);X	}X	for (i = 0, w = wireTable; i < wires; i++, w++) {X		if ((w->file = fopen(w->RRfile, "w")) == NULL) {X			exit(3);X		}X		writeheader(w->file, w->headerfile, (char *) 0);X	}X}XXstatic void closefiles()X{	int i;X	domain *d;X	wire *w;XX	for (i = 0, d = domainTable; i < domains; i++, d++) {X		(void) fclose(d->file);X		if (d->other) (void) fclose(d->other);X	}X	for (i = 0, w = wireTable; i < wires; i++, w++) {X		(void) fclose(w->file);X	}X}END_OF_makeDNS.cif test 13157 -ne `wc -c <makeDNS.c`; then    echo shar: \"makeDNS.c\" unpacked with wrong size!fi# end of overwriting checkfiif test -f makeHS.c -a "${1}" != "-c" ; then   echo shar: Will not over-write existing file \"makeHS.c\"elseecho shar: Extracting \"makeHS.c\" \(789 characters\)sed "s/^X//" >makeHS.c <<'END_OF_makeHS.c'X/* Copy stdin to stdout, substituting any %s for the current timestampX * (hacked out of makeDNS.c).  The idea is that the HS-class header shouldX * just $INCLUDE anything it needs, which will have been generated separately.X */XX#include <stdio.h>X#include <sys/types.h>X#include <sys/time.h>X#include <time.h>XX#define LINEBUFFER 120X#define LOG "/dev/tty"XXint main()X{	time_t tt;X	struct tm *ttm;X	char *t;X	char stamp[20];X	char buffer[LINEBUFFER];XX	tt = time(NULL);X	ttm = localtime(&tt);X	(void) sprintf(stamp, "%d%3.3d%3.3d",X		ttm->tm_year, ttm->tm_yday,X		((60 * ttm->tm_hour) + ttm->tm_min) >> 1);X	t = asctime(ttm);XX	(void) printf(";; Generated on %s\n", t);XX	for (;;) {X		if (fgets(buffer, LINEBUFFER, stdin) == NULL) break;X		(void) printf(buffer, stamp);X	}X	return 0;X}END_OF_makeHS.cif test 789 -ne `wc -c <makeHS.c`; then    echo shar: \"makeHS.c\" unpacked with wrong size!fi# end of overwriting checkfiif test -f updateDNS -a "${1}" != "-c" ; then   echo shar: Will not over-write existing file \"updateDNS\"elseecho shar: Extracting \"updateDNS\" \(222 characters\)sed "s/^X//" >updateDNS <<'END_OF_updateDNS'X#! /bin/shXcd /var/named.PrimaryX/usr/local/etc/makeDNSXecho "Update DNS database"Xif [ $? != 0 ] ; thenX	exitXfiX/bin/cp New/zone.* .Xif [ $? != 0 ] ; thenX	exitXfiXecho "Reload DNS server"Xkill -HUP `cat /etc/named.pid`END_OF_updateDNSif test 222 -ne `wc -c <updateDNS`; then    echo shar: \"updateDNS\" unpacked with wrong size!fichmod +x updateDNS# end of overwriting checkfiecho shar: End of shell archive.exit 0

⌨️ 快捷键说明

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