|
|
3d166f |
From a49994ab4ac36ff39a1e24a228e57a5269bf8fdf Mon Sep 17 00:00:00 2001
|
|
|
3d166f |
From: Sumit Bose <sbose@redhat.com>
|
|
|
3d166f |
Date: Wed, 12 Aug 2020 12:58:27 +0200
|
|
|
3d166f |
Subject: [PATCH] service: use 'additional dns hostnames' with net ads join
|
|
|
3d166f |
|
|
|
3d166f |
With newer versions of Samba the net ads join does not add services
|
|
|
3d166f |
principals with the configured host name anymore but added the new
|
|
|
3d166f |
option 'additional dns hostnames' for this.
|
|
|
3d166f |
|
|
|
3d166f |
realmd will try to figure out a fully-qualified host name and use it
|
|
|
3d166f |
with the new option if it is from a different domain.
|
|
|
3d166f |
|
|
|
3d166f |
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1867912
|
|
|
3d166f |
---
|
|
|
3d166f |
service/realm-disco.c | 1 +
|
|
|
3d166f |
service/realm-disco.h | 1 +
|
|
|
3d166f |
service/realm-samba-enroll.c | 57 +++++++++++++++++++++++++++++++++++-
|
|
|
3d166f |
service/realm-samba.c | 6 ++++
|
|
|
3d166f |
4 files changed, 64 insertions(+), 1 deletion(-)
|
|
|
3d166f |
|
|
|
3d166f |
diff --git a/service/realm-disco.c b/service/realm-disco.c
|
|
|
3d166f |
index ab06939..a12be50 100644
|
|
|
3d166f |
--- a/service/realm-disco.c
|
|
|
3d166f |
+++ b/service/realm-disco.c
|
|
|
3d166f |
@@ -62,6 +62,7 @@ realm_disco_unref (gpointer data)
|
|
|
3d166f |
g_free (disco->explicit_netbios);
|
|
|
3d166f |
g_free (disco->kerberos_realm);
|
|
|
3d166f |
g_free (disco->workgroup);
|
|
|
3d166f |
+ g_free (disco->dns_fqdn);
|
|
|
3d166f |
if (disco->server_address)
|
|
|
3d166f |
g_object_unref (disco->server_address);
|
|
|
3d166f |
g_free (disco);
|
|
|
3d166f |
diff --git a/service/realm-disco.h b/service/realm-disco.h
|
|
|
3d166f |
index 5f3e5e9..35532d2 100644
|
|
|
3d166f |
--- a/service/realm-disco.h
|
|
|
3d166f |
+++ b/service/realm-disco.h
|
|
|
3d166f |
@@ -30,6 +30,7 @@ typedef struct {
|
|
|
3d166f |
gchar *explicit_server;
|
|
|
3d166f |
gchar *explicit_netbios;
|
|
|
3d166f |
GSocketAddress *server_address;
|
|
|
3d166f |
+ gchar *dns_fqdn;
|
|
|
3d166f |
} RealmDisco;
|
|
|
3d166f |
|
|
|
3d166f |
#define REALM_TYPE_DISCO (realm_disco_get_type ())
|
|
|
3d166f |
diff --git a/service/realm-samba-enroll.c b/service/realm-samba-enroll.c
|
|
|
3d166f |
index 3f86c51..5624a08 100644
|
|
|
3d166f |
--- a/service/realm-samba-enroll.c
|
|
|
3d166f |
+++ b/service/realm-samba-enroll.c
|
|
|
3d166f |
@@ -33,6 +33,9 @@
|
|
|
3d166f |
#include <errno.h>
|
|
|
3d166f |
#include <fcntl.h>
|
|
|
3d166f |
#include <string.h>
|
|
|
3d166f |
+#include <sys/types.h>
|
|
|
3d166f |
+#include <sys/socket.h>
|
|
|
3d166f |
+#include <netdb.h>
|
|
|
3d166f |
|
|
|
3d166f |
typedef struct {
|
|
|
3d166f |
GDBusMethodInvocation *invocation;
|
|
|
3d166f |
@@ -81,6 +84,44 @@ fallback_workgroup (const gchar *realm)
|
|
|
3d166f |
return g_utf8_strup (realm, pos - realm);
|
|
|
3d166f |
}
|
|
|
3d166f |
|
|
|
3d166f |
+static char *
|
|
|
3d166f |
+try_to_get_fqdn (void)
|
|
|
3d166f |
+{
|
|
|
3d166f |
+ char hostname[HOST_NAME_MAX + 1];
|
|
|
3d166f |
+ gchar *fqdn = NULL;
|
|
|
3d166f |
+ int ret;
|
|
|
3d166f |
+ struct addrinfo *res;
|
|
|
3d166f |
+ struct addrinfo hints;
|
|
|
3d166f |
+
|
|
|
3d166f |
+ ret = gethostname (hostname, sizeof (hostname));
|
|
|
3d166f |
+ if (ret < 0) {
|
|
|
3d166f |
+ return NULL;
|
|
|
3d166f |
+ }
|
|
|
3d166f |
+
|
|
|
3d166f |
+ if (strchr (hostname, '.') == NULL) {
|
|
|
3d166f |
+ memset (&hints, 0, sizeof (struct addrinfo));
|
|
|
3d166f |
+ hints.ai_socktype = SOCK_DGRAM;
|
|
|
3d166f |
+ hints.ai_flags = AI_CANONNAME;
|
|
|
3d166f |
+
|
|
|
3d166f |
+ ret = getaddrinfo (hostname, NULL, &hints, &res;;
|
|
|
3d166f |
+ if (ret != 0) {
|
|
|
3d166f |
+ return NULL;
|
|
|
3d166f |
+ }
|
|
|
3d166f |
+
|
|
|
3d166f |
+ /* Only use a fully-qualified name */
|
|
|
3d166f |
+ if (strchr (res->ai_canonname, '.') != NULL) {
|
|
|
3d166f |
+ fqdn = g_strdup (res->ai_canonname);
|
|
|
3d166f |
+ }
|
|
|
3d166f |
+
|
|
|
3d166f |
+ freeaddrinfo (res);
|
|
|
3d166f |
+
|
|
|
3d166f |
+ } else {
|
|
|
3d166f |
+ fqdn = g_strdup (hostname);
|
|
|
3d166f |
+ }
|
|
|
3d166f |
+
|
|
|
3d166f |
+ return fqdn;
|
|
|
3d166f |
+}
|
|
|
3d166f |
+
|
|
|
3d166f |
static JoinClosure *
|
|
|
3d166f |
join_closure_init (GTask *task,
|
|
|
3d166f |
RealmDisco *disco,
|
|
|
3d166f |
@@ -95,5 +136,7 @@ join_closure_init (GTask *task,
|
|
|
3d166f |
const gchar *explicit_computer_name = NULL;
|
|
|
3d166f |
const gchar *authid = NULL;
|
|
|
3d166f |
+ gchar *fqdn = NULL;
|
|
|
3d166f |
+ gchar *fqdn_dom = NULL;
|
|
|
3d166f |
|
|
|
3d166f |
join = g_new0 (JoinClosure, 1);
|
|
|
3d166f |
join->disco = realm_disco_ref (disco);
|
|
|
3d166f |
@@ -124,7 +167,7 @@ join_closure_init (GTask *task,
|
|
|
3d166f |
"netbios name", authid,
|
|
|
3d166f |
NULL);
|
|
|
3d166f |
|
|
|
3d166f |
- /*
|
|
|
3d166f |
+ /*
|
|
|
3d166f |
* Samba complains if we don't set a 'workgroup' setting for the realm we're
|
|
|
3d166f |
* going to join. If we didn't yet manage to lookup the workgroup, then go ahead
|
|
|
3d166f |
* and assume that the first domain component is the workgroup name.
|
|
|
3d166f |
@@ -144,6 +187,18 @@ join_closure_init (GTask *task,
|
|
|
3d166f |
g_free (workgroup);
|
|
|
3d166f |
}
|
|
|
3d166f |
|
|
|
3d166f |
+ /* Add the fully-qualified DNS hostname as additional name if it is from
|
|
|
3d166f |
+ * a different domain. */
|
|
|
3d166f |
+ fqdn = try_to_get_fqdn ();
|
|
|
3d166f |
+ if (fqdn != NULL && join->disco->domain_name != NULL
|
|
|
3d166f |
+ && (fqdn_dom = strchr (fqdn, '.')) != NULL
|
|
|
3d166f |
+ && g_ascii_strcasecmp (fqdn_dom + 1, join->disco->domain_name) != 0 ) {
|
|
|
3d166f |
+ disco->dns_fqdn = g_strdup (fqdn);
|
|
|
3d166f |
+ realm_ini_config_set (join->config, REALM_SAMBA_CONFIG_GLOBAL,
|
|
|
3d166f |
+ "additional dns hostnames", disco->dns_fqdn, NULL);
|
|
|
3d166f |
+ }
|
|
|
3d166f |
+ g_free (fqdn);
|
|
|
3d166f |
+
|
|
|
3d166f |
/* Write out the config file for use by various net commands */
|
|
|
3d166f |
join->custom_smb_conf = g_build_filename (g_get_tmp_dir (), "realmd-smb-conf.XXXXXX", NULL);
|
|
|
3d166f |
temp_fd = g_mkstemp_full (join->custom_smb_conf, O_WRONLY, S_IRUSR | S_IWUSR);
|
|
|
3d166f |
diff --git a/service/realm-samba.c b/service/realm-samba.c
|
|
|
3d166f |
index 4940b38..fe33600 100644
|
|
|
3d166f |
--- a/service/realm-samba.c
|
|
|
3d166f |
+++ b/service/realm-samba.c
|
|
|
3d166f |
@@ -204,6 +204,11 @@ on_join_do_winbind (GObject *source,
|
|
|
3d166f |
NULL);
|
|
|
3d166f |
}
|
|
|
3d166f |
|
|
|
3d166f |
+ if (error == NULL && enroll->disco->dns_fqdn != NULL) {
|
|
|
3d166f |
+ realm_ini_config_change (self->config, REALM_SAMBA_CONFIG_GLOBAL, &error,
|
|
|
3d166f |
+ "additional dns hostnames", enroll->disco->dns_fqdn,
|
|
|
3d166f |
+ NULL);
|
|
|
3d166f |
+ }
|
|
|
3d166f |
|
|
|
3d166f |
if (error == NULL) {
|
|
|
3d166f |
name = realm_kerberos_get_name (REALM_KERBEROS (self));
|
|
|
3d166f |
@@ -364,6 +369,7 @@ leave_deconfigure_begin (RealmSamba *self,
|
|
|
3d166f |
if (!realm_ini_config_change (self->config, REALM_SAMBA_CONFIG_GLOBAL, &error,
|
|
|
3d166f |
"workgroup", NULL,
|
|
|
3d166f |
"realm", NULL,
|
|
|
3d166f |
+ "additional dns hostnames", NULL,
|
|
|
3d166f |
"security", "user",
|
|
|
3d166f |
NULL)) {
|
|
|
3d166f |
g_task_return_error (task, error);
|
|
|
3d166f |
--
|
|
|
3d166f |
2.26.2
|
|
|
3d166f |
|