---
name: "_cap_names"
section: "3"
platform: "linux"
package: "libcap-dev"
version: "1:1.10-14"
release: "Debian 5.0 (Lenny)"
platforms: ["linux"]
url: "https://carta.tech/man/cap_from_text"
---

# \_cap\_names(3)

capability state textual representation translation

Part of [cap\_from\_text(3)](/man/cap_from_text/3.md).

## NAME

cap\_from\_text, cap\_to\_text, \_cap\_names - capability state textual representation translation

## SYNOPSIS

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

**cap\_t cap\_from\_text(const char \****buf\_p***);**

**char \*cap\_to\_text(cap\_t** *caps***, ssize\_t \****length\_p***);**

**extern char const \*\_cap\_names\[\];**

## USAGE

**cc ... -lcap**

## DESCRIPTION

These functions translate a capability state from an internal representation into a textual one.  The internal representation is managed by the capability functions in working storage. The textual representation is a structured, human-readable, string suitable for display.

**cap\_from\_text** allocates and initializes a capability state in working storage. It then sets the contents of this newly-created capability state to the state represented by human-readable, null terminated character string pointed to by *buf\_p*. It returns a pointer to the newly created capability state.  The caller should free any releasable memory, when the capability state in working storage is no longer required, by calling **cap\_free** with *cap\_t* as an argument.  The function returns an error if it cannot parse the contents of the string pointed to by *buf\_p* or does not recognize any *capability\_name* or flag character as valid.  The function also returns an error if any flag is both set and cleared within a single clause.

**cap\_to\_text** converts the capability state in working storage identified by *cap\_p* into a null terminated human-readable string.  This function allocates any memory necessary to contain the string, and returns a pointer to the string.  If the pointer *len\_p* is not **NULL**, the function shall also return the full length of the string (not including the null terminator) in the location pointed to by *len\_p*. The capability state in working storage, identified by *cap\_p*, is completely represented in the character string.  The caller should free any releasable memory, when the capability state in working storage is no longer required, by calling **cap\_free** with **cap\_p** as an argument.

**\_cap\_names** is an array of textual names for capability numbers.  Unnamed capabilities have a NULL entry.  (This array is not defined by POSIX.1e.)

## TEXTUAL REPRESENTATION

A textual representation of capability sets consists of one or more whitespace-separated *clauses*. Each clause specifies some operations to a capability set; the set starts out with all capabilities lowered, and the meaning of the string is the state of the capability set after all the clauses have been applied in order.

Each clause consists of a list of comma-separated capability names (or the word \`**all**'), followed by an *action-list*. An action-list consists of a sequence of *operator flag* pairs.  Legal operators are: \`**=**', '**+**', and \`**-**'. Legal flags are: \`**e**', \`**i**', and \`**p**'. These flags are case-sensitive and specify the Effective, Inheritable and Permitted sets respectively.

In the capability name lists, all names are case-insensitive.  The special name \`**all**' specifies all capabilities; it is equivalent to a list naming every capability individually.

Although not defined by POSIX, unnamed capabilities can be specified by number.

The \`**=**' operator indicates that the listed capabilities are first reset in all three capability sets.  The subsequent flags (which are optional when associated with this operator) indicate that the listed capabilities for the corresponding set are to be raised.  For example: "all=p" means lower every capability in the Effective and Inheritable sets but raise all of the Permitted capabilities; or, "cap\_fowner=ep" means raise the Effective and Permitted override-file-ownership capability, while lowering this Inheritable capability.

In the case that the leading operator is \`**=**', and no list of capabilities is provided, the action-list is assumed to refer to \`all' capabilities.  For example, the following three clauses are equivalent to each other (and indicate a completely empty capability set): "all="; "="; "cap\_chown,\<every-other-capability\>=".

The operators, \`+' and \`-' both require an explicit preceding capability list and one or more explicit trailing flags.  The \`+' operator will raise all of the listed capabilities in the flagged capability sets.  The \`-' operator will lower all of the listed capabilities in the flagged capability sets.  For example: "all+p" will raise all of the Permitted capabilities; "cap\_fowner+p-i" will raise the override-file-ownership capability in the Permitted capability set and lower this Inheritable capability; "cap\_fowner+pe-i" and "cap\_fowner=+pe" are equivalent.

## RETURN VALUE

**cap\_from\_text** and **cap\_to\_text** return a non-NULL value on success, and NULL on failure.

On failure, [**errno**(3)](/man/errno/3.md) is set to  **EINVAL**, or  **ENOMEM**.

## CONFORMING TO

**cap\_from\_text** and **cap\_to\_text** are specified by POSIX.1e. **\_cap\_names** is a Linux extension.

## SEE ALSO

[*cap\_clear*(3)](/man/cap_clear/3.md), [*cap\_copy\_ext*(3)](/man/cap_copy_ext/3.md), [*cap\_get\_file*(3)](/man/cap_get_file/3.md), [*cap\_get\_proc*(3)](/man/cap_get_proc/3.md), [*cap\_init*(3)](/man/cap_init/3.md)
