selinux-access.h revision 718db96199eb307751264e4163555662c9a389fa
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen#pragma once
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen/***
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen This file is part of systemd.
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen Copyright 2012 Dan Walsh
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen systemd is free software; you can redistribute it and/or modify it
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen under the terms of the GNU Lesser General Public License as published by
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen the Free Software Foundation; either version 2.1 of the License, or
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen (at your option) any later version.
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen systemd is distributed in the hope that it will be useful, but
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen WITHOUT ANY WARRANTY; without even the implied warranty of
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen Lesser General Public License for more details.
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen You should have received a copy of the GNU Lesser General Public License
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen***/
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen#include "sd-bus.h"
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen#include "bus-error.h"
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen#include "bus-util.h"
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersenvoid selinux_access_free(void);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersenint selinux_access_check(sd_bus *bus, sd_bus_message *message, const char *path, const char *permission, sd_bus_error *error);
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen#ifdef HAVE_SELINUX
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen#define SELINUX_ACCESS_CHECK(bus, message, permission) \
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen do { \
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen _cleanup_bus_error_free_ sd_bus_error _error = SD_BUS_ERROR_NULL; \
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen sd_bus_message *_m = (message); \
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen sd_bus *_b = (bus); \
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen int _r; \
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen _r = selinux_access_check(_b, _m, NULL, (permission), &_error); \
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen if (_r < 0) \
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen return sd_bus_reply_method_errno(_b, _m, _r, &_error); \
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen } while (false)
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen#define SELINUX_UNIT_ACCESS_CHECK(unit, bus, message, permission) \
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen do { \
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen _cleanup_bus_error_free_ sd_bus_error _error = SD_BUS_ERROR_NULL; \
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen sd_bus_message *_m = (message); \
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen sd_bus *_b = (bus); \
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen Unit *_u = (unit); \
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen int _r; \
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen _r = selinux_access_check(_b, _m, _u->source_path ?: _u->fragment_path, (permission), &_error); \
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen if (_r < 0) \
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen return sd_bus_reply_method_errno(_b, _m, _r, &_error); \
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen } while (false)
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen#else
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen#define SELINUX_ACCESS_CHECK(bus, message, permission) do { } while (false)
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen#define SELINUX_UNIT_ACCESS_CHECK(unit, bus, message, permission) do { } while (false)
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen#endif
e3dca0089b7b50e2ec21409d1292727921d06102Tom Gundersen