NetworkManager r4053 - in trunk/vpn-daemons/vpnc: . auth-dialog common-gnome properties
- From: dcbw svn gnome org
- To: svn-commits-list gnome org
- Subject: NetworkManager r4053 - in trunk/vpn-daemons/vpnc: . auth-dialog common-gnome properties
- Date: Tue, 9 Sep 2008 20:29:59 +0000 (UTC)
Author: dcbw
Date: Tue Sep 9 20:29:59 2008
New Revision: 4053
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=4053&view=rev
Log:
2008-09-09 Dan Williams <dcbw redhat com>
* common-gnome/keyring-helpers.c
common-gnome/keyring-helpers.h
- Add defines for secret tags in the keyring
- (keyring_helpers_delete_secret): delete a secret from the keyring for
a given connection UUID
- (keyring_helpers_save_secret): vpn service is always going to be
vpnc's
* auth-dialog/main.c
- (get_secrets): use secret tag #defines; vpn service will always be
vpnc's
* properties/nm-vpnc.c
properties/nm-vpnc.h
- (fill_vpn_passwords): fill secrets in the UI if the connection is
system-scope
- (update_connection): fill secrets if the connection is system-scope
so they can be saved with the system settings service
- (save_secrets, delete_connection): implement
Modified:
trunk/vpn-daemons/vpnc/ChangeLog
trunk/vpn-daemons/vpnc/auth-dialog/main.c
trunk/vpn-daemons/vpnc/common-gnome/keyring-helpers.c
trunk/vpn-daemons/vpnc/common-gnome/keyring-helpers.h
trunk/vpn-daemons/vpnc/properties/nm-vpnc.c
trunk/vpn-daemons/vpnc/properties/nm-vpnc.h
Modified: trunk/vpn-daemons/vpnc/auth-dialog/main.c
==============================================================================
--- trunk/vpn-daemons/vpnc/auth-dialog/main.c (original)
+++ trunk/vpn-daemons/vpnc/auth-dialog/main.c Tue Sep 9 20:29:59 2008
@@ -43,7 +43,6 @@
static gboolean
get_secrets (const char *vpn_uuid,
const char *vpn_name,
- const char *vpn_service,
gboolean retry,
char **password,
char **group_password)
@@ -104,12 +103,12 @@
switch (gnome_two_password_dialog_get_remember (dialog)) {
case GNOME_TWO_PASSWORD_DIALOG_REMEMBER_SESSION:
- keyring_helpers_save_secret (vpn_uuid, vpn_name, vpn_service, "session", "password", *password);
- keyring_helpers_save_secret (vpn_uuid, vpn_name, vpn_service, "session", "group-password", *group_password);
+ keyring_helpers_save_secret (vpn_uuid, vpn_name, "session", VPNC_USER_PASSWORD, *password);
+ keyring_helpers_save_secret (vpn_uuid, vpn_name, "session", VPNC_GROUP_PASSWORD, *group_password);
break;
case GNOME_TWO_PASSWORD_DIALOG_REMEMBER_FOREVER:
- keyring_helpers_save_secret (vpn_uuid, vpn_name, vpn_service, NULL, "password", *password);
- keyring_helpers_save_secret (vpn_uuid, vpn_name, vpn_service, NULL, "group-password", *group_password);
+ keyring_helpers_save_secret (vpn_uuid, vpn_name, NULL, VPNC_USER_PASSWORD, *password);
+ keyring_helpers_save_secret (vpn_uuid, vpn_name, NULL, VPNC_GROUP_PASSWORD, *group_password);
break;
default:
break;
@@ -169,7 +168,7 @@
return 1;
}
- if (!get_secrets (vpn_uuid, vpn_name, vpn_service, retry, &password, &group_password))
+ if (!get_secrets (vpn_uuid, vpn_name, retry, &password, &group_password))
return 1;
/* dump the passwords to stdout */
Modified: trunk/vpn-daemons/vpnc/common-gnome/keyring-helpers.c
==============================================================================
--- trunk/vpn-daemons/vpnc/common-gnome/keyring-helpers.c (original)
+++ trunk/vpn-daemons/vpnc/common-gnome/keyring-helpers.c Tue Sep 9 20:29:59 2008
@@ -26,6 +26,7 @@
#include <nm-setting-vpn.h>
#include "keyring-helpers.h"
+#include "../src/nm-vpnc-service.h"
#define KEYRING_UUID_TAG "connection-uuid"
#define KEYRING_SN_TAG "setting-name"
@@ -82,11 +83,11 @@
g_return_val_if_fail (group_password != NULL, FALSE);
g_return_val_if_fail (*group_password == NULL, FALSE);
- *password = find_one_password (vpn_uuid, "password", is_session);
+ *password = find_one_password (vpn_uuid, VPNC_USER_PASSWORD, is_session);
if (!*password)
return FALSE;
- *group_password = find_one_password (vpn_uuid, "group-password", is_session);
+ *group_password = find_one_password (vpn_uuid, VPNC_GROUP_PASSWORD, is_session);
if (!*group_password) {
memset (*password, 0, strlen (*password));
gnome_keyring_memory_free (*password);
@@ -100,7 +101,6 @@
GnomeKeyringResult
keyring_helpers_save_secret (const char *vpn_uuid,
const char *vpn_name,
- const char *vpn_service,
const char *keyring,
const char *secret_name,
const char *secret)
@@ -113,7 +113,7 @@
display_name = g_strdup_printf ("VPN %s secret for %s/%s/" NM_SETTING_VPN_SETTING_NAME,
secret_name,
vpn_name,
- vpn_service);
+ NM_DBUS_SERVICE_VPNC);
attrs = gnome_keyring_attribute_list_new ();
gnome_keyring_attribute_list_append_string (attrs,
@@ -138,3 +138,47 @@
return ret;
}
+static void
+ignore_callback (GnomeKeyringResult result, gpointer data)
+{
+}
+
+gboolean
+keyring_helpers_delete_secret (const char *vpn_uuid,
+ const char *secret_name)
+{
+ GList *found = NULL, *iter;
+ GnomeKeyringResult ret;
+
+ g_return_val_if_fail (vpn_uuid != NULL, FALSE);
+ g_return_val_if_fail (secret_name != NULL, FALSE);
+
+ ret = gnome_keyring_find_itemsv_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET,
+ &found,
+ KEYRING_UUID_TAG,
+ GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
+ vpn_uuid,
+ KEYRING_SN_TAG,
+ GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
+ NM_SETTING_VPN_SETTING_NAME,
+ KEYRING_SK_TAG,
+ GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
+ secret_name,
+ NULL);
+ if (ret != GNOME_KEYRING_RESULT_OK && ret != GNOME_KEYRING_RESULT_NO_MATCH)
+ return FALSE;
+ if (g_list_length (found) == 0)
+ return TRUE;
+
+ /* delete them all */
+ for (iter = found; iter; iter = g_list_next (iter)) {
+ GnomeKeyringFound *item = (GnomeKeyringFound *) iter->data;
+
+ gnome_keyring_item_delete (item->keyring, item->item_id,
+ ignore_callback, NULL, NULL);
+ }
+
+ gnome_keyring_found_list_free (found);
+ return TRUE;
+}
+
Modified: trunk/vpn-daemons/vpnc/common-gnome/keyring-helpers.h
==============================================================================
--- trunk/vpn-daemons/vpnc/common-gnome/keyring-helpers.h (original)
+++ trunk/vpn-daemons/vpnc/common-gnome/keyring-helpers.h Tue Sep 9 20:29:59 2008
@@ -26,6 +26,9 @@
#include <glib.h>
#include <gnome-keyring.h>
+#define VPNC_USER_PASSWORD "password"
+#define VPNC_GROUP_PASSWORD "group-password"
+
gboolean keyring_helpers_lookup_secrets (const char *vpn_uuid,
char **password,
char **group_password,
@@ -33,10 +36,12 @@
GnomeKeyringResult keyring_helpers_save_secret (const char *vpn_uuid,
const char *vpn_name,
- const char *vpn_service,
const char *keyring,
const char *secret_name,
const char *secret);
+gboolean keyring_helpers_delete_secret (const char *vpn_uuid,
+ const char *secret_name);
+
#endif /* KEYRING_HELPERS_H */
Modified: trunk/vpn-daemons/vpnc/properties/nm-vpnc.c
==============================================================================
--- trunk/vpn-daemons/vpnc/properties/nm-vpnc.c (original)
+++ trunk/vpn-daemons/vpnc/properties/nm-vpnc.c Tue Sep 9 20:29:59 2008
@@ -113,6 +113,8 @@
ENUM_ENTRY (VPNC_PLUGIN_UI_ERROR_INVALID_PROPERTY, "InvalidProperty"),
/* The specified property was missing and is required. */
ENUM_ENTRY (VPNC_PLUGIN_UI_ERROR_MISSING_PROPERTY, "MissingProperty"),
+ /* The connection was missing invalid. */
+ ENUM_ENTRY (VPNC_PLUGIN_UI_ERROR_INVALID_CONNECTION, "InvalidConnection"),
{ 0, 0, 0 }
};
etype = g_enum_register_static ("VpncPluginUiError", values);
@@ -169,27 +171,42 @@
/* Grab secrets from the keyring */
if (connection) {
NMSettingConnection *s_con;
+ NMSettingVPN *s_vpn;
+ const char *tmp;
- s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
- keyring_helpers_lookup_secrets (s_con->uuid, &password, &group_password, NULL);
+ if (nm_connection_get_scope (connection) == NM_CONNECTION_SCOPE_SYSTEM) {
+ s_vpn = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN);
+ if (s_vpn) {
+ tmp = g_hash_table_lookup (s_vpn->secrets, NM_VPNC_KEY_XAUTH_PASSWORD);
+ if (tmp)
+ password = gnome_keyring_memory_strdup (tmp);
+
+ tmp = g_hash_table_lookup (s_vpn->secrets, NM_VPNC_KEY_SECRET);
+ if (tmp)
+ group_password = gnome_keyring_memory_strdup (tmp);
+ }
+ } else {
+ s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
+ keyring_helpers_lookup_secrets (s_con->uuid, &password, &group_password, NULL);
+ }
}
/* User password */
widget = glade_xml_get_widget (priv->xml, "user_password_entry");
- gtk_size_group_add_widget (priv->group, GTK_WIDGET (widget));
if (!widget)
goto out;
if (password)
gtk_entry_set_text (GTK_ENTRY (widget), password);
+ gtk_size_group_add_widget (priv->group, GTK_WIDGET (widget));
g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (stuff_changed_cb), self);
/* Group password */
widget = glade_xml_get_widget (priv->xml, "group_password_entry");
- gtk_size_group_add_widget (priv->group, GTK_WIDGET (widget));
if (!widget)
goto out;
if (group_password)
gtk_entry_set_text (GTK_ENTRY (widget), group_password);
+ gtk_size_group_add_widget (priv->group, GTK_WIDGET (widget));
g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (stuff_changed_cb), self);
success = TRUE;
@@ -473,10 +490,77 @@
g_strdup_printf ("%d", priv->orig_dpd_timeout));
}
+ /* System secrets get stored in the connection, user secrets are saved
+ * via the save_secrets() hook.
+ */
+ if (nm_connection_get_scope (connection) == NM_CONNECTION_SCOPE_SYSTEM) {
+ /* User password */
+ widget = glade_xml_get_widget (priv->xml, "user_password_entry");
+ str = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
+ if (str && strlen (str)) {
+ g_hash_table_insert (s_vpn->secrets,
+ g_strdup (NM_VPNC_KEY_XAUTH_PASSWORD),
+ g_strdup (str));
+ }
+
+ /* Group password */
+ widget = glade_xml_get_widget (priv->xml, "group_password_entry");
+ str = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
+ if (str && strlen (str)) {
+ g_hash_table_insert (s_vpn->secrets,
+ g_strdup (NM_VPNC_KEY_SECRET),
+ g_strdup (str));
+ }
+ }
+
nm_connection_add_setting (connection, NM_SETTING (s_vpn));
return TRUE;
}
+static gboolean
+save_secrets (NMVpnPluginUiWidgetInterface *iface,
+ NMConnection *connection,
+ GError **error)
+{
+ VpncPluginUiWidget *self = VPNC_PLUGIN_UI_WIDGET (iface);
+ VpncPluginUiWidgetPrivate *priv = VPNC_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
+ GnomeKeyringResult ret;
+ NMSettingConnection *s_con;
+ GtkWidget *widget;
+ const char *str;
+
+ s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
+ if (!s_con) {
+ g_set_error (error,
+ VPNC_PLUGIN_UI_ERROR,
+ VPNC_PLUGIN_UI_ERROR_INVALID_CONNECTION,
+ "missing 'connection' setting");
+ return FALSE;
+ }
+
+ widget = glade_xml_get_widget (priv->xml, "user_password_entry");
+ g_assert (widget);
+ str = gtk_entry_get_text (GTK_ENTRY (widget));
+ if (str && strlen (str)) {
+ ret = keyring_helpers_save_secret (s_con->uuid, s_con->id, NULL, VPNC_USER_PASSWORD, str);
+ if (ret != GNOME_KEYRING_RESULT_OK)
+ g_warning ("%s: failed to save user password to keyring.", __func__);
+ } else
+ keyring_helpers_delete_secret (s_con->uuid, VPNC_USER_PASSWORD);
+
+ widget = glade_xml_get_widget (priv->xml, "group_password_entry");
+ g_assert (widget);
+ str = gtk_entry_get_text (GTK_ENTRY (widget));
+ if (str && strlen (str)) {
+ ret = keyring_helpers_save_secret (s_con->uuid, s_con->id, NULL, VPNC_GROUP_PASSWORD, str);
+ if (ret != GNOME_KEYRING_RESULT_OK)
+ g_warning ("%s: failed to save group password to keyring.", __func__);
+ } else
+ keyring_helpers_delete_secret (s_con->uuid, VPNC_GROUP_PASSWORD);
+
+ return TRUE;
+}
+
static NMVpnPluginUiWidgetInterface *
nm_vpn_plugin_ui_widget_interface_new (NMConnection *connection, GError **error)
{
@@ -561,6 +645,7 @@
/* interface implementation */
iface_class->get_widget = get_widget;
iface_class->update_connection = update_connection;
+ iface_class->save_secrets = save_secrets;
}
static GSList *
@@ -903,6 +988,32 @@
return (NM_VPN_PLUGIN_UI_CAPABILITY_IMPORT | NM_VPN_PLUGIN_UI_CAPABILITY_EXPORT);
}
+static gboolean
+delete_connection (NMVpnPluginUiInterface *iface,
+ NMConnection *connection,
+ GError **error)
+{
+ NMSettingConnection *s_con;
+
+ /* Remove any secrets in the keyring associated with this connection's UUID */
+ s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
+ if (!s_con) {
+ g_set_error (error,
+ VPNC_PLUGIN_UI_ERROR,
+ VPNC_PLUGIN_UI_ERROR_INVALID_CONNECTION,
+ "missing 'connection' setting");
+ return FALSE;
+ }
+
+ if (!keyring_helpers_delete_secret (s_con->uuid, VPNC_USER_PASSWORD))
+ g_message ("%s: couldn't delete user password for '%s'", __func__, s_con->id);
+
+ if (!keyring_helpers_delete_secret (s_con->uuid, VPNC_GROUP_PASSWORD))
+ g_message ("%s: couldn't delete group password for '%s'", __func__, s_con->id);
+
+ return TRUE;
+}
+
static NMVpnPluginUiWidgetInterface *
ui_factory (NMVpnPluginUiInterface *iface, NMConnection *connection, GError **error)
{
@@ -963,6 +1074,7 @@
iface_class->import = import;
iface_class->export = export;
iface_class->get_suggested_name = get_suggested_name;
+ iface_class->delete_connection = delete_connection;
}
Modified: trunk/vpn-daemons/vpnc/properties/nm-vpnc.h
==============================================================================
--- trunk/vpn-daemons/vpnc/properties/nm-vpnc.h (original)
+++ trunk/vpn-daemons/vpnc/properties/nm-vpnc.h Tue Sep 9 20:29:59 2008
@@ -29,7 +29,8 @@
{
VPNC_PLUGIN_UI_ERROR_UNKNOWN = 0,
VPNC_PLUGIN_UI_ERROR_INVALID_PROPERTY,
- VPNC_PLUGIN_UI_ERROR_MISSING_PROPERTY
+ VPNC_PLUGIN_UI_ERROR_MISSING_PROPERTY,
+ VPNC_PLUGIN_UI_ERROR_INVALID_CONNECTION
} VpncPluginUiError;
#define VPNC_TYPE_PLUGIN_UI_ERROR (vpnc_plugin_ui_error_get_type ())
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]