class ActiveLdap::Adapter::Ldap::Method::TLS

def connect(host, port, options={})

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

def start_tls?

def start_tls?
  true
end