/* 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 #include #include #include #include #define CPULIMIT 90 #define MEMLIMIT 90 char *dontkill[] = { "", "" }; void parse_pstab(char pstab[]); void do_pstab(); int check_dontkill(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);*/ sscanf(pstab, "%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 (i < checksize_for_dontkill()) { if (strcmp(dontkill[i], name) == 0) return (0); i++; } return (1); } int checksize_for_dontkill() { int i = 0; while (1) { if (dontkill[i] != NULL) i++; else return (-1); } }