getsockcreatecon(3)
π getsockcreatecon β get or set the SELinux security context used for creating new labeled sockets π
okay bestie, welcome to getsockcreatecon(3) from the SELinux API docs, she's niche but she's iconic β¨ this page covers getsockcreatecon, setsockcreatecon and their raw twins. no cap, it's giving "tiny API, big responsibility". let's get into it π«Ά
β¨ SYNOPSIS β¨
#include <selinux/selinux.h>
int getsockcreatecon(char **con);
int getsockcreatecon_raw(char **con);
int setsockcreatecon(const char *context);
int setsockcreatecon_raw(const char *context);
πΈ DESCRIPTION πΈ
so getsockcreatecon() is the lil gossip girl of this duo β she retrieves the context that's used for creating a new labeled network socket. π
if the returned context is non-NULL, you gotta free it with freecon(3). and here's the tea: getsockcreatecon() sets *con to NULL if no sockcreate context has been explicitly set by the program (meaning it's just vibing with the default policy behavior). so NULL is not a bug, it's a whole mood π
setsockcreatecon() is the one doing the setting β she sets the context used for creating new labeled network sockets. and yes, you can pass NULL to setsockcreatecon() to reset back to the default policy behavior. no drama, just a clean slate β¨
and listen, the sockcreate context is automatically reset after the next execve(2), so your program doesn't have to explicitly sanitize it on startup. she cleans up after herself, main character energy fr fr π
setsockcreatecon() can also be applied prior to library functions that internally perform a file creation, in order to set a file context on the objects. lowkey powerful π¦
getsockcreatecon_raw() and setsockcreatecon_raw() behave identically to their non-raw counterparts, except they do not perform context translation. same girl, no translator π
β οΈ Note: signal handlers that perform a setsockcreatecon() must take care to save, reset, and restore the sockcreate context, otherwise you get unexpected behavior. do not skip this step bestie, it WILL bite π
β οΈ Note: contexts are thread specific. so like, one thread's context is not another thread's context, periodt π
β RETURN VALUE β
- on error,
-1is returned π - on success,
0is returned π
π¦ SEE ALSO π¦
and that's the whole page, bestie!! π this gem was written by dwalsh@redhat.com on 24 September 2008, and it's getsockcreatecon(3) out of the SELinux API documentation. she's been slaying since '08 and she's still relevant. obsessed π«Άβ¨π
π¦ 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