Stop ignoring Io exceptions
[hcoop/domtool2.git] / src / main.sml
index 3b54316..4539b65 100644 (file)
@@ -576,7 +576,7 @@ fun requestListMailboxes domain =
             case m of
                 MsgMailboxes users => (Msg.send (bio, MsgOk);
                                        Vmail.Listing users)
-              | MsgError s => Vmail.Error ("Creation failed: " ^ s)
+              | MsgError s => Vmail.Error ("Listing failed: " ^ s)
               | _ => Vmail.Error "Unexpected server reply.")
        before OpenSSL.close bio
     end
@@ -680,6 +680,21 @@ fun requestSmtpLog domain =
        OpenSSL.close bio
     end
 
+fun requestMysqlFixperms () =
+    let
+       val (_, bio) = requestBio (fn () => ())
+    in
+       Msg.send (bio, MsgMysqlFixperms);
+       case Msg.recv bio of
+           NONE => print "Server closed connection unexpectedly.\n"
+         | SOME m =>
+           case m of
+               MsgOk => print "Permissions granted.\n"
+             | MsgError s => print ("Failed: " ^ s ^ "\n")
+             | _ => print "Unexpected server reply.\n";
+       OpenSSL.close bio
+    end
+
 fun requestApt {node, pkg} =
     let
        val (user, context) = requestContext (fn () => ())
@@ -924,7 +939,9 @@ fun regenerate context =
                else
                    ()
            end
-           handle IO.Io _ => ()
+           handle IO.Io {name, function, ...} =>
+                  (print ("IO error processing user " ^ user ^ ": " ^ function ^ ": " ^ name ^ "\n");
+                   ok := false)
                 | OS.SysErr (s, _) => (print ("System error processing user " ^ user ^ ": " ^ s ^ "\n");
                                        ok := false)
                 | ErrorMsg.Error => (ErrorMsg.reset ();
@@ -1346,7 +1363,8 @@ fun service () =
                                               SOME "Invalid password; may only contain printable, non-space characters")
                                          else if not (Domain.yourPath mailbox) then
                                              ("User wasn't authorized to add a mailbox at " ^ mailbox,
-                                              SOME "You're not authorized to use that mailbox location.")
+                                              SOME ("You're not authorized to use that mailbox location. ("
+                                                    ^ mailbox ^ ")"))
                                          else
                                              case Vmail.add {requester = user,
                                                              domain = domain, user = emailUser,
@@ -1433,6 +1451,16 @@ fun service () =
                                                  NONE)))
                                      (fn () => ())
 
+                              | MsgMysqlFixperms =>
+                                doIt (fn () => if OS.Process.isSuccess
+                                                      (OS.Process.system "/usr/bin/sudo -H /afs/hcoop.net/common/etc/scripts/mysql-grant-table-drop") then
+                                                   ("Requested mysql-fixperms",
+                                                    NONE)
+                                                else
+                                                    ("Requested mysql-fixperms, but execution failed!",
+                                                     SOME "Script execution failed."))
+                                     (fn () => ())
+
                               | _ =>
                                 doIt (fn () => ("Unexpected command",
                                                 SOME "Unexpected command"))