37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/active_ldap/adapter/ldap.rb', line 37
def connect(host, port, options={})
connection = LDAP::Conn.new(host, port)
if connection.get_option(LDAP::LDAP_OPT_PROTOCOL_VERSION) < 3
connection.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3)
end
tls_options = options[:tls_options]
if tls_options and LDAP.const_defined?(:LDAP_OPT_X_TLS_NEWCTX)
tls_options.each do |key, value|
case key
when :verify_mode
case value
when :none, OpenSSL::SSL::SSL_VERIFY_NONE
connection.set_option(LDAP::LDAP_OPT_X_TLS_REQUIRE_CERT,
LDAP::LDAP_OPT_X_TLS_NEVER)
when :peer, OpenSSL::SSL::SSL_VERIFY_PEER
connection.set_option(LDAP::LDAP_OPT_X_TLS_REQUIRE_CERT,
LDAP::LDAP_OPT_X_TLS_DEMAND)
end
when :verify_hostname
unless value
connection.set_option(LDAP::LDAP_OPT_X_TLS_REQUIRE_CERT,
LDAP::LDAP_OPT_X_TLS_ALLOW)
end
end
end
connection.set_option(LDAP::LDAP_OPT_X_TLS_NEWCTX, 0)
end
connection.start_tls
connection
end
|