smack-setup.c revision ffbd2c4d45787ba5ba85a32db6551efba66a1ee6
/*-*- 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_info("Smack is not enabled in the kernel, not loading access rules.");
return 0;
}
/* write rules to load2 from every file in the directory */
if (!dir) {
return 0;
}
if (dfd < 0) {
return 0;
}
if (pol < 0) {
continue;
}
if (!policy) {
continue;
}
pol = -1;
/* load2 write rules in the kernel require a line buffered stream */
FOREACH_LINE(buf, policy, log_error("Failed to read from Smack access rule file %s: %m", entry->d_name)) {
}
}
log_info("Successfully loaded Smack policies.");
return 0;
}