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 <mprivozn@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Michal Privoznik 2022-05-27 09:00:59 +02:00
parent 76802e5dc6
commit 7f463b4c0d
4 changed files with 4 additions and 3 deletions

View File

@ -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$$

View File

@ -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);

View File

@ -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);

View File

@ -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)