NetworkManager/info-daemon/NetworkManagerInfoDbus.c
Dan Williams aab500146f 2004-07-19 Dan Williams <dcbw@redhat.com>
* Makefile.am
		- Add info-daemon directory

	* configure.in
		- Check for glade libs and headers
		- Add info-daemon directory

	* src/NetworkManagerAP.c
		- nm_ap_new_from_ap(): Fix bug that resulted in an APs encryption status not getting
			copied over to the new AP.

	* src/NetworkManagerDbus.c
	  src/NetworkManagerDbus.h
		- Deal with nm_device_ap_list_get_ap()->nm_device_ap_list_get_ap_by_index() change
		- Remove nm_dbus_signal_need_key_for_network()
		- Add disabled code for asynchronous user wep key callbacks
		- Add functions for getting, setting, and cancelling user key operations
		- Remove "setKeyForNetwork" device dbus method call, its on NetworkManager object instead
		- Add "setKeyForNetwork" dbus method call on NetworkManager object

	* src/NetworkManagerDevice.c
	  src/NetworkManagerDevice.h
		- nm_device_update_link_active(): revert changes for wireless link detection, the WEP-key-is-wrong
			logic is in device activation now
		- nm_device_activate(): for wireless devices, if we can't associate with access point (perhaps
			key is wrong) trigger get-user-key pending action
		- Implement get-user-key pending action stuff, tie to dbus messages
		- Rename nm_device_ap_list_get_ap() -> nm_device_ap_list_get_ap_by_index()
		- Add nm_device_ap_list_get_ap_by_essid()
		- Instead of copying "best" access points, ref them instead so that the key we set
			sticks around

	* src/NetworkManagerPolicy.c
		- Deal with wrong WEP key, but right access point (and if so, return link_active = TRUE)
		- Don't cancel pending actions on a device if its the same device as last iteration
		- Only promote pending_device->active_device if activation was successfull

	* src/Makefile.am
		- Rename nmclienttest->nmtest

	* info-daemon/Makefile.am
	  info-daemon/NetworkManagerInfo.c
	  info-daemon/NetworkManagerInfo.h
	  info-daemon/NetworkManagerInfoDbus.c
	  info-daemon/NetworkManagerInfoDbus.h
	  info-daemon/passphrase.glade
	  info-daemon/NetworkManagerInfo.conf
	  info-daemon/keyring.png
	  	- Import sources for info-daemon, which pops up dialog for passphrase/key when
	  		NetworkManager asks for it, and also will (soon) provide "allowed" access point
	  		lists to NetworkManager by proxying user's GConf


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@16 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2004-07-19 06:08:52 +00:00

209 lines
6 KiB
C

