Commit 260563a7 authored by Lubomir Rintel's avatar Lubomir Rintel

all: use nm_utils_is_valid_iface_name()

parent ac0563d7
......@@ -3991,16 +3991,18 @@ set_connection_type (NmCli *nmc, NMConnection *con, OptionInfo *option, const ch
static gboolean
set_connection_iface (NmCli *nmc, NMConnection *con, OptionInfo *option, const char *value, GError **error)
{
GError *tmp_error = NULL;
if (value) {
if (!nm_utils_iface_valid_name (value) && strcmp (value, "*") != 0) {
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
_("Error: '%s' is not a valid interface nor '*'."),
value);
return FALSE;
}
/* Special value of '*' means no specific interface name */
if (strcmp (value, "*") == 0)
value = NULL;
else if (!nm_utils_is_valid_iface_name (value, &tmp_error)) {
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
_("Error: '%s': %s"), value, tmp_error->message);
g_error_free (tmp_error);
return FALSE;
}
}
return set_property (con, option->setting_name, option->property, value, '\0', error);
......
......@@ -3080,10 +3080,8 @@ nmc_property_set_ifname (NMSetting *setting, const char *prop, const char *val,
{
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
if (!nm_utils_iface_valid_name (val)) {
g_set_error (error, 1, 0, _("'%s' is not a valid interface name"), val);
if (!nm_utils_is_valid_iface_name (val, error))
return FALSE;
}
g_object_set (setting, prop, val, NULL);
return TRUE;
}
......@@ -3345,7 +3343,7 @@ nmc_property_con_set_master (NMSetting *setting, const char *prop, const char *v
;
else if (!*val)
val = NULL;
else if ( !nm_utils_iface_valid_name (val)
else if ( !nm_utils_is_valid_iface_name (val, NULL)
&& !nm_utils_is_uuid (val)) {
g_set_error (error, 1, 0,
_("'%s' is not valid master; use ifname or connection UUID"),
......
......@@ -118,7 +118,7 @@ device_entry_parse (NmtDeviceEntry *deventry,
return TRUE;
if (priv->hardware_type == G_TYPE_NONE && !priv->device_filter) {
if (nm_utils_iface_valid_name (text)) {
if (nm_utils_is_valid_iface_name (text, NULL)) {
*interface_name = g_strdup (text);
return TRUE;
} else
......@@ -142,12 +142,12 @@ device_entry_parse (NmtDeviceEntry *deventry,
len = nm_utils_hwaddr_len (priv->arptype);
if ( nm_utils_hwaddr_aton (words[0], buf, len)
&& (!words[1] || nm_utils_iface_valid_name (words[1]))) {
&& (!words[1] || nm_utils_is_valid_iface_name (words[1], NULL))) {
*mac_address = words[0];
*interface_name = NULL;
g_free (words);
return TRUE;
} else if ( nm_utils_iface_valid_name (words[0])
} else if ( nm_utils_is_valid_iface_name (words[0], NULL)
&& (!words[1] || nm_utils_hwaddr_aton (words[1], buf, len))) {
*interface_name = words[0];
*mac_address = NULL;
......
......@@ -245,7 +245,7 @@ validate_ifname (const char *name, const char *value)
if (!value || !value[0])
return FALSE;
return nm_utils_iface_valid_name (value);
return nm_utils_is_valid_iface_name (value, NULL);
}
/**
......@@ -618,13 +618,16 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
primary = g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_PRIMARY);
if (strcmp (mode_new, "active-backup") == 0) {
if (primary && !nm_utils_iface_valid_name (primary)) {
GError *tmp_error = NULL;
if (primary && !nm_utils_is_valid_iface_name (primary, &tmp_error)) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
_("'%s' is not a valid interface name for '%s' option"),
primary, NM_SETTING_BOND_OPTION_PRIMARY);
_("'%s' is not a valid for '%s' option: %s"),
primary, NM_SETTING_BOND_OPTION_PRIMARY, tmp_error->message);
g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
g_error_free (tmp_error);
return FALSE;
}
} else {
......
......@@ -891,13 +891,15 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
}
if (priv->interface_name) {
if (!nm_utils_iface_valid_name (priv->interface_name)) {
GError *tmp_error = NULL;
if (!nm_utils_is_valid_iface_name (priv->interface_name, &tmp_error)) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
_("'%s' is not a valid interface name"),
priv->interface_name);
"'%s': %s", priv->interface_name, tmp_error->message);
g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME);
g_error_free (tmp_error);
return FALSE;
}
}
......@@ -1104,7 +1106,7 @@ nm_setting_connection_set_interface_name (NMSetting *setting,
* overridden by a valid connection.interface-name.
*/
interface_name = find_virtual_interface_name (connection_dict);
if (!interface_name || nm_utils_iface_valid_name (interface_name))
if (!interface_name || nm_utils_is_valid_iface_name (interface_name, NULL))
interface_name = g_variant_get_string (value, NULL);
g_object_set (G_OBJECT (setting),
......
......@@ -210,12 +210,15 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
}
if (priv->parent) {
if (!nm_utils_iface_valid_name (priv->parent)) {
g_set_error_literal (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
_("not a valid interface name"));
GError *tmp_error = NULL;
if (!nm_utils_is_valid_iface_name (priv->parent, &tmp_error)) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
"'%s': %s", priv->parent, tmp_error->message);
g_prefix_error (error, "%s: ", NM_SETTING_INFINIBAND_PARENT);
g_error_free (tmp_error);
return FALSE;
}
if (priv->p_key == -1) {
......@@ -241,10 +244,11 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
s_con = nm_connection_get_setting_connection (connection);
if (s_con) {
const char *interface_name = nm_setting_connection_get_interface_name (s_con);
GError *tmp_error = NULL;
if (!interface_name)
;
else if (!nm_utils_iface_valid_name (interface_name)) {
else if (!nm_utils_is_valid_iface_name (interface_name, &tmp_error)) {
/* report the error for NMSettingConnection:interface-name, because
* it's that property that is invalid -- although we currently verify()
* NMSettingInfiniband.
......@@ -252,9 +256,9 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
_("'%s' is not a valid interface name"),
interface_name);
"'%s': %s", interface_name, tmp_error->message);
g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME);
g_error_free (tmp_error);
return FALSE;
} else {
if (priv->p_key != -1) {
......
......@@ -2233,7 +2233,7 @@ verify_label (const char *label)
if (!p)
return FALSE;
iface = g_strndup (label, p - label);
if (!nm_utils_iface_valid_name (iface)) {
if (!nm_utils_is_valid_iface_name (iface, NULL)) {
g_free (iface);
return FALSE;
}
......
......@@ -322,7 +322,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
}
if ( priv->parent
&& !nm_utils_iface_valid_name (priv->parent)
&& !nm_utils_is_valid_iface_name (priv->parent, NULL)
&& !nm_utils_is_uuid (priv->parent)) {
g_set_error (error,
NM_CONNECTION_ERROR,
......
......@@ -160,7 +160,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
if (priv->parent) {
if ( !nm_utils_is_uuid (priv->parent)
&& !nm_utils_iface_valid_name (priv->parent)) {
&& !nm_utils_is_valid_iface_name (priv->parent, NULL)) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
......
......@@ -637,7 +637,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
return FALSE;
}
}
} else if (!nm_utils_iface_valid_name (priv->parent)) {
} else if (!nm_utils_is_valid_iface_name (priv->parent, NULL)) {
/* parent must be either a UUID or an interface name */
g_set_error (error,
NM_CONNECTION_ERROR,
......
......@@ -395,7 +395,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
}
if ( priv->parent
&& !nm_utils_iface_valid_name (priv->parent)
&& !nm_utils_is_valid_iface_name (priv->parent, NULL)
&& !nm_utils_is_uuid (priv->parent)) {
g_set_error (error,
NM_CONNECTION_ERROR,
......
......@@ -202,12 +202,10 @@ nm_device_factory_get_connection_iface (NMDeviceFactory *factory,
return NULL;
}
if (!nm_utils_iface_valid_name (ifname)) {
g_set_error (error,
NM_MANAGER_ERROR,
NM_MANAGER_ERROR_FAILED,
"failed to determine interface name: name \"%s\" is invalid",
ifname);
if (!nm_utils_is_valid_iface_name (ifname, error)) {
g_prefix_error (error,
"failed to determine interface name: name \"%s\" is invalid",
ifname);
g_free (ifname);
return NULL;
}
......
......@@ -3606,7 +3606,7 @@ nm_utils_ifname_cpy (char *dst, const char *name)
g_return_if_fail (dst);
g_return_if_fail (name && name[0]);
nm_assert (nm_utils_iface_valid_name (name));
nm_assert (nm_utils_is_valid_iface_name (name, NULL));
if (g_strlcpy (dst, name, IFNAMSIZ) >= IFNAMSIZ)
g_return_if_reached ();
......
......@@ -723,7 +723,7 @@ nmp_utils_sysctl_open_netdir (int ifindex,
return -1;
}
nm_assert (nm_utils_iface_valid_name (ifname));
nm_assert (nm_utils_is_valid_iface_name (ifname, NULL));
if (g_strlcpy (&sysdir[NM_STRLEN (SYS_CLASS_NET)], ifname, IFNAMSIZ) >= IFNAMSIZ)
g_return_val_if_reached (-1);
......
......@@ -226,7 +226,7 @@ nmtstp_ip4_route_exists (const char *ifname, guint32 network, int plen, guint32
gs_free_error GError *error = NULL;
gs_free char *metric_pattern = NULL;
g_assert (ifname && nm_utils_iface_valid_name (ifname));
g_assert (ifname && nm_utils_is_valid_iface_name (ifname, NULL));
g_assert (!strstr (ifname, " metric "));
g_assert (plen >= 0 && plen <= 32);
......@@ -933,7 +933,7 @@ nmtstp_link_dummy_add (NMPlatform *platform,
const NMPlatformLink *pllink = NULL;
gboolean success;
g_assert (nm_utils_iface_valid_name (name));
g_assert (nm_utils_is_valid_iface_name (name, NULL));
external_command = nmtstp_run_command_check_external (external_command);
......@@ -962,7 +962,7 @@ nmtstp_link_gre_add (NMPlatform *platform,
gboolean success;
char buffer[INET_ADDRSTRLEN];
g_assert (nm_utils_iface_valid_name (name));
g_assert (nm_utils_is_valid_iface_name (name, NULL));
external_command = nmtstp_run_command_check_external (external_command);
......@@ -1002,7 +1002,7 @@ nmtstp_link_ip6tnl_add (NMPlatform *platform,
gboolean success;
char buffer[INET6_ADDRSTRLEN];
g_assert (nm_utils_iface_valid_name (name));
g_assert (nm_utils_is_valid_iface_name (name, NULL));
external_command = nmtstp_run_command_check_external (external_command);
......@@ -1056,7 +1056,7 @@ nmtstp_link_ipip_add (NMPlatform *platform,
gboolean success;
char buffer[INET_ADDRSTRLEN];
g_assert (nm_utils_iface_valid_name (name));
g_assert (nm_utils_is_valid_iface_name (name, NULL));
external_command = nmtstp_run_command_check_external (external_command);
......@@ -1097,7 +1097,7 @@ nmtstp_link_macvlan_add (NMPlatform *platform,
gboolean success;
NMLinkType link_type;
g_assert (nm_utils_iface_valid_name (name));
g_assert (nm_utils_is_valid_iface_name (name, NULL));
external_command = nmtstp_run_command_check_external (external_command);
......@@ -1144,7 +1144,7 @@ nmtstp_link_sit_add (NMPlatform *platform,
gboolean success;
char buffer[INET_ADDRSTRLEN];
g_assert (nm_utils_iface_valid_name (name));
g_assert (nm_utils_is_valid_iface_name (name, NULL));
external_command = nmtstp_run_command_check_external (external_command);
......@@ -1189,7 +1189,7 @@ nmtstp_link_vxlan_add (NMPlatform *platform,
NMPlatformError plerr;
int err;
g_assert (nm_utils_iface_valid_name (name));
g_assert (nm_utils_is_valid_iface_name (name, NULL));
external_command = nmtstp_run_command_check_external (external_command);
......@@ -1273,7 +1273,7 @@ nmtstp_link_get_typed (NMPlatform *platform,
g_assert_cmpstr (name, ==, pllink->name);
}
g_assert (!name || nm_utils_iface_valid_name (name));
g_assert (!name || nm_utils_is_valid_iface_name (name, NULL));
if (pllink && link_type != NM_LINK_TYPE_NONE)
g_assert_cmpint (pllink->type, ==, link_type);
......
......@@ -159,12 +159,16 @@ make_connection_setting (const char *file,
value = svGetValueString (ifcfg, "DEVICE");
if (value) {
if (nm_utils_iface_valid_name (value)) {
GError *error = NULL;
if (nm_utils_is_valid_iface_name (value, &error)) {
g_object_set (s_con,
NM_SETTING_CONNECTION_INTERFACE_NAME, value,
NULL);
} else
PARSE_WARNING ("invalid DEVICE name '%s'", value);
} else {
PARSE_WARNING ("invalid DEVICE name '%s': %s", value, error->message);
g_error_free (error);
}
g_free (value);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment