]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
python: Port samdb module to Python 3 compatible form
authorLumir Balhar <lbalhar@redhat.com>
Tue, 30 Jan 2018 17:52:11 +0000 (18:52 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 14 Feb 2018 23:18:29 +0000 (00:18 +0100)
Signed-off-by: Lumir Balhar <lbalhar@redhat.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/common.py
python/samba/samdb.py

index a915934f184360d3dca2fa93299d8143f01376f4..1c410a4702d48ec44af10766b2e6d1710826f8a6 100644 (file)
@@ -18,7 +18,7 @@
 
 
 import ldb
-import dsdb
+from samba import dsdb
 from samba.ndr import ndr_pack
 from samba.dcerpc import misc
 import binascii
index abc7e188853b328fbf2eab0fbb8323ae6c7c354c..89014a53ed2d4fc5b5c903627889f7916810ae22 100644 (file)
@@ -31,6 +31,7 @@ from samba import dsdb, dsdb_dns
 from samba.ndr import ndr_unpack, ndr_pack
 from samba.dcerpc import drsblobs, misc
 from samba.common import normalise_int32
+from samba.compat import text_type
 
 __docformat__ = "restructuredText"
 
@@ -509,7 +510,7 @@ member: %s
             if len(res) > 1:
                 raise Exception('Matched %u multiple users with filter "%s"' % (len(res), search_filter))
             user_dn = res[0].dn
-            pw = unicode('"' + password.encode('utf-8') + '"', 'utf-8').encode('utf-16-le')
+            pw = text_type(b'"' + password.encode('utf-8') + b'"', 'utf-8').encode('utf-16-le')
             setpw = """
 dn: %s
 changetype: modify
@@ -690,7 +691,7 @@ accountExpires: %u
         """
         if len(self.hash_oid_name.keys()) == 0:
             self._populate_oid_attid()
-        if self.hash_oid_name.has_key(self.get_oid_from_attid(attid)):
+        if self.get_oid_from_attid(attid) in self.hash_oid_name:
             return self.hash_oid_name[self.get_oid_from_attid(attid)]
         else:
             return None
@@ -729,14 +730,14 @@ accountExpires: %u
             return None
 
         repl = ndr_unpack(drsblobs.replPropertyMetaDataBlob,
-                            str(res[0]["replPropertyMetaData"]))
+                          res[0]["replPropertyMetaData"][0])
         ctr = repl.ctr
         if len(self.hash_oid_name.keys()) == 0:
             self._populate_oid_attid()
         for o in ctr.array:
             # Search for Description
             att_oid = self.get_oid_from_attid(o.attid)
-            if self.hash_oid_name.has_key(att_oid) and\
+            if att_oid in self.hash_oid_name and\
                att.lower() == self.hash_oid_name[att_oid].lower():
                 return o.version
         return None
@@ -751,7 +752,7 @@ accountExpires: %u
             return None
 
         repl = ndr_unpack(drsblobs.replPropertyMetaDataBlob,
-                            str(res[0]["replPropertyMetaData"]))
+                          res[0]["replPropertyMetaData"][0])
         ctr = repl.ctr
         now = samba.unix2nttime(int(time.time()))
         found = False
@@ -760,7 +761,7 @@ accountExpires: %u
         for o in ctr.array:
             # Search for Description
             att_oid = self.get_oid_from_attid(o.attid)
-            if self.hash_oid_name.has_key(att_oid) and\
+            if att_oid in self.hash_oid_name and\
                att.lower() == self.hash_oid_name[att_oid].lower():
                 found = True
                 seq = self.sequence_number(ldb.SEQ_NEXT)