# 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
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)
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
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
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):
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"
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)
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):
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