PERFORCE change 45113 for review
Robert Watson
rwatson at FreeBSD.org
Sun Jan 11 06:18:59 GMT 2004
http://perforce.freebsd.org/chv.cgi?CH=45113
Change 45113 by rwatson at rwatson_paprika on 2004/01/10 22:17:59
Steps towards audit.c building on FreeBSD:
- Fix up include files.
- Lots of Darwin/FreeBSD-isms (synchronization, allocation, asserts..)
- FreeBSD uses threads as arguments to system calls, and doesn't
pass *retval.
- In fact, FreeBSD uses threads most places.
- FreeBSD requires C99.
- FreeBSD uses Giant not funnels for VFS.
Not there yet.
Affected files ...
.. //depot/projects/trustedbsd/audit2/sys/security/audit/audit.c#5 edit
Differences ...
==== //depot/projects/trustedbsd/audit2/sys/security/audit/audit.c#5 (text+ko) ====
@@ -22,32 +22,38 @@
*
* @APPLE_LICENSE_HEADER_END@
*/
+
#include <sys/param.h>
+#include <sys/audit.h>
+#include <sys/bsm_kevents.h>
#include <sys/condvar.h>
-#include <sys/lock.h>
-#include <sys/mutex.h>
#include <sys/fcntl.h>
-#include <sys/kernel.h>
-#include <sys/lock.h>
-#include <sys/namei.h>
+#include <sys/ipc.h>
#include <sys/proc.h>
#include <sys/queue.h>
+#include <sys/socket.h>
+#include <sys/sysproto.h>
#include <sys/systm.h>
-#include <sys/time.h>
#include <sys/ucred.h>
#include <sys/uio.h>
-#include <sys/unistd.h>
#include <sys/vnode.h>
-#include <sys/user.h>
-#include <sys/bsm_kevents.h>
-#include <sys/syscall.h>
-#include <sys/malloc.h>
-#include <sys/un.h>
-#include <sys/audit.h>
#include <security/audit/kern_audit.h>
#include <security/audit/bsm_klib.h>
+typedef struct mutex mutex_t;
+typedef struct cv wait_queue_t;
+
+#define kmem_alloc(map, ptrref, size)
+#define kmem_free(map, ptr, size)
+
+#define vn_rdwr(rw, vp, base, len, offset, segflg, ioflg, cred, resid, td) \
+ vn_rdwr((rw), (vp), (base), (len), (offset), (segflg), (ioflg), \
+ (cred), NULL, (resid), (td))
+
+#define mutex_lock(x) mtx_lock(x)
+#define mutex_unlock(x) mtx_unlock(x)
+
#ifdef AUDIT
/*
@@ -74,7 +80,7 @@
#include <kern/assert.h>
#endif /* DIAGNOSTIC */
#endif
-#define assert KASSERT
+#define assert(x) KASSERT(x, x)
/*
* Define the audit control flags.
@@ -131,7 +137,7 @@
* XXX: Couldn't find the include file for this, so copied kern_exec.c's
* behavior.
*/
-extern task_t kernel_task;
+// extern task_t kernel_task;
static void
audit_free(struct kaudit_record *ar)
@@ -159,7 +165,7 @@
static int
audit_write(struct vnode *vp, struct kaudit_record *ar, struct ucred *cred,
- struct proc *p)
+ struct thread *td)
{
int ret;
struct au_record *bsm;
@@ -176,7 +182,7 @@
*/
if (ar->k_udata != NULL) {
vn_rdwr(UIO_WRITE, vp, (void *)ar->k_udata, ar->k_ulen,
- (off_t)0, UIO_SYSSPACE, IO_APPEND|IO_UNIT, cred, NULL, p);
+ (off_t)0, UIO_SYSSPACE, IO_APPEND|IO_UNIT, cred, NULL, td);
}
/*
@@ -199,7 +205,7 @@
* take the BSM record as a parameter.
*/
ret = (vn_rdwr(UIO_WRITE, vp, (void *)bsm->data, bsm->len,
- (off_t)0, UIO_SYSSPACE, IO_APPEND|IO_UNIT, cred, NULL, p));
+ (off_t)0, UIO_SYSSPACE, IO_APPEND|IO_UNIT, cred, NULL, td));
kau_free(bsm);
@@ -207,27 +213,29 @@
}
static void
-audit_worker()
+audit_worker(void)
{
int do_replacement_signal, error, release_funnel;
TAILQ_HEAD(, kaudit_record) ar_worklist;
struct kaudit_record *ar, *ar_start, *ar_stop;
struct vnode *audit_vp, *old_vp;
struct ucred *audit_cred, *old_cred;
- struct proc *audit_p;
+ struct thread *audit_td;
AUDIT_PRINTF(("audit_worker starting\n"));
TAILQ_INIT(&ar_worklist);
audit_cred = NULL;
- audit_p = current_proc();
+ audit_td = curthread;
audit_vp = NULL;
/*
* XXX: Presumably we can assume Mach threads are started without
* holding the BSD kernel funnel?
*/
+#ifdef DARWIN_FOO
thread_funnel_set(kernel_flock, FALSE);
+#endif
mutex_lock(audit_mtx);
while (1) {
@@ -256,7 +264,11 @@
if (old_vp != NULL || audit_vp != NULL) {
mutex_unlock(audit_mtx);
+#ifdef DARWIN_FOO
thread_funnel_set(kernel_flock, TRUE);
+#else
+ mtx_lock(&Giant);
+#endif
release_funnel = 1;
} else
release_funnel = 0;
@@ -266,7 +278,7 @@
if (old_vp != NULL) {
AUDIT_PRINTF(("Closing old audit file\n"));
vn_close(old_vp, audit_close_flags, old_cred,
- audit_p);
+ audit_td);
crfree(old_cred);
old_cred = NULL;
old_vp = NULL;
@@ -276,7 +288,11 @@
AUDIT_PRINTF(("Opening new audit file\n"));
}
if (release_funnel) {
+#ifdef DARWIN_FOO
thread_funnel_set(kernel_flock, FALSE);
+#else
+ mtx_unlock(&Giant);
+#endif
mutex_lock(audit_mtx);
}
do_replacement_signal = 1;
@@ -369,13 +385,17 @@
* error here?
*/
if (!release_funnel) {
+#ifdef DARWIN_FOO
thread_funnel_set(kernel_flock, TRUE);
+#else
+ mtx_lock(&Giant);
+#endif
release_funnel = 1;
}
- VOP_LEASE(audit_vp, audit_p, audit_cred,
+ VOP_LEASE(audit_vp, audit_td, audit_cred,
LEASE_WRITE);
error = audit_write(audit_vp, ar, audit_cred,
- audit_p);
+ audit_td);
if (error)
printf("audit_worker: write error %d\n",
error);
@@ -383,7 +403,11 @@
audit_free(ar);
}
if (release_funnel)
+#ifdef DARWIN_FOO
thread_funnel_set(kernel_flock, FALSE);
+#else
+ mtx_unlock(&Giant);
+#endif
mutex_lock(audit_mtx);
}
}
@@ -482,18 +506,11 @@
audit_rotate_vnode(NULL, NULL);
}
-static __inline__ struct uthread *
-curuthread(void)
-{
-
- return (get_bsdthread_info(current_act()));
-}
-
static __inline__ struct kaudit_record *
currecord(void)
{
- return (curuthread()->uu_ar);
+ return (curthread->td_ar);
}
/**********************************
@@ -508,13 +525,9 @@
* work, since we pre-select only based on the AUE_audit event type,
* not the event type submitted as part of the user audit data.
*/
-struct audit_args {
- void * record;
- int length;
-};
/* ARGSUSED */
int
-audit(struct proc *p, struct audit_args *uap, register_t *retval)
+audit(struct thread *td, struct audit_args *uap)
{
register struct pcred *pc = p->p_cred;
int error;
@@ -573,7 +586,7 @@
};
/* ARGSUSED */
int
-auditon(struct proc *p, struct auditon_args *uap, register_t *retval)
+auditon(struct thread *td, struct auditon_args *uap)
{
register struct pcred *pc = p->p_cred;
int error;
@@ -593,7 +606,7 @@
};
/* ARGSUSED */
int
-auditsvc(struct proc *p, struct auditsvc_args *uap, register_t *retval)
+auditsvc(struct thread *td, struct auditsvc_args *uap)
{
register struct pcred *pc = p->p_cred;
int error;
@@ -613,7 +626,7 @@
};
/* ARGSUSED */
int
-getauid(struct proc *p, struct getauid_args *uap, register_t *retval)
+getauid(struct thread *td, struct getauid_args *uap)
{
register struct pcred *pc = p->p_cred;
int error;
@@ -635,7 +648,7 @@
};
/* ARGSUSED */
int
-setauid(struct proc *p, struct setauid_args *uap, register_t *retval)
+setauid(struct thread *td, struct setauid_args *uap)
{
register struct pcred *pc = p->p_cred;
int error;
@@ -661,7 +674,7 @@
};
/* ARGSUSED */
int
-getaudit(struct proc *p, struct getaudit_args *uap, register_t *retval)
+getaudit(struct thread *td, struct getaudit_args *uap)
{
register struct pcred *pc = p->p_cred;
int error;
@@ -682,7 +695,7 @@
};
/* ARGSUSED */
int
-setaudit(struct proc *p, struct setaudit_args *uap, register_t *retval)
+setaudit(struct thread *td, struct setaudit_args *uap)
{
register struct pcred *pc = p->p_cred;
int error;
@@ -704,7 +717,7 @@
};
/* ARGSUSED */
int
-getaudit_addr(struct proc *p, struct getaudit_addr_args *uap, register_t *retval)
+getaudit_addr(struct thread *td, struct getaudit_addr_args *uap)
{
register struct pcred *pc = p->p_cred;
int error;
@@ -721,7 +734,7 @@
};
/* ARGSUSED */
int
-setaudit_addr(struct proc *p, struct setaudit_addr_args *uap, register_t *retval)
+setaudit_addr(struct thread *td, struct setaudit_addr_args *uap)
{
register struct pcred *pc = p->p_cred;
int error;
@@ -742,7 +755,7 @@
};
/* ARGSUSED */
int
-auditctl(struct proc *p, struct auditctl_args *uap)
+auditctl(struct thread *td, struct auditctl_args *uap)
{
struct kaudit_record *ar;
struct nameidata nd;
@@ -1516,61 +1529,61 @@
}
int
-audit(struct proc *p, struct audit_args *uap, register_t *retval)
+audit(struct thread *td, struct audit_args *uap)
{
return (ENOSYS);
}
int
-auditon(struct proc *p, struct auditon_args *uap, register_t *retval)
+auditon(struct thread *td, struct auditon_args *uap)
{
return (ENOSYS);
}
int
-auditsvc(struct proc *p, struct auditsvc_args *uap, register_t *retval)
+auditsvc(struct thread *td, struct auditsvc_args *uap)
{
return (ENOSYS);
}
int
-getauid(struct proc *p, struct getauid_args *uap, register_t *retval)
+getauid(struct thread *td, struct getauid_args *uap)
{
return (ENOSYS);
}
int
-setauid(struct proc *p, struct setauid_args *uap, register_t *retval)
+setauid(struct thread *td, struct setauid_args *uap)
{
return (ENOSYS);
}
int
-getaudit(struct proc *p, struct getaudit_args *uap, register_t *retval)
+getaudit(struct thread *td, struct getaudit_args *uap)
{
return (ENOSYS);
}
int
-setaudit(struct proc *p, struct setaudit_args *uap, register_t *retval)
+setaudit(struct thread *td, struct setaudit_args *uap)
{
return (ENOSYS);
}
int
-getaudit_addr(struct proc *p, struct getaudit_addr_args *uap, register_t *retval)
+getaudit_addr(struct thread *td, struct getaudit_addr_args *uap)
{
return (ENOSYS);
}
int
-setaudit_addr(struct proc *p, struct setaudit_addr_args *uap, register_t *retval)
+setaudit_addr(struct thread *td, struct setaudit_addr_args *uap)
{
return (ENOSYS);
}
int
-auditctl(struct proc *p, struct auditctl_args *uap, register_t *retval)
+auditctl(struct thread *td, struct auditctl_args *uap)
{
return (ENOSYS);
}
To Unsubscribe: send mail to majordomo at trustedbsd.org
with "unsubscribe trustedbsd-cvs" in the body of the message
More information about the trustedbsd-cvs
mailing list