Imported Upstream version 0.10.0
[platform/upstream/augeas.git] / lenses / access.aug
1 (* 
2 Module: Access
3   Parses /etc/security/access.conf
4
5 Author: Lorenzo Dalrio <lorenzo.dalrio@gmail.com>
6
7 About: Reference
8   Some examples of valid entries can be found in access.conf or "man access.conf"
9
10 About: License
11   This file is licensed under the LGPLv2+, like the rest of Augeas.
12
13 About: Lens Usage
14   Sample usage of this lens in augtool
15
16   * Add a rule to permit login of all users from local sources (tty's, X, cron)
17   > set /files/etc/security/access.conf[0] +
18   > set /files/etc/security/access.conf[0]/user ALL
19   > set /files/etc/security/access.conf[0]/origin LOCAL
20
21 About: Configuration files
22   This lens applies to /etc/security/access.conf. See <filter>.
23
24 About: Examples
25    The <Test_Access> file contains various examples and tests.
26 *)
27 module Access =
28   autoload xfm
29
30 (* Group: Comments and empty lines *)
31 (* Variable: comment *)
32 let comment   = Util.comment
33 (* Variable: empty *)
34 let empty     = Util.empty
35
36 (* Group: Useful primitives *)
37 (* Variable: colon
38  *  this is the standard field separator " : "
39  *)
40 let colon     = del (Rx.opt_space . ":" . Rx.opt_space) " : "
41
42
43 (************************************************************************
44  * Group:                     ENTRY LINE
45   *************************************************************************)
46 (* View: access
47  * Allow (+) or deny (-) access
48  *)
49 let access    = label "access" . store /[+-]/
50
51 (* View: user_re
52  * Regex for user/netgroup fields
53  *)
54 let user_re = Rx.word - /[Ee][Xx][Cc][Ee][Pp][Tt]/
55
56 (* View: user
57  * user can be a username, username@hostname or a group
58  *)
59 let user      = [ label "user"
60                 . ( store user_re
61                   | store Rx.word . Util.del_str "@"
62                     . [ label "host" . store Rx.word ] ) ]
63
64 (* View: group
65  * Format is (GROUP)
66  *)
67 let group     = [ label "group"
68                   . Util.del_str "(" . store Rx.word . Util.del_str ")" ]
69
70 (* View: netgroup
71  * Format is @NETGROUP[@@NISDOMAIN]
72  *)
73 let netgroup =
74     [ label "netgroup" . Util.del_str "@" . store user_re
75       . [ label "nisdomain" . Util.del_str "@@" . store Rx.word ]? ]
76
77 (* View: user_list
78  * A list of users or netgroups to apply the rule to
79  *)
80 let user_list = Build.opt_list (user|group|netgroup) Sep.space
81
82 (* View: origin_list
83  * origin_list can be a single ipaddr/originname/domain/fqdn or a list of those values
84  *)
85 let origin_list = 
86    let origin_re = Rx.no_spaces - /[Ee][Xx][Cc][Ee][Pp][Tt]/
87    in Build.opt_list [ label "origin" . store origin_re ] Sep.space
88
89 (* View: except
90  * The except operator makes it possible to write very compact rules. 
91  *)
92 let except (lns:lens) = [ label "except" . Sep.space
93                         . del /[Ee][Xx][Cc][Ee][Pp][Tt]/ "EXCEPT"
94                         . Sep.space . lns ]
95
96 (* View: entry 
97  * A valid entry line
98  * Definition:
99  *   > entry ::= access ':' user ':' origin_list
100  *)
101 let entry     = [ access . colon
102                 . user_list
103                 . (except user_list)?
104                 . colon
105                 . origin_list
106                 . (except origin_list)?
107                 . Util.eol ]
108
109 (************************************************************************
110  * Group:                        LENS & FILTER
111   *************************************************************************)
112 (* View: lns
113     The access.conf lens, any amount of
114       * <empty> lines
115       * <comments>
116       * <entry>
117 *)
118 let lns       = (comment|empty|entry) *
119
120 (* Variable: filter *)
121 let filter    = incl "/etc/security/access.conf"
122
123 (* xfm *)
124 let xfm       = transform lns filter