~network-manager/network-manager/ubuntu.hardy.07

« back to all changes in this revision

Viewing changes to vpn-daemons/vpnc/properties/nm-vpnc.c

(merge) RELEASE 0.7~~svn20080928t225540+eni0-0ubuntu1 to ubuntu/intrepid

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2
2
/***************************************************************************
3
 
 * CVSID: $Id: nm-vpnc.c 4030 2008-09-03 21:00:36Z dcbw $
 
3
 * CVSID: $Id: nm-vpnc.c 4053 2008-09-09 20:29:59Z dcbw $
4
4
 *
5
5
 * nm-vpnc.c : GNOME UI dialogs for configuring vpnc VPN connections
6
6
 *
113
113
                        ENUM_ENTRY (VPNC_PLUGIN_UI_ERROR_INVALID_PROPERTY, "InvalidProperty"),
114
114
                        /* The specified property was missing and is required. */
115
115
                        ENUM_ENTRY (VPNC_PLUGIN_UI_ERROR_MISSING_PROPERTY, "MissingProperty"),
 
116
                        /* The connection was missing invalid. */
 
117
                        ENUM_ENTRY (VPNC_PLUGIN_UI_ERROR_INVALID_CONNECTION, "InvalidConnection"),
116
118
                        { 0, 0, 0 }
117
119
                };
118
120
                etype = g_enum_register_static ("VpncPluginUiError", values);
169
171
        /* Grab secrets from the keyring */
170
172
        if (connection) {
171
173
                NMSettingConnection *s_con;
172
 
 
173
 
                s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
174
 
                keyring_helpers_lookup_secrets (s_con->uuid, &password, &group_password, NULL);
 
174
                NMSettingVPN *s_vpn;
 
175
                const char *tmp;
 
176
 
 
177
                if (nm_connection_get_scope (connection) == NM_CONNECTION_SCOPE_SYSTEM) {
 
178
                        s_vpn = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN);
 
179
                        if (s_vpn) {
 
180
                                tmp = g_hash_table_lookup (s_vpn->secrets, NM_VPNC_KEY_XAUTH_PASSWORD);
 
181
                                if (tmp)
 
182
                                        password = gnome_keyring_memory_strdup (tmp);
 
183
 
 
184
                                tmp = g_hash_table_lookup (s_vpn->secrets, NM_VPNC_KEY_SECRET);
 
185
                                if (tmp)
 
186
                                        group_password = gnome_keyring_memory_strdup (tmp);
 
187
                        }
 
188
                } else {
 
189
                        s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
 
190
                        keyring_helpers_lookup_secrets (s_con->uuid, &password, &group_password, NULL);
 
191
                }
175
192
        }
176
193
 
177
194
        /* User password */
178
195
        widget = glade_xml_get_widget (priv->xml, "user_password_entry");
179
 
        gtk_size_group_add_widget (priv->group, GTK_WIDGET (widget));
180
196
        if (!widget)
181
197
                goto out;
182
198
        if (password)
183
199
                gtk_entry_set_text (GTK_ENTRY (widget), password);
 
200
        gtk_size_group_add_widget (priv->group, GTK_WIDGET (widget));
184
201
        g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (stuff_changed_cb), self);
185
202
 
186
203
        /* Group password */
187
204
        widget = glade_xml_get_widget (priv->xml, "group_password_entry");
188
 
        gtk_size_group_add_widget (priv->group, GTK_WIDGET (widget));
189
205
        if (!widget)
190
206
                goto out;
191
207
        if (group_password)
192
208
                gtk_entry_set_text (GTK_ENTRY (widget), group_password);
 
209
        gtk_size_group_add_widget (priv->group, GTK_WIDGET (widget));
193
210
        g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (stuff_changed_cb), self);
194
211
 
195
212
        success = TRUE;
473
490
                                     g_strdup_printf ("%d", priv->orig_dpd_timeout));
474
491
        }
475
492
 
 
493
        /* System secrets get stored in the connection, user secrets are saved
 
494
         * via the save_secrets() hook.
 
495
         */
 
496
        if (nm_connection_get_scope (connection) == NM_CONNECTION_SCOPE_SYSTEM) {
 
497
                /* User password */
 
498
                widget = glade_xml_get_widget (priv->xml, "user_password_entry");
 
499
                str = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
 
500
                if (str && strlen (str)) {
 
501
                        g_hash_table_insert (s_vpn->secrets,
 
502
                                             g_strdup (NM_VPNC_KEY_XAUTH_PASSWORD),
 
503
                                             g_strdup (str));
 
504
                }
 
505
 
 
506
                /* Group password */
 
507
                widget = glade_xml_get_widget (priv->xml, "group_password_entry");
 
508
                str = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
 
509
                if (str && strlen (str)) {
 
510
                        g_hash_table_insert (s_vpn->secrets,
 
511
                                             g_strdup (NM_VPNC_KEY_SECRET),
 
512
                                             g_strdup (str));
 
513
                }
 
514
        }
 
