Commit de1d4171 authored by Dan Williams's avatar Dan Williams
Browse files

2005-04-15 Dan Williams <dcbw@redhat.com>

	Initial VPN Support
		- supports 'vpnc'
		- reworks device IP configuration, backend files have changed and will need
			to be updated for all distributions.  I will try to do what I can for
			them, but I cannot test them.

	- Move named directory to src/named-manager
	- Make backends directory self-contained


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@571 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
parent 498d1b64
2005-04-15 Dan Williams <dcbw@redhat.com>
Initial VPN Support
- supports 'vpnc'
- reworks device IP configuration, backend files have changed and will need
to be updated for all distributions. I will try to do what I can for
them, but I cannot test them.
- Move named directory to src/named-manager
- Make backends directory self-contained
2005-04-06 Dan Williams <dcbw@redhat.com>
Add debug code for socket/file descriptor leaks. We register every socket
......
SUBDIRS = utils dhcpcd named src libnm_glib dispatcher-daemon $(notification_icon_dir) info-daemon initscript test po
SUBDIRS = utils dhcpcd src libnm_glib dispatcher-daemon $(notification_icon_dir) info-daemon vpn-daemons initscript test po
EXTRA_DIST = CONTRIBUTING NetworkManager.pc.in NetworkManager.h
......
......@@ -33,6 +33,8 @@
#define NM_DBUS_INTERFACE_DEVICES "org.freedesktop.NetworkManager.Devices"
#define NM_DBUS_PATH_DHCP "/org/freedesktop/NetworkManager/DhcpOptions"
#define NM_DBUS_INTERFACE_DHCP "org.freedesktop.NetworkManager.DhcpOptions"
#define NM_DBUS_PATH_VPN "/org/freedesktop/NetworkManager/VPNConnections"
#define NM_DBUS_INTERFACE_VPN "org.freedesktop.NetworkManager.VPNConnections"
#define NMI_DBUS_SERVICE "org.freedesktop.NetworkManagerInfo"
#define NMI_DBUS_PATH "/org/freedesktop/NetworkManagerInfo"
......@@ -46,6 +48,21 @@
#define NM_DBUS_NO_ACTIVE_DEVICE_ERROR "org.freedesktop.NetworkManager.NoActiveDevice"
#define NM_DBUS_NO_NETWORKS_ERROR "org.freedesktop.NetworkManager.NoNetworks"
#define NM_DBUS_NO_ACTIVE_VPN_CONNECTION "org.freedesktop.NetworkManager.VPNConnections.NoActiveVPNConnection"
#define NM_DBUS_NO_VPN_CONNECTIONS "org.freedesktop.NetworkManager.VPNConnections.NoVPNConnections"
#define NM_DBUS_VPN_STARTING_IN_PROGRESS "StartingInProgress"
#define NM_DBUS_VPN_ALREADY_STARTED "AlreadyStarted"
#define NM_DBUS_VPN_STOPPING_IN_PROGRESS "StoppingInProgress"
#define NM_DBUS_VPN_ALREADY_STOPPED "AlreadyStopped"
#define NM_DBUS_VPN_WRONG_STATE "WrongState"
#define NM_DBUS_VPN_BAD_ARGUMENTS "BadArguments"
#define NM_DBUS_VPN_SIGNAL_LOGIN_FAILED "LoginFailed"
#define NM_DBUS_VPN_SIGNAL_CONFIG_BAD "ConfigurationBad"
#define NM_DBUS_VPN_SIGNAL_STATE_CHANGE "StateChange"
#define NM_DBUS_VPN_SIGNAL_IP4_CONFIG "IP4Config"
/*
* Types of NetworkManager devices
......@@ -130,6 +147,21 @@ typedef enum NMDeviceAuthMethod
} NMDeviceAuthMethod;
/*
* VPN daemon states
*/
typedef enum NMVPNState
{
NM_VPN_STATE_ERROR = 0,
NM_VPN_STATE_INIT,
NM_VPN_STATE_SHUTDOWN,
NM_VPN_STATE_STARTING,
NM_VPN_STATE_STARTED,
NM_VPN_STATE_STOPPING,
NM_VPN_STATE_STOPPED
} NMVPNState;
/*
* Info-daemon specific preference locations
*/
......
......@@ -169,6 +169,10 @@ PKG_CHECK_MODULES(LIBGNOMEUI, libgnomeui-2.0)
AC_SUBST(LIBGNOMEUI_CFLAGS) # is this even needed? it was typed incorrectly before
AC_SUBST(LIBGNOMEUI_LIBS)
PKG_CHECK_MODULES(GNOMEKEYRING, gnome-keyring-1)
AC_SUBST(GNOMEKEYRING_CFLAGS) # is this even needed? it was typed incorrectly before
AC_SUBST(GNOMEKEYRING_LIBS)
AC_ARG_WITH(dbus-sys, AC_HELP_STRING([--with-dbus-sys=DIR], [where D-BUS system.d directory is]))
if ! test -z "$with_dbus_sys" ; then
......@@ -266,11 +270,13 @@ AC_OUTPUT([
Makefile
utils/Makefile
src/Makefile
src/named-manager/Makefile
src/vpn-manager/Makefile
src/backends/Makefile
dispatcher-daemon/Makefile
info-daemon/Makefile
panel-applet/Makefile
panel-applet/icons/Makefile
named/Makefile
dhcpcd/Makefile
libnm_glib/Makefile
test/Makefile
......@@ -282,6 +288,8 @@ initscript/Slackware/Makefile
po/Makefile.in
NetworkManager.pc
libnm_glib/libnm_glib.pc
vpn-daemons/Makefile
vpn-daemons/vpnc/Makefile
])
echo
......
......@@ -49,12 +49,12 @@ static void nmi_spawn_notification_icon (NMIAppInfo *info);
/*
* nmi_gconf_notify_callback
* nmi_gconf_networks_notify_callback
*
* Callback from gconf when wireless networking key/values have changed.
*
*/
void nmi_gconf_notify_callback (GConfClient *client, guint connection_id, GConfEntry *entry, gpointer user_data)
static void nmi_gconf_networks_notify_callback (GConfClient *client, guint connection_id, GConfEntry *entry, gpointer user_data)
{
NMIAppInfo *info = (NMIAppInfo *)user_data;
const char *key = NULL;
......@@ -88,6 +88,46 @@ void nmi_gconf_notify_callback (GConfClient *client, guint connection_id, GConfE
}
/*
* nmi_gconf_vpn_connections_notify_callback
*
* Callback from gconf when VPN connection values have changed.
*
*/
static void nmi_gconf_vpn_connections_notify_callback (GConfClient *client, guint connection_id, GConfEntry *entry, gpointer user_data)
{
NMIAppInfo *info = (NMIAppInfo *)user_data;
const char *key = NULL;
g_return_if_fail (client != NULL);
g_return_if_fail (entry != NULL);
g_return_if_fail (info != NULL);
if ((key = gconf_entry_get_key (entry)))
{
int path_len = strlen (NMI_GCONF_VPN_CONNECTIONS_PATH) + 1;
if (strncmp (NMI_GCONF_VPN_CONNECTIONS_PATH"/", key, path_len) == 0)
{
char *name = g_strdup ((key + path_len));
char *slash_pos;
char *unescaped_name;
/* If its a key under the the VPN name, zero out the slash so we
* are left with only the VPN name.
*/
unescaped_name = gconf_unescape_key (name, strlen (name));
if ((slash_pos = strchr (unescaped_name, '/')))
*slash_pos = '\0';
nmi_dbus_signal_update_vpn_connection (info->connection, unescaped_name);
g_free (unescaped_name);
g_free (name);
}
}
}
#ifdef BUILD_NOTIFICATION_ICON
static void
on_icon_exit_callback (GPid pid, int status, gpointer data)
......@@ -238,7 +278,9 @@ int main( int argc, char *argv[] )
gconf_client_add_dir (app_info->gconf_client, NMI_GCONF_WIRELESS_NETWORKS_PATH,
GCONF_CLIENT_PRELOAD_NONE, NULL);
notify_id = gconf_client_notify_add (app_info->gconf_client, NMI_GCONF_WIRELESS_NETWORKS_PATH,
nmi_gconf_notify_callback, app_info, NULL, NULL);
nmi_gconf_networks_notify_callback, app_info, NULL, NULL);
notify_id = gconf_client_notify_add (app_info->gconf_client, NMI_GCONF_VPN_CONNECTIONS_PATH,
nmi_gconf_vpn_connections_notify_callback, app_info, NULL, NULL);
/* Create our own dbus service */
err = nmi_dbus_service_init (dbus_connection, app_info);
......
......@@ -32,6 +32,8 @@
#include <dbus/dbus-glib.h>
#include <gconf/gconf-client.h>
#define NMI_GCONF_VPN_CONNECTIONS_PATH "/system/networking/vpn_connections"
struct NMIAppInfo
{
GladeXML *passphrase_dialog;
......
......@@ -35,7 +35,6 @@
#include "NetworkManagerInfoVPN.h"
#include "nm-utils.h"
/*
* nmi_show_warning_dialog
*
......@@ -332,7 +331,7 @@ static DBusMessage *nmi_dbus_get_networks (NMIAppInfo *info, DBusMessage *messag
/*
* nmi_dbus_get_network
* nmi_dbus_get_network_properties
*
* Returns the properties of a specific wireless network from gconf
*
......@@ -499,6 +498,279 @@ static DBusMessage *nmi_dbus_get_network_properties (NMIAppInfo *info, DBusMessa
}
/*
* nmi_dbus_signal_update_vpn_connection
*
* Signal NetworkManager that it needs to update info associated with a particular
* VPN connection.
*
*/
void nmi_dbus_signal_update_vpn_connection (DBusConnection *connection, const char *name)
{
DBusMessage *message;
g_return_if_fail (connection != NULL);
g_return_if_fail (name != NULL);
if (!(message = dbus_message_new_signal (NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "VPNConnectionUpdate")))
{
nm_warning ("nmi_dbus_signal_update_vpn_connection(): Not enough memory for new dbus message!");
return;
}
dbus_message_append_args (message, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID);
if (!dbus_connection_send (connection, message, NULL))
nm_warning ("nmi_dbus_signal_update_vpn_connection(): Could not raise the 'VPNConnectionUpdate' signal!");
dbus_message_unref (message);
}
/*
* nmi_dbus_get_vpn_connections
*
* Grab a list of VPN connections from GConf and return it in the form
* of a string array in a dbus message.
*
*/
static DBusMessage *nmi_dbus_get_vpn_connections (NMIAppInfo *info, DBusMessage *message)
{
GSList *dir_list = NULL;
GSList *element = NULL;
DBusError error;
DBusMessage *reply_message = NULL;
DBusMessageIter iter;
DBusMessageIter iter_array;
g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (message != NULL, NULL);
dbus_error_init (&error);
/* List all VPN connections that gconf knows about */
element = dir_list = gconf_client_all_dirs (info->gconf_client, NMI_GCONF_VPN_CONNECTIONS_PATH, NULL);
if (!dir_list)
{
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "NoVPNConnections",
"There are no VPN connections stored.");
}
else
{
gboolean value_added = FALSE;
reply_message = dbus_message_new_method_return (message);
dbus_message_iter_init_append (reply_message, &iter);
dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &iter_array);
/* Append the essid of every allowed or ignored access point we know of
* to a string array in the dbus message.
*/
while (element)
{
char key[100];
GConfValue *value;
g_snprintf (&key[0], 99, "%s/name", (char *)(element->data));
value = gconf_client_get (info->gconf_client, key, NULL);
if (value && gconf_value_get_string (value))
{
const gchar *essid;
essid = gconf_value_get_string (value);
dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_STRING, &essid);
value_added = TRUE;
gconf_value_free (value);
}
g_free (element->data);
element = element->next;
}
g_slist_free (dir_list);
dbus_message_iter_close_container (&iter, &iter_array);
if (!value_added)
{
dbus_message_unref (reply_message);
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "NoVPNConnections",
"There are no VPN connections stored.");
}
}
return (reply_message);
}
/*
* nmi_dbus_get_vpn_connection_properties
*
* Returns the properties of a specific VPN connection from gconf
*
*/
static DBusMessage *nmi_dbus_get_vpn_connection_properties (NMIAppInfo *info, DBusMessage *message)
{
DBusMessage *reply = NULL;
gchar *gconf_key = NULL;
char *vpn_connection = NULL;
GConfValue *value;
DBusError error;
char *escaped_name;
char *name = NULL;
char *service_name = NULL;
char *user_name = NULL;
g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (message != NULL, NULL);
dbus_error_init (&error);
if ( !dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &vpn_connection, DBUS_TYPE_INVALID)
|| (strlen (vpn_connection) <= 0))
{
reply = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "InvalidArguments",
"NetworkManagerInfo::getVPNConnectionProperties called with invalid arguments.");
return (reply);
}
escaped_name = gconf_escape_key (vpn_connection, strlen (vpn_connection));
/* User-visible name of connection */
gconf_key = g_strdup_printf ("%s/%s/name", NMI_GCONF_VPN_CONNECTIONS_PATH, escaped_name);
if ((value = gconf_client_get (info->gconf_client, gconf_key, NULL)))
{
name = g_strdup (gconf_value_get_string (value));
gconf_value_free (value);
}
g_free (gconf_key);
/* Service name of connection */
gconf_key = g_strdup_printf ("%s/%s/service_name", NMI_GCONF_VPN_CONNECTIONS_PATH, escaped_name);
if ((value = gconf_client_get (info->gconf_client, gconf_key, NULL)))
{
service_name = g_strdup (gconf_value_get_string (value));
gconf_value_free (value);
}
g_free (gconf_key);
/* User name of connection */
gconf_key = g_strdup_printf ("%s/%s/user_name", NMI_GCONF_VPN_CONNECTIONS_PATH, escaped_name);
if ((value = gconf_client_get (info->gconf_client, gconf_key, NULL)))
{
user_name = g_strdup (gconf_value_get_string (value));
gconf_value_free (value);
}
g_free (gconf_key);
if (!name)
{
reply = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadVPNConnectionData",
"NetworkManagerInfo::getVPNConnectionProperties could not access the name for connection '%s'", vpn_connection);
}
else if (!service_name)
{
reply = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadVPNConnectionData",
"NetworkManagerInfo::getVPNConnectionProperties could not access the service name for connection '%s'", vpn_connection);
}
else if (!user_name)
{
reply = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadVPNConnectionData",
"NetworkManagerInfo::getVPNConnectionProperties could not access the user name for connection '%s'", vpn_connection);
}
else
{
DBusMessageIter iter, array_iter;
reply = dbus_message_new_method_return (message);
dbus_message_iter_init_append (reply, &iter);
dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &name);
dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &service_name);
dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &user_name);
}
g_free (user_name);
g_free (service_name);
g_free (name);
g_free (escaped_name);
return (reply);
}
/*
* nmi_dbus_get_vpn_connection_vpn_data
*
* Returns vpn-daemon specific properties for a particular VPN connection.
*
*/
static DBusMessage *nmi_dbus_get_vpn_connection_vpn_data (NMIAppInfo *info, DBusMessage *message)
{
DBusMessage *reply = NULL;
gchar *gconf_key = NULL;
char *name = NULL;
GConfValue *vpn_data_value = NULL;
GConfValue *value = NULL;
DBusError error;
char *escaped_name;
DBusMessageIter iter, array_iter;
GSList *elt;
g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (message != NULL, NULL);
dbus_error_init (&error);
if ( !dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID)
|| (strlen (name) <= 0))
{
reply = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "InvalidArguments",
"NetworkManagerInfo::getVPNConnectionVPNData called with invalid arguments.");
return reply;
}
escaped_name = gconf_escape_key (name, strlen (name));
/* User-visible name of connection */
gconf_key = g_strdup_printf ("%s/%s/name", NMI_GCONF_VPN_CONNECTIONS_PATH, escaped_name);
if (!(value = gconf_client_get (info->gconf_client, gconf_key, NULL)))
{
reply = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadVPNConnectionData",
"NetworkManagerInfo::getVPNConnectionVPNData could not access the name for connection '%s'", name);
return reply;
}
gconf_value_free (value);
g_free (gconf_key);
/* Grab vpn-daemon specific data */
gconf_key = g_strdup_printf ("%s/%s/vpn_data", NMI_GCONF_VPN_CONNECTIONS_PATH, escaped_name);
if (!(vpn_data_value = gconf_client_get (info->gconf_client, gconf_key, NULL))
|| !(vpn_data_value->type == GCONF_VALUE_LIST)
|| !(gconf_value_get_list_type (vpn_data_value) == GCONF_VALUE_STRING))
{
reply = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "BadVPNConnectionData",
"NetworkManagerInfo::getVPNConnectionVPNData could not access the VPN data for connection '%s'", name);
if (vpn_data_value)
gconf_value_free (vpn_data_value);
return reply;
}
g_free (gconf_key);
reply = dbus_message_new_method_return (message);
dbus_message_iter_init_append (reply, &iter);
dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &array_iter);
for (elt = gconf_value_get_list (vpn_data_value); elt; elt = g_slist_next (elt))
{
const char *string = gconf_value_get_string ((GConfValue *)elt->data);
if (string)
dbus_message_iter_append_basic (&array_iter, DBUS_TYPE_STRING, &string);
}
dbus_message_iter_close_container (&iter, &array_iter);
gconf_value_free (vpn_data_value);
g_free (escaped_name);
return (reply);
}
/*
* nmi_dbus_update_network_auth_method
*
......@@ -707,6 +979,12 @@ static DBusHandlerResult nmi_dbus_nmi_message_handler (DBusConnection *connectio
nmi_dbus_update_network_auth_method (info, message);
else if (strcmp ("addNetworkAddress", method) == 0)
nmi_dbus_add_network_address (info, message);
else if (strcmp ("getVPNConnections", method) == 0)
reply_message = nmi_dbus_get_vpn_connections (info, message);
else if (strcmp ("getVPNConnectionProperties", method) == 0)
reply_message = nmi_dbus_get_vpn_connection_properties (info, message);
else if (strcmp ("getVPNConnectionVPNData", method) == 0)
reply_message = nmi_dbus_get_vpn_connection_vpn_data (info, message);
else
{
reply_message = nmi_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "UnknownMethod",
......
......@@ -43,4 +43,6 @@ void nmi_dbus_return_vpn_password (DBusConnection *connection, DBusMessage *me
void nmi_dbus_signal_update_network (DBusConnection *connection, const char *network, NMNetworkType type);
void nmi_dbus_signal_update_vpn_connection (DBusConnection *connection, const char *name);
#endif
namedconf_DATA = named.conf
namedconfdir = $(pkgdatadir)
EXTRA_DIST = $(namedconf_DATA)
INCLUDES = -I${top_srcdir}/utils
noinst_LTLIBRARIES = libnamed.la
libnamed_la_SOURCES = nm-named-manager.h nm-named-manager.c
libnamed_la_CPPFLAGS = $(DBUS_CFLAGS) $(GTHREAD_CFLAGS) -DNM_PKGDATADIR=\"$(pkgdatadir)\" -DNM_LOCALSTATEDIR=\"$(localstatedir)\"
libnamed_la_LIBADD = $(DBUS_LIBS) $(GTHREAD_LIBS)
......@@ -20,6 +20,7 @@ libnm_notification_applet_la_CPPFLAGS = \
$(GCONF_CFLAGS) \
$(LIBGNOMEUI_CFLAGS) \
$(PANEL_APPLET_CFLAGS) \
$(GNOMEKEYRING_CFLAGS) \
-DICONDIR=\""$(datadir)/pixmaps"\" \
-DGLADEDIR=\""$(gladedir)"\" \
-DDBUS_API_SUBJECT_TO_CHANGE \
......@@ -43,6 +44,10 @@ libnm_notification_applet_la_SOURCES = \
gtkcellview.h \
gtkcellrendererprogress.c \
gtkcellrendererprogress.h \
nmwa-vpn-password-dialog.c \
nmwa-vpn-password-dialog.h \
nmwa-vpn-connection.c \
nmwa-vpn-connection.h \
$(NULL)
libnm_notification_applet_la_SOURCES += \
......@@ -59,6 +64,7 @@ libnm_notification_applet_la_LIBADD = \
$(GTK_LIBS) \
$(GCONF_LIBS) \
$(LIBGNOMEUI_LIBS) \
$(GNOMEKEYRING_LIBS) \
$(NULL)
libexec_PROGRAMS = NetworkManagerNotification
......
......@@ -56,6 +56,8 @@
#include "NMWirelessAppletDbus.h"
#include "NMWirelessAppletOtherNetworkDialog.h"
#include "menu-info.h"
#include "nmwa-vpn-password-dialog.h"
#include "nmwa-vpn-connection.h"
#define CFG_UPDATE_INTERVAL 1
#define NMWA_GCONF_PATH "/apps/NetworkManagerNotification"
......@@ -176,6 +178,119 @@ void nmwa_about_cb (NMWirelessApplet *applet)
#endif
}
static void vpn_login_failure_dialog_close_cb (GtkWidget *dialog, gpointer user_data)
{
char *message;
if ((message = g_object_get_data (G_OBJECT (dialog), "message")))
{
g_object_set_data (G_OBJECT (dialog), "message", NULL);
g_free (message);
}
gtk_widget_destroy (dialog);
}
/*
* nmwa_show_vpn_login_failure_dialog
*
* Present the VPN login failure dialog.
*
*/
static gboolean nmwa_show_vpn_login_failure_dialog (char *message)
{
GtkWidget *dialog;
g_return_val_if_fail (message != NULL, FALSE);
dialog = gtk_message_dialog_new_with_markup (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, message, NULL);
g_signal_connect (dialog, "response", G_CALLBACK (vpn_login_failure_dialog_close_cb), NULL);
g_signal_connect (dialog, "close", G_CALLBACK (vpn_login_failure_dialog_close_cb), NULL);
g_object_set_data (G_OBJECT (dialog), "message", message);
gtk_widget_show_all (dialog);
return FALSE;
}
/*
* nmwa_schedule_vpn_login_failure_dialog
*
* Schedule display of the VPN Login Failure dialog.
*
*/
void nmwa_schedule_vpn_login_failure_dialog (NMWirelessApplet *applet, const char *vpn_name, const char *error_msg)
{
char *msg;
g_return_if_fail (applet != NULL);
g_return_if_fail (vpn_name != NULL);
g_return_if_fail (error_msg != NULL);