#!/home/product/code/webui-perl/bin/perl -T -I /home/product/code/firmware/current/lib/perl5
#SUDOER_USERS: nobody
#SUDOER_RUNAS_USERS: root, mta
#SUDOER_TAGS: NOPASSWD, NOEXEC
use strict;
use warnings;
use Barracuda::Sudo::Lib;
use Barracuda::Sudo::SafeOpen;
use Barracuda::Sudo::SafeOpen::Validator;
use FileHandle;
use Fcntl;

=pod

=head1 NAME

mkfile

=head1 DESCRIPTION

touches a whitelisted file, creating it if it doesn't exist

=cut

my $validator = Barracuda::Sudo::SafeOpen::Validator->new();
my $test_validator = Barracuda::Sudo::SafeOpen::Validator->new();
$test_validator->allow_world_writeable();

my %whitelist = (
    '/etc/barracuda/activated' => $validator,
    '/var/tmp/config_flush' => $validator,
    '/tmp/test_mkfile' => $test_validator
);

my ($file) = get_argv(is_whitelisted(keys %whitelist));

my $fd = Barracuda::Sudo::SafeOpen::safe_open($file, $whitelist{$file}, O_WRONLY | O_CREAT) or die $!;
my $fh = FileHandle->new_from_fd($fd, 'r+');
close $fh;

