From: Michal Privoznik Date: Fri, 27 May 2022 07:00:59 +0000 (+0200) Subject: nss: Compare hostname case insensitive X-Git-Tag: v8.4.0-rc2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7f463b4c0d9c7f07c335b44fc47432414222f209;p=thirdparty%2Flibvirt.git nss: Compare hostname case insensitive There are some tools that convert hostname to lowercase before resolving it (e.g. ssh). In a way it makes sense because DNS is case insensitive and in case of ssh the lowercase version is then used to find matching record in its config file. However, our NSS module performs case sensitive comparison, which makes it useless with ssh. Just consider a machine named FooBar. Therefore, switch to case insensitive string comparison. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1777873 Signed-off-by: Michal Privoznik Reviewed-by: Martin Kletzander --- diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 3c196bdf68..e8f9a91cee 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -1325,7 +1325,7 @@ sc_prohibit_enum_impl_with_vir_prefix_in_virsh: ## Exceptions ## ## ---------- ## -exclude_file_name_regexp--sc_avoid_strcase = ^tools/vsh\.h$$ +exclude_file_name_regexp--sc_avoid_strcase = ^tools/(vsh\.h|nss/libvirt_nss_(leases|macs)\.c)$$ exclude_file_name_regexp--sc_avoid_write = ^src/libvirt-stream\.c$$ diff --git a/tests/nsstest.c b/tests/nsstest.c index 2c2e57769b..a03f230452 100644 --- a/tests/nsstest.c +++ b/tests/nsstest.c @@ -173,6 +173,7 @@ mymain(void) # if !defined(LIBVIRT_NSS_GUEST) DO_TEST("fedora", AF_INET, "192.168.122.197", "192.168.122.198", "192.168.122.199", "192.168.122.3"); DO_TEST("gentoo", AF_INET, "192.168.122.254"); + DO_TEST("Gentoo", AF_INET, "192.168.122.254"); DO_TEST("gentoo", AF_INET6, "2001:1234:dead:beef::2"); DO_TEST("gentoo", AF_UNSPEC, "192.168.122.254"); DO_TEST("non-existent", AF_UNSPEC, NULL); diff --git a/tools/nss/libvirt_nss_leases.c b/tools/nss/libvirt_nss_leases.c index 536fcf8608..770dae8625 100644 --- a/tools/nss/libvirt_nss_leases.c +++ b/tools/nss/libvirt_nss_leases.c @@ -272,7 +272,7 @@ findLeasesParserEndMap(void *ctx) } } else { DEBUG("Check name '%s' vs '%s'", parser->name, NULLSTR(parser->entry.hostname)); - if (parser->entry.hostname && !strcmp(parser->name, parser->entry.hostname)) + if (parser->entry.hostname && !strcasecmp(parser->name, parser->entry.hostname)) found = true; } DEBUG("Found %d", found); diff --git a/tools/nss/libvirt_nss_macs.c b/tools/nss/libvirt_nss_macs.c index d4b165eef6..f45d149793 100644 --- a/tools/nss/libvirt_nss_macs.c +++ b/tools/nss/libvirt_nss_macs.c @@ -142,7 +142,7 @@ findMACsParserEndMap(void *ctx) if (parser->state != FIND_MACS_STATE_ENTRY) return 0; - if (!strcmp(parser->entry.name, parser->name)) { + if (!strcasecmp(parser->entry.name, parser->name)) { char **macs = realloc(*parser->macs, sizeof(char *) * ((*parser->nmacs) + parser->entry.nmacs)); if (!macs)