Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/hookit/resource/directory.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'shellwords'

module Hookit
module Resource
class Directory < Base
Expand Down Expand Up @@ -31,19 +33,19 @@ def run(action)

def create!
return if ::File.exists? path
run_command! "mkdir #{"-p " if recursive}#{path}"
run_command! "mkdir #{"-p " if recursive}#{Shellwords.escape(path)}"
end

def delete!
return if not ::File.exists? path
run_command! "rm -rf #{path}"
run_command! "rm -rf #{Shellwords.escape(path)}"
end

def chown!
return unless owner or group
if ::File.exists? path
cmd = "chown #{(group.nil?) ? owner : "#{owner}:#{group}"} #{path}"
run_command! "chown #{(group.nil?) ? owner : "#{owner}:#{group}"} #{path}"
cmd = "chown #{(group.nil?) ? owner : "#{owner}:#{group}"} #{Shellwords.escape(path)}"
run_command! "chown #{(group.nil?) ? owner : "#{owner}:#{group}"} #{Shellwords.escape(path)}"
end
end

Expand Down
6 changes: 4 additions & 2 deletions lib/hookit/resource/file.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'shellwords'

module Hookit
module Resource
class File < Base
Expand Down Expand Up @@ -60,7 +62,7 @@ def delete!
def chown!
return unless owner or group
if ::File.exists? path
run_command! "chown #{(group.nil?) ? owner : "#{owner}:#{group}"} #{path}"
run_command! "chown #{(group.nil?) ? owner : "#{owner}:#{group}"} #{Shellwords.escape(path)}"
end
end

Expand All @@ -75,7 +77,7 @@ def chmod!
end

def touch!
run_command! "touch -c #{path}"
run_command! "touch -c #{Shellwords.escape(path)}"
end

def unexpected_failure(message, reason)
Expand Down
6 changes: 4 additions & 2 deletions lib/hookit/resource/hook_file.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'shellwords'

module Hookit
module Resource
class HookFile < Base
Expand Down Expand Up @@ -61,7 +63,7 @@ def delete!
def chown!
return unless owner or group
if ::File.exists? path
run_command! "chown #{(group.nil?) ? owner : "#{owner}:#{group}"} #{path}"
run_command! "chown #{(group.nil?) ? owner : "#{owner}:#{group}"} #{Shellwords.escape(path)}"
end
end

Expand All @@ -76,7 +78,7 @@ def chmod!
end

def touch!
run_command! "touch -c #{path}"
run_command! "touch -c #{Shellwords.escape(path)}"
end

def render
Expand Down
8 changes: 5 additions & 3 deletions lib/hookit/resource/link.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'shellwords'

module Hookit
module Resource
class Link < Base
Expand Down Expand Up @@ -32,17 +34,17 @@ def run(action)
def create!
args = ['f']
args << 'sn' if link_type == :symbolic
run_command! "ln -#{args.join} #{to} #{target_file}"
run_command! "ln -#{args.join} #{Shellwords.escape(to)} #{Shellwords.escape(target_file)}"
end

def delete!
run_command! "rm -f #{target_file}"
run_command! "rm -f #{Shellwords.escape(target_file)}"
end

def chown!
return unless owner or group
if ::File.exists? target_file
run_command! "chown #{(group.nil?) ? owner : "#{owner}:#{group}"} #{target_file}"
run_command! "chown #{(group.nil?) ? owner : "#{owner}:#{group}"} #{Shellwords.escape(target_file)}"
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/hookit/resource/logrotate.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'shellwords'

module Hookit
module Resource
class Logrotate < Base
Expand Down Expand Up @@ -27,7 +29,7 @@ def run(action)
def create!
case platform.os
when 'sun'
run_command! `logadm -c -w #{path} -s #{filesize ||= '10m'} -S #{max_size ||= '500m'} -C #{count ||= '10'} -N`
run_command! `logadm -c -w #{Shellwords.escape(path)} -s #{filesize ||= '10m'} -S #{max_size ||= '500m'} -C #{count ||= '10'} -N`
end
end

Expand Down
14 changes: 8 additions & 6 deletions lib/hookit/resource/mount.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'shellwords'

