3 Parses PostgreSQL's pg_hba.conf
5 Author: Aurelien Bompard <aurelien@bompard.org>
8 The file format is described in PostgreSQL's documentation:
9 http://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html
12 This file is licensed under the LGPLv2+, like the rest of Augeas.
14 About: Configuration files
15 This lens applies to pg_hba.conf. See <filter> for exact locations.
22 (* Group: Generic primitives *)
28 let ipaddr = /[0-9a-fA-F:.]+(\/[0-9]+|[ \t]+[0-9.]+)/
30 let comma_sep_list (l:string) =
31 let lns = [ label l . store word ] in
32 Build.opt_list lns Sep.comma
34 (* Group: Columns definitions *)
37 TODO: support for quoted strings *)
38 let database = comma_sep_list "database"
40 TODO: support for quoted strings *)
41 let user = comma_sep_list "user"
43 let address = [ label "address" . store ipaddr ]
46 let option = [ label "option" . store word ]
48 can contain an <option> *)
49 let method = [ label "method" . store Rx.word . ( Sep.tab . option )? ]
51 (* Group: Records definitions *)
54 when type is "local", there is no "address" field *)
55 let record_local = [ label "type" . store "local" ] . Sep.tab .
56 database . Sep.tab . user . Sep.tab . method
59 non-local connection types *)
60 let remtypes = "host" | "hostssl" | "hostnossl"
62 (* View: record_remote *)
63 let record_remote = [ label "type" . store remtypes ] . Sep.tab .
64 database . Sep.tab . user . Sep.tab .
65 address . Sep.tab . method
68 A sequence of <record_local> or <record_remote> entries *)
69 let record = [ seq "entries" . (record_local | record_remote) . eol ]
72 The pg_hba.conf conf file *)
73 let filter = (incl "/var/lib/pgsql/data/pg_hba.conf" .
74 incl "/etc/postgresql/*/*/pg_hba.conf" )
77 The pg_hba.conf lens *)
78 let lns = ( record | Util.comment | Util.empty ) *
80 let xfm = transform lns filter