[SCM] Samba Shared Repository - branch master updated

Kamen Mazdrashki kamenim at samba.org
Sat Oct 2 17:06:01 MDT 2010


The branch, master has been updated
       via  197a151 s4-ldapcmp.py: Don't guess credentials for second Credentials object
       via  da0f3bd s4-getopt.py: Make Anonymous creds when no credentials
       via  d385d9a s4-test-fsmo.py: Implement kind of busy-wait for role transfer
       via  657d4d8 s4-test-dsdb_schema_info.py: Get rid of global module variables
       via  83a1515 s4-test-dsdb_schema_info.py: Simplify connection SamDB
       via  2a23f0d s4-test-fsmo.py: Use common implementation for env_get_var_value()
       via  c05180c s4-test-delete_object.py: Use common implementation for env_get_var_value()
       via  302e1d2 s4-python-test: Common implementation for getting environment variable value
       via  6546127 s4-python-samba: Remove trailing ';'s
       via  6bc7c01 s4-test-fsmo.py: Use common implementation for connect_samdb()
       via  98e4d27 s4-test-delete_object.py: Use common implementation for connect_samdb()
       via  7acbb73 s4-python-test: Implement global connect_samdb() function
       via  46ac1c3 s4-samba.samdb: Fix masking names from outer context
       via  0cb476f s4-python-samba: 'file' is a built-in
       via  edfb8c6 s4-samba.samdb: Fix leading indention and trailing ';'
       via  e9620c5 s4-python-samba: Fix few cosmetics
      from  24f1893 s3: Attempt to fix the non-ads build

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 197a1514d62494cc8b862d169c841a26e04b8925
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Fri Oct 1 03:30:50 2010 +0300

    s4-ldapcmp.py: Don't guess credentials for second Credentials object
    
    This allow us to fallback to first credentials given.
    
    Autobuild-User: Kamen Mazdrashki <kamenim at samba.org>
    Autobuild-Date: Sat Oct  2 23:05:20 UTC 2010 on sn-devel-104

commit da0f3bd2291e561fd8b6f0fafd4bf6cb52dad722
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Fri Oct 1 03:29:33 2010 +0300

    s4-getopt.py: Make Anonymous creds when no credentials
    
    are supplied on command line and caller doesn't want us
    to guess credentials from environment

commit d385d9a3178c6cc705f7cccf6688ba9b60571e96
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Thu Sep 30 21:42:17 2010 +0300

    s4-test-fsmo.py: Implement kind of busy-wait for role transfer
    
    This allows us not to hard code timeout we are going to wait for
    before failing the test - if DCs are not very busy, we won't wait
    at all (speeds up 'make test' by a minute also)
    
    Maximum timeout to wait for is set to 20 secs currently,
    which should be enough even for slow machines and tested
    DCs being under load

commit 657d4d88124f3a6b48e543abadd37948c426dca9
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Wed Sep 29 15:56:23 2010 +0300

    s4-test-dsdb_schema_info.py: Get rid of global module variables

commit 83a15155ebb3399117ce0da7d4e0faa1b72199f9
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Wed Sep 29 15:51:11 2010 +0300

    s4-test-dsdb_schema_info.py: Simplify connection SamDB
    
    by using samba.tests.connect_samdb() helper

commit 2a23f0d524298c2cc78f36a2f5b45560ec36747f
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Wed Sep 29 16:00:43 2010 +0300

    s4-test-fsmo.py: Use common implementation for env_get_var_value()

commit c05180caa78eac0beb26c6791afd8642a97853e6
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Wed Sep 29 16:00:04 2010 +0300

    s4-test-delete_object.py: Use common implementation for env_get_var_value()

commit 302e1d29d82570ec32fd066bb9038649a67d148b
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Wed Sep 29 14:53:12 2010 +0300

    s4-python-test: Common implementation for getting environment variable value
    
    Unit-test based python tests require certain input parameters
    to be set in environment, otherwise they can't be run

