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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#ident "%Z%%M% %I% %E% SMI" /* from SVR4 bnu:account.c 1.3 */
/*
*/
#include "uucp.h"
#include "log.h"
#include <pwd.h>
/*
* SYMBOL DEFINITIONS
*/
#define FS ' ' /* Field seperator for output records. */
#define STD 'S' /* standard service. */
#define LOGCHECK { if (Collecting == FALSE) return; }
/*
* STRUCTURE DEFINITIONS
*/
struct acData /* Data for construction of account record. */
{
char uid[MODSTR]; /* user id */
char jobID[MODSTR]; /* C. file */
off_t jobsize; /* Bytes transferred in a job.*/
char status; /* transaction status */
char service; /* service grade */
char jobgrade[MODSTR]; /* job grade */
char time[MODSTR]; /* date and time the job execed */
char origSystem[MODSTR]; /* originating system's name */
char origUser[MODSTR]; /* originator's login
name */
char rmtSystem[MODSTR]; /* system's name of
first hop */
char rmtUser[MODSTR]; /* user's name of first
hop */
char device[MODSTR]; /* network medium */
char netid[MODSTR]; /* Network ID in use */
char type[MODSTR]; /* type of transaction */
char path[BUFSIZ]; /* path of the rest of the hops */
};
/*
* LOCAL DATA
*/
static int Collecting = FALSE; /* True if we are collecting
* data. */
static int LogFile = CLOSED; /* Log file file destriptor. */
static char LogName[] = ACCOUNT; /* Name of our log file. */
static char Record[LOGSIZE]; /* Place to build log records. */
static struct acData Acct; /* Accounting data. */
/*
* LOCAL FUNCTIONS
*/
/* Declarations of functions: */
STATIC_FUNC void reportJob();
/*
* Local Function: reportJob - Write Job accounting information to Log
*
* This function writes accounting information about the current job to the log
* file.
*
* Parameters:
*
* none.
*/
STATIC_FUNC void
reportJob ()
{
static char format[] = "%s%c%s%c%ld%c%c%c%c%c%s%c%s%c%s%c(%s)%c%s%c%s%c%s%c%s%c%s%c%s%c";
register struct acData * acptr;
acptr = &Acct; /* Point to Acct data. */
sprintf(Record, format,
acptr->uid, FS,
acptr->jobID, FS,
acptr->jobsize, FS,
acptr->status, FS,
acptr->service, FS,
acptr->jobgrade, FS,
acptr->origSystem, FS,
acptr->origUser, FS,
acptr->time, FS,
acptr->rmtSystem, FS,
acptr->rmtUser, FS,
acptr->device, FS,
acptr->netid, FS,
acptr->type, FS,
acptr->path, FS);
/* Terminate the record and write it out. */
(void) strcat(Record, EOR);
writeLog(Record,&LogFile,LogName,&Collecting);
}
/*
* EXTERNAL FUNCTIONS
*/
/*
* Function: acConnected - Report Connection Completion
*
* Parameters:
*
* remote - name of the remote system.
*
* device - the type of device being used for communicaitons.
*/
void
acConnected (remote, device)
char * remote;
char * device;
{
register struct acData * acptr = &Acct;
LOGCHECK;
copyText(acptr->rmtSystem, sizeof(acptr->rmtSystem), remote);
copyText(acptr->device, sizeof(acptr->device), device);
acptr->service = 'S'; /* default to standard service */
}
/* Function: acDojob - Found Another Job
*
* acDojob is called when a new job has been found.
*
* Parameters:
*
* jobid - The name of the job that was found.
*
* system - Originating system's name.
*
* user - Originator's login name.
*/
void
acDojob(jobid, system, user)
char * jobid;
char * system;
char * user;
{
register struct acData * acptr = &Acct;
struct passwd *passent;
LOGCHECK;
if (strcmp(acptr->jobID,jobid) == 0)
return;
if ((*acptr->jobID != NULLCHAR) && (acptr->jobsize != 0)){
reportJob();
}
copyText(acptr->jobID, sizeof(acptr->jobID), jobid);
copyText(acptr->origSystem, sizeof(acptr->origSystem), system);
copyText(acptr->origUser, sizeof(acptr->origUser), user);
copyText(acptr->time, sizeof(acptr->time), timeStamp());
acptr->jobgrade[0] = jobid[strlen(jobid)-5];
acptr->jobgrade[1] = NULLCHAR;/* get job grade from jobid */
acptr->jobsize = 0;
while ((passent = getpwent()) != NULL){
if (strcmp(passent->pw_name,user) == 0){
sprintf(acptr->uid,"%ld",(long) passent->pw_uid);
break;
}
}
}
/* End recording the accounting log */
void
acEnd(status)
char status;
{
register struct acData * acptr = &Acct;
LOGCHECK;
if (((*acptr->jobID != NULLCHAR) && (acptr->jobsize != 0))
|| (status == PARTIAL)){
acptr->status = status;
reportJob();
}
}
/* increment job size */
void
acInc()
{
register struct acData * acptr = &Acct;
LOGCHECK;
acptr->jobsize += getfilesize();
}
/*
* Function: acInit - Initialize Accounting Package
*
* This function allows the accounting package to initialize its internal
* data structures. It should be called when uucico starts running on master
* or changes the role from slave to master, or uuxqt is invoked.
*
* Parameters:
*
* type: file transfer or remote exec.
*/
void
acInit (type)
char * type;
{
register struct acData * acptr = &Acct;
/*
* Attempt to open the log file. If we can't do it, then we
* won't collect statistics.
*/
if (openLog(&LogFile,LogName) == SUCCESS){
Collecting = TRUE;
acptr->service = STD; /* default to standard service */
acptr->status = COMPLETE; /* default to completed transfer */
copyText(acptr->jobgrade, sizeof(acptr->jobgrade), NOTAVAIL);
copyText(acptr->uid, sizeof(acptr->uid), NOTAVAIL);
copyText(acptr->origSystem, sizeof(acptr->origSystem), NOTAVAIL);
copyText(acptr->origUser, sizeof(acptr->origUser), NOTAVAIL);
copyText(acptr->rmtSystem, sizeof(acptr->rmtSystem), NOTAVAIL);
copyText(acptr->rmtUser, sizeof(acptr->rmtUser), NOTAVAIL);
copyText(acptr->device, sizeof(acptr->device), NOTAVAIL);
copyText(acptr->netid, sizeof(acptr->netid), NOTAVAIL);
copyText(acptr->path, sizeof(acptr->path), NOTAVAIL);
copyText(acptr->type, sizeof(acptr->type), type);
}
else
Collecting = FALSE;
}
/*
* It is called when uuxqt is running
*
* jobid - jobid after X. prefix
* origsys - Originating system's name.
* origuser - Originator's login name.
* connsys - local system
* connuser - login user
* cmd - command to be execed by uuxqt
*/
void
acRexe(jobid,origsys,origuser,connsys,connuser,cmd)
char * jobid;
char * origsys;
char * origuser;
char * connsys;
char * connuser;
char * cmd;
{
register struct acData * acptr = &Acct;
LOGCHECK;
copyText(acptr->jobID, sizeof(acptr->jobID), jobid);
copyText(acptr->origSystem, sizeof(acptr->origSystem), origsys);
copyText(acptr->origUser, sizeof(acptr->origUser), origuser);
copyText(acptr->rmtSystem, sizeof(acptr->rmtSystem), connsys);
copyText(acptr->rmtUser, sizeof(acptr->rmtUser), connuser);
copyText(acptr->path, sizeof(acptr->path), cmd);
copyText(acptr->time, sizeof(acptr->time), timeStamp());
}
/*
* It is called when the command to be execed is finished
*
* cpucycle: cpu time the command is consumed
*/
void
acEndexe(cycle,status)
time_t cycle;
char status;
{
register struct acData * acptr = &Acct;
LOGCHECK;
acptr->jobsize = cycle;
acptr->status = status;
reportJob();
}
/*
* cpucycle()
*
* return cputime(utime+stime) since last time called
*/
time_t
cpucycle()
{
struct tms tbuf;
time_t rval;
static time_t utime,stime; /* guaranteed 0 first time called */
times(&tbuf);
rval = ((tbuf.tms_utime-utime) + (tbuf.tms_stime-stime))*1000/HZ;
utime = tbuf.tms_utime;
stime = tbuf.tms_stime;
return(rval);
}
|