# Path: ldaptor/samba/smbpassword.py
# def nthash(password=''):
# def lmhash_locked(password=''):
# def _no_lmhash(password=''):
# def _have_lmhash(password=''):
# def _deshash(p):
#     def _pack(bits):
# LM_MAGIC = "KGS!@#$%"
# 
# Path: ldaptor/config.py
# class MissingBaseDNError(Exception):
# class LDAPConfig(object):
#     def __str__(self):
#     def __init__(self,
#                  baseDN=None,
#                  serviceLocationOverrides=None,
#                  identityBaseDN=None,
#                  identitySearch=None):
#     def getBaseDN(self):
#     def getServiceLocationOverrides(self):
#     def _loadServiceLocationOverrides(self):
#     def copy(self, **kw):
#     def getIdentityBaseDN(self):
#     def getIdentitySearch(self, name):
# def loadConfig(configFiles=None,
#                reload=False):
# def useLMhash():
# DEFAULTS = {
#     'samba': { 'use-lmhash': 'no',
#                },
#     }
# CONFIG_FILES = [
#     '/etc/ldaptor/global.cfg',
#     os.path.expanduser('~/.ldaptor/global.cfg'),
#     ]


from twisted.trial import unittest
from ldaptor.samba import smbpassword
from ldaptor import config
        """nthash(...) gives known results"""
        for password, expected_result in self.knownValues:
            result = smbpassword.nthash(password)
            if result != expected_result:
                raise AssertionError, 'nthash(%s)=%s, expected %s' \
                      % (repr(password), repr(result), repr(expected_result))

class TestLMHash(unittest.TestCase):
    knownValues=( # password, expected_result
        ('', 'AAD3B435B51404EEAAD3B435B51404EE'),
        ('foo', '5BFAFBEBFB6A0942AAD3B435B51404EE'),
        (13*'x', '3AA62DBBEFDB676366B4159AF5A7C45C'),
        (14*'x', '3AA62DBBEFDB67633AA62DBBEFDB6763'),
        (15*'x', '3AA62DBBEFDB67633AA62DBBEFDB6763'),
        (100*'x', '3AA62DBBEFDB67633AA62DBBEFDB6763'),
        ('1234567abcdefg', '0182BD0BD4444BF8E0C510199CC66ABD'),
        ('XXXXXXXabcdefg', '3AA62DBBEFDB6763E0C510199CC66ABD'),
        ('1234567XXXXXXX', '0182BD0BD4444BF83AA62DBBEFDB6763'),
        )

    def testKnownValues(self):
        """lmhash(...) gives known results"""
        cfg = config.loadConfig()
        for password, expected_result in self.knownValues:
            cfg.set('samba', 'use-lmhash', 'no')
            disabled = smbpassword.lmhash(password)
            self.assertEquals(disabled, 32*'X',
                              "Disabled lmhash must be X's: %r" % disabled)

            cfg.set('samba', 'use-lmhash', 'yes')

# Path: ldaptor/samba/smbpassword.py
# def nthash(password=''):
# def lmhash_locked(password=''):
# def _no_lmhash(password=''):
# def _have_lmhash(password=''):
# def _deshash(p):
#     def _pack(bits):
# LM_MAGIC = "KGS!@#$%"
# 
# Path: ldaptor/config.py
# class MissingBaseDNError(Exception):
# class LDAPConfig(object):
#     def __str__(self):
#     def __init__(self,
#                  baseDN=None,
#                  serviceLocationOverrides=None,
#                  identityBaseDN=None,
#                  identitySearch=None):
#     def getBaseDN(self):
#     def getServiceLocationOverrides(self):
#     def _loadServiceLocationOverrides(self):
#     def copy(self, **kw):
#     def getIdentityBaseDN(self):
#     def getIdentitySearch(self, name):
# def loadConfig(configFiles=None,
#                reload=False):
# def useLMhash():
# DEFAULTS = {
#     'samba': { 'use-lmhash': 'no',
#                },
#     }
# CONFIG_FILES = [
#     '/etc/ldaptor/global.cfg',
#     os.path.expanduser('~/.ldaptor/global.cfg'),
#     ]


# Path: ldaptor/test/test_smbpassword.py
from twisted.trial import unittest
from ldaptor.samba import smbpassword
from ldaptor import config

        """nthash(...) gives known results"""
        for password, expected_result in self.knownValues:
            result = smbpassword.nthash(password)
            if result != expected_result:
                raise AssertionError, 'nthash(%s)=%s, expected %s' \
                      % (repr(password), repr(result), repr(expected_result))

class TestLMHash(unittest.TestCase):
    knownValues=( # password, expected_result
        ('', 'AAD3B435B51404EEAAD3B435B51404EE'),
        ('foo', '5BFAFBEBFB6A0942AAD3B435B51404EE'),
        (13*'x', '3AA62DBBEFDB676366B4159AF5A7C45C'),
        (14*'x', '3AA62DBBEFDB67633AA62DBBEFDB6763'),
        (15*'x', '3AA62DBBEFDB67633AA62DBBEFDB6763'),
        (100*'x', '3AA62DBBEFDB67633AA62DBBEFDB6763'),
        ('1234567abcdefg', '0182BD0BD4444BF8E0C510199CC66ABD'),
        ('XXXXXXXabcdefg', '3AA62DBBEFDB6763E0C510199CC66ABD'),
        ('1234567XXXXXXX', '0182BD0BD4444BF83AA62DBBEFDB6763'),
        )

    def testKnownValues(self):
        """lmhash(...) gives known results"""
        cfg = config.loadConfig()
        for password, expected_result in self.knownValues:
            cfg.set('samba', 'use-lmhash', 'no')
            disabled = smbpassword.lmhash(password)
            self.assertEquals(disabled, 32*'X',
                              "Disabled lmhash must be X's: %r" % disabled)

            cfg.set('samba', 'use-lmhash', 'yes')

            result = smbpassword.lmhash(password)