home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / unix / bsd / 10851 < prev    next >
Encoding:
Text File  |  1993-01-02  |  10.5 KB  |  254 lines

  1. Newsgroups: comp.unix.bsd
  2. Path: sparky!uunet!spool.mu.edu!agate!dog.ee.lbl.gov!hellgate.utah.edu!fcom.cc.utah.edu!cs.weber.edu!terry
  3. From: terry@cs.weber.edu (A Wizard of Earth C)
  4. Subject: Re: 386BSD - Network services w/ 2 ethernet boards
  5. Message-ID: <1993Jan3.003955.14569@fcom.cc.utah.edu>
  6. Sender: news@fcom.cc.utah.edu
  7. Organization: Weber State University  (Ogden, UT)
  8. References: <C08r81.3qJ@moxie.hou.tx.us>
  9. Date: Sun, 3 Jan 93 00:39:55 GMT
  10. Lines: 242
  11.  
  12. In article <C08r81.3qJ@moxie.hou.tx.us> hackney@moxie.hou.tx.us (Greg Hackney) writes:
  13. >
  14. >I have a 386BSD machine with 2 ethernet boards to different network
  15. >segments. The kernel is compiled with the "GATEWAY" option.
  16. >
  17. >Is there a way to activate some inetd network services for one board,
  18. >but not for the other?
  19.  
  20. The easiest way I have found is to hack inetd itself and the inetd.conf file.
  21.  
  22. Basically the hack is applicable only to stream tcp nowait services, due to
  23. the fact that wait services daemons handle all future connection requests,
  24. non-stream  services aren't tcp, and non-connection oriented services do
  25. not have sufficient information to determine the local socket number, since
  26. the connection dies after delivery (although one could conceivably hack the
  27. changes into the code following the recvfrom() calls and use that information,
  28. the local socket information isn't fixed.  This might require a router hack.
  29.  
  30.  
  31. The following hack description assumes the socket type to be Internet; no
  32. other protocols are supported.
  33.  
  34. The lack of support for the standard regular expression mechanisms means
  35. that I can only give comments as pseudo-code for the actual pattern matching
  36. itself (Sorry; I didn't do the hack for 386BSD in the first place).
  37.  
  38. If you fill out the code in the comment-only section (--- 282,326 ----),
  39. this should work for you.
  40.  
  41.  
  42. ]#
  43. ]# Internet server configuration database
  44. ]#
  45. ]#       @(#)inetd.conf  5.4 (Berkeley) 6/30/90
  46. ]#
  47. ]ftp     stream  tcp     nowait  root    /usr/libexec/ftpd       ftpd -l
  48. ]telnet  stream  tcp     nowait  root    /usr/libexec/telnetd    telnetd
  49. ]shell   stream  tcp     nowait  root    /usr/libexec/rshd       rshd
  50. ]login   stream  tcp     nowait  root    /usr/libexec/rlogind    rlogind
  51. ]exec    stream  tcp     nowait  root    /usr/libexec/rexecd     rexecd
  52. ]#uucpd  stream  tcp     nowait  root    /usr/libexec/uucpd      uucpd
  53. ]#nntp   stream  tcp     nowait  usenet  /usr/libexec/nntpd      nntpd
  54. ]finger  stream  tcp     nowait  nobody  /usr/libexec/fingerd    fingerd
  55. ].
  56. ].
  57. ].
  58.  
  59. Becomes:
  60.  
  61. ]#
  62. ]# Internet server configuration database
  63. ]#
  64. ]#       @(#)inetd.conf  5.4 (Berkeley) 6/30/90
  65. ]#
  66. ]# Our trusted net is 128.89; our external net is 136.120.  We allow ftp,
  67. ]# telnet, and nntp externally (our fire wall provides news service for
  68. ]# external sites, telnet for the BBS, and ftp for the source archives).
  69. ]# Users on the trusted net have access to all services except nntp, which
  70. ]# is handled by an internal machine named news.cs.example.edu to reduce
  71. ]# loading on the gateway.
  72. ]#
  73. ]ftp     stream tcp nowait root   *       /usr/libexec/ftpd       ftpd -l
  74. ]telnet  stream tcp nowait root   *       /usr/libexec/telnetd    telnetd
  75. ]shell   stream tcp nowait root   128.89  /usr/libexec/rshd       rshd
  76. ]login   stream tcp nowait root   128.89  /usr/libexec/rlogind    rlogind
  77. ]exec    stream tcp nowait root   128.89  /usr/libexec/rexecd     rexecd
  78. ]#uucpd  stream tcp nowait root   *       /usr/libexec/uucpd      uucpd
  79. ]nntp   stream tcp nowait usenet  136.120 /usr/libexec/nntpd      nntpd
  80. ]finger  stream tcp nowait nobody 128.89  /usr/libexec/fingerd    fingerd
  81. ].
  82. ].
  83. ].
  84.  
  85. in /usr/src/usr.sbin/inetd/inetd.c, the changes look like this:
  86.  
  87. ------ 8< ------ 8< ------ 8< ------ 8< ------ 8< ------ 8< ------ 8< ------
  88. *** inetd.c     Mon Jun  3 21:25:23 1991
  89. --- inetd.c.new Sat Jan  2 18:20:13 1993
  90. ***************
  91. *** 29,34 ****
  92. --- 29,36 ----
  93.    * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  94.    * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  95.    * SUCH DAMAGE.
  96. +  *
  97. +  * 02 Jan 93  Terry Lambert           Added GATEMOD compilation option
  98.    */
  99.  
  100.   #ifndef lint
  101. ***************
  102. *** 123,128 ****
  103. --- 125,133 ----
  104.         short   se_wait;                /* single threaded server */
  105.         short   se_checked;             /* looked at during merge */
  106.         char    *se_user;               /* user name to run as */
  107. + #ifdef GATEMOD
  108. +       char    *se_restict;            /* interface restriction*/
  109. + #endif        /* GATEMOD*/
  110.         struct  biltin *se_bi;          /* if built-in, description */
  111.         char    *se_server;             /* server program */
  112.   #define       MAXARGV 20
  113. ***************
  114. *** 184,189 ****
  115. --- 189,198 ----
  116.         struct sigvec sv;
  117.         int ch, pid, dofork;
  118.         char buf[50];
  119. + #ifdef GATEMOD
  120. +       struct sockaddr_in      inaddr;         /* for socket comparison*/
  121. +       int                     inaddrsz = sizeof( struct sockaddr_in);
  122. + #endif        /* !GATEMOD*/
  123.  
  124.         Argv = argv;
  125.         if (envp == 0 || *envp == 0)
  126. ***************
  127. *** 256,263 ****
  128. --- 265,278 ----
  129.                             fprintf(stderr, "someone wants %s\n",
  130.                                 sep->se_service);
  131.                     if (sep->se_socktype == SOCK_STREAM) {
  132. + #ifdef GATEMOD
  133. +                           ctrl = accept(sep->se_fd,
  134. +                                         (struct sockaddr *)&inaddr,
  135. +                                         &inaddrsz);
  136. + #else /* !GATEMOD*/
  137.                             ctrl = accept(sep->se_fd, (struct sockaddr *)0,
  138.                                 (int *)0);
  139. + #endif        /* !GATEMOD*/
  140.                             if (debug)
  141.                                     fprintf(stderr, "accept, ctrl %d\n", ctrl);
  142.                             if (ctrl < 0) {
  143. ***************
  144. *** 267,272 ****
  145. --- 282,326 ----
  146.                                             sep->se_service);
  147.                                     continue;
  148.                             }
  149. + #ifdef GATEMOD
  150. +                           /* if there is a restriction...*/
  151. +                           if( strcmp( sep->se_restrict, "*") {
  152. +                               /*
  153. +                                * look up the address of the local side
  154. +                                * to determine which interface it came in
  155. +                                * from.
  156. +                                */
  157. +
  158. +                               /*
  159. +                                * read from the symbol _tcpstat out of the
  160. +                                * kernel to get the local/remote socket
  161. +                                * pairs; basically, we are interested in
  162. +                                * the local address part, and not the state,
  163. +                                * so all we have to read is the inpcb's.
  164. +                                * These are in a circular list, with a
  165. +                                * NULL entry as a list marker with it's
  166. +                                * inp_next pointing to the symbol offset
  167. +                                * for _tcpstat in the kvm; once we kvm_read()
  168. +                                * this record, we are done with the list.
  169. +                                *
  170. +                                * For each inpcb.inp_fport, check the socket
  171. +                                * number against the socket we got in the
  172. +                                * accept.  If it matches, check the value of
  173. +                                * inpcb.inp_laddr against the restriction
  174. +                                * pattern; if it doesn't match, drop the
  175. +                                * connection (close()) and go to the next
  176. +                                * event (continue;).
  177. +                                *
  178. +                                * There is a great deal of lattitude here
  179. +                                * for multiple patterns seperated by commas,
  180. +                                * etc. when doing the pattern match.  You
  181. +                                * can choose to implement matching against
  182. +                                * a list of addresses or whatever.  386BSD
  183. +                                * doesn't support the re_* routines, so my
  184. +                                * code won't work for this on 386BSD.
  185. +                                */
  186. +                           }
  187. + #endif        /* GATEMOD*/
  188.                     } else
  189.                             ctrl = sep->se_fd;
  190.                     (void) sigblock(SIGBLOCK);
  191. ***************
  192. *** 604,609 ****
  193. --- 658,667 ----
  194.         arg = skip(&cp);
  195.         sep->se_wait = strcmp(arg, "wait") == 0;
  196.         sep->se_user = newstr(skip(&cp));
  197. + #ifdef GATEMOD
  198. +       /* local address use restrictions (for fire wall gateways)*/
  199. +       sep->se_restrict = newstr(skip(&cp));
  200. + #endif        /* GATEMOD*/
  201.         sep->se_server = newstr(skip(&cp));
  202.         if (strcmp(sep->se_server, "internal") == 0) {
  203.                 register struct biltin *bi;
  204. ***************
  205. *** 641,646 ****
  206. --- 699,709 ----
  207.                 free(cp->se_proto);
  208.         if (cp->se_user)
  209.                 free(cp->se_user);
  210. + #ifdef GATEMOD
  211. +       /* local address use restrictions (for fire wall gateways)*/
  212. +       if (cp->se_restrict)
  213. +               free(cp->se_restrict);
  214. + #endif        /* GATEMOD*/
  215.         if (cp->se_server)
  216.                 free(cp->se_server);
  217.         for (i = 0; i < MAXARGV; i++)
  218. ***************
  219. *** 957,964 ****
  220. --- 1020,1034 ----
  221.         char *action;
  222.         struct servtab *sep;
  223.   {
  224. + #ifdef GATEMOD
  225. +       fprintf(stderr,
  226. +           "%s: %s proto=%s, wait=%d, user=%s restrict=%s builtin=%x server=%s\
  227. n",
  228. +           action, sep->se_service, sep->se_proto, sep->se_wait,
  229. +           sep->se_user, sep->se_restrict, (int)sep->se_bi, sep->se_server);
  230. + #else /* !GATEMOD*/
  231.         fprintf(stderr,
  232.             "%s: %s proto=%s, wait=%d, user=%s builtin=%x server=%s\n",
  233.             action, sep->se_service, sep->se_proto,
  234.             sep->se_wait, sep->se_user, (int)sep->se_bi, sep->se_server);
  235. + #endif        /* !GATEMOD*/
  236.   }
  237. ------ 8< ------ 8< ------ 8< ------ 8< ------ 8< ------ 8< ------ 8< ------
  238.  
  239. Remember, this code won't run as is!  DON'T apply the patch unless you are
  240. ready to change the globbing and write the KVM reading routines.
  241.  
  242.  
  243.                     Terry Lambert
  244.                     terry@icarus.weber.edu
  245.                     terry_lambert@novell.com
  246. ---
  247. Any opinions in this posting are my own and not those of my present
  248. or previous employers.
  249. -- 
  250. -------------------------------------------------------------------------------
  251.                                         "I have an 8 user poetic license" - me
  252.  Get the 386bsd FAQ from agate.berkeley.edu:/pub/386BSD/386bsd-0.1/unofficial
  253. -------------------------------------------------------------------------------
  254.