{"id":4486,"date":"2022-12-20T18:08:47","date_gmt":"2022-12-20T21:08:47","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/selabel_file-man5\/"},"modified":"2022-12-20T18:08:47","modified_gmt":"2022-12-20T21:08:47","slug":"selabel_file-man5","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/selabel_file-man5\/","title":{"rendered":"selabel_file (man5)"},"content":{"rendered":"<h1 align=\"center\">selabel_file<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#OPTIONS\">OPTIONS<\/a><br \/> <a href=\"#FILES\">FILES<\/a><br \/> <a href=\"#FILE FORMAT\">FILE FORMAT<\/a><br \/> <a href=\"#File Contexts Format\">File Contexts Format<\/a><br \/> <a href=\"#Substitution File Format\">Substitution File Format<\/a><br \/> <a href=\"#NOTES\">NOTES<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">selabel_file \u2212 userspace SELinux labeling interface and configuration file format for the file contexts backend<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>#include <selinux\/label.h><\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>int selabel_lookup(struct selabel_handle *<\/b><i>hnd<\/i><b>,<\/b><\/p>\n<p style=\"margin-left:40%;\"><b>char **<\/b><i>context<\/i><b>, <br \/> const char *<\/b><i>path<\/i><b>, int<\/b> <i>mode<\/i><b>);<\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>int selabel_lookup_raw(struct selabel_handle *<\/b><i>hnd<\/i><b>,<\/b><\/p>\n<p style=\"margin-left:40%;\"><b>char **<\/b><i>context<\/i><b>, <br \/> const char *<\/b><i>path<\/i><b>, int<\/b> <i>mode<\/i><b>);<\/b><\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The file contexts backend maps from pathname\/mode combinations into security contexts. It is used to find the appropriate context for each file when relabeling a file system. The returned <i>context<\/i> must be freed using <b>freecon<\/b>(3). <b><br \/> selabel_lookup<\/b>(3) describes the function with its return and error codes, however the following <i>errno<\/i> is clarified further for the file contexts backend:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"9%\">\n<p><b>ENOENT<\/b><\/p>\n<\/td>\n<td width=\"1%\"><\/td>\n<td width=\"68%\">\n<p>No context corresponding to the <i>path<\/i> and <i>mode<\/i> was found &#8211; This will also be returned when the file contexts series of files have a context of <b><<none>><\/b> against the <i>path<\/i> (see the <b>FILE FORMAT<\/b> section).<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>path<\/i> argument should be set to the full pathname of the file whose assigned context is being checked. The <i>mode<\/i> argument should be set to the mode bits of the file, as determined by <b>lstat<\/b>(2). <i>mode<\/i> may be zero, however full matching may not occur.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Any messages generated by <b>selabel_lookup<\/b>(3) are sent to <i>stderr<\/i> by default, although this can be changed by <b>selinux_set_callback<\/b>(3).<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>selabel_lookup_raw<\/b>(3) behaves identically to <b>selabel_lookup<\/b>(3) but does not perform context translation.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>FILES<\/b> section details the configuration files used to determine a file context.<\/p>\n<h2>OPTIONS <a name=\"OPTIONS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">In addition to the global options described in <b>selabel_open<\/b>(3), this backend recognizes the following options:<\/p>\n<p style=\"margin-left:22%;\"><b>SELABEL_OPT_PATH<\/b><\/p>\n<p style=\"margin-left:32%;\">A non-null value for this option specifies a path to a file that will be opened in lieu of the standard file contexts file. This value is also used as the base name for determining the names of local customization files.<\/p>\n<p style=\"margin-left:22%;\"><b>SELABEL_OPT_BASEONLY<\/b><\/p>\n<p style=\"margin-left:32%;\">A non-null value for this option indicates that any local customizations to the file contexts mapping should be ignored.<\/p>\n<p style=\"margin-left:22%;\"><b>SELABEL_OPT_SUBSET<\/b><\/p>\n<p style=\"margin-left:32%;\">A non-null value for this option is interpreted as a path prefix, for example &#8220;\/etc&#8221;. Only file context specifications with starting with a first component that prefix matches the given prefix are loaded. This may increase lookup performance, however any attempt to look up a path not starting with the given prefix may fail. This optimization is no longer required due to the use of <i>file_contexts.bin<\/i> files and is deprecated.<\/p>\n<h2>FILES <a name=\"FILES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The file context files used to retrieve the default context depends on the <b>SELABEL_OPT_PATH<\/b> parameter passed to <b>selabel_open<\/b>(3). If <i>NULL<\/i>, then the <b>SELABEL_OPT_PATH<\/b> value will default to the active policy file contexts location (as returned by <b>selinux_file_context_path<\/b>(3)), otherwise the actual <b>SELABEL_OPT_PATH<\/b> value specified is used.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If <b>SELABEL_OPT_BASEONLY<\/b> is set, then the following files will be processed:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"3%\">\n<p>1.<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"72%\">\n<p>The mandatory file contexts file that is either the fully qualified file name from <i>SELABEL_OPT_PATH.value<\/i> or if <i>NULL<\/i>, then the path returned by <b>selinux_file_context_path<\/b>(3).<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"3%\">\n<p>2.<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"72%\">\n<p>The optional local and distribution substitution files that perform path aliasing on the \u2019in memory\u2019 version of the file contexts file.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:28%;\">These files have the same name as the mandatory file contexts file with the extensions <i>.subs<\/i> and <i>.subs_dist<\/i> added.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If the <b>SELABEL_OPT_BASEONLY<\/b> is not set, then the following files will be processed:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"3%\">\n<p style=\"margin-top: 1em\">1.<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"72%\">\n<p style=\"margin-top: 1em\">The mandatory file contexts file that is either the fully qualified file name from <i>SELABEL_OPT_PATH.value<\/i> or if <i>NULL<\/i>, then the path returned by <b>selinux_file_context_path<\/b>(3).<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"3%\">\n<p>2.<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"72%\">\n<p>The optional local customizations file that has the same name as the mandatory file contexts file with the extension <i>.local<\/i> added.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:28%;\"><b>selinux_file_context_local_path<\/b>(3) will return the default path to this file.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"3%\">\n<p style=\"margin-top: 1em\">3.<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"72%\">\n<p style=\"margin-top: 1em\">The optional user home directory customizations file that has the same name as the mandatory file contexts file with the extension <i>.homedirs<\/i> added.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:28%;\"><b>selinux_file_context_homedir_path<\/b>(3) will return the default path to this file.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"3%\">\n<p style=\"margin-top: 1em\">4.<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"72%\">\n<p style=\"margin-top: 1em\">The optional local and distribution substitution files that perform any path aliasing on the \u2019in memory\u2019 version of the file contexts file (and the <i>.local<\/i> and\/or <i>.homedirs<\/i> if present). These files have the same name as the mandatory file contexts file with the extensions <i>.subs<\/i> and <i>.subs_dist<\/i> added.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:28%;\"><b>selinux_file_context_subs_path<\/b>(3) and <b>selinux_file_context_subs_dist_path<\/b>(3) will return the default paths to these files.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The default file context series of files are:<\/p>\n<p style=\"margin-left:20%;\"><i>\/etc\/selinux\/{SELINUXTYPE}\/contexts\/files\/file_contexts <br \/> \/etc\/selinux\/{SELINUXTYPE}\/contexts\/files\/file_contexts.local <br \/> \/etc\/selinux\/{SELINUXTYPE}\/contexts\/files\/file_contexts.homedirs <br \/> \/etc\/selinux\/{SELINUXTYPE}\/contexts\/files\/file_contexts.subs <br \/> \/etc\/selinux\/{SELINUXTYPE}\/contexts\/files\/file_contexts.subs_dist<\/i><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Where <i>{SELINUXTYPE}<\/i> is the entry from the selinux configuration file <i>config<\/i> (see <b>selinux_config<\/b>(5)).<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Only the <i>file_contexts<\/i> file is mandatory, the remainder are optional.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The entries within the file contexts series of files are shown in the <b>FILE FORMAT<\/b> section.<\/p>\n<h2>FILE FORMAT <a name=\"FILE FORMAT\"><\/a> <\/h2>\n<h2>File Contexts Format <a name=\"File Contexts Format\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Each line within the <i>file_contexts<\/i> and the two customization files (<i>.local<\/i> and <i>.homedirs<\/i>) is as follows:<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\"><i>pathname [file_type] context<\/i><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Where:<\/p>\n<p style=\"margin-left:22%;\"><i>pathname<\/i><\/p>\n<p style=\"margin-left:32%;\">An entry that defines the pathname that may be in the form of a regular expression.<\/p>\n<p style=\"margin-left:22%;\"><i>file_type<\/i><\/p>\n<p style=\"margin-left:32%;\">An optional file type consisting of:<\/p>\n<p style=\"margin-left:43%;\"><i>\u2212b<\/i> &#8211; Block Device <i>\u2212c<\/i> &#8211; Character Device <i><br \/> \u2212d<\/i> &#8211; Directory <i>\u2212p<\/i> &#8211; Named Pipe <i><br \/> \u2212l<\/i> &#8211; Symbolic Link <i>\u2212s<\/i> &#8211; Socket <i><br \/> \u2212\u2212<\/i> &#8211; Ordinary file<\/p>\n<p style=\"margin-left:22%;\"><i>context<\/i><\/p>\n<p style=\"margin-left:32%;\">This entry can be either:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"43%\"><\/td>\n<td width=\"3%\">\n<p style=\"margin-top: 1em\">a.<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"51%\">\n<p style=\"margin-top: 1em\">The security context that will be assigned to the file (i.e. returned as <i>context<\/i>).<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"43%\"><\/td>\n<td width=\"3%\">\n<p>b.<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"51%\">\n<p>A value of <b><<none>><\/b> can be used to indicate that the matching files should not be re-labeled and causes <b>selabel_lookup<\/b>(3) to return \u22121 with <i>errno<\/i> set to <b>ENOENT<\/b>.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">Example:<\/p>\n<p style=\"margin-left:22%;\"># .\/contexts\/files\/file_contexts <br \/> # pathname file_type context <br \/> \/. \/.. \/.cache system_u:object_r:default_t:s0 <br \/> \/[^\/]+ \u2212\u2212 system_u:object_r:etc_runtime_t:s0 <br \/> \/tmp\/. \/tmp\/.. \/tmp\/.esd-1000 \/tmp\/.font-unix \/tmp\/.ICE-unix \/tmp\/.Test-unix \/tmp\/.urpmi-1000 \/tmp\/.X0-lock \/tmp\/.X11-unix \/tmp\/.xfsm-ICE-77ORX1 \/tmp\/.XIM-unix <<none>><\/p>\n<h2>Substitution File Format <a name=\"Substitution File Format\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Each line within the substitution files (<i>.subs<\/i> and <i>.subs_dist<\/i>) has the form:<\/p>\n<p style=\"margin-left:22%;\"><i>subs_pathname pathname<\/i><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Where:<\/p>\n<p style=\"margin-left:22%;\"><i>pathname<\/i><\/p>\n<p style=\"margin-left:32%;\">A path that matches an entry in one or more of the file contexts policy configuration file.<\/p>\n<p style=\"margin-left:22%;\"><i>subs_pathname<\/i><\/p>\n<p style=\"margin-left:32%;\">The path that will be aliased (considered equivalent) with pathname by the look up process.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Example:<\/p>\n<p style=\"margin-left:22%;\"># .\/contexts\/files\/file_contexts.subs <br \/> # pathname subs_pathname <br \/> \/myweb \/var\/www <br \/> \/myspool \/var\/spool\/mail<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">Using the above example, when <b>selabel_lookup<\/b>(3) is passed a path of <i>\/myweb\/index.html<\/i> the function will substitute the <i>\/myweb<\/i> component with <i>\/var\/www<\/i>, therefore the path used is:<\/p>\n<p style=\"margin-left:32%; margin-top: 1em\"><i>\/var\/www\/index.html<\/i><\/p>\n<h2>NOTES <a name=\"NOTES\"><\/a> <\/h2>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"3%\">\n<p style=\"margin-top: 1em\">1.<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"83%\">\n<p style=\"margin-top: 1em\">If contexts are to be validated, then the global option <b>SELABEL_OPT_VALIDATE<\/b> must be set before calling <b>selabel_open<\/b>(3). If this is not set, then it is possible for an invalid context to be returned.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"3%\">\n<p>2.<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"83%\">\n<p>If the size of file contexts series of files contain many entries, then <b>selabel_open<\/b>(3) may have a delay as it reads in the files, and if requested validates the entries.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"3%\">\n<p>3.<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"83%\">\n<p>Depending on the version of SELinux it is possible that a <i>file_contexts.template<\/i> file may also be present, however this is now deprecated.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:17%;\">The template file has the same format as the <i>file_contexts<\/i> file and may also contain the keywords <b>HOME_ROOT<\/b>, <b>HOME_DIR<\/b>, <b>ROLE<\/b> and <b>USER<\/b>. This functionality has now been moved to the policy store and managed by <b>semodule<\/b>(8) and <b>genhomedircon<\/b>(8).<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>selinux<\/b>(8), <b>selabel_open<\/b>(3), <b>selabel_lookup<\/b>(3), <b>selabel_stats<\/b>(3), <b>selabel_close<\/b>(3), <b>selinux_set_callback<\/b>(3), <b>selinux_file_context_path<\/b>(3), <b>freecon<\/b>(3), <b>selinux_config<\/b>(5), <b>lstat<\/b>(2), <b>selinux_file_context_subs_path<\/b>(3), <b>selinux_file_context_subs_dist_path<\/b>(3), <b>selinux_file_context_homedir_path<\/b>(3), <b>selinux_file_context_local_path<\/b>(3), <b>semodule<\/b>(8), <b>genhomedircon<\/b>(8)<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  selabel_file \u2212 userspace SELinux labeling interface and configuration file format for the file contexts backend <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[959],"tags":[961,1291,1459],"class_list":["post-4486","post","type-post","status-publish","format-standard","hentry","category-5-formatos-de-ficheros","tag-961","tag-man5","tag-selabel_file"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4486","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=4486"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4486\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=4486"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=4486"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=4486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}