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

# avc\_get\_initial\_context(3)

obtain and manipulate SELinux security ID's

Part of [avc\_context\_to\_sid(3)](/avc_context_to_sid/3.md).

## NAME

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

## SYNOPSIS

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

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

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)](/freecon/3.md).

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

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

- **ENOMEM**

  An attempt to allocate memory failed.

## 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)](/avc_destroy/3.md). The [**sidget**(3)](/sidget/3.md) and [**sidput**(3)](/sidput/3.md) functions, formerly used to adjust the reference count, are no-ops and are deprecated.

## AUTHOR

Eamon Walsh \<ewalsh@tycho.nsa.gov\>

## SEE ALSO

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