]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
machine-dbus: use in_same_namespace() at one more place
authorMike Yuan <me@yhndnzj.com>
Sat, 31 Aug 2024 15:16:47 +0000 (17:16 +0200)
committerMike Yuan <me@yhndnzj.com>
Wed, 4 Sep 2024 16:50:55 +0000 (18:50 +0200)
src/machine/machine-dbus.c

index 366be8fbdeb282e659af1582998147ef7daee4e6..49ec710df0e900d6b961e714b6b08894eedc9d8f 100644 (file)
@@ -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,