audit-consolidate-open-20081217
authorSteve McIntosh <stevemac@sinenomine.net>
Wed, 17 Dec 2008 18:14:41 +0000 (18:14 +0000)
committerDerrick Brashear <shadow@dementia.org>
Wed, 17 Dec 2008 18:14:41 +0000 (18:14 +0000)
LICENSE IPL10
FIXES 123923

consolidate opening auditlog in one place; make opening nonblock easier

src/audit/audit.c
src/audit/audit.h
src/bozo/bosserver.c
src/budb/server.c
src/kauth/kaserver.c
src/ptserver/ptserver.c
src/viced/viced.c
src/vlserver/vlserver.c
src/volser/volmain.c

index 96283f2..2cd5d5b 100644 (file)
@@ -16,6 +16,9 @@ RCSID
 #include <fcntl.h>
 #include <stdarg.h>
 #include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
 #ifdef AFS_AIX32_ENV
 #include <sys/audit.h>
 #else
@@ -555,8 +558,35 @@ osi_audit_check()
 }
 
 int
-osi_audit_file(FILE *out)
+osi_audit_file(char *fileName)
 {
-    auditout = out;
+    int tempfd, flags;
+    char oldName[MAXPATHLEN];
+    
+#ifndef AFS_NT40_ENV
+    struct stat statbuf;
+    
+    if ((lstat(fileName, &statbuf) == 0)
+        && (S_ISFIFO(statbuf.st_mode))) {
+        flags = O_WRONLY | O_NONBLOCK;
+    } else 
+#endif
+    {
+        strcpy(oldName, fileName);
+        strcat(oldName, ".old");
+        renamefile(fileName, oldName);
+        flags = O_WRONLY | O_TRUNC | O_CREAT;
+    }
+    tempfd = open(fileName, flags, 0666);
+    if (tempfd > -1) {
+        auditout = fdopen(tempfd, "a");
+        if (!auditout) {
+            printf("Warning: auditlog %s not writable, ignored.\n", fileName);
+            return 1;
+        }
+    } else { 
+        printf("Warning: auditlog %s not writable, ignored.\n", fileName);
+        return 1;
+    }
     return 0;
 }
index ba6f277..bed4b53 100644 (file)
 /* prototypes for audit functions */
 int osi_audit(char *audEvent, afs_int32 errCode, ...);
 int osi_auditU(struct rx_call *call, char *audEvent, int errCode, ...);
-int osi_audit_file(FILE *out);
+int osi_audit_file(char *filename);
 void osi_audit_init(void);
 
