home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / unix / volume03 / uuhosts3 < prev    next >
Encoding:
Internet Message Format  |  1988-09-11  |  27.0 KB

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