[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[augeas-devel] augeas: master - Sudoers: produce at most one negate node



Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=468976635238ce814d954b7d44df3b7b41121f87
Commit:        468976635238ce814d954b7d44df3b7b41121f87
Parent:        c35ad5aef2069b39472e209c8700e13706bef8fe
Author:        David Lutterkort <lutter redhat com>
AuthorDate:    Wed Mar 25 12:21:44 2009 -0700
Committer:     David Lutterkort <lutter redhat com>
CommitterDate: Wed Mar 25 12:21:44 2009 -0700

Sudoers: produce at most one negate node

Even if there are multiple '!' signs, only produce one negate node.
---
 lenses/sudoers.aug            |   62 +++++++++++++++++++++--------------------
 lenses/tests/test_sudoers.aug |   13 ++++++++
 2 files changed, 45 insertions(+), 30 deletions(-)

diff --git a/lenses/sudoers.aug b/lenses/sudoers.aug
index 423ce45..39d7d12 100644
--- a/lenses/sudoers.aug
+++ b/lenses/sudoers.aug
@@ -1,9 +1,9 @@
-(* 
+(*
 Module: Sudoers
-  Parses /etc/sudoers     
+  Parses /etc/sudoers
+
+Author: Raphael Pinson <raphink gmail com>
 
-Author: Raphael Pinson <raphink gmail com> 
-                                            
 About: Reference
   This lens tries to keep as close as possible to `man sudoers` where possible.
 
@@ -95,7 +95,7 @@ let sto_to_com_user = store ( /[^,=:#() \t\n]+/
                               - /(User|Runas|Host|Cmnd)_Alias|Defaults.*/ )
 
 (* Variable: sto_to_com_col *)
-let sto_to_com_col      = store /[^",=#() \t\n\\\\]+/
+let sto_to_com_col      = store /[^",=#() \t\n\\\\]+/ (* " relax emacs *)
 
 (* Variable: sto_to_eq *)
 let sto_to_eq  = store /[^,=:#() \t\n\\\\]+/
@@ -233,10 +233,20 @@ let default_type     =
   [ label "type" . value ]
 
 (************************************************************************
- * View: parameter_negate
- *   Negation of boolean values for <defaults>
+ * View: del_negate
+ *   Delete an even number of '!' signs
  *************************************************************************)
-let parameter_negate = [ del "!" "!" . label "negate" ]
+let del_negate = del /(!!)*/ ""
+
+(************************************************************************
+ * View: negate_node
+ *   Negation of boolean values for <defaults>. Accept one optional '!'
+ *   and produce a 'negate' node if there is one.
+ *************************************************************************)
+let negate_node = [ del "!" "!" . label "negate" ]
+
+let negate_or_value (key:lens) (value:lens) =
+  [ del_negate . (negate_node . key | key . value) ]
 
 (************************************************************************
  * View: parameter_flag
@@ -258,8 +268,8 @@ let parameter_flag_kw    = "always_set_home" | "authenticate" | "env_editor"
                          | "shell_noargs" | "stay_setuid" | "targetpw"
                          | "tty_tickets"
 
-let parameter_flag       = [ parameter_negate?
-                           . key parameter_flag_kw ]
+let parameter_flag       = [ (del_negate . negate_node)?
+                               . key parameter_flag_kw ]
 
 (************************************************************************
  * View: parameter_integer
@@ -275,11 +285,10 @@ let parameter_integer_nobool    = [ key parameter_integer_nobool_kw . sep_eq
 let parameter_integer_bool_kw   = "loglinelen" | "passwd_timeout"
                                 | "timestamp_timeout" | "umask"
 
-let parameter_integer_bool      = [ ( parameter_negate
-                                     . key parameter_integer_bool_kw )
-                                | ( key parameter_integer_bool_kw . sep_eq
-                                     . del /"?/ "" . sto_integer
-                                     . del /"?/ "" ) ]
+let parameter_integer_bool      =
+  negate_or_value
+    (key parameter_integer_bool_kw)
+    (sep_eq . del /"?/ "" . sto_integer . del /"?/ "")
 
 let parameter_integer           = parameter_integer_nobool
                                 | parameter_integer_bool
@@ -307,13 +316,10 @@ let parameter_string_bool_kw   = "exempt_group" | "lecture" | "lecture_file"
                                | "mailerflags" | "mailerpath" | "mailto"
                                | "syslog" | "verifypw"
 
-let parameter_string_bool      = [ ( parameter_negate
-                                         . ( parameter_negate
-                                                . parameter_negate )*
-                                         . key parameter_string_bool_kw )
-                               | ( ( parameter_negate . parameter_negate )*
-                                         . key parameter_string_bool_kw
-                                         . sep_eq . sto_to_com_col ) ]
+let parameter_string_bool      =
+  negate_or_value
+    (key parameter_string_bool_kw)
+    (sep_eq . sto_to_com_col)
 
 let parameter_string           = parameter_string_nobool
                                | parameter_string_bool
@@ -346,14 +352,10 @@ let parameter_lists_sep    = sep_cont_opt
                                | [ del "-" "-" . label "remove" ] )?
                              . del "=" "=" . sep_cont_opt
 
-let parameter_lists        = [ ( parameter_negate
-                                         . ( parameter_negate
-                                                . parameter_negate )*
-                                         . key parameter_lists_kw )
-                             | ( ( parameter_negate . parameter_negate )*
-                                         . key parameter_lists_kw
-                                         . parameter_lists_sep
-                                         . parameter_lists_values ) ]
+let parameter_lists        =
+  negate_or_value
+    (key parameter_lists_kw)
+    (parameter_lists_sep . parameter_lists_values)
 
 (************************************************************************
  * View: parameter
diff --git a/lenses/tests/test_sudoers.aug b/lenses/tests/test_sudoers.aug
index f9bc594..86cf119 100644
--- a/lenses/tests/test_sudoers.aug
+++ b/lenses/tests/test_sudoers.aug
@@ -121,3 +121,16 @@ www-data +biglab=(rpinson)NOEXEC: ICAL \
 	      { "host" = "ALPHA" }
 	      { "command" = "/usr/bin/su [!-]*" }
 	      { "command" = "!/usr/bin/su *root*" } } }
+
+test Sudoers.parameter_integer_bool
+    put "umask = 022"
+    after set "/umask/negate" ""  = "!umask"
+
+test Sudoers.parameter_integer_bool
+    put "!!!!!umask"
+    after rm "/umask/negate"; set "/umask" "022" = "!!!!umask = 022"
+
+test Sudoers.parameter_integer_bool put "!!!!umask = 022" after
+    set "/umask/negate" "" = "!!!!!umask"
+
+test Sudoers.parameter_integer_bool get "!!!umask = 022" = *



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]