From: Joe Guo Date: Mon, 29 Oct 2018 04:28:56 +0000 (+1300) Subject: netcmd/ldapcmp: avoid modifying data while looping on dict X-Git-Tag: tdb-1.3.17~695 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bbd082e7929010545deb5ce59e370ebe934aa23e;p=thirdparty%2Fsamba.git netcmd/ldapcmp: avoid modifying data while looping on dict Just define another dict for return value, seems no need to modify original dict. Signed-off-by: Joe Guo Reviewed-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/netcmd/ldapcmp.py b/python/samba/netcmd/ldapcmp.py index 338dc049fd2..69aab8b779f 100644 --- a/python/samba/netcmd/ldapcmp.py +++ b/python/samba/netcmd/ldapcmp.py @@ -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"])