[PATCH] nss: Compare hostname case insensitive

Michal Privoznik posted 1 patch 1 year, 11 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/a6418c0cdd27cdc2bd8b57fd8f8c98087b9292a9.1653642406.git.mprivozn@redhat.com
build-aux/syntax-check.mk      | 2 +-
tests/nsstest.c                | 1 +
tools/nss/libvirt_nss_leases.c | 2 +-
tools/nss/libvirt_nss_macs.c   | 2 +-
4 files changed, 4 insertions(+), 3 deletions(-)
[PATCH] nss: Compare hostname case insensitive
Posted by Michal Privoznik 1 year, 11 months ago
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>
---
 build-aux/syntax-check.mk      | 2 +-
 tests/nsstest.c                | 1 +
 tools/nss/libvirt_nss_leases.c | 2 +-
 tools/nss/libvirt_nss_macs.c   | 2 +-
 4 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk
index 73f8a21c1b..f9f60c934c 100644
--- a/build-aux/syntax-check.mk
+++ b/build-aux/syntax-check.mk
@@ -1337,7 +1337,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)
-- 
2.35.1
Re: [PATCH] nss: Compare hostname case insensitive
Posted by Ján Tomko 1 year, 11 months ago
On a Friday in 2022, Michal Privoznik wrote:
>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>
>---
> build-aux/syntax-check.mk      | 2 +-
> tests/nsstest.c                | 1 +
> tools/nss/libvirt_nss_leases.c | 2 +-
> tools/nss/libvirt_nss_macs.c   | 2 +-
> 4 files changed, 4 insertions(+), 3 deletions(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano
Re: [PATCH] nss: Compare hostname case insensitive
Posted by Martin Kletzander 1 year, 11 months ago
On Fri, May 27, 2022 at 11:06:46AM +0200, Michal Privoznik wrote:
>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>