X-Git-Url: https://git.hcoop.net/hcoop/domtool2.git/blobdiff_plain/c53e82e40cef407de986aa329d31457915ad0dbe..c189cbe97d554b26ec6b203b4ce9f697947ecc38:/src/main.sml diff --git a/src/main.sml b/src/main.sml index 3c0b728..0f65362 100644 --- a/src/main.sml +++ b/src/main.sml @@ -324,6 +324,21 @@ fun requestWhoHas perm = before OpenSSL.close bio end +fun requestRmdom dom = + let + val (_, bio) = requestBio (fn () => ()) + in + Msg.send (bio, MsgRmdom dom); + case Msg.recv bio of + NONE => print "Server closed connection unexpectedly.\n" + | SOME m => + case m of + MsgOk => print "Removal succeeded.\n" + | MsgError s => print ("Removal failed: " ^ s ^ "\n") + | _ => print "Unexpected server reply.\n"; + OpenSSL.close bio + end + fun service () = let val () = Acl.read Config.aclFile @@ -466,6 +481,30 @@ fun service () = handle OpenSSL.OpenSSL _ => (); loop ()) + | MsgRmdom dom => + if Acl.query {user = user, class = "priv", value = "all"} + orelse Acl.query {user = user, class = "domain", value = dom} then + ((Domain.rmdom dom; + Msg.send (bio, MsgOk); + print ("Removed domain " ^ dom ^ ".\n")) + handle OpenSSL.OpenSSL s => + (print "OpenSSL error\n"; + Msg.send (bio, + MsgError + ("Error during revocation: " + ^ s))); + (ignore (OpenSSL.readChar bio); + OpenSSL.close bio) + handle OpenSSL.OpenSSL _ => (); + loop ()) + else + ((Msg.send (bio, MsgError "Not authorized to remove that domain"); + print "Unauthorized user asked to remove a domain!\n"; + ignore (OpenSSL.readChar bio); + OpenSSL.close bio) + handle OpenSSL.OpenSSL _ => (); + loop ()) + | _ => (Msg.send (bio, MsgError "Unexpected command") handle OpenSSL.OpenSSL _ => ();