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