]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
samba-tool ldapcmp: do not assume common attributes
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Wed, 17 Aug 2022 23:38:35 +0000 (11:38 +1200)
committerDouglas Bagnall <dbagnall@samba.org>
Tue, 6 Sep 2022 21:12:36 +0000 (21:12 +0000)
This has caused numerous reports of

ERROR(<class 'KeyError'>): uncaught exception - 'serverReferenceBL'
  File /usr/lib/python3/dist-packages/samba/netcmd/__init__.py, line 185, in _run
    return self.run(*args, **kwargs)
  File /usr/lib/python3/dist-packages/samba/netcmd/ldapcmp.py, line 957, in run
    if b1.diff(b2):
  File /usr/lib/python3/dist-packages/samba/netcmd/ldapcmp.py, line 781, in diff
    if object1 == object2:
  File /usr/lib/python3/dist-packages/samba/netcmd/ldapcmp.py, line 549, in __eq__
    return self.cmp_attrs(other)
  File /usr/lib/python3/dist-packages/samba/netcmd/ldapcmp.py, line 590, in cmp_attrs
    if isinstance(self.attributes[x], list) and isinstance(other.attributes[x], list):

because other does not have attribute 'x'.

It is better to assume other.attributes[x] is None, which will compare
as unequal to whatever self.attributes[x] is, showing up as a diff
rather than a crash.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/netcmd/ldapcmp.py

index dc5e86e905d6f183552d09d5f69ed13f985024d6..dd34e0cf015ac9b6d14c88b0f1c823da2e12b073 100644 (file)
@@ -588,7 +588,7 @@ class LDAPObject(object):
             if x.upper() in self.ignore_attributes or x.upper() in missing_attrs:
                 continue
             ours = self.attributes[x]
-            theirs = other.attributes[x]
+            theirs = other.attributes.get(x)
 
             if isinstance(ours, list) and isinstance(theirs, list):
                 ours = sorted(ours)