home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.0 (User) / OS_user_4.0.iso / private / etc / ppp / Examples / pppkill.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-03  |  2.1 KB  |  73 lines

  1. Many thanks to:
  2.    shess@winternet.com (Scott Hess)  
  3.    andrew_abernathy@wire.seanet.com (Andrew Abernathy)
  4.  
  5. for contributing programs that can take the place
  6. of the pppdown script.  I have included Scott Hess's 
  7. here.  If you would like to see the other program, please
  8. mail Andrew.
  9.  
  10. ======================================================================
  11.  
  12. From shess@winternet.com Mon Jan  9 02:45 EST 1995
  13. Date: Mon, 9 Jan 95 01:45 CST
  14. From: shess@winternet.com (Scott Hess)
  15. Reply-To: shess@winternet.com (Scott Hess)
  16. To: Steve Perkins <perkins@cps.msu.edu>
  17. Subject: Bringing down ppp.
  18.  
  19. [munch]
  20.  
  21. In any case, having to run pppdown as root has been annoying,
  22. because I don't like to run things as root more than necessary.
  23. In other words, more than about once a week is too often :-).  So,
  24. I wrote the following quick&dirty hack.  Basic operation is to read
  25. the pppd pid from a file where it's stored and send a SIGINT to
  26. that process.  Since there's not a shell script in sight, this
  27. should be a reasonably safe program to make setuid root.  [I'll
  28. have to think on what someone can do if they crack it or /etc/ppp
  29. and can send SIGINT to just anyone.  Perhaps it should check to
  30. see if the process is really a pppd?  Oh, well.]
  31.  
  32. howard:/tmp> ls -l /usr/local/ppp/bin/killppp 
  33.  
  34. -rwsr-sr-x  1 root        1464 Jan  7 12:41 /usr/local/ppp/bin/killppp*
  35. howard:/tmp> cat /usr/local/ppp/src/killppp.c 
  36.  
  37. #include <libc.h>
  38. #include <stdio.h>
  39.  
  40. void main( void)
  41. {
  42.     FILE *ff;
  43.     int pid;
  44.  
  45.     ff=fopen( "/etc/ppp/ppp0.pid", "r");
  46.     if( ff==NULL) {
  47.         perror( "opening ppp0.pid");
  48.         exit( 1);
  49.     }
  50.     
  51.  
  52.     if( fscanf( ff, "%d", &pid)<1) {
  53.         fprintf( stderr, "Unable to read pid from ppp0.pid\n");
  54.         exit( 1);
  55.     }
  56.     
  57.  
  58.     fclose( ff);
  59.     if( kill( pid, SIGINT)==-1) {
  60.         perror( "killing pppd");
  61.     }
  62. }
  63.  
  64. Later,
  65. ---
  66. scott hess <shess@winternet.com> (WWW to "http://www.winternet.com/~shess/")
  67. Home:   12901 Upton Avenue South, #326  Burnsville, MN 55337  (612) 895-1208
  68. Office: 101 W. Burnsville Pkwy, Suite 108E, Burnsville, MN 55337    890-1332
  69. <?If you haven't the time to design, where will you find the time to debug?>
  70.  
  71.  
  72.  
  73.