From c1bf6f148edd9a56087c894bb3bc63b71ac9a912 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Sat, 31 Aug 2024 17:16:47 +0200 Subject: [PATCH] machine-dbus: use in_same_namespace() at one more place --- src/machine/machine-dbus.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/machine/machine-dbus.c b/src/machine/machine-dbus.c index 366be8fbdeb..49ec710df0e 100644 --- a/src/machine/machine-dbus.c +++ b/src/machine/machine-dbus.c @@ -215,21 +215,13 @@ int bus_machine_method_get_addresses(sd_bus_message *message, void *userdata, sd case MACHINE_CONTAINER: { _cleanup_close_pair_ int pair[2] = EBADF_PAIR; - _cleanup_free_ char *us = NULL, *them = NULL; _cleanup_close_ int netns_fd = -EBADF; - const char *p; pid_t child; - r = readlink_malloc("/proc/self/ns/net", &us); + r = in_same_namespace(0, m->leader.pid, NAMESPACE_NET); if (r < 0) return r; - - p = procfs_file_alloca(m->leader.pid, "ns/net"); - r = readlink_malloc(p, &them); - if (r < 0) - return r; - - if (streq(us, them)) + if (r > 0) return sd_bus_error_setf(error, BUS_ERROR_NO_PRIVATE_NETWORKING, "Machine %s does not use private networking", m->name); r = pidref_namespace_open(&m->leader, -- 2.47.3