netcmd/ldapcmp: avoid modifying data while looping on dict
authorJoe Guo <joeg@catalyst.net.nz>
Mon, 29 Oct 2018 04:28:56 +0000 (17:28 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 21 Nov 2018 06:46:19 +0000 (07:46 +0100)
Just define another dict for return value, seems no need to modify
original dict.

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

index 338dc049fd2984d29bdfe80d9fe147fa0cffbe7d..69aab8b779fa6f260da225dff93a167578304eb0 100644 (file)
@@ -208,13 +208,15 @@ class LDAPBase(object):
         res = dict(res[0])
         # 'Dn' element is not iterable and we have it as 'distinguishedName'
         del res["dn"]
-        for key in list(res.keys()):
-            vals = list(res[key])
-            del res[key]
+
+        attributes = {}
+        for key, vals in res.items():
             name = self.get_attribute_name(key)
-            res[name] = self.get_attribute_values(object_dn, key, vals)
+            # sort vals and return a list, help to compare
+            vals = sorted(vals)
+            attributes[name] = self.get_attribute_values(object_dn, key, vals)
 
-        return res
+        return attributes
 
     def get_descriptor_sddl(self, object_dn):
         res = self.ldb.search(base=object_dn, scope=SCOPE_BASE, attrs=["nTSecurityDescriptor"])