Properly quote and escape commands
Some checks failed
Build / build (push) Has been cancelled
Close inactive / close-inactive (push) Has been cancelled
Tests / prove (push) Has been cancelled

This commit is contained in:
Jamie Cameron
2026-05-30 10:22:17 -07:00
parent 184887d365
commit fd79acd840
2 changed files with 22 additions and 16 deletions

View File

@@ -35,21 +35,24 @@ return @rv;
# create_atjob(user, time, commands, directory, send-email)
sub create_atjob
{
my @tm = localtime($_[1]);
my ($user, $tm, $cmds, $dir, $email) = @_;
my @tm = localtime($tm);
my $date = sprintf "%2.2d:%2.2d %d.%d.%d",
$tm[2], $tm[1], $tm[3], $tm[4]+1, $tm[5]+1900;
my $mailflag = $_[4] ? "-m" : "";
my $mailflag = $email ? "-m" : "";
no strict "subs";
&open_execute_command(AT, "su \"$_[0]\" -c \"cd $_[3] ; at $mailflag $date\" >/dev/null 2>&1", 0);
print AT $_[2];
my $fullcmd = &command_as_user($user, 0, "cd $dir ; at $mailflag $date");
&open_execute_command(AT, "$fullcmd >/dev/null 2>&1", 0);
print AT $cmds;
close(AT);
use strict "subs";
&additional_log('exec', undef, "su \"$_[0]\" -c \"cd $_[3] ; at $mailflag $date\"");
&additional_log('exec', undef, $fullcmd);
}
# delete_atjob(id)
sub delete_atjob
{
&system_logged("atrm \"$_[0]\" >/dev/null 2>&1");
my ($id) = @_;
&system_logged("atrm ".quotemeta($id)." >/dev/null 2>&1");
}

View File

@@ -5,13 +5,13 @@ no warnings "redefine";
sub list_atjobs
{
local @rv;
my @rv;
opendir(DIR, $config{'at_dir'}) || return ();
while($f = readdir(DIR)) {
local $p = "$config{'at_dir'}/$f";
my $p = "$config{'at_dir'}/$f";
if ($f =~ /^(\d+)\.a(\S+)$/) {
local @st = stat($p);
local $job = { 'id' => $f,
my @st = stat($p);
my $job = { 'id' => $f,
'date' => $1,
'user' => scalar(getpwuid($st[4])),
'created' => $st[9] };
@@ -32,17 +32,20 @@ return @rv;
# create_atjob(user, time, commands, directory)
sub create_atjob
{
local @tm = localtime($_[1]);
local $date = strftime "%H:%M %b %d", @tm;
&open_execute_command(AT, "su \"$_[0]\" -c \"cd $_[3] ; at $date\"", 0);
print AT $_[2];
my ($user, $tm, $cmds, $dir) = @_;
my @tm = localtime($tm);
my $date = strftime "%H:%M %b %d", @tm;
my $fullcmd = &command_as_user($user, 0, "cd $dir ; at $date");
&open_execute_command(AT, $fullcmd, 0);
print AT $cmds;
close(AT);
&additional_log('exec', undef, "su \"$_[0]\" -c \"cd $_[3] ; at $date\"");
&additional_log('exec', undef, $fullcmd);
}
# delete_atjob(id)
sub delete_atjob
{
&system_logged("at -r \"$_[0]\"");
my ($id) = @_;
&system_logged("at -r ".quotemeta($id));
}