From c0d4f2462f75e0bc0545402b76984b4e6fcb13f1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 16 Sep 2012 14:18:51 +0200 Subject: s4-python: Formatting fixes, break lines. Autobuild-User(master): Jelmer Vernooij Autobuild-Date(master): Sun Sep 16 15:58:04 CEST 2012 on sn-devel-104 --- source4/scripting/python/samba/idmap.py | 2 - source4/scripting/python/samba/join.py | 51 +++++++++++----------- source4/scripting/python/samba/samba3/__init__.py | 5 +++ source4/scripting/python/samba/samdb.py | 1 - source4/scripting/python/samba/sd_utils.py | 9 ++-- source4/scripting/python/samba/tests/dns.py | 5 ++- source4/scripting/python/samba/tests/gensec.py | 2 +- source4/scripting/python/samba/tests/hostconfig.py | 4 +- source4/scripting/python/samba/tests/messaging.py | 2 +- source4/scripting/python/samba/tests/posixacl.py | 6 +-- source4/scripting/python/samba/tests/provision.py | 12 +++-- source4/scripting/python/samba/tests/registry.py | 2 +- source4/scripting/python/samba/tests/samba3.py | 1 + source4/scripting/python/samba/upgrade.py | 17 +++++--- 14 files changed, 69 insertions(+), 50 deletions(-) (limited to 'source4/scripting') diff --git a/source4/scripting/python/samba/idmap.py b/source4/scripting/python/samba/idmap.py index b651b2053d..0cb729fbc2 100644 --- a/source4/scripting/python/samba/idmap.py +++ b/source4/scripting/python/samba/idmap.py @@ -96,5 +96,3 @@ cn: %s """ % (sid, unixid, sid, type_string, sid) self.add(self.parse_ldif(mod).next()[1]) - - diff --git a/source4/scripting/python/samba/join.py b/source4/scripting/python/samba/join.py index ac822fb15b..5ddc5db1ad 100644 --- a/source4/scripting/python/samba/join.py +++ b/source4/scripting/python/samba/join.py @@ -44,7 +44,7 @@ class DCJoinException(Exception): class dc_join(object): - '''perform a DC join''' + """Perform a DC join.""" def __init__(ctx, server=None, creds=None, lp=None, site=None, netbios_name=None, targetdir=None, domain=None, @@ -166,7 +166,7 @@ class dc_join(object): pass def cleanup_old_join(ctx): - '''remove any DNs from a previous join''' + """Remove any DNs from a previous join.""" try: # find the krbtgt link print("checking sAMAccountName") @@ -219,7 +219,7 @@ class dc_join(object): pass def promote_possible(ctx): - '''confirm that the account is just a bare NT4 BDC or a member server, so can be safely promoted''' + """confirm that the account is just a bare NT4 BDC or a member server, so can be safely promoted""" if ctx.subdomain: # This shouldn't happen raise Exception("Can not promote into a subdomain") @@ -233,12 +233,12 @@ class dc_join(object): raise Exception("Account '%s' appears to be an active DC, use 'samba-tool domain join' if you must re-create this account" % ctx.samname) if (int(res[0]["userAccountControl"][0]) & (samba.dsdb.UF_WORKSTATION_TRUST_ACCOUNT|samba.dsdb.UF_SERVER_TRUST_ACCOUNT) == 0): raise Exception("Account %s is not a domain member or a bare NT4 BDC, use 'samba-tool domain join' instead'" % ctx.samname) - + ctx.promote_from_dn = res[0].dn def find_dc(ctx, domain): - '''find a writeable DC for the given domain''' + """find a writeable DC for the given domain""" try: ctx.cldap_ret = ctx.net.finddc(domain=domain, flags=nbt.NBT_SERVER_LDAP | nbt.NBT_SERVER_DS | nbt.NBT_SERVER_WRITABLE) except Exception: @@ -484,7 +484,7 @@ class dc_join(object): rec["msDS-NeverRevealGroup"] = ctx.never_reveal_sid elif ctx.promote_existing: rec["msDS-NeverRevealGroup"] = [] - + if ctx.reveal_sid: rec["msDS-RevealOnDemandGroup"] = ctx.reveal_sid elif ctx.promote_existing: @@ -579,7 +579,7 @@ class dc_join(object): ctx.samdb.modify(m) def join_add_objects2(ctx): - '''add the various objects needed for the join, for subdomains post replication''' + """add the various objects needed for the join, for subdomains post replication""" print "Adding %s" % ctx.partition_dn # NOTE: windows sends a ntSecurityDescriptor here, we @@ -638,7 +638,7 @@ class dc_join(object): replica_flags=drsuapi.DRSUAPI_DRS_WRIT_REP) def join_provision(ctx): - '''provision the local SAM''' + """Provision the local SAM.""" print "Calling bare provision" @@ -662,7 +662,7 @@ class dc_join(object): ctx.names = presult.names def join_provision_own_domain(ctx): - '''provision the local SAM''' + """Provision the local SAM.""" # we now operate exclusively on the local database, which # we need to reopen in order to get the newly created schema @@ -697,7 +697,7 @@ class dc_join(object): print("Provision OK for domain %s" % ctx.names.dnsdomain) def join_replicate(ctx): - '''replicate the SAM''' + """Replicate the SAM.""" print "Starting replication" ctx.local_samdb.transaction_start() @@ -790,7 +790,7 @@ class dc_join(object): ctx.drsuapi.DsReplicaUpdateRefs(ctx.drsuapi_handle, 1, r) def join_finalise(ctx): - '''finalise the join, mark us synchronised and setup secrets db''' + """Finalise the join, mark us synchronised and setup secrets db.""" logger = logging.getLogger("provision") logger.addHandler(logging.StreamHandler(sys.stdout)) @@ -858,7 +858,7 @@ class dc_join(object): targetdir=ctx.targetdir) def join_setup_trusts(ctx): - '''provision the local SAM''' + """provision the local SAM.""" def arcfour_encrypt(key, data): from Crypto.Cipher import ARC4 @@ -988,7 +988,7 @@ class dc_join(object): ctx.promote_possible() else: ctx.cleanup_old_join() - + try: ctx.join_add_objects() ctx.join_provision() @@ -1008,7 +1008,7 @@ def join_RODC(server=None, creds=None, lp=None, site=None, netbios_name=None, targetdir=None, domain=None, domain_critical_only=False, machinepass=None, use_ntvfs=False, dns_backend=None, promote_existing=False): - """join as a RODC""" + """Join as a RODC.""" ctx = dc_join(server, creds, lp, site, netbios_name, targetdir, domain, machinepass, use_ntvfs, dns_backend, promote_existing) @@ -1022,11 +1022,12 @@ def join_RODC(server=None, creds=None, lp=None, site=None, netbios_name=None, ctx.krbtgt_dn = "CN=krbtgt_%s,CN=Users,%s" % (ctx.myname, ctx.base_dn) # setup some defaults for accounts that should be replicated to this RODC - ctx.never_reveal_sid = [ "" % (ctx.domsid, security.DOMAIN_RID_RODC_DENY), - "" % security.SID_BUILTIN_ADMINISTRATORS, - "" % security.SID_BUILTIN_SERVER_OPERATORS, - "" % security.SID_BUILTIN_BACKUP_OPERATORS, - "" % security.SID_BUILTIN_ACCOUNT_OPERATORS ] + ctx.never_reveal_sid = [ + "" % (ctx.domsid, security.DOMAIN_RID_RODC_DENY), + "" % security.SID_BUILTIN_ADMINISTRATORS, + "" % security.SID_BUILTIN_SERVER_OPERATORS, + "" % security.SID_BUILTIN_BACKUP_OPERATORS, + "" % security.SID_BUILTIN_ACCOUNT_OPERATORS] ctx.reveal_sid = "" % (ctx.domsid, security.DOMAIN_RID_RODC_ALLOW) mysid = ctx.get_mysid() @@ -1055,7 +1056,6 @@ def join_RODC(server=None, creds=None, lp=None, site=None, netbios_name=None, ctx.do_join() - print "Joined domain %s (SID %s) as an RODC" % (ctx.domain_name, ctx.domsid) @@ -1063,7 +1063,7 @@ def join_DC(server=None, creds=None, lp=None, site=None, netbios_name=None, targetdir=None, domain=None, domain_critical_only=False, machinepass=None, use_ntvfs=False, dns_backend=None, promote_existing=False): - """join as a DC""" + """Join as a DC.""" ctx = dc_join(server, creds, lp, site, netbios_name, targetdir, domain, machinepass, use_ntvfs, dns_backend, promote_existing) @@ -1090,10 +1090,11 @@ def join_DC(server=None, creds=None, lp=None, site=None, netbios_name=None, ctx.do_join() print "Joined domain %s (SID %s) as a DC" % (ctx.domain_name, ctx.domsid) -def join_subdomain(server=None, creds=None, lp=None, site=None, netbios_name=None, - targetdir=None, parent_domain=None, dnsdomain=None, netbios_domain=None, - machinepass=None, use_ntvfs=False, dns_backend=None): - """join as a DC""" +def join_subdomain(server=None, creds=None, lp=None, site=None, + netbios_name=None, targetdir=None, parent_domain=None, dnsdomain=None, + netbios_domain=None, machinepass=None, use_ntvfs=False, + dns_backend=None): + """Join as a DC.""" ctx = dc_join(server, creds, lp, site, netbios_name, targetdir, parent_domain, machinepass, use_ntvfs, dns_backend) ctx.subdomain = True diff --git a/source4/scripting/python/samba/samba3/__init__.py b/source4/scripting/python/samba/samba3/__init__.py index 14db90ac51..acccff4e29 100644 --- a/source4/scripting/python/samba/samba3/__init__.py +++ b/source4/scripting/python/samba/samba3/__init__.py @@ -137,6 +137,7 @@ IDMAP_VERSION_V2 = 2 class IdmapDatabase(TdbDatabase): """Samba 3 ID map database reader.""" + def _check_version(self): assert fetch_int32(self.tdb, "IDMAP_VERSION\0") == IDMAP_VERSION_V2 @@ -199,6 +200,7 @@ class IdmapDatabase(TdbDatabase): class SecretsDatabase(TdbDatabase): """Samba 3 Secrets database reader.""" + def get_auth_password(self): return self.tdb.get("SECRETS/AUTH_PASSWORD") @@ -261,8 +263,10 @@ class SecretsDatabase(TdbDatabase): SHARE_DATABASE_VERSION_V1 = 1 SHARE_DATABASE_VERSION_V2 = 2 + class ShareInfoDatabase(TdbDatabase): """Samba 3 Share Info database reader.""" + def _check_version(self): assert fetch_int32(self.tdb, "INFO/version\0") in (SHARE_DATABASE_VERSION_V1, SHARE_DATABASE_VERSION_V2) @@ -355,6 +359,7 @@ class WinsDatabase(object): class Samba3(object): """Samba 3 configuration and state data reader.""" + def __init__(self, smbconfpath, s3_lp_ctx=None): """Open the configuration and data for a Samba 3 installation. diff --git a/source4/scripting/python/samba/samdb.py b/source4/scripting/python/samba/samdb.py index 7db1b00754..d83e0a6f7c 100644 --- a/source4/scripting/python/samba/samdb.py +++ b/source4/scripting/python/samba/samdb.py @@ -431,7 +431,6 @@ member: %s else: self.transaction_commit() - def setpassword(self, search_filter, password, force_change_at_next_login=False, username=None): """Sets the password for a user diff --git a/source4/scripting/python/samba/sd_utils.py b/source4/scripting/python/samba/sd_utils.py index 61e5980a4f..ded9bfc192 100644 --- a/source4/scripting/python/samba/sd_utils.py +++ b/source4/scripting/python/samba/sd_utils.py @@ -26,15 +26,14 @@ from samba.dcerpc import security class SDUtils(object): - """Some utilities for manipulation of security descriptors - on objects""" + """Some utilities for manipulation of security descriptors on objects.""" def __init__(self, samdb): self.ldb = samdb self.domain_sid = security.dom_sid(self.ldb.get_domain_sid()) def modify_sd_on_dn(self, object_dn, sd, controls=None): - """ Modify security descriptor using either SDDL string + """Modify security descriptor using either SDDL string or security.descriptor object """ m = Message() @@ -61,7 +60,7 @@ class SDUtils(object): return ndr_unpack(security.dom_sid, res[0]["objectSid"][0]) def dacl_add_ace(self, object_dn, ace): - """ Adds an ACE to an objects security descriptor + """Add an ACE to an objects security descriptor """ desc = self.read_sd_on_dn(object_dn) desc_sddl = desc.as_sddl(self.domain_sid) @@ -75,7 +74,7 @@ class SDUtils(object): self.modify_sd_on_dn(object_dn, desc_sddl) def get_sd_as_sddl(self, object_dn, controls=None): - """ Return object nTSecutiryDescriptor in SDDL format + """Return object nTSecutiryDescriptor in SDDL format """ desc = self.read_sd_on_dn(object_dn, controls=controls) return desc.as_sddl(self.domain_sid) diff --git a/source4/scripting/python/samba/tests/dns.py b/source4/scripting/python/samba/tests/dns.py index 8815474061..3eee306d43 100644 --- a/source4/scripting/python/samba/tests/dns.py +++ b/source4/scripting/python/samba/tests/dns.py @@ -112,7 +112,9 @@ class DNSTest(TestCase): if s is not None: s.close() + class TestSimpleQueries(DNSTest): + def test_one_a_query(self): "create a query packet containing one query record" p = self.make_name_packet(dns.DNS_OPCODE_QUERY) @@ -240,6 +242,7 @@ class TestSimpleQueries(DNSTest): class TestDNSUpdates(DNSTest): + def test_two_updates(self): "create two update requests" p = self.make_name_packet(dns.DNS_OPCODE_UPDATE) @@ -429,7 +432,6 @@ class TestDNSUpdates(DNSTest): self.assertEquals(response.ancount, 1) self.assertEquals(response.answers[0].rdata.txt, '"This is a test" "and this is a test, too"') - def test_delete_record(self): "Test if deleting records works" p = self.make_name_packet(dns.DNS_OPCODE_UPDATE) @@ -470,6 +472,7 @@ class TestDNSUpdates(DNSTest): class TestComplexQueries(DNSTest): + def setUp(self): super(TestComplexQueries, self).setUp() p = self.make_name_packet(dns.DNS_OPCODE_UPDATE) diff --git a/source4/scripting/python/samba/tests/gensec.py b/source4/scripting/python/samba/tests/gensec.py index 02302a8e11..712f177cfc 100644 --- a/source4/scripting/python/samba/tests/gensec.py +++ b/source4/scripting/python/samba/tests/gensec.py @@ -67,7 +67,7 @@ class GensecTests(samba.tests.TestCase): client_finished = False server_finished = False server_to_client = "" - + """Run the actual call loop""" while client_finished == False and server_finished == False: if not client_finished: diff --git a/source4/scripting/python/samba/tests/hostconfig.py b/source4/scripting/python/samba/tests/hostconfig.py index 85cb1df0c1..526dc0fe4e 100644 --- a/source4/scripting/python/samba/tests/hostconfig.py +++ b/source4/scripting/python/samba/tests/hostconfig.py @@ -57,7 +57,9 @@ class ShareTests(TestCase): def test_iter(self): self.assertEquals([], list(self._get_shares({}))) self.assertEquals([], list(self._get_shares({"global":{}}))) - self.assertEquals(["bla"], list(self._get_shares({"global":{}, "bla":{}}))) + self.assertEquals( + ["bla"], + list(self._get_shares({"global":{}, "bla":{}}))) def test_len(self): shares = self._get_shares({"global": {}}) diff --git a/source4/scripting/python/samba/tests/messaging.py b/source4/scripting/python/samba/tests/messaging.py index b6c9a0abbc..fd9aa8ef82 100644 --- a/source4/scripting/python/samba/tests/messaging.py +++ b/source4/scripting/python/samba/tests/messaging.py @@ -26,7 +26,7 @@ class MessagingTests(TestCase): def get_context(self, *args, **kwargs): return Messaging(*args, **kwargs) - + def test_register(self): x = self.get_context() def callback(): diff --git a/source4/scripting/python/samba/tests/posixacl.py b/source4/scripting/python/samba/tests/posixacl.py index b323f91f1a..066cc97373 100644 --- a/source4/scripting/python/samba/tests/posixacl.py +++ b/source4/scripting/python/samba/tests/posixacl.py @@ -18,10 +18,10 @@ """Tests for the Samba3 NT -> posix ACL layer""" -from samba.ntacls import setntacl, getntacl, XattrBackendError +from samba.ntacls import setntacl, getntacl from samba.dcerpc import xattr, security, smb_acl, idmap from samba.param import LoadParm -from samba.tests import TestCase, TestSkipped +from samba.tests import TestCase from samba import provision import random import os @@ -34,7 +34,7 @@ from samba.samba3 import param as s3param # print "a_perm: %o" % entry.a_perm # print "uid: %d" % entry.uid # print "gid: %d" % entry.gid - + class PosixAclMappingTests(TestCase): def test_setntacl(self): diff --git a/source4/scripting/python/samba/tests/provision.py b/source4/scripting/python/samba/tests/provision.py index 9375f91b83..408c9883f3 100644 --- a/source4/scripting/python/samba/tests/provision.py +++ b/source4/scripting/python/samba/tests/provision.py @@ -135,9 +135,15 @@ class SanitizeServerRoleTests(TestCase): self.assertRaises(ValueError, sanitize_server_role, "foo") def test_valid(self): - self.assertEquals("standalone server", sanitize_server_role("ROLE_STANDALONE")) - self.assertEquals("standalone server", sanitize_server_role("standalone")) - self.assertEquals("active directory domain controller", sanitize_server_role("domain controller")) + self.assertEquals( + "standalone server", + sanitize_server_role("ROLE_STANDALONE")) + self.assertEquals( + "standalone server", + sanitize_server_role("standalone")) + self.assertEquals( + "active directory domain controller", + sanitize_server_role("domain controller")) class DummyLogger(object): diff --git a/source4/scripting/python/samba/tests/registry.py b/source4/scripting/python/samba/tests/registry.py index 73fe06dfb9..8016a0bb68 100644 --- a/source4/scripting/python/samba/tests/registry.py +++ b/source4/scripting/python/samba/tests/registry.py @@ -24,7 +24,7 @@ import samba.tests class HelperTests(samba.tests.TestCase): def test_predef_to_name(self): - self.assertEquals("HKEY_LOCAL_MACHINE", + self.assertEquals("HKEY_LOCAL_MACHINE", registry.get_predef_name(0x80000002)) def test_str_regtype(self): diff --git a/source4/scripting/python/samba/tests/samba3.py b/source4/scripting/python/samba/tests/samba3.py index 239a4b0dd7..d83db0f8b2 100644 --- a/source4/scripting/python/samba/tests/samba3.py +++ b/source4/scripting/python/samba/tests/samba3.py @@ -28,6 +28,7 @@ from samba.tests import TestCase, TestCaseInTempDir from samba.dcerpc.security import dom_sid import os + for p in [ "../../../../../testdata/samba3", "../../../../testdata/samba3" ]: DATADIR = os.path.join(os.path.dirname(__file__), p) if os.path.exists(DATADIR): diff --git a/source4/scripting/python/samba/upgrade.py b/source4/scripting/python/samba/upgrade.py index 6b6a188fa8..05d0dd6d88 100644 --- a/source4/scripting/python/samba/upgrade.py +++ b/source4/scripting/python/samba/upgrade.py @@ -32,7 +32,6 @@ from samba.samba3 import param as s3param from samba.dcerpc import lsa, samr, security from samba.dcerpc.security import dom_sid from samba.credentials import Credentials -from samba.auth import system_session from samba import dsdb from samba.ndr import ndr_pack from samba import unix2nttime @@ -93,7 +92,9 @@ def import_sam_policy(samdb, policy, logger): except ldb.LdbError, e: logger.warn("Could not set account policy, (%s)", str(e)) -def add_posix_attrs(logger, samdb, sid, name, nisdomain, xid_type, home=None, shell=None, pgid=None): + +def add_posix_attrs(logger, samdb, sid, name, nisdomain, xid_type, home=None, + shell=None, pgid=None): """Add posix attributes for the user/group :param samdb: Samba4 sam.ldb database @@ -156,6 +157,7 @@ def add_ad_posix_idmap_entry(samdb, sid, xid, xid_type, logger): 'Could not modify AD idmap entry for sid=%s, id=%s, type=%s (%s)', str(sid), str(xid), xid_type, str(e)) + def add_idmap_entry(idmapdb, sid, xid, xid_type, logger): """Create idmap entry @@ -545,8 +547,9 @@ def get_posix_attr_from_ldap_backend(logger, ldb_object, base_dn, user, attr): logger.warning("LDAP entry for user %s contains more than one %s", user, attr) return None -def upgrade_from_samba3(samba3, logger, targetdir, session_info=None, useeadb=False, dns_backend=None, - use_ntvfs=False): + +def upgrade_from_samba3(samba3, logger, targetdir, session_info=None, + useeadb=False, dns_backend=None, use_ntvfs=False): """Upgrade from samba3 database to samba4 AD database :param samba3: samba3 object @@ -904,8 +907,10 @@ Please fix this account before attempting to upgrade again logger.info("Administrator password has been set to password of user '%s'", admin_user) if result.server_role == "active directory domain controller": - setsysvolacl(result.samdb, result.paths.netlogon, result.paths.sysvol, result.paths.root_uid, result.paths.wheel_gid, - security.dom_sid(result.domainsid), result.names.dnsdomain, result.names.domaindn, result.lp, use_ntvfs) + setsysvolacl(result.samdb, result.paths.netlogon, result.paths.sysvol, + result.paths.root_uid, result.paths.wheel_gid, + security.dom_sid(result.domainsid), result.names.dnsdomain, + result.names.domaindn, result.lp, use_ntvfs) # FIXME: import_registry(registry.Registry(), samba3.get_registry()) # FIXME: shares -- cgit