|
|
48b328 |
From 85b835f8258a57e3b23de47a255dddd822d5bfb3 Mon Sep 17 00:00:00 2001
|
|
|
48b328 |
From: Sumit Bose <sbose@redhat.com>
|
|
|
48b328 |
Date: Fri, 15 Mar 2019 17:33:44 +0100
|
|
|
48b328 |
Subject: [PATCH] library: use getaddrinfo with AI_CANONNAME to find a FQDN
|
|
|
48b328 |
|
|
|
48b328 |
Currently adcli creates service principals only with a short name if the
|
|
|
48b328 |
hostname of the client is a short name. This would fail is
|
|
|
48b328 |
Kerberos/GSSAPI clients will use the fully-qualified domain name (FQDN)
|
|
|
48b328 |
to access the host.
|
|
|
48b328 |
|
|
|
48b328 |
With this patch adcli tries to expand the short name by calling
|
|
|
48b328 |
getaddrinfo with the AI_CANONNAME hint.
|
|
|
48b328 |
|
|
|
48b328 |
Related to https://gitlab.freedesktop.org/realmd/adcli/issues/1
|
|
|
48b328 |
---
|
|
|
48b328 |
doc/adcli.xml | 6 +++++-
|
|
|
48b328 |
library/adconn.c | 30 +++++++++++++++++++++++++++++-
|
|
|
48b328 |
2 files changed, 34 insertions(+), 2 deletions(-)
|
|
|
48b328 |
|
|
|
48b328 |
diff --git a/doc/adcli.xml b/doc/adcli.xml
|
|
|
48b328 |
index 97dec08..4722c3a 100644
|
|
|
48b328 |
--- a/doc/adcli.xml
|
|
|
48b328 |
+++ b/doc/adcli.xml
|
|
|
48b328 |
@@ -228,7 +228,11 @@ Password for Administrator:
|
|
|
48b328 |
<term><option>-H, --host-fqdn=<parameter>host</parameter></option></term>
|
|
|
48b328 |
<listitem><para>Override the local machine's fully qualified
|
|
|
48b328 |
domain name. If not specified, the local machine's hostname
|
|
|
48b328 |
- will be retrieved via <function>gethostname()</function>.</para></listitem>
|
|
|
48b328 |
+ will be retrieved via <function>gethostname()</function>.
|
|
|
48b328 |
+ If <function>gethostname()</function> only returns a short name
|
|
|
48b328 |
+ <function>getaddrinfo()</function> with the AI_CANONNAME hint
|
|
|
48b328 |
+ is called to expand the name to a fully qualified domain
|
|
|
48b328 |
+ name.</para></listitem>
|
|
|
48b328 |
</varlistentry>
|
|
|
48b328 |
<varlistentry>
|
|
|
48b328 |
<term><option>-K, --host-keytab=<parameter>/path/to/keytab</parameter></option></term>
|
|
|
48b328 |
diff --git a/library/adconn.c b/library/adconn.c
|
|
|
48b328 |
index e2250e3..f6c23d3 100644
|
|
|
48b328 |
--- a/library/adconn.c
|
|
|
48b328 |
+++ b/library/adconn.c
|
|
|
48b328 |
@@ -86,11 +86,36 @@ struct _adcli_conn_ctx {
|
|
|
48b328 |
krb5_keytab keytab;
|
|
|
48b328 |
};
|
|
|
48b328 |
|
|
|
48b328 |
+static char *try_to_get_fqdn (const char *host_name)
|
|
|
48b328 |
+{
|
|
|
48b328 |
+ int ret;
|
|
|
48b328 |
+ char *fqdn = NULL;
|
|
|
48b328 |
+ struct addrinfo *res;
|
|
|
48b328 |
+ struct addrinfo hints;
|
|
|
48b328 |
+
|
|
|
48b328 |
+ memset (&hints, 0, sizeof (struct addrinfo));
|
|
|
48b328 |
+ hints.ai_socktype = SOCK_DGRAM;
|
|
|
48b328 |
+ hints.ai_flags = AI_CANONNAME;
|
|
|
48b328 |
+
|
|
|
48b328 |
+ ret = getaddrinfo (host_name, NULL, &hints, &res;;
|
|
|
48b328 |
+ if (ret != 0) {
|
|
|
48b328 |
+ _adcli_err ("Failed to find FQDN: %s", gai_strerror (ret));
|
|
|
48b328 |
+ return NULL;
|
|
|
48b328 |
+ }
|
|
|
48b328 |
+
|
|
|
48b328 |
+ fqdn = strdup (res->ai_canonname);
|
|
|
48b328 |
+
|
|
|
48b328 |
+ freeaddrinfo (res);
|
|
|
48b328 |
+
|
|
|
48b328 |
+ return fqdn;
|
|
|
48b328 |
+}
|
|
|
48b328 |
+
|
|
|
48b328 |
static adcli_result
|
|
|
48b328 |
ensure_host_fqdn (adcli_result res,
|
|
|
48b328 |
adcli_conn *conn)
|
|
|
48b328 |
{
|
|
|
48b328 |
char hostname[HOST_NAME_MAX + 1];
|
|
|
48b328 |
+ char *fqdn = NULL;
|
|
|
48b328 |
int ret;
|
|
|
48b328 |
|
|
|
48b328 |
if (res != ADCLI_SUCCESS)
|
|
|
48b328 |
@@ -107,7 +132,10 @@ ensure_host_fqdn (adcli_result res,
|
|
|
48b328 |
return ADCLI_ERR_UNEXPECTED;
|
|
|
48b328 |
}
|
|
|
48b328 |
|
|
|
48b328 |
- conn->host_fqdn = strdup (hostname);
|
|
|
48b328 |
+ if (strchr (hostname, '.') == NULL) {
|
|
|
48b328 |
+ fqdn = try_to_get_fqdn (hostname);
|
|
|
48b328 |
+ }
|
|
|
48b328 |
+ conn->host_fqdn = fqdn != NULL ? fqdn : strdup (hostname);
|
|
|
48b328 |
return_unexpected_if_fail (conn->host_fqdn != NULL);
|
|
|
48b328 |
return ADCLI_SUCCESS;
|
|
|
48b328 |
}
|
|
|
48b328 |
--
|
|
|
48b328 |
2.20.1
|
|
|
48b328 |
|