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

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