summaryrefslogtreecommitdiff
path: root/src/udev/smack-util.c
diff options
context:
space:
mode:
authorKay Sievers <kay@vrfy.org>2013-10-11 09:47:31 +0200
committerAnthony G. Basile <blueness@gentoo.org>2014-01-09 19:39:13 -0500
commitb49063901eaa5f883a7f2d3c0fa4968eed5589b4 (patch)
treebc3f47988967e78aedce10cc9bd46965057cbef0 /src/udev/smack-util.c
parentb51ff2cd4aee8033f8d3f4bb8eb9eb7035737152 (diff)
smack: minimize ifdef use, and move all labeling to smack-util.c
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src/udev/smack-util.c')
-rw-r--r--src/udev/smack-util.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/udev/smack-util.c b/src/udev/smack-util.c
index 93c0d4a347..2711041c7e 100644
--- a/src/udev/smack-util.c
+++ b/src/udev/smack-util.c
@@ -40,3 +40,50 @@ bool use_smack(void) {
#endif
}
+
+int smack_label_path(const char *path, const char *label) {
+#ifdef HAVE_SMACK
+ if (!use_smack())
+ return 0;
+
+ if (label)
+ return setxattr(path, "security.SMACK64", label, strlen(label), 0);
+ else
+ return lremovexattr(path, "security.SMACK64");
+#else
+ return 0;
+#endif
+}
+
+int smack_label_fd(int fd, const char *label) {
+#ifdef HAVE_SMACK
+ if (!use_smack())
+ return 0;
+
+ return fsetxattr(fd, "security.SMACK64", label, strlen(label), 0);
+#else
+ return 0;
+#endif
+}
+
+int smack_label_ip_out_fd(int fd, const char *label) {
+#ifdef HAVE_SMACK
+ if (!use_smack())
+ return 0;
+
+ return fsetxattr(fd, "security.SMACK64IPOUT", label, strlen(label), 0);
+#else
+ return 0;
+#endif
+}
+
+int smack_label_ip_in_fd(int fd, const char *label) {
+#ifdef HAVE_SMACK
+ if (!use_smack())
+ return 0;
+
+ return fsetxattr(fd, "security.SMACK64IPIN", label, strlen(label), 0);
+#else
+ return 0;
+#endif
+}