chiark / gitweb /
selinux: rework selinux access check logic
[elogind.git] / src / core / dbus-socket.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4   This file is part of systemd.
5
6   Copyright 2010 Lennart Poettering
7
8   systemd is free software; you can redistribute it and/or modify it
9   under the terms of the GNU Lesser General Public License as published by
10   the Free Software Foundation; either version 2.1 of the License, or
11   (at your option) any later version.
12
13   systemd is distributed in the hope that it will be useful, but
14   WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   Lesser General Public License for more details.
17
18   You should have received a copy of the GNU Lesser General Public License
19   along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include <errno.h>
23
24 #include "dbus-unit.h"
25 #include "dbus-socket.h"
26 #include "dbus-execute.h"
27 #include "dbus-kill.h"
28 #include "dbus-common.h"
29 #include "selinux-access.h"
30
31 #define BUS_SOCKET_INTERFACE                                            \
32         " <interface name=\"org.freedesktop.systemd1.Socket\">\n"       \
33         "  <property name=\"BindIPv6Only\" type=\"b\" access=\"read\"/>\n" \
34         "  <property name=\"Backlog\" type=\"u\" access=\"read\"/>\n"   \
35         "  <property name=\"TimeoutUSec\" type=\"t\" access=\"read\"/>\n" \
36         BUS_EXEC_COMMAND_INTERFACE("ExecStartPre")                      \
37         BUS_EXEC_COMMAND_INTERFACE("ExecStartPost")                     \
38         BUS_EXEC_COMMAND_INTERFACE("ExecStopPre")                       \
39         BUS_EXEC_COMMAND_INTERFACE("ExecStopPost")                      \
40         BUS_EXEC_CONTEXT_INTERFACE                                      \
41         BUS_KILL_CONTEXT_INTERFACE                                      \
42         "  <property name=\"ControlPID\" type=\"u\" access=\"read\"/>\n" \
43         "  <property name=\"BindToDevice\" type=\"s\" access=\"read\"/>\n" \
44         "  <property name=\"DirectoryMode\" type=\"u\" access=\"read\"/>\n" \
45         "  <property name=\"SocketMode\" type=\"u\" access=\"read\"/>\n" \
46         "  <property name=\"Accept\" type=\"b\" access=\"read\"/>\n"    \
47         "  <property name=\"KeepAlive\" type=\"b\" access=\"read\"/>\n" \
48         "  <property name=\"Priority\" type=\"i\" access=\"read\"/>\n"  \
49         "  <property name=\"ReceiveBuffer\" type=\"t\" access=\"read\"/>\n" \
50         "  <property name=\"SendBuffer\" type=\"t\" access=\"read\"/>\n" \
51         "  <property name=\"IPTOS\" type=\"i\" access=\"read\"/>\n"     \
52         "  <property name=\"IPTTL\" type=\"i\" access=\"read\"/>\n"     \
53         "  <property name=\"PipeSize\" type=\"t\" access=\"read\"/>\n"  \
54         "  <property name=\"FreeBind\" type=\"b\" access=\"read\"/>\n"  \
55         "  <property name=\"Transparent\" type=\"b\" access=\"read\"/>\n" \
56         "  <property name=\"Broadcast\" type=\"b\" access=\"read\"/>\n" \
57         "  <property name=\"PassCredentials\" type=\"b\" access=\"read\"/>\n" \
58         "  <property name=\"PassSecurity\" type=\"b\" access=\"read\"/>\n" \
59         "  <property name=\"Mark\" type=\"i\" access=\"read\"/>\n"      \
60         "  <property name=\"MaxConnections\" type=\"u\" access=\"read\"/>\n" \
61         "  <property name=\"NAccepted\" type=\"u\" access=\"read\"/>\n" \
62         "  <property name=\"NConnections\" type=\"u\" access=\"read\"/>\n" \
63         "  <property name=\"MessageQueueMaxMessages\" type=\"x\" access=\"read\"/>\n" \
64         "  <property name=\"MessageQueueMessageSize\" type=\"x\" access=\"read\"/>\n" \
65         "  <property name=\"Result\" type=\"s\" access=\"read\"/>\n"    \
66         " </interface>\n"                                               \
67
68 #define INTROSPECTION                                                   \
69         DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE                       \
70         "<node>\n"                                                      \
71         BUS_UNIT_INTERFACE                                              \
72         BUS_SOCKET_INTERFACE                                            \
73         BUS_PROPERTIES_INTERFACE                                        \
74         BUS_PEER_INTERFACE                                              \
75         BUS_INTROSPECTABLE_INTERFACE                                    \
76         "</node>\n"
77
78 #define INTERFACES_LIST                              \
79         BUS_UNIT_INTERFACES_LIST                     \
80         "org.freedesktop.systemd1.Socket\0"
81
82 const char bus_socket_interface[] _introspect_("Socket") = BUS_SOCKET_INTERFACE;
83
84 const char bus_socket_invalidating_properties[] =
85         "ExecStartPre\0"
86         "ExecStartPost\0"
87         "ExecStopPre\0"
88         "ExecStopPost\0"
89         "ControlPID\0"
90         "NAccepted\0"
91         "NConnections\0"
92         "Result\0";
93
94 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_socket_append_bind_ipv6_only, socket_address_bind_ipv6_only, SocketAddressBindIPv6Only);
95 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_socket_append_socket_result, socket_result, SocketResult);
96
97 static const BusProperty bus_socket_properties[] = {
98         { "BindIPv6Only",   bus_socket_append_bind_ipv6_only,  "s", offsetof(Socket, bind_ipv6_only)  },
99         { "Backlog",        bus_property_append_unsigned,      "u", offsetof(Socket, backlog)         },
100         { "TimeoutUSec",    bus_property_append_usec,          "t", offsetof(Socket, timeout_usec)    },
101         BUS_EXEC_COMMAND_PROPERTY("ExecStartPre",  offsetof(Socket, exec_command[SOCKET_EXEC_START_PRE]),  true ),
102         BUS_EXEC_COMMAND_PROPERTY("ExecStartPost", offsetof(Socket, exec_command[SOCKET_EXEC_START_POST]), true ),
103         BUS_EXEC_COMMAND_PROPERTY("ExecStopPre",   offsetof(Socket, exec_command[SOCKET_EXEC_STOP_PRE]),   true ),
104         BUS_EXEC_COMMAND_PROPERTY("ExecStopPost",  offsetof(Socket, exec_command[SOCKET_EXEC_STOP_POST]),  true ),
105         { "ControlPID",     bus_property_append_pid,           "u", offsetof(Socket, control_pid)     },
106         { "BindToDevice",   bus_property_append_string,        "s", offsetof(Socket, bind_to_device), true },
107         { "DirectoryMode",  bus_property_append_mode,          "u", offsetof(Socket, directory_mode)  },
108         { "SocketMode",     bus_property_append_mode,          "u", offsetof(Socket, socket_mode)     },
109         { "Accept",         bus_property_append_bool,          "b", offsetof(Socket, accept)          },
110         { "KeepAlive",      bus_property_append_bool,          "b", offsetof(Socket, keep_alive)      },
111         { "Priority",       bus_property_append_int,           "i", offsetof(Socket, priority)        },
112         { "ReceiveBuffer",  bus_property_append_size,          "t", offsetof(Socket, receive_buffer)  },
113         { "SendBuffer",     bus_property_append_size,          "t", offsetof(Socket, send_buffer)     },
114         { "IPTOS",          bus_property_append_int,           "i", offsetof(Socket, ip_tos)          },
115         { "IPTTL",          bus_property_append_int,           "i", offsetof(Socket, ip_ttl)          },
116         { "PipeSize",       bus_property_append_size,          "t", offsetof(Socket, pipe_size)       },
117         { "FreeBind",       bus_property_append_bool,          "b", offsetof(Socket, free_bind)       },
118         { "Transparent",    bus_property_append_bool,          "b", offsetof(Socket, transparent)     },
119         { "Broadcast",      bus_property_append_bool,          "b", offsetof(Socket, broadcast)       },
120         { "PassCredentials",bus_property_append_bool,          "b", offsetof(Socket, pass_cred)       },
121         { "PassSecurity",   bus_property_append_bool,          "b", offsetof(Socket, pass_sec)        },
122         { "Mark",           bus_property_append_int,           "i", offsetof(Socket, mark)            },
123         { "MaxConnections", bus_property_append_unsigned,      "u", offsetof(Socket, max_connections) },
124         { "NConnections",   bus_property_append_unsigned,      "u", offsetof(Socket, n_connections)   },
125         { "NAccepted",      bus_property_append_unsigned,      "u", offsetof(Socket, n_accepted)      },
126         { "MessageQueueMaxMessages", bus_property_append_long, "x", offsetof(Socket, mq_maxmsg)       },
127         { "MessageQueueMessageSize", bus_property_append_long, "x", offsetof(Socket, mq_msgsize)      },
128         { "Result",         bus_socket_append_socket_result,   "s", offsetof(Socket, result)          },
129         { NULL, }
130 };
131
132 DBusHandlerResult bus_socket_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
133         Socket *s = SOCKET(u);
134         const BusBoundProperties bps[] = {
135                 { "org.freedesktop.systemd1.Unit",   bus_unit_properties,         u },
136                 { "org.freedesktop.systemd1.Socket", bus_socket_properties,       s },
137                 { "org.freedesktop.systemd1.Socket", bus_exec_context_properties, &s->exec_context },
138                 { "org.freedesktop.systemd1.Socket", bus_kill_context_properties, &s->kill_context },
139                 { NULL, }
140         };
141
142         SELINUX_UNIT_ACCESS_CHECK(u, c, message, "status");
143
144         return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, bps);
145 }