X-Git-Url: https://git.hcoop.net/hcoop/domtool2.git/blobdiff_plain/41c58dafe735d17b7d3241bf248ca8806a355926..3af11fe69bf5f83cf12f5a37855faa8c81025b34:/src/main.sml?ds=sidebyside diff --git a/src/main.sml b/src/main.sml index 15a5853..d769a61 100644 --- a/src/main.sml +++ b/src/main.sml @@ -873,8 +873,80 @@ fun requestFirewall {node, uname} = before OpenSSL.close bio end +fun requestDescribe dom = + let + val (_, bio) = requestBio (fn () => ()) + in + Msg.send (bio, MsgDescribe dom); + case Msg.recv bio of + NONE => print "Server closed connection unexpectedly.\n" + | SOME m => + case m of + MsgDescription s => print s + | MsgError s => print ("Description failed: " ^ s ^ "\n") + | _ => print "Unexpected server reply.\n"; + OpenSSL.close bio + end + +structure SS = StringSet + +fun domainList dname = + let + val dir = Posix.FileSys.opendir dname + + fun visitNode dset = + case Posix.FileSys.readdir dir of + NONE => dset + | SOME node => + let + val path = OS.Path.joinDirFile {dir = dname, + file = node} + + fun visitDomains (path, bfor, dset) = + let + val dir = Posix.FileSys.opendir path + + fun loop dset = + case Posix.FileSys.readdir dir of + NONE => dset + | SOME dname => + let + val path = OS.Path.joinDirFile {dir = path, + file = dname} + in + if Posix.FileSys.ST.isDir (Posix.FileSys.stat path) then + let + val bfor = dname :: bfor + in + loop (visitDomains (path, bfor, + SS.add (dset, + String.concatWith "." bfor))) + end + else + loop dset + end + in + loop dset + before Posix.FileSys.closedir dir + end + in + visitNode (visitDomains (path, [], dset)) + end + in + visitNode SS.empty + before Posix.FileSys.closedir dir + end + fun regenerateEither tc checker context = let + val () = print "Starting regeneration....\n" + + val domainsBefore = + if tc then + SS.empty + else + domainList Config.resultRoot + fun ifReal f = if tc then () @@ -886,7 +958,11 @@ fun regenerateEither tc checker context = val b = basis () val () = Tycheck.disallowExterns () - val () = ifReal Domain.resetGlobal + val () = ifReal (fn () => + (ignore (OS.Process.system ("rm -rf " ^ Config.oldResultRoot ^ "/*")); + ignore (OS.Process.system ("cp -r " ^ Config.resultRoot + ^ "/* " ^ Config.oldResultRoot ^ "/")); + Domain.resetGlobal ())) val ok = ref true @@ -942,9 +1018,11 @@ fun regenerateEither tc checker context = in if !ErrorMsg.anyErrors then (ErrorMsg.reset (); - print ("User " ^ user ^ "'s configuration has errors!\n")) + print ("User " ^ user ^ "'s configuration has errors!\n"); + ok := false) else - app checker files + (); + app checker files end else () @@ -963,7 +1041,22 @@ fun regenerateEither tc checker context = ifReal (fn () => (app contactNode Config.nodeIps; Env.pre ())); app doUser (Acl.users ()); - ifReal Env.post; + ifReal (fn () => + let + val domainsAfter = domainList Config.resultRoot + val domainsGone = SS.difference (domainsBefore, domainsAfter) + in + if SS.isEmpty domainsGone then + () + else + (print "Domains to kill:"; + SS.app (fn s => (print " "; print s)) domainsGone; + print "\n"; + + Domain.rmdom' Config.oldResultRoot (SS.listItems domainsGone)); + + Env.post () + end); !ok end @@ -1417,6 +1510,20 @@ fun service () = SOME "Script execution failed.")) (fn () => ()) + | MsgDescribe dom => + doIt (fn () => if not (Domain.validDomain dom) then + ("Requested description of invalid domain " ^ dom, + SOME "Invalid domain name") + else if not (Domain.yourDomain dom + orelse Acl.query {user = user, class = "priv", value = "all"}) then + ("Requested description of " ^ dom ^ ", but not allowed access", + SOME "Access denied") + else + (Msg.send (bio, MsgDescription (Domain.describe dom)); + ("Sent description of domain " ^ dom, + NONE))) + (fn () => ()) + | _ => doIt (fn () => ("Unexpected command", SOME "Unexpected command"))