ruby-ldap 0.9.9
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.
- data/COPYING +24 -0
- data/ChangeLog +762 -0
- data/FAQ +62 -0
- data/NOTES +77 -0
- data/README +266 -0
- data/TODO +15 -0
- data/conn.c +1810 -0
- data/entry.c +215 -0
- data/extconf.rb +268 -0
- data/ldap.c +577 -0
- data/lib/ldap/control.rb +50 -0
- data/lib/ldap/ldif.rb +569 -0
- data/lib/ldap/schema.rb +129 -0
- data/misc.c +512 -0
- data/mod.c +355 -0
- data/rbldap.h +194 -0
- data/saslconn.c +176 -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/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 +124 -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
- metadata +100 -0
data/test/add.rb
ADDED
@@ -0,0 +1,31 @@
|
|
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
|
+
entry1 = [
|
12
|
+
LDAP.mod(LDAP::LDAP_MOD_ADD, 'objectclass', ['top', 'domain']),
|
13
|
+
LDAP.mod(LDAP::LDAP_MOD_ADD, 'o', ['TTSKY.NET']),
|
14
|
+
LDAP.mod(LDAP::LDAP_MOD_ADD, 'dc', ['localhost']),
|
15
|
+
]
|
16
|
+
|
17
|
+
entry2 = [
|
18
|
+
LDAP.mod(LDAP::LDAP_MOD_ADD, 'objectclass', ['top', 'person']),
|
19
|
+
LDAP.mod(LDAP::LDAP_MOD_ADD, 'cn', ['Takaaki Tateishi']),
|
20
|
+
LDAP.mod(LDAP::LDAP_MOD_ADD | LDAP::LDAP_MOD_BVALUES, 'sn', ['ttate','Tateishi', "zero\000zero"]),
|
21
|
+
]
|
22
|
+
|
23
|
+
begin
|
24
|
+
conn.add("dc=localhost, dc=localdomain", entry1)
|
25
|
+
conn.add("cn=Takaaki Tateishi, dc=localhost, dc=localdomain", entry2)
|
26
|
+
rescue LDAP::ResultError
|
27
|
+
conn.perror("add")
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
conn.perror("add")
|
31
|
+
}
|
data/test/add2.rb
ADDED
@@ -0,0 +1,31 @@
|
|
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
|
+
entry1 = {
|
12
|
+
'objectclass' => ['top', 'person'],
|
13
|
+
'cn' => ['Tatsuya Kawai'],
|
14
|
+
'sn' => ['kawai'],
|
15
|
+
}
|
16
|
+
|
17
|
+
entry2 = {
|
18
|
+
'objectclass' => ['top', 'person'],
|
19
|
+
'cn' => ['Mio Tanaka'],
|
20
|
+
'sn' => ['mit','mio'],
|
21
|
+
}
|
22
|
+
|
23
|
+
begin
|
24
|
+
conn.add("cn=#{entry1['cn'][0]}, dc=localhost, dc=localdomain", entry1)
|
25
|
+
conn.add("cn=#{entry2['cn'][0]}, dc=localhost, dc=localdomain", entry2)
|
26
|
+
rescue LDAP::ResultError
|
27
|
+
conn.perror("add")
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
conn.perror("add")
|
31
|
+
}
|
data/test/add3.rb
ADDED
@@ -0,0 +1,33 @@
|
|
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.bind('cn=root, dc=localhost, dc=localdomain','secret'){
|
12
|
+
conn.perror("bind")
|
13
|
+
entry1 = {
|
14
|
+
'objectclass' => ['top', 'person'],
|
15
|
+
'cn' => ['立石 孝彰'],
|
16
|
+
'sn' => ['孝彰'],
|
17
|
+
}
|
18
|
+
|
19
|
+
entry2 = {
|
20
|
+
'objectclass' => ['top', 'person'],
|
21
|
+
'cn' => ['たていし たかあき'],
|
22
|
+
'sn' => ['たていし','たかあき'],
|
23
|
+
}
|
24
|
+
|
25
|
+
begin
|
26
|
+
conn.add("cn=#{entry1['cn'][0]}, dc=localhost, dc=localdomain", entry1)
|
27
|
+
conn.add("cn=#{entry2['cn'][0]}, dc=localhost, dc=localdomain", entry2)
|
28
|
+
rescue LDAP::ResultError
|
29
|
+
conn.perror("add")
|
30
|
+
exit
|
31
|
+
end
|
32
|
+
conn.perror("add")
|
33
|
+
}
|
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/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
|
+
}
|