mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-01 23:13:40 +02:00
gdbus: support unix:dir= addresses
unix:dir= addresses are exactly the same as unix:tmpdir= addresses, already supported by GDBus, except they forbid use of abstract sockets. This is convenient for situations where abstract sockets are impermissible, such as when a D-Bus client inside a network namespace needs to connect to a server running in a different network namespace. An abstract socket cannot be shared between two processes in different network namespaces. Applications could use unix:path= addresses instead, so this is only a convenience, but there's no good reason not to support unix:dir=. Currently it is not supported simply because unix:dir= is a relatively recent addition to the D-Bus spec.
This commit is contained in:
@@ -641,7 +641,7 @@ random_ascii (void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* note that address_entry has already been validated => exactly one of path, tmpdir or abstract keys are set */
|
||||
/* note that address_entry has already been validated => exactly one of path, dir, tmpdir, or abstract keys are set */
|
||||
static gboolean
|
||||
try_unix (GDBusServer *server,
|
||||
const gchar *address_entry,
|
||||
@@ -650,6 +650,7 @@ try_unix (GDBusServer *server,
|
||||
{
|
||||
gboolean ret;
|
||||
const gchar *path;
|
||||
const gchar *dir;
|
||||
const gchar *tmpdir;
|
||||
const gchar *abstract;
|
||||
GSocketAddress *address;
|
||||
@@ -658,6 +659,7 @@ try_unix (GDBusServer *server,
|
||||
address = NULL;
|
||||
|
||||
path = g_hash_table_lookup (key_value_pairs, "path");
|
||||
dir = g_hash_table_lookup (key_value_pairs, "dir");
|
||||
tmpdir = g_hash_table_lookup (key_value_pairs, "tmpdir");
|
||||
abstract = g_hash_table_lookup (key_value_pairs, "abstract");
|
||||
|
||||
@@ -665,20 +667,21 @@ try_unix (GDBusServer *server,
|
||||
{
|
||||
address = g_unix_socket_address_new (path);
|
||||
}
|
||||
else if (tmpdir != NULL)
|
||||
else if (dir != NULL || tmpdir != NULL)
|
||||
{
|
||||
gint n;
|
||||
GString *s;
|
||||
GError *local_error;
|
||||
|
||||
retry:
|
||||
s = g_string_new (tmpdir);
|
||||
s = g_string_new (tmpdir != NULL ? tmpdir : dir);
|
||||
g_string_append (s, "/dbus-");
|
||||
for (n = 0; n < 8; n++)
|
||||
g_string_append_c (s, random_ascii ());
|
||||
|
||||
/* prefer abstract namespace if available */
|
||||
if (g_unix_socket_address_abstract_names_supported ())
|
||||
/* prefer abstract namespace if available for tmpdir: addresses
|
||||
* abstract namespace is disallowed for dir: addresses */
|
||||
if (tmpdir != NULL && g_unix_socket_address_abstract_names_supported ())
|
||||
address = g_unix_socket_address_new_with_type (s->str,
|
||||
-1,
|
||||
G_UNIX_SOCKET_ADDRESS_ABSTRACT);
|
||||
|
Reference in New Issue
Block a user