File: utmpdump.c.OLD

package info (click to toggle)
sysvinit 2.86.ds1-38+etchnhalf.1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 1,268 kB
  • ctags: 655
  • sloc: ansic: 7,385; sh: 4,736; makefile: 405; perl: 244
file content (61 lines) | stat: -rw-r--r-- 1,421 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * utmpdump	Simple program to dump UTMP and WTMP files in
 *		raw format, so they can be examined.
 *
 * Version:	@(#)utmpdump.c  13-Aug-1996  1.00  miquels@cistron.nl
 *
 *		This file is part of the sysvinit suite,
 *		Copyright 1991-1996 Miquel van Smoorenburg.
 *
 *		This program is free software; you can redistribute it and/or
 *		modify it under the terms of the GNU General Public License
 *		as published by the Free Software Foundation; either version
 *		2 of the License, or (at your option) any later version.
 */

#include <stdio.h>
#include <utmp.h>
#include <time.h>

void dump(fp)
FILE *fp;
{
  struct utmp ut;
  int f;
  time_t tm;

  while (fread(&ut, sizeof(struct utmp), 1, fp) == 1) {
	for(f = 0; f < 12; f++) if (ut.ut_line[f] == ' ') ut.ut_line[f] = '_';
	for(f = 0; f <  8; f++) if (ut.ut_name[f] == ' ') ut.ut_name[f] = '_';
	tm = ut.ut_time;
	printf("[%d] [%05d] [%-4.4s] [%-8.8s] [%-12.12s] [%-15.15s]\n",
		ut.ut_type, ut.ut_pid, ut.ut_id, ut.ut_user,
		ut.ut_line, 4 + ctime(&tm));
  }
}

int main(argc, argv)
int argc;
char **argv;
{
  int f;
  FILE *fp;

  if (argc < 2) {
	argc = 2;
	argv[1] = UTMP_FILE;
  }

  for(f = 1; f < argc; f++) {
	if (strcmp(argv[f], "-") == 0) {
		printf("Utmp dump of stdin\n");
		dump(stdin);
	} else if ((fp = fopen(argv[f], "r")) != NULL) {
		printf("Utmp dump of %s\n", argv[f]);
		dump(fp);
		fclose(fp);
	} else
		perror(argv[f]);
  }
  return(0);
}