From c68da5954d40f636eef5cee6ec21aeb8939cd97b Mon Sep 17 00:00:00 2001 From: Packit Service Date: Dec 23 2020 06:09:30 +0000 Subject: Apply patch 0001-library-use-getaddrinfo-with-AI_CANONNAME-to-find-a-.patch patch_name: 0001-library-use-getaddrinfo-with-AI_CANONNAME-to-find-a-.patch present_in_specfile: true location_in_specfile: 32 --- diff --git a/doc/adcli.xml b/doc/adcli.xml index 97dec08..4722c3a 100644 --- a/doc/adcli.xml +++ b/doc/adcli.xml @@ -228,7 +228,11 @@ Password for Administrator: Override the local machine's fully qualified domain name. If not specified, the local machine's hostname - will be retrieved via gethostname(). + will be retrieved via gethostname(). + If gethostname() only returns a short name + getaddrinfo() with the AI_CANONNAME hint + is called to expand the name to a fully qualified domain + name. diff --git a/library/adconn.c b/library/adconn.c index e2250e3..f6c23d3 100644 --- a/library/adconn.c +++ b/library/adconn.c @@ -86,11 +86,36 @@ struct _adcli_conn_ctx { krb5_keytab keytab; }; +static char *try_to_get_fqdn (const char *host_name) +{ + int ret; + char *fqdn = NULL; + struct addrinfo *res; + struct addrinfo hints; + + memset (&hints, 0, sizeof (struct addrinfo)); + hints.ai_socktype = SOCK_DGRAM; + hints.ai_flags = AI_CANONNAME; + + ret = getaddrinfo (host_name, NULL, &hints, &res); + if (ret != 0) { + _adcli_err ("Failed to find FQDN: %s", gai_strerror (ret)); + return NULL; + } + + fqdn = strdup (res->ai_canonname); + + freeaddrinfo (res); + + return fqdn; +} + static adcli_result ensure_host_fqdn (adcli_result res, adcli_conn *conn) { char hostname[HOST_NAME_MAX + 1]; + char *fqdn = NULL; int ret; if (res != ADCLI_SUCCESS) @@ -107,7 +132,10 @@ ensure_host_fqdn (adcli_result res, return ADCLI_ERR_UNEXPECTED; } - conn->host_fqdn = strdup (hostname); + if (strchr (hostname, '.') == NULL) { + fqdn = try_to_get_fqdn (hostname); + } + conn->host_fqdn = fqdn != NULL ? fqdn : strdup (hostname); return_unexpected_if_fail (conn->host_fqdn != NULL); return ADCLI_SUCCESS; }