ifcfg-rh: add testcases
With a few fixes to WPA support found while writing the testcases.
This commit is contained in:
@@ -481,6 +481,8 @@ system-settings/src/Makefile
|
||||
system-settings/plugins/Makefile
|
||||
system-settings/plugins/ifupdown/Makefile
|
||||
system-settings/plugins/ifcfg-rh/Makefile
|
||||
system-settings/plugins/ifcfg-rh/tests/Makefile
|
||||
system-settings/plugins/ifcfg-rh/tests/network-scripts/Makefile
|
||||
system-settings/plugins/ifcfg-suse/Makefile
|
||||
system-settings/plugins/keyfile/Makefile
|
||||
system-settings/plugins/keyfile/io/Makefile
|
||||
|
@@ -1,3 +1,4 @@
|
||||
SUBDIRS=. tests
|
||||
|
||||
pkglib_LTLIBRARIES = libnm-settings-plugin-ifcfg-rh.la
|
||||
|
||||
|
@@ -255,7 +255,7 @@ nm_ifcfg_connection_new (const char *filename,
|
||||
|
||||
g_return_val_if_fail (filename != NULL, NULL);
|
||||
|
||||
wrapped = connection_from_file (filename, &unmanaged, &keyfile, error, ignore_error);
|
||||
wrapped = connection_from_file (filename, NULL, NULL, &unmanaged, &keyfile, error, ignore_error);
|
||||
if (!wrapped)
|
||||
return NULL;
|
||||
|
||||
|
@@ -486,7 +486,7 @@ plugin_get_hostname (SCPluginIfcfg *plugin)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
hostname = svGetValue (network, "HOSTNAME");
|
||||
hostname = svGetValue (network, "HOSTNAME", FALSE);
|
||||
svCloseFile (network);
|
||||
|
||||
/* Ignore a hostname of 'localhost' or 'localhost.localdomain' to preserve
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright (C) 2008 Red Hat, Inc.
|
||||
* Copyright (C) 2008 - 2009 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
@@ -60,9 +60,6 @@
|
||||
#define PLUGIN_WARN(pname, fmt, args...) \
|
||||
{ g_warning (" " pname ": " fmt, ##args); }
|
||||
|
||||
#define TYPE_ETHERNET "Ethernet"
|
||||
#define TYPE_WIRELESS "Wireless"
|
||||
|
||||
static char *
|
||||
get_ifcfg_name (const char *file)
|
||||
{
|
||||
@@ -124,7 +121,7 @@ make_connection_setting (const char *file,
|
||||
g_free (new_id);
|
||||
|
||||
/* Try for a UUID key before falling back to hashing the file name */
|
||||
uuid = svGetValue (ifcfg, "UUID");
|
||||
uuid = svGetValue (ifcfg, "UUID", FALSE);
|
||||
if (!uuid || !strlen (uuid)) {
|
||||
g_free (uuid);
|
||||
uuid = nm_utils_uuid_generate_from_string (ifcfg->fileName);
|
||||
@@ -136,10 +133,11 @@ make_connection_setting (const char *file,
|
||||
g_free (uuid);
|
||||
|
||||
/* Be somewhat conservative about autoconnect */
|
||||
if (svTrueValue (ifcfg, "ONBOOT", FALSE))
|
||||
g_object_set (s_con, NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NULL);
|
||||
g_object_set (s_con, NM_SETTING_CONNECTION_AUTOCONNECT,
|
||||
svTrueValue (ifcfg, "ONBOOT", FALSE),
|
||||
NULL);
|
||||
|
||||
value = svGetValue (ifcfg, "LAST_CONNECT");
|
||||
value = svGetValue (ifcfg, "LAST_CONNECT", FALSE);
|
||||
if (value) {
|
||||
unsigned long int tmp;
|
||||
|
||||
@@ -172,7 +170,7 @@ get_one_ip4_addr (shvarFile *ifcfg,
|
||||
g_return_if_fail (error != NULL);
|
||||
g_return_if_fail (*error == NULL);
|
||||
|
||||
value = svGetValue (ifcfg, tag);
|
||||
value = svGetValue (ifcfg, tag, FALSE);
|
||||
if (!value)
|
||||
return;
|
||||
|
||||
@@ -199,7 +197,7 @@ get_one_ip4_addr (shvarFile *ifcfg,
|
||||
|
||||
|
||||
static NMSetting *
|
||||
make_ip4_setting (shvarFile *ifcfg, GError **error)
|
||||
make_ip4_setting (shvarFile *ifcfg, const char *network_file, GError **error)
|
||||
{
|
||||
NMSettingIP4Config *s_ip4 = NULL;
|
||||
char *value = NULL;
|
||||
@@ -209,13 +207,13 @@ make_ip4_setting (shvarFile *ifcfg, GError **error)
|
||||
shvarFile *network_ifcfg;
|
||||
gboolean never_default = FALSE;
|
||||
|
||||
network_ifcfg = svNewFile (SYSCONFDIR "/sysconfig/network");
|
||||
network_ifcfg = svNewFile (network_file);
|
||||
if (network_ifcfg) {
|
||||
char *gatewaydev;
|
||||
|
||||
/* Get the connection ifcfg device name and the global gateway device */
|
||||
value = svGetValue (ifcfg, "DEVICE");
|
||||
gatewaydev = svGetValue (network_ifcfg, "GATEWAYDEV");
|
||||
value = svGetValue (ifcfg, "DEVICE", FALSE);
|
||||
gatewaydev = svGetValue (network_ifcfg, "GATEWAYDEV", FALSE);
|
||||
|
||||
/* If there was a global gateway device specified, then only connections
|
||||
* for that device can be the default connection.
|
||||
@@ -228,7 +226,7 @@ make_ip4_setting (shvarFile *ifcfg, GError **error)
|
||||
svCloseFile (network_ifcfg);
|
||||
}
|
||||
|
||||
value = svGetValue (ifcfg, "BOOTPROTO");
|
||||
value = svGetValue (ifcfg, "BOOTPROTO", FALSE);
|
||||
if (value) {
|
||||
if (!g_ascii_strcasecmp (value, "bootp") || !g_ascii_strcasecmp (value, "dhcp"))
|
||||
method = NM_SETTING_IP4_CONFIG_METHOD_AUTO;
|
||||
@@ -252,9 +250,9 @@ make_ip4_setting (shvarFile *ifcfg, GError **error)
|
||||
* HWADDR=11:22:33:44:55:66
|
||||
*
|
||||
*/
|
||||
tmp_ip4 = svGetValue (ifcfg, "IPADDR");
|
||||
tmp_prefix = svGetValue (ifcfg, "PREFIX");
|
||||
tmp_netmask = svGetValue (ifcfg, "NETMASK");
|
||||
tmp_ip4 = svGetValue (ifcfg, "IPADDR", FALSE);
|
||||
tmp_prefix = svGetValue (ifcfg, "PREFIX", FALSE);
|
||||
tmp_netmask = svGetValue (ifcfg, "NETMASK", FALSE);
|
||||
if (!tmp_ip4 && !tmp_prefix && !tmp_netmask)
|
||||
method = NM_SETTING_IP4_CONFIG_METHOD_AUTO;
|
||||
g_free (tmp_ip4);
|
||||
@@ -280,7 +278,7 @@ make_ip4_setting (shvarFile *ifcfg, GError **error)
|
||||
|
||||
/* If no gateway in the ifcfg, try /etc/sysconfig/network instead */
|
||||
if (!nm_ip4_address_get_gateway (addr)) {
|
||||
network_ifcfg = svNewFile (SYSCONFDIR "/sysconfig/network");
|
||||
network_ifcfg = svNewFile (network_file);
|
||||
if (network_ifcfg) {
|
||||
tmp = 0;
|
||||
get_one_ip4_addr (network_ifcfg, "GATEWAY", &tmp, error);
|
||||
@@ -291,7 +289,7 @@ make_ip4_setting (shvarFile *ifcfg, GError **error)
|
||||
}
|
||||
}
|
||||
|
||||
value = svGetValue (ifcfg, "PREFIX");
|
||||
value = svGetValue (ifcfg, "PREFIX", FALSE);
|
||||
if (value) {
|
||||
long int prefix;
|
||||
|
||||
@@ -336,7 +334,7 @@ make_ip4_setting (shvarFile *ifcfg, GError **error)
|
||||
|
||||
/* DHCP hostname for 'send host-name' option */
|
||||
if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) {
|
||||
value = svGetValue (ifcfg, "DHCP_HOSTNAME");
|
||||
value = svGetValue (ifcfg, "DHCP_HOSTNAME", FALSE);
|
||||
if (value && strlen (value))
|
||||
g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME, value, NULL);
|
||||
g_free (value);
|
||||
@@ -352,7 +350,7 @@ make_ip4_setting (shvarFile *ifcfg, GError **error)
|
||||
GET_ONE_DNS("DNS3");
|
||||
|
||||
/* DNS searches */
|
||||
value = svGetValue (ifcfg, "DOMAIN");
|
||||
value = svGetValue (ifcfg, "DOMAIN", FALSE);
|
||||
if (value) {
|
||||
char **searches = NULL;
|
||||
|
||||
@@ -372,7 +370,7 @@ make_ip4_setting (shvarFile *ifcfg, GError **error)
|
||||
|
||||
/* Legacy value NM used for a while but is incorrect (rh #459370) */
|
||||
if (!nm_setting_ip4_config_get_num_dns_searches (s_ip4)) {
|
||||
value = svGetValue (ifcfg, "SEARCH");
|
||||
value = svGetValue (ifcfg, "SEARCH", FALSE);
|
||||
if (value) {
|
||||
char **searches = NULL;
|
||||
|
||||
@@ -449,7 +447,7 @@ read_mac_address (shvarFile *ifcfg, GByteArray **array, GError **error)
|
||||
g_return_val_if_fail (error != NULL, FALSE);
|
||||
g_return_val_if_fail (*error == NULL, FALSE);
|
||||
|
||||
value = svGetValue (ifcfg, "HWADDR");
|
||||
value = svGetValue (ifcfg, "HWADDR", FALSE);
|
||||
if (!value || !strlen (value)) {
|
||||
g_free (value);
|
||||
return TRUE;
|
||||
@@ -485,7 +483,7 @@ add_one_wep_key (shvarFile *ifcfg,
|
||||
g_return_val_if_fail (key_idx <= 3, FALSE);
|
||||
g_return_val_if_fail (s_wsec != NULL, FALSE);
|
||||
|
||||
value = svGetValue (ifcfg, shvar_key);
|
||||
value = svGetValue (ifcfg, shvar_key, FALSE);
|
||||
if (!value || !strlen (value)) {
|
||||
g_free (value);
|
||||
return TRUE;
|
||||
@@ -605,7 +603,7 @@ make_wep_setting (shvarFile *ifcfg,
|
||||
s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (nm_setting_wireless_security_new ());
|
||||
g_object_set (s_wireless_sec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", NULL);
|
||||
|
||||
value = svGetValue (ifcfg, "DEFAULTKEY");
|
||||
value = svGetValue (ifcfg, "DEFAULTKEY", FALSE);
|
||||
if (value) {
|
||||
gboolean success;
|
||||
|
||||
@@ -651,7 +649,7 @@ make_wep_setting (shvarFile *ifcfg,
|
||||
goto error;
|
||||
}
|
||||
|
||||
value = svGetValue (ifcfg, "SECURITYMODE");
|
||||
value = svGetValue (ifcfg, "SECURITYMODE", FALSE);
|
||||
if (value) {
|
||||
char *lcase;
|
||||
|
||||
@@ -703,12 +701,14 @@ error:
|
||||
static gboolean
|
||||
fill_wpa_ciphers (shvarFile *ifcfg,
|
||||
NMSettingWirelessSecurity *wsec,
|
||||
gboolean group)
|
||||
gboolean group,
|
||||
gboolean adhoc)
|
||||
{
|
||||
char *value = NULL, *p;
|
||||
char **list = NULL, **iter;
|
||||
int i = 0;
|
||||
|
||||
p = value = svGetValue (ifcfg, group ? "CIPHER_GROUP" : "CIPHER_PAIRWISE");
|
||||
p = value = svGetValue (ifcfg, group ? "CIPHER_GROUP" : "CIPHER_PAIRWISE", TRUE);
|
||||
if (!value)
|
||||
return TRUE;
|
||||
|
||||
@@ -719,7 +719,23 @@ fill_wpa_ciphers (shvarFile *ifcfg,
|
||||
p[strlen (p) - 1] = '\0';
|
||||
|
||||
list = g_strsplit_set (p, " ", 0);
|
||||
for (iter = list; iter && *iter; iter++) {
|
||||
for (iter = list; iter && *iter; iter++, i++) {
|
||||
/* Ad-Hoc configurations cannot have pairwise ciphers, and can only
|
||||
* have one group cipher. Ignore any additional group ciphers and
|
||||
* any pairwise ciphers specified.
|
||||
*/
|
||||
if (adhoc) {
|
||||
if (group && (i > 0)) {
|
||||
PLUGIN_WARN (IFCFG_PLUGIN_NAME, " warning: ignoring group cipher '%s' (only one group cipher allowed in Ad-Hoc mode)",
|
||||
*iter);
|
||||
continue;
|
||||
} else if (!group) {
|
||||
PLUGIN_WARN (IFCFG_PLUGIN_NAME, " warning: ignoring pairwise cipher '%s' (pairwise not used in Ad-Hoc mode)",
|
||||
*iter);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!strcmp (*iter, "CCMP")) {
|
||||
if (group)
|
||||
nm_setting_wireless_security_add_group (wsec, "ccmp");
|
||||
@@ -767,13 +783,13 @@ parse_wpa_psk (shvarFile *ifcfg,
|
||||
/* Try to get keys from the "shadow" key file */
|
||||
keys_ifcfg = get_keys_ifcfg (file);
|
||||
if (keys_ifcfg) {
|
||||
psk = svGetValue (keys_ifcfg, "WPA_PSK");
|
||||
psk = svGetValue (keys_ifcfg, "WPA_PSK", TRUE);
|
||||
svCloseFile (keys_ifcfg);
|
||||
}
|
||||
|
||||
/* Fall back to the original ifcfg */
|
||||
if (!psk)
|
||||
psk = svGetValue (ifcfg, "WPA_PSK");
|
||||
psk = svGetValue (ifcfg, "WPA_PSK", TRUE);
|
||||
|
||||
if (!psk) {
|
||||
g_set_error (error, ifcfg_plugin_error_quark (), 0,
|
||||
@@ -799,7 +815,7 @@ parse_wpa_psk (shvarFile *ifcfg,
|
||||
|
||||
/* hash the passphrase to a hex key */
|
||||
buf = g_malloc0 (WPA_PMK_LEN * 2);
|
||||
pbkdf2_sha1 (psk, (char *) ssid->data, ssid->len, 4096, buf, WPA_PMK_LEN);
|
||||
pbkdf2_sha1 (p, (char *) ssid->data, ssid->len, 4096, buf, WPA_PMK_LEN);
|
||||
hashed = utils_bin2hexstr ((const char *) buf, WPA_PMK_LEN, WPA_PMK_LEN * 2);
|
||||
g_free (buf);
|
||||
} else if (strlen (psk) == 64) {
|
||||
@@ -847,19 +863,24 @@ make_wpa_setting (shvarFile *ifcfg,
|
||||
|
||||
wsec = NM_SETTING_WIRELESS_SECURITY (nm_setting_wireless_security_new ());
|
||||
|
||||
value = svGetValue (ifcfg, "KEY_MGMT");
|
||||
value = svGetValue (ifcfg, "KEY_MGMT", FALSE);
|
||||
if (!value)
|
||||
goto error; /* Not WPA or Dynamic WEP */
|
||||
|
||||
/* Pairwise and Group ciphers */
|
||||
fill_wpa_ciphers (ifcfg, wsec, FALSE);
|
||||
fill_wpa_ciphers (ifcfg, wsec, TRUE);
|
||||
fill_wpa_ciphers (ifcfg, wsec, FALSE, adhoc);
|
||||
fill_wpa_ciphers (ifcfg, wsec, TRUE, adhoc);
|
||||
|
||||
/* WPA and/or RSN */
|
||||
if (svTrueValue (ifcfg, "WPA_ALLOW_WPA", TRUE))
|
||||
if (adhoc) {
|
||||
/* Ad-Hoc mode only supports WPA proto for now */
|
||||
nm_setting_wireless_security_add_proto (wsec, "wpa");
|
||||
if (svTrueValue (ifcfg, "WPA_ALLOW_WPA2", TRUE))
|
||||
nm_setting_wireless_security_add_proto (wsec, "rsn");
|
||||
} else {
|
||||
if (svTrueValue (ifcfg, "WPA_ALLOW_WPA", TRUE))
|
||||
nm_setting_wireless_security_add_proto (wsec, "wpa");
|
||||
if (svTrueValue (ifcfg, "WPA_ALLOW_WPA2", TRUE))
|
||||
nm_setting_wireless_security_add_proto (wsec, "rsn");
|
||||
}
|
||||
|
||||
if (!strcmp (value, "WPA-PSK")) {
|
||||
psk = parse_wpa_psk (ifcfg, file, ssid, error);
|
||||
@@ -867,6 +888,11 @@ make_wpa_setting (shvarFile *ifcfg,
|
||||
goto error;
|
||||
g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_PSK, psk, NULL);
|
||||
g_free (psk);
|
||||
|
||||
if (adhoc)
|
||||
g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-none", NULL);
|
||||
else
|
||||
g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-psk", NULL);
|
||||
#if 0
|
||||
} else if (!strcmp (value, "WPA-EAP") || !strcmp (value, "IEEE8021X")) {
|
||||
/* Adhoc mode is mutually exclusive with any 802.1x-based authentication */
|
||||
@@ -940,7 +966,7 @@ make_wireless_setting (shvarFile *ifcfg,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
value = svGetValue (ifcfg, "ESSID");
|
||||
value = svGetValue (ifcfg, "ESSID", FALSE);
|
||||
if (value) {
|
||||
gsize len = strlen (value);
|
||||
|
||||
@@ -966,7 +992,7 @@ make_wireless_setting (shvarFile *ifcfg,
|
||||
}
|
||||
|
||||
if (!unmanaged) {
|
||||
value = svGetValue (ifcfg, "MODE");
|
||||
value = svGetValue (ifcfg, "MODE", FALSE);
|
||||
if (value) {
|
||||
char *lcase;
|
||||
const char *mode = NULL;
|
||||
@@ -980,7 +1006,7 @@ make_wireless_setting (shvarFile *ifcfg,
|
||||
mode = "infrastructure";
|
||||
} else {
|
||||
g_set_error (error, ifcfg_plugin_error_quark (), 0,
|
||||
"Invalid mode '%s' (not ad-hoc or managed)",
|
||||
"Invalid mode '%s' (not 'Ad-Hoc' or 'Managed')",
|
||||
lcase);
|
||||
g_free (lcase);
|
||||
goto error;
|
||||
@@ -1097,7 +1123,7 @@ make_wired_setting (shvarFile *ifcfg, gboolean unmanaged, GError **error)
|
||||
|
||||
s_wired = NM_SETTING_WIRED (nm_setting_wired_new ());
|
||||
|
||||
value = svGetValue (ifcfg, "MTU");
|
||||
value = svGetValue (ifcfg, "MTU", FALSE);
|
||||
if (value) {
|
||||
if (get_int (value, &mtu)) {
|
||||
if (mtu >= 0 && mtu < 65536)
|
||||
@@ -1207,6 +1233,8 @@ is_wireless_device (const char *iface)
|
||||
|
||||
NMConnection *
|
||||
connection_from_file (const char *filename,
|
||||
const char *network_file,
|
||||
const char *test_type, /* for unit tests only */
|
||||
gboolean *ignored,
|
||||
char **keyfile,
|
||||
GError **error,
|
||||
@@ -1225,6 +1253,10 @@ connection_from_file (const char *filename,
|
||||
g_return_val_if_fail (keyfile != NULL, NULL);
|
||||
g_return_val_if_fail (*keyfile == NULL, NULL);
|
||||
|
||||
/* Non-NULL only for unit tests; normally use /etc/sysconfig/network */
|
||||
if (!network_file)
|
||||
network_file = SYSCONFDIR "/sysconfig/network";
|
||||
|
||||
ifcfg_name = get_ifcfg_name (filename);
|
||||
if (!ifcfg_name) {
|
||||
g_set_error (error, ifcfg_plugin_error_quark (), 0,
|
||||
@@ -1240,14 +1272,14 @@ connection_from_file (const char *filename,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
type = svGetValue (parsed, "TYPE");
|
||||
type = svGetValue (parsed, "TYPE", FALSE);
|
||||
if (!type) {
|
||||
char *device;
|
||||
|
||||
/* If no type, if the device has wireless extensions, it's wifi,
|
||||
* otherwise it's ethernet.
|
||||
*/
|
||||
device = svGetValue (parsed, "DEVICE");
|
||||
device = svGetValue (parsed, "DEVICE", FALSE);
|
||||
if (!device) {
|
||||
g_set_error (error, ifcfg_plugin_error_quark (), 0,
|
||||
"File '%s' had neither TYPE nor DEVICE keys.", filename);
|
||||
@@ -1262,16 +1294,24 @@ connection_from_file (const char *filename,
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Test wireless extensions */
|
||||
if (is_wireless_device (device))
|
||||
type = g_strdup (TYPE_WIRELESS);
|
||||
else
|
||||
type = g_strdup (TYPE_ETHERNET);
|
||||
if (!test_type) {
|
||||
/* Test wireless extensions */
|
||||
if (is_wireless_device (device))
|
||||
type = g_strdup (TYPE_WIRELESS);
|
||||
else
|
||||
type = g_strdup (TYPE_ETHERNET);
|
||||
} else {
|
||||
/* For the unit tests, there won't necessarily be any
|
||||
* adapters of the connection's type in the system so the
|
||||
* type can't be tested with ioctls.
|
||||
*/
|
||||
type = g_strdup (test_type);
|
||||
}
|
||||
|
||||
g_free (device);
|
||||
}
|
||||
|
||||
nmc = svGetValue (parsed, "NM_CONTROLLED");
|
||||
nmc = svGetValue (parsed, "NM_CONTROLLED", FALSE);
|
||||
if (nmc) {
|
||||
char *lower;
|
||||
|
||||
@@ -1305,7 +1345,7 @@ connection_from_file (const char *filename,
|
||||
if (!connection || *ignored)
|
||||
goto done;
|
||||
|
||||
s_ip4 = make_ip4_setting (parsed, error);
|
||||
s_ip4 = make_ip4_setting (parsed, network_file, error);
|
||||
if (*error) {
|
||||
g_object_unref (connection);
|
||||
connection = NULL;
|
||||
|
@@ -24,7 +24,12 @@
|
||||
#include <glib.h>
|
||||
#include <nm-connection.h>
|
||||
|
||||
#define TYPE_ETHERNET "Ethernet"
|
||||
#define TYPE_WIRELESS "Wireless"
|
||||
|
||||
NMConnection *connection_from_file (const char *filename,
|
||||
const char *network_file,
|
||||
const char *test_type,
|
||||
gboolean *ignored,
|
||||
char **keyfile,
|
||||
GError **error,
|
||||
|
@@ -182,7 +182,7 @@ escape(const char *s) {
|
||||
* be freed by the caller.
|
||||
*/
|
||||
char *
|
||||
svGetValue(shvarFile *s, const char *key)
|
||||
svGetValue(shvarFile *s, const char *key, gboolean verbatim)
|
||||
{
|
||||
char *value = NULL;
|
||||
char *line;
|
||||
@@ -201,7 +201,8 @@ svGetValue(shvarFile *s, const char *key)
|
||||
line = s->current->data;
|
||||
if (!strncmp(keyString, line, len)) {
|
||||
value = g_strdup(line + len);
|
||||
unescape(value);
|
||||
if (!verbatim)
|
||||
unescape(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -215,7 +216,7 @@ svGetValue(shvarFile *s, const char *key)
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if (s->parent) value = svGetValue(s->parent, key);
|
||||
if (s->parent) value = svGetValue(s->parent, key, verbatim);
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -229,7 +230,7 @@ svTrueValue(shvarFile *s, const char *key, int def)
|
||||
char *tmp;
|
||||
int returnValue = def;
|
||||
|
||||
tmp = svGetValue(s, key);
|
||||
tmp = svGetValue(s, key, FALSE);
|
||||
if (!tmp) return returnValue;
|
||||
|
||||
if ( (!strcasecmp("yes", tmp)) ||
|
||||
@@ -283,9 +284,9 @@ svSetValue(shvarFile *s, const char *key, const char *value)
|
||||
if (value) newval = escape(value);
|
||||
keyValue = g_strdup_printf("%s=%s", key, newval ? newval : "");
|
||||
|
||||
val1 = svGetValue(s, key);
|
||||
val1 = svGetValue(s, key, FALSE);
|
||||
if (val1 && newval && !strcmp(val1, newval)) goto bail;
|
||||
if (s->parent) val2 = svGetValue(s->parent, key);
|
||||
if (s->parent) val2 = svGetValue(s->parent, key, FALSE);
|
||||
|
||||
if (!newval || !newval[0]) {
|
||||
/* delete value somehow */
|
||||
|
@@ -62,7 +62,7 @@ svNewFile(const char *name);
|
||||
* be freed by the caller.
|
||||
*/
|
||||
char *
|
||||
svGetValue(shvarFile *s, const char *key);
|
||||
svGetValue(shvarFile *s, const char *key, gboolean verbatim);
|
||||
|
||||
/* return 1 if <key> resolves to any truth value (e.g. "yes", "y", "true")
|
||||
* return 0 if <key> resolves to any non-truth value (e.g. "no", "n", "false")
|
||||
|
31
system-settings/plugins/ifcfg-rh/tests/Makefile.am
Normal file
31
system-settings/plugins/ifcfg-rh/tests/Makefile.am
Normal file
@@ -0,0 +1,31 @@
|
||||
SUBDIRS=network-scripts
|
||||
|
||||
INCLUDES = \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_srcdir)/libnm-util \
|
||||
-I$(top_srcdir)/libnm-glib \
|
||||
-I$(top_srcdir)/system-settings/plugins/ifcfg-rh
|
||||
|
||||
noinst_PROGRAMS = test-ifcfg-rh
|
||||
|
||||
test_ifcfg_rh_SOURCES = \
|
||||
test-ifcfg-rh.c
|
||||
|
||||
test_ifcfg_rh_CPPFLAGS = \
|
||||
$(GLIB_CFLAGS) \
|
||||
$(DBUS_CFLAGS) \
|
||||
-DTEST_DIR=\"$(abs_srcdir)/\"
|
||||
|
||||
test_ifcfg_rh_LDADD = \
|
||||
$(DBUS_LIBS) \
|
||||
$(top_builddir)/libnm-glib/libnm_glib.la \
|
||||
$(top_builddir)/libnm-util/libnm-util.la \
|
||||
$(top_builddir)/system-settings/plugins/ifcfg-rh/libifcfg-rh-io.la
|
||||
|
||||
if WITH_TESTS
|
||||
|
||||
check-local: test-ifcfg-rh
|
||||
$(abs_builddir)/test-ifcfg-rh
|
||||
|
||||
endif
|
||||
|
@@ -0,0 +1,26 @@
|
||||
EXTRA_DIST = \
|
||||
ifcfg-test-minimal \
|
||||
ifcfg-test-nm-controlled \
|
||||
ifcfg-test-wired-static \
|
||||
ifcfg-test-wired-dhcp \
|
||||
ifcfg-test-wired-global-gateway \
|
||||
network-test-wired-global-gateway \
|
||||
ifcfg-test-wired-never-default \
|
||||
network-test-wired-never-default \
|
||||
ifcfg-test-wifi-open \
|
||||
ifcfg-test-wifi-wep \
|
||||
keys-test-wifi-wep \
|
||||
ifcfg-test-wifi-wep-adhoc \
|
||||
keys-test-wifi-wep-adhoc \
|
||||
ifcfg-test-wifi-wpa-psk \
|
||||
keys-test-wifi-wpa-psk \
|
||||
ifcfg-test-wifi-wpa-psk-adhoc \
|
||||
keys-test-wifi-wpa-psk-adhoc \
|
||||
ifcfg-test-wifi-wpa-psk-hex \
|
||||
keys-test-wifi-wpa-psk-hex
|
||||
|
||||
check-local:
|
||||
@for f in $(EXTRA_DIST); do \
|
||||
chmod 0600 $(abs_srcdir)/$$f; \
|
||||
done
|
||||
|
@@ -0,0 +1,4 @@
|
||||
# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile)
|
||||
DEVICE=eth0
|
||||
HWADDR=00:16:41:11:22:33
|
||||
|
@@ -0,0 +1,9 @@
|
||||
TYPE=Ethernet
|
||||
DEVICE=eth0
|
||||
HWADDR=00:11:22:33:f8:9f
|
||||
BOOTPROTO=dhcp
|
||||
ONBOOT=yes
|
||||
USERCTL=yes
|
||||
IPV6INIT=no
|
||||
NM_CONTROLLED=no
|
||||
|
@@ -0,0 +1,13 @@
|
||||
TYPE=Wireless
|
||||
DEVICE=eth2
|
||||
HWADDR=00:16:41:11:22:33
|
||||
NM_CONTROLLED=yes
|
||||
BOOTPROTO=dhcp
|
||||
ESSID=blahblah
|
||||
CHANNEL=1
|
||||
MODE=Managed
|
||||
RATE=auto
|
||||
ONBOOT=yes
|
||||
USERCTL=yes
|
||||
PEERDNS=yes
|
||||
IPV6INIT=no
|
@@ -0,0 +1,14 @@
|
||||
TYPE=Wireless
|
||||
DEVICE=eth2
|
||||
HWADDR=00:16:41:11:22:33
|
||||
NM_CONTROLLED=yes
|
||||
BOOTPROTO=dhcp
|
||||
ESSID=blahblah
|
||||
CHANNEL=1
|
||||
MODE=Managed
|
||||
RATE=auto
|
||||
ONBOOT=yes
|
||||
USERCTL=yes
|
||||
PEERDNS=yes
|
||||
IPV6INIT=no
|
||||
SECURITYMODE=restricted
|
@@ -0,0 +1,15 @@
|
||||
TYPE=Wireless
|
||||
DEVICE=eth2
|
||||
HWADDR=00:16:41:11:22:33
|
||||
NM_CONTROLLED=yes
|
||||
BOOTPROTO=dhcp
|
||||
ESSID=blahblah
|
||||
CHANNEL=11
|
||||
MODE=Ad-Hoc
|
||||
RATE=auto
|
||||
ONBOOT=no
|
||||
USERCTL=yes
|
||||
PEERDNS=no
|
||||
DNS1=4.2.2.1
|
||||
DNS2=4.2.2.2
|
||||
IPV6INIT=no
|
@@ -0,0 +1,19 @@
|
||||
TYPE=Wireless
|
||||
DEVICE=eth2
|
||||
HWADDR=00:16:41:11:22:33
|
||||
NM_CONTROLLED=yes
|
||||
BOOTPROTO=dhcp
|
||||
ESSID=blahblah
|
||||
CHANNEL=1
|
||||
MODE=Managed
|
||||
RATE=auto
|
||||
ONBOOT=yes
|
||||
USERCTL=yes
|
||||
PEERDNS=yes
|
||||
IPV6INIT=no
|
||||
CIPHER_PAIRWISE="TKIP CCMP"
|
||||
CIPHER_GROUP="TKIP CCMP WEP40 WEP104"
|
||||
KEY_MGMT=WPA-PSK
|
||||
WPA_ALLOW_WPA=yes
|
||||
WPA_ALLOW_WPA2=yes
|
||||
|
@@ -0,0 +1,16 @@
|
||||
TYPE=Wireless
|
||||
DEVICE=eth2
|
||||
HWADDR=00:16:41:11:22:33
|
||||
NM_CONTROLLED=yes
|
||||
BOOTPROTO=dhcp
|
||||
ESSID=blahblah
|
||||
CHANNEL=1
|
||||
MODE=Ad-Hoc
|
||||
RATE=auto
|
||||
ONBOOT=yes
|
||||
USERCTL=yes
|
||||
PEERDNS=yes
|
||||
IPV6INIT=no
|
||||
CIPHER_GROUP=CCMP
|
||||
KEY_MGMT=WPA-PSK
|
||||
|
@@ -0,0 +1,19 @@
|
||||
TYPE=Wireless
|
||||
DEVICE=eth2
|
||||
HWADDR=00:16:41:11:22:33
|
||||
NM_CONTROLLED=yes
|
||||
BOOTPROTO=dhcp
|
||||
ESSID=blahblah
|
||||
CHANNEL=1
|
||||
MODE=Managed
|
||||
RATE=auto
|
||||
ONBOOT=yes
|
||||
USERCTL=yes
|
||||
PEERDNS=yes
|
||||
IPV6INIT=no
|
||||
CIPHER_PAIRWISE="TKIP CCMP"
|
||||
CIPHER_GROUP="TKIP CCMP WEP40 WEP104"
|
||||
KEY_MGMT=WPA-PSK
|
||||
WPA_ALLOW_WPA=yes
|
||||
WPA_ALLOW_WPA2=yes
|
||||
|
@@ -0,0 +1,14 @@
|
||||
# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile)
|
||||
TYPE=Ethernet
|
||||
DEVICE=eth0
|
||||
HWADDR=00:11:22:33:44:ee
|
||||
BOOTPROTO=dhcp
|
||||
ONBOOT=yes
|
||||
USERCTL=yes
|
||||
IPV6INIT=no
|
||||
NM_CONTROLLED=yes
|
||||
PEERDNS=no
|
||||
DHCP_HOSTNAME=foobar
|
||||
DNS1=4.2.2.1
|
||||
DNS2=4.2.2.2
|
||||
|
@@ -0,0 +1,14 @@
|
||||
# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile)
|
||||
TYPE=Ethernet
|
||||
DEVICE=eth0
|
||||
HWADDR=00:11:22:33:44:ee
|
||||
BOOTPROTO=none
|
||||
ONBOOT=yes
|
||||
USERCTL=yes
|
||||
IPV6INIT=no
|
||||
NM_CONTROLLED=yes
|
||||
DNS1=4.2.2.1
|
||||
DNS2=4.2.2.2
|
||||
IPADDR=192.168.1.5
|
||||
PREFIX=24
|
||||
|
@@ -0,0 +1,10 @@
|
||||
# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile)
|
||||
TYPE=Ethernet
|
||||
DEVICE=eth4
|
||||
HWADDR=00:11:22:33:44:ee
|
||||
BOOTPROTO=dhcp
|
||||
ONBOOT=yes
|
||||
USERCTL=yes
|
||||
NM_CONTROLLED=yes
|
||||
PEERDNS=yes
|
||||
|
@@ -0,0 +1,15 @@
|
||||
# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile)
|
||||
TYPE=Ethernet
|
||||
DEVICE=eth0
|
||||
HWADDR=00:11:22:33:44:ee
|
||||
BOOTPROTO=none
|
||||
ONBOOT=yes
|
||||
USERCTL=yes
|
||||
IPV6INIT=no
|
||||
MTU=1492
|
||||
NM_CONTROLLED=yes
|
||||
DNS1=4.2.2.1
|
||||
DNS2=4.2.2.2
|
||||
IPADDR=192.168.1.5
|
||||
NETMASK=255.255.255.0
|
||||
GATEWAY=192.168.1.1
|
@@ -0,0 +1 @@
|
||||
KEY=0123456789abcdef0123456789
|
@@ -0,0 +1 @@
|
||||
KEY=0123456789abcdef0123456789
|
@@ -0,0 +1,2 @@
|
||||
WPA_PSK="I wonder what the king is doing tonight?"
|
||||
|
@@ -0,0 +1,2 @@
|
||||
WPA_PSK="I wonder what the king is doing tonight?"
|
||||
|
@@ -0,0 +1,2 @@
|
||||
WPA_PSK=1da190379817bc360dda52e85c388c439a21ea5c7bf819c64e9da051807deae6
|
||||
|
@@ -0,0 +1 @@
|
||||
GATEWAY=192.168.1.2
|
@@ -0,0 +1 @@
|
||||
GATEWAYDEV=eth0
|
2217
system-settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
Normal file
2217
system-settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user