Bump to 1.14.1
[platform/upstream/augeas.git] / lenses / pg_hba.aug
1 (*
2 Module: Pg_Hba
3   Parses PostgreSQL's pg_hba.conf
4
5 Author: Aurelien Bompard <aurelien@bompard.org>
6 About: Reference
7   The file format is described in PostgreSQL's documentation:
8   http://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html
9
10 About: License
11   This file is licensed under the LGPL v2+, like the rest of Augeas.
12
13 About: Configuration files
14   This lens applies to pg_hba.conf. See <filter> for exact locations.
15 *)
16
17
18 module Pg_Hba =
19     autoload xfm
20
21     (* Group: Generic primitives *)
22
23     let eol     = Util.eol
24     let word    = Rx.neg1
25     (* Variable: ipaddr
26        CIDR or ip+netmask *)
27     let ipaddr   = /[0-9a-fA-F:.]+(\/[0-9]+|[ \t]+[0-9.]+)/
28     (* Variable: hostname
29        Hostname, FQDN or part of an FQDN possibly 
30        starting with a dot. Taken from the syslog lens. *)
31     let hostname = /\.?[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*/
32
33     let comma_sep_list (l:string) =
34         let lns = [ label l . store word ] in
35             Build.opt_list lns Sep.comma
36
37     (* Group: Columns definitions *)
38
39     (* View: ipaddr_or_hostname *)
40     let ipaddr_or_hostname = ipaddr | hostname
41     (* View: database
42        TODO: support for quoted strings *)
43     let database = comma_sep_list "database"
44     (* View: user
45        TODO: support for quoted strings *)
46     let user = comma_sep_list "user"
47     (* View: address *)
48     let address = [ label "address" . store ipaddr_or_hostname ]
49     (* View: option
50        part of <method> *)
51     let option =
52          let value_start = label "value" . Sep.equal
53       in [ label "option" . store Rx.word
54          . (Quote.quote_spaces value_start)? ]
55
56     (* View: method
57        can contain an <option> *)
58     let method = [ label "method" . store /[A-Za-z][A-Za-z0-9-]+/
59                                   . ( Sep.tab . option )* ]
60
61     (* Group: Records definitions *)
62
63     (* View: record_local
64        when type is "local", there is no "address" field *)
65     let record_local = [ label "type" . store "local" ] . Sep.tab .
66                        database . Sep.tab . user . Sep.tab . method
67
68     (* Variable: remtypes
69        non-local connection types *)
70     let remtypes = "host" | "hostssl" | "hostnossl"
71
72     (* View: record_remote *)
73     let record_remote = [ label "type" . store remtypes ] . Sep.tab .
74                         database . Sep.tab .  user . Sep.tab .
75                         address . Sep.tab . method
76
77     (* View: record
78         A sequence of <record_local> or <record_remote> entries *)
79     let record = [ seq "entries" . (record_local | record_remote) . eol ]
80
81     (* View: filter
82         The pg_hba.conf conf file *)
83     let filter = (incl "/var/lib/pgsql/data/pg_hba.conf" .
84                   incl "/var/lib/pgsql/*/data/pg_hba.conf" .
85                   incl "/var/lib/postgresql/*/data/pg_hba.conf" .
86                   incl "/etc/postgresql/*/*/pg_hba.conf" )
87
88     (* View: lns
89         The pg_hba.conf lens *)
90     let lns = ( record | Util.comment | Util.empty ) *
91
92     let xfm = transform lns filter