Skip to content

Commit 59dac76

Browse files
author
Austin Ziegler
committed
Cleaning up Net::LDAP documentation.
1 parent 5f5031b commit 59dac76

File tree

6 files changed

+81
-200
lines changed

6 files changed

+81
-200
lines changed

lib/net/ldap.rb

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
require 'ostruct'
22

3-
module Net
3+
module Net # :nodoc:
44
class LDAP
55
begin
66
require 'openssl'
7+
##
8+
# Set to +true+ if OpenSSL is available and LDAPS is supported.
79
HasOpenSSL = true
810
rescue LoadError
11+
# :stopdoc:
912
HasOpenSSL = false
13+
# :startdoc:
1014
end
1115
end
1216
end
@@ -19,16 +23,6 @@ class LDAP
1923
require 'net/ldap/password'
2024
require 'net/ldap/entry'
2125

22-
# == Net::LDAP
23-
#
24-
# This library provides a pure-Ruby implementation of the LDAP client
25-
# protocol, per RFC-2251. It can be used to access any server which
26-
# implements the LDAP protocol.
27-
#
28-
# Net::LDAP is intended to provide full LDAP functionality while hiding the
29-
# more arcane aspects the LDAP protocol itself, and thus presenting as
30-
# Ruby-like a programming interface as possible.
31-
#
3226
# == Quick-start for the Impatient
3327
# === Quick Example of a user-authentication against an LDAP directory:
3428
#

lib/net/ldap/dataset.rb

Lines changed: 74 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,3 @@
1-
#----------------------------------------------------------------------------
2-
#
3-
# Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
4-
#
5-
# Gmail: garbagecat10
6-
#
7-
# This program is free software; you can redistribute it and/or modify
8-
# it under the terms of the GNU General Public License as published by
9-
# the Free Software Foundation; either version 2 of the License, or
10-
# (at your option) any later version.
11-
#
12-
# This program is distributed in the hope that it will be useful,
13-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15-
# GNU General Public License for more details.
16-
#
17-
# You should have received a copy of the GNU General Public License
18-
# along with this program; if not, write to the Free Software
19-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20-
#
21-
#---------------------------------------------------------------------------
22-
231
##
242
# An LDAP Dataset. Used primarily as an intermediate format for converting
253
# to and from LDIF strings and Net::LDAP::Entry objects.
@@ -28,78 +6,7 @@ class Net::LDAP::Dataset < Hash
286
# Dataset object comments.
297
attr_reader :comments
308

31-
class << self
32-
class ChompedIO #:nodoc:
33-
def initialize(io)
34-
@io = io
35-
end
36-
def gets
37-
s = @io.gets
38-
s.chomp if s
39-
end
40-
end
41-
42-
##
43-
# Reads an object that returns data line-wise (using #gets) and parses
44-
# LDIF data into a Dataset object.
45-
def read_ldif(io) #:yields: entry-type, value Used mostly for debugging.
46-
ds = Net::LDAP::Dataset.new
47-
io = ChompedIO.new(io)
48-
49-
line = io.gets
50-
dn = nil
51-
52-
while line
53-
new_line = io.gets
54-
55-
if new_line =~ /^[\s]+/
56-
line << " " << $'
57-
else
58-
nextline = new_line
59-
60-
if line =~ /^#/
61-
ds.comments << line
62-
yield :comment, line if block_given?
63-
elsif line =~ /^dn:[\s]*/i
64-
dn = $'
65-
ds[dn] = Hash.new { |k,v| k[v] = [] }
66-
yield :dn, dn if block_given?
67-
elsif line.empty?
68-
dn = nil
69-
yield :end, nil if block_given?
70-
elsif line =~ /^([^:]+):([\:]?)[\s]*/
71-
# $1 is the attribute name
72-
# $2 is a colon iff the attr-value is base-64 encoded
73-
# $' is the attr-value
74-
# Avoid the Base64 class because not all Ruby versions have it.
75-
attrvalue = ($2 == ":") ? $'.unpack('m').shift : $'
76-
ds[dn][$1.downcase.to_sym] << attrvalue
77-
yield :attr, [$1.downcase.to_sym, attrvalue] if block_given?
78-
end
79-
80-
line = nextline
81-
end
82-
end
83-
84-
ds
85-
end
86-
87-
##
88-
# Creates a Dataset object from an Entry object. Used mostly to assist
89-
# with the conversion of
90-
def from_entry(entry)
91-
dataset = Net::LDAP::Dataset.new
92-
hash = { }
93-
entry.each_attribute do |attribute, value|
94-
next if attribute == :dn
95-
hash[attribute] = value
96-
end
97-
dataset[entry.dn] = hash
98-
dataset
99-
end
100-
end
101-
102-
def initialize(*args, &block) #:nodoc:
9+
def initialize(*args, &block) # :nodoc:
10310
super
10411
@comments = []
10512
end
@@ -152,6 +59,7 @@ def to_entries
15259
ary
15360
end
15461

