1 (* HCoop
Domtool (http
://hcoop
.sourceforge
.net
/)
2 * Copyright (c
) 2006, Adam Chlipala
4 * This program is free software
; you can redistribute it
and/or
5 * modify it under the terms
of the GNU General Public License
6 * as published by the Free Software Foundation
; either version
2
7 * of the License
, or (at your option
) any later version
.
9 * This program is distributed
in the hope that it will be useful
,
10 * but WITHOUT ANY WARRANTY
; without even the implied warranty
of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
. See the
12 * GNU General Public License for more details
.
14 * You should have received a copy
of the GNU General Public License
15 * along
with this program
; if not
, write to the Free Software
16 * Foundation
, Inc
., 51 Franklin Street
, Fifth Floor
, Boston
, MA
02110-1301, USA
.
21 structure Main
:> MAIN
= struct
23 open Ast MsgTypes Print
25 structure SM
= StringMap
27 fun init () = Acl
.read Config
.aclFile
31 val prog
= Parse
.parse fname
33 if !ErrorMsg
.anyErrors
then
36 Tycheck
.checkFile
G (Defaults
.tInit ()) prog
41 val dir
= Posix
.FileSys
.opendir Config
.libRoot
44 case Posix
.FileSys
.readdir dir
of
45 NONE
=> (Posix
.FileSys
.closedir dir
;
48 if String.isSuffix
".dtl" fname
then
49 loop (OS
.Path
.joinDirFile
{dir
= Config
.libRoot
,
56 val (_
, files
) = Order
.order NONE files
58 if !ErrorMsg
.anyErrors
then
61 (Tycheck
.allowExterns ();
62 foldl (fn (fname
, G
) => check
' G fname
) Env
.empty files
63 before Tycheck
.disallowExterns ())
68 val _
= ErrorMsg
.reset ()
69 val _
= Env
.preTycheck ()
73 if !ErrorMsg
.anyErrors
then
77 val _
= Tycheck
.disallowExterns ()
78 val _
= ErrorMsg
.reset ()
79 val prog
= Parse
.parse fname
81 if !ErrorMsg
.anyErrors
then
85 val G
' = Tycheck
.checkFile
b (Defaults
.tInit ()) prog
87 if !ErrorMsg
.anyErrors
then
95 val notTmp
= CharVector
.all (fn ch
=> Char.isAlphaNum ch
orelse ch
= #
"." orelse ch
= #
"_" orelse ch
= #
"-")
101 val dir
= Posix
.FileSys
.opendir dname
104 case Posix
.FileSys
.readdir dir
of
105 NONE
=> (Posix
.FileSys
.closedir dir
;
109 loop (OS
.Path
.joinDirFile
{dir
= dname
,
116 val (_
, files
) = Order
.order (SOME b
) files
118 if !ErrorMsg
.anyErrors
then
121 (foldl (fn (fname
, G
) => check
' G fname
) b files
;
122 if !ErrorMsg
.anyErrors
then
130 val (G
, body
) = check fname
132 if !ErrorMsg
.anyErrors
then
138 val body
' = Reduce
.reduceExp G body
140 (*printd (PD
.hovBox (PD
.PPS
.Rel
0,
141 [PD
.string "Result:",
152 if !ErrorMsg
.anyErrors
then
155 Eval
.exec (Defaults
.eInit ()) body
'
156 | NONE
=> raise ErrorMsg
.Error
161 if !ErrorMsg
.anyErrors
then
164 ignore (Eval
.exec
' (Defaults
.eInit ()) body
')
165 | NONE
=> raise ErrorMsg
.Error
168 Config
.dispatcher ^
":" ^
Int.toString Config
.dispatcherPort
170 fun requestContext f
=
172 val uid
= Posix
.ProcEnv
.getuid ()
173 val user
= Posix
.SysDB
.Passwd
.name (Posix
.SysDB
.getpwuid uid
)
175 val () = Acl
.read Config
.aclFile
176 val () = Domain
.setUser user
180 val context
= OpenSSL
.context (Config
.certDir ^
"/" ^ user ^
".pem",
181 Config
.keyDir ^
"/" ^ user ^
"/key.pem",
189 val (user
, context
) = requestContext f
191 (user
, OpenSSL
.connect (context
, dispatcher
))
196 val (user
, bio
) = requestBio (fn () => ignore (check fname
))
198 val inf
= TextIO.openIn fname
201 case TextIO.inputLine inf
of
202 NONE
=> String.concat (List.rev lines
)
203 | SOME line
=> loop (line
:: lines
)
208 Msg
.send (bio
, MsgConfig code
);
210 NONE
=> print
"Server closed connection unexpectedly.\n"
213 MsgOk
=> print
"Configuration succeeded.\n"
214 | MsgError s
=> print ("Configuration failed: " ^ s ^
"\n")
215 | _
=> print
"Unexpected server reply.\n";
218 handle ErrorMsg
.Error
=> ()
220 fun requestDir dname
=
222 val _
= ErrorMsg
.reset ()
224 val (user
, bio
) = requestBio (fn () => checkDir dname
)
228 val dir
= Posix
.FileSys
.opendir dname
231 case Posix
.FileSys
.readdir dir
of
232 NONE
=> (Posix
.FileSys
.closedir dir
;
236 loop (OS
.Path
.joinDirFile
{dir
= dname
,
243 val (_
, files
) = Order
.order (SOME b
) files
245 val _
= if !ErrorMsg
.anyErrors
then
250 val codes
= map (fn fname
=>
252 val inf
= TextIO.openIn fname
255 case TextIO.inputLine inf
of
256 NONE
=> String.concat (rev lines
)
257 | SOME line
=> loop (line
:: lines
)
260 before TextIO.closeIn inf
263 if !ErrorMsg
.anyErrors
then
266 (Msg
.send (bio
, MsgMultiConfig codes
);
268 NONE
=> print
"Server closed connection unexpectedly.\n"
271 MsgOk
=> print
"Configuration succeeded.\n"
272 | MsgError s
=> print ("Configuration failed: " ^ s ^
"\n")
273 | _
=> print
"Unexpected server reply.\n";
276 handle ErrorMsg
.Error
=> ()
278 fun requestGrant acl
=
280 val (user
, bio
) = requestBio (fn () => ())
282 Msg
.send (bio
, MsgGrant acl
);
284 NONE
=> print
"Server closed connection unexpectedly.\n"
287 MsgOk
=> print
"Grant succeeded.\n"
288 | MsgError s
=> print ("Grant failed: " ^ s ^
"\n")
289 | _
=> print
"Unexpected server reply.\n";
293 fun requestRevoke acl
=
295 val (user
, bio
) = requestBio (fn () => ())
297 Msg
.send (bio
, MsgRevoke acl
);
299 NONE
=> print
"Server closed connection unexpectedly.\n"
302 MsgOk
=> print
"Revoke succeeded.\n"
303 | MsgError s
=> print ("Revoke failed: " ^ s ^
"\n")
304 | _
=> print
"Unexpected server reply.\n";
308 fun requestListPerms user
=
310 val (_
, bio
) = requestBio (fn () => ())
312 Msg
.send (bio
, MsgListPerms user
);
313 (case Msg
.recv bio
of
314 NONE
=> (print
"Server closed connection unexpectedly.\n";
318 MsgPerms perms
=> SOME perms
319 | MsgError s
=> (print ("Listing failed: " ^ s ^
"\n");
321 | _
=> (print
"Unexpected server reply.\n";
323 before OpenSSL
.close bio
326 fun requestWhoHas perm
=
328 val (_
, bio
) = requestBio (fn () => ())
330 Msg
.send (bio
, MsgWhoHas perm
);
331 (case Msg
.recv bio
of
332 NONE
=> (print
"Server closed connection unexpectedly.\n";
336 MsgWhoHasResponse users
=> SOME users
337 | MsgError s
=> (print ("whohas failed: " ^ s ^
"\n");
339 | _
=> (print
"Unexpected server reply.\n";
341 before OpenSSL
.close bio
344 fun requestRegen () =
346 val (_
, bio
) = requestBio (fn () => ())
348 Msg
.send (bio
, MsgRegenerate
);
350 NONE
=> print
"Server closed connection unexpectedly.\n"
353 MsgOk
=> print
"Regeneration succeeded.\n"
354 | MsgError s
=> print ("Regeneration failed: " ^ s ^
"\n")
355 | _
=> print
"Unexpected server reply.\n";
359 fun requestRmdom dom
=
361 val (_
, bio
) = requestBio (fn () => ())
363 Msg
.send (bio
, MsgRmdom dom
);
365 NONE
=> print
"Server closed connection unexpectedly.\n"
368 MsgOk
=> print
"Removal succeeded.\n"
369 | MsgError s
=> print ("Removal failed: " ^ s ^
"\n")
370 | _
=> print
"Unexpected server reply.\n";
374 fun requestRmuser user
=
376 val (_
, bio
) = requestBio (fn () => ())
378 Msg
.send (bio
, MsgRmuser user
);
380 NONE
=> print
"Server closed connection unexpectedly.\n"
383 MsgOk
=> print
"Removal succeeded.\n"
384 | MsgError s
=> print ("Removal failed: " ^ s ^
"\n")
385 | _
=> print
"Unexpected server reply.\n";
389 fun requestDbUser dbtype
=
391 val (_
, bio
) = requestBio (fn () => ())
393 Msg
.send (bio
, MsgCreateDbUser dbtype
);
395 NONE
=> print
"Server closed connection unexpectedly.\n"
398 MsgOk
=> print
"Your user has been created.\n"
399 | MsgError s
=> print ("Creation failed: " ^ s ^
"\n")
400 | _
=> print
"Unexpected server reply.\n";
404 fun requestDbTable p
=
406 val (user
, bio
) = requestBio (fn () => ())
408 Msg
.send (bio
, MsgCreateDbTable p
);
410 NONE
=> print
"Server closed connection unexpectedly.\n"
413 MsgOk
=> print ("Your database " ^ user ^
"_" ^ #dbname p ^
" has been created.\n")
414 | MsgError s
=> print ("Creation failed: " ^ s ^
"\n")
415 | _
=> print
"Unexpected server reply.\n";
419 fun requestListMailboxes domain
=
421 val (_
, bio
) = requestBio (fn () => ())
423 Msg
.send (bio
, MsgListMailboxes domain
);
424 (case Msg
.recv bio
of
425 NONE
=> Vmail
.Error
"Server closed connection unexpectedly."
428 MsgMailboxes users
=> (Msg
.send (bio
, MsgOk
);
430 | MsgError s
=> Vmail
.Error ("Creation failed: " ^ s
)
431 | _
=> Vmail
.Error
"Unexpected server reply.")
432 before OpenSSL
.close bio
435 fun requestNewMailbox p
=
437 val (_
, bio
) = requestBio (fn () => ())
439 Msg
.send (bio
, MsgNewMailbox p
);
441 NONE
=> print
"Server closed connection unexpectedly.\n"
444 MsgOk
=> print ("A mapping for " ^ #user p ^
"@" ^ #domain p ^
" has been created.\n")
445 | MsgError s
=> print ("Creation failed: " ^ s ^
"\n")
446 | _
=> print
"Unexpected server reply.\n";
450 fun requestPasswdMailbox p
=
452 val (_
, bio
) = requestBio (fn () => ())
454 Msg
.send (bio
, MsgPasswdMailbox p
);
456 NONE
=> print
"Server closed connection unexpectedly.\n"
459 MsgOk
=> print ("The password for " ^ #user p ^
"@" ^ #domain p ^
" has been changed.\n")
460 | MsgError s
=> print ("Set failed: " ^ s ^
"\n")
461 | _
=> print
"Unexpected server reply.\n";
465 fun requestRmMailbox p
=
467 val (_
, bio
) = requestBio (fn () => ())
469 Msg
.send (bio
, MsgRmMailbox p
);
471 NONE
=> print
"Server closed connection unexpectedly.\n"
474 MsgOk
=> print ("The mapping for mailbox " ^ #user p ^
"@" ^ #domain p ^
" has been deleted.\n")
475 | MsgError s
=> print ("Remove failed: " ^ s ^
"\n")
476 | _
=> print
"Unexpected server reply.\n";
480 fun requestSaQuery addr
=
482 val (_
, bio
) = requestBio (fn () => ())
484 Msg
.send (bio
, MsgSaQuery addr
);
485 (case Msg
.recv bio
of
486 NONE
=> print
"Server closed connection unexpectedly.\n"
489 MsgSaStatus b
=> (print ("SpamAssassin filtering for " ^ addr ^
" is "
490 ^
(if b
then "ON" else "OFF") ^
".\n");
491 Msg
.send (bio
, MsgOk
))
492 | MsgError s
=> print ("Query failed: " ^ s ^
"\n")
493 | _
=> print
"Unexpected server reply.\n")
494 before OpenSSL
.close bio
499 val (_
, bio
) = requestBio (fn () => ())
501 Msg
.send (bio
, MsgSaSet p
);
503 NONE
=> print
"Server closed connection unexpectedly.\n"
506 MsgOk
=> print ("SpamAssassin filtering for " ^ #
1 p ^
" is now "
507 ^
(if #
2 p
then "ON" else "OFF") ^
".\n")
508 | MsgError s
=> print ("Set failed: " ^ s ^
"\n")
509 | _
=> print
"Unexpected server reply.\n";
513 fun regenerate context
=
516 val () = Tycheck
.disallowExterns ()
518 val () = Domain
.resetGlobal ()
520 fun contactNode (node
, ip
) =
521 if node
= Config
.defaultNode
then
524 val bio
= OpenSSL
.connect (context
,
527 ^
Int.toString Config
.slavePort
)
529 Msg
.send (bio
, MsgRegenerate
);
531 NONE
=> print
"Slave closed connection unexpectedly\n"
534 MsgOk
=> print ("Slave " ^ node ^
" pre-regeneration finished\n")
535 | MsgError s
=> print ("Slave " ^ node
536 ^
" returned error: " ^
538 | _
=> print ("Slave " ^ node
539 ^
" returned unexpected command\n");
545 val _
= Domain
.setUser user
546 val _
= ErrorMsg
.reset ()
548 val dname
= Config
.domtoolDir user
550 val dir
= Posix
.FileSys
.opendir dname
553 case Posix
.FileSys
.readdir dir
of
554 NONE
=> (Posix
.FileSys
.closedir dir
;
558 loop (OS
.Path
.joinDirFile
{dir
= dname
,
565 val (_
, files
) = Order
.order (SOME b
) files
567 if !ErrorMsg
.anyErrors
then
568 print ("User " ^ user ^
"'s configuration has errors!\n")
573 | OS
.SysErr (s
, _
) => print ("System error processing user " ^ user ^
": " ^ s ^
"\n")
575 app contactNode Config
.nodeIps
;
577 app
doUser (Acl
.users ());
583 val doms
= Acl
.class
{user
= user
, class
= "domain"}
584 val doms
= List.filter (fn dom
=>
585 case Acl
.whoHas
{class
= "domain", value
= dom
} of
587 | _
=> false) (StringSet
.listItems doms
)
595 val () = Acl
.read Config
.aclFile
597 val context
= OpenSSL
.context (Config
.serverCert
,
600 val _
= Domain
.set_context context
602 val sock
= OpenSSL
.listen (context
, Config
.dispatcherPort
)
605 case OpenSSL
.accept sock
of
609 val user
= OpenSSL
.peerCN bio
610 val () = print ("\nConnection from " ^ user ^
"\n")
611 val () = Domain
.setUser user
615 (msgLocal
, SOME msgRemote
) =>
618 Msg
.send (bio
, MsgError msgRemote
))
619 |
(msgLocal
, NONE
) =>
622 Msg
.send (bio
, MsgOk
)))
623 handle OpenSSL
.OpenSSL _
=>
624 print
"OpenSSL error\n"
625 | OS
.SysErr (s
, _
) =>
626 (print
"System error: ";
629 Msg
.send (bio
, MsgError ("System error: " ^ s
))
630 handle OpenSSL
.OpenSSL _
=> ())
635 Msg
.send (bio
, MsgError ("Failure: " ^ s
))
636 handle OpenSSL
.OpenSSL _
=> ())
638 (print
"Compilation error\n";
639 Msg
.send (bio
, MsgError
"Error during configuration evaluation")
640 handle OpenSSL
.OpenSSL _
=> ());
642 ignore (OpenSSL
.readChar bio
);
644 handle OpenSSL
.OpenSSL _
=> ();
649 val _
= print
"Configuration:\n"
650 val _
= app (fn s
=> (print s
; print
"\n")) codes
653 val outname
= OS
.FileSys
.tmpName ()
657 val outf
= TextIO.openOut outname
659 TextIO.output (outf
, code
);
660 TextIO.closeOut outf
;
664 doIt (fn () => (Env
.pre ();
667 Msg
.send (bio
, MsgOk
);
668 ("Configuration complete.", NONE
)))
669 (fn () => OS
.FileSys
.remove outname
)
673 case String.fields (fn ch
=> ch
= #
"@") s
of
680 if Domain
.validEmailUser user
' andalso Domain
.yourDomain domain
then
688 NONE
=> (OpenSSL
.close bio
689 handle OpenSSL
.OpenSSL _
=> ();
693 MsgConfig code
=> doConfig
[code
]
694 | MsgMultiConfig codes
=> doConfig codes
698 if Acl
.query
{user
= user
, class
= "priv", value
= "all"} then
700 Acl
.write Config
.aclFile
;
701 ("Granted permission " ^ #value acl ^
" to " ^ #user acl ^
" in " ^ #class acl ^
".",
704 ("Unauthorized user asked to grant a permission!",
705 SOME
"Not authorized to grant privileges"))
710 if Acl
.query
{user
= user
, class
= "priv", value
= "all"} then
712 Acl
.write Config
.aclFile
;
713 ("Revoked permission " ^ #value acl ^
" from " ^ #user acl ^
" in " ^ #class acl ^
".",
716 ("Unauthorized user asked to revoke a permission!",
717 SOME
"Not authorized to revoke privileges"))
720 | MsgListPerms user
=>
722 (Msg
.send (bio
, MsgPerms (Acl
.queryAll user
));
723 ("Sent permission list for user " ^ user ^
".",
729 (Msg
.send (bio
, MsgWhoHasResponse (Acl
.whoHas perm
));
730 ("Sent whohas response for " ^ #class perm ^
" / " ^ #value perm ^
".",
736 if Acl
.query
{user
= user
, class
= "priv", value
= "all"}
737 orelse List.all (fn dom
=> Acl
.query
{user
= user
, class
= "domain", value
= dom
}) doms
then
740 Acl
.revokeFromAll
{class
= "domain", value
= dom
}) doms
;
741 Acl
.write Config
.aclFile
;
742 ("Removed domains" ^
foldl (fn (d
, s
) => s ^
" " ^ d
) "" doms ^
".",
745 ("Unauthorized user asked to remove a domain!",
746 SOME
"Not authorized to remove that domain"))
751 if Acl
.query
{user
= user
, class
= "priv", value
= "regen"}
752 orelse Acl
.query
{user
= user
, class
= "priv", value
= "all"} then
754 ("Regenerated all configuration.",
757 ("Unauthorized user asked to regenerate!",
758 SOME
"Not authorized to regenerate"))
763 if Acl
.query
{user
= user
, class
= "priv", value
= "all"} then
765 Acl
.write Config
.aclFile
;
766 ("Removed user " ^ user
' ^
".",
769 ("Unauthorized user asked to remove a user!",
770 SOME
"Not authorized to remove users"))
773 | MsgCreateDbUser
{dbtype
, passwd
} =>
775 case Dbms
.lookup dbtype
of
776 NONE
=> ("Database user creation request with unknown datatype type " ^ dbtype
,
777 SOME ("Unknown database type " ^ dbtype
))
779 case #adduser handler
{user
= user
, passwd
= passwd
} of
780 NONE
=> ("Added " ^ dbtype ^
" user " ^ user ^
".",
783 ("Error adding a " ^ dbtype ^
" user " ^ user ^
": " ^ msg
,
784 SOME ("Error adding user: " ^ msg
)))
787 | MsgCreateDbTable
{dbtype
, dbname
} =>
789 if Dbms
.validDbname dbname
then
790 case Dbms
.lookup dbtype
of
791 NONE
=> ("Database creation request with unknown datatype type " ^ dbtype
,
792 SOME ("Unknown database type " ^ dbtype
))
794 case #createdb handler
{user
= user
, dbname
= dbname
} of
795 NONE
=> ("Created database " ^ user ^
"_" ^ dbname ^
".",
797 | SOME msg
=> ("Error creating database " ^ user ^
"_" ^ dbname ^
": " ^ msg
,
798 SOME ("Error creating database: " ^ msg
))
800 ("Invalid database name " ^ user ^
"_" ^ dbname
,
801 SOME ("Invalid database name " ^ dbname
)))
804 | MsgListMailboxes domain
=>
806 if not (Domain
.yourDomain domain
) then
807 ("User wasn't authorized to list mailboxes for " ^ domain
,
808 SOME
"You're not authorized to configure that domain.")
810 case Vmail
.list domain
of
811 Vmail
.Listing users
=> (Msg
.send (bio
, MsgMailboxes users
);
812 ("Sent mailbox list for " ^ domain
,
814 | Vmail
.Error msg
=> ("Error listing mailboxes for " ^ domain ^
": " ^ msg
,
818 | MsgNewMailbox
{domain
, user
= emailUser
, passwd
, mailbox
} =>
820 if not (Domain
.yourDomain domain
) then
821 ("User wasn't authorized to add a mailbox to " ^ domain
,
822 SOME
"You're not authorized to configure that domain.")
823 else if not (Domain
.validEmailUser emailUser
) then
824 ("Invalid e-mail username " ^ emailUser
,
825 SOME
"Invalid e-mail username")
826 else if not (CharVector
.all
Char.isGraph passwd
) then
828 SOME
"Invalid password; may only contain printable, non-space characters")
829 else if not (Domain
.yourPath mailbox
) then
830 ("User wasn't authorized to add a mailbox at " ^ mailbox
,
831 SOME
"You're not authorized to use that mailbox location.")
833 case Vmail
.add
{requester
= user
,
834 domain
= domain
, user
= emailUser
,
835 passwd
= passwd
, mailbox
= mailbox
} of
836 NONE
=> ("Added mailbox " ^ emailUser ^
"@" ^ domain ^
" at " ^ mailbox
,
838 | SOME msg
=> ("Error adding mailbox " ^ emailUser ^
"@" ^ domain ^
": " ^ msg
,
842 | MsgPasswdMailbox
{domain
, user
= emailUser
, passwd
} =>
844 if not (Domain
.yourDomain domain
) then
845 ("User wasn't authorized to change password of a mailbox for " ^ domain
,
846 SOME
"You're not authorized to configure that domain.")
847 else if not (Domain
.validEmailUser emailUser
) then
848 ("Invalid e-mail username " ^ emailUser
,
849 SOME
"Invalid e-mail username")
850 else if not (CharVector
.all
Char.isGraph passwd
) then
852 SOME
"Invalid password; may only contain printable, non-space characters")
854 case Vmail
.passwd
{domain
= domain
, user
= emailUser
,
856 NONE
=> ("Changed password of mailbox " ^ emailUser ^
"@" ^ domain
,
858 | SOME msg
=> ("Error changing mailbox password for " ^ emailUser ^
"@" ^ domain ^
": " ^ msg
,
862 | MsgRmMailbox
{domain
, user
= emailUser
} =>
864 if not (Domain
.yourDomain domain
) then
865 ("User wasn't authorized to change password of a mailbox for " ^ domain
,
866 SOME
"You're not authorized to configure that domain.")
867 else if not (Domain
.validEmailUser emailUser
) then
868 ("Invalid e-mail username " ^ emailUser
,
869 SOME
"Invalid e-mail username")
871 case Vmail
.rm
{domain
= domain
, user
= emailUser
} of
872 NONE
=> ("Deleted mailbox " ^ emailUser ^
"@" ^ domain
,
874 | SOME msg
=> ("Error deleting mailbox " ^ emailUser ^
"@" ^ domain ^
": " ^ msg
,
880 case checkAddr addr
of
881 NONE
=> ("User tried to query SA filtering for " ^ addr
,
882 SOME
"You aren't allowed to configure SA filtering for that recipient.")
883 | SOME addr
' => (Msg
.send (bio
, MsgSaStatus (SetSA
.query addr
'));
884 ("Queried SA filtering status for " ^ addr
,
888 |
MsgSaSet (addr
, b
) =>
890 case checkAddr addr
of
891 NONE
=> ("User tried to set SA filtering for " ^ addr
,
892 SOME
"You aren't allowed to configure SA filtering for that recipient.")
893 | SOME addr
' => (SetSA
.set (addr
', b
);
894 Msg
.send (bio
, MsgOk
);
895 ("Set SA filtering status for " ^ addr ^
" to "
896 ^
(if b
then "ON" else "OFF"),
901 doIt (fn () => ("Unexpected command",
902 SOME
"Unexpected command"))
907 handle OpenSSL
.OpenSSL s
=>
908 (print ("OpenSSL error: " ^ s ^
"\n");
910 handle OpenSSL
.OpenSSL _
=> ();
912 | OS
.SysErr (s
, _
) =>
913 (print ("System error: " ^ s ^
"\n");
915 handle OpenSSL
.OpenSSL _
=> ();
918 print
"Listening for connections....\n";
920 OpenSSL
.shutdown sock
925 val host
= Slave
.hostname ()
927 val context
= OpenSSL
.context (Config
.certDir ^
"/" ^ host ^
".pem",
928 Config
.keyDir ^
"/" ^ host ^
"/key.pem",
931 val sock
= OpenSSL
.listen (context
, Config
.slavePort
)
934 case OpenSSL
.accept sock
of
938 val peer
= OpenSSL
.peerCN bio
939 val () = print ("\nConnection from " ^ peer ^
"\n")
941 if peer
<> Config
.dispatcherName
then
942 (print
"Not authorized!\n";
948 NONE
=> print
"Dispatcher closed connection unexpectedly\n"
951 MsgFile file
=> loop
' (file
:: files
)
952 | MsgDoFiles
=> (Slave
.handleChanges files
;
953 Msg
.send (bio
, MsgOk
))
954 | MsgRegenerate
=> (Domain
.resetLocal ();
955 Msg
.send (bio
, MsgOk
))
956 | _
=> (print
"Dispatcher sent unexpected command\n";
957 Msg
.send (bio
, MsgError
"Unexpected command"))
960 ignore (OpenSSL
.readChar bio
);
964 end handle OpenSSL
.OpenSSL s
=>
965 (print ("OpenSSL error: "^ s ^
"\n");
967 handle OpenSSL
.OpenSSL _
=> ();
969 | OS
.SysErr (s
, _
) =>
970 (print ("System error: "^ s ^
"\n");
972 handle OpenSSL
.OpenSSL _
=> ();
976 OpenSSL
.shutdown sock
981 val dir
= Posix
.FileSys
.opendir Config
.libRoot
984 case Posix
.FileSys
.readdir dir
of
985 NONE
=> (Posix
.FileSys
.closedir dir
;
988 if String.isSuffix
".dtl" fname
then
989 loop (OS
.Path
.joinDirFile
{dir
= Config
.libRoot
,
998 fun autodocBasis outdir
=
999 Autodoc
.autodoc
{outdir
= outdir
, infiles
= listBasis ()}