2

I want to create a ldap test server with python and import all data with a ldif file.

import ldap
import slapdtest

with slapdtest.SlapdObject() as server:

    server.start()

    with open('ldap_dump.ldif') as fd:
        server.ldapadd(fd.read(), ['-D', 'cn=User,dc=institute.edu'])

    root_dn = server.root_dn
    root_pw = server.root_pw

    connect = ldap.initialize(f"ldap://{server.hostname}")
    connect.set_option(ldap.OPT_REFERRALS, 0)
    connect.simple_bind_s(root_dn, root_pw)

    result = connect.search_s(...)

But I have the problem, that I get the error message that the ldap server is down (ldap.SERVER_DOWN: {'result': -1, 'desc': "Can't contact LDAP server", 'errno': 107, 'ctrls': [], 'info': 'Transport endpoint is not connected'}).

ikreb
  • 2,133
  • 1
  • 16
  • 35
  • 1
    check if the server starts listining to 123 or not, btw if your ldap is not run by a root service, he cant use usual ports, so try somehitng like 1389 – Hamza Tahiri Oct 26 '20 at 12:18
  • 2
    The server should be trying to access an already allocated port or unpermitted port. try a different port. BTW, if you are looking for a test LDAP server try ```https://github.com/Upekshe/simple-ldap-server```, or the dockerized version ```https://hub.docker.com/r/upekshejay/simple-ldap-test-server``` – MarterJay Jun 21 '21 at 08:07

0 Answers0