home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume05 / rman < prev    next >
Encoding:
Internet Message Format  |  1991-08-27  |  4.9 KB

  1. From decwrl!labrea!rutgers!ukma!cwjcc!hal!ncoast!allbery Sun Oct 30 15:07:36 PST 1988
  2. Article 698 of comp.sources.misc:
  3. Path: granite!decwrl!labrea!rutgers!ukma!cwjcc!hal!ncoast!allbery
  4. From: reggers@julian.uucp (Reg Quinton)
  5. Newsgroups: comp.sources.misc
  6. Subject: v05i021: "man" client with trivial server
  7. Message-ID: <8810031625.AA01245@julian.uwo.ca>
  8. Date: 28 Oct 88 03:19:10 GMT
  9. Sender: allbery@ncoast.UUCP
  10. Reply-To: reggers@julian.uucp (Reg Quinton)
  11. Lines: 158
  12. Approved: allbery@ncoast.UUCP
  13.  
  14. Posting-number: Volume 5, Issue 21
  15. Submitted-by: "Reg Quinton" <reggers@julian.uucp>
  16. Archive-name: rman
  17.  
  18. Here's a posting for comp.sources.unix that others might find useful. If nothing
  19. else the strategy is a sneaky one for building arbitrary client/server pairs.
  20.  
  21. We've implemented a simple "man/apropos" client for machines which don't have
  22. the /usr/man directory. I'm sure this has been done a hundred times by others
  23. but, for what it's worth, here's my way of doing it. Oh yes, this is a BSDism,
  24. I don't know how you'd do the same thing under SysV.
  25.  
  26. [Given SVR4, that last comment is a non-sequitur.  ++bsa]
  27.  
  28. -----------------------cut, cut, blood, spurt. I wanted to be a lumber jack!
  29. #!/bin/sh
  30. # to extract, remove the header and type "sh filename"
  31. if `test ! -s ./README`
  32. then
  33. echo "writing ./README"
  34. cat > ./README << '\Rogue\Monster\'
  35. There's no need to have manuals stored on every machine. Sources in this
  36. directory are used to build a client man and apropos program which use the
  37. man program on a server machine. This builds on the rcmd(3) call instead of
  38. defining another service. Here's what you need to do.
  39.  
  40. a) on your client machines build and install the man program (see Makefile);
  41.    and add an entry for "manhost" into your /etc/hosts and/or bind files.
  42.  
  43. b) on your server (ie. "manhost") machine add a user call "man" into your
  44.    password file with home directory /usr/man (shell can be csh or sh). Clients
  45.    not in /etc/hosts.equiv need to be added to /usr/man/.rhosts with lines of
  46.    the form "<host-name> man".
  47.  
  48. c) although not required you can remove /usr/man on your clients, and chown
  49.    -R man /usr/man on your server.
  50.  
  51. The names "manhost" and "man" are "#defines" in my code, you can use something
  52. else if you like.
  53.  
  54. The client man program tells the rshd on manhost that a local user called "man"
  55. wants the remote user called "man" to execute some man or apropos command. This
  56. relies then on the rshd access control system.  Hosts in the server (ie manhost)
  57. /etc/hosts.equiv file will be able to use the server without doing anything
  58. else. Hosts not in manhost's /etc/hosts.equiv should have an entry put into
  59. /usr/man/.rhosts for them (see rshd(8) for more details).
  60.  
  61. Reg Quinton <reggers@julian.uwo.ca>; 30-Sept-88
  62. \Rogue\Monster\
  63. else
  64.   echo "will not over write ./README"
  65. fi
  66. if `test ! -s ./Makefile`
  67. then
  68. echo "writing ./Makefile"
  69. cat > ./Makefile << '\Rogue\Monster\'
  70. # $Author: reggers $
  71. # $Date: 88/09/30 14:40:08 $
  72. # $Header: Makefile,v 1.1 88/09/30 14:40:08 reggers Locked $
  73. # $Locker: reggers $
  74. # $Revision: 1.1 $
  75. # $Source: /usrs/guru/reggers/rman/RCS/Makefile,v $
  76. # $State: Exp $
  77.  
  78. BIN=/usr/local
  79.  
  80. man: rman.c Makefile
  81.     cc -s -O -o man rman.c
  82.  
  83. install: man
  84.     install -m 4555 -o root man ${BIN}
  85.     -rm ${BIN}/apropos
  86.     ln -s ${BIN}/man ${BIN}/apropos
  87.     -rm /usr/ucb/man /usr/ucb/apropos
  88.     @echo you might ... rm -rf /usr/man
  89. \Rogue\Monster\
  90. else
  91.   echo "will not over write ./Makefile"
  92. fi
  93. if `test ! -s ./rman.c`
  94. then
  95. echo "writing ./rman.c"
  96. cat > ./rman.c << '\Rogue\Monster\'
  97. char *rcsversion=
  98. "$Header: rman.c,v 1.3 88/10/03 11:58:23 reggers Exp $";
  99.  
  100. /*
  101.  $Author: reggers $
  102.  $Date: 88/10/03 11:58:23 $
  103.  $Header: rman.c,v 1.3 88/10/03 11:58:23 reggers Exp $
  104.  $Locker:  $
  105.  $Revision: 1.3 $
  106.  $Source: /usrs/guru/reggers/rman/RCS/rman.c,v $
  107.  $State: Exp $
  108.  
  109.  This looks a lot like the rsh code (I'd bet) but we're only going to
  110.  hit either man, or apropos, via the rsh sequence. And we're going to
  111.  hit a particular user.
  112. */
  113.  
  114. #define    PAGER    "/usr/ucb/more"
  115. #define    MANUSER    "man"
  116. #define    MANHOST    "manhost"
  117. #define    RSHPORT 514
  118.  
  119. #include    <stdio.h>
  120. #include    <sysexits.h>
  121. #include    <strings.h>
  122.  
  123. main(argc,argv)
  124. int    argc;
  125. char    *argv[];
  126. {
  127.     char    *cmd,*p,c;
  128.     int    i,n,rem;
  129.  
  130.     if (p=rindex(argv[0],'/')) ++p;
  131.     else    p= argv[0];
  132.  
  133.     cmd=(char *)malloc(n=(strlen(p)+1));    strcpy(cmd,p);
  134.  
  135.     if (strcmp(cmd,"man") && strcmp(cmd, "apropos"))
  136.     {
  137.         fprintf(stderr,"Usage: man topic\nor: apropos topic\n");
  138.         exit(EX_USAGE);
  139.     }
  140.  
  141.     for (i=1; argv[i]; i++)
  142.     {
  143.         cmd=(char *)realloc(cmd,n+=strlen(argv[i])+1);
  144.         strcat(cmd," ");
  145.         strcat(cmd,argv[i]);
  146.     }
  147.  
  148.     p=MANHOST;
  149.  
  150.     if ((rem=rcmd(&p,RSHPORT,MANUSER,MANUSER,cmd,0)) < 0)
  151.     {
  152.         fprintf(stderr,"Oops... cannot connect to man server\n");
  153.         exit(EX_UNAVAILABLE);
  154.     }
  155.  
  156.     if (isatty(0) && isatty(1))
  157.     {
  158.         close(0);    dup(rem);
  159.         execl(PAGER,PAGER,0);
  160.         fprintf(stderr,"\"%s\" not found!\n",PAGER);
  161.         exit(EX_UNAVAILABLE);
  162.     }
  163.         while (read(rem,&c,1) == 1) fputc(c,stdout);
  164.     exit(0);
  165. }
  166. \Rogue\Monster\
  167. else
  168.   echo "will not over write ./rman.c"
  169. fi
  170. echo "Finished archive 1 of 1"
  171. exit
  172.  
  173.  
  174.