home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume5 / rman < prev    next >
Encoding:
Text File  |  1989-02-03  |  4.8 KB  |  170 lines

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