我已成功使用python-ldap通过ldaps连接到Windows 2012 R2服务器。我用这个程序如下:无法从python-ldap连接到windows server 2016上的ldaps
Python代码:
import ldap
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
ldap.set_option(ldap.OPT_DEBUG_LEVEL, 255)
ip = '<redacted>'
url = "%s://%s:%d" % ('ldaps', ip, 636)
ld = ldap.initialize(url)
ld.protocol_version = 3
ld.set_option(ldap.OPT_REFERRALS, ldap.OPT_OFF)
user = '<redacted>'
passwd = '<redacted>'
ld.simple_bind_s('<redacted>\%s' % user, passwd)
和Windows服务器上,我使用了“服务器管理器”添加“AD CS”的角色,并创建了一个根证书。我不关心验证证书,只是使用一些加密。在创建根证书之后,服务器上启用了LDAPS,并且此代码运行时没有错误。
现在,我在windows server 2016上遵循了完全相同的过程,结果并不是很好。我已经设法从同一个脚本中得到一些错误。通常是'收到一个意外长度的TLS数据包'。或'推送功能出错'。我已经搜索了几个小时,但我一直无法找到解决方案。有谁知道是否需要额外的步骤在Windows服务器上进行配置,或者如果有关于我的脚本的内容不正确?
我正在测试的客户端是使用python 2.7和ubuntu 14.04。 pip2.7已将python-ldap库更新为最新版本。 Lere是脚本运行失败的一个例子:
ldap_create
ldap_url_parse_ext(ldaps://<redacted>:636)
ldap_sasl_bind
ldap_send_initial_request
ldap_new_connection 1 1 0
ldap_int_open_connection
ldap_connect_to_host: TCP <redacted>:636
ldap_new_socket: 3
ldap_prepare_socket: 3
ldap_connect_to_host: Trying <redacted>:636
ldap_pvt_connect: fd: 3 tm: -1 async: 0
TLS: can't connect: Error in the push function..
ldap_err2string
Traceback (most recent call last):
File "test_ldap.py", line 13, in <module>
ld.simple_bind_s('<redacted>\%s' % user, passwd)
File "/usr/local/lib/python2.7/dist-packages/ldap/ldapobject.py", line 228, in simple_bind_s
msgid = self.simple_bind(who,cred,serverctrls,clientctrls)
File "/usr/local/lib/python2.7/dist-packages/ldap/ldapobject.py", line 222, in simple_bind
return self._ldap_call(self._l.simple_bind,who,cred,RequestControlTuples(serverctrls),RequestControlTuples(clientctrls))
File "/usr/local/lib/python2.7/dist-packages/ldap/ldapobject.py", line 108, in _ldap_call
result = func(*args,**kwargs)
ldap.SERVER_DOWN: {'info': 'Error in the push function.', 'errno': 104, 'desc': "Can't contact LDAP server"}