SELINUX_FILE_CONTEXT_CMP(3)
π selinux_file_context_cmp β bestie edition π
okay so you're in the selinux_file_context_cmp(3) page, which lives in the Library Functions Manual, and honestly? it's a little one but it's a good one. let's get into it π«Ά
β¨ NAME β¨
selinux_file_context_cmp β compare two SELinux security contexts, but skip the 'user' component entirely. yeah. we're not even looking at it. iconic behaviour honestly π
β¨ SYNOPSIS β¨
#include <selinux/selinux.h>
int selinux_file_context_cmp(const char *a,
const char *b);
two strings walk in, one int walks out. classic π
β¨ DESCRIPTION β¨
so selinux_file_context_cmp() takes two context strings and compares them, excluding the user component, using strcmp(3) β and yes, the EXAMPLE section below literally shows you exactly how that works, so don't stress.
and why would you want that? because for most object contexts, the user component isn't relevant. that's the whole point. it's giving "we can agree to disagree about the user part" and honestly? slay πΈ
β¨ RETURN VALUE β¨
the return values are just doing what strcmp(3) does, no cap:
0β if they are equal π1β ifais greater thanb-1β ifais less thanb
β¨ ERRORS β¨
None. zero. nada. no errors to worry about β¨ (a rare and blessed occurrence, bestie)
β¨ NOTES β¨
just so we're clear: the contexts you're comparing don't specifically need to be file contexts. the name is a little misleading, the vibe is not. iykyk π¦
β¨ EXAMPLE β¨
say context a is:
user_u:user_r:user_t:s0
and context b is:
root:user_r:user_t:s0
then the actual strings being compared are:
:user_r:user_t:s0 and :user_r:user_t:s0
see how the user part just... vanished? bye bye user_u, bye bye root π
so they match, and selinux_file_context_cmp() returns zero. we love a happy ending π₯Ήπ
β¨ SEE ALSO β¨
SELinux API documentation Β· 08 March 2011 Β· selinux_file_context_cmp(3)
and that's the page, bestie!! written back on 08 March 2011 for the SELinux API documentation, and it's still out here being selinux_file_context_cmp(3) in the Library Functions Manual. go forth and compare contexts, minus the user component. periodt π
β¨π
π¦ 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 jammy: libselinux1-dev 3.3-1build2
- 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