ip_of_node support
[hcoop/domtool2.git] / src / main.sml
index 9f01855..490f66d 100644 (file)
@@ -63,12 +63,6 @@ fun basis () =
 
 fun check fname =
     let
 
 fun check fname =
     let
-       val uid = Posix.ProcEnv.getuid ()
-       val user = Posix.SysDB.Passwd.name (Posix.SysDB.getpwuid uid)
-
-       val () = Acl.read Config.aclFile
-       val () = Domain.setUser user
-
        val _ = ErrorMsg.reset ()
        val _ = Env.preTycheck ()
 
        val _ = ErrorMsg.reset ()
        val _ = Env.preTycheck ()
 
@@ -139,13 +133,19 @@ fun hostname () =
 
 fun request fname =
     let
 
 fun request fname =
     let
+       val uid = Posix.ProcEnv.getuid ()
+       val user = Posix.SysDB.Passwd.name (Posix.SysDB.getpwuid uid)
+
+       val () = Acl.read Config.aclFile
+       val () = Domain.setUser user
+
        val _ = check fname
 
        val uid = Posix.ProcEnv.getuid ()
        val user = Posix.SysDB.Passwd.name (Posix.SysDB.getpwuid uid)
 
        val context = OpenSSL.context (Config.certDir ^ "/" ^ user ^ ".pem",
        val _ = check fname
 
        val uid = Posix.ProcEnv.getuid ()
        val user = Posix.SysDB.Passwd.name (Posix.SysDB.getpwuid uid)
 
        val context = OpenSSL.context (Config.certDir ^ "/" ^ user ^ ".pem",
-                                      Config.keyDir ^ "/" ^ user ^ ".pem",
+                                      Config.keyDir ^ "/" ^ user ^ "/key.pem",
                                       Config.trustStore)
 
        val bio = OpenSSL.connect (context, dispatcher)
                                       Config.trustStore)
 
        val bio = OpenSSL.connect (context, dispatcher)
@@ -212,21 +212,21 @@ fun service () =
                                    TextIO.closeOut outf;
                                    (eval outname;
                                     Msg.send (bio, MsgOk))
                                    TextIO.closeOut outf;
                                    (eval outname;
                                     Msg.send (bio, MsgOk))
-                                    handle ErrorMsg.Error =>
-                                           (print "Compilation error\n";
-                                            Msg.send (bio,
-                                                      MsgError "Error during configuration evaluation"))
-                                         | OpenSSL.OpenSSL s =>
-                                           (print "OpenSSL error\n";
-                                            Msg.send (bio,
-                                                      MsgError
-                                                          ("Error during configuration evaluation: "
-                                                           ^ s)));
-                                   OS.FileSys.remove outname;
-                                   (ignore (OpenSSL.readChar bio);
-                                    OpenSSL.close bio)
-                                   handle OpenSSL.OpenSSL _ => ();
-                                   loop ()
+                                   handle ErrorMsg.Error =>
+                                          (print "Compilation error\n";
+                                           Msg.send (bio,
+                                                     MsgError "Error during configuration evaluation"))
+                                        | OpenSSL.OpenSSL s =>
+                                          (print "OpenSSL error\n";
+                                           Msg.send (bio,
+                                                     MsgError
+                                                         ("Error during configuration evaluation: "
+                                                          ^ s)));
+                                          OS.FileSys.remove outname;
+                                          (ignore (OpenSSL.readChar bio);
+                                           OpenSSL.close bio)
+                                          handle OpenSSL.OpenSSL _ => ();
+                                          loop ()
                                end
                              | _ =>
                                (Msg.send (bio, MsgError "Unexpected command")
                                end
                              | _ =>
                                (Msg.send (bio, MsgError "Unexpected command")
@@ -237,6 +237,16 @@ fun service () =
                in
                    cmdLoop ()
                end
                in
                    cmdLoop ()
                end
+                   handle OpenSSL.OpenSSL s =>
+                          (print ("OpenSSL error: " ^ s ^ "\n");
+                           OpenSSL.close bio
+                           handle OpenSSL.OpenSSL _ => ();
+                           loop ())
+                        | OS.SysErr (s, _) =>
+                          (print ("System error: " ^ s ^ "\n");
+                           OpenSSL.close bio
+                           handle OpenSSL.OpenSSL _ => ();
+                           loop ())
     in
        print "Listening for connections....\n";
        loop ();
     in
        print "Listening for connections....\n";
        loop ();
@@ -248,7 +258,7 @@ fun slave () =
        val host = hostname ()
 
        val context = OpenSSL.context (Config.certDir ^ "/" ^ host ^ ".pem",
        val host = hostname ()
 
        val context = OpenSSL.context (Config.certDir ^ "/" ^ host ^ ".pem",
-                                      Config.keyDir ^ "/" ^ host ^ ".pem",
+                                      Config.keyDir ^ "/" ^ host ^ "/key.pem",
                                       Config.trustStore)
 
        val sock = OpenSSL.listen (context, Config.slavePort)
                                       Config.trustStore)
 
        val sock = OpenSSL.listen (context, Config.slavePort)
@@ -287,6 +297,11 @@ fun slave () =
                            OpenSSL.close bio
                                          handle OpenSSL.OpenSSL _ => ();
                            loop ())
                            OpenSSL.close bio
                                          handle OpenSSL.OpenSSL _ => ();
                            loop ())
+                        | OS.SysErr (s, _) =>
+                          (print ("System error: "^ s ^ "\n");
+                           OpenSSL.close bio
+                           handle OpenSSL.OpenSSL _ => ();
+                           loop ())
     in
        loop ();
        OpenSSL.shutdown sock
     in
        loop ();
        OpenSSL.shutdown sock