2008-07-31 Dan Williams <dcbw@redhat.com>

* system-settings/plugins/ifcfg-fedora/plugin.c
	  system-settings/plugins/ifcfg-fedora/reader.c
		- Don't ignore unmanaged devices if their ifcfg file doesn't make a
			valid NM connection



git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3878 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Dan Williams
2008-07-31 16:19:28 +00:00
parent 55620f122e
commit b2d92c4d17
4 changed files with 97 additions and 78 deletions

View File

@@ -1,3 +1,10 @@
2008-07-31 Dan Williams <dcbw@redhat.com>
* system-settings/plugins/ifcfg-fedora/plugin.c
system-settings/plugins/ifcfg-fedora/reader.c
- Don't ignore unmanaged devices if their ifcfg file doesn't make a
valid NM connection
2008-07-29 Dan Williams <dcbw@redhat.com> 2008-07-29 Dan Williams <dcbw@redhat.com>
* src/nm-gsm-device.c * src/nm-gsm-device.c

View File

@@ -28,6 +28,9 @@
#define ORIG_TAG ".orig" #define ORIG_TAG ".orig"
#define REJ_TAG ".rej" #define REJ_TAG ".rej"
#define IFCFG_PLUGIN_NAME "ifcfg-fedora"
#define IFCFG_PLUGIN_INFO "(c) 2007 - 2008 Red Hat, Inc. To report bugs please use the NetworkManager mailing list."
#include <glib.h> #include <glib.h>
GQuark ifcfg_plugin_error_quark (void); GQuark ifcfg_plugin_error_quark (void);

View File

@@ -45,9 +45,6 @@
#include "nm-system-config-interface.h" #include "nm-system-config-interface.h"
#include "nm-ifcfg-connection.h" #include "nm-ifcfg-connection.h"
#define IFCFG_PLUGIN_NAME "ifcfg-fedora"
#define IFCFG_PLUGIN_INFO "(c) 2007 - 2008 Red Hat, Inc. To report bugs please use the NetworkManager mailing list."
#define IFCFG_DIR SYSCONFDIR"/sysconfig/network-scripts/" #define IFCFG_DIR SYSCONFDIR"/sysconfig/network-scripts/"
static void system_config_interface_init (NMSystemConfigInterface *system_config_interface_class); static void system_config_interface_init (NMSystemConfigInterface *system_config_interface_class);

View File

