chiark / gitweb /
selinux: rework selinux access check logic
[elogind.git] / src / core / selinux-access.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #pragma once
4
5 /***
6   This file is part of systemd.
7
8   Copyright 2012 Dan Walsh
9
10   systemd is free software; you can redistribute it and/or modify it
11   under the terms of the GNU General Public License as published by
12   the Free Software Foundation; either version 2 of the License, or
13   (at your option) any later version.
14
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   General Public License for more details.
19
20   You should have received a copy of the GNU General Public License
21   along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24 void selinux_access_finish(void);
25 int selinux_manager_access_check(Manager *manager, DBusConnection *connection, DBusMessage *message, const char *permission, DBusError *error);
26 int selinux_unit_access_check(Unit *unit, DBusConnection *connection, DBusMessage *message, const char *permission, DBusError *error);
27
28 #ifdef HAVE_SELINUX
29
30 #define SELINUX_MANAGER_ACCESS_CHECK(manager, connection, message, permission)   \
31         do {                                                            \
32                 DBusError _error;                                       \
33                 int _r;                                                 \
34                 DBusConnection *_c = (connection);                      \
35                 DBusMessage *_m = (message);                            \
36                 dbus_error_init(&_error);                               \
37                 _r = selinux_manager_access_check((manager), _c, _m, (permission), &_error); \
38                 if (_r < 0)                                             \
39                         return bus_send_error_reply(_c, _m, &_error, _r); \
40         } while (false)
41
42 #define SELINUX_UNIT_ACCESS_CHECK(unit, connection, message, permission) \
43         do {                                                            \
44                 DBusError _error;                                       \
45                 int _r;                                                 \
46                 DBusConnection *_c = (connection);                      \
47                 DBusMessage *_m = (message);                            \
48                 dbus_error_init(&_error);                               \
49                 _r = selinux_unit_access_check((unit), _c, _m, (permission), &_error); \
50                 if (_r < 0)                                             \
51                         return bus_send_error_reply(_c, _m, &_error, _r); \
52         } while (false)
53
54 #else
55
56 #define SELINUX_MANAGER_ACCESS_CHECK(manager, connection, message, permission) do { } while (false)
57 #define SELINUX_UNIT_ACCESS_CHECK(unit, connection, message, permission) do { } while (false)
58
59 #endif