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