module Hookit
module Resource
class Mount < Base
Expand Down Expand Up @@ -43,18 +45,18 @@ def mount!
::FileUtils.mkdir_p(mount_point)
case platform.os
when 'sun'
run_command! "mount -O -F #{fstype} -o retry=5,timeo=300 #{options!(as_arg=true)} #{device} #{mount_point}"
run_command! "mount -O -F #{fstype} -o retry=5,timeo=300 #{options!(as_arg=true)} #{device} #{Shellwords.escape(mount_point)}"
when 'linux'
run_command! "mount -t #{fstype} -o retry=5,timeo=300 #{options!(as_arg=true)} #{device} #{mount_point}"
run_command! "mount -t #{fstype} -o retry=5,timeo=300 #{options!(as_arg=true)} #{device} #{Shellwords.escape(mount_point)}"
end
end

def umount!
run_command! "umount #{mount_point}"
run_command! "umount #{Shellwords.escape(mount_point)}"
end

def enable!
entry = "#{device}\t#{device =~ /^\/dev/ ? device : "-"}\t#{mount_point}\t#{fstype}\t#{pass}\tyes\t#{options!}"
entry = "#{device}\t#{device =~ /^\/dev/ ? device : "-"}\t#{Shellwords.escape(mount_point)}\t#{fstype}\t#{pass}\tyes\t#{options!}"
case platform.os
when 'sun'
run_command! `echo "#{entry}" >> /etc/vfstab`
Expand All @@ -66,9 +68,9 @@ def enable!
def disable!
case platform.os
when 'sun'
run_command! `egrep -v "#{device}.*#{mount_point}" /etc/vfstab > /tmp/vfstab.tmp; mv -f /tmp/vfstab.tmp /etc/vfstab`
run_command! `egrep -v "#{device}.*#{Shellwords.escape(mount_point)}" /etc/vfstab > /tmp/vfstab.tmp; mv -f /tmp/vfstab.tmp /etc/vfstab`
when 'linux'
run_command! `egrep -v "#{device}.*#{mount_point}" /etc/fstab > /tmp/vfstab.tmp; mv -f /tmp/vfstab.tmp /etc/vfstab`
run_command! `egrep -v "#{device}.*#{Shellwords.escape(mount_point)}" /etc/fstab > /tmp/vfstab.tmp; mv -f /tmp/vfstab.tmp /etc/vfstab`
end
end

Expand Down
4 changes: 3 additions & 1 deletion lib/hookit/resource/rsync.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'shellwords'

module Hookit
module Resource
class Rsync < Base
Expand Down Expand Up @@ -26,7 +28,7 @@ def run(action)
end

def sync!
run_command! "rsync -q#{archive!}#{recursive!}#{checksum!}#{compress!} #{wrapper!} #{source} #{destination}"
run_command! "rsync -q#{archive!}#{recursive!}#{checksum!}#{compress!} #{wrapper!} #{Shellwords.escape(source)} #{Shellwords.escape(destination)}"
end

def archive!
Expand Down
4 changes: 3 additions & 1 deletion lib/hookit/resource/scp.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'shellwords'

module Hookit
module Resource
class Scp < Base
Expand Down Expand Up @@ -31,7 +33,7 @@ def run(action)
end

def copy!
run_command! "scp -q#{preserve!}#{recursive!}B#{compression!} #{config!} #{port!} #{cipher!} #{identity!} #{ssh_options!} #{source} #{destination}"
run_command! "scp -q#{preserve!}#{recursive!}B#{compression!} #{config!} #{port!} #{cipher!} #{identity!} #{ssh_options!} #{Shellwords.escape(source)} #{Shellwords.escape(destination)}"
end

def cipher!
Expand Down
5 changes: 3 additions & 2 deletions lib/hookit/resource/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'erb'
require 'oj'
require 'multi_json'
require 'shellwords'

module Hookit
module Resource
Expand Down Expand Up @@ -68,7 +69,7 @@ def delete!
def chown!
return unless owner or group
if ::File.exists? path
run_command! "chown #{(group.nil?) ? owner : "#{owner}:#{group}"} #{path}"
run_command! "chown #{(group.nil?) ? owner : "#{owner}:#{group}"} #{Shellwords.escape(path)}"
end
end

Expand All @@ -83,7 +84,7 @@ def chmod!
end

def touch!
run_command! "touch -c #{path}"
run_command! "touch -c #{Shellwords.escape(path)}"
end

def render
Expand Down
2 changes: 1 addition & 1 deletion lib/hookit/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Hookit
VERSION = "0.12.8"
VERSION = "0.12.9"
end