Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def main(base, serviceLocationOverrides, numOfConnections=3, numOfSearches=3):
log.startLogging(sys.stderr, setStdout=0)
l=[]
for connection in xrange(0, numOfConnections):
c=ldapconnector.LDAPClientCreator(reactor, ldapclient.LDAPClient)
d=c.connectAnonymously(base, serviceLocationOverrides)
d.addCallback(_search, base, connection, numOfSearches)
d.addErrback(error)
l.append(d)
dl=defer.DeferredList(l)
dl.addBoth(lambda dummy: reactor.stop())
reactor.run()
sys.exit(exitStatus)
def child_base(self, context):
cfg = context.locate(interfaces.ILDAPConfig)
c=ldapconnector.LDAPClientCreator(reactor, ldapclient.LDAPClient)
d=c.connectAnonymously(iwebui.ICurrentDN(context),
cfg.getServiceLocationOverrides())
def _search(proto, base):
baseEntry = ldapsyntax.LDAPEntry(client=proto,
dn=base)
d=baseEntry.search(scope=pureldap.LDAP_SCOPE_baseObject,
sizeLimit=1)
def _cb(result, proto):
proto.unbind()
return result
d.addBoth(_cb, proto)
return d
d.addCallback(_search, iwebui.ICurrentDN(context))
def _first(results, dn):
def _search(self, searchFilter):
c=ldapconnector.LDAPClientCreator(reactor, ldapclient.LDAPClient)
d=c.connectAnonymously(self.config.getBaseDN(),
self.config.getServiceLocationOverrides())
def _doSearch(proto, searchFilter):
searchFilter = ldapfilter.parseFilter(searchFilter)
baseEntry = ldapsyntax.LDAPEntry(client=proto,
dn=self.config.getBaseDN())
d=baseEntry.search(filterObject=searchFilter)
return d
d.addCallback(_doSearch, searchFilter)
return d
def child(self, context, name):
if name == 'searchFilter':
return self.search
if name != 'results':
return None
config = context.locate(ILDAPConfig)
c=ldapconnector.LDAPClientCreator(reactor, ldapclient.LDAPClient)
d=c.connectAnonymously(config.getBaseDN(),
config.getServiceLocationOverrides())
def _search(proto, base, searchFilter):
baseEntry = ldapsyntax.LDAPEntry(client=proto, dn=base)
d=baseEntry.search(filterObject=searchFilter)
return d
d.addCallback(_search, config.getBaseDN(), self.search)
return d
def _search(self):
c=ldapconnector.LDAPClientCreator(reactor, ldapclient.LDAPClient)
d=c.connectAnonymously(self.config.getBaseDN(),
self.config.getServiceLocationOverrides())
def _doSearch(proto):
searchFilter = ldapfilter.parseFilter('(gn=j*)')
baseEntry = ldapsyntax.LDAPEntry(client=proto,
dn=self.config.getBaseDN())
d=baseEntry.search(filterObject=searchFilter)
return d
d.addCallback(_doSearch)
return d
def search(config):
c=ldapconnector.LDAPClientCreator(reactor, ldapclient.LDAPClient)
d=c.connectAnonymously(config['base'],
config['serviceLocationOverrides'])
def _doSearch(proto, config):
searchFilter = ldapfilter.parseFilter('(gn=j*)')
baseEntry = ldapsyntax.LDAPEntry(client=proto, dn=config['base'])
d=baseEntry.search(filterObject=searchFilter)
return d
d.addCallback(_doSearch, config)
return d
def connectionMade(self):
clientCreator = ldapconnector.LDAPClientCreator(
reactor, self.protocol)
for (c, tls) in zip(self.configs, self.use_tls):
d = clientCreator.connect(dn='',
overrides=c.getServiceLocationOverrides())
if tls:
d.addCallback(lambda x: x.startTLS())
d.addCallback(self._cbConnectionMade)
d.addErrback(self._failConnection)
ldapserver.BaseLDAPServer.connectionMade(self)
def child_results(self, context):
assert self.filter is not None
cfg = context.locate(interfaces.ILDAPConfig)
c=ldapconnector.LDAPClientCreator(reactor, ldapclient.LDAPClient)
curDN = iwebui.ICurrentDN(context)
d=c.connectAnonymously(curDN,
cfg.getServiceLocationOverrides())
def _search(proto, dn, searchFilter, scope):
baseEntry = ldapsyntax.LDAPEntry(client=proto, dn=dn)
d=baseEntry.search(filterObject=searchFilter,
scope=scope,
sizeLimit=20,
sizeLimitIsNonFatal=True)
def _cb(result, proto):
proto.unbind()
return result
d.addBoth(_cb, proto)
return d
d.addCallback(_search, curDN, self.filter, self.data['scope'])
def connectionMade(self):
clientCreator = ldapconnector.LDAPClientCreator(
reactor, self.protocol)
d = clientCreator.connect(
dn='',
overrides=self.config.getServiceLocationOverrides())
d.addCallback(self._cbConnectionMade)
d.addErrback(self._failConnection)
ldapserver.BaseLDAPServer.connectionMade(self)