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

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