Blame SOURCES/0002-trust-add-handle-missing-msSFU30MaxGidNumber_rhbz#2162355.patch

5347ee
From 703ab8c4dfb7f8fd1540c3849ad469d39695a26f Mon Sep 17 00:00:00 2001
5347ee
From: Florence Blanc-Renaud <flo@redhat.com>
5347ee
Date: Jan 25 2023 16:57:02 +0000
5347ee
Subject: trust-add: handle missing msSFU30MaxGidNumber
5347ee
5347ee
5347ee
When ipa trust-add is executed with --range-type ad-trust-posix,
5347ee
the server tries to find the max uidnumber and max gidnumber
5347ee
from AD domain controller.
5347ee
The values are extracted from the entry
5347ee
CN=<domain>,CN=ypservers,CN=ypServ30,CN=RpcServices,CN=System,<AD suffix>
5347ee
in the msSFU30MaxUidNumber and msSFU30MaxGidNumber attributes.
5347ee
5347ee
msSFU30MaxUidNumber is required but not msSFU30MaxGidNumber.
5347ee
In case msSFU30MaxGidNumber is missing, the code is currently assigning
5347ee
a "None" value and later on evaluates the max between this value and
5347ee
msSFU30MaxUidNumber. The max function cannot compare None and a list
5347ee
of string and triggers an exception.
5347ee
5347ee
To avoid the exception, assign [b'0'] to max gid if msSFU30MaxGidNumber
5347ee
is missing. This way, the comparison succeeds and max returns the
5347ee
value from msSFU30MaxUidNumber.
5347ee
5347ee
Fixes: https://pagure.io/freeipa/issue/9310
5347ee
Signed-off-by: Florence Blanc-Renaud <flo@redhat.com>
5347ee
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
5347ee
5347ee
---
5347ee
5347ee
diff --git a/ipaserver/plugins/trust.py b/ipaserver/plugins/trust.py
5347ee
index c074f6d..79264b8 100644
5347ee
--- a/ipaserver/plugins/trust.py
5347ee
+++ b/ipaserver/plugins/trust.py
5347ee
@@ -379,7 +379,10 @@ def add_range(myapi, trustinstance, range_name, dom_sid, *keys, **options):
5347ee
                 range_type = u'ipa-ad-trust-posix'
5347ee
 
5347ee
                 max_uid = info.get('msSFU30MaxUidNumber')
5347ee
-                max_gid = info.get('msSFU30MaxGidNumber', None)
5347ee
+                # if max_gid is missing, assume 0 and the max will
5347ee
+                # be obtained from max_uid. We just checked that
5347ee
+                # msSFU30MaxUidNumber is defined
5347ee
+                max_gid = info.get('msSFU30MaxGidNumber', [b'0'])
5347ee
                 max_id = int(max(max_uid, max_gid)[0])
5347ee
 
5347ee
                 base_id = int(info.get('msSFU30OrderNumber')[0])
5347ee