From f5ce680ee6bfb275c7988e0451473c488429e061 Mon Sep 17 00:00:00 2001 From: Damien Dejean Date: Thu, 28 Jul 2022 08:19:18 +0000 Subject: [PATCH] D-Bus: Hotspot 2.0 credentials with multiple domains Add the support of multiple domains for interworking credentials in D-Bus API AddCred() using an array of strings. Signed-off-by: Damien Dejean --- tests/hwsim/test_dbus.py | 4 ++- wpa_supplicant/dbus/dbus_new_handlers.c | 34 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/tests/hwsim/test_dbus.py b/tests/hwsim/test_dbus.py index adff78faf..a61211fe1 100644 --- a/tests/hwsim/test_dbus.py +++ b/tests/hwsim/test_dbus.py @@ -6102,7 +6102,7 @@ def test_dbus_creds(dev, apdev): (bus, wpas_obj, path, if_obj) = prepare_dbus(dev[0]) iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE) - args = {'domain': 'server.w1.fi', + args = {'domain': ['server.w1.fi','server2.w1.fi'], 'realm': 'server.w1.fi', 'home_ois': '50a9bf', 'required_home_ois': '23bf50', @@ -6118,6 +6118,8 @@ def test_dbus_creds(dev, apdev): if k == 'password': continue prop = dev[0].get_cred(0, k) + if isinstance(v, list): + v = '\n'.join(v) if prop != v: raise Exception('Credential add failed: %s does not match %s' % (prop, v)) diff --git a/wpa_supplicant/dbus/dbus_new_handlers.c b/wpa_supplicant/dbus/dbus_new_handlers.c index e63e2209e..a8146dd08 100644 --- a/wpa_supplicant/dbus/dbus_new_handlers.c +++ b/wpa_supplicant/dbus/dbus_new_handlers.c @@ -412,6 +412,40 @@ static dbus_bool_t set_cred_properties(struct wpa_supplicant *wpa_s, entry.int32_value); if (os_snprintf_error(size, ret)) goto error; + } else if (entry.type == DBUS_TYPE_ARRAY && + entry.array_type == DBUS_TYPE_STRING) { + dbus_uint32_t i; + + if (entry.array_len <= 0) + goto error; + + for (i = 0; i < entry.array_len; i++) { + if (should_quote_opt(entry.key)) { + size = os_strlen(entry.strarray_value[i]); + + size += 3; + value = os_zalloc(size); + if (!value) + goto error; + + ret = os_snprintf(value, size, "\"%s\"", + entry.strarray_value[i]); + if (os_snprintf_error(size, ret)) + goto error; + } else { + value = os_strdup(entry.strarray_value[i]); + if (!value) + goto error; + } + + ret = wpa_config_set_cred(cred, entry.key, value, 0); + if (ret < 0) + goto error; + os_free(value); + value = NULL; + } + wpa_dbus_dict_entry_clear(&entry); + continue; } else { goto error; }