audit: Tidy header includes
[openafs.git] / src / audit / audit-file.c
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
19 static FILE *auditout;
20
21 static void
22 send_msg(void)
23 {
24     fprintf(auditout, "\n");
25     fflush(auditout);
26 }
27
28 static void
29 append_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
38 static int
39 open_file(const char *fileName)
40 {
41     int tempfd, flags;
42     char oldName[MAXPATHLEN];
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         strcpy(oldName, fileName);
54         strcat(oldName, ".old");
55         renamefile(fileName, oldName);
56         flags = O_WRONLY | O_TRUNC | O_CREAT;
57     }
58     tempfd = open(fileName, flags, 0666);
59     if (tempfd > -1) {
60         auditout = fdopen(tempfd, "a");
61         if (!auditout) {
62             printf("Warning: auditlog %s not writable, ignored.\n", fileName);
63             return 1;
64         }
65     } else {
66         printf("Warning: auditlog %s not writable, ignored.\n", fileName);
67         return 1;
68     }
69     return 0;
70 }
71
72 static void
73 print_interface_stats(FILE *out)
74 {
75     return;
76 }
77
78 const struct osi_audit_ops audit_file_ops = {
79     &send_msg,
80     &append_msg,
81     &open_file,
82     &print_interface_stats,
83 };