Skip to content

Commit

Permalink
Merge pull request #1619 from jrha/altogrotate-su
Browse files Browse the repository at this point in the history
ncm-altlogrotate: Support 'su' directive
  • Loading branch information
jrha committed Sep 5, 2023
2 parents d50ac39 + 10ef095 commit b17891e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
Expand Up @@ -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'.
Expand Down Expand Up @@ -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');
Expand All @@ -88,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);
};
};
};
Expand Down
4 changes: 4 additions & 0 deletions ncm-altlogrotate/src/main/perl/altlogrotate.pm
Expand Up @@ -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";
}
Expand Down
1 change: 1 addition & 0 deletions ncm-altlogrotate/src/test/perl/simple.t
Expand Up @@ -32,6 +32,7 @@ create 0751 someuser agroup
mailfirst
nomail
tabooext a,b
su foouser bargroup
lastaction
/run/this
Expand Down
2 changes: 2 additions & 0 deletions ncm-altlogrotate/src/test/resources/simple.pan
Expand Up @@ -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";
Expand Down

0 comments on commit b17891e

Please sign in to comment.