#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
*(afs_int32 *) bufferPtr = vaLong;
bufferPtr += sizeof(vaLong);
break;
- case AUD_LST: /* Ptr to another list */
- va_copy(vaLst, vaList);
- audmakebuf(audEvent, vaLst);
- va_end(vaLst);
- break;
case AUD_FID: /* AFSFid - contains 3 entries */
vaFid = (struct AFSFid *)va_arg(vaList, struct AFSFid *);
if (vaFid) {
}
static void
-printbuf(FILE *out, int rec, char *audEvent, afs_int32 errCode, va_list vaList)
+printbuf(FILE *out, int rec, char *audEvent, char *afsName, afs_int32 hostId,
+ afs_int32 errCode, va_list vaList)
{
int vaEntry;
int vaInt;
fprintf(out, "[%d] ", num);
}
- if (strcmp(audEvent, "VALST") != 0)
- fprintf(out, "EVENT %s CODE %d ", audEvent, errCode);
+ fprintf(out, "EVENT %s CODE %d ", audEvent, errCode);
+
+ if (afsName) {
+ hostAddr.s_addr = hostId;
+ fprintf(out, "NAME %s HOST %s ", afsName, inet_ntoa(hostAddr));
+ }
vaEntry = va_arg(vaList, int);
while (vaEntry != AUD_END) {
vaLong = va_arg(vaList, afs_int32);
fprintf(out, "LONG %d ", vaLong);
break;
- case AUD_LST: /* Ptr to another list */
- va_copy(vaLst, vaList);
- printbuf(out, 1, "VALST", 0, vaLst);
- va_end(vaLst);
- break;
case AUD_FID: /* AFSFid - contains 3 entries */
vaFid = va_arg(vaList, struct AFSFid *);
if (vaFid)
break;
case AUD_FIDS: /* array of Fids */
vaFids = va_arg(vaList, struct AFSCBFids *);
- vaFid = NULL;
if (vaFids) {
int i;
- if (vaFid)
+
+ vaFid = vaFids->AFSCBFids_val;
+
+ if (vaFid) {
fprintf(out, "FIDS %u FID %u:%u:%u ", vaFids->AFSCBFids_len, vaFid->Volume,
vaFid->Vnode, vaFid->Unique);
- else
+ for ( i = 1; i < vaFids->AFSCBFids_len; i++, vaFid++ )
+ fprintf(out, "FID %u:%u:%u ", vaFid->Volume,
+ vaFid->Vnode, vaFid->Unique);
+ } else
fprintf(out, "FIDS 0 FID 0:0:0 ");
- for ( i = 1; i < vaFids->AFSCBFids_len; i++ ) {
- vaFid = vaFids->AFSCBFids_val;
- if (vaFid)
- fprintf(out, "FID %u:%u:%u ", vaFid->Volume,
- vaFid->Vnode, vaFid->Unique);
- else
- fprintf(out, "FID 0:0:0 ");
- }
}
break;
default:
vaEntry = va_arg(vaList, int);
} /* end while */
- if (strcmp(audEvent, "VALST") != 0)
- fprintf(out, "\n");
+ fprintf(out, "\n");
}
#ifdef AFS_PTHREAD_ENV
/* The routine that acually does the audit call.
* ************************************************************************** */
int
-osi_audit(char *audEvent, /* Event name (15 chars or less) */
- afs_int32 errCode, /* The error code */
- ...)
+osi_audit_internal(char *audEvent, /* Event name (15 chars or less) */
+ afs_int32 errCode, /* The error code */
+ char *afsName,
+ afs_int32 hostId,
+ va_list vaList)
{
#ifdef AFS_AIX32_ENV
afs_int32 code;
static char BUFFER[32768];
#endif
int result;
- va_list vaList;
+ va_list vaCopy;
#ifdef AFS_PTHREAD_ENV
/* i'm pretty sure all the server apps now call osi_audit_init(),
if (!osi_audit_all && !auditout)
return 0;
+ va_copy(vaCopy, vaList);
+
switch (errCode) {
case 0:
result = AUDIT_OK;
*(int *)bufferPtr = errCode;
bufferPtr += sizeof(errCode);
- va_start(vaList, errCode);
audmakebuf(audEvent, vaList);
#endif
if (osi_echo_trail) {
- va_start(vaList, errCode);
- printbuf(stdout, 0, audEvent, errCode, vaList);
+ printbuf(stdout, 0, audEvent, afsName, hostId, errCode, vaList);
}
+ va_end(vaCopy);
#ifdef AFS_AIX32_ENV
bufferLen = (int)((afs_int32) bufferPtr - (afs_int32) & BUFFER[0]);
code = auditlog(audEvent, result, BUFFER, bufferLen);
-#ifdef notdef
- if (code) {
- err = errno;
- code = auditlog("AFS_Aud_Fail", result, &err, sizeof(err));
- if (code)
- printf("Error while writing audit entry: %d.\n", errno);
- }
-#endif /* notdef */
#else
if (auditout) {
- va_start(vaList, errCode);
- printbuf(auditout, 0, audEvent, errCode, vaList);
+ printbuf(auditout, 0, audEvent, afsName, hostId, errCode, vaList);
fflush(auditout);
}
#endif
return 0;
}
+int
+osi_audit(char *audEvent, /* Event name (15 chars or less) */
+ afs_int32 errCode, /* The error code */
+ ...)
+{
+ va_list vaList;
+
+ if ((osi_audit_all < 0) || (osi_echo_trail < 0))
+ osi_audit_check();
+ if (!osi_audit_all && !auditout)
+ return 0;
+
+ va_start(vaList, errCode);
+ osi_audit_internal(audEvent, errCode, NULL, 0, vaList);
+ va_end(vaList);
+
+ return 0;
+}
/* ************************************************************************** */
/* Given a RPC call structure, this routine extracts the name and host id from the
break;
}
- if (i=0)
+ if (i == 0)
strncpy(local_realms[0], "UNKNOWN.LOCAL.REALM", AFS_REALM_SZ);
num_lrealms = i;
}
osi_audit("AFS_Aud_NoCall", (-1), AUD_STR, audEvent, AUD_END);
}
va_start(vaList, errCode);
- osi_audit(audEvent, errCode, AUD_NAME, afsName, AUD_HOST, hostId,
- AUD_LST, vaList, AUD_END);
-
+ osi_audit_internal(audEvent, errCode, afsName, hostId, vaList);
+ va_end(vaList);
return 0;
}
}
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;
}