Imported Upstream version 1.7.0
[platform/upstream/augeas.git] / lenses / nsswitch.aug
1 (*
2 Module: Nsswitch
3   Parses /etc/nsswitch.conf
4
5 Author: Raphael Pinson <raphink@gmail.com>
6
7 About: Reference
8   This lens tries to keep as close as possible to `man nsswitch.conf` where possible.
9
10 About: Licence
11   This file is licensed under the LGPL v2+, like the rest of Augeas.
12
13 About: Lens Usage
14
15 About: Configuration files
16   This lens applies to /etc/nsswitch.conf. See <filter>.
17 *)
18
19 module Nsswitch =
20 autoload xfm
21
22 (************************************************************************
23  * Group:                 USEFUL PRIMITIVES
24  *************************************************************************)
25
26 (* View: comment *)
27 let comment = Util.comment
28
29 (* View: empty *)
30 let empty = Util.empty
31
32 (* View: sep_colon
33     The separator for database entries *)
34 let sep_colon = del /:[ \t]*/ ": "
35
36 (* View: database_kw
37     The database specification like `passwd', `shadow', or `hosts' *)
38 let database_kw = Rx.word
39
40 (* View: service
41     The service specification like `files', `db', or `nis' *)
42 let service = [ label "service" . store Rx.word ]
43
44 (* View: reaction
45     The reaction on lookup result like `[NOTFOUND=return]'
46     TODO: Use case-insensitive regexps when ticket #147 is fixed.
47 *)
48 let reaction =
49   let status_kw = /[Ss][Uu][Cc][Cc][Ee][Ss][Ss]/
50                 | /[Nn][Oo][Tt][Ff][Oo][Uu][Nn][Dd]/
51                 | /[Uu][Nn][Aa][Vv][Aa][Ii][Ll]/
52                 | /[Tt][Rr][Yy][Aa][Gg][Aa][Ii][Nn]/
53     in let action_kw = /[Rr][Ee][Tt][Uu][Rr][Nn]/
54                      | /[Cc][Oo][Nn][Tt][Ii][Nn][Uu][Ee]/
55       in let negate = [ Util.del_str "!" . label "negate" ]
56         in let reaction_entry = [ label "status" . negate?
57                                 . store status_kw
58                                 . Util.del_str "="
59                                 . [ label "action" . store action_kw ] ]
60           in Util.del_str "["
61              . [ label "reaction"
62                . (Build.opt_list reaction_entry Sep.space) ]
63              . Util.del_str "]"
64
65 (* View: database *)
66 let database = 
67     [ label "database" . store database_kw
68        . sep_colon
69        . (Build.opt_list
70             (service|reaction)
71             Sep.space)
72        . Util.eol ]
73
74 (* View: lns *)
75 let lns = ( empty | comment | database )*
76
77 (* Variable: filter *)
78 let filter = (incl "/etc/nsswitch.conf")
79
80 let xfm = transform lns filter