vmail: use domtool-portal to update vmail passwords
authorClinton Ebadi <clinton@unknownlamer.org>
Tue, 7 Oct 2014 04:10:56 +0000 (00:10 -0400)
committerClinton Ebadi <clinton@unknownlamer.org>
Tue, 7 Oct 2014 04:10:56 +0000 (00:10 -0400)
This disentangles the portal from having to run on the same machine as
the IMAP server.

vmailpasswd/pass.sml

index fbbf26f..30aef24 100644 (file)
@@ -8,15 +8,24 @@ fun validEmail email =
 
 fun change (email, old, new) =
     let
-       val cmd = String.concat ["/usr/bin/sudo /usr/local/bin/vmailpasswd \"",
-                                String.toString email,
-                                "\" \"",
-                                String.toString old,
-                                "\" \"",
-                                String.toString new,
-                                "\" >/dev/null 2>/dev/null"]
+       val [user, dom] = String.fields (fn ch => ch = #"@") email
+       val proc = Unix.executeInEnv ("/usr/local/sbin/domtool-portal", ["vmailpasswd", dom, user],
+                                     ["DOMTOOL_USER=hcoop.daemon"])
+       val out = Unix.textOutstreamOf proc
+
+       fun eatinput inf =
+           case TextIO.inputLine inf of
+               NONE => ()
+             | SOME line => eatinput inf
     in
-       OS.Process.isSuccess (OS.Process.system cmd)
+       TextIO.output (out, old ^ "\n");
+       TextIO.output (out, new ^ "\n");
+       TextIO.flushOut out;
+
+       eatinput (Unix.textInstreamOf proc);
+       TextIO.closeOut out;
+
+       OS.Process.isSuccess (Unix.reap proc)
     end
 
 end