Remove catchAllAlias in favor of defaultAlias; add better handling of slave servers...
[hcoop/domtool2.git] / src / main.sml
index 4e377a9..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 ()
 
@@ -242,6 +249,14 @@ fun request fname =
 
 fun requestDir dname =
     let
+       val _ = if Posix.FileSys.access (dname, []) then
+                   ()
+               else
+                   (print ("Can't access " ^ dname ^ ".\n");
+                    print "Did you mean to run domtool on a specific file, instead of asking for all\n";
+                    print "files in your ~/domtool directory?\n";
+                    OS.Process.exit OS.Process.failure)
+
        val _ = ErrorMsg.reset ()
 
        val (user, bio) = requestBio (fn () => checkDir dname)
@@ -821,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
@@ -927,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;
@@ -1253,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 ())