setfilecon(3)
π setfilecon β the SELinux glow-up page π
okay bestie, welcome to setfilecon(3), straight out of the SELinux API documentation β¨ this is the little family of functions that gives a file a whole new security context. it's giving makeover montage, but for extended attributes. no cap.
β¨ NAME β¨
setfilecon, fsetfilecon, lsetfilecon β set SELinux security context of a file π
πΈ SYNOPSIS πΈ
#include <selinux/selinux.h>
int setfilecon(const char *path, const char *con);
int setfilecon_raw(const char *path, const char *con);
int lsetfilecon(const char *path, const char *con);
int lsetfilecon_raw(const char *path, const char *con);
int fsetfilecon(int fd, const char *con);
int fsetfilecon_raw(int fd, const char *con);
π¦ DESCRIPTION π¦
so setfilecon() sets the security context of the file system object. that's the whole vibe. main character behavior, honestly π
lsetfilecon() is identical to setfilecon, except in the case of a symbolic link β there, the link itself has its context set, not the file that it refers to. it does NOT follow the link. lowkey important, don't skip this one π
fsetfilecon() is identical to setfilecon too, only the open file pointed to by filedes (as returned by open(2)) has its context set in place of path. and since libselinux 3.4, a file opened via O_PATH is supported π that's the upgrade arc fr fr.
setfilecon_raw(), lsetfilecon_raw(), and fsetfilecon_raw() behave identically to their non-raw counterparts but do not perform context translation. raw is raw, no filter, no translation layer, periodt π
β RETURN VALUE β
- on success, zero is returned β¨
- on failure,
-1is returned anderrnois set appropriately π
π ERRORS π
if there's not enough space left to store the extended attribute, errno gets set to either ENOSPC, or EDQUOT if quota enforcement was the cause. not me getting hit with a quota π
if extended attributes are not supported by the filesystem, or are disabled, errno is set to ENOTSUP. the filesystem said "no π
" and honestly we respect it.
also: the errors documented for the stat(2) system call are applicable here too. so go read that one, bestie, iykyk π«Ά
π SEE ALSO π
selinux(3)freecon(3)getfilecon(3)setfscreatecon(3)
and that's the whole page, you ate it πβ¨
cute lil sign-off: this gem is from the SELinux API documentation, setfilecon(3), and the page itself was written by russell@coker.com.au, dated 1 January 2004. iconic. historic. 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
- 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