Skip to content

Commit

Permalink
Make it possible to specify local address for LDAP client
Browse files Browse the repository at this point in the history
This adds an optional argument 'bindAddress' to the LDAPClientCreator.connect()
method. This argument is ultimately passed as-is to reactor.connectTCP to
specify the local address and port to use for the client connection.
  • Loading branch information
antong committed Sep 1, 2010
1 parent 7213c2d commit 5ab62a6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions ldaptor/protocols/ldap/ldapconnector.py
Expand Up @@ -8,7 +8,7 @@

class LDAPConnector(SRVConnector):
def __init__(self, reactor, dn, factory,
overrides=None):
overrides=None, bindAddress=None):
if not isinstance(dn, distinguishedname.DistinguishedName):
dn = distinguishedname.DistinguishedName(stringValue=dn)
if overrides is None:
Expand All @@ -17,7 +17,8 @@ def __init__(self, reactor, dn, factory,

domain = dn.getDomainName()
SRVConnector.__init__(self, reactor,
'ldap', domain, factory)
'ldap', domain, factory,
connectFuncKwArgs={'bindAddress': bindAddress})

def __getstate__(self):
r={}
Expand Down Expand Up @@ -86,11 +87,12 @@ def pickServer(self):
return host, port

class LDAPClientCreator(protocol.ClientCreator):
def connect(self, dn, overrides=None):
def connect(self, dn, overrides=None, bindAddress=None):
"""Connect to remote host, return Deferred of resulting protocol instance."""
d = defer.Deferred()
f = protocol._InstanceFactory(self.reactor, self.protocolClass(*self.args, **self.kwargs), d)
c = LDAPConnector(self.reactor, dn, f, overrides=overrides)
c = LDAPConnector(self.reactor, dn, f, overrides=overrides,
bindAddress=bindAddress)
c.connect()
return d

Expand Down

0 comments on commit 5ab62a6

Please sign in to comment.