summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorDavid Mulder <dmulder@suse.com>2020-09-14 11:12:37 -0600
committerDavid Mulder <dmulder@samba.org>2020-10-02 13:29:35 +0000
commit85d2ff2f0003b106ca84866b7e7893723f1dd93c (patch)
tree7d7ed7ac27b47cc3b05dedea730f352e3eefc9af /python
parent234957a2e4408537c5722edf04dfe03dd31bd1b1 (diff)
downloadsamba-85d2ff2f0003b106ca84866b7e7893723f1dd93c.tar.gz
python: Move dsdb_Dn to samdb
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>
Diffstat (limited to 'python')
-rw-r--r--python/samba/common.py79
-rw-r--r--python/samba/dbchecker.py2
-rw-r--r--python/samba/kcc/kcc_utils.py2
-rw-r--r--python/samba/kcc/ldif_import_export.py3
-rw-r--r--python/samba/samdb.py76
-rw-r--r--python/samba/tests/common.py4
6 files changed, 80 insertions, 86 deletions
diff --git a/python/samba/common.py b/python/samba/common.py
index 8876e4f4faa..a8faa90065d 100644
--- a/python/samba/common.py
+++ b/python/samba/common.py
@@ -16,13 +16,6 @@
# 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)
diff --git a/python/samba/dbchecker.py b/python/samba/dbchecker.py
index 5b4645ebb45..339af01cb1b 100644
--- a/python/samba/dbchecker.py
+++ b/python/samba/dbchecker.py
@@ -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
diff --git a/python/samba/kcc/kcc_utils.py b/python/samba/kcc/kcc_utils.py
index e0712e49c82..9b4a894b743 100644
--- a/python/samba/kcc/kcc_utils.py
+++ b/python/samba/kcc/kcc_utils.py
@@ -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
diff --git a/python/samba/kcc/ldif_import_export.py b/python/samba/kcc/ldif_import_export.py
index 86453f1e5c9..7ec553edcb9 100644
--- a/python/samba/kcc/ldif_import_export.py
+++ b/python/samba/kcc/ldif_import_export.py
@@ -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):
diff --git a/python/samba/samdb.py b/python/samba/samdb.py
index f1af3c28c30..1da59dcdaab 100644
--- a/python/samba/samdb.py
+++ b/python/samba/samdb.py
@@ -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)
diff --git a/python/samba/tests/common.py b/python/samba/tests/common.py
index d326f795f85..b7248b0826e 100644
--- a/python/samba/tests/common.py
+++ b/python/samba/tests/common.py
@@ -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):