smack-setup.c revision 03e334a1c7dc8c20c38902aa039440763acc9b17
/*-*- 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 "fileio.h"
#include "log.h"
#include "label.h"
#define SMACK_CONFIG "/etc/smack/accesses.d/"
#define CIPSO_CONFIG "/etc/smack/cipso.d/"
#ifdef HAVE_SMACK
int dfd = -1;
int r = 0;
if (!dst) {
return -errno; /* negative error */
}
/* write rules to dst from every file in the directory */
if (!dir) {
return errno; /* positive on purpose */
}
int fd;
if (fd < 0) {
if (r == 0)
r = -errno;
continue;
}
if (!policy) {
if (r == 0)
r = -errno;
safe_close(fd);
continue;
}
/* load2 write rules in the kernel require a line buffered stream */
log_error("Failed to read line from %s: %m",
if (r == 0)
r = -EINVAL;
break;
}
if (r == 0)
r = -errno;
break;
}
}
}
return r;
}
#endif
int smack_setup(bool *loaded_policy) {
#ifdef HAVE_SMACK
int r;
switch(r) {
case -ENOENT:
log_debug("Smack is not enabled in the kernel.");
return 0;
case ENOENT:
return 0;
case 0:
log_info("Successfully loaded Smack policies.");
break;
default:
log_warning("Failed to load Smack access rules: %s, ignoring.",
return 0;
}
#ifdef SMACK_RUN_LABEL
if (r)
log_warning("Failed to set SMACK label \"%s\" on self: %s",
SMACK_RUN_LABEL, strerror(-r));
#endif
switch(r) {
case -ENOENT:
return 0;
case ENOENT:
return 0;
case 0:
return 0;
default:
log_warning("Failed to load Smack/CIPSO access rules: %s, ignoring.",
return 0;
}
*loaded_policy = true;
#endif
return 0;
}