Proper username determination in requests
[hcoop/domtool2.git] / src / main.sml
index 461207a..59607bb 100644 (file)
@@ -63,12 +63,6 @@ fun basis () =
 
 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 ()
 
@@ -139,13 +133,19 @@ fun hostname () =
 
 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",
-                                      Config.keyDir ^ "/" ^ user ^ ".pem",
+                                      Config.keyDir ^ "/" ^ user ^ "/key.pem",
                                       Config.trustStore)
 
        val bio = OpenSSL.connect (context, dispatcher)
@@ -238,6 +238,7 @@ fun service () =
                    cmdLoop ()
                end
     in
+       print "Listening for connections....\n";
        loop ();
        OpenSSL.shutdown sock
     end
@@ -247,7 +248,7 @@ fun slave () =
        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)