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. */
| 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. */ |
| 319 | static void |
| 320 | setdefaultfilecon (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. */ |
| 354 | static void |
no test coverage detected