uuhosts: extract and display mod.map.all
Bill's area
bill at caribou.UUCP
Wed Dec 26 23:17:45 AEST 1984
>
> : This is a shar archive. Extract with sh, not csh.
> echo x - README
> sed -e 's/^X//' > README << '!Funky!Stuff!'
> XThis is the source directory for uuhosts, which may be used to
> Xautomatically collect map information from mod.map.all and also
> Xto display it to the users.
> X
> XUnlike the version I posted some time back, this one doesn't have
> Xsecurity problems with extracting things from mod.map.all, and it
> Xcan also display UUCP mail paths and USENET map entries faster.
> !Funky!Stuff!
> echo x - Makefile
> sed -e 's/^X//' > Makefile << '!Funky!Stuff!'
> XSHELL=/bin/sh
> X
> X# nmail.paths is found in this directory
> XLIB=/usr/local/lib
> X# Most of the news parameter files and mapsh are in this directory.
> XNEWS=$(LIB)/news
> X# The maps from mod.map.all are under this directory.
> XMAPS=$(NEWS)/maps
> X
> XSOURCES=uuhosts.sh mapsh.c uucp.from.news.sh
> XALL=uuhosts mapsh uucp.from.news
> X
> Xall: $(ALL)
> X
> Xuuhosts: uuhosts.sh
> X sed -e \
> X's%^LIB=.*$$%LIB=$(LIB)%;s%^NEWS=.*$$%NEWS=$(NEWS)%;s%^MAPS=.*$$%MAPS=$(MAPS)%'\
> X uuhosts.sh > uuhosts
> X
> Xmapsh: mapsh.c
> X $(CC) -o mapsh -DMAPS=\"$(MAPS)\" mapsh.c
> X
> Xuucp.from.news: uucp.from.news.sh
> X sed -e \
> X's%^LIB=.*$$%LIB=$(LIB)%;s%^NEWS=.*$$%NEWS=$(NEWS)%;s%^MAPS=.*$$%MAPS=$(MAPS)%'\
> X uucp.from.news.sh > uucp.from.news
> X
> Xinstall: mapsh
> X cp uuhosts /usr/local/uuhosts
> X rm $(NEWS)/mapsh
> X cp mapsh $(NEWS)/mapsh
> X strip $(NEWS)/mapsh
> X chown root $(NEWS)/mapsh
> X chgrp news $(NEWS)/mapsh
> X chmod 4550 $(NEWS)/mapsh
> X ls -lg $(NEWS)/mapsh
> X
> Xclean:
> X rm -f $(ALL)
> X rm -f *.o
> X rm -f *.shar
> X
> Xshar:
> X shar README Makefile $(SOURCES) > uuhosts.shar
> !Funky!Stuff!
> echo x - uuhosts.sh
> sed -e 's/^X//' > uuhosts.sh << '!Funky!Stuff!'
> X#!/bin/sh
> X# '@(#) uuhosts.sh 1.39 84/12/15'
> X
> X# PATH will have to be adjusted for non-BSD systems.
> XPATH=/usr/local:/usr/ucb:/bin:/usr/bin
> XLIB=/usr/local/lib
> XNEWS=$LIB/news
> XMAPS=$NEWS/maps
> XNEWSMAPGROUP=mod.map.news
> XUUCPMAPGROUP=mod.map.uucp
> XNEWSMAP=$NEWSMAPGROUP
> XUUCPMAP=$UUCPMAPGROUP
> XMAPSH=$NEWS/mapsh
> X
> X# Routing information produced by pathalias.
> Xpaths=$LIB/nmail.paths
> X
> X# The directories $MAPS/$NEWSMAP and $MAPS/$UUCPMAP contain the map information
> X# extracted from the newsgroups mod.map.news (for the USENET news map)
> X# and mod.map.uucp (for the UUCP mail map). The extraction is done by
> X# a line in $NEWS/sys like this:
> X
> X# maps:mod.map.news,mod.map.mail:B:/usr/local/uuhosts -x
> X
> X# Locally-known USENET news map information should go in $MAPS/$NEWSMAP/Local.
> X
> X# $MAPSH is needed, to use the chroot(2) system call to limit
> X# what can be done when executing a shell with a news article as input.
> X# $MAPS, $MAPS/bin and $MAPS/bin/* must be unwritable by anyone:
> X
> X# $MAPS: total 16
> X# dr-xr-xr-x 6 root news 512 Nov 11 16:42 .
> X# drwxrwxr-x 19 news news 1024 Nov 11 16:45 ..
> X# dr-xr-xr-x 2 root news 512 Nov 11 16:39 bin
> X# drwxrwxr-x 2 news news 2048 Nov 11 16:42 mod.map.news
> X# drwxrwxr-x 2 news news 10240 Nov 11 16:39 mod.map.uucp
> X# drwxrwxrwx 2 news news 24 Nov 11 16:41 tmp
> X
> X# $MAPS/bin: total 59
> X# -r-xr-xr-x 1 root news 10240 Nov 11 15:29 cat
> X# -r-xr-xr-x 1 root news 4096 Nov 11 16:33 echo
> X# -r-xr-xr-x 1 root news 18432 Nov 11 15:29 sed
> X# -r-xr-xr-x 1 root news 27648 Nov 11 15:29 sh
> X
> X# Update notices are mailed to postmaster (for UUCP) and usenet (for news),
> X# which should be aliases which redistribute to the local mail and news
> X# (respectively) administrators.
> X
> Xcd $NEWS
> X
> Xcase $1 in
> 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 usenet' > $tempcomm
> X awk '
> XBEGIN {
> X temphead = "'$temphead'"; tempcomm = "'$tempcomm'";
> X typeset = 0; isnewsmap = 0; isuucpmap = 0;
> X shead = 0; stext = 1; snews = 2; suucp = 3;
> 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 == "'$NEWSMAPGROUP'") {
> X isnewsmap = 1;
> X typeset = 1;
> X print "Reply-To: usenet" >> temphead;
> X print "exec /bin/mail usenet" > tempcomm;
> X } else if ($2 == "'$UUCPMAPGROUP'") {
> X isuucpmap = 1;
> X typeset = 1;
> X print "Reply-To: postmaster" >> temphead;
> X print "exec /bin/mail postmaster" > tempcomm;
> X }
> X}
> Xstate == shead && $1 == "Subject:" {
> X if ($1 == "Re:" || $1 == "RE:" || $1 == "re:"\
> X || !typeset) { # this requires Newsgroups: before Subject:
> X print "Subject: not a map update" >> temphead;
> X print "Original-" $0 >> temphead;
> X } else
> X print $0 >> temphead;
> X next;
> X}
> Xstate == shead && /^$/ {
> X if (isnewsmap != 0) {
> X print "cd '$NEWSMAP'" | "uuhosts -n";
> X state = snews;
> X } else if (isuucpmap != 0) {
> X print "cd '$UUCPMAP'" | "uuhosts -u";
> X state = suucp;
> X } else
> X state = stext;
> X}
> Xstate == shead {
> X print $0 >> temphead;
> X}
> Xstate == snews {
> X print | "uuhosts -n";
> X}
> Xstate == suucp {
> X print | "uuhosts -u";
> 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 -u)
> X # extract a UUCP map piece
> X $MAPSH
> X cd $MAPS/$UUCPMAP
> X for f in *.a *.ar
> X do
> X ar xv $f
> X rm $f
> X done
> X exit 0
> X ;;
> X
> X -n)
> X # extract a USENET map piece
> X $MAPSH
> X exec uuhosts -i
> X exit 0
> X ;;
> X
> X -i)
> X # make an index for the USENET map
> X cd $MAPS/$NEWSMAP
> X awk '$1 == "Name:" {
> X printf ("%s\t%s\n", $2, FILENAME);
> X }' Local [a-z]* | sort -f > Index.$$
> X mv Index.$$ Index
> X exit 0
> X ;;
> X
> X -g)
> X # by geographical region
> X cd $MAPS/$NEWSMAP
> X shift
> X if test $# -eq 0
> X then
> X exec ls
> X exit 1
> X fi
> X exec cat $*
> X exit 1
> X ;;
> X
> X -k)
> X # by keyword
> X cd $MAPS/$NEWSMAP
> X shift
> X exec awk '
> XBEGIN { inside = 1; outside = 0; state = outside; }
> X/^Name:/ { state = inside; count = 0; useit = 0; }
> Xstate == inside { block[count++] = $0; }
> X/'"$*"'/ { useit = 1; }
> X/^$/ && state == inside {
> X if (useit == 1) {
> X for (i = 0; i < count; i++) {
> X print block[i];
> X }
> X }
> X state = outside;
> X}
> X' *
> X exit 1
> X ;;
> X
> X -*)
> X # unknown option
> X ;;
> X
> X "")
> X # no arguments
> X ;;
> X
> X *)
> X # by site name
> X if [ -x /usr/bin/look ]; then
> X look=/usr/bin/look
> X lookopt="-f "
> X else
> X look=grep
> X lookopt="^"
> X fi
> X for arg in $*
> X do
> X echo 'UUCP mail path:'
> X $look $lookopt$arg $paths
> X echo '
> XUUCP mail host information:'
> X cd $MAPS/$UUCPMAP
> X sed -e '
> Xs/^#N/#Name /
> 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 /' ${arg}*
> X cd $MAPS/$NEWSMAP
> X echo '
> XUSENET news host information:'
> X sed -n -e "/^Name:[ ]*${arg}/,/^$/p" \
> X `$look $lookopt$arg Index | awk '{print $2}'`
> X done
> 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' -g geographical-region
> Xfor information about USENET news sites in a geographical region, or
> X
> X 'uuhosts' -g
> Xfor a list of known USENET geographical-regions.
> X
> XSee uuhosts(1) for further details and more obscure options.
> X'
> Xexit 1
> !Funky!Stuff!
> echo x - mapsh.c
> sed -e 's/^X//' > mapsh.c << '!Funky!Stuff!'
> X#include <stdio.h>
> 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}
> !Funky!Stuff!
> echo x - uucp.from.news.sh
> sed -e 's/^X//' > uucp.from.news.sh << '!Funky!Stuff!'
> X#!/bin/sh
> X#
> X# This command, uucp.from.news, is a stopgap measure for use until
> X# the UUCP map is complete. It extracts mail information from the
> X# USENET news map and uses it to fill in gaps in the UUCP mail map.
> X#
> X# It should be called from the news map directory, $MAPS/$NEWSMAP,
> X# with a list of news map files as arguments, i.e.:
> X# cd $MAPS/$NEWSMAP
> X# uucp.from.news *
> X# It looks through the news map entries for ones with mail information,
> X# extracts those into individual files in $DIR by host name, and later
> X# copies all those for which there are not already host entries in
> X# the mail map directory to the mail map directory, $MAPS/UUCPMAP.
> X# The new mail map files all have '-' appended so they can be easily
> X# distinguished. If uucp.from.news is run again, such
> X# $MAPS/UUCPMAP/*- entries will be overwritten.
> X#
> X# The temporary directory $DIR is removed after the command is done.
> X#
> XPATH=/usr/local:/usr/ucb:/bin:/usr/bin
> Xumask 0002
> X
> XLIB=/usr/local/lib
> XNEWS=$LIB/news
> XMAPS=$NEWS/maps
> XNEWSMAPGROUP=mod.map.news
> XUUCPMAPGROUP=mod.map.uucp
> XNEWSMAP=$NEWSMAPGROUP
> XUUCPMAP=$UUCPMAPGROUP
> X
> XDIR=uucptmp
> Xmkdir $DIR
> X
> Xawk '
> XBEGIN {
> X sbetween = 0; sinside = 1; state = sbetween;
> X Date = "'"`date`"'";
> X split (Date, date, " ");
> X Mark = "uucp.from.news " date[3] " " date[2] " " date[6];
> X dir = "'$DIR'";
> X}
> Xstate == sbetween && $1 == "Name:" {
> X state = sinside;
> X last = "";
> X Name = "";
> X System = "";
> X Organization = "";
> X Contact = "";
> X Telephone = "";
> X Postal = "";
> X Address = "";
> X News = "";
> X Mail = "";
> X Latlong = "";
> X Remarks = "";
> X Written = "";
> X Comments = "";
> X}
> Xstate != sinside {
> X next;
> X}
> X# { print $0; }
> X$1 == "Name:" { Name = $2; next; }
> X$1 == "Organization:" {
> X Organization = $2;
> X for (x = 3; x <= NF; x++)
> X Organization = Organization " " $x;
> X last = $1;
> X next;
> X}
> X$1 == "Contact:" {
> X Contact = $2;
> X for (x = 3; x <= NF; x++)
> X Contact = Contact " " $x;
> X last = $1;
> X next;
> X}
> X$1 == "Phone:" {
> X Telephone = $2;
> X for (x = 3; x <= NF; x++)
> X Telephone = Telephone " " $x;
> X last = $1;
> X next;
> X}
> X$1 == "Postal-Address:" {
> X Postal = $2;
> X for (x = 3; x <= NF; x++)
> X Postal = Postal " " $x;
> X last = $1;
> X next;
> X}
> X$1 == "Electronic-Address:" {
> X Address = $2;
> X for (x = 3; x <= NF; x++)
> X Address = Address " " $x;
> X last = $1;
> X next;
> X}
> X$1 == "News:" {
> X News = $2;
> X for (x = 3; x <= NF; x++)
> X News = News " " $x;
> X last = $1;
> X next;
> X}
> X/^ / && last == "News:" {
> X for (x = 2; x <= NF; x++)
> X News = News " " $x;
> X next;
> X}
> X$1 == "Mail:" {
> X Mail = $2;
> X for (x = 3; x <= NF; x++)
> X Mail = Mail " " $x;
> X last = $1;
> X next;
> X}
> X/^ / && last == "Mail:" {
> X for (x = 1; x <= NF; x++)
> X Mail = Mail " " $x;
> X next;
> X}
> X$1 == "Comments:" {
> X last = $1;
> X if ($2 == "last" && $3 == "edited") {
> X Written = $4;
> X for (x = 5; x <= NF; x++)
> X Written = Written " " $x;
> X next;
> X }
> X Comments = $2;
> X for (x = 3; x <= NF; x++)
> X Comments = Comments " " $x;
> X next;
> X}
> X/^$/ {
> X state = sbetween;
> X if (Mail == "")
> X next;
> X output = dir "/" Name;
> X printf ("echo x - %s\n", output);
> X printf ("cat > %s << '\''End-of-%s'\''\n", output, output);
> X printf ("#N\t%s\n", Name);
> X printf ("#S\t%s\n", System);
> X printf ("#O\t%s\n", Organization);
> X printf ("#C\t%s\n", Contact);
> X printf ("#E\t%s\n", Address);
> X printf ("#T\t%s\n", Telephone);
> X printf ("#P\t%s\n", Postal);
> X printf ("#L\t%s\n", Latlong);
> X printf ("#R\t%s\n", Mark);
> X# split (News, news, "");
> X# printf ("#R\tNews: %s", news[1]);
> X# for (x = 2; news[x] != ""; x++) {
> X# if ((x % 8) == 0)
> X# printf ("\n\t");
> X# else
> X# printf (", ");
> X# printf ("%s", news[x]);
> X# }
> X# printf ("\n");
> X printf ("#W\t%s\n", Written);
> X printf ("#\n");
> X split (Mail, mail, " ");
> X printf ("%s\t%s", Name, mail[1]);
> X for (x = 2; mail[x] != ""; x++) {
> X if ((x % 8) == 0)
> X printf ("\n\t");
> X else
> X printf (", ");
> X printf ("%s", mail[x]);
> X }
> X printf ("\n");
> X if (Comments != "") {
> X printf ("#\n");
> X printf ("#%s\n", Comments);
> X }
> X printf ("\n");
> X printf ("End-of-%s\n", output);
> X next;
> X}
> X' $* | sh
> X
> Xcd $DIR
> Xfor f in *
> Xdo
> X there=$MAPS/$UUCPMAP/$f
> X if [ -r ${there} ]; then
> X echo ${there}
> X continue
> X fi
> X if [ -r ${there}. ]; then
> X echo ${there}.
> X continue
> X fi
> X if [ -r ${there}% ]; then
> X echo ${there}%
> X continue
> X fi
> X# if [ -r ${there}- ]; then
> X# echo ${there}-
> X# continue
> X# fi
> X echo new ${there}-
> X mv $f ${there}-
> Xdone
> Xcd ..
> Xrm -rf $DIR
> !Funky!Stuff!
> exit
> --
>
> John Quarterman, CS Dept., University of Texas, Austin, Texas 78712 USA
> jsq at ut-sally.ARPA, jsq at ut-sally.UUCP, {ihnp4,seismo,ctvax}!ut-sally!jsq
*** REPLACE THIS LINE WITH YOUR MESSAGE ***
More information about the Comp.sources.unix
mailing list