~ubuntu-branches/ubuntu/oneiric/openafs/oneiric-201305130334

« back to all changes in this revision

Viewing changes to src/audit/audit.c

  • Committer: Bazaar Package Importer
  • Author(s): Sam Hartman
  • Date: 2006-10-21 20:57:09 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20061021205709-y5keam1v20qxjwwo
Tags: 1.4.2-2
Upstream fix to prevent butc segfaulting.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
#include <afs/param.h>
12
12
 
13
13
RCSID
14
 
    ("$Header: /cvs/openafs/src/audit/audit.c,v 1.8.2.8 2006/02/13 17:57:26 jaltman Exp $");
 
14
    ("$Header: /cvs/openafs/src/audit/audit.c,v 1.8.2.12 2006/10/13 19:42:19 shadow Exp $");
15
15
 
16
16
#include <fcntl.h>
17
17
#include <stdarg.h>
37
37
#endif
38
38
#include <afs/afsutil.h>
39
39
 
 
40
/* C99 requires va_copy.  Older versions of GCC provide __va_copy.  Per t
 
41
   Autoconf manual, memcpy is a generally portable fallback. */          
 
42
#ifndef va_copy              
 
43
# ifdef __va_copy
 
44
#  define va_copy(d, s)         __va_copy((d), (s))             
 
45
# else
 
46
#  define va_copy(d, s)         memcpy(&(d), &(s), sizeof(va_list)) 
 
47
# endif
 
48
#endif      
 
49
 
40
50
char *bufferPtr;
41
51
int bufferLen;
42
52
int osi_audit_all = (-1);       /* Not determined yet */
87
97
            *(afs_int32 *) bufferPtr = vaLong;
88
98
            bufferPtr += sizeof(vaLong);
89
99
            break;
90
 
        case AUD_LST:           /* Ptr to another list */
91
 
            vaLst = va_arg(vaList, va_list);
92
 
            audmakebuf(audEvent, vaLst);
93
 
            break;
94
100
        case AUD_FID:           /* AFSFid - contains 3 entries */
95
101
            vaFid = (struct AFSFid *)va_arg(vaList, struct AFSFid *);
96
102
            if (vaFid) {
137
143
}
138
144
 
139
145
static void
140
 
printbuf(FILE *out, int rec, char *audEvent, afs_int32 errCode, va_list vaList)
 
146
printbuf(FILE *out, int rec, char *audEvent, char *afsName, afs_int32 hostId, 
 
147
         afs_int32 errCode, va_list vaList)
141
148
{
142
149
    int vaEntry;
143
150
    int vaInt;
164
171
            fprintf(out, "[%d] ", num);
165
172
    }
166
173
    
167
 
    if (strcmp(audEvent, "VALST") != 0)
168
 
        fprintf(out,  "EVENT %s CODE %d ", audEvent, errCode);
 
174
    fprintf(out,  "EVENT %s CODE %d ", audEvent, errCode);
 
175
 
 
176
    if (afsName) {
 
177
        hostAddr.s_addr = hostId;
 
178
        fprintf(out,  "NAME %s HOST %s ", afsName, inet_ntoa(hostAddr));
 
179
    }
169
180
 
170
181
    vaEntry = va_arg(vaList, int);
171
182
    while (vaEntry != AUD_END) {
212
223
            vaLong = va_arg(vaList, afs_int32);
213
224
            fprintf(out, "LONG %d ", vaLong);
214
225
            break;
215
 
        case AUD_LST:           /* Ptr to another list */
216
 
            vaLst = va_arg(vaList, va_list);
217
 
            printbuf(out, 1, "VALST", 0, vaLst);
218
 
            break;
219
226
        case AUD_FID:           /* AFSFid - contains 3 entries */
220
227
            vaFid = va_arg(vaList, struct AFSFid *);
221
228
            if (vaFid)
253
260
        vaEntry = va_arg(vaList, int);
254
261
    }                           /* end while */
255
262
 
256
 
    if (strcmp(audEvent, "VALST") != 0)
257
 
        fprintf(out, "\n");
 
263
    fprintf(out, "\n");
258
264
}
259
265
 
