selabel_open(3)
β¨ selabel_open(3) β SELinux API documentation β¨
okay bestie, sit down, hydrate, and let me tell you about the two little functions that run the whole SELinux labeling situation: selabel_open and selabel_close. π
π NAME π
selabel_open, selabel_close β the userspace SELinux labeling interface, no cap.
πΈ SYNOPSIS πΈ
#include <selinux/selinux.h>
#include <selinux/label.h>
struct selabel_handle *selabel_open(unsigned int backend,
const struct selinux_opt *options,
unsigned nopt);
void selabel_close(struct selabel_handle *hnd);
π DESCRIPTION π
So selabel_open() is the glow-up moment where you initialize a labeling handle β you're gonna use that handle for all your lookup operations later. The backend argument tells it which backend you're opening, and the whole roster of current backends is chilling down in BACKENDS below. π
The options argument should be NULL, OR a pointer to an array of selinux_opt structs that's nopt long:
struct selinux_opt {
int type;
const char *value;
};
Which option types exist? They're described in GLOBAL OPTIONS below, plus in the docs for each individual backend, so go read those too bestie. π«Ά On success you get back a non-NULL value, and you use that in all your later label operations.
Then selabel_close() is the "okay we're done here" β it terminates use of a handle and frees any internal resources attached to it. After you've made this call, you must NOT use the handle again. Like, ever. It's over. π
β¨ GLOBAL OPTIONS β¨
These are the global options you can pass to selabel_open():
SELABEL_OPT_UNUSEDβ the option with a type code of zero is a no-op. Which is lowkey genius, because it means you can initialize an array of options to zero and any elements you never touched won't throw an error at you. π§SELABEL_OPT_VALIDATEβ a non-null value for this one turns on context validation. By default it usessecurity_check_context(3), but you can hand it a custom validation function throughselinux_set_callback(3). Heads up though: an invalid context might not be treated as an error unless it's actually encountered during a lookup operation. So it's giving "we'll deal with it when we get there." πSELABEL_OPT_DIGESTβ a non-null value here enables generation of a SHA256 digest of the spec files loaded, exactly as described inselabel_digest(3). π₯
π BACKENDS π
SELABEL_CTX_FILEβ the file contexts backend, fully described inselabel_file(5).SELABEL_CTX_MEDIAβ the media contexts backend, described inselabel_media(5).SELABEL_CTX_Xβ the X Windows contexts backend, described inselabel_x(5).SELABEL_CTX_DBβ the database objects contexts backend, described inselabel_db(5).
β RETURN VALUE β
On success, you get a non-NULL handle value back. π On error, NULL is returned and errno is set appropriately β classic, honestly.
π AUTHOR π
Eamon Walsh <ewalsh@tycho.nsa.gov> β king behavior, we thank him for his service. π«Ά
π SEE ALSO π
selabel_lookup(3), selabel_stats(3), selinux_set_callback(3), selinux(8)
and that's the whole page bestie!! this one's from the SELinux API documentation, dated 18 Jun 2007 β yes, 2007, it's vintage, it's iconic, it's still slaying. go forth and label things responsibly πβ¨π
π¦ where this page comes from
- centos-stream 10: libselinux-devel 3.11-3.el10 Β· LicenseRef-Fedora-Public-Domain
- centos-stream 9: libselinux-devel 3.6-5.el9 Β· Public Domain
- centos-stream 9: libselinux-devel 3.6-5.el9 Β· Public Domain
- fedora 43: libselinux-devel 3.9-5.fc43 Β· LicenseRef-Fedora-Public-Domain
- fedora 43: libselinux-devel 3.9-5.fc43 Β· LicenseRef-Fedora-Public-Domain
- fedora 44: libselinux-devel 3.10-1.fc44 Β· LicenseRef-Fedora-Public-Domain
- fedora 44: libselinux-devel 3.10-1.fc44 Β· LicenseRef-Fedora-Public-Domain
- fedora 44: libselinux-devel 3.11-2.fc44 Β· LicenseRef-Fedora-Public-Domain
- fedora 44: libselinux-devel 3.11-2.fc44 Β· LicenseRef-Fedora-Public-Domain
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms