[alt.sources] uuhosts

wisner@eddie.MIT.EDU (Bill Wisner) (02/15/88)

From: talcott!ut-sally!jsq (John Quarterman)
Subject: uuhosts 1.69
Newsgroups: mod.sources
Approved: jpn@panda.UUCP

Mod.sources:  Volume 3, Issue 90
Submitted by: talcott!ut-sally!jsq (John Quarterman)

This is uuhosts version 1.69   Improvements over the last release (1.59)
include faster execution, compressed maps, multiple hosts in #N lines,
and path.local

		John Quarterman
		Department of Computer Sciences
		University of Texas at Austin
		Austin, Texas 78712 USA
		jsq@sally.utexas.edu (formerly jsq@ut-sally.ARPA)
		{ctvax,gatech,harvard,ihnp4,pyramid,seismo,topaz}!ut-sally!jsq

: This is a shar archive.  Extract with sh, not csh.
echo x - README
sed -e 's/^X//' > README << '!RoNnIe!RaYgUn!'
XThis is the source directory for uuhosts, which may be used to display
XUUCP mail and USENET news information previously extracted from the
XUSENET newsgroup mod.map.  Mail routing information as produced by
Xpathalias is also displayed.  Since uuhosts needs the map information
Xfrom the USENET spool directory for mod.map extracted into a more
Xaccessible (and permanent) location it can also be used to do that.
X
XThis version of uuhosts, 1.69, works with the latest (December 1985)
Xmod.map postings.  Changes from the previous distributed version, 1.59,
Xinclude faster display (sed is used in place of awk), and path.local is
Xused (per mod.map's README) instead of Local for local path information.
XThe maps may be kept compressed to save disk space.  Multiple host names
Xmay appear (separated by white space or commas) in #N lines of map entries.
X
XIf you have a uuhosts of version 1.58 or previous, you will need to
X*completely reinstall* uuhosts.  Even with a newer version, you
Xshould still run "uuhosts -setup", and it wouldn't hurt to do it all.
X
X
XIf you don't have a UNIX group named news in /etc/group, you should 
Xcreate one, as uuhosts depends on it.
X
XTo install uuhosts, first look at the beginning of the Makefile and
Xadjust any pathnames or other parameters which are incorrect for your
Xsystem.  Then do "make" to be sure everything compiles correctly.
XTo install the necessary shell script, C program, and manual entry,
Xas well as creating all necessary new directories, do "make install"
Xas root.
X
XOnce the program is installed, you will want to extract any existing
Xmod.map articles so uuhosts can display their information.  To do
Xthis, type "uuhosts -setup &".  Do not do it as root!  Do it as some
Xuser in group news.  It will take a while:  display speed has been
Xbought by slowness in extraction.  You should only need to do this
Xonce, because of the last installation steps:
X
XFinally, modify NEWS/sys by hand so that inews will batch incoming
Xmod.map articles, and also arrange for "uuhosts -unbatch" to
Xbe called nightly by cron.  See the MAINTENANCE section of the uuhosts
Xmanual entry for how to do this.  Do not call "uuhosts -unbatch" as root!
XHave it called as some user in group news.
X
X
XNeither pathalias nor compress are included here.  Both have been
Xposted to mod.sources recently:  contact the moderator for copies.
XIf you have uupath, you may want to use it to look up UUCP routing
Xinformation instead of the method uuhosts uses by default.
XJust look for uupath in uuhosts.sh and it's obvious what to change.
X
X
XFor the mod.map extraction (and *only* that extraction), uuhosts
Xdepends on a small setuid program called mapsh (included here) which
Xuses chroot(2), which is in (at least) 4BSD, System N, and Version 7.
XThe purpose of mapsh is to limit the commands which may be executed
Xwhen found in a map article.  If you trust everyone who can post to
XUSENET from any machine in the world, you can probably replace mapsh
Xwith "cd $MAPS; sh".  Or you can use unmvax!lee's article parser in C,
Xif you like.
X
X		John Quarterman
X		Department of Computer Sciences
X		University of Texas at Austin
X		Austin, Texas 78712 USA
X		jsq@sally.utexas.edu (formerly jsq@ut-sally.ARPA)
X		{ctvax,gatech,harvard,ihnp4,pyramid,seismo,topaz}!ut-sally!jsq
X
XHere is an example of the most common use of uuhosts, which is to
Xdisplay information about a particular host:
X
Xim4u% uuhosts nbires
XUUCP mail path from im4u to nbires:
Xnbires	ut-sally!nbires!%s
XUUCP mail path for nbires annotated by location:
Xnbires(usa.co)	ut-sally(usa.tx)!nbires(usa.co)!%s
X
XUUCP mail information for host nbires (#USENET lines show USENET news links):
X#Name			nbires
X#System-CPU-OS		VAX-11/750; UNIX BSD 4.2
X#Organization		NBI, Inc.
X#Contact		Kirk Webb
X#Electronic-Address	postmaster@nbires.UUCP
X#Telephone		(303) 444-5710
X#Postal-Address		P.O. Box 9001, Boulder, CO 80301
X#Latitude-Longitude	40 01 N / 105 17 W city
X#Written-by		mccallum@nbires.UUCP (Doug McCallum); Mon Sep  9 13:27:28 MDT 1985
X#USENET	cires opus stcvax gangue utopia hao isis bdaemon fred boulder
Xnbires	allegra(EVENING+HIGH), amd(EVENING+HIGH), attunix(EVENING+HIGH),
X	boulder(DEMAND), bdaemon(DEMAND), cbosgd(EVENING+HIGH), cires(DEMAND),
X	cisden(DEMAND), cornell(EVENING), csu-cs(DEMAND), ctvax(DEMAND),
X	cadnetix(DEMAND), 
X	fred(DIRECT), gangue(DEMAND), galon(DEMAND), hao(DEMAND),
X	isis(DIRECT), koala(DEMAND),
X	lbl-csam(EVENING),
X	onecom(DIRECT),
X	princeton(WEEKLY/3), pyramid(EVENING+LOW),
X	scgvaxd(EVENING), stcvax(DEMAND), ucbvax(EVENING+HIGH),
X	udenva(DEMAND), uofm-cv(EVENING), usenix(EVENING+HIGH), usiiden(DEMAND),
X	utah-cs(EVENING+LOW), ut-ngp(EVENING), ut-sally(EVENING),
X	utopia(DAILY), unidot(DEMAND), vianet(POLLED)
X# nbinet = @{nbires, binkley, opus, yaz, milo, oasys, boson}(LOCAL)
X
!RoNnIe!RaYgUn!
echo x - uuhosts.sh
sed -e 's/^X//' > uuhosts.sh << '!RoNnIe!RaYgUn!'
X#!/bin/sh
X# '@(#) uuhosts.sh 1.69 86/01/06'
X# uuhosts - UUCP mail and USENET news information
X
XMAPS=/usr/spool/news/maps
XUUCPMAPGROUP=mod.map
XUUCPMAP=$UUCPMAPGROUP
XRUUHOSTS=uuhosts
XDEFPAGER=cat
Xpager="${PAGER-$DEFPAGER}"
X
Xcase $RUUHOSTS in
X"")
X	;;
X*)
X	if [ ! -d $MAPS/$UUCPMAP ]; then
X		client $RUUHOSTS uuhosts $* | $pager
X		exit
X	fi
X	;;
Xesac
X
XBIN=/usr/local
XLIB=/usr/local/lib
XNEWS=$LIB/news
XMAPSH=$NEWS/mapsh
XUUCPSPOOL=/usr/spool/news/mod/map
XPATHS=$LIB/nmail.paths
XWHERE=$LIB/nmail.where
XLOOK=1
XCOMPRESS=1
Xcase $COMPRESS in
X"")
X	zcat=cat
X	;;
X*)
X	zcat=zcat
X	;;
Xesac
X
Xcase $1 in
X	-setup)
X		# Initial setup.  Should only need to be done once.
X		ls $UUCPSPOOL/[0-9]* > $MAPS/$UUCPMAP/Batch
X		exec $BIN/uuhosts -unbatch
X		exit 1
X	;;
X
X	-unbatch)
X		# Unbatch map articles batched by inews.  Called from cron.
X		cd $MAPS/$UUCPMAP
X		if [ -f Batch ]; then
X			:
X		else
X			exit 1
X		fi
X		mv Batch Batch.working
X		for f in `cat Batch.working`
X		do
X			$BIN/uuhosts -x < $f
X			sleep 60
X		done
X		rm Batch.working
X		exec $BIN/uuhosts -i
X		exit 1
X	;;
X
X	-x)
X		# extract a new map piece into a map directory
X		temphead=/tmp/maphead.$$
X		temptext=/tmp/maptext.$$
X		tempcomm=/tmp/mapcomm.$$
X		cp /dev/null $temphead
X		cp /dev/null $temptext
X		echo 'exec /bin/mail postmaster' > $tempcomm
X		echo 'Reply-To: postmaster' > $temphead
X		awk '
XBEGIN	{
X	temphead = "'$temphead'"; tempcomm = "'$tempcomm'";
X	isuucpmap = 1;	# Assume most postings are map entries.
X	shead = 0; stext = 1; suucp = 2;
X	state = shead;
X}
Xstate == shead && ($1 == "From:" || $1 == "Sender:" \
X    || $1 == "Date:" || $1 == "Message-ID:" || $1 == "Message-Id:") {
X	print "Original-" $0 >> temphead;
X	next;
X}
Xstate == shead && $1 == "Newsgroups:" {	# no cross-postings allowed
X 	if ($2 != "'$UUCPMAPGROUP'") {
X		isuucpmap = 0;
X 		print "Bad-Newsgroups: " $2 " (should be '"$UUCPMAPGROUP"')" \
X 			>> temphead;
X 		next;
X	}
X}
Xstate == shead && $1 == "Subject:" {
X	# the odd initial test is to avoid certain brain damaged awks
X	if ("X" ~ /X/ \
X	&& $2 !~ /^UUCP/ && $2 !~ /^uucp/ && $2 !~ /^Uucp/) {
X		print "Subject:  not a map update" >> temphead;
X		print "Original-" $0 >> temphead;
X		isuucpmap = 0;
X	} else
X		print $0 >> temphead;
X	next;
X}
Xstate == shead && /^$/	{
X	if (isuucpmap != 0) {
X	print "PATH=/bin; umask 0002; cd '$UUCPMAP'" | "'$MAPSH'";
X		state = suucp;
X	} else
X		state = stext;
X}
Xstate == shead {
X		print $0 >> temphead;
X}
Xstate == suucp	{
X	print | "'$MAPSH'";
X}
Xstate == stext	{
X	print;
X}
X' > $temptext 2>&1
X		cat $temphead $temptext | sh $tempcomm
X		rm -f $temphead $temptext $tempcomm
X		exit 0
X	;;
X
X	-compress)
X		case $COMPRESS in
X		"")
X			exit
X			;;
X		esac
X		cd $MAPS/$UUCPMAP
X		if [ -f README ]; then
X			compress -f README
X		fi
X		compress -f [a-z]*.*[a-z0-9]
X		exit 0
X	;;
X
X	-i)
X		# Create the Index used for fast lookups.
X		cd $MAPS/$UUCPMAP
X		$BIN/uuhosts -compress
X		for file in [a-z]*.*
X		do
X			f=`basename $file .Z`
X			$zcat $f |
X			sed -n -e "s/,/ /g" -e "/^#N/s/#N[	 ]*//p" |
X			awk 'BEGIN { filename = "'"$f"'" }
X			{
X				for (x=1; x<=NF; x++)
X					printf("%s\t%s\n", $x, filename);
X			}'
X		done | sort -f > Index.$$
X 		mv Index.$$ Index
X		if [ -f $LIB/uuwhere ]; then
X			$LIB/uuwhere
X		fi
X		exit 0
X	;;
X
X	-r)
X		# by region
X		cd $MAPS/$UUCPMAP
X		shift
X		case $# in
X		0)
X			exec ls
X			exit 1
X		;;
X		esac
X		case $COMPRESS in
X		"")
X			exec $pager $*
X			exit 1
X			;;
X		*)
X			zcat $* | $pager
X			exit 0
X			;;
X		esac
X		exit 1
X	;;
X
X	-u)
X		exec $BIN/uuhosts -r
X		exit 1
X	;;
X
X	-n)
X		exec $BIN/uuhosts -r
X		exit 1
X	;;
X
X	-k)
X		# by keyword
X		cd $MAPS/$UUCPMAP
X		shift
X		$zcat [a-z]*.* | awk '
XBEGIN		{ inside = 1; outside = 0; state = outside; }
X/^#N/ && state == inside	{
X	if (useit == 1) {
X		for (i = 0; i < count; i++) {
X			print block[i];
X		}
X	}
X	state = outside;
X}
X/^#N/	{ state = inside; count = 0; useit = 0; }
Xstate == inside	{ block[count++] = $0; }
X/'"$*"'/	{ useit = 1; }
XEND {
X	if (useit == 1) {
X		for (i = 0; i < count; i++) {
X			print block[i];
X		}
X	}
X}
X' | $pager
X		exit 0
X	;;
X
X	-*)
X		# unknown option
X	;;
X
X	"")
X		# no arguments
X	;;
X
X	*)
X		# by host name
X		case $LOOK in
X		"")
X			look=grep
X			lookopt="^"
X			;;
X		*)
X			look=look
X			lookopt="-f "
X			;;
X		esac
X		for arg in $*
X		do
X			echo "UUCP mail path from `uuname -l` to $arg:"
X			$look $lookopt$arg $PATHS
X# 			uupath $arg
X			case $WHERE in
X			"")
X				;;
X			*)
X			if [ -f $WHERE ]; then
X			echo "UUCP mail path for $arg annotated by location:"
X				$look $lookopt$arg $WHERE
X			fi
X				;;
X			esac
X			echo "
XUUCP mail information for host $arg (#USENET lines show USENET news links):"
X			cd $MAPS/$UUCPMAP
X# Find the Index entry for the host with look or sed.
X# Select the file name(s) with sed.
X# Uncompress the file and select the appropriate lines with sed.
X			case $look in
X			*look*)
X				files=`$look $lookopt$arg Index |
X				sed -n -e "/^$arg/s%.*	%%p"`
X				;;
X			*)
X				files=`
X				sed -n -e "/^$arg/s%.*	%%p" Index`
X				;;
X			esac
X			case $files in
X			"")
X				continue
X				;;
X			esac
X			$zcat $files | sed -n -e ":toss
X/#N.*[	 ]*$arg/bcopy
Xd
Xbtoss
X:copy
Xs/^#N/#Name		/
Xp
Xn
X:copy2
X/^#N/btoss
Xs/^#S/#System-CPU-OS	/
Xs/^#O/#Organization	/
Xs/^#C/#Contact	/
Xs/^#E/#Electronic-Address/
Xs/^#T/#Telephone	/
Xs/^#P/#Postal-Address	/
Xs/^#L/#Latitude-Longitude/
Xs/^#R/#Remarks	/
Xs/^#W/#Written-by	/
Xs/^#U/#USENET/
Xp
Xn
Xbcopy2"
X		done | $pager
X		exit 0
X	;;
Xesac
X
Xecho 'Usage:	uuhosts hostname ...
Xfor information about a particular UUCP or USENET host or hosts, or
X
X	uuhosts -r region
Xfor information about hosts in a region of the UUCP or USENET networks, or
X
X	uuhosts -r
Xfor a list of known regions.
X
XSee uuhosts(1) or "uuhosts -r README" for further details.
X'
Xexit 1
!RoNnIe!RaYgUn!
echo x - mapsh.c
sed -e 's/^X//' > mapsh.c << '!RoNnIe!RaYgUn!'
X#include <stdio.h>
X/*
X	This command depends on chroot(2), which exists in 4BSD, System V,
X	Version 7, and probably all related systems.
X */
X
X#ifndef MAPS
X#define MAPS "/usr/local/lib/news/maps"
X#endif
X
Xmain(argc,argv)
Xint argc;
Xchar **argv;
X{
X	char *rootdir = MAPS;
X	char *command = "/bin/sh";
X
X	if (geteuid() != 0) {
X		fprintf (stderr, "mapsh must be setuid to root\n");
X		exit(1);
X	}
X	if (chroot(rootdir) == -1) {
X		fprintf (stderr, "mapsh:  chroot(%s) failed\n", rootdir);
X		perror ("");
X		exit(1);
X	}
X	if (setuid(getuid()) == -1) {
X		perror ("mapsh:  setuid(getuid()) failed");
X		exit(1);
X	}
X	if (chdir("/") == -1) {
X		fprintf (stderr, "mapsh:  chdir(%s) failed\n", "/");
X		perror ("");
X		exit(1);
X	}
X	execvp (command, argv);
X	fprintf (stderr, "mapsh:  %s not found\n", command);
X	perror ("mapsh:  execvp(2) failed");
X	exit(1);
X}
!RoNnIe!RaYgUn!
echo x - uuwhere.c
sed -e 's/^X//' > uuwhere.c << '!RoNnIe!RaYgUn!'
X#ifndef lint
Xchar sccsid[] = "@(#) uuwhere.c 1.12 85/11/29";
X#endif
X/*
X * uuwhere:
X * This is a frill which may be called by uuhosts to annotate routing
X * information produced by pathalias(1L) with the location of each host.
X * It takes the ASCII UUCP routing database PATHS on standard input,
X * and produces the annnotated version on standard output, to be put
X * in WHERE.  It gets the location information from the UUCP map directory
X * produced by uuhosts from the map posted to the USENET newsgroup
X * mod.map.uucp by the UUCP Project.
X *
X * Uuwhere is usually called by uuhosts, and most of the time just
X * checks to see if WHERE needs to be updated.  Uuhosts itself
X * displays the annotated routing information to the user.
X *
X * The host location information is first put into a dbm(3x)
X * database so that generating the final output will not take forever.
X * If you don't have dbm, this won't work.
X */
X
X#include <stdio.h>
X#include <ctype.h>
X#include <dbm.h>
X#include <sys/types.h>
X#include <sys/stat.h>
X
X#ifndef UUCPINDEX
X#define UUCPINDEX "/usr/local/lib/news/maps/mod.map.uucp/Index"
X#endif
X#ifndef TMP
X#define TMP "/usr/local/lib/nmail.tmp"
X#endif
X#ifndef PATHS
X#define PATHS "/usr/local/lib/nmail.paths"
X#endif
X#ifndef WHERE
X#define WHERE "/usr/local/lib/nmail.where"
X#endif
X#ifndef DATABASE
X#define DATABASE	"/usr/local/lib/uuindex"
X#endif
X
Xstatic int verbose, flagcreat, flagupdate, flaginput;
X
Xmain(argc, argv)
Xint argc;
Xregister char **argv;
X{
X	register FILE *fin;
X	flagcreat = 0;
X	flagupdate = 1;
X	flaginput = 0;
X
X	(void) umask(0);
X	while (*++argv != NULL) {
X		if (**argv != '-') {
X			flaginput = 1;
X			flagupdate = 0;
X		} else
X		switch (argv[0][1]) {
X			case '\0':
X				flaginput = 1;
X				flagupdate = 0;
X				break;
X			case 'c':
X				flagcreat = 1;
X				flagupdate = 0;
X				break;
X			case 'v':
X				verbose = 1;
X				break;
X			default:
X				usage();
X				break;
X		}
X		if (flaginput)
X			break;
X	}
X	if (verbose) {
X		if (flagcreat)
X			fprintf(stderr, "Force creation of database %s.\n",
X				DATABASE);
X		if (flagupdate)
X			fprintf(stderr, "Attempt update of %s.\n",
X				WHERE);
X		if (flaginput)
X			fprintf(stderr, "Input files (%s ...) specified.\n",
X				*argv);
X	}
X	if (!flaginput) {
X		(void)fclose(stdout);
X		(void)fclose(stdin);
X	}
X	init(flagcreat, flagupdate, flaginput);
X	if (!flaginput) {
X		char tmpbuf[64];
X
X 		if ((fin = fopen(PATHS, "r")) == (FILE *)NULL) {
X			perror (PATHS);
X			exit (1);
X		}
X		(void)sprintf(tmpbuf, "%s.%d", TMP, getpid());
X		if (freopen(tmpbuf, "w", stdout) == (FILE *)NULL) {
X			perror (tmpbuf);
X			exit (1);
X		}
X		parsefile(fin, PATHS);
X		(void)fclose(stdout);
X		if (unlink (WHERE) == -1 || link(tmpbuf, WHERE) == -1) {
X			perror(WHERE);
X			exit(1);
X		}
X		(void)unlink(tmpbuf);
X		exit (0);
X	}
X	for (; *argv != NULL; argv++) {
X		if (strcmp (*argv, "-") == 0) {
X			parsefile(stdin, "stdin");
X			continue;
X		}
X		if ((fin = fopen(*argv, "r")) != (FILE *)NULL) {
X			parsefile(fin, *argv);
X			continue;
X		}
X		perror (*argv);
X	}
X	exit(0);
X}
X
Xusage()
X{
X	fprintf (stderr, "usage:  uuwhere [-c] [-v] [infiles]\n");
X	exit (1);
X}
X
Xinit(flagcreat, flagupdate, flaginput)
Xint flagcreat, flagupdate, flaginput;
X{
X	char datadir[512], datapag[512];
X	struct stat statuucp, statpaths, statwhere;
X	int fd;
X	char c;
X
X/*
X * If any of the stats fail,
X * an open will fail later and produce a diagnostic.
X */
X	if (flagupdate
X	&& stat(WHERE, &statwhere) != -1
X	&& stat(PATHS, &statpaths) != -1
X	&& stat(UUCPINDEX, &statuucp) != -1) {
X		if (statwhere.st_mtime > statpaths.st_mtime
X		&& statwhere.st_mtime > statuucp.st_mtime) {
X			if (verbose)
X				fprintf (stderr, "%s up to date\n", WHERE);
X			exit(0);
X		}
X		if (statuucp.st_mtime > statwhere.st_mtime
X		|| statuucp.st_mtime > statpaths.st_mtime)
X			flagcreat = 1;
X	}
X	if (!flaginput) {
X		/* touch WHERE to forestall duplicate uuwheres */
X		if ((fd = open(WHERE, 2)) < 0) {
X			perror(WHERE);
X			exit(1);
X		}
X		if (read (fd, &c, 1) == 1)
X			(void) write (fd, &c, 1);
X		(void) close (fd);
X	}
X	(void) sprintf (datadir, "%s.dir", DATABASE);
X	(void) sprintf (datapag, "%s.pag", DATABASE);
X	if (flagcreat || access(datadir, 0) == -1 || access(datapag, 0) == -1) {
X		flagcreat = 1;
X		if (verbose)
X			fprintf (stderr, "Creating database %s...\n", DATABASE);
X		if (makefile(datadir) == -1 || makefile(datapag) == -1)
X			exit(1);
X	}
X	if (dbminit(DATABASE) < 0)
X		exit(1);
X	if (!flagcreat)
X		return;
X	if (!initit(UUCPINDEX))
X		exit(1);
X	if (verbose)
X		fprintf (stderr, "...database %s created.\n", DATABASE);
X}
X
Xmakefile(name)
Xchar *name;
X{
X	register int fd;
X
X	if ((fd = creat(name, 0666)) == -1) {
X		perror(name);
X		return(-1);
X	}
X	(void) close(fd);
X	return (0);
X}
X
Xinitit(name)
Xchar *name;
X{
X	register FILE *fp;
X	char buffer[1024], site[128], where[128];
X	datum key, data;
X
X	if (verbose)
X		fprintf(stderr, "Reading %s...", name);
X	if ((fp = fopen(name, "r")) == (FILE *)NULL) {
X		perror(name);
X		return (0);
X	}
X 	while (fgets(buffer, sizeof(buffer), fp) != NULL) {
X		if (sscanf(buffer, "%s%s", site, where) != 2) {
X			fprintf (stderr, "Can't parse:  %s\n", buffer);
X			continue;
X		}
X		key.dptr = site;
X		key.dsize = strlen(key.dptr) + 1;
X		data.dptr = where;
X		data.dsize = strlen(data.dptr) + 1;
X		store (key, data);
X	}
X	(void)fclose(fp);
X	if (verbose)
X		fprintf(stderr, ".\n");
X	return(1);
X}
X
Xparsefile(fin, name)
Xregister FILE *fin;
Xchar *name;
X{
X	char buffer[128];
X	register char *cp;
X	register int c;
X	register int inside;
X	register int last = 0;
X
X	if (verbose)
X		fprintf(stderr, "%s\n", name);
X	for (inside = 0; (c = getc(fin)) != EOF; putchar(c)) {
X		if (isalnum(c) || c == '.' || c == '-' || c == '_') {
X			if (!inside) {
X				cp = buffer;
X				inside = 1;
X			}
X			*cp++ = c;
X			continue;
X		}
X		if (inside) {
X			*cp = '\0';
X			if (cp != buffer
X/* %s */	&& !((cp - buffer) == 1 && last == '%' && buffer[0] == 's'))
X				doit(buffer);
X			inside = 0;
X		}
X		last = c;
X	}
X}
X
Xdoit (site)
Xchar *site;
X{
X	datum key, data;
X
X	key.dptr = site;
X	key.dsize = strlen(key.dptr) + 1;
X	data = fetch(key);
X	if (data.dptr != NULL)
X		printf ("(%s)", data.dptr);
X}
!RoNnIe!RaYgUn!
echo x - uuhosts.man
sed -e 's/^X//' > uuhosts.man << '!RoNnIe!RaYgUn!'
X.TH UUHOSTS 1L 85/11/04
X.SH NAME
Xuuhosts \- UUCP mail and USENET news information.
X.SH SYNOPSIS
X.B
Xuuhosts
Xhostname ...
X.br
X.B
Xuuhosts
X-r [ region ]
X.SH DESCRIPTION
XThe \fIuuhosts\fP command is used to look up information about
Xthe configurations of the UUCP mail network and the USENET news network.
X.TP
Xuuhosts \fIhostname\fP ...
Xfor information about a particular UUCP or USENET host or hosts.
XThe UUCP mail path is given first, followed by the map information.
XThe USENET map is carried as notations in entries in the UUCP map,
Xin the lines starting with ``#USENET''.
XAny hosts with names for which the argument is a prefix are shown, e.g.:
X.TP
Xuuhosts ut
Xgets information about all hosts whose names start with ``ut''.
X.TP
Xuuhosts \-r \fIregion\fP
Xfor information about hosts in a (usually geographical) region.
X.TP
Xuuhosts \-r README
Xgets an introduction to the map.
X.TP
Xuuhosts \-r path.local
Xgets map information known only locally.
X.TP
Xuuhosts \-r
Xfor a list of known regions.
X.TP
Xuuhosts
Xwith no arguments gets a short usage message.
X.PP
XOutput is broken into pages by the program named in the PAGER environment
Xvariable, or by a default pager set at compile time,
Xwhich is usually one of more, pg, or cat,
Xas appropriate for the host system.
X.SH MAINTENANCE
XNone of these options should be used by the super-user (root).
X.TP
Xuuhosts \-setup
XOnce "make\ install" has been done for the initial installation,
Xthis option may be used to extract any backlog of \fBUUCPMAPGROUP\fP articles.
XDo not run it as root!
XRun it as some user in group news.
X.TP
Xmaps:UUCPMAPGROUP:F:UUCPMAP/Batch
XThis line should go in \fBNEWS/sys\fP.
XIt causes \fIinews\fP(1L) to list the pathnames of incoming articles of
X\fBUUCPMAPGROUP\fP in the \fBBatch\fP file.
X.TP
Xuuhosts \-unbatch
XThis should be called nightly by \fIcron\fP(8) or whatever mechanism is
Xused to call the USENET \fIexpire\fP(8) command.
XIt extracts articles from \fBUUCPMAPGROUP\fP which have
Xcome in since the last time it was run.
XDo not run it as root!
XRun it as some user in group news.
X.TP
Xuuhosts \-x
XExtract an individual \fBUUCPMAPGROUP\fP article.
XOrdinarily called from \fIuuhosts\fP\ \-\fBunbatch\fP.
X.TP
Xuuhosts \-i
XRebuild the Index file (see below).
XOrdinarily called from \fIuuhosts\fP\ \-\fBunbatch\fP.
X.SH FILES
X.TP
XPATHS
XUUCP mail path database as produced by \fIpathalias\fP and used by \fInmail\fP
X(which is called automatically from \fIsendmail\fP on \fIut\-sally\fP)
XIt is searched by \fIlook\fP(1), if present, else \fIgrep\fP(1).
XThe file WHERE is similarly searched, if present:
Xsee \fIuuwhere\fP(1).
X.TP
XUUCPMAP
XUUCP and USENET map information taken from newsgroup \fBUUCPMAPGROUP\fP
X(thanks to the UUCP mapping project).
XNotices of updates are mailed to \fBpostmaster\fP, which should be an alias
Xredistributing to the local mail and UUCP administrators.
X.TP
XUUCPMAP/Index
XThis index is used to decrease search time on the map about an order
Xof magnitude.
XThe search is done by either \fIlook\fP(1) or \fIgrep\fP(1), as above.
X.SH SEE ALSO
Xvnews(1), readnews(1), mail(1), sendmail(8), look(1)
!RoNnIe!RaYgUn!
echo x - uuwhere.man
sed -e 's/^X//' > uuwhere.man << '!RoNnIe!RaYgUn!'
X.TH UUW\HERE 1L 85/08/11
X.SH NAME
Xuuwhere \- annotate UUCP mail routes by host location
X.SH SYNOPSIS
X.B
XLIB/uuwhere
X[ -c ]
X[ infile ]
X.SH DESCRIPTION
XThe \fIuuwhere\fP command is used take a list of UUCP routes,
Xsuch as produced by \fIpathalias\fP, and make a similar list,
Xannotated by the geographical location of each host as found
Xin the UUCP map posted to USENET newsgroup mod.map.uucp.
XIt is ordinarily called with no arguments by \fIuuhosts\fP(1L),
Xand will update \fBWHERE\fP, taking routes from \fBPATHS\fP and locations
Xfrom \fBUUCPMAP/Index\fP, if either
X\fBPATHS\fP or \fBUUCPMAP/Index\fP is newer than \fBWHERE\fP.
XThe information in \fBWHERE\fP is displayed by \fIuuhosts\fP itself.
X.PP
XInput file names may be specified as arguments.
XThis also causes output to go to standard output instead of directly to
XInput file name \fI-\fP is taken to be standard input.
X\fBWHERE\fP.
X.TP
X\-\fBc
X\fIUuwhere\fP uses a \fIdbm\fP(3) database to store the location information
Xfrom \fBUUCPMAP/Index\fP before creating output.
XThis option causes \fIuuwhere\fP to recreate the database regardless
Xof the state of any input files.
X.SH FILES
X.TP
XWHERE
XThe place where the output of \fIuuwhere\fP is usually kept for use
Xby \fIuuhosts\fP.
X.TP
XPATHS
XThe default route list used as input by \fIuuwhere\fP.
XProduced by \fIuuhosts\fP.
X.TP
XUUCPMAP/Index
XThe source of the location information used by \fIuuwhere\fP.
XProduced by \fIpathalias\fP.
X.SH SEE ALSO
Xuuhosts(1), pathalias(1), dbm(3).
!RoNnIe!RaYgUn!
echo x - maps.ls
sed -e 's/^X//' > maps.ls << '!RoNnIe!RaYgUn!'
X/usr/spool/news/maps:
Xtotal 9
Xdr-xr-xr-x  5 root     news          512 Sep 17 09:10 .
Xdrwxrwxrwx 20 news     news         1024 Jan  6 10:06 ..
Xdr-xr-xr-x  2 root     news          512 Aug 10 11:07 bin
Xdrwxrwxr-x  2 root     news         4608 Jan  4 09:57 mod.map
Xdrwxrwxrwx  2 root     news         1024 Dec  6 18:12 tmp
X/usr/spool/news/maps/bin:
Xtotal 75
Xdr-xr-xr-x  2 root     news          512 Aug 10 11:07 .
Xdr-xr-xr-x  5 root     news          512 Sep 17 09:10 ..
X-r-xr-xr-x  1 root     news        16384 Jan  2 12:20 cat
X-r-xr-xr-x  1 root     news         8192 Jan  2 12:20 echo
X-r-xr-xr-x  1 root     news        23552 Jan  2 12:20 sed
X-r-xr-xr-x  1 root     news        26624 Jan  2 12:20 sh
!RoNnIe!RaYgUn!
echo x - Makefile
sed -e 's/^X//' > Makefile << '!RoNnIe!RaYgUn!'
X# @(#) Makefile 1.33 85/12/09
XSHELL=/bin/sh
X
X# Settable parameters.
X
X# Default pager for use if PAGER environment variable is not set.
XDEFPAGER=more	# BSD systems
X#DEFPAGER=pg	# AT&T systems
X#DEFPAGER=cat	# systems with paging in the kernel
X# Set this if you have look(1).
XLOOK=1
X# Set this to compress the map files.
XCOMPRESS=yes
X#COMPRESS=
X
X# BIN should be either /usr/local or /usr/local/bin
XBIN=/usr/local
XLIB=/usr/local/lib
X
X# Routing information produced by pathalias.
XPATHS=$(LIB)/nmail.paths
X
X# If you do not have dbm(3), i.e., -ldbm, set UUWHERE to nothing.
XUUWHERE=uuwhere
X# UUWHERE=
X# Munged by uuwhere for location information.
XWHERE=$(LIB)/nmail.where
X# TMP should be in the same directory as WHERE.
XTMP=$(LIB)/nmail.tmp
X# -ldbm DATABASE used by uuwhere.
XDATABASE=$(LIB)/uuindex
X
X# Most of the news parameter files and mapsh are in this directory.
XNEWS=$(LIB)/news
X# The maps from mod.map are under this directory.
XMAPS=/usr/spool/news/maps
X#MAPS=$(NEWS)/maps	# another possibility
X
X# The filename of the manual entry.
XUUHOSTSMAN=uuhosts.1
XUUWHEREMAN=uuwhere.1
XMAN=$(UUHOSTSMAN) $(UUWHEREMAN)
XMANSOURCES=uuhosts.man uuwhere.man
X# The manual directory for local entries.
XMANDIR=/usr/man/manl
X
X# This is a very local UT hack which is meaningless on your system.
XRUUHOSTS=uuhosts.CS.UTEXAS.EDU
X
X# The rest of the Makefile shouldn't need to be changed.
X
XUUCPMAPGROUP=mod.map
X# This can't be the same as UUCPMAPGROUP
XOLDUUCPMAPGROUP=mod.map.uucp
X# USENET spool directory containing articles from newsgroup $(UUCPMAPGROUP).
X# Must match $(UUCPMAPGROUP)!
XUUCPSPOOL=/usr/spool/news/mod/map
X# The place uuhosts stores the $(UUCPMAPGROUP) information for later retrieval.
XUUCPMAP=$(MAPS)/$(UUCPMAPGROUP)
X
XSOURCES=uuhosts.sh mapsh.c uuwhere.c $(MANSOURCES) maps.ls
XALL= uuhosts mapsh $(UUWHERE) $(MAN)
X
Xall: $(ALL)
X
Xuuhosts: Makefile uuhosts.sh
X	sed -e '/^DEFPAGER=/s%=.*%=$(DEFPAGER)%' \
X		-e '/^LOOK=/s%=.*%=$(LOOK)%' \
X		-e '/^COMPRESS=/s%=.*%=$(COMPRESS)%' \
X		-e '/^RUUHOSTS=/s%=.*%=$(RUUHOSTS)%' \
X		-e '/^UUCPMAPGROUP=/s%=.*%=$(UUCPMAPGROUP)%' \
X		-e '/^UUCPSPOOL=/s%=.*%=$(UUCPSPOOL)%' \
X		-e '/^BIN=/s%=.*%=$(BIN)%' \
X		-e '/^LIB=/s%=.*%=$(LIB)%' \
X		-e '/^PATHS=/s%=.*%=$(PATHS)%' \
X		-e '/^WHERE=/s%=.*%=$(WHERE)%'\
X		-e '/^NEWS=/s%=.*%=$(NEWS)%' \
X		-e '/^MAPS=/s%=.*%=$(MAPS)%'\
X		uuhosts.sh > uuhosts
X	chmod +x uuhosts
X
Xmapsh: Makefile mapsh.c
X	$(CC) -o mapsh -DMAPS=\"$(MAPS)\" mapsh.c
X
Xuuwhere: Makefile uuwhere.c
X	$(CC) -DUUCPINDEX=\"$(UUCPMAP)/Index\" \
X		-DPATHS=\"$(PATHS)\" \
X		-DWHERE=\"$(WHERE)\" \
X		-DTMP=\"$(TMP)\" \
X		-DDATABASE=\"$(DATABASE)\" \
X		uuwhere.c -ldbm -o uuwhere
X
Xwhere:	$(LIB)/uuwhere
X
X$(UUHOSTSMAN):	Makefile uuhosts.man
X	sed -e 's%UUCPMAPGROUP%$(UUCPMAPGROUP)%' \
X		-e 's%UUCPMAP%$(UUCPMAP)%' \
X		-e 's%DEFPAGER%$(DEFPAGER)%' \
X		-e 's%BIN%$(BIN)%' \
X		-e 's%LIB%$(LIB)%' \
X		-e 's%PATHS%$(PATHS)%' \
X		-e 's%WHERE%$(WHERE)%' \
X		-e 's%TMP%$(TMP)%' \
X		-e 's%DATABASE%$(DATABASE)%' \
X		-e 's%NEWS%$(NEWS)%' \
X		-e 's%MAPS%$(MAPS)%'\
X		uuhosts.man > $(UUHOSTSMAN)
X
X$(UUWHEREMAN):	Makefile uuwhere.man
X	sed -e 's%UUCPMAP%$(UUCPMAP)%' \
X		-e 's%BIN%$(BIN)%' \
X		-e 's%LIB%$(LIB)%' \
X		-e 's%PATHS%$(PATHS)%' \
X		-e 's%WHERE%$(WHERE)%' \
X		-e 's%TMP%$(TMP)%' \
X		-e 's%DATABASE%$(DATABASE)%' \
X		-e 's%NEWS%$(NEWS)%' \
X		-e 's%MAPS%$(MAPS)%'\
X		uuwhere.man > $(UUWHEREMAN)
X
Xinst_:
X
Xinst_uuwhere: $(UUWHERE)
X	-rm -f $(LIB)/uuwhere
X	cp uuwhere $(LIB)/uuwhere
X	chmod 555 $(LIB)/uuwhere
X	cp /dev/null $(WHERE)
X	-chmod 666 $(WHERE)
X	-rm -f $(MANDIR)/$(UUWHEREMAN)
X	-cp $(UUWHEREMAN) $(MANDIR)
X	-chmod 444 $(MANDIR)/$(UUWHEREMAN)
X
Xinstall: $(ALL) inst_$(UUWHERE) inst_most $(UUCPMAP)/path.local recover
X
Xinst_most:
X	-rm -f $(BIN)/uuhosts
X	cp uuhosts $(BIN)/uuhosts
X	chmod 555 $(BIN)/uuhosts
X	-rm -f $(MANDIR)/$(UUHOSTSMAN)
X	-cp $(UUHOSTSMAN) $(MANDIR)
X	-chmod 444 $(MANDIR)/$(UUHOSTSMAN)
X	@echo "Rest of installation has to be done as root."
X	cp mapsh $(NEWS)/mapsh
X	-strip $(NEWS)/mapsh
X	chown root $(NEWS)/mapsh
X	chgrp news $(NEWS)/mapsh
X	chmod 4750 $(NEWS)/mapsh
X	ls -lg $(NEWS)/mapsh
X	-mkdir $(MAPS)
X	-mkdir $(MAPS)/bin $(MAPS)/tmp $(UUCPMAP)
X	chgrp news $(MAPS) $(MAPS)/*
X	chmod 555 $(MAPS)
X	chmod 775 $(UUCPMAP)
X	chmod 777 $(MAPS)/tmp
X	chmod 555 $(MAPS)/bin
X	cp /bin/cat $(MAPS)/bin
X	cp /bin/echo $(MAPS)/bin
X	cp /bin/sed $(MAPS)/bin
X	cp /bin/sh $(MAPS)/bin
X	-strip $(MAPS)/bin/*
X	chgrp news $(MAPS)/bin/*
X	chmod 555 $(MAPS)/bin/*
X	@echo ''
X	@echo 'This is what the things just installed *should* look like:'
X	@cat maps.ls
X	@echo ''
X	@echo 'And here is what they actually *do* look like:'
X	ls -lga $(MAPS)
X	ls -lga $(MAPS)/bin
X	@echo ''
X
Xmaps.ls: Makefile uuhosts
X	rsh im4u echo $(MAPS): ';' ls -lga $(MAPS) ';' \
X		echo $(MAPS)/bin: ';' ls -lga $(MAPS)/bin \
X		< /dev/null > maps.ls
X
X$(UUCPMAP)/path.local:
X	-cd $(UUCPMAP); umask 002; \
X		cp /dev/null path.local; chgrp news path.local; \
X		cp Local path.local
X	@echo 'See "uuhosts -r README" about path.local.'
X
Xrecover:
X	@echo "Attempt to recover map data from a previous newsgroup ("$(OLDUUCPMAPGROUP)")."
X	@echo "If it fails, you probably don't have any old map data."
X	mkdir /tmp/$(OLDUUCPMAPGROUP)
X	-cd /tmp/$(OLDUUCPMAPGROUP); cd $(MAPS)/$(OLDUUCPMAPGROUP); \
X		mv * ../$(UUCPMAPGROUP); cd ..;  rmdir $(OLDUUCPMAPGROUP)
X	rmdir /tmp/$(OLDUUCPMAPGROUP)
X
Xclean:
X	rm -f $(ALL)
X	rm -f *.pag *.dir
X	rm -f *.o
X	rm -f *.shar
X
Xshar: uuhosts.shar
X
Xuuhosts.shar: README $(SOURCES) Makefile
X	shar README* $(SOURCES) Makefile > uuhosts.shar
!RoNnIe!RaYgUn!
exit

bba@mtuxo.UUCP (XMRJ4-B.BANERJEE) (02/19/88)

This version of uuhosts blows up when trying to automatically extract
maps on our system (An Amdahl running Unix V.2).  The difference seems
to be with the versions of awk.  What follows is a patch to fix it (should
you have the same problem).

-- Binayak

*** OLDuuhosts.sh	Thu Feb 18 13:25:51 1988
--- uuhosts.sh	Fri Nov 13 19:37:34 1987
***************
*** 70,75
  		temphead=/tmp/maphead.$$
  		temptext=/tmp/maptext.$$
  		tempcomm=/tmp/mapcomm.$$
  		cp /dev/null $temphead
  		cp /dev/null $temptext
  		echo 'exec /bin/mail postmaster' > $tempcomm

--- 70,76 -----
  		temphead=/tmp/maphead.$$
  		temptext=/tmp/maptext.$$
  		tempcomm=/tmp/mapcomm.$$
+ 		tempmaph=/tmp/mapsh.$$
  		cp /dev/null $temphead
  		cp /dev/null $temptext
  		cp /dev/null $tempmaph
***************
*** 72,77
  		tempcomm=/tmp/mapcomm.$$
  		cp /dev/null $temphead
  		cp /dev/null $temptext
  		echo 'exec /bin/mail postmaster' > $tempcomm
  		echo 'Reply-To: postmaster' > $temphead
  		awk '

--- 73,79 -----
  		tempmaph=/tmp/mapsh.$$
  		cp /dev/null $temphead
  		cp /dev/null $temptext
+ 		cp /dev/null $tempmaph
  		echo 'exec /bin/mail postmaster' > $tempcomm
  		echo 'Reply-To: postmaster' > $temphead
  		awk '
***************
*** 77,82
  		awk '
  BEGIN	{
  	temphead = "'$temphead'"; tempcomm = "'$tempcomm'";
  	isuucpmap = 1;	# Assume most postings are map entries.
  	shead = 0; stext = 1; suucp = 2;
  	state = shead;

--- 79,85 -----
  		awk '
  BEGIN	{
  	temphead = "'$temphead'"; tempcomm = "'$tempcomm'";
+ 	tempmaph = "'$tempmaph'";
  	isuucpmap = 1;	# Assume most postings are map entries.
  	shead = 0; stext = 1; suucp = 2;
  	state = shead;
***************
*** 107,113
  }
  state == shead && /^$/	{
  	if (isuucpmap != 0) {
! 	print "PATH=/bin; umask 0002; cd '$UUCPMAP'" | "'$MAPSH'";
  		state = suucp;
  	} else
  		state = stext;

--- 110,116 -----
  }
  state == shead && /^$/	{
  	if (isuucpmap != 0) {
! 	print "PATH=/bin; umask 0002; cd '$UUCPMAP'" >> tempmaph ;
  		state = suucp;
  	} else
  		state = stext;
***************
*** 116,122
  		print $0 >> temphead;
  }
  state == suucp	{
! 	print | "'$MAPSH'";
  }
  state == stext	{
  	print;

--- 119,125 -----
  		print $0 >> temphead;
  }
  state == suucp	{
! 	print >> tempmaph ;
  }
  state == stext	{
  	print;
***************
*** 122,127
  	print;
  }
  ' > $temptext 2>&1
  		cat $temphead $temptext | sh $tempcomm
  		rm -f $temphead $temptext $tempcomm
  		exit 0

--- 125,131 -----
  	print;
  }
  ' > $temptext 2>&1
+ 		$MAPSH < $tempmaph >> $temptext 2>&1
  		cat $temphead $temptext | sh $tempcomm
  		rm -f $temphead $temptext $tempcomm $tempmaph
  		exit 0
***************
*** 123,129
  }
  ' > $temptext 2>&1
  		cat $temphead $temptext | sh $tempcomm
! 		rm -f $temphead $temptext $tempcomm
  		exit 0
  	;;
  

--- 127,133 -----
  ' > $temptext 2>&1
  		$MAPSH < $tempmaph >> $temptext 2>&1
  		cat $temphead $temptext | sh $tempcomm
! 		rm -f $temphead $temptext $tempcomm $tempmaph
  		exit 0
  	;;