mirror of
https://github.com/samba-team/samba.git
synced 2025-08-04 08:22:08 +03:00
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>
This commit is contained in:
committed by
David Mulder
parent
234957a2e4
commit
85d2ff2f00
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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)
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user