summaryrefslogtreecommitdiffstats
path: root/contrib/openbsm/libbsm
diff options
context:
space:
mode:
authorrwatson <rwatson@FreeBSD.org>2008-12-02 23:26:43 +0000
committerrwatson <rwatson@FreeBSD.org>2008-12-02 23:26:43 +0000
commit0ac6f8ebdfebed8ad6c6fa1334d227524df2c013 (patch)
tree909e4490f5c6d4141d466ad2fdf963beeb90afca /contrib/openbsm/libbsm
parent1383cec09e16a1fb5117c67951f100e7931363e7 (diff)
parent208cf4160e79a64866887cc5f89f964cc899f97e (diff)
downloadFreeBSD-src-0ac6f8ebdfebed8ad6c6fa1334d227524df2c013.zip
FreeBSD-src-0ac6f8ebdfebed8ad6c6fa1334d227524df2c013.tar.gz
Merge OpenBSM 1.1 alpha 2 from the OpenBSM vendor branch to head, both
contrib/openbsm (svn merge) and sys/{bsm,security/audit} (manual merge). - Add OpenBSM contrib tree to include paths for audit(8) and auditd(8). - Merge support for new tokens, fixes to existing token generation to audit_bsm_token.c. - Synchronize bsm includes and definitions. OpenBSM history for imported revisions below for reference. MFC after: 1 month Sponsored by: Apple Inc. Obtained from: TrustedBSD Project -- OpenBSM 1.1 alpha 2 - Include files in OpenBSM are now broken out into two parts: library builds required solely for user space, and system includes, which may also be required for use in the kernels of systems integrating OpenBSM. Submitted by Stacey Son. - Configure option --with-native-includes allows forcing the use of native include for system includes, rather than the versions bundled with OpenBSM. This is intended specifically for platforms that ship OpenBSM, have adapted versions of the system includes in a kernel source tree, and will use the OpenBSM build infrastructure with an unmodified OpenBSM distribution, allowing the customized system includes to be used with the OpenBSM build. Submitted by Stacey Son. - Various strcpy()'s/strcat()'s have been changed to strlcpy()'s/strlcat()'s or asprintf(). Added compat/strlcpy.h for Linux. - Remove compatibility defines for old Darwin token constant names; now only BSM token names are provided and used. - Add support for extended header tokens, which contain space for information on the host generating the record. - Add support for setting extended host information in the kernel, which is used for setting host information in extended header tokens. The audit_control file now supports a "host" parameter which can be used by auditd to set the information; if not present, the kernel parameters won't be set and auditd uses unextended headers for records that it generates. OpenBSM 1.1 alpha 1 - Add option to auditreduce(1) which allows users to invert sense of matching, such that BSM records that do not match, are selected. - Fix bug in audit_write() where we commit an incomplete record in the event there is an error writing the subject token. This was submitted by Diego Giagio. - Build support for Mac OS X 10.5.1 submitted by Eric Hall. - Fix a bug which resulted in host XML attributes not being arguments so that const strings can be passed as arguments to tokens. This patch was submitted by Xin LI. - Modify the -m option so users can select more then one audit event. - For Mac OS X, added Mach IPC support for audit trigger messages. - Fixed a bug in getacna() which resulted in a locking problem on Mac OS X. - Added LOG_PERROR flag to openlog when -d option is used with auditd. - AUE events added for Mac OS X Leopard system calls.
Diffstat (limited to 'contrib/openbsm/libbsm')
-rw-r--r--contrib/openbsm/libbsm/Makefile.am8
-rw-r--r--contrib/openbsm/libbsm/Makefile.in6
-rw-r--r--contrib/openbsm/libbsm/au_class.32
-rw-r--r--contrib/openbsm/libbsm/au_free_token.36
-rw-r--r--contrib/openbsm/libbsm/au_token.326
-rw-r--r--contrib/openbsm/libbsm/audit_submit.36
-rw-r--r--contrib/openbsm/libbsm/bsm_audit.c61
-rw-r--r--contrib/openbsm/libbsm/bsm_class.c17
-rw-r--r--contrib/openbsm/libbsm/bsm_control.c51
-rw-r--r--contrib/openbsm/libbsm/bsm_event.c21
-rw-r--r--contrib/openbsm/libbsm/bsm_flags.c18
-rw-r--r--contrib/openbsm/libbsm/bsm_io.c84
-rw-r--r--contrib/openbsm/libbsm/bsm_mask.c8
-rw-r--r--contrib/openbsm/libbsm/bsm_notify.c10
-rw-r--r--contrib/openbsm/libbsm/bsm_token.c156
-rw-r--r--contrib/openbsm/libbsm/bsm_user.c16
-rw-r--r--contrib/openbsm/libbsm/bsm_wrappers.c10
17 files changed, 345 insertions, 161 deletions
diff --git a/contrib/openbsm/libbsm/Makefile.am b/contrib/openbsm/libbsm/Makefile.am
index 5e4a317..d4e31fe 100644
--- a/contrib/openbsm/libbsm/Makefile.am
+++ b/contrib/openbsm/libbsm/Makefile.am
@@ -1,8 +1,12 @@
#
-# $P4: //depot/projects/trustedbsd/openbsm/libbsm/Makefile.am#3 $
+# $P4: //depot/projects/trustedbsd/openbsm/libbsm/Makefile.am#5 $
#
-INCLUDES = -I$(top_srcdir)
+if USE_NATIVE_INCLUDES
+INCLUDES = -I$(top_builddir) -I$(top_srcdir)
+else
+INCLUDES = -I$(top_builddir) -I$(top_srcdir) -I$(top_srcdir)/sys
+endif
lib_LTLIBRARIES = libbsm.la
diff --git a/contrib/openbsm/libbsm/Makefile.in b/contrib/openbsm/libbsm/Makefile.in
index d9da623..dd09ce0 100644
--- a/contrib/openbsm/libbsm/Makefile.in
+++ b/contrib/openbsm/libbsm/Makefile.in
@@ -15,7 +15,7 @@
@SET_MAKE@
#
-# $P4: //depot/projects/trustedbsd/openbsm/libbsm/Makefile.in#5 $
+# $P4: //depot/projects/trustedbsd/openbsm/libbsm/Makefile.in#9 $
#
VPATH = @srcdir@
@@ -129,6 +129,7 @@ LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAINT = @MAINT@
MAKEINFO = @MAKEINFO@
+MIG = @MIG@
MKDIR_P = @MKDIR_P@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
@@ -195,7 +196,8 @@ sysconfdir = @sysconfdir@
target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
-INCLUDES = -I$(top_srcdir)
+@USE_NATIVE_INCLUDES_FALSE@INCLUDES = -I$(top_builddir) -I$(top_srcdir) -I$(top_srcdir)/sys
+@USE_NATIVE_INCLUDES_TRUE@INCLUDES = -I$(top_builddir) -I$(top_srcdir)
lib_LTLIBRARIES = libbsm.la
libbsm_la_SOURCES = bsm_audit.c bsm_class.c bsm_control.c bsm_event.c \
bsm_flags.c bsm_io.c bsm_mask.c bsm_token.c bsm_user.c \
diff --git a/contrib/openbsm/libbsm/au_class.3 b/contrib/openbsm/libbsm/au_class.3
index d270b52..a3f200f 100644
--- a/contrib/openbsm/libbsm/au_class.3
+++ b/contrib/openbsm/libbsm/au_class.3
@@ -23,7 +23,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/libbsm/au_class.3#6 $
+.\" $P4: //depot/projects/trustedbsd/openbsm/libbsm/au_class.3#7 $
.\"
.Dd April 19, 2005
.Dt AU_CLASS 3
diff --git a/contrib/openbsm/libbsm/au_free_token.3 b/contrib/openbsm/libbsm/au_free_token.3
index 7ce109a..223d50a 100644
--- a/contrib/openbsm/libbsm/au_free_token.3
+++ b/contrib/openbsm/libbsm/au_free_token.3
@@ -1,5 +1,5 @@
.\"-
-.\" Copyright (c) 2004 Apple Computer, Inc.
+.\" Copyright (c) 2004 Apple Inc.
.\" Copyright (c) 2005 Robert N. M. Watson
.\" All rights reserved.
.\"
@@ -11,7 +11,7 @@
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
-.\" 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+.\" 3. Neither the name of Apple Inc. ("Apple") nor the names of
.\" its contributors may be used to endorse or promote products derived
.\" from this software without specific prior written permission.
.\"
@@ -27,7 +27,7 @@
.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/libbsm/au_free_token.3#6 $
+.\" $P4: //depot/projects/trustedbsd/openbsm/libbsm/au_free_token.3#7 $
.\"
.Dd April 19, 2005
.Dt AU_FREE_TOKEN 3
diff --git a/contrib/openbsm/libbsm/au_token.3 b/contrib/openbsm/libbsm/au_token.3
index e4ea65f..cb8ef70 100644
--- a/contrib/openbsm/libbsm/au_token.3
+++ b/contrib/openbsm/libbsm/au_token.3
@@ -23,7 +23,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/libbsm/au_token.3#13 $
+.\" $P4: //depot/projects/trustedbsd/openbsm/libbsm/au_token.3#15 $
.\"
.Dd April 19, 2005
.Dt AU_TOKEN 3
@@ -72,6 +72,8 @@
.Nm au_to_header ,
.Nm au_to_header32 ,
.Nm au_to_header64 ,
+.Nm au_to_header_ex ,
+.Nm au_to_header32_ex ,
.Nm au_to_trailer ,
.Nm au_to_zonename
.Nd "routines for generating BSM audit tokens"
@@ -80,11 +82,11 @@
.Sh SYNOPSIS
.In bsm/libbsm.h
.Ft "token_t *"
-.Fn au_to_arg32 "char n" "char *text" "u_int32_t v"
+.Fn au_to_arg32 "char n" "const char *text" "u_int32_t v"
.Ft "token_t *"
-.Fn au_to_arg64 "char n" "char *text" "u_int64_t v"
+.Fn au_to_arg64 "char n" "const char *text" "u_int64_t v"
.Ft "token_t *"
-.Fn au_to_arg "char n" "char *text" "u_int32_t v"
+.Fn au_to_arg "char n" "const char *text" "u_int32_t v"
.Ft "token_t *"
.Fn au_to_attr32 "struct vattr *attr"
.Ft "token_t *"
@@ -92,7 +94,7 @@
.Ft "token_t *"
.Fn au_to_attr "struct vattr *attr"
.Ft "token_t *"
-.Fn au_to_data "char unit_print" "char unit_type" "char unit_count" "char *p"
+.Fn au_to_data "char unit_print" "char unit_type" "char unit_count" "const char *p"
.Ft "token_t *"
.Fn au_to_exit "int retval" "int err"
.Ft "token_t *"
@@ -112,13 +114,13 @@
.Ft "token_t *"
.Fn au_to_iport "u_int16_t iport"
.Ft "token_t *"
-.Fn au_to_opaque "char *data" "u_int16_t bytes"
+.Fn au_to_opaque "const char *data" "u_int16_t bytes"
.Ft "token_t *"
-.Fn au_to_file "char *file" "struct timeval tm"
+.Fn au_to_file "const char *file" "struct timeval tm"
.Ft "token_t *"
-.Fn au_to_text "char *text"
+.Fn au_to_text "const char *text"
.Ft "token_t *"
-.Fn au_to_path "char *text"
+.Fn au_to_path "const char *text"
.Ft "token_t *"
.Fo au_to_process32
.Fa "au_id_t auid" "uid_t euid" "gid_t egid" "uid_t ruid"
@@ -196,9 +198,13 @@
.Ft "token_t *"
.Fn au_to_header64 "int rec_size" "au_event_t e_type" "au_emod_t e_mod"
.Ft "token_t *"
+.Fn au_to_header_ex "int rec_size" "au_event_t e_type" "au_emod_t e_mod"
+.Ft "token_t *"
+.Fn au_to_header32_ex "int rec_size" "au_event_t e_type" "au_emod_t e_mod"
+.Ft "token_t *"
.Fn au_to_trailer "int rec_size"
.Ft "token_t *"
-.Fn au_to_zonename "char *zonename"
+.Fn au_to_zonename "const char *zonename"
.Sh DESCRIPTION
These interfaces support the allocation of BSM audit tokens, represented by
.Vt token_t ,
diff --git a/contrib/openbsm/libbsm/audit_submit.3 b/contrib/openbsm/libbsm/audit_submit.3
index 609468c..6a61d99 100644
--- a/contrib/openbsm/libbsm/audit_submit.3
+++ b/contrib/openbsm/libbsm/audit_submit.3
@@ -27,9 +27,9 @@
.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $P4: //depot/projects/trustedbsd/openbsm/libbsm/audit_submit.3#12 $
+.\" $P4: //depot/projects/trustedbsd/openbsm/libbsm/audit_submit.3#14 $
.\"
-.Dd May 29, 2006
+.Dd January 18, 2008
.Dt audit_submit 3
.Os
.Sh NAME
@@ -53,7 +53,7 @@ return token, and a trailer.
The header will contain the event class specified by
.Fa au_event .
The subject token will be generated based on
-.Fa au_ctx .
+.Fa auid .
The return token is dependent on the
.Fa status
and
diff --git a/contrib/openbsm/libbsm/bsm_audit.c b/contrib/openbsm/libbsm/bsm_audit.c
index 2f6df41..2fd9466 100644
--- a/contrib/openbsm/libbsm/bsm_audit.c
+++ b/contrib/openbsm/libbsm/bsm_audit.c
@@ -1,5 +1,5 @@
-/*
- * Copyright (c) 2004 Apple Computer, Inc.
+/*-
+ * Copyright (c) 2004 Apple Inc.
* Copyright (c) 2005 SPARTA, Inc.
* All rights reserved.
*
@@ -30,7 +30,7 @@
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_audit.c#28 $
+ * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_audit.c#31 $
*/
#include <sys/types.h>
@@ -45,6 +45,8 @@
#include <bsm/audit_internal.h>
#include <bsm/libbsm.h>
+#include <netinet/in.h>
+
#include <errno.h>
#include <pthread.h>
#include <stdlib.h>
@@ -204,12 +206,55 @@ static int
au_assemble(au_record_t *rec, short event)
{
token_t *header, *tok, *trailer;
- size_t tot_rec_size;
+ size_t tot_rec_size, hdrsize;
u_char *dptr;
+ struct in6_addr *aptr;
int error;
+ struct auditinfo_addr aia;
+ struct timeval tm;
- tot_rec_size = rec->len + AUDIT_HEADER_SIZE + AUDIT_TRAILER_SIZE;
- header = au_to_header32(tot_rec_size, event, 0);
+#ifdef HAVE_AUDIT_SYSCALLS
+ /*
+ * Grab the size of the address family stored in the kernel's audit
+ * state.
+ */
+ aia.ai_termid.at_type = AU_IPv4;
+ aia.ai_termid.at_addr[0] = INADDR_ANY;
+ if (auditon(A_GETKAUDIT, &aia, sizeof(aia)) < 0) {
+ if (errno != ENOSYS)
+ return (-1);
+#endif /* HAVE_AUDIT_SYSCALLS */
+ tot_rec_size = rec->len + AUDIT_HEADER_SIZE +
+ AUDIT_TRAILER_SIZE;
+ header = au_to_header(tot_rec_size, event, 0);
+#ifdef HAVE_AUDIT_SYSCALLS
+ } else {
+ if (gettimeofday(&tm, NULL) < 0)
+ return (-1);
+ switch (aia.ai_termid.at_type) {
+ case AU_IPv4:
+ hdrsize = (aia.ai_termid.at_addr[0] == INADDR_ANY) ?
+ AUDIT_HEADER_SIZE : AUDIT_HEADER_EX_SIZE(&aia);
+ break;
+ case AU_IPv6:
+ aptr = (struct in6_addr *)&aia.ai_termid.at_addr[0];
+ hdrsize =
+ (IN6_IS_ADDR_UNSPECIFIED(aptr)) ?
+ AUDIT_HEADER_SIZE : AUDIT_HEADER_EX_SIZE(&aia);
+ break;
+ }
+ tot_rec_size = rec->len + hdrsize + AUDIT_TRAILER_SIZE;
+ /*
+ * A header size greater then AUDIT_HEADER_SIZE means
+ * that we are using an extended header.
+ */
+ if (hdrsize > AUDIT_HEADER_SIZE)
+ header = au_to_header32_ex_tm(tot_rec_size, event,
+ 0, tm, &aia);
+ else
+ header = au_to_header(tot_rec_size, event, 0);
+ }
+#endif /* HAVE_AUDIT_SYSCALLS */
if (header == NULL)
return (-1);
@@ -285,7 +330,7 @@ au_close(int d, int keep, short event)
goto cleanup;
}
- tot_rec_size = rec->len + AUDIT_HEADER_SIZE + AUDIT_TRAILER_SIZE;
+ tot_rec_size = rec->len + MAX_AUDIT_HEADER_SIZE + AUDIT_TRAILER_SIZE;
if (tot_rec_size > MAX_AUDIT_RECORD_SIZE) {
/*
@@ -335,7 +380,7 @@ au_close_buffer(int d, short event, u_char *buffer, size_t *buflen)
}
retval = 0;
- tot_rec_size = rec->len + AUDIT_HEADER_SIZE + AUDIT_TRAILER_SIZE;
+ tot_rec_size = rec->len + MAX_AUDIT_HEADER_SIZE + AUDIT_TRAILER_SIZE;
if ((tot_rec_size > MAX_AUDIT_RECORD_SIZE) ||
(tot_rec_size > *buflen)) {
/*
diff --git a/contrib/openbsm/libbsm/bsm_class.c b/contrib/openbsm/libbsm/bsm_class.c
index 5982d7e..0acfed4 100644
--- a/contrib/openbsm/libbsm/bsm_class.c
+++ b/contrib/openbsm/libbsm/bsm_class.c
@@ -1,5 +1,5 @@
-/*
- * Copyright (c) 2004 Apple Computer, Inc.
+/*-
+ * Copyright (c) 2004 Apple Inc.
* Copyright (c) 2006 Robert N. M. Watson
* All rights reserved.
*
@@ -27,9 +27,11 @@
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_class.c#11 $
+ * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_class.c#14 $
*/
+#include <config/config.h>
+
#include <bsm/libbsm.h>
#include <string.h>
@@ -37,6 +39,10 @@
#include <stdio.h>
#include <stdlib.h>
+#ifndef HAVE_STRLCPY
+#include <compat/strlcpy.h>
+#endif
+
/*
* Parse the contents of the audit_class file to return struct au_class_ent
* entries.
@@ -70,15 +76,14 @@ classfromstr(char *str, struct au_class_ent *c)
*/
if (strlen(classname) >= AU_CLASS_NAME_MAX)
return (NULL);
-
- strcpy(c->ac_name, classname);
+ strlcpy(c->ac_name, classname, AU_CLASS_NAME_MAX);
/*
* Check for very large class description.
*/
if (strlen(classdesc) >= AU_CLASS_DESC_MAX)
return (NULL);
- strcpy(c->ac_desc, classdesc);
+ strlcpy(c->ac_desc, classdesc, AU_CLASS_DESC_MAX);
c->ac_class = strtoul(classflag, (char **) NULL, 0);
return (c);
diff --git a/contrib/openbsm/libbsm/bsm_control.c b/contrib/openbsm/libbsm/bsm_control.c
index dd901b7..96cbc23 100644
--- a/contrib/openbsm/libbsm/bsm_control.c
+++ b/contrib/openbsm/libbsm/bsm_control.c
@@ -1,5 +1,5 @@
-/*
- * Copyright (c) 2004 Apple Computer, Inc.
+/*-
+ * Copyright (c) 2004 Apple Inc.
* Copyright (c) 2006 Robert N. M. Watson
* All rights reserved.
*
@@ -11,7 +11,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * 3. Neither the name of Apple Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
@@ -27,9 +27,11 @@
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_control.c#16 $
+ * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_control.c#23 $
*/
+#include <config/config.h>
+
#include <bsm/libbsm.h>
#include <errno.h>
@@ -38,10 +40,12 @@
#include <stdio.h>
#include <stdlib.h>
-#include <config/config.h>
#ifndef HAVE_STRLCAT
#include <compat/strlcat.h>
#endif
+#ifndef HAVE_STRLCPY
+#include <compat/strlcpy.h>
+#endif
/*
* Parse the contents of the audit_control file to return the audit control
@@ -363,11 +367,11 @@ getacdir(char *name, int len)
pthread_mutex_unlock(&mutex);
return (-1);
}
- if (strlen(dir) >= len) {
+ if (strlen(dir) >= (size_t)len) {
pthread_mutex_unlock(&mutex);
return (-3);
}
- strcpy(name, dir);
+ strlcpy(name, dir, len);
pthread_mutex_unlock(&mutex);
return (ret);
}
@@ -453,11 +457,11 @@ getacflg(char *auditstr, int len)
pthread_mutex_unlock(&mutex);
return (1);
}
- if (strlen(str) >= len) {
+ if (strlen(str) >= (size_t)len) {
pthread_mutex_unlock(&mutex);
return (-3);
}
- strcpy(auditstr, str);
+ strlcpy(auditstr, str, len);
pthread_mutex_unlock(&mutex);
return (0);
}
@@ -480,11 +484,12 @@ getacna(char *auditstr, int len)
pthread_mutex_unlock(&mutex);
return (1);
}
- if (strlen(str) >= len) {
+ if (strlen(str) >= (size_t)len) {
pthread_mutex_unlock(&mutex);
return (-3);
}
- strcpy(auditstr, str);
+ strlcpy(auditstr, str, len);
+ pthread_mutex_unlock(&mutex);
return (0);
}
@@ -510,6 +515,30 @@ getacpol(char *auditstr, size_t len)
pthread_mutex_unlock(&mutex);
return (-3);
}
+ strlcpy(auditstr, str, len);
+ pthread_mutex_unlock(&mutex);
+ return (0);
+}
+
+int
+getachost(char *auditstr, size_t len)
+{
+ char *str;
+
+ pthread_mutex_lock(&mutex);
+ setac_locked();
+ if (getstrfromtype_locked(AUDIT_HOST_CONTROL_ENTRY, &str) < 0) {
+ pthread_mutex_unlock(&mutex);
+ return (-2);
+ }
+ if (str == NULL) {
+ pthread_mutex_unlock(&mutex);
+ return (1);
+ }
+ if (strlen(str) >= len) {
+ pthread_mutex_unlock(&mutex);
+ return (-3);
+ }
strcpy(auditstr, str);
pthread_mutex_unlock(&mutex);
return (0);
diff --git a/contrib/openbsm/libbsm/bsm_event.c b/contrib/openbsm/libbsm/bsm_event.c
index 092d176..695e617c 100644
--- a/contrib/openbsm/libbsm/bsm_event.c
+++ b/contrib/openbsm/libbsm/bsm_event.c
@@ -1,5 +1,5 @@
-/*
- * Copyright (c) 2004 Apple Computer, Inc.
+/*-
+ * Copyright (c) 2004 Apple Inc.
* Copyright (c) 2006 Robert N. M. Watson
* All rights reserved.
*
@@ -11,7 +11,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * 3. Neither the name of Apple Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
@@ -27,9 +27,11 @@
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_event.c#13 $
+ * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_event.c#16 $
*/
+#include <config/config.h>
+
#include <bsm/libbsm.h>
#include <string.h>
@@ -37,6 +39,11 @@
#include <stdio.h>
#include <stdlib.h>
+#ifndef HAVE_STRLCPY
+#include <compat/strlcpy.h>
+#endif
+
+
/*
* Parse the contents of the audit_event file to return
* au_event_ent entries
@@ -68,13 +75,13 @@ eventfromstr(char *str, struct au_event_ent *e)
if (strlen(evname) >= AU_EVENT_NAME_MAX)
return (NULL);
- strcpy(e->ae_name, evname);
+ strlcpy(e->ae_name, evname, AU_EVENT_NAME_MAX);
if (evdesc != NULL) {
if (strlen(evdesc) >= AU_EVENT_DESC_MAX)
return (NULL);
- strcpy(e->ae_desc, evdesc);
+ strlcpy(e->ae_desc, evdesc, AU_EVENT_DESC_MAX);
} else
- strcpy(e->ae_desc, "");
+ strlcpy(e->ae_desc, "", AU_EVENT_DESC_MAX);
e->ae_number = atoi(evno);
diff --git a/contrib/openbsm/libbsm/bsm_flags.c b/contrib/openbsm/libbsm/bsm_flags.c
index e514c86..c87ae84 100644
--- a/contrib/openbsm/libbsm/bsm_flags.c
+++ b/contrib/openbsm/libbsm/bsm_flags.c
@@ -1,5 +1,5 @@
-/*
- * Copyright (c) 2004 Apple Computer, Inc.
+/*-
+ * Copyright (c) 2004 Apple Inc.
* Copyright (c) 2006 Robert N. M. Watson
* All rights reserved.
*
@@ -11,7 +11,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * 3. Neither the name of Apple Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
@@ -27,15 +27,21 @@
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_flags.c#13 $
+ * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_flags.c#16 $
*/
+#include <config/config.h>
+
#include <bsm/libbsm.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
+#ifndef HAVE_STRLCPY
+#include <compat/strlcpy.h>
+#endif
+
static const char *flagdelim = ",";
/*
@@ -157,10 +163,10 @@ getauditflagschar(char *auditstr, au_mask_t *masks, int verbose)
if (sel != 0) {
if (verbose) {
- strcpy(strptr, c.ac_desc);
+ strlcpy(strptr, c.ac_desc, AU_CLASS_DESC_MAX);
strptr += strlen(c.ac_desc);
} else {
- strcpy(strptr, c.ac_name);
+ strlcpy(strptr, c.ac_name, AU_CLASS_NAME_MAX);
strptr += strlen(c.ac_name);
}
*strptr = ','; /* delimiter */
diff --git a/contrib/openbsm/libbsm/bsm_io.c b/contrib/openbsm/libbsm/bsm_io.c
index 29fdc87..989fd8b 100644
--- a/contrib/openbsm/libbsm/bsm_io.c
+++ b/contrib/openbsm/libbsm/bsm_io.c
@@ -1,5 +1,5 @@
-/*
- * Copyright (c) 2004 Apple Computer, Inc.
+/*-
+ * Copyright (c) 2004 Apple Inc.
* Copyright (c) 2005 SPARTA, Inc.
* Copyright (c) 2006 Robert N. M. Watson
* Copyright (c) 2006 Martin Voros
@@ -32,7 +32,7 @@
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_io.c#50 $
+ * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_io.c#55 $
*/
#include <sys/types.h>
@@ -77,48 +77,48 @@
#include <bsm/audit_internal.h>
#define READ_TOKEN_BYTES(buf, len, dest, size, bytesread, err) do { \
- if (bytesread + size > len) { \
- err = 1; \
+ if ((bytesread) + (size) > (u_int32_t)(len)) { \
+ (err) = 1; \
} else { \
- memcpy(dest, buf + bytesread, size); \
+ memcpy((dest), (buf) + (bytesread), (size)); \
bytesread += size; \
} \
} while (0)
#define READ_TOKEN_U_CHAR(buf, len, dest, bytesread, err) do { \
- if (bytesread + sizeof(u_char) <= len) { \
- dest = buf[bytesread]; \
- bytesread += sizeof(u_char); \
+ if ((bytesread) + sizeof(u_char) <= (u_int32_t)(len)) { \
+ (dest) = buf[(bytesread)]; \
+ (bytesread) += sizeof(u_char); \
} else \
- err = 1; \
+ (err) = 1; \
} while (0)
#define READ_TOKEN_U_INT16(buf, len, dest, bytesread, err) do { \
- if (bytesread + sizeof(u_int16_t) <= len) { \
- dest = be16dec(buf + bytesread); \
- bytesread += sizeof(u_int16_t); \
+ if ((bytesread) + sizeof(u_int16_t) <= (u_int32_t)(len)) { \
+ (dest) = be16dec((buf) + (bytesread)); \
+ (bytesread) += sizeof(u_int16_t); \
} else \
- err = 1; \
+ (err) = 1; \
} while (0)
#define READ_TOKEN_U_INT32(buf, len, dest, bytesread, err) do { \
- if (bytesread + sizeof(u_int32_t) <= len) { \
- dest = be32dec(buf + bytesread); \
- bytesread += sizeof(u_int32_t); \
+ if ((bytesread) + sizeof(u_int32_t) <= (u_int32_t)(len)) { \
+ (dest) = be32dec((buf) + (bytesread)); \
+ (bytesread) += sizeof(u_int32_t); \
} else \
- err = 1; \
+ (err) = 1; \
} while (0)
#define READ_TOKEN_U_INT64(buf, len, dest, bytesread, err) do { \
- if (bytesread + sizeof(u_int64_t) <= len) { \
- dest = be64dec(buf + bytesread); \
- bytesread += sizeof(u_int64_t); \
+ if ((bytesread) + sizeof(u_int64_t) <= (u_int32_t)(len)) { \
+ dest = be64dec((buf) + (bytesread)); \
+ (bytesread) += sizeof(u_int64_t); \
} else \
- err = 1; \
+ (err) = 1; \
} while (0)
#define SET_PTR(buf, len, ptr, size, bytesread, err) do { \
- if ((bytesread) + (size) > (len)) \
+ if ((bytesread) + (size) > (u_int32_t)(len)) \
(err) = 1; \
else { \
(ptr) = (buf) + (bytesread); \
@@ -188,7 +188,7 @@ print_8_bytes(FILE *fp, u_int64_t val, const char *format)
static void
print_mem(FILE *fp, u_char *data, size_t len)
{
- int i;
+ u_int32_t i;
if (len > 0) {
fprintf(fp, "0x");
@@ -203,7 +203,7 @@ print_mem(FILE *fp, u_char *data, size_t len)
static void
print_string(FILE *fp, const char *str, size_t len)
{
- int i;
+ u_int32_t i;
if (len > 0) {
for (i = 0; i < len; i++) {
@@ -996,12 +996,10 @@ print_header32_ex_tok(FILE *fp, tokenstr_t *tok, char *del, char raw,
open_attr(fp, "modifier");
print_evmod(fp, tok->tt.hdr32_ex.e_mod, raw);
close_attr(fp);
- /*
- * No attribute for additional types.
- *
+ open_attr(fp, "host");
print_ip_ex_address(fp, tok->tt.hdr32_ex.ad_type,
tok->tt.hdr32_ex.addr);
- */
+ close_attr(fp);
open_attr(fp, "time");
print_sec32(fp, tok->tt.hdr32_ex.s, raw);
close_attr(fp);
@@ -1188,12 +1186,10 @@ print_header64_ex_tok(FILE *fp, tokenstr_t *tok, char *del, char raw,
open_attr(fp, "modifier");
print_evmod(fp, tok->tt.hdr64_ex.e_mod, raw);
close_attr(fp);
- /*
- * No attribute for additional types.
- *
+ open_attr(fp, "host");
print_ip_ex_address(fp, tok->tt.hdr64_ex.ad_type,
tok->tt.hdr64_ex.addr);
- */
+ close_attr(fp);
open_attr(fp, "time");
print_sec64(fp, tok->tt.hdr64_ex.s, raw);
close_attr(fp);
@@ -1478,7 +1474,7 @@ print_arb_tok(FILE *fp, tokenstr_t *tok, char *del, char raw,
size = AUR_BYTE_SIZE;
if (xml) {
open_attr(fp, "type");
- fprintf(fp, "%u", size);
+ fprintf(fp, "%zu", size);
close_attr(fp);
open_attr(fp, "count");
print_1_byte(fp, tok->tt.arb.uc, "%u");
@@ -1504,7 +1500,7 @@ print_arb_tok(FILE *fp, tokenstr_t *tok, char *del, char raw,
size = AUR_SHORT_SIZE;
if (xml) {
open_attr(fp, "type");
- fprintf(fp, "%u", size);
+ fprintf(fp, "%zu", size);
close_attr(fp);
open_attr(fp, "count");
print_1_byte(fp, tok->tt.arb.uc, "%u");
@@ -1533,7 +1529,7 @@ print_arb_tok(FILE *fp, tokenstr_t *tok, char *del, char raw,
size = AUR_INT32_SIZE;
if (xml) {
open_attr(fp, "type");
- fprintf(fp, "%u", size);
+ fprintf(fp, "%zu", size);
close_attr(fp);
open_attr(fp, "count");
print_1_byte(fp, tok->tt.arb.uc, "%u");
@@ -1561,7 +1557,7 @@ print_arb_tok(FILE *fp, tokenstr_t *tok, char *del, char raw,
size = AUR_INT64_SIZE;
if (xml) {
open_attr(fp, "type");
- fprintf(fp, "%u", size);
+ fprintf(fp, "%zu", size);
close_attr(fp);
open_attr(fp, "count");
print_1_byte(fp, tok->tt.arb.uc, "%u");
@@ -1803,7 +1799,7 @@ static int
fetch_execarg_tok(tokenstr_t *tok, u_char *buf, int len)
{
int err = 0;
- int i;
+ u_int32_t i;
u_char *bptr;
READ_TOKEN_U_INT32(buf, len, tok->tt.execarg.count, tok->len, err);
@@ -1817,7 +1813,7 @@ fetch_execarg_tok(tokenstr_t *tok, u_char *buf, int len)
/* Look for a null terminated string. */
while (bptr && (*bptr != '\0')) {
- if (++tok->len >=len)
+ if (++tok->len >= (u_int32_t)len)
return (-1);
bptr = buf + tok->len;
}
@@ -1835,7 +1831,7 @@ static void
print_execarg_tok(FILE *fp, tokenstr_t *tok, char *del, char raw,
__unused char sfrm, int xml)
{
- int i;
+ u_int32_t i;
print_tok_type(fp, tok->id, "exec arg", raw, xml);
for (i = 0; i < tok->tt.execarg.count; i++) {
@@ -1862,7 +1858,7 @@ static int
fetch_execenv_tok(tokenstr_t *tok, u_char *buf, int len)
{
int err = 0;
- int i;
+ u_int32_t i;
u_char *bptr;
READ_TOKEN_U_INT32(buf, len, tok->tt.execenv.count, tok->len, err);
@@ -1876,7 +1872,7 @@ fetch_execenv_tok(tokenstr_t *tok, u_char *buf, int len)
/* Look for a null terminated string. */
while (bptr && (*bptr != '\0')) {
- if (++tok->len >=len)
+ if (++tok->len >= (u_int32_t)len)
return (-1);
bptr = buf + tok->len;
}
@@ -1894,7 +1890,7 @@ static void
print_execenv_tok(FILE *fp, tokenstr_t *tok, char *del, char raw,
__unused char sfrm, int xml)
{
- int i;
+ u_int32_t i;
print_tok_type(fp, tok->id, "exec env", raw, xml);
for (i = 0; i< tok->tt.execenv.count; i++) {
@@ -3817,7 +3813,7 @@ print_socketex32_tok(FILE *fp, tokenstr_t *tok, char *del, char raw,
print_ip_address(fp, tok->tt.socket_ex32.r_addr);
close_attr(fp);
open_attr(fp, "fport");
- print_2_bytes(fp, tok->tt.socket_ex32.type, "%#x");
+ print_2_bytes(fp, ntohs(tok->tt.socket_ex32.r_port), "%#x");
close_attr(fp);
close_tag(fp, tok->id);
} else {
diff --git a/contrib/openbsm/libbsm/bsm_mask.c b/contrib/openbsm/libbsm/bsm_mask.c
index 4914dd3..07d3da3 100644
--- a/contrib/openbsm/libbsm/bsm_mask.c
+++ b/contrib/openbsm/libbsm/bsm_mask.c
@@ -1,5 +1,5 @@
-/*
- * Copyright (c) 2004 Apple Computer, Inc.
+/*-
+ * Copyright (c) 2004 Apple Inc.
* Copyright (c) 2005 Robert N. M. Watson
* All rights reserved.
*
@@ -11,7 +11,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * 3. Neither the name of Apple Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
@@ -27,7 +27,7 @@
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_mask.c#13 $
+ * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_mask.c#14 $
*/
#include <sys/types.h>
diff --git a/contrib/openbsm/libbsm/bsm_notify.c b/contrib/openbsm/libbsm/bsm_notify.c
index e7d3ea2..72458aa 100644
--- a/contrib/openbsm/libbsm/bsm_notify.c
+++ b/contrib/openbsm/libbsm/bsm_notify.c
@@ -1,5 +1,5 @@
-/*
- * Copyright (c) 2004 Apple Computer, Inc.
+/*-
+ * Copyright (c) 2004 Apple Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -10,7 +10,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * 3. Neither the name of Apple Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
@@ -26,7 +26,7 @@
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_notify.c#13 $
+ * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_notify.c#15 $
*/
/*
@@ -165,7 +165,7 @@ cannot_audit(int val __unused)
#ifdef __APPLE__
return (!(au_get_state() == AUC_AUDITING));
#else
- unsigned long au_cond;
+ long au_cond;
if (auditon(A_GETCOND, &au_cond, sizeof(long)) < 0) {
if (errno != ENOSYS) {
diff --git a/contrib/openbsm/libbsm/bsm_token.c b/contrib/openbsm/libbsm/bsm_token.c
index c660895..f9692d1 100644
--- a/contrib/openbsm/libbsm/bsm_token.c
+++ b/contrib/openbsm/libbsm/bsm_token.c
@@ -1,5 +1,5 @@
-/*
- * Copyright (c) 2004 Apple Computer, Inc.
+/*-
+ * Copyright (c) 2004-2008 Apple Inc.
* Copyright (c) 2005 SPARTA, Inc.
* All rights reserved.
*
@@ -14,7 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * 3. Neither the name of Apple Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
@@ -30,7 +30,7 @@
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_token.c#63 $
+ * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_token.c#72 $
*/
#include <sys/types.h>
@@ -87,7 +87,7 @@
memset((dptr), 0, (length)); \
} else \
(dptr) = NULL; \
- assert(t == NULL || dptr != NULL); \
+ assert((t) == NULL || (dptr) != NULL); \
} while (0)
/*
@@ -98,7 +98,7 @@
* text N bytes + 1 terminating NULL byte
*/
token_t *
-au_to_arg32(char n, char *text, u_int32_t v)
+au_to_arg32(char n, const char *text, u_int32_t v)
{
token_t *t;
u_char *dptr = NULL;
@@ -119,11 +119,10 @@ au_to_arg32(char n, char *text, u_int32_t v)
ADD_STRING(dptr, text, textlen);
return (t);
-
}
token_t *
-au_to_arg64(char n, char *text, u_int64_t v)
+au_to_arg64(char n, const char *text, u_int64_t v)
{
token_t *t;
u_char *dptr = NULL;
@@ -144,11 +143,10 @@ au_to_arg64(char n, char *text, u_int64_t v)
ADD_STRING(dptr, text, textlen);
return (t);
-
}
token_t *
-au_to_arg(char n, char *text, u_int32_t v)
+au_to_arg(char n, const char *text, u_int32_t v)
{
return (au_to_arg32(n, text, v));
@@ -180,8 +178,8 @@ au_to_attr32(struct vnode_au_info *vni)
ADD_U_CHAR(dptr, AUT_ATTR32);
/*
- * Darwin defines the size for the file mode
- * as 2 bytes; BSM defines 4 so pad with 0
+ * Darwin defines the size for the file mode as 2 bytes; BSM defines
+ * 4 so pad with 0.
*/
ADD_U_INT16(dptr, pad0_16);
ADD_U_INT16(dptr, vni->vn_mode);
@@ -191,7 +189,7 @@ au_to_attr32(struct vnode_au_info *vni)
ADD_U_INT32(dptr, vni->vn_fsid);
/*
- * Some systems use 32-bit file ID's, other's use 64-bit file IDs.
+ * Some systems use 32-bit file ID's, others use 64-bit file IDs.
* Attempt to handle both, and let the compiler sort it out. If we
* could pick this out at compile-time, it would be better, so as to
* avoid the else case below.
@@ -225,8 +223,8 @@ au_to_attr64(struct vnode_au_info *vni)
ADD_U_CHAR(dptr, AUT_ATTR64);
/*
- * Darwin defines the size for the file mode
- * as 2 bytes; BSM defines 4 so pad with 0
+ * Darwin defines the size for the file mode as 2 bytes; BSM defines
+ * 4 so pad with 0.
*/
ADD_U_INT16(dptr, pad0_16);
ADD_U_INT16(dptr, vni->vn_mode);
@@ -270,7 +268,7 @@ au_to_attr(struct vnode_au_info *vni)
* data items (depends on basic unit)
*/
token_t *
-au_to_data(char unit_print, char unit_type, char unit_count, char *p)
+au_to_data(char unit_print, char unit_type, char unit_count, const char *p)
{
token_t *t;
u_char *dptr = NULL;
@@ -298,7 +296,7 @@ au_to_data(char unit_print, char unit_type, char unit_count, char *p)
default:
errno = EINVAL;
- return (NULL);
+ return (NULL);
}
totdata = datasize * unit_count;
@@ -345,7 +343,7 @@ token_t *
au_to_groups(int *groups)
{
- return (au_to_newgroups(AUDIT_MAX_GROUPS, (gid_t*)groups));
+ return (au_to_newgroups(AUDIT_MAX_GROUPS, (gid_t *)groups));
}
/*
@@ -396,7 +394,7 @@ au_to_in_addr(struct in_addr *internet_addr)
/*
* token ID 1 byte
* address type/length 4 bytes
- * Address 16 bytes
+ * address 16 bytes
*/
token_t *
au_to_in_addr_ex(struct in6_addr *internet_addr)
@@ -484,8 +482,8 @@ au_to_ipc_perm(struct ipc_perm *perm)
ADD_U_CHAR(dptr, AUT_IPC_PERM);
/*
- * Darwin defines the sizes for ipc_perm members
- * as 2 bytes; BSM defines 4 so pad with 0
+ * Darwin defines the sizes for ipc_perm members as 2 bytes; BSM
+ * defines 4 so pad with 0.
*/
ADD_U_INT16(dptr, pad0);
ADD_U_INT16(dptr, perm->uid);
@@ -506,15 +504,23 @@ au_to_ipc_perm(struct ipc_perm *perm)
#ifdef HAVE_IPC_PERM___SEQ
ADD_U_INT16(dptr, perm->__seq);
-#else
+#else /* HAVE_IPC_PERM___SEQ */
+#ifdef HAVE_IPC_PERM__SEQ
+ ADD_U_INT16(dptr, perm->_seq);
+#else /* HAVE_IPC_PERM__SEQ */
ADD_U_INT16(dptr, perm->seq);
-#endif
+#endif /* HAVE_IPC_PERM__SEQ */
+#endif /* HAVE_IPC_PERM___SEQ */
#ifdef HAVE_IPC_PERM___KEY
ADD_U_INT32(dptr, perm->__key);
-#else
+#else /* HAVE_IPC_PERM___KEY */
+#ifdef HAVE_IPC_PERM__KEY
+ ADD_U_INT32(dptr, perm->_key);
+#else /* HAVE_IPC_PERM__KEY */
ADD_U_INT32(dptr, perm->key);
-#endif
+#endif /* HAVE_IPC_PERM__KEY */
+#endif /* HAVE_IPC_PERM___KEY */
return (t);
}
@@ -545,7 +551,7 @@ au_to_iport(u_int16_t iport)
* data size bytes
*/
token_t *
-au_to_opaque(char *data, u_int16_t bytes)
+au_to_opaque(const char *data, u_int16_t bytes)
{
token_t *t;
u_char *dptr = NULL;
@@ -569,7 +575,7 @@ au_to_opaque(char *data, u_int16_t bytes)
* file pathname N bytes + 1 terminating NULL byte
*/
token_t *
-au_to_file(char *file, struct timeval tm)
+au_to_file(const char *file, struct timeval tm)
{
token_t *t;
u_char *dptr = NULL;
@@ -601,7 +607,7 @@ au_to_file(char *file, struct timeval tm)
* text N bytes + 1 terminating NULL byte
*/
token_t *
-au_to_text(char *text)
+au_to_text(const char *text)
{
token_t *t;
u_char *dptr = NULL;
@@ -627,7 +633,7 @@ au_to_text(char *text)
* path N bytes + 1 terminating NULL byte
*/
token_t *
-au_to_path(char *text)
+au_to_path(const char *text)
{
token_t *t;
u_char *dptr = NULL;
@@ -906,7 +912,7 @@ au_to_sock_unix(struct sockaddr_un *so)
if (t == NULL)
return (NULL);
- ADD_U_CHAR(dptr, AU_SOCK_UNIX_TOKEN);
+ ADD_U_CHAR(dptr, AUT_SOCKUNIX);
/* BSM token has two bytes for family */
ADD_U_CHAR(dptr, 0);
ADD_U_CHAR(dptr, so->sun_family);
@@ -943,14 +949,13 @@ au_to_sock_inet32(struct sockaddr_in *so)
*
* XXXRW: Should a name space conversion be taking place on the value
* of sin_family?
- */
+ */
family = so->sin_family;
ADD_U_INT16(dptr, family);
ADD_MEM(dptr, &so->sin_port, sizeof(uint16_t));
ADD_MEM(dptr, &so->sin_addr.s_addr, sizeof(uint32_t));
return (t);
-
}
token_t *
@@ -967,8 +972,8 @@ au_to_sock_inet128(struct sockaddr_in6 *so)
ADD_U_CHAR(dptr, AUT_SOCKINET128);
/*
* In Darwin, sin6_family is one octet, but BSM defines the token
- * to store two. So we copy in a 0 first.
- */
+ * to store two. So we copy in a 0 first.
+ */
ADD_U_CHAR(dptr, 0);
ADD_U_CHAR(dptr, so->sin6_family);
@@ -976,7 +981,6 @@ au_to_sock_inet128(struct sockaddr_in6 *so)
ADD_MEM(dptr, &so->sin6_addr, 4 * sizeof(uint32_t));
return (t);
-
}
token_t *
@@ -1162,8 +1166,8 @@ au_to_subject_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
#if !defined(_KERNEL) && !defined(KERNEL) && defined(HAVE_AUDIT_SYSCALLS)
/*
- * Collects audit information for the current process
- * and creates a subject token from it
+ * Collects audit information for the current process and creates a subject
+ * token from it.
*/
token_t *
au_to_me(void)
@@ -1225,7 +1229,7 @@ au_to_exec_args(char **argv)
* zonename N bytes + 1 terminating NULL byte
*/
token_t *
-au_to_zonename(char *zonename)
+au_to_zonename(const char *zonename)
{
u_char *dptr = NULL;
u_int16_t textlen;
@@ -1317,6 +1321,53 @@ au_to_header32_tm(int rec_size, au_event_t e_type, au_emod_t e_mod,
return (t);
}
+/*
+ * token ID 1 byte
+ * record byte count 4 bytes
+ * version # 1 byte [2]
+ * event type 2 bytes
+ * event modifier 2 bytes
+ * address type/length 4 bytes
+ * machine address 4 bytes/16 bytes (IPv4/IPv6 address)
+ * seconds of time 4 bytes/8 bytes (32-bit/64-bit value)
+ * milliseconds of time 4 bytes/8 bytes (32-bit/64-bit value)
+ */
+token_t *
+au_to_header32_ex_tm(int rec_size, au_event_t e_type, au_emod_t e_mod,
+ struct timeval tm, struct auditinfo_addr *aia)
+{
+ token_t *t;
+ u_char *dptr = NULL;
+ u_int32_t timems, hostid;
+ au_tid_addr_t *tid = &aia->ai_termid;
+
+ if (tid->at_type != AU_IPv4 && tid->at_type != AU_IPv6)
+ return (NULL);
+ GET_TOKEN_AREA(t, dptr, sizeof(u_char) + sizeof(u_int32_t) +
+ sizeof(u_char) + 2 * sizeof(u_int16_t) + 3 *
+ sizeof(u_int32_t) + tid->at_type);
+ if (t == NULL)
+ return (NULL);
+
+ ADD_U_CHAR(dptr, AUT_HEADER32_EX);
+ ADD_U_INT32(dptr, rec_size);
+ ADD_U_CHAR(dptr, AUDIT_HEADER_VERSION_OPENBSM);
+ ADD_U_INT16(dptr, e_type);
+ ADD_U_INT16(dptr, e_mod);
+
+ ADD_U_INT32(dptr, tid->at_type);
+ if (tid->at_type == AU_IPv6)
+ ADD_MEM(dptr, &tid->at_addr[0], 4 * sizeof(u_int32_t));
+ else
+ ADD_MEM(dptr, &tid->at_addr[0], sizeof(u_int32_t));
+ timems = tm.tv_usec/1000;
+ /* Add the timestamp */
+ ADD_U_INT32(dptr, tm.tv_sec);
+ ADD_U_INT32(dptr, timems); /* We need time in ms. */
+
+ return (t);
+}
+
token_t *
au_to_header64_tm(int rec_size, au_event_t e_type, au_emod_t e_mod,
struct timeval tm)
@@ -1345,6 +1396,24 @@ au_to_header64_tm(int rec_size, au_event_t e_type, au_emod_t e_mod,
}
#if !defined(KERNEL) && !defined(_KERNEL)
+#ifdef HAVE_AUDIT_SYSCALLS
+token_t *
+au_to_header32_ex(int rec_size, au_event_t e_type, au_emod_t e_mod)
+{
+ struct timeval tm;
+ struct auditinfo_addr aia;
+
+ if (gettimeofday(&tm, NULL) == -1)
+ return (NULL);
+ if (auditon(A_GETKAUDIT, &aia, sizeof(aia)) < 0) {
+ if (errno != ENOSYS)
+ return (NULL);
+ return (au_to_header32_tm(rec_size, e_type, e_mod, tm));
+ }
+ return (au_to_header32_ex_tm(rec_size, e_type, e_mod, tm, &aia));
+}
+#endif /* HAVE_AUDIT_SYSCALLS */
+
token_t *
au_to_header32(int rec_size, au_event_t e_type, au_emod_t e_mod)
{
@@ -1372,7 +1441,16 @@ au_to_header(int rec_size, au_event_t e_type, au_emod_t e_mod)
return (au_to_header32(rec_size, e_type, e_mod));
}
-#endif
+
+#ifdef HAVE_AUDIT_SYSCALLS
+token_t *
+au_to_header_ex(int rec_size, au_event_t e_type, au_emod_t e_mod)
+{
+
+ return (au_to_header32_ex(rec_size, e_type, e_mod));
+}
+#endif /* HAVE_AUDIT_SYSCALLS */
+#endif /* !defined(KERNEL) && !defined(_KERNEL) */
/*
* token ID 1 byte
diff --git a/contrib/openbsm/libbsm/bsm_user.c b/contrib/openbsm/libbsm/bsm_user.c
index c00d139..5266fdf 100644
--- a/contrib/openbsm/libbsm/bsm_user.c
+++ b/contrib/openbsm/libbsm/bsm_user.c
@@ -1,5 +1,5 @@
-/*
- * Copyright (c) 2004 Apple Computer, Inc.
+/*-
+ * Copyright (c) 2004 Apple Inc.
* Copyright (c) 2006 Robert N. M. Watson
* All rights reserved.
*
@@ -11,7 +11,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * 3. Neither the name of Apple Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
@@ -27,9 +27,11 @@
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_user.c#15 $
+ * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_user.c#18 $
*/
+#include <config/config.h>
+
#include <bsm/libbsm.h>
#include <string.h>
@@ -37,6 +39,10 @@
#include <stdio.h>
#include <stdlib.h>
+#ifndef HAVE_STRLCPY
+#include <compat/strlcpy.h>
+#endif
+
/*
* Parse the contents of the audit_user file into au_user_ent structures.
*/
@@ -66,7 +72,7 @@ userfromstr(char *str, struct au_user_ent *u)
if (strlen(username) >= AU_USER_NAME_MAX)
return (NULL);
- strcpy(u->au_name, username);
+ strlcpy(u->au_name, username, AU_USER_NAME_MAX);
if (getauditflagsbin(always, &(u->au_always)) == -1)
return (NULL);
diff --git a/contrib/openbsm/libbsm/bsm_wrappers.c b/contrib/openbsm/libbsm/bsm_wrappers.c
index f001e5f..f818f1d 100644
--- a/contrib/openbsm/libbsm/bsm_wrappers.c
+++ b/contrib/openbsm/libbsm/bsm_wrappers.c
@@ -1,5 +1,5 @@
-/*
- * Copyright (c) 2004 Apple Computer, Inc.
+/*-
+ * Copyright (c) 2004 Apple Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -10,7 +10,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * 3. Neither the name of Apple Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
@@ -26,7 +26,7 @@
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_wrappers.c#24 $
+ * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_wrappers.c#26 $
*/
#ifdef __APPLE__
@@ -285,7 +285,7 @@ audit_write(short event_code, token_t *subject, token_t *misctok, char retval,
if (subject && au_write(aufd, subject) == -1) {
au_free_token(subject);
au_free_token(misctok);
- (void)au_close(aufd, AU_TO_WRITE, event_code);
+ (void)au_close(aufd, AU_TO_NO_WRITE, event_code);
syslog(LOG_ERR, "%s: write of subject failed", func);
return (kAUWriteSubjectTokErr);
}
OpenPOWER on IntegriCloud