From 071175d1484caeb4cf64ecaff6b271b1081f88f4 Mon Sep 17 00:00:00 2001 From: Borislav Stoichkov Date: Tue, 12 May 2015 22:13:07 +0000 Subject: [PATCH] Shadow: allow NIS entries Add support for the NIS default entry + and the nis default entry with overrides +:::::::: Based on https://github.com/hercules-team/augeas/pull/237 --- AUTHORS | 1 + lenses/shadow.aug | 35 ++++++++++++++++++++++------------- lenses/tests/test_shadow.aug | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 13 deletions(-) diff --git a/AUTHORS b/AUTHORS index 0852fc73b..cf22341d2 100644 --- a/AUTHORS +++ b/AUTHORS @@ -76,6 +76,7 @@ Contributions by: Nicolas Valcárcel Scerpella Gonzalo Servat Nahum Shalman + Borislav Stoichkov Tim Stoop Laine Stump Jiri Suchomel diff --git a/lenses/shadow.aug b/lenses/shadow.aug index dc2ace3d9..959cb3ace 100644 --- a/lenses/shadow.aug +++ b/lenses/shadow.aug @@ -45,25 +45,34 @@ let sto_to_eol = Passwd.sto_to_eol (************************************************************************ * Group: ENTRIES *************************************************************************) - +(* Common for entry and nisdefault *) +let common = [ label "lastchange_date" . store integer? . colon ] + . [ label "minage_days" . store integer? . colon ] + . [ label "maxage_days" . store integer? . colon ] + . [ label "warn_days" . store integer? . colon ] + . [ label "inactive_days" . store integer? . colon ] + . [ label "expire_date" . store integer? . colon ] + . [ label "flag" . store integer? ] + (* View: entry *) -let entry = [ key word - . colon - . [ label "password" . sto_to_col? . colon ] - . [ label "lastchange_date" . store integer? . colon ] - . [ label "minage_days" . store integer? . colon ] - . [ label "maxage_days" . store integer? . colon ] - . [ label "warn_days" . store integer? . colon ] - . [ label "inactive_days" . store integer? . colon ] - . [ label "expire_date" . store integer? . colon ] - . [ label "flag" . store integer? ] - . eol ] +let entry = [ key word + . colon + . [ label "password" . sto_to_col? . colon ] + . common + . eol ] + +let nisdefault = + let overrides = + colon + . [ label "password" . store word? . colon ] + . common in + [ dels "+" . label "@nisdefault" . overrides? . eol ] (************************************************************************ * LENS *************************************************************************) -let lns = (comment|empty|entry) * +let lns = (comment|empty|entry|nisdefault) * let filter = incl "/etc/shadow" diff --git a/lenses/tests/test_shadow.aug b/lenses/tests/test_shadow.aug index 44b5a944f..ed3e222b0 100644 --- a/lenses/tests/test_shadow.aug +++ b/lenses/tests/test_shadow.aug @@ -43,3 +43,39 @@ test Shadow.lns get conf = { "inactive_days" = "" } { "expire_date" = "" } { "flag" = "" } } + +test Shadow.lns get "+\n" = + { "@nisdefault" } + +test Shadow.lns get "+::::::::\n" = + { "@nisdefault" + { "password" = "" } + { "lastchange_date" = "" } + { "minage_days" = "" } + { "maxage_days" = "" } + { "warn_days" = "" } + { "inactive_days" = "" } + { "expire_date" = "" } + { "flag" = "" } } + +test Shadow.lns put "+\n" after + set "@nisdefault/password" ""; + set "@nisdefault/lastchange_date" ""; + set "@nisdefault/minage_days" ""; + set "@nisdefault/maxage_days" ""; + set "@nisdefault/warn_days" ""; + set "@nisdefault/inactive_days" ""; + set "@nisdefault/expire_date" ""; + set "@nisdefault/flag" "" += "+::::::::\n" + +test Shadow.lns put "+::::::::\n" after + rm "@nisdefault/password"; + rm "@nisdefault/lastchange_date"; + rm "@nisdefault/minage_days"; + rm "@nisdefault/maxage_days"; + rm "@nisdefault/warn_days"; + rm "@nisdefault/inactive_days"; + rm "@nisdefault/expire_date"; + rm "@nisdefault/flag" += "+\n"