]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
python: Move dsdb_Dn to samdb
authorDavid Mulder <dmulder@suse.com>
Mon, 14 Sep 2020 17:12:37 +0000 (11:12 -0600)
committerDavid Mulder <dmulder@samba.org>
Fri, 2 Oct 2020 13:29:35 +0000 (13:29 +0000)
The import dsdb needed for dsdb_Dn causes import
errors when trying to import get_bytes/get_string
in some places.

Signed-off-by: David Mulder <dmulder@suse.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
python/samba/common.py
python/samba/dbchecker.py
python/samba/kcc/kcc_utils.py
python/samba/kcc/ldif_import_export.py
python/samba/samdb.py
python/samba/tests/common.py
source4/torture/drs/python/repl_rodc.py

index 8876e4f4faa0bfae3cb2eb68c7c6ba4987090f1a..a8faa90065da53c0f4ebed795139f10ab0fbd069 100644 (file)
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
-
-import ldb
-from samba import dsdb
-from samba.ndr import ndr_pack
-from samba.dcerpc import misc
-import binascii
-
 from samba.compat import PY3
 
 
@@ -74,75 +67,3 @@ def normalise_int32(ivalue):
     return str(ivalue)
 
 
-class dsdb_Dn(object):
-    '''a class for binary DN'''
-
-    def __init__(self, samdb, dnstring, syntax_oid=None):
-        '''create a dsdb_Dn'''
-        if syntax_oid is None:
-            # auto-detect based on string
-            if dnstring.startswith("B:"):
-                syntax_oid = dsdb.DSDB_SYNTAX_BINARY_DN
-            elif dnstring.startswith("S:"):
-                syntax_oid = dsdb.DSDB_SYNTAX_STRING_DN
-            else:
-                syntax_oid = dsdb.DSDB_SYNTAX_OR_NAME
-        if syntax_oid in [dsdb.DSDB_SYNTAX_BINARY_DN, dsdb.DSDB_SYNTAX_STRING_DN]:
-            # it is a binary DN
-            colons = dnstring.split(':')
-            if len(colons) < 4:
-                raise RuntimeError("Invalid DN %s" % dnstring)
-            prefix_len = 4 + len(colons[1]) + int(colons[1])
-            self.prefix = dnstring[0:prefix_len]
-            self.binary = self.prefix[3 + len(colons[1]):-1]
-            self.dnstring = dnstring[prefix_len:]
-        else:
-            self.dnstring = dnstring
-            self.prefix = ''
-            self.binary = ''
-        self.dn = ldb.Dn(samdb, self.dnstring)
-
-    def __str__(self):
-        return self.prefix + str(self.dn.extended_str(mode=1))
-
-    def __cmp__(self, other):
-        ''' compare dsdb_Dn values similar to parsed_dn_compare()'''
-        dn1 = self
-        dn2 = other
-        guid1 = dn1.dn.get_extended_component("GUID")
-        guid2 = dn2.dn.get_extended_component("GUID")
-
-        v = cmp(guid1, guid2)
-        if v != 0:
-            return v
-        v = cmp(dn1.binary, dn2.binary)
-        return v
-
-    # In Python3, __cmp__ is replaced by these 6 methods
-    def __eq__(self, other):
-        return self.__cmp__(other) == 0
-
-    def __ne__(self, other):
-        return self.__cmp__(other) != 0
-
-    def __lt__(self, other):
-        return self.__cmp__(other) < 0
-
-    def __le__(self, other):
-        return self.__cmp__(other) <= 0
-
-    def __gt__(self, other):
-        return self.__cmp__(other) > 0
-
-    def __ge__(self, other):
-        return self.__cmp__(other) >= 0
-
-    def get_binary_integer(self):
-        '''return binary part of a dsdb_Dn as an integer, or None'''
-        if self.prefix == '':
-            return None
-        return int(self.binary, 16)
-
-    def get_bytes(self):
-        '''return binary as a byte string'''
-        return binascii.unhexlify(self.binary)
index 5b4645ebb45460fa6173801ac9234aeff26218d7..339af01cb1b73db009bf186322831251235abc44 100644 (file)
@@ -28,7 +28,7 @@ from samba.dcerpc import misc
 from samba.dcerpc import drsuapi
 from samba.ndr import ndr_unpack, ndr_pack
 from samba.dcerpc import drsblobs
-from samba.common import dsdb_Dn
+from samba.samdb import dsdb_Dn
 from samba.dcerpc import security
 from samba.descriptor import get_wellknown_sds, get_diff_sds
 from samba.auth import system_session, admin_session
index e0712e49c822c07ca0be557cfdaa4ac347cba62e..9b4a894b74321cc95b978528745dc9fabca8b86c 100644 (file)
@@ -30,7 +30,7 @@ from samba.dcerpc import (
     drsuapi,
     misc,
 )
-from samba.common import dsdb_Dn
+from samba.samdb import dsdb_Dn
 from samba.ndr import ndr_unpack, ndr_pack
 from collections import Counter
 
index 86453f1e5c9f3844fdcdb04607366606fb7130b4..7ec553edcb94abe369ae8c979fc85044ad785dac 100644 (file)
@@ -23,8 +23,7 @@ import os
 
 from samba import Ldb, ldb, read_and_sub_file
 from samba.auth import system_session
-from samba.samdb import SamDB
-from samba.common import dsdb_Dn
+from samba.samdb import SamDB, dsdb_Dn
 
 
 class LdifError(Exception):
index f1af3c28c30e40263acce8648e1d431f1379ef4b..1da59dcdaab97f2febe66748e0aff9a5e5d924bc 100644 (file)
@@ -32,8 +32,9 @@ 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 get_bytes
+from samba.compat import get_bytes, cmp
 from samba.dcerpc import security
+import binascii
 
 __docformat__ = "restructuredText"
 
@@ -1341,3 +1342,76 @@ schemaUpdateNow: 1
         if not full_dn.is_child_of(domain_dn):
             full_dn.add_base(domain_dn)
         return full_dn
+
+class dsdb_Dn(object):
+    '''a class for binary DN'''
+
+    def __init__(self, samdb, dnstring, syntax_oid=None):
+        '''create a dsdb_Dn'''
+        if syntax_oid is None:
+            # auto-detect based on string
+            if dnstring.startswith("B:"):
+                syntax_oid = dsdb.DSDB_SYNTAX_BINARY_DN
+            elif dnstring.startswith("S:"):
+                syntax_oid = dsdb.DSDB_SYNTAX_STRING_DN
+            else:
+                syntax_oid = dsdb.DSDB_SYNTAX_OR_NAME
+        if syntax_oid in [dsdb.DSDB_SYNTAX_BINARY_DN, dsdb.DSDB_SYNTAX_STRING_DN]:
+            # it is a binary DN
+            colons = dnstring.split(':')
+            if len(colons) < 4:
+                raise RuntimeError("Invalid DN %s" % dnstring)
+            prefix_len = 4 + len(colons[1]) + int(colons[1])
+            self.prefix = dnstring[0:prefix_len]
+            self.binary = self.prefix[3 + len(colons[1]):-1]
+            self.dnstring = dnstring[prefix_len:]
+        else:
+            self.dnstring = dnstring
+            self.prefix = ''
+            self.binary = ''
+        self.dn = ldb.Dn(samdb, self.dnstring)
+
+    def __str__(self):
+        return self.prefix + str(self.dn.extended_str(mode=1))
+
+    def __cmp__(self, other):
+        ''' compare dsdb_Dn values similar to parsed_dn_compare()'''
+        dn1 = self
+        dn2 = other
+        guid1 = dn1.dn.get_extended_component("GUID")
+        guid2 = dn2.dn.get_extended_component("GUID")
+
+        v = cmp(guid1, guid2)
+        if v != 0:
+            return v
+        v = cmp(dn1.binary, dn2.binary)
+        return v
+
+    # In Python3, __cmp__ is replaced by these 6 methods
+    def __eq__(self, other):
+        return self.__cmp__(other) == 0
+
+    def __ne__(self, other):
+        return self.__cmp__(other) != 0
+
+    def __lt__(self, other):
+        return self.__cmp__(other) < 0
+
+    def __le__(self, other):
+        return self.__cmp__(other) <= 0
+
+    def __gt__(self, other):
+        return self.__cmp__(other) > 0
+
+    def __ge__(self, other):
+        return self.__cmp__(other) >= 0
+
+    def get_binary_integer(self):
+        '''return binary part of a dsdb_Dn as an integer, or None'''
+        if self.prefix == '':
+            return None
+        return int(self.binary, 16)
+
+    def get_bytes(self):
+        '''return binary as a byte string'''
+        return binascii.unhexlify(self.binary)
index d326f795f85d24f668e37fc3ceaeb02013a709c2..b7248b0826eaa312f73b4763ba3b1501220c1a19 100644 (file)
@@ -20,8 +20,8 @@
 import samba
 import os
 import samba.tests
-from samba.common import normalise_int32, dsdb_Dn
-from samba.samdb import SamDB
+from samba.common import normalise_int32
+from samba.samdb import SamDB, dsdb_Dn
 
 
 class CommonTests(samba.tests.TestCaseInTempDir):
index 166ba5ba5dbc737a2200a853fbeb775876e8636b..21e70b8bc6f17bd8a8ffc25d3c9d8df4c419a9f1 100644 (file)
@@ -37,7 +37,7 @@ from samba.join import DCJoinContext
 from samba.dcerpc import drsuapi, misc, drsblobs, security
 from samba.drs_utils import drs_DsBind, drs_Replicate
 from samba.ndr import ndr_unpack, ndr_pack
-from samba.common import dsdb_Dn
+from samba.samdb import dsdb_Dn
 from samba.credentials import Credentials
 
 import random