diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b57e372a..a418b4ffd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ BUG FIXES: rather than at runtime. - guests/redhat: Set hostname to FQDN, per the documentation for RedHat. [GH-2792] + - hosts/bsd: Don't invoke shell for NFS sudo calls. [GH-2808] - providers/virtualbox: Enabling internal networks by just setting "true" works properly. [GH-2751] - provisioners/chef: When chowning folders, don't follow symlinks. diff --git a/plugins/hosts/bsd/cap/nfs.rb b/plugins/hosts/bsd/cap/nfs.rb index 662985e38..34b4a90b3 100644 --- a/plugins/hosts/bsd/cap/nfs.rb +++ b/plugins/hosts/bsd/cap/nfs.rb @@ -1,6 +1,7 @@ require "log4r" require "vagrant/util" +require "vagrant/util/shell_quote" module VagrantPlugins module HostBSD @@ -102,14 +103,13 @@ module VagrantPlugins # Output the rendered template into the exports output.split("\n").each do |line| - line.gsub!('"', '\"') - line.gsub!("'", "'\\\\''") - system(%Q[sudo -s -- "echo '#{line}' >> /etc/exports"]) + line = Vagrant::Util::ShellQuote.escape(line, "'") + system("sudo", "-s", "--", "echo '#{line}' >> /etc/exports") end # We run restart here instead of "update" just in case nfsd # is not starting - system(nfs_restart_command) + system(*nfs_restart_command) end def self.nfs_exports_template(environment) @@ -152,7 +152,7 @@ module VagrantPlugins end def self.nfs_restart_command(environment) - "sudo nfsd restart" + ["sudo", "nfsd", "restart"] end protected @@ -168,7 +168,10 @@ module VagrantPlugins # Use sed to just strip out the block of code which was inserted # by Vagrant, and restart NFS. - system("sudo sed -E -e '/^# VAGRANT-BEGIN:( #{user})? #{id}/,/^# VAGRANT-END:( #{user})? #{id}/ d' -ibak /etc/exports") + system( + "sudo", "sed", "-E", "-e", + "/^# VAGRANT-BEGIN:( #{user})? #{id}/,/^# VAGRANT-END:( #{user})? #{id}/ d", + "-ibak", "/etc/exports") end def self.nfs_checkexports! diff --git a/plugins/hosts/freebsd/cap/nfs.rb b/plugins/hosts/freebsd/cap/nfs.rb index bc61628ea..452dd20b3 100644 --- a/plugins/hosts/freebsd/cap/nfs.rb +++ b/plugins/hosts/freebsd/cap/nfs.rb @@ -23,7 +23,7 @@ module VagrantPlugins end def self.nfs_restart_command(environment) - "sudo /etc/rc.d/mountd onereload" + ["sudo", "/etc/rc.d/mountd", "onereload"] end end end