Added support for a commit hook:

* Transformed the config a bit.
  * Added Backend::Basic#commit, call commit when one or more updates are
    performed by the backend.
  * Implemented commit for the LDAPv3 backend updating the serial and
    calling an optional hook.
  * Style fixes.


git-svn-id: svn+ssh://svn.luon.net/svn/ildus/trunk@11 65a33f86-aa00-0410-91be-cd1bf5efb309
This commit is contained in:
paul 2005-11-01 15:12:51 +00:00
parent baca1dd160
commit 7b7b4c6631
4 changed files with 71 additions and 21 deletions

View File

@ -32,6 +32,8 @@ passwd: /etc/ildusd/passwd
# Backend to use and the backend's options/parameters.
backend:
type: ldap
basedn: cn=somedomain.test,ou=DNS,dc=somedomain,dc=test
dnsdn: cn=admin,ou=People,dc=somedomain,dc=test
dnspw: secret
host: ldap.somedomain.tld
base: cn=somedomain.test,ou=DNS,dc=somedomain,dc=test
user: cn=admin,ou=People,dc=somedomain,dc=test
pass: secret
domain: somedomain.tld

View File

@ -17,22 +17,26 @@ module Ildus
BackendClasses = Hash.new
def self.load
path = File.dirname(__FILE__)
Dir["#{path}/backends/**/*.rb"].each { |file| require file }
end
class << self
def self.get(type)
BackendClasses[type.to_sym]
end
alias_method :[], :get
def self.register(type, backend_class)
if BackendClasses.include? type
raise "type #{type} already registered"
def load
path = File.dirname(__FILE__)
Dir["#{path}/backends/**/*.rb"].each { |file| require file }
end
BackendClasses[type] = backend_class
end
def get(type)
BackendClasses[type.to_sym]
end
alias_method :[], :get
def register(type, backend_class)
if BackendClasses.include? type
raise "type #{type} already registered"
end
BackendClasses[type] = backend_class
end
end # self
class Basic
@ -70,6 +74,10 @@ module Ildus
#################
# Backend methods
def commit
raise Handler::NotImplementedError
end
def authenticate
raise Handler::NotImplementedError
end

View File

@ -20,6 +20,11 @@ module Ildus::Server::Backend
@ldap.simple_bind(config['user'], config['pass'])
end
def commit
update_serial
system "#{@config['hook']}" if @config['hook']
end
def authenticate
## STUB
@auth = (@pass == "foo")
@ -32,7 +37,7 @@ module Ildus::Server::Backend
all_entries.each do |entry|
assoc_dom, a_rr, aaaa_rr, cname_rr =
["associatedDomain", "aRecord",
"aAAArecord", "cNAMErecord"].map { |attr| entry[attr] }
"aAAArecord", "cNAMErecord"].map { |attr| entry[attr] }
host = assoc_dom.first.gsub(/\.#{config['domain']}$/, '')
entries[host].first.push(*a_rr) if a_rr
@ -53,10 +58,12 @@ module Ildus::Server::Backend
raise Handler::HostNotFoundError if entry.nil?
if addr.ipv4?
@ldap.modify(entry['dn'][0], {"aRecord" => [addr.to_s]})
@ldap.modify(entry['dn'][0], {"aRecord" => [addr.to_s]})
elsif addr.ipv6?
@ldap.modify(entry['dn'][0], {"aAAARecord" => [addr.to_s]})
end
true
end
#########
@ -67,6 +74,36 @@ module Ildus::Server::Backend
@ldap.search2(config['base'], LDAP::LDAP_SCOPE_SUBTREE,
"(&(objectClass=ildusRecord)(ildusOwner=#{user}))")
end
def soa_record
@ldap.search2(config['base'], LDAP::LDAP_SCOPE_BASE,
"(&(associatedDomain=#{config['domain'].downcase})" \
" (sOARecord=*))").first
end
def update_serial
record = soa_record
soa = record['sOARecord'].first.split
soa[2] = serial_succ(soa[2])
@ldap.modify(record['dn'][0], {"sOARecord" => [soa.join(" ")]})
end
# FIXME: unit tests!
def serial_succ(serial)
date, num = serial.scan(/\d{8}|\d{2}/)
today = Time.now.strftime("%Y%m%d")
if (date < today)
date, num = today, '00'
elsif (num == '99')
date, num = date.succ, '00'
else
num = num.succ
end
return "%08s%02s" % [date, num]
end
end # class LDAPv3

View File

@ -67,6 +67,7 @@ module Ildus
@server = server
@config = server.config
@io = io
@commit = false
type = @config["backend"]["type"]
klass = Backend[@config["backend"]["type"]]
raise "backend type `#{type}' not found" if klass.nil?
@ -112,6 +113,8 @@ module Ildus
rescue RuntimeError => msg # 505
prot_msg 505, msg
raise
ensure
@backend.commit if @commit
end
#########
@ -121,7 +124,7 @@ module Ildus
def handle_command(cmd, args=[])
method_name = cmd.downcase + "_cmd"
meth = method(method_name)
meth.call(*args)
meth[*args]
rescue ArgumentError
raise ArgsSyntaxError
rescue NameError => e
@ -164,7 +167,7 @@ module Ildus
def updt_cmd(host, addr)
raise NotAuthError unless @backend.authenticated?
addr = IPAddr.new(addr)
@backend.update_host(host, addr)
@commit ||= @backend.update_host(host, addr)
rescue HostNotFoundError
prot_msg 425, host
rescue RecordNotFoundError