augeas/SOURCES/0004-Tmpfiles-allow-for-let...

165 lines
4.5 KiB
Diff

From 34749f9ea1af8e3fad9e60891beda0fe786cb0f2 Mon Sep 17 00:00:00 2001
From: Pino Toscano <ptoscano@redhat.com>
Date: Fri, 24 Mar 2023 11:26:46 +0100
Subject: [PATCH 4/5] Tmpfiles: allow '=', '~', '^' for letter types, allow ":"
as prefix for the mode
* Tmpfiles: allow '=', '~', '^' for letter types
Allow an equal sign, a tilde character and/or a caret for the type
specification:
- equal: strict file type enforcing
- tilde: base64-encoded content in the argument
- caret: credential name in the argument
Fixes: #795
* Tmpfiles: allow ":" as prefix for the mode
Represents a mode to be set only for new inodes.
(cherry picked from commit 41b2a33ff02687fa53d69a012a1d47141b196a86)
---
lenses/tests/test_tmpfiles.aug | 78 ++++++++++++++++++++++++++++++++++
lenses/tmpfiles.aug | 9 ++--
2 files changed, 83 insertions(+), 4 deletions(-)
diff --git a/lenses/tests/test_tmpfiles.aug b/lenses/tests/test_tmpfiles.aug
index 6ced069f..4bbd06a2 100644
--- a/lenses/tests/test_tmpfiles.aug
+++ b/lenses/tests/test_tmpfiles.aug
@@ -97,6 +97,60 @@ Tree for <minus_tree> *)
{ "argument" = "-" }
}
+ (* Variable: equal
+Example with an equal sign in the type *)
+ let equal = "d= /tmp/foo 0755 root root - -\n"
+
+ (* Variable: equal_tree
+Tree for <equal> *)
+ let equal_tree =
+ {
+ "1"
+ { "type" = "d=" }
+ { "path" = "/tmp/foo" }
+ { "mode" = "0755" }
+ { "uid" = "root" }
+ { "gid" = "root" }
+ { "age" = "-" }
+ { "argument" = "-" }
+ }
+
+ (* Variable: tilde
+Example with a tilde character in the type *)
+ let tilde = "w~ /tmp/foo 0755 root root - dGVzdAo=\n"
+
+ (* Variable: tilde_tree
+Tree for <tilde> *)
+ let tilde_tree =
+ {
+ "1"
+ { "type" = "w~" }
+ { "path" = "/tmp/foo" }
+ { "mode" = "0755" }
+ { "uid" = "root" }
+ { "gid" = "root" }
+ { "age" = "-" }
+ { "argument" = "dGVzdAo=" }
+ }
+
+ (* Variable: caret
+Example with a caret in the type *)
+ let caret = "f^ /etc/motd.d/50-provision.conf - - - - login.motd\n"
+
+ (* Variable: caret_tree
+Tree for <caret> *)
+ let caret_tree =
+ {
+ "1"
+ { "type" = "f^" }
+ { "path" = "/etc/motd.d/50-provision.conf" }
+ { "mode" = "-" }
+ { "uid" = "-" }
+ { "gid" = "-" }
+ { "age" = "-" }
+ { "argument" = "login.motd" }
+ }
+
(* Variable: short
Example with only type and path *)
let short = "A+ /tmp/foo\n"
@@ -337,6 +391,22 @@ Tree for <mode3> *)
{ "mode" = "755" }
}
+ (* Variable: mode_colon
+Mode field with colon prefix *)
+ let mode_colon = "d- /root :0700 root :root\n"
+
+ (* Variable: mode_colon_tree
+Tree for <mode_colon> *)
+ let mode_colon_tree =
+ {
+ "1"
+ { "type" = "d-" }
+ { "path" = "/root" }
+ { "mode" = ":0700" }
+ { "uid" = "root" }
+ { "gid" = ":root" }
+ }
+
(************************************************************************
* Group: INVALID EXAMPLES
*************************************************************************)
@@ -377,6 +447,12 @@ Invalid example that contain invalid mode (letter) *)
test Tmpfiles.lns get minus = minus_tree
+ test Tmpfiles.lns get equal = equal_tree
+
+ test Tmpfiles.lns get tilde = tilde_tree
+
+ test Tmpfiles.lns get caret = caret_tree
+
test Tmpfiles.lns get short = short_tree
test Tmpfiles.lns get short_mode = short_mode_tree
@@ -405,6 +481,8 @@ Invalid example that contain invalid mode (letter) *)
test Tmpfiles.lns get mode3 = mode3_tree
+ test Tmpfiles.lns get mode_colon = mode_colon_tree
+
(* failure cases *)
diff --git a/lenses/tmpfiles.aug b/lenses/tmpfiles.aug
index 01b3003a..1163c84a 100644
--- a/lenses/tmpfiles.aug
+++ b/lenses/tmpfiles.aug
@@ -50,15 +50,16 @@ Empty lines *)
(* View: type
One letter. Some of them can have a "+" and all can have an
-exclamation mark ("!") and/or minus sign ("-").
+exclamation mark ("!"), a minus sign ("-"), an equal sign ("="),
+a tilde character ("~") and/or a caret ("^").
Not all letters are valid.
*)
- let type = /([fFwdDevqQpLcbCxXrRzZtThHaAm]|[fFwpLcbaA]\+)!?-?/
+ let type = /([fFwdDevqQpLcbCxXrRzZtThHaAm]|[fFwpLcbaA]\+)[-!=~^]*/
(* View: mode
-"-", or 3-4 bytes. Optionally starts with a "~". *)
- let mode = /(-|~?[0-7]{3,4})/
+"-", or 3-4 bytes. Optionally starts with a "~" or a ":". *)
+ let mode = /(-|(~|:)?[0-7]{3,4})/
(* View: age
"-", or one of the formats seen in the manpage: 10d, 5seconds, 1y5days.
--
2.31.1