Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / audit / audit-file.c
CommitLineData
805e021f
CE
1/*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
4 *
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
9
10#include <afsconfig.h>
11#include <afs/param.h>
12
13#include <roken.h>
14
15#include <afs/afsutil.h>
16
17#include "audit-api.h"
18
19static FILE *auditout;
20
21static void
22send_msg(void)
23{
24 fprintf(auditout, "\n");
25 fflush(auditout);
26}
27
28static void
29append_msg(const char *format, ...)
30{
31 va_list vaList;
32
33 va_start(vaList, format);
34 vfprintf(auditout, format, vaList);
35 va_end(vaList);
36}
37
38static int
39open_file(const char *fileName)
40{
41 int tempfd, flags, r;
42 char *oldName;
43
44#ifndef AFS_NT40_ENV
45 struct stat statbuf;
46
47 if ((lstat(fileName, &statbuf) == 0)
48 && (S_ISFIFO(statbuf.st_mode))) {
49 flags = O_WRONLY | O_NONBLOCK;
50 } else
51#endif
52 {
53 r = asprintf(&oldName, "%s.old", fileName);
54 if (r < 0 || oldName == NULL) {
55 printf("Warning: Unable to create backup filename. Auditing ignored\n");
56 return 1;
57 }
58 rk_rename(fileName, oldName);
59 flags = O_WRONLY | O_TRUNC | O_CREAT;
60 free(oldName);
61 }
62 tempfd = open(fileName, flags, 0666);
63 if (tempfd > -1) {
64 auditout = fdopen(tempfd, "a");
65 if (!auditout) {
66 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
67 return 1;
68 }
69 } else {
70 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
71 return 1;
72 }
73 return 0;
74}
75
76static void
77print_interface_stats(FILE *out)
78{
79 return;
80}
81
82const struct osi_audit_ops audit_file_ops = {
83 &send_msg,
84 &append_msg,
85 &open_file,
86 &print_interface_stats,
87};