@@ -51,6 +51,7 @@
#include "shvar.h" #include "shvar.h"
#include "reader.h" #include "reader.h"
#include "nm-system-config-interface.h"
#define TYPE_ETHERNET "Ethernet" #define TYPE_ETHERNET "Ethernet"
#define TYPE_WIRELESS "Wireless" #define TYPE_WIRELESS "Wireless"
@@ -604,6 +605,7 @@ error:
static NMSetting * static NMSetting *
make_wireless_setting (shvarFile *ifcfg, make_wireless_setting (shvarFile *ifcfg,
NMSetting *security, NMSetting *security,
gboolean unmanaged,
GError **error) GError **error)
{ {
NMSettingWireless *s_wireless; NMSettingWireless *s_wireless;
@@ -611,6 +613,11 @@ make_wireless_setting (shvarFile *ifcfg,
s_wireless = NM_SETTING_WIRELESS (nm_setting_wireless_new ()); s_wireless = NM_SETTING_WIRELESS (nm_setting_wireless_new ());
if (!read_mac_address (ifcfg, &s_wireless->mac_address, error)) {
g_object_unref (s_wireless);
return NULL;
}
value = svGetValue (ifcfg, "ESSID"); value = svGetValue (ifcfg, "ESSID");
if (value) { if (value) {
gsize len = strlen (value); gsize len = strlen (value);
@@ -627,41 +634,41 @@ make_wireless_setting (shvarFile *ifcfg,
g_byte_array_append (s_wireless->ssid, (const guint8 *) value, len); g_byte_array_append (s_wireless->ssid, (const guint8 *) value, len);
g_free (value); g_free (value);
} else { } else {
g_set_error (error, ifcfg_plugin_error_quark (), 0, "Missing SSID"); /* Only fail on lack of SSID if device is managed */
goto error; if (!unmanaged) {
} g_set_error (error, ifcfg_plugin_error_quark (), 0, "Missing SSID");
value = svGetValue (ifcfg, "MODE");
if (value) {
char *lcase;
lcase = g_ascii_strdown (value, -1);
g_free (value);
if (!strcmp (lcase, "ad-hoc")) {
s_wireless->mode = g_strdup ("adhoc");
} else if (!strcmp (lcase, "managed")) {
s_wireless->mode = g_strdup ("infrastructure");
} else {
g_set_error (error, ifcfg_plugin_error_quark (), 0,
"Invalid mode '%s' (not ad-hoc or managed)",
lcase);
g_free (lcase);
goto error; goto error;
} }
g_free (lcase);
} }
if (security) if (!unmanaged) {
s_wireless->security = g_strdup (NM_SETTING_WIRELESS_SECURITY_SETTING_NAME); value = svGetValue (ifcfg, "MODE");
if (value) {
char *lcase;
if (!read_mac_address (ifcfg, &s_wireless->mac_address, error)) { lcase = g_ascii_strdown (value, -1);
g_object_unref (s_wireless); g_free (value);
s_wireless = NULL;
if (!strcmp (lcase, "ad-hoc")) {
s_wireless->mode = g_strdup ("adhoc");
} else if (!strcmp (lcase, "managed")) {
s_wireless->mode = g_strdup ("infrastructure");
} else {
g_set_error (error, ifcfg_plugin_error_quark (), 0,
"Invalid mode '%s' (not ad-hoc or managed)",
lcase);
g_free (lcase);
goto error;
}
g_free (lcase);
}
if (security)
s_wireless->security = g_strdup (NM_SETTING_WIRELESS_SECURITY_SETTING_NAME);
// FIXME: channel/freq, other L2 parameters like RTS
} }
// FIXME: channel/freq, other L2 parameters like RTS
return NM_SETTING (s_wireless); return NM_SETTING (s_wireless);
error: error:
@@ -671,12 +678,15 @@ error:
} }
static NMConnection * static NMConnection *
wireless_connection_from_ifcfg (const char *file, shvarFile *ifcfg, GError **error) wireless_connection_from_ifcfg (const char *file,
shvarFile *ifcfg,
gboolean unmanaged,
GError **error)
{ {
NMConnection *connection = NULL; NMConnection *connection = NULL;
NMSetting *con_setting = NULL; NMSetting *con_setting = NULL;
NMSetting *wireless_setting = NULL; NMSetting *wireless_setting = NULL;
NMSettingWireless *tmp; NMSettingWireless *s_wireless;
NMSetting *security_setting = NULL; NMSetting *security_setting = NULL;
char *printable_ssid = NULL; char *printable_ssid = NULL;
@@ -694,49 +704,53 @@ wireless_connection_from_ifcfg (const char *file, shvarFile *ifcfg, GError **err
/* Wireless security */ /* Wireless security */
security_setting = make_wireless_security_setting (ifcfg, file, error); security_setting = make_wireless_security_setting (ifcfg, file, error);
if (*error) if (*error) {
goto error; g_object_unref (connection);
return NULL;
}
if (security_setting) if (security_setting)
nm_connection_add_setting (connection, security_setting); nm_connection_add_setting (connection, security_setting);
/* Wireless */ /* Wireless */
wireless_setting = make_wireless_setting (ifcfg, security_setting, error); wireless_setting = make_wireless_setting (ifcfg, security_setting, unmanaged, error);
if (!wireless_setting) if (!wireless_setting) {
goto error; g_object_unref (connection);
return NULL;
}
nm_connection_add_setting (connection, wireless_setting); nm_connection_add_setting (connection, wireless_setting);
tmp = NM_SETTING_WIRELESS (wireless_setting); s_wireless = (NMSettingWireless *) wireless_setting;
printable_ssid = nm_utils_ssid_to_utf8 ((const char *) tmp->ssid->data, if (s_wireless && s_wireless->ssid) {
(guint32) tmp->ssid->len); printable_ssid = nm_utils_ssid_to_utf8 ((const char *) s_wireless->ssid->data,
(guint32) s_wireless->ssid->len);
} else
printable_ssid = g_strdup_printf ("unmanaged");
con_setting = make_connection_setting (file, ifcfg, con_setting = make_connection_setting (file, ifcfg,
NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_SETTING_NAME,
printable_ssid); printable_ssid);
g_free (printable_ssid);
if (!con_setting) { if (!con_setting) {
g_set_error (error, ifcfg_plugin_error_quark (), 0, g_set_error (error, ifcfg_plugin_error_quark (), 0,
"Failed to create connection setting."); "Failed to create connection setting.");
goto error; g_object_unref (connection);
return NULL;
} }
nm_connection_add_setting (connection, con_setting); nm_connection_add_setting (connection, con_setting);
if (!nm_connection_verify (connection, error)) /* Don't verify if unmanaged since we may not have an SSID or whatever */
goto error; if (!unmanaged) {
if (!nm_connection_verify (connection, error)) {
g_object_unref (connection);
return NULL;
}
}
return connection; return connection;
error:
g_free (printable_ssid);
g_object_unref (connection);
if (con_setting)
g_object_unref (con_setting);
if (wireless_setting)
g_object_unref (wireless_setting);
return NULL;
} }
static NMSetting * static NMSetting *
make_wired_setting (shvarFile *ifcfg, GError **error) make_wired_setting (shvarFile *ifcfg, gboolean unmanaged, GError **error)
{ {
NMSettingWired *s_wired; NMSettingWired *s_wired;
char *value; char *value;
@@ -750,10 +764,8 @@ make_wired_setting (shvarFile *ifcfg, GError **error)
if (mtu >= 0 && mtu < 65536) if (mtu >= 0 && mtu < 65536)
s_wired->mtu = mtu; s_wired->mtu = mtu;
} else { } else {
g_set_error (error, ifcfg_plugin_error_quark (), 0, /* Shouldn't be fatal... */
"Invalid MTU '%s'", value); PLUGIN_PRINT (IFCFG_PLUGIN_NAME, " warning: invalid MTU '%s'", value);
g_object_unref (s_wired);
s_wired = NULL;
} }
g_free (value); g_free (value);
} }
@@ -767,7 +779,10 @@ make_wired_setting (shvarFile *ifcfg, GError **error)
} }
static NMConnection * static NMConnection *
wired_connection_from_ifcfg (const char *file, shvarFile *ifcfg, GError **error) wired_connection_from_ifcfg (const char *file,
shvarFile *ifcfg,
gboolean unmanaged,
GError **error)
{ {
NMConnection *connection = NULL; NMConnection *connection = NULL;
NMSetting *con_setting = NULL; NMSetting *con_setting = NULL;
@@ -787,28 +802,24 @@ wired_connection_from_ifcfg (const char *file, shvarFile *ifcfg, GError **error)
if (!con_setting) { if (!con_setting) {
g_set_error (error, ifcfg_plugin_error_quark (), 0, g_set_error (error, ifcfg_plugin_error_quark (), 0,
"Failed to create connection setting."); "Failed to create connection setting.");
goto error; g_object_unref (connection);
return NULL;
} }
nm_connection_add_setting (connection, con_setting); nm_connection_add_setting (connection, con_setting);
wired_setting = make_wired_setting (ifcfg, error); wired_setting = make_wired_setting (ifcfg, unmanaged, error);
if (!wired_setting) if (!wired_setting) {
goto error; g_object_unref (connection);
return NULL;
}
nm_connection_add_setting (connection, wired_setting); nm_connection_add_setting (connection, wired_setting);
if (!nm_connection_verify (connection, error)) if (!nm_connection_verify (connection, error)) {
goto error; g_object_unref (connection);
return NULL;
}
return connection; return connection;
error:
g_object_unref (connection);
if (con_setting)
g_object_unref (con_setting);
if (wired_setting)
g_object_unref (wired_setting);
return NULL;
} }
static gboolean static gboolean
@@ -933,9 +944,9 @@ connection_from_file (const char *filename,
} }
if (!strcmp (type, TYPE_ETHERNET)) if (!strcmp (type, TYPE_ETHERNET))
connection = wired_connection_from_ifcfg (filename, parsed, error); connection = wired_connection_from_ifcfg (filename, parsed, *ignored, error);
else if (!strcmp (type, TYPE_WIRELESS)) else if (!strcmp (type, TYPE_WIRELESS))
connection = wireless_connection_from_ifcfg (filename, parsed, error); connection = wireless_connection_from_ifcfg (filename, parsed, *ignored, error);
else { else {
g_set_error (error, ifcfg_plugin_error_quark (), 0, g_set_error (error, ifcfg_plugin_error_quark (), 0,
"Unknown connection type '%s'", type); "Unknown connection type '%s'", type);
@@ -943,7 +954,8 @@ connection_from_file (const char *filename,
g_free (type); g_free (type);
if (!connection) /* Don't bother reading the connection fully if it's unmanaged */
if (!connection || *ignored)
goto done; goto done;
s_ip4 = make_ip4_setting (parsed, error); s_ip4 = make_ip4_setting (parsed, error);