]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
4139c1b2 LP |
2 | /*** |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright 2010 Lennart Poettering | |
4139c1b2 LP |
6 | ***/ |
7 | ||
b5efdb8a | 8 | #include "alloc-util.h" |
07630cea | 9 | #include "bus-util.h" |
4ad49000 | 10 | #include "dbus-cgroup.h" |
07630cea | 11 | #include "dbus-execute.h" |
9c0320e7 | 12 | #include "dbus-kill.h" |
b5efdb8a | 13 | #include "dbus-socket.h" |
8c3fd5eb | 14 | #include "dbus-util.h" |
9c0320e7 YW |
15 | #include "fd-util.h" |
16 | #include "parse-util.h" | |
17 | #include "path-util.h" | |
07630cea | 18 | #include "socket.h" |
e045e325 | 19 | #include "socket-protocol-list.h" |
9c0320e7 | 20 | #include "socket-util.h" |
07630cea LP |
21 | #include "string-util.h" |
22 | #include "unit.h" | |
718db961 LP |
23 | |
24 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, socket_result, SocketResult); | |
25 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_bind_ipv6_only, socket_address_bind_ipv6_only, SocketAddressBindIPv6Only); | |
26 | ||
27 | static int property_get_listen( | |
28 | sd_bus *bus, | |
29 | const char *path, | |
30 | const char *interface, | |
31 | const char *property, | |
32 | sd_bus_message *reply, | |
ebcf1f97 LP |
33 | void *userdata, |
34 | sd_bus_error *error) { | |
4139c1b2 | 35 | |
718db961 | 36 | Socket *s = SOCKET(userdata); |
67419600 | 37 | SocketPort *p; |
718db961 | 38 | int r; |
67419600 | 39 | |
718db961 LP |
40 | assert(bus); |
41 | assert(reply); | |
67419600 OS |
42 | assert(s); |
43 | ||
718db961 LP |
44 | r = sd_bus_message_open_container(reply, 'a', "(ss)"); |
45 | if (r < 0) | |
46 | return r; | |
67419600 OS |
47 | |
48 | LIST_FOREACH(port, p, s->ports) { | |
7fd1b19b | 49 | _cleanup_free_ char *address = NULL; |
67419600 OS |
50 | const char *a; |
51 | ||
67419600 OS |
52 | switch (p->type) { |
53 | case SOCKET_SOCKET: { | |
67419600 | 54 | r = socket_address_print(&p->address, &address); |
718db961 | 55 | if (r) |
67419600 | 56 | return r; |
718db961 | 57 | |
67419600 OS |
58 | a = address; |
59 | break; | |
60 | } | |
61 | ||
62 | case SOCKET_SPECIAL: | |
63 | case SOCKET_MQUEUE: | |
64 | case SOCKET_FIFO: | |
60252446 | 65 | case SOCKET_USB_FUNCTION: |
67419600 OS |
66 | a = p->path; |
67 | break; | |
68 | ||
69 | default: | |
718db961 | 70 | assert_not_reached("Unknown socket type"); |
67419600 OS |
71 | } |
72 | ||
718db961 LP |
73 | r = sd_bus_message_append(reply, "(ss)", socket_port_type_to_string(p), a); |
74 | if (r < 0) | |
75 | return r; | |
67419600 OS |
76 | } |
77 | ||
718db961 | 78 | return sd_bus_message_close_container(reply); |
67419600 OS |
79 | } |
80 | ||
8dd4c05b LP |
81 | static int property_get_fdname( |
82 | sd_bus *bus, | |
83 | const char *path, | |
84 | const char *interface, | |
85 | const char *property, | |
86 | sd_bus_message *reply, | |
87 | void *userdata, | |
88 | sd_bus_error *error) { | |
89 | ||
90 | Socket *s = SOCKET(userdata); | |
91 | ||
92 | assert(bus); | |
93 | assert(reply); | |
94 | assert(s); | |
95 | ||
96 | return sd_bus_message_append(reply, "s", socket_fdname(s)); | |
97 | } | |
98 | ||
718db961 LP |
99 | const sd_bus_vtable bus_socket_vtable[] = { |
100 | SD_BUS_VTABLE_START(0), | |
556089dc LP |
101 | SD_BUS_PROPERTY("BindIPv6Only", "s", property_get_bind_ipv6_only, offsetof(Socket, bind_ipv6_only), SD_BUS_VTABLE_PROPERTY_CONST), |
102 | SD_BUS_PROPERTY("Backlog", "u", bus_property_get_unsigned, offsetof(Socket, backlog), SD_BUS_VTABLE_PROPERTY_CONST), | |
103 | SD_BUS_PROPERTY("TimeoutUSec", "t", bus_property_get_usec, offsetof(Socket, timeout_usec), SD_BUS_VTABLE_PROPERTY_CONST), | |
556089dc | 104 | SD_BUS_PROPERTY("BindToDevice", "s", NULL, offsetof(Socket, bind_to_device), SD_BUS_VTABLE_PROPERTY_CONST), |
3900e5fd LP |
105 | SD_BUS_PROPERTY("SocketUser", "s", NULL, offsetof(Socket, user), SD_BUS_VTABLE_PROPERTY_CONST), |
106 | SD_BUS_PROPERTY("SocketGroup", "s", NULL, offsetof(Socket, group), SD_BUS_VTABLE_PROPERTY_CONST), | |
556089dc | 107 | SD_BUS_PROPERTY("SocketMode", "u", bus_property_get_mode, offsetof(Socket, socket_mode), SD_BUS_VTABLE_PROPERTY_CONST), |
3900e5fd | 108 | SD_BUS_PROPERTY("DirectoryMode", "u", bus_property_get_mode, offsetof(Socket, directory_mode), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 109 | SD_BUS_PROPERTY("Accept", "b", bus_property_get_bool, offsetof(Socket, accept), SD_BUS_VTABLE_PROPERTY_CONST), |
55301ec0 | 110 | SD_BUS_PROPERTY("Writable", "b", bus_property_get_bool, offsetof(Socket, writable), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 111 | SD_BUS_PROPERTY("KeepAlive", "b", bus_property_get_bool, offsetof(Socket, keep_alive), SD_BUS_VTABLE_PROPERTY_CONST), |
3cd761e4 LP |
112 | SD_BUS_PROPERTY("KeepAliveTimeUSec", "t", bus_property_get_usec, offsetof(Socket, keep_alive_time), SD_BUS_VTABLE_PROPERTY_CONST), |
113 | SD_BUS_PROPERTY("KeepAliveIntervalUSec", "t", bus_property_get_usec, offsetof(Socket, keep_alive_interval), SD_BUS_VTABLE_PROPERTY_CONST), | |
209e9dcd | 114 | SD_BUS_PROPERTY("KeepAliveProbes", "u", bus_property_get_unsigned, offsetof(Socket, keep_alive_cnt), SD_BUS_VTABLE_PROPERTY_CONST), |
3cd761e4 | 115 | SD_BUS_PROPERTY("DeferAcceptUSec" , "t", bus_property_get_usec, offsetof(Socket, defer_accept), SD_BUS_VTABLE_PROPERTY_CONST), |
fd062cd4 | 116 | SD_BUS_PROPERTY("NoDelay", "b", bus_property_get_bool, offsetof(Socket, no_delay), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc LP |
117 | SD_BUS_PROPERTY("Priority", "i", bus_property_get_int, offsetof(Socket, priority), SD_BUS_VTABLE_PROPERTY_CONST), |
118 | SD_BUS_PROPERTY("ReceiveBuffer", "t", bus_property_get_size, offsetof(Socket, receive_buffer), SD_BUS_VTABLE_PROPERTY_CONST), | |
119 | SD_BUS_PROPERTY("SendBuffer", "t", bus_property_get_size, offsetof(Socket, send_buffer), SD_BUS_VTABLE_PROPERTY_CONST), | |
120 | SD_BUS_PROPERTY("IPTOS", "i", bus_property_get_int, offsetof(Socket, ip_tos), SD_BUS_VTABLE_PROPERTY_CONST), | |
121 | SD_BUS_PROPERTY("IPTTL", "i", bus_property_get_int, offsetof(Socket, ip_ttl), SD_BUS_VTABLE_PROPERTY_CONST), | |
122 | SD_BUS_PROPERTY("PipeSize", "t", bus_property_get_size, offsetof(Socket, pipe_size), SD_BUS_VTABLE_PROPERTY_CONST), | |
123 | SD_BUS_PROPERTY("FreeBind", "b", bus_property_get_bool, offsetof(Socket, free_bind), SD_BUS_VTABLE_PROPERTY_CONST), | |
124 | SD_BUS_PROPERTY("Transparent", "b", bus_property_get_bool, offsetof(Socket, transparent), SD_BUS_VTABLE_PROPERTY_CONST), | |
125 | SD_BUS_PROPERTY("Broadcast", "b", bus_property_get_bool, offsetof(Socket, broadcast), SD_BUS_VTABLE_PROPERTY_CONST), | |
126 | SD_BUS_PROPERTY("PassCredentials", "b", bus_property_get_bool, offsetof(Socket, pass_cred), SD_BUS_VTABLE_PROPERTY_CONST), | |
127 | SD_BUS_PROPERTY("PassSecurity", "b", bus_property_get_bool, offsetof(Socket, pass_sec), SD_BUS_VTABLE_PROPERTY_CONST), | |
bd1fe7c7 | 128 | SD_BUS_PROPERTY("RemoveOnStop", "b", bus_property_get_bool, offsetof(Socket, remove_on_stop), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc | 129 | SD_BUS_PROPERTY("Listen", "a(ss)", property_get_listen, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
811ba7a0 | 130 | SD_BUS_PROPERTY("Symlinks", "as", NULL, offsetof(Socket, symlinks), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc LP |
131 | SD_BUS_PROPERTY("Mark", "i", bus_property_get_int, offsetof(Socket, mark), SD_BUS_VTABLE_PROPERTY_CONST), |
132 | SD_BUS_PROPERTY("MaxConnections", "u", bus_property_get_unsigned, offsetof(Socket, max_connections), SD_BUS_VTABLE_PROPERTY_CONST), | |
9d565427 | 133 | SD_BUS_PROPERTY("MaxConnectionsPerSource", "u", bus_property_get_unsigned, offsetof(Socket, max_connections_per_source), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc LP |
134 | SD_BUS_PROPERTY("MessageQueueMaxMessages", "x", bus_property_get_long, offsetof(Socket, mq_maxmsg), SD_BUS_VTABLE_PROPERTY_CONST), |
135 | SD_BUS_PROPERTY("MessageQueueMessageSize", "x", bus_property_get_long, offsetof(Socket, mq_msgsize), SD_BUS_VTABLE_PROPERTY_CONST), | |
9c0320e7 | 136 | SD_BUS_PROPERTY("TCPCongestion", "s", NULL, offsetof(Socket, tcp_congestion), SD_BUS_VTABLE_PROPERTY_CONST), |
556089dc LP |
137 | SD_BUS_PROPERTY("ReusePort", "b", bus_property_get_bool, offsetof(Socket, reuse_port), SD_BUS_VTABLE_PROPERTY_CONST), |
138 | SD_BUS_PROPERTY("SmackLabel", "s", NULL, offsetof(Socket, smack), SD_BUS_VTABLE_PROPERTY_CONST), | |
139 | SD_BUS_PROPERTY("SmackLabelIPIn", "s", NULL, offsetof(Socket, smack_ip_in), SD_BUS_VTABLE_PROPERTY_CONST), | |
140 | SD_BUS_PROPERTY("SmackLabelIPOut", "s", NULL, offsetof(Socket, smack_ip_out), SD_BUS_VTABLE_PROPERTY_CONST), | |
aec8de63 LP |
141 | SD_BUS_PROPERTY("ControlPID", "u", bus_property_get_pid, offsetof(Socket, control_pid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
142 | SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Socket, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), | |
143 | SD_BUS_PROPERTY("NConnections", "u", bus_property_get_unsigned, offsetof(Socket, n_connections), 0), | |
144 | SD_BUS_PROPERTY("NAccepted", "u", bus_property_get_unsigned, offsetof(Socket, n_accepted), 0), | |
8dd4c05b | 145 | SD_BUS_PROPERTY("FileDescriptorName", "s", property_get_fdname, 0, 0), |
faf1cc93 | 146 | SD_BUS_PROPERTY("SocketProtocol", "i", bus_property_get_int, offsetof(Socket, socket_protocol), SD_BUS_VTABLE_PROPERTY_CONST), |
5d105c4a | 147 | SD_BUS_PROPERTY("TriggerLimitIntervalUSec", "t", bus_property_get_usec, offsetof(Socket, trigger_limit.interval), SD_BUS_VTABLE_PROPERTY_CONST), |
8b26cdbd | 148 | SD_BUS_PROPERTY("TriggerLimitBurst", "u", bus_property_get_unsigned, offsetof(Socket, trigger_limit.burst), SD_BUS_VTABLE_PROPERTY_CONST), |
05156503 YW |
149 | SD_BUS_PROPERTY("UID", "u", bus_property_get_uid, offsetof(Unit, ref_uid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
150 | SD_BUS_PROPERTY("GID", "u", bus_property_get_gid, offsetof(Unit, ref_gid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), | |
556089dc LP |
151 | BUS_EXEC_COMMAND_LIST_VTABLE("ExecStartPre", offsetof(Socket, exec_command[SOCKET_EXEC_START_PRE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), |
152 | BUS_EXEC_COMMAND_LIST_VTABLE("ExecStartPost", offsetof(Socket, exec_command[SOCKET_EXEC_START_POST]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), | |
153 | BUS_EXEC_COMMAND_LIST_VTABLE("ExecStopPre", offsetof(Socket, exec_command[SOCKET_EXEC_STOP_PRE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), | |
154 | BUS_EXEC_COMMAND_LIST_VTABLE("ExecStopPost", offsetof(Socket, exec_command[SOCKET_EXEC_STOP_POST]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION), | |
718db961 | 155 | SD_BUS_VTABLE_END |
d200735e MS |
156 | }; |
157 | ||
8c3fd5eb YW |
158 | static inline bool check_size_t_truncation(uint64_t t) { |
159 | return (size_t) t == t; | |
160 | } | |
161 | ||
162 | static inline const char* socket_protocol_to_name_supported(int32_t i) { | |
163 | if (!IN_SET(i, IPPROTO_UDPLITE, IPPROTO_SCTP)) | |
164 | return NULL; | |
165 | ||
166 | return socket_protocol_to_name(i); | |
167 | } | |
168 | ||
169 | static BUS_DEFINE_SET_TRANSIENT(int, "i", int32_t, int, "%" PRIi32); | |
170 | static BUS_DEFINE_SET_TRANSIENT(message_queue, "x", int64_t, long, "%" PRIi64); | |
171 | static BUS_DEFINE_SET_TRANSIENT_IS_VALID(size_t_check_truncation, "t", uint64_t, size_t, "%" PRIu64, check_size_t_truncation); | |
172 | static BUS_DEFINE_SET_TRANSIENT_PARSE(bind_ipv6_only, SocketAddressBindIPv6Only, parse_socket_address_bind_ipv6_only_or_bool); | |
173 | static BUS_DEFINE_SET_TRANSIENT_STRING_WITH_CHECK(fdname, fdname_is_valid); | |
174 | static BUS_DEFINE_SET_TRANSIENT_STRING_WITH_CHECK(ifname, ifname_valid); | |
175 | static BUS_DEFINE_SET_TRANSIENT_TO_STRING_ALLOC(ip_tos, "i", int32_t, int, "%" PRIi32, ip_tos_to_string_alloc); | |
176 | static BUS_DEFINE_SET_TRANSIENT_TO_STRING(socket_protocol, "i", int32_t, int, "%" PRIi32, socket_protocol_to_name_supported); | |
177 | ||
9c0320e7 YW |
178 | static int bus_socket_set_transient_property( |
179 | Socket *s, | |
180 | const char *name, | |
181 | sd_bus_message *message, | |
182 | UnitWriteFlags flags, | |
183 | sd_bus_error *error) { | |
184 | ||
185 | SocketExecCommand ci; | |
186 | Unit *u = UNIT(s); | |
187 | int r; | |
188 | ||
189 | assert(s); | |
190 | assert(name); | |
191 | assert(message); | |
192 | ||
193 | flags |= UNIT_PRIVATE; | |
194 | ||
8c3fd5eb YW |
195 | if (streq(name, "Accept")) |
196 | return bus_set_transient_bool(u, name, &s->accept, message, flags, error); | |
9c0320e7 | 197 | |
8c3fd5eb YW |
198 | if (streq(name, "Writable")) |
199 | return bus_set_transient_bool(u, name, &s->writable, message, flags, error); | |
9c0320e7 | 200 | |
8c3fd5eb YW |
201 | if (streq(name, "KeepAlive")) |
202 | return bus_set_transient_bool(u, name, &s->keep_alive, message, flags, error); | |
9c0320e7 | 203 | |
8c3fd5eb YW |
204 | if (streq(name, "NoDelay")) |
205 | return bus_set_transient_bool(u, name, &s->no_delay, message, flags, error); | |
9c0320e7 | 206 | |
8c3fd5eb YW |
207 | if (streq(name, "FreeBind")) |
208 | return bus_set_transient_bool(u, name, &s->free_bind, message, flags, error); | |
9c0320e7 | 209 | |
8c3fd5eb YW |
210 | if (streq(name, "Transparent")) |
211 | return bus_set_transient_bool(u, name, &s->transparent, message, flags, error); | |
9c0320e7 | 212 | |
8c3fd5eb YW |
213 | if (streq(name, "Broadcast")) |
214 | return bus_set_transient_bool(u, name, &s->broadcast, message, flags, error); | |
9c0320e7 | 215 | |
8c3fd5eb YW |
216 | if (streq(name, "PassCredentials")) |
217 | return bus_set_transient_bool(u, name, &s->pass_cred, message, flags, error); | |
9c0320e7 | 218 | |
8c3fd5eb YW |
219 | if (streq(name, "PassSecurity")) |
220 | return bus_set_transient_bool(u, name, &s->pass_sec, message, flags, error); | |
9c0320e7 | 221 | |
8c3fd5eb YW |
222 | if (streq(name, "ReusePort")) |
223 | return bus_set_transient_bool(u, name, &s->reuse_port, message, flags, error); | |
9c0320e7 | 224 | |
8c3fd5eb YW |
225 | if (streq(name, "RemoveOnStop")) |
226 | return bus_set_transient_bool(u, name, &s->remove_on_stop, message, flags, error); | |
9c0320e7 | 227 | |
8c3fd5eb YW |
228 | if (streq(name, "SELinuxContextFromNet")) |
229 | return bus_set_transient_bool(u, name, &s->selinux_context_from_net, message, flags, error); | |
9c0320e7 | 230 | |
8c3fd5eb YW |
231 | if (streq(name, "Priority")) |
232 | return bus_set_transient_int(u, name, &s->priority, message, flags, error); | |
9c0320e7 | 233 | |
8c3fd5eb YW |
234 | if (streq(name, "IPTTL")) |
235 | return bus_set_transient_int(u, name, &s->ip_ttl, message, flags, error); | |
9c0320e7 | 236 | |
8c3fd5eb YW |
237 | if (streq(name, "Mark")) |
238 | return bus_set_transient_int(u, name, &s->mark, message, flags, error); | |
9c0320e7 | 239 | |
8c3fd5eb YW |
240 | if (streq(name, "Backlog")) |
241 | return bus_set_transient_unsigned(u, name, &s->backlog, message, flags, error); | |
9c0320e7 | 242 | |
8c3fd5eb YW |
243 | if (streq(name, "MaxConnections")) |
244 | return bus_set_transient_unsigned(u, name, &s->max_connections, message, flags, error); | |
e045e325 | 245 | |
8c3fd5eb YW |
246 | if (streq(name, "MaxConnectionsPerSource")) |
247 | return bus_set_transient_unsigned(u, name, &s->max_connections_per_source, message, flags, error); | |
9c0320e7 | 248 | |
8c3fd5eb YW |
249 | if (streq(name, "KeepAliveProbes")) |
250 | return bus_set_transient_unsigned(u, name, &s->keep_alive_cnt, message, flags, error); | |
9c0320e7 | 251 | |
8c3fd5eb YW |
252 | if (streq(name, "TriggerLimitBurst")) |
253 | return bus_set_transient_unsigned(u, name, &s->trigger_limit.burst, message, flags, error); | |
9c0320e7 | 254 | |
8c3fd5eb YW |
255 | if (streq(name, "SocketMode")) |
256 | return bus_set_transient_mode_t(u, name, &s->socket_mode, message, flags, error); | |
9c0320e7 | 257 | |
8c3fd5eb YW |
258 | if (streq(name, "DirectoryMode")) |
259 | return bus_set_transient_mode_t(u, name, &s->directory_mode, message, flags, error); | |
9c0320e7 | 260 | |
8c3fd5eb YW |
261 | if (streq(name, "MessageQueueMaxMessages")) |
262 | return bus_set_transient_message_queue(u, name, &s->mq_maxmsg, message, flags, error); | |
9c0320e7 | 263 | |
8c3fd5eb YW |
264 | if (streq(name, "MessageQueueMessageSize")) |
265 | return bus_set_transient_message_queue(u, name, &s->mq_msgsize, message, flags, error); | |
9c0320e7 | 266 | |
8c3fd5eb YW |
267 | if (streq(name, "TimeoutUSec")) |
268 | return bus_set_transient_usec_fix_0(u, name, &s->timeout_usec, message, flags, error); | |
9c0320e7 | 269 | |
8c3fd5eb YW |
270 | if (streq(name, "KeepAliveTimeUSec")) |
271 | return bus_set_transient_usec(u, name, &s->keep_alive_time, message, flags, error); | |
9c0320e7 | 272 | |
8c3fd5eb YW |
273 | if (streq(name, "KeepAliveIntervalUSec")) |
274 | return bus_set_transient_usec(u, name, &s->keep_alive_interval, message, flags, error); | |
9c0320e7 | 275 | |
8c3fd5eb YW |
276 | if (streq(name, "DeferAcceptUSec")) |
277 | return bus_set_transient_usec(u, name, &s->defer_accept, message, flags, error); | |
9c0320e7 | 278 | |
8c3fd5eb YW |
279 | if (streq(name, "TriggerLimitIntervalUSec")) |
280 | return bus_set_transient_usec(u, name, &s->trigger_limit.interval, message, flags, error); | |
9c0320e7 | 281 | |
8c3fd5eb YW |
282 | if (streq(name, "SmackLabel")) |
283 | return bus_set_transient_string(u, name, &s->smack, message, flags, error); | |
9c0320e7 | 284 | |
8c3fd5eb YW |
285 | if (streq(name, "SmackLabelIPin")) |
286 | return bus_set_transient_string(u, name, &s->smack_ip_in, message, flags, error); | |
9c0320e7 | 287 | |
8c3fd5eb YW |
288 | if (streq(name, "SmackLabelIPOut")) |
289 | return bus_set_transient_string(u, name, &s->smack_ip_out, message, flags, error); | |
9c0320e7 | 290 | |
8c3fd5eb YW |
291 | if (streq(name, "TCPCongestion")) |
292 | return bus_set_transient_string(u, name, &s->tcp_congestion, message, flags, error); | |
9c0320e7 | 293 | |
8c3fd5eb YW |
294 | if (streq(name, "FileDescriptorName")) |
295 | return bus_set_transient_fdname(u, name, &s->fdname, message, flags, error); | |
9c0320e7 | 296 | |
8c3fd5eb YW |
297 | if (streq(name, "SocketUser")) |
298 | return bus_set_transient_user(u, name, &s->user, message, flags, error); | |
9c0320e7 | 299 | |
8c3fd5eb YW |
300 | if (streq(name, "SocketGroup")) |
301 | return bus_set_transient_user(u, name, &s->group, message, flags, error); | |
9c0320e7 | 302 | |
8c3fd5eb YW |
303 | if (streq(name, "BindIPv6Only")) |
304 | return bus_set_transient_bind_ipv6_only(u, name, &s->bind_ipv6_only, message, flags, error); | |
9c0320e7 | 305 | |
8c3fd5eb YW |
306 | if (streq(name, "ReceiveBuffer")) |
307 | return bus_set_transient_size_t_check_truncation(u, name, &s->receive_buffer, message, flags, error); | |
9c0320e7 | 308 | |
8c3fd5eb YW |
309 | if (streq(name, "SendBuffer")) |
310 | return bus_set_transient_size_t_check_truncation(u, name, &s->send_buffer, message, flags, error); | |
9c0320e7 | 311 | |
8c3fd5eb YW |
312 | if (streq(name, "PipeSize")) |
313 | return bus_set_transient_size_t_check_truncation(u, name, &s->pipe_size, message, flags, error); | |
b48e508d | 314 | |
8c3fd5eb YW |
315 | if (streq(name, "BindToDevice")) |
316 | return bus_set_transient_ifname(u, name, &s->bind_to_device, message, flags, error); | |
9c0320e7 | 317 | |
8c3fd5eb YW |
318 | if (streq(name, "IPTOS")) |
319 | return bus_set_transient_ip_tos(u, name, &s->ip_tos, message, flags, error); | |
9c0320e7 | 320 | |
8c3fd5eb YW |
321 | if (streq(name, "SocketProtocol")) |
322 | return bus_set_transient_socket_protocol(u, name, &s->socket_protocol, message, flags, error); | |
9c0320e7 | 323 | |
8c3fd5eb YW |
324 | if ((ci = socket_exec_command_from_string(name)) >= 0) |
325 | return bus_set_transient_exec_command(u, name, &s->exec_command[ci], message, flags, error); | |
9c0320e7 | 326 | |
8c3fd5eb | 327 | if (streq(name, "Symlinks")) { |
9c0320e7 YW |
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) { | |
9c0320e7 YW |
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 | ||
372 | p = new0(SocketPort, 1); | |
373 | if (!p) | |
374 | return log_oom(); | |
375 | ||
e045e325 | 376 | p->type = socket_port_type_from_string(t); |
9c0320e7 YW |
377 | if (p->type < 0) |
378 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown Socket type: %s", t); | |
379 | ||
380 | if (p->type != SOCKET_SOCKET) { | |
381 | p->path = strdup(a); | |
382 | path_kill_slashes(p->path); | |
383 | ||
384 | } else if (streq(t, "Netlink")) { | |
385 | r = socket_address_parse_netlink(&p->address, a); | |
386 | if (r < 0) | |
387 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid netlink address: %s", a); | |
388 | ||
389 | } else { | |
390 | r = socket_address_parse(&p->address, a); | |
391 | if (r < 0) | |
392 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid address: %s", a); | |
393 | ||
394 | p->address.type = socket_address_type_from_string(t); | |
395 | if (p->address.type < 0) | |
396 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid address type: %s", t); | |
397 | ||
398 | if (socket_address_family(&p->address) != AF_LOCAL && p->address.type == SOCK_SEQPACKET) | |
399 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Address family not supported: %s", a); | |
400 | } | |
401 | ||
402 | p->fd = -1; | |
403 | p->auxiliary_fds = NULL; | |
404 | p->n_auxiliary_fds = 0; | |
405 | p->socket = s; | |
406 | ||
407 | empty = false; | |
408 | ||
409 | if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | |
410 | SocketPort *tail; | |
411 | ||
412 | LIST_FIND_TAIL(port, s->ports, tail); | |
413 | LIST_INSERT_AFTER(port, s->ports, tail, p); | |
414 | ||
415 | p = NULL; | |
416 | ||
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; | |
8c3fd5eb | 433 | } |
9c0320e7 YW |
434 | |
435 | return 0; | |
436 | } | |
437 | ||
74c964d3 LP |
438 | int bus_socket_set_property( |
439 | Unit *u, | |
440 | const char *name, | |
718db961 | 441 | sd_bus_message *message, |
2e59b241 | 442 | UnitWriteFlags flags, |
718db961 | 443 | sd_bus_error *error) { |
74c964d3 LP |
444 | |
445 | Socket *s = SOCKET(u); | |
9c0320e7 YW |
446 | int r; |
447 | ||
448 | assert(s); | |
449 | assert(name); | |
450 | assert(message); | |
74c964d3 | 451 | |
718db961 | 452 | assert(s); |
74c964d3 | 453 | assert(name); |
718db961 | 454 | assert(message); |
74c964d3 | 455 | |
9c0320e7 YW |
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; | |
74c964d3 LP |
477 | } |
478 | ||
479 | int bus_socket_commit_properties(Unit *u) { | |
480 | assert(u); | |
481 | ||
bc432dc7 | 482 | unit_update_cgroup_members_masks(u); |
74c964d3 | 483 | unit_realize_cgroup(u); |
bc432dc7 | 484 | |
74c964d3 LP |
485 | return 0; |
486 | } |