From 21bdc07fa87e66474798b2710aed1efab9b46b23 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Sat, 14 May 2005 21:54:30 +0000 Subject: [PATCH] 2005-05-14 Dan Williams * NetworkManager.h - Add signals for VPN Launch and Connect failures * gnome/applet/applet-dbus.c - (nmwa_dbus_filter): Trap new VPN launch & connect failure signals * gnome/applet/applet.c - (nmwa_show_vpn_failure_dialog): generalize old nmwa_show_vpn_login_failure_dialog() function to handle all VPN failure messages - (nmwa_schedule_vpn_failure_dialog): generalize old nmwa_schedule_vpn_login_failure_dialog() function to hanlde all VPN failure messages - (show_warning_dialog): work around focus-stealing prevention * gnome/applet/other-network-dialog.c gnome/applet/passphrase-dialog.c - (update_button_cb): Make sure the OK button is enabled when it should be, fixes problem where it never enabled for ASCII Key and Hex Key types * gnome/applet/wireless-applet.glade - Add window title to Other Wireless Network Dialog * src/vpn-manager/nm-dbus-vpn.c - (nm_dbus_vpn_signal_vpn_failed): generalize old nm_dbus_vpn_signal_vpn_login_failed() function to handle all VPN failure messages * src/vpn-manager/nm-vpn-manager.c - (nm_vpn_manager_process_signal): trap and proxy VPN launch & connect failure signals too * vpn-daemons/vpnc/nm-vpnc-service.c - (nm_vpnc_dbus_signal_launch_failed): new function - (nm_vpnc_dbus_signal_connect_failed): new function - (nm_vpnc_helper_timer_cb): signal connect failure on timeout - (vpnc_watch_cb): signal connection failure when vpnc exits with connection failure - (nm_vpnc_start_vpnc_binary): search a number of locations for vpnc - (nm_vpnc_dbus_handle_start): send launch failure signal when we fail to launch vpnc git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@627 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 38 ++++++++++++ NetworkManager.h | 3 + gnome/applet/applet-dbus.c | 8 ++- gnome/applet/applet.c | 89 +++++++++++++++++++++------- gnome/applet/applet.h | 2 +- gnome/applet/other-network-dialog.c | 60 +++++++++---------- gnome/applet/passphrase-dialog.c | 44 +++++++------- gnome/applet/wireless-applet.glade | 58 +++++++++++++++++-- src/vpn-manager/nm-dbus-vpn.c | 13 +++-- src/vpn-manager/nm-dbus-vpn.h | 2 +- src/vpn-manager/nm-vpn-manager.c | 22 ++++--- vpn-daemons/vpnc/nm-vpnc-service.c | 90 +++++++++++++++++++++++++++-- 12 files changed, 327 insertions(+), 102 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3c771e6548..ba4330584b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,41 @@ +2005-05-14 Dan Williams + + * NetworkManager.h + - Add signals for VPN Launch and Connect failures + + * gnome/applet/applet-dbus.c + - (nmwa_dbus_filter): Trap new VPN launch & connect failure signals + + * gnome/applet/applet.c + - (nmwa_show_vpn_failure_dialog): generalize old nmwa_show_vpn_login_failure_dialog() + function to handle all VPN failure messages + - (nmwa_schedule_vpn_failure_dialog): generalize old nmwa_schedule_vpn_login_failure_dialog() + function to hanlde all VPN failure messages + - (show_warning_dialog): work around focus-stealing prevention + + * gnome/applet/other-network-dialog.c + gnome/applet/passphrase-dialog.c + - (update_button_cb): Make sure the OK button is enabled when it should be, fixes + problem where it never enabled for ASCII Key and Hex Key types + + * gnome/applet/wireless-applet.glade + - Add window title to Other Wireless Network Dialog + + * src/vpn-manager/nm-dbus-vpn.c + - (nm_dbus_vpn_signal_vpn_failed): generalize old nm_dbus_vpn_signal_vpn_login_failed() + function to handle all VPN failure messages + + * src/vpn-manager/nm-vpn-manager.c + - (nm_vpn_manager_process_signal): trap and proxy VPN launch & connect failure signals too + + * vpn-daemons/vpnc/nm-vpnc-service.c + - (nm_vpnc_dbus_signal_launch_failed): new function + - (nm_vpnc_dbus_signal_connect_failed): new function + - (nm_vpnc_helper_timer_cb): signal connect failure on timeout + - (vpnc_watch_cb): signal connection failure when vpnc exits with connection failure + - (nm_vpnc_start_vpnc_binary): search a number of locations for vpnc + - (nm_vpnc_dbus_handle_start): send launch failure signal when we fail to launch vpnc + 2005-05-11 Dan Williams * vpn-daemons/vpnc/nm-vpnc-service.c diff --git a/NetworkManager.h b/NetworkManager.h index 05f2abe476..64ac3e4ed7 100644 --- a/NetworkManager.h +++ b/NetworkManager.h @@ -64,7 +64,10 @@ /* * VPN daemon signals */ +#define NM_DBUS_VPN_SIGNAL_LOGIN_BANNER "LoginBanner" #define NM_DBUS_VPN_SIGNAL_LOGIN_FAILED "LoginFailed" +#define NM_DBUS_VPN_SIGNAL_LAUNCH_FAILED "LaunchFailed" +#define NM_DBUS_VPN_SIGNAL_CONNECT_FAILED "ConnectFailed" #define NM_DBUS_VPN_SIGNAL_CONFIG_BAD "ConfigurationBad" #define NM_DBUS_VPN_SIGNAL_STATE_CHANGE "StateChange" #define NM_DBUS_VPN_SIGNAL_IP4_CONFIG "IP4Config" diff --git a/gnome/applet/applet-dbus.c b/gnome/applet/applet-dbus.c index 4286af9a13..cf4de21b50 100644 --- a/gnome/applet/applet-dbus.c +++ b/gnome/applet/applet-dbus.c @@ -544,15 +544,17 @@ static DBusHandlerResult nmwa_dbus_filter (DBusConnection *connection, DBusMessa nmwa_dbus_device_update_one_network (applet, dev_path, net_path, NULL); } } - else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE_VPN, "VPNLoginFailed")) + else if ( dbus_message_is_signal (message, NM_DBUS_INTERFACE_VPN, NM_DBUS_VPN_SIGNAL_LOGIN_FAILED) + || dbus_message_is_signal (message, NM_DBUS_INTERFACE_VPN, NM_DBUS_VPN_SIGNAL_LAUNCH_FAILED) + || dbus_message_is_signal (message, NM_DBUS_INTERFACE_VPN, NM_DBUS_VPN_SIGNAL_CONNECT_FAILED)) { char *vpn_name; char *error_msg; if (dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &vpn_name, DBUS_TYPE_STRING, &error_msg, DBUS_TYPE_INVALID)) - nmwa_schedule_vpn_login_failure_dialog (applet, vpn_name, error_msg); + nmwa_schedule_vpn_failure_dialog (applet, member, vpn_name, error_msg); } - else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE_VPN, "VPNLoginBanner")) + else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE_VPN, NM_DBUS_VPN_SIGNAL_LOGIN_BANNER)) { char *vpn_name; char *banner; diff --git a/gnome/applet/applet.c b/gnome/applet/applet.c index 750dc9cdf6..13df8fd94a 100644 --- a/gnome/applet/applet.c +++ b/gnome/applet/applet.c @@ -222,14 +222,30 @@ void nmwa_about_cb (NMWirelessApplet *applet) } -static void vpn_login_failure_dialog_close_cb (GtkWidget *dialog, gpointer user_data) +typedef struct DialogCBData { - char *message; + char *msg; + char *title; +} DialogCBData; - if ((message = g_object_get_data (G_OBJECT (dialog), "message"))) +static void free_dialog_cb_data (DialogCBData *data) +{ + g_return_if_fail (data != NULL); + + g_free (data->msg); + g_free (data->title); + memset (data, 0, sizeof (DialogCBData)); + g_free (data); +} + +static void vpn_failure_dialog_close_cb (GtkWidget *dialog, gpointer user_data) +{ + DialogCBData *data; + + if ((data = g_object_get_data (G_OBJECT (dialog), "data"))) { - g_object_set_data (G_OBJECT (dialog), "message", NULL); - g_free (message); + g_object_set_data (G_OBJECT (dialog), "data", NULL); + free_dialog_cb_data (data); } gtk_widget_destroy (dialog); @@ -237,22 +253,25 @@ static void vpn_login_failure_dialog_close_cb (GtkWidget *dialog, gpointer user_ /* - * nmwa_show_vpn_login_failure_dialog + * nmwa_show_vpn_failure_dialog * - * Present the VPN login failure dialog. + * Present the VPN failure dialog. * */ -static gboolean nmwa_show_vpn_login_failure_dialog (char *message) +static gboolean nmwa_show_vpn_failure_dialog (DialogCBData *cb_data) { GtkWidget *dialog; guint32 timestamp; - g_return_val_if_fail (message != NULL, FALSE); + g_return_val_if_fail (cb_data != NULL, FALSE); + g_return_val_if_fail (cb_data->msg != NULL, FALSE); + g_return_val_if_fail (cb_data->title != 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); + dialog = gtk_message_dialog_new_with_markup (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, cb_data->msg, NULL); + gtk_window_set_title (GTK_WINDOW (dialog), cb_data->title); + g_signal_connect (dialog, "response", G_CALLBACK (vpn_failure_dialog_close_cb), NULL); + g_signal_connect (dialog, "close", G_CALLBACK (vpn_failure_dialog_close_cb), NULL); + g_object_set_data (G_OBJECT (dialog), "data", cb_data); gtk_widget_show_all (dialog); /* Bash focus-stealing prevention in the face */ @@ -264,22 +283,43 @@ static gboolean nmwa_show_vpn_login_failure_dialog (char *message) /* - * nmwa_schedule_vpn_login_failure_dialog + * nmwa_schedule_vpn_failure_dialog * - * Schedule display of the VPN Login Failure dialog. + * Schedule display of the VPN Failure dialog. * */ -void nmwa_schedule_vpn_login_failure_dialog (NMWirelessApplet *applet, const char *vpn_name, const char *error_msg) +void nmwa_schedule_vpn_failure_dialog (NMWirelessApplet *applet, const char *member, const char *vpn_name, const char *error_msg) { - char *msg; + DialogCBData *cb_data = NULL; g_return_if_fail (applet != NULL); + g_return_if_fail (member != NULL); g_return_if_fail (vpn_name != NULL); g_return_if_fail (error_msg != NULL); - msg = g_strdup_printf (_("VPN Login Failure\n\nCould not start the " + cb_data = g_malloc0 (sizeof (DialogCBData)); + cb_data->title = g_strdup (_("VPN Error")); + + if (!strcmp (member, NM_DBUS_VPN_SIGNAL_LOGIN_FAILED)) + { + cb_data->msg = g_strdup_printf (_("VPN Login Failure\n\nCould not start the " "VPN connection '%s' due to a login failure.\n\nThe VPN service said: \"%s\""), vpn_name, error_msg); - g_idle_add ((GSourceFunc) nmwa_show_vpn_login_failure_dialog, msg); + } + else if (!strcmp (member, NM_DBUS_VPN_SIGNAL_LAUNCH_FAILED)) + { + cb_data->msg = g_strdup_printf (_("VPN Start Failure\n\nCould not start the " + "VPN connection '%s' due to a failure launching the VPN program.\n\nThe VPN service said: \"%s\""), vpn_name, error_msg); + } + else if (!strcmp (member, NM_DBUS_VPN_SIGNAL_CONNECT_FAILED)) + { + cb_data->msg = g_strdup_printf (_("VPN Connect Failure\n\nCould not start the " + "VPN connection '%s' due to a connection error.\n\nThe VPN service said: \"%s\""), vpn_name, error_msg); + } + + if (cb_data->msg) + g_idle_add ((GSourceFunc) nmwa_show_vpn_failure_dialog, cb_data); + else + free_dialog_cb_data (cb_data); } @@ -897,13 +937,20 @@ static void nmwa_start_redraw_timeout (NMWirelessApplet *applet) * pop up a warning or error dialog with certain text * */ -gboolean show_warning_dialog (gchar *mesg) +gboolean show_warning_dialog (char *mesg) { GtkWidget * dialog; + guint32 timestamp; dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, mesg, NULL); + + /* Bash focus-stealing prevention in the face */ + timestamp = gdk_x11_get_server_time (dialog->window); + gdk_x11_window_set_user_time (dialog->window, timestamp); + gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); + g_free (mesg); return FALSE; } @@ -923,7 +970,7 @@ void nmwa_schedule_warning_dialog (NMWirelessApplet *applet, const char *msg) g_return_if_fail (msg != NULL); lcl_msg = g_strdup (msg); - g_idle_add ((GSourceFunc) nmwa_show_vpn_login_failure_dialog, lcl_msg); + g_idle_add ((GSourceFunc) show_warning_dialog, lcl_msg); } diff --git a/gnome/applet/applet.h b/gnome/applet/applet.h index 77f324425d..bea119f017 100644 --- a/gnome/applet/applet.h +++ b/gnome/applet/applet.h @@ -147,7 +147,7 @@ NetworkDevice * nmwa_get_device_for_nm_path (GSList *dev_list, const char *nm_ NMWirelessApplet * nmwa_new (void); void nmwa_schedule_warning_dialog (NMWirelessApplet *applet, const char *msg); gboolean nmwa_driver_notify (gpointer user_data); -void nmwa_schedule_vpn_login_failure_dialog (NMWirelessApplet *applet, const char *vpn_name, const char *error_msg); +void nmwa_schedule_vpn_failure_dialog (NMWirelessApplet *applet, const char *member, const char *vpn_name, const char *error_msg); void nmwa_schedule_vpn_login_banner_dialog (NMWirelessApplet *applet, const char *vpn_name, const char *banner); NetworkDevice * nmwa_get_first_active_device (GSList *dev_list); diff --git a/gnome/applet/other-network-dialog.c b/gnome/applet/other-network-dialog.c index 53ed4e796e..eff8bb05b1 100644 --- a/gnome/applet/other-network-dialog.c +++ b/gnome/applet/other-network-dialog.c @@ -52,11 +52,11 @@ enum NMWAEncryptionKeyTypes static void update_button_cb (GtkWidget *widget, GladeXML *xml) { - gboolean enable = TRUE; - const char *text; - GtkButton *button; - GtkEntry *essid_entry; - GtkCheckButton *enc_check_button; + gboolean enable = FALSE; + const char * text; + GtkButton * button; + GtkEntry * essid_entry; + GtkCheckButton * enc_check_button; g_return_if_fail (xml != NULL); @@ -64,36 +64,36 @@ static void update_button_cb (GtkWidget *widget, GladeXML *xml) button = GTK_BUTTON (glade_xml_get_widget (xml, "ok_button")); enc_check_button = GTK_CHECK_BUTTON (glade_xml_get_widget (xml, "use_encryption_checkbox")); + /* An ESSID is required */ text = gtk_entry_get_text (essid_entry); - if (text[0] == '\000') - enable = FALSE; + if (text && strlen (text) > 0) + enable = TRUE; - /* If we're using encryptin, validate the settings */ - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (enc_check_button))) + /* If we're using encryption, validate the settings */ + if (enable && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (enc_check_button))) { - GtkComboBox *combo = GTK_COMBO_BOX (glade_xml_get_widget (xml, "key_type_combo")); - GtkEntry *passphrase_entry = GTK_ENTRY (glade_xml_get_widget (xml, "passphrase_entry")); - const char *passphrase_text = gtk_entry_get_text (passphrase_entry); + GtkComboBox * combo = GTK_COMBO_BOX (glade_xml_get_widget (xml, "key_type_combo")); + GtkEntry * passphrase_entry = GTK_ENTRY (glade_xml_get_widget (xml, "passphrase_entry")); + const char * passphrase_text = gtk_entry_get_text (passphrase_entry); - if (passphrase_text[0] == '\000') - enable = FALSE; - else + enable = FALSE; + switch (gtk_combo_box_get_active (combo)) { - int combo_choice = gtk_combo_box_get_active (combo); - switch (combo_choice) - { - case KEY_TYPE_ASCII_KEY: - if ((strlen (passphrase_text) != 5) && (strlen (passphrase_text) != 13)) - enable = FALSE; - break; - case KEY_TYPE_HEX_KEY: - if ((strlen (passphrase_text) != 10) && (strlen (passphrase_text) != 26)) - enable = FALSE; - break; - default: - break; - } - } + case KEY_TYPE_128_BIT_PASSPHRASE: + if (strlen (passphrase_text) > 0) + enable = TRUE; + break; + case KEY_TYPE_ASCII_KEY: + if ((strlen (passphrase_text) == 5) || (strlen (passphrase_text) == 13)) + enable = TRUE; + break; + case KEY_TYPE_HEX_KEY: + if ((strlen (passphrase_text) == 10) || (strlen (passphrase_text) == 26)) + enable = TRUE; + break; + default: + break; + } } gtk_widget_set_sensitive (GTK_WIDGET (button), enable); diff --git a/gnome/applet/passphrase-dialog.c b/gnome/applet/passphrase-dialog.c index 7f90962626..bb5180c65a 100644 --- a/gnome/applet/passphrase-dialog.c +++ b/gnome/applet/passphrase-dialog.c @@ -59,11 +59,11 @@ static GladeXML *get_dialog_xml (GtkWidget *dialog) static void update_button_cb (GtkWidget *widget, GladeXML *xml) { - GtkButton *button; - GtkComboBox *combo; - GtkEntry *passphrase_entry; - const char *passphrase_text; - gboolean enable = TRUE; + GtkButton * button; + GtkComboBox * combo; + GtkEntry * passphrase_entry; + const char * passphrase_text; + gboolean enable = FALSE; g_return_if_fail (xml != NULL); @@ -72,25 +72,23 @@ static void update_button_cb (GtkWidget *widget, GladeXML *xml) passphrase_entry = GTK_ENTRY (glade_xml_get_widget (xml, "passphrase_entry")); passphrase_text = gtk_entry_get_text (passphrase_entry); - if (passphrase_text[0] == '\000') - enable = FALSE; - else + switch (gtk_combo_box_get_active (combo)) { - int combo_choice = gtk_combo_box_get_active (combo); - switch (combo_choice) - { - case KEY_TYPE_ASCII_KEY: - if ((strlen (passphrase_text) != 5) && (strlen (passphrase_text) != 13)) - enable = FALSE; - break; - case KEY_TYPE_HEX_KEY: - if ((strlen (passphrase_text) != 10) && (strlen (passphrase_text) != 26)) - enable = FALSE; - break; - default: - break; - } - } + case KEY_TYPE_128_BIT_PASSPHRASE: + if (strlen (passphrase_text) > 0) + enable = TRUE; + break; + case KEY_TYPE_ASCII_KEY: + if ((strlen (passphrase_text) == 5) || (strlen (passphrase_text) == 13)) + enable = TRUE; + break; + case KEY_TYPE_HEX_KEY: + if ((strlen (passphrase_text) == 10) || (strlen (passphrase_text) == 26)) + enable = TRUE; + break; + default: + break; + } gtk_widget_set_sensitive (GTK_WIDGET (button), enable); } diff --git a/gnome/applet/wireless-applet.glade b/gnome/applet/wireless-applet.glade index 664b70e1cd..b7748c6bdd 100644 --- a/gnome/applet/wireless-applet.glade +++ b/gnome/applet/wireless-applet.glade @@ -16,6 +16,7 @@ False GDK_WINDOW_TYPE_HINT_DIALOG GDK_GRAVITY_NORTH_WEST + True False @@ -109,6 +110,10 @@ You have chosen log in to the wireless network '%s'. If you are sure this wirel 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -166,6 +171,7 @@ You have chosen log in to the wireless network '%s'. If you are sure this wirel False GDK_WINDOW_TYPE_HINT_DIALOG GDK_GRAVITY_NORTH_WEST + True False @@ -246,6 +252,10 @@ You have chosen log in to the wireless network '%s'. If you are sure this wirel 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -293,7 +303,7 @@ You have chosen log in to the wireless network '%s'. If you are sure this wirel 6 True - + Other Wireless Network... GTK_WINDOW_TOPLEVEL GTK_WIN_POS_NONE False @@ -305,6 +315,7 @@ You have chosen log in to the wireless network '%s'. If you are sure this wirel False GDK_WINDOW_TYPE_HINT_DIALOG GDK_GRAVITY_NORTH_WEST + True False @@ -396,6 +407,10 @@ You have chosen log in to the wireless network '%s'. If you are sure this wirel 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -427,6 +442,10 @@ You have chosen log in to the wireless network '%s'. If you are sure this wirel 0 0 wireless_adapter_combo + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -442,6 +461,8 @@ You have chosen log in to the wireless network '%s'. If you are sure this wirel True + False + True 1 @@ -467,6 +488,10 @@ You have chosen log in to the wireless network '%s'. If you are sure this wirel 0 0 essid_entry + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -487,7 +512,7 @@ You have chosen log in to the wireless network '%s'. If you are sure this wirel 0 True - * + * True @@ -540,6 +565,10 @@ You have chosen log in to the wireless network '%s'. If you are sure this wirel 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -564,6 +593,10 @@ You have chosen log in to the wireless network '%s'. If you are sure this wirel 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -584,7 +617,7 @@ You have chosen log in to the wireless network '%s'. If you are sure this wirel 0 True - * + * False @@ -602,6 +635,8 @@ You have chosen log in to the wireless network '%s'. If you are sure this wirel 128-bit passphrase (WEP) Ascii key (WEP) Hex key (WEP) + False + True 1 @@ -681,6 +716,7 @@ Hex key (WEP) False GDK_WINDOW_TYPE_HINT_DIALOG GDK_GRAVITY_NORTH_WEST + True False @@ -773,6 +809,10 @@ A passphrase or encryption key is required to access the wireless network '%s'.< 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -800,6 +840,10 @@ A passphrase or encryption key is required to access the wireless network '%s'.< 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -814,6 +858,8 @@ A passphrase or encryption key is required to access the wireless network '%s'.< 128-bit Passphrase (WEP) Ascii Key (WEP) Hex Key (WEP) + False + True 0 @@ -852,6 +898,10 @@ Hex Key (WEP) 0.5 0 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 0 @@ -870,7 +920,7 @@ Hex Key (WEP) 0 True - * + * True diff --git a/src/vpn-manager/nm-dbus-vpn.c b/src/vpn-manager/nm-dbus-vpn.c index ff5123b8e1..2238278cf7 100644 --- a/src/vpn-manager/nm-dbus-vpn.c +++ b/src/vpn-manager/nm-dbus-vpn.c @@ -92,21 +92,22 @@ void nm_dbus_vpn_signal_vpn_connection_change (DBusConnection *con, NMVPNConnect /* - * nnm_dbus_vpn_signal_vpn_login_failed + * nnm_dbus_vpn_signal_vpn_failure * - * Pass the VPN Login Failure message from the daemon to the bus. + * Proxy a VPN Failure message from the vpn daemon to the bus. * */ -void nm_dbus_vpn_signal_vpn_login_failed (DBusConnection *con, NMVPNConnection *vpn, const char *error_msg) +void nm_dbus_vpn_signal_vpn_failed (DBusConnection *con, const char *signal, NMVPNConnection *vpn, const char *error_msg) { DBusMessage *message; const char *vpn_name; g_return_if_fail (con != NULL); + g_return_if_fail (signal != NULL); g_return_if_fail (vpn != NULL); g_return_if_fail (error_msg != NULL); - if (!(message = dbus_message_new_signal (NM_DBUS_PATH_VPN, NM_DBUS_INTERFACE_VPN, "VPNLoginFailed"))) + if (!(message = dbus_message_new_signal (NM_DBUS_PATH_VPN, NM_DBUS_INTERFACE_VPN, signal))) { nm_warning ("Not enough memory for new dbus message!"); return; @@ -115,7 +116,7 @@ void nm_dbus_vpn_signal_vpn_login_failed (DBusConnection *con, NMVPNConnection * vpn_name = nm_vpn_connection_get_name (vpn); dbus_message_append_args (message, DBUS_TYPE_STRING, &vpn_name, DBUS_TYPE_STRING, &error_msg, DBUS_TYPE_INVALID); if (!dbus_connection_send (con, message, NULL)) - nm_warning ("Could not raise the VPNLoginFailed signal!"); + nm_warning ("Could not raise the %s signal!", signal); dbus_message_unref (message); } @@ -136,7 +137,7 @@ void nm_dbus_vpn_signal_vpn_login_banner (DBusConnection *con, NMVPNConnection * g_return_if_fail (vpn != NULL); g_return_if_fail (banner != NULL); - if (!(message = dbus_message_new_signal (NM_DBUS_PATH_VPN, NM_DBUS_INTERFACE_VPN, "VPNLoginBanner"))) + if (!(message = dbus_message_new_signal (NM_DBUS_PATH_VPN, NM_DBUS_INTERFACE_VPN, NM_DBUS_VPN_SIGNAL_LOGIN_BANNER))) { nm_warning ("Not enough memory for new dbus message!"); return; diff --git a/src/vpn-manager/nm-dbus-vpn.h b/src/vpn-manager/nm-dbus-vpn.h index 7868de669c..af072a30ec 100644 --- a/src/vpn-manager/nm-dbus-vpn.h +++ b/src/vpn-manager/nm-dbus-vpn.h @@ -32,7 +32,7 @@ void nm_dbus_vpn_update_one_vpn_connection (DBusConnection *connection, cons void nm_dbus_vpn_signal_vpn_connection_update (DBusConnection *con, NMVPNConnection *vpn, const char *signal); void nm_dbus_vpn_signal_vpn_connection_change (DBusConnection *con, NMVPNConnection *vpn); -void nm_dbus_vpn_signal_vpn_login_failed (DBusConnection *con, NMVPNConnection *vpn, const char *error_msg); +void nm_dbus_vpn_signal_vpn_failed (DBusConnection *con, const char *signal, NMVPNConnection *vpn, const char *error_msg); void nm_dbus_vpn_signal_vpn_login_banner (DBusConnection *con, NMVPNConnection *vpn, const char *banner); NMDbusMethodList * nm_dbus_vpn_methods_setup (void); diff --git a/src/vpn-manager/nm-vpn-manager.c b/src/vpn-manager/nm-vpn-manager.c index c0d2480081..b85f6105e5 100644 --- a/src/vpn-manager/nm-vpn-manager.c +++ b/src/vpn-manager/nm-vpn-manager.c @@ -527,11 +527,12 @@ static char *construct_op_from_service_name (const char *service_name) */ gboolean nm_vpn_manager_process_signal (NMVPNManager *manager, DBusMessage *message) { - const char *object_path; - const char *temp_op; - NMVPNConnection *active; - NMVPNService *service; - const char *service_name; + const char * object_path; + const char * member; + const char * temp_op; + NMVPNConnection * active; + NMVPNService * service; + const char * service_name; g_return_val_if_fail (manager != NULL, FALSE); g_return_val_if_fail (message != NULL, FALSE); @@ -539,6 +540,9 @@ gboolean nm_vpn_manager_process_signal (NMVPNManager *manager, DBusMessage *mess if (!(object_path = dbus_message_get_path (message))) return FALSE; + if (!(member = dbus_message_get_member (message))) + return FALSE; + if (!(active = nm_vpn_manager_get_active_vpn_connection (manager))) return FALSE; @@ -550,15 +554,17 @@ gboolean nm_vpn_manager_process_signal (NMVPNManager *manager, DBusMessage *mess if (!temp_op || (strcmp (object_path, temp_op) != 0)) return FALSE; - if (dbus_message_is_signal (message, service_name, NM_DBUS_VPN_SIGNAL_LOGIN_FAILED)) + if ( dbus_message_is_signal (message, service_name, NM_DBUS_VPN_SIGNAL_LOGIN_FAILED) + || dbus_message_is_signal (message, service_name, NM_DBUS_VPN_SIGNAL_LAUNCH_FAILED) + || dbus_message_is_signal (message, service_name, NM_DBUS_VPN_SIGNAL_CONNECT_FAILED)) { char *error_msg; char *blank_msg = ""; if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &error_msg, DBUS_TYPE_INVALID)) error_msg = blank_msg; - nm_warning ("VPN Login failed for service '%s' with message '%s'.", service_name, error_msg); - nm_dbus_vpn_signal_vpn_login_failed (manager->app_data->dbus_connection, active, error_msg); + nm_warning ("VPN failed for service '%s', signal '%s', with message '%s'.", service_name, member, error_msg); + nm_dbus_vpn_signal_vpn_failed (manager->app_data->dbus_connection, member, active, error_msg); } else if (dbus_message_is_signal (message, service_name, NM_DBUS_VPN_SIGNAL_STATE_CHANGE)) { diff --git a/vpn-daemons/vpnc/nm-vpnc-service.c b/vpn-daemons/vpnc/nm-vpnc-service.c index 5d8c5b84db..bd46dd0c43 100644 --- a/vpn-daemons/vpnc/nm-vpnc-service.c +++ b/vpn-daemons/vpnc/nm-vpnc-service.c @@ -39,7 +39,14 @@ #include "nm-vpnc-service.h" #include "nm-utils.h" -#define VPNC_BINARY_PATH_DEFAULT "/usr/sbin/vpnc" + +static char *vpnc_binary_paths[] = +{ + "/usr/sbin/vpnc", + "/sbin/vpnc", + NULL +}; + #define NM_VPNC_HELPER_PATH BINDIR"/nm-vpnc-service-vpnc-helper" #define NM_VPNC_PID_FILE_PATH LOCALSTATEDIR"/run/vpnc/pid" #define NM_VPNC_CONFIG_FILE_PATH LOCALSTATEDIR"/run/vpnc/nm-vpnc-service-vpnc.conf" @@ -111,6 +118,60 @@ static void nm_vpnc_dbus_signal_login_failed (NmVpncData *data) } +/* + * nm_vpnc_dbus_signal_launch_failed + * + * Signal the bus that we couldn't launch the VPN daemon. + * + */ +static void nm_vpnc_dbus_signal_launch_failed (NmVpncData *data) +{ + DBusMessage *message; + const char *error_msg = "The VPN login failed because the VPN program could not be started."; + + g_return_if_fail (data != NULL); + + if (!(message = dbus_message_new_signal (NM_DBUS_PATH_VPNC, NM_DBUS_INTERFACE_VPNC, NM_DBUS_VPN_SIGNAL_LAUNCH_FAILED))) + { + nm_warning ("Not enough memory for new dbus message!"); + return; + } + + dbus_message_append_args (message, DBUS_TYPE_STRING, &error_msg, DBUS_TYPE_INVALID); + if (!dbus_connection_send (data->con, message, NULL)) + nm_warning ("Could not raise the signal!"); + + dbus_message_unref (message); +} + + +/* + * nm_vpnc_dbus_signal_connect_failed + * + * Signal the bus that VPN daemon failed to connect to the VPN concentrator. + * + */ +static void nm_vpnc_dbus_signal_connect_failed (NmVpncData *data) +{ + DBusMessage *message; + const char *error_msg = "The VPN login failed because the VPN program could not connect to the VPN server."; + + g_return_if_fail (data != NULL); + + if (!(message = dbus_message_new_signal (NM_DBUS_PATH_VPNC, NM_DBUS_INTERFACE_VPNC, NM_DBUS_VPN_SIGNAL_CONNECT_FAILED))) + { + nm_warning ("Not enough memory for new dbus message!"); + return; + } + + dbus_message_append_args (message, DBUS_TYPE_STRING, &error_msg, DBUS_TYPE_INVALID); + if (!dbus_connection_send (data->con, message, NULL)) + nm_warning ("Could not raise the signal!"); + + dbus_message_unref (message); +} + + /* * nm_vpnc_dbus_signal_state_change * @@ -218,6 +279,7 @@ static gboolean nm_vpnc_helper_timer_cb (NmVpncData *data) g_return_val_if_fail (data != NULL, FALSE); + nm_vpnc_dbus_signal_connect_failed (data); nm_vpnc_dbus_handle_stop_vpn (data); return FALSE; @@ -287,11 +349,12 @@ static void vpnc_watch_cb (GPid pid, gint status, gpointer user_data) /* Must be after data->state is set since signals use data->state */ switch (error) { - case 2: /* Couldn't log in */ + case 2: /* Couldn't log in due to bad user/pass */ nm_vpnc_dbus_signal_login_failed (data); break; case 1: /* Other error (couldn't bind to address, etc) */ + nm_vpnc_dbus_signal_connect_failed (data); break; case 0: /* Success, vpnc has daemonized */ @@ -339,7 +402,7 @@ static void vpnc_watch_cb (GPid pid, gint status, gpointer user_data) static gboolean nm_vpnc_start_vpnc_binary (NmVpncData *data) { GPid pid; - const char * vpnc_binary; + char ** vpnc_binary = NULL; GPtrArray * vpnc_argv; GError * error = NULL; gboolean success = FALSE; @@ -351,9 +414,23 @@ static gboolean nm_vpnc_start_vpnc_binary (NmVpncData *data) unlink (NM_VPNC_PID_FILE_PATH); + /* Find vpnc */ + vpnc_binary = vpnc_binary_paths; + while (*vpnc_binary != NULL) + { + if (g_file_test (*vpnc_binary, G_FILE_TEST_EXISTS)) + break; + vpnc_binary++; + } + + if (!*vpnc_binary) + { + nm_info ("Could not find vpnc binary."); + return FALSE; + } + vpnc_argv = g_ptr_array_new (); - vpnc_binary = g_getenv ("VPNC_BINARY_PATH") ? g_getenv ("VPNC_BINARY_PATH") : VPNC_BINARY_PATH_DEFAULT; - g_ptr_array_add (vpnc_argv, (char *) vpnc_binary); + g_ptr_array_add (vpnc_argv, (char *) (*vpnc_binary)); g_ptr_array_add (vpnc_argv, "--script"); g_ptr_array_add (vpnc_argv, NM_VPNC_HELPER_PATH); g_ptr_array_add (vpnc_argv, "--pid-file"); @@ -493,7 +570,10 @@ static gboolean nm_vpnc_dbus_handle_start_vpn (DBusMessage *message, DBusMessage if (nm_vpnc_config_file_generate (user_name, password, data_items, num_items)) success = nm_vpnc_start_vpnc_binary (data); if (!success) + { + nm_vpnc_dbus_signal_launch_failed (data); nm_vpnc_set_state (data, NM_VPN_STATE_STOPPED); + } out: return success;