From 68ab26143bdf89f52332c268ef912aa7d9e269bb Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 18 Jan 2011 14:57:44 -0600 Subject: [PATCH] core: use GetSecrets flags everywhere --- src/modem-manager/nm-modem.c | 11 +++++++++-- src/nm-activation-request.c | 4 ++-- src/nm-activation-request.h | 2 +- src/nm-agent-manager.c | 16 ++++++++-------- src/nm-agent-manager.h | 4 ++-- src/nm-device-ethernet.c | 10 ++++++---- src/nm-device-wifi.c | 10 ++++++---- src/nm-secret-agent.c | 4 ++-- src/nm-secret-agent.h | 13 +++++++++++-- src/ppp-manager/nm-ppp-manager.c | 14 +++++++++----- src/vpn-manager/nm-vpn-connection.c | 2 +- 11 files changed, 57 insertions(+), 33 deletions(-) diff --git a/src/modem-manager/nm-modem.c b/src/modem-manager/nm-modem.c index 1e8d7941d1..30817f9322 100644 --- a/src/modem-manager/nm-modem.c +++ b/src/modem-manager/nm-modem.c @@ -516,13 +516,16 @@ nm_modem_get_secrets (NMModem *self, const char *hint) { NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (self); + guint32 flags = NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION; cancel_get_secrets (self); + if (request_new) + flags |= NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW; priv->secrets_id = nm_act_request_get_secrets (priv->act_request, NULL, setting_name, - request_new, + flags, hint, modem_secrets_cb, self); @@ -552,6 +555,7 @@ nm_modem_act_stage1_prepare (NMModem *self, NMActStageReturn ret; GPtrArray *hints = NULL; const char *setting_name = NULL; + guint32 flags = NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION; if (priv->act_request) g_object_unref (priv->act_request); @@ -563,10 +567,13 @@ nm_modem_act_stage1_prepare (NMModem *self, &setting_name, reason); if ((ret == NM_ACT_STAGE_RETURN_POSTPONE) && setting_name) { + if (priv->secrets_tries++) + flags |= NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW; + priv->secrets_id = nm_act_request_get_secrets (req, NULL, setting_name, - priv->secrets_tries++ ? TRUE : FALSE, + flags, hints ? g_ptr_array_index (hints, 0) : NULL, modem_secrets_cb, self); diff --git a/src/nm-activation-request.c b/src/nm-activation-request.c index dbc65b4d4a..4192b9d8a3 100644 --- a/src/nm-activation-request.c +++ b/src/nm-activation-request.c @@ -114,7 +114,7 @@ guint32 nm_act_request_get_secrets (NMActRequest *self, NMConnection *connection, const char *setting_name, - gboolean request_new, + guint32 flags, const char *hint, NMActRequestSecretsFunc callback, gpointer callback_data) @@ -137,7 +137,7 @@ nm_act_request_get_secrets (NMActRequest *self, call_id = nm_agent_manager_get_secrets (priv->agent_mgr, connection ? connection : priv->connection, setting_name, - request_new, + flags, hint, get_secrets_cb, self, diff --git a/src/nm-activation-request.h b/src/nm-activation-request.h index 172ebf39a7..f7a3addd77 100644 --- a/src/nm-activation-request.h +++ b/src/nm-activation-request.h @@ -95,7 +95,7 @@ typedef void (*NMActRequestSecretsFunc) (NMActRequest *req, guint32 nm_act_request_get_secrets (NMActRequest *req, NMConnection *connection, /* NULL == use activation request's connection */ const char *setting_name, - gboolean request_new, + guint32 flags, const char *hint, NMActRequestSecretsFunc callback, gpointer callback_data); diff --git a/src/nm-agent-manager.c b/src/nm-agent-manager.c index ddefc877b8..7355a2ffcc 100644 --- a/src/nm-agent-manager.c +++ b/src/nm-agent-manager.c @@ -15,7 +15,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright (C) 2010 Red Hat, Inc. + * Copyright (C) 2010 - 2011 Red Hat, Inc. */ #include @@ -331,7 +331,7 @@ struct _Request { NMConnection *connection; char *setting_name; - gboolean request_new; + guint32 flags; char *hint; /* Current agent being asked for secrets */ @@ -365,7 +365,7 @@ struct _Request { static Request * request_new (NMConnection *connection, const char *setting_name, - gboolean get_new, + guint32 flags, const char *hint, NMAgentSecretsResultFunc callback, gpointer callback_data, @@ -381,7 +381,7 @@ request_new (NMConnection *connection, req->reqid = next_id++; req->connection = g_object_ref (connection); req->setting_name = g_strdup (setting_name); - req->request_new = get_new; + req->flags = flags; req->hint = g_strdup (hint); req->callback = callback; req->callback_data = callback_data; @@ -547,7 +547,7 @@ request_next (Request *req) req->connection, req->setting_name, req->hint, - req->request_new, + req->flags, request_secrets_done_cb, req); if (req->current_call_id == NULL) { @@ -570,7 +570,7 @@ request_start_secrets (gpointer user_data) secrets = nm_sysconfig_connection_get_secrets (NM_SYSCONFIG_CONNECTION (req->connection), req->setting_name, req->hint, - req->request_new, + req->flags ? TRUE : FALSE, &error); if (secrets) setting_secrets = g_hash_table_lookup (secrets, req->setting_name); @@ -773,7 +773,7 @@ guint32 nm_agent_manager_get_secrets (NMAgentManager *self, NMConnection *connection, const char *setting_name, - gboolean get_new, + guint32 flags, const char *hint, NMAgentSecretsResultFunc callback, gpointer callback_data, @@ -797,7 +797,7 @@ nm_agent_manager_get_secrets (NMAgentManager *self, req = request_new (connection, setting_name, - get_new, + flags, hint, callback, callback_data, diff --git a/src/nm-agent-manager.h b/src/nm-agent-manager.h index 4ddd6165d5..0e22af3e58 100644 --- a/src/nm-agent-manager.h +++ b/src/nm-agent-manager.h @@ -27,7 +27,7 @@ #include #include "nm-dbus-manager.h" -#include "nm-session-monitor.h" +#include "nm-secret-agent.h" #define NM_TYPE_AGENT_MANAGER (nm_agent_manager_get_type ()) #define NM_AGENT_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_AGENT_MANAGER, NMAgentManager)) @@ -59,7 +59,7 @@ typedef void (*NMAgentSecretsResultFunc) (NMAgentManager *manager, guint32 nm_agent_manager_get_secrets (NMAgentManager *manager, NMConnection *connection, const char *setting_name, - gboolean get_new, + guint32 flags, const char *hint, NMAgentSecretsResultFunc callback, gpointer callback_data, diff --git a/src/nm-device-ethernet.c b/src/nm-device-ethernet.c index c318f0869a..159a66ad2a 100644 --- a/src/nm-device-ethernet.c +++ b/src/nm-device-ethernet.c @@ -1023,7 +1023,7 @@ link_timeout_cb (gpointer user_data) nm_act_request_get_secrets (req, NULL, setting_name, - TRUE, + NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW, NULL, wired_secrets_cb, self); @@ -1204,16 +1204,18 @@ handle_auth_or_fail (NMDeviceEthernet *self, nm_connection_clear_secrets (connection); setting_name = nm_connection_need_secrets (connection, NULL); if (setting_name) { - gboolean get_new; + guint32 flags = NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION; /* If the caller doesn't necessarily want completely new secrets, * only ask for new secrets after the first failure. */ - get_new = new_secrets ? TRUE : (tries ? TRUE : FALSE); + if (new_secrets || tries) + flags |= NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW; + nm_act_request_get_secrets (req, NULL, setting_name, - get_new, + flags, NULL, wired_secrets_cb, self); diff --git a/src/nm-device-wifi.c b/src/nm-device-wifi.c index c19557b004..a07efc8684 100644 --- a/src/nm-device-wifi.c +++ b/src/nm-device-wifi.c @@ -2488,7 +2488,7 @@ link_timeout_cb (gpointer user_data) nm_act_request_get_secrets (req, NULL, setting_name, - TRUE, + NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW, NULL, wifi_secrets_cb, self); @@ -2726,16 +2726,18 @@ handle_auth_or_fail (NMDeviceWifi *self, nm_connection_clear_secrets (connection); setting_name = nm_connection_need_secrets (connection, NULL); if (setting_name) { - gboolean get_new; + guint32 flags = NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION; /* If the caller doesn't necessarily want completely new secrets, * only ask for new secrets after the first failure. */ - get_new = new_secrets ? TRUE : (tries ? TRUE : FALSE); + if (new_secrets || tries) + flags |= NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW; + nm_act_request_get_secrets (req, NULL, setting_name, - get_new, + flags, NULL, wifi_secrets_cb, self); diff --git a/src/nm-secret-agent.c b/src/nm-secret-agent.c index e1755d26a6..d65f5f369d 100644 --- a/src/nm-secret-agent.c +++ b/src/nm-secret-agent.c @@ -172,7 +172,7 @@ nm_secret_agent_get_secrets (NMSecretAgent *self, NMConnection *connection, const char *setting_name, const char *hint, - gboolean get_new, + guint32 flags, NMSecretAgentCallback callback, gpointer callback_data) { @@ -200,7 +200,7 @@ nm_secret_agent_get_secrets (NMSecretAgent *self, DBUS_TYPE_G_OBJECT_PATH, nm_connection_get_path (connection), G_TYPE_STRING, setting_name, G_TYPE_STRV, hints, - G_TYPE_BOOLEAN, get_new, + G_TYPE_UINT, flags, G_TYPE_INVALID); g_hash_table_insert (priv->requests, r->call, r); diff --git a/src/nm-secret-agent.h b/src/nm-secret-agent.h index 7241ecb920..bb86835e3a 100644 --- a/src/nm-secret-agent.h +++ b/src/nm-secret-agent.h @@ -15,7 +15,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright (C) 2010 Red Hat, Inc. + * Copyright (C) 2010 - 2011 Red Hat, Inc. */ #ifndef NM_SECRET_AGENT_H @@ -29,6 +29,15 @@ #include #include "nm-dbus-manager.h" +/* NOTE: these values should match the NM_SECRET_AGENT_GET_SECRETS_FLAGS in + * the nm-secret-agent.xml introspection file. + */ +enum { + NM_SECRET_AGENT_GET_SECRETS_FLAG_NONE = 0x0, + NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION = 0x1, + NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW = 0x2 +}; + #define NM_TYPE_SECRET_AGENT (nm_secret_agent_get_type ()) #define NM_SECRET_AGENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SECRET_AGENT, NMSecretAgent)) #define NM_SECRET_AGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SECRET_AGENT, NMSecretAgentClass)) @@ -71,7 +80,7 @@ gconstpointer nm_secret_agent_get_secrets (NMSecretAgent *agent, NMConnection *connection, const char *setting_name, const char *hint, - gboolean request_new, + guint32 flags, NMSecretAgentCallback callback, gpointer callback_data); diff --git a/src/ppp-manager/nm-ppp-manager.c b/src/ppp-manager/nm-ppp-manager.c index 3694668250..35db28e6e8 100644 --- a/src/ppp-manager/nm-ppp-manager.c +++ b/src/ppp-manager/nm-ppp-manager.c @@ -442,6 +442,7 @@ impl_ppp_manager_need_secrets (NMPPPManager *manager, guint32 tries; GPtrArray *hints = NULL; GError *error = NULL; + guint32 flags = NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION; connection = nm_act_request_get_connection (priv->act_req); @@ -461,15 +462,18 @@ impl_ppp_manager_need_secrets (NMPPPManager *manager, return; } - tries = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (connection), PPP_MANAGER_SECRET_TRIES)); - /* Only ask for completely new secrets after retrying them once; some PPP - * servers (T-Mobile USA) appear to ask a few times when they actually don't - * even care what you pass back. + /* Only ask for completely new secrets after retrying them once; some devices + * appear to ask a few times when they actually don't even care what you + * pass back. */ + tries = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (connection), PPP_MANAGER_SECRET_TRIES)); + if (tries > 1) + flags |= NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW; + priv->secrets_id = nm_act_request_get_secrets (priv->act_req, NULL, setting_name, - tries > 1 ? TRUE : FALSE, + flags, hints ? g_ptr_array_index (hints, 0) : NULL, ppp_secrets_cb, manager); diff --git a/src/vpn-manager/nm-vpn-connection.c b/src/vpn-manager/nm-vpn-connection.c index e835aa6920..bc1f3dbfe9 100644 --- a/src/vpn-manager/nm-vpn-connection.c +++ b/src/vpn-manager/nm-vpn-connection.c @@ -839,7 +839,7 @@ connection_need_secrets_cb (DBusGProxy *proxy, priv->secrets_id = nm_act_request_get_secrets (priv->act_request, priv->connection, setting_name, - FALSE, + NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION, NULL, vpn_secrets_cb, self);