3 Parses OpenNTPD's ntpd.conf
5 Author: Jasper Lievisse Adriaanse <jasper@jasper.la>
8 This lens is used to parse OpenNTPD's configuration file, ntpd.conf.
15 This file is licensed under the LGPL v2+, like the rest of Augeas.
17 About: Configuration files
18 This lens applies to /etc/ntpd.conf.
25 (************************************************************************
26 * Group: Utility variables/functions
27 ************************************************************************)
30 let comment = Util.comment
32 let empty = Util.empty
40 let device_re = Rx.device_name | /\*/
42 (* View: address_re *)
43 let address_re = Rx.ip | /\*/ | Rx.hostname
46 value between 1 and 15 *)
47 let stratum_re = /1[0-5]|[1-9]/
50 string with length < 5 *)
51 let refid_re = /[A-Za-z0-9_.-]{1,5}/
54 value between 1 and 10 *)
55 let weight_re = /10|[1-9]/
59 let rtable_re = Rx.byte
61 (* View: correction_re
62 should actually only match between -127000000 and 127000000 *)
63 let correction_re = Rx.relinteger_noplus
65 (************************************************************************
66 * View: key_opt_rtable_line
67 * A subnode with a keyword, an optional routing table id and an end
71 * kw:regexp - the pattern to match as key
72 * sto:lens - the storing lens
73 ************************************************************************)
74 let key_opt_rtable_line (kw:regexp) (sto:lens) =
75 let rtable = [ Util.del_str "rtable" . space . label "rtable"
77 in [ key kw . space . sto . (space . rtable)? . eol ]
79 (************************************************************************
80 * View: key_opt_weight_rtable_line
81 * A subnode with a keyword, an optional routing table id, an optional
82 * weight-value and an end of line.
86 * kw:regexp - the pattern to match as key
87 * sto:lens - the storing lens
88 ************************************************************************)
89 let key_opt_weight_rtable_line (kw:regexp) (sto:lens) =
90 let rtable = [ Util.del_str "rtable" . space . label "rtable" . store rtable_re ]
91 in let weight = [ Util.del_str "weight" . space . label "weight"
93 in [ key kw . space . sto . (space . weight)? . (space . rtable)? . eol ]
95 (************************************************************************
97 * A subnode for optional values.
100 * s:string - the option name and subtree label
101 * r:regexp - the pattern to match as store
102 ************************************************************************)
103 let opt_value (s:string) (r:regexp) =
104 Build.key_value s space (store r)
106 (************************************************************************
108 ************************************************************************)
111 listen on address [rtable table-id] *)
113 let addr = [ label "address" . store address_re ]
114 in key_opt_rtable_line "listen on" addr
117 server address [weight weight-value] [rtable table-id] *)
119 let addr = [ label "address" . store address_re ]
120 in key_opt_weight_rtable_line "server" addr
123 servers address [weight weight-value] [rtable table-id] *)
125 let addr = [ label "address" . store address_re ]
126 in key_opt_weight_rtable_line "servers" addr
129 sensor device [correction microseconds] [weight weight-value] [refid
130 string] [stratum stratum-value] *)
132 let device = [ label "device" . store device_re ]
133 in let correction = opt_value "correction" correction_re
134 in let weight = opt_value "weight" weight_re
135 in let refid = opt_value "refid" refid_re
136 in let stratum = opt_value "stratum" stratum_re
137 in [ key "sensor" . space . device
138 . (space . correction)?
144 (************************************************************************
146 ************************************************************************)
149 let keyword = listen | server | servers | sensor
152 let lns = ( empty | comment | keyword )*
155 let filter = (incl "/etc/ntpd.conf")
157 let xfm = transform lns filter