mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-10 19:50:22 +01:00
ifcfg-rh: strip trailing whitespace from ifcfg files (rh #1100336)
shvar.c has apparently never stripped trailing whitespace, but obviously a shell doesn't care. Unfortunately NM does. Strip trailing whitespace before unescaping, to preserve quoted whitespace. https://bugzilla.redhat.com/show_bug.cgi?id=1100336
This commit is contained in:
parent
b5668f22be
commit
941897cc97
4 changed files with 53 additions and 2 deletions
|
|
@ -265,7 +265,8 @@ svGetValue (shvarFile *s, const char *key, gboolean verbatim)
|
|||
for (s->current = s->lineList; s->current; s->current = s->current->next) {
|
||||
line = s->current->data;
|
||||
if (!strncmp (keyString, line, len)) {
|
||||
value = g_strdup (line + len);
|
||||
/* Strip trailing spaces before unescaping to preserve spaces quoted whitespace */
|
||||
value = g_strchomp (g_strdup (line + len));
|
||||
if (!verbatim)
|
||||
svUnescape (value);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -119,7 +119,8 @@ EXTRA_DIST = \
|
|||
ifcfg-test-fcoe-vn2vn \
|
||||
ifcfg-test-team-master \
|
||||
ifcfg-test-team-port \
|
||||
ifcfg-test-team-port-empty-config
|
||||
ifcfg-test-team-port-empty-config \
|
||||
ifcfg-test-vlan-trailing-spaces
|
||||
|
||||
# make target dependencies can't have colons in their names, which ends up
|
||||
# meaning that we can't add the alias files to EXTRA_DIST
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
DEVICE="vlan201"
|
||||
ONBOOT=yes
|
||||
NETBOOT=yes
|
||||
BOOTPROTO=none
|
||||
IPADDR="10.130.70.7"
|
||||
NETMASK="255.255.0.0"
|
||||
TYPE=Vlan
|
||||
NAME="vlan201"
|
||||
VLAN=yes
|
||||
PHYSDEV="enccw0.0.fb00"
|
||||
|
||||
|
|
@ -13452,6 +13452,43 @@ test_svUnescape (void)
|
|||
g_rand_free (r);
|
||||
}
|
||||
|
||||
static void
|
||||
test_read_vlan_trailing_spaces (void)
|
||||
{
|
||||
const char *testfile = TEST_IFCFG_DIR"/network-scripts/ifcfg-test-vlan-trailing-spaces";
|
||||
NMConnection *connection;
|
||||
gboolean success;
|
||||
GError *error = NULL;
|
||||
NMSettingVlan *s_vlan;
|
||||
char *contents = NULL;
|
||||
|
||||
/* Ensure there is whitespace at the end of the VLAN interface name,
|
||||
* to prevent the whitespace getting stripped off and committed mistakenly
|
||||
* by something in the future.
|
||||
*/
|
||||
success = g_file_get_contents (testfile, &contents, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (success);
|
||||
g_assert (contents && contents[0]);
|
||||
g_assert (strstr (contents, "DEVICE=\"vlan201\" \n"));
|
||||
g_free (contents);
|
||||
|
||||
connection = connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL,
|
||||
NULL, NULL, NULL, &error, NULL);
|
||||
g_assert_no_error (error);
|
||||
g_assert (connection != NULL);
|
||||
|
||||
s_vlan = nm_connection_get_setting_vlan (connection);
|
||||
g_assert (s_vlan);
|
||||
|
||||
g_assert_cmpstr (nm_connection_get_interface_name (connection), ==, "vlan201");
|
||||
g_assert_cmpstr (nm_setting_vlan_get_parent (s_vlan), ==, "enccw0.0.fb00");
|
||||
g_assert_cmpint (nm_setting_vlan_get_id (s_vlan), ==, 201);
|
||||
g_assert_cmpint (nm_setting_vlan_get_flags (s_vlan), ==, 0);
|
||||
|
||||
g_object_unref (connection);
|
||||
}
|
||||
|
||||
|
||||
#define TEST_IFCFG_WIFI_OPEN_SSID_BAD_HEX TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-open-ssid-bad-hex"
|
||||
#define TEST_IFCFG_WIFI_OPEN_SSID_LONG_QUOTED TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-open-ssid-long-quoted"
|
||||
|
|
@ -13477,6 +13514,7 @@ int main (int argc, char **argv)
|
|||
nmtst_init_assert_logging (&argc, &argv);
|
||||
|
||||
g_test_add_func (TPATH "svUnescape", test_svUnescape);
|
||||
g_test_add_func (TPATH "vlan-trailing-spaces", test_read_vlan_trailing_spaces);
|
||||
|
||||
g_test_add_func (TPATH "unmanaged", test_read_unmanaged);
|
||||
g_test_add_func (TPATH "unmanaged-unrecognized", test_read_unmanaged_unrecognized);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue