From 28440ca607542cebbd337dfff11472d531993fc5 Mon Sep 17 00:00:00 2001 From: James Adams Date: Thu, 17 Aug 2023 15:38:00 +0100 Subject: [PATCH 1/2] ncm-altlogrotate: Support 'su' directive --- .../src/main/pan/components/altlogrotate/schema.pan | 7 +++++++ ncm-altlogrotate/src/main/perl/altlogrotate.pm | 4 ++++ ncm-altlogrotate/src/test/perl/simple.t | 1 + ncm-altlogrotate/src/test/resources/simple.pan | 2 ++ 4 files changed, 14 insertions(+) diff --git a/ncm-altlogrotate/src/main/pan/components/altlogrotate/schema.pan b/ncm-altlogrotate/src/main/pan/components/altlogrotate/schema.pan index 6c2a506960..49ce3f29a8 100644 --- a/ncm-altlogrotate/src/main/pan/components/altlogrotate/schema.pan +++ b/ncm-altlogrotate/src/main/pan/components/altlogrotate/schema.pan @@ -16,6 +16,11 @@ type structure_altlogrotate_create_params = { 'group' : string }; +type structure_altlogrotate_su = { + 'user' : string_trimmed + 'group' : string_trimmed +}; + type structure_altlogrotate_logrot = { 'pattern' ? string @{part of global configuration file, requires an entry called 'global'. @@ -65,6 +70,8 @@ type structure_altlogrotate_logrot = { 'frequency' ? choice('daily', 'weekly', 'monthly', 'yearly') 'scripts' ? structure_altlogrotate_scripts + + 'su' ? structure_altlogrotate_su } with { if (exists(SELF['pattern']) && exists(SELF['include'])) { error('altlogrotate entry: pattern and include are mutually exclusive'); diff --git a/ncm-altlogrotate/src/main/perl/altlogrotate.pm b/ncm-altlogrotate/src/main/perl/altlogrotate.pm index 0f940ae91b..85d1fd0f2e 100755 --- a/ncm-altlogrotate/src/main/perl/altlogrotate.pm +++ b/ncm-altlogrotate/src/main/perl/altlogrotate.pm @@ -74,6 +74,10 @@ sub process_entry print $fh 'tabooext ', $entry->{taboo_replace} ? '' : '+ ', join(',', @{$entry->{tabooext}}), "\n" if defined($entry->{tabooext}); + if (defined($entry->{su})) { + print $fh join(' ', 'su', $entry->{su}->{user}, $entry->{su}->{group}), "\n"; + } + foreach my $name (sort keys %{$entry->{scripts} || {}}) { print $fh "$name\n\n", $entry->{scripts}->{$name}, "\n\nendscript\n"; } diff --git a/ncm-altlogrotate/src/test/perl/simple.t b/ncm-altlogrotate/src/test/perl/simple.t index f2b495c118..22e0d42115 100644 --- a/ncm-altlogrotate/src/test/perl/simple.t +++ b/ncm-altlogrotate/src/test/perl/simple.t @@ -32,6 +32,7 @@ create 0751 someuser agroup mailfirst nomail tabooext a,b +su foouser bargroup lastaction /run/this diff --git a/ncm-altlogrotate/src/test/resources/simple.pan b/ncm-altlogrotate/src/test/resources/simple.pan index a01ed79e7e..38caa0238a 100644 --- a/ncm-altlogrotate/src/test/resources/simple.pan +++ b/ncm-altlogrotate/src/test/resources/simple.pan @@ -20,6 +20,8 @@ prefix '/software/components/altlogrotate/entries/test1'; "scripts" = dict("lastaction", "/run/this"); "tabooext" = list('a', 'b'); "taboo_replace" = true; +"su/user" = 'foouser'; +"su/group" = 'bargroup'; prefix '/software/components/altlogrotate/entries/global'; "include" = "some_file"; From 10ef095bfb804f4fd5530d5aeda3e7f3abb82864 Mon Sep 17 00:00:00 2001 From: James Adams Date: Thu, 17 Aug 2023 17:40:33 +0100 Subject: [PATCH 2/2] ncm-altlogrotate: Remove redundant format in error --- .../src/main/pan/components/altlogrotate/schema.pan | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ncm-altlogrotate/src/main/pan/components/altlogrotate/schema.pan b/ncm-altlogrotate/src/main/pan/components/altlogrotate/schema.pan index 49ce3f29a8..aee6df78a2 100644 --- a/ncm-altlogrotate/src/main/pan/components/altlogrotate/schema.pan +++ b/ncm-altlogrotate/src/main/pan/components/altlogrotate/schema.pan @@ -95,7 +95,7 @@ type altlogrotate_component = { if(!exists(SELF['entries']['global'])) { foreach(name; entry; SELF['entries']) { if(exists(entry['global']) && entry['global']) { - error(format("Cannot have altlogrotate entry %s (with global=true) without 'global' entry", name)); + error("Cannot have altlogrotate entry %s (with global=true) without 'global' entry", name); }; }; };