add a parser for openntpd's ntpd.conf (committed upstream)
This commit is contained in:
parent
79d080b0b1
commit
79b3fa7d8c
@ -1,9 +1,9 @@
|
||||
# $OpenBSD: Makefile,v 1.11 2013/01/03 19:50:47 jasper Exp $
|
||||
# $OpenBSD: Makefile,v 1.12 2013/01/04 07:55:47 jasper Exp $
|
||||
|
||||
COMMENT= configuration editing tool and API
|
||||
|
||||
DISTNAME= augeas-1.0.0
|
||||
REVISION= 9
|
||||
REVISION= 10
|
||||
CATEGORIES= sysutils devel
|
||||
|
||||
SHARED_LIBS += augeas 0.0 # 16.0
|
||||
@ -37,10 +37,13 @@ CONFIGURE_ENV+= CPPFLAGS="-I${LOCALBASE}/include" \
|
||||
LDFLAGS="-L${LOCALBASE}/lib"
|
||||
|
||||
# https://fedorahosted.org/augeas/ticket/322
|
||||
# https://fedorahosted.org/augeas/ticket/324
|
||||
post-extract:
|
||||
cp ${FILESDIR}/bootconf.aug ${WRKSRC}/lenses/
|
||||
cp ${FILESDIR}/test_bootconf.aug ${WRKSRC}/lenses/tests/
|
||||
cp ${WRKSRC}/tests/lens-fonts.sh ${WRKSRC}/tests/test-bootconf.sh
|
||||
.for l in bootconf ntpd
|
||||
cp ${FILESDIR}/$l.aug ${WRKSRC}/lenses/
|
||||
cp ${FILESDIR}/test_$l.aug ${WRKSRC}/lenses/tests/
|
||||
cp ${WRKSRC}/tests/lens-fonts.sh ${WRKSRC}/tests/test-$l.sh
|
||||
.endfor
|
||||
|
||||
pre-configure:
|
||||
${SUBST_CMD} ${WRKSRC}/man/augparse.1
|
||||
|
157
sysutils/augeas/files/ntpd.aug
Normal file
157
sysutils/augeas/files/ntpd.aug
Normal file
@ -0,0 +1,157 @@
|
||||
(*
|
||||
Module: Ntpd
|
||||
Parses OpenNTPD's ntpd.conf
|
||||
|
||||
Author: Jasper Lievisse Adriaanse <jasper@jasper.la>
|
||||
|
||||
About: Reference
|
||||
This lens is used to parse OpenNTPD's configuration file, ntpd.conf.
|
||||
http://openntpd.org/
|
||||
|
||||
About: Usage Example
|
||||
To be documented
|
||||
|
||||
About: License
|
||||
This file is licensed under the LGPL v2+, like the rest of Augeas.
|
||||
|
||||
About: Configuration files
|
||||
This lens applies to /etc/ntpd.conf.
|
||||
See <filter>.
|
||||
*)
|
||||
|
||||
module Ntpd =
|
||||
autoload xfm
|
||||
|
||||
(************************************************************************
|
||||
* Group: Utility variables/functions
|
||||
************************************************************************)
|
||||
|
||||
(* View: comment *)
|
||||
let comment = Util.comment
|
||||
(* View: empty *)
|
||||
let empty = Util.empty
|
||||
(* View: eol *)
|
||||
let eol = Util.eol
|
||||
(* View: space *)
|
||||
let space = Sep.space
|
||||
(* View: word *)
|
||||
let word = Rx.word
|
||||
(* View: device_re *)
|
||||
let device_re = Rx.device_name | /\*/
|
||||
|
||||
(* View: address_re *)
|
||||
let address_re = Rx.ip | /\*/ | Rx.hostname
|
||||
|
||||
(* View: stratum_re
|
||||
value between 1 and 15 *)
|
||||
let stratum_re = /1[0-5]|[1-9]/
|
||||
|
||||
(* View: refid_re
|
||||
string with length < 5 *)
|
||||
let refid_re = /[A-Za-z0-9_.-]{1,5}/
|
||||
|
||||
(* View: weight_re
|
||||
value between 1 and 10 *)
|
||||
let weight_re = /10|[1-9]/
|
||||
|
||||
(* View: rtable_re
|
||||
0 - RT_TABLE_MAX *)
|
||||
let rtable_re = Rx.byte
|
||||
|
||||
(* View: correction_re
|
||||
should actually only match between -127000000 and 127000000 *)
|
||||
let correction_re = Rx.relinteger_noplus
|
||||
|
||||
(************************************************************************
|
||||
* View: key_opt_rtable_line
|
||||
* A subnode with a keyword, an optional routing table id and an end
|
||||
* of line.
|
||||
*
|
||||
* Parameters:
|
||||
* kw:regexp - the pattern to match as key
|
||||
* sto:lens - the storing lens
|
||||
************************************************************************)
|
||||
let key_opt_rtable_line (kw:regexp) (sto:lens) =
|
||||
let rtable = [ Util.del_str "rtable" . space . label "rtable"
|
||||
. store rtable_re ]
|
||||
in [ key kw . space . sto . (space . rtable)? . eol ]
|
||||
|
||||
(************************************************************************
|
||||
* View: key_opt_weight_rtable_line
|
||||
* A subnode with a keyword, an optional routing table id, an optional
|
||||
* weight-value and an end of line.
|
||||
* of line.
|
||||
*
|
||||
* Parameters:
|
||||
* kw:regexp - the pattern to match as key
|
||||
* sto:lens - the storing lens
|
||||
************************************************************************)
|
||||
let key_opt_weight_rtable_line (kw:regexp) (sto:lens) =
|
||||
let rtable = [ Util.del_str "rtable" . space . label "rtable" . store rtable_re ]
|
||||
in let weight = [ Util.del_str "weight" . space . label "weight"
|
||||
. store weight_re ]
|
||||
in [ key kw . space . sto . (space . weight)? . (space . rtable)? . eol ]
|
||||
|
||||
(************************************************************************
|
||||
* View: opt_value
|
||||
* A subnode for optional values.
|
||||
*
|
||||
* Parameters:
|
||||
* s:string - the option name and subtree label
|
||||
* r:regexp - the pattern to match as store
|
||||
************************************************************************)
|
||||
let opt_value (s:string) (r:regexp) =
|
||||
Build.key_value s space (store r)
|
||||
|
||||
(************************************************************************
|
||||
* Group: Keywords
|
||||
************************************************************************)
|
||||
|
||||
(* View: listen
|
||||
listen on address [rtable table-id] *)
|
||||
let listen =
|
||||
let addr = [ label "address" . store address_re ]
|
||||
in key_opt_rtable_line "listen on" addr
|
||||
|
||||
(* View: server
|
||||
server address [weight weight-value] [rtable table-id] *)
|
||||
let server =
|
||||
let addr = [ label "address" . store address_re ]
|
||||
in key_opt_weight_rtable_line "server" addr
|
||||
|
||||
(* View: servers
|
||||
servers address [weight weight-value] [rtable table-id] *)
|
||||
let servers =
|
||||
let addr = [ label "address" . store address_re ]
|
||||
in key_opt_weight_rtable_line "servers" addr
|
||||
|
||||
(* View: sensor
|
||||
sensor device [correction microseconds] [weight weight-value] [refid
|
||||
string] [stratum stratum-value] *)
|
||||
let sensor =
|
||||
let device = [ label "device" . store device_re ]
|
||||
in let correction = opt_value "correction" correction_re
|
||||
in let weight = opt_value "weight" weight_re
|
||||
in let refid = opt_value "refid" refid_re
|
||||
in let stratum = opt_value "stratum" stratum_re
|
||||
in [ key "sensor" . space . device
|
||||
. (space . correction)?
|
||||
. (space . weight)?
|
||||
. (space . refid)?
|
||||
. (space . stratum)?
|
||||
. eol ]
|
||||
|
||||
(************************************************************************
|
||||
* Group: Lens
|
||||
************************************************************************)
|
||||
|
||||
(* View: keyword *)
|
||||
let keyword = listen | server | servers | sensor
|
||||
|
||||
(* View: lns *)
|
||||
let lns = ( empty | comment | keyword )*
|
||||
|
||||
(* Variable: filter *)
|
||||
let filter = (incl "/etc/ntpd.conf")
|
||||
|
||||
let xfm = transform lns filter
|
80
sysutils/augeas/files/test_ntpd.aug
Normal file
80
sysutils/augeas/files/test_ntpd.aug
Normal file
@ -0,0 +1,80 @@
|
||||
(*
|
||||
Module: Test_Ntpd
|
||||
Provides unit tests for the <Ntpd> lens.
|
||||
*)
|
||||
|
||||
module Test_ntpd =
|
||||
|
||||
test Ntpd.listen get "listen on *\n" =
|
||||
{ "listen on"
|
||||
{ "address" = "*" } }
|
||||
|
||||
test Ntpd.listen get "listen on 127.0.0.1\n" =
|
||||
{ "listen on"
|
||||
{ "address" = "127.0.0.1" } }
|
||||
|
||||
test Ntpd.listen get "listen on ::1\n" =
|
||||
{ "listen on"
|
||||
{ "address" = "::1" } }
|
||||
|
||||
test Ntpd.listen get "listen on ::1 rtable 4\n" =
|
||||
{ "listen on"
|
||||
{ "address" = "::1" }
|
||||
{ "rtable" = "4" } }
|
||||
|
||||
test Ntpd.server get "server ntp.example.org\n" =
|
||||
{ "server"
|
||||
{ "address" = "ntp.example.org" } }
|
||||
|
||||
test Ntpd.server get "server ntp.example.org rtable 42\n" =
|
||||
{ "server"
|
||||
{ "address" = "ntp.example.org" }
|
||||
{ "rtable" = "42" } }
|
||||
|
||||
test Ntpd.server get "server ntp.example.org weight 1 rtable 42\n" =
|
||||
{ "server"
|
||||
{ "address" = "ntp.example.org" }
|
||||
{ "weight" = "1" }
|
||||
{ "rtable" = "42" } }
|
||||
|
||||
test Ntpd.server get "server ntp.example.org weight 10\n" =
|
||||
{ "server"
|
||||
{ "address" = "ntp.example.org" }
|
||||
{ "weight" = "10" } }
|
||||
|
||||
|
||||
test Ntpd.sensor get "sensor *\n" =
|
||||
{ "sensor"
|
||||
{ "device" = "*" } }
|
||||
|
||||
test Ntpd.sensor get "sensor nmea0\n" =
|
||||
{ "sensor"
|
||||
{ "device" = "nmea0" } }
|
||||
|
||||
test Ntpd.sensor get "sensor nmea0 correction 42\n" =
|
||||
{ "sensor"
|
||||
{ "device" = "nmea0" }
|
||||
{ "correction" = "42" } }
|
||||
|
||||
test Ntpd.sensor get "sensor nmea0 correction -42\n" =
|
||||
{ "sensor"
|
||||
{ "device" = "nmea0" }
|
||||
{ "correction" = "-42" } }
|
||||
|
||||
test Ntpd.sensor get "sensor nmea0 correction 42 weight 2\n" =
|
||||
{ "sensor"
|
||||
{ "device" = "nmea0" }
|
||||
{ "correction" = "42" }
|
||||
{ "weight" = "2" } }
|
||||
|
||||
test Ntpd.sensor get "sensor nmea0 correction 42 refid Puffy\n" =
|
||||
{ "sensor"
|
||||
{ "device" = "nmea0" }
|
||||
{ "correction" = "42" }
|
||||
{ "refid" = "Puffy" } }
|
||||
|
||||
test Ntpd.sensor get "sensor nmea0 correction 42 stratum 2\n" =
|
||||
{ "sensor"
|
||||
{ "device" = "nmea0" }
|
||||
{ "correction" = "42" }
|
||||
{ "stratum" = "2" } }
|
86
sysutils/augeas/patches/patch-lenses_rx_aug
Normal file
86
sysutils/augeas/patches/patch-lenses_rx_aug
Normal file
@ -0,0 +1,86 @@
|
||||
$OpenBSD: patch-lenses_rx_aug,v 1.1 2013/01/04 07:55:47 jasper Exp $
|
||||
|
||||
commit 41adae0ed1ddb805200fda754f933d286c710a7c
|
||||
Author: Jasper Lievisse Adriaanse <jasper@humppa.nl>
|
||||
Date: Thu Jan 3 21:09:48 2013 +0100
|
||||
|
||||
Some small Rx tweaks: include regexes for octal and hex and simplify ipv4 matching.
|
||||
|
||||
Fixes ticket #327
|
||||
|
||||
commit c7f74c4e43242876e391f936c3c3b27e7292c8aa
|
||||
Author: Jasper Lievisse Adriaanse <jasper@humppa.nl>
|
||||
Date: Thu Jan 3 09:37:49 2013 +0100
|
||||
|
||||
Add a lens for OpenNTPD's config file (ntpd.conf).
|
||||
|
||||
Extend rx.aug with some helpful regexes while here.
|
||||
Fixes ticket #324
|
||||
|
||||
--- lenses/rx.aug.orig Fri Jan 4 08:51:56 2013
|
||||
+++ lenses/rx.aug Fri Jan 4 08:51:58 2013
|
||||
@@ -50,10 +50,14 @@ let word = /[A-Za-z0-9_.-]+/
|
||||
One or more digits *)
|
||||
let integer = /[0-9]+/
|
||||
|
||||
-(* Variable: integer
|
||||
+(* Variable: relinteger
|
||||
A relative <integer> *)
|
||||
let relinteger = /[-+]?[0-9]+/
|
||||
|
||||
+(* Variable: relinteger_noplus
|
||||
+ A relative <integer>, without explicit plus sign *)
|
||||
+let relinteger_noplus = /[-]?[0-9]+/
|
||||
+
|
||||
(* Variable: decimal
|
||||
A decimal value (using ',' or '.' as a separator) *)
|
||||
let decimal = /[0-9]+([.,][0-9]+)?/
|
||||
@@ -62,6 +66,18 @@ let decimal = /[0-9]+([.,][0-9]+)?/
|
||||
A relative <decimal> *)
|
||||
let reldecimal = /[+-]?[0-9]+([.,][0-9]+)?/
|
||||
|
||||
+(* Variable: byte
|
||||
+ A byte (0 - 255) *)
|
||||
+let byte = /25[0-5]?|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9]/
|
||||
+
|
||||
+(* Variable: hex
|
||||
+ A hex value *)
|
||||
+let hex = /0x[0-9a-fA-F]+/
|
||||
+
|
||||
+(* Variable: octal
|
||||
+ An octal value *)
|
||||
+let octal = /0[0-7]+/
|
||||
+
|
||||
(* Variable: fspath
|
||||
A filesystem path *)
|
||||
let fspath = /[^ \t\n]+/
|
||||
@@ -71,7 +87,6 @@ let fspath = /[^ \t\n]+/
|
||||
Anything but a space, a comma or a comment sign *)
|
||||
let neg1 = /[^,# \n\t]+/
|
||||
|
||||
-
|
||||
(*
|
||||
* Group: IPs
|
||||
* Cf. http://blog.mes-stats.fr/2008/10/09/regex-ipv4-et-ipv6/ (in fr)
|
||||
@@ -80,8 +95,7 @@ let neg1 = /[^,# \n\t]+/
|
||||
(* Variable: ipv4 *)
|
||||
let ipv4 =
|
||||
let dot = "." in
|
||||
- let digits = /(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/ in
|
||||
- digits . dot . digits . dot . digits . dot . digits
|
||||
+ byte . dot . byte . dot . byte . dot . byte
|
||||
|
||||
(* Variable: ipv6 *)
|
||||
let ipv6 =
|
||||
@@ -114,6 +128,11 @@ let ipv6 =
|
||||
An <ipv4> or <ipv6> *)
|
||||
let ip = ipv4 | ipv6
|
||||
|
||||
+
|
||||
+(* Variable: hostname
|
||||
+ A valid RFC 1123 hostname *)
|
||||
+let hostname = /(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*(
|
||||
+ [A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])/
|
||||
|
||||
(*
|
||||
* Variable: device_name
|
@ -1,4 +1,4 @@
|
||||
@comment $OpenBSD: PLIST,v 1.2 2013/01/02 20:28:08 jasper Exp $
|
||||
@comment $OpenBSD: PLIST,v 1.3 2013/01/04 07:55:47 jasper Exp $
|
||||
%%SHARED%%
|
||||
@bin bin/augparse
|
||||
@bin bin/augtool
|
||||
@ -108,6 +108,7 @@ share/augeas/lenses/dist/nginx.aug
|
||||
share/augeas/lenses/dist/nrpe.aug
|
||||
share/augeas/lenses/dist/nsswitch.aug
|
||||
share/augeas/lenses/dist/ntp.aug
|
||||
share/augeas/lenses/dist/ntpd.aug
|
||||
share/augeas/lenses/dist/odbc.aug
|
||||
share/augeas/lenses/dist/openvpn.aug
|
||||
share/augeas/lenses/dist/pam.aug
|
||||
@ -257,6 +258,7 @@ share/augeas/lenses/dist/tests/test_nginx.aug
|
||||
share/augeas/lenses/dist/tests/test_nrpe.aug
|
||||
share/augeas/lenses/dist/tests/test_nsswitch.aug
|
||||
share/augeas/lenses/dist/tests/test_ntp.aug
|
||||
share/augeas/lenses/dist/tests/test_ntpd.aug
|
||||
share/augeas/lenses/dist/tests/test_odbc.aug
|
||||
share/augeas/lenses/dist/tests/test_openvpn.aug
|
||||
share/augeas/lenses/dist/tests/test_pam.aug
|
||||
|
Loading…
x
Reference in New Issue
Block a user