libnm: add nm_utils_is_valid_iface_name_utf8safe() util

This commit is contained in:
Thomas Haller 2019-03-24 20:36:00 +01:00
parent e96643a0b6
commit d0727509b2
2 changed files with 25 additions and 0 deletions

View file

@ -250,6 +250,8 @@ guint nm_setting_ethtool_init_features (NMSettingEthtool *setting,
guint8 *_nm_utils_hwaddr_aton (const char *asc, gpointer buffer, gsize buffer_length, gsize *out_length);
const char *nm_utils_hwaddr_ntoa_buf (gconstpointer addr, gsize addr_len, gboolean upper_case, char *buf, gsize buf_len);
gboolean nm_utils_is_valid_iface_name_utf8safe (const char *utf8safe_name);
GSList * _nm_utils_hash_values_to_slist (GHashTable *hash);
GHashTable *_nm_utils_copy_strdict (GHashTable *strdict);

View file

@ -4541,6 +4541,29 @@ _nm_utils_generate_mac_address_mask_parse (const char *value,
/*****************************************************************************/
gboolean
nm_utils_is_valid_iface_name_utf8safe (const char *utf8safe_name)
{
gs_free gpointer bin_to_free = NULL;
gconstpointer bin;
gsize len;
g_return_val_if_fail (utf8safe_name, FALSE);
bin = nm_utils_buf_utf8safe_unescape (utf8safe_name, &len, &bin_to_free);
if (bin_to_free) {
/* some unescaping happened... */
if (len != strlen (bin)) {
/* there are embedded NUL chars. Invalid. */
return FALSE;
}
}
return nm_utils_is_valid_iface_name (bin, NULL);
}
/**
* nm_utils_is_valid_iface_name:
* @name: Name of interface