Imported Upstream version 1.7.0
[platform/upstream/augeas.git] / lenses / masterpasswd.aug
1 (*
2  Module: MasterPasswd
3  Parses /etc/master.passwd
4
5  Author: Matt Dainty <matt@bodgit-n-scarper.com>
6
7  About: Reference
8         - man 5 master.passwd
9
10  Each line in the master.passwd file represents a single user record, whose
11  colon-separated attributes correspond to the members of the passwd struct
12
13 *)
14
15 module MasterPasswd =
16
17    autoload xfm
18
19 (************************************************************************
20  * Group:                    USEFUL PRIMITIVES
21  *************************************************************************)
22
23 (* Group: Comments and empty lines *)
24
25 let eol        = Util.eol
26 let comment    = Util.comment
27 let empty      = Util.empty
28 let dels       = Util.del_str
29
30 let word       = Rx.word
31 let integer    = Rx.integer
32
33 let colon      = Sep.colon
34
35 let sto_to_eol = Passwd.sto_to_eol
36 let sto_to_col = Passwd.sto_to_col
37 (* Store an empty string if nothing matches *)
38 let sto_to_col_or_empty = Passwd.sto_to_col_or_empty
39
40 (************************************************************************
41  * Group:                        ENTRIES
42  *************************************************************************)
43
44 let username    = /[_.A-Za-z0-9][-_.A-Za-z0-9]*\$?/
45
46 (* View: password
47         pw_passwd *)
48 let password    = [ label "password"    . sto_to_col?   . colon ]
49
50 (* View: uid
51         pw_uid *)
52 let uid         = [ label "uid"         . store integer . colon ]
53
54 (* View: gid
55         pw_gid *)
56 let gid         = [ label "gid"         . store integer . colon ]
57
58 (* View: class
59         pw_class *)
60 let class       = [ label "class"       . sto_to_col? . colon ]
61
62 (* View: change
63         pw_change *)
64 let change_date = [ label "change_date" . store integer? . colon ]
65
66 (* View: expire
67         pw_expire *)
68 let expire_date = [ label "expire_date" . store integer? . colon ]
69
70 (* View: name
71         pw_gecos; the user's full name *)
72 let name        = [ label "name"        . sto_to_col? . colon ]
73
74 (* View: home
75         pw_dir *)
76 let home        = [ label "home"        . sto_to_col?   . colon ]
77
78 (* View: shell
79         pw_shell *)
80 let shell       = [ label "shell"       . sto_to_eol? ]
81
82 (* View: entry
83         struct passwd *)
84 let entry       = [ key username
85                 . colon
86                 . password
87                 . uid
88                 . gid
89                 . class
90                 . change_date
91                 . expire_date
92                 . name
93                 . home
94                 . shell
95                 . eol ]
96
97 (* NIS entries *)
98 let niscommon   =  [ label "password"    . sto_to_col ]?    . colon
99                . [ label "uid"         . store integer ]? . colon
100                . [ label "gid"         . store integer ]? . colon
101                . [ label "class"       . sto_to_col ]?    . colon
102                . [ label "change_date" . store integer ]? . colon
103                . [ label "expire_date" . store integer ]? . colon
104                . [ label "name"        . sto_to_col ]?    . colon
105                . [ label "home"        . sto_to_col ]?    . colon
106                . [ label "shell"       . sto_to_eol ]?
107
108 let nisentry =
109   let overrides =
110         colon
111       . niscommon in
112   [ dels "+@" . label "@nis" . store username . overrides . eol ]
113
114 let nisuserplus =
115   let overrides =
116         colon
117       . niscommon in
118   [ dels "+" . label "@+nisuser" . store username . overrides . eol ]
119
120 let nisuserminus =
121   let overrides =
122         colon
123       . niscommon in
124   [ dels "-" . label "@-nisuser" . store username . overrides . eol ]
125
126 let nisdefault =
127   let overrides =
128         colon
129       . [ label "password"    . sto_to_col_or_empty . colon ]
130       . [ label "uid"         . store integer? . colon ]
131       . [ label "gid"         . store integer? . colon ]
132       . [ label "class"       . sto_to_col?    . colon ]
133       . [ label "change_date" . store integer? . colon ]
134       . [ label "expire_date" . store integer? . colon ]
135       . [ label "name"        . sto_to_col?    . colon ]
136       . [ label "home"        . sto_to_col?    . colon ]
137       . [ label "shell"       . sto_to_eol? ] in
138   [ dels "+" . label "@nisdefault" . overrides? . eol ]
139
140 (************************************************************************
141  *                                LENS
142  *************************************************************************)
143
144 let lns        = (comment|empty|entry|nisentry|nisdefault|nisuserplus|nisuserminus) *
145
146 let filter     = incl "/etc/master.passwd"
147
148 let xfm        = transform lns filter