]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/dbus-socket.c
socket: add option for SO_PASSEC
[thirdparty/systemd.git] / src / dbus-socket.c
CommitLineData
d6c9574f 1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4139c1b2
LP
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 General Public License as published by
10 the Free Software Foundation; either version 2 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 General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
c0120d99
LP
22#include <errno.h>
23
4139c1b2
LP
24#include "dbus-unit.h"
25#include "dbus-socket.h"
26#include "dbus-execute.h"
bfebab7f 27#include "dbus-common.h"
4139c1b2 28
4288f619
LP
29#define BUS_SOCKET_INTERFACE \
30 " <interface name=\"org.freedesktop.systemd1.Socket\">\n" \
31 " <property name=\"BindIPv6Only\" type=\"b\" access=\"read\"/>\n" \
32 " <property name=\"Backlog\" type=\"u\" access=\"read\"/>\n" \
33 " <property name=\"TimeoutUSec\" type=\"t\" access=\"read\"/>\n" \
fe68089d
LP
34 BUS_EXEC_COMMAND_INTERFACE("ExecStartPre") \
35 BUS_EXEC_COMMAND_INTERFACE("ExecStartPost") \
36 BUS_EXEC_COMMAND_INTERFACE("ExecStopPre") \
37 BUS_EXEC_COMMAND_INTERFACE("ExecStopPost") \
4288f619 38 BUS_EXEC_CONTEXT_INTERFACE \
4288f619
LP
39 " <property name=\"ControlPID\" type=\"u\" access=\"read\"/>\n" \
40 " <property name=\"BindToDevice\" type=\"s\" access=\"read\"/>\n" \
41 " <property name=\"DirectoryMode\" type=\"u\" access=\"read\"/>\n" \
42 " <property name=\"SocketMode\" type=\"u\" access=\"read\"/>\n" \
43 " <property name=\"Accept\" type=\"b\" access=\"read\"/>\n" \
4fd5948e
LP
44 " <property name=\"KeepAlive\" type=\"b\" access=\"read\"/>\n" \
45 " <property name=\"Priority\" type=\"i\" access=\"read\"/>\n" \
2419cc5b
LP
46 " <property name=\"ReceiveBuffer\" type=\"t\" access=\"read\"/>\n" \
47 " <property name=\"SendBuffer\" type=\"t\" access=\"read\"/>\n" \
48 " <property name=\"IPTOS\" type=\"i\" access=\"read\"/>\n" \
49 " <property name=\"IPTTL\" type=\"i\" access=\"read\"/>\n" \
50 " <property name=\"PipeSize\" type=\"t\" access=\"read\"/>\n" \
51 " <property name=\"FreeBind\" type=\"b\" access=\"read\"/>\n" \
6b6d2dee 52 " <property name=\"Transparent\" type=\"b\" access=\"read\"/>\n" \
ec6370a2 53 " <property name=\"Broadcast\" type=\"b\" access=\"read\"/>\n" \
271b032a 54 " <property name=\"PassCredentials\" type=\"b\" access=\"read\"/>\n" \
54ecda32 55 " <property name=\"PassSecurity\" type=\"b\" access=\"read\"/>\n" \
2419cc5b 56 " <property name=\"Mark\" type=\"i\" access=\"read\"/>\n" \
4e1e43c8
LP
57 " <property name=\"MaxConnections\" type=\"u\" access=\"read\"/>\n" \
58 " <property name=\"NAccepted\" type=\"u\" access=\"read\"/>\n" \
59 " <property name=\"NConnections\" type=\"u\" access=\"read\"/>\n" \
cb4fdfc1
LP
60 " <property name=\"MessageQueueMaxMessages\" type=\"x\" access=\"read\"/>\n" \
61 " <property name=\"MessageQueueMessageSize\" type=\"x\" access=\"read\"/>\n" \
cfc4eb4c 62 " <property name=\"Result\" type=\"s\" access=\"read\"/>\n" \
4288f619
LP
63 " </interface>\n" \
64
65#define INTROSPECTION \
66 DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
67 "<node>\n" \
68 BUS_UNIT_INTERFACE \
69 BUS_SOCKET_INTERFACE \
70 BUS_PROPERTIES_INTERFACE \
c4e2ceae 71 BUS_PEER_INTERFACE \
4288f619
LP
72 BUS_INTROSPECTABLE_INTERFACE \
73 "</node>\n"
74
05feefe0
LP
75#define INTERFACES_LIST \
76 BUS_UNIT_INTERFACES_LIST \
77 "org.freedesktop.systemd1.Socket\0"
78
9a60da28 79const char bus_socket_interface[] _introspect_("Socket") = BUS_SOCKET_INTERFACE;
4139c1b2 80
c4e2ceae
LP
81const char bus_socket_invalidating_properties[] =
82 "ExecStartPre\0"
83 "ExecStartPost\0"
84 "ExecStopPre\0"
85 "ExecStopPost\0"
86 "ControlPID\0"
87 "NAccepted\0"
cfc4eb4c
LP
88 "NConnections\0"
89 "Result\0";
c4e2ceae 90
c0120d99 91static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_socket_append_bind_ipv6_only, socket_address_bind_ipv6_only, SocketAddressBindIPv6Only);
cfc4eb4c 92static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_socket_append_socket_result, socket_result, SocketResult);
c0120d99 93
d200735e
MS
94static const BusProperty bus_socket_properties[] = {
95 { "BindIPv6Only", bus_socket_append_bind_ipv6_only, "s", offsetof(Socket, bind_ipv6_only) },
96 { "Backlog", bus_property_append_unsigned, "u", offsetof(Socket, backlog) },
97 { "TimeoutUSec", bus_property_append_usec, "t", offsetof(Socket, timeout_usec) },
98 BUS_EXEC_COMMAND_PROPERTY("ExecStartPre", offsetof(Socket, exec_command[SOCKET_EXEC_START_PRE]), true ),
99 BUS_EXEC_COMMAND_PROPERTY("ExecStartPost", offsetof(Socket, exec_command[SOCKET_EXEC_START_POST]), true ),
100 BUS_EXEC_COMMAND_PROPERTY("ExecStopPre", offsetof(Socket, exec_command[SOCKET_EXEC_STOP_PRE]), true ),
101 BUS_EXEC_COMMAND_PROPERTY("ExecStopPost", offsetof(Socket, exec_command[SOCKET_EXEC_STOP_POST]), true ),
102 { "ControlPID", bus_property_append_pid, "u", offsetof(Socket, control_pid) },
103 { "BindToDevice", bus_property_append_string, "s", offsetof(Socket, bind_to_device), true },
104 { "DirectoryMode", bus_property_append_mode, "u", offsetof(Socket, directory_mode) },
105 { "SocketMode", bus_property_append_mode, "u", offsetof(Socket, socket_mode) },
106 { "Accept", bus_property_append_bool, "b", offsetof(Socket, accept) },
107 { "KeepAlive", bus_property_append_bool, "b", offsetof(Socket, keep_alive) },
108 { "Priority", bus_property_append_int, "i", offsetof(Socket, priority) },
109 { "ReceiveBuffer", bus_property_append_size, "t", offsetof(Socket, receive_buffer) },
110 { "SendBuffer", bus_property_append_size, "t", offsetof(Socket, send_buffer) },
111 { "IPTOS", bus_property_append_int, "i", offsetof(Socket, ip_tos) },
112 { "IPTTL", bus_property_append_int, "i", offsetof(Socket, ip_ttl) },
113 { "PipeSize", bus_property_append_size, "t", offsetof(Socket, pipe_size) },
114 { "FreeBind", bus_property_append_bool, "b", offsetof(Socket, free_bind) },
115 { "Transparent", bus_property_append_bool, "b", offsetof(Socket, transparent) },
116 { "Broadcast", bus_property_append_bool, "b", offsetof(Socket, broadcast) },
117 { "PassCredentials",bus_property_append_bool, "b", offsetof(Socket, pass_cred) },
54ecda32 118 { "PassSecurity", bus_property_append_bool, "b", offsetof(Socket, pass_sec) },
d200735e
MS
119 { "Mark", bus_property_append_int, "i", offsetof(Socket, mark) },
120 { "MaxConnections", bus_property_append_unsigned, "u", offsetof(Socket, max_connections) },
121 { "NConnections", bus_property_append_unsigned, "u", offsetof(Socket, n_connections) },
122 { "NAccepted", bus_property_append_unsigned, "u", offsetof(Socket, n_accepted) },
123 { "MessageQueueMaxMessages", bus_property_append_long, "x", offsetof(Socket, mq_maxmsg) },
124 { "MessageQueueMessageSize", bus_property_append_long, "x", offsetof(Socket, mq_msgsize) },
cfc4eb4c 125 { "Result", bus_socket_append_socket_result, "s", offsetof(Socket, result) },
d200735e
MS
126 { NULL, }
127};
128
5e8d1c9a 129DBusHandlerResult bus_socket_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
ac155bb8 130 Socket *s = SOCKET(u);
d200735e
MS
131 const BusBoundProperties bps[] = {
132 { "org.freedesktop.systemd1.Unit", bus_unit_properties, u },
133 { "org.freedesktop.systemd1.Socket", bus_socket_properties, s },
134 { "org.freedesktop.systemd1.Socket", bus_exec_context_properties, &s->exec_context },
135 { NULL, }
4139c1b2
LP
136 };
137
d200735e 138 return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, bps);
4139c1b2 139}