summaryrefslogtreecommitdiff
path: root/worker/tests/ldap.rb
blob: 35151bac901dffbbc9eb19a6bdabc75fac043afa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'timeout'


#
# Run an LDAP test.
#
#
# Return value
#   TRUE:  The host is up
#
#  FALSE:  The host is not up
#
def ldap_test ( params )

  #
  #  Get the hostname & port to test against.
  #
  host = params['target_host']
  port = params['test_port']

  puts "LDAP testing host #{host}:#{port}" if ( params['verbose'] )


  begin
    timeout(3) do

      begin
        socket = TCPSocket.new( host, port )
        socket.close()
        return true
      rescue
        puts "LDAP exception on host #{host}:#{port} - #{$!}" if ( params['verbose'] )
        return false
      end
    end
  rescue Timeout::Error => e
    puts "TIMEOUT: #{e}" if ( params['verbose'] )
    return false
  end
  puts "Misc failure" if ( params['verbose'] )
  return false
end