index f29ba8f..91ddf17 100644 (file)
@@ -840,34 +840,9 @@ main(int argc, char **argv, char **envp)
            }
        }
        else if (strcmp(argv[code], "-auditlog") == 0) {
-           int tempfd, flags;
-           FILE *auditout;
-           char oldName[MAXPATHLEN];
            char *fileName = argv[++code];
 
-#ifndef AFS_NT40_ENV
-           struct stat statbuf;
-           
-           if ((lstat(fileName, &statbuf) == 0) 
-               && (S_ISFIFO(statbuf.st_mode))) {
-               flags = O_WRONLY | O_NONBLOCK;
-           } else 
-#endif
-           {
-               strcpy(oldName, fileName);
-               strcat(oldName, ".old");
-               renamefile(fileName, oldName);
-               flags = O_WRONLY | O_TRUNC | O_CREAT;
-           }
-           tempfd = open(fileName, flags, 0666);
-           if (tempfd > -1) {
-               auditout = fdopen(tempfd, "a");
-               if (auditout) {
-                   osi_audit_file(auditout);
-               } else
-                   printf("Warning: auditlog %s not writable, ignored.\n", fileName);
-           } else
-               printf("Warning: auditlog %s not writable, ignored.\n", fileName);
+            osi_audit_file(fileName);
        }
        else {
 
index b929305..feb99d0 100644 (file)
@@ -229,33 +229,9 @@ argHandler(struct cmd_syndesc *as, void *arock)
        ubik_nBuffers = 0;
 
     if (as->parms[7].items != 0) {
-       int tempfd, flags;
-       FILE *auditout;
-       char oldName[MAXPATHLEN];
        char *fileName = as->parms[7].items->data;
-#ifndef AFS_NT40_ENV
-       struct stat statbuf;
 
-       if ((lstat(fileName, &statbuf) == 0) 
-           && (S_ISFIFO(statbuf.st_mode))) {
-           flags = O_WRONLY | O_NONBLOCK;
-       } else 
-#endif
-       {
-           strcpy(oldName, fileName);
-           strcat(oldName, ".old");
-           renamefile(fileName, oldName);
-           flags = O_WRONLY | O_TRUNC | O_CREAT;
-       }
-       tempfd = open(fileName, flags, 0666);
-       if (tempfd > -1) {
-           auditout = fdopen(tempfd, "a");
-           if (auditout) {
-               osi_audit_file(auditout);
-           } else
-               printf("Warning: auditlog %s not writable, ignored.\n", fileName);
-       } else
-           printf("Warning: auditlog %s not writable, ignored.\n", fileName);
+        osi_audit_file(fileName);
     }
 
     /* user provided the number of threads    */
index 9c22ba2..a8548ae 100644 (file)
@@ -249,34 +249,9 @@ main(argc, argv)
                lclpath = dbpath;
        }
        else if (strncmp(arg, "-auditlog", arglen) == 0) {
-           int tempfd, flags;
-           FILE *auditout;
-           char oldName[MAXPATHLEN];
            char *fileName = argv[++a];
            
-#ifndef AFS_NT40_ENV
-           struct stat statbuf;
-           
-           if ((lstat(fileName, &statbuf) == 0) 
-               && (S_ISFIFO(statbuf.st_mode))) {
-               flags = O_WRONLY | O_NONBLOCK;
-           } else 
-#endif
-           {
-               strcpy(oldName, fileName);
-               strcat(oldName, ".old");
-               renamefile(fileName, oldName);
-               flags = O_WRONLY | O_TRUNC | O_CREAT;
-           }
-           tempfd = open(fileName, flags, 0666);
-           if (tempfd > -1) {
-               auditout = fdopen(tempfd, "a");
-               if (auditout) {
-                   osi_audit_file(auditout);
-               } else
-                   printf("Warning: auditlog %s not writable, ignored.\n", fileName);
-           } else
-               printf("Warning: auditlog %s not writable, ignored.\n", fileName);
+           osi_audit_file(fileName);
        } else if (strcmp(arg, "-localfiles") == 0)
            lclpath = argv[++a];
        else if (strcmp(arg, "-servers") == 0)
