1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2013 Intel Corporation
8 Author: Auke Kok <auke-jan.h.kok@intel.com>
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
27 #include <attr/xattr.h>
30 #include "smack-util.h"
32 bool use_smack(void) {
34 static int use_smack_cached = -1;
36 if (use_smack_cached < 0)
37 use_smack_cached = access("/sys/fs/smackfs/", F_OK) >= 0;
39 return use_smack_cached;
46 int smack_label_path(const char *path, const char *label) {
52 return setxattr(path, "security.SMACK64", label, strlen(label), 0);
54 return lremovexattr(path, "security.SMACK64");
60 int smack_label_fd(int fd, const char *label) {
65 return fsetxattr(fd, "security.SMACK64", label, strlen(label), 0);
71 int smack_label_ip_out_fd(int fd, const char *label) {
76 return fsetxattr(fd, "security.SMACK64IPOUT", label, strlen(label), 0);
82 int smack_label_ip_in_fd(int fd, const char *label) {
87 return fsetxattr(fd, "security.SMACK64IPIN", label, strlen(label), 0);