MCPcopy Create free account
hub / github.com/coreutils/coreutils / setdefaultfilecon

Function setdefaultfilecon

src/install.c:319–351  ·  view source on GitHub ↗

Modify file context to match the specified policy. If an error occurs the file will remain with the default directory context. Note this sets the context to that returned by selabel_lookup and thus discards MLS levels and user identity of the FILE. */

Source from the content-addressed store, hash-verified

317 context. Note this sets the context to that returned by selabel_lookup
318 and thus discards MLS levels and user identity of the FILE. */
319static void
320setdefaultfilecon (char const *file)
321{
322 if (selinux_enabled != 1)
323 {
324 /* Indicate no context found. */
325 return;
326 }
327
328 struct stat st;
329 if (lstat (file, &st) != 0)
330 return;
331
332 struct selabel_handle *hnd = get_labeling_handle ();
333 if (!hnd)
334 return;
335
336 char *scontext_raw = NULL;
337 if (selabel_lookup_raw (hnd, &scontext_raw, file, st.st_mode) != 0)
338 {
339 if (errno != ENOENT && ! ignorable_ctx_err (errno))
340 error (0, errno, _("warning: %s: context lookup failed"),
341 quotef (file));
342 return;
343 }
344
345 if (lsetfilecon_raw (file, scontext_raw) < 0 && errno != ENOTSUP)
346 error (0, errno,
347 _("warning: %s: failed to change context to %s"),
348 quotef_n (0, file), quote_n (1, scontext_raw));
349
350 freecon (scontext_raw);
351}
352
353/* Report that directory DIR was made, if OPTIONS requests this. */
354static void

Callers 1

change_attributesFunction · 0.85

Calls 2

get_labeling_handleFunction · 0.85
ignorable_ctx_errFunction · 0.85

Tested by

no test coverage detected