I wrote a program, and it wont compile, the reason is probably obvious, I havnt even coded in C in ages, I wrote this in C (or tried to) mainly because it has to run as suid root.
- Code: Select all
/*
* pppfix by John Tate
* This program checks if a ppp interface is up, if not, it kills
* some processes. This is because I often find I cannot connect
* because even after disconnection, these processes still exist
* and lock up the modem device, when I attempt to reconnect it
* hangs and never connects, or outputs an error.
*
* This Program is under the GNU General Public Licence
*/
#include <stdlib.h>
#include <stdio.h>
int checkdev(char interface[16])
{
char ifcfgpath[45]="/sbin/ifconfig";
char chkcmd[64]="";
//make a pretty string
strcpy(ifcfgpath,chkcmd);
strcat(chkcmd," ");
strcat(chkcmd,interface);
// the chkcmd string will contain somthing like "/sbin/ifconfig ppp0" now
if ( system(chkcmd) )
{
system("/usr/bin/killall /sbin/ppp-watch");
system("/usr/bin/killall pppd");
return 1;
} else {
return 0;
}
}
int main(int argc, char *argv[])
{
char interface[16];
// this should provide protection agaisnt overflowing the string and doing anything nasty
strncpy(argv[1], interface, 16);
// check if program is running as UID 0 (root)
if ( getuid() != 0 )
{
printf("pppfix: must be run as user root\n");
return 0;
}
if ( !checkdev(interface) )
{
printf("pppfix: interface %s active, no procs killed\n". interface);
return 1;
}
return 0;
}


