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

# selabel\_lookup(3)

obtain SELinux security context from a string label

## NAME

selabel\_lookup - obtain SELinux security context from a string label

## SYNOPSIS

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

**int selabel\_lookup(struct selabel\_handle \****hnd***,** **char \*\****context***,**\
 **const char \****key***, int** *type***);**

**int selabel\_lookup\_raw(struct selabel\_handle \****hnd***,** **char \*\****context***,**\
 **const char \****key***, int** *type***);**

## DESCRIPTION

**selabel\_lookup**() performs a lookup operation on the handle  *hnd*, returning the result in the memory pointed to by  *context*, which must be freed by the caller using [**freecon**(3)](/freecon/3.md). The  *key* and *type* parameters are the inputs to the lookup operation and are interpreted according to the specific backend that  *handle* is open on.

**selabel\_lookup\_raw**() behaves identically to  **selabel\_lookup**() but does not perform context translation.

## RETURN VALUE

On success, zero is returned.  On error, -1 is returned and *errno* is set appropriately.

## ERRORS

- **ENOENT**

  No context corresponding to the input  *key* and *type* was found.

- **EINVAL**

  The *key* and/or *type* inputs are invalid, or the context being returned failed validation, or a regular expression in the database failed to compile.

- **ENOMEM**

  An attempt to allocate memory failed.

## AUTHOR

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

## SEE ALSO

[**selabel\_open**(3)](/selabel_open/3.md), [**selabel\_stats**(3)](/selabel_stats/3.md), [**selinux\_set\_callback**(3)](/selinux_set_callback/3.md), [**selinux**(8)](/selinux/8.md)
