}[https://travis-ci.org/github/ruby-net-ldap]
== Description
Net::LDAP for Ruby (also called net-ldap) implements client access for the
Lightweight Directory Access Protocol (LDAP), an IETF standard protocol for
accessing distributed directory services. Net::LDAP is written completely in
Ruby with no external dependencies. It supports most LDAP client features and a
subset of server features as well.
Net::LDAP has been tested against modern popular LDAP servers including
OpenLDAP and Active Directory. The current release is mostly compliant with
earlier versions of the IETF LDAP RFCs (2251–2256, 2829–2830, 3377, and 3771).
Our roadmap for Net::LDAP 1.0 is to gain full client compliance with
the most recent LDAP RFCs (4510–4519, plus portions of 4520–4532).
== Where
* {GitHub}[https://github.com/ruby-ldap/ruby-net-ldap]
* {ruby-ldap@googlegroups.com}[http://groups.google.com/group/ruby-ldap]
== Synopsis
See Net::LDAP for documentation and usage samples.
== Requirements
Net::LDAP requires a Ruby 1.9.3 compatible interpreter or better.
== Install
Net::LDAP is a pure Ruby library. It does not require any external libraries.
You can install the RubyGems version of Net::LDAP available from the usual
sources.
gem install net-ldap
Simply require either 'net-ldap' or 'net/ldap'.
:include: Contributors.rdoc
:include: License.rdoc
net-ldap-0.8.0/.travis.yml 0000644 0000041 0000041 00000000230 12404411554 015357 0 ustar www-data www-data language: ruby
rvm:
- 1.9.3
- 2.0.0
- jruby-19mode
- rbx-19mode
matrix:
allow_failures:
- rvm: jruby-19mode
script: bundle exec rake spec
net-ldap-0.8.0/lib/ 0000755 0000041 0000041 00000000000 12404411554 014021 5 ustar www-data www-data net-ldap-0.8.0/lib/net-ldap.rb 0000644 0000041 0000041 00000000062 12404411554 016050 0 ustar www-data www-data # -*- ruby encoding: utf-8 -*-
require 'net/ldap'
net-ldap-0.8.0/lib/net/ 0000755 0000041 0000041 00000000000 12404411554 014607 5 ustar www-data www-data net-ldap-0.8.0/lib/net/snmp.rb 0000644 0000041 0000041 00000014516 12404411554 016120 0 ustar www-data www-data # -*- ruby encoding: utf-8 -*-
require 'net/ldap/version'
# :stopdoc:
module Net
class SNMP
VERSION = Net::LDAP::VERSION
AsnSyntax = Net::BER.compile_syntax({
:application => {
:primitive => {
1 => :integer, # Counter32, (RFC2578 sec 2)
2 => :integer, # Gauge32 or Unsigned32, (RFC2578 sec 2)
3 => :integer # TimeTicks32, (RFC2578 sec 2)
},
:constructed => {
}
},
:context_specific => {
:primitive => {
},
:constructed => {
0 => :array, # GetRequest PDU (RFC1157 pgh 4.1.2)
1 => :array, # GetNextRequest PDU (RFC1157 pgh 4.1.3)
2 => :array # GetResponse PDU (RFC1157 pgh 4.1.4)
}
}
})
# SNMP 32-bit counter.
# Defined in RFC1155 (Structure of Mangement Information), section 6.
# A 32-bit counter is an ASN.1 application [1] implicit unsigned integer
# with a range from 0 to 2^^32 - 1.
class Counter32
def initialize value
@value = value
end
def to_ber
@value.to_ber_application(1)
end
end
# SNMP 32-bit gauge.
# Defined in RFC1155 (Structure of Mangement Information), section 6.
# A 32-bit counter is an ASN.1 application [2] implicit unsigned integer.
# This is also indistinguishable from Unsigned32. (Need to alias them.)
class Gauge32
def initialize value
@value = value
end
def to_ber
@value.to_ber_application(2)
end
end
# SNMP 32-bit timer-ticks.
# Defined in RFC1155 (Structure of Mangement Information), section 6.
# A 32-bit counter is an ASN.1 application [3] implicit unsigned integer.
class TimeTicks32
def initialize value
@value = value
end
def to_ber
@value.to_ber_application(3)
end
end
end
class SnmpPdu
class Error < StandardError; end
PduTypes = [
:get_request,
:get_next_request,
:get_response,
:set_request,
:trap
]
ErrorStatusCodes = { # Per RFC1157, pgh 4.1.1
0 => "noError",
1 => "tooBig",
2 => "noSuchName",
3 => "badValue",
4 => "readOnly",
5 => "genErr"
}
class << self
def parse ber_object
n = new
n.send :parse, ber_object
n
end
end
attr_reader :version, :community, :pdu_type, :variables, :error_status
attr_accessor :request_id, :error_index
def initialize args={}
@version = args[:version] || 0
@community = args[:community] || "public"
@pdu_type = args[:pdu_type] # leave nil unless specified; there's no reasonable default value.
@error_status = args[:error_status] || 0
@error_index = args[:error_index] || 0
@variables = args[:variables] || []
end
#--
def parse ber_object
begin
parse_ber_object ber_object
rescue Error
# Pass through any SnmpPdu::Error instances
raise $!
rescue
# Wrap any basic parsing error so it becomes a PDU-format error
raise Error.new( "snmp-pdu format error" )
end
end
private :parse
def parse_ber_object ber_object
send :version=, ber_object[0].to_i
send :community=, ber_object[1].to_s
data = ber_object[2]
case (app_tag = data.ber_identifier & 31)
when 0
send :pdu_type=, :get_request
parse_get_request data
when 1
send :pdu_type=, :get_next_request
# This PDU is identical to get-request except for the type.
parse_get_request data
when 2
send :pdu_type=, :get_response
# This PDU is identical to get-request except for the type,
# the error_status and error_index values are meaningful,
# and the fact that the variable bindings will be non-null.
parse_get_response data
else
raise Error.new( "unknown snmp-pdu type: #{app_tag}" )
end
end
private :parse_ber_object
#--
# Defined in RFC1157, pgh 4.1.2.
def parse_get_request data
send :request_id=, data[0].to_i
# data[1] is error_status, always zero.
# data[2] is error_index, always zero.
send :error_status=, 0
send :error_index=, 0
data[3].each {|n,v|
# A variable-binding, of which there may be several,
# consists of an OID and a BER null.
# We're ignoring the null, we might want to verify it instead.
unless v.is_a?(Net::BER::BerIdentifiedNull)
raise Error.new(" invalid variable-binding in get-request" )
end
add_variable_binding n, nil
}
end
private :parse_get_request
#--
# Defined in RFC1157, pgh 4.1.4
def parse_get_response data
send :request_id=, data[0].to_i
send :error_status=, data[1].to_i
send :error_index=, data[2].to_i
data[3].each {|n,v|
# A variable-binding, of which there may be several,
# consists of an OID and a BER null.
# We're ignoring the null, we might want to verify it instead.
add_variable_binding n, v
}
end
private :parse_get_response
def version= ver
unless [0,2].include?(ver)
raise Error.new("unknown snmp-version: #{ver}")
end
@version = ver
end
def pdu_type= t
unless PduTypes.include?(t)
raise Error.new("unknown pdu-type: #{t}")
end
@pdu_type = t
end
def error_status= es
unless ErrorStatusCodes.has_key?(es)
raise Error.new("unknown error-status: #{es}")
end
@error_status = es
end
def community= c
@community = c.to_s
end
#--
# Syntactic sugar
def add_variable_binding name, value=nil
@variables ||= []
@variables << [name, value]
end
def to_ber_string
[
version.to_ber,
community.to_ber,
pdu_to_ber_string
].to_ber_sequence
end
#--
# Helper method that returns a PDU payload in BER form,
# depending on the PDU type.
def pdu_to_ber_string
case pdu_type
when :get_request
[
request_id.to_ber,
error_status.to_ber,
error_index.to_ber,
[
@variables.map {|n,v|
[n.to_ber_oid, Net::BER::BerIdentifiedNull.new.to_ber].to_ber_sequence
}
].to_ber_sequence
].to_ber_contextspecific(0)
when :get_next_request
[
request_id.to_ber,
error_status.to_ber,
error_index.to_ber,
[
@variables.map {|n,v|
[n.to_ber_oid, Net::BER::BerIdentifiedNull.new.to_ber].to_ber_sequence
}
].to_ber_sequence
].to_ber_contextspecific(1)
when :get_response
[
request_id.to_ber,
error_status.to_ber,
error_index.to_ber,
[
@variables.map {|n,v|
[n.to_ber_oid, v.to_ber].to_ber_sequence
}
].to_ber_sequence
].to_ber_contextspecific(2)
else
raise Error.new( "unknown pdu-type: #{pdu_type}" )
end
end
private :pdu_to_ber_string
end
end
# :startdoc:
net-ldap-0.8.0/lib/net/ber.rb 0000644 0000041 0000041 00000030344 12404411554 015710 0 ustar www-data www-data # -*- ruby encoding: utf-8 -*-
require 'net/ldap/version'
module Net # :nodoc:
##
# == Basic Encoding Rules (BER) Support Module
#
# Much of the text below is cribbed from Wikipedia:
# http://en.wikipedia.org/wiki/Basic_Encoding_Rules
#
# The ITU Specification is also worthwhile reading:
# http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf
#
# The Basic Encoding Rules were the original rules laid out by the ASN.1
# standard for encoding abstract information into a concrete data stream.
# The rules, collectively referred to as a transfer syntax in ASN.1
# parlance, specify the exact octet sequences which are used to encode a
# given data item. The syntax defines such elements as: the
# representations for basic data types, the structure of length
# information, and the means for defining complex or compound types based
# on more primitive types. The BER syntax, along with two subsets of BER
# (the Canonical Encoding Rules and the Distinguished Encoding Rules), are
# defined by the ITU-T's X.690 standards document, which is part of the
# ASN.1 document series.
#
# == Encoding
# The BER format specifies a self-describing and self-delimiting format
# for encoding ASN.1 data structures. Each data element is encoded as a
# type identifier, a length description, the actual data elements, and
# where necessary, an end-of-content marker. This format allows a receiver
# to decode the ASN.1 information from an incomplete stream, without
# requiring any pre-knowledge of the size, content, or semantic meaning of
# the data.
#
# | Name | Primitive Constructed | Number |
|---|---|---|
| EOC (End-of-Content) | P | 0: 0 (0x0, 0b00000000) |
| BOOLEAN | P | 1: 1 (0x01, 0b00000001) |
| INTEGER | P | 2: 2 (0x02, 0b00000010) |
| BIT STRING | P | 3: 3 (0x03, 0b00000011) |
| BIT STRING | C | 3: 35 (0x23, 0b00100011) |
| OCTET STRING | P | 4: 4 (0x04, 0b00000100) |
| OCTET STRING | C | 4: 36 (0x24, 0b00100100) |
| NULL | P | 5: 5 (0x05, 0b00000101) |
| OBJECT IDENTIFIER | P | 6: 6 (0x06, 0b00000110) |
| Object Descriptor | P | 7: 7 (0x07, 0b00000111) |
| EXTERNAL | C | 8: 40 (0x28, 0b00101000) |
| REAL (float) | P | 9: 9 (0x09, 0b00001001) |
| ENUMERATED | P | 10: 10 (0x0a, 0b00001010) |
| EMBEDDED PDV | C | 11: 43 (0x2b, 0b00101011) |
| UTF8String | P | 12: 12 (0x0c, 0b00001100) |
| UTF8String | C | 12: 44 (0x2c, 0b00101100) |
| RELATIVE-OID | P | 13: 13 (0x0d, 0b00001101) |
| SEQUENCE and SEQUENCE OF | C | 16: 48 (0x30, 0b00110000) |
| SET and SET OF | C | 17: 49 (0x31, 0b00110001) |
| NumericString | P | 18: 18 (0x12, 0b00010010) |
| NumericString | C | 18: 50 (0x32, 0b00110010) |
| PrintableString | P | 19: 19 (0x13, 0b00010011) |
| PrintableString | C | 19: 51 (0x33, 0b00110011) |
| T61String | P | 20: 20 (0x14, 0b00010100) |
| T61String | C | 20: 52 (0x34, 0b00110100) |
| VideotexString | P | 21: 21 (0x15, 0b00010101) |
| VideotexString | C | 21: 53 (0x35, 0b00110101) |
| IA5String | P | 22: 22 (0x16, 0b00010110) |
| IA5String | C | 22: 54 (0x36, 0b00110110) |
| UTCTime | P | 23: 23 (0x17, 0b00010111) |
| UTCTime | C | 23: 55 (0x37, 0b00110111) |
| GeneralizedTime | P | 24: 24 (0x18, 0b00011000) |
| GeneralizedTime | C | 24: 56 (0x38, 0b00111000) |
| GraphicString | P | 25: 25 (0x19, 0b00011001) |
| GraphicString | C | 25: 57 (0x39, 0b00111001) |
| VisibleString | P | 26: 26 (0x1a, 0b00011010) |
| VisibleString | C | 26: 58 (0x3a, 0b00111010) |
| GeneralString | P | 27: 27 (0x1b, 0b00011011) |
| GeneralString | C | 27: 59 (0x3b, 0b00111011) |
| UniversalString | P | 28: 28 (0x1c, 0b00011100) |
| UniversalString | C | 28: 60 (0x3c, 0b00111100) |
| CHARACTER STRING | P | 29: 29 (0x1d, 0b00011101) |
| CHARACTER STRING | C | 29: 61 (0x3d, 0b00111101) |
| BMPString | P | 30: 30 (0x1e, 0b00011110) |
| BMPString | C | 30: 62 (0x3e, 0b00111110) |
| Bitmask | Definition |
|---|---|
| 0b00______ | Universal (ASN.1 Native) Types |
| 0b01______ | Application Types |
| 0b10______ | Context-Specific Types |
| 0b11______ | Private Types |
| Bitmask | Definition |
|---|---|
| 0b__0_____ | Primitive |
| 0b__1_____ | Constructed |
| Range | #Length | #
|---|---|
| 0x00 -- 0x7f 0b00000000 -- 0b01111111 |
# 0 - 127 bytes | #
| 0x80 0b10000000 |
# Indeterminate (end-of-content marker required) | #
| 0x81 -- 0xfe 0b10000001 -- 0b11111110 |
# 1 - 126 bytes of length as an integer value | #
| 0xff 0b11111111 |
# Illegal (reserved for future expansion) | #