Project

General

Profile

Bug #2783 ยป dumputmp.c

Gary Mills, 2012-11-13 04:33 PM

 
1
/* dumputmp.c: dump the utmpx file */
2

    
3
#include <sys/types.h>
4
#include <sys/time.h>
5
#include <stdlib.h>
6
#include <utmpx.h>
7
#include <string.h>
8
#include <stdio.h>
9

    
10
char *types[] = {
11
    "EMPTY",
12
    "RUN_LVL",
13
    "BOOT_TIME",
14
    "OLD_TIME",
15
    "NEW_TIME",
16
    "INIT_PROCESS",
17
    "LOGIN_PROCESS",
18
    "USER_PROCESS",
19
    "DEAD_PROCESS",
20
    "ACCOUNTING",
21
    "DOWN_TIME",
22
};
23

    
24
#define TYPES (sizeof (types) / sizeof (char *))
25

    
26
int main(int argc, char *argv[]) {
27
    struct utmpx	*ut;
28
    char		*utmp_file;
29
    char		buf[5];
30

    
31
    if ( argc > 1 ) utmp_file = argv[1];
32
    else utmp_file = UTMPX_FILE;
33

    
34
    (void) printf("Entry size: %d\n", sizeof(struct utmpx)); 
35

    
36
    buf[4] = '\0';
37
    utmpxname (utmp_file);
38
    setutxent ();
39
    while ( (ut = getutxent()) ) {
40
        char *ct, *ty;
41

    
42
	(void)memcpy(buf, ut->ut_id, 4);
43
	ct = ctime(&ut->ut_xtime);
44
	ty = (ut->ut_type <= TYPES) ? types[ut->ut_type] : "UNKNOWN" ;
45
	(void)printf("User: %s, Id: %s, Line: %s, Pid: %d, Type: %s, Exit: %d/%d, Time: %10.10s %5.5s, Host: %s\n",
46
		     ut->ut_user, buf, ut->ut_line, ut->ut_pid, ty,
47
		     ut->ut_exit.e_termination, ut->ut_exit.e_exit,
48
		     ct, ct + 11, ut->ut_host);
49
    }
50

    
51
    exit(0);
52
}
53

    
54
/**/
    (1-1/1)