home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / vmsnet / networks / tcpip / multinet / 2364 < prev    next >
Encoding:
Text File  |  1992-11-17  |  6.2 KB  |  177 lines

  1. Path: sparky!uunet!stanford.edu!agate!spool.mu.edu!uwm.edu!zaphod.mps.ohio-state.edu!wupost!sdd.hp.com!caen!sol.ctr.columbia.edu!hamblin.math.byu.edu!arizona.edu!carat.arizona.edu!jms
  2. Newsgroups: vmsnet.networks.tcp-ip.multinet
  3. Subject: Re: Finger
  4. Message-ID: <17NOV199211474748@carat.arizona.edu>
  5. From: jms@carat.arizona.edu (A virtually vegetal non-entity)
  6. Date: 17 Nov 1992 11:47 MST  
  7. Reply-To: jms@Arizona.EDU
  8. References: <1992Nov16.133456.9310@abo.fi> <Keith.W.Johnson.22.721965538@tek.com> <1992Nov17.071012.8426@abo.fi>
  9. Distribution: world,local
  10. Organization: University of Arizona MIS Department - Mosaic Group
  11. Nntp-Posting-Host: carat0.mis.arizona.edu
  12. X-Lunar-Date: 5 days, 21 hours, 3 minutes since the full moon
  13. News-Software: VAX/VMS VNEWS 1.50A   
  14. Lines: 161
  15.  
  16. I guess it all depends on what you want Finger to do for people.  On one
  17. system I managed, we felt that the information that finger gave out was a
  18. little too intrusive, and so I re-wrote finger to do the equivalent of a
  19. "show users/full" and pass that back over the pipe.  I think it was about a
  20. hundred lines of code.
  21.  
  22. On my system at home, the link is slow, so I want to discourage people from
  23. fingering (especially since it doesn't tell them anything).  After
  24. encountering a system manager who thought that security management meant
  25. fingering every single system around every ten minutes, I wrote "JFINGER,"
  26. which responds to finger requests by randomly picking a host from a list
  27. of systems (generated from the multi-thousand HOSTS.TXT NIC tables),
  28. fingering THAT host, and sending that data back.  
  29.  
  30. Ehud Gavron enhanced JFINGER two ways: one is to reply to fingers with
  31. fingers of the fingerers own machine (read that one slowly, eh), and the
  32. other is to hang forever on fingers from certain machines, which is a
  33. strong discouragement to the folks on those machines from fingering you
  34. at all.
  35.  
  36. Anyway: code below, for anyone interested. 
  37.  
  38. Joel M Snyder, 1103 E Spring Street, Tucson, AZ, 85719 
  39. Phone: 602.882.4094 (voice) .4095 (FAX) .4093 (data)
  40. BITNET: jms@Arizona  Internet: jms@arizona.edu  SPAN: 47541::telcom::jms
  41. Yow!  I want my nose in lights!
  42.  
  43. /* JFINGER - replaces a FINGER server for Multinet; returns random answers */
  44.  
  45. /* This code is placed into the public domain. jms/920703 */
  46.  
  47. /* Modified:
  48.     04-Jul-1992    Ehud Gavron    If SELF is defined, then this will
  49.                     finger the fingeree instead of a
  50.             random host from a randomly unavailable file ;-) 
  51.  
  52.     12-Oct-1992    Ehud Gavron    The folks at bruno.cs.colorado.edu
  53.                     insist on fingering me several times
  54.             a day in the hopes I would create a wide area 
  55.             information server all of a sudden.  Although I have
  56.             asked them nicely, they don't want to take my host
  57.             out of their pinging tables.  This little addition,
  58.             activated by  /DEFINE=(SELF,FUCKTHEM) makes Jfinger
  59.             hang on the read.  Note: successive fingerings by
  60.             them will cause one of the machines to run out of
  61.             TCBs or process slots first.  I suspect it won't
  62.             be me.  However, if it turns out it's me, I can
  63.             always modify the code so ONE connection from them
  64.             turns into 32767 sockets coming right back at them :) */
  65.  
  66.  
  67. #include <stdio.h>
  68. #ifndef SELF
  69. #include <time.h>
  70. #endif
  71. #include <descrip.h>
  72. #include "multinet_root:[multinet.include.sys]types.h"
  73. #include "multinet_root:[multinet.include.sys]socket.h"
  74. #include "multinet_root:[multinet.include.netinet]in.h"
  75. #include "multinet_root:[multinet.include]netdb.h"
  76.  
  77. main()
  78. {
  79.     unsigned int seed, random, n, status;
  80.     unsigned short lchan, rchan;    
  81.     time_t now;
  82.     struct tm *tptr;    
  83.     FILE *hostfile;
  84.     char ahost[25], buf[256];
  85.     static struct {int Size; char *Ptr;} Descr={9 ,"SYS$INPUT"};
  86.     struct servent *sp;
  87. #ifdef    FUCKTHEM
  88.     struct hostent *hp;
  89. #endif
  90.     struct sockaddr_in sin;
  91.  
  92. /*
  93.  * Open up the LOCAL finger channel.  That's the one coming in to
  94.  * us.  Read the record that the other end sent, and promptly ignore it.
  95.  */
  96.     status = SYS$ASSIGN(&Descr, &lchan, 0, 0);
  97.     if (!(status&1)) return(status);
  98. #ifdef SELF
  99.     getpeername(lchan,&sin,&sizeof(sin));
  100. #ifndef FUCKTHEM
  101.     socket_read(lchan, buf, sizeof(buf));
  102. #endif
  103.     hp = gethostbyaddr(&sin.sin_addr, sizeof(sin.sin_addr), AF_INET);
  104.     if (0 == strcmp((char *)hp->h_name,"bruno.cs.colorado.edu")) {
  105.         for (;;);
  106.     }
  107. #else
  108. /*
  109.  * Seed our random number generator and generate a random number between
  110.  * 0 and 65535 (by throwing out the high 16 bits)
  111.  */
  112.     time(&now);
  113.     tptr = localtime(&now);
  114.     seed = tptr->tm_sec + tptr->tm_min + tptr->tm_hour + 
  115.             tptr->tm_mday + tptr->tm_mon;
  116.     srand(seed);
  117.     random = (unsigned short int) rand();
  118.     
  119. /*
  120.  * Open up a list of hosts which return something when you finger them.
  121.  * Then seek to a random byte location in the file.  Get the record
  122.  * which remains, and throw it out.  Then get the next record, which
  123.  * will be a full record.  NOTE: This only works with stream_lf files.
  124.  * Other VMS file formats probably will cause this to blow up. YOU
  125.  * HAVE BEEN WARNED!
  126.  */
  127.     hostfile = fopen("multinet:hosts.finger","r");
  128.  
  129.     fseek(hostfile,random,0);
  130.     fgets (&ahost[0], 24, hostfile);
  131.     fgets (&ahost[0], 24, hostfile);
  132.  
  133. /*
  134.  * Here we get into serious code theft.  Get the address, convert it
  135.  * into a canonical internet address and stick it into the official
  136.  * socket structure.  Open up a socket to the remote host and call
  137.  * it RCHAN. 
  138.  */
  139.     strcpy(buf, &ahost[0]);
  140.     sin.sin_addr.s_addr = inet_addr(buf);
  141.     if (sin.sin_addr.s_addr == -1) return(-1);
  142. #endif
  143.     rchan = socket(AF_INET, SOCK_STREAM, 0);
  144.     if (rchan < 0) return;
  145.  
  146. /*
  147.  * Bind the socket to the appropriate port (I could have hardwired
  148.  * this, but the code I stole did it so beautifully, I didn't screw with
  149.  * it.  Except, of course, to delete all the nice error checking.) Then
  150.  * connect to the socket. 
  151.  */
  152.     sp = getservbyname("finger", "tcp");
  153.     if (sp == NULL) return;
  154.     sin.sin_port = sp->s_port;
  155.     sin.sin_family = AF_INET;
  156.     if (connect(rchan, &sin, sizeof (sin), 0) < 0) return;
  157.  
  158. /*
  159.  * Give the remote guy a "finger all" command by sending a blank
  160.  * line.  
  161.  */
  162.     strcpy(buf,"\r\n\000");
  163.     socket_write(rchan, buf, strlen(buf));
  164.  
  165. /*
  166.  * While he has something to say, read it, and then write it right
  167.  * back out to the local channel.  When he's done, we're done, and
  168.  * give it up.
  169.  */
  170.     while ((n = socket_read(rchan, buf, 255)) > 0) {
  171.         buf[n] = '\0';
  172.         socket_write(lchan, buf, strlen(buf));
  173.     }
  174.  
  175.     return;
  176. }
  177.