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

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