commit 6546127b6420361469112325d3ec2e2d19ed864c
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Wed Sep 29 04:31:02 2010 +0300

    s4-python-samba: Remove trailing ';'s

commit 6bc7c015fb510756dce4ada4831ca094a5d07a61
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Wed Sep 29 03:02:11 2010 +0300

    s4-test-fsmo.py: Use common implementation for connect_samdb()
    
    Connections are restricted to LDAP only (remote),
    as this test can't be run against local LDBs

commit 98e4d2702aa98d0cf89d3240276f2b5d6e841d45
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Wed Sep 29 03:00:18 2010 +0300

    s4-test-delete_object.py: Use common implementation for connect_samdb()
    
    Connections are restricted to LDAP only (remote),
    as this test can't be run against local LDBs

commit 7acbb7346fdf96f25b3c465dd070b86694beb12b
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Wed Sep 29 02:58:23 2010 +0300

    s4-python-test: Implement global connect_samdb() function
    
    This helper makes proper ldb url to connect to
    and is a shorthand for test to create SamDB connections

commit 46ac1c3b478d087723962b6a6b6febf38620bcc9
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Wed Sep 29 01:55:22 2010 +0300

    s4-samba.samdb: Fix masking names from outer context
    
    - 'filter' is built-in
    - 'ldb' is a module name we imported

commit 0cb476fb26f450950c73c5df5223edc736ceb651
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Wed Sep 29 01:53:22 2010 +0300

    s4-python-samba: 'file' is a built-in

commit edfb8c64f60bb56d0dc9124f2aebd21ed9d1188a
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Wed Sep 29 01:35:51 2010 +0300

    s4-samba.samdb: Fix leading indention and trailing ';'

commit e9620c5fd211c854ed3f05f8821079efa729bc33
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Wed Sep 29 01:09:09 2010 +0300

    s4-python-samba: Fix few cosmetics
    
    - we have sys module already imported
    - _glue module is part of samba package so be more precise how to import

-----------------------------------------------------------------------

Summary of changes:
 source4/dsdb/tests/python/dsdb_schema_info.py    |   52 +++++--------
 source4/scripting/devel/ldapcmp                  |    2 +-
 source4/scripting/python/samba/__init__.py       |   13 ++--
 source4/scripting/python/samba/drs_utils.py      |   56 +++++++-------
 source4/scripting/python/samba/getopt.py         |    9 ++-
 source4/scripting/python/samba/join.py           |    2 +-
 source4/scripting/python/samba/samdb.py          |   54 +++++++-------
 source4/scripting/python/samba/tests/__init__.py |   57 ++++++++++++++
 source4/torture/drs/python/delete_object.py      |   32 +-------
 source4/torture/drs/python/fsmo.py               |   88 ++++++++++------------
 10 files changed, 190 insertions(+), 175 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source4/dsdb/tests/python/dsdb_schema_info.py b/source4/dsdb/tests/python/dsdb_schema_info.py
index 893cd4c..9c4f7b1 100755
--- a/source4/dsdb/tests/python/dsdb_schema_info.py
+++ b/source4/dsdb/tests/python/dsdb_schema_info.py
@@ -48,29 +48,36 @@ from samba.dcerpc.misc import GUID
 
 class SchemaInfoTestCase(samba.tests.TestCase):
 
+    # static SamDB connection
+    sam_db = None
+
     def setUp(self):
         super(SchemaInfoTestCase, self).setUp()
 
+        # connect SamDB if we haven't yet
+        if self.sam_db is None:
+            ldb_url = samba.tests.env_get_var_value("DC_SERVER")
+            SchemaInfoTestCase.sam_db = samba.tests.connect_samdb(ldb_url)
+
         # fetch rootDSE
