String.sub (s, 0) <> #"."
andalso CharVector.all (fn ch => Char.isAlphaNum ch orelse ch = #"." orelse ch = #"_" orelse ch = #"-") s
-fun checkDir dname =
+fun setupUser () =
+ let
+ val user =
+ case Posix.ProcEnv.getenv "DOMTOOL_USER" of
+ NONE =>
+ let
+ val uid = Posix.ProcEnv.getuid ()
+ in
+ Posix.SysDB.Passwd.name (Posix.SysDB.getpwuid uid)
+ end
+ | SOME user => user
+ in
+ Acl.read Config.aclFile;
+ Domain.setUser user;
+ user
+ end
+
+fun checkDir' dname =
let
val b = basis ()
())
end
+fun checkDir dname =
+ (setupUser ();
+ checkDir' dname)
+
fun reduce fname =
let
val (G, body) = check fname
print ("Additional information: " ^ s ^ "\n");
raise e)
-fun setupUser () =
- let
- val user =
- case Posix.ProcEnv.getenv "DOMTOOL_USER" of
- NONE =>
- let
- val uid = Posix.ProcEnv.getuid ()
- in
- Posix.SysDB.Passwd.name (Posix.SysDB.getpwuid uid)
- end
- | SOME user => user
- in
- Acl.read Config.aclFile;
- Domain.setUser user;
- user
- end
-
fun requestContext f =
let
val user = setupUser ()
val _ = ErrorMsg.reset ()
- val (user, bio) = requestBio (fn () => checkDir dname)
+ val (user, bio) = requestBio (fn () => checkDir' dname)
val b = basis ()
let
val (user, bio) = requestBio (fn () => ())
in
- Msg.send (bio, MsgCreateDbTable p);
+ Msg.send (bio, MsgCreateDb p);
case Msg.recv bio of
NONE => print "Server closed connection unexpectedly.\n"
| SOME m =>
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
before OpenSSL.close bio
end
-fun regenerate context =
+fun requestDescribe dom =
+ let
+ val (_, bio) = requestBio (fn () => ())
+ in
+ Msg.send (bio, MsgDescribe dom);
+ case Msg.recv bio of
+ NONE => print "Server closed connection unexpectedly.\n"
+ | SOME m =>
+ case m of
+ MsgDescription s => print s
+ | MsgError s => print ("Description failed: " ^ s ^ "\n")
+ | _ => print "Unexpected server reply.\n";
+ OpenSSL.close bio
+ end
+
+fun regenerateEither tc checker context =
let
+ fun ifReal f =
+ if tc then
+ ()
+ else
+ f ()
+
val _ = ErrorMsg.reset ()
val b = basis ()
val () = Tycheck.disallowExterns ()
- val () = Domain.resetGlobal ()
+ val () = ifReal Domain.resetGlobal
val ok = ref true
in
if !ErrorMsg.anyErrors then
(ErrorMsg.reset ();
- print ("User " ^ user ^ "'s configuration has errors!\n"))
+ print ("User " ^ user ^ "'s configuration has errors!\n");
+ ok := false)
else
- app eval' files
+ app checker files
end
else
()
end
- handle IO.Io _ => ()
- | OS.SysErr (s, _) => (print ("System error processing user " ^ user ^ ": " ^ s ^ "\n");
- ok := false)
+ handle IO.Io {name, function, ...} =>
+ (print ("IO error processing user " ^ user ^ ": " ^ function ^ ": " ^ name ^ "\n");
+ ok := false)
+ | exn as OS.SysErr (s, _) => (print ("System error processing user " ^ user ^ ": " ^ s ^ "\n");
+ ok := false)
| ErrorMsg.Error => (ErrorMsg.reset ();
print ("User " ^ user ^ " had a compilation error.\n");
ok := false)
| _ => (print "Unknown exception during regeneration!\n";
ok := false)
in
- app contactNode Config.nodeIps;
- Env.pre ();
+ ifReal (fn () => (app contactNode Config.nodeIps;
+ Env.pre ()));
app doUser (Acl.users ());
- Env.post ();
+ ifReal Env.post;
!ok
end
-fun regenerateTc context =
- let
- val _ = ErrorMsg.reset ()
-
- val b = basis ()
- val () = Tycheck.disallowExterns ()
-
- val () = Domain.resetGlobal ()
-
- val ok = ref true
-
- fun doUser user =
- let
- val _ = Domain.setUser user
- val _ = ErrorMsg.reset ()
-
- val dname = Config.domtoolDir user
- in
- if Posix.FileSys.access (dname, []) then
- let
- val dir = Posix.FileSys.opendir dname
-
- fun loop files =
- case Posix.FileSys.readdir dir of
- NONE => (Posix.FileSys.closedir dir;
- files)
- | SOME fname =>
- if notTmp fname then
- loop (OS.Path.joinDirFile {dir = dname,
- file = fname}
- :: files)
- else
- loop files
-
- val files = loop []
- val (_, files) = Order.order (SOME b) files
- in
- if !ErrorMsg.anyErrors then
- (ErrorMsg.reset ();
- print ("User " ^ user ^ "'s configuration has errors!\n");
- ok := false)
- else
- app (ignore o check) files
- end
- else
- ()
- end
- handle IO.Io _ => ()
- | OS.SysErr (s, _) => print ("System error processing user " ^ user ^ ": " ^ s ^ "\n")
- | ErrorMsg.Error => (ErrorMsg.reset ();
- print ("User " ^ user ^ " had a compilation error.\n"))
- | _ => print "Unknown exception during -tc regeneration!\n"
- in
- app doUser (Acl.users ());
- !ok
- end
+val regenerate = regenerateEither false eval'
+val regenerateTc = regenerateEither true (ignore o check)
fun rmuser user =
let
SOME ("Error adding user: " ^ msg)))
(fn () => ())
- | MsgCreateDbTable {dbtype, dbname} =>
+ | MsgCreateDb {dbtype, dbname} =>
doIt (fn () =>
if Dbms.validDbname dbname then
case Dbms.lookup dbtype of
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,
SOME "Script execution failed."))
(fn () => ())
+ | MsgDescribe dom =>
+ doIt (fn () => if not (Domain.validDomain dom) then
+ ("Requested description of invalid domain " ^ dom,
+ SOME "Invalid domain name")
+ else if not (Domain.yourDomain dom
+ orelse Acl.query {user = user, class = "priv", value = "all"}) then
+ ("Requested description of " ^ dom ^ ", but not allowed access",
+ SOME "Access denied")
+ else
+ (Msg.send (bio, MsgDescription (Domain.describe dom));
+ ("Sent description of domain " ^ dom,
+ NONE)))
+ (fn () => ())
+
| _ =>
doIt (fn () => ("Unexpected command",
SOME "Unexpected command"))
OpenSSL.close bio
handle OpenSSL.OpenSSL _ => ();
loop ())
+ | OS.Path.InvalidArc =>
+ (print "Invalid arc\n";
+ OpenSSL.close bio
+ handle OpenSSL.OpenSSL _ => ();
+ loop ())
| e =>
(print "Unknown exception in main loop!\n";
app (fn x => print (x ^ "\n")) (SMLofNJ.exnHistory e);