1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright (C) 2009 Red Hat, Inc.
*/
#include <string.h>
#include "nm-marshal.h"
#include "nm-secrets-provider-interface.h"
#include <nm-setting-8021x.h>
#include <nm-setting-wireless-security.h>
#include "nm-logging.h"
static void
nm_secrets_provider_interface_init (gpointer g_iface)
{
GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
static gboolean initialized = FALSE;
if (initialized)
return;
initialized = TRUE;
/* Signals */
g_signal_new ("manager-get-secrets",
iface_type,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (NMSecretsProviderInterface, manager_get_secrets),
NULL, NULL,
_nm_marshal_BOOLEAN__POINTER_STRING_BOOLEAN_UINT_STRING_STRING,
G_TYPE_BOOLEAN, 6,
G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING);
g_signal_new ("manager-cancel-secrets",
iface_type,
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMSecretsProviderInterface, manager_cancel_secrets),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
}
GType
nm_secrets_provider_interface_get_type (void)
{
static GType interface_type = 0;
if (!interface_type) {
const GTypeInfo interface_info = {
sizeof (NMSecretsProviderInterface), /* class_size */
nm_secrets_provider_interface_init, /* base_init */
NULL, /* base_finalize */
NULL,
NULL, /* class_finalize */
NULL, /* class_data */
0,
0, /* n_preallocs */
NULL
};
interface_type = g_type_register_static (G_TYPE_INTERFACE,
"NMSecretsProviderInterface",
&interface_info, 0);
g_type_interface_add_prerequisite (interface_type, G_TYPE_OBJECT);
}
return interface_type;
}
gboolean
nm_secrets_provider_interface_get_secrets (NMSecretsProviderInterface *self,
NMConnection *connection,
const char *setting_name,
gboolean request_new,
RequestSecretsCaller caller,
const char *hint1,
const char *hint2)
{
guint success = FALSE;
g_return_val_if_fail (self != NULL, FALSE);
g_return_val_if_fail (NM_IS_SECRETS_PROVIDER_INTERFACE (self), FALSE);
g_return_val_if_fail (connection != NULL, FALSE);
g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
g_return_val_if_fail (setting_name != NULL, FALSE);
nm_secrets_provider_interface_cancel_get_secrets (self);
g_signal_emit_by_name (self, "manager-get-secrets",
connection, setting_name, request_new, caller, hint1, hint2,
&success);
if (!success) {
nm_log_warn (LOGD_CORE, "failed to get connection secrets.");
return FALSE;
}
return TRUE;
}
void
nm_secrets_provider_interface_cancel_get_secrets (NMSecretsProviderInterface *self)
{
g_return_if_fail (self != NULL);
g_return_if_fail (NM_IS_SECRETS_PROVIDER_INTERFACE (self));
g_signal_emit_by_name (self, "manager-cancel-secrets");
}
static void
add_one_key_to_list (gpointer key, gpointer data, gpointer user_data)
{
GSList **list = (GSList **) user_data;
*list = g_slist_append (*list, key);
}
static gint
settings_order_func (gconstpointer a, gconstpointer b)
{
/* Just ensure the 802.1x setting gets processed _before_ the
* wireless-security one.
*/
if ( !strcmp (a, NM_SETTING_802_1X_SETTING_NAME)
&& !strcmp (b, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME))
return -1;
if ( !strcmp (a, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME)
&& !strcmp (b, NM_SETTING_802_1X_SETTING_NAME))
return 1;
return 0;
}
void
nm_secrets_provider_interface_get_secrets_result (NMSecretsProviderInterface *self,
const char *setting_name,
RequestSecretsCaller caller,
GHashTable *settings,
GError *error)
{
GSList *keys = NULL, *iter;
GSList *updated = NULL;
GError *tmp_error = NULL;
g_return_if_fail (self != NULL);
g_return_if_fail (NM_IS_SECRETS_PROVIDER_INTERFACE (self));
if (error) {
NM_SECRETS_PROVIDER_INTERFACE_GET_INTERFACE (self)->result (self,
setting_name,
caller,
NULL,
error);
return;
}
if (g_hash_table_size (settings) == 0) {
g_set_error (&tmp_error, 0, 0, "%s", "no secrets were received!");
NM_SECRETS_PROVIDER_INTERFACE_GET_INTERFACE (self)->result (self,
setting_name,
caller,
NULL,
tmp_error);
g_clear_error (&tmp_error);
return;
}
g_hash_table_foreach (settings, add_one_key_to_list, &keys);
keys = g_slist_sort (keys, settings_order_func);
for (iter = keys; iter; iter = g_slist_next (iter)) {
GHashTable *hash;
const char *name = (const char *) iter->data;
hash = g_hash_table_lookup (settings, name);
if (!hash) {
nm_log_warn (LOGD_CORE, "couldn't get setting secrets for '%s'", name);
continue;
}
if (NM_SECRETS_PROVIDER_INTERFACE_GET_INTERFACE (self)->update_setting (self, name, hash))
updated = g_slist_append (updated, (gpointer) setting_name);
}
g_slist_free (keys);
if (g_slist_length (updated)) {
NM_SECRETS_PROVIDER_INTERFACE_GET_INTERFACE (self)->result (self,
setting_name,
caller,
updated,
NULL);
} else {
g_set_error (&tmp_error, 0, 0, "%s", "no secrets updated because no valid "
"settings were received!");
NM_SECRETS_PROVIDER_INTERFACE_GET_INTERFACE (self)->result (self,
setting_name,
caller,
NULL,
tmp_error);
g_clear_error (&tmp_error);
}
g_slist_free (updated);
}
|