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

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