Blame SOURCES/0001-Use-current-idmap-options-for-smb.conf.patch

3a7434
From e683fb573bc09893ec541be29751560cea30ce3f Mon Sep 17 00:00:00 2001
3a7434
From: Sumit Bose <sbose@redhat.com>
3a7434
Date: Wed, 30 May 2018 13:10:57 +0200
3a7434
Subject: [PATCH] Use current idmap options for smb.conf
3a7434
3a7434
Samba change some time ago the way how to configure id-mapping. With
3a7434
this patch realmd will use the current supported options when creating
3a7434
smb.conf.
3a7434
3a7434
A new option --legacy-samba-config is added to use the old options if
3a7434
realmd is used with Samba 3.5 or earlier.
3a7434
3a7434
Related to https://bugzilla.redhat.com/show_bug.cgi?id=1484072
3a7434
---
3a7434
 dbus/realm-dbus-constants.h   |  1 +
3a7434
 doc/manual/realmd.conf.xml    | 17 ++++++++++++
3a7434
 service/realm-samba-enroll.c  |  2 +-
3a7434
 service/realm-samba-enroll.h  |  3 +++
3a7434
 service/realm-samba-winbind.c | 63 ++++++++++++++++++++++++++++++++++---------
3a7434
 5 files changed, 72 insertions(+), 14 deletions(-)
3a7434
3a7434
diff --git a/dbus/realm-dbus-constants.h b/dbus/realm-dbus-constants.h
3a7434
index 9cd30ef..40ffa2d 100644
3a7434
--- a/dbus/realm-dbus-constants.h
3a7434
+++ b/dbus/realm-dbus-constants.h
3a7434
@@ -69,6 +69,7 @@ G_BEGIN_DECLS
3a7434
 #define   REALM_DBUS_OPTION_COMPUTER_NAME          "computer-name"
3a7434
 #define   REALM_DBUS_OPTION_OS_NAME                "os-name"
3a7434
 #define   REALM_DBUS_OPTION_OS_VERSION             "os-version"
3a7434
+#define   REALM_DBUS_OPTION_LEGACY_SMB_CONF        "legacy-samba-config"
3a7434
 
3a7434
 #define   REALM_DBUS_IDENTIFIER_ACTIVE_DIRECTORY   "active-directory"
3a7434
 #define   REALM_DBUS_IDENTIFIER_WINBIND            "winbind"
3a7434
diff --git a/doc/manual/realmd.conf.xml b/doc/manual/realmd.conf.xml
3a7434
index 7853230..a2b577c 100644
3a7434
--- a/doc/manual/realmd.conf.xml
3a7434
+++ b/doc/manual/realmd.conf.xml
3a7434
@@ -192,6 +192,23 @@ automatic-install = no
3a7434
 	</listitem>
3a7434
 	</varlistentry>
3a7434
 
3a7434
+	<varlistentry>
3a7434
+	<term><option>legacy-samba-config</option></term>
3a7434
+	<listitem>
3a7434
+		<para>Set this to <parameter>yes</parameter> to create a Samba
3a7434
+		configuration file with id-mapping options used by Samba-3.5
3a7434
+		and earlier version.</para>
3a7434
+
3a7434
+		<informalexample>
3a7434
+<programlisting language="js">
3a7434
+[service]
3a7434
+legacy-samba-config = no
3a7434
+# legacy-samba-config = yes
3a7434
+</programlisting>
3a7434
+		</informalexample>
3a7434
+	</listitem>
3a7434
+	</varlistentry>
3a7434
+
3a7434
 	</variablelist>
3a7434
 </refsect1>
3a7434
 
3a7434
diff --git a/service/realm-samba-enroll.c b/service/realm-samba-enroll.c
3a7434
index c81aed2..76e7b79 100644
3a7434
--- a/service/realm-samba-enroll.c
3a7434
+++ b/service/realm-samba-enroll.c
3a7434
@@ -69,7 +69,7 @@ join_closure_free (gpointer data)
3a7434
 	g_free (join);
3a7434
 }
3a7434
 
3a7434
-static gchar *
3a7434
+gchar *
3a7434
 fallback_workgroup (const gchar *realm)
