---
name: "mac"
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/mac/3"
---

# mac(3)

introduction to the MAC security API

## NAME

**mac** – introduction to the MAC security API

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

**#include \<sys/mac.h\>**

In the kernel configuration file: **options MAC**

## DESCRIPTION

Mandatory Access Control labels describe confidentiality, integrity, and other security attributes of operating system objects, overriding discretionary access control. Not all system objects support MAC labeling, and MAC policies must be explicitly enabled by the administrator. This API, based on POSIX.1e, includes routines to retrieve, manipulate, set, and convert to and from text the MAC labels on files and processes.

MAC labels consist of a set of (name, value) tuples, representing security attributes from MAC policies. For example, this label contains security labels defined by two policies, [mac\_biba(4)](/mac_biba/4.md) and [mac\_mls(4)](/mac_mls/4.md):

```
biba/low,mls/low
```

Further syntax and semantics of MAC labels may be found in [maclabel(7)](/maclabel/7.md).

Applications operate on labels stored in *mac\_t*, but can convert between this internal format and a text format for the purposes of presentation to uses or external storage. When querying a label on an object, a *mac\_t* must first be prepared using the interfaces described in [mac\_prepare(3)](/mac_prepare/3.md), allowing the application to declare which policies it wishes to interrogate. The application writer can also rely on default label names declared in [mac.conf(5)](/mac.conf/5.md).

When finished with a *mac\_t*, the application must call [mac\_free(3)](/mac_free/3.md) to release its storage.

The following functions are defined:

- **mac\_is\_present**()

  This function, described in [mac\_is\_present(3)](/mac_is_present/3.md), allows applications to test whether MAC is configured, as well as whether specific policies are configured.

- **mac\_get\_fd**(*,*, *Fn*, *mac\_get\_file*, *,*, *Fn*, *mac\_get\_link*, *,*, *Fn*, *mac\_get\_peer*)

  These functions, described in [mac\_get(3)](/mac_get/3.md), retrieve the MAC labels associated with file descriptors, files, and socket peers.

- **mac\_get\_pid**(*,*, *Fn*, *mac\_get\_proc*)

  These functions, described in [mac\_get(3)](/mac_get/3.md), retrieve the MAC labels associated with processes.

- **mac\_set\_fd**(*,*, *Fn*, *mac\_set\_file*, *,*, *Fn*, *mac\_set\_link*)

  These functions, described in [mac\_set(3)](/mac_set/3.md), set the MAC labels associated with file descriptors and files.

- **mac\_set\_proc**()

  This function, described in [mac\_set(3)](/mac_set/3.md), sets the MAC label associated with the current process.

- **mac\_free**()

  This function, described in [mac\_free(3)](/mac_free/3.md), frees working MAC label storage.

- **mac\_from\_text**()

  This function, described in [mac\_text(3)](/mac_text/3.md), converts a text-form MAC label into working MAC label storage, *mac\_t*.

- **mac\_prepare**(*,*, *Fn*, *mac\_prepare\_file\_label*, *,*, *Fn*, *mac\_prepare\_ifnet\_label*, *,*, *Fn*, *mac\_prepare\_process\_label*, *,*, *Fn*, *mac\_prepare\_type*)

  These functions,  described in [mac\_prepare(3)](/mac_prepare/3.md), allocate working storage for MAC label operations. [mac\_prepare(3)](/mac_prepare/3.md) prepares a label based on caller-specified label names; the other calls rely on the default configuration specified in [mac.conf(5)](/mac.conf/5.md).

- **mac\_to\_text**()

  This function is described in [mac\_text(3)](/mac_text/3.md), and may be used to convert a *mac\_t* into a text-form MAC label.

## FILES

- */etc/mac.conf*

  MAC library configuration file, documented in [mac.conf(5)](/mac.conf/5.md). Provides default behavior for applications aware of MAC labels on system objects, but without policy-specific knowledge.

## SEE ALSO

[mac\_free(3)](/mac_free/3.md), [mac\_get(3)](/mac_get/3.md), [mac\_is\_present(3)](/mac_is_present/3.md), [mac\_prepare(3)](/mac_prepare/3.md), [mac\_set(3)](/mac_set/3.md), [mac\_text(3)](/mac_text/3.md), [posix1e(3)](/posix1e/3.md), [mac(4)](/mac/4.md), [mac.conf(5)](/mac.conf/5.md), [mac(9)](/mac/9.md)

## STANDARDS

These APIs are loosely based on the APIs described in POSIX.1e, as described in IEEE POSIX.1e draft 17. However, the resemblance of these APIs to the POSIX APIs is loose, as the POSIX APIs were unable to express some notions required for flexible and extensible access control.

## HISTORY

Support for Mandatory Access Control was introduced in FreeBSD 5.0 as part of the TrustedBSD Project.
