summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2021-05-02 22:29:56 +0200
committerThomas Haller <thaller@redhat.com>2021-05-04 15:51:53 +0200
commitb12f116a02c658c911d0483423000df942077632 (patch)
tree6a5f6146607bf4ce48d43da214465e741390fd66
parent2fcabf5699cb612a04167e4eba1a89be73a4956b (diff)
downloadNetworkManager-b12f116a02c658c911d0483423000df942077632.tar.gz
glib-aux: add nm_uuid_is_valid_nmlegacy() helper
-rw-r--r--src/libnm-glib-aux/nm-uuid.c41
-rw-r--r--src/libnm-glib-aux/nm-uuid.h4
2 files changed, 45 insertions, 0 deletions
diff --git a/src/libnm-glib-aux/nm-uuid.c b/src/libnm-glib-aux/nm-uuid.c
index 7497b7c489..18badc46d8 100644
--- a/src/libnm-glib-aux/nm-uuid.c
+++ b/src/libnm-glib-aux/nm-uuid.c
@@ -129,6 +129,47 @@ nm_uuid_generate_random(NMUuid *out_uuid)
/*****************************************************************************/
+/**
+ * nm_uuid_is_valid_nmlegacy()
+ * @str: the string to check whether it's a valid UUID.
+ *
+ * Note that this does not perform a strict check.
+ * Instead, it checks a more relaxed format (including
+ * non valid UUID strings). This is for backward compatibility,
+ * where older code did not perform a strict check.
+ *
+ * Returns: %TRUE, if the string is a valid legacy format.
+ * This may not be a valid UUID!
+ */
+gboolean
+nm_uuid_is_valid_nmlegacy(const char *str)
+{
+ const char *p = str;
+ int num_dashes = 0;
+
+ if (!p)
+ return FALSE;
+
+ while (*p) {
+ if (*p == '-')
+ num_dashes++;
+ else if (!g_ascii_isxdigit(*p))
+ return FALSE;
+ p++;
+ }
+
+ if ((num_dashes == 4) && (p - str == 36))
+ return TRUE;
+
+ /* Backwards compat for older configurations */
+ if ((num_dashes == 0) && (p - str == 40))
+ return TRUE;
+
+ return FALSE;
+}
+
+/*****************************************************************************/
+
gboolean
nm_uuid_is_null(const NMUuid *uuid)
{
diff --git a/src/libnm-glib-aux/nm-uuid.h b/src/libnm-glib-aux/nm-uuid.h
index c4a6bdb57c..0cb7ec2311 100644
--- a/src/libnm-glib-aux/nm-uuid.h
+++ b/src/libnm-glib-aux/nm-uuid.h
@@ -33,6 +33,10 @@ gboolean nm_uuid_is_null(const NMUuid *uuid);
/*****************************************************************************/
+gboolean nm_uuid_is_valid_nmlegacy(const char *str);
+
+/*****************************************************************************/
+
char *nm_uuid_generate_random_str(char buf[static 37]);
#define nm_uuid_generate_random_str_arr(buf) \