This repository has been archived on 2020-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
ildus/lib/ildus/server/backends/ldap.rb

52 lines
1.4 KiB
Ruby

# = ildus/server/backend - generic server backend library
#
# Copyright (C) 2005 Paul van Tilburg <paul@luon.net>
#
# Ildus 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.
require 'ldap'
module Ildus::Server::Backend
class LDAPv3 < Basic
def initialize(*args)
super
@ldap = LDAP::Conn.new(config['host'])
@ldap.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3)
@ldap.simple_bind(config['user'], config['pass'])
end
def hostnames
entries = Hash.new { |h, k| h[k] = [[], []] }
@ldap.search(config['base'], LDAP::LDAP_SCOPE_SUBTREE,
"ildusOwner=#{user}") do |entry|
assoc_dom, a_rr, aaaa_rr, cname_rr =
["associatedDomain", "aRecord",
"aAAArecord", "cNAMErecord"].map do |attr|
entry.vals(attr)
end
host = assoc_dom.first.gsub(/\.#{config['domain']}$/, '')
if a_rr
entries[host].first.push(*a_rr)
end
if aaaa_rr
entries[host].first.push(*aaaa_rr)
end
if cname_rr
cname = cname_rr.first.gsub(/\.#{config['domain']}$/, '')
entries[cname].last << host
end
end
return entries
end # hostnames
end # class LDAPv3
end # module Ildus::Server::Backend