diff --git a/libnm-util/libnm-util.ver b/libnm-util/libnm-util.ver index 7507dff00c..98de7d0521 100644 --- a/libnm-util/libnm-util.ver +++ b/libnm-util/libnm-util.ver @@ -520,6 +520,7 @@ global: nm_utils_ip6_routes_from_gvalue; nm_utils_ip6_routes_to_gvalue; nm_utils_is_empty_ssid; + nm_utils_is_uuid; nm_utils_rsa_key_encrypt; nm_utils_same_ssid; nm_utils_security_type_get_type; diff --git a/libnm-util/nm-setting-connection.c b/libnm-util/nm-setting-connection.c index b247a60f9a..77aff4faef 100644 --- a/libnm-util/nm-setting-connection.c +++ b/libnm-util/nm-setting-connection.c @@ -24,7 +24,6 @@ */ #include -#include #include "nm-utils.h" #include "nm-dbus-glib-types.h" #include "nm-param-spec-specialized.h" @@ -628,22 +627,6 @@ find_setting_by_name (gconstpointer a, gconstpointer b) return strcmp (nm_setting_get_name (setting), str); } -static gboolean -validate_uuid (const char *uuid) -{ - int i; - - if (!uuid || !strlen (uuid)) - return FALSE; - - for (i = 0; i < strlen (uuid); i++) { - if (!isxdigit (uuid[i]) && (uuid[i] != '-')) - return FALSE; - } - - return TRUE; -} - static gboolean verify (NMSetting *setting, GSList *all_settings, GError **error) { @@ -669,7 +652,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error) NM_SETTING_CONNECTION_ERROR_MISSING_PROPERTY, NM_SETTING_CONNECTION_UUID); return FALSE; - } else if (!validate_uuid (priv->uuid)) { + } else if (!nm_utils_is_uuid (priv->uuid)) { g_set_error (error, NM_SETTING_CONNECTION_ERROR, NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY, diff --git a/libnm-util/nm-utils.c b/libnm-util/nm-utils.c index 1b04bd75ac..f88f1392b5 100644 --- a/libnm-util/nm-utils.c +++ b/libnm-util/nm-utils.c @@ -2584,7 +2584,7 @@ nm_utils_hwaddr_ntoa (gconstpointer addr, int type) } /** - * nm_utils_iface_name_valid: + * nm_utils_iface_valid_name: * @name: Name of interface * * This function is a 1:1 copy of the kernel's interface validation @@ -2614,3 +2614,28 @@ nm_utils_iface_valid_name (const char *name) return TRUE; } + +/** + * nm_utils_is_uuid: + * @str: a string that might be a UUID + * + * Checks if @str is a UUID + * + * Returns: %TRUE if @str is a UUID, %FALSE if not + */ +gboolean +nm_utils_is_uuid (const char *str) +{ + const char *p = str; + int num_dashes = 0; + + while (*p) { + if (*p == '-') + num_dashes++; + else if (!isxdigit (*p)) + return FALSE; + p++; + } + + return (num_dashes == 4) && (p - str == 36); +} diff --git a/libnm-util/nm-utils.h b/libnm-util/nm-utils.h index 28514864f4..ef4b875d74 100644 --- a/libnm-util/nm-utils.h +++ b/libnm-util/nm-utils.h @@ -137,6 +137,8 @@ guint8 *nm_utils_hwaddr_aton (const char *asc, int type, gpointer buffer); gboolean nm_utils_iface_valid_name(const char *name); +gboolean nm_utils_is_uuid (const char *str); + G_END_DECLS #endif /* NM_UTILS_H */ diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c index c222c3e377..5dcc02fffd 100644 --- a/src/NetworkManagerUtils.c +++ b/src/NetworkManagerUtils.c @@ -799,23 +799,6 @@ nm_utils_complete_generic (NMConnection *connection, } } -gboolean -nm_utils_is_uuid (const char *str) -{ - const char *p = str; - int num_dashes = 0; - - while (*p) { - if (*p == '-') - num_dashes++; - else if (!isxdigit (*p)) - return FALSE; - p++; - } - - return (num_dashes == 4) && (p - str == 36); -} - char * nm_utils_new_vlan_name (const char *parent_iface, guint32 vlan_id) { diff --git a/src/NetworkManagerUtils.h b/src/NetworkManagerUtils.h index 1ee40689d3..057ad283f9 100644 --- a/src/NetworkManagerUtils.h +++ b/src/NetworkManagerUtils.h @@ -90,8 +90,6 @@ void nm_utils_complete_generic (NMConnection *connection, const char *preferred, gboolean default_enable_ipv6); -gboolean nm_utils_is_uuid (const char *str); - char *nm_utils_new_vlan_name (const char *parent_iface, guint32 vlan_id); #endif /* NETWORK_MANAGER_UTILS_H */