Sha256: 9bee33ee436e73c3a1282166d23d9da61ad6aaffdb06079cdc3be359f489f90b

Contents?: true

Size: 1.81 KB

Versions: 148

Compression:

Stored size: 1.81 KB

Contents

require 'puppet/util/ldap'

class Puppet::Util::Ldap::Connection
  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
    user = Puppet.settings[:ldapuser]
    if user && user != ""
      options[:user] = user
      pass = Puppet.settings[:ldappassword]
      if pass && 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, user: nil, password: nil, reset: nil, ssl: nil)
    raise Puppet::Error, _("Could not set up LDAP Connection: Missing ruby/ldap libraries") unless Puppet.features.ldap?

    @host = host
    @port = port
    @user = user
    @password = password
    @reset = reset
    @ssl = ssl
  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 & 1 rubygems

Version Path
puppet-6.19.0 lib/puppet/util/ldap/connection.rb
puppet-6.19.0-x86-mingw32 lib/puppet/util/ldap/connection.rb
puppet-6.19.0-x64-mingw32 lib/puppet/util/ldap/connection.rb
puppet-6.19.0-universal-darwin lib/puppet/util/ldap/connection.rb
puppet-6.18.0 lib/puppet/util/ldap/connection.rb
puppet-6.18.0-x86-mingw32 lib/puppet/util/ldap/connection.rb
puppet-6.18.0-x64-mingw32 lib/puppet/util/ldap/connection.rb
puppet-6.18.0-universal-darwin lib/puppet/util/ldap/connection.rb
puppet-6.17.0 lib/puppet/util/ldap/connection.rb
puppet-6.17.0-x86-mingw32 lib/puppet/util/ldap/connection.rb
puppet-6.17.0-x64-mingw32 lib/puppet/util/ldap/connection.rb
puppet-6.17.0-universal-darwin lib/puppet/util/ldap/connection.rb
puppet-6.16.0 lib/puppet/util/ldap/connection.rb
puppet-6.16.0-x86-mingw32 lib/puppet/util/ldap/connection.rb
puppet-6.16.0-x64-mingw32 lib/puppet/util/ldap/connection.rb
puppet-6.16.0-universal-darwin lib/puppet/util/ldap/connection.rb
puppet-6.15.0 lib/puppet/util/ldap/connection.rb
puppet-6.15.0-x86-mingw32 lib/puppet/util/ldap/connection.rb
puppet-6.15.0-x64-mingw32 lib/puppet/util/ldap/connection.rb
puppet-6.15.0-universal-darwin lib/puppet/util/ldap/connection.rb