Debian Codegraph @

libselinux/man/man5/selabel_file.5

raw
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" Author: Eamon Walsh ([email protected]) 2007
4 .TH "selabel_file" "5" "01 Dec 2011" "Security Enhanced Linux" "SELinux API documentation"
5 .SH "NAME"
6 selabel_file \- userspace SELinux labeling interface and configuration file format for the file contexts backend
7 .
8 .SH "SYNOPSIS"
9 .B #include <selinux/label.h>
10 .sp
11 .BI "int selabel_lookup(struct selabel_handle *" hnd ,
12 .in +\w'int selabel_lookup('u
13 .BI "char **" context ,
14 .br
15 .BI "const char *" path ", int " mode ");"
16 .in
17 .sp
18 .BI "int selabel_lookup_raw(struct selabel_handle *" hnd ,
19 .in +\w'int selabel_lookup('u
20 .BI "char **" context ,
21 .br
22 .BI "const char *" path ", int " mode ");"
23 .
24 .SH "DESCRIPTION"
25 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 \fIcontext\fR must be freed using \fBfreecon\fR(3).
26 .br
27 \fBselabel_lookup\fR(3) describes the function with its return and error codes, however the following \fIerrno\fR is clarified further for the file contexts backend:
28 .RS
29 .TP
30 .B ENOENT
31 No context corresponding to the \fIpath\fR and \fImode\fR was found - This will also be returned when the file contexts series of files have a context of \fB<<none>>\fR against the \fIpath\fR (see the \fBFILE FORMAT\fR section).
32 .RE
33 .sp
34 The \fIpath\fR argument should be set to the full pathname of the file whose assigned context is being checked. The \fImode\fR argument should be set to the mode bits of the file, as determined by \fBlstat\fR(2). \fImode\fR may be zero, however full matching may not occur.
35 .sp
36 Any messages generated by \fBselabel_lookup\fR(3) are sent to \fIstderr\fR
37 by default, although this can be changed by \fBselinux_set_callback\fR(3).
38 .sp
39 .BR selabel_lookup_raw (3)
40 behaves identically to \fBselabel_lookup\fR(3) but does not perform context
41 translation.
42 .sp
43 The \fBFILES\fR section details the configuration files used to determine a file context.
44 .
45 .SH "OPTIONS"
46 In addition to the global options described in
47 .BR selabel_open (3),
48 this backend recognizes the following options:
49 .RS
50 .TP
51 .B SELABEL_OPT_PATH
52 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.
53 .TP
54 .B SELABEL_OPT_BASEONLY
55 A non-null value for this option indicates that any local customizations to the file contexts mapping should be ignored.
56 .TP
57 .B SELABEL_OPT_SUBSET
58 A non-null value for this option is interpreted as a path prefix, for example "/etc". 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
59 .I file_contexts.bin
60 files and is deprecated.
61 .RE
62 .
63 .SH "FILES"
64 The file context files used to retrieve the default context depends on the \fBSELABEL_OPT_PATH\fR parameter passed to \fBselabel_open\fR(3). If \fINULL\fR, then the \fBSELABEL_OPT_PATH\fR value will default to the active policy file contexts location (as returned by \fBselinux_file_context_path\fR(3)), otherwise the actual \fBSELABEL_OPT_PATH\fR value specified is used.
65 .sp
66 If \fBSELABEL_OPT_BASEONLY\fR is set, then the following files will be processed:
67 .RS
68 .IP "1." 4
69 The mandatory file contexts file that is either the fully qualified file name from \fISELABEL_OPT_PATH.value\fR or if \fINULL\fR, then the path returned by \fBselinux_file_context_path\fR(3).
70 .IP "2." 4
71 The optional local and distribution substitution files that perform path aliasing on the 'in memory' version of the file contexts file.
72 .br
73 These files have the same name as the mandatory file contexts file with the extensions \fI.subs\fR and \fI.subs_dist\fR added.
74 .RE
75 .sp
76 If the \fBSELABEL_OPT_BASEONLY\fR is not set, then the following files will be processed:
77 .RS
78 .IP "1." 4
79 The mandatory file contexts file that is either the fully qualified file name from \fISELABEL_OPT_PATH.value\fR or if \fINULL\fR, then the path returned by \fBselinux_file_context_path\fR(3).
80 .IP "2." 4
81 The optional local customizations file that has the same name as the mandatory file contexts file with the extension \fI.local\fR added.
82 .br
83 \fBselinux_file_context_local_path\fR(3) will return the default path to this file.
84 .IP "3." 4
85 The optional user home directory customizations file that has the same name as the mandatory file contexts file with the extension \fI.homedirs\fR added.
86 .br
87 \fBselinux_file_context_homedir_path\fR(3) will return the default path to this file.
88 .IP "4." 4
89 The optional local and distribution substitution files that perform any path aliasing on the 'in memory' version of the file contexts file (and the \fI.local\fR and/or \fI.homedirs\fR if present). These files have the same name as the mandatory file contexts file with the extensions \fI.subs\fR and \fI.subs_dist\fR added.
90 .br
91 \fBselinux_file_context_subs_path\fR(3) and \fBselinux_file_context_subs_dist_path\fR(3) will return the default paths to these files.
92 .RE
93 .sp
94 The default file context series of files are:
95 .RS 6
96 .I /etc/selinux/{SELINUXTYPE}/contexts/files/file_contexts
97 .br
98 .I /etc/selinux/{SELINUXTYPE}/contexts/files/file_contexts.local
99 .br
100 .I /etc/selinux/{SELINUXTYPE}/contexts/files/file_contexts.homedirs
101 .br
102 .I /etc/selinux/{SELINUXTYPE}/contexts/files/file_contexts.subs
103 .br
104 .I /etc/selinux/{SELINUXTYPE}/contexts/files/file_contexts.subs_dist
105 .RE
106 .sp
107 Where \fI{SELINUXTYPE}\fR is the entry from the selinux configuration file \fIconfig\fR (see \fBselinux_config\fR(5)).
108 .sp
109 Only the \fIfile_contexts\fR file is mandatory, the remainder are optional.
110 .sp
111 The entries within the file contexts series of files are shown in the \fBFILE FORMAT\fR section.
112 .
113 .SH "FILE FORMAT"
114 .sp
115 .SH "File Contexts Format"
116 .sp
117 Each line within the \fIfile_contexts\fR and the two customization files (\fI.local\fR and \fI.homedirs\fR) is as follows:
118 .sp
119 .RS
120 .I pathname [file_type] context
121 .RE
122 .sp
123 Where:
124 .br
125 .RS
126 .I pathname
127 .RS
128 An entry that defines the pathname that may be in the form of a regular expression.
129 .RE
130 .I file_type
131 .RS
132 An optional file type consisting of:
133 .RS
134 \fI\-b\fR - Block Device \fI\-c\fR - Character Device
135 .br
136 \fI\-d\fR - Directory \fI\-p\fR - Named Pipe
137 .br
138 \fI\-l\fR - Symbolic Link \fI\-s\fR - Socket
139 .br
140 \fI\-\-\fR - Ordinary file
141 .RE
142 .RE
143 .I context
144 .RS
145 This entry can be either:
146 .RS
147 .IP "a." 4
148 The security context that will be assigned to the file (i.e. returned as \fIcontext\fR).
149 .IP "b." 4
150 A value of \fB<<none>>\fR can be used to indicate that the matching files should not be re-labeled and causes \fBselabel_lookup\fR(3) to return \-1 with \fIerrno\fR set to \fBENOENT\fR.
151 .RE
152 .RE
153 .RE
154 .sp
155 Example:
156 .RS
157 # ./contexts/files/file_contexts
158 .br
159 # pathname file_type context
160 .br
161 /.* system_u:object_r:default_t:s0
162 .br
163 /[^/]+ \-\- system_u:object_r:etc_runtime_t:s0
164 .br
165 /tmp/.* <<none>>
166 .RE
167 .sp
168 .SH "Substitution File Format"
169 .sp
170 Each line within the substitution files (\fI.subs\fR and \fI.subs_dist\fR) has the form:
171 .RS
172 .I subs_pathname pathname
173 .RE
174 .sp
175 Where:
176 .RS
177 .I pathname
178 .RS
179 A path that matches an entry in one or more of the file contexts policy configuration file.
180 .RE
181 .I subs_pathname
182 .RS
183 The path that will be aliased (considered equivalent) with pathname by the look up process.
184 .RE
185 .RE
186 .sp
187 Example:
188 .RS
189 # ./contexts/files/file_contexts.subs
190 .br
191 # pathname subs_pathname
192 .br
193 /myweb /var/www
194 .br
195 /myspool /var/spool/mail
196 .sp
197 Using the above example, when \fBselabel_lookup\fR(3) is passed a path of
198 \fI/myweb/index.html\fR the function will substitute the \fI/myweb\fR
199 component with \fI/var/www\fR, therefore the path used is:
200 .sp
201 .RS
202 .I /var/www/index.html
203 .RE
204 .RE
205 .
206 .SH "NOTES"
207 .IP "1." 4
208 If contexts are to be validated, then the global option \fBSELABEL_OPT_VALIDATE\fR must be set before calling \fBselabel_open\fR(3). If this is not set, then it is possible for an invalid context to be returned.
209 .IP "2." 4
210 If the size of file contexts series of files contain many entries, then \fBselabel_open\fR(3) may have a delay as it reads in the files, and if
211 requested validates the entries.
212 .IP "3." 4
213 Depending on the version of SELinux it is possible that a \fIfile_contexts.template\fR file may also be present, however this is now deprecated.
214 .br
215 The template file has the same format as the \fIfile_contexts\fR file and may also contain the keywords \fBHOME_ROOT\fR, \fBHOME_DIR\fR, \fBROLE\fR and \fBUSER\fR. This functionality has now been moved to the policy store and managed by \fBsemodule\fR(8) and \fBgenhomedircon\fR(8).
216 .
217 .SH "SEE ALSO"
218 .ad l
219 .nh
220 .BR selinux "(8), " selabel_open "(3), " selabel_lookup "(3), " selabel_stats "(3), " selabel_close "(3), " selinux_set_callback "(3), " selinux_file_context_path "(3), " freecon "(3), " selinux_config "(5), " lstat "(2), "selinux_file_context_subs_path "(3), " selinux_file_context_subs_dist_path "(3), " selinux_file_context_homedir_path "(3), "selinux_file_context_local_path "(3), " semodule "(8), " genhomedircon "(8) "