WIP: SPF. Produce correct mechanism TXT bind9 output.

This commit is contained in:
Philippe Pittoli 2024-03-01 02:27:28 +01:00
parent fcbed27f60
commit 9953ccfb0b

View File

@ -260,21 +260,6 @@ class DNSManager::Storage::Zone
# baguette.netlib.re. 3600 IN TXT "v=spf1 a mx ip4:<IP> a:mail.baguette.netlib.re ~all" # baguette.netlib.re. 3600 IN TXT "v=spf1 a mx ip4:<IP> a:mail.baguette.netlib.re ~all"
class SPF < ResourceRecord class SPF < ResourceRecord
def qualifier_to_char(qualifier : Qualifier) : Char
case qualifier
when .pass?
'+'
when .none?
'?'
when .soft_fail?
'~'
# when .hard_fail?
else '-'
end
end
def qualifier_to_string(qualifier : Qualifier) : String
"#{qualifier_to_char qualifier}all"
end
# SPF mechanisms are about policy, which comes with the form of a single character: # SPF mechanisms are about policy, which comes with the form of a single character:
# - '?' means no policy (neutral), # - '?' means no policy (neutral),
@ -326,8 +311,8 @@ class DNSManager::Storage::Zone
errors errors
end end
def to_s def to_s(io : IO)
"#{@t}=#{v}" io << "#{@t}=#{v}"
end end
end end
@ -353,20 +338,32 @@ class DNSManager::Storage::Zone
# TODO # TODO
def get_errors : Array(Error) def get_errors : Array(Error)
errors = [] of Error errors = [] of Error
case @t case t
when Mechanism::Type::A when .a?
when Mechanism::Type::IP4 when .ip4?
when Mechanism::Type::IP6 when .ip6?
when Mechanism::Type::MX when .mx?
when Mechanism::Type::PTR when .ptr?
when Mechanism::Type::EXISTS when .exists?
when Mechanism::Type::INCLUDE when .include?
end end
errors errors
end end
def to_s def to_s(io : IO)
"#{qualifier_to_char @q}#{@t}=#{v}" to_bind9(io)
end
def to_bind9(io : IO)
case q
when .pass?
"#{t}=#{v}"
else
io << "#{qualifier_to_char q}"
end
io << t.to_s.downcase
io << "=#{v}" if v != ""
end end
end end
@ -704,3 +701,20 @@ class DNSManager::Storage::Zone
end end
end end
end end
def qualifier_to_char(qualifier : DNSManager::Storage::Zone::SPF::Qualifier) : Char
case qualifier
when .pass?
'+'
when .none?
'?'
when .soft_fail?
'~'
# when .hard_fail?
else '-'
end
end
def qualifier_to_string(qualifier : DNSManager::Storage::Zone::SPF::Qualifier) : String
"#{qualifier_to_char qualifier}all"
end