File 0025-library-use-getaddrinfo-with-AI_CANONNAME-to-find-a-.patch of Package adcli (Revision ce46d0e7322eb68daa00b5c190e5847d)
Currently displaying revision ce46d0e7322eb68daa00b5c190e5847d , Show latest
94
1
From fd5b6bd9fd2c79b438349bada2c1a80f44daae0f Mon Sep 17 00:00:00 2001
2
From: Sumit Bose <sbose@redhat.com>
3
Date: Fri, 15 Mar 2019 17:33:44 +0100
4
Subject: [PATCH 25/25] library: use getaddrinfo with AI_CANONNAME to find a
5
FQDN
6
7
Currently adcli creates service principals only with a short name if the
8
hostname of the client is a short name. This would fail is
9
Kerberos/GSSAPI clients will use the fully-qualified domain name (FQDN)
10
to access the host.
11
12
With this patch adcli tries to expand the short name by calling
13
getaddrinfo with the AI_CANONNAME hint.
14
15
Related to https://gitlab.freedesktop.org/realmd/adcli/issues/1
16
---
17
doc/adcli.xml | 6 +++++-
18
library/adconn.c | 30 +++++++++++++++++++++++++++++-
19
2 files changed, 34 insertions(+), 2 deletions(-)
20
21
diff --git a/doc/adcli.xml b/doc/adcli.xml
22
index 7003e5f..2fe9309 100644
23
--- a/doc/adcli.xml
24
+++ b/doc/adcli.xml
25
26
<term><option>-H, --host-fqdn=<parameter>host</parameter></option></term>
27
<listitem><para>Override the local machine's fully qualified
28
domain name. If not specified the local machine's hostname
29
- will be retrieved via <function>gethostname()</function>.</para></listitem>
30
+ will be retrieved via <function>gethostname()</function>.
31
+ If <function>gethostname()</function> only returns a short name
32
+ <function>getaddrinfo()</function> with the AI_CANONNAME hint
33
+ is called to expand the name to a fully qualified domain
34
+ name.</para></listitem>
35
</varlistentry>
36
<varlistentry>
37
<term><option>-K, --host-keytab=<parameter>/path/to/keytab</parameter></option></term>
38
diff --git a/library/adconn.c b/library/adconn.c
39
index e2250e3..f6c23d3 100644
40
--- a/library/adconn.c
41
+++ b/library/adconn.c
42
43
krb5_keytab keytab;
44
};
45
46
+static char *try_to_get_fqdn (const char *host_name)
47
+{
48
+ int ret;
49
+ char *fqdn = NULL;
50
+ struct addrinfo *res;
51
+ struct addrinfo hints;
52
+
53
+ memset (&hints, 0, sizeof (struct addrinfo));
54
+ hints.ai_socktype = SOCK_DGRAM;
55
+ hints.ai_flags = AI_CANONNAME;
56
+
57
+ ret = getaddrinfo (host_name, NULL, &hints, &res);
58
+ if (ret != 0) {
59
+ _adcli_err ("Failed to find FQDN: %s", gai_strerror (ret));
60
+ return NULL;
61
+ }
62
+
63
+ fqdn = strdup (res->ai_canonname);
64
+
65
+ freeaddrinfo (res);
66
+
67
+ return fqdn;
68
+}
69
+
70
static adcli_result
71
ensure_host_fqdn (adcli_result res,
72
adcli_conn *conn)
73
{
74
char hostname[HOST_NAME_MAX + 1];
75
+ char *fqdn = NULL;
76
int ret;
77
78
if (res != ADCLI_SUCCESS)
79
80
return ADCLI_ERR_UNEXPECTED;
81
}
82
83
- conn->host_fqdn = strdup (hostname);
84
+ if (strchr (hostname, '.') == NULL) {
85
+ fqdn = try_to_get_fqdn (hostname);
86
+ }
87
+ conn->host_fqdn = fqdn != NULL ? fqdn : strdup (hostname);
88
return_unexpected_if_fail (conn->host_fqdn != NULL);
89
return ADCLI_SUCCESS;
90
}
91
--
92
2.16.4
93
94