]>
| Commit | Line | Data |
|---|---|---|
| db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 1ee306e1 | 2 | |
| 1ee306e1 | 3 | #include <unistd.h> |
| 1ee306e1 | 4 | |
| 64943cac | 5 | #include "sd-bus.h" |
| c3350683 | 6 | #include "sd-id128.h" |
| 3ffd4af2 | 7 | |
| b5efdb8a | 8 | #include "alloc-util.h" |
| 3ffd4af2 | 9 | #include "btrfs-util.h" |
| 96aad8d1 | 10 | #include "bus-common-errors.h" |
| 40af3d02 | 11 | #include "bus-get-properties.h" |
| 9b71e4ab | 12 | #include "bus-locator.h" |
| ab33edb0 | 13 | #include "bus-message-util.h" |
| 64943cac | 14 | #include "bus-object.h" |
| 269e4d2d | 15 | #include "bus-polkit.h" |
| ff43267c | 16 | #include "bus-util.h" |
| 23c80348 | 17 | #include "cgroup-util.h" |
| 57f1b61b | 18 | #include "discover-image.h" |
| 66855de7 | 19 | #include "errno-util.h" |
| 3ffd4af2 | 20 | #include "fd-util.h" |
| 03c2b288 | 21 | #include "fileio.h" |
| f97b34a6 | 22 | #include "format-util.h" |
| 64943cac | 23 | #include "hashmap.h" |
| 25300b5a | 24 | #include "hostname-util.h" |
| 5a99c9d7 | 25 | #include "image.h" |
| 3ffd4af2 | 26 | #include "image-dbus.h" |
| a90fb858 | 27 | #include "io-util.h" |
| 1cf40697 | 28 | #include "machine.h" |
| 3ffd4af2 | 29 | #include "machine-dbus.h" |
| 4cee5eed | 30 | #include "machine-pool.h" |
| c3350683 | 31 | #include "machined.h" |
| 119d332d | 32 | #include "namespace-util.h" |
| ff43267c | 33 | #include "operation.h" |
| 6ef06723 | 34 | #include "os-util.h" |
| 3ffd4af2 | 35 | #include "path-util.h" |
| d80af3b9 | 36 | #include "socket-util.h" |
| 64943cac | 37 | #include "string-util.h" |
| 3ffd4af2 | 38 | #include "strv.h" |
| 64943cac | 39 | #include "unit-def.h" |
| b1d4f8e1 | 40 | #include "user-util.h" |
| 1ee306e1 | 41 | |
| 74c308ae | 42 | static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_pool_path, "s", "/var/lib/machines"); |
| 160e3793 LP |
43 | |
| 44 | static int property_get_pool_usage( | |
| 45 | sd_bus *bus, | |
| 46 | const char *path, | |
| 47 | const char *interface, | |
| 48 | const char *property, | |
| 49 | sd_bus_message *reply, | |
| 50 | void *userdata, | |
| 51 | sd_bus_error *error) { | |
| 52 | ||
| 254d1313 | 53 | _cleanup_close_ int fd = -EBADF; |
| f5fbe71d | 54 | uint64_t usage = UINT64_MAX; |
| 160e3793 LP |
55 | |
| 56 | assert(bus); | |
| 57 | assert(reply); | |
| 58 | ||
| 160e3793 LP |
59 | fd = open("/var/lib/machines", O_RDONLY|O_CLOEXEC|O_DIRECTORY); |
| 60 | if (fd >= 0) { | |
| 61 | BtrfsQuotaInfo q; | |
| 62 | ||
| 5bcd08db | 63 | if (btrfs_subvol_get_subtree_quota_fd(fd, 0, &q) >= 0) |
| cb81cd80 | 64 | usage = q.referenced; |
| 160e3793 LP |
65 | } |
| 66 | ||
| 160e3793 LP |
67 | return sd_bus_message_append(reply, "t", usage); |
| 68 | } | |
| 69 | ||
| 70 | static int property_get_pool_limit( | |
| 71 | sd_bus *bus, | |
| 72 | const char *path, | |
| 73 | const char *interface, | |
| 74 | const char *property, | |
| 75 | sd_bus_message *reply, | |
| 76 | void *userdata, | |
| 77 | sd_bus_error *error) { | |
| 78 | ||
| 254d1313 | 79 | _cleanup_close_ int fd = -EBADF; |
| f5fbe71d | 80 | uint64_t size = UINT64_MAX; |
| 160e3793 LP |
81 | |
| 82 | assert(bus); | |
| 83 | assert(reply); | |
| 84 | ||
| 160e3793 LP |
85 | fd = open("/var/lib/machines", O_RDONLY|O_CLOEXEC|O_DIRECTORY); |
| 86 | if (fd >= 0) { | |
| 87 | BtrfsQuotaInfo q; | |
| 88 | ||
| 5bcd08db | 89 | if (btrfs_subvol_get_subtree_quota_fd(fd, 0, &q) >= 0) |
| cb81cd80 | 90 | size = q.referenced_max; |
| 160e3793 LP |
91 | } |
| 92 | ||
| 160e3793 LP |
93 | return sd_bus_message_append(reply, "t", size); |
| 94 | } | |
| 95 | ||
| 19070062 | 96 | static int method_get_machine(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| c3350683 | 97 | _cleanup_free_ char *p = NULL; |
| 99534007 | 98 | Manager *m = ASSERT_PTR(userdata); |
| c3350683 LP |
99 | Machine *machine; |
| 100 | const char *name; | |
| 101 | int r; | |
| 102 | ||
| c3350683 | 103 | assert(message); |
| c3350683 LP |
104 | |
| 105 | r = sd_bus_message_read(message, "s", &name); | |
| 106 | if (r < 0) | |
| ebcf1f97 | 107 | return r; |
| c3350683 LP |
108 | |
| 109 | machine = hashmap_get(m->machines, name); | |
| 110 | if (!machine) | |
| ebcf1f97 | 111 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name); |
| c3350683 LP |
112 | |
| 113 | p = machine_bus_path(machine); | |
| 114 | if (!p) | |
| ebcf1f97 | 115 | return -ENOMEM; |
| c3350683 | 116 | |
| df2d202e | 117 | return sd_bus_reply_method_return(message, "o", p); |
| c3350683 LP |
118 | } |
| 119 | ||
| 19070062 | 120 | static int method_get_image(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| c2ce6a3d | 121 | _cleanup_free_ char *p = NULL; |
| 99534007 | 122 | _unused_ Manager *m = ASSERT_PTR(userdata); |
| c2ce6a3d LP |
123 | const char *name; |
| 124 | int r; | |
| 125 | ||
| c2ce6a3d | 126 | assert(message); |
| c2ce6a3d LP |
127 | |
| 128 | r = sd_bus_message_read(message, "s", &name); | |
| 129 | if (r < 0) | |
| 130 | return r; | |
| 131 | ||
| 1c0ade2e | 132 | r = image_find(m->runtime_scope, IMAGE_MACHINE, name, NULL, NULL); |
| 3a6ce860 | 133 | if (r == -ENOENT) |
| c2ce6a3d LP |
134 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_IMAGE, "No image '%s' known", name); |
| 135 | if (r < 0) | |
| 136 | return r; | |
| 137 | ||
| 138 | p = image_bus_path(name); | |
| 139 | if (!p) | |
| 140 | return -ENOMEM; | |
| 141 | ||
| 142 | return sd_bus_reply_method_return(message, "o", p); | |
| 143 | } | |
| 144 | ||
| 19070062 | 145 | static int method_get_machine_by_pid(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| f6cb4d4a | 146 | _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL; |
| c3350683 | 147 | _cleanup_free_ char *p = NULL; |
| 99534007 | 148 | Manager *m = ASSERT_PTR(userdata); |
| c3350683 | 149 | Machine *machine = NULL; |
| 4e724d9c | 150 | pid_t pid; |
| c3350683 LP |
151 | int r; |
| 152 | ||
| c3350683 | 153 | assert(message); |
| c3350683 | 154 | |
| 4e724d9c LP |
155 | assert_cc(sizeof(pid_t) == sizeof(uint32_t)); |
| 156 | ||
| c3350683 LP |
157 | r = sd_bus_message_read(message, "u", &pid); |
| 158 | if (r < 0) | |
| ebcf1f97 | 159 | return r; |
| c3350683 | 160 | |
| 07b38ba5 | 161 | if (pid < 0) |
| 06820eaf LP |
162 | return -EINVAL; |
| 163 | ||
| f6cb4d4a IK |
164 | pidref = PIDREF_MAKE_FROM_PID(pid); |
| 165 | ||
| 4e724d9c | 166 | if (pid == 0) { |
| 4afd3348 | 167 | _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL; |
| 5b12334d | 168 | |
| f6cb4d4a | 169 | r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID|SD_BUS_CREDS_PIDFD, &creds); |
| 5b12334d LP |
170 | if (r < 0) |
| 171 | return r; | |
| 172 | ||
| f6cb4d4a | 173 | r = bus_creds_get_pidref(creds, &pidref); |
| 4e724d9c | 174 | if (r < 0) |
| ebcf1f97 | 175 | return r; |
| 4e724d9c LP |
176 | } |
| 177 | ||
| f6cb4d4a | 178 | r = manager_get_machine_by_pidref(m, &pidref, &machine); |
| c3350683 | 179 | if (r < 0) |
| ebcf1f97 | 180 | return r; |
| 85ab917b | 181 | if (r == 0) |
| de0671ee | 182 | return sd_bus_error_setf(error, BUS_ERROR_NO_MACHINE_FOR_PID, "PID "PID_FMT" does not belong to any known machine", pid); |
| c3350683 LP |
183 | |
| 184 | p = machine_bus_path(machine); | |
| 185 | if (!p) | |
| ebcf1f97 | 186 | return -ENOMEM; |
| c3350683 | 187 | |
| df2d202e | 188 | return sd_bus_reply_method_return(message, "o", p); |
| c3350683 LP |
189 | } |
| 190 | ||
| 19070062 | 191 | static int method_list_machines(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| 4afd3348 | 192 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
| 99534007 | 193 | Manager *m = ASSERT_PTR(userdata); |
| c3350683 | 194 | Machine *machine; |
| c3350683 LP |
195 | int r; |
| 196 | ||
| c3350683 | 197 | assert(message); |
| c3350683 | 198 | |
| df2d202e | 199 | r = sd_bus_message_new_method_return(message, &reply); |
| c3350683 | 200 | if (r < 0) |
| ebcf1f97 | 201 | return sd_bus_error_set_errno(error, r); |
| c3350683 LP |
202 | |
| 203 | r = sd_bus_message_open_container(reply, 'a', "(ssso)"); | |
| 204 | if (r < 0) | |
| ebcf1f97 | 205 | return sd_bus_error_set_errno(error, r); |
| c3350683 | 206 | |
| 90e74a66 | 207 | HASHMAP_FOREACH(machine, m->machines) { |
| c3350683 LP |
208 | _cleanup_free_ char *p = NULL; |
| 209 | ||
| 210 | p = machine_bus_path(machine); | |
| 211 | if (!p) | |
| ebcf1f97 | 212 | return -ENOMEM; |
| c3350683 LP |
213 | |
| 214 | r = sd_bus_message_append(reply, "(ssso)", | |
| 215 | machine->name, | |
| 216 | strempty(machine_class_to_string(machine->class)), | |
| 217 | machine->service, | |
| 218 | p); | |
| 219 | if (r < 0) | |
| ebcf1f97 | 220 | return sd_bus_error_set_errno(error, r); |
| c3350683 | 221 | } |
| 1ee306e1 | 222 | |
| c3350683 LP |
223 | r = sd_bus_message_close_container(reply); |
| 224 | if (r < 0) | |
| ebcf1f97 | 225 | return sd_bus_error_set_errno(error, r); |
| c3350683 | 226 | |
| 51cc3825 | 227 | return sd_bus_message_send(reply); |
| c3350683 LP |
228 | } |
| 229 | ||
| d80af3b9 LB |
230 | static int machine_add_from_params( |
| 231 | Manager *manager, | |
| 232 | sd_bus_message *message, | |
| 233 | const char *polkit_action, | |
| 234 | const char *name, | |
| 235 | MachineClass c, | |
| 236 | sd_id128_t id, | |
| 237 | const char *service, | |
| 238 | PidRef *leader_pidref, | |
| 239 | PidRef *supervisor_pidref, | |
| 240 | const char *root_directory, | |
| 241 | const int32_t *netif, | |
| 242 | size_t n_netif, | |
| 243 | unsigned cid, | |
| 244 | const char *ssh_address, | |
| 245 | const char *ssh_private_key_path, | |
| 246 | Machine **ret, | |
| 247 | sd_bus_error *error) { | |
| 248 | ||
| 249 | Machine *m; | |
| 250 | int r; | |
| 251 | ||
| 252 | assert(manager); | |
| 253 | assert(message); | |
| 254 | assert(name); | |
| 255 | assert(ret); | |
| 256 | ||
| 257 | if (leader_pidref->pid == 1) | |
| 258 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid leader PID"); | |
| 259 | if (supervisor_pidref->pid == 1) | |
| 260 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid supervisor PID"); | |
| 261 | ||
| 262 | _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL; | |
| 263 | r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_EUID, &creds); | |
| 264 | if (r < 0) | |
| 265 | return r; | |
| 266 | ||
| 267 | uid_t uid; | |
| 268 | r = sd_bus_creds_get_euid(creds, &uid); | |
| 269 | if (r < 0) | |
| 270 | return r; | |
| 271 | ||
| 272 | /* Ensure an unprivileged user cannot claim any process they don't control as their own machine */ | |
| 273 | if (uid != 0) { | |
| 274 | r = process_is_owned_by_uid(leader_pidref, uid); | |
| 275 | if (r < 0) | |
| 276 | return r; | |
| 277 | if (r == 0) | |
| 278 | return sd_bus_error_set(error, SD_BUS_ERROR_ACCESS_DENIED, "Only root may register machines for other users"); | |
| 279 | } | |
| 280 | ||
| f5fa86f9 LP |
281 | if (manager->runtime_scope != RUNTIME_SCOPE_USER) { |
| 282 | const char *details[] = { | |
| 283 | "name", name, | |
| 284 | "class", machine_class_to_string(c), | |
| 285 | NULL | |
| 286 | }; | |
| 287 | ||
| 288 | r = bus_verify_polkit_async( | |
| 289 | message, | |
| 290 | polkit_action, | |
| 291 | details, | |
| 292 | &manager->polkit_registry, | |
| 293 | error); | |
| 294 | if (r < 0) | |
| 295 | return r; | |
| 296 | if (r == 0) | |
| 297 | return 0; /* Will call us back */ | |
| 298 | } | |
| d80af3b9 LB |
299 | |
| 300 | r = manager_add_machine(manager, name, &m); | |
| 301 | if (r < 0) | |
| 302 | return r; | |
| 303 | ||
| 304 | m->leader = TAKE_PIDREF(*leader_pidref); | |
| 305 | m->supervisor = TAKE_PIDREF(*supervisor_pidref); | |
| 306 | m->class = c; | |
| 307 | m->id = id; | |
| 308 | m->uid = uid; | |
| 309 | m->vsock_cid = cid; | |
| 310 | ||
| 311 | if (!isempty(service)) { | |
| 312 | m->service = strdup(service); | |
| 313 | if (!m->service) { | |
| 314 | r = -ENOMEM; | |
| 315 | goto fail; | |
| 316 | } | |
| 317 | } | |
| 318 | ||
| 319 | if (!isempty(root_directory)) { | |
| 320 | m->root_directory = strdup(root_directory); | |
| 321 | if (!m->root_directory) { | |
| 322 | r = -ENOMEM; | |
| 323 | goto fail; | |
| 324 | } | |
| 325 | } | |
| 326 | ||
| 327 | if (n_netif > 0) { | |
| 328 | assert_cc(sizeof(int32_t) == sizeof(int)); | |
| 329 | m->netif = memdup(netif, sizeof(int32_t) * n_netif); | |
| 330 | if (!m->netif) { | |
| 331 | r = -ENOMEM; | |
| 332 | goto fail; | |
| 333 | } | |
| 334 | ||
| 335 | m->n_netif = n_netif; | |
| 336 | } | |
| 337 | ||
| 338 | if (!isempty(ssh_address)) { | |
| 339 | m->ssh_address = strdup(ssh_address); | |
| 340 | if (!m->ssh_address) { | |
| 341 | r = -ENOMEM; | |
| 342 | goto fail; | |
| 343 | } | |
| 344 | } | |
| 345 | ||
| 346 | if (!isempty(ssh_private_key_path)) { | |
| 347 | m->ssh_private_key_path = strdup(ssh_private_key_path); | |
| 348 | if (!m->ssh_private_key_path) { | |
| 349 | r = -ENOMEM; | |
| 350 | goto fail; | |
| 351 | } | |
| 352 | } | |
| 353 | ||
| 354 | *ret = m; | |
| 355 | return 1; | |
| 356 | ||
| 357 | fail: | |
| 358 | machine_add_to_gc_queue(m); | |
| 359 | return r; | |
| 360 | } | |
| 361 | ||
| 4198ff4c LP |
362 | static int method_create_or_register_machine( |
| 363 | Manager *manager, | |
| 364 | sd_bus_message *message, | |
| adaff8eb | 365 | const char *polkit_action, |
| 4198ff4c LP |
366 | Machine **ret, |
| 367 | sd_bus_error *error) { | |
| 368 | ||
| 97754cd1 | 369 | _cleanup_(pidref_done) PidRef leader_pidref = PIDREF_NULL, supervisor_pidref = PIDREF_NULL; |
| 8aec412f | 370 | const char *name, *service, *class, *root_directory; |
| 9b5ed6fe | 371 | const int32_t *netif = NULL; |
| 1ee306e1 LP |
372 | MachineClass c; |
| 373 | uint32_t leader; | |
| 374 | sd_id128_t id; | |
| 4db747b0 | 375 | size_t n_netif = 0; |
| c3350683 | 376 | int r; |
| 1ee306e1 | 377 | |
| c3350683 | 378 | assert(manager); |
| 89f7c846 | 379 | assert(message); |
| 4198ff4c | 380 | assert(ret); |
| 1ee306e1 | 381 | |
| c3350683 LP |
382 | r = sd_bus_message_read(message, "s", &name); |
| 383 | if (r < 0) | |
| ebcf1f97 | 384 | return r; |
| 52ef5dd7 | 385 | if (!hostname_is_valid(name, 0)) |
| 1b09b81c | 386 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid machine name"); |
| 1ee306e1 | 387 | |
| 4db747b0 | 388 | r = bus_message_read_id128(message, &id); |
| c3350683 | 389 | if (r < 0) |
| 1b09b81c | 390 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid machine ID parameter"); |
| 1ee306e1 | 391 | |
| c3350683 LP |
392 | r = sd_bus_message_read(message, "ssus", &service, &class, &leader, &root_directory); |
| 393 | if (r < 0) | |
| ebcf1f97 | 394 | return r; |
| 1ee306e1 | 395 | |
| d80af3b9 | 396 | if (endswith(sd_bus_message_get_member(message), "WithNetwork")) { |
| 9b5ed6fe LP |
397 | r = sd_bus_message_read_array(message, 'i', (const void**) &netif, &n_netif); |
| 398 | if (r < 0) | |
| 399 | return r; | |
| 400 | ||
| 401 | n_netif /= sizeof(int32_t); | |
| 402 | ||
| d007c583 | 403 | for (size_t i = 0; i < n_netif; i++) { |
| 9b5ed6fe LP |
404 | if (netif[i] <= 0) |
| 405 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid network interface index %i", netif[i]); | |
| 406 | } | |
| 407 | } | |
| 408 | ||
| 1ee306e1 LP |
409 | if (isempty(class)) |
| 410 | c = _MACHINE_CLASS_INVALID; | |
| 411 | else { | |
| 412 | c = machine_class_from_string(class); | |
| 413 | if (c < 0) | |
| 1b09b81c | 414 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid machine class parameter"); |
| 1ee306e1 LP |
415 | } |
| 416 | ||
| c3350683 | 417 | if (leader == 1) |
| 1b09b81c | 418 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid leader PID"); |
| 1ee306e1 | 419 | |
| 0c18c0de | 420 | if (!isempty(root_directory) && (!path_is_absolute(root_directory) || !path_is_valid(root_directory))) |
| 1b09b81c | 421 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Root directory must be empty or an absolute path"); |
| 1ee306e1 | 422 | |
| c3350683 | 423 | if (leader == 0) { |
| 97754cd1 LP |
424 | /* If no PID is specified, the client is the leader */ |
| 425 | r = bus_query_sender_pidref(message, &leader_pidref); | |
| 5b12334d | 426 | if (r < 0) |
| 92a6f214 LP |
427 | return sd_bus_error_set_errnof(error, r, "Failed to pin client process: %m"); |
| 428 | } else { | |
| 97754cd1 LP |
429 | /* If a PID is specified that's the leader, but if the client process is different from it, than that's the supervisor */ |
| 430 | r = pidref_set_pid(&leader_pidref, leader); | |
| c3350683 | 431 | if (r < 0) |
| 92a6f214 | 432 | return sd_bus_error_set_errnof(error, r, "Failed to pin process " PID_FMT ": %m", (pid_t) leader); |
| 97754cd1 LP |
433 | |
| 434 | _cleanup_(pidref_done) PidRef client_pidref = PIDREF_NULL; | |
| 435 | r = bus_query_sender_pidref(message, &client_pidref); | |
| 436 | if (r < 0) | |
| 437 | return sd_bus_error_set_errnof(error, r, "Failed to pin client process: %m"); | |
| 438 | ||
| 439 | if (!pidref_equal(&client_pidref, &leader_pidref)) | |
| 440 | supervisor_pidref = TAKE_PIDREF(client_pidref); | |
| c3350683 | 441 | } |
| 554604b3 | 442 | |
| 1ee306e1 | 443 | if (hashmap_get(manager->machines, name)) |
| ebcf1f97 | 444 | return sd_bus_error_setf(error, BUS_ERROR_MACHINE_EXISTS, "Machine '%s' already exists", name); |
| 1ee306e1 | 445 | |
| d80af3b9 LB |
446 | return machine_add_from_params( |
| 447 | manager, | |
| 448 | message, | |
| 449 | polkit_action, | |
| 450 | name, | |
| 451 | c, | |
| 452 | id, | |
| 453 | service, | |
| 454 | &leader_pidref, | |
| 455 | &supervisor_pidref, | |
| 456 | root_directory, | |
| 457 | netif, | |
| 458 | n_netif, | |
| 459 | /* cid= */ 0, | |
| 460 | /* ssh_address= */ NULL, | |
| 461 | /* ssh_private_key_path= */ NULL, | |
| 462 | ret, | |
| 463 | error); | |
| 464 | } | |
| 465 | ||
| 466 | static int method_create_or_register_machine_ex( | |
| 467 | Manager *manager, | |
| 468 | sd_bus_message *message, | |
| 469 | const char *polkit_action, | |
| 470 | Machine **ret, | |
| 471 | sd_bus_error *error) { | |
| 472 | ||
| 473 | const char *name = NULL, *service = NULL, *class = NULL, *root_directory = NULL, *ssh_address = NULL, *ssh_private_key_path = NULL; | |
| 474 | _cleanup_(pidref_done) PidRef leader_pidref = PIDREF_NULL, supervisor_pidref = PIDREF_NULL; | |
| 475 | sd_id128_t id = SD_ID128_NULL; | |
| 476 | const int32_t *netif = NULL; | |
| 477 | size_t n_netif = 0; | |
| 478 | unsigned cid = 0; | |
| 479 | MachineClass c; | |
| 480 | uint64_t leader_pidfdid = 0; | |
| 481 | uint32_t leader_pid = 0; | |
| 482 | int r, leader_pidfd = -EBADF; | |
| 483 | ||
| 484 | assert(manager); | |
| 485 | assert(message); | |
| 486 | assert(ret); | |
| 487 | ||
| 488 | r = sd_bus_message_read(message, "s", &name); | |
| 276d2001 LP |
489 | if (r < 0) |
| 490 | return r; | |
| d80af3b9 LB |
491 | if (!hostname_is_valid(name, 0)) |
| 492 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid machine name"); | |
| 276d2001 | 493 | |
| d80af3b9 | 494 | r = sd_bus_message_enter_container(message, 'a', "(sv)"); |
| 276d2001 LP |
495 | if (r < 0) |
| 496 | return r; | |
| 497 | ||
| d80af3b9 LB |
498 | for (;;) { |
| 499 | const char *key; | |
| 500 | ||
| 501 | r = sd_bus_message_enter_container(message, 'r', "sv"); | |
| 119d332d LB |
502 | if (r < 0) |
| 503 | return r; | |
| 504 | if (r == 0) | |
| d80af3b9 | 505 | break; |
| 119d332d | 506 | |
| d80af3b9 LB |
507 | r = sd_bus_message_read(message, "s", &key); |
| 508 | if (r < 0) | |
| 509 | return r; | |
| 790f5162 | 510 | |
| d80af3b9 LB |
511 | r = sd_bus_message_enter_container(message, 'v', NULL); |
| 512 | if (r < 0) | |
| 513 | return r; | |
| 790f5162 | 514 | |
| d80af3b9 LB |
515 | if (streq(key, "Id")) { |
| 516 | r = bus_message_read_id128(message, &id); | |
| 517 | if (r < 0) | |
| 518 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid machine ID parameter"); | |
| 519 | } else if (streq(key, "Service")) { | |
| 520 | r = sd_bus_message_read(message, "s", &service); | |
| 521 | if (r < 0) | |
| 522 | return r; | |
| 523 | } else if (streq(key, "Class")) { | |
| 524 | r = sd_bus_message_read(message, "s", &class); | |
| 525 | if (r < 0) | |
| 526 | return r; | |
| 527 | } else if (streq(key, "LeaderPID")) { | |
| 528 | r = sd_bus_message_read(message, "u", &leader_pid); | |
| 529 | if (r < 0) | |
| 530 | return r; | |
| 531 | } else if (streq(key, "LeaderPIDFD")) { | |
| 532 | r = sd_bus_message_read(message, "h", &leader_pidfd); | |
| 533 | if (r < 0) | |
| 534 | return r; | |
| 535 | } else if (streq(key, "LeaderPIDFDID")) { | |
| 536 | r = sd_bus_message_read(message, "t", &leader_pidfdid); | |
| 537 | if (r < 0) | |
| 538 | return r; | |
| 539 | } else if (streq(key, "RootDirectory")) { | |
| 540 | r = sd_bus_message_read(message, "s", &root_directory); | |
| 541 | if (r < 0) | |
| 542 | return r; | |
| 543 | } else if (streq(key, "NetworkInterfaces")) { | |
| 544 | r = sd_bus_message_read_array(message, 'i', (const void**) &netif, &n_netif); | |
| 545 | if (r < 0) | |
| 546 | return r; | |
| 547 | ||
| 548 | n_netif /= sizeof(int32_t); | |
| 549 | ||
| 550 | for (size_t i = 0; i < n_netif; i++) | |
| 551 | if (netif[i] <= 0) | |
| 552 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid network interface index %i", netif[i]); | |
| 553 | } else if (streq(key, "VSockCID")) { | |
| 554 | r = sd_bus_message_read(message, "u", &cid); | |
| 555 | if (r < 0) | |
| 556 | return r; | |
| 557 | ||
| 558 | if (!VSOCK_CID_IS_REGULAR(cid)) | |
| 559 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "JSON field 'vSockCid' is not a regular VSOCK CID."); | |
| 560 | } else if (streq(key, "SSHAddress")) { | |
| 561 | r = sd_bus_message_read(message, "s", &ssh_address); | |
| 562 | if (r < 0) | |
| 563 | return r; | |
| 564 | } else if (streq(key, "SSHPrivateKeyPath")) { | |
| 565 | r = sd_bus_message_read(message, "s", &ssh_private_key_path); | |
| 566 | if (r < 0) | |
| 567 | return r; | |
| 568 | } else | |
| 569 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown property '%s'", key); | |
| 570 | ||
| 571 | r = sd_bus_message_exit_container(message); | |
| 572 | if (r < 0) | |
| 573 | return r; | |
| 574 | ||
| 575 | r = sd_bus_message_exit_container(message); | |
| 576 | if (r < 0) | |
| 577 | return r; | |
| 578 | } | |
| 579 | ||
| 580 | r = sd_bus_message_exit_container(message); | |
| 1ee306e1 | 581 | if (r < 0) |
| ebcf1f97 | 582 | return r; |
| 1ee306e1 | 583 | |
| d80af3b9 LB |
584 | if (isempty(class)) |
| 585 | c = _MACHINE_CLASS_INVALID; | |
| 586 | else { | |
| 587 | c = machine_class_from_string(class); | |
| 588 | if (c < 0) | |
| 589 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid machine class parameter"); | |
| 1ee306e1 LP |
590 | } |
| 591 | ||
| d80af3b9 LB |
592 | if (!isempty(root_directory) && (!path_is_absolute(root_directory) || !path_is_valid(root_directory))) |
| 593 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Root directory must be empty or an absolute path"); | |
| 1ee306e1 | 594 | |
| d80af3b9 LB |
595 | if (hashmap_get(manager->machines, name)) |
| 596 | return sd_bus_error_setf(error, BUS_ERROR_MACHINE_EXISTS, "Machine '%s' already exists", name); | |
| 597 | ||
| 598 | /* If a PID is specified that's the leader, but if the client process is different from it, than that's the supervisor */ | |
| 599 | if (leader_pidfd >= 0) { | |
| 600 | r = pidref_set_pidfd(&leader_pidref, leader_pidfd); | |
| 601 | if (r < 0) | |
| 602 | return sd_bus_error_set_errnof(error, r, "Failed to parse PIDFD %d: %m", leader_pidfd); | |
| 603 | ||
| 604 | if (leader_pid > 0 && leader_pidref.pid != (pid_t) leader_pid) | |
| 605 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "LeaderPID and LeaderPIDFD refer to different processes"); | |
| 606 | if (leader_pidfdid > 0) { | |
| 607 | r = pidref_acquire_pidfd_id(&leader_pidref); | |
| 608 | if (r >= 0 && leader_pidref.fd_id != leader_pidfdid) | |
| 609 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "LeaderPIDFDID does not match the inode number of LeaderPIDFD"); | |
| 9b5ed6fe | 610 | } |
| d80af3b9 LB |
611 | } else if (leader_pid > 0 && leader_pidfdid > 0) { |
| 612 | r = pidref_set_pid_and_pidfd_id(&leader_pidref, leader_pid, leader_pidfdid); | |
| 613 | if (r < 0) | |
| 614 | return sd_bus_error_set_errnof(error, r, "Failed to pin process " PID_FMT " by PIDFDID %" PRIu64 ": %m", (pid_t) leader_pid, leader_pidfdid); | |
| 615 | } else if (leader_pid > 0 || leader_pidfdid > 0) | |
| 616 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Both LeaderPID and LeaderPIDFDID must be specified to identify the leader process by PIDFDID"); | |
| 9b5ed6fe | 617 | |
| d80af3b9 LB |
618 | if (pidref_is_set(&leader_pidref)) { |
| 619 | _cleanup_(pidref_done) PidRef client_pidref = PIDREF_NULL; | |
| 620 | r = bus_query_sender_pidref(message, &client_pidref); | |
| 621 | if (r < 0) | |
| 622 | return sd_bus_error_set_errnof(error, r, "Failed to pin client process: %m"); | |
| 9b5ed6fe | 623 | |
| d80af3b9 LB |
624 | if (!pidref_equal(&client_pidref, &leader_pidref)) |
| 625 | supervisor_pidref = TAKE_PIDREF(client_pidref); | |
| 626 | } else { | |
| 627 | /* If no PID is specified, the client is the leader */ | |
| 628 | r = bus_query_sender_pidref(message, &leader_pidref); | |
| 629 | if (r < 0) | |
| 630 | return sd_bus_error_set_errnof(error, r, "Failed to pin client process: %m"); | |
| 631 | } | |
| 89f7c846 | 632 | |
| d80af3b9 LB |
633 | return machine_add_from_params( |
| 634 | manager, | |
| 635 | message, | |
| 636 | polkit_action, | |
| 637 | name, | |
| 638 | c, | |
| 639 | id, | |
| 640 | service, | |
| 641 | &leader_pidref, | |
| 642 | &supervisor_pidref, | |
| 643 | root_directory, | |
| 644 | netif, | |
| 645 | n_netif, | |
| 646 | cid, | |
| 647 | ssh_address, | |
| 648 | ssh_private_key_path, | |
| 649 | ret, | |
| 650 | error); | |
| 89f7c846 LP |
651 | } |
| 652 | ||
| d80af3b9 | 653 | static int method_create_machine(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| 99534007 | 654 | Manager *manager = ASSERT_PTR(userdata); |
| 89f7c846 LP |
655 | Machine *m = NULL; |
| 656 | int r; | |
| 657 | ||
| 19070062 | 658 | assert(message); |
| 19070062 | 659 | |
| d80af3b9 LB |
660 | if (sd_bus_message_is_method_call(message, NULL, "CreateMachineEx")) |
| 661 | r = method_create_or_register_machine_ex(manager, message, "org.freedesktop.machine1.create-machines", &m, error); | |
| 662 | else | |
| 663 | r = method_create_or_register_machine(manager, message, "org.freedesktop.machine1.create-machine", &m, error); | |
| 89f7c846 LP |
664 | if (r < 0) |
| 665 | return r; | |
| 790f5162 LP |
666 | if (r == 0) |
| 667 | return 1; /* Will call us back */ | |
| 89f7c846 LP |
668 | |
| 669 | r = sd_bus_message_enter_container(message, 'a', "(sv)"); | |
| 670 | if (r < 0) | |
| 671 | goto fail; | |
| 672 | ||
| ebcf1f97 LP |
673 | r = machine_start(m, message, error); |
| 674 | if (r < 0) | |
| 1ee306e1 LP |
675 | goto fail; |
| 676 | ||
| c3350683 | 677 | m->create_message = sd_bus_message_ref(message); |
| c3350683 | 678 | return 1; |
| 1ee306e1 LP |
679 | |
| 680 | fail: | |
| a3e7f417 | 681 | machine_add_to_gc_queue(m); |
| 89f7c846 LP |
682 | return r; |
| 683 | } | |
| 1ee306e1 | 684 | |
| d80af3b9 | 685 | static int method_register_machine(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| 99534007 | 686 | Manager *manager = ASSERT_PTR(userdata); |
| 89f7c846 LP |
687 | _cleanup_free_ char *p = NULL; |
| 688 | Machine *m = NULL; | |
| 689 | int r; | |
| 690 | ||
| 19070062 | 691 | assert(message); |
| 19070062 | 692 | |
| d80af3b9 LB |
693 | if (sd_bus_message_is_method_call(message, NULL, "RegisterMachineEx")) |
| 694 | r = method_create_or_register_machine_ex(manager, message, "org.freedesktop.machine1.register-machine", &m, error); | |
| 695 | else | |
| 696 | r = method_create_or_register_machine(manager, message, "org.freedesktop.machine1.register-machine", &m, error); | |
| 89f7c846 LP |
697 | if (r < 0) |
| 698 | return r; | |
| 790f5162 LP |
699 | if (r == 0) |
| 700 | return 1; /* Will call us back */ | |
| 89f7c846 | 701 | |
| f5fa86f9 LP |
702 | switch (manager->runtime_scope) { |
| 703 | case RUNTIME_SCOPE_USER: | |
| 704 | r = cg_pidref_get_user_unit_full(&m->leader, &m->unit, &m->subgroup); | |
| 705 | break; | |
| 706 | ||
| 707 | case RUNTIME_SCOPE_SYSTEM: | |
| 708 | r = cg_pidref_get_unit_full(&m->leader, &m->unit, &m->subgroup); | |
| 709 | break; | |
| 710 | ||
| 711 | default: | |
| 712 | assert_not_reached(); | |
| 713 | } | |
| 89f7c846 | 714 | if (r < 0) { |
| 048c386e ZJS |
715 | r = sd_bus_error_set_errnof(error, r, |
| 716 | "Failed to determine unit of process "PID_FMT" : %m", | |
| d8854ff1 | 717 | m->leader.pid); |
| 89f7c846 LP |
718 | goto fail; |
| 719 | } | |
| 720 | ||
| 74546a7e LP |
721 | if (!empty_or_root(m->subgroup)) { |
| 722 | /* If this is not a top-level cgroup, then we need the cgroup path to be able to watch when | |
| 723 | * it empties */ | |
| 724 | ||
| 725 | r = cg_pidref_get_path(SYSTEMD_CGROUP_CONTROLLER, &m->leader, &m->cgroup); | |
| 726 | if (r < 0) { | |
| 727 | r = sd_bus_error_set_errnof(error, r, | |
| 728 | "Failed to determine cgroup of process "PID_FMT" : %m", | |
| 729 | m->leader.pid); | |
| 730 | goto fail; | |
| 731 | } | |
| 732 | } | |
| 733 | ||
| 89f7c846 LP |
734 | r = machine_start(m, NULL, error); |
| 735 | if (r < 0) | |
| 736 | goto fail; | |
| 737 | ||
| 738 | p = machine_bus_path(m); | |
| 739 | if (!p) { | |
| 740 | r = -ENOMEM; | |
| 741 | goto fail; | |
| 742 | } | |
| 743 | ||
| 744 | return sd_bus_reply_method_return(message, "o", p); | |
| 745 | ||
| 746 | fail: | |
| 747 | machine_add_to_gc_queue(m); | |
| 1ee306e1 LP |
748 | return r; |
| 749 | } | |
| 750 | ||
| eecf0181 | 751 | static int redirect_method_to_machine(sd_bus_message *message, Manager *m, sd_bus_error *error, sd_bus_message_handler_t method) { |
| c3350683 LP |
752 | Machine *machine; |
| 753 | const char *name; | |
| 1ee306e1 LP |
754 | int r; |
| 755 | ||
| 1ee306e1 LP |
756 | assert(message); |
| 757 | assert(m); | |
| eecf0181 | 758 | assert(method); |
| 1ee306e1 | 759 | |
| c3350683 LP |
760 | r = sd_bus_message_read(message, "s", &name); |
| 761 | if (r < 0) | |
| ebcf1f97 | 762 | return sd_bus_error_set_errno(error, r); |
| 1ee306e1 | 763 | |
| c3350683 LP |
764 | machine = hashmap_get(m->machines, name); |
| 765 | if (!machine) | |
| ebcf1f97 | 766 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name); |
| 1ee306e1 | 767 | |
| eecf0181 | 768 | return method(message, machine, error); |
| c3350683 | 769 | } |
| 1ee306e1 | 770 | |
| ef8ff92e ZJS |
771 | static int method_unregister_machine(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| 772 | return redirect_method_to_machine(message, userdata, error, bus_machine_method_unregister); | |
| 773 | } | |
| 774 | ||
| eecf0181 LP |
775 | static int method_terminate_machine(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| 776 | return redirect_method_to_machine(message, userdata, error, bus_machine_method_terminate); | |
| 777 | } | |
| 1ee306e1 | 778 | |
| eecf0181 LP |
779 | static int method_kill_machine(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| 780 | return redirect_method_to_machine(message, userdata, error, bus_machine_method_kill); | |
| 878cd7e9 LP |
781 | } |
| 782 | ||
| 19070062 | 783 | static int method_get_machine_addresses(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| eecf0181 | 784 | return redirect_method_to_machine(message, userdata, error, bus_machine_method_get_addresses); |
| c3350683 | 785 | } |
| 1ee306e1 | 786 | |
| 1f815bf1 SL |
787 | static int method_get_machine_ssh_info(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| 788 | return redirect_method_to_machine(message, userdata, error, bus_machine_method_get_ssh_info); | |
| 789 | } | |
| 790 | ||
| 19070062 | 791 | static int method_get_machine_os_release(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| eecf0181 | 792 | return redirect_method_to_machine(message, userdata, error, bus_machine_method_get_os_release); |
| 717603e3 LP |
793 | } |
| 794 | ||
| 19070062 | 795 | static int method_list_images(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| 4afd3348 | 796 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
| 624d3698 | 797 | Manager *m = ASSERT_PTR(userdata); |
| cd61c3bf LP |
798 | int r; |
| 799 | ||
| cd61c3bf | 800 | assert(message); |
| cd61c3bf | 801 | |
| 624d3698 YW |
802 | _cleanup_hashmap_free_ Hashmap *images = NULL; |
| 803 | r = image_discover(m->runtime_scope, IMAGE_MACHINE, NULL, &images); | |
| cd61c3bf LP |
804 | if (r < 0) |
| 805 | return r; | |
| 806 | ||
| 807 | r = sd_bus_message_new_method_return(message, &reply); | |
| 808 | if (r < 0) | |
| 809 | return r; | |
| 810 | ||
| b6b18498 | 811 | r = sd_bus_message_open_container(reply, 'a', "(ssbttto)"); |
| cd61c3bf LP |
812 | if (r < 0) |
| 813 | return r; | |
| 814 | ||
| 624d3698 | 815 | Image *image; |
| 90e74a66 | 816 | HASHMAP_FOREACH(image, images) { |
| cd61c3bf LP |
817 | _cleanup_free_ char *p = NULL; |
| 818 | ||
| 819 | p = image_bus_path(image->name); | |
| 820 | if (!p) | |
| 821 | return -ENOMEM; | |
| 822 | ||
| b6b18498 | 823 | r = sd_bus_message_append(reply, "(ssbttto)", |
| cd61c3bf LP |
824 | image->name, |
| 825 | image_type_to_string(image->type), | |
| 826 | image->read_only, | |
| 10f9c755 LP |
827 | image->crtime, |
| 828 | image->mtime, | |
| c19de711 | 829 | image->usage, |
| cd61c3bf LP |
830 | p); |
| 831 | if (r < 0) | |
| 832 | return r; | |
| 833 | } | |
| 834 | ||
| 835 | r = sd_bus_message_close_container(reply); | |
| 836 | if (r < 0) | |
| 837 | return r; | |
| 838 | ||
| 51cc3825 | 839 | return sd_bus_message_send(reply); |
| cd61c3bf LP |
840 | } |
| 841 | ||
| 19070062 | 842 | static int method_open_machine_pty(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| eecf0181 | 843 | return redirect_method_to_machine(message, userdata, error, bus_machine_method_open_pty); |
| 40205d70 LP |
844 | } |
| 845 | ||
| 19070062 | 846 | static int method_open_machine_login(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| eecf0181 | 847 | return redirect_method_to_machine(message, userdata, error, bus_machine_method_open_login); |
| 5f8cc96a LP |
848 | } |
| 849 | ||
| 49af9e13 | 850 | static int method_open_machine_shell(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| eecf0181 | 851 | return redirect_method_to_machine(message, userdata, error, bus_machine_method_open_shell); |
| 49af9e13 LP |
852 | } |
| 853 | ||
| 19070062 | 854 | static int method_bind_mount_machine(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| eecf0181 | 855 | return redirect_method_to_machine(message, userdata, error, bus_machine_method_bind_mount); |
| 90adaa25 LP |
856 | } |
| 857 | ||
| 19070062 | 858 | static int method_copy_machine(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| eecf0181 | 859 | return redirect_method_to_machine(message, userdata, error, bus_machine_method_copy); |
| 0370612e LP |
860 | } |
| 861 | ||
| ae203207 | 862 | static int method_open_machine_root_directory(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| eecf0181 | 863 | return redirect_method_to_machine(message, userdata, error, bus_machine_method_open_root_directory); |
| ae203207 LP |
864 | } |
| 865 | ||
| 3401419b | 866 | static int method_get_machine_uid_shift(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| eecf0181 | 867 | return redirect_method_to_machine(message, userdata, error, bus_machine_method_get_uid_shift); |
| 3401419b LP |
868 | } |
| 869 | ||
| 9b06c1e1 | 870 | static int redirect_method_to_image(sd_bus_message *message, Manager *m, sd_bus_error *error, sd_bus_message_handler_t method) { |
| 08682124 | 871 | const char *name; |
| c6aeb9b5 | 872 | Image *i; |
| 08682124 LP |
873 | int r; |
| 874 | ||
| 08682124 | 875 | assert(message); |
| 9b06c1e1 LP |
876 | assert(m); |
| 877 | assert(method); | |
| 08682124 LP |
878 | |
| 879 | r = sd_bus_message_read(message, "s", &name); | |
| 880 | if (r < 0) | |
| 881 | return r; | |
| 882 | ||
| 883 | if (!image_name_is_valid(name)) | |
| 884 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Image name '%s' is invalid.", name); | |
| 885 | ||
| c6aeb9b5 | 886 | r = manager_acquire_image(m, name, &i); |
| 3a6ce860 LP |
887 | if (r == -ENOENT) |
| 888 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_IMAGE, "No image '%s' known", name); | |
| 08682124 LP |
889 | if (r < 0) |
| 890 | return r; | |
| 08682124 | 891 | |
| 9b06c1e1 | 892 | return method(message, i, error); |
| 08682124 LP |
893 | } |
| 894 | ||
| 9b06c1e1 LP |
895 | static int method_remove_image(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| 896 | return redirect_method_to_image(message, userdata, error, bus_image_method_remove); | |
| 897 | } | |
| ebd93cb6 | 898 | |
| 9b06c1e1 LP |
899 | static int method_rename_image(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| 900 | return redirect_method_to_image(message, userdata, error, bus_image_method_rename); | |
| ebd93cb6 LP |
901 | } |
| 902 | ||
| 19070062 | 903 | static int method_clone_image(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| 9b06c1e1 | 904 | return redirect_method_to_image(message, userdata, error, bus_image_method_clone); |
| ebd93cb6 LP |
905 | } |
| 906 | ||
| 19070062 | 907 | static int method_mark_image_read_only(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| 9b06c1e1 | 908 | return redirect_method_to_image(message, userdata, error, bus_image_method_mark_read_only); |
| ebd93cb6 LP |
909 | } |
| 910 | ||
| cf30a8c1 | 911 | static int method_get_image_hostname(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| 9b06c1e1 | 912 | return redirect_method_to_image(message, userdata, error, bus_image_method_get_hostname); |
| cf30a8c1 LP |
913 | } |
| 914 | ||
| 915 | static int method_get_image_machine_id(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
| 9b06c1e1 | 916 | return redirect_method_to_image(message, userdata, error, bus_image_method_get_machine_id); |
| cf30a8c1 LP |
917 | } |
| 918 | ||
| 919 | static int method_get_image_machine_info(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
| 9b06c1e1 | 920 | return redirect_method_to_image(message, userdata, error, bus_image_method_get_machine_info); |
| cf30a8c1 LP |
921 | } |
| 922 | ||
| 9153b02b | 923 | static int method_get_image_os_release(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| 9b06c1e1 | 924 | return redirect_method_to_image(message, userdata, error, bus_image_method_get_os_release); |
| 9153b02b LP |
925 | } |
| 926 | ||
| 5a99c9d7 | 927 | static int clean_pool_done(Operation *operation, int child_error, sd_bus_error *error) { |
| 03c2b288 | 928 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
| 5a99c9d7 | 929 | _cleanup_fclose_ FILE *file = NULL; |
| 03c2b288 LP |
930 | int r; |
| 931 | ||
| 932 | assert(operation); | |
| 5a99c9d7 | 933 | assert(operation->message); |
| 03c2b288 LP |
934 | assert(operation->extra_fd >= 0); |
| 935 | ||
| 5a99c9d7 IK |
936 | file = take_fdopen(&operation->extra_fd, "r"); |
| 937 | if (!file) | |
| 938 | return log_debug_errno(errno, "Failed to take opened tmp file's fd: %m"); | |
| 03c2b288 | 939 | |
| 5a99c9d7 IK |
940 | r = clean_pool_read_first_entry(file, child_error, error); |
| 941 | if (r < 0) | |
| 942 | return r; | |
| 03c2b288 LP |
943 | |
| 944 | r = sd_bus_message_new_method_return(operation->message, &reply); | |
| 945 | if (r < 0) | |
| 946 | return r; | |
| 947 | ||
| 948 | r = sd_bus_message_open_container(reply, 'a', "(st)"); | |
| 949 | if (r < 0) | |
| 950 | return r; | |
| 951 | ||
| 952 | /* On success the resulting temporary file will contain a list of image names that were removed followed by | |
| 953 | * their size on disk. Let's read that and turn it into a bus message. */ | |
| 954 | for (;;) { | |
| 955 | _cleanup_free_ char *name = NULL; | |
| 5a99c9d7 | 956 | uint64_t usage; |
| 03c2b288 | 957 | |
| 5a99c9d7 | 958 | r = clean_pool_read_next_entry(file, &name, &usage); |
| 03c2b288 LP |
959 | if (r < 0) |
| 960 | return r; | |
| 5a99c9d7 | 961 | if (r == 0) |
| 03c2b288 LP |
962 | break; |
| 963 | ||
| 5a99c9d7 | 964 | r = sd_bus_message_append(reply, "(st)", name, usage); |
| 03c2b288 LP |
965 | if (r < 0) |
| 966 | return r; | |
| 967 | } | |
| 968 | ||
| 969 | r = sd_bus_message_close_container(reply); | |
| 970 | if (r < 0) | |
| 971 | return r; | |
| 972 | ||
| 51cc3825 | 973 | return sd_bus_message_send(reply); |
| 03c2b288 LP |
974 | } |
| 975 | ||
| d94c2b06 | 976 | static int method_clean_pool(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| 5a99c9d7 | 977 | ImageCleanPoolMode mode; |
| d94c2b06 | 978 | Manager *m = userdata; |
| 03c2b288 | 979 | Operation *operation; |
| d94c2b06 | 980 | const char *mm; |
| d94c2b06 LP |
981 | int r; |
| 982 | ||
| 983 | assert(message); | |
| 984 | ||
| 03c2b288 | 985 | if (m->n_operations >= OPERATIONS_MAX) |
| 1b09b81c | 986 | return sd_bus_error_set(error, SD_BUS_ERROR_LIMITS_EXCEEDED, "Too many ongoing operations."); |
| 03c2b288 | 987 | |
| d94c2b06 LP |
988 | r = sd_bus_message_read(message, "s", &mm); |
| 989 | if (r < 0) | |
| 990 | return r; | |
| 991 | ||
| 992 | if (streq(mm, "all")) | |
| 5a99c9d7 | 993 | mode = IMAGE_CLEAN_POOL_REMOVE_ALL; |
| d94c2b06 | 994 | else if (streq(mm, "hidden")) |
| 5a99c9d7 | 995 | mode = IMAGE_CLEAN_POOL_REMOVE_HIDDEN; |
| d94c2b06 LP |
996 | else |
| 997 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown mode '%s'.", mm); | |
| 998 | ||
| f5fa86f9 LP |
999 | if (m->runtime_scope != RUNTIME_SCOPE_USER) { |
| 1000 | const char *details[] = { | |
| 1001 | "verb", "clean_pool", | |
| 1002 | "mode", mm, | |
| 1003 | NULL | |
| 1004 | }; | |
| 1005 | ||
| 1006 | r = bus_verify_polkit_async( | |
| 1007 | message, | |
| 1008 | "org.freedesktop.machine1.manage-machines", | |
| 1009 | details, | |
| 1010 | &m->polkit_registry, | |
| 1011 | error); | |
| 1012 | if (r < 0) | |
| 1013 | return r; | |
| 1014 | if (r == 0) | |
| 1015 | return 1; /* Will call us back */ | |
| 1016 | } | |
| d94c2b06 | 1017 | |
| 5a99c9d7 | 1018 | r = image_clean_pool_operation(m, mode, &operation); |
| 4c253ed1 | 1019 | if (r < 0) |
| 5a99c9d7 | 1020 | return log_debug_errno(r, "Failed to clean pool of images: %m"); |
| 03c2b288 | 1021 | |
| 5a99c9d7 | 1022 | operation_attach_bus_reply(operation, message); |
| 03c2b288 | 1023 | operation->done = clean_pool_done; |
| 03c2b288 | 1024 | return 1; |
| d94c2b06 LP |
1025 | } |
| 1026 | ||
| 19070062 | 1027 | static int method_set_pool_limit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| d6ce17c7 LP |
1028 | Manager *m = userdata; |
| 1029 | uint64_t limit; | |
| 1030 | int r; | |
| 1031 | ||
| 19070062 LP |
1032 | assert(message); |
| 1033 | ||
| d6ce17c7 LP |
1034 | r = sd_bus_message_read(message, "t", &limit); |
| 1035 | if (r < 0) | |
| 1036 | return r; | |
| a90fb858 | 1037 | if (!FILE_SIZE_VALID_OR_INFINITY(limit)) |
| 1b09b81c | 1038 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "New limit out of range"); |
| d6ce17c7 | 1039 | |
| f5fa86f9 LP |
1040 | if (m->runtime_scope != RUNTIME_SCOPE_USER) { |
| 1041 | const char *details[] = { | |
| 1042 | "verb", "set_pool_limit", | |
| 1043 | NULL | |
| 1044 | }; | |
| 1045 | ||
| 1046 | r = bus_verify_polkit_async( | |
| 1047 | message, | |
| 1048 | "org.freedesktop.machine1.manage-machines", | |
| 1049 | details, | |
| 1050 | &m->polkit_registry, | |
| 1051 | error); | |
| 1052 | if (r < 0) | |
| 1053 | return r; | |
| 1054 | if (r == 0) | |
| 1055 | return 1; /* Will call us back */ | |
| 1056 | } | |
| d6ce17c7 | 1057 | |
| 4cee5eed | 1058 | /* Set up the machine directory if necessary */ |
| c7779a61 | 1059 | r = setup_machine_directory(error, /* use_btrfs_subvol= */ true, /* use_btrfs_quota= */ true); |
| 4cee5eed LP |
1060 | if (r < 0) |
| 1061 | return r; | |
| 1062 | ||
| e1b3319b | 1063 | r = image_set_pool_limit(m->runtime_scope, IMAGE_MACHINE, limit); |
| efe47f58 | 1064 | if (ERRNO_IS_NEG_NOT_SUPPORTED(r)) |
| 1b09b81c | 1065 | return sd_bus_error_set(error, SD_BUS_ERROR_NOT_SUPPORTED, "Quota is only supported on btrfs."); |
| 26166c88 | 1066 | if (r < 0) |
| d6ce17c7 LP |
1067 | return sd_bus_error_set_errnof(error, r, "Failed to adjust quota limit: %m"); |
| 1068 | ||
| 1069 | return sd_bus_reply_method_return(message, NULL); | |
| 1070 | } | |
| 1071 | ||
| 19070062 | 1072 | static int method_set_image_limit(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| 9b06c1e1 | 1073 | return redirect_method_to_image(message, userdata, error, bus_image_method_set_limit); |
| d6ce17c7 LP |
1074 | } |
| 1075 | ||
| c01ff965 | 1076 | static int method_map_from_machine_user(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| c01ff965 | 1077 | Manager *m = userdata; |
| 74d1b7d2 | 1078 | const char *name; |
| c01ff965 LP |
1079 | Machine *machine; |
| 1080 | uint32_t uid; | |
| 74d1b7d2 | 1081 | uid_t converted; |
| c01ff965 LP |
1082 | int r; |
| 1083 | ||
| 1084 | r = sd_bus_message_read(message, "su", &name, &uid); | |
| 1085 | if (r < 0) | |
| 1086 | return r; | |
| 1087 | ||
| c077529b | 1088 | if (!uid_is_valid(uid)) |
| c01ff965 LP |
1089 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid user ID " UID_FMT, uid); |
| 1090 | ||
| 1091 | machine = hashmap_get(m->machines, name); | |
| 1092 | if (!machine) | |
| 1093 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name); | |
| 1094 | ||
| a79366e2 | 1095 | if (machine->class != MACHINE_CONTAINER) |
| 1b09b81c | 1096 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Not supported for non-container machines."); |
| a79366e2 | 1097 | |
| 74d1b7d2 LP |
1098 | r = machine_translate_uid(machine, uid, &converted); |
| 1099 | if (r == -ESRCH) | |
| 1100 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_USER_MAPPING, "Machine '%s' has no matching user mappings.", name); | |
| 1101 | if (r < 0) | |
| 1102 | return r; | |
| c01ff965 | 1103 | |
| 74d1b7d2 | 1104 | return sd_bus_reply_method_return(message, "u", (uint32_t) converted); |
| c01ff965 LP |
1105 | } |
| 1106 | ||
| 1107 | static int method_map_to_machine_user(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |
| 74d1b7d2 | 1108 | _cleanup_free_ char *o = NULL; |
| c01ff965 LP |
1109 | Manager *m = userdata; |
| 1110 | Machine *machine; | |
| 74d1b7d2 | 1111 | uid_t uid, converted; |
| c01ff965 LP |
1112 | int r; |
| 1113 | ||
| 1114 | r = sd_bus_message_read(message, "u", &uid); | |
| 1115 | if (r < 0) | |
| 1116 | return r; | |
| c077529b | 1117 | if (!uid_is_valid(uid)) |
| c01ff965 LP |
1118 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid user ID " UID_FMT, uid); |
| 1119 | if (uid < 0x10000) | |
| 1120 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_USER_MAPPING, "User " UID_FMT " belongs to host UID range", uid); | |
| 1121 | ||
| 74d1b7d2 LP |
1122 | r = manager_find_machine_for_uid(m, uid, &machine, &converted); |
| 1123 | if (r < 0) | |
| 1124 | return r; | |
| 1125 | if (!r) | |
| 1126 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_USER_MAPPING, "No matching user mapping for " UID_FMT ".", uid); | |
| c01ff965 | 1127 | |
| 74d1b7d2 LP |
1128 | o = machine_bus_path(machine); |
| 1129 | if (!o) | |
| 1130 | return -ENOMEM; | |
| c01ff965 | 1131 | |
| 74d1b7d2 | 1132 | return sd_bus_reply_method_return(message, "sou", machine->name, o, (uint32_t) converted); |
| c01ff965 LP |
1133 | } |
| 1134 | ||
| 74d1b7d2 LP |
1135 | static int method_map_from_machine_group(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| 1136 | Manager *m = userdata; | |
| 1137 | const char *name; | |
| c01ff965 | 1138 | Machine *machine; |
| 74d1b7d2 | 1139 | gid_t converted; |
| c01ff965 LP |
1140 | uint32_t gid; |
| 1141 | int r; | |
| 1142 | ||
| 1143 | r = sd_bus_message_read(message, "su", &name, &gid); | |
| 1144 | if (r < 0) | |
| 1145 | return r; | |
| 1146 | ||
| c077529b | 1147 | if (!gid_is_valid(gid)) |
| c01ff965 LP |
1148 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid group ID " GID_FMT, gid); |
| 1149 | ||
| 1150 | machine = hashmap_get(m->machines, name); | |
| 1151 | if (!machine) | |
| 1152 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name); | |
| 1153 | ||
| a79366e2 | 1154 | if (machine->class != MACHINE_CONTAINER) |
| 1b09b81c | 1155 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Not supported for non-container machines."); |
| a79366e2 | 1156 | |
| 74d1b7d2 LP |
1157 | r = machine_translate_gid(machine, gid, &converted); |
| 1158 | if (r == -ESRCH) | |
| 1159 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_USER_MAPPING, "Machine '%s' has no matching group mappings.", name); | |
| 1160 | if (r < 0) | |
| 1161 | return r; | |
| c01ff965 | 1162 | |
| 74d1b7d2 | 1163 | return sd_bus_reply_method_return(message, "u", (uint32_t) converted); |
| c01ff965 LP |
1164 | } |
| 1165 | ||
| 74d1b7d2 LP |
1166 | static int method_map_to_machine_group(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| 1167 | _cleanup_free_ char *o = NULL; | |
| 1168 | Manager *m = userdata; | |
| c01ff965 | 1169 | Machine *machine; |
| 74d1b7d2 | 1170 | gid_t gid, converted; |
| c01ff965 LP |
1171 | int r; |
| 1172 | ||
| 1173 | r = sd_bus_message_read(message, "u", &gid); | |
| 1174 | if (r < 0) | |
| 1175 | return r; | |
| c077529b | 1176 | if (!gid_is_valid(gid)) |
| c01ff965 LP |
1177 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid group ID " GID_FMT, gid); |
| 1178 | if (gid < 0x10000) | |
| 1179 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_GROUP_MAPPING, "Group " GID_FMT " belongs to host GID range", gid); | |
| 1180 | ||
| 74d1b7d2 LP |
1181 | r = manager_find_machine_for_gid(m, gid, &machine, &converted); |
| 1182 | if (r < 0) | |
| 1183 | return r; | |
| 1184 | if (!r) | |
| 1185 | return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_GROUP_MAPPING, "No matching group mapping for " GID_FMT ".", gid); | |
| c01ff965 | 1186 | |
| 74d1b7d2 LP |
1187 | o = machine_bus_path(machine); |
| 1188 | if (!o) | |
| 1189 | return -ENOMEM; | |
| c01ff965 | 1190 | |
| 74d1b7d2 | 1191 | return sd_bus_reply_method_return(message, "sou", machine->name, o, (uint32_t) converted); |
| c01ff965 LP |
1192 | } |
| 1193 | ||
| c3350683 LP |
1194 | const sd_bus_vtable manager_vtable[] = { |
| 1195 | SD_BUS_VTABLE_START(0), | |
| bbe17ca1 | 1196 | |
| 160e3793 LP |
1197 | SD_BUS_PROPERTY("PoolPath", "s", property_get_pool_path, 0, 0), |
| 1198 | SD_BUS_PROPERTY("PoolUsage", "t", property_get_pool_usage, 0, 0), | |
| 1199 | SD_BUS_PROPERTY("PoolLimit", "t", property_get_pool_limit, 0, 0), | |
| bbe17ca1 | 1200 | |
| d5e4e60b A |
1201 | SD_BUS_METHOD_WITH_ARGS("GetMachine", |
| 1202 | SD_BUS_ARGS("s", name), | |
| 1203 | SD_BUS_RESULT("o", machine), | |
| 1204 | method_get_machine, | |
| 1205 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1206 | SD_BUS_METHOD_WITH_ARGS("GetImage", | |
| 1207 | SD_BUS_ARGS("s", name), | |
| 1208 | SD_BUS_RESULT("o", image), | |
| 1209 | method_get_image, | |
| 1210 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1211 | SD_BUS_METHOD_WITH_ARGS("GetMachineByPID", | |
| 1212 | SD_BUS_ARGS("u", pid), | |
| 1213 | SD_BUS_RESULT("o", machine), | |
| 1214 | method_get_machine_by_pid, | |
| 1215 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1216 | SD_BUS_METHOD_WITH_ARGS("ListMachines", | |
| 1217 | SD_BUS_NO_ARGS, | |
| 1218 | SD_BUS_RESULT("a(ssso)", machines), | |
| 1219 | method_list_machines, | |
| 1220 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1221 | SD_BUS_METHOD_WITH_ARGS("ListImages", | |
| 1222 | SD_BUS_NO_ARGS, | |
| 1223 | SD_BUS_RESULT("a(ssbttto)", images), | |
| 1224 | method_list_images, | |
| 1225 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1226 | SD_BUS_METHOD_WITH_ARGS("CreateMachine", | |
| 1227 | SD_BUS_ARGS("s", name, "ay", id, "s", service, "s", class, "u", leader, "s", root_directory, "a(sv)", scope_properties), | |
| 1228 | SD_BUS_RESULT("o", path), | |
| 790f5162 LP |
1229 | method_create_machine, |
| 1230 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| d5e4e60b A |
1231 | SD_BUS_METHOD_WITH_ARGS("CreateMachineWithNetwork", |
| 1232 | SD_BUS_ARGS("s", name, "ay", id, "s", service, "s", class, "u", leader, "s", root_directory, "ai", ifindices, "a(sv)", scope_properties), | |
| 1233 | SD_BUS_RESULT("o", path), | |
| d80af3b9 LB |
1234 | method_create_machine, |
| 1235 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1236 | SD_BUS_METHOD_WITH_ARGS("CreateMachineEx", | |
| 1237 | SD_BUS_ARGS("s", name, "a(sv)", properties, "a(sv)", scope_properties), | |
| 1238 | SD_BUS_RESULT("o", path), | |
| 1239 | method_create_machine, | |
| 790f5162 | 1240 | SD_BUS_VTABLE_UNPRIVILEGED), |
| d5e4e60b A |
1241 | SD_BUS_METHOD_WITH_ARGS("RegisterMachine", |
| 1242 | SD_BUS_ARGS("s", name, "ay", id, "s", service, "s", class, "u", leader, "s", root_directory), | |
| 1243 | SD_BUS_RESULT("o", path), | |
| 790f5162 LP |
1244 | method_register_machine, |
| 1245 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| d5e4e60b A |
1246 | SD_BUS_METHOD_WITH_ARGS("RegisterMachineWithNetwork", |
| 1247 | SD_BUS_ARGS("s", name, "ay", id, "s", service, "s", class, "u", leader, "s", root_directory, "ai", ifindices), | |
| 1248 | SD_BUS_RESULT("o", path), | |
| d80af3b9 LB |
1249 | method_register_machine, |
| 1250 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1251 | SD_BUS_METHOD_WITH_ARGS("RegisterMachineEx", | |
| 1252 | SD_BUS_ARGS("s", name, "a(sv)", properties), | |
| 1253 | SD_BUS_RESULT("o", path), | |
| 1254 | method_register_machine, | |
| 790f5162 | 1255 | SD_BUS_VTABLE_UNPRIVILEGED), |
| d5e4e60b A |
1256 | SD_BUS_METHOD_WITH_ARGS("UnregisterMachine", |
| 1257 | SD_BUS_ARGS("s", name), | |
| 1258 | SD_BUS_NO_RESULT, | |
| 1259 | method_unregister_machine, | |
| 1260 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1261 | SD_BUS_METHOD_WITH_ARGS("TerminateMachine", | |
| 1262 | SD_BUS_ARGS("s", id), | |
| 1263 | SD_BUS_NO_RESULT, | |
| 1264 | method_terminate_machine, | |
| 1265 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1266 | SD_BUS_METHOD_WITH_ARGS("KillMachine", | |
| 3ae0e545 | 1267 | SD_BUS_ARGS("s", name, "s", whom, "i", signal), |
| d5e4e60b A |
1268 | SD_BUS_NO_RESULT, |
| 1269 | method_kill_machine, | |
| 1270 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1271 | SD_BUS_METHOD_WITH_ARGS("GetMachineAddresses", | |
| 1272 | SD_BUS_ARGS("s", name), | |
| 1273 | SD_BUS_RESULT("a(iay)", addresses), | |
| 1274 | method_get_machine_addresses, | |
| 1275 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1f815bf1 SL |
1276 | SD_BUS_METHOD_WITH_ARGS("GetMachineSSHInfo", |
| 1277 | SD_BUS_ARGS("s", name), | |
| 1278 | SD_BUS_RESULT("s", ssh_address, "s", ssh_private_key_path), | |
| 1279 | method_get_machine_ssh_info, | |
| 1280 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| d5e4e60b A |
1281 | SD_BUS_METHOD_WITH_ARGS("GetMachineOSRelease", |
| 1282 | SD_BUS_ARGS("s", name), | |
| 1283 | SD_BUS_RESULT("a{ss}", fields), | |
| 1284 | method_get_machine_os_release, | |
| 1285 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1286 | SD_BUS_METHOD_WITH_ARGS("OpenMachinePTY", | |
| 1287 | SD_BUS_ARGS("s", name), | |
| 1288 | SD_BUS_RESULT("h", pty, "s", pty_path), | |
| 1289 | method_open_machine_pty, | |
| 020d6c1d | 1290 | SD_BUS_VTABLE_UNPRIVILEGED), |
| d5e4e60b A |
1291 | SD_BUS_METHOD_WITH_ARGS("OpenMachineLogin", |
| 1292 | SD_BUS_ARGS("s", name), | |
| 1293 | SD_BUS_RESULT("h", pty, "s", pty_path), | |
| 1294 | method_open_machine_login, | |
| 1295 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1296 | SD_BUS_METHOD_WITH_ARGS("OpenMachineShell", | |
| 1297 | SD_BUS_ARGS("s", name, "s", user, "s", path, "as", args, "as", environment), | |
| 1298 | SD_BUS_RESULT("h", pty, "s", pty_path), | |
| 1299 | method_open_machine_shell, | |
| 1300 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1301 | SD_BUS_METHOD_WITH_ARGS("BindMountMachine", | |
| 1302 | SD_BUS_ARGS("s", name, "s", source, "s", destination, "b", read_only, "b", mkdir), | |
| 1303 | SD_BUS_NO_RESULT, | |
| 1304 | method_bind_mount_machine, | |
| 1305 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1306 | SD_BUS_METHOD_WITH_ARGS("CopyFromMachine", | |
| 1307 | SD_BUS_ARGS("s", name, "s", source, "s", destination), | |
| 1308 | SD_BUS_NO_RESULT, | |
| 1309 | method_copy_machine, | |
| 1310 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1311 | SD_BUS_METHOD_WITH_ARGS("CopyToMachine", | |
| 1312 | SD_BUS_ARGS("s", name, "s", source, "s", destination), | |
| 1313 | SD_BUS_NO_RESULT, | |
| 1314 | method_copy_machine, | |
| 1315 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| ae03e1a9 AW |
1316 | SD_BUS_METHOD_WITH_ARGS("CopyFromMachineWithFlags", |
| 1317 | SD_BUS_ARGS("s", name, "s", source, "s", destination, "t", flags), | |
| 1318 | SD_BUS_NO_RESULT, | |
| 1319 | method_copy_machine, | |
| 1320 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1321 | SD_BUS_METHOD_WITH_ARGS("CopyToMachineWithFlags", | |
| 1322 | SD_BUS_ARGS("s", name, "s", source, "s", destination, "t", flags), | |
| 1323 | SD_BUS_NO_RESULT, | |
| 1324 | method_copy_machine, | |
| 1325 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| d5e4e60b A |
1326 | SD_BUS_METHOD_WITH_ARGS("OpenMachineRootDirectory", |
| 1327 | SD_BUS_ARGS("s", name), | |
| 1328 | SD_BUS_RESULT("h", fd), | |
| 1329 | method_open_machine_root_directory, | |
| 1330 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1331 | SD_BUS_METHOD_WITH_ARGS("GetMachineUIDShift", | |
| 1332 | SD_BUS_ARGS("s", name), | |
| 1333 | SD_BUS_RESULT("u", shift), | |
| 1334 | method_get_machine_uid_shift, | |
| 1335 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1336 | SD_BUS_METHOD_WITH_ARGS("RemoveImage", | |
| 1337 | SD_BUS_ARGS("s", name), | |
| 1338 | SD_BUS_NO_RESULT, | |
| 1339 | method_remove_image, | |
| 1340 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1341 | SD_BUS_METHOD_WITH_ARGS("RenameImage", | |
| 1342 | SD_BUS_ARGS("s", name, "s", new_name), | |
| 1343 | SD_BUS_NO_RESULT, | |
| 1344 | method_rename_image, | |
| 1345 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1346 | SD_BUS_METHOD_WITH_ARGS("CloneImage", | |
| 1347 | SD_BUS_ARGS("s", name, "s", new_name, "b", read_only), | |
| 1348 | SD_BUS_NO_RESULT, | |
| 1349 | method_clone_image, | |
| 1350 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1351 | SD_BUS_METHOD_WITH_ARGS("MarkImageReadOnly", | |
| 1352 | SD_BUS_ARGS("s", name, "b", read_only), | |
| 1353 | SD_BUS_NO_RESULT, | |
| 1354 | method_mark_image_read_only, | |
| 1355 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1356 | SD_BUS_METHOD_WITH_ARGS("GetImageHostname", | |
| 1357 | SD_BUS_ARGS("s", name), | |
| 1358 | SD_BUS_RESULT("s", hostname), | |
| 1359 | method_get_image_hostname, | |
| 1360 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1361 | SD_BUS_METHOD_WITH_ARGS("GetImageMachineID", | |
| 1362 | SD_BUS_ARGS("s", name), | |
| 1363 | SD_BUS_RESULT("ay", id), | |
| 1364 | method_get_image_machine_id, | |
| 1365 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1366 | SD_BUS_METHOD_WITH_ARGS("GetImageMachineInfo", | |
| 1367 | SD_BUS_ARGS("s", name), | |
| 1368 | SD_BUS_RESULT("a{ss}", machine_info), | |
| 1369 | method_get_image_machine_info, | |
| 1370 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1371 | SD_BUS_METHOD_WITH_ARGS("GetImageOSRelease", | |
| 1372 | SD_BUS_ARGS("s", name), | |
| 1373 | SD_BUS_RESULT("a{ss}", os_release), | |
| 1374 | method_get_image_os_release, | |
| 1375 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1376 | SD_BUS_METHOD_WITH_ARGS("SetPoolLimit", | |
| 1377 | SD_BUS_ARGS("t", size), | |
| 1378 | SD_BUS_NO_RESULT, | |
| 1379 | method_set_pool_limit, | |
| 1380 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1381 | SD_BUS_METHOD_WITH_ARGS("SetImageLimit", | |
| 1382 | SD_BUS_ARGS("s", name, "t", size), | |
| 1383 | SD_BUS_NO_RESULT, | |
| 1384 | method_set_image_limit, | |
| 1385 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1386 | SD_BUS_METHOD_WITH_ARGS("CleanPool", | |
| 1387 | SD_BUS_ARGS("s", mode), | |
| 1388 | SD_BUS_RESULT("a(st)",images), | |
| 1389 | method_clean_pool, | |
| 1390 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1391 | SD_BUS_METHOD_WITH_ARGS("MapFromMachineUser", | |
| 1392 | SD_BUS_ARGS("s", name, "u", uid_inner), | |
| 1393 | SD_BUS_RESULT("u", uid_outer), | |
| 1394 | method_map_from_machine_user, | |
| 1395 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1396 | SD_BUS_METHOD_WITH_ARGS("MapToMachineUser", | |
| 1397 | SD_BUS_ARGS("u", uid_outer), | |
| 1398 | SD_BUS_RESULT("s", machine_name, "o", machine_path, "u", uid_inner), | |
| 1399 | method_map_to_machine_user, | |
| 1400 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1401 | SD_BUS_METHOD_WITH_ARGS("MapFromMachineGroup", | |
| 1402 | SD_BUS_ARGS("s", name, "u", gid_inner), | |
| 1403 | SD_BUS_RESULT("u", gid_outer), | |
| 1404 | method_map_from_machine_group, | |
| 1405 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1406 | SD_BUS_METHOD_WITH_ARGS("MapToMachineGroup", | |
| 1407 | SD_BUS_ARGS("u", gid_outer), | |
| 1408 | SD_BUS_RESULT("s", machine_name, "o", machine_path, "u", gid_inner), | |
| 1409 | method_map_to_machine_group, | |
| 1410 | SD_BUS_VTABLE_UNPRIVILEGED), | |
| 1411 | ||
| 1412 | SD_BUS_SIGNAL_WITH_ARGS("MachineNew", | |
| 1413 | SD_BUS_ARGS("s", machine, "o", path), | |
| 1414 | 0), | |
| 1415 | SD_BUS_SIGNAL_WITH_ARGS("MachineRemoved", | |
| 1416 | SD_BUS_ARGS("s", machine, "o", path), | |
| 1417 | 0), | |
| bbe17ca1 | 1418 | |
| c3350683 LP |
1419 | SD_BUS_VTABLE_END |
| 1420 | }; | |
| 1ee306e1 | 1421 | |
| 4faa530c ZJS |
1422 | const BusObjectImplementation manager_object = { |
| 1423 | "/org/freedesktop/machine1", | |
| 1424 | "org.freedesktop.machine1.Manager", | |
| 1425 | .vtables = BUS_VTABLES(manager_vtable), | |
| 1426 | .children = BUS_IMPLEMENTATIONS( &machine_object, | |
| 1427 | &image_object ), | |
| 1428 | }; | |
| 1429 | ||
| 19070062 | 1430 | int match_job_removed(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| c3350683 | 1431 | const char *path, *result, *unit; |
| 99534007 | 1432 | Manager *m = ASSERT_PTR(userdata); |
| c3350683 LP |
1433 | Machine *machine; |
| 1434 | uint32_t id; | |
| 1435 | int r; | |
| 1ee306e1 | 1436 | |
| 1ee306e1 LP |
1437 | assert(message); |
| 1438 | ||
| c3350683 LP |
1439 | r = sd_bus_message_read(message, "uoss", &id, &path, &unit, &result); |
| 1440 | if (r < 0) { | |
| ebcf1f97 | 1441 | bus_log_parse_error(r); |
| 65d73cf0 | 1442 | return 0; |
| c3350683 | 1443 | } |
| 6797c324 | 1444 | |
| 85ab917b | 1445 | machine = hashmap_get(m->machines_by_unit, unit); |
| c3350683 LP |
1446 | if (!machine) |
| 1447 | return 0; | |
| 6797c324 | 1448 | |
| c3350683 | 1449 | if (streq_ptr(path, machine->scope_job)) { |
| 491ac9f2 | 1450 | machine->scope_job = mfree(machine->scope_job); |
| 6797c324 | 1451 | |
| c3350683 LP |
1452 | if (machine->started) { |
| 1453 | if (streq(result, "done")) | |
| 1454 | machine_send_create_reply(machine, NULL); | |
| 1455 | else { | |
| 4afd3348 | 1456 | _cleanup_(sd_bus_error_free) sd_bus_error e = SD_BUS_ERROR_NULL; |
| 6797c324 | 1457 | |
| ebcf1f97 | 1458 | sd_bus_error_setf(&e, BUS_ERROR_JOB_FAILED, "Start job for unit %s failed with '%s'", unit, result); |
| 6797c324 | 1459 | |
| ebcf1f97 | 1460 | machine_send_create_reply(machine, &e); |
| c3350683 | 1461 | } |
| 49f3fffd LP |
1462 | } |
| 1463 | ||
| 1464 | machine_save(machine); | |
| 1ee306e1 LP |
1465 | } |
| 1466 | ||
| c3350683 LP |
1467 | machine_add_to_gc_queue(machine); |
| 1468 | return 0; | |
| 1ee306e1 LP |
1469 | } |
| 1470 | ||
| 19070062 | 1471 | int match_properties_changed(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| c3350683 | 1472 | _cleanup_free_ char *unit = NULL; |
| 49f3fffd | 1473 | const char *path; |
| 99534007 | 1474 | Manager *m = ASSERT_PTR(userdata); |
| c3350683 | 1475 | Machine *machine; |
| ebcf1f97 | 1476 | int r; |
| 554604b3 | 1477 | |
| c3350683 | 1478 | assert(message); |
| 554604b3 | 1479 | |
| c3350683 LP |
1480 | path = sd_bus_message_get_path(message); |
| 1481 | if (!path) | |
| 554604b3 | 1482 | return 0; |
| 554604b3 | 1483 | |
| ebcf1f97 | 1484 | r = unit_name_from_dbus_path(path, &unit); |
| e5f5b5b9 LP |
1485 | if (r == -EINVAL) /* not for a unit */ |
| 1486 | return 0; | |
| 9ed794a3 | 1487 | if (r < 0) { |
| 9b420b3c LP |
1488 | log_oom(); |
| 1489 | return 0; | |
| 1490 | } | |
| 554604b3 | 1491 | |
| 85ab917b | 1492 | machine = hashmap_get(m->machines_by_unit, unit); |
| 9b420b3c LP |
1493 | if (!machine) |
| 1494 | return 0; | |
| 1495 | ||
| 9b420b3c | 1496 | machine_add_to_gc_queue(machine); |
| c3350683 LP |
1497 | return 0; |
| 1498 | } | |
| 554604b3 | 1499 | |
| 19070062 | 1500 | int match_unit_removed(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| c3350683 | 1501 | const char *path, *unit; |
| 99534007 | 1502 | Manager *m = ASSERT_PTR(userdata); |
| c3350683 LP |
1503 | Machine *machine; |
| 1504 | int r; | |
| 554604b3 | 1505 | |
| c3350683 | 1506 | assert(message); |
| 554604b3 | 1507 | |
| c3350683 LP |
1508 | r = sd_bus_message_read(message, "so", &unit, &path); |
| 1509 | if (r < 0) { | |
| ebcf1f97 | 1510 | bus_log_parse_error(r); |
| 9b420b3c | 1511 | return 0; |
| 554604b3 LP |
1512 | } |
| 1513 | ||
| 85ab917b | 1514 | machine = hashmap_get(m->machines_by_unit, unit); |
| 9b420b3c LP |
1515 | if (!machine) |
| 1516 | return 0; | |
| 1517 | ||
| 9b420b3c | 1518 | machine_add_to_gc_queue(machine); |
| c3350683 LP |
1519 | return 0; |
| 1520 | } | |
| 554604b3 | 1521 | |
| 19070062 | 1522 | int match_reloading(sd_bus_message *message, void *userdata, sd_bus_error *error) { |
| 99534007 | 1523 | Manager *m = ASSERT_PTR(userdata); |
| a658cafa | 1524 | Machine *machine; |
| c3350683 | 1525 | int b, r; |
| 554604b3 | 1526 | |
| 19070062 | 1527 | assert(message); |
| 554604b3 | 1528 | |
| c3350683 LP |
1529 | r = sd_bus_message_read(message, "b", &b); |
| 1530 | if (r < 0) { | |
| ebcf1f97 | 1531 | bus_log_parse_error(r); |
| 65d73cf0 | 1532 | return 0; |
| 554604b3 | 1533 | } |
| a658cafa LP |
1534 | if (b) |
| 1535 | return 0; | |
| 554604b3 | 1536 | |
| a658cafa LP |
1537 | /* systemd finished reloading, let's recheck all our machines */ |
| 1538 | log_debug("System manager has been reloaded, rechecking machines..."); | |
| 554604b3 | 1539 | |
| 90e74a66 | 1540 | HASHMAP_FOREACH(machine, m->machines) |
| a658cafa | 1541 | machine_add_to_gc_queue(machine); |
| 554604b3 LP |
1542 | |
| 1543 | return 0; | |
| 1544 | } | |
| 1545 | ||
| b92d0b4c LP |
1546 | int manager_unref_unit( |
| 1547 | Manager *m, | |
| 1548 | const char *unit, | |
| 1549 | sd_bus_error *error) { | |
| 1550 | ||
| 1551 | assert(m); | |
| 1552 | assert(unit); | |
| 1553 | ||
| f5fa86f9 | 1554 | return bus_call_method(m->api_bus, bus_systemd_mgr, "UnrefUnit", error, NULL, "s", unit); |
| b92d0b4c LP |
1555 | } |
| 1556 | ||
| c3350683 | 1557 | int manager_stop_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job) { |
| 4afd3348 | 1558 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; |
| 1ee306e1 LP |
1559 | int r; |
| 1560 | ||
| 1561 | assert(manager); | |
| 1562 | assert(unit); | |
| 1563 | ||
| f5fa86f9 | 1564 | r = bus_call_method(manager->api_bus, bus_systemd_mgr, "StopUnit", error, &reply, "ss", unit, "fail"); |
| 1ee306e1 | 1565 | if (r < 0) { |
| 955a6329 ZJS |
1566 | if (sd_bus_error_has_names(error, BUS_ERROR_NO_SUCH_UNIT, |
| 1567 | BUS_ERROR_LOAD_FAILED)) { | |
| 6797c324 LP |
1568 | |
| 1569 | if (job) | |
| 1570 | *job = NULL; | |
| 1571 | ||
| c3350683 | 1572 | sd_bus_error_free(error); |
| 6797c324 LP |
1573 | return 0; |
| 1574 | } | |
| 1575 | ||
| 1ee306e1 LP |
1576 | return r; |
| 1577 | } | |
| 1578 | ||
| 1579 | if (job) { | |
| 1580 | const char *j; | |
| 1581 | char *copy; | |
| 1582 | ||
| c3350683 LP |
1583 | r = sd_bus_message_read(reply, "o", &j); |
| 1584 | if (r < 0) | |
| 1585 | return r; | |
| 1ee306e1 LP |
1586 | |
| 1587 | copy = strdup(j); | |
| 1588 | if (!copy) | |
| 1589 | return -ENOMEM; | |
| 1590 | ||
| 1591 | *job = copy; | |
| 1592 | } | |
| 1593 | ||
| 6797c324 | 1594 | return 1; |
| 1ee306e1 LP |
1595 | } |
| 1596 | ||
| d5feeb37 | 1597 | int manager_kill_unit(Manager *manager, const char *unit, const char *subgroup, int signo, sd_bus_error *reterr_error) { |
| 1ee306e1 LP |
1598 | assert(manager); |
| 1599 | assert(unit); | |
| 1600 | ||
| d5feeb37 | 1601 | if (empty_or_root(subgroup)) |
| f5fa86f9 | 1602 | return bus_call_method(manager->api_bus, bus_systemd_mgr, "KillUnit", reterr_error, NULL, "ssi", unit, "all", signo); |
| d5feeb37 | 1603 | |
| f5fa86f9 | 1604 | return bus_call_method(manager->api_bus, bus_systemd_mgr, "KillUnitSubgroup", reterr_error, NULL, "sssi", unit, "cgroup", subgroup, signo); |
| 1ee306e1 LP |
1605 | } |
| 1606 | ||
| ca02f658 | 1607 | int manager_unit_is_active(Manager *manager, const char *unit, sd_bus_error *reterr_error) { |
| 4afd3348 LP |
1608 | _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; |
| 1609 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; | |
| 1ee306e1 | 1610 | _cleanup_free_ char *path = NULL; |
| 1ee306e1 | 1611 | const char *state; |
| 1ee306e1 LP |
1612 | int r; |
| 1613 | ||
| 1614 | assert(manager); | |
| 1615 | assert(unit); | |
| 1616 | ||
| 1ee306e1 LP |
1617 | path = unit_dbus_path_from_name(unit); |
| 1618 | if (!path) | |
| 1619 | return -ENOMEM; | |
| 1620 | ||
| c3350683 | 1621 | r = sd_bus_get_property( |
| f5fa86f9 | 1622 | manager->api_bus, |
| 1ee306e1 LP |
1623 | "org.freedesktop.systemd1", |
| 1624 | path, | |
| c3350683 LP |
1625 | "org.freedesktop.systemd1.Unit", |
| 1626 | "ActiveState", | |
| 1ee306e1 | 1627 | &error, |
| c3350683 LP |
1628 | &reply, |
| 1629 | "s"); | |
| 1ee306e1 | 1630 | if (r < 0) { |
| ac004f4c | 1631 | if (bus_error_is_connection(&error)) |
| 6797c324 | 1632 | return true; |
| 6797c324 | 1633 | |
| 955a6329 ZJS |
1634 | if (sd_bus_error_has_names(&error, BUS_ERROR_NO_SUCH_UNIT, |
| 1635 | BUS_ERROR_LOAD_FAILED)) | |
| 6797c324 | 1636 | return false; |
| 6797c324 | 1637 | |
| ca02f658 | 1638 | sd_bus_error_move(reterr_error, &error); |
| 1ee306e1 LP |
1639 | return r; |
| 1640 | } | |
| 1641 | ||
| c3350683 LP |
1642 | r = sd_bus_message_read(reply, "s", &state); |
| 1643 | if (r < 0) | |
| 1ee306e1 | 1644 | return -EINVAL; |
| 1ee306e1 | 1645 | |
| 9b420b3c | 1646 | return !STR_IN_SET(state, "inactive", "failed"); |
| 1ee306e1 | 1647 | } |
| bd16acf3 | 1648 | |
| ca02f658 | 1649 | int manager_job_is_active(Manager *manager, const char *path, sd_bus_error *reterr_error) { |
| 4afd3348 LP |
1650 | _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; |
| 1651 | _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; | |
| c3350683 | 1652 | int r; |
| bd16acf3 | 1653 | |
| c3350683 LP |
1654 | assert(manager); |
| 1655 | assert(path); | |
| bd16acf3 | 1656 | |
| c3350683 | 1657 | r = sd_bus_get_property( |
| f5fa86f9 | 1658 | manager->api_bus, |
| c3350683 LP |
1659 | "org.freedesktop.systemd1", |
| 1660 | path, | |
| 1661 | "org.freedesktop.systemd1.Job", | |
| 1662 | "State", | |
| 1663 | &error, | |
| 1664 | &reply, | |
| 1665 | "s"); | |
| 1666 | if (r < 0) { | |
| ac004f4c | 1667 | if (bus_error_is_connection(&error)) |
| c3350683 | 1668 | return true; |
| bd16acf3 | 1669 | |
| c3350683 LP |
1670 | if (sd_bus_error_has_name(&error, SD_BUS_ERROR_UNKNOWN_OBJECT)) |
| 1671 | return false; | |
| bd16acf3 | 1672 | |
| ca02f658 | 1673 | sd_bus_error_move(reterr_error, &error); |
| bd16acf3 | 1674 | return r; |
| c3350683 | 1675 | } |
| bd16acf3 | 1676 | |
| c3350683 LP |
1677 | /* We don't actually care about the state really. The fact |
| 1678 | * that we could read the job state is enough for us */ | |
| bd16acf3 | 1679 | |
| c3350683 | 1680 | return true; |
| bd16acf3 | 1681 | } |