Commit d3d86110 authored by Thomas Haller's avatar Thomas Haller

secret-agent: merge branch 'th/secret-agent-cleanup'

https://github.com/NetworkManager/NetworkManager/pull/288
parents 9f558e4d 472f89da
Pipeline #17640 passed with stages
in 16 minutes and 49 seconds
......@@ -149,7 +149,7 @@ do_agent_secret (NmCli *nmc, int argc, char **argv)
/* We keep running */
nmc->should_wait++;
nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (nmc->secret_agent), NULL);
nm_secret_agent_simple_enable (nmc->secret_agent, NULL);
g_signal_connect (nmc->secret_agent,
NM_SECRET_AGENT_SIMPLE_REQUEST_SECRETS,
G_CALLBACK (secrets_requested),
......
......@@ -778,7 +778,7 @@ nmc_secrets_requested (NMSecretAgentSimple *agent,
/* Unregister our secret agent on failure, so that another agent
* may be tried */
if (nmc->secret_agent) {
nm_secret_agent_old_unregister (nmc->secret_agent, NULL, NULL);
nm_secret_agent_old_unregister (NM_SECRET_AGENT_OLD (nmc->secret_agent), NULL, NULL);
g_clear_object (&nmc->secret_agent);
}
}
......
......@@ -2474,7 +2474,7 @@ check_activated (ActivateConnectionInfo *info)
if (nmc->secret_agent) {
NMRemoteConnection *connection = nm_active_connection_get_connection (info->active);
nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (nmc->secret_agent),
nm_secret_agent_simple_enable (nmc->secret_agent,
nm_connection_get_path (NM_CONNECTION (connection)));
}
break;
......@@ -2776,7 +2776,6 @@ nmc_activate_connection (NmCli *nmc,
g_hash_table_destroy (nmc->pwds_hash);
nmc->pwds_hash = pwds_hash;
/* Create secret agent */
nmc->secret_agent = nm_secret_agent_simple_new ("nmcli-connect");
if (nmc->secret_agent) {
g_signal_connect (nmc->secret_agent,
......@@ -6728,7 +6727,7 @@ progress_activation_editor_cb (gpointer user_data)
NMRemoteConnection *connection;
connection = nm_active_connection_get_connection (ac);
nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (info->nmc->secret_agent),
nm_secret_agent_simple_enable (info->nmc->secret_agent,
nm_object_get_path (NM_OBJECT (connection)));
}
......
......@@ -1961,7 +1961,7 @@ connect_device_cb (GObject *client, GAsyncResult *result, gpointer user_data)
if (nmc->secret_agent) {
NMRemoteConnection *connection = nm_active_connection_get_connection (active);
nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (nmc->secret_agent),
nm_secret_agent_simple_enable (nmc->secret_agent,
nm_connection_get_path (NM_CONNECTION (connection)));
}
......
......@@ -1013,15 +1013,15 @@ nmc_cleanup (NmCli *nmc)
g_clear_object (&nmc->client);
g_string_free (nmc->return_text, TRUE);
if (nmc->return_text)
g_string_free (g_steal_pointer (&nmc->return_text), TRUE);
if (nmc->secret_agent) {
/* Destroy secret agent if we have one. */
nm_secret_agent_old_unregister (nmc->secret_agent, NULL, NULL);
g_object_unref (nmc->secret_agent);
nm_secret_agent_old_unregister (NM_SECRET_AGENT_OLD (nmc->secret_agent), NULL, NULL);
g_clear_object (&nmc->secret_agent);
}
if (nmc->pwds_hash)
g_hash_table_destroy (nmc->pwds_hash);
nm_clear_pointer (&nmc->pwds_hash, g_hash_table_destroy);
nm_clear_g_free (&nmc->required_fields);
......
......@@ -20,7 +20,7 @@
#ifndef NMC_NMCLI_H
#define NMC_NMCLI_H
#include "nm-secret-agent-old.h"
#include "nm-secret-agent-simple.h"
#include "nm-meta-setting-desc.h"
struct _NMPolkitListener;
......@@ -129,7 +129,7 @@ typedef struct _NmCli {
int timeout; /* Operation timeout */
NMSecretAgentOld *secret_agent; /* Secret agent */
NMSecretAgentSimple *secret_agent; /* Secret agent */
GHashTable *pwds_hash; /* Hash table with passwords in passwd-file */
struct _NMPolkitListener *pk_listener; /* polkit agent listener */
......
This diff is collapsed.
......@@ -21,26 +21,6 @@
#include "nm-secret-agent-old.h"
#define NM_TYPE_SECRET_AGENT_SIMPLE (nm_secret_agent_simple_get_type ())
#define NM_SECRET_AGENT_SIMPLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SECRET_AGENT_SIMPLE, NMSecretAgentSimple))
#define NM_SECRET_AGENT_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SECRET_AGENT_SIMPLE, NMSecretAgentSimpleClass))
#define NM_IS_SECRET_AGENT_SIMPLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SECRET_AGENT_SIMPLE))
#define NM_IS_SECRET_AGENT_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SECRET_AGENT_SIMPLE))
#define NM_SECRET_AGENT_SIMPLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SECRET_AGENT_SIMPLE, NMSecretAgentSimpleClass))
/* Signals */
#define NM_SECRET_AGENT_SIMPLE_REQUEST_SECRETS "request-secrets"
typedef struct {
NMSecretAgentOld parent;
} NMSecretAgentSimple;
typedef struct {
NMSecretAgentOldClass parent;
} NMSecretAgentSimpleClass;
typedef enum {
NM_SECRET_AGENT_SECRET_TYPE_PROPERTY,
NM_SECRET_AGENT_SECRET_TYPE_SECRET,
......@@ -60,9 +40,23 @@ typedef struct {
#define NM_SECRET_AGENT_VPN_TYPE_OPENCONNECT NM_DBUS_INTERFACE".openconnect"
/*****************************************************************************/
#define NM_TYPE_SECRET_AGENT_SIMPLE (nm_secret_agent_simple_get_type ())
#define NM_SECRET_AGENT_SIMPLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SECRET_AGENT_SIMPLE, NMSecretAgentSimple))
#define NM_SECRET_AGENT_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SECRET_AGENT_SIMPLE, NMSecretAgentSimpleClass))
#define NM_IS_SECRET_AGENT_SIMPLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SECRET_AGENT_SIMPLE))
#define NM_IS_SECRET_AGENT_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SECRET_AGENT_SIMPLE))
#define NM_SECRET_AGENT_SIMPLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SECRET_AGENT_SIMPLE, NMSecretAgentSimpleClass))
#define NM_SECRET_AGENT_SIMPLE_REQUEST_SECRETS "request-secrets"
typedef struct _NMSecretAgentSimple NMSecretAgentSimple;
typedef struct _NMSecretAgentSimpleClass NMSecretAgentSimpleClass;
GType nm_secret_agent_simple_get_type (void);
NMSecretAgentOld *nm_secret_agent_simple_new (const char *name);
NMSecretAgentSimple *nm_secret_agent_simple_new (const char *name);
void nm_secret_agent_simple_response (NMSecretAgentSimple *self,
const char *request_id,
......
......@@ -240,7 +240,7 @@ activate_connection (NMConnection *connection,
NMObject *specific_object)
{
NmtNewtForm *form;
gs_unref_object NMSecretAgentOld *agent = NULL;
gs_unref_object NMSecretAgentSimple *agent = NULL;
NmtNewtWidget *label;
NmtSyncOp op;
const char *specific_object_path;
......@@ -257,7 +257,7 @@ activate_connection (NMConnection *connection,
agent = nm_secret_agent_simple_new ("nmtui");
if (agent) {
if (connection) {
nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (agent),
nm_secret_agent_simple_enable (agent,
nm_object_get_path (NM_OBJECT (connection)));
}
g_signal_connect (agent,
......@@ -303,7 +303,7 @@ activate_connection (NMConnection *connection,
if (agent && !connection) {
connection = NM_CONNECTION (nm_active_connection_get_connection (ac));
if (connection) {
nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (agent),
nm_secret_agent_simple_enable (agent,
nm_object_get_path (NM_OBJECT (connection)));
}
}
......@@ -341,7 +341,7 @@ activate_connection (NMConnection *connection,
g_object_unref (form);
if (agent)
nm_secret_agent_old_unregister (agent, NULL, NULL);
nm_secret_agent_old_unregister (NM_SECRET_AGENT_OLD (agent), NULL, NULL);
}
static void
......
This diff is collapsed.
......@@ -1149,6 +1149,28 @@ nm_clear_g_cancellable (GCancellable **cancellable)
return FALSE;
}
/* If @cancellable_id is not 0, clear it and call g_cancellable_disconnect().
* @cancellable may be %NULL, if there is nothing to disconnect.
*
* It's like nm_clear_g_signal_handler(), except that it uses g_cancellable_disconnect()
* instead of g_signal_handler_disconnect().
*
* Note the warning in glib documentation about dead-lock and what g_cancellable_disconnect()
* actually does. */
static inline gboolean
nm_clear_g_cancellable_disconnect (GCancellable *cancellable, gulong *cancellable_id)
{
gulong id;
if ( cancellable_id
&& (id = *cancellable_id) != 0) {
*cancellable_id = 0;
g_cancellable_disconnect (cancellable, id);
return TRUE;
}
return FALSE;
}
/*****************************************************************************/
static inline GVariant *
......
......@@ -1380,7 +1380,7 @@ wifi_secrets_get_one (NMDeviceIwd *self,
TRUE,
setting_name,
flags,
setting_key,
NM_MAKE_STRV (setting_key),
wifi_secrets_cb,
nm_utils_user_data_pack (self, invocation));
}
......@@ -1894,7 +1894,7 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason)
TRUE,
NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION,
"psk",
NM_MAKE_STRV (NM_SETTING_WIRELESS_SECURITY_PSK),
act_psk_cb,
self);
nm_device_state_changed (device, NM_DEVICE_STATE_NEED_AUTH, NM_DEVICE_STATE_REASON_NONE);
......
......@@ -948,7 +948,7 @@ nm_modem_get_secrets (NMModem *self,
FALSE,
setting_name,
flags,
hint,
NM_MAKE_STRV (hint),
modem_secrets_cb,
self);
g_return_if_fail (priv->secrets_id);
......@@ -986,8 +986,7 @@ nm_modem_act_stage1_prepare (NMModem *self,
setting_name = nm_connection_need_secrets (connection, &hints);
if (!setting_name) {
/* Ready to connect */
g_assert (!hints);
nm_assert (!hints);
return NM_MODEM_GET_CLASS (self)->act_stage1_prepare (self, connection, out_failure_reason);
}
......@@ -995,11 +994,14 @@ nm_modem_act_stage1_prepare (NMModem *self,
if (priv->secrets_tries++)
flags |= NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW;
if (hints)
g_ptr_array_add (hints, NULL);
priv->secrets_id = nm_act_request_get_secrets (req,
FALSE,
setting_name,
flags,
hints ? g_ptr_array_index (hints, 0) : NULL,
hints ? (const char *const*) hints->pdata : NULL,
modem_secrets_cb,
self);
g_return_val_if_fail (priv->secrets_id, NM_ACT_STAGE_RETURN_FAILURE);
......
......@@ -166,7 +166,7 @@ nm_act_request_get_secrets (NMActRequest *self,
gboolean ref_self,
const char *setting_name,
NMSecretAgentGetSecretsFlags flags,
const char *hint,
const char *const*hints,
NMActRequestSecretsFunc callback,
gpointer callback_data)
{
......@@ -175,7 +175,6 @@ nm_act_request_get_secrets (NMActRequest *self,
NMSettingsConnectionCallId *call_id_s;
NMSettingsConnection *settings_connection;
NMConnection *applied_connection;
const char *hints[2] = { hint, NULL };
g_return_val_if_fail (NM_IS_ACT_REQUEST (self), NULL);
......
......@@ -69,7 +69,7 @@ NMActRequestGetSecretsCallId *nm_act_request_get_secrets (NMActRequest *req,
gboolean take_ref,
const char *setting_name,
NMSecretAgentGetSecretsFlags flags,
const char *hint,
const char *const*hints,
NMActRequestSecretsFunc callback,
gpointer callback_data);
......
......@@ -363,7 +363,7 @@ impl_ppp_manager_need_secrets (NMDBusObject *obj,
const char *username = NULL;
const char *password = NULL;
guint32 tries;
GPtrArray *hints = NULL;
gs_unref_ptrarray GPtrArray *hints = NULL;
GError *error = NULL;
NMSecretAgentGetSecretsFlags flags = NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION;
......@@ -393,18 +393,18 @@ impl_ppp_manager_need_secrets (NMDBusObject *obj,
if (tries > 1)
flags |= NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW;
if (hints)
g_ptr_array_add (hints, NULL);
priv->secrets_id = nm_act_request_get_secrets (priv->act_req,
FALSE,
priv->secrets_setting_name,
flags,
hints ? g_ptr_array_index (hints, 0) : NULL,
hints ? (const char *const*) hints->pdata : NULL,
ppp_secrets_cb,
self);
g_object_set_qdata (G_OBJECT (applied_connection), ppp_manager_secret_tries_quark (), GUINT_TO_POINTER (++tries));
priv->pending_secrets_context = invocation;
if (hints)
g_ptr_array_free (hints, TRUE);
}
static void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment