2007-09-26 Dan Williams <dcbw@redhat.com>

* src/nm-manager.c
	  src/nm-manager.h
	  src/nm-activation-request.c
	  src/nm-activation-request.h
		- Move the GetSecrets stuff out of the NMManager instance because it
			doesn't really need to be there and complicates things

	* src/nm-device.c
		- (connection_secrets_failed_cb, device_activation_go): connect to the
			connection-secrets-failed signal and deactivate the device if
			the GetSecrets call fails

	* src/nm-device-802-11-wireless.c
		- (link_timeout_cb, supplicant_connection_timeout_cb,
		   real_act_stage2_config, real_act_stage4_ip_config_timeout): request
			secrets and give correct hints about whether new secrets should be
			asked for by the client or not



git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2899 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Dan Williams
2007-09-27 04:52:03 +00:00
parent 63500816c0
commit b1bd00af07
7 changed files with 199 additions and 195 deletions

View File

@@ -25,12 +25,15 @@
#include "nm-manager.h"
#include "nm-utils.h"
#define CONNECTION_GET_SECRETS_CALL_TAG "get-secrets-call"
G_DEFINE_TYPE (NMActRequest, nm_act_request, G_TYPE_OBJECT)
#define NM_ACT_REQUEST_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_ACT_REQUEST, NMActRequestPrivate))
enum {
CONNECTION_SECRETS_UPDATED,
CONNECTION_SECRETS_FAILED,
DEFERRED_ACTIVATION_TIMEOUT,
DEFERRED_ACTIVATION_START,
@@ -40,10 +43,6 @@ enum {
static guint signals[LAST_SIGNAL] = { 0 };
static void connection_secrets_updated_cb (NMConnection *connection,
const char *setting_name,
NMActRequest *self);
typedef struct {
char *deferred_service_name;
char *deferred_connection_path;
@@ -53,8 +52,6 @@ typedef struct {
NMConnection *connection;
char *specific_object;
gboolean user_requested;
gulong secrets_updated_id;
} NMActRequestPrivate;
static void
@@ -92,18 +89,20 @@ dispose (GObject *object)
clear_deferred_stuff (NM_ACT_REQUEST (object));
if (priv->secrets_updated_id) {
g_signal_handler_disconnect (priv->connection,
priv->secrets_updated_id);
priv->secrets_updated_id = 0;
}
if (priv->connection) {
NMManager *manager = nm_manager_get ();
DBusGProxy *proxy;
DBusGProxyCall *call;
nm_manager_cancel_get_connection_secrets (manager, priv->connection);
g_object_unref (manager);
proxy = g_object_get_data (G_OBJECT (priv->connection),
NM_MANAGER_CONNECTION_PROXY_TAG);
call = g_object_get_data (G_OBJECT (priv->connection),
CONNECTION_GET_SECRETS_CALL_TAG);
if (proxy && call)
dbus_g_proxy_cancel_call (proxy, call);
g_object_set_data (G_OBJECT (priv->connection),
CONNECTION_GET_SECRETS_CALL_TAG, NULL);
g_object_unref (priv->connection);
}
}
@@ -141,6 +140,16 @@ nm_act_request_class_init (NMActRequestClass *req_class)
G_TYPE_NONE, 2,
G_TYPE_OBJECT, G_TYPE_STRING);
signals[CONNECTION_SECRETS_FAILED] =
g_signal_new ("connection-secrets-failed",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMActRequestClass, connection_secrets_failed),
NULL, NULL,
nm_marshal_VOID__OBJECT_STRING,
G_TYPE_NONE, 2,
G_TYPE_OBJECT, G_TYPE_STRING);
signals[DEFERRED_ACTIVATION_TIMEOUT] =
g_signal_new ("deferred-activation-timeout",
G_OBJECT_CLASS_TYPE (object_class),
@@ -184,12 +193,6 @@ nm_act_request_new (NMConnection *connection,
if (specific_object)
priv->specific_object = g_strdup (specific_object);
id = g_signal_connect (priv->connection,
"secrets-updated",
G_CALLBACK (connection_secrets_updated_cb),
NM_ACT_REQUEST (obj));
priv->secrets_updated_id = id;
return NM_ACT_REQUEST (obj);
}
@@ -237,13 +240,7 @@ connection_added_cb (NMManager *manager,
return;
clear_deferred_stuff (self);
priv->connection = g_object_ref (connection);
id = g_signal_connect (priv->connection,
"secrets-updated",
G_CALLBACK (connection_secrets_updated_cb),
self);
priv->secrets_updated_id = id;
g_signal_emit (self, signals[DEFERRED_ACTIVATION_START], 0);
}
@@ -300,15 +297,116 @@ nm_act_request_is_deferred (NMActRequest *req)
return priv->deferred_connection_path ? TRUE : FALSE;
}
static void
connection_secrets_updated_cb (NMConnection *connection,
const char *setting_name,
NMActRequest *self)
{
g_return_if_fail (setting_name != NULL);
g_return_if_fail (self != NULL);
typedef struct GetSecretsInfo {
NMActRequest *req;
char *setting_name;
} GetSecretsInfo;
g_signal_emit (self, signals[CONNECTION_SECRETS_UPDATED], 0, connection, setting_name);
static void
free_get_secrets_info (gpointer data)
{
GetSecretsInfo *info = (GetSecretsInfo *) data;
g_free (info->setting_name);
g_slice_free (GetSecretsInfo, info);
}
static void
get_secrets_cb (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
{
GetSecretsInfo *info = (GetSecretsInfo *) user_data;
GError *err = NULL;
GHashTable *secrets = NULL;
NMActRequestPrivate *priv = NULL;
g_return_if_fail (info != NULL);
g_return_if_fail (info->req);
g_return_if_fail (info->setting_name);
priv = NM_ACT_REQUEST_GET_PRIVATE (info->req);
g_object_set_data (G_OBJECT (priv->connection), CONNECTION_GET_SECRETS_CALL_TAG, NULL);
if (!dbus_g_proxy_end_call (proxy, call, &err,
dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), &secrets,
G_TYPE_INVALID)) {
nm_warning ("Couldn't get connection secrets: %s.", err->message);
g_error_free (err);
g_signal_emit (info->req,
signals[CONNECTION_SECRETS_FAILED],
0,
priv->connection,
info->setting_name);
return;
}
if (g_hash_table_size (secrets) > 0) {
nm_connection_update_secrets (priv->connection, info->setting_name, secrets);
g_signal_emit (info->req,
signals[CONNECTION_SECRETS_UPDATED],
0,
priv->connection,
info->setting_name);
} else {
// FIXME: some better way to handle invalid message?
nm_warning ("GetSecrets call returned but no secrets were found.");
}
g_hash_table_destroy (secrets);
}
gboolean
nm_act_request_request_connection_secrets (NMActRequest *req,
const char *setting_name,
gboolean request_new)
{
DBusGProxy *proxy;
DBusGProxyCall *call;
GetSecretsInfo *info = NULL;
NMActRequestPrivate *priv = NULL;
g_return_val_if_fail (NM_IS_ACT_REQUEST (req), FALSE);
g_return_val_if_fail (setting_name != NULL, FALSE);
priv = NM_ACT_REQUEST_GET_PRIVATE (req);
proxy = g_object_get_data (G_OBJECT (priv->connection), NM_MANAGER_CONNECTION_PROXY_TAG);
if (!DBUS_IS_G_PROXY (proxy)) {
nm_warning ("Couldn't get dbus proxy for connection.");
goto error;
}
info = g_slice_new0 (GetSecretsInfo);
if (!info) {
nm_warning ("Not enough memory to get secrets");
goto error;
}
info->setting_name = g_strdup (setting_name);
if (!info->setting_name) {
nm_warning ("Not enough memory to get secrets");
goto error;
}
info->req = req;
call = dbus_g_proxy_begin_call_with_timeout (proxy, "GetSecrets",
get_secrets_cb,
info,
free_get_secrets_info,
G_MAXINT32,
G_TYPE_STRING, setting_name,
G_TYPE_BOOLEAN, request_new,
G_TYPE_INVALID);
if (!call) {
nm_warning ("Could not call GetSecrets");
goto error;
}
g_object_set_data (G_OBJECT (priv->connection), CONNECTION_GET_SECRETS_CALL_TAG, call);
return TRUE;
error:
if (info)
free_get_secrets_info (info);
return FALSE;
}
NMConnection *