-        self.ldb = ldb
-        res = ldb.search(base="", expression="", scope=SCOPE_BASE, attrs=["*"])
+        res = self.sam_db.search(base="", expression="", scope=SCOPE_BASE, attrs=["*"])
         self.assertEquals(len(res), 1)
         self.schema_dn = res[0]["schemaNamingContext"][0]
         self.base_dn = res[0]["defaultNamingContext"][0]
         self.forest_level = int(res[0]["forestFunctionality"][0])
 
         # get DC invocation_id
-        self.invocation_id = GUID(ldb.get_invocation_id())
+        self.invocation_id = GUID(self.sam_db.get_invocation_id())
 
     def tearDown(self):
         super(SchemaInfoTestCase, self).tearDown()
 
     def _getSchemaInfo(self):
         try:
-            schema_info_data = ldb.searchone(attribute="schemaInfo",
-                                             basedn=self.schema_dn,
-                                             expression="(objectClass=*)",
-                                             scope=SCOPE_BASE)
+            schema_info_data = self.sam_db.searchone(attribute="schemaInfo",
+                                                     basedn=self.schema_dn,
+                                                     expression="(objectClass=*)",
+                                                     scope=SCOPE_BASE)
             self.assertEqual(len(schema_info_data), 21)
             schema_info = ndr_unpack(schemaInfoBlob, schema_info_data)
             self.assertEqual(schema_info.marker, 0xFF)
@@ -94,7 +101,7 @@ changetype: modify
 add: schemaUpdateNow
 schemaUpdateNow: 1
 """
-        self.ldb.modify_ldif(ldif)
+        self.sam_db.modify_ldif(ldif)
 
     def _make_obj_names(self, prefix):
         obj_name = prefix + time.strftime("%s", time.gmtime())
@@ -128,7 +135,7 @@ systemOnly: FALSE
         ldif = self._make_attr_ldif(attr_name, attr_dn)
 
         # add the new attribute
-        self.ldb.add_ldif(ldif)
+        self.sam_db.add_ldif(ldif)
         self._ldap_schemaUpdateNow()
         # compare resulting schemaInfo
         schi_after = self._getSchemaInfo()
@@ -137,7 +144,7 @@ systemOnly: FALSE
         # rename the Attribute
         attr_dn_new = attr_dn.replace(attr_name, attr_name + "-NEW")
         try:
-            self.ldb.rename(attr_dn, attr_dn_new)
+            self.sam_db.rename(attr_dn, attr_dn_new)
         except LdbError, (num, _):
             self.fail("failed to change lDAPDisplayName for %s: %s" % (attr_name, _))
 
@@ -174,7 +181,7 @@ systemOnly: FALSE
         ldif = self._make_class_ldif(class_name, class_dn)
 
         # add the new Class
-        self.ldb.add_ldif(ldif)
+        self.sam_db.add_ldif(ldif)
         self._ldap_schemaUpdateNow()
         # compare resulting schemaInfo
         schi_after = self._getSchemaInfo()
@@ -183,7 +190,7 @@ systemOnly: FALSE
         # rename the Class
         class_dn_new = class_dn.replace(class_name, class_name + "-NEW")
         try:
-            self.ldb.rename(class_dn, class_dn_new)
+            self.sam_db.rename(class_dn, class_dn_new)
         except LdbError, (num, _):
             self.fail("failed to change lDAPDisplayName for %s: %s" % (class_name, _))
 
@@ -191,24 +198,3 @@ systemOnly: FALSE
         schi_after = self._getSchemaInfo()
         self._checkSchemaInfo(schi_before, schi_after)
 
-
-########################################################################################
-if not "DC_SERVER" in os.environ.keys():
-    raise AssertionError("Please supply TARGET_DC in environment")
-ldb_url = os.environ["DC_SERVER"]
-
-ldb_options = []
-if not "://" in ldb_url:
-    if os.path.isfile(ldb_url):
-        ldb_url = "tdb://%s" % ldb_url
-    else:
-        ldb_url = "ldap://%s" % ldb_url
-# use 'paged_search' module when connecting remotely
-if ldb_url.lower().startswith("ldap://"):
-    ldb_options = ["modules:paged_searches"]
-
-ldb = SamDB(url=ldb_url,
-            lp=samba.tests.env_loadparm(),
-            session_info=system_session(),
-            credentials=samba.tests.cmdline_credentials,
-            options=ldb_options)
diff --git a/source4/scripting/devel/ldapcmp b/source4/scripting/devel/ldapcmp
index 58b187a..fdb87e8 100755
--- a/source4/scripting/devel/ldapcmp
+++ b/source4/scripting/devel/ldapcmp
@@ -764,7 +764,7 @@ if __name__ == "__main__":
 
     lp = sambaopts.get_loadparm()
     creds = credopts.get_credentials(lp)
-    creds2 = credopts.get_credentials2(lp)
+    creds2 = credopts.get_credentials2(lp, False)
     if creds2.is_anonymous():
         creds2 = creds
 
diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py
index fb71110..f249708 100644
--- a/source4/scripting/python/samba/__init__.py
+++ b/source4/scripting/python/samba/__init__.py
@@ -92,7 +92,7 @@ class Ldb(_Ldb):
         self.register_samba_handlers()
 
         # TODO set debug
-        def msg(l,text):
+        def msg(l, text):
             print text
         #self.set_debug(msg)
 
@@ -215,7 +215,7 @@ class Ldb(_Ldb):
         """
         for changetype, msg in self.parse_ldif(ldif):
             assert changetype == ldb.CHANGETYPE_NONE
