summaryrefslogtreecommitdiff
path: root/src/mkdir.c
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2013-12-04 19:10:37 +0000
committerPádraig Brady <P@draigBrady.com>2013-12-05 00:18:36 +0000
commit0013de3e603162081c4464ea1f7ad3285f633d78 (patch)
treed93f83bc57d79b098b7d20d9cb60cf1b8296779e /src/mkdir.c
parentb53b0fd940382497e58a9e912f1262c2084fe534 (diff)
downloadcoreutils-0013de3e603162081c4464ea1f7ad3285f633d78.tar.xz
selinux: fix --context=CTX for cp and diagnose defaultcon() errors
* src/selinux.h (ignorable_ctx_err): A new function used to determine if a warning should be given after a call to defaultcon() or restorecon(). * src/cp.c (main): Fix the setfscreatecon() call to use the argument passed by the user. * src/mkdir.c (make_ancestor): Show all but "ignoreable" errors from defaultcon() and restorecon(). * tests/misc/selinux.sh: Add a test run as root in selinux enforcing mode, to ensure cp --context=invalid is honored and fails immediately.
Diffstat (limited to 'src/mkdir.c')
-rw-r--r--src/mkdir.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/mkdir.c b/src/mkdir.c
index 25b1da5e7..adc293019 100644
--- a/src/mkdir.c
+++ b/src/mkdir.c
@@ -118,7 +118,8 @@ make_ancestor (char const *dir, char const *component, void *options)
{
struct mkdir_options const *o = options;
- if (o->set_security_context && defaultcon (dir, S_IFDIR) < 0)
+ if (o->set_security_context && defaultcon (dir, S_IFDIR) < 0
+ && ! ignorable_ctx_err (errno))
error (0, errno, _("failed to set default creation context for %s"),
quote (dir));
@@ -162,7 +163,8 @@ process_dir (char *dir, struct savewd *wd, void *options)
set_defaultcon = true;
free (pdir);
}
- if (set_defaultcon && defaultcon (dir, S_IFDIR) < 0)
+ if (set_defaultcon && defaultcon (dir, S_IFDIR) < 0
+ && ! ignorable_ctx_err (errno))
error (0, errno, _("failed to set default creation context for %s"),
quote (dir));
}
@@ -180,8 +182,9 @@ process_dir (char *dir, struct savewd *wd, void *options)
and here we set the context for the final component. */
if (ret == EXIT_SUCCESS && o->set_security_context && ! set_defaultcon)
{
- if (restorecon (last_component (dir), false, false) < 0)
- error (0, errno, _("failed to set restore context for %s"),
+ if (! restorecon (last_component (dir), false, false)
+ && ! ignorable_ctx_err (errno))
+ error (0, errno, _("failed to restore context for %s"),
quote (dir));
}