rendered paste bodycommit 82a38ce65490afbec5d4d1c29bd97f7d7e94d861Author: Matt Benjamin <matt@linuxbox.com>Date: Wed Jun 1 19:29:50 2011 -0400 Audit BCB Add support to conditionally report callback breaks to the audit channel. Example: Wed Jun 01 19:29:01 2011 [4] EVENT AFS_SRX_BreakCallBack CODE 0 FID 536870915:772:4666 NCBAS 1 HOST 1023475978 PORT 22811diff --git a/src/audit/audit.c b/src/audit/audit.cindex 3bb5f76..d302e75 100644--- a/src/audit/audit.c+++ b/src/audit/audit.c@@ -28,6 +28,9 @@ #include "audit.h" #include "audit-api.h" #include "lock.h"+#include <afs/ptclient.h> /* need definition of prlist for host.h */+#include "../viced/callback.h"+#include "../viced/host.h" #include <afs/afsutil.h> @@ -111,6 +114,8 @@ audmakebuf(char *audEvent, va_list vaList) *(afs_int32 *) bufferPtr = vaLong; bufferPtr += sizeof(vaLong); break;+ case AUD_CBAS: /* struct cbstruct array */+ break; case AUD_FID: /* AFSFid - contains 3 entries */ vaFid = (struct AFSFid *)va_arg(vaList, struct AFSFid *); if (vaFid) {@@ -167,11 +172,13 @@ printbuf(int rec, char *audEvent, char *afsName, afs_int32 hostId, char *vaStr; struct AFSFid *vaFid; struct AFSCBFids *vaFids;+ struct cbstruct_arr *vaCbsr; int num = LogThreadNum(); struct in_addr hostAddr; time_t currenttime; char tbuffer[26]; struct tm tm;+ int ix; /* Don't print the timestamp or thread id if we recursed */ if (rec == 0) {@@ -236,6 +243,19 @@ printbuf(int rec, char *audEvent, char *afsName, afs_int32 hostId, vaLong = va_arg(vaList, afs_int32); audit_ops->append_msg("LONG %d ", vaLong); break;+ case AUD_CBAS: /* array of cbstruct */+ vaCbsr = va_arg(vaList, struct cbstruct_arr *);+ if (vaCbsr) {+ audit_ops->append_msg("NCBAS %d ", vaCbsr->len);+ for (ix = 0; ix < vaCbsr->len; ++ix) {+ struct cbstruct *cba = &(vaCbsr->data[ix]);+ struct host *hp = cba->hp;+ audit_ops->append_msg("HOST %d PORT %d",+ hp->host,+ hp->port);+ }+ }+ break; case AUD_FID: /* AFSFid - contains 3 entries */ vaFid = va_arg(vaList, struct AFSFid *); if (vaFid)diff --git a/src/audit/audit.h b/src/audit/audit.hindex 0014f86..b9cba92 100644--- a/src/audit/audit.h+++ b/src/audit/audit.h@@ -23,6 +23,7 @@ #define AUD_RESID 20 /* resid in variable list */ #define AUD_RSSIZERANGE 21 /* rssizerange in variable list */ #define AUD_LOOKUPINFO 22 /* LookupInfo in variable list */+#define AUD_CBAS 23 /* array of struct cbstruct in var. list */ /* * Note: the master definitions of these error codes come from *.et@@ -190,6 +191,7 @@ #define SetExtendedVolumeAttributesEvent "AFS_SRX_SetVA" #define GetStatisticsEvent "AFS_SRX_GetStats" #define XStatsVersionEvent "AFS_SRX_XStatsVer"+#define BreakCallbackEvent "AFS_SRX_BreakCallBack" #define NoAuthEvent "AFS_RunNoAuth" #define NoAuthDisableEvent "AFS_NoAuthDsbl"diff --git a/src/viced/callback.c b/src/viced/callback.cindex 7cdb18e..a6666df 100644--- a/src/viced/callback.c+++ b/src/viced/callback.c@@ -102,6 +102,7 @@ #include <afs/ihandle.h> #include <afs/vnode.h> #include <afs/volume.h>+#include <afs/audit.h> #include "viced_prototypes.h" #include "viced.h" @@ -796,6 +797,7 @@ BreakCallBack(struct host *xhost, AFSFid * fid, int flag) struct CallBack *cb, *nextcb; struct cbstruct cbaDef[MAX_CB_HOSTS], *cba = cbaDef; unsigned int ncbas, cbaAlloc = MAX_CB_HOSTS;+ struct cbstruct_arr cbsr[1]; struct AFSCBFids tf; int hostindex; char hoststr[16];@@ -868,6 +870,14 @@ BreakCallBack(struct host *xhost, AFSFid * fid, int flag) struct cbstruct *cba2; int num; + /* conditionally audit BCBs */+ if (audit_bcb) {+ cbsr->data = cba;+ cbsr->len = ncbas;+ osi_audit(BreakCallbackEvent, 0, AUD_FID, fid, AUD_CBAS, cbsr,+ AUD_END);+ }+ for (cba2 = cba, num = ncbas; ncbas > 0; cba2 += num, ncbas -= num) { num = (ncbas > MAX_CB_HOSTS) ? MAX_CB_HOSTS : ncbas; MultiBreakCallBack_r(cba2, num, &tf);diff --git a/src/viced/callback.h b/src/viced/callback.hindex 58e6ee0..7b00c2b 100644--- a/src/viced/callback.h+++ b/src/viced/callback.h@@ -46,6 +46,11 @@ struct cbstruct { afs_uint32 thead; }; +struct cbstruct_arr {+ unsigned long len;+ struct cbstruct *data;+};+ /* structure MUST be multiple of 8 bytes, otherwise the casts to * struct object will have alignment issues on *P64 userspaces */ struct FileEntry {diff --git a/src/viced/viced.c b/src/viced/viced.cindex e9770fd..83bb9f6 100644--- a/src/viced/viced.c+++ b/src/viced/viced.c@@ -175,6 +175,7 @@ int abort_threshold = 10; int udpBufSize = 0; /* UDP buffer size for receive */ int sendBufSize = 16384; /* send buffer size */ int saneacls = 0; /* Sane ACLs Flag */+int audit_bcb; /* Audit BCB Flag */ static int unsafe_attach = 0; /* avoid inUse check on vol attach? */ static int offline_timeout = -1; /* -offline-timeout option */ static int offline_shutdown_timeout = -1; /* -offline-shutdown-timeout option */@@ -892,6 +893,7 @@ FlagMsg(void) fputs("Usage: fileserver ", stdout); fputs("[-auditlog <log path>] ", stdout); fputs("[-audit-interface <file|sysvmq> (default is file)] ", stdout);+ fputs("[-audit-bcb] ", stdout); fputs("[-d <debug level>] ", stdout); fputs("[-p <number of processes>] ", stdout); fputs("[-spare <number of spare blocks>] ", stdout);@@ -1405,6 +1407,9 @@ ParseArgs(int argc, char *argv[]) return -1; } }+ else if (strcmp(argv[i], "-audit-bcb") == 0) {+ audit_bcb = 1;+ } #ifndef AFS_NT40_ENV else if (strcmp(argv[i], "-syslog") == 0) { /* set syslog logging flag */diff --git a/src/viced/viced.h b/src/viced/viced.hindex 09e2bf3..cc645ca 100644--- a/src/viced/viced.h+++ b/src/viced/viced.h@@ -182,6 +182,8 @@ struct AFSStatistics { extern int busyonrst; extern int saneacls;+extern int audit_bcb;+ #define RESTART_ORDINARY 1 #define RESTART_FAST 2