1
/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
3
/* NetworkManager system settings service (ifupdown)
5
* Alexander Sack <asac@ubuntu.com>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
* (C) Copyright 2008 Canonical Ltd.
3
25
#include <arpa/inet.h>
120
NMSettingWireless *wireless_setting;
139
NMSettingWireless *wireless_setting = NULL;
122
141
if(value && !strcmp("ppp", value)) {
126
wireless_setting = NM_SETTING_WIRELESS(nm_connection_get_setting
127
(connection, NM_TYPE_SETTING_WIRELESS));
129
g_debug("update wireless settings (%s).", block->name);
130
if(!wireless_setting) {
131
wireless_setting = NM_SETTING_WIRELESS(nm_setting_wireless_new());
145
PLUGIN_PRINT ("SCPlugin-Ifupdown", "update wireless settings (%s).", block->name);
146
wireless_setting = NM_SETTING_WIRELESS(nm_setting_wireless_new());
135
g_debug("testing key/value (%s/%s)", curr->key, curr->data);
136
149
if(strlen(curr->key) > wireless_l &&
137
150
!strncmp("wireless-", curr->key, wireless_l)) {
138
151
const gchar* newkey = map_by_mapping(mapping, curr->key+wireless_l);
139
g_debug("setting wireless newkey(%s)=data(%s)", newkey, curr->data);
152
PLUGIN_PRINT ("SCPlugin-Ifupdown", "wireless setting key: %s='%s'",
140
154
g_object_set(wireless_setting,
141
155
newkey, curr->data,
148
162
gint len = strlen(curr->data);
149
163
wireless_setting->ssid = g_byte_array_sized_new (len);
150
164
g_byte_array_append (wireless_setting->ssid, (const guint8 *) curr->data, len);
151
g_debug("ssid = %d", wireless_setting->ssid->len);
165
PLUGIN_PRINT("SCPlugin-Ifupdown", "setting wpa ssid = %d", wireless_setting->ssid->len);
152
166
} else if(newkey) {
154
168
g_object_set(wireless_setting,
158
g_debug("unknown wpa- key (%s) found in /etc/network/interfaces"
159
" iface (%s) definition", curr->key, block->name);
171
PLUGIN_PRINT ("SCPlugin-Ifupdown", "setting wpa newkey(%s)=data(%s)", newkey, curr->data);
161
g_debug("setting 1 wpa newkey(%s)=data(%s)", newkey, curr->data);
163
g_debug(" => not a wireless setting!");
165
174
curr = curr->next;
167
nm_connection_add_setting(connection, NM_SETTING(wireless_setting));
176
nm_connection_add_setting(connection, (NMSetting*) wireless_setting);
170
179
typedef gchar* (*IfupdownStrDupeFunc) (gpointer value, gpointer data);
180
typedef gpointer (*IfupdownStrToTypeFunc) (const gchar* value);
173
183
normalize_dupe (gpointer value, gpointer data) {
227
265
{"pairwise", normalize_tolower},
228
266
{"proto", normalize_tolower},
229
267
{"pin", normalize_dupe},
268
{"wep-key0", normalize_dupe},
269
{"wep-key1", normalize_dupe},
270
{"wep-key2", normalize_dupe},
271
{"wep-key3", normalize_dupe},
275
struct _Mapping type_mapping[] = {
276
{"group", string_to_glist_of_strings},
277
{"pairwise", string_to_glist_of_strings},
278
{"proto", string_to_glist_of_strings},
233
283
NMSettingWirelessSecurity *wireless_security_setting;
234
284
NMSettingWireless *s_wireless;
285
gboolean security = FALSE;
237
287
if(value && !strcmp("ppp", value)) {
241
291
s_wireless = NM_SETTING_WIRELESS(nm_connection_get_setting(connection,
242
NM_TYPE_SETTING_WIRELESS));
244
g_warning("no wireless setting for wireless-security settings");
292
NM_TYPE_SETTING_WIRELESS));
293
g_return_if_fail(s_wireless);
246
g_debug("update wireless settings (%s).", block->name);
295
PLUGIN_PRINT ("SCPlugin-Ifupdown","update wireless security settings (%s).", block->name);
247
296
wireless_security_setting =
248
297
NM_SETTING_WIRELESS_SECURITY(nm_setting_wireless_security_new());
251
g_debug("testing key/value (%s/%s)", curr->key, curr->data);
252
300
if(strlen(curr->key) > wireless_l &&
253
301
!strncmp("wireless-", curr->key, wireless_l)) {
255
303
gchar *property_value = NULL;
304
gpointer property_value2 = NULL;
256
305
const gchar* newkey = map_by_mapping(mapping, curr->key+wireless_l);
257
306
IfupdownStrDupeFunc func = map_by_mapping (dupe_mapping, curr->key+wireless_l);
307
IfupdownStrToTypeFunc func1 = map_by_mapping (type_mapping, curr->key+wireless_l);
258
308
if(!newkey || !func) {
259
309
g_warning("no (wireless) mapping found for key: %s", curr->key);
262
312
property_value = (*func) (curr->data, connection);
263
g_debug("setting wireless security newkey(%s)=data(%s)",
264
newkey, property_value);
313
PLUGIN_PRINT ("SCPlugin-Ifupdown", "setting wireless security key: %s=%s",
314
newkey, property_value);
316
property_value2 = (*func1) (property_value);
265
318
g_object_set(wireless_security_setting,
266
newkey, property_value,
319
newkey, property_value2 ? property_value2 : property_value,
268
322
g_free(property_value);
324
g_free(property_value2);
269
325
} else if(strlen(curr->key) > wpa_l &&
270
326
!strncmp("wpa-", curr->key, wpa_l)) {
272
328
gchar *property_value = NULL;
329
gpointer property_value2 = NULL;
273
330
const gchar* newkey = map_by_mapping(mapping, curr->key+wpa_l);
274
331
IfupdownStrDupeFunc func = map_by_mapping (dupe_mapping, curr->key+wpa_l);
332
IfupdownStrToTypeFunc func1 = map_by_mapping (type_mapping, curr->key+wpa_l);
275
333
if(!newkey || !func) {
276
g_debug("no (wpa) mapping found for key: %s", curr->key);
279
336
property_value = (*func) (curr->data, connection);
280
g_debug("setting wpa newkey(%s)=data(%s)", newkey, property_value);
337
PLUGIN_PRINT ("SCPlugin-Ifupdown", "setting wpa security key: %s=%s",
341
#else // DEBUG_SECRETS
342
!strcmp("key", newkey) ||
343
!strcmp("password", newkey) ||
344
!strcmp("pin", newkey) ||
345
!strcmp("psk", newkey) ||
346
!strcmp("wep-key0", newkey) ||
347
!strcmp("wep-key1", newkey) ||
348
!strcmp("wep-key2", newkey) ||
349
!strcmp("wep-key3", newkey) ||
351
"<omitted>" : property_value
352
#endif // DEBUG_SECRETS
356
property_value2 = (*func1) (property_value);
281
358
g_object_set(wireless_security_setting,
282
newkey, property_value,
359
newkey, property_value2 ? property_value2 : property_value,
284
362
g_free(property_value);
286
g_debug(" => not a wireless setting!");
289
365
curr = curr->next;
292
nm_connection_add_setting(connection, NM_SETTING(wireless_security_setting));
294
g_object_set(s_wireless,
295
NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
370
nm_connection_add_setting(connection, NM_SETTING(wireless_security_setting));
371
g_object_set(s_wireless, NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NULL);
363
448
PLUGIN_PRINT("SCPlugin-Ifupdown", "addresses count: %d", g_slist_length(ip4_addresses));
365
if (nameserver_v && inet_pton (AF_INET, nameserver_v, &tmp_ip4_addr))
366
g_array_append_vals(nameserver, &tmp_ip4_addr.s_addr, 1);
368
else if (nameserver_v)
369
g_set_error (&error, eni_plugin_error_quark (), 0,
370
"Invalid %s IP4 address '%s'", "nameserver", nameserver_v);
450
while(nameservers_list_i) {
451
gchar *dns = nameservers_list_i->data;
452
nameservers_list_i = nameservers_list_i -> next;
455
if (inet_pton (AF_INET, dns, &tmp_ip4_addr))
456
g_array_append_vals(nameserver, &tmp_ip4_addr.s_addr, 1);
458
g_set_error (&error, eni_plugin_error_quark (), 0,
459
"Invalid %s IP4 address nameserver '%s'", "nameserver", dns);
461
if (!nameserver->len)
372
462
PLUGIN_PRINT("SCPlugin-Ifupdown", "No dns-nameserver configured in /etc/network/interfaces");
374
g_object_set(ip4_setting,
375
NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
378
464
ip4_setting->addresses = ip4_addresses;
379
465
ip4_setting->dns = nameserver;
467
g_object_set(ip4_setting,
468
NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
471
g_slist_foreach (nameservers_list, (GFunc) g_free, NULL);
472
g_slist_free (nameservers_list);
382
475
nm_connection_add_setting(connection, NM_SETTING(ip4_setting));
400
496
type = _ifupdownplugin_guess_connection_type (block);
401
497
idstr = g_strconcat("Ifupdown (", block->name,")", NULL);
403
500
g_object_set (connection_setting,
504
connection_setting->uuid =
505
nm_utils_uuid_generate_from_string(uuid_base);
408
PLUGIN_PRINT("SCPlugin-Ifupdown", "update_connection_setting_from_if_block (%s) - set type %s",
410
PLUGIN_PRINT("SCPlugin-Ifupdown",
411
"update_connection_setting_from_if_block (%s) - set autoconnect %d",
412
block->name, ((gboolean) strcmp("dhcp", type) == 0));
413
PLUGIN_PRINT("SCPlugin-Ifupdown",
414
"update_connection_setting_from_if_block (%s) - set id %s",
507
PLUGIN_PRINT("SCPlugin-Ifupdown", "update_connection_setting_from_if_block: name:%s, type:%s, autoconnect:%d, id:%s, uuid: %s",
509
((gboolean) strcmp("dhcp", type) == 0),
511
connection_setting->uuid);
417
513
if(!strcmp (NM_SETTING_WIRED_SETTING_NAME, type)) {
418
514
update_wired_setting_from_if_block (connection, block);