Upload Tizen:Main source
[external/augeas.git] / lenses / exports.aug
1 (* Lens for Linux syntax of NFS exports(5) *)
2
3 (*
4 Module: Exports
5     Parses /etc/exports
6
7 Author: David Lutterkort <lutter@redhat.com>
8
9 About: Description
10     /etc/exports contains lines associating a directory with one or
11     more hosts, and NFS options for each host.
12
13 About: Usage Example
14
15 (start code)
16
17     $ augtool
18     augtool> ls /files/etc/exports/
19     comment[1] = /etc/exports: the access control list for filesystems which may be exported
20     comment[2] = to NFS clients.  See exports(5).
21     comment[3] = sample /etc/exports file
22     dir[1]/ = /
23     dir[2]/ = /projects
24     dir[3]/ = /usr
25     dir[4]/ = /home/joe
26
27
28     augtool> ls /files/etc/exports/dir[1]
29     client[1]/ = master
30     client[2]/ = trusty
31 (end code)
32
33 The corresponding line in the file is:
34
35 (start code)
36         /               master(rw) trusty(rw,no_root_squash)
37 (end code)
38
39     Digging further:
40
41 (start code)
42     augtool> ls /files/etc/exports/dir[1]/client[1]
43     option = rw
44
45     To add a new entry, you'd do something like this:
46 (end code)
47
48 (start code)
49     augtool> set /files/etc/exports/dir[10000] /foo
50     augtool> set /files/etc/exports/dir[last()]/client[1] weeble
51     augtool> set /files/etc/exports/dir[last()]/client[1]/option[1] ro
52     augtool> set /files/etc/exports/dir[last()]/client[1]/option[2] all_squash
53     augtool> save
54     Saved 1 file(s)
55 (end code)
56
57     Which creates the line:
58
59 (start code)
60     /foo weeble(ro,all_squash)
61 (end code)
62
63 About: Limitations
64     This lens cannot handle options without a host, as with the last
65     example line in "man 5 exports":
66
67         /pub            (ro,insecure,all_squash)
68
69     In this case, though, you can just do:
70
71         /pub            *(ro,insecure,all_squash)
72
73     It also can't handle whitespace before the directory name.
74 *)
75
76 module Exports =
77   autoload xfm
78
79   let client_re = /[a-zA-Z0-9\.@\*\?\/\-]+/
80
81   let eol = Util.eol
82   let lbracket  = Util.del_str "("
83   let rbracket  = Util.del_str ")"
84   let sep_com   = Sep.comma
85   let sep_spc   = Sep.space
86
87   let option = [ label "option" . store /[^,)]+/ ]
88
89   let client    = [ label "client" . store client_re .
90                     ( Build.brackets lbracket rbracket
91                          ( Build.opt_list option sep_com ) )? ]
92
93   let entry = [ label "dir" . store /\/[^ \t]*/
94                 . sep_spc . Build.opt_list client sep_spc . eol ]
95
96   let lns = (Hosts.empty | Hosts.comment | entry)*
97
98   let xfm = transform lns (incl "/etc/exports")