diff --git a/lenses/getcap.aug b/lenses/getcap.aug new file mode 100644 index 000000000..bd002de4a --- /dev/null +++ b/lenses/getcap.aug @@ -0,0 +1,48 @@ +(* +Module: Getcap + Parses termcap-style capability databases + +Author: Matt Dainty + +About: Reference + - man 3 getcap + - man 5 login.conf + - man 5 printcap + - man 5 rtadvd.conf + - man 5 termcap + +Each line represents a record consisting of a number of ':'-separated fields +the first of which is the name or identifier for the record. Records can be +split across multiple lines with '\'. + +*) + +module Getcap = + autoload xfm + + let eol = Util.eol + + let comment = Util.comment + let empty = Util.empty + + (* field must not contain ':' unless quoted or '\'-escaped *) + let field = /([^:\n]|\\\\:)+|[^:\n]*(\"[^\n]+\"[^:\n]*)+/ + + let sep = del /:|:[ \t]*\\\\\n[ \t]*:/ ":" + let name = store field . sep + let capability = [ label "capability" . store field . sep ] + let record = [ seq "record" . name . capability+ . eol ] + + let lns = ( empty | comment | record )* + + let filter = incl "/etc/login.conf" + . incl "/etc/printcap" + . incl "/etc/rtadvd.conf" + . incl "/usr/share/misc/termcap" + . Util.stdexcl + + let xfm = transform lns filter + +(* Local Variables: *) +(* mode: caml *) +(* End: *) diff --git a/lenses/tests/test_getcap.aug b/lenses/tests/test_getcap.aug new file mode 100644 index 000000000..bda17305d --- /dev/null +++ b/lenses/tests/test_getcap.aug @@ -0,0 +1,288 @@ +module Test_getcap = + + (* Example from getcap(3) *) + let getcap = "example|an example of binding multiple values to names:\ + :foo%bar:foo^blah:foo@:\ + :abc%xyz:abc^frap:abc$@:\ + :tc=more: +" + (* Taken from the standard /etc/login.conf *) + let login_conf = "# Default allowed authentication styles +auth-defaults:auth=passwd,skey: + +# Default allowed authentication styles for authentication type ftp +auth-ftp-defaults:auth-ftp=passwd: + +# +# The default values +# To alter the default authentication types change the line: +# :tc=auth-defaults:\ +# to be read something like: (enables passwd, \"myauth\", and activ) +# :auth=passwd,myauth,activ:\ +# Any value changed in the daemon class should be reset in default +# class. +# +default:\ + :path=/usr/bin /bin /usr/sbin /sbin /usr/X11R6/bin /usr/local/bin /usr/local/sbin:\ + :umask=022:\ + :datasize-max=512M:\ + :datasize-cur=512M:\ + :maxproc-max=256:\ + :maxproc-cur=128:\ + :openfiles-cur=512:\ + :stacksize-cur=4M:\ + :localcipher=blowfish,8:\ + :ypcipher=old:\ + :tc=auth-defaults:\ + :tc=auth-ftp-defaults: +" + + (* Example from rtadvd.conf(5) *) + let rtadvd_conf = "default:\ + :chlim#64:raflags#0:rltime#1800:rtime#0:retrans#0:\ + :pinfoflags=\"la\":vltime#2592000:pltime#604800:mtu#0: +ef0:\ + :addr=\"2001:db8:ffff:1000::\":prefixlen#64:tc=default: +" + + (* Sample /etc/printcap *) + let printcap = "# $OpenBSD: printcap,v 1.1 2014/07/12 03:52:39 deraadt Exp $ + +lp|local line printer:\ + :lp=/dev/lp:sd=/var/spool/output:lf=/var/log/lpd-errs: + +rp|remote line printer:\ + :lp=:rm=printhost:rp=lp:sd=/var/spool/output:lf=/var/log/lpd-errs: +" + + (* Sample termcap entry with escaped ':''s *) + let termcap = "vt420pc|DEC VT420 w/PC keyboard:\ + :@7=\E[4~:F1=\E[23~:F2=\E[24~:F3=\E[11;2~:F4=\E[12;2~:\ + :F5=\E[13;2~:F6=\E[14;2~:F7=\E[15;2~:F8=\E[17;2~:\ + :F9=\E[18;2~:FA=\E[19;2~:FB=\E[20;2~:FC=\E[21;2~:\ + :FD=\E[23;2~:FE=\E[24;2~:FF=\E[23~:FG=\E[24~:FH=\E[25~:\ + :FI=\E[26~:FJ=\E[28~:FK=\E[29~:FL=\E[31~:FM=\E[32~:\ + :FN=\E[33~:FO=\E[34~:FP=\E[35~:FQ=\E[36~:FR=\E[23;2~:\ + :FS=\E[24;2~:FT=\E[25;2~:FU=\E[26;2~:FV=\E[28;2~:\ + :FW=\E[29;2~:FX=\E[31;2~:FY=\E[32;2~:FZ=\E[33;2~:\ + :Fa=\E[34;2~:Fb=\E[35;2~:Fc=\E[36;2~:\ + :S6=USR_TERM\:vt420pcdos\::k1=\E[11~:k2=\E[12~:\ + :k3=\E[13~:k4=\E[14~:k5=\E[15~:k6=\E[17~:k7=\E[18~:\ + :k8=\E[19~:k9=\E[20~:k;=\E[21~:kD=\177:kh=\E[H:\ + :..px=\EP1;1|%?%{16}%p1%>%t%{0}%e%{21}%p1%>%t%{1}%e%{25}%p1%>%t%{2}%e%{27}%p1%>%t%{3}%e%{30}%p1%>%t%{4}%e%{5}%;%p1%+%d/%p2%s\E\\:\ + :tc=vt420: +" + +test Getcap.lns get getcap = + { "1" = "example|an example of binding multiple values to names" + { "capability" = "foo%bar" } + { "capability" = "foo^blah" } + { "capability" = "foo@" } + { "capability" = "abc%xyz" } + { "capability" = "abc^frap" } + { "capability" = "abc$@" } + { "capability" = "tc=more" } + } + +test Getcap.lns get login_conf = + { "#comment" = "Default allowed authentication styles" } + { "1" = "auth-defaults" + { "capability" = "auth=passwd,skey" } + } + { } + { "#comment" = "Default allowed authentication styles for authentication type ftp" } + { "2" = "auth-ftp-defaults" + { "capability" = "auth-ftp=passwd" } + } + { } + { } + { "#comment" = "The default values" } + { "#comment" = "To alter the default authentication types change the line:" } + { "#comment" = ":tc=auth-defaults:\\" } + { "#comment" = "to be read something like: (enables passwd, \"myauth\", and activ)" } + { "#comment" = ":auth=passwd,myauth,activ:\\" } + { "#comment" = "Any value changed in the daemon class should be reset in default" } + { "#comment" = "class." } + { } + { "3" = "default" + { "capability" = "path=/usr/bin /bin /usr/sbin /sbin /usr/X11R6/bin /usr/local/bin /usr/local/sbin" } + { "capability" = "umask=022" } + { "capability" = "datasize-max=512M" } + { "capability" = "datasize-cur=512M" } + { "capability" = "maxproc-max=256" } + { "capability" = "maxproc-cur=128" } + { "capability" = "openfiles-cur=512" } + { "capability" = "stacksize-cur=4M" } + { "capability" = "localcipher=blowfish,8" } + { "capability" = "ypcipher=old" } + { "capability" = "tc=auth-defaults" } + { "capability" = "tc=auth-ftp-defaults" } + } + +test Getcap.lns get rtadvd_conf = + { "1" = "default" + { "capability" = "chlim#64" } + { "capability" = "raflags#0" } + { "capability" = "rltime#1800" } + { "capability" = "rtime#0" } + { "capability" = "retrans#0" } + { "capability" = "pinfoflags=\"la\"" } + { "capability" = "vltime#2592000" } + { "capability" = "pltime#604800" } + { "capability" = "mtu#0" } + } + { "2" = "ef0" + { "capability" = "addr=\"2001:db8:ffff:1000::\"" } + { "capability" = "prefixlen#64" } + { "capability" = "tc=default" } + } + +test Getcap.lns get printcap = + { "#comment" = "$OpenBSD: printcap,v 1.1 2014/07/12 03:52:39 deraadt Exp $" } + { } + { "1" = "lp|local line printer" + { "capability" = "lp=/dev/lp" } + { "capability" = "sd=/var/spool/output" } + { "capability" = "lf=/var/log/lpd-errs" } + } + { } + { "2" = "rp|remote line printer" + { "capability" = "lp=" } + { "capability" = "rm=printhost" } + { "capability" = "rp=lp" } + { "capability" = "sd=/var/spool/output" } + { "capability" = "lf=/var/log/lpd-errs" } + } + +test Getcap.lns get termcap = + { "#comment" = "The entries for stv52 and stv52pc probably need a revision." } + { "1" = "stv52|MiNT virtual console" + { "capability" = "am" } + { "capability" = "ms" } + { "capability" = "co#80" } + { "capability" = "it#8" } + { "capability" = "li#30" } + { "capability" = "%1=\EH" } + { "capability" = "&8=\EK" } + { "capability" = "F1=\Ep" } + { "capability" = "F2=\Eq" } + { "capability" = "F3=\Er" } + { "capability" = "F4=\Es" } + { "capability" = "F5=\Et" } + { "capability" = "F6=\Eu" } + { "capability" = "F7=\Ev" } + { "capability" = "F8=\Ew" } + { "capability" = "F9=\Ex" } + { "capability" = "FA=\Ey" } + { "capability" = "al=\EL" } + { "capability" = "bl=^G" } + { "capability" = "cd=\EJ" } + { "capability" = "ce=\EK" } + { "capability" = "cl=\EE" } + { "capability" = "cm=\EY%+ %+ " } + { "capability" = "cr=^M" } + { "capability" = "dl=\EM" } + { "capability" = "do=\EB" } + { "capability" = "ho=\EH" } + { "capability" = "k1=\EP" } + { "capability" = "k2=\EQ" } + { "capability" = "k3=\ER" } + { "capability" = "k4=\ES" } + { "capability" = "k5=\ET" } + { "capability" = "k6=\EU" } + { "capability" = "k7=\EV" } + { "capability" = "k8=\EW" } + { "capability" = "k9=\EX" } + { "capability" = "k;=\EY" } + { "capability" = "kD=\177" } + { "capability" = "kI=\EI" } + { "capability" = "kN=\Eb" } + { "capability" = "kP=\Ea" } + { "capability" = "kb=^H" } + { "capability" = "kd=\EB" } + { "capability" = "kh=\EE" } + { "capability" = "kl=\ED" } + { "capability" = "kr=\EC" } + { "capability" = "ku=\EA" } + { "capability" = "le=^H" } + { "capability" = "mb=\Er" } + { "capability" = "md=\EyA" } + { "capability" = "me=\Ez_" } + { "capability" = "mh=\Em" } + { "capability" = "mr=\Ep" } + { "capability" = "nd=\EC" } + { "capability" = "nw=2*\\r\\n" } + { "capability" = "op=\Eb@\EcO" } + { "capability" = "r1=\Ez_\Eb@\EcA" } + { "capability" = "se=\Eq" } + { "capability" = "sf=2*\\n" } + { "capability" = "so=\Ep" } + { "capability" = "sr=2*\EI" } + { "capability" = "ta=^I" } + { "capability" = "te=\Ev\E. \Ee\Ez_" } + { "capability" = "ti=\Ev\Ee\Ez_" } + { "capability" = "ue=\EzH" } + { "capability" = "up=\EA" } + { "capability" = "us=\EyH" } + { "capability" = "ve=\E. \Ee" } + { "capability" = "vi=\Ef" } + { "capability" = "vs=\E.\"" } + } + +test Getcap.lns get termcap = + { "1" = "vt420pc|DEC VT420 w/PC keyboard" + { "capability" = "@7=\E[4~" } + { "capability" = "F1=\E[23~" } + { "capability" = "F2=\E[24~" } + { "capability" = "F3=\E[11;2~" } + { "capability" = "F4=\E[12;2~" } + { "capability" = "F5=\E[13;2~" } + { "capability" = "F6=\E[14;2~" } + { "capability" = "F7=\E[15;2~" } + { "capability" = "F8=\E[17;2~" } + { "capability" = "F9=\E[18;2~" } + { "capability" = "FA=\E[19;2~" } + { "capability" = "FB=\E[20;2~" } + { "capability" = "FC=\E[21;2~" } + { "capability" = "FD=\E[23;2~" } + { "capability" = "FE=\E[24;2~" } + { "capability" = "FF=\E[23~" } + { "capability" = "FG=\E[24~" } + { "capability" = "FH=\E[25~" } + { "capability" = "FI=\E[26~" } + { "capability" = "FJ=\E[28~" } + { "capability" = "FK=\E[29~" } + { "capability" = "FL=\E[31~" } + { "capability" = "FM=\E[32~" } + { "capability" = "FN=\E[33~" } + { "capability" = "FO=\E[34~" } + { "capability" = "FP=\E[35~" } + { "capability" = "FQ=\E[36~" } + { "capability" = "FR=\E[23;2~" } + { "capability" = "FS=\E[24;2~" } + { "capability" = "FT=\E[25;2~" } + { "capability" = "FU=\E[26;2~" } + { "capability" = "FV=\E[28;2~" } + { "capability" = "FW=\E[29;2~" } + { "capability" = "FX=\E[31;2~" } + { "capability" = "FY=\E[32;2~" } + { "capability" = "FZ=\E[33;2~" } + { "capability" = "Fa=\E[34;2~" } + { "capability" = "Fb=\E[35;2~" } + { "capability" = "Fc=\E[36;2~" } + { "capability" = "S6=USR_TERM\\:vt420pcdos\\:" } + { "capability" = "k1=\E[11~" } + { "capability" = "k2=\E[12~" } + { "capability" = "k3=\E[13~" } + { "capability" = "k4=\E[14~" } + { "capability" = "k5=\E[15~" } + { "capability" = "k6=\E[17~" } + { "capability" = "k7=\E[18~" } + { "capability" = "k8=\E[19~" } + { "capability" = "k9=\E[20~" } + { "capability" = "k;=\E[21~" } + { "capability" = "kD=\177" } + { "capability" = "kh=\E[H" } + { "capability" = "..px=\EP1;1|%?%{16}%p1%>%t%{0}%e%{21}%p1%>%t%{1}%e%{25}%p1%>%t%{2}%e%{27}%p1%>%t%{3}%e%{30}%p1%>%t%{4}%e%{5}%;%p1%+%d/%p2%s\E\" } + { "capability" = "tc=vt420" } + } diff --git a/tests/Makefile.am b/tests/Makefile.am index da8173883..163224f4d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -71,6 +71,7 @@ lens_tests = \ lens-fstab.sh \ lens-fuse.sh \ lens-gdm.sh \ + lens-getcap.sh \ lens-group.sh \ lens-gshadow.sh \ lens-gtkbookmarks.sh \