Re: [PATCH 1/7] virutil: Introduce virIsValidHostname

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Apr 19, 2015 at 20:49:06 -0400, John Ferlan wrote:
> Similar to virGetHostname, but this time taking a parameter which is a
> hostname or ipaddress from a <source ... <host name ='%s'.../>... />
> XML property and validating that the name can be resolved.
> 
> Return true or false depending on whether we can ascertain the hostname
> address from calls to 'getnameinfo' and 'getaddrinfo'. Subsequent patches
> will be validating a proposed pool hostname definition against existing
> pool hostnames to ensure they are not the same hostname (and thus having
> two pools looking at the same data)
> 
> Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
> ---
>  src/libvirt_private.syms |  1 +
>  src/util/virutil.c       | 49 ++++++++++++++++++++++++++++++++++++++++++++++++
>  src/util/virutil.h       |  1 +
>  3 files changed, 51 insertions(+)
> 
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index 8c37303..5ba9635 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -2324,6 +2324,7 @@ virIsCapableFCHost;
>  virIsCapableVport;
>  virIsDevMapperDevice;
>  virIsSUID;
> +virIsValidHostname;
>  virManageVport;
>  virMemoryLimitIsSet;
>  virMemoryLimitTruncate;
> diff --git a/src/util/virutil.c b/src/util/virutil.c
> index 79cdb7a..f6cc9af 100644
> --- a/src/util/virutil.c
> +++ b/src/util/virutil.c
> @@ -690,6 +690,55 @@ char *virGetHostname(void)
>  }
>  
>  
> +/*
> + * virIsValidHostname:
> + *
> + * Unlike virGetHostname, this variant of the code receives a hostname
> + * retrieves the getaddrinfo. If the passed hostname can be successfully
> + * and if successfully resolved via getaddrinfo, then success is declared.
> + *
> + * On error in lookup, if an IP Address is not found, or error formatting
> + * the name, an error is generated and a NULL is returned.
> + *
> + * On success, a pointer to a character representation of the numeric IP
> + * Address is returned.
> + *
> + * It is the caller's responsibility to check for a non NULL return and
> + * VIR_FREE the resultant string.

This comment does not describe how this function works.

> + */
> +bool
> +virIsValidHostname(const char *hostname)
> +{
> +    int r;
> +    struct addrinfo hints, *info;
> +
> +    if (STRPREFIX(hostname, "localhost") ||

This certainly is not a good idea:

 $ host localhost.pipo.sk
 localhost.pipo.sk has address 46.255.230.242


> +        STREQ(hostname, "127.0.0.1") || STREQ(hostname, "::1"))
> +        return true;
> +
> +    memset(&hints, 0, sizeof(hints));
> +    hints.ai_family = AF_UNSPEC;
> +    hints.ai_protocol = IPPROTO_TCP;
> +
> +    if ((r = getaddrinfo(hostname, NULL, &hints, &info)) != 0) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR,
> +                       _("IP address lookup for host '%s' failed: %s"),
> +                       hostname, gai_strerror(r));
> +        return false;
> +    }
> +
> +    if (!info) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR,
> +                       _("No IP address for host '%s' found"),
> +                       hostname);
> +        return false;
> +    }
> +    freeaddrinfo(info);
> +
> +    return true;
> +}
> +
> +

Ghm, this seems a bit too excesive IMO, let see how it's used.

Peter

Attachment: signature.asc
Description: Digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]