selinux_ra...t_to_color(3)

πŸ“¦
version 3.11 Β· 2 versions
, in alpine 3.24, centos-stream 10, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– selinux_ra...t_to_color β€” bestie edition πŸ’–

okay so you found the selinux_raw_context_to_color(3) page, a lil' number from the Library Functions Manual, and honestly? it's giving ✨ color-coded MLS vibes ✨. let's get into it.


🌈 NAME 🌈

selinux_raw_context_to_color β€” literally just returns an RGB color string for an SELinux security context. that's the whole job. she's a one-trick pony and she ate. πŸ’…


✨ SYNOPSIS ✨

#include <selinux/selinux.h>

int selinux_raw_context_to_color(const char *raw,
       char **color_str);

πŸŽ€ DESCRIPTION πŸŽ€

so selinux_raw_context_to_color() hands you back a color_str that's associated with the raw context raw, but ONLY if all three of these lil' conditions are slaying at the same time:

  • the mcstransd(8) daemon is running πŸ”₯
  • the policy is an MLS type policy (MCS or MLS, pick your fighter)
  • there's a color configuration file secolor.conf(5) chillin' there (peep the FILES section, iykyk)

the color_str string? it's a space separated list of eight hexadecimal RGB triples, and every single one is prefixed with a hash character (#). these represent the user:role:type:range components of the foreground and background colors. there's a whole example string down in the EXAMPLE section if you wanna see one irl. πŸ¦‹

bestie the returned color_str string MUST be freed with free(3). don't be a memory leaker, that's not main character energy. 😭

so like, what if a color hasn't been configured for a specific user, role, type and/or range component of context raw? then selinux_raw_context_to_color() will select the color returned in color_str in order of precedence, like this:

  • role, type, range
  • user, type, range
  • user, role, range
  • user, role, type

and if there are literally NO entries in the secolor.conf(5) file for any of the components of context raw (or the file just... isn't there πŸ™ˆ), then the default string returned in color_str is:

----- user ---- ---- role ----  ---- type ----  ---- range ----
#000000 #ffffff #000000 #ffffff #000000 #ffffff #000000 #ffffff

πŸ’« RETURN VALUE πŸ’«

  • on success, zero is returned 🫢
  • on failure, -1 is returned with errno set appropriately πŸ˜”

πŸ’€ ERRORS πŸ’€

  • ENOENT β€” thrown when the mcstransd(8) daemon is not running. like girl, wake up. πŸ””

🌸 FILES 🌸

selinux_raw_context_to_color() obtains the translated entry from the active policy secolor.conf(5) file as returned by selinux_colors_path(3). the file format is fully described in secolor.conf(5). go read it, no cap. πŸ“–


πŸ‘‘ NOTES πŸ‘‘

  1. the primary use of selinux_raw_context_to_color() is to return a color that corresponds to a range, that can then be used to highlight information at different MLS levels. that's the ✨ moment ✨ it was born for.
  2. the mcstransd(8) daemon process security level must dominate the raw security level passed to it by the selinux_raw_context_to_color() function. if it does NOT? then the range color selected will be as defined by the order of precedence. so like, respect the hierarchy bestie, it's not optional. 🧚

πŸ“ EXAMPLE πŸ“

selinux_raw_context_to_color() returns the foreground and background colors of the context string components (user:role:type:range) as RGB triples, like this:

      user     :       role      :      type      :      range
  fg       bg  :   fg       bg   :  fg       bg   :  fg       bg
#000000 #ffffff  #ffffff #000000  #d2b48c #ffa500  #000000 #008000
 black   white :  white   black  : tan    orange  : black   green

look at that. tan and orange in the house. iconic. 🌈


πŸ’œ SEE ALSO πŸ’œ

selinux(8), selinux_colors_path(3), mcstransd(8), secolor.conf(5), selinux_raw_to_trans_context(3), selinux_trans_to_raw_context(3), free(3)


and that's the whole page bestie!! this lil' slice of SELinux API documentation was brought to you on 08 April 2011 by the SELinux API documentation crew, and honestly? still slaying all these years later. mwah. πŸ’–βœ¨πŸŽ€πŸ¦‹