selinux_ra...t_to_color(3)
π 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 returnedcolor_strstring MUST be freed withfree(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, rangeuser, type, rangeuser, role, rangeuser, 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,
-1is returned witherrnoset appropriately π
π ERRORS π
ENOENTβ thrown when themcstransd(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 π
- 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. - the
mcstransd(8)daemon process security level must dominate the raw security level passed to it by theselinux_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. πβ¨ππ¦
π¦ 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