# File lib/activeldap/base.rb, line 179
    def Base.connect(config={}) # :user, :password_block, :logger
      # Process config
      # Class options
      ## These will be replace by configuration.rb defaults if defined
      @@config = {}
      @@config[:host] = config[:host] || @@host
      @@config[:port] = config[:port] || @@port
      if config[:base]
        Base.class_eval "def Base.base\n'\#{config[:base]}'\nend\n"
      end
      @@config[:bind_format] = config[:bind_format] || @@bind_format

      @@logger = config[:logger] || nil
      # Setup default logger to console
      if @@logger.nil?
        @@logger = Log4r::Logger.new('activeldap')
        @@logger.level = Log4r::OFF
        Log4r::StderrOutputter.new 'console'
        @@logger.add('console')
      end

      # Method options
      user = nil
      password_block = nil
      @@config[:allow_anonymous] = true
      @@config[:try_sasl] = false

      @@config[:user] = config[:user] || user
      @@config[:allow_anonymous] = config[:allow_anonymous] if config.has_key? :allow_anonymous
      @@config[:try_sasl] = config[:try_sasl]
      @@config[:password_block] = config[:password_block] if config.has_key? :password_block

      # Setup bind credentials
      @@config[:user] = ENV['USER'] unless @@config[:user]

      # Connect to LDAP
      begin
        # SSL using START_TLS
        @@conn = LDAP::SSLConn.new(@@config[:host], @@config[:port], true)
      rescue
        @@logger.warn "Warning: Failed to connect using TLS!"
        begin
          @@logger.warn "Warning: Attempting SSL connection . . ."
          @@conn = LDAP::SSLConn.new(@@config[:host], @@config[:port], false)
          # HACK: Load the schema here because otherwise you can't tell if the
          # HACK: SSLConn is a real SSL connection.
          @@schema = @@conn.schema() if @@schema.nil?
        rescue
          @@logger.warn "Warning: Attempting unencrypted connection . . ."
          @@conn = LDAP::Conn.new(@@config[:host], @@config[:port])
        end
      end
      @@logger.debug "Connected to #{@@config[:host]}:#{@@config[:port]}."

      # Enforce LDAPv3
      @@conn.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3)

      # Authenticate
      do_bind

      # Load Schema (if not straight SSL...)
      begin
        @@schema = @@conn.schema() if @@schema.nil?
      rescue => detail
        raise ConnectionError, "#{detail.exception} - LDAP connection failure, or server does not support schema queries."
      end

      # Cleanly return
      return true
    end