/* loginlog.c 1.0.1 Mark mark@blackplague.gmu.edu 3rd Feb 1994 */ /* Distribute freely, copyright remains with the author */ /* Compile with: cc -s -O -o loginlog loginlog.c */ /* Compiled and tested on NeXTStep 3.1 and Linux 0.99.10 */ #include #include #include #include #include #include #include #include #include #define INPUTFILE "/usr/adm/wtmp" #define NMAX sizeof(utmpbp->ut_name) #define LMAX sizeof(utmpbp->ut_line) #define HMAX sizeof(utmpbp->ut_host) char buf[256]; struct utmp *utmpbp; main(argc, argv) int argc; char **argv; { register int n; (void)close(0); if (fork()) exit(0); if (open(INPUTFILE,0)!=0) { fprintf(stderr, "lasttolog: "); perror(INPUTFILE); exit(1); } utmpbp = (struct utmp *) malloc(sizeof(struct utmp)); (void) openlog(argv[0], LOG_NDELAY, LOG_AUTH); /* syslog(LOG_ALERT, "running"); */ (void)lseek(0,(off_t)0,L_XTND); /* seek to end */ for (;;) { /* sit here and wait for people to log in */ sleep(10); while ((n = read (0, utmpbp, sizeof(struct utmp))) > 0) { if (strncmp(utmpbp->ut_name, "", NMAX)) { sprintf(buf, "%-*.*s %-*.*s %-*.*s", NMAX, NMAX, utmpbp->ut_name, 8, 8, utmpbp->ut_line, HMAX, HMAX, utmpbp->ut_host); syslog(LOG_ALERT, buf); } } } }