Sha256: 6467ab78d836163e80e8ad4a3be1d3db74f8af10b9b78bb55cdfbfc75f21e575

Contents?: true

Size: 1.78 KB

Versions: 148

Compression:

Stored size: 1.78 KB

Contents

require 'puppet/util/ldap'
require 'puppet/util/methodhelper'

class Puppet::Util::Ldap::Connection
  include Puppet::Util::MethodHelper

  attr_accessor :host, :port, :user, :password, :reset, :ssl

  attr_reader :connection

  # Return a default connection, using our default settings.
  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

  def close
    connection.unbind if connection.bound?
  end

  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

  # Create a per-connection unique name.
  def name
    [host, port, user, password, ssl].collect { |p| p.to_s }.join("/")
  end

  # Should we reset the connection?
  def reset?
    reset
  end

  # Start our ldap connection.
  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}") % { detail: detail }, detail.backtrace
  end
end

Version data entries

148 entries across 148 versions & 2 rubygems

Version Path
bolt-0.6.1 vendored/puppet/lib/puppet/util/ldap/connection.rb
bolt-0.6.0 vendored/puppet/lib/puppet/util/ldap/connection.rb
bolt-0.5.1 vendored/puppet/lib/puppet/util/ldap/connection.rb
bolt-0.5.0 vendored/puppet/lib/puppet/util/ldap/connection.rb
puppet-5.3.2 lib/puppet/util/ldap/connection.rb
puppet-5.3.2-x86-mingw32 lib/puppet/util/ldap/connection.rb
puppet-5.3.2-x64-mingw32 lib/puppet/util/ldap/connection.rb
puppet-5.3.2-universal-darwin lib/puppet/util/ldap/connection.rb
puppet-5.3.1 lib/puppet/util/ldap/connection.rb
puppet-5.3.1-x86-mingw32 lib/puppet/util/ldap/connection.rb
puppet-5.3.1-x64-mingw32 lib/puppet/util/ldap/connection.rb
puppet-5.3.1-universal-darwin lib/puppet/util/ldap/connection.rb
puppet-5.2.0 lib/puppet/util/ldap/connection.rb
puppet-5.2.0-x86-mingw32 lib/puppet/util/ldap/connection.rb
puppet-5.2.0-x64-mingw32 lib/puppet/util/ldap/connection.rb
puppet-5.2.0-universal-darwin lib/puppet/util/ldap/connection.rb
puppet-5.1.0 lib/puppet/util/ldap/connection.rb
puppet-5.1.0-x86-mingw32 lib/puppet/util/ldap/connection.rb
puppet-5.1.0-x64-mingw32 lib/puppet/util/ldap/connection.rb
puppet-5.1.0-universal-darwin lib/puppet/util/ldap/connection.rb