iwd: Handle the net.connman.iwd.Agent.Cancel() method

Implement a Cancel method on our IWD secrets agent DBus object.  This
results in a call to nm_device_iwd_agent_query() for the device
currently handling the request and the @invocation parameter is NULL to
signal that the current query is being cancelled.

nm_device_iwd_agent_query doesn't do much with this call just yet but
the handling will be necessary when IWD autoconnect is used by NM.
This commit is contained in:
Andrew Zaborowski 2020-10-22 15:59:04 +02:00 committed by Thomas Haller
parent adaeb7a872
commit 7d9b37feaf
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
2 changed files with 61 additions and 4 deletions

View file

@ -2607,6 +2607,23 @@ nm_device_iwd_agent_query(NMDeviceIwd *self, GDBusMethodInvocation *invocation)
NMSecretAgentGetSecretsFlags get_secret_flags =
NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION;
if (!invocation) {
NMActRequest *act_req = nm_device_get_act_request(device);
if (!act_req)
return FALSE;
wifi_secrets_cancel(self);
if (nm_device_get_state(device) == NM_DEVICE_STATE_NEED_AUTH)
nm_device_state_changed(device, NM_DEVICE_STATE_CONFIG, NM_DEVICE_STATE_REASON_NONE);
/* The secrets request is being cancelled. Let the Network.Connect
* method call's callback handle the failure.
*/
return TRUE;
}
req = nm_device_get_act_request(device);
if (!req || nm_device_get_state(device) != NM_DEVICE_STATE_CONFIG) {
_LOGI(LOGD_WIFI, "IWD asked for secrets without explicit connect request");

View file

@ -39,6 +39,7 @@ typedef struct {
guint agent_id;
char * agent_path;
GHashTable * known_networks;
NMDeviceIwd * last_agent_call_device;
} NMIwdManagerPrivate;
struct _NMIwdManager {
@ -178,6 +179,25 @@ agent_dbus_method_cb(GDBusConnection * connection,
if (!nm_streq0(name_owner, sender))
goto return_error;
if (!strcmp(method_name, "Cancel")) {
const char *reason = NULL;
g_variant_get(parameters, "(&s)", &reason);
_LOGD("agent-request: Cancel reason: %s", reason);
if (!priv->last_agent_call_device)
goto return_error;
if (nm_device_iwd_agent_query(priv->last_agent_call_device, NULL)) {
priv->last_agent_call_device = NULL;
g_dbus_method_invocation_return_value(invocation, NULL);
return;
}
priv->last_agent_call_device = NULL;
goto return_error;
}
if (!strcmp(method_name, "RequestUserPassword"))
g_variant_get(parameters, "(&os)", &network_path, NULL);
else
@ -197,8 +217,10 @@ agent_dbus_method_cb(GDBusConnection * connection,
goto return_error;
}
if (nm_device_iwd_agent_query(device, invocation))
if (nm_device_iwd_agent_query(device, invocation)) {
priv->last_agent_call_device = device;
return;
}
_LOGD("agent-request: device %s did not handle the IWD Agent request",
nm_device_get_iface(NM_DEVICE(device)));
@ -229,10 +251,12 @@ static const GDBusInterfaceInfo iwd_agent_iface_info = NM_DEFINE_GDBUS_INTERFACE
NM_DEFINE_GDBUS_ARG_INFO("password", "s"), ), ),
NM_DEFINE_GDBUS_METHOD_INFO(
"RequestUserPassword",
.in_args = NM_DEFINE_GDBUS_ARG_INFOS(NM_DEFINE_GDBUS_ARG_INFO("network", "o"),
.in_args = NM_DEFINE_GDBUS_ARG_INFOS(NM_DEFINE_GDBUS_ARG_INFO("network", "o"),
NM_DEFINE_GDBUS_ARG_INFO("user", "s"), ),
.out_args =
NM_DEFINE_GDBUS_ARG_INFOS(NM_DEFINE_GDBUS_ARG_INFO("password", "s"), ), ), ), );
.out_args = NM_DEFINE_GDBUS_ARG_INFOS(NM_DEFINE_GDBUS_ARG_INFO("password", "s"), ), ),
NM_DEFINE_GDBUS_METHOD_INFO("Cancel",
.in_args = NM_DEFINE_GDBUS_ARG_INFOS(
NM_DEFINE_GDBUS_ARG_INFO("reason", "s"), ), ), ), );
static guint
iwd_agent_export(GDBusConnection *connection, gpointer user_data, char **agent_path, GError **error)
@ -839,6 +863,19 @@ device_added(NMManager *manager, NMDevice *device, gpointer user_data)
g_list_free_full(objects, g_object_unref);
}
static void
device_removed(NMManager *manager, NMDevice *device, gpointer user_data)
{
NMIwdManager * self = user_data;
NMIwdManagerPrivate *priv = NM_IWD_MANAGER_GET_PRIVATE(self);
if (!NM_IS_DEVICE_IWD(device))
return;
if (priv->last_agent_call_device == NM_DEVICE_IWD(device))
priv->last_agent_call_device = NULL;
}
static void
got_object_manager(GObject *object, GAsyncResult *result, gpointer user_data)
{
@ -955,6 +992,7 @@ nm_iwd_manager_init(NMIwdManager *self)
priv->manager = g_object_ref(NM_MANAGER_GET);
g_signal_connect(priv->manager, NM_MANAGER_DEVICE_ADDED, G_CALLBACK(device_added), self);
g_signal_connect(priv->manager, NM_MANAGER_DEVICE_REMOVED, G_CALLBACK(device_removed), self);
priv->settings = g_object_ref(NM_SETTINGS_GET);
g_signal_connect(priv->settings,
@ -997,6 +1035,8 @@ dispose(GObject *object)
g_clear_object(&priv->manager);
}
priv->last_agent_call_device = NULL;
G_OBJECT_CLASS(nm_iwd_manager_parent_class)->dispose(object);
}