34340e
From 89f7b7790dd7f3a300718de2d811104dc0637bbd Mon Sep 17 00:00:00 2001
34340e
From: Andreas Schneider <asn@samba.org>
34340e
Date: Tue, 1 Feb 2022 10:06:30 +0100
34340e
Subject: [PATCH 1/3] s3:winbindd: Add a sanity check for the range
34340e
34340e
What we want to avoid:
34340e
34340e
$ ./bin/testparm -s | grep "idmap config"
34340e
        idmap config * : rangesize = 10000
34340e
        idmap config * : range = 10000-19999
34340e
        idmap config * : backend = autorid
34340e
34340e
$ ./bin/wbinfo --name-to-sid BUILTIN/Administrators
34340e
S-1-5-32-544 SID_ALIAS (4)
34340e
34340e
$ ./bin/wbinfo --sid-to-gid S-1-5-32-544
34340e
10000
34340e
34340e
$ ./bin/wbinfo --name-to-sid ADDOMAIN/alice
34340e
S-1-5-21-4058748110-895691256-3682847423-1107 SID_USER (1)
34340e
34340e
$ ./bin/wbinfo --sid-to-gid S-1-5-21-984165912-589366285-3903095728-1107
34340e
failed to call wbcSidToGid: WBC_ERR_DOMAIN_NOT_FOUND
34340e
Could not convert sid S-1-5-21-984165912-589366285-3903095728-1107 to gid
34340e
34340e
If only one range is configured we are either not able to map users/groups
34340e
from our primary *and* the BUILTIN domain. We need at least two ranges to also
34340e
cover the BUILTIN domain!
34340e
34340e
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14967
34340e
34340e
Signed-off-by: Andreas Schneider <asn@samba.org>
34340e
Reviewed-by: Guenther Deschner <gd@samba.org>
34340e
(cherry picked from commit fe84ae5547313e482ea0eba8ddca5b38a033dc8f)
34340e
---
34340e
 source3/winbindd/idmap_autorid.c | 7 ++++---
34340e
 1 file changed, 4 insertions(+), 3 deletions(-)
34340e
34340e
diff --git a/source3/winbindd/idmap_autorid.c b/source3/winbindd/idmap_autorid.c
34340e
index ad53b5810ee..c7d56a37684 100644
34340e
--- a/source3/winbindd/idmap_autorid.c
34340e
+++ b/source3/winbindd/idmap_autorid.c
34340e
@@ -856,9 +856,10 @@ static NTSTATUS idmap_autorid_initialize(struct idmap_domain *dom)
34340e
 	config->maxranges = (dom->high_id - dom->low_id + 1) /
34340e
 	    config->rangesize;
34340e
 
34340e
-	if (config->maxranges == 0) {
34340e
-		DEBUG(1, ("Allowed uid range is smaller than rangesize. "
34340e
-			  "Increase uid range or decrease rangesize.\n"));
34340e
+	if (config->maxranges < 2) {
34340e
+		DBG_WARNING("Allowed idmap range is not a least double the "
34340e
+			    "size of the rangesize. Please increase idmap "
34340e
+			    "range.\n");
34340e
 		status = NT_STATUS_INVALID_PARAMETER;
34340e
 		goto error;
34340e
 	}
34340e
-- 
34340e
2.35.1
34340e
34340e
34340e
From 70a0069038948a22b1e7dfd8917a3487206ec770 Mon Sep 17 00:00:00 2001
34340e
From: Andreas Schneider <asn@samba.org>
34340e
Date: Tue, 1 Feb 2022 10:07:50 +0100
34340e
Subject: [PATCH 2/3] s3:utils: Add a testparm check for idmap autorid
34340e
34340e
What we want to avoid:
34340e
34340e
$ ./bin/testparm -s | grep "idmap config"
34340e
        idmap config * : rangesize = 10000
34340e
        idmap config * : range = 10000-19999
34340e
        idmap config * : backend = autorid
34340e
34340e
$ ./bin/wbinfo --name-to-sid BUILTIN/Administrators
34340e
S-1-5-32-544 SID_ALIAS (4)
34340e
34340e
$ ./bin/wbinfo --sid-to-gid S-1-5-32-544
34340e
10000
34340e
34340e
$ ./bin/wbinfo --name-to-sid ADDOMAIN/alice
34340e
S-1-5-21-4058748110-895691256-3682847423-1107 SID_USER (1)
34340e
34340e
$ ./bin/wbinfo --sid-to-gid S-1-5-21-984165912-589366285-3903095728-1107
34340e
failed to call wbcSidToGid: WBC_ERR_DOMAIN_NOT_FOUND
34340e
Could not convert sid S-1-5-21-984165912-589366285-3903095728-1107 to gid
34340e
34340e
If only one range is configured we are either not able to map users/groups
34340e
from our primary *and* the BUILTIN domain. We need at least two ranges to also
34340e
cover the BUILTIN domain!
34340e
34340e
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14967
34340e
34340e
Signed-off-by: Andreas Schneider <asn@samba.org>
34340e
Reviewed-by: Guenther Deschner <gd@samba.org>
34340e
(cherry picked from commit db6d4da3411a910e7ce45fe1fecfabf2864eb9f4)
34340e
---
34340e
 source3/utils/testparm.c | 51 ++++++++++++++++++++++++++++++++++++++++
34340e
 1 file changed, 51 insertions(+)
34340e
34340e
diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c
34340e
index 98bcc219b1e..58ba46bc15f 100644
34340e
--- a/source3/utils/testparm.c
34340e
+++ b/source3/utils/testparm.c
34340e
@@ -128,6 +128,21 @@ static bool lp_scan_idmap_found_domain(const char *string,
34340e
 	return false; /* Keep scanning */
34340e
 }
34340e
 
34340e
+static int idmap_config_int(const char *domname, const char *option, int def)
34340e
+{
34340e
+	int len = snprintf(NULL, 0, "idmap config %s", domname);
34340e
+
34340e
+	if (len == -1) {
34340e
+		return def;
34340e
+	}
34340e
+	{
34340e
+		char config_option[len+1];
34340e
+		snprintf(config_option, sizeof(config_option),
34340e
+			 "idmap config %s", domname);
34340e
+		return lp_parm_int(-1, config_option, option, def);
34340e
+	}
34340e
+}
34340e
+
34340e
 static bool do_idmap_check(void)
34340e
 {
34340e
 	struct idmap_domains *d;
34340e
@@ -157,6 +172,42 @@ static bool do_idmap_check(void)
34340e
 			rc);
34340e
 	}
