Description of problem:
If the libvirt_guest NSS module is configured in /etc/nsswitch.conf to provide hostname -> IP mapping _and_ a VM name is used that is not all lowercase, the mapping will fail when used with e.g. "ssh" because it automatically lowercases hostnames and libvirt_guest maps the original case only.
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. Configure /etc/nsswitch.conf to use "libvirt_guest" for "hosts" lookups
2. Define and start am VM with a uppercase name such as "FooBar" connected to the NATed "default" network
3. Verify VM is running with "virsh -c qemu:///system list"
4. Verify expected lease with "virsh -c qemu:///system net-dhcp-leases default"
5. "ssh -v FooBar"
"ssh -v FooBar" will fail and show that connecting fails because the actual lookup is done on "foobar" for which "getent hosts foobar" does not provide a host -> IP mapping as NSS lookups are case-sensitive.
Either libvirt_guest should also add lower-cased host -> IP mapping so that "getent hosts foobar" and thus "ssh -v FooBar" work _or_ the documentation at https://libvirt.org/nss.html should be updated that libvirt_guest explictly works with all lower-cased VM names only.
Patch posted on the list:
Author: Michal Prívozník <mprivozn>
AuthorDate: Fri May 27 09:00:59 2022 +0200
Commit: Michal Prívozník <mprivozn>
CommitDate: Fri May 27 13:43:14 2022 +0200
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.
Signed-off-by: Michal Privoznik <mprivozn>
Reviewed-by: Martin Kletzander <mkletzan>