1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2
/* NetworkManager Wireless Applet -- Display wireless access points and allow user control
4
* Dan Williams <dcbw@redhat.com>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License along
17
* with this program; if not, write to the Free Software Foundation, Inc.,
18
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
* (C) Copyright 2004 - 2008 Red Hat, Inc.
24
#include <gnome-keyring-memory.h>
26
#include <nm-setting-vpn.h>
28
#include "keyring-helpers.h"
29
#include "../src/nm-openvpn-service.h"
31
#define KEYRING_UUID_TAG "connection-uuid"
32
#define KEYRING_SN_TAG "setting-name"
33
#define KEYRING_SK_TAG "setting-key"
36
keyring_helpers_lookup_secret (const char *vpn_uuid,
37
const char *secret_name,
40
GList *found_list = NULL;
41
GnomeKeyringResult ret;
42
GnomeKeyringFound *found;
45
ret = gnome_keyring_find_itemsv_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET,
48
GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
51
GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
52
NM_SETTING_VPN_SETTING_NAME,
54
GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
57
if ((ret != GNOME_KEYRING_RESULT_OK) || (g_list_length (found_list) == 0))
60
found = (GnomeKeyringFound *) found_list->data;
62
if (strcmp (found->keyring, "session") == 0)
67
secret = found->secret ? g_strdup (found->secret) : NULL;
68
gnome_keyring_found_list_free (found_list);
74
keyring_helpers_save_secret (const char *vpn_uuid,
77
const char *secret_name,
81
GnomeKeyringResult ret;
82
GnomeKeyringAttributeList *attrs = NULL;
85
display_name = g_strdup_printf ("VPN %s secret for %s/%s/" NM_SETTING_VPN_SETTING_NAME,
88
NM_DBUS_SERVICE_OPENVPN);
90
attrs = gnome_keyring_attribute_list_new ();
91
gnome_keyring_attribute_list_append_string (attrs,
94
gnome_keyring_attribute_list_append_string (attrs,
96
NM_SETTING_VPN_SETTING_NAME);
97
gnome_keyring_attribute_list_append_string (attrs,
101
ret = gnome_keyring_item_create_sync (keyring,
102
GNOME_KEYRING_ITEM_GENERIC_SECRET,
108
gnome_keyring_attribute_list_free (attrs);
109
g_free (display_name);
114
ignore_callback (GnomeKeyringResult result, gpointer data)
119
keyring_helpers_delete_secret (const char *vpn_uuid,
120
const char *secret_name)
122
GList *found = NULL, *iter;
123
GnomeKeyringResult ret;
125
g_return_val_if_fail (vpn_uuid != NULL, FALSE);
126
g_return_val_if_fail (secret_name != NULL, FALSE);
128
ret = gnome_keyring_find_itemsv_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET,
131
GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
134
GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
135
NM_SETTING_VPN_SETTING_NAME,
137
GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
140
if (ret != GNOME_KEYRING_RESULT_OK && ret != GNOME_KEYRING_RESULT_NO_MATCH)
142
if (g_list_length (found) == 0)
145
/* delete them all */
146
for (iter = found; iter; iter = g_list_next (iter)) {
147
GnomeKeyringFound *item = (GnomeKeyringFound *) iter->data;
149
gnome_keyring_item_delete (item->keyring, item->item_id,
150
ignore_callback, NULL, NULL);
153
gnome_keyring_found_list_free (found);