PERFORCE change 164622 for review
Ilias Marinos
marinosi at FreeBSD.org
Wed Jun 17 20:23:12 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=164622
Change 164622 by marinosi at marinosi_redrum on 2009/06/17 20:23:07
Create audit_slice_create(), audit_slice_init(), audit_slice_destroy()
functions to smoothly handle slice management.
Affected files ...
.. //depot/projects/soc2009/marinosi_appaudit/src/sys/security/audit/audit.c#5 edit
.. //depot/projects/soc2009/marinosi_appaudit/src/sys/security/audit/audit_slice.h#3 edit
.. //depot/projects/soc2009/marinosi_appaudit/src/sys/security/audit/audit_syscalls.c#4 edit
Differences ...
==== //depot/projects/soc2009/marinosi_appaudit/src/sys/security/audit/audit.c#5 (text) ====
@@ -195,67 +195,31 @@
* synchronization primitives, worker thread, and trigger device node. Also
* call into the BSM assembly code to initialize it.
*/
-void
-audit_init(void *arg)
+static void
+audit_init(void)
{
- struct audit_slice *as;
+ struct audit_slice *as = NULL;
/*
* Initialize the slice queue and add every slice in it except the
- * base(no reason to be in the queue).
+ * base(no reason to be in the queue). We want the queue initialized
+ * once, even if there are no other slices except the base one and
+ * thus this is happening in audit_init().
*/
TAILQ_INIT(&audit_slice_q);
- if ( audit_base_slice == NULL && arg == NULL ) {
+ if ( audit_base_slice == NULL ) {
+ /*
+ * If base slice is null, allocate the base slice.
+ */
audit_base_slice = malloc(sizeof(*audit_base_slice),
M_AUDITSLICE, M_WAITOK | M_ZERO);
- /*
- * If base slice is null allocate and then initialize the base
- * slice first of all.
- */
as = audit_base_slice;
- } else {
- //as = (struct audit_slice *) arg;
- as = malloc(sizeof(*as), M_AUDITSLICE, M_WAITOK | M_ZERO);
- TAILQ_INSERT_TAIL(&audit_slice_q, as, as_q);
}
- /*
- * XXX: As M_ZERO flag is used during allocation, we may remove some
- * of the following initialization is useless.
- */
- as->audit_enabled = 0;
- as->audit_suspended = 0;
- as->audit_panic_on_write_fail = 0;
- as->audit_fail_stop = 0;
- as->audit_in_failure = 0;
- as->audit_argv = 0;
- as->audit_arge = 0;
-
-
-
- as->audit_fstat.af_filesz = 0; /* '0' means unset, unbounded. */
- as->audit_fstat.af_currsz = 0;
- as->audit_nae_mask.am_success = 0;
- as->audit_nae_mask.am_failure = 0;
-
- TAILQ_INIT(&(as->audit_q));
- as->audit_q_len = 0;
- as->audit_pre_q_len = 0;
- as->audit_qctrl.aq_hiwater = AQ_HIWATER;
- as->audit_qctrl.aq_lowater = AQ_LOWATER;
- as->audit_qctrl.aq_bufsz = AQ_BUFSZ;
- as->audit_qctrl.aq_minfree = AU_FS_MINFREE;
+ if ( as != NULL )
+ audit_slice_init(as, "base_slice");
- audit_kinfo.ai_termid.at_type = AU_IPv4;
- audit_kinfo.ai_termid.at_addr[0] = INADDR_ANY;
-
- mtx_init(&(as->audit_mtx), "audit_mtx", NULL, MTX_DEF);
- KINFO_LOCK_INIT();
- cv_init(&(as->audit_worker_cv), "audit_worker_cv");
- cv_init(&(as->audit_watermark_cv), "audit_watermark_cv");
- cv_init(&(as->audit_fail_cv), "audit_fail_cv");
-
audit_record_zone = uma_zcreate("audit_record",
sizeof(struct kaudit_record), audit_record_ctor,
audit_record_dtor, NULL, NULL, UMA_ALIGN_PTR, 0);
@@ -660,6 +624,80 @@
}
/*
+ * audit_slice_create() is called through A_CREATESLICE command of auditon()
+ * syscall to create a new slice.(except the base one!)
+ */
+void
+audit_slice_create(char *name)
+{
+ struct audit_slice *as = NULL;
+ int ret;
+
+ ret = 0;
+ as = malloc(sizeof(*as), M_AUDITSLICE, M_WAITOK | M_ZERO);
+ if ( as == NULL )
+ ret = 1; /* Failed to allocate slice */
+
+ TAILQ_INSERT_TAIL(&audit_slice_q, as, as_q);
+
+ /* Initialize the base slice */
+ audit_slice_init(as, name);
+
+ /* Start audit worker thread. */
+ audit_worker_init(as);
+}
+
+/*
+ * audit_slice_init() function is the initialization routine used for ALL
+ * slices (including the base one).
+ */
+void
+audit_slice_init(struct audit_slice *as, char *name)
+{
+ strcpy(as->as_name, name);
+
+ /*
+ * XXX: As M_ZERO flag is used during allocation, some of the
+ * following initilization is pointless and should be removed.
+ */
+ as->audit_enabled = 0;
+ as->audit_suspended = 0;
+ as->audit_panic_on_write_fail = 0;
+ as->audit_fail_stop = 0;
+ as->audit_in_failure = 0;
+ as->audit_argv = 0;
+ as->audit_arge = 0;
+
+
+
+ as->audit_fstat.af_filesz = 0; /* '0' means unset, unbounded. */
+ as->audit_fstat.af_currsz = 0;
+ as->audit_nae_mask.am_success = 0;
+ as->audit_nae_mask.am_failure = 0;
+
+ TAILQ_INIT(&(as->audit_q));
+ as->audit_q_len = 0;
+ as->audit_pre_q_len = 0;
+ as->audit_qctrl.aq_hiwater = AQ_HIWATER;
+ as->audit_qctrl.aq_lowater = AQ_LOWATER;
+ as->audit_qctrl.aq_bufsz = AQ_BUFSZ;
+ as->audit_qctrl.aq_minfree = AU_FS_MINFREE;
+
+ audit_kinfo.ai_termid.at_type = AU_IPv4;
+ audit_kinfo.ai_termid.at_addr[0] = INADDR_ANY;
+
+ mtx_init(&(as->audit_mtx), "audit_mtx", NULL, MTX_DEF);
+ if ( as == audit_base_slice )
+ KINFO_LOCK_INIT();
+
+ cv_init(&(as->audit_worker_cv), "audit_worker_cv");
+ cv_init(&(as->audit_watermark_cv), "audit_watermark_cv");
+ cv_init(&(as->audit_fail_cv), "audit_fail_cv");
+
+}
+
+
+/*
* audit_slice_destroy() is called through A_REMOVESLICE command of auditon()
* syscall to remove an existing slice ( except the base one!)
*/
==== //depot/projects/soc2009/marinosi_appaudit/src/sys/security/audit/audit_slice.h#3 (text+ko) ====
@@ -172,9 +172,9 @@
/*
* Audit related functions prototypes
*/
-
-void audit_init(void *arg);
void audit_rotate_vnode(struct ucred *cred,
struct vnode *vp);
void audit_worker_init(void *arg);
+void audit_slice_init(struct audit_slice *as, char *name);
+void audit_slice_create(char *name);
void audit_slice_destroy(struct audit_slice *as);
==== //depot/projects/soc2009/marinosi_appaudit/src/sys/security/audit/audit_syscalls.c#4 (text) ====
@@ -546,8 +546,7 @@
/* Check if slice exists? */
if ((udata.au_slice.as_name == NULL))
return (EINVAL);
- /* Passing null for testing purposes. TO be changed */
- audit_init(NULL);
+ audit_slice_create(udata.au_slice.as_name);
break;
case A_UPDATESLICE:
More information about the p4-projects
mailing list