index d2ee077..09eb7dc 100644 (file)
@@ -335,35 +335,10 @@ main(int argc, char **argv)
        }
 #endif
        else if (strncmp(arg, "-auditlog", alen) == 0) {
-           int tempfd, flags;
-           FILE *auditout;
-           char oldName[MAXPATHLEN];
            char *fileName = argv[++a];
 
-#ifndef AFS_NT40_ENV
-           struct stat statbuf;
-
-           if ((lstat(fileName, &statbuf) == 0) 
-               && (S_ISFIFO(statbuf.st_mode))) {
-               flags = O_WRONLY | O_NONBLOCK;
-           } else 
-#endif
-           {
-               strcpy(oldName, fileName);
-               strcat(oldName, ".old");
-               renamefile(fileName, oldName);
-               flags = O_WRONLY | O_TRUNC | O_CREAT;
-           }
-           tempfd = open(fileName, flags, 0666);
-           if (tempfd > -1) {
-               auditout = fdopen(tempfd, "a");
-               if (auditout) {
-                   osi_audit_file(auditout);
-                   osi_audit(PTS_StartEvent, 0, AUD_END);
-               } else
-                   printf("Warning: auditlog %s not writable, ignored.\n", fileName);
-           } else
-               printf("Warning: auditlog %s not writable, ignored.\n", fileName);
+            osi_audit_file(fileName);
+            osi_audit(PTS_StartEvent, 0, AUD_END);
        }
        else if (!strncmp(arg, "-rxmaxmtu", alen)) {
            if ((a + 1) >= argc) {
index c8fee20..0ef90b3 100644 (file)
@@ -1346,34 +1346,9 @@ ParseArgs(int argc, char *argv[])
            rx_enableProcessRPCStats();
        }
        else if (strcmp(argv[i], "-auditlog") == 0) {
-           int tempfd, flags;
-           FILE *auditout;
-           char oldName[MAXPATHLEN];
            char *fileName = argv[++i];
-           
-#ifndef AFS_NT40_ENV
-           struct stat statbuf;
-           
-           if ((lstat(fileName, &statbuf) == 0) 
-               && (S_ISFIFO(statbuf.st_mode))) {
-               flags = O_WRONLY | O_NONBLOCK;
-           } else 
-#endif
-           {
-               strcpy(oldName, fileName);
-               strcat(oldName, ".old");
-               renamefile(fileName, oldName);
-               flags = O_WRONLY | O_TRUNC | O_CREAT;
-           }
-           tempfd = open(fileName, flags, 0666);
-           if (tempfd > -1) {
-               auditout = fdopen(tempfd, "a");
-               if (auditout) {
-                   osi_audit_file(auditout);
-               } else
-                   printf("Warning: auditlog %s not writable, ignored.\n", fileName);
-           } else
-               printf("Warning: auditlog %s not writable, ignored.\n", fileName);
+
+            osi_audit_file(fileName);
        }
 #ifndef AFS_NT40_ENV
        else if (strcmp(argv[i], "-syslog") == 0) {
index af4640d..26bfabf 100644 (file)
@@ -215,34 +215,9 @@ main(argc, argv)
            strcpy(rxi_tracename, argv[++index]);
 
        } else if (strcmp(argv[index], "-auditlog") == 0) {
-          int tempfd, flags;
-           FILE *auditout;
-           char oldName[MAXPATHLEN];
            char *fileName = argv[++index];
 
-#ifndef AFS_NT40_ENV
-           struct stat statbuf;
-
-           if ((lstat(fileName, &statbuf) == 0) 
-               && (S_ISFIFO(statbuf.st_mode))) {
-               flags = O_WRONLY | O_NONBLOCK;
-           } else 
-#endif
-           {
-               strcpy(oldName, fileName);
-               strcat(oldName, ".old");
-               renamefile(fileName, oldName);
-               flags = O_WRONLY | O_TRUNC | O_CREAT;
-           }
-           tempfd = open(fileName, flags, 0666);
-           if (tempfd > -1) {
-               auditout = fdopen(tempfd, "a");
-               if (auditout) {
-                   osi_audit_file(auditout);
-               } else
-                   printf("Warning: auditlog %s not writable, ignored.\n", fileName);
-           } else
-               printf("Warning: auditlog %s not writable, ignored.\n", fileName);
+           osi_audit_file(fileName);
        } else if (strcmp(argv[index], "-enable_peer_stats") == 0) {
            rx_enablePeerRPCStats();
        } else if (strcmp(argv[index], "-enable_process_stats") == 0) {
index 5181abf..cd596b2 100644 (file)
@@ -310,35 +310,10 @@ main(int argc, char **argv)
                lwps = MAXLWP;
            }
        } else if (strcmp(argv[code], "-auditlog") == 0) {
-           int tempfd, flags;
-           FILE *auditout;
-           char oldName[MAXPATHLEN];
            char *fileName = argv[++code];
 
-#ifndef AFS_NT40_ENV
-           struct stat statbuf;
-           
-           if ((lstat(fileName, &statbuf) == 0) 
-               && (S_ISFIFO(statbuf.st_mode))) {
-               flags = O_WRONLY | O_NONBLOCK;
-           } else 
-#endif
-           {
-               strcpy(oldName, fileName);
-               strcat(oldName, ".old");
-               renamefile(fileName, oldName);
-               flags = O_WRONLY | O_TRUNC | O_CREAT;
-           }
-           tempfd = open(fileName, flags, 0666);
-           if (tempfd > -1) {
-               auditout = fdopen(tempfd, "a");
-               if (auditout) {
-                   osi_audit_file(auditout);
-                   osi_audit(VS_StartEvent, 0, AUD_END);
-               } else
-                   printf("Warning: auditlog %s not writable, ignored.\n", fileName);
-           } else
-               printf("Warning: auditlog %s not writable, ignored.\n", fileName);
+            osi_audit_file(fileName);
+            osi_audit(VS_StartEvent, 0, AUD_END);
        } else if (strcmp(argv[code], "-nojumbo") == 0) {
            rxJumbograms = 0;
        } else if (strcmp(argv[code], "-jumbo") == 0) {