From 539dc6f501459712136f574744dba196598bee0b Mon Sep 17 00:00:00 2001 From: Steve McIntosh Date: Wed, 17 Dec 2008 18:14:41 +0000 Subject: [PATCH] audit-consolidate-open-20081217 LICENSE IPL10 FIXES 123923 consolidate opening auditlog in one place; make opening nonblock easier --- src/audit/audit.c | 34 ++++++++++++++++++++++++++++++++-- src/audit/audit.h | 2 +- src/bozo/bosserver.c | 27 +-------------------------- src/budb/server.c | 26 +------------------------- src/kauth/kaserver.c | 27 +-------------------------- src/ptserver/ptserver.c | 29 ++--------------------------- src/viced/viced.c | 29 ++--------------------------- src/vlserver/vlserver.c | 27 +-------------------------- src/volser/volmain.c | 29 ++--------------------------- 9 files changed, 43 insertions(+), 187 deletions(-) diff --git a/src/audit/audit.c b/src/audit/audit.c index 96283f2..2cd5d5b 100644 --- a/src/audit/audit.c +++ b/src/audit/audit.c @@ -16,6 +16,9 @@ RCSID #include #include #include +#include +#include +#include #ifdef AFS_AIX32_ENV #include #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; } diff --git a/src/audit/audit.h b/src/audit/audit.h index ba6f277..bed4b53 100644 --- a/src/audit/audit.h +++ b/src/audit/audit.h @@ -291,6 +291,6 @@ /* 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); diff --git a/src/bozo/bosserver.c b/src/bozo/bosserver.c index f29ba8f..91ddf17 100644 --- a/src/bozo/bosserver.c +++ b/src/bozo/bosserver.c @@ -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 { diff --git a/src/budb/server.c b/src/budb/server.c index b929305..feb99d0 100644 --- a/src/budb/server.c +++ b/src/budb/server.c @@ -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 */ diff --git a/src/kauth/kaserver.c b/src/kauth/kaserver.c index 9c22ba2..a8548ae 100644 --- a/src/kauth/kaserver.c +++ b/src/kauth/kaserver.c @@ -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) diff --git a/src/ptserver/ptserver.c b/src/ptserver/ptserver.c index d2ee077..09eb7dc 100644 --- a/src/ptserver/ptserver.c +++ b/src/ptserver/ptserver.c @@ -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) { diff --git a/src/viced/viced.c b/src/viced/viced.c index c8fee20..0ef90b3 100644 --- a/src/viced/viced.c +++ b/src/viced/viced.c @@ -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) { diff --git a/src/vlserver/vlserver.c b/src/vlserver/vlserver.c index af4640d..26bfabf 100644 --- a/src/vlserver/vlserver.c +++ b/src/vlserver/vlserver.c @@ -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) { diff --git a/src/volser/volmain.c b/src/volser/volmain.c index 5181abf..cd596b2 100644 --- a/src/volser/volmain.c +++ b/src/volser/volmain.c @@ -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) { -- 1.9.4