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 your_ipss
= ref SS
.empty
52 fun your_ips () = !your_ipss
54 val world_readable
= SS
.addList (SS
.empty
, Config
.worldReadable
)
55 val readable_pths
= ref world_readable
56 fun readable_paths () = !readable_pths
62 val your_paths
= Acl
.class
{user
= getUser (),
65 your_doms
:= Acl
.class
{user
= getUser (),
67 your_usrs
:= Acl
.class
{user
= getUser (),
69 your_grps
:= Acl
.class
{user
= getUser (),
71 your_pths
:= your_paths
;
72 readable_pths
:= SS
.union (your_paths
, world_readable
);
73 your_ipss
:= Acl
.class
{user
= getUser (),
78 case map
Int.fromString (String.fields (fn ch
=> ch
= #
".") s
) of
79 [SOME n1
, SOME n2
, SOME n3
, SOME n4
] =>
80 n1
>= 0 andalso n1
< 256 andalso n2
>= 0 andalso n2
< 256 andalso n3
>= 0 andalso n3
< 256 andalso n4
>= 0 andalso n4
< 256
83 fun isIdent ch
= Char.isLower ch
orelse Char.isDigit ch
86 size s
> 0 andalso size s
< 20
87 andalso CharVector
.all (fn ch
=> isIdent ch
orelse ch
= #
"-") s
90 size s
> 0 andalso size s
< 100
91 andalso List.all
validHost (String.fields (fn ch
=> ch
= #
".") s
)
93 fun validNode s
= List.exists (fn s
' => s
= s
') nodes
95 fun yourDomain s
= SS
.member (your_domains (), s
)
96 fun yourUser s
= SS
.member (your_users (), s
)
97 fun yourGroup s
= SS
.member (your_groups (), s
)
98 fun checkPath paths path
=
99 List.all (fn s
=> s
<> "..") (String.fields (fn ch
=> ch
= #
"/") path
)
100 andalso CharVector
.all (fn ch
=> Char.isAlphaNum ch
orelse ch
= #
"." orelse ch
= #
"/"
101 orelse ch
= #
"-" orelse ch
= #
"_") path
102 andalso SS
.exists (fn s
' => path
= s
' orelse String.isPrefix (s
' ^
"/") path
) (paths ())
103 val yourPath
= checkPath your_paths
104 val readablePath
= checkPath readable_paths
105 fun yourIp s
= SS
.member (your_ips (), s
)
107 fun yourDomainHost s
=
110 val (pref
, suf
) = Substring
.splitl (fn ch
=> ch
<> #
".") (Substring
.full s
)
112 Substring
.size suf
> 0
113 andalso validHost (Substring
.string pref
)
114 andalso yourDomain (Substring
.string
115 (Substring
.slice (suf
, 1, NONE
)))
118 val yourDomain
= yourDomainHost
120 fun validUser s
= size s
> 0 andalso size s
< 20
121 andalso CharVector
.all
Char.isAlphaNum s
123 fun validEmailUser s
=
124 size s
> 0 andalso size s
< 50
125 andalso CharVector
.all (fn ch
=> Char.isAlphaNum ch
131 val validGroup
= validUser
133 val _
= Env
.type_one
"no_spaces"
135 (CharVector
.all (fn ch
=> Char.isPrint ch
andalso not (Char.isSpace ch
)
136 andalso ch
<> #
"\"" andalso ch
<> #
"'"))
137 val _
= Env
.type_one
"no_newlines"
139 (CharVector
.all (fn ch
=> Char.isPrint ch
andalso ch
<> #
"\n" andalso ch
<> #
"\r"
140 andalso ch
<> #
"\"" andalso ch
<> #
"'"))
142 val _
= Env
.type_one
"ip"
146 val _
= Env
.type_one
"host"
150 val _
= Env
.type_one
"domain"
154 val _
= Env
.type_one
"your_domain"
158 val _
= Env
.type_one
"your_domain_host"
162 val _
= Env
.type_one
"user"
166 val _
= Env
.type_one
"group"
170 val _
= Env
.type_one
"your_user"
174 val _
= Env
.type_one
"your_group"
178 val _
= Env
.type_one
"your_path"
182 val _
= Env
.type_one
"readable_path"
186 val _
= Env
.type_one
"your_ip"
190 val _
= Env
.type_one
"node"
194 val _
= Env
.registerFunction ("your_ip_to_ip",
198 val _
= Env
.registerFunction ("dns_node_to_node",
202 val _
= Env
.registerFunction ("mail_node_to_node",
207 val dl
= ErrorMsg
.dummyLoc
209 val nsD
= (EString Config
.defaultNs
, dl
)
210 val serialD
= (EVar
"serialAuto", dl
)
211 val refD
= (EInt Config
.defaultRefresh
, dl
)
212 val retD
= (EInt Config
.defaultRetry
, dl
)
213 val expD
= (EInt Config
.defaultExpiry
, dl
)
214 val minD
= (EInt Config
.defaultMinimum
, dl
)
216 val soaD
= multiApp ((EVar
"soa", dl
),
218 [nsD
, serialD
, refD
, retD
, expD
, minD
])
220 val masterD
= (EApp ((EVar
"internalMaster", dl
),
221 (EString Config
.masterNode
, dl
)),
224 val slavesD
= (EList (map (fn s
=> (EString s
, dl
)) Config
.slaveNodes
), dl
)
226 val _
= Defaults
.registerDefault ("Aliases",
227 (TList (TBase
"your_domain", dl
), dl
),
228 (fn () => (EList
[], dl
)))
230 val _
= Defaults
.registerDefault ("Mailbox",
232 (fn () => (EString (getUser ()), dl
)))
234 val _
= Defaults
.registerDefault ("DNS",
235 (TBase
"dnsKind", dl
),
236 (fn () => multiApp ((EVar
"useDns", dl
),
238 [soaD
, masterD
, slavesD
])))
240 val _
= Defaults
.registerDefault ("TTL",
242 (fn () => (EInt Config
.Bind
.defaultTTL
, dl
)))
244 type soa
= {ns
: string,
251 val serial
= fn (EVar
"serialAuto", _
) => SOME NONE
252 |
(EApp ((EVar
"serialConst", _
), n
), _
) => Option
.map
SOME (Env
.int n
)
255 val soa
= fn (EApp ((EApp ((EApp ((EApp ((EApp ((EApp
256 ((EVar
"soa", _
), ns
), _
),
262 (case (Env
.string ns
, serial sl
, Env
.int rf
,
263 Env
.int ret
, Env
.int exp
, Env
.int min
) of
264 (SOME ns
, SOME sl
, SOME rf
,
265 SOME ret
, SOME exp
, SOME min
) =>
276 ExternalMaster
of string
277 | InternalMaster
of string
281 val _
= Env
.registerFunction ("ip_of_node",
282 fn [(EString node
, _
)] => SOME (EString (nodeIp node
), dl
)
285 val master
= fn (EApp ((EVar
"externalMaster", _
), e
), _
) => Option
.map
ExternalMaster (ip e
)
286 |
(EApp ((EVar
"internalMaster", _
), e
), _
) => Option
.map
InternalMaster (Env
.string e
)
290 UseDns
of {soa
: soa
,
292 slaves
: string list
}
295 val dnsKind
= fn (EApp ((EApp ((EApp
296 ((EVar
"useDns", _
), sa
), _
),
299 (case (soa sa
, master mstr
, Env
.list Env
.string slaves
) of
300 (SOME sa
, SOME mstr
, SOME slaves
) =>
301 SOME (UseDns
{soa
= sa
,
305 |
(EVar
"noDns", _
) => SOME NoDns
308 val befores
= ref (fn (_
: string) => ())
309 val afters
= ref (fn (_
: string) => ())
311 fun registerBefore f
=
315 befores
:= (fn x
=> (old x
; f x
))
318 fun registerAfter f
=
322 afters
:= (fn x
=> (old x
; f x
))
325 val globals
= ref (fn () => ())
326 val locals
= ref (fn () => ())
328 fun registerResetGlobal f
=
332 globals
:= (fn x
=> (old x
; f x
))
335 fun registerResetLocal f
=
339 locals
:= (fn x
=> (old x
; f x
))
342 fun resetGlobal () = (!globals ();
343 ignore (OS
.Process
.system (Config
.rm ^
" -rf " ^ Config
.resultRoot ^
"/*")))
344 fun resetLocal () = !locals ()
347 val currentPath
= ref (fn (_
: string) => "")
348 val currentPathAli
= ref (fn (_
: string, _
: string) => "")
352 fun currentDomain () = !current
354 val currentsAli
= ref ([] : string list
)
356 fun currentAliasDomains () = !currentsAli
357 fun currentDomains () = currentDomain () :: currentAliasDomains ()
359 fun domainFile
{node
, name
} = ((*print ("Opening " ^
!currentPath node ^ name ^
"\n");*)
360 TextIO.openOut (!currentPath node ^ name
))
362 type files
= {write
: string -> unit
,
363 writeDom
: unit
-> unit
,
364 close
: unit
-> unit
}
366 fun domainsFile
{node
, name
} =
368 val doms
= currentDomains ()
369 val files
= map (fn dom
=> (dom
, TextIO.openOut (!currentPathAli (dom
, node
) ^ name
))) doms
371 {write
= fn s
=> app (fn (_
, outf
) => TextIO.output (outf
, s
)) files
,
372 writeDom
= fn () => app (fn (dom
, outf
) => TextIO.output (outf
, dom
)) files
,
373 close
= fn () => app (fn (_
, outf
) => TextIO.closeOut outf
) files
}
378 val toks
= String.fields (fn ch
=> ch
= #
".") domain
380 val elems
= foldr (fn (piece
, elems
) =>
382 val elems
= piece
:: elems
386 val path
= String.concatWith
"/"
387 (Config
.resultRoot
:: node
:: rev elems
)
388 val tmpPath
= String.concatWith
"/"
389 (Config
.tmpDir
:: node
:: rev elems
)
391 (if Posix
.FileSys
.ST
.isDir
392 (Posix
.FileSys
.stat path
) then
395 (OS
.FileSys
.remove path
;
396 OS
.FileSys
.mkDir path
))
397 handle OS
.SysErr _
=> OS
.FileSys
.mkDir path
;
399 (if Posix
.FileSys
.ST
.isDir
400 (Posix
.FileSys
.stat tmpPath
) then
403 (OS
.FileSys
.remove tmpPath
;
404 OS
.FileSys
.mkDir tmpPath
))
405 handle OS
.SysErr _
=> OS
.FileSys
.mkDir tmpPath
412 fn (root
, site
) => String.concatWith
"/" (root
:: site
:: rev ("" :: elems
))
415 datatype file_action
' =
416 Add
' of {src
: string, dst
: string}
418 | Modify
' of {src
: string, dst
: string}
420 fun findDiffs (prefixes
, site
, dom
, acts
) =
423 val realPath
= gp (Config
.resultRoot
, site
)
424 val tmpPath
= gp (Config
.tmpDir
, site
)
426 (*val _
= print ("getDiffs(" ^ site ^
", " ^ dom ^
")... " ^ realPath ^
"; " ^ tmpPath ^
"\n")*)
428 val dir
= Posix
.FileSys
.opendir realPath
431 case Posix
.FileSys
.readdir dir
of
432 NONE
=> (Posix
.FileSys
.closedir dir
;
436 val real = OS
.Path
.joinDirFile
{dir
= realPath
,
438 val tmp
= OS
.Path
.joinDirFile
{dir
= tmpPath
,
441 if Posix
.FileSys
.ST
.isDir (Posix
.FileSys
.stat
real) then
443 else if Posix
.FileSys
.access (tmp
, []) then
444 if Slave
.shell
[Config
.diff
, " ", real, " ", tmp
] then
447 loopReal ((site
, dom
, realPath
, Modify
' {src
= tmp
, dst
= real}) :: acts
)
448 else if List.exists (fn prefix
=> String.isPrefix prefix
real) prefixes
then
449 loopReal ((site
, dom
, realPath
, Delete
' real) :: acts
)
454 val acts
= loopReal acts
456 val dir
= Posix
.FileSys
.opendir tmpPath
459 case Posix
.FileSys
.readdir dir
of
460 NONE
=> (Posix
.FileSys
.closedir dir
;
464 val real = OS
.Path
.joinDirFile
{dir
= realPath
,
466 val tmp
= OS
.Path
.joinDirFile
{dir
= tmpPath
,
469 if Posix
.FileSys
.ST
.isDir (Posix
.FileSys
.stat tmp
) then
471 else if Posix
.FileSys
.access (real, []) then
474 loopTmp ((site
, dom
, realPath
, Add
' {src
= tmp
, dst
= real}) :: acts
)
477 val acts
= loopTmp acts
482 fun findAllDiffs prefixes
=
484 val dir
= Posix
.FileSys
.opendir Config
.tmpDir
485 val len
= length (String.fields (fn ch
=> ch
= #
"/") Config
.tmpDir
) + 1
487 fun exploreSites diffs
=
488 case Posix
.FileSys
.readdir dir
of
492 fun explore (dname
, diffs
) =
494 val dir
= Posix
.FileSys
.opendir dname
497 case Posix
.FileSys
.readdir dir
of
501 val fname
= OS
.Path
.joinDirFile
{dir
= dname
,
504 loop (if Posix
.FileSys
.ST
.isDir (Posix
.FileSys
.stat fname
) then
506 val dom
= String.fields (fn ch
=> ch
= #
"/") fname
507 val dom
= List.drop (dom
, len
)
508 val dom
= String.concatWith
"." (rev dom
)
510 val dname
' = OS
.Path
.joinDirFile
{dir
= dname
,
514 findDiffs (prefixes
, site
, dom
, diffs
))
521 before Posix
.FileSys
.closedir dir
524 exploreSites (explore (OS
.Path
.joinDirFile
{dir
= Config
.tmpDir
,
525 file
= site
}, diffs
))
529 before Posix
.FileSys
.closedir dir
532 val masterNode
: string option ref
= ref NONE
533 fun dnsMaster () = !masterNode
535 val seenDomains
: string list ref
= ref
[]
537 val _
= Env
.containerV_one
"domain"
538 ("domain", Env
.string)
541 val () = seenDomains
:= dom
:: !seenDomains
543 val kind
= Env
.env
dnsKind (evs
, "DNS")
544 val ttl
= Env
.env Env
.int (evs
, "TTL")
545 val aliases
= Env
.env (Env
.list Env
.string) (evs
, "Aliases")
547 val path
= getPath dom
549 val () = (current
:= dom
;
550 currentsAli
:= Slave
.remove (Slave
.removeDups aliases
, dom
);
551 currentPath
:= (fn site
=> path (Config
.tmpDir
, site
));
552 currentPathAli
:= (fn (dom
, site
) => getPath
dom (Config
.tmpDir
, site
)))
554 fun saveSoa (kind
, soa
: soa
) node
=
556 val {write
, writeDom
, close
} = domainsFile
{node
= node
, name
= "soa"}
560 write (Int.toString ttl
);
566 | SOME n
=> write (Int.toString n
);
568 write (Int.toString (#ref soa
));
570 write (Int.toString (#ret soa
));
572 write (Int.toString (#exp soa
));
574 write (Int.toString (#min soa
));
579 fun saveNamed (kind
, soa
: soa
, masterIp
, slaveIps
) node
=
580 if dom
= "localhost" then
583 val {write
, writeDom
, close
} = domainsFile
{node
= node
, name
= "named.conf"}
587 write
"\" {\n\ttype ";
589 write
";\n\tfile \"";
590 write Config
.Bind
.zonePath_real
;
595 "master" => (write
"\tallow-transfer {\n";
596 app (fn ip
=> (write
"\t\t";
598 write
";\n")) slaveIps
;
600 | _
=> (write
"\tmasters { ";
608 NoDns
=> masterNode
:= NONE
613 InternalMaster node
=> nodeIp node
614 | ExternalMaster ip
=> ip
616 val slaveIps
= map
nodeIp (#slaves dns
)
618 app (saveSoa ("slave", #soa dns
)) (#slaves dns
);
619 app (saveNamed ("slave", #soa dns
, masterIp
, slaveIps
)) (#slaves dns
);
621 InternalMaster node
=>
622 (masterNode
:= SOME node
;
623 saveSoa ("master", #soa dns
) node
;
624 saveNamed ("master", #soa dns
, masterIp
, slaveIps
) node
)
625 | _
=> masterNode
:= NONE
629 fn () => !afters (!current
))
631 val () = Env
.registerPre (fn () => (seenDomains
:= [];
632 ignore (Slave
.shellF ([Config
.rm
, " -rf ", Config
.tmpDir
, ""],
633 fn cl
=> "Temp file cleanup failed: " ^ cl
));
634 OS
.FileSys
.mkDir Config
.tmpDir
;
635 app (fn node
=> OS
.FileSys
.mkDir
636 (OS
.Path
.joinDirFile
{dir
= Config
.tmpDir
,
639 app (fn node
=> OS
.FileSys
.mkDir
640 (OS
.Path
.joinDirFile
{dir
= Config
.resultRoot
,
642 handle OS
.SysErr _
=> ())
645 fun handleSite (site
, files
) =
649 print ("New configuration for node " ^ site ^
"\n");
650 if site
= Config
.defaultNode
then
651 Slave
.handleChanges files
653 val bio
= OpenSSL
.connect (valOf (!ssl_context
),
656 ^
Int.toString Config
.slavePort
)
658 app (fn file
=> Msg
.send (bio
, MsgFile file
)) files
;
659 Msg
.send (bio
, MsgDoFiles
);
661 NONE
=> print
"Slave closed connection unexpectedly\n"
664 MsgOk
=> print ("Slave " ^ site ^
" finished\n")
665 | MsgError s
=> print ("Slave " ^ site
666 ^
" returned error: " ^
668 | _
=> print ("Slave " ^ site
669 ^
" returned unexpected command\n");
674 val () = Env
.registerPost (fn () =>
676 val prefixes
= List.concat
679 val pieces
= String.tokens (fn ch
=> ch
= #
".") dom
680 val path
= String.concatWith
"/" (rev pieces
)
683 Config
.resultRoot ^
"/" ^ node ^
"/" ^ path ^
"/")
687 val diffs
= findAllDiffs prefixes
689 val diffs
= map (fn (site
, dom
, dir
, Add
' {src
, dst
}) =>
690 (Slave
.shellF ([Config
.cp
, " ", src
, " ", dst
],
691 fn cl
=> "Copy failed: " ^ cl
);
697 |
(site
, dom
, dir
, Delete
' dst
) =>
698 (OS
.FileSys
.remove dst
699 handle OS
.SysErr _
=>
700 ErrorMsg
.error
NONE ("Delete failed for " ^ dst
);
702 {action
= Slave
.Delete
true,
706 |
(site
, dom
, dir
, Modify
' {src
, dst
}) =>
707 (Slave
.shellF ([Config
.cp
, " ", src
, " ", dst
],
708 fn cl
=> "Copy failed: " ^ cl
);
710 {action
= Slave
.Modify
,
715 if !ErrorMsg
.anyErrors
then
718 val changed
= foldl (fn ((site
, file
), changed
) =>
720 val ls
= case SM
.find (changed
, site
) of
724 SM
.insert (changed
, site
, file
:: ls
)
727 SM
.appi handleSite changed
729 ignore (Slave
.shellF ([Config
.rm
, " -rf ", Config
.tmpDir
, ""],
730 fn cl
=> "Temp file cleanup failed: " ^ cl
))
733 fun hasPriv priv
= Acl
.query
{user
= getUser (), class
= "priv", value
= "all"}
734 orelse Acl
.query
{user
= getUser (), class
= "priv", value
= priv
}
736 val _
= Env
.type_one
"dns_node"
739 List.exists (fn x
=> x
= node
) Config
.dnsNodes_all
740 orelse (hasPriv
"dns"
741 andalso List.exists (fn x
=> x
= node
) Config
.dnsNodes_admin
))
743 val _
= Env
.type_one
"mail_node"
746 List.exists (fn x
=> x
= node
) Config
.mailNodes_all
747 orelse (hasPriv
"mail"
748 andalso List.exists (fn x
=> x
= node
) Config
.mailNodes_admin
))
750 fun rmdom
' delete resultRoot doms
=
752 fun doNode (node
, _
) =
754 val dname
= OS
.Path
.joinDirFile
{dir
= resultRoot
,
757 fun doDom (dom
, actions
) =
759 val domPath
= String.concatWith
"/" (rev (String.fields (fn ch
=> ch
= #
".") dom
))
760 val dname
= OS
.Path
.concat (dname
, domPath
)
762 fun visitDom (dom
, dname
, actions
) =
764 val dir
= Posix
.FileSys
.opendir dname
767 case Posix
.FileSys
.readdir dir
of
771 val fnameFull
= OS
.Path
.joinDirFile
{dir
= dname
,
774 if Posix
.FileSys
.ST
.isDir (Posix
.FileSys
.stat fnameFull
) then
775 loop (visitDom (fname ^
"." ^ dom
,
779 loop ({action
= Slave
.Delete delete
,
782 file
= fnameFull
} :: actions
)
786 before Posix
.FileSys
.closedir dir
788 handle OS
.SysErr (s
, _
) =>
789 (print ("Warning: System error deleting domain " ^ dom ^
" on " ^ node ^
": " ^ s ^
"\n");
792 visitDom (dom
, dname
, actions
)
795 val actions
= foldl doDom
[] doms
797 handleSite (node
, actions
)
799 handle IO
.Io _
=> print ("Warning: IO error deleting domains on " ^ node ^
".\n")
801 fun cleanupNode (node
, _
) =
805 val domPath
= String.concatWith
"/" (rev (String.fields (fn ch
=> ch
= #
".") dom
))
806 val dname
= OS
.Path
.joinDirFile
{dir
= resultRoot
,
808 val dname
= OS
.Path
.concat (dname
, domPath
)
811 ignore (OS
.Process
.system (Config
.rm ^
" -rf " ^ dname
))
819 app doNode Config
.nodeIps
;
820 app cleanupNode Config
.nodeIps
823 val rmdom
= rmdom
' true Config
.resultRoot
824 val rmdom
' = rmdom
' false
826 fun homedirOf uname
=
827 Posix
.SysDB
.Passwd
.home (Posix
.SysDB
.getpwnam uname
)
829 fun homedir () = homedirOf (getUser ())
831 type subject
= {node
: string, domain
: string}
833 val describers
: (subject
-> string) list ref
= ref
[]
835 fun registerDescriber f
= describers
:= f
:: !describers
837 fun describeOne arg
= String.concat (map (fn f
=> f arg
) (rev (!describers
)))
839 val line
= "--------------------------------------------------------------\n"
840 val dline
= "==============================================================\n"
843 String.concat (List.mapPartial
845 case describeOne
{node
= node
, domain
= dom
} of
848 SOME (String.concat
[dline
, "Node ", node
, "\n", dline
, "\n", s
]))
851 datatype description
=
852 Filename
of { filename
: string, heading
: string, showEmpty
: bool }
853 | Extension
of { extension
: string, heading
: string -> string }
855 fun considerAll ds
{node
, domain
} =
857 val ds
= map (fn d
=> (d
, ref
[])) ds
859 val path
= Config
.resultRoot
860 val jdf
= OS
.Path
.joinDirFile
861 val path
= jdf
{dir
= path
, file
= node
}
862 val path
= foldr (fn (more
, path
) => jdf
{dir
= path
, file
= more
})
863 path (String.tokens (fn ch
=> ch
= #
".") domain
)
865 if Posix
.FileSys
.access (path
, []) then
867 val dir
= Posix
.FileSys
.opendir path
870 case Posix
.FileSys
.readdir dir
of
873 (app (fn (d
, entries
) =>
875 fun readFile showEmpty entries
' =
877 val fname
= OS
.Path
.joinDirFile
{dir
= path
,
880 val inf
= TextIO.openIn fname
882 fun loop (seenOne
, entries
') =
883 case TextIO.inputLine inf
of
884 NONE
=> if seenOne
orelse showEmpty
then
888 | SOME line
=> loop (true, line
:: entries
')
890 loop (false, entries
')
891 before TextIO.closeIn inf
895 Filename
{filename
, heading
, showEmpty
} =>
896 if fname
= filename
then
897 entries
:= readFile
showEmpty ("\n" :: line
:: ":\n" :: heading
:: line
:: !entries
)
900 | Extension
{extension
, heading
} =>
902 val {base
, ext
} = OS
.Path
.splitBaseExt fname
907 if extension
' = extension
then
908 entries
:= readFile
true ("\n" :: line
:: ":\n" :: heading base
:: line
:: !entries
)
916 Posix
.FileSys
.closedir dir
;
917 String.concat (List.concat (map (fn (_
, entries
) => rev (!entries
)) ds
))
923 val () = registerDescriber (considerAll
[Filename
{filename
= "soa",
927 val () = Env
.registerAction ("domainHost",
928 fn (env
, [(EString host
, _
)]) =>
929 SM
.insert (env
, "Hostname",
930 (EString (host ^
"." ^
currentDomain ()), dl
))
931 |
(_
, args
) => Env
.badArgs ("domainHost", args
))