selinux_re...econ_xattr(3)
β¨ selinux_restorecon_xattr β¨ β the <pink>manage your security.sehash xattr entries</pink> era π
okay bestie, this is section 3 of the SELinux API documentation and we're about to make extended attributes make sense, fr fr.
πΈ NAME πΈ
selinux_restorecon_xattr β manage default security.sehash extended attribute entries added by selinux_restorecon(3), setfiles(8) or restorecon(8).
likeβ¦ it's the lil cleanup-and-look-at-your-xattrs bestie of the restorecon family. no cap. π
π¦ SYNOPSIS π¦
#include <selinux/restorecon.h>
int selinux_restorecon_xattr(const char *pathname,
unsigned int xattr_flags,
struct dir_xattr ***xattr_list);
three arguments, one header, zero drama. periodt. π
π DESCRIPTION π
so selinux_restorecon_xattr() hands you back a linked list of dir_xattr structures stuffed with the info described below, and what ends up in that list depends on:
pathnameβ a directory tree that we're gonna search forsecurity.sehashextended attribute entries. πxattr_flagsβ the options, and there are four of them, bestie, so buckle up:SELINUX_RESTORECON_XATTR_RECURSEβ recursively descend directories. go deeper. π³οΈβ¨SELINUX_RESTORECON_XATTR_DELETE_NONMATCH_DIGESTSβ delete non-matching digests from each directory inpathname. bye to the ones that don't match πSELINUX_RESTORECON_XATTR_DELETE_ALL_DIGESTSβ delete all digests from each directory inpathname. ALL of them. like, every single one. just so you know. πSELINUX_RESTORECON_XATTR_IGNORE_MOUNTSβ do not read/proc/mountsto obtain a list of non-seclabel mounts to be excluded from the search. settingSELINUX_RESTORECON_XATTR_IGNORE_MOUNTSis useful where there is a non-seclabel fs mounted with a seclabel fs mounted on a directory below this. iykyk π§
xattr_listβ the returned pointer to a linked list ofdir_xattrstructures, and each one is giving:
struct dir_xattr {
char *directory;
char *digest; /* Printable hex encoded string */
enum digest_result result;
struct dir_xattr *next;
};
and the result entry is enumerated like this, bestie:
enum digest_result {
MATCH = 0,
NOMATCH,
DELETED_MATCH,
DELETED_NOMATCH,
ERROR
};
π«Ά real talk:xattr_listmust be set toNULLbefore callingselinux_restorecon_xattr(3). and the caller is responsible for freeing the returnedxattr_listentries in the linked list. that's on you, not on us. don't be the girl who leaks memory π
see the NOTES section for more info. π
β RETURN VALUE β
- on success, zero is returned. slay. β
- on error, -1 is returned and
errnois set appropriately. π
π NOTES π
- by default
selinux_restorecon_xattr(3)will use the default set of specfiles described infiles_contexts(5)to calculate the SHA256 digests to be used for comparison. to change this default behaviorselabel_open(3)must be called specifying the requiredSELABEL_OPT_PATHand setting theSELABEL_OPT_DIGESToption to a non-NULL value. thenselinux_restorecon_set_sehandle(3)is called to set the handle to be used byselinux_restorecon_xattr(3). so many steps but we ate. π - by default
selinux_restorecon_xattr(3)reads/proc/mountsto obtain a list of non-seclabel mounts to be excluded from searches β unless theSELINUX_RESTORECON_XATTR_IGNORE_MOUNTSflag has been set. β¨ RAMFSandTMPFSfilesystems do not support thesecurity.sehashextended attribute and are automatically excluded from searches. they're just not invited to the party, and honestly? fair. π- by default
stderris used to log output messages and errors. this may be changed by callingselinux_set_callback(3)with theSELINUX_CB_LOGtype option. redirect that output wherever you want, main character. π
π SEE ALSO π
selinux_restorecon(3)selinux_restorecon_set_sehandle(3)selinux_restorecon_default_handle(3)selinux_restorecon_set_exclude_list(3)selinux_restorecon_set_alt_rootpath(3)selinux_set_callback(3)
go read those too, bestie, they're all in the same friend group. π«Ά
and that's the whole page, mwah π β this little baddie dropped on 30 July 2016 under the SELinux API documentation umbrella. old but iconic, and still absolutely ate. stay safe out there with your digests, and don't forget to free your linked list. xoxo ππ¦β¨
π¦ where this page comes from
- 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
- 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
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms