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 β€” if a is greater than b
  • -1 β€” if a is less than b

✨ 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