Ejemplo n.º 1
0
 def setUp(self):
     SetupMixin.setUp(self)
     d=self.config.db.lookup('cn=fred,dc=example,dc=com')
     ldapconfig.loadConfig(configFiles=[], reload=True)
     def _setPassword(e, password):
         return e.setPassword(password)
     d.addCallback(_setPassword, 'flintstone')
     ldaptestutil.pumpingDeferredResult(d)
     os.mkdir(os.path.join(self.spool, 'example.com', 'h1'))
Ejemplo n.º 2
0
def getSearchFieldByName(name, vars):
    for pri, n, raw in _getSearchFields():
        if n == name:
            cfg = config.loadConfig()
            val = cfg.get('webui', raw, raw=None, vars=vars)
            return val
    return None
Ejemplo n.º 3
0
def getSearchFieldByName(name, vars):
    for pri, n, raw in _getSearchFields():
        if n == name:
            cfg = config.loadConfig()
            val = cfg.get("webui", raw, raw=None, vars=vars)
            return val
    return None
Ejemplo n.º 4
0
    def testSomething(self):
        self.dir = self.mktemp()
        os.mkdir(self.dir)
        self.f1 = os.path.join(self.dir, 'one.cfg')
        writeFile(
            self.f1, """\
[fooSection]
fooVar = val

[barSection]
barVar = anotherVal
""")
        self.f2 = os.path.join(self.dir, 'two.cfg')
        writeFile(self.f2, """\
[fooSection]
fooVar = val2
""")
        self.cfg = config.loadConfig(configFiles=[self.f1, self.f2],
                                     reload=True)

        val = self.cfg.get('fooSection', 'fooVar')
        self.assertEquals(val, 'val2')

        val = self.cfg.get('barSection', 'barVar')
        self.assertEquals(val, 'anotherVal')
Ejemplo n.º 5
0
    def testMultileConfigurationFile(self):
        """
        It can read configuration from multiple files, merging the
        loaded values.
        """
        self.dir = self.mktemp()
        os.mkdir(self.dir)
        self.f1 = os.path.join(self.dir, 'one.cfg')
        writeFile(
            self.f1, """\
[fooSection]
fooVar = val

[barSection]
barVar = anotherVal
""")
        self.f2 = os.path.join(self.dir, 'two.cfg')
        writeFile(self.f2, """\
[fooSection]
fooVar = val2
""")
        self.cfg = config.loadConfig(configFiles=[self.f1, self.f2],
                                     reload=True)

        val = self.cfg.get('fooSection', 'fooVar')
        self.assertEqual(val, 'val2')

        val = self.cfg.get('barSection', 'barVar')
        self.assertEqual(val, 'anotherVal')
Ejemplo n.º 6
0
    def testMultileConfigurationFile(self):
        """
        It can read configuration from multiple files, merging the
        loaded values.
        """
        self.dir = self.mktemp()
        os.mkdir(self.dir)
        self.f1 = os.path.join(self.dir, "one.cfg")
        writeFile(
            self.f1,
            b"""\
[fooSection]
fooVar = val

[barSection]
barVar = anotherVal
""",
        )
        self.f2 = os.path.join(self.dir, "two.cfg")
        writeFile(
            self.f2,
            b"""\
[fooSection]
fooVar = val2
""",
        )
        self.cfg = config.loadConfig(configFiles=[self.f1, self.f2],
                                     reload=True)

        val = self.cfg.get("fooSection", "fooVar")
        self.assertEqual(val, "val2")

        val = self.cfg.get("barSection", "barVar")
        self.assertEqual(val, "anotherVal")
Ejemplo n.º 7
0
    def testSomething(self):
        self.dir = self.mktemp()
        os.mkdir(self.dir)
        self.f1 = os.path.join(self.dir, 'one.cfg')
        writeFile(self.f1, """\
[fooSection]
fooVar = val

[barSection]
barVar = anotherVal
""")
        self.f2 = os.path.join(self.dir, 'two.cfg')
        writeFile(self.f2, """\
[fooSection]
fooVar = val2
""")
        self.cfg = config.loadConfig(
            configFiles=[self.f1, self.f2],
            reload=True)

        val = self.cfg.get('fooSection', 'fooVar')
        self.assertEquals(val, 'val2')

        val = self.cfg.get('barSection', 'barVar')
        self.assertEquals(val, 'anotherVal')
 def testKnownValues(self):
     """
     When lanman password are enabled in the configuration, they will
     return
     """
     cfg = config.loadConfig()
     cfg.set('samba', 'use-lmhash', 'yes')
     self.assertEqual(self.knownValues, [(p, smbpassword.lmhash(p))
                                         for p, _ in self.knownValues])
Ejemplo n.º 9
0
    def testLMHashConfiguationDisabled(self):
        """
        When the lanman passwords are disabled from the configuration, it will
        return the disabled password.
        """
        cfg = config.loadConfig()
        cfg.set('samba', 'use-lmhash', 'no')

        result = smbpassword.lmhash(b'any-pass')

        self.assertEqual(32 * b'X', result)
Ejemplo n.º 10
0
    def setUp(self):
        self.dir = self.mktemp()
        os.mkdir(self.dir)
        self.f1 = os.path.join(self.dir, 'one.cfg')
        writeFile(
            self.f1, """\
[authentication]
identity-search = (something=%(name)s)
""")
        self.cfg = config.loadConfig(configFiles=[self.f1], reload=True)
        self.config = config.LDAPConfig()
