Imported Upstream version 0.10.0
[platform/upstream/augeas.git] / lenses / resolv.aug
1 (*
2 Module: Resolv
3   Parses /etc/resolv.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 resolv.conf` where possible.
9
10 About: Licence
11   This file is licensed under the LGPLv2+, like the rest of Augeas.
12
13 About: Lens Usage
14
15 About: Configuration files
16   This lens applies to /etc/resolv.conf. See <filter>.
17 *)
18
19 module Resolv =
20 autoload xfm
21
22 (************************************************************************
23  * Group:                 USEFUL PRIMITIVES
24  *************************************************************************)
25
26 (* View: comment *)
27 let comment = Util.comment_generic /[ \t]*[;#][ \t]*/ "# "
28
29 (* View: comment_eol *)
30 let comment_eol = Util.comment_generic /[ \t]*[;#][ \t]*/ " # "
31
32 (* View: empty *)
33 let empty = Util.empty
34
35
36 (************************************************************************
37  * Group:                 MAIN OPTIONS
38  *************************************************************************)
39
40 (* View: netmask
41 A network mask for IP addresses *)
42 let netmask = [ label "netmask" . Util.del_str "/" . store Rx.ip ]
43
44 (* View: ipaddr 
45 An IP address or range with an optional mask *) 
46 let ipaddr = [label "ipaddr" . store Rx.ip . netmask?]
47
48
49 (* View: nameserver
50      A nameserver entry *)
51 let nameserver = Build.key_value_line_comment
52                     "nameserver" Sep.space (store Rx.ip) comment_eol
53
54 (* View: domain *)
55 let domain = Build.key_value_line_comment
56                     "domain" Sep.space (store Rx.word) comment_eol
57
58 (* View: search *)
59 let search = Build.key_value_line_comment
60                     "search" Sep.space
61                     (Build.opt_list 
62                            [label "domain" . store Rx.word]
63                             Sep.space)
64                     comment_eol
65
66 (* View: sortlist *)
67 let sortlist = Build.key_value_line_comment
68                     "sortlist" Sep.space
69                     (Build.opt_list
70                            ipaddr
71                            Sep.space) 
72                     comment_eol
73
74 (************************************************************************
75  * Group:                 SPECIAL OPTIONS
76  *************************************************************************)
77
78 (* View: ip6_dotint
79      ip6-dotint option, which supports negation *)
80 let ip6_dotint = 
81   let negate = [ del "no-" "no-" . label "negate" ]
82     in [ negate? . key "ip6-dotint" ]
83
84 (* View: options 
85      Options values *)
86 let options =
87       let options_entry = Build.key_value ("ndots"|"timeout"|"attempts") 
88                                           (Util.del_str ":") (store Rx.integer)
89                         | Build.flag ("debug"|"rotate"|"no-check-names"
90                                      |"inet6"|"ip6-bytestring"|"edns0")
91                         | ip6_dotint
92
93             in Build.key_value_line_comment
94                     "options" Sep.space
95                     (Build.opt_list
96                            options_entry
97                            Sep.space)
98                     comment_eol
99
100 (* View: entry *)
101 let entry = nameserver
102           | domain
103           | search
104           | sortlist
105           | options
106
107 (* View: lns *)
108 let lns = ( empty | comment | entry )*
109
110 (* Variable: filter *)
111 let filter = (incl "/etc/resolv.conf")
112     . Util.stdexcl
113
114 let xfm = transform lns filter
115