chiark / gitweb /
build-sys: add a makefile target to run all tests through valgrind
[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 Lesser General Public License as published by
12   the Free Software Foundation; either version 2.1 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   Lesser General Public License for more details.
19
20   You should have received a copy of the GNU Lesser General Public License
21   along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24 #include <dbus.h>
25
26 void selinux_access_free(void);
27
28 int selinux_access_check(DBusConnection *connection, DBusMessage *message, const char *path, const char *permission, DBusError *error);
29
30 #ifdef HAVE_SELINUX
31
32 #define SELINUX_ACCESS_CHECK(connection, message, permission) \
33         do {                                                            \
34                 DBusError _error;                                       \
35                 int _r;                                                 \
36                 DBusConnection *_c = (connection);                      \
37                 DBusMessage *_m = (message);                            \
38                 dbus_error_init(&_error);                               \
39                 _r = selinux_access_check(_c, _m, NULL, (permission), &_error); \
40                 if (_r < 0)                                             \
41                         return bus_send_error_reply(_c, _m, &_error, _r); \
42         } while (false)
43
44 #define SELINUX_UNIT_ACCESS_CHECK(unit, connection, message, permission) \
45         do {                                                            \
46                 DBusError _error;                                       \
47                 int _r;                                                 \
48                 DBusConnection *_c = (connection);                      \
49                 DBusMessage *_m = (message);                            \
50                 Unit *_u = (unit);                                      \
51                 dbus_error_init(&_error);                               \
52                 _r = selinux_access_check(_c, _m, _u->source_path ?: _u->fragment_path, (permission), &_error); \
53                 if (_r < 0)                                             \
54                         return bus_send_error_reply(_c, _m, &_error, _r); \
55         } while (false)
56
57 #else
58
59 #define SELINUX_ACCESS_CHECK(connection, message, permission) do { } while (false)
60 #define SELINUX_UNIT_ACCESS_CHECK(unit, connection, message, permission) do { } while (false)
61
62 #endif