aboutsummaryrefslogtreecommitdiff
path: root/miscutils/dutmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'miscutils/dutmp.c')
-rw-r--r--miscutils/dutmp.c66
1 files changed, 0 insertions, 66 deletions
diff --git a/miscutils/dutmp.c b/miscutils/dutmp.c
deleted file mode 100644
index 86d7ce4b3..000000000
--- a/miscutils/dutmp.c
+++ /dev/null
@@ -1,66 +0,0 @@
1/* vi: set sw=4 ts=4: */
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 */
12
13/* Mar 13, 2003 Manuel Novoa III
14 *
15 * 1) Added proper error checking.
16 * 2) Allow '-' arg for stdin.
17 * 3) For modern libcs, take into account that utmp char[] members
18 * need not be nul-terminated.
19 */
20
21#include <stdlib.h>
22#include <unistd.h>
23#include <fcntl.h>
24#include <utmp.h>
25#include "busybox.h"
26
27/* Grr... utmp char[] members do not have to be nul-terminated.
28 * Do what we can while still keeping this reasonably small.
29 * Note: We are assuming the ut_id[] size is fixed at 4. */
30
31#if (UT_LINESIZE != 32) || (UT_NAMESIZE != 32) || (UT_HOSTSIZE != 256)
32#error struct utmp member char[] size(s) have changed!
33#endif
34
35extern int dutmp_main(int argc, char **argv)
36{
37 int file = STDIN_FILENO;
38 ssize_t n;
39 struct utmp ut;
40
41 if (argc > 2) {
42 bb_show_usage();
43 }
44 ++argv;
45 if ((argc == 2) && ((argv[0][0] != '-') || argv[0][1])) {
46 file = bb_xopen(*argv, O_RDONLY);
47 }
48
49
50 while ((n = safe_read(file, (void*)&ut, sizeof(struct utmp))) != 0) {
51
52 if (n != sizeof(struct utmp)) {
53 bb_perror_msg_and_die("short read");
54 }
55
56 bb_printf("%d|%d|%.32s|%.4s|%.32s|%.256s|%d|%d|%ld|%ld|%ld|%x\n",
57 ut.ut_type, ut.ut_pid, ut.ut_line,
58 ut.ut_id, ut.ut_user, ut.ut_host,
59 ut.ut_exit.e_termination, ut.ut_exit.e_exit,
60 ut.ut_session,
61 ut.ut_tv.tv_sec, ut.ut_tv.tv_usec,
62 ut.ut_addr);
63 }
64
65 bb_fflush_stdout_and_exit(EXIT_SUCCESS);
66}