diff options
author | Douglas Bagnall <douglas.bagnall@catalyst.net.nz> | 2018-10-26 19:33:48 +1300 |
---|---|---|
committer | Douglas Bagnall <dbagnall@samba.org> | 2018-11-02 03:48:52 +0100 |
commit | f17a77af4602af02ebb05b8f6d6344c2dadf62f0 (patch) | |
tree | a4acb4552ebbee65833075b7154dbfbad85c6f97 /python/samba/dbchecker.py | |
parent | 28826ec49cc9f90ec514e9398d9bcf7f46a99a56 (diff) | |
download | samba-f17a77af4602af02ebb05b8f6d6344c2dadf62f0.tar.gz |
python dbcheck: don't use mutable default args
In this code
def f(a, b=[]):
b.append(a)
return b
all single argument calls to f() will affect the same copy of b.
In the controls case, controls=None has the same effect as
controls=[].
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Noel Power <noel.power@suse.com>
Diffstat (limited to 'python/samba/dbchecker.py')
-rw-r--r-- | python/samba/dbchecker.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/python/samba/dbchecker.py b/python/samba/dbchecker.py index 9af11162ce5..030bea4b299 100644 --- a/python/samba/dbchecker.py +++ b/python/samba/dbchecker.py @@ -226,7 +226,8 @@ class dbcheck(object): raise pass - def check_database(self, DN=None, scope=ldb.SCOPE_SUBTREE, controls=[], attrs=['*']): + def check_database(self, DN=None, scope=ldb.SCOPE_SUBTREE, controls=None, + attrs=None): '''perform a database check, returning the number of errors found''' res = self.samdb.search(base=DN, scope=scope, attrs=['dn'], controls=controls) self.report('Checking %u objects' % len(res)) @@ -2021,14 +2022,15 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base))) raise KeyError - def check_object(self, dn, attrs=['*']): + def check_object(self, dn, attrs=None): '''check one object''' if self.verbose: self.report("Checking object %s" % dn) - - # If we modify the pass-by-reference attrs variable, then we get a - # replPropertyMetadata for every object that we check. - attrs = list(attrs) + if attrs is None: + attrs = ['*'] + else: + # make a local copy to modify + attrs = list(attrs) if "dn" in map(str.lower, attrs): attrs.append("name") if "distinguishedname" in map(str.lower, attrs): |