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