File: sac.h

package info (click to toggle)
sac 1.9b5-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 300 kB
  • ctags: 450
  • sloc: ansic: 3,696; sh: 203; makefile: 120
file content (248 lines) | stat: -rw-r--r-- 6,358 bytes parent folder | download | duplicates (2)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/* $Copyright: $
 * Copyright (c) 1995 - 2001 by Steve Baker (ice@mama.indstate.edu)
 * All Rights reserved
 *
 * This software is provided as is without any express or implied
 * warranties, including, without limitation, the implied warranties
 * of merchant-ability and fitness for a particular purpose.
 */

#include <sys/types.h>
#include <sys/time.h>
#include <time.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <dirent.h>
#include <errno.h>
#include <sys/wait.h>

#include "utmp.h"

#define scopy(s)	(strcpy(bmalloc(strlen(s)+1),s))
#define min(a,b)	((a) < (b) ? (a) : (b))
#define max(a,b)	((a) > (b) ? (a) : (b))

/* This will break if someone has an 89 year old wtmp  =) */
#define MINUSZERO	-32767		/* HACK ALERT!! */
#define PLUSZERO	+32767		/* HACK ALERT!! */

#define BUFSIZE		1024

enum {
  TOTAL	  = 0x0001,	/* Total login time */
  DAY     = 0x0002,	/* Daily average */
  USER    = 0x0003,	/* Per user login time */
  TTY     = 0x0004,	/* Show usage / tty */
  RAW	  = 0x0005,	/* Show everything */
  SIMUSE  = 0x0006,	/* Simultaneous tty usage */

  AVERAGE = 0x0010,	/* Average login time / login */
  HOUR    = 0x0020,	/* Hourly profile */
  CLIP	  = 0x0040,	/* Multiple logins during same time count only once */
  MINMAX  = 0x0080,	/* Show min max # logins at one time */
  LOGIN	  = 0x0100,	/* Display login breakdown */
  IPACCT  = 0x0200,	/* Display IP accounting/data rate info */
  CALLID  = 0x0400,	/* Display caller ID accounting */
  IGNORE  = 0x0800	/* Ignore X amount of usage before starting accounting */
};

/* Time formats */
enum {
  FRAC	  = 0x00,	/* default: %10.2f hours */
  HMS	  = 0x01,
  HM	  = 0x02,
  HOURS	  = 0x03,
  SECONDS = 0x04,
  ROUND	  = 0x40,
};

#ifndef TRUE
enum { FALSE=0, TRUE=1 };
#endif

enum { USERLIST, EXCLUDELIST, TTYLIST, HOSTLIST, PORTMASTERLIST, LOGFILELIST, FILELIST };

struct day {
  time_t start, stop;
  short day, wday, month, year, minlogins, maxlogins;
  time_t time;
  time_t h[24];
  double inoct, outoct;
  double inpkt, outpkt;
  u_long datarate;
  struct login *login, *lastlogin;
  u_long logins;
  struct usr *us;
  struct tty *tty;
  struct simuse *simuse;
  struct day *nxt;
};

/*
 * Keep a pointer at the end of the days list, since we'll usually be
 * adding crap to it, not to days before.  What 'o what do we do about
 * time changes aka time warps?
 */

struct usr {
  char user[UT_NAMESIZE+1];
  short loggedin, minlogins, maxlogins;
  time_t time;
  time_t ignore;
  time_t h[24];
  double inoct, outoct;
  double inpkt, outpkt;
  u_long datarate;
  struct login *login, *lastlogin;
  u_long logins, xlogins;
  struct usr *nxt;
};

struct tty {
  char line[UT_LINESIZE+1];
  time_t time, h[24];
  double inoct, outoct;
  double inpkt, outpkt;
  u_long datarate;
  struct login *login, *lastlogin;
  u_long logins, xlogins;
  struct tty *nxt;
};

/* simultaneous usage time */
struct simuse {
  short index;
  time_t time;
  long count;
  time_t h[24];
  struct login *login, *lastlogin;
  struct simuse *nxt;
};

/* excluded users list */
struct exc {
  char user[UT_NAMESIZE+1];
  struct exc *nxt;
};

