]>
Commit | Line | Data |
---|---|---|
a032b68d | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
663996b3 | 2 | |
db2df898 | 3 | #include "alloc-util.h" |
a10f5d05 | 4 | #include "bus-get-properties.h" |
14228c0d | 5 | #include "dbus-cgroup.h" |
db2df898 | 6 | #include "dbus-execute.h" |
1d42b86d | 7 | #include "dbus-kill.h" |
14228c0d | 8 | #include "dbus-socket.h" |
1d42b86d MB |
9 | #include "dbus-util.h" |
10 | #include "fd-util.h" | |
6e866b33 | 11 | #include "ip-protocol-list.h" |
1d42b86d MB |
12 | #include "parse-util.h" |
13 | #include "path-util.h" | |
db2df898 | 14 | #include "socket.h" |
46cdbd49 | 15 | #include "socket-netlink.h" |
1d42b86d | 16 | #include "socket-util.h" |
db2df898 MP |
17 | #include "string-util.h" |
18 | #include "unit.h" | |
60f067b4 JS |
19 | |
20 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, socket_result, SocketResult); | |
21 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_bind_ipv6_only, socket_address_bind_ipv6_only, SocketAddressBindIPv6Only); | |
b012e921 | 22 | static BUS_DEFINE_PROPERTY_GET(property_get_fdname, "s", Socket, socket_fdname); |
a032b68d | 23 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_timestamping, socket_timestamping, SocketTimestamping); |
60f067b4 JS |
24 | |
25 | static int property_get_listen( | |
26 | sd_bus *bus, | |
27 | const char *path, | |
28 | const char *interface, | |
29 | const char *property, | |
30 | sd_bus_message *reply, | |
31 | void *userdata, | |
32 | sd_bus_error *error) { | |
663996b3 | 33 | |
60f067b4 | 34 | Socket *s = SOCKET(userdata); |
663996b3 | 35 | SocketPort *p; |
60f067b4 | 36 | int r; |
663996b3 | 37 | |
60f067b4 JS |
38 | assert(bus); |
39 | assert(reply); | |
663996b3 MS |
40 | assert(s); |
41 | ||
60f067b4 JS |
42 | r = sd_bus_message_open_container(reply, 'a', "(ss)"); |
43 | if (r < 0) | |
44 | return r; | |
663996b3 MS |
45 | |
46 | LIST_FOREACH(port, p, s->ports) { | |
663996b3 MS |
47 | _cleanup_free_ char *address = NULL; |
48 | const char *a; | |
49 | ||
663996b3 MS |
50 | switch (p->type) { |
51 | case SOCKET_SOCKET: { | |
663996b3 | 52 | r = socket_address_print(&p->address, &address); |
60f067b4 | 53 | if (r) |
663996b3 | 54 | return r; |
60f067b4 | 55 | |
663996b3 MS |
56 | a = address; |
57 | break; | |
58 | } | |
59 | ||
60 | case SOCKET_SPECIAL: | |
61 | case SOCKET_MQUEUE: | |
62 | case SOCKET_FIFO: | |
6300502b | 63 | case SOCKET_USB_FUNCTION: |
663996b3 MS |
64 | a = p->path; |
65 | break; | |
66 | ||
67 | default: | |
60f067b4 | 68 | assert_not_reached("Unknown socket type"); |
663996b3 MS |
69 | } |
70 | ||
60f067b4 JS |
71 | r = sd_bus_message_append(reply, "(ss)", socket_port_type_to_string(p), a); |
72 | if (r < 0) | |
73 | return r; | |
663996b3 MS |
74 | } |
75 | ||
60f067b4 | 76 | return sd_bus_message_close_container(reply); |
663996b3 MS |
77 | } |
78 | ||
60f067b4 JS |
79 | const sd_bus_vtable bus_socket_vtable[] = { |
80 | SD_BUS_VTABLE_START(0), | |
81 | SD_BUS_PROPERTY("BindIPv6Only", "s", property_get_bind_ipv6_only, offsetof(Socket, bind_ipv6_only), SD_BUS_VTABLE_PROPERTY_CONST), | |
82 | SD_BUS_PROPERTY("Backlog", "u", bus_property_get_unsigned, offsetof(Socket, backlog), SD_BUS_VTABLE_PROPERTY_CONST), | |
83 | SD_BUS_PROPERTY("TimeoutUSec", "t", bus_property_get_usec, offsetof(Socket, timeout_usec), SD_BUS_VTABLE_PROPERTY_CONST), | |
84 | SD_BUS_PROPERTY("BindToDevice", "s", NULL, offsetof(Socket, bind_to_device), SD_BUS_VTABLE_PROPERTY_CONST), | |
85 | SD_BUS_PROPERTY("SocketUser", "s", NULL, offsetof(Socket, user), SD_BUS_VTABLE_PROPERTY_CONST), | |
86 | SD_BUS_PROPERTY("SocketGroup", "s", NULL, offsetof(Socket, group), SD_BUS_VTABLE_PROPERTY_CONST), | |
87 | SD_BUS_PROPERTY("SocketMode", "u", bus_property_get_mode, offsetof(Socket, socket_mode), SD_BUS_VTABLE_PROPERTY_CONST), | |
88 | SD_BUS_PROPERTY("DirectoryMode", "u", bus_property_get_mode, offsetof(Socket, directory_mode), SD_BUS_VTABLE_PROPERTY_CONST), | |
89 | SD_BUS_PROPERTY("Accept", "b", bus_property_get_bool, offsetof(Socket, accept), SD_BUS_VTABLE_PROPERTY_CONST), | |
a032b68d | 90 | SD_BUS_PROPERTY("FlushPending", "b", bus_property_get_bool, offsetof(Socket, flush_pending), SD_BUS_VTABLE_PROPERTY_CONST), |
6300502b | 91 | SD_BUS_PROPERTY("Writable", "b", bus_property_get_bool, offsetof(Socket, writable), SD_BUS_VTABLE_PROPERTY_CONST), |
60f067b4 | 92 | SD_BUS_PROPERTY("KeepAlive", "b", bus_property_get_bool, offsetof(Socket, keep_alive), SD_BUS_VTABLE_PROPERTY_CONST), |
5eef597e MP |
93 | SD_BUS_PROPERTY("KeepAliveTimeUSec", "t", bus_property_get_usec, offsetof(Socket, keep_alive_time), SD_BUS_VTABLE_PROPERTY_CONST), |
94 | SD_BUS_PROPERTY("KeepAliveIntervalUSec", "t", bus_property_get_usec, offsetof(Socket, keep_alive_interval), SD_BUS_VTABLE_PROPERTY_CONST), | |
95 | SD_BUS_PROPERTY("KeepAliveProbes", "u", bus_property_get_unsigned, offsetof(Socket, keep_alive_cnt), SD_BUS_VTABLE_PROPERTY_CONST), | |
96 | SD_BUS_PROPERTY("DeferAcceptUSec" , "t", bus_property_get_usec, offsetof(Socket, defer_accept), SD_BUS_VTABLE_PROPERTY_CONST), | |
97 | SD_BUS_PROPERTY("NoDelay", "b", bus_property_get_bool, offsetof(Socket, no_delay), SD_BUS_VTABLE_PROPERTY_CONST), | |
60f067b4 JS |
98 | SD_BUS_PROPERTY("Priority", "i", bus_property_get_int, offsetof(Socket, priority), SD_BUS_VTABLE_PROPERTY_CONST), |
99 | SD_BUS_PROPERTY("ReceiveBuffer", "t", bus_property_get_size, offsetof(Socket, receive_buffer), SD_BUS_VTABLE_PROPERTY_CONST), | |
100 | SD_BUS_PROPERTY("SendBuffer", "t", bus_property_get_size, offsetof(Socket, send_buffer), SD_BUS_VTABLE_PROPERTY_CONST), | |
101 | SD_BUS_PROPERTY("IPTOS", "i", bus_property_get_int, offsetof(Socket, ip_tos), SD_BUS_VTABLE_PROPERTY_CONST), | |
102 | SD_BUS_PROPERTY("IPTTL", "i", bus_property_get_int, offsetof(Socket, ip_ttl), SD_BUS_VTABLE_PROPERTY_CONST), | |
103 | SD_BUS_PROPERTY("PipeSize", "t", bus_property_get_size, offsetof(Socket, pipe_size), SD_BUS_VTABLE_PROPERTY_CONST), | |
104 | SD_BUS_PROPERTY("FreeBind", "b", bus_property_get_bool, offsetof(Socket, free_bind), SD_BUS_VTABLE_PROPERTY_CONST), | |
105 | SD_BUS_PROPERTY("Transparent", "b", bus_property_get_bool, offsetof(Socket, transparent), SD_BUS_VTABLE_PROPERTY_CONST), | |
106 | SD_BUS_PROPERTY("Broadcast", "b", bus_property_get_bool, offsetof(Socket, broadcast), SD_BUS_VTABLE_PROPERTY_CONST), | |
107 | SD_BUS_PROPERTY("PassCredentials", "b", bus_property_get_bool, offsetof(Socket, pass_cred), SD_BUS_VTABLE_PROPERTY_CONST), | |
108 | SD_BUS_PROPERTY("PassSecurity", "b", bus_property_get_bool, offsetof(Socket, pass_sec), SD_BUS_VTABLE_PROPERTY_CONST), | |
a10f5d05 | 109 | SD_BUS_PROPERTY("PassPacketInfo", "b", bus_property_get_bool, offsetof(Socket, pass_pktinfo), SD_BUS_VTABLE_PROPERTY_CONST), |
a032b68d | 110 | SD_BUS_PROPERTY("Timestamping", "s", property_get_timestamping, offsetof(Socket, timestamping), SD_BUS_VTABLE_PROPERTY_CONST), |
60f067b4 JS |
111 | SD_BUS_PROPERTY("RemoveOnStop", "b", bus_property_get_bool, offsetof(Socket, remove_on_stop), SD_BUS_VTABLE_PROPERTY_CONST), |
112 | SD_BUS_PROPERTY("Listen", "a(ss)", property_get_listen, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
113 | SD_BUS_PROPERTY("Symlinks", "as", NULL, offsetof(Socket, symlinks), SD_BUS_VTABLE_PROPERTY_CONST), | |
114 | SD_BUS_PROPERTY("Mark", "i", bus_property_get_int, offsetof(Socket, mark), SD_BUS_VTABLE_PROPERTY_CONST), | |
115 | SD_BUS_PROPERTY("MaxConnections", "u", bus_property_get_unsigned, offsetof(Socket, max_connections), SD_BUS_VTABLE_PROPERTY_CONST), | |
8a584da2 | 116 | SD_BUS_PROPERTY("MaxConnectionsPerSource", "u", bus_property_get_unsigned, offsetof(Socket, max_connections_per_source), SD_BUS_VTABLE_PROPERTY_CONST), |
60f067b4 JS |
117 | SD_BUS_PROPERTY("MessageQueueMaxMessages", "x", bus_property_get_long, offsetof(Socket, mq_maxmsg), SD_BUS_VTABLE_PROPERTY_CONST), |
118 | SD_BUS_PROPERTY("MessageQueueMessageSize", "x", bus_property_get_long, offsetof(Socket, mq_msgsize), SD_BUS_VTABLE_PROPERTY_CONST), | |
1d42b86d | 119 | SD_BUS_PROPERTY("TCPCongestion", "s", NULL, offsetof(Socket, tcp_congestion), SD_BUS_VTABLE_PROPERTY_CONST), |
60f067b4 JS |
120 | SD_BUS_PROPERTY("ReusePort", "b", bus_property_get_bool, offsetof(Socket, reuse_port), SD_BUS_VTABLE_PROPERTY_CONST), |
121 | SD_BUS_PROPERTY("SmackLabel", "s", NULL, offsetof(Socket, smack), SD_BUS_VTABLE_PROPERTY_CONST), | |
122 | SD_BUS_PROPERTY("SmackLabelIPIn", "s", NULL, offsetof(Socket, smack_ip_in), SD_BUS_VTABLE_PROPERTY_CONST), | |
123 | SD_BUS_PROPERTY("SmackLabelIPOut", "s", NULL, offsetof(Socket, smack_ip_out), SD_BUS_VTABLE_PROPERTY_CONST), | |
124 | SD_BUS_PROPERTY("ControlPID", "u", bus_property_get_pid, offsetof(Socket, control_pid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), | |
125 | SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Socket, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), | |
126 | SD_BUS_PROPERTY("NConnections", "u", bus_property_get_unsigned, offsetof(Socket, n_connections), 0), | |
127 | SD_BUS_PROPERTY("NAccepted", "u", bus_property_get_unsigned, offsetof(Socket, n_accepted), 0), | |
b012e921 | 128 | SD_BUS_PROPERTY("NRefused", "u", bus_property_get_unsigned, offsetof(Socket, n_refused), 0), |
6300502b | 129 | SD_BUS_PROPERTY("FileDescriptorName", "s", property_get_fdname, 0, 0), |
4c89c718 | 130 | SD_BUS_PROPERTY("SocketProtocol", "i", bus_property_get_int, offsetof(Socket, socket_protocol), SD_BUS_VTABLE_PROPERTY_CONST), |
aa27b158 MP |
131 | SD_BUS_PROPERTY("TriggerLimitIntervalUSec", "t", bus_property_get_usec, offsetof(Socket, trigger_limit.interval), SD_BUS_VTABLE_PROPERTY_CONST), |
132 | SD_BUS_PROPERTY("TriggerLimitBurst", "u", bus_property_get_unsigned, offsetof(Socket, trigger_limit.burst), SD_BUS_VTABLE_PROPERTY_CONST), | |
b012e921 MB |
133 | SD_BUS_PROPERTY("UID", "u", bus_property_get_uid, offsetof(Unit, ref_uid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
134 | SD_BUS_PROPERTY("GID", "u", bus_property_get_gid, offsetof(Unit, ref_gid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), | |
60f067b4 JS |
135 | BUS_EXEC_COMMAND_LIST_VTABLE("ExecStartPre", offsetof(Socket, exec_command[SOCKET_EXEC_START_PRE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
136 | BUS_EXEC_COMMAND_LIST_VTABLE("ExecStartPost", offsetof(Socket, exec_command[SOCKET_EXEC_START_POST]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), | |
137 | BUS_EXEC_COMMAND_LIST_VTABLE("ExecStopPre", offsetof(Socket, exec_command[SOCKET_EXEC_STOP_PRE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), | |
138 | BUS_EXEC_COMMAND_LIST_VTABLE("ExecStopPost", offsetof(Socket, exec_command[SOCKET_EXEC_STOP_POST]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), | |
139 | SD_BUS_VTABLE_END | |
663996b3 MS |
140 | }; |
141 | ||
7c20daf6 | 142 | static bool check_size_t_truncation(uint64_t t) { |
1d42b86d MB |
143 | return (size_t) t == t; |
144 | } | |
145 | ||
7c20daf6 | 146 | static const char* socket_protocol_to_string(int32_t i) { |
b012e921 MB |
147 | if (i == IPPROTO_IP) |
148 | return ""; | |
149 | ||
1d42b86d MB |
150 | if (!IN_SET(i, IPPROTO_UDPLITE, IPPROTO_SCTP)) |
151 | return NULL; | |
152 | ||
6e866b33 | 153 | return ip_protocol_to_name(i); |
1d42b86d MB |
154 | } |
155 | ||
156 | static BUS_DEFINE_SET_TRANSIENT(int, "i", int32_t, int, "%" PRIi32); | |
157 | static BUS_DEFINE_SET_TRANSIENT(message_queue, "x", int64_t, long, "%" PRIi64); | |
158 | static BUS_DEFINE_SET_TRANSIENT_IS_VALID(size_t_check_truncation, "t", uint64_t, size_t, "%" PRIu64, check_size_t_truncation); | |
b012e921 | 159 | static BUS_DEFINE_SET_TRANSIENT_PARSE(bind_ipv6_only, SocketAddressBindIPv6Only, socket_address_bind_ipv6_only_or_bool_from_string); |
1d42b86d MB |
160 | static BUS_DEFINE_SET_TRANSIENT_STRING_WITH_CHECK(fdname, fdname_is_valid); |
161 | static BUS_DEFINE_SET_TRANSIENT_STRING_WITH_CHECK(ifname, ifname_valid); | |
162 | static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(ip_tos, "i", int32_t, int, "%" PRIi32, ip_tos_to_string_alloc); | |
6e866b33 | 163 | static BUS_DEFINE_SET_TRANSIENT_TO_STRING(socket_protocol, "i", int32_t, int, "%" PRIi32, socket_protocol_to_string); |
a032b68d | 164 | static BUS_DEFINE_SET_TRANSIENT_PARSE(socket_timestamping, SocketTimestamping, socket_timestamping_from_string_harder); |
1d42b86d MB |
165 | |
166 | static int bus_socket_set_transient_property( | |
167 | Socket *s, | |
168 | const char *name, | |
169 | sd_bus_message *message, | |
170 | UnitWriteFlags flags, | |
171 | sd_bus_error *error) { | |
172 | ||
173 | SocketExecCommand ci; | |
174 | Unit *u = UNIT(s); | |
175 | int r; | |
176 | ||
177 | assert(s); | |
178 | assert(name); | |
179 | assert(message); | |
180 | ||
181 | flags |= UNIT_PRIVATE; | |
182 | ||
183 | if (streq(name, "Accept")) | |
184 | return bus_set_transient_bool(u, name, &s->accept, message, flags, error); | |
185 | ||
a032b68d MB |
186 | if (streq(name, "FlushPending")) |
187 | return bus_set_transient_bool(u, name, &s->flush_pending, message, flags, error); | |
188 | ||
1d42b86d MB |
189 | if (streq(name, "Writable")) |
190 | return bus_set_transient_bool(u, name, &s->writable, message, flags, error); | |
191 | ||
192 | if (streq(name, "KeepAlive")) | |
193 | return bus_set_transient_bool(u, name, &s->keep_alive, message, flags, error); | |
194 | ||
195 | if (streq(name, "NoDelay")) | |
196 | return bus_set_transient_bool(u, name, &s->no_delay, message, flags, error); | |
197 | ||
198 | if (streq(name, "FreeBind")) | |
199 | return bus_set_transient_bool(u, name, &s->free_bind, message, flags, error); | |
200 | ||
201 | if (streq(name, "Transparent")) | |
202 | return bus_set_transient_bool(u, name, &s->transparent, message, flags, error); | |
203 | ||
204 | if (streq(name, "Broadcast")) | |
205 | return bus_set_transient_bool(u, name, &s->broadcast, message, flags, error); | |
206 | ||
207 | if (streq(name, "PassCredentials")) | |
208 | return bus_set_transient_bool(u, name, &s->pass_cred, message, flags, error); | |
209 | ||
210 | if (streq(name, "PassSecurity")) | |
211 | return bus_set_transient_bool(u, name, &s->pass_sec, message, flags, error); | |
212 | ||
a10f5d05 MB |
213 | if (streq(name, "PassPacketInfo")) |
214 | return bus_set_transient_bool(u, name, &s->pass_pktinfo, message, flags, error); | |
215 | ||
a032b68d MB |
216 | if (streq(name, "Timestamping")) |
217 | return bus_set_transient_socket_timestamping(u, name, &s->timestamping, message, flags, error); | |
218 | ||
1d42b86d MB |
219 | if (streq(name, "ReusePort")) |
220 | return bus_set_transient_bool(u, name, &s->reuse_port, message, flags, error); | |
221 | ||
222 | if (streq(name, "RemoveOnStop")) | |
223 | return bus_set_transient_bool(u, name, &s->remove_on_stop, message, flags, error); | |
224 | ||
225 | if (streq(name, "SELinuxContextFromNet")) | |
226 | return bus_set_transient_bool(u, name, &s->selinux_context_from_net, message, flags, error); | |
227 | ||
228 | if (streq(name, "Priority")) | |
229 | return bus_set_transient_int(u, name, &s->priority, message, flags, error); | |
230 | ||
231 | if (streq(name, "IPTTL")) | |
232 | return bus_set_transient_int(u, name, &s->ip_ttl, message, flags, error); | |
233 | ||
234 | if (streq(name, "Mark")) | |
235 | return bus_set_transient_int(u, name, &s->mark, message, flags, error); | |
236 | ||
237 | if (streq(name, "Backlog")) | |
238 | return bus_set_transient_unsigned(u, name, &s->backlog, message, flags, error); | |
239 | ||
240 | if (streq(name, "MaxConnections")) | |
241 | return bus_set_transient_unsigned(u, name, &s->max_connections, message, flags, error); | |
242 | ||
243 | if (streq(name, "MaxConnectionsPerSource")) | |
244 | return bus_set_transient_unsigned(u, name, &s->max_connections_per_source, message, flags, error); | |
245 | ||
246 | if (streq(name, "KeepAliveProbes")) | |
247 | return bus_set_transient_unsigned(u, name, &s->keep_alive_cnt, message, flags, error); | |
248 | ||
249 | if (streq(name, "TriggerLimitBurst")) | |
250 | return bus_set_transient_unsigned(u, name, &s->trigger_limit.burst, message, flags, error); | |
251 | ||
252 | if (streq(name, "SocketMode")) | |
253 | return bus_set_transient_mode_t(u, name, &s->socket_mode, message, flags, error); | |
254 | ||
255 | if (streq(name, "DirectoryMode")) | |
256 | return bus_set_transient_mode_t(u, name, &s->directory_mode, message, flags, error); | |
257 | ||
258 | if (streq(name, "MessageQueueMaxMessages")) | |
259 | return bus_set_transient_message_queue(u, name, &s->mq_maxmsg, message, flags, error); | |
260 | ||
261 | if (streq(name, "MessageQueueMessageSize")) | |
262 | return bus_set_transient_message_queue(u, name, &s->mq_msgsize, message, flags, error); | |
263 | ||
264 | if (streq(name, "TimeoutUSec")) | |
265 | return bus_set_transient_usec_fix_0(u, name, &s->timeout_usec, message, flags, error); | |
266 | ||
267 | if (streq(name, "KeepAliveTimeUSec")) | |
268 | return bus_set_transient_usec(u, name, &s->keep_alive_time, message, flags, error); | |
269 | ||
270 | if (streq(name, "KeepAliveIntervalUSec")) | |
271 | return bus_set_transient_usec(u, name, &s->keep_alive_interval, message, flags, error); | |
272 | ||
273 | if (streq(name, "DeferAcceptUSec")) | |
274 | return bus_set_transient_usec(u, name, &s->defer_accept, message, flags, error); | |
275 | ||
276 | if (streq(name, "TriggerLimitIntervalUSec")) | |
277 | return bus_set_transient_usec(u, name, &s->trigger_limit.interval, message, flags, error); | |
278 | ||
279 | if (streq(name, "SmackLabel")) | |
280 | return bus_set_transient_string(u, name, &s->smack, message, flags, error); | |
281 | ||
282 | if (streq(name, "SmackLabelIPin")) | |
283 | return bus_set_transient_string(u, name, &s->smack_ip_in, message, flags, error); | |
284 | ||
285 | if (streq(name, "SmackLabelIPOut")) | |
286 | return bus_set_transient_string(u, name, &s->smack_ip_out, message, flags, error); | |
287 | ||
288 | if (streq(name, "TCPCongestion")) | |
289 | return bus_set_transient_string(u, name, &s->tcp_congestion, message, flags, error); | |
290 | ||
291 | if (streq(name, "FileDescriptorName")) | |
292 | return bus_set_transient_fdname(u, name, &s->fdname, message, flags, error); | |
293 | ||
294 | if (streq(name, "SocketUser")) | |
d0648cfe | 295 | return bus_set_transient_user_relaxed(u, name, &s->user, message, flags, error); |
1d42b86d MB |
296 | |
297 | if (streq(name, "SocketGroup")) | |
d0648cfe | 298 | return bus_set_transient_user_relaxed(u, name, &s->group, message, flags, error); |
1d42b86d MB |
299 | |
300 | if (streq(name, "BindIPv6Only")) | |
301 | return bus_set_transient_bind_ipv6_only(u, name, &s->bind_ipv6_only, message, flags, error); | |
302 | ||
303 | if (streq(name, "ReceiveBuffer")) | |
304 | return bus_set_transient_size_t_check_truncation(u, name, &s->receive_buffer, message, flags, error); | |
305 | ||
306 | if (streq(name, "SendBuffer")) | |
307 | return bus_set_transient_size_t_check_truncation(u, name, &s->send_buffer, message, flags, error); | |
308 | ||
309 | if (streq(name, "PipeSize")) | |
310 | return bus_set_transient_size_t_check_truncation(u, name, &s->pipe_size, message, flags, error); | |
311 | ||
312 | if (streq(name, "BindToDevice")) | |
313 | return bus_set_transient_ifname(u, name, &s->bind_to_device, message, flags, error); | |
314 | ||
315 | if (streq(name, "IPTOS")) | |
316 | return bus_set_transient_ip_tos(u, name, &s->ip_tos, message, flags, error); | |
317 | ||
318 | if (streq(name, "SocketProtocol")) | |
319 | return bus_set_transient_socket_protocol(u, name, &s->socket_protocol, message, flags, error); | |
320 | ||
f2dec872 BR |
321 | ci = socket_exec_command_from_string(name); |
322 | if (ci >= 0) | |
323 | return bus_set_transient_exec_command(u, name, | |
324 | &s->exec_command[ci], | |
325 | message, flags, error); | |
1d42b86d MB |
326 | |
327 | if (streq(name, "Symlinks")) { | |
328 | _cleanup_strv_free_ char **l = NULL; | |
329 | char **p; | |
330 | ||
331 | r = sd_bus_message_read_strv(message, &l); | |
332 | if (r < 0) | |
333 | return r; | |
334 | ||
335 | STRV_FOREACH(p, l) { | |
336 | if (!path_is_absolute(*p)) | |
337 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Symlink path is not absolute: %s", *p); | |
338 | } | |
339 | ||
340 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
341 | if (strv_isempty(l)) { | |
342 | s->symlinks = strv_free(s->symlinks); | |
343 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=", name); | |
344 | } else { | |
345 | _cleanup_free_ char *joined = NULL; | |
346 | ||
347 | r = strv_extend_strv(&s->symlinks, l, true); | |
348 | if (r < 0) | |
349 | return -ENOMEM; | |
350 | ||
351 | joined = strv_join(l, " "); | |
352 | if (!joined) | |
353 | return -ENOMEM; | |
354 | ||
355 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s", name, joined); | |
356 | } | |
357 | } | |
358 | ||
359 | return 1; | |
360 | ||
361 | } else if (streq(name, "Listen")) { | |
362 | const char *t, *a; | |
363 | bool empty = true; | |
364 | ||
365 | r = sd_bus_message_enter_container(message, 'a', "(ss)"); | |
366 | if (r < 0) | |
367 | return r; | |
368 | ||
369 | while ((r = sd_bus_message_read(message, "(ss)", &t, &a)) > 0) { | |
370 | _cleanup_free_ SocketPort *p = NULL; | |
371 | ||
6e866b33 | 372 | p = new(SocketPort, 1); |
1d42b86d MB |
373 | if (!p) |
374 | return log_oom(); | |
375 | ||
6e866b33 MB |
376 | *p = (SocketPort) { |
377 | .fd = -1, | |
378 | .socket = s, | |
379 | }; | |
380 | ||
1d42b86d MB |
381 | p->type = socket_port_type_from_string(t); |
382 | if (p->type < 0) | |
383 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown Socket type: %s", t); | |
384 | ||
385 | if (p->type != SOCKET_SOCKET) { | |
6e866b33 MB |
386 | if (!path_is_valid(p->path)) |
387 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid socket path: %s", t); | |
388 | ||
1d42b86d | 389 | p->path = strdup(a); |
6e866b33 MB |
390 | if (!p->path) |
391 | return log_oom(); | |
392 | ||
8b3d4ff0 | 393 | path_simplify(p->path); |
1d42b86d MB |
394 | |
395 | } else if (streq(t, "Netlink")) { | |
396 | r = socket_address_parse_netlink(&p->address, a); | |
397 | if (r < 0) | |
398 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid netlink address: %s", a); | |
399 | ||
400 | } else { | |
401 | r = socket_address_parse(&p->address, a); | |
402 | if (r < 0) | |
403 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid address: %s", a); | |
404 | ||
405 | p->address.type = socket_address_type_from_string(t); | |
406 | if (p->address.type < 0) | |
407 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid address type: %s", t); | |
408 | ||
409 | if (socket_address_family(&p->address) != AF_LOCAL && p->address.type == SOCK_SEQPACKET) | |
410 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Address family not supported: %s", a); | |
411 | } | |
412 | ||
1d42b86d MB |
413 | empty = false; |
414 | ||
415 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
6e866b33 | 416 | LIST_APPEND(port, s->ports, TAKE_PTR(p)); |
1d42b86d MB |
417 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "Listen%s=%s", t, a); |
418 | } | |
419 | } | |
420 | if (r < 0) | |
421 | return r; | |
422 | ||
423 | r = sd_bus_message_exit_container(message); | |
424 | if (r < 0) | |
425 | return r; | |
426 | ||
427 | if (!UNIT_WRITE_FLAGS_NOOP(flags) && empty) { | |
428 | socket_free_ports(s); | |
429 | unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "ListenStream="); | |
430 | } | |
431 | ||
432 | return 1; | |
433 | } | |
434 | ||
435 | return 0; | |
436 | } | |
437 | ||
14228c0d MB |
438 | int bus_socket_set_property( |
439 | Unit *u, | |
440 | const char *name, | |
60f067b4 | 441 | sd_bus_message *message, |
52ad194e | 442 | UnitWriteFlags flags, |
60f067b4 | 443 | sd_bus_error *error) { |
14228c0d MB |
444 | |
445 | Socket *s = SOCKET(u); | |
1d42b86d | 446 | int r; |
14228c0d | 447 | |
60f067b4 | 448 | assert(s); |
14228c0d | 449 | assert(name); |
60f067b4 | 450 | assert(message); |
14228c0d | 451 | |
1d42b86d MB |
452 | assert(s); |
453 | assert(name); | |
454 | assert(message); | |
455 | ||
456 | r = bus_cgroup_set_property(u, &s->cgroup_context, name, message, flags, error); | |
457 | if (r != 0) | |
458 | return r; | |
459 | ||
460 | if (u->transient && u->load_state == UNIT_STUB) { | |
461 | /* This is a transient unit, let's load a little more */ | |
462 | ||
463 | r = bus_socket_set_transient_property(s, name, message, flags, error); | |
464 | if (r != 0) | |
465 | return r; | |
466 | ||
467 | r = bus_exec_context_set_transient_property(u, &s->exec_context, name, message, flags, error); | |
468 | if (r != 0) | |
469 | return r; | |
470 | ||
471 | r = bus_kill_context_set_transient_property(u, &s->kill_context, name, message, flags, error); | |
472 | if (r != 0) | |
473 | return r; | |
474 | } | |
475 | ||
476 | return 0; | |
14228c0d MB |
477 | } |
478 | ||
479 | int bus_socket_commit_properties(Unit *u) { | |
480 | assert(u); | |
481 | ||
482 | unit_realize_cgroup(u); | |
60f067b4 | 483 | |
14228c0d MB |
484 | return 0; |
485 | } |