Use sudo for sharing lists on darwin platform

On systems prior to high sierra the sharing binary
requires root user for access, so use sudo to get
full list output and inspect output.
This commit is contained in:
Chris Roberts 2017-12-21 14:53:55 -08:00
parent c9e4a400f2
commit 68439f6bac
4 changed files with 12 additions and 6 deletions

View File

@ -3,4 +3,5 @@ Cmnd_Alias VAGRANT_NFSD = /sbin/nfsd restart
Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /usr/bin/sed -E -e /*/ d -ibak /etc/exports
Cmnd_Alias VAGRANT_SMB_ADD = /usr/sbin/sharing -a * -S * -s * -g * -n *
Cmnd_Alias VAGRANT_SMB_REMOVE = /usr/sbin/sharing -r *
%admin ALL=(root) NOPASSWD: VAGRANT_EXPORTS_ADD, VAGRANT_NFSD, VAGRANT_EXPORTS_REMOVE, VAGRANT_SMB_ADD, VAGRANT_SMB_REMOVE
Cmnd_Alias VAGRANT_SMB_LIST = /usr/sbin/sharing -l
%admin ALL=(root) NOPASSWD: VAGRANT_EXPORTS_ADD, VAGRANT_NFSD, VAGRANT_EXPORTS_REMOVE, VAGRANT_SMB_ADD, VAGRANT_SMB_REMOVE, VAGRANT_SMB_LIST

View File

@ -18,12 +18,16 @@ module VagrantPlugins
def self.smb_cleanup(env, machine, opts)
m_id = machine_id(machine)
result = Vagrant::Util::Subprocess.execute("/bin/sh", "-c",
"/usr/sbin/sharing -l | grep -E \"^name:.+\\svgt-#{m_id}-\" | awk '{print $2}'")
result = Vagrant::Util::Subprocess.execute("/usr/bin/sudo", "/usr/sbin/sharing", "-l")
if result.exit_code != 0
@@logger.warn("failed to locate any shares for cleanup")
end
shares = result.stdout.split(/\s/).map(&:strip)
shares = result.stdout.split("\n").map do |line|
if line.start_with?("name:")
share_name = line.sub("name:", "").strip
share_name if share_name.start_with?("vgt-#{m_id}")
end
end.compact
@@logger.debug("shares to be removed: #{shares}")
shares.each do |share_name|
@@logger.info("removing share name=#{share_name}")

View File

@ -13,7 +13,7 @@ en:
warning_password: |-
You will be asked for the username and password to use for the SMB
folders shortly. Please use the proper username/password of your
Windows account.
account.
uac:
prune_warning: |-

View File

@ -55,7 +55,8 @@ without requiring a password each time:
```
Cmnd_Alias VAGRANT_SMB_ADD = /usr/sbin/sharing -a * -S * -s * -g * -n *
Cmnd_Alias VAGRANT_SMB_REMOVE = /usr/sbin/sharing -r *
%admin ALL=(root) NOPASSWD: VAGRANT_SMB_ADD, VAGRANT_SMB_REMOVE
Cmnd_Alias VAGRANT_SMB_LIST = /usr/sbin/sharing -l
%admin ALL=(root) NOPASSWD: VAGRANT_SMB_ADD, VAGRANT_SMB_REMOVE, VAGRANT_SMB_LIST
```
### Guests