-            self.add(msg,controls)
+            self.add(msg, controls)
 
     def modify_ldif(self, ldif, controls=None):
         """Modify database based on a LDIF string.
@@ -260,13 +260,13 @@ def check_all_substituted(text):
     raise Exception("Not all variables substituted: %s" % text[var_start:var_end+1])
 
 
-def read_and_sub_file(file, subst_vars):
+def read_and_sub_file(file_name, subst_vars):
     """Read a file and sub in variables found in it
 
-    :param file: File to be read (typically from setup directory)
+    :param file_name: File to be read (typically from setup directory)
      param subst_vars: Optional variables to subsitute in the file.
     """
-    data = open(file, 'r').read()
+    data = open(file_name, 'r').read()
     if subst_vars is not None:
         data = substitute_var(data, subst_vars)
         check_all_substituted(data)
@@ -312,7 +312,6 @@ def ensure_external_module(modulename, location):
     try:
         __import__(modulename)
     except ImportError:
-        import sys
         if _in_source_tree():
             sys.path.insert(0, 
                 os.path.join(os.path.dirname(__file__),
@@ -322,7 +321,7 @@ def ensure_external_module(modulename, location):
             sys.modules[modulename] = __import__(
                 "samba.external.%s" % modulename, fromlist=["samba.external"])
 
-import _glue
+from samba import _glue
 version = _glue.version
 interface_ips = _glue.interface_ips
 set_debug_level = _glue.set_debug_level
diff --git a/source4/scripting/python/samba/drs_utils.py b/source4/scripting/python/samba/drs_utils.py
index 0382178..4686259 100644
--- a/source4/scripting/python/samba/drs_utils.py
+++ b/source4/scripting/python/samba/drs_utils.py
@@ -29,34 +29,34 @@ def drs_DsBind(drs):
     bind_info = drsuapi.DsBindInfoCtr()
     bind_info.length = 28
     bind_info.info = drsuapi.DsBindInfo28()
-    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_BASE;
-    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_ASYNC_REPLICATION;
-    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_REMOVEAPI;
-    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_MOVEREQ_V2;
-    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_GETCHG_COMPRESS;
-    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V1;
-    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_RESTORE_USN_OPTIMIZATION;
-    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_KCC_EXECUTE;
-    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_ADDENTRY_V2;
-    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_LINKED_VALUE_REPLICATION;
-    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V2;
-    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_INSTANCE_TYPE_NOT_REQ_ON_MOD;
-    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_CRYPTO_BIND;
-    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_GET_REPL_INFO;
-    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_STRONG_ENCRYPTION;
-    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V01;
-    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_TRANSITIVE_MEMBERSHIP;
-    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_ADD_SID_HISTORY;
-    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_POST_BETA3;
-    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_GET_MEMBERSHIPS2;
-    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V6;
-    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_NONDOMAIN_NCS;
-    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V8;
-    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V5;
-    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V6;
-    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3;
-    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V7;
-    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_VERIFY_OBJECT;
+    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_BASE
+    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_ASYNC_REPLICATION
+    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_REMOVEAPI
+    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_MOVEREQ_V2
+    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_GETCHG_COMPRESS
+    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V1
+    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_RESTORE_USN_OPTIMIZATION
+    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_KCC_EXECUTE
+    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_ADDENTRY_V2
+    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_LINKED_VALUE_REPLICATION
+    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V2
+    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_INSTANCE_TYPE_NOT_REQ_ON_MOD
+    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_CRYPTO_BIND
+    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_GET_REPL_INFO
+    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_STRONG_ENCRYPTION
+    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V01
+    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_TRANSITIVE_MEMBERSHIP
+    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_ADD_SID_HISTORY
+    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_POST_BETA3
+    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_GET_MEMBERSHIPS2
+    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V6
+    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_NONDOMAIN_NCS
+    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V8
+    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V5
+    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V6
+    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3
+    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V7
+    bind_info.info.supported_extensions	|= drsuapi.DRSUAPI_SUPPORTED_EXTENSION_VERIFY_OBJECT
     (info, handle) = drs.DsBind(misc.GUID(drsuapi.DRSUAPI_DS_BIND_GUID), bind_info)
     return handle
 
diff --git a/source4/scripting/python/samba/getopt.py b/source4/scripting/python/samba/getopt.py
index 62c94e4..08fe692 100644
--- a/source4/scripting/python/samba/getopt.py
+++ b/source4/scripting/python/samba/getopt.py
@@ -196,13 +196,18 @@ class CredentialsOptionsDouble(CredentialsOptions):
     def _set_simple_bind_dn2(self, option, opt_str, arg, parser):
         self.creds2.set_bind_dn(arg)
 
-    def get_credentials2(self, lp):
+    def get_credentials2(self, lp, guess=True):
         """Obtain the credentials set on the command-line.
 
         :param lp: Loadparm object to use.
