# class Puppet::Util::Ldap::Connection

### Attributes

connection[R]
host[RW]
password[RW]
port[RW]
reset[RW]
ssl[RW]
user[RW]

### Public Class Methods

instance() click to toggle source

Return a default connection, using our default settings.

    # File lib/puppet/util/ldap/connection.rb, line 12
    def self.instance
      ssl = if Puppet[:ldaptls]
        :tls
          elsif Puppet[:ldapssl]
            true
          else
            false
          end

      options = {}
      options[:ssl] = ssl
      if user = Puppet.settings[:ldapuser] and user != ""
        options[:user] = user
        if pass = Puppet.settings[:ldappassword] and pass != ""
          options[:password] = pass
        end
      end

      new(Puppet[:ldapserver], Puppet[:ldapport], options)
    end

new(host, port, options = {}) click to toggle source

    # File lib/puppet/util/ldap/connection.rb, line 37
    def initialize(host, port, options = {})
      raise Puppet::Error, "Could not set up LDAP Connection: Missing ruby/ldap libraries" unless Puppet.features.ldap?

      @host, @port = host, port

      set_options(options)
    end

### Public Instance Methods

close() click to toggle source

    # File lib/puppet/util/ldap/connection.rb, line 33
    def close
      connection.unbind if connection.bound?
    end

name() click to toggle source

Create a per-connection unique name.

    # File lib/puppet/util/ldap/connection.rb, line 46
    def name
      [host, port, user, password, ssl].collect { |p| p.to_s }.join("/")
    end

reset?() click to toggle source

Should we reset the connection?

    # File lib/puppet/util/ldap/connection.rb, line 51
    def reset?
      reset
    end

start() click to toggle source

Start our ldap connection.

    # File lib/puppet/util/ldap/connection.rb, line 56
    def start
        case ssl
        when :tls
          @connection = LDAP::SSLConn.new(host, port, true)
        when true
          @connection = LDAP::SSLConn.new(host, port)
        else
          @connection = LDAP::Conn.new(host, port)
        end
        @connection.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3)
        @connection.set_option(LDAP::LDAP_OPT_REFERRALS, LDAP::LDAP_OPT_ON)
        @connection.simple_bind(user, password)
    rescue => detail
        raise Puppet::Error, "Could not connect to LDAP: #{detail}"
    end