From: Steve McIntosh Date: Wed, 17 Dec 2008 18:16:25 +0000 (+0000) Subject: STABLE14-audit-consolidate-open-20081217 X-Git-Tag: openafs-stable-1_4_9pre1~86 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=86d2faf323a45fc6202be8989606cb0b7ea5c105;p=packages%2Fo%2Fopenafs.git STABLE14-audit-consolidate-open-20081217 LICENSE IPL10 FIXES 123923 consolidate opening auditlog in one place; make opening nonblock easier AUTHOR LICENSE IPL10 (cherry picked from commit 539dc6f501459712136f574744dba196598bee0b) --- diff --git a/src/audit/audit.c b/src/audit/audit.c index 833e69723..da8cb7f8c 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 @@ -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; } diff --git a/src/audit/audit.h b/src/audit/audit.h index ba6f27741..bed4b53dd 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 f29cfe933..b9c660d05 100644 --- a/src/bozo/bosserver.c +++ b/src/bozo/bosserver.c @@ -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 { diff --git a/src/budb/server.c b/src/budb/server.c index fafe992ca..10838a05d 100644 --- a/src/budb/server.c +++ b/src/budb/server.c @@ -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; diff --git a/src/kauth/kaserver.c b/src/kauth/kaserver.c index 396830c63..40c53c6bd 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 6e76174d5..79d1b76b8 100644 --- a/src/ptserver/ptserver.c +++ b/src/ptserver/ptserver.c @@ -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) { diff --git a/src/viced/viced.c b/src/viced/viced.c index 992ffd388..ac69dcefc 100644 --- a/src/viced/viced.c +++ b/src/viced/viced.c @@ -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) { diff --git a/src/vlserver/vlserver.c b/src/vlserver/vlserver.c index 948ff62da..03f9c90bd 100644 --- a/src/vlserver/vlserver.c +++ b/src/vlserver/vlserver.c @@ -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) { diff --git a/src/volser/volmain.c b/src/volser/volmain.c index ecb606667..581e81c1e 100644 --- a/src/volser/volmain.c +++ b/src/volser/volmain.c @@ -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) {