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
From 675255ec00f5739a9b41b988bba6daccfc261e23 Mon Sep 17 00:00:00 2001 From: Fred <[email protected]> Date: Tue, 11 Jan 2011 16:55:52 +0100 Subject: [PATCH] New lens for /etc/crypttab file --- lenses/crypttab.aug | 39 ++++++++++++++++++++++++++++++ lenses/tests/test_crypttab.aug | 52 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 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..e835c53 --- /dev/null +++ b/lenses/crypttab.aug @@ -0,0 +1,39 @@ +(* Parsing /etc/crypttab *) + +module Crypttab = + autoload xfm + + let sep_tab = Sep.tab + let sep_spc = Sep.space + let comma = Sep.comma + let eol = Util.eol + + let comment = Util.comment + let empty = Util.empty + + let word = Rx.word + let optval = /[A-Za-z0-9_.:-]+/ + let device = Rx.device_name + let fspath = Rx.fspath + let spec = /[^,# \n\t][^ \n\t]*/ + + 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 + + let record = [ seq "entry" . + [ label "target" . store device ] . sep_tab . + [ label "device" . store fspath ] . + (sep_tab . [ label "password" . store spec ] . + ( sep_tab . comma_sep_list "opt")? )? + . eol ] + + let lns = ( empty | comment | record ) * + 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