515
 
476
516
        nm_connection_add_setting (connection, NM_SETTING (s_vpn));
477
517
        return TRUE;
478
518
}
479
519
 
 
520
static gboolean
 
521
save_secrets (NMVpnPluginUiWidgetInterface *iface,
 
522
              NMConnection *connection,
 
523
              GError **error)
 
524
{
 
525
        VpncPluginUiWidget *self = VPNC_PLUGIN_UI_WIDGET (iface);
 
526
        VpncPluginUiWidgetPrivate *priv = VPNC_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
 
527
        GnomeKeyringResult ret;
 
528
        NMSettingConnection *s_con;
 
529
        GtkWidget *widget;
 
530
        const char *str;
 
531
 
 
532
        s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
 
533
        if (!s_con) {
 
534
                g_set_error (error,
 
535
                             VPNC_PLUGIN_UI_ERROR,
 
536
                             VPNC_PLUGIN_UI_ERROR_INVALID_CONNECTION,
 
537
                             "missing 'connection' setting");
 
538
                return FALSE;
 
539
        }
 
540
 
 
541
        widget = glade_xml_get_widget (priv->xml, "user_password_entry");
 
542
        g_assert (widget);
 
543
        str = gtk_entry_get_text (GTK_ENTRY (widget));
 
544
        if (str && strlen (str)) {
 
545
                ret = keyring_helpers_save_secret (s_con->uuid, s_con->id, NULL, VPNC_USER_PASSWORD, str);
 
546
                if (ret != GNOME_KEYRING_RESULT_OK)
 
547
                        g_warning ("%s: failed to save user password to keyring.", __func__);
 
548
        } else
 
549
                keyring_helpers_delete_secret (s_con->uuid, VPNC_USER_PASSWORD);
 
550
 
 
551
        widget = glade_xml_get_widget (priv->xml, "group_password_entry");
 
552
        g_assert (widget);
 
553
        str = gtk_entry_get_text (GTK_ENTRY (widget));
 
554
        if (str && strlen (str)) {
 
555
                ret = keyring_helpers_save_secret (s_con->uuid, s_con->id, NULL, VPNC_GROUP_PASSWORD, str);
 
556
                if (ret != GNOME_KEYRING_RESULT_OK)
 
557
                        g_warning ("%s: failed to save group password to keyring.", __func__);
 
558
        } else
 
559
                keyring_helpers_delete_secret (s_con->uuid, VPNC_GROUP_PASSWORD);
 
560
 
 
561
        return TRUE;
 
562
}
 
563
 
480
564
static NMVpnPluginUiWidgetInterface *
481
565
nm_vpn_plugin_ui_widget_interface_new (NMConnection *connection, GError **error)
482
566
{
561
645
        /* interface implementation */
562
646
        iface_class->get_widget = get_widget;
563
647
        iface_class->update_connection = update_connection;
 
648
        iface_class->save_secrets = save_secrets;
564
649
}
565
650
 
566
651
static GSList *
903
988
        return (NM_VPN_PLUGIN_UI_CAPABILITY_IMPORT | NM_VPN_PLUGIN_UI_CAPABILITY_EXPORT);
904
989
}
905
990
 
 
991
static gboolean
 
992
delete_connection (NMVpnPluginUiInterface *iface,
 
993
                   NMConnection *connection,
 
994
                   GError **error)
 
995
{
 
996
        NMSettingConnection *s_con;
 
997
 
 
998
        /* Remove any secrets in the keyring associated with this connection's UUID */
 
999
        s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
 
1000
        if (!s_con) {
 
1001
                g_set_error (error,
 
1002
                             VPNC_PLUGIN_UI_ERROR,
 
1003
                             VPNC_PLUGIN_UI_ERROR_INVALID_CONNECTION,
 
1004
                             "missing 'connection' setting");
 
1005
                return FALSE;
 
1006
        }
 
1007
 
 
1008
        if (!keyring_helpers_delete_secret (s_con->uuid, VPNC_USER_PASSWORD))
 
1009
                g_message ("%s: couldn't delete user password for '%s'", __func__, s_con->id);
 
1010
 
 
1011
        if (!keyring_helpers_delete_secret (s_con->uuid, VPNC_GROUP_PASSWORD))
 
1012
                g_message ("%s: couldn't delete group password for '%s'", __func__, s_con->id);
 
1013
 
 
1014
        return TRUE;
 
1015
}
 
1016
 
906
1017
static NMVpnPluginUiWidgetInterface *
907
1018
ui_factory (NMVpnPluginUiInterface *iface, NMConnection *connection, GError **error)
908
1019
{
963
1074
        iface_class->import = import;
964
1075
        iface_class->export = export;
965
1076
        iface_class->get_suggested_name = get_suggested_name;
 
1077
        iface_class->delete_connection = delete_connection;
966
1078
}
967
1079
 
968
1080