3a7434
 {
3a7434
 	const gchar *pos;
3a7434
diff --git a/service/realm-samba-enroll.h b/service/realm-samba-enroll.h
3a7434
index 84e8b2f..310ec65 100644
3a7434
--- a/service/realm-samba-enroll.h
3a7434
+++ b/service/realm-samba-enroll.h
3a7434
@@ -46,6 +46,9 @@ void               realm_samba_enroll_leave_async          (RealmDisco *disco,
3a7434
 gboolean           realm_samba_enroll_leave_finish         (GAsyncResult *result,
3a7434
                                                             GError **error);
3a7434
 
3a7434
+gchar *
3a7434
+fallback_workgroup (const gchar *realm);
3a7434
+
3a7434
 G_END_DECLS
3a7434
 
3a7434
 #endif /* __REALM_SAMBA_ENROLL_H__ */
3a7434
diff --git a/service/realm-samba-winbind.c b/service/realm-samba-winbind.c
3a7434
index a7ddec3..9335e26 100644
3a7434
--- a/service/realm-samba-winbind.c
3a7434
+++ b/service/realm-samba-winbind.c
3a7434
@@ -21,8 +21,10 @@
3a7434
 #include "realm-options.h"
3a7434
 #include "realm-samba-config.h"
3a7434
 #include "realm-samba-winbind.h"
3a7434
+#include "realm-samba-enroll.h"
3a7434
 #include "realm-settings.h"
3a7434
 #include "realm-service.h"
3a7434
+#include "dbus/realm-dbus-constants.h"
3a7434
 
3a7434
 #include <glib/gstdio.h>
3a7434
 
3a7434
@@ -80,6 +82,10 @@ realm_samba_winbind_configure_async (RealmIniConfig *config,
3a7434
 	RealmIniConfig *pwc;
3a7434
 	GTask *task;
3a7434
 	GError *error = NULL;
3a7434
+	gchar *workgroup = NULL;
3a7434
+	gchar *idmap_config_backend = NULL;
3a7434
+	gchar *idmap_config_range = NULL;
3a7434
+	gchar *idmap_config_schema_mode = NULL;
3a7434
 
3a7434
 	g_return_if_fail (config != NULL);
3a7434
 	g_return_if_fail (invocation != NULL || G_IS_DBUS_METHOD_INVOCATION (invocation));
3a7434
@@ -100,23 +106,54 @@ realm_samba_winbind_configure_async (RealmIniConfig *config,
3a7434
 		                      "template shell", realm_settings_string ("users", "default-shell"),
3a7434
 		                      NULL);
3a7434
 
3a7434
-		if (realm_options_automatic_mapping (options, domain_name)) {
3a7434
-			realm_ini_config_set (config, REALM_SAMBA_CONFIG_GLOBAL,
3a7434
-			                      "idmap uid", "10000-2000000",
3a7434
-			                      "idmap gid", "10000-2000000",
3a7434
-			                      "idmap backend", "tdb",
3a7434
-			                      "idmap schema", NULL,
3a7434
-			                      NULL);
3a7434
+		if (realm_settings_boolean ("service", REALM_DBUS_OPTION_LEGACY_SMB_CONF, FALSE)) {
3a7434
+			if (realm_options_automatic_mapping (options, domain_name)) {
3a7434
+				realm_ini_config_set (config, REALM_SAMBA_CONFIG_GLOBAL,
3a7434
+						      "idmap uid", "10000-2000000",
3a7434
+						      "idmap gid", "10000-2000000",
3a7434
+						      "idmap backend", "tdb",
3a7434
+						      "idmap schema", NULL,
3a7434
+						      NULL);
3a7434
+			} else {
3a7434
+				realm_ini_config_set (config, REALM_SAMBA_CONFIG_GLOBAL,
3a7434
+						      "idmap uid", "500-4294967296",
3a7434
+						      "idmap gid", "500-4294967296",
3a7434
+						      "idmap backend", "ad",
3a7434
+						      "idmap schema", "rfc2307",
3a7434
+						      NULL);
3a7434
+			}
3a7434
 		} else {
3a7434
-			realm_ini_config_set (config, REALM_SAMBA_CONFIG_GLOBAL,
3a7434
-			                      "idmap uid", "500-4294967296",
3a7434
-			                      "idmap gid", "500-4294967296",
3a7434
-			                      "idmap backend", "ad",
3a7434
-			                      "idmap schema", "rfc2307",
3a7434
-			                      NULL);
3a7434
+			workgroup = realm_ini_config_get (config, REALM_SAMBA_CONFIG_GLOBAL, "workgroup");
3a7434
+			if (workgroup == NULL) {
3a7434
+				workgroup = fallback_workgroup (domain_name);
3a7434
+			}
3a7434
+			idmap_config_backend = g_strdup_printf ("idmap config %s : backend", workgroup != NULL ? workgroup : "PLEASE_REPLACE");
3a7434
+			idmap_config_range = g_strdup_printf ("idmap config %s : range", workgroup != NULL ? workgroup : "PLEASE_REPLACE");
3a7434
+			idmap_config_schema_mode = g_strdup_printf ("idmap config %s : schema_mode", workgroup != NULL ? workgroup : "PLEASE_REPLACE");
3a7434
+			g_free (workgroup);
3a7434
+
3a7434
+			if (realm_options_automatic_mapping (options, domain_name)) {
3a7434
+				realm_ini_config_set (config, REALM_SAMBA_CONFIG_GLOBAL,
3a7434
+						      "idmap config * : backend", "tdb",
3a7434
+						      "idmap config * : range", "10000-999999",
3a7434
+						      idmap_config_backend != NULL ? idmap_config_backend : "idmap config PLEASE_REPLACE : backend", "rid",
3a7434
+						      idmap_config_range != NULL ? idmap_config_range: "idmap config PLEASE_REPLACE : range", "2000000-2999999",
3a7434
+						      idmap_config_schema_mode != NULL ? idmap_config_schema_mode: "idmap config PLEASE_REPLACE : schema_mode", NULL,
3a7434
+						      NULL);
3a7434
+			} else {
3a7434
+				realm_ini_config_set (config, REALM_SAMBA_CONFIG_GLOBAL,
3a7434
+						      "idmap config * : backend", "tdb",
3a7434
+						      "idmap config * : range", "10000000-10999999",
3a7434
+						      idmap_config_backend != NULL ? idmap_config_backend : "idmap config PLEASE_REPLACE : backend", "ad",
3a7434
+						      idmap_config_range != NULL ? idmap_config_range: "idmap config PLEASE_REPLACE : range", "500-999999",
3a7434
+						      idmap_config_schema_mode != NULL ? idmap_config_schema_mode: "idmap config PLEASE_REPLACE : schema_mode", "rfc2307",
3a7434
+						      NULL);
3a7434
+			}
3a7434
 		}
3a7434
 
3a7434
 		realm_ini_config_finish_change (config, &error);
3a7434
+		g_free (idmap_config_backend);
3a7434
+		g_free (idmap_config_range);
3a7434
 	}
3a7434
 
3a7434
 	/* Setup pam_winbind.conf with decent defaults matching our expectations */
3a7434
-- 
3a7434
2.14.4
3a7434