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

Function set_process_security_ctx

src/copy.c:575–628  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

573 Return FALSE on failure, TRUE on success. */
574
575bool
576set_process_security_ctx (char const *src_name, char const *dst_name,
577 mode_t mode, bool new_dst, const struct cp_options *x)
578{
579 if (x->preserve_security_context)
580 {
581 /* Set the default context for the process to match the source. */
582 bool all_errors = !x->data_copy_required || x->require_preserve_context;
583 bool some_errors = !all_errors && !x->reduce_diagnostics;
584 char *con_raw;
585
586 if (0 <= lgetfilecon_raw (src_name, &con_raw))
587 {
588 if (setfscreatecon_raw (con_raw) < 0)
589 {
590 if (all_errors || (some_errors && !errno_unsupported (errno)))
591 error (0, errno,
592 _("failed to set default file creation context to %s"),
593 quote (con_raw));
594 if (x->require_preserve_context)
595 {
596 freecon (con_raw);
597 return false;
598 }
599 }
600 freecon (con_raw);
601 }
602 else
603 {
604 if (all_errors || (some_errors && !errno_unsupported (errno)))
605 {
606 error (0, errno,
607 _("failed to get security context of %s"),
608 quoteaf (src_name));
609 }
610 if (x->require_preserve_context)
611 return false;
612 }
613 }
614 else if (x->set_security_context)
615 {
616 /* With -Z, adjust the default context for the process
617 to have the type component adjusted as per the destination path. */
618 if (new_dst && defaultcon (x->set_security_context, dst_name, mode) < 0
619 && ! ignorable_ctx_err (errno))
620 {
621 error (0, errno,
622 _("failed to set default file creation context for %s"),
623 quoteaf (dst_name));
624 }
625 }
626
627 return true;
628}
629
630/* Reset the security context of DST_NAME, to that already set
631 as the process default if !X->set_security_context. Otherwise

Callers 3

copy_regFunction · 0.85
copy_internalFunction · 0.85
make_dir_parents_privateFunction · 0.85

Calls 3

errno_unsupportedFunction · 0.85
ignorable_ctx_errFunction · 0.85
defaultconFunction · 0.70

Tested by

no test coverage detected