1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-12 09:18:10 +03:00

python: fix mutable default arguments

Signed-off-by: Rob van der Linde <rob@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>

Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Thu Feb 23 23:33:46 UTC 2023 on atb-devel-224
This commit is contained in:
Rob van der Linde 2023-02-23 15:54:37 +13:00 committed by Andrew Bartlett
parent e7c87b1d9b
commit 5cb8805811
26 changed files with 243 additions and 66 deletions

View File

@ -45,14 +45,20 @@ def sddl2binary(sddl_in, domain_sid, name_map):
return ndr_pack(sec)
def get_empty_descriptor(domain_sid, name_map={}):
def get_empty_descriptor(domain_sid, name_map=None):
if name_map is None:
name_map = {}
sddl = ""
return sddl2binary(sddl, domain_sid, name_map)
# "get_schema_descriptor" is located in "schema.py"
def get_config_descriptor(domain_sid, name_map={}):
def get_config_descriptor(domain_sid, name_map=None):
if name_map is None:
name_map = {}
sddl = "O:EAG:EAD:(OA;;CR;1131f6aa-9c07-11d1-f79f-00c04fc2dcd2;;ED)" \
"(OA;;CR;1131f6ab-9c07-11d1-f79f-00c04fc2dcd2;;ED)" \
"(OA;;CR;1131f6ac-9c07-11d1-f79f-00c04fc2dcd2;;ED)" \
@ -71,7 +77,10 @@ def get_config_descriptor(domain_sid, name_map={}):
return sddl2binary(sddl, domain_sid, name_map)
def get_config_partitions_descriptor(domain_sid, name_map={}):
def get_config_partitions_descriptor(domain_sid, name_map=None):
if name_map is None:
name_map = {}
sddl = "D:" \
"(A;;LCLORC;;;AU)" \
"(OA;;RP;e48d0154-bcf8-11d1-8702-00c04fb96050;;AU)" \
@ -89,7 +98,10 @@ def get_config_partitions_descriptor(domain_sid, name_map={}):
return sddl2binary(sddl, domain_sid, name_map)
def get_config_sites_descriptor(domain_sid, name_map={}):
def get_config_sites_descriptor(domain_sid, name_map=None):
if name_map is None:
name_map = {}
sddl = "D:" \
"(A;;RPLCLORC;;;AU)" \
"(OA;CIIO;SW;d31a8757-2447-4545-8081-3bb610cacbf2;f0f8ffab-1191-11d0-a060-00aa006c33ed;RO)" \
@ -104,7 +116,10 @@ def get_config_sites_descriptor(domain_sid, name_map={}):
return sddl2binary(sddl, domain_sid, name_map)
def get_config_ntds_quotas_descriptor(domain_sid, name_map={}):
def get_config_ntds_quotas_descriptor(domain_sid, name_map=None):
if name_map is None:
name_map = {}
sddl = "D:" \
"(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;EA)" \
"(A;;RPLCLORC;;;BA)" \
@ -112,7 +127,10 @@ def get_config_ntds_quotas_descriptor(domain_sid, name_map={}):
return sddl2binary(sddl, domain_sid, name_map)
def get_config_delete_protected1_descriptor(domain_sid, name_map={}):
def get_config_delete_protected1_descriptor(domain_sid, name_map=None):
if name_map is None:
name_map = {}
sddl = "D:AI" \
"(A;;RPLCLORC;;;AU)" \
"(A;;RPWPCRCCLCLORCWOWDSW;;;EA)" \
@ -120,7 +138,10 @@ def get_config_delete_protected1_descriptor(domain_sid, name_map={}):
return sddl2binary(sddl, domain_sid, name_map)
def get_config_delete_protected1wd_descriptor(domain_sid, name_map={}):
def get_config_delete_protected1wd_descriptor(domain_sid, name_map=None):
if name_map is None:
name_map = {}
sddl = "D:AI" \
"(A;;RPLCLORC;;;WD)" \
"(A;;RPWPCRCCLCLORCWOWDSW;;;EA)" \
@ -128,7 +149,10 @@ def get_config_delete_protected1wd_descriptor(domain_sid, name_map={}):
return sddl2binary(sddl, domain_sid, name_map)
def get_config_delete_protected2_descriptor(domain_sid, name_map={}):
def get_config_delete_protected2_descriptor(domain_sid, name_map=None):
if name_map is None:
name_map = {}
sddl = "D:AI" \
"(A;;RPLCLORC;;;AU)" \
"(A;;RPWPCRCCDCLCLORCWOWDSW;;;EA)" \
@ -136,7 +160,10 @@ def get_config_delete_protected2_descriptor(domain_sid, name_map={}):
return sddl2binary(sddl, domain_sid, name_map)
def get_domain_descriptor(domain_sid, name_map={}):
def get_domain_descriptor(domain_sid, name_map=None):
if name_map is None:
name_map = {}
sddl = "O:BAG:BAD:AI(OA;CIIO;RP;4c164200-20c0-11d0-a768-00aa006e0529;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)" \
"(OA;CIIO;RP;4c164200-20c0-11d0-a768-00aa006e0529;bf967aba-0de6-11d0-a285-00aa003049e2;RU)" \
"(OA;CIIO;RP;5f202010-79a5-11d0-9020-00c04fc2d4cf;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)" \
@ -189,7 +216,10 @@ def get_domain_descriptor(domain_sid, name_map={}):
return sddl2binary(sddl, domain_sid, name_map)
def get_domain_infrastructure_descriptor(domain_sid, name_map={}):
def get_domain_infrastructure_descriptor(domain_sid, name_map=None):
if name_map is None:
name_map = {}
sddl = "D:" \
"(A;;RPLCLORC;;;AU)" \
"(A;;RPWPCRCCLCLORCWOWDSW;;;DA)" \
@ -199,7 +229,10 @@ def get_domain_infrastructure_descriptor(domain_sid, name_map={}):
return sddl2binary(sddl, domain_sid, name_map)
def get_domain_builtin_descriptor(domain_sid, name_map={}):
def get_domain_builtin_descriptor(domain_sid, name_map=None):
if name_map is None:
name_map = {}
sddl = "D:" \
"(OA;CIIO;RP;4c164200-20c0-11d0-a768-00aa006e0529;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)" \
"(OA;CIIO;RP;4c164200-20c0-11d0-a768-00aa006e0529;bf967aba-0de6-11d0-a285-00aa003049e2;RU)" \
@ -256,7 +289,10 @@ def get_domain_builtin_descriptor(domain_sid, name_map={}):
return sddl2binary(sddl, domain_sid, name_map)
def get_domain_computers_descriptor(domain_sid, name_map={}):
def get_domain_computers_descriptor(domain_sid, name_map=None):
if name_map is None:
name_map = {}
sddl = "D:" \
"(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)" \
"(A;;RPWPCRCCDCLCLORCWOWDSW;;;DA)" \
@ -270,7 +306,10 @@ def get_domain_computers_descriptor(domain_sid, name_map={}):
return sddl2binary(sddl, domain_sid, name_map)
def get_domain_users_descriptor(domain_sid, name_map={}):
def get_domain_users_descriptor(domain_sid, name_map=None):
if name_map is None:
name_map = {}
sddl = "D:" \
"(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)" \
"(A;;RPWPCRCCDCLCLORCWOWDSW;;;DA)" \
@ -283,7 +322,10 @@ def get_domain_users_descriptor(domain_sid, name_map={}):
return sddl2binary(sddl, domain_sid, name_map)
def get_managed_service_accounts_descriptor(domain_sid, name_map={}):
def get_managed_service_accounts_descriptor(domain_sid, name_map=None):
if name_map is None:
name_map = {}
sddl = "D:" \
"(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)" \
"(A;;RPWPCRCCDCLCLORCWOWDSW;;;DA)" \
@ -295,7 +337,10 @@ def get_managed_service_accounts_descriptor(domain_sid, name_map={}):
return sddl2binary(sddl, domain_sid, name_map)
def get_domain_controllers_descriptor(domain_sid, name_map={}):
def get_domain_controllers_descriptor(domain_sid, name_map=None):
if name_map is None:
name_map = {}
sddl = "D:" \
"(A;;RPLCLORC;;;AU)" \
"(A;;RPWPCRCCLCLORCWOWDSW;;;DA)" \
@ -307,7 +352,10 @@ def get_domain_controllers_descriptor(domain_sid, name_map={}):
return sddl2binary(sddl, domain_sid, name_map)
def get_domain_delete_protected1_descriptor(domain_sid, name_map={}):
def get_domain_delete_protected1_descriptor(domain_sid, name_map=None):
if name_map is None:
name_map = {}
sddl = "D:AI" \
"(A;;RPLCLORC;;;AU)" \
"(A;;RPWPCRCCLCLORCWOWDSW;;;DA)" \
@ -315,7 +363,10 @@ def get_domain_delete_protected1_descriptor(domain_sid, name_map={}):
return sddl2binary(sddl, domain_sid, name_map)
def get_domain_delete_protected2_descriptor(domain_sid, name_map={}):
def get_domain_delete_protected2_descriptor(domain_sid, name_map=None):
if name_map is None:
name_map = {}
sddl = "D:AI" \
"(A;;RPLCLORC;;;AU)" \
"(A;;RPWPCRCCDCLCLORCWOWDSW;;;DA)" \
@ -323,7 +374,10 @@ def get_domain_delete_protected2_descriptor(domain_sid, name_map={}):
return sddl2binary(sddl, domain_sid, name_map)
def get_dns_partition_descriptor(domain_sid, name_map={}):
def get_dns_partition_descriptor(domain_sid, name_map=None):
if name_map is None:
name_map = {}
sddl = "O:SYG:BAD:AI" \
"(OA;CIIO;RP;4c164200-20c0-11d0-a768-00aa006e0529;4828cc14-1437-45bc-9b07-ad6f015e5f28;RU)" \
"(OA;CIIO;RP;4c164200-20c0-11d0-a768-00aa006e0529;bf967aba-0de6-11d0-a285-00aa003049e2;RU)" \
@ -378,14 +432,20 @@ def get_dns_partition_descriptor(domain_sid, name_map={}):
return sddl2binary(sddl, domain_sid, name_map)
def get_dns_forest_microsoft_dns_descriptor(domain_sid, name_map={}):
def get_dns_forest_microsoft_dns_descriptor(domain_sid, name_map=None):
if name_map is None:
name_map = {}
sddl = "O:SYG:SYD:AI" \
"(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)" \
"(A;CI;RPWPCRCCDCLCRCWOWDSDDTSW;;;ED)"
return sddl2binary(sddl, domain_sid, name_map)
def get_dns_domain_microsoft_dns_descriptor(domain_sid, name_map={}):
def get_dns_domain_microsoft_dns_descriptor(domain_sid, name_map=None):
if name_map is None:
name_map = {}
sddl = "O:SYG:SYD:AI" \
"(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;DA)" \
"(A;CI;RPWPCRCCDCLCRCWOWDSDDTSW;;;DnsAdmins)" \
@ -394,7 +454,10 @@ def get_dns_domain_microsoft_dns_descriptor(domain_sid, name_map={}):
return sddl2binary(sddl, domain_sid, name_map)
def get_paritions_crossref_subdomain_descriptor(domain_sid, name_map={}):
def get_paritions_crossref_subdomain_descriptor(domain_sid, name_map=None):
if name_map is None:
name_map = {}
sddl = "O:SubdomainAdminsG:SubdomainAdminsD:AI" \
"(A;;RPWPCRCCLCLORCWOWDSW;;;SubdomainAdmins)" \
"(A;;RPLCLORC;;;AU)" \