+        :param guess: Try guess Credentials from environment
         :return: Credentials object
         """
-        self.creds2.guess(lp)
+        if guess:
+            self.creds2.guess(lp)
+        elif not self.creds2.get_username():
+                self.creds2.set_anonymous()
+
         if self.no_pass2:
             self.creds2.set_cmdline_callbacks()
         return self.creds2
diff --git a/source4/scripting/python/samba/join.py b/source4/scripting/python/samba/join.py
index 6cd18b4..2e6edca 100644
--- a/source4/scripting/python/samba/join.py
+++ b/source4/scripting/python/samba/join.py
@@ -72,7 +72,7 @@ def join_rodc(server=None, creds=None, lp=None, site=None, netbios_name=None,
         ctx.cldap_ret = ctx.net.finddc(domain, nbt.NBT_SERVER_LDAP | nbt.NBT_SERVER_DS | nbt.NBT_SERVER_WRITABLE)
         if ctx.cldap_ret.client_site is not None and ctx.cldap_ret.client_site != "":
             ctx.site = ctx.cldap_ret.client_site
-        return ctx.cldap_ret.pdc_dns_name;
+        return ctx.cldap_ret.pdc_dns_name
 
 
     def get_dsServiceName(samdb):
diff --git a/source4/scripting/python/samba/samdb.py b/source4/scripting/python/samba/samdb.py
index bbc52a9..a40d10d 100644
--- a/source4/scripting/python/samba/samdb.py
+++ b/source4/scripting/python/samba/samdb.py
@@ -23,11 +23,11 @@
 
 """Convenience functions for using the SAM."""
 
-import dsdb
 import samba
 import ldb
 import time
 import base64
+from samba import dsdb
 from samba.ndr import ndr_unpack, ndr_pack
 from samba.dcerpc import drsblobs, misc
 
@@ -76,13 +76,13 @@ class SamDB(samba.Ldb):
         assert(len(res) == 1 and res[0]["defaultNamingContext"] is not None)
         return res[0]["defaultNamingContext"][0]
 
-    def enable_account(self, filter):
+    def enable_account(self, search_filter):
         """Enables an account
         
