X-Git-Url: https://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=NeXT%2FExamples%2Fpppkill.c;fp=NeXT%2FExamples%2Fpppkill.c;h=932eaca2c879c3cc981946f4b29774d3f50f7122;hp=0000000000000000000000000000000000000000;hb=b5c0cf380b11e37f580e6f2affcb78d5ccedade0;hpb=c178bf94c8aa2e30d3934dde8b5371d05ad41f7e diff --git a/NeXT/Examples/pppkill.c b/NeXT/Examples/pppkill.c new file mode 100644 index 0000000..932eaca --- /dev/null +++ b/NeXT/Examples/pppkill.c @@ -0,0 +1,90 @@ +Many thanks to: + shess@winternet.com (Scott Hess) + andrew_abernathy@wire.seanet.com (Andrew Abernathy) + michal@ellpspace.math.ualberta.ca (Michal Jaegermann) + +for contributing programs that can take the place +of the pppdown script. I have included Scott Hess's +(now modified) here. If you would like to see the other program, please +mail Andrew. + +====================================================================== + +From shess@winternet.com Mon Jan 9 02:45 EST 1995 +Date: Mon, 9 Jan 95 01:45 CST +From: shess@winternet.com (Scott Hess) +Reply-To: shess@winternet.com (Scott Hess) +To: Steve Perkins +Subject: Bringing down ppp. + +[munch] + +In any case, having to run pppdown as root has been annoying, +because I don't like to run things as root more than necessary. +In other words, more than about once a week is too often :-). So, +I wrote the following quick&dirty hack. Basic operation is to read +the pppd pid from a file where it's stored and send a SIGINT to +that process. Since there's not a shell script in sight, this +should be a reasonably safe program to make setuid root. [I'll +have to think on what someone can do if they crack it or /etc/ppp +and can send SIGINT to just anyone. Perhaps it should check to +see if the process is really a pppd? Oh, well.] + +howard:/tmp> ls -l /usr/local/ppp/bin/killppp + +-rwsr-sr-x 1 root 1464 Jan 7 12:41 /usr/local/ppp/bin/killppp* +howard:/tmp> cat /usr/local/ppp/src/killppp.c + +/* + * Originally written by Scott Hess + * and later modified by Michal Jaegermann + */ + +#include +#include + + +#include +#include + +#define PIDF "/etc/ppp/ppp0.pid" + +int +main( void) +{ + FILE *ff; + int pid; + + + if( NULL == (ff = fopen( PIDF, "r"))) { + perror( "opening " PIDF + "\nppp0 link does not seem to be active" ); + exit(1); + } + + + if( fscanf( ff, "%d", &pid)<1) { + fprintf( stderr, "Cannot read pid from" PIDF "\n"); + exit(1); + } + + + fclose( ff); + if( kill( pid, SIGINT)==-1) { + perror( "killing pppd"); + fprintf( stderr, "removing stale" PIDF "file\n"); + if (0 != unlink( PIDF)) { + perror("cannot remove" PIDF); + } + exit(1); + } + return 0; +} + +Later, +--- +scott hess (WWW to "http://www.winternet.com/~shess/") +Home: 12901 Upton Avenue South, #326 Burnsville, MN 55337 (612) 895-1208 +Office: 101 W. Burnsville Pkwy, Suite 108E, Burnsville, MN 55337 890-1332 + +