Hi Raphaël, Thanks for your quick feedback.
Here is a reworked version with documentation and some improvements (removal of used variables, better naming...) Tell me if there are others things to improve. Fred Le mardi 11 janvier 2011 à 17:41 +0100, Raphaël Pinson a écrit : > Hi Frédéric, > > > That looks good. Can you document the module a bit, according to > http://augeas.net/page/Documenting_your_modules ? > > > Raphaël > > > 2011/1/11 Frédéric Lespez <[email protected]>: > > Hi, > > > > Here is a new lens to parse /etc/crypttab (the configuration file > > associated to the cryptsetup package). This lens is based on the fstab > > one. > > > > Do not hesitate to send me comments. I hope it can be useful to others. > > > > Regards, > > Fred > > > > _______________________________________________ > > augeas-devel mailing list > > [email protected] > > https://www.redhat.com/mailman/listinfo/augeas-devel > > >
From 9d145ac9807d260273c5fa5cfe5ad7393bfb9a1f Mon Sep 17 00:00:00 2001 From: Fred <[email protected]> Date: Tue, 11 Jan 2011 21:44:17 +0100 Subject: [PATCH] A new lense for /etc/crypttab --- lenses/crypttab.aug | 107 ++++++++++++++++++++++++++++++++++++++++ lenses/tests/test_crypttab.aug | 52 +++++++++++++++++++ 2 files changed, 159 insertions(+), 0 deletions(-) create mode 100644 lenses/crypttab.aug create mode 100644 lenses/tests/test_crypttab.aug diff --git a/lenses/crypttab.aug b/lenses/crypttab.aug new file mode 100644 index 0000000..20129a2 --- /dev/null +++ b/lenses/crypttab.aug @@ -0,0 +1,107 @@ +(* +Module: Crypttab + Parses /etc/crypttab from the cryptsetup package. + +Author: Frédéric Lespez <[email protected]> + +About: Reference + This lens tries to keep as close as possible to `man crypttab` where possible. + +About: License + This file is licensed under the GPL. + +About: Lens Usage + Sample usage of this lens in augtool + + * Create a new entry for an encrypted block devices + > ins 01 after /files/etc/crypttab/*[last()] + > set /files/etc/crypttab/01/target crypt_sda2 + > set /files/etc/crypttab/01/device /dev/sda2 + > set /files/etc/crypttab/01/password /dev/random + > set /files/etc/crypttab/01/opt swap + * Print the entry applying to the "/dev/sda2" device + > print /files/etc/crypttab/01 + * Remove the entry applying to the "/dev/sda2" device + > rm /files/etc/crypttab/*[device="/dev/sda2"] + +About: Configuration files + This lens applies to /etc/crypttab. See <filter>. +*) + +module Crypttab = + autoload xfm + + (************************************************************************ + * Group: USEFUL PRIMITIVES + *************************************************************************) + + (* Group: Separators *) + + (* Variable: sep_tab *) + let sep_tab = Sep.tab + + (* Variable: comma *) + let comma = Sep.comma + + (* Group: Generic primitives *) + + (* Variable: eol *) + let eol = Util.eol + + (* Variable: comment *) + let comment = Util.comment + + (* Variable: empty *) + let empty = Util.empty + + (* Variable: word *) + let word = Rx.word + + (* Variable: optval *) + let optval = /[A-Za-z0-9_.:-]+/ + + (* Variable: target *) + let target = Rx.device_name + + (* Variable: fspath *) + let fspath = Rx.fspath + + (************************************************************************ + * Group: ENTRIES + *************************************************************************) + + (************************************************************************ + * View: comma_sep_list + * A comma separated list of options (opt=value or opt) + *************************************************************************) + let comma_sep_list (l:string) = + let value = [ label "value" . Util.del_str "=" . store optval ] in + let lns = [ label l . store word . value? ] in + Build.opt_list lns comma + + (************************************************************************ + * View: record + * A crypttab record + *************************************************************************) + + let record = [ seq "entry" . + [ label "target" . store target ] . sep_tab . + [ label "device" . store fspath ] . + (sep_tab . [ label "password" . store fspath ] . + ( sep_tab . comma_sep_list "opt")? )? + . eol ] + + (* + * View: lns + * The crypttab lens + *) + let lns = ( empty | comment | record ) * + + (* Variable: filter *) + let filter = (incl "/etc/crypttab") + + let xfm = transform lns filter + +(* Local Variables: *) +(* mode: caml *) +(* End: *) diff --git a/lenses/tests/test_crypttab.aug b/lenses/tests/test_crypttab.aug new file mode 100644 index 0000000..5845241 --- /dev/null +++ b/lenses/tests/test_crypttab.aug @@ -0,0 +1,52 @@ +module Test_crypttab = + + let simple = "sda1_crypt\t /dev/sda1\t /dev/random \t swap\n" + + let simple_tree = + { "1" + { "target" = "sda1_crypt" } + { "device" = "/dev/sda1" } + { "password" = "/dev/random" } + { "opt" = "swap" } } + + let trailing_ws = "sda1_crypt\t /dev/sda1\t /dev/random \t swap\t\n" + + let no_opts = "sda1_crypt\t /dev/sda1\t /etc/key\n" + + let no_opts_tree = + { "1" + { "target" = "sda1_crypt" } + { "device" = "/dev/sda1" } + { "password" = "/etc/key" } } + + let no_password = "sda1_crypt\t /dev/sda1\n" + + let no_password_tree = + { "1" + { "target" = "sda1_crypt" } + { "device" = "/dev/sda1" } } + + let multi_opts = "sda1_crypt\t /dev/sda1\t /etc/key \t cipher=aes-cbc-essiv:sha256,verify\n" + + let multi_opts_tree = + { "1" + { "target" = "sda1_crypt" } + { "device" = "/dev/sda1" } + { "password" = "/etc/key" } + { "opt" = "cipher" + { "value" = "aes-cbc-essiv:sha256" } } + { "opt" = "verify" } } + + test Crypttab.lns get simple = simple_tree + + test Crypttab.lns get trailing_ws = simple_tree + + test Crypttab.lns get no_opts = no_opts_tree + + test Crypttab.lns get no_password = no_password_tree + + test Crypttab.lns get multi_opts = multi_opts_tree + +(* Local Variables: *) +(* mode: caml *) +(* End: *) -- 1.7.1
_______________________________________________ augeas-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/augeas-devel
