From 7e4178b383f65e9a564b7fa20292bfa36cce7e93 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 4 Mar 2016 17:48:02 +0100 Subject: [PATCH] ifcfg-rh: skip loading files for unhandled types due to existing ifup script When an ifcfg file doesn't specify the TYPE, ifup will look for a script "ifup-${DEVICETYPE}", where DEVICETYPE is determined as [ -z "$DEVICETYPE" ] && DEVICETYPE=$(echo ${DEVICE} | sed "s/[0-9]*$//") Avoid handling such files by checking that no such ifup script exists. --- src/settings/plugins/ifcfg-rh/reader.c | 48 ++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c index 14a743dec6..a65ca5d7c4 100644 --- a/src/settings/plugins/ifcfg-rh/reader.c +++ b/src/settings/plugins/ifcfg-rh/reader.c @@ -5010,6 +5010,7 @@ connection_from_file_full (const char *filename, "File '%s' had neither TYPE nor DEVICE keys.", filename); goto done; } + g_assert (device[0]); if (!strcmp (device, "lo")) { if (out_ignore_error) @@ -5027,8 +5028,51 @@ connection_from_file_full (const char *filename, type = g_strdup (TYPE_VLAN); else if (is_wifi_device (device, parsed)) type = g_strdup (TYPE_WIRELESS); - else - type = g_strdup (TYPE_ETHERNET); + else { + gs_free char *p_path = NULL; + char *p_device; + gsize i; + + /* network-functions detects DEVICETYPE based on the ifcfg-* name and the existence + * of a ifup script: + * [ -z "$DEVICETYPE" ] && DEVICETYPE=$(echo ${DEVICE} | sed "s/[0-9]*$//") + * later... + * OTHERSCRIPT="/etc/sysconfig/network-scripts/ifup-${DEVICETYPE}" + * */ +#define IFUP_PATH_PREFIX "/etc/sysconfig/network-scripts/ifup-" + i = strlen (device); + p_path = g_malloc (NM_STRLEN (IFUP_PATH_PREFIX) + i + 1); + p_device = &p_path[NM_STRLEN (IFUP_PATH_PREFIX)]; + memcpy (p_device, device, i + 1); + + /* strip trailing numbers */ + while (i >= 1) { + i--; + if (p_device[i] < '0' || p_device[i] > '9') + break; + p_device[i] = '\0'; + } + + if (nm_streq (p_device, "eth")) + type = g_strdup (TYPE_ETHERNET); + else if (nm_streq (p_device, "wireless")) + type = g_strdup (TYPE_WIRELESS); + else if (p_device[0]) { + memcpy (p_path, IFUP_PATH_PREFIX, NM_STRLEN (IFUP_PATH_PREFIX)); + if (access (p_path, X_OK) == 0) { + /* for all other types, this is not something we want to handle. */ + if (out_ignore_error) + *out_ignore_error = TRUE; + g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, + "Ignore script for unknown device type which has a matching %s script", + p_path); + goto done; + } + } + + if (!type) + 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