Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ncm-altlogrotate: Support 'su' directive #1619

Merged
merged 2 commits into from Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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