---
name: "au_open"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/au_close"
---

# au\_open(3)

create and commit audit records

Part of [au\_close(3)](/au_close/3.md).

## NAME

**au\_close**, **au\_close\_buffer**, **au\_close\_token**, **au\_open**, **au\_write** – create and commit audit records

## LIBRARY

library “libbsm”

## SYNOPSIS

**#include \<bsm/libbsm.h\>**

*int*\

**au\_open**(*void*);

*int*\

**au\_write**(*int d*, *token\_t \*tok*);

*int*\

**au\_close**(*int d*, *int keep*, *short event*);

*int*\

**au\_close\_buffer**(*int d*, *short event*, *u\_char \*buffer*, *size\_t \*buflen*);

*int*\

**au\_close\_token**(*token\_t \*tok*, *u\_char \*buffer*, *size\_t \*buflen*);

## DESCRIPTION

These interfaces allow applications to allocate audit records, construct a record using a series of tokens, and commit the audit record to the system event log. An extension API is also provided to commit the record to an in-memory buffer rather than the system audit log.

The **au\_open**() interface allocates a new audit record descriptor.

The **au\_write**() interface adds a token to an allocated audit descriptor. When a token has been successfully added to a record, the caller no longer owns the token memory, and does not need to free it directly via a call to [au\_free\_token(3)](/au_free_token/3.md).

The **au\_close**() function is used to commit an audit record to the system audit log, or abandon the record. In either cases, all resources associated with the record will be released. The *keep* argument determines the behavior: a value of AU\_TO\_WRITE causes the record to be committed; a value of AU\_TO\_NO\_WRITE causes it to be abandoned. When the audit record is committed, a BSM header will be inserted before tokens added to the record, using the event identifier passed via *event*, and a trailer added to the end. Committing a record to the system audit log requires privilege.

The **au\_close\_buffer**() function writes the resulting record to an in-memory buffer of size *\*buflen*; it will write back the filled buffer length into the same variable. The argument *event* is the event identifier to use in the record header.

The **au\_close\_token**() function generates the BSM stream output for a single token, *tok*, in the passed buffer *buffer*. The initial buffer size and resulting data size are passed via *\*buflen*. The **au\_close\_token**() function will free the token before returning.

## RETURN VALUES

The function **au\_open**() returns a non-negative audit record descriptor number on success, or a negative value on failure, along with error information in *errno*.

The functions **au\_write**(), **au\_close**(), **au\_close\_buffer**(), and **au\_close\_token**() return 0 on success, or a negative value on failure, along with error information in *errno*.

## SEE ALSO

[audit\_submit(3)](/audit_submit/3.md), [libbsm(3)](/libbsm/3.md)

## HISTORY

The OpenBSM implementation was created by McAfee Research, the security division of McAfee Inc., under contract to Apple Computer, Inc., in 2004. It was subsequently adopted by the TrustedBSD Project as the foundation for the OpenBSM distribution.

## AUTHORS

This software was created by Robert Watson, Wayne Salamon, and Suresh Krishnaswamy for McAfee Research, the security research division of McAfee, Inc., under contract to Apple Computer, Inc.

The Basic Security Module (BSM) interface to audit records and audit event stream format were defined by Sun Microsystems.

## BUGS

Currently, **au\_open**() does not reserve kernel resources necessary to commit the record to the trail; on systems supporting **au\_close**(), the call will block until resources are available to commit the record. However, this leads to the possibility of an action being permitted without the record being guaranteed to go to disk. Ideally, **au\_open**() would reserve resources necessary to commit any submitted record, releasing them on **au\_close**().
