From 6ddfca24cd333ec93938b3de85c2658da19ca8c8 Mon Sep 17 00:00:00 2001
From: Michal Filka <mfilka@suse.cz>
Date: Thu, 24 Mar 2022 11:18:10 +0100
Subject: [PATCH] Sysctl keys can contain some more non-alphanumeric
 charackters

like net.ipv4.conf.*.rp_filter = 2
---
 .gnulib                      |  2 +-
 lenses/sysctl.aug            | 14 +++++++++++++-
 lenses/tests/test_sysctl.aug | 24 ++++++++++++++++++++++++
 man/augtool.1                | 26 +++++++++++---------------
 4 files changed, 49 insertions(+), 17 deletions(-)

Index: augeas-0.9.0/lenses/sysctl.aug
===================================================================
--- augeas-0.9.0.orig/lenses/sysctl.aug
+++ augeas-0.9.0/lenses/sysctl.aug
@@ -2,20 +2,42 @@ module Sysctl =
   autoload xfm
 
   let filter = incl "/etc/sysctl.conf"
-
-  let eol = Util.eol
-  let indent = Util.indent
-  let key_re = /[A-Za-z0-9_.-]+/
-  let eq = del /[ \t]*=[ \t]*/ " = "
-  let value_re = /[^ \t\n](.*[^ \t\n])?/
-
-  let comment = [ indent . label "#comment" . del /[#;][ \t]*/ "# "
-        . store /([^ \t\n].*[^ \t\n]|[^ \t\n])/ . eol ]
-
-  let empty = Util.empty
-
-  let kv = [ indent . key key_re . eq . store value_re . eol ]
-
-  let lns = (empty | comment | kv) *
+           . incl "/etc/sysctl.d/*"
+           . excl "/etc/sysctl.d/README"
+           . excl "/etc/sysctl.d/README.sysctl"
+           . Util.stdexcl
+
+  (* Following symbols are backported from new augea versions: 
+      comment      : from Util.comment
+      delim        : from Util.delim
+      space_equal  : from Sep.space_equal
+      to_comment_re: from Simplevars.to_comment_re
+  *)
+  let comment = Util.comment_generic /[ \t]*[#;][ \t]*/ "# "
+  let delim (op:string) = del (/[ \t]*/ . op . /[ \t]*/)
+                              (" " . op . " ") 
+  let space_equal = delim "="
+  let to_comment_re =
+         let to_comment_squote = /'[^\n']*'/
+      in let to_comment_dquote = /"[^\n"]*"/
+      in let to_comment_noquote = /[^\n \t'"#][^\n#]*[^\n \t#]|[^\n \t'"#]/
+      in to_comment_squote | to_comment_dquote | to_comment_noquote
+ 
+  (* View: entry
+     basically a Simplevars.entry but key has to allow some special chars as '*' *)
+  let entry =
+         let some_value = space_equal . store to_comment_re
+      (* Rx.word extended by * and : *)
+      in let word = /[*:A-Za-z0-9_.-]+/
+      (* Avoid ambiguity in tree by making a subtree here *)
+      in let empty_value = [del /[ \t]*=/ "="] . store ""
+      in [ Util.indent . key word
+                  . (some_value? | empty_value)
+                  . (Util.eol | Util.comment_eol) ]
+
+  (* View: lns
+     The sysctl lens *)
+  let lns = (Util.empty | comment | entry)*
 
   let xfm = transform lns filter
+
Index: augeas-0.9.0/man/augtool.1
===================================================================
--- augeas-0.9.0.orig/man/augtool.1
+++ augeas-0.9.0/man/augtool.1
@@ -44,20 +44,23 @@
 .ie \n(.g .ds Aq \(aq
 .el       .ds Aq '
 .\"
-.\" If the F register is turned on, we'll generate index entries on stderr for
+.\" If the F register is >0, we'll generate index entries on stderr for
 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
 .\" entries marked with X<> in POD.  Of course, you'll have to process the
 .\" output yourself in some meaningful fashion.
-.ie \nF \{\
-.    de IX
-.    tm Index:\\$1\t\\n%\t"\\$2"
+.\"
+.\" Avoid warning from groff about undefined register 'F'.
+.de IX
 ..
-.    nr % 0
-.    rr F
-.\}
-.el \{\
+.if !\nF .nr F 0
+.if \nF>0 \{\
 .    de IX
+.    tm Index:\\$1\t\\n%\t"\\$2"
 ..
+.    if !\nF==2 \{\
+.        nr % 0
+.        nr F 2
+.    \}
 .\}
 .\"
 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
Index: augeas-0.9.0/lenses/tests/test_sysctl.aug
===================================================================
--- augeas-0.9.0.orig/lenses/tests/test_sysctl.aug
+++ augeas-0.9.0/lenses/tests/test_sysctl.aug
@@ -13,6 +13,13 @@ kernel.sysrq  =  0
 net.ipv4.tcp_mem = \t393216 524288 786432
 "
 
+  (* Variable: spec_chars_sysctl *)
+  let spec_chars_sysctl = "# Kernel sysctl configuration file
+# Controls IP packet forwarding
+net.ipv4.conf.*.rp_filter = 2
+net.ipv4.conf.ib0:0.arp_filter = 1
+"
+
   test Sysctl.lns get default_sysctl =
     { "#comment" = "Kernel sysctl configuration file" }
     { "#comment" = "Controls IP packet forwarding"}
@@ -25,6 +32,13 @@ net.ipv4.tcp_mem = \t393216 524288 78643
     { "#comment" = "Semicolon comments are also allowed" }
     { "net.ipv4.tcp_mem" = "393216 524288 786432" }
 
+  (* Test: Sysctl.lns *)
+  test Sysctl.lns get spec_chars_sysctl =
+    { "#comment" = "Kernel sysctl configuration file" }
+    { "#comment" = "Controls IP packet forwarding"}
+    { "net.ipv4.conf.*.rp_filter" = "2" }
+    { "net.ipv4.conf.ib0:0.arp_filter" = "1" }
+
   test Sysctl.lns put default_sysctl after
     set "net.ipv4.ip_forward" "1" ;
     rm "net.ipv4.conf.default.rp_filter" ;
@@ -39,6 +53,15 @@ net.ipv4.ip_forward = 1
 net.ipv4.tcp_mem = \t393216 524288 786432
 "
 
+  test Sysctl.lns put spec_chars_sysctl after
+    set "net.ipv4.conf.*.rp_filter" "0" ;
+    set "net.ipv4.conf.ib0:0.arp_filter" "0"
+  = "# Kernel sysctl configuration file
+# Controls IP packet forwarding
+net.ipv4.conf.*.rp_filter = 0
+net.ipv4.conf.ib0:0.arp_filter = 0
+"
+
 (* Local Variables: *)
 (* mode: caml       *)
 (* End:             *)
