]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
STABLE14-audit-consolidate-open-20081217
authorSteve McIntosh <stevemac@sinenomine.net>
Wed, 17 Dec 2008 18:16:25 +0000 (18:16 +0000)
committerDerrick Brashear <shadow@dementia.org>
Wed, 17 Dec 2008 18:16:25 +0000 (18:16 +0000)
LICENSE IPL10
FIXES 123923

consolidate opening auditlog in one place; make opening nonblock easier
AUTHOR
LICENSE IPL10

(cherry picked from commit 539dc6f501459712136f574744dba196598bee0b)

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 833e6972385766d38e6e2eb3df7ede2ef8bfb536..da8cb7f8cc4f7e355481a792e96b0304bac9c641 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
@@ -524,8 +527,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 ba6f27741c71730185e4f78cfabb5c3782bd3b7e..bed4b53dd150ba72ffb0de811e87516ed209216f 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 f29cfe933591ada2787cd2171cc9f39ac23cf321..b9c660d053d768923f41f3192bd35e43c80deb17 100644 (file)
@@ -841,34 +841,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 fafe992cafbb12a964e6411f9152f5a0d7922d27..10838a05de901267d56f14384dac8a1268b0c014 100644 (file)
@@ -220,33 +220,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);
     }
 
     return 0;
index 396830c63ed7a9a30d6a5ae071b3dbb4dca9fbcb..40c53c6bdd56215590d3f210e676dc2e8fe30682 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 6e76174d565ed09d5cf554f1c4e20c50a5180740..79d1b76b87a0d28ab18b8889c39ee484e0bf783b 100644 (file)
@@ -336,35 +336,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 992ffd3881391d6a002bfac49f451b0130e60ae5..ac69dcefc1d30ba96fff7b3f321baccae80cbbf8 100644 (file)
@@ -1120,34 +1120,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 948ff62da95087478ef6ee10bcf1b7a1220b940e..03f9c90bde42e58831520554bc0bee591600460c 100644 (file)
@@ -211,34 +211,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 ecb6066671906db73729023edf926d8b1cbf6f1a..581e81c1e1b97394bb8b6372a5f2b9927c39b283 100644 (file)
@@ -311,35 +311,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) {