Imported Upstream version 1.4.0
[platform/upstream/augeas.git] / lenses / crypttab.aug
1 (*
2 Module: Crypttab
3   Parses /etc/crypttab from the cryptsetup package.
4
5 Author: Frédéric Lespez <frederic.lespez@free.fr>
6
7 About: Reference
8   This lens tries to keep as close as possible to `man crypttab` where possible.
9
10 About: License
11   This file is licensed under the LGPL v2+, like the rest of Augeas.
12
13 About: Lens Usage
14   Sample usage of this lens in augtool
15
16     * Create a new entry for an encrypted block devices
17       > ins 01 after /files/etc/crypttab/*[last()]
18       > set /files/etc/crypttab/01/target crypt_sda2
19       > set /files/etc/crypttab/01/device /dev/sda2
20       > set /files/etc/crypttab/01/password /dev/random
21       > set /files/etc/crypttab/01/opt swap
22     * Print the entry applying to the "/dev/sda2" device
23       > print /files/etc/crypttab/01
24     * Remove the entry applying to the "/dev/sda2" device
25       > rm /files/etc/crypttab/*[device="/dev/sda2"]
26
27 About: Configuration files
28   This lens applies to /etc/crypttab. See <filter>.
29 *)
30
31 module Crypttab =
32   autoload xfm
33
34   (************************************************************************
35    * Group:                 USEFUL PRIMITIVES
36    *************************************************************************)
37
38   (* Group: Separators *)
39
40   (* Variable: sep_tab *)
41   let sep_tab = Sep.tab
42
43   (* Variable: comma *)
44   let comma   = Sep.comma
45
46   (* Group: Generic primitives *)
47
48   (* Variable: eol *)
49   let eol     = Util.eol
50
51   (* Variable: comment *)
52   let comment = Util.comment
53
54   (* Variable: empty *)
55   let empty   = Util.empty
56
57   (* Variable: word *)
58   let word    = Rx.word
59
60    (* Variable: optval *)
61   let optval  = /[A-Za-z0-9_.:-]+/
62
63   (* Variable: target *)
64   let target  = Rx.device_name
65
66   (* Variable: fspath *)
67   let fspath  = Rx.fspath
68
69   (************************************************************************
70    * Group:                       ENTRIES
71    *************************************************************************)
72
73   (************************************************************************
74    * View: comma_sep_list
75    *   A comma separated list of options (opt=value or opt)
76    *************************************************************************)
77   let comma_sep_list (l:string) =
78     let value = [ label "value" . Util.del_str "=" . store optval ] in
79       let lns = [ label l . store word . value? ] in
80          Build.opt_list lns comma
81
82   (************************************************************************
83    * View: record
84    *   A crypttab record
85    *************************************************************************)
86
87   let record = [ seq "entry" .
88                    [ label "target" . store target ] . sep_tab .
89                    [ label "device" . store fspath ] .
90                    (sep_tab . [ label "password" . store fspath ] .
91                     ( sep_tab . comma_sep_list "opt")? )?
92                  . eol ]
93
94   (*
95    * View: lns
96    *   The crypttab lens
97    *)
98   let lns = ( empty | comment | record ) *
99
100   (* Variable: filter *)
101   let filter = (incl "/etc/crypttab")
102
103   let xfm = transform lns filter
104
105 (* coding: utf-8 *)