/* NetworkManagerInfo -- Manage allowed access points and provide a UI
* for WEP key entry
*
* Dan Williams <dcbw@redhat.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* (C) Copyright 2004 Red Hat, Inc.
*/
#include <glib.h>
#include <dbus/dbus-glib.h>
#include <stdio.h>
#include <string.h>
#include "NetworkManagerInfo.h"
#include "NetworkManagerInfoDbus.h"
#define NMI_DBUS_NMI_OBJECT_PATH_PREFIX "/org/freedesktop/NetworkManagerInfo"
#define NMI_DBUS_NMI_NAMESPACE "org.freedesktop.NetworkManagerInfo"
/*
* nmi_dbus_create_error_message
*
* Make a DBus error message
*
*/
static DBusMessage *nmi_dbus_create_error_message (DBusMessage *message, const char *exception_namespace,
const char *exception, const char *format, ...)
{
DBusMessage *reply_message;
va_list args;
char error_text[512];
va_start (args, format);
vsnprintf (error_text, 512, format, args);
va_end (args);
char *exception_text = g_strdup_printf ("%s.%s", exception_namespace, exception);
reply_message = dbus_message_new_error (message, exception_text, error_text);
g_free (exception_text);
return (reply_message);
}
/*
* nmi_dbus_dbus_return_user_key
*
* Alert NetworkManager of the new user key
*
*/
void nmi_dbus_return_user_key (DBusConnection *connection, const char *device,
const char *network, const char *passphrase)
{
DBusMessage *message;
DBusMessageIter iter;
g_return_if_fail (connection != NULL);
g_return_if_fail (device != NULL);
g_return_if_fail (network != NULL);
g_return_if_fail (passphrase != NULL);
message = dbus_message_new_method_call ("org.freedesktop.NetworkManager",
"/org/freedesktop/NetworkManager",
"org.freedesktop.NetworkManager",
"setKeyForNetwork");
if (message == NULL)
{
fprintf (stderr, "nmi_dbus_return_user_key(): Couldn't allocate the dbus message\n");
return;
}
/* Add network name and passphrase */
dbus_message_iter_init (message, &iter);
dbus_message_iter_append_string (&iter, device);
dbus_message_iter_append_string (&iter, network);
dbus_message_iter_append_string (&iter, passphrase);
if (!dbus_connection_send (connection, message, NULL))
{
fprintf (stderr, "nmi_dbus_return_user_key(): dbus could not send the message\n");
return;
}
}
/*
* nmi_dbus_nmi_message_handler
*
* Responds to requests for our services
*
*/
static DBusHandlerResult nmi_dbus_nmi_message_handler (DBusConnection *connection, DBusMessage *message, void *user_data)
{
const char *method;
const char *path;
NMIAppInfo *info = (NMIAppInfo *)user_data;
DBusMessage *reply_message = NULL;
g_return_val_if_fail (info != NULL, DBUS_HANDLER_RESULT_HANDLED);
method = dbus_message_get_member (message);
path = dbus_message_get_path (message);
/* fprintf (stderr, "nmi_dbus_nmi_message_handler() got method %s for path %s\n", method, path); */
if (strcmp ("getKeyForNetwork", method) == 0)
{
GtkWidget *dialog = glade_xml_get_widget (info->xml, "passphrase_dialog");
if (!GTK_WIDGET_VISIBLE (dialog))
{
DBusMessageIter iter;
char *dbus_string;
char *device = NULL;
char *network = NULL;
dbus_message_iter_init (message, &iter);
/* Grab device */
dbus_string = dbus_message_iter_get_string (&iter);
device = (dbus_string == NULL ? NULL : strdup (dbus_string));
dbus_free (dbus_string);
/* Grab network to get key for */
if (dbus_message_iter_next (&iter))
{
dbus_string = dbus_message_iter_get_string (&iter);
network = (dbus_string == NULL ? NULL : strdup (dbus_string));
dbus_free (dbus_string);
}
if (device && network)
nmi_show_user_key_dialog (device, network, info);
g_free (device);
g_free (network);
}
}
else if (strcmp ("cancelGetKeyForNetwork", method) == 0)
{
GtkWidget *dialog = glade_xml_get_widget (info->xml, "passphrase_dialog");
if (GTK_WIDGET_VISIBLE (dialog))
nmi_cancel_user_key_dialog (info);
}
else
{
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_NMI_NAMESPACE, "UnknownMethod",
"NetworkManagerInfo knows nothing about the method %s for object %s", method, path);
dbus_connection_send (connection, reply_message, NULL);
}
return (DBUS_HANDLER_RESULT_HANDLED);
}
/*
* nmi_dbus_nmi_unregister_handler
*
* Nothing happens here.
*
*/
void nmi_dbus_nmi_unregister_handler (DBusConnection *connection, void *user_data)
{
/* do nothing */
}
/*
* nmi_dbus_service_init
*
* Connect to the system messagebus and register ourselves as a service.
*
*/
int nmi_dbus_service_init (DBusConnection *dbus_connection, NMIAppInfo *info)
{
DBusError dbus_error;
DBusObjectPathVTable nmi_vtable = { &nmi_dbus_nmi_unregister_handler, &nmi_dbus_nmi_message_handler, NULL, NULL, NULL, NULL };
const char *nmi_path[] = { "org", "freedesktop", "NetworkManagerInfo", NULL };
dbus_error_init (&dbus_error);
dbus_bus_acquire_service (dbus_connection, NMI_DBUS_NMI_NAMESPACE, 0, &dbus_error);
if (dbus_error_is_set (&dbus_error))
{
fprintf (stderr, "nmi_dbus_service_init() could not acquire its service. dbus_bus_acquire_service() says: '%s'\n", dbus_error.message);
return (-1);
}
if (!dbus_connection_register_object_path (dbus_connection, nmi_path, &nmi_vtable, info))
{
fprintf (stderr, "nmi_dbus_service_init() could not register a handler for NetworkManagerInfo. Not enough memory?\n");
return (-1);
}
return (0);
}