Debian Codegraph @

libselinux/man/man3/selinux_restorecon.3

raw
1 .TH "selinux_restorecon" "3" "20 Oct 2015" "Security Enhanced Linux" "SELinux API documentation"
2
3 .SH "NAME"
4 selinux_restorecon \- restore file(s) default SELinux security contexts
5 .
6 .SH "SYNOPSIS"
7 .B #include <selinux/restorecon.h>
8 .sp
9 .BI "int selinux_restorecon(const char *" pathname ,
10 .in +\w'int selinux_restorecon('u
11 .br
12 .BI "unsigned int " restorecon_flags ");"
13 .in
14 .
15 .SH "DESCRIPTION"
16 .BR selinux_restorecon ()
17 restores file default security contexts on filesystems that support extended
18 attributes (see
19 .BR xattr (7)),
20 based on:
21 .sp
22 .RS
23 .IR pathname
24 containing a directory or file to be relabeled.
25 .br
26 If this is a directory and the
27 .IR restorecon_flags
28 .B SELINUX_RESTORECON_RECURSE
29 has been set (for descending through directories), then
30 .BR selinux_restorecon ()
31 will write an SHA1 digest of the combined specfiles (see the
32 .B NOTES
33 section for details) to an extended attribute of
34 .IR security.restorecon_last
35 once the relabeling has been completed successfully. This digest will be
36 checked should
37 .BR selinux_restorecon ()
38 be rerun
39 with the
40 .IR restorecon_flags
41 .B SELINUX_RESTORECON_RECURSE
42 flag set. If any of the specfiles had been updated, the digest
43 will also be updated. However if the digest is the same, no relabeling checks
44 will take place (unless the
45 .B SELINUX_RESTORECON_IGNORE_DIGEST
46 flag is set).
47 .sp
48 .IR restorecon_flags
49 contains the labeling option/rules as follows:
50 .sp
51 .RS
52 .sp
53 .B SELINUX_RESTORECON_IGNORE_DIGEST
54 force the checking of labels even if the stored SHA1 digest matches the
55 specfiles SHA1 digest. The specfiles digest will be written to the
56 .IR security.restorecon_last
57 extended attribute once relabeling has been completed successfully provided the
58 .B SELINUX_RESTORECON_NOCHANGE
59 flag has not been set.
60 .sp
61 .B SELINUX_RESTORECON_NOCHANGE
62 don't change any file labels (passive check) or update the digest in the
63 .IR security.restorecon_last
64 extended attribute.
65 .sp
66 .B SELINUX_RESTORECON_SET_SPECFILE_CTX
67 If set, reset the files label to match the default specfile context.
68 If not set only reset the files "type" component of the context to match the
69 default specfile context.
70 .sp
71 .B SELINUX_RESTORECON_RECURSE
72 change file and directory labels recursively (descend directories)
73 and if successful write an SHA1 digest of the combined specfiles to an
74 extended attribute as described in the
75 .B NOTES
76 section.
77 .sp
78 .B SELINUX_RESTORECON_VERBOSE
79 log file label changes.
80 .RS
81 Note that if
82 .B SELINUX_RESTORECON_VERBOSE
83 and
84 .B SELINUX_RESTORECON_PROGRESS
85 flags are set, then
86 .B SELINUX_RESTORECON_PROGRESS
87 will take precedence.
88 .RE
89 .sp
90 .B SELINUX_RESTORECON_PROGRESS
91 show progress by outputting the number of files in 1k blocks processed
92 to stdout. If the
93 .B SELINUX_RESTORECON_MASS_RELABEL
94 flag is also set then the approximate percentage complete will be shown.
95 .sp
96 .B SELINUX_RESTORECON_MASS_RELABEL
97 generally set when relabeling the entire OS, that will then show the
98 approximate percentage complete. The
99 .B SELINUX_RESTORECON_PROGRESS
100 flag must also be set.
101 .sp
102 .B SELINUX_RESTORECON_REALPATH
103 convert passed-in
104 .I pathname
105 to the canonical pathname using
106 .BR realpath (3).
107 .sp
108 .B SELINUX_RESTORECON_XDEV
109 prevent descending into directories that have a different device number than
110 the
111 .I pathname
112 entry from which the descent began.
113 .sp
114 .B SELINUX_RESTORECON_ADD_ASSOC
115 attempt to add an association between an inode and a specification. If there
116 is already an association for the inode and it conflicts with the
117 specification, then use the last matching specification.
118 .sp
119 .B SELINUX_RESTORECON_ABORT_ON_ERROR
120 abort on errors during the file tree walk.
121 .sp
122 .B SELINUX_RESTORECON_SYSLOG_CHANGES
123 log any label changes to
124 .BR syslog (3).
125 .sp
126 .B SELINUX_RESTORECON_LOG_MATCHES
127 log what specfile context matched each file.
128 .sp
129 .B SELINUX_RESTORECON_IGNORE_NOENTRY
130 ignore files that do not exist.
131 .sp
132 .B SELINUX_RESTORECON_IGNORE_MOUNTS
133 do not read
134 .B /proc/mounts
135 to obtain a list of non-seclabel mounts to be excluded from relabeling checks.
136 .br
137 Setting
138 .B SELINUX_RESTORECON_IGNORE_MOUNTS
139 is useful where there is a non-seclabel fs mounted with a seclabel fs mounted
140 on a directory below this.
141 .RE
142 .sp
143 The behavior regarding the checking and updating of the SHA1 digest described
144 above is the default behavior. It is possible to change this by first calling
145 .BR selabel_open (3)
146 and not enabling the
147 .B SELABEL_OPT_DIGEST
148 option, then calling
149 .BR selinux_restorecon_set_sehandle (3)
150 to set the handle to be used by
151 .BR selinux_restorecon (3).
152 .sp
153 If the
154 .I pathname
155 is a directory path, then it is possible to set directories to be excluded
156 from the path by calling
157 .BR selinux_restorecon_set_exclude_list (3)
158 with a
159 .B NULL
160 terminated list before calling
161 .BR selinux_restorecon (3).
162 .sp
163 By default
164 .BR selinux_restorecon (3)
165 reads
166 .B /proc/mounts
167 to obtain a list of non-seclabel mounts to be excluded from relabeling checks
168 unless the
169 .B SELINUX_RESTORECON_IGNORE_MOUNTS
170 flag has been set.
171 .RE
172 .
173 .SH "RETURN VALUE"
174 On success, zero is returned. On error, \-1 is returned and
175 .I errno
176 is set appropriately.
177 .
178 .SH "NOTES"
179 .IP "1." 4
180 To improve performance when relabeling file systems recursively (e.g. the
181 .IR restorecon_flags
182 .B SELINUX_RESTORECON_RECURSE
183 flag is set)
184 .BR selinux_restorecon ()
185 will write an SHA1 digest of the specfiles that are processed by
186 .BR selabel_open (3)
187 to an extended attribute named
188 .IR security.restorecon_last
189 to the directory specified in the
190 .IR pathname .
191 .IP "2." 4
192 To check the extended attribute entry use
193 .BR getfattr (1) ,
194 for example:
195 .sp
196 .RS
197 .RS
198 getfattr -e hex -n security.restorecon_last /
199 .RE
200 .RE
201 .IP "3." 4
202 The SHA1 digest is calculated by
203 .BR selabel_open (3)
204 concatenating the specfiles it reads during initialisation with the
205 resulting digest and list of specfiles being retrieved by
206 .BR selabel_digest (3).
207 .IP "4." 4
208 The specfiles consist of the mandatory
209 .I file_contexts
210 file plus any subs, subs_dist, local and homedir entries (text or binary versions)
211 as determined by any
212 .BR selabel_open (3)
213 options e.g.
214 .BR SELABEL_OPT_BASEONLY .
215 .sp
216 Should any of the specfiles have changed, then when
217 .BR selinux_restorecon ()
218 is run again with the
219 .B SELINUX_RESTORECON_RECURSE
220 flag set, a new SHA1 digest will be calculated and all files will be automatically
221 relabeled depending on the settings of the
222 .B SELINUX_RESTORECON_SET_SPECFILE_CTX
223 flag (provided
224 .B SELINUX_RESTORECON_NOCHANGE
225 is not set).
226 .IP "5." 4
227 .B /sys
228 and in-memory filesystems do not support the
229 .IR security.restorecon_last
230 extended attribute and are automatically excluded from any relabeling checks.
231 .IP "6." 4
232 By default
233 .B stderr
234 is used to log output messages and errors. This may be changed by calling
235 .BR selinux_set_callback (3)
236 with the
237 .B SELINUX_CB_LOG
238 .I type
239 option.
240 .
241 .SH "SEE ALSO"
242 .BR selinux_restorecon_set_sehandle (3),
243 .br
244 .BR selinux_restorecon_default_handle (3),
245 .br
246 .BR selinux_restorecon_set_exclude_list (3),
247 .br
248 .BR selinux_restorecon_set_alt_rootpath (3),
249 .br
250 .BR selinux_restorecon_xattr (3),
251 .br
252 .BR selinux_set_callback (3)