1 (* HCoop
Domtool (http
://hcoop
.sourceforge
.net
/)
2 * Copyright (c
) 2006-2007, 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
.
19 (* Domain
-related primitive actions
*)
21 structure Domain
:> DOMAIN
= struct
25 structure SM
= DataStructures
.StringMap
26 structure SS
= DataStructures
.StringSet
28 val ssl_context
= ref (NONE
: OpenSSL
.context option
)
29 fun set_context ctx
= ssl_context
:= SOME ctx
31 val nodes
= map #
1 Config
.nodeIps
32 val nodeMap
= foldl (fn ((node
, ip
), mp
) => SM
.insert (mp
, node
, ip
))
33 SM
.empty Config
.nodeIps
34 fun nodeIp node
= valOf (SM
.find (nodeMap
, node
))
39 val your_doms
= ref SS
.empty
40 fun your_domains () = !your_doms
42 val your_usrs
= ref SS
.empty
43 fun your_users () = !your_usrs
45 val your_grps
= ref SS
.empty
46 fun your_groups () = !your_grps
48 val your_pths
= ref SS
.empty
49 fun your_paths () = !your_pths
51 val world_readable
= SS
.addList (SS
.empty
, Config
.worldReadable
)
52 val readable_pths
= ref SS
.empty
53 fun readable_paths () = !readable_pths
59 val your_paths
= Acl
.class
{user
= getUser (),
62 your_doms
:= Acl
.class
{user
= getUser (),
64 your_usrs
:= Acl
.class
{user
= getUser (),
66 your_grps
:= Acl
.class
{user
= getUser (),
68 your_pths
:= your_paths
;
69 readable_pths
:= SS
.union (your_paths
, world_readable
)
73 case map
Int.fromString (String.fields (fn ch
=> ch
= #
".") s
) of
74 [SOME n1
, SOME n2
, SOME n3
, SOME n4
] =>
75 n1
>= 0 andalso n1
< 256 andalso n2
>= 0 andalso n2
< 256 andalso n3
>= 0 andalso n3
< 256 andalso n4
>= 0 andalso n4
< 256
78 fun isIdent ch
= Char.isLower ch
orelse Char.isDigit ch
81 size s
> 0 andalso size s
< 20
82 andalso CharVector
.all (fn ch
=> isIdent ch
orelse ch
= #
"-") s
85 size s
> 0 andalso size s
< 100
86 andalso List.all
validHost (String.fields (fn ch
=> ch
= #
".") s
)
88 fun validNode s
= List.exists (fn s
' => s
= s
') nodes
90 fun yourDomain s
= SS
.member (your_domains (), s
)
91 fun yourUser s
= SS
.member (your_users (), s
)
92 fun yourGroup s
= SS
.member (your_groups (), s
)
93 fun checkPath paths path
=
94 List.all (fn s
=> s
<> "..") (String.fields (fn ch
=> ch
= #
"/") path
)
95 andalso CharVector
.all (fn ch
=> Char.isAlphaNum ch
orelse ch
= #
"." orelse ch
= #
"/"
96 orelse ch
= #
"-" orelse ch
= #
"_") path
97 andalso SS
.exists (fn s
' => path
= s
' orelse String.isPrefix (s
' ^
"/") path
) (paths ())
98 val yourPath
= checkPath your_paths
99 val readablePath
= checkPath readable_paths
101 fun yourDomainHost s
=
104 val (pref
, suf
) = Substring
.splitl (fn ch
=> ch
<> #
".") (Substring
.full s
)
106 Substring
.size suf
> 0
107 andalso validHost (Substring
.string pref
)
108 andalso yourDomain (Substring
.string
109 (Substring
.slice (suf
, 1, NONE
)))
112 val yourDomain
= yourDomainHost
114 fun validUser s
= size s
> 0 andalso size s
< 20
115 andalso CharVector
.all
Char.isAlphaNum s
117 fun validEmailUser s
=
118 size s
> 0 andalso size s
< 50
119 andalso CharVector
.all (fn ch
=> Char.isAlphaNum ch
125 val validGroup
= validUser
127 val _
= Env
.type_one
"no_spaces"
129 (CharVector
.all (fn ch
=> Char.isPrint ch
andalso not (Char.isSpace ch
)
130 andalso ch
<> #
"\"" andalso ch
<> #
"'"))
131 val _
= Env
.type_one
"no_newlines"
133 (CharVector
.all (fn ch
=> Char.isPrint ch
andalso ch
<> #
"\n" andalso ch
<> #
"\r"
134 andalso ch
<> #
"\"" andalso ch
<> #
"'"))
136 val _
= Env
.type_one
"ip"
140 val _
= Env
.type_one
"host"
144 val _
= Env
.type_one
"domain"
148 val _
= Env
.type_one
"your_domain"
152 val _
= Env
.type_one
"your_domain_host"
156 val _
= Env
.type_one
"user"
160 val _
= Env
.type_one
"group"
164 val _
= Env
.type_one
"your_user"
168 val _
= Env
.type_one
"your_group"
172 val _
= Env
.type_one
"your_path"
176 val _
= Env
.type_one
"readable_path"
180 val _
= Env
.type_one
"node"
184 val _
= Env
.registerFunction ("dns_node_to_node",
188 val _
= Env
.registerFunction ("mail_node_to_node",
193 val dl
= ErrorMsg
.dummyLoc
195 val nsD
= (EString Config
.defaultNs
, dl
)
196 val serialD
= (EVar
"serialAuto", dl
)
197 val refD
= (EInt Config
.defaultRefresh
, dl
)
198 val retD
= (EInt Config
.defaultRetry
, dl
)
199 val expD
= (EInt Config
.defaultExpiry
, dl
)
200 val minD
= (EInt Config
.defaultMinimum
, dl
)
202 val soaD
= multiApp ((EVar
"soa", dl
),
204 [nsD
, serialD
, refD
, retD
, expD
, minD
])
206 val masterD
= (EApp ((EVar
"internalMaster", dl
),
207 (EString Config
.masterNode
, dl
)),
210 val slavesD
= (EList (map (fn s
=> (EString s
, dl
)) Config
.slaveNodes
), dl
)
212 val _
= Defaults
.registerDefault ("Aliases",
213 (TList (TBase
"your_domain", dl
), dl
),
214 (fn () => (EList
[], dl
)))
216 val _
= Defaults
.registerDefault ("Mailbox",
218 (fn () => (EString (getUser ()), dl
)))
220 val _
= Defaults
.registerDefault ("DNS",
221 (TBase
"dnsKind", dl
),
222 (fn () => multiApp ((EVar
"useDns", dl
),
224 [soaD
, masterD
, slavesD
])))
226 val _
= Defaults
.registerDefault ("TTL",
228 (fn () => (EInt Config
.Bind
.defaultTTL
, dl
)))
230 type soa
= {ns
: string,
237 val serial
= fn (EVar
"serialAuto", _
) => SOME NONE
238 |
(EApp ((EVar
"serialConst", _
), n
), _
) => Option
.map
SOME (Env
.int n
)
241 val soa
= fn (EApp ((EApp ((EApp ((EApp ((EApp ((EApp
242 ((EVar
"soa", _
), ns
), _
),
248 (case (Env
.string ns
, serial sl
, Env
.int rf
,
249 Env
.int ret
, Env
.int exp
, Env
.int min
) of
250 (SOME ns
, SOME sl
, SOME rf
,
251 SOME ret
, SOME exp
, SOME min
) =>
262 ExternalMaster
of string
263 | InternalMaster
of string
267 val _
= Env
.registerFunction ("ip_of_node",
268 fn [(EString node
, _
)] => SOME (EString (nodeIp node
), dl
)
271 val master
= fn (EApp ((EVar
"externalMaster", _
), e
), _
) => Option
.map
ExternalMaster (ip e
)
272 |
(EApp ((EVar
"internalMaster", _
), e
), _
) => Option
.map
InternalMaster (Env
.string e
)
276 UseDns
of {soa
: soa
,
278 slaves
: string list
}
281 val dnsKind
= fn (EApp ((EApp ((EApp
282 ((EVar
"useDns", _
), sa
), _
),
285 (case (soa sa
, master mstr
, Env
.list Env
.string slaves
) of
286 (SOME sa
, SOME mstr
, SOME slaves
) =>
287 SOME (UseDns
{soa
= sa
,
291 |
(EVar
"noDns", _
) => SOME NoDns
294 val befores
= ref (fn (_
: string) => ())
295 val afters
= ref (fn (_
: string) => ())
297 fun registerBefore f
=
301 befores
:= (fn x
=> (old x
; f x
))
304 fun registerAfter f
=
308 afters
:= (fn x
=> (old x
; f x
))
311 val globals
= ref (fn () => ())
312 val locals
= ref (fn () => ())
314 fun registerResetGlobal f
=
318 globals
:= (fn x
=> (old x
; f x
))
321 fun registerResetLocal f
=
325 locals
:= (fn x
=> (old x
; f x
))
328 fun resetGlobal () = (!globals ();
329 ignore (OS
.Process
.system (Config
.rm ^
" -rf " ^ Config
.resultRoot ^
"/*")))
330 fun resetLocal () = !locals ()
333 val currentPath
= ref (fn (_
: string) => "")
334 val currentPathAli
= ref (fn (_
: string, _
: string) => "")
338 fun currentDomain () = !current
340 val currentsAli
= ref ([] : string list
)
342 fun currentAliasDomains () = !currentsAli
343 fun currentDomains () = currentDomain () :: currentAliasDomains ()
345 fun domainFile
{node
, name
} = ((*print ("Opening " ^
!currentPath node ^ name ^
"\n");*)
346 TextIO.openOut (!currentPath node ^ name
))
348 type files
= {write
: string -> unit
,
349 writeDom
: unit
-> unit
,
350 close
: unit
-> unit
}
352 fun domainsFile
{node
, name
} =
354 val doms
= currentDomains ()
355 val files
= map (fn dom
=> (dom
, TextIO.openOut (!currentPathAli (dom
, node
) ^ name
))) doms
357 {write
= fn s
=> app (fn (_
, outf
) => TextIO.output (outf
, s
)) files
,
358 writeDom
= fn () => app (fn (dom
, outf
) => TextIO.output (outf
, dom
)) files
,
359 close
= fn () => app (fn (_
, outf
) => TextIO.closeOut outf
) files
}
364 val toks
= String.fields (fn ch
=> ch
= #
".") domain
366 val elems
= foldr (fn (piece
, elems
) =>
368 val elems
= piece
:: elems
372 val path
= String.concatWith
"/"
373 (Config
.resultRoot
:: node
:: rev elems
)
374 val tmpPath
= String.concatWith
"/"
375 (Config
.tmpDir
:: node
:: rev elems
)
377 (if Posix
.FileSys
.ST
.isDir
378 (Posix
.FileSys
.stat path
) then
381 (OS
.FileSys
.remove path
;
382 OS
.FileSys
.mkDir path
))
383 handle OS
.SysErr _
=> OS
.FileSys
.mkDir path
;
385 (if Posix
.FileSys
.ST
.isDir
386 (Posix
.FileSys
.stat tmpPath
) then
389 (OS
.FileSys
.remove tmpPath
;
390 OS
.FileSys
.mkDir tmpPath
))
391 handle OS
.SysErr _
=> OS
.FileSys
.mkDir tmpPath
398 fn (root
, site
) => String.concatWith
"/" (root
:: site
:: rev ("" :: elems
))
401 datatype file_action
' =
402 Add
' of {src
: string, dst
: string}
404 | Modify
' of {src
: string, dst
: string}
406 fun findDiffs (prefixes
, site
, dom
, acts
) =
409 val realPath
= gp (Config
.resultRoot
, site
)
410 val tmpPath
= gp (Config
.tmpDir
, site
)
412 (*val _
= print ("getDiffs(" ^ site ^
", " ^ dom ^
")... " ^ realPath ^
"; " ^ tmpPath ^
"\n")*)
414 val dir
= Posix
.FileSys
.opendir realPath
417 case Posix
.FileSys
.readdir dir
of
418 NONE
=> (Posix
.FileSys
.closedir dir
;
422 val real = OS
.Path
.joinDirFile
{dir
= realPath
,
424 val tmp
= OS
.Path
.joinDirFile
{dir
= tmpPath
,
427 if Posix
.FileSys
.ST
.isDir (Posix
.FileSys
.stat
real) then
429 else if Posix
.FileSys
.access (tmp
, []) then
430 if Slave
.shell
[Config
.diff
, " ", real, " ", tmp
] then
433 loopReal ((site
, dom
, realPath
, Modify
' {src
= tmp
, dst
= real}) :: acts
)
434 else if List.exists (fn prefix
=> String.isPrefix prefix realPath
) prefixes
then
435 loopReal ((site
, dom
, realPath
, Delete
' real) :: acts
)
440 val acts
= loopReal acts
442 val dir
= Posix
.FileSys
.opendir tmpPath
445 case Posix
.FileSys
.readdir dir
of
446 NONE
=> (Posix
.FileSys
.closedir dir
;
450 val real = OS
.Path
.joinDirFile
{dir
= realPath
,
452 val tmp
= OS
.Path
.joinDirFile
{dir
= tmpPath
,
455 if Posix
.FileSys
.ST
.isDir (Posix
.FileSys
.stat tmp
) then
457 else if Posix
.FileSys
.access (real, []) then
460 loopTmp ((site
, dom
, realPath
, Add
' {src
= tmp
, dst
= real}) :: acts
)
463 val acts
= loopTmp acts
468 fun findAllDiffs prefixes
=
470 val dir
= Posix
.FileSys
.opendir Config
.tmpDir
471 val len
= length (String.fields (fn ch
=> ch
= #
"/") Config
.tmpDir
) + 1
473 fun exploreSites diffs
=
474 case Posix
.FileSys
.readdir dir
of
478 fun explore (dname
, diffs
) =
480 val dir
= Posix
.FileSys
.opendir dname
483 case Posix
.FileSys
.readdir dir
of
487 val fname
= OS
.Path
.joinDirFile
{dir
= dname
,
490 loop (if Posix
.FileSys
.ST
.isDir (Posix
.FileSys
.stat fname
) then
492 val dom
= String.fields (fn ch
=> ch
= #
"/") fname
493 val dom
= List.drop (dom
, len
)
494 val dom
= String.concatWith
"." (rev dom
)
496 val dname
' = OS
.Path
.joinDirFile
{dir
= dname
,
500 findDiffs (prefixes
, site
, dom
, diffs
))
507 before Posix
.FileSys
.closedir dir
510 exploreSites (explore (OS
.Path
.joinDirFile
{dir
= Config
.tmpDir
,
511 file
= site
}, diffs
))
515 before Posix
.FileSys
.closedir dir
518 val masterNode
: string option ref
= ref NONE
519 fun dnsMaster () = !masterNode
521 val seenDomains
: string list ref
= ref
[]
523 val _
= Env
.containerV_one
"domain"
524 ("domain", Env
.string)
527 val () = seenDomains
:= dom
:: !seenDomains
529 val kind
= Env
.env
dnsKind (evs
, "DNS")
530 val ttl
= Env
.env Env
.int (evs
, "TTL")
531 val aliases
= Env
.env (Env
.list Env
.string) (evs
, "Aliases")
533 val path
= getPath dom
535 val () = (current
:= dom
;
536 currentsAli
:= Slave
.remove (Slave
.removeDups aliases
, dom
);
537 currentPath
:= (fn site
=> path (Config
.tmpDir
, site
));
538 currentPathAli
:= (fn (dom
, site
) => getPath
dom (Config
.tmpDir
, site
)))
540 fun saveSoa (kind
, soa
: soa
) node
=
542 val {write
, writeDom
, close
} = domainsFile
{node
= node
, name
= "soa"}
546 write (Int.toString ttl
);
552 | SOME n
=> write (Int.toString n
);
554 write (Int.toString (#ref soa
));
556 write (Int.toString (#ret soa
));
558 write (Int.toString (#exp soa
));
560 write (Int.toString (#min soa
));
565 fun saveNamed (kind
, soa
: soa
, masterIp
, slaveIps
) node
=
566 if dom
= "localhost" then
569 val {write
, writeDom
, close
} = domainsFile
{node
= node
, name
= "named.conf"}
573 write
"\" {\n\ttype ";
575 write
";\n\tfile \"";
576 write Config
.Bind
.zonePath_real
;
581 "master" => (write
"\tallow-transfer {\n";
582 app (fn ip
=> (write
"\t\t";
584 write
";\n")) slaveIps
;
586 | _
=> (write
"\tmasters { ";
594 NoDns
=> masterNode
:= NONE
599 InternalMaster node
=> nodeIp node
600 | ExternalMaster ip
=> ip
602 val slaveIps
= map
nodeIp (#slaves dns
)
604 app (saveSoa ("slave", #soa dns
)) (#slaves dns
);
605 app (saveNamed ("slave", #soa dns
, masterIp
, slaveIps
)) (#slaves dns
);
607 InternalMaster node
=>
608 (masterNode
:= SOME node
;
609 saveSoa ("master", #soa dns
) node
;
610 saveNamed ("master", #soa dns
, masterIp
, slaveIps
) node
)
611 | _
=> masterNode
:= NONE
615 fn () => !afters (!current
))
617 val () = Env
.registerPre (fn () => (seenDomains
:= [];
618 ignore (Slave
.shellF ([Config
.rm
, " -rf ", Config
.tmpDir
, ""],
619 fn cl
=> "Temp file cleanup failed: " ^ cl
));
620 OS
.FileSys
.mkDir Config
.tmpDir
;
621 app (fn node
=> OS
.FileSys
.mkDir
622 (OS
.Path
.joinDirFile
{dir
= Config
.tmpDir
,
625 app (fn node
=> OS
.FileSys
.mkDir
626 (OS
.Path
.joinDirFile
{dir
= Config
.resultRoot
,
628 handle OS
.SysErr _
=> ())
631 fun handleSite (site
, files
) =
635 print ("New configuration for node " ^ site ^
"\n");
636 if site
= Config
.defaultNode
then
637 Slave
.handleChanges files
639 val bio
= OpenSSL
.connect (valOf (!ssl_context
),
642 ^
Int.toString Config
.slavePort
)
644 app (fn file
=> Msg
.send (bio
, MsgFile file
)) files
;
645 Msg
.send (bio
, MsgDoFiles
);
647 NONE
=> print
"Slave closed connection unexpectedly\n"
650 MsgOk
=> print ("Slave " ^ site ^
" finished\n")
651 | MsgError s
=> print ("Slave " ^ site
652 ^
" returned error: " ^
654 | _
=> print ("Slave " ^ site
655 ^
" returned unexpected command\n");
660 val () = Env
.registerPost (fn () =>
662 val prefixes
= List.map (fn dom
=>
664 val pieces
= String.tokens (fn ch
=> ch
= #
".") dom
665 val path
= String.concatWith
"/" (rev pieces
)
667 Config
.resultRoot ^
"/" ^ path ^
"/"
670 val diffs
= findAllDiffs prefixes
672 val diffs
= map (fn (site
, dom
, dir
, Add
' {src
, dst
}) =>
673 (Slave
.shellF ([Config
.cp
, " ", src
, " ", dst
],
674 fn cl
=> "Copy failed: " ^ cl
);
680 |
(site
, dom
, dir
, Delete
' dst
) =>
681 (OS
.FileSys
.remove dst
682 handle OS
.SysErr _
=>
683 ErrorMsg
.error
NONE ("Delete failed for " ^ dst
);
685 {action
= Slave
.Delete
true,
689 |
(site
, dom
, dir
, Modify
' {src
, dst
}) =>
690 (Slave
.shellF ([Config
.cp
, " ", src
, " ", dst
],
691 fn cl
=> "Copy failed: " ^ cl
);
693 {action
= Slave
.Modify
,
698 if !ErrorMsg
.anyErrors
then
701 val changed
= foldl (fn ((site
, file
), changed
) =>
703 val ls
= case SM
.find (changed
, site
) of
707 SM
.insert (changed
, site
, file
:: ls
)
710 SM
.appi handleSite changed
712 ignore (Slave
.shellF ([Config
.rm
, " -rf ", Config
.tmpDir
, ""],
713 fn cl
=> "Temp file cleanup failed: " ^ cl
))
716 fun hasPriv priv
= Acl
.query
{user
= getUser (), class
= "priv", value
= "all"}
717 orelse Acl
.query
{user
= getUser (), class
= "priv", value
= priv
}
719 val _
= Env
.type_one
"dns_node"
722 List.exists (fn x
=> x
= node
) Config
.dnsNodes_all
723 orelse (hasPriv
"dns"
724 andalso List.exists (fn x
=> x
= node
) Config
.dnsNodes_admin
))
726 val _
= Env
.type_one
"mail_node"
729 List.exists (fn x
=> x
= node
) Config
.mailNodes_all
730 orelse (hasPriv
"mail"
731 andalso List.exists (fn x
=> x
= node
) Config
.mailNodes_admin
))
733 fun rmdom
' delete resultRoot doms
=
735 fun doNode (node
, _
) =
737 val dname
= OS
.Path
.joinDirFile
{dir
= resultRoot
,
740 fun doDom (dom
, actions
) =
742 val domPath
= String.concatWith
"/" (rev (String.fields (fn ch
=> ch
= #
".") dom
))
743 val dname
= OS
.Path
.concat (dname
, domPath
)
745 fun visitDom (dom
, dname
, actions
) =
747 val dir
= Posix
.FileSys
.opendir dname
750 case Posix
.FileSys
.readdir dir
of
754 val fnameFull
= OS
.Path
.joinDirFile
{dir
= dname
,
757 if Posix
.FileSys
.ST
.isDir (Posix
.FileSys
.stat fnameFull
) then
758 loop (visitDom (fname ^
"." ^ dom
,
762 loop ({action
= Slave
.Delete delete
,
765 file
= fnameFull
} :: actions
)
769 before Posix
.FileSys
.closedir dir
771 handle OS
.SysErr (s
, _
) =>
772 (print ("Warning: System error deleting domain " ^ dom ^
" on " ^ node ^
": " ^ s ^
"\n");
775 visitDom (dom
, dname
, actions
)
778 val actions
= foldl doDom
[] doms
780 handleSite (node
, actions
)
782 handle IO
.Io _
=> print ("Warning: IO error deleting domains on " ^ node ^
".\n")
784 fun cleanupNode (node
, _
) =
788 val domPath
= String.concatWith
"/" (rev (String.fields (fn ch
=> ch
= #
".") dom
))
789 val dname
= OS
.Path
.joinDirFile
{dir
= resultRoot
,
791 val dname
= OS
.Path
.concat (dname
, domPath
)
794 ignore (OS
.Process
.system (Config
.rm ^
" -rf " ^ dname
))
802 app doNode Config
.nodeIps
;
803 app cleanupNode Config
.nodeIps
806 val rmdom
= rmdom
' true Config
.resultRoot
807 val rmdom
' = rmdom
' false
809 fun homedirOf uname
=
810 Posix
.SysDB
.Passwd
.home (Posix
.SysDB
.getpwnam uname
)
812 fun homedir () = homedirOf (getUser ())
814 type subject
= {node
: string, domain
: string}
816 val describers
: (subject
-> string) list ref
= ref
[]
818 fun registerDescriber f
= describers
:= f
:: !describers
820 fun describeOne arg
= String.concat (map (fn f
=> f arg
) (rev (!describers
)))
822 val line
= "--------------------------------------------------------------\n"
823 val dline
= "==============================================================\n"
826 String.concat (List.mapPartial
828 case describeOne
{node
= node
, domain
= dom
} of
831 SOME (String.concat
[dline
, "Node ", node
, "\n", dline
, "\n", s
]))
834 datatype description
=
835 Filename
of { filename
: string, heading
: string, showEmpty
: bool }
836 | Extension
of { extension
: string, heading
: string -> string }
838 fun considerAll ds
{node
, domain
} =
840 val ds
= map (fn d
=> (d
, ref
[])) ds
842 val path
= Config
.resultRoot
843 val jdf
= OS
.Path
.joinDirFile
844 val path
= jdf
{dir
= path
, file
= node
}
845 val path
= foldr (fn (more
, path
) => jdf
{dir
= path
, file
= more
})
846 path (String.tokens (fn ch
=> ch
= #
".") domain
)
848 if Posix
.FileSys
.access (path
, []) then
850 val dir
= Posix
.FileSys
.opendir path
853 case Posix
.FileSys
.readdir dir
of
856 (app (fn (d
, entries
) =>
858 fun readFile showEmpty entries
' =
860 val fname
= OS
.Path
.joinDirFile
{dir
= path
,
863 val inf
= TextIO.openIn fname
865 fun loop (seenOne
, entries
') =
866 case TextIO.inputLine inf
of
867 NONE
=> if seenOne
orelse showEmpty
then
871 | SOME line
=> loop (true, line
:: entries
')
873 loop (false, entries
')
874 before TextIO.closeIn inf
878 Filename
{filename
, heading
, showEmpty
} =>
879 if fname
= filename
then
880 entries
:= readFile
showEmpty ("\n" :: line
:: ":\n" :: heading
:: line
:: !entries
)
883 | Extension
{extension
, heading
} =>
885 val {base
, ext
} = OS
.Path
.splitBaseExt fname
890 if extension
' = extension
then
891 entries
:= readFile
true ("\n" :: line
:: ":\n" :: heading base
:: line
:: !entries
)
899 Posix
.FileSys
.closedir dir
;
900 String.concat (List.concat (map (fn (_
, entries
) => rev (!entries
)) ds
))
906 val () = registerDescriber (considerAll
[Filename
{filename
= "soa",