260
266
#ifdef AFS_PTHREAD_ENV
284
290
/* The routine that acually does the audit call.
285
291
 * ************************************************************************** */
286
292
int
287
 
osi_audit(char *audEvent,       /* Event name (15 chars or less) */
288
 
          afs_int32 errCode,    /* The error code */
289
 
          ...)
 
293
osi_audit_internal(char *audEvent,      /* Event name (15 chars or less) */
 
294
                   afs_int32 errCode,   /* The error code */
 
295
                   char *afsName,
 
296
                   afs_int32 hostId,
 
297
                   va_list vaList)
290
298
{
291
299
#ifdef AFS_AIX32_ENV
292
300
    afs_int32 code;
294
302
    static char BUFFER[32768];
295
303
#endif
296
304
    int result;
297
 
    va_list vaList;
 
305
    va_list vaCopy;
298
306
 
299
307
#ifdef AFS_PTHREAD_ENV
300
308
    /* i'm pretty sure all the server apps now call osi_audit_init(),
308
316
    if (!osi_audit_all && !auditout)
309
317
        return 0;
310
318
 
 
319
    va_copy(vaCopy, vaList);
 
320
 
311
321
    switch (errCode) {
312
322
    case 0:
313
323
        result = AUDIT_OK;
342
352
    *(int *)bufferPtr = errCode;
343
353
    bufferPtr += sizeof(errCode);
344
354
 
345
 
    va_start(vaList, errCode);
346
355
    audmakebuf(audEvent, vaList);
347
356
#endif
348
357
 
349
358
    if (osi_echo_trail) {
350
 
        va_start(vaList, errCode);
351
 
        printbuf(stdout, 0, audEvent, errCode, vaList);
 
359
        printbuf(stdout, 0, audEvent, afsName, hostId, errCode, vaList);
352
360
    }
 
361
    va_end(vaCopy);
353
362
 
354
363
#ifdef AFS_AIX32_ENV
355
364
    bufferLen = (int)((afs_int32) bufferPtr - (afs_int32) & BUFFER[0]);
356
365
    code = auditlog(audEvent, result, BUFFER, bufferLen);
357
 
#ifdef notdef
358
 
    if (code) {
359
 
        err = errno;
360
 
        code = auditlog("AFS_Aud_Fail", result, &err, sizeof(err));
361
 
        if (code)
362
 
            printf("Error while writing audit entry: %d.\n", errno);
363
 
    }
364
 
#endif /* notdef */
365
366
#else
366
367
    if (auditout) {
367
 
        va_start(vaList, errCode);
368
 
        printbuf(auditout, 0, audEvent, errCode, vaList);
 
368
        printbuf(auditout, 0, audEvent, afsName, hostId, errCode, vaList);
369
369
        fflush(auditout);
370
370
    }
371
371
#endif
375
375
 
376
376
    return 0;
377
377
}
 
378
int
 
379
osi_audit(char *audEvent,       /* Event name (15 chars or less) */
 
380
          afs_int32 errCode,    /* The error code */
 
381
          ...)
 
382
{
 
383
    va_list vaList;
 
384
 
 
385
    if ((osi_audit_all < 0) || (osi_echo_trail < 0))
 
386
        osi_audit_check();
 
387
    if (!osi_audit_all && !auditout)
 
388
        return 0;
 
389
 
 
390
    va_start(vaList, errCode);
 
391
    osi_audit_internal(audEvent, errCode, NULL, 0, vaList);
 
392
    va_end(vaList);
 
393
 
 
394
    return 0;
 
395
}
378
396
 
379
397
/* ************************************************************************** */
380
398
/* Given a RPC call structure, this routine extracts the name and host id from the 
461
479
        osi_audit("AFS_Aud_NoCall", (-1), AUD_STR, audEvent, AUD_END);
462
480
    }
463
481
    va_start(vaList, errCode);
464
 
    osi_audit(audEvent, errCode, AUD_NAME, afsName, AUD_HOST, hostId, 
465
 
              AUD_LST, vaList, AUD_END);
466
 
 
 
482
    osi_audit_internal(audEvent, errCode, afsName, hostId, vaList);
 
483
    va_end(vaList);
467
484
    return 0;
468
485
}
469
486