---
name: "context_type_set"
section: "3"
platform: "linux"
package: "libselinux1-dev"
version: "3.8.1-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/context_new"
---

# context\_type\_set(3)

Routines to manipulate SELinux security contexts

Part of [context\_new(3)](/context_new/3.md).

## 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

**#include \<selinux/context.h\>**

**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

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

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

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

On failure *errno* is set appropriately.

## SEE ALSO

[**selinux**(8)](/selinux/8.md)
