Upload Tizen:Main source
[external/augeas.git] / lenses / passwd.aug
1 (* Passwd module for Augeas
2  Author: Free Ekanayaka <free@64studio.com>
3
4  Reference: man 5 passwd
5
6 *)
7
8 module Passwd =
9
10    autoload xfm
11
12 (************************************************************************
13  *                           USEFUL PRIMITIVES
14  *************************************************************************)
15
16 let eol        = Util.eol
17 let comment    = Util.comment
18 let empty      = Util.empty
19 let dels       = Util.del_str
20
21 let colon      = del /:/ ":"
22
23 let sto_to_col  = store /[^:\n]+/
24 let sto_to_eol = store /([^ \t\n].*[^ \t\n]|[^ \t\n])/
25
26 let word       = /[A-Za-z0-9_.-]+/
27 let integer    = /[0-9]+/
28
29 (************************************************************************
30  *                               ENTRIES
31  *************************************************************************)
32
33 let entry     = [ key word
34                 . colon
35                 . [ label "password" . store word    . colon ]
36                 . [ label "uid"      . store integer . colon ]
37                 . [ label "gid"      . store integer . colon ]
38                 . [ label "name"     . sto_to_col?   . colon ]
39                 . [ label "home"     . sto_to_col?  . colon ]
40                 . [ label "shell"    . sto_to_eol? ]
41                 . eol ]
42
43 (* A NIS entry has nothing bar the +@:::::: bits. *)
44 let nisentry =
45   let nisuser = /\+\@[A-Za-z0-9_.-]+/ in
46   let colons = "::::::" in
47   [ dels "+@" . label "@nis" . store word . dels colons . eol ]
48
49 let nisdefault =
50   let overrides =
51         colon
52       . [ label "password" . store word?    . colon ]
53       . [ label "uid"      . store integer? . colon ]
54       . [ label "gid"      . store integer? . colon ]
55       . [ label "name"     . sto_to_col?    . colon ]
56       . [ label "home"     . sto_to_col?    . colon ]
57       . [ label "shell"    . sto_to_eol? ] in
58   [ dels "+" . label "@nisdefault" . overrides? . eol ]
59
60 (************************************************************************
61  *                                LENS
62  *************************************************************************)
63
64 let lns        = (comment|empty|entry|nisentry|nisdefault) *
65
66 let filter
67                = incl "/etc/passwd"
68                . Util.stdexcl
69
70 let xfm        = transform lns filter