Ejemplo n.º 11
0
    def testLMHashConfiguationDisabled(self):
        """
        When the lanman passwords are disabled from the configuration, it will
        return the disabled password.
        """
        cfg = config.loadConfig()
        cfg.set("samba", "use-lmhash", "no")

        result = smbpassword.lmhash(b"any-pass")

        self.assertEqual(32 * b"X", result)
Ejemplo n.º 12
0
 def testKnownValues(self):
     """
     When lanman password are enabled in the configuration, they will
     return
     """
     cfg = config.loadConfig()
     cfg.set('samba', 'use-lmhash', 'yes')
     self.assertEqual(
         self.knownValues,
         [(p, smbpassword.lmhash(p)) for p, _ in self.knownValues]
     )
Ejemplo n.º 13
0
    def testLMHashConfiguationDisabled(self):
        """
        When the lanman passwords are disabled from the configuration, it will
        return the disabled password.
        """
        cfg = config.loadConfig()
        cfg.set('samba', 'use-lmhash', 'no')

        result = smbpassword.lmhash(b'any-pass')

        self.assertEqual(32 * b'X', result)
Ejemplo n.º 14
0
    def setUp(self):
        self.dir = self.mktemp()
        os.mkdir(self.dir)
        self.f1 = os.path.join(self.dir, 'one.cfg')
        writeFile(self.f1, """\
[authentication]
identity-search = (something=%(name)s)
""")
        self.cfg = config.loadConfig(
            configFiles=[self.f1],
            reload=True)
        self.config = config.LDAPConfig()
Ejemplo n.º 15
0
    def testKnownValues(self):
        """
        When lanman password are enabled in the configuration, they will
        return
        """
        cfg = config.loadConfig()
        cfg.set('samba', 'use-lmhash', 'yes')
        for password, expected in self.knownValues:

            result = smbpassword.lmhash(password)

            self.assertEqual(expected, result)
Ejemplo n.º 16
0
def _getSearchFields():
    cfg = config.loadConfig()
    if not cfg.has_section("webui"):
        return
    for raw in cfg.options("webui"):
        if not raw:
            continue
        l = raw.split(None, 2)
        if l[0].lower() == "search-field":
            pri, name = l[1:]
            pri = int(pri)
            yield (pri, name, raw)
Ejemplo n.º 17
0
    def testKnownValues(self):
        """
        When lanman password are enabled in the configuration, they will
        return
        """
        cfg = config.loadConfig()
        cfg.set('samba', 'use-lmhash', 'yes')
        for password, expected in self.knownValues:

            result = smbpassword.lmhash(password)

            self.assertEqual(expected, result)
Ejemplo n.º 18
0
def _getSearchFields():
    cfg = config.loadConfig()
    if not cfg.has_section('webui'):
        return
    for raw in cfg.options('webui'):
        if not raw:
            continue
        l=raw.split(None, 2)
        if l[0].lower() == 'search-field':
            pri, name = l[1:]
            pri = int(pri)
            yield (pri, name, raw)
Ejemplo n.º 19
0
    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)
            if result != expected_result:
                raise AssertionError, 'lmhash(%s)=%s, expected %s' \
                      % (repr(password), repr(result), repr(expected_result))
Ejemplo n.º 20
0
    def testKnownValues(self):
        """lmhash(...) gives known results"""
        cfg = config.loadConfig()
        for password, expected in self.knownValues:
            cfg.set('samba', 'use-lmhash', 'no')
            disabled = smbpassword.lmhash(password)
            self.assertEqual(disabled, 32 * 'X',
                             "Disabled lmhash must be X's: %r" % disabled)

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

            result = smbpassword.lmhash(password)

            self.assertEqual(expected, result)
Ejemplo n.º 21
0
def reloadFromContent(testCase, content):
    """
    Reload the global configuration file with raw `content`.
    """
    base_path = testCase.mktemp()
    os.mkdir(base_path)
    config_path = os.path.join(base_path, "test.cfg")
    writeFile(config_path, content)

    # Reload with empty content to reduce the side effects.
    testCase.addCleanup(reloadFromContent, testCase, b"")

    return config.loadConfig(
        configFiles=[config_path],
        reload=True,
    )
Ejemplo n.º 22
0
def createServer(proto, *responses, **kw):
    def createClient(factory):
        factory.doStart()
        #TODO factory.startedConnecting(c)
        proto = factory.buildProtocol(addr=None)
        proto.connectionMade()

    cfg = config.loadConfig(configFiles=[], reload=True)
    overrides = kw.setdefault('serviceLocationOverrides', {})
    overrides.setdefault('', createClient)
    conf = config.LDAPConfig(**kw)
    server = proto(conf)
    server.protocol = lambda: LDAPClientTestDriver(*responses)
    server.transport = proto_helpers.StringTransport()
    server.connectionMade()
    return server
Ejemplo n.º 23
0
    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)
            if result != expected_result:
                raise AssertionError, "lmhash(%s)=%s, expected %s" % (
                    repr(password),
                    repr(result),
                    repr(expected_result),
                )
Ejemplo n.º 24
0
def createServer(proto, *responses, **kw):
    def createClient(factory):
        factory.doStart()
        #TODO factory.startedConnecting(c)
        proto = factory.buildProtocol(addr=None)
        proto.connectionMade()
    cfg = config.loadConfig(
        configFiles=[],
        reload=True)
    overrides = kw.setdefault('serviceLocationOverrides', {})
    overrides.setdefault('', createClient)
    conf = config.LDAPConfig(**kw)
    server = proto(conf)
    server.protocol = lambda : LDAPClientTestDriver(*responses)
    server.transport = proto_helpers.StringTransport()
    server.connectionMade()
    return server