in client.py [0:0]
def main(config):
ldap_url = ldapurl.LDAPUrl(config['ldapurl'])
while True:
print('Connecting to %s...' % ldap_url.initializeUrl())
# Prepare the LDAP server connection (triggers the connection as well)
ldap_connection = SyncReplClient(ldap_url.initializeUrl())
if config.get("pubsuburl"):
ldap_connection.set_pubsub_url(config['pubsuburl'])
# Now we login to the LDAP server
try:
ldap_connection.simple_bind_s(ldap_url.who, ldap_url.cred)
except ldap.INVALID_CREDENTIALS as err:
print('Login to LDAP server failed: %s' % err)
sys.exit(1)
except ldap.SERVER_DOWN:
print('LDAP server is down, going to retry.')
time.sleep(5)
continue
# Commence the syncing
print('Starting syncrepl...')
ldap_search = ldap_connection.syncrepl_search(
ldap_url.dn or '',
ldap_url.scope or ldap.SCOPE_SUBTREE,
mode = 'refreshAndPersist',
attrlist=ldap_url.attrs,
filterstr = ldap_url.filterstr or '(objectClass=*)'
)
try:
while ldap_connection.syncrepl_poll( all = 1, msgid = ldap_search):
pass
except KeyboardInterrupt:
# User asked to exit
return
except Exception as err:
# Handle any exception
print('Unhandled exception, reconnecting in 5 seconds: %s' % err)
time.sleep(5)