avc\_context\_to\_sid(3) SELinux API documentation avc\_context\_to\_sid(3)

# [NAME](#NAME)

avc\_context\_to\_sid, avc\_sid\_to\_context, avc\_get\_initial\_sid - obtain and manipulate SELinux security ID's

# [SYNOPSIS](#SYNOPSIS)

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

**int avc\_context\_to\_sid(const char \*ctx, security\_id\_t \*sid);**

**int avc\_sid\_to\_context(security\_id\_t sid, char \*\*ctx);**

**int avc\_get\_initial\_sid(const char \*name, security\_id\_t \*sid);**

# [DESCRIPTION](#DESCRIPTION)

Security ID's (SID's) are opaque representations of security contexts, managed by the userspace AVC.

**avc\_context\_to\_sid**() returns a SID for the given *context* in the memory referenced by *sid*.

**avc\_sid\_to\_context**() returns a copy of the context represented by *sid* in the memory referenced by *ctx*. The user must free the copy with [**freecon**(3)](/man/os/libselinux/freecon.3).

**avc\_get\_initial\_sid**() returns a SID for the kernel initial security identifier specified by *name*.

# [RETURN VALUE](#RETURN_VALUE)

**avc\_context\_to\_sid**() and **avc\_sid\_to\_context**() return zero on success. On error, -1 is returned and *errno* is set appropriately.

# [ERRORS](#ERRORS)

[**ENOMEM**](#ENOMEM)

An attempt to allocate memory failed.

# [NOTES](#NOTES)

As of libselinux version 2.0.86, SID's are no longer reference counted. A SID will be valid from the time it is first obtained until the next call to [**avc\_destroy**(3)](/man/os/libselinux/avc_destroy.3). The [**sidget**(3)](/man/os/libselinux/sidget.3) and [**sidput**(3)](/man/os/libselinux/sidput.3) functions, formerly used to adjust the reference count, are no-ops and are deprecated.

# [AUTHOR](#AUTHOR)

Eamon Walsh &lt;ewalsh@tycho.nsa.gov&gt;

# [SEE ALSO](#SEE_ALSO)

[**avc\_init**(3)](/man/os/libselinux/avc_init.3), [**avc\_has\_perm**(3)](/man/os/libselinux/avc_has_perm.3), [**avc\_cache\_stats**(3)](/man/os/libselinux/avc_cache_stats.3), [**avc\_add\_callback**(3)](/man/os/libselinux/avc_add_callback.3), [**getcon**(3)](/man/os/libselinux/getcon.3), [**freecon**(3)](/man/os/libselinux/freecon.3), [**selinux**(8)](/man/os/libselinux/selinux.8)

27 May 2004

---

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