-        :param filter: LDAP filter to find the user (eg samccountname=name)
+        :param search_filter: LDAP filter to find the user (eg samccountname=name)
         """
         res = self.search(base=self.domain_dn(), scope=ldb.SCOPE_SUBTREE,
-                          expression=filter, attrs=["userAccountControl"])
+                          expression=search_filter, attrs=["userAccountControl"])
         assert(len(res) == 1)
         user_dn = res[0].dn
 
@@ -100,13 +100,13 @@ userAccountControl: %u
 """ % (user_dn, userAccountControl)
         self.modify_ldif(mod)
         
-    def force_password_change_at_next_login(self, filter):
+    def force_password_change_at_next_login(self, search_filter):
         """Forces a password change at next login
         
-        :param filter: LDAP filter to find the user (eg samccountname=name)
+        :param search_filter: LDAP filter to find the user (eg samccountname=name)
         """
         res = self.search(base=self.domain_dn(), scope=ldb.SCOPE_SUBTREE,
-                          expression=filter, attrs=[])
+                          expression=search_filter, attrs=[])
         assert(len(res) == 1)
         user_dn = res[0].dn
 
@@ -165,7 +165,7 @@ pwdLastSet: 0
             if len(targetgroup) == 0:
                 raise Exception('Unable to find group "%s"' % groupname)
             assert(len(targetgroup) == 1)
-            self.delete(targetgroup[0].dn);
+            self.delete(targetgroup[0].dn)
         except:
             self.transaction_cancel()
             raise
@@ -204,22 +204,22 @@ changetype: modify
                                     expression="(|(sAMAccountName=%s)(CN=%s))" % (member, member), attrs=[])
 
                 if len(targetmember) != 1:
-                   continue
+                    continue
 
                 if add_members_operation is True and (targetgroup[0].get('member') is None or str(targetmember[0].dn) not in targetgroup[0]['member']):
-                   modified = True
-                   addtargettogroup += """add: member
+                    modified = True
+                    addtargettogroup += """add: member
 member: %s
 """ % (str(targetmember[0].dn))
 
                 elif add_members_operation is False and (targetgroup[0].get('member') is not None and str(targetmember[0].dn) in targetgroup[0]['member']):
-                   modified = True
-                   addtargettogroup += """delete: member
+                    modified = True
+                    addtargettogroup += """delete: member
 member: %s
 """ % (str(targetmember[0].dn))
 
             if modified is True:
-               self.modify_ldif(addtargettogroup)
+                self.modify_ldif(addtargettogroup)
 
         except:
             self.transaction_cancel()
@@ -258,7 +258,7 @@ member: %s
         :param physicaldeliveryoffice: Office location of the new user
         """
 
-        displayname = "";
+        displayname = ""
         if givenname is not None:
             displayname += givenname
 
@@ -277,8 +277,8 @@ member: %s
         # The new user record. Note the reliance on the SAMLDB module which
         # fills in the default informations
         ldbmessage = {"dn": user_dn,
-            "sAMAccountName": username,
-            "objectClass": "user"}
+                      "sAMAccountName": username,
+                      "objectClass": "user"}
 
         if surname is not None:
             ldbmessage["sn"] = surname
@@ -342,21 +342,21 @@ member: %s
         else:
             self.transaction_commit()
 
-    def setpassword(self, filter, password,
+    def setpassword(self, search_filter, password,
                     force_change_at_next_login=False,
                     username=None):
         """Sets the password for a user
         
