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