View File

@ -1188,7 +1188,9 @@ class TrafficModel(object):
self.cumulative_duration = 0.0
self.packet_rate = [0, 1]
def learn(self, conversations, dns_opcounts={}):
def learn(self, conversations, dns_opcounts=None):
if dns_opcounts is None:
dns_opcounts = {}
prev = 0.0
cum_duration = 0.0
key = (NON_PACKET,) * (self.n - 1)

View File

@ -161,7 +161,9 @@ def fetch_certification_authorities(ldb):
result.append(data)
return result
def fetch_template_attrs(ldb, name, attrs=['msPKI-Minimal-Key-Size']):
def fetch_template_attrs(ldb, name, attrs=None):
if attrs is None:
attrs = ['msPKI-Minimal-Key-Size']
basedn = ldb.get_default_basedn()
dn = 'CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,%s' % basedn
expr = '(cn=%s)' % name

View File

@ -475,7 +475,7 @@ class gp_applier(object):
'''
pass
def clean(self, guid, keep=[], remove=[], **kwargs):
def clean(self, guid, keep=None, remove=None, **kwargs):
'''Cleanup old removed attributes
keep - A list of attributes to keep
remove - A single attribute to remove, or a list of attributes to
@ -487,6 +487,11 @@ class gp_applier(object):
'''
# Clean syntax is, either provide a single remove attribute,
# or a list of either removal attributes or keep attributes.
if keep is None:
keep = []
if remove is None:
remove = []
if type(remove) != list:
value = self.cache_get_attribute_value(guid, remove)
if value is not None:

View File

@ -42,7 +42,9 @@ class slogm(object):
'''
Structured log message class
'''
def __init__(self, message, kwargs=dict()):
def __init__(self, message, kwargs=None):
if kwargs is None:
kwargs = {}
self.message = message
self.kwargs = kwargs
if not isinstance(self.kwargs, dict):
@ -64,35 +66,47 @@ def message_with_code(mtype, message):
class log(object):
@staticmethod
def info(message, data={}):
def info(message, data=None):
if data is None:
data = {}
msg = message_with_code('I', message)
logger.info(slogm(msg, data))
return msg
@staticmethod
def warning(message, data={}):
def warning(message, data=None):
if data is None:
data = {}
msg = message_with_code('W', message)
logger.warning(slogm(msg, data))
return msg
@staticmethod
def warn(message, data={}):
def warn(message, data=None):
if data is None:
data = {}
return log.warning(message, data)
@staticmethod
def error(message, data={}):
def error(message, data=None):
if data is None:
data = {}
msg = message_with_code('E', message)
logger.error(slogm(msg, data))
return msg
@staticmethod
def fatal(message, data={}):
def fatal(message, data=None):
if data is None:
data = {}
msg = message_with_code('F', message)
logger.fatal(slogm(msg, data))
return msg
@staticmethod
def debug(message, data={}):
def debug(message, data=None):
if data is None:
data = {}
msg = message_with_code('D', message)
logger.debug(slogm(msg, data))
return msg

View File

@ -133,7 +133,7 @@ def shorten_vertex_names(vertices, suffix=',...', aggressive=False):
return vmap, replacements
def compile_graph_key(key_items, nodes_above=[], elisions=None,
def compile_graph_key(key_items, nodes_above=None, elisions=None,
prefix='key_', width=2):
"""Generate a dot file snippet that acts as a legend for a graph.
@ -148,6 +148,8 @@ def compile_graph_key(key_items, nodes_above=[], elisions=None,
(True) or edge (False). Style is a dot style string for the edge
or vertex. label is the text associated with the key item.
"""
if nodes_above is None:
nodes_above = []
edge_lines = []
edge_names = []
vertex_lines = []

View File

@ -96,7 +96,10 @@ class cmd_dbcheck(Command):
quick_membership_checks=False,
reset_well_known_acls=False,
selftest_check_expired_tombstones=False,
yes_rules=[]):
yes_rules=None):
if yes_rules is None:
yes_rules = []
lp = sambaopts.get_loadparm()

View File

@ -111,7 +111,10 @@ class DnsConnWrapper:
"DnssrvUpdateRecord2"}:
return attr
def f(*args, messages={}):
def f(*args, messages=None):
if messages is None:
messages = {}
try:
return attr(*args)
except WERRORError as e:

View File

@ -3272,9 +3272,34 @@ class cmd_domain_trust_namespaces(DomainTrustCommand):
def run(self, domain=None, sambaopts=None, localdcopts=None, versionopts=None,
refresh=None, enable_all=False,
enable_tln=[], disable_tln=[], add_tln_ex=[], delete_tln_ex=[],
enable_sid_str=[], disable_sid_str=[], enable_nb=[], disable_nb=[],
add_upn=[], delete_upn=[], add_spn=[], delete_spn=[]):
enable_tln=None, disable_tln=None, add_tln_ex=None, delete_tln_ex=None,
enable_sid_str=None, disable_sid_str=None, enable_nb=None, disable_nb=None,
add_upn=None, delete_upn=None, add_spn=None, delete_spn=None):
if enable_tln is None:
enable_tln = []
if disable_tln is None:
disable_tln = []
if add_tln_ex is None:
add_tln_ex = []
if delete_tln_ex is None:
delete_tln_ex = []
if enable_sid_str is None:
enable_sid_str = []
if disable_sid_str is None:
disable_sid_str = []
if enable_nb is None:
enable_nb = []
if disable_nb is None:
disable_nb = []
if add_upn is None:
add_upn = []
if delete_upn is None:
delete_upn = []
if add_spn is None:
add_spn = []
if delete_spn is None:
delete_spn = []
require_update = False

View File

@ -761,9 +761,13 @@ class cmd_load(GPOCommand):
]
def run(self, gpo, H=None, content=None,
machine_exts=['{35378EAC-683F-11D2-A89A-00C04FBBCFA2}'],
user_exts=['{35378EAC-683F-11D2-A89A-00C04FBBCFA2}'],
machine_exts=None,
user_exts=None,
replace=False, sambaopts=None, credopts=None, versionopts=None):
if machine_exts is None:
machine_exts = ['{35378EAC-683F-11D2-A89A-00C04FBBCFA2}']
if user_exts is None:
user_exts = ['{35378EAC-683F-11D2-A89A-00C04FBBCFA2}']
if content is None:
policy_defs = json.loads(sys.stdin.read())
elif os.path.exists(content):
@ -848,8 +852,12 @@ class cmd_remove(GPOCommand):
help="A user extension name to remove from gPCUserExtensionNames")
]
def run(self, gpo, H=None, content=None, machine_exts=[], user_exts=[],
def run(self, gpo, H=None, content=None, machine_exts=None, user_exts=None,
sambaopts=None, credopts=None, versionopts=None):
if machine_exts is None:
machine_exts = []
if user_exts is None:
user_exts = []
if content is None:
policy_defs = json.loads(sys.stdin.read())
elif os.path.exists(content):

View File

@ -42,7 +42,7 @@ def setup_path(file):
return os.path.join(setup_dir(), file)
def setup_add_ldif(ldb, ldif_path, subst_vars=None, controls=["relax:0"]):
def setup_add_ldif(ldb, ldif_path, subst_vars=None, controls=None):
"""Setup a ldb in the private dir.
:param ldb: LDB file to import data into
@ -50,18 +50,22 @@ def setup_add_ldif(ldb, ldif_path, subst_vars=None, controls=["relax:0"]):
:param subst_vars: Optional variables to subsitute in LDIF.
:param nocontrols: Optional list of controls, can be None for no controls
"""
if controls is None:
controls = ["relax:0"]
assert isinstance(ldif_path, str)
data = read_and_sub_file(ldif_path, subst_vars)
ldb.add_ldif(data, controls)
def setup_modify_ldif(ldb, ldif_path, subst_vars=None, controls=["relax:0"]):
def setup_modify_ldif(ldb, ldif_path, subst_vars=None, controls=None):
"""Modify a ldb in the private dir.
:param ldb: LDB object.
:param ldif_path: LDIF file path.
:param subst_vars: Optional dictionary with substitution variables.
"""
if controls is None:
controls = ["relax:0"]
data = read_and_sub_file(ldif_path, subst_vars)
ldb.modify_ldif(data, controls)

View File

@ -361,7 +361,7 @@ lockoutTime: 0
def add_remove_group_members(self, groupname, members,
add_members_operation=True,
member_types=[ 'user', 'group', 'computer' ],
member_types=None,
member_base_dn=None):
"""Adds or removes group members
@ -370,6 +370,8 @@ lockoutTime: 0
:param add_members_operation: Defines if its an add or remove
operation
"""
if member_types is None:
member_types = ['user', 'group', 'computer']
groupfilter = "(&(sAMAccountName=%s)(objectCategory=%s,%s))" % (
ldb.binary_encode(groupname), "CN=Group,CN=Schema,CN=Configuration", self.domain_dn())
@ -473,10 +475,12 @@ member: %s
msg.add(el)
def fullname_from_names(self, given_name=None, initials=None, surname=None,
old_attrs={}, fallback_default=""):
old_attrs=None, fallback_default=""):
"""Prepares new combined fullname, using the name parts.
Used for things like displayName or cn.
Use the original name values, if no new one is specified."""
if old_attrs is None:
old_attrs = {}
attrs = {"givenName": given_name,
"initials": initials,

View File

@ -33,7 +33,10 @@ from samba import dsdb
from ldb import SCOPE_SUBTREE, SCOPE_ONELEVEL
def get_schema_descriptor(domain_sid, name_map={}):
def get_schema_descriptor(domain_sid, name_map=None):
if name_map is None:
name_map = {}
sddl = "O:SAG:SAD:AI(OA;;CR;e12b56b6-0a95-11d1-adbb-00c04fd8d5cd;;SA)" \
"(OA;;CR;1131f6aa-9c07-11d1-f79f-00c04fc2dcd2;;ED)" \
"(OA;;CR;1131f6ab-9c07-11d1-f79f-00c04fc2dcd2;;ED)" \

View File

@ -77,8 +77,10 @@ class SDUtils(object):
desc_sddl = desc_sddl + ace
self.modify_sd_on_dn(object_dn, desc_sddl, ["show_deleted:1"])
def get_sd_as_sddl(self, object_dn, controls=[]):
def get_sd_as_sddl(self, object_dn, controls=None):
"""Return object nTSecutiryDescriptor in SDDL format
"""
if controls is None:
controls = []
desc = self.read_sd_on_dn(object_dn, controls + ["show_deleted:1"])
return desc.as_sddl(self.domain_sid)

View File

@ -257,8 +257,10 @@ class LdbTestCase(TestCase):
self.filename = self.tempfile.name
self.ldb = samba.Ldb(self.filename)
def set_modules(self, modules=[]):
def set_modules(self, modules=None):
"""Change the modules for this Ldb."""
if modules is None:
modules = []
m = ldb.Message()
m.dn = ldb.Dn(self.ldb, "@MODULES")
m["@LIST"] = ",".join(modules)

View File

@ -842,9 +842,11 @@ class RawDCERPCTest(TestCase):
rpc_vers_minor=0,
pfc_flags=(samba.dcerpc.dcerpc.DCERPC_PFC_FLAG_FIRST |
samba.dcerpc.dcerpc.DCERPC_PFC_FLAG_LAST),
drep=[samba.dcerpc.dcerpc.DCERPC_DREP_LE, 0, 0, 0],
drep=None,
ndr_print=None, hexdump=None):
if drep is None:
drep = [samba.dcerpc.dcerpc.DCERPC_DREP_LE, 0, 0, 0]
if getattr(payload, 'auth_info', None):
ai = payload.auth_info
else:
@ -950,9 +952,11 @@ class RawDCERPCTest(TestCase):
rpc_vers_minor=0,
pfc_flags=(samba.dcerpc.dcerpc.DCERPC_PFC_FLAG_FIRST |
samba.dcerpc.dcerpc.DCERPC_PFC_FLAG_LAST),
drep=[samba.dcerpc.dcerpc.DCERPC_DREP_LE, 0, 0, 0],
drep=None,
auth_length=None):
if drep is None:
drep = [samba.dcerpc.dcerpc.DCERPC_DREP_LE, 0, 0, 0]
self.assertIsNotNone(p, "No valid pdu")
if getattr(p.u, 'auth_info', None):
@ -984,10 +988,12 @@ class RawDCERPCTest(TestCase):
max_xmit_frag=None,
max_recv_frag=None,
assoc_group_id=0,
ctx_list=[],
ctx_list=None,
auth_info=b"",
ndr_print=None, hexdump=None):
if ctx_list is None:
ctx_list = []
if max_xmit_frag is None:
max_xmit_frag=self.max_xmit_frag
if max_recv_frag is None:
@ -1015,10 +1021,12 @@ class RawDCERPCTest(TestCase):
max_xmit_frag=None,
max_recv_frag=None,
assoc_group_id=0,
ctx_list=[],
ctx_list=None,
auth_info=b"",
ndr_print=None, hexdump=None):
if ctx_list is None:
ctx_list = []
if max_xmit_frag is None:
max_xmit_frag=self.max_xmit_frag
if max_recv_frag is None:

View File

@ -1221,7 +1221,9 @@ class TestZones(DNSTest):
Aging=int(bool(enable)),
AllowUpdate=dnsp.DNS_ZONE_UPDATE_UNSECURE)
def test_set_aging(self, enable=True, name='agingtest', txt=['test txt']):
def test_set_aging(self, enable=True, name='agingtest', txt=None):
if txt is None:
txt = ['test txt']
self.set_aging(enable=True)
settings = self.ldap_get_zone_settings()
self.assertTrue(settings['aging_state'] is not None)

View File

@ -152,7 +152,9 @@ class DomainBackupOfflineCmp(BlackboxTestCase):
self.ldapcmp(self.prov_dir, self.extract_dir)
def ldapcmp(self, prov_dir, ex_dir, args=[]):
def ldapcmp(self, prov_dir, ex_dir, args=None):
if args is None:
args = []
sam_fn = os.path.join("private", "sam.ldb")
url1 = "tdb://" + os.path.join(os.path.realpath(prov_dir), sam_fn)
url2 = "tdb://" + os.path.join(os.path.realpath(ex_dir), sam_fn)

View File

@ -94,7 +94,9 @@ class SiteCoverageTests(samba.tests.TestCase):
self.sites[dn] = name
return dn, name.lower()
def _add_site_link(self, name, links=[], cost=100):
def _add_site_link(self, name, links=None, cost=100):
if links is None:
links = []
dn = "CN={0},CN=IP,CN=Inter-Site Transports,CN=Sites,{1}".format(
name, self.samdb.get_config_basedn()
)

View File

@ -277,9 +277,11 @@ class ComputerCmdTestCase(SambaToolCmdTest):
self.assertCmdSuccess(result, out, err,
"Failed to delete ou '%s'" % parentou["name"])
def _randomComputer(self, base={}):
def _randomComputer(self, base=None):
"""create a computer with random attribute values, you can specify base
attributes"""
if base is None:
base = {}
computer = {
"name": self.randomName(),
@ -288,9 +290,11 @@ class ComputerCmdTestCase(SambaToolCmdTest):
computer.update(base)
return computer
def _randomOU(self, base={}):
def _randomOU(self, base=None):
"""create an ou with random attribute values, you can specify base
attributes"""
if base is None:
base = {}
ou = {
"name": self.randomName(),

View File

@ -392,9 +392,11 @@ class ContactCmdTestCase(SambaToolCmdTest):
"--display-name=%s" % old_displayname)
self.assertCmdSuccess(result, out, err)
def _randomContact(self, base={}):
def _randomContact(self, base=None):
"""Create a contact with random attribute values, you can specify base
attributes"""
if base is None:
base = {}
# No name attributes are given here, because the object name will
# be made from the sn, givenName and initials attributes, if no name
@ -405,9 +407,11 @@ class ContactCmdTestCase(SambaToolCmdTest):
contact.update(base)
return contact
def _randomOU(self, base={}):
def _randomOU(self, base=None):
"""Create an ou with random attribute values, you can specify base
attributes."""
if base is None:
base = {}
ou = {
"name": self.randomName(),

View File

@ -574,11 +574,13 @@ template """
self.assertTrue("Total groups: {0}".format(total_groups) in out,
"Total groups not reported correctly")
def _random_user(self, base={}):
def _random_user(self, base=None):
'''
create a user with random attribute values, you can specify
base attributes
'''
if base is None:
base = {}
user = {
"name": self.randomName(),
"password": self.random_password(16),

View File

@ -261,10 +261,11 @@ class OUCmdTestCase(SambaToolCmdTest):
found = self.assertMatch(out, str(obj.dn),
"object '%s' not found" % obj.dn)
def _randomOU(self, base={}):
def _randomOU(self, base=None):
"""create an ou with random attribute values, you can specify base
attributes"""
if base is None:
base = {}
ou = {
"name": self.randomName(),
"description": self.randomName(count=100),

View File

@ -1100,8 +1100,10 @@ sAMAccountName: %s
self.assertCmdSuccess(result, out, err, "Error running user unlock")
self.assertEqual(err, "", "Shouldn't be any error messages")
def _randomUser(self, base={}):
def _randomUser(self, base=None):
"""create a user with random attribute values, you can specify base attributes"""
if base is None:
base = {}
user = {
"name": self.randomName(),
"password": self.random_password(16),
@ -1117,9 +1119,11 @@ sAMAccountName: %s
user.update(base)
return user
def _randomPosixUser(self, base={}):
def _randomPosixUser(self, base=None):
"""create a user with random attribute values and additional RFC2307
attributes, you can specify base attributes"""
if base is None:
base = {}
user = self._randomUser({})
user.update(base)
posixAttributes = {
@ -1135,9 +1139,11 @@ sAMAccountName: %s
user.update(base)
return user
def _randomUnixUser(self, base={}):
def _randomUnixUser(self, base=None):
"""create a user with random attribute values and additional RFC2307
attributes, you can specify base attributes"""
if base is None:
base = {}
user = self._randomUser({})
user.update(base)
posixAttributes = {

View File

@ -95,8 +95,10 @@ class UserCheckPwdTestCase(SambaToolCmdTest):
good_password,
"username")
def _randomUser(self, base={}):
def _randomUser(self, base=None):
"""create a user with random attribute values, you can specify base attributes"""
if base is None:
base = {}
user = {
"name": self.randomName(),
}

View File

@ -161,7 +161,9 @@ is_git_file = _init_git_file_finder()
def script_iterator(d=BASEDIR, cache=None,
shebang_filter=None,
filename_filter=None,
subdirs=TEST_DIRS):
subdirs=None):
if subdirs is None:
subdirs = TEST_DIRS
if not cache:
safename = re.compile(r'\W+').sub
for subdir in subdirs: