class RBMK::Upstream
Constants
- FILTER_PREFIX
- SPECIAL_ATS
Attributes
ldap[R]
root_dse[R]
schema[R]
Public Class Methods
new()
click to toggle source
# File lib/rbmk/upstream.rb, line 36 def initialize @schema = LDAP::Server::Schema.new SPECIAL_ATS.each { |name, at| @schema.add_attrtype format(name, at) } ldap = LDAP::Conn.new self.class.host, self.class.port ldap.set_option LDAP::LDAP_OPT_PROTOCOL_VERSION, 3 ldap.bind do |ldap| @root_dse = ldap.root_dse.first ssse = ldap.schema {add_attrtype: 'attributeTypes', add_objectclass: 'objectClasses'}.each { |meth,id| ssse[id].each { |str| @schema.send meth, str unless str.start_with? FILTER_PREFIX } } end @schema.resolve_oids user_init end
search(ldap, opts) { |e| ... }
click to toggle source
# File lib/rbmk/upstream.rb, line 16 def self.search ldap, opts args = [ opts.fetch(:base, ''), opts.fetch(:scope, LDAP::LDAP_SCOPE_SUBTREE), opts.fetch(:filter, '(objectClass=*)'), opts.fetch(:attrs, ['*', '+']), (not opts.fetch(:vals, true)), opts.fetch(:serverctrls, nil), opts.fetch(:clientctrls, nil), opts.fetch(:sec, 0), opts.fetch(:usec, 0), opts.fetch(:s_attr, 0), opts.fetch(:s_proc, ''), ] res = ldap.search_ext2 *args res.each { |e| yield e } if block_given? res end
Protected Class Methods
host()
click to toggle source
# File lib/rbmk/upstream.rb, line 79 def self.host; '127.0.0.1' end
port()
click to toggle source
# File lib/rbmk/upstream.rb, line 80 def self.port; 389 end
Public Instance Methods
bind(version, dn, password)
click to toggle source
# File lib/rbmk/upstream.rb, line 50 def bind version, dn, password @ldap = LDAP::Conn.new self.class.host, self.class.port @ldap.set_option LDAP::LDAP_OPT_PROTOCOL_VERSION, version.to_i dn ? @ldap.bind(dn, password) : @ldap.bind rescue LDAP::ResultError handle_ldap_error end
handle_ldap_error()
click to toggle source
# File lib/rbmk/upstream.rb, line 66 def handle_ldap_error stderr = from_stderr { @ldap.perror 'LDAP' } # WHY U NO? message = stderr.match(/additional info:(.*)$/)[1].strip rescue nil # Seriously, how hard can it be to expose a server's message? raise LDAP::ResultError.from_id(@ldap.err, message) # FUCK ME WHY SHOULD I EVER PARSE MY OWN STDERR end
mktemp()
click to toggle source
# File lib/rbmk/upstream.rb, line 72 def mktemp @temp = Tempfile.new 'rbmk' File.unlink @temp end
search(opts, &block)
click to toggle source
# File lib/rbmk/upstream.rb, line 62 def search opts, &block self.class.send __method__, @ldap, opts, &block end
unbind()
click to toggle source
# File lib/rbmk/upstream.rb, line 58 def unbind @ldap.unbind end
Protected Instance Methods
format(name, at)
click to toggle source
# File lib/rbmk/upstream.rb, line 82 def format name, at sprintf '( %s NAME \'%s\'%s SYNTAX 1.3.6.1.4.1.1466.115.121.1.%s%s%s USAGE %s )', at[:oid], name, (at[:eq] ? " EQUALITY #{at[:eq]}": ''), at[:s], ((at[:f] and at[:f].include?('s')) ? ' SINGLE-VALUE' : ''), ((at[:f] and at[:f].include?('u')) ? ' NO-USER-MODIFICATION' : ''), ((at[:f] and at[:f].include?('a')) ? 'dSAOperation' : 'directoryOperation') end
from_stderr() { || ... }
click to toggle source
# File lib/rbmk/upstream.rb, line 88 def from_stderr saved = STDERR.dup STDERR.reopen @temp yield if block_given? STDERR.rewind STDERR.read ensure STDERR.reopen saved saved.close end
user_init()
click to toggle source
Patch this method to do something useful right after initialization
# File lib/rbmk/upstream.rb, line 100 def user_init; end