getkeycreatecon(3)
π getkeycreatecon β the SELinux API docs, but make it a group chat π
okay bestie, so you're reading the getkeycreatecon(3) page from the SELinux API documentation, and honestly? it's giving "small but mighty." two little functions, one big job: getting and setting the security context that gets slapped onto a brand new kernel keyring. no cap.
β¨ NAME β¨
getkeycreatecon, setkeycreatecon β get or set the SELinux security context used for creating a new kernel keyrings π
ngl the original says "a new kernel keyrings" and I'm not fixing it. that's canon. leave her alone. π
π¦ SYNOPSIS π¦
#include <selinux/selinux.h>
int getkeycreatecon(char **con);
int getkeycreatecon_raw(char **con);
int setkeycreatecon(const char *context);
int setkeycreatecon_raw(const char *context);
four functions, one header, zero drama. let's gooo πΈ
π DESCRIPTION π
so getkeycreatecon() does the cute little retrieval thing: it grabs the context that's used for creating a new kernel keyring. ποΈ
if what you get back is non-NULL, bestie, you gotta free it with freecon(3). don't just leave it lying around like an unread text. π
and here's the lil plot twist: getkeycreatecon() sets *con to NULL if no keycreate context has been explicitly set by the program β like, i.e. when you're just running on the default policy behavior. nothing set, nothing returned, NULL it is. periodt.
setkeycreatecon() is the setter of the duo β it sets the context used for creating a new kernel keyring. β¨
you can pass NULL to setkeycreatecon() to reset back to the default policy behavior. like a factory reset but for your context, iconic.
and this is the part that lowkey saves you: the keycreate context is automatically reset after the next execve(2). so a program doesn't need to explicitly sanitize it upon startup. she cleans up after herself. we love a self-sufficient queen. π
also β and this is such a useful vibe β setkeycreatecon() can be applied prior to library functions that internally perform an file creation, in order to set an file context on the objects. (yes, "an file." keeping it exactly as the ancestors wrote it, iykyk π«Ά)
getkeycreatecon_raw() and setkeycreatecon_raw() behave identically to their non-raw counterparts, but they do not perform context translation. that's it. that's the difference. raw is just raw. π§
Note: Signal handlers that perform a setkeycreatecon() must take care to save, reset, and restore the keycreate context to avoid unexpected behavior. π like please, save your state, bestie. don't rawdog a signal handler and then act surprised.
Note: Contexts are thread specific. π§΅ so don't go assuming your fave context is shared across threads, because she is NOT.
β RETURN VALUE β
- On error,
-1is returned. π - On success,
0is returned. π
that's it. no middle ground. she's binary and she's thriving.
π SEE ALSO π
go read your siblings, they're all part of the same iconic family. π
okay that's the whole page, you're officially educated π this lil masterpiece was brought to you by dwalsh@redhat.com, dated 9 September 2008 β a true vintage banger that still slays today. πβ¨
π¦ 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
- debian trixie: libselinux1-dev 3.8.1-1 Β· LicenseRef-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
- nixos 26.05: libselinux 3.10
- nixpkgs unstable: libselinux 3.11
- opensuse-leap 16.0: libselinux-devel 3.8.1-160000.4.1 Β· SUSE-Public-Domain
- opensuse-leap 16.0: libselinux-devel 3.8.1-160000.4.1 Β· SUSE-Public-Domain
- opensuse-leap 16.0: libselinux-devel 3.8.1-160000.4.1 Β· SUSE-Public-Domain
- opensuse-leap 16.0: libselinux-devel 3.8.1-160000.4.1 Β· SUSE-Public-Domain
- ubuntu questing: libselinux1-dev 3.8.1-1build1
- ubuntu resolute: libselinux-dev 3.9-4build1 Β· LicenseRef-public-domain
- 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