smack-setup.c revision fea7838e7e0b2724f5e0bc028121a08b42995045
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright (C) 2013 Intel Corporation
Authors:
Nathaniel Chen <nathaniel.chen@intel.com>
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 <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <dirent.h>
#include <stdint.h>
#include "macro.h"
#include "smack-setup.h"
#include "util.h"
#include "log.h"
#include "label.h"
#define ACCESSES_D_PATH "/etc/smack/accesses.d/"
int smack_setup(void) {
int dfd = -1;
if (!smack) {
log_debug("Smack is not enabled in the kernel, not loading access rules.");
else
log_warning("Failed to open /sys/fs/smackfs/load2: %m");
return 0;
}
/* write rules to load2 from every file in the directory */
if (!dir) {
"Opening Smack access rules directory "
ACCESSES_D_PATH ": %m");
return 0;
}
if (pol < 0) {
log_error("Smack access rule file %s not opened: %m",
continue;
}
if (!policy) {
log_error("Smack access rule file %s not opened: %m",
continue;
}
pol = -1;
/* load2 write rules in the kernel require a line buffered stream */
log_error("Failed to read from Smack access rule file %s: %m",
}
}
log_info("Successfully loaded Smack policies.");
return 0;
}