home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume3 / uuhosts2 < prev    next >
Internet Message Format  |  1986-11-30  |  27KB

  1. From: genrad!ihnp4!ut-sally!im4u!jsq@tzec.UTEXAS.EDU (John Quarterman)
  2. Subject: newer uuhosts (too many changes for diff listings)
  3. Newsgroups: mod.sources
  4. Approved: jpn@panda.UUCP
  5.  
  6. Mod.sources:  Volume 3, Issue 11
  7. Submitted by: ihnp4!ut-sally!im4u!jsq@tzec.UTEXAS.EDU (John Quarterman)
  8.  
  9. : This is a shar archive.  Extract with sh, not csh.
  10. echo x - README
  11. sed -e 's/^X//' > README << '!RoNnIe!RaYgUn!'
  12. XThis is the source directory for uuhosts, which may be used to display
  13. XUUCP mail and USENET news information previously extracted from the
  14. XUSENET newsgroup mod.map.uucp.  Mail routing information as produced by
  15. Xpathalias is also displayed.  Since uuhosts needs the map information
  16. Xfrom the USENET spool directory for mod.map.uucp extracted into a more
  17. Xaccessible (and permanent) location, it can be used to do that, too.
  18. X
  19. XThis posting of uuhosts works with the latest (August 1985)
  20. Xmod.map.uucp postings.  Peculiar failures which I have not been able
  21. Xto reproduce here have been reported from some systems running some
  22. Xports of System V.  Please let me know of any problems, such as
  23. Xuuhosts not recognizing articles in mod.map.uucp as valid,
  24. Xand mailing them to postmaster rather than extracting them.
  25. X
  26. XThis version of uuhosts, 1.58, does map extraction quite differently
  27. Xfrom the previous version, 1.52.  Rather than immediately extracting
  28. Xeach article when it arrives, a list is kept of the pathnames of
  29. Xincoming articles, and "uuhosts -unbatch" is called nightly to do the
  30. Xextraction.  --->  It is necessary to completely reinstall uuhosts <---
  31. Xusing the new installation instructions.
  32. X
  33. XOutput paging by means of more, pg, etc. has been added, due to popular
  34. Xdemand.  A default pager must be set in the Makefile.  If the compile-time
  35. Xparameters get much more complicated, I will probably pick up Larry Wall's
  36. Xconfiguration package.
  37. X
  38. X
  39. XIf you don't have a UNIX group named news in /etc/group, you should 
  40. Xcreate one, as uuhosts depends on it.
  41. X
  42. XTo install uuhosts, first look at the beginning of the Makefile and
  43. Xadjust any pathnames or other parameters which are incorrect for your
  44. Xsystem.  Then do "make" to be sure everything compiles correctly.
  45. XTo install the necessary shell script, C program, and manual entry,
  46. Xas well as creating all necessary new directories, do "make install"
  47. Xas root.
  48. X
  49. XOnce the program is installed, you will want to extract any existing
  50. Xmod.map.uucp articles so uuhosts can display their information.  To do
  51. Xthis, type "uuhosts -setup &".  Do not do it as root!  Do it as some
  52. Xuser in group news.  It will take a while:  display speed has been
  53. Xbought by slowness in extraction.  You should only ever need to do
  54. Xthis once, because of the last installation steps:
  55. X
  56. XFinally, modify NEWS/sys by hand so that inews will batch incoming
  57. Xmod.map.uucp articles, and also arrange for "uuhosts -unbatch" to
  58. Xbe called nightly by cron.  See the MAINTENANCE section of the uuhosts
  59. Xmanual entry for how to do this.  Do not call "uuhosts -unbatch" as root!
  60. XHave it called as some user in group news.
  61. X
  62. X
  63. XPathalias is not included here:  it was posted to net.sources recently.
  64. XIf you have uupath, you may want to use it to look up UUCP routing
  65. Xinformation instead of the method uuhosts uses by default.
  66. XJust look for uupath in uuhosts.sh and it's obvious what to change.
  67. X
  68. X
  69. XFor the mod.map.uucp extraction (and *only* that extraction), uuhosts
  70. Xdepends on a small setuid program called mapsh (included here) which
  71. Xuses chroot(2), which is in (at least) 4BSD, System N, and Version 7.
  72. XThe purpose of mapsh is to limit the commands which may be executed
  73. Xwhen found in a map article.  If you trust everyone who can post to
  74. XUSENET from any machine in the world, you can probably replace mapsh
  75. Xwith "cd $MAPS; sh".  Or you can use unmvax!lee's article parser in C,
  76. Xif you like.
  77. X
  78. X                John Quarterman
  79. X                Department of Computer Sciences
  80. X                University of Texas at Austin
  81. X                Austin, Texas 78712 USA
  82. X                jsq@sally.utexas.edu (jsq@ut-sally.ARPA)
  83. X                {ihnp4,seismo,gatech,harvard,ctvax}!ut-sally!jsq
  84. X
  85. XHere is an example of the most common use of uuhosts, which is to
  86. Xdisplay information about a particular host:
  87. X
  88. Xsally% uuhosts bang
  89. XUUCP mail path for bang:
  90. Xbang    ihnp4!bang!%s
  91. XUUCP mail path for bang annotated by location:
  92. Xbang(usa.ca.s)    ihnp4(att.il)!bang(usa.ca.s)!%s
  93. X
  94. XUUCP mail information for host bang (#USENET lines show USENET news links):
  95. X#Name              bang
  96. X#System-CPU-OS          Model 16B - Xenix
  97. X#Organization          Bang World Communications
  98. X#Contact          Bret Marquis
  99. X#Electronic-Address      {ihnp4, sdcsvax}!bang!bam
  100. X#Telephone          (619) 450-2110
  101. X#Postal-Address          La Jolla, CA
  102. X#Latitude-Longitude    32 51 N / 117 16 W city 
  103. X#Remarks    
  104. X#Written-by          web 4/28/85, web 4/6/85, web per bam 3/28/85
  105. X#USENET    sys1 futura
  106. X#
  107. Xbang    blia(EVENING), cbosgd(DEMAND), celerity(DIRECT), crash(DIRECT),
  108. X    epicom(WEEKLY), futura(WEEKLY), ihnp4(DEMAND), netword(EVENING), 
  109. X    noscvax(DIRECT), orca(DEMAND), sdchema(DIRECT), sdcsvax(DIRECT),
  110. X    sdhubbs(WEEKLY), sys1(DEMAND), systech(DAILY), telesoft(DIRECT),
  111. X    vis(DEMAND), westsci(DAILY), wolf(DIRECT)
  112. X
  113. !RoNnIe!RaYgUn!
  114. echo x - uuhosts.sh
  115. sed -e 's/^X//' > uuhosts.sh << '!RoNnIe!RaYgUn!'
  116. X#!/bin/sh
  117. X# '@(#) uuhosts.sh 1.58 85/09/03'
  118. X# uuhosts - UUCP mail and USENET news information
  119. X
  120. XDEFPAGER=cat
  121. XBIN=/usr/local
  122. XLIB=/usr/local/lib
  123. XNEWS=$LIB/news
  124. XMAPS=$NEWS/maps
  125. XUUCPMAPGROUP=mod.map.uucp
  126. XUUCPMAP=$UUCPMAPGROUP
  127. XMAPSH=$NEWS/mapsh
  128. XUUCPSPOOL=/usr/spool/news/mod/map/uucp
  129. X
  130. X# Routing information produced by pathalias.
  131. XPATHS=$LIB/nmail.paths
  132. X# Munged by uuwhere for location information.
  133. XWHERE=$LIB/nmail.where
  134. X
  135. Xpager="${PAGER-$DEFPAGER}"
  136. X
  137. Xcd $NEWS
  138. X
  139. Xcase $1 in
  140. X    -setup)
  141. X        # Initial setup.  Should only need to be done once.
  142. X        ls $UUCPSPOOL/* > $MAPS/$UUCPMAP/Batch
  143. X        exec $BIN/uuhosts -unbatch
  144. X        exit 1
  145. X    ;;
  146. X
  147. X    -unbatch)
  148. X        # Unbatch map articles batched by sys.  Called from cron.
  149. X        cd $MAPS/$UUCPMAP
  150. X        if [ -f Batch ]; then
  151. X            :
  152. X        else
  153. X            exit 0
  154. X        fi
  155. X        mv Batch Batch.working
  156. X        for f in `cat Batch.working`
  157. X        do
  158. X            $BIN/uuhosts -x < $f
  159. X            sleep 60
  160. X        done
  161. X        rm Batch.working
  162. X        exec $BIN/uuhosts -i
  163. X        exit 1
  164. X    ;;
  165. X
  166. X    -x)
  167. X        # extract a new map piece into a map directory
  168. X        temphead=/tmp/maphead.$$
  169. X        temptext=/tmp/maptext.$$
  170. X        tempcomm=/tmp/mapcomm.$$
  171. X        cp /dev/null $temphead
  172. X        cp /dev/null $temptext
  173. X        echo 'exec /bin/mail postmaster' > $tempcomm
  174. X        echo 'Reply-To: postmaster' > $temphead
  175. X        awk '
  176. XBEGIN    {
  177. X    temphead = "'$temphead'"; tempcomm = "'$tempcomm'";
  178. X    isuucpmap = 0;
  179. X    shead = 0; stext = 1; suucp = 2;
  180. X    state = shead;
  181. X}
  182. Xstate == shead && ($1 == "From:" || $1 == "Sender:" \
  183. X    || $1 == "Date:" || $1 == "Message-ID:" || $1 == "Message-Id:") {
  184. X    print "Original-" $0 >> temphead;
  185. X    next;
  186. X}
  187. X# Assume we were called on the right newsgroup.
  188. X#state == shead && $1 == "Newsgroups:" {    # no cross-postings allowed
  189. X#    if ($2 == "'$UUCPMAPGROUP'")
  190. X#        isuucpmap = 1;
  191. X#}
  192. Xstate == shead && $1 == "Subject:" {
  193. X    # the odd initial test is to avoid certain brain damaged awks
  194. X    if ("X" ~ /X/ \
  195. X    && $2 !~ /^UUCP/ && $2 !~ /^uucp/ && $2 !~ /^Uucp/) {
  196. X        print "Subject:  not a map update" >> temphead;
  197. X        print "Original-" $0 >> temphead;
  198. X        isuucpmap = 0;
  199. X    } else
  200. X        print $0 >> temphead;
  201. X    next;
  202. X}
  203. Xstate == shead && /^$/    {
  204. X    if (isuucpmap != 0) {
  205. X    print "PATH=/bin; umask 0002; cd '$UUCPMAP'" | "'$MAPSH'";
  206. X        state = suucp;
  207. X    } else
  208. X        state = stext;
  209. X}
  210. Xstate == shead {
  211. X        print $0 >> temphead;
  212. X}
  213. Xstate == suucp    {
  214. X    print | "'$MAPSH'";
  215. X}
  216. Xstate == stext    {
  217. X    print;
  218. X}
  219. X' > $temptext 2>&1
  220. X        cat $temphead $temptext | sh $tempcomm
  221. X        rm -f $temphead $temptext $tempcomm
  222. X        exit 0
  223. X    ;;
  224. X
  225. X    -i)
  226. X        cd $MAPS/$UUCPMAP
  227. X        hostmarker="#N"
  228. X        if [ ! -f Local ]; then
  229. X            cp /dev/null Local
  230. X        fi
  231. X        cp /dev/null Index.t.$$
  232. X        for f in Local [a-z]* 
  233. X        do
  234. X             awk '
  235. XBEGIN {
  236. X    isinside = 0;
  237. X}
  238. X$1 == "'"$hostmarker"'" {
  239. X    if (isinside)
  240. X        printf ("%s\t%s\t%d\t%d\n", hostname, FILENAME, firstline, NR - 1);
  241. X    isinside = 1;
  242. X    hostname = $2;
  243. X    firstline = NR;
  244. X}
  245. XEND {
  246. X    if (isinside)
  247. X        printf ("%s\t%s\t%d\t%d\n", hostname, FILENAME, firstline, NR);
  248. X}
  249. X' $f >> Index.t.$$
  250. X        done
  251. X        sort -f Index.t.$$ > Index.s.$$
  252. X         mv Index.s.$$ Index
  253. X        rm Index.t.$$
  254. X        exit 0
  255. X    ;;
  256. X
  257. X    -r)
  258. X        # by region
  259. X        cd $MAPS/$UUCPMAP
  260. X        shift
  261. X        case $# in
  262. X        0)
  263. X            exec ls
  264. X            exit 1
  265. X        ;;
  266. X        esac
  267. X        exec $pager $*
  268. X        exit 1
  269. X    ;;
  270. X
  271. X    -u)
  272. X        exec $BIN/uuhosts -r
  273. X        exit 1
  274. X    ;;
  275. X
  276. X    -n)
  277. X        exec $BIN/uuhosts -r
  278. X        exit 1
  279. X    ;;
  280. X
  281. X    -k)
  282. X        # by keyword
  283. X        cd $MAPS/$UUCPMAP
  284. X        shift
  285. X        exec awk '
  286. XBEGIN        { inside = 1; outside = 0; state = outside; }
  287. X/^#N/ && state == inside    {
  288. X    if (useit == 1) {
  289. X        for (i = 0; i < count; i++) {
  290. X            print block[i];
  291. X        }
  292. X    }
  293. X    state = outside;
  294. X}
  295. X/^#N/    { state = inside; count = 0; useit = 0; }
  296. Xstate == inside    { block[count++] = $0; }
  297. X/'"$*"'/    { useit = 1; }
  298. XEND {
  299. X    if (useit == 1) {
  300. X        for (i = 0; i < count; i++) {
  301. X            print block[i];
  302. X        }
  303. X    }
  304. X}
  305. X' * | $pager
  306. X        exit 1
  307. X    ;;
  308. X
  309. X    -*)
  310. X        # unknown option
  311. X    ;;
  312. X
  313. X    "")
  314. X        # no arguments
  315. X    ;;
  316. X
  317. X    *)
  318. X        # by host name
  319. X        if [ -f /usr/bin/look ]; then
  320. X            look=/usr/bin/look
  321. X            lookopt="-f "
  322. X        else
  323. X            look=grep
  324. X            lookopt="^"
  325. X        fi
  326. X        for arg in $*
  327. X        do
  328. X            echo 'UUCP mail path for '$arg':'
  329. X            $look $lookopt$arg $PATHS
  330. X#             uupath $arg
  331. X            if [ -f $WHERE ]; then
  332. X            echo 'UUCP mail path for '$arg' annotated by location:'
  333. X                $look $lookopt$arg $WHERE
  334. X                $LIB/uuwhere &
  335. X            fi
  336. X            echo '
  337. XUUCP mail information for host '$arg' (#USENET lines show USENET news links):'
  338. X            cd $MAPS/$UUCPMAP
  339. X            eval `$look $lookopt$arg Index | awk '
  340. X/^'$arg'/ {
  341. X    printf ("sed -n -e \"%d,%dp\" %s;\n", $3, $4, $2);
  342. X}'` | sed -e '
  343. Xs/^#N/#Name        /
  344. Xs/^#S/#System-CPU-OS    /
  345. Xs/^#O/#Organization    /
  346. Xs/^#C/#Contact    /
  347. Xs/^#E/#Electronic-Address/
  348. Xs/^#T/#Telephone    /
  349. Xs/^#P/#Postal-Address    /
  350. Xs/^#L/#Latitude-Longitude/
  351. Xs/^#R/#Remarks    /
  352. Xs/^#W/#Written-by    /
  353. Xs/^#U/#USENET/'
  354. X        done | $pager
  355. X        exit 0
  356. X    ;;
  357. Xesac
  358. X
  359. Xecho 'Usage:    'uuhosts' hostname ...
  360. Xfor information about a particular UUCP or USENET host or hosts, or
  361. X
  362. X    'uuhosts' -r region
  363. Xfor information about hosts in a region of the UUCP or USENET networks, or
  364. X
  365. X    'uuhosts' -r
  366. Xfor a list of known regions.
  367. X
  368. XSee uuhosts(1) or "uuhosts -r README" for further details.
  369. X'
  370. Xexit 1
  371. !RoNnIe!RaYgUn!
  372. echo x - mapsh.c
  373. sed -e 's/^X//' > mapsh.c << '!RoNnIe!RaYgUn!'
  374. X#include <stdio.h>
  375. X/*
  376. X    This command depends on chroot(2), which exists in 4BSD, System V,
  377. X    Version 7, and probably all related systems.
  378. X */
  379. X
  380. X#ifndef MAPS
  381. X#define MAPS "/usr/local/lib/news/maps"
  382. X#endif
  383. X
  384. Xmain(argc,argv)
  385. Xint argc;
  386. Xchar **argv;
  387. X{
  388. X    char *rootdir = MAPS;
  389. X    char *command = "/bin/sh";
  390. X
  391. X    if (geteuid() != 0) {
  392. X        fprintf (stderr, "mapsh must be setuid to root\n");
  393. X        exit(1);
  394. X    }
  395. X    if (chroot(rootdir) == -1) {
  396. X        fprintf (stderr, "mapsh:  chroot(%s) failed\n", rootdir);
  397. X        perror ("");
  398. X        exit(1);
  399. X    }
  400. X    if (setuid(getuid()) == -1) {
  401. X        perror ("mapsh:  setuid(getuid()) failed");
  402. X        exit(1);
  403. X    }
  404. X    if (chdir("/") == -1) {
  405. X        fprintf (stderr, "mapsh:  chdir(%s) failed\n", "/");
  406. X        perror ("");
  407. X        exit(1);
  408. X    }
  409. X    execvp (command, argv);
  410. X    fprintf (stderr, "mapsh:  %s not found\n", command);
  411. X    perror ("mapsh:  execvp(2) failed");
  412. X    exit(1);
  413. X}
  414. !RoNnIe!RaYgUn!
  415. echo x - uuwhere.c
  416. sed -e 's/^X//' > uuwhere.c << '!RoNnIe!RaYgUn!'
  417. X#ifndef lint
  418. Xchar sccsid[] = "@(#) uuwhere.c 1.11 85/09/04";
  419. X#endif
  420. X/*
  421. X * uuwhere:
  422. X * This is a frill which may be called by uuhosts to annotate routing
  423. X * information produced by pathalias(1L) with the location of each host.
  424. X * It takes the ASCII UUCP routing database PATHS on standard input,
  425. X * and produces the annnotated version on standard output, to be put
  426. X * in WHERE.  It gets the location information from the UUCP map directory
  427. X * produced by uuhosts from the map posted to the USENET newsgroup
  428. X * mod.map.uucp by the UUCP Project.
  429. X *
  430. X * Uuwhere is usually called by uuhosts, and most of the time just
  431. X * checks to see if WHERE needs to be updated.  Uuhosts itself
  432. X * displays the annotated routing information to the user.
  433. X *
  434. X * The host location information is first put into a dbm(3x)
  435. X * database so that generating the final output will not take forever.
  436. X * If you don't have dbm, this won't work.
  437. X */
  438. X
  439. X#include <stdio.h>
  440. X#include <ctype.h>
  441. X#include <dbm.h>
  442. X#include <sys/types.h>
  443. X#include <sys/stat.h>
  444. X
  445. X#ifndef UUCPINDEX
  446. X#define UUCPINDEX "/usr/local/lib/news/maps/mod.map.uucp/Index"
  447. X#endif
  448. X#ifndef TMP
  449. X#define TMP "/usr/local/lib/nmail.tmp"
  450. X#endif
  451. X#ifndef PATHS
  452. X#define PATHS "/usr/local/lib/nmail.paths"
  453. X#endif
  454. X#ifndef WHERE
  455. X#define WHERE "/usr/local/lib/nmail.where"
  456. X#endif
  457. X#ifndef DATABASE
  458. X#define DATABASE    "/usr/local/lib/uuindex"
  459. X#endif
  460. X
  461. Xint verbose;
  462. X
  463. Xmain(argc, argv)
  464. Xint argc;
  465. Xchar **argv;
  466. X{
  467. X    register char **cp;
  468. X    int flagcreat = 0;
  469. X    int flagupdate = 1;
  470. X    int flaginput = 0;
  471. X
  472. X    (void) umask(0);
  473. X    for (cp = argv; *++cp != NULL; ) {
  474. X        if (**cp != '-') {
  475. X            flaginput = 1;
  476. X            flagupdate = 0;
  477. X            break;
  478. X        }
  479. X        switch (cp[0][1]) {
  480. X            case '\0':
  481. X                flaginput = 1;
  482. X                flagupdate = 0;
  483. X                break;
  484. X            case 'c':
  485. X                flagcreat = 1;
  486. X                flagupdate = 0;
  487. X                break;
  488. X            case 'v':
  489. X                verbose = 1;
  490. X                break;
  491. X            default:
  492. X                usage();
  493. X                break;
  494. X        }
  495. X    }
  496. X    if (!flaginput) {
  497. X        (void)fclose(stdout);
  498. X        (void)fclose(stdin);
  499. X    }
  500. X    init(flagcreat, flagupdate, flaginput);
  501. X    if (!flaginput) {
  502. X        char tmpbuf[64];
  503. X
  504. X         if (freopen (PATHS, "r", stdin) == (FILE *)NULL) {
  505. X            perror (PATHS);
  506. X            exit (1);
  507. X        }
  508. X        (void)sprintf(tmpbuf, "%s.%d", TMP, getpid());
  509. X        if (freopen (tmpbuf, "w", stdout) == (FILE *)NULL) {
  510. X            perror (tmpbuf);
  511. X            exit (1);
  512. X        }
  513. X        parsefile();
  514. X        (void)fclose(stdout);
  515. X        if (unlink (WHERE) == -1 || link(tmpbuf, WHERE) == -1) {
  516. X            perror(WHERE);
  517. X            exit(1);
  518. X        }
  519. X        (void)unlink(tmpbuf);
  520. X        exit (0);
  521. X    }
  522. X    for (; *cp != NULL; cp++) {
  523. X        if (strcmp (*cp, "-") != 0
  524. X          && freopen (*cp, "r", stdin) == (FILE *)NULL) {
  525. X            perror (*cp);
  526. X            continue;
  527. X        }
  528. X        parsefile();
  529. X    }
  530. X    exit(0);
  531. X}
  532. X
  533. Xusage()
  534. X{
  535. X    fprintf (stderr, "usage:  uuwhere [-c] [-v] [infiles]\n");
  536. X    exit (1);
  537. X}
  538. X
  539. Xinit(flagcreat, flagupdate, flaginput)
  540. Xint flagcreat, flagupdate, flaginput;
  541. X{
  542. X    char datadir[512], datapag[512];
  543. X    struct stat statuucp, statpaths, statwhere;
  544. X    int fd;
  545. X    char c;
  546. X
  547. X/*
  548. X * If any of the stats fail,
  549. X * an open will fail later and produce a diagnostic.
  550. X */
  551. X    if (flagupdate
  552. X    && stat(WHERE, &statwhere) != -1
  553. X    && stat(PATHS, &statpaths) != -1
  554. X    && stat(UUCPINDEX, &statuucp) != -1) {
  555. X        if (statwhere.st_mtime > statpaths.st_mtime
  556. X        && statwhere.st_mtime > statuucp.st_mtime) {
  557. X            if (verbose)
  558. X                fprintf (stderr, "%s up to date\n", WHERE);
  559. X            exit(0);
  560. X        }
  561. X        if (statuucp.st_mtime > statwhere.st_mtime
  562. X        || statuucp.st_mtime > statpaths.st_mtime)
  563. X            flagcreat = 1;
  564. X    }
  565. X    if (!flaginput) {
  566. X        /* touch WHERE to forestall duplicate uuwheres */
  567. X        if ((fd = open(WHERE, 2)) < 0) {
  568. X            perror(WHERE);
  569. X            exit(1);
  570. X        }
  571. X        if (read (fd, &c, 1) == 1)
  572. X            (void) write (fd, &c, 1);
  573. X        (void) close (fd);
  574. X    }
  575. X    (void) sprintf (datadir, "%s.dir", DATABASE);
  576. X    (void) sprintf (datapag, "%s.pag", DATABASE);
  577. X    if (flagcreat || access(datadir, 0) == -1 || access(datapag, 0) == -1) {
  578. X        flagcreat = 1;
  579. X        if (verbose)
  580. X            fprintf (stderr, "Creating database %s...\n", DATABASE);
  581. X        if (makefile(datadir) == -1 || makefile(datapag) == -1)
  582. X            exit(1);
  583. X    }
  584. X    if (dbminit(DATABASE) < 0)
  585. X        exit(1);
  586. X    if (!flagcreat)
  587. X        return;
  588. X    if (!initit(UUCPINDEX))
  589. X        exit(1);
  590. X    if (verbose)
  591. X        fprintf (stderr, "...database %s created.\n", DATABASE);
  592. X}
  593. X
  594. Xmakefile(name)
  595. Xchar *name;
  596. X{
  597. X    register int fd;
  598. X
  599. X    if ((fd = creat(name, 0666)) == -1) {
  600. X        perror(name);
  601. X        return(-1);
  602. X    }
  603. X    (void) close(fd);
  604. X    return (0);
  605. X}
  606. X
  607. Xinitit(name)
  608. Xchar *name;
  609. X{
  610. X    register FILE *fp;
  611. X    char buffer[1024], site[128], where[128];
  612. X    datum key, data;
  613. X
  614. X    if (verbose)
  615. X        fprintf(stderr, "Reading %s...", name);
  616. X    if ((fp = fopen(name, "r")) == (FILE *)NULL) {
  617. X        perror(name);
  618. X        return (0);
  619. X    }
  620. X     while (fgets(buffer, sizeof(buffer), fp) != NULL) {
  621. X        if (sscanf(buffer, "%s%s", site, where) != 2) {
  622. X            fprintf (stderr, "Can't parse:  %s\n", buffer);
  623. X            continue;
  624. X        }
  625. X        key.dptr = site;
  626. X        key.dsize = strlen(key.dptr) + 1;
  627. X        data.dptr = where;
  628. X        data.dsize = strlen(data.dptr) + 1;
  629. X        store (key, data);
  630. X    }
  631. X    (void)fclose(fp);
  632. X    if (verbose)
  633. X        fprintf(stderr, ".\n");
  634. X    return(1);
  635. X}
  636. X
  637. Xparsefile()
  638. X{
  639. X    char buffer[128];
  640. X    register char *cp;
  641. X    register int c;
  642. X    register int inside;
  643. X    register int last = 0;
  644. X
  645. X    for (inside = 0; (c = getchar()) != EOF; putchar(c)) {
  646. X        if (isalnum(c) || (c) == '.' || (c) == '-' || (c) == '_') {
  647. X            if (!inside) {
  648. X                cp = buffer;
  649. X                inside = 1;
  650. X            }
  651. X            *cp++ = c;
  652. X            continue;
  653. X        }
  654. X        if (inside) {
  655. X            *cp = '\0';
  656. X            if (cp != buffer
  657. X/* %s */    && !((cp - buffer) == 1 && last == '%' && buffer[0] == 's'))
  658. X                doit(buffer);
  659. X            inside = 0;
  660. X        }
  661. X        last = c;
  662. X    }
  663. X}
  664. X
  665. Xdoit (site)
  666. Xchar *site;
  667. X{
  668. X    datum key, data;
  669. X
  670. X    key.dptr = site;
  671. X    key.dsize = strlen(key.dptr) + 1;
  672. X    data = fetch(key);
  673. X    if (data.dptr != NULL)
  674. X        printf ("(%s)", data.dptr);
  675. X}
  676. !RoNnIe!RaYgUn!
  677. echo x - uuhosts.man
  678. sed -e 's/^X//' > uuhosts.man << '!RoNnIe!RaYgUn!'
  679. X.TH UUHOSTS 1L 85/09/03
  680. X.SH NAME
  681. Xuuhosts \- UUCP mail and USENET news information.
  682. X.SH SYNOPSIS
  683. X.B
  684. Xuuhosts
  685. Xhostname ...
  686. X.br
  687. X.B
  688. Xuuhosts
  689. X-r [ region ]
  690. X.SH DESCRIPTION
  691. XThe \fIuuhosts\fP command is used to look up information about
  692. Xthe configurations of the UUCP mail network and the USENET news network.
  693. X.TP
  694. Xuuhosts \fIhostname\fP ...
  695. Xfor information about a particular UUCP or USENET host or hosts.
  696. XThe UUCP mail path is given first, followed by the map information.
  697. XThe USENET map is carried as notations in entries in the UUCP map,
  698. Xin the lines starting with ``#USENET''.
  699. XAny hosts with names for which the argument is a prefix are shown, e.g.:
  700. X.TP
  701. Xuuhosts ut
  702. Xgets information about all hosts whose names start with ``ut''.
  703. X.TP
  704. Xuuhosts \-r \fIregion\fP
  705. Xfor information about hosts in a (usually geographical) region.
  706. X.TP
  707. Xuuhosts \-r README
  708. Xgets an introduction to the map.
  709. X.TP
  710. Xuuhosts \-r Local
  711. Xgets map information known only locally.
  712. X.TP
  713. Xuuhosts \-r
  714. Xfor a list of known regions.
  715. X.TP
  716. Xuuhosts
  717. Xwith no arguments gets a short usage message.
  718. X.PP
  719. XOutput is broken into pages by the program named in the PAGER environment
  720. Xvariable, or by a default pager set at compile time,
  721. Xwhich is usually one of more, pg, or cat,
  722. Xas appropriate for the host system.
  723. X.SH MAINTENANCE
  724. XNone of these options should be used by the super-user (root).
  725. X.TP
  726. Xuuhosts \-setup
  727. XOnce "make\ install" has been done for the initial installation,
  728. Xthis option may be used to extract any backlog of \fBmod.map.uucp\fP articles.
  729. XDo not run it as root!
  730. XRun it as some user in group news.
  731. X.TP
  732. Xmaps:mod.map.uucp:F:MAPS/mod.map.uucp/Batch
  733. XThis line should go in \fBNEWS/sys\fP.
  734. XIt causes \fIinews\fP(1L) to list the pathnames of incoming articles of
  735. X\fBmod.map.uucp\fP in the \fBBatch\fP file.
  736. X.TP
  737. Xuuhosts \-unbatch
  738. XThis should be called nightly by \fIcron\fP(8) or whatever mechanism is
  739. Xused to call the USENET \fIexpire\fP(8) command.
  740. XIt extracts articles from \fBmod.map.uucp\fP which have
  741. Xcome in since the last time it was run.
  742. XDo not run it as root!
  743. XRun it as some user in group news.
  744. X.TP
  745. Xuuhosts \-x
  746. XExtract an individual \fBmod.map.uucp\fP article.
  747. XOrdinarily called from \fIuuhosts\fP\ \-\fBunbatch\fP.
  748. X.TP
  749. Xuuhosts \-i
  750. XRebuild the Index file (see below).
  751. XOrdinarily called from \fIuuhosts\fP\ \-\fBunbatch\fP.
  752. X.SH FILES
  753. X.TP
  754. XPATHS
  755. XUUCP mail path database as produced by \fIpathalias\fP and used by \fInmail\fP
  756. X(which is called automatically from \fIsendmail\fP on \fIut\-sally\fP)
  757. XIt is searched by \fIlook\fP(1), if present, else \fIgrep\fP(1).
  758. XThe file WHERE is similarly searched, if present:
  759. Xsee \fIuuwhere\fP(1).
  760. X.TP
  761. XUUCPMAP
  762. XUUCP and USENET map information taken from newsgroup \fBmod.map.uucp\fP
  763. X(thanks to the UUCP mapping project).
  764. XNotices of updates are mailed to \fBpostmaster\fP, which should be an alias
  765. Xredistributing to the local mail and UUCP administrators.
  766. X.TP
  767. XUUCPMAP/Index
  768. XThis index is used to decrease search time on the map about an order
  769. Xof magnitude.
  770. XThe search is done by either \fIlook\fP(1) or \fIgrep\fP(1), as above.
  771. X.SH SEE ALSO
  772. Xvnews(1), readnews(1), mail(1), sendmail(8), look(1)
  773. !RoNnIe!RaYgUn!
  774. echo x - uuwhere.man
  775. sed -e 's/^X//' > uuwhere.man << '!RoNnIe!RaYgUn!'
  776. X.TH UUW\HERE 1L 85/08/11
  777. X.SH NAME
  778. Xuuwhere \- annotate UUCP mail routes by host location
  779. X.SH SYNOPSIS
  780. X.B
  781. XLIB/uuwhere
  782. X[ -c ]
  783. X[ infile ]
  784. X.SH DESCRIPTION
  785. XThe \fIuuwhere\fP command is used take a list of UUCP routes,
  786. Xsuch as produced by \fIpathalias\fP, and make a similar list,
  787. Xannotated by the geographical location of each host as found
  788. Xin the UUCP map posted to USENET newsgroup mod.map.uucp.
  789. XIt is ordinarily called with no arguments by \fIuuhosts\fP(1L),
  790. Xand will update \fBWHERE\fP, taking routes from \fBPATHS\fP and locations
  791. Xfrom \fBUUCPMAP/Index\fP, if either
  792. X\fBPATHS\fP or \fBUUCPMAP/Index\fP is newer than \fBWHERE\fP.
  793. XThe information in \fBWHERE\fP is displayed by \fIuuhosts\fP itself.
  794. X.PP
  795. XInput file names may be specified as arguments.
  796. XThis also causes output to go to standard output instead of directly to
  797. XInput file name \fI-\fP is taken to be standard input.
  798. X\fBWHERE\fP.
  799. X.TP
  800. X\-\fBc
  801. X\fIUuwhere\fP uses a \fIdbm\fP(3) database to store the location information
  802. Xfrom \fBUUCPMAP/Index\fP before creating output.
  803. XThis option causes \fIuuwhere\fP to recreate the database regardless
  804. Xof the state of any input files.
  805. X.SH FILES
  806. X.TP
  807. XWHERE
  808. XThe place where the output of \fIuuwhere\fP is usually kept for use
  809. Xby \fIuuhosts\fP.
  810. X.TP
  811. XPATHS
  812. XThe default route list used as input by \fIuuwhere\fP.
  813. XProduced by \fIuuhosts\fP.
  814. X.TP
  815. XUUCPMAP/Index
  816. XThe source of the location information used by \fIuuwhere\fP.
  817. XProduced by \fIpathalias\fP.
  818. X.SH SEE ALSO
  819. Xuuhosts(1), pathalias(1), dbm(3).
  820. !RoNnIe!RaYgUn!
  821. echo x - Makefile
  822. sed -e 's/^X//' > Makefile << '!RoNnIe!RaYgUn!'
  823. X# @(#) Makefile 1.25 85/09/03
  824. XSHELL=/bin/sh
  825. X
  826. X# Settable parameters.
  827. X
  828. X# Default pager for use if PAGER environment variable is not set.
  829. XDEFPAGER=more    # BSD systems
  830. X#DEFPAGER=pg    # AT&T systems
  831. X#DEFPAGER=cat    # systems with paging in the kernel
  832. X
  833. X# BIN should be either /usr/local or /usr/local/bin
  834. XBIN=/usr/local
  835. XLIB=/usr/local/lib
  836. XPATHS=$(LIB)/nmail.paths
  837. X
  838. X# If you do not have dbm(3), i.e., -ldbm, set UUWHERE to nothing.
  839. XUUWHERE=uuwhere
  840. X# UUWHERE=
  841. XWHERE=$(LIB)/nmail.where
  842. X# TMP should be in the same directory as WHERE.
  843. XTMP=$(LIB)/nmail.tmp
  844. X# -ldbm DATABASE used by uuwhere.
  845. XDATABASE=$(LIB)/uuindex
  846. X
  847. X# Most of the news parameter files and mapsh are in this directory.
  848. XNEWS=$(LIB)/news
  849. X# The maps from mod.map.all are under this directory.
  850. X# (Another good place to put it is MAPS=/usr/spool/news/maps.)
  851. XMAPS=$(NEWS)/maps
  852. X# USENET spool directory containing articles from newsgroup mod.map.uucp.
  853. XUUCPSPOOL=/usr/spool/news/mod/map/uucp
  854. X
  855. X# The filename of the manual entry.
  856. XUUHOSTSMAN=uuhosts.1
  857. XUUWHEREMAN=uuwhere.1
  858. XMAN=$(UUHOSTSMAN) $(UUWHEREMAN)
  859. XMANSOURCES=uuhosts.man uuwhere.man
  860. X# The manual directory for local entries.
  861. XMANDIR=/usr/man/manl
  862. X
  863. X# The rest of the Makefile shouldn't need to be changed.
  864. X
  865. XUUCPMAP=$(MAPS)/mod.map.uucp
  866. X
  867. XSOURCES=uuhosts.sh mapsh.c uuwhere.c $(MANSOURCES)
  868. XALL= uuhosts mapsh $(UUWHERE) $(MAN)
  869. X
  870. Xall: $(ALL)
  871. X
  872. Xuuhosts: uuhosts.sh
  873. X    cat uuhosts.sh \
  874. X    | sed -e 's%^DEFPAGER=.*$$%DEFPAGER=$(DEFPAGER)%' \
  875. X    | sed -e 's%^UUCPSPOOL=.*$$%UUCPSPOOL=$(UUCPSPOOL)%' \
  876. X    | sed -e 's%^BIN=.*$$%BIN=$(BIN)%;s%^LIB=.*$$%LIB=$(LIB)%' \
  877. X    | sed -e 's%^PATHS=.*$$%PATHS=$(PATHS)%;s%^WHERE=.*$$%WHERE=$(WHERE)%'\
  878. X    | sed -e 's%^NEWS=.*$$%NEWS=$(NEWS)%;s%^MAPS=.*$$%MAPS=$(MAPS)%'\
  879. X    > uuhosts
  880. X    chmod +x uuhosts
  881. X
  882. Xmapsh: mapsh.c
  883. X    $(CC) -o mapsh -DMAPS=\"$(MAPS)\" mapsh.c
  884. X
  885. Xuuwhere: uuwhere.c
  886. X    $(CC) -o uuwhere -DUUCPINDEX=\"$(UUCPMAP)/Index\" \
  887. X            -DPATHS=\"$(PATHS)\" -DWHERE=\"$(WHERE)\" \
  888. X            -DTMP=\"$(TMP)\" -DDATABASE=\"$(DATABASE)\" \
  889. X            uuwhere.c -ldbm
  890. X
  891. Xwhere:    $(LIB)/uuwhere
  892. X
  893. X$(UUHOSTSMAN):    uuhosts.man
  894. X    sed -e 's%UUCPMAP%$(UUCPMAP)%' uuhosts.man \
  895. X    | sed -e 's%DEFPAGER%$(DEFPAGER)%;s%BIN%$(BIN)%;s%LIB%$(LIB)%' \
  896. X    | sed -e 's%PATHS%$(PATHS)%;s%WHERE%$(WHERE)%;s%TMP%$(TMP)%'\
  897. X    | sed -e 's%DATABASE%$(DATABASE)%;s%NEWS%$(NEWS)%;s%MAPS%$(MAPS)%'\
  898. X        > $(UUHOSTSMAN)
  899. X
  900. X$(UUWHEREMAN):    uuwhere.man
  901. X    sed -e 's%UUCPMAP%$(UUCPMAP)%' uuwhere.man \
  902. X    | sed -e 's%BIN%$(BIN)%;s%LIB%$(LIB)%' \
  903. X    | sed -e 's%PATHS%$(PATHS)%;s%WHERE%$(WHERE)%;s%TMP%$(TMP)%'\
  904. X    | sed -e 's%DATABASE%$(DATABASE)%;s%NEWS%$(NEWS)%;s%MAPS%$(MAPS)%'\
  905. X        > $(UUWHEREMAN)
  906. X
  907. Xinst_:
  908. X
  909. Xinst_uuwhere: $(UUWHERE)
  910. X    -rm -f $(LIB)/uuwhere
  911. X    cp uuwhere $(LIB)/uuwhere
  912. X    chmod 555 $(LIB)/uuwhere
  913. X    cp /dev/null $(WHERE)
  914. X    -chmod 666 $(WHERE)
  915. X    -rm -f $(MANDIR)/$(UUWHEREMAN)
  916. X    cp $(UUWHEREMAN) $(MANDIR)
  917. X    chmod 444 $(MANDIR)/$(UUWHEREMAN)
  918. X
  919. Xinstall: $(ALL) inst_$(UUWHERE)
  920. X    -rm -f $(BIN)/uuhosts
  921. X    cp uuhosts $(BIN)/uuhosts
  922. X    chmod 555 $(BIN)/uuhosts
  923. X    -rm -f $(MANDIR)/$(UUHOSTSMAN)
  924. X    cp $(UUHOSTSMAN) $(MANDIR)
  925. X    chmod 444 $(MANDIR)/$(UUHOSTSMAN)
  926. X    @echo "Rest of installation has to be done as root."
  927. X    cp mapsh $(NEWS)/mapsh
  928. X    -strip $(NEWS)/mapsh
  929. X    chown root $(NEWS)/mapsh
  930. X    chgrp news $(NEWS)/mapsh
  931. X    chmod 4750 $(NEWS)/mapsh
  932. X    ls -lg $(NEWS)/mapsh
  933. X    @echo "If the following mkdir of $(MAPS) fails,"
  934. X    @echo "it is assumed that the map directories were set up previously."
  935. X    mkdir $(MAPS)
  936. X    mkdir $(MAPS)/bin $(MAPS)/tmp $(UUCPMAP)
  937. X    chgrp news $(MAPS) $(MAPS)/*
  938. X    chmod 555 $(MAPS)
  939. X    chmod 775 $(UUCPMAP)
  940. X    chmod 777 $(MAPS)/tmp
  941. X    chmod 555 $(MAPS)/bin
  942. X    cp /bin/cat $(MAPS)/bin
  943. X    cp /bin/echo $(MAPS)/bin
  944. X    cp /bin/sed $(MAPS)/bin
  945. X    cp /bin/sh $(MAPS)/bin
  946. X    -strip $(MAPS)/bin/*
  947. X    chgrp news $(MAPS)/bin/*
  948. X    chmod 555 $(MAPS)/bin/*
  949. X    @echo ''
  950. X    @echo 'This is what the things just installed *should* look like:'
  951. X    @echo '$(MAPS): total 16'
  952. X    @echo 'dr-xr-xr-x  6 root     news          512 Nov 11 16:42 .'
  953. X    @echo 'drwxrwxr-x 19 news     news         1024 Nov 11 16:45 ..'
  954. X    @echo 'dr-xr-xr-x  2 root     news          512 Nov 11 16:39 bin'
  955. X    @echo 'drwxrwxr-x  2 news     news        10240 Nov 11 16:39 mod.map.uucp'
  956. X    @echo 'drwxrwxrwx  2 news     news           24 Nov 11 16:41 tmp'
  957. X    @echo ''
  958. X    @echo '$(MAPS)/bin: total 59'
  959. X    @echo '-r-xr-xr-x  1 root     news        10240 Nov 11 15:29 cat'
  960. X    @echo '-r-xr-xr-x  1 root     news         4096 Nov 11 16:33 echo'
  961. X    @echo '-r-xr-xr-x  1 root     news        18432 Nov 11 15:29 sed'
  962. X    @echo '-r-xr-xr-x  1 root     news        27648 Nov 11 15:29 sh'
  963. X    @echo ''
  964. X    @echo 'And here is what they actually *do* look like:'
  965. X    ls -lga $(MAPS)
  966. X    ls -lga $(MAPS)/bin
  967. X
  968. Xclean:
  969. X    rm -f $(ALL)
  970. X    rm -f *.pag *.dir
  971. X    rm -f *.o
  972. X    rm -f *.shar
  973. X
  974. Xshar:
  975. X    shar README* $(SOURCES) Makefile > uuhosts.shar
  976. !RoNnIe!RaYgUn!
  977. exit
  978.  
  979.  
  980.