getfilecon(3)
π getfilecon β SELinux API documentation β¨
okay bestie, so this is a page from the SELinux API documentation β the manual name is getfilecon and it lives in section 3 of the manual (that's the library-functions section, iykyk). it's all about peeking at a file's SELinux security context and honestly? iconic. π
πΈ NAME πΈ
getfilecon, fgetfilecon, lgetfilecon β get SELinux security context of a file π
no cap, that's the whole job. grab the security context. slay.
β¨ SYNOPSIS β¨
#include <selinux/selinux.h>
int getfilecon(const char *path, char **con);
int getfilecon_raw(const char *path, char **con);
int lgetfilecon(const char *path, char **con);
int lgetfilecon_raw(const char *path, char **con);
int fgetfilecon(int fd, char **con);
int fgetfilecon_raw(int fd, char **con);
six functions, all matching, all serving looks. π
π¦ DESCRIPTION π¦
so here's the tea, bestie. π
getfilecon()β retrieves the context associated with the given path in the file system, and the length of the context is returned. literally just "hey what's this file's vibe" and it tells you. πlgetfilecon()β identical togetfilecon(), except in the case of a symbolic link, where the link itself is interrogated, not the file that it refers to. so it's the "don't look at the destination, look at the link, bestie" version. πfgetfilecon()β identical togetfilecon(), only the open file pointed to by filedes (as returned byopen(2)) is interrogated in place of path. and ooh, since libselinux 3.4 a file opened viaO_PATHis supported. glow up fr fr. β¨getfilecon_raw(),lgetfilecon_raw()andfgetfilecon_raw()β they behave identically to their non-raw counterparts but do not perform context translation. raw is raw, no filter, no translation, just the context as it is. periodt. π
β οΈ important bestie: the returned context should be freed with freecon(3) if non-NULL. don't be out here leaking memory, that's not the vibe. π«Ά
π RETURN VALUE π
okay so the receipts:
- on success, a positive number is returned indicating the size of the extended attribute value. so it's giving you a number AND the context. main character energy. π
- on failure,
-1is returned anderrnois set appropriately.
and the errno lore, because context matters (literally):
- if the context does not exist, or the process has no access to this attribute,
errnois set toENODATA. it's not there, or it's not for you. π - if extended attributes are not supported by the filesystem, or are disabled,
errnois set toENOTSUP. the filesystem said "we don't do that here". π
and also β the errors documented for the stat(2) system call are also applicable here. so go read that one too, bestie. π
π SEE ALSO π
go read these next, it's the friend group of manpages fr fr. π
russell@coker.com.au wrote this one, and it's dated 1 January 2004 β so yeah, this page is old enough to have its own aesthetic, and it's still serving. mwah. πβ¨
π¦ 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
- centos-stream 9: libselinux-devel 3.6-5.el9 Β· Public Domain
- centos-stream 9: libselinux-devel 3.6-5.el9 Β· Public Domain
- debian bookworm: libselinux1-dev 3.4-1+b6
- 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 noble: libselinux1-dev 3.5-2ubuntu2 Β· LicenseRef-public-domain
- ubuntu noble: libselinux1-dev 3.5-2ubuntu2.1 Β· LicenseRef-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