46: def connect
47: raise ArgumentError, "You must pass a block to #connect" unless block_given?
48:
49: unless defined?(@connection) and @connection
50: if Puppet[:ldaptls]
51: ssl = :tls
52: elsif Puppet[:ldapssl]
53: ssl = true
54: else
55: ssl = false
56: end
57: options = {:ssl => ssl}
58: if user = Puppet[:ldapuser] and user != ""
59: options[:user] = user
60: end
61: if password = Puppet[:ldappassword] and password != ""
62: options[:password] = password
63: end
64: @connection = Puppet::Util::Ldap::Connection.new(Puppet[:ldapserver], Puppet[:ldapport], options)
65: end
66: @connection.start
67: begin
68: yield @connection.connection
69: ensure
70: @connection.close
71: end
72: return nil
73: end