Skip to content

Commit 3e1b976

Browse files
committed
Added alias dereferencing as described under
#13
1 parent 8a18267 commit 3e1b976

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lib/net/ldap.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ class LdapError < StandardError; end
251251
SearchScopes = [ SearchScope_BaseObject, SearchScope_SingleLevel,
252252
SearchScope_WholeSubtree ]
253253

254+
DerefAliases_Never = 0
255+
DerefAliases_Search = 1
256+
DerefAliases_Find = 2
257+
DerefAliases_Always = 3
258+
DerefAliasesArray = [ DerefAliases_Never, DerefAliases_Search, DerefAliases_Find, DerefAliases_Always ]
259+
254260
primitive = { 2 => :null } # UnbindRequest body
255261
constructed = {
256262
0 => :array, # BindRequest
@@ -995,7 +1001,7 @@ def rename(args)
9951001
begin
9961002
conn = Connection.new(:host => @host, :port => @port,
9971003
:encryption => @encryption)
998-
if (@result = conn.bind(args[:auth] || @auth)).result_code == 0
1004+
if (@result = conn.bind(args[:auth] || @auth)).result_code == 0
9991005
@result = conn.rename(args)
10001006
end
10011007
ensure
@@ -1396,7 +1402,11 @@ def search(args = {})
13961402
scope = args[:scope] || Net::LDAP::SearchScope_WholeSubtree
13971403
raise Net::LDAP::LdapError, "invalid search scope" unless Net::LDAP::SearchScopes.include?(scope)
13981404

1399-
sort_control = encode_sort_controls(args.fetch(:sort_controls){ false })
1405+
deref = args[:deref] || Net::LDAP::DerefAliases_Never
1406+
raise LdapError.new( "invalid alias dereferencing value" ) unless Net::LDAP::DerefAliasesArray.include?(deref)
1407+
1408+
sort_control = encode_sort_controls(args.fetch(:sort_controls){ false })
1409+
14001410
# An interesting value for the size limit would be close to A/D's
14011411
# built-in page limit of 1000 records, but openLDAP newer than version
14021412
# 2.2.0 chokes on anything bigger than 126. You get a silent error that
@@ -1436,7 +1446,7 @@ def search(args = {})
14361446
request = [
14371447
search_base.to_ber,
14381448
scope.to_ber_enumerated,
1439-
0.to_ber_enumerated,
1449+
deref.to_ber_enumerated,
14401450
query_limit.to_ber, # size limit
14411451
0.to_ber,
14421452
attributes_only.to_ber,

0 commit comments

Comments
 (0)