Be more cautious creating log directories
[hcoop/domtool2.git] / src / main.sml
index 3c0b728..0f65362 100644 (file)
@@ -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 _ => ();