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
puppet-5.5.22 lib/puppet/util/ldap/connection.rb
puppet-5.5.22-x86-mingw32 lib/puppet/util/ldap/connection.rb
puppet-5.5.22-x64-mingw32 lib/puppet/util/ldap/connection.rb
puppet-5.5.22-universal-darwin lib/puppet/util/ldap/connection.rb
puppet-5.5.21 lib/puppet/util/ldap/connection.rb
puppet-5.5.21-x86-mingw32 lib/puppet/util/ldap/connection.rb
puppet-5.5.21-x64-mingw32 lib/puppet/util/ldap/connection.rb
puppet-5.5.21-universal-darwin lib/puppet/util/ldap/connection.rb
puppet-5.5.20 lib/puppet/util/ldap/connection.rb
puppet-5.5.20-x86-mingw32 lib/puppet/util/ldap/connection.rb
puppet-5.5.20-x64-mingw32 lib/puppet/util/ldap/connection.rb
puppet-5.5.20-universal-darwin lib/puppet/util/ldap/connection.rb
puppet-5.5.19 lib/puppet/util/ldap/connection.rb
puppet-5.5.19-x86-mingw32 lib/puppet/util/ldap/connection.rb
puppet-5.5.19-x64-mingw32 lib/puppet/util/ldap/connection.rb
puppet-5.5.19-universal-darwin lib/puppet/util/ldap/connection.rb
puppet-5.5.18 lib/puppet/util/ldap/connection.rb
puppet-5.5.18-x86-mingw32 lib/puppet/util/ldap/connection.rb
puppet-5.5.18-x64-mingw32 lib/puppet/util/ldap/connection.rb
puppet-5.5.18-universal-darwin lib/puppet/util/ldap/connection.rb