ruby-activeldap 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/activeldap/associations.rb +122 -0
- data/lib/activeldap/base.rb +1094 -0
- data/lib/activeldap/configuration.rb +25 -0
- data/lib/activeldap/schema2.rb +141 -0
- data/lib/activeldap.rb +889 -0
- metadata +53 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
module ActiveLDAP
|
3
|
+
# Configuration
|
4
|
+
#
|
5
|
+
# Configuration provides the default settings required for
|
6
|
+
# ActiveLDAP to work with your LDAP server. All of these
|
7
|
+
# settings can be passed in at initialization time.
|
8
|
+
module Configuration
|
9
|
+
@@host = "localhost"
|
10
|
+
@@port = 389
|
11
|
+
@@bind_format = "uid=%s,ou=People,dc=example,dc=com"
|
12
|
+
|
13
|
+
# Make the return value the string that is your LDAP base
|
14
|
+
def Base.base
|
15
|
+
'dc=example,dc=com'
|
16
|
+
end
|
17
|
+
|
18
|
+
# This is optionally set to the array of objectClass names
|
19
|
+
# that are minimally required for EVERY object on your LDAP server.
|
20
|
+
# If you don't want one, set this to [].
|
21
|
+
def Base.required_classes
|
22
|
+
['top']
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'ldap'
|
2
|
+
require 'ldap/schema'
|
3
|
+
|
4
|
+
module LDAP
|
5
|
+
class Schema2 < Schema
|
6
|
+
|
7
|
+
# attr
|
8
|
+
#
|
9
|
+
# This is just like LDAP::Schema#attr except that it allows
|
10
|
+
# look up in any of the given keys.
|
11
|
+
# e.g.
|
12
|
+
# attr('attributeTypes', 'cn', 'DESC')
|
13
|
+
# attr('ldapSyntaxes', '1.3.6.1.4.1.1466.115.121.1.5', 'DESC')
|
14
|
+
def attr(sub, type, at)
|
15
|
+
return '' if sub.empty?
|
16
|
+
return '' if type.empty?
|
17
|
+
return '' if at.empty?
|
18
|
+
|
19
|
+
at = at.upcase
|
20
|
+
self[sub].each do |s|
|
21
|
+
line = ''
|
22
|
+
if type[0..0] =~ /[0-9]/
|
23
|
+
line = s if s =~ /\(\s+#{type}\s+([A-Z]|\))/
|
24
|
+
else
|
25
|
+
line = s if s =~ /NAME\s+\(?.*'#{type}'.*\)?\s+([A-Z]|\))/
|
26
|
+
end
|
27
|
+
|
28
|
+
# I need to check, but I think some of these matchs
|
29
|
+
# overlap. I'll need to check these when I'm less sleepy.
|
30
|
+
multi = ''
|
31
|
+
case line
|
32
|
+
when /#{at}\s+[\)A-Z]/
|
33
|
+
return ['TRUE']
|
34
|
+
when /#{at}\s+'(.+?)'/
|
35
|
+
return [$1]
|
36
|
+
when /#{at}\s+\((.+?)\)/
|
37
|
+
multi = $1
|
38
|
+
when /#{at}\s+\(([\w\d\s\.]+)\)/
|
39
|
+
multi = $1
|
40
|
+
when /#{at}\s+([\w\d\.]+)/
|
41
|
+
return [$1]
|
42
|
+
end
|
43
|
+
# Split up multiple matches
|
44
|
+
# if oc then it is sep'd by $
|
45
|
+
# if attr then bu spaces
|
46
|
+
if multi.match(/\$/)
|
47
|
+
return multi.split("$").collect{|attr| attr.strip}
|
48
|
+
elsif not multi.empty?
|
49
|
+
return multi.gsub(/'/, '').split(' ').collect{|attr| attr.strip}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
return []
|
53
|
+
end
|
54
|
+
|
55
|
+
# attribute_aliases
|
56
|
+
#
|
57
|
+
# Returns all names from the LDAP schema for the
|
58
|
+
# attribute given.
|
59
|
+
def attribute_aliases(attr)
|
60
|
+
attr('attributeTypes', attr, 'NAME')
|
61
|
+
end # attribute aliases
|
62
|
+
|
63
|
+
# read_only?
|
64
|
+
#
|
65
|
+
# Returns true if an attribute is read-only
|
66
|
+
# NO-USER-MODIFICATION
|
67
|
+
def read_only?(attr)
|
68
|
+
result = attr('attributeTypes', attr, 'NO-USER-MODIFICATION')
|
69
|
+
return true if result[0] == 'TRUE'
|
70
|
+
return false
|
71
|
+
end
|
72
|
+
|
73
|
+
# single_value?
|
74
|
+
#
|
75
|
+
# Returns true if an attribute can only have one
|
76
|
+
# value defined
|
77
|
+
# SINGLE-VALUE
|
78
|
+
def single_value?(attr)
|
79
|
+
result = attr('attributeTypes', attr, 'SINGLE-VALUE')
|
80
|
+
return true if result[0] == 'TRUE'
|
81
|
+
return false
|
82
|
+
end
|
83
|
+
|
84
|
+
# binary?
|
85
|
+
#
|
86
|
+
# Returns true if the given attribute's syntax
|
87
|
+
# is X-NOT-HUMAN-READABLE or X-BINARY-TRANSFER-REQUIRED
|
88
|
+
def binary?(attr)
|
89
|
+
# Get syntax OID
|
90
|
+
syntax = attr('attributeTypes', attr, 'SYNTAX')
|
91
|
+
return false if syntax.empty?
|
92
|
+
|
93
|
+
# This seems to indicate binary
|
94
|
+
result = attr('ldapSyntaxes', syntax[0], 'X-NOT-HUMAN-READABLE')
|
95
|
+
return true if result[0] == "TRUE"
|
96
|
+
|
97
|
+
# Get if binary transfer is required (non-binary types)
|
98
|
+
# Usually these have the above tag
|
99
|
+
result = attr('ldapSyntaxes', syntax[0], 'X-BINARY-TRANSFER-REQUIRED')
|
100
|
+
return true if result[0] == "TRUE"
|
101
|
+
|
102
|
+
return false
|
103
|
+
end # binary?
|
104
|
+
|
105
|
+
# binary_required?
|
106
|
+
#
|
107
|
+
# Returns true if the value MUST be transferred in binary
|
108
|
+
def binary_required?(attr)
|
109
|
+
# Get syntax OID
|
110
|
+
syntax = attr('attributeTypes', attr, 'SYNTAX')
|
111
|
+
return false if syntax.empty?
|
112
|
+
|
113
|
+
# Get if binary transfer is required (non-binary types)
|
114
|
+
# Usually these have the above tag
|
115
|
+
result = attr('ldapSyntaxes', syntax[0], 'X-BINARY-TRANSFER-REQUIRED')
|
116
|
+
return true if result[0] == "TRUE"
|
117
|
+
|
118
|
+
return false
|
119
|
+
end # binary_required?
|
120
|
+
end # Schema2
|
121
|
+
|
122
|
+
class Conn
|
123
|
+
def schema(base = nil, attrs = nil, sec = 0, usec = 0)
|
124
|
+
attrs ||= [
|
125
|
+
'objectClasses',
|
126
|
+
'attributeTypes',
|
127
|
+
'matchingRules',
|
128
|
+
'matchingRuleUse',
|
129
|
+
'dITStructureRules',
|
130
|
+
'dITContentRules',
|
131
|
+
'nameForms',
|
132
|
+
'ldapSyntaxes',
|
133
|
+
]
|
134
|
+
base ||= root_dse(['subschemaSubentry'], sec, usec)[0]['subschemaSubentry'][0]
|
135
|
+
base ||= 'cn=schema'
|
136
|
+
ent = search2(base, LDAP_SCOPE_BASE, '(objectClass=subschema)',
|
137
|
+
attrs, false, sec, usec)
|
138
|
+
return Schema2.new(ent[0])
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end # end LDAP
|