--- lenses/nsswitch.aug | 89 ++++++++++++++++++++++++++++++++++++++++ lenses/tests/test_nsswitch.aug | 39 +++++++++++++++++ 2 files changed, 128 insertions(+), 0 deletions(-) create mode 100644 lenses/nsswitch.aug create mode 100644 lenses/tests/test_nsswitch.aug
diff --git a/lenses/nsswitch.aug b/lenses/nsswitch.aug new file mode 100644 index 0000000..34d892c --- /dev/null +++ b/lenses/nsswitch.aug @@ -0,0 +1,89 @@ +(* +Module: Nsswitch + Parses /etc/nsswitch.conf + +Author: Raphael Pinson <[email protected]> + +About: Reference + This lens tries to keep as close as possible to `man nsswitch.conf` where possible. + +About: Licence + This file is licensed under the LGPLv2+, like the rest of Augeas. + +About: Lens Usage + +About: Configuration files + This lens applies to /etc/nsswitch.conf. See <filter>. +*) + +module Nsswitch = +autoload xfm + +(************************************************************************ + * Group: USEFUL PRIMITIVES + *************************************************************************) + +(* View: comment *) +let comment = Util.comment + +(* View: empty *) +let empty = Util.empty + +(* View: sep_colon + The separator for database entries *) +let sep_colon = del /:[ \t]*/ ": " + +(* View: service + The service specification like `files', `db', or `nis' *) +let service = [ label "service" . store Rx.word ] + +(* View: reaction + The reaction on lookup result like `[NOTFOUND=return]' + TODO: Use case-insensitive regexps when ticket #147 is fixed. +*) +let reaction = + let status_kw = /[Ss][Uu][Cc][Cc][Ee][Ss][Ss]/ + | /[Nn][Oo][Tt][Ff][Oo][Uu][Nn][Dd]/ + | /[Uu][Nn][Aa][Vv][Aa][Ii][Ll]/ + | /[Tt][Rr][Yy][Aa][Gg][Aa][Ii][Nn]/ + in let action_kw = /[Rr][Ee][Tt][Uu][Rr][Nn]/ + | /[Cc][Oo][Nn][Tt][Ii][Nn][Uu][Ee]/ + in let negate = [ Util.del_str "!" . label "negate" ] + in let reaction_entry = [ label "status" . negate? + . store status_kw + . Util.del_str "=" + . [ label "action" . store action_kw ] ] + in Util.del_str "[" + . [ label "reaction" + . (Build.opt_list reaction_entry Sep.space) ] + . Util.del_str "]" + +(* View: database *) +let database = + let database_kw = "aliases" + | "ethers" + | "group" + | "hosts" + | "netgroup" + | "networks" + | "passwd" + | "protocols" + | "publickey" + | "rpc" + | "services" + | "shadow" + in [ label "database" . store database_kw + . sep_colon + . (Build.opt_list + (service|reaction) + Sep.space) + . Util.eol ] + +(* View: lns *) +let lns = ( empty | comment | database )* + +(* Variable: filter *) +let filter = (incl "/etc/resolv.conf") + . Util.stdexcl + +let xfm = transform lns filter diff --git a/lenses/tests/test_nsswitch.aug b/lenses/tests/test_nsswitch.aug new file mode 100644 index 0000000..d9e5d99 --- /dev/null +++ b/lenses/tests/test_nsswitch.aug @@ -0,0 +1,39 @@ +module Test_nsswitch = + + let conf = "# Sample nsswitch.conf +passwd: compat + +hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4 +networks: nis [!UNAVAIL=return success=continue] files +protocols: db files +netgroup: nis +" + +test Nsswitch.lns get conf = + { "#comment" = "Sample nsswitch.conf" } + { "database" = "passwd" + { "service" = "compat" } } + {} + { "database" = "hosts" + { "service" = "files" } + { "service" = "mdns4_minimal" } + { "reaction" + { "status" = "NOTFOUND" + { "action" = "return" } } } + { "service" = "dns" } + { "service" = "mdns4" } } + { "database" = "networks" + { "service" = "nis" } + { "reaction" + { "status" = "UNAVAIL" + { "negate" } + { "action" = "return" } } + { "status" = "success" + { "action" = "continue" } } } + { "service" = "files" } } + { "database" = "protocols" + { "service" = "db" } + { "service" = "files" } } + { "database" = "netgroup" + { "service" = "nis" } } + -- 1.7.0.4
_______________________________________________ augeas-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/augeas-devel
