python: Fix representation of UUIDs as strings in zone files rather than binary blobs...
authorJelmer Vernooij <jelmer@samba.org>
Fri, 25 Jan 2008 02:54:33 +0000 (03:54 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Fri, 25 Jan 2008 02:54:33 +0000 (03:54 +0100)
Pair-programmed with Andrew, but git doesn't appear to support multiple --author arguments. :-(

source/scripting/python/samba/__init__.py
source/scripting/python/samba/provision.py
source/scripting/python/samba/samdb.py
source/scripting/python/samba/tests/__init__.py
source/scripting/python/samba/tests/provision.py

index 5c14edd357f6ee9d1e64f27e89aa4f7f82b15e49..b041165800fc1de0c65ae41f613f71f59f4a2e9c 100644 (file)
@@ -91,7 +91,7 @@ class Ldb(ldb.Ldb):
     set_session_info = misc.ldb_set_session_info
     set_loadparm = misc.ldb_set_loadparm
 
     set_session_info = misc.ldb_set_session_info
     set_loadparm = misc.ldb_set_loadparm
 
-    def searchone(self, basedn, attribute, expression=None, 
+    def searchone(self, attribute, basedn=None, expression=None, 
                   scope=ldb.SCOPE_BASE):
         """Search for one attribute as a string.
         
                   scope=ldb.SCOPE_BASE):
         """Search for one attribute as a string.
         
@@ -106,7 +106,7 @@ class Ldb(ldb.Ldb):
             return None
         values = set(res[0][attribute])
         assert len(values) == 1
             return None
         values = set(res[0][attribute])
         assert len(values) == 1
-        return values.pop()
+        return self.schema_format_value(attribute, values.pop())
 
     def erase(self):
         """Erase this ldb, removing all records."""
 
     def erase(self):
         """Erase this ldb, removing all records."""
index 918d983782bb338ffb92d787d1b09fe0e4bc1c15..0e498f65e5fd729f1dc87538190cc9c50085dcfc 100644 (file)
@@ -725,7 +725,7 @@ def provision(lp, setup_dir, message, paths, session_info,
     
     if ldap_backend == "ldapi":
        # provision-backend will set this path suggested slapd command line / fedorads.inf
     
     if ldap_backend == "ldapi":
        # provision-backend will set this path suggested slapd command line / fedorads.inf
-       ldap_backend = "ldapi://" % urllib.quote(os.path.join(lp.get("private dir"), "ldap", "ldapi"))
+       ldap_backend = "ldapi://" % urllib.quote(os.path.join(lp.get("private dir"), "ldap", "ldapi"), "")
 
     assert realm is not None
     realm = realm.upper()
 
     assert realm is not None
     realm = realm.upper()
@@ -860,9 +860,9 @@ def provision(lp, setup_dir, message, paths, session_info,
         samdb = SamDB(paths.samdb, session_info=session_info, 
                       credentials=credentials, lp=lp)
 
         samdb = SamDB(paths.samdb, session_info=session_info, 
                       credentials=credentials, lp=lp)
 
-        domainguid = samdb.searchone(domaindn, "objectGUID")
+        domainguid = samdb.searchone(basedn=domaindn, attribute="objectGUID")
         assert isinstance(domainguid, str)
         assert isinstance(domainguid, str)
-        hostguid = samdb.searchone(domaindn, "objectGUID",
+        hostguid = samdb.searchone(basedn=domaindn, attribute="objectGUID",
                 expression="(&(objectClass=computer)(cn=%s))" % hostname,
                 scope=SCOPE_SUBTREE)
         assert isinstance(hostguid, str)
                 expression="(&(objectClass=computer)(cn=%s))" % hostname,
                 scope=SCOPE_SUBTREE)
         assert isinstance(hostguid, str)
@@ -877,14 +877,14 @@ def provision(lp, setup_dir, message, paths, session_info,
     return domaindn
 
 
     return domaindn
 
 
-def create_phpldapadmin_config(path, setup_path, ldap_backend):
+def create_phpldapadmin_config(path, setup_path, ldapi_uri):
     """Create a PHP LDAP admin configuration file.
 
     :param path: Path to write the configuration to.
     :param setup_path: Function to generate setup paths.
     """
     setup_file(setup_path("phpldapadmin-config.php"), path, 
     """Create a PHP LDAP admin configuration file.
 
     :param path: Path to write the configuration to.
     :param setup_path: Function to generate setup paths.
     """
     setup_file(setup_path("phpldapadmin-config.php"), path, 
-            {"S4_LDAPI_URI": ldap_backend})
+            {"S4_LDAPI_URI": ldapi_uri})
 
 
 def create_zone_file(path, setup_path, samdb, dnsdomain, domaindn, 
 
 
 def create_zone_file(path, setup_path, samdb, dnsdomain, domaindn, 
@@ -903,6 +903,7 @@ def create_zone_file(path, setup_path, samdb, dnsdomain, domaindn,
     :param domainguid: GUID of the domain.
     :param hostguid: GUID of the host.
     """
     :param domainguid: GUID of the domain.
     :param hostguid: GUID of the host.
     """
+    assert isinstance(domainguid, str)
 
     setup_file(setup_path("provision.zone"), path, {
             "DNSPASS_B64": b64encode(dnspass),
 
     setup_file(setup_path("provision.zone"), path, {
             "DNSPASS_B64": b64encode(dnspass),
index b757330ecb34c6a5298c3e4c7f1cb079aef559c6..c11fabf553d75714fd84dfa7a204ff9c836d728c 100644 (file)
@@ -105,7 +105,7 @@ userAccountControl: %u
         assert(len(res) == 1 and res[0].defaultNamingContext is not None)
         domain_dn = res[0]["defaultNamingContext"][0]
         assert(domain_dn is not None)
         assert(len(res) == 1 and res[0].defaultNamingContext is not None)
         domain_dn = res[0]["defaultNamingContext"][0]
         assert(domain_dn is not None)
-        dom_users = self.searchone(domain_dn, "dn", "name=Domain Users")
+        dom_users = self.searchone(basedn=domain_dn, attribute="dn", expression="name=Domain Users")
         assert(dom_users is not None)
 
         user_dn = "CN=%s,CN=Users,%s" % (username, domain_dn)
         assert(dom_users is not None)
 
         user_dn = "CN=%s,CN=Users,%s" % (username, domain_dn)
index e557dd95bee395a343f89ebad74063acec5dbd23..94020026749a7b2d0638b7102efed3ba65b52c2c 100644 (file)
@@ -79,7 +79,7 @@ class LdbExtensionTests(TestCaseInTempDir):
         l = samba.Ldb(path)
         try:
             l.add({"dn": "foo=dc", "bar": "bla"})
         l = samba.Ldb(path)
         try:
             l.add({"dn": "foo=dc", "bar": "bla"})
-            self.assertEquals("bla", l.searchone(ldb.Dn(l, "foo=dc"), "bar"))
+            self.assertEquals("bla", l.searchone(basedn=ldb.Dn(l, "foo=dc"), attribute="bar"))
         finally:
             del l
             os.unlink(path)
         finally:
             del l
             os.unlink(path)
index 83952df9fe752d21c5a1193879f73532eaf7180d..1456b6751ce555171686024e96b4d40ca6e06529 100644 (file)
@@ -33,7 +33,7 @@ class ProvisionTestCase(samba.tests.TestCaseInTempDir):
         ldb = setup_secretsdb(path, setup_path, None, None, None)
         try:
             self.assertEquals("LSA Secrets",
         ldb = setup_secretsdb(path, setup_path, None, None, None)
         try:
             self.assertEquals("LSA Secrets",
-                 ldb.searchone(Dn(ldb, "CN=LSA Secrets"), "CN"))
+                 ldb.searchone(basedn="CN=LSA Secrets", attribute="CN"))
         finally:
             del ldb
             os.unlink(path)
         finally:
             del ldb
             os.unlink(path)
@@ -50,6 +50,14 @@ class ProvisionTestCase(samba.tests.TestCaseInTempDir):
                            machinepass="machinepass", dnsdomain="example.com")
             self.assertEquals(1, 
                     len(secrets_ldb.search("samAccountName=krbtgt,flatname=EXAMPLE,CN=Principals")))
                            machinepass="machinepass", dnsdomain="example.com")
             self.assertEquals(1, 
                     len(secrets_ldb.search("samAccountName=krbtgt,flatname=EXAMPLE,CN=Principals")))
+           self.assertEquals("keytab.path",
+                    secrets_ldb.searchone(basedn="flatname=EXAMPLE,CN=primary domains", 
+                                          expression="(privateKeytab=*)", 
+                                          attribute="privateKeytab"))
+            self.assertEquals("S-5-22",
+                    secrets_ldb.searchone(basedn="flatname=EXAMPLE,CN=primary domains",
+                                          expression="objectSid=*", attribute="objectSid"))
+
         finally:
             del secrets_ldb
             os.unlink(path)
         finally:
             del secrets_ldb
             os.unlink(path)