62+
##
15563
# This is an internal convenience method to determine if a value requires
15664
# base64-encoding before conversion to LDIF output. The standard approach
15765
# in most LDAP tools is to check whether the value is a password, or if
@@ -162,13 +70,84 @@ def to_entries
16270
# why we handle the simplest cases first. Ideally, we would also test the
16371
# first/last byte, but it's a bit harder to do this in a way that's
16472
# compatible with both 1.8.6 and 1.8.7.
165-
def value_is_binary?(value)
73+
def value_is_binary?(value) # :nodoc:
16674
value = value.to_s
16775
return true if value[0] == ?: or value[0] == ?<
16876
value.each_byte { |byte| return true if (byte < 32) || (byte > 126) }
16977
false
17078
end
17179
private :value_is_binary?
80+
81+
class << self
82+
class ChompedIO # :nodoc:
83+
def initialize(io)
84+
@io = io
85+
end
86+
def gets
87+
s = @io.gets
88+
s.chomp if s
89+
end
90+
end
91+
92+
##
93+
# Creates a Dataset object from an Entry object. Used mostly to assist
94+
# with the conversion of
95+
def from_entry(entry)
96+
dataset = Net::LDAP::Dataset.new
97+
hash = { }
98+
entry.each_attribute do |attribute, value|
99+
next if attribute == :dn
100+
hash[attribute] = value
101+
end
102+
dataset[entry.dn] = hash
103+
dataset
104+
end
105+
106+
##
107+
# Reads an object that returns data line-wise (using #gets) and parses
108+
# LDIF data into a Dataset object.
109+
def read_ldif(io)
110+
ds = Net::LDAP::Dataset.new
111+
io = ChompedIO.new(io)
112+
113+
line = io.gets
114+
dn = nil
115+
116+
while line
117+
new_line = io.gets
118+
119+
if new_line =~ /^[\s]+/
120+
line << " " << $'
121+
else
122+
nextline = new_line
123+
124+
if line =~ /^#/
125+
ds.comments << line
126+
yield :comment, line if block_given?
127+
elsif line =~ /^dn:[\s]*/i
128+
dn = $'
129+
ds[dn] = Hash.new { |k,v| k[v] = [] }
130+
yield :dn, dn if block_given?
131+
elsif line.empty?
132+
dn = nil
133+
yield :end, nil if block_given?
134+
elsif line =~ /^([^:]+):([\:]?)[\s]*/
135+
# $1 is the attribute name
136+
# $2 is a colon iff the attr-value is base-64 encoded
137+
# $' is the attr-value
138+
# Avoid the Base64 class because not all Ruby versions have it.
139+
attrvalue = ($2 == ":") ? $'.unpack('m').shift : $'
140+
ds[dn][$1.downcase.to_sym] << attrvalue
141+
yield :attr, [$1.downcase.to_sym, attrvalue] if block_given?
142+
end
143+
144+
line = nextline
145+
end
146+
end
147+
148+
ds
149+
end
150+
end
172151
end
173152

174153
require 'net/ldap/entry' unless defined? Net::LDAP::Entry

lib/net/ldap/entry.rb

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,3 @@
1-
# LDAP Entry (search-result) support classes
2-
#
3-
#----------------------------------------------------------------------------
4-
#
5-
# Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
6-
#
7-
# Gmail: garbagecat10
8-
#
9-
# This program is free software; you can redistribute it and/or modify
10-
# it under the terms of the GNU General Public License as published by
11-
# the Free Software Foundation; either version 2 of the License, or
12-
# (at your option) any later version.
13-
#
14-
# This program is distributed in the hope that it will be useful,
15-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17-
# GNU General Public License for more details.
18-
#
19-
# You should have received a copy of the GNU General Public License
20-
# along with this program; if not, write to the Free Software
21-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22-
#
23-
#---------------------------------------------------------------------------
24-
251
##
262
# Objects of this class represent individual entries in an LDAP directory.
273
# User code generally does not instantiate this class. Net::LDAP#search

lib/net/ldap/filter.rb

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,3 @@
1-
# Copyright (C) 2006 by Francis Cianfrocca and other contributors. All
2-
# Rights Reserved.
3-
#
4-
# Gmail: garbagecat10
5-
#
6-
# This program is free software; you can redistribute it and/or modify it
7-
# under the terms of the GNU General Public License as published by the Free
8-
# Software Foundation; either version 2 of the License, or (at your option)
9-
# any later version.
10-
#
11-
# This program is distributed in the hope that it will be useful, but
12-
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13-
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14-
# for more details.
15-
#
16-
# You should have received a copy of the GNU General Public License along
17-
# with this program; if not, write to:
18-
# Free Software Foundation, Inc.
19-
# 51 Franklin St, Fifth Floor
20-
# Boston, MA 02110-1301
21-
# USA
22-
231
##
242
# Class Net::LDAP::Filter is used to constrain LDAP searches. An object of
253
# this class is passed to Net::LDAP#search in the parameter :filter.

lib/net/ldap/password.rb

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,3 @@
1-
#----------------------------------------------------------------------------
2-
#
3-
# Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
4-
#
5-
# Gmail: garbagecat10
6-
#
7-
# This program is free software; you can redistribute it and/or modify
8-
# it under the terms of the GNU General Public License as published by
9-
# the Free Software Foundation; either version 2 of the License, or
10-
# (at your option) any later version.
11-
#
12-
# This program is distributed in the hope that it will be useful,
13-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15-
# GNU General Public License for more details.
16-
#
17-
# You should have received a copy of the GNU General Public License
18-
# along with this program; if not, write to the Free Software
19-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20-
#
21-
#---------------------------------------------------------------------------
22-
231
require 'digest/sha1'
242
require 'digest/md5'
253

lib/net/ldap/pdu.rb

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,3 @@
1-
# LDAP PDU support classes
2-
#
3-
#----------------------------------------------------------------------------
4-
#
5-
# Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
6-
#
7-
# Gmail: garbagecat10
8-
#
9-
# This program is free software; you can redistribute it and/or modify
10-
# it under the terms of the GNU General Public License as published by
11-
# the Free Software Foundation; either version 2 of the License, or
12-
# (at your option) any later version.
13-
#
14-
# This program is distributed in the hope that it will be useful,
15-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17-
# GNU General Public License for more details.
18-
#
19-
# You should have received a copy of the GNU General Public License
20-
# along with this program; if not, write to the Free Software
21-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22-
#
23-
#---------------------------------------------------------------------------
24-
251
require 'ostruct'
262

273
##
@@ -261,7 +237,8 @@ def parse_unbind_request(sequence)
261237

262238
module Net
263239
##
264-
# Handle the renamed constants.
240+
# Handle renamed constants Net::LdapPdu (Net::LDAP::PDU) and
241+
# Net::LdapPduError (Net::LDAP::PDU::Error).
265242
def self.const_missing(name) #:nodoc:
266243
case name.to_s
267244
when "LdapPdu"
@@ -275,4 +252,3 @@ def self.const_missing(name) #:nodoc:
275252
end
276253
end
277254
end # module Net
278-

0 commit comments

Comments
 (0)