From e9a33bbbf87d4f01b883949bf5e2434117b0ca73 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 28 Sep 2022 12:37:34 +0200 Subject: 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 ++--- .../plugins/keyfile/tests/test-keyfile-settings.c | 3 +- src/libnm-core-impl/nm-keyfile.c | 5 ++- src/libnm-core-impl/tests/test-general.c | 50 ++++++++-------------- 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, 40 insertions(+), 50 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) { -- cgit v1.2.3