/* ttys list */
struct ttys {
  char *line;
  char ispat;		/* Is tty a pattern?	*/
  struct ttys *nxt;
};

/* hosts list */
struct hosts {
  char *host;
  char ispat;		/* Is host a pattern?	*/
  char len,ss;		/* Is host a substring?	*/
  struct hosts *nxt;
};

struct user {
  char user[UT_NAMESIZE+1];
  char line[UT_LINESIZE+1];
  char host[UT_HOSTSIZE+1];
  time_t in;
  struct user *nxt;
};

enum filetype {
  ACCT_WTMP,			/* Good old linux (sysv) extended utmp format */
  ACCT_ANCIENT,			/* Bad old BSD style utmp with no ut_type field. */
  ACCT_TACACS3,			/* same as above (old BSD style) */
  ACCT_TACACS4,			/* Bizarre utmp w/ ut_comment field. (no ut_type) */
  ACCT_RADIUS,			/* sucky detail file support */
  ACCT_RADIUS_LOGFILE		/* probably won't support this. */
};

struct file {
  char *file;
  char ftype;
  void (*gronk)();
  struct file *nxt;
};

struct login {
  time_t start, stop;
  char *name;
  char *tty;
  char *host;
  struct login *nxt;
};

#include "proto.h"

/* Globals */

#ifdef MAIN
#  define EXTERN
#  define INIT(x) = x
#else
#  define EXTERN extern
#  define INIT(x)
#endif

EXTERN struct day *days INIT(NULL), *end INIT(NULL);
EXTERN struct usr *us INIT(NULL);
EXTERN struct ttys *tty INIT(NULL);
EXTERN struct exc *ex INIT(NULL);
EXTERN struct simuse *simuse INIT(NULL);
EXTERN struct tty *ttys INIT(NULL);
EXTERN struct hosts *hosts INIT(NULL);
EXTERN struct user *usr INIT(NULL);

#ifdef MAIN
  char *month[13] = {
    "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec", NULL
  };
  char *dayabbr[8] = {"Sun","Mon","Tue","Wed","Thr","Fri","Sat",NULL};
#else
  extern char *month[13], *dayaddbr[8];
#endif

EXTERN char fix INIT(FALSE), exclude INIT(FALSE), fixtty INIT(FALSE), fixhost INIT(FALSE), radhost INIT(FALSE);
EXTERN char hosttoo INIT(FALSE), verbose INIT(FALSE), longdate INIT(FALSE);
EXTERN char *back INIT(NULL), *ignore INIT(NULL), timefmt INIT(FRAC);
EXTERN u_short type INIT(TOTAL);
EXTERN time_t total INIT(0), sd INIT(0), ed INIT(0), backtime INIT(0), curtime INIT(0);
EXTERN time_t lastent INIT(0), ignoretime INIT(0), cutoff INIT(0), discard INIT(0);
EXTERN int ndays INIT(0), logins INIT(0), loggedin INIT(0), minlogins INIT(-1), maxlogins INIT(0);
EXTERN signed int sm INIT(0), em INIT(0);
EXTERN u_long hourmask INIT(0);
EXTERN char *usespec;

/* Simultaneous usage globals */
EXTERN int simdex INIT(0);
EXTERN time_t simtime INIT(0);

EXTERN char buf[BUFSIZE+1];

/*
char *month[] = {
  "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec", NULL
};
char *dayabbr[] = {"Sun","Mon","Tue","Wed","Thr","Fri","Sat",NULL };

char fix = FALSE, exclude = FALSE, fixtty = FALSE, fixhost = FALSE, radhost = FALSE;
char hosttoo = FALSE, verbose = FALSE, longdate = FALSE;
char *back = NULL, *ignore = NULL, timefmt = FRAC;
u_short type = TOTAL;
time_t total = 0, sd = 0, ed = 0, backtime = 0, curtime = 0;
time_t lastent = 0, ignoretime = 0, cutoff = 0, discard = 0;
int ndays = 0, logins = 0, loggedin = 0, minlogins = -1, maxlogins = 0;
signed int sm = 0, em = 0;
u_long hourmask = 0;
char *usespec;

int simdex = 0;
time_t simtime = 0;

char buf[BUFSIZE+1];
*/