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