-        :param filter: LDAP filter to find the user (eg samccountname=name)
+        :param search_filter: LDAP filter to find the user (eg samccountname=name)
         :param password: Password for the user
         :param force_change_at_next_login: Force password change
         """
         self.transaction_start()
         try:
             res = self.search(base=self.domain_dn(), scope=ldb.SCOPE_SUBTREE,
-                              expression=filter, attrs=[])
+                              expression=search_filter, attrs=[])
             if len(res) == 0:
-                raise Exception('Unable to find user "%s"' % (username or filter))
+                raise Exception('Unable to find user "%s"' % (username or search_filter))
             assert(len(res) == 1)
             user_dn = res[0].dn
 
@@ -374,24 +374,24 @@ unicodePwd:: %s
                   "(dn=" + str(user_dn) + ")")
 
             #  modify the userAccountControl to remove the disabled bit
-            self.enable_account(filter)
+            self.enable_account(search_filter)
         except:
             self.transaction_cancel()
             raise
         else:
             self.transaction_commit()
 
-    def setexpiry(self, filter, expiry_seconds, no_expiry_req=False):
+    def setexpiry(self, search_filter, expiry_seconds, no_expiry_req=False):
         """Sets the account expiry for a user
         
-        :param filter: LDAP filter to find the user (eg samccountname=name)
+        :param search_filter: LDAP filter to find the user (eg samccountname=name)
         :param expiry_seconds: expiry time from now in seconds
         :param no_expiry_req: if set, then don't expire password
         """
         self.transaction_start()
         try:
             res = self.search(base=self.domain_dn(), scope=ldb.SCOPE_SUBTREE,
-                          expression=filter,
+                          expression=search_filter,
                           attrs=["userAccountControl", "accountExpires"])
             assert(len(res) == 1)
             user_dn = res[0].dn
@@ -478,8 +478,8 @@ accountExpires: %u
     def set_schema(self, schema):
         self.set_schema_from_ldb(schema.ldb)
 
-    def set_schema_from_ldb(self, ldb):
-        dsdb._dsdb_set_schema_from_ldb(self, ldb)
+    def set_schema_from_ldb(self, ldb_conn):
+        dsdb._dsdb_set_schema_from_ldb(self, ldb_conn)
 
     def get_attribute_from_attid(self, attid):
         """ Get from an attid the associated attribute
diff --git a/source4/scripting/python/samba/tests/__init__.py b/source4/scripting/python/samba/tests/__init__.py
index f2c2fbf..7a5c2aa 100644
--- a/source4/scripting/python/samba/tests/__init__.py
+++ b/source4/scripting/python/samba/tests/__init__.py
@@ -22,6 +22,7 @@
 import os
 import ldb
 import samba
+import samba.auth
 from samba import param
 import subprocess
 import tempfile
@@ -67,6 +68,17 @@ def env_loadparm():
         raise Exception("SMB_CONF_PATH not set")
     return lp
 
+def env_get_var_value(var_name):
+    """Returns value for variable in os.environ
+
+    Function throws AssertionError if variable is defined.
+    Unit-test based python tests require certain input params
+    to be set in environment, otherwise they can't be run
+    """
+    assert var_name in os.environ.keys(), "Please supply %s in environment" % var_name
+    return os.environ[var_name]
+
+
 cmdline_credentials = None
 
 class RpcInterfaceTestCase(TestCase):
@@ -100,3 +112,48 @@ class BlackboxTestCase(TestCase):
             parts[0] = os.path.join(bindir, parts[0])
         line = " ".join(parts)


-- 
Samba Shared Repository


More information about the samba-cvs mailing list