Back to server-slide describe
[hcoop/domtool2.git] / src / main.sml
index 15a5853..8cc5a3a 100644 (file)
@@ -873,6 +873,21 @@ fun requestFirewall {node, uname} =
        before OpenSSL.close bio
     end
 
        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
+
 fun regenerateEither tc checker context =
     let
        fun ifReal f =
 fun regenerateEither tc checker context =
     let
        fun ifReal f =
@@ -942,7 +957,8 @@ fun regenerateEither tc checker context =
                    in
                        if !ErrorMsg.anyErrors then
                            (ErrorMsg.reset ();
                    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
                    end
                        else
                            app checker files
                    end
@@ -1417,6 +1433,20 @@ fun service () =
                                                      SOME "Script execution failed."))
                                      (fn () => ())
 
                                                      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"))
                               | _ =>
                                 doIt (fn () => ("Unexpected command",
                                                 SOME "Unexpected command"))