context_new(3)
β¨ context_new(3) β SELinux API documentation β¨
okay bestie so this is a page from the SELinux API documentation, section 3 (that's the library-calls section, iykyk), and it's all about manipulating SELinux security contexts without losing your whole entire mind π
π 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 β the routines that let you 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 π
so the whole vibe of this little family of functions is: your app gets to poke at the fields of a security context string without ever having to know what the format of that string even is. iconic behaviour honestly. no parsing drama, no format lore required π«Ά
context_new()β returns a new context, initialized to a context string. fresh out the box, slay β¨context_str()β hands you back a pointer to the string value of thecontext_t. it's valid until the next call tocontext_str()orcontext_free()for that samecontext_t*. so like, enjoy it while it lasts, bestie πcontext_free()β frees the storage used by a context. it's giving cleanup era π§Ήcontext_type_get(),context_range_get(),context_role_get(),context_user_get()β these get you a pointer to the string value of a context component. the little pieces of the puzzle, if you will π§©
β οΈ Note, and this one matters: values returned by the get functions are only valid until the next call to a set function orcontext_free()for the samecontext_tstructure. so don't go stashing that pointer in your purse and expecting it to still be cute later, because it will NOT be π
context_type_set(),context_range_set(),context_role_set(),context_user_set()β these set a context component. you're in charge now π
β RETURN VALUE β
- on failure, the
context_*_set()functions return non-zero, and on success they return 0. - the other functions return
NULLon failure and non-NULLon success. - on failure,
errnois set appropriately. (she always tells you what went wrong, we love an honest queen π)
π SEE ALSO π
that's the whole page, no notes, periodt. this lil masterpiece was written by dwalsh@redhat.com and dated 20 December 2011 β so yeah she's been serving this exact energy since way before it was cool, and honestly? she ate π ππ¦
π¦ where this page comes from
- alpine 3.24: libselinux-doc 3.10-r1 Β· Public-Domain
- centos-stream 10: libselinux-devel 3.11-3.el10 Β· 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
- nixos 26.05: libselinux 3.10
- nixpkgs unstable: libselinux 3.11
- ubuntu stonking: libselinux-dev 3.11-2.1 Β· LicenseRef-public-domain
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms