Bump to 1.14.1
[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 LGPL v2+, 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 (* Variable: identifier_re
52    Regex for user/group identifiers *)
53 let identifier_re = /[A-Za-z0-9_.\\-]+/
54
55 (* View: user_re
56  * Regex for user/netgroup fields
57  *)
58 let user_re = identifier_re - /[Ee][Xx][Cc][Ee][Pp][Tt]/
59
60 (* View: user
61  * user can be a username, username@hostname or a group
62  *)
63 let user      = [ label "user"
64                 . ( store user_re
65                   | store Rx.word . Util.del_str "@"
66                     . [ label "host" . store Rx.word ] ) ]
67
68 (* View: group
69  * Format is (GROUP)
70  *)
71 let group     = [ label "group"
72                   . Util.del_str "(" . store identifier_re . Util.del_str ")" ]
73
74 (* View: netgroup
75  * Format is @NETGROUP[@@NISDOMAIN]
76  *)
77 let netgroup =
78     [ label "netgroup" . Util.del_str "@" . store user_re
79       . [ label "nisdomain" . Util.del_str "@@" . store Rx.word ]? ]
80
81 (* View: user_list
82  * A list of users or netgroups to apply the rule to
83  *)
84 let user_list = Build.opt_list (user|group|netgroup) Sep.space
85
86 (* View: origin_list
87  * origin_list can be a single ipaddr/originname/domain/fqdn or a list of those values
88  *)
89 let origin_list = 
90    let origin_re = Rx.no_spaces - /[Ee][Xx][Cc][Ee][Pp][Tt]/
91    in Build.opt_list [ label "origin" . store origin_re ] Sep.space
92
93 (* View: except
94  * The except operator makes it possible to write very compact rules. 
95  *)
96 let except (lns:lens) = [ label "except" . Sep.space
97                         . del /[Ee][Xx][Cc][Ee][Pp][Tt]/ "EXCEPT"
98                         . Sep.space . lns ]
99
100 (* View: entry 
101  * A valid entry line
102  * Definition:
103  *   > entry ::= access ':' user ':' origin_list
104  *)
105 let entry     = [ access . colon
106                 . user_list
107                 . (except user_list)?
108                 . colon
109                 . origin_list
110                 . (except origin_list)?
111                 . Util.eol ]
112
113 (************************************************************************
114  * Group:                        LENS & FILTER
115   *************************************************************************)
116 (* View: lns
117     The access.conf lens, any amount of
118       * <empty> lines
119       * <comments>
120       * <entry>
121 *)
122 let lns       = (comment|empty|entry) *
123
124 (* Variable: filter *)
125 let filter    = incl "/etc/security/access.conf"
126
127 (* xfm *)
128 let xfm       = transform lns filter