selabel_l...best_match(3)
π selabel_l...best_match(3) β SELinux API documentation β¨
okay bestie, welcome to the selabel_l...best_match(3) page β it's from the SELinux API documentation and it's giving extremely niche but honestly kind of iconic energy π
πΈ NAME πΈ
selabel_lookup_best_match β obtain a best match SELinux security context.
Only supported on file backend. like. fr. don't come for me, that's just the rules π
π¦ SYNOPSIS π¦
#include <selinux/selinux.h>
#include <selinux/label.h>
int selabel_lookup_best_match(struct selabel_handle *hnd,
char **context,
const char *key,
const char **links,
int type);
int selabel_lookup_best_match_raw(struct selabel_handle *hnd,
char **context,
const char *key,
const char **links,
int type);
two whole functions, both iconic, both taking the exact same arguments π«Ά
π DESCRIPTION π
so selabel_lookup_best_match() does a best match lookup operation on the handle hnd, and it drops the result into the memory that context points to. and bestie, heads up: that memory is yours to deal with β the caller has to free it using freecon(3). no takebacks, no shortcuts β¨
the key parameter is a file path to check for best match, and it does that using zero or more link (aliases) parameters. the order of precedence for best match is, in order:
- An exact match for the real path (
key) or - An exact match for any of the links (aliases), or
- The longest fixed prefix match.
like, that's the ranking. exact real path first, then aliases, then longest fixed prefix. periodt π
the type parameter is an optional file mode argument that should be set to the mode bits of the file, as determined by lstat(2). mode may be zero, however full matching may not occur. so likeβ¦ you can skip it but you're lowkey leaving matches on the table π
and then selabel_lookup_best_match_raw() behaves identically to selabel_lookup_best_match() but does not perform context translation. same vibes, one fewer step π
π RETURN VALUE π
- On success, zero is returned.
- On error,
-1is returned anderrnois set appropriately.
π ERRORS π
ENOENTβ No context corresponding to the inputkeyandtypewas found. she's just not there bestie π«EINVALβ Thekeyand/ortypeinputs are invalid, or the context being returned failed validation, or a regular expression in the database failed to compile. three different ways to be mad, all of them valid β¨ENOMEMβ An attempt to allocate memory failed. the RAM said no π
π§ NOTES π§
Example usage β when a service creates a device node, it may also create one or more symlinks to the device node. These symlinks may be the only stable name for the device, e.g. if the partition is dynamically assigned. The file label backend supports this by looking up the "best match" for a device node based on its real path (key) and any links to it (aliases). The order of precedence for best match is described above.
likeβ¦ that's the whole plot. dynamic partitions said "the symlink is the only name you're getting" and the file label backend said "say less, best match it is" π₯
β SEE ALSO β
and that's the page bestie!! this one came from Security Enhanced Linux, dated 05 May 2015, and honestly it ate π go free your context with freecon(3) and hydrate. 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
- 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