From ed9fda3a0e2edcf4ed546e0eb9ac128865538276 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Sun, 30 Jul 2006 22:29:22 +0000 Subject: [PATCH] More Exim stuff --- configDefault/exim.cfg | 2 ++ configDefault/exim.csg | 3 +++ lib/exim.dtl | 4 ++++ src/env.sig | 2 ++ src/env.sml | 5 +++++ src/plugins/exim.sml | 17 ++++++++++++++-- src/slave.sig | 5 +++++ src/slave.sml | 44 ++++++++++++++++++++++++++++++++++++++++++ tests/testExim.dtl | 11 +++++++++++ 9 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 lib/exim.dtl create mode 100644 tests/testExim.dtl diff --git a/configDefault/exim.cfg b/configDefault/exim.cfg index 78c7228..2a537be 100644 --- a/configDefault/exim.cfg +++ b/configDefault/exim.cfg @@ -6,4 +6,6 @@ val aliasesDefault = "/home/adamc/fake/aliases.default" val reload = "echo \"I would reload exim now.\"" (*"/etc/init.d/exim4 reload"*) +val handleDomains = "/home/adamc/fake/mail" + end diff --git a/configDefault/exim.csg b/configDefault/exim.csg index c8a2232..20c0e44 100644 --- a/configDefault/exim.csg +++ b/configDefault/exim.csg @@ -8,4 +8,7 @@ val aliasesDefault : string val reload : string (* Command-line to reload exim configuration *) +val handleDomains : string +(* File to which to write a comma-separate list of domains to handle mail for *) + end diff --git a/lib/exim.dtl b/lib/exim.dtl new file mode 100644 index 0000000..1152aef --- /dev/null +++ b/lib/exim.dtl @@ -0,0 +1,4 @@ +{{Exim MTA configuration}} + +extern val handleMail : [Domain]; +{{The local server should handle mail for this domain.}} diff --git a/src/env.sig b/src/env.sig index 5108bea..9c26f00 100644 --- a/src/env.sig +++ b/src/env.sig @@ -41,11 +41,13 @@ signature ENV = sig val string : string arg val list : 'a arg -> 'a list arg + val none : string -> (unit -> unit) -> action val one : string -> string * 'a arg -> ('a -> unit) -> action val two : string -> string * 'a arg * string * 'b arg -> ('a * 'b -> unit) -> action val type_one : string -> 'a arg -> ('a -> bool) -> unit + val action_none : string -> (unit -> unit) -> unit val action_one : string -> string * 'a arg -> ('a -> unit) -> unit val action_two : string -> string * 'a arg * string * 'b arg -> ('a * 'b -> unit) -> unit diff --git a/src/env.sml b/src/env.sml index 48ec715..85c29c9 100644 --- a/src/env.sml +++ b/src/env.sml @@ -70,6 +70,10 @@ fun mapFail f [] = SOME [] fun list f (EList ls, _) = mapFail f ls | list _ _ = NONE +fun none func f (_, []) = (f (); + SM.empty) + | none func _ (_, es) = badArgs (func, es) + fun one func (name, arg) f (_, [e]) = (case arg e of NONE => badArg (func, name, e) @@ -91,6 +95,7 @@ fun type_one func arg f = NONE => false | SOME v => f v) +fun action_none name f = registerAction (name, none name f) fun action_one name args f = registerAction (name, one name args f) fun action_two name args f = registerAction (name, two name args f) diff --git a/src/plugins/exim.sml b/src/plugins/exim.sml index 112ab5f..ee4cf80 100644 --- a/src/plugins/exim.sml +++ b/src/plugins/exim.sml @@ -22,10 +22,12 @@ structure Exim :> EXIM = struct val aliasesChanged = ref false val aliasesDefaultChanged = ref false +val hostsChanged = ref false val () = Slave.registerPreHandler (fn () => (aliasesChanged := false; - aliasesDefaultChanged := false)) + aliasesDefaultChanged := false; + hostsChanged := false)) val () = Slave.registerFileHandler (fn fs => let @@ -35,6 +37,8 @@ val () = Slave.registerFileHandler (fn fs => aliasesChanged := true else if #file spl = "aliases.default" then aliasesDefaultChanged := true + else if #file spl = "mail" then + hostsChanged := true else () end) @@ -49,10 +53,19 @@ val () = Slave.registerPostHandler Slave.concatTo (fn s => s = "aliases.default") Config.Exim.aliasesDefault else (); - if !aliasesChanged orelse !aliasesDefaultChanged then + if !hostsChanged then + Slave.enumerateTo (fn s => s = "mail") ":" Config.Exim.handleDomains + else + (); + if !aliasesChanged orelse !aliasesDefaultChanged + orelse !hostsChanged then Slave.shellF ([Config.Exim.reload], fn cl => "Error reloading exim with " ^ cl) else ())) + +val () = Env.action_none "handleMail" + (fn () => TextIO.closeOut (Domain.domainFile "mail")) + end diff --git a/src/slave.sig b/src/slave.sig index 76a4b05..52c9381 100644 --- a/src/slave.sig +++ b/src/slave.sig @@ -47,4 +47,9 @@ signature SLAVE = sig (* Search through the result configuration hierarchy for all files matching * the predicate, concatenating their contents in arbitrary order to the * given file. *) + + val enumerateTo : (string -> bool) -> string -> string -> unit + (* Search through the result configuration hierarchy for all files matching + * the predicate, writing a list of their domains to the file named by the + * third argument, delimiting the entries with the second argument. *) end diff --git a/src/slave.sml b/src/slave.sml index 1521b73..d43a8fa 100644 --- a/src/slave.sml +++ b/src/slave.sml @@ -100,4 +100,48 @@ fun concatTo p fname = visitDir Config.resultRoot end +fun enumerateTo p sep fname = + let + val outf = TextIO.openOut fname + + val first = ref true + val baseLen = length (String.fields (fn ch => ch = #"/") Config.resultRoot) + + fun visitDir dname = + let + val dir = Posix.FileSys.opendir dname + + fun loop () = + case Posix.FileSys.readdir dir of + NONE => Posix.FileSys.closedir dir + | SOME fname' => + let + val path = OS.Path.joinDirFile {dir = dname, file = fname'} + in + if Posix.FileSys.ST.isDir (Posix.FileSys.stat path) then + visitDir path + else if p fname' then + let + val toks = String.fields (fn ch => ch = #"/") dname + val toks = List.drop (toks, baseLen) + val dom = String.concatWith "." (rev toks) + in + if !first then + first := false + else + TextIO.output (outf, sep); + TextIO.output (outf, dom) + end + else + (); + loop () + end + in + loop () + end + in + visitDir Config.resultRoot; + TextIO.closeOut outf + end + end diff --git a/tests/testExim.dtl b/tests/testExim.dtl new file mode 100644 index 0000000..582cea3 --- /dev/null +++ b/tests/testExim.dtl @@ -0,0 +1,11 @@ +domain "hcoop.net" with + handleMail +end; + +domain "tpu.org" with + handleMail +end; + +domain "schizomaniac.net" with + +end -- 2.20.1