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:
Michael Catanzaro
2019-06-11 22:35:19 -05:00
parent d2450c8124
commit fc597fa5f9
3 changed files with 20 additions and 10 deletions

View File

@@ -127,12 +127,14 @@ is_valid_unix (const gchar *address_entry,
GList *keys;
GList *l;
const gchar *path;
const gchar *dir;
const gchar *tmpdir;
const gchar *abstract;
ret = FALSE;
keys = NULL;
path = NULL;
dir = NULL;
tmpdir = NULL;
abstract = NULL;
@@ -142,6 +144,8 @@ is_valid_unix (const gchar *address_entry,
const gchar *key = l->data;
if (g_strcmp0 (key, "path") == 0)
path = g_hash_table_lookup (key_value_pairs, key);
else if (g_strcmp0 (key, "dir") == 0)
dir = g_hash_table_lookup (key_value_pairs, key);
else if (g_strcmp0 (key, "tmpdir") == 0)
tmpdir = g_hash_table_lookup (key_value_pairs, key);
else if (g_strcmp0 (key, "abstract") == 0)
@@ -158,9 +162,8 @@ is_valid_unix (const gchar *address_entry,
}
}
if ((path != NULL && tmpdir != NULL) ||
(tmpdir != NULL && abstract != NULL) ||
(abstract != NULL && path != NULL))
/* Exactly one key must be set */
if ((path != NULL) + (dir != NULL) + (tmpdir != NULL) + (abstract != NULL) > 1)
{
g_set_error (error,
G_IO_ERROR,
@@ -169,12 +172,12 @@ is_valid_unix (const gchar *address_entry,
address_entry);
goto out;
}
else if (path == NULL && tmpdir == NULL && abstract == NULL)
else if (path == NULL && dir == NULL && tmpdir == NULL && abstract == NULL)
{
g_set_error (error,
G_IO_ERROR,
G_IO_ERROR_INVALID_ARGUMENT,
_("Address “%s” is invalid (need exactly one of path, tmpdir or abstract keys)"),
_("Address “%s” is invalid (need exactly one of path, dir, tmpdir, or abstract keys)"),
address_entry);
goto out;
}