From ecd1414cefd3b945dd6ddadac82600e977198787 Mon Sep 17 00:00:00 2001 From: Simon McVittie <smcv@collabora.com> Date: Wed, 27 Jan 2021 17:46:46 +0000 Subject: [PATCH] pressure-vessel: Share host /etc/hosts, etc., according to a table We take the same action for each of these files, so let's make the code more data-driven. Signed-off-by: Simon McVittie <smcv@collabora.com> --- pressure-vessel/runtime.c | 58 ++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 35 deletions(-) diff --git a/pressure-vessel/runtime.c b/pressure-vessel/runtime.c index f95e369cc..1d1093a67 100644 --- a/pressure-vessel/runtime.c +++ b/pressure-vessel/runtime.c @@ -1660,13 +1660,8 @@ bind_runtime_base (PvRuntime *self, }; static const char * const dont_bind[] = { - "/etc/group", - "/etc/passwd", - "/etc/host.conf", - "/etc/hosts", "/etc/localtime", "/etc/machine-id", - "/etc/resolv.conf", "/var/cache/ldconfig", "/var/lib/dbus", "/var/lib/dhcp", @@ -1674,6 +1669,17 @@ bind_runtime_base (PvRuntime *self, "/var/lib/urandom", NULL }; + static const char * const from_host[] = + { + /* TODO: Synthesize a passwd with only the user and nobody, + * like Flatpak does? */ + "/etc/group", + "/etc/passwd", + "/etc/host.conf", + "/etc/hosts", + "/etc/resolv.conf", + NULL + }; g_autofree gchar *xrd = g_strdup_printf ("/run/user/%ld", (long) geteuid ()); gsize i, j; const gchar *member; @@ -1774,6 +1780,9 @@ bind_runtime_base (PvRuntime *self, if (g_strv_contains (dont_bind, dest)) continue; + if (g_strv_contains (from_host, dest)) + continue; + full = g_build_filename (self->runtime_files, bind_mutable[i], member, @@ -1859,37 +1868,16 @@ bind_runtime_base (PvRuntime *self, NULL); } - if (_srt_file_test_in_sysroot (self->host_in_current_namespace, -1, - "/etc/resolv.conf", G_FILE_TEST_EXISTS)) - flatpak_bwrap_add_args (bwrap, - "--ro-bind", "/etc/resolv.conf", "/etc/resolv.conf", - NULL); - - if (_srt_file_test_in_sysroot (self->host_in_current_namespace, -1, - "/etc/host.conf", G_FILE_TEST_EXISTS)) - flatpak_bwrap_add_args (bwrap, - "--ro-bind", "/etc/host.conf", "/etc/host.conf", - NULL); - - if (_srt_file_test_in_sysroot (self->host_in_current_namespace, -1, - "/etc/hosts", G_FILE_TEST_EXISTS)) - flatpak_bwrap_add_args (bwrap, - "--ro-bind", "/etc/hosts", "/etc/hosts", - NULL); - - /* TODO: Synthesize a passwd with only the user and nobody, - * like Flatpak does? */ - if (_srt_file_test_in_sysroot (self->host_in_current_namespace, -1, - "/etc/passwd", G_FILE_TEST_EXISTS)) - flatpak_bwrap_add_args (bwrap, - "--ro-bind", "/etc/passwd", "/etc/passwd", - NULL); + for (i = 0; from_host[i] != NULL; i++) + { + const char *item = from_host[i]; - if (_srt_file_test_in_sysroot (self->host_in_current_namespace, -1, - "/etc/group", G_FILE_TEST_EXISTS)) - flatpak_bwrap_add_args (bwrap, - "--ro-bind", "/etc/group", "/etc/group", - NULL); + if (_srt_file_test_in_sysroot (self->host_in_current_namespace, -1, + item, G_FILE_TEST_EXISTS)) + flatpak_bwrap_add_args (bwrap, + "--ro-bind", item, item, + NULL); + } return TRUE; } -- GitLab