Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 2 | /* |
| 3 | * public domain -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com> |
| 4 | * |
| 5 | * dutmp |
| 6 | * Takes utmp formated file on stdin and dumps it's contents |
| 7 | * out in colon delimited fields. Easy to 'cut' for shell based |
| 8 | * versions of 'who', 'last', etc. IP Addr is output in hex, |
| 9 | * little endian on x86. |
| 10 | * |
| 11 | * made against libc6 |
| 12 | */ |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame] | 13 | |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 14 | #include "internal.h" |
| 15 | #include <stdio.h> |
Erik Andersen | 61677fe | 2000-04-13 01:18:56 +0000 | [diff] [blame] | 16 | #include <errno.h> |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 17 | #include <utmp.h> |
Erik Andersen | 61677fe | 2000-04-13 01:18:56 +0000 | [diff] [blame] | 18 | #define BB_DECLARE_EXTERN |
| 19 | #define bb_need_io_error |
| 20 | #include "messages.c" |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 21 | |
Erik Andersen | 9cf3bfa | 2000-04-13 18:49:43 +0000 | [diff] [blame] | 22 | static const char dutmp_usage[] = "dutmp [FILE]\n\n" |
| 23 | "Dump utmp file format (pipe delimited) from FILE\n" |
| 24 | "or stdin to stdout. (i.e. 'dutmp /var/run/utmp')\n"; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 25 | |
| 26 | extern int dutmp_main(int argc, char **argv) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 27 | { |
| 28 | |
Erik Andersen | 61677fe | 2000-04-13 01:18:56 +0000 | [diff] [blame] | 29 | FILE *f; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 30 | struct utmp ut; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 31 | |
Erik Andersen | 61677fe | 2000-04-13 01:18:56 +0000 | [diff] [blame] | 32 | if (argc<2) { |
| 33 | f = stdin; |
| 34 | } else if (*argv[1] == '-' ) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 35 | usage(dutmp_usage); |
Erik Andersen | 61677fe | 2000-04-13 01:18:56 +0000 | [diff] [blame] | 36 | } else { |
| 37 | f = fopen(argv[1], "r"); |
| 38 | if (f == NULL) { |
| 39 | fatalError(io_error, argv[1], strerror(errno)); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 40 | } |
| 41 | } |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 42 | |
Erik Andersen | 61677fe | 2000-04-13 01:18:56 +0000 | [diff] [blame] | 43 | while (fread(&ut, sizeof(struct utmp), 1, f)) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 44 | printf("%d|%d|%s|%s|%s|%s|%d|%d|%ld|%ld|%ld|%x\n", |
| 45 | ut.ut_type, ut.ut_pid, ut.ut_line, |
| 46 | ut.ut_id, ut.ut_user, ut.ut_host, |
| 47 | ut.ut_exit.e_termination, ut.ut_exit.e_exit, |
| 48 | ut.ut_session, |
| 49 | ut.ut_tv.tv_sec, ut.ut_tv.tv_usec, ut.ut_addr); |
| 50 | } |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame] | 51 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 52 | exit(TRUE); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 53 | } |