From 6289caf68f561adba14afa95bd4c745787407e49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Sat, 29 Aug 2015 11:46:46 +0200 Subject: [PATCH] ifcfg-rh: allow svTrueValue() to accept "0" and "1" values Some initscripts variables can use "0" or "1" instead of more common "yes", "no", for example REORDER_HDR. And we also write REORDER_HDR=0|1 in writer.c, so we did not read REODER_HDR correctly. Fixes: ccea4425048cce8aef5a295c7d09daa6b66f596f (cherry picked from commit e8257af0d9324c2b9b59fa37c7283931c10defe1) --- src/settings/plugins/ifcfg-rh/shvar.c | 10 +- .../tests/network-scripts/Makefile.am | 1 + .../ifcfg-test-vlan-reorder-hdr-1 | 7 ++ .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 100 ++++++++++++++++++ 4 files changed, 114 insertions(+), 4 deletions(-) create mode 100644 src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-reorder-hdr-1 diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index 283aa82611..5fd7755fa0 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -299,8 +299,8 @@ svGetValueFull (shvarFile *s, const char *key, gboolean verbatim) return value; } -/* return TRUE if resolves to any truth value (e.g. "yes", "y", "true") - * return FALSE if resolves to any non-truth value (e.g. "no", "n", "false") +/* return TRUE if resolves to any truth value (e.g. "yes", "true", "y", "t", "1") + * return FALSE if resolves to any non-truth value (e.g. "no", "false", "n", "f", "0") * return otherwise */ gint @@ -316,12 +316,14 @@ svTrueValue (shvarFile *s, const char *key, gint def) if ( !g_ascii_strcasecmp ("yes", tmp) || !g_ascii_strcasecmp ("true", tmp) || !g_ascii_strcasecmp ("t", tmp) - || !g_ascii_strcasecmp ("y", tmp)) + || !g_ascii_strcasecmp ("y", tmp) + || !g_ascii_strcasecmp ("1", tmp)) returnValue = TRUE; else if ( !g_ascii_strcasecmp ("no", tmp) || !g_ascii_strcasecmp ("false", tmp) || !g_ascii_strcasecmp ("f", tmp) - || !g_ascii_strcasecmp ("n", tmp)) + || !g_ascii_strcasecmp ("n", tmp) + || !g_ascii_strcasecmp ("0", tmp)) returnValue = FALSE; g_free (tmp); diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am b/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am index 63c10a32db..34d94d1caa 100644 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am @@ -101,6 +101,7 @@ EXTRA_DIST = \ ifcfg-test-vlan-only-vlanid \ ifcfg-test-vlan-only-device \ ifcfg-test-vlan-physdev \ + ifcfg-test-vlan-reorder-hdr-1 \ ifcfg-test-wifi-wep-no-keys \ ifcfg-test-permissions \ ifcfg-test-wifi-wep-agent-keys \ diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-reorder-hdr-1 b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-reorder-hdr-1 new file mode 100644 index 0000000000..ca38f839b1 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-reorder-hdr-1 @@ -0,0 +1,7 @@ +VLAN=yes +TYPE=Vlan +DEVICE=vlan0.3 +PHYSDEV=eth0 +VLAN_ID=3 +REORDER_HDR=1 + diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index 39a0abaf79..731909ce92 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -10949,6 +10949,33 @@ test_read_vlan_physdev (void) g_object_unref (connection); } +static void +test_read_vlan_reorder_hdr_1 (void) +{ + NMConnection *connection; + GError *error = NULL; + NMSettingVlan *s_vlan; + + connection = connection_from_file_test (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-vlan-reorder-hdr-1", + NULL, TYPE_ETHERNET, NULL, + &error); + g_assert_no_error (error); + g_assert (connection); + g_assert (nm_connection_verify (connection, &error)); + + g_assert_cmpstr (nm_connection_get_interface_name (connection), ==, "vlan0.3"); + + s_vlan = nm_connection_get_setting_vlan (connection); + g_assert (s_vlan); + + g_assert_cmpstr (nm_setting_vlan_get_parent (s_vlan), ==, "eth0"); + g_assert_cmpint (nm_setting_vlan_get_id (s_vlan), ==, 3); + /* Check correct read of REORDER_HDR=1 */ + g_assert_cmpint (nm_setting_vlan_get_flags (s_vlan), ==, 1); + + g_object_unref (connection); +} + static void test_write_vlan (void) { @@ -11024,6 +11051,77 @@ test_write_vlan_only_vlanid (void) g_object_unref (reread); } +static void +test_write_vlan_reorder_hdr (void) +{ + NMConnection *connection, *reread; + NMSettingConnection *s_con; + NMSettingVlan *s_vlan; + NMSettingWired *s_wired; + char *uuid; + GError *error = NULL; + gboolean success; + char *testfile = NULL; + + connection = nm_simple_connection_new (); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new (); + nm_connection_add_setting (connection, NM_SETTING (s_con)); + + uuid = nm_utils_uuid_generate (); + g_object_set (s_con, + NM_SETTING_CONNECTION_ID, "Test Write VLAN reorder_hdr", + NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_AUTOCONNECT, FALSE, + NM_SETTING_CONNECTION_TYPE, NM_SETTING_VLAN_SETTING_NAME, + NULL); + g_free (uuid); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new (); + nm_connection_add_setting (connection, NM_SETTING (s_wired)); + + /* VLAN setting */ + s_vlan = (NMSettingVlan *) nm_setting_vlan_new (); + nm_connection_add_setting (connection, NM_SETTING (s_vlan)); + + g_object_set (s_vlan, + NM_SETTING_VLAN_PARENT, "eth0", + NM_SETTING_VLAN_ID, 444, + NM_SETTING_VLAN_FLAGS, 1, + NULL); + + /* Save the ifcfg */ + success = writer_new_connection (connection, + TEST_SCRATCH_DIR "/network-scripts/", + &testfile, + &error); + g_assert_no_error (error); + g_assert (success); + g_assert (testfile); + + /* reread will be normalized, so we must normalize connection too. */ + nm_connection_normalize (connection, NULL, NULL, NULL); + + /* re-read the connection for comparison */ + reread = connection_from_file_test (testfile, + NULL, + TYPE_ETHERNET, + NULL, + &error); + unlink (testfile); + + g_assert_no_error (error); + g_assert (reread); + g_assert (nm_connection_verify (reread, &error)); + g_assert (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT)); + + g_object_unref (connection); + g_object_unref (reread); + g_free (testfile); +} + static void test_write_ethernet_missing_ipv6 (void) { @@ -12717,6 +12815,7 @@ int main (int argc, char **argv) test_read_vlan_only_vlan_id (); test_read_vlan_only_device (); g_test_add_func (TPATH "vlan/physdev", test_read_vlan_physdev); + g_test_add_func (TPATH "vlan/reorder-hdr-1", test_read_vlan_reorder_hdr_1); g_test_add_func (TPATH "wired/read-wake-on-lan", test_read_wired_wake_on_lan); test_write_wired_static (); @@ -12796,6 +12895,7 @@ int main (int argc, char **argv) test_write_infiniband (); test_write_vlan (); test_write_vlan_only_vlanid (); + g_test_add_func (TPATH "vlan/write-vlan-reorder-hdr", test_write_vlan_reorder_hdr); test_write_ethernet_missing_ipv6 (); /* iSCSI / ibft */