Modified SamDB to accept options like Ldb.
[ira/wip.git] / source4 / scripting / python / samba / samdb.py
index 614970d3ec5b6bfadd144853fd29d99ebfcb76ef..454a9d144cf922e72edf2078537edbecdc1e5bba 100644 (file)
@@ -28,6 +28,7 @@ import ldb
 from samba.idmap import IDmapDB
 import pwd
 import time
+import base64
 
 __docformat__ = "restructuredText"
 
@@ -35,14 +36,14 @@ class SamDB(samba.Ldb):
     """The SAM database."""
 
     def __init__(self, url=None, session_info=None, credentials=None, 
-                 modules_dir=None, lp=None):
+                 modules_dir=None, lp=None, options=None):
         """Open the Sam Database.
 
         :param url: URL of the database.
         """
         self.lp = lp
         super(SamDB, self).__init__(session_info=session_info, credentials=credentials,
-                                    modules_dir=modules_dir, lp=lp)
+                                    modules_dir=modules_dir, lp=lp, options=options)
         glue.dsdb_set_global_schema(self)
         if url:
             self.connect(url)
@@ -59,7 +60,7 @@ dn: CN=%s,CN=ForeignSecurityPrincipals,%s
 objectClass: top
 objectClass: foreignSecurityPrincipal
 description: %s
-        """ % (sid, domaindn, desc)
+""" % (sid, domaindn, desc)
         # deliberately ignore errors from this, as the records may
         # already exist
         for msg in self.parse_ldif(add):
@@ -175,11 +176,11 @@ userAccountControl: %u
             user_dn = res[0].dn
 
             setpw = """
-    dn: %s
-    changetype: modify
-    replace: userPassword
-    userPassword: %s
-    """ % (user_dn, password)
+dn: %s
+changetype: modify
+replace: userPassword
+userPassword:: %s
+""" % (user_dn, base64.b64encode(password))
 
             self.modify_ldif(setpw)
 
@@ -198,7 +199,10 @@ userAccountControl: %u
         glue.samdb_set_domain_sid(self, sid)
 
     def attach_schema_from_ldif(self, pf, df):
-        glue.dsdb_attach_schema_from_ldif_file(self, pf, df)
+        glue.dsdb_attach_schema_from_ldif(self, pf, df)
+
+    def convert_schema_to_openldap(self, target, mapping):
+        return glue.dsdb_convert_schema_to_openldap(self, target, mapping)
 
     def set_invocation_id(self, invocation_id):
         """Set the invocation id for this SamDB handle.
@@ -229,13 +233,13 @@ userAccountControl: %u
                 accountExpires = glue.unix2nttime(expiry_seconds + int(time.time()))
 
             mod = """
-    dn: %s
-    changetype: modify
-    replace: userAccountControl
-    userAccountControl: %u
-    replace: accountExpires
-    accountExpires: %u
-    """ % (res[0].dn, userAccountControl, accountExpires)
+dn: %s
+changetype: modify
+replace: userAccountControl
+userAccountControl: %u
+replace: accountExpires
+accountExpires: %u
+""" % (res[0].dn, userAccountControl, accountExpires)
             # now change the database
             self.modify_ldif(mod)
         except: