From ee32de41cfd47f25932f7dc872f977a93375cc73 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 28 Sep 2022 13:10:14 +0200 Subject: [PATCH 1/9] glib-aux: add code comment to NM_UUID_INIT() `NM_UUID_INIT(00, 09, 01, ...)` would look as if the values are octal numbers. That is not the case. The macro mangles them, so that the look like the UUID in string form "000901...". This is a bit odd. Maybe more confusing than helpful. Or maybe helpful? --- src/libnm-glib-aux/nm-uuid.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libnm-glib-aux/nm-uuid.h b/src/libnm-glib-aux/nm-uuid.h index 15b03a2d47..f84778998e 100644 --- a/src/libnm-glib-aux/nm-uuid.h +++ b/src/libnm-glib-aux/nm-uuid.h @@ -9,6 +9,9 @@ typedef struct _NMUuid { #define NM_UUID_INIT_ZERO() ((NMUuid){.uuid = {0}}) +/* Beware, the 16 macro arguments are two hex-digits, not plain numbers. The macro + * will automatically add the "0x". In particular, "09" is not an octal number, it's + * 0x09. This oddity is so that the arguments look very much like the UUID in string form. */ #define NM_UUID_INIT(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) \ ((NMUuid){ \ .uuid = {(0x##a0), \ From 2fcea1cf05af28dc76c015f2fef01d58dee9d2ba Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 28 Sep 2022 10:40:22 +0200 Subject: [PATCH 2/9] glib-aux: rename nm_uuid_generate_from_strings() to nm_uuid_generate_from_strings_v3() nm_uuid_generate_from_strings() uses variant3 UUIDs based on MD5. We shouldn't use that in the future. We will add a replacement, so rename this function so that the "good" name is free again. Of course, code that uses this function currently relies on that the behavior doesn't change. We cannot just drop it entirely, but will replace it by something that gives the same result. Rename. --- src/core/devices/nm-device-ethernet.c | 10 +++--- .../keyfile/tests/test-keyfile-settings.c | 2 +- src/libnm-core-impl/nm-keyfile.c | 2 +- src/libnm-core-impl/tests/test-general.c | 34 +++++++++---------- src/libnm-glib-aux/nm-uuid.c | 6 ++-- src/libnm-glib-aux/nm-uuid.h | 2 +- src/nm-initrd-generator/nmi-ibft-reader.c | 14 ++++---- 7 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/core/devices/nm-device-ethernet.c b/src/core/devices/nm-device-ethernet.c index 40c6d208e1..6cd5e32292 100644 --- a/src/core/devices/nm-device-ethernet.c +++ b/src/core/devices/nm-device-ethernet.c @@ -1725,11 +1725,11 @@ new_default_connection(NMDevice *self) /* Create a stable UUID. The UUID is also the Network_ID for stable-privacy addr-gen-mode, * thus when it changes we will also generate different IPv6 addresses. */ - uuid = nm_uuid_generate_from_strings("default-wired", - nm_utils_machine_id_str(), - defname, - perm_hw_addr ?: iface, - NULL); + uuid = nm_uuid_generate_from_strings_v3("default-wired", + nm_utils_machine_id_str(), + defname, + perm_hw_addr ?: iface, + NULL); g_object_set(setting, NM_SETTING_CONNECTION_ID, diff --git a/src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c b/src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c index 1307d4b2f8..eae94920b6 100644 --- a/src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c +++ b/src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c @@ -2296,7 +2296,7 @@ test_read_missing_id_uuid(void) gs_free char *expected_uuid = NULL; const char *FILENAME = TEST_KEYFILES_DIR "/Test_Missing_ID_UUID"; - expected_uuid = nm_uuid_generate_from_strings("keyfile", FILENAME, NULL); + expected_uuid = nm_uuid_generate_from_strings_v3("keyfile", FILENAME, NULL); connection = keyfile_read_connection_from_file(FILENAME); diff --git a/src/libnm-core-impl/nm-keyfile.c b/src/libnm-core-impl/nm-keyfile.c index 384522c0cf..fdd3341fba 100644 --- a/src/libnm-core-impl/nm-keyfile.c +++ b/src/libnm-core-impl/nm-keyfile.c @@ -3800,7 +3800,7 @@ nm_keyfile_read_ensure_uuid(NMConnection *connection, const char *fallback_uuid_ if (nm_setting_connection_get_uuid(s_con)) return FALSE; - hashed_uuid = nm_uuid_generate_from_strings("keyfile", fallback_uuid_seed, NULL); + hashed_uuid = nm_uuid_generate_from_strings_v3("keyfile", fallback_uuid_seed, NULL); g_object_set(s_con, NM_SETTING_CONNECTION_UUID, hashed_uuid, NULL); return TRUE; } diff --git a/src/libnm-core-impl/tests/test-general.c b/src/libnm-core-impl/tests/test-general.c index 0a47890f1f..a9e5d2e788 100644 --- a/src/libnm-core-impl/tests/test-general.c +++ b/src/libnm-core-impl/tests/test-general.c @@ -7946,7 +7946,7 @@ test_nm_utils_uuid_generate_from_string(void) /*****************************************************************************/ static void -__test_uuid(const char *expected_uuid, const char *str, gssize slen, char *uuid_test) +_check_uuid_v3(const char *expected_uuid, const char *str, gssize slen, char *uuid_test) { g_assert(uuid_test); g_assert(nm_uuid_is_normalized(uuid_test)); @@ -7975,8 +7975,8 @@ __test_uuid(const char *expected_uuid, const char *str, gssize slen, char *uuid_ g_free(uuid_test); } -#define _test_uuid(expected_uuid, str, strlen, ...) \ - __test_uuid(expected_uuid, str, strlen, nm_uuid_generate_from_strings(__VA_ARGS__, NULL)) +#define check_uuid_v3(expected_uuid, str, strlen, ...) \ + _check_uuid_v3(expected_uuid, str, strlen, nm_uuid_generate_from_strings_v3(__VA_ARGS__, NULL)) static void test_nm_utils_uuid_generate_from_strings(void) @@ -7998,20 +7998,20 @@ test_nm_utils_uuid_generate_from_strings(void) g_assert_cmpstr(NM_UUID_NS_1, ==, nm_uuid_unparse(&nm_uuid_ns_1, buf)); g_assert_cmpstr(NM_UUID_NS_ZERO, ==, nm_uuid_unparse(&nm_uuid_ns_zero, buf)); - _test_uuid("b07c334a-399b-32de-8d50-58e4e08f98e3", "", 0, NULL); - _test_uuid("b8a426cb-bcb5-30a3-bd8f-6786fea72df9", "\0", 1, ""); - _test_uuid("12a4a982-7aae-39e1-951e-41aeb1250959", "a\0", 2, "a"); - _test_uuid("69e22c7e-f89f-3a43-b239-1cb52ed8db69", "aa\0", 3, "aa"); - _test_uuid("59829fd3-5ad5-3d90-a7b0-4911747e4088", "\0\0", 2, "", ""); - _test_uuid("01ad0e06-6c50-3384-8d86-ddab81421425", "a\0\0", 3, "a", ""); - _test_uuid("e1ed8647-9ed3-3ec8-8c6d-e8204524d71d", "aa\0\0", 4, "aa", ""); - _test_uuid("fb1c7cd6-275c-3489-9382-83b900da8af0", "\0a\0", 3, "", "a"); - _test_uuid("5d79494e-c4ba-31a6-80a2-d6016ccd7e17", "a\0a\0", 4, "a", "a"); - _test_uuid("fd698d86-1b60-3ebe-855f-7aada9950a8d", "aa\0a\0", 5, "aa", "a"); - _test_uuid("8c573b48-0f01-30ba-bb94-c5f59f4fe517", "\0aa\0", 4, "", "aa"); - _test_uuid("2bdd3d46-eb83-3c53-a41b-a724d04b5544", "a\0aa\0", 5, "a", "aa"); - _test_uuid("13d4b780-07c1-3ba7-b449-81c4844ef039", "aa\0aa\0", 6, "aa", "aa"); - _test_uuid("dd265bf7-c05a-3037-9939-b9629858a477", "a\0b\0", 4, "a", "b"); + check_uuid_v3("b07c334a-399b-32de-8d50-58e4e08f98e3", "", 0, NULL); + check_uuid_v3("b8a426cb-bcb5-30a3-bd8f-6786fea72df9", "\0", 1, ""); + check_uuid_v3("12a4a982-7aae-39e1-951e-41aeb1250959", "a\0", 2, "a"); + check_uuid_v3("69e22c7e-f89f-3a43-b239-1cb52ed8db69", "aa\0", 3, "aa"); + check_uuid_v3("59829fd3-5ad5-3d90-a7b0-4911747e4088", "\0\0", 2, "", ""); + check_uuid_v3("01ad0e06-6c50-3384-8d86-ddab81421425", "a\0\0", 3, "a", ""); + check_uuid_v3("e1ed8647-9ed3-3ec8-8c6d-e8204524d71d", "aa\0\0", 4, "aa", ""); + check_uuid_v3("fb1c7cd6-275c-3489-9382-83b900da8af0", "\0a\0", 3, "", "a"); + check_uuid_v3("5d79494e-c4ba-31a6-80a2-d6016ccd7e17", "a\0a\0", 4, "a", "a"); + check_uuid_v3("fd698d86-1b60-3ebe-855f-7aada9950a8d", "aa\0a\0", 5, "aa", "a"); + check_uuid_v3("8c573b48-0f01-30ba-bb94-c5f59f4fe517", "\0aa\0", 4, "", "aa"); + check_uuid_v3("2bdd3d46-eb83-3c53-a41b-a724d04b5544", "a\0aa\0", 5, "a", "aa"); + check_uuid_v3("13d4b780-07c1-3ba7-b449-81c4844ef039", "aa\0aa\0", 6, "aa", "aa"); + check_uuid_v3("dd265bf7-c05a-3037-9939-b9629858a477", "a\0b\0", 4, "a", "b"); } static void diff --git a/src/libnm-glib-aux/nm-uuid.c b/src/libnm-glib-aux/nm-uuid.c index 817279db6b..9a75d1c7af 100644 --- a/src/libnm-glib-aux/nm-uuid.c +++ b/src/libnm-glib-aux/nm-uuid.c @@ -12,7 +12,7 @@ const NMUuid nm_uuid_ns_zero = NM_UUID_INIT(00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00); -/* arbitrarily chosen namespace UUID for nm_uuid_generate_from_strings() */ +/* arbitrarily chosen namespace UUID for nm_uuid_generate_from_strings_v3() */ const NMUuid nm_uuid_ns_1 = NM_UUID_INIT(b4, 25, e9, fb, 75, 98, 44, b4, 9e, 3b, 5a, 2e, 3a, aa, 49, 05); @@ -406,7 +406,7 @@ nm_uuid_generate_from_string_str(const char *s, } /** - * nm_uuid_generate_from_strings: + * nm_uuid_generate_from_strings_v3: * @string1: a variadic list of strings. Must be NULL terminated. * * Returns a variant3 UUID based on the concatenated C strings. @@ -419,7 +419,7 @@ nm_uuid_generate_from_string_str(const char *s, * ("aa"), ("aa", ""), ("", "aa"), ... */ char * -nm_uuid_generate_from_strings(const char *string1, ...) +nm_uuid_generate_from_strings_v3(const char *string1, ...) { if (!string1) return nm_uuid_generate_from_string_str(NULL, 0, NM_UUID_TYPE_VERSION3, &nm_uuid_ns_1); diff --git a/src/libnm-glib-aux/nm-uuid.h b/src/libnm-glib-aux/nm-uuid.h index f84778998e..5448191c03 100644 --- a/src/libnm-glib-aux/nm-uuid.h +++ b/src/libnm-glib-aux/nm-uuid.h @@ -123,7 +123,7 @@ char *nm_uuid_generate_from_string_str(const char *s, NMUuidType uuid_type, const NMUuid *type_args); -char *nm_uuid_generate_from_strings(const char *string1, ...) G_GNUC_NULL_TERMINATED; +char *nm_uuid_generate_from_strings_v3(const char *string1, ...) G_GNUC_NULL_TERMINATED; /*****************************************************************************/ diff --git a/src/nm-initrd-generator/nmi-ibft-reader.c b/src/nm-initrd-generator/nmi-ibft-reader.c index a5330fd2cb..66472f784b 100644 --- a/src/nm-initrd-generator/nmi-ibft-reader.c +++ b/src/nm-initrd-generator/nmi-ibft-reader.c @@ -307,13 +307,13 @@ connection_setting_add(GHashTable *nic, s_index ? " " : "", s_index ? s_index : ""); - uuid = nm_uuid_generate_from_strings("ibft", - s_hwaddr, - s_vlanid ? "V" : "v", - s_vlanid ? s_vlanid : "", - s_ipaddr ? "A" : "DHCP", - s_ipaddr ? s_ipaddr : "", - NULL); + uuid = nm_uuid_generate_from_strings_v3("ibft", + s_hwaddr, + s_vlanid ? "V" : "v", + s_vlanid ? s_vlanid : "", + s_ipaddr ? "A" : "DHCP", + s_ipaddr ? s_ipaddr : "", + NULL); s_con = (NMSetting *) nm_connection_get_setting_connection(connection); if (!s_con) { From a33459ed2f8f91ded9dbce3b77d7afcbcfdf9510 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 28 Sep 2022 11:46:09 +0200 Subject: [PATCH 3/9] libnm/tests: drop redundant argument in test code --- src/libnm-core-impl/tests/test-general.c | 35 +++++++++++++----------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/libnm-core-impl/tests/test-general.c b/src/libnm-core-impl/tests/test-general.c index a9e5d2e788..d214db5616 100644 --- a/src/libnm-core-impl/tests/test-general.c +++ b/src/libnm-core-impl/tests/test-general.c @@ -7975,8 +7975,11 @@ _check_uuid_v3(const char *expected_uuid, const char *str, gssize slen, char *uu g_free(uuid_test); } -#define check_uuid_v3(expected_uuid, str, strlen, ...) \ - _check_uuid_v3(expected_uuid, str, strlen, nm_uuid_generate_from_strings_v3(__VA_ARGS__, NULL)) +#define check_uuid_v3(expected_uuid, str, ...) \ + _check_uuid_v3(expected_uuid, \ + str, \ + NM_STRLEN(str), \ + nm_uuid_generate_from_strings_v3(__VA_ARGS__, NULL)) static void test_nm_utils_uuid_generate_from_strings(void) @@ -7998,20 +8001,20 @@ test_nm_utils_uuid_generate_from_strings(void) g_assert_cmpstr(NM_UUID_NS_1, ==, nm_uuid_unparse(&nm_uuid_ns_1, buf)); g_assert_cmpstr(NM_UUID_NS_ZERO, ==, nm_uuid_unparse(&nm_uuid_ns_zero, buf)); - check_uuid_v3("b07c334a-399b-32de-8d50-58e4e08f98e3", "", 0, NULL); - check_uuid_v3("b8a426cb-bcb5-30a3-bd8f-6786fea72df9", "\0", 1, ""); - check_uuid_v3("12a4a982-7aae-39e1-951e-41aeb1250959", "a\0", 2, "a"); - check_uuid_v3("69e22c7e-f89f-3a43-b239-1cb52ed8db69", "aa\0", 3, "aa"); - check_uuid_v3("59829fd3-5ad5-3d90-a7b0-4911747e4088", "\0\0", 2, "", ""); - check_uuid_v3("01ad0e06-6c50-3384-8d86-ddab81421425", "a\0\0", 3, "a", ""); - check_uuid_v3("e1ed8647-9ed3-3ec8-8c6d-e8204524d71d", "aa\0\0", 4, "aa", ""); - check_uuid_v3("fb1c7cd6-275c-3489-9382-83b900da8af0", "\0a\0", 3, "", "a"); - check_uuid_v3("5d79494e-c4ba-31a6-80a2-d6016ccd7e17", "a\0a\0", 4, "a", "a"); - check_uuid_v3("fd698d86-1b60-3ebe-855f-7aada9950a8d", "aa\0a\0", 5, "aa", "a"); - check_uuid_v3("8c573b48-0f01-30ba-bb94-c5f59f4fe517", "\0aa\0", 4, "", "aa"); - check_uuid_v3("2bdd3d46-eb83-3c53-a41b-a724d04b5544", "a\0aa\0", 5, "a", "aa"); - check_uuid_v3("13d4b780-07c1-3ba7-b449-81c4844ef039", "aa\0aa\0", 6, "aa", "aa"); - check_uuid_v3("dd265bf7-c05a-3037-9939-b9629858a477", "a\0b\0", 4, "a", "b"); + check_uuid_v3("b07c334a-399b-32de-8d50-58e4e08f98e3", "", NULL); + check_uuid_v3("b8a426cb-bcb5-30a3-bd8f-6786fea72df9", "\0", ""); + check_uuid_v3("12a4a982-7aae-39e1-951e-41aeb1250959", "a\0", "a"); + check_uuid_v3("69e22c7e-f89f-3a43-b239-1cb52ed8db69", "aa\0", "aa"); + check_uuid_v3("59829fd3-5ad5-3d90-a7b0-4911747e4088", "\0\0", "", ""); + check_uuid_v3("01ad0e06-6c50-3384-8d86-ddab81421425", "a\0\0", "a", ""); + check_uuid_v3("e1ed8647-9ed3-3ec8-8c6d-e8204524d71d", "aa\0\0", "aa", ""); + check_uuid_v3("fb1c7cd6-275c-3489-9382-83b900da8af0", "\0a\0", "", "a"); + check_uuid_v3("5d79494e-c4ba-31a6-80a2-d6016ccd7e17", "a\0a\0", "a", "a"); + check_uuid_v3("fd698d86-1b60-3ebe-855f-7aada9950a8d", "aa\0a\0", "aa", "a"); + check_uuid_v3("8c573b48-0f01-30ba-bb94-c5f59f4fe517", "\0aa\0", "", "aa"); + check_uuid_v3("2bdd3d46-eb83-3c53-a41b-a724d04b5544", "a\0aa\0", "a", "aa"); + check_uuid_v3("13d4b780-07c1-3ba7-b449-81c4844ef039", "aa\0aa\0", "aa", "aa"); + check_uuid_v3("dd265bf7-c05a-3037-9939-b9629858a477", "a\0b\0", "a", "b"); } static void From 168bc7f120711780049e8005fb168e69d5631570 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 28 Sep 2022 10:50:10 +0200 Subject: [PATCH 4/9] glib: add nm_uuid_generate_from_strings() helper nm_uuid_generate_from_strings() accepts a uuid_type and type_arg parameter, so that we can use it to generate version 5 UUIDs. This is a more flexible variant of nm_uuid_generate_from_strings_v3(), which will be used to replace it. With the right parameters, the new function behaves the same as nm_uuid_generate_from_strings_v3(). --- src/libnm-core-impl/tests/test-general.c | 203 +++++++++++++++++++++++ src/libnm-glib-aux/nm-uuid.c | 50 ++++++ src/libnm-glib-aux/nm-uuid.h | 7 + 3 files changed, 260 insertions(+) diff --git a/src/libnm-core-impl/tests/test-general.c b/src/libnm-core-impl/tests/test-general.c index d214db5616..46f2df36da 100644 --- a/src/libnm-core-impl/tests/test-general.c +++ b/src/libnm-core-impl/tests/test-general.c @@ -7981,6 +7981,72 @@ _check_uuid_v3(const char *expected_uuid, const char *str, gssize slen, char *uu NM_STRLEN(str), \ nm_uuid_generate_from_strings_v3(__VA_ARGS__, NULL)) +static void +_check_uuid(NMUuidType uuid_type, + const NMUuid *type_arg, + const char *expected_uuid, + const char *str, + gssize slen, + char *uuid_test, + char *uuid_test_v3) +{ + g_assert(uuid_test); + g_assert(nm_uuid_is_normalized(uuid_test)); + g_assert(str); + + if (!nm_streq(uuid_test, expected_uuid)) { + g_error("UUID test failed (1): text=%s, len=%lld, expected=%s, uuid_test=%s", + str, + (long long) slen, + expected_uuid, + uuid_test); + } + g_free(uuid_test); + + uuid_test = nm_uuid_generate_from_string_str(str, slen, uuid_type, type_arg); + + g_assert(uuid_test); + g_assert(nm_utils_is_uuid(uuid_test)); + + if (strcmp(uuid_test, expected_uuid)) { + g_error("UUID test failed (2): text=%s; len=%lld, expected=%s, uuid2=%s", + str, + (long long) slen, + expected_uuid, + uuid_test); + } + g_free(uuid_test); + + if (!uuid_test_v3) { + /* The special case of NULL argument. This cannot be represented by + * nm_uuid_generate_from_strings_v3(). */ + g_assert_cmpmem(str, slen, "x", 1); + } else if (uuid_type == NM_UUID_TYPE_VERSION3 && type_arg == &nm_uuid_ns_1) + g_assert_cmpstr(expected_uuid, ==, uuid_test_v3); + else + g_assert_cmpstr(expected_uuid, !=, uuid_test_v3); + + g_free(uuid_test_v3); +} + +#define check_uuid(uuid_type, type_arg, expected_uuid, str, ...) \ + ({ \ + const NMUuidType _uuid_type = (uuid_type); \ + const NMUuid *_type_arg = type_arg; \ + const char *_expected_uuid = (expected_uuid); \ + const char *_str = (str); \ + const gsize _strlen = NM_STRLEN(str); \ + \ + _check_uuid( \ + _uuid_type, \ + _type_arg, \ + _expected_uuid, \ + _str, \ + _strlen, \ + nm_uuid_generate_from_strings_strv(_uuid_type, _type_arg, NM_MAKE_STRV(__VA_ARGS__)), \ + nm_uuid_generate_from_strings_v3(__VA_ARGS__, NULL)); \ + }) + static void test_nm_utils_uuid_generate_from_strings(void) { @@ -8015,6 +8081,143 @@ test_nm_utils_uuid_generate_from_strings(void) check_uuid_v3("2bdd3d46-eb83-3c53-a41b-a724d04b5544", "a\0aa\0", "a", "aa"); check_uuid_v3("13d4b780-07c1-3ba7-b449-81c4844ef039", "aa\0aa\0", "aa", "aa"); check_uuid_v3("dd265bf7-c05a-3037-9939-b9629858a477", "a\0b\0", "a", "b"); + + _check_uuid(NM_UUID_TYPE_VERSION3, + &nm_uuid_ns_1, + "457229f4-fe49-32f5-8b09-c531d81f44d9", + "x", + 1, + nm_uuid_generate_from_strings_strv(NM_UUID_TYPE_VERSION3, &nm_uuid_ns_1, NULL), + NULL); + check_uuid(NM_UUID_TYPE_VERSION3, + &nm_uuid_ns_1, + "b07c334a-399b-32de-8d50-58e4e08f98e3", + "", + NULL); + check_uuid(NM_UUID_TYPE_VERSION3, + &nm_uuid_ns_1, + "b8a426cb-bcb5-30a3-bd8f-6786fea72df9", + "\0", + ""); + check_uuid(NM_UUID_TYPE_VERSION3, + &nm_uuid_ns_1, + "12a4a982-7aae-39e1-951e-41aeb1250959", + "a\0", + "a"); + check_uuid(NM_UUID_TYPE_VERSION3, + &nm_uuid_ns_1, + "69e22c7e-f89f-3a43-b239-1cb52ed8db69", + "aa\0", + "aa"); + check_uuid(NM_UUID_TYPE_VERSION3, + &nm_uuid_ns_1, + "59829fd3-5ad5-3d90-a7b0-4911747e4088", + "\0\0", + "", + ""); + check_uuid(NM_UUID_TYPE_VERSION3, + &nm_uuid_ns_1, + "01ad0e06-6c50-3384-8d86-ddab81421425", + "a\0\0", + "a", + ""); + check_uuid(NM_UUID_TYPE_VERSION3, + &nm_uuid_ns_1, + "e1ed8647-9ed3-3ec8-8c6d-e8204524d71d", + "aa\0\0", + "aa", + ""); + check_uuid(NM_UUID_TYPE_VERSION3, + &nm_uuid_ns_1, + "fb1c7cd6-275c-3489-9382-83b900da8af0", + "\0a\0", + "", + "a"); + check_uuid(NM_UUID_TYPE_VERSION3, + &nm_uuid_ns_1, + "5d79494e-c4ba-31a6-80a2-d6016ccd7e17", + "a\0a\0", + "a", + "a"); + check_uuid(NM_UUID_TYPE_VERSION3, + &nm_uuid_ns_1, + "fd698d86-1b60-3ebe-855f-7aada9950a8d", + "aa\0a\0", + "aa", + "a"); + check_uuid(NM_UUID_TYPE_VERSION3, + &nm_uuid_ns_1, + "8c573b48-0f01-30ba-bb94-c5f59f4fe517", + "\0aa\0", + "", + "aa"); + check_uuid(NM_UUID_TYPE_VERSION3, + &nm_uuid_ns_1, + "2bdd3d46-eb83-3c53-a41b-a724d04b5544", + "a\0aa\0", + "a", + "aa"); + check_uuid(NM_UUID_TYPE_VERSION3, + &nm_uuid_ns_1, + "13d4b780-07c1-3ba7-b449-81c4844ef039", + "aa\0aa\0", + "aa", + "aa"); + check_uuid(NM_UUID_TYPE_VERSION3, + &nm_uuid_ns_1, + "dd265bf7-c05a-3037-9939-b9629858a477", + "a\0b\0", + "a", + "b"); + + check_uuid(NM_UUID_TYPE_VERSION5, + _uuid(NM_UUID_NS_URL), + "dd247a64-df22-5d30-8087-0bd709f6941a", + "a\0b\0", + "a", + "b"); + check_uuid(NM_UUID_TYPE_VERSION5, + _uuid(NM_UUID_NS_URL), + "cbb93d73-085d-5072-94cd-a394b8149993", + "\0b\0", + "", + "b"); + check_uuid(NM_UUID_TYPE_VERSION3, + _uuid(NM_UUID_NS_URL), + "916dcdd8-5042-3b9b-9763-4312a31e5735", + "aa\0a\0", + "aa", + "a"); + check_uuid(NM_UUID_TYPE_VERSION3, + NULL, + "1700bb72-7116-3d1f-8cd2-6d074a40a3a9", + "aa\0a\0", + "aa", + "a"); + check_uuid(NM_UUID_TYPE_VERSION3, + &nm_uuid_ns_zero, + "1700bb72-7116-3d1f-8cd2-6d074a40a3a9", + "aa\0a\0", + "aa", + "a"); + check_uuid(NM_UUID_TYPE_VERSION5, + NULL, + "03c5de66-28ad-5a2e-8ed3-e256f3218900", + "aa\0a\0", + "aa", + "a"); + check_uuid(NM_UUID_TYPE_VERSION5, + &nm_uuid_ns_zero, + "03c5de66-28ad-5a2e-8ed3-e256f3218900", + "aa\0a\0", + "aa", + "a"); + check_uuid(NM_UUID_TYPE_LEGACY, + NULL, + "c38f63cf-1e50-ad7f-ae26-50f85cc5da47", + "aa\0a\0", + "aa", + "a"); } static void diff --git a/src/libnm-glib-aux/nm-uuid.c b/src/libnm-glib-aux/nm-uuid.c index 9a75d1c7af..979f91ea9f 100644 --- a/src/libnm-glib-aux/nm-uuid.c +++ b/src/libnm-glib-aux/nm-uuid.c @@ -445,3 +445,53 @@ nm_uuid_generate_from_strings_v3(const char *string1, ...) &nm_uuid_ns_1); } } + +/** + * nm_uuid_generate_from_strings_strv: + * @uuid_type: the UUID type to use. Prefer version 5 unless you have + * good reasons. + * @type_args: the namespace UUID. + * @strv: (allow-none): the strv list to hash. Can be NULL, in which + * case the result is different from an empty array. + * + * Returns a @uuid_type UUID based on the concatenated C strings. + * It does not simply concatenate them, but also includes the + * terminating '\0' character. For example "a", "b", gives + * "a\0b\0". + * This has the advantage, that the following invocations + * all give different UUIDs: (NULL), (""), ("",""), ("","a"), ("a",""), + * ("aa"), ("aa", ""), ("", "aa"), ... + */ +char * +nm_uuid_generate_from_strings_strv(NMUuidType uuid_type, + const NMUuid *type_args, + const char *const *strv) +{ + nm_auto_str_buf NMStrBuf str = NM_STR_BUF_INIT_A(NM_UTILS_GET_NEXT_REALLOC_SIZE_232, FALSE); + gsize slen; + const char *s; + + if (!strv) { + /* NULL is treated differently from an empty strv. We achieve that + * by using a non-empty, non-NUL terminated string (which cannot happen + * in the other cases). */ + slen = 1; + s = "x"; + } else if (!strv[0]) { + slen = 0; + s = ""; + } else if (!strv[1]) { + slen = strlen(strv[0]) + 1u; + s = strv[0]; + } else { + /* We concatenate the NUL termiated string, including the NUL + * character. This way, ("a","a"), ("aa"), ("aa","") all hash + * differently. */ + for (; strv[0]; strv++) + nm_str_buf_append_len(&str, strv[0], strlen(strv[0]) + 1u); + slen = str.len; + s = nm_str_buf_get_str_unsafe(&str); + } + + return nm_uuid_generate_from_string_str(s, slen, uuid_type, type_args); +} diff --git a/src/libnm-glib-aux/nm-uuid.h b/src/libnm-glib-aux/nm-uuid.h index 5448191c03..d287ea53de 100644 --- a/src/libnm-glib-aux/nm-uuid.h +++ b/src/libnm-glib-aux/nm-uuid.h @@ -123,6 +123,13 @@ char *nm_uuid_generate_from_string_str(const char *s, NMUuidType uuid_type, const NMUuid *type_args); +char *nm_uuid_generate_from_strings_strv(NMUuidType uuid_type, + const NMUuid *type_args, + const char *const *strv); + +#define nm_uuid_generate_from_strings(uuid_type, type_args, ...) \ + nm_uuid_generate_from_strings_strv((uuid_type), (type_args), NM_MAKE_STRV(__VA_ARGS__)) + char *nm_uuid_generate_from_strings_v3(const char *string1, ...) G_GNUC_NULL_TERMINATED; /*****************************************************************************/ From f849426b84c196d71f6d6258336b3edfae3696da Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 28 Sep 2022 12:09:51 +0200 Subject: [PATCH 5/9] glib-aux: avoid leaking secrets in memory during nm_uuid_generate_from_strings_strv() Some snake oil, but this is a low level function and we don't know whether the caller doesn't try to hash secret information. Just clear the buffer after use. --- src/libnm-glib-aux/nm-uuid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libnm-glib-aux/nm-uuid.c b/src/libnm-glib-aux/nm-uuid.c index 979f91ea9f..d7ba706e2f 100644 --- a/src/libnm-glib-aux/nm-uuid.c +++ b/src/libnm-glib-aux/nm-uuid.c @@ -467,7 +467,7 @@ nm_uuid_generate_from_strings_strv(NMUuidType uuid_type, const NMUuid *type_args, const char *const *strv) { - nm_auto_str_buf NMStrBuf str = NM_STR_BUF_INIT_A(NM_UTILS_GET_NEXT_REALLOC_SIZE_232, FALSE); + nm_auto_str_buf NMStrBuf str = NM_STR_BUF_INIT_A(NM_UTILS_GET_NEXT_REALLOC_SIZE_232, TRUE); gsize slen; const char *s; From 871c82fd5f6e7376f9f1a0f331d1e68803c51c0c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 28 Sep 2022 12:08:16 +0200 Subject: [PATCH 6/9] glib-aux: implement nm_uuid_generate_from_strings_legacy() in terms of nm_uuid_generate_from_strings() As the unit tests show, the behavior is the same. --- src/libnm-glib-aux/nm-uuid.c | 41 ------------------------------------ src/libnm-glib-aux/nm-uuid.h | 3 ++- 2 files changed, 2 insertions(+), 42 deletions(-) diff --git a/src/libnm-glib-aux/nm-uuid.c b/src/libnm-glib-aux/nm-uuid.c index d7ba706e2f..5b7edd74e2 100644 --- a/src/libnm-glib-aux/nm-uuid.c +++ b/src/libnm-glib-aux/nm-uuid.c @@ -405,47 +405,6 @@ nm_uuid_generate_from_string_str(const char *s, return nm_uuid_unparse(&uuid, g_new(char, 37)); } -/** - * nm_uuid_generate_from_strings_v3: - * @string1: a variadic list of strings. Must be NULL terminated. - * - * Returns a variant3 UUID based on the concatenated C strings. - * It does not simply concatenate them, but also includes the - * terminating '\0' character. For example "a", "b", gives - * "a\0b\0". - * - * This has the advantage, that the following invocations - * all give different UUIDs: (NULL), (""), ("",""), ("","a"), ("a",""), - * ("aa"), ("aa", ""), ("", "aa"), ... - */ -char * -nm_uuid_generate_from_strings_v3(const char *string1, ...) -{ - if (!string1) - return nm_uuid_generate_from_string_str(NULL, 0, NM_UUID_TYPE_VERSION3, &nm_uuid_ns_1); - - { - nm_auto_str_buf NMStrBuf str = NM_STR_BUF_INIT_A(NM_UTILS_GET_NEXT_REALLOC_SIZE_232, FALSE); - va_list args; - const char *s; - - nm_str_buf_append_len(&str, string1, strlen(string1) + 1u); - - va_start(args, string1); - s = va_arg(args, const char *); - while (s) { - nm_str_buf_append_len(&str, s, strlen(s) + 1u); - s = va_arg(args, const char *); - } - va_end(args); - - return nm_uuid_generate_from_string_str(nm_str_buf_get_str_unsafe(&str), - str.len, - NM_UUID_TYPE_VERSION3, - &nm_uuid_ns_1); - } -} - /** * nm_uuid_generate_from_strings_strv: * @uuid_type: the UUID type to use. Prefer version 5 unless you have diff --git a/src/libnm-glib-aux/nm-uuid.h b/src/libnm-glib-aux/nm-uuid.h index d287ea53de..19430c99de 100644 --- a/src/libnm-glib-aux/nm-uuid.h +++ b/src/libnm-glib-aux/nm-uuid.h @@ -130,7 +130,8 @@ char *nm_uuid_generate_from_strings_strv(NMUuidType uuid_type, #define nm_uuid_generate_from_strings(uuid_type, type_args, ...) \ nm_uuid_generate_from_strings_strv((uuid_type), (type_args), NM_MAKE_STRV(__VA_ARGS__)) -char *nm_uuid_generate_from_strings_v3(const char *string1, ...) G_GNUC_NULL_TERMINATED; +#define nm_uuid_generate_from_strings_v3(...) \ + nm_uuid_generate_from_strings(NM_UUID_TYPE_VERSION3, &nm_uuid_ns_1, __VA_ARGS__) /*****************************************************************************/ From d527181e1f559837068071aa70adfa4308cd5cc3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 28 Sep 2022 12:30:12 +0200 Subject: [PATCH 7/9] libnm-core/tests: drop duplicate tests _check_uuid_v3() As the unit test shows, the behavior is the same. --- src/libnm-core-impl/tests/test-general.c | 39 ++---------------------- 1 file changed, 3 insertions(+), 36 deletions(-) diff --git a/src/libnm-core-impl/tests/test-general.c b/src/libnm-core-impl/tests/test-general.c index 46f2df36da..f29fa39927 100644 --- a/src/libnm-core-impl/tests/test-general.c +++ b/src/libnm-core-impl/tests/test-general.c @@ -7945,42 +7945,6 @@ test_nm_utils_uuid_generate_from_string(void) /*****************************************************************************/ -static void -_check_uuid_v3(const char *expected_uuid, const char *str, gssize slen, char *uuid_test) -{ - g_assert(uuid_test); - g_assert(nm_uuid_is_normalized(uuid_test)); - - if (strcmp(uuid_test, expected_uuid)) { - g_error("UUID test failed (1): text=%s, len=%lld, expected=%s, uuid_test=%s", - str, - (long long) slen, - expected_uuid, - uuid_test); - } - g_free(uuid_test); - - uuid_test = nm_uuid_generate_from_string_str(str, slen, NM_UUID_TYPE_VERSION3, &nm_uuid_ns_1); - - g_assert(uuid_test); - g_assert(nm_utils_is_uuid(uuid_test)); - - if (strcmp(uuid_test, expected_uuid)) { - g_error("UUID test failed (2): text=%s; len=%lld, expected=%s, uuid2=%s", - str, - (long long) slen, - expected_uuid, - uuid_test); - } - g_free(uuid_test); -} - -#define check_uuid_v3(expected_uuid, str, ...) \ - _check_uuid_v3(expected_uuid, \ - str, \ - NM_STRLEN(str), \ - nm_uuid_generate_from_strings_v3(__VA_ARGS__, NULL)) - static void _check_uuid(NMUuidType uuid_type, const NMUuid *type_arg, @@ -8047,6 +8011,9 @@ _check_uuid(NMUuidType uuid_type, nm_uuid_generate_from_strings_v3(__VA_ARGS__, NULL)); \ }) +#define check_uuid_v3(expected_uuid, str, ...) \ + check_uuid(NM_UUID_TYPE_VERSION3, &nm_uuid_ns_1, expected_uuid, str, __VA_ARGS__) + static void test_nm_utils_uuid_generate_from_strings(void) { From 7e33ef916a07445c41756d6ede4933e8e0d0d094 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 28 Sep 2022 12:30:12 +0200 Subject: [PATCH 8/9] libnm-core/tests: drop duplicate tests _check_uuid_v3() (2) The previous commits show that the behavior is the same. We can not drop these checks. --- src/libnm-core-impl/tests/test-general.c | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/libnm-core-impl/tests/test-general.c b/src/libnm-core-impl/tests/test-general.c index f29fa39927..1de7c75f1e 100644 --- a/src/libnm-core-impl/tests/test-general.c +++ b/src/libnm-core-impl/tests/test-general.c @@ -8011,9 +8011,6 @@ _check_uuid(NMUuidType uuid_type, nm_uuid_generate_from_strings_v3(__VA_ARGS__, NULL)); \ }) -#define check_uuid_v3(expected_uuid, str, ...) \ - check_uuid(NM_UUID_TYPE_VERSION3, &nm_uuid_ns_1, expected_uuid, str, __VA_ARGS__) - static void test_nm_utils_uuid_generate_from_strings(void) { @@ -8034,21 +8031,6 @@ test_nm_utils_uuid_generate_from_strings(void) g_assert_cmpstr(NM_UUID_NS_1, ==, nm_uuid_unparse(&nm_uuid_ns_1, buf)); g_assert_cmpstr(NM_UUID_NS_ZERO, ==, nm_uuid_unparse(&nm_uuid_ns_zero, buf)); - check_uuid_v3("b07c334a-399b-32de-8d50-58e4e08f98e3", "", NULL); - check_uuid_v3("b8a426cb-bcb5-30a3-bd8f-6786fea72df9", "\0", ""); - check_uuid_v3("12a4a982-7aae-39e1-951e-41aeb1250959", "a\0", "a"); - check_uuid_v3("69e22c7e-f89f-3a43-b239-1cb52ed8db69", "aa\0", "aa"); - check_uuid_v3("59829fd3-5ad5-3d90-a7b0-4911747e4088", "\0\0", "", ""); - check_uuid_v3("01ad0e06-6c50-3384-8d86-ddab81421425", "a\0\0", "a", ""); - check_uuid_v3("e1ed8647-9ed3-3ec8-8c6d-e8204524d71d", "aa\0\0", "aa", ""); - check_uuid_v3("fb1c7cd6-275c-3489-9382-83b900da8af0", "\0a\0", "", "a"); - check_uuid_v3("5d79494e-c4ba-31a6-80a2-d6016ccd7e17", "a\0a\0", "a", "a"); - check_uuid_v3("fd698d86-1b60-3ebe-855f-7aada9950a8d", "aa\0a\0", "aa", "a"); - check_uuid_v3("8c573b48-0f01-30ba-bb94-c5f59f4fe517", "\0aa\0", "", "aa"); - check_uuid_v3("2bdd3d46-eb83-3c53-a41b-a724d04b5544", "a\0aa\0", "a", "aa"); - check_uuid_v3("13d4b780-07c1-3ba7-b449-81c4844ef039", "aa\0aa\0", "aa", "aa"); - check_uuid_v3("dd265bf7-c05a-3037-9939-b9629858a477", "a\0b\0", "a", "b"); - _check_uuid(NM_UUID_TYPE_VERSION3, &nm_uuid_ns_1, "457229f4-fe49-32f5-8b09-c531d81f44d9", From e9a33bbbf87d4f01b883949bf5e2434117b0ca73 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 28 Sep 2022 12:37:34 +0200 Subject: [PATCH 9/9] all: drop nm_uuid_generate_from_strings_v3() For new uses of nm_uuid_generate_from_strings() we should generate version5 UUIDs and we should use unique namespace UUID arguments. The namespace UUID was so far replaced by always passing a special prefix as first string. It seems nicer to use a namespace instead. Version3 UUIDs should not be used for new applications. Hence, nm_uuid_generate_from_strings_v3() is no longer a desirable way to generate UUIDs, so drop the wrapper. --- src/core/devices/nm-device-ethernet.c | 11 +++-- .../keyfile/tests/test-keyfile-settings.c | 3 +- src/libnm-core-impl/nm-keyfile.c | 5 +- src/libnm-core-impl/tests/test-general.c | 48 +++++++------------ src/libnm-glib-aux/nm-uuid.c | 3 +- src/libnm-glib-aux/nm-uuid.h | 3 -- src/nm-initrd-generator/nmi-ibft-reader.c | 15 +++--- 7 files changed, 39 insertions(+), 49 deletions(-) diff --git a/src/core/devices/nm-device-ethernet.c b/src/core/devices/nm-device-ethernet.c index 6cd5e32292..dff6466a2e 100644 --- a/src/core/devices/nm-device-ethernet.c +++ b/src/core/devices/nm-device-ethernet.c @@ -1725,11 +1725,12 @@ new_default_connection(NMDevice *self) /* Create a stable UUID. The UUID is also the Network_ID for stable-privacy addr-gen-mode, * thus when it changes we will also generate different IPv6 addresses. */ - uuid = nm_uuid_generate_from_strings_v3("default-wired", - nm_utils_machine_id_str(), - defname, - perm_hw_addr ?: iface, - NULL); + uuid = nm_uuid_generate_from_strings(NM_UUID_TYPE_VERSION3, + &nm_uuid_ns_1, + "default-wired", + nm_utils_machine_id_str(), + defname, + perm_hw_addr ?: iface); g_object_set(setting, NM_SETTING_CONNECTION_ID, diff --git a/src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c b/src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c index eae94920b6..eec529ce6c 100644 --- a/src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c +++ b/src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c @@ -2296,7 +2296,8 @@ test_read_missing_id_uuid(void) gs_free char *expected_uuid = NULL; const char *FILENAME = TEST_KEYFILES_DIR "/Test_Missing_ID_UUID"; - expected_uuid = nm_uuid_generate_from_strings_v3("keyfile", FILENAME, NULL); + expected_uuid = + nm_uuid_generate_from_strings(NM_UUID_TYPE_VERSION3, &nm_uuid_ns_1, "keyfile", FILENAME); connection = keyfile_read_connection_from_file(FILENAME); diff --git a/src/libnm-core-impl/nm-keyfile.c b/src/libnm-core-impl/nm-keyfile.c index fdd3341fba..d8dd27821f 100644 --- a/src/libnm-core-impl/nm-keyfile.c +++ b/src/libnm-core-impl/nm-keyfile.c @@ -3800,7 +3800,10 @@ nm_keyfile_read_ensure_uuid(NMConnection *connection, const char *fallback_uuid_ if (nm_setting_connection_get_uuid(s_con)) return FALSE; - hashed_uuid = nm_uuid_generate_from_strings_v3("keyfile", fallback_uuid_seed, NULL); + hashed_uuid = nm_uuid_generate_from_strings(NM_UUID_TYPE_VERSION3, + &nm_uuid_ns_1, + "keyfile", + fallback_uuid_seed); g_object_set(s_con, NM_SETTING_CONNECTION_UUID, hashed_uuid, NULL); return TRUE; } diff --git a/src/libnm-core-impl/tests/test-general.c b/src/libnm-core-impl/tests/test-general.c index 1de7c75f1e..d66b820d7f 100644 --- a/src/libnm-core-impl/tests/test-general.c +++ b/src/libnm-core-impl/tests/test-general.c @@ -7951,8 +7951,7 @@ _check_uuid(NMUuidType uuid_type, const char *expected_uuid, const char *str, gssize slen, - char *uuid_test, - char *uuid_test_v3) + char *uuid_test) { g_assert(uuid_test); g_assert(nm_uuid_is_normalized(uuid_test)); @@ -7980,35 +7979,23 @@ _check_uuid(NMUuidType uuid_type, uuid_test); } g_free(uuid_test); - - if (!uuid_test_v3) { - /* The special case of NULL argument. This cannot be represented by - * nm_uuid_generate_from_strings_v3(). */ - g_assert_cmpmem(str, slen, "x", 1); - } else if (uuid_type == NM_UUID_TYPE_VERSION3 && type_arg == &nm_uuid_ns_1) - g_assert_cmpstr(expected_uuid, ==, uuid_test_v3); - else - g_assert_cmpstr(expected_uuid, !=, uuid_test_v3); - - g_free(uuid_test_v3); } -#define check_uuid(uuid_type, type_arg, expected_uuid, str, ...) \ - ({ \ - const NMUuidType _uuid_type = (uuid_type); \ - const NMUuid *_type_arg = type_arg; \ - const char *_expected_uuid = (expected_uuid); \ - const char *_str = (str); \ - const gsize _strlen = NM_STRLEN(str); \ - \ - _check_uuid( \ - _uuid_type, \ - _type_arg, \ - _expected_uuid, \ - _str, \ - _strlen, \ - nm_uuid_generate_from_strings_strv(_uuid_type, _type_arg, NM_MAKE_STRV(__VA_ARGS__)), \ - nm_uuid_generate_from_strings_v3(__VA_ARGS__, NULL)); \ +#define check_uuid(uuid_type, type_arg, expected_uuid, str, ...) \ + ({ \ + const NMUuidType _uuid_type = (uuid_type); \ + const NMUuid *_type_arg = type_arg; \ + const char *_expected_uuid = (expected_uuid); \ + const char *_str = (str); \ + const gsize _strlen = NM_STRLEN(str); \ + \ + _check_uuid( \ + _uuid_type, \ + _type_arg, \ + _expected_uuid, \ + _str, \ + _strlen, \ + nm_uuid_generate_from_strings_strv(_uuid_type, _type_arg, NM_MAKE_STRV(__VA_ARGS__))); \ }) static void @@ -8036,8 +8023,7 @@ test_nm_utils_uuid_generate_from_strings(void) "457229f4-fe49-32f5-8b09-c531d81f44d9", "x", 1, - nm_uuid_generate_from_strings_strv(NM_UUID_TYPE_VERSION3, &nm_uuid_ns_1, NULL), - NULL); + nm_uuid_generate_from_strings_strv(NM_UUID_TYPE_VERSION3, &nm_uuid_ns_1, NULL)); check_uuid(NM_UUID_TYPE_VERSION3, &nm_uuid_ns_1, "b07c334a-399b-32de-8d50-58e4e08f98e3", diff --git a/src/libnm-glib-aux/nm-uuid.c b/src/libnm-glib-aux/nm-uuid.c index 5b7edd74e2..ae0f7233e7 100644 --- a/src/libnm-glib-aux/nm-uuid.c +++ b/src/libnm-glib-aux/nm-uuid.c @@ -12,7 +12,8 @@ const NMUuid nm_uuid_ns_zero = NM_UUID_INIT(00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00); -/* arbitrarily chosen namespace UUID for nm_uuid_generate_from_strings_v3() */ +/* arbitrarily chosen namespace UUID for some uses of nm_uuid_generate_from_strings(). + * Try not to re-use this namespace, instead, generate a unique one. */ const NMUuid nm_uuid_ns_1 = NM_UUID_INIT(b4, 25, e9, fb, 75, 98, 44, b4, 9e, 3b, 5a, 2e, 3a, aa, 49, 05); diff --git a/src/libnm-glib-aux/nm-uuid.h b/src/libnm-glib-aux/nm-uuid.h index 19430c99de..770d7af1ae 100644 --- a/src/libnm-glib-aux/nm-uuid.h +++ b/src/libnm-glib-aux/nm-uuid.h @@ -130,9 +130,6 @@ char *nm_uuid_generate_from_strings_strv(NMUuidType uuid_type, #define nm_uuid_generate_from_strings(uuid_type, type_args, ...) \ nm_uuid_generate_from_strings_strv((uuid_type), (type_args), NM_MAKE_STRV(__VA_ARGS__)) -#define nm_uuid_generate_from_strings_v3(...) \ - nm_uuid_generate_from_strings(NM_UUID_TYPE_VERSION3, &nm_uuid_ns_1, __VA_ARGS__) - /*****************************************************************************/ #endif /* __NM_UUID_H__ */ diff --git a/src/nm-initrd-generator/nmi-ibft-reader.c b/src/nm-initrd-generator/nmi-ibft-reader.c index 66472f784b..c0915a8f01 100644 --- a/src/nm-initrd-generator/nmi-ibft-reader.c +++ b/src/nm-initrd-generator/nmi-ibft-reader.c @@ -307,13 +307,14 @@ connection_setting_add(GHashTable *nic, s_index ? " " : "", s_index ? s_index : ""); - uuid = nm_uuid_generate_from_strings_v3("ibft", - s_hwaddr, - s_vlanid ? "V" : "v", - s_vlanid ? s_vlanid : "", - s_ipaddr ? "A" : "DHCP", - s_ipaddr ? s_ipaddr : "", - NULL); + uuid = nm_uuid_generate_from_strings(NM_UUID_TYPE_VERSION3, + &nm_uuid_ns_1, + "ibft", + s_hwaddr, + s_vlanid ? "V" : "v", + s_vlanid ? s_vlanid : "", + s_ipaddr ? "A" : "DHCP", + s_ipaddr ? s_ipaddr : ""); s_con = (NMSetting *) nm_connection_get_setting_connection(connection); if (!s_con) {