34340e
 
34340e
+	/* Check autorid backend */
34340e
+	if (strequal(lp_idmap_default_backend(), "autorid")) {
34340e
+		struct idmap_config *c = NULL;
34340e
+		bool found = false;
34340e
+
34340e
+		for (i = 0; i < d->count; i++) {
34340e
+			c = &d->c[i];
34340e
+
34340e
+			if (strequal(c->backend, "autorid")) {
34340e
+				found = true;
34340e
+				break;
34340e
+			}
34340e
+		}
34340e
+
34340e
+		if (found) {
34340e
+			uint32_t rangesize =
34340e
+				idmap_config_int("*", "rangesize", 100000);
34340e
+			uint32_t maxranges =
34340e
+				(c->high - c->low  + 1) / rangesize;
34340e
+
34340e
+			if (maxranges < 2) {
34340e
+				fprintf(stderr,
34340e
+					"ERROR: The idmap autorid range "
34340e
+					"[%u-%u] needs to be at least twice as "
34340e
+					"big as the rangesize [%u]!"
34340e
+					"\n\n",
34340e
+					c->low,
34340e
+					c->high,
34340e
+					rangesize);
34340e
+				ok = false;
34340e
+				goto done;
34340e
+			}
34340e
+		}
34340e
+	}
34340e
+
34340e
+	/* Check for overlapping idmap ranges */
34340e
 	for (i = 0; i < d->count; i++) {
34340e
 		struct idmap_config *c = &d->c[i];
34340e
 		uint32_t j;
34340e
-- 
34340e
2.35.1
34340e
34340e
34340e
From 9cc90a306bc31ca9fb0b82556ae28c173b77724e Mon Sep 17 00:00:00 2001
34340e
From: Andreas Schneider <asn@samba.org>
34340e
Date: Tue, 1 Feb 2022 10:05:19 +0100
34340e
Subject: [PATCH 3/3] docs-xml: Fix idmap_autorid documentation
34340e
34340e
What we want to avoid:
34340e
34340e
$ ./bin/testparm -s | grep "idmap config"
34340e
        idmap config * : rangesize = 10000
34340e
        idmap config * : range = 10000-19999
34340e
        idmap config * : backend = autorid
34340e
34340e
$ ./bin/wbinfo --name-to-sid BUILTIN/Administrators
34340e
S-1-5-32-544 SID_ALIAS (4)
34340e
34340e
$ ./bin/wbinfo --sid-to-gid S-1-5-32-544
34340e
10000
34340e
34340e
$ ./bin/wbinfo --name-to-sid ADDOMAIN/alice
34340e
S-1-5-21-4058748110-895691256-3682847423-1107 SID_USER (1)
34340e
34340e
$ ./bin/wbinfo --sid-to-gid S-1-5-21-984165912-589366285-3903095728-1107
34340e
failed to call wbcSidToGid: WBC_ERR_DOMAIN_NOT_FOUND
34340e
Could not convert sid S-1-5-21-984165912-589366285-3903095728-1107 to gid
34340e
34340e
If only one range is configured we are either not able to map users/groups
34340e
from our primary *and* the BUILTIN domain. We need at least two ranges to also
34340e
cover the BUILTIN domain!
34340e
34340e
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14967
34340e
34340e
Signed-off-by: Andreas Schneider <asn@samba.org>
34340e
Reviewed-by: Guenther Deschner <gd@samba.org>
34340e
(cherry picked from commit 7e5afd8f1f7e5cfab1a8ef7f4293ac465b7cd8de)
34340e
---
34340e
 docs-xml/manpages/idmap_autorid.8.xml | 8 +++++++-
34340e
 1 file changed, 7 insertions(+), 1 deletion(-)
34340e
34340e
diff --git a/docs-xml/manpages/idmap_autorid.8.xml b/docs-xml/manpages/idmap_autorid.8.xml
34340e
index 6c4da1cad8a..980718f0bd4 100644
34340e
--- a/docs-xml/manpages/idmap_autorid.8.xml
34340e
+++ b/docs-xml/manpages/idmap_autorid.8.xml
34340e
@@ -48,7 +48,13 @@
34340e
 			and the corresponding map is discarded.  It is
34340e
 			intended as a way to avoid accidental UID/GID
34340e
 			overlaps between local and remotely defined
34340e
-			IDs.
34340e
+			IDs. Note that the range should be a multiple
34340e
+			of the rangesize and needs to be at least twice
34340e
+			as large in order to have sufficient id range
34340e
+			space for the mandatory BUILTIN domain.
34340e
+			With a default rangesize of 100000 the range
34340e
+			needs to span at least 200000.
34340e
+			This would be: range = 100000 - 299999.
34340e
 		</para></listitem>
34340e
 		</varlistentry>
34340e
 
34340e
-- 
34340e
2.35.1
34340e