summaryrefslogtreecommitdiff
path: root/src/udev/smack-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-01-09 19:36:26 -0500
committerAnthony G. Basile <blueness@gentoo.org>2014-01-09 19:36:26 -0500
commitb51ff2cd4aee8033f8d3f4bb8eb9eb7035737152 (patch)
tree3ebe72403fb96eb0c011be72a15b88cdd9eb8a66 /src/udev/smack-util.c
parent97b903d94eca5cc6cf17262f91e43227998d3301 (diff)
security: rework selinux, smack, ima, apparmor detection logic
Always cache the results, and bypass low-level security calls when the respective subsystem is not enabled. Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src/udev/smack-util.c')
-rw-r--r--src/udev/smack-util.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/udev/smack-util.c b/src/udev/smack-util.c
new file mode 100644
index 0000000000..93c0d4a347
--- /dev/null
+++ b/src/udev/smack-util.c
@@ -0,0 +1,42 @@
+/***
+ This file is part of eudev, forked from systemd.
+
+ Copyright 2013 Intel Corporation
+
+ Author: Auke Kok <auke-jan.h.kok@intel.com>
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <unistd.h>
+#include <string.h>
+#ifdef HAVE_XATTR
+#include <attr/xattr.h>
+#endif
+
+#include "smack-util.h"
+
+bool use_smack(void) {
+#ifdef HAVE_SMACK
+ static int use_smack_cached = -1;
+
+ if (use_smack_cached < 0)
+ use_smack_cached = access("/sys/fs/smackfs/", F_OK) >= 0;
+
+ return use_smack_cached;
+#else
+ return false;
+#endif
+
+}