ruby-ldap3 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/COPYING +24 -0
- data/ChangeLog +842 -0
- data/FAQ +58 -0
- data/LICENSE +28 -0
- data/NOTES +193 -0
- data/README +279 -0
- data/TODO +15 -0
- data/clientauth.c +605 -0
- data/conn.c +1918 -0
- data/entry.c +342 -0
- data/extconf.rb +310 -0
- data/ldap.c +650 -0
- data/lib/ldap/control.rb +50 -0
- data/lib/ldap/ldif.rb +564 -0
- data/lib/ldap/schema.rb +135 -0
- data/misc.c +512 -0
- data/mod.c +359 -0
- data/rbldap.h +207 -0
- data/saslconn.c +242 -0
- data/sslconn.c +377 -0
- data/test/add.rb +31 -0
- data/test/add2.rb +31 -0
- data/test/add3.rb +33 -0
- data/test/bind-ldaps.rb +25 -0
- data/test/bind-sasl.rb +17 -0
- data/test/bind-ssl.rb +25 -0
- data/test/bind.rb +34 -0
- data/test/compare.rb +17 -0
- data/test/conf.rb +12 -0
- data/test/delete.rb +13 -0
- data/test/ext.rb +49 -0
- data/test/misc1.rb +49 -0
- data/test/misc2.rb +40 -0
- data/test/modrdn.rb +23 -0
- data/test/moz_cert.rb +104 -0
- data/test/search.rb +20 -0
- data/test/search2.rb +34 -0
- data/test/search3.rb +23 -0
- data/test/setup.rb +38 -0
- data/test/subschema.rb +21 -0
- data/test/tc_conn.rb +123 -0
- data/test/tc_ldif.rb +174 -0
- data/test/tc_schema.rb +32 -0
- data/test/tc_search.rb +137 -0
- data/test/ts_ldap.rb +8 -0
- data/win/winlber.h +21 -0
- data/win/winldap.h +324 -0
- data/win/wldap32.def +257 -0
- metadata +97 -0
data/test/bind-ldaps.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
# This file is a part of test scripts of LDAP extension module.
|
3
|
+
|
4
|
+
$test = File.dirname($0)
|
5
|
+
require "#{$test}/conf"
|
6
|
+
require "./ldap"
|
7
|
+
|
8
|
+
case LDAP::LDAP_VENDOR_NAME
|
9
|
+
when /^OpenLDAP/i
|
10
|
+
# false means we use SSL connection.
|
11
|
+
conn = LDAP::SSLConn.new($HOST, $SSLPORT, false)
|
12
|
+
when /^Netscape/i
|
13
|
+
conn = LDAP::SSLConn.new($HOST, $SSLPORT,
|
14
|
+
false, File.expand_path("~/.netscape/cert7.db"))
|
15
|
+
conn.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3)
|
16
|
+
else
|
17
|
+
raise(RuntimeError, "unknown vendor")
|
18
|
+
end
|
19
|
+
|
20
|
+
v = conn.get_option(LDAP::LDAP_OPT_PROTOCOL_VERSION)
|
21
|
+
printf("protocol version = #{v}\n")
|
22
|
+
|
23
|
+
conn.bind{
|
24
|
+
conn.perror("bind")
|
25
|
+
}
|
data/test/bind-sasl.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
# This file is a part of test scripts of LDAP extension module.
|
3
|
+
|
4
|
+
$test = File.dirname($0)
|
5
|
+
require "#{$test}/conf"
|
6
|
+
require "./ldap"
|
7
|
+
|
8
|
+
cred = "secret"
|
9
|
+
|
10
|
+
conn = LDAP::Conn.new($HOST, $PORT)
|
11
|
+
|
12
|
+
v = conn.get_option(LDAP::LDAP_OPT_PROTOCOL_VERSION)
|
13
|
+
printf("protocol version = #{v}\n")
|
14
|
+
|
15
|
+
conn.sasl_bind(nil, LDAP::LDAP_SASL_SIMPLE, cred){
|
16
|
+
conn.perror("bind")
|
17
|
+
}
|
data/test/bind-ssl.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
# This file is a part of test scripts of LDAP extension module.
|
3
|
+
|
4
|
+
$test = File.dirname($0)
|
5
|
+
require "#{$test}/conf"
|
6
|
+
require "./ldap"
|
7
|
+
|
8
|
+
case LDAP::LDAP_VENDOR_NAME
|
9
|
+
when /^OpenLDAP/i
|
10
|
+
# true means we use start_tls extension.
|
11
|
+
conn = LDAP::SSLConn.new($HOST, $PORT, true)
|
12
|
+
when /^Netscape/i
|
13
|
+
conn = LDAP::SSLConn.new($HOST, $SSLPORT,
|
14
|
+
false, File.expand_path("~/.netscape/cert7.db"))
|
15
|
+
conn.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3)
|
16
|
+
else
|
17
|
+
raise(RuntimeError, "unknown vendor")
|
18
|
+
end
|
19
|
+
|
20
|
+
v = conn.get_option(LDAP::LDAP_OPT_PROTOCOL_VERSION)
|
21
|
+
printf("protocol version = #{v}\n")
|
22
|
+
|
23
|
+
conn.bind{
|
24
|
+
conn.perror("bind")
|
25
|
+
}
|
data/test/bind.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
# This file is a part of test scripts of LDAP extension module.
|
3
|
+
|
4
|
+
$test = File.dirname($0)
|
5
|
+
require "#{$test}/conf"
|
6
|
+
require "./ldap"
|
7
|
+
|
8
|
+
conn = LDAP::Conn.new($HOST, $PORT)
|
9
|
+
conn.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3)
|
10
|
+
conn.bind{
|
11
|
+
conn.perror("bind")
|
12
|
+
if( defined?(LDAP::LDAP_OPT_HOST_NAME) &&
|
13
|
+
defined?(LDAP::LDAP_OPT_PROTOCOL_VERSION) &&
|
14
|
+
defined?(LDAP::LDAP_OPT_API_INFO) ) # checking for LDAPv3 API
|
15
|
+
host = conn.get_option(LDAP::LDAP_OPT_HOST_NAME)
|
16
|
+
proto = conn.get_option(LDAP::LDAP_OPT_PROTOCOL_VERSION)
|
17
|
+
begin
|
18
|
+
info = conn.get_option(LDAP::LDAP_OPT_API_INFO)
|
19
|
+
rescue LDAP::Error
|
20
|
+
info = nil
|
21
|
+
end
|
22
|
+
print("host = #{host}, proto = #{proto}\n",
|
23
|
+
"info.protocol_version = #{info.protocol_version}\n")
|
24
|
+
end
|
25
|
+
}
|
26
|
+
|
27
|
+
begin
|
28
|
+
conn.bind
|
29
|
+
rescue LDAP::InvalidDataError
|
30
|
+
$ok = true
|
31
|
+
end
|
32
|
+
if( ! $ok )
|
33
|
+
raise(RuntimeError, "multiple bind calls")
|
34
|
+
end
|
data/test/compare.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
# This file is a part of test scripts of LDAP extension module.
|
3
|
+
|
4
|
+
$test = File.dirname($0)
|
5
|
+
require "#{$test}/conf"
|
6
|
+
require "./ldap"
|
7
|
+
|
8
|
+
LDAP::Conn.new($HOST, $PORT).bind{|conn|
|
9
|
+
conn.perror("bind")
|
10
|
+
begin
|
11
|
+
conn.compare("cn=Takaaki Tateishi, dc=localhost, dc=localdomain",
|
12
|
+
"cn", "Takaaki Tateishi")
|
13
|
+
rescue LDAP::ResultError
|
14
|
+
exit(0)
|
15
|
+
end
|
16
|
+
exit(1)
|
17
|
+
}
|
data/test/conf.rb
ADDED
data/test/delete.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
# This file is a part of test scripts of LDAP extension module.
|
3
|
+
|
4
|
+
$test = File.dirname($0)
|
5
|
+
require "#{$test}/conf"
|
6
|
+
require "./ldap"
|
7
|
+
|
8
|
+
conn = LDAP::Conn.new($HOST, $PORT)
|
9
|
+
conn.bind('cn=root, dc=localhost, dc=localdomain','secret'){
|
10
|
+
conn.perror("bind")
|
11
|
+
conn.delete("cn=Takaaki-Tateishi, dc=localhost, dc=localdomain")
|
12
|
+
conn.perror("delete")
|
13
|
+
}
|
data/test/ext.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
# This file is a part of test scripts of LDAP extension module.
|
3
|
+
|
4
|
+
$test = File.dirname($0)
|
5
|
+
require "#{$test}/conf"
|
6
|
+
require "./ldap"
|
7
|
+
|
8
|
+
conn = LDAP::Conn.new($HOST, $PORT)
|
9
|
+
conn.bind('cn=root, dc=localhost, dc=localdomain','secret'){
|
10
|
+
conn.perror("bind")
|
11
|
+
begin
|
12
|
+
(1..200).each{|i|
|
13
|
+
entry = {
|
14
|
+
'objectclass' => ['top', 'person'],
|
15
|
+
'cn' => ["User #{i}"],
|
16
|
+
'sn' => ["user#{i}"],
|
17
|
+
}
|
18
|
+
conn.add("cn=User #{i}, dc=localhost, dc=localdomain", entry)
|
19
|
+
}
|
20
|
+
rescue LDAP::ResultError
|
21
|
+
conn.perror("add")
|
22
|
+
exit(1)
|
23
|
+
end
|
24
|
+
conn.perror("add")
|
25
|
+
|
26
|
+
if( !defined?(conn.search_ext) )
|
27
|
+
exit(0)
|
28
|
+
end
|
29
|
+
|
30
|
+
users = []
|
31
|
+
begin
|
32
|
+
conn.search_ext("dc=localhost, dc=localdomain",
|
33
|
+
LDAP::LDAP_SCOPE_SUBTREE,
|
34
|
+
"(&(objectclass=*)(cn=User*))",
|
35
|
+
nil, false, # attrs, attrsonly
|
36
|
+
nil, nil, # serverctrls, clientctrls
|
37
|
+
0, 0, # sec, usec
|
38
|
+
100){|e| # sizelimit
|
39
|
+
users.push(e.vals("sn"))
|
40
|
+
}
|
41
|
+
rescue LDAP::ResultError
|
42
|
+
conn.perror("search_ext")
|
43
|
+
if( conn.err == LDAP::LDAP_SIZELIMIT_EXCEEDED )
|
44
|
+
exit(0)
|
45
|
+
else
|
46
|
+
exit(1)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
}
|
data/test/misc1.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
$test = File.dirname($0)
|
4
|
+
require "#{$test}/conf"
|
5
|
+
require "./ldap"
|
6
|
+
|
7
|
+
def admin_bind
|
8
|
+
@ldap_conn.bind("cn=root, dc=localhost, dc=localdomain", 'secret')
|
9
|
+
end
|
10
|
+
|
11
|
+
#test method goes here
|
12
|
+
|
13
|
+
def add_ou(agency)
|
14
|
+
#creates an organizational unit and places an agency inside
|
15
|
+
begin
|
16
|
+
entry = {
|
17
|
+
'objectclass' => ['organizationalUnit'],
|
18
|
+
'ou' => [agency]
|
19
|
+
}
|
20
|
+
admin_bind.add("ou=#{entry['ou'][0]}, dc=localhost, dc=localdomain", entry)
|
21
|
+
return(true)
|
22
|
+
rescue LDAP::ResultError => error
|
23
|
+
return(false)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def delete_ou(agency)
|
28
|
+
#removes an agency organizational unit
|
29
|
+
begin
|
30
|
+
admin_bind.delete("ou=#{agency}, dc=localhost, dc=localdomain")
|
31
|
+
return(true)
|
32
|
+
rescue LDAP::ResultError => error
|
33
|
+
return(false)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
@ldap_conn = LDAP::Conn.new($HOST, $PORT)
|
38
|
+
|
39
|
+
p LDAP::VERSION
|
40
|
+
begin
|
41
|
+
(1..1000).each do |count|
|
42
|
+
p count
|
43
|
+
p add_ou("an_agency")
|
44
|
+
p delete_ou("an_agency")
|
45
|
+
end
|
46
|
+
rescue LDAP::Error
|
47
|
+
exit(0)
|
48
|
+
end
|
49
|
+
exit(1)
|
data/test/misc2.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
$test = File.dirname($0)
|
4
|
+
require "#{$test}/conf"
|
5
|
+
require "./ldap"
|
6
|
+
|
7
|
+
def add_ou(agency)
|
8
|
+
#creates an organizational unit and places an agency inside
|
9
|
+
begin
|
10
|
+
entry = {
|
11
|
+
'objectclass' => ['organizationalUnit'],
|
12
|
+
'ou' => [agency]
|
13
|
+
}
|
14
|
+
@ldap_conn.add("ou=#{entry['ou'][0]}, dc=localhost, dc=localdomain", entry)
|
15
|
+
return(true)
|
16
|
+
rescue LDAP::ResultError => error
|
17
|
+
return(false)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def delete_ou(agency)
|
22
|
+
#removes an agency organizational unit
|
23
|
+
begin
|
24
|
+
@ldap_conn.delete("ou=#{agency}, dc=localhost, dc=localdomain")
|
25
|
+
return(true)
|
26
|
+
rescue LDAP::ResultError => error
|
27
|
+
return(false)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
@ldap_conn = LDAP::Conn.new($HOST, $PORT)
|
32
|
+
@ldap_conn.bind("cn=root, dc=localhost, dc=localdomain", 'secret')
|
33
|
+
|
34
|
+
p LDAP::VERSION
|
35
|
+
(1..100).each do |count|
|
36
|
+
p count
|
37
|
+
p add_ou("an_agency")
|
38
|
+
p delete_ou("an_agency")
|
39
|
+
GC.start
|
40
|
+
end
|
data/test/modrdn.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
# This file is a part of test scripts of LDAP extension module.
|
3
|
+
|
4
|
+
$test = File.dirname($0)
|
5
|
+
require "#{$test}/conf"
|
6
|
+
require "./ldap"
|
7
|
+
|
8
|
+
conn = LDAP::Conn.new($HOST, $PORT)
|
9
|
+
|
10
|
+
begin
|
11
|
+
conn.bind('cn=root, dc=localhost, dc=localdomain','seret')
|
12
|
+
rescue LDAP::ResultError => e
|
13
|
+
$stderr.print("#{e.inspect} ... expected.\n")
|
14
|
+
conn.bind('cn=root, dc=localhost, dc=localdomain','secret'){
|
15
|
+
conn.perror("bind")
|
16
|
+
conn.modrdn("cn=Takaaki Tateishi, dc=localhost, dc=localdomain",
|
17
|
+
"cn=Takaaki-Tateishi",
|
18
|
+
true)
|
19
|
+
conn.perror("modrdn")
|
20
|
+
}
|
21
|
+
exit(0)
|
22
|
+
end
|
23
|
+
exit(1)
|
data/test/moz_cert.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'ldap'
|
5
|
+
require 'optparse'
|
6
|
+
require 'pp'
|
7
|
+
|
8
|
+
options = {
|
9
|
+
:host => 'localhost',
|
10
|
+
:port => '389',
|
11
|
+
:scope => 'base',
|
12
|
+
:filter => '(objectclass=*)',
|
13
|
+
:key_pw => ''
|
14
|
+
}
|
15
|
+
|
16
|
+
optparse = OptionParser.new do |opts|
|
17
|
+
opts.on("-P", "--certpath [CERTFILE]", "cert8 path") do |cp|
|
18
|
+
options[:cp] = cp
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on("-N", "--certname [CERTNAME]", "certificate name") do |opt|
|
22
|
+
options[:cn] = opt
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.on("-W", "--keypassword PASSWORD", "key password") do |opt|
|
26
|
+
options[:key_pw] = opt
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on("-h", "--host HOST", "server hostname") do |host|
|
30
|
+
options[:host] = host
|
31
|
+
end
|
32
|
+
|
33
|
+
opts.on("-p", "--port PORT", "server port") do |opt|
|
34
|
+
options[:port] = opt
|
35
|
+
end
|
36
|
+
|
37
|
+
opts.on("-b", "--base [BASE]", "search base") do |opt|
|
38
|
+
options[:base] = opt
|
39
|
+
end
|
40
|
+
|
41
|
+
opts.on("-s", "--scope SCOPE", "search scope") do |opt|
|
42
|
+
options[:scope] = opt
|
43
|
+
end
|
44
|
+
|
45
|
+
opts.on("-f", "--filter FILTER", "search filter") do |opt|
|
46
|
+
options[:filter] = opt
|
47
|
+
end
|
48
|
+
|
49
|
+
opts.on("-a", "--attributes ATTRS", "attrs to return") do |opt|
|
50
|
+
options[:attrs] = opt.split(/ *, */)
|
51
|
+
end
|
52
|
+
|
53
|
+
opts.on("--help") do |opt|
|
54
|
+
puts opts
|
55
|
+
exit 0
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
optparse.parse!
|
60
|
+
|
61
|
+
required_keys = [:cp, :cn, :base]
|
62
|
+
if (required_keys - options.keys).length > 0
|
63
|
+
puts "Some options are missing."
|
64
|
+
puts optparse
|
65
|
+
exit 1
|
66
|
+
end
|
67
|
+
|
68
|
+
options[:scope] = case options[:scope]
|
69
|
+
when "sub"
|
70
|
+
LDAP::LDAP_SCOPE_SUBTREE
|
71
|
+
when "one"
|
72
|
+
LDAP::LDAP_SCOPE_ONELEVEL
|
73
|
+
else
|
74
|
+
LDAP::LDAP_SCOPE_BASE
|
75
|
+
end
|
76
|
+
|
77
|
+
raise ArgumentError.new("cert file's missing") unless (File.exists? options[:cp])
|
78
|
+
|
79
|
+
#Signal.trap("INT") { puts("INT"); exit(2); }
|
80
|
+
|
81
|
+
# Connect
|
82
|
+
conn = LDAP::SSLAuthConn.new(options[:host], options[:port].to_i, true,
|
83
|
+
File.expand_path(options[:cp]), options[:cn], options[:key_pw])
|
84
|
+
conn.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3)
|
85
|
+
|
86
|
+
|
87
|
+
# oid = '2.16.840.1.113730.3.4.15' # get bound DN
|
88
|
+
# bindctls = [LDAP::Control.new(oid, "", false)]
|
89
|
+
# pass bindctls as argument to bind()
|
90
|
+
|
91
|
+
begin
|
92
|
+
conn.bind
|
93
|
+
|
94
|
+
results = {}
|
95
|
+
conn.search(options[:base], options[:scope], options[:filter], options[:attrs], false, 10) do |entry|
|
96
|
+
results[entry.dn] = entry.to_hash
|
97
|
+
end
|
98
|
+
|
99
|
+
pp results
|
100
|
+
rescue LDAP::ResultError => e
|
101
|
+
puts "error: #{e.to_s}"
|
102
|
+
end
|
103
|
+
|
104
|
+
exit 0
|
data/test/search.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
# This file is a part of test scripts of LDAP extension module.
|
3
|
+
|
4
|
+
$test = File.dirname($0)
|
5
|
+
require "#{$test}/conf"
|
6
|
+
require "./ldap"
|
7
|
+
|
8
|
+
LDAP::Conn.new($HOST, $PORT).bind{|conn|
|
9
|
+
conn.perror("bind")
|
10
|
+
begin
|
11
|
+
conn.search("dc=localhost, dc=localdomain",
|
12
|
+
LDAP::LDAP_SCOPE_SUBTREE,
|
13
|
+
"(objectclass=*)"){|e|
|
14
|
+
p e.vals("cn")
|
15
|
+
p e.to_hash()
|
16
|
+
}
|
17
|
+
rescue LDAP::ResultError => msg
|
18
|
+
$stderr.print(msg)
|
19
|
+
end
|
20
|
+
}
|
data/test/search2.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
# This file is a part of test scripts of LDAP extension module.
|
3
|
+
|
4
|
+
$test = File.dirname($0)
|
5
|
+
require "#{$test}/conf"
|
6
|
+
require "./ldap"
|
7
|
+
|
8
|
+
sorter = proc{|s1,s2|
|
9
|
+
print("sorter: #{s1} <=> #{s2}\n")
|
10
|
+
s1<=>s2
|
11
|
+
}
|
12
|
+
|
13
|
+
LDAP::Conn.new($HOST, $PORT).bind{|conn|
|
14
|
+
conn.perror("bind")
|
15
|
+
sub = nil
|
16
|
+
conn.search("dc=localhost, dc=localdomain", LDAP::LDAP_SCOPE_SUBTREE,
|
17
|
+
"(objectclass=*)", nil, false, 0, 0, "sn", sorter){|e|
|
18
|
+
dn = e.dn
|
19
|
+
print("# #{LDAP.dn2ufn(dn)}\n")
|
20
|
+
print("dn: #{dn}\n")
|
21
|
+
e.attrs.each{|attr|
|
22
|
+
print("#{attr}: #{e.vals(attr).join(', ')}\n")
|
23
|
+
}
|
24
|
+
print("\n")
|
25
|
+
sub = e if !sub
|
26
|
+
}
|
27
|
+
|
28
|
+
begin
|
29
|
+
sub.dn
|
30
|
+
rescue LDAP::InvalidEntryError => e
|
31
|
+
$stderr.print("#{e.to_s}.\n",
|
32
|
+
"This exception is expected.\n")
|
33
|
+
end
|
34
|
+
}
|
data/test/search3.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
# This file is a part of test scripts of LDAP extension module.
|
3
|
+
|
4
|
+
$test = File.dirname($0)
|
5
|
+
require "#{$test}/conf"
|
6
|
+
require "./ldap"
|
7
|
+
|
8
|
+
$KCODE = "UTF8"
|
9
|
+
|
10
|
+
conn = LDAP::Conn.new($HOST, $PORT)
|
11
|
+
conn.perror("bind")
|
12
|
+
conn.bind{
|
13
|
+
# search2 returns an array of hash
|
14
|
+
print("search2 without a block:\n")
|
15
|
+
conn.search2("dc=localhost, dc=localdomain", LDAP::LDAP_SCOPE_SUBTREE,
|
16
|
+
"(objectclass=*)", nil, false, 0, 0).each{|ent|
|
17
|
+
ent.each{|attr,vals|
|
18
|
+
print("#{attr}: #{vals.join(', ')}\n")
|
19
|
+
}
|
20
|
+
print("\n")
|
21
|
+
}
|
22
|
+
GC.start()
|
23
|
+
}
|
data/test/setup.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# $Id: setup.rb,v 1.3 2005/03/13 10:10:56 ianmacd Exp $
|
2
|
+
#
|
3
|
+
# Basic set-up for performing LDAP unit tests.
|
4
|
+
|
5
|
+
require 'ldap'
|
6
|
+
require 'ldap/schema'
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
class TC_LDAPTest < Test::Unit::TestCase
|
10
|
+
|
11
|
+
@@conn = nil
|
12
|
+
|
13
|
+
# Get the LDAP host and base DN from /etc/ldap.conf.
|
14
|
+
def setup
|
15
|
+
unless @@conn && @@conn.bound?
|
16
|
+
File.open( '/etc/ldap.conf' ) do |f|
|
17
|
+
while line = f.gets
|
18
|
+
if line =~ /^host\s+(\S+)$/
|
19
|
+
@@host = $1
|
20
|
+
break
|
21
|
+
elsif line =~ /^base\s+(\S+)$/
|
22
|
+
@@base = $1
|
23
|
+
break
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
@@conn = LDAP::Conn.new( @@host )
|
29
|
+
@@conn.set_option( LDAP::LDAP_OPT_PROTOCOL_VERSION, 3 )
|
30
|
+
@@conn.bind
|
31
|
+
@@root_dse = @@conn.root_dse[0]
|
32
|
+
@@naming_context = @@root_dse['namingContexts'][0]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
undef_method :default_test
|
37
|
+
|
38
|
+
end
|
data/test/subschema.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
$test = File.dirname($0)
|
3
|
+
require "#{$test}/conf"
|
4
|
+
require "./ldap"
|
5
|
+
require "#{$test}/../lib/ldap/schema"
|
6
|
+
|
7
|
+
conn = LDAP::Conn.new($HOST, $PORT)
|
8
|
+
conn.bind{
|
9
|
+
schema = conn.schema()
|
10
|
+
p schema.must("person")
|
11
|
+
p schema.attr("person", "MUST")
|
12
|
+
p schema.may("person")
|
13
|
+
p schema.attr("person", "MAY")
|
14
|
+
p schema.sup("person")
|
15
|
+
p schema.attr("person", "SUP")
|
16
|
+
schema.each{|key,vals|
|
17
|
+
vals.each{|val|
|
18
|
+
print("#{key}: #{val}\n")
|
19
|
+
}
|
20
|
+
}
|
21
|
+
}
|
data/test/tc_conn.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
# $Id: tc_conn.rb,v 1.3 2005/03/15 01:43:59 ianmacd Exp $
|
2
|
+
#
|
3
|
+
# A suite of unit tests for testing Ruby/LDAP connection functionality.
|
4
|
+
|
5
|
+
require 'ldap'
|
6
|
+
require 'test/unit'
|
7
|
+
require './setup'
|
8
|
+
|
9
|
+
class TC_ConnectionTest < TC_LDAPTest
|
10
|
+
|
11
|
+
# Ensure that rebinding works.
|
12
|
+
#
|
13
|
+
def test_rebind
|
14
|
+
id = @@conn.object_id
|
15
|
+
|
16
|
+
assert_nothing_raised do
|
17
|
+
@@conn.unbind
|
18
|
+
@@conn.bind
|
19
|
+
end
|
20
|
+
|
21
|
+
id2 = @@conn.object_id
|
22
|
+
assert_equal( id, id2 )
|
23
|
+
|
24
|
+
assert_nothing_raised do
|
25
|
+
@@conn.unbind
|
26
|
+
@@conn.simple_bind
|
27
|
+
end
|
28
|
+
|
29
|
+
id2 = @@conn.object_id
|
30
|
+
assert_equal( id, id2 )
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_double_bind
|
34
|
+
assert_raises( LDAP::Error ) { @@conn.bind }
|
35
|
+
assert_raises( LDAP::Error ) { @@conn.simple_bind }
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_double_unbind
|
39
|
+
assert_nothing_raised { @@conn.unbind }
|
40
|
+
assert_raises( LDAP::InvalidDataError ) { @@conn.unbind }
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_bound?
|
44
|
+
assert( @@conn.bound? )
|
45
|
+
@@conn.unbind
|
46
|
+
assert( ! @@conn.bound? )
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_sasl_bind
|
50
|
+
@@conn = LDAP::Conn.new( @@host )
|
51
|
+
@@conn.sasl_quiet = true
|
52
|
+
|
53
|
+
assert_nothing_raised { @@conn.sasl_bind( '', '' ) }
|
54
|
+
|
55
|
+
@@conn = nil
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_double_sasl_bind
|
59
|
+
@@conn = LDAP::Conn.new( @@host )
|
60
|
+
@@conn.sasl_quiet = true
|
61
|
+
|
62
|
+
assert_nothing_raised { @@conn.sasl_bind( '', '' ) }
|
63
|
+
assert_raises( LDAP::Error ) { @@conn.sasl_bind( '', '' ) }
|
64
|
+
|
65
|
+
@@conn = nil
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_sasl_rebind
|
69
|
+
@@conn = LDAP::Conn.new( @@host )
|
70
|
+
@@conn.sasl_quiet = true
|
71
|
+
|
72
|
+
id = @@conn.object_id
|
73
|
+
|
74
|
+
assert_nothing_raised do
|
75
|
+
@@conn.unbind
|
76
|
+
@@conn.sasl_bind( '', '' )
|
77
|
+
end
|
78
|
+
|
79
|
+
id2 = @@conn.object_id
|
80
|
+
assert_equal( id, id2 )
|
81
|
+
|
82
|
+
@@conn = nil
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_ssl_rebind
|
86
|
+
@@conn = LDAP::SSLConn.new( @@host, LDAP::LDAPS_PORT )
|
87
|
+
|
88
|
+
id = @@conn.object_id
|
89
|
+
|
90
|
+
assert_nothing_raised do
|
91
|
+
@@conn.bind
|
92
|
+
@@conn.unbind
|
93
|
+
@@conn.bind
|
94
|
+
end
|
95
|
+
|
96
|
+
id2 = @@conn.object_id
|
97
|
+
assert_equal( id, id2 )
|
98
|
+
|
99
|
+
@@conn = nil
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_ssl_open
|
103
|
+
assert_raises( NotImplementedError ) { LDAP::SSLConn.open( @@host ) }
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_ssl_starttls_rebind
|
107
|
+
@@conn = LDAP::SSLConn.new( @@host, LDAP::LDAP_PORT, true )
|
108
|
+
|
109
|
+
id = @@conn.object_id
|
110
|
+
|
111
|
+
assert_nothing_raised do
|
112
|
+
@@conn.bind
|
113
|
+
@@conn.unbind
|
114
|
+
@@conn.bind
|
115
|
+
end
|
116
|
+
|
117
|
+
id2 = @@conn.object_id
|
118
|
+
assert_equal( id, id2 )
|
119
|
+
|
120
|
+
@@conn = nil
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|