]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
nss: Compare hostname case insensitive
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 27 May 2022 07:00:59 +0000 (09:00 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 27 May 2022 11:43:14 +0000 (13:43 +0200)
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>
build-aux/syntax-check.mk
tests/nsstest.c
tools/nss/libvirt_nss_leases.c
tools/nss/libvirt_nss_macs.c

index 3c196bdf68dd412e2311a4787730cf1ec93a4ccd..e8f9a91ceed59349f80f4a7fb305760655078a94 100644 (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$$
 
index 2c2e57769b1aca0a7c34b9c6e639920cb8df8f90..a03f230452be40dc1a4cd6d731e428297bf59121 100644 (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);
index 536fcf8608113d0b74963b34c10d664527ce8c0e..770dae8625d7c27a8fecc34214662f645d9f6c5c 100644 (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);
index d4b165eef61ae680b940b219611f87cdf8e6c8d0..f45d149793d6a2dd7930ccfd75d2320b50e0e7d7 100644 (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)