context\_new(3) SELinux API documentation context\_new(3)

# [NAME](#NAME)

context\_new, context\_str, context\_free, context\_type\_get, context\_type\_set, context\_range\_get, context\_range\_set,context\_role\_get, context\_role\_set, context\_user\_get, context\_user\_set - Routines to manipulate SELinux security contexts

# [SYNOPSIS](#SYNOPSIS)

**#include &lt;selinux/context.h&gt;**

**context\_t context\_new(const char \*context\_str);**

**const char * context\_str(context\_t con);**

**void context\_free(context\_t con);**

**const char * context\_type\_get(context\_t con);**

**const char * context\_range\_get(context\_t con);**

**const char * context\_role\_get(context\_t con);**

**const char * context\_user\_get(context\_t con);**

**int context\_type\_set(context\_t con, const char \*type);**

**int context\_range\_set(context\_t con, const char \*range);**

**int context\_role\_set(context\_t con, const char \*role);**

**int context\_user\_set(context\_t con, const char \*user);**

# [DESCRIPTION](#DESCRIPTION)

These functions allow an application to manipulate the fields of a security context string without requiring it to know the format of the string.

**context\_new**() returns a new context initialized to a context string.

**context\_str**() returns a pointer to the string value of the **context\_t**, valid until the next call to **context\_str**() or **context\_free**() for the same **context\_t\***.

**context\_free**() frees the storage used by a context.

**context\_type\_get**(), **context\_range\_get**(), **context\_role\_get**(), **context\_user\_get**() get a pointer to the string value of a context component.

**Note:** Values returned by the get functions are only valid until the next call to a set function or **context\_free**() for the same **context\_t** structure.

**context\_type\_set**(), **context\_range\_set**(), **context\_role\_set**(), **context\_user\_set**() set a context component.

# [RETURN VALUE](#RETURN_VALUE)

On failure **context\_\*\_set**() functions return non-zero on failure and 0 on success.

The other functions return NULL on failure and non-NULL on success.

On failure *errno* is set appropriately.

# [SEE ALSO](#SEE_ALSO)

[**selinux**(8)](/man/os/libselinux/selinux.8)

20 December 2011 dwalsh@redhat.com

---

Document: context_type_set(3) from libselinux 3.11-r2 (Chainguard OS)
Source: https://github.com/SELinuxProject/selinux.git
