summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util/ldap/connection.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-05-12 17:00:48 -0500
committerLuke Kanies <luke@madstop.com>2008-05-12 17:00:48 -0500
commit17e8158e35336291c551da03067b55dd815ab539 (patch)
tree7783b1f3d08ea9eeea7116d522018acabf438f10 /lib/puppet/util/ldap/connection.rb
parentc56e9a6a0a9491270e22363e750046f284ee2793 (diff)
downloadpuppet-17e8158e35336291c551da03067b55dd815ab539.tar.gz
puppet-17e8158e35336291c551da03067b55dd815ab539.tar.xz
puppet-17e8158e35336291c551da03067b55dd815ab539.zip
Adding ldap providers for the user and group type.
These providers use posixAccount and posixGroup. This is a collapsed merge, fwiw.
Diffstat (limited to 'lib/puppet/util/ldap/connection.rb')
-rw-r--r--lib/puppet/util/ldap/connection.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/puppet/util/ldap/connection.rb b/lib/puppet/util/ldap/connection.rb
new file mode 100644
index 000000000..abcc07ecb
--- /dev/null
+++ b/lib/puppet/util/ldap/connection.rb
@@ -0,0 +1,57 @@
+#
+# Created by Luke Kanies on 2008-3-23.
+# Copyright (c) 2008. All rights reserved.
+require 'puppet/util/ldap'
+
+class Puppet::Util::Ldap::Connection
+ attr_accessor :host, :port, :user, :password, :reset, :ssl
+
+ attr_reader :connection
+
+ 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
+
+ options.each do |param, value|
+ begin
+ send(param.to_s + "=", value)
+ rescue
+ raise ArgumentError, "LDAP connections do not support %s parameters" % param
+ end
+ end
+ 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
+ begin
+ 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: %s" % detail
+ end
+ end
+end