Remove catchAllAlias in favor of defaultAlias; add better handling of slave servers...
[hcoop/domtool2.git] / src / main.sml
index 51b8347..87f2869 100644 (file)
@@ -172,11 +172,12 @@ val self =
 
 fun context x =
     (OpenSSL.context false x)
-    handle e as OpenSSL.OpenSSL _ =>
+    handle e as OpenSSL.OpenSSL s =>
           (print "Couldn't find your certificate.\nYou probably haven't been given any Domtool privileges.\n";
+           print ("Additional information: " ^ s ^ "\n");
            raise e)
 
-fun requestContext f =
+fun setupUser () =
     let
        val user =
            case Posix.ProcEnv.getenv "DOMTOOL_USER" of
@@ -187,9 +188,15 @@ fun requestContext f =
                    Posix.SysDB.Passwd.name (Posix.SysDB.getpwuid uid)
                end
              | SOME user => user
-                  
-       val () = Acl.read Config.aclFile
-       val () = Domain.setUser user
+    in
+       Acl.read Config.aclFile;
+       Domain.setUser user;
+       user
+    end
+
+fun requestContext f =
+    let
+       val user = setupUser ()
                 
        val () = f ()
 
@@ -829,7 +836,8 @@ fun regenerate context =
                          | _ => print ("Slave " ^ node
                                        ^ " returned unexpected command\n");
                    OpenSSL.close bio
-               end             
+               end
+                handle OpenSSL.OpenSSL s => print ("OpenSSL error: " ^ s ^ "\n")
 
        fun doUser user =
            let
@@ -935,8 +943,11 @@ fun service () =
                             (print msgLocal;
                              print "\n";
                              Msg.send (bio, MsgOk)))
-                        handle OpenSSL.OpenSSL _ =>
-                               print "OpenSSL error\n"
+                        handle e as (OpenSSL.OpenSSL s) =>
+                               (print ("OpenSSL error: " ^ s ^ "\n");
+                                app (fn x => print (x ^ "\n")) (SMLofNJ.exnHistory e);
+                                Msg.send (bio, MsgError ("OpenSSL error: " ^ s))
+                                handle OpenSSL.OpenSSL _ => ())
                              | OS.SysErr (s, _) =>
                                (print "System error: ";
                                 print s;
@@ -1261,8 +1272,9 @@ fun service () =
                in
                    cmdLoop ()
                end
-                   handle OpenSSL.OpenSSL s =>
+                   handle e as (OpenSSL.OpenSSL s) =>
                           (print ("OpenSSL error: " ^ s ^ "\n");
+                           app (fn x => print (x ^ "\n")) (SMLofNJ.exnHistory e);
                            OpenSSL.close bio
                            handle OpenSSL.OpenSSL _ => ();
                            loop ())