home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3875 < prev    next >
Encoding:
Text File  |  1991-08-22  |  2.0 KB  |  57 lines

  1. Xref: wupost alt.sex.pictures.d:6819 alt.sources:3875
  2. Path: wupost!uunet!lll-winken!sun-barr!cronkite.Central.Sun.COM!exodus!athena.Eng.Sun.COM!williamt
  3. From: williamt@athena.Eng.Sun.COM (William Turnbow)
  4. Newsgroups: alt.sex.pictures.d,alt.sources
  5. Subject: ftp limit source
  6. Message-ID: <18815@exodus.Eng.Sun.COM>
  7. Date: 22 Aug 91 00:00:30 GMT
  8. Sender: news@exodus.Eng.Sun.COM
  9. Reply-To: williamt@athena.Eng.sun.com (William Turnbow)
  10. Followup-To: alt.sex.pictures.d
  11. Lines: 44
  12.  
  13.  
  14.     Don't know if this is of any use to anyone.  It's just something I
  15. cooked up on short notice and it seems to work, but there is no warrantee
  16. expressed or implied...etc.
  17.  
  18.     I renamed the ftp demon (in.ftpd) to in.ftpd.2, and put the program
  19. below in its place.  I am running under SunOS 4.1, a BSD variant, so
  20. your path for wc and args to ps may be different.  But the program is
  21. sufficiently short and simple that it should be easily modifiable.
  22.  
  23.  
  24. /* ftp limit demon -- limits ftp connections
  25.  * author: William.Turnbow@Sun.COM
  26.  */
  27.  
  28. #include <stdio.h>
  29. main(argc,argv)
  30.     int argc; char * argv[];
  31. {
  32.     int maxusers;
  33.     int nusers;                      
  34.                                      
  35.     if (argc>1) maxusers=atoi(argv[1]); /* any errors means 0 users get in */ 
  36.     else maxusers=1;    /* default = 1 here */ 
  37.                                                                                     /* get number of ftp demons running:  
  38.         ps for all process,          
  39.         only look for ftpd (demons),
  40.         filter out the grep that did the looking, and
  41.         do a line count
  42.     */   
  43.     
  44.     nusers=system("a=`ps x|grep ftpd|grep -v grep |/usr/ucb/wc -l`;exit $a")>>8;     
  45.     /* if under limit, do the real ftp demon */    
  46.     if (nusers<=maxusers) execl("/usr/etc/in.ftpd.2","/usr/etc/in.ftpd",0);
  47.     else {       
  48.         /* too many users: bye bye */ 
  49.         fprintf(stderr,"Too many users.  Sorry, try again later.\n");
  50.         exit(0); 
  51.     }
  52. }
  53. --
  54.  
  55. Help!  I've tripped and I can't get down!
  56.                                    -- Bumper sticker at Eel River Jerry Show
  57.