Merging an ugly set of changes I had forgotten about.
This commit is contained in:
commit
84e42ceb78
23 changed files with 228 additions and 272 deletions
|
@ -1,4 +1,4 @@
|
|||
module Net
|
||||
module Net # :nodoc:
|
||||
##
|
||||
# == Basic Encoding Rules (BER) Support Module
|
||||
#
|
||||
|
@ -105,7 +105,7 @@ module Net
|
|||
# <tr><th>BMPString</th><th>C</th><td>30: 62 (0x3e, 0b00111110)</td></tr>
|
||||
# </table>
|
||||
module BER
|
||||
VERSION = '0.1.0'
|
||||
VERSION = '0.2'
|
||||
|
||||
##
|
||||
# Used for BER-encoding the length and content bytes of a Fixnum integer
|
||||
|
|
|
@ -1,29 +1,5 @@
|
|||
# NET::BER
|
||||
# Mixes ASN.1/BER convenience methods into several standard classes. Also
|
||||
# provides BER parsing functionality.
|
||||
#
|
||||
#--
|
||||
# Copyright (C) 2006 by Francis Cianfrocca and other contributors. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Gmail: garbagecat10
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#++
|
||||
|
||||
require 'net/ber/ber_parser'
|
||||
# :stopdoc:
|
||||
class IO
|
||||
include Net::BER::BERParser
|
||||
end
|
||||
|
@ -37,36 +13,49 @@ if defined? ::OpenSSL
|
|||
include Net::BER::BERParser
|
||||
end
|
||||
end
|
||||
# :startdoc:
|
||||
|
||||
module Net::BER::Extensions; end
|
||||
module Net::BER::Extensions # :nodoc:
|
||||
end
|
||||
|
||||
require 'net/ber/core_ext/string'
|
||||
# :stopdoc:
|
||||
class String
|
||||
include Net::BER::BERParser
|
||||
include Net::BER::Extensions::String
|
||||
end
|
||||
|
||||
require 'net/ber/core_ext/array'
|
||||
class Array
|
||||
# :stopdoc:
|
||||
class Array
|
||||
include Net::BER::Extensions::Array
|
||||
end
|
||||
# :startdoc:
|
||||
|
||||
require 'net/ber/core_ext/bignum'
|
||||
class Bignum
|
||||
# :stopdoc:
|
||||
class Bignum
|
||||
include Net::BER::Extensions::Bignum
|
||||
end
|
||||
# :startdoc:
|
||||
|
||||
require 'net/ber/core_ext/fixnum'
|
||||
class Fixnum
|
||||
# :stopdoc:
|
||||
class Fixnum
|
||||
include Net::BER::Extensions::Fixnum
|
||||
end
|
||||
# :startdoc:
|
||||
|
||||
require 'net/ber/core_ext/true_class'
|
||||
class TrueClass
|
||||
# :stopdoc:
|
||||
class TrueClass
|
||||
include Net::BER::Extensions::TrueClass
|
||||
end
|
||||
# :startdoc:
|
||||
|
||||
require 'net/ber/core_ext/false_class'
|
||||
class FalseClass
|
||||
# :stopdoc:
|
||||
class FalseClass
|
||||
include Net::BER::Extensions::FalseClass
|
||||
end
|
||||
# :startdoc:
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
##
|
||||
# BER extensions to the Array class.
|
||||
module Net::BER::Extensions::Array
|
||||
##
|
||||
# Converts an Array to a BER sequence. All values in the Array are
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
##
|
||||
# BER extensions to the Bignum class.
|
||||
module Net::BER::Extensions::Bignum
|
||||
##
|
||||
# Converts a Bignum to an uncompressed BER integer.
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
##
|
||||
# BER extensions to +false+.
|
||||
module Net::BER::Extensions::FalseClass
|
||||
##
|
||||
# Converts +false+ to the BER wireline representation of +false+.
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
##
|
||||
# Ber extensions to the Fixnum class.
|
||||
module Net::BER::Extensions::Fixnum
|
||||
##
|
||||
# Converts the fixnum to BER format.
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
require 'stringio'
|
||||
|
||||
##
|
||||
# BER extensions to the String class.
|
||||
module Net::BER::Extensions::String
|
||||
##
|
||||
# Converts a string to a BER string. Universal octet-strings are tagged
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
##
|
||||
# BER extensions to +true+.
|
||||
module Net::BER::Extensions::TrueClass
|
||||
##
|
||||
# Converts +true+ to the BER wireline representation of +true+.
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
require 'ostruct'
|
||||
|
||||
module Net
|
||||
module Net # :nodoc:
|
||||
class LDAP
|
||||
begin
|
||||
require 'openssl'
|
||||
##
|
||||
# Set to +true+ if OpenSSL is available and LDAPS is supported.
|
||||
HasOpenSSL = true
|
||||
rescue LoadError
|
||||
# :stopdoc:
|
||||
HasOpenSSL = false
|
||||
# :startdoc:
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -19,16 +23,6 @@ require 'net/ldap/dataset'
|
|||
require 'net/ldap/password'
|
||||
require 'net/ldap/entry'
|
||||
|
||||
# == Net::LDAP
|
||||
#
|
||||
# This library provides a pure-Ruby implementation of the LDAP client
|
||||
# protocol, per RFC-2251. It can be used to access any server which
|
||||
# implements the LDAP protocol.
|
||||
#
|
||||
# Net::LDAP is intended to provide full LDAP functionality while hiding the
|
||||
# more arcane aspects the LDAP protocol itself, and thus presenting as
|
||||
# Ruby-like a programming interface as possible.
|
||||
#
|
||||
# == Quick-start for the Impatient
|
||||
# === Quick Example of a user-authentication against an LDAP directory:
|
||||
#
|
||||
|
@ -246,7 +240,7 @@ require 'net/ldap/entry'
|
|||
# and then keeps it open while it executes a user-supplied block.
|
||||
# Net::LDAP#open closes the connection on completion of the block.
|
||||
class Net::LDAP
|
||||
VERSION = "0.1.1"
|
||||
VERSION = "0.2"
|
||||
|
||||
class LdapError < StandardError; end
|
||||
|
||||
|
|
|
@ -1,25 +1,3 @@
|
|||
#----------------------------------------------------------------------------
|
||||
#
|
||||
# Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
|
||||
#
|
||||
# Gmail: garbagecat10
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
##
|
||||
# An LDAP Dataset. Used primarily as an intermediate format for converting
|
||||
# to and from LDIF strings and Net::LDAP::Entry objects.
|
||||
|
@ -28,78 +6,7 @@ class Net::LDAP::Dataset < Hash
|
|||
# Dataset object comments.
|
||||
attr_reader :comments
|
||||
|
||||
class << self
|
||||
class ChompedIO #:nodoc:
|
||||
def initialize(io)
|
||||
@io = io
|
||||
end
|
||||
def gets
|
||||
s = @io.gets
|
||||
s.chomp if s
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# Reads an object that returns data line-wise (using #gets) and parses
|
||||
# LDIF data into a Dataset object.
|
||||
def read_ldif(io) #:yields: entry-type, value Used mostly for debugging.
|
||||
ds = Net::LDAP::Dataset.new
|
||||
io = ChompedIO.new(io)
|
||||
|
||||
line = io.gets
|
||||
dn = nil
|
||||
|
||||
while line
|
||||
new_line = io.gets
|
||||
|
||||
if new_line =~ /^[\s]+/
|
||||
line << " " << $'
|
||||
else
|
||||
nextline = new_line
|
||||
|
||||
if line =~ /^#/
|
||||
ds.comments << line
|
||||
yield :comment, line if block_given?
|
||||
elsif line =~ /^dn:[\s]*/i
|
||||
dn = $'
|
||||
ds[dn] = Hash.new { |k,v| k[v] = [] }
|
||||
yield :dn, dn if block_given?
|
||||
elsif line.empty?
|
||||
dn = nil
|
||||
yield :end, nil if block_given?
|
||||
elsif line =~ /^([^:]+):([\:]?)[\s]*/
|
||||
# $1 is the attribute name
|
||||
# $2 is a colon iff the attr-value is base-64 encoded
|
||||
# $' is the attr-value
|
||||
# Avoid the Base64 class because not all Ruby versions have it.
|
||||
attrvalue = ($2 == ":") ? $'.unpack('m').shift : $'
|
||||
ds[dn][$1.downcase.to_sym] << attrvalue
|
||||
yield :attr, [$1.downcase.to_sym, attrvalue] if block_given?
|
||||
end
|
||||
|
||||
line = nextline
|
||||
end
|
||||
end
|
||||
|
||||
ds
|
||||
end
|
||||
|
||||
##
|
||||
# Creates a Dataset object from an Entry object. Used mostly to assist
|
||||
# with the conversion of
|
||||
def from_entry(entry)
|
||||
dataset = Net::LDAP::Dataset.new
|
||||
hash = { }
|
||||
entry.each_attribute do |attribute, value|
|
||||
next if attribute == :dn
|
||||
hash[attribute] = value
|
||||
end
|
||||
dataset[entry.dn] = hash
|
||||
dataset
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(*args, &block) #:nodoc:
|
||||
def initialize(*args, &block) # :nodoc:
|
||||
super
|
||||
@comments = []
|
||||
end
|
||||
|
@ -152,6 +59,7 @@ class Net::LDAP::Dataset < Hash
|
|||
ary
|
||||
end
|
||||
|
||||
##
|
||||
# This is an internal convenience method to determine if a value requires
|
||||
# base64-encoding before conversion to LDIF output. The standard approach
|
||||
# in most LDAP tools is to check whether the value is a password, or if
|
||||
|
@ -162,13 +70,84 @@ class Net::LDAP::Dataset < Hash
|
|||
# why we handle the simplest cases first. Ideally, we would also test the
|
||||
# first/last byte, but it's a bit harder to do this in a way that's
|
||||
# compatible with both 1.8.6 and 1.8.7.
|
||||
def value_is_binary?(value)
|
||||
def value_is_binary?(value) # :nodoc:
|
||||
value = value.to_s
|
||||
return true if value[0] == ?: or value[0] == ?<
|
||||
value.each_byte { |byte| return true if (byte < 32) || (byte > 126) }
|
||||
false
|
||||
end
|
||||
private :value_is_binary?
|
||||
|
||||
class << self
|
||||
class ChompedIO # :nodoc:
|
||||
def initialize(io)
|
||||
@io = io
|
||||
end
|
||||
def gets
|
||||
s = @io.gets
|
||||
s.chomp if s
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# Creates a Dataset object from an Entry object. Used mostly to assist
|
||||
# with the conversion of
|
||||
def from_entry(entry)
|
||||
dataset = Net::LDAP::Dataset.new
|
||||
hash = { }
|
||||
entry.each_attribute do |attribute, value|
|
||||
next if attribute == :dn
|
||||
hash[attribute] = value
|
||||
end
|
||||
dataset[entry.dn] = hash
|
||||
dataset
|
||||
end
|
||||
|
||||
##
|
||||
# Reads an object that returns data line-wise (using #gets) and parses
|
||||
# LDIF data into a Dataset object.
|
||||
def read_ldif(io)
|
||||
ds = Net::LDAP::Dataset.new
|
||||
io = ChompedIO.new(io)
|
||||
|
||||
line = io.gets
|
||||
dn = nil
|
||||
|
||||
while line
|
||||
new_line = io.gets
|
||||
|
||||
if new_line =~ /^[\s]+/
|
||||
line << " " << $'
|
||||
else
|
||||
nextline = new_line
|
||||
|
||||
if line =~ /^#/
|
||||
ds.comments << line
|
||||
yield :comment, line if block_given?
|
||||
elsif line =~ /^dn:[\s]*/i
|
||||
dn = $'
|
||||
ds[dn] = Hash.new { |k,v| k[v] = [] }
|
||||
yield :dn, dn if block_given?
|
||||
elsif line.empty?
|
||||
dn = nil
|
||||
yield :end, nil if block_given?
|
||||
elsif line =~ /^([^:]+):([\:]?)[\s]*/
|
||||
# $1 is the attribute name
|
||||
# $2 is a colon iff the attr-value is base-64 encoded
|
||||
# $' is the attr-value
|
||||
# Avoid the Base64 class because not all Ruby versions have it.
|
||||
attrvalue = ($2 == ":") ? $'.unpack('m').shift : $'
|
||||
ds[dn][$1.downcase.to_sym] << attrvalue
|
||||
yield :attr, [$1.downcase.to_sym, attrvalue] if block_given?
|
||||
end
|
||||
|
||||
line = nextline
|
||||
end
|
||||
end
|
||||
|
||||
ds
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
require 'net/ldap/entry' unless defined? Net::LDAP::Entry
|
||||
|
|
|
@ -1,27 +1,3 @@
|
|||
# LDAP Entry (search-result) support classes
|
||||
#
|
||||
#----------------------------------------------------------------------------
|
||||
#
|
||||
# Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
|
||||
#
|
||||
# Gmail: garbagecat10
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
##
|
||||
# Objects of this class represent individual entries in an LDAP directory.
|
||||
# User code generally does not instantiate this class. Net::LDAP#search
|
||||
|
|
|
@ -1,25 +1,4 @@
|
|||
# Encoding: UTF-8
|
||||
# Copyright (C) 2006 by Francis Cianfrocca and other contributors. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Gmail: garbagecat10
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
# Software Foundation; either version 2 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program; if not, write to:
|
||||
# Free Software Foundation, Inc.
|
||||
# 51 Franklin St, Fifth Floor
|
||||
# Boston, MA 02110-1301
|
||||
# USA
|
||||
# -*- ruby encoding: utf-8 -*-
|
||||
|
||||
##
|
||||
# Class Net::LDAP::Filter is used to constrain LDAP searches. An object of
|
||||
|
|
|
@ -1,25 +1,3 @@
|
|||
#----------------------------------------------------------------------------
|
||||
#
|
||||
# Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
|
||||
#
|
||||
# Gmail: garbagecat10
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
require 'digest/sha1'
|
||||
require 'digest/md5'
|
||||
|
||||
|
|
|
@ -1,27 +1,3 @@
|
|||
# LDAP PDU support classes
|
||||
#
|
||||
#----------------------------------------------------------------------------
|
||||
#
|
||||
# Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
|
||||
#
|
||||
# Gmail: garbagecat10
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
require 'ostruct'
|
||||
|
||||
##
|
||||
|
@ -261,7 +237,8 @@ end
|
|||
|
||||
module Net
|
||||
##
|
||||
# Handle the renamed constants.
|
||||
# Handle renamed constants Net::LdapPdu (Net::LDAP::PDU) and
|
||||
# Net::LdapPduError (Net::LDAP::PDU::Error).
|
||||
def self.const_missing(name) #:nodoc:
|
||||
case name.to_s
|
||||
when "LdapPdu"
|
||||
|
@ -276,4 +253,3 @@ module Net
|
|||
end
|
||||
end
|
||||
end # module Net
|
||||
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
module Net
|
||||
class LDIF
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
# :stopdoc:
|
||||
module Net
|
||||
|
||||
class SNMP
|
||||
VERSION = '0.1.0'
|
||||
VERSION = '0.2'
|
||||
|
||||
AsnSyntax = Net::BER.compile_syntax({
|
||||
:application => {
|
||||
|
@ -264,4 +264,4 @@ module Net
|
|||
|
||||
end
|
||||
end
|
||||
|
||||
# :startdoc:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue