3 Parses PostgreSQL's pg_hba.conf
5 Author: Aurelien Bompard <aurelien@bompard.org>
7 The file format is described in PostgreSQL's documentation:
8 http://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html
11 This file is licensed under the LGPL v2+, like the rest of Augeas.
13 About: Configuration files
14 This lens applies to pg_hba.conf. See <filter> for exact locations.
21 (* Group: Generic primitives *)
27 let ipaddr = /[0-9a-fA-F:.]+(\/[0-9]+|[ \t]+[0-9.]+)/
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])?)*/
33 let comma_sep_list (l:string) =
34 let lns = [ label l . store word ] in
35 Build.opt_list lns Sep.comma
37 (* Group: Columns definitions *)
39 (* View: ipaddr_or_hostname *)
40 let ipaddr_or_hostname = ipaddr | hostname
42 TODO: support for quoted strings *)
43 let database = comma_sep_list "database"
45 TODO: support for quoted strings *)
46 let user = comma_sep_list "user"
48 let address = [ label "address" . store ipaddr_or_hostname ]
52 let value_start = label "value" . Sep.equal
53 in [ label "option" . store Rx.word
54 . (Quote.quote_spaces value_start)? ]
57 can contain an <option> *)
58 let method = [ label "method" . store /[A-Za-z][A-Za-z0-9-]+/
59 . ( Sep.tab . option )* ]
61 (* Group: Records definitions *)
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
69 non-local connection types *)
70 let remtypes = "host" | "hostssl" | "hostnossl"
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
78 A sequence of <record_local> or <record_remote> entries *)
79 let record = [ seq "entries" . (record_local | record_remote) . eol ]
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" )
89 The pg_hba.conf lens *)
90 let lns = ( record | Util.comment | Util.empty